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 = -1;
179 /* True if -mfp32 was passed. */
180 static int file_mips_fp32 = -1;
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 /* Whether mips_cprestore_offset has been set in the current function
416 (or whether it has already been warned about, if not). */
417 static int mips_cprestore_valid = 0;
419 /* This is the register which holds the stack frame, as set by the
420 .frame pseudo-op. This is needed to implement .cprestore. */
421 static int mips_frame_reg = SP;
423 /* Whether mips_frame_reg has been set in the current function
424 (or whether it has already been warned about, if not). */
425 static int mips_frame_reg_valid = 0;
427 /* To output NOP instructions correctly, we need to keep information
428 about the previous two instructions. */
430 /* Whether we are optimizing. The default value of 2 means to remove
431 unneeded NOPs and swap branch instructions when possible. A value
432 of 1 means to not swap branches. A value of 0 means to always
434 static int mips_optimize = 2;
436 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
437 equivalent to seeing no -g option at all. */
438 static int mips_debug = 0;
440 /* The previous instruction. */
441 static struct mips_cl_insn prev_insn;
443 /* The instruction before prev_insn. */
444 static struct mips_cl_insn prev_prev_insn;
446 /* If we don't want information for prev_insn or prev_prev_insn, we
447 point the insn_mo field at this dummy integer. */
448 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
450 /* Non-zero if prev_insn is valid. */
451 static int prev_insn_valid;
453 /* The frag for the previous instruction. */
454 static struct frag *prev_insn_frag;
456 /* The offset into prev_insn_frag for the previous instruction. */
457 static long prev_insn_where;
459 /* The reloc type for the previous instruction, if any. */
460 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
462 /* The reloc for the previous instruction, if any. */
463 static fixS *prev_insn_fixp[3];
465 /* Non-zero if the previous instruction was in a delay slot. */
466 static int prev_insn_is_delay_slot;
468 /* Non-zero if the previous instruction was in a .set noreorder. */
469 static int prev_insn_unreordered;
471 /* Non-zero if the previous instruction uses an extend opcode (if
473 static int prev_insn_extended;
475 /* Non-zero if the previous previous instruction was in a .set
477 static int prev_prev_insn_unreordered;
479 /* If this is set, it points to a frag holding nop instructions which
480 were inserted before the start of a noreorder section. If those
481 nops turn out to be unnecessary, the size of the frag can be
483 static fragS *prev_nop_frag;
485 /* The number of nop instructions we created in prev_nop_frag. */
486 static int prev_nop_frag_holds;
488 /* The number of nop instructions that we know we need in
490 static int prev_nop_frag_required;
492 /* The number of instructions we've seen since prev_nop_frag. */
493 static int prev_nop_frag_since;
495 /* For ECOFF and ELF, relocations against symbols are done in two
496 parts, with a HI relocation and a LO relocation. Each relocation
497 has only 16 bits of space to store an addend. This means that in
498 order for the linker to handle carries correctly, it must be able
499 to locate both the HI and the LO relocation. This means that the
500 relocations must appear in order in the relocation table.
502 In order to implement this, we keep track of each unmatched HI
503 relocation. We then sort them so that they immediately precede the
504 corresponding LO relocation. */
509 struct mips_hi_fixup *next;
512 /* The section this fixup is in. */
516 /* The list of unmatched HI relocs. */
518 static struct mips_hi_fixup *mips_hi_fixup_list;
520 /* Map normal MIPS register numbers to mips16 register numbers. */
522 #define X ILLEGAL_REG
523 static const int mips32_to_16_reg_map[] =
525 X, X, 2, 3, 4, 5, 6, 7,
526 X, X, X, X, X, X, X, X,
527 0, 1, X, X, X, X, X, X,
528 X, X, X, X, X, X, X, X
532 /* Map mips16 register numbers to normal MIPS register numbers. */
534 static const unsigned int mips16_to_32_reg_map[] =
536 16, 17, 2, 3, 4, 5, 6, 7
539 /* Since the MIPS does not have multiple forms of PC relative
540 instructions, we do not have to do relaxing as is done on other
541 platforms. However, we do have to handle GP relative addressing
542 correctly, which turns out to be a similar problem.
544 Every macro that refers to a symbol can occur in (at least) two
545 forms, one with GP relative addressing and one without. For
546 example, loading a global variable into a register generally uses
547 a macro instruction like this:
549 If i can be addressed off the GP register (this is true if it is in
550 the .sbss or .sdata section, or if it is known to be smaller than
551 the -G argument) this will generate the following instruction:
553 This instruction will use a GPREL reloc. If i can not be addressed
554 off the GP register, the following instruction sequence will be used:
557 In this case the first instruction will have a HI16 reloc, and the
558 second reloc will have a LO16 reloc. Both relocs will be against
561 The issue here is that we may not know whether i is GP addressable
562 until after we see the instruction that uses it. Therefore, we
563 want to be able to choose the final instruction sequence only at
564 the end of the assembly. This is similar to the way other
565 platforms choose the size of a PC relative instruction only at the
568 When generating position independent code we do not use GP
569 addressing in quite the same way, but the issue still arises as
570 external symbols and local symbols must be handled differently.
572 We handle these issues by actually generating both possible
573 instruction sequences. The longer one is put in a frag_var with
574 type rs_machine_dependent. We encode what to do with the frag in
575 the subtype field. We encode (1) the number of existing bytes to
576 replace, (2) the number of new bytes to use, (3) the offset from
577 the start of the existing bytes to the first reloc we must generate
578 (that is, the offset is applied from the start of the existing
579 bytes after they are replaced by the new bytes, if any), (4) the
580 offset from the start of the existing bytes to the second reloc,
581 (5) whether a third reloc is needed (the third reloc is always four
582 bytes after the second reloc), and (6) whether to warn if this
583 variant is used (this is sometimes needed if .set nomacro or .set
584 noat is in effect). All these numbers are reasonably small.
586 Generating two instruction sequences must be handled carefully to
587 ensure that delay slots are handled correctly. Fortunately, there
588 are a limited number of cases. When the second instruction
589 sequence is generated, append_insn is directed to maintain the
590 existing delay slot information, so it continues to apply to any
591 code after the second instruction sequence. This means that the
592 second instruction sequence must not impose any requirements not
593 required by the first instruction sequence.
595 These variant frags are then handled in functions called by the
596 machine independent code. md_estimate_size_before_relax returns
597 the final size of the frag. md_convert_frag sets up the final form
598 of the frag. tc_gen_reloc adjust the first reloc and adds a second
600 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
604 | (((reloc1) + 64) << 9) \
605 | (((reloc2) + 64) << 2) \
606 | ((reloc3) ? (1 << 1) : 0) \
608 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
609 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
610 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
611 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
612 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
613 #define RELAX_WARN(i) ((i) & 1)
615 /* For mips16 code, we use an entirely different form of relaxation.
616 mips16 supports two versions of most instructions which take
617 immediate values: a small one which takes some small value, and a
618 larger one which takes a 16 bit value. Since branches also follow
619 this pattern, relaxing these values is required.
621 We can assemble both mips16 and normal MIPS code in a single
622 object. Therefore, we need to support this type of relaxation at
623 the same time that we support the relaxation described above. We
624 use the high bit of the subtype field to distinguish these cases.
626 The information we store for this type of relaxation is the
627 argument code found in the opcode file for this relocation, whether
628 the user explicitly requested a small or extended form, and whether
629 the relocation is in a jump or jal delay slot. That tells us the
630 size of the value, and how it should be stored. We also store
631 whether the fragment is considered to be extended or not. We also
632 store whether this is known to be a branch to a different section,
633 whether we have tried to relax this frag yet, and whether we have
634 ever extended a PC relative fragment because of a shift count. */
635 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
638 | ((small) ? 0x100 : 0) \
639 | ((ext) ? 0x200 : 0) \
640 | ((dslot) ? 0x400 : 0) \
641 | ((jal_dslot) ? 0x800 : 0))
642 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
643 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
644 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
645 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
646 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
647 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
648 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
649 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
650 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
651 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
652 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
653 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
655 /* Prototypes for static functions. */
658 #define internalError() \
659 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
661 #define internalError() as_fatal (_("MIPS internal Error"));
664 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
666 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
667 unsigned int reg, enum mips_regclass class));
668 static int reg_needs_delay PARAMS ((unsigned int));
669 static void mips16_mark_labels PARAMS ((void));
670 static void append_insn PARAMS ((char *place,
671 struct mips_cl_insn * ip,
673 bfd_reloc_code_real_type *r,
675 static void mips_no_prev_insn PARAMS ((int));
676 static void mips_emit_delays PARAMS ((boolean));
678 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
679 const char *name, const char *fmt,
682 static void macro_build ();
684 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
685 const char *, const char *,
687 static void macro_build_lui PARAMS ((char *place, int *counter,
688 expressionS * ep, int regnum));
689 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
690 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
692 static void load_register PARAMS ((int *, int, expressionS *, int));
693 static void load_address PARAMS ((int *, int, expressionS *, int, int *));
694 static void move_register PARAMS ((int *, int, int));
695 static void macro PARAMS ((struct mips_cl_insn * ip));
696 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
697 #ifdef LOSING_COMPILER
698 static void macro2 PARAMS ((struct mips_cl_insn * ip));
700 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
701 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
702 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
703 boolean, boolean, unsigned long *,
704 boolean *, unsigned short *));
705 static int my_getPercentOp PARAMS ((char **, unsigned int *, int *));
706 static int my_getSmallParser PARAMS ((char **, unsigned int *, int *));
707 static int my_getSmallExpression PARAMS ((expressionS *, char *));
708 static void my_getExpression PARAMS ((expressionS *, char *));
710 static int support_64bit_objects PARAMS((void));
712 static symbolS *get_symbol PARAMS ((void));
713 static void mips_align PARAMS ((int to, int fill, symbolS *label));
714 static void s_align PARAMS ((int));
715 static void s_change_sec PARAMS ((int));
716 static void s_cons PARAMS ((int));
717 static void s_float_cons PARAMS ((int));
718 static void s_mips_globl PARAMS ((int));
719 static void s_option PARAMS ((int));
720 static void s_mipsset PARAMS ((int));
721 static void s_abicalls PARAMS ((int));
722 static void s_cpload PARAMS ((int));
723 static void s_cpsetup PARAMS ((int));
724 static void s_cplocal PARAMS ((int));
725 static void s_cprestore PARAMS ((int));
726 static void s_cpreturn PARAMS ((int));
727 static void s_gpvalue PARAMS ((int));
728 static void s_gpword PARAMS ((int));
729 static void s_cpadd PARAMS ((int));
730 static void s_insn PARAMS ((int));
731 static void md_obj_begin PARAMS ((void));
732 static void md_obj_end PARAMS ((void));
733 static long get_number PARAMS ((void));
734 static void s_mips_ent PARAMS ((int));
735 static void s_mips_end PARAMS ((int));
736 static void s_mips_frame PARAMS ((int));
737 static void s_mips_mask PARAMS ((int));
738 static void s_mips_stab PARAMS ((int));
739 static void s_mips_weakext PARAMS ((int));
740 static void s_file PARAMS ((int));
741 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
742 static const char *mips_isa_to_str PARAMS ((int));
743 static const char *mips_cpu_to_str PARAMS ((int));
744 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
745 static void show PARAMS ((FILE *, char *, int *, int *));
747 static int mips_need_elf_addend_fixup PARAMS ((fixS *));
750 /* Return values of my_getSmallExpression(). */
757 /* Direct relocation creation by %percent_op(). */
776 /* Table and functions used to map between CPU/ISA names, and
777 ISA levels, and CPU numbers. */
781 const char *name; /* CPU or ISA name. */
782 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
783 int isa; /* ISA level. */
784 int cpu; /* CPU number (default CPU if ISA). */
787 static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *));
788 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
789 static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int));
793 The following pseudo-ops from the Kane and Heinrich MIPS book
794 should be defined here, but are currently unsupported: .alias,
795 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
797 The following pseudo-ops from the Kane and Heinrich MIPS book are
798 specific to the type of debugging information being generated, and
799 should be defined by the object format: .aent, .begin, .bend,
800 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
803 The following pseudo-ops from the Kane and Heinrich MIPS book are
804 not MIPS CPU specific, but are also not specific to the object file
805 format. This file is probably the best place to define them, but
806 they are not currently supported: .asm0, .endr, .lab, .repeat,
809 static const pseudo_typeS mips_pseudo_table[] =
811 /* MIPS specific pseudo-ops. */
812 {"option", s_option, 0},
813 {"set", s_mipsset, 0},
814 {"rdata", s_change_sec, 'r'},
815 {"sdata", s_change_sec, 's'},
816 {"livereg", s_ignore, 0},
817 {"abicalls", s_abicalls, 0},
818 {"cpload", s_cpload, 0},
819 {"cpsetup", s_cpsetup, 0},
820 {"cplocal", s_cplocal, 0},
821 {"cprestore", s_cprestore, 0},
822 {"cpreturn", s_cpreturn, 0},
823 {"gpvalue", s_gpvalue, 0},
824 {"gpword", s_gpword, 0},
825 {"cpadd", s_cpadd, 0},
828 /* Relatively generic pseudo-ops that happen to be used on MIPS
830 {"asciiz", stringer, 1},
831 {"bss", s_change_sec, 'b'},
834 {"dword", s_cons, 3},
835 {"weakext", s_mips_weakext, 0},
837 /* These pseudo-ops are defined in read.c, but must be overridden
838 here for one reason or another. */
839 {"align", s_align, 0},
841 {"data", s_change_sec, 'd'},
842 {"double", s_float_cons, 'd'},
843 {"float", s_float_cons, 'f'},
844 {"globl", s_mips_globl, 0},
845 {"global", s_mips_globl, 0},
846 {"hword", s_cons, 1},
851 {"short", s_cons, 1},
852 {"single", s_float_cons, 'f'},
853 {"stabn", s_mips_stab, 'n'},
854 {"text", s_change_sec, 't'},
857 #ifdef MIPS_STABS_ELF
858 { "extern", ecoff_directive_extern, 0},
864 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
866 /* These pseudo-ops should be defined by the object file format.
867 However, a.out doesn't support them, so we have versions here. */
868 {"aent", s_mips_ent, 1},
869 {"bgnb", s_ignore, 0},
870 {"end", s_mips_end, 0},
871 {"endb", s_ignore, 0},
872 {"ent", s_mips_ent, 0},
874 {"fmask", s_mips_mask, 'F'},
875 {"frame", s_mips_frame, 0},
876 {"loc", s_ignore, 0},
877 {"mask", s_mips_mask, 'R'},
878 {"verstamp", s_ignore, 0},
882 extern void pop_insert PARAMS ((const pseudo_typeS *));
887 pop_insert (mips_pseudo_table);
888 if (! ECOFF_DEBUGGING)
889 pop_insert (mips_nonecoff_pseudo_table);
892 /* Symbols labelling the current insn. */
894 struct insn_label_list
896 struct insn_label_list *next;
900 static struct insn_label_list *insn_labels;
901 static struct insn_label_list *free_insn_labels;
903 static void mips_clear_insn_labels PARAMS ((void));
906 mips_clear_insn_labels ()
908 register struct insn_label_list **pl;
910 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
916 static char *expr_end;
918 /* Expressions which appear in instructions. These are set by
921 static expressionS imm_expr;
922 static expressionS offset_expr;
924 /* Relocs associated with imm_expr and offset_expr. */
926 static bfd_reloc_code_real_type imm_reloc[3]
927 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
928 static bfd_reloc_code_real_type offset_reloc[3]
929 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
931 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
933 static boolean imm_unmatched_hi;
935 /* These are set by mips16_ip if an explicit extension is used. */
937 static boolean mips16_small, mips16_ext;
939 #ifdef MIPS_STABS_ELF
940 /* The pdr segment for per procedure frame/regmask info */
946 mips_isa_to_str (isa)
949 const struct mips_cpu_info *ci;
952 ci = mips_cpu_info_from_isa (isa);
956 sprintf (s, "ISA#%d", isa);
961 mips_cpu_to_str (cpu)
964 const struct mips_cpu_info *ci;
967 ci = mips_cpu_info_from_cpu (cpu);
971 sprintf (s, "CPU#%d", cpu);
975 /* The default target format to use. */
978 mips_target_format ()
980 switch (OUTPUT_FLAVOR)
982 case bfd_target_aout_flavour:
983 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
984 case bfd_target_ecoff_flavour:
985 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
986 case bfd_target_coff_flavour:
988 case bfd_target_elf_flavour:
990 /* This is traditional mips */
991 return (target_big_endian
992 ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips"
993 : "elf32-tradbigmips")
994 : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips"
995 : "elf32-tradlittlemips"));
997 return (target_big_endian
998 ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips")
999 : (HAVE_64BIT_OBJECTS ? "elf64-littlemips"
1000 : "elf32-littlemips"));
1008 /* This function is called once, at assembler startup time. It should
1009 set up all the tables, etc. that the MD part of the assembler will need. */
1014 register const char *retval = NULL;
1019 int mips_isa_from_cpu;
1020 int target_cpu_had_mips16 = 0;
1021 const struct mips_cpu_info *ci;
1023 /* GP relative stuff not working for PE */
1024 if (strncmp (TARGET_OS, "pe", 2) == 0
1025 && g_switch_value != 0)
1028 as_bad (_("-G not supported in this configuration."));
1033 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
1035 a = xmalloc (sizeof TARGET_CPU);
1036 strcpy (a, TARGET_CPU);
1037 a[(sizeof TARGET_CPU) - 3] = '\0';
1041 if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0)
1043 target_cpu_had_mips16 = 1;
1044 cpu += sizeof "mips16" - 1;
1047 if (mips_opts.mips16 < 0)
1048 mips_opts.mips16 = target_cpu_had_mips16;
1050 /* Backward compatibility for historic -mcpu= option. Check for
1051 incompatible options, warn if -mcpu is used. */
1052 if (mips_cpu != CPU_UNKNOWN
1053 && mips_arch != CPU_UNKNOWN
1054 && mips_cpu != mips_arch)
1056 as_fatal (_("The -mcpu option can't be used together with -march. "
1057 "Use -mtune instead of -mcpu."));
1060 if (mips_cpu != CPU_UNKNOWN
1061 && mips_tune != CPU_UNKNOWN
1062 && mips_cpu != mips_tune)
1064 as_fatal (_("The -mcpu option can't be used together with -mtune. "
1065 "Use -march instead of -mcpu."));
1069 /* For backward compatibility, let -mipsN set various defaults. */
1070 /* This code should go away, to be replaced with something rather more
1071 draconian. Until GCC 3.1 has been released for some reasonable
1072 amount of time, however, we need to support this. */
1073 if (mips_opts.isa != ISA_UNKNOWN)
1075 /* Translate -mipsN to the appropriate settings of file_mips_gp32
1076 and file_mips_fp32. Tag binaries as using the mipsN ISA. */
1077 if (file_mips_gp32 < 0)
1079 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1084 if (file_mips_fp32 < 0)
1086 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1092 ci = mips_cpu_info_from_isa (mips_opts.isa);
1093 assert (ci != NULL);
1094 /* -mipsN has higher priority than -mcpu but lower than -march. */
1095 if (mips_arch == CPU_UNKNOWN)
1096 mips_arch = ci->cpu;
1098 /* Default mips_abi. */
1099 if (mips_opts.abi == NO_ABI)
1101 if (mips_opts.isa == ISA_MIPS1 || mips_opts.isa == ISA_MIPS2)
1102 mips_opts.abi = O32_ABI;
1103 else if (mips_opts.isa == ISA_MIPS3 || mips_opts.isa == ISA_MIPS4)
1104 mips_opts.abi = O64_ABI;
1108 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1110 ci = mips_cpu_info_from_cpu (mips_cpu);
1111 assert (ci != NULL);
1112 mips_arch = ci->cpu;
1113 as_warn (_("The -mcpu option is deprecated. Please use -march and "
1114 "-mtune instead."));
1117 /* Set tune from -mcpu, not from -mipsN. */
1118 if (mips_tune == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1120 ci = mips_cpu_info_from_cpu (mips_cpu);
1121 assert (ci != NULL);
1122 mips_tune = ci->cpu;
1125 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
1126 specified on the command line, or some other value if one was.
1127 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
1128 the command line, or will be set otherwise if one was. */
1130 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1131 /* Handled above. */;
1133 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1135 ci = mips_cpu_info_from_cpu (mips_cpu);
1136 assert (ci != NULL);
1137 mips_arch = ci->cpu;
1138 as_warn (_("The -mcpu option is deprecated. Please use -march and "
1139 "-mtune instead."));
1142 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
1143 specified on the command line, or some other value if one was.
1144 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
1145 the command line, or will be set otherwise if one was. */
1147 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1149 /* We have to check if the isa is the default isa of arch. Otherwise
1150 we'll get invalid object file headers. */
1151 ci = mips_cpu_info_from_cpu (mips_arch);
1152 assert (ci != NULL);
1153 if (mips_opts.isa != ci->isa)
1155 /* This really should be an error instead of a warning, but old
1156 compilers only have -mcpu which sets both arch and tune. For
1157 now, we discard arch and preserve tune. */
1158 as_warn (_("The -march option is incompatible to -mipsN and "
1159 "therefore ignored."));
1160 if (mips_tune == CPU_UNKNOWN)
1161 mips_tune = mips_arch;
1162 ci = mips_cpu_info_from_isa (mips_opts.isa);
1163 assert (ci != NULL);
1164 mips_arch = ci->cpu;
1168 else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN)
1170 /* We have ARCH, we need ISA. */
1171 ci = mips_cpu_info_from_cpu (mips_arch);
1172 assert (ci != NULL);
1173 mips_opts.isa = ci->isa;
1175 else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1177 /* We have ISA, we need default ARCH. */
1178 ci = mips_cpu_info_from_isa (mips_opts.isa);
1179 assert (ci != NULL);
1180 mips_arch = ci->cpu;
1184 /* We need to set both ISA and ARCH from target cpu. */
1185 ci = mips_cpu_info_from_name (cpu);
1187 ci = mips_cpu_info_from_cpu (CPU_R3000);
1188 assert (ci != NULL);
1189 mips_opts.isa = ci->isa;
1190 mips_arch = ci->cpu;
1193 if (mips_tune == CPU_UNKNOWN)
1194 mips_tune = mips_arch;
1196 ci = mips_cpu_info_from_cpu (mips_arch);
1197 assert (ci != NULL);
1198 mips_isa_from_cpu = ci->isa;
1200 /* End of TARGET_CPU processing, get rid of malloced memory
1209 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
1210 as_bad (_("trap exception not supported at ISA 1"));
1212 /* Set the EABI kind based on the ISA before the user gets
1213 to change the ISA with directives. This isn't really
1214 the best, but then neither is basing the abi on the isa. */
1215 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
1216 && mips_opts.abi == EABI_ABI)
1219 /* If they asked for mips1 or mips2 and a cpu that is
1220 mips3 or greater, then mark the object file 32BITMODE. */
1221 if (mips_isa_from_cpu != ISA_UNKNOWN
1222 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
1223 && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
1226 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1227 as_warn (_("Could not set architecture and machine"));
1229 if (file_mips_gp32 < 0)
1231 if (file_mips_fp32 < 0)
1234 file_mips_isa = mips_opts.isa;
1235 file_mips_abi = mips_opts.abi;
1236 mips_opts.gp32 = file_mips_gp32;
1237 mips_opts.fp32 = file_mips_fp32;
1239 op_hash = hash_new ();
1241 for (i = 0; i < NUMOPCODES;)
1243 const char *name = mips_opcodes[i].name;
1245 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1248 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1249 mips_opcodes[i].name, retval);
1250 /* Probably a memory allocation problem? Give up now. */
1251 as_fatal (_("Broken assembler. No assembly attempted."));
1255 if (mips_opcodes[i].pinfo != INSN_MACRO)
1257 if (!validate_mips_insn (&mips_opcodes[i]))
1262 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1265 mips16_op_hash = hash_new ();
1268 while (i < bfd_mips16_num_opcodes)
1270 const char *name = mips16_opcodes[i].name;
1272 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1274 as_fatal (_("internal: can't hash `%s': %s"),
1275 mips16_opcodes[i].name, retval);
1278 if (mips16_opcodes[i].pinfo != INSN_MACRO
1279 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1280 != mips16_opcodes[i].match))
1282 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1283 mips16_opcodes[i].name, mips16_opcodes[i].args);
1288 while (i < bfd_mips16_num_opcodes
1289 && strcmp (mips16_opcodes[i].name, name) == 0);
1293 as_fatal (_("Broken assembler. No assembly attempted."));
1295 /* We add all the general register names to the symbol table. This
1296 helps us detect invalid uses of them. */
1297 for (i = 0; i < 32; i++)
1301 sprintf (buf, "$%d", i);
1302 symbol_table_insert (symbol_new (buf, reg_section, i,
1303 &zero_address_frag));
1305 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1306 &zero_address_frag));
1307 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1308 &zero_address_frag));
1309 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1310 &zero_address_frag));
1311 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1312 &zero_address_frag));
1313 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1314 &zero_address_frag));
1315 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1316 &zero_address_frag));
1317 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1318 &zero_address_frag));
1320 mips_no_prev_insn (false);
1323 mips_cprmask[0] = 0;
1324 mips_cprmask[1] = 0;
1325 mips_cprmask[2] = 0;
1326 mips_cprmask[3] = 0;
1328 /* set the default alignment for the text section (2**2) */
1329 record_alignment (text_section, 2);
1331 if (USE_GLOBAL_POINTER_OPT)
1332 bfd_set_gp_size (stdoutput, g_switch_value);
1334 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1336 /* On a native system, sections must be aligned to 16 byte
1337 boundaries. When configured for an embedded ELF target, we
1339 if (strcmp (TARGET_OS, "elf") != 0)
1341 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1342 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1343 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1346 /* Create a .reginfo section for register masks and a .mdebug
1347 section for debugging information. */
1355 subseg = now_subseg;
1357 /* The ABI says this section should be loaded so that the
1358 running program can access it. However, we don't load it
1359 if we are configured for an embedded target */
1360 flags = SEC_READONLY | SEC_DATA;
1361 if (strcmp (TARGET_OS, "elf") != 0)
1362 flags |= SEC_ALLOC | SEC_LOAD;
1366 sec = subseg_new (".reginfo", (subsegT) 0);
1368 (void) bfd_set_section_flags (stdoutput, sec, flags);
1369 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1372 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1377 /* The 64-bit ABI uses a .MIPS.options section rather than
1378 .reginfo section. */
1379 sec = subseg_new (".MIPS.options", (subsegT) 0);
1380 (void) bfd_set_section_flags (stdoutput, sec, flags);
1381 (void) bfd_set_section_alignment (stdoutput, sec, 3);
1384 /* Set up the option header. */
1386 Elf_Internal_Options opthdr;
1389 opthdr.kind = ODK_REGINFO;
1390 opthdr.size = (sizeof (Elf_External_Options)
1391 + sizeof (Elf64_External_RegInfo));
1394 f = frag_more (sizeof (Elf_External_Options));
1395 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1396 (Elf_External_Options *) f);
1398 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1403 if (ECOFF_DEBUGGING)
1405 sec = subseg_new (".mdebug", (subsegT) 0);
1406 (void) bfd_set_section_flags (stdoutput, sec,
1407 SEC_HAS_CONTENTS | SEC_READONLY);
1408 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1411 #ifdef MIPS_STABS_ELF
1412 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1413 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1414 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
1415 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1418 subseg_set (seg, subseg);
1422 if (! ECOFF_DEBUGGING)
1429 if (! ECOFF_DEBUGGING)
1437 struct mips_cl_insn insn;
1438 bfd_reloc_code_real_type unused_reloc[3]
1439 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1441 imm_expr.X_op = O_absent;
1442 imm_unmatched_hi = false;
1443 offset_expr.X_op = O_absent;
1444 imm_reloc[0] = BFD_RELOC_UNUSED;
1445 imm_reloc[1] = BFD_RELOC_UNUSED;
1446 imm_reloc[2] = BFD_RELOC_UNUSED;
1447 offset_reloc[0] = BFD_RELOC_UNUSED;
1448 offset_reloc[1] = BFD_RELOC_UNUSED;
1449 offset_reloc[2] = BFD_RELOC_UNUSED;
1451 if (mips_opts.mips16)
1452 mips16_ip (str, &insn);
1455 mips_ip (str, &insn);
1456 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1457 str, insn.insn_opcode));
1462 as_bad ("%s `%s'", insn_error, str);
1466 if (insn.insn_mo->pinfo == INSN_MACRO)
1468 if (mips_opts.mips16)
1469 mips16_macro (&insn);
1475 if (imm_expr.X_op != O_absent)
1476 append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi);
1477 else if (offset_expr.X_op != O_absent)
1478 append_insn (NULL, &insn, &offset_expr, offset_reloc, false);
1480 append_insn (NULL, &insn, NULL, unused_reloc, false);
1484 /* See whether instruction IP reads register REG. CLASS is the type
1488 insn_uses_reg (ip, reg, class)
1489 struct mips_cl_insn *ip;
1491 enum mips_regclass class;
1493 if (class == MIPS16_REG)
1495 assert (mips_opts.mips16);
1496 reg = mips16_to_32_reg_map[reg];
1497 class = MIPS_GR_REG;
1500 /* Don't report on general register 0, since it never changes. */
1501 if (class == MIPS_GR_REG && reg == 0)
1504 if (class == MIPS_FP_REG)
1506 assert (! mips_opts.mips16);
1507 /* If we are called with either $f0 or $f1, we must check $f0.
1508 This is not optimal, because it will introduce an unnecessary
1509 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1510 need to distinguish reading both $f0 and $f1 or just one of
1511 them. Note that we don't have to check the other way,
1512 because there is no instruction that sets both $f0 and $f1
1513 and requires a delay. */
1514 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1515 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1516 == (reg &~ (unsigned) 1)))
1518 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1519 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1520 == (reg &~ (unsigned) 1)))
1523 else if (! mips_opts.mips16)
1525 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1526 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1528 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1529 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1534 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1535 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1536 & MIPS16OP_MASK_RX)]
1539 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1540 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1541 & MIPS16OP_MASK_RY)]
1544 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1545 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1546 & MIPS16OP_MASK_MOVE32Z)]
1549 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1551 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1553 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1555 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1556 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1557 & MIPS16OP_MASK_REGR32) == reg)
1564 /* This function returns true if modifying a register requires a
1568 reg_needs_delay (reg)
1571 unsigned long prev_pinfo;
1573 prev_pinfo = prev_insn.insn_mo->pinfo;
1574 if (! mips_opts.noreorder
1575 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1576 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1577 || (! gpr_interlocks
1578 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1580 /* A load from a coprocessor or from memory. All load
1581 delays delay the use of general register rt for one
1582 instruction on the r3000. The r6000 and r4000 use
1584 /* Itbl support may require additional care here. */
1585 know (prev_pinfo & INSN_WRITE_GPR_T);
1586 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1593 /* Mark instruction labels in mips16 mode. This permits the linker to
1594 handle them specially, such as generating jalx instructions when
1595 needed. We also make them odd for the duration of the assembly, in
1596 order to generate the right sort of code. We will make them even
1597 in the adjust_symtab routine, while leaving them marked. This is
1598 convenient for the debugger and the disassembler. The linker knows
1599 to make them odd again. */
1602 mips16_mark_labels ()
1604 if (mips_opts.mips16)
1606 struct insn_label_list *l;
1609 for (l = insn_labels; l != NULL; l = l->next)
1612 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1613 S_SET_OTHER (l->label, STO_MIPS16);
1615 val = S_GET_VALUE (l->label);
1617 S_SET_VALUE (l->label, val + 1);
1622 /* Output an instruction. PLACE is where to put the instruction; if
1623 it is NULL, this uses frag_more to get room. IP is the instruction
1624 information. ADDRESS_EXPR is an operand of the instruction to be
1625 used with RELOC_TYPE. */
1628 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1630 struct mips_cl_insn *ip;
1631 expressionS *address_expr;
1632 bfd_reloc_code_real_type *reloc_type;
1633 boolean unmatched_hi;
1635 register unsigned long prev_pinfo, pinfo;
1640 /* Mark instruction labels in mips16 mode. */
1641 if (mips_opts.mips16)
1642 mips16_mark_labels ();
1644 prev_pinfo = prev_insn.insn_mo->pinfo;
1645 pinfo = ip->insn_mo->pinfo;
1647 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1651 /* If the previous insn required any delay slots, see if we need
1652 to insert a NOP or two. There are eight kinds of possible
1653 hazards, of which an instruction can have at most one type.
1654 (1) a load from memory delay
1655 (2) a load from a coprocessor delay
1656 (3) an unconditional branch delay
1657 (4) a conditional branch delay
1658 (5) a move to coprocessor register delay
1659 (6) a load coprocessor register from memory delay
1660 (7) a coprocessor condition code delay
1661 (8) a HI/LO special register delay
1663 There are a lot of optimizations we could do that we don't.
1664 In particular, we do not, in general, reorder instructions.
1665 If you use gcc with optimization, it will reorder
1666 instructions and generally do much more optimization then we
1667 do here; repeating all that work in the assembler would only
1668 benefit hand written assembly code, and does not seem worth
1671 /* This is how a NOP is emitted. */
1672 #define emit_nop() \
1674 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1675 : md_number_to_chars (frag_more (4), 0, 4))
1677 /* The previous insn might require a delay slot, depending upon
1678 the contents of the current insn. */
1679 if (! mips_opts.mips16
1680 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1681 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1682 && ! cop_interlocks)
1683 || (! gpr_interlocks
1684 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1686 /* A load from a coprocessor or from memory. All load
1687 delays delay the use of general register rt for one
1688 instruction on the r3000. The r6000 and r4000 use
1690 /* Itbl support may require additional care here. */
1691 know (prev_pinfo & INSN_WRITE_GPR_T);
1692 if (mips_optimize == 0
1693 || insn_uses_reg (ip,
1694 ((prev_insn.insn_opcode >> OP_SH_RT)
1699 else if (! mips_opts.mips16
1700 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1701 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1702 && ! cop_interlocks)
1703 || (mips_opts.isa == ISA_MIPS1
1704 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1706 /* A generic coprocessor delay. The previous instruction
1707 modified a coprocessor general or control register. If
1708 it modified a control register, we need to avoid any
1709 coprocessor instruction (this is probably not always
1710 required, but it sometimes is). If it modified a general
1711 register, we avoid using that register.
1713 On the r6000 and r4000 loading a coprocessor register
1714 from memory is interlocked, and does not require a delay.
1716 This case is not handled very well. There is no special
1717 knowledge of CP0 handling, and the coprocessors other
1718 than the floating point unit are not distinguished at
1720 /* Itbl support may require additional care here. FIXME!
1721 Need to modify this to include knowledge about
1722 user specified delays! */
1723 if (prev_pinfo & INSN_WRITE_FPR_T)
1725 if (mips_optimize == 0
1726 || insn_uses_reg (ip,
1727 ((prev_insn.insn_opcode >> OP_SH_FT)
1732 else if (prev_pinfo & INSN_WRITE_FPR_S)
1734 if (mips_optimize == 0
1735 || insn_uses_reg (ip,
1736 ((prev_insn.insn_opcode >> OP_SH_FS)
1743 /* We don't know exactly what the previous instruction
1744 does. If the current instruction uses a coprocessor
1745 register, we must insert a NOP. If previous
1746 instruction may set the condition codes, and the
1747 current instruction uses them, we must insert two
1749 /* Itbl support may require additional care here. */
1750 if (mips_optimize == 0
1751 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1752 && (pinfo & INSN_READ_COND_CODE)))
1754 else if (pinfo & INSN_COP)
1758 else if (! mips_opts.mips16
1759 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1760 && (prev_pinfo & INSN_WRITE_COND_CODE)
1761 && ! cop_interlocks)
1763 /* The previous instruction sets the coprocessor condition
1764 codes, but does not require a general coprocessor delay
1765 (this means it is a floating point comparison
1766 instruction). If this instruction uses the condition
1767 codes, we need to insert a single NOP. */
1768 /* Itbl support may require additional care here. */
1769 if (mips_optimize == 0
1770 || (pinfo & INSN_READ_COND_CODE))
1774 /* If we're fixing up mfhi/mflo for the r7000 and the
1775 previous insn was an mfhi/mflo and the current insn
1776 reads the register that the mfhi/mflo wrote to, then
1779 else if (mips_7000_hilo_fix
1780 && MF_HILO_INSN (prev_pinfo)
1781 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1788 /* If we're fixing up mfhi/mflo for the r7000 and the
1789 2nd previous insn was an mfhi/mflo and the current insn
1790 reads the register that the mfhi/mflo wrote to, then
1793 else if (mips_7000_hilo_fix
1794 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1795 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1803 else if (prev_pinfo & INSN_READ_LO)
1805 /* The previous instruction reads the LO register; if the
1806 current instruction writes to the LO register, we must
1807 insert two NOPS. Some newer processors have interlocks.
1808 Also the tx39's multiply instructions can be exectuted
1809 immediatly after a read from HI/LO (without the delay),
1810 though the tx39's divide insns still do require the
1812 if (! (hilo_interlocks
1813 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1814 && (mips_optimize == 0
1815 || (pinfo & INSN_WRITE_LO)))
1817 /* Most mips16 branch insns don't have a delay slot.
1818 If a read from LO is immediately followed by a branch
1819 to a write to LO we have a read followed by a write
1820 less than 2 insns away. We assume the target of
1821 a branch might be a write to LO, and insert a nop
1822 between a read and an immediately following branch. */
1823 else if (mips_opts.mips16
1824 && (mips_optimize == 0
1825 || (pinfo & MIPS16_INSN_BRANCH)))
1828 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1830 /* The previous instruction reads the HI register; if the
1831 current instruction writes to the HI register, we must
1832 insert a NOP. Some newer processors have interlocks.
1833 Also the note tx39's multiply above. */
1834 if (! (hilo_interlocks
1835 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1836 && (mips_optimize == 0
1837 || (pinfo & INSN_WRITE_HI)))
1839 /* Most mips16 branch insns don't have a delay slot.
1840 If a read from HI is immediately followed by a branch
1841 to a write to HI we have a read followed by a write
1842 less than 2 insns away. We assume the target of
1843 a branch might be a write to HI, and insert a nop
1844 between a read and an immediately following branch. */
1845 else if (mips_opts.mips16
1846 && (mips_optimize == 0
1847 || (pinfo & MIPS16_INSN_BRANCH)))
1851 /* If the previous instruction was in a noreorder section, then
1852 we don't want to insert the nop after all. */
1853 /* Itbl support may require additional care here. */
1854 if (prev_insn_unreordered)
1857 /* There are two cases which require two intervening
1858 instructions: 1) setting the condition codes using a move to
1859 coprocessor instruction which requires a general coprocessor
1860 delay and then reading the condition codes 2) reading the HI
1861 or LO register and then writing to it (except on processors
1862 which have interlocks). If we are not already emitting a NOP
1863 instruction, we must check for these cases compared to the
1864 instruction previous to the previous instruction. */
1865 if ((! mips_opts.mips16
1866 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1867 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1868 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1869 && (pinfo & INSN_READ_COND_CODE)
1870 && ! cop_interlocks)
1871 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1872 && (pinfo & INSN_WRITE_LO)
1873 && ! (hilo_interlocks
1874 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1875 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1876 && (pinfo & INSN_WRITE_HI)
1877 && ! (hilo_interlocks
1878 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1883 if (prev_prev_insn_unreordered)
1886 if (prev_prev_nop && nops == 0)
1889 /* If we are being given a nop instruction, don't bother with
1890 one of the nops we would otherwise output. This will only
1891 happen when a nop instruction is used with mips_optimize set
1894 && ! mips_opts.noreorder
1895 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1898 /* Now emit the right number of NOP instructions. */
1899 if (nops > 0 && ! mips_opts.noreorder)
1902 unsigned long old_frag_offset;
1904 struct insn_label_list *l;
1906 old_frag = frag_now;
1907 old_frag_offset = frag_now_fix ();
1909 for (i = 0; i < nops; i++)
1914 listing_prev_line ();
1915 /* We may be at the start of a variant frag. In case we
1916 are, make sure there is enough space for the frag
1917 after the frags created by listing_prev_line. The
1918 argument to frag_grow here must be at least as large
1919 as the argument to all other calls to frag_grow in
1920 this file. We don't have to worry about being in the
1921 middle of a variant frag, because the variants insert
1922 all needed nop instructions themselves. */
1926 for (l = insn_labels; l != NULL; l = l->next)
1930 assert (S_GET_SEGMENT (l->label) == now_seg);
1931 symbol_set_frag (l->label, frag_now);
1932 val = (valueT) frag_now_fix ();
1933 /* mips16 text labels are stored as odd. */
1934 if (mips_opts.mips16)
1936 S_SET_VALUE (l->label, val);
1939 #ifndef NO_ECOFF_DEBUGGING
1940 if (ECOFF_DEBUGGING)
1941 ecoff_fix_loc (old_frag, old_frag_offset);
1944 else if (prev_nop_frag != NULL)
1946 /* We have a frag holding nops we may be able to remove. If
1947 we don't need any nops, we can decrease the size of
1948 prev_nop_frag by the size of one instruction. If we do
1949 need some nops, we count them in prev_nops_required. */
1950 if (prev_nop_frag_since == 0)
1954 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1955 --prev_nop_frag_holds;
1958 prev_nop_frag_required += nops;
1962 if (prev_prev_nop == 0)
1964 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1965 --prev_nop_frag_holds;
1968 ++prev_nop_frag_required;
1971 if (prev_nop_frag_holds <= prev_nop_frag_required)
1972 prev_nop_frag = NULL;
1974 ++prev_nop_frag_since;
1976 /* Sanity check: by the time we reach the second instruction
1977 after prev_nop_frag, we should have used up all the nops
1978 one way or another. */
1979 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1983 if (*reloc_type > BFD_RELOC_UNUSED)
1985 /* We need to set up a variant frag. */
1986 assert (mips_opts.mips16 && address_expr != NULL);
1987 f = frag_var (rs_machine_dependent, 4, 0,
1988 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
1989 mips16_small, mips16_ext,
1991 & INSN_UNCOND_BRANCH_DELAY),
1992 (*prev_insn_reloc_type
1993 == BFD_RELOC_MIPS16_JMP)),
1994 make_expr_symbol (address_expr), 0, NULL);
1996 else if (place != NULL)
1998 else if (mips_opts.mips16
2000 && *reloc_type != BFD_RELOC_MIPS16_JMP)
2002 /* Make sure there is enough room to swap this instruction with
2003 a following jump instruction. */
2009 if (mips_opts.mips16
2010 && mips_opts.noreorder
2011 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
2012 as_warn (_("extended instruction in delay slot"));
2017 fixp[0] = fixp[1] = fixp[2] = NULL;
2018 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
2020 if (address_expr->X_op == O_constant)
2024 switch (*reloc_type)
2027 ip->insn_opcode |= address_expr->X_add_number;
2030 case BFD_RELOC_MIPS_HIGHEST:
2031 tmp = (address_expr->X_add_number + 0x800080008000) >> 16;
2033 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2036 case BFD_RELOC_MIPS_HIGHER:
2037 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
2038 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2041 case BFD_RELOC_HI16_S:
2042 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
2046 case BFD_RELOC_HI16:
2047 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2050 case BFD_RELOC_LO16:
2051 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2054 case BFD_RELOC_MIPS_JMP:
2055 if ((address_expr->X_add_number & 3) != 0)
2056 as_bad (_("jump to misaligned address (0x%lx)"),
2057 (unsigned long) address_expr->X_add_number);
2058 if (address_expr->X_add_number & ~0xfffffff
2059 || address_expr->X_add_number > 0x7fffffc)
2060 as_bad (_("jump address range overflow (0x%lx)"),
2061 (unsigned long) address_expr->X_add_number);
2062 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2065 case BFD_RELOC_MIPS16_JMP:
2066 if ((address_expr->X_add_number & 3) != 0)
2067 as_bad (_("jump to misaligned address (0x%lx)"),
2068 (unsigned long) address_expr->X_add_number);
2069 if (address_expr->X_add_number & ~0xfffffff
2070 || address_expr->X_add_number > 0x7fffffc)
2071 as_bad (_("jump address range overflow (0x%lx)"),
2072 (unsigned long) address_expr->X_add_number);
2074 (((address_expr->X_add_number & 0x7c0000) << 3)
2075 | ((address_expr->X_add_number & 0xf800000) >> 7)
2076 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2079 case BFD_RELOC_16_PCREL:
2080 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2083 case BFD_RELOC_16_PCREL_S2:
2093 /* Don't generate a reloc if we are writing into a variant frag. */
2096 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
2098 (*reloc_type == BFD_RELOC_16_PCREL
2099 || *reloc_type == BFD_RELOC_16_PCREL_S2),
2102 /* These relocations can have an addend that won't fit in
2103 4 octets for 64bit assembly. */
2104 if (HAVE_64BIT_GPRS &&
2105 (*reloc_type == BFD_RELOC_16
2106 || *reloc_type == BFD_RELOC_32
2107 || *reloc_type == BFD_RELOC_MIPS_JMP
2108 || *reloc_type == BFD_RELOC_HI16_S
2109 || *reloc_type == BFD_RELOC_LO16
2110 || *reloc_type == BFD_RELOC_GPREL16
2111 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2112 || *reloc_type == BFD_RELOC_GPREL32
2113 || *reloc_type == BFD_RELOC_64
2114 || *reloc_type == BFD_RELOC_CTOR
2115 || *reloc_type == BFD_RELOC_MIPS_SUB
2116 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2117 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2118 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2119 || *reloc_type == BFD_RELOC_MIPS_REL16
2120 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2121 fixp[0]->fx_no_overflow = 1;
2125 struct mips_hi_fixup *hi_fixup;
2127 assert (*reloc_type == BFD_RELOC_HI16_S);
2128 hi_fixup = ((struct mips_hi_fixup *)
2129 xmalloc (sizeof (struct mips_hi_fixup)));
2130 hi_fixup->fixp = fixp[0];
2131 hi_fixup->seg = now_seg;
2132 hi_fixup->next = mips_hi_fixup_list;
2133 mips_hi_fixup_list = hi_fixup;
2136 if (reloc_type[1] != BFD_RELOC_UNUSED)
2138 /* FIXME: This symbol can be one of
2139 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
2140 address_expr->X_op = O_absent;
2141 address_expr->X_add_symbol = 0;
2142 address_expr->X_add_number = 0;
2144 fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal,
2145 4, address_expr, false,
2148 /* These relocations can have an addend that won't fit in
2149 4 octets for 64bit assembly. */
2150 if (HAVE_64BIT_GPRS &&
2151 (*reloc_type == BFD_RELOC_16
2152 || *reloc_type == BFD_RELOC_32
2153 || *reloc_type == BFD_RELOC_MIPS_JMP
2154 || *reloc_type == BFD_RELOC_HI16_S
2155 || *reloc_type == BFD_RELOC_LO16
2156 || *reloc_type == BFD_RELOC_GPREL16
2157 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2158 || *reloc_type == BFD_RELOC_GPREL32
2159 || *reloc_type == BFD_RELOC_64
2160 || *reloc_type == BFD_RELOC_CTOR
2161 || *reloc_type == BFD_RELOC_MIPS_SUB
2162 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2163 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2164 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2165 || *reloc_type == BFD_RELOC_MIPS_REL16
2166 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2167 fixp[1]->fx_no_overflow = 1;
2169 if (reloc_type[2] != BFD_RELOC_UNUSED)
2171 address_expr->X_op = O_absent;
2172 address_expr->X_add_symbol = 0;
2173 address_expr->X_add_number = 0;
2175 fixp[2] = fix_new_exp (frag_now,
2176 f - frag_now->fr_literal, 4,
2177 address_expr, false,
2180 /* These relocations can have an addend that won't fit in
2181 4 octets for 64bit assembly. */
2182 if (HAVE_64BIT_GPRS &&
2183 (*reloc_type == BFD_RELOC_16
2184 || *reloc_type == BFD_RELOC_32
2185 || *reloc_type == BFD_RELOC_MIPS_JMP
2186 || *reloc_type == BFD_RELOC_HI16_S
2187 || *reloc_type == BFD_RELOC_LO16
2188 || *reloc_type == BFD_RELOC_GPREL16
2189 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2190 || *reloc_type == BFD_RELOC_GPREL32
2191 || *reloc_type == BFD_RELOC_64
2192 || *reloc_type == BFD_RELOC_CTOR
2193 || *reloc_type == BFD_RELOC_MIPS_SUB
2194 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2195 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2196 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2197 || *reloc_type == BFD_RELOC_MIPS_REL16
2198 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2199 fixp[2]->fx_no_overflow = 1;
2206 if (! mips_opts.mips16)
2207 md_number_to_chars (f, ip->insn_opcode, 4);
2208 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2210 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2211 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2217 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2220 md_number_to_chars (f, ip->insn_opcode, 2);
2223 /* Update the register mask information. */
2224 if (! mips_opts.mips16)
2226 if (pinfo & INSN_WRITE_GPR_D)
2227 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2228 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2229 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2230 if (pinfo & INSN_READ_GPR_S)
2231 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2232 if (pinfo & INSN_WRITE_GPR_31)
2233 mips_gprmask |= 1 << 31;
2234 if (pinfo & INSN_WRITE_FPR_D)
2235 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2236 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2237 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2238 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2239 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2240 if ((pinfo & INSN_READ_FPR_R) != 0)
2241 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2242 if (pinfo & INSN_COP)
2244 /* We don't keep enough information to sort these cases out.
2245 The itbl support does keep this information however, although
2246 we currently don't support itbl fprmats as part of the cop
2247 instruction. May want to add this support in the future. */
2249 /* Never set the bit for $0, which is always zero. */
2250 mips_gprmask &= ~1 << 0;
2254 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2255 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2256 & MIPS16OP_MASK_RX);
2257 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2258 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2259 & MIPS16OP_MASK_RY);
2260 if (pinfo & MIPS16_INSN_WRITE_Z)
2261 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2262 & MIPS16OP_MASK_RZ);
2263 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2264 mips_gprmask |= 1 << TREG;
2265 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2266 mips_gprmask |= 1 << SP;
2267 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2268 mips_gprmask |= 1 << RA;
2269 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2270 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2271 if (pinfo & MIPS16_INSN_READ_Z)
2272 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2273 & MIPS16OP_MASK_MOVE32Z);
2274 if (pinfo & MIPS16_INSN_READ_GPR_X)
2275 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2276 & MIPS16OP_MASK_REGR32);
2279 if (place == NULL && ! mips_opts.noreorder)
2281 /* Filling the branch delay slot is more complex. We try to
2282 switch the branch with the previous instruction, which we can
2283 do if the previous instruction does not set up a condition
2284 that the branch tests and if the branch is not itself the
2285 target of any branch. */
2286 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2287 || (pinfo & INSN_COND_BRANCH_DELAY))
2289 if (mips_optimize < 2
2290 /* If we have seen .set volatile or .set nomove, don't
2292 || mips_opts.nomove != 0
2293 /* If we had to emit any NOP instructions, then we
2294 already know we can not swap. */
2296 /* If we don't even know the previous insn, we can not
2298 || ! prev_insn_valid
2299 /* If the previous insn is already in a branch delay
2300 slot, then we can not swap. */
2301 || prev_insn_is_delay_slot
2302 /* If the previous previous insn was in a .set
2303 noreorder, we can't swap. Actually, the MIPS
2304 assembler will swap in this situation. However, gcc
2305 configured -with-gnu-as will generate code like
2311 in which we can not swap the bne and INSN. If gcc is
2312 not configured -with-gnu-as, it does not output the
2313 .set pseudo-ops. We don't have to check
2314 prev_insn_unreordered, because prev_insn_valid will
2315 be 0 in that case. We don't want to use
2316 prev_prev_insn_valid, because we do want to be able
2317 to swap at the start of a function. */
2318 || prev_prev_insn_unreordered
2319 /* If the branch is itself the target of a branch, we
2320 can not swap. We cheat on this; all we check for is
2321 whether there is a label on this instruction. If
2322 there are any branches to anything other than a
2323 label, users must use .set noreorder. */
2324 || insn_labels != NULL
2325 /* If the previous instruction is in a variant frag, we
2326 can not do the swap. This does not apply to the
2327 mips16, which uses variant frags for different
2329 || (! mips_opts.mips16
2330 && prev_insn_frag->fr_type == rs_machine_dependent)
2331 /* If the branch reads the condition codes, we don't
2332 even try to swap, because in the sequence
2337 we can not swap, and I don't feel like handling that
2339 || (! mips_opts.mips16
2340 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2341 && (pinfo & INSN_READ_COND_CODE))
2342 /* We can not swap with an instruction that requires a
2343 delay slot, becase the target of the branch might
2344 interfere with that instruction. */
2345 || (! mips_opts.mips16
2346 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2348 /* Itbl support may require additional care here. */
2349 & (INSN_LOAD_COPROC_DELAY
2350 | INSN_COPROC_MOVE_DELAY
2351 | INSN_WRITE_COND_CODE)))
2352 || (! (hilo_interlocks
2353 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2357 || (! mips_opts.mips16
2359 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2360 || (! mips_opts.mips16
2361 && mips_opts.isa == ISA_MIPS1
2362 /* Itbl support may require additional care here. */
2363 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2364 /* We can not swap with a branch instruction. */
2366 & (INSN_UNCOND_BRANCH_DELAY
2367 | INSN_COND_BRANCH_DELAY
2368 | INSN_COND_BRANCH_LIKELY))
2369 /* We do not swap with a trap instruction, since it
2370 complicates trap handlers to have the trap
2371 instruction be in a delay slot. */
2372 || (prev_pinfo & INSN_TRAP)
2373 /* If the branch reads a register that the previous
2374 instruction sets, we can not swap. */
2375 || (! mips_opts.mips16
2376 && (prev_pinfo & INSN_WRITE_GPR_T)
2377 && insn_uses_reg (ip,
2378 ((prev_insn.insn_opcode >> OP_SH_RT)
2381 || (! mips_opts.mips16
2382 && (prev_pinfo & INSN_WRITE_GPR_D)
2383 && insn_uses_reg (ip,
2384 ((prev_insn.insn_opcode >> OP_SH_RD)
2387 || (mips_opts.mips16
2388 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2389 && insn_uses_reg (ip,
2390 ((prev_insn.insn_opcode
2392 & MIPS16OP_MASK_RX),
2394 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2395 && insn_uses_reg (ip,
2396 ((prev_insn.insn_opcode
2398 & MIPS16OP_MASK_RY),
2400 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2401 && insn_uses_reg (ip,
2402 ((prev_insn.insn_opcode
2404 & MIPS16OP_MASK_RZ),
2406 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2407 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2408 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2409 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2410 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2411 && insn_uses_reg (ip,
2412 MIPS16OP_EXTRACT_REG32R (prev_insn.
2415 /* If the branch writes a register that the previous
2416 instruction sets, we can not swap (we know that
2417 branches write only to RD or to $31). */
2418 || (! mips_opts.mips16
2419 && (prev_pinfo & INSN_WRITE_GPR_T)
2420 && (((pinfo & INSN_WRITE_GPR_D)
2421 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2422 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2423 || ((pinfo & INSN_WRITE_GPR_31)
2424 && (((prev_insn.insn_opcode >> OP_SH_RT)
2427 || (! mips_opts.mips16
2428 && (prev_pinfo & INSN_WRITE_GPR_D)
2429 && (((pinfo & INSN_WRITE_GPR_D)
2430 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2431 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2432 || ((pinfo & INSN_WRITE_GPR_31)
2433 && (((prev_insn.insn_opcode >> OP_SH_RD)
2436 || (mips_opts.mips16
2437 && (pinfo & MIPS16_INSN_WRITE_31)
2438 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2439 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2440 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2442 /* If the branch writes a register that the previous
2443 instruction reads, we can not swap (we know that
2444 branches only write to RD or to $31). */
2445 || (! mips_opts.mips16
2446 && (pinfo & INSN_WRITE_GPR_D)
2447 && insn_uses_reg (&prev_insn,
2448 ((ip->insn_opcode >> OP_SH_RD)
2451 || (! mips_opts.mips16
2452 && (pinfo & INSN_WRITE_GPR_31)
2453 && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG))
2454 || (mips_opts.mips16
2455 && (pinfo & MIPS16_INSN_WRITE_31)
2456 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2457 /* If we are generating embedded PIC code, the branch
2458 might be expanded into a sequence which uses $at, so
2459 we can't swap with an instruction which reads it. */
2460 || (mips_pic == EMBEDDED_PIC
2461 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2462 /* If the previous previous instruction has a load
2463 delay, and sets a register that the branch reads, we
2465 || (! mips_opts.mips16
2466 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2467 /* Itbl support may require additional care here. */
2468 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2469 || (! gpr_interlocks
2470 && (prev_prev_insn.insn_mo->pinfo
2471 & INSN_LOAD_MEMORY_DELAY)))
2472 && insn_uses_reg (ip,
2473 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2476 /* If one instruction sets a condition code and the
2477 other one uses a condition code, we can not swap. */
2478 || ((pinfo & INSN_READ_COND_CODE)
2479 && (prev_pinfo & INSN_WRITE_COND_CODE))
2480 || ((pinfo & INSN_WRITE_COND_CODE)
2481 && (prev_pinfo & INSN_READ_COND_CODE))
2482 /* If the previous instruction uses the PC, we can not
2484 || (mips_opts.mips16
2485 && (prev_pinfo & MIPS16_INSN_READ_PC))
2486 /* If the previous instruction was extended, we can not
2488 || (mips_opts.mips16 && prev_insn_extended)
2489 /* If the previous instruction had a fixup in mips16
2490 mode, we can not swap. This normally means that the
2491 previous instruction was a 4 byte branch anyhow. */
2492 || (mips_opts.mips16 && prev_insn_fixp[0])
2493 /* If the previous instruction is a sync, sync.l, or
2494 sync.p, we can not swap. */
2495 || (prev_pinfo & INSN_SYNC))
2497 /* We could do even better for unconditional branches to
2498 portions of this object file; we could pick up the
2499 instruction at the destination, put it in the delay
2500 slot, and bump the destination address. */
2502 /* Update the previous insn information. */
2503 prev_prev_insn = *ip;
2504 prev_insn.insn_mo = &dummy_opcode;
2508 /* It looks like we can actually do the swap. */
2509 if (! mips_opts.mips16)
2514 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2515 memcpy (temp, prev_f, 4);
2516 memcpy (prev_f, f, 4);
2517 memcpy (f, temp, 4);
2518 if (prev_insn_fixp[0])
2520 prev_insn_fixp[0]->fx_frag = frag_now;
2521 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2523 if (prev_insn_fixp[1])
2525 prev_insn_fixp[1]->fx_frag = frag_now;
2526 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2528 if (prev_insn_fixp[2])
2530 prev_insn_fixp[2]->fx_frag = frag_now;
2531 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2535 fixp[0]->fx_frag = prev_insn_frag;
2536 fixp[0]->fx_where = prev_insn_where;
2540 fixp[1]->fx_frag = prev_insn_frag;
2541 fixp[1]->fx_where = prev_insn_where;
2545 fixp[2]->fx_frag = prev_insn_frag;
2546 fixp[2]->fx_where = prev_insn_where;
2554 assert (prev_insn_fixp[0] == NULL);
2555 assert (prev_insn_fixp[1] == NULL);
2556 assert (prev_insn_fixp[2] == NULL);
2557 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2558 memcpy (temp, prev_f, 2);
2559 memcpy (prev_f, f, 2);
2560 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2562 assert (*reloc_type == BFD_RELOC_UNUSED);
2563 memcpy (f, temp, 2);
2567 memcpy (f, f + 2, 2);
2568 memcpy (f + 2, temp, 2);
2572 fixp[0]->fx_frag = prev_insn_frag;
2573 fixp[0]->fx_where = prev_insn_where;
2577 fixp[1]->fx_frag = prev_insn_frag;
2578 fixp[1]->fx_where = prev_insn_where;
2582 fixp[2]->fx_frag = prev_insn_frag;
2583 fixp[2]->fx_where = prev_insn_where;
2587 /* Update the previous insn information; leave prev_insn
2589 prev_prev_insn = *ip;
2591 prev_insn_is_delay_slot = 1;
2593 /* If that was an unconditional branch, forget the previous
2594 insn information. */
2595 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2597 prev_prev_insn.insn_mo = &dummy_opcode;
2598 prev_insn.insn_mo = &dummy_opcode;
2601 prev_insn_fixp[0] = NULL;
2602 prev_insn_fixp[1] = NULL;
2603 prev_insn_fixp[2] = NULL;
2604 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2605 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2606 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2607 prev_insn_extended = 0;
2609 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2611 /* We don't yet optimize a branch likely. What we should do
2612 is look at the target, copy the instruction found there
2613 into the delay slot, and increment the branch to jump to
2614 the next instruction. */
2616 /* Update the previous insn information. */
2617 prev_prev_insn = *ip;
2618 prev_insn.insn_mo = &dummy_opcode;
2619 prev_insn_fixp[0] = NULL;
2620 prev_insn_fixp[1] = NULL;
2621 prev_insn_fixp[2] = NULL;
2622 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2623 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2624 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2625 prev_insn_extended = 0;
2629 /* Update the previous insn information. */
2631 prev_prev_insn.insn_mo = &dummy_opcode;
2633 prev_prev_insn = prev_insn;
2636 /* Any time we see a branch, we always fill the delay slot
2637 immediately; since this insn is not a branch, we know it
2638 is not in a delay slot. */
2639 prev_insn_is_delay_slot = 0;
2641 prev_insn_fixp[0] = fixp[0];
2642 prev_insn_fixp[1] = fixp[1];
2643 prev_insn_fixp[2] = fixp[2];
2644 prev_insn_reloc_type[0] = reloc_type[0];
2645 prev_insn_reloc_type[1] = reloc_type[1];
2646 prev_insn_reloc_type[2] = reloc_type[2];
2647 if (mips_opts.mips16)
2648 prev_insn_extended = (ip->use_extend
2649 || *reloc_type > BFD_RELOC_UNUSED);
2652 prev_prev_insn_unreordered = prev_insn_unreordered;
2653 prev_insn_unreordered = 0;
2654 prev_insn_frag = frag_now;
2655 prev_insn_where = f - frag_now->fr_literal;
2656 prev_insn_valid = 1;
2658 else if (place == NULL)
2660 /* We need to record a bit of information even when we are not
2661 reordering, in order to determine the base address for mips16
2662 PC relative relocs. */
2663 prev_prev_insn = prev_insn;
2665 prev_insn_reloc_type[0] = reloc_type[0];
2666 prev_insn_reloc_type[1] = reloc_type[1];
2667 prev_insn_reloc_type[2] = reloc_type[2];
2668 prev_prev_insn_unreordered = prev_insn_unreordered;
2669 prev_insn_unreordered = 1;
2672 /* We just output an insn, so the next one doesn't have a label. */
2673 mips_clear_insn_labels ();
2675 /* We must ensure that a fixup associated with an unmatched %hi
2676 reloc does not become a variant frag. Otherwise, the
2677 rearrangement of %hi relocs in frob_file may confuse
2681 frag_wane (frag_now);
2686 /* This function forgets that there was any previous instruction or
2687 label. If PRESERVE is non-zero, it remembers enough information to
2688 know whether nops are needed before a noreorder section. */
2691 mips_no_prev_insn (preserve)
2696 prev_insn.insn_mo = &dummy_opcode;
2697 prev_prev_insn.insn_mo = &dummy_opcode;
2698 prev_nop_frag = NULL;
2699 prev_nop_frag_holds = 0;
2700 prev_nop_frag_required = 0;
2701 prev_nop_frag_since = 0;
2703 prev_insn_valid = 0;
2704 prev_insn_is_delay_slot = 0;
2705 prev_insn_unreordered = 0;
2706 prev_insn_extended = 0;
2707 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2708 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2709 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2710 prev_prev_insn_unreordered = 0;
2711 mips_clear_insn_labels ();
2714 /* This function must be called whenever we turn on noreorder or emit
2715 something other than instructions. It inserts any NOPS which might
2716 be needed by the previous instruction, and clears the information
2717 kept for the previous instructions. The INSNS parameter is true if
2718 instructions are to follow. */
2721 mips_emit_delays (insns)
2724 if (! mips_opts.noreorder)
2729 if ((! mips_opts.mips16
2730 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2731 && (! cop_interlocks
2732 && (prev_insn.insn_mo->pinfo
2733 & (INSN_LOAD_COPROC_DELAY
2734 | INSN_COPROC_MOVE_DELAY
2735 | INSN_WRITE_COND_CODE))))
2736 || (! hilo_interlocks
2737 && (prev_insn.insn_mo->pinfo
2740 || (! mips_opts.mips16
2742 && (prev_insn.insn_mo->pinfo
2743 & INSN_LOAD_MEMORY_DELAY))
2744 || (! mips_opts.mips16
2745 && mips_opts.isa == ISA_MIPS1
2746 && (prev_insn.insn_mo->pinfo
2747 & INSN_COPROC_MEMORY_DELAY)))
2749 /* Itbl support may require additional care here. */
2751 if ((! mips_opts.mips16
2752 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2753 && (! cop_interlocks
2754 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2755 || (! hilo_interlocks
2756 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2757 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2760 if (prev_insn_unreordered)
2763 else if ((! mips_opts.mips16
2764 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2765 && (! cop_interlocks
2766 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2767 || (! hilo_interlocks
2768 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2769 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2771 /* Itbl support may require additional care here. */
2772 if (! prev_prev_insn_unreordered)
2778 struct insn_label_list *l;
2782 /* Record the frag which holds the nop instructions, so
2783 that we can remove them if we don't need them. */
2784 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2785 prev_nop_frag = frag_now;
2786 prev_nop_frag_holds = nops;
2787 prev_nop_frag_required = 0;
2788 prev_nop_frag_since = 0;
2791 for (; nops > 0; --nops)
2796 /* Move on to a new frag, so that it is safe to simply
2797 decrease the size of prev_nop_frag. */
2798 frag_wane (frag_now);
2802 for (l = insn_labels; l != NULL; l = l->next)
2806 assert (S_GET_SEGMENT (l->label) == now_seg);
2807 symbol_set_frag (l->label, frag_now);
2808 val = (valueT) frag_now_fix ();
2809 /* mips16 text labels are stored as odd. */
2810 if (mips_opts.mips16)
2812 S_SET_VALUE (l->label, val);
2817 /* Mark instruction labels in mips16 mode. */
2818 if (mips_opts.mips16 && insns)
2819 mips16_mark_labels ();
2821 mips_no_prev_insn (insns);
2824 /* Build an instruction created by a macro expansion. This is passed
2825 a pointer to the count of instructions created so far, an
2826 expression, the name of the instruction to build, an operand format
2827 string, and corresponding arguments. */
2831 macro_build (char *place,
2839 macro_build (place, counter, ep, name, fmt, va_alist)
2848 struct mips_cl_insn insn;
2849 bfd_reloc_code_real_type r[3];
2853 va_start (args, fmt);
2859 * If the macro is about to expand into a second instruction,
2860 * print a warning if needed. We need to pass ip as a parameter
2861 * to generate a better warning message here...
2863 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2864 as_warn (_("Macro instruction expanded into multiple instructions"));
2867 *counter += 1; /* bump instruction counter */
2869 if (mips_opts.mips16)
2871 mips16_macro_build (place, counter, ep, name, fmt, args);
2876 r[0] = BFD_RELOC_UNUSED;
2877 r[1] = BFD_RELOC_UNUSED;
2878 r[2] = BFD_RELOC_UNUSED;
2879 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2880 assert (insn.insn_mo);
2881 assert (strcmp (name, insn.insn_mo->name) == 0);
2883 /* Search until we get a match for NAME. */
2886 if (strcmp (fmt, insn.insn_mo->args) == 0
2887 && insn.insn_mo->pinfo != INSN_MACRO
2888 && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch)
2889 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2893 assert (insn.insn_mo->name);
2894 assert (strcmp (name, insn.insn_mo->name) == 0);
2897 insn.insn_opcode = insn.insn_mo->match;
2913 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2917 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2922 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2927 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2932 int tmp = va_arg (args, int);
2934 insn.insn_opcode |= tmp << OP_SH_RT;
2935 insn.insn_opcode |= tmp << OP_SH_RD;
2941 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2948 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2952 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2956 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2960 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2964 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2971 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2977 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2978 assert (*r == BFD_RELOC_GPREL16
2979 || *r == BFD_RELOC_MIPS_LITERAL
2980 || *r == BFD_RELOC_MIPS_HIGHER
2981 || *r == BFD_RELOC_HI16_S
2982 || *r == BFD_RELOC_LO16
2983 || *r == BFD_RELOC_MIPS_GOT16
2984 || *r == BFD_RELOC_MIPS_CALL16
2985 || *r == BFD_RELOC_MIPS_GOT_LO16
2986 || *r == BFD_RELOC_MIPS_CALL_LO16
2987 || (ep->X_op == O_subtract
2988 && *r == BFD_RELOC_PCREL_LO16));
2992 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2994 && (ep->X_op == O_constant
2995 || (ep->X_op == O_symbol
2996 && (*r == BFD_RELOC_MIPS_HIGHEST
2997 || *r == BFD_RELOC_HI16_S
2998 || *r == BFD_RELOC_HI16
2999 || *r == BFD_RELOC_GPREL16
3000 || *r == BFD_RELOC_MIPS_GOT_HI16
3001 || *r == BFD_RELOC_MIPS_CALL_HI16))
3002 || (ep->X_op == O_subtract
3003 && *r == BFD_RELOC_PCREL_HI16_S)));
3007 assert (ep != NULL);
3009 * This allows macro() to pass an immediate expression for
3010 * creating short branches without creating a symbol.
3011 * Note that the expression still might come from the assembly
3012 * input, in which case the value is not checked for range nor
3013 * is a relocation entry generated (yuck).
3015 if (ep->X_op == O_constant)
3017 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
3021 if (mips_pic == EMBEDDED_PIC)
3022 *r = BFD_RELOC_16_PCREL_S2;
3024 *r = BFD_RELOC_16_PCREL;
3028 assert (ep != NULL);
3029 *r = BFD_RELOC_MIPS_JMP;
3033 insn.insn_opcode |= va_arg (args, unsigned long);
3042 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3044 append_insn (place, &insn, ep, r, false);
3048 mips16_macro_build (place, counter, ep, name, fmt, args)
3050 int *counter ATTRIBUTE_UNUSED;
3056 struct mips_cl_insn insn;
3057 bfd_reloc_code_real_type r[3]
3058 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3060 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3061 assert (insn.insn_mo);
3062 assert (strcmp (name, insn.insn_mo->name) == 0);
3064 while (strcmp (fmt, insn.insn_mo->args) != 0
3065 || insn.insn_mo->pinfo == INSN_MACRO)
3068 assert (insn.insn_mo->name);
3069 assert (strcmp (name, insn.insn_mo->name) == 0);
3072 insn.insn_opcode = insn.insn_mo->match;
3073 insn.use_extend = false;
3092 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
3097 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
3101 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
3105 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
3115 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
3122 regno = va_arg (args, int);
3123 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3124 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3145 assert (ep != NULL);
3147 if (ep->X_op != O_constant)
3148 *r = BFD_RELOC_UNUSED + c;
3151 mips16_immed (NULL, 0, c, ep->X_add_number, false, false,
3152 false, &insn.insn_opcode, &insn.use_extend,
3155 *r = BFD_RELOC_UNUSED;
3161 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3168 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3170 append_insn (place, &insn, ep, r, false);
3174 * Generate a "lui" instruction.
3177 macro_build_lui (place, counter, ep, regnum)
3183 expressionS high_expr;
3184 struct mips_cl_insn insn;
3185 bfd_reloc_code_real_type r[3]
3186 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3187 CONST char *name = "lui";
3188 CONST char *fmt = "t,u";
3190 assert (! mips_opts.mips16);
3196 high_expr.X_op = O_constant;
3197 high_expr.X_add_number = ep->X_add_number;
3200 if (high_expr.X_op == O_constant)
3202 /* we can compute the instruction now without a relocation entry */
3203 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3205 *r = BFD_RELOC_UNUSED;
3207 else if (! HAVE_NEWABI)
3209 assert (ep->X_op == O_symbol);
3210 /* _gp_disp is a special case, used from s_cpload. */
3211 assert (mips_pic == NO_PIC
3212 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
3213 *r = BFD_RELOC_HI16_S;
3217 * If the macro is about to expand into a second instruction,
3218 * print a warning if needed. We need to pass ip as a parameter
3219 * to generate a better warning message here...
3221 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3222 as_warn (_("Macro instruction expanded into multiple instructions"));
3225 *counter += 1; /* bump instruction counter */
3227 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3228 assert (insn.insn_mo);
3229 assert (strcmp (name, insn.insn_mo->name) == 0);
3230 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3232 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3233 if (*r == BFD_RELOC_UNUSED)
3235 insn.insn_opcode |= high_expr.X_add_number;
3236 append_insn (place, &insn, NULL, r, false);
3239 append_insn (place, &insn, &high_expr, r, false);
3243 * Generates code to set the $at register to true (one)
3244 * if reg is less than the immediate expression.
3247 set_at (counter, reg, unsignedp)
3252 if (imm_expr.X_op == O_constant
3253 && imm_expr.X_add_number >= -0x8000
3254 && imm_expr.X_add_number < 0x8000)
3255 macro_build ((char *) NULL, counter, &imm_expr,
3256 unsignedp ? "sltiu" : "slti",
3257 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
3260 load_register (counter, AT, &imm_expr, 0);
3261 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3262 unsignedp ? "sltu" : "slt",
3263 "d,v,t", AT, reg, AT);
3267 /* Warn if an expression is not a constant. */
3270 check_absolute_expr (ip, ex)
3271 struct mips_cl_insn *ip;
3274 if (ex->X_op == O_big)
3275 as_bad (_("unsupported large constant"));
3276 else if (ex->X_op != O_constant)
3277 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3280 /* Count the leading zeroes by performing a binary chop. This is a
3281 bulky bit of source, but performance is a LOT better for the
3282 majority of values than a simple loop to count the bits:
3283 for (lcnt = 0; (lcnt < 32); lcnt++)
3284 if ((v) & (1 << (31 - lcnt)))
3286 However it is not code size friendly, and the gain will drop a bit
3287 on certain cached systems.
3289 #define COUNT_TOP_ZEROES(v) \
3290 (((v) & ~0xffff) == 0 \
3291 ? ((v) & ~0xff) == 0 \
3292 ? ((v) & ~0xf) == 0 \
3293 ? ((v) & ~0x3) == 0 \
3294 ? ((v) & ~0x1) == 0 \
3299 : ((v) & ~0x7) == 0 \
3302 : ((v) & ~0x3f) == 0 \
3303 ? ((v) & ~0x1f) == 0 \
3306 : ((v) & ~0x7f) == 0 \
3309 : ((v) & ~0xfff) == 0 \
3310 ? ((v) & ~0x3ff) == 0 \
3311 ? ((v) & ~0x1ff) == 0 \
3314 : ((v) & ~0x7ff) == 0 \
3317 : ((v) & ~0x3fff) == 0 \
3318 ? ((v) & ~0x1fff) == 0 \
3321 : ((v) & ~0x7fff) == 0 \
3324 : ((v) & ~0xffffff) == 0 \
3325 ? ((v) & ~0xfffff) == 0 \
3326 ? ((v) & ~0x3ffff) == 0 \
3327 ? ((v) & ~0x1ffff) == 0 \
3330 : ((v) & ~0x7ffff) == 0 \
3333 : ((v) & ~0x3fffff) == 0 \
3334 ? ((v) & ~0x1fffff) == 0 \
3337 : ((v) & ~0x7fffff) == 0 \
3340 : ((v) & ~0xfffffff) == 0 \
3341 ? ((v) & ~0x3ffffff) == 0 \
3342 ? ((v) & ~0x1ffffff) == 0 \
3345 : ((v) & ~0x7ffffff) == 0 \
3348 : ((v) & ~0x3fffffff) == 0 \
3349 ? ((v) & ~0x1fffffff) == 0 \
3352 : ((v) & ~0x7fffffff) == 0 \
3356 /* Is the given value a sign-extended 32-bit value? */
3357 #define IS_SEXT_32BIT_NUM(x) \
3358 (((x) &~ (offsetT) 0x7fffffff) == 0 \
3359 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
3362 * This routine generates the least number of instructions neccessary to load
3363 * an absolute expression value into a register.
3366 load_register (counter, reg, ep, dbl)
3373 expressionS hi32, lo32;
3375 if (ep->X_op != O_big)
3377 assert (ep->X_op == O_constant);
3378 if (ep->X_add_number < 0x8000
3379 && (ep->X_add_number >= 0
3380 || (ep->X_add_number >= -0x8000
3383 || sizeof (ep->X_add_number) > 4))))
3385 /* We can handle 16 bit signed values with an addiu to
3386 $zero. No need to ever use daddiu here, since $zero and
3387 the result are always correct in 32 bit mode. */
3388 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3389 (int) BFD_RELOC_LO16);
3392 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3394 /* We can handle 16 bit unsigned values with an ori to
3396 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3397 (int) BFD_RELOC_LO16);
3400 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)
3403 || sizeof (ep->X_add_number) > 4
3404 || (ep->X_add_number & 0x80000000) == 0))
3405 || ((HAVE_32BIT_GPRS || ! dbl)
3406 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3409 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3410 == ~ (offsetT) 0xffffffff)))
3412 /* 32 bit values require an lui. */
3413 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3414 (int) BFD_RELOC_HI16);
3415 if ((ep->X_add_number & 0xffff) != 0)
3416 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3417 (int) BFD_RELOC_LO16);
3422 /* The value is larger than 32 bits. */
3424 if (HAVE_32BIT_GPRS)
3426 as_bad (_("Number (0x%lx) larger than 32 bits"),
3427 (unsigned long) ep->X_add_number);
3428 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3429 (int) BFD_RELOC_LO16);
3433 if (ep->X_op != O_big)
3436 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3437 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3438 hi32.X_add_number &= 0xffffffff;
3440 lo32.X_add_number &= 0xffffffff;
3444 assert (ep->X_add_number > 2);
3445 if (ep->X_add_number == 3)
3446 generic_bignum[3] = 0;
3447 else if (ep->X_add_number > 4)
3448 as_bad (_("Number larger than 64 bits"));
3449 lo32.X_op = O_constant;
3450 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3451 hi32.X_op = O_constant;
3452 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3455 if (hi32.X_add_number == 0)
3460 unsigned long hi, lo;
3462 if (hi32.X_add_number == (offsetT) 0xffffffff)
3464 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3466 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3467 reg, 0, (int) BFD_RELOC_LO16);
3470 if (lo32.X_add_number & 0x80000000)
3472 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3473 (int) BFD_RELOC_HI16);
3474 if (lo32.X_add_number & 0xffff)
3475 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3476 reg, reg, (int) BFD_RELOC_LO16);
3481 /* Check for 16bit shifted constant. We know that hi32 is
3482 non-zero, so start the mask on the first bit of the hi32
3487 unsigned long himask, lomask;
3491 himask = 0xffff >> (32 - shift);
3492 lomask = (0xffff << shift) & 0xffffffff;
3496 himask = 0xffff << (shift - 32);
3499 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3500 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3504 tmp.X_op = O_constant;
3506 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3507 | (lo32.X_add_number >> shift));
3509 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3510 macro_build ((char *) NULL, counter, &tmp,
3511 "ori", "t,r,i", reg, 0,
3512 (int) BFD_RELOC_LO16);
3513 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3514 (shift >= 32) ? "dsll32" : "dsll",
3516 (shift >= 32) ? shift - 32 : shift);
3521 while (shift <= (64 - 16));
3523 /* Find the bit number of the lowest one bit, and store the
3524 shifted value in hi/lo. */
3525 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3526 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3530 while ((lo & 1) == 0)
3535 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3541 while ((hi & 1) == 0)
3550 /* Optimize if the shifted value is a (power of 2) - 1. */
3551 if ((hi == 0 && ((lo + 1) & lo) == 0)
3552 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3554 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3559 /* This instruction will set the register to be all
3561 tmp.X_op = O_constant;
3562 tmp.X_add_number = (offsetT) -1;
3563 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3564 reg, 0, (int) BFD_RELOC_LO16);
3568 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3569 (bit >= 32) ? "dsll32" : "dsll",
3571 (bit >= 32) ? bit - 32 : bit);
3573 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3574 (shift >= 32) ? "dsrl32" : "dsrl",
3576 (shift >= 32) ? shift - 32 : shift);
3581 /* Sign extend hi32 before calling load_register, because we can
3582 generally get better code when we load a sign extended value. */
3583 if ((hi32.X_add_number & 0x80000000) != 0)
3584 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3585 load_register (counter, reg, &hi32, 0);
3588 if ((lo32.X_add_number & 0xffff0000) == 0)
3592 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3593 "dsll32", "d,w,<", reg, freg, 0);
3601 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3603 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3604 (int) BFD_RELOC_HI16);
3605 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3606 "dsrl32", "d,w,<", reg, reg, 0);
3612 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3613 "d,w,<", reg, freg, 16);
3617 mid16.X_add_number >>= 16;
3618 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3619 freg, (int) BFD_RELOC_LO16);
3620 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3621 "d,w,<", reg, reg, 16);
3624 if ((lo32.X_add_number & 0xffff) != 0)
3625 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3626 (int) BFD_RELOC_LO16);
3629 /* Load an address into a register. */
3632 load_address (counter, reg, ep, dbl, used_at)
3641 if (ep->X_op != O_constant
3642 && ep->X_op != O_symbol)
3644 as_bad (_("expression too complex"));
3645 ep->X_op = O_constant;
3648 if (ep->X_op == O_constant)
3650 load_register (counter, reg, ep, dbl);
3654 if (mips_pic == NO_PIC)
3656 /* If this is a reference to a GP relative symbol, we want
3657 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3659 lui $reg,<sym> (BFD_RELOC_HI16_S)
3660 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3661 If we have an addend, we always use the latter form.
3663 With 64bit address space and a usable $at we want
3664 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3665 lui $at,<sym> (BFD_RELOC_HI16_S)
3666 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3667 daddiu $at,<sym> (BFD_RELOC_LO16)
3671 If $at is already in use, we use an path which is suboptimal
3672 on superscalar processors.
3673 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3674 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3676 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3678 daddiu $reg,<sym> (BFD_RELOC_LO16)
3684 /* We don't do GP optimization for now because RELAX_ENCODE can't
3685 hold the data for such large chunks. */
3689 macro_build (p, counter, ep, "lui", "t,u",
3690 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3691 macro_build (p, counter, ep, "lui", "t,u",
3692 AT, (int) BFD_RELOC_HI16_S);
3693 macro_build (p, counter, ep, "daddiu", "t,r,j",
3694 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3695 macro_build (p, counter, ep, "daddiu", "t,r,j",
3696 AT, AT, (int) BFD_RELOC_LO16);
3697 macro_build (p, counter, (expressionS *) NULL, "dsll32",
3698 "d,w,<", reg, reg, 0);
3699 macro_build (p, counter, (expressionS *) NULL, "dadd",
3700 "d,v,t", reg, reg, AT);
3705 macro_build (p, counter, ep, "lui", "t,u",
3706 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3707 macro_build (p, counter, ep, "daddiu", "t,r,j",
3708 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3709 macro_build (p, counter, (expressionS *) NULL, "dsll",
3710 "d,w,<", reg, reg, 16);
3711 macro_build (p, counter, ep, "daddiu", "t,r,j",
3712 reg, reg, (int) BFD_RELOC_HI16_S);
3713 macro_build (p, counter, (expressionS *) NULL, "dsll",
3714 "d,w,<", reg, reg, 16);
3715 macro_build (p, counter, ep, "daddiu", "t,r,j",
3716 reg, reg, (int) BFD_RELOC_LO16);
3722 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3723 && ! nopic_need_relax (ep->X_add_symbol, 1))
3726 macro_build ((char *) NULL, counter, ep,
3727 dbl ? "daddiu" : "addiu", "t,r,j", reg, GP,
3728 (int) BFD_RELOC_GPREL16);
3729 p = frag_var (rs_machine_dependent, 8, 0,
3730 RELAX_ENCODE (4, 8, 0, 4, 0,
3731 mips_opts.warn_about_macros),
3732 ep->X_add_symbol, 0, NULL);
3734 macro_build_lui (p, counter, ep, reg);
3737 macro_build (p, counter, ep, dbl ? "daddiu" : "addiu",
3738 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3741 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3745 /* If this is a reference to an external symbol, we want
3746 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3748 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3750 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3751 If there is a constant, it must be added in after. */
3752 ex.X_add_number = ep->X_add_number;
3753 ep->X_add_number = 0;
3755 macro_build ((char *) NULL, counter, ep,
3756 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
3757 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3758 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3759 p = frag_var (rs_machine_dependent, 4, 0,
3760 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3761 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3762 macro_build (p, counter, ep,
3763 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3764 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3765 if (ex.X_add_number != 0)
3767 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3768 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3769 ex.X_op = O_constant;
3770 macro_build ((char *) NULL, counter, &ex,
3771 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3772 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3775 else if (mips_pic == SVR4_PIC)
3780 /* This is the large GOT case. If this is a reference to an
3781 external symbol, we want
3782 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3784 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3785 Otherwise, for a reference to a local symbol, we want
3786 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3788 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3789 If there is a constant, it must be added in after. */
3790 ex.X_add_number = ep->X_add_number;
3791 ep->X_add_number = 0;
3792 if (reg_needs_delay (GP))
3797 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3798 (int) BFD_RELOC_MIPS_GOT_HI16);
3799 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3800 dbl ? "daddu" : "addu", "d,v,t", reg, reg, GP);
3801 macro_build ((char *) NULL, counter, ep, dbl ? "ld" : "lw",
3802 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3803 p = frag_var (rs_machine_dependent, 12 + off, 0,
3804 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3805 mips_opts.warn_about_macros),
3806 ep->X_add_symbol, 0, NULL);
3809 /* We need a nop before loading from $gp. This special
3810 check is required because the lui which starts the main
3811 instruction stream does not refer to $gp, and so will not
3812 insert the nop which may be required. */
3813 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3816 macro_build (p, counter, ep, dbl ? "ld" : "lw",
3817 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3819 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3821 macro_build (p, counter, ep, dbl ? "daddiu" : "addiu",
3822 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3823 if (ex.X_add_number != 0)
3825 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3826 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3827 ex.X_op = O_constant;
3828 macro_build ((char *) NULL, counter, &ex, dbl ? "daddiu" : "addiu",
3829 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3832 else if (mips_pic == EMBEDDED_PIC)
3835 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3837 macro_build ((char *) NULL, counter, ep, dbl ? "daddiu" : "addiu",
3838 "t,r,j", reg, GP, (int) BFD_RELOC_GPREL16);
3844 /* Move the contents of register SOURCE into register DEST. */
3847 move_register (counter, dest, source)
3852 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3853 HAVE_32BIT_GPRS ? "addu" : "daddu",
3854 "d,v,t", dest, source, 0);
3859 * This routine implements the seemingly endless macro or synthesized
3860 * instructions and addressing modes in the mips assembly language. Many
3861 * of these macros are simple and are similar to each other. These could
3862 * probably be handled by some kind of table or grammer aproach instead of
3863 * this verbose method. Others are not simple macros but are more like
3864 * optimizing code generation.
3865 * One interesting optimization is when several store macros appear
3866 * consecutivly that would load AT with the upper half of the same address.
3867 * The ensuing load upper instructions are ommited. This implies some kind
3868 * of global optimization. We currently only optimize within a single macro.
3869 * For many of the load and store macros if the address is specified as a
3870 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3871 * first load register 'at' with zero and use it as the base register. The
3872 * mips assembler simply uses register $zero. Just one tiny optimization
3877 struct mips_cl_insn *ip;
3879 register int treg, sreg, dreg, breg;
3895 bfd_reloc_code_real_type r;
3897 int hold_mips_optimize;
3899 assert (! mips_opts.mips16);
3901 treg = (ip->insn_opcode >> 16) & 0x1f;
3902 dreg = (ip->insn_opcode >> 11) & 0x1f;
3903 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3904 mask = ip->insn_mo->mask;
3906 expr1.X_op = O_constant;
3907 expr1.X_op_symbol = NULL;
3908 expr1.X_add_symbol = NULL;
3909 expr1.X_add_number = 1;
3921 mips_emit_delays (true);
3922 ++mips_opts.noreorder;
3923 mips_any_noreorder = 1;
3925 expr1.X_add_number = 8;
3926 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3928 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
3931 move_register (&icnt, dreg, sreg);
3932 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3933 dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
3935 --mips_opts.noreorder;
3956 if (imm_expr.X_op == O_constant
3957 && imm_expr.X_add_number >= -0x8000
3958 && imm_expr.X_add_number < 0x8000)
3960 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3961 (int) BFD_RELOC_LO16);
3964 load_register (&icnt, AT, &imm_expr, dbl);
3965 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3985 if (imm_expr.X_op == O_constant
3986 && imm_expr.X_add_number >= 0
3987 && imm_expr.X_add_number < 0x10000)
3989 if (mask != M_NOR_I)
3990 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
3991 sreg, (int) BFD_RELOC_LO16);
3994 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
3995 treg, sreg, (int) BFD_RELOC_LO16);
3996 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor",
3997 "d,v,t", treg, treg, 0);
4002 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4003 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
4021 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4023 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
4027 load_register (&icnt, AT, &imm_expr, 0);
4028 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
4036 macro_build ((char *) NULL, &icnt, &offset_expr,
4037 likely ? "bgezl" : "bgez", "s,p", sreg);
4042 macro_build ((char *) NULL, &icnt, &offset_expr,
4043 likely ? "blezl" : "blez", "s,p", treg);
4046 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4048 macro_build ((char *) NULL, &icnt, &offset_expr,
4049 likely ? "beql" : "beq", "s,t,p", AT, 0);
4055 /* check for > max integer */
4056 maxnum = 0x7fffffff;
4057 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4064 if (imm_expr.X_op == O_constant
4065 && imm_expr.X_add_number >= maxnum
4066 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4069 /* result is always false */
4073 as_warn (_("Branch %s is always false (nop)"),
4075 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop",
4081 as_warn (_("Branch likely %s is always false"),
4083 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
4088 if (imm_expr.X_op != O_constant)
4089 as_bad (_("Unsupported large constant"));
4090 imm_expr.X_add_number++;
4094 if (mask == M_BGEL_I)
4096 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4098 macro_build ((char *) NULL, &icnt, &offset_expr,
4099 likely ? "bgezl" : "bgez", "s,p", sreg);
4102 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4104 macro_build ((char *) NULL, &icnt, &offset_expr,
4105 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4108 maxnum = 0x7fffffff;
4109 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4116 maxnum = - maxnum - 1;
4117 if (imm_expr.X_op == O_constant
4118 && imm_expr.X_add_number <= maxnum
4119 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4122 /* result is always true */
4123 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4124 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4127 set_at (&icnt, sreg, 0);
4128 macro_build ((char *) NULL, &icnt, &offset_expr,
4129 likely ? "beql" : "beq", "s,t,p", AT, 0);
4139 macro_build ((char *) NULL, &icnt, &offset_expr,
4140 likely ? "beql" : "beq", "s,t,p", 0, treg);
4143 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4144 "d,v,t", AT, sreg, treg);
4145 macro_build ((char *) NULL, &icnt, &offset_expr,
4146 likely ? "beql" : "beq", "s,t,p", AT, 0);
4154 && imm_expr.X_op == O_constant
4155 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4157 if (imm_expr.X_op != O_constant)
4158 as_bad (_("Unsupported large constant"));
4159 imm_expr.X_add_number++;
4163 if (mask == M_BGEUL_I)
4165 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4167 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4169 macro_build ((char *) NULL, &icnt, &offset_expr,
4170 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4173 set_at (&icnt, sreg, 1);
4174 macro_build ((char *) NULL, &icnt, &offset_expr,
4175 likely ? "beql" : "beq", "s,t,p", AT, 0);
4183 macro_build ((char *) NULL, &icnt, &offset_expr,
4184 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4189 macro_build ((char *) NULL, &icnt, &offset_expr,
4190 likely ? "bltzl" : "bltz", "s,p", treg);
4193 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4195 macro_build ((char *) NULL, &icnt, &offset_expr,
4196 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4204 macro_build ((char *) NULL, &icnt, &offset_expr,
4205 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4210 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4211 "d,v,t", AT, treg, sreg);
4212 macro_build ((char *) NULL, &icnt, &offset_expr,
4213 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4221 macro_build ((char *) NULL, &icnt, &offset_expr,
4222 likely ? "blezl" : "blez", "s,p", sreg);
4227 macro_build ((char *) NULL, &icnt, &offset_expr,
4228 likely ? "bgezl" : "bgez", "s,p", treg);
4231 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4233 macro_build ((char *) NULL, &icnt, &offset_expr,
4234 likely ? "beql" : "beq", "s,t,p", AT, 0);
4240 maxnum = 0x7fffffff;
4241 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4248 if (imm_expr.X_op == O_constant
4249 && imm_expr.X_add_number >= maxnum
4250 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4252 if (imm_expr.X_op != O_constant)
4253 as_bad (_("Unsupported large constant"));
4254 imm_expr.X_add_number++;
4258 if (mask == M_BLTL_I)
4260 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4262 macro_build ((char *) NULL, &icnt, &offset_expr,
4263 likely ? "bltzl" : "bltz", "s,p", sreg);
4266 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4268 macro_build ((char *) NULL, &icnt, &offset_expr,
4269 likely ? "blezl" : "blez", "s,p", sreg);
4272 set_at (&icnt, sreg, 0);
4273 macro_build ((char *) NULL, &icnt, &offset_expr,
4274 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4282 macro_build ((char *) NULL, &icnt, &offset_expr,
4283 likely ? "beql" : "beq", "s,t,p", sreg, 0);
4288 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4289 "d,v,t", AT, treg, sreg);
4290 macro_build ((char *) NULL, &icnt, &offset_expr,
4291 likely ? "beql" : "beq", "s,t,p", AT, 0);
4299 && imm_expr.X_op == O_constant
4300 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4302 if (imm_expr.X_op != O_constant)
4303 as_bad (_("Unsupported large constant"));
4304 imm_expr.X_add_number++;
4308 if (mask == M_BLTUL_I)
4310 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4312 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4314 macro_build ((char *) NULL, &icnt, &offset_expr,
4315 likely ? "beql" : "beq",
4319 set_at (&icnt, sreg, 1);
4320 macro_build ((char *) NULL, &icnt, &offset_expr,
4321 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4329 macro_build ((char *) NULL, &icnt, &offset_expr,
4330 likely ? "bltzl" : "bltz", "s,p", sreg);
4335 macro_build ((char *) NULL, &icnt, &offset_expr,
4336 likely ? "bgtzl" : "bgtz", "s,p", treg);
4339 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4341 macro_build ((char *) NULL, &icnt, &offset_expr,
4342 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4352 macro_build ((char *) NULL, &icnt, &offset_expr,
4353 likely ? "bnel" : "bne", "s,t,p", 0, treg);
4356 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4359 macro_build ((char *) NULL, &icnt, &offset_expr,
4360 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4375 as_warn (_("Divide by zero."));
4377 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4380 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4385 mips_emit_delays (true);
4386 ++mips_opts.noreorder;
4387 mips_any_noreorder = 1;
4390 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4392 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4393 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4397 expr1.X_add_number = 8;
4398 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4399 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4400 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4401 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4404 expr1.X_add_number = -1;
4405 macro_build ((char *) NULL, &icnt, &expr1,
4406 dbl ? "daddiu" : "addiu",
4407 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
4408 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4409 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4412 expr1.X_add_number = 1;
4413 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4414 (int) BFD_RELOC_LO16);
4415 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32",
4416 "d,w,<", AT, AT, 31);
4420 expr1.X_add_number = 0x80000000;
4421 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4422 (int) BFD_RELOC_HI16);
4426 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4428 /* We want to close the noreorder block as soon as possible, so
4429 that later insns are available for delay slot filling. */
4430 --mips_opts.noreorder;
4434 expr1.X_add_number = 8;
4435 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4436 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4439 /* We want to close the noreorder block as soon as possible, so
4440 that later insns are available for delay slot filling. */
4441 --mips_opts.noreorder;
4443 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4446 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg);
4485 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4487 as_warn (_("Divide by zero."));
4489 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4492 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4496 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4498 if (strcmp (s2, "mflo") == 0)
4499 move_register (&icnt, dreg, sreg);
4501 move_register (&icnt, dreg, 0);
4504 if (imm_expr.X_op == O_constant
4505 && imm_expr.X_add_number == -1
4506 && s[strlen (s) - 1] != 'u')
4508 if (strcmp (s2, "mflo") == 0)
4510 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4511 dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4514 move_register (&icnt, dreg, 0);
4518 load_register (&icnt, AT, &imm_expr, dbl);
4519 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4521 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4540 mips_emit_delays (true);
4541 ++mips_opts.noreorder;
4542 mips_any_noreorder = 1;
4545 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4547 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4549 /* We want to close the noreorder block as soon as possible, so
4550 that later insns are available for delay slot filling. */
4551 --mips_opts.noreorder;
4555 expr1.X_add_number = 8;
4556 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4557 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4560 /* We want to close the noreorder block as soon as possible, so
4561 that later insns are available for delay slot filling. */
4562 --mips_opts.noreorder;
4563 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4566 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4572 /* Load the address of a symbol into a register. If breg is not
4573 zero, we then add a base register to it. */
4586 /* When generating embedded PIC code, we permit expressions of
4589 la $treg,foo-bar($breg)
4590 where bar is an address in the current section. These are used
4591 when getting the addresses of functions. We don't permit
4592 X_add_number to be non-zero, because if the symbol is
4593 external the relaxing code needs to know that any addend is
4594 purely the offset to X_op_symbol. */
4595 if (mips_pic == EMBEDDED_PIC
4596 && offset_expr.X_op == O_subtract
4597 && (symbol_constant_p (offset_expr.X_op_symbol)
4598 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4599 : (symbol_equated_p (offset_expr.X_op_symbol)
4601 (symbol_get_value_expression (offset_expr.X_op_symbol)
4604 && (offset_expr.X_add_number == 0
4605 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4611 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4612 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4616 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4617 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4618 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4619 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4620 "d,v,t", tempreg, tempreg, breg);
4622 macro_build ((char *) NULL, &icnt, &offset_expr,
4623 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4624 "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16);
4630 if (offset_expr.X_op != O_symbol
4631 && offset_expr.X_op != O_constant)
4633 as_bad (_("expression too complex"));
4634 offset_expr.X_op = O_constant;
4637 if (offset_expr.X_op == O_constant)
4638 load_register (&icnt, tempreg, &offset_expr, dbl);
4639 else if (mips_pic == NO_PIC)
4641 /* If this is a reference to a GP relative symbol, we want
4642 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4644 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4645 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4646 If we have a constant, we need two instructions anyhow,
4647 so we may as well always use the latter form.
4649 With 64bit address space and a usable $at we want
4650 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4651 lui $at,<sym> (BFD_RELOC_HI16_S)
4652 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4653 daddiu $at,<sym> (BFD_RELOC_LO16)
4655 dadd $tempreg,$tempreg,$at
4657 If $at is already in use, we use an path which is suboptimal
4658 on superscalar processors.
4659 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4660 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4662 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4664 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4667 if (HAVE_64BIT_ADDRESSES)
4669 /* We don't do GP optimization for now because RELAX_ENCODE can't
4670 hold the data for such large chunks. */
4674 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4675 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4676 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4677 AT, (int) BFD_RELOC_HI16_S);
4678 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4679 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4680 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4681 AT, AT, (int) BFD_RELOC_LO16);
4682 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
4683 "d,w,<", tempreg, tempreg, 0);
4684 macro_build (p, &icnt, (expressionS *) NULL, "dadd", "d,v,t",
4685 tempreg, tempreg, AT);
4690 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4691 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4692 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4693 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4694 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4695 tempreg, tempreg, 16);
4696 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4697 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
4698 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4699 tempreg, tempreg, 16);
4700 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4701 tempreg, tempreg, (int) BFD_RELOC_LO16);
4706 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4707 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4710 macro_build ((char *) NULL, &icnt, &offset_expr,
4711 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4712 "t,r,j", tempreg, GP, (int) BFD_RELOC_GPREL16);
4713 p = frag_var (rs_machine_dependent, 8, 0,
4714 RELAX_ENCODE (4, 8, 0, 4, 0,
4715 mips_opts.warn_about_macros),
4716 offset_expr.X_add_symbol, 0, NULL);
4718 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4721 macro_build (p, &icnt, &offset_expr,
4722 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4723 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4726 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4728 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4730 /* If this is a reference to an external symbol, and there
4731 is no constant, we want
4732 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4733 or if tempreg is PIC_CALL_REG
4734 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4735 For a local symbol, we want
4736 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4738 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4740 If we have a small constant, and this is a reference to
4741 an external symbol, we want
4742 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4744 addiu $tempreg,$tempreg,<constant>
4745 For a local symbol, we want the same instruction
4746 sequence, but we output a BFD_RELOC_LO16 reloc on the
4749 If we have a large constant, and this is a reference to
4750 an external symbol, we want
4751 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4752 lui $at,<hiconstant>
4753 addiu $at,$at,<loconstant>
4754 addu $tempreg,$tempreg,$at
4755 For a local symbol, we want the same instruction
4756 sequence, but we output a BFD_RELOC_LO16 reloc on the
4757 addiu instruction. */
4758 expr1.X_add_number = offset_expr.X_add_number;
4759 offset_expr.X_add_number = 0;
4761 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4762 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4763 macro_build ((char *) NULL, &icnt, &offset_expr, dbl ? "ld" : "lw",
4764 "t,o(b)", tempreg, lw_reloc_type, GP);
4765 if (expr1.X_add_number == 0)
4773 /* We're going to put in an addu instruction using
4774 tempreg, so we may as well insert the nop right
4776 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4780 p = frag_var (rs_machine_dependent, 8 - off, 0,
4781 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4783 ? mips_opts.warn_about_macros
4785 offset_expr.X_add_symbol, 0, NULL);
4788 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4791 macro_build (p, &icnt, &expr1,
4792 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4793 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4794 /* FIXME: If breg == 0, and the next instruction uses
4795 $tempreg, then if this variant case is used an extra
4796 nop will be generated. */
4798 else if (expr1.X_add_number >= -0x8000
4799 && expr1.X_add_number < 0x8000)
4801 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4803 macro_build ((char *) NULL, &icnt, &expr1,
4804 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4805 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4806 frag_var (rs_machine_dependent, 0, 0,
4807 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4808 offset_expr.X_add_symbol, 0, NULL);
4814 /* If we are going to add in a base register, and the
4815 target register and the base register are the same,
4816 then we are using AT as a temporary register. Since
4817 we want to load the constant into AT, we add our
4818 current AT (from the global offset table) and the
4819 register into the register now, and pretend we were
4820 not using a base register. */
4825 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4827 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4828 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4829 "d,v,t", treg, AT, breg);
4835 /* Set mips_optimize around the lui instruction to avoid
4836 inserting an unnecessary nop after the lw. */
4837 hold_mips_optimize = mips_optimize;
4839 macro_build_lui (NULL, &icnt, &expr1, AT);
4840 mips_optimize = hold_mips_optimize;
4842 macro_build ((char *) NULL, &icnt, &expr1,
4843 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4844 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4845 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4846 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4847 "d,v,t", tempreg, tempreg, AT);
4848 frag_var (rs_machine_dependent, 0, 0,
4849 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4850 offset_expr.X_add_symbol, 0, NULL);
4854 else if (mips_pic == SVR4_PIC)
4857 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
4858 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
4860 /* This is the large GOT case. If this is a reference to an
4861 external symbol, and there is no constant, we want
4862 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4863 addu $tempreg,$tempreg,$gp
4864 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4865 or if tempreg is PIC_CALL_REG
4866 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4867 addu $tempreg,$tempreg,$gp
4868 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4869 For a local symbol, we want
4870 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4872 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4874 If we have a small constant, and this is a reference to
4875 an external symbol, we want
4876 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4877 addu $tempreg,$tempreg,$gp
4878 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4880 addiu $tempreg,$tempreg,<constant>
4881 For a local symbol, we want
4882 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4884 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4886 If we have a large constant, and this is a reference to
4887 an external symbol, we want
4888 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4889 addu $tempreg,$tempreg,$gp
4890 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4891 lui $at,<hiconstant>
4892 addiu $at,$at,<loconstant>
4893 addu $tempreg,$tempreg,$at
4894 For a local symbol, we want
4895 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4896 lui $at,<hiconstant>
4897 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4898 addu $tempreg,$tempreg,$at
4900 expr1.X_add_number = offset_expr.X_add_number;
4901 offset_expr.X_add_number = 0;
4903 if (reg_needs_delay (GP))
4907 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4909 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
4910 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
4912 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4913 tempreg, lui_reloc_type);
4914 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4915 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4916 "d,v,t", tempreg, tempreg, GP);
4917 macro_build ((char *) NULL, &icnt, &offset_expr,
4919 "t,o(b)", tempreg, lw_reloc_type, tempreg);
4920 if (expr1.X_add_number == 0)
4928 /* We're going to put in an addu instruction using
4929 tempreg, so we may as well insert the nop right
4931 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4936 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4937 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4940 ? mips_opts.warn_about_macros
4942 offset_expr.X_add_symbol, 0, NULL);
4944 else if (expr1.X_add_number >= -0x8000
4945 && expr1.X_add_number < 0x8000)
4947 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4949 macro_build ((char *) NULL, &icnt, &expr1,
4950 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4951 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4953 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4954 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4956 ? mips_opts.warn_about_macros
4958 offset_expr.X_add_symbol, 0, NULL);
4964 /* If we are going to add in a base register, and the
4965 target register and the base register are the same,
4966 then we are using AT as a temporary register. Since
4967 we want to load the constant into AT, we add our
4968 current AT (from the global offset table) and the
4969 register into the register now, and pretend we were
4970 not using a base register. */
4978 assert (tempreg == AT);
4979 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4981 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4982 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4983 "d,v,t", treg, AT, breg);
4988 /* Set mips_optimize around the lui instruction to avoid
4989 inserting an unnecessary nop after the lw. */
4990 hold_mips_optimize = mips_optimize;
4992 macro_build_lui (NULL, &icnt, &expr1, AT);
4993 mips_optimize = hold_mips_optimize;
4995 macro_build ((char *) NULL, &icnt, &expr1,
4996 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4997 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4998 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4999 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5000 "d,v,t", dreg, dreg, AT);
5002 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
5003 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
5006 ? mips_opts.warn_about_macros
5008 offset_expr.X_add_symbol, 0, NULL);
5015 /* This is needed because this instruction uses $gp, but
5016 the first instruction on the main stream does not. */
5017 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5020 macro_build (p, &icnt, &offset_expr,
5022 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5024 if (expr1.X_add_number >= -0x8000
5025 && expr1.X_add_number < 0x8000)
5027 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5029 macro_build (p, &icnt, &expr1,
5030 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5031 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5032 /* FIXME: If add_number is 0, and there was no base
5033 register, the external symbol case ended with a load,
5034 so if the symbol turns out to not be external, and
5035 the next instruction uses tempreg, an unnecessary nop
5036 will be inserted. */
5042 /* We must add in the base register now, as in the
5043 external symbol case. */
5044 assert (tempreg == AT);
5045 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5047 macro_build (p, &icnt, (expressionS *) NULL,
5048 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5049 "d,v,t", treg, AT, breg);
5052 /* We set breg to 0 because we have arranged to add
5053 it in in both cases. */
5057 macro_build_lui (p, &icnt, &expr1, AT);
5059 macro_build (p, &icnt, &expr1,
5060 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5061 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5063 macro_build (p, &icnt, (expressionS *) NULL,
5064 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5065 "d,v,t", tempreg, tempreg, AT);
5069 else if (mips_pic == EMBEDDED_PIC)
5072 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5074 macro_build ((char *) NULL, &icnt, &offset_expr,
5075 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5076 "t,r,j", tempreg, GP, (int) BFD_RELOC_GPREL16);
5082 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5083 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5084 "d,v,t", treg, tempreg, breg);
5092 /* The j instruction may not be used in PIC code, since it
5093 requires an absolute address. We convert it to a b
5095 if (mips_pic == NO_PIC)
5096 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
5098 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
5101 /* The jal instructions must be handled as macros because when
5102 generating PIC code they expand to multi-instruction
5103 sequences. Normally they are simple instructions. */
5108 if (mips_pic == NO_PIC
5109 || mips_pic == EMBEDDED_PIC)
5110 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5112 else if (mips_pic == SVR4_PIC)
5114 if (sreg != PIC_CALL_REG)
5115 as_warn (_("MIPS PIC call to register other than $25"));
5117 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5121 if (mips_cprestore_offset < 0)
5122 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5125 if (! mips_frame_reg_valid)
5127 as_warn (_("No .frame pseudo-op used in PIC code"));
5128 /* Quiet this warning. */
5129 mips_frame_reg_valid = 1;
5131 if (! mips_cprestore_valid)
5133 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5134 /* Quiet this warning. */
5135 mips_cprestore_valid = 1;
5137 expr1.X_add_number = mips_cprestore_offset;
5138 macro_build ((char *) NULL, &icnt, &expr1,
5139 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5140 GP, (int) BFD_RELOC_LO16, mips_frame_reg);
5150 if (mips_pic == NO_PIC)
5151 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
5152 else if (mips_pic == SVR4_PIC)
5154 /* If this is a reference to an external symbol, and we are
5155 using a small GOT, we want
5156 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5160 lw $gp,cprestore($sp)
5161 The cprestore value is set using the .cprestore
5162 pseudo-op. If we are using a big GOT, we want
5163 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5165 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5169 lw $gp,cprestore($sp)
5170 If the symbol is not external, we want
5171 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5173 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5176 lw $gp,cprestore($sp) */
5180 macro_build ((char *) NULL, &icnt, &offset_expr,
5181 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5182 "t,o(b)", PIC_CALL_REG,
5183 (int) BFD_RELOC_MIPS_CALL16, GP);
5184 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5186 p = frag_var (rs_machine_dependent, 4, 0,
5187 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5188 offset_expr.X_add_symbol, 0, NULL);
5194 if (reg_needs_delay (GP))
5198 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5199 PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16);
5200 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5201 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5202 "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP);
5203 macro_build ((char *) NULL, &icnt, &offset_expr,
5204 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5205 "t,o(b)", PIC_CALL_REG,
5206 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5207 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5209 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5210 RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel,
5212 offset_expr.X_add_symbol, 0, NULL);
5215 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5218 macro_build (p, &icnt, &offset_expr,
5219 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5220 "t,o(b)", PIC_CALL_REG,
5221 (int) BFD_RELOC_MIPS_GOT16, GP);
5223 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5226 macro_build (p, &icnt, &offset_expr,
5227 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5228 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5229 (int) BFD_RELOC_LO16);
5230 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5231 "jalr", "s", PIC_CALL_REG);
5234 if (mips_cprestore_offset < 0)
5235 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5238 if (! mips_frame_reg_valid)
5240 as_warn (_("No .frame pseudo-op used in PIC code"));
5241 /* Quiet this warning. */
5242 mips_frame_reg_valid = 1;
5244 if (! mips_cprestore_valid)
5246 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5247 /* Quiet this warning. */
5248 mips_cprestore_valid = 1;
5250 if (mips_opts.noreorder)
5251 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5253 expr1.X_add_number = mips_cprestore_offset;
5254 macro_build ((char *) NULL, &icnt, &expr1,
5255 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5256 GP, (int) BFD_RELOC_LO16, mips_frame_reg);
5260 else if (mips_pic == EMBEDDED_PIC)
5262 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
5263 /* The linker may expand the call to a longer sequence which
5264 uses $at, so we must break rather than return. */
5289 /* Itbl support may require additional care here. */
5294 /* Itbl support may require additional care here. */
5299 /* Itbl support may require additional care here. */
5304 /* Itbl support may require additional care here. */
5316 if (mips_arch == CPU_R4650)
5318 as_bad (_("opcode not supported on this processor"));
5322 /* Itbl support may require additional care here. */
5327 /* Itbl support may require additional care here. */
5332 /* Itbl support may require additional care here. */
5352 if (breg == treg || coproc || lr)
5374 /* Itbl support may require additional care here. */
5379 /* Itbl support may require additional care here. */
5384 /* Itbl support may require additional care here. */
5389 /* Itbl support may require additional care here. */
5405 if (mips_arch == CPU_R4650)
5407 as_bad (_("opcode not supported on this processor"));
5412 /* Itbl support may require additional care here. */
5416 /* Itbl support may require additional care here. */
5421 /* Itbl support may require additional care here. */
5433 /* Itbl support may require additional care here. */
5434 if (mask == M_LWC1_AB
5435 || mask == M_SWC1_AB
5436 || mask == M_LDC1_AB
5437 || mask == M_SDC1_AB
5446 /* For embedded PIC, we allow loads where the offset is calculated
5447 by subtracting a symbol in the current segment from an unknown
5448 symbol, relative to a base register, e.g.:
5449 <op> $treg, <sym>-<localsym>($breg)
5450 This is used by the compiler for switch statements. */
5451 if (mips_pic == EMBEDDED_PIC
5452 && offset_expr.X_op == O_subtract
5453 && (symbol_constant_p (offset_expr.X_op_symbol)
5454 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5455 : (symbol_equated_p (offset_expr.X_op_symbol)
5457 (symbol_get_value_expression (offset_expr.X_op_symbol)
5461 && (offset_expr.X_add_number == 0
5462 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5464 /* For this case, we output the instructions:
5465 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5466 addiu $tempreg,$tempreg,$breg
5467 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5468 If the relocation would fit entirely in 16 bits, it would be
5470 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5471 instead, but that seems quite difficult. */
5472 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5473 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
5474 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5475 ((bfd_arch_bits_per_address (stdoutput) == 32
5476 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5477 ? "addu" : "daddu"),
5478 "d,v,t", tempreg, tempreg, breg);
5479 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
5480 (int) BFD_RELOC_PCREL_LO16, tempreg);
5486 if (offset_expr.X_op != O_constant
5487 && offset_expr.X_op != O_symbol)
5489 as_bad (_("expression too complex"));
5490 offset_expr.X_op = O_constant;
5493 /* A constant expression in PIC code can be handled just as it
5494 is in non PIC code. */
5495 if (mips_pic == NO_PIC
5496 || offset_expr.X_op == O_constant)
5498 /* If this is a reference to a GP relative symbol, and there
5499 is no base register, we want
5500 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5501 Otherwise, if there is no base register, we want
5502 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5503 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5504 If we have a constant, we need two instructions anyhow,
5505 so we always use the latter form.
5507 If we have a base register, and this is a reference to a
5508 GP relative symbol, we want
5509 addu $tempreg,$breg,$gp
5510 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5512 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5513 addu $tempreg,$tempreg,$breg
5514 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5515 With a constant we always use the latter case.
5517 With 64bit address space and no base register and $at usable,
5519 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5520 lui $at,<sym> (BFD_RELOC_HI16_S)
5521 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5524 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5525 If we have a base register, we want
5526 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5527 lui $at,<sym> (BFD_RELOC_HI16_S)
5528 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5532 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5534 Without $at we can't generate the optimal path for superscalar
5535 processors here since this would require two temporary registers.
5536 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5537 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5539 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5541 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5542 If we have a base register, we want
5543 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5544 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5546 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5548 daddu $tempreg,$tempreg,$breg
5549 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5551 If we have 64-bit addresses, as an optimization, for
5552 addresses which are 32-bit constants (e.g. kseg0/kseg1
5553 addresses) we fall back to the 32-bit address generation
5554 mechanism since it is more efficient. This code should
5555 probably attempt to generate 64-bit constants more
5556 efficiently in general.
5558 if (HAVE_64BIT_ADDRESSES
5559 && !(offset_expr.X_op == O_constant
5560 && IS_SEXT_32BIT_NUM (offset_expr.X_add_number)))
5564 /* We don't do GP optimization for now because RELAX_ENCODE can't
5565 hold the data for such large chunks. */
5569 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5570 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5571 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5572 AT, (int) BFD_RELOC_HI16_S);
5573 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5574 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5576 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5577 "d,v,t", AT, AT, breg);
5578 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
5579 "d,w,<", tempreg, tempreg, 0);
5580 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5581 "d,v,t", tempreg, tempreg, AT);
5582 macro_build (p, &icnt, &offset_expr, s,
5583 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5588 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5589 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5590 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5591 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5592 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5593 "d,w,<", tempreg, tempreg, 16);
5594 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5595 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
5596 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5597 "d,w,<", tempreg, tempreg, 16);
5599 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5600 "d,v,t", tempreg, tempreg, breg);
5601 macro_build (p, &icnt, &offset_expr, s,
5602 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5610 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5611 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5616 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5617 treg, (int) BFD_RELOC_GPREL16, GP);
5618 p = frag_var (rs_machine_dependent, 8, 0,
5619 RELAX_ENCODE (4, 8, 0, 4, 0,
5620 (mips_opts.warn_about_macros
5622 && mips_opts.noat))),
5623 offset_expr.X_add_symbol, 0, NULL);
5626 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5629 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5630 (int) BFD_RELOC_LO16, tempreg);
5634 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5635 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5640 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5641 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5642 "d,v,t", tempreg, breg, GP);
5643 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5644 treg, (int) BFD_RELOC_GPREL16, tempreg);
5645 p = frag_var (rs_machine_dependent, 12, 0,
5646 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5647 offset_expr.X_add_symbol, 0, NULL);
5649 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5652 macro_build (p, &icnt, (expressionS *) NULL,
5653 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5654 "d,v,t", tempreg, tempreg, breg);
5657 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5658 (int) BFD_RELOC_LO16, tempreg);
5661 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5663 /* If this is a reference to an external symbol, we want
5664 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5666 <op> $treg,0($tempreg)
5668 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5670 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5671 <op> $treg,0($tempreg)
5672 If there is a base register, we add it to $tempreg before
5673 the <op>. If there is a constant, we stick it in the
5674 <op> instruction. We don't handle constants larger than
5675 16 bits, because we have no way to load the upper 16 bits
5676 (actually, we could handle them for the subset of cases
5677 in which we are not using $at). */
5678 assert (offset_expr.X_op == O_symbol);
5679 expr1.X_add_number = offset_expr.X_add_number;
5680 offset_expr.X_add_number = 0;
5681 if (expr1.X_add_number < -0x8000
5682 || expr1.X_add_number >= 0x8000)
5683 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5685 macro_build ((char *) NULL, &icnt, &offset_expr,
5686 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5687 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5688 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5689 p = frag_var (rs_machine_dependent, 4, 0,
5690 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5691 offset_expr.X_add_symbol, 0, NULL);
5692 macro_build (p, &icnt, &offset_expr,
5693 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5694 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5696 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5697 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5698 "d,v,t", tempreg, tempreg, breg);
5699 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5700 (int) BFD_RELOC_LO16, tempreg);
5702 else if (mips_pic == SVR4_PIC)
5706 /* If this is a reference to an external symbol, we want
5707 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5708 addu $tempreg,$tempreg,$gp
5709 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5710 <op> $treg,0($tempreg)
5712 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5714 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5715 <op> $treg,0($tempreg)
5716 If there is a base register, we add it to $tempreg before
5717 the <op>. If there is a constant, we stick it in the
5718 <op> instruction. We don't handle constants larger than
5719 16 bits, because we have no way to load the upper 16 bits
5720 (actually, we could handle them for the subset of cases
5721 in which we are not using $at). */
5722 assert (offset_expr.X_op == O_symbol);
5723 expr1.X_add_number = offset_expr.X_add_number;
5724 offset_expr.X_add_number = 0;
5725 if (expr1.X_add_number < -0x8000
5726 || expr1.X_add_number >= 0x8000)
5727 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5728 if (reg_needs_delay (GP))
5733 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5734 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5735 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5736 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5737 "d,v,t", tempreg, tempreg, GP);
5738 macro_build ((char *) NULL, &icnt, &offset_expr,
5739 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5740 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5742 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5743 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5744 offset_expr.X_add_symbol, 0, NULL);
5747 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5750 macro_build (p, &icnt, &offset_expr,
5751 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5752 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5754 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5756 macro_build (p, &icnt, &offset_expr,
5757 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5758 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5760 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5761 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5762 "d,v,t", tempreg, tempreg, breg);
5763 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5764 (int) BFD_RELOC_LO16, tempreg);
5766 else if (mips_pic == EMBEDDED_PIC)
5768 /* If there is no base register, we want
5769 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5770 If there is a base register, we want
5771 addu $tempreg,$breg,$gp
5772 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5774 assert (offset_expr.X_op == O_symbol);
5777 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5778 treg, (int) BFD_RELOC_GPREL16, GP);
5783 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5784 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5785 "d,v,t", tempreg, breg, GP);
5786 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5787 treg, (int) BFD_RELOC_GPREL16, tempreg);
5800 load_register (&icnt, treg, &imm_expr, 0);
5804 load_register (&icnt, treg, &imm_expr, 1);
5808 if (imm_expr.X_op == O_constant)
5810 load_register (&icnt, AT, &imm_expr, 0);
5811 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5812 "mtc1", "t,G", AT, treg);
5817 assert (offset_expr.X_op == O_symbol
5818 && strcmp (segment_name (S_GET_SEGMENT
5819 (offset_expr.X_add_symbol)),
5821 && offset_expr.X_add_number == 0);
5822 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5823 treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5828 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
5829 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
5830 order 32 bits of the value and the low order 32 bits are either
5831 zero or in OFFSET_EXPR. */
5832 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5834 if (HAVE_64BIT_GPRS)
5835 load_register (&icnt, treg, &imm_expr, 1);
5840 if (target_big_endian)
5852 load_register (&icnt, hreg, &imm_expr, 0);
5855 if (offset_expr.X_op == O_absent)
5856 move_register (&icnt, lreg, 0);
5859 assert (offset_expr.X_op == O_constant);
5860 load_register (&icnt, lreg, &offset_expr, 0);
5867 /* We know that sym is in the .rdata section. First we get the
5868 upper 16 bits of the address. */
5869 if (mips_pic == NO_PIC)
5871 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5873 else if (mips_pic == SVR4_PIC)
5875 macro_build ((char *) NULL, &icnt, &offset_expr,
5876 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5877 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5879 else if (mips_pic == EMBEDDED_PIC)
5881 /* For embedded PIC we pick up the entire address off $gp in
5882 a single instruction. */
5883 macro_build ((char *) NULL, &icnt, &offset_expr,
5884 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5885 "t,r,j", AT, GP, (int) BFD_RELOC_GPREL16);
5886 offset_expr.X_op = O_constant;
5887 offset_expr.X_add_number = 0;
5892 /* Now we load the register(s). */
5893 if (HAVE_64BIT_GPRS)
5894 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5895 treg, (int) BFD_RELOC_LO16, AT);
5898 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5899 treg, (int) BFD_RELOC_LO16, AT);
5902 /* FIXME: How in the world do we deal with the possible
5904 offset_expr.X_add_number += 4;
5905 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5906 treg + 1, (int) BFD_RELOC_LO16, AT);
5910 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5911 does not become a variant frag. */
5912 frag_wane (frag_now);
5918 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
5919 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
5920 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
5921 the value and the low order 32 bits are either zero or in
5923 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5925 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
5926 if (HAVE_64BIT_FPRS)
5928 assert (HAVE_64BIT_GPRS);
5929 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5930 "dmtc1", "t,S", AT, treg);
5934 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5935 "mtc1", "t,G", AT, treg + 1);
5936 if (offset_expr.X_op == O_absent)
5937 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5938 "mtc1", "t,G", 0, treg);
5941 assert (offset_expr.X_op == O_constant);
5942 load_register (&icnt, AT, &offset_expr, 0);
5943 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5944 "mtc1", "t,G", AT, treg);
5950 assert (offset_expr.X_op == O_symbol
5951 && offset_expr.X_add_number == 0);
5952 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5953 if (strcmp (s, ".lit8") == 0)
5955 if (mips_opts.isa != ISA_MIPS1)
5957 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5958 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5962 r = BFD_RELOC_MIPS_LITERAL;
5967 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5968 if (mips_pic == SVR4_PIC)
5969 macro_build ((char *) NULL, &icnt, &offset_expr,
5970 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5971 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5974 /* FIXME: This won't work for a 64 bit address. */
5975 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5978 if (mips_opts.isa != ISA_MIPS1)
5980 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5981 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
5983 /* To avoid confusion in tc_gen_reloc, we must ensure
5984 that this does not become a variant frag. */
5985 frag_wane (frag_now);
5996 if (mips_arch == CPU_R4650)
5998 as_bad (_("opcode not supported on this processor"));
6001 /* Even on a big endian machine $fn comes before $fn+1. We have
6002 to adjust when loading from memory. */
6005 assert (mips_opts.isa == ISA_MIPS1);
6006 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6007 target_big_endian ? treg + 1 : treg,
6009 /* FIXME: A possible overflow which I don't know how to deal
6011 offset_expr.X_add_number += 4;
6012 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6013 target_big_endian ? treg : treg + 1,
6016 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6017 does not become a variant frag. */
6018 frag_wane (frag_now);
6027 * The MIPS assembler seems to check for X_add_number not
6028 * being double aligned and generating:
6031 * addiu at,at,%lo(foo+1)
6034 * But, the resulting address is the same after relocation so why
6035 * generate the extra instruction?
6037 if (mips_arch == CPU_R4650)
6039 as_bad (_("opcode not supported on this processor"));
6042 /* Itbl support may require additional care here. */
6044 if (mips_opts.isa != ISA_MIPS1)
6055 if (mips_arch == CPU_R4650)
6057 as_bad (_("opcode not supported on this processor"));
6061 if (mips_opts.isa != ISA_MIPS1)
6069 /* Itbl support may require additional care here. */
6074 if (HAVE_64BIT_GPRS)
6085 if (HAVE_64BIT_GPRS)
6095 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6096 loads for the case of doing a pair of loads to simulate an 'ld'.
6097 This is not currently done by the compiler, and assembly coders
6098 writing embedded-pic code can cope. */
6100 if (offset_expr.X_op != O_symbol
6101 && offset_expr.X_op != O_constant)
6103 as_bad (_("expression too complex"));
6104 offset_expr.X_op = O_constant;
6107 /* Even on a big endian machine $fn comes before $fn+1. We have
6108 to adjust when loading from memory. We set coproc if we must
6109 load $fn+1 first. */
6110 /* Itbl support may require additional care here. */
6111 if (! target_big_endian)
6114 if (mips_pic == NO_PIC
6115 || offset_expr.X_op == O_constant)
6117 /* If this is a reference to a GP relative symbol, we want
6118 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6119 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6120 If we have a base register, we use this
6122 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6123 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6124 If this is not a GP relative symbol, we want
6125 lui $at,<sym> (BFD_RELOC_HI16_S)
6126 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6127 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6128 If there is a base register, we add it to $at after the
6129 lui instruction. If there is a constant, we always use
6131 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6132 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6151 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6152 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6153 "d,v,t", AT, breg, GP);
6159 /* Itbl support may require additional care here. */
6160 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6161 coproc ? treg + 1 : treg,
6162 (int) BFD_RELOC_GPREL16, tempreg);
6163 offset_expr.X_add_number += 4;
6165 /* Set mips_optimize to 2 to avoid inserting an
6167 hold_mips_optimize = mips_optimize;
6169 /* Itbl support may require additional care here. */
6170 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6171 coproc ? treg : treg + 1,
6172 (int) BFD_RELOC_GPREL16, tempreg);
6173 mips_optimize = hold_mips_optimize;
6175 p = frag_var (rs_machine_dependent, 12 + off, 0,
6176 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6177 used_at && mips_opts.noat),
6178 offset_expr.X_add_symbol, 0, NULL);
6180 /* We just generated two relocs. When tc_gen_reloc
6181 handles this case, it will skip the first reloc and
6182 handle the second. The second reloc already has an
6183 extra addend of 4, which we added above. We must
6184 subtract it out, and then subtract another 4 to make
6185 the first reloc come out right. The second reloc
6186 will come out right because we are going to add 4 to
6187 offset_expr when we build its instruction below.
6189 If we have a symbol, then we don't want to include
6190 the offset, because it will wind up being included
6191 when we generate the reloc. */
6193 if (offset_expr.X_op == O_constant)
6194 offset_expr.X_add_number -= 8;
6197 offset_expr.X_add_number = -4;
6198 offset_expr.X_op = O_constant;
6201 macro_build_lui (p, &icnt, &offset_expr, AT);
6206 macro_build (p, &icnt, (expressionS *) NULL,
6207 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6208 "d,v,t", AT, breg, AT);
6212 /* Itbl support may require additional care here. */
6213 macro_build (p, &icnt, &offset_expr, s, fmt,
6214 coproc ? treg + 1 : treg,
6215 (int) BFD_RELOC_LO16, AT);
6218 /* FIXME: How do we handle overflow here? */
6219 offset_expr.X_add_number += 4;
6220 /* Itbl support may require additional care here. */
6221 macro_build (p, &icnt, &offset_expr, s, fmt,
6222 coproc ? treg : treg + 1,
6223 (int) BFD_RELOC_LO16, AT);
6225 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6229 /* If this is a reference to an external symbol, we want
6230 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6235 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6237 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6238 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6239 If there is a base register we add it to $at before the
6240 lwc1 instructions. If there is a constant we include it
6241 in the lwc1 instructions. */
6243 expr1.X_add_number = offset_expr.X_add_number;
6244 offset_expr.X_add_number = 0;
6245 if (expr1.X_add_number < -0x8000
6246 || expr1.X_add_number >= 0x8000 - 4)
6247 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6252 frag_grow (24 + off);
6253 macro_build ((char *) NULL, &icnt, &offset_expr,
6254 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6255 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
6256 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6258 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6259 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6260 "d,v,t", AT, breg, AT);
6261 /* Itbl support may require additional care here. */
6262 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6263 coproc ? treg + 1 : treg,
6264 (int) BFD_RELOC_LO16, AT);
6265 expr1.X_add_number += 4;
6267 /* Set mips_optimize to 2 to avoid inserting an undesired
6269 hold_mips_optimize = mips_optimize;
6271 /* Itbl support may require additional care here. */
6272 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6273 coproc ? treg : treg + 1,
6274 (int) BFD_RELOC_LO16, AT);
6275 mips_optimize = hold_mips_optimize;
6277 (void) frag_var (rs_machine_dependent, 0, 0,
6278 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6279 offset_expr.X_add_symbol, 0, NULL);
6281 else if (mips_pic == SVR4_PIC)
6285 /* If this is a reference to an external symbol, we want
6286 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6288 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6293 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6295 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6296 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6297 If there is a base register we add it to $at before the
6298 lwc1 instructions. If there is a constant we include it
6299 in the lwc1 instructions. */
6301 expr1.X_add_number = offset_expr.X_add_number;
6302 offset_expr.X_add_number = 0;
6303 if (expr1.X_add_number < -0x8000
6304 || expr1.X_add_number >= 0x8000 - 4)
6305 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6306 if (reg_needs_delay (GP))
6315 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6316 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
6317 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6318 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6319 "d,v,t", AT, AT, GP);
6320 macro_build ((char *) NULL, &icnt, &offset_expr,
6321 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6322 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
6323 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6325 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6326 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6327 "d,v,t", AT, breg, AT);
6328 /* Itbl support may require additional care here. */
6329 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6330 coproc ? treg + 1 : treg,
6331 (int) BFD_RELOC_LO16, AT);
6332 expr1.X_add_number += 4;
6334 /* Set mips_optimize to 2 to avoid inserting an undesired
6336 hold_mips_optimize = mips_optimize;
6338 /* Itbl support may require additional care here. */
6339 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6340 coproc ? treg : treg + 1,
6341 (int) BFD_RELOC_LO16, AT);
6342 mips_optimize = hold_mips_optimize;
6343 expr1.X_add_number -= 4;
6345 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6346 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6347 8 + gpdel + off, 1, 0),
6348 offset_expr.X_add_symbol, 0, NULL);
6351 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6354 macro_build (p, &icnt, &offset_expr,
6355 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6356 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
6358 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6362 macro_build (p, &icnt, (expressionS *) NULL,
6363 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6364 "d,v,t", AT, breg, AT);
6367 /* Itbl support may require additional care here. */
6368 macro_build (p, &icnt, &expr1, s, fmt,
6369 coproc ? treg + 1 : treg,
6370 (int) BFD_RELOC_LO16, AT);
6372 expr1.X_add_number += 4;
6374 /* Set mips_optimize to 2 to avoid inserting an undesired
6376 hold_mips_optimize = mips_optimize;
6378 /* Itbl support may require additional care here. */
6379 macro_build (p, &icnt, &expr1, s, fmt,
6380 coproc ? treg : treg + 1,
6381 (int) BFD_RELOC_LO16, AT);
6382 mips_optimize = hold_mips_optimize;
6384 else if (mips_pic == EMBEDDED_PIC)
6386 /* If there is no base register, we use
6387 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6388 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6389 If we have a base register, we use
6391 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6392 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6401 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6402 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6403 "d,v,t", AT, breg, GP);
6408 /* Itbl support may require additional care here. */
6409 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6410 coproc ? treg + 1 : treg,
6411 (int) BFD_RELOC_GPREL16, tempreg);
6412 offset_expr.X_add_number += 4;
6413 /* Itbl support may require additional care here. */
6414 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6415 coproc ? treg : treg + 1,
6416 (int) BFD_RELOC_GPREL16, tempreg);
6432 assert (HAVE_32BIT_ADDRESSES);
6433 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6434 (int) BFD_RELOC_LO16, breg);
6435 offset_expr.X_add_number += 4;
6436 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
6437 (int) BFD_RELOC_LO16, breg);
6440 /* New code added to support COPZ instructions.
6441 This code builds table entries out of the macros in mip_opcodes.
6442 R4000 uses interlocks to handle coproc delays.
6443 Other chips (like the R3000) require nops to be inserted for delays.
6445 FIXME: Currently, we require that the user handle delays.
6446 In order to fill delay slots for non-interlocked chips,
6447 we must have a way to specify delays based on the coprocessor.
6448 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6449 What are the side-effects of the cop instruction?
6450 What cache support might we have and what are its effects?
6451 Both coprocessor & memory require delays. how long???
6452 What registers are read/set/modified?
6454 If an itbl is provided to interpret cop instructions,
6455 this knowledge can be encoded in the itbl spec. */
6469 /* For now we just do C (same as Cz). The parameter will be
6470 stored in insn_opcode by mips_ip. */
6471 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
6476 move_register (&icnt, dreg, sreg);
6479 #ifdef LOSING_COMPILER
6481 /* Try and see if this is a new itbl instruction.
6482 This code builds table entries out of the macros in mip_opcodes.
6483 FIXME: For now we just assemble the expression and pass it's
6484 value along as a 32-bit immediate.
6485 We may want to have the assembler assemble this value,
6486 so that we gain the assembler's knowledge of delay slots,
6488 Would it be more efficient to use mask (id) here? */
6489 if (itbl_have_entries
6490 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6492 s = ip->insn_mo->name;
6494 coproc = ITBL_DECODE_PNUM (immed_expr);;
6495 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
6502 as_warn (_("Macro used $at after \".set noat\""));
6507 struct mips_cl_insn *ip;
6509 register int treg, sreg, dreg, breg;
6525 bfd_reloc_code_real_type r;
6528 treg = (ip->insn_opcode >> 16) & 0x1f;
6529 dreg = (ip->insn_opcode >> 11) & 0x1f;
6530 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6531 mask = ip->insn_mo->mask;
6533 expr1.X_op = O_constant;
6534 expr1.X_op_symbol = NULL;
6535 expr1.X_add_symbol = NULL;
6536 expr1.X_add_number = 1;
6540 #endif /* LOSING_COMPILER */
6545 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6546 dbl ? "dmultu" : "multu", "s,t", sreg, treg);
6547 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6554 /* The MIPS assembler some times generates shifts and adds. I'm
6555 not trying to be that fancy. GCC should do this for us
6557 load_register (&icnt, AT, &imm_expr, dbl);
6558 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6559 dbl ? "dmult" : "mult", "s,t", sreg, AT);
6560 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6574 mips_emit_delays (true);
6575 ++mips_opts.noreorder;
6576 mips_any_noreorder = 1;
6578 load_register (&icnt, AT, &imm_expr, dbl);
6579 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6580 dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
6581 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6583 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6584 dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, 31);
6585 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6588 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6592 expr1.X_add_number = 8;
6593 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg,
6595 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6597 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6600 --mips_opts.noreorder;
6601 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg);
6614 mips_emit_delays (true);
6615 ++mips_opts.noreorder;
6616 mips_any_noreorder = 1;
6618 load_register (&icnt, AT, &imm_expr, dbl);
6619 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6620 dbl ? "dmultu" : "multu",
6621 "s,t", sreg, imm ? AT : treg);
6622 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6624 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6627 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6631 expr1.X_add_number = 8;
6632 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6633 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6635 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6638 --mips_opts.noreorder;
6642 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6643 "d,v,t", AT, 0, treg);
6644 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6645 "d,t,s", AT, sreg, AT);
6646 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6647 "d,t,s", dreg, sreg, treg);
6648 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6649 "d,v,t", dreg, dreg, AT);
6653 if (imm_expr.X_op != O_constant)
6654 as_bad (_("rotate count too large"));
6655 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
6656 AT, sreg, (int) (imm_expr.X_add_number & 0x1f));
6657 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
6658 dreg, sreg, (int) ((0 - imm_expr.X_add_number) & 0x1f));
6659 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
6664 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6665 "d,v,t", AT, 0, treg);
6666 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6667 "d,t,s", AT, sreg, AT);
6668 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6669 "d,t,s", dreg, sreg, treg);
6670 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6671 "d,v,t", dreg, dreg, AT);
6675 if (imm_expr.X_op != O_constant)
6676 as_bad (_("rotate count too large"));
6677 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
6678 AT, sreg, (int) (imm_expr.X_add_number & 0x1f));
6679 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
6680 dreg, sreg, (int) ((0 - imm_expr.X_add_number) & 0x1f));
6681 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
6686 if (mips_arch == CPU_R4650)
6688 as_bad (_("opcode not supported on this processor"));
6691 assert (mips_opts.isa == ISA_MIPS1);
6692 /* Even on a big endian machine $fn comes before $fn+1. We have
6693 to adjust when storing to memory. */
6694 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6695 target_big_endian ? treg + 1 : treg,
6696 (int) BFD_RELOC_LO16, breg);
6697 offset_expr.X_add_number += 4;
6698 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6699 target_big_endian ? treg : treg + 1,
6700 (int) BFD_RELOC_LO16, breg);
6705 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6706 treg, (int) BFD_RELOC_LO16);
6708 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6709 sreg, (int) BFD_RELOC_LO16);
6712 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6713 "d,v,t", dreg, sreg, treg);
6714 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6715 dreg, (int) BFD_RELOC_LO16);
6720 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6722 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6723 sreg, (int) BFD_RELOC_LO16);
6728 as_warn (_("Instruction %s: result is always false"),
6730 move_register (&icnt, dreg, 0);
6733 if (imm_expr.X_op == O_constant
6734 && imm_expr.X_add_number >= 0
6735 && imm_expr.X_add_number < 0x10000)
6737 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6738 sreg, (int) BFD_RELOC_LO16);
6741 else if (imm_expr.X_op == O_constant
6742 && imm_expr.X_add_number > -0x8000
6743 && imm_expr.X_add_number < 0)
6745 imm_expr.X_add_number = -imm_expr.X_add_number;
6746 macro_build ((char *) NULL, &icnt, &imm_expr,
6747 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6748 "t,r,j", dreg, sreg,
6749 (int) BFD_RELOC_LO16);
6754 load_register (&icnt, AT, &imm_expr, 0);
6755 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6756 "d,v,t", dreg, sreg, AT);
6759 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6760 (int) BFD_RELOC_LO16);
6765 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6771 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6773 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6774 (int) BFD_RELOC_LO16);
6777 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6779 if (imm_expr.X_op == O_constant
6780 && imm_expr.X_add_number >= -0x8000
6781 && imm_expr.X_add_number < 0x8000)
6783 macro_build ((char *) NULL, &icnt, &imm_expr,
6784 mask == M_SGE_I ? "slti" : "sltiu",
6785 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6790 load_register (&icnt, AT, &imm_expr, 0);
6791 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6792 mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg,
6796 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6797 (int) BFD_RELOC_LO16);
6802 case M_SGT: /* sreg > treg <==> treg < sreg */
6808 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6812 case M_SGT_I: /* sreg > I <==> I < sreg */
6818 load_register (&icnt, AT, &imm_expr, 0);
6819 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6823 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6829 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6831 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6832 (int) BFD_RELOC_LO16);
6835 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6841 load_register (&icnt, AT, &imm_expr, 0);
6842 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6844 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6845 (int) BFD_RELOC_LO16);
6849 if (imm_expr.X_op == O_constant
6850 && imm_expr.X_add_number >= -0x8000
6851 && imm_expr.X_add_number < 0x8000)
6853 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
6854 dreg, sreg, (int) BFD_RELOC_LO16);
6857 load_register (&icnt, AT, &imm_expr, 0);
6858 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
6863 if (imm_expr.X_op == O_constant
6864 && imm_expr.X_add_number >= -0x8000
6865 && imm_expr.X_add_number < 0x8000)
6867 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
6868 dreg, sreg, (int) BFD_RELOC_LO16);
6871 load_register (&icnt, AT, &imm_expr, 0);
6872 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6873 "d,v,t", dreg, sreg, AT);
6878 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6879 "d,v,t", dreg, 0, treg);
6881 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6882 "d,v,t", dreg, 0, sreg);
6885 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6886 "d,v,t", dreg, sreg, treg);
6887 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6888 "d,v,t", dreg, 0, dreg);
6893 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6895 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6896 "d,v,t", dreg, 0, sreg);
6901 as_warn (_("Instruction %s: result is always true"),
6903 macro_build ((char *) NULL, &icnt, &expr1,
6904 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6905 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
6908 if (imm_expr.X_op == O_constant
6909 && imm_expr.X_add_number >= 0
6910 && imm_expr.X_add_number < 0x10000)
6912 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
6913 dreg, sreg, (int) BFD_RELOC_LO16);
6916 else if (imm_expr.X_op == O_constant
6917 && imm_expr.X_add_number > -0x8000
6918 && imm_expr.X_add_number < 0)
6920 imm_expr.X_add_number = -imm_expr.X_add_number;
6921 macro_build ((char *) NULL, &icnt, &imm_expr,
6922 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6923 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6928 load_register (&icnt, AT, &imm_expr, 0);
6929 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6930 "d,v,t", dreg, sreg, AT);
6933 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6934 "d,v,t", dreg, 0, dreg);
6942 if (imm_expr.X_op == O_constant
6943 && imm_expr.X_add_number > -0x8000
6944 && imm_expr.X_add_number <= 0x8000)
6946 imm_expr.X_add_number = -imm_expr.X_add_number;
6947 macro_build ((char *) NULL, &icnt, &imm_expr,
6948 dbl ? "daddi" : "addi",
6949 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6952 load_register (&icnt, AT, &imm_expr, dbl);
6953 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6954 dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
6960 if (imm_expr.X_op == O_constant
6961 && imm_expr.X_add_number > -0x8000
6962 && imm_expr.X_add_number <= 0x8000)
6964 imm_expr.X_add_number = -imm_expr.X_add_number;
6965 macro_build ((char *) NULL, &icnt, &imm_expr,
6966 dbl ? "daddiu" : "addiu",
6967 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6970 load_register (&icnt, AT, &imm_expr, dbl);
6971 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6972 dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
6993 load_register (&icnt, AT, &imm_expr, 0);
6994 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg,
7000 assert (mips_opts.isa == ISA_MIPS1);
7001 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7002 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7005 * Is the double cfc1 instruction a bug in the mips assembler;
7006 * or is there a reason for it?
7008 mips_emit_delays (true);
7009 ++mips_opts.noreorder;
7010 mips_any_noreorder = 1;
7011 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7013 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7015 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7016 expr1.X_add_number = 3;
7017 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7018 (int) BFD_RELOC_LO16);
7019 expr1.X_add_number = 2;
7020 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7021 (int) BFD_RELOC_LO16);
7022 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7024 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7025 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7026 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
7027 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7029 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7030 --mips_opts.noreorder;
7039 if (offset_expr.X_add_number >= 0x7fff)
7040 as_bad (_("operand overflow"));
7041 /* avoid load delay */
7042 if (! target_big_endian)
7043 offset_expr.X_add_number += 1;
7044 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7045 (int) BFD_RELOC_LO16, breg);
7046 if (! target_big_endian)
7047 offset_expr.X_add_number -= 1;
7049 offset_expr.X_add_number += 1;
7050 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
7051 (int) BFD_RELOC_LO16, breg);
7052 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7054 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7068 if (offset_expr.X_add_number >= 0x8000 - off)
7069 as_bad (_("operand overflow"));
7070 if (! target_big_endian)
7071 offset_expr.X_add_number += off;
7072 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7073 (int) BFD_RELOC_LO16, breg);
7074 if (! target_big_endian)
7075 offset_expr.X_add_number -= off;
7077 offset_expr.X_add_number += off;
7078 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7079 (int) BFD_RELOC_LO16, breg);
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 = off;
7101 expr1.X_add_number = 0;
7102 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7103 (int) BFD_RELOC_LO16, AT);
7104 if (! target_big_endian)
7105 expr1.X_add_number = 0;
7107 expr1.X_add_number = off;
7108 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7109 (int) BFD_RELOC_LO16, AT);
7115 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7117 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7118 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7119 "d,v,t", AT, AT, breg);
7120 if (target_big_endian)
7121 expr1.X_add_number = 0;
7122 macro_build ((char *) NULL, &icnt, &expr1,
7123 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
7124 (int) BFD_RELOC_LO16, AT);
7125 if (target_big_endian)
7126 expr1.X_add_number = 1;
7128 expr1.X_add_number = 0;
7129 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7130 (int) BFD_RELOC_LO16, AT);
7131 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7133 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7138 if (offset_expr.X_add_number >= 0x7fff)
7139 as_bad (_("operand overflow"));
7140 if (target_big_endian)
7141 offset_expr.X_add_number += 1;
7142 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7143 (int) BFD_RELOC_LO16, breg);
7144 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7146 if (target_big_endian)
7147 offset_expr.X_add_number -= 1;
7149 offset_expr.X_add_number += 1;
7150 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7151 (int) BFD_RELOC_LO16, breg);
7164 if (offset_expr.X_add_number >= 0x8000 - off)
7165 as_bad (_("operand overflow"));
7166 if (! target_big_endian)
7167 offset_expr.X_add_number += off;
7168 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7169 (int) BFD_RELOC_LO16, breg);
7170 if (! target_big_endian)
7171 offset_expr.X_add_number -= off;
7173 offset_expr.X_add_number += off;
7174 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7175 (int) BFD_RELOC_LO16, breg);
7189 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7191 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7192 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7193 "d,v,t", AT, AT, breg);
7194 if (! target_big_endian)
7195 expr1.X_add_number = off;
7197 expr1.X_add_number = 0;
7198 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7199 (int) BFD_RELOC_LO16, AT);
7200 if (! target_big_endian)
7201 expr1.X_add_number = 0;
7203 expr1.X_add_number = off;
7204 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7205 (int) BFD_RELOC_LO16, AT);
7210 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7212 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7213 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7214 "d,v,t", AT, AT, breg);
7215 if (! target_big_endian)
7216 expr1.X_add_number = 0;
7217 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7218 (int) BFD_RELOC_LO16, AT);
7219 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7221 if (! target_big_endian)
7222 expr1.X_add_number = 1;
7224 expr1.X_add_number = 0;
7225 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7226 (int) BFD_RELOC_LO16, AT);
7227 if (! target_big_endian)
7228 expr1.X_add_number = 0;
7230 expr1.X_add_number = 1;
7231 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7232 (int) BFD_RELOC_LO16, AT);
7233 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7235 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7240 /* FIXME: Check if this is one of the itbl macros, since they
7241 are added dynamically. */
7242 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7246 as_warn (_("Macro used $at after \".set noat\""));
7249 /* Implement macros in mips16 mode. */
7253 struct mips_cl_insn *ip;
7256 int xreg, yreg, zreg, tmp;
7260 const char *s, *s2, *s3;
7262 mask = ip->insn_mo->mask;
7264 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7265 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7266 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7270 expr1.X_op = O_constant;
7271 expr1.X_op_symbol = NULL;
7272 expr1.X_add_symbol = NULL;
7273 expr1.X_add_number = 1;
7292 mips_emit_delays (true);
7293 ++mips_opts.noreorder;
7294 mips_any_noreorder = 1;
7295 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7296 dbl ? "ddiv" : "div",
7297 "0,x,y", xreg, yreg);
7298 expr1.X_add_number = 2;
7299 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7300 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6",
7303 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7304 since that causes an overflow. We should do that as well,
7305 but I don't see how to do the comparisons without a temporary
7307 --mips_opts.noreorder;
7308 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg);
7327 mips_emit_delays (true);
7328 ++mips_opts.noreorder;
7329 mips_any_noreorder = 1;
7330 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y",
7332 expr1.X_add_number = 2;
7333 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7334 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7336 --mips_opts.noreorder;
7337 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg);
7343 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7344 dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7345 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x",
7354 if (imm_expr.X_op != O_constant)
7355 as_bad (_("Unsupported large constant"));
7356 imm_expr.X_add_number = -imm_expr.X_add_number;
7357 macro_build ((char *) NULL, &icnt, &imm_expr,
7358 dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7362 if (imm_expr.X_op != O_constant)
7363 as_bad (_("Unsupported large constant"));
7364 imm_expr.X_add_number = -imm_expr.X_add_number;
7365 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
7370 if (imm_expr.X_op != O_constant)
7371 as_bad (_("Unsupported large constant"));
7372 imm_expr.X_add_number = -imm_expr.X_add_number;
7373 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
7396 goto do_reverse_branch;
7400 goto do_reverse_branch;
7412 goto do_reverse_branch;
7423 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
7425 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7452 goto do_addone_branch_i;
7457 goto do_addone_branch_i;
7472 goto do_addone_branch_i;
7479 if (imm_expr.X_op != O_constant)
7480 as_bad (_("Unsupported large constant"));
7481 ++imm_expr.X_add_number;
7484 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
7485 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7489 expr1.X_add_number = 0;
7490 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
7492 move_register (&icnt, xreg, yreg);
7493 expr1.X_add_number = 2;
7494 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
7495 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7496 "neg", "x,w", xreg, xreg);
7500 /* For consistency checking, verify that all bits are specified either
7501 by the match/mask part of the instruction definition, or by the
7504 validate_mips_insn (opc)
7505 const struct mips_opcode *opc;
7507 const char *p = opc->args;
7509 unsigned long used_bits = opc->mask;
7511 if ((used_bits & opc->match) != opc->match)
7513 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7514 opc->name, opc->args);
7517 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7524 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7525 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7527 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
7528 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
7529 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7530 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7532 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7533 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7535 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
7537 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
7538 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
7539 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
7540 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7541 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7542 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7543 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7544 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
7545 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7546 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
7547 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7549 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
7550 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7551 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7552 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
7554 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7555 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7556 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
7557 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7558 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7559 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7560 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7561 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7562 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7565 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
7566 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
7567 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7569 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7570 c, opc->name, opc->args);
7574 if (used_bits != 0xffffffff)
7576 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7577 ~used_bits & 0xffffffff, opc->name, opc->args);
7583 /* This routine assembles an instruction into its binary format. As a
7584 side effect, it sets one of the global variables imm_reloc or
7585 offset_reloc to the type of relocation to do if one of the operands
7586 is an address expression. */
7591 struct mips_cl_insn *ip;
7596 struct mips_opcode *insn;
7599 unsigned int lastregno = 0;
7602 int full_opcode_match = 1;
7606 /* If the instruction contains a '.', we first try to match an instruction
7607 including the '.'. Then we try again without the '.'. */
7609 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
7612 /* If we stopped on whitespace, then replace the whitespace with null for
7613 the call to hash_find. Save the character we replaced just in case we
7614 have to re-parse the instruction. */
7621 insn = (struct mips_opcode *) hash_find (op_hash, str);
7623 /* If we didn't find the instruction in the opcode table, try again, but
7624 this time with just the instruction up to, but not including the
7628 /* Restore the character we overwrite above (if any). */
7632 /* Scan up to the first '.' or whitespace. */
7634 *s != '\0' && *s != '.' && !ISSPACE (*s);
7638 /* If we did not find a '.', then we can quit now. */
7641 insn_error = "unrecognized opcode";
7645 /* Lookup the instruction in the hash table. */
7647 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7649 insn_error = "unrecognized opcode";
7653 full_opcode_match = 0;
7661 assert (strcmp (insn->name, str) == 0);
7663 if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_arch))
7668 if (insn->pinfo != INSN_MACRO)
7670 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7676 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7677 && strcmp (insn->name, insn[1].name) == 0)
7686 static char buf[100];
7688 _("opcode not supported on this processor: %s (%s)"),
7689 mips_cpu_to_str (mips_arch),
7690 mips_isa_to_str (mips_opts.isa));
7701 ip->insn_opcode = insn->match;
7703 for (args = insn->args;; ++args)
7705 s += strspn (s, " \t");
7708 case '\0': /* end of args */
7721 ip->insn_opcode |= lastregno << OP_SH_RS;
7725 ip->insn_opcode |= lastregno << OP_SH_RT;
7729 ip->insn_opcode |= lastregno << OP_SH_FT;
7733 ip->insn_opcode |= lastregno << OP_SH_FS;
7739 /* Handle optional base register.
7740 Either the base register is omitted or
7741 we must have a left paren. */
7742 /* This is dependent on the next operand specifier
7743 is a base register specification. */
7744 assert (args[1] == 'b' || args[1] == '5'
7745 || args[1] == '-' || args[1] == '4');
7749 case ')': /* these must match exactly */
7754 case '<': /* must be at least one digit */
7756 * According to the manual, if the shift amount is greater
7757 * than 31 or less than 0, then the shift amount should be
7758 * mod 32. In reality the mips assembler issues an error.
7759 * We issue a warning and mask out all but the low 5 bits.
7761 my_getExpression (&imm_expr, s);
7762 check_absolute_expr (ip, &imm_expr);
7763 if ((unsigned long) imm_expr.X_add_number > 31)
7765 as_warn (_("Improper shift amount (%ld)"),
7766 (long) imm_expr.X_add_number);
7767 imm_expr.X_add_number &= OP_MASK_SHAMT;
7769 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
7770 imm_expr.X_op = O_absent;
7774 case '>': /* shift amount minus 32 */
7775 my_getExpression (&imm_expr, s);
7776 check_absolute_expr (ip, &imm_expr);
7777 if ((unsigned long) imm_expr.X_add_number < 32
7778 || (unsigned long) imm_expr.X_add_number > 63)
7780 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
7781 imm_expr.X_op = O_absent;
7785 case 'k': /* cache code */
7786 case 'h': /* prefx code */
7787 my_getExpression (&imm_expr, s);
7788 check_absolute_expr (ip, &imm_expr);
7789 if ((unsigned long) imm_expr.X_add_number > 31)
7791 as_warn (_("Invalid value for `%s' (%lu)"),
7793 (unsigned long) imm_expr.X_add_number);
7794 imm_expr.X_add_number &= 0x1f;
7797 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7799 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7800 imm_expr.X_op = O_absent;
7804 case 'c': /* break code */
7805 my_getExpression (&imm_expr, s);
7806 check_absolute_expr (ip, &imm_expr);
7807 if ((unsigned) imm_expr.X_add_number > 1023)
7809 as_warn (_("Illegal break code (%ld)"),
7810 (long) imm_expr.X_add_number);
7811 imm_expr.X_add_number &= OP_MASK_CODE;
7813 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
7814 imm_expr.X_op = O_absent;
7818 case 'q': /* lower break code */
7819 my_getExpression (&imm_expr, s);
7820 check_absolute_expr (ip, &imm_expr);
7821 if ((unsigned) imm_expr.X_add_number > 1023)
7823 as_warn (_("Illegal lower break code (%ld)"),
7824 (long) imm_expr.X_add_number);
7825 imm_expr.X_add_number &= OP_MASK_CODE2;
7827 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
7828 imm_expr.X_op = O_absent;
7832 case 'B': /* 20-bit syscall/break code. */
7833 my_getExpression (&imm_expr, s);
7834 check_absolute_expr (ip, &imm_expr);
7835 if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE20)
7836 as_warn (_("Illegal 20-bit code (%ld)"),
7837 (long) imm_expr.X_add_number);
7838 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
7839 imm_expr.X_op = O_absent;
7843 case 'C': /* Coprocessor code */
7844 my_getExpression (&imm_expr, s);
7845 check_absolute_expr (ip, &imm_expr);
7846 if ((unsigned long) imm_expr.X_add_number >= (1<<25))
7848 as_warn (_("Coproccesor code > 25 bits (%ld)"),
7849 (long) imm_expr.X_add_number);
7850 imm_expr.X_add_number &= ((1<<25) - 1);
7852 ip->insn_opcode |= imm_expr.X_add_number;
7853 imm_expr.X_op = O_absent;
7857 case 'J': /* 19-bit wait code. */
7858 my_getExpression (&imm_expr, s);
7859 check_absolute_expr (ip, &imm_expr);
7860 if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE19)
7861 as_warn (_("Illegal 19-bit code (%ld)"),
7862 (long) imm_expr.X_add_number);
7863 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
7864 imm_expr.X_op = O_absent;
7868 case 'P': /* Performance register */
7869 my_getExpression (&imm_expr, s);
7870 check_absolute_expr (ip, &imm_expr);
7871 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
7873 as_warn (_("Invalid performance register (%ld)"),
7874 (long) imm_expr.X_add_number);
7875 imm_expr.X_add_number &= OP_MASK_PERFREG;
7877 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
7878 imm_expr.X_op = O_absent;
7882 case 'b': /* base register */
7883 case 'd': /* destination register */
7884 case 's': /* source register */
7885 case 't': /* target register */
7886 case 'r': /* both target and source */
7887 case 'v': /* both dest and source */
7888 case 'w': /* both dest and target */
7889 case 'E': /* coprocessor target register */
7890 case 'G': /* coprocessor destination register */
7891 case 'x': /* ignore register name */
7892 case 'z': /* must be zero register */
7893 case 'U': /* destination register (clo/clz). */
7908 while (ISDIGIT (*s));
7910 as_bad (_("Invalid register number (%d)"), regno);
7912 else if (*args == 'E' || *args == 'G')
7916 if (s[1] == 'f' && s[2] == 'p')
7921 else if (s[1] == 's' && s[2] == 'p')
7926 else if (s[1] == 'g' && s[2] == 'p')
7931 else if (s[1] == 'a' && s[2] == 't')
7936 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
7941 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
7946 else if (itbl_have_entries)
7951 p = s + 1; /* advance past '$' */
7952 n = itbl_get_field (&p); /* n is name */
7954 /* See if this is a register defined in an
7956 if (itbl_get_reg_val (n, &r))
7958 /* Get_field advances to the start of
7959 the next field, so we need to back
7960 rack to the end of the last field. */
7964 s = strchr (s, '\0');
7977 as_warn (_("Used $at without \".set noat\""));
7983 if (c == 'r' || c == 'v' || c == 'w')
7990 /* 'z' only matches $0. */
7991 if (c == 'z' && regno != 0)
7994 /* Now that we have assembled one operand, we use the args string
7995 * to figure out where it goes in the instruction. */
8002 ip->insn_opcode |= regno << OP_SH_RS;
8006 ip->insn_opcode |= regno << OP_SH_RD;
8009 ip->insn_opcode |= regno << OP_SH_RD;
8010 ip->insn_opcode |= regno << OP_SH_RT;
8015 ip->insn_opcode |= regno << OP_SH_RT;
8018 /* This case exists because on the r3000 trunc
8019 expands into a macro which requires a gp
8020 register. On the r6000 or r4000 it is
8021 assembled into a single instruction which
8022 ignores the register. Thus the insn version
8023 is MIPS_ISA2 and uses 'x', and the macro
8024 version is MIPS_ISA1 and uses 't'. */
8027 /* This case is for the div instruction, which
8028 acts differently if the destination argument
8029 is $0. This only matches $0, and is checked
8030 outside the switch. */
8033 /* Itbl operand; not yet implemented. FIXME ?? */
8035 /* What about all other operands like 'i', which
8036 can be specified in the opcode table? */
8046 ip->insn_opcode |= lastregno << OP_SH_RS;
8049 ip->insn_opcode |= lastregno << OP_SH_RT;
8054 case 'D': /* floating point destination register */
8055 case 'S': /* floating point source register */
8056 case 'T': /* floating point target register */
8057 case 'R': /* floating point source register */
8061 if (s[0] == '$' && s[1] == 'f'
8072 while (ISDIGIT (*s));
8075 as_bad (_("Invalid float register number (%d)"), regno);
8077 if ((regno & 1) != 0
8079 && ! (strcmp (str, "mtc1") == 0
8080 || strcmp (str, "mfc1") == 0
8081 || strcmp (str, "lwc1") == 0
8082 || strcmp (str, "swc1") == 0
8083 || strcmp (str, "l.s") == 0
8084 || strcmp (str, "s.s") == 0))
8085 as_warn (_("Float register should be even, was %d"),
8093 if (c == 'V' || c == 'W')
8103 ip->insn_opcode |= regno << OP_SH_FD;
8107 ip->insn_opcode |= regno << OP_SH_FS;
8111 ip->insn_opcode |= regno << OP_SH_FT;
8114 ip->insn_opcode |= regno << OP_SH_FR;
8124 ip->insn_opcode |= lastregno << OP_SH_FS;
8127 ip->insn_opcode |= lastregno << OP_SH_FT;
8133 my_getExpression (&imm_expr, s);
8134 if (imm_expr.X_op != O_big
8135 && imm_expr.X_op != O_constant)
8136 insn_error = _("absolute expression required");
8141 my_getExpression (&offset_expr, s);
8142 *imm_reloc = BFD_RELOC_32;
8155 unsigned char temp[8];
8157 unsigned int length;
8162 /* These only appear as the last operand in an
8163 instruction, and every instruction that accepts
8164 them in any variant accepts them in all variants.
8165 This means we don't have to worry about backing out
8166 any changes if the instruction does not match.
8168 The difference between them is the size of the
8169 floating point constant and where it goes. For 'F'
8170 and 'L' the constant is 64 bits; for 'f' and 'l' it
8171 is 32 bits. Where the constant is placed is based
8172 on how the MIPS assembler does things:
8175 f -- immediate value
8178 The .lit4 and .lit8 sections are only used if
8179 permitted by the -G argument.
8181 When generating embedded PIC code, we use the
8182 .lit8 section but not the .lit4 section (we can do
8183 .lit4 inline easily; we need to put .lit8
8184 somewhere in the data segment, and using .lit8
8185 permits the linker to eventually combine identical
8188 The code below needs to know whether the target register
8189 is 32 or 64 bits wide. It relies on the fact 'f' and
8190 'F' are used with GPR-based instructions and 'l' and
8191 'L' are used with FPR-based instructions. */
8193 f64 = *args == 'F' || *args == 'L';
8194 using_gprs = *args == 'F' || *args == 'f';
8196 save_in = input_line_pointer;
8197 input_line_pointer = s;
8198 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8200 s = input_line_pointer;
8201 input_line_pointer = save_in;
8202 if (err != NULL && *err != '\0')
8204 as_bad (_("Bad floating point constant: %s"), err);
8205 memset (temp, '\0', sizeof temp);
8206 length = f64 ? 8 : 4;
8209 assert (length == (unsigned) (f64 ? 8 : 4));
8213 && (! USE_GLOBAL_POINTER_OPT
8214 || mips_pic == EMBEDDED_PIC
8215 || g_switch_value < 4
8216 || (temp[0] == 0 && temp[1] == 0)
8217 || (temp[2] == 0 && temp[3] == 0))))
8219 imm_expr.X_op = O_constant;
8220 if (! target_big_endian)
8221 imm_expr.X_add_number = bfd_getl32 (temp);
8223 imm_expr.X_add_number = bfd_getb32 (temp);
8226 && ! mips_disable_float_construction
8227 /* Constants can only be constructed in GPRs and
8228 copied to FPRs if the GPRs are at least as wide
8229 as the FPRs. Force the constant into memory if
8230 we are using 64-bit FPRs but the GPRs are only
8233 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8234 && ((temp[0] == 0 && temp[1] == 0)
8235 || (temp[2] == 0 && temp[3] == 0))
8236 && ((temp[4] == 0 && temp[5] == 0)
8237 || (temp[6] == 0 && temp[7] == 0)))
8239 /* The value is simple enough to load with a couple of
8240 instructions. If using 32-bit registers, set
8241 imm_expr to the high order 32 bits and offset_expr to
8242 the low order 32 bits. Otherwise, set imm_expr to
8243 the entire 64 bit constant. */
8244 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8246 imm_expr.X_op = O_constant;
8247 offset_expr.X_op = O_constant;
8248 if (! target_big_endian)
8250 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8251 offset_expr.X_add_number = bfd_getl32 (temp);
8255 imm_expr.X_add_number = bfd_getb32 (temp);
8256 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8258 if (offset_expr.X_add_number == 0)
8259 offset_expr.X_op = O_absent;
8261 else if (sizeof (imm_expr.X_add_number) > 4)
8263 imm_expr.X_op = O_constant;
8264 if (! target_big_endian)
8265 imm_expr.X_add_number = bfd_getl64 (temp);
8267 imm_expr.X_add_number = bfd_getb64 (temp);
8271 imm_expr.X_op = O_big;
8272 imm_expr.X_add_number = 4;
8273 if (! target_big_endian)
8275 generic_bignum[0] = bfd_getl16 (temp);
8276 generic_bignum[1] = bfd_getl16 (temp + 2);
8277 generic_bignum[2] = bfd_getl16 (temp + 4);
8278 generic_bignum[3] = bfd_getl16 (temp + 6);
8282 generic_bignum[0] = bfd_getb16 (temp + 6);
8283 generic_bignum[1] = bfd_getb16 (temp + 4);
8284 generic_bignum[2] = bfd_getb16 (temp + 2);
8285 generic_bignum[3] = bfd_getb16 (temp);
8291 const char *newname;
8294 /* Switch to the right section. */
8296 subseg = now_subseg;
8299 default: /* unused default case avoids warnings. */
8301 newname = RDATA_SECTION_NAME;
8302 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
8303 || mips_pic == EMBEDDED_PIC)
8307 if (mips_pic == EMBEDDED_PIC)
8310 newname = RDATA_SECTION_NAME;
8313 assert (!USE_GLOBAL_POINTER_OPT
8314 || g_switch_value >= 4);
8318 new_seg = subseg_new (newname, (subsegT) 0);
8319 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
8320 bfd_set_section_flags (stdoutput, new_seg,
8325 frag_align (*args == 'l' ? 2 : 3, 0, 0);
8326 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
8327 && strcmp (TARGET_OS, "elf") != 0)
8328 record_alignment (new_seg, 4);
8330 record_alignment (new_seg, *args == 'l' ? 2 : 3);
8332 as_bad (_("Can't use floating point insn in this section"));
8334 /* Set the argument to the current address in the
8336 offset_expr.X_op = O_symbol;
8337 offset_expr.X_add_symbol =
8338 symbol_new ("L0\001", now_seg,
8339 (valueT) frag_now_fix (), frag_now);
8340 offset_expr.X_add_number = 0;
8342 /* Put the floating point number into the section. */
8343 p = frag_more ((int) length);
8344 memcpy (p, temp, length);
8346 /* Switch back to the original section. */
8347 subseg_set (seg, subseg);
8352 case 'i': /* 16 bit unsigned immediate */
8353 case 'j': /* 16 bit signed immediate */
8354 *imm_reloc = BFD_RELOC_LO16;
8355 c = my_getSmallExpression (&imm_expr, s);
8360 if (imm_expr.X_op == O_constant)
8361 imm_expr.X_add_number =
8362 (imm_expr.X_add_number >> 16) & 0xffff;
8364 else if (c == S_EX_HIGHEST)
8365 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8366 else if (c == S_EX_HIGHER)
8367 *imm_reloc = BFD_RELOC_MIPS_HIGHER;
8368 else if (c == S_EX_GP_REL)
8370 /* This occurs in NewABI only. */
8371 c = my_getSmallExpression (&imm_expr, s);
8373 as_bad (_("bad composition of relocations"));
8376 c = my_getSmallExpression (&imm_expr, s);
8378 as_bad (_("bad composition of relocations"));
8381 imm_reloc[0] = BFD_RELOC_GPREL16;
8382 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8383 imm_reloc[2] = BFD_RELOC_LO16;
8388 else if (c == S_EX_HI)
8390 *imm_reloc = BFD_RELOC_HI16_S;
8391 imm_unmatched_hi = true;
8394 *imm_reloc = BFD_RELOC_HI16;
8396 else if (imm_expr.X_op == O_constant)
8397 imm_expr.X_add_number &= 0xffff;
8401 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8402 || ((imm_expr.X_add_number < 0
8403 || imm_expr.X_add_number >= 0x10000)
8404 && imm_expr.X_op == O_constant))
8406 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8407 !strcmp (insn->name, insn[1].name))
8409 if (imm_expr.X_op == O_constant
8410 || imm_expr.X_op == O_big)
8411 as_bad (_("16 bit expression not in range 0..65535"));
8419 /* The upper bound should be 0x8000, but
8420 unfortunately the MIPS assembler accepts numbers
8421 from 0x8000 to 0xffff and sign extends them, and
8422 we want to be compatible. We only permit this
8423 extended range for an instruction which does not
8424 provide any further alternates, since those
8425 alternates may handle other cases. People should
8426 use the numbers they mean, rather than relying on
8427 a mysterious sign extension. */
8428 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8429 strcmp (insn->name, insn[1].name) == 0);
8434 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8435 || ((imm_expr.X_add_number < -0x8000
8436 || imm_expr.X_add_number >= max)
8437 && imm_expr.X_op == O_constant)
8439 && imm_expr.X_add_number < 0
8441 && imm_expr.X_unsigned
8442 && sizeof (imm_expr.X_add_number) <= 4))
8446 if (imm_expr.X_op == O_constant
8447 || imm_expr.X_op == O_big)
8448 as_bad (_("16 bit expression not in range -32768..32767"));
8454 case 'o': /* 16 bit offset */
8455 c = my_getSmallExpression (&offset_expr, s);
8457 /* If this value won't fit into a 16 bit offset, then go
8458 find a macro that will generate the 32 bit offset
8461 && (offset_expr.X_op != O_constant
8462 || offset_expr.X_add_number >= 0x8000
8463 || offset_expr.X_add_number < -0x8000))
8468 if (offset_expr.X_op != O_constant)
8470 offset_expr.X_add_number =
8471 (offset_expr.X_add_number >> 16) & 0xffff;
8473 *offset_reloc = BFD_RELOC_LO16;
8477 case 'p': /* pc relative offset */
8478 if (mips_pic == EMBEDDED_PIC)
8479 *offset_reloc = BFD_RELOC_16_PCREL_S2;
8481 *offset_reloc = BFD_RELOC_16_PCREL;
8482 my_getExpression (&offset_expr, s);
8486 case 'u': /* upper 16 bits */
8487 c = my_getSmallExpression (&imm_expr, s);
8488 *imm_reloc = BFD_RELOC_LO16;
8493 if (imm_expr.X_op == O_constant)
8494 imm_expr.X_add_number =
8495 (imm_expr.X_add_number >> 16) & 0xffff;
8496 else if (c == S_EX_HI)
8498 *imm_reloc = BFD_RELOC_HI16_S;
8499 imm_unmatched_hi = true;
8502 else if (c == S_EX_HIGHEST)
8503 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8504 else if (c == S_EX_GP_REL)
8506 /* This occurs in NewABI only. */
8507 c = my_getSmallExpression (&imm_expr, s);
8509 as_bad (_("bad composition of relocations"));
8512 c = my_getSmallExpression (&imm_expr, s);
8514 as_bad (_("bad composition of relocations"));
8517 imm_reloc[0] = BFD_RELOC_GPREL16;
8518 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8519 imm_reloc[2] = BFD_RELOC_HI16_S;
8525 *imm_reloc = BFD_RELOC_HI16;
8527 else if (imm_expr.X_op == O_constant)
8528 imm_expr.X_add_number &= 0xffff;
8530 if (imm_expr.X_op == O_constant
8531 && (imm_expr.X_add_number < 0
8532 || imm_expr.X_add_number >= 0x10000))
8533 as_bad (_("lui expression not in range 0..65535"));
8537 case 'a': /* 26 bit address */
8538 my_getExpression (&offset_expr, s);
8540 *offset_reloc = BFD_RELOC_MIPS_JMP;
8543 case 'N': /* 3 bit branch condition code */
8544 case 'M': /* 3 bit compare condition code */
8545 if (strncmp (s, "$fcc", 4) != 0)
8555 while (ISDIGIT (*s));
8557 as_bad (_("invalid condition code register $fcc%d"), regno);
8559 ip->insn_opcode |= regno << OP_SH_BCC;
8561 ip->insn_opcode |= regno << OP_SH_CCC;
8565 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
8576 while (ISDIGIT (*s));
8579 c = 8; /* Invalid sel value. */
8582 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
8583 ip->insn_opcode |= c;
8587 as_bad (_("bad char = '%c'\n"), *args);
8592 /* Args don't match. */
8593 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8594 !strcmp (insn->name, insn[1].name))
8598 insn_error = _("illegal operands");
8603 insn_error = _("illegal operands");
8608 /* This routine assembles an instruction into its binary format when
8609 assembling for the mips16. As a side effect, it sets one of the
8610 global variables imm_reloc or offset_reloc to the type of
8611 relocation to do if one of the operands is an address expression.
8612 It also sets mips16_small and mips16_ext if the user explicitly
8613 requested a small or extended instruction. */
8618 struct mips_cl_insn *ip;
8622 struct mips_opcode *insn;
8625 unsigned int lastregno = 0;
8630 mips16_small = false;
8633 for (s = str; ISLOWER (*s); ++s)
8645 if (s[1] == 't' && s[2] == ' ')
8648 mips16_small = true;
8652 else if (s[1] == 'e' && s[2] == ' ')
8661 insn_error = _("unknown opcode");
8665 if (mips_opts.noautoextend && ! mips16_ext)
8666 mips16_small = true;
8668 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
8670 insn_error = _("unrecognized opcode");
8677 assert (strcmp (insn->name, str) == 0);
8680 ip->insn_opcode = insn->match;
8681 ip->use_extend = false;
8682 imm_expr.X_op = O_absent;
8683 imm_reloc[0] = BFD_RELOC_UNUSED;
8684 imm_reloc[1] = BFD_RELOC_UNUSED;
8685 imm_reloc[2] = BFD_RELOC_UNUSED;
8686 offset_expr.X_op = O_absent;
8687 offset_reloc[0] = BFD_RELOC_UNUSED;
8688 offset_reloc[1] = BFD_RELOC_UNUSED;
8689 offset_reloc[2] = BFD_RELOC_UNUSED;
8690 for (args = insn->args; 1; ++args)
8697 /* In this switch statement we call break if we did not find
8698 a match, continue if we did find a match, or return if we
8707 /* Stuff the immediate value in now, if we can. */
8708 if (imm_expr.X_op == O_constant
8709 && *imm_reloc > BFD_RELOC_UNUSED
8710 && insn->pinfo != INSN_MACRO)
8712 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
8713 imm_expr.X_add_number, true, mips16_small,
8714 mips16_ext, &ip->insn_opcode,
8715 &ip->use_extend, &ip->extend);
8716 imm_expr.X_op = O_absent;
8717 *imm_reloc = BFD_RELOC_UNUSED;
8731 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8734 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8750 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8752 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8779 while (ISDIGIT (*s));
8782 as_bad (_("invalid register number (%d)"), regno);
8788 if (s[1] == 'f' && s[2] == 'p')
8793 else if (s[1] == 's' && s[2] == 'p')
8798 else if (s[1] == 'g' && s[2] == 'p')
8803 else if (s[1] == 'a' && s[2] == 't')
8808 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8813 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8826 if (c == 'v' || c == 'w')
8828 regno = mips16_to_32_reg_map[lastregno];
8842 regno = mips32_to_16_reg_map[regno];
8847 regno = ILLEGAL_REG;
8852 regno = ILLEGAL_REG;
8857 regno = ILLEGAL_REG;
8862 if (regno == AT && ! mips_opts.noat)
8863 as_warn (_("used $at without \".set noat\""));
8870 if (regno == ILLEGAL_REG)
8877 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
8881 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
8884 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
8887 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
8893 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
8896 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
8897 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
8907 if (strncmp (s, "$pc", 3) == 0)
8931 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
8933 /* This is %gprel(SYMBOL). We need to read SYMBOL,
8934 and generate the appropriate reloc. If the text
8935 inside %gprel is not a symbol name with an
8936 optional offset, then we generate a normal reloc
8937 and will probably fail later. */
8938 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
8939 if (imm_expr.X_op == O_symbol)
8942 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
8944 ip->use_extend = true;
8951 /* Just pick up a normal expression. */
8952 my_getExpression (&imm_expr, s);
8955 if (imm_expr.X_op == O_register)
8957 /* What we thought was an expression turned out to
8960 if (s[0] == '(' && args[1] == '(')
8962 /* It looks like the expression was omitted
8963 before a register indirection, which means
8964 that the expression is implicitly zero. We
8965 still set up imm_expr, so that we handle
8966 explicit extensions correctly. */
8967 imm_expr.X_op = O_constant;
8968 imm_expr.X_add_number = 0;
8969 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
8976 /* We need to relax this instruction. */
8977 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
8986 /* We use offset_reloc rather than imm_reloc for the PC
8987 relative operands. This lets macros with both
8988 immediate and address operands work correctly. */
8989 my_getExpression (&offset_expr, s);
8991 if (offset_expr.X_op == O_register)
8994 /* We need to relax this instruction. */
8995 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
8999 case '6': /* break code */
9000 my_getExpression (&imm_expr, s);
9001 check_absolute_expr (ip, &imm_expr);
9002 if ((unsigned long) imm_expr.X_add_number > 63)
9004 as_warn (_("Invalid value for `%s' (%lu)"),
9006 (unsigned long) imm_expr.X_add_number);
9007 imm_expr.X_add_number &= 0x3f;
9009 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9010 imm_expr.X_op = O_absent;
9014 case 'a': /* 26 bit address */
9015 my_getExpression (&offset_expr, s);
9017 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9018 ip->insn_opcode <<= 16;
9021 case 'l': /* register list for entry macro */
9022 case 'L': /* register list for exit macro */
9032 int freg, reg1, reg2;
9034 while (*s == ' ' || *s == ',')
9038 as_bad (_("can't parse register list"));
9050 while (ISDIGIT (*s))
9072 as_bad (_("invalid register list"));
9077 while (ISDIGIT (*s))
9084 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9089 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9094 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9095 mask |= (reg2 - 3) << 3;
9096 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9097 mask |= (reg2 - 15) << 1;
9098 else if (reg1 == 31 && reg2 == 31)
9102 as_bad (_("invalid register list"));
9106 /* The mask is filled in in the opcode table for the
9107 benefit of the disassembler. We remove it before
9108 applying the actual mask. */
9109 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9110 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9114 case 'e': /* extend code */
9115 my_getExpression (&imm_expr, s);
9116 check_absolute_expr (ip, &imm_expr);
9117 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9119 as_warn (_("Invalid value for `%s' (%lu)"),
9121 (unsigned long) imm_expr.X_add_number);
9122 imm_expr.X_add_number &= 0x7ff;
9124 ip->insn_opcode |= imm_expr.X_add_number;
9125 imm_expr.X_op = O_absent;
9135 /* Args don't match. */
9136 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9137 strcmp (insn->name, insn[1].name) == 0)
9144 insn_error = _("illegal operands");
9150 /* This structure holds information we know about a mips16 immediate
9153 struct mips16_immed_operand
9155 /* The type code used in the argument string in the opcode table. */
9157 /* The number of bits in the short form of the opcode. */
9159 /* The number of bits in the extended form of the opcode. */
9161 /* The amount by which the short form is shifted when it is used;
9162 for example, the sw instruction has a shift count of 2. */
9164 /* The amount by which the short form is shifted when it is stored
9165 into the instruction code. */
9167 /* Non-zero if the short form is unsigned. */
9169 /* Non-zero if the extended form is unsigned. */
9171 /* Non-zero if the value is PC relative. */
9175 /* The mips16 immediate operand types. */
9177 static const struct mips16_immed_operand mips16_immed_operands[] =
9179 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9180 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9181 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9182 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9183 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9184 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9185 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9186 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9187 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9188 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9189 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9190 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9191 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9192 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9193 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9194 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9195 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9196 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9197 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9198 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9199 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9202 #define MIPS16_NUM_IMMED \
9203 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9205 /* Handle a mips16 instruction with an immediate value. This or's the
9206 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9207 whether an extended value is needed; if one is needed, it sets
9208 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9209 If SMALL is true, an unextended opcode was explicitly requested.
9210 If EXT is true, an extended opcode was explicitly requested. If
9211 WARN is true, warn if EXT does not match reality. */
9214 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
9223 unsigned long *insn;
9224 boolean *use_extend;
9225 unsigned short *extend;
9227 register const struct mips16_immed_operand *op;
9228 int mintiny, maxtiny;
9231 op = mips16_immed_operands;
9232 while (op->type != type)
9235 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9240 if (type == '<' || type == '>' || type == '[' || type == ']')
9243 maxtiny = 1 << op->nbits;
9248 maxtiny = (1 << op->nbits) - 1;
9253 mintiny = - (1 << (op->nbits - 1));
9254 maxtiny = (1 << (op->nbits - 1)) - 1;
9257 /* Branch offsets have an implicit 0 in the lowest bit. */
9258 if (type == 'p' || type == 'q')
9261 if ((val & ((1 << op->shift) - 1)) != 0
9262 || val < (mintiny << op->shift)
9263 || val > (maxtiny << op->shift))
9268 if (warn && ext && ! needext)
9269 as_warn_where (file, line,
9270 _("extended operand requested but not required"));
9271 if (small && needext)
9272 as_bad_where (file, line, _("invalid unextended operand value"));
9274 if (small || (! ext && ! needext))
9278 *use_extend = false;
9279 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9280 insnval <<= op->op_shift;
9285 long minext, maxext;
9291 maxext = (1 << op->extbits) - 1;
9295 minext = - (1 << (op->extbits - 1));
9296 maxext = (1 << (op->extbits - 1)) - 1;
9298 if (val < minext || val > maxext)
9299 as_bad_where (file, line,
9300 _("operand value out of range for instruction"));
9303 if (op->extbits == 16)
9305 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
9308 else if (op->extbits == 15)
9310 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
9315 extval = ((val & 0x1f) << 6) | (val & 0x20);
9319 *extend = (unsigned short) extval;
9324 static struct percent_op_match
9327 const enum small_ex_type type;
9332 {"%call_hi", S_EX_CALL_HI},
9333 {"%call_lo", S_EX_CALL_LO},
9334 {"%call16", S_EX_CALL16},
9335 {"%got_disp", S_EX_GOT_DISP},
9336 {"%got_page", S_EX_GOT_PAGE},
9337 {"%got_ofst", S_EX_GOT_OFST},
9338 {"%got_hi", S_EX_GOT_HI},
9339 {"%got_lo", S_EX_GOT_LO},
9341 {"%gp_rel", S_EX_GP_REL},
9342 {"%half", S_EX_HALF},
9343 {"%highest", S_EX_HIGHEST},
9344 {"%higher", S_EX_HIGHER},
9350 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9351 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9352 can be nested, this is handled by blanking the innermost, parsing the
9353 rest by subsequent calls. */
9356 my_getSmallParser (str, len, nestlevel)
9362 *str += strspn (*str, " \t");
9363 /* Check for expression in parentheses. */
9366 char *b = *str + 1 + strspn (*str + 1, " \t");
9369 /* Check for base register. */
9373 && (e = b + strcspn (b, ") \t"))
9374 && e - b > 1 && e - b < 4)
9377 && ((b[1] == 'f' && b[2] == 'p')
9378 || (b[1] == 's' && b[2] == 'p')
9379 || (b[1] == 'g' && b[2] == 'p')
9380 || (b[1] == 'a' && b[2] == 't')
9382 && ISDIGIT (b[2]))))
9383 || (ISDIGIT (b[1])))
9385 *len = strcspn (*str, ")") + 1;
9386 return S_EX_REGISTER;
9390 /* Check for percent_op (in parentheses). */
9391 else if (b[0] == '%')
9394 return my_getPercentOp (str, len, nestlevel);
9397 /* Some other expression in the parentheses, which can contain
9398 parentheses itself. Attempt to find the matching one. */
9404 for (s = *str + 1; *s && pcnt; s++, (*len)++)
9413 /* Check for percent_op (outside of parentheses). */
9414 else if (*str[0] == '%')
9415 return my_getPercentOp (str, len, nestlevel);
9417 /* Any other expression. */
9422 my_getPercentOp (str, len, nestlevel)
9427 char *tmp = *str + 1;
9430 while (ISALPHA (*tmp) || *tmp == '_')
9432 *tmp = TOLOWER (*tmp);
9435 while (i < (sizeof (percent_op) / sizeof (struct percent_op_match)))
9437 if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str)))
9441 int type = percent_op[i].type;
9443 /* Only %hi and %lo are allowed for OldABI. */
9444 if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO)
9447 *len = strlen (percent_op[i].str);
9456 my_getSmallExpression (ep, str)
9460 static char *oldstr = NULL;
9466 /* Don't update oldstr if the last call had nested percent_op's. We need
9467 it to parse the outer ones later. */
9474 c = my_getSmallParser (&str, &len, &nestlevel);
9475 if (c != S_EX_NONE && c != S_EX_REGISTER)
9478 while (c != S_EX_NONE && c != S_EX_REGISTER);
9482 /* A percent_op was encountered. Don't try to get an expression if
9483 it is already blanked out. */
9484 if (*(str + strspn (str + 1, " )")) != ')')
9488 /* Let my_getExpression() stop at the closing parenthesis. */
9489 save = *(str + len);
9490 *(str + len) = '\0';
9491 my_getExpression (ep, str);
9492 *(str + len) = save;
9496 /* Blank out including the % sign and the proper matching
9499 char *s = strrchr (oldstr, '%');
9502 for (end = strchr (s, '(') + 1; *end && pcnt; end++)
9506 else if (*end == ')')
9510 memset (s, ' ', end - s);
9514 expr_end = str + len;
9518 else if (c == S_EX_NONE)
9520 my_getExpression (ep, str);
9522 else if (c == S_EX_REGISTER)
9524 ep->X_op = O_constant;
9526 ep->X_add_symbol = NULL;
9527 ep->X_op_symbol = NULL;
9528 ep->X_add_number = 0;
9532 as_fatal(_("internal error"));
9536 /* All percent_op's have been handled. */
9543 my_getExpression (ep, str)
9550 save_in = input_line_pointer;
9551 input_line_pointer = str;
9553 expr_end = input_line_pointer;
9554 input_line_pointer = save_in;
9556 /* If we are in mips16 mode, and this is an expression based on `.',
9557 then we bump the value of the symbol by 1 since that is how other
9558 text symbols are handled. We don't bother to handle complex
9559 expressions, just `.' plus or minus a constant. */
9560 if (mips_opts.mips16
9561 && ep->X_op == O_symbol
9562 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
9563 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
9564 && symbol_get_frag (ep->X_add_symbol) == frag_now
9565 && symbol_constant_p (ep->X_add_symbol)
9566 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
9567 S_SET_VALUE (ep->X_add_symbol, val + 1);
9570 /* Turn a string in input_line_pointer into a floating point constant
9571 of type TYPE, and store the appropriate bytes in *LITP. The number
9572 of LITTLENUMS emitted is stored in *SIZEP. An error message is
9573 returned, or NULL on OK. */
9576 md_atof (type, litP, sizeP)
9582 LITTLENUM_TYPE words[4];
9598 return _("bad call to md_atof");
9601 t = atof_ieee (input_line_pointer, type, words);
9603 input_line_pointer = t;
9607 if (! target_big_endian)
9609 for (i = prec - 1; i >= 0; i--)
9611 md_number_to_chars (litP, (valueT) words[i], 2);
9617 for (i = 0; i < prec; i++)
9619 md_number_to_chars (litP, (valueT) words[i], 2);
9628 md_number_to_chars (buf, val, n)
9633 if (target_big_endian)
9634 number_to_chars_bigendian (buf, val, n);
9636 number_to_chars_littleendian (buf, val, n);
9640 static int support_64bit_objects(void)
9642 const char **list, **l;
9644 list = bfd_target_list ();
9645 for (l = list; *l != NULL; l++)
9647 /* This is traditional mips */
9648 if (strcmp (*l, "elf64-tradbigmips") == 0
9649 || strcmp (*l, "elf64-tradlittlemips") == 0)
9651 if (strcmp (*l, "elf64-bigmips") == 0
9652 || strcmp (*l, "elf64-littlemips") == 0)
9656 return (*l != NULL);
9658 #endif /* OBJ_ELF */
9660 CONST char *md_shortopts = "nO::g::G:";
9662 struct option md_longopts[] =
9664 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
9665 {"mips0", no_argument, NULL, OPTION_MIPS1},
9666 {"mips1", no_argument, NULL, OPTION_MIPS1},
9667 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
9668 {"mips2", no_argument, NULL, OPTION_MIPS2},
9669 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
9670 {"mips3", no_argument, NULL, OPTION_MIPS3},
9671 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
9672 {"mips4", no_argument, NULL, OPTION_MIPS4},
9673 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
9674 {"mips5", no_argument, NULL, OPTION_MIPS5},
9675 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
9676 {"mips32", no_argument, NULL, OPTION_MIPS32},
9677 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
9678 {"mips64", no_argument, NULL, OPTION_MIPS64},
9679 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
9680 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
9681 #define OPTION_TRAP (OPTION_MD_BASE + 9)
9682 {"trap", no_argument, NULL, OPTION_TRAP},
9683 {"no-break", no_argument, NULL, OPTION_TRAP},
9684 #define OPTION_BREAK (OPTION_MD_BASE + 10)
9685 {"break", no_argument, NULL, OPTION_BREAK},
9686 {"no-trap", no_argument, NULL, OPTION_BREAK},
9687 #define OPTION_EB (OPTION_MD_BASE + 11)
9688 {"EB", no_argument, NULL, OPTION_EB},
9689 #define OPTION_EL (OPTION_MD_BASE + 12)
9690 {"EL", no_argument, NULL, OPTION_EL},
9691 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
9692 {"mips16", no_argument, NULL, OPTION_MIPS16},
9693 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
9694 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
9695 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
9696 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
9697 #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 16)
9698 {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX},
9699 #define OPTION_FP32 (OPTION_MD_BASE + 17)
9700 {"mfp32", no_argument, NULL, OPTION_FP32},
9701 #define OPTION_GP32 (OPTION_MD_BASE + 18)
9702 {"mgp32", no_argument, NULL, OPTION_GP32},
9703 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
9704 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
9705 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
9706 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
9707 #define OPTION_MARCH (OPTION_MD_BASE + 21)
9708 {"march", required_argument, NULL, OPTION_MARCH},
9709 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
9710 {"mtune", required_argument, NULL, OPTION_MTUNE},
9711 #define OPTION_MCPU (OPTION_MD_BASE + 23)
9712 {"mcpu", required_argument, NULL, OPTION_MCPU},
9713 #define OPTION_M4650 (OPTION_MD_BASE + 24)
9714 {"m4650", no_argument, NULL, OPTION_M4650},
9715 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
9716 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
9717 #define OPTION_M4010 (OPTION_MD_BASE + 26)
9718 {"m4010", no_argument, NULL, OPTION_M4010},
9719 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
9720 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
9721 #define OPTION_M4100 (OPTION_MD_BASE + 28)
9722 {"m4100", no_argument, NULL, OPTION_M4100},
9723 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
9724 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
9725 #define OPTION_M3900 (OPTION_MD_BASE + 30)
9726 {"m3900", no_argument, NULL, OPTION_M3900},
9727 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
9728 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
9729 #define OPTION_GP64 (OPTION_MD_BASE + 32)
9730 {"mgp64", no_argument, NULL, OPTION_GP64},
9732 #define OPTION_ELF_BASE (OPTION_MD_BASE + 33)
9733 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
9734 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
9735 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
9736 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
9737 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
9738 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
9739 {"xgot", no_argument, NULL, OPTION_XGOT},
9740 #define OPTION_MABI (OPTION_ELF_BASE + 3)
9741 {"mabi", required_argument, NULL, OPTION_MABI},
9742 #define OPTION_32 (OPTION_ELF_BASE + 4)
9743 {"32", no_argument, NULL, OPTION_32},
9744 #define OPTION_N32 (OPTION_ELF_BASE + 5)
9745 {"n32", no_argument, NULL, OPTION_N32},
9746 #define OPTION_64 (OPTION_ELF_BASE + 6)
9747 {"64", no_argument, NULL, OPTION_64},
9748 #endif /* OBJ_ELF */
9749 {NULL, no_argument, NULL, 0}
9751 size_t md_longopts_size = sizeof (md_longopts);
9754 md_parse_option (c, arg)
9760 case OPTION_CONSTRUCT_FLOATS:
9761 mips_disable_float_construction = 0;
9764 case OPTION_NO_CONSTRUCT_FLOATS:
9765 mips_disable_float_construction = 1;
9777 target_big_endian = 1;
9781 target_big_endian = 0;
9789 if (arg && arg[1] == '0')
9799 mips_debug = atoi (arg);
9800 /* When the MIPS assembler sees -g or -g2, it does not do
9801 optimizations which limit full symbolic debugging. We take
9802 that to be equivalent to -O0. */
9803 if (mips_debug == 2)
9808 mips_opts.isa = ISA_MIPS1;
9812 mips_opts.isa = ISA_MIPS2;
9816 mips_opts.isa = ISA_MIPS3;
9820 mips_opts.isa = ISA_MIPS4;
9824 mips_opts.isa = ISA_MIPS5;
9828 mips_opts.isa = ISA_MIPS32;
9832 mips_opts.isa = ISA_MIPS64;
9839 int cpu = CPU_UNKNOWN;
9841 /* Identify the processor type. */
9842 if (strcasecmp (arg, "default") != 0)
9844 const struct mips_cpu_info *ci;
9846 ci = mips_cpu_info_from_name (arg);
9847 if (ci == NULL || ci->is_isa)
9852 as_fatal (_("invalid architecture -mtune=%s"), arg);
9855 as_fatal (_("invalid architecture -march=%s"), arg);
9858 as_fatal (_("invalid architecture -mcpu=%s"), arg);
9869 if (mips_tune != CPU_UNKNOWN && mips_tune != cpu)
9870 as_warn(_("A different -mtune= was already specified, is now "
9875 if (mips_arch != CPU_UNKNOWN && mips_arch != cpu)
9876 as_warn(_("A different -march= was already specified, is now "
9881 if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu)
9882 as_warn(_("A different -mcpu= was already specified, is now "
9890 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650)
9891 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650))
9892 as_warn(_("A different -march= or -mtune= was already specified, "
9894 mips_arch = CPU_R4650;
9895 mips_tune = CPU_R4650;
9898 case OPTION_NO_M4650:
9902 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010)
9903 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010))
9904 as_warn(_("A different -march= or -mtune= was already specified, "
9906 mips_arch = CPU_R4010;
9907 mips_tune = CPU_R4010;
9910 case OPTION_NO_M4010:
9914 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100)
9915 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100))
9916 as_warn(_("A different -march= or -mtune= was already specified, "
9918 mips_arch = CPU_VR4100;
9919 mips_tune = CPU_VR4100;
9922 case OPTION_NO_M4100:
9926 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900)
9927 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900))
9928 as_warn(_("A different -march= or -mtune= was already specified, "
9930 mips_arch = CPU_R3900;
9931 mips_tune = CPU_R3900;
9934 case OPTION_NO_M3900:
9938 mips_opts.mips16 = 1;
9939 mips_no_prev_insn (false);
9942 case OPTION_NO_MIPS16:
9943 mips_opts.mips16 = 0;
9944 mips_no_prev_insn (false);
9947 case OPTION_MEMBEDDED_PIC:
9948 mips_pic = EMBEDDED_PIC;
9949 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
9951 as_bad (_("-G may not be used with embedded PIC code"));
9954 g_switch_value = 0x7fffffff;
9958 /* When generating ELF code, we permit -KPIC and -call_shared to
9959 select SVR4_PIC, and -non_shared to select no PIC. This is
9960 intended to be compatible with Irix 5. */
9961 case OPTION_CALL_SHARED:
9962 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9964 as_bad (_("-call_shared is supported only for ELF format"));
9967 mips_pic = SVR4_PIC;
9968 if (g_switch_seen && g_switch_value != 0)
9970 as_bad (_("-G may not be used with SVR4 PIC code"));
9976 case OPTION_NON_SHARED:
9977 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9979 as_bad (_("-non_shared is supported only for ELF format"));
9985 /* The -xgot option tells the assembler to use 32 offsets when
9986 accessing the got in SVR4_PIC mode. It is for Irix
9991 #endif /* OBJ_ELF */
9994 if (! USE_GLOBAL_POINTER_OPT)
9996 as_bad (_("-G is not supported for this configuration"));
9999 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10001 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10005 g_switch_value = atoi (arg);
10010 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10013 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10015 as_bad (_("-32 is supported for ELF format only"));
10018 mips_opts.abi = O32_ABI;
10022 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10024 as_bad (_("-n32 is supported for ELF format only"));
10027 mips_opts.abi = N32_ABI;
10031 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10033 as_bad (_("-64 is supported for ELF format only"));
10036 mips_opts.abi = N64_ABI;
10037 if (! support_64bit_objects())
10038 as_fatal (_("No compiled in support for 64 bit object file format"));
10040 #endif /* OBJ_ELF */
10043 file_mips_gp32 = 1;
10044 if (mips_opts.abi != O32_ABI)
10045 mips_opts.abi = NO_ABI;
10049 file_mips_gp32 = 0;
10050 if (mips_opts.abi == O32_ABI)
10051 mips_opts.abi = NO_ABI;
10055 file_mips_fp32 = 1;
10056 if (mips_opts.abi != O32_ABI)
10057 mips_opts.abi = NO_ABI;
10062 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10064 as_bad (_("-mabi is supported for ELF format only"));
10067 if (strcmp (arg, "32") == 0)
10068 mips_opts.abi = O32_ABI;
10069 else if (strcmp (arg, "o64") == 0)
10070 mips_opts.abi = O64_ABI;
10071 else if (strcmp (arg, "n32") == 0)
10072 mips_opts.abi = N32_ABI;
10073 else if (strcmp (arg, "64") == 0)
10075 mips_opts.abi = N64_ABI;
10076 if (! support_64bit_objects())
10077 as_fatal (_("No compiled in support for 64 bit object file "
10080 else if (strcmp (arg, "eabi") == 0)
10081 mips_opts.abi = EABI_ABI;
10084 as_fatal (_("invalid abi -mabi=%s"), arg);
10088 #endif /* OBJ_ELF */
10090 case OPTION_M7000_HILO_FIX:
10091 mips_7000_hilo_fix = true;
10094 case OPTION_NO_M7000_HILO_FIX:
10095 mips_7000_hilo_fix = false;
10106 show (stream, string, col_p, first_p)
10114 fprintf (stream, "%24s", "");
10119 fprintf (stream, ", ");
10123 if (*col_p + strlen (string) > 72)
10125 fprintf (stream, "\n%24s", "");
10129 fprintf (stream, "%s", string);
10130 *col_p += strlen (string);
10136 md_show_usage (stream)
10141 fprintf (stream, _("\
10143 -membedded-pic generate embedded position independent code\n\
10144 -EB generate big endian output\n\
10145 -EL generate little endian output\n\
10146 -g, -g2 do not remove unneeded NOPs or swap branches\n\
10147 -G NUM allow referencing objects up to NUM bytes\n\
10148 implicitly with the gp register [default 8]\n"));
10149 fprintf (stream, _("\
10150 -mips1 generate MIPS ISA I instructions\n\
10151 -mips2 generate MIPS ISA II instructions\n\
10152 -mips3 generate MIPS ISA III instructions\n\
10153 -mips4 generate MIPS ISA IV instructions\n\
10154 -mips5 generate MIPS ISA V instructions\n\
10155 -mips32 generate MIPS32 ISA instructions\n\
10156 -mips64 generate MIPS64 ISA instructions\n\
10157 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
10161 show (stream, "2000", &column, &first);
10162 show (stream, "3000", &column, &first);
10163 show (stream, "3900", &column, &first);
10164 show (stream, "4000", &column, &first);
10165 show (stream, "4010", &column, &first);
10166 show (stream, "4100", &column, &first);
10167 show (stream, "4111", &column, &first);
10168 show (stream, "4300", &column, &first);
10169 show (stream, "4400", &column, &first);
10170 show (stream, "4600", &column, &first);
10171 show (stream, "4650", &column, &first);
10172 show (stream, "5000", &column, &first);
10173 show (stream, "5200", &column, &first);
10174 show (stream, "5230", &column, &first);
10175 show (stream, "5231", &column, &first);
10176 show (stream, "5261", &column, &first);
10177 show (stream, "5721", &column, &first);
10178 show (stream, "6000", &column, &first);
10179 show (stream, "8000", &column, &first);
10180 show (stream, "10000", &column, &first);
10181 show (stream, "12000", &column, &first);
10182 show (stream, "sb1", &column, &first);
10183 fputc ('\n', stream);
10185 fprintf (stream, _("\
10186 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
10187 -no-mCPU don't generate code specific to CPU.\n\
10188 For -mCPU and -no-mCPU, CPU must be one of:\n"));
10192 show (stream, "3900", &column, &first);
10193 show (stream, "4010", &column, &first);
10194 show (stream, "4100", &column, &first);
10195 show (stream, "4650", &column, &first);
10196 fputc ('\n', stream);
10198 fprintf (stream, _("\
10199 -mips16 generate mips16 instructions\n\
10200 -no-mips16 do not generate mips16 instructions\n"));
10201 fprintf (stream, _("\
10202 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
10203 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
10204 -O0 remove unneeded NOPs, do not swap branches\n\
10205 -O remove unneeded NOPs and swap branches\n\
10206 -n warn about NOPs generated from macros\n\
10207 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
10208 --trap, --no-break trap exception on div by 0 and mult overflow\n\
10209 --break, --no-trap break exception on div by 0 and mult overflow\n"));
10211 fprintf (stream, _("\
10212 -KPIC, -call_shared generate SVR4 position independent code\n\
10213 -non_shared do not generate position independent code\n\
10214 -xgot assume a 32 bit GOT\n\
10215 -mabi=ABI create ABI conformant object file for:\n"));
10219 show (stream, "32", &column, &first);
10220 show (stream, "o64", &column, &first);
10221 show (stream, "n32", &column, &first);
10222 show (stream, "64", &column, &first);
10223 show (stream, "eabi", &column, &first);
10225 fputc ('\n', stream);
10227 fprintf (stream, _("\
10228 -32 create o32 ABI object file (default)\n\
10229 -n32 create n32 ABI object file\n\
10230 -64 create 64 ABI object file\n"));
10235 mips_init_after_args ()
10237 /* initialize opcodes */
10238 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10239 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10243 md_pcrel_from (fixP)
10246 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
10247 && fixP->fx_addsy != (symbolS *) NULL
10248 && ! S_IS_DEFINED (fixP->fx_addsy))
10250 /* This makes a branch to an undefined symbol be a branch to the
10251 current location. */
10252 if (mips_pic == EMBEDDED_PIC)
10258 /* return the address of the delay slot */
10259 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
10262 /* This is called before the symbol table is processed. In order to
10263 work with gcc when using mips-tfile, we must keep all local labels.
10264 However, in other cases, we want to discard them. If we were
10265 called with -g, but we didn't see any debugging information, it may
10266 mean that gcc is smuggling debugging information through to
10267 mips-tfile, in which case we must generate all local labels. */
10270 mips_frob_file_before_adjust ()
10272 #ifndef NO_ECOFF_DEBUGGING
10273 if (ECOFF_DEBUGGING
10275 && ! ecoff_debugging_seen)
10276 flag_keep_locals = 1;
10280 /* Sort any unmatched HI16_S relocs so that they immediately precede
10281 the corresponding LO reloc. This is called before md_apply_fix3 and
10282 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10283 explicit use of the %hi modifier. */
10288 struct mips_hi_fixup *l;
10290 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
10292 segment_info_type *seginfo;
10295 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
10297 /* Check quickly whether the next fixup happens to be a matching
10299 if (l->fixp->fx_next != NULL
10300 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
10301 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
10302 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
10305 /* Look through the fixups for this segment for a matching %lo.
10306 When we find one, move the %hi just in front of it. We do
10307 this in two passes. In the first pass, we try to find a
10308 unique %lo. In the second pass, we permit multiple %hi
10309 relocs for a single %lo (this is a GNU extension). */
10310 seginfo = seg_info (l->seg);
10311 for (pass = 0; pass < 2; pass++)
10316 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
10318 /* Check whether this is a %lo fixup which matches l->fixp. */
10319 if (f->fx_r_type == BFD_RELOC_LO16
10320 && f->fx_addsy == l->fixp->fx_addsy
10321 && f->fx_offset == l->fixp->fx_offset
10324 || prev->fx_r_type != BFD_RELOC_HI16_S
10325 || prev->fx_addsy != f->fx_addsy
10326 || prev->fx_offset != f->fx_offset))
10330 /* Move l->fixp before f. */
10331 for (pf = &seginfo->fix_root;
10333 pf = &(*pf)->fx_next)
10334 assert (*pf != NULL);
10336 *pf = l->fixp->fx_next;
10338 l->fixp->fx_next = f;
10340 seginfo->fix_root = l->fixp;
10342 prev->fx_next = l->fixp;
10353 #if 0 /* GCC code motion plus incomplete dead code elimination
10354 can leave a %hi without a %lo. */
10356 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
10357 _("Unmatched %%hi reloc"));
10363 /* When generating embedded PIC code we need to use a special
10364 relocation to represent the difference of two symbols in the .text
10365 section (switch tables use a difference of this sort). See
10366 include/coff/mips.h for details. This macro checks whether this
10367 fixup requires the special reloc. */
10368 #define SWITCH_TABLE(fixp) \
10369 ((fixp)->fx_r_type == BFD_RELOC_32 \
10370 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10371 && (fixp)->fx_addsy != NULL \
10372 && (fixp)->fx_subsy != NULL \
10373 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10374 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10376 /* When generating embedded PIC code we must keep all PC relative
10377 relocations, in case the linker has to relax a call. We also need
10378 to keep relocations for switch table entries.
10380 We may have combined relocations without symbols in the N32/N64 ABI.
10381 We have to prevent gas from dropping them. */
10384 mips_force_relocation (fixp)
10387 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10388 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
10392 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
10393 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
10394 || fixp->fx_r_type == BFD_RELOC_HI16_S
10395 || fixp->fx_r_type == BFD_RELOC_LO16))
10398 return (mips_pic == EMBEDDED_PIC
10400 || SWITCH_TABLE (fixp)
10401 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
10402 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
10407 mips_need_elf_addend_fixup (fixP)
10410 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
10412 if ((S_IS_WEAK (fixP->fx_addsy)
10413 || S_IS_EXTERN (fixP->fx_addsy))
10414 && !S_IS_COMMON (fixP->fx_addsy))
10416 if (symbol_used_in_reloc_p (fixP->fx_addsy)
10417 && (((bfd_get_section_flags (stdoutput,
10418 S_GET_SEGMENT (fixP->fx_addsy))
10419 & SEC_LINK_ONCE) != 0)
10420 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
10422 sizeof (".gnu.linkonce") - 1)))
10428 /* Apply a fixup to the object file. */
10431 md_apply_fix3 (fixP, valP, seg)
10434 segT seg ATTRIBUTE_UNUSED;
10436 unsigned char *buf;
10440 assert (fixP->fx_size == 4
10441 || fixP->fx_r_type == BFD_RELOC_16
10442 || fixP->fx_r_type == BFD_RELOC_32
10443 || fixP->fx_r_type == BFD_RELOC_MIPS_JMP
10444 || fixP->fx_r_type == BFD_RELOC_HI16_S
10445 || fixP->fx_r_type == BFD_RELOC_LO16
10446 || fixP->fx_r_type == BFD_RELOC_GPREL16
10447 || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL
10448 || fixP->fx_r_type == BFD_RELOC_GPREL32
10449 || fixP->fx_r_type == BFD_RELOC_64
10450 || fixP->fx_r_type == BFD_RELOC_CTOR
10451 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
10452 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST
10453 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER
10454 || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP
10455 || fixP->fx_r_type == BFD_RELOC_MIPS_REL16
10456 || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT
10457 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10458 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
10462 /* If we aren't adjusting this fixup to be against the section
10463 symbol, we need to adjust the value. */
10465 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
10467 if (mips_need_elf_addend_fixup (fixP))
10469 valueT symval = S_GET_VALUE (fixP->fx_addsy);
10472 if (value != 0 && ! fixP->fx_pcrel)
10474 /* In this case, the bfd_install_relocation routine will
10475 incorrectly add the symbol value back in. We just want
10476 the addend to appear in the object file. */
10479 /* Make sure the addend is still non-zero. If it became zero
10480 after the last operation, set it to a spurious value and
10481 subtract the same value from the object file's contents. */
10486 /* The in-place addends for LO16 relocations are signed;
10487 leave the matching HI16 in-place addends as zero. */
10488 if (fixP->fx_r_type != BFD_RELOC_HI16_S)
10490 reloc_howto_type *howto;
10491 bfd_vma contents, mask, field;
10493 howto = bfd_reloc_type_lookup (stdoutput,
10496 contents = bfd_get_bits (fixP->fx_frag->fr_literal
10499 target_big_endian);
10501 /* MASK has bits set where the relocation should go.
10502 FIELD is -value, shifted into the appropriate place
10503 for this relocation. */
10504 mask = 1 << (howto->bitsize - 1);
10505 mask = (((mask - 1) << 1) | 1) << howto->bitpos;
10506 field = (-value >> howto->rightshift) << howto->bitpos;
10508 bfd_put_bits ((field & mask) | (contents & ~mask),
10509 fixP->fx_frag->fr_literal + fixP->fx_where,
10511 target_big_endian);
10517 /* This code was generated using trial and error and so is
10518 fragile and not trustworthy. If you change it, you should
10519 rerun the elf-rel, elf-rel2, and empic testcases and ensure
10520 they still pass. */
10521 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
10523 value += fixP->fx_frag->fr_address + fixP->fx_where;
10525 /* BFD's REL handling, for MIPS, is _very_ weird.
10526 This gives the right results, but it can't possibly
10527 be the way things are supposed to work. */
10528 if ((fixP->fx_r_type != BFD_RELOC_16_PCREL
10529 && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
10530 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
10531 value += fixP->fx_frag->fr_address + fixP->fx_where;
10536 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */
10538 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
10541 switch (fixP->fx_r_type)
10543 case BFD_RELOC_MIPS_JMP:
10544 case BFD_RELOC_MIPS_SHIFT5:
10545 case BFD_RELOC_MIPS_SHIFT6:
10546 case BFD_RELOC_MIPS_GOT_DISP:
10547 case BFD_RELOC_MIPS_GOT_PAGE:
10548 case BFD_RELOC_MIPS_GOT_OFST:
10549 case BFD_RELOC_MIPS_SUB:
10550 case BFD_RELOC_MIPS_INSERT_A:
10551 case BFD_RELOC_MIPS_INSERT_B:
10552 case BFD_RELOC_MIPS_DELETE:
10553 case BFD_RELOC_MIPS_HIGHEST:
10554 case BFD_RELOC_MIPS_HIGHER:
10555 case BFD_RELOC_MIPS_SCN_DISP:
10556 case BFD_RELOC_MIPS_REL16:
10557 case BFD_RELOC_MIPS_RELGOT:
10558 case BFD_RELOC_MIPS_JALR:
10559 case BFD_RELOC_HI16:
10560 case BFD_RELOC_HI16_S:
10561 case BFD_RELOC_GPREL16:
10562 case BFD_RELOC_MIPS_LITERAL:
10563 case BFD_RELOC_MIPS_CALL16:
10564 case BFD_RELOC_MIPS_GOT16:
10565 case BFD_RELOC_GPREL32:
10566 case BFD_RELOC_MIPS_GOT_HI16:
10567 case BFD_RELOC_MIPS_GOT_LO16:
10568 case BFD_RELOC_MIPS_CALL_HI16:
10569 case BFD_RELOC_MIPS_CALL_LO16:
10570 case BFD_RELOC_MIPS16_GPREL:
10571 if (fixP->fx_pcrel)
10572 as_bad_where (fixP->fx_file, fixP->fx_line,
10573 _("Invalid PC relative reloc"));
10574 /* Nothing needed to do. The value comes from the reloc entry */
10577 case BFD_RELOC_MIPS16_JMP:
10578 /* We currently always generate a reloc against a symbol, which
10579 means that we don't want an addend even if the symbol is
10581 fixP->fx_addnumber = 0;
10584 case BFD_RELOC_PCREL_HI16_S:
10585 /* The addend for this is tricky if it is internal, so we just
10586 do everything here rather than in bfd_install_relocation. */
10587 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10592 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10594 /* For an external symbol adjust by the address to make it
10595 pcrel_offset. We use the address of the RELLO reloc
10596 which follows this one. */
10597 value += (fixP->fx_next->fx_frag->fr_address
10598 + fixP->fx_next->fx_where);
10600 value = ((value + 0x8000) >> 16) & 0xffff;
10601 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
10602 if (target_big_endian)
10604 md_number_to_chars (buf, value, 2);
10607 case BFD_RELOC_PCREL_LO16:
10608 /* The addend for this is tricky if it is internal, so we just
10609 do everything here rather than in bfd_install_relocation. */
10610 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10615 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10616 value += fixP->fx_frag->fr_address + fixP->fx_where;
10617 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
10618 if (target_big_endian)
10620 md_number_to_chars (buf, value, 2);
10624 /* This is handled like BFD_RELOC_32, but we output a sign
10625 extended value if we are only 32 bits. */
10627 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10629 if (8 <= sizeof (valueT))
10630 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10637 w1 = w2 = fixP->fx_where;
10638 if (target_big_endian)
10642 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
10643 if ((value & 0x80000000) != 0)
10647 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
10652 case BFD_RELOC_RVA:
10654 /* If we are deleting this reloc entry, we must fill in the
10655 value now. This can happen if we have a .word which is not
10656 resolved when it appears but is later defined. We also need
10657 to fill in the value if this is an embedded PIC switch table
10660 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10661 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10666 /* If we are deleting this reloc entry, we must fill in the
10668 assert (fixP->fx_size == 2);
10670 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10674 case BFD_RELOC_LO16:
10675 /* When handling an embedded PIC switch statement, we can wind
10676 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
10679 if (value + 0x8000 > 0xffff)
10680 as_bad_where (fixP->fx_file, fixP->fx_line,
10681 _("relocation overflow"));
10682 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
10683 if (target_big_endian)
10685 md_number_to_chars (buf, value, 2);
10689 case BFD_RELOC_16_PCREL_S2:
10690 if ((value & 0x3) != 0)
10691 as_bad_where (fixP->fx_file, fixP->fx_line,
10692 _("Branch to odd address (%lx)"), (long) value);
10694 /* Fall through. */
10696 case BFD_RELOC_16_PCREL:
10698 * We need to save the bits in the instruction since fixup_segment()
10699 * might be deleting the relocation entry (i.e., a branch within
10700 * the current segment).
10702 if (!fixP->fx_done && value != 0)
10704 /* If 'value' is zero, the remaining reloc code won't actually
10705 do the store, so it must be done here. This is probably
10706 a bug somewhere. */
10707 if (!fixP->fx_done)
10708 value -= fixP->fx_frag->fr_address + fixP->fx_where;
10710 value = (offsetT) value >> 2;
10712 /* update old instruction data */
10713 buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal);
10714 if (target_big_endian)
10715 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
10717 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
10719 if (value + 0x8000 <= 0xffff)
10720 insn |= value & 0xffff;
10723 /* The branch offset is too large. If this is an
10724 unconditional branch, and we are not generating PIC code,
10725 we can convert it to an absolute jump instruction. */
10726 if (mips_pic == NO_PIC
10728 && fixP->fx_frag->fr_address >= text_section->vma
10729 && (fixP->fx_frag->fr_address
10730 < text_section->vma + text_section->_raw_size)
10731 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
10732 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
10733 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
10735 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
10736 insn = 0x0c000000; /* jal */
10738 insn = 0x08000000; /* j */
10739 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
10741 fixP->fx_addsy = section_symbol (text_section);
10742 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
10746 /* FIXME. It would be possible in principle to handle
10747 conditional branches which overflow. They could be
10748 transformed into a branch around a jump. This would
10749 require setting up variant frags for each different
10750 branch type. The native MIPS assembler attempts to
10751 handle these cases, but it appears to do it
10753 as_bad_where (fixP->fx_file, fixP->fx_line,
10754 _("Branch out of range"));
10758 md_number_to_chars ((char *) buf, (valueT) insn, 4);
10761 case BFD_RELOC_VTABLE_INHERIT:
10764 && !S_IS_DEFINED (fixP->fx_addsy)
10765 && !S_IS_WEAK (fixP->fx_addsy))
10766 S_SET_WEAK (fixP->fx_addsy);
10769 case BFD_RELOC_VTABLE_ENTRY:
10783 const struct mips_opcode *p;
10784 int treg, sreg, dreg, shamt;
10789 for (i = 0; i < NUMOPCODES; ++i)
10791 p = &mips_opcodes[i];
10792 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
10794 printf ("%08lx %s\t", oc, p->name);
10795 treg = (oc >> 16) & 0x1f;
10796 sreg = (oc >> 21) & 0x1f;
10797 dreg = (oc >> 11) & 0x1f;
10798 shamt = (oc >> 6) & 0x1f;
10800 for (args = p->args;; ++args)
10811 printf ("%c", *args);
10815 assert (treg == sreg);
10816 printf ("$%d,$%d", treg, sreg);
10821 printf ("$%d", dreg);
10826 printf ("$%d", treg);
10830 printf ("0x%x", treg);
10835 printf ("$%d", sreg);
10839 printf ("0x%08lx", oc & 0x1ffffff);
10846 printf ("%d", imm);
10851 printf ("$%d", shamt);
10862 printf (_("%08lx UNDEFINED\n"), oc);
10873 name = input_line_pointer;
10874 c = get_symbol_end ();
10875 p = (symbolS *) symbol_find_or_make (name);
10876 *input_line_pointer = c;
10880 /* Align the current frag to a given power of two. The MIPS assembler
10881 also automatically adjusts any preceding label. */
10884 mips_align (to, fill, label)
10889 mips_emit_delays (false);
10890 frag_align (to, fill, 0);
10891 record_alignment (now_seg, to);
10894 assert (S_GET_SEGMENT (label) == now_seg);
10895 symbol_set_frag (label, frag_now);
10896 S_SET_VALUE (label, (valueT) frag_now_fix ());
10900 /* Align to a given power of two. .align 0 turns off the automatic
10901 alignment used by the data creating pseudo-ops. */
10905 int x ATTRIBUTE_UNUSED;
10908 register long temp_fill;
10909 long max_alignment = 15;
10913 o Note that the assembler pulls down any immediately preceeding label
10914 to the aligned address.
10915 o It's not documented but auto alignment is reinstated by
10916 a .align pseudo instruction.
10917 o Note also that after auto alignment is turned off the mips assembler
10918 issues an error on attempt to assemble an improperly aligned data item.
10923 temp = get_absolute_expression ();
10924 if (temp > max_alignment)
10925 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
10928 as_warn (_("Alignment negative: 0 assumed."));
10931 if (*input_line_pointer == ',')
10933 input_line_pointer++;
10934 temp_fill = get_absolute_expression ();
10941 mips_align (temp, (int) temp_fill,
10942 insn_labels != NULL ? insn_labels->label : NULL);
10949 demand_empty_rest_of_line ();
10953 mips_flush_pending_output ()
10955 mips_emit_delays (false);
10956 mips_clear_insn_labels ();
10965 /* When generating embedded PIC code, we only use the .text, .lit8,
10966 .sdata and .sbss sections. We change the .data and .rdata
10967 pseudo-ops to use .sdata. */
10968 if (mips_pic == EMBEDDED_PIC
10969 && (sec == 'd' || sec == 'r'))
10973 /* The ELF backend needs to know that we are changing sections, so
10974 that .previous works correctly. We could do something like check
10975 for an obj_section_change_hook macro, but that might be confusing
10976 as it would not be appropriate to use it in the section changing
10977 functions in read.c, since obj-elf.c intercepts those. FIXME:
10978 This should be cleaner, somehow. */
10979 obj_elf_section_change_hook ();
10982 mips_emit_delays (false);
10992 subseg_set (bss_section, (subsegT) get_absolute_expression ());
10993 demand_empty_rest_of_line ();
10997 if (USE_GLOBAL_POINTER_OPT)
10999 seg = subseg_new (RDATA_SECTION_NAME,
11000 (subsegT) get_absolute_expression ());
11001 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11003 bfd_set_section_flags (stdoutput, seg,
11009 if (strcmp (TARGET_OS, "elf") != 0)
11010 record_alignment (seg, 4);
11012 demand_empty_rest_of_line ();
11016 as_bad (_("No read only data section in this object file format"));
11017 demand_empty_rest_of_line ();
11023 if (USE_GLOBAL_POINTER_OPT)
11025 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11026 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11028 bfd_set_section_flags (stdoutput, seg,
11029 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11031 if (strcmp (TARGET_OS, "elf") != 0)
11032 record_alignment (seg, 4);
11034 demand_empty_rest_of_line ();
11039 as_bad (_("Global pointers not supported; recompile -G 0"));
11040 demand_empty_rest_of_line ();
11049 mips_enable_auto_align ()
11060 label = insn_labels != NULL ? insn_labels->label : NULL;
11061 mips_emit_delays (false);
11062 if (log_size > 0 && auto_align)
11063 mips_align (log_size, 0, label);
11064 mips_clear_insn_labels ();
11065 cons (1 << log_size);
11069 s_float_cons (type)
11074 label = insn_labels != NULL ? insn_labels->label : NULL;
11076 mips_emit_delays (false);
11081 mips_align (3, 0, label);
11083 mips_align (2, 0, label);
11086 mips_clear_insn_labels ();
11091 /* Handle .globl. We need to override it because on Irix 5 you are
11094 where foo is an undefined symbol, to mean that foo should be
11095 considered to be the address of a function. */
11099 int x ATTRIBUTE_UNUSED;
11106 name = input_line_pointer;
11107 c = get_symbol_end ();
11108 symbolP = symbol_find_or_make (name);
11109 *input_line_pointer = c;
11110 SKIP_WHITESPACE ();
11112 /* On Irix 5, every global symbol that is not explicitly labelled as
11113 being a function is apparently labelled as being an object. */
11116 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11121 secname = input_line_pointer;
11122 c = get_symbol_end ();
11123 sec = bfd_get_section_by_name (stdoutput, secname);
11125 as_bad (_("%s: no such section"), secname);
11126 *input_line_pointer = c;
11128 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11129 flag = BSF_FUNCTION;
11132 symbol_get_bfdsym (symbolP)->flags |= flag;
11134 S_SET_EXTERNAL (symbolP);
11135 demand_empty_rest_of_line ();
11140 int x ATTRIBUTE_UNUSED;
11145 opt = input_line_pointer;
11146 c = get_symbol_end ();
11150 /* FIXME: What does this mean? */
11152 else if (strncmp (opt, "pic", 3) == 0)
11156 i = atoi (opt + 3);
11160 mips_pic = SVR4_PIC;
11162 as_bad (_(".option pic%d not supported"), i);
11164 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
11166 if (g_switch_seen && g_switch_value != 0)
11167 as_warn (_("-G may not be used with SVR4 PIC code"));
11168 g_switch_value = 0;
11169 bfd_set_gp_size (stdoutput, 0);
11173 as_warn (_("Unrecognized option \"%s\""), opt);
11175 *input_line_pointer = c;
11176 demand_empty_rest_of_line ();
11179 /* This structure is used to hold a stack of .set values. */
11181 struct mips_option_stack
11183 struct mips_option_stack *next;
11184 struct mips_set_options options;
11187 static struct mips_option_stack *mips_opts_stack;
11189 /* Handle the .set pseudo-op. */
11193 int x ATTRIBUTE_UNUSED;
11195 char *name = input_line_pointer, ch;
11197 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11198 input_line_pointer++;
11199 ch = *input_line_pointer;
11200 *input_line_pointer = '\0';
11202 if (strcmp (name, "reorder") == 0)
11204 if (mips_opts.noreorder && prev_nop_frag != NULL)
11206 /* If we still have pending nops, we can discard them. The
11207 usual nop handling will insert any that are still
11209 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11210 * (mips_opts.mips16 ? 2 : 4));
11211 prev_nop_frag = NULL;
11213 mips_opts.noreorder = 0;
11215 else if (strcmp (name, "noreorder") == 0)
11217 mips_emit_delays (true);
11218 mips_opts.noreorder = 1;
11219 mips_any_noreorder = 1;
11221 else if (strcmp (name, "at") == 0)
11223 mips_opts.noat = 0;
11225 else if (strcmp (name, "noat") == 0)
11227 mips_opts.noat = 1;
11229 else if (strcmp (name, "macro") == 0)
11231 mips_opts.warn_about_macros = 0;
11233 else if (strcmp (name, "nomacro") == 0)
11235 if (mips_opts.noreorder == 0)
11236 as_bad (_("`noreorder' must be set before `nomacro'"));
11237 mips_opts.warn_about_macros = 1;
11239 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11241 mips_opts.nomove = 0;
11243 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11245 mips_opts.nomove = 1;
11247 else if (strcmp (name, "bopt") == 0)
11249 mips_opts.nobopt = 0;
11251 else if (strcmp (name, "nobopt") == 0)
11253 mips_opts.nobopt = 1;
11255 else if (strcmp (name, "mips16") == 0
11256 || strcmp (name, "MIPS-16") == 0)
11257 mips_opts.mips16 = 1;
11258 else if (strcmp (name, "nomips16") == 0
11259 || strcmp (name, "noMIPS-16") == 0)
11260 mips_opts.mips16 = 0;
11261 else if (strncmp (name, "mips", 4) == 0)
11265 /* Permit the user to change the ISA on the fly. Needless to
11266 say, misuse can cause serious problems. */
11267 isa = atoi (name + 4);
11271 mips_opts.gp32 = file_mips_gp32;
11272 mips_opts.fp32 = file_mips_fp32;
11273 mips_opts.abi = file_mips_abi;
11278 mips_opts.gp32 = 1;
11279 mips_opts.fp32 = 1;
11285 /* Loosen ABI register width restriction. */
11286 if (mips_opts.abi == O32_ABI)
11287 mips_opts.abi = NO_ABI;
11288 mips_opts.gp32 = 0;
11289 mips_opts.fp32 = 0;
11292 as_bad (_("unknown ISA level %s"), name + 4);
11298 case 0: mips_opts.isa = file_mips_isa; break;
11299 case 1: mips_opts.isa = ISA_MIPS1; break;
11300 case 2: mips_opts.isa = ISA_MIPS2; break;
11301 case 3: mips_opts.isa = ISA_MIPS3; break;
11302 case 4: mips_opts.isa = ISA_MIPS4; break;
11303 case 5: mips_opts.isa = ISA_MIPS5; break;
11304 case 32: mips_opts.isa = ISA_MIPS32; break;
11305 case 64: mips_opts.isa = ISA_MIPS64; break;
11306 default: as_bad (_("unknown ISA level %s"), name + 4); break;
11309 else if (strcmp (name, "autoextend") == 0)
11310 mips_opts.noautoextend = 0;
11311 else if (strcmp (name, "noautoextend") == 0)
11312 mips_opts.noautoextend = 1;
11313 else if (strcmp (name, "push") == 0)
11315 struct mips_option_stack *s;
11317 s = (struct mips_option_stack *) xmalloc (sizeof *s);
11318 s->next = mips_opts_stack;
11319 s->options = mips_opts;
11320 mips_opts_stack = s;
11322 else if (strcmp (name, "pop") == 0)
11324 struct mips_option_stack *s;
11326 s = mips_opts_stack;
11328 as_bad (_(".set pop with no .set push"));
11331 /* If we're changing the reorder mode we need to handle
11332 delay slots correctly. */
11333 if (s->options.noreorder && ! mips_opts.noreorder)
11334 mips_emit_delays (true);
11335 else if (! s->options.noreorder && mips_opts.noreorder)
11337 if (prev_nop_frag != NULL)
11339 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11340 * (mips_opts.mips16 ? 2 : 4));
11341 prev_nop_frag = NULL;
11345 mips_opts = s->options;
11346 mips_opts_stack = s->next;
11352 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
11354 *input_line_pointer = ch;
11355 demand_empty_rest_of_line ();
11358 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11359 .option pic2. It means to generate SVR4 PIC calls. */
11362 s_abicalls (ignore)
11363 int ignore ATTRIBUTE_UNUSED;
11365 mips_pic = SVR4_PIC;
11366 if (USE_GLOBAL_POINTER_OPT)
11368 if (g_switch_seen && g_switch_value != 0)
11369 as_warn (_("-G may not be used with SVR4 PIC code"));
11370 g_switch_value = 0;
11372 bfd_set_gp_size (stdoutput, 0);
11373 demand_empty_rest_of_line ();
11376 /* Handle the .cpload pseudo-op. This is used when generating SVR4
11377 PIC code. It sets the $gp register for the function based on the
11378 function address, which is in the register named in the argument.
11379 This uses a relocation against _gp_disp, which is handled specially
11380 by the linker. The result is:
11381 lui $gp,%hi(_gp_disp)
11382 addiu $gp,$gp,%lo(_gp_disp)
11383 addu $gp,$gp,.cpload argument
11384 The .cpload argument is normally $25 == $t9. */
11388 int ignore ATTRIBUTE_UNUSED;
11393 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11394 .cpload is ignored. */
11395 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11401 /* .cpload should be in a .set noreorder section. */
11402 if (mips_opts.noreorder == 0)
11403 as_warn (_(".cpload not in noreorder section"));
11405 ex.X_op = O_symbol;
11406 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
11407 ex.X_op_symbol = NULL;
11408 ex.X_add_number = 0;
11410 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
11411 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
11413 macro_build_lui (NULL, &icnt, &ex, GP);
11414 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP,
11415 (int) BFD_RELOC_LO16);
11417 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
11418 GP, GP, tc_get_register (0));
11420 demand_empty_rest_of_line ();
11423 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
11424 .cpsetup $reg1, offset|$reg2, label
11426 If offset is given, this results in:
11427 sd $gp, offset($sp)
11428 lui $gp, %hi(%neg(%gp_rel(label)))
11429 daddiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11430 addu $gp, $gp, $reg1
11432 If $reg2 is given, this results in:
11433 daddu $reg2, $gp, $0
11434 lui $gp, %hi(%neg(%gp_rel(label)))
11435 daddiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11436 addu $gp, $gp, $reg1
11440 int ignore ATTRIBUTE_UNUSED;
11442 expressionS ex_off;
11443 expressionS ex_sym;
11448 /* If we are not generating SVR4 PIC code, .cpload is ignored.
11449 We also need NewABI support. */
11450 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11456 reg1 = tc_get_register (0);
11457 SKIP_WHITESPACE ();
11458 if (*input_line_pointer != ',')
11460 as_bad (_("missing argument separator ',' for .cpsetup"));
11464 input_line_pointer++;
11465 SKIP_WHITESPACE ();
11466 if (*input_line_pointer == '$')
11467 mips_cpreturn_register = tc_get_register (0);
11469 mips_cpreturn_offset = get_absolute_expression ();
11470 SKIP_WHITESPACE ();
11471 if (*input_line_pointer != ',')
11473 as_bad (_("missing argument separator ',' for .cpsetup"));
11477 input_line_pointer++;
11478 SKIP_WHITESPACE ();
11479 sym = input_line_pointer;
11480 while (ISALNUM (*input_line_pointer))
11481 input_line_pointer++;
11482 *input_line_pointer = 0;
11484 ex_sym.X_op = O_symbol;
11485 ex_sym.X_add_symbol = symbol_find_or_make (sym);
11486 ex_sym.X_op_symbol = NULL;
11487 ex_sym.X_add_number = 0;
11489 if (mips_cpreturn_register == -1)
11491 ex_off.X_op = O_constant;
11492 ex_off.X_add_symbol = NULL;
11493 ex_off.X_op_symbol = NULL;
11494 ex_off.X_add_number = mips_cpreturn_offset;
11496 macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)",
11497 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11500 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11501 "d,v,t", mips_cpreturn_register, mips_gp_register, 0);
11503 macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
11504 (int) BFD_RELOC_GPREL16);
11505 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11506 NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11507 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11508 NULL, 0, 0, BFD_RELOC_HI16_S);
11509 macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j",
11510 mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16);
11511 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11512 NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11513 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11514 NULL, 0, 0, BFD_RELOC_LO16);
11515 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11516 "d,v,t", mips_gp_register, mips_gp_register, reg1);
11518 demand_empty_rest_of_line ();
11523 int ignore ATTRIBUTE_UNUSED;
11525 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
11526 .cplocal is ignored. */
11527 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11533 mips_gp_register = tc_get_register (0);
11536 /* Handle the .cprestore pseudo-op. This stores $gp into a given
11537 offset from $sp. The offset is remembered, and after making a PIC
11538 call $gp is restored from that location. */
11541 s_cprestore (ignore)
11542 int ignore ATTRIBUTE_UNUSED;
11547 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11548 .cprestore is ignored. */
11549 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11555 mips_cprestore_offset = get_absolute_expression ();
11556 mips_cprestore_valid = 1;
11558 ex.X_op = O_constant;
11559 ex.X_add_symbol = NULL;
11560 ex.X_op_symbol = NULL;
11561 ex.X_add_number = mips_cprestore_offset;
11563 macro_build ((char *) NULL, &icnt, &ex,
11564 HAVE_32BIT_ADDRESSES ? "sw" : "sd",
11565 "t,o(b)", GP, (int) BFD_RELOC_LO16, SP);
11567 demand_empty_rest_of_line ();
11570 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
11571 was given in the preceeding .gpsetup, it results in:
11572 ld $gp, offset($sp)
11574 If a register $reg2 was given there, it results in:
11575 daddiu $gp, $gp, $reg2
11578 s_cpreturn (ignore)
11579 int ignore ATTRIBUTE_UNUSED;
11584 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
11585 We also need NewABI support. */
11586 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11592 if (mips_cpreturn_register == -1)
11594 ex.X_op = O_constant;
11595 ex.X_add_symbol = NULL;
11596 ex.X_op_symbol = NULL;
11597 ex.X_add_number = mips_cpreturn_offset;
11599 macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)",
11600 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11603 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11604 "d,v,t", mips_gp_register, mips_cpreturn_register, 0);
11606 demand_empty_rest_of_line ();
11609 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
11610 code. It sets the offset to use in gp_rel relocations. */
11614 int ignore ATTRIBUTE_UNUSED;
11616 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
11617 We also need NewABI support. */
11618 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11624 mips_cpreturn_offset = get_absolute_expression ();
11626 demand_empty_rest_of_line ();
11629 /* Handle the .gpword pseudo-op. This is used when generating PIC
11630 code. It generates a 32 bit GP relative reloc. */
11634 int ignore ATTRIBUTE_UNUSED;
11640 /* When not generating PIC code, this is treated as .word. */
11641 if (mips_pic != SVR4_PIC)
11647 label = insn_labels != NULL ? insn_labels->label : NULL;
11648 mips_emit_delays (true);
11650 mips_align (2, 0, label);
11651 mips_clear_insn_labels ();
11655 if (ex.X_op != O_symbol || ex.X_add_number != 0)
11657 as_bad (_("Unsupported use of .gpword"));
11658 ignore_rest_of_line ();
11662 md_number_to_chars (p, (valueT) 0, 4);
11663 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0,
11664 BFD_RELOC_GPREL32);
11666 demand_empty_rest_of_line ();
11669 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
11670 tables in SVR4 PIC code. */
11674 int ignore ATTRIBUTE_UNUSED;
11679 /* This is ignored when not generating SVR4 PIC code or if this is NewABI
11681 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11687 /* Add $gp to the register named as an argument. */
11688 reg = tc_get_register (0);
11689 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11690 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
11691 "d,v,t", reg, reg, GP);
11693 demand_empty_rest_of_line ();
11696 /* Handle the .insn pseudo-op. This marks instruction labels in
11697 mips16 mode. This permits the linker to handle them specially,
11698 such as generating jalx instructions when needed. We also make
11699 them odd for the duration of the assembly, in order to generate the
11700 right sort of code. We will make them even in the adjust_symtab
11701 routine, while leaving them marked. This is convenient for the
11702 debugger and the disassembler. The linker knows to make them odd
11707 int ignore ATTRIBUTE_UNUSED;
11709 if (mips_opts.mips16)
11710 mips16_mark_labels ();
11712 demand_empty_rest_of_line ();
11715 /* Handle a .stabn directive. We need these in order to mark a label
11716 as being a mips16 text label correctly. Sometimes the compiler
11717 will emit a label, followed by a .stabn, and then switch sections.
11718 If the label and .stabn are in mips16 mode, then the label is
11719 really a mips16 text label. */
11725 if (type == 'n' && mips_opts.mips16)
11726 mips16_mark_labels ();
11731 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
11735 s_mips_weakext (ignore)
11736 int ignore ATTRIBUTE_UNUSED;
11743 name = input_line_pointer;
11744 c = get_symbol_end ();
11745 symbolP = symbol_find_or_make (name);
11746 S_SET_WEAK (symbolP);
11747 *input_line_pointer = c;
11749 SKIP_WHITESPACE ();
11751 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11753 if (S_IS_DEFINED (symbolP))
11755 as_bad ("ignoring attempt to redefine symbol %s",
11756 S_GET_NAME (symbolP));
11757 ignore_rest_of_line ();
11761 if (*input_line_pointer == ',')
11763 ++input_line_pointer;
11764 SKIP_WHITESPACE ();
11768 if (exp.X_op != O_symbol)
11770 as_bad ("bad .weakext directive");
11771 ignore_rest_of_line();
11774 symbol_set_value_expression (symbolP, &exp);
11777 demand_empty_rest_of_line ();
11780 /* Parse a register string into a number. Called from the ECOFF code
11781 to parse .frame. The argument is non-zero if this is the frame
11782 register, so that we can record it in mips_frame_reg. */
11785 tc_get_register (frame)
11790 SKIP_WHITESPACE ();
11791 if (*input_line_pointer++ != '$')
11793 as_warn (_("expected `$'"));
11796 else if (ISDIGIT (*input_line_pointer))
11798 reg = get_absolute_expression ();
11799 if (reg < 0 || reg >= 32)
11801 as_warn (_("Bad register number"));
11807 if (strncmp (input_line_pointer, "fp", 2) == 0)
11809 else if (strncmp (input_line_pointer, "sp", 2) == 0)
11811 else if (strncmp (input_line_pointer, "gp", 2) == 0)
11813 else if (strncmp (input_line_pointer, "at", 2) == 0)
11817 as_warn (_("Unrecognized register name"));
11820 input_line_pointer += 2;
11824 mips_frame_reg = reg != 0 ? reg : SP;
11825 mips_frame_reg_valid = 1;
11826 mips_cprestore_valid = 0;
11832 md_section_align (seg, addr)
11836 int align = bfd_get_section_alignment (stdoutput, seg);
11839 /* We don't need to align ELF sections to the full alignment.
11840 However, Irix 5 may prefer that we align them at least to a 16
11841 byte boundary. We don't bother to align the sections if we are
11842 targeted for an embedded system. */
11843 if (strcmp (TARGET_OS, "elf") == 0)
11849 return ((addr + (1 << align) - 1) & (-1 << align));
11852 /* Utility routine, called from above as well. If called while the
11853 input file is still being read, it's only an approximation. (For
11854 example, a symbol may later become defined which appeared to be
11855 undefined earlier.) */
11858 nopic_need_relax (sym, before_relaxing)
11860 int before_relaxing;
11865 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
11867 const char *symname;
11870 /* Find out whether this symbol can be referenced off the GP
11871 register. It can be if it is smaller than the -G size or if
11872 it is in the .sdata or .sbss section. Certain symbols can
11873 not be referenced off the GP, although it appears as though
11875 symname = S_GET_NAME (sym);
11876 if (symname != (const char *) NULL
11877 && (strcmp (symname, "eprol") == 0
11878 || strcmp (symname, "etext") == 0
11879 || strcmp (symname, "_gp") == 0
11880 || strcmp (symname, "edata") == 0
11881 || strcmp (symname, "_fbss") == 0
11882 || strcmp (symname, "_fdata") == 0
11883 || strcmp (symname, "_ftext") == 0
11884 || strcmp (symname, "end") == 0
11885 || strcmp (symname, "_gp_disp") == 0))
11887 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
11889 #ifndef NO_ECOFF_DEBUGGING
11890 || (symbol_get_obj (sym)->ecoff_extern_size != 0
11891 && (symbol_get_obj (sym)->ecoff_extern_size
11892 <= g_switch_value))
11894 /* We must defer this decision until after the whole
11895 file has been read, since there might be a .extern
11896 after the first use of this symbol. */
11897 || (before_relaxing
11898 #ifndef NO_ECOFF_DEBUGGING
11899 && symbol_get_obj (sym)->ecoff_extern_size == 0
11901 && S_GET_VALUE (sym) == 0)
11902 || (S_GET_VALUE (sym) != 0
11903 && S_GET_VALUE (sym) <= g_switch_value)))
11907 const char *segname;
11909 segname = segment_name (S_GET_SEGMENT (sym));
11910 assert (strcmp (segname, ".lit8") != 0
11911 && strcmp (segname, ".lit4") != 0);
11912 change = (strcmp (segname, ".sdata") != 0
11913 && strcmp (segname, ".sbss") != 0
11914 && strncmp (segname, ".sdata.", 7) != 0
11915 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
11920 /* We are not optimizing for the GP register. */
11924 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
11925 extended opcode. SEC is the section the frag is in. */
11928 mips16_extended_frag (fragp, sec, stretch)
11934 register const struct mips16_immed_operand *op;
11936 int mintiny, maxtiny;
11940 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
11942 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
11945 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
11946 op = mips16_immed_operands;
11947 while (op->type != type)
11950 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
11955 if (type == '<' || type == '>' || type == '[' || type == ']')
11958 maxtiny = 1 << op->nbits;
11963 maxtiny = (1 << op->nbits) - 1;
11968 mintiny = - (1 << (op->nbits - 1));
11969 maxtiny = (1 << (op->nbits - 1)) - 1;
11972 sym_frag = symbol_get_frag (fragp->fr_symbol);
11973 val = S_GET_VALUE (fragp->fr_symbol);
11974 symsec = S_GET_SEGMENT (fragp->fr_symbol);
11980 /* We won't have the section when we are called from
11981 mips_relax_frag. However, we will always have been called
11982 from md_estimate_size_before_relax first. If this is a
11983 branch to a different section, we mark it as such. If SEC is
11984 NULL, and the frag is not marked, then it must be a branch to
11985 the same section. */
11988 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
11993 /* Must have been called from md_estimate_size_before_relax. */
11996 fragp->fr_subtype =
11997 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
11999 /* FIXME: We should support this, and let the linker
12000 catch branches and loads that are out of range. */
12001 as_bad_where (fragp->fr_file, fragp->fr_line,
12002 _("unsupported PC relative reference to different section"));
12006 if (fragp != sym_frag && sym_frag->fr_address == 0)
12007 /* Assume non-extended on the first relaxation pass.
12008 The address we have calculated will be bogus if this is
12009 a forward branch to another frag, as the forward frag
12010 will have fr_address == 0. */
12014 /* In this case, we know for sure that the symbol fragment is in
12015 the same section. If the relax_marker of the symbol fragment
12016 differs from the relax_marker of this fragment, we have not
12017 yet adjusted the symbol fragment fr_address. We want to add
12018 in STRETCH in order to get a better estimate of the address.
12019 This particularly matters because of the shift bits. */
12021 && sym_frag->relax_marker != fragp->relax_marker)
12025 /* Adjust stretch for any alignment frag. Note that if have
12026 been expanding the earlier code, the symbol may be
12027 defined in what appears to be an earlier frag. FIXME:
12028 This doesn't handle the fr_subtype field, which specifies
12029 a maximum number of bytes to skip when doing an
12031 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
12033 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
12036 stretch = - ((- stretch)
12037 & ~ ((1 << (int) f->fr_offset) - 1));
12039 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
12048 addr = fragp->fr_address + fragp->fr_fix;
12050 /* The base address rules are complicated. The base address of
12051 a branch is the following instruction. The base address of a
12052 PC relative load or add is the instruction itself, but if it
12053 is in a delay slot (in which case it can not be extended) use
12054 the address of the instruction whose delay slot it is in. */
12055 if (type == 'p' || type == 'q')
12059 /* If we are currently assuming that this frag should be
12060 extended, then, the current address is two bytes
12062 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12065 /* Ignore the low bit in the target, since it will be set
12066 for a text label. */
12067 if ((val & 1) != 0)
12070 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12072 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12075 val -= addr & ~ ((1 << op->shift) - 1);
12077 /* Branch offsets have an implicit 0 in the lowest bit. */
12078 if (type == 'p' || type == 'q')
12081 /* If any of the shifted bits are set, we must use an extended
12082 opcode. If the address depends on the size of this
12083 instruction, this can lead to a loop, so we arrange to always
12084 use an extended opcode. We only check this when we are in
12085 the main relaxation loop, when SEC is NULL. */
12086 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
12088 fragp->fr_subtype =
12089 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12093 /* If we are about to mark a frag as extended because the value
12094 is precisely maxtiny + 1, then there is a chance of an
12095 infinite loop as in the following code:
12100 In this case when the la is extended, foo is 0x3fc bytes
12101 away, so the la can be shrunk, but then foo is 0x400 away, so
12102 the la must be extended. To avoid this loop, we mark the
12103 frag as extended if it was small, and is about to become
12104 extended with a value of maxtiny + 1. */
12105 if (val == ((maxtiny + 1) << op->shift)
12106 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
12109 fragp->fr_subtype =
12110 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12114 else if (symsec != absolute_section && sec != NULL)
12115 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
12117 if ((val & ((1 << op->shift) - 1)) != 0
12118 || val < (mintiny << op->shift)
12119 || val > (maxtiny << op->shift))
12125 /* Estimate the size of a frag before relaxing. Unless this is the
12126 mips16, we are not really relaxing here, and the final size is
12127 encoded in the subtype information. For the mips16, we have to
12128 decide whether we are using an extended opcode or not. */
12131 md_estimate_size_before_relax (fragp, segtype)
12136 boolean linkonce = false;
12138 if (RELAX_MIPS16_P (fragp->fr_subtype))
12140 if (mips16_extended_frag (fragp, segtype, 0))
12142 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
12147 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
12152 if (mips_pic == NO_PIC)
12154 change = nopic_need_relax (fragp->fr_symbol, 0);
12156 else if (mips_pic == SVR4_PIC)
12161 sym = fragp->fr_symbol;
12163 /* Handle the case of a symbol equated to another symbol. */
12164 while (symbol_equated_reloc_p (sym))
12168 /* It's possible to get a loop here in a badly written
12170 n = symbol_get_value_expression (sym)->X_add_symbol;
12176 symsec = S_GET_SEGMENT (sym);
12178 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12179 if (symsec != segtype && ! S_IS_LOCAL (sym))
12181 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12185 /* The GNU toolchain uses an extension for ELF: a section
12186 beginning with the magic string .gnu.linkonce is a linkonce
12188 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12189 sizeof ".gnu.linkonce" - 1) == 0)
12193 /* This must duplicate the test in adjust_reloc_syms. */
12194 change = (symsec != &bfd_und_section
12195 && symsec != &bfd_abs_section
12196 && ! bfd_is_com_section (symsec)
12199 /* A global or weak symbol is treated as external. */
12200 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12201 || (! S_IS_EXTERN (sym) && ! S_IS_WEAK (sym)))
12210 /* Record the offset to the first reloc in the fr_opcode field.
12211 This lets md_convert_frag and tc_gen_reloc know that the code
12212 must be expanded. */
12213 fragp->fr_opcode = (fragp->fr_literal
12215 - RELAX_OLD (fragp->fr_subtype)
12216 + RELAX_RELOC1 (fragp->fr_subtype));
12217 /* FIXME: This really needs as_warn_where. */
12218 if (RELAX_WARN (fragp->fr_subtype))
12219 as_warn (_("AT used after \".set noat\" or macro used after "
12220 "\".set nomacro\""));
12222 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
12228 /* This is called to see whether a reloc against a defined symbol
12229 should be converted into a reloc against a section. Don't adjust
12230 MIPS16 jump relocations, so we don't have to worry about the format
12231 of the offset in the .o file. Don't adjust relocations against
12232 mips16 symbols, so that the linker can find them if it needs to set
12236 mips_fix_adjustable (fixp)
12240 /* Prevent all adjustments to global symbols. */
12241 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12242 && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
12245 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
12247 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12248 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12250 if (fixp->fx_addsy == NULL)
12253 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12254 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
12255 && fixp->fx_subsy == NULL)
12261 /* Translate internal representation of relocation info to BFD target
12265 tc_gen_reloc (section, fixp)
12266 asection *section ATTRIBUTE_UNUSED;
12269 static arelent *retval[4];
12271 bfd_reloc_code_real_type code;
12273 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
12276 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12277 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12278 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12280 if (mips_pic == EMBEDDED_PIC
12281 && SWITCH_TABLE (fixp))
12283 /* For a switch table entry we use a special reloc. The addend
12284 is actually the difference between the reloc address and the
12286 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12287 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
12288 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
12289 fixp->fx_r_type = BFD_RELOC_GPREL32;
12291 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
12293 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12294 reloc->addend = fixp->fx_addnumber;
12297 /* We use a special addend for an internal RELLO reloc. */
12298 if (symbol_section_p (fixp->fx_addsy))
12299 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12301 reloc->addend = fixp->fx_addnumber + reloc->address;
12304 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
12306 assert (fixp->fx_next != NULL
12307 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
12309 /* The reloc is relative to the RELLO; adjust the addend
12311 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12312 reloc->addend = fixp->fx_next->fx_addnumber;
12315 /* We use a special addend for an internal RELHI reloc. */
12316 if (symbol_section_p (fixp->fx_addsy))
12317 reloc->addend = (fixp->fx_next->fx_frag->fr_address
12318 + fixp->fx_next->fx_where
12319 - S_GET_VALUE (fixp->fx_subsy));
12321 reloc->addend = (fixp->fx_addnumber
12322 + fixp->fx_next->fx_frag->fr_address
12323 + fixp->fx_next->fx_where);
12326 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12327 reloc->addend = fixp->fx_addnumber;
12330 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
12331 /* A gruesome hack which is a result of the gruesome gas reloc
12333 reloc->addend = reloc->address;
12335 reloc->addend = -reloc->address;
12338 /* If this is a variant frag, we may need to adjust the existing
12339 reloc and generate a new one. */
12340 if (fixp->fx_frag->fr_opcode != NULL
12341 && (fixp->fx_r_type == BFD_RELOC_GPREL16
12342 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
12343 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
12344 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12345 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
12346 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12347 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
12352 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
12354 /* If this is not the last reloc in this frag, then we have two
12355 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
12356 CALL_HI16/CALL_LO16, both of which are being replaced. Let
12357 the second one handle all of them. */
12358 if (fixp->fx_next != NULL
12359 && fixp->fx_frag == fixp->fx_next->fx_frag)
12361 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
12362 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
12363 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12364 && (fixp->fx_next->fx_r_type
12365 == BFD_RELOC_MIPS_GOT_LO16))
12366 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12367 && (fixp->fx_next->fx_r_type
12368 == BFD_RELOC_MIPS_CALL_LO16)));
12373 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
12374 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12375 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
12377 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12378 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12379 reloc2->address = (reloc->address
12380 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
12381 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
12382 reloc2->addend = fixp->fx_addnumber;
12383 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
12384 assert (reloc2->howto != NULL);
12386 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
12390 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
12393 reloc3->address += 4;
12396 if (mips_pic == NO_PIC)
12398 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
12399 fixp->fx_r_type = BFD_RELOC_HI16_S;
12401 else if (mips_pic == SVR4_PIC)
12403 switch (fixp->fx_r_type)
12407 case BFD_RELOC_MIPS_GOT16:
12409 case BFD_RELOC_MIPS_CALL16:
12410 case BFD_RELOC_MIPS_GOT_LO16:
12411 case BFD_RELOC_MIPS_CALL_LO16:
12412 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
12420 /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry
12421 to be used in the relocation's section offset. */
12422 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12424 reloc->address = reloc->addend;
12428 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
12429 fixup_segment converted a non-PC relative reloc into a PC
12430 relative reloc. In such a case, we need to convert the reloc
12432 code = fixp->fx_r_type;
12433 if (fixp->fx_pcrel)
12438 code = BFD_RELOC_8_PCREL;
12441 code = BFD_RELOC_16_PCREL;
12444 code = BFD_RELOC_32_PCREL;
12447 code = BFD_RELOC_64_PCREL;
12449 case BFD_RELOC_8_PCREL:
12450 case BFD_RELOC_16_PCREL:
12451 case BFD_RELOC_32_PCREL:
12452 case BFD_RELOC_64_PCREL:
12453 case BFD_RELOC_16_PCREL_S2:
12454 case BFD_RELOC_PCREL_HI16_S:
12455 case BFD_RELOC_PCREL_LO16:
12458 as_bad_where (fixp->fx_file, fixp->fx_line,
12459 _("Cannot make %s relocation PC relative"),
12460 bfd_get_reloc_code_name (code));
12465 /* md_apply_fix3 has a double-subtraction hack to get
12466 bfd_install_relocation to behave nicely. GPREL relocations are
12467 handled correctly without this hack, so undo it here. We can't
12468 stop md_apply_fix3 from subtracting twice in the first place since
12469 the fake addend is required for variant frags above. */
12470 if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
12471 && code == BFD_RELOC_GPREL16
12472 && reloc->addend != 0
12473 && mips_need_elf_addend_fixup (fixp))
12474 reloc->addend += S_GET_VALUE (fixp->fx_addsy);
12477 /* To support a PC relative reloc when generating embedded PIC code
12478 for ECOFF, we use a Cygnus extension. We check for that here to
12479 make sure that we don't let such a reloc escape normally. */
12480 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
12481 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12482 && code == BFD_RELOC_16_PCREL_S2
12483 && mips_pic != EMBEDDED_PIC)
12484 reloc->howto = NULL;
12486 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12488 if (reloc->howto == NULL)
12490 as_bad_where (fixp->fx_file, fixp->fx_line,
12491 _("Can not represent %s relocation in this object file format"),
12492 bfd_get_reloc_code_name (code));
12499 /* Relax a machine dependent frag. This returns the amount by which
12500 the current size of the frag should change. */
12503 mips_relax_frag (fragp, stretch)
12507 if (! RELAX_MIPS16_P (fragp->fr_subtype))
12510 if (mips16_extended_frag (fragp, NULL, stretch))
12512 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12514 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
12519 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12521 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
12528 /* Convert a machine dependent frag. */
12531 md_convert_frag (abfd, asec, fragp)
12532 bfd *abfd ATTRIBUTE_UNUSED;
12539 if (RELAX_MIPS16_P (fragp->fr_subtype))
12542 register const struct mips16_immed_operand *op;
12543 boolean small, ext;
12546 unsigned long insn;
12547 boolean use_extend;
12548 unsigned short extend;
12550 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12551 op = mips16_immed_operands;
12552 while (op->type != type)
12555 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12566 resolve_symbol_value (fragp->fr_symbol);
12567 val = S_GET_VALUE (fragp->fr_symbol);
12572 addr = fragp->fr_address + fragp->fr_fix;
12574 /* The rules for the base address of a PC relative reloc are
12575 complicated; see mips16_extended_frag. */
12576 if (type == 'p' || type == 'q')
12581 /* Ignore the low bit in the target, since it will be
12582 set for a text label. */
12583 if ((val & 1) != 0)
12586 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12588 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12591 addr &= ~ (addressT) ((1 << op->shift) - 1);
12594 /* Make sure the section winds up with the alignment we have
12597 record_alignment (asec, op->shift);
12601 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
12602 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
12603 as_warn_where (fragp->fr_file, fragp->fr_line,
12604 _("extended instruction in delay slot"));
12606 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
12608 if (target_big_endian)
12609 insn = bfd_getb16 (buf);
12611 insn = bfd_getl16 (buf);
12613 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
12614 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
12615 small, ext, &insn, &use_extend, &extend);
12619 md_number_to_chars (buf, 0xf000 | extend, 2);
12620 fragp->fr_fix += 2;
12624 md_number_to_chars (buf, insn, 2);
12625 fragp->fr_fix += 2;
12630 if (fragp->fr_opcode == NULL)
12633 old = RELAX_OLD (fragp->fr_subtype);
12634 new = RELAX_NEW (fragp->fr_subtype);
12635 fixptr = fragp->fr_literal + fragp->fr_fix;
12638 memcpy (fixptr - old, fixptr, new);
12640 fragp->fr_fix += new - old;
12646 /* This function is called after the relocs have been generated.
12647 We've been storing mips16 text labels as odd. Here we convert them
12648 back to even for the convenience of the debugger. */
12651 mips_frob_file_after_relocs ()
12654 unsigned int count, i;
12656 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
12659 syms = bfd_get_outsymbols (stdoutput);
12660 count = bfd_get_symcount (stdoutput);
12661 for (i = 0; i < count; i++, syms++)
12663 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
12664 && ((*syms)->value & 1) != 0)
12666 (*syms)->value &= ~1;
12667 /* If the symbol has an odd size, it was probably computed
12668 incorrectly, so adjust that as well. */
12669 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
12670 ++elf_symbol (*syms)->internal_elf_sym.st_size;
12677 /* This function is called whenever a label is defined. It is used
12678 when handling branch delays; if a branch has a label, we assume we
12679 can not move it. */
12682 mips_define_label (sym)
12685 struct insn_label_list *l;
12687 if (free_insn_labels == NULL)
12688 l = (struct insn_label_list *) xmalloc (sizeof *l);
12691 l = free_insn_labels;
12692 free_insn_labels = l->next;
12696 l->next = insn_labels;
12700 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12702 /* Some special processing for a MIPS ELF file. */
12705 mips_elf_final_processing ()
12707 /* Write out the register information. */
12712 s.ri_gprmask = mips_gprmask;
12713 s.ri_cprmask[0] = mips_cprmask[0];
12714 s.ri_cprmask[1] = mips_cprmask[1];
12715 s.ri_cprmask[2] = mips_cprmask[2];
12716 s.ri_cprmask[3] = mips_cprmask[3];
12717 /* The gp_value field is set by the MIPS ELF backend. */
12719 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
12720 ((Elf32_External_RegInfo *)
12721 mips_regmask_frag));
12725 Elf64_Internal_RegInfo s;
12727 s.ri_gprmask = mips_gprmask;
12729 s.ri_cprmask[0] = mips_cprmask[0];
12730 s.ri_cprmask[1] = mips_cprmask[1];
12731 s.ri_cprmask[2] = mips_cprmask[2];
12732 s.ri_cprmask[3] = mips_cprmask[3];
12733 /* The gp_value field is set by the MIPS ELF backend. */
12735 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
12736 ((Elf64_External_RegInfo *)
12737 mips_regmask_frag));
12740 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
12741 sort of BFD interface for this. */
12742 if (mips_any_noreorder)
12743 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
12744 if (mips_pic != NO_PIC)
12745 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
12747 /* Set the MIPS ELF ABI flags. */
12748 if (file_mips_abi == NO_ABI)
12750 else if (file_mips_abi == O32_ABI)
12751 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
12752 else if (file_mips_abi == O64_ABI)
12753 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
12754 else if (file_mips_abi == EABI_ABI)
12757 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
12759 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
12761 else if (file_mips_abi == N32_ABI)
12762 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
12764 /* Nothing to do for "64". */
12766 if (mips_32bitmode)
12767 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
12770 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
12772 typedef struct proc {
12774 unsigned long reg_mask;
12775 unsigned long reg_offset;
12776 unsigned long fpreg_mask;
12777 unsigned long fpreg_offset;
12778 unsigned long frame_offset;
12779 unsigned long frame_reg;
12780 unsigned long pc_reg;
12783 static procS cur_proc;
12784 static procS *cur_proc_ptr;
12785 static int numprocs;
12787 /* Fill in an rs_align_code fragment. */
12790 mips_handle_align (fragp)
12793 if (fragp->fr_type != rs_align_code)
12796 if (mips_opts.mips16)
12798 static const unsigned char be_nop[] = { 0x65, 0x00 };
12799 static const unsigned char le_nop[] = { 0x00, 0x65 };
12804 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
12805 p = fragp->fr_literal + fragp->fr_fix;
12810 fragp->fr_fix += 1;
12813 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
12817 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
12828 /* check for premature end, nesting errors, etc */
12830 as_warn (_("missing .end at end of assembly"));
12839 if (*input_line_pointer == '-')
12841 ++input_line_pointer;
12844 if (!ISDIGIT (*input_line_pointer))
12845 as_bad (_("expected simple number"));
12846 if (input_line_pointer[0] == '0')
12848 if (input_line_pointer[1] == 'x')
12850 input_line_pointer += 2;
12851 while (ISXDIGIT (*input_line_pointer))
12854 val |= hex_value (*input_line_pointer++);
12856 return negative ? -val : val;
12860 ++input_line_pointer;
12861 while (ISDIGIT (*input_line_pointer))
12864 val |= *input_line_pointer++ - '0';
12866 return negative ? -val : val;
12869 if (!ISDIGIT (*input_line_pointer))
12871 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
12872 *input_line_pointer, *input_line_pointer);
12873 as_warn (_("invalid number"));
12876 while (ISDIGIT (*input_line_pointer))
12879 val += *input_line_pointer++ - '0';
12881 return negative ? -val : val;
12884 /* The .file directive; just like the usual .file directive, but there
12885 is an initial number which is the ECOFF file index. */
12889 int x ATTRIBUTE_UNUSED;
12893 line = get_number ();
12897 /* The .end directive. */
12901 int x ATTRIBUTE_UNUSED;
12906 /* Following functions need their own .frame and .cprestore directives. */
12907 mips_frame_reg_valid = 0;
12908 mips_cprestore_valid = 0;
12910 if (!is_end_of_line[(unsigned char) *input_line_pointer])
12913 demand_empty_rest_of_line ();
12918 #ifdef BFD_ASSEMBLER
12919 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
12924 if (now_seg != data_section && now_seg != bss_section)
12931 as_warn (_(".end not in text section"));
12935 as_warn (_(".end directive without a preceding .ent directive."));
12936 demand_empty_rest_of_line ();
12942 assert (S_GET_NAME (p));
12943 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
12944 as_warn (_(".end symbol does not match .ent symbol."));
12947 as_warn (_(".end directive missing or unknown symbol"));
12949 #ifdef MIPS_STABS_ELF
12951 segT saved_seg = now_seg;
12952 subsegT saved_subseg = now_subseg;
12957 dot = frag_now_fix ();
12959 #ifdef md_flush_pending_output
12960 md_flush_pending_output ();
12964 subseg_set (pdr_seg, 0);
12966 /* Write the symbol. */
12967 exp.X_op = O_symbol;
12968 exp.X_add_symbol = p;
12969 exp.X_add_number = 0;
12970 emit_expr (&exp, 4);
12972 fragp = frag_more (7 * 4);
12974 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
12975 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
12976 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
12977 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
12978 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
12979 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
12980 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
12982 subseg_set (saved_seg, saved_subseg);
12986 cur_proc_ptr = NULL;
12989 /* The .aent and .ent directives. */
12999 symbolP = get_symbol ();
13000 if (*input_line_pointer == ',')
13001 input_line_pointer++;
13002 SKIP_WHITESPACE ();
13003 if (ISDIGIT (*input_line_pointer)
13004 || *input_line_pointer == '-')
13005 number = get_number ();
13007 #ifdef BFD_ASSEMBLER
13008 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13013 if (now_seg != data_section && now_seg != bss_section)
13020 as_warn (_(".ent or .aent not in text section."));
13022 if (!aent && cur_proc_ptr)
13023 as_warn (_("missing .end"));
13027 /* This function needs its own .frame and .cprestore directives. */
13028 mips_frame_reg_valid = 0;
13029 mips_cprestore_valid = 0;
13031 cur_proc_ptr = &cur_proc;
13032 memset (cur_proc_ptr, '\0', sizeof (procS));
13034 cur_proc_ptr->isym = symbolP;
13036 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
13041 demand_empty_rest_of_line ();
13044 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
13045 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
13046 s_mips_frame is used so that we can set the PDR information correctly.
13047 We can't use the ecoff routines because they make reference to the ecoff
13048 symbol table (in the mdebug section). */
13051 s_mips_frame (ignore)
13052 int ignore ATTRIBUTE_UNUSED;
13054 #ifdef MIPS_STABS_ELF
13058 if (cur_proc_ptr == (procS *) NULL)
13060 as_warn (_(".frame outside of .ent"));
13061 demand_empty_rest_of_line ();
13065 cur_proc_ptr->frame_reg = tc_get_register (1);
13067 SKIP_WHITESPACE ();
13068 if (*input_line_pointer++ != ','
13069 || get_absolute_expression_and_terminator (&val) != ',')
13071 as_warn (_("Bad .frame directive"));
13072 --input_line_pointer;
13073 demand_empty_rest_of_line ();
13077 cur_proc_ptr->frame_offset = val;
13078 cur_proc_ptr->pc_reg = tc_get_register (0);
13080 demand_empty_rest_of_line ();
13083 #endif /* MIPS_STABS_ELF */
13086 /* The .fmask and .mask directives. If the mdebug section is present
13087 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
13088 embedded targets, s_mips_mask is used so that we can set the PDR
13089 information correctly. We can't use the ecoff routines because they
13090 make reference to the ecoff symbol table (in the mdebug section). */
13093 s_mips_mask (reg_type)
13096 #ifdef MIPS_STABS_ELF
13099 if (cur_proc_ptr == (procS *) NULL)
13101 as_warn (_(".mask/.fmask outside of .ent"));
13102 demand_empty_rest_of_line ();
13106 if (get_absolute_expression_and_terminator (&mask) != ',')
13108 as_warn (_("Bad .mask/.fmask directive"));
13109 --input_line_pointer;
13110 demand_empty_rest_of_line ();
13114 off = get_absolute_expression ();
13116 if (reg_type == 'F')
13118 cur_proc_ptr->fpreg_mask = mask;
13119 cur_proc_ptr->fpreg_offset = off;
13123 cur_proc_ptr->reg_mask = mask;
13124 cur_proc_ptr->reg_offset = off;
13127 demand_empty_rest_of_line ();
13129 s_ignore (reg_type);
13130 #endif /* MIPS_STABS_ELF */
13133 /* The .loc directive. */
13144 assert (now_seg == text_section);
13146 lineno = get_number ();
13147 addroff = frag_now_fix ();
13149 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
13150 S_SET_TYPE (symbolP, N_SLINE);
13151 S_SET_OTHER (symbolP, 0);
13152 S_SET_DESC (symbolP, lineno);
13153 symbolP->sy_segment = now_seg;
13157 /* CPU name/ISA/number mapping table.
13159 Entries are grouped by type. The first matching CPU or ISA entry
13160 gets chosen by CPU or ISA, so it should be the 'canonical' name
13161 for that type. Entries after that within the type are sorted
13164 Case is ignored in comparison, so put the canonical entry in the
13165 appropriate case but everything else in lower case to ease eye pain. */
13166 static const struct mips_cpu_info mips_cpu_info_table[] =
13169 { "MIPS1", 1, ISA_MIPS1, CPU_R3000, },
13170 { "mips", 1, ISA_MIPS1, CPU_R3000, },
13173 { "MIPS2", 1, ISA_MIPS2, CPU_R6000, },
13176 { "MIPS3", 1, ISA_MIPS3, CPU_R4000, },
13179 { "MIPS4", 1, ISA_MIPS4, CPU_R8000, },
13182 { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, },
13183 { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, },
13186 { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, },
13187 { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, },
13188 { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, },
13189 { "4kc", 0, ISA_MIPS32, CPU_MIPS32, },
13190 { "4km", 0, ISA_MIPS32, CPU_MIPS32, },
13191 { "4kp", 0, ISA_MIPS32, CPU_MIPS32, },
13193 /* For historical reasons. */
13194 { "MIPS64", 1, ISA_MIPS3, CPU_R4000, },
13197 { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, },
13198 { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, },
13199 { "5kc", 0, ISA_MIPS64, CPU_MIPS64, },
13200 { "20kc", 0, ISA_MIPS64, CPU_MIPS64, },
13203 { "R2000", 0, ISA_MIPS1, CPU_R2000, },
13204 { "2000", 0, ISA_MIPS1, CPU_R2000, },
13205 { "2k", 0, ISA_MIPS1, CPU_R2000, },
13206 { "r2k", 0, ISA_MIPS1, CPU_R2000, },
13209 { "R3000", 0, ISA_MIPS1, CPU_R3000, },
13210 { "3000", 0, ISA_MIPS1, CPU_R3000, },
13211 { "3k", 0, ISA_MIPS1, CPU_R3000, },
13212 { "r3k", 0, ISA_MIPS1, CPU_R3000, },
13215 { "R3900", 0, ISA_MIPS1, CPU_R3900, },
13216 { "3900", 0, ISA_MIPS1, CPU_R3900, },
13217 { "mipstx39", 0, ISA_MIPS1, CPU_R3900, },
13220 { "R4000", 0, ISA_MIPS3, CPU_R4000, },
13221 { "4000", 0, ISA_MIPS3, CPU_R4000, },
13222 { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */
13223 { "r4k", 0, ISA_MIPS3, CPU_R4000, },
13226 { "R4010", 0, ISA_MIPS2, CPU_R4010, },
13227 { "4010", 0, ISA_MIPS2, CPU_R4010, },
13230 { "R4400", 0, ISA_MIPS3, CPU_R4400, },
13231 { "4400", 0, ISA_MIPS3, CPU_R4400, },
13234 { "R4600", 0, ISA_MIPS3, CPU_R4600, },
13235 { "4600", 0, ISA_MIPS3, CPU_R4600, },
13236 { "mips64orion", 0, ISA_MIPS3, CPU_R4600, },
13237 { "orion", 0, ISA_MIPS3, CPU_R4600, },
13240 { "R4650", 0, ISA_MIPS3, CPU_R4650, },
13241 { "4650", 0, ISA_MIPS3, CPU_R4650, },
13244 { "R6000", 0, ISA_MIPS2, CPU_R6000, },
13245 { "6000", 0, ISA_MIPS2, CPU_R6000, },
13246 { "6k", 0, ISA_MIPS2, CPU_R6000, },
13247 { "r6k", 0, ISA_MIPS2, CPU_R6000, },
13250 { "R8000", 0, ISA_MIPS4, CPU_R8000, },
13251 { "8000", 0, ISA_MIPS4, CPU_R8000, },
13252 { "8k", 0, ISA_MIPS4, CPU_R8000, },
13253 { "r8k", 0, ISA_MIPS4, CPU_R8000, },
13256 { "R10000", 0, ISA_MIPS4, CPU_R10000, },
13257 { "10000", 0, ISA_MIPS4, CPU_R10000, },
13258 { "10k", 0, ISA_MIPS4, CPU_R10000, },
13259 { "r10k", 0, ISA_MIPS4, CPU_R10000, },
13262 { "R12000", 0, ISA_MIPS4, CPU_R12000, },
13263 { "12000", 0, ISA_MIPS4, CPU_R12000, },
13264 { "12k", 0, ISA_MIPS4, CPU_R12000, },
13265 { "r12k", 0, ISA_MIPS4, CPU_R12000, },
13268 { "VR4100", 0, ISA_MIPS3, CPU_VR4100, },
13269 { "4100", 0, ISA_MIPS3, CPU_VR4100, },
13270 { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, },
13271 { "r4100", 0, ISA_MIPS3, CPU_VR4100, },
13274 { "VR4111", 0, ISA_MIPS3, CPU_R4111, },
13275 { "4111", 0, ISA_MIPS3, CPU_R4111, },
13276 { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, },
13277 { "r4111", 0, ISA_MIPS3, CPU_R4111, },
13280 { "VR4300", 0, ISA_MIPS3, CPU_R4300, },
13281 { "4300", 0, ISA_MIPS3, CPU_R4300, },
13282 { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, },
13283 { "r4300", 0, ISA_MIPS3, CPU_R4300, },
13286 { "VR5000", 0, ISA_MIPS4, CPU_R5000, },
13287 { "5000", 0, ISA_MIPS4, CPU_R5000, },
13288 { "5k", 0, ISA_MIPS4, CPU_R5000, },
13289 { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, },
13290 { "r5000", 0, ISA_MIPS4, CPU_R5000, },
13291 { "r5200", 0, ISA_MIPS4, CPU_R5000, },
13292 { "rm5200", 0, ISA_MIPS4, CPU_R5000, },
13293 { "r5230", 0, ISA_MIPS4, CPU_R5000, },
13294 { "rm5230", 0, ISA_MIPS4, CPU_R5000, },
13295 { "r5231", 0, ISA_MIPS4, CPU_R5000, },
13296 { "rm5231", 0, ISA_MIPS4, CPU_R5000, },
13297 { "r5261", 0, ISA_MIPS4, CPU_R5000, },
13298 { "rm5261", 0, ISA_MIPS4, CPU_R5000, },
13299 { "r5721", 0, ISA_MIPS4, CPU_R5000, },
13300 { "rm5721", 0, ISA_MIPS4, CPU_R5000, },
13301 { "r5k", 0, ISA_MIPS4, CPU_R5000, },
13302 { "r7000", 0, ISA_MIPS4, CPU_R5000, },
13304 /* Broadcom SB-1 CPU */
13305 { "SB-1", 0, ISA_MIPS64, CPU_SB1, },
13306 { "sb-1250", 0, ISA_MIPS64, CPU_SB1, },
13307 { "sb1", 0, ISA_MIPS64, CPU_SB1, },
13308 { "sb1250", 0, ISA_MIPS64, CPU_SB1, },
13311 { NULL, 0, 0, 0, },
13314 static const struct mips_cpu_info *
13315 mips_cpu_info_from_name (name)
13320 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13321 if (strcasecmp (name, mips_cpu_info_table[i].name) == 0)
13322 return (&mips_cpu_info_table[i]);
13327 static const struct mips_cpu_info *
13328 mips_cpu_info_from_isa (isa)
13333 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13334 if (mips_cpu_info_table[i].is_isa
13335 && isa == mips_cpu_info_table[i].isa)
13336 return (&mips_cpu_info_table[i]);
13341 static const struct mips_cpu_info *
13342 mips_cpu_info_from_cpu (cpu)
13347 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13348 if (!mips_cpu_info_table[i].is_isa
13349 && cpu == mips_cpu_info_table[i].cpu)
13350 return (&mips_cpu_info_table[i]);