1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by the OSF and Ralph Campbell.
5 Written by Keith Knowles and Ralph Campbell, working independently.
6 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
9 This file is part of GAS.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include "safe-ctype.h"
38 #include "opcode/mips.h"
42 #define DBG(x) printf x
48 /* Clean up namespace so we can include obj-elf.h too. */
49 static int mips_output_flavor PARAMS ((void));
50 static int mips_output_flavor () { return OUTPUT_FLAVOR; }
51 #undef OBJ_PROCESS_STAB
58 #undef obj_frob_file_after_relocs
59 #undef obj_frob_symbol
61 #undef obj_sec_sym_ok_for_reloc
62 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
65 /* Fix any of them that we actually care about. */
67 #define OUTPUT_FLAVOR mips_output_flavor()
74 #ifndef ECOFF_DEBUGGING
75 #define NO_ECOFF_DEBUGGING
76 #define ECOFF_DEBUGGING 0
81 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
82 static char *mips_regmask_frag;
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 /* Enabled Application Specific Extensions (ASEs). These are set to -1
141 if they have not been initialized. Changed by `.set <asename>', by
142 command line options, and based on the default architecture. */
144 /* Whether we are assembling for the mips16 processor. 0 if we are
145 not, 1 if we are, and -1 if the value has not been initialized.
146 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
147 -nomips16 command line options, and the default CPU. */
149 /* Non-zero if we should not reorder instructions. Changed by `.set
150 reorder' and `.set noreorder'. */
152 /* Non-zero if we should not permit the $at ($1) register to be used
153 in instructions. Changed by `.set at' and `.set noat'. */
155 /* Non-zero if we should warn when a macro instruction expands into
156 more than one machine instruction. Changed by `.set nomacro' and
158 int warn_about_macros;
159 /* Non-zero if we should not move instructions. Changed by `.set
160 move', `.set volatile', `.set nomove', and `.set novolatile'. */
162 /* Non-zero if we should not optimize branches by moving the target
163 of the branch into the delay slot. Actually, we don't perform
164 this optimization anyhow. Changed by `.set bopt' and `.set
167 /* Non-zero if we should not autoextend mips16 instructions.
168 Changed by `.set autoextend' and `.set noautoextend'. */
170 /* Restrict general purpose registers and floating point registers
171 to 32 bit. This is initially determined when -mgp32 or -mfp32
172 is passed but can changed if the assembler code uses .set mipsN. */
175 /* The ABI currently in use. This is changed by .set mipsN to loosen
176 restrictions and doesn't affect the whole file. */
177 enum mips_abi_level abi;
180 /* True if -mgp32 was passed. */
181 static int file_mips_gp32 = -1;
183 /* True if -mfp32 was passed. */
184 static int file_mips_fp32 = -1;
186 /* This is the struct we use to hold the current set of options. Note
187 that we must set the isa field to ISA_UNKNOWN and the mips16 field to
188 -1 to indicate that they have not been initialized. */
190 static struct mips_set_options mips_opts =
192 ISA_UNKNOWN, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, NO_ABI
195 /* These variables are filled in with the masks of registers used.
196 The object format code reads them and puts them in the appropriate
198 unsigned long mips_gprmask;
199 unsigned long mips_cprmask[4];
201 /* MIPS ISA we are using for this output file. */
202 static int file_mips_isa = ISA_UNKNOWN;
204 /* True if -mips3d was passed or implied by arguments passed on the
205 command line (e.g., by -march). */
206 static int file_ase_mips3d;
208 /* The argument of the -mcpu= flag. Historical for code generation. */
209 static int mips_cpu = CPU_UNKNOWN;
211 /* The argument of the -march= flag. The architecture we are assembling. */
212 static int mips_arch = CPU_UNKNOWN;
214 /* The argument of the -mtune= flag. The architecture for which we
216 static int mips_tune = CPU_UNKNOWN;
218 /* Whether we should mark the file EABI64 or EABI32. */
219 static int mips_eabi64 = 0;
221 /* If they asked for mips1 or mips2 and a cpu that is
222 mips3 or greater, then mark the object file 32BITMODE. */
223 static int mips_32bitmode = 0;
225 /* Some ISA's have delay slots for instructions which read or write
226 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
227 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
228 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
229 delay slot in this ISA. The uses of this macro assume that any
230 ISA that has delay slots for one of these, has them for all. They
231 also assume that ISAs which don't have delays for these insns, don't
232 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
233 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
235 || (ISA) == ISA_MIPS2 \
236 || (ISA) == ISA_MIPS3 \
239 /* Return true if ISA supports 64 bit gp register instructions. */
240 #define ISA_HAS_64BIT_REGS(ISA) ( \
242 || (ISA) == ISA_MIPS4 \
243 || (ISA) == ISA_MIPS5 \
244 || (ISA) == ISA_MIPS64 \
247 #define HAVE_32BIT_GPRS \
249 || mips_opts.abi == O32_ABI \
250 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
252 #define HAVE_32BIT_FPRS \
254 || mips_opts.abi == O32_ABI \
255 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
257 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
258 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
260 #define HAVE_NEWABI (mips_opts.abi == N32_ABI || mips_opts.abi == N64_ABI)
262 #define HAVE_64BIT_OBJECTS (mips_opts.abi == N64_ABI)
264 /* We can only have 64bit addresses if the object file format
266 #define HAVE_32BIT_ADDRESSES \
268 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
269 || ! HAVE_64BIT_OBJECTS) \
270 && mips_pic != EMBEDDED_PIC))
272 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
274 /* Return true if the given CPU supports the MIPS3D ASE. */
275 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
278 /* Whether the processor uses hardware interlocks to protect
279 reads from the HI and LO registers, and thus does not
280 require nops to be inserted. */
282 #define hilo_interlocks (mips_arch == CPU_R4010 \
283 || mips_arch == CPU_SB1 \
286 /* Whether the processor uses hardware interlocks to protect reads
287 from the GPRs, and thus does not require nops to be inserted. */
288 #define gpr_interlocks \
289 (mips_opts.isa != ISA_MIPS1 \
290 || mips_arch == CPU_R3900)
292 /* As with other "interlocks" this is used by hardware that has FP
293 (co-processor) interlocks. */
294 /* Itbl support may require additional care here. */
295 #define cop_interlocks (mips_arch == CPU_R4300 \
296 || mips_arch == CPU_SB1 \
299 /* Is this a mfhi or mflo instruction? */
300 #define MF_HILO_INSN(PINFO) \
301 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
303 /* MIPS PIC level. */
307 /* Do not generate PIC code. */
310 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
311 not sure what it is supposed to do. */
314 /* Generate PIC code as in the SVR4 MIPS ABI. */
317 /* Generate PIC code without using a global offset table: the data
318 segment has a maximum size of 64K, all data references are off
319 the $gp register, and all text references are PC relative. This
320 is used on some embedded systems. */
324 static enum mips_pic_level mips_pic;
326 /* Warn about all NOPS that the assembler generates. */
327 static int warn_nops = 0;
329 /* 1 if we should generate 32 bit offsets from the $gp register in
330 SVR4_PIC mode. Currently has no meaning in other modes. */
331 static int mips_big_got = 0;
333 /* 1 if trap instructions should used for overflow rather than break
335 static int mips_trap = 0;
337 /* 1 if double width floating point constants should not be constructed
338 by assembling two single width halves into two single width floating
339 point registers which just happen to alias the double width destination
340 register. On some architectures this aliasing can be disabled by a bit
341 in the status register, and the setting of this bit cannot be determined
342 automatically at assemble time. */
343 static int mips_disable_float_construction;
345 /* Non-zero if any .set noreorder directives were used. */
347 static int mips_any_noreorder;
349 /* Non-zero if nops should be inserted when the register referenced in
350 an mfhi/mflo instruction is read in the next two instructions. */
351 static int mips_7000_hilo_fix;
353 /* The size of the small data section. */
354 static unsigned int g_switch_value = 8;
355 /* Whether the -G option was used. */
356 static int g_switch_seen = 0;
361 /* If we can determine in advance that GP optimization won't be
362 possible, we can skip the relaxation stuff that tries to produce
363 GP-relative references. This makes delay slot optimization work
366 This function can only provide a guess, but it seems to work for
367 gcc output. It needs to guess right for gcc, otherwise gcc
368 will put what it thinks is a GP-relative instruction in a branch
371 I don't know if a fix is needed for the SVR4_PIC mode. I've only
372 fixed it for the non-PIC mode. KR 95/04/07 */
373 static int nopic_need_relax PARAMS ((symbolS *, int));
375 /* handle of the OPCODE hash table */
376 static struct hash_control *op_hash = NULL;
378 /* The opcode hash table we use for the mips16. */
379 static struct hash_control *mips16_op_hash = NULL;
381 /* This array holds the chars that always start a comment. If the
382 pre-processor is disabled, these aren't very useful */
383 const char comment_chars[] = "#";
385 /* This array holds the chars that only start a comment at the beginning of
386 a line. If the line seems to have the form '# 123 filename'
387 .line and .file directives will appear in the pre-processed output */
388 /* Note that input_file.c hand checks for '#' at the beginning of the
389 first line of the input file. This is because the compiler outputs
390 #NO_APP at the beginning of its output. */
391 /* Also note that C style comments are always supported. */
392 const char line_comment_chars[] = "#";
394 /* This array holds machine specific line separator characters. */
395 const char line_separator_chars[] = ";";
397 /* Chars that can be used to separate mant from exp in floating point nums */
398 const char EXP_CHARS[] = "eE";
400 /* Chars that mean this number is a floating point constant */
403 const char FLT_CHARS[] = "rRsSfFdDxXpP";
405 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
406 changed in read.c . Ideally it shouldn't have to know about it at all,
407 but nothing is ideal around here.
410 static char *insn_error;
412 static int auto_align = 1;
414 /* When outputting SVR4 PIC code, the assembler needs to know the
415 offset in the stack frame from which to restore the $gp register.
416 This is set by the .cprestore pseudo-op, and saved in this
418 static offsetT mips_cprestore_offset = -1;
420 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
421 more optimizations, it can use a register value instead of a memory-saved
422 offset and even an other register than $gp as global pointer. */
423 static offsetT mips_cpreturn_offset = -1;
424 static int mips_cpreturn_register = -1;
425 static int mips_gp_register = GP;
427 /* Whether mips_cprestore_offset has been set in the current function
428 (or whether it has already been warned about, if not). */
429 static int mips_cprestore_valid = 0;
431 /* This is the register which holds the stack frame, as set by the
432 .frame pseudo-op. This is needed to implement .cprestore. */
433 static int mips_frame_reg = SP;
435 /* Whether mips_frame_reg has been set in the current function
436 (or whether it has already been warned about, if not). */
437 static int mips_frame_reg_valid = 0;
439 /* To output NOP instructions correctly, we need to keep information
440 about the previous two instructions. */
442 /* Whether we are optimizing. The default value of 2 means to remove
443 unneeded NOPs and swap branch instructions when possible. A value
444 of 1 means to not swap branches. A value of 0 means to always
446 static int mips_optimize = 2;
448 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
449 equivalent to seeing no -g option at all. */
450 static int mips_debug = 0;
452 /* The previous instruction. */
453 static struct mips_cl_insn prev_insn;
455 /* The instruction before prev_insn. */
456 static struct mips_cl_insn prev_prev_insn;
458 /* If we don't want information for prev_insn or prev_prev_insn, we
459 point the insn_mo field at this dummy integer. */
460 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
462 /* Non-zero if prev_insn is valid. */
463 static int prev_insn_valid;
465 /* The frag for the previous instruction. */
466 static struct frag *prev_insn_frag;
468 /* The offset into prev_insn_frag for the previous instruction. */
469 static long prev_insn_where;
471 /* The reloc type for the previous instruction, if any. */
472 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
474 /* The reloc for the previous instruction, if any. */
475 static fixS *prev_insn_fixp[3];
477 /* Non-zero if the previous instruction was in a delay slot. */
478 static int prev_insn_is_delay_slot;
480 /* Non-zero if the previous instruction was in a .set noreorder. */
481 static int prev_insn_unreordered;
483 /* Non-zero if the previous instruction uses an extend opcode (if
485 static int prev_insn_extended;
487 /* Non-zero if the previous previous instruction was in a .set
489 static int prev_prev_insn_unreordered;
491 /* If this is set, it points to a frag holding nop instructions which
492 were inserted before the start of a noreorder section. If those
493 nops turn out to be unnecessary, the size of the frag can be
495 static fragS *prev_nop_frag;
497 /* The number of nop instructions we created in prev_nop_frag. */
498 static int prev_nop_frag_holds;
500 /* The number of nop instructions that we know we need in
502 static int prev_nop_frag_required;
504 /* The number of instructions we've seen since prev_nop_frag. */
505 static int prev_nop_frag_since;
507 /* For ECOFF and ELF, relocations against symbols are done in two
508 parts, with a HI relocation and a LO relocation. Each relocation
509 has only 16 bits of space to store an addend. This means that in
510 order for the linker to handle carries correctly, it must be able
511 to locate both the HI and the LO relocation. This means that the
512 relocations must appear in order in the relocation table.
514 In order to implement this, we keep track of each unmatched HI
515 relocation. We then sort them so that they immediately precede the
516 corresponding LO relocation. */
521 struct mips_hi_fixup *next;
524 /* The section this fixup is in. */
528 /* The list of unmatched HI relocs. */
530 static struct mips_hi_fixup *mips_hi_fixup_list;
532 /* Map normal MIPS register numbers to mips16 register numbers. */
534 #define X ILLEGAL_REG
535 static const int mips32_to_16_reg_map[] =
537 X, X, 2, 3, 4, 5, 6, 7,
538 X, X, X, X, X, X, X, X,
539 0, 1, X, X, X, X, X, X,
540 X, X, X, X, X, X, X, X
544 /* Map mips16 register numbers to normal MIPS register numbers. */
546 static const unsigned int mips16_to_32_reg_map[] =
548 16, 17, 2, 3, 4, 5, 6, 7
551 /* Since the MIPS does not have multiple forms of PC relative
552 instructions, we do not have to do relaxing as is done on other
553 platforms. However, we do have to handle GP relative addressing
554 correctly, which turns out to be a similar problem.
556 Every macro that refers to a symbol can occur in (at least) two
557 forms, one with GP relative addressing and one without. For
558 example, loading a global variable into a register generally uses
559 a macro instruction like this:
561 If i can be addressed off the GP register (this is true if it is in
562 the .sbss or .sdata section, or if it is known to be smaller than
563 the -G argument) this will generate the following instruction:
565 This instruction will use a GPREL reloc. If i can not be addressed
566 off the GP register, the following instruction sequence will be used:
569 In this case the first instruction will have a HI16 reloc, and the
570 second reloc will have a LO16 reloc. Both relocs will be against
573 The issue here is that we may not know whether i is GP addressable
574 until after we see the instruction that uses it. Therefore, we
575 want to be able to choose the final instruction sequence only at
576 the end of the assembly. This is similar to the way other
577 platforms choose the size of a PC relative instruction only at the
580 When generating position independent code we do not use GP
581 addressing in quite the same way, but the issue still arises as
582 external symbols and local symbols must be handled differently.
584 We handle these issues by actually generating both possible
585 instruction sequences. The longer one is put in a frag_var with
586 type rs_machine_dependent. We encode what to do with the frag in
587 the subtype field. We encode (1) the number of existing bytes to
588 replace, (2) the number of new bytes to use, (3) the offset from
589 the start of the existing bytes to the first reloc we must generate
590 (that is, the offset is applied from the start of the existing
591 bytes after they are replaced by the new bytes, if any), (4) the
592 offset from the start of the existing bytes to the second reloc,
593 (5) whether a third reloc is needed (the third reloc is always four
594 bytes after the second reloc), and (6) whether to warn if this
595 variant is used (this is sometimes needed if .set nomacro or .set
596 noat is in effect). All these numbers are reasonably small.
598 Generating two instruction sequences must be handled carefully to
599 ensure that delay slots are handled correctly. Fortunately, there
600 are a limited number of cases. When the second instruction
601 sequence is generated, append_insn is directed to maintain the
602 existing delay slot information, so it continues to apply to any
603 code after the second instruction sequence. This means that the
604 second instruction sequence must not impose any requirements not
605 required by the first instruction sequence.
607 These variant frags are then handled in functions called by the
608 machine independent code. md_estimate_size_before_relax returns
609 the final size of the frag. md_convert_frag sets up the final form
610 of the frag. tc_gen_reloc adjust the first reloc and adds a second
612 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
616 | (((reloc1) + 64) << 9) \
617 | (((reloc2) + 64) << 2) \
618 | ((reloc3) ? (1 << 1) : 0) \
620 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
621 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
622 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
623 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
624 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
625 #define RELAX_WARN(i) ((i) & 1)
627 /* For mips16 code, we use an entirely different form of relaxation.
628 mips16 supports two versions of most instructions which take
629 immediate values: a small one which takes some small value, and a
630 larger one which takes a 16 bit value. Since branches also follow
631 this pattern, relaxing these values is required.
633 We can assemble both mips16 and normal MIPS code in a single
634 object. Therefore, we need to support this type of relaxation at
635 the same time that we support the relaxation described above. We
636 use the high bit of the subtype field to distinguish these cases.
638 The information we store for this type of relaxation is the
639 argument code found in the opcode file for this relocation, whether
640 the user explicitly requested a small or extended form, and whether
641 the relocation is in a jump or jal delay slot. That tells us the
642 size of the value, and how it should be stored. We also store
643 whether the fragment is considered to be extended or not. We also
644 store whether this is known to be a branch to a different section,
645 whether we have tried to relax this frag yet, and whether we have
646 ever extended a PC relative fragment because of a shift count. */
647 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
650 | ((small) ? 0x100 : 0) \
651 | ((ext) ? 0x200 : 0) \
652 | ((dslot) ? 0x400 : 0) \
653 | ((jal_dslot) ? 0x800 : 0))
654 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
655 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
656 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
657 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
658 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
659 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
660 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
661 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
662 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
663 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
664 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
665 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
667 /* Prototypes for static functions. */
670 #define internalError() \
671 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
673 #define internalError() as_fatal (_("MIPS internal Error"));
676 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
678 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
679 unsigned int reg, enum mips_regclass class));
680 static int reg_needs_delay PARAMS ((unsigned int));
681 static void mips16_mark_labels PARAMS ((void));
682 static void append_insn PARAMS ((char *place,
683 struct mips_cl_insn * ip,
685 bfd_reloc_code_real_type *r,
687 static void mips_no_prev_insn PARAMS ((int));
688 static void mips_emit_delays PARAMS ((boolean));
690 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
691 const char *name, const char *fmt,
694 static void macro_build ();
696 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
697 const char *, const char *,
699 static void macro_build_lui PARAMS ((char *place, int *counter,
700 expressionS * ep, int regnum));
701 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
702 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
704 static void load_register PARAMS ((int *, int, expressionS *, int));
705 static void load_address PARAMS ((int *, int, expressionS *, int *));
706 static void move_register PARAMS ((int *, int, int));
707 static void macro PARAMS ((struct mips_cl_insn * ip));
708 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
709 #ifdef LOSING_COMPILER
710 static void macro2 PARAMS ((struct mips_cl_insn * ip));
712 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
713 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
714 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
715 boolean, boolean, unsigned long *,
716 boolean *, unsigned short *));
717 static int my_getPercentOp PARAMS ((char **, unsigned int *, int *));
718 static int my_getSmallParser PARAMS ((char **, unsigned int *, int *));
719 static int my_getSmallExpression PARAMS ((expressionS *, char *));
720 static void my_getExpression PARAMS ((expressionS *, char *));
722 static int support_64bit_objects PARAMS((void));
724 static symbolS *get_symbol PARAMS ((void));
725 static void mips_align PARAMS ((int to, int fill, symbolS *label));
726 static void s_align PARAMS ((int));
727 static void s_change_sec PARAMS ((int));
728 static void s_cons PARAMS ((int));
729 static void s_float_cons PARAMS ((int));
730 static void s_mips_globl PARAMS ((int));
731 static void s_option PARAMS ((int));
732 static void s_mipsset PARAMS ((int));
733 static void s_abicalls PARAMS ((int));
734 static void s_cpload PARAMS ((int));
735 static void s_cpsetup PARAMS ((int));
736 static void s_cplocal PARAMS ((int));
737 static void s_cprestore PARAMS ((int));
738 static void s_cpreturn PARAMS ((int));
739 static void s_gpvalue PARAMS ((int));
740 static void s_gpword PARAMS ((int));
741 static void s_cpadd PARAMS ((int));
742 static void s_insn PARAMS ((int));
743 static void md_obj_begin PARAMS ((void));
744 static void md_obj_end PARAMS ((void));
745 static long get_number PARAMS ((void));
746 static void s_mips_ent PARAMS ((int));
747 static void s_mips_end PARAMS ((int));
748 static void s_mips_frame PARAMS ((int));
749 static void s_mips_mask PARAMS ((int));
750 static void s_mips_stab PARAMS ((int));
751 static void s_mips_weakext PARAMS ((int));
752 static void s_file PARAMS ((int));
753 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
754 static const char *mips_isa_to_str PARAMS ((int));
755 static const char *mips_cpu_to_str PARAMS ((int));
756 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
757 static void show PARAMS ((FILE *, char *, int *, int *));
759 static int mips_need_elf_addend_fixup PARAMS ((fixS *));
762 /* Return values of my_getSmallExpression(). */
769 /* Direct relocation creation by %percent_op(). */
788 /* Table and functions used to map between CPU/ISA names, and
789 ISA levels, and CPU numbers. */
793 const char *name; /* CPU or ISA name. */
794 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
795 int isa; /* ISA level. */
796 int cpu; /* CPU number (default CPU if ISA). */
799 static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *));
800 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
801 static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int));
805 The following pseudo-ops from the Kane and Heinrich MIPS book
806 should be defined here, but are currently unsupported: .alias,
807 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
809 The following pseudo-ops from the Kane and Heinrich MIPS book are
810 specific to the type of debugging information being generated, and
811 should be defined by the object format: .aent, .begin, .bend,
812 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
815 The following pseudo-ops from the Kane and Heinrich MIPS book are
816 not MIPS CPU specific, but are also not specific to the object file
817 format. This file is probably the best place to define them, but
818 they are not currently supported: .asm0, .endr, .lab, .repeat,
821 static const pseudo_typeS mips_pseudo_table[] =
823 /* MIPS specific pseudo-ops. */
824 {"option", s_option, 0},
825 {"set", s_mipsset, 0},
826 {"rdata", s_change_sec, 'r'},
827 {"sdata", s_change_sec, 's'},
828 {"livereg", s_ignore, 0},
829 {"abicalls", s_abicalls, 0},
830 {"cpload", s_cpload, 0},
831 {"cpsetup", s_cpsetup, 0},
832 {"cplocal", s_cplocal, 0},
833 {"cprestore", s_cprestore, 0},
834 {"cpreturn", s_cpreturn, 0},
835 {"gpvalue", s_gpvalue, 0},
836 {"gpword", s_gpword, 0},
837 {"cpadd", s_cpadd, 0},
840 /* Relatively generic pseudo-ops that happen to be used on MIPS
842 {"asciiz", stringer, 1},
843 {"bss", s_change_sec, 'b'},
846 {"dword", s_cons, 3},
847 {"weakext", s_mips_weakext, 0},
849 /* These pseudo-ops are defined in read.c, but must be overridden
850 here for one reason or another. */
851 {"align", s_align, 0},
853 {"data", s_change_sec, 'd'},
854 {"double", s_float_cons, 'd'},
855 {"float", s_float_cons, 'f'},
856 {"globl", s_mips_globl, 0},
857 {"global", s_mips_globl, 0},
858 {"hword", s_cons, 1},
863 {"short", s_cons, 1},
864 {"single", s_float_cons, 'f'},
865 {"stabn", s_mips_stab, 'n'},
866 {"text", s_change_sec, 't'},
869 #ifdef MIPS_STABS_ELF
870 { "extern", ecoff_directive_extern, 0},
876 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
878 /* These pseudo-ops should be defined by the object file format.
879 However, a.out doesn't support them, so we have versions here. */
880 {"aent", s_mips_ent, 1},
881 {"bgnb", s_ignore, 0},
882 {"end", s_mips_end, 0},
883 {"endb", s_ignore, 0},
884 {"ent", s_mips_ent, 0},
886 {"fmask", s_mips_mask, 'F'},
887 {"frame", s_mips_frame, 0},
888 {"loc", s_ignore, 0},
889 {"mask", s_mips_mask, 'R'},
890 {"verstamp", s_ignore, 0},
894 extern void pop_insert PARAMS ((const pseudo_typeS *));
899 pop_insert (mips_pseudo_table);
900 if (! ECOFF_DEBUGGING)
901 pop_insert (mips_nonecoff_pseudo_table);
904 /* Symbols labelling the current insn. */
906 struct insn_label_list
908 struct insn_label_list *next;
912 static struct insn_label_list *insn_labels;
913 static struct insn_label_list *free_insn_labels;
915 static void mips_clear_insn_labels PARAMS ((void));
918 mips_clear_insn_labels ()
920 register struct insn_label_list **pl;
922 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
928 static char *expr_end;
930 /* Expressions which appear in instructions. These are set by
933 static expressionS imm_expr;
934 static expressionS offset_expr;
936 /* Relocs associated with imm_expr and offset_expr. */
938 static bfd_reloc_code_real_type imm_reloc[3]
939 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
940 static bfd_reloc_code_real_type offset_reloc[3]
941 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
943 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
945 static boolean imm_unmatched_hi;
947 /* These are set by mips16_ip if an explicit extension is used. */
949 static boolean mips16_small, mips16_ext;
951 #ifdef MIPS_STABS_ELF
952 /* The pdr segment for per procedure frame/regmask info */
958 mips_isa_to_str (isa)
961 const struct mips_cpu_info *ci;
964 ci = mips_cpu_info_from_isa (isa);
968 sprintf (s, "ISA#%d", isa);
973 mips_cpu_to_str (cpu)
976 const struct mips_cpu_info *ci;
979 ci = mips_cpu_info_from_cpu (cpu);
983 sprintf (s, "CPU#%d", cpu);
987 /* The default target format to use. */
990 mips_target_format ()
992 switch (OUTPUT_FLAVOR)
994 case bfd_target_aout_flavour:
995 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
996 case bfd_target_ecoff_flavour:
997 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
998 case bfd_target_coff_flavour:
1000 case bfd_target_elf_flavour:
1002 /* This is traditional mips */
1003 return (target_big_endian
1004 ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips"
1005 : "elf32-tradbigmips")
1006 : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips"
1007 : "elf32-tradlittlemips"));
1009 return (target_big_endian
1010 ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips")
1011 : (HAVE_64BIT_OBJECTS ? "elf64-littlemips"
1012 : "elf32-littlemips"));
1020 /* This function is called once, at assembler startup time. It should
1021 set up all the tables, etc. that the MD part of the assembler will need. */
1026 register const char *retval = NULL;
1031 int mips_isa_from_cpu;
1032 int target_cpu_had_mips16 = 0;
1033 const struct mips_cpu_info *ci;
1035 /* GP relative stuff not working for PE */
1036 if (strncmp (TARGET_OS, "pe", 2) == 0
1037 && g_switch_value != 0)
1040 as_bad (_("-G not supported in this configuration."));
1045 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
1047 a = xmalloc (sizeof TARGET_CPU);
1048 strcpy (a, TARGET_CPU);
1049 a[(sizeof TARGET_CPU) - 3] = '\0';
1053 if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0)
1055 target_cpu_had_mips16 = 1;
1056 cpu += sizeof "mips16" - 1;
1059 if (mips_opts.mips16 < 0)
1060 mips_opts.mips16 = target_cpu_had_mips16;
1062 /* Backward compatibility for historic -mcpu= option. Check for
1063 incompatible options, warn if -mcpu is used. */
1064 if (mips_cpu != CPU_UNKNOWN
1065 && mips_arch != CPU_UNKNOWN
1066 && mips_cpu != mips_arch)
1068 as_fatal (_("The -mcpu option can't be used together with -march. "
1069 "Use -mtune instead of -mcpu."));
1072 if (mips_cpu != CPU_UNKNOWN
1073 && mips_tune != CPU_UNKNOWN
1074 && mips_cpu != mips_tune)
1076 as_fatal (_("The -mcpu option can't be used together with -mtune. "
1077 "Use -march instead of -mcpu."));
1081 /* For backward compatibility, let -mipsN set various defaults. */
1082 /* This code should go away, to be replaced with something rather more
1083 draconian. Until GCC 3.1 has been released for some reasonable
1084 amount of time, however, we need to support this. */
1085 if (mips_opts.isa != ISA_UNKNOWN)
1087 /* Translate -mipsN to the appropriate settings of file_mips_gp32
1088 and file_mips_fp32. Tag binaries as using the mipsN ISA. */
1089 if (file_mips_gp32 < 0)
1091 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1096 if (file_mips_fp32 < 0)
1098 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1104 ci = mips_cpu_info_from_isa (mips_opts.isa);
1105 assert (ci != NULL);
1106 /* -mipsN has higher priority than -mcpu but lower than -march. */
1107 if (mips_arch == CPU_UNKNOWN)
1108 mips_arch = ci->cpu;
1110 /* Default mips_abi. */
1111 if (mips_opts.abi == NO_ABI)
1113 if (mips_opts.isa == ISA_MIPS1 || mips_opts.isa == ISA_MIPS2)
1114 mips_opts.abi = O32_ABI;
1115 else if (mips_opts.isa == ISA_MIPS3 || mips_opts.isa == ISA_MIPS4)
1116 mips_opts.abi = O64_ABI;
1120 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1122 ci = mips_cpu_info_from_cpu (mips_cpu);
1123 assert (ci != NULL);
1124 mips_arch = ci->cpu;
1125 as_warn (_("The -mcpu option is deprecated. Please use -march and "
1126 "-mtune instead."));
1129 /* Set tune from -mcpu, not from -mipsN. */
1130 if (mips_tune == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1132 ci = mips_cpu_info_from_cpu (mips_cpu);
1133 assert (ci != NULL);
1134 mips_tune = ci->cpu;
1137 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
1138 specified on the command line, or some other value if one was.
1139 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
1140 the command line, or will be set otherwise if one was. */
1142 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1143 /* Handled above. */;
1145 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1147 ci = mips_cpu_info_from_cpu (mips_cpu);
1148 assert (ci != NULL);
1149 mips_arch = ci->cpu;
1150 as_warn (_("The -mcpu option is deprecated. Please use -march and "
1151 "-mtune instead."));
1154 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
1155 specified on the command line, or some other value if one was.
1156 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
1157 the command line, or will be set otherwise if one was. */
1159 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1161 /* We have to check if the isa is the default isa of arch. Otherwise
1162 we'll get invalid object file headers. */
1163 ci = mips_cpu_info_from_cpu (mips_arch);
1164 assert (ci != NULL);
1165 if (mips_opts.isa != ci->isa)
1167 /* This really should be an error instead of a warning, but old
1168 compilers only have -mcpu which sets both arch and tune. For
1169 now, we discard arch and preserve tune. */
1170 as_warn (_("The -march option is incompatible to -mipsN and "
1171 "therefore ignored."));
1172 if (mips_tune == CPU_UNKNOWN)
1173 mips_tune = mips_arch;
1174 ci = mips_cpu_info_from_isa (mips_opts.isa);
1175 assert (ci != NULL);
1176 mips_arch = ci->cpu;
1180 else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN)
1182 /* We have ARCH, we need ISA. */
1183 ci = mips_cpu_info_from_cpu (mips_arch);
1184 assert (ci != NULL);
1185 mips_opts.isa = ci->isa;
1187 else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1189 /* We have ISA, we need default ARCH. */
1190 ci = mips_cpu_info_from_isa (mips_opts.isa);
1191 assert (ci != NULL);
1192 mips_arch = ci->cpu;
1196 /* We need to set both ISA and ARCH from target cpu. */
1197 ci = mips_cpu_info_from_name (cpu);
1199 ci = mips_cpu_info_from_cpu (CPU_R3000);
1200 assert (ci != NULL);
1201 mips_opts.isa = ci->isa;
1202 mips_arch = ci->cpu;
1205 if (mips_tune == CPU_UNKNOWN)
1206 mips_tune = mips_arch;
1208 ci = mips_cpu_info_from_cpu (mips_arch);
1209 assert (ci != NULL);
1210 mips_isa_from_cpu = ci->isa;
1212 /* End of TARGET_CPU processing, get rid of malloced memory
1221 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
1222 as_bad (_("trap exception not supported at ISA 1"));
1224 /* Set the EABI kind based on the ISA before the user gets
1225 to change the ISA with directives. This isn't really
1226 the best, but then neither is basing the abi on the isa. */
1227 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
1228 && mips_opts.abi == EABI_ABI)
1231 /* If they asked for mips1 or mips2 and a cpu that is
1232 mips3 or greater, then mark the object file 32BITMODE. */
1233 if (mips_isa_from_cpu != ISA_UNKNOWN
1234 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
1235 && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
1238 /* If the selected architecture includes support for ASEs, enable
1239 generation of code for them. */
1240 if (mips_opts.ase_mips3d == -1 && CPU_HAS_MIPS3D (mips_arch))
1241 mips_opts.ase_mips3d = 1;
1243 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1244 as_warn (_("Could not set architecture and machine"));
1246 if (file_mips_gp32 < 0)
1248 if (file_mips_fp32 < 0)
1251 file_mips_isa = mips_opts.isa;
1252 file_mips_abi = mips_opts.abi;
1253 file_ase_mips3d = mips_opts.ase_mips3d;
1254 mips_opts.gp32 = file_mips_gp32;
1255 mips_opts.fp32 = file_mips_fp32;
1257 op_hash = hash_new ();
1259 for (i = 0; i < NUMOPCODES;)
1261 const char *name = mips_opcodes[i].name;
1263 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1266 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1267 mips_opcodes[i].name, retval);
1268 /* Probably a memory allocation problem? Give up now. */
1269 as_fatal (_("Broken assembler. No assembly attempted."));
1273 if (mips_opcodes[i].pinfo != INSN_MACRO)
1275 if (!validate_mips_insn (&mips_opcodes[i]))
1280 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1283 mips16_op_hash = hash_new ();
1286 while (i < bfd_mips16_num_opcodes)
1288 const char *name = mips16_opcodes[i].name;
1290 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1292 as_fatal (_("internal: can't hash `%s': %s"),
1293 mips16_opcodes[i].name, retval);
1296 if (mips16_opcodes[i].pinfo != INSN_MACRO
1297 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1298 != mips16_opcodes[i].match))
1300 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1301 mips16_opcodes[i].name, mips16_opcodes[i].args);
1306 while (i < bfd_mips16_num_opcodes
1307 && strcmp (mips16_opcodes[i].name, name) == 0);
1311 as_fatal (_("Broken assembler. No assembly attempted."));
1313 /* We add all the general register names to the symbol table. This
1314 helps us detect invalid uses of them. */
1315 for (i = 0; i < 32; i++)
1319 sprintf (buf, "$%d", i);
1320 symbol_table_insert (symbol_new (buf, reg_section, i,
1321 &zero_address_frag));
1323 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1324 &zero_address_frag));
1325 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1326 &zero_address_frag));
1327 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1328 &zero_address_frag));
1329 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1330 &zero_address_frag));
1331 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1332 &zero_address_frag));
1333 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1334 &zero_address_frag));
1335 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1336 &zero_address_frag));
1338 mips_no_prev_insn (false);
1341 mips_cprmask[0] = 0;
1342 mips_cprmask[1] = 0;
1343 mips_cprmask[2] = 0;
1344 mips_cprmask[3] = 0;
1346 /* set the default alignment for the text section (2**2) */
1347 record_alignment (text_section, 2);
1349 if (USE_GLOBAL_POINTER_OPT)
1350 bfd_set_gp_size (stdoutput, g_switch_value);
1352 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1354 /* On a native system, sections must be aligned to 16 byte
1355 boundaries. When configured for an embedded ELF target, we
1357 if (strcmp (TARGET_OS, "elf") != 0)
1359 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1360 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1361 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1364 /* Create a .reginfo section for register masks and a .mdebug
1365 section for debugging information. */
1373 subseg = now_subseg;
1375 /* The ABI says this section should be loaded so that the
1376 running program can access it. However, we don't load it
1377 if we are configured for an embedded target */
1378 flags = SEC_READONLY | SEC_DATA;
1379 if (strcmp (TARGET_OS, "elf") != 0)
1380 flags |= SEC_ALLOC | SEC_LOAD;
1382 if (file_mips_abi != N64_ABI)
1384 sec = subseg_new (".reginfo", (subsegT) 0);
1386 bfd_set_section_flags (stdoutput, sec, flags);
1387 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1390 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1395 /* The 64-bit ABI uses a .MIPS.options section rather than
1396 .reginfo section. */
1397 sec = subseg_new (".MIPS.options", (subsegT) 0);
1398 bfd_set_section_flags (stdoutput, sec, flags);
1399 bfd_set_section_alignment (stdoutput, sec, 3);
1402 /* Set up the option header. */
1404 Elf_Internal_Options opthdr;
1407 opthdr.kind = ODK_REGINFO;
1408 opthdr.size = (sizeof (Elf_External_Options)
1409 + sizeof (Elf64_External_RegInfo));
1412 f = frag_more (sizeof (Elf_External_Options));
1413 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1414 (Elf_External_Options *) f);
1416 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1421 if (ECOFF_DEBUGGING)
1423 sec = subseg_new (".mdebug", (subsegT) 0);
1424 (void) bfd_set_section_flags (stdoutput, sec,
1425 SEC_HAS_CONTENTS | SEC_READONLY);
1426 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1429 #ifdef MIPS_STABS_ELF
1430 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1431 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1432 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
1433 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1436 subseg_set (seg, subseg);
1440 if (! ECOFF_DEBUGGING)
1447 if (! ECOFF_DEBUGGING)
1455 struct mips_cl_insn insn;
1456 bfd_reloc_code_real_type unused_reloc[3]
1457 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1459 imm_expr.X_op = O_absent;
1460 imm_unmatched_hi = false;
1461 offset_expr.X_op = O_absent;
1462 imm_reloc[0] = BFD_RELOC_UNUSED;
1463 imm_reloc[1] = BFD_RELOC_UNUSED;
1464 imm_reloc[2] = BFD_RELOC_UNUSED;
1465 offset_reloc[0] = BFD_RELOC_UNUSED;
1466 offset_reloc[1] = BFD_RELOC_UNUSED;
1467 offset_reloc[2] = BFD_RELOC_UNUSED;
1469 if (mips_opts.mips16)
1470 mips16_ip (str, &insn);
1473 mips_ip (str, &insn);
1474 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1475 str, insn.insn_opcode));
1480 as_bad ("%s `%s'", insn_error, str);
1484 if (insn.insn_mo->pinfo == INSN_MACRO)
1486 if (mips_opts.mips16)
1487 mips16_macro (&insn);
1493 if (imm_expr.X_op != O_absent)
1494 append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi);
1495 else if (offset_expr.X_op != O_absent)
1496 append_insn (NULL, &insn, &offset_expr, offset_reloc, false);
1498 append_insn (NULL, &insn, NULL, unused_reloc, false);
1502 /* See whether instruction IP reads register REG. CLASS is the type
1506 insn_uses_reg (ip, reg, class)
1507 struct mips_cl_insn *ip;
1509 enum mips_regclass class;
1511 if (class == MIPS16_REG)
1513 assert (mips_opts.mips16);
1514 reg = mips16_to_32_reg_map[reg];
1515 class = MIPS_GR_REG;
1518 /* Don't report on general register 0, since it never changes. */
1519 if (class == MIPS_GR_REG && reg == 0)
1522 if (class == MIPS_FP_REG)
1524 assert (! mips_opts.mips16);
1525 /* If we are called with either $f0 or $f1, we must check $f0.
1526 This is not optimal, because it will introduce an unnecessary
1527 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1528 need to distinguish reading both $f0 and $f1 or just one of
1529 them. Note that we don't have to check the other way,
1530 because there is no instruction that sets both $f0 and $f1
1531 and requires a delay. */
1532 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1533 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1534 == (reg &~ (unsigned) 1)))
1536 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1537 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1538 == (reg &~ (unsigned) 1)))
1541 else if (! mips_opts.mips16)
1543 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1544 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1546 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1547 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1552 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1553 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1554 & MIPS16OP_MASK_RX)]
1557 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1558 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1559 & MIPS16OP_MASK_RY)]
1562 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1563 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1564 & MIPS16OP_MASK_MOVE32Z)]
1567 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1569 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1571 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1573 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1574 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1575 & MIPS16OP_MASK_REGR32) == reg)
1582 /* This function returns true if modifying a register requires a
1586 reg_needs_delay (reg)
1589 unsigned long prev_pinfo;
1591 prev_pinfo = prev_insn.insn_mo->pinfo;
1592 if (! mips_opts.noreorder
1593 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1594 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1595 || (! gpr_interlocks
1596 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1598 /* A load from a coprocessor or from memory. All load
1599 delays delay the use of general register rt for one
1600 instruction on the r3000. The r6000 and r4000 use
1602 /* Itbl support may require additional care here. */
1603 know (prev_pinfo & INSN_WRITE_GPR_T);
1604 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1611 /* Mark instruction labels in mips16 mode. This permits the linker to
1612 handle them specially, such as generating jalx instructions when
1613 needed. We also make them odd for the duration of the assembly, in
1614 order to generate the right sort of code. We will make them even
1615 in the adjust_symtab routine, while leaving them marked. This is
1616 convenient for the debugger and the disassembler. The linker knows
1617 to make them odd again. */
1620 mips16_mark_labels ()
1622 if (mips_opts.mips16)
1624 struct insn_label_list *l;
1627 for (l = insn_labels; l != NULL; l = l->next)
1630 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1631 S_SET_OTHER (l->label, STO_MIPS16);
1633 val = S_GET_VALUE (l->label);
1635 S_SET_VALUE (l->label, val + 1);
1640 /* Output an instruction. PLACE is where to put the instruction; if
1641 it is NULL, this uses frag_more to get room. IP is the instruction
1642 information. ADDRESS_EXPR is an operand of the instruction to be
1643 used with RELOC_TYPE. */
1646 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1648 struct mips_cl_insn *ip;
1649 expressionS *address_expr;
1650 bfd_reloc_code_real_type *reloc_type;
1651 boolean unmatched_hi;
1653 register unsigned long prev_pinfo, pinfo;
1658 /* Mark instruction labels in mips16 mode. */
1659 mips16_mark_labels ();
1661 prev_pinfo = prev_insn.insn_mo->pinfo;
1662 pinfo = ip->insn_mo->pinfo;
1664 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1668 /* If the previous insn required any delay slots, see if we need
1669 to insert a NOP or two. There are eight kinds of possible
1670 hazards, of which an instruction can have at most one type.
1671 (1) a load from memory delay
1672 (2) a load from a coprocessor delay
1673 (3) an unconditional branch delay
1674 (4) a conditional branch delay
1675 (5) a move to coprocessor register delay
1676 (6) a load coprocessor register from memory delay
1677 (7) a coprocessor condition code delay
1678 (8) a HI/LO special register delay
1680 There are a lot of optimizations we could do that we don't.
1681 In particular, we do not, in general, reorder instructions.
1682 If you use gcc with optimization, it will reorder
1683 instructions and generally do much more optimization then we
1684 do here; repeating all that work in the assembler would only
1685 benefit hand written assembly code, and does not seem worth
1688 /* This is how a NOP is emitted. */
1689 #define emit_nop() \
1691 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1692 : md_number_to_chars (frag_more (4), 0, 4))
1694 /* The previous insn might require a delay slot, depending upon
1695 the contents of the current insn. */
1696 if (! mips_opts.mips16
1697 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1698 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1699 && ! cop_interlocks)
1700 || (! gpr_interlocks
1701 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1703 /* A load from a coprocessor or from memory. All load
1704 delays delay the use of general register rt for one
1705 instruction on the r3000. The r6000 and r4000 use
1707 /* Itbl support may require additional care here. */
1708 know (prev_pinfo & INSN_WRITE_GPR_T);
1709 if (mips_optimize == 0
1710 || insn_uses_reg (ip,
1711 ((prev_insn.insn_opcode >> OP_SH_RT)
1716 else if (! mips_opts.mips16
1717 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1718 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1719 && ! cop_interlocks)
1720 || (mips_opts.isa == ISA_MIPS1
1721 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1723 /* A generic coprocessor delay. The previous instruction
1724 modified a coprocessor general or control register. If
1725 it modified a control register, we need to avoid any
1726 coprocessor instruction (this is probably not always
1727 required, but it sometimes is). If it modified a general
1728 register, we avoid using that register.
1730 On the r6000 and r4000 loading a coprocessor register
1731 from memory is interlocked, and does not require a delay.
1733 This case is not handled very well. There is no special
1734 knowledge of CP0 handling, and the coprocessors other
1735 than the floating point unit are not distinguished at
1737 /* Itbl support may require additional care here. FIXME!
1738 Need to modify this to include knowledge about
1739 user specified delays! */
1740 if (prev_pinfo & INSN_WRITE_FPR_T)
1742 if (mips_optimize == 0
1743 || insn_uses_reg (ip,
1744 ((prev_insn.insn_opcode >> OP_SH_FT)
1749 else if (prev_pinfo & INSN_WRITE_FPR_S)
1751 if (mips_optimize == 0
1752 || insn_uses_reg (ip,
1753 ((prev_insn.insn_opcode >> OP_SH_FS)
1760 /* We don't know exactly what the previous instruction
1761 does. If the current instruction uses a coprocessor
1762 register, we must insert a NOP. If previous
1763 instruction may set the condition codes, and the
1764 current instruction uses them, we must insert two
1766 /* Itbl support may require additional care here. */
1767 if (mips_optimize == 0
1768 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1769 && (pinfo & INSN_READ_COND_CODE)))
1771 else if (pinfo & INSN_COP)
1775 else if (! mips_opts.mips16
1776 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1777 && (prev_pinfo & INSN_WRITE_COND_CODE)
1778 && ! cop_interlocks)
1780 /* The previous instruction sets the coprocessor condition
1781 codes, but does not require a general coprocessor delay
1782 (this means it is a floating point comparison
1783 instruction). If this instruction uses the condition
1784 codes, we need to insert a single NOP. */
1785 /* Itbl support may require additional care here. */
1786 if (mips_optimize == 0
1787 || (pinfo & INSN_READ_COND_CODE))
1791 /* If we're fixing up mfhi/mflo for the r7000 and the
1792 previous insn was an mfhi/mflo and the current insn
1793 reads the register that the mfhi/mflo wrote to, then
1796 else if (mips_7000_hilo_fix
1797 && MF_HILO_INSN (prev_pinfo)
1798 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1805 /* If we're fixing up mfhi/mflo for the r7000 and the
1806 2nd previous insn was an mfhi/mflo and the current insn
1807 reads the register that the mfhi/mflo wrote to, then
1810 else if (mips_7000_hilo_fix
1811 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1812 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1820 else if (prev_pinfo & INSN_READ_LO)
1822 /* The previous instruction reads the LO register; if the
1823 current instruction writes to the LO register, we must
1824 insert two NOPS. Some newer processors have interlocks.
1825 Also the tx39's multiply instructions can be exectuted
1826 immediatly after a read from HI/LO (without the delay),
1827 though the tx39's divide insns still do require the
1829 if (! (hilo_interlocks
1830 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1831 && (mips_optimize == 0
1832 || (pinfo & INSN_WRITE_LO)))
1834 /* Most mips16 branch insns don't have a delay slot.
1835 If a read from LO is immediately followed by a branch
1836 to a write to LO we have a read followed by a write
1837 less than 2 insns away. We assume the target of
1838 a branch might be a write to LO, and insert a nop
1839 between a read and an immediately following branch. */
1840 else if (mips_opts.mips16
1841 && (mips_optimize == 0
1842 || (pinfo & MIPS16_INSN_BRANCH)))
1845 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1847 /* The previous instruction reads the HI register; if the
1848 current instruction writes to the HI register, we must
1849 insert a NOP. Some newer processors have interlocks.
1850 Also the note tx39's multiply above. */
1851 if (! (hilo_interlocks
1852 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1853 && (mips_optimize == 0
1854 || (pinfo & INSN_WRITE_HI)))
1856 /* Most mips16 branch insns don't have a delay slot.
1857 If a read from HI is immediately followed by a branch
1858 to a write to HI we have a read followed by a write
1859 less than 2 insns away. We assume the target of
1860 a branch might be a write to HI, and insert a nop
1861 between a read and an immediately following branch. */
1862 else if (mips_opts.mips16
1863 && (mips_optimize == 0
1864 || (pinfo & MIPS16_INSN_BRANCH)))
1868 /* If the previous instruction was in a noreorder section, then
1869 we don't want to insert the nop after all. */
1870 /* Itbl support may require additional care here. */
1871 if (prev_insn_unreordered)
1874 /* There are two cases which require two intervening
1875 instructions: 1) setting the condition codes using a move to
1876 coprocessor instruction which requires a general coprocessor
1877 delay and then reading the condition codes 2) reading the HI
1878 or LO register and then writing to it (except on processors
1879 which have interlocks). If we are not already emitting a NOP
1880 instruction, we must check for these cases compared to the
1881 instruction previous to the previous instruction. */
1882 if ((! mips_opts.mips16
1883 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1884 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1885 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1886 && (pinfo & INSN_READ_COND_CODE)
1887 && ! cop_interlocks)
1888 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1889 && (pinfo & INSN_WRITE_LO)
1890 && ! (hilo_interlocks
1891 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1892 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1893 && (pinfo & INSN_WRITE_HI)
1894 && ! (hilo_interlocks
1895 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1900 if (prev_prev_insn_unreordered)
1903 if (prev_prev_nop && nops == 0)
1906 /* If we are being given a nop instruction, don't bother with
1907 one of the nops we would otherwise output. This will only
1908 happen when a nop instruction is used with mips_optimize set
1911 && ! mips_opts.noreorder
1912 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1915 /* Now emit the right number of NOP instructions. */
1916 if (nops > 0 && ! mips_opts.noreorder)
1919 unsigned long old_frag_offset;
1921 struct insn_label_list *l;
1923 old_frag = frag_now;
1924 old_frag_offset = frag_now_fix ();
1926 for (i = 0; i < nops; i++)
1931 listing_prev_line ();
1932 /* We may be at the start of a variant frag. In case we
1933 are, make sure there is enough space for the frag
1934 after the frags created by listing_prev_line. The
1935 argument to frag_grow here must be at least as large
1936 as the argument to all other calls to frag_grow in
1937 this file. We don't have to worry about being in the
1938 middle of a variant frag, because the variants insert
1939 all needed nop instructions themselves. */
1943 for (l = insn_labels; l != NULL; l = l->next)
1947 assert (S_GET_SEGMENT (l->label) == now_seg);
1948 symbol_set_frag (l->label, frag_now);
1949 val = (valueT) frag_now_fix ();
1950 /* mips16 text labels are stored as odd. */
1951 if (mips_opts.mips16)
1953 S_SET_VALUE (l->label, val);
1956 #ifndef NO_ECOFF_DEBUGGING
1957 if (ECOFF_DEBUGGING)
1958 ecoff_fix_loc (old_frag, old_frag_offset);
1961 else if (prev_nop_frag != NULL)
1963 /* We have a frag holding nops we may be able to remove. If
1964 we don't need any nops, we can decrease the size of
1965 prev_nop_frag by the size of one instruction. If we do
1966 need some nops, we count them in prev_nops_required. */
1967 if (prev_nop_frag_since == 0)
1971 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1972 --prev_nop_frag_holds;
1975 prev_nop_frag_required += nops;
1979 if (prev_prev_nop == 0)
1981 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1982 --prev_nop_frag_holds;
1985 ++prev_nop_frag_required;
1988 if (prev_nop_frag_holds <= prev_nop_frag_required)
1989 prev_nop_frag = NULL;
1991 ++prev_nop_frag_since;
1993 /* Sanity check: by the time we reach the second instruction
1994 after prev_nop_frag, we should have used up all the nops
1995 one way or another. */
1996 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
2000 if (*reloc_type > BFD_RELOC_UNUSED)
2002 /* We need to set up a variant frag. */
2003 assert (mips_opts.mips16 && address_expr != NULL);
2004 f = frag_var (rs_machine_dependent, 4, 0,
2005 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
2006 mips16_small, mips16_ext,
2008 & INSN_UNCOND_BRANCH_DELAY),
2009 (*prev_insn_reloc_type
2010 == BFD_RELOC_MIPS16_JMP)),
2011 make_expr_symbol (address_expr), 0, NULL);
2013 else if (place != NULL)
2015 else if (mips_opts.mips16
2017 && *reloc_type != BFD_RELOC_MIPS16_JMP)
2019 /* Make sure there is enough room to swap this instruction with
2020 a following jump instruction. */
2026 if (mips_opts.mips16
2027 && mips_opts.noreorder
2028 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
2029 as_warn (_("extended instruction in delay slot"));
2034 fixp[0] = fixp[1] = fixp[2] = NULL;
2035 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
2037 if (address_expr->X_op == O_constant)
2041 switch (*reloc_type)
2044 ip->insn_opcode |= address_expr->X_add_number;
2047 case BFD_RELOC_MIPS_HIGHEST:
2048 tmp = (address_expr->X_add_number + 0x800080008000) >> 16;
2050 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2053 case BFD_RELOC_MIPS_HIGHER:
2054 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
2055 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2058 case BFD_RELOC_HI16_S:
2059 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
2063 case BFD_RELOC_HI16:
2064 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2067 case BFD_RELOC_LO16:
2068 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2071 case BFD_RELOC_MIPS_JMP:
2072 if ((address_expr->X_add_number & 3) != 0)
2073 as_bad (_("jump to misaligned address (0x%lx)"),
2074 (unsigned long) address_expr->X_add_number);
2075 if (address_expr->X_add_number & ~0xfffffff
2076 || address_expr->X_add_number > 0x7fffffc)
2077 as_bad (_("jump address range overflow (0x%lx)"),
2078 (unsigned long) address_expr->X_add_number);
2079 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2082 case BFD_RELOC_MIPS16_JMP:
2083 if ((address_expr->X_add_number & 3) != 0)
2084 as_bad (_("jump to misaligned address (0x%lx)"),
2085 (unsigned long) address_expr->X_add_number);
2086 if (address_expr->X_add_number & ~0xfffffff
2087 || address_expr->X_add_number > 0x7fffffc)
2088 as_bad (_("jump address range overflow (0x%lx)"),
2089 (unsigned long) address_expr->X_add_number);
2091 (((address_expr->X_add_number & 0x7c0000) << 3)
2092 | ((address_expr->X_add_number & 0xf800000) >> 7)
2093 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2096 case BFD_RELOC_16_PCREL:
2097 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2100 case BFD_RELOC_16_PCREL_S2:
2110 /* Don't generate a reloc if we are writing into a variant frag. */
2113 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
2115 (*reloc_type == BFD_RELOC_16_PCREL
2116 || *reloc_type == BFD_RELOC_16_PCREL_S2),
2119 /* These relocations can have an addend that won't fit in
2120 4 octets for 64bit assembly. */
2121 if (HAVE_64BIT_GPRS &&
2122 (*reloc_type == BFD_RELOC_16
2123 || *reloc_type == BFD_RELOC_32
2124 || *reloc_type == BFD_RELOC_MIPS_JMP
2125 || *reloc_type == BFD_RELOC_HI16_S
2126 || *reloc_type == BFD_RELOC_LO16
2127 || *reloc_type == BFD_RELOC_GPREL16
2128 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2129 || *reloc_type == BFD_RELOC_GPREL32
2130 || *reloc_type == BFD_RELOC_64
2131 || *reloc_type == BFD_RELOC_CTOR
2132 || *reloc_type == BFD_RELOC_MIPS_SUB
2133 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2134 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2135 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2136 || *reloc_type == BFD_RELOC_MIPS_REL16
2137 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2138 fixp[0]->fx_no_overflow = 1;
2142 struct mips_hi_fixup *hi_fixup;
2144 assert (*reloc_type == BFD_RELOC_HI16_S);
2145 hi_fixup = ((struct mips_hi_fixup *)
2146 xmalloc (sizeof (struct mips_hi_fixup)));
2147 hi_fixup->fixp = fixp[0];
2148 hi_fixup->seg = now_seg;
2149 hi_fixup->next = mips_hi_fixup_list;
2150 mips_hi_fixup_list = hi_fixup;
2153 if (reloc_type[1] != BFD_RELOC_UNUSED)
2155 /* FIXME: This symbol can be one of
2156 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
2157 address_expr->X_op = O_absent;
2158 address_expr->X_add_symbol = 0;
2159 address_expr->X_add_number = 0;
2161 fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal,
2162 4, address_expr, false,
2165 /* These relocations can have an addend that won't fit in
2166 4 octets for 64bit assembly. */
2167 if (HAVE_64BIT_GPRS &&
2168 (*reloc_type == BFD_RELOC_16
2169 || *reloc_type == BFD_RELOC_32
2170 || *reloc_type == BFD_RELOC_MIPS_JMP
2171 || *reloc_type == BFD_RELOC_HI16_S
2172 || *reloc_type == BFD_RELOC_LO16
2173 || *reloc_type == BFD_RELOC_GPREL16
2174 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2175 || *reloc_type == BFD_RELOC_GPREL32
2176 || *reloc_type == BFD_RELOC_64
2177 || *reloc_type == BFD_RELOC_CTOR
2178 || *reloc_type == BFD_RELOC_MIPS_SUB
2179 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2180 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2181 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2182 || *reloc_type == BFD_RELOC_MIPS_REL16
2183 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2184 fixp[1]->fx_no_overflow = 1;
2186 if (reloc_type[2] != BFD_RELOC_UNUSED)
2188 address_expr->X_op = O_absent;
2189 address_expr->X_add_symbol = 0;
2190 address_expr->X_add_number = 0;
2192 fixp[2] = fix_new_exp (frag_now,
2193 f - frag_now->fr_literal, 4,
2194 address_expr, false,
2197 /* These relocations can have an addend that won't fit in
2198 4 octets for 64bit assembly. */
2199 if (HAVE_64BIT_GPRS &&
2200 (*reloc_type == BFD_RELOC_16
2201 || *reloc_type == BFD_RELOC_32
2202 || *reloc_type == BFD_RELOC_MIPS_JMP
2203 || *reloc_type == BFD_RELOC_HI16_S
2204 || *reloc_type == BFD_RELOC_LO16
2205 || *reloc_type == BFD_RELOC_GPREL16
2206 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2207 || *reloc_type == BFD_RELOC_GPREL32
2208 || *reloc_type == BFD_RELOC_64
2209 || *reloc_type == BFD_RELOC_CTOR
2210 || *reloc_type == BFD_RELOC_MIPS_SUB
2211 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2212 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2213 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2214 || *reloc_type == BFD_RELOC_MIPS_REL16
2215 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2216 fixp[2]->fx_no_overflow = 1;
2223 if (! mips_opts.mips16)
2224 md_number_to_chars (f, ip->insn_opcode, 4);
2225 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2227 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2228 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2234 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2237 md_number_to_chars (f, ip->insn_opcode, 2);
2240 /* Update the register mask information. */
2241 if (! mips_opts.mips16)
2243 if (pinfo & INSN_WRITE_GPR_D)
2244 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2245 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2246 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2247 if (pinfo & INSN_READ_GPR_S)
2248 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2249 if (pinfo & INSN_WRITE_GPR_31)
2250 mips_gprmask |= 1 << RA;
2251 if (pinfo & INSN_WRITE_FPR_D)
2252 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2253 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2254 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2255 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2256 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2257 if ((pinfo & INSN_READ_FPR_R) != 0)
2258 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2259 if (pinfo & INSN_COP)
2261 /* We don't keep enough information to sort these cases out.
2262 The itbl support does keep this information however, although
2263 we currently don't support itbl fprmats as part of the cop
2264 instruction. May want to add this support in the future. */
2266 /* Never set the bit for $0, which is always zero. */
2267 mips_gprmask &= ~1 << 0;
2271 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2272 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2273 & MIPS16OP_MASK_RX);
2274 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2275 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2276 & MIPS16OP_MASK_RY);
2277 if (pinfo & MIPS16_INSN_WRITE_Z)
2278 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2279 & MIPS16OP_MASK_RZ);
2280 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2281 mips_gprmask |= 1 << TREG;
2282 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2283 mips_gprmask |= 1 << SP;
2284 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2285 mips_gprmask |= 1 << RA;
2286 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2287 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2288 if (pinfo & MIPS16_INSN_READ_Z)
2289 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2290 & MIPS16OP_MASK_MOVE32Z);
2291 if (pinfo & MIPS16_INSN_READ_GPR_X)
2292 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2293 & MIPS16OP_MASK_REGR32);
2296 if (place == NULL && ! mips_opts.noreorder)
2298 /* Filling the branch delay slot is more complex. We try to
2299 switch the branch with the previous instruction, which we can
2300 do if the previous instruction does not set up a condition
2301 that the branch tests and if the branch is not itself the
2302 target of any branch. */
2303 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2304 || (pinfo & INSN_COND_BRANCH_DELAY))
2306 if (mips_optimize < 2
2307 /* If we have seen .set volatile or .set nomove, don't
2309 || mips_opts.nomove != 0
2310 /* If we had to emit any NOP instructions, then we
2311 already know we can not swap. */
2313 /* If we don't even know the previous insn, we can not
2315 || ! prev_insn_valid
2316 /* If the previous insn is already in a branch delay
2317 slot, then we can not swap. */
2318 || prev_insn_is_delay_slot
2319 /* If the previous previous insn was in a .set
2320 noreorder, we can't swap. Actually, the MIPS
2321 assembler will swap in this situation. However, gcc
2322 configured -with-gnu-as will generate code like
2328 in which we can not swap the bne and INSN. If gcc is
2329 not configured -with-gnu-as, it does not output the
2330 .set pseudo-ops. We don't have to check
2331 prev_insn_unreordered, because prev_insn_valid will
2332 be 0 in that case. We don't want to use
2333 prev_prev_insn_valid, because we do want to be able
2334 to swap at the start of a function. */
2335 || prev_prev_insn_unreordered
2336 /* If the branch is itself the target of a branch, we
2337 can not swap. We cheat on this; all we check for is
2338 whether there is a label on this instruction. If
2339 there are any branches to anything other than a
2340 label, users must use .set noreorder. */
2341 || insn_labels != NULL
2342 /* If the previous instruction is in a variant frag, we
2343 can not do the swap. This does not apply to the
2344 mips16, which uses variant frags for different
2346 || (! mips_opts.mips16
2347 && prev_insn_frag->fr_type == rs_machine_dependent)
2348 /* If the branch reads the condition codes, we don't
2349 even try to swap, because in the sequence
2354 we can not swap, and I don't feel like handling that
2356 || (! mips_opts.mips16
2357 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2358 && (pinfo & INSN_READ_COND_CODE))
2359 /* We can not swap with an instruction that requires a
2360 delay slot, becase the target of the branch might
2361 interfere with that instruction. */
2362 || (! mips_opts.mips16
2363 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2365 /* Itbl support may require additional care here. */
2366 & (INSN_LOAD_COPROC_DELAY
2367 | INSN_COPROC_MOVE_DELAY
2368 | INSN_WRITE_COND_CODE)))
2369 || (! (hilo_interlocks
2370 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2374 || (! mips_opts.mips16
2376 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2377 || (! mips_opts.mips16
2378 && mips_opts.isa == ISA_MIPS1
2379 /* Itbl support may require additional care here. */
2380 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2381 /* We can not swap with a branch instruction. */
2383 & (INSN_UNCOND_BRANCH_DELAY
2384 | INSN_COND_BRANCH_DELAY
2385 | INSN_COND_BRANCH_LIKELY))
2386 /* We do not swap with a trap instruction, since it
2387 complicates trap handlers to have the trap
2388 instruction be in a delay slot. */
2389 || (prev_pinfo & INSN_TRAP)
2390 /* If the branch reads a register that the previous
2391 instruction sets, we can not swap. */
2392 || (! mips_opts.mips16
2393 && (prev_pinfo & INSN_WRITE_GPR_T)
2394 && insn_uses_reg (ip,
2395 ((prev_insn.insn_opcode >> OP_SH_RT)
2398 || (! mips_opts.mips16
2399 && (prev_pinfo & INSN_WRITE_GPR_D)
2400 && insn_uses_reg (ip,
2401 ((prev_insn.insn_opcode >> OP_SH_RD)
2404 || (mips_opts.mips16
2405 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2406 && insn_uses_reg (ip,
2407 ((prev_insn.insn_opcode
2409 & MIPS16OP_MASK_RX),
2411 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2412 && insn_uses_reg (ip,
2413 ((prev_insn.insn_opcode
2415 & MIPS16OP_MASK_RY),
2417 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2418 && insn_uses_reg (ip,
2419 ((prev_insn.insn_opcode
2421 & MIPS16OP_MASK_RZ),
2423 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2424 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2425 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2426 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2427 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2428 && insn_uses_reg (ip,
2429 MIPS16OP_EXTRACT_REG32R (prev_insn.
2432 /* If the branch writes a register that the previous
2433 instruction sets, we can not swap (we know that
2434 branches write only to RD or to $31). */
2435 || (! mips_opts.mips16
2436 && (prev_pinfo & INSN_WRITE_GPR_T)
2437 && (((pinfo & INSN_WRITE_GPR_D)
2438 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2439 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2440 || ((pinfo & INSN_WRITE_GPR_31)
2441 && (((prev_insn.insn_opcode >> OP_SH_RT)
2444 || (! mips_opts.mips16
2445 && (prev_pinfo & INSN_WRITE_GPR_D)
2446 && (((pinfo & INSN_WRITE_GPR_D)
2447 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2448 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2449 || ((pinfo & INSN_WRITE_GPR_31)
2450 && (((prev_insn.insn_opcode >> OP_SH_RD)
2453 || (mips_opts.mips16
2454 && (pinfo & MIPS16_INSN_WRITE_31)
2455 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2456 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2457 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2459 /* If the branch writes a register that the previous
2460 instruction reads, we can not swap (we know that
2461 branches only write to RD or to $31). */
2462 || (! mips_opts.mips16
2463 && (pinfo & INSN_WRITE_GPR_D)
2464 && insn_uses_reg (&prev_insn,
2465 ((ip->insn_opcode >> OP_SH_RD)
2468 || (! mips_opts.mips16
2469 && (pinfo & INSN_WRITE_GPR_31)
2470 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2471 || (mips_opts.mips16
2472 && (pinfo & MIPS16_INSN_WRITE_31)
2473 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2474 /* If we are generating embedded PIC code, the branch
2475 might be expanded into a sequence which uses $at, so
2476 we can't swap with an instruction which reads it. */
2477 || (mips_pic == EMBEDDED_PIC
2478 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2479 /* If the previous previous instruction has a load
2480 delay, and sets a register that the branch reads, we
2482 || (! mips_opts.mips16
2483 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2484 /* Itbl support may require additional care here. */
2485 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2486 || (! gpr_interlocks
2487 && (prev_prev_insn.insn_mo->pinfo
2488 & INSN_LOAD_MEMORY_DELAY)))
2489 && insn_uses_reg (ip,
2490 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2493 /* If one instruction sets a condition code and the
2494 other one uses a condition code, we can not swap. */
2495 || ((pinfo & INSN_READ_COND_CODE)
2496 && (prev_pinfo & INSN_WRITE_COND_CODE))
2497 || ((pinfo & INSN_WRITE_COND_CODE)
2498 && (prev_pinfo & INSN_READ_COND_CODE))
2499 /* If the previous instruction uses the PC, we can not
2501 || (mips_opts.mips16
2502 && (prev_pinfo & MIPS16_INSN_READ_PC))
2503 /* If the previous instruction was extended, we can not
2505 || (mips_opts.mips16 && prev_insn_extended)
2506 /* If the previous instruction had a fixup in mips16
2507 mode, we can not swap. This normally means that the
2508 previous instruction was a 4 byte branch anyhow. */
2509 || (mips_opts.mips16 && prev_insn_fixp[0])
2510 /* If the previous instruction is a sync, sync.l, or
2511 sync.p, we can not swap. */
2512 || (prev_pinfo & INSN_SYNC))
2514 /* We could do even better for unconditional branches to
2515 portions of this object file; we could pick up the
2516 instruction at the destination, put it in the delay
2517 slot, and bump the destination address. */
2519 /* Update the previous insn information. */
2520 prev_prev_insn = *ip;
2521 prev_insn.insn_mo = &dummy_opcode;
2525 /* It looks like we can actually do the swap. */
2526 if (! mips_opts.mips16)
2531 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2532 memcpy (temp, prev_f, 4);
2533 memcpy (prev_f, f, 4);
2534 memcpy (f, temp, 4);
2535 if (prev_insn_fixp[0])
2537 prev_insn_fixp[0]->fx_frag = frag_now;
2538 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2540 if (prev_insn_fixp[1])
2542 prev_insn_fixp[1]->fx_frag = frag_now;
2543 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2545 if (prev_insn_fixp[2])
2547 prev_insn_fixp[2]->fx_frag = frag_now;
2548 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2552 fixp[0]->fx_frag = prev_insn_frag;
2553 fixp[0]->fx_where = prev_insn_where;
2557 fixp[1]->fx_frag = prev_insn_frag;
2558 fixp[1]->fx_where = prev_insn_where;
2562 fixp[2]->fx_frag = prev_insn_frag;
2563 fixp[2]->fx_where = prev_insn_where;
2571 assert (prev_insn_fixp[0] == NULL);
2572 assert (prev_insn_fixp[1] == NULL);
2573 assert (prev_insn_fixp[2] == NULL);
2574 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2575 memcpy (temp, prev_f, 2);
2576 memcpy (prev_f, f, 2);
2577 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2579 assert (*reloc_type == BFD_RELOC_UNUSED);
2580 memcpy (f, temp, 2);
2584 memcpy (f, f + 2, 2);
2585 memcpy (f + 2, temp, 2);
2589 fixp[0]->fx_frag = prev_insn_frag;
2590 fixp[0]->fx_where = prev_insn_where;
2594 fixp[1]->fx_frag = prev_insn_frag;
2595 fixp[1]->fx_where = prev_insn_where;
2599 fixp[2]->fx_frag = prev_insn_frag;
2600 fixp[2]->fx_where = prev_insn_where;
2604 /* Update the previous insn information; leave prev_insn
2606 prev_prev_insn = *ip;
2608 prev_insn_is_delay_slot = 1;
2610 /* If that was an unconditional branch, forget the previous
2611 insn information. */
2612 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2614 prev_prev_insn.insn_mo = &dummy_opcode;
2615 prev_insn.insn_mo = &dummy_opcode;
2618 prev_insn_fixp[0] = NULL;
2619 prev_insn_fixp[1] = NULL;
2620 prev_insn_fixp[2] = NULL;
2621 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2622 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2623 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2624 prev_insn_extended = 0;
2626 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2628 /* We don't yet optimize a branch likely. What we should do
2629 is look at the target, copy the instruction found there
2630 into the delay slot, and increment the branch to jump to
2631 the next instruction. */
2633 /* Update the previous insn information. */
2634 prev_prev_insn = *ip;
2635 prev_insn.insn_mo = &dummy_opcode;
2636 prev_insn_fixp[0] = NULL;
2637 prev_insn_fixp[1] = NULL;
2638 prev_insn_fixp[2] = NULL;
2639 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2640 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2641 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2642 prev_insn_extended = 0;
2646 /* Update the previous insn information. */
2648 prev_prev_insn.insn_mo = &dummy_opcode;
2650 prev_prev_insn = prev_insn;
2653 /* Any time we see a branch, we always fill the delay slot
2654 immediately; since this insn is not a branch, we know it
2655 is not in a delay slot. */
2656 prev_insn_is_delay_slot = 0;
2658 prev_insn_fixp[0] = fixp[0];
2659 prev_insn_fixp[1] = fixp[1];
2660 prev_insn_fixp[2] = fixp[2];
2661 prev_insn_reloc_type[0] = reloc_type[0];
2662 prev_insn_reloc_type[1] = reloc_type[1];
2663 prev_insn_reloc_type[2] = reloc_type[2];
2664 if (mips_opts.mips16)
2665 prev_insn_extended = (ip->use_extend
2666 || *reloc_type > BFD_RELOC_UNUSED);
2669 prev_prev_insn_unreordered = prev_insn_unreordered;
2670 prev_insn_unreordered = 0;
2671 prev_insn_frag = frag_now;
2672 prev_insn_where = f - frag_now->fr_literal;
2673 prev_insn_valid = 1;
2675 else if (place == NULL)
2677 /* We need to record a bit of information even when we are not
2678 reordering, in order to determine the base address for mips16
2679 PC relative relocs. */
2680 prev_prev_insn = prev_insn;
2682 prev_insn_reloc_type[0] = reloc_type[0];
2683 prev_insn_reloc_type[1] = reloc_type[1];
2684 prev_insn_reloc_type[2] = reloc_type[2];
2685 prev_prev_insn_unreordered = prev_insn_unreordered;
2686 prev_insn_unreordered = 1;
2689 /* We just output an insn, so the next one doesn't have a label. */
2690 mips_clear_insn_labels ();
2692 /* We must ensure that a fixup associated with an unmatched %hi
2693 reloc does not become a variant frag. Otherwise, the
2694 rearrangement of %hi relocs in frob_file may confuse
2698 frag_wane (frag_now);
2703 /* This function forgets that there was any previous instruction or
2704 label. If PRESERVE is non-zero, it remembers enough information to
2705 know whether nops are needed before a noreorder section. */
2708 mips_no_prev_insn (preserve)
2713 prev_insn.insn_mo = &dummy_opcode;
2714 prev_prev_insn.insn_mo = &dummy_opcode;
2715 prev_nop_frag = NULL;
2716 prev_nop_frag_holds = 0;
2717 prev_nop_frag_required = 0;
2718 prev_nop_frag_since = 0;
2720 prev_insn_valid = 0;
2721 prev_insn_is_delay_slot = 0;
2722 prev_insn_unreordered = 0;
2723 prev_insn_extended = 0;
2724 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2725 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2726 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2727 prev_prev_insn_unreordered = 0;
2728 mips_clear_insn_labels ();
2731 /* This function must be called whenever we turn on noreorder or emit
2732 something other than instructions. It inserts any NOPS which might
2733 be needed by the previous instruction, and clears the information
2734 kept for the previous instructions. The INSNS parameter is true if
2735 instructions are to follow. */
2738 mips_emit_delays (insns)
2741 if (! mips_opts.noreorder)
2746 if ((! mips_opts.mips16
2747 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2748 && (! cop_interlocks
2749 && (prev_insn.insn_mo->pinfo
2750 & (INSN_LOAD_COPROC_DELAY
2751 | INSN_COPROC_MOVE_DELAY
2752 | INSN_WRITE_COND_CODE))))
2753 || (! hilo_interlocks
2754 && (prev_insn.insn_mo->pinfo
2757 || (! mips_opts.mips16
2759 && (prev_insn.insn_mo->pinfo
2760 & INSN_LOAD_MEMORY_DELAY))
2761 || (! mips_opts.mips16
2762 && mips_opts.isa == ISA_MIPS1
2763 && (prev_insn.insn_mo->pinfo
2764 & INSN_COPROC_MEMORY_DELAY)))
2766 /* Itbl support may require additional care here. */
2768 if ((! mips_opts.mips16
2769 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2770 && (! cop_interlocks
2771 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2772 || (! hilo_interlocks
2773 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2774 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2777 if (prev_insn_unreordered)
2780 else if ((! mips_opts.mips16
2781 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2782 && (! cop_interlocks
2783 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2784 || (! hilo_interlocks
2785 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2786 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2788 /* Itbl support may require additional care here. */
2789 if (! prev_prev_insn_unreordered)
2795 struct insn_label_list *l;
2799 /* Record the frag which holds the nop instructions, so
2800 that we can remove them if we don't need them. */
2801 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2802 prev_nop_frag = frag_now;
2803 prev_nop_frag_holds = nops;
2804 prev_nop_frag_required = 0;
2805 prev_nop_frag_since = 0;
2808 for (; nops > 0; --nops)
2813 /* Move on to a new frag, so that it is safe to simply
2814 decrease the size of prev_nop_frag. */
2815 frag_wane (frag_now);
2819 for (l = insn_labels; l != NULL; l = l->next)
2823 assert (S_GET_SEGMENT (l->label) == now_seg);
2824 symbol_set_frag (l->label, frag_now);
2825 val = (valueT) frag_now_fix ();
2826 /* mips16 text labels are stored as odd. */
2827 if (mips_opts.mips16)
2829 S_SET_VALUE (l->label, val);
2834 /* Mark instruction labels in mips16 mode. */
2836 mips16_mark_labels ();
2838 mips_no_prev_insn (insns);
2841 /* Build an instruction created by a macro expansion. This is passed
2842 a pointer to the count of instructions created so far, an
2843 expression, the name of the instruction to build, an operand format
2844 string, and corresponding arguments. */
2848 macro_build (char *place,
2856 macro_build (place, counter, ep, name, fmt, va_alist)
2865 struct mips_cl_insn insn;
2866 bfd_reloc_code_real_type r[3];
2870 va_start (args, fmt);
2876 * If the macro is about to expand into a second instruction,
2877 * print a warning if needed. We need to pass ip as a parameter
2878 * to generate a better warning message here...
2880 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2881 as_warn (_("Macro instruction expanded into multiple instructions"));
2884 * If the macro is about to expand into a second instruction,
2885 * and it is in a delay slot, print a warning.
2889 && mips_opts.noreorder
2890 && (prev_prev_insn.insn_mo->pinfo
2891 & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY
2892 | INSN_COND_BRANCH_LIKELY)) != 0)
2893 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2896 ++*counter; /* bump instruction counter */
2898 if (mips_opts.mips16)
2900 mips16_macro_build (place, counter, ep, name, fmt, args);
2905 r[0] = BFD_RELOC_UNUSED;
2906 r[1] = BFD_RELOC_UNUSED;
2907 r[2] = BFD_RELOC_UNUSED;
2908 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2909 assert (insn.insn_mo);
2910 assert (strcmp (name, insn.insn_mo->name) == 0);
2912 /* Search until we get a match for NAME. */
2915 /* It is assumed here that macros will never generate
2916 MIPS-3D instructions. */
2917 if (strcmp (fmt, insn.insn_mo->args) == 0
2918 && insn.insn_mo->pinfo != INSN_MACRO
2919 && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch)
2920 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2924 assert (insn.insn_mo->name);
2925 assert (strcmp (name, insn.insn_mo->name) == 0);
2928 insn.insn_opcode = insn.insn_mo->match;
2944 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2948 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2953 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2958 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2963 int tmp = va_arg (args, int);
2965 insn.insn_opcode |= tmp << OP_SH_RT;
2966 insn.insn_opcode |= tmp << OP_SH_RD;
2972 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2979 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2983 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2987 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2991 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2995 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
3002 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
3008 *r = (bfd_reloc_code_real_type) va_arg (args, int);
3009 assert (*r == BFD_RELOC_GPREL16
3010 || *r == BFD_RELOC_MIPS_LITERAL
3011 || *r == BFD_RELOC_MIPS_HIGHER
3012 || *r == BFD_RELOC_HI16_S
3013 || *r == BFD_RELOC_LO16
3014 || *r == BFD_RELOC_MIPS_GOT16
3015 || *r == BFD_RELOC_MIPS_CALL16
3016 || *r == BFD_RELOC_MIPS_GOT_LO16
3017 || *r == BFD_RELOC_MIPS_CALL_LO16
3018 || (ep->X_op == O_subtract
3019 && *r == BFD_RELOC_PCREL_LO16));
3023 *r = (bfd_reloc_code_real_type) va_arg (args, int);
3025 && (ep->X_op == O_constant
3026 || (ep->X_op == O_symbol
3027 && (*r == BFD_RELOC_MIPS_HIGHEST
3028 || *r == BFD_RELOC_HI16_S
3029 || *r == BFD_RELOC_HI16
3030 || *r == BFD_RELOC_GPREL16
3031 || *r == BFD_RELOC_MIPS_GOT_HI16
3032 || *r == BFD_RELOC_MIPS_CALL_HI16))
3033 || (ep->X_op == O_subtract
3034 && *r == BFD_RELOC_PCREL_HI16_S)));
3038 assert (ep != NULL);
3040 * This allows macro() to pass an immediate expression for
3041 * creating short branches without creating a symbol.
3042 * Note that the expression still might come from the assembly
3043 * input, in which case the value is not checked for range nor
3044 * is a relocation entry generated (yuck).
3046 if (ep->X_op == O_constant)
3048 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
3052 if (mips_pic == EMBEDDED_PIC)
3053 *r = BFD_RELOC_16_PCREL_S2;
3055 *r = BFD_RELOC_16_PCREL;
3059 assert (ep != NULL);
3060 *r = BFD_RELOC_MIPS_JMP;
3064 insn.insn_opcode |= va_arg (args, unsigned long);
3073 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3075 append_insn (place, &insn, ep, r, false);
3079 mips16_macro_build (place, counter, ep, name, fmt, args)
3081 int *counter ATTRIBUTE_UNUSED;
3087 struct mips_cl_insn insn;
3088 bfd_reloc_code_real_type r[3]
3089 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3091 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3092 assert (insn.insn_mo);
3093 assert (strcmp (name, insn.insn_mo->name) == 0);
3095 while (strcmp (fmt, insn.insn_mo->args) != 0
3096 || insn.insn_mo->pinfo == INSN_MACRO)
3099 assert (insn.insn_mo->name);
3100 assert (strcmp (name, insn.insn_mo->name) == 0);
3103 insn.insn_opcode = insn.insn_mo->match;
3104 insn.use_extend = false;
3123 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
3128 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
3132 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
3136 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
3146 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
3153 regno = va_arg (args, int);
3154 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3155 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3176 assert (ep != NULL);
3178 if (ep->X_op != O_constant)
3179 *r = (int) BFD_RELOC_UNUSED + c;
3182 mips16_immed (NULL, 0, c, ep->X_add_number, false, false,
3183 false, &insn.insn_opcode, &insn.use_extend,
3186 *r = BFD_RELOC_UNUSED;
3192 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3199 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3201 append_insn (place, &insn, ep, r, false);
3205 * Generate a "lui" instruction.
3208 macro_build_lui (place, counter, ep, regnum)
3214 expressionS high_expr;
3215 struct mips_cl_insn insn;
3216 bfd_reloc_code_real_type r[3]
3217 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3218 CONST char *name = "lui";
3219 CONST char *fmt = "t,u";
3221 assert (! mips_opts.mips16);
3227 high_expr.X_op = O_constant;
3228 high_expr.X_add_number = ep->X_add_number;
3231 if (high_expr.X_op == O_constant)
3233 /* we can compute the instruction now without a relocation entry */
3234 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3236 *r = BFD_RELOC_UNUSED;
3238 else if (! HAVE_NEWABI)
3240 assert (ep->X_op == O_symbol);
3241 /* _gp_disp is a special case, used from s_cpload. */
3242 assert (mips_pic == NO_PIC
3243 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
3244 *r = BFD_RELOC_HI16_S;
3248 * If the macro is about to expand into a second instruction,
3249 * print a warning if needed. We need to pass ip as a parameter
3250 * to generate a better warning message here...
3252 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3253 as_warn (_("Macro instruction expanded into multiple instructions"));
3256 ++*counter; /* bump instruction counter */
3258 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3259 assert (insn.insn_mo);
3260 assert (strcmp (name, insn.insn_mo->name) == 0);
3261 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3263 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3264 if (*r == BFD_RELOC_UNUSED)
3266 insn.insn_opcode |= high_expr.X_add_number;
3267 append_insn (place, &insn, NULL, r, false);
3270 append_insn (place, &insn, &high_expr, r, false);
3274 * Generates code to set the $at register to true (one)
3275 * if reg is less than the immediate expression.
3278 set_at (counter, reg, unsignedp)
3283 if (imm_expr.X_op == O_constant
3284 && imm_expr.X_add_number >= -0x8000
3285 && imm_expr.X_add_number < 0x8000)
3286 macro_build ((char *) NULL, counter, &imm_expr,
3287 unsignedp ? "sltiu" : "slti",
3288 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
3291 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3292 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3293 unsignedp ? "sltu" : "slt",
3294 "d,v,t", AT, reg, AT);
3298 /* Warn if an expression is not a constant. */
3301 check_absolute_expr (ip, ex)
3302 struct mips_cl_insn *ip;
3305 if (ex->X_op == O_big)
3306 as_bad (_("unsupported large constant"));
3307 else if (ex->X_op != O_constant)
3308 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3311 /* Count the leading zeroes by performing a binary chop. This is a
3312 bulky bit of source, but performance is a LOT better for the
3313 majority of values than a simple loop to count the bits:
3314 for (lcnt = 0; (lcnt < 32); lcnt++)
3315 if ((v) & (1 << (31 - lcnt)))
3317 However it is not code size friendly, and the gain will drop a bit
3318 on certain cached systems.
3320 #define COUNT_TOP_ZEROES(v) \
3321 (((v) & ~0xffff) == 0 \
3322 ? ((v) & ~0xff) == 0 \
3323 ? ((v) & ~0xf) == 0 \
3324 ? ((v) & ~0x3) == 0 \
3325 ? ((v) & ~0x1) == 0 \
3330 : ((v) & ~0x7) == 0 \
3333 : ((v) & ~0x3f) == 0 \
3334 ? ((v) & ~0x1f) == 0 \
3337 : ((v) & ~0x7f) == 0 \
3340 : ((v) & ~0xfff) == 0 \
3341 ? ((v) & ~0x3ff) == 0 \
3342 ? ((v) & ~0x1ff) == 0 \
3345 : ((v) & ~0x7ff) == 0 \
3348 : ((v) & ~0x3fff) == 0 \
3349 ? ((v) & ~0x1fff) == 0 \
3352 : ((v) & ~0x7fff) == 0 \
3355 : ((v) & ~0xffffff) == 0 \
3356 ? ((v) & ~0xfffff) == 0 \
3357 ? ((v) & ~0x3ffff) == 0 \
3358 ? ((v) & ~0x1ffff) == 0 \
3361 : ((v) & ~0x7ffff) == 0 \
3364 : ((v) & ~0x3fffff) == 0 \
3365 ? ((v) & ~0x1fffff) == 0 \
3368 : ((v) & ~0x7fffff) == 0 \
3371 : ((v) & ~0xfffffff) == 0 \
3372 ? ((v) & ~0x3ffffff) == 0 \
3373 ? ((v) & ~0x1ffffff) == 0 \
3376 : ((v) & ~0x7ffffff) == 0 \
3379 : ((v) & ~0x3fffffff) == 0 \
3380 ? ((v) & ~0x1fffffff) == 0 \
3383 : ((v) & ~0x7fffffff) == 0 \
3387 /* Is the given value a sign-extended 32-bit value? */
3388 #define IS_SEXT_32BIT_NUM(x) \
3389 (((x) &~ (offsetT) 0x7fffffff) == 0 \
3390 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
3393 * This routine generates the least number of instructions neccessary to load
3394 * an absolute expression value into a register.
3397 load_register (counter, reg, ep, dbl)
3404 expressionS hi32, lo32;
3406 if (ep->X_op != O_big)
3408 assert (ep->X_op == O_constant);
3409 if (ep->X_add_number < 0x8000
3410 && (ep->X_add_number >= 0
3411 || (ep->X_add_number >= -0x8000
3414 || sizeof (ep->X_add_number) > 4))))
3416 /* We can handle 16 bit signed values with an addiu to
3417 $zero. No need to ever use daddiu here, since $zero and
3418 the result are always correct in 32 bit mode. */
3419 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3420 (int) BFD_RELOC_LO16);
3423 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3425 /* We can handle 16 bit unsigned values with an ori to
3427 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3428 (int) BFD_RELOC_LO16);
3431 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)
3434 || sizeof (ep->X_add_number) > 4
3435 || (ep->X_add_number & 0x80000000) == 0))
3436 || ((HAVE_32BIT_GPRS || ! dbl)
3437 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3440 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3441 == ~ (offsetT) 0xffffffff)))
3443 /* 32 bit values require an lui. */
3444 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3445 (int) BFD_RELOC_HI16);
3446 if ((ep->X_add_number & 0xffff) != 0)
3447 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3448 (int) BFD_RELOC_LO16);
3453 /* The value is larger than 32 bits. */
3455 if (HAVE_32BIT_GPRS)
3457 as_bad (_("Number (0x%lx) larger than 32 bits"),
3458 (unsigned long) ep->X_add_number);
3459 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3460 (int) BFD_RELOC_LO16);
3464 if (ep->X_op != O_big)
3467 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3468 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3469 hi32.X_add_number &= 0xffffffff;
3471 lo32.X_add_number &= 0xffffffff;
3475 assert (ep->X_add_number > 2);
3476 if (ep->X_add_number == 3)
3477 generic_bignum[3] = 0;
3478 else if (ep->X_add_number > 4)
3479 as_bad (_("Number larger than 64 bits"));
3480 lo32.X_op = O_constant;
3481 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3482 hi32.X_op = O_constant;
3483 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3486 if (hi32.X_add_number == 0)
3491 unsigned long hi, lo;
3493 if (hi32.X_add_number == (offsetT) 0xffffffff)
3495 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3497 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3498 reg, 0, (int) BFD_RELOC_LO16);
3501 if (lo32.X_add_number & 0x80000000)
3503 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3504 (int) BFD_RELOC_HI16);
3505 if (lo32.X_add_number & 0xffff)
3506 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3507 reg, reg, (int) BFD_RELOC_LO16);
3512 /* Check for 16bit shifted constant. We know that hi32 is
3513 non-zero, so start the mask on the first bit of the hi32
3518 unsigned long himask, lomask;
3522 himask = 0xffff >> (32 - shift);
3523 lomask = (0xffff << shift) & 0xffffffff;
3527 himask = 0xffff << (shift - 32);
3530 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3531 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3535 tmp.X_op = O_constant;
3537 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3538 | (lo32.X_add_number >> shift));
3540 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3541 macro_build ((char *) NULL, counter, &tmp,
3542 "ori", "t,r,i", reg, 0,
3543 (int) BFD_RELOC_LO16);
3544 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3545 (shift >= 32) ? "dsll32" : "dsll",
3547 (shift >= 32) ? shift - 32 : shift);
3552 while (shift <= (64 - 16));
3554 /* Find the bit number of the lowest one bit, and store the
3555 shifted value in hi/lo. */
3556 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3557 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3561 while ((lo & 1) == 0)
3566 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3572 while ((hi & 1) == 0)
3581 /* Optimize if the shifted value is a (power of 2) - 1. */
3582 if ((hi == 0 && ((lo + 1) & lo) == 0)
3583 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3585 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3590 /* This instruction will set the register to be all
3592 tmp.X_op = O_constant;
3593 tmp.X_add_number = (offsetT) -1;
3594 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3595 reg, 0, (int) BFD_RELOC_LO16);
3599 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3600 (bit >= 32) ? "dsll32" : "dsll",
3602 (bit >= 32) ? bit - 32 : bit);
3604 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3605 (shift >= 32) ? "dsrl32" : "dsrl",
3607 (shift >= 32) ? shift - 32 : shift);
3612 /* Sign extend hi32 before calling load_register, because we can
3613 generally get better code when we load a sign extended value. */
3614 if ((hi32.X_add_number & 0x80000000) != 0)
3615 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3616 load_register (counter, reg, &hi32, 0);
3619 if ((lo32.X_add_number & 0xffff0000) == 0)
3623 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3624 "dsll32", "d,w,<", reg, freg, 0);
3632 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3634 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3635 (int) BFD_RELOC_HI16);
3636 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3637 "dsrl32", "d,w,<", reg, reg, 0);
3643 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3644 "d,w,<", reg, freg, 16);
3648 mid16.X_add_number >>= 16;
3649 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3650 freg, (int) BFD_RELOC_LO16);
3651 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3652 "d,w,<", reg, reg, 16);
3655 if ((lo32.X_add_number & 0xffff) != 0)
3656 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3657 (int) BFD_RELOC_LO16);
3660 /* Load an address into a register. */
3663 load_address (counter, reg, ep, used_at)
3671 if (ep->X_op != O_constant
3672 && ep->X_op != O_symbol)
3674 as_bad (_("expression too complex"));
3675 ep->X_op = O_constant;
3678 if (ep->X_op == O_constant)
3680 load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES);
3684 if (mips_pic == NO_PIC)
3686 /* If this is a reference to a GP relative symbol, we want
3687 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3689 lui $reg,<sym> (BFD_RELOC_HI16_S)
3690 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3691 If we have an addend, we always use the latter form.
3693 With 64bit address space and a usable $at we want
3694 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3695 lui $at,<sym> (BFD_RELOC_HI16_S)
3696 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3697 daddiu $at,<sym> (BFD_RELOC_LO16)
3701 If $at is already in use, we use an path which is suboptimal
3702 on superscalar processors.
3703 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3704 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3706 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3708 daddiu $reg,<sym> (BFD_RELOC_LO16)
3710 if (HAVE_64BIT_ADDRESSES)
3712 /* We don't do GP optimization for now because RELAX_ENCODE can't
3713 hold the data for such large chunks. */
3717 macro_build (p, counter, ep, "lui", "t,u",
3718 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3719 macro_build (p, counter, ep, "lui", "t,u",
3720 AT, (int) BFD_RELOC_HI16_S);
3721 macro_build (p, counter, ep, "daddiu", "t,r,j",
3722 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3723 macro_build (p, counter, ep, "daddiu", "t,r,j",
3724 AT, AT, (int) BFD_RELOC_LO16);
3725 macro_build (p, counter, (expressionS *) NULL, "dsll32",
3726 "d,w,<", reg, reg, 0);
3727 macro_build (p, counter, (expressionS *) NULL, "dadd",
3728 "d,v,t", reg, reg, AT);
3733 macro_build (p, counter, ep, "lui", "t,u",
3734 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3735 macro_build (p, counter, ep, "daddiu", "t,r,j",
3736 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3737 macro_build (p, counter, (expressionS *) NULL, "dsll",
3738 "d,w,<", reg, reg, 16);
3739 macro_build (p, counter, ep, "daddiu", "t,r,j",
3740 reg, reg, (int) BFD_RELOC_HI16_S);
3741 macro_build (p, counter, (expressionS *) NULL, "dsll",
3742 "d,w,<", reg, reg, 16);
3743 macro_build (p, counter, ep, "daddiu", "t,r,j",
3744 reg, reg, (int) BFD_RELOC_LO16);
3749 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3750 && ! nopic_need_relax (ep->X_add_symbol, 1))
3753 macro_build ((char *) NULL, counter, ep,
3754 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
3755 reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
3756 p = frag_var (rs_machine_dependent, 8, 0,
3757 RELAX_ENCODE (4, 8, 0, 4, 0,
3758 mips_opts.warn_about_macros),
3759 ep->X_add_symbol, 0, NULL);
3761 macro_build_lui (p, counter, ep, reg);
3764 macro_build (p, counter, ep,
3765 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3766 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3769 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3773 /* If this is a reference to an external symbol, we want
3774 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3776 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3778 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3779 If there is a constant, it must be added in after. */
3780 ex.X_add_number = ep->X_add_number;
3781 ep->X_add_number = 0;
3783 macro_build ((char *) NULL, counter, ep,
3784 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
3785 reg, (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
3786 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3787 p = frag_var (rs_machine_dependent, 4, 0,
3788 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3789 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3790 macro_build (p, counter, ep,
3791 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3792 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3793 if (ex.X_add_number != 0)
3795 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3796 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3797 ex.X_op = O_constant;
3798 macro_build ((char *) NULL, counter, &ex,
3799 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3800 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3803 else if (mips_pic == SVR4_PIC)
3808 /* This is the large GOT case. If this is a reference to an
3809 external symbol, we want
3810 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3812 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3813 Otherwise, for a reference to a local symbol, we want
3814 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3816 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3817 If there is a constant, it must be added in after. */
3818 ex.X_add_number = ep->X_add_number;
3819 ep->X_add_number = 0;
3820 if (reg_needs_delay (GP))
3825 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3826 (int) BFD_RELOC_MIPS_GOT_HI16);
3827 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3828 dbl ? "daddu" : "addu", "d,v,t", reg, reg, GP);
3829 macro_build ((char *) NULL, counter, ep, dbl ? "ld" : "lw",
3830 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3831 p = frag_var (rs_machine_dependent, 12 + off, 0,
3832 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3833 mips_opts.warn_about_macros),
3834 ep->X_add_symbol, 0, NULL);
3837 /* We need a nop before loading from $gp. This special
3838 check is required because the lui which starts the main
3839 instruction stream does not refer to $gp, and so will not
3840 insert the nop which may be required. */
3841 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3844 macro_build (p, counter, ep, dbl ? "ld" : "lw",
3845 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3847 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3849 macro_build (p, counter, ep, dbl ? "daddiu" : "addiu",
3850 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3851 if (ex.X_add_number != 0)
3853 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3854 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3855 ex.X_op = O_constant;
3856 macro_build ((char *) NULL, counter, &ex, dbl ? "daddiu" : "addiu",
3857 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3860 else if (mips_pic == EMBEDDED_PIC)
3863 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3865 macro_build ((char *) NULL, counter, ep,
3866 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3867 "t,r,j", reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
3873 /* Move the contents of register SOURCE into register DEST. */
3876 move_register (counter, dest, source)
3881 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3882 HAVE_32BIT_GPRS ? "addu" : "daddu",
3883 "d,v,t", dest, source, 0);
3888 * This routine implements the seemingly endless macro or synthesized
3889 * instructions and addressing modes in the mips assembly language. Many
3890 * of these macros are simple and are similar to each other. These could
3891 * probably be handled by some kind of table or grammer aproach instead of
3892 * this verbose method. Others are not simple macros but are more like
3893 * optimizing code generation.
3894 * One interesting optimization is when several store macros appear
3895 * consecutivly that would load AT with the upper half of the same address.
3896 * The ensuing load upper instructions are ommited. This implies some kind
3897 * of global optimization. We currently only optimize within a single macro.
3898 * For many of the load and store macros if the address is specified as a
3899 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3900 * first load register 'at' with zero and use it as the base register. The
3901 * mips assembler simply uses register $zero. Just one tiny optimization
3906 struct mips_cl_insn *ip;
3908 register int treg, sreg, dreg, breg;
3924 bfd_reloc_code_real_type r;
3925 int hold_mips_optimize;
3927 assert (! mips_opts.mips16);
3929 treg = (ip->insn_opcode >> 16) & 0x1f;
3930 dreg = (ip->insn_opcode >> 11) & 0x1f;
3931 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3932 mask = ip->insn_mo->mask;
3934 expr1.X_op = O_constant;
3935 expr1.X_op_symbol = NULL;
3936 expr1.X_add_symbol = NULL;
3937 expr1.X_add_number = 1;
3949 mips_emit_delays (true);
3950 ++mips_opts.noreorder;
3951 mips_any_noreorder = 1;
3953 expr1.X_add_number = 8;
3954 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3956 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
3959 move_register (&icnt, dreg, sreg);
3960 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3961 dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
3963 --mips_opts.noreorder;
3984 if (imm_expr.X_op == O_constant
3985 && imm_expr.X_add_number >= -0x8000
3986 && imm_expr.X_add_number < 0x8000)
3988 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3989 (int) BFD_RELOC_LO16);
3992 load_register (&icnt, AT, &imm_expr, dbl);
3993 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
4013 if (imm_expr.X_op == O_constant
4014 && imm_expr.X_add_number >= 0
4015 && imm_expr.X_add_number < 0x10000)
4017 if (mask != M_NOR_I)
4018 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
4019 sreg, (int) BFD_RELOC_LO16);
4022 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
4023 treg, sreg, (int) BFD_RELOC_LO16);
4024 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor",
4025 "d,v,t", treg, treg, 0);
4030 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4031 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
4049 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4051 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
4055 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4056 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
4064 macro_build ((char *) NULL, &icnt, &offset_expr,
4065 likely ? "bgezl" : "bgez", "s,p", sreg);
4070 macro_build ((char *) NULL, &icnt, &offset_expr,
4071 likely ? "blezl" : "blez", "s,p", treg);
4074 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4076 macro_build ((char *) NULL, &icnt, &offset_expr,
4077 likely ? "beql" : "beq", "s,t,p", AT, 0);
4083 /* check for > max integer */
4084 maxnum = 0x7fffffff;
4085 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4092 if (imm_expr.X_op == O_constant
4093 && imm_expr.X_add_number >= maxnum
4094 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4097 /* result is always false */
4101 as_warn (_("Branch %s is always false (nop)"),
4103 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop",
4109 as_warn (_("Branch likely %s is always false"),
4111 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
4116 if (imm_expr.X_op != O_constant)
4117 as_bad (_("Unsupported large constant"));
4118 ++imm_expr.X_add_number;
4122 if (mask == M_BGEL_I)
4124 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4126 macro_build ((char *) NULL, &icnt, &offset_expr,
4127 likely ? "bgezl" : "bgez", "s,p", sreg);
4130 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4132 macro_build ((char *) NULL, &icnt, &offset_expr,
4133 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4136 maxnum = 0x7fffffff;
4137 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4144 maxnum = - maxnum - 1;
4145 if (imm_expr.X_op == O_constant
4146 && imm_expr.X_add_number <= maxnum
4147 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4150 /* result is always true */
4151 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4152 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4155 set_at (&icnt, sreg, 0);
4156 macro_build ((char *) NULL, &icnt, &offset_expr,
4157 likely ? "beql" : "beq", "s,t,p", AT, 0);
4167 macro_build ((char *) NULL, &icnt, &offset_expr,
4168 likely ? "beql" : "beq", "s,t,p", 0, treg);
4171 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4172 "d,v,t", AT, sreg, treg);
4173 macro_build ((char *) NULL, &icnt, &offset_expr,
4174 likely ? "beql" : "beq", "s,t,p", AT, 0);
4182 && imm_expr.X_op == O_constant
4183 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4185 if (imm_expr.X_op != O_constant)
4186 as_bad (_("Unsupported large constant"));
4187 ++imm_expr.X_add_number;
4191 if (mask == M_BGEUL_I)
4193 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4195 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4197 macro_build ((char *) NULL, &icnt, &offset_expr,
4198 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4201 set_at (&icnt, sreg, 1);
4202 macro_build ((char *) NULL, &icnt, &offset_expr,
4203 likely ? "beql" : "beq", "s,t,p", AT, 0);
4211 macro_build ((char *) NULL, &icnt, &offset_expr,
4212 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4217 macro_build ((char *) NULL, &icnt, &offset_expr,
4218 likely ? "bltzl" : "bltz", "s,p", treg);
4221 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4223 macro_build ((char *) NULL, &icnt, &offset_expr,
4224 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4232 macro_build ((char *) NULL, &icnt, &offset_expr,
4233 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4238 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4239 "d,v,t", AT, treg, sreg);
4240 macro_build ((char *) NULL, &icnt, &offset_expr,
4241 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4249 macro_build ((char *) NULL, &icnt, &offset_expr,
4250 likely ? "blezl" : "blez", "s,p", sreg);
4255 macro_build ((char *) NULL, &icnt, &offset_expr,
4256 likely ? "bgezl" : "bgez", "s,p", treg);
4259 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4261 macro_build ((char *) NULL, &icnt, &offset_expr,
4262 likely ? "beql" : "beq", "s,t,p", AT, 0);
4268 maxnum = 0x7fffffff;
4269 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4276 if (imm_expr.X_op == O_constant
4277 && imm_expr.X_add_number >= maxnum
4278 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4280 if (imm_expr.X_op != O_constant)
4281 as_bad (_("Unsupported large constant"));
4282 ++imm_expr.X_add_number;
4286 if (mask == M_BLTL_I)
4288 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4290 macro_build ((char *) NULL, &icnt, &offset_expr,
4291 likely ? "bltzl" : "bltz", "s,p", sreg);
4294 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4296 macro_build ((char *) NULL, &icnt, &offset_expr,
4297 likely ? "blezl" : "blez", "s,p", sreg);
4300 set_at (&icnt, sreg, 0);
4301 macro_build ((char *) NULL, &icnt, &offset_expr,
4302 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4310 macro_build ((char *) NULL, &icnt, &offset_expr,
4311 likely ? "beql" : "beq", "s,t,p", sreg, 0);
4316 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4317 "d,v,t", AT, treg, sreg);
4318 macro_build ((char *) NULL, &icnt, &offset_expr,
4319 likely ? "beql" : "beq", "s,t,p", AT, 0);
4327 && imm_expr.X_op == O_constant
4328 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4330 if (imm_expr.X_op != O_constant)
4331 as_bad (_("Unsupported large constant"));
4332 ++imm_expr.X_add_number;
4336 if (mask == M_BLTUL_I)
4338 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4340 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4342 macro_build ((char *) NULL, &icnt, &offset_expr,
4343 likely ? "beql" : "beq",
4347 set_at (&icnt, sreg, 1);
4348 macro_build ((char *) NULL, &icnt, &offset_expr,
4349 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4357 macro_build ((char *) NULL, &icnt, &offset_expr,
4358 likely ? "bltzl" : "bltz", "s,p", sreg);
4363 macro_build ((char *) NULL, &icnt, &offset_expr,
4364 likely ? "bgtzl" : "bgtz", "s,p", treg);
4367 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4369 macro_build ((char *) NULL, &icnt, &offset_expr,
4370 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4380 macro_build ((char *) NULL, &icnt, &offset_expr,
4381 likely ? "bnel" : "bne", "s,t,p", 0, treg);
4384 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4387 macro_build ((char *) NULL, &icnt, &offset_expr,
4388 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4403 as_warn (_("Divide by zero."));
4405 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4408 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4413 mips_emit_delays (true);
4414 ++mips_opts.noreorder;
4415 mips_any_noreorder = 1;
4418 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4420 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4421 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4425 expr1.X_add_number = 8;
4426 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4427 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4428 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4429 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4432 expr1.X_add_number = -1;
4433 macro_build ((char *) NULL, &icnt, &expr1,
4434 dbl ? "daddiu" : "addiu",
4435 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
4436 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4437 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4440 expr1.X_add_number = 1;
4441 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4442 (int) BFD_RELOC_LO16);
4443 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32",
4444 "d,w,<", AT, AT, 31);
4448 expr1.X_add_number = 0x80000000;
4449 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4450 (int) BFD_RELOC_HI16);
4454 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4456 /* We want to close the noreorder block as soon as possible, so
4457 that later insns are available for delay slot filling. */
4458 --mips_opts.noreorder;
4462 expr1.X_add_number = 8;
4463 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4464 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4467 /* We want to close the noreorder block as soon as possible, so
4468 that later insns are available for delay slot filling. */
4469 --mips_opts.noreorder;
4471 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4474 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg);
4513 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4515 as_warn (_("Divide by zero."));
4517 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4520 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4524 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4526 if (strcmp (s2, "mflo") == 0)
4527 move_register (&icnt, dreg, sreg);
4529 move_register (&icnt, dreg, 0);
4532 if (imm_expr.X_op == O_constant
4533 && imm_expr.X_add_number == -1
4534 && s[strlen (s) - 1] != 'u')
4536 if (strcmp (s2, "mflo") == 0)
4538 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4539 dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4542 move_register (&icnt, dreg, 0);
4546 load_register (&icnt, AT, &imm_expr, dbl);
4547 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4549 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4568 mips_emit_delays (true);
4569 ++mips_opts.noreorder;
4570 mips_any_noreorder = 1;
4573 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4575 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4577 /* We want to close the noreorder block as soon as possible, so
4578 that later insns are available for delay slot filling. */
4579 --mips_opts.noreorder;
4583 expr1.X_add_number = 8;
4584 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4585 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4588 /* We want to close the noreorder block as soon as possible, so
4589 that later insns are available for delay slot filling. */
4590 --mips_opts.noreorder;
4591 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4594 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4600 /* Load the address of a symbol into a register. If breg is not
4601 zero, we then add a base register to it. */
4603 if (dbl && HAVE_32BIT_GPRS)
4604 as_warn (_("dla used to load 32-bit register"));
4606 if (! dbl && HAVE_64BIT_OBJECTS)
4607 as_warn (_("la used to load 64-bit address"));
4620 /* When generating embedded PIC code, we permit expressions of
4623 la $treg,foo-bar($breg)
4624 where bar is an address in the current section. These are used
4625 when getting the addresses of functions. We don't permit
4626 X_add_number to be non-zero, because if the symbol is
4627 external the relaxing code needs to know that any addend is
4628 purely the offset to X_op_symbol. */
4629 if (mips_pic == EMBEDDED_PIC
4630 && offset_expr.X_op == O_subtract
4631 && (symbol_constant_p (offset_expr.X_op_symbol)
4632 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4633 : (symbol_equated_p (offset_expr.X_op_symbol)
4635 (symbol_get_value_expression (offset_expr.X_op_symbol)
4638 && (offset_expr.X_add_number == 0
4639 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4645 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4646 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4650 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4651 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4652 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4653 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4654 "d,v,t", tempreg, tempreg, breg);
4656 macro_build ((char *) NULL, &icnt, &offset_expr,
4657 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4658 "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16);
4664 if (offset_expr.X_op != O_symbol
4665 && offset_expr.X_op != O_constant)
4667 as_bad (_("expression too complex"));
4668 offset_expr.X_op = O_constant;
4671 if (offset_expr.X_op == O_constant)
4672 load_register (&icnt, tempreg, &offset_expr,
4673 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4674 ? (dbl || HAVE_64BIT_ADDRESSES)
4675 : HAVE_64BIT_ADDRESSES));
4676 else if (mips_pic == NO_PIC)
4678 /* If this is a reference to a GP relative symbol, we want
4679 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4681 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4682 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4683 If we have a constant, we need two instructions anyhow,
4684 so we may as well always use the latter form.
4686 With 64bit address space and a usable $at we want
4687 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4688 lui $at,<sym> (BFD_RELOC_HI16_S)
4689 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4690 daddiu $at,<sym> (BFD_RELOC_LO16)
4692 dadd $tempreg,$tempreg,$at
4694 If $at is already in use, we use an path which is suboptimal
4695 on superscalar processors.
4696 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4697 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4699 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4701 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4704 if (HAVE_64BIT_ADDRESSES)
4706 /* We don't do GP optimization for now because RELAX_ENCODE can't
4707 hold the data for such large chunks. */
4711 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4712 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4713 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4714 AT, (int) BFD_RELOC_HI16_S);
4715 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4716 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4717 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4718 AT, AT, (int) BFD_RELOC_LO16);
4719 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
4720 "d,w,<", tempreg, tempreg, 0);
4721 macro_build (p, &icnt, (expressionS *) NULL, "dadd", "d,v,t",
4722 tempreg, tempreg, AT);
4727 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4728 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4729 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4730 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4731 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4732 tempreg, tempreg, 16);
4733 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4734 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
4735 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4736 tempreg, tempreg, 16);
4737 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4738 tempreg, tempreg, (int) BFD_RELOC_LO16);
4743 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4744 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4747 macro_build ((char *) NULL, &icnt, &offset_expr, "addiu",
4748 "t,r,j", tempreg, mips_gp_register,
4749 (int) BFD_RELOC_GPREL16);
4750 p = frag_var (rs_machine_dependent, 8, 0,
4751 RELAX_ENCODE (4, 8, 0, 4, 0,
4752 mips_opts.warn_about_macros),
4753 offset_expr.X_add_symbol, 0, NULL);
4755 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4758 macro_build (p, &icnt, &offset_expr, "addiu",
4759 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4762 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4764 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4766 /* If this is a reference to an external symbol, and there
4767 is no constant, we want
4768 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4769 or if tempreg is PIC_CALL_REG
4770 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4771 For a local symbol, we want
4772 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4774 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4776 If we have a small constant, and this is a reference to
4777 an external symbol, we want
4778 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4780 addiu $tempreg,$tempreg,<constant>
4781 For a local symbol, we want the same instruction
4782 sequence, but we output a BFD_RELOC_LO16 reloc on the
4785 If we have a large constant, and this is a reference to
4786 an external symbol, we want
4787 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4788 lui $at,<hiconstant>
4789 addiu $at,$at,<loconstant>
4790 addu $tempreg,$tempreg,$at
4791 For a local symbol, we want the same instruction
4792 sequence, but we output a BFD_RELOC_LO16 reloc on the
4793 addiu instruction. */
4794 expr1.X_add_number = offset_expr.X_add_number;
4795 offset_expr.X_add_number = 0;
4797 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4798 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4799 macro_build ((char *) NULL, &icnt, &offset_expr,
4800 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4801 "t,o(b)", tempreg, lw_reloc_type, mips_gp_register);
4802 if (expr1.X_add_number == 0)
4811 /* We're going to put in an addu instruction using
4812 tempreg, so we may as well insert the nop right
4814 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4818 p = frag_var (rs_machine_dependent, 8 - off, 0,
4819 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4821 ? mips_opts.warn_about_macros
4823 offset_expr.X_add_symbol, 0, NULL);
4826 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4829 macro_build (p, &icnt, &expr1,
4830 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4831 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4832 /* FIXME: If breg == 0, and the next instruction uses
4833 $tempreg, then if this variant case is used an extra
4834 nop will be generated. */
4836 else if (expr1.X_add_number >= -0x8000
4837 && expr1.X_add_number < 0x8000)
4839 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4841 macro_build ((char *) NULL, &icnt, &expr1,
4842 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4843 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4844 frag_var (rs_machine_dependent, 0, 0,
4845 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4846 offset_expr.X_add_symbol, 0, NULL);
4852 /* If we are going to add in a base register, and the
4853 target register and the base register are the same,
4854 then we are using AT as a temporary register. Since
4855 we want to load the constant into AT, we add our
4856 current AT (from the global offset table) and the
4857 register into the register now, and pretend we were
4858 not using a base register. */
4863 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4865 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4866 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4867 "d,v,t", treg, AT, breg);
4873 /* Set mips_optimize around the lui instruction to avoid
4874 inserting an unnecessary nop after the lw. */
4875 hold_mips_optimize = mips_optimize;
4877 macro_build_lui (NULL, &icnt, &expr1, AT);
4878 mips_optimize = hold_mips_optimize;
4880 macro_build ((char *) NULL, &icnt, &expr1,
4881 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4882 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4883 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4884 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4885 "d,v,t", tempreg, tempreg, AT);
4886 frag_var (rs_machine_dependent, 0, 0,
4887 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4888 offset_expr.X_add_symbol, 0, NULL);
4892 else if (mips_pic == SVR4_PIC)
4896 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
4897 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
4899 /* This is the large GOT case. If this is a reference to an
4900 external symbol, and there is no constant, we want
4901 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4902 addu $tempreg,$tempreg,$gp
4903 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4904 or if tempreg is PIC_CALL_REG
4905 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4906 addu $tempreg,$tempreg,$gp
4907 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4908 For a local symbol, we want
4909 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4911 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4913 If we have a small constant, and this is a reference to
4914 an external symbol, we want
4915 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4916 addu $tempreg,$tempreg,$gp
4917 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4919 addiu $tempreg,$tempreg,<constant>
4920 For a local symbol, we want
4921 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4923 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4925 If we have a large constant, and this is a reference to
4926 an external symbol, we want
4927 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4928 addu $tempreg,$tempreg,$gp
4929 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4930 lui $at,<hiconstant>
4931 addiu $at,$at,<loconstant>
4932 addu $tempreg,$tempreg,$at
4933 For a local symbol, we want
4934 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4935 lui $at,<hiconstant>
4936 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4937 addu $tempreg,$tempreg,$at
4939 expr1.X_add_number = offset_expr.X_add_number;
4940 offset_expr.X_add_number = 0;
4942 if (reg_needs_delay (GP))
4946 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4948 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
4949 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
4951 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4952 tempreg, lui_reloc_type);
4953 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4954 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4955 "d,v,t", tempreg, tempreg, mips_gp_register);
4956 macro_build ((char *) NULL, &icnt, &offset_expr,
4957 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4958 "t,o(b)", tempreg, lw_reloc_type, tempreg);
4959 if (expr1.X_add_number == 0)
4967 /* We're going to put in an addu instruction using
4968 tempreg, so we may as well insert the nop right
4970 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4975 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4976 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4979 ? mips_opts.warn_about_macros
4981 offset_expr.X_add_symbol, 0, NULL);
4983 else if (expr1.X_add_number >= -0x8000
4984 && expr1.X_add_number < 0x8000)
4986 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4988 macro_build ((char *) NULL, &icnt, &expr1,
4989 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4990 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4992 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4993 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4995 ? mips_opts.warn_about_macros
4997 offset_expr.X_add_symbol, 0, NULL);
5003 /* If we are going to add in a base register, and the
5004 target register and the base register are the same,
5005 then we are using AT as a temporary register. Since
5006 we want to load the constant into AT, we add our
5007 current AT (from the global offset table) and the
5008 register into the register now, and pretend we were
5009 not using a base register. */
5017 assert (tempreg == AT);
5018 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5020 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5021 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5022 "d,v,t", treg, AT, breg);
5027 /* Set mips_optimize around the lui instruction to avoid
5028 inserting an unnecessary nop after the lw. */
5029 hold_mips_optimize = mips_optimize;
5031 macro_build_lui (NULL, &icnt, &expr1, AT);
5032 mips_optimize = hold_mips_optimize;
5034 macro_build ((char *) NULL, &icnt, &expr1,
5035 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5036 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5037 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5038 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5039 "d,v,t", dreg, dreg, AT);
5041 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
5042 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
5045 ? mips_opts.warn_about_macros
5047 offset_expr.X_add_symbol, 0, NULL);
5054 /* This is needed because this instruction uses $gp, but
5055 the first instruction on the main stream does not. */
5056 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5059 macro_build (p, &icnt, &offset_expr,
5060 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5061 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
5064 if (expr1.X_add_number >= -0x8000
5065 && expr1.X_add_number < 0x8000)
5067 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5069 macro_build (p, &icnt, &expr1,
5070 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5071 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5072 /* FIXME: If add_number is 0, and there was no base
5073 register, the external symbol case ended with a load,
5074 so if the symbol turns out to not be external, and
5075 the next instruction uses tempreg, an unnecessary nop
5076 will be inserted. */
5082 /* We must add in the base register now, as in the
5083 external symbol case. */
5084 assert (tempreg == AT);
5085 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5087 macro_build (p, &icnt, (expressionS *) NULL,
5088 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5089 "d,v,t", treg, AT, breg);
5092 /* We set breg to 0 because we have arranged to add
5093 it in in both cases. */
5097 macro_build_lui (p, &icnt, &expr1, AT);
5099 macro_build (p, &icnt, &expr1,
5100 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5101 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5103 macro_build (p, &icnt, (expressionS *) NULL,
5104 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5105 "d,v,t", tempreg, tempreg, AT);
5109 else if (mips_pic == EMBEDDED_PIC)
5112 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5114 macro_build ((char *) NULL, &icnt, &offset_expr,
5115 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
5116 tempreg, mips_gp_register, (int) BFD_RELOC_GPREL16);
5125 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
5126 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu";
5128 s = HAVE_64BIT_ADDRESSES ? "daddu" : "addu";
5130 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
5131 "d,v,t", treg, tempreg, breg);
5140 /* The j instruction may not be used in PIC code, since it
5141 requires an absolute address. We convert it to a b
5143 if (mips_pic == NO_PIC)
5144 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
5146 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
5149 /* The jal instructions must be handled as macros because when
5150 generating PIC code they expand to multi-instruction
5151 sequences. Normally they are simple instructions. */
5156 if (mips_pic == NO_PIC
5157 || mips_pic == EMBEDDED_PIC)
5158 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5160 else if (mips_pic == SVR4_PIC)
5162 if (sreg != PIC_CALL_REG)
5163 as_warn (_("MIPS PIC call to register other than $25"));
5165 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5169 if (mips_cprestore_offset < 0)
5170 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5173 if (! mips_frame_reg_valid)
5175 as_warn (_("No .frame pseudo-op used in PIC code"));
5176 /* Quiet this warning. */
5177 mips_frame_reg_valid = 1;
5179 if (! mips_cprestore_valid)
5181 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5182 /* Quiet this warning. */
5183 mips_cprestore_valid = 1;
5185 expr1.X_add_number = mips_cprestore_offset;
5186 macro_build ((char *) NULL, &icnt, &expr1,
5187 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5188 mips_gp_register, (int) BFD_RELOC_LO16,
5199 if (mips_pic == NO_PIC)
5200 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
5201 else if (mips_pic == SVR4_PIC)
5205 /* If this is a reference to an external symbol, and we are
5206 using a small GOT, we want
5207 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5211 lw $gp,cprestore($sp)
5212 The cprestore value is set using the .cprestore
5213 pseudo-op. If we are using a big GOT, we want
5214 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5216 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5220 lw $gp,cprestore($sp)
5221 If the symbol is not external, we want
5222 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5224 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5227 lw $gp,cprestore($sp) */
5231 macro_build ((char *) NULL, &icnt, &offset_expr,
5232 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5233 "t,o(b)", PIC_CALL_REG,
5234 (int) BFD_RELOC_MIPS_CALL16, GP);
5235 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5237 p = frag_var (rs_machine_dependent, 4, 0,
5238 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5239 offset_expr.X_add_symbol, 0, NULL);
5245 if (reg_needs_delay (GP))
5249 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5250 PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16);
5251 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5252 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5253 "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP);
5254 macro_build ((char *) NULL, &icnt, &offset_expr,
5255 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5256 "t,o(b)", PIC_CALL_REG,
5257 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5258 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5260 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5261 RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel,
5263 offset_expr.X_add_symbol, 0, NULL);
5266 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5269 macro_build (p, &icnt, &offset_expr,
5270 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5271 "t,o(b)", PIC_CALL_REG,
5272 (int) BFD_RELOC_MIPS_GOT16, GP);
5274 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5277 macro_build (p, &icnt, &offset_expr,
5278 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5279 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5280 (int) BFD_RELOC_LO16);
5281 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5282 "jalr", "s", PIC_CALL_REG);
5285 if (mips_cprestore_offset < 0)
5286 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5289 if (! mips_frame_reg_valid)
5291 as_warn (_("No .frame pseudo-op used in PIC code"));
5292 /* Quiet this warning. */
5293 mips_frame_reg_valid = 1;
5295 if (! mips_cprestore_valid)
5297 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5298 /* Quiet this warning. */
5299 mips_cprestore_valid = 1;
5301 if (mips_opts.noreorder)
5302 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5304 expr1.X_add_number = mips_cprestore_offset;
5305 macro_build ((char *) NULL, &icnt, &expr1,
5306 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5307 mips_gp_register, (int) BFD_RELOC_LO16,
5312 else if (mips_pic == EMBEDDED_PIC)
5314 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
5315 /* The linker may expand the call to a longer sequence which
5316 uses $at, so we must break rather than return. */
5341 /* Itbl support may require additional care here. */
5346 /* Itbl support may require additional care here. */
5351 /* Itbl support may require additional care here. */
5356 /* Itbl support may require additional care here. */
5368 if (mips_arch == CPU_R4650)
5370 as_bad (_("opcode not supported on this processor"));
5374 /* Itbl support may require additional care here. */
5379 /* Itbl support may require additional care here. */
5384 /* Itbl support may require additional care here. */
5404 if (breg == treg || coproc || lr)
5426 /* Itbl support may require additional care here. */
5431 /* Itbl support may require additional care here. */
5436 /* Itbl support may require additional care here. */
5441 /* Itbl support may require additional care here. */
5457 if (mips_arch == CPU_R4650)
5459 as_bad (_("opcode not supported on this processor"));
5464 /* Itbl support may require additional care here. */
5468 /* Itbl support may require additional care here. */
5473 /* Itbl support may require additional care here. */
5485 /* Itbl support may require additional care here. */
5486 if (mask == M_LWC1_AB
5487 || mask == M_SWC1_AB
5488 || mask == M_LDC1_AB
5489 || mask == M_SDC1_AB
5498 /* For embedded PIC, we allow loads where the offset is calculated
5499 by subtracting a symbol in the current segment from an unknown
5500 symbol, relative to a base register, e.g.:
5501 <op> $treg, <sym>-<localsym>($breg)
5502 This is used by the compiler for switch statements. */
5503 if (mips_pic == EMBEDDED_PIC
5504 && offset_expr.X_op == O_subtract
5505 && (symbol_constant_p (offset_expr.X_op_symbol)
5506 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5507 : (symbol_equated_p (offset_expr.X_op_symbol)
5509 (symbol_get_value_expression (offset_expr.X_op_symbol)
5513 && (offset_expr.X_add_number == 0
5514 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5516 /* For this case, we output the instructions:
5517 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5518 addiu $tempreg,$tempreg,$breg
5519 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5520 If the relocation would fit entirely in 16 bits, it would be
5522 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5523 instead, but that seems quite difficult. */
5524 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5525 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
5526 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5527 ((bfd_arch_bits_per_address (stdoutput) == 32
5528 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5529 ? "addu" : "daddu"),
5530 "d,v,t", tempreg, tempreg, breg);
5531 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
5532 (int) BFD_RELOC_PCREL_LO16, tempreg);
5538 if (offset_expr.X_op != O_constant
5539 && offset_expr.X_op != O_symbol)
5541 as_bad (_("expression too complex"));
5542 offset_expr.X_op = O_constant;
5545 /* A constant expression in PIC code can be handled just as it
5546 is in non PIC code. */
5547 if (mips_pic == NO_PIC
5548 || offset_expr.X_op == O_constant)
5552 /* If this is a reference to a GP relative symbol, and there
5553 is no base register, we want
5554 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5555 Otherwise, if there is no base register, we want
5556 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5557 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5558 If we have a constant, we need two instructions anyhow,
5559 so we always use the latter form.
5561 If we have a base register, and this is a reference to a
5562 GP relative symbol, we want
5563 addu $tempreg,$breg,$gp
5564 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5566 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5567 addu $tempreg,$tempreg,$breg
5568 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5569 With a constant we always use the latter case.
5571 With 64bit address space and no base register and $at usable,
5573 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5574 lui $at,<sym> (BFD_RELOC_HI16_S)
5575 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5578 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5579 If we have a base register, we want
5580 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5581 lui $at,<sym> (BFD_RELOC_HI16_S)
5582 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5586 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5588 Without $at we can't generate the optimal path for superscalar
5589 processors here since this would require two temporary registers.
5590 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5591 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5593 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5595 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5596 If we have a base register, we want
5597 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5598 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5600 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5602 daddu $tempreg,$tempreg,$breg
5603 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5605 If we have 64-bit addresses, as an optimization, for
5606 addresses which are 32-bit constants (e.g. kseg0/kseg1
5607 addresses) we fall back to the 32-bit address generation
5608 mechanism since it is more efficient. This code should
5609 probably attempt to generate 64-bit constants more
5610 efficiently in general.
5612 if (HAVE_64BIT_ADDRESSES
5613 && !(offset_expr.X_op == O_constant
5614 && IS_SEXT_32BIT_NUM (offset_expr.X_add_number)))
5618 /* We don't do GP optimization for now because RELAX_ENCODE can't
5619 hold the data for such large chunks. */
5623 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5624 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5625 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5626 AT, (int) BFD_RELOC_HI16_S);
5627 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5628 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5630 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5631 "d,v,t", AT, AT, breg);
5632 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
5633 "d,w,<", tempreg, tempreg, 0);
5634 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5635 "d,v,t", tempreg, tempreg, AT);
5636 macro_build (p, &icnt, &offset_expr, s,
5637 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5642 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5643 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5644 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5645 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5646 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5647 "d,w,<", tempreg, tempreg, 16);
5648 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5649 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
5650 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5651 "d,w,<", tempreg, tempreg, 16);
5653 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5654 "d,v,t", tempreg, tempreg, breg);
5655 macro_build (p, &icnt, &offset_expr, s,
5656 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5664 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5665 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5670 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5671 treg, (int) BFD_RELOC_GPREL16,
5673 p = frag_var (rs_machine_dependent, 8, 0,
5674 RELAX_ENCODE (4, 8, 0, 4, 0,
5675 (mips_opts.warn_about_macros
5677 && mips_opts.noat))),
5678 offset_expr.X_add_symbol, 0, NULL);
5681 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5684 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5685 (int) BFD_RELOC_LO16, tempreg);
5689 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5690 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5695 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5696 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5697 "d,v,t", tempreg, breg, mips_gp_register);
5698 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5699 treg, (int) BFD_RELOC_GPREL16, tempreg);
5700 p = frag_var (rs_machine_dependent, 12, 0,
5701 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5702 offset_expr.X_add_symbol, 0, NULL);
5704 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5707 macro_build (p, &icnt, (expressionS *) NULL,
5708 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5709 "d,v,t", tempreg, tempreg, breg);
5712 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5713 (int) BFD_RELOC_LO16, tempreg);
5716 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5720 /* If this is a reference to an external symbol, we want
5721 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5723 <op> $treg,0($tempreg)
5725 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5727 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5728 <op> $treg,0($tempreg)
5729 If there is a base register, we add it to $tempreg before
5730 the <op>. If there is a constant, we stick it in the
5731 <op> instruction. We don't handle constants larger than
5732 16 bits, because we have no way to load the upper 16 bits
5733 (actually, we could handle them for the subset of cases
5734 in which we are not using $at). */
5735 assert (offset_expr.X_op == O_symbol);
5736 expr1.X_add_number = offset_expr.X_add_number;
5737 offset_expr.X_add_number = 0;
5738 if (expr1.X_add_number < -0x8000
5739 || expr1.X_add_number >= 0x8000)
5740 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5742 macro_build ((char *) NULL, &icnt, &offset_expr,
5743 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", tempreg,
5744 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
5745 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5746 p = frag_var (rs_machine_dependent, 4, 0,
5747 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5748 offset_expr.X_add_symbol, 0, NULL);
5749 macro_build (p, &icnt, &offset_expr,
5750 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5751 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5753 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5754 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5755 "d,v,t", tempreg, tempreg, breg);
5756 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5757 (int) BFD_RELOC_LO16, tempreg);
5759 else if (mips_pic == SVR4_PIC)
5764 /* If this is a reference to an external symbol, we want
5765 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5766 addu $tempreg,$tempreg,$gp
5767 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5768 <op> $treg,0($tempreg)
5770 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5772 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5773 <op> $treg,0($tempreg)
5774 If there is a base register, we add it to $tempreg before
5775 the <op>. If there is a constant, we stick it in the
5776 <op> instruction. We don't handle constants larger than
5777 16 bits, because we have no way to load the upper 16 bits
5778 (actually, we could handle them for the subset of cases
5779 in which we are not using $at). */
5780 assert (offset_expr.X_op == O_symbol);
5781 expr1.X_add_number = offset_expr.X_add_number;
5782 offset_expr.X_add_number = 0;
5783 if (expr1.X_add_number < -0x8000
5784 || expr1.X_add_number >= 0x8000)
5785 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5786 if (reg_needs_delay (GP))
5791 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5792 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5793 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5794 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5795 "d,v,t", tempreg, tempreg, mips_gp_register);
5796 macro_build ((char *) NULL, &icnt, &offset_expr,
5797 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5798 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5800 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5801 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5802 offset_expr.X_add_symbol, 0, NULL);
5805 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5808 macro_build (p, &icnt, &offset_expr,
5809 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5810 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
5813 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5815 macro_build (p, &icnt, &offset_expr,
5816 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5817 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5819 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5820 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5821 "d,v,t", tempreg, tempreg, breg);
5822 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5823 (int) BFD_RELOC_LO16, tempreg);
5825 else if (mips_pic == EMBEDDED_PIC)
5827 /* If there is no base register, we want
5828 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5829 If there is a base register, we want
5830 addu $tempreg,$breg,$gp
5831 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5833 assert (offset_expr.X_op == O_symbol);
5836 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5837 treg, (int) BFD_RELOC_GPREL16, mips_gp_register);
5842 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5843 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5844 "d,v,t", tempreg, breg, mips_gp_register);
5845 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5846 treg, (int) BFD_RELOC_GPREL16, tempreg);
5859 load_register (&icnt, treg, &imm_expr, 0);
5863 load_register (&icnt, treg, &imm_expr, 1);
5867 if (imm_expr.X_op == O_constant)
5869 load_register (&icnt, AT, &imm_expr, 0);
5870 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5871 "mtc1", "t,G", AT, treg);
5876 assert (offset_expr.X_op == O_symbol
5877 && strcmp (segment_name (S_GET_SEGMENT
5878 (offset_expr.X_add_symbol)),
5880 && offset_expr.X_add_number == 0);
5881 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5882 treg, (int) BFD_RELOC_MIPS_LITERAL, mips_gp_register);
5887 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
5888 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
5889 order 32 bits of the value and the low order 32 bits are either
5890 zero or in OFFSET_EXPR. */
5891 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5893 if (HAVE_64BIT_GPRS)
5894 load_register (&icnt, treg, &imm_expr, 1);
5899 if (target_big_endian)
5911 load_register (&icnt, hreg, &imm_expr, 0);
5914 if (offset_expr.X_op == O_absent)
5915 move_register (&icnt, lreg, 0);
5918 assert (offset_expr.X_op == O_constant);
5919 load_register (&icnt, lreg, &offset_expr, 0);
5926 /* We know that sym is in the .rdata section. First we get the
5927 upper 16 bits of the address. */
5928 if (mips_pic == NO_PIC)
5930 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5932 else if (mips_pic == SVR4_PIC)
5934 macro_build ((char *) NULL, &icnt, &offset_expr,
5935 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5936 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
5939 else if (mips_pic == EMBEDDED_PIC)
5941 /* For embedded PIC we pick up the entire address off $gp in
5942 a single instruction. */
5943 macro_build ((char *) NULL, &icnt, &offset_expr,
5944 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j", AT,
5945 mips_gp_register, (int) BFD_RELOC_GPREL16);
5946 offset_expr.X_op = O_constant;
5947 offset_expr.X_add_number = 0;
5952 /* Now we load the register(s). */
5953 if (HAVE_64BIT_GPRS)
5954 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5955 treg, (int) BFD_RELOC_LO16, AT);
5958 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5959 treg, (int) BFD_RELOC_LO16, AT);
5962 /* FIXME: How in the world do we deal with the possible
5964 offset_expr.X_add_number += 4;
5965 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5966 treg + 1, (int) BFD_RELOC_LO16, AT);
5970 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5971 does not become a variant frag. */
5972 frag_wane (frag_now);
5978 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
5979 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
5980 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
5981 the value and the low order 32 bits are either zero or in
5983 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5985 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
5986 if (HAVE_64BIT_FPRS)
5988 assert (HAVE_64BIT_GPRS);
5989 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5990 "dmtc1", "t,S", AT, treg);
5994 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5995 "mtc1", "t,G", AT, treg + 1);
5996 if (offset_expr.X_op == O_absent)
5997 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5998 "mtc1", "t,G", 0, treg);
6001 assert (offset_expr.X_op == O_constant);
6002 load_register (&icnt, AT, &offset_expr, 0);
6003 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6004 "mtc1", "t,G", AT, treg);
6010 assert (offset_expr.X_op == O_symbol
6011 && offset_expr.X_add_number == 0);
6012 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
6013 if (strcmp (s, ".lit8") == 0)
6015 if (mips_opts.isa != ISA_MIPS1)
6017 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
6018 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL,
6022 breg = mips_gp_register;
6023 r = BFD_RELOC_MIPS_LITERAL;
6028 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
6029 if (mips_pic == SVR4_PIC)
6030 macro_build ((char *) NULL, &icnt, &offset_expr,
6031 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6032 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
6036 /* FIXME: This won't work for a 64 bit address. */
6037 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6040 if (mips_opts.isa != ISA_MIPS1)
6042 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
6043 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
6045 /* To avoid confusion in tc_gen_reloc, we must ensure
6046 that this does not become a variant frag. */
6047 frag_wane (frag_now);
6058 if (mips_arch == CPU_R4650)
6060 as_bad (_("opcode not supported on this processor"));
6063 /* Even on a big endian machine $fn comes before $fn+1. We have
6064 to adjust when loading from memory. */
6067 assert (mips_opts.isa == ISA_MIPS1);
6068 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6069 target_big_endian ? treg + 1 : treg,
6071 /* FIXME: A possible overflow which I don't know how to deal
6073 offset_expr.X_add_number += 4;
6074 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6075 target_big_endian ? treg : treg + 1,
6078 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6079 does not become a variant frag. */
6080 frag_wane (frag_now);
6089 * The MIPS assembler seems to check for X_add_number not
6090 * being double aligned and generating:
6093 * addiu at,at,%lo(foo+1)
6096 * But, the resulting address is the same after relocation so why
6097 * generate the extra instruction?
6099 if (mips_arch == CPU_R4650)
6101 as_bad (_("opcode not supported on this processor"));
6104 /* Itbl support may require additional care here. */
6106 if (mips_opts.isa != ISA_MIPS1)
6117 if (mips_arch == CPU_R4650)
6119 as_bad (_("opcode not supported on this processor"));
6123 if (mips_opts.isa != ISA_MIPS1)
6131 /* Itbl support may require additional care here. */
6136 if (HAVE_64BIT_GPRS)
6147 if (HAVE_64BIT_GPRS)
6157 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6158 loads for the case of doing a pair of loads to simulate an 'ld'.
6159 This is not currently done by the compiler, and assembly coders
6160 writing embedded-pic code can cope. */
6162 if (offset_expr.X_op != O_symbol
6163 && offset_expr.X_op != O_constant)
6165 as_bad (_("expression too complex"));
6166 offset_expr.X_op = O_constant;
6169 /* Even on a big endian machine $fn comes before $fn+1. We have
6170 to adjust when loading from memory. We set coproc if we must
6171 load $fn+1 first. */
6172 /* Itbl support may require additional care here. */
6173 if (! target_big_endian)
6176 if (mips_pic == NO_PIC
6177 || offset_expr.X_op == O_constant)
6181 /* If this is a reference to a GP relative symbol, we want
6182 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6183 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6184 If we have a base register, we use this
6186 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6187 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6188 If this is not a GP relative symbol, we want
6189 lui $at,<sym> (BFD_RELOC_HI16_S)
6190 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6191 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6192 If there is a base register, we add it to $at after the
6193 lui instruction. If there is a constant, we always use
6195 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6196 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6208 tempreg = mips_gp_register;
6215 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6216 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6217 "d,v,t", AT, breg, mips_gp_register);
6223 /* Itbl support may require additional care here. */
6224 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6225 coproc ? treg + 1 : treg,
6226 (int) BFD_RELOC_GPREL16, tempreg);
6227 offset_expr.X_add_number += 4;
6229 /* Set mips_optimize to 2 to avoid inserting an
6231 hold_mips_optimize = mips_optimize;
6233 /* Itbl support may require additional care here. */
6234 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6235 coproc ? treg : treg + 1,
6236 (int) BFD_RELOC_GPREL16, tempreg);
6237 mips_optimize = hold_mips_optimize;
6239 p = frag_var (rs_machine_dependent, 12 + off, 0,
6240 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6241 used_at && mips_opts.noat),
6242 offset_expr.X_add_symbol, 0, NULL);
6244 /* We just generated two relocs. When tc_gen_reloc
6245 handles this case, it will skip the first reloc and
6246 handle the second. The second reloc already has an
6247 extra addend of 4, which we added above. We must
6248 subtract it out, and then subtract another 4 to make
6249 the first reloc come out right. The second reloc
6250 will come out right because we are going to add 4 to
6251 offset_expr when we build its instruction below.
6253 If we have a symbol, then we don't want to include
6254 the offset, because it will wind up being included
6255 when we generate the reloc. */
6257 if (offset_expr.X_op == O_constant)
6258 offset_expr.X_add_number -= 8;
6261 offset_expr.X_add_number = -4;
6262 offset_expr.X_op = O_constant;
6265 macro_build_lui (p, &icnt, &offset_expr, AT);
6270 macro_build (p, &icnt, (expressionS *) NULL,
6271 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6272 "d,v,t", AT, breg, AT);
6276 /* Itbl support may require additional care here. */
6277 macro_build (p, &icnt, &offset_expr, s, fmt,
6278 coproc ? treg + 1 : treg,
6279 (int) BFD_RELOC_LO16, AT);
6282 /* FIXME: How do we handle overflow here? */
6283 offset_expr.X_add_number += 4;
6284 /* Itbl support may require additional care here. */
6285 macro_build (p, &icnt, &offset_expr, s, fmt,
6286 coproc ? treg : treg + 1,
6287 (int) BFD_RELOC_LO16, AT);
6289 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6293 /* If this is a reference to an external symbol, we want
6294 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6299 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6301 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6302 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6303 If there is a base register we add it to $at before the
6304 lwc1 instructions. If there is a constant we include it
6305 in the lwc1 instructions. */
6307 expr1.X_add_number = offset_expr.X_add_number;
6308 offset_expr.X_add_number = 0;
6309 if (expr1.X_add_number < -0x8000
6310 || expr1.X_add_number >= 0x8000 - 4)
6311 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6316 frag_grow (24 + off);
6317 macro_build ((char *) NULL, &icnt, &offset_expr,
6318 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", AT,
6319 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
6320 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6322 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6323 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6324 "d,v,t", AT, breg, AT);
6325 /* Itbl support may require additional care here. */
6326 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6327 coproc ? treg + 1 : treg,
6328 (int) BFD_RELOC_LO16, AT);
6329 expr1.X_add_number += 4;
6331 /* Set mips_optimize to 2 to avoid inserting an undesired
6333 hold_mips_optimize = mips_optimize;
6335 /* Itbl support may require additional care here. */
6336 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6337 coproc ? treg : treg + 1,
6338 (int) BFD_RELOC_LO16, AT);
6339 mips_optimize = hold_mips_optimize;
6341 (void) frag_var (rs_machine_dependent, 0, 0,
6342 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6343 offset_expr.X_add_symbol, 0, NULL);
6345 else if (mips_pic == SVR4_PIC)
6350 /* If this is a reference to an external symbol, we want
6351 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6353 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6358 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6360 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6361 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6362 If there is a base register we add it to $at before the
6363 lwc1 instructions. If there is a constant we include it
6364 in the lwc1 instructions. */
6366 expr1.X_add_number = offset_expr.X_add_number;
6367 offset_expr.X_add_number = 0;
6368 if (expr1.X_add_number < -0x8000
6369 || expr1.X_add_number >= 0x8000 - 4)
6370 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6371 if (reg_needs_delay (mips_gp_register))
6380 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6381 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
6382 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6383 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6384 "d,v,t", AT, AT, mips_gp_register);
6385 macro_build ((char *) NULL, &icnt, &offset_expr,
6386 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6387 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
6388 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6390 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6391 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6392 "d,v,t", AT, breg, AT);
6393 /* Itbl support may require additional care here. */
6394 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6395 coproc ? treg + 1 : treg,
6396 (int) BFD_RELOC_LO16, AT);
6397 expr1.X_add_number += 4;
6399 /* Set mips_optimize to 2 to avoid inserting an undesired
6401 hold_mips_optimize = mips_optimize;
6403 /* Itbl support may require additional care here. */
6404 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6405 coproc ? treg : treg + 1,
6406 (int) BFD_RELOC_LO16, AT);
6407 mips_optimize = hold_mips_optimize;
6408 expr1.X_add_number -= 4;
6410 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6411 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6412 8 + gpdel + off, 1, 0),
6413 offset_expr.X_add_symbol, 0, NULL);
6416 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6419 macro_build (p, &icnt, &offset_expr,
6420 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6421 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
6424 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6428 macro_build (p, &icnt, (expressionS *) NULL,
6429 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6430 "d,v,t", AT, breg, AT);
6433 /* Itbl support may require additional care here. */
6434 macro_build (p, &icnt, &expr1, s, fmt,
6435 coproc ? treg + 1 : treg,
6436 (int) BFD_RELOC_LO16, AT);
6438 expr1.X_add_number += 4;
6440 /* Set mips_optimize to 2 to avoid inserting an undesired
6442 hold_mips_optimize = mips_optimize;
6444 /* Itbl support may require additional care here. */
6445 macro_build (p, &icnt, &expr1, s, fmt,
6446 coproc ? treg : treg + 1,
6447 (int) BFD_RELOC_LO16, AT);
6448 mips_optimize = hold_mips_optimize;
6450 else if (mips_pic == EMBEDDED_PIC)
6452 /* If there is no base register, we use
6453 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6454 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6455 If we have a base register, we use
6457 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6458 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6462 tempreg = mips_gp_register;
6467 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6468 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6469 "d,v,t", AT, breg, mips_gp_register);
6474 /* Itbl support may require additional care here. */
6475 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6476 coproc ? treg + 1 : treg,
6477 (int) BFD_RELOC_GPREL16, tempreg);
6478 offset_expr.X_add_number += 4;
6479 /* Itbl support may require additional care here. */
6480 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6481 coproc ? treg : treg + 1,
6482 (int) BFD_RELOC_GPREL16, tempreg);
6498 assert (HAVE_32BIT_ADDRESSES);
6499 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6500 (int) BFD_RELOC_LO16, breg);
6501 offset_expr.X_add_number += 4;
6502 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
6503 (int) BFD_RELOC_LO16, breg);
6506 /* New code added to support COPZ instructions.
6507 This code builds table entries out of the macros in mip_opcodes.
6508 R4000 uses interlocks to handle coproc delays.
6509 Other chips (like the R3000) require nops to be inserted for delays.
6511 FIXME: Currently, we require that the user handle delays.
6512 In order to fill delay slots for non-interlocked chips,
6513 we must have a way to specify delays based on the coprocessor.
6514 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6515 What are the side-effects of the cop instruction?
6516 What cache support might we have and what are its effects?
6517 Both coprocessor & memory require delays. how long???
6518 What registers are read/set/modified?
6520 If an itbl is provided to interpret cop instructions,
6521 this knowledge can be encoded in the itbl spec. */
6535 /* For now we just do C (same as Cz). The parameter will be
6536 stored in insn_opcode by mips_ip. */
6537 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
6542 move_register (&icnt, dreg, sreg);
6545 #ifdef LOSING_COMPILER
6547 /* Try and see if this is a new itbl instruction.
6548 This code builds table entries out of the macros in mip_opcodes.
6549 FIXME: For now we just assemble the expression and pass it's
6550 value along as a 32-bit immediate.
6551 We may want to have the assembler assemble this value,
6552 so that we gain the assembler's knowledge of delay slots,
6554 Would it be more efficient to use mask (id) here? */
6555 if (itbl_have_entries
6556 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6558 s = ip->insn_mo->name;
6560 coproc = ITBL_DECODE_PNUM (immed_expr);;
6561 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
6568 as_warn (_("Macro used $at after \".set noat\""));
6573 struct mips_cl_insn *ip;
6575 register int treg, sreg, dreg, breg;
6591 bfd_reloc_code_real_type r;
6594 treg = (ip->insn_opcode >> 16) & 0x1f;
6595 dreg = (ip->insn_opcode >> 11) & 0x1f;
6596 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6597 mask = ip->insn_mo->mask;
6599 expr1.X_op = O_constant;
6600 expr1.X_op_symbol = NULL;
6601 expr1.X_add_symbol = NULL;
6602 expr1.X_add_number = 1;
6606 #endif /* LOSING_COMPILER */
6611 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6612 dbl ? "dmultu" : "multu", "s,t", sreg, treg);
6613 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6620 /* The MIPS assembler some times generates shifts and adds. I'm
6621 not trying to be that fancy. GCC should do this for us
6623 load_register (&icnt, AT, &imm_expr, dbl);
6624 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6625 dbl ? "dmult" : "mult", "s,t", sreg, AT);
6626 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6640 mips_emit_delays (true);
6641 ++mips_opts.noreorder;
6642 mips_any_noreorder = 1;
6644 load_register (&icnt, AT, &imm_expr, dbl);
6645 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6646 dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
6647 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6649 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6650 dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA);
6651 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6654 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6658 expr1.X_add_number = 8;
6659 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg,
6661 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6663 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6666 --mips_opts.noreorder;
6667 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg);
6680 mips_emit_delays (true);
6681 ++mips_opts.noreorder;
6682 mips_any_noreorder = 1;
6684 load_register (&icnt, AT, &imm_expr, dbl);
6685 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6686 dbl ? "dmultu" : "multu",
6687 "s,t", sreg, imm ? AT : treg);
6688 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6690 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6693 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6697 expr1.X_add_number = 8;
6698 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6699 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6701 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6704 --mips_opts.noreorder;
6708 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
6709 "d,v,t", AT, 0, treg);
6710 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
6711 "d,t,s", AT, sreg, AT);
6712 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
6713 "d,t,s", dreg, sreg, treg);
6714 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6715 "d,v,t", dreg, dreg, AT);
6719 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6720 "d,v,t", AT, 0, treg);
6721 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6722 "d,t,s", AT, sreg, AT);
6723 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6724 "d,t,s", dreg, sreg, treg);
6725 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6726 "d,v,t", dreg, dreg, AT);
6734 if (imm_expr.X_op != O_constant)
6735 as_bad (_("rotate count too large"));
6736 rot = imm_expr.X_add_number & 0x3f;
6739 l = (rot < 0x20) ? "dsll" : "dsll32";
6740 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
6742 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
6743 "d,w,<", AT, sreg, rot);
6744 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
6745 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6746 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6747 "d,v,t", dreg, dreg, AT);
6755 if (imm_expr.X_op != O_constant)
6756 as_bad (_("rotate count too large"));
6757 rot = imm_expr.X_add_number & 0x1f;
6760 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
6761 "d,w,<", AT, sreg, rot);
6762 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
6763 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6764 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6765 "d,v,t", dreg, dreg, AT);
6770 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
6771 "d,v,t", AT, 0, treg);
6772 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
6773 "d,t,s", AT, sreg, AT);
6774 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
6775 "d,t,s", dreg, sreg, treg);
6776 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6777 "d,v,t", dreg, dreg, AT);
6781 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6782 "d,v,t", AT, 0, treg);
6783 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6784 "d,t,s", AT, sreg, AT);
6785 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6786 "d,t,s", dreg, sreg, treg);
6787 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6788 "d,v,t", dreg, dreg, AT);
6796 if (imm_expr.X_op != O_constant)
6797 as_bad (_("rotate count too large"));
6798 rot = imm_expr.X_add_number & 0x3f;
6801 r = (rot < 0x20) ? "dsrl" : "dsrl32";
6802 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
6804 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
6805 "d,w,<", AT, sreg, rot);
6806 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
6807 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6808 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6809 "d,v,t", dreg, dreg, AT);
6817 if (imm_expr.X_op != O_constant)
6818 as_bad (_("rotate count too large"));
6819 rot = imm_expr.X_add_number & 0x1f;
6822 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
6823 "d,w,<", AT, sreg, rot);
6824 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
6825 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6826 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6827 "d,v,t", dreg, dreg, AT);
6832 if (mips_arch == CPU_R4650)
6834 as_bad (_("opcode not supported on this processor"));
6837 assert (mips_opts.isa == ISA_MIPS1);
6838 /* Even on a big endian machine $fn comes before $fn+1. We have
6839 to adjust when storing to memory. */
6840 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6841 target_big_endian ? treg + 1 : treg,
6842 (int) BFD_RELOC_LO16, breg);
6843 offset_expr.X_add_number += 4;
6844 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6845 target_big_endian ? treg : treg + 1,
6846 (int) BFD_RELOC_LO16, breg);
6851 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6852 treg, (int) BFD_RELOC_LO16);
6854 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6855 sreg, (int) BFD_RELOC_LO16);
6858 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6859 "d,v,t", dreg, sreg, treg);
6860 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6861 dreg, (int) BFD_RELOC_LO16);
6866 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6868 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6869 sreg, (int) BFD_RELOC_LO16);
6874 as_warn (_("Instruction %s: result is always false"),
6876 move_register (&icnt, dreg, 0);
6879 if (imm_expr.X_op == O_constant
6880 && imm_expr.X_add_number >= 0
6881 && imm_expr.X_add_number < 0x10000)
6883 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6884 sreg, (int) BFD_RELOC_LO16);
6887 else if (imm_expr.X_op == O_constant
6888 && imm_expr.X_add_number > -0x8000
6889 && imm_expr.X_add_number < 0)
6891 imm_expr.X_add_number = -imm_expr.X_add_number;
6892 macro_build ((char *) NULL, &icnt, &imm_expr,
6893 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6894 "t,r,j", dreg, sreg,
6895 (int) BFD_RELOC_LO16);
6900 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6901 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6902 "d,v,t", dreg, sreg, AT);
6905 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6906 (int) BFD_RELOC_LO16);
6911 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6917 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6919 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6920 (int) BFD_RELOC_LO16);
6923 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6925 if (imm_expr.X_op == O_constant
6926 && imm_expr.X_add_number >= -0x8000
6927 && imm_expr.X_add_number < 0x8000)
6929 macro_build ((char *) NULL, &icnt, &imm_expr,
6930 mask == M_SGE_I ? "slti" : "sltiu",
6931 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6936 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6937 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6938 mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg,
6942 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6943 (int) BFD_RELOC_LO16);
6948 case M_SGT: /* sreg > treg <==> treg < sreg */
6954 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6958 case M_SGT_I: /* sreg > I <==> I < sreg */
6964 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6965 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6969 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6975 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6977 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6978 (int) BFD_RELOC_LO16);
6981 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6987 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6988 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6990 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6991 (int) BFD_RELOC_LO16);
6995 if (imm_expr.X_op == O_constant
6996 && imm_expr.X_add_number >= -0x8000
6997 && imm_expr.X_add_number < 0x8000)
6999 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
7000 dreg, sreg, (int) BFD_RELOC_LO16);
7003 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7004 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
7009 if (imm_expr.X_op == O_constant
7010 && imm_expr.X_add_number >= -0x8000
7011 && imm_expr.X_add_number < 0x8000)
7013 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
7014 dreg, sreg, (int) BFD_RELOC_LO16);
7017 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7018 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7019 "d,v,t", dreg, sreg, AT);
7024 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7025 "d,v,t", dreg, 0, treg);
7027 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7028 "d,v,t", dreg, 0, sreg);
7031 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
7032 "d,v,t", dreg, sreg, treg);
7033 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7034 "d,v,t", dreg, 0, dreg);
7039 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7041 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7042 "d,v,t", dreg, 0, sreg);
7047 as_warn (_("Instruction %s: result is always true"),
7049 macro_build ((char *) NULL, &icnt, &expr1,
7050 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7051 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
7054 if (imm_expr.X_op == O_constant
7055 && imm_expr.X_add_number >= 0
7056 && imm_expr.X_add_number < 0x10000)
7058 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
7059 dreg, sreg, (int) BFD_RELOC_LO16);
7062 else if (imm_expr.X_op == O_constant
7063 && imm_expr.X_add_number > -0x8000
7064 && imm_expr.X_add_number < 0)
7066 imm_expr.X_add_number = -imm_expr.X_add_number;
7067 macro_build ((char *) NULL, &icnt, &imm_expr,
7068 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7069 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7074 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7075 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
7076 "d,v,t", dreg, sreg, AT);
7079 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7080 "d,v,t", dreg, 0, dreg);
7088 if (imm_expr.X_op == O_constant
7089 && imm_expr.X_add_number > -0x8000
7090 && imm_expr.X_add_number <= 0x8000)
7092 imm_expr.X_add_number = -imm_expr.X_add_number;
7093 macro_build ((char *) NULL, &icnt, &imm_expr,
7094 dbl ? "daddi" : "addi",
7095 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7098 load_register (&icnt, AT, &imm_expr, dbl);
7099 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7100 dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
7106 if (imm_expr.X_op == O_constant
7107 && imm_expr.X_add_number > -0x8000
7108 && imm_expr.X_add_number <= 0x8000)
7110 imm_expr.X_add_number = -imm_expr.X_add_number;
7111 macro_build ((char *) NULL, &icnt, &imm_expr,
7112 dbl ? "daddiu" : "addiu",
7113 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7116 load_register (&icnt, AT, &imm_expr, dbl);
7117 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7118 dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
7139 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7140 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg,
7146 assert (mips_opts.isa == ISA_MIPS1);
7147 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7148 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7151 * Is the double cfc1 instruction a bug in the mips assembler;
7152 * or is there a reason for it?
7154 mips_emit_delays (true);
7155 ++mips_opts.noreorder;
7156 mips_any_noreorder = 1;
7157 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7159 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7161 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7162 expr1.X_add_number = 3;
7163 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7164 (int) BFD_RELOC_LO16);
7165 expr1.X_add_number = 2;
7166 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7167 (int) BFD_RELOC_LO16);
7168 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7170 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7171 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7172 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
7173 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7175 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7176 --mips_opts.noreorder;
7185 if (offset_expr.X_add_number >= 0x7fff)
7186 as_bad (_("operand overflow"));
7187 /* avoid load delay */
7188 if (! target_big_endian)
7189 ++offset_expr.X_add_number;
7190 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7191 (int) BFD_RELOC_LO16, breg);
7192 if (! target_big_endian)
7193 --offset_expr.X_add_number;
7195 ++offset_expr.X_add_number;
7196 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
7197 (int) BFD_RELOC_LO16, breg);
7198 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7200 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7214 if (offset_expr.X_add_number >= 0x8000 - off)
7215 as_bad (_("operand overflow"));
7216 if (! target_big_endian)
7217 offset_expr.X_add_number += off;
7218 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7219 (int) BFD_RELOC_LO16, breg);
7220 if (! target_big_endian)
7221 offset_expr.X_add_number -= off;
7223 offset_expr.X_add_number += off;
7224 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7225 (int) BFD_RELOC_LO16, breg);
7239 load_address (&icnt, AT, &offset_expr, &used_at);
7241 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7242 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7243 "d,v,t", AT, AT, breg);
7244 if (! target_big_endian)
7245 expr1.X_add_number = off;
7247 expr1.X_add_number = 0;
7248 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7249 (int) BFD_RELOC_LO16, AT);
7250 if (! target_big_endian)
7251 expr1.X_add_number = 0;
7253 expr1.X_add_number = off;
7254 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7255 (int) BFD_RELOC_LO16, AT);
7261 load_address (&icnt, AT, &offset_expr, &used_at);
7263 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7264 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7265 "d,v,t", AT, AT, breg);
7266 if (target_big_endian)
7267 expr1.X_add_number = 0;
7268 macro_build ((char *) NULL, &icnt, &expr1,
7269 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
7270 (int) BFD_RELOC_LO16, AT);
7271 if (target_big_endian)
7272 expr1.X_add_number = 1;
7274 expr1.X_add_number = 0;
7275 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7276 (int) BFD_RELOC_LO16, AT);
7277 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7279 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7284 if (offset_expr.X_add_number >= 0x7fff)
7285 as_bad (_("operand overflow"));
7286 if (target_big_endian)
7287 ++offset_expr.X_add_number;
7288 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7289 (int) BFD_RELOC_LO16, breg);
7290 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7292 if (target_big_endian)
7293 --offset_expr.X_add_number;
7295 ++offset_expr.X_add_number;
7296 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7297 (int) BFD_RELOC_LO16, breg);
7310 if (offset_expr.X_add_number >= 0x8000 - off)
7311 as_bad (_("operand overflow"));
7312 if (! target_big_endian)
7313 offset_expr.X_add_number += off;
7314 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7315 (int) BFD_RELOC_LO16, breg);
7316 if (! target_big_endian)
7317 offset_expr.X_add_number -= off;
7319 offset_expr.X_add_number += off;
7320 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7321 (int) BFD_RELOC_LO16, breg);
7335 load_address (&icnt, AT, &offset_expr, &used_at);
7337 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7338 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7339 "d,v,t", AT, AT, breg);
7340 if (! target_big_endian)
7341 expr1.X_add_number = off;
7343 expr1.X_add_number = 0;
7344 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7345 (int) BFD_RELOC_LO16, AT);
7346 if (! target_big_endian)
7347 expr1.X_add_number = 0;
7349 expr1.X_add_number = off;
7350 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7351 (int) BFD_RELOC_LO16, AT);
7356 load_address (&icnt, AT, &offset_expr, &used_at);
7358 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7359 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7360 "d,v,t", AT, AT, breg);
7361 if (! target_big_endian)
7362 expr1.X_add_number = 0;
7363 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7364 (int) BFD_RELOC_LO16, AT);
7365 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7367 if (! target_big_endian)
7368 expr1.X_add_number = 1;
7370 expr1.X_add_number = 0;
7371 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7372 (int) BFD_RELOC_LO16, AT);
7373 if (! target_big_endian)
7374 expr1.X_add_number = 0;
7376 expr1.X_add_number = 1;
7377 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7378 (int) BFD_RELOC_LO16, AT);
7379 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7381 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7386 /* FIXME: Check if this is one of the itbl macros, since they
7387 are added dynamically. */
7388 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7392 as_warn (_("Macro used $at after \".set noat\""));
7395 /* Implement macros in mips16 mode. */
7399 struct mips_cl_insn *ip;
7402 int xreg, yreg, zreg, tmp;
7406 const char *s, *s2, *s3;
7408 mask = ip->insn_mo->mask;
7410 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7411 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7412 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7416 expr1.X_op = O_constant;
7417 expr1.X_op_symbol = NULL;
7418 expr1.X_add_symbol = NULL;
7419 expr1.X_add_number = 1;
7438 mips_emit_delays (true);
7439 ++mips_opts.noreorder;
7440 mips_any_noreorder = 1;
7441 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7442 dbl ? "ddiv" : "div",
7443 "0,x,y", xreg, yreg);
7444 expr1.X_add_number = 2;
7445 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7446 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6",
7449 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7450 since that causes an overflow. We should do that as well,
7451 but I don't see how to do the comparisons without a temporary
7453 --mips_opts.noreorder;
7454 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg);
7473 mips_emit_delays (true);
7474 ++mips_opts.noreorder;
7475 mips_any_noreorder = 1;
7476 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y",
7478 expr1.X_add_number = 2;
7479 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7480 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7482 --mips_opts.noreorder;
7483 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg);
7489 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7490 dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7491 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x",
7500 if (imm_expr.X_op != O_constant)
7501 as_bad (_("Unsupported large constant"));
7502 imm_expr.X_add_number = -imm_expr.X_add_number;
7503 macro_build ((char *) NULL, &icnt, &imm_expr,
7504 dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7508 if (imm_expr.X_op != O_constant)
7509 as_bad (_("Unsupported large constant"));
7510 imm_expr.X_add_number = -imm_expr.X_add_number;
7511 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
7516 if (imm_expr.X_op != O_constant)
7517 as_bad (_("Unsupported large constant"));
7518 imm_expr.X_add_number = -imm_expr.X_add_number;
7519 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
7542 goto do_reverse_branch;
7546 goto do_reverse_branch;
7558 goto do_reverse_branch;
7569 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
7571 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7598 goto do_addone_branch_i;
7603 goto do_addone_branch_i;
7618 goto do_addone_branch_i;
7625 if (imm_expr.X_op != O_constant)
7626 as_bad (_("Unsupported large constant"));
7627 ++imm_expr.X_add_number;
7630 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
7631 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7635 expr1.X_add_number = 0;
7636 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
7638 move_register (&icnt, xreg, yreg);
7639 expr1.X_add_number = 2;
7640 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
7641 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7642 "neg", "x,w", xreg, xreg);
7646 /* For consistency checking, verify that all bits are specified either
7647 by the match/mask part of the instruction definition, or by the
7650 validate_mips_insn (opc)
7651 const struct mips_opcode *opc;
7653 const char *p = opc->args;
7655 unsigned long used_bits = opc->mask;
7657 if ((used_bits & opc->match) != opc->match)
7659 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7660 opc->name, opc->args);
7663 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7670 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7671 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7673 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
7674 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
7675 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7676 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7678 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7679 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7681 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
7683 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
7684 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
7685 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
7686 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7687 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7688 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7689 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7690 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
7691 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7692 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
7693 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7695 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
7696 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7697 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7698 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
7700 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7701 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7702 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
7703 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7704 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7705 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7706 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7707 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7708 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7711 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
7712 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
7713 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7715 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7716 c, opc->name, opc->args);
7720 if (used_bits != 0xffffffff)
7722 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7723 ~used_bits & 0xffffffff, opc->name, opc->args);
7729 /* This routine assembles an instruction into its binary format. As a
7730 side effect, it sets one of the global variables imm_reloc or
7731 offset_reloc to the type of relocation to do if one of the operands
7732 is an address expression. */
7737 struct mips_cl_insn *ip;
7742 struct mips_opcode *insn;
7745 unsigned int lastregno = 0;
7751 /* If the instruction contains a '.', we first try to match an instruction
7752 including the '.'. Then we try again without the '.'. */
7754 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
7757 /* If we stopped on whitespace, then replace the whitespace with null for
7758 the call to hash_find. Save the character we replaced just in case we
7759 have to re-parse the instruction. */
7766 insn = (struct mips_opcode *) hash_find (op_hash, str);
7768 /* If we didn't find the instruction in the opcode table, try again, but
7769 this time with just the instruction up to, but not including the
7773 /* Restore the character we overwrite above (if any). */
7777 /* Scan up to the first '.' or whitespace. */
7779 *s != '\0' && *s != '.' && !ISSPACE (*s);
7783 /* If we did not find a '.', then we can quit now. */
7786 insn_error = "unrecognized opcode";
7790 /* Lookup the instruction in the hash table. */
7792 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7794 insn_error = "unrecognized opcode";
7804 assert (strcmp (insn->name, str) == 0);
7806 if (OPCODE_IS_MEMBER (insn,
7808 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
7814 if (insn->pinfo != INSN_MACRO)
7816 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7822 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7823 && strcmp (insn->name, insn[1].name) == 0)
7832 static char buf[100];
7834 _("opcode not supported on this processor: %s (%s)"),
7835 mips_cpu_to_str (mips_arch),
7836 mips_isa_to_str (mips_opts.isa));
7847 ip->insn_opcode = insn->match;
7849 for (args = insn->args;; ++args)
7851 s += strspn (s, " \t");
7854 case '\0': /* end of args */
7867 ip->insn_opcode |= lastregno << OP_SH_RS;
7871 ip->insn_opcode |= lastregno << OP_SH_RT;
7875 ip->insn_opcode |= lastregno << OP_SH_FT;
7879 ip->insn_opcode |= lastregno << OP_SH_FS;
7885 /* Handle optional base register.
7886 Either the base register is omitted or
7887 we must have a left paren. */
7888 /* This is dependent on the next operand specifier
7889 is a base register specification. */
7890 assert (args[1] == 'b' || args[1] == '5'
7891 || args[1] == '-' || args[1] == '4');
7895 case ')': /* these must match exactly */
7900 case '<': /* must be at least one digit */
7902 * According to the manual, if the shift amount is greater
7903 * than 31 or less than 0, then the shift amount should be
7904 * mod 32. In reality the mips assembler issues an error.
7905 * We issue a warning and mask out all but the low 5 bits.
7907 my_getExpression (&imm_expr, s);
7908 check_absolute_expr (ip, &imm_expr);
7909 if ((unsigned long) imm_expr.X_add_number > 31)
7911 as_warn (_("Improper shift amount (%ld)"),
7912 (long) imm_expr.X_add_number);
7913 imm_expr.X_add_number &= OP_MASK_SHAMT;
7915 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
7916 imm_expr.X_op = O_absent;
7920 case '>': /* shift amount minus 32 */
7921 my_getExpression (&imm_expr, s);
7922 check_absolute_expr (ip, &imm_expr);
7923 if ((unsigned long) imm_expr.X_add_number < 32
7924 || (unsigned long) imm_expr.X_add_number > 63)
7926 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
7927 imm_expr.X_op = O_absent;
7931 case 'k': /* cache code */
7932 case 'h': /* prefx code */
7933 my_getExpression (&imm_expr, s);
7934 check_absolute_expr (ip, &imm_expr);
7935 if ((unsigned long) imm_expr.X_add_number > 31)
7937 as_warn (_("Invalid value for `%s' (%lu)"),
7939 (unsigned long) imm_expr.X_add_number);
7940 imm_expr.X_add_number &= 0x1f;
7943 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7945 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7946 imm_expr.X_op = O_absent;
7950 case 'c': /* break code */
7951 my_getExpression (&imm_expr, s);
7952 check_absolute_expr (ip, &imm_expr);
7953 if ((unsigned) imm_expr.X_add_number > 1023)
7955 as_warn (_("Illegal break code (%ld)"),
7956 (long) imm_expr.X_add_number);
7957 imm_expr.X_add_number &= OP_MASK_CODE;
7959 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
7960 imm_expr.X_op = O_absent;
7964 case 'q': /* lower break code */
7965 my_getExpression (&imm_expr, s);
7966 check_absolute_expr (ip, &imm_expr);
7967 if ((unsigned) imm_expr.X_add_number > 1023)
7969 as_warn (_("Illegal lower break code (%ld)"),
7970 (long) imm_expr.X_add_number);
7971 imm_expr.X_add_number &= OP_MASK_CODE2;
7973 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
7974 imm_expr.X_op = O_absent;
7978 case 'B': /* 20-bit syscall/break code. */
7979 my_getExpression (&imm_expr, s);
7980 check_absolute_expr (ip, &imm_expr);
7981 if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE20)
7982 as_warn (_("Illegal 20-bit code (%ld)"),
7983 (long) imm_expr.X_add_number);
7984 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
7985 imm_expr.X_op = O_absent;
7989 case 'C': /* Coprocessor code */
7990 my_getExpression (&imm_expr, s);
7991 check_absolute_expr (ip, &imm_expr);
7992 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
7994 as_warn (_("Coproccesor code > 25 bits (%ld)"),
7995 (long) imm_expr.X_add_number);
7996 imm_expr.X_add_number &= ((1 << 25) - 1);
7998 ip->insn_opcode |= imm_expr.X_add_number;
7999 imm_expr.X_op = O_absent;
8003 case 'J': /* 19-bit wait code. */
8004 my_getExpression (&imm_expr, s);
8005 check_absolute_expr (ip, &imm_expr);
8006 if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE19)
8007 as_warn (_("Illegal 19-bit code (%ld)"),
8008 (long) imm_expr.X_add_number);
8009 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
8010 imm_expr.X_op = O_absent;
8014 case 'P': /* Performance register */
8015 my_getExpression (&imm_expr, s);
8016 check_absolute_expr (ip, &imm_expr);
8017 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
8019 as_warn (_("Invalid performance register (%ld)"),
8020 (long) imm_expr.X_add_number);
8021 imm_expr.X_add_number &= OP_MASK_PERFREG;
8023 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
8024 imm_expr.X_op = O_absent;
8028 case 'b': /* base register */
8029 case 'd': /* destination register */
8030 case 's': /* source register */
8031 case 't': /* target register */
8032 case 'r': /* both target and source */
8033 case 'v': /* both dest and source */
8034 case 'w': /* both dest and target */
8035 case 'E': /* coprocessor target register */
8036 case 'G': /* coprocessor destination register */
8037 case 'x': /* ignore register name */
8038 case 'z': /* must be zero register */
8039 case 'U': /* destination register (clo/clz). */
8054 while (ISDIGIT (*s));
8056 as_bad (_("Invalid register number (%d)"), regno);
8058 else if (*args == 'E' || *args == 'G')
8062 if (s[1] == 'f' && s[2] == 'p')
8067 else if (s[1] == 's' && s[2] == 'p')
8072 else if (s[1] == 'g' && s[2] == 'p')
8077 else if (s[1] == 'a' && s[2] == 't')
8082 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8087 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8092 else if (itbl_have_entries)
8097 p = s + 1; /* advance past '$' */
8098 n = itbl_get_field (&p); /* n is name */
8100 /* See if this is a register defined in an
8102 if (itbl_get_reg_val (n, &r))
8104 /* Get_field advances to the start of
8105 the next field, so we need to back
8106 rack to the end of the last field. */
8110 s = strchr (s, '\0');
8123 as_warn (_("Used $at without \".set noat\""));
8129 if (c == 'r' || c == 'v' || c == 'w')
8136 /* 'z' only matches $0. */
8137 if (c == 'z' && regno != 0)
8140 /* Now that we have assembled one operand, we use the args string
8141 * to figure out where it goes in the instruction. */
8148 ip->insn_opcode |= regno << OP_SH_RS;
8152 ip->insn_opcode |= regno << OP_SH_RD;
8155 ip->insn_opcode |= regno << OP_SH_RD;
8156 ip->insn_opcode |= regno << OP_SH_RT;
8161 ip->insn_opcode |= regno << OP_SH_RT;
8164 /* This case exists because on the r3000 trunc
8165 expands into a macro which requires a gp
8166 register. On the r6000 or r4000 it is
8167 assembled into a single instruction which
8168 ignores the register. Thus the insn version
8169 is MIPS_ISA2 and uses 'x', and the macro
8170 version is MIPS_ISA1 and uses 't'. */
8173 /* This case is for the div instruction, which
8174 acts differently if the destination argument
8175 is $0. This only matches $0, and is checked
8176 outside the switch. */
8179 /* Itbl operand; not yet implemented. FIXME ?? */
8181 /* What about all other operands like 'i', which
8182 can be specified in the opcode table? */
8192 ip->insn_opcode |= lastregno << OP_SH_RS;
8195 ip->insn_opcode |= lastregno << OP_SH_RT;
8200 case 'D': /* floating point destination register */
8201 case 'S': /* floating point source register */
8202 case 'T': /* floating point target register */
8203 case 'R': /* floating point source register */
8207 if (s[0] == '$' && s[1] == 'f'
8218 while (ISDIGIT (*s));
8221 as_bad (_("Invalid float register number (%d)"), regno);
8223 if ((regno & 1) != 0
8225 && ! (strcmp (str, "mtc1") == 0
8226 || strcmp (str, "mfc1") == 0
8227 || strcmp (str, "lwc1") == 0
8228 || strcmp (str, "swc1") == 0
8229 || strcmp (str, "l.s") == 0
8230 || strcmp (str, "s.s") == 0))
8231 as_warn (_("Float register should be even, was %d"),
8239 if (c == 'V' || c == 'W')
8249 ip->insn_opcode |= regno << OP_SH_FD;
8253 ip->insn_opcode |= regno << OP_SH_FS;
8257 ip->insn_opcode |= regno << OP_SH_FT;
8260 ip->insn_opcode |= regno << OP_SH_FR;
8270 ip->insn_opcode |= lastregno << OP_SH_FS;
8273 ip->insn_opcode |= lastregno << OP_SH_FT;
8279 my_getExpression (&imm_expr, s);
8280 if (imm_expr.X_op != O_big
8281 && imm_expr.X_op != O_constant)
8282 insn_error = _("absolute expression required");
8287 my_getExpression (&offset_expr, s);
8288 *imm_reloc = BFD_RELOC_32;
8301 unsigned char temp[8];
8303 unsigned int length;
8308 /* These only appear as the last operand in an
8309 instruction, and every instruction that accepts
8310 them in any variant accepts them in all variants.
8311 This means we don't have to worry about backing out
8312 any changes if the instruction does not match.
8314 The difference between them is the size of the
8315 floating point constant and where it goes. For 'F'
8316 and 'L' the constant is 64 bits; for 'f' and 'l' it
8317 is 32 bits. Where the constant is placed is based
8318 on how the MIPS assembler does things:
8321 f -- immediate value
8324 The .lit4 and .lit8 sections are only used if
8325 permitted by the -G argument.
8327 When generating embedded PIC code, we use the
8328 .lit8 section but not the .lit4 section (we can do
8329 .lit4 inline easily; we need to put .lit8
8330 somewhere in the data segment, and using .lit8
8331 permits the linker to eventually combine identical
8334 The code below needs to know whether the target register
8335 is 32 or 64 bits wide. It relies on the fact 'f' and
8336 'F' are used with GPR-based instructions and 'l' and
8337 'L' are used with FPR-based instructions. */
8339 f64 = *args == 'F' || *args == 'L';
8340 using_gprs = *args == 'F' || *args == 'f';
8342 save_in = input_line_pointer;
8343 input_line_pointer = s;
8344 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8346 s = input_line_pointer;
8347 input_line_pointer = save_in;
8348 if (err != NULL && *err != '\0')
8350 as_bad (_("Bad floating point constant: %s"), err);
8351 memset (temp, '\0', sizeof temp);
8352 length = f64 ? 8 : 4;
8355 assert (length == (unsigned) (f64 ? 8 : 4));
8359 && (! USE_GLOBAL_POINTER_OPT
8360 || mips_pic == EMBEDDED_PIC
8361 || g_switch_value < 4
8362 || (temp[0] == 0 && temp[1] == 0)
8363 || (temp[2] == 0 && temp[3] == 0))))
8365 imm_expr.X_op = O_constant;
8366 if (! target_big_endian)
8367 imm_expr.X_add_number = bfd_getl32 (temp);
8369 imm_expr.X_add_number = bfd_getb32 (temp);
8372 && ! mips_disable_float_construction
8373 /* Constants can only be constructed in GPRs and
8374 copied to FPRs if the GPRs are at least as wide
8375 as the FPRs. Force the constant into memory if
8376 we are using 64-bit FPRs but the GPRs are only
8379 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8380 && ((temp[0] == 0 && temp[1] == 0)
8381 || (temp[2] == 0 && temp[3] == 0))
8382 && ((temp[4] == 0 && temp[5] == 0)
8383 || (temp[6] == 0 && temp[7] == 0)))
8385 /* The value is simple enough to load with a couple of
8386 instructions. If using 32-bit registers, set
8387 imm_expr to the high order 32 bits and offset_expr to
8388 the low order 32 bits. Otherwise, set imm_expr to
8389 the entire 64 bit constant. */
8390 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8392 imm_expr.X_op = O_constant;
8393 offset_expr.X_op = O_constant;
8394 if (! target_big_endian)
8396 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8397 offset_expr.X_add_number = bfd_getl32 (temp);
8401 imm_expr.X_add_number = bfd_getb32 (temp);
8402 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8404 if (offset_expr.X_add_number == 0)
8405 offset_expr.X_op = O_absent;
8407 else if (sizeof (imm_expr.X_add_number) > 4)
8409 imm_expr.X_op = O_constant;
8410 if (! target_big_endian)
8411 imm_expr.X_add_number = bfd_getl64 (temp);
8413 imm_expr.X_add_number = bfd_getb64 (temp);
8417 imm_expr.X_op = O_big;
8418 imm_expr.X_add_number = 4;
8419 if (! target_big_endian)
8421 generic_bignum[0] = bfd_getl16 (temp);
8422 generic_bignum[1] = bfd_getl16 (temp + 2);
8423 generic_bignum[2] = bfd_getl16 (temp + 4);
8424 generic_bignum[3] = bfd_getl16 (temp + 6);
8428 generic_bignum[0] = bfd_getb16 (temp + 6);
8429 generic_bignum[1] = bfd_getb16 (temp + 4);
8430 generic_bignum[2] = bfd_getb16 (temp + 2);
8431 generic_bignum[3] = bfd_getb16 (temp);
8437 const char *newname;
8440 /* Switch to the right section. */
8442 subseg = now_subseg;
8445 default: /* unused default case avoids warnings. */
8447 newname = RDATA_SECTION_NAME;
8448 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
8449 || mips_pic == EMBEDDED_PIC)
8453 if (mips_pic == EMBEDDED_PIC)
8456 newname = RDATA_SECTION_NAME;
8459 assert (!USE_GLOBAL_POINTER_OPT
8460 || g_switch_value >= 4);
8464 new_seg = subseg_new (newname, (subsegT) 0);
8465 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
8466 bfd_set_section_flags (stdoutput, new_seg,
8471 frag_align (*args == 'l' ? 2 : 3, 0, 0);
8472 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
8473 && strcmp (TARGET_OS, "elf") != 0)
8474 record_alignment (new_seg, 4);
8476 record_alignment (new_seg, *args == 'l' ? 2 : 3);
8478 as_bad (_("Can't use floating point insn in this section"));
8480 /* Set the argument to the current address in the
8482 offset_expr.X_op = O_symbol;
8483 offset_expr.X_add_symbol =
8484 symbol_new ("L0\001", now_seg,
8485 (valueT) frag_now_fix (), frag_now);
8486 offset_expr.X_add_number = 0;
8488 /* Put the floating point number into the section. */
8489 p = frag_more ((int) length);
8490 memcpy (p, temp, length);
8492 /* Switch back to the original section. */
8493 subseg_set (seg, subseg);
8498 case 'i': /* 16 bit unsigned immediate */
8499 case 'j': /* 16 bit signed immediate */
8500 *imm_reloc = BFD_RELOC_LO16;
8501 c = my_getSmallExpression (&imm_expr, s);
8506 if (imm_expr.X_op == O_constant)
8507 imm_expr.X_add_number =
8508 (imm_expr.X_add_number >> 16) & 0xffff;
8510 else if (c == S_EX_HIGHEST)
8511 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8512 else if (c == S_EX_HIGHER)
8513 *imm_reloc = BFD_RELOC_MIPS_HIGHER;
8514 else if (c == S_EX_GP_REL)
8516 /* This occurs in NewABI only. */
8517 c = my_getSmallExpression (&imm_expr, s);
8519 as_bad (_("bad composition of relocations"));
8522 c = my_getSmallExpression (&imm_expr, s);
8524 as_bad (_("bad composition of relocations"));
8527 imm_reloc[0] = BFD_RELOC_GPREL16;
8528 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8529 imm_reloc[2] = BFD_RELOC_LO16;
8534 else if (c == S_EX_HI)
8536 *imm_reloc = BFD_RELOC_HI16_S;
8537 imm_unmatched_hi = true;
8540 *imm_reloc = BFD_RELOC_HI16;
8542 else if (imm_expr.X_op == O_constant)
8543 imm_expr.X_add_number &= 0xffff;
8547 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8548 || ((imm_expr.X_add_number < 0
8549 || imm_expr.X_add_number >= 0x10000)
8550 && imm_expr.X_op == O_constant))
8552 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8553 !strcmp (insn->name, insn[1].name))
8555 if (imm_expr.X_op == O_constant
8556 || imm_expr.X_op == O_big)
8557 as_bad (_("16 bit expression not in range 0..65535"));
8565 /* The upper bound should be 0x8000, but
8566 unfortunately the MIPS assembler accepts numbers
8567 from 0x8000 to 0xffff and sign extends them, and
8568 we want to be compatible. We only permit this
8569 extended range for an instruction which does not
8570 provide any further alternates, since those
8571 alternates may handle other cases. People should
8572 use the numbers they mean, rather than relying on
8573 a mysterious sign extension. */
8574 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8575 strcmp (insn->name, insn[1].name) == 0);
8580 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8581 || ((imm_expr.X_add_number < -0x8000
8582 || imm_expr.X_add_number >= max)
8583 && imm_expr.X_op == O_constant)
8585 && imm_expr.X_add_number < 0
8587 && imm_expr.X_unsigned
8588 && sizeof (imm_expr.X_add_number) <= 4))
8592 if (imm_expr.X_op == O_constant
8593 || imm_expr.X_op == O_big)
8594 as_bad (_("16 bit expression not in range -32768..32767"));
8600 case 'o': /* 16 bit offset */
8601 c = my_getSmallExpression (&offset_expr, s);
8603 /* If this value won't fit into a 16 bit offset, then go
8604 find a macro that will generate the 32 bit offset
8607 && (offset_expr.X_op != O_constant
8608 || offset_expr.X_add_number >= 0x8000
8609 || offset_expr.X_add_number < -0x8000))
8614 if (offset_expr.X_op != O_constant)
8616 offset_expr.X_add_number =
8617 (offset_expr.X_add_number >> 16) & 0xffff;
8619 *offset_reloc = BFD_RELOC_LO16;
8623 case 'p': /* pc relative offset */
8624 if (mips_pic == EMBEDDED_PIC)
8625 *offset_reloc = BFD_RELOC_16_PCREL_S2;
8627 *offset_reloc = BFD_RELOC_16_PCREL;
8628 my_getExpression (&offset_expr, s);
8632 case 'u': /* upper 16 bits */
8633 c = my_getSmallExpression (&imm_expr, s);
8634 *imm_reloc = BFD_RELOC_LO16;
8639 if (imm_expr.X_op == O_constant)
8640 imm_expr.X_add_number =
8641 (imm_expr.X_add_number >> 16) & 0xffff;
8642 else if (c == S_EX_HI)
8644 *imm_reloc = BFD_RELOC_HI16_S;
8645 imm_unmatched_hi = true;
8648 else if (c == S_EX_HIGHEST)
8649 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8650 else if (c == S_EX_GP_REL)
8652 /* This occurs in NewABI only. */
8653 c = my_getSmallExpression (&imm_expr, s);
8655 as_bad (_("bad composition of relocations"));
8658 c = my_getSmallExpression (&imm_expr, s);
8660 as_bad (_("bad composition of relocations"));
8663 imm_reloc[0] = BFD_RELOC_GPREL16;
8664 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8665 imm_reloc[2] = BFD_RELOC_HI16_S;
8671 *imm_reloc = BFD_RELOC_HI16;
8673 else if (imm_expr.X_op == O_constant)
8674 imm_expr.X_add_number &= 0xffff;
8676 if (imm_expr.X_op == O_constant
8677 && (imm_expr.X_add_number < 0
8678 || imm_expr.X_add_number >= 0x10000))
8679 as_bad (_("lui expression not in range 0..65535"));
8683 case 'a': /* 26 bit address */
8684 my_getExpression (&offset_expr, s);
8686 *offset_reloc = BFD_RELOC_MIPS_JMP;
8689 case 'N': /* 3 bit branch condition code */
8690 case 'M': /* 3 bit compare condition code */
8691 if (strncmp (s, "$fcc", 4) != 0)
8701 while (ISDIGIT (*s));
8703 as_bad (_("invalid condition code register $fcc%d"), regno);
8705 ip->insn_opcode |= regno << OP_SH_BCC;
8707 ip->insn_opcode |= regno << OP_SH_CCC;
8711 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
8722 while (ISDIGIT (*s));
8725 c = 8; /* Invalid sel value. */
8728 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
8729 ip->insn_opcode |= c;
8733 as_bad (_("bad char = '%c'\n"), *args);
8738 /* Args don't match. */
8739 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8740 !strcmp (insn->name, insn[1].name))
8744 insn_error = _("illegal operands");
8749 insn_error = _("illegal operands");
8754 /* This routine assembles an instruction into its binary format when
8755 assembling for the mips16. As a side effect, it sets one of the
8756 global variables imm_reloc or offset_reloc to the type of
8757 relocation to do if one of the operands is an address expression.
8758 It also sets mips16_small and mips16_ext if the user explicitly
8759 requested a small or extended instruction. */
8764 struct mips_cl_insn *ip;
8768 struct mips_opcode *insn;
8771 unsigned int lastregno = 0;
8776 mips16_small = false;
8779 for (s = str; ISLOWER (*s); ++s)
8791 if (s[1] == 't' && s[2] == ' ')
8794 mips16_small = true;
8798 else if (s[1] == 'e' && s[2] == ' ')
8807 insn_error = _("unknown opcode");
8811 if (mips_opts.noautoextend && ! mips16_ext)
8812 mips16_small = true;
8814 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
8816 insn_error = _("unrecognized opcode");
8823 assert (strcmp (insn->name, str) == 0);
8826 ip->insn_opcode = insn->match;
8827 ip->use_extend = false;
8828 imm_expr.X_op = O_absent;
8829 imm_reloc[0] = BFD_RELOC_UNUSED;
8830 imm_reloc[1] = BFD_RELOC_UNUSED;
8831 imm_reloc[2] = BFD_RELOC_UNUSED;
8832 offset_expr.X_op = O_absent;
8833 offset_reloc[0] = BFD_RELOC_UNUSED;
8834 offset_reloc[1] = BFD_RELOC_UNUSED;
8835 offset_reloc[2] = BFD_RELOC_UNUSED;
8836 for (args = insn->args; 1; ++args)
8843 /* In this switch statement we call break if we did not find
8844 a match, continue if we did find a match, or return if we
8853 /* Stuff the immediate value in now, if we can. */
8854 if (imm_expr.X_op == O_constant
8855 && *imm_reloc > BFD_RELOC_UNUSED
8856 && insn->pinfo != INSN_MACRO)
8858 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
8859 imm_expr.X_add_number, true, mips16_small,
8860 mips16_ext, &ip->insn_opcode,
8861 &ip->use_extend, &ip->extend);
8862 imm_expr.X_op = O_absent;
8863 *imm_reloc = BFD_RELOC_UNUSED;
8877 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8880 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8896 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8898 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8925 while (ISDIGIT (*s));
8928 as_bad (_("invalid register number (%d)"), regno);
8934 if (s[1] == 'f' && s[2] == 'p')
8939 else if (s[1] == 's' && s[2] == 'p')
8944 else if (s[1] == 'g' && s[2] == 'p')
8949 else if (s[1] == 'a' && s[2] == 't')
8954 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8959 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8972 if (c == 'v' || c == 'w')
8974 regno = mips16_to_32_reg_map[lastregno];
8988 regno = mips32_to_16_reg_map[regno];
8993 regno = ILLEGAL_REG;
8998 regno = ILLEGAL_REG;
9003 regno = ILLEGAL_REG;
9008 if (regno == AT && ! mips_opts.noat)
9009 as_warn (_("used $at without \".set noat\""));
9016 if (regno == ILLEGAL_REG)
9023 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
9027 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
9030 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
9033 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
9039 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
9042 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9043 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
9053 if (strncmp (s, "$pc", 3) == 0)
9077 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
9079 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9080 and generate the appropriate reloc. If the text
9081 inside %gprel is not a symbol name with an
9082 optional offset, then we generate a normal reloc
9083 and will probably fail later. */
9084 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
9085 if (imm_expr.X_op == O_symbol)
9088 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
9090 ip->use_extend = true;
9097 /* Just pick up a normal expression. */
9098 my_getExpression (&imm_expr, s);
9101 if (imm_expr.X_op == O_register)
9103 /* What we thought was an expression turned out to
9106 if (s[0] == '(' && args[1] == '(')
9108 /* It looks like the expression was omitted
9109 before a register indirection, which means
9110 that the expression is implicitly zero. We
9111 still set up imm_expr, so that we handle
9112 explicit extensions correctly. */
9113 imm_expr.X_op = O_constant;
9114 imm_expr.X_add_number = 0;
9115 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9122 /* We need to relax this instruction. */
9123 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9132 /* We use offset_reloc rather than imm_reloc for the PC
9133 relative operands. This lets macros with both
9134 immediate and address operands work correctly. */
9135 my_getExpression (&offset_expr, s);
9137 if (offset_expr.X_op == O_register)
9140 /* We need to relax this instruction. */
9141 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9145 case '6': /* break code */
9146 my_getExpression (&imm_expr, s);
9147 check_absolute_expr (ip, &imm_expr);
9148 if ((unsigned long) imm_expr.X_add_number > 63)
9150 as_warn (_("Invalid value for `%s' (%lu)"),
9152 (unsigned long) imm_expr.X_add_number);
9153 imm_expr.X_add_number &= 0x3f;
9155 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9156 imm_expr.X_op = O_absent;
9160 case 'a': /* 26 bit address */
9161 my_getExpression (&offset_expr, s);
9163 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9164 ip->insn_opcode <<= 16;
9167 case 'l': /* register list for entry macro */
9168 case 'L': /* register list for exit macro */
9178 int freg, reg1, reg2;
9180 while (*s == ' ' || *s == ',')
9184 as_bad (_("can't parse register list"));
9196 while (ISDIGIT (*s))
9218 as_bad (_("invalid register list"));
9223 while (ISDIGIT (*s))
9230 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9235 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9240 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9241 mask |= (reg2 - 3) << 3;
9242 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9243 mask |= (reg2 - 15) << 1;
9244 else if (reg1 == RA && reg2 == RA)
9248 as_bad (_("invalid register list"));
9252 /* The mask is filled in in the opcode table for the
9253 benefit of the disassembler. We remove it before
9254 applying the actual mask. */
9255 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9256 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9260 case 'e': /* extend code */
9261 my_getExpression (&imm_expr, s);
9262 check_absolute_expr (ip, &imm_expr);
9263 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9265 as_warn (_("Invalid value for `%s' (%lu)"),
9267 (unsigned long) imm_expr.X_add_number);
9268 imm_expr.X_add_number &= 0x7ff;
9270 ip->insn_opcode |= imm_expr.X_add_number;
9271 imm_expr.X_op = O_absent;
9281 /* Args don't match. */
9282 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9283 strcmp (insn->name, insn[1].name) == 0)
9290 insn_error = _("illegal operands");
9296 /* This structure holds information we know about a mips16 immediate
9299 struct mips16_immed_operand
9301 /* The type code used in the argument string in the opcode table. */
9303 /* The number of bits in the short form of the opcode. */
9305 /* The number of bits in the extended form of the opcode. */
9307 /* The amount by which the short form is shifted when it is used;
9308 for example, the sw instruction has a shift count of 2. */
9310 /* The amount by which the short form is shifted when it is stored
9311 into the instruction code. */
9313 /* Non-zero if the short form is unsigned. */
9315 /* Non-zero if the extended form is unsigned. */
9317 /* Non-zero if the value is PC relative. */
9321 /* The mips16 immediate operand types. */
9323 static const struct mips16_immed_operand mips16_immed_operands[] =
9325 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9326 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9327 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9328 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9329 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9330 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9331 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9332 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9333 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9334 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9335 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9336 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9337 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9338 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9339 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9340 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9341 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9342 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9343 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9344 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9345 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9348 #define MIPS16_NUM_IMMED \
9349 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9351 /* Handle a mips16 instruction with an immediate value. This or's the
9352 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9353 whether an extended value is needed; if one is needed, it sets
9354 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9355 If SMALL is true, an unextended opcode was explicitly requested.
9356 If EXT is true, an extended opcode was explicitly requested. If
9357 WARN is true, warn if EXT does not match reality. */
9360 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
9369 unsigned long *insn;
9370 boolean *use_extend;
9371 unsigned short *extend;
9373 register const struct mips16_immed_operand *op;
9374 int mintiny, maxtiny;
9377 op = mips16_immed_operands;
9378 while (op->type != type)
9381 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9386 if (type == '<' || type == '>' || type == '[' || type == ']')
9389 maxtiny = 1 << op->nbits;
9394 maxtiny = (1 << op->nbits) - 1;
9399 mintiny = - (1 << (op->nbits - 1));
9400 maxtiny = (1 << (op->nbits - 1)) - 1;
9403 /* Branch offsets have an implicit 0 in the lowest bit. */
9404 if (type == 'p' || type == 'q')
9407 if ((val & ((1 << op->shift) - 1)) != 0
9408 || val < (mintiny << op->shift)
9409 || val > (maxtiny << op->shift))
9414 if (warn && ext && ! needext)
9415 as_warn_where (file, line,
9416 _("extended operand requested but not required"));
9417 if (small && needext)
9418 as_bad_where (file, line, _("invalid unextended operand value"));
9420 if (small || (! ext && ! needext))
9424 *use_extend = false;
9425 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9426 insnval <<= op->op_shift;
9431 long minext, maxext;
9437 maxext = (1 << op->extbits) - 1;
9441 minext = - (1 << (op->extbits - 1));
9442 maxext = (1 << (op->extbits - 1)) - 1;
9444 if (val < minext || val > maxext)
9445 as_bad_where (file, line,
9446 _("operand value out of range for instruction"));
9449 if (op->extbits == 16)
9451 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
9454 else if (op->extbits == 15)
9456 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
9461 extval = ((val & 0x1f) << 6) | (val & 0x20);
9465 *extend = (unsigned short) extval;
9470 static struct percent_op_match
9473 const enum small_ex_type type;
9478 {"%call_hi", S_EX_CALL_HI},
9479 {"%call_lo", S_EX_CALL_LO},
9480 {"%call16", S_EX_CALL16},
9481 {"%got_disp", S_EX_GOT_DISP},
9482 {"%got_page", S_EX_GOT_PAGE},
9483 {"%got_ofst", S_EX_GOT_OFST},
9484 {"%got_hi", S_EX_GOT_HI},
9485 {"%got_lo", S_EX_GOT_LO},
9487 {"%gp_rel", S_EX_GP_REL},
9488 {"%half", S_EX_HALF},
9489 {"%highest", S_EX_HIGHEST},
9490 {"%higher", S_EX_HIGHER},
9496 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9497 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9498 can be nested, this is handled by blanking the innermost, parsing the
9499 rest by subsequent calls. */
9502 my_getSmallParser (str, len, nestlevel)
9508 *str += strspn (*str, " \t");
9509 /* Check for expression in parentheses. */
9512 char *b = *str + 1 + strspn (*str + 1, " \t");
9515 /* Check for base register. */
9519 && (e = b + strcspn (b, ") \t"))
9520 && e - b > 1 && e - b < 4)
9523 && ((b[1] == 'f' && b[2] == 'p')
9524 || (b[1] == 's' && b[2] == 'p')
9525 || (b[1] == 'g' && b[2] == 'p')
9526 || (b[1] == 'a' && b[2] == 't')
9528 && ISDIGIT (b[2]))))
9529 || (ISDIGIT (b[1])))
9531 *len = strcspn (*str, ")") + 1;
9532 return S_EX_REGISTER;
9536 /* Check for percent_op (in parentheses). */
9537 else if (b[0] == '%')
9540 return my_getPercentOp (str, len, nestlevel);
9543 /* Some other expression in the parentheses, which can contain
9544 parentheses itself. Attempt to find the matching one. */
9550 for (s = *str + 1; *s && pcnt; s++, (*len)++)
9559 /* Check for percent_op (outside of parentheses). */
9560 else if (*str[0] == '%')
9561 return my_getPercentOp (str, len, nestlevel);
9563 /* Any other expression. */
9568 my_getPercentOp (str, len, nestlevel)
9573 char *tmp = *str + 1;
9576 while (ISALPHA (*tmp) || *tmp == '_')
9578 *tmp = TOLOWER (*tmp);
9581 while (i < (sizeof (percent_op) / sizeof (struct percent_op_match)))
9583 if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str)))
9587 int type = percent_op[i].type;
9589 /* Only %hi and %lo are allowed for OldABI. */
9590 if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO)
9593 *len = strlen (percent_op[i].str);
9602 my_getSmallExpression (ep, str)
9606 static char *oldstr = NULL;
9612 /* Don't update oldstr if the last call had nested percent_op's. We need
9613 it to parse the outer ones later. */
9620 c = my_getSmallParser (&str, &len, &nestlevel);
9621 if (c != S_EX_NONE && c != S_EX_REGISTER)
9624 while (c != S_EX_NONE && c != S_EX_REGISTER);
9628 /* A percent_op was encountered. Don't try to get an expression if
9629 it is already blanked out. */
9630 if (*(str + strspn (str + 1, " )")) != ')')
9634 /* Let my_getExpression() stop at the closing parenthesis. */
9635 save = *(str + len);
9636 *(str + len) = '\0';
9637 my_getExpression (ep, str);
9638 *(str + len) = save;
9642 /* Blank out including the % sign and the proper matching
9645 char *s = strrchr (oldstr, '%');
9648 for (end = strchr (s, '(') + 1; *end && pcnt; end++)
9652 else if (*end == ')')
9656 memset (s, ' ', end - s);
9660 expr_end = str + len;
9664 else if (c == S_EX_NONE)
9666 my_getExpression (ep, str);
9668 else if (c == S_EX_REGISTER)
9670 ep->X_op = O_constant;
9672 ep->X_add_symbol = NULL;
9673 ep->X_op_symbol = NULL;
9674 ep->X_add_number = 0;
9678 as_fatal (_("internal error"));
9682 /* All percent_op's have been handled. */
9689 my_getExpression (ep, str)
9696 save_in = input_line_pointer;
9697 input_line_pointer = str;
9699 expr_end = input_line_pointer;
9700 input_line_pointer = save_in;
9702 /* If we are in mips16 mode, and this is an expression based on `.',
9703 then we bump the value of the symbol by 1 since that is how other
9704 text symbols are handled. We don't bother to handle complex
9705 expressions, just `.' plus or minus a constant. */
9706 if (mips_opts.mips16
9707 && ep->X_op == O_symbol
9708 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
9709 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
9710 && symbol_get_frag (ep->X_add_symbol) == frag_now
9711 && symbol_constant_p (ep->X_add_symbol)
9712 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
9713 S_SET_VALUE (ep->X_add_symbol, val + 1);
9716 /* Turn a string in input_line_pointer into a floating point constant
9717 of type TYPE, and store the appropriate bytes in *LITP. The number
9718 of LITTLENUMS emitted is stored in *SIZEP. An error message is
9719 returned, or NULL on OK. */
9722 md_atof (type, litP, sizeP)
9728 LITTLENUM_TYPE words[4];
9744 return _("bad call to md_atof");
9747 t = atof_ieee (input_line_pointer, type, words);
9749 input_line_pointer = t;
9753 if (! target_big_endian)
9755 for (i = prec - 1; i >= 0; i--)
9757 md_number_to_chars (litP, (valueT) words[i], 2);
9763 for (i = 0; i < prec; i++)
9765 md_number_to_chars (litP, (valueT) words[i], 2);
9774 md_number_to_chars (buf, val, n)
9779 if (target_big_endian)
9780 number_to_chars_bigendian (buf, val, n);
9782 number_to_chars_littleendian (buf, val, n);
9786 static int support_64bit_objects(void)
9788 const char **list, **l;
9790 list = bfd_target_list ();
9791 for (l = list; *l != NULL; l++)
9793 /* This is traditional mips */
9794 if (strcmp (*l, "elf64-tradbigmips") == 0
9795 || strcmp (*l, "elf64-tradlittlemips") == 0)
9797 if (strcmp (*l, "elf64-bigmips") == 0
9798 || strcmp (*l, "elf64-littlemips") == 0)
9802 return (*l != NULL);
9804 #endif /* OBJ_ELF */
9806 CONST char *md_shortopts = "nO::g::G:";
9808 struct option md_longopts[] =
9810 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
9811 {"mips0", no_argument, NULL, OPTION_MIPS1},
9812 {"mips1", no_argument, NULL, OPTION_MIPS1},
9813 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
9814 {"mips2", no_argument, NULL, OPTION_MIPS2},
9815 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
9816 {"mips3", no_argument, NULL, OPTION_MIPS3},
9817 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
9818 {"mips4", no_argument, NULL, OPTION_MIPS4},
9819 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
9820 {"mips5", no_argument, NULL, OPTION_MIPS5},
9821 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
9822 {"mips32", no_argument, NULL, OPTION_MIPS32},
9823 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
9824 {"mips64", no_argument, NULL, OPTION_MIPS64},
9825 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
9826 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
9827 #define OPTION_TRAP (OPTION_MD_BASE + 9)
9828 {"trap", no_argument, NULL, OPTION_TRAP},
9829 {"no-break", no_argument, NULL, OPTION_TRAP},
9830 #define OPTION_BREAK (OPTION_MD_BASE + 10)
9831 {"break", no_argument, NULL, OPTION_BREAK},
9832 {"no-trap", no_argument, NULL, OPTION_BREAK},
9833 #define OPTION_EB (OPTION_MD_BASE + 11)
9834 {"EB", no_argument, NULL, OPTION_EB},
9835 #define OPTION_EL (OPTION_MD_BASE + 12)
9836 {"EL", no_argument, NULL, OPTION_EL},
9837 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
9838 {"mips16", no_argument, NULL, OPTION_MIPS16},
9839 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
9840 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
9841 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
9842 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
9843 #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 16)
9844 {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX},
9845 #define OPTION_FP32 (OPTION_MD_BASE + 17)
9846 {"mfp32", no_argument, NULL, OPTION_FP32},
9847 #define OPTION_GP32 (OPTION_MD_BASE + 18)
9848 {"mgp32", no_argument, NULL, OPTION_GP32},
9849 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
9850 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
9851 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
9852 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
9853 #define OPTION_MARCH (OPTION_MD_BASE + 21)
9854 {"march", required_argument, NULL, OPTION_MARCH},
9855 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
9856 {"mtune", required_argument, NULL, OPTION_MTUNE},
9857 #define OPTION_MCPU (OPTION_MD_BASE + 23)
9858 {"mcpu", required_argument, NULL, OPTION_MCPU},
9859 #define OPTION_M4650 (OPTION_MD_BASE + 24)
9860 {"m4650", no_argument, NULL, OPTION_M4650},
9861 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
9862 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
9863 #define OPTION_M4010 (OPTION_MD_BASE + 26)
9864 {"m4010", no_argument, NULL, OPTION_M4010},
9865 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
9866 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
9867 #define OPTION_M4100 (OPTION_MD_BASE + 28)
9868 {"m4100", no_argument, NULL, OPTION_M4100},
9869 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
9870 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
9871 #define OPTION_M3900 (OPTION_MD_BASE + 30)
9872 {"m3900", no_argument, NULL, OPTION_M3900},
9873 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
9874 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
9875 #define OPTION_GP64 (OPTION_MD_BASE + 32)
9876 {"mgp64", no_argument, NULL, OPTION_GP64},
9877 #define OPTION_MIPS3D (OPTION_MD_BASE + 33)
9878 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
9879 #define OPTION_NO_MIPS3D (OPTION_MD_BASE + 34)
9880 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
9882 #define OPTION_ELF_BASE (OPTION_MD_BASE + 35)
9883 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
9884 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
9885 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
9886 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
9887 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
9888 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
9889 {"xgot", no_argument, NULL, OPTION_XGOT},
9890 #define OPTION_MABI (OPTION_ELF_BASE + 3)
9891 {"mabi", required_argument, NULL, OPTION_MABI},
9892 #define OPTION_32 (OPTION_ELF_BASE + 4)
9893 {"32", no_argument, NULL, OPTION_32},
9894 #define OPTION_N32 (OPTION_ELF_BASE + 5)
9895 {"n32", no_argument, NULL, OPTION_N32},
9896 #define OPTION_64 (OPTION_ELF_BASE + 6)
9897 {"64", no_argument, NULL, OPTION_64},
9898 #endif /* OBJ_ELF */
9899 {NULL, no_argument, NULL, 0}
9901 size_t md_longopts_size = sizeof (md_longopts);
9904 md_parse_option (c, arg)
9910 case OPTION_CONSTRUCT_FLOATS:
9911 mips_disable_float_construction = 0;
9914 case OPTION_NO_CONSTRUCT_FLOATS:
9915 mips_disable_float_construction = 1;
9927 target_big_endian = 1;
9931 target_big_endian = 0;
9939 if (arg && arg[1] == '0')
9949 mips_debug = atoi (arg);
9950 /* When the MIPS assembler sees -g or -g2, it does not do
9951 optimizations which limit full symbolic debugging. We take
9952 that to be equivalent to -O0. */
9953 if (mips_debug == 2)
9958 mips_opts.isa = ISA_MIPS1;
9962 mips_opts.isa = ISA_MIPS2;
9966 mips_opts.isa = ISA_MIPS3;
9970 mips_opts.isa = ISA_MIPS4;
9974 mips_opts.isa = ISA_MIPS5;
9978 mips_opts.isa = ISA_MIPS32;
9982 mips_opts.isa = ISA_MIPS64;
9989 int cpu = CPU_UNKNOWN;
9991 /* Identify the processor type. */
9992 if (strcasecmp (arg, "default") != 0)
9994 const struct mips_cpu_info *ci;
9996 ci = mips_cpu_info_from_name (arg);
9997 if (ci == NULL || ci->is_isa)
10002 as_fatal (_("invalid architecture -mtune=%s"), arg);
10005 as_fatal (_("invalid architecture -march=%s"), arg);
10008 as_fatal (_("invalid architecture -mcpu=%s"), arg);
10019 if (mips_tune != CPU_UNKNOWN && mips_tune != cpu)
10020 as_warn (_("A different -mtune= was already specified, is now "
10021 "-mtune=%s"), arg);
10025 if (mips_arch != CPU_UNKNOWN && mips_arch != cpu)
10026 as_warn (_("A different -march= was already specified, is now "
10027 "-march=%s"), arg);
10031 if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu)
10032 as_warn (_("A different -mcpu= was already specified, is now "
10040 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650)
10041 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650))
10042 as_warn (_("A different -march= or -mtune= was already specified, "
10044 mips_arch = CPU_R4650;
10045 mips_tune = CPU_R4650;
10048 case OPTION_NO_M4650:
10052 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010)
10053 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010))
10054 as_warn (_("A different -march= or -mtune= was already specified, "
10056 mips_arch = CPU_R4010;
10057 mips_tune = CPU_R4010;
10060 case OPTION_NO_M4010:
10064 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100)
10065 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100))
10066 as_warn (_("A different -march= or -mtune= was already specified, "
10068 mips_arch = CPU_VR4100;
10069 mips_tune = CPU_VR4100;
10072 case OPTION_NO_M4100:
10076 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900)
10077 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900))
10078 as_warn (_("A different -march= or -mtune= was already specified, "
10080 mips_arch = CPU_R3900;
10081 mips_tune = CPU_R3900;
10084 case OPTION_NO_M3900:
10087 case OPTION_MIPS16:
10088 mips_opts.mips16 = 1;
10089 mips_no_prev_insn (false);
10092 case OPTION_NO_MIPS16:
10093 mips_opts.mips16 = 0;
10094 mips_no_prev_insn (false);
10097 case OPTION_MIPS3D:
10098 mips_opts.ase_mips3d = 1;
10101 case OPTION_NO_MIPS3D:
10102 mips_opts.ase_mips3d = 0;
10105 case OPTION_MEMBEDDED_PIC:
10106 mips_pic = EMBEDDED_PIC;
10107 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
10109 as_bad (_("-G may not be used with embedded PIC code"));
10112 g_switch_value = 0x7fffffff;
10116 /* When generating ELF code, we permit -KPIC and -call_shared to
10117 select SVR4_PIC, and -non_shared to select no PIC. This is
10118 intended to be compatible with Irix 5. */
10119 case OPTION_CALL_SHARED:
10120 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10122 as_bad (_("-call_shared is supported only for ELF format"));
10125 mips_pic = SVR4_PIC;
10126 if (g_switch_seen && g_switch_value != 0)
10128 as_bad (_("-G may not be used with SVR4 PIC code"));
10131 g_switch_value = 0;
10134 case OPTION_NON_SHARED:
10135 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10137 as_bad (_("-non_shared is supported only for ELF format"));
10143 /* The -xgot option tells the assembler to use 32 offsets when
10144 accessing the got in SVR4_PIC mode. It is for Irix
10149 #endif /* OBJ_ELF */
10152 if (! USE_GLOBAL_POINTER_OPT)
10154 as_bad (_("-G is not supported for this configuration"));
10157 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10159 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10163 g_switch_value = atoi (arg);
10168 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10171 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10173 as_bad (_("-32 is supported for ELF format only"));
10176 mips_opts.abi = O32_ABI;
10180 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10182 as_bad (_("-n32 is supported for ELF format only"));
10185 mips_opts.abi = N32_ABI;
10189 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10191 as_bad (_("-64 is supported for ELF format only"));
10194 mips_opts.abi = N64_ABI;
10195 if (! support_64bit_objects())
10196 as_fatal (_("No compiled in support for 64 bit object file format"));
10198 #endif /* OBJ_ELF */
10201 file_mips_gp32 = 1;
10202 if (mips_opts.abi != O32_ABI)
10203 mips_opts.abi = NO_ABI;
10207 file_mips_gp32 = 0;
10208 if (mips_opts.abi == O32_ABI)
10209 mips_opts.abi = NO_ABI;
10213 file_mips_fp32 = 1;
10214 if (mips_opts.abi != O32_ABI)
10215 mips_opts.abi = NO_ABI;
10220 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10222 as_bad (_("-mabi is supported for ELF format only"));
10225 if (strcmp (arg, "32") == 0)
10226 mips_opts.abi = O32_ABI;
10227 else if (strcmp (arg, "o64") == 0)
10228 mips_opts.abi = O64_ABI;
10229 else if (strcmp (arg, "n32") == 0)
10230 mips_opts.abi = N32_ABI;
10231 else if (strcmp (arg, "64") == 0)
10233 mips_opts.abi = N64_ABI;
10234 if (! support_64bit_objects())
10235 as_fatal (_("No compiled in support for 64 bit object file "
10238 else if (strcmp (arg, "eabi") == 0)
10239 mips_opts.abi = EABI_ABI;
10242 as_fatal (_("invalid abi -mabi=%s"), arg);
10246 #endif /* OBJ_ELF */
10248 case OPTION_M7000_HILO_FIX:
10249 mips_7000_hilo_fix = true;
10252 case OPTION_NO_M7000_HILO_FIX:
10253 mips_7000_hilo_fix = false;
10264 show (stream, string, col_p, first_p)
10272 fprintf (stream, "%24s", "");
10277 fprintf (stream, ", ");
10281 if (*col_p + strlen (string) > 72)
10283 fprintf (stream, "\n%24s", "");
10287 fprintf (stream, "%s", string);
10288 *col_p += strlen (string);
10294 md_show_usage (stream)
10299 fprintf (stream, _("\
10301 -membedded-pic generate embedded position independent code\n\
10302 -EB generate big endian output\n\
10303 -EL generate little endian output\n\
10304 -g, -g2 do not remove unneeded NOPs or swap branches\n\
10305 -G NUM allow referencing objects up to NUM bytes\n\
10306 implicitly with the gp register [default 8]\n"));
10307 fprintf (stream, _("\
10308 -mips1 generate MIPS ISA I instructions\n\
10309 -mips2 generate MIPS ISA II instructions\n\
10310 -mips3 generate MIPS ISA III instructions\n\
10311 -mips4 generate MIPS ISA IV instructions\n\
10312 -mips5 generate MIPS ISA V instructions\n\
10313 -mips32 generate MIPS32 ISA instructions\n\
10314 -mips64 generate MIPS64 ISA instructions\n\
10315 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
10319 show (stream, "2000", &column, &first);
10320 show (stream, "3000", &column, &first);
10321 show (stream, "3900", &column, &first);
10322 show (stream, "4000", &column, &first);
10323 show (stream, "4010", &column, &first);
10324 show (stream, "4100", &column, &first);
10325 show (stream, "4111", &column, &first);
10326 show (stream, "4300", &column, &first);
10327 show (stream, "4400", &column, &first);
10328 show (stream, "4600", &column, &first);
10329 show (stream, "4650", &column, &first);
10330 show (stream, "5000", &column, &first);
10331 show (stream, "5200", &column, &first);
10332 show (stream, "5230", &column, &first);
10333 show (stream, "5231", &column, &first);
10334 show (stream, "5261", &column, &first);
10335 show (stream, "5721", &column, &first);
10336 show (stream, "6000", &column, &first);
10337 show (stream, "8000", &column, &first);
10338 show (stream, "10000", &column, &first);
10339 show (stream, "12000", &column, &first);
10340 show (stream, "sb1", &column, &first);
10341 fputc ('\n', stream);
10343 fprintf (stream, _("\
10344 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
10345 -no-mCPU don't generate code specific to CPU.\n\
10346 For -mCPU and -no-mCPU, CPU must be one of:\n"));
10350 show (stream, "3900", &column, &first);
10351 show (stream, "4010", &column, &first);
10352 show (stream, "4100", &column, &first);
10353 show (stream, "4650", &column, &first);
10354 fputc ('\n', stream);
10356 fprintf (stream, _("\
10357 -mips16 generate mips16 instructions\n\
10358 -no-mips16 do not generate mips16 instructions\n"));
10359 fprintf (stream, _("\
10360 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
10361 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
10362 -O0 remove unneeded NOPs, do not swap branches\n\
10363 -O remove unneeded NOPs and swap branches\n\
10364 -n warn about NOPs generated from macros\n\
10365 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
10366 --trap, --no-break trap exception on div by 0 and mult overflow\n\
10367 --break, --no-trap break exception on div by 0 and mult overflow\n"));
10369 fprintf (stream, _("\
10370 -KPIC, -call_shared generate SVR4 position independent code\n\
10371 -non_shared do not generate position independent code\n\
10372 -xgot assume a 32 bit GOT\n\
10373 -mabi=ABI create ABI conformant object file for:\n"));
10377 show (stream, "32", &column, &first);
10378 show (stream, "o64", &column, &first);
10379 show (stream, "n32", &column, &first);
10380 show (stream, "64", &column, &first);
10381 show (stream, "eabi", &column, &first);
10383 fputc ('\n', stream);
10385 fprintf (stream, _("\
10386 -32 create o32 ABI object file (default)\n\
10387 -n32 create n32 ABI object file\n\
10388 -64 create 64 ABI object file\n"));
10393 mips_init_after_args ()
10395 /* initialize opcodes */
10396 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10397 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10401 md_pcrel_from (fixP)
10404 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
10405 && fixP->fx_addsy != (symbolS *) NULL
10406 && ! S_IS_DEFINED (fixP->fx_addsy))
10408 /* This makes a branch to an undefined symbol be a branch to the
10409 current location. */
10410 if (mips_pic == EMBEDDED_PIC)
10416 /* Return the address of the delay slot. */
10417 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
10420 /* This is called before the symbol table is processed. In order to
10421 work with gcc when using mips-tfile, we must keep all local labels.
10422 However, in other cases, we want to discard them. If we were
10423 called with -g, but we didn't see any debugging information, it may
10424 mean that gcc is smuggling debugging information through to
10425 mips-tfile, in which case we must generate all local labels. */
10428 mips_frob_file_before_adjust ()
10430 #ifndef NO_ECOFF_DEBUGGING
10431 if (ECOFF_DEBUGGING
10433 && ! ecoff_debugging_seen)
10434 flag_keep_locals = 1;
10438 /* Sort any unmatched HI16_S relocs so that they immediately precede
10439 the corresponding LO reloc. This is called before md_apply_fix3 and
10440 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10441 explicit use of the %hi modifier. */
10446 struct mips_hi_fixup *l;
10448 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
10450 segment_info_type *seginfo;
10453 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
10455 /* Check quickly whether the next fixup happens to be a matching
10457 if (l->fixp->fx_next != NULL
10458 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
10459 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
10460 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
10463 /* Look through the fixups for this segment for a matching %lo.
10464 When we find one, move the %hi just in front of it. We do
10465 this in two passes. In the first pass, we try to find a
10466 unique %lo. In the second pass, we permit multiple %hi
10467 relocs for a single %lo (this is a GNU extension). */
10468 seginfo = seg_info (l->seg);
10469 for (pass = 0; pass < 2; pass++)
10474 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
10476 /* Check whether this is a %lo fixup which matches l->fixp. */
10477 if (f->fx_r_type == BFD_RELOC_LO16
10478 && f->fx_addsy == l->fixp->fx_addsy
10479 && f->fx_offset == l->fixp->fx_offset
10482 || prev->fx_r_type != BFD_RELOC_HI16_S
10483 || prev->fx_addsy != f->fx_addsy
10484 || prev->fx_offset != f->fx_offset))
10488 /* Move l->fixp before f. */
10489 for (pf = &seginfo->fix_root;
10491 pf = &(*pf)->fx_next)
10492 assert (*pf != NULL);
10494 *pf = l->fixp->fx_next;
10496 l->fixp->fx_next = f;
10498 seginfo->fix_root = l->fixp;
10500 prev->fx_next = l->fixp;
10511 #if 0 /* GCC code motion plus incomplete dead code elimination
10512 can leave a %hi without a %lo. */
10514 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
10515 _("Unmatched %%hi reloc"));
10521 /* When generating embedded PIC code we need to use a special
10522 relocation to represent the difference of two symbols in the .text
10523 section (switch tables use a difference of this sort). See
10524 include/coff/mips.h for details. This macro checks whether this
10525 fixup requires the special reloc. */
10526 #define SWITCH_TABLE(fixp) \
10527 ((fixp)->fx_r_type == BFD_RELOC_32 \
10528 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10529 && (fixp)->fx_addsy != NULL \
10530 && (fixp)->fx_subsy != NULL \
10531 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10532 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10534 /* When generating embedded PIC code we must keep all PC relative
10535 relocations, in case the linker has to relax a call. We also need
10536 to keep relocations for switch table entries.
10538 We may have combined relocations without symbols in the N32/N64 ABI.
10539 We have to prevent gas from dropping them. */
10542 mips_force_relocation (fixp)
10545 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10546 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
10550 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
10551 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
10552 || fixp->fx_r_type == BFD_RELOC_HI16_S
10553 || fixp->fx_r_type == BFD_RELOC_LO16))
10556 return (mips_pic == EMBEDDED_PIC
10558 || SWITCH_TABLE (fixp)
10559 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
10560 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
10565 mips_need_elf_addend_fixup (fixP)
10568 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
10570 if (mips_pic == EMBEDDED_PIC
10571 && S_IS_WEAK (fixP->fx_addsy))
10573 if (mips_pic != EMBEDDED_PIC
10574 && (S_IS_WEAK (fixP->fx_addsy)
10575 || S_IS_EXTERN (fixP->fx_addsy))
10576 && !S_IS_COMMON (fixP->fx_addsy))
10578 if (symbol_used_in_reloc_p (fixP->fx_addsy)
10579 && (((bfd_get_section_flags (stdoutput,
10580 S_GET_SEGMENT (fixP->fx_addsy))
10581 & SEC_LINK_ONCE) != 0)
10582 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
10584 sizeof (".gnu.linkonce") - 1)))
10590 /* Apply a fixup to the object file. */
10593 md_apply_fix3 (fixP, valP, seg)
10596 segT seg ATTRIBUTE_UNUSED;
10602 assert (fixP->fx_size == 4
10603 || fixP->fx_r_type == BFD_RELOC_16
10604 || fixP->fx_r_type == BFD_RELOC_32
10605 || fixP->fx_r_type == BFD_RELOC_MIPS_JMP
10606 || fixP->fx_r_type == BFD_RELOC_HI16_S
10607 || fixP->fx_r_type == BFD_RELOC_LO16
10608 || fixP->fx_r_type == BFD_RELOC_GPREL16
10609 || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL
10610 || fixP->fx_r_type == BFD_RELOC_GPREL32
10611 || fixP->fx_r_type == BFD_RELOC_64
10612 || fixP->fx_r_type == BFD_RELOC_CTOR
10613 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
10614 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST
10615 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER
10616 || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP
10617 || fixP->fx_r_type == BFD_RELOC_MIPS_REL16
10618 || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT
10619 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10620 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
10624 /* If we aren't adjusting this fixup to be against the section
10625 symbol, we need to adjust the value. */
10627 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
10629 if (mips_need_elf_addend_fixup (fixP))
10631 valueT symval = S_GET_VALUE (fixP->fx_addsy);
10634 if (value != 0 && ! fixP->fx_pcrel)
10636 /* In this case, the bfd_install_relocation routine will
10637 incorrectly add the symbol value back in. We just want
10638 the addend to appear in the object file. */
10641 /* Make sure the addend is still non-zero. If it became zero
10642 after the last operation, set it to a spurious value and
10643 subtract the same value from the object file's contents. */
10648 /* The in-place addends for LO16 relocations are signed;
10649 leave the matching HI16 in-place addends as zero. */
10650 if (fixP->fx_r_type != BFD_RELOC_HI16_S)
10652 reloc_howto_type *howto;
10653 bfd_vma contents, mask, field;
10655 howto = bfd_reloc_type_lookup (stdoutput,
10658 contents = bfd_get_bits (fixP->fx_frag->fr_literal
10661 target_big_endian);
10663 /* MASK has bits set where the relocation should go.
10664 FIELD is -value, shifted into the appropriate place
10665 for this relocation. */
10666 mask = 1 << (howto->bitsize - 1);
10667 mask = (((mask - 1) << 1) | 1) << howto->bitpos;
10668 field = (-value >> howto->rightshift) << howto->bitpos;
10670 bfd_put_bits ((field & mask) | (contents & ~mask),
10671 fixP->fx_frag->fr_literal + fixP->fx_where,
10673 target_big_endian);
10679 /* This code was generated using trial and error and so is
10680 fragile and not trustworthy. If you change it, you should
10681 rerun the elf-rel, elf-rel2, and empic testcases and ensure
10682 they still pass. */
10683 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
10685 value += fixP->fx_frag->fr_address + fixP->fx_where;
10687 /* BFD's REL handling, for MIPS, is _very_ weird.
10688 This gives the right results, but it can't possibly
10689 be the way things are supposed to work. */
10690 if ((fixP->fx_r_type != BFD_RELOC_16_PCREL
10691 && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
10692 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
10693 value += fixP->fx_frag->fr_address + fixP->fx_where;
10698 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */
10700 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
10703 switch (fixP->fx_r_type)
10705 case BFD_RELOC_MIPS_JMP:
10706 case BFD_RELOC_MIPS_SHIFT5:
10707 case BFD_RELOC_MIPS_SHIFT6:
10708 case BFD_RELOC_MIPS_GOT_DISP:
10709 case BFD_RELOC_MIPS_GOT_PAGE:
10710 case BFD_RELOC_MIPS_GOT_OFST:
10711 case BFD_RELOC_MIPS_SUB:
10712 case BFD_RELOC_MIPS_INSERT_A:
10713 case BFD_RELOC_MIPS_INSERT_B:
10714 case BFD_RELOC_MIPS_DELETE:
10715 case BFD_RELOC_MIPS_HIGHEST:
10716 case BFD_RELOC_MIPS_HIGHER:
10717 case BFD_RELOC_MIPS_SCN_DISP:
10718 case BFD_RELOC_MIPS_REL16:
10719 case BFD_RELOC_MIPS_RELGOT:
10720 case BFD_RELOC_MIPS_JALR:
10721 case BFD_RELOC_HI16:
10722 case BFD_RELOC_HI16_S:
10723 case BFD_RELOC_GPREL16:
10724 case BFD_RELOC_MIPS_LITERAL:
10725 case BFD_RELOC_MIPS_CALL16:
10726 case BFD_RELOC_MIPS_GOT16:
10727 case BFD_RELOC_GPREL32:
10728 case BFD_RELOC_MIPS_GOT_HI16:
10729 case BFD_RELOC_MIPS_GOT_LO16:
10730 case BFD_RELOC_MIPS_CALL_HI16:
10731 case BFD_RELOC_MIPS_CALL_LO16:
10732 case BFD_RELOC_MIPS16_GPREL:
10733 if (fixP->fx_pcrel)
10734 as_bad_where (fixP->fx_file, fixP->fx_line,
10735 _("Invalid PC relative reloc"));
10736 /* Nothing needed to do. The value comes from the reloc entry */
10739 case BFD_RELOC_MIPS16_JMP:
10740 /* We currently always generate a reloc against a symbol, which
10741 means that we don't want an addend even if the symbol is
10743 fixP->fx_addnumber = 0;
10746 case BFD_RELOC_PCREL_HI16_S:
10747 /* The addend for this is tricky if it is internal, so we just
10748 do everything here rather than in bfd_install_relocation. */
10749 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10754 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10756 /* For an external symbol adjust by the address to make it
10757 pcrel_offset. We use the address of the RELLO reloc
10758 which follows this one. */
10759 value += (fixP->fx_next->fx_frag->fr_address
10760 + fixP->fx_next->fx_where);
10762 value = ((value + 0x8000) >> 16) & 0xffff;
10763 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10764 if (target_big_endian)
10766 md_number_to_chars ((char *) buf, value, 2);
10769 case BFD_RELOC_PCREL_LO16:
10770 /* The addend for this is tricky if it is internal, so we just
10771 do everything here rather than in bfd_install_relocation. */
10772 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10777 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10778 value += fixP->fx_frag->fr_address + fixP->fx_where;
10779 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10780 if (target_big_endian)
10782 md_number_to_chars ((char *) buf, value, 2);
10786 /* This is handled like BFD_RELOC_32, but we output a sign
10787 extended value if we are only 32 bits. */
10789 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10791 if (8 <= sizeof (valueT))
10792 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10799 w1 = w2 = fixP->fx_where;
10800 if (target_big_endian)
10804 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
10805 if ((value & 0x80000000) != 0)
10809 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
10814 case BFD_RELOC_RVA:
10816 /* If we are deleting this reloc entry, we must fill in the
10817 value now. This can happen if we have a .word which is not
10818 resolved when it appears but is later defined. We also need
10819 to fill in the value if this is an embedded PIC switch table
10822 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10823 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10828 /* If we are deleting this reloc entry, we must fill in the
10830 assert (fixP->fx_size == 2);
10832 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10836 case BFD_RELOC_LO16:
10837 /* When handling an embedded PIC switch statement, we can wind
10838 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
10841 if (value + 0x8000 > 0xffff)
10842 as_bad_where (fixP->fx_file, fixP->fx_line,
10843 _("relocation overflow"));
10844 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10845 if (target_big_endian)
10847 md_number_to_chars ((char *) buf, value, 2);
10851 case BFD_RELOC_16_PCREL_S2:
10852 if ((value & 0x3) != 0)
10853 as_bad_where (fixP->fx_file, fixP->fx_line,
10854 _("Branch to odd address (%lx)"), (long) value);
10856 /* Fall through. */
10858 case BFD_RELOC_16_PCREL:
10860 * We need to save the bits in the instruction since fixup_segment()
10861 * might be deleting the relocation entry (i.e., a branch within
10862 * the current segment).
10864 if (!fixP->fx_done && value != 0)
10866 /* If 'value' is zero, the remaining reloc code won't actually
10867 do the store, so it must be done here. This is probably
10868 a bug somewhere. */
10870 && (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
10871 || fixP->fx_addsy == NULL /* ??? */
10872 || ! S_IS_DEFINED (fixP->fx_addsy)))
10873 value -= fixP->fx_frag->fr_address + fixP->fx_where;
10875 value = (offsetT) value >> 2;
10877 /* update old instruction data */
10878 buf = (bfd_byte *) (fixP->fx_where + fixP->fx_frag->fr_literal);
10879 if (target_big_endian)
10880 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
10882 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
10884 if (value + 0x8000 <= 0xffff)
10885 insn |= value & 0xffff;
10888 /* The branch offset is too large. If this is an
10889 unconditional branch, and we are not generating PIC code,
10890 we can convert it to an absolute jump instruction. */
10891 if (mips_pic == NO_PIC
10893 && fixP->fx_frag->fr_address >= text_section->vma
10894 && (fixP->fx_frag->fr_address
10895 < text_section->vma + text_section->_raw_size)
10896 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
10897 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
10898 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
10900 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
10901 insn = 0x0c000000; /* jal */
10903 insn = 0x08000000; /* j */
10904 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
10906 fixP->fx_addsy = section_symbol (text_section);
10907 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
10911 /* FIXME. It would be possible in principle to handle
10912 conditional branches which overflow. They could be
10913 transformed into a branch around a jump. This would
10914 require setting up variant frags for each different
10915 branch type. The native MIPS assembler attempts to
10916 handle these cases, but it appears to do it
10918 as_bad_where (fixP->fx_file, fixP->fx_line,
10919 _("Branch out of range"));
10923 md_number_to_chars ((char *) buf, (valueT) insn, 4);
10926 case BFD_RELOC_VTABLE_INHERIT:
10929 && !S_IS_DEFINED (fixP->fx_addsy)
10930 && !S_IS_WEAK (fixP->fx_addsy))
10931 S_SET_WEAK (fixP->fx_addsy);
10934 case BFD_RELOC_VTABLE_ENTRY:
10948 const struct mips_opcode *p;
10949 int treg, sreg, dreg, shamt;
10954 for (i = 0; i < NUMOPCODES; ++i)
10956 p = &mips_opcodes[i];
10957 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
10959 printf ("%08lx %s\t", oc, p->name);
10960 treg = (oc >> 16) & 0x1f;
10961 sreg = (oc >> 21) & 0x1f;
10962 dreg = (oc >> 11) & 0x1f;
10963 shamt = (oc >> 6) & 0x1f;
10965 for (args = p->args;; ++args)
10976 printf ("%c", *args);
10980 assert (treg == sreg);
10981 printf ("$%d,$%d", treg, sreg);
10986 printf ("$%d", dreg);
10991 printf ("$%d", treg);
10995 printf ("0x%x", treg);
11000 printf ("$%d", sreg);
11004 printf ("0x%08lx", oc & 0x1ffffff);
11011 printf ("%d", imm);
11016 printf ("$%d", shamt);
11027 printf (_("%08lx UNDEFINED\n"), oc);
11038 name = input_line_pointer;
11039 c = get_symbol_end ();
11040 p = (symbolS *) symbol_find_or_make (name);
11041 *input_line_pointer = c;
11045 /* Align the current frag to a given power of two. The MIPS assembler
11046 also automatically adjusts any preceding label. */
11049 mips_align (to, fill, label)
11054 mips_emit_delays (false);
11055 frag_align (to, fill, 0);
11056 record_alignment (now_seg, to);
11059 assert (S_GET_SEGMENT (label) == now_seg);
11060 symbol_set_frag (label, frag_now);
11061 S_SET_VALUE (label, (valueT) frag_now_fix ());
11065 /* Align to a given power of two. .align 0 turns off the automatic
11066 alignment used by the data creating pseudo-ops. */
11070 int x ATTRIBUTE_UNUSED;
11073 register long temp_fill;
11074 long max_alignment = 15;
11078 o Note that the assembler pulls down any immediately preceeding label
11079 to the aligned address.
11080 o It's not documented but auto alignment is reinstated by
11081 a .align pseudo instruction.
11082 o Note also that after auto alignment is turned off the mips assembler
11083 issues an error on attempt to assemble an improperly aligned data item.
11088 temp = get_absolute_expression ();
11089 if (temp > max_alignment)
11090 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11093 as_warn (_("Alignment negative: 0 assumed."));
11096 if (*input_line_pointer == ',')
11098 ++input_line_pointer;
11099 temp_fill = get_absolute_expression ();
11106 mips_align (temp, (int) temp_fill,
11107 insn_labels != NULL ? insn_labels->label : NULL);
11114 demand_empty_rest_of_line ();
11118 mips_flush_pending_output ()
11120 mips_emit_delays (false);
11121 mips_clear_insn_labels ();
11130 /* When generating embedded PIC code, we only use the .text, .lit8,
11131 .sdata and .sbss sections. We change the .data and .rdata
11132 pseudo-ops to use .sdata. */
11133 if (mips_pic == EMBEDDED_PIC
11134 && (sec == 'd' || sec == 'r'))
11138 /* The ELF backend needs to know that we are changing sections, so
11139 that .previous works correctly. We could do something like check
11140 for an obj_section_change_hook macro, but that might be confusing
11141 as it would not be appropriate to use it in the section changing
11142 functions in read.c, since obj-elf.c intercepts those. FIXME:
11143 This should be cleaner, somehow. */
11144 obj_elf_section_change_hook ();
11147 mips_emit_delays (false);
11157 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11158 demand_empty_rest_of_line ();
11162 if (USE_GLOBAL_POINTER_OPT)
11164 seg = subseg_new (RDATA_SECTION_NAME,
11165 (subsegT) get_absolute_expression ());
11166 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11168 bfd_set_section_flags (stdoutput, seg,
11174 if (strcmp (TARGET_OS, "elf") != 0)
11175 record_alignment (seg, 4);
11177 demand_empty_rest_of_line ();
11181 as_bad (_("No read only data section in this object file format"));
11182 demand_empty_rest_of_line ();
11188 if (USE_GLOBAL_POINTER_OPT)
11190 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11191 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11193 bfd_set_section_flags (stdoutput, seg,
11194 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11196 if (strcmp (TARGET_OS, "elf") != 0)
11197 record_alignment (seg, 4);
11199 demand_empty_rest_of_line ();
11204 as_bad (_("Global pointers not supported; recompile -G 0"));
11205 demand_empty_rest_of_line ();
11214 mips_enable_auto_align ()
11225 label = insn_labels != NULL ? insn_labels->label : NULL;
11226 mips_emit_delays (false);
11227 if (log_size > 0 && auto_align)
11228 mips_align (log_size, 0, label);
11229 mips_clear_insn_labels ();
11230 cons (1 << log_size);
11234 s_float_cons (type)
11239 label = insn_labels != NULL ? insn_labels->label : NULL;
11241 mips_emit_delays (false);
11246 mips_align (3, 0, label);
11248 mips_align (2, 0, label);
11251 mips_clear_insn_labels ();
11256 /* Handle .globl. We need to override it because on Irix 5 you are
11259 where foo is an undefined symbol, to mean that foo should be
11260 considered to be the address of a function. */
11264 int x ATTRIBUTE_UNUSED;
11271 name = input_line_pointer;
11272 c = get_symbol_end ();
11273 symbolP = symbol_find_or_make (name);
11274 *input_line_pointer = c;
11275 SKIP_WHITESPACE ();
11277 /* On Irix 5, every global symbol that is not explicitly labelled as
11278 being a function is apparently labelled as being an object. */
11281 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11286 secname = input_line_pointer;
11287 c = get_symbol_end ();
11288 sec = bfd_get_section_by_name (stdoutput, secname);
11290 as_bad (_("%s: no such section"), secname);
11291 *input_line_pointer = c;
11293 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11294 flag = BSF_FUNCTION;
11297 symbol_get_bfdsym (symbolP)->flags |= flag;
11299 S_SET_EXTERNAL (symbolP);
11300 demand_empty_rest_of_line ();
11305 int x ATTRIBUTE_UNUSED;
11310 opt = input_line_pointer;
11311 c = get_symbol_end ();
11315 /* FIXME: What does this mean? */
11317 else if (strncmp (opt, "pic", 3) == 0)
11321 i = atoi (opt + 3);
11325 mips_pic = SVR4_PIC;
11327 as_bad (_(".option pic%d not supported"), i);
11329 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
11331 if (g_switch_seen && g_switch_value != 0)
11332 as_warn (_("-G may not be used with SVR4 PIC code"));
11333 g_switch_value = 0;
11334 bfd_set_gp_size (stdoutput, 0);
11338 as_warn (_("Unrecognized option \"%s\""), opt);
11340 *input_line_pointer = c;
11341 demand_empty_rest_of_line ();
11344 /* This structure is used to hold a stack of .set values. */
11346 struct mips_option_stack
11348 struct mips_option_stack *next;
11349 struct mips_set_options options;
11352 static struct mips_option_stack *mips_opts_stack;
11354 /* Handle the .set pseudo-op. */
11358 int x ATTRIBUTE_UNUSED;
11360 char *name = input_line_pointer, ch;
11362 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11363 ++input_line_pointer;
11364 ch = *input_line_pointer;
11365 *input_line_pointer = '\0';
11367 if (strcmp (name, "reorder") == 0)
11369 if (mips_opts.noreorder && prev_nop_frag != NULL)
11371 /* If we still have pending nops, we can discard them. The
11372 usual nop handling will insert any that are still
11374 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11375 * (mips_opts.mips16 ? 2 : 4));
11376 prev_nop_frag = NULL;
11378 mips_opts.noreorder = 0;
11380 else if (strcmp (name, "noreorder") == 0)
11382 mips_emit_delays (true);
11383 mips_opts.noreorder = 1;
11384 mips_any_noreorder = 1;
11386 else if (strcmp (name, "at") == 0)
11388 mips_opts.noat = 0;
11390 else if (strcmp (name, "noat") == 0)
11392 mips_opts.noat = 1;
11394 else if (strcmp (name, "macro") == 0)
11396 mips_opts.warn_about_macros = 0;
11398 else if (strcmp (name, "nomacro") == 0)
11400 if (mips_opts.noreorder == 0)
11401 as_bad (_("`noreorder' must be set before `nomacro'"));
11402 mips_opts.warn_about_macros = 1;
11404 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11406 mips_opts.nomove = 0;
11408 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11410 mips_opts.nomove = 1;
11412 else if (strcmp (name, "bopt") == 0)
11414 mips_opts.nobopt = 0;
11416 else if (strcmp (name, "nobopt") == 0)
11418 mips_opts.nobopt = 1;
11420 else if (strcmp (name, "mips16") == 0
11421 || strcmp (name, "MIPS-16") == 0)
11422 mips_opts.mips16 = 1;
11423 else if (strcmp (name, "nomips16") == 0
11424 || strcmp (name, "noMIPS-16") == 0)
11425 mips_opts.mips16 = 0;
11426 else if (strcmp (name, "mips3d") == 0)
11427 mips_opts.ase_mips3d = 1;
11428 else if (strcmp (name, "nomips3d") == 0)
11429 mips_opts.ase_mips3d = 0;
11430 else if (strncmp (name, "mips", 4) == 0)
11434 /* Permit the user to change the ISA on the fly. Needless to
11435 say, misuse can cause serious problems. */
11436 isa = atoi (name + 4);
11440 mips_opts.gp32 = file_mips_gp32;
11441 mips_opts.fp32 = file_mips_fp32;
11442 mips_opts.abi = file_mips_abi;
11447 mips_opts.gp32 = 1;
11448 mips_opts.fp32 = 1;
11454 /* Loosen ABI register width restriction. */
11455 if (mips_opts.abi == O32_ABI)
11456 mips_opts.abi = NO_ABI;
11457 mips_opts.gp32 = 0;
11458 mips_opts.fp32 = 0;
11461 as_bad (_("unknown ISA level %s"), name + 4);
11467 case 0: mips_opts.isa = file_mips_isa; break;
11468 case 1: mips_opts.isa = ISA_MIPS1; break;
11469 case 2: mips_opts.isa = ISA_MIPS2; break;
11470 case 3: mips_opts.isa = ISA_MIPS3; break;
11471 case 4: mips_opts.isa = ISA_MIPS4; break;
11472 case 5: mips_opts.isa = ISA_MIPS5; break;
11473 case 32: mips_opts.isa = ISA_MIPS32; break;
11474 case 64: mips_opts.isa = ISA_MIPS64; break;
11475 default: as_bad (_("unknown ISA level %s"), name + 4); break;
11478 else if (strcmp (name, "autoextend") == 0)
11479 mips_opts.noautoextend = 0;
11480 else if (strcmp (name, "noautoextend") == 0)
11481 mips_opts.noautoextend = 1;
11482 else if (strcmp (name, "push") == 0)
11484 struct mips_option_stack *s;
11486 s = (struct mips_option_stack *) xmalloc (sizeof *s);
11487 s->next = mips_opts_stack;
11488 s->options = mips_opts;
11489 mips_opts_stack = s;
11491 else if (strcmp (name, "pop") == 0)
11493 struct mips_option_stack *s;
11495 s = mips_opts_stack;
11497 as_bad (_(".set pop with no .set push"));
11500 /* If we're changing the reorder mode we need to handle
11501 delay slots correctly. */
11502 if (s->options.noreorder && ! mips_opts.noreorder)
11503 mips_emit_delays (true);
11504 else if (! s->options.noreorder && mips_opts.noreorder)
11506 if (prev_nop_frag != NULL)
11508 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11509 * (mips_opts.mips16 ? 2 : 4));
11510 prev_nop_frag = NULL;
11514 mips_opts = s->options;
11515 mips_opts_stack = s->next;
11521 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
11523 *input_line_pointer = ch;
11524 demand_empty_rest_of_line ();
11527 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11528 .option pic2. It means to generate SVR4 PIC calls. */
11531 s_abicalls (ignore)
11532 int ignore ATTRIBUTE_UNUSED;
11534 mips_pic = SVR4_PIC;
11535 if (USE_GLOBAL_POINTER_OPT)
11537 if (g_switch_seen && g_switch_value != 0)
11538 as_warn (_("-G may not be used with SVR4 PIC code"));
11539 g_switch_value = 0;
11541 bfd_set_gp_size (stdoutput, 0);
11542 demand_empty_rest_of_line ();
11545 /* Handle the .cpload pseudo-op. This is used when generating SVR4
11546 PIC code. It sets the $gp register for the function based on the
11547 function address, which is in the register named in the argument.
11548 This uses a relocation against _gp_disp, which is handled specially
11549 by the linker. The result is:
11550 lui $gp,%hi(_gp_disp)
11551 addiu $gp,$gp,%lo(_gp_disp)
11552 addu $gp,$gp,.cpload argument
11553 The .cpload argument is normally $25 == $t9. */
11557 int ignore ATTRIBUTE_UNUSED;
11562 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11563 .cpload is ignored. */
11564 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11570 /* .cpload should be in a .set noreorder section. */
11571 if (mips_opts.noreorder == 0)
11572 as_warn (_(".cpload not in noreorder section"));
11574 ex.X_op = O_symbol;
11575 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
11576 ex.X_op_symbol = NULL;
11577 ex.X_add_number = 0;
11579 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
11580 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
11582 macro_build_lui (NULL, &icnt, &ex, mips_gp_register);
11583 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j",
11584 mips_gp_register, mips_gp_register, (int) BFD_RELOC_LO16);
11586 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
11587 mips_gp_register, mips_gp_register, tc_get_register (0));
11589 demand_empty_rest_of_line ();
11592 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
11593 .cpsetup $reg1, offset|$reg2, label
11595 If offset is given, this results in:
11596 sd $gp, offset($sp)
11597 lui $gp, %hi(%neg(%gp_rel(label)))
11598 daddiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11599 addu $gp, $gp, $reg1
11601 If $reg2 is given, this results in:
11602 daddu $reg2, $gp, $0
11603 lui $gp, %hi(%neg(%gp_rel(label)))
11604 daddiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11605 addu $gp, $gp, $reg1
11609 int ignore ATTRIBUTE_UNUSED;
11611 expressionS ex_off;
11612 expressionS ex_sym;
11617 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
11618 We also need NewABI support. */
11619 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11625 reg1 = tc_get_register (0);
11626 SKIP_WHITESPACE ();
11627 if (*input_line_pointer != ',')
11629 as_bad (_("missing argument separator ',' for .cpsetup"));
11633 input_line_pointer++;
11634 SKIP_WHITESPACE ();
11635 if (*input_line_pointer == '$')
11636 mips_cpreturn_register = tc_get_register (0);
11638 mips_cpreturn_offset = get_absolute_expression ();
11639 SKIP_WHITESPACE ();
11640 if (*input_line_pointer != ',')
11642 as_bad (_("missing argument separator ',' for .cpsetup"));
11646 ++input_line_pointer;
11647 SKIP_WHITESPACE ();
11648 sym = input_line_pointer;
11649 while (ISALNUM (*input_line_pointer))
11650 ++input_line_pointer;
11651 *input_line_pointer = 0;
11653 ex_sym.X_op = O_symbol;
11654 ex_sym.X_add_symbol = symbol_find_or_make (sym);
11655 ex_sym.X_op_symbol = NULL;
11656 ex_sym.X_add_number = 0;
11658 if (mips_cpreturn_register == -1)
11660 ex_off.X_op = O_constant;
11661 ex_off.X_add_symbol = NULL;
11662 ex_off.X_op_symbol = NULL;
11663 ex_off.X_add_number = mips_cpreturn_offset;
11665 macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)",
11666 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11669 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11670 "d,v,t", mips_cpreturn_register, mips_gp_register, 0);
11672 macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
11673 (int) BFD_RELOC_GPREL16);
11674 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11675 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_HI16_S);
11676 macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j",
11677 mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16);
11678 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11679 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_LO16);
11680 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11681 HAVE_64BIT_ADDRESSES ? "daddu" : "addu", "d,v,t",
11682 mips_gp_register, mips_gp_register, reg1);
11684 demand_empty_rest_of_line ();
11689 int ignore ATTRIBUTE_UNUSED;
11691 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
11692 .cplocal is ignored. */
11693 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11699 mips_gp_register = tc_get_register (0);
11702 /* Handle the .cprestore pseudo-op. This stores $gp into a given
11703 offset from $sp. The offset is remembered, and after making a PIC
11704 call $gp is restored from that location. */
11707 s_cprestore (ignore)
11708 int ignore ATTRIBUTE_UNUSED;
11713 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11714 .cprestore is ignored. */
11715 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11721 mips_cprestore_offset = get_absolute_expression ();
11722 mips_cprestore_valid = 1;
11724 ex.X_op = O_constant;
11725 ex.X_add_symbol = NULL;
11726 ex.X_op_symbol = NULL;
11727 ex.X_add_number = mips_cprestore_offset;
11729 macro_build ((char *) NULL, &icnt, &ex, HAVE_32BIT_ADDRESSES ? "sw" : "sd",
11730 "t,o(b)", mips_gp_register, (int) BFD_RELOC_LO16, SP);
11732 demand_empty_rest_of_line ();
11735 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
11736 was given in the preceeding .gpsetup, it results in:
11737 ld $gp, offset($sp)
11739 If a register $reg2 was given there, it results in:
11740 daddiu $gp, $gp, $reg2
11743 s_cpreturn (ignore)
11744 int ignore ATTRIBUTE_UNUSED;
11749 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
11750 We also need NewABI support. */
11751 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11757 if (mips_cpreturn_register == -1)
11759 ex.X_op = O_constant;
11760 ex.X_add_symbol = NULL;
11761 ex.X_op_symbol = NULL;
11762 ex.X_add_number = mips_cpreturn_offset;
11764 macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)",
11765 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11768 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11769 "d,v,t", mips_gp_register, mips_cpreturn_register, 0);
11771 demand_empty_rest_of_line ();
11774 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
11775 code. It sets the offset to use in gp_rel relocations. */
11779 int ignore ATTRIBUTE_UNUSED;
11781 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
11782 We also need NewABI support. */
11783 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11789 mips_cpreturn_offset = get_absolute_expression ();
11791 demand_empty_rest_of_line ();
11794 /* Handle the .gpword pseudo-op. This is used when generating PIC
11795 code. It generates a 32 bit GP relative reloc. */
11799 int ignore ATTRIBUTE_UNUSED;
11805 /* When not generating PIC code, this is treated as .word. */
11806 if (mips_pic != SVR4_PIC)
11812 label = insn_labels != NULL ? insn_labels->label : NULL;
11813 mips_emit_delays (true);
11815 mips_align (2, 0, label);
11816 mips_clear_insn_labels ();
11820 if (ex.X_op != O_symbol || ex.X_add_number != 0)
11822 as_bad (_("Unsupported use of .gpword"));
11823 ignore_rest_of_line ();
11827 md_number_to_chars (p, (valueT) 0, 4);
11828 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, false,
11829 BFD_RELOC_GPREL32);
11831 demand_empty_rest_of_line ();
11834 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
11835 tables in SVR4 PIC code. */
11839 int ignore ATTRIBUTE_UNUSED;
11844 /* This is ignored when not generating SVR4 PIC code or if this is NewABI
11846 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11852 /* Add $gp to the register named as an argument. */
11853 reg = tc_get_register (0);
11854 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11855 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
11856 "d,v,t", reg, reg, mips_gp_register);
11858 demand_empty_rest_of_line ();
11861 /* Handle the .insn pseudo-op. This marks instruction labels in
11862 mips16 mode. This permits the linker to handle them specially,
11863 such as generating jalx instructions when needed. We also make
11864 them odd for the duration of the assembly, in order to generate the
11865 right sort of code. We will make them even in the adjust_symtab
11866 routine, while leaving them marked. This is convenient for the
11867 debugger and the disassembler. The linker knows to make them odd
11872 int ignore ATTRIBUTE_UNUSED;
11874 mips16_mark_labels ();
11876 demand_empty_rest_of_line ();
11879 /* Handle a .stabn directive. We need these in order to mark a label
11880 as being a mips16 text label correctly. Sometimes the compiler
11881 will emit a label, followed by a .stabn, and then switch sections.
11882 If the label and .stabn are in mips16 mode, then the label is
11883 really a mips16 text label. */
11890 mips16_mark_labels ();
11895 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
11899 s_mips_weakext (ignore)
11900 int ignore ATTRIBUTE_UNUSED;
11907 name = input_line_pointer;
11908 c = get_symbol_end ();
11909 symbolP = symbol_find_or_make (name);
11910 S_SET_WEAK (symbolP);
11911 *input_line_pointer = c;
11913 SKIP_WHITESPACE ();
11915 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11917 if (S_IS_DEFINED (symbolP))
11919 as_bad ("ignoring attempt to redefine symbol %s",
11920 S_GET_NAME (symbolP));
11921 ignore_rest_of_line ();
11925 if (*input_line_pointer == ',')
11927 ++input_line_pointer;
11928 SKIP_WHITESPACE ();
11932 if (exp.X_op != O_symbol)
11934 as_bad ("bad .weakext directive");
11935 ignore_rest_of_line ();
11938 symbol_set_value_expression (symbolP, &exp);
11941 demand_empty_rest_of_line ();
11944 /* Parse a register string into a number. Called from the ECOFF code
11945 to parse .frame. The argument is non-zero if this is the frame
11946 register, so that we can record it in mips_frame_reg. */
11949 tc_get_register (frame)
11954 SKIP_WHITESPACE ();
11955 if (*input_line_pointer++ != '$')
11957 as_warn (_("expected `$'"));
11960 else if (ISDIGIT (*input_line_pointer))
11962 reg = get_absolute_expression ();
11963 if (reg < 0 || reg >= 32)
11965 as_warn (_("Bad register number"));
11971 if (strncmp (input_line_pointer, "fp", 2) == 0)
11973 else if (strncmp (input_line_pointer, "sp", 2) == 0)
11975 else if (strncmp (input_line_pointer, "gp", 2) == 0)
11977 else if (strncmp (input_line_pointer, "at", 2) == 0)
11981 as_warn (_("Unrecognized register name"));
11984 input_line_pointer += 2;
11988 mips_frame_reg = reg != 0 ? reg : SP;
11989 mips_frame_reg_valid = 1;
11990 mips_cprestore_valid = 0;
11996 md_section_align (seg, addr)
12000 int align = bfd_get_section_alignment (stdoutput, seg);
12003 /* We don't need to align ELF sections to the full alignment.
12004 However, Irix 5 may prefer that we align them at least to a 16
12005 byte boundary. We don't bother to align the sections if we are
12006 targeted for an embedded system. */
12007 if (strcmp (TARGET_OS, "elf") == 0)
12013 return ((addr + (1 << align) - 1) & (-1 << align));
12016 /* Utility routine, called from above as well. If called while the
12017 input file is still being read, it's only an approximation. (For
12018 example, a symbol may later become defined which appeared to be
12019 undefined earlier.) */
12022 nopic_need_relax (sym, before_relaxing)
12024 int before_relaxing;
12029 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
12031 const char *symname;
12034 /* Find out whether this symbol can be referenced off the $gp
12035 register. It can be if it is smaller than the -G size or if
12036 it is in the .sdata or .sbss section. Certain symbols can
12037 not be referenced off the $gp, although it appears as though
12039 symname = S_GET_NAME (sym);
12040 if (symname != (const char *) NULL
12041 && (strcmp (symname, "eprol") == 0
12042 || strcmp (symname, "etext") == 0
12043 || strcmp (symname, "_gp") == 0
12044 || strcmp (symname, "edata") == 0
12045 || strcmp (symname, "_fbss") == 0
12046 || strcmp (symname, "_fdata") == 0
12047 || strcmp (symname, "_ftext") == 0
12048 || strcmp (symname, "end") == 0
12049 || strcmp (symname, "_gp_disp") == 0))
12051 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12053 #ifndef NO_ECOFF_DEBUGGING
12054 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12055 && (symbol_get_obj (sym)->ecoff_extern_size
12056 <= g_switch_value))
12058 /* We must defer this decision until after the whole
12059 file has been read, since there might be a .extern
12060 after the first use of this symbol. */
12061 || (before_relaxing
12062 #ifndef NO_ECOFF_DEBUGGING
12063 && symbol_get_obj (sym)->ecoff_extern_size == 0
12065 && S_GET_VALUE (sym) == 0)
12066 || (S_GET_VALUE (sym) != 0
12067 && S_GET_VALUE (sym) <= g_switch_value)))
12071 const char *segname;
12073 segname = segment_name (S_GET_SEGMENT (sym));
12074 assert (strcmp (segname, ".lit8") != 0
12075 && strcmp (segname, ".lit4") != 0);
12076 change = (strcmp (segname, ".sdata") != 0
12077 && strcmp (segname, ".sbss") != 0
12078 && strncmp (segname, ".sdata.", 7) != 0
12079 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12084 /* We are not optimizing for the $gp register. */
12088 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12089 extended opcode. SEC is the section the frag is in. */
12092 mips16_extended_frag (fragp, sec, stretch)
12098 register const struct mips16_immed_operand *op;
12100 int mintiny, maxtiny;
12104 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
12106 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
12109 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12110 op = mips16_immed_operands;
12111 while (op->type != type)
12114 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12119 if (type == '<' || type == '>' || type == '[' || type == ']')
12122 maxtiny = 1 << op->nbits;
12127 maxtiny = (1 << op->nbits) - 1;
12132 mintiny = - (1 << (op->nbits - 1));
12133 maxtiny = (1 << (op->nbits - 1)) - 1;
12136 sym_frag = symbol_get_frag (fragp->fr_symbol);
12137 val = S_GET_VALUE (fragp->fr_symbol);
12138 symsec = S_GET_SEGMENT (fragp->fr_symbol);
12144 /* We won't have the section when we are called from
12145 mips_relax_frag. However, we will always have been called
12146 from md_estimate_size_before_relax first. If this is a
12147 branch to a different section, we mark it as such. If SEC is
12148 NULL, and the frag is not marked, then it must be a branch to
12149 the same section. */
12152 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
12157 /* Must have been called from md_estimate_size_before_relax. */
12160 fragp->fr_subtype =
12161 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12163 /* FIXME: We should support this, and let the linker
12164 catch branches and loads that are out of range. */
12165 as_bad_where (fragp->fr_file, fragp->fr_line,
12166 _("unsupported PC relative reference to different section"));
12170 if (fragp != sym_frag && sym_frag->fr_address == 0)
12171 /* Assume non-extended on the first relaxation pass.
12172 The address we have calculated will be bogus if this is
12173 a forward branch to another frag, as the forward frag
12174 will have fr_address == 0. */
12178 /* In this case, we know for sure that the symbol fragment is in
12179 the same section. If the relax_marker of the symbol fragment
12180 differs from the relax_marker of this fragment, we have not
12181 yet adjusted the symbol fragment fr_address. We want to add
12182 in STRETCH in order to get a better estimate of the address.
12183 This particularly matters because of the shift bits. */
12185 && sym_frag->relax_marker != fragp->relax_marker)
12189 /* Adjust stretch for any alignment frag. Note that if have
12190 been expanding the earlier code, the symbol may be
12191 defined in what appears to be an earlier frag. FIXME:
12192 This doesn't handle the fr_subtype field, which specifies
12193 a maximum number of bytes to skip when doing an
12195 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
12197 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
12200 stretch = - ((- stretch)
12201 & ~ ((1 << (int) f->fr_offset) - 1));
12203 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
12212 addr = fragp->fr_address + fragp->fr_fix;
12214 /* The base address rules are complicated. The base address of
12215 a branch is the following instruction. The base address of a
12216 PC relative load or add is the instruction itself, but if it
12217 is in a delay slot (in which case it can not be extended) use
12218 the address of the instruction whose delay slot it is in. */
12219 if (type == 'p' || type == 'q')
12223 /* If we are currently assuming that this frag should be
12224 extended, then, the current address is two bytes
12226 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12229 /* Ignore the low bit in the target, since it will be set
12230 for a text label. */
12231 if ((val & 1) != 0)
12234 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12236 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12239 val -= addr & ~ ((1 << op->shift) - 1);
12241 /* Branch offsets have an implicit 0 in the lowest bit. */
12242 if (type == 'p' || type == 'q')
12245 /* If any of the shifted bits are set, we must use an extended
12246 opcode. If the address depends on the size of this
12247 instruction, this can lead to a loop, so we arrange to always
12248 use an extended opcode. We only check this when we are in
12249 the main relaxation loop, when SEC is NULL. */
12250 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
12252 fragp->fr_subtype =
12253 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12257 /* If we are about to mark a frag as extended because the value
12258 is precisely maxtiny + 1, then there is a chance of an
12259 infinite loop as in the following code:
12264 In this case when the la is extended, foo is 0x3fc bytes
12265 away, so the la can be shrunk, but then foo is 0x400 away, so
12266 the la must be extended. To avoid this loop, we mark the
12267 frag as extended if it was small, and is about to become
12268 extended with a value of maxtiny + 1. */
12269 if (val == ((maxtiny + 1) << op->shift)
12270 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
12273 fragp->fr_subtype =
12274 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12278 else if (symsec != absolute_section && sec != NULL)
12279 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
12281 if ((val & ((1 << op->shift) - 1)) != 0
12282 || val < (mintiny << op->shift)
12283 || val > (maxtiny << op->shift))
12289 /* Estimate the size of a frag before relaxing. Unless this is the
12290 mips16, we are not really relaxing here, and the final size is
12291 encoded in the subtype information. For the mips16, we have to
12292 decide whether we are using an extended opcode or not. */
12295 md_estimate_size_before_relax (fragp, segtype)
12300 boolean linkonce = false;
12302 if (RELAX_MIPS16_P (fragp->fr_subtype))
12303 /* We don't want to modify the EXTENDED bit here; it might get us
12304 into infinite loops. We change it only in mips_relax_frag(). */
12305 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
12307 if (mips_pic == NO_PIC)
12309 change = nopic_need_relax (fragp->fr_symbol, 0);
12311 else if (mips_pic == SVR4_PIC)
12316 sym = fragp->fr_symbol;
12318 /* Handle the case of a symbol equated to another symbol. */
12319 while (symbol_equated_reloc_p (sym))
12323 /* It's possible to get a loop here in a badly written
12325 n = symbol_get_value_expression (sym)->X_add_symbol;
12331 symsec = S_GET_SEGMENT (sym);
12333 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12334 if (symsec != segtype && ! S_IS_LOCAL (sym))
12336 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12340 /* The GNU toolchain uses an extension for ELF: a section
12341 beginning with the magic string .gnu.linkonce is a linkonce
12343 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12344 sizeof ".gnu.linkonce" - 1) == 0)
12348 /* This must duplicate the test in adjust_reloc_syms. */
12349 change = (symsec != &bfd_und_section
12350 && symsec != &bfd_abs_section
12351 && ! bfd_is_com_section (symsec)
12354 /* A global or weak symbol is treated as external. */
12355 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12356 || (! S_IS_WEAK (sym)
12357 && (! S_IS_EXTERN (sym) || mips_pic == EMBEDDED_PIC)))
12366 /* Record the offset to the first reloc in the fr_opcode field.
12367 This lets md_convert_frag and tc_gen_reloc know that the code
12368 must be expanded. */
12369 fragp->fr_opcode = (fragp->fr_literal
12371 - RELAX_OLD (fragp->fr_subtype)
12372 + RELAX_RELOC1 (fragp->fr_subtype));
12373 /* FIXME: This really needs as_warn_where. */
12374 if (RELAX_WARN (fragp->fr_subtype))
12375 as_warn (_("AT used after \".set noat\" or macro used after "
12376 "\".set nomacro\""));
12378 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
12384 /* This is called to see whether a reloc against a defined symbol
12385 should be converted into a reloc against a section. Don't adjust
12386 MIPS16 jump relocations, so we don't have to worry about the format
12387 of the offset in the .o file. Don't adjust relocations against
12388 mips16 symbols, so that the linker can find them if it needs to set
12392 mips_fix_adjustable (fixp)
12396 /* Prevent all adjustments to global symbols. */
12397 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12398 && mips_pic != EMBEDDED_PIC
12399 && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
12402 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
12404 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12405 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12407 if (fixp->fx_addsy == NULL)
12410 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12411 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
12412 && fixp->fx_subsy == NULL)
12418 /* Translate internal representation of relocation info to BFD target
12422 tc_gen_reloc (section, fixp)
12423 asection *section ATTRIBUTE_UNUSED;
12426 static arelent *retval[4];
12428 bfd_reloc_code_real_type code;
12430 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
12433 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12434 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12435 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12437 if (mips_pic == EMBEDDED_PIC
12438 && SWITCH_TABLE (fixp))
12440 /* For a switch table entry we use a special reloc. The addend
12441 is actually the difference between the reloc address and the
12443 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12444 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
12445 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
12446 fixp->fx_r_type = BFD_RELOC_GPREL32;
12448 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
12450 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12451 reloc->addend = fixp->fx_addnumber;
12454 /* We use a special addend for an internal RELLO reloc. */
12455 if (symbol_section_p (fixp->fx_addsy))
12456 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12458 reloc->addend = fixp->fx_addnumber + reloc->address;
12461 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
12463 assert (fixp->fx_next != NULL
12464 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
12466 /* The reloc is relative to the RELLO; adjust the addend
12468 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12469 reloc->addend = fixp->fx_next->fx_addnumber;
12472 /* We use a special addend for an internal RELHI reloc. */
12473 if (symbol_section_p (fixp->fx_addsy))
12474 reloc->addend = (fixp->fx_next->fx_frag->fr_address
12475 + fixp->fx_next->fx_where
12476 - S_GET_VALUE (fixp->fx_subsy));
12478 reloc->addend = (fixp->fx_addnumber
12479 + fixp->fx_next->fx_frag->fr_address
12480 + fixp->fx_next->fx_where);
12483 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12484 reloc->addend = fixp->fx_addnumber;
12487 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
12488 /* A gruesome hack which is a result of the gruesome gas reloc
12490 reloc->addend = reloc->address;
12492 reloc->addend = -reloc->address;
12495 /* If this is a variant frag, we may need to adjust the existing
12496 reloc and generate a new one. */
12497 if (fixp->fx_frag->fr_opcode != NULL
12498 && (fixp->fx_r_type == BFD_RELOC_GPREL16
12499 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
12500 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
12501 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12502 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
12503 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12504 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
12509 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
12511 /* If this is not the last reloc in this frag, then we have two
12512 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
12513 CALL_HI16/CALL_LO16, both of which are being replaced. Let
12514 the second one handle all of them. */
12515 if (fixp->fx_next != NULL
12516 && fixp->fx_frag == fixp->fx_next->fx_frag)
12518 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
12519 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
12520 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12521 && (fixp->fx_next->fx_r_type
12522 == BFD_RELOC_MIPS_GOT_LO16))
12523 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12524 && (fixp->fx_next->fx_r_type
12525 == BFD_RELOC_MIPS_CALL_LO16)));
12530 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
12531 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12532 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
12534 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12535 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12536 reloc2->address = (reloc->address
12537 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
12538 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
12539 reloc2->addend = fixp->fx_addnumber;
12540 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
12541 assert (reloc2->howto != NULL);
12543 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
12547 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
12550 reloc3->address += 4;
12553 if (mips_pic == NO_PIC)
12555 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
12556 fixp->fx_r_type = BFD_RELOC_HI16_S;
12558 else if (mips_pic == SVR4_PIC)
12560 switch (fixp->fx_r_type)
12564 case BFD_RELOC_MIPS_GOT16:
12566 case BFD_RELOC_MIPS_CALL16:
12567 case BFD_RELOC_MIPS_GOT_LO16:
12568 case BFD_RELOC_MIPS_CALL_LO16:
12569 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
12577 /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry
12578 to be used in the relocation's section offset. */
12579 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12581 reloc->address = reloc->addend;
12585 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
12586 fixup_segment converted a non-PC relative reloc into a PC
12587 relative reloc. In such a case, we need to convert the reloc
12589 code = fixp->fx_r_type;
12590 if (fixp->fx_pcrel)
12595 code = BFD_RELOC_8_PCREL;
12598 code = BFD_RELOC_16_PCREL;
12601 code = BFD_RELOC_32_PCREL;
12604 code = BFD_RELOC_64_PCREL;
12606 case BFD_RELOC_8_PCREL:
12607 case BFD_RELOC_16_PCREL:
12608 case BFD_RELOC_32_PCREL:
12609 case BFD_RELOC_64_PCREL:
12610 case BFD_RELOC_16_PCREL_S2:
12611 case BFD_RELOC_PCREL_HI16_S:
12612 case BFD_RELOC_PCREL_LO16:
12615 as_bad_where (fixp->fx_file, fixp->fx_line,
12616 _("Cannot make %s relocation PC relative"),
12617 bfd_get_reloc_code_name (code));
12622 /* md_apply_fix3 has a double-subtraction hack to get
12623 bfd_install_relocation to behave nicely. GPREL relocations are
12624 handled correctly without this hack, so undo it here. We can't
12625 stop md_apply_fix3 from subtracting twice in the first place since
12626 the fake addend is required for variant frags above. */
12627 if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
12628 && code == BFD_RELOC_GPREL16
12629 && reloc->addend != 0
12630 && mips_need_elf_addend_fixup (fixp))
12631 reloc->addend += S_GET_VALUE (fixp->fx_addsy);
12634 /* To support a PC relative reloc when generating embedded PIC code
12635 for ECOFF, we use a Cygnus extension. We check for that here to
12636 make sure that we don't let such a reloc escape normally. */
12637 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
12638 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12639 && code == BFD_RELOC_16_PCREL_S2
12640 && mips_pic != EMBEDDED_PIC)
12641 reloc->howto = NULL;
12643 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12645 if (reloc->howto == NULL)
12647 as_bad_where (fixp->fx_file, fixp->fx_line,
12648 _("Can not represent %s relocation in this object file format"),
12649 bfd_get_reloc_code_name (code));
12656 /* Relax a machine dependent frag. This returns the amount by which
12657 the current size of the frag should change. */
12660 mips_relax_frag (fragp, stretch)
12664 if (! RELAX_MIPS16_P (fragp->fr_subtype))
12667 if (mips16_extended_frag (fragp, NULL, stretch))
12669 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12671 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
12676 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12678 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
12685 /* Convert a machine dependent frag. */
12688 md_convert_frag (abfd, asec, fragp)
12689 bfd *abfd ATTRIBUTE_UNUSED;
12696 if (RELAX_MIPS16_P (fragp->fr_subtype))
12699 register const struct mips16_immed_operand *op;
12700 boolean small, ext;
12703 unsigned long insn;
12704 boolean use_extend;
12705 unsigned short extend;
12707 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12708 op = mips16_immed_operands;
12709 while (op->type != type)
12712 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12723 resolve_symbol_value (fragp->fr_symbol);
12724 val = S_GET_VALUE (fragp->fr_symbol);
12729 addr = fragp->fr_address + fragp->fr_fix;
12731 /* The rules for the base address of a PC relative reloc are
12732 complicated; see mips16_extended_frag. */
12733 if (type == 'p' || type == 'q')
12738 /* Ignore the low bit in the target, since it will be
12739 set for a text label. */
12740 if ((val & 1) != 0)
12743 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12745 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12748 addr &= ~ (addressT) ((1 << op->shift) - 1);
12751 /* Make sure the section winds up with the alignment we have
12754 record_alignment (asec, op->shift);
12758 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
12759 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
12760 as_warn_where (fragp->fr_file, fragp->fr_line,
12761 _("extended instruction in delay slot"));
12763 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
12765 if (target_big_endian)
12766 insn = bfd_getb16 (buf);
12768 insn = bfd_getl16 (buf);
12770 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
12771 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
12772 small, ext, &insn, &use_extend, &extend);
12776 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
12777 fragp->fr_fix += 2;
12781 md_number_to_chars ((char *) buf, insn, 2);
12782 fragp->fr_fix += 2;
12787 if (fragp->fr_opcode == NULL)
12790 old = RELAX_OLD (fragp->fr_subtype);
12791 new = RELAX_NEW (fragp->fr_subtype);
12792 fixptr = fragp->fr_literal + fragp->fr_fix;
12795 memcpy (fixptr - old, fixptr, new);
12797 fragp->fr_fix += new - old;
12803 /* This function is called after the relocs have been generated.
12804 We've been storing mips16 text labels as odd. Here we convert them
12805 back to even for the convenience of the debugger. */
12808 mips_frob_file_after_relocs ()
12811 unsigned int count, i;
12813 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
12816 syms = bfd_get_outsymbols (stdoutput);
12817 count = bfd_get_symcount (stdoutput);
12818 for (i = 0; i < count; i++, syms++)
12820 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
12821 && ((*syms)->value & 1) != 0)
12823 (*syms)->value &= ~1;
12824 /* If the symbol has an odd size, it was probably computed
12825 incorrectly, so adjust that as well. */
12826 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
12827 ++elf_symbol (*syms)->internal_elf_sym.st_size;
12834 /* This function is called whenever a label is defined. It is used
12835 when handling branch delays; if a branch has a label, we assume we
12836 can not move it. */
12839 mips_define_label (sym)
12842 struct insn_label_list *l;
12844 if (free_insn_labels == NULL)
12845 l = (struct insn_label_list *) xmalloc (sizeof *l);
12848 l = free_insn_labels;
12849 free_insn_labels = l->next;
12853 l->next = insn_labels;
12857 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12859 /* Some special processing for a MIPS ELF file. */
12862 mips_elf_final_processing ()
12864 /* Write out the register information. */
12865 if (file_mips_abi != N64_ABI)
12869 s.ri_gprmask = mips_gprmask;
12870 s.ri_cprmask[0] = mips_cprmask[0];
12871 s.ri_cprmask[1] = mips_cprmask[1];
12872 s.ri_cprmask[2] = mips_cprmask[2];
12873 s.ri_cprmask[3] = mips_cprmask[3];
12874 /* The gp_value field is set by the MIPS ELF backend. */
12876 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
12877 ((Elf32_External_RegInfo *)
12878 mips_regmask_frag));
12882 Elf64_Internal_RegInfo s;
12884 s.ri_gprmask = mips_gprmask;
12886 s.ri_cprmask[0] = mips_cprmask[0];
12887 s.ri_cprmask[1] = mips_cprmask[1];
12888 s.ri_cprmask[2] = mips_cprmask[2];
12889 s.ri_cprmask[3] = mips_cprmask[3];
12890 /* The gp_value field is set by the MIPS ELF backend. */
12892 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
12893 ((Elf64_External_RegInfo *)
12894 mips_regmask_frag));
12897 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
12898 sort of BFD interface for this. */
12899 if (mips_any_noreorder)
12900 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
12901 if (mips_pic != NO_PIC)
12902 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
12904 /* Set MIPS ELF flags for ASEs. */
12905 #if 0 /* XXX FIXME */
12906 if (file_ase_mips3d)
12907 elf_elfheader (stdoutput)->e_flags |= ???;
12910 /* Set the MIPS ELF ABI flags. */
12911 if (file_mips_abi == NO_ABI)
12913 else if (file_mips_abi == O32_ABI)
12914 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
12915 else if (file_mips_abi == O64_ABI)
12916 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
12917 else if (file_mips_abi == EABI_ABI)
12920 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
12922 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
12924 else if (file_mips_abi == N32_ABI)
12925 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
12927 /* Nothing to do for N64_ABI. */
12929 if (mips_32bitmode)
12930 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
12933 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
12935 typedef struct proc {
12937 unsigned long reg_mask;
12938 unsigned long reg_offset;
12939 unsigned long fpreg_mask;
12940 unsigned long fpreg_offset;
12941 unsigned long frame_offset;
12942 unsigned long frame_reg;
12943 unsigned long pc_reg;
12946 static procS cur_proc;
12947 static procS *cur_proc_ptr;
12948 static int numprocs;
12950 /* Fill in an rs_align_code fragment. */
12953 mips_handle_align (fragp)
12956 if (fragp->fr_type != rs_align_code)
12959 if (mips_opts.mips16)
12961 static const unsigned char be_nop[] = { 0x65, 0x00 };
12962 static const unsigned char le_nop[] = { 0x00, 0x65 };
12967 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
12968 p = fragp->fr_literal + fragp->fr_fix;
12976 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
12980 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
12991 /* check for premature end, nesting errors, etc */
12993 as_warn (_("missing .end at end of assembly"));
13002 if (*input_line_pointer == '-')
13004 ++input_line_pointer;
13007 if (!ISDIGIT (*input_line_pointer))
13008 as_bad (_("expected simple number"));
13009 if (input_line_pointer[0] == '0')
13011 if (input_line_pointer[1] == 'x')
13013 input_line_pointer += 2;
13014 while (ISXDIGIT (*input_line_pointer))
13017 val |= hex_value (*input_line_pointer++);
13019 return negative ? -val : val;
13023 ++input_line_pointer;
13024 while (ISDIGIT (*input_line_pointer))
13027 val |= *input_line_pointer++ - '0';
13029 return negative ? -val : val;
13032 if (!ISDIGIT (*input_line_pointer))
13034 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13035 *input_line_pointer, *input_line_pointer);
13036 as_warn (_("invalid number"));
13039 while (ISDIGIT (*input_line_pointer))
13042 val += *input_line_pointer++ - '0';
13044 return negative ? -val : val;
13047 /* The .file directive; just like the usual .file directive, but there
13048 is an initial number which is the ECOFF file index. */
13052 int x ATTRIBUTE_UNUSED;
13058 /* The .end directive. */
13062 int x ATTRIBUTE_UNUSED;
13067 /* Following functions need their own .frame and .cprestore directives. */
13068 mips_frame_reg_valid = 0;
13069 mips_cprestore_valid = 0;
13071 if (!is_end_of_line[(unsigned char) *input_line_pointer])
13074 demand_empty_rest_of_line ();
13079 #ifdef BFD_ASSEMBLER
13080 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13085 if (now_seg != data_section && now_seg != bss_section)
13092 as_warn (_(".end not in text section"));
13096 as_warn (_(".end directive without a preceding .ent directive."));
13097 demand_empty_rest_of_line ();
13103 assert (S_GET_NAME (p));
13104 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
13105 as_warn (_(".end symbol does not match .ent symbol."));
13108 as_warn (_(".end directive missing or unknown symbol"));
13110 #ifdef MIPS_STABS_ELF
13112 segT saved_seg = now_seg;
13113 subsegT saved_subseg = now_subseg;
13118 dot = frag_now_fix ();
13120 #ifdef md_flush_pending_output
13121 md_flush_pending_output ();
13125 subseg_set (pdr_seg, 0);
13127 /* Write the symbol. */
13128 exp.X_op = O_symbol;
13129 exp.X_add_symbol = p;
13130 exp.X_add_number = 0;
13131 emit_expr (&exp, 4);
13133 fragp = frag_more (7 * 4);
13135 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
13136 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
13137 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
13138 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
13139 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
13140 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
13141 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
13143 subseg_set (saved_seg, saved_subseg);
13145 #endif /* MIPS_STABS_ELF */
13147 cur_proc_ptr = NULL;
13150 /* The .aent and .ent directives. */
13159 symbolP = get_symbol ();
13160 if (*input_line_pointer == ',')
13161 ++input_line_pointer;
13162 SKIP_WHITESPACE ();
13163 if (ISDIGIT (*input_line_pointer)
13164 || *input_line_pointer == '-')
13167 #ifdef BFD_ASSEMBLER
13168 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13173 if (now_seg != data_section && now_seg != bss_section)
13180 as_warn (_(".ent or .aent not in text section."));
13182 if (!aent && cur_proc_ptr)
13183 as_warn (_("missing .end"));
13187 /* This function needs its own .frame and .cprestore directives. */
13188 mips_frame_reg_valid = 0;
13189 mips_cprestore_valid = 0;
13191 cur_proc_ptr = &cur_proc;
13192 memset (cur_proc_ptr, '\0', sizeof (procS));
13194 cur_proc_ptr->isym = symbolP;
13196 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
13201 demand_empty_rest_of_line ();
13204 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
13205 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
13206 s_mips_frame is used so that we can set the PDR information correctly.
13207 We can't use the ecoff routines because they make reference to the ecoff
13208 symbol table (in the mdebug section). */
13211 s_mips_frame (ignore)
13212 int ignore ATTRIBUTE_UNUSED;
13214 #ifdef MIPS_STABS_ELF
13218 if (cur_proc_ptr == (procS *) NULL)
13220 as_warn (_(".frame outside of .ent"));
13221 demand_empty_rest_of_line ();
13225 cur_proc_ptr->frame_reg = tc_get_register (1);
13227 SKIP_WHITESPACE ();
13228 if (*input_line_pointer++ != ','
13229 || get_absolute_expression_and_terminator (&val) != ',')
13231 as_warn (_("Bad .frame directive"));
13232 --input_line_pointer;
13233 demand_empty_rest_of_line ();
13237 cur_proc_ptr->frame_offset = val;
13238 cur_proc_ptr->pc_reg = tc_get_register (0);
13240 demand_empty_rest_of_line ();
13243 #endif /* MIPS_STABS_ELF */
13246 /* The .fmask and .mask directives. If the mdebug section is present
13247 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
13248 embedded targets, s_mips_mask is used so that we can set the PDR
13249 information correctly. We can't use the ecoff routines because they
13250 make reference to the ecoff symbol table (in the mdebug section). */
13253 s_mips_mask (reg_type)
13256 #ifdef MIPS_STABS_ELF
13259 if (cur_proc_ptr == (procS *) NULL)
13261 as_warn (_(".mask/.fmask outside of .ent"));
13262 demand_empty_rest_of_line ();
13266 if (get_absolute_expression_and_terminator (&mask) != ',')
13268 as_warn (_("Bad .mask/.fmask directive"));
13269 --input_line_pointer;
13270 demand_empty_rest_of_line ();
13274 off = get_absolute_expression ();
13276 if (reg_type == 'F')
13278 cur_proc_ptr->fpreg_mask = mask;
13279 cur_proc_ptr->fpreg_offset = off;
13283 cur_proc_ptr->reg_mask = mask;
13284 cur_proc_ptr->reg_offset = off;
13287 demand_empty_rest_of_line ();
13289 s_ignore (reg_type);
13290 #endif /* MIPS_STABS_ELF */
13293 /* The .loc directive. */
13304 assert (now_seg == text_section);
13306 lineno = get_number ();
13307 addroff = frag_now_fix ();
13309 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
13310 S_SET_TYPE (symbolP, N_SLINE);
13311 S_SET_OTHER (symbolP, 0);
13312 S_SET_DESC (symbolP, lineno);
13313 symbolP->sy_segment = now_seg;
13317 /* CPU name/ISA/number mapping table.
13319 Entries are grouped by type. The first matching CPU or ISA entry
13320 gets chosen by CPU or ISA, so it should be the 'canonical' name
13321 for that type. Entries after that within the type are sorted
13324 Case is ignored in comparison, so put the canonical entry in the
13325 appropriate case but everything else in lower case to ease eye pain. */
13326 static const struct mips_cpu_info mips_cpu_info_table[] =
13329 { "MIPS1", 1, ISA_MIPS1, CPU_R3000, },
13330 { "mips", 1, ISA_MIPS1, CPU_R3000, },
13333 { "MIPS2", 1, ISA_MIPS2, CPU_R6000, },
13336 { "MIPS3", 1, ISA_MIPS3, CPU_R4000, },
13339 { "MIPS4", 1, ISA_MIPS4, CPU_R8000, },
13342 { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, },
13343 { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, },
13346 { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, },
13347 { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, },
13348 { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, },
13349 { "4kc", 0, ISA_MIPS32, CPU_MIPS32, },
13350 { "4km", 0, ISA_MIPS32, CPU_MIPS32, },
13351 { "4kp", 0, ISA_MIPS32, CPU_MIPS32, },
13353 /* For historical reasons. */
13354 { "MIPS64", 1, ISA_MIPS3, CPU_R4000, },
13357 { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, },
13358 { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, },
13359 { "5kc", 0, ISA_MIPS64, CPU_MIPS64, },
13360 { "20kc", 0, ISA_MIPS64, CPU_MIPS64, },
13363 { "R2000", 0, ISA_MIPS1, CPU_R2000, },
13364 { "2000", 0, ISA_MIPS1, CPU_R2000, },
13365 { "2k", 0, ISA_MIPS1, CPU_R2000, },
13366 { "r2k", 0, ISA_MIPS1, CPU_R2000, },
13369 { "R3000", 0, ISA_MIPS1, CPU_R3000, },
13370 { "3000", 0, ISA_MIPS1, CPU_R3000, },
13371 { "3k", 0, ISA_MIPS1, CPU_R3000, },
13372 { "r3k", 0, ISA_MIPS1, CPU_R3000, },
13375 { "R3900", 0, ISA_MIPS1, CPU_R3900, },
13376 { "3900", 0, ISA_MIPS1, CPU_R3900, },
13377 { "mipstx39", 0, ISA_MIPS1, CPU_R3900, },
13380 { "R4000", 0, ISA_MIPS3, CPU_R4000, },
13381 { "4000", 0, ISA_MIPS3, CPU_R4000, },
13382 { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */
13383 { "r4k", 0, ISA_MIPS3, CPU_R4000, },
13386 { "R4010", 0, ISA_MIPS2, CPU_R4010, },
13387 { "4010", 0, ISA_MIPS2, CPU_R4010, },
13390 { "R4400", 0, ISA_MIPS3, CPU_R4400, },
13391 { "4400", 0, ISA_MIPS3, CPU_R4400, },
13394 { "R4600", 0, ISA_MIPS3, CPU_R4600, },
13395 { "4600", 0, ISA_MIPS3, CPU_R4600, },
13396 { "mips64orion", 0, ISA_MIPS3, CPU_R4600, },
13397 { "orion", 0, ISA_MIPS3, CPU_R4600, },
13400 { "R4650", 0, ISA_MIPS3, CPU_R4650, },
13401 { "4650", 0, ISA_MIPS3, CPU_R4650, },
13404 { "R6000", 0, ISA_MIPS2, CPU_R6000, },
13405 { "6000", 0, ISA_MIPS2, CPU_R6000, },
13406 { "6k", 0, ISA_MIPS2, CPU_R6000, },
13407 { "r6k", 0, ISA_MIPS2, CPU_R6000, },
13410 { "R8000", 0, ISA_MIPS4, CPU_R8000, },
13411 { "8000", 0, ISA_MIPS4, CPU_R8000, },
13412 { "8k", 0, ISA_MIPS4, CPU_R8000, },
13413 { "r8k", 0, ISA_MIPS4, CPU_R8000, },
13416 { "R10000", 0, ISA_MIPS4, CPU_R10000, },
13417 { "10000", 0, ISA_MIPS4, CPU_R10000, },
13418 { "10k", 0, ISA_MIPS4, CPU_R10000, },
13419 { "r10k", 0, ISA_MIPS4, CPU_R10000, },
13422 { "R12000", 0, ISA_MIPS4, CPU_R12000, },
13423 { "12000", 0, ISA_MIPS4, CPU_R12000, },
13424 { "12k", 0, ISA_MIPS4, CPU_R12000, },
13425 { "r12k", 0, ISA_MIPS4, CPU_R12000, },
13428 { "VR4100", 0, ISA_MIPS3, CPU_VR4100, },
13429 { "4100", 0, ISA_MIPS3, CPU_VR4100, },
13430 { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, },
13431 { "r4100", 0, ISA_MIPS3, CPU_VR4100, },
13434 { "VR4111", 0, ISA_MIPS3, CPU_R4111, },
13435 { "4111", 0, ISA_MIPS3, CPU_R4111, },
13436 { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, },
13437 { "r4111", 0, ISA_MIPS3, CPU_R4111, },
13440 { "VR4300", 0, ISA_MIPS3, CPU_R4300, },
13441 { "4300", 0, ISA_MIPS3, CPU_R4300, },
13442 { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, },
13443 { "r4300", 0, ISA_MIPS3, CPU_R4300, },
13446 { "VR5000", 0, ISA_MIPS4, CPU_R5000, },
13447 { "5000", 0, ISA_MIPS4, CPU_R5000, },
13448 { "5k", 0, ISA_MIPS4, CPU_R5000, },
13449 { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, },
13450 { "r5000", 0, ISA_MIPS4, CPU_R5000, },
13451 { "r5200", 0, ISA_MIPS4, CPU_R5000, },
13452 { "rm5200", 0, ISA_MIPS4, CPU_R5000, },
13453 { "r5230", 0, ISA_MIPS4, CPU_R5000, },
13454 { "rm5230", 0, ISA_MIPS4, CPU_R5000, },
13455 { "r5231", 0, ISA_MIPS4, CPU_R5000, },
13456 { "rm5231", 0, ISA_MIPS4, CPU_R5000, },
13457 { "r5261", 0, ISA_MIPS4, CPU_R5000, },
13458 { "rm5261", 0, ISA_MIPS4, CPU_R5000, },
13459 { "r5721", 0, ISA_MIPS4, CPU_R5000, },
13460 { "rm5721", 0, ISA_MIPS4, CPU_R5000, },
13461 { "r5k", 0, ISA_MIPS4, CPU_R5000, },
13462 { "r7000", 0, ISA_MIPS4, CPU_R5000, },
13464 /* Broadcom SB-1 CPU */
13465 { "SB-1", 0, ISA_MIPS64, CPU_SB1, },
13466 { "sb-1250", 0, ISA_MIPS64, CPU_SB1, },
13467 { "sb1", 0, ISA_MIPS64, CPU_SB1, },
13468 { "sb1250", 0, ISA_MIPS64, CPU_SB1, },
13471 { NULL, 0, 0, 0, },
13474 static const struct mips_cpu_info *
13475 mips_cpu_info_from_name (name)
13480 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13481 if (strcasecmp (name, mips_cpu_info_table[i].name) == 0)
13482 return (&mips_cpu_info_table[i]);
13487 static const struct mips_cpu_info *
13488 mips_cpu_info_from_isa (isa)
13493 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13494 if (mips_cpu_info_table[i].is_isa
13495 && isa == mips_cpu_info_table[i].isa)
13496 return (&mips_cpu_info_table[i]);
13501 static const struct mips_cpu_info *
13502 mips_cpu_info_from_cpu (cpu)
13507 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13508 if (!mips_cpu_info_table[i].is_isa
13509 && cpu == mips_cpu_info_table[i].cpu)
13510 return (&mips_cpu_info_table[i]);