1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by the OSF and Ralph Campbell.
5 Written by Keith Knowles and Ralph Campbell, working independently.
6 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
9 This file is part of GAS.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include "safe-ctype.h"
38 #include "opcode/mips.h"
40 #include "dwarf2dbg.h"
43 #define DBG(x) printf x
49 /* Clean up namespace so we can include obj-elf.h too. */
50 static int mips_output_flavor PARAMS ((void));
51 static int mips_output_flavor () { return OUTPUT_FLAVOR; }
52 #undef OBJ_PROCESS_STAB
59 #undef obj_frob_file_after_relocs
60 #undef obj_frob_symbol
62 #undef obj_sec_sym_ok_for_reloc
63 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
66 /* Fix any of them that we actually care about. */
68 #define OUTPUT_FLAVOR mips_output_flavor()
75 #ifndef ECOFF_DEBUGGING
76 #define NO_ECOFF_DEBUGGING
77 #define ECOFF_DEBUGGING 0
80 int mips_flag_mdebug = -1;
84 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
85 static char *mips_regmask_frag;
91 #define PIC_CALL_REG 25
99 #define ILLEGAL_REG (32)
101 /* Allow override of standard little-endian ECOFF format. */
103 #ifndef ECOFF_LITTLE_FORMAT
104 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
107 extern int target_big_endian;
109 /* The name of the readonly data section. */
110 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
112 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
114 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
116 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
120 /* The ABI to use. */
131 /* MIPS ABI we are using for this output file. */
132 static enum mips_abi_level mips_abi = NO_ABI;
134 /* This is the set of options which may be modified by the .set
135 pseudo-op. We use a struct so that .set push and .set pop are more
138 struct mips_set_options
140 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
141 if it has not been initialized. Changed by `.set mipsN', and the
142 -mipsN command line option, and the default CPU. */
144 /* Enabled Application Specific Extensions (ASEs). These are set to -1
145 if they have not been initialized. Changed by `.set <asename>', by
146 command line options, and based on the default architecture. */
149 /* Whether we are assembling for the mips16 processor. 0 if we are
150 not, 1 if we are, and -1 if the value has not been initialized.
151 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
152 -nomips16 command line options, and the default CPU. */
154 /* Non-zero if we should not reorder instructions. Changed by `.set
155 reorder' and `.set noreorder'. */
157 /* Non-zero if we should not permit the $at ($1) register to be used
158 in instructions. Changed by `.set at' and `.set noat'. */
160 /* Non-zero if we should warn when a macro instruction expands into
161 more than one machine instruction. Changed by `.set nomacro' and
163 int warn_about_macros;
164 /* Non-zero if we should not move instructions. Changed by `.set
165 move', `.set volatile', `.set nomove', and `.set novolatile'. */
167 /* Non-zero if we should not optimize branches by moving the target
168 of the branch into the delay slot. Actually, we don't perform
169 this optimization anyhow. Changed by `.set bopt' and `.set
172 /* Non-zero if we should not autoextend mips16 instructions.
173 Changed by `.set autoextend' and `.set noautoextend'. */
175 /* Restrict general purpose registers and floating point registers
176 to 32 bit. This is initially determined when -mgp32 or -mfp32
177 is passed but can changed if the assembler code uses .set mipsN. */
182 /* True if -mgp32 was passed. */
183 static int file_mips_gp32 = -1;
185 /* True if -mfp32 was passed. */
186 static int file_mips_fp32 = -1;
188 /* This is the struct we use to hold the current set of options. Note
189 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
190 -1 to indicate that they have not been initialized. */
192 static struct mips_set_options mips_opts =
194 ISA_UNKNOWN, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0
197 /* These variables are filled in with the masks of registers used.
198 The object format code reads them and puts them in the appropriate
200 unsigned long mips_gprmask;
201 unsigned long mips_cprmask[4];
203 /* MIPS ISA we are using for this output file. */
204 static int file_mips_isa = ISA_UNKNOWN;
206 /* True if -mips16 was passed or implied by arguments passed on the
207 command line (e.g., by -march). */
208 static int file_ase_mips16;
210 /* True if -mips3d was passed or implied by arguments passed on the
211 command line (e.g., by -march). */
212 static int file_ase_mips3d;
214 /* True if -mdmx was passed or implied by arguments passed on the
215 command line (e.g., by -march). */
216 static int file_ase_mdmx;
218 /* The argument of the -march= flag. The architecture we are assembling. */
219 static int mips_arch = CPU_UNKNOWN;
220 static const char *mips_arch_string;
221 static const struct mips_cpu_info *mips_arch_info;
223 /* The argument of the -mtune= flag. The architecture for which we
225 static int mips_tune = CPU_UNKNOWN;
226 static const char *mips_tune_string;
227 static const struct mips_cpu_info *mips_tune_info;
229 /* True when generating 32-bit code for a 64-bit processor. */
230 static int mips_32bitmode = 0;
232 /* Some ISA's have delay slots for instructions which read or write
233 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
234 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
235 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
236 delay slot in this ISA. The uses of this macro assume that any
237 ISA that has delay slots for one of these, has them for all. They
238 also assume that ISAs which don't have delays for these insns, don't
239 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
240 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
242 || (ISA) == ISA_MIPS2 \
243 || (ISA) == ISA_MIPS3 \
246 /* True if the given ABI requires 32-bit registers. */
247 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
249 /* Likewise 64-bit registers. */
250 #define ABI_NEEDS_64BIT_REGS(ABI) \
252 || (ABI) == N64_ABI \
255 /* Return true if ISA supports 64 bit gp register instructions. */
256 #define ISA_HAS_64BIT_REGS(ISA) ( \
258 || (ISA) == ISA_MIPS4 \
259 || (ISA) == ISA_MIPS5 \
260 || (ISA) == ISA_MIPS64 \
263 #define HAVE_32BIT_GPRS \
264 (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
266 #define HAVE_32BIT_FPRS \
267 (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
269 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
270 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
272 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
274 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
276 /* We can only have 64bit addresses if the object file format
278 #define HAVE_32BIT_ADDRESSES \
280 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
281 || ! HAVE_64BIT_OBJECTS) \
282 && mips_pic != EMBEDDED_PIC))
284 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
286 /* Return true if the given CPU supports the MIPS16 ASE. */
287 #define CPU_HAS_MIPS16(cpu) \
288 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0)
290 /* Return true if the given CPU supports the MIPS3D ASE. */
291 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
294 /* Return true if the given CPU supports the MDMX ASE. */
295 #define CPU_HAS_MDMX(cpu) (false \
298 /* Whether the processor uses hardware interlocks to protect
299 reads from the HI and LO registers, and thus does not
300 require nops to be inserted. */
302 #define hilo_interlocks (mips_arch == CPU_R4010 \
303 || mips_arch == CPU_SB1 \
306 /* Whether the processor uses hardware interlocks to protect reads
307 from the GPRs, and thus does not require nops to be inserted. */
308 #define gpr_interlocks \
309 (mips_opts.isa != ISA_MIPS1 \
310 || mips_arch == CPU_R3900)
312 /* As with other "interlocks" this is used by hardware that has FP
313 (co-processor) interlocks. */
314 /* Itbl support may require additional care here. */
315 #define cop_interlocks (mips_arch == CPU_R4300 \
316 || mips_arch == CPU_SB1 \
319 /* Is this a mfhi or mflo instruction? */
320 #define MF_HILO_INSN(PINFO) \
321 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
323 /* MIPS PIC level. */
327 /* Do not generate PIC code. */
330 /* Generate PIC code as in the SVR4 MIPS ABI. */
333 /* Generate PIC code without using a global offset table: the data
334 segment has a maximum size of 64K, all data references are off
335 the $gp register, and all text references are PC relative. This
336 is used on some embedded systems. */
340 static enum mips_pic_level mips_pic;
342 /* Warn about all NOPS that the assembler generates. */
343 static int warn_nops = 0;
345 /* 1 if we should generate 32 bit offsets from the $gp register in
346 SVR4_PIC mode. Currently has no meaning in other modes. */
347 static int mips_big_got = 0;
349 /* 1 if trap instructions should used for overflow rather than break
351 static int mips_trap = 0;
353 /* 1 if double width floating point constants should not be constructed
354 by assembling two single width halves into two single width floating
355 point registers which just happen to alias the double width destination
356 register. On some architectures this aliasing can be disabled by a bit
357 in the status register, and the setting of this bit cannot be determined
358 automatically at assemble time. */
359 static int mips_disable_float_construction;
361 /* Non-zero if any .set noreorder directives were used. */
363 static int mips_any_noreorder;
365 /* Non-zero if nops should be inserted when the register referenced in
366 an mfhi/mflo instruction is read in the next two instructions. */
367 static int mips_7000_hilo_fix;
369 /* The size of the small data section. */
370 static unsigned int g_switch_value = 8;
371 /* Whether the -G option was used. */
372 static int g_switch_seen = 0;
377 /* If we can determine in advance that GP optimization won't be
378 possible, we can skip the relaxation stuff that tries to produce
379 GP-relative references. This makes delay slot optimization work
382 This function can only provide a guess, but it seems to work for
383 gcc output. It needs to guess right for gcc, otherwise gcc
384 will put what it thinks is a GP-relative instruction in a branch
387 I don't know if a fix is needed for the SVR4_PIC mode. I've only
388 fixed it for the non-PIC mode. KR 95/04/07 */
389 static int nopic_need_relax PARAMS ((symbolS *, int));
391 /* handle of the OPCODE hash table */
392 static struct hash_control *op_hash = NULL;
394 /* The opcode hash table we use for the mips16. */
395 static struct hash_control *mips16_op_hash = NULL;
397 /* This array holds the chars that always start a comment. If the
398 pre-processor is disabled, these aren't very useful */
399 const char comment_chars[] = "#";
401 /* This array holds the chars that only start a comment at the beginning of
402 a line. If the line seems to have the form '# 123 filename'
403 .line and .file directives will appear in the pre-processed output */
404 /* Note that input_file.c hand checks for '#' at the beginning of the
405 first line of the input file. This is because the compiler outputs
406 #NO_APP at the beginning of its output. */
407 /* Also note that C style comments are always supported. */
408 const char line_comment_chars[] = "#";
410 /* This array holds machine specific line separator characters. */
411 const char line_separator_chars[] = ";";
413 /* Chars that can be used to separate mant from exp in floating point nums */
414 const char EXP_CHARS[] = "eE";
416 /* Chars that mean this number is a floating point constant */
419 const char FLT_CHARS[] = "rRsSfFdDxXpP";
421 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
422 changed in read.c . Ideally it shouldn't have to know about it at all,
423 but nothing is ideal around here.
426 static char *insn_error;
428 static int auto_align = 1;
430 /* When outputting SVR4 PIC code, the assembler needs to know the
431 offset in the stack frame from which to restore the $gp register.
432 This is set by the .cprestore pseudo-op, and saved in this
434 static offsetT mips_cprestore_offset = -1;
436 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
437 more optimizations, it can use a register value instead of a memory-saved
438 offset and even an other register than $gp as global pointer. */
439 static offsetT mips_cpreturn_offset = -1;
440 static int mips_cpreturn_register = -1;
441 static int mips_gp_register = GP;
442 static int mips_gprel_offset = 0;
444 /* Whether mips_cprestore_offset has been set in the current function
445 (or whether it has already been warned about, if not). */
446 static int mips_cprestore_valid = 0;
448 /* This is the register which holds the stack frame, as set by the
449 .frame pseudo-op. This is needed to implement .cprestore. */
450 static int mips_frame_reg = SP;
452 /* Whether mips_frame_reg has been set in the current function
453 (or whether it has already been warned about, if not). */
454 static int mips_frame_reg_valid = 0;
456 /* To output NOP instructions correctly, we need to keep information
457 about the previous two instructions. */
459 /* Whether we are optimizing. The default value of 2 means to remove
460 unneeded NOPs and swap branch instructions when possible. A value
461 of 1 means to not swap branches. A value of 0 means to always
463 static int mips_optimize = 2;
465 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
466 equivalent to seeing no -g option at all. */
467 static int mips_debug = 0;
469 /* The previous instruction. */
470 static struct mips_cl_insn prev_insn;
472 /* The instruction before prev_insn. */
473 static struct mips_cl_insn prev_prev_insn;
475 /* If we don't want information for prev_insn or prev_prev_insn, we
476 point the insn_mo field at this dummy integer. */
477 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
479 /* Non-zero if prev_insn is valid. */
480 static int prev_insn_valid;
482 /* The frag for the previous instruction. */
483 static struct frag *prev_insn_frag;
485 /* The offset into prev_insn_frag for the previous instruction. */
486 static long prev_insn_where;
488 /* The reloc type for the previous instruction, if any. */
489 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
491 /* The reloc for the previous instruction, if any. */
492 static fixS *prev_insn_fixp[3];
494 /* Non-zero if the previous instruction was in a delay slot. */
495 static int prev_insn_is_delay_slot;
497 /* Non-zero if the previous instruction was in a .set noreorder. */
498 static int prev_insn_unreordered;
500 /* Non-zero if the previous instruction uses an extend opcode (if
502 static int prev_insn_extended;
504 /* Non-zero if the previous previous instruction was in a .set
506 static int prev_prev_insn_unreordered;
508 /* If this is set, it points to a frag holding nop instructions which
509 were inserted before the start of a noreorder section. If those
510 nops turn out to be unnecessary, the size of the frag can be
512 static fragS *prev_nop_frag;
514 /* The number of nop instructions we created in prev_nop_frag. */
515 static int prev_nop_frag_holds;
517 /* The number of nop instructions that we know we need in
519 static int prev_nop_frag_required;
521 /* The number of instructions we've seen since prev_nop_frag. */
522 static int prev_nop_frag_since;
524 /* For ECOFF and ELF, relocations against symbols are done in two
525 parts, with a HI relocation and a LO relocation. Each relocation
526 has only 16 bits of space to store an addend. This means that in
527 order for the linker to handle carries correctly, it must be able
528 to locate both the HI and the LO relocation. This means that the
529 relocations must appear in order in the relocation table.
531 In order to implement this, we keep track of each unmatched HI
532 relocation. We then sort them so that they immediately precede the
533 corresponding LO relocation. */
538 struct mips_hi_fixup *next;
541 /* The section this fixup is in. */
545 /* The list of unmatched HI relocs. */
547 static struct mips_hi_fixup *mips_hi_fixup_list;
549 /* Map normal MIPS register numbers to mips16 register numbers. */
551 #define X ILLEGAL_REG
552 static const int mips32_to_16_reg_map[] =
554 X, X, 2, 3, 4, 5, 6, 7,
555 X, X, X, X, X, X, X, X,
556 0, 1, X, X, X, X, X, X,
557 X, X, X, X, X, X, X, X
561 /* Map mips16 register numbers to normal MIPS register numbers. */
563 static const unsigned int mips16_to_32_reg_map[] =
565 16, 17, 2, 3, 4, 5, 6, 7
568 /* Since the MIPS does not have multiple forms of PC relative
569 instructions, we do not have to do relaxing as is done on other
570 platforms. However, we do have to handle GP relative addressing
571 correctly, which turns out to be a similar problem.
573 Every macro that refers to a symbol can occur in (at least) two
574 forms, one with GP relative addressing and one without. For
575 example, loading a global variable into a register generally uses
576 a macro instruction like this:
578 If i can be addressed off the GP register (this is true if it is in
579 the .sbss or .sdata section, or if it is known to be smaller than
580 the -G argument) this will generate the following instruction:
582 This instruction will use a GPREL reloc. If i can not be addressed
583 off the GP register, the following instruction sequence will be used:
586 In this case the first instruction will have a HI16 reloc, and the
587 second reloc will have a LO16 reloc. Both relocs will be against
590 The issue here is that we may not know whether i is GP addressable
591 until after we see the instruction that uses it. Therefore, we
592 want to be able to choose the final instruction sequence only at
593 the end of the assembly. This is similar to the way other
594 platforms choose the size of a PC relative instruction only at the
597 When generating position independent code we do not use GP
598 addressing in quite the same way, but the issue still arises as
599 external symbols and local symbols must be handled differently.
601 We handle these issues by actually generating both possible
602 instruction sequences. The longer one is put in a frag_var with
603 type rs_machine_dependent. We encode what to do with the frag in
604 the subtype field. We encode (1) the number of existing bytes to
605 replace, (2) the number of new bytes to use, (3) the offset from
606 the start of the existing bytes to the first reloc we must generate
607 (that is, the offset is applied from the start of the existing
608 bytes after they are replaced by the new bytes, if any), (4) the
609 offset from the start of the existing bytes to the second reloc,
610 (5) whether a third reloc is needed (the third reloc is always four
611 bytes after the second reloc), and (6) whether to warn if this
612 variant is used (this is sometimes needed if .set nomacro or .set
613 noat is in effect). All these numbers are reasonably small.
615 Generating two instruction sequences must be handled carefully to
616 ensure that delay slots are handled correctly. Fortunately, there
617 are a limited number of cases. When the second instruction
618 sequence is generated, append_insn is directed to maintain the
619 existing delay slot information, so it continues to apply to any
620 code after the second instruction sequence. This means that the
621 second instruction sequence must not impose any requirements not
622 required by the first instruction sequence.
624 These variant frags are then handled in functions called by the
625 machine independent code. md_estimate_size_before_relax returns
626 the final size of the frag. md_convert_frag sets up the final form
627 of the frag. tc_gen_reloc adjust the first reloc and adds a second
629 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
633 | (((reloc1) + 64) << 9) \
634 | (((reloc2) + 64) << 2) \
635 | ((reloc3) ? (1 << 1) : 0) \
637 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
638 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
639 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
640 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
641 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
642 #define RELAX_WARN(i) ((i) & 1)
644 /* For mips16 code, we use an entirely different form of relaxation.
645 mips16 supports two versions of most instructions which take
646 immediate values: a small one which takes some small value, and a
647 larger one which takes a 16 bit value. Since branches also follow
648 this pattern, relaxing these values is required.
650 We can assemble both mips16 and normal MIPS code in a single
651 object. Therefore, we need to support this type of relaxation at
652 the same time that we support the relaxation described above. We
653 use the high bit of the subtype field to distinguish these cases.
655 The information we store for this type of relaxation is the
656 argument code found in the opcode file for this relocation, whether
657 the user explicitly requested a small or extended form, and whether
658 the relocation is in a jump or jal delay slot. That tells us the
659 size of the value, and how it should be stored. We also store
660 whether the fragment is considered to be extended or not. We also
661 store whether this is known to be a branch to a different section,
662 whether we have tried to relax this frag yet, and whether we have
663 ever extended a PC relative fragment because of a shift count. */
664 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
667 | ((small) ? 0x100 : 0) \
668 | ((ext) ? 0x200 : 0) \
669 | ((dslot) ? 0x400 : 0) \
670 | ((jal_dslot) ? 0x800 : 0))
671 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
672 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
673 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
674 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
675 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
676 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
677 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
678 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
679 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
680 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
681 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
682 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
684 /* Prototypes for static functions. */
687 #define internalError() \
688 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
690 #define internalError() as_fatal (_("MIPS internal Error"));
693 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
695 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
696 unsigned int reg, enum mips_regclass class));
697 static int reg_needs_delay PARAMS ((unsigned int));
698 static void mips16_mark_labels PARAMS ((void));
699 static void append_insn PARAMS ((char *place,
700 struct mips_cl_insn * ip,
702 bfd_reloc_code_real_type *r,
704 static void mips_no_prev_insn PARAMS ((int));
705 static void mips_emit_delays PARAMS ((boolean));
707 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
708 const char *name, const char *fmt,
711 static void macro_build ();
713 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
714 const char *, const char *,
716 static void macro_build_jalr PARAMS ((int, expressionS *));
717 static void macro_build_lui PARAMS ((char *place, int *counter,
718 expressionS * ep, int regnum));
719 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
720 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
722 static void load_register PARAMS ((int *, int, expressionS *, int));
723 static void load_address PARAMS ((int *, int, expressionS *, int *));
724 static void move_register PARAMS ((int *, int, int));
725 static void macro PARAMS ((struct mips_cl_insn * ip));
726 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
727 #ifdef LOSING_COMPILER
728 static void macro2 PARAMS ((struct mips_cl_insn * ip));
730 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
731 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
732 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
733 boolean, boolean, unsigned long *,
734 boolean *, unsigned short *));
735 static int my_getPercentOp PARAMS ((char **, unsigned int *, int *));
736 static int my_getSmallParser PARAMS ((char **, unsigned int *, int *));
737 static int my_getSmallExpression PARAMS ((expressionS *, char *));
738 static void my_getExpression PARAMS ((expressionS *, char *));
740 static int support_64bit_objects PARAMS((void));
742 static void mips_set_option_string PARAMS ((const char **, const char *));
743 static symbolS *get_symbol PARAMS ((void));
744 static void mips_align PARAMS ((int to, int fill, symbolS *label));
745 static void s_align PARAMS ((int));
746 static void s_change_sec PARAMS ((int));
747 static void s_cons PARAMS ((int));
748 static void s_float_cons PARAMS ((int));
749 static void s_mips_globl PARAMS ((int));
750 static void s_option PARAMS ((int));
751 static void s_mipsset PARAMS ((int));
752 static void s_abicalls PARAMS ((int));
753 static void s_cpload PARAMS ((int));
754 static void s_cpsetup PARAMS ((int));
755 static void s_cplocal PARAMS ((int));
756 static void s_cprestore PARAMS ((int));
757 static void s_cpreturn PARAMS ((int));
758 static void s_gpvalue PARAMS ((int));
759 static void s_gpword PARAMS ((int));
760 static void s_cpadd PARAMS ((int));
761 static void s_insn PARAMS ((int));
762 static void md_obj_begin PARAMS ((void));
763 static void md_obj_end PARAMS ((void));
764 static long get_number PARAMS ((void));
765 static void s_mips_ent PARAMS ((int));
766 static void s_mips_end PARAMS ((int));
767 static void s_mips_frame PARAMS ((int));
768 static void s_mips_mask PARAMS ((int));
769 static void s_mips_stab PARAMS ((int));
770 static void s_mips_weakext PARAMS ((int));
771 static void s_mips_file PARAMS ((int));
772 static void s_mips_loc PARAMS ((int));
773 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
774 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
775 static void show PARAMS ((FILE *, const char *, int *, int *));
777 static int mips_need_elf_addend_fixup PARAMS ((fixS *));
780 /* Return values of my_getSmallExpression(). */
787 /* Direct relocation creation by %percent_op(). */
806 /* Table and functions used to map between CPU/ISA names, and
807 ISA levels, and CPU numbers. */
811 const char *name; /* CPU or ISA name. */
812 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
813 int isa; /* ISA level. */
814 int cpu; /* CPU number (default CPU if ISA). */
817 static void mips_set_architecture PARAMS ((const struct mips_cpu_info *));
818 static void mips_set_tune PARAMS ((const struct mips_cpu_info *));
819 static boolean mips_strict_matching_cpu_name_p PARAMS ((const char *,
821 static boolean mips_matching_cpu_name_p PARAMS ((const char *, const char *));
822 static const struct mips_cpu_info *mips_parse_cpu PARAMS ((const char *,
824 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
828 The following pseudo-ops from the Kane and Heinrich MIPS book
829 should be defined here, but are currently unsupported: .alias,
830 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
832 The following pseudo-ops from the Kane and Heinrich MIPS book are
833 specific to the type of debugging information being generated, and
834 should be defined by the object format: .aent, .begin, .bend,
835 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
838 The following pseudo-ops from the Kane and Heinrich MIPS book are
839 not MIPS CPU specific, but are also not specific to the object file
840 format. This file is probably the best place to define them, but
841 they are not currently supported: .asm0, .endr, .lab, .repeat,
844 static const pseudo_typeS mips_pseudo_table[] =
846 /* MIPS specific pseudo-ops. */
847 {"option", s_option, 0},
848 {"set", s_mipsset, 0},
849 {"rdata", s_change_sec, 'r'},
850 {"sdata", s_change_sec, 's'},
851 {"livereg", s_ignore, 0},
852 {"abicalls", s_abicalls, 0},
853 {"cpload", s_cpload, 0},
854 {"cpsetup", s_cpsetup, 0},
855 {"cplocal", s_cplocal, 0},
856 {"cprestore", s_cprestore, 0},
857 {"cpreturn", s_cpreturn, 0},
858 {"gpvalue", s_gpvalue, 0},
859 {"gpword", s_gpword, 0},
860 {"cpadd", s_cpadd, 0},
863 /* Relatively generic pseudo-ops that happen to be used on MIPS
865 {"asciiz", stringer, 1},
866 {"bss", s_change_sec, 'b'},
869 {"dword", s_cons, 3},
870 {"weakext", s_mips_weakext, 0},
872 /* These pseudo-ops are defined in read.c, but must be overridden
873 here for one reason or another. */
874 {"align", s_align, 0},
876 {"data", s_change_sec, 'd'},
877 {"double", s_float_cons, 'd'},
878 {"float", s_float_cons, 'f'},
879 {"globl", s_mips_globl, 0},
880 {"global", s_mips_globl, 0},
881 {"hword", s_cons, 1},
886 {"short", s_cons, 1},
887 {"single", s_float_cons, 'f'},
888 {"stabn", s_mips_stab, 'n'},
889 {"text", s_change_sec, 't'},
892 { "extern", ecoff_directive_extern, 0},
897 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
899 /* These pseudo-ops should be defined by the object file format.
900 However, a.out doesn't support them, so we have versions here. */
901 {"aent", s_mips_ent, 1},
902 {"bgnb", s_ignore, 0},
903 {"end", s_mips_end, 0},
904 {"endb", s_ignore, 0},
905 {"ent", s_mips_ent, 0},
906 {"file", s_mips_file, 0},
907 {"fmask", s_mips_mask, 'F'},
908 {"frame", s_mips_frame, 0},
909 {"loc", s_mips_loc, 0},
910 {"mask", s_mips_mask, 'R'},
911 {"verstamp", s_ignore, 0},
915 extern void pop_insert PARAMS ((const pseudo_typeS *));
920 pop_insert (mips_pseudo_table);
921 if (! ECOFF_DEBUGGING)
922 pop_insert (mips_nonecoff_pseudo_table);
925 /* Symbols labelling the current insn. */
927 struct insn_label_list
929 struct insn_label_list *next;
933 static struct insn_label_list *insn_labels;
934 static struct insn_label_list *free_insn_labels;
936 static void mips_clear_insn_labels PARAMS ((void));
939 mips_clear_insn_labels ()
941 register struct insn_label_list **pl;
943 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
949 static char *expr_end;
951 /* Expressions which appear in instructions. These are set by
954 static expressionS imm_expr;
955 static expressionS offset_expr;
957 /* Relocs associated with imm_expr and offset_expr. */
959 static bfd_reloc_code_real_type imm_reloc[3]
960 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
961 static bfd_reloc_code_real_type offset_reloc[3]
962 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
964 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
966 static boolean imm_unmatched_hi;
968 /* These are set by mips16_ip if an explicit extension is used. */
970 static boolean mips16_small, mips16_ext;
972 /* The pdr segment for per procedure frame/regmask info. Not used for
977 /* The default target format to use. */
980 mips_target_format ()
982 switch (OUTPUT_FLAVOR)
984 case bfd_target_aout_flavour:
985 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
986 case bfd_target_ecoff_flavour:
987 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
988 case bfd_target_coff_flavour:
990 case bfd_target_elf_flavour:
992 /* This is traditional mips */
993 return (target_big_endian
994 ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips"
995 : "elf32-tradbigmips")
996 : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips"
997 : "elf32-tradlittlemips"));
999 return (target_big_endian
1000 ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips")
1001 : (HAVE_64BIT_OBJECTS ? "elf64-littlemips"
1002 : "elf32-littlemips"));
1010 /* This function is called once, at assembler startup time. It should
1011 set up all the tables, etc. that the MD part of the assembler will need. */
1016 register const char *retval = NULL;
1020 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1021 as_warn (_("Could not set architecture and machine"));
1023 op_hash = hash_new ();
1025 for (i = 0; i < NUMOPCODES;)
1027 const char *name = mips_opcodes[i].name;
1029 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1032 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1033 mips_opcodes[i].name, retval);
1034 /* Probably a memory allocation problem? Give up now. */
1035 as_fatal (_("Broken assembler. No assembly attempted."));
1039 if (mips_opcodes[i].pinfo != INSN_MACRO)
1041 if (!validate_mips_insn (&mips_opcodes[i]))
1046 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1049 mips16_op_hash = hash_new ();
1052 while (i < bfd_mips16_num_opcodes)
1054 const char *name = mips16_opcodes[i].name;
1056 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1058 as_fatal (_("internal: can't hash `%s': %s"),
1059 mips16_opcodes[i].name, retval);
1062 if (mips16_opcodes[i].pinfo != INSN_MACRO
1063 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1064 != mips16_opcodes[i].match))
1066 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1067 mips16_opcodes[i].name, mips16_opcodes[i].args);
1072 while (i < bfd_mips16_num_opcodes
1073 && strcmp (mips16_opcodes[i].name, name) == 0);
1077 as_fatal (_("Broken assembler. No assembly attempted."));
1079 /* We add all the general register names to the symbol table. This
1080 helps us detect invalid uses of them. */
1081 for (i = 0; i < 32; i++)
1085 sprintf (buf, "$%d", i);
1086 symbol_table_insert (symbol_new (buf, reg_section, i,
1087 &zero_address_frag));
1089 symbol_table_insert (symbol_new ("$ra", reg_section, RA,
1090 &zero_address_frag));
1091 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1092 &zero_address_frag));
1093 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1094 &zero_address_frag));
1095 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1096 &zero_address_frag));
1097 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1098 &zero_address_frag));
1099 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1100 &zero_address_frag));
1101 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1102 &zero_address_frag));
1103 symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
1104 &zero_address_frag));
1105 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1106 &zero_address_frag));
1108 mips_no_prev_insn (false);
1111 mips_cprmask[0] = 0;
1112 mips_cprmask[1] = 0;
1113 mips_cprmask[2] = 0;
1114 mips_cprmask[3] = 0;
1116 /* set the default alignment for the text section (2**2) */
1117 record_alignment (text_section, 2);
1119 if (USE_GLOBAL_POINTER_OPT)
1120 bfd_set_gp_size (stdoutput, g_switch_value);
1122 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1124 /* On a native system, sections must be aligned to 16 byte
1125 boundaries. When configured for an embedded ELF target, we
1127 if (strcmp (TARGET_OS, "elf") != 0)
1129 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1130 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1131 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1134 /* Create a .reginfo section for register masks and a .mdebug
1135 section for debugging information. */
1143 subseg = now_subseg;
1145 /* The ABI says this section should be loaded so that the
1146 running program can access it. However, we don't load it
1147 if we are configured for an embedded target */
1148 flags = SEC_READONLY | SEC_DATA;
1149 if (strcmp (TARGET_OS, "elf") != 0)
1150 flags |= SEC_ALLOC | SEC_LOAD;
1152 if (mips_abi != N64_ABI)
1154 sec = subseg_new (".reginfo", (subsegT) 0);
1156 bfd_set_section_flags (stdoutput, sec, flags);
1157 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1160 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1165 /* The 64-bit ABI uses a .MIPS.options section rather than
1166 .reginfo section. */
1167 sec = subseg_new (".MIPS.options", (subsegT) 0);
1168 bfd_set_section_flags (stdoutput, sec, flags);
1169 bfd_set_section_alignment (stdoutput, sec, 3);
1172 /* Set up the option header. */
1174 Elf_Internal_Options opthdr;
1177 opthdr.kind = ODK_REGINFO;
1178 opthdr.size = (sizeof (Elf_External_Options)
1179 + sizeof (Elf64_External_RegInfo));
1182 f = frag_more (sizeof (Elf_External_Options));
1183 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1184 (Elf_External_Options *) f);
1186 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1191 if (ECOFF_DEBUGGING)
1193 sec = subseg_new (".mdebug", (subsegT) 0);
1194 (void) bfd_set_section_flags (stdoutput, sec,
1195 SEC_HAS_CONTENTS | SEC_READONLY);
1196 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1199 else if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1201 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1202 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1203 SEC_READONLY | SEC_RELOC
1205 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1209 subseg_set (seg, subseg);
1213 if (! ECOFF_DEBUGGING)
1220 if (! ECOFF_DEBUGGING)
1228 struct mips_cl_insn insn;
1229 bfd_reloc_code_real_type unused_reloc[3]
1230 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1232 imm_expr.X_op = O_absent;
1233 imm_unmatched_hi = false;
1234 offset_expr.X_op = O_absent;
1235 imm_reloc[0] = BFD_RELOC_UNUSED;
1236 imm_reloc[1] = BFD_RELOC_UNUSED;
1237 imm_reloc[2] = BFD_RELOC_UNUSED;
1238 offset_reloc[0] = BFD_RELOC_UNUSED;
1239 offset_reloc[1] = BFD_RELOC_UNUSED;
1240 offset_reloc[2] = BFD_RELOC_UNUSED;
1242 if (mips_opts.mips16)
1243 mips16_ip (str, &insn);
1246 mips_ip (str, &insn);
1247 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1248 str, insn.insn_opcode));
1253 as_bad ("%s `%s'", insn_error, str);
1257 if (insn.insn_mo->pinfo == INSN_MACRO)
1259 if (mips_opts.mips16)
1260 mips16_macro (&insn);
1266 if (imm_expr.X_op != O_absent)
1267 append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi);
1268 else if (offset_expr.X_op != O_absent)
1269 append_insn (NULL, &insn, &offset_expr, offset_reloc, false);
1271 append_insn (NULL, &insn, NULL, unused_reloc, false);
1275 /* See whether instruction IP reads register REG. CLASS is the type
1279 insn_uses_reg (ip, reg, class)
1280 struct mips_cl_insn *ip;
1282 enum mips_regclass class;
1284 if (class == MIPS16_REG)
1286 assert (mips_opts.mips16);
1287 reg = mips16_to_32_reg_map[reg];
1288 class = MIPS_GR_REG;
1291 /* Don't report on general register ZERO, since it never changes. */
1292 if (class == MIPS_GR_REG && reg == ZERO)
1295 if (class == MIPS_FP_REG)
1297 assert (! mips_opts.mips16);
1298 /* If we are called with either $f0 or $f1, we must check $f0.
1299 This is not optimal, because it will introduce an unnecessary
1300 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1301 need to distinguish reading both $f0 and $f1 or just one of
1302 them. Note that we don't have to check the other way,
1303 because there is no instruction that sets both $f0 and $f1
1304 and requires a delay. */
1305 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1306 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1307 == (reg &~ (unsigned) 1)))
1309 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1310 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1311 == (reg &~ (unsigned) 1)))
1314 else if (! mips_opts.mips16)
1316 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1317 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1319 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1320 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1325 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1326 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1327 & MIPS16OP_MASK_RX)]
1330 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1331 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1332 & MIPS16OP_MASK_RY)]
1335 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1336 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1337 & MIPS16OP_MASK_MOVE32Z)]
1340 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1342 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1344 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1346 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1347 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1348 & MIPS16OP_MASK_REGR32) == reg)
1355 /* This function returns true if modifying a register requires a
1359 reg_needs_delay (reg)
1362 unsigned long prev_pinfo;
1364 prev_pinfo = prev_insn.insn_mo->pinfo;
1365 if (! mips_opts.noreorder
1366 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1367 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1368 || (! gpr_interlocks
1369 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1371 /* A load from a coprocessor or from memory. All load
1372 delays delay the use of general register rt for one
1373 instruction on the r3000. The r6000 and r4000 use
1375 /* Itbl support may require additional care here. */
1376 know (prev_pinfo & INSN_WRITE_GPR_T);
1377 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1384 /* Mark instruction labels in mips16 mode. This permits the linker to
1385 handle them specially, such as generating jalx instructions when
1386 needed. We also make them odd for the duration of the assembly, in
1387 order to generate the right sort of code. We will make them even
1388 in the adjust_symtab routine, while leaving them marked. This is
1389 convenient for the debugger and the disassembler. The linker knows
1390 to make them odd again. */
1393 mips16_mark_labels ()
1395 if (mips_opts.mips16)
1397 struct insn_label_list *l;
1400 for (l = insn_labels; l != NULL; l = l->next)
1403 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1404 S_SET_OTHER (l->label, STO_MIPS16);
1406 val = S_GET_VALUE (l->label);
1408 S_SET_VALUE (l->label, val + 1);
1413 /* Output an instruction. PLACE is where to put the instruction; if
1414 it is NULL, this uses frag_more to get room. IP is the instruction
1415 information. ADDRESS_EXPR is an operand of the instruction to be
1416 used with RELOC_TYPE. */
1419 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1421 struct mips_cl_insn *ip;
1422 expressionS *address_expr;
1423 bfd_reloc_code_real_type *reloc_type;
1424 boolean unmatched_hi;
1426 register unsigned long prev_pinfo, pinfo;
1431 /* Mark instruction labels in mips16 mode. */
1432 mips16_mark_labels ();
1434 prev_pinfo = prev_insn.insn_mo->pinfo;
1435 pinfo = ip->insn_mo->pinfo;
1437 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1441 /* If the previous insn required any delay slots, see if we need
1442 to insert a NOP or two. There are eight kinds of possible
1443 hazards, of which an instruction can have at most one type.
1444 (1) a load from memory delay
1445 (2) a load from a coprocessor delay
1446 (3) an unconditional branch delay
1447 (4) a conditional branch delay
1448 (5) a move to coprocessor register delay
1449 (6) a load coprocessor register from memory delay
1450 (7) a coprocessor condition code delay
1451 (8) a HI/LO special register delay
1453 There are a lot of optimizations we could do that we don't.
1454 In particular, we do not, in general, reorder instructions.
1455 If you use gcc with optimization, it will reorder
1456 instructions and generally do much more optimization then we
1457 do here; repeating all that work in the assembler would only
1458 benefit hand written assembly code, and does not seem worth
1461 /* This is how a NOP is emitted. */
1462 #define emit_nop() \
1464 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1465 : md_number_to_chars (frag_more (4), 0, 4))
1467 /* The previous insn might require a delay slot, depending upon
1468 the contents of the current insn. */
1469 if (! mips_opts.mips16
1470 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1471 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1472 && ! cop_interlocks)
1473 || (! gpr_interlocks
1474 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1476 /* A load from a coprocessor or from memory. All load
1477 delays delay the use of general register rt for one
1478 instruction on the r3000. The r6000 and r4000 use
1480 /* Itbl support may require additional care here. */
1481 know (prev_pinfo & INSN_WRITE_GPR_T);
1482 if (mips_optimize == 0
1483 || insn_uses_reg (ip,
1484 ((prev_insn.insn_opcode >> OP_SH_RT)
1489 else if (! mips_opts.mips16
1490 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1491 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1492 && ! cop_interlocks)
1493 || (mips_opts.isa == ISA_MIPS1
1494 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1496 /* A generic coprocessor delay. The previous instruction
1497 modified a coprocessor general or control register. If
1498 it modified a control register, we need to avoid any
1499 coprocessor instruction (this is probably not always
1500 required, but it sometimes is). If it modified a general
1501 register, we avoid using that register.
1503 On the r6000 and r4000 loading a coprocessor register
1504 from memory is interlocked, and does not require a delay.
1506 This case is not handled very well. There is no special
1507 knowledge of CP0 handling, and the coprocessors other
1508 than the floating point unit are not distinguished at
1510 /* Itbl support may require additional care here. FIXME!
1511 Need to modify this to include knowledge about
1512 user specified delays! */
1513 if (prev_pinfo & INSN_WRITE_FPR_T)
1515 if (mips_optimize == 0
1516 || insn_uses_reg (ip,
1517 ((prev_insn.insn_opcode >> OP_SH_FT)
1522 else if (prev_pinfo & INSN_WRITE_FPR_S)
1524 if (mips_optimize == 0
1525 || insn_uses_reg (ip,
1526 ((prev_insn.insn_opcode >> OP_SH_FS)
1533 /* We don't know exactly what the previous instruction
1534 does. If the current instruction uses a coprocessor
1535 register, we must insert a NOP. If previous
1536 instruction may set the condition codes, and the
1537 current instruction uses them, we must insert two
1539 /* Itbl support may require additional care here. */
1540 if (mips_optimize == 0
1541 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1542 && (pinfo & INSN_READ_COND_CODE)))
1544 else if (pinfo & INSN_COP)
1548 else if (! mips_opts.mips16
1549 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1550 && (prev_pinfo & INSN_WRITE_COND_CODE)
1551 && ! cop_interlocks)
1553 /* The previous instruction sets the coprocessor condition
1554 codes, but does not require a general coprocessor delay
1555 (this means it is a floating point comparison
1556 instruction). If this instruction uses the condition
1557 codes, we need to insert a single NOP. */
1558 /* Itbl support may require additional care here. */
1559 if (mips_optimize == 0
1560 || (pinfo & INSN_READ_COND_CODE))
1564 /* If we're fixing up mfhi/mflo for the r7000 and the
1565 previous insn was an mfhi/mflo and the current insn
1566 reads the register that the mfhi/mflo wrote to, then
1569 else if (mips_7000_hilo_fix
1570 && MF_HILO_INSN (prev_pinfo)
1571 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1578 /* If we're fixing up mfhi/mflo for the r7000 and the
1579 2nd previous insn was an mfhi/mflo and the current insn
1580 reads the register that the mfhi/mflo wrote to, then
1583 else if (mips_7000_hilo_fix
1584 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1585 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1593 else if (prev_pinfo & INSN_READ_LO)
1595 /* The previous instruction reads the LO register; if the
1596 current instruction writes to the LO register, we must
1597 insert two NOPS. Some newer processors have interlocks.
1598 Also the tx39's multiply instructions can be exectuted
1599 immediatly after a read from HI/LO (without the delay),
1600 though the tx39's divide insns still do require the
1602 if (! (hilo_interlocks
1603 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1604 && (mips_optimize == 0
1605 || (pinfo & INSN_WRITE_LO)))
1607 /* Most mips16 branch insns don't have a delay slot.
1608 If a read from LO is immediately followed by a branch
1609 to a write to LO we have a read followed by a write
1610 less than 2 insns away. We assume the target of
1611 a branch might be a write to LO, and insert a nop
1612 between a read and an immediately following branch. */
1613 else if (mips_opts.mips16
1614 && (mips_optimize == 0
1615 || (pinfo & MIPS16_INSN_BRANCH)))
1618 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1620 /* The previous instruction reads the HI register; if the
1621 current instruction writes to the HI register, we must
1622 insert a NOP. Some newer processors have interlocks.
1623 Also the note tx39's multiply above. */
1624 if (! (hilo_interlocks
1625 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1626 && (mips_optimize == 0
1627 || (pinfo & INSN_WRITE_HI)))
1629 /* Most mips16 branch insns don't have a delay slot.
1630 If a read from HI is immediately followed by a branch
1631 to a write to HI we have a read followed by a write
1632 less than 2 insns away. We assume the target of
1633 a branch might be a write to HI, and insert a nop
1634 between a read and an immediately following branch. */
1635 else if (mips_opts.mips16
1636 && (mips_optimize == 0
1637 || (pinfo & MIPS16_INSN_BRANCH)))
1641 /* If the previous instruction was in a noreorder section, then
1642 we don't want to insert the nop after all. */
1643 /* Itbl support may require additional care here. */
1644 if (prev_insn_unreordered)
1647 /* There are two cases which require two intervening
1648 instructions: 1) setting the condition codes using a move to
1649 coprocessor instruction which requires a general coprocessor
1650 delay and then reading the condition codes 2) reading the HI
1651 or LO register and then writing to it (except on processors
1652 which have interlocks). If we are not already emitting a NOP
1653 instruction, we must check for these cases compared to the
1654 instruction previous to the previous instruction. */
1655 if ((! mips_opts.mips16
1656 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1657 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1658 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1659 && (pinfo & INSN_READ_COND_CODE)
1660 && ! cop_interlocks)
1661 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1662 && (pinfo & INSN_WRITE_LO)
1663 && ! (hilo_interlocks
1664 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1665 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1666 && (pinfo & INSN_WRITE_HI)
1667 && ! (hilo_interlocks
1668 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1673 if (prev_prev_insn_unreordered)
1676 if (prev_prev_nop && nops == 0)
1679 /* If we are being given a nop instruction, don't bother with
1680 one of the nops we would otherwise output. This will only
1681 happen when a nop instruction is used with mips_optimize set
1684 && ! mips_opts.noreorder
1685 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1688 /* Now emit the right number of NOP instructions. */
1689 if (nops > 0 && ! mips_opts.noreorder)
1692 unsigned long old_frag_offset;
1694 struct insn_label_list *l;
1696 old_frag = frag_now;
1697 old_frag_offset = frag_now_fix ();
1699 for (i = 0; i < nops; i++)
1704 listing_prev_line ();
1705 /* We may be at the start of a variant frag. In case we
1706 are, make sure there is enough space for the frag
1707 after the frags created by listing_prev_line. The
1708 argument to frag_grow here must be at least as large
1709 as the argument to all other calls to frag_grow in
1710 this file. We don't have to worry about being in the
1711 middle of a variant frag, because the variants insert
1712 all needed nop instructions themselves. */
1716 for (l = insn_labels; l != NULL; l = l->next)
1720 assert (S_GET_SEGMENT (l->label) == now_seg);
1721 symbol_set_frag (l->label, frag_now);
1722 val = (valueT) frag_now_fix ();
1723 /* mips16 text labels are stored as odd. */
1724 if (mips_opts.mips16)
1726 S_SET_VALUE (l->label, val);
1729 #ifndef NO_ECOFF_DEBUGGING
1730 if (ECOFF_DEBUGGING)
1731 ecoff_fix_loc (old_frag, old_frag_offset);
1734 else if (prev_nop_frag != NULL)
1736 /* We have a frag holding nops we may be able to remove. If
1737 we don't need any nops, we can decrease the size of
1738 prev_nop_frag by the size of one instruction. If we do
1739 need some nops, we count them in prev_nops_required. */
1740 if (prev_nop_frag_since == 0)
1744 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1745 --prev_nop_frag_holds;
1748 prev_nop_frag_required += nops;
1752 if (prev_prev_nop == 0)
1754 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1755 --prev_nop_frag_holds;
1758 ++prev_nop_frag_required;
1761 if (prev_nop_frag_holds <= prev_nop_frag_required)
1762 prev_nop_frag = NULL;
1764 ++prev_nop_frag_since;
1766 /* Sanity check: by the time we reach the second instruction
1767 after prev_nop_frag, we should have used up all the nops
1768 one way or another. */
1769 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1773 if (*reloc_type > BFD_RELOC_UNUSED)
1775 /* We need to set up a variant frag. */
1776 assert (mips_opts.mips16 && address_expr != NULL);
1777 f = frag_var (rs_machine_dependent, 4, 0,
1778 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
1779 mips16_small, mips16_ext,
1781 & INSN_UNCOND_BRANCH_DELAY),
1782 (*prev_insn_reloc_type
1783 == BFD_RELOC_MIPS16_JMP)),
1784 make_expr_symbol (address_expr), 0, NULL);
1786 else if (place != NULL)
1788 else if (mips_opts.mips16
1790 && *reloc_type != BFD_RELOC_MIPS16_JMP)
1792 /* Make sure there is enough room to swap this instruction with
1793 a following jump instruction. */
1799 if (mips_opts.mips16
1800 && mips_opts.noreorder
1801 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1802 as_warn (_("extended instruction in delay slot"));
1807 fixp[0] = fixp[1] = fixp[2] = NULL;
1808 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
1810 if (address_expr->X_op == O_constant)
1814 switch (*reloc_type)
1817 ip->insn_opcode |= address_expr->X_add_number;
1820 case BFD_RELOC_MIPS_HIGHEST:
1821 tmp = (address_expr->X_add_number + 0x800080008000) >> 16;
1823 ip->insn_opcode |= (tmp >> 16) & 0xffff;
1826 case BFD_RELOC_MIPS_HIGHER:
1827 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
1828 ip->insn_opcode |= (tmp >> 16) & 0xffff;
1831 case BFD_RELOC_HI16_S:
1832 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
1836 case BFD_RELOC_HI16:
1837 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
1840 case BFD_RELOC_LO16:
1841 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1844 case BFD_RELOC_MIPS_JMP:
1845 if ((address_expr->X_add_number & 3) != 0)
1846 as_bad (_("jump to misaligned address (0x%lx)"),
1847 (unsigned long) address_expr->X_add_number);
1848 if (address_expr->X_add_number & ~0xfffffff
1849 || address_expr->X_add_number > 0x7fffffc)
1850 as_bad (_("jump address range overflow (0x%lx)"),
1851 (unsigned long) address_expr->X_add_number);
1852 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
1855 case BFD_RELOC_MIPS16_JMP:
1856 if ((address_expr->X_add_number & 3) != 0)
1857 as_bad (_("jump to misaligned address (0x%lx)"),
1858 (unsigned long) address_expr->X_add_number);
1859 if (address_expr->X_add_number & ~0xfffffff
1860 || address_expr->X_add_number > 0x7fffffc)
1861 as_bad (_("jump address range overflow (0x%lx)"),
1862 (unsigned long) address_expr->X_add_number);
1864 (((address_expr->X_add_number & 0x7c0000) << 3)
1865 | ((address_expr->X_add_number & 0xf800000) >> 7)
1866 | ((address_expr->X_add_number & 0x3fffc) >> 2));
1869 case BFD_RELOC_16_PCREL:
1870 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1873 case BFD_RELOC_16_PCREL_S2:
1883 /* Don't generate a reloc if we are writing into a variant frag. */
1886 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1888 (*reloc_type == BFD_RELOC_16_PCREL
1889 || *reloc_type == BFD_RELOC_16_PCREL_S2),
1892 /* These relocations can have an addend that won't fit in
1893 4 octets for 64bit assembly. */
1894 if (HAVE_64BIT_GPRS &&
1895 (*reloc_type == BFD_RELOC_16
1896 || *reloc_type == BFD_RELOC_32
1897 || *reloc_type == BFD_RELOC_MIPS_JMP
1898 || *reloc_type == BFD_RELOC_HI16_S
1899 || *reloc_type == BFD_RELOC_LO16
1900 || *reloc_type == BFD_RELOC_GPREL16
1901 || *reloc_type == BFD_RELOC_MIPS_LITERAL
1902 || *reloc_type == BFD_RELOC_GPREL32
1903 || *reloc_type == BFD_RELOC_64
1904 || *reloc_type == BFD_RELOC_CTOR
1905 || *reloc_type == BFD_RELOC_MIPS_SUB
1906 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
1907 || *reloc_type == BFD_RELOC_MIPS_HIGHER
1908 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
1909 || *reloc_type == BFD_RELOC_MIPS_REL16
1910 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
1911 fixp[0]->fx_no_overflow = 1;
1915 struct mips_hi_fixup *hi_fixup;
1917 assert (*reloc_type == BFD_RELOC_HI16_S);
1918 hi_fixup = ((struct mips_hi_fixup *)
1919 xmalloc (sizeof (struct mips_hi_fixup)));
1920 hi_fixup->fixp = fixp[0];
1921 hi_fixup->seg = now_seg;
1922 hi_fixup->next = mips_hi_fixup_list;
1923 mips_hi_fixup_list = hi_fixup;
1926 if (reloc_type[1] != BFD_RELOC_UNUSED)
1928 /* FIXME: This symbol can be one of
1929 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
1930 address_expr->X_op = O_absent;
1931 address_expr->X_add_symbol = 0;
1932 address_expr->X_add_number = 0;
1934 fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal,
1935 4, address_expr, false,
1938 /* These relocations can have an addend that won't fit in
1939 4 octets for 64bit assembly. */
1940 if (HAVE_64BIT_GPRS &&
1941 (*reloc_type == BFD_RELOC_16
1942 || *reloc_type == BFD_RELOC_32
1943 || *reloc_type == BFD_RELOC_MIPS_JMP
1944 || *reloc_type == BFD_RELOC_HI16_S
1945 || *reloc_type == BFD_RELOC_LO16
1946 || *reloc_type == BFD_RELOC_GPREL16
1947 || *reloc_type == BFD_RELOC_MIPS_LITERAL
1948 || *reloc_type == BFD_RELOC_GPREL32
1949 || *reloc_type == BFD_RELOC_64
1950 || *reloc_type == BFD_RELOC_CTOR
1951 || *reloc_type == BFD_RELOC_MIPS_SUB
1952 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
1953 || *reloc_type == BFD_RELOC_MIPS_HIGHER
1954 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
1955 || *reloc_type == BFD_RELOC_MIPS_REL16
1956 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
1957 fixp[1]->fx_no_overflow = 1;
1959 if (reloc_type[2] != BFD_RELOC_UNUSED)
1961 address_expr->X_op = O_absent;
1962 address_expr->X_add_symbol = 0;
1963 address_expr->X_add_number = 0;
1965 fixp[2] = fix_new_exp (frag_now,
1966 f - frag_now->fr_literal, 4,
1967 address_expr, false,
1970 /* These relocations can have an addend that won't fit in
1971 4 octets for 64bit assembly. */
1972 if (HAVE_64BIT_GPRS &&
1973 (*reloc_type == BFD_RELOC_16
1974 || *reloc_type == BFD_RELOC_32
1975 || *reloc_type == BFD_RELOC_MIPS_JMP
1976 || *reloc_type == BFD_RELOC_HI16_S
1977 || *reloc_type == BFD_RELOC_LO16
1978 || *reloc_type == BFD_RELOC_GPREL16
1979 || *reloc_type == BFD_RELOC_MIPS_LITERAL
1980 || *reloc_type == BFD_RELOC_GPREL32
1981 || *reloc_type == BFD_RELOC_64
1982 || *reloc_type == BFD_RELOC_CTOR
1983 || *reloc_type == BFD_RELOC_MIPS_SUB
1984 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
1985 || *reloc_type == BFD_RELOC_MIPS_HIGHER
1986 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
1987 || *reloc_type == BFD_RELOC_MIPS_REL16
1988 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
1989 fixp[2]->fx_no_overflow = 1;
1996 if (! mips_opts.mips16)
1998 md_number_to_chars (f, ip->insn_opcode, 4);
2000 dwarf2_emit_insn (4);
2003 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2005 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2006 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2008 dwarf2_emit_insn (4);
2015 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2018 md_number_to_chars (f, ip->insn_opcode, 2);
2020 dwarf2_emit_insn (ip->use_extend ? 4 : 2);
2024 /* Update the register mask information. */
2025 if (! mips_opts.mips16)
2027 if (pinfo & INSN_WRITE_GPR_D)
2028 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2029 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2030 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2031 if (pinfo & INSN_READ_GPR_S)
2032 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2033 if (pinfo & INSN_WRITE_GPR_31)
2034 mips_gprmask |= 1 << RA;
2035 if (pinfo & INSN_WRITE_FPR_D)
2036 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2037 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2038 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2039 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2040 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2041 if ((pinfo & INSN_READ_FPR_R) != 0)
2042 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2043 if (pinfo & INSN_COP)
2045 /* We don't keep enough information to sort these cases out.
2046 The itbl support does keep this information however, although
2047 we currently don't support itbl fprmats as part of the cop
2048 instruction. May want to add this support in the future. */
2050 /* Never set the bit for $0, which is always zero. */
2051 mips_gprmask &= ~1 << 0;
2055 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2056 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2057 & MIPS16OP_MASK_RX);
2058 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2059 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2060 & MIPS16OP_MASK_RY);
2061 if (pinfo & MIPS16_INSN_WRITE_Z)
2062 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2063 & MIPS16OP_MASK_RZ);
2064 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2065 mips_gprmask |= 1 << TREG;
2066 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2067 mips_gprmask |= 1 << SP;
2068 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2069 mips_gprmask |= 1 << RA;
2070 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2071 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2072 if (pinfo & MIPS16_INSN_READ_Z)
2073 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2074 & MIPS16OP_MASK_MOVE32Z);
2075 if (pinfo & MIPS16_INSN_READ_GPR_X)
2076 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2077 & MIPS16OP_MASK_REGR32);
2080 if (place == NULL && ! mips_opts.noreorder)
2082 /* Filling the branch delay slot is more complex. We try to
2083 switch the branch with the previous instruction, which we can
2084 do if the previous instruction does not set up a condition
2085 that the branch tests and if the branch is not itself the
2086 target of any branch. */
2087 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2088 || (pinfo & INSN_COND_BRANCH_DELAY))
2090 if (mips_optimize < 2
2091 /* If we have seen .set volatile or .set nomove, don't
2093 || mips_opts.nomove != 0
2094 /* If we had to emit any NOP instructions, then we
2095 already know we can not swap. */
2097 /* If we don't even know the previous insn, we can not
2099 || ! prev_insn_valid
2100 /* If the previous insn is already in a branch delay
2101 slot, then we can not swap. */
2102 || prev_insn_is_delay_slot
2103 /* If the previous previous insn was in a .set
2104 noreorder, we can't swap. Actually, the MIPS
2105 assembler will swap in this situation. However, gcc
2106 configured -with-gnu-as will generate code like
2112 in which we can not swap the bne and INSN. If gcc is
2113 not configured -with-gnu-as, it does not output the
2114 .set pseudo-ops. We don't have to check
2115 prev_insn_unreordered, because prev_insn_valid will
2116 be 0 in that case. We don't want to use
2117 prev_prev_insn_valid, because we do want to be able
2118 to swap at the start of a function. */
2119 || prev_prev_insn_unreordered
2120 /* If the branch is itself the target of a branch, we
2121 can not swap. We cheat on this; all we check for is
2122 whether there is a label on this instruction. If
2123 there are any branches to anything other than a
2124 label, users must use .set noreorder. */
2125 || insn_labels != NULL
2126 /* If the previous instruction is in a variant frag, we
2127 can not do the swap. This does not apply to the
2128 mips16, which uses variant frags for different
2130 || (! mips_opts.mips16
2131 && prev_insn_frag->fr_type == rs_machine_dependent)
2132 /* If the branch reads the condition codes, we don't
2133 even try to swap, because in the sequence
2138 we can not swap, and I don't feel like handling that
2140 || (! mips_opts.mips16
2141 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2142 && (pinfo & INSN_READ_COND_CODE))
2143 /* We can not swap with an instruction that requires a
2144 delay slot, becase the target of the branch might
2145 interfere with that instruction. */
2146 || (! mips_opts.mips16
2147 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2149 /* Itbl support may require additional care here. */
2150 & (INSN_LOAD_COPROC_DELAY
2151 | INSN_COPROC_MOVE_DELAY
2152 | INSN_WRITE_COND_CODE)))
2153 || (! (hilo_interlocks
2154 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2158 || (! mips_opts.mips16
2160 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2161 || (! mips_opts.mips16
2162 && mips_opts.isa == ISA_MIPS1
2163 /* Itbl support may require additional care here. */
2164 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2165 /* We can not swap with a branch instruction. */
2167 & (INSN_UNCOND_BRANCH_DELAY
2168 | INSN_COND_BRANCH_DELAY
2169 | INSN_COND_BRANCH_LIKELY))
2170 /* We do not swap with a trap instruction, since it
2171 complicates trap handlers to have the trap
2172 instruction be in a delay slot. */
2173 || (prev_pinfo & INSN_TRAP)
2174 /* If the branch reads a register that the previous
2175 instruction sets, we can not swap. */
2176 || (! mips_opts.mips16
2177 && (prev_pinfo & INSN_WRITE_GPR_T)
2178 && insn_uses_reg (ip,
2179 ((prev_insn.insn_opcode >> OP_SH_RT)
2182 || (! mips_opts.mips16
2183 && (prev_pinfo & INSN_WRITE_GPR_D)
2184 && insn_uses_reg (ip,
2185 ((prev_insn.insn_opcode >> OP_SH_RD)
2188 || (mips_opts.mips16
2189 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2190 && insn_uses_reg (ip,
2191 ((prev_insn.insn_opcode
2193 & MIPS16OP_MASK_RX),
2195 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2196 && insn_uses_reg (ip,
2197 ((prev_insn.insn_opcode
2199 & MIPS16OP_MASK_RY),
2201 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2202 && insn_uses_reg (ip,
2203 ((prev_insn.insn_opcode
2205 & MIPS16OP_MASK_RZ),
2207 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2208 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2209 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2210 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2211 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2212 && insn_uses_reg (ip,
2213 MIPS16OP_EXTRACT_REG32R (prev_insn.
2216 /* If the branch writes a register that the previous
2217 instruction sets, we can not swap (we know that
2218 branches write only to RD or to $31). */
2219 || (! mips_opts.mips16
2220 && (prev_pinfo & INSN_WRITE_GPR_T)
2221 && (((pinfo & INSN_WRITE_GPR_D)
2222 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2223 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2224 || ((pinfo & INSN_WRITE_GPR_31)
2225 && (((prev_insn.insn_opcode >> OP_SH_RT)
2228 || (! mips_opts.mips16
2229 && (prev_pinfo & INSN_WRITE_GPR_D)
2230 && (((pinfo & INSN_WRITE_GPR_D)
2231 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2232 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2233 || ((pinfo & INSN_WRITE_GPR_31)
2234 && (((prev_insn.insn_opcode >> OP_SH_RD)
2237 || (mips_opts.mips16
2238 && (pinfo & MIPS16_INSN_WRITE_31)
2239 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2240 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2241 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2243 /* If the branch writes a register that the previous
2244 instruction reads, we can not swap (we know that
2245 branches only write to RD or to $31). */
2246 || (! mips_opts.mips16
2247 && (pinfo & INSN_WRITE_GPR_D)
2248 && insn_uses_reg (&prev_insn,
2249 ((ip->insn_opcode >> OP_SH_RD)
2252 || (! mips_opts.mips16
2253 && (pinfo & INSN_WRITE_GPR_31)
2254 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2255 || (mips_opts.mips16
2256 && (pinfo & MIPS16_INSN_WRITE_31)
2257 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2258 /* If we are generating embedded PIC code, the branch
2259 might be expanded into a sequence which uses $at, so
2260 we can't swap with an instruction which reads it. */
2261 || (mips_pic == EMBEDDED_PIC
2262 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2263 /* If the previous previous instruction has a load
2264 delay, and sets a register that the branch reads, we
2266 || (! mips_opts.mips16
2267 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2268 /* Itbl support may require additional care here. */
2269 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2270 || (! gpr_interlocks
2271 && (prev_prev_insn.insn_mo->pinfo
2272 & INSN_LOAD_MEMORY_DELAY)))
2273 && insn_uses_reg (ip,
2274 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2277 /* If one instruction sets a condition code and the
2278 other one uses a condition code, we can not swap. */
2279 || ((pinfo & INSN_READ_COND_CODE)
2280 && (prev_pinfo & INSN_WRITE_COND_CODE))
2281 || ((pinfo & INSN_WRITE_COND_CODE)
2282 && (prev_pinfo & INSN_READ_COND_CODE))
2283 /* If the previous instruction uses the PC, we can not
2285 || (mips_opts.mips16
2286 && (prev_pinfo & MIPS16_INSN_READ_PC))
2287 /* If the previous instruction was extended, we can not
2289 || (mips_opts.mips16 && prev_insn_extended)
2290 /* If the previous instruction had a fixup in mips16
2291 mode, we can not swap. This normally means that the
2292 previous instruction was a 4 byte branch anyhow. */
2293 || (mips_opts.mips16 && prev_insn_fixp[0])
2294 /* If the previous instruction is a sync, sync.l, or
2295 sync.p, we can not swap. */
2296 || (prev_pinfo & INSN_SYNC))
2298 /* We could do even better for unconditional branches to
2299 portions of this object file; we could pick up the
2300 instruction at the destination, put it in the delay
2301 slot, and bump the destination address. */
2303 /* Update the previous insn information. */
2304 prev_prev_insn = *ip;
2305 prev_insn.insn_mo = &dummy_opcode;
2309 /* It looks like we can actually do the swap. */
2310 if (! mips_opts.mips16)
2315 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2316 memcpy (temp, prev_f, 4);
2317 memcpy (prev_f, f, 4);
2318 memcpy (f, temp, 4);
2319 if (prev_insn_fixp[0])
2321 prev_insn_fixp[0]->fx_frag = frag_now;
2322 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2324 if (prev_insn_fixp[1])
2326 prev_insn_fixp[1]->fx_frag = frag_now;
2327 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2329 if (prev_insn_fixp[2])
2331 prev_insn_fixp[2]->fx_frag = frag_now;
2332 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2336 fixp[0]->fx_frag = prev_insn_frag;
2337 fixp[0]->fx_where = prev_insn_where;
2341 fixp[1]->fx_frag = prev_insn_frag;
2342 fixp[1]->fx_where = prev_insn_where;
2346 fixp[2]->fx_frag = prev_insn_frag;
2347 fixp[2]->fx_where = prev_insn_where;
2355 assert (prev_insn_fixp[0] == NULL);
2356 assert (prev_insn_fixp[1] == NULL);
2357 assert (prev_insn_fixp[2] == NULL);
2358 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2359 memcpy (temp, prev_f, 2);
2360 memcpy (prev_f, f, 2);
2361 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2363 assert (*reloc_type == BFD_RELOC_UNUSED);
2364 memcpy (f, temp, 2);
2368 memcpy (f, f + 2, 2);
2369 memcpy (f + 2, temp, 2);
2373 fixp[0]->fx_frag = prev_insn_frag;
2374 fixp[0]->fx_where = prev_insn_where;
2378 fixp[1]->fx_frag = prev_insn_frag;
2379 fixp[1]->fx_where = prev_insn_where;
2383 fixp[2]->fx_frag = prev_insn_frag;
2384 fixp[2]->fx_where = prev_insn_where;
2388 /* Update the previous insn information; leave prev_insn
2390 prev_prev_insn = *ip;
2392 prev_insn_is_delay_slot = 1;
2394 /* If that was an unconditional branch, forget the previous
2395 insn information. */
2396 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2398 prev_prev_insn.insn_mo = &dummy_opcode;
2399 prev_insn.insn_mo = &dummy_opcode;
2402 prev_insn_fixp[0] = NULL;
2403 prev_insn_fixp[1] = NULL;
2404 prev_insn_fixp[2] = NULL;
2405 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2406 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2407 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2408 prev_insn_extended = 0;
2410 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2412 /* We don't yet optimize a branch likely. What we should do
2413 is look at the target, copy the instruction found there
2414 into the delay slot, and increment the branch to jump to
2415 the next instruction. */
2417 /* Update the previous insn information. */
2418 prev_prev_insn = *ip;
2419 prev_insn.insn_mo = &dummy_opcode;
2420 prev_insn_fixp[0] = NULL;
2421 prev_insn_fixp[1] = NULL;
2422 prev_insn_fixp[2] = NULL;
2423 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2424 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2425 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2426 prev_insn_extended = 0;
2430 /* Update the previous insn information. */
2432 prev_prev_insn.insn_mo = &dummy_opcode;
2434 prev_prev_insn = prev_insn;
2437 /* Any time we see a branch, we always fill the delay slot
2438 immediately; since this insn is not a branch, we know it
2439 is not in a delay slot. */
2440 prev_insn_is_delay_slot = 0;
2442 prev_insn_fixp[0] = fixp[0];
2443 prev_insn_fixp[1] = fixp[1];
2444 prev_insn_fixp[2] = fixp[2];
2445 prev_insn_reloc_type[0] = reloc_type[0];
2446 prev_insn_reloc_type[1] = reloc_type[1];
2447 prev_insn_reloc_type[2] = reloc_type[2];
2448 if (mips_opts.mips16)
2449 prev_insn_extended = (ip->use_extend
2450 || *reloc_type > BFD_RELOC_UNUSED);
2453 prev_prev_insn_unreordered = prev_insn_unreordered;
2454 prev_insn_unreordered = 0;
2455 prev_insn_frag = frag_now;
2456 prev_insn_where = f - frag_now->fr_literal;
2457 prev_insn_valid = 1;
2459 else if (place == NULL)
2461 /* We need to record a bit of information even when we are not
2462 reordering, in order to determine the base address for mips16
2463 PC relative relocs. */
2464 prev_prev_insn = prev_insn;
2466 prev_insn_reloc_type[0] = reloc_type[0];
2467 prev_insn_reloc_type[1] = reloc_type[1];
2468 prev_insn_reloc_type[2] = reloc_type[2];
2469 prev_prev_insn_unreordered = prev_insn_unreordered;
2470 prev_insn_unreordered = 1;
2473 /* We just output an insn, so the next one doesn't have a label. */
2474 mips_clear_insn_labels ();
2476 /* We must ensure that a fixup associated with an unmatched %hi
2477 reloc does not become a variant frag. Otherwise, the
2478 rearrangement of %hi relocs in frob_file may confuse
2482 frag_wane (frag_now);
2487 /* This function forgets that there was any previous instruction or
2488 label. If PRESERVE is non-zero, it remembers enough information to
2489 know whether nops are needed before a noreorder section. */
2492 mips_no_prev_insn (preserve)
2497 prev_insn.insn_mo = &dummy_opcode;
2498 prev_prev_insn.insn_mo = &dummy_opcode;
2499 prev_nop_frag = NULL;
2500 prev_nop_frag_holds = 0;
2501 prev_nop_frag_required = 0;
2502 prev_nop_frag_since = 0;
2504 prev_insn_valid = 0;
2505 prev_insn_is_delay_slot = 0;
2506 prev_insn_unreordered = 0;
2507 prev_insn_extended = 0;
2508 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2509 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2510 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2511 prev_prev_insn_unreordered = 0;
2512 mips_clear_insn_labels ();
2515 /* This function must be called whenever we turn on noreorder or emit
2516 something other than instructions. It inserts any NOPS which might
2517 be needed by the previous instruction, and clears the information
2518 kept for the previous instructions. The INSNS parameter is true if
2519 instructions are to follow. */
2522 mips_emit_delays (insns)
2525 if (! mips_opts.noreorder)
2530 if ((! mips_opts.mips16
2531 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2532 && (! cop_interlocks
2533 && (prev_insn.insn_mo->pinfo
2534 & (INSN_LOAD_COPROC_DELAY
2535 | INSN_COPROC_MOVE_DELAY
2536 | INSN_WRITE_COND_CODE))))
2537 || (! hilo_interlocks
2538 && (prev_insn.insn_mo->pinfo
2541 || (! mips_opts.mips16
2543 && (prev_insn.insn_mo->pinfo
2544 & INSN_LOAD_MEMORY_DELAY))
2545 || (! mips_opts.mips16
2546 && mips_opts.isa == ISA_MIPS1
2547 && (prev_insn.insn_mo->pinfo
2548 & INSN_COPROC_MEMORY_DELAY)))
2550 /* Itbl support may require additional care here. */
2552 if ((! mips_opts.mips16
2553 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2554 && (! cop_interlocks
2555 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2556 || (! hilo_interlocks
2557 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2558 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2561 if (prev_insn_unreordered)
2564 else if ((! mips_opts.mips16
2565 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2566 && (! cop_interlocks
2567 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2568 || (! hilo_interlocks
2569 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2570 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2572 /* Itbl support may require additional care here. */
2573 if (! prev_prev_insn_unreordered)
2579 struct insn_label_list *l;
2583 /* Record the frag which holds the nop instructions, so
2584 that we can remove them if we don't need them. */
2585 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2586 prev_nop_frag = frag_now;
2587 prev_nop_frag_holds = nops;
2588 prev_nop_frag_required = 0;
2589 prev_nop_frag_since = 0;
2592 for (; nops > 0; --nops)
2597 /* Move on to a new frag, so that it is safe to simply
2598 decrease the size of prev_nop_frag. */
2599 frag_wane (frag_now);
2603 for (l = insn_labels; l != NULL; l = l->next)
2607 assert (S_GET_SEGMENT (l->label) == now_seg);
2608 symbol_set_frag (l->label, frag_now);
2609 val = (valueT) frag_now_fix ();
2610 /* mips16 text labels are stored as odd. */
2611 if (mips_opts.mips16)
2613 S_SET_VALUE (l->label, val);
2618 /* Mark instruction labels in mips16 mode. */
2620 mips16_mark_labels ();
2622 mips_no_prev_insn (insns);
2625 /* Build an instruction created by a macro expansion. This is passed
2626 a pointer to the count of instructions created so far, an
2627 expression, the name of the instruction to build, an operand format
2628 string, and corresponding arguments. */
2632 macro_build (char *place,
2640 macro_build (place, counter, ep, name, fmt, va_alist)
2649 struct mips_cl_insn insn;
2650 bfd_reloc_code_real_type r[3];
2654 va_start (args, fmt);
2660 * If the macro is about to expand into a second instruction,
2661 * print a warning if needed. We need to pass ip as a parameter
2662 * to generate a better warning message here...
2664 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2665 as_warn (_("Macro instruction expanded into multiple instructions"));
2668 * If the macro is about to expand into a second instruction,
2669 * and it is in a delay slot, print a warning.
2673 && mips_opts.noreorder
2674 && (prev_prev_insn.insn_mo->pinfo
2675 & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY
2676 | INSN_COND_BRANCH_LIKELY)) != 0)
2677 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2680 ++*counter; /* bump instruction counter */
2682 if (mips_opts.mips16)
2684 mips16_macro_build (place, counter, ep, name, fmt, args);
2689 r[0] = BFD_RELOC_UNUSED;
2690 r[1] = BFD_RELOC_UNUSED;
2691 r[2] = BFD_RELOC_UNUSED;
2692 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2693 assert (insn.insn_mo);
2694 assert (strcmp (name, insn.insn_mo->name) == 0);
2696 /* Search until we get a match for NAME. */
2699 /* It is assumed here that macros will never generate
2700 MDMX or MIPS-3D instructions. */
2701 if (strcmp (fmt, insn.insn_mo->args) == 0
2702 && insn.insn_mo->pinfo != INSN_MACRO
2703 && OPCODE_IS_MEMBER (insn.insn_mo,
2705 | (mips_opts.mips16 ? INSN_MIPS16 : 0)),
2707 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2711 assert (insn.insn_mo->name);
2712 assert (strcmp (name, insn.insn_mo->name) == 0);
2715 insn.insn_opcode = insn.insn_mo->match;
2731 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2735 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2740 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2745 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2750 int tmp = va_arg (args, int);
2752 insn.insn_opcode |= tmp << OP_SH_RT;
2753 insn.insn_opcode |= tmp << OP_SH_RD;
2759 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2766 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2770 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2774 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2778 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2782 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2789 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2795 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2796 assert (*r == BFD_RELOC_GPREL16
2797 || *r == BFD_RELOC_MIPS_LITERAL
2798 || *r == BFD_RELOC_MIPS_HIGHER
2799 || *r == BFD_RELOC_HI16_S
2800 || *r == BFD_RELOC_LO16
2801 || *r == BFD_RELOC_MIPS_GOT16
2802 || *r == BFD_RELOC_MIPS_CALL16
2803 || *r == BFD_RELOC_MIPS_GOT_DISP
2804 || *r == BFD_RELOC_MIPS_GOT_PAGE
2805 || *r == BFD_RELOC_MIPS_GOT_OFST
2806 || *r == BFD_RELOC_MIPS_GOT_LO16
2807 || *r == BFD_RELOC_MIPS_CALL_LO16
2808 || (ep->X_op == O_subtract
2809 && *r == BFD_RELOC_PCREL_LO16));
2813 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2815 && (ep->X_op == O_constant
2816 || (ep->X_op == O_symbol
2817 && (*r == BFD_RELOC_MIPS_HIGHEST
2818 || *r == BFD_RELOC_HI16_S
2819 || *r == BFD_RELOC_HI16
2820 || *r == BFD_RELOC_GPREL16
2821 || *r == BFD_RELOC_MIPS_GOT_HI16
2822 || *r == BFD_RELOC_MIPS_CALL_HI16))
2823 || (ep->X_op == O_subtract
2824 && *r == BFD_RELOC_PCREL_HI16_S)));
2828 assert (ep != NULL);
2830 * This allows macro() to pass an immediate expression for
2831 * creating short branches without creating a symbol.
2832 * Note that the expression still might come from the assembly
2833 * input, in which case the value is not checked for range nor
2834 * is a relocation entry generated (yuck).
2836 if (ep->X_op == O_constant)
2838 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
2842 if (mips_pic == EMBEDDED_PIC)
2843 *r = BFD_RELOC_16_PCREL_S2;
2845 *r = BFD_RELOC_16_PCREL;
2849 assert (ep != NULL);
2850 *r = BFD_RELOC_MIPS_JMP;
2854 insn.insn_opcode |= va_arg (args, unsigned long);
2863 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2865 append_insn (place, &insn, ep, r, false);
2869 mips16_macro_build (place, counter, ep, name, fmt, args)
2871 int *counter ATTRIBUTE_UNUSED;
2877 struct mips_cl_insn insn;
2878 bfd_reloc_code_real_type r[3]
2879 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2881 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
2882 assert (insn.insn_mo);
2883 assert (strcmp (name, insn.insn_mo->name) == 0);
2885 while (strcmp (fmt, insn.insn_mo->args) != 0
2886 || insn.insn_mo->pinfo == INSN_MACRO)
2889 assert (insn.insn_mo->name);
2890 assert (strcmp (name, insn.insn_mo->name) == 0);
2893 insn.insn_opcode = insn.insn_mo->match;
2894 insn.use_extend = false;
2913 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
2918 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
2922 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
2926 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
2936 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
2943 regno = va_arg (args, int);
2944 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
2945 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
2966 assert (ep != NULL);
2968 if (ep->X_op != O_constant)
2969 *r = (int) BFD_RELOC_UNUSED + c;
2972 mips16_immed (NULL, 0, c, ep->X_add_number, false, false,
2973 false, &insn.insn_opcode, &insn.use_extend,
2976 *r = BFD_RELOC_UNUSED;
2982 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
2989 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2991 append_insn (place, &insn, ep, r, false);
2995 * Generate a "jalr" instruction with a relocation hint to the called
2996 * function. This occurs in NewABI PIC code.
2999 macro_build_jalr (icnt, ep)
3005 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", "d,s",
3008 fix_new_exp (frag_now, 0, 0, ep, false, BFD_RELOC_MIPS_JALR);
3012 * Generate a "lui" instruction.
3015 macro_build_lui (place, counter, ep, regnum)
3021 expressionS high_expr;
3022 struct mips_cl_insn insn;
3023 bfd_reloc_code_real_type r[3]
3024 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3025 const char *name = "lui";
3026 const char *fmt = "t,u";
3028 assert (! mips_opts.mips16);
3034 high_expr.X_op = O_constant;
3035 high_expr.X_add_number = ep->X_add_number;
3038 if (high_expr.X_op == O_constant)
3040 /* we can compute the instruction now without a relocation entry */
3041 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3043 *r = BFD_RELOC_UNUSED;
3045 else if (! HAVE_NEWABI)
3047 assert (ep->X_op == O_symbol);
3048 /* _gp_disp is a special case, used from s_cpload. */
3049 assert (mips_pic == NO_PIC
3050 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
3051 *r = BFD_RELOC_HI16_S;
3055 * If the macro is about to expand into a second instruction,
3056 * print a warning if needed. We need to pass ip as a parameter
3057 * to generate a better warning message here...
3059 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3060 as_warn (_("Macro instruction expanded into multiple instructions"));
3063 ++*counter; /* bump instruction counter */
3065 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3066 assert (insn.insn_mo);
3067 assert (strcmp (name, insn.insn_mo->name) == 0);
3068 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3070 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3071 if (*r == BFD_RELOC_UNUSED)
3073 insn.insn_opcode |= high_expr.X_add_number;
3074 append_insn (place, &insn, NULL, r, false);
3077 append_insn (place, &insn, &high_expr, r, false);
3081 * Generates code to set the $at register to true (one)
3082 * if reg is less than the immediate expression.
3085 set_at (counter, reg, unsignedp)
3090 if (imm_expr.X_op == O_constant
3091 && imm_expr.X_add_number >= -0x8000
3092 && imm_expr.X_add_number < 0x8000)
3093 macro_build ((char *) NULL, counter, &imm_expr,
3094 unsignedp ? "sltiu" : "slti",
3095 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
3098 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3099 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3100 unsignedp ? "sltu" : "slt",
3101 "d,v,t", AT, reg, AT);
3105 /* Warn if an expression is not a constant. */
3108 check_absolute_expr (ip, ex)
3109 struct mips_cl_insn *ip;
3112 if (ex->X_op == O_big)
3113 as_bad (_("unsupported large constant"));
3114 else if (ex->X_op != O_constant)
3115 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3118 /* Count the leading zeroes by performing a binary chop. This is a
3119 bulky bit of source, but performance is a LOT better for the
3120 majority of values than a simple loop to count the bits:
3121 for (lcnt = 0; (lcnt < 32); lcnt++)
3122 if ((v) & (1 << (31 - lcnt)))
3124 However it is not code size friendly, and the gain will drop a bit
3125 on certain cached systems.
3127 #define COUNT_TOP_ZEROES(v) \
3128 (((v) & ~0xffff) == 0 \
3129 ? ((v) & ~0xff) == 0 \
3130 ? ((v) & ~0xf) == 0 \
3131 ? ((v) & ~0x3) == 0 \
3132 ? ((v) & ~0x1) == 0 \
3137 : ((v) & ~0x7) == 0 \
3140 : ((v) & ~0x3f) == 0 \
3141 ? ((v) & ~0x1f) == 0 \
3144 : ((v) & ~0x7f) == 0 \
3147 : ((v) & ~0xfff) == 0 \
3148 ? ((v) & ~0x3ff) == 0 \
3149 ? ((v) & ~0x1ff) == 0 \
3152 : ((v) & ~0x7ff) == 0 \
3155 : ((v) & ~0x3fff) == 0 \
3156 ? ((v) & ~0x1fff) == 0 \
3159 : ((v) & ~0x7fff) == 0 \
3162 : ((v) & ~0xffffff) == 0 \
3163 ? ((v) & ~0xfffff) == 0 \
3164 ? ((v) & ~0x3ffff) == 0 \
3165 ? ((v) & ~0x1ffff) == 0 \
3168 : ((v) & ~0x7ffff) == 0 \
3171 : ((v) & ~0x3fffff) == 0 \
3172 ? ((v) & ~0x1fffff) == 0 \
3175 : ((v) & ~0x7fffff) == 0 \
3178 : ((v) & ~0xfffffff) == 0 \
3179 ? ((v) & ~0x3ffffff) == 0 \
3180 ? ((v) & ~0x1ffffff) == 0 \
3183 : ((v) & ~0x7ffffff) == 0 \
3186 : ((v) & ~0x3fffffff) == 0 \
3187 ? ((v) & ~0x1fffffff) == 0 \
3190 : ((v) & ~0x7fffffff) == 0 \
3194 /* Is the given value a sign-extended 32-bit value? */
3195 #define IS_SEXT_32BIT_NUM(x) \
3196 (((x) &~ (offsetT) 0x7fffffff) == 0 \
3197 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
3200 * This routine generates the least number of instructions neccessary to load
3201 * an absolute expression value into a register.
3204 load_register (counter, reg, ep, dbl)
3211 expressionS hi32, lo32;
3213 if (ep->X_op != O_big)
3215 assert (ep->X_op == O_constant);
3216 if (ep->X_add_number < 0x8000
3217 && (ep->X_add_number >= 0
3218 || (ep->X_add_number >= -0x8000
3221 || sizeof (ep->X_add_number) > 4))))
3223 /* We can handle 16 bit signed values with an addiu to
3224 $zero. No need to ever use daddiu here, since $zero and
3225 the result are always correct in 32 bit mode. */
3226 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3227 (int) BFD_RELOC_LO16);
3230 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3232 /* We can handle 16 bit unsigned values with an ori to
3234 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3235 (int) BFD_RELOC_LO16);
3238 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)
3241 || sizeof (ep->X_add_number) > 4
3242 || (ep->X_add_number & 0x80000000) == 0))
3243 || ((HAVE_32BIT_GPRS || ! dbl)
3244 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3247 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3248 == ~ (offsetT) 0xffffffff)))
3250 /* 32 bit values require an lui. */
3251 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3252 (int) BFD_RELOC_HI16);
3253 if ((ep->X_add_number & 0xffff) != 0)
3254 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3255 (int) BFD_RELOC_LO16);
3260 /* The value is larger than 32 bits. */
3262 if (HAVE_32BIT_GPRS)
3264 as_bad (_("Number (0x%lx) larger than 32 bits"),
3265 (unsigned long) ep->X_add_number);
3266 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3267 (int) BFD_RELOC_LO16);
3271 if (ep->X_op != O_big)
3274 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3275 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3276 hi32.X_add_number &= 0xffffffff;
3278 lo32.X_add_number &= 0xffffffff;
3282 assert (ep->X_add_number > 2);
3283 if (ep->X_add_number == 3)
3284 generic_bignum[3] = 0;
3285 else if (ep->X_add_number > 4)
3286 as_bad (_("Number larger than 64 bits"));
3287 lo32.X_op = O_constant;
3288 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3289 hi32.X_op = O_constant;
3290 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3293 if (hi32.X_add_number == 0)
3298 unsigned long hi, lo;
3300 if (hi32.X_add_number == (offsetT) 0xffffffff)
3302 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3304 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3305 reg, 0, (int) BFD_RELOC_LO16);
3308 if (lo32.X_add_number & 0x80000000)
3310 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3311 (int) BFD_RELOC_HI16);
3312 if (lo32.X_add_number & 0xffff)
3313 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3314 reg, reg, (int) BFD_RELOC_LO16);
3319 /* Check for 16bit shifted constant. We know that hi32 is
3320 non-zero, so start the mask on the first bit of the hi32
3325 unsigned long himask, lomask;
3329 himask = 0xffff >> (32 - shift);
3330 lomask = (0xffff << shift) & 0xffffffff;
3334 himask = 0xffff << (shift - 32);
3337 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3338 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3342 tmp.X_op = O_constant;
3344 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3345 | (lo32.X_add_number >> shift));
3347 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3348 macro_build ((char *) NULL, counter, &tmp,
3349 "ori", "t,r,i", reg, 0,
3350 (int) BFD_RELOC_LO16);
3351 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3352 (shift >= 32) ? "dsll32" : "dsll",
3354 (shift >= 32) ? shift - 32 : shift);
3359 while (shift <= (64 - 16));
3361 /* Find the bit number of the lowest one bit, and store the
3362 shifted value in hi/lo. */
3363 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3364 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3368 while ((lo & 1) == 0)
3373 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3379 while ((hi & 1) == 0)
3388 /* Optimize if the shifted value is a (power of 2) - 1. */
3389 if ((hi == 0 && ((lo + 1) & lo) == 0)
3390 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3392 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3397 /* This instruction will set the register to be all
3399 tmp.X_op = O_constant;
3400 tmp.X_add_number = (offsetT) -1;
3401 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3402 reg, 0, (int) BFD_RELOC_LO16);
3406 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3407 (bit >= 32) ? "dsll32" : "dsll",
3409 (bit >= 32) ? bit - 32 : bit);
3411 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3412 (shift >= 32) ? "dsrl32" : "dsrl",
3414 (shift >= 32) ? shift - 32 : shift);
3419 /* Sign extend hi32 before calling load_register, because we can
3420 generally get better code when we load a sign extended value. */
3421 if ((hi32.X_add_number & 0x80000000) != 0)
3422 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3423 load_register (counter, reg, &hi32, 0);
3426 if ((lo32.X_add_number & 0xffff0000) == 0)
3430 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3431 "dsll32", "d,w,<", reg, freg, 0);
3439 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3441 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3442 (int) BFD_RELOC_HI16);
3443 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3444 "dsrl32", "d,w,<", reg, reg, 0);
3450 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3451 "d,w,<", reg, freg, 16);
3455 mid16.X_add_number >>= 16;
3456 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3457 freg, (int) BFD_RELOC_LO16);
3458 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3459 "d,w,<", reg, reg, 16);
3462 if ((lo32.X_add_number & 0xffff) != 0)
3463 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3464 (int) BFD_RELOC_LO16);
3467 /* Load an address into a register. */
3470 load_address (counter, reg, ep, used_at)
3478 if (ep->X_op != O_constant
3479 && ep->X_op != O_symbol)
3481 as_bad (_("expression too complex"));
3482 ep->X_op = O_constant;
3485 if (ep->X_op == O_constant)
3487 load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES);
3491 if (mips_pic == NO_PIC)
3493 /* If this is a reference to a GP relative symbol, we want
3494 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3496 lui $reg,<sym> (BFD_RELOC_HI16_S)
3497 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3498 If we have an addend, we always use the latter form.
3500 With 64bit address space and a usable $at we want
3501 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3502 lui $at,<sym> (BFD_RELOC_HI16_S)
3503 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3504 daddiu $at,<sym> (BFD_RELOC_LO16)
3508 If $at is already in use, we use an path which is suboptimal
3509 on superscalar processors.
3510 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3511 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3513 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3515 daddiu $reg,<sym> (BFD_RELOC_LO16)
3517 if (HAVE_64BIT_ADDRESSES)
3519 /* We don't do GP optimization for now because RELAX_ENCODE can't
3520 hold the data for such large chunks. */
3524 macro_build (p, counter, ep, "lui", "t,u",
3525 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3526 macro_build (p, counter, ep, "lui", "t,u",
3527 AT, (int) BFD_RELOC_HI16_S);
3528 macro_build (p, counter, ep, "daddiu", "t,r,j",
3529 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3530 macro_build (p, counter, ep, "daddiu", "t,r,j",
3531 AT, AT, (int) BFD_RELOC_LO16);
3532 macro_build (p, counter, (expressionS *) NULL, "dsll32",
3533 "d,w,<", reg, reg, 0);
3534 macro_build (p, counter, (expressionS *) NULL, "daddu",
3535 "d,v,t", reg, reg, AT);
3540 macro_build (p, counter, ep, "lui", "t,u",
3541 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3542 macro_build (p, counter, ep, "daddiu", "t,r,j",
3543 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3544 macro_build (p, counter, (expressionS *) NULL, "dsll",
3545 "d,w,<", reg, reg, 16);
3546 macro_build (p, counter, ep, "daddiu", "t,r,j",
3547 reg, reg, (int) BFD_RELOC_HI16_S);
3548 macro_build (p, counter, (expressionS *) NULL, "dsll",
3549 "d,w,<", reg, reg, 16);
3550 macro_build (p, counter, ep, "daddiu", "t,r,j",
3551 reg, reg, (int) BFD_RELOC_LO16);
3556 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3557 && ! nopic_need_relax (ep->X_add_symbol, 1))
3560 macro_build ((char *) NULL, counter, ep,
3561 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
3562 reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
3563 p = frag_var (rs_machine_dependent, 8, 0,
3564 RELAX_ENCODE (4, 8, 0, 4, 0,
3565 mips_opts.warn_about_macros),
3566 ep->X_add_symbol, 0, NULL);
3568 macro_build_lui (p, counter, ep, reg);
3571 macro_build (p, counter, ep,
3572 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3573 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3576 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3580 /* If this is a reference to an external symbol, we want
3581 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3583 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3585 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3586 If there is a constant, it must be added in after. */
3587 ex.X_add_number = ep->X_add_number;
3588 ep->X_add_number = 0;
3590 macro_build ((char *) NULL, counter, ep,
3591 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
3592 reg, (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
3593 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3594 p = frag_var (rs_machine_dependent, 4, 0,
3595 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3596 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3597 macro_build (p, counter, ep,
3598 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3599 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3600 if (ex.X_add_number != 0)
3602 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3603 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3604 ex.X_op = O_constant;
3605 macro_build ((char *) NULL, counter, &ex,
3606 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3607 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3610 else if (mips_pic == SVR4_PIC)
3615 /* This is the large GOT case. If this is a reference to an
3616 external symbol, we want
3617 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3619 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3620 Otherwise, for a reference to a local symbol, we want
3621 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3623 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3624 If we have NewABI, we want
3625 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3626 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3627 If there is a constant, it must be added in after. */
3628 ex.X_add_number = ep->X_add_number;
3629 ep->X_add_number = 0;
3632 macro_build ((char *) NULL, counter, ep,
3633 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg,
3634 (int) BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
3635 macro_build (p, counter, ep,
3636 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
3637 reg, reg, (int) BFD_RELOC_MIPS_GOT_OFST);
3641 if (reg_needs_delay (mips_gp_register))
3646 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3647 (int) BFD_RELOC_MIPS_GOT_HI16);
3648 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3649 HAVE_32BIT_ADDRESSES ? "addu" : "daddu", "d,v,t", reg,
3650 reg, mips_gp_register);
3651 macro_build ((char *) NULL, counter, ep,
3652 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
3653 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3654 p = frag_var (rs_machine_dependent, 12 + off, 0,
3655 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3656 mips_opts.warn_about_macros),
3657 ep->X_add_symbol, 0, NULL);
3660 /* We need a nop before loading from $gp. This special
3661 check is required because the lui which starts the main
3662 instruction stream does not refer to $gp, and so will not
3663 insert the nop which may be required. */
3664 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3667 macro_build (p, counter, ep,
3668 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg,
3669 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
3671 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3673 macro_build (p, counter, ep,
3674 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3675 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3678 if (ex.X_add_number != 0)
3680 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3681 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3682 ex.X_op = O_constant;
3683 macro_build ((char *) NULL, counter, &ex,
3684 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3685 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3688 else if (mips_pic == EMBEDDED_PIC)
3691 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3693 macro_build ((char *) NULL, counter, ep,
3694 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3695 "t,r,j", reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
3701 /* Move the contents of register SOURCE into register DEST. */
3704 move_register (counter, dest, source)
3709 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3710 HAVE_32BIT_GPRS ? "addu" : "daddu",
3711 "d,v,t", dest, source, 0);
3716 * This routine implements the seemingly endless macro or synthesized
3717 * instructions and addressing modes in the mips assembly language. Many
3718 * of these macros are simple and are similar to each other. These could
3719 * probably be handled by some kind of table or grammer aproach instead of
3720 * this verbose method. Others are not simple macros but are more like
3721 * optimizing code generation.
3722 * One interesting optimization is when several store macros appear
3723 * consecutivly that would load AT with the upper half of the same address.
3724 * The ensuing load upper instructions are ommited. This implies some kind
3725 * of global optimization. We currently only optimize within a single macro.
3726 * For many of the load and store macros if the address is specified as a
3727 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3728 * first load register 'at' with zero and use it as the base register. The
3729 * mips assembler simply uses register $zero. Just one tiny optimization
3734 struct mips_cl_insn *ip;
3736 register int treg, sreg, dreg, breg;
3752 bfd_reloc_code_real_type r;
3753 int hold_mips_optimize;
3755 assert (! mips_opts.mips16);
3757 treg = (ip->insn_opcode >> 16) & 0x1f;
3758 dreg = (ip->insn_opcode >> 11) & 0x1f;
3759 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3760 mask = ip->insn_mo->mask;
3762 expr1.X_op = O_constant;
3763 expr1.X_op_symbol = NULL;
3764 expr1.X_add_symbol = NULL;
3765 expr1.X_add_number = 1;
3777 mips_emit_delays (true);
3778 ++mips_opts.noreorder;
3779 mips_any_noreorder = 1;
3781 expr1.X_add_number = 8;
3782 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3784 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
3787 move_register (&icnt, dreg, sreg);
3788 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3789 dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
3791 --mips_opts.noreorder;
3812 if (imm_expr.X_op == O_constant
3813 && imm_expr.X_add_number >= -0x8000
3814 && imm_expr.X_add_number < 0x8000)
3816 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3817 (int) BFD_RELOC_LO16);
3820 load_register (&icnt, AT, &imm_expr, dbl);
3821 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3841 if (imm_expr.X_op == O_constant
3842 && imm_expr.X_add_number >= 0
3843 && imm_expr.X_add_number < 0x10000)
3845 if (mask != M_NOR_I)
3846 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
3847 sreg, (int) BFD_RELOC_LO16);
3850 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
3851 treg, sreg, (int) BFD_RELOC_LO16);
3852 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor",
3853 "d,v,t", treg, treg, 0);
3858 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
3859 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3877 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3879 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
3883 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
3884 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
3892 macro_build ((char *) NULL, &icnt, &offset_expr,
3893 likely ? "bgezl" : "bgez", "s,p", sreg);
3898 macro_build ((char *) NULL, &icnt, &offset_expr,
3899 likely ? "blezl" : "blez", "s,p", treg);
3902 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
3904 macro_build ((char *) NULL, &icnt, &offset_expr,
3905 likely ? "beql" : "beq", "s,t,p", AT, 0);
3911 /* check for > max integer */
3912 maxnum = 0x7fffffff;
3913 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
3920 if (imm_expr.X_op == O_constant
3921 && imm_expr.X_add_number >= maxnum
3922 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
3925 /* result is always false */
3929 as_warn (_("Branch %s is always false (nop)"),
3931 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop",
3937 as_warn (_("Branch likely %s is always false"),
3939 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
3944 if (imm_expr.X_op != O_constant)
3945 as_bad (_("Unsupported large constant"));
3946 ++imm_expr.X_add_number;
3950 if (mask == M_BGEL_I)
3952 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3954 macro_build ((char *) NULL, &icnt, &offset_expr,
3955 likely ? "bgezl" : "bgez", "s,p", sreg);
3958 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3960 macro_build ((char *) NULL, &icnt, &offset_expr,
3961 likely ? "bgtzl" : "bgtz", "s,p", sreg);
3964 maxnum = 0x7fffffff;
3965 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
3972 maxnum = - maxnum - 1;
3973 if (imm_expr.X_op == O_constant
3974 && imm_expr.X_add_number <= maxnum
3975 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
3978 /* result is always true */
3979 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
3980 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
3983 set_at (&icnt, sreg, 0);
3984 macro_build ((char *) NULL, &icnt, &offset_expr,
3985 likely ? "beql" : "beq", "s,t,p", AT, 0);
3995 macro_build ((char *) NULL, &icnt, &offset_expr,
3996 likely ? "beql" : "beq", "s,t,p", 0, treg);
3999 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4000 "d,v,t", AT, sreg, treg);
4001 macro_build ((char *) NULL, &icnt, &offset_expr,
4002 likely ? "beql" : "beq", "s,t,p", AT, 0);
4010 && imm_expr.X_op == O_constant
4011 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4013 if (imm_expr.X_op != O_constant)
4014 as_bad (_("Unsupported large constant"));
4015 ++imm_expr.X_add_number;
4019 if (mask == M_BGEUL_I)
4021 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4023 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4025 macro_build ((char *) NULL, &icnt, &offset_expr,
4026 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4029 set_at (&icnt, sreg, 1);
4030 macro_build ((char *) NULL, &icnt, &offset_expr,
4031 likely ? "beql" : "beq", "s,t,p", AT, 0);
4039 macro_build ((char *) NULL, &icnt, &offset_expr,
4040 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4045 macro_build ((char *) NULL, &icnt, &offset_expr,
4046 likely ? "bltzl" : "bltz", "s,p", treg);
4049 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4051 macro_build ((char *) NULL, &icnt, &offset_expr,
4052 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4060 macro_build ((char *) NULL, &icnt, &offset_expr,
4061 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4066 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4067 "d,v,t", AT, treg, sreg);
4068 macro_build ((char *) NULL, &icnt, &offset_expr,
4069 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4077 macro_build ((char *) NULL, &icnt, &offset_expr,
4078 likely ? "blezl" : "blez", "s,p", sreg);
4083 macro_build ((char *) NULL, &icnt, &offset_expr,
4084 likely ? "bgezl" : "bgez", "s,p", treg);
4087 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4089 macro_build ((char *) NULL, &icnt, &offset_expr,
4090 likely ? "beql" : "beq", "s,t,p", AT, 0);
4096 maxnum = 0x7fffffff;
4097 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4104 if (imm_expr.X_op == O_constant
4105 && imm_expr.X_add_number >= maxnum
4106 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4108 if (imm_expr.X_op != O_constant)
4109 as_bad (_("Unsupported large constant"));
4110 ++imm_expr.X_add_number;
4114 if (mask == M_BLTL_I)
4116 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4118 macro_build ((char *) NULL, &icnt, &offset_expr,
4119 likely ? "bltzl" : "bltz", "s,p", sreg);
4122 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4124 macro_build ((char *) NULL, &icnt, &offset_expr,
4125 likely ? "blezl" : "blez", "s,p", sreg);
4128 set_at (&icnt, sreg, 0);
4129 macro_build ((char *) NULL, &icnt, &offset_expr,
4130 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4138 macro_build ((char *) NULL, &icnt, &offset_expr,
4139 likely ? "beql" : "beq", "s,t,p", sreg, 0);
4144 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4145 "d,v,t", AT, treg, sreg);
4146 macro_build ((char *) NULL, &icnt, &offset_expr,
4147 likely ? "beql" : "beq", "s,t,p", AT, 0);
4155 && imm_expr.X_op == O_constant
4156 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4158 if (imm_expr.X_op != O_constant)
4159 as_bad (_("Unsupported large constant"));
4160 ++imm_expr.X_add_number;
4164 if (mask == M_BLTUL_I)
4166 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4168 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4170 macro_build ((char *) NULL, &icnt, &offset_expr,
4171 likely ? "beql" : "beq",
4175 set_at (&icnt, sreg, 1);
4176 macro_build ((char *) NULL, &icnt, &offset_expr,
4177 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4185 macro_build ((char *) NULL, &icnt, &offset_expr,
4186 likely ? "bltzl" : "bltz", "s,p", sreg);
4191 macro_build ((char *) NULL, &icnt, &offset_expr,
4192 likely ? "bgtzl" : "bgtz", "s,p", treg);
4195 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4197 macro_build ((char *) NULL, &icnt, &offset_expr,
4198 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4208 macro_build ((char *) NULL, &icnt, &offset_expr,
4209 likely ? "bnel" : "bne", "s,t,p", 0, treg);
4212 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4215 macro_build ((char *) NULL, &icnt, &offset_expr,
4216 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4231 as_warn (_("Divide by zero."));
4233 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4236 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4241 mips_emit_delays (true);
4242 ++mips_opts.noreorder;
4243 mips_any_noreorder = 1;
4246 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4248 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4249 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4253 expr1.X_add_number = 8;
4254 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4255 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4256 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4257 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4260 expr1.X_add_number = -1;
4261 macro_build ((char *) NULL, &icnt, &expr1,
4262 dbl ? "daddiu" : "addiu",
4263 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
4264 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4265 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4268 expr1.X_add_number = 1;
4269 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4270 (int) BFD_RELOC_LO16);
4271 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32",
4272 "d,w,<", AT, AT, 31);
4276 expr1.X_add_number = 0x80000000;
4277 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4278 (int) BFD_RELOC_HI16);
4282 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4284 /* We want to close the noreorder block as soon as possible, so
4285 that later insns are available for delay slot filling. */
4286 --mips_opts.noreorder;
4290 expr1.X_add_number = 8;
4291 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4292 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4295 /* We want to close the noreorder block as soon as possible, so
4296 that later insns are available for delay slot filling. */
4297 --mips_opts.noreorder;
4299 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4302 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg);
4341 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4343 as_warn (_("Divide by zero."));
4345 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4348 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4352 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4354 if (strcmp (s2, "mflo") == 0)
4355 move_register (&icnt, dreg, sreg);
4357 move_register (&icnt, dreg, 0);
4360 if (imm_expr.X_op == O_constant
4361 && imm_expr.X_add_number == -1
4362 && s[strlen (s) - 1] != 'u')
4364 if (strcmp (s2, "mflo") == 0)
4366 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4367 dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4370 move_register (&icnt, dreg, 0);
4374 load_register (&icnt, AT, &imm_expr, dbl);
4375 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4377 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4396 mips_emit_delays (true);
4397 ++mips_opts.noreorder;
4398 mips_any_noreorder = 1;
4401 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4403 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4405 /* We want to close the noreorder block as soon as possible, so
4406 that later insns are available for delay slot filling. */
4407 --mips_opts.noreorder;
4411 expr1.X_add_number = 8;
4412 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4413 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4416 /* We want to close the noreorder block as soon as possible, so
4417 that later insns are available for delay slot filling. */
4418 --mips_opts.noreorder;
4419 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4422 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4428 /* Load the address of a symbol into a register. If breg is not
4429 zero, we then add a base register to it. */
4431 if (dbl && HAVE_32BIT_GPRS)
4432 as_warn (_("dla used to load 32-bit register"));
4434 if (! dbl && HAVE_64BIT_OBJECTS)
4435 as_warn (_("la used to load 64-bit address"));
4448 /* When generating embedded PIC code, we permit expressions of
4451 la $treg,foo-bar($breg)
4452 where bar is an address in the current section. These are used
4453 when getting the addresses of functions. We don't permit
4454 X_add_number to be non-zero, because if the symbol is
4455 external the relaxing code needs to know that any addend is
4456 purely the offset to X_op_symbol. */
4457 if (mips_pic == EMBEDDED_PIC
4458 && offset_expr.X_op == O_subtract
4459 && (symbol_constant_p (offset_expr.X_op_symbol)
4460 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4461 : (symbol_equated_p (offset_expr.X_op_symbol)
4463 (symbol_get_value_expression (offset_expr.X_op_symbol)
4466 && (offset_expr.X_add_number == 0
4467 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4473 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4474 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4478 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4479 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4480 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4481 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4482 "d,v,t", tempreg, tempreg, breg);
4484 macro_build ((char *) NULL, &icnt, &offset_expr,
4485 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4486 "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16);
4492 if (offset_expr.X_op != O_symbol
4493 && offset_expr.X_op != O_constant)
4495 as_bad (_("expression too complex"));
4496 offset_expr.X_op = O_constant;
4499 if (offset_expr.X_op == O_constant)
4500 load_register (&icnt, tempreg, &offset_expr,
4501 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4502 ? (dbl || HAVE_64BIT_ADDRESSES)
4503 : HAVE_64BIT_ADDRESSES));
4504 else if (mips_pic == NO_PIC)
4506 /* If this is a reference to a GP relative symbol, we want
4507 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4509 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4510 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4511 If we have a constant, we need two instructions anyhow,
4512 so we may as well always use the latter form.
4514 With 64bit address space and a usable $at we want
4515 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4516 lui $at,<sym> (BFD_RELOC_HI16_S)
4517 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4518 daddiu $at,<sym> (BFD_RELOC_LO16)
4520 daddu $tempreg,$tempreg,$at
4522 If $at is already in use, we use an path which is suboptimal
4523 on superscalar processors.
4524 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4525 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4527 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4529 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4532 if (HAVE_64BIT_ADDRESSES)
4534 /* We don't do GP optimization for now because RELAX_ENCODE can't
4535 hold the data for such large chunks. */
4539 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4540 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4541 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4542 AT, (int) BFD_RELOC_HI16_S);
4543 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4544 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4545 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4546 AT, AT, (int) BFD_RELOC_LO16);
4547 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
4548 "d,w,<", tempreg, tempreg, 0);
4549 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
4550 "d,v,t", tempreg, tempreg, AT);
4555 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4556 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4557 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4558 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4559 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4560 tempreg, tempreg, 16);
4561 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4562 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
4563 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4564 tempreg, tempreg, 16);
4565 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4566 tempreg, tempreg, (int) BFD_RELOC_LO16);
4571 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4572 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4575 macro_build ((char *) NULL, &icnt, &offset_expr, "addiu",
4576 "t,r,j", tempreg, mips_gp_register,
4577 (int) BFD_RELOC_GPREL16);
4578 p = frag_var (rs_machine_dependent, 8, 0,
4579 RELAX_ENCODE (4, 8, 0, 4, 0,
4580 mips_opts.warn_about_macros),
4581 offset_expr.X_add_symbol, 0, NULL);
4583 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4586 macro_build (p, &icnt, &offset_expr, "addiu",
4587 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4590 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4592 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4594 /* If this is a reference to an external symbol, and there
4595 is no constant, we want
4596 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4597 or if tempreg is PIC_CALL_REG
4598 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4599 For a local symbol, we want
4600 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4602 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4604 If we have a small constant, and this is a reference to
4605 an external symbol, we want
4606 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4608 addiu $tempreg,$tempreg,<constant>
4609 For a local symbol, we want the same instruction
4610 sequence, but we output a BFD_RELOC_LO16 reloc on the
4613 If we have a large constant, and this is a reference to
4614 an external symbol, we want
4615 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4616 lui $at,<hiconstant>
4617 addiu $at,$at,<loconstant>
4618 addu $tempreg,$tempreg,$at
4619 For a local symbol, we want the same instruction
4620 sequence, but we output a BFD_RELOC_LO16 reloc on the
4621 addiu instruction. */
4622 expr1.X_add_number = offset_expr.X_add_number;
4623 offset_expr.X_add_number = 0;
4625 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4626 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4627 macro_build ((char *) NULL, &icnt, &offset_expr,
4628 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4629 "t,o(b)", tempreg, lw_reloc_type, mips_gp_register);
4630 if (expr1.X_add_number == 0)
4639 /* We're going to put in an addu instruction using
4640 tempreg, so we may as well insert the nop right
4642 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4646 p = frag_var (rs_machine_dependent, 8 - off, 0,
4647 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4649 ? mips_opts.warn_about_macros
4651 offset_expr.X_add_symbol, 0, NULL);
4654 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4657 macro_build (p, &icnt, &expr1,
4658 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4659 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4660 /* FIXME: If breg == 0, and the next instruction uses
4661 $tempreg, then if this variant case is used an extra
4662 nop will be generated. */
4664 else if (expr1.X_add_number >= -0x8000
4665 && expr1.X_add_number < 0x8000)
4667 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4669 macro_build ((char *) NULL, &icnt, &expr1,
4670 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4671 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4672 frag_var (rs_machine_dependent, 0, 0,
4673 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4674 offset_expr.X_add_symbol, 0, NULL);
4680 /* If we are going to add in a base register, and the
4681 target register and the base register are the same,
4682 then we are using AT as a temporary register. Since
4683 we want to load the constant into AT, we add our
4684 current AT (from the global offset table) and the
4685 register into the register now, and pretend we were
4686 not using a base register. */
4691 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4693 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4694 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4695 "d,v,t", treg, AT, breg);
4701 /* Set mips_optimize around the lui instruction to avoid
4702 inserting an unnecessary nop after the lw. */
4703 hold_mips_optimize = mips_optimize;
4705 macro_build_lui (NULL, &icnt, &expr1, AT);
4706 mips_optimize = hold_mips_optimize;
4708 macro_build ((char *) NULL, &icnt, &expr1,
4709 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4710 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4711 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4712 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4713 "d,v,t", tempreg, tempreg, AT);
4714 frag_var (rs_machine_dependent, 0, 0,
4715 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4716 offset_expr.X_add_symbol, 0, NULL);
4720 else if (mips_pic == SVR4_PIC)
4724 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
4725 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
4727 /* This is the large GOT case. If this is a reference to an
4728 external symbol, and there is no constant, we want
4729 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4730 addu $tempreg,$tempreg,$gp
4731 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4732 or if tempreg is PIC_CALL_REG
4733 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4734 addu $tempreg,$tempreg,$gp
4735 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4736 For a local symbol, we want
4737 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4739 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4741 If we have a small constant, and this is a reference to
4742 an external symbol, we want
4743 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4744 addu $tempreg,$tempreg,$gp
4745 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4747 addiu $tempreg,$tempreg,<constant>
4748 For a local symbol, we want
4749 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4751 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4753 If we have a large constant, and this is a reference to
4754 an external symbol, we want
4755 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4756 addu $tempreg,$tempreg,$gp
4757 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4758 lui $at,<hiconstant>
4759 addiu $at,$at,<loconstant>
4760 addu $tempreg,$tempreg,$at
4761 For a local symbol, we want
4762 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4763 lui $at,<hiconstant>
4764 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4765 addu $tempreg,$tempreg,$at
4767 For NewABI, we want for data addresses
4768 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4769 If tempreg is PIC_CALL_REG pointing to a external symbol, we want
4770 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4774 int reloc_type = (tempreg == PIC_CALL_REG
4775 ? BFD_RELOC_MIPS_CALL16
4776 : BFD_RELOC_MIPS_GOT_DISP);
4778 macro_build ((char *) NULL, &icnt, &offset_expr,
4779 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4780 "t,o(b)", tempreg, reloc_type, mips_gp_register);
4783 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4784 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4785 "d,v,t", treg, tempreg, breg);
4792 expr1.X_add_number = offset_expr.X_add_number;
4793 offset_expr.X_add_number = 0;
4795 if (reg_needs_delay (mips_gp_register))
4799 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4801 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
4802 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
4804 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4805 tempreg, lui_reloc_type);
4806 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4807 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4808 "d,v,t", tempreg, tempreg, mips_gp_register);
4809 macro_build ((char *) NULL, &icnt, &offset_expr,
4810 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4811 "t,o(b)", tempreg, lw_reloc_type, tempreg);
4812 if (expr1.X_add_number == 0)
4820 /* We're going to put in an addu instruction using
4821 tempreg, so we may as well insert the nop right
4823 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4828 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4829 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4832 ? mips_opts.warn_about_macros
4834 offset_expr.X_add_symbol, 0, NULL);
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);
4845 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4846 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4848 ? mips_opts.warn_about_macros
4850 offset_expr.X_add_symbol, 0, NULL);
4856 /* If we are going to add in a base register, and the
4857 target register and the base register are the same,
4858 then we are using AT as a temporary register. Since
4859 we want to load the constant into AT, we add our
4860 current AT (from the global offset table) and the
4861 register into the register now, and pretend we were
4862 not using a base register. */
4870 assert (tempreg == AT);
4871 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4873 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4874 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4875 "d,v,t", treg, AT, breg);
4880 /* Set mips_optimize around the lui instruction to avoid
4881 inserting an unnecessary nop after the lw. */
4882 hold_mips_optimize = mips_optimize;
4884 macro_build_lui (NULL, &icnt, &expr1, AT);
4885 mips_optimize = hold_mips_optimize;
4887 macro_build ((char *) NULL, &icnt, &expr1,
4888 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4889 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4890 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4891 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4892 "d,v,t", dreg, dreg, AT);
4894 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
4895 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
4898 ? mips_opts.warn_about_macros
4900 offset_expr.X_add_symbol, 0, NULL);
4907 /* This is needed because this instruction uses $gp, but
4908 the first instruction on the main stream does not. */
4909 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4912 macro_build (p, &icnt, &offset_expr,
4913 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4914 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
4917 if (expr1.X_add_number >= -0x8000
4918 && expr1.X_add_number < 0x8000)
4920 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4922 macro_build (p, &icnt, &expr1,
4923 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4924 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4925 /* FIXME: If add_number is 0, and there was no base
4926 register, the external symbol case ended with a load,
4927 so if the symbol turns out to not be external, and
4928 the next instruction uses tempreg, an unnecessary nop
4929 will be inserted. */
4935 /* We must add in the base register now, as in the
4936 external symbol case. */
4937 assert (tempreg == AT);
4938 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4940 macro_build (p, &icnt, (expressionS *) NULL,
4941 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4942 "d,v,t", treg, AT, breg);
4945 /* We set breg to 0 because we have arranged to add
4946 it in in both cases. */
4950 macro_build_lui (p, &icnt, &expr1, AT);
4952 macro_build (p, &icnt, &expr1,
4953 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4954 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4956 macro_build (p, &icnt, (expressionS *) NULL,
4957 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4958 "d,v,t", tempreg, tempreg, AT);
4962 else if (mips_pic == EMBEDDED_PIC)
4965 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4967 macro_build ((char *) NULL, &icnt, &offset_expr,
4968 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
4969 tempreg, mips_gp_register, (int) BFD_RELOC_GPREL16);
4978 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4979 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu";
4981 s = HAVE_64BIT_ADDRESSES ? "daddu" : "addu";
4983 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
4984 "d,v,t", treg, tempreg, breg);
4993 /* The j instruction may not be used in PIC code, since it
4994 requires an absolute address. We convert it to a b
4996 if (mips_pic == NO_PIC)
4997 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
4999 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
5002 /* The jal instructions must be handled as macros because when
5003 generating PIC code they expand to multi-instruction
5004 sequences. Normally they are simple instructions. */
5009 if (mips_pic == NO_PIC
5010 || mips_pic == EMBEDDED_PIC)
5011 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5013 else if (mips_pic == SVR4_PIC)
5015 if (sreg != PIC_CALL_REG)
5016 as_warn (_("MIPS PIC call to register other than $25"));
5018 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5022 if (mips_cprestore_offset < 0)
5023 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5026 if (! mips_frame_reg_valid)
5028 as_warn (_("No .frame pseudo-op used in PIC code"));
5029 /* Quiet this warning. */
5030 mips_frame_reg_valid = 1;
5032 if (! mips_cprestore_valid)
5034 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5035 /* Quiet this warning. */
5036 mips_cprestore_valid = 1;
5038 expr1.X_add_number = mips_cprestore_offset;
5039 macro_build ((char *) NULL, &icnt, &expr1,
5040 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5041 mips_gp_register, (int) BFD_RELOC_LO16,
5052 if (mips_pic == NO_PIC)
5053 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
5054 else if (mips_pic == SVR4_PIC)
5058 /* If this is a reference to an external symbol, and we are
5059 using a small GOT, we want
5060 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5064 lw $gp,cprestore($sp)
5065 The cprestore value is set using the .cprestore
5066 pseudo-op. If we are using a big GOT, we want
5067 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5069 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5073 lw $gp,cprestore($sp)
5074 If the symbol is not external, we want
5075 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5077 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5080 lw $gp,cprestore($sp)
5082 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5083 jalr $ra,$25 (BFD_RELOC_MIPS_JALR)
5087 macro_build ((char *) NULL, &icnt, &offset_expr,
5088 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5089 "t,o(b)", PIC_CALL_REG,
5090 (int) BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5091 macro_build_jalr (icnt, &offset_expr);
5098 macro_build ((char *) NULL, &icnt, &offset_expr,
5099 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5100 "t,o(b)", PIC_CALL_REG,
5101 (int) BFD_RELOC_MIPS_CALL16, mips_gp_register);
5102 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5104 p = frag_var (rs_machine_dependent, 4, 0,
5105 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5106 offset_expr.X_add_symbol, 0, NULL);
5112 if (reg_needs_delay (mips_gp_register))
5116 macro_build ((char *) NULL, &icnt, &offset_expr, "lui",
5117 "t,u", PIC_CALL_REG,
5118 (int) BFD_RELOC_MIPS_CALL_HI16);
5119 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5120 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5121 "d,v,t", PIC_CALL_REG, PIC_CALL_REG,
5123 macro_build ((char *) NULL, &icnt, &offset_expr,
5124 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5125 "t,o(b)", PIC_CALL_REG,
5126 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5127 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5129 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5130 RELAX_ENCODE (16, 12 + gpdel, gpdel,
5132 offset_expr.X_add_symbol, 0, NULL);
5135 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5138 macro_build (p, &icnt, &offset_expr,
5139 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5140 "t,o(b)", PIC_CALL_REG,
5141 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
5143 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5146 macro_build (p, &icnt, &offset_expr,
5147 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5148 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5149 (int) BFD_RELOC_LO16);
5150 macro_build_jalr (icnt, &offset_expr);
5152 if (mips_cprestore_offset < 0)
5153 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5156 if (! mips_frame_reg_valid)
5158 as_warn (_("No .frame pseudo-op used in PIC code"));
5159 /* Quiet this warning. */
5160 mips_frame_reg_valid = 1;
5162 if (! mips_cprestore_valid)
5164 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5165 /* Quiet this warning. */
5166 mips_cprestore_valid = 1;
5168 if (mips_opts.noreorder)
5169 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5171 expr1.X_add_number = mips_cprestore_offset;
5172 macro_build ((char *) NULL, &icnt, &expr1,
5173 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5174 mips_gp_register, (int) BFD_RELOC_LO16,
5179 else if (mips_pic == EMBEDDED_PIC)
5181 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
5182 /* The linker may expand the call to a longer sequence which
5183 uses $at, so we must break rather than return. */
5208 /* Itbl support may require additional care here. */
5213 /* Itbl support may require additional care here. */
5218 /* Itbl support may require additional care here. */
5223 /* Itbl support may require additional care here. */
5235 if (mips_arch == CPU_R4650)
5237 as_bad (_("opcode not supported on this processor"));
5241 /* Itbl support may require additional care here. */
5246 /* Itbl support may require additional care here. */
5251 /* Itbl support may require additional care here. */
5271 if (breg == treg || coproc || lr)
5293 /* Itbl support may require additional care here. */
5298 /* Itbl support may require additional care here. */
5303 /* Itbl support may require additional care here. */
5308 /* Itbl support may require additional care here. */
5324 if (mips_arch == CPU_R4650)
5326 as_bad (_("opcode not supported on this processor"));
5331 /* Itbl support may require additional care here. */
5335 /* Itbl support may require additional care here. */
5340 /* Itbl support may require additional care here. */
5352 /* Itbl support may require additional care here. */
5353 if (mask == M_LWC1_AB
5354 || mask == M_SWC1_AB
5355 || mask == M_LDC1_AB
5356 || mask == M_SDC1_AB
5365 /* For embedded PIC, we allow loads where the offset is calculated
5366 by subtracting a symbol in the current segment from an unknown
5367 symbol, relative to a base register, e.g.:
5368 <op> $treg, <sym>-<localsym>($breg)
5369 This is used by the compiler for switch statements. */
5370 if (mips_pic == EMBEDDED_PIC
5371 && offset_expr.X_op == O_subtract
5372 && (symbol_constant_p (offset_expr.X_op_symbol)
5373 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5374 : (symbol_equated_p (offset_expr.X_op_symbol)
5376 (symbol_get_value_expression (offset_expr.X_op_symbol)
5380 && (offset_expr.X_add_number == 0
5381 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5383 /* For this case, we output the instructions:
5384 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5385 addiu $tempreg,$tempreg,$breg
5386 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5387 If the relocation would fit entirely in 16 bits, it would be
5389 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5390 instead, but that seems quite difficult. */
5391 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5392 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
5393 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5394 ((bfd_arch_bits_per_address (stdoutput) == 32
5395 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5396 ? "addu" : "daddu"),
5397 "d,v,t", tempreg, tempreg, breg);
5398 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
5399 (int) BFD_RELOC_PCREL_LO16, tempreg);
5405 if (offset_expr.X_op != O_constant
5406 && offset_expr.X_op != O_symbol)
5408 as_bad (_("expression too complex"));
5409 offset_expr.X_op = O_constant;
5412 /* A constant expression in PIC code can be handled just as it
5413 is in non PIC code. */
5414 if (mips_pic == NO_PIC
5415 || offset_expr.X_op == O_constant)
5419 /* If this is a reference to a GP relative symbol, and there
5420 is no base register, we want
5421 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5422 Otherwise, if there is no base register, we want
5423 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5424 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5425 If we have a constant, we need two instructions anyhow,
5426 so we always use the latter form.
5428 If we have a base register, and this is a reference to a
5429 GP relative symbol, we want
5430 addu $tempreg,$breg,$gp
5431 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5433 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5434 addu $tempreg,$tempreg,$breg
5435 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5436 With a constant we always use the latter case.
5438 With 64bit address space and no base register and $at usable,
5440 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5441 lui $at,<sym> (BFD_RELOC_HI16_S)
5442 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5445 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5446 If we have a base register, we want
5447 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5448 lui $at,<sym> (BFD_RELOC_HI16_S)
5449 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5453 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5455 Without $at we can't generate the optimal path for superscalar
5456 processors here since this would require two temporary registers.
5457 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5458 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5460 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5462 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5463 If we have a base register, we want
5464 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5465 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5467 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5469 daddu $tempreg,$tempreg,$breg
5470 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5472 If we have 64-bit addresses, as an optimization, for
5473 addresses which are 32-bit constants (e.g. kseg0/kseg1
5474 addresses) we fall back to the 32-bit address generation
5475 mechanism since it is more efficient. Note that due to
5476 the signed offset used by memory operations, the 32-bit
5477 range is shifted down by 32768 here. This code should
5478 probably attempt to generate 64-bit constants more
5479 efficiently in general.
5481 if (HAVE_64BIT_ADDRESSES
5482 && !(offset_expr.X_op == O_constant
5483 && IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000)))
5487 /* We don't do GP optimization for now because RELAX_ENCODE can't
5488 hold the data for such large chunks. */
5492 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5493 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5494 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5495 AT, (int) BFD_RELOC_HI16_S);
5496 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5497 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5499 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5500 "d,v,t", AT, AT, breg);
5501 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
5502 "d,w,<", tempreg, tempreg, 0);
5503 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5504 "d,v,t", tempreg, tempreg, AT);
5505 macro_build (p, &icnt, &offset_expr, s,
5506 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5511 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5512 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5513 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5514 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5515 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5516 "d,w,<", tempreg, tempreg, 16);
5517 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5518 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
5519 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5520 "d,w,<", tempreg, tempreg, 16);
5522 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5523 "d,v,t", tempreg, tempreg, breg);
5524 macro_build (p, &icnt, &offset_expr, s,
5525 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5533 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5534 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5539 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5540 treg, (int) BFD_RELOC_GPREL16,
5542 p = frag_var (rs_machine_dependent, 8, 0,
5543 RELAX_ENCODE (4, 8, 0, 4, 0,
5544 (mips_opts.warn_about_macros
5546 && mips_opts.noat))),
5547 offset_expr.X_add_symbol, 0, NULL);
5550 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5553 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5554 (int) BFD_RELOC_LO16, tempreg);
5558 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5559 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5564 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5565 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5566 "d,v,t", tempreg, breg, mips_gp_register);
5567 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5568 treg, (int) BFD_RELOC_GPREL16, tempreg);
5569 p = frag_var (rs_machine_dependent, 12, 0,
5570 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5571 offset_expr.X_add_symbol, 0, NULL);
5573 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5576 macro_build (p, &icnt, (expressionS *) NULL,
5577 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5578 "d,v,t", tempreg, tempreg, breg);
5581 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5582 (int) BFD_RELOC_LO16, tempreg);
5585 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5589 /* If this is a reference to an external symbol, we want
5590 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5592 <op> $treg,0($tempreg)
5594 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5596 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5597 <op> $treg,0($tempreg)
5598 If there is a base register, we add it to $tempreg before
5599 the <op>. If there is a constant, we stick it in the
5600 <op> instruction. We don't handle constants larger than
5601 16 bits, because we have no way to load the upper 16 bits
5602 (actually, we could handle them for the subset of cases
5603 in which we are not using $at). */
5604 assert (offset_expr.X_op == O_symbol);
5605 expr1.X_add_number = offset_expr.X_add_number;
5606 offset_expr.X_add_number = 0;
5607 if (expr1.X_add_number < -0x8000
5608 || expr1.X_add_number >= 0x8000)
5609 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5611 macro_build ((char *) NULL, &icnt, &offset_expr,
5612 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", tempreg,
5613 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
5614 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5615 p = frag_var (rs_machine_dependent, 4, 0,
5616 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5617 offset_expr.X_add_symbol, 0, NULL);
5618 macro_build (p, &icnt, &offset_expr,
5619 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5620 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5622 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5623 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5624 "d,v,t", tempreg, tempreg, breg);
5625 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5626 (int) BFD_RELOC_LO16, tempreg);
5628 else if (mips_pic == SVR4_PIC)
5633 /* If this is a reference to an external symbol, we want
5634 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5635 addu $tempreg,$tempreg,$gp
5636 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5637 <op> $treg,0($tempreg)
5639 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5641 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5642 <op> $treg,0($tempreg)
5643 If there is a base register, we add it to $tempreg before
5644 the <op>. If there is a constant, we stick it in the
5645 <op> instruction. We don't handle constants larger than
5646 16 bits, because we have no way to load the upper 16 bits
5647 (actually, we could handle them for the subset of cases
5648 in which we are not using $at).
5651 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5652 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5653 <op> $treg,0($tempreg)
5655 assert (offset_expr.X_op == O_symbol);
5656 expr1.X_add_number = offset_expr.X_add_number;
5657 offset_expr.X_add_number = 0;
5658 if (expr1.X_add_number < -0x8000
5659 || expr1.X_add_number >= 0x8000)
5660 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5663 macro_build ((char *) NULL, &icnt, &offset_expr,
5664 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5665 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_PAGE,
5667 macro_build ((char *) NULL, &icnt, &offset_expr,
5668 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5669 "t,r,j", tempreg, tempreg,
5670 BFD_RELOC_MIPS_GOT_OFST);
5672 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5673 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5674 "d,v,t", tempreg, tempreg, breg);
5675 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5676 (int) BFD_RELOC_LO16, tempreg);
5683 if (reg_needs_delay (mips_gp_register))
5688 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5689 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5690 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5691 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5692 "d,v,t", tempreg, tempreg, mips_gp_register);
5693 macro_build ((char *) NULL, &icnt, &offset_expr,
5694 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5695 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5697 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5698 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5699 offset_expr.X_add_symbol, 0, NULL);
5702 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5705 macro_build (p, &icnt, &offset_expr,
5706 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5707 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
5710 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5712 macro_build (p, &icnt, &offset_expr,
5713 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5714 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5716 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5717 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5718 "d,v,t", tempreg, tempreg, breg);
5719 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5720 (int) BFD_RELOC_LO16, tempreg);
5722 else if (mips_pic == EMBEDDED_PIC)
5724 /* If there is no base register, we want
5725 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5726 If there is a base register, we want
5727 addu $tempreg,$breg,$gp
5728 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5730 assert (offset_expr.X_op == O_symbol);
5733 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5734 treg, (int) BFD_RELOC_GPREL16, mips_gp_register);
5739 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5740 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5741 "d,v,t", tempreg, breg, mips_gp_register);
5742 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5743 treg, (int) BFD_RELOC_GPREL16, tempreg);
5756 load_register (&icnt, treg, &imm_expr, 0);
5760 load_register (&icnt, treg, &imm_expr, 1);
5764 if (imm_expr.X_op == O_constant)
5766 load_register (&icnt, AT, &imm_expr, 0);
5767 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5768 "mtc1", "t,G", AT, treg);
5773 assert (offset_expr.X_op == O_symbol
5774 && strcmp (segment_name (S_GET_SEGMENT
5775 (offset_expr.X_add_symbol)),
5777 && offset_expr.X_add_number == 0);
5778 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5779 treg, (int) BFD_RELOC_MIPS_LITERAL, mips_gp_register);
5784 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
5785 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
5786 order 32 bits of the value and the low order 32 bits are either
5787 zero or in OFFSET_EXPR. */
5788 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5790 if (HAVE_64BIT_GPRS)
5791 load_register (&icnt, treg, &imm_expr, 1);
5796 if (target_big_endian)
5808 load_register (&icnt, hreg, &imm_expr, 0);
5811 if (offset_expr.X_op == O_absent)
5812 move_register (&icnt, lreg, 0);
5815 assert (offset_expr.X_op == O_constant);
5816 load_register (&icnt, lreg, &offset_expr, 0);
5823 /* We know that sym is in the .rdata section. First we get the
5824 upper 16 bits of the address. */
5825 if (mips_pic == NO_PIC)
5827 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5829 else if (mips_pic == SVR4_PIC)
5831 macro_build ((char *) NULL, &icnt, &offset_expr,
5832 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5833 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
5836 else if (mips_pic == EMBEDDED_PIC)
5838 /* For embedded PIC we pick up the entire address off $gp in
5839 a single instruction. */
5840 macro_build ((char *) NULL, &icnt, &offset_expr,
5841 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j", AT,
5842 mips_gp_register, (int) BFD_RELOC_GPREL16);
5843 offset_expr.X_op = O_constant;
5844 offset_expr.X_add_number = 0;
5849 /* Now we load the register(s). */
5850 if (HAVE_64BIT_GPRS)
5851 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5852 treg, (int) BFD_RELOC_LO16, AT);
5855 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5856 treg, (int) BFD_RELOC_LO16, AT);
5859 /* FIXME: How in the world do we deal with the possible
5861 offset_expr.X_add_number += 4;
5862 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5863 treg + 1, (int) BFD_RELOC_LO16, AT);
5867 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5868 does not become a variant frag. */
5869 frag_wane (frag_now);
5875 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
5876 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
5877 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
5878 the value and the low order 32 bits are either zero or in
5880 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5882 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
5883 if (HAVE_64BIT_FPRS)
5885 assert (HAVE_64BIT_GPRS);
5886 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5887 "dmtc1", "t,S", AT, treg);
5891 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5892 "mtc1", "t,G", AT, treg + 1);
5893 if (offset_expr.X_op == O_absent)
5894 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5895 "mtc1", "t,G", 0, treg);
5898 assert (offset_expr.X_op == O_constant);
5899 load_register (&icnt, AT, &offset_expr, 0);
5900 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5901 "mtc1", "t,G", AT, treg);
5907 assert (offset_expr.X_op == O_symbol
5908 && offset_expr.X_add_number == 0);
5909 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5910 if (strcmp (s, ".lit8") == 0)
5912 if (mips_opts.isa != ISA_MIPS1)
5914 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5915 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL,
5919 breg = mips_gp_register;
5920 r = BFD_RELOC_MIPS_LITERAL;
5925 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5926 if (mips_pic == SVR4_PIC)
5927 macro_build ((char *) NULL, &icnt, &offset_expr,
5928 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5929 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
5933 /* FIXME: This won't work for a 64 bit address. */
5934 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5937 if (mips_opts.isa != ISA_MIPS1)
5939 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5940 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
5942 /* To avoid confusion in tc_gen_reloc, we must ensure
5943 that this does not become a variant frag. */
5944 frag_wane (frag_now);
5955 if (mips_arch == CPU_R4650)
5957 as_bad (_("opcode not supported on this processor"));
5960 /* Even on a big endian machine $fn comes before $fn+1. We have
5961 to adjust when loading from memory. */
5964 assert (mips_opts.isa == ISA_MIPS1);
5965 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5966 target_big_endian ? treg + 1 : treg,
5968 /* FIXME: A possible overflow which I don't know how to deal
5970 offset_expr.X_add_number += 4;
5971 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5972 target_big_endian ? treg : treg + 1,
5975 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5976 does not become a variant frag. */
5977 frag_wane (frag_now);
5986 * The MIPS assembler seems to check for X_add_number not
5987 * being double aligned and generating:
5990 * addiu at,at,%lo(foo+1)
5993 * But, the resulting address is the same after relocation so why
5994 * generate the extra instruction?
5996 if (mips_arch == CPU_R4650)
5998 as_bad (_("opcode not supported on this processor"));
6001 /* Itbl support may require additional care here. */
6003 if (mips_opts.isa != ISA_MIPS1)
6014 if (mips_arch == CPU_R4650)
6016 as_bad (_("opcode not supported on this processor"));
6020 if (mips_opts.isa != ISA_MIPS1)
6028 /* Itbl support may require additional care here. */
6033 if (HAVE_64BIT_GPRS)
6044 if (HAVE_64BIT_GPRS)
6054 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6055 loads for the case of doing a pair of loads to simulate an 'ld'.
6056 This is not currently done by the compiler, and assembly coders
6057 writing embedded-pic code can cope. */
6059 if (offset_expr.X_op != O_symbol
6060 && offset_expr.X_op != O_constant)
6062 as_bad (_("expression too complex"));
6063 offset_expr.X_op = O_constant;
6066 /* Even on a big endian machine $fn comes before $fn+1. We have
6067 to adjust when loading from memory. We set coproc if we must
6068 load $fn+1 first. */
6069 /* Itbl support may require additional care here. */
6070 if (! target_big_endian)
6073 if (mips_pic == NO_PIC
6074 || offset_expr.X_op == O_constant)
6078 /* If this is a reference to a GP relative symbol, we want
6079 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6080 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6081 If we have a base register, we use this
6083 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6084 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6085 If this is not a GP relative symbol, we want
6086 lui $at,<sym> (BFD_RELOC_HI16_S)
6087 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6088 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6089 If there is a base register, we add it to $at after the
6090 lui instruction. If there is a constant, we always use
6092 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6093 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6105 tempreg = mips_gp_register;
6112 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6113 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6114 "d,v,t", AT, breg, mips_gp_register);
6120 /* Itbl support may require additional care here. */
6121 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6122 coproc ? treg + 1 : treg,
6123 (int) BFD_RELOC_GPREL16, tempreg);
6124 offset_expr.X_add_number += 4;
6126 /* Set mips_optimize to 2 to avoid inserting an
6128 hold_mips_optimize = mips_optimize;
6130 /* Itbl support may require additional care here. */
6131 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6132 coproc ? treg : treg + 1,
6133 (int) BFD_RELOC_GPREL16, tempreg);
6134 mips_optimize = hold_mips_optimize;
6136 p = frag_var (rs_machine_dependent, 12 + off, 0,
6137 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6138 used_at && mips_opts.noat),
6139 offset_expr.X_add_symbol, 0, NULL);
6141 /* We just generated two relocs. When tc_gen_reloc
6142 handles this case, it will skip the first reloc and
6143 handle the second. The second reloc already has an
6144 extra addend of 4, which we added above. We must
6145 subtract it out, and then subtract another 4 to make
6146 the first reloc come out right. The second reloc
6147 will come out right because we are going to add 4 to
6148 offset_expr when we build its instruction below.
6150 If we have a symbol, then we don't want to include
6151 the offset, because it will wind up being included
6152 when we generate the reloc. */
6154 if (offset_expr.X_op == O_constant)
6155 offset_expr.X_add_number -= 8;
6158 offset_expr.X_add_number = -4;
6159 offset_expr.X_op = O_constant;
6162 macro_build_lui (p, &icnt, &offset_expr, AT);
6167 macro_build (p, &icnt, (expressionS *) NULL,
6168 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6169 "d,v,t", AT, breg, AT);
6173 /* Itbl support may require additional care here. */
6174 macro_build (p, &icnt, &offset_expr, s, fmt,
6175 coproc ? treg + 1 : treg,
6176 (int) BFD_RELOC_LO16, AT);
6179 /* FIXME: How do we handle overflow here? */
6180 offset_expr.X_add_number += 4;
6181 /* Itbl support may require additional care here. */
6182 macro_build (p, &icnt, &offset_expr, s, fmt,
6183 coproc ? treg : treg + 1,
6184 (int) BFD_RELOC_LO16, AT);
6186 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6190 /* If this is a reference to an external symbol, we want
6191 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6196 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6198 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6199 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6200 If there is a base register we add it to $at before the
6201 lwc1 instructions. If there is a constant we include it
6202 in the lwc1 instructions. */
6204 expr1.X_add_number = offset_expr.X_add_number;
6205 offset_expr.X_add_number = 0;
6206 if (expr1.X_add_number < -0x8000
6207 || expr1.X_add_number >= 0x8000 - 4)
6208 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6213 frag_grow (24 + off);
6214 macro_build ((char *) NULL, &icnt, &offset_expr,
6215 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", AT,
6216 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
6217 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6219 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6220 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6221 "d,v,t", AT, breg, AT);
6222 /* Itbl support may require additional care here. */
6223 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6224 coproc ? treg + 1 : treg,
6225 (int) BFD_RELOC_LO16, AT);
6226 expr1.X_add_number += 4;
6228 /* Set mips_optimize to 2 to avoid inserting an undesired
6230 hold_mips_optimize = mips_optimize;
6232 /* Itbl support may require additional care here. */
6233 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6234 coproc ? treg : treg + 1,
6235 (int) BFD_RELOC_LO16, AT);
6236 mips_optimize = hold_mips_optimize;
6238 (void) frag_var (rs_machine_dependent, 0, 0,
6239 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6240 offset_expr.X_add_symbol, 0, NULL);
6242 else if (mips_pic == SVR4_PIC)
6247 /* If this is a reference to an external symbol, we want
6248 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6250 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6255 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6257 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6258 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6259 If there is a base register we add it to $at before the
6260 lwc1 instructions. If there is a constant we include it
6261 in the lwc1 instructions. */
6263 expr1.X_add_number = offset_expr.X_add_number;
6264 offset_expr.X_add_number = 0;
6265 if (expr1.X_add_number < -0x8000
6266 || expr1.X_add_number >= 0x8000 - 4)
6267 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6268 if (reg_needs_delay (mips_gp_register))
6277 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6278 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
6279 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6280 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6281 "d,v,t", AT, AT, mips_gp_register);
6282 macro_build ((char *) NULL, &icnt, &offset_expr,
6283 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6284 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
6285 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6287 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6288 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6289 "d,v,t", AT, breg, AT);
6290 /* Itbl support may require additional care here. */
6291 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6292 coproc ? treg + 1 : treg,
6293 (int) BFD_RELOC_LO16, AT);
6294 expr1.X_add_number += 4;
6296 /* Set mips_optimize to 2 to avoid inserting an undesired
6298 hold_mips_optimize = mips_optimize;
6300 /* Itbl support may require additional care here. */
6301 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6302 coproc ? treg : treg + 1,
6303 (int) BFD_RELOC_LO16, AT);
6304 mips_optimize = hold_mips_optimize;
6305 expr1.X_add_number -= 4;
6307 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6308 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6309 8 + gpdel + off, 1, 0),
6310 offset_expr.X_add_symbol, 0, NULL);
6313 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6316 macro_build (p, &icnt, &offset_expr,
6317 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6318 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
6321 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6325 macro_build (p, &icnt, (expressionS *) NULL,
6326 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6327 "d,v,t", AT, breg, AT);
6330 /* Itbl support may require additional care here. */
6331 macro_build (p, &icnt, &expr1, s, fmt,
6332 coproc ? treg + 1 : treg,
6333 (int) BFD_RELOC_LO16, AT);
6335 expr1.X_add_number += 4;
6337 /* Set mips_optimize to 2 to avoid inserting an undesired
6339 hold_mips_optimize = mips_optimize;
6341 /* Itbl support may require additional care here. */
6342 macro_build (p, &icnt, &expr1, s, fmt,
6343 coproc ? treg : treg + 1,
6344 (int) BFD_RELOC_LO16, AT);
6345 mips_optimize = hold_mips_optimize;
6347 else if (mips_pic == EMBEDDED_PIC)
6349 /* If there is no base register, we use
6350 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6351 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6352 If we have a base register, we use
6354 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6355 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6359 tempreg = mips_gp_register;
6364 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6365 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6366 "d,v,t", AT, breg, mips_gp_register);
6371 /* Itbl support may require additional care here. */
6372 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6373 coproc ? treg + 1 : treg,
6374 (int) BFD_RELOC_GPREL16, tempreg);
6375 offset_expr.X_add_number += 4;
6376 /* Itbl support may require additional care here. */
6377 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6378 coproc ? treg : treg + 1,
6379 (int) BFD_RELOC_GPREL16, tempreg);
6395 assert (HAVE_32BIT_ADDRESSES);
6396 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6397 (int) BFD_RELOC_LO16, breg);
6398 offset_expr.X_add_number += 4;
6399 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
6400 (int) BFD_RELOC_LO16, breg);
6403 /* New code added to support COPZ instructions.
6404 This code builds table entries out of the macros in mip_opcodes.
6405 R4000 uses interlocks to handle coproc delays.
6406 Other chips (like the R3000) require nops to be inserted for delays.
6408 FIXME: Currently, we require that the user handle delays.
6409 In order to fill delay slots for non-interlocked chips,
6410 we must have a way to specify delays based on the coprocessor.
6411 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6412 What are the side-effects of the cop instruction?
6413 What cache support might we have and what are its effects?
6414 Both coprocessor & memory require delays. how long???
6415 What registers are read/set/modified?
6417 If an itbl is provided to interpret cop instructions,
6418 this knowledge can be encoded in the itbl spec. */
6432 /* For now we just do C (same as Cz). The parameter will be
6433 stored in insn_opcode by mips_ip. */
6434 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
6439 move_register (&icnt, dreg, sreg);
6442 #ifdef LOSING_COMPILER
6444 /* Try and see if this is a new itbl instruction.
6445 This code builds table entries out of the macros in mip_opcodes.
6446 FIXME: For now we just assemble the expression and pass it's
6447 value along as a 32-bit immediate.
6448 We may want to have the assembler assemble this value,
6449 so that we gain the assembler's knowledge of delay slots,
6451 Would it be more efficient to use mask (id) here? */
6452 if (itbl_have_entries
6453 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6455 s = ip->insn_mo->name;
6457 coproc = ITBL_DECODE_PNUM (immed_expr);;
6458 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
6465 as_warn (_("Macro used $at after \".set noat\""));
6470 struct mips_cl_insn *ip;
6472 register int treg, sreg, dreg, breg;
6488 bfd_reloc_code_real_type r;
6491 treg = (ip->insn_opcode >> 16) & 0x1f;
6492 dreg = (ip->insn_opcode >> 11) & 0x1f;
6493 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6494 mask = ip->insn_mo->mask;
6496 expr1.X_op = O_constant;
6497 expr1.X_op_symbol = NULL;
6498 expr1.X_add_symbol = NULL;
6499 expr1.X_add_number = 1;
6503 #endif /* LOSING_COMPILER */
6508 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6509 dbl ? "dmultu" : "multu", "s,t", sreg, treg);
6510 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6517 /* The MIPS assembler some times generates shifts and adds. I'm
6518 not trying to be that fancy. GCC should do this for us
6520 load_register (&icnt, AT, &imm_expr, dbl);
6521 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6522 dbl ? "dmult" : "mult", "s,t", sreg, AT);
6523 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6537 mips_emit_delays (true);
6538 ++mips_opts.noreorder;
6539 mips_any_noreorder = 1;
6541 load_register (&icnt, AT, &imm_expr, dbl);
6542 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6543 dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
6544 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6546 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6547 dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA);
6548 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6551 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6555 expr1.X_add_number = 8;
6556 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg,
6558 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6560 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6563 --mips_opts.noreorder;
6564 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg);
6577 mips_emit_delays (true);
6578 ++mips_opts.noreorder;
6579 mips_any_noreorder = 1;
6581 load_register (&icnt, AT, &imm_expr, dbl);
6582 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6583 dbl ? "dmultu" : "multu",
6584 "s,t", sreg, imm ? AT : treg);
6585 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6587 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6590 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6594 expr1.X_add_number = 8;
6595 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6596 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6598 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6601 --mips_opts.noreorder;
6605 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
6606 "d,v,t", AT, 0, treg);
6607 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
6608 "d,t,s", AT, sreg, AT);
6609 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
6610 "d,t,s", dreg, sreg, treg);
6611 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6612 "d,v,t", dreg, dreg, AT);
6616 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6617 "d,v,t", AT, 0, treg);
6618 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6619 "d,t,s", AT, sreg, AT);
6620 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6621 "d,t,s", dreg, sreg, treg);
6622 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6623 "d,v,t", dreg, dreg, AT);
6631 if (imm_expr.X_op != O_constant)
6632 as_bad (_("rotate count too large"));
6633 rot = imm_expr.X_add_number & 0x3f;
6636 l = (rot < 0x20) ? "dsll" : "dsll32";
6637 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
6639 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
6640 "d,w,<", AT, sreg, rot);
6641 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
6642 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6643 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6644 "d,v,t", dreg, dreg, AT);
6652 if (imm_expr.X_op != O_constant)
6653 as_bad (_("rotate count too large"));
6654 rot = imm_expr.X_add_number & 0x1f;
6657 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
6658 "d,w,<", AT, sreg, rot);
6659 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
6660 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6661 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6662 "d,v,t", dreg, dreg, AT);
6667 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
6668 "d,v,t", AT, 0, treg);
6669 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
6670 "d,t,s", AT, sreg, AT);
6671 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
6672 "d,t,s", dreg, sreg, treg);
6673 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6674 "d,v,t", dreg, dreg, AT);
6678 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6679 "d,v,t", AT, 0, treg);
6680 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6681 "d,t,s", AT, sreg, AT);
6682 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6683 "d,t,s", dreg, sreg, treg);
6684 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6685 "d,v,t", dreg, dreg, AT);
6693 if (imm_expr.X_op != O_constant)
6694 as_bad (_("rotate count too large"));
6695 rot = imm_expr.X_add_number & 0x3f;
6698 r = (rot < 0x20) ? "dsrl" : "dsrl32";
6699 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
6701 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
6702 "d,w,<", AT, sreg, rot);
6703 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
6704 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6705 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6706 "d,v,t", dreg, dreg, AT);
6714 if (imm_expr.X_op != O_constant)
6715 as_bad (_("rotate count too large"));
6716 rot = imm_expr.X_add_number & 0x1f;
6719 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
6720 "d,w,<", AT, sreg, rot);
6721 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
6722 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6723 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6724 "d,v,t", dreg, dreg, AT);
6729 if (mips_arch == CPU_R4650)
6731 as_bad (_("opcode not supported on this processor"));
6734 assert (mips_opts.isa == ISA_MIPS1);
6735 /* Even on a big endian machine $fn comes before $fn+1. We have
6736 to adjust when storing to memory. */
6737 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6738 target_big_endian ? treg + 1 : treg,
6739 (int) BFD_RELOC_LO16, breg);
6740 offset_expr.X_add_number += 4;
6741 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6742 target_big_endian ? treg : treg + 1,
6743 (int) BFD_RELOC_LO16, breg);
6748 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6749 treg, (int) BFD_RELOC_LO16);
6751 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6752 sreg, (int) BFD_RELOC_LO16);
6755 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6756 "d,v,t", dreg, sreg, treg);
6757 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6758 dreg, (int) BFD_RELOC_LO16);
6763 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6765 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6766 sreg, (int) BFD_RELOC_LO16);
6771 as_warn (_("Instruction %s: result is always false"),
6773 move_register (&icnt, dreg, 0);
6776 if (imm_expr.X_op == O_constant
6777 && imm_expr.X_add_number >= 0
6778 && imm_expr.X_add_number < 0x10000)
6780 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6781 sreg, (int) BFD_RELOC_LO16);
6784 else if (imm_expr.X_op == O_constant
6785 && imm_expr.X_add_number > -0x8000
6786 && imm_expr.X_add_number < 0)
6788 imm_expr.X_add_number = -imm_expr.X_add_number;
6789 macro_build ((char *) NULL, &icnt, &imm_expr,
6790 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6791 "t,r,j", dreg, sreg,
6792 (int) BFD_RELOC_LO16);
6797 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6798 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6799 "d,v,t", dreg, sreg, AT);
6802 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6803 (int) BFD_RELOC_LO16);
6808 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6814 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6816 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6817 (int) BFD_RELOC_LO16);
6820 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6822 if (imm_expr.X_op == O_constant
6823 && imm_expr.X_add_number >= -0x8000
6824 && imm_expr.X_add_number < 0x8000)
6826 macro_build ((char *) NULL, &icnt, &imm_expr,
6827 mask == M_SGE_I ? "slti" : "sltiu",
6828 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6833 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6834 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6835 mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg,
6839 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6840 (int) BFD_RELOC_LO16);
6845 case M_SGT: /* sreg > treg <==> treg < sreg */
6851 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6855 case M_SGT_I: /* sreg > I <==> I < sreg */
6861 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6862 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6866 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6872 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6874 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6875 (int) BFD_RELOC_LO16);
6878 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6884 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6885 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6887 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6888 (int) BFD_RELOC_LO16);
6892 if (imm_expr.X_op == O_constant
6893 && imm_expr.X_add_number >= -0x8000
6894 && imm_expr.X_add_number < 0x8000)
6896 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
6897 dreg, sreg, (int) BFD_RELOC_LO16);
6900 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6901 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
6906 if (imm_expr.X_op == O_constant
6907 && imm_expr.X_add_number >= -0x8000
6908 && imm_expr.X_add_number < 0x8000)
6910 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
6911 dreg, sreg, (int) BFD_RELOC_LO16);
6914 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6915 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6916 "d,v,t", dreg, sreg, AT);
6921 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6922 "d,v,t", dreg, 0, treg);
6924 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6925 "d,v,t", dreg, 0, sreg);
6928 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6929 "d,v,t", dreg, sreg, treg);
6930 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6931 "d,v,t", dreg, 0, dreg);
6936 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6938 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6939 "d,v,t", dreg, 0, sreg);
6944 as_warn (_("Instruction %s: result is always true"),
6946 macro_build ((char *) NULL, &icnt, &expr1,
6947 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6948 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
6951 if (imm_expr.X_op == O_constant
6952 && imm_expr.X_add_number >= 0
6953 && imm_expr.X_add_number < 0x10000)
6955 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
6956 dreg, sreg, (int) BFD_RELOC_LO16);
6959 else if (imm_expr.X_op == O_constant
6960 && imm_expr.X_add_number > -0x8000
6961 && imm_expr.X_add_number < 0)
6963 imm_expr.X_add_number = -imm_expr.X_add_number;
6964 macro_build ((char *) NULL, &icnt, &imm_expr,
6965 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6966 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6971 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6972 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6973 "d,v,t", dreg, sreg, AT);
6976 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6977 "d,v,t", dreg, 0, dreg);
6985 if (imm_expr.X_op == O_constant
6986 && imm_expr.X_add_number > -0x8000
6987 && imm_expr.X_add_number <= 0x8000)
6989 imm_expr.X_add_number = -imm_expr.X_add_number;
6990 macro_build ((char *) NULL, &icnt, &imm_expr,
6991 dbl ? "daddi" : "addi",
6992 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6995 load_register (&icnt, AT, &imm_expr, dbl);
6996 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6997 dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
7003 if (imm_expr.X_op == O_constant
7004 && imm_expr.X_add_number > -0x8000
7005 && imm_expr.X_add_number <= 0x8000)
7007 imm_expr.X_add_number = -imm_expr.X_add_number;
7008 macro_build ((char *) NULL, &icnt, &imm_expr,
7009 dbl ? "daddiu" : "addiu",
7010 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7013 load_register (&icnt, AT, &imm_expr, dbl);
7014 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7015 dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
7036 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7037 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg,
7043 assert (mips_opts.isa == ISA_MIPS1);
7044 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7045 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7048 * Is the double cfc1 instruction a bug in the mips assembler;
7049 * or is there a reason for it?
7051 mips_emit_delays (true);
7052 ++mips_opts.noreorder;
7053 mips_any_noreorder = 1;
7054 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7056 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7058 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7059 expr1.X_add_number = 3;
7060 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7061 (int) BFD_RELOC_LO16);
7062 expr1.X_add_number = 2;
7063 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7064 (int) BFD_RELOC_LO16);
7065 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7067 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7068 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7069 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
7070 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7072 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7073 --mips_opts.noreorder;
7082 if (offset_expr.X_add_number >= 0x7fff)
7083 as_bad (_("operand overflow"));
7084 /* avoid load delay */
7085 if (! target_big_endian)
7086 ++offset_expr.X_add_number;
7087 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7088 (int) BFD_RELOC_LO16, breg);
7089 if (! target_big_endian)
7090 --offset_expr.X_add_number;
7092 ++offset_expr.X_add_number;
7093 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
7094 (int) BFD_RELOC_LO16, breg);
7095 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7097 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7111 if (offset_expr.X_add_number >= 0x8000 - off)
7112 as_bad (_("operand overflow"));
7113 if (! target_big_endian)
7114 offset_expr.X_add_number += off;
7115 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7116 (int) BFD_RELOC_LO16, breg);
7117 if (! target_big_endian)
7118 offset_expr.X_add_number -= off;
7120 offset_expr.X_add_number += off;
7121 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7122 (int) BFD_RELOC_LO16, breg);
7136 load_address (&icnt, AT, &offset_expr, &used_at);
7138 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7139 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7140 "d,v,t", AT, AT, breg);
7141 if (! target_big_endian)
7142 expr1.X_add_number = off;
7144 expr1.X_add_number = 0;
7145 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7146 (int) BFD_RELOC_LO16, AT);
7147 if (! target_big_endian)
7148 expr1.X_add_number = 0;
7150 expr1.X_add_number = off;
7151 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7152 (int) BFD_RELOC_LO16, AT);
7158 load_address (&icnt, AT, &offset_expr, &used_at);
7160 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7161 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7162 "d,v,t", AT, AT, breg);
7163 if (target_big_endian)
7164 expr1.X_add_number = 0;
7165 macro_build ((char *) NULL, &icnt, &expr1,
7166 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
7167 (int) BFD_RELOC_LO16, AT);
7168 if (target_big_endian)
7169 expr1.X_add_number = 1;
7171 expr1.X_add_number = 0;
7172 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7173 (int) BFD_RELOC_LO16, AT);
7174 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7176 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7181 if (offset_expr.X_add_number >= 0x7fff)
7182 as_bad (_("operand overflow"));
7183 if (target_big_endian)
7184 ++offset_expr.X_add_number;
7185 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7186 (int) BFD_RELOC_LO16, breg);
7187 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7189 if (target_big_endian)
7190 --offset_expr.X_add_number;
7192 ++offset_expr.X_add_number;
7193 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7194 (int) BFD_RELOC_LO16, breg);
7207 if (offset_expr.X_add_number >= 0x8000 - off)
7208 as_bad (_("operand overflow"));
7209 if (! target_big_endian)
7210 offset_expr.X_add_number += off;
7211 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7212 (int) BFD_RELOC_LO16, breg);
7213 if (! target_big_endian)
7214 offset_expr.X_add_number -= off;
7216 offset_expr.X_add_number += off;
7217 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7218 (int) BFD_RELOC_LO16, breg);
7232 load_address (&icnt, AT, &offset_expr, &used_at);
7234 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7235 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7236 "d,v,t", AT, AT, breg);
7237 if (! target_big_endian)
7238 expr1.X_add_number = off;
7240 expr1.X_add_number = 0;
7241 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7242 (int) BFD_RELOC_LO16, AT);
7243 if (! target_big_endian)
7244 expr1.X_add_number = 0;
7246 expr1.X_add_number = off;
7247 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7248 (int) BFD_RELOC_LO16, AT);
7253 load_address (&icnt, AT, &offset_expr, &used_at);
7255 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7256 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7257 "d,v,t", AT, AT, breg);
7258 if (! target_big_endian)
7259 expr1.X_add_number = 0;
7260 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7261 (int) BFD_RELOC_LO16, AT);
7262 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7264 if (! target_big_endian)
7265 expr1.X_add_number = 1;
7267 expr1.X_add_number = 0;
7268 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7269 (int) BFD_RELOC_LO16, AT);
7270 if (! target_big_endian)
7271 expr1.X_add_number = 0;
7273 expr1.X_add_number = 1;
7274 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7275 (int) BFD_RELOC_LO16, AT);
7276 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7278 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7283 /* FIXME: Check if this is one of the itbl macros, since they
7284 are added dynamically. */
7285 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7289 as_warn (_("Macro used $at after \".set noat\""));
7292 /* Implement macros in mips16 mode. */
7296 struct mips_cl_insn *ip;
7299 int xreg, yreg, zreg, tmp;
7303 const char *s, *s2, *s3;
7305 mask = ip->insn_mo->mask;
7307 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7308 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7309 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7313 expr1.X_op = O_constant;
7314 expr1.X_op_symbol = NULL;
7315 expr1.X_add_symbol = NULL;
7316 expr1.X_add_number = 1;
7335 mips_emit_delays (true);
7336 ++mips_opts.noreorder;
7337 mips_any_noreorder = 1;
7338 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7339 dbl ? "ddiv" : "div",
7340 "0,x,y", xreg, yreg);
7341 expr1.X_add_number = 2;
7342 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7343 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6",
7346 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7347 since that causes an overflow. We should do that as well,
7348 but I don't see how to do the comparisons without a temporary
7350 --mips_opts.noreorder;
7351 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg);
7370 mips_emit_delays (true);
7371 ++mips_opts.noreorder;
7372 mips_any_noreorder = 1;
7373 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y",
7375 expr1.X_add_number = 2;
7376 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7377 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7379 --mips_opts.noreorder;
7380 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg);
7386 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7387 dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7388 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x",
7397 if (imm_expr.X_op != O_constant)
7398 as_bad (_("Unsupported large constant"));
7399 imm_expr.X_add_number = -imm_expr.X_add_number;
7400 macro_build ((char *) NULL, &icnt, &imm_expr,
7401 dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7405 if (imm_expr.X_op != O_constant)
7406 as_bad (_("Unsupported large constant"));
7407 imm_expr.X_add_number = -imm_expr.X_add_number;
7408 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
7413 if (imm_expr.X_op != O_constant)
7414 as_bad (_("Unsupported large constant"));
7415 imm_expr.X_add_number = -imm_expr.X_add_number;
7416 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
7439 goto do_reverse_branch;
7443 goto do_reverse_branch;
7455 goto do_reverse_branch;
7466 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
7468 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7495 goto do_addone_branch_i;
7500 goto do_addone_branch_i;
7515 goto do_addone_branch_i;
7522 if (imm_expr.X_op != O_constant)
7523 as_bad (_("Unsupported large constant"));
7524 ++imm_expr.X_add_number;
7527 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
7528 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7532 expr1.X_add_number = 0;
7533 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
7535 move_register (&icnt, xreg, yreg);
7536 expr1.X_add_number = 2;
7537 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
7538 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7539 "neg", "x,w", xreg, xreg);
7543 /* For consistency checking, verify that all bits are specified either
7544 by the match/mask part of the instruction definition, or by the
7547 validate_mips_insn (opc)
7548 const struct mips_opcode *opc;
7550 const char *p = opc->args;
7552 unsigned long used_bits = opc->mask;
7554 if ((used_bits & opc->match) != opc->match)
7556 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7557 opc->name, opc->args);
7560 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7567 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7568 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7570 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
7571 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
7572 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7573 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7575 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7576 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7578 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
7580 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
7581 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
7582 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
7583 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
7584 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7585 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
7586 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7587 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7588 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7589 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7590 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7591 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7592 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7593 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
7594 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7595 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
7596 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7598 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
7599 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7600 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7601 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
7603 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7604 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7605 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
7606 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7607 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7608 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7609 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7610 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7611 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7614 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
7615 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
7616 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7618 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7619 c, opc->name, opc->args);
7623 if (used_bits != 0xffffffff)
7625 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7626 ~used_bits & 0xffffffff, opc->name, opc->args);
7632 /* This routine assembles an instruction into its binary format. As a
7633 side effect, it sets one of the global variables imm_reloc or
7634 offset_reloc to the type of relocation to do if one of the operands
7635 is an address expression. */
7640 struct mips_cl_insn *ip;
7645 struct mips_opcode *insn;
7648 unsigned int lastregno = 0;
7654 /* If the instruction contains a '.', we first try to match an instruction
7655 including the '.'. Then we try again without the '.'. */
7657 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
7660 /* If we stopped on whitespace, then replace the whitespace with null for
7661 the call to hash_find. Save the character we replaced just in case we
7662 have to re-parse the instruction. */
7669 insn = (struct mips_opcode *) hash_find (op_hash, str);
7671 /* If we didn't find the instruction in the opcode table, try again, but
7672 this time with just the instruction up to, but not including the
7676 /* Restore the character we overwrite above (if any). */
7680 /* Scan up to the first '.' or whitespace. */
7682 *s != '\0' && *s != '.' && !ISSPACE (*s);
7686 /* If we did not find a '.', then we can quit now. */
7689 insn_error = "unrecognized opcode";
7693 /* Lookup the instruction in the hash table. */
7695 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7697 insn_error = "unrecognized opcode";
7707 assert (strcmp (insn->name, str) == 0);
7709 if (OPCODE_IS_MEMBER (insn,
7711 | (mips_opts.mips16 ? INSN_MIPS16 : 0)
7712 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
7713 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
7719 if (insn->pinfo != INSN_MACRO)
7721 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7727 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7728 && strcmp (insn->name, insn[1].name) == 0)
7737 static char buf[100];
7738 if (mips_arch_info->is_isa)
7740 _("opcode not supported at this ISA level (%s)"),
7741 mips_cpu_info_from_isa (mips_opts.isa)->name);
7744 _("opcode not supported on this processor: %s (%s)"),
7745 mips_arch_info->name,
7746 mips_cpu_info_from_isa (mips_opts.isa)->name);
7756 ip->insn_opcode = insn->match;
7758 for (args = insn->args;; ++args)
7762 s += strspn (s, " \t");
7766 case '\0': /* end of args */
7779 ip->insn_opcode |= lastregno << OP_SH_RS;
7783 ip->insn_opcode |= lastregno << OP_SH_RT;
7787 ip->insn_opcode |= lastregno << OP_SH_FT;
7791 ip->insn_opcode |= lastregno << OP_SH_FS;
7797 /* Handle optional base register.
7798 Either the base register is omitted or
7799 we must have a left paren. */
7800 /* This is dependent on the next operand specifier
7801 is a base register specification. */
7802 assert (args[1] == 'b' || args[1] == '5'
7803 || args[1] == '-' || args[1] == '4');
7807 case ')': /* these must match exactly */
7812 case '<': /* must be at least one digit */
7814 * According to the manual, if the shift amount is greater
7815 * than 31 or less than 0, then the shift amount should be
7816 * mod 32. In reality the mips assembler issues an error.
7817 * We issue a warning and mask out all but the low 5 bits.
7819 my_getExpression (&imm_expr, s);
7820 check_absolute_expr (ip, &imm_expr);
7821 if ((unsigned long) imm_expr.X_add_number > 31)
7823 as_warn (_("Improper shift amount (%lu)"),
7824 (unsigned long) imm_expr.X_add_number);
7825 imm_expr.X_add_number &= OP_MASK_SHAMT;
7827 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
7828 imm_expr.X_op = O_absent;
7832 case '>': /* shift amount minus 32 */
7833 my_getExpression (&imm_expr, s);
7834 check_absolute_expr (ip, &imm_expr);
7835 if ((unsigned long) imm_expr.X_add_number < 32
7836 || (unsigned long) imm_expr.X_add_number > 63)
7838 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
7839 imm_expr.X_op = O_absent;
7843 case 'k': /* cache code */
7844 case 'h': /* prefx code */
7845 my_getExpression (&imm_expr, s);
7846 check_absolute_expr (ip, &imm_expr);
7847 if ((unsigned long) imm_expr.X_add_number > 31)
7849 as_warn (_("Invalid value for `%s' (%lu)"),
7851 (unsigned long) imm_expr.X_add_number);
7852 imm_expr.X_add_number &= 0x1f;
7855 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7857 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7858 imm_expr.X_op = O_absent;
7862 case 'c': /* break code */
7863 my_getExpression (&imm_expr, s);
7864 check_absolute_expr (ip, &imm_expr);
7865 if ((unsigned long) imm_expr.X_add_number > 1023)
7867 as_warn (_("Illegal break code (%lu)"),
7868 (unsigned long) imm_expr.X_add_number);
7869 imm_expr.X_add_number &= OP_MASK_CODE;
7871 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
7872 imm_expr.X_op = O_absent;
7876 case 'q': /* lower break code */
7877 my_getExpression (&imm_expr, s);
7878 check_absolute_expr (ip, &imm_expr);
7879 if ((unsigned long) imm_expr.X_add_number > 1023)
7881 as_warn (_("Illegal lower break code (%lu)"),
7882 (unsigned long) imm_expr.X_add_number);
7883 imm_expr.X_add_number &= OP_MASK_CODE2;
7885 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
7886 imm_expr.X_op = O_absent;
7890 case 'B': /* 20-bit syscall/break code. */
7891 my_getExpression (&imm_expr, s);
7892 check_absolute_expr (ip, &imm_expr);
7893 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
7894 as_warn (_("Illegal 20-bit code (%lu)"),
7895 (unsigned long) imm_expr.X_add_number);
7896 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
7897 imm_expr.X_op = O_absent;
7901 case 'C': /* Coprocessor code */
7902 my_getExpression (&imm_expr, s);
7903 check_absolute_expr (ip, &imm_expr);
7904 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
7906 as_warn (_("Coproccesor code > 25 bits (%lu)"),
7907 (unsigned long) imm_expr.X_add_number);
7908 imm_expr.X_add_number &= ((1 << 25) - 1);
7910 ip->insn_opcode |= imm_expr.X_add_number;
7911 imm_expr.X_op = O_absent;
7915 case 'J': /* 19-bit wait code. */
7916 my_getExpression (&imm_expr, s);
7917 check_absolute_expr (ip, &imm_expr);
7918 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
7919 as_warn (_("Illegal 19-bit code (%lu)"),
7920 (unsigned long) imm_expr.X_add_number);
7921 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
7922 imm_expr.X_op = O_absent;
7926 case 'P': /* Performance register */
7927 my_getExpression (&imm_expr, s);
7928 check_absolute_expr (ip, &imm_expr);
7929 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
7931 as_warn (_("Invalid performance register (%lu)"),
7932 (unsigned long) imm_expr.X_add_number);
7933 imm_expr.X_add_number &= OP_MASK_PERFREG;
7935 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
7936 imm_expr.X_op = O_absent;
7940 case 'b': /* base register */
7941 case 'd': /* destination register */
7942 case 's': /* source register */
7943 case 't': /* target register */
7944 case 'r': /* both target and source */
7945 case 'v': /* both dest and source */
7946 case 'w': /* both dest and target */
7947 case 'E': /* coprocessor target register */
7948 case 'G': /* coprocessor destination register */
7949 case 'x': /* ignore register name */
7950 case 'z': /* must be zero register */
7951 case 'U': /* destination register (clo/clz). */
7966 while (ISDIGIT (*s));
7968 as_bad (_("Invalid register number (%d)"), regno);
7970 else if (*args == 'E' || *args == 'G')
7974 if (s[1] == 'r' && s[2] == 'a')
7979 else if (s[1] == 'f' && s[2] == 'p')
7984 else if (s[1] == 's' && s[2] == 'p')
7989 else if (s[1] == 'g' && s[2] == 'p')
7994 else if (s[1] == 'a' && s[2] == 't')
7999 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8004 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8009 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8014 else if (itbl_have_entries)
8019 p = s + 1; /* advance past '$' */
8020 n = itbl_get_field (&p); /* n is name */
8022 /* See if this is a register defined in an
8024 if (itbl_get_reg_val (n, &r))
8026 /* Get_field advances to the start of
8027 the next field, so we need to back
8028 rack to the end of the last field. */
8032 s = strchr (s, '\0');
8045 as_warn (_("Used $at without \".set noat\""));
8051 if (c == 'r' || c == 'v' || c == 'w')
8058 /* 'z' only matches $0. */
8059 if (c == 'z' && regno != 0)
8062 /* Now that we have assembled one operand, we use the args string
8063 * to figure out where it goes in the instruction. */
8070 ip->insn_opcode |= regno << OP_SH_RS;
8074 ip->insn_opcode |= regno << OP_SH_RD;
8077 ip->insn_opcode |= regno << OP_SH_RD;
8078 ip->insn_opcode |= regno << OP_SH_RT;
8083 ip->insn_opcode |= regno << OP_SH_RT;
8086 /* This case exists because on the r3000 trunc
8087 expands into a macro which requires a gp
8088 register. On the r6000 or r4000 it is
8089 assembled into a single instruction which
8090 ignores the register. Thus the insn version
8091 is MIPS_ISA2 and uses 'x', and the macro
8092 version is MIPS_ISA1 and uses 't'. */
8095 /* This case is for the div instruction, which
8096 acts differently if the destination argument
8097 is $0. This only matches $0, and is checked
8098 outside the switch. */
8101 /* Itbl operand; not yet implemented. FIXME ?? */
8103 /* What about all other operands like 'i', which
8104 can be specified in the opcode table? */
8114 ip->insn_opcode |= lastregno << OP_SH_RS;
8117 ip->insn_opcode |= lastregno << OP_SH_RT;
8122 case 'O': /* MDMX alignment immediate constant. */
8123 my_getExpression (&imm_expr, s);
8124 check_absolute_expr (ip, &imm_expr);
8125 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
8127 as_warn ("Improper align amount (%ld), using low bits",
8128 (long) imm_expr.X_add_number);
8129 imm_expr.X_add_number &= OP_MASK_ALN;
8131 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_ALN;
8132 imm_expr.X_op = O_absent;
8136 case 'Q': /* MDMX vector, element sel, or const. */
8139 /* MDMX Immediate. */
8140 my_getExpression (&imm_expr, s);
8141 check_absolute_expr (ip, &imm_expr);
8142 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
8144 as_warn (_("Invalid MDMX Immediate (%ld)"),
8145 (long) imm_expr.X_add_number);
8146 imm_expr.X_add_number &= OP_MASK_FT;
8148 imm_expr.X_add_number &= OP_MASK_FT;
8149 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8150 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
8152 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
8153 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_FT;
8154 imm_expr.X_op = O_absent;
8158 /* Not MDMX Immediate. Fall through. */
8159 case 'X': /* MDMX destination register. */
8160 case 'Y': /* MDMX source register. */
8161 case 'Z': /* MDMX target register. */
8163 case 'D': /* floating point destination register */
8164 case 'S': /* floating point source register */
8165 case 'T': /* floating point target register */
8166 case 'R': /* floating point source register */
8170 /* Accept $fN for FP and MDMX register numbers, and in
8171 addition accept $vN for MDMX register numbers. */
8172 if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2]))
8173 || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v'
8184 while (ISDIGIT (*s));
8187 as_bad (_("Invalid float register number (%d)"), regno);
8189 if ((regno & 1) != 0
8191 && ! (strcmp (str, "mtc1") == 0
8192 || strcmp (str, "mfc1") == 0
8193 || strcmp (str, "lwc1") == 0
8194 || strcmp (str, "swc1") == 0
8195 || strcmp (str, "l.s") == 0
8196 || strcmp (str, "s.s") == 0))
8197 as_warn (_("Float register should be even, was %d"),
8205 if (c == 'V' || c == 'W')
8216 ip->insn_opcode |= regno << OP_SH_FD;
8221 ip->insn_opcode |= regno << OP_SH_FS;
8224 /* This is like 'Z', but also needs to fix the MDMX
8225 vector/scalar select bits. Note that the
8226 scalar immediate case is handled above. */
8229 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
8230 int max_el = (is_qh ? 3 : 7);
8232 my_getExpression(&imm_expr, s);
8233 check_absolute_expr (ip, &imm_expr);
8235 if (imm_expr.X_add_number > max_el)
8236 as_bad(_("Bad element selector %ld"),
8237 (long) imm_expr.X_add_number);
8238 imm_expr.X_add_number &= max_el;
8239 ip->insn_opcode |= (imm_expr.X_add_number
8243 as_warn(_("Expecting ']' found '%s'"), s);
8249 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8250 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
8253 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
8260 ip->insn_opcode |= regno << OP_SH_FT;
8263 ip->insn_opcode |= regno << OP_SH_FR;
8273 ip->insn_opcode |= lastregno << OP_SH_FS;
8276 ip->insn_opcode |= lastregno << OP_SH_FT;
8282 my_getExpression (&imm_expr, s);
8283 if (imm_expr.X_op != O_big
8284 && imm_expr.X_op != O_constant)
8285 insn_error = _("absolute expression required");
8290 my_getExpression (&offset_expr, s);
8291 *imm_reloc = BFD_RELOC_32;
8304 unsigned char temp[8];
8306 unsigned int length;
8311 /* These only appear as the last operand in an
8312 instruction, and every instruction that accepts
8313 them in any variant accepts them in all variants.
8314 This means we don't have to worry about backing out
8315 any changes if the instruction does not match.
8317 The difference between them is the size of the
8318 floating point constant and where it goes. For 'F'
8319 and 'L' the constant is 64 bits; for 'f' and 'l' it
8320 is 32 bits. Where the constant is placed is based
8321 on how the MIPS assembler does things:
8324 f -- immediate value
8327 The .lit4 and .lit8 sections are only used if
8328 permitted by the -G argument.
8330 When generating embedded PIC code, we use the
8331 .lit8 section but not the .lit4 section (we can do
8332 .lit4 inline easily; we need to put .lit8
8333 somewhere in the data segment, and using .lit8
8334 permits the linker to eventually combine identical
8337 The code below needs to know whether the target register
8338 is 32 or 64 bits wide. It relies on the fact 'f' and
8339 'F' are used with GPR-based instructions and 'l' and
8340 'L' are used with FPR-based instructions. */
8342 f64 = *args == 'F' || *args == 'L';
8343 using_gprs = *args == 'F' || *args == 'f';
8345 save_in = input_line_pointer;
8346 input_line_pointer = s;
8347 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8349 s = input_line_pointer;
8350 input_line_pointer = save_in;
8351 if (err != NULL && *err != '\0')
8353 as_bad (_("Bad floating point constant: %s"), err);
8354 memset (temp, '\0', sizeof temp);
8355 length = f64 ? 8 : 4;
8358 assert (length == (unsigned) (f64 ? 8 : 4));
8362 && (! USE_GLOBAL_POINTER_OPT
8363 || mips_pic == EMBEDDED_PIC
8364 || g_switch_value < 4
8365 || (temp[0] == 0 && temp[1] == 0)
8366 || (temp[2] == 0 && temp[3] == 0))))
8368 imm_expr.X_op = O_constant;
8369 if (! target_big_endian)
8370 imm_expr.X_add_number = bfd_getl32 (temp);
8372 imm_expr.X_add_number = bfd_getb32 (temp);
8375 && ! mips_disable_float_construction
8376 /* Constants can only be constructed in GPRs and
8377 copied to FPRs if the GPRs are at least as wide
8378 as the FPRs. Force the constant into memory if
8379 we are using 64-bit FPRs but the GPRs are only
8382 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8383 && ((temp[0] == 0 && temp[1] == 0)
8384 || (temp[2] == 0 && temp[3] == 0))
8385 && ((temp[4] == 0 && temp[5] == 0)
8386 || (temp[6] == 0 && temp[7] == 0)))
8388 /* The value is simple enough to load with a couple of
8389 instructions. If using 32-bit registers, set
8390 imm_expr to the high order 32 bits and offset_expr to
8391 the low order 32 bits. Otherwise, set imm_expr to
8392 the entire 64 bit constant. */
8393 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8395 imm_expr.X_op = O_constant;
8396 offset_expr.X_op = O_constant;
8397 if (! target_big_endian)
8399 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8400 offset_expr.X_add_number = bfd_getl32 (temp);
8404 imm_expr.X_add_number = bfd_getb32 (temp);
8405 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8407 if (offset_expr.X_add_number == 0)
8408 offset_expr.X_op = O_absent;
8410 else if (sizeof (imm_expr.X_add_number) > 4)
8412 imm_expr.X_op = O_constant;
8413 if (! target_big_endian)
8414 imm_expr.X_add_number = bfd_getl64 (temp);
8416 imm_expr.X_add_number = bfd_getb64 (temp);
8420 imm_expr.X_op = O_big;
8421 imm_expr.X_add_number = 4;
8422 if (! target_big_endian)
8424 generic_bignum[0] = bfd_getl16 (temp);
8425 generic_bignum[1] = bfd_getl16 (temp + 2);
8426 generic_bignum[2] = bfd_getl16 (temp + 4);
8427 generic_bignum[3] = bfd_getl16 (temp + 6);
8431 generic_bignum[0] = bfd_getb16 (temp + 6);
8432 generic_bignum[1] = bfd_getb16 (temp + 4);
8433 generic_bignum[2] = bfd_getb16 (temp + 2);
8434 generic_bignum[3] = bfd_getb16 (temp);
8440 const char *newname;
8443 /* Switch to the right section. */
8445 subseg = now_subseg;
8448 default: /* unused default case avoids warnings. */
8450 newname = RDATA_SECTION_NAME;
8451 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
8452 || mips_pic == EMBEDDED_PIC)
8456 if (mips_pic == EMBEDDED_PIC)
8459 newname = RDATA_SECTION_NAME;
8462 assert (!USE_GLOBAL_POINTER_OPT
8463 || g_switch_value >= 4);
8467 new_seg = subseg_new (newname, (subsegT) 0);
8468 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
8469 bfd_set_section_flags (stdoutput, new_seg,
8474 frag_align (*args == 'l' ? 2 : 3, 0, 0);
8475 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
8476 && strcmp (TARGET_OS, "elf") != 0)
8477 record_alignment (new_seg, 4);
8479 record_alignment (new_seg, *args == 'l' ? 2 : 3);
8481 as_bad (_("Can't use floating point insn in this section"));
8483 /* Set the argument to the current address in the
8485 offset_expr.X_op = O_symbol;
8486 offset_expr.X_add_symbol =
8487 symbol_new ("L0\001", now_seg,
8488 (valueT) frag_now_fix (), frag_now);
8489 offset_expr.X_add_number = 0;
8491 /* Put the floating point number into the section. */
8492 p = frag_more ((int) length);
8493 memcpy (p, temp, length);
8495 /* Switch back to the original section. */
8496 subseg_set (seg, subseg);
8501 case 'i': /* 16 bit unsigned immediate */
8502 case 'j': /* 16 bit signed immediate */
8503 *imm_reloc = BFD_RELOC_LO16;
8504 c = my_getSmallExpression (&imm_expr, s);
8509 if (imm_expr.X_op == O_constant)
8510 imm_expr.X_add_number =
8511 (imm_expr.X_add_number >> 16) & 0xffff;
8513 else if (c == S_EX_HIGHEST)
8514 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8515 else if (c == S_EX_HIGHER)
8516 *imm_reloc = BFD_RELOC_MIPS_HIGHER;
8517 else if (c == S_EX_GP_REL)
8519 /* This occurs in NewABI only. */
8520 c = my_getSmallExpression (&imm_expr, s);
8522 as_bad (_("bad composition of relocations"));
8525 c = my_getSmallExpression (&imm_expr, s);
8527 as_bad (_("bad composition of relocations"));
8530 imm_reloc[0] = BFD_RELOC_GPREL16;
8531 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8532 imm_reloc[2] = BFD_RELOC_LO16;
8537 else if (c == S_EX_HI)
8539 *imm_reloc = BFD_RELOC_HI16_S;
8540 imm_unmatched_hi = true;
8543 *imm_reloc = BFD_RELOC_HI16;
8545 else if (imm_expr.X_op == O_constant)
8546 imm_expr.X_add_number &= 0xffff;
8550 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8551 || ((imm_expr.X_add_number < 0
8552 || imm_expr.X_add_number >= 0x10000)
8553 && imm_expr.X_op == O_constant))
8555 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8556 !strcmp (insn->name, insn[1].name))
8558 if (imm_expr.X_op == O_constant
8559 || imm_expr.X_op == O_big)
8560 as_bad (_("16 bit expression not in range 0..65535"));
8568 /* The upper bound should be 0x8000, but
8569 unfortunately the MIPS assembler accepts numbers
8570 from 0x8000 to 0xffff and sign extends them, and
8571 we want to be compatible. We only permit this
8572 extended range for an instruction which does not
8573 provide any further alternates, since those
8574 alternates may handle other cases. People should
8575 use the numbers they mean, rather than relying on
8576 a mysterious sign extension. */
8577 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8578 strcmp (insn->name, insn[1].name) == 0);
8583 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8584 || ((imm_expr.X_add_number < -0x8000
8585 || imm_expr.X_add_number >= max)
8586 && imm_expr.X_op == O_constant)
8588 && imm_expr.X_add_number < 0
8590 && imm_expr.X_unsigned
8591 && sizeof (imm_expr.X_add_number) <= 4))
8595 if (imm_expr.X_op == O_constant
8596 || imm_expr.X_op == O_big)
8597 as_bad (_("16 bit expression not in range -32768..32767"));
8603 case 'o': /* 16 bit offset */
8604 c = my_getSmallExpression (&offset_expr, s);
8606 /* If this value won't fit into a 16 bit offset, then go
8607 find a macro that will generate the 32 bit offset
8610 && (offset_expr.X_op != O_constant
8611 || offset_expr.X_add_number >= 0x8000
8612 || offset_expr.X_add_number < -0x8000))
8617 if (offset_expr.X_op != O_constant)
8619 offset_expr.X_add_number =
8620 (offset_expr.X_add_number >> 16) & 0xffff;
8622 *offset_reloc = BFD_RELOC_LO16;
8626 case 'p': /* pc relative offset */
8627 if (mips_pic == EMBEDDED_PIC)
8628 *offset_reloc = BFD_RELOC_16_PCREL_S2;
8630 *offset_reloc = BFD_RELOC_16_PCREL;
8631 my_getExpression (&offset_expr, s);
8635 case 'u': /* upper 16 bits */
8636 c = my_getSmallExpression (&imm_expr, s);
8637 *imm_reloc = BFD_RELOC_LO16;
8642 if (imm_expr.X_op == O_constant)
8643 imm_expr.X_add_number =
8644 (imm_expr.X_add_number >> 16) & 0xffff;
8645 else if (c == S_EX_HI)
8647 *imm_reloc = BFD_RELOC_HI16_S;
8648 imm_unmatched_hi = true;
8651 else if (c == S_EX_HIGHEST)
8652 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8653 else if (c == S_EX_GP_REL)
8655 /* This occurs in NewABI only. */
8656 c = my_getSmallExpression (&imm_expr, s);
8658 as_bad (_("bad composition of relocations"));
8661 c = my_getSmallExpression (&imm_expr, s);
8663 as_bad (_("bad composition of relocations"));
8666 imm_reloc[0] = BFD_RELOC_GPREL16;
8667 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8668 imm_reloc[2] = BFD_RELOC_HI16_S;
8674 *imm_reloc = BFD_RELOC_HI16;
8676 else if (imm_expr.X_op == O_constant)
8677 imm_expr.X_add_number &= 0xffff;
8679 if (imm_expr.X_op == O_constant
8680 && (imm_expr.X_add_number < 0
8681 || imm_expr.X_add_number >= 0x10000))
8682 as_bad (_("lui expression not in range 0..65535"));
8686 case 'a': /* 26 bit address */
8687 my_getExpression (&offset_expr, s);
8689 *offset_reloc = BFD_RELOC_MIPS_JMP;
8692 case 'N': /* 3 bit branch condition code */
8693 case 'M': /* 3 bit compare condition code */
8694 if (strncmp (s, "$fcc", 4) != 0)
8704 while (ISDIGIT (*s));
8706 as_bad (_("invalid condition code register $fcc%d"), regno);
8708 ip->insn_opcode |= regno << OP_SH_BCC;
8710 ip->insn_opcode |= regno << OP_SH_CCC;
8714 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
8725 while (ISDIGIT (*s));
8728 c = 8; /* Invalid sel value. */
8731 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
8732 ip->insn_opcode |= c;
8736 as_bad (_("bad char = '%c'\n"), *args);
8741 /* Args don't match. */
8742 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8743 !strcmp (insn->name, insn[1].name))
8747 insn_error = _("illegal operands");
8752 insn_error = _("illegal operands");
8757 /* This routine assembles an instruction into its binary format when
8758 assembling for the mips16. As a side effect, it sets one of the
8759 global variables imm_reloc or offset_reloc to the type of
8760 relocation to do if one of the operands is an address expression.
8761 It also sets mips16_small and mips16_ext if the user explicitly
8762 requested a small or extended instruction. */
8767 struct mips_cl_insn *ip;
8771 struct mips_opcode *insn;
8774 unsigned int lastregno = 0;
8779 mips16_small = false;
8782 for (s = str; ISLOWER (*s); ++s)
8794 if (s[1] == 't' && s[2] == ' ')
8797 mips16_small = true;
8801 else if (s[1] == 'e' && s[2] == ' ')
8810 insn_error = _("unknown opcode");
8814 if (mips_opts.noautoextend && ! mips16_ext)
8815 mips16_small = true;
8817 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
8819 insn_error = _("unrecognized opcode");
8826 assert (strcmp (insn->name, str) == 0);
8829 ip->insn_opcode = insn->match;
8830 ip->use_extend = false;
8831 imm_expr.X_op = O_absent;
8832 imm_reloc[0] = BFD_RELOC_UNUSED;
8833 imm_reloc[1] = BFD_RELOC_UNUSED;
8834 imm_reloc[2] = BFD_RELOC_UNUSED;
8835 offset_expr.X_op = O_absent;
8836 offset_reloc[0] = BFD_RELOC_UNUSED;
8837 offset_reloc[1] = BFD_RELOC_UNUSED;
8838 offset_reloc[2] = BFD_RELOC_UNUSED;
8839 for (args = insn->args; 1; ++args)
8846 /* In this switch statement we call break if we did not find
8847 a match, continue if we did find a match, or return if we
8856 /* Stuff the immediate value in now, if we can. */
8857 if (imm_expr.X_op == O_constant
8858 && *imm_reloc > BFD_RELOC_UNUSED
8859 && insn->pinfo != INSN_MACRO)
8861 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
8862 imm_expr.X_add_number, true, mips16_small,
8863 mips16_ext, &ip->insn_opcode,
8864 &ip->use_extend, &ip->extend);
8865 imm_expr.X_op = O_absent;
8866 *imm_reloc = BFD_RELOC_UNUSED;
8880 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8883 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8899 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8901 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8928 while (ISDIGIT (*s));
8931 as_bad (_("invalid register number (%d)"), regno);
8937 if (s[1] == 'r' && s[2] == 'a')
8942 else if (s[1] == 'f' && s[2] == 'p')
8947 else if (s[1] == 's' && s[2] == 'p')
8952 else if (s[1] == 'g' && s[2] == 'p')
8957 else if (s[1] == 'a' && s[2] == 't')
8962 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8967 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8972 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8985 if (c == 'v' || c == 'w')
8987 regno = mips16_to_32_reg_map[lastregno];
9001 regno = mips32_to_16_reg_map[regno];
9006 regno = ILLEGAL_REG;
9011 regno = ILLEGAL_REG;
9016 regno = ILLEGAL_REG;
9021 if (regno == AT && ! mips_opts.noat)
9022 as_warn (_("used $at without \".set noat\""));
9029 if (regno == ILLEGAL_REG)
9036 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
9040 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
9043 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
9046 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
9052 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
9055 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9056 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
9066 if (strncmp (s, "$pc", 3) == 0)
9090 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
9092 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9093 and generate the appropriate reloc. If the text
9094 inside %gprel is not a symbol name with an
9095 optional offset, then we generate a normal reloc
9096 and will probably fail later. */
9097 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
9098 if (imm_expr.X_op == O_symbol)
9101 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
9103 ip->use_extend = true;
9110 /* Just pick up a normal expression. */
9111 my_getExpression (&imm_expr, s);
9114 if (imm_expr.X_op == O_register)
9116 /* What we thought was an expression turned out to
9119 if (s[0] == '(' && args[1] == '(')
9121 /* It looks like the expression was omitted
9122 before a register indirection, which means
9123 that the expression is implicitly zero. We
9124 still set up imm_expr, so that we handle
9125 explicit extensions correctly. */
9126 imm_expr.X_op = O_constant;
9127 imm_expr.X_add_number = 0;
9128 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9135 /* We need to relax this instruction. */
9136 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9145 /* We use offset_reloc rather than imm_reloc for the PC
9146 relative operands. This lets macros with both
9147 immediate and address operands work correctly. */
9148 my_getExpression (&offset_expr, s);
9150 if (offset_expr.X_op == O_register)
9153 /* We need to relax this instruction. */
9154 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9158 case '6': /* break code */
9159 my_getExpression (&imm_expr, s);
9160 check_absolute_expr (ip, &imm_expr);
9161 if ((unsigned long) imm_expr.X_add_number > 63)
9163 as_warn (_("Invalid value for `%s' (%lu)"),
9165 (unsigned long) imm_expr.X_add_number);
9166 imm_expr.X_add_number &= 0x3f;
9168 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9169 imm_expr.X_op = O_absent;
9173 case 'a': /* 26 bit address */
9174 my_getExpression (&offset_expr, s);
9176 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9177 ip->insn_opcode <<= 16;
9180 case 'l': /* register list for entry macro */
9181 case 'L': /* register list for exit macro */
9191 int freg, reg1, reg2;
9193 while (*s == ' ' || *s == ',')
9197 as_bad (_("can't parse register list"));
9209 while (ISDIGIT (*s))
9231 as_bad (_("invalid register list"));
9236 while (ISDIGIT (*s))
9243 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9248 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9253 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9254 mask |= (reg2 - 3) << 3;
9255 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9256 mask |= (reg2 - 15) << 1;
9257 else if (reg1 == RA && reg2 == RA)
9261 as_bad (_("invalid register list"));
9265 /* The mask is filled in in the opcode table for the
9266 benefit of the disassembler. We remove it before
9267 applying the actual mask. */
9268 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9269 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9273 case 'e': /* extend code */
9274 my_getExpression (&imm_expr, s);
9275 check_absolute_expr (ip, &imm_expr);
9276 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9278 as_warn (_("Invalid value for `%s' (%lu)"),
9280 (unsigned long) imm_expr.X_add_number);
9281 imm_expr.X_add_number &= 0x7ff;
9283 ip->insn_opcode |= imm_expr.X_add_number;
9284 imm_expr.X_op = O_absent;
9294 /* Args don't match. */
9295 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9296 strcmp (insn->name, insn[1].name) == 0)
9303 insn_error = _("illegal operands");
9309 /* This structure holds information we know about a mips16 immediate
9312 struct mips16_immed_operand
9314 /* The type code used in the argument string in the opcode table. */
9316 /* The number of bits in the short form of the opcode. */
9318 /* The number of bits in the extended form of the opcode. */
9320 /* The amount by which the short form is shifted when it is used;
9321 for example, the sw instruction has a shift count of 2. */
9323 /* The amount by which the short form is shifted when it is stored
9324 into the instruction code. */
9326 /* Non-zero if the short form is unsigned. */
9328 /* Non-zero if the extended form is unsigned. */
9330 /* Non-zero if the value is PC relative. */
9334 /* The mips16 immediate operand types. */
9336 static const struct mips16_immed_operand mips16_immed_operands[] =
9338 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9339 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9340 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9341 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9342 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9343 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9344 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9345 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9346 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9347 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9348 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9349 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9350 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9351 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9352 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9353 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9354 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9355 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9356 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9357 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9358 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9361 #define MIPS16_NUM_IMMED \
9362 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9364 /* Handle a mips16 instruction with an immediate value. This or's the
9365 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9366 whether an extended value is needed; if one is needed, it sets
9367 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9368 If SMALL is true, an unextended opcode was explicitly requested.
9369 If EXT is true, an extended opcode was explicitly requested. If
9370 WARN is true, warn if EXT does not match reality. */
9373 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
9382 unsigned long *insn;
9383 boolean *use_extend;
9384 unsigned short *extend;
9386 register const struct mips16_immed_operand *op;
9387 int mintiny, maxtiny;
9390 op = mips16_immed_operands;
9391 while (op->type != type)
9394 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9399 if (type == '<' || type == '>' || type == '[' || type == ']')
9402 maxtiny = 1 << op->nbits;
9407 maxtiny = (1 << op->nbits) - 1;
9412 mintiny = - (1 << (op->nbits - 1));
9413 maxtiny = (1 << (op->nbits - 1)) - 1;
9416 /* Branch offsets have an implicit 0 in the lowest bit. */
9417 if (type == 'p' || type == 'q')
9420 if ((val & ((1 << op->shift) - 1)) != 0
9421 || val < (mintiny << op->shift)
9422 || val > (maxtiny << op->shift))
9427 if (warn && ext && ! needext)
9428 as_warn_where (file, line,
9429 _("extended operand requested but not required"));
9430 if (small && needext)
9431 as_bad_where (file, line, _("invalid unextended operand value"));
9433 if (small || (! ext && ! needext))
9437 *use_extend = false;
9438 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9439 insnval <<= op->op_shift;
9444 long minext, maxext;
9450 maxext = (1 << op->extbits) - 1;
9454 minext = - (1 << (op->extbits - 1));
9455 maxext = (1 << (op->extbits - 1)) - 1;
9457 if (val < minext || val > maxext)
9458 as_bad_where (file, line,
9459 _("operand value out of range for instruction"));
9462 if (op->extbits == 16)
9464 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
9467 else if (op->extbits == 15)
9469 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
9474 extval = ((val & 0x1f) << 6) | (val & 0x20);
9478 *extend = (unsigned short) extval;
9483 static struct percent_op_match
9486 const enum small_ex_type type;
9491 {"%call_hi", S_EX_CALL_HI},
9492 {"%call_lo", S_EX_CALL_LO},
9493 {"%call16", S_EX_CALL16},
9494 {"%got_disp", S_EX_GOT_DISP},
9495 {"%got_page", S_EX_GOT_PAGE},
9496 {"%got_ofst", S_EX_GOT_OFST},
9497 {"%got_hi", S_EX_GOT_HI},
9498 {"%got_lo", S_EX_GOT_LO},
9500 {"%gp_rel", S_EX_GP_REL},
9501 {"%half", S_EX_HALF},
9502 {"%highest", S_EX_HIGHEST},
9503 {"%higher", S_EX_HIGHER},
9509 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9510 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9511 can be nested, this is handled by blanking the innermost, parsing the
9512 rest by subsequent calls. */
9515 my_getSmallParser (str, len, nestlevel)
9521 *str += strspn (*str, " \t");
9522 /* Check for expression in parentheses. */
9525 char *b = *str + 1 + strspn (*str + 1, " \t");
9528 /* Check for base register. */
9532 && (e = b + strcspn (b, ") \t"))
9533 && e - b > 1 && e - b < 4)
9536 && ((b[1] == 'f' && b[2] == 'p')
9537 || (b[1] == 's' && b[2] == 'p')
9538 || (b[1] == 'g' && b[2] == 'p')
9539 || (b[1] == 'a' && b[2] == 't')
9541 && ISDIGIT (b[2]))))
9542 || (ISDIGIT (b[1])))
9544 *len = strcspn (*str, ")") + 1;
9545 return S_EX_REGISTER;
9549 /* Check for percent_op (in parentheses). */
9550 else if (b[0] == '%')
9553 return my_getPercentOp (str, len, nestlevel);
9556 /* Some other expression in the parentheses, which can contain
9557 parentheses itself. Attempt to find the matching one. */
9563 for (s = *str + 1; *s && pcnt; s++, (*len)++)
9572 /* Check for percent_op (outside of parentheses). */
9573 else if (*str[0] == '%')
9574 return my_getPercentOp (str, len, nestlevel);
9576 /* Any other expression. */
9581 my_getPercentOp (str, len, nestlevel)
9586 char *tmp = *str + 1;
9589 while (ISALPHA (*tmp) || *tmp == '_')
9591 *tmp = TOLOWER (*tmp);
9594 while (i < (sizeof (percent_op) / sizeof (struct percent_op_match)))
9596 if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str)))
9600 int type = percent_op[i].type;
9602 /* Only %hi and %lo are allowed for OldABI. */
9603 if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO)
9606 *len = strlen (percent_op[i].str);
9615 my_getSmallExpression (ep, str)
9619 static char *oldstr = NULL;
9625 /* Don't update oldstr if the last call had nested percent_op's. We need
9626 it to parse the outer ones later. */
9633 c = my_getSmallParser (&str, &len, &nestlevel);
9634 if (c != S_EX_NONE && c != S_EX_REGISTER)
9637 while (c != S_EX_NONE && c != S_EX_REGISTER);
9641 /* A percent_op was encountered. Don't try to get an expression if
9642 it is already blanked out. */
9643 if (*(str + strspn (str + 1, " )")) != ')')
9647 /* Let my_getExpression() stop at the closing parenthesis. */
9648 save = *(str + len);
9649 *(str + len) = '\0';
9650 my_getExpression (ep, str);
9651 *(str + len) = save;
9655 /* Blank out including the % sign and the proper matching
9658 char *s = strrchr (oldstr, '%');
9661 for (end = strchr (s, '(') + 1; *end && pcnt; end++)
9665 else if (*end == ')')
9669 memset (s, ' ', end - s);
9673 expr_end = str + len;
9677 else if (c == S_EX_NONE)
9679 my_getExpression (ep, str);
9681 else if (c == S_EX_REGISTER)
9683 ep->X_op = O_constant;
9685 ep->X_add_symbol = NULL;
9686 ep->X_op_symbol = NULL;
9687 ep->X_add_number = 0;
9691 as_fatal (_("internal error"));
9695 /* All percent_op's have been handled. */
9702 my_getExpression (ep, str)
9709 save_in = input_line_pointer;
9710 input_line_pointer = str;
9712 expr_end = input_line_pointer;
9713 input_line_pointer = save_in;
9715 /* If we are in mips16 mode, and this is an expression based on `.',
9716 then we bump the value of the symbol by 1 since that is how other
9717 text symbols are handled. We don't bother to handle complex
9718 expressions, just `.' plus or minus a constant. */
9719 if (mips_opts.mips16
9720 && ep->X_op == O_symbol
9721 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
9722 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
9723 && symbol_get_frag (ep->X_add_symbol) == frag_now
9724 && symbol_constant_p (ep->X_add_symbol)
9725 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
9726 S_SET_VALUE (ep->X_add_symbol, val + 1);
9729 /* Turn a string in input_line_pointer into a floating point constant
9730 of type TYPE, and store the appropriate bytes in *LITP. The number
9731 of LITTLENUMS emitted is stored in *SIZEP. An error message is
9732 returned, or NULL on OK. */
9735 md_atof (type, litP, sizeP)
9741 LITTLENUM_TYPE words[4];
9757 return _("bad call to md_atof");
9760 t = atof_ieee (input_line_pointer, type, words);
9762 input_line_pointer = t;
9766 if (! target_big_endian)
9768 for (i = prec - 1; i >= 0; i--)
9770 md_number_to_chars (litP, (valueT) words[i], 2);
9776 for (i = 0; i < prec; i++)
9778 md_number_to_chars (litP, (valueT) words[i], 2);
9787 md_number_to_chars (buf, val, n)
9792 if (target_big_endian)
9793 number_to_chars_bigendian (buf, val, n);
9795 number_to_chars_littleendian (buf, val, n);
9799 static int support_64bit_objects(void)
9801 const char **list, **l;
9803 list = bfd_target_list ();
9804 for (l = list; *l != NULL; l++)
9806 /* This is traditional mips */
9807 if (strcmp (*l, "elf64-tradbigmips") == 0
9808 || strcmp (*l, "elf64-tradlittlemips") == 0)
9810 if (strcmp (*l, "elf64-bigmips") == 0
9811 || strcmp (*l, "elf64-littlemips") == 0)
9815 return (*l != NULL);
9817 #endif /* OBJ_ELF */
9819 const char *md_shortopts = "nO::g::G:";
9821 struct option md_longopts[] =
9823 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
9824 {"mips0", no_argument, NULL, OPTION_MIPS1},
9825 {"mips1", no_argument, NULL, OPTION_MIPS1},
9826 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
9827 {"mips2", no_argument, NULL, OPTION_MIPS2},
9828 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
9829 {"mips3", no_argument, NULL, OPTION_MIPS3},
9830 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
9831 {"mips4", no_argument, NULL, OPTION_MIPS4},
9832 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
9833 {"mips5", no_argument, NULL, OPTION_MIPS5},
9834 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
9835 {"mips32", no_argument, NULL, OPTION_MIPS32},
9836 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
9837 {"mips64", no_argument, NULL, OPTION_MIPS64},
9838 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
9839 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
9840 #define OPTION_TRAP (OPTION_MD_BASE + 9)
9841 {"trap", no_argument, NULL, OPTION_TRAP},
9842 {"no-break", no_argument, NULL, OPTION_TRAP},
9843 #define OPTION_BREAK (OPTION_MD_BASE + 10)
9844 {"break", no_argument, NULL, OPTION_BREAK},
9845 {"no-trap", no_argument, NULL, OPTION_BREAK},
9846 #define OPTION_EB (OPTION_MD_BASE + 11)
9847 {"EB", no_argument, NULL, OPTION_EB},
9848 #define OPTION_EL (OPTION_MD_BASE + 12)
9849 {"EL", no_argument, NULL, OPTION_EL},
9850 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
9851 {"mips16", no_argument, NULL, OPTION_MIPS16},
9852 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
9853 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
9854 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
9855 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
9856 #define OPTION_MNO_7000_HILO_FIX (OPTION_MD_BASE + 16)
9857 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
9858 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
9859 #define OPTION_FP32 (OPTION_MD_BASE + 17)
9860 {"mfp32", no_argument, NULL, OPTION_FP32},
9861 #define OPTION_GP32 (OPTION_MD_BASE + 18)
9862 {"mgp32", no_argument, NULL, OPTION_GP32},
9863 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
9864 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
9865 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
9866 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
9867 #define OPTION_MARCH (OPTION_MD_BASE + 21)
9868 {"march", required_argument, NULL, OPTION_MARCH},
9869 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
9870 {"mtune", required_argument, NULL, OPTION_MTUNE},
9871 #define OPTION_FP64 (OPTION_MD_BASE + 23)
9872 {"mfp64", no_argument, NULL, OPTION_FP64},
9873 #define OPTION_M4650 (OPTION_MD_BASE + 24)
9874 {"m4650", no_argument, NULL, OPTION_M4650},
9875 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
9876 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
9877 #define OPTION_M4010 (OPTION_MD_BASE + 26)
9878 {"m4010", no_argument, NULL, OPTION_M4010},
9879 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
9880 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
9881 #define OPTION_M4100 (OPTION_MD_BASE + 28)
9882 {"m4100", no_argument, NULL, OPTION_M4100},
9883 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
9884 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
9885 #define OPTION_M3900 (OPTION_MD_BASE + 30)
9886 {"m3900", no_argument, NULL, OPTION_M3900},
9887 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
9888 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
9889 #define OPTION_GP64 (OPTION_MD_BASE + 32)
9890 {"mgp64", no_argument, NULL, OPTION_GP64},
9891 #define OPTION_MIPS3D (OPTION_MD_BASE + 33)
9892 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
9893 #define OPTION_NO_MIPS3D (OPTION_MD_BASE + 34)
9894 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
9895 #define OPTION_MDMX (OPTION_MD_BASE + 35)
9896 {"mdmx", no_argument, NULL, OPTION_MDMX},
9897 #define OPTION_NO_MDMX (OPTION_MD_BASE + 36)
9898 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
9900 #define OPTION_ELF_BASE (OPTION_MD_BASE + 37)
9901 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
9902 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
9903 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
9904 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
9905 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
9906 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
9907 {"xgot", no_argument, NULL, OPTION_XGOT},
9908 #define OPTION_MABI (OPTION_ELF_BASE + 3)
9909 {"mabi", required_argument, NULL, OPTION_MABI},
9910 #define OPTION_32 (OPTION_ELF_BASE + 4)
9911 {"32", no_argument, NULL, OPTION_32},
9912 #define OPTION_N32 (OPTION_ELF_BASE + 5)
9913 {"n32", no_argument, NULL, OPTION_N32},
9914 #define OPTION_64 (OPTION_ELF_BASE + 6)
9915 {"64", no_argument, NULL, OPTION_64},
9916 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
9917 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
9918 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
9919 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
9920 #endif /* OBJ_ELF */
9921 {NULL, no_argument, NULL, 0}
9923 size_t md_longopts_size = sizeof (md_longopts);
9925 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
9926 NEW_VALUE. Warn if another value was already specified. Note:
9927 we have to defer parsing the -march and -mtune arguments in order
9928 to handle 'from-abi' correctly, since the ABI might be specified
9929 in a later argument. */
9932 mips_set_option_string (string_ptr, new_value)
9933 const char **string_ptr, *new_value;
9935 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
9936 as_warn (_("A different %s was already specified, is now %s"),
9937 string_ptr == &mips_arch_string ? "-march" : "-mtune",
9940 *string_ptr = new_value;
9944 md_parse_option (c, arg)
9950 case OPTION_CONSTRUCT_FLOATS:
9951 mips_disable_float_construction = 0;
9954 case OPTION_NO_CONSTRUCT_FLOATS:
9955 mips_disable_float_construction = 1;
9967 target_big_endian = 1;
9971 target_big_endian = 0;
9979 if (arg && arg[1] == '0')
9989 mips_debug = atoi (arg);
9990 /* When the MIPS assembler sees -g or -g2, it does not do
9991 optimizations which limit full symbolic debugging. We take
9992 that to be equivalent to -O0. */
9993 if (mips_debug == 2)
9998 file_mips_isa = ISA_MIPS1;
10002 file_mips_isa = ISA_MIPS2;
10006 file_mips_isa = ISA_MIPS3;
10010 file_mips_isa = ISA_MIPS4;
10014 file_mips_isa = ISA_MIPS5;
10017 case OPTION_MIPS32:
10018 file_mips_isa = ISA_MIPS32;
10021 case OPTION_MIPS64:
10022 file_mips_isa = ISA_MIPS64;
10026 mips_set_option_string (&mips_tune_string, arg);
10030 mips_set_option_string (&mips_arch_string, arg);
10034 mips_set_option_string (&mips_arch_string, "4650");
10035 mips_set_option_string (&mips_tune_string, "4650");
10038 case OPTION_NO_M4650:
10042 mips_set_option_string (&mips_arch_string, "4010");
10043 mips_set_option_string (&mips_tune_string, "4010");
10046 case OPTION_NO_M4010:
10050 mips_set_option_string (&mips_arch_string, "4100");
10051 mips_set_option_string (&mips_tune_string, "4100");
10054 case OPTION_NO_M4100:
10058 mips_set_option_string (&mips_arch_string, "3900");
10059 mips_set_option_string (&mips_tune_string, "3900");
10062 case OPTION_NO_M3900:
10066 mips_opts.ase_mdmx = 1;
10069 case OPTION_NO_MDMX:
10070 mips_opts.ase_mdmx = 0;
10073 case OPTION_MIPS16:
10074 mips_opts.mips16 = 1;
10075 mips_no_prev_insn (false);
10078 case OPTION_NO_MIPS16:
10079 mips_opts.mips16 = 0;
10080 mips_no_prev_insn (false);
10083 case OPTION_MIPS3D:
10084 mips_opts.ase_mips3d = 1;
10087 case OPTION_NO_MIPS3D:
10088 mips_opts.ase_mips3d = 0;
10091 case OPTION_MEMBEDDED_PIC:
10092 mips_pic = EMBEDDED_PIC;
10093 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
10095 as_bad (_("-G may not be used with embedded PIC code"));
10098 g_switch_value = 0x7fffffff;
10102 /* When generating ELF code, we permit -KPIC and -call_shared to
10103 select SVR4_PIC, and -non_shared to select no PIC. This is
10104 intended to be compatible with Irix 5. */
10105 case OPTION_CALL_SHARED:
10106 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10108 as_bad (_("-call_shared is supported only for ELF format"));
10111 mips_pic = SVR4_PIC;
10112 if (g_switch_seen && g_switch_value != 0)
10114 as_bad (_("-G may not be used with SVR4 PIC code"));
10117 g_switch_value = 0;
10120 case OPTION_NON_SHARED:
10121 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10123 as_bad (_("-non_shared is supported only for ELF format"));
10129 /* The -xgot option tells the assembler to use 32 offsets when
10130 accessing the got in SVR4_PIC mode. It is for Irix
10135 #endif /* OBJ_ELF */
10138 if (! USE_GLOBAL_POINTER_OPT)
10140 as_bad (_("-G is not supported for this configuration"));
10143 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10145 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10149 g_switch_value = atoi (arg);
10154 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10157 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10159 as_bad (_("-32 is supported for ELF format only"));
10162 mips_abi = O32_ABI;
10166 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10168 as_bad (_("-n32 is supported for ELF format only"));
10171 mips_abi = N32_ABI;
10175 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10177 as_bad (_("-64 is supported for ELF format only"));
10180 mips_abi = N64_ABI;
10181 if (! support_64bit_objects())
10182 as_fatal (_("No compiled in support for 64 bit object file format"));
10184 #endif /* OBJ_ELF */
10187 file_mips_gp32 = 1;
10191 file_mips_gp32 = 0;
10195 file_mips_fp32 = 1;
10199 file_mips_fp32 = 0;
10204 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10206 as_bad (_("-mabi is supported for ELF format only"));
10209 if (strcmp (arg, "32") == 0)
10210 mips_abi = O32_ABI;
10211 else if (strcmp (arg, "o64") == 0)
10212 mips_abi = O64_ABI;
10213 else if (strcmp (arg, "n32") == 0)
10214 mips_abi = N32_ABI;
10215 else if (strcmp (arg, "64") == 0)
10217 mips_abi = N64_ABI;
10218 if (! support_64bit_objects())
10219 as_fatal (_("No compiled in support for 64 bit object file "
10222 else if (strcmp (arg, "eabi") == 0)
10223 mips_abi = EABI_ABI;
10226 as_fatal (_("invalid abi -mabi=%s"), arg);
10230 #endif /* OBJ_ELF */
10232 case OPTION_M7000_HILO_FIX:
10233 mips_7000_hilo_fix = true;
10236 case OPTION_MNO_7000_HILO_FIX:
10237 mips_7000_hilo_fix = false;
10241 case OPTION_MDEBUG:
10242 mips_flag_mdebug = true;
10245 case OPTION_NO_MDEBUG:
10246 mips_flag_mdebug = false;
10248 #endif /* OBJ_ELF */
10257 /* Set up globals to generate code for the ISA or processor
10258 described by INFO. */
10261 mips_set_architecture (info)
10262 const struct mips_cpu_info *info;
10266 mips_arch_info = info;
10267 mips_arch = info->cpu;
10268 mips_opts.isa = info->isa;
10273 /* Likewise for tuning. */
10276 mips_set_tune (info)
10277 const struct mips_cpu_info *info;
10281 mips_tune_info = info;
10282 mips_tune = info->cpu;
10288 mips_after_parse_args ()
10290 /* GP relative stuff not working for PE */
10291 if (strncmp (TARGET_OS, "pe", 2) == 0
10292 && g_switch_value != 0)
10295 as_bad (_("-G not supported in this configuration."));
10296 g_switch_value = 0;
10299 /* The following code determines the architecture, ABI and register
10300 size. Similar code was added to GCC 3.2 (see override_options()
10301 in config/mips/mips.c). The GAS and GCC code should be kept in
10302 sync as much as possible. */
10304 if (mips_arch_string != 0)
10305 mips_set_architecture (mips_parse_cpu ("-march", mips_arch_string));
10307 if (mips_tune_string != 0)
10308 mips_set_tune (mips_parse_cpu ("-mtune", mips_tune_string));
10310 if (file_mips_isa != ISA_UNKNOWN)
10312 /* Handle -mipsN. At this point, file_mips_isa contains the
10313 ISA level specified by -mipsN, while mips_opts.isa contains
10314 the -march selection (if any). */
10315 if (mips_arch_info != 0)
10317 /* -march takes precedence over -mipsN, since it is more descriptive.
10318 There's no harm in specifying both as long as the ISA levels
10320 if (file_mips_isa != mips_opts.isa)
10321 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
10322 mips_cpu_info_from_isa (file_mips_isa)->name,
10323 mips_cpu_info_from_isa (mips_opts.isa)->name);
10326 mips_set_architecture (mips_cpu_info_from_isa (file_mips_isa));
10329 if (mips_arch_info == 0)
10330 mips_set_architecture (mips_parse_cpu ("default CPU",
10331 MIPS_CPU_STRING_DEFAULT));
10333 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (mips_opts.isa))
10334 as_bad ("-march=%s is not compatible with the selected ABI",
10335 mips_arch_info->name);
10337 /* Optimize for mips_arch, unless -mtune selects a different processor. */
10338 if (mips_tune_info == 0)
10339 mips_set_tune (mips_arch_info);
10341 if (file_mips_gp32 >= 0)
10343 /* The user specified the size of the integer registers. Make sure
10344 it agrees with the ABI and ISA. */
10345 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
10346 as_bad (_("-mgp64 used with a 32-bit processor"));
10347 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
10348 as_bad (_("-mgp32 used with a 64-bit ABI"));
10349 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
10350 as_bad (_("-mgp64 used with a 32-bit ABI"));
10354 /* Infer the integer register size from the ABI and processor.
10355 Restrict ourselves to 32-bit registers if that's all the
10356 processor has, or if the ABI cannot handle 64-bit registers. */
10357 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
10358 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
10361 /* ??? GAS treats single-float processors as though they had 64-bit
10362 float registers (although it complains when double-precision
10363 instructions are used). As things stand, saying they have 32-bit
10364 registers would lead to spurious "register must be even" messages.
10365 So here we assume float registers are always the same size as
10366 integer ones, unless the user says otherwise. */
10367 if (file_mips_fp32 < 0)
10368 file_mips_fp32 = file_mips_gp32;
10370 /* End of GCC-shared inference code. */
10372 /* ??? When do we want this flag to be set? Who uses it? */
10373 if (file_mips_gp32 == 1
10374 && mips_abi == NO_ABI
10375 && ISA_HAS_64BIT_REGS (mips_opts.isa))
10376 mips_32bitmode = 1;
10378 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
10379 as_bad (_("trap exception not supported at ISA 1"));
10381 /* If the selected architecture includes support for ASEs, enable
10382 generation of code for them. */
10383 if (mips_opts.mips16 == -1)
10384 mips_opts.mips16 = (CPU_HAS_MIPS16 (mips_arch)) ? 1 : 0;
10385 if (mips_opts.ase_mips3d == -1)
10386 mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (mips_arch)) ? 1 : 0;
10387 if (mips_opts.ase_mdmx == -1)
10388 mips_opts.ase_mdmx = (CPU_HAS_MDMX (mips_arch)) ? 1 : 0;
10390 file_mips_isa = mips_opts.isa;
10391 file_ase_mips16 = mips_opts.mips16;
10392 file_ase_mips3d = mips_opts.ase_mips3d;
10393 file_ase_mdmx = mips_opts.ase_mdmx;
10394 mips_opts.gp32 = file_mips_gp32;
10395 mips_opts.fp32 = file_mips_fp32;
10400 if (mips_flag_mdebug < 0)
10402 #ifdef OBJ_MAYBE_ECOFF
10403 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
10404 mips_flag_mdebug = 1;
10406 #endif /* OBJ_MAYBE_ECOFF */
10407 mips_flag_mdebug = 0;
10412 mips_init_after_args ()
10414 /* initialize opcodes */
10415 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10416 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10420 md_pcrel_from (fixP)
10423 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
10424 && fixP->fx_addsy != (symbolS *) NULL
10425 && ! S_IS_DEFINED (fixP->fx_addsy))
10427 /* This makes a branch to an undefined symbol be a branch to the
10428 current location. */
10429 if (mips_pic == EMBEDDED_PIC)
10435 /* Return the address of the delay slot. */
10436 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
10439 /* This is called before the symbol table is processed. In order to
10440 work with gcc when using mips-tfile, we must keep all local labels.
10441 However, in other cases, we want to discard them. If we were
10442 called with -g, but we didn't see any debugging information, it may
10443 mean that gcc is smuggling debugging information through to
10444 mips-tfile, in which case we must generate all local labels. */
10447 mips_frob_file_before_adjust ()
10449 #ifndef NO_ECOFF_DEBUGGING
10450 if (ECOFF_DEBUGGING
10452 && ! ecoff_debugging_seen)
10453 flag_keep_locals = 1;
10457 /* Sort any unmatched HI16_S relocs so that they immediately precede
10458 the corresponding LO reloc. This is called before md_apply_fix3 and
10459 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10460 explicit use of the %hi modifier. */
10465 struct mips_hi_fixup *l;
10467 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
10469 segment_info_type *seginfo;
10472 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
10474 /* Check quickly whether the next fixup happens to be a matching
10476 if (l->fixp->fx_next != NULL
10477 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
10478 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
10479 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
10482 /* Look through the fixups for this segment for a matching %lo.
10483 When we find one, move the %hi just in front of it. We do
10484 this in two passes. In the first pass, we try to find a
10485 unique %lo. In the second pass, we permit multiple %hi
10486 relocs for a single %lo (this is a GNU extension). */
10487 seginfo = seg_info (l->seg);
10488 for (pass = 0; pass < 2; pass++)
10493 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
10495 /* Check whether this is a %lo fixup which matches l->fixp. */
10496 if (f->fx_r_type == BFD_RELOC_LO16
10497 && f->fx_addsy == l->fixp->fx_addsy
10498 && f->fx_offset == l->fixp->fx_offset
10501 || prev->fx_r_type != BFD_RELOC_HI16_S
10502 || prev->fx_addsy != f->fx_addsy
10503 || prev->fx_offset != f->fx_offset))
10507 /* Move l->fixp before f. */
10508 for (pf = &seginfo->fix_root;
10510 pf = &(*pf)->fx_next)
10511 assert (*pf != NULL);
10513 *pf = l->fixp->fx_next;
10515 l->fixp->fx_next = f;
10517 seginfo->fix_root = l->fixp;
10519 prev->fx_next = l->fixp;
10530 #if 0 /* GCC code motion plus incomplete dead code elimination
10531 can leave a %hi without a %lo. */
10533 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
10534 _("Unmatched %%hi reloc"));
10540 /* When generating embedded PIC code we need to use a special
10541 relocation to represent the difference of two symbols in the .text
10542 section (switch tables use a difference of this sort). See
10543 include/coff/mips.h for details. This macro checks whether this
10544 fixup requires the special reloc. */
10545 #define SWITCH_TABLE(fixp) \
10546 ((fixp)->fx_r_type == BFD_RELOC_32 \
10547 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10548 && (fixp)->fx_addsy != NULL \
10549 && (fixp)->fx_subsy != NULL \
10550 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10551 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10553 /* When generating embedded PIC code we must keep all PC relative
10554 relocations, in case the linker has to relax a call. We also need
10555 to keep relocations for switch table entries.
10557 We may have combined relocations without symbols in the N32/N64 ABI.
10558 We have to prevent gas from dropping them. */
10561 mips_force_relocation (fixp)
10564 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10565 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
10569 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
10570 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
10571 || fixp->fx_r_type == BFD_RELOC_HI16_S
10572 || fixp->fx_r_type == BFD_RELOC_LO16))
10575 return (mips_pic == EMBEDDED_PIC
10577 || SWITCH_TABLE (fixp)
10578 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
10579 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
10584 mips_need_elf_addend_fixup (fixP)
10587 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
10589 if (mips_pic == EMBEDDED_PIC
10590 && S_IS_WEAK (fixP->fx_addsy))
10592 if (mips_pic != EMBEDDED_PIC
10593 && (S_IS_WEAK (fixP->fx_addsy)
10594 || S_IS_EXTERNAL (fixP->fx_addsy))
10595 && !S_IS_COMMON (fixP->fx_addsy))
10597 if (symbol_used_in_reloc_p (fixP->fx_addsy)
10598 && (((bfd_get_section_flags (stdoutput,
10599 S_GET_SEGMENT (fixP->fx_addsy))
10600 & SEC_LINK_ONCE) != 0)
10601 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
10603 sizeof (".gnu.linkonce") - 1)))
10609 /* Apply a fixup to the object file. */
10612 md_apply_fix3 (fixP, valP, seg)
10615 segT seg ATTRIBUTE_UNUSED;
10621 assert (fixP->fx_size == 4
10622 || fixP->fx_r_type == BFD_RELOC_16
10623 || fixP->fx_r_type == BFD_RELOC_32
10624 || fixP->fx_r_type == BFD_RELOC_MIPS_JMP
10625 || fixP->fx_r_type == BFD_RELOC_HI16_S
10626 || fixP->fx_r_type == BFD_RELOC_LO16
10627 || fixP->fx_r_type == BFD_RELOC_GPREL16
10628 || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL
10629 || fixP->fx_r_type == BFD_RELOC_GPREL32
10630 || fixP->fx_r_type == BFD_RELOC_64
10631 || fixP->fx_r_type == BFD_RELOC_CTOR
10632 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
10633 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST
10634 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER
10635 || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP
10636 || fixP->fx_r_type == BFD_RELOC_MIPS_REL16
10637 || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT
10638 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10639 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
10640 || fixP->fx_r_type == BFD_RELOC_MIPS_JALR);
10644 /* If we aren't adjusting this fixup to be against the section
10645 symbol, we need to adjust the value. */
10647 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
10649 if (mips_need_elf_addend_fixup (fixP))
10651 reloc_howto_type *howto;
10652 valueT symval = S_GET_VALUE (fixP->fx_addsy);
10656 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
10657 if (value != 0 && howto->partial_inplace && ! fixP->fx_pcrel)
10659 /* In this case, the bfd_install_relocation routine will
10660 incorrectly add the symbol value back in. We just want
10661 the addend to appear in the object file. */
10664 /* Make sure the addend is still non-zero. If it became zero
10665 after the last operation, set it to a spurious value and
10666 subtract the same value from the object file's contents. */
10671 /* The in-place addends for LO16 relocations are signed;
10672 leave the matching HI16 in-place addends as zero. */
10673 if (fixP->fx_r_type != BFD_RELOC_HI16_S)
10675 bfd_vma contents, mask, field;
10677 contents = bfd_get_bits (fixP->fx_frag->fr_literal
10680 target_big_endian);
10682 /* MASK has bits set where the relocation should go.
10683 FIELD is -value, shifted into the appropriate place
10684 for this relocation. */
10685 mask = 1 << (howto->bitsize - 1);
10686 mask = (((mask - 1) << 1) | 1) << howto->bitpos;
10687 field = (-value >> howto->rightshift) << howto->bitpos;
10689 bfd_put_bits ((field & mask) | (contents & ~mask),
10690 fixP->fx_frag->fr_literal + fixP->fx_where,
10692 target_big_endian);
10698 /* This code was generated using trial and error and so is
10699 fragile and not trustworthy. If you change it, you should
10700 rerun the elf-rel, elf-rel2, and empic testcases and ensure
10701 they still pass. */
10702 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
10704 value += fixP->fx_frag->fr_address + fixP->fx_where;
10706 /* BFD's REL handling, for MIPS, is _very_ weird.
10707 This gives the right results, but it can't possibly
10708 be the way things are supposed to work. */
10709 if ((fixP->fx_r_type != BFD_RELOC_16_PCREL
10710 && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
10711 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
10712 value += fixP->fx_frag->fr_address + fixP->fx_where;
10717 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */
10719 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
10722 switch (fixP->fx_r_type)
10724 case BFD_RELOC_MIPS_JMP:
10725 case BFD_RELOC_MIPS_SHIFT5:
10726 case BFD_RELOC_MIPS_SHIFT6:
10727 case BFD_RELOC_MIPS_GOT_DISP:
10728 case BFD_RELOC_MIPS_GOT_PAGE:
10729 case BFD_RELOC_MIPS_GOT_OFST:
10730 case BFD_RELOC_MIPS_SUB:
10731 case BFD_RELOC_MIPS_INSERT_A:
10732 case BFD_RELOC_MIPS_INSERT_B:
10733 case BFD_RELOC_MIPS_DELETE:
10734 case BFD_RELOC_MIPS_HIGHEST:
10735 case BFD_RELOC_MIPS_HIGHER:
10736 case BFD_RELOC_MIPS_SCN_DISP:
10737 case BFD_RELOC_MIPS_REL16:
10738 case BFD_RELOC_MIPS_RELGOT:
10739 case BFD_RELOC_MIPS_JALR:
10740 case BFD_RELOC_HI16:
10741 case BFD_RELOC_HI16_S:
10742 case BFD_RELOC_GPREL16:
10743 case BFD_RELOC_MIPS_LITERAL:
10744 case BFD_RELOC_MIPS_CALL16:
10745 case BFD_RELOC_MIPS_GOT16:
10746 case BFD_RELOC_GPREL32:
10747 case BFD_RELOC_MIPS_GOT_HI16:
10748 case BFD_RELOC_MIPS_GOT_LO16:
10749 case BFD_RELOC_MIPS_CALL_HI16:
10750 case BFD_RELOC_MIPS_CALL_LO16:
10751 case BFD_RELOC_MIPS16_GPREL:
10752 if (fixP->fx_pcrel)
10753 as_bad_where (fixP->fx_file, fixP->fx_line,
10754 _("Invalid PC relative reloc"));
10755 /* Nothing needed to do. The value comes from the reloc entry */
10758 case BFD_RELOC_MIPS16_JMP:
10759 /* We currently always generate a reloc against a symbol, which
10760 means that we don't want an addend even if the symbol is
10762 fixP->fx_addnumber = 0;
10765 case BFD_RELOC_PCREL_HI16_S:
10766 /* The addend for this is tricky if it is internal, so we just
10767 do everything here rather than in bfd_install_relocation. */
10768 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10773 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10775 /* For an external symbol adjust by the address to make it
10776 pcrel_offset. We use the address of the RELLO reloc
10777 which follows this one. */
10778 value += (fixP->fx_next->fx_frag->fr_address
10779 + fixP->fx_next->fx_where);
10781 value = ((value + 0x8000) >> 16) & 0xffff;
10782 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10783 if (target_big_endian)
10785 md_number_to_chars ((char *) buf, value, 2);
10788 case BFD_RELOC_PCREL_LO16:
10789 /* The addend for this is tricky if it is internal, so we just
10790 do everything here rather than in bfd_install_relocation. */
10791 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10796 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10797 value += fixP->fx_frag->fr_address + fixP->fx_where;
10798 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10799 if (target_big_endian)
10801 md_number_to_chars ((char *) buf, value, 2);
10805 /* This is handled like BFD_RELOC_32, but we output a sign
10806 extended value if we are only 32 bits. */
10808 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10810 if (8 <= sizeof (valueT))
10811 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10818 w1 = w2 = fixP->fx_where;
10819 if (target_big_endian)
10823 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
10824 if ((value & 0x80000000) != 0)
10828 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
10833 case BFD_RELOC_RVA:
10835 /* If we are deleting this reloc entry, we must fill in the
10836 value now. This can happen if we have a .word which is not
10837 resolved when it appears but is later defined. We also need
10838 to fill in the value if this is an embedded PIC switch table
10841 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10842 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10847 /* If we are deleting this reloc entry, we must fill in the
10849 assert (fixP->fx_size == 2);
10851 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10855 case BFD_RELOC_LO16:
10856 /* When handling an embedded PIC switch statement, we can wind
10857 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
10860 if (value + 0x8000 > 0xffff)
10861 as_bad_where (fixP->fx_file, fixP->fx_line,
10862 _("relocation overflow"));
10863 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10864 if (target_big_endian)
10866 md_number_to_chars ((char *) buf, value, 2);
10870 case BFD_RELOC_16_PCREL_S2:
10871 if ((value & 0x3) != 0)
10872 as_bad_where (fixP->fx_file, fixP->fx_line,
10873 _("Branch to odd address (%lx)"), (long) value);
10875 /* Fall through. */
10877 case BFD_RELOC_16_PCREL:
10879 * We need to save the bits in the instruction since fixup_segment()
10880 * might be deleting the relocation entry (i.e., a branch within
10881 * the current segment).
10883 if (!fixP->fx_done && value != 0)
10885 /* If 'value' is zero, the remaining reloc code won't actually
10886 do the store, so it must be done here. This is probably
10887 a bug somewhere. */
10889 && (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
10890 || fixP->fx_addsy == NULL /* ??? */
10891 || ! S_IS_DEFINED (fixP->fx_addsy)))
10892 value -= fixP->fx_frag->fr_address + fixP->fx_where;
10894 value = (offsetT) value >> 2;
10896 /* update old instruction data */
10897 buf = (bfd_byte *) (fixP->fx_where + fixP->fx_frag->fr_literal);
10898 if (target_big_endian)
10899 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
10901 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
10903 if (value + 0x8000 <= 0xffff)
10904 insn |= value & 0xffff;
10907 /* The branch offset is too large. If this is an
10908 unconditional branch, and we are not generating PIC code,
10909 we can convert it to an absolute jump instruction. */
10910 if (mips_pic == NO_PIC
10912 && fixP->fx_frag->fr_address >= text_section->vma
10913 && (fixP->fx_frag->fr_address
10914 < text_section->vma + text_section->_raw_size)
10915 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
10916 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
10917 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
10919 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
10920 insn = 0x0c000000; /* jal */
10922 insn = 0x08000000; /* j */
10923 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
10925 fixP->fx_addsy = section_symbol (text_section);
10926 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
10930 /* FIXME. It would be possible in principle to handle
10931 conditional branches which overflow. They could be
10932 transformed into a branch around a jump. This would
10933 require setting up variant frags for each different
10934 branch type. The native MIPS assembler attempts to
10935 handle these cases, but it appears to do it
10937 as_bad_where (fixP->fx_file, fixP->fx_line,
10938 _("Branch out of range"));
10942 md_number_to_chars ((char *) buf, (valueT) insn, 4);
10945 case BFD_RELOC_VTABLE_INHERIT:
10948 && !S_IS_DEFINED (fixP->fx_addsy)
10949 && !S_IS_WEAK (fixP->fx_addsy))
10950 S_SET_WEAK (fixP->fx_addsy);
10953 case BFD_RELOC_VTABLE_ENTRY:
10967 const struct mips_opcode *p;
10968 int treg, sreg, dreg, shamt;
10973 for (i = 0; i < NUMOPCODES; ++i)
10975 p = &mips_opcodes[i];
10976 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
10978 printf ("%08lx %s\t", oc, p->name);
10979 treg = (oc >> 16) & 0x1f;
10980 sreg = (oc >> 21) & 0x1f;
10981 dreg = (oc >> 11) & 0x1f;
10982 shamt = (oc >> 6) & 0x1f;
10984 for (args = p->args;; ++args)
10995 printf ("%c", *args);
10999 assert (treg == sreg);
11000 printf ("$%d,$%d", treg, sreg);
11005 printf ("$%d", dreg);
11010 printf ("$%d", treg);
11014 printf ("0x%x", treg);
11019 printf ("$%d", sreg);
11023 printf ("0x%08lx", oc & 0x1ffffff);
11030 printf ("%d", imm);
11035 printf ("$%d", shamt);
11046 printf (_("%08lx UNDEFINED\n"), oc);
11057 name = input_line_pointer;
11058 c = get_symbol_end ();
11059 p = (symbolS *) symbol_find_or_make (name);
11060 *input_line_pointer = c;
11064 /* Align the current frag to a given power of two. The MIPS assembler
11065 also automatically adjusts any preceding label. */
11068 mips_align (to, fill, label)
11073 mips_emit_delays (false);
11074 frag_align (to, fill, 0);
11075 record_alignment (now_seg, to);
11078 assert (S_GET_SEGMENT (label) == now_seg);
11079 symbol_set_frag (label, frag_now);
11080 S_SET_VALUE (label, (valueT) frag_now_fix ());
11084 /* Align to a given power of two. .align 0 turns off the automatic
11085 alignment used by the data creating pseudo-ops. */
11089 int x ATTRIBUTE_UNUSED;
11092 register long temp_fill;
11093 long max_alignment = 15;
11097 o Note that the assembler pulls down any immediately preceeding label
11098 to the aligned address.
11099 o It's not documented but auto alignment is reinstated by
11100 a .align pseudo instruction.
11101 o Note also that after auto alignment is turned off the mips assembler
11102 issues an error on attempt to assemble an improperly aligned data item.
11107 temp = get_absolute_expression ();
11108 if (temp > max_alignment)
11109 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11112 as_warn (_("Alignment negative: 0 assumed."));
11115 if (*input_line_pointer == ',')
11117 ++input_line_pointer;
11118 temp_fill = get_absolute_expression ();
11125 mips_align (temp, (int) temp_fill,
11126 insn_labels != NULL ? insn_labels->label : NULL);
11133 demand_empty_rest_of_line ();
11137 mips_flush_pending_output ()
11139 mips_emit_delays (false);
11140 mips_clear_insn_labels ();
11149 /* When generating embedded PIC code, we only use the .text, .lit8,
11150 .sdata and .sbss sections. We change the .data and .rdata
11151 pseudo-ops to use .sdata. */
11152 if (mips_pic == EMBEDDED_PIC
11153 && (sec == 'd' || sec == 'r'))
11157 /* The ELF backend needs to know that we are changing sections, so
11158 that .previous works correctly. We could do something like check
11159 for an obj_section_change_hook macro, but that might be confusing
11160 as it would not be appropriate to use it in the section changing
11161 functions in read.c, since obj-elf.c intercepts those. FIXME:
11162 This should be cleaner, somehow. */
11163 obj_elf_section_change_hook ();
11166 mips_emit_delays (false);
11176 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11177 demand_empty_rest_of_line ();
11181 if (USE_GLOBAL_POINTER_OPT)
11183 seg = subseg_new (RDATA_SECTION_NAME,
11184 (subsegT) get_absolute_expression ());
11185 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11187 bfd_set_section_flags (stdoutput, seg,
11193 if (strcmp (TARGET_OS, "elf") != 0)
11194 record_alignment (seg, 4);
11196 demand_empty_rest_of_line ();
11200 as_bad (_("No read only data section in this object file format"));
11201 demand_empty_rest_of_line ();
11207 if (USE_GLOBAL_POINTER_OPT)
11209 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11210 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11212 bfd_set_section_flags (stdoutput, seg,
11213 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11215 if (strcmp (TARGET_OS, "elf") != 0)
11216 record_alignment (seg, 4);
11218 demand_empty_rest_of_line ();
11223 as_bad (_("Global pointers not supported; recompile -G 0"));
11224 demand_empty_rest_of_line ();
11233 mips_enable_auto_align ()
11244 label = insn_labels != NULL ? insn_labels->label : NULL;
11245 mips_emit_delays (false);
11246 if (log_size > 0 && auto_align)
11247 mips_align (log_size, 0, label);
11248 mips_clear_insn_labels ();
11249 cons (1 << log_size);
11253 s_float_cons (type)
11258 label = insn_labels != NULL ? insn_labels->label : NULL;
11260 mips_emit_delays (false);
11265 mips_align (3, 0, label);
11267 mips_align (2, 0, label);
11270 mips_clear_insn_labels ();
11275 /* Handle .globl. We need to override it because on Irix 5 you are
11278 where foo is an undefined symbol, to mean that foo should be
11279 considered to be the address of a function. */
11283 int x ATTRIBUTE_UNUSED;
11290 name = input_line_pointer;
11291 c = get_symbol_end ();
11292 symbolP = symbol_find_or_make (name);
11293 *input_line_pointer = c;
11294 SKIP_WHITESPACE ();
11296 /* On Irix 5, every global symbol that is not explicitly labelled as
11297 being a function is apparently labelled as being an object. */
11300 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11305 secname = input_line_pointer;
11306 c = get_symbol_end ();
11307 sec = bfd_get_section_by_name (stdoutput, secname);
11309 as_bad (_("%s: no such section"), secname);
11310 *input_line_pointer = c;
11312 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11313 flag = BSF_FUNCTION;
11316 symbol_get_bfdsym (symbolP)->flags |= flag;
11318 S_SET_EXTERNAL (symbolP);
11319 demand_empty_rest_of_line ();
11324 int x ATTRIBUTE_UNUSED;
11329 opt = input_line_pointer;
11330 c = get_symbol_end ();
11334 /* FIXME: What does this mean? */
11336 else if (strncmp (opt, "pic", 3) == 0)
11340 i = atoi (opt + 3);
11344 mips_pic = SVR4_PIC;
11346 as_bad (_(".option pic%d not supported"), i);
11348 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
11350 if (g_switch_seen && g_switch_value != 0)
11351 as_warn (_("-G may not be used with SVR4 PIC code"));
11352 g_switch_value = 0;
11353 bfd_set_gp_size (stdoutput, 0);
11357 as_warn (_("Unrecognized option \"%s\""), opt);
11359 *input_line_pointer = c;
11360 demand_empty_rest_of_line ();
11363 /* This structure is used to hold a stack of .set values. */
11365 struct mips_option_stack
11367 struct mips_option_stack *next;
11368 struct mips_set_options options;
11371 static struct mips_option_stack *mips_opts_stack;
11373 /* Handle the .set pseudo-op. */
11377 int x ATTRIBUTE_UNUSED;
11379 char *name = input_line_pointer, ch;
11381 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11382 ++input_line_pointer;
11383 ch = *input_line_pointer;
11384 *input_line_pointer = '\0';
11386 if (strcmp (name, "reorder") == 0)
11388 if (mips_opts.noreorder && prev_nop_frag != NULL)
11390 /* If we still have pending nops, we can discard them. The
11391 usual nop handling will insert any that are still
11393 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11394 * (mips_opts.mips16 ? 2 : 4));
11395 prev_nop_frag = NULL;
11397 mips_opts.noreorder = 0;
11399 else if (strcmp (name, "noreorder") == 0)
11401 mips_emit_delays (true);
11402 mips_opts.noreorder = 1;
11403 mips_any_noreorder = 1;
11405 else if (strcmp (name, "at") == 0)
11407 mips_opts.noat = 0;
11409 else if (strcmp (name, "noat") == 0)
11411 mips_opts.noat = 1;
11413 else if (strcmp (name, "macro") == 0)
11415 mips_opts.warn_about_macros = 0;
11417 else if (strcmp (name, "nomacro") == 0)
11419 if (mips_opts.noreorder == 0)
11420 as_bad (_("`noreorder' must be set before `nomacro'"));
11421 mips_opts.warn_about_macros = 1;
11423 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11425 mips_opts.nomove = 0;
11427 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11429 mips_opts.nomove = 1;
11431 else if (strcmp (name, "bopt") == 0)
11433 mips_opts.nobopt = 0;
11435 else if (strcmp (name, "nobopt") == 0)
11437 mips_opts.nobopt = 1;
11439 else if (strcmp (name, "mips16") == 0
11440 || strcmp (name, "MIPS-16") == 0)
11441 mips_opts.mips16 = 1;
11442 else if (strcmp (name, "nomips16") == 0
11443 || strcmp (name, "noMIPS-16") == 0)
11444 mips_opts.mips16 = 0;
11445 else if (strcmp (name, "mips3d") == 0)
11446 mips_opts.ase_mips3d = 1;
11447 else if (strcmp (name, "nomips3d") == 0)
11448 mips_opts.ase_mips3d = 0;
11449 else if (strcmp (name, "mdmx") == 0)
11450 mips_opts.ase_mdmx = 1;
11451 else if (strcmp (name, "nomdmx") == 0)
11452 mips_opts.ase_mdmx = 0;
11453 else if (strncmp (name, "mips", 4) == 0)
11457 /* Permit the user to change the ISA on the fly. Needless to
11458 say, misuse can cause serious problems. */
11459 isa = atoi (name + 4);
11463 mips_opts.gp32 = file_mips_gp32;
11464 mips_opts.fp32 = file_mips_fp32;
11469 mips_opts.gp32 = 1;
11470 mips_opts.fp32 = 1;
11476 mips_opts.gp32 = 0;
11477 mips_opts.fp32 = 0;
11480 as_bad (_("unknown ISA level %s"), name + 4);
11486 case 0: mips_opts.isa = file_mips_isa; break;
11487 case 1: mips_opts.isa = ISA_MIPS1; break;
11488 case 2: mips_opts.isa = ISA_MIPS2; break;
11489 case 3: mips_opts.isa = ISA_MIPS3; break;
11490 case 4: mips_opts.isa = ISA_MIPS4; break;
11491 case 5: mips_opts.isa = ISA_MIPS5; break;
11492 case 32: mips_opts.isa = ISA_MIPS32; break;
11493 case 64: mips_opts.isa = ISA_MIPS64; break;
11494 default: as_bad (_("unknown ISA level %s"), name + 4); break;
11497 else if (strcmp (name, "autoextend") == 0)
11498 mips_opts.noautoextend = 0;
11499 else if (strcmp (name, "noautoextend") == 0)
11500 mips_opts.noautoextend = 1;
11501 else if (strcmp (name, "push") == 0)
11503 struct mips_option_stack *s;
11505 s = (struct mips_option_stack *) xmalloc (sizeof *s);
11506 s->next = mips_opts_stack;
11507 s->options = mips_opts;
11508 mips_opts_stack = s;
11510 else if (strcmp (name, "pop") == 0)
11512 struct mips_option_stack *s;
11514 s = mips_opts_stack;
11516 as_bad (_(".set pop with no .set push"));
11519 /* If we're changing the reorder mode we need to handle
11520 delay slots correctly. */
11521 if (s->options.noreorder && ! mips_opts.noreorder)
11522 mips_emit_delays (true);
11523 else if (! s->options.noreorder && mips_opts.noreorder)
11525 if (prev_nop_frag != NULL)
11527 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11528 * (mips_opts.mips16 ? 2 : 4));
11529 prev_nop_frag = NULL;
11533 mips_opts = s->options;
11534 mips_opts_stack = s->next;
11540 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
11542 *input_line_pointer = ch;
11543 demand_empty_rest_of_line ();
11546 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11547 .option pic2. It means to generate SVR4 PIC calls. */
11550 s_abicalls (ignore)
11551 int ignore ATTRIBUTE_UNUSED;
11553 mips_pic = SVR4_PIC;
11554 if (USE_GLOBAL_POINTER_OPT)
11556 if (g_switch_seen && g_switch_value != 0)
11557 as_warn (_("-G may not be used with SVR4 PIC code"));
11558 g_switch_value = 0;
11560 bfd_set_gp_size (stdoutput, 0);
11561 demand_empty_rest_of_line ();
11564 /* Handle the .cpload pseudo-op. This is used when generating SVR4
11565 PIC code. It sets the $gp register for the function based on the
11566 function address, which is in the register named in the argument.
11567 This uses a relocation against _gp_disp, which is handled specially
11568 by the linker. The result is:
11569 lui $gp,%hi(_gp_disp)
11570 addiu $gp,$gp,%lo(_gp_disp)
11571 addu $gp,$gp,.cpload argument
11572 The .cpload argument is normally $25 == $t9. */
11576 int ignore ATTRIBUTE_UNUSED;
11581 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11582 .cpload is ignored. */
11583 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11589 /* .cpload should be in a .set noreorder section. */
11590 if (mips_opts.noreorder == 0)
11591 as_warn (_(".cpload not in noreorder section"));
11593 ex.X_op = O_symbol;
11594 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
11595 ex.X_op_symbol = NULL;
11596 ex.X_add_number = 0;
11598 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
11599 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
11601 macro_build_lui (NULL, &icnt, &ex, mips_gp_register);
11602 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j",
11603 mips_gp_register, mips_gp_register, (int) BFD_RELOC_LO16);
11605 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
11606 mips_gp_register, mips_gp_register, tc_get_register (0));
11608 demand_empty_rest_of_line ();
11611 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
11612 .cpsetup $reg1, offset|$reg2, label
11614 If offset is given, this results in:
11615 sd $gp, offset($sp)
11616 lui $gp, %hi(%neg(%gp_rel(label)))
11617 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11618 daddu $gp, $gp, $reg1
11620 If $reg2 is given, this results in:
11621 daddu $reg2, $gp, $0
11622 lui $gp, %hi(%neg(%gp_rel(label)))
11623 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11624 daddu $gp, $gp, $reg1
11625 $reg1 is normally $25 == $t9. */
11628 int ignore ATTRIBUTE_UNUSED;
11630 expressionS ex_off;
11631 expressionS ex_sym;
11636 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
11637 We also need NewABI support. */
11638 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11644 reg1 = tc_get_register (0);
11645 SKIP_WHITESPACE ();
11646 if (*input_line_pointer != ',')
11648 as_bad (_("missing argument separator ',' for .cpsetup"));
11652 ++input_line_pointer;
11653 SKIP_WHITESPACE ();
11654 if (*input_line_pointer == '$')
11656 mips_cpreturn_register = tc_get_register (0);
11657 mips_cpreturn_offset = -1;
11661 mips_cpreturn_offset = get_absolute_expression ();
11662 mips_cpreturn_register = -1;
11664 SKIP_WHITESPACE ();
11665 if (*input_line_pointer != ',')
11667 as_bad (_("missing argument separator ',' for .cpsetup"));
11671 ++input_line_pointer;
11672 SKIP_WHITESPACE ();
11673 sym = input_line_pointer;
11674 while (ISALNUM (*input_line_pointer))
11675 ++input_line_pointer;
11676 *input_line_pointer = 0;
11678 ex_sym.X_op = O_symbol;
11679 ex_sym.X_add_symbol = symbol_find_or_make (sym);
11680 ex_sym.X_op_symbol = NULL;
11681 ex_sym.X_add_number = 0;
11683 if (mips_cpreturn_register == -1)
11685 ex_off.X_op = O_constant;
11686 ex_off.X_add_symbol = NULL;
11687 ex_off.X_op_symbol = NULL;
11688 ex_off.X_add_number = mips_cpreturn_offset;
11690 macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)",
11691 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11694 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11695 "d,v,t", mips_cpreturn_register, mips_gp_register, 0);
11697 macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
11698 (int) BFD_RELOC_GPREL16);
11699 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11700 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_HI16_S);
11701 macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j",
11702 mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16);
11703 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11704 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_LO16);
11705 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11706 HAVE_64BIT_ADDRESSES ? "daddu" : "addu", "d,v,t",
11707 mips_gp_register, mips_gp_register, reg1);
11709 demand_empty_rest_of_line ();
11714 int ignore ATTRIBUTE_UNUSED;
11716 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
11717 .cplocal is ignored. */
11718 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11724 mips_gp_register = tc_get_register (0);
11725 demand_empty_rest_of_line ();
11728 /* Handle the .cprestore pseudo-op. This stores $gp into a given
11729 offset from $sp. The offset is remembered, and after making a PIC
11730 call $gp is restored from that location. */
11733 s_cprestore (ignore)
11734 int ignore ATTRIBUTE_UNUSED;
11739 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11740 .cprestore is ignored. */
11741 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11747 mips_cprestore_offset = get_absolute_expression ();
11748 mips_cprestore_valid = 1;
11750 ex.X_op = O_constant;
11751 ex.X_add_symbol = NULL;
11752 ex.X_op_symbol = NULL;
11753 ex.X_add_number = mips_cprestore_offset;
11755 macro_build ((char *) NULL, &icnt, &ex, HAVE_32BIT_ADDRESSES ? "sw" : "sd",
11756 "t,o(b)", mips_gp_register, (int) BFD_RELOC_LO16, SP);
11758 demand_empty_rest_of_line ();
11761 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
11762 was given in the preceeding .gpsetup, it results in:
11763 ld $gp, offset($sp)
11765 If a register $reg2 was given there, it results in:
11766 daddiu $gp, $gp, $reg2
11769 s_cpreturn (ignore)
11770 int ignore ATTRIBUTE_UNUSED;
11775 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
11776 We also need NewABI support. */
11777 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11783 if (mips_cpreturn_register == -1)
11785 ex.X_op = O_constant;
11786 ex.X_add_symbol = NULL;
11787 ex.X_op_symbol = NULL;
11788 ex.X_add_number = mips_cpreturn_offset;
11790 macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)",
11791 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11794 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11795 "d,v,t", mips_gp_register, mips_cpreturn_register, 0);
11797 demand_empty_rest_of_line ();
11800 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
11801 code. It sets the offset to use in gp_rel relocations. */
11805 int ignore ATTRIBUTE_UNUSED;
11807 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
11808 We also need NewABI support. */
11809 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11815 mips_gprel_offset = get_absolute_expression ();
11817 demand_empty_rest_of_line ();
11820 /* Handle the .gpword pseudo-op. This is used when generating PIC
11821 code. It generates a 32 bit GP relative reloc. */
11825 int ignore ATTRIBUTE_UNUSED;
11831 /* When not generating PIC code, this is treated as .word. */
11832 if (mips_pic != SVR4_PIC)
11838 label = insn_labels != NULL ? insn_labels->label : NULL;
11839 mips_emit_delays (true);
11841 mips_align (2, 0, label);
11842 mips_clear_insn_labels ();
11846 if (ex.X_op != O_symbol || ex.X_add_number != 0)
11848 as_bad (_("Unsupported use of .gpword"));
11849 ignore_rest_of_line ();
11853 md_number_to_chars (p, (valueT) 0, 4);
11854 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, false,
11855 BFD_RELOC_GPREL32);
11857 demand_empty_rest_of_line ();
11860 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
11861 tables in SVR4 PIC code. */
11865 int ignore ATTRIBUTE_UNUSED;
11870 /* This is ignored when not generating SVR4 PIC code or if this is NewABI
11872 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11878 /* Add $gp to the register named as an argument. */
11879 reg = tc_get_register (0);
11880 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11881 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
11882 "d,v,t", reg, reg, mips_gp_register);
11884 demand_empty_rest_of_line ();
11887 /* Handle the .insn pseudo-op. This marks instruction labels in
11888 mips16 mode. This permits the linker to handle them specially,
11889 such as generating jalx instructions when needed. We also make
11890 them odd for the duration of the assembly, in order to generate the
11891 right sort of code. We will make them even in the adjust_symtab
11892 routine, while leaving them marked. This is convenient for the
11893 debugger and the disassembler. The linker knows to make them odd
11898 int ignore ATTRIBUTE_UNUSED;
11900 mips16_mark_labels ();
11902 demand_empty_rest_of_line ();
11905 /* Handle a .stabn directive. We need these in order to mark a label
11906 as being a mips16 text label correctly. Sometimes the compiler
11907 will emit a label, followed by a .stabn, and then switch sections.
11908 If the label and .stabn are in mips16 mode, then the label is
11909 really a mips16 text label. */
11916 mips16_mark_labels ();
11921 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
11925 s_mips_weakext (ignore)
11926 int ignore ATTRIBUTE_UNUSED;
11933 name = input_line_pointer;
11934 c = get_symbol_end ();
11935 symbolP = symbol_find_or_make (name);
11936 S_SET_WEAK (symbolP);
11937 *input_line_pointer = c;
11939 SKIP_WHITESPACE ();
11941 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11943 if (S_IS_DEFINED (symbolP))
11945 as_bad ("ignoring attempt to redefine symbol %s",
11946 S_GET_NAME (symbolP));
11947 ignore_rest_of_line ();
11951 if (*input_line_pointer == ',')
11953 ++input_line_pointer;
11954 SKIP_WHITESPACE ();
11958 if (exp.X_op != O_symbol)
11960 as_bad ("bad .weakext directive");
11961 ignore_rest_of_line ();
11964 symbol_set_value_expression (symbolP, &exp);
11967 demand_empty_rest_of_line ();
11970 /* Parse a register string into a number. Called from the ECOFF code
11971 to parse .frame. The argument is non-zero if this is the frame
11972 register, so that we can record it in mips_frame_reg. */
11975 tc_get_register (frame)
11980 SKIP_WHITESPACE ();
11981 if (*input_line_pointer++ != '$')
11983 as_warn (_("expected `$'"));
11986 else if (ISDIGIT (*input_line_pointer))
11988 reg = get_absolute_expression ();
11989 if (reg < 0 || reg >= 32)
11991 as_warn (_("Bad register number"));
11997 if (strncmp (input_line_pointer, "ra", 2) == 0)
12000 input_line_pointer += 2;
12002 else if (strncmp (input_line_pointer, "fp", 2) == 0)
12005 input_line_pointer += 2;
12007 else if (strncmp (input_line_pointer, "sp", 2) == 0)
12010 input_line_pointer += 2;
12012 else if (strncmp (input_line_pointer, "gp", 2) == 0)
12015 input_line_pointer += 2;
12017 else if (strncmp (input_line_pointer, "at", 2) == 0)
12020 input_line_pointer += 2;
12022 else if (strncmp (input_line_pointer, "kt0", 3) == 0)
12025 input_line_pointer += 3;
12027 else if (strncmp (input_line_pointer, "kt1", 3) == 0)
12030 input_line_pointer += 3;
12032 else if (strncmp (input_line_pointer, "zero", 4) == 0)
12035 input_line_pointer += 4;
12039 as_warn (_("Unrecognized register name"));
12041 while (ISALNUM(*input_line_pointer))
12042 input_line_pointer++;
12047 mips_frame_reg = reg != 0 ? reg : SP;
12048 mips_frame_reg_valid = 1;
12049 mips_cprestore_valid = 0;
12055 md_section_align (seg, addr)
12059 int align = bfd_get_section_alignment (stdoutput, seg);
12062 /* We don't need to align ELF sections to the full alignment.
12063 However, Irix 5 may prefer that we align them at least to a 16
12064 byte boundary. We don't bother to align the sections if we are
12065 targeted for an embedded system. */
12066 if (strcmp (TARGET_OS, "elf") == 0)
12072 return ((addr + (1 << align) - 1) & (-1 << align));
12075 /* Utility routine, called from above as well. If called while the
12076 input file is still being read, it's only an approximation. (For
12077 example, a symbol may later become defined which appeared to be
12078 undefined earlier.) */
12081 nopic_need_relax (sym, before_relaxing)
12083 int before_relaxing;
12088 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
12090 const char *symname;
12093 /* Find out whether this symbol can be referenced off the $gp
12094 register. It can be if it is smaller than the -G size or if
12095 it is in the .sdata or .sbss section. Certain symbols can
12096 not be referenced off the $gp, although it appears as though
12098 symname = S_GET_NAME (sym);
12099 if (symname != (const char *) NULL
12100 && (strcmp (symname, "eprol") == 0
12101 || strcmp (symname, "etext") == 0
12102 || strcmp (symname, "_gp") == 0
12103 || strcmp (symname, "edata") == 0
12104 || strcmp (symname, "_fbss") == 0
12105 || strcmp (symname, "_fdata") == 0
12106 || strcmp (symname, "_ftext") == 0
12107 || strcmp (symname, "end") == 0
12108 || strcmp (symname, "_gp_disp") == 0))
12110 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12112 #ifndef NO_ECOFF_DEBUGGING
12113 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12114 && (symbol_get_obj (sym)->ecoff_extern_size
12115 <= g_switch_value))
12117 /* We must defer this decision until after the whole
12118 file has been read, since there might be a .extern
12119 after the first use of this symbol. */
12120 || (before_relaxing
12121 #ifndef NO_ECOFF_DEBUGGING
12122 && symbol_get_obj (sym)->ecoff_extern_size == 0
12124 && S_GET_VALUE (sym) == 0)
12125 || (S_GET_VALUE (sym) != 0
12126 && S_GET_VALUE (sym) <= g_switch_value)))
12130 const char *segname;
12132 segname = segment_name (S_GET_SEGMENT (sym));
12133 assert (strcmp (segname, ".lit8") != 0
12134 && strcmp (segname, ".lit4") != 0);
12135 change = (strcmp (segname, ".sdata") != 0
12136 && strcmp (segname, ".sbss") != 0
12137 && strncmp (segname, ".sdata.", 7) != 0
12138 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12143 /* We are not optimizing for the $gp register. */
12147 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12148 extended opcode. SEC is the section the frag is in. */
12151 mips16_extended_frag (fragp, sec, stretch)
12157 register const struct mips16_immed_operand *op;
12159 int mintiny, maxtiny;
12163 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
12165 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
12168 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12169 op = mips16_immed_operands;
12170 while (op->type != type)
12173 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12178 if (type == '<' || type == '>' || type == '[' || type == ']')
12181 maxtiny = 1 << op->nbits;
12186 maxtiny = (1 << op->nbits) - 1;
12191 mintiny = - (1 << (op->nbits - 1));
12192 maxtiny = (1 << (op->nbits - 1)) - 1;
12195 sym_frag = symbol_get_frag (fragp->fr_symbol);
12196 val = S_GET_VALUE (fragp->fr_symbol);
12197 symsec = S_GET_SEGMENT (fragp->fr_symbol);
12203 /* We won't have the section when we are called from
12204 mips_relax_frag. However, we will always have been called
12205 from md_estimate_size_before_relax first. If this is a
12206 branch to a different section, we mark it as such. If SEC is
12207 NULL, and the frag is not marked, then it must be a branch to
12208 the same section. */
12211 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
12216 /* Must have been called from md_estimate_size_before_relax. */
12219 fragp->fr_subtype =
12220 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12222 /* FIXME: We should support this, and let the linker
12223 catch branches and loads that are out of range. */
12224 as_bad_where (fragp->fr_file, fragp->fr_line,
12225 _("unsupported PC relative reference to different section"));
12229 if (fragp != sym_frag && sym_frag->fr_address == 0)
12230 /* Assume non-extended on the first relaxation pass.
12231 The address we have calculated will be bogus if this is
12232 a forward branch to another frag, as the forward frag
12233 will have fr_address == 0. */
12237 /* In this case, we know for sure that the symbol fragment is in
12238 the same section. If the relax_marker of the symbol fragment
12239 differs from the relax_marker of this fragment, we have not
12240 yet adjusted the symbol fragment fr_address. We want to add
12241 in STRETCH in order to get a better estimate of the address.
12242 This particularly matters because of the shift bits. */
12244 && sym_frag->relax_marker != fragp->relax_marker)
12248 /* Adjust stretch for any alignment frag. Note that if have
12249 been expanding the earlier code, the symbol may be
12250 defined in what appears to be an earlier frag. FIXME:
12251 This doesn't handle the fr_subtype field, which specifies
12252 a maximum number of bytes to skip when doing an
12254 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
12256 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
12259 stretch = - ((- stretch)
12260 & ~ ((1 << (int) f->fr_offset) - 1));
12262 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
12271 addr = fragp->fr_address + fragp->fr_fix;
12273 /* The base address rules are complicated. The base address of
12274 a branch is the following instruction. The base address of a
12275 PC relative load or add is the instruction itself, but if it
12276 is in a delay slot (in which case it can not be extended) use
12277 the address of the instruction whose delay slot it is in. */
12278 if (type == 'p' || type == 'q')
12282 /* If we are currently assuming that this frag should be
12283 extended, then, the current address is two bytes
12285 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12288 /* Ignore the low bit in the target, since it will be set
12289 for a text label. */
12290 if ((val & 1) != 0)
12293 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12295 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12298 val -= addr & ~ ((1 << op->shift) - 1);
12300 /* Branch offsets have an implicit 0 in the lowest bit. */
12301 if (type == 'p' || type == 'q')
12304 /* If any of the shifted bits are set, we must use an extended
12305 opcode. If the address depends on the size of this
12306 instruction, this can lead to a loop, so we arrange to always
12307 use an extended opcode. We only check this when we are in
12308 the main relaxation loop, when SEC is NULL. */
12309 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
12311 fragp->fr_subtype =
12312 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12316 /* If we are about to mark a frag as extended because the value
12317 is precisely maxtiny + 1, then there is a chance of an
12318 infinite loop as in the following code:
12323 In this case when the la is extended, foo is 0x3fc bytes
12324 away, so the la can be shrunk, but then foo is 0x400 away, so
12325 the la must be extended. To avoid this loop, we mark the
12326 frag as extended if it was small, and is about to become
12327 extended with a value of maxtiny + 1. */
12328 if (val == ((maxtiny + 1) << op->shift)
12329 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
12332 fragp->fr_subtype =
12333 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12337 else if (symsec != absolute_section && sec != NULL)
12338 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
12340 if ((val & ((1 << op->shift) - 1)) != 0
12341 || val < (mintiny << op->shift)
12342 || val > (maxtiny << op->shift))
12348 /* Estimate the size of a frag before relaxing. Unless this is the
12349 mips16, we are not really relaxing here, and the final size is
12350 encoded in the subtype information. For the mips16, we have to
12351 decide whether we are using an extended opcode or not. */
12354 md_estimate_size_before_relax (fragp, segtype)
12359 boolean linkonce = false;
12361 if (RELAX_MIPS16_P (fragp->fr_subtype))
12362 /* We don't want to modify the EXTENDED bit here; it might get us
12363 into infinite loops. We change it only in mips_relax_frag(). */
12364 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
12366 if (mips_pic == NO_PIC)
12368 change = nopic_need_relax (fragp->fr_symbol, 0);
12370 else if (mips_pic == SVR4_PIC)
12375 sym = fragp->fr_symbol;
12377 /* Handle the case of a symbol equated to another symbol. */
12378 while (symbol_equated_reloc_p (sym))
12382 /* It's possible to get a loop here in a badly written
12384 n = symbol_get_value_expression (sym)->X_add_symbol;
12390 symsec = S_GET_SEGMENT (sym);
12392 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12393 if (symsec != segtype && ! S_IS_LOCAL (sym))
12395 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12399 /* The GNU toolchain uses an extension for ELF: a section
12400 beginning with the magic string .gnu.linkonce is a linkonce
12402 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12403 sizeof ".gnu.linkonce" - 1) == 0)
12407 /* This must duplicate the test in adjust_reloc_syms. */
12408 change = (symsec != &bfd_und_section
12409 && symsec != &bfd_abs_section
12410 && ! bfd_is_com_section (symsec)
12413 /* A global or weak symbol is treated as external. */
12414 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12415 || (! S_IS_WEAK (sym)
12416 && (! S_IS_EXTERNAL (sym)
12417 || mips_pic == EMBEDDED_PIC)))
12426 /* Record the offset to the first reloc in the fr_opcode field.
12427 This lets md_convert_frag and tc_gen_reloc know that the code
12428 must be expanded. */
12429 fragp->fr_opcode = (fragp->fr_literal
12431 - RELAX_OLD (fragp->fr_subtype)
12432 + RELAX_RELOC1 (fragp->fr_subtype));
12433 /* FIXME: This really needs as_warn_where. */
12434 if (RELAX_WARN (fragp->fr_subtype))
12435 as_warn (_("AT used after \".set noat\" or macro used after "
12436 "\".set nomacro\""));
12438 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
12444 /* This is called to see whether a reloc against a defined symbol
12445 should be converted into a reloc against a section. Don't adjust
12446 MIPS16 jump relocations, so we don't have to worry about the format
12447 of the offset in the .o file. Don't adjust relocations against
12448 mips16 symbols, so that the linker can find them if it needs to set
12452 mips_fix_adjustable (fixp)
12456 /* Prevent all adjustments to global symbols. */
12457 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12458 && mips_pic != EMBEDDED_PIC
12459 && (S_IS_EXTERNAL (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
12462 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
12464 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12465 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12467 if (fixp->fx_addsy == NULL)
12470 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12471 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
12472 && fixp->fx_subsy == NULL)
12478 /* Translate internal representation of relocation info to BFD target
12482 tc_gen_reloc (section, fixp)
12483 asection *section ATTRIBUTE_UNUSED;
12486 static arelent *retval[4];
12488 bfd_reloc_code_real_type code;
12490 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
12493 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12494 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12495 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12497 if (mips_pic == EMBEDDED_PIC
12498 && SWITCH_TABLE (fixp))
12500 /* For a switch table entry we use a special reloc. The addend
12501 is actually the difference between the reloc address and the
12503 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12504 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
12505 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
12506 fixp->fx_r_type = BFD_RELOC_GPREL32;
12508 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
12510 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12511 reloc->addend = fixp->fx_addnumber;
12514 /* We use a special addend for an internal RELLO reloc. */
12515 if (symbol_section_p (fixp->fx_addsy))
12516 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12518 reloc->addend = fixp->fx_addnumber + reloc->address;
12521 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
12523 assert (fixp->fx_next != NULL
12524 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
12526 /* The reloc is relative to the RELLO; adjust the addend
12528 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12529 reloc->addend = fixp->fx_next->fx_addnumber;
12532 /* We use a special addend for an internal RELHI reloc. */
12533 if (symbol_section_p (fixp->fx_addsy))
12534 reloc->addend = (fixp->fx_next->fx_frag->fr_address
12535 + fixp->fx_next->fx_where
12536 - S_GET_VALUE (fixp->fx_subsy));
12538 reloc->addend = (fixp->fx_addnumber
12539 + fixp->fx_next->fx_frag->fr_address
12540 + fixp->fx_next->fx_where);
12543 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12544 reloc->addend = fixp->fx_addnumber;
12547 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
12548 /* A gruesome hack which is a result of the gruesome gas reloc
12550 reloc->addend = reloc->address;
12552 reloc->addend = -reloc->address;
12555 /* If this is a variant frag, we may need to adjust the existing
12556 reloc and generate a new one. */
12557 if (fixp->fx_frag->fr_opcode != NULL
12558 && (fixp->fx_r_type == BFD_RELOC_GPREL16
12559 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
12560 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
12561 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12562 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
12563 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12564 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
12569 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
12571 /* If this is not the last reloc in this frag, then we have two
12572 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
12573 CALL_HI16/CALL_LO16, both of which are being replaced. Let
12574 the second one handle all of them. */
12575 if (fixp->fx_next != NULL
12576 && fixp->fx_frag == fixp->fx_next->fx_frag)
12578 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
12579 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
12580 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12581 && (fixp->fx_next->fx_r_type
12582 == BFD_RELOC_MIPS_GOT_LO16))
12583 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12584 && (fixp->fx_next->fx_r_type
12585 == BFD_RELOC_MIPS_CALL_LO16)));
12590 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
12591 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12592 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
12594 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12595 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12596 reloc2->address = (reloc->address
12597 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
12598 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
12599 reloc2->addend = fixp->fx_addnumber;
12600 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
12601 assert (reloc2->howto != NULL);
12603 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
12607 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
12610 reloc3->address += 4;
12613 if (mips_pic == NO_PIC)
12615 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
12616 fixp->fx_r_type = BFD_RELOC_HI16_S;
12618 else if (mips_pic == SVR4_PIC)
12620 switch (fixp->fx_r_type)
12624 case BFD_RELOC_MIPS_GOT16:
12626 case BFD_RELOC_MIPS_CALL16:
12627 case BFD_RELOC_MIPS_GOT_LO16:
12628 case BFD_RELOC_MIPS_CALL_LO16:
12629 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
12637 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
12638 entry to be used in the relocation's section offset. */
12639 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12641 reloc->address = reloc->addend;
12645 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
12646 fixup_segment converted a non-PC relative reloc into a PC
12647 relative reloc. In such a case, we need to convert the reloc
12649 code = fixp->fx_r_type;
12650 if (fixp->fx_pcrel)
12655 code = BFD_RELOC_8_PCREL;
12658 code = BFD_RELOC_16_PCREL;
12661 code = BFD_RELOC_32_PCREL;
12664 code = BFD_RELOC_64_PCREL;
12666 case BFD_RELOC_8_PCREL:
12667 case BFD_RELOC_16_PCREL:
12668 case BFD_RELOC_32_PCREL:
12669 case BFD_RELOC_64_PCREL:
12670 case BFD_RELOC_16_PCREL_S2:
12671 case BFD_RELOC_PCREL_HI16_S:
12672 case BFD_RELOC_PCREL_LO16:
12675 as_bad_where (fixp->fx_file, fixp->fx_line,
12676 _("Cannot make %s relocation PC relative"),
12677 bfd_get_reloc_code_name (code));
12682 /* md_apply_fix3 has a double-subtraction hack to get
12683 bfd_install_relocation to behave nicely. GPREL relocations are
12684 handled correctly without this hack, so undo it here. We can't
12685 stop md_apply_fix3 from subtracting twice in the first place since
12686 the fake addend is required for variant frags above. */
12687 if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
12688 && code == BFD_RELOC_GPREL16
12689 && reloc->addend != 0
12690 && mips_need_elf_addend_fixup (fixp))
12691 reloc->addend += S_GET_VALUE (fixp->fx_addsy);
12694 /* To support a PC relative reloc when generating embedded PIC code
12695 for ECOFF, we use a Cygnus extension. We check for that here to
12696 make sure that we don't let such a reloc escape normally. */
12697 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
12698 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12699 && code == BFD_RELOC_16_PCREL_S2
12700 && mips_pic != EMBEDDED_PIC)
12701 reloc->howto = NULL;
12703 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12705 if (reloc->howto == NULL)
12707 as_bad_where (fixp->fx_file, fixp->fx_line,
12708 _("Can not represent %s relocation in this object file format"),
12709 bfd_get_reloc_code_name (code));
12716 /* Relax a machine dependent frag. This returns the amount by which
12717 the current size of the frag should change. */
12720 mips_relax_frag (fragp, stretch)
12724 if (! RELAX_MIPS16_P (fragp->fr_subtype))
12727 if (mips16_extended_frag (fragp, NULL, stretch))
12729 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12731 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
12736 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12738 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
12745 /* Convert a machine dependent frag. */
12748 md_convert_frag (abfd, asec, fragp)
12749 bfd *abfd ATTRIBUTE_UNUSED;
12756 if (RELAX_MIPS16_P (fragp->fr_subtype))
12759 register const struct mips16_immed_operand *op;
12760 boolean small, ext;
12763 unsigned long insn;
12764 boolean use_extend;
12765 unsigned short extend;
12767 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12768 op = mips16_immed_operands;
12769 while (op->type != type)
12772 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12783 resolve_symbol_value (fragp->fr_symbol);
12784 val = S_GET_VALUE (fragp->fr_symbol);
12789 addr = fragp->fr_address + fragp->fr_fix;
12791 /* The rules for the base address of a PC relative reloc are
12792 complicated; see mips16_extended_frag. */
12793 if (type == 'p' || type == 'q')
12798 /* Ignore the low bit in the target, since it will be
12799 set for a text label. */
12800 if ((val & 1) != 0)
12803 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12805 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12808 addr &= ~ (addressT) ((1 << op->shift) - 1);
12811 /* Make sure the section winds up with the alignment we have
12814 record_alignment (asec, op->shift);
12818 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
12819 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
12820 as_warn_where (fragp->fr_file, fragp->fr_line,
12821 _("extended instruction in delay slot"));
12823 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
12825 if (target_big_endian)
12826 insn = bfd_getb16 (buf);
12828 insn = bfd_getl16 (buf);
12830 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
12831 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
12832 small, ext, &insn, &use_extend, &extend);
12836 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
12837 fragp->fr_fix += 2;
12841 md_number_to_chars ((char *) buf, insn, 2);
12842 fragp->fr_fix += 2;
12847 if (fragp->fr_opcode == NULL)
12850 old = RELAX_OLD (fragp->fr_subtype);
12851 new = RELAX_NEW (fragp->fr_subtype);
12852 fixptr = fragp->fr_literal + fragp->fr_fix;
12855 memcpy (fixptr - old, fixptr, new);
12857 fragp->fr_fix += new - old;
12863 /* This function is called after the relocs have been generated.
12864 We've been storing mips16 text labels as odd. Here we convert them
12865 back to even for the convenience of the debugger. */
12868 mips_frob_file_after_relocs ()
12871 unsigned int count, i;
12873 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
12876 syms = bfd_get_outsymbols (stdoutput);
12877 count = bfd_get_symcount (stdoutput);
12878 for (i = 0; i < count; i++, syms++)
12880 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
12881 && ((*syms)->value & 1) != 0)
12883 (*syms)->value &= ~1;
12884 /* If the symbol has an odd size, it was probably computed
12885 incorrectly, so adjust that as well. */
12886 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
12887 ++elf_symbol (*syms)->internal_elf_sym.st_size;
12894 /* This function is called whenever a label is defined. It is used
12895 when handling branch delays; if a branch has a label, we assume we
12896 can not move it. */
12899 mips_define_label (sym)
12902 struct insn_label_list *l;
12904 if (free_insn_labels == NULL)
12905 l = (struct insn_label_list *) xmalloc (sizeof *l);
12908 l = free_insn_labels;
12909 free_insn_labels = l->next;
12913 l->next = insn_labels;
12917 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12919 /* Some special processing for a MIPS ELF file. */
12922 mips_elf_final_processing ()
12924 /* Write out the register information. */
12925 if (mips_abi != N64_ABI)
12929 s.ri_gprmask = mips_gprmask;
12930 s.ri_cprmask[0] = mips_cprmask[0];
12931 s.ri_cprmask[1] = mips_cprmask[1];
12932 s.ri_cprmask[2] = mips_cprmask[2];
12933 s.ri_cprmask[3] = mips_cprmask[3];
12934 /* The gp_value field is set by the MIPS ELF backend. */
12936 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
12937 ((Elf32_External_RegInfo *)
12938 mips_regmask_frag));
12942 Elf64_Internal_RegInfo s;
12944 s.ri_gprmask = mips_gprmask;
12946 s.ri_cprmask[0] = mips_cprmask[0];
12947 s.ri_cprmask[1] = mips_cprmask[1];
12948 s.ri_cprmask[2] = mips_cprmask[2];
12949 s.ri_cprmask[3] = mips_cprmask[3];
12950 /* The gp_value field is set by the MIPS ELF backend. */
12952 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
12953 ((Elf64_External_RegInfo *)
12954 mips_regmask_frag));
12957 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
12958 sort of BFD interface for this. */
12959 if (mips_any_noreorder)
12960 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
12961 if (mips_pic != NO_PIC)
12962 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
12964 /* Set MIPS ELF flags for ASEs. */
12965 if (file_ase_mips16)
12966 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
12967 #if 0 /* XXX FIXME */
12968 if (file_ase_mips3d)
12969 elf_elfheader (stdoutput)->e_flags |= ???;
12972 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
12974 /* Set the MIPS ELF ABI flags. */
12975 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
12976 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
12977 else if (mips_abi == O64_ABI)
12978 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
12979 else if (mips_abi == EABI_ABI)
12981 if (!file_mips_gp32)
12982 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
12984 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
12986 else if (mips_abi == N32_ABI)
12987 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
12989 /* Nothing to do for N64_ABI. */
12991 if (mips_32bitmode)
12992 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
12995 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
12997 typedef struct proc {
12999 unsigned long reg_mask;
13000 unsigned long reg_offset;
13001 unsigned long fpreg_mask;
13002 unsigned long fpreg_offset;
13003 unsigned long frame_offset;
13004 unsigned long frame_reg;
13005 unsigned long pc_reg;
13008 static procS cur_proc;
13009 static procS *cur_proc_ptr;
13010 static int numprocs;
13012 /* Fill in an rs_align_code fragment. */
13015 mips_handle_align (fragp)
13018 if (fragp->fr_type != rs_align_code)
13021 if (mips_opts.mips16)
13023 static const unsigned char be_nop[] = { 0x65, 0x00 };
13024 static const unsigned char le_nop[] = { 0x00, 0x65 };
13029 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
13030 p = fragp->fr_literal + fragp->fr_fix;
13038 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
13042 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
13053 /* check for premature end, nesting errors, etc */
13055 as_warn (_("missing .end at end of assembly"));
13064 if (*input_line_pointer == '-')
13066 ++input_line_pointer;
13069 if (!ISDIGIT (*input_line_pointer))
13070 as_bad (_("expected simple number"));
13071 if (input_line_pointer[0] == '0')
13073 if (input_line_pointer[1] == 'x')
13075 input_line_pointer += 2;
13076 while (ISXDIGIT (*input_line_pointer))
13079 val |= hex_value (*input_line_pointer++);
13081 return negative ? -val : val;
13085 ++input_line_pointer;
13086 while (ISDIGIT (*input_line_pointer))
13089 val |= *input_line_pointer++ - '0';
13091 return negative ? -val : val;
13094 if (!ISDIGIT (*input_line_pointer))
13096 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13097 *input_line_pointer, *input_line_pointer);
13098 as_warn (_("invalid number"));
13101 while (ISDIGIT (*input_line_pointer))
13104 val += *input_line_pointer++ - '0';
13106 return negative ? -val : val;
13109 /* The .file directive; just like the usual .file directive, but there
13110 is an initial number which is the ECOFF file index. In the non-ECOFF
13111 case .file implies DWARF-2. */
13115 int x ATTRIBUTE_UNUSED;
13117 static int first_file_directive = 0;
13119 if (ECOFF_DEBUGGING)
13128 filename = dwarf2_directive_file (0);
13130 /* Versions of GCC up to 3.1 start files with a ".file"
13131 directive even for stabs output. Make sure that this
13132 ".file" is handled. Note that you need a version of GCC
13133 after 3.1 in order to support DWARF-2 on MIPS. */
13134 if (filename != NULL && ! first_file_directive)
13136 (void) new_logical_line (filename, -1);
13137 s_app_file_string (filename);
13139 first_file_directive = 1;
13143 /* The .loc directive, implying DWARF-2. */
13147 int x ATTRIBUTE_UNUSED;
13149 if (!ECOFF_DEBUGGING)
13150 dwarf2_directive_loc (0);
13153 /* The .end directive. */
13157 int x ATTRIBUTE_UNUSED;
13162 /* Following functions need their own .frame and .cprestore directives. */
13163 mips_frame_reg_valid = 0;
13164 mips_cprestore_valid = 0;
13166 if (!is_end_of_line[(unsigned char) *input_line_pointer])
13169 demand_empty_rest_of_line ();
13174 #ifdef BFD_ASSEMBLER
13175 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13180 if (now_seg != data_section && now_seg != bss_section)
13187 as_warn (_(".end not in text section"));
13191 as_warn (_(".end directive without a preceding .ent directive."));
13192 demand_empty_rest_of_line ();
13198 assert (S_GET_NAME (p));
13199 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
13200 as_warn (_(".end symbol does not match .ent symbol."));
13202 if (debug_type == DEBUG_STABS)
13203 stabs_generate_asm_endfunc (S_GET_NAME (p),
13207 as_warn (_(".end directive missing or unknown symbol"));
13210 /* Generate a .pdr section. */
13211 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
13213 segT saved_seg = now_seg;
13214 subsegT saved_subseg = now_subseg;
13219 dot = frag_now_fix ();
13221 #ifdef md_flush_pending_output
13222 md_flush_pending_output ();
13226 subseg_set (pdr_seg, 0);
13228 /* Write the symbol. */
13229 exp.X_op = O_symbol;
13230 exp.X_add_symbol = p;
13231 exp.X_add_number = 0;
13232 emit_expr (&exp, 4);
13234 fragp = frag_more (7 * 4);
13236 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
13237 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
13238 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
13239 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
13240 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
13241 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
13242 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
13244 subseg_set (saved_seg, saved_subseg);
13246 #endif /* OBJ_ELF */
13248 cur_proc_ptr = NULL;
13251 /* The .aent and .ent directives. */
13260 symbolP = get_symbol ();
13261 if (*input_line_pointer == ',')
13262 ++input_line_pointer;
13263 SKIP_WHITESPACE ();
13264 if (ISDIGIT (*input_line_pointer)
13265 || *input_line_pointer == '-')
13268 #ifdef BFD_ASSEMBLER
13269 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13274 if (now_seg != data_section && now_seg != bss_section)
13281 as_warn (_(".ent or .aent not in text section."));
13283 if (!aent && cur_proc_ptr)
13284 as_warn (_("missing .end"));
13288 /* This function needs its own .frame and .cprestore directives. */
13289 mips_frame_reg_valid = 0;
13290 mips_cprestore_valid = 0;
13292 cur_proc_ptr = &cur_proc;
13293 memset (cur_proc_ptr, '\0', sizeof (procS));
13295 cur_proc_ptr->isym = symbolP;
13297 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
13301 if (debug_type == DEBUG_STABS)
13302 stabs_generate_asm_func (S_GET_NAME (symbolP),
13303 S_GET_NAME (symbolP));
13306 demand_empty_rest_of_line ();
13309 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
13310 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
13311 s_mips_frame is used so that we can set the PDR information correctly.
13312 We can't use the ecoff routines because they make reference to the ecoff
13313 symbol table (in the mdebug section). */
13316 s_mips_frame (ignore)
13317 int ignore ATTRIBUTE_UNUSED;
13320 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
13324 if (cur_proc_ptr == (procS *) NULL)
13326 as_warn (_(".frame outside of .ent"));
13327 demand_empty_rest_of_line ();
13331 cur_proc_ptr->frame_reg = tc_get_register (1);
13333 SKIP_WHITESPACE ();
13334 if (*input_line_pointer++ != ','
13335 || get_absolute_expression_and_terminator (&val) != ',')
13337 as_warn (_("Bad .frame directive"));
13338 --input_line_pointer;
13339 demand_empty_rest_of_line ();
13343 cur_proc_ptr->frame_offset = val;
13344 cur_proc_ptr->pc_reg = tc_get_register (0);
13346 demand_empty_rest_of_line ();
13349 #endif /* OBJ_ELF */
13353 /* The .fmask and .mask directives. If the mdebug section is present
13354 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
13355 embedded targets, s_mips_mask is used so that we can set the PDR
13356 information correctly. We can't use the ecoff routines because they
13357 make reference to the ecoff symbol table (in the mdebug section). */
13360 s_mips_mask (reg_type)
13364 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
13368 if (cur_proc_ptr == (procS *) NULL)
13370 as_warn (_(".mask/.fmask outside of .ent"));
13371 demand_empty_rest_of_line ();
13375 if (get_absolute_expression_and_terminator (&mask) != ',')
13377 as_warn (_("Bad .mask/.fmask directive"));
13378 --input_line_pointer;
13379 demand_empty_rest_of_line ();
13383 off = get_absolute_expression ();
13385 if (reg_type == 'F')
13387 cur_proc_ptr->fpreg_mask = mask;
13388 cur_proc_ptr->fpreg_offset = off;
13392 cur_proc_ptr->reg_mask = mask;
13393 cur_proc_ptr->reg_offset = off;
13396 demand_empty_rest_of_line ();
13399 #endif /* OBJ_ELF */
13400 s_ignore (reg_type);
13403 /* The .loc directive. */
13414 assert (now_seg == text_section);
13416 lineno = get_number ();
13417 addroff = frag_now_fix ();
13419 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
13420 S_SET_TYPE (symbolP, N_SLINE);
13421 S_SET_OTHER (symbolP, 0);
13422 S_SET_DESC (symbolP, lineno);
13423 symbolP->sy_segment = now_seg;
13427 /* A table describing all the processors gas knows about. Names are
13428 matched in the order listed.
13430 To ease comparison, please keep this table in the same order as
13431 gcc's mips_cpu_info_table[]. */
13432 static const struct mips_cpu_info mips_cpu_info_table[] =
13434 /* Entries for generic ISAs */
13435 { "mips1", 1, ISA_MIPS1, CPU_R3000 },
13436 { "mips2", 1, ISA_MIPS2, CPU_R6000 },
13437 { "mips3", 1, ISA_MIPS3, CPU_R4000 },
13438 { "mips4", 1, ISA_MIPS4, CPU_R8000 },
13439 { "mips5", 1, ISA_MIPS5, CPU_MIPS5 },
13440 { "mips32", 1, ISA_MIPS32, CPU_MIPS32 },
13441 { "mips64", 1, ISA_MIPS64, CPU_MIPS64 },
13444 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
13445 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
13446 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
13449 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
13452 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
13453 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
13454 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
13455 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
13456 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
13457 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
13458 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
13459 { "orion", 0, ISA_MIPS3, CPU_R4600 },
13460 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
13463 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
13464 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
13465 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
13466 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
13467 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
13468 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
13469 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
13470 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
13471 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
13472 { "r7000", 0, ISA_MIPS4, CPU_R5000 },
13475 { "4kc", 0, ISA_MIPS32, CPU_MIPS32, },
13476 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
13477 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
13480 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
13481 { "20kc", 0, ISA_MIPS64, CPU_MIPS64 },
13483 /* Broadcom SB-1 CPU */
13484 { "SB-1", 0, ISA_MIPS64, CPU_SB1 },
13485 { "sb-1250", 0, ISA_MIPS64, CPU_SB1 },
13486 { "sb1", 0, ISA_MIPS64, CPU_SB1 },
13487 { "sb1250", 0, ISA_MIPS64, CPU_SB1 },
13494 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
13495 with a final "000" replaced by "k". Ignore case.
13497 Note: this function is shared between GCC and GAS. */
13500 mips_strict_matching_cpu_name_p (canonical, given)
13501 const char *canonical, *given;
13503 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
13504 given++, canonical++;
13506 return ((*given == 0 && *canonical == 0)
13507 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
13511 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
13512 CPU name. We've traditionally allowed a lot of variation here.
13514 Note: this function is shared between GCC and GAS. */
13517 mips_matching_cpu_name_p (canonical, given)
13518 const char *canonical, *given;
13520 /* First see if the name matches exactly, or with a final "000"
13521 turned into "k". */
13522 if (mips_strict_matching_cpu_name_p (canonical, given))
13525 /* If not, try comparing based on numerical designation alone.
13526 See if GIVEN is an unadorned number, or 'r' followed by a number. */
13527 if (TOLOWER (*given) == 'r')
13529 if (!ISDIGIT (*given))
13532 /* Skip over some well-known prefixes in the canonical name,
13533 hoping to find a number there too. */
13534 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
13536 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
13538 else if (TOLOWER (canonical[0]) == 'r')
13541 return mips_strict_matching_cpu_name_p (canonical, given);
13545 /* Parse an option that takes the name of a processor as its argument.
13546 OPTION is the name of the option and CPU_STRING is the argument.
13547 Return the corresponding processor enumeration if the CPU_STRING is
13548 recognized, otherwise report an error and return null.
13550 A similar function exists in GCC. */
13552 static const struct mips_cpu_info *
13553 mips_parse_cpu (option, cpu_string)
13554 const char *option, *cpu_string;
13556 const struct mips_cpu_info *p;
13558 /* 'from-abi' selects the most compatible architecture for the given
13559 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
13560 EABIs, we have to decide whether we're using the 32-bit or 64-bit
13561 version. Look first at the -mgp options, if given, otherwise base
13562 the choice on MIPS_DEFAULT_64BIT.
13564 Treat NO_ABI like the EABIs. One reason to do this is that the
13565 plain 'mips' and 'mips64' configs have 'from-abi' as their default
13566 architecture. This code picks MIPS I for 'mips' and MIPS III for
13567 'mips64', just as we did in the days before 'from-abi'. */
13568 if (strcasecmp (cpu_string, "from-abi") == 0)
13570 if (ABI_NEEDS_32BIT_REGS (mips_abi))
13571 return mips_cpu_info_from_isa (ISA_MIPS1);
13573 if (ABI_NEEDS_64BIT_REGS (mips_abi))
13574 return mips_cpu_info_from_isa (ISA_MIPS3);
13576 if (file_mips_gp32 >= 0)
13577 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
13579 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
13584 /* 'default' has traditionally been a no-op. Probably not very useful. */
13585 if (strcasecmp (cpu_string, "default") == 0)
13588 for (p = mips_cpu_info_table; p->name != 0; p++)
13589 if (mips_matching_cpu_name_p (p->name, cpu_string))
13592 as_bad ("Bad value (%s) for %s", cpu_string, option);
13596 /* Return the canonical processor information for ISA (a member of the
13597 ISA_MIPS* enumeration). */
13599 static const struct mips_cpu_info *
13600 mips_cpu_info_from_isa (isa)
13605 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13606 if (mips_cpu_info_table[i].is_isa
13607 && isa == mips_cpu_info_table[i].isa)
13608 return (&mips_cpu_info_table[i]);
13614 show (stream, string, col_p, first_p)
13616 const char *string;
13622 fprintf (stream, "%24s", "");
13627 fprintf (stream, ", ");
13631 if (*col_p + strlen (string) > 72)
13633 fprintf (stream, "\n%24s", "");
13637 fprintf (stream, "%s", string);
13638 *col_p += strlen (string);
13644 md_show_usage (stream)
13650 fprintf (stream, _("\
13652 -membedded-pic generate embedded position independent code\n\
13653 -EB generate big endian output\n\
13654 -EL generate little endian output\n\
13655 -g, -g2 do not remove unneeded NOPs or swap branches\n\
13656 -G NUM allow referencing objects up to NUM bytes\n\
13657 implicitly with the gp register [default 8]\n"));
13658 fprintf (stream, _("\
13659 -mips1 generate MIPS ISA I instructions\n\
13660 -mips2 generate MIPS ISA II instructions\n\
13661 -mips3 generate MIPS ISA III instructions\n\
13662 -mips4 generate MIPS ISA IV instructions\n\
13663 -mips5 generate MIPS ISA V instructions\n\
13664 -mips32 generate MIPS32 ISA instructions\n\
13665 -mips64 generate MIPS64 ISA instructions\n\
13666 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
13670 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13671 show (stream, mips_cpu_info_table[i].name, &column, &first);
13672 show (stream, "from-abi", &column, &first);
13673 fputc ('\n', stream);
13675 fprintf (stream, _("\
13676 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
13677 -no-mCPU don't generate code specific to CPU.\n\
13678 For -mCPU and -no-mCPU, CPU must be one of:\n"));
13682 show (stream, "3900", &column, &first);
13683 show (stream, "4010", &column, &first);
13684 show (stream, "4100", &column, &first);
13685 show (stream, "4650", &column, &first);
13686 fputc ('\n', stream);
13688 fprintf (stream, _("\
13689 -mips16 generate mips16 instructions\n\
13690 -no-mips16 do not generate mips16 instructions\n"));
13691 fprintf (stream, _("\
13692 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
13693 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
13694 -O0 remove unneeded NOPs, do not swap branches\n\
13695 -O remove unneeded NOPs and swap branches\n\
13696 -n warn about NOPs generated from macros\n\
13697 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
13698 --trap, --no-break trap exception on div by 0 and mult overflow\n\
13699 --break, --no-trap break exception on div by 0 and mult overflow\n"));
13701 fprintf (stream, _("\
13702 -KPIC, -call_shared generate SVR4 position independent code\n\
13703 -non_shared do not generate position independent code\n\
13704 -xgot assume a 32 bit GOT\n\
13705 -mabi=ABI create ABI conformant object file for:\n"));
13709 show (stream, "32", &column, &first);
13710 show (stream, "o64", &column, &first);
13711 show (stream, "n32", &column, &first);
13712 show (stream, "64", &column, &first);
13713 show (stream, "eabi", &column, &first);
13715 fputc ('\n', stream);
13717 fprintf (stream, _("\
13718 -32 create o32 ABI object file (default)\n\
13719 -n32 create n32 ABI object file\n\
13720 -64 create 64 ABI object file\n"));