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_change_section
PARAMS ((int));
748 static void s_cons
PARAMS ((int));
749 static void s_float_cons
PARAMS ((int));
750 static void s_mips_globl
PARAMS ((int));
751 static void s_option
PARAMS ((int));
752 static void s_mipsset
PARAMS ((int));
753 static void s_abicalls
PARAMS ((int));
754 static void s_cpload
PARAMS ((int));
755 static void s_cpsetup
PARAMS ((int));
756 static void s_cplocal
PARAMS ((int));
757 static void s_cprestore
PARAMS ((int));
758 static void s_cpreturn
PARAMS ((int));
759 static void s_gpvalue
PARAMS ((int));
760 static void s_gpword
PARAMS ((int));
761 static void s_cpadd
PARAMS ((int));
762 static void s_insn
PARAMS ((int));
763 static void md_obj_begin
PARAMS ((void));
764 static void md_obj_end
PARAMS ((void));
765 static long get_number
PARAMS ((void));
766 static void s_mips_ent
PARAMS ((int));
767 static void s_mips_end
PARAMS ((int));
768 static void s_mips_frame
PARAMS ((int));
769 static void s_mips_mask
PARAMS ((int));
770 static void s_mips_stab
PARAMS ((int));
771 static void s_mips_weakext
PARAMS ((int));
772 static void s_mips_file
PARAMS ((int));
773 static void s_mips_loc
PARAMS ((int));
774 static int mips16_extended_frag
PARAMS ((fragS
*, asection
*, long));
775 static int validate_mips_insn
PARAMS ((const struct mips_opcode
*));
776 static void show
PARAMS ((FILE *, const char *, int *, int *));
778 static int mips_need_elf_addend_fixup
PARAMS ((fixS
*));
781 /* Return values of my_getSmallExpression(). */
788 /* Direct relocation creation by %percent_op(). */
807 /* Table and functions used to map between CPU/ISA names, and
808 ISA levels, and CPU numbers. */
812 const char *name
; /* CPU or ISA name. */
813 int is_isa
; /* Is this an ISA? (If 0, a CPU.) */
814 int isa
; /* ISA level. */
815 int cpu
; /* CPU number (default CPU if ISA). */
818 static void mips_set_architecture
PARAMS ((const struct mips_cpu_info
*));
819 static void mips_set_tune
PARAMS ((const struct mips_cpu_info
*));
820 static boolean mips_strict_matching_cpu_name_p
PARAMS ((const char *,
822 static boolean mips_matching_cpu_name_p
PARAMS ((const char *, const char *));
823 static const struct mips_cpu_info
*mips_parse_cpu
PARAMS ((const char *,
825 static const struct mips_cpu_info
*mips_cpu_info_from_isa
PARAMS ((int));
829 The following pseudo-ops from the Kane and Heinrich MIPS book
830 should be defined here, but are currently unsupported: .alias,
831 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
833 The following pseudo-ops from the Kane and Heinrich MIPS book are
834 specific to the type of debugging information being generated, and
835 should be defined by the object format: .aent, .begin, .bend,
836 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
839 The following pseudo-ops from the Kane and Heinrich MIPS book are
840 not MIPS CPU specific, but are also not specific to the object file
841 format. This file is probably the best place to define them, but
842 they are not currently supported: .asm0, .endr, .lab, .repeat,
845 static const pseudo_typeS mips_pseudo_table
[] =
847 /* MIPS specific pseudo-ops. */
848 {"option", s_option
, 0},
849 {"set", s_mipsset
, 0},
850 {"rdata", s_change_sec
, 'r'},
851 {"sdata", s_change_sec
, 's'},
852 {"livereg", s_ignore
, 0},
853 {"abicalls", s_abicalls
, 0},
854 {"cpload", s_cpload
, 0},
855 {"cpsetup", s_cpsetup
, 0},
856 {"cplocal", s_cplocal
, 0},
857 {"cprestore", s_cprestore
, 0},
858 {"cpreturn", s_cpreturn
, 0},
859 {"gpvalue", s_gpvalue
, 0},
860 {"gpword", s_gpword
, 0},
861 {"cpadd", s_cpadd
, 0},
864 /* Relatively generic pseudo-ops that happen to be used on MIPS
866 {"asciiz", stringer
, 1},
867 {"bss", s_change_sec
, 'b'},
870 {"dword", s_cons
, 3},
871 {"weakext", s_mips_weakext
, 0},
873 /* These pseudo-ops are defined in read.c, but must be overridden
874 here for one reason or another. */
875 {"align", s_align
, 0},
877 {"data", s_change_sec
, 'd'},
878 {"double", s_float_cons
, 'd'},
879 {"float", s_float_cons
, 'f'},
880 {"globl", s_mips_globl
, 0},
881 {"global", s_mips_globl
, 0},
882 {"hword", s_cons
, 1},
887 {"section", s_change_section
, 0},
888 {"short", s_cons
, 1},
889 {"single", s_float_cons
, 'f'},
890 {"stabn", s_mips_stab
, 'n'},
891 {"text", s_change_sec
, 't'},
894 { "extern", ecoff_directive_extern
, 0},
899 static const pseudo_typeS mips_nonecoff_pseudo_table
[] =
901 /* These pseudo-ops should be defined by the object file format.
902 However, a.out doesn't support them, so we have versions here. */
903 {"aent", s_mips_ent
, 1},
904 {"bgnb", s_ignore
, 0},
905 {"end", s_mips_end
, 0},
906 {"endb", s_ignore
, 0},
907 {"ent", s_mips_ent
, 0},
908 {"file", s_mips_file
, 0},
909 {"fmask", s_mips_mask
, 'F'},
910 {"frame", s_mips_frame
, 0},
911 {"loc", s_mips_loc
, 0},
912 {"mask", s_mips_mask
, 'R'},
913 {"verstamp", s_ignore
, 0},
917 extern void pop_insert
PARAMS ((const pseudo_typeS
*));
922 pop_insert (mips_pseudo_table
);
923 if (! ECOFF_DEBUGGING
)
924 pop_insert (mips_nonecoff_pseudo_table
);
927 /* Symbols labelling the current insn. */
929 struct insn_label_list
931 struct insn_label_list
*next
;
935 static struct insn_label_list
*insn_labels
;
936 static struct insn_label_list
*free_insn_labels
;
938 static void mips_clear_insn_labels
PARAMS ((void));
941 mips_clear_insn_labels ()
943 register struct insn_label_list
**pl
;
945 for (pl
= &free_insn_labels
; *pl
!= NULL
; pl
= &(*pl
)->next
)
951 static char *expr_end
;
953 /* Expressions which appear in instructions. These are set by
956 static expressionS imm_expr
;
957 static expressionS offset_expr
;
959 /* Relocs associated with imm_expr and offset_expr. */
961 static bfd_reloc_code_real_type imm_reloc
[3]
962 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
963 static bfd_reloc_code_real_type offset_reloc
[3]
964 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
966 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
968 static boolean imm_unmatched_hi
;
970 /* These are set by mips16_ip if an explicit extension is used. */
972 static boolean mips16_small
, mips16_ext
;
974 /* The pdr segment for per procedure frame/regmask info. Not used for
979 /* The default target format to use. */
982 mips_target_format ()
984 switch (OUTPUT_FLAVOR
)
986 case bfd_target_aout_flavour
:
987 return target_big_endian
? "a.out-mips-big" : "a.out-mips-little";
988 case bfd_target_ecoff_flavour
:
989 return target_big_endian
? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT
;
990 case bfd_target_coff_flavour
:
992 case bfd_target_elf_flavour
:
994 /* This is traditional mips. */
995 return (target_big_endian
996 ? (HAVE_64BIT_OBJECTS
997 ? "elf64-tradbigmips"
999 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1000 : (HAVE_64BIT_OBJECTS
1001 ? "elf64-tradlittlemips"
1003 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1005 return (target_big_endian
1006 ? (HAVE_64BIT_OBJECTS
1009 ? "elf32-nbigmips" : "elf32-bigmips"))
1010 : (HAVE_64BIT_OBJECTS
1011 ? "elf64-littlemips"
1013 ? "elf32-nlittlemips" : "elf32-littlemips")));
1021 /* This function is called once, at assembler startup time. It should
1022 set up all the tables, etc. that the MD part of the assembler will need. */
1027 register const char *retval
= NULL
;
1031 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_mips
, mips_arch
))
1032 as_warn (_("Could not set architecture and machine"));
1034 op_hash
= hash_new ();
1036 for (i
= 0; i
< NUMOPCODES
;)
1038 const char *name
= mips_opcodes
[i
].name
;
1040 retval
= hash_insert (op_hash
, name
, (PTR
) &mips_opcodes
[i
]);
1043 fprintf (stderr
, _("internal error: can't hash `%s': %s\n"),
1044 mips_opcodes
[i
].name
, retval
);
1045 /* Probably a memory allocation problem? Give up now. */
1046 as_fatal (_("Broken assembler. No assembly attempted."));
1050 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
)
1052 if (!validate_mips_insn (&mips_opcodes
[i
]))
1057 while ((i
< NUMOPCODES
) && !strcmp (mips_opcodes
[i
].name
, name
));
1060 mips16_op_hash
= hash_new ();
1063 while (i
< bfd_mips16_num_opcodes
)
1065 const char *name
= mips16_opcodes
[i
].name
;
1067 retval
= hash_insert (mips16_op_hash
, name
, (PTR
) &mips16_opcodes
[i
]);
1069 as_fatal (_("internal: can't hash `%s': %s"),
1070 mips16_opcodes
[i
].name
, retval
);
1073 if (mips16_opcodes
[i
].pinfo
!= INSN_MACRO
1074 && ((mips16_opcodes
[i
].match
& mips16_opcodes
[i
].mask
)
1075 != mips16_opcodes
[i
].match
))
1077 fprintf (stderr
, _("internal error: bad mips16 opcode: %s %s\n"),
1078 mips16_opcodes
[i
].name
, mips16_opcodes
[i
].args
);
1083 while (i
< bfd_mips16_num_opcodes
1084 && strcmp (mips16_opcodes
[i
].name
, name
) == 0);
1088 as_fatal (_("Broken assembler. No assembly attempted."));
1090 /* We add all the general register names to the symbol table. This
1091 helps us detect invalid uses of them. */
1092 for (i
= 0; i
< 32; i
++)
1096 sprintf (buf
, "$%d", i
);
1097 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
1098 &zero_address_frag
));
1100 symbol_table_insert (symbol_new ("$ra", reg_section
, RA
,
1101 &zero_address_frag
));
1102 symbol_table_insert (symbol_new ("$fp", reg_section
, FP
,
1103 &zero_address_frag
));
1104 symbol_table_insert (symbol_new ("$sp", reg_section
, SP
,
1105 &zero_address_frag
));
1106 symbol_table_insert (symbol_new ("$gp", reg_section
, GP
,
1107 &zero_address_frag
));
1108 symbol_table_insert (symbol_new ("$at", reg_section
, AT
,
1109 &zero_address_frag
));
1110 symbol_table_insert (symbol_new ("$kt0", reg_section
, KT0
,
1111 &zero_address_frag
));
1112 symbol_table_insert (symbol_new ("$kt1", reg_section
, KT1
,
1113 &zero_address_frag
));
1114 symbol_table_insert (symbol_new ("$zero", reg_section
, ZERO
,
1115 &zero_address_frag
));
1116 symbol_table_insert (symbol_new ("$pc", reg_section
, -1,
1117 &zero_address_frag
));
1119 mips_no_prev_insn (false);
1122 mips_cprmask
[0] = 0;
1123 mips_cprmask
[1] = 0;
1124 mips_cprmask
[2] = 0;
1125 mips_cprmask
[3] = 0;
1127 /* set the default alignment for the text section (2**2) */
1128 record_alignment (text_section
, 2);
1130 if (USE_GLOBAL_POINTER_OPT
)
1131 bfd_set_gp_size (stdoutput
, g_switch_value
);
1133 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1135 /* On a native system, sections must be aligned to 16 byte
1136 boundaries. When configured for an embedded ELF target, we
1138 if (strcmp (TARGET_OS
, "elf") != 0)
1140 (void) bfd_set_section_alignment (stdoutput
, text_section
, 4);
1141 (void) bfd_set_section_alignment (stdoutput
, data_section
, 4);
1142 (void) bfd_set_section_alignment (stdoutput
, bss_section
, 4);
1145 /* Create a .reginfo section for register masks and a .mdebug
1146 section for debugging information. */
1154 subseg
= now_subseg
;
1156 /* The ABI says this section should be loaded so that the
1157 running program can access it. However, we don't load it
1158 if we are configured for an embedded target */
1159 flags
= SEC_READONLY
| SEC_DATA
;
1160 if (strcmp (TARGET_OS
, "elf") != 0)
1161 flags
|= SEC_ALLOC
| SEC_LOAD
;
1163 if (mips_abi
!= N64_ABI
)
1165 sec
= subseg_new (".reginfo", (subsegT
) 0);
1167 bfd_set_section_flags (stdoutput
, sec
, flags
);
1168 bfd_set_section_alignment (stdoutput
, sec
, HAVE_NEWABI
? 3 : 2);
1171 mips_regmask_frag
= frag_more (sizeof (Elf32_External_RegInfo
));
1176 /* The 64-bit ABI uses a .MIPS.options section rather than
1177 .reginfo section. */
1178 sec
= subseg_new (".MIPS.options", (subsegT
) 0);
1179 bfd_set_section_flags (stdoutput
, sec
, flags
);
1180 bfd_set_section_alignment (stdoutput
, sec
, 3);
1183 /* Set up the option header. */
1185 Elf_Internal_Options opthdr
;
1188 opthdr
.kind
= ODK_REGINFO
;
1189 opthdr
.size
= (sizeof (Elf_External_Options
)
1190 + sizeof (Elf64_External_RegInfo
));
1193 f
= frag_more (sizeof (Elf_External_Options
));
1194 bfd_mips_elf_swap_options_out (stdoutput
, &opthdr
,
1195 (Elf_External_Options
*) f
);
1197 mips_regmask_frag
= frag_more (sizeof (Elf64_External_RegInfo
));
1202 if (ECOFF_DEBUGGING
)
1204 sec
= subseg_new (".mdebug", (subsegT
) 0);
1205 (void) bfd_set_section_flags (stdoutput
, sec
,
1206 SEC_HAS_CONTENTS
| SEC_READONLY
);
1207 (void) bfd_set_section_alignment (stdoutput
, sec
, 2);
1210 else if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1212 pdr_seg
= subseg_new (".pdr", (subsegT
) 0);
1213 (void) bfd_set_section_flags (stdoutput
, pdr_seg
,
1214 SEC_READONLY
| SEC_RELOC
1216 (void) bfd_set_section_alignment (stdoutput
, pdr_seg
, 2);
1220 subseg_set (seg
, subseg
);
1224 if (! ECOFF_DEBUGGING
)
1231 if (! ECOFF_DEBUGGING
)
1239 struct mips_cl_insn insn
;
1240 bfd_reloc_code_real_type unused_reloc
[3]
1241 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1243 imm_expr
.X_op
= O_absent
;
1244 imm_unmatched_hi
= false;
1245 offset_expr
.X_op
= O_absent
;
1246 imm_reloc
[0] = BFD_RELOC_UNUSED
;
1247 imm_reloc
[1] = BFD_RELOC_UNUSED
;
1248 imm_reloc
[2] = BFD_RELOC_UNUSED
;
1249 offset_reloc
[0] = BFD_RELOC_UNUSED
;
1250 offset_reloc
[1] = BFD_RELOC_UNUSED
;
1251 offset_reloc
[2] = BFD_RELOC_UNUSED
;
1253 if (mips_opts
.mips16
)
1254 mips16_ip (str
, &insn
);
1257 mips_ip (str
, &insn
);
1258 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1259 str
, insn
.insn_opcode
));
1264 as_bad ("%s `%s'", insn_error
, str
);
1268 if (insn
.insn_mo
->pinfo
== INSN_MACRO
)
1270 if (mips_opts
.mips16
)
1271 mips16_macro (&insn
);
1277 if (imm_expr
.X_op
!= O_absent
)
1278 append_insn (NULL
, &insn
, &imm_expr
, imm_reloc
, imm_unmatched_hi
);
1279 else if (offset_expr
.X_op
!= O_absent
)
1280 append_insn (NULL
, &insn
, &offset_expr
, offset_reloc
, false);
1282 append_insn (NULL
, &insn
, NULL
, unused_reloc
, false);
1286 /* See whether instruction IP reads register REG. CLASS is the type
1290 insn_uses_reg (ip
, reg
, class)
1291 struct mips_cl_insn
*ip
;
1293 enum mips_regclass
class;
1295 if (class == MIPS16_REG
)
1297 assert (mips_opts
.mips16
);
1298 reg
= mips16_to_32_reg_map
[reg
];
1299 class = MIPS_GR_REG
;
1302 /* Don't report on general register ZERO, since it never changes. */
1303 if (class == MIPS_GR_REG
&& reg
== ZERO
)
1306 if (class == MIPS_FP_REG
)
1308 assert (! mips_opts
.mips16
);
1309 /* If we are called with either $f0 or $f1, we must check $f0.
1310 This is not optimal, because it will introduce an unnecessary
1311 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1312 need to distinguish reading both $f0 and $f1 or just one of
1313 them. Note that we don't have to check the other way,
1314 because there is no instruction that sets both $f0 and $f1
1315 and requires a delay. */
1316 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_S
)
1317 && ((((ip
->insn_opcode
>> OP_SH_FS
) & OP_MASK_FS
) &~(unsigned)1)
1318 == (reg
&~ (unsigned) 1)))
1320 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_T
)
1321 && ((((ip
->insn_opcode
>> OP_SH_FT
) & OP_MASK_FT
) &~(unsigned)1)
1322 == (reg
&~ (unsigned) 1)))
1325 else if (! mips_opts
.mips16
)
1327 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_S
)
1328 && ((ip
->insn_opcode
>> OP_SH_RS
) & OP_MASK_RS
) == reg
)
1330 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_T
)
1331 && ((ip
->insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
) == reg
)
1336 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_X
)
1337 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_RX
)
1338 & MIPS16OP_MASK_RX
)]
1341 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Y
)
1342 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_RY
)
1343 & MIPS16OP_MASK_RY
)]
1346 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Z
)
1347 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_MOVE32Z
)
1348 & MIPS16OP_MASK_MOVE32Z
)]
1351 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_T
) && reg
== TREG
)
1353 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_SP
) && reg
== SP
)
1355 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_31
) && reg
== RA
)
1357 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_GPR_X
)
1358 && ((ip
->insn_opcode
>> MIPS16OP_SH_REGR32
)
1359 & MIPS16OP_MASK_REGR32
) == reg
)
1366 /* This function returns true if modifying a register requires a
1370 reg_needs_delay (reg
)
1373 unsigned long prev_pinfo
;
1375 prev_pinfo
= prev_insn
.insn_mo
->pinfo
;
1376 if (! mips_opts
.noreorder
1377 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1378 && ((prev_pinfo
& INSN_LOAD_COPROC_DELAY
)
1379 || (! gpr_interlocks
1380 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))))
1382 /* A load from a coprocessor or from memory. All load
1383 delays delay the use of general register rt for one
1384 instruction on the r3000. The r6000 and r4000 use
1386 /* Itbl support may require additional care here. */
1387 know (prev_pinfo
& INSN_WRITE_GPR_T
);
1388 if (reg
== ((prev_insn
.insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
))
1395 /* Mark instruction labels in mips16 mode. This permits the linker to
1396 handle them specially, such as generating jalx instructions when
1397 needed. We also make them odd for the duration of the assembly, in
1398 order to generate the right sort of code. We will make them even
1399 in the adjust_symtab routine, while leaving them marked. This is
1400 convenient for the debugger and the disassembler. The linker knows
1401 to make them odd again. */
1404 mips16_mark_labels ()
1406 if (mips_opts
.mips16
)
1408 struct insn_label_list
*l
;
1411 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
1414 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1415 S_SET_OTHER (l
->label
, STO_MIPS16
);
1417 val
= S_GET_VALUE (l
->label
);
1419 S_SET_VALUE (l
->label
, val
+ 1);
1424 /* Output an instruction. PLACE is where to put the instruction; if
1425 it is NULL, this uses frag_more to get room. IP is the instruction
1426 information. ADDRESS_EXPR is an operand of the instruction to be
1427 used with RELOC_TYPE. */
1430 append_insn (place
, ip
, address_expr
, reloc_type
, unmatched_hi
)
1432 struct mips_cl_insn
*ip
;
1433 expressionS
*address_expr
;
1434 bfd_reloc_code_real_type
*reloc_type
;
1435 boolean unmatched_hi
;
1437 register unsigned long prev_pinfo
, pinfo
;
1442 /* Mark instruction labels in mips16 mode. */
1443 mips16_mark_labels ();
1445 prev_pinfo
= prev_insn
.insn_mo
->pinfo
;
1446 pinfo
= ip
->insn_mo
->pinfo
;
1448 if (place
== NULL
&& (! mips_opts
.noreorder
|| prev_nop_frag
!= NULL
))
1452 /* If the previous insn required any delay slots, see if we need
1453 to insert a NOP or two. There are eight kinds of possible
1454 hazards, of which an instruction can have at most one type.
1455 (1) a load from memory delay
1456 (2) a load from a coprocessor delay
1457 (3) an unconditional branch delay
1458 (4) a conditional branch delay
1459 (5) a move to coprocessor register delay
1460 (6) a load coprocessor register from memory delay
1461 (7) a coprocessor condition code delay
1462 (8) a HI/LO special register delay
1464 There are a lot of optimizations we could do that we don't.
1465 In particular, we do not, in general, reorder instructions.
1466 If you use gcc with optimization, it will reorder
1467 instructions and generally do much more optimization then we
1468 do here; repeating all that work in the assembler would only
1469 benefit hand written assembly code, and does not seem worth
1472 /* This is how a NOP is emitted. */
1473 #define emit_nop() \
1475 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1476 : md_number_to_chars (frag_more (4), 0, 4))
1478 /* The previous insn might require a delay slot, depending upon
1479 the contents of the current insn. */
1480 if (! mips_opts
.mips16
1481 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1482 && (((prev_pinfo
& INSN_LOAD_COPROC_DELAY
)
1483 && ! cop_interlocks
)
1484 || (! gpr_interlocks
1485 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))))
1487 /* A load from a coprocessor or from memory. All load
1488 delays delay the use of general register rt for one
1489 instruction on the r3000. The r6000 and r4000 use
1491 /* Itbl support may require additional care here. */
1492 know (prev_pinfo
& INSN_WRITE_GPR_T
);
1493 if (mips_optimize
== 0
1494 || insn_uses_reg (ip
,
1495 ((prev_insn
.insn_opcode
>> OP_SH_RT
)
1500 else if (! mips_opts
.mips16
1501 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1502 && (((prev_pinfo
& INSN_COPROC_MOVE_DELAY
)
1503 && ! cop_interlocks
)
1504 || (mips_opts
.isa
== ISA_MIPS1
1505 && (prev_pinfo
& INSN_COPROC_MEMORY_DELAY
))))
1507 /* A generic coprocessor delay. The previous instruction
1508 modified a coprocessor general or control register. If
1509 it modified a control register, we need to avoid any
1510 coprocessor instruction (this is probably not always
1511 required, but it sometimes is). If it modified a general
1512 register, we avoid using that register.
1514 On the r6000 and r4000 loading a coprocessor register
1515 from memory is interlocked, and does not require a delay.
1517 This case is not handled very well. There is no special
1518 knowledge of CP0 handling, and the coprocessors other
1519 than the floating point unit are not distinguished at
1521 /* Itbl support may require additional care here. FIXME!
1522 Need to modify this to include knowledge about
1523 user specified delays! */
1524 if (prev_pinfo
& INSN_WRITE_FPR_T
)
1526 if (mips_optimize
== 0
1527 || insn_uses_reg (ip
,
1528 ((prev_insn
.insn_opcode
>> OP_SH_FT
)
1533 else if (prev_pinfo
& INSN_WRITE_FPR_S
)
1535 if (mips_optimize
== 0
1536 || insn_uses_reg (ip
,
1537 ((prev_insn
.insn_opcode
>> OP_SH_FS
)
1544 /* We don't know exactly what the previous instruction
1545 does. If the current instruction uses a coprocessor
1546 register, we must insert a NOP. If previous
1547 instruction may set the condition codes, and the
1548 current instruction uses them, we must insert two
1550 /* Itbl support may require additional care here. */
1551 if (mips_optimize
== 0
1552 || ((prev_pinfo
& INSN_WRITE_COND_CODE
)
1553 && (pinfo
& INSN_READ_COND_CODE
)))
1555 else if (pinfo
& INSN_COP
)
1559 else if (! mips_opts
.mips16
1560 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1561 && (prev_pinfo
& INSN_WRITE_COND_CODE
)
1562 && ! cop_interlocks
)
1564 /* The previous instruction sets the coprocessor condition
1565 codes, but does not require a general coprocessor delay
1566 (this means it is a floating point comparison
1567 instruction). If this instruction uses the condition
1568 codes, we need to insert a single NOP. */
1569 /* Itbl support may require additional care here. */
1570 if (mips_optimize
== 0
1571 || (pinfo
& INSN_READ_COND_CODE
))
1575 /* If we're fixing up mfhi/mflo for the r7000 and the
1576 previous insn was an mfhi/mflo and the current insn
1577 reads the register that the mfhi/mflo wrote to, then
1580 else if (mips_7000_hilo_fix
1581 && MF_HILO_INSN (prev_pinfo
)
1582 && insn_uses_reg (ip
, ((prev_insn
.insn_opcode
>> OP_SH_RD
)
1589 /* If we're fixing up mfhi/mflo for the r7000 and the
1590 2nd previous insn was an mfhi/mflo and the current insn
1591 reads the register that the mfhi/mflo wrote to, then
1594 else if (mips_7000_hilo_fix
1595 && MF_HILO_INSN (prev_prev_insn
.insn_opcode
)
1596 && insn_uses_reg (ip
, ((prev_prev_insn
.insn_opcode
>> OP_SH_RD
)
1604 else if (prev_pinfo
& INSN_READ_LO
)
1606 /* The previous instruction reads the LO register; if the
1607 current instruction writes to the LO register, we must
1608 insert two NOPS. Some newer processors have interlocks.
1609 Also the tx39's multiply instructions can be exectuted
1610 immediatly after a read from HI/LO (without the delay),
1611 though the tx39's divide insns still do require the
1613 if (! (hilo_interlocks
1614 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
1615 && (mips_optimize
== 0
1616 || (pinfo
& INSN_WRITE_LO
)))
1618 /* Most mips16 branch insns don't have a delay slot.
1619 If a read from LO is immediately followed by a branch
1620 to a write to LO we have a read followed by a write
1621 less than 2 insns away. We assume the target of
1622 a branch might be a write to LO, and insert a nop
1623 between a read and an immediately following branch. */
1624 else if (mips_opts
.mips16
1625 && (mips_optimize
== 0
1626 || (pinfo
& MIPS16_INSN_BRANCH
)))
1629 else if (prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
1631 /* The previous instruction reads the HI register; if the
1632 current instruction writes to the HI register, we must
1633 insert a NOP. Some newer processors have interlocks.
1634 Also the note tx39's multiply above. */
1635 if (! (hilo_interlocks
1636 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
1637 && (mips_optimize
== 0
1638 || (pinfo
& INSN_WRITE_HI
)))
1640 /* Most mips16 branch insns don't have a delay slot.
1641 If a read from HI is immediately followed by a branch
1642 to a write to HI we have a read followed by a write
1643 less than 2 insns away. We assume the target of
1644 a branch might be a write to HI, and insert a nop
1645 between a read and an immediately following branch. */
1646 else if (mips_opts
.mips16
1647 && (mips_optimize
== 0
1648 || (pinfo
& MIPS16_INSN_BRANCH
)))
1652 /* If the previous instruction was in a noreorder section, then
1653 we don't want to insert the nop after all. */
1654 /* Itbl support may require additional care here. */
1655 if (prev_insn_unreordered
)
1658 /* There are two cases which require two intervening
1659 instructions: 1) setting the condition codes using a move to
1660 coprocessor instruction which requires a general coprocessor
1661 delay and then reading the condition codes 2) reading the HI
1662 or LO register and then writing to it (except on processors
1663 which have interlocks). If we are not already emitting a NOP
1664 instruction, we must check for these cases compared to the
1665 instruction previous to the previous instruction. */
1666 if ((! mips_opts
.mips16
1667 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1668 && (prev_prev_insn
.insn_mo
->pinfo
& INSN_COPROC_MOVE_DELAY
)
1669 && (prev_prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
)
1670 && (pinfo
& INSN_READ_COND_CODE
)
1671 && ! cop_interlocks
)
1672 || ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
)
1673 && (pinfo
& INSN_WRITE_LO
)
1674 && ! (hilo_interlocks
1675 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
))))
1676 || ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
1677 && (pinfo
& INSN_WRITE_HI
)
1678 && ! (hilo_interlocks
1679 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))))
1684 if (prev_prev_insn_unreordered
)
1687 if (prev_prev_nop
&& nops
== 0)
1690 /* If we are being given a nop instruction, don't bother with
1691 one of the nops we would otherwise output. This will only
1692 happen when a nop instruction is used with mips_optimize set
1695 && ! mips_opts
.noreorder
1696 && ip
->insn_opcode
== (unsigned) (mips_opts
.mips16
? 0x6500 : 0))
1699 /* Now emit the right number of NOP instructions. */
1700 if (nops
> 0 && ! mips_opts
.noreorder
)
1703 unsigned long old_frag_offset
;
1705 struct insn_label_list
*l
;
1707 old_frag
= frag_now
;
1708 old_frag_offset
= frag_now_fix ();
1710 for (i
= 0; i
< nops
; i
++)
1715 listing_prev_line ();
1716 /* We may be at the start of a variant frag. In case we
1717 are, make sure there is enough space for the frag
1718 after the frags created by listing_prev_line. The
1719 argument to frag_grow here must be at least as large
1720 as the argument to all other calls to frag_grow in
1721 this file. We don't have to worry about being in the
1722 middle of a variant frag, because the variants insert
1723 all needed nop instructions themselves. */
1727 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
1731 assert (S_GET_SEGMENT (l
->label
) == now_seg
);
1732 symbol_set_frag (l
->label
, frag_now
);
1733 val
= (valueT
) frag_now_fix ();
1734 /* mips16 text labels are stored as odd. */
1735 if (mips_opts
.mips16
)
1737 S_SET_VALUE (l
->label
, val
);
1740 #ifndef NO_ECOFF_DEBUGGING
1741 if (ECOFF_DEBUGGING
)
1742 ecoff_fix_loc (old_frag
, old_frag_offset
);
1745 else if (prev_nop_frag
!= NULL
)
1747 /* We have a frag holding nops we may be able to remove. If
1748 we don't need any nops, we can decrease the size of
1749 prev_nop_frag by the size of one instruction. If we do
1750 need some nops, we count them in prev_nops_required. */
1751 if (prev_nop_frag_since
== 0)
1755 prev_nop_frag
->fr_fix
-= mips_opts
.mips16
? 2 : 4;
1756 --prev_nop_frag_holds
;
1759 prev_nop_frag_required
+= nops
;
1763 if (prev_prev_nop
== 0)
1765 prev_nop_frag
->fr_fix
-= mips_opts
.mips16
? 2 : 4;
1766 --prev_nop_frag_holds
;
1769 ++prev_nop_frag_required
;
1772 if (prev_nop_frag_holds
<= prev_nop_frag_required
)
1773 prev_nop_frag
= NULL
;
1775 ++prev_nop_frag_since
;
1777 /* Sanity check: by the time we reach the second instruction
1778 after prev_nop_frag, we should have used up all the nops
1779 one way or another. */
1780 assert (prev_nop_frag_since
<= 1 || prev_nop_frag
== NULL
);
1784 if (*reloc_type
> BFD_RELOC_UNUSED
)
1786 /* We need to set up a variant frag. */
1787 assert (mips_opts
.mips16
&& address_expr
!= NULL
);
1788 f
= frag_var (rs_machine_dependent
, 4, 0,
1789 RELAX_MIPS16_ENCODE (*reloc_type
- BFD_RELOC_UNUSED
,
1790 mips16_small
, mips16_ext
,
1792 & INSN_UNCOND_BRANCH_DELAY
),
1793 (*prev_insn_reloc_type
1794 == BFD_RELOC_MIPS16_JMP
)),
1795 make_expr_symbol (address_expr
), 0, NULL
);
1797 else if (place
!= NULL
)
1799 else if (mips_opts
.mips16
1801 && *reloc_type
!= BFD_RELOC_MIPS16_JMP
)
1803 /* Make sure there is enough room to swap this instruction with
1804 a following jump instruction. */
1810 if (mips_opts
.mips16
1811 && mips_opts
.noreorder
1812 && (prev_pinfo
& INSN_UNCOND_BRANCH_DELAY
) != 0)
1813 as_warn (_("extended instruction in delay slot"));
1818 fixp
[0] = fixp
[1] = fixp
[2] = NULL
;
1819 if (address_expr
!= NULL
&& *reloc_type
< BFD_RELOC_UNUSED
)
1821 if (address_expr
->X_op
== O_constant
)
1825 switch (*reloc_type
)
1828 ip
->insn_opcode
|= address_expr
->X_add_number
;
1831 case BFD_RELOC_MIPS_HIGHEST
:
1832 tmp
= (address_expr
->X_add_number
+ 0x800080008000) >> 16;
1834 ip
->insn_opcode
|= (tmp
>> 16) & 0xffff;
1837 case BFD_RELOC_MIPS_HIGHER
:
1838 tmp
= (address_expr
->X_add_number
+ 0x80008000) >> 16;
1839 ip
->insn_opcode
|= (tmp
>> 16) & 0xffff;
1842 case BFD_RELOC_HI16_S
:
1843 ip
->insn_opcode
|= ((address_expr
->X_add_number
+ 0x8000)
1847 case BFD_RELOC_HI16
:
1848 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 16) & 0xffff;
1851 case BFD_RELOC_LO16
:
1852 ip
->insn_opcode
|= address_expr
->X_add_number
& 0xffff;
1855 case BFD_RELOC_MIPS_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
);
1863 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 2) & 0x3ffffff;
1866 case BFD_RELOC_MIPS16_JMP
:
1867 if ((address_expr
->X_add_number
& 3) != 0)
1868 as_bad (_("jump to misaligned address (0x%lx)"),
1869 (unsigned long) address_expr
->X_add_number
);
1870 if (address_expr
->X_add_number
& ~0xfffffff
1871 || address_expr
->X_add_number
> 0x7fffffc)
1872 as_bad (_("jump address range overflow (0x%lx)"),
1873 (unsigned long) address_expr
->X_add_number
);
1875 (((address_expr
->X_add_number
& 0x7c0000) << 3)
1876 | ((address_expr
->X_add_number
& 0xf800000) >> 7)
1877 | ((address_expr
->X_add_number
& 0x3fffc) >> 2));
1880 case BFD_RELOC_16_PCREL
:
1881 ip
->insn_opcode
|= address_expr
->X_add_number
& 0xffff;
1884 case BFD_RELOC_16_PCREL_S2
:
1894 /* Don't generate a reloc if we are writing into a variant frag. */
1897 fixp
[0] = fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1899 (*reloc_type
== BFD_RELOC_16_PCREL
1900 || *reloc_type
== BFD_RELOC_16_PCREL_S2
),
1903 /* These relocations can have an addend that won't fit in
1904 4 octets for 64bit assembly. */
1905 if (HAVE_64BIT_GPRS
&&
1906 (*reloc_type
== BFD_RELOC_16
1907 || *reloc_type
== BFD_RELOC_32
1908 || *reloc_type
== BFD_RELOC_MIPS_JMP
1909 || *reloc_type
== BFD_RELOC_HI16_S
1910 || *reloc_type
== BFD_RELOC_LO16
1911 || *reloc_type
== BFD_RELOC_GPREL16
1912 || *reloc_type
== BFD_RELOC_MIPS_LITERAL
1913 || *reloc_type
== BFD_RELOC_GPREL32
1914 || *reloc_type
== BFD_RELOC_64
1915 || *reloc_type
== BFD_RELOC_CTOR
1916 || *reloc_type
== BFD_RELOC_MIPS_SUB
1917 || *reloc_type
== BFD_RELOC_MIPS_HIGHEST
1918 || *reloc_type
== BFD_RELOC_MIPS_HIGHER
1919 || *reloc_type
== BFD_RELOC_MIPS_SCN_DISP
1920 || *reloc_type
== BFD_RELOC_MIPS_REL16
1921 || *reloc_type
== BFD_RELOC_MIPS_RELGOT
))
1922 fixp
[0]->fx_no_overflow
= 1;
1926 struct mips_hi_fixup
*hi_fixup
;
1928 assert (*reloc_type
== BFD_RELOC_HI16_S
);
1929 hi_fixup
= ((struct mips_hi_fixup
*)
1930 xmalloc (sizeof (struct mips_hi_fixup
)));
1931 hi_fixup
->fixp
= fixp
[0];
1932 hi_fixup
->seg
= now_seg
;
1933 hi_fixup
->next
= mips_hi_fixup_list
;
1934 mips_hi_fixup_list
= hi_fixup
;
1937 if (reloc_type
[1] != BFD_RELOC_UNUSED
)
1939 /* FIXME: This symbol can be one of
1940 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
1941 address_expr
->X_op
= O_absent
;
1942 address_expr
->X_add_symbol
= 0;
1943 address_expr
->X_add_number
= 0;
1945 fixp
[1] = fix_new_exp (frag_now
, f
- frag_now
->fr_literal
,
1946 4, address_expr
, false,
1949 /* These relocations can have an addend that won't fit in
1950 4 octets for 64bit assembly. */
1951 if (HAVE_64BIT_GPRS
&&
1952 (*reloc_type
== BFD_RELOC_16
1953 || *reloc_type
== BFD_RELOC_32
1954 || *reloc_type
== BFD_RELOC_MIPS_JMP
1955 || *reloc_type
== BFD_RELOC_HI16_S
1956 || *reloc_type
== BFD_RELOC_LO16
1957 || *reloc_type
== BFD_RELOC_GPREL16
1958 || *reloc_type
== BFD_RELOC_MIPS_LITERAL
1959 || *reloc_type
== BFD_RELOC_GPREL32
1960 || *reloc_type
== BFD_RELOC_64
1961 || *reloc_type
== BFD_RELOC_CTOR
1962 || *reloc_type
== BFD_RELOC_MIPS_SUB
1963 || *reloc_type
== BFD_RELOC_MIPS_HIGHEST
1964 || *reloc_type
== BFD_RELOC_MIPS_HIGHER
1965 || *reloc_type
== BFD_RELOC_MIPS_SCN_DISP
1966 || *reloc_type
== BFD_RELOC_MIPS_REL16
1967 || *reloc_type
== BFD_RELOC_MIPS_RELGOT
))
1968 fixp
[1]->fx_no_overflow
= 1;
1970 if (reloc_type
[2] != BFD_RELOC_UNUSED
)
1972 address_expr
->X_op
= O_absent
;
1973 address_expr
->X_add_symbol
= 0;
1974 address_expr
->X_add_number
= 0;
1976 fixp
[2] = fix_new_exp (frag_now
,
1977 f
- frag_now
->fr_literal
, 4,
1978 address_expr
, false,
1981 /* These relocations can have an addend that won't fit in
1982 4 octets for 64bit assembly. */
1983 if (HAVE_64BIT_GPRS
&&
1984 (*reloc_type
== BFD_RELOC_16
1985 || *reloc_type
== BFD_RELOC_32
1986 || *reloc_type
== BFD_RELOC_MIPS_JMP
1987 || *reloc_type
== BFD_RELOC_HI16_S
1988 || *reloc_type
== BFD_RELOC_LO16
1989 || *reloc_type
== BFD_RELOC_GPREL16
1990 || *reloc_type
== BFD_RELOC_MIPS_LITERAL
1991 || *reloc_type
== BFD_RELOC_GPREL32
1992 || *reloc_type
== BFD_RELOC_64
1993 || *reloc_type
== BFD_RELOC_CTOR
1994 || *reloc_type
== BFD_RELOC_MIPS_SUB
1995 || *reloc_type
== BFD_RELOC_MIPS_HIGHEST
1996 || *reloc_type
== BFD_RELOC_MIPS_HIGHER
1997 || *reloc_type
== BFD_RELOC_MIPS_SCN_DISP
1998 || *reloc_type
== BFD_RELOC_MIPS_REL16
1999 || *reloc_type
== BFD_RELOC_MIPS_RELGOT
))
2000 fixp
[2]->fx_no_overflow
= 1;
2007 if (! mips_opts
.mips16
)
2009 md_number_to_chars (f
, ip
->insn_opcode
, 4);
2011 dwarf2_emit_insn (4);
2014 else if (*reloc_type
== BFD_RELOC_MIPS16_JMP
)
2016 md_number_to_chars (f
, ip
->insn_opcode
>> 16, 2);
2017 md_number_to_chars (f
+ 2, ip
->insn_opcode
& 0xffff, 2);
2019 dwarf2_emit_insn (4);
2026 md_number_to_chars (f
, 0xf000 | ip
->extend
, 2);
2029 md_number_to_chars (f
, ip
->insn_opcode
, 2);
2031 dwarf2_emit_insn (ip
->use_extend
? 4 : 2);
2035 /* Update the register mask information. */
2036 if (! mips_opts
.mips16
)
2038 if (pinfo
& INSN_WRITE_GPR_D
)
2039 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
);
2040 if ((pinfo
& (INSN_WRITE_GPR_T
| INSN_READ_GPR_T
)) != 0)
2041 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
);
2042 if (pinfo
& INSN_READ_GPR_S
)
2043 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RS
) & OP_MASK_RS
);
2044 if (pinfo
& INSN_WRITE_GPR_31
)
2045 mips_gprmask
|= 1 << RA
;
2046 if (pinfo
& INSN_WRITE_FPR_D
)
2047 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FD
) & OP_MASK_FD
);
2048 if ((pinfo
& (INSN_WRITE_FPR_S
| INSN_READ_FPR_S
)) != 0)
2049 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FS
) & OP_MASK_FS
);
2050 if ((pinfo
& (INSN_WRITE_FPR_T
| INSN_READ_FPR_T
)) != 0)
2051 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FT
) & OP_MASK_FT
);
2052 if ((pinfo
& INSN_READ_FPR_R
) != 0)
2053 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FR
) & OP_MASK_FR
);
2054 if (pinfo
& INSN_COP
)
2056 /* We don't keep enough information to sort these cases out.
2057 The itbl support does keep this information however, although
2058 we currently don't support itbl fprmats as part of the cop
2059 instruction. May want to add this support in the future. */
2061 /* Never set the bit for $0, which is always zero. */
2062 mips_gprmask
&= ~1 << 0;
2066 if (pinfo
& (MIPS16_INSN_WRITE_X
| MIPS16_INSN_READ_X
))
2067 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RX
)
2068 & MIPS16OP_MASK_RX
);
2069 if (pinfo
& (MIPS16_INSN_WRITE_Y
| MIPS16_INSN_READ_Y
))
2070 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RY
)
2071 & MIPS16OP_MASK_RY
);
2072 if (pinfo
& MIPS16_INSN_WRITE_Z
)
2073 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RZ
)
2074 & MIPS16OP_MASK_RZ
);
2075 if (pinfo
& (MIPS16_INSN_WRITE_T
| MIPS16_INSN_READ_T
))
2076 mips_gprmask
|= 1 << TREG
;
2077 if (pinfo
& (MIPS16_INSN_WRITE_SP
| MIPS16_INSN_READ_SP
))
2078 mips_gprmask
|= 1 << SP
;
2079 if (pinfo
& (MIPS16_INSN_WRITE_31
| MIPS16_INSN_READ_31
))
2080 mips_gprmask
|= 1 << RA
;
2081 if (pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2082 mips_gprmask
|= 1 << MIPS16OP_EXTRACT_REG32R (ip
->insn_opcode
);
2083 if (pinfo
& MIPS16_INSN_READ_Z
)
2084 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_MOVE32Z
)
2085 & MIPS16OP_MASK_MOVE32Z
);
2086 if (pinfo
& MIPS16_INSN_READ_GPR_X
)
2087 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_REGR32
)
2088 & MIPS16OP_MASK_REGR32
);
2091 if (place
== NULL
&& ! mips_opts
.noreorder
)
2093 /* Filling the branch delay slot is more complex. We try to
2094 switch the branch with the previous instruction, which we can
2095 do if the previous instruction does not set up a condition
2096 that the branch tests and if the branch is not itself the
2097 target of any branch. */
2098 if ((pinfo
& INSN_UNCOND_BRANCH_DELAY
)
2099 || (pinfo
& INSN_COND_BRANCH_DELAY
))
2101 if (mips_optimize
< 2
2102 /* If we have seen .set volatile or .set nomove, don't
2104 || mips_opts
.nomove
!= 0
2105 /* If we had to emit any NOP instructions, then we
2106 already know we can not swap. */
2108 /* If we don't even know the previous insn, we can not
2110 || ! prev_insn_valid
2111 /* If the previous insn is already in a branch delay
2112 slot, then we can not swap. */
2113 || prev_insn_is_delay_slot
2114 /* If the previous previous insn was in a .set
2115 noreorder, we can't swap. Actually, the MIPS
2116 assembler will swap in this situation. However, gcc
2117 configured -with-gnu-as will generate code like
2123 in which we can not swap the bne and INSN. If gcc is
2124 not configured -with-gnu-as, it does not output the
2125 .set pseudo-ops. We don't have to check
2126 prev_insn_unreordered, because prev_insn_valid will
2127 be 0 in that case. We don't want to use
2128 prev_prev_insn_valid, because we do want to be able
2129 to swap at the start of a function. */
2130 || prev_prev_insn_unreordered
2131 /* If the branch is itself the target of a branch, we
2132 can not swap. We cheat on this; all we check for is
2133 whether there is a label on this instruction. If
2134 there are any branches to anything other than a
2135 label, users must use .set noreorder. */
2136 || insn_labels
!= NULL
2137 /* If the previous instruction is in a variant frag, we
2138 can not do the swap. This does not apply to the
2139 mips16, which uses variant frags for different
2141 || (! mips_opts
.mips16
2142 && prev_insn_frag
->fr_type
== rs_machine_dependent
)
2143 /* If the branch reads the condition codes, we don't
2144 even try to swap, because in the sequence
2149 we can not swap, and I don't feel like handling that
2151 || (! mips_opts
.mips16
2152 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2153 && (pinfo
& INSN_READ_COND_CODE
))
2154 /* We can not swap with an instruction that requires a
2155 delay slot, becase the target of the branch might
2156 interfere with that instruction. */
2157 || (! mips_opts
.mips16
2158 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2160 /* Itbl support may require additional care here. */
2161 & (INSN_LOAD_COPROC_DELAY
2162 | INSN_COPROC_MOVE_DELAY
2163 | INSN_WRITE_COND_CODE
)))
2164 || (! (hilo_interlocks
2165 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
2169 || (! mips_opts
.mips16
2171 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))
2172 || (! mips_opts
.mips16
2173 && mips_opts
.isa
== ISA_MIPS1
2174 /* Itbl support may require additional care here. */
2175 && (prev_pinfo
& INSN_COPROC_MEMORY_DELAY
))
2176 /* We can not swap with a branch instruction. */
2178 & (INSN_UNCOND_BRANCH_DELAY
2179 | INSN_COND_BRANCH_DELAY
2180 | INSN_COND_BRANCH_LIKELY
))
2181 /* We do not swap with a trap instruction, since it
2182 complicates trap handlers to have the trap
2183 instruction be in a delay slot. */
2184 || (prev_pinfo
& INSN_TRAP
)
2185 /* If the branch reads a register that the previous
2186 instruction sets, we can not swap. */
2187 || (! mips_opts
.mips16
2188 && (prev_pinfo
& INSN_WRITE_GPR_T
)
2189 && insn_uses_reg (ip
,
2190 ((prev_insn
.insn_opcode
>> OP_SH_RT
)
2193 || (! mips_opts
.mips16
2194 && (prev_pinfo
& INSN_WRITE_GPR_D
)
2195 && insn_uses_reg (ip
,
2196 ((prev_insn
.insn_opcode
>> OP_SH_RD
)
2199 || (mips_opts
.mips16
2200 && (((prev_pinfo
& MIPS16_INSN_WRITE_X
)
2201 && insn_uses_reg (ip
,
2202 ((prev_insn
.insn_opcode
2204 & MIPS16OP_MASK_RX
),
2206 || ((prev_pinfo
& MIPS16_INSN_WRITE_Y
)
2207 && insn_uses_reg (ip
,
2208 ((prev_insn
.insn_opcode
2210 & MIPS16OP_MASK_RY
),
2212 || ((prev_pinfo
& MIPS16_INSN_WRITE_Z
)
2213 && insn_uses_reg (ip
,
2214 ((prev_insn
.insn_opcode
2216 & MIPS16OP_MASK_RZ
),
2218 || ((prev_pinfo
& MIPS16_INSN_WRITE_T
)
2219 && insn_uses_reg (ip
, TREG
, MIPS_GR_REG
))
2220 || ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
2221 && insn_uses_reg (ip
, RA
, MIPS_GR_REG
))
2222 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2223 && insn_uses_reg (ip
,
2224 MIPS16OP_EXTRACT_REG32R (prev_insn
.
2227 /* If the branch writes a register that the previous
2228 instruction sets, we can not swap (we know that
2229 branches write only to RD or to $31). */
2230 || (! mips_opts
.mips16
2231 && (prev_pinfo
& INSN_WRITE_GPR_T
)
2232 && (((pinfo
& INSN_WRITE_GPR_D
)
2233 && (((prev_insn
.insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
)
2234 == ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)))
2235 || ((pinfo
& INSN_WRITE_GPR_31
)
2236 && (((prev_insn
.insn_opcode
>> OP_SH_RT
)
2239 || (! mips_opts
.mips16
2240 && (prev_pinfo
& INSN_WRITE_GPR_D
)
2241 && (((pinfo
& INSN_WRITE_GPR_D
)
2242 && (((prev_insn
.insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)
2243 == ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)))
2244 || ((pinfo
& INSN_WRITE_GPR_31
)
2245 && (((prev_insn
.insn_opcode
>> OP_SH_RD
)
2248 || (mips_opts
.mips16
2249 && (pinfo
& MIPS16_INSN_WRITE_31
)
2250 && ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
2251 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2252 && (MIPS16OP_EXTRACT_REG32R (prev_insn
.insn_opcode
)
2254 /* If the branch writes a register that the previous
2255 instruction reads, we can not swap (we know that
2256 branches only write to RD or to $31). */
2257 || (! mips_opts
.mips16
2258 && (pinfo
& INSN_WRITE_GPR_D
)
2259 && insn_uses_reg (&prev_insn
,
2260 ((ip
->insn_opcode
>> OP_SH_RD
)
2263 || (! mips_opts
.mips16
2264 && (pinfo
& INSN_WRITE_GPR_31
)
2265 && insn_uses_reg (&prev_insn
, RA
, MIPS_GR_REG
))
2266 || (mips_opts
.mips16
2267 && (pinfo
& MIPS16_INSN_WRITE_31
)
2268 && insn_uses_reg (&prev_insn
, RA
, MIPS_GR_REG
))
2269 /* If we are generating embedded PIC code, the branch
2270 might be expanded into a sequence which uses $at, so
2271 we can't swap with an instruction which reads it. */
2272 || (mips_pic
== EMBEDDED_PIC
2273 && insn_uses_reg (&prev_insn
, AT
, MIPS_GR_REG
))
2274 /* If the previous previous instruction has a load
2275 delay, and sets a register that the branch reads, we
2277 || (! mips_opts
.mips16
2278 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2279 /* Itbl support may require additional care here. */
2280 && ((prev_prev_insn
.insn_mo
->pinfo
& INSN_LOAD_COPROC_DELAY
)
2281 || (! gpr_interlocks
2282 && (prev_prev_insn
.insn_mo
->pinfo
2283 & INSN_LOAD_MEMORY_DELAY
)))
2284 && insn_uses_reg (ip
,
2285 ((prev_prev_insn
.insn_opcode
>> OP_SH_RT
)
2288 /* If one instruction sets a condition code and the
2289 other one uses a condition code, we can not swap. */
2290 || ((pinfo
& INSN_READ_COND_CODE
)
2291 && (prev_pinfo
& INSN_WRITE_COND_CODE
))
2292 || ((pinfo
& INSN_WRITE_COND_CODE
)
2293 && (prev_pinfo
& INSN_READ_COND_CODE
))
2294 /* If the previous instruction uses the PC, we can not
2296 || (mips_opts
.mips16
2297 && (prev_pinfo
& MIPS16_INSN_READ_PC
))
2298 /* If the previous instruction was extended, we can not
2300 || (mips_opts
.mips16
&& prev_insn_extended
)
2301 /* If the previous instruction had a fixup in mips16
2302 mode, we can not swap. This normally means that the
2303 previous instruction was a 4 byte branch anyhow. */
2304 || (mips_opts
.mips16
&& prev_insn_fixp
[0])
2305 /* If the previous instruction is a sync, sync.l, or
2306 sync.p, we can not swap. */
2307 || (prev_pinfo
& INSN_SYNC
))
2309 /* We could do even better for unconditional branches to
2310 portions of this object file; we could pick up the
2311 instruction at the destination, put it in the delay
2312 slot, and bump the destination address. */
2314 /* Update the previous insn information. */
2315 prev_prev_insn
= *ip
;
2316 prev_insn
.insn_mo
= &dummy_opcode
;
2320 /* It looks like we can actually do the swap. */
2321 if (! mips_opts
.mips16
)
2326 prev_f
= prev_insn_frag
->fr_literal
+ prev_insn_where
;
2327 memcpy (temp
, prev_f
, 4);
2328 memcpy (prev_f
, f
, 4);
2329 memcpy (f
, temp
, 4);
2330 if (prev_insn_fixp
[0])
2332 prev_insn_fixp
[0]->fx_frag
= frag_now
;
2333 prev_insn_fixp
[0]->fx_where
= f
- frag_now
->fr_literal
;
2335 if (prev_insn_fixp
[1])
2337 prev_insn_fixp
[1]->fx_frag
= frag_now
;
2338 prev_insn_fixp
[1]->fx_where
= f
- frag_now
->fr_literal
;
2340 if (prev_insn_fixp
[2])
2342 prev_insn_fixp
[2]->fx_frag
= frag_now
;
2343 prev_insn_fixp
[2]->fx_where
= f
- frag_now
->fr_literal
;
2347 fixp
[0]->fx_frag
= prev_insn_frag
;
2348 fixp
[0]->fx_where
= prev_insn_where
;
2352 fixp
[1]->fx_frag
= prev_insn_frag
;
2353 fixp
[1]->fx_where
= prev_insn_where
;
2357 fixp
[2]->fx_frag
= prev_insn_frag
;
2358 fixp
[2]->fx_where
= prev_insn_where
;
2366 assert (prev_insn_fixp
[0] == NULL
);
2367 assert (prev_insn_fixp
[1] == NULL
);
2368 assert (prev_insn_fixp
[2] == NULL
);
2369 prev_f
= prev_insn_frag
->fr_literal
+ prev_insn_where
;
2370 memcpy (temp
, prev_f
, 2);
2371 memcpy (prev_f
, f
, 2);
2372 if (*reloc_type
!= BFD_RELOC_MIPS16_JMP
)
2374 assert (*reloc_type
== BFD_RELOC_UNUSED
);
2375 memcpy (f
, temp
, 2);
2379 memcpy (f
, f
+ 2, 2);
2380 memcpy (f
+ 2, temp
, 2);
2384 fixp
[0]->fx_frag
= prev_insn_frag
;
2385 fixp
[0]->fx_where
= prev_insn_where
;
2389 fixp
[1]->fx_frag
= prev_insn_frag
;
2390 fixp
[1]->fx_where
= prev_insn_where
;
2394 fixp
[2]->fx_frag
= prev_insn_frag
;
2395 fixp
[2]->fx_where
= prev_insn_where
;
2399 /* Update the previous insn information; leave prev_insn
2401 prev_prev_insn
= *ip
;
2403 prev_insn_is_delay_slot
= 1;
2405 /* If that was an unconditional branch, forget the previous
2406 insn information. */
2407 if (pinfo
& INSN_UNCOND_BRANCH_DELAY
)
2409 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2410 prev_insn
.insn_mo
= &dummy_opcode
;
2413 prev_insn_fixp
[0] = NULL
;
2414 prev_insn_fixp
[1] = NULL
;
2415 prev_insn_fixp
[2] = NULL
;
2416 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2417 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2418 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2419 prev_insn_extended
= 0;
2421 else if (pinfo
& INSN_COND_BRANCH_LIKELY
)
2423 /* We don't yet optimize a branch likely. What we should do
2424 is look at the target, copy the instruction found there
2425 into the delay slot, and increment the branch to jump to
2426 the next instruction. */
2428 /* Update the previous insn information. */
2429 prev_prev_insn
= *ip
;
2430 prev_insn
.insn_mo
= &dummy_opcode
;
2431 prev_insn_fixp
[0] = NULL
;
2432 prev_insn_fixp
[1] = NULL
;
2433 prev_insn_fixp
[2] = NULL
;
2434 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2435 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2436 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2437 prev_insn_extended
= 0;
2441 /* Update the previous insn information. */
2443 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2445 prev_prev_insn
= prev_insn
;
2448 /* Any time we see a branch, we always fill the delay slot
2449 immediately; since this insn is not a branch, we know it
2450 is not in a delay slot. */
2451 prev_insn_is_delay_slot
= 0;
2453 prev_insn_fixp
[0] = fixp
[0];
2454 prev_insn_fixp
[1] = fixp
[1];
2455 prev_insn_fixp
[2] = fixp
[2];
2456 prev_insn_reloc_type
[0] = reloc_type
[0];
2457 prev_insn_reloc_type
[1] = reloc_type
[1];
2458 prev_insn_reloc_type
[2] = reloc_type
[2];
2459 if (mips_opts
.mips16
)
2460 prev_insn_extended
= (ip
->use_extend
2461 || *reloc_type
> BFD_RELOC_UNUSED
);
2464 prev_prev_insn_unreordered
= prev_insn_unreordered
;
2465 prev_insn_unreordered
= 0;
2466 prev_insn_frag
= frag_now
;
2467 prev_insn_where
= f
- frag_now
->fr_literal
;
2468 prev_insn_valid
= 1;
2470 else if (place
== NULL
)
2472 /* We need to record a bit of information even when we are not
2473 reordering, in order to determine the base address for mips16
2474 PC relative relocs. */
2475 prev_prev_insn
= prev_insn
;
2477 prev_insn_reloc_type
[0] = reloc_type
[0];
2478 prev_insn_reloc_type
[1] = reloc_type
[1];
2479 prev_insn_reloc_type
[2] = reloc_type
[2];
2480 prev_prev_insn_unreordered
= prev_insn_unreordered
;
2481 prev_insn_unreordered
= 1;
2484 /* We just output an insn, so the next one doesn't have a label. */
2485 mips_clear_insn_labels ();
2487 /* We must ensure that a fixup associated with an unmatched %hi
2488 reloc does not become a variant frag. Otherwise, the
2489 rearrangement of %hi relocs in frob_file may confuse
2493 frag_wane (frag_now
);
2498 /* This function forgets that there was any previous instruction or
2499 label. If PRESERVE is non-zero, it remembers enough information to
2500 know whether nops are needed before a noreorder section. */
2503 mips_no_prev_insn (preserve
)
2508 prev_insn
.insn_mo
= &dummy_opcode
;
2509 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2510 prev_nop_frag
= NULL
;
2511 prev_nop_frag_holds
= 0;
2512 prev_nop_frag_required
= 0;
2513 prev_nop_frag_since
= 0;
2515 prev_insn_valid
= 0;
2516 prev_insn_is_delay_slot
= 0;
2517 prev_insn_unreordered
= 0;
2518 prev_insn_extended
= 0;
2519 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2520 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2521 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2522 prev_prev_insn_unreordered
= 0;
2523 mips_clear_insn_labels ();
2526 /* This function must be called whenever we turn on noreorder or emit
2527 something other than instructions. It inserts any NOPS which might
2528 be needed by the previous instruction, and clears the information
2529 kept for the previous instructions. The INSNS parameter is true if
2530 instructions are to follow. */
2533 mips_emit_delays (insns
)
2536 if (! mips_opts
.noreorder
)
2541 if ((! mips_opts
.mips16
2542 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2543 && (! cop_interlocks
2544 && (prev_insn
.insn_mo
->pinfo
2545 & (INSN_LOAD_COPROC_DELAY
2546 | INSN_COPROC_MOVE_DELAY
2547 | INSN_WRITE_COND_CODE
))))
2548 || (! hilo_interlocks
2549 && (prev_insn
.insn_mo
->pinfo
2552 || (! mips_opts
.mips16
2554 && (prev_insn
.insn_mo
->pinfo
2555 & INSN_LOAD_MEMORY_DELAY
))
2556 || (! mips_opts
.mips16
2557 && mips_opts
.isa
== ISA_MIPS1
2558 && (prev_insn
.insn_mo
->pinfo
2559 & INSN_COPROC_MEMORY_DELAY
)))
2561 /* Itbl support may require additional care here. */
2563 if ((! mips_opts
.mips16
2564 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2565 && (! cop_interlocks
2566 && prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
))
2567 || (! hilo_interlocks
2568 && ((prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
2569 || (prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
))))
2572 if (prev_insn_unreordered
)
2575 else if ((! mips_opts
.mips16
2576 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2577 && (! cop_interlocks
2578 && prev_prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
))
2579 || (! hilo_interlocks
2580 && ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
2581 || (prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
))))
2583 /* Itbl support may require additional care here. */
2584 if (! prev_prev_insn_unreordered
)
2590 struct insn_label_list
*l
;
2594 /* Record the frag which holds the nop instructions, so
2595 that we can remove them if we don't need them. */
2596 frag_grow (mips_opts
.mips16
? nops
* 2 : nops
* 4);
2597 prev_nop_frag
= frag_now
;
2598 prev_nop_frag_holds
= nops
;
2599 prev_nop_frag_required
= 0;
2600 prev_nop_frag_since
= 0;
2603 for (; nops
> 0; --nops
)
2608 /* Move on to a new frag, so that it is safe to simply
2609 decrease the size of prev_nop_frag. */
2610 frag_wane (frag_now
);
2614 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
2618 assert (S_GET_SEGMENT (l
->label
) == now_seg
);
2619 symbol_set_frag (l
->label
, frag_now
);
2620 val
= (valueT
) frag_now_fix ();
2621 /* mips16 text labels are stored as odd. */
2622 if (mips_opts
.mips16
)
2624 S_SET_VALUE (l
->label
, val
);
2629 /* Mark instruction labels in mips16 mode. */
2631 mips16_mark_labels ();
2633 mips_no_prev_insn (insns
);
2636 /* Build an instruction created by a macro expansion. This is passed
2637 a pointer to the count of instructions created so far, an
2638 expression, the name of the instruction to build, an operand format
2639 string, and corresponding arguments. */
2643 macro_build (char *place
,
2651 macro_build (place
, counter
, ep
, name
, fmt
, va_alist
)
2660 struct mips_cl_insn insn
;
2661 bfd_reloc_code_real_type r
[3];
2665 va_start (args
, fmt
);
2671 * If the macro is about to expand into a second instruction,
2672 * print a warning if needed. We need to pass ip as a parameter
2673 * to generate a better warning message here...
2675 if (mips_opts
.warn_about_macros
&& place
== NULL
&& *counter
== 1)
2676 as_warn (_("Macro instruction expanded into multiple instructions"));
2679 * If the macro is about to expand into a second instruction,
2680 * and it is in a delay slot, print a warning.
2684 && mips_opts
.noreorder
2685 && (prev_prev_insn
.insn_mo
->pinfo
2686 & (INSN_UNCOND_BRANCH_DELAY
| INSN_COND_BRANCH_DELAY
2687 | INSN_COND_BRANCH_LIKELY
)) != 0)
2688 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2691 ++*counter
; /* bump instruction counter */
2693 if (mips_opts
.mips16
)
2695 mips16_macro_build (place
, counter
, ep
, name
, fmt
, args
);
2700 r
[0] = BFD_RELOC_UNUSED
;
2701 r
[1] = BFD_RELOC_UNUSED
;
2702 r
[2] = BFD_RELOC_UNUSED
;
2703 insn
.insn_mo
= (struct mips_opcode
*) hash_find (op_hash
, name
);
2704 assert (insn
.insn_mo
);
2705 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
2707 /* Search until we get a match for NAME. */
2710 /* It is assumed here that macros will never generate
2711 MDMX or MIPS-3D instructions. */
2712 if (strcmp (fmt
, insn
.insn_mo
->args
) == 0
2713 && insn
.insn_mo
->pinfo
!= INSN_MACRO
2714 && OPCODE_IS_MEMBER (insn
.insn_mo
,
2716 | (mips_opts
.mips16
? INSN_MIPS16
: 0)),
2718 && (mips_arch
!= CPU_R4650
|| (insn
.insn_mo
->pinfo
& FP_D
) == 0))
2722 assert (insn
.insn_mo
->name
);
2723 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
2726 insn
.insn_opcode
= insn
.insn_mo
->match
;
2742 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RT
;
2746 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE
;
2751 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FT
;
2756 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RD
;
2761 int tmp
= va_arg (args
, int);
2763 insn
.insn_opcode
|= tmp
<< OP_SH_RT
;
2764 insn
.insn_opcode
|= tmp
<< OP_SH_RD
;
2770 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FS
;
2777 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_SHAMT
;
2781 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FD
;
2785 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE20
;
2789 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE19
;
2793 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE2
;
2800 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RS
;
2806 *r
= (bfd_reloc_code_real_type
) va_arg (args
, int);
2807 assert (*r
== BFD_RELOC_GPREL16
2808 || *r
== BFD_RELOC_MIPS_LITERAL
2809 || *r
== BFD_RELOC_MIPS_HIGHER
2810 || *r
== BFD_RELOC_HI16_S
2811 || *r
== BFD_RELOC_LO16
2812 || *r
== BFD_RELOC_MIPS_GOT16
2813 || *r
== BFD_RELOC_MIPS_CALL16
2814 || *r
== BFD_RELOC_MIPS_GOT_DISP
2815 || *r
== BFD_RELOC_MIPS_GOT_PAGE
2816 || *r
== BFD_RELOC_MIPS_GOT_OFST
2817 || *r
== BFD_RELOC_MIPS_GOT_LO16
2818 || *r
== BFD_RELOC_MIPS_CALL_LO16
2819 || (ep
->X_op
== O_subtract
2820 && *r
== BFD_RELOC_PCREL_LO16
));
2824 *r
= (bfd_reloc_code_real_type
) va_arg (args
, int);
2826 && (ep
->X_op
== O_constant
2827 || (ep
->X_op
== O_symbol
2828 && (*r
== BFD_RELOC_MIPS_HIGHEST
2829 || *r
== BFD_RELOC_HI16_S
2830 || *r
== BFD_RELOC_HI16
2831 || *r
== BFD_RELOC_GPREL16
2832 || *r
== BFD_RELOC_MIPS_GOT_HI16
2833 || *r
== BFD_RELOC_MIPS_CALL_HI16
))
2834 || (ep
->X_op
== O_subtract
2835 && *r
== BFD_RELOC_PCREL_HI16_S
)));
2839 assert (ep
!= NULL
);
2841 * This allows macro() to pass an immediate expression for
2842 * creating short branches without creating a symbol.
2843 * Note that the expression still might come from the assembly
2844 * input, in which case the value is not checked for range nor
2845 * is a relocation entry generated (yuck).
2847 if (ep
->X_op
== O_constant
)
2849 insn
.insn_opcode
|= (ep
->X_add_number
>> 2) & 0xffff;
2853 if (mips_pic
== EMBEDDED_PIC
)
2854 *r
= BFD_RELOC_16_PCREL_S2
;
2856 *r
= BFD_RELOC_16_PCREL
;
2860 assert (ep
!= NULL
);
2861 *r
= BFD_RELOC_MIPS_JMP
;
2865 insn
.insn_opcode
|= va_arg (args
, unsigned long);
2874 assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
2876 append_insn (place
, &insn
, ep
, r
, false);
2880 mips16_macro_build (place
, counter
, ep
, name
, fmt
, args
)
2882 int *counter ATTRIBUTE_UNUSED
;
2888 struct mips_cl_insn insn
;
2889 bfd_reloc_code_real_type r
[3]
2890 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
2892 insn
.insn_mo
= (struct mips_opcode
*) hash_find (mips16_op_hash
, name
);
2893 assert (insn
.insn_mo
);
2894 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
2896 while (strcmp (fmt
, insn
.insn_mo
->args
) != 0
2897 || insn
.insn_mo
->pinfo
== INSN_MACRO
)
2900 assert (insn
.insn_mo
->name
);
2901 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
2904 insn
.insn_opcode
= insn
.insn_mo
->match
;
2905 insn
.use_extend
= false;
2924 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RY
;
2929 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RX
;
2933 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RZ
;
2937 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_MOVE32Z
;
2947 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_REGR32
;
2954 regno
= va_arg (args
, int);
2955 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
2956 insn
.insn_opcode
|= regno
<< MIPS16OP_SH_REG32R
;
2977 assert (ep
!= NULL
);
2979 if (ep
->X_op
!= O_constant
)
2980 *r
= (int) BFD_RELOC_UNUSED
+ c
;
2983 mips16_immed (NULL
, 0, c
, ep
->X_add_number
, false, false,
2984 false, &insn
.insn_opcode
, &insn
.use_extend
,
2987 *r
= BFD_RELOC_UNUSED
;
2993 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_IMM6
;
3000 assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3002 append_insn (place
, &insn
, ep
, r
, false);
3006 * Generate a "jalr" instruction with a relocation hint to the called
3007 * function. This occurs in NewABI PIC code.
3010 macro_build_jalr (icnt
, ep
)
3021 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "jalr", "d,s",
3024 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
,
3025 0, ep
, false, BFD_RELOC_MIPS_JALR
);
3029 * Generate a "lui" instruction.
3032 macro_build_lui (place
, counter
, ep
, regnum
)
3038 expressionS high_expr
;
3039 struct mips_cl_insn insn
;
3040 bfd_reloc_code_real_type r
[3]
3041 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3042 const char *name
= "lui";
3043 const char *fmt
= "t,u";
3045 assert (! mips_opts
.mips16
);
3051 high_expr
.X_op
= O_constant
;
3052 high_expr
.X_add_number
= ep
->X_add_number
;
3055 if (high_expr
.X_op
== O_constant
)
3057 /* we can compute the instruction now without a relocation entry */
3058 high_expr
.X_add_number
= ((high_expr
.X_add_number
+ 0x8000)
3060 *r
= BFD_RELOC_UNUSED
;
3062 else if (! HAVE_NEWABI
)
3064 assert (ep
->X_op
== O_symbol
);
3065 /* _gp_disp is a special case, used from s_cpload. */
3066 assert (mips_pic
== NO_PIC
3067 || strcmp (S_GET_NAME (ep
->X_add_symbol
), "_gp_disp") == 0);
3068 *r
= BFD_RELOC_HI16_S
;
3072 * If the macro is about to expand into a second instruction,
3073 * print a warning if needed. We need to pass ip as a parameter
3074 * to generate a better warning message here...
3076 if (mips_opts
.warn_about_macros
&& place
== NULL
&& *counter
== 1)
3077 as_warn (_("Macro instruction expanded into multiple instructions"));
3080 ++*counter
; /* bump instruction counter */
3082 insn
.insn_mo
= (struct mips_opcode
*) hash_find (op_hash
, name
);
3083 assert (insn
.insn_mo
);
3084 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
3085 assert (strcmp (fmt
, insn
.insn_mo
->args
) == 0);
3087 insn
.insn_opcode
= insn
.insn_mo
->match
| (regnum
<< OP_SH_RT
);
3088 if (*r
== BFD_RELOC_UNUSED
)
3090 insn
.insn_opcode
|= high_expr
.X_add_number
;
3091 append_insn (place
, &insn
, NULL
, r
, false);
3094 append_insn (place
, &insn
, &high_expr
, r
, false);
3098 * Generates code to set the $at register to true (one)
3099 * if reg is less than the immediate expression.
3102 set_at (counter
, reg
, unsignedp
)
3107 if (imm_expr
.X_op
== O_constant
3108 && imm_expr
.X_add_number
>= -0x8000
3109 && imm_expr
.X_add_number
< 0x8000)
3110 macro_build ((char *) NULL
, counter
, &imm_expr
,
3111 unsignedp
? "sltiu" : "slti",
3112 "t,r,j", AT
, reg
, (int) BFD_RELOC_LO16
);
3115 load_register (counter
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
3116 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3117 unsignedp
? "sltu" : "slt",
3118 "d,v,t", AT
, reg
, AT
);
3122 /* Warn if an expression is not a constant. */
3125 check_absolute_expr (ip
, ex
)
3126 struct mips_cl_insn
*ip
;
3129 if (ex
->X_op
== O_big
)
3130 as_bad (_("unsupported large constant"));
3131 else if (ex
->X_op
!= O_constant
)
3132 as_bad (_("Instruction %s requires absolute expression"), ip
->insn_mo
->name
);
3135 /* Count the leading zeroes by performing a binary chop. This is a
3136 bulky bit of source, but performance is a LOT better for the
3137 majority of values than a simple loop to count the bits:
3138 for (lcnt = 0; (lcnt < 32); lcnt++)
3139 if ((v) & (1 << (31 - lcnt)))
3141 However it is not code size friendly, and the gain will drop a bit
3142 on certain cached systems.
3144 #define COUNT_TOP_ZEROES(v) \
3145 (((v) & ~0xffff) == 0 \
3146 ? ((v) & ~0xff) == 0 \
3147 ? ((v) & ~0xf) == 0 \
3148 ? ((v) & ~0x3) == 0 \
3149 ? ((v) & ~0x1) == 0 \
3154 : ((v) & ~0x7) == 0 \
3157 : ((v) & ~0x3f) == 0 \
3158 ? ((v) & ~0x1f) == 0 \
3161 : ((v) & ~0x7f) == 0 \
3164 : ((v) & ~0xfff) == 0 \
3165 ? ((v) & ~0x3ff) == 0 \
3166 ? ((v) & ~0x1ff) == 0 \
3169 : ((v) & ~0x7ff) == 0 \
3172 : ((v) & ~0x3fff) == 0 \
3173 ? ((v) & ~0x1fff) == 0 \
3176 : ((v) & ~0x7fff) == 0 \
3179 : ((v) & ~0xffffff) == 0 \
3180 ? ((v) & ~0xfffff) == 0 \
3181 ? ((v) & ~0x3ffff) == 0 \
3182 ? ((v) & ~0x1ffff) == 0 \
3185 : ((v) & ~0x7ffff) == 0 \
3188 : ((v) & ~0x3fffff) == 0 \
3189 ? ((v) & ~0x1fffff) == 0 \
3192 : ((v) & ~0x7fffff) == 0 \
3195 : ((v) & ~0xfffffff) == 0 \
3196 ? ((v) & ~0x3ffffff) == 0 \
3197 ? ((v) & ~0x1ffffff) == 0 \
3200 : ((v) & ~0x7ffffff) == 0 \
3203 : ((v) & ~0x3fffffff) == 0 \
3204 ? ((v) & ~0x1fffffff) == 0 \
3207 : ((v) & ~0x7fffffff) == 0 \
3211 /* Is the given value a sign-extended 32-bit value? */
3212 #define IS_SEXT_32BIT_NUM(x) \
3213 (((x) &~ (offsetT) 0x7fffffff) == 0 \
3214 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
3217 * This routine generates the least number of instructions neccessary to load
3218 * an absolute expression value into a register.
3221 load_register (counter
, reg
, ep
, dbl
)
3228 expressionS hi32
, lo32
;
3230 if (ep
->X_op
!= O_big
)
3232 assert (ep
->X_op
== O_constant
);
3233 if (ep
->X_add_number
< 0x8000
3234 && (ep
->X_add_number
>= 0
3235 || (ep
->X_add_number
>= -0x8000
3238 || sizeof (ep
->X_add_number
) > 4))))
3240 /* We can handle 16 bit signed values with an addiu to
3241 $zero. No need to ever use daddiu here, since $zero and
3242 the result are always correct in 32 bit mode. */
3243 macro_build ((char *) NULL
, counter
, ep
, "addiu", "t,r,j", reg
, 0,
3244 (int) BFD_RELOC_LO16
);
3247 else if (ep
->X_add_number
>= 0 && ep
->X_add_number
< 0x10000)
3249 /* We can handle 16 bit unsigned values with an ori to
3251 macro_build ((char *) NULL
, counter
, ep
, "ori", "t,r,i", reg
, 0,
3252 (int) BFD_RELOC_LO16
);
3255 else if ((IS_SEXT_32BIT_NUM (ep
->X_add_number
)
3258 || sizeof (ep
->X_add_number
) > 4
3259 || (ep
->X_add_number
& 0x80000000) == 0))
3260 || ((HAVE_32BIT_GPRS
|| ! dbl
)
3261 && (ep
->X_add_number
&~ (offsetT
) 0xffffffff) == 0)
3264 && ((ep
->X_add_number
&~ (offsetT
) 0xffffffff)
3265 == ~ (offsetT
) 0xffffffff)))
3267 /* 32 bit values require an lui. */
3268 macro_build ((char *) NULL
, counter
, ep
, "lui", "t,u", reg
,
3269 (int) BFD_RELOC_HI16
);
3270 if ((ep
->X_add_number
& 0xffff) != 0)
3271 macro_build ((char *) NULL
, counter
, ep
, "ori", "t,r,i", reg
, reg
,
3272 (int) BFD_RELOC_LO16
);
3277 /* The value is larger than 32 bits. */
3279 if (HAVE_32BIT_GPRS
)
3281 as_bad (_("Number (0x%lx) larger than 32 bits"),
3282 (unsigned long) ep
->X_add_number
);
3283 macro_build ((char *) NULL
, counter
, ep
, "addiu", "t,r,j", reg
, 0,
3284 (int) BFD_RELOC_LO16
);
3288 if (ep
->X_op
!= O_big
)
3291 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
3292 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
3293 hi32
.X_add_number
&= 0xffffffff;
3295 lo32
.X_add_number
&= 0xffffffff;
3299 assert (ep
->X_add_number
> 2);
3300 if (ep
->X_add_number
== 3)
3301 generic_bignum
[3] = 0;
3302 else if (ep
->X_add_number
> 4)
3303 as_bad (_("Number larger than 64 bits"));
3304 lo32
.X_op
= O_constant
;
3305 lo32
.X_add_number
= generic_bignum
[0] + (generic_bignum
[1] << 16);
3306 hi32
.X_op
= O_constant
;
3307 hi32
.X_add_number
= generic_bignum
[2] + (generic_bignum
[3] << 16);
3310 if (hi32
.X_add_number
== 0)
3315 unsigned long hi
, lo
;
3317 if (hi32
.X_add_number
== (offsetT
) 0xffffffff)
3319 if ((lo32
.X_add_number
& 0xffff8000) == 0xffff8000)
3321 macro_build ((char *) NULL
, counter
, &lo32
, "addiu", "t,r,j",
3322 reg
, 0, (int) BFD_RELOC_LO16
);
3325 if (lo32
.X_add_number
& 0x80000000)
3327 macro_build ((char *) NULL
, counter
, &lo32
, "lui", "t,u", reg
,
3328 (int) BFD_RELOC_HI16
);
3329 if (lo32
.X_add_number
& 0xffff)
3330 macro_build ((char *) NULL
, counter
, &lo32
, "ori", "t,r,i",
3331 reg
, reg
, (int) BFD_RELOC_LO16
);
3336 /* Check for 16bit shifted constant. We know that hi32 is
3337 non-zero, so start the mask on the first bit of the hi32
3342 unsigned long himask
, lomask
;
3346 himask
= 0xffff >> (32 - shift
);
3347 lomask
= (0xffff << shift
) & 0xffffffff;
3351 himask
= 0xffff << (shift
- 32);
3354 if ((hi32
.X_add_number
& ~(offsetT
) himask
) == 0
3355 && (lo32
.X_add_number
& ~(offsetT
) lomask
) == 0)
3359 tmp
.X_op
= O_constant
;
3361 tmp
.X_add_number
= ((hi32
.X_add_number
<< (32 - shift
))
3362 | (lo32
.X_add_number
>> shift
));
3364 tmp
.X_add_number
= hi32
.X_add_number
>> (shift
- 32);
3365 macro_build ((char *) NULL
, counter
, &tmp
,
3366 "ori", "t,r,i", reg
, 0,
3367 (int) BFD_RELOC_LO16
);
3368 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3369 (shift
>= 32) ? "dsll32" : "dsll",
3371 (shift
>= 32) ? shift
- 32 : shift
);
3376 while (shift
<= (64 - 16));
3378 /* Find the bit number of the lowest one bit, and store the
3379 shifted value in hi/lo. */
3380 hi
= (unsigned long) (hi32
.X_add_number
& 0xffffffff);
3381 lo
= (unsigned long) (lo32
.X_add_number
& 0xffffffff);
3385 while ((lo
& 1) == 0)
3390 lo
|= (hi
& (((unsigned long) 1 << bit
) - 1)) << (32 - bit
);
3396 while ((hi
& 1) == 0)
3405 /* Optimize if the shifted value is a (power of 2) - 1. */
3406 if ((hi
== 0 && ((lo
+ 1) & lo
) == 0)
3407 || (lo
== 0xffffffff && ((hi
+ 1) & hi
) == 0))
3409 shift
= COUNT_TOP_ZEROES ((unsigned int) hi32
.X_add_number
);
3414 /* This instruction will set the register to be all
3416 tmp
.X_op
= O_constant
;
3417 tmp
.X_add_number
= (offsetT
) -1;
3418 macro_build ((char *) NULL
, counter
, &tmp
, "addiu", "t,r,j",
3419 reg
, 0, (int) BFD_RELOC_LO16
);
3423 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3424 (bit
>= 32) ? "dsll32" : "dsll",
3426 (bit
>= 32) ? bit
- 32 : bit
);
3428 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3429 (shift
>= 32) ? "dsrl32" : "dsrl",
3431 (shift
>= 32) ? shift
- 32 : shift
);
3436 /* Sign extend hi32 before calling load_register, because we can
3437 generally get better code when we load a sign extended value. */
3438 if ((hi32
.X_add_number
& 0x80000000) != 0)
3439 hi32
.X_add_number
|= ~(offsetT
) 0xffffffff;
3440 load_register (counter
, reg
, &hi32
, 0);
3443 if ((lo32
.X_add_number
& 0xffff0000) == 0)
3447 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3448 "dsll32", "d,w,<", reg
, freg
, 0);
3456 if ((freg
== 0) && (lo32
.X_add_number
== (offsetT
) 0xffffffff))
3458 macro_build ((char *) NULL
, counter
, &lo32
, "lui", "t,u", reg
,
3459 (int) BFD_RELOC_HI16
);
3460 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3461 "dsrl32", "d,w,<", reg
, reg
, 0);
3467 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
, "dsll",
3468 "d,w,<", reg
, freg
, 16);
3472 mid16
.X_add_number
>>= 16;
3473 macro_build ((char *) NULL
, counter
, &mid16
, "ori", "t,r,i", reg
,
3474 freg
, (int) BFD_RELOC_LO16
);
3475 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
, "dsll",
3476 "d,w,<", reg
, reg
, 16);
3479 if ((lo32
.X_add_number
& 0xffff) != 0)
3480 macro_build ((char *) NULL
, counter
, &lo32
, "ori", "t,r,i", reg
, freg
,
3481 (int) BFD_RELOC_LO16
);
3484 /* Load an address into a register. */
3487 load_address (counter
, reg
, ep
, used_at
)
3495 if (ep
->X_op
!= O_constant
3496 && ep
->X_op
!= O_symbol
)
3498 as_bad (_("expression too complex"));
3499 ep
->X_op
= O_constant
;
3502 if (ep
->X_op
== O_constant
)
3504 load_register (counter
, reg
, ep
, HAVE_64BIT_ADDRESSES
);
3508 if (mips_pic
== NO_PIC
)
3510 /* If this is a reference to a GP relative symbol, we want
3511 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3513 lui $reg,<sym> (BFD_RELOC_HI16_S)
3514 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3515 If we have an addend, we always use the latter form.
3517 With 64bit address space and a usable $at we want
3518 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3519 lui $at,<sym> (BFD_RELOC_HI16_S)
3520 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3521 daddiu $at,<sym> (BFD_RELOC_LO16)
3525 If $at is already in use, we use an path which is suboptimal
3526 on superscalar processors.
3527 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3528 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3530 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3532 daddiu $reg,<sym> (BFD_RELOC_LO16)
3534 if (HAVE_64BIT_ADDRESSES
)
3536 /* We don't do GP optimization for now because RELAX_ENCODE can't
3537 hold the data for such large chunks. */
3539 if (*used_at
== 0 && ! mips_opts
.noat
)
3541 macro_build (p
, counter
, ep
, "lui", "t,u",
3542 reg
, (int) BFD_RELOC_MIPS_HIGHEST
);
3543 macro_build (p
, counter
, ep
, "lui", "t,u",
3544 AT
, (int) BFD_RELOC_HI16_S
);
3545 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3546 reg
, reg
, (int) BFD_RELOC_MIPS_HIGHER
);
3547 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3548 AT
, AT
, (int) BFD_RELOC_LO16
);
3549 macro_build (p
, counter
, (expressionS
*) NULL
, "dsll32",
3550 "d,w,<", reg
, reg
, 0);
3551 macro_build (p
, counter
, (expressionS
*) NULL
, "daddu",
3552 "d,v,t", reg
, reg
, AT
);
3557 macro_build (p
, counter
, ep
, "lui", "t,u",
3558 reg
, (int) BFD_RELOC_MIPS_HIGHEST
);
3559 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3560 reg
, reg
, (int) BFD_RELOC_MIPS_HIGHER
);
3561 macro_build (p
, counter
, (expressionS
*) NULL
, "dsll",
3562 "d,w,<", reg
, reg
, 16);
3563 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3564 reg
, reg
, (int) BFD_RELOC_HI16_S
);
3565 macro_build (p
, counter
, (expressionS
*) NULL
, "dsll",
3566 "d,w,<", reg
, reg
, 16);
3567 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3568 reg
, reg
, (int) BFD_RELOC_LO16
);
3573 if ((valueT
) ep
->X_add_number
<= MAX_GPREL_OFFSET
3574 && ! nopic_need_relax (ep
->X_add_symbol
, 1))
3577 macro_build ((char *) NULL
, counter
, ep
,
3578 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu", "t,r,j",
3579 reg
, mips_gp_register
, (int) BFD_RELOC_GPREL16
);
3580 p
= frag_var (rs_machine_dependent
, 8, 0,
3581 RELAX_ENCODE (4, 8, 0, 4, 0,
3582 mips_opts
.warn_about_macros
),
3583 ep
->X_add_symbol
, 0, NULL
);
3585 macro_build_lui (p
, counter
, ep
, reg
);
3588 macro_build (p
, counter
, ep
,
3589 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3590 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3593 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
3597 /* If this is a reference to an external symbol, we want
3598 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3600 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3602 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3603 If there is a constant, it must be added in after. */
3604 ex
.X_add_number
= ep
->X_add_number
;
3605 ep
->X_add_number
= 0;
3607 macro_build ((char *) NULL
, counter
, ep
,
3608 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)",
3609 reg
, (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
3610 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
, "nop", "");
3611 p
= frag_var (rs_machine_dependent
, 4, 0,
3612 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts
.warn_about_macros
),
3613 ep
->X_add_symbol
, (offsetT
) 0, (char *) NULL
);
3614 macro_build (p
, counter
, ep
,
3615 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3616 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3617 if (ex
.X_add_number
!= 0)
3619 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
3620 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3621 ex
.X_op
= O_constant
;
3622 macro_build ((char *) NULL
, counter
, &ex
,
3623 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3624 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3627 else if (mips_pic
== SVR4_PIC
)
3632 /* This is the large GOT case. If this is a reference to an
3633 external symbol, we want
3634 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3636 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3637 Otherwise, for a reference to a local symbol, we want
3638 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3640 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3641 If we have NewABI, we want
3642 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3643 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3644 If there is a constant, it must be added in after. */
3645 ex
.X_add_number
= ep
->X_add_number
;
3646 ep
->X_add_number
= 0;
3649 macro_build ((char *) NULL
, counter
, ep
,
3650 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", reg
,
3651 (int) BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
3652 macro_build (p
, counter
, ep
,
3653 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu", "t,r,j",
3654 reg
, reg
, (int) BFD_RELOC_MIPS_GOT_OFST
);
3658 if (reg_needs_delay (mips_gp_register
))
3663 macro_build ((char *) NULL
, counter
, ep
, "lui", "t,u", reg
,
3664 (int) BFD_RELOC_MIPS_GOT_HI16
);
3665 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3666 HAVE_32BIT_ADDRESSES
? "addu" : "daddu", "d,v,t", reg
,
3667 reg
, mips_gp_register
);
3668 macro_build ((char *) NULL
, counter
, ep
,
3669 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
3670 "t,o(b)", reg
, (int) BFD_RELOC_MIPS_GOT_LO16
, reg
);
3671 p
= frag_var (rs_machine_dependent
, 12 + off
, 0,
3672 RELAX_ENCODE (12, 12 + off
, off
, 8 + off
, 0,
3673 mips_opts
.warn_about_macros
),
3674 ep
->X_add_symbol
, 0, NULL
);
3677 /* We need a nop before loading from $gp. This special
3678 check is required because the lui which starts the main
3679 instruction stream does not refer to $gp, and so will not
3680 insert the nop which may be required. */
3681 macro_build (p
, counter
, (expressionS
*) NULL
, "nop", "");
3684 macro_build (p
, counter
, ep
,
3685 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", reg
,
3686 (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
3688 macro_build (p
, counter
, (expressionS
*) NULL
, "nop", "");
3690 macro_build (p
, counter
, ep
,
3691 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3692 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3695 if (ex
.X_add_number
!= 0)
3697 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
3698 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3699 ex
.X_op
= O_constant
;
3700 macro_build ((char *) NULL
, counter
, &ex
,
3701 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3702 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3705 else if (mips_pic
== EMBEDDED_PIC
)
3708 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3710 macro_build ((char *) NULL
, counter
, ep
,
3711 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3712 "t,r,j", reg
, mips_gp_register
, (int) BFD_RELOC_GPREL16
);
3718 /* Move the contents of register SOURCE into register DEST. */
3721 move_register (counter
, dest
, source
)
3726 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3727 HAVE_32BIT_GPRS
? "addu" : "daddu",
3728 "d,v,t", dest
, source
, 0);
3733 * This routine implements the seemingly endless macro or synthesized
3734 * instructions and addressing modes in the mips assembly language. Many
3735 * of these macros are simple and are similar to each other. These could
3736 * probably be handled by some kind of table or grammer aproach instead of
3737 * this verbose method. Others are not simple macros but are more like
3738 * optimizing code generation.
3739 * One interesting optimization is when several store macros appear
3740 * consecutivly that would load AT with the upper half of the same address.
3741 * The ensuing load upper instructions are ommited. This implies some kind
3742 * of global optimization. We currently only optimize within a single macro.
3743 * For many of the load and store macros if the address is specified as a
3744 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3745 * first load register 'at' with zero and use it as the base register. The
3746 * mips assembler simply uses register $zero. Just one tiny optimization
3751 struct mips_cl_insn
*ip
;
3753 register int treg
, sreg
, dreg
, breg
;
3769 bfd_reloc_code_real_type r
;
3770 int hold_mips_optimize
;
3772 assert (! mips_opts
.mips16
);
3774 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
3775 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
3776 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
3777 mask
= ip
->insn_mo
->mask
;
3779 expr1
.X_op
= O_constant
;
3780 expr1
.X_op_symbol
= NULL
;
3781 expr1
.X_add_symbol
= NULL
;
3782 expr1
.X_add_number
= 1;
3794 mips_emit_delays (true);
3795 ++mips_opts
.noreorder
;
3796 mips_any_noreorder
= 1;
3798 expr1
.X_add_number
= 8;
3799 macro_build ((char *) NULL
, &icnt
, &expr1
, "bgez", "s,p", sreg
);
3801 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "",
3804 move_register (&icnt
, dreg
, sreg
);
3805 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
3806 dbl
? "dsub" : "sub", "d,v,t", dreg
, 0, sreg
);
3808 --mips_opts
.noreorder
;
3829 if (imm_expr
.X_op
== O_constant
3830 && imm_expr
.X_add_number
>= -0x8000
3831 && imm_expr
.X_add_number
< 0x8000)
3833 macro_build ((char *) NULL
, &icnt
, &imm_expr
, s
, "t,r,j", treg
, sreg
,
3834 (int) BFD_RELOC_LO16
);
3837 load_register (&icnt
, AT
, &imm_expr
, dbl
);
3838 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "d,v,t",
3858 if (imm_expr
.X_op
== O_constant
3859 && imm_expr
.X_add_number
>= 0
3860 && imm_expr
.X_add_number
< 0x10000)
3862 if (mask
!= M_NOR_I
)
3863 macro_build ((char *) NULL
, &icnt
, &imm_expr
, s
, "t,r,i", treg
,
3864 sreg
, (int) BFD_RELOC_LO16
);
3867 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "ori", "t,r,i",
3868 treg
, sreg
, (int) BFD_RELOC_LO16
);
3869 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nor",
3870 "d,v,t", treg
, treg
, 0);
3875 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
3876 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "d,v,t",
3894 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
3896 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "s,t,p", sreg
,
3900 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
3901 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "s,t,p", sreg
, AT
);
3909 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
3910 likely
? "bgezl" : "bgez", "s,p", sreg
);
3915 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
3916 likely
? "blezl" : "blez", "s,p", treg
);
3919 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
3921 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
3922 likely
? "beql" : "beq", "s,t,p", AT
, 0);
3928 /* check for > max integer */
3929 maxnum
= 0x7fffffff;
3930 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
3937 if (imm_expr
.X_op
== O_constant
3938 && imm_expr
.X_add_number
>= maxnum
3939 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
3942 /* result is always false */
3946 as_warn (_("Branch %s is always false (nop)"),
3948 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop",
3954 as_warn (_("Branch likely %s is always false"),
3956 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "bnel",
3961 if (imm_expr
.X_op
!= O_constant
)
3962 as_bad (_("Unsupported large constant"));
3963 ++imm_expr
.X_add_number
;
3967 if (mask
== M_BGEL_I
)
3969 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
3971 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
3972 likely
? "bgezl" : "bgez", "s,p", sreg
);
3975 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
3977 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
3978 likely
? "bgtzl" : "bgtz", "s,p", sreg
);
3981 maxnum
= 0x7fffffff;
3982 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
3989 maxnum
= - maxnum
- 1;
3990 if (imm_expr
.X_op
== O_constant
3991 && imm_expr
.X_add_number
<= maxnum
3992 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
3995 /* result is always true */
3996 as_warn (_("Branch %s is always true"), ip
->insn_mo
->name
);
3997 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "b", "p");
4000 set_at (&icnt
, sreg
, 0);
4001 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4002 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4012 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4013 likely
? "beql" : "beq", "s,t,p", 0, treg
);
4016 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
4017 "d,v,t", AT
, sreg
, treg
);
4018 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4019 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4027 && imm_expr
.X_op
== O_constant
4028 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
4030 if (imm_expr
.X_op
!= O_constant
)
4031 as_bad (_("Unsupported large constant"));
4032 ++imm_expr
.X_add_number
;
4036 if (mask
== M_BGEUL_I
)
4038 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4040 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4042 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4043 likely
? "bnel" : "bne", "s,t,p", sreg
, 0);
4046 set_at (&icnt
, sreg
, 1);
4047 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4048 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4056 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4057 likely
? "bgtzl" : "bgtz", "s,p", sreg
);
4062 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4063 likely
? "bltzl" : "bltz", "s,p", treg
);
4066 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
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
? "bnel" : "bne", "s,t,p", sreg
, 0);
4083 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
4084 "d,v,t", AT
, treg
, sreg
);
4085 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4086 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4094 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4095 likely
? "blezl" : "blez", "s,p", sreg
);
4100 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4101 likely
? "bgezl" : "bgez", "s,p", treg
);
4104 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
4106 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4107 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4113 maxnum
= 0x7fffffff;
4114 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4121 if (imm_expr
.X_op
== O_constant
4122 && imm_expr
.X_add_number
>= maxnum
4123 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4125 if (imm_expr
.X_op
!= O_constant
)
4126 as_bad (_("Unsupported large constant"));
4127 ++imm_expr
.X_add_number
;
4131 if (mask
== M_BLTL_I
)
4133 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4135 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4136 likely
? "bltzl" : "bltz", "s,p", sreg
);
4139 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4141 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4142 likely
? "blezl" : "blez", "s,p", sreg
);
4145 set_at (&icnt
, sreg
, 0);
4146 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4147 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4155 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4156 likely
? "beql" : "beq", "s,t,p", sreg
, 0);
4161 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
4162 "d,v,t", AT
, treg
, sreg
);
4163 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4164 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4172 && imm_expr
.X_op
== O_constant
4173 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
4175 if (imm_expr
.X_op
!= O_constant
)
4176 as_bad (_("Unsupported large constant"));
4177 ++imm_expr
.X_add_number
;
4181 if (mask
== M_BLTUL_I
)
4183 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4185 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4187 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4188 likely
? "beql" : "beq",
4192 set_at (&icnt
, sreg
, 1);
4193 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4194 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4202 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4203 likely
? "bltzl" : "bltz", "s,p", sreg
);
4208 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4209 likely
? "bgtzl" : "bgtz", "s,p", treg
);
4212 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
4214 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4215 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4225 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4226 likely
? "bnel" : "bne", "s,t,p", 0, treg
);
4229 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
4232 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4233 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4248 as_warn (_("Divide by zero."));
4250 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4253 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4258 mips_emit_delays (true);
4259 ++mips_opts
.noreorder
;
4260 mips_any_noreorder
= 1;
4263 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4264 "s,t,q", treg
, 0, 7);
4265 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4266 dbl
? "ddiv" : "div", "z,s,t", sreg
, treg
);
4270 expr1
.X_add_number
= 8;
4271 macro_build ((char *) NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, 0);
4272 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4273 dbl
? "ddiv" : "div", "z,s,t", sreg
, treg
);
4274 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4277 expr1
.X_add_number
= -1;
4278 macro_build ((char *) NULL
, &icnt
, &expr1
,
4279 dbl
? "daddiu" : "addiu",
4280 "t,r,j", AT
, 0, (int) BFD_RELOC_LO16
);
4281 expr1
.X_add_number
= mips_trap
? (dbl
? 12 : 8) : (dbl
? 20 : 16);
4282 macro_build ((char *) NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, AT
);
4285 expr1
.X_add_number
= 1;
4286 macro_build ((char *) NULL
, &icnt
, &expr1
, "daddiu", "t,r,j", AT
, 0,
4287 (int) BFD_RELOC_LO16
);
4288 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsll32",
4289 "d,w,<", AT
, AT
, 31);
4293 expr1
.X_add_number
= 0x80000000;
4294 macro_build ((char *) NULL
, &icnt
, &expr1
, "lui", "t,u", AT
,
4295 (int) BFD_RELOC_HI16
);
4299 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4300 "s,t,q", sreg
, AT
, 6);
4301 /* We want to close the noreorder block as soon as possible, so
4302 that later insns are available for delay slot filling. */
4303 --mips_opts
.noreorder
;
4307 expr1
.X_add_number
= 8;
4308 macro_build ((char *) NULL
, &icnt
, &expr1
, "bne", "s,t,p", sreg
, AT
);
4309 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "",
4312 /* We want to close the noreorder block as soon as possible, so
4313 that later insns are available for delay slot filling. */
4314 --mips_opts
.noreorder
;
4316 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4319 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d", dreg
);
4358 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4360 as_warn (_("Divide by zero."));
4362 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4365 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4369 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4371 if (strcmp (s2
, "mflo") == 0)
4372 move_register (&icnt
, dreg
, sreg
);
4374 move_register (&icnt
, dreg
, 0);
4377 if (imm_expr
.X_op
== O_constant
4378 && imm_expr
.X_add_number
== -1
4379 && s
[strlen (s
) - 1] != 'u')
4381 if (strcmp (s2
, "mflo") == 0)
4383 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4384 dbl
? "dneg" : "neg", "d,w", dreg
, sreg
);
4387 move_register (&icnt
, dreg
, 0);
4391 load_register (&icnt
, AT
, &imm_expr
, dbl
);
4392 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "z,s,t",
4394 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "d", dreg
);
4413 mips_emit_delays (true);
4414 ++mips_opts
.noreorder
;
4415 mips_any_noreorder
= 1;
4418 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4419 "s,t,q", treg
, 0, 7);
4420 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "z,s,t",
4422 /* We want to close the noreorder block as soon as possible, so
4423 that later insns are available for delay slot filling. */
4424 --mips_opts
.noreorder
;
4428 expr1
.X_add_number
= 8;
4429 macro_build ((char *) NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, 0);
4430 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "z,s,t",
4433 /* We want to close the noreorder block as soon as possible, so
4434 that later insns are available for delay slot filling. */
4435 --mips_opts
.noreorder
;
4436 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4439 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "d", dreg
);
4445 /* Load the address of a symbol into a register. If breg is not
4446 zero, we then add a base register to it. */
4448 if (dbl
&& HAVE_32BIT_GPRS
)
4449 as_warn (_("dla used to load 32-bit register"));
4451 if (! dbl
&& HAVE_64BIT_OBJECTS
)
4452 as_warn (_("la used to load 64-bit address"));
4454 if (offset_expr
.X_op
== O_constant
4455 && offset_expr
.X_add_number
>= -0x8000
4456 && offset_expr
.X_add_number
< 0x8000)
4458 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4459 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddiu" : "addiu",
4460 "t,r,j", treg
, sreg
, (int) BFD_RELOC_LO16
);
4475 /* When generating embedded PIC code, we permit expressions of
4478 la $treg,foo-bar($breg)
4479 where bar is an address in the current section. These are used
4480 when getting the addresses of functions. We don't permit
4481 X_add_number to be non-zero, because if the symbol is
4482 external the relaxing code needs to know that any addend is
4483 purely the offset to X_op_symbol. */
4484 if (mips_pic
== EMBEDDED_PIC
4485 && offset_expr
.X_op
== O_subtract
4486 && (symbol_constant_p (offset_expr
.X_op_symbol
)
4487 ? S_GET_SEGMENT (offset_expr
.X_op_symbol
) == now_seg
4488 : (symbol_equated_p (offset_expr
.X_op_symbol
)
4490 (symbol_get_value_expression (offset_expr
.X_op_symbol
)
4493 && (offset_expr
.X_add_number
== 0
4494 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
))
4500 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
4501 tempreg
, (int) BFD_RELOC_PCREL_HI16_S
);
4505 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
4506 tempreg
, (int) BFD_RELOC_PCREL_HI16_S
);
4507 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4508 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddu" : "addu",
4509 "d,v,t", tempreg
, tempreg
, breg
);
4511 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4512 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddiu" : "addiu",
4513 "t,r,j", treg
, tempreg
, (int) BFD_RELOC_PCREL_LO16
);
4519 if (offset_expr
.X_op
!= O_symbol
4520 && offset_expr
.X_op
!= O_constant
)
4522 as_bad (_("expression too complex"));
4523 offset_expr
.X_op
= O_constant
;
4526 if (offset_expr
.X_op
== O_constant
)
4527 load_register (&icnt
, tempreg
, &offset_expr
,
4528 ((mips_pic
== EMBEDDED_PIC
|| mips_pic
== NO_PIC
)
4529 ? (dbl
|| HAVE_64BIT_ADDRESSES
)
4530 : HAVE_64BIT_ADDRESSES
));
4531 else if (mips_pic
== NO_PIC
)
4533 /* If this is a reference to a GP relative symbol, we want
4534 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4536 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4537 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4538 If we have a constant, we need two instructions anyhow,
4539 so we may as well always use the latter form.
4541 With 64bit address space and a usable $at we want
4542 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4543 lui $at,<sym> (BFD_RELOC_HI16_S)
4544 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4545 daddiu $at,<sym> (BFD_RELOC_LO16)
4547 daddu $tempreg,$tempreg,$at
4549 If $at is already in use, we use an path which is suboptimal
4550 on superscalar processors.
4551 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4552 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4554 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4556 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4559 if (HAVE_64BIT_ADDRESSES
)
4561 /* We don't do GP optimization for now because RELAX_ENCODE can't
4562 hold the data for such large chunks. */
4564 if (used_at
== 0 && ! mips_opts
.noat
)
4566 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4567 tempreg
, (int) BFD_RELOC_MIPS_HIGHEST
);
4568 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4569 AT
, (int) BFD_RELOC_HI16_S
);
4570 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4571 tempreg
, tempreg
, (int) BFD_RELOC_MIPS_HIGHER
);
4572 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4573 AT
, AT
, (int) BFD_RELOC_LO16
);
4574 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll32",
4575 "d,w,<", tempreg
, tempreg
, 0);
4576 macro_build (p
, &icnt
, (expressionS
*) NULL
, "daddu",
4577 "d,v,t", tempreg
, tempreg
, AT
);
4582 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4583 tempreg
, (int) BFD_RELOC_MIPS_HIGHEST
);
4584 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4585 tempreg
, tempreg
, (int) BFD_RELOC_MIPS_HIGHER
);
4586 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll", "d,w,<",
4587 tempreg
, tempreg
, 16);
4588 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4589 tempreg
, tempreg
, (int) BFD_RELOC_HI16_S
);
4590 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll", "d,w,<",
4591 tempreg
, tempreg
, 16);
4592 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4593 tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4598 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
4599 && ! nopic_need_relax (offset_expr
.X_add_symbol
, 1))
4602 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "addiu",
4603 "t,r,j", tempreg
, mips_gp_register
,
4604 (int) BFD_RELOC_GPREL16
);
4605 p
= frag_var (rs_machine_dependent
, 8, 0,
4606 RELAX_ENCODE (4, 8, 0, 4, 0,
4607 mips_opts
.warn_about_macros
),
4608 offset_expr
.X_add_symbol
, 0, NULL
);
4610 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
4613 macro_build (p
, &icnt
, &offset_expr
, "addiu",
4614 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4617 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
4619 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
4621 /* If this is a reference to an external symbol, and there
4622 is no constant, we want
4623 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4624 or if tempreg is PIC_CALL_REG
4625 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4626 For a local symbol, we want
4627 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4629 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4631 If we have a small constant, and this is a reference to
4632 an external symbol, we want
4633 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4635 addiu $tempreg,$tempreg,<constant>
4636 For a local symbol, we want the same instruction
4637 sequence, but we output a BFD_RELOC_LO16 reloc on the
4640 If we have a large constant, and this is a reference to
4641 an external symbol, we want
4642 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4643 lui $at,<hiconstant>
4644 addiu $at,$at,<loconstant>
4645 addu $tempreg,$tempreg,$at
4646 For a local symbol, we want the same instruction
4647 sequence, but we output a BFD_RELOC_LO16 reloc on the
4648 addiu instruction. */
4649 expr1
.X_add_number
= offset_expr
.X_add_number
;
4650 offset_expr
.X_add_number
= 0;
4652 if (expr1
.X_add_number
== 0 && tempreg
== PIC_CALL_REG
)
4653 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL16
;
4654 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4655 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
4656 "t,o(b)", tempreg
, lw_reloc_type
, mips_gp_register
);
4657 if (expr1
.X_add_number
== 0)
4666 /* We're going to put in an addu instruction using
4667 tempreg, so we may as well insert the nop right
4669 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4673 p
= frag_var (rs_machine_dependent
, 8 - off
, 0,
4674 RELAX_ENCODE (0, 8 - off
, -4 - off
, 4 - off
, 0,
4676 ? mips_opts
.warn_about_macros
4678 offset_expr
.X_add_symbol
, 0, NULL
);
4681 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
4684 macro_build (p
, &icnt
, &expr1
,
4685 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4686 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4687 /* FIXME: If breg == 0, and the next instruction uses
4688 $tempreg, then if this variant case is used an extra
4689 nop will be generated. */
4691 else if (expr1
.X_add_number
>= -0x8000
4692 && expr1
.X_add_number
< 0x8000)
4694 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4696 macro_build ((char *) NULL
, &icnt
, &expr1
,
4697 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4698 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4699 frag_var (rs_machine_dependent
, 0, 0,
4700 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4701 offset_expr
.X_add_symbol
, 0, NULL
);
4707 /* If we are going to add in a base register, and the
4708 target register and the base register are the same,
4709 then we are using AT as a temporary register. Since
4710 we want to load the constant into AT, we add our
4711 current AT (from the global offset table) and the
4712 register into the register now, and pretend we were
4713 not using a base register. */
4718 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4720 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4721 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4722 "d,v,t", treg
, AT
, breg
);
4728 /* Set mips_optimize around the lui instruction to avoid
4729 inserting an unnecessary nop after the lw. */
4730 hold_mips_optimize
= mips_optimize
;
4732 macro_build_lui (NULL
, &icnt
, &expr1
, AT
);
4733 mips_optimize
= hold_mips_optimize
;
4735 macro_build ((char *) NULL
, &icnt
, &expr1
,
4736 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4737 "t,r,j", AT
, AT
, (int) BFD_RELOC_LO16
);
4738 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4739 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4740 "d,v,t", tempreg
, tempreg
, AT
);
4741 frag_var (rs_machine_dependent
, 0, 0,
4742 RELAX_ENCODE (0, 0, -16 + off1
, -8, 0, 0),
4743 offset_expr
.X_add_symbol
, 0, NULL
);
4747 else if (mips_pic
== SVR4_PIC
)
4751 int lui_reloc_type
= (int) BFD_RELOC_MIPS_GOT_HI16
;
4752 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_LO16
;
4754 /* This is the large GOT case. If this is a reference to an
4755 external symbol, and there is no constant, we want
4756 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4757 addu $tempreg,$tempreg,$gp
4758 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4759 or if tempreg is PIC_CALL_REG
4760 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4761 addu $tempreg,$tempreg,$gp
4762 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4763 For a local symbol, we want
4764 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4766 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4768 If we have a small constant, and this is a reference to
4769 an external symbol, we want
4770 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4771 addu $tempreg,$tempreg,$gp
4772 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4774 addiu $tempreg,$tempreg,<constant>
4775 For a local symbol, we want
4776 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4778 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4780 If we have a large constant, and this is a reference to
4781 an external symbol, we want
4782 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4783 addu $tempreg,$tempreg,$gp
4784 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4785 lui $at,<hiconstant>
4786 addiu $at,$at,<loconstant>
4787 addu $tempreg,$tempreg,$at
4788 For a local symbol, we want
4789 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4790 lui $at,<hiconstant>
4791 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4792 addu $tempreg,$tempreg,$at
4794 For NewABI, we want for data addresses
4795 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4796 If tempreg is PIC_CALL_REG pointing to a external symbol, we want
4797 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4801 int reloc_type
= (tempreg
== PIC_CALL_REG
4802 ? BFD_RELOC_MIPS_CALL16
4803 : BFD_RELOC_MIPS_GOT_DISP
);
4805 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4806 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
4807 "t,o(b)", tempreg
, reloc_type
, mips_gp_register
);
4810 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4811 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4812 "d,v,t", treg
, tempreg
, breg
);
4819 expr1
.X_add_number
= offset_expr
.X_add_number
;
4820 offset_expr
.X_add_number
= 0;
4822 if (reg_needs_delay (mips_gp_register
))
4826 if (expr1
.X_add_number
== 0 && tempreg
== PIC_CALL_REG
)
4828 lui_reloc_type
= (int) BFD_RELOC_MIPS_CALL_HI16
;
4829 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL_LO16
;
4831 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
4832 tempreg
, lui_reloc_type
);
4833 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4834 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4835 "d,v,t", tempreg
, tempreg
, mips_gp_register
);
4836 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4837 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
4838 "t,o(b)", tempreg
, lw_reloc_type
, tempreg
);
4839 if (expr1
.X_add_number
== 0)
4847 /* We're going to put in an addu instruction using
4848 tempreg, so we may as well insert the nop right
4850 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4855 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
4856 RELAX_ENCODE (12 + off
, 12 + gpdel
, gpdel
,
4859 ? mips_opts
.warn_about_macros
4861 offset_expr
.X_add_symbol
, 0, NULL
);
4863 else if (expr1
.X_add_number
>= -0x8000
4864 && expr1
.X_add_number
< 0x8000)
4866 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4868 macro_build ((char *) NULL
, &icnt
, &expr1
,
4869 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4870 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4872 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
4873 RELAX_ENCODE (20, 12 + gpdel
, gpdel
, 8 + gpdel
, 0,
4875 ? mips_opts
.warn_about_macros
4877 offset_expr
.X_add_symbol
, 0, NULL
);
4883 /* If we are going to add in a base register, and the
4884 target register and the base register are the same,
4885 then we are using AT as a temporary register. Since
4886 we want to load the constant into AT, we add our
4887 current AT (from the global offset table) and the
4888 register into the register now, and pretend we were
4889 not using a base register. */
4897 assert (tempreg
== AT
);
4898 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4900 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4901 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4902 "d,v,t", treg
, AT
, breg
);
4907 /* Set mips_optimize around the lui instruction to avoid
4908 inserting an unnecessary nop after the lw. */
4909 hold_mips_optimize
= mips_optimize
;
4911 macro_build_lui (NULL
, &icnt
, &expr1
, AT
);
4912 mips_optimize
= hold_mips_optimize
;
4914 macro_build ((char *) NULL
, &icnt
, &expr1
,
4915 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4916 "t,r,j", AT
, AT
, (int) BFD_RELOC_LO16
);
4917 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4918 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4919 "d,v,t", dreg
, dreg
, AT
);
4921 p
= frag_var (rs_machine_dependent
, 16 + gpdel
+ adj
, 0,
4922 RELAX_ENCODE (24 + adj
, 16 + gpdel
+ adj
, gpdel
,
4925 ? mips_opts
.warn_about_macros
4927 offset_expr
.X_add_symbol
, 0, NULL
);
4934 /* This is needed because this instruction uses $gp, but
4935 the first instruction on the main stream does not. */
4936 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
4939 macro_build (p
, &icnt
, &offset_expr
,
4940 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
4941 "t,o(b)", tempreg
, (int) BFD_RELOC_MIPS_GOT16
,
4944 if (expr1
.X_add_number
>= -0x8000
4945 && expr1
.X_add_number
< 0x8000)
4947 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
4949 macro_build (p
, &icnt
, &expr1
,
4950 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4951 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4952 /* FIXME: If add_number is 0, and there was no base
4953 register, the external symbol case ended with a load,
4954 so if the symbol turns out to not be external, and
4955 the next instruction uses tempreg, an unnecessary nop
4956 will be inserted. */
4962 /* We must add in the base register now, as in the
4963 external symbol case. */
4964 assert (tempreg
== AT
);
4965 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
4967 macro_build (p
, &icnt
, (expressionS
*) NULL
,
4968 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4969 "d,v,t", treg
, AT
, breg
);
4972 /* We set breg to 0 because we have arranged to add
4973 it in in both cases. */
4977 macro_build_lui (p
, &icnt
, &expr1
, AT
);
4979 macro_build (p
, &icnt
, &expr1
,
4980 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4981 "t,r,j", AT
, AT
, (int) BFD_RELOC_LO16
);
4983 macro_build (p
, &icnt
, (expressionS
*) NULL
,
4984 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4985 "d,v,t", tempreg
, tempreg
, AT
);
4989 else if (mips_pic
== EMBEDDED_PIC
)
4992 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4994 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4995 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu", "t,r,j",
4996 tempreg
, mips_gp_register
, (int) BFD_RELOC_GPREL16
);
5005 if (mips_pic
== EMBEDDED_PIC
|| mips_pic
== NO_PIC
)
5006 s
= (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddu" : "addu";
5008 s
= HAVE_64BIT_ADDRESSES
? "daddu" : "addu";
5010 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
,
5011 "d,v,t", treg
, tempreg
, breg
);
5020 /* The j instruction may not be used in PIC code, since it
5021 requires an absolute address. We convert it to a b
5023 if (mips_pic
== NO_PIC
)
5024 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "j", "a");
5026 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "b", "p");
5029 /* The jal instructions must be handled as macros because when
5030 generating PIC code they expand to multi-instruction
5031 sequences. Normally they are simple instructions. */
5036 if (mips_pic
== NO_PIC
5037 || mips_pic
== EMBEDDED_PIC
)
5038 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "jalr",
5040 else if (mips_pic
== SVR4_PIC
)
5042 if (sreg
!= PIC_CALL_REG
)
5043 as_warn (_("MIPS PIC call to register other than $25"));
5045 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "jalr",
5049 if (mips_cprestore_offset
< 0)
5050 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5053 if (! mips_frame_reg_valid
)
5055 as_warn (_("No .frame pseudo-op used in PIC code"));
5056 /* Quiet this warning. */
5057 mips_frame_reg_valid
= 1;
5059 if (! mips_cprestore_valid
)
5061 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5062 /* Quiet this warning. */
5063 mips_cprestore_valid
= 1;
5065 expr1
.X_add_number
= mips_cprestore_offset
;
5066 macro_build ((char *) NULL
, &icnt
, &expr1
,
5067 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)",
5068 mips_gp_register
, (int) BFD_RELOC_LO16
,
5079 if (mips_pic
== NO_PIC
)
5080 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "jal", "a");
5081 else if (mips_pic
== SVR4_PIC
)
5085 /* If this is a reference to an external symbol, and we are
5086 using a small GOT, we want
5087 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5091 lw $gp,cprestore($sp)
5092 The cprestore value is set using the .cprestore
5093 pseudo-op. If we are using a big GOT, we want
5094 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5096 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5100 lw $gp,cprestore($sp)
5101 If the symbol is not external, we want
5102 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5104 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5107 lw $gp,cprestore($sp)
5109 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5110 jalr $ra,$25 (BFD_RELOC_MIPS_JALR)
5114 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5115 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5116 "t,o(b)", PIC_CALL_REG
,
5117 (int) BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5118 macro_build_jalr (icnt
, &offset_expr
);
5125 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5126 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5127 "t,o(b)", PIC_CALL_REG
,
5128 (int) BFD_RELOC_MIPS_CALL16
, mips_gp_register
);
5129 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5131 p
= frag_var (rs_machine_dependent
, 4, 0,
5132 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5133 offset_expr
.X_add_symbol
, 0, NULL
);
5139 if (reg_needs_delay (mips_gp_register
))
5143 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui",
5144 "t,u", PIC_CALL_REG
,
5145 (int) BFD_RELOC_MIPS_CALL_HI16
);
5146 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5147 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5148 "d,v,t", PIC_CALL_REG
, PIC_CALL_REG
,
5150 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5151 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5152 "t,o(b)", PIC_CALL_REG
,
5153 (int) BFD_RELOC_MIPS_CALL_LO16
, PIC_CALL_REG
);
5154 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5156 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5157 RELAX_ENCODE (16, 12 + gpdel
, gpdel
,
5159 offset_expr
.X_add_symbol
, 0, NULL
);
5162 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5165 macro_build (p
, &icnt
, &offset_expr
,
5166 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5167 "t,o(b)", PIC_CALL_REG
,
5168 (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
5170 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5173 macro_build (p
, &icnt
, &offset_expr
,
5174 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5175 "t,r,j", PIC_CALL_REG
, PIC_CALL_REG
,
5176 (int) BFD_RELOC_LO16
);
5177 macro_build_jalr (icnt
, &offset_expr
);
5179 if (mips_cprestore_offset
< 0)
5180 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5183 if (! mips_frame_reg_valid
)
5185 as_warn (_("No .frame pseudo-op used in PIC code"));
5186 /* Quiet this warning. */
5187 mips_frame_reg_valid
= 1;
5189 if (! mips_cprestore_valid
)
5191 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5192 /* Quiet this warning. */
5193 mips_cprestore_valid
= 1;
5195 if (mips_opts
.noreorder
)
5196 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5198 expr1
.X_add_number
= mips_cprestore_offset
;
5199 macro_build ((char *) NULL
, &icnt
, &expr1
,
5200 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)",
5201 mips_gp_register
, (int) BFD_RELOC_LO16
,
5206 else if (mips_pic
== EMBEDDED_PIC
)
5208 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "bal", "p");
5209 /* The linker may expand the call to a longer sequence which
5210 uses $at, so we must break rather than return. */
5235 /* Itbl support may require additional care here. */
5240 /* Itbl support may require additional care here. */
5245 /* Itbl support may require additional care here. */
5250 /* Itbl support may require additional care here. */
5262 if (mips_arch
== CPU_R4650
)
5264 as_bad (_("opcode not supported on this processor"));
5268 /* Itbl support may require additional care here. */
5273 /* Itbl support may require additional care here. */
5278 /* Itbl support may require additional care here. */
5298 if (breg
== treg
|| coproc
|| lr
)
5320 /* Itbl support may require additional care here. */
5325 /* Itbl support may require additional care here. */
5330 /* Itbl support may require additional care here. */
5335 /* Itbl support may require additional care here. */
5351 if (mips_arch
== CPU_R4650
)
5353 as_bad (_("opcode not supported on this processor"));
5358 /* Itbl support may require additional care here. */
5362 /* Itbl support may require additional care here. */
5367 /* Itbl support may require additional care here. */
5379 /* Itbl support may require additional care here. */
5380 if (mask
== M_LWC1_AB
5381 || mask
== M_SWC1_AB
5382 || mask
== M_LDC1_AB
5383 || mask
== M_SDC1_AB
5392 /* For embedded PIC, we allow loads where the offset is calculated
5393 by subtracting a symbol in the current segment from an unknown
5394 symbol, relative to a base register, e.g.:
5395 <op> $treg, <sym>-<localsym>($breg)
5396 This is used by the compiler for switch statements. */
5397 if (mips_pic
== EMBEDDED_PIC
5398 && offset_expr
.X_op
== O_subtract
5399 && (symbol_constant_p (offset_expr
.X_op_symbol
)
5400 ? S_GET_SEGMENT (offset_expr
.X_op_symbol
) == now_seg
5401 : (symbol_equated_p (offset_expr
.X_op_symbol
)
5403 (symbol_get_value_expression (offset_expr
.X_op_symbol
)
5407 && (offset_expr
.X_add_number
== 0
5408 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
))
5410 /* For this case, we output the instructions:
5411 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5412 addiu $tempreg,$tempreg,$breg
5413 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5414 If the relocation would fit entirely in 16 bits, it would be
5416 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5417 instead, but that seems quite difficult. */
5418 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5419 tempreg
, (int) BFD_RELOC_PCREL_HI16_S
);
5420 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5421 ((bfd_arch_bits_per_address (stdoutput
) == 32
5422 || ! ISA_HAS_64BIT_REGS (mips_opts
.isa
))
5423 ? "addu" : "daddu"),
5424 "d,v,t", tempreg
, tempreg
, breg
);
5425 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5426 (int) BFD_RELOC_PCREL_LO16
, tempreg
);
5432 if (offset_expr
.X_op
!= O_constant
5433 && offset_expr
.X_op
!= O_symbol
)
5435 as_bad (_("expression too complex"));
5436 offset_expr
.X_op
= O_constant
;
5439 /* A constant expression in PIC code can be handled just as it
5440 is in non PIC code. */
5441 if (mips_pic
== NO_PIC
5442 || offset_expr
.X_op
== O_constant
)
5446 /* If this is a reference to a GP relative symbol, and there
5447 is no base register, we want
5448 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5449 Otherwise, if there is no base register, we want
5450 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5451 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5452 If we have a constant, we need two instructions anyhow,
5453 so we always use the latter form.
5455 If we have a base register, and this is a reference to a
5456 GP relative symbol, we want
5457 addu $tempreg,$breg,$gp
5458 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5460 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5461 addu $tempreg,$tempreg,$breg
5462 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5463 With a constant we always use the latter case.
5465 With 64bit address space and no base register and $at usable,
5467 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5468 lui $at,<sym> (BFD_RELOC_HI16_S)
5469 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5472 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5473 If we have a base register, we want
5474 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5475 lui $at,<sym> (BFD_RELOC_HI16_S)
5476 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5480 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5482 Without $at we can't generate the optimal path for superscalar
5483 processors here since this would require two temporary registers.
5484 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5485 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5487 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5489 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5490 If we have a base register, we want
5491 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5492 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5494 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5496 daddu $tempreg,$tempreg,$breg
5497 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5499 If we have 64-bit addresses, as an optimization, for
5500 addresses which are 32-bit constants (e.g. kseg0/kseg1
5501 addresses) we fall back to the 32-bit address generation
5502 mechanism since it is more efficient. Note that due to
5503 the signed offset used by memory operations, the 32-bit
5504 range is shifted down by 32768 here. This code should
5505 probably attempt to generate 64-bit constants more
5506 efficiently in general.
5508 if (HAVE_64BIT_ADDRESSES
5509 && !(offset_expr
.X_op
== O_constant
5510 && IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
+ 0x8000)))
5514 /* We don't do GP optimization for now because RELAX_ENCODE can't
5515 hold the data for such large chunks. */
5517 if (used_at
== 0 && ! mips_opts
.noat
)
5519 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5520 tempreg
, (int) BFD_RELOC_MIPS_HIGHEST
);
5521 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5522 AT
, (int) BFD_RELOC_HI16_S
);
5523 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5524 tempreg
, tempreg
, (int) BFD_RELOC_MIPS_HIGHER
);
5526 macro_build (p
, &icnt
, (expressionS
*) NULL
, "daddu",
5527 "d,v,t", AT
, AT
, breg
);
5528 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll32",
5529 "d,w,<", tempreg
, tempreg
, 0);
5530 macro_build (p
, &icnt
, (expressionS
*) NULL
, "daddu",
5531 "d,v,t", tempreg
, tempreg
, AT
);
5532 macro_build (p
, &icnt
, &offset_expr
, s
,
5533 fmt
, treg
, (int) BFD_RELOC_LO16
, tempreg
);
5538 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5539 tempreg
, (int) BFD_RELOC_MIPS_HIGHEST
);
5540 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5541 tempreg
, tempreg
, (int) BFD_RELOC_MIPS_HIGHER
);
5542 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll",
5543 "d,w,<", tempreg
, tempreg
, 16);
5544 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5545 tempreg
, tempreg
, (int) BFD_RELOC_HI16_S
);
5546 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll",
5547 "d,w,<", tempreg
, tempreg
, 16);
5549 macro_build (p
, &icnt
, (expressionS
*) NULL
, "daddu",
5550 "d,v,t", tempreg
, tempreg
, breg
);
5551 macro_build (p
, &icnt
, &offset_expr
, s
,
5552 fmt
, treg
, (int) BFD_RELOC_LO16
, tempreg
);
5560 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
5561 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5566 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
5567 treg
, (int) BFD_RELOC_GPREL16
,
5569 p
= frag_var (rs_machine_dependent
, 8, 0,
5570 RELAX_ENCODE (4, 8, 0, 4, 0,
5571 (mips_opts
.warn_about_macros
5573 && mips_opts
.noat
))),
5574 offset_expr
.X_add_symbol
, 0, NULL
);
5577 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
5580 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5581 (int) BFD_RELOC_LO16
, tempreg
);
5585 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
5586 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5591 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5592 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5593 "d,v,t", tempreg
, breg
, mips_gp_register
);
5594 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
5595 treg
, (int) BFD_RELOC_GPREL16
, tempreg
);
5596 p
= frag_var (rs_machine_dependent
, 12, 0,
5597 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5598 offset_expr
.X_add_symbol
, 0, NULL
);
5600 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
5603 macro_build (p
, &icnt
, (expressionS
*) NULL
,
5604 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5605 "d,v,t", tempreg
, tempreg
, breg
);
5608 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5609 (int) BFD_RELOC_LO16
, tempreg
);
5612 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
5616 /* If this is a reference to an external symbol, we want
5617 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5619 <op> $treg,0($tempreg)
5621 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5623 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5624 <op> $treg,0($tempreg)
5625 If there is a base register, we add it to $tempreg before
5626 the <op>. If there is a constant, we stick it in the
5627 <op> instruction. We don't handle constants larger than
5628 16 bits, because we have no way to load the upper 16 bits
5629 (actually, we could handle them for the subset of cases
5630 in which we are not using $at). */
5631 assert (offset_expr
.X_op
== O_symbol
);
5632 expr1
.X_add_number
= offset_expr
.X_add_number
;
5633 offset_expr
.X_add_number
= 0;
5634 if (expr1
.X_add_number
< -0x8000
5635 || expr1
.X_add_number
>= 0x8000)
5636 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5638 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5639 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", tempreg
,
5640 (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
5641 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
5642 p
= frag_var (rs_machine_dependent
, 4, 0,
5643 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5644 offset_expr
.X_add_symbol
, 0, NULL
);
5645 macro_build (p
, &icnt
, &offset_expr
,
5646 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5647 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
5649 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5650 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5651 "d,v,t", tempreg
, tempreg
, breg
);
5652 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
, treg
,
5653 (int) BFD_RELOC_LO16
, tempreg
);
5655 else if (mips_pic
== SVR4_PIC
)
5660 /* If this is a reference to an external symbol, we want
5661 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5662 addu $tempreg,$tempreg,$gp
5663 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5664 <op> $treg,0($tempreg)
5666 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5668 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5669 <op> $treg,0($tempreg)
5670 If there is a base register, we add it to $tempreg before
5671 the <op>. If there is a constant, we stick it in the
5672 <op> instruction. We don't handle constants larger than
5673 16 bits, because we have no way to load the upper 16 bits
5674 (actually, we could handle them for the subset of cases
5675 in which we are not using $at).
5678 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5679 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5680 <op> $treg,0($tempreg)
5682 assert (offset_expr
.X_op
== O_symbol
);
5683 expr1
.X_add_number
= offset_expr
.X_add_number
;
5684 offset_expr
.X_add_number
= 0;
5685 if (expr1
.X_add_number
< -0x8000
5686 || expr1
.X_add_number
>= 0x8000)
5687 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5690 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5691 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5692 "t,o(b)", tempreg
, BFD_RELOC_MIPS_GOT_PAGE
,
5694 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5695 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5696 "t,r,j", tempreg
, tempreg
,
5697 BFD_RELOC_MIPS_GOT_OFST
);
5699 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5700 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5701 "d,v,t", tempreg
, tempreg
, breg
);
5702 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
, treg
,
5703 (int) BFD_RELOC_LO16
, tempreg
);
5710 if (reg_needs_delay (mips_gp_register
))
5715 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5716 tempreg
, (int) BFD_RELOC_MIPS_GOT_HI16
);
5717 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5718 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5719 "d,v,t", tempreg
, tempreg
, mips_gp_register
);
5720 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5721 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5722 "t,o(b)", tempreg
, (int) BFD_RELOC_MIPS_GOT_LO16
,
5724 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5725 RELAX_ENCODE (12, 12 + gpdel
, gpdel
, 8 + gpdel
, 0, 0),
5726 offset_expr
.X_add_symbol
, 0, NULL
);
5729 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5732 macro_build (p
, &icnt
, &offset_expr
,
5733 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5734 "t,o(b)", tempreg
, (int) BFD_RELOC_MIPS_GOT16
,
5737 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5739 macro_build (p
, &icnt
, &offset_expr
,
5740 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5741 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
5743 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5744 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5745 "d,v,t", tempreg
, tempreg
, breg
);
5746 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
, treg
,
5747 (int) BFD_RELOC_LO16
, tempreg
);
5749 else if (mips_pic
== EMBEDDED_PIC
)
5751 /* If there is no base register, we want
5752 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5753 If there is a base register, we want
5754 addu $tempreg,$breg,$gp
5755 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5757 assert (offset_expr
.X_op
== O_symbol
);
5760 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
5761 treg
, (int) BFD_RELOC_GPREL16
, mips_gp_register
);
5766 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5767 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5768 "d,v,t", tempreg
, breg
, mips_gp_register
);
5769 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
5770 treg
, (int) BFD_RELOC_GPREL16
, tempreg
);
5783 load_register (&icnt
, treg
, &imm_expr
, 0);
5787 load_register (&icnt
, treg
, &imm_expr
, 1);
5791 if (imm_expr
.X_op
== O_constant
)
5793 load_register (&icnt
, AT
, &imm_expr
, 0);
5794 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5795 "mtc1", "t,G", AT
, treg
);
5800 assert (offset_expr
.X_op
== O_symbol
5801 && strcmp (segment_name (S_GET_SEGMENT
5802 (offset_expr
.X_add_symbol
)),
5804 && offset_expr
.X_add_number
== 0);
5805 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)",
5806 treg
, (int) BFD_RELOC_MIPS_LITERAL
, mips_gp_register
);
5811 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
5812 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
5813 order 32 bits of the value and the low order 32 bits are either
5814 zero or in OFFSET_EXPR. */
5815 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
5817 if (HAVE_64BIT_GPRS
)
5818 load_register (&icnt
, treg
, &imm_expr
, 1);
5823 if (target_big_endian
)
5835 load_register (&icnt
, hreg
, &imm_expr
, 0);
5838 if (offset_expr
.X_op
== O_absent
)
5839 move_register (&icnt
, lreg
, 0);
5842 assert (offset_expr
.X_op
== O_constant
);
5843 load_register (&icnt
, lreg
, &offset_expr
, 0);
5850 /* We know that sym is in the .rdata section. First we get the
5851 upper 16 bits of the address. */
5852 if (mips_pic
== NO_PIC
)
5854 macro_build_lui (NULL
, &icnt
, &offset_expr
, AT
);
5856 else if (mips_pic
== SVR4_PIC
)
5858 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5859 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5860 "t,o(b)", AT
, (int) BFD_RELOC_MIPS_GOT16
,
5863 else if (mips_pic
== EMBEDDED_PIC
)
5865 /* For embedded PIC we pick up the entire address off $gp in
5866 a single instruction. */
5867 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5868 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu", "t,r,j", AT
,
5869 mips_gp_register
, (int) BFD_RELOC_GPREL16
);
5870 offset_expr
.X_op
= O_constant
;
5871 offset_expr
.X_add_number
= 0;
5876 /* Now we load the register(s). */
5877 if (HAVE_64BIT_GPRS
)
5878 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "ld", "t,o(b)",
5879 treg
, (int) BFD_RELOC_LO16
, AT
);
5882 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lw", "t,o(b)",
5883 treg
, (int) BFD_RELOC_LO16
, AT
);
5886 /* FIXME: How in the world do we deal with the possible
5888 offset_expr
.X_add_number
+= 4;
5889 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lw", "t,o(b)",
5890 treg
+ 1, (int) BFD_RELOC_LO16
, AT
);
5894 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5895 does not become a variant frag. */
5896 frag_wane (frag_now
);
5902 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
5903 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
5904 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
5905 the value and the low order 32 bits are either zero or in
5907 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
5909 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_FPRS
);
5910 if (HAVE_64BIT_FPRS
)
5912 assert (HAVE_64BIT_GPRS
);
5913 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5914 "dmtc1", "t,S", AT
, treg
);
5918 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5919 "mtc1", "t,G", AT
, treg
+ 1);
5920 if (offset_expr
.X_op
== O_absent
)
5921 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5922 "mtc1", "t,G", 0, treg
);
5925 assert (offset_expr
.X_op
== O_constant
);
5926 load_register (&icnt
, AT
, &offset_expr
, 0);
5927 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5928 "mtc1", "t,G", AT
, treg
);
5934 assert (offset_expr
.X_op
== O_symbol
5935 && offset_expr
.X_add_number
== 0);
5936 s
= segment_name (S_GET_SEGMENT (offset_expr
.X_add_symbol
));
5937 if (strcmp (s
, ".lit8") == 0)
5939 if (mips_opts
.isa
!= ISA_MIPS1
)
5941 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "ldc1",
5942 "T,o(b)", treg
, (int) BFD_RELOC_MIPS_LITERAL
,
5946 breg
= mips_gp_register
;
5947 r
= BFD_RELOC_MIPS_LITERAL
;
5952 assert (strcmp (s
, RDATA_SECTION_NAME
) == 0);
5953 if (mips_pic
== SVR4_PIC
)
5954 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5955 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5956 "t,o(b)", AT
, (int) BFD_RELOC_MIPS_GOT16
,
5960 /* FIXME: This won't work for a 64 bit address. */
5961 macro_build_lui (NULL
, &icnt
, &offset_expr
, AT
);
5964 if (mips_opts
.isa
!= ISA_MIPS1
)
5966 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "ldc1",
5967 "T,o(b)", treg
, (int) BFD_RELOC_LO16
, AT
);
5969 /* To avoid confusion in tc_gen_reloc, we must ensure
5970 that this does not become a variant frag. */
5971 frag_wane (frag_now
);
5982 if (mips_arch
== CPU_R4650
)
5984 as_bad (_("opcode not supported on this processor"));
5987 /* Even on a big endian machine $fn comes before $fn+1. We have
5988 to adjust when loading from memory. */
5991 assert (mips_opts
.isa
== ISA_MIPS1
);
5992 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)",
5993 target_big_endian
? treg
+ 1 : treg
,
5995 /* FIXME: A possible overflow which I don't know how to deal
5997 offset_expr
.X_add_number
+= 4;
5998 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)",
5999 target_big_endian
? treg
: treg
+ 1,
6002 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6003 does not become a variant frag. */
6004 frag_wane (frag_now
);
6013 * The MIPS assembler seems to check for X_add_number not
6014 * being double aligned and generating:
6017 * addiu at,at,%lo(foo+1)
6020 * But, the resulting address is the same after relocation so why
6021 * generate the extra instruction?
6023 if (mips_arch
== CPU_R4650
)
6025 as_bad (_("opcode not supported on this processor"));
6028 /* Itbl support may require additional care here. */
6030 if (mips_opts
.isa
!= ISA_MIPS1
)
6041 if (mips_arch
== CPU_R4650
)
6043 as_bad (_("opcode not supported on this processor"));
6047 if (mips_opts
.isa
!= ISA_MIPS1
)
6055 /* Itbl support may require additional care here. */
6060 if (HAVE_64BIT_GPRS
)
6071 if (HAVE_64BIT_GPRS
)
6081 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6082 loads for the case of doing a pair of loads to simulate an 'ld'.
6083 This is not currently done by the compiler, and assembly coders
6084 writing embedded-pic code can cope. */
6086 if (offset_expr
.X_op
!= O_symbol
6087 && offset_expr
.X_op
!= O_constant
)
6089 as_bad (_("expression too complex"));
6090 offset_expr
.X_op
= O_constant
;
6093 /* Even on a big endian machine $fn comes before $fn+1. We have
6094 to adjust when loading from memory. We set coproc if we must
6095 load $fn+1 first. */
6096 /* Itbl support may require additional care here. */
6097 if (! target_big_endian
)
6100 if (mips_pic
== NO_PIC
6101 || offset_expr
.X_op
== O_constant
)
6105 /* If this is a reference to a GP relative symbol, we want
6106 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6107 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6108 If we have a base register, we use this
6110 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6111 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6112 If this is not a GP relative symbol, we want
6113 lui $at,<sym> (BFD_RELOC_HI16_S)
6114 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6115 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6116 If there is a base register, we add it to $at after the
6117 lui instruction. If there is a constant, we always use
6119 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
6120 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6132 tempreg
= mips_gp_register
;
6139 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6140 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6141 "d,v,t", AT
, breg
, mips_gp_register
);
6147 /* Itbl support may require additional care here. */
6148 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6149 coproc
? treg
+ 1 : treg
,
6150 (int) BFD_RELOC_GPREL16
, tempreg
);
6151 offset_expr
.X_add_number
+= 4;
6153 /* Set mips_optimize to 2 to avoid inserting an
6155 hold_mips_optimize
= mips_optimize
;
6157 /* Itbl support may require additional care here. */
6158 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6159 coproc
? treg
: treg
+ 1,
6160 (int) BFD_RELOC_GPREL16
, tempreg
);
6161 mips_optimize
= hold_mips_optimize
;
6163 p
= frag_var (rs_machine_dependent
, 12 + off
, 0,
6164 RELAX_ENCODE (8 + off
, 12 + off
, 0, 4 + off
, 1,
6165 used_at
&& mips_opts
.noat
),
6166 offset_expr
.X_add_symbol
, 0, NULL
);
6168 /* We just generated two relocs. When tc_gen_reloc
6169 handles this case, it will skip the first reloc and
6170 handle the second. The second reloc already has an
6171 extra addend of 4, which we added above. We must
6172 subtract it out, and then subtract another 4 to make
6173 the first reloc come out right. The second reloc
6174 will come out right because we are going to add 4 to
6175 offset_expr when we build its instruction below.
6177 If we have a symbol, then we don't want to include
6178 the offset, because it will wind up being included
6179 when we generate the reloc. */
6181 if (offset_expr
.X_op
== O_constant
)
6182 offset_expr
.X_add_number
-= 8;
6185 offset_expr
.X_add_number
= -4;
6186 offset_expr
.X_op
= O_constant
;
6189 macro_build_lui (p
, &icnt
, &offset_expr
, AT
);
6194 macro_build (p
, &icnt
, (expressionS
*) NULL
,
6195 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6196 "d,v,t", AT
, breg
, AT
);
6200 /* Itbl support may require additional care here. */
6201 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
,
6202 coproc
? treg
+ 1 : treg
,
6203 (int) BFD_RELOC_LO16
, AT
);
6206 /* FIXME: How do we handle overflow here? */
6207 offset_expr
.X_add_number
+= 4;
6208 /* Itbl support may require additional care here. */
6209 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
,
6210 coproc
? treg
: treg
+ 1,
6211 (int) BFD_RELOC_LO16
, AT
);
6213 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
6217 /* If this is a reference to an external symbol, we want
6218 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6223 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6225 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6226 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6227 If there is a base register we add it to $at before the
6228 lwc1 instructions. If there is a constant we include it
6229 in the lwc1 instructions. */
6231 expr1
.X_add_number
= offset_expr
.X_add_number
;
6232 offset_expr
.X_add_number
= 0;
6233 if (expr1
.X_add_number
< -0x8000
6234 || expr1
.X_add_number
>= 0x8000 - 4)
6235 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6240 frag_grow (24 + off
);
6241 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
6242 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", AT
,
6243 (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6244 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
6246 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6247 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6248 "d,v,t", AT
, breg
, AT
);
6249 /* Itbl support may require additional care here. */
6250 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
,
6251 coproc
? treg
+ 1 : treg
,
6252 (int) BFD_RELOC_LO16
, AT
);
6253 expr1
.X_add_number
+= 4;
6255 /* Set mips_optimize to 2 to avoid inserting an undesired
6257 hold_mips_optimize
= mips_optimize
;
6259 /* Itbl support may require additional care here. */
6260 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
,
6261 coproc
? treg
: treg
+ 1,
6262 (int) BFD_RELOC_LO16
, AT
);
6263 mips_optimize
= hold_mips_optimize
;
6265 (void) frag_var (rs_machine_dependent
, 0, 0,
6266 RELAX_ENCODE (0, 0, -16 - off
, -8, 1, 0),
6267 offset_expr
.X_add_symbol
, 0, NULL
);
6269 else if (mips_pic
== SVR4_PIC
)
6274 /* If this is a reference to an external symbol, we want
6275 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6277 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6282 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6284 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6285 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6286 If there is a base register we add it to $at before the
6287 lwc1 instructions. If there is a constant we include it
6288 in the lwc1 instructions. */
6290 expr1
.X_add_number
= offset_expr
.X_add_number
;
6291 offset_expr
.X_add_number
= 0;
6292 if (expr1
.X_add_number
< -0x8000
6293 || expr1
.X_add_number
>= 0x8000 - 4)
6294 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6295 if (reg_needs_delay (mips_gp_register
))
6304 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
6305 AT
, (int) BFD_RELOC_MIPS_GOT_HI16
);
6306 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6307 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6308 "d,v,t", AT
, AT
, mips_gp_register
);
6309 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
6310 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
6311 "t,o(b)", AT
, (int) BFD_RELOC_MIPS_GOT_LO16
, AT
);
6312 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
6314 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6315 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6316 "d,v,t", AT
, breg
, AT
);
6317 /* Itbl support may require additional care here. */
6318 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
,
6319 coproc
? treg
+ 1 : treg
,
6320 (int) BFD_RELOC_LO16
, AT
);
6321 expr1
.X_add_number
+= 4;
6323 /* Set mips_optimize to 2 to avoid inserting an undesired
6325 hold_mips_optimize
= mips_optimize
;
6327 /* Itbl support may require additional care here. */
6328 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
,
6329 coproc
? treg
: treg
+ 1,
6330 (int) BFD_RELOC_LO16
, AT
);
6331 mips_optimize
= hold_mips_optimize
;
6332 expr1
.X_add_number
-= 4;
6334 p
= frag_var (rs_machine_dependent
, 16 + gpdel
+ off
, 0,
6335 RELAX_ENCODE (24 + off
, 16 + gpdel
+ off
, gpdel
,
6336 8 + gpdel
+ off
, 1, 0),
6337 offset_expr
.X_add_symbol
, 0, NULL
);
6340 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
6343 macro_build (p
, &icnt
, &offset_expr
,
6344 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
6345 "t,o(b)", AT
, (int) BFD_RELOC_MIPS_GOT16
,
6348 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
6352 macro_build (p
, &icnt
, (expressionS
*) NULL
,
6353 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6354 "d,v,t", AT
, breg
, AT
);
6357 /* Itbl support may require additional care here. */
6358 macro_build (p
, &icnt
, &expr1
, s
, fmt
,
6359 coproc
? treg
+ 1 : treg
,
6360 (int) BFD_RELOC_LO16
, AT
);
6362 expr1
.X_add_number
+= 4;
6364 /* Set mips_optimize to 2 to avoid inserting an undesired
6366 hold_mips_optimize
= mips_optimize
;
6368 /* Itbl support may require additional care here. */
6369 macro_build (p
, &icnt
, &expr1
, s
, fmt
,
6370 coproc
? treg
: treg
+ 1,
6371 (int) BFD_RELOC_LO16
, AT
);
6372 mips_optimize
= hold_mips_optimize
;
6374 else if (mips_pic
== EMBEDDED_PIC
)
6376 /* If there is no base register, we use
6377 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6378 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6379 If we have a base register, we use
6381 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6382 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6386 tempreg
= mips_gp_register
;
6391 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6392 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6393 "d,v,t", AT
, breg
, mips_gp_register
);
6398 /* Itbl support may require additional care here. */
6399 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6400 coproc
? treg
+ 1 : treg
,
6401 (int) BFD_RELOC_GPREL16
, tempreg
);
6402 offset_expr
.X_add_number
+= 4;
6403 /* Itbl support may require additional care here. */
6404 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6405 coproc
? treg
: treg
+ 1,
6406 (int) BFD_RELOC_GPREL16
, tempreg
);
6422 assert (HAVE_32BIT_ADDRESSES
);
6423 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
6424 (int) BFD_RELOC_LO16
, breg
);
6425 offset_expr
.X_add_number
+= 4;
6426 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
+ 1,
6427 (int) BFD_RELOC_LO16
, breg
);
6430 /* New code added to support COPZ instructions.
6431 This code builds table entries out of the macros in mip_opcodes.
6432 R4000 uses interlocks to handle coproc delays.
6433 Other chips (like the R3000) require nops to be inserted for delays.
6435 FIXME: Currently, we require that the user handle delays.
6436 In order to fill delay slots for non-interlocked chips,
6437 we must have a way to specify delays based on the coprocessor.
6438 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6439 What are the side-effects of the cop instruction?
6440 What cache support might we have and what are its effects?
6441 Both coprocessor & memory require delays. how long???
6442 What registers are read/set/modified?
6444 If an itbl is provided to interpret cop instructions,
6445 this knowledge can be encoded in the itbl spec. */
6459 /* For now we just do C (same as Cz). The parameter will be
6460 stored in insn_opcode by mips_ip. */
6461 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "C",
6466 move_register (&icnt
, dreg
, sreg
);
6469 #ifdef LOSING_COMPILER
6471 /* Try and see if this is a new itbl instruction.
6472 This code builds table entries out of the macros in mip_opcodes.
6473 FIXME: For now we just assemble the expression and pass it's
6474 value along as a 32-bit immediate.
6475 We may want to have the assembler assemble this value,
6476 so that we gain the assembler's knowledge of delay slots,
6478 Would it be more efficient to use mask (id) here? */
6479 if (itbl_have_entries
6480 && (immed_expr
= itbl_assemble (ip
->insn_mo
->name
, "")))
6482 s
= ip
->insn_mo
->name
;
6484 coproc
= ITBL_DECODE_PNUM (immed_expr
);;
6485 macro_build ((char *) NULL
, &icnt
, &immed_expr
, s
, "C");
6492 as_warn (_("Macro used $at after \".set noat\""));
6497 struct mips_cl_insn
*ip
;
6499 register int treg
, sreg
, dreg
, breg
;
6515 bfd_reloc_code_real_type r
;
6518 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
6519 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
6520 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
6521 mask
= ip
->insn_mo
->mask
;
6523 expr1
.X_op
= O_constant
;
6524 expr1
.X_op_symbol
= NULL
;
6525 expr1
.X_add_symbol
= NULL
;
6526 expr1
.X_add_number
= 1;
6530 #endif /* LOSING_COMPILER */
6535 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6536 dbl
? "dmultu" : "multu", "s,t", sreg
, treg
);
6537 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d",
6544 /* The MIPS assembler some times generates shifts and adds. I'm
6545 not trying to be that fancy. GCC should do this for us
6547 load_register (&icnt
, AT
, &imm_expr
, dbl
);
6548 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6549 dbl
? "dmult" : "mult", "s,t", sreg
, AT
);
6550 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d",
6564 mips_emit_delays (true);
6565 ++mips_opts
.noreorder
;
6566 mips_any_noreorder
= 1;
6568 load_register (&icnt
, AT
, &imm_expr
, dbl
);
6569 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6570 dbl
? "dmult" : "mult", "s,t", sreg
, imm
? AT
: treg
);
6571 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d",
6573 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6574 dbl
? "dsra32" : "sra", "d,w,<", dreg
, dreg
, RA
);
6575 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mfhi", "d",
6578 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "tne",
6579 "s,t,q", dreg
, AT
, 6);
6582 expr1
.X_add_number
= 8;
6583 macro_build ((char *) NULL
, &icnt
, &expr1
, "beq", "s,t,p", dreg
,
6585 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "",
6587 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
6590 --mips_opts
.noreorder
;
6591 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d", dreg
);
6604 mips_emit_delays (true);
6605 ++mips_opts
.noreorder
;
6606 mips_any_noreorder
= 1;
6608 load_register (&icnt
, AT
, &imm_expr
, dbl
);
6609 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6610 dbl
? "dmultu" : "multu",
6611 "s,t", sreg
, imm
? AT
: treg
);
6612 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mfhi", "d",
6614 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d",
6617 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "tne",
6621 expr1
.X_add_number
= 8;
6622 macro_build ((char *) NULL
, &icnt
, &expr1
, "beq", "s,t,p", AT
, 0);
6623 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "",
6625 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
6628 --mips_opts
.noreorder
;
6632 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsubu",
6633 "d,v,t", AT
, 0, treg
);
6634 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsrlv",
6635 "d,t,s", AT
, sreg
, AT
);
6636 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsllv",
6637 "d,t,s", dreg
, sreg
, treg
);
6638 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6639 "d,v,t", dreg
, dreg
, AT
);
6643 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "subu",
6644 "d,v,t", AT
, 0, treg
);
6645 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srlv",
6646 "d,t,s", AT
, sreg
, AT
);
6647 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sllv",
6648 "d,t,s", dreg
, sreg
, treg
);
6649 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6650 "d,v,t", dreg
, dreg
, AT
);
6657 if (imm_expr
.X_op
!= O_constant
)
6658 as_bad (_("rotate count too large"));
6659 rot
= imm_expr
.X_add_number
& 0x3f;
6661 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsrl",
6662 "d,w,<", dreg
, sreg
, 0);
6667 l
= (rot
< 0x20) ? "dsll" : "dsll32";
6668 r
= ((0x40 - rot
) < 0x20) ? "dsrl" : "dsrl32";
6670 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, l
,
6671 "d,w,<", AT
, sreg
, rot
);
6672 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, r
,
6673 "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
6674 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6675 "d,v,t", dreg
, dreg
, AT
);
6684 if (imm_expr
.X_op
!= O_constant
)
6685 as_bad (_("rotate count too large"));
6686 rot
= imm_expr
.X_add_number
& 0x1f;
6688 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl",
6689 "d,w,<", dreg
, sreg
, 0);
6692 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll",
6693 "d,w,<", AT
, sreg
, rot
);
6694 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl",
6695 "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
6696 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6697 "d,v,t", dreg
, dreg
, AT
);
6703 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsubu",
6704 "d,v,t", AT
, 0, treg
);
6705 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsllv",
6706 "d,t,s", AT
, sreg
, AT
);
6707 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsrlv",
6708 "d,t,s", dreg
, sreg
, treg
);
6709 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6710 "d,v,t", dreg
, dreg
, AT
);
6714 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "subu",
6715 "d,v,t", AT
, 0, treg
);
6716 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sllv",
6717 "d,t,s", AT
, sreg
, AT
);
6718 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srlv",
6719 "d,t,s", dreg
, sreg
, treg
);
6720 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6721 "d,v,t", dreg
, dreg
, AT
);
6728 if (imm_expr
.X_op
!= O_constant
)
6729 as_bad (_("rotate count too large"));
6730 rot
= imm_expr
.X_add_number
& 0x3f;
6732 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsrl",
6733 "d,w,<", dreg
, sreg
, 0);
6738 r
= (rot
< 0x20) ? "dsrl" : "dsrl32";
6739 l
= ((0x40 - rot
) < 0x20) ? "dsll" : "dsll32";
6741 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, r
,
6742 "d,w,<", AT
, sreg
, rot
);
6743 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, l
,
6744 "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
6745 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6746 "d,v,t", dreg
, dreg
, AT
);
6755 if (imm_expr
.X_op
!= O_constant
)
6756 as_bad (_("rotate count too large"));
6757 rot
= imm_expr
.X_add_number
& 0x1f;
6759 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl",
6760 "d,w,<", dreg
, sreg
, 0);
6763 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl",
6764 "d,w,<", AT
, sreg
, rot
);
6765 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll",
6766 "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
6767 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6768 "d,v,t", dreg
, dreg
, AT
);
6774 if (mips_arch
== CPU_R4650
)
6776 as_bad (_("opcode not supported on this processor"));
6779 assert (mips_opts
.isa
== ISA_MIPS1
);
6780 /* Even on a big endian machine $fn comes before $fn+1. We have
6781 to adjust when storing to memory. */
6782 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "swc1", "T,o(b)",
6783 target_big_endian
? treg
+ 1 : treg
,
6784 (int) BFD_RELOC_LO16
, breg
);
6785 offset_expr
.X_add_number
+= 4;
6786 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "swc1", "T,o(b)",
6787 target_big_endian
? treg
: treg
+ 1,
6788 (int) BFD_RELOC_LO16
, breg
);
6793 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
,
6794 treg
, (int) BFD_RELOC_LO16
);
6796 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
,
6797 sreg
, (int) BFD_RELOC_LO16
);
6800 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "xor",
6801 "d,v,t", dreg
, sreg
, treg
);
6802 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
,
6803 dreg
, (int) BFD_RELOC_LO16
);
6808 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
6810 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
,
6811 sreg
, (int) BFD_RELOC_LO16
);
6816 as_warn (_("Instruction %s: result is always false"),
6818 move_register (&icnt
, dreg
, 0);
6821 if (imm_expr
.X_op
== O_constant
6822 && imm_expr
.X_add_number
>= 0
6823 && imm_expr
.X_add_number
< 0x10000)
6825 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "xori", "t,r,i", dreg
,
6826 sreg
, (int) BFD_RELOC_LO16
);
6829 else if (imm_expr
.X_op
== O_constant
6830 && imm_expr
.X_add_number
> -0x8000
6831 && imm_expr
.X_add_number
< 0)
6833 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
6834 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
6835 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
6836 "t,r,j", dreg
, sreg
,
6837 (int) BFD_RELOC_LO16
);
6842 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
6843 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "xor",
6844 "d,v,t", dreg
, sreg
, AT
);
6847 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
, dreg
,
6848 (int) BFD_RELOC_LO16
);
6853 case M_SGE
: /* sreg >= treg <==> not (sreg < treg) */
6859 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
6861 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
6862 (int) BFD_RELOC_LO16
);
6865 case M_SGE_I
: /* sreg >= I <==> not (sreg < I) */
6867 if (imm_expr
.X_op
== O_constant
6868 && imm_expr
.X_add_number
>= -0x8000
6869 && imm_expr
.X_add_number
< 0x8000)
6871 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
6872 mask
== M_SGE_I
? "slti" : "sltiu",
6873 "t,r,j", dreg
, sreg
, (int) BFD_RELOC_LO16
);
6878 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
6879 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6880 mask
== M_SGE_I
? "slt" : "sltu", "d,v,t", dreg
, sreg
,
6884 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
6885 (int) BFD_RELOC_LO16
);
6890 case M_SGT
: /* sreg > treg <==> treg < sreg */
6896 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
6900 case M_SGT_I
: /* sreg > I <==> I < sreg */
6906 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
6907 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
6911 case M_SLE
: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6917 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
6919 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
6920 (int) BFD_RELOC_LO16
);
6923 case M_SLE_I
: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6929 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
6930 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
6932 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
6933 (int) BFD_RELOC_LO16
);
6937 if (imm_expr
.X_op
== O_constant
6938 && imm_expr
.X_add_number
>= -0x8000
6939 && imm_expr
.X_add_number
< 0x8000)
6941 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "slti", "t,r,j",
6942 dreg
, sreg
, (int) BFD_RELOC_LO16
);
6945 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
6946 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
6951 if (imm_expr
.X_op
== O_constant
6952 && imm_expr
.X_add_number
>= -0x8000
6953 && imm_expr
.X_add_number
< 0x8000)
6955 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "sltiu", "t,r,j",
6956 dreg
, sreg
, (int) BFD_RELOC_LO16
);
6959 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
6960 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
6961 "d,v,t", dreg
, sreg
, AT
);
6966 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
6967 "d,v,t", dreg
, 0, treg
);
6969 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
6970 "d,v,t", dreg
, 0, sreg
);
6973 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "xor",
6974 "d,v,t", dreg
, sreg
, treg
);
6975 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
6976 "d,v,t", dreg
, 0, dreg
);
6981 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
6983 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
6984 "d,v,t", dreg
, 0, sreg
);
6989 as_warn (_("Instruction %s: result is always true"),
6991 macro_build ((char *) NULL
, &icnt
, &expr1
,
6992 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
6993 "t,r,j", dreg
, 0, (int) BFD_RELOC_LO16
);
6996 if (imm_expr
.X_op
== O_constant
6997 && imm_expr
.X_add_number
>= 0
6998 && imm_expr
.X_add_number
< 0x10000)
7000 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "xori", "t,r,i",
7001 dreg
, sreg
, (int) BFD_RELOC_LO16
);
7004 else if (imm_expr
.X_op
== O_constant
7005 && imm_expr
.X_add_number
> -0x8000
7006 && imm_expr
.X_add_number
< 0)
7008 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7009 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7010 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7011 "t,r,j", dreg
, sreg
, (int) BFD_RELOC_LO16
);
7016 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7017 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "xor",
7018 "d,v,t", dreg
, sreg
, AT
);
7021 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
7022 "d,v,t", dreg
, 0, dreg
);
7030 if (imm_expr
.X_op
== O_constant
7031 && imm_expr
.X_add_number
> -0x8000
7032 && imm_expr
.X_add_number
<= 0x8000)
7034 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7035 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7036 dbl
? "daddi" : "addi",
7037 "t,r,j", dreg
, sreg
, (int) BFD_RELOC_LO16
);
7040 load_register (&icnt
, AT
, &imm_expr
, dbl
);
7041 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7042 dbl
? "dsub" : "sub", "d,v,t", dreg
, sreg
, AT
);
7048 if (imm_expr
.X_op
== O_constant
7049 && imm_expr
.X_add_number
> -0x8000
7050 && imm_expr
.X_add_number
<= 0x8000)
7052 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7053 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7054 dbl
? "daddiu" : "addiu",
7055 "t,r,j", dreg
, sreg
, (int) BFD_RELOC_LO16
);
7058 load_register (&icnt
, AT
, &imm_expr
, dbl
);
7059 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7060 dbl
? "dsubu" : "subu", "d,v,t", dreg
, sreg
, AT
);
7081 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7082 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "s,t", sreg
,
7088 assert (mips_opts
.isa
== ISA_MIPS1
);
7089 sreg
= (ip
->insn_opcode
>> 11) & 0x1f; /* floating reg */
7090 dreg
= (ip
->insn_opcode
>> 06) & 0x1f; /* floating reg */
7093 * Is the double cfc1 instruction a bug in the mips assembler;
7094 * or is there a reason for it?
7096 mips_emit_delays (true);
7097 ++mips_opts
.noreorder
;
7098 mips_any_noreorder
= 1;
7099 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "cfc1", "t,G",
7101 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "cfc1", "t,G",
7103 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
7104 expr1
.X_add_number
= 3;
7105 macro_build ((char *) NULL
, &icnt
, &expr1
, "ori", "t,r,i", AT
, treg
,
7106 (int) BFD_RELOC_LO16
);
7107 expr1
.X_add_number
= 2;
7108 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", AT
, AT
,
7109 (int) BFD_RELOC_LO16
);
7110 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "ctc1", "t,G",
7112 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
7113 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7114 mask
== M_TRUNCWD
? "cvt.w.d" : "cvt.w.s", "D,S", dreg
, sreg
);
7115 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "ctc1", "t,G",
7117 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
7118 --mips_opts
.noreorder
;
7127 if (offset_expr
.X_add_number
>= 0x7fff)
7128 as_bad (_("operand overflow"));
7129 /* avoid load delay */
7130 if (! target_big_endian
)
7131 ++offset_expr
.X_add_number
;
7132 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
7133 (int) BFD_RELOC_LO16
, breg
);
7134 if (! target_big_endian
)
7135 --offset_expr
.X_add_number
;
7137 ++offset_expr
.X_add_number
;
7138 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lbu", "t,o(b)", AT
,
7139 (int) BFD_RELOC_LO16
, breg
);
7140 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll", "d,w,<",
7142 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or", "d,v,t",
7156 if (offset_expr
.X_add_number
>= 0x8000 - off
)
7157 as_bad (_("operand overflow"));
7158 if (! target_big_endian
)
7159 offset_expr
.X_add_number
+= off
;
7160 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
7161 (int) BFD_RELOC_LO16
, breg
);
7162 if (! target_big_endian
)
7163 offset_expr
.X_add_number
-= off
;
7165 offset_expr
.X_add_number
+= off
;
7166 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s2
, "t,o(b)", treg
,
7167 (int) BFD_RELOC_LO16
, breg
);
7181 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7183 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7184 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
7185 "d,v,t", AT
, AT
, breg
);
7186 if (! target_big_endian
)
7187 expr1
.X_add_number
= off
;
7189 expr1
.X_add_number
= 0;
7190 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, "t,o(b)", treg
,
7191 (int) BFD_RELOC_LO16
, AT
);
7192 if (! target_big_endian
)
7193 expr1
.X_add_number
= 0;
7195 expr1
.X_add_number
= off
;
7196 macro_build ((char *) NULL
, &icnt
, &expr1
, s2
, "t,o(b)", treg
,
7197 (int) BFD_RELOC_LO16
, AT
);
7203 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7205 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7206 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
7207 "d,v,t", AT
, AT
, breg
);
7208 if (target_big_endian
)
7209 expr1
.X_add_number
= 0;
7210 macro_build ((char *) NULL
, &icnt
, &expr1
,
7211 mask
== M_ULH_A
? "lb" : "lbu", "t,o(b)", treg
,
7212 (int) BFD_RELOC_LO16
, AT
);
7213 if (target_big_endian
)
7214 expr1
.X_add_number
= 1;
7216 expr1
.X_add_number
= 0;
7217 macro_build ((char *) NULL
, &icnt
, &expr1
, "lbu", "t,o(b)", AT
,
7218 (int) BFD_RELOC_LO16
, AT
);
7219 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll", "d,w,<",
7221 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or", "d,v,t",
7226 if (offset_expr
.X_add_number
>= 0x7fff)
7227 as_bad (_("operand overflow"));
7228 if (target_big_endian
)
7229 ++offset_expr
.X_add_number
;
7230 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "sb", "t,o(b)", treg
,
7231 (int) BFD_RELOC_LO16
, breg
);
7232 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl", "d,w,<",
7234 if (target_big_endian
)
7235 --offset_expr
.X_add_number
;
7237 ++offset_expr
.X_add_number
;
7238 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "sb", "t,o(b)", AT
,
7239 (int) BFD_RELOC_LO16
, breg
);
7252 if (offset_expr
.X_add_number
>= 0x8000 - off
)
7253 as_bad (_("operand overflow"));
7254 if (! target_big_endian
)
7255 offset_expr
.X_add_number
+= off
;
7256 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
7257 (int) BFD_RELOC_LO16
, breg
);
7258 if (! target_big_endian
)
7259 offset_expr
.X_add_number
-= off
;
7261 offset_expr
.X_add_number
+= off
;
7262 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s2
, "t,o(b)", treg
,
7263 (int) BFD_RELOC_LO16
, breg
);
7277 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7279 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7280 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
7281 "d,v,t", AT
, AT
, breg
);
7282 if (! target_big_endian
)
7283 expr1
.X_add_number
= off
;
7285 expr1
.X_add_number
= 0;
7286 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, "t,o(b)", treg
,
7287 (int) BFD_RELOC_LO16
, AT
);
7288 if (! target_big_endian
)
7289 expr1
.X_add_number
= 0;
7291 expr1
.X_add_number
= off
;
7292 macro_build ((char *) NULL
, &icnt
, &expr1
, s2
, "t,o(b)", treg
,
7293 (int) BFD_RELOC_LO16
, AT
);
7298 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7300 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7301 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
7302 "d,v,t", AT
, AT
, breg
);
7303 if (! target_big_endian
)
7304 expr1
.X_add_number
= 0;
7305 macro_build ((char *) NULL
, &icnt
, &expr1
, "sb", "t,o(b)", treg
,
7306 (int) BFD_RELOC_LO16
, AT
);
7307 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl", "d,w,<",
7309 if (! target_big_endian
)
7310 expr1
.X_add_number
= 1;
7312 expr1
.X_add_number
= 0;
7313 macro_build ((char *) NULL
, &icnt
, &expr1
, "sb", "t,o(b)", treg
,
7314 (int) BFD_RELOC_LO16
, AT
);
7315 if (! target_big_endian
)
7316 expr1
.X_add_number
= 0;
7318 expr1
.X_add_number
= 1;
7319 macro_build ((char *) NULL
, &icnt
, &expr1
, "lbu", "t,o(b)", AT
,
7320 (int) BFD_RELOC_LO16
, AT
);
7321 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll", "d,w,<",
7323 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or", "d,v,t",
7328 /* FIXME: Check if this is one of the itbl macros, since they
7329 are added dynamically. */
7330 as_bad (_("Macro %s not implemented yet"), ip
->insn_mo
->name
);
7334 as_warn (_("Macro used $at after \".set noat\""));
7337 /* Implement macros in mips16 mode. */
7341 struct mips_cl_insn
*ip
;
7344 int xreg
, yreg
, zreg
, tmp
;
7348 const char *s
, *s2
, *s3
;
7350 mask
= ip
->insn_mo
->mask
;
7352 xreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RX
) & MIPS16OP_MASK_RX
;
7353 yreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RY
) & MIPS16OP_MASK_RY
;
7354 zreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RZ
) & MIPS16OP_MASK_RZ
;
7358 expr1
.X_op
= O_constant
;
7359 expr1
.X_op_symbol
= NULL
;
7360 expr1
.X_add_symbol
= NULL
;
7361 expr1
.X_add_number
= 1;
7380 mips_emit_delays (true);
7381 ++mips_opts
.noreorder
;
7382 mips_any_noreorder
= 1;
7383 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7384 dbl
? "ddiv" : "div",
7385 "0,x,y", xreg
, yreg
);
7386 expr1
.X_add_number
= 2;
7387 macro_build ((char *) NULL
, &icnt
, &expr1
, "bnez", "x,p", yreg
);
7388 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break", "6",
7391 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7392 since that causes an overflow. We should do that as well,
7393 but I don't see how to do the comparisons without a temporary
7395 --mips_opts
.noreorder
;
7396 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "x", zreg
);
7415 mips_emit_delays (true);
7416 ++mips_opts
.noreorder
;
7417 mips_any_noreorder
= 1;
7418 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "0,x,y",
7420 expr1
.X_add_number
= 2;
7421 macro_build ((char *) NULL
, &icnt
, &expr1
, "bnez", "x,p", yreg
);
7422 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
7424 --mips_opts
.noreorder
;
7425 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "x", zreg
);
7431 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7432 dbl
? "dmultu" : "multu", "x,y", xreg
, yreg
);
7433 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "x",
7442 if (imm_expr
.X_op
!= O_constant
)
7443 as_bad (_("Unsupported large constant"));
7444 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7445 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7446 dbl
? "daddiu" : "addiu", "y,x,4", yreg
, xreg
);
7450 if (imm_expr
.X_op
!= O_constant
)
7451 as_bad (_("Unsupported large constant"));
7452 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7453 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "addiu",
7458 if (imm_expr
.X_op
!= O_constant
)
7459 as_bad (_("Unsupported large constant"));
7460 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7461 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "daddiu",
7484 goto do_reverse_branch
;
7488 goto do_reverse_branch
;
7500 goto do_reverse_branch
;
7511 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "x,y",
7513 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s2
, "p");
7540 goto do_addone_branch_i
;
7545 goto do_addone_branch_i
;
7560 goto do_addone_branch_i
;
7567 if (imm_expr
.X_op
!= O_constant
)
7568 as_bad (_("Unsupported large constant"));
7569 ++imm_expr
.X_add_number
;
7572 macro_build ((char *) NULL
, &icnt
, &imm_expr
, s
, s3
, xreg
);
7573 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s2
, "p");
7577 expr1
.X_add_number
= 0;
7578 macro_build ((char *) NULL
, &icnt
, &expr1
, "slti", "x,8", yreg
);
7580 move_register (&icnt
, xreg
, yreg
);
7581 expr1
.X_add_number
= 2;
7582 macro_build ((char *) NULL
, &icnt
, &expr1
, "bteqz", "p");
7583 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7584 "neg", "x,w", xreg
, xreg
);
7588 /* For consistency checking, verify that all bits are specified either
7589 by the match/mask part of the instruction definition, or by the
7592 validate_mips_insn (opc
)
7593 const struct mips_opcode
*opc
;
7595 const char *p
= opc
->args
;
7597 unsigned long used_bits
= opc
->mask
;
7599 if ((used_bits
& opc
->match
) != opc
->match
)
7601 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7602 opc
->name
, opc
->args
);
7605 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7612 case '<': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
7613 case '>': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
7615 case 'B': USE_BITS (OP_MASK_CODE20
, OP_SH_CODE20
); break;
7616 case 'C': USE_BITS (OP_MASK_COPZ
, OP_SH_COPZ
); break;
7617 case 'D': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
7618 case 'E': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
7620 case 'G': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
7621 case 'H': USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
7623 case 'J': USE_BITS (OP_MASK_CODE19
, OP_SH_CODE19
); break;
7625 case 'M': USE_BITS (OP_MASK_CCC
, OP_SH_CCC
); break;
7626 case 'N': USE_BITS (OP_MASK_BCC
, OP_SH_BCC
); break;
7627 case 'O': USE_BITS (OP_MASK_ALN
, OP_SH_ALN
); break;
7628 case 'Q': USE_BITS (OP_MASK_VSEL
, OP_SH_VSEL
);
7629 USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
7630 case 'R': USE_BITS (OP_MASK_FR
, OP_SH_FR
); break;
7631 case 'S': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
7632 case 'T': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
7633 case 'V': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
7634 case 'W': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
7635 case 'X': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
7636 case 'Y': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
7637 case 'Z': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
7638 case 'a': USE_BITS (OP_MASK_TARGET
, OP_SH_TARGET
); break;
7639 case 'b': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
7640 case 'c': USE_BITS (OP_MASK_CODE
, OP_SH_CODE
); break;
7641 case 'd': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
7643 case 'h': USE_BITS (OP_MASK_PREFX
, OP_SH_PREFX
); break;
7644 case 'i': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
7645 case 'j': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
7646 case 'k': USE_BITS (OP_MASK_CACHE
, OP_SH_CACHE
); break;
7648 case 'o': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
7649 case 'p': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
7650 case 'q': USE_BITS (OP_MASK_CODE2
, OP_SH_CODE2
); break;
7651 case 'r': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
7652 case 's': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
7653 case 't': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
7654 case 'u': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
7655 case 'v': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
7656 case 'w': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
7659 case 'P': USE_BITS (OP_MASK_PERFREG
, OP_SH_PERFREG
); break;
7660 case 'U': USE_BITS (OP_MASK_RD
, OP_SH_RD
);
7661 USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
7663 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7664 c
, opc
->name
, opc
->args
);
7668 if (used_bits
!= 0xffffffff)
7670 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7671 ~used_bits
& 0xffffffff, opc
->name
, opc
->args
);
7677 /* This routine assembles an instruction into its binary format. As a
7678 side effect, it sets one of the global variables imm_reloc or
7679 offset_reloc to the type of relocation to do if one of the operands
7680 is an address expression. */
7685 struct mips_cl_insn
*ip
;
7690 struct mips_opcode
*insn
;
7693 unsigned int lastregno
= 0;
7699 /* If the instruction contains a '.', we first try to match an instruction
7700 including the '.'. Then we try again without the '.'. */
7702 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); ++s
)
7705 /* If we stopped on whitespace, then replace the whitespace with null for
7706 the call to hash_find. Save the character we replaced just in case we
7707 have to re-parse the instruction. */
7714 insn
= (struct mips_opcode
*) hash_find (op_hash
, str
);
7716 /* If we didn't find the instruction in the opcode table, try again, but
7717 this time with just the instruction up to, but not including the
7721 /* Restore the character we overwrite above (if any). */
7725 /* Scan up to the first '.' or whitespace. */
7727 *s
!= '\0' && *s
!= '.' && !ISSPACE (*s
);
7731 /* If we did not find a '.', then we can quit now. */
7734 insn_error
= "unrecognized opcode";
7738 /* Lookup the instruction in the hash table. */
7740 if ((insn
= (struct mips_opcode
*) hash_find (op_hash
, str
)) == NULL
)
7742 insn_error
= "unrecognized opcode";
7752 assert (strcmp (insn
->name
, str
) == 0);
7754 if (OPCODE_IS_MEMBER (insn
,
7756 | (mips_opts
.mips16
? INSN_MIPS16
: 0)
7757 | (mips_opts
.ase_mdmx
? INSN_MDMX
: 0)
7758 | (mips_opts
.ase_mips3d
? INSN_MIPS3D
: 0)),
7764 if (insn
->pinfo
!= INSN_MACRO
)
7766 if (mips_arch
== CPU_R4650
&& (insn
->pinfo
& FP_D
) != 0)
7772 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
]
7773 && strcmp (insn
->name
, insn
[1].name
) == 0)
7782 static char buf
[100];
7783 if (mips_arch_info
->is_isa
)
7785 _("opcode not supported at this ISA level (%s)"),
7786 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
7789 _("opcode not supported on this processor: %s (%s)"),
7790 mips_arch_info
->name
,
7791 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
7801 ip
->insn_opcode
= insn
->match
;
7803 for (args
= insn
->args
;; ++args
)
7807 s
+= strspn (s
, " \t");
7811 case '\0': /* end of args */
7824 ip
->insn_opcode
|= lastregno
<< OP_SH_RS
;
7828 ip
->insn_opcode
|= lastregno
<< OP_SH_RT
;
7832 ip
->insn_opcode
|= lastregno
<< OP_SH_FT
;
7836 ip
->insn_opcode
|= lastregno
<< OP_SH_FS
;
7842 /* Handle optional base register.
7843 Either the base register is omitted or
7844 we must have a left paren. */
7845 /* This is dependent on the next operand specifier
7846 is a base register specification. */
7847 assert (args
[1] == 'b' || args
[1] == '5'
7848 || args
[1] == '-' || args
[1] == '4');
7852 case ')': /* these must match exactly */
7857 case '<': /* must be at least one digit */
7859 * According to the manual, if the shift amount is greater
7860 * than 31 or less than 0, then the shift amount should be
7861 * mod 32. In reality the mips assembler issues an error.
7862 * We issue a warning and mask out all but the low 5 bits.
7864 my_getExpression (&imm_expr
, s
);
7865 check_absolute_expr (ip
, &imm_expr
);
7866 if ((unsigned long) imm_expr
.X_add_number
> 31)
7868 as_warn (_("Improper shift amount (%lu)"),
7869 (unsigned long) imm_expr
.X_add_number
);
7870 imm_expr
.X_add_number
&= OP_MASK_SHAMT
;
7872 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_SHAMT
;
7873 imm_expr
.X_op
= O_absent
;
7877 case '>': /* shift amount minus 32 */
7878 my_getExpression (&imm_expr
, s
);
7879 check_absolute_expr (ip
, &imm_expr
);
7880 if ((unsigned long) imm_expr
.X_add_number
< 32
7881 || (unsigned long) imm_expr
.X_add_number
> 63)
7883 ip
->insn_opcode
|= (imm_expr
.X_add_number
- 32) << OP_SH_SHAMT
;
7884 imm_expr
.X_op
= O_absent
;
7888 case 'k': /* cache code */
7889 case 'h': /* prefx code */
7890 my_getExpression (&imm_expr
, s
);
7891 check_absolute_expr (ip
, &imm_expr
);
7892 if ((unsigned long) imm_expr
.X_add_number
> 31)
7894 as_warn (_("Invalid value for `%s' (%lu)"),
7896 (unsigned long) imm_expr
.X_add_number
);
7897 imm_expr
.X_add_number
&= 0x1f;
7900 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CACHE
;
7902 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_PREFX
;
7903 imm_expr
.X_op
= O_absent
;
7907 case 'c': /* break code */
7908 my_getExpression (&imm_expr
, s
);
7909 check_absolute_expr (ip
, &imm_expr
);
7910 if ((unsigned long) imm_expr
.X_add_number
> 1023)
7912 as_warn (_("Illegal break code (%lu)"),
7913 (unsigned long) imm_expr
.X_add_number
);
7914 imm_expr
.X_add_number
&= OP_MASK_CODE
;
7916 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE
;
7917 imm_expr
.X_op
= O_absent
;
7921 case 'q': /* lower break code */
7922 my_getExpression (&imm_expr
, s
);
7923 check_absolute_expr (ip
, &imm_expr
);
7924 if ((unsigned long) imm_expr
.X_add_number
> 1023)
7926 as_warn (_("Illegal lower break code (%lu)"),
7927 (unsigned long) imm_expr
.X_add_number
);
7928 imm_expr
.X_add_number
&= OP_MASK_CODE2
;
7930 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE2
;
7931 imm_expr
.X_op
= O_absent
;
7935 case 'B': /* 20-bit syscall/break code. */
7936 my_getExpression (&imm_expr
, s
);
7937 check_absolute_expr (ip
, &imm_expr
);
7938 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE20
)
7939 as_warn (_("Illegal 20-bit code (%lu)"),
7940 (unsigned long) imm_expr
.X_add_number
);
7941 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE20
;
7942 imm_expr
.X_op
= O_absent
;
7946 case 'C': /* Coprocessor code */
7947 my_getExpression (&imm_expr
, s
);
7948 check_absolute_expr (ip
, &imm_expr
);
7949 if ((unsigned long) imm_expr
.X_add_number
>= (1 << 25))
7951 as_warn (_("Coproccesor code > 25 bits (%lu)"),
7952 (unsigned long) imm_expr
.X_add_number
);
7953 imm_expr
.X_add_number
&= ((1 << 25) - 1);
7955 ip
->insn_opcode
|= imm_expr
.X_add_number
;
7956 imm_expr
.X_op
= O_absent
;
7960 case 'J': /* 19-bit wait code. */
7961 my_getExpression (&imm_expr
, s
);
7962 check_absolute_expr (ip
, &imm_expr
);
7963 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE19
)
7964 as_warn (_("Illegal 19-bit code (%lu)"),
7965 (unsigned long) imm_expr
.X_add_number
);
7966 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE19
;
7967 imm_expr
.X_op
= O_absent
;
7971 case 'P': /* Performance register */
7972 my_getExpression (&imm_expr
, s
);
7973 check_absolute_expr (ip
, &imm_expr
);
7974 if (imm_expr
.X_add_number
!= 0 && imm_expr
.X_add_number
!= 1)
7976 as_warn (_("Invalid performance register (%lu)"),
7977 (unsigned long) imm_expr
.X_add_number
);
7978 imm_expr
.X_add_number
&= OP_MASK_PERFREG
;
7980 ip
->insn_opcode
|= (imm_expr
.X_add_number
<< OP_SH_PERFREG
);
7981 imm_expr
.X_op
= O_absent
;
7985 case 'b': /* base register */
7986 case 'd': /* destination register */
7987 case 's': /* source register */
7988 case 't': /* target register */
7989 case 'r': /* both target and source */
7990 case 'v': /* both dest and source */
7991 case 'w': /* both dest and target */
7992 case 'E': /* coprocessor target register */
7993 case 'G': /* coprocessor destination register */
7994 case 'x': /* ignore register name */
7995 case 'z': /* must be zero register */
7996 case 'U': /* destination register (clo/clz). */
8011 while (ISDIGIT (*s
));
8013 as_bad (_("Invalid register number (%d)"), regno
);
8015 else if (*args
== 'E' || *args
== 'G')
8019 if (s
[1] == 'r' && s
[2] == 'a')
8024 else if (s
[1] == 'f' && s
[2] == 'p')
8029 else if (s
[1] == 's' && s
[2] == 'p')
8034 else if (s
[1] == 'g' && s
[2] == 'p')
8039 else if (s
[1] == 'a' && s
[2] == 't')
8044 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '0')
8049 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '1')
8054 else if (s
[1] == 'z' && s
[2] == 'e' && s
[3] == 'r' && s
[4] == 'o')
8059 else if (itbl_have_entries
)
8064 p
= s
+ 1; /* advance past '$' */
8065 n
= itbl_get_field (&p
); /* n is name */
8067 /* See if this is a register defined in an
8069 if (itbl_get_reg_val (n
, &r
))
8071 /* Get_field advances to the start of
8072 the next field, so we need to back
8073 rack to the end of the last field. */
8077 s
= strchr (s
, '\0');
8090 as_warn (_("Used $at without \".set noat\""));
8096 if (c
== 'r' || c
== 'v' || c
== 'w')
8103 /* 'z' only matches $0. */
8104 if (c
== 'z' && regno
!= 0)
8107 /* Now that we have assembled one operand, we use the args string
8108 * to figure out where it goes in the instruction. */
8115 ip
->insn_opcode
|= regno
<< OP_SH_RS
;
8119 ip
->insn_opcode
|= regno
<< OP_SH_RD
;
8122 ip
->insn_opcode
|= regno
<< OP_SH_RD
;
8123 ip
->insn_opcode
|= regno
<< OP_SH_RT
;
8128 ip
->insn_opcode
|= regno
<< OP_SH_RT
;
8131 /* This case exists because on the r3000 trunc
8132 expands into a macro which requires a gp
8133 register. On the r6000 or r4000 it is
8134 assembled into a single instruction which
8135 ignores the register. Thus the insn version
8136 is MIPS_ISA2 and uses 'x', and the macro
8137 version is MIPS_ISA1 and uses 't'. */
8140 /* This case is for the div instruction, which
8141 acts differently if the destination argument
8142 is $0. This only matches $0, and is checked
8143 outside the switch. */
8146 /* Itbl operand; not yet implemented. FIXME ?? */
8148 /* What about all other operands like 'i', which
8149 can be specified in the opcode table? */
8159 ip
->insn_opcode
|= lastregno
<< OP_SH_RS
;
8162 ip
->insn_opcode
|= lastregno
<< OP_SH_RT
;
8167 case 'O': /* MDMX alignment immediate constant. */
8168 my_getExpression (&imm_expr
, s
);
8169 check_absolute_expr (ip
, &imm_expr
);
8170 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_ALN
)
8172 as_warn ("Improper align amount (%ld), using low bits",
8173 (long) imm_expr
.X_add_number
);
8174 imm_expr
.X_add_number
&= OP_MASK_ALN
;
8176 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_ALN
;
8177 imm_expr
.X_op
= O_absent
;
8181 case 'Q': /* MDMX vector, element sel, or const. */
8184 /* MDMX Immediate. */
8185 my_getExpression (&imm_expr
, s
);
8186 check_absolute_expr (ip
, &imm_expr
);
8187 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_FT
)
8189 as_warn (_("Invalid MDMX Immediate (%ld)"),
8190 (long) imm_expr
.X_add_number
);
8191 imm_expr
.X_add_number
&= OP_MASK_FT
;
8193 imm_expr
.X_add_number
&= OP_MASK_FT
;
8194 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
8195 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_QH
<< OP_SH_VSEL
;
8197 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_OB
<< OP_SH_VSEL
;
8198 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_FT
;
8199 imm_expr
.X_op
= O_absent
;
8203 /* Not MDMX Immediate. Fall through. */
8204 case 'X': /* MDMX destination register. */
8205 case 'Y': /* MDMX source register. */
8206 case 'Z': /* MDMX target register. */
8208 case 'D': /* floating point destination register */
8209 case 'S': /* floating point source register */
8210 case 'T': /* floating point target register */
8211 case 'R': /* floating point source register */
8215 /* Accept $fN for FP and MDMX register numbers, and in
8216 addition accept $vN for MDMX register numbers. */
8217 if ((s
[0] == '$' && s
[1] == 'f' && ISDIGIT (s
[2]))
8218 || (is_mdmx
!= 0 && s
[0] == '$' && s
[1] == 'v'
8229 while (ISDIGIT (*s
));
8232 as_bad (_("Invalid float register number (%d)"), regno
);
8234 if ((regno
& 1) != 0
8236 && ! (strcmp (str
, "mtc1") == 0
8237 || strcmp (str
, "mfc1") == 0
8238 || strcmp (str
, "lwc1") == 0
8239 || strcmp (str
, "swc1") == 0
8240 || strcmp (str
, "l.s") == 0
8241 || strcmp (str
, "s.s") == 0))
8242 as_warn (_("Float register should be even, was %d"),
8250 if (c
== 'V' || c
== 'W')
8261 ip
->insn_opcode
|= regno
<< OP_SH_FD
;
8266 ip
->insn_opcode
|= regno
<< OP_SH_FS
;
8269 /* This is like 'Z', but also needs to fix the MDMX
8270 vector/scalar select bits. Note that the
8271 scalar immediate case is handled above. */
8274 int is_qh
= (ip
->insn_opcode
& (1 << OP_SH_VSEL
));
8275 int max_el
= (is_qh
? 3 : 7);
8277 my_getExpression(&imm_expr
, s
);
8278 check_absolute_expr (ip
, &imm_expr
);
8280 if (imm_expr
.X_add_number
> max_el
)
8281 as_bad(_("Bad element selector %ld"),
8282 (long) imm_expr
.X_add_number
);
8283 imm_expr
.X_add_number
&= max_el
;
8284 ip
->insn_opcode
|= (imm_expr
.X_add_number
8288 as_warn(_("Expecting ']' found '%s'"), s
);
8294 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
8295 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_QH
8298 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_OB
<<
8305 ip
->insn_opcode
|= regno
<< OP_SH_FT
;
8308 ip
->insn_opcode
|= regno
<< OP_SH_FR
;
8318 ip
->insn_opcode
|= lastregno
<< OP_SH_FS
;
8321 ip
->insn_opcode
|= lastregno
<< OP_SH_FT
;
8327 my_getExpression (&imm_expr
, s
);
8328 if (imm_expr
.X_op
!= O_big
8329 && imm_expr
.X_op
!= O_constant
)
8330 insn_error
= _("absolute expression required");
8335 my_getExpression (&offset_expr
, s
);
8336 *imm_reloc
= BFD_RELOC_32
;
8349 unsigned char temp
[8];
8351 unsigned int length
;
8356 /* These only appear as the last operand in an
8357 instruction, and every instruction that accepts
8358 them in any variant accepts them in all variants.
8359 This means we don't have to worry about backing out
8360 any changes if the instruction does not match.
8362 The difference between them is the size of the
8363 floating point constant and where it goes. For 'F'
8364 and 'L' the constant is 64 bits; for 'f' and 'l' it
8365 is 32 bits. Where the constant is placed is based
8366 on how the MIPS assembler does things:
8369 f -- immediate value
8372 The .lit4 and .lit8 sections are only used if
8373 permitted by the -G argument.
8375 When generating embedded PIC code, we use the
8376 .lit8 section but not the .lit4 section (we can do
8377 .lit4 inline easily; we need to put .lit8
8378 somewhere in the data segment, and using .lit8
8379 permits the linker to eventually combine identical
8382 The code below needs to know whether the target register
8383 is 32 or 64 bits wide. It relies on the fact 'f' and
8384 'F' are used with GPR-based instructions and 'l' and
8385 'L' are used with FPR-based instructions. */
8387 f64
= *args
== 'F' || *args
== 'L';
8388 using_gprs
= *args
== 'F' || *args
== 'f';
8390 save_in
= input_line_pointer
;
8391 input_line_pointer
= s
;
8392 err
= md_atof (f64
? 'd' : 'f', (char *) temp
, &len
);
8394 s
= input_line_pointer
;
8395 input_line_pointer
= save_in
;
8396 if (err
!= NULL
&& *err
!= '\0')
8398 as_bad (_("Bad floating point constant: %s"), err
);
8399 memset (temp
, '\0', sizeof temp
);
8400 length
= f64
? 8 : 4;
8403 assert (length
== (unsigned) (f64
? 8 : 4));
8407 && (! USE_GLOBAL_POINTER_OPT
8408 || mips_pic
== EMBEDDED_PIC
8409 || g_switch_value
< 4
8410 || (temp
[0] == 0 && temp
[1] == 0)
8411 || (temp
[2] == 0 && temp
[3] == 0))))
8413 imm_expr
.X_op
= O_constant
;
8414 if (! target_big_endian
)
8415 imm_expr
.X_add_number
= bfd_getl32 (temp
);
8417 imm_expr
.X_add_number
= bfd_getb32 (temp
);
8420 && ! mips_disable_float_construction
8421 /* Constants can only be constructed in GPRs and
8422 copied to FPRs if the GPRs are at least as wide
8423 as the FPRs. Force the constant into memory if
8424 we are using 64-bit FPRs but the GPRs are only
8427 || ! (HAVE_64BIT_FPRS
&& HAVE_32BIT_GPRS
))
8428 && ((temp
[0] == 0 && temp
[1] == 0)
8429 || (temp
[2] == 0 && temp
[3] == 0))
8430 && ((temp
[4] == 0 && temp
[5] == 0)
8431 || (temp
[6] == 0 && temp
[7] == 0)))
8433 /* The value is simple enough to load with a couple of
8434 instructions. If using 32-bit registers, set
8435 imm_expr to the high order 32 bits and offset_expr to
8436 the low order 32 bits. Otherwise, set imm_expr to
8437 the entire 64 bit constant. */
8438 if (using_gprs
? HAVE_32BIT_GPRS
: HAVE_32BIT_FPRS
)
8440 imm_expr
.X_op
= O_constant
;
8441 offset_expr
.X_op
= O_constant
;
8442 if (! target_big_endian
)
8444 imm_expr
.X_add_number
= bfd_getl32 (temp
+ 4);
8445 offset_expr
.X_add_number
= bfd_getl32 (temp
);
8449 imm_expr
.X_add_number
= bfd_getb32 (temp
);
8450 offset_expr
.X_add_number
= bfd_getb32 (temp
+ 4);
8452 if (offset_expr
.X_add_number
== 0)
8453 offset_expr
.X_op
= O_absent
;
8455 else if (sizeof (imm_expr
.X_add_number
) > 4)
8457 imm_expr
.X_op
= O_constant
;
8458 if (! target_big_endian
)
8459 imm_expr
.X_add_number
= bfd_getl64 (temp
);
8461 imm_expr
.X_add_number
= bfd_getb64 (temp
);
8465 imm_expr
.X_op
= O_big
;
8466 imm_expr
.X_add_number
= 4;
8467 if (! target_big_endian
)
8469 generic_bignum
[0] = bfd_getl16 (temp
);
8470 generic_bignum
[1] = bfd_getl16 (temp
+ 2);
8471 generic_bignum
[2] = bfd_getl16 (temp
+ 4);
8472 generic_bignum
[3] = bfd_getl16 (temp
+ 6);
8476 generic_bignum
[0] = bfd_getb16 (temp
+ 6);
8477 generic_bignum
[1] = bfd_getb16 (temp
+ 4);
8478 generic_bignum
[2] = bfd_getb16 (temp
+ 2);
8479 generic_bignum
[3] = bfd_getb16 (temp
);
8485 const char *newname
;
8488 /* Switch to the right section. */
8490 subseg
= now_subseg
;
8493 default: /* unused default case avoids warnings. */
8495 newname
= RDATA_SECTION_NAME
;
8496 if ((USE_GLOBAL_POINTER_OPT
&& g_switch_value
>= 8)
8497 || mips_pic
== EMBEDDED_PIC
)
8501 if (mips_pic
== EMBEDDED_PIC
)
8504 newname
= RDATA_SECTION_NAME
;
8507 assert (!USE_GLOBAL_POINTER_OPT
8508 || g_switch_value
>= 4);
8512 new_seg
= subseg_new (newname
, (subsegT
) 0);
8513 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
8514 bfd_set_section_flags (stdoutput
, new_seg
,
8519 frag_align (*args
== 'l' ? 2 : 3, 0, 0);
8520 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
8521 && strcmp (TARGET_OS
, "elf") != 0)
8522 record_alignment (new_seg
, 4);
8524 record_alignment (new_seg
, *args
== 'l' ? 2 : 3);
8526 as_bad (_("Can't use floating point insn in this section"));
8528 /* Set the argument to the current address in the
8530 offset_expr
.X_op
= O_symbol
;
8531 offset_expr
.X_add_symbol
=
8532 symbol_new ("L0\001", now_seg
,
8533 (valueT
) frag_now_fix (), frag_now
);
8534 offset_expr
.X_add_number
= 0;
8536 /* Put the floating point number into the section. */
8537 p
= frag_more ((int) length
);
8538 memcpy (p
, temp
, length
);
8540 /* Switch back to the original section. */
8541 subseg_set (seg
, subseg
);
8546 case 'i': /* 16 bit unsigned immediate */
8547 case 'j': /* 16 bit signed immediate */
8548 *imm_reloc
= BFD_RELOC_LO16
;
8549 c
= my_getSmallExpression (&imm_expr
, s
);
8556 *imm_reloc
= BFD_RELOC_HI16_S
;
8557 imm_unmatched_hi
= true;
8560 else if (c
== S_EX_HIGHEST
)
8561 *imm_reloc
= BFD_RELOC_MIPS_HIGHEST
;
8562 else if (c
== S_EX_HIGHER
)
8563 *imm_reloc
= BFD_RELOC_MIPS_HIGHER
;
8564 else if (c
== S_EX_GP_REL
)
8566 /* This occurs in NewABI only. */
8567 c
= my_getSmallExpression (&imm_expr
, s
);
8569 as_bad (_("bad composition of relocations"));
8572 c
= my_getSmallExpression (&imm_expr
, s
);
8574 as_bad (_("bad composition of relocations"));
8577 imm_reloc
[0] = BFD_RELOC_GPREL16
;
8578 imm_reloc
[1] = BFD_RELOC_MIPS_SUB
;
8579 imm_reloc
[2] = BFD_RELOC_LO16
;
8585 *imm_reloc
= BFD_RELOC_HI16
;
8587 else if (imm_expr
.X_op
== O_constant
)
8588 imm_expr
.X_add_number
&= 0xffff;
8592 if ((c
== S_EX_NONE
&& imm_expr
.X_op
!= O_constant
)
8593 || ((imm_expr
.X_add_number
< 0
8594 || imm_expr
.X_add_number
>= 0x10000)
8595 && imm_expr
.X_op
== O_constant
))
8597 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
8598 !strcmp (insn
->name
, insn
[1].name
))
8600 if (imm_expr
.X_op
== O_constant
8601 || imm_expr
.X_op
== O_big
)
8602 as_bad (_("16 bit expression not in range 0..65535"));
8610 /* The upper bound should be 0x8000, but
8611 unfortunately the MIPS assembler accepts numbers
8612 from 0x8000 to 0xffff and sign extends them, and
8613 we want to be compatible. We only permit this
8614 extended range for an instruction which does not
8615 provide any further alternates, since those
8616 alternates may handle other cases. People should
8617 use the numbers they mean, rather than relying on
8618 a mysterious sign extension. */
8619 more
= (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
8620 strcmp (insn
->name
, insn
[1].name
) == 0);
8625 if ((c
== S_EX_NONE
&& imm_expr
.X_op
!= O_constant
)
8626 || ((imm_expr
.X_add_number
< -0x8000
8627 || imm_expr
.X_add_number
>= max
)
8628 && imm_expr
.X_op
== O_constant
)
8630 && imm_expr
.X_add_number
< 0
8632 && imm_expr
.X_unsigned
8633 && sizeof (imm_expr
.X_add_number
) <= 4))
8637 if (imm_expr
.X_op
== O_constant
8638 || imm_expr
.X_op
== O_big
)
8639 as_bad (_("16 bit expression not in range -32768..32767"));
8645 case 'o': /* 16 bit offset */
8646 c
= my_getSmallExpression (&offset_expr
, s
);
8648 /* If this value won't fit into a 16 bit offset, then go
8649 find a macro that will generate the 32 bit offset
8652 && (offset_expr
.X_op
!= O_constant
8653 || offset_expr
.X_add_number
>= 0x8000
8654 || offset_expr
.X_add_number
< -0x8000))
8659 if (offset_expr
.X_op
!= O_constant
)
8661 offset_expr
.X_add_number
=
8662 (offset_expr
.X_add_number
>> 16) & 0xffff;
8664 *offset_reloc
= BFD_RELOC_LO16
;
8668 case 'p': /* pc relative offset */
8669 if (mips_pic
== EMBEDDED_PIC
)
8670 *offset_reloc
= BFD_RELOC_16_PCREL_S2
;
8672 *offset_reloc
= BFD_RELOC_16_PCREL
;
8673 my_getExpression (&offset_expr
, s
);
8677 case 'u': /* upper 16 bits */
8678 c
= my_getSmallExpression (&imm_expr
, s
);
8679 *imm_reloc
= BFD_RELOC_LO16
;
8686 *imm_reloc
= BFD_RELOC_HI16_S
;
8687 imm_unmatched_hi
= true;
8690 else if (c
== S_EX_HIGHEST
)
8691 *imm_reloc
= BFD_RELOC_MIPS_HIGHEST
;
8692 else if (c
== S_EX_GP_REL
)
8694 /* This occurs in NewABI only. */
8695 c
= my_getSmallExpression (&imm_expr
, s
);
8697 as_bad (_("bad composition of relocations"));
8700 c
= my_getSmallExpression (&imm_expr
, s
);
8702 as_bad (_("bad composition of relocations"));
8705 imm_reloc
[0] = BFD_RELOC_GPREL16
;
8706 imm_reloc
[1] = BFD_RELOC_MIPS_SUB
;
8707 imm_reloc
[2] = BFD_RELOC_HI16_S
;
8713 *imm_reloc
= BFD_RELOC_HI16
;
8715 else if (imm_expr
.X_op
== O_constant
)
8716 imm_expr
.X_add_number
&= 0xffff;
8718 else if (imm_expr
.X_op
== O_constant
8719 && (imm_expr
.X_add_number
< 0
8720 || imm_expr
.X_add_number
>= 0x10000))
8721 as_bad (_("lui expression not in range 0..65535"));
8725 case 'a': /* 26 bit address */
8726 my_getExpression (&offset_expr
, s
);
8728 *offset_reloc
= BFD_RELOC_MIPS_JMP
;
8731 case 'N': /* 3 bit branch condition code */
8732 case 'M': /* 3 bit compare condition code */
8733 if (strncmp (s
, "$fcc", 4) != 0)
8743 while (ISDIGIT (*s
));
8745 as_bad (_("invalid condition code register $fcc%d"), regno
);
8747 ip
->insn_opcode
|= regno
<< OP_SH_BCC
;
8749 ip
->insn_opcode
|= regno
<< OP_SH_CCC
;
8753 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
8764 while (ISDIGIT (*s
));
8767 c
= 8; /* Invalid sel value. */
8770 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
8771 ip
->insn_opcode
|= c
;
8775 as_bad (_("bad char = '%c'\n"), *args
);
8780 /* Args don't match. */
8781 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
8782 !strcmp (insn
->name
, insn
[1].name
))
8786 insn_error
= _("illegal operands");
8791 insn_error
= _("illegal operands");
8796 /* This routine assembles an instruction into its binary format when
8797 assembling for the mips16. As a side effect, it sets one of the
8798 global variables imm_reloc or offset_reloc to the type of
8799 relocation to do if one of the operands is an address expression.
8800 It also sets mips16_small and mips16_ext if the user explicitly
8801 requested a small or extended instruction. */
8806 struct mips_cl_insn
*ip
;
8810 struct mips_opcode
*insn
;
8813 unsigned int lastregno
= 0;
8818 mips16_small
= false;
8821 for (s
= str
; ISLOWER (*s
); ++s
)
8833 if (s
[1] == 't' && s
[2] == ' ')
8836 mips16_small
= true;
8840 else if (s
[1] == 'e' && s
[2] == ' ')
8849 insn_error
= _("unknown opcode");
8853 if (mips_opts
.noautoextend
&& ! mips16_ext
)
8854 mips16_small
= true;
8856 if ((insn
= (struct mips_opcode
*) hash_find (mips16_op_hash
, str
)) == NULL
)
8858 insn_error
= _("unrecognized opcode");
8865 assert (strcmp (insn
->name
, str
) == 0);
8868 ip
->insn_opcode
= insn
->match
;
8869 ip
->use_extend
= false;
8870 imm_expr
.X_op
= O_absent
;
8871 imm_reloc
[0] = BFD_RELOC_UNUSED
;
8872 imm_reloc
[1] = BFD_RELOC_UNUSED
;
8873 imm_reloc
[2] = BFD_RELOC_UNUSED
;
8874 offset_expr
.X_op
= O_absent
;
8875 offset_reloc
[0] = BFD_RELOC_UNUSED
;
8876 offset_reloc
[1] = BFD_RELOC_UNUSED
;
8877 offset_reloc
[2] = BFD_RELOC_UNUSED
;
8878 for (args
= insn
->args
; 1; ++args
)
8885 /* In this switch statement we call break if we did not find
8886 a match, continue if we did find a match, or return if we
8895 /* Stuff the immediate value in now, if we can. */
8896 if (imm_expr
.X_op
== O_constant
8897 && *imm_reloc
> BFD_RELOC_UNUSED
8898 && insn
->pinfo
!= INSN_MACRO
)
8900 mips16_immed (NULL
, 0, *imm_reloc
- BFD_RELOC_UNUSED
,
8901 imm_expr
.X_add_number
, true, mips16_small
,
8902 mips16_ext
, &ip
->insn_opcode
,
8903 &ip
->use_extend
, &ip
->extend
);
8904 imm_expr
.X_op
= O_absent
;
8905 *imm_reloc
= BFD_RELOC_UNUSED
;
8919 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RX
;
8922 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RY
;
8938 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RX
;
8940 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RY
;
8967 while (ISDIGIT (*s
));
8970 as_bad (_("invalid register number (%d)"), regno
);
8976 if (s
[1] == 'r' && s
[2] == 'a')
8981 else if (s
[1] == 'f' && s
[2] == 'p')
8986 else if (s
[1] == 's' && s
[2] == 'p')
8991 else if (s
[1] == 'g' && s
[2] == 'p')
8996 else if (s
[1] == 'a' && s
[2] == 't')
9001 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '0')
9006 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '1')
9011 else if (s
[1] == 'z' && s
[2] == 'e' && s
[3] == 'r' && s
[4] == 'o')
9024 if (c
== 'v' || c
== 'w')
9026 regno
= mips16_to_32_reg_map
[lastregno
];
9040 regno
= mips32_to_16_reg_map
[regno
];
9045 regno
= ILLEGAL_REG
;
9050 regno
= ILLEGAL_REG
;
9055 regno
= ILLEGAL_REG
;
9060 if (regno
== AT
&& ! mips_opts
.noat
)
9061 as_warn (_("used $at without \".set noat\""));
9068 if (regno
== ILLEGAL_REG
)
9075 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RX
;
9079 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RY
;
9082 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RZ
;
9085 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_MOVE32Z
;
9091 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_REGR32
;
9094 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
9095 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_REG32R
;
9105 if (strncmp (s
, "$pc", 3) == 0)
9129 && strncmp (s
+ 1, "gprel(", sizeof "gprel(" - 1) == 0)
9131 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9132 and generate the appropriate reloc. If the text
9133 inside %gprel is not a symbol name with an
9134 optional offset, then we generate a normal reloc
9135 and will probably fail later. */
9136 my_getExpression (&imm_expr
, s
+ sizeof "%gprel" - 1);
9137 if (imm_expr
.X_op
== O_symbol
)
9140 *imm_reloc
= BFD_RELOC_MIPS16_GPREL
;
9142 ip
->use_extend
= true;
9149 /* Just pick up a normal expression. */
9150 my_getExpression (&imm_expr
, s
);
9153 if (imm_expr
.X_op
== O_register
)
9155 /* What we thought was an expression turned out to
9158 if (s
[0] == '(' && args
[1] == '(')
9160 /* It looks like the expression was omitted
9161 before a register indirection, which means
9162 that the expression is implicitly zero. We
9163 still set up imm_expr, so that we handle
9164 explicit extensions correctly. */
9165 imm_expr
.X_op
= O_constant
;
9166 imm_expr
.X_add_number
= 0;
9167 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9174 /* We need to relax this instruction. */
9175 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9184 /* We use offset_reloc rather than imm_reloc for the PC
9185 relative operands. This lets macros with both
9186 immediate and address operands work correctly. */
9187 my_getExpression (&offset_expr
, s
);
9189 if (offset_expr
.X_op
== O_register
)
9192 /* We need to relax this instruction. */
9193 *offset_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9197 case '6': /* break code */
9198 my_getExpression (&imm_expr
, s
);
9199 check_absolute_expr (ip
, &imm_expr
);
9200 if ((unsigned long) imm_expr
.X_add_number
> 63)
9202 as_warn (_("Invalid value for `%s' (%lu)"),
9204 (unsigned long) imm_expr
.X_add_number
);
9205 imm_expr
.X_add_number
&= 0x3f;
9207 ip
->insn_opcode
|= imm_expr
.X_add_number
<< MIPS16OP_SH_IMM6
;
9208 imm_expr
.X_op
= O_absent
;
9212 case 'a': /* 26 bit address */
9213 my_getExpression (&offset_expr
, s
);
9215 *offset_reloc
= BFD_RELOC_MIPS16_JMP
;
9216 ip
->insn_opcode
<<= 16;
9219 case 'l': /* register list for entry macro */
9220 case 'L': /* register list for exit macro */
9230 int freg
, reg1
, reg2
;
9232 while (*s
== ' ' || *s
== ',')
9236 as_bad (_("can't parse register list"));
9248 while (ISDIGIT (*s
))
9270 as_bad (_("invalid register list"));
9275 while (ISDIGIT (*s
))
9282 if (freg
&& reg1
== 0 && reg2
== 0 && c
== 'L')
9287 else if (freg
&& reg1
== 0 && reg2
== 1 && c
== 'L')
9292 else if (reg1
== 4 && reg2
>= 4 && reg2
<= 7 && c
!= 'L')
9293 mask
|= (reg2
- 3) << 3;
9294 else if (reg1
== 16 && reg2
>= 16 && reg2
<= 17)
9295 mask
|= (reg2
- 15) << 1;
9296 else if (reg1
== RA
&& reg2
== RA
)
9300 as_bad (_("invalid register list"));
9304 /* The mask is filled in in the opcode table for the
9305 benefit of the disassembler. We remove it before
9306 applying the actual mask. */
9307 ip
->insn_opcode
&= ~ ((7 << 3) << MIPS16OP_SH_IMM6
);
9308 ip
->insn_opcode
|= mask
<< MIPS16OP_SH_IMM6
;
9312 case 'e': /* extend code */
9313 my_getExpression (&imm_expr
, s
);
9314 check_absolute_expr (ip
, &imm_expr
);
9315 if ((unsigned long) imm_expr
.X_add_number
> 0x7ff)
9317 as_warn (_("Invalid value for `%s' (%lu)"),
9319 (unsigned long) imm_expr
.X_add_number
);
9320 imm_expr
.X_add_number
&= 0x7ff;
9322 ip
->insn_opcode
|= imm_expr
.X_add_number
;
9323 imm_expr
.X_op
= O_absent
;
9333 /* Args don't match. */
9334 if (insn
+ 1 < &mips16_opcodes
[bfd_mips16_num_opcodes
] &&
9335 strcmp (insn
->name
, insn
[1].name
) == 0)
9342 insn_error
= _("illegal operands");
9348 /* This structure holds information we know about a mips16 immediate
9351 struct mips16_immed_operand
9353 /* The type code used in the argument string in the opcode table. */
9355 /* The number of bits in the short form of the opcode. */
9357 /* The number of bits in the extended form of the opcode. */
9359 /* The amount by which the short form is shifted when it is used;
9360 for example, the sw instruction has a shift count of 2. */
9362 /* The amount by which the short form is shifted when it is stored
9363 into the instruction code. */
9365 /* Non-zero if the short form is unsigned. */
9367 /* Non-zero if the extended form is unsigned. */
9369 /* Non-zero if the value is PC relative. */
9373 /* The mips16 immediate operand types. */
9375 static const struct mips16_immed_operand mips16_immed_operands
[] =
9377 { '<', 3, 5, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
9378 { '>', 3, 5, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
9379 { '[', 3, 6, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
9380 { ']', 3, 6, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
9381 { '4', 4, 15, 0, MIPS16OP_SH_IMM4
, 0, 0, 0 },
9382 { '5', 5, 16, 0, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9383 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9384 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9385 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9386 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5
, 0, 0, 0 },
9387 { '8', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9388 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9389 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9390 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 1, 0 },
9391 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 0 },
9392 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8
, 0, 0, 0 },
9393 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
9394 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
9395 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 1 },
9396 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 1 },
9397 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 1 }
9400 #define MIPS16_NUM_IMMED \
9401 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9403 /* Handle a mips16 instruction with an immediate value. This or's the
9404 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9405 whether an extended value is needed; if one is needed, it sets
9406 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9407 If SMALL is true, an unextended opcode was explicitly requested.
9408 If EXT is true, an extended opcode was explicitly requested. If
9409 WARN is true, warn if EXT does not match reality. */
9412 mips16_immed (file
, line
, type
, val
, warn
, small
, ext
, insn
, use_extend
,
9421 unsigned long *insn
;
9422 boolean
*use_extend
;
9423 unsigned short *extend
;
9425 register const struct mips16_immed_operand
*op
;
9426 int mintiny
, maxtiny
;
9429 op
= mips16_immed_operands
;
9430 while (op
->type
!= type
)
9433 assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
9438 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
9441 maxtiny
= 1 << op
->nbits
;
9446 maxtiny
= (1 << op
->nbits
) - 1;
9451 mintiny
= - (1 << (op
->nbits
- 1));
9452 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
9455 /* Branch offsets have an implicit 0 in the lowest bit. */
9456 if (type
== 'p' || type
== 'q')
9459 if ((val
& ((1 << op
->shift
) - 1)) != 0
9460 || val
< (mintiny
<< op
->shift
)
9461 || val
> (maxtiny
<< op
->shift
))
9466 if (warn
&& ext
&& ! needext
)
9467 as_warn_where (file
, line
,
9468 _("extended operand requested but not required"));
9469 if (small
&& needext
)
9470 as_bad_where (file
, line
, _("invalid unextended operand value"));
9472 if (small
|| (! ext
&& ! needext
))
9476 *use_extend
= false;
9477 insnval
= ((val
>> op
->shift
) & ((1 << op
->nbits
) - 1));
9478 insnval
<<= op
->op_shift
;
9483 long minext
, maxext
;
9489 maxext
= (1 << op
->extbits
) - 1;
9493 minext
= - (1 << (op
->extbits
- 1));
9494 maxext
= (1 << (op
->extbits
- 1)) - 1;
9496 if (val
< minext
|| val
> maxext
)
9497 as_bad_where (file
, line
,
9498 _("operand value out of range for instruction"));
9501 if (op
->extbits
== 16)
9503 extval
= ((val
>> 11) & 0x1f) | (val
& 0x7e0);
9506 else if (op
->extbits
== 15)
9508 extval
= ((val
>> 11) & 0xf) | (val
& 0x7f0);
9513 extval
= ((val
& 0x1f) << 6) | (val
& 0x20);
9517 *extend
= (unsigned short) extval
;
9522 static struct percent_op_match
9525 const enum small_ex_type type
;
9530 {"%call_hi", S_EX_CALL_HI
},
9531 {"%call_lo", S_EX_CALL_LO
},
9532 {"%call16", S_EX_CALL16
},
9533 {"%got_disp", S_EX_GOT_DISP
},
9534 {"%got_page", S_EX_GOT_PAGE
},
9535 {"%got_ofst", S_EX_GOT_OFST
},
9536 {"%got_hi", S_EX_GOT_HI
},
9537 {"%got_lo", S_EX_GOT_LO
},
9539 {"%gp_rel", S_EX_GP_REL
},
9540 {"%half", S_EX_HALF
},
9541 {"%highest", S_EX_HIGHEST
},
9542 {"%higher", S_EX_HIGHER
},
9548 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9549 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9550 can be nested, this is handled by blanking the innermost, parsing the
9551 rest by subsequent calls. */
9554 my_getSmallParser (str
, len
, nestlevel
)
9560 *str
+= strspn (*str
, " \t");
9561 /* Check for expression in parentheses. */
9564 char *b
= *str
+ 1 + strspn (*str
+ 1, " \t");
9567 /* Check for base register. */
9571 && (e
= b
+ strcspn (b
, ") \t"))
9572 && e
- b
> 1 && e
- b
< 4)
9575 && ((b
[1] == 'f' && b
[2] == 'p')
9576 || (b
[1] == 's' && b
[2] == 'p')
9577 || (b
[1] == 'g' && b
[2] == 'p')
9578 || (b
[1] == 'a' && b
[2] == 't')
9580 && ISDIGIT (b
[2]))))
9581 || (ISDIGIT (b
[1])))
9583 *len
= strcspn (*str
, ")") + 1;
9584 return S_EX_REGISTER
;
9588 /* Check for percent_op (in parentheses). */
9589 else if (b
[0] == '%')
9592 return my_getPercentOp (str
, len
, nestlevel
);
9595 /* Some other expression in the parentheses, which can contain
9596 parentheses itself. Attempt to find the matching one. */
9602 for (s
= *str
+ 1; *s
&& pcnt
; s
++, (*len
)++)
9611 /* Check for percent_op (outside of parentheses). */
9612 else if (*str
[0] == '%')
9613 return my_getPercentOp (str
, len
, nestlevel
);
9615 /* Any other expression. */
9620 my_getPercentOp (str
, len
, nestlevel
)
9625 char *tmp
= *str
+ 1;
9628 while (ISALPHA (*tmp
) || *tmp
== '_')
9630 *tmp
= TOLOWER (*tmp
);
9633 while (i
< (sizeof (percent_op
) / sizeof (struct percent_op_match
)))
9635 if (strncmp (*str
, percent_op
[i
].str
, strlen (percent_op
[i
].str
)))
9639 int type
= percent_op
[i
].type
;
9641 /* Only %hi and %lo are allowed for OldABI. */
9642 if (! HAVE_NEWABI
&& type
!= S_EX_HI
&& type
!= S_EX_LO
)
9645 *len
= strlen (percent_op
[i
].str
);
9654 my_getSmallExpression (ep
, str
)
9658 static char *oldstr
= NULL
;
9664 /* Don't update oldstr if the last call had nested percent_op's. We need
9665 it to parse the outer ones later. */
9672 c
= my_getSmallParser (&str
, &len
, &nestlevel
);
9673 if (c
!= S_EX_NONE
&& c
!= S_EX_REGISTER
)
9676 while (c
!= S_EX_NONE
&& c
!= S_EX_REGISTER
);
9680 /* A percent_op was encountered. Don't try to get an expression if
9681 it is already blanked out. */
9682 if (*(str
+ strspn (str
+ 1, " )")) != ')')
9686 /* Let my_getExpression() stop at the closing parenthesis. */
9687 save
= *(str
+ len
);
9688 *(str
+ len
) = '\0';
9689 my_getExpression (ep
, str
);
9690 *(str
+ len
) = save
;
9694 /* Blank out including the % sign and the proper matching
9697 char *s
= strrchr (oldstr
, '%');
9700 for (end
= strchr (s
, '(') + 1; *end
&& pcnt
; end
++)
9704 else if (*end
== ')')
9708 memset (s
, ' ', end
- s
);
9712 expr_end
= str
+ len
;
9716 else if (c
== S_EX_NONE
)
9718 my_getExpression (ep
, str
);
9720 else if (c
== S_EX_REGISTER
)
9722 ep
->X_op
= O_constant
;
9724 ep
->X_add_symbol
= NULL
;
9725 ep
->X_op_symbol
= NULL
;
9726 ep
->X_add_number
= 0;
9730 as_fatal (_("internal error"));
9734 /* All percent_op's have been handled. */
9741 my_getExpression (ep
, str
)
9748 save_in
= input_line_pointer
;
9749 input_line_pointer
= str
;
9751 expr_end
= input_line_pointer
;
9752 input_line_pointer
= save_in
;
9754 /* If we are in mips16 mode, and this is an expression based on `.',
9755 then we bump the value of the symbol by 1 since that is how other
9756 text symbols are handled. We don't bother to handle complex
9757 expressions, just `.' plus or minus a constant. */
9758 if (mips_opts
.mips16
9759 && ep
->X_op
== O_symbol
9760 && strcmp (S_GET_NAME (ep
->X_add_symbol
), FAKE_LABEL_NAME
) == 0
9761 && S_GET_SEGMENT (ep
->X_add_symbol
) == now_seg
9762 && symbol_get_frag (ep
->X_add_symbol
) == frag_now
9763 && symbol_constant_p (ep
->X_add_symbol
)
9764 && (val
= S_GET_VALUE (ep
->X_add_symbol
)) == frag_now_fix ())
9765 S_SET_VALUE (ep
->X_add_symbol
, val
+ 1);
9768 /* Turn a string in input_line_pointer into a floating point constant
9769 of type TYPE, and store the appropriate bytes in *LITP. The number
9770 of LITTLENUMS emitted is stored in *SIZEP. An error message is
9771 returned, or NULL on OK. */
9774 md_atof (type
, litP
, sizeP
)
9780 LITTLENUM_TYPE words
[4];
9796 return _("bad call to md_atof");
9799 t
= atof_ieee (input_line_pointer
, type
, words
);
9801 input_line_pointer
= t
;
9805 if (! target_big_endian
)
9807 for (i
= prec
- 1; i
>= 0; i
--)
9809 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
9815 for (i
= 0; i
< prec
; i
++)
9817 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
9826 md_number_to_chars (buf
, val
, n
)
9831 if (target_big_endian
)
9832 number_to_chars_bigendian (buf
, val
, n
);
9834 number_to_chars_littleendian (buf
, val
, n
);
9838 static int support_64bit_objects(void)
9840 const char **list
, **l
;
9842 list
= bfd_target_list ();
9843 for (l
= list
; *l
!= NULL
; l
++)
9845 /* This is traditional mips */
9846 if (strcmp (*l
, "elf64-tradbigmips") == 0
9847 || strcmp (*l
, "elf64-tradlittlemips") == 0)
9849 if (strcmp (*l
, "elf64-bigmips") == 0
9850 || strcmp (*l
, "elf64-littlemips") == 0)
9854 return (*l
!= NULL
);
9856 #endif /* OBJ_ELF */
9858 const char *md_shortopts
= "nO::g::G:";
9860 struct option md_longopts
[] =
9862 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
9863 {"mips0", no_argument
, NULL
, OPTION_MIPS1
},
9864 {"mips1", no_argument
, NULL
, OPTION_MIPS1
},
9865 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
9866 {"mips2", no_argument
, NULL
, OPTION_MIPS2
},
9867 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
9868 {"mips3", no_argument
, NULL
, OPTION_MIPS3
},
9869 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
9870 {"mips4", no_argument
, NULL
, OPTION_MIPS4
},
9871 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
9872 {"mips5", no_argument
, NULL
, OPTION_MIPS5
},
9873 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
9874 {"mips32", no_argument
, NULL
, OPTION_MIPS32
},
9875 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
9876 {"mips64", no_argument
, NULL
, OPTION_MIPS64
},
9877 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
9878 {"membedded-pic", no_argument
, NULL
, OPTION_MEMBEDDED_PIC
},
9879 #define OPTION_TRAP (OPTION_MD_BASE + 9)
9880 {"trap", no_argument
, NULL
, OPTION_TRAP
},
9881 {"no-break", no_argument
, NULL
, OPTION_TRAP
},
9882 #define OPTION_BREAK (OPTION_MD_BASE + 10)
9883 {"break", no_argument
, NULL
, OPTION_BREAK
},
9884 {"no-trap", no_argument
, NULL
, OPTION_BREAK
},
9885 #define OPTION_EB (OPTION_MD_BASE + 11)
9886 {"EB", no_argument
, NULL
, OPTION_EB
},
9887 #define OPTION_EL (OPTION_MD_BASE + 12)
9888 {"EL", no_argument
, NULL
, OPTION_EL
},
9889 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
9890 {"mips16", no_argument
, NULL
, OPTION_MIPS16
},
9891 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
9892 {"no-mips16", no_argument
, NULL
, OPTION_NO_MIPS16
},
9893 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
9894 {"mfix7000", no_argument
, NULL
, OPTION_M7000_HILO_FIX
},
9895 #define OPTION_MNO_7000_HILO_FIX (OPTION_MD_BASE + 16)
9896 {"no-fix-7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
9897 {"mno-fix7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
9898 #define OPTION_FP32 (OPTION_MD_BASE + 17)
9899 {"mfp32", no_argument
, NULL
, OPTION_FP32
},
9900 #define OPTION_GP32 (OPTION_MD_BASE + 18)
9901 {"mgp32", no_argument
, NULL
, OPTION_GP32
},
9902 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
9903 {"construct-floats", no_argument
, NULL
, OPTION_CONSTRUCT_FLOATS
},
9904 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
9905 {"no-construct-floats", no_argument
, NULL
, OPTION_NO_CONSTRUCT_FLOATS
},
9906 #define OPTION_MARCH (OPTION_MD_BASE + 21)
9907 {"march", required_argument
, NULL
, OPTION_MARCH
},
9908 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
9909 {"mtune", required_argument
, NULL
, OPTION_MTUNE
},
9910 #define OPTION_FP64 (OPTION_MD_BASE + 23)
9911 {"mfp64", no_argument
, NULL
, OPTION_FP64
},
9912 #define OPTION_M4650 (OPTION_MD_BASE + 24)
9913 {"m4650", no_argument
, NULL
, OPTION_M4650
},
9914 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
9915 {"no-m4650", no_argument
, NULL
, OPTION_NO_M4650
},
9916 #define OPTION_M4010 (OPTION_MD_BASE + 26)
9917 {"m4010", no_argument
, NULL
, OPTION_M4010
},
9918 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
9919 {"no-m4010", no_argument
, NULL
, OPTION_NO_M4010
},
9920 #define OPTION_M4100 (OPTION_MD_BASE + 28)
9921 {"m4100", no_argument
, NULL
, OPTION_M4100
},
9922 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
9923 {"no-m4100", no_argument
, NULL
, OPTION_NO_M4100
},
9924 #define OPTION_M3900 (OPTION_MD_BASE + 30)
9925 {"m3900", no_argument
, NULL
, OPTION_M3900
},
9926 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
9927 {"no-m3900", no_argument
, NULL
, OPTION_NO_M3900
},
9928 #define OPTION_GP64 (OPTION_MD_BASE + 32)
9929 {"mgp64", no_argument
, NULL
, OPTION_GP64
},
9930 #define OPTION_MIPS3D (OPTION_MD_BASE + 33)
9931 {"mips3d", no_argument
, NULL
, OPTION_MIPS3D
},
9932 #define OPTION_NO_MIPS3D (OPTION_MD_BASE + 34)
9933 {"no-mips3d", no_argument
, NULL
, OPTION_NO_MIPS3D
},
9934 #define OPTION_MDMX (OPTION_MD_BASE + 35)
9935 {"mdmx", no_argument
, NULL
, OPTION_MDMX
},
9936 #define OPTION_NO_MDMX (OPTION_MD_BASE + 36)
9937 {"no-mdmx", no_argument
, NULL
, OPTION_NO_MDMX
},
9939 #define OPTION_ELF_BASE (OPTION_MD_BASE + 37)
9940 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
9941 {"KPIC", no_argument
, NULL
, OPTION_CALL_SHARED
},
9942 {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
9943 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
9944 {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
9945 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
9946 {"xgot", no_argument
, NULL
, OPTION_XGOT
},
9947 #define OPTION_MABI (OPTION_ELF_BASE + 3)
9948 {"mabi", required_argument
, NULL
, OPTION_MABI
},
9949 #define OPTION_32 (OPTION_ELF_BASE + 4)
9950 {"32", no_argument
, NULL
, OPTION_32
},
9951 #define OPTION_N32 (OPTION_ELF_BASE + 5)
9952 {"n32", no_argument
, NULL
, OPTION_N32
},
9953 #define OPTION_64 (OPTION_ELF_BASE + 6)
9954 {"64", no_argument
, NULL
, OPTION_64
},
9955 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
9956 {"mdebug", no_argument
, NULL
, OPTION_MDEBUG
},
9957 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
9958 {"no-mdebug", no_argument
, NULL
, OPTION_NO_MDEBUG
},
9959 #endif /* OBJ_ELF */
9960 {NULL
, no_argument
, NULL
, 0}
9962 size_t md_longopts_size
= sizeof (md_longopts
);
9964 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
9965 NEW_VALUE. Warn if another value was already specified. Note:
9966 we have to defer parsing the -march and -mtune arguments in order
9967 to handle 'from-abi' correctly, since the ABI might be specified
9968 in a later argument. */
9971 mips_set_option_string (string_ptr
, new_value
)
9972 const char **string_ptr
, *new_value
;
9974 if (*string_ptr
!= 0 && strcasecmp (*string_ptr
, new_value
) != 0)
9975 as_warn (_("A different %s was already specified, is now %s"),
9976 string_ptr
== &mips_arch_string
? "-march" : "-mtune",
9979 *string_ptr
= new_value
;
9983 md_parse_option (c
, arg
)
9989 case OPTION_CONSTRUCT_FLOATS
:
9990 mips_disable_float_construction
= 0;
9993 case OPTION_NO_CONSTRUCT_FLOATS
:
9994 mips_disable_float_construction
= 1;
10006 target_big_endian
= 1;
10010 target_big_endian
= 0;
10018 if (arg
&& arg
[1] == '0')
10028 mips_debug
= atoi (arg
);
10029 /* When the MIPS assembler sees -g or -g2, it does not do
10030 optimizations which limit full symbolic debugging. We take
10031 that to be equivalent to -O0. */
10032 if (mips_debug
== 2)
10037 file_mips_isa
= ISA_MIPS1
;
10041 file_mips_isa
= ISA_MIPS2
;
10045 file_mips_isa
= ISA_MIPS3
;
10049 file_mips_isa
= ISA_MIPS4
;
10053 file_mips_isa
= ISA_MIPS5
;
10056 case OPTION_MIPS32
:
10057 file_mips_isa
= ISA_MIPS32
;
10060 case OPTION_MIPS64
:
10061 file_mips_isa
= ISA_MIPS64
;
10065 mips_set_option_string (&mips_tune_string
, arg
);
10069 mips_set_option_string (&mips_arch_string
, arg
);
10073 mips_set_option_string (&mips_arch_string
, "4650");
10074 mips_set_option_string (&mips_tune_string
, "4650");
10077 case OPTION_NO_M4650
:
10081 mips_set_option_string (&mips_arch_string
, "4010");
10082 mips_set_option_string (&mips_tune_string
, "4010");
10085 case OPTION_NO_M4010
:
10089 mips_set_option_string (&mips_arch_string
, "4100");
10090 mips_set_option_string (&mips_tune_string
, "4100");
10093 case OPTION_NO_M4100
:
10097 mips_set_option_string (&mips_arch_string
, "3900");
10098 mips_set_option_string (&mips_tune_string
, "3900");
10101 case OPTION_NO_M3900
:
10105 mips_opts
.ase_mdmx
= 1;
10108 case OPTION_NO_MDMX
:
10109 mips_opts
.ase_mdmx
= 0;
10112 case OPTION_MIPS16
:
10113 mips_opts
.mips16
= 1;
10114 mips_no_prev_insn (false);
10117 case OPTION_NO_MIPS16
:
10118 mips_opts
.mips16
= 0;
10119 mips_no_prev_insn (false);
10122 case OPTION_MIPS3D
:
10123 mips_opts
.ase_mips3d
= 1;
10126 case OPTION_NO_MIPS3D
:
10127 mips_opts
.ase_mips3d
= 0;
10130 case OPTION_MEMBEDDED_PIC
:
10131 mips_pic
= EMBEDDED_PIC
;
10132 if (USE_GLOBAL_POINTER_OPT
&& g_switch_seen
)
10134 as_bad (_("-G may not be used with embedded PIC code"));
10137 g_switch_value
= 0x7fffffff;
10141 /* When generating ELF code, we permit -KPIC and -call_shared to
10142 select SVR4_PIC, and -non_shared to select no PIC. This is
10143 intended to be compatible with Irix 5. */
10144 case OPTION_CALL_SHARED
:
10145 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10147 as_bad (_("-call_shared is supported only for ELF format"));
10150 mips_pic
= SVR4_PIC
;
10151 if (g_switch_seen
&& g_switch_value
!= 0)
10153 as_bad (_("-G may not be used with SVR4 PIC code"));
10156 g_switch_value
= 0;
10159 case OPTION_NON_SHARED
:
10160 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10162 as_bad (_("-non_shared is supported only for ELF format"));
10168 /* The -xgot option tells the assembler to use 32 offsets when
10169 accessing the got in SVR4_PIC mode. It is for Irix
10174 #endif /* OBJ_ELF */
10177 if (! USE_GLOBAL_POINTER_OPT
)
10179 as_bad (_("-G is not supported for this configuration"));
10182 else if (mips_pic
== SVR4_PIC
|| mips_pic
== EMBEDDED_PIC
)
10184 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10188 g_switch_value
= atoi (arg
);
10193 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10196 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10198 as_bad (_("-32 is supported for ELF format only"));
10201 mips_abi
= O32_ABI
;
10205 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10207 as_bad (_("-n32 is supported for ELF format only"));
10210 mips_abi
= N32_ABI
;
10214 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10216 as_bad (_("-64 is supported for ELF format only"));
10219 mips_abi
= N64_ABI
;
10220 if (! support_64bit_objects())
10221 as_fatal (_("No compiled in support for 64 bit object file format"));
10223 #endif /* OBJ_ELF */
10226 file_mips_gp32
= 1;
10230 file_mips_gp32
= 0;
10234 file_mips_fp32
= 1;
10238 file_mips_fp32
= 0;
10243 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10245 as_bad (_("-mabi is supported for ELF format only"));
10248 if (strcmp (arg
, "32") == 0)
10249 mips_abi
= O32_ABI
;
10250 else if (strcmp (arg
, "o64") == 0)
10251 mips_abi
= O64_ABI
;
10252 else if (strcmp (arg
, "n32") == 0)
10253 mips_abi
= N32_ABI
;
10254 else if (strcmp (arg
, "64") == 0)
10256 mips_abi
= N64_ABI
;
10257 if (! support_64bit_objects())
10258 as_fatal (_("No compiled in support for 64 bit object file "
10261 else if (strcmp (arg
, "eabi") == 0)
10262 mips_abi
= EABI_ABI
;
10265 as_fatal (_("invalid abi -mabi=%s"), arg
);
10269 #endif /* OBJ_ELF */
10271 case OPTION_M7000_HILO_FIX
:
10272 mips_7000_hilo_fix
= true;
10275 case OPTION_MNO_7000_HILO_FIX
:
10276 mips_7000_hilo_fix
= false;
10280 case OPTION_MDEBUG
:
10281 mips_flag_mdebug
= true;
10284 case OPTION_NO_MDEBUG
:
10285 mips_flag_mdebug
= false;
10287 #endif /* OBJ_ELF */
10296 /* Set up globals to generate code for the ISA or processor
10297 described by INFO. */
10300 mips_set_architecture (info
)
10301 const struct mips_cpu_info
*info
;
10305 mips_arch_info
= info
;
10306 mips_arch
= info
->cpu
;
10307 mips_opts
.isa
= info
->isa
;
10312 /* Likewise for tuning. */
10315 mips_set_tune (info
)
10316 const struct mips_cpu_info
*info
;
10320 mips_tune_info
= info
;
10321 mips_tune
= info
->cpu
;
10327 mips_after_parse_args ()
10329 /* GP relative stuff not working for PE */
10330 if (strncmp (TARGET_OS
, "pe", 2) == 0
10331 && g_switch_value
!= 0)
10334 as_bad (_("-G not supported in this configuration."));
10335 g_switch_value
= 0;
10338 /* The following code determines the architecture and register size.
10339 Similar code was added to GCC 3.3 (see override_options() in
10340 config/mips/mips.c). The GAS and GCC code should be kept in sync
10341 as much as possible. */
10343 if (mips_arch_string
!= 0)
10344 mips_set_architecture (mips_parse_cpu ("-march", mips_arch_string
));
10346 if (mips_tune_string
!= 0)
10347 mips_set_tune (mips_parse_cpu ("-mtune", mips_tune_string
));
10349 if (file_mips_isa
!= ISA_UNKNOWN
)
10351 /* Handle -mipsN. At this point, file_mips_isa contains the
10352 ISA level specified by -mipsN, while mips_opts.isa contains
10353 the -march selection (if any). */
10354 if (mips_arch_info
!= 0)
10356 /* -march takes precedence over -mipsN, since it is more descriptive.
10357 There's no harm in specifying both as long as the ISA levels
10359 if (file_mips_isa
!= mips_opts
.isa
)
10360 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
10361 mips_cpu_info_from_isa (file_mips_isa
)->name
,
10362 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
10365 mips_set_architecture (mips_cpu_info_from_isa (file_mips_isa
));
10368 if (mips_arch_info
== 0)
10369 mips_set_architecture (mips_parse_cpu ("default CPU",
10370 MIPS_CPU_STRING_DEFAULT
));
10372 if (ABI_NEEDS_64BIT_REGS (mips_abi
) && !ISA_HAS_64BIT_REGS (mips_opts
.isa
))
10373 as_bad ("-march=%s is not compatible with the selected ABI",
10374 mips_arch_info
->name
);
10376 /* Optimize for mips_arch, unless -mtune selects a different processor. */
10377 if (mips_tune_info
== 0)
10378 mips_set_tune (mips_arch_info
);
10380 if (file_mips_gp32
>= 0)
10382 /* The user specified the size of the integer registers. Make sure
10383 it agrees with the ABI and ISA. */
10384 if (file_mips_gp32
== 0 && !ISA_HAS_64BIT_REGS (mips_opts
.isa
))
10385 as_bad (_("-mgp64 used with a 32-bit processor"));
10386 else if (file_mips_gp32
== 1 && ABI_NEEDS_64BIT_REGS (mips_abi
))
10387 as_bad (_("-mgp32 used with a 64-bit ABI"));
10388 else if (file_mips_gp32
== 0 && ABI_NEEDS_32BIT_REGS (mips_abi
))
10389 as_bad (_("-mgp64 used with a 32-bit ABI"));
10393 /* Infer the integer register size from the ABI and processor.
10394 Restrict ourselves to 32-bit registers if that's all the
10395 processor has, or if the ABI cannot handle 64-bit registers. */
10396 file_mips_gp32
= (ABI_NEEDS_32BIT_REGS (mips_abi
)
10397 || !ISA_HAS_64BIT_REGS (mips_opts
.isa
));
10400 /* ??? GAS treats single-float processors as though they had 64-bit
10401 float registers (although it complains when double-precision
10402 instructions are used). As things stand, saying they have 32-bit
10403 registers would lead to spurious "register must be even" messages.
10404 So here we assume float registers are always the same size as
10405 integer ones, unless the user says otherwise. */
10406 if (file_mips_fp32
< 0)
10407 file_mips_fp32
= file_mips_gp32
;
10409 /* End of GCC-shared inference code. */
10411 /* ??? When do we want this flag to be set? Who uses it? */
10412 if (file_mips_gp32
== 1
10413 && mips_abi
== NO_ABI
10414 && ISA_HAS_64BIT_REGS (mips_opts
.isa
))
10415 mips_32bitmode
= 1;
10417 if (mips_opts
.isa
== ISA_MIPS1
&& mips_trap
)
10418 as_bad (_("trap exception not supported at ISA 1"));
10420 /* If the selected architecture includes support for ASEs, enable
10421 generation of code for them. */
10422 if (mips_opts
.mips16
== -1)
10423 mips_opts
.mips16
= (CPU_HAS_MIPS16 (mips_arch
)) ? 1 : 0;
10424 if (mips_opts
.ase_mips3d
== -1)
10425 mips_opts
.ase_mips3d
= (CPU_HAS_MIPS3D (mips_arch
)) ? 1 : 0;
10426 if (mips_opts
.ase_mdmx
== -1)
10427 mips_opts
.ase_mdmx
= (CPU_HAS_MDMX (mips_arch
)) ? 1 : 0;
10429 file_mips_isa
= mips_opts
.isa
;
10430 file_ase_mips16
= mips_opts
.mips16
;
10431 file_ase_mips3d
= mips_opts
.ase_mips3d
;
10432 file_ase_mdmx
= mips_opts
.ase_mdmx
;
10433 mips_opts
.gp32
= file_mips_gp32
;
10434 mips_opts
.fp32
= file_mips_fp32
;
10439 if (mips_flag_mdebug
< 0)
10441 #ifdef OBJ_MAYBE_ECOFF
10442 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
)
10443 mips_flag_mdebug
= 1;
10445 #endif /* OBJ_MAYBE_ECOFF */
10446 mips_flag_mdebug
= 0;
10451 mips_init_after_args ()
10453 /* initialize opcodes */
10454 bfd_mips_num_opcodes
= bfd_mips_num_builtin_opcodes
;
10455 mips_opcodes
= (struct mips_opcode
*) mips_builtin_opcodes
;
10459 md_pcrel_from (fixP
)
10462 if (OUTPUT_FLAVOR
!= bfd_target_aout_flavour
10463 && fixP
->fx_addsy
!= (symbolS
*) NULL
10464 && ! S_IS_DEFINED (fixP
->fx_addsy
))
10466 /* This makes a branch to an undefined symbol be a branch to the
10467 current location. */
10468 if (mips_pic
== EMBEDDED_PIC
)
10474 /* Return the address of the delay slot. */
10475 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
10478 /* This is called before the symbol table is processed. In order to
10479 work with gcc when using mips-tfile, we must keep all local labels.
10480 However, in other cases, we want to discard them. If we were
10481 called with -g, but we didn't see any debugging information, it may
10482 mean that gcc is smuggling debugging information through to
10483 mips-tfile, in which case we must generate all local labels. */
10486 mips_frob_file_before_adjust ()
10488 #ifndef NO_ECOFF_DEBUGGING
10489 if (ECOFF_DEBUGGING
10491 && ! ecoff_debugging_seen
)
10492 flag_keep_locals
= 1;
10496 /* Sort any unmatched HI16_S relocs so that they immediately precede
10497 the corresponding LO reloc. This is called before md_apply_fix3 and
10498 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10499 explicit use of the %hi modifier. */
10504 struct mips_hi_fixup
*l
;
10506 for (l
= mips_hi_fixup_list
; l
!= NULL
; l
= l
->next
)
10508 segment_info_type
*seginfo
;
10511 assert (l
->fixp
->fx_r_type
== BFD_RELOC_HI16_S
);
10513 /* Check quickly whether the next fixup happens to be a matching
10515 if (l
->fixp
->fx_next
!= NULL
10516 && l
->fixp
->fx_next
->fx_r_type
== BFD_RELOC_LO16
10517 && l
->fixp
->fx_addsy
== l
->fixp
->fx_next
->fx_addsy
10518 && l
->fixp
->fx_offset
== l
->fixp
->fx_next
->fx_offset
)
10521 /* Look through the fixups for this segment for a matching %lo.
10522 When we find one, move the %hi just in front of it. We do
10523 this in two passes. In the first pass, we try to find a
10524 unique %lo. In the second pass, we permit multiple %hi
10525 relocs for a single %lo (this is a GNU extension). */
10526 seginfo
= seg_info (l
->seg
);
10527 for (pass
= 0; pass
< 2; pass
++)
10532 for (f
= seginfo
->fix_root
; f
!= NULL
; f
= f
->fx_next
)
10534 /* Check whether this is a %lo fixup which matches l->fixp. */
10535 if (f
->fx_r_type
== BFD_RELOC_LO16
10536 && f
->fx_addsy
== l
->fixp
->fx_addsy
10537 && f
->fx_offset
== l
->fixp
->fx_offset
10540 || prev
->fx_r_type
!= BFD_RELOC_HI16_S
10541 || prev
->fx_addsy
!= f
->fx_addsy
10542 || prev
->fx_offset
!= f
->fx_offset
))
10546 /* Move l->fixp before f. */
10547 for (pf
= &seginfo
->fix_root
;
10549 pf
= &(*pf
)->fx_next
)
10550 assert (*pf
!= NULL
);
10552 *pf
= l
->fixp
->fx_next
;
10554 l
->fixp
->fx_next
= f
;
10556 seginfo
->fix_root
= l
->fixp
;
10558 prev
->fx_next
= l
->fixp
;
10569 #if 0 /* GCC code motion plus incomplete dead code elimination
10570 can leave a %hi without a %lo. */
10572 as_warn_where (l
->fixp
->fx_file
, l
->fixp
->fx_line
,
10573 _("Unmatched %%hi reloc"));
10579 /* When generating embedded PIC code we need to use a special
10580 relocation to represent the difference of two symbols in the .text
10581 section (switch tables use a difference of this sort). See
10582 include/coff/mips.h for details. This macro checks whether this
10583 fixup requires the special reloc. */
10584 #define SWITCH_TABLE(fixp) \
10585 ((fixp)->fx_r_type == BFD_RELOC_32 \
10586 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10587 && (fixp)->fx_addsy != NULL \
10588 && (fixp)->fx_subsy != NULL \
10589 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10590 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10592 /* When generating embedded PIC code we must keep all PC relative
10593 relocations, in case the linker has to relax a call. We also need
10594 to keep relocations for switch table entries.
10596 We may have combined relocations without symbols in the N32/N64 ABI.
10597 We have to prevent gas from dropping them. */
10600 mips_force_relocation (fixp
)
10603 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
10604 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
10608 && S_GET_SEGMENT (fixp
->fx_addsy
) == bfd_abs_section_ptr
10609 && (fixp
->fx_r_type
== BFD_RELOC_MIPS_SUB
10610 || fixp
->fx_r_type
== BFD_RELOC_HI16_S
10611 || fixp
->fx_r_type
== BFD_RELOC_LO16
))
10614 return (mips_pic
== EMBEDDED_PIC
10616 || SWITCH_TABLE (fixp
)
10617 || fixp
->fx_r_type
== BFD_RELOC_PCREL_HI16_S
10618 || fixp
->fx_r_type
== BFD_RELOC_PCREL_LO16
));
10623 mips_need_elf_addend_fixup (fixP
)
10626 if (S_GET_OTHER (fixP
->fx_addsy
) == STO_MIPS16
)
10628 if (mips_pic
== EMBEDDED_PIC
10629 && S_IS_WEAK (fixP
->fx_addsy
))
10631 if (mips_pic
!= EMBEDDED_PIC
10632 && (S_IS_WEAK (fixP
->fx_addsy
)
10633 || S_IS_EXTERNAL (fixP
->fx_addsy
))
10634 && !S_IS_COMMON (fixP
->fx_addsy
))
10636 if (symbol_used_in_reloc_p (fixP
->fx_addsy
)
10637 && (((bfd_get_section_flags (stdoutput
,
10638 S_GET_SEGMENT (fixP
->fx_addsy
))
10639 & SEC_LINK_ONCE
) != 0)
10640 || !strncmp (segment_name (S_GET_SEGMENT (fixP
->fx_addsy
)),
10642 sizeof (".gnu.linkonce") - 1)))
10648 /* Apply a fixup to the object file. */
10651 md_apply_fix3 (fixP
, valP
, seg
)
10654 segT seg ATTRIBUTE_UNUSED
;
10660 assert (fixP
->fx_size
== 4
10661 || fixP
->fx_r_type
== BFD_RELOC_16
10662 || fixP
->fx_r_type
== BFD_RELOC_32
10663 || fixP
->fx_r_type
== BFD_RELOC_MIPS_JMP
10664 || fixP
->fx_r_type
== BFD_RELOC_HI16_S
10665 || fixP
->fx_r_type
== BFD_RELOC_LO16
10666 || fixP
->fx_r_type
== BFD_RELOC_GPREL16
10667 || fixP
->fx_r_type
== BFD_RELOC_MIPS_LITERAL
10668 || fixP
->fx_r_type
== BFD_RELOC_GPREL32
10669 || fixP
->fx_r_type
== BFD_RELOC_64
10670 || fixP
->fx_r_type
== BFD_RELOC_CTOR
10671 || fixP
->fx_r_type
== BFD_RELOC_MIPS_SUB
10672 || fixP
->fx_r_type
== BFD_RELOC_MIPS_HIGHEST
10673 || fixP
->fx_r_type
== BFD_RELOC_MIPS_HIGHER
10674 || fixP
->fx_r_type
== BFD_RELOC_MIPS_SCN_DISP
10675 || fixP
->fx_r_type
== BFD_RELOC_MIPS_REL16
10676 || fixP
->fx_r_type
== BFD_RELOC_MIPS_RELGOT
10677 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
10678 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
10679 || fixP
->fx_r_type
== BFD_RELOC_MIPS_JALR
);
10683 /* If we aren't adjusting this fixup to be against the section
10684 symbol, we need to adjust the value. */
10686 if (fixP
->fx_addsy
!= NULL
&& OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
10688 if (mips_need_elf_addend_fixup (fixP
))
10690 reloc_howto_type
*howto
;
10691 valueT symval
= S_GET_VALUE (fixP
->fx_addsy
);
10695 howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
10696 if (value
!= 0 && howto
->partial_inplace
&& ! fixP
->fx_pcrel
)
10698 /* In this case, the bfd_install_relocation routine will
10699 incorrectly add the symbol value back in. We just want
10700 the addend to appear in the object file. */
10703 /* Make sure the addend is still non-zero. If it became zero
10704 after the last operation, set it to a spurious value and
10705 subtract the same value from the object file's contents. */
10710 /* The in-place addends for LO16 relocations are signed;
10711 leave the matching HI16 in-place addends as zero. */
10712 if (fixP
->fx_r_type
!= BFD_RELOC_HI16_S
)
10714 bfd_vma contents
, mask
, field
;
10716 contents
= bfd_get_bits (fixP
->fx_frag
->fr_literal
10719 target_big_endian
);
10721 /* MASK has bits set where the relocation should go.
10722 FIELD is -value, shifted into the appropriate place
10723 for this relocation. */
10724 mask
= 1 << (howto
->bitsize
- 1);
10725 mask
= (((mask
- 1) << 1) | 1) << howto
->bitpos
;
10726 field
= (-value
>> howto
->rightshift
) << howto
->bitpos
;
10728 bfd_put_bits ((field
& mask
) | (contents
& ~mask
),
10729 fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
10731 target_big_endian
);
10737 /* This code was generated using trial and error and so is
10738 fragile and not trustworthy. If you change it, you should
10739 rerun the elf-rel, elf-rel2, and empic testcases and ensure
10740 they still pass. */
10741 if (fixP
->fx_pcrel
|| fixP
->fx_subsy
!= NULL
)
10743 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
10745 /* BFD's REL handling, for MIPS, is _very_ weird.
10746 This gives the right results, but it can't possibly
10747 be the way things are supposed to work. */
10748 if ((fixP
->fx_r_type
!= BFD_RELOC_16_PCREL
10749 && fixP
->fx_r_type
!= BFD_RELOC_16_PCREL_S2
)
10750 || S_GET_SEGMENT (fixP
->fx_addsy
) != undefined_section
)
10751 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
10756 fixP
->fx_addnumber
= value
; /* Remember value for tc_gen_reloc. */
10758 if (fixP
->fx_addsy
== NULL
&& ! fixP
->fx_pcrel
)
10761 switch (fixP
->fx_r_type
)
10763 case BFD_RELOC_MIPS_JMP
:
10764 case BFD_RELOC_MIPS_SHIFT5
:
10765 case BFD_RELOC_MIPS_SHIFT6
:
10766 case BFD_RELOC_MIPS_GOT_DISP
:
10767 case BFD_RELOC_MIPS_GOT_PAGE
:
10768 case BFD_RELOC_MIPS_GOT_OFST
:
10769 case BFD_RELOC_MIPS_SUB
:
10770 case BFD_RELOC_MIPS_INSERT_A
:
10771 case BFD_RELOC_MIPS_INSERT_B
:
10772 case BFD_RELOC_MIPS_DELETE
:
10773 case BFD_RELOC_MIPS_HIGHEST
:
10774 case BFD_RELOC_MIPS_HIGHER
:
10775 case BFD_RELOC_MIPS_SCN_DISP
:
10776 case BFD_RELOC_MIPS_REL16
:
10777 case BFD_RELOC_MIPS_RELGOT
:
10778 case BFD_RELOC_MIPS_JALR
:
10779 case BFD_RELOC_HI16
:
10780 case BFD_RELOC_HI16_S
:
10781 case BFD_RELOC_GPREL16
:
10782 case BFD_RELOC_MIPS_LITERAL
:
10783 case BFD_RELOC_MIPS_CALL16
:
10784 case BFD_RELOC_MIPS_GOT16
:
10785 case BFD_RELOC_GPREL32
:
10786 case BFD_RELOC_MIPS_GOT_HI16
:
10787 case BFD_RELOC_MIPS_GOT_LO16
:
10788 case BFD_RELOC_MIPS_CALL_HI16
:
10789 case BFD_RELOC_MIPS_CALL_LO16
:
10790 case BFD_RELOC_MIPS16_GPREL
:
10791 if (fixP
->fx_pcrel
)
10792 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
10793 _("Invalid PC relative reloc"));
10794 /* Nothing needed to do. The value comes from the reloc entry */
10797 case BFD_RELOC_MIPS16_JMP
:
10798 /* We currently always generate a reloc against a symbol, which
10799 means that we don't want an addend even if the symbol is
10801 fixP
->fx_addnumber
= 0;
10804 case BFD_RELOC_PCREL_HI16_S
:
10805 /* The addend for this is tricky if it is internal, so we just
10806 do everything here rather than in bfd_install_relocation. */
10807 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
10812 && (symbol_get_bfdsym (fixP
->fx_addsy
)->flags
& BSF_SECTION_SYM
) == 0)
10814 /* For an external symbol adjust by the address to make it
10815 pcrel_offset. We use the address of the RELLO reloc
10816 which follows this one. */
10817 value
+= (fixP
->fx_next
->fx_frag
->fr_address
10818 + fixP
->fx_next
->fx_where
);
10820 value
= ((value
+ 0x8000) >> 16) & 0xffff;
10821 buf
= (bfd_byte
*) fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
10822 if (target_big_endian
)
10824 md_number_to_chars ((char *) buf
, value
, 2);
10827 case BFD_RELOC_PCREL_LO16
:
10828 /* The addend for this is tricky if it is internal, so we just
10829 do everything here rather than in bfd_install_relocation. */
10830 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
10835 && (symbol_get_bfdsym (fixP
->fx_addsy
)->flags
& BSF_SECTION_SYM
) == 0)
10836 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
10837 buf
= (bfd_byte
*) fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
10838 if (target_big_endian
)
10840 md_number_to_chars ((char *) buf
, value
, 2);
10844 /* This is handled like BFD_RELOC_32, but we output a sign
10845 extended value if we are only 32 bits. */
10847 || (mips_pic
== EMBEDDED_PIC
&& SWITCH_TABLE (fixP
)))
10849 if (8 <= sizeof (valueT
))
10850 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
10857 w1
= w2
= fixP
->fx_where
;
10858 if (target_big_endian
)
10862 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ w1
, value
, 4);
10863 if ((value
& 0x80000000) != 0)
10867 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ w2
, hiv
, 4);
10872 case BFD_RELOC_RVA
:
10874 /* If we are deleting this reloc entry, we must fill in the
10875 value now. This can happen if we have a .word which is not
10876 resolved when it appears but is later defined. We also need
10877 to fill in the value if this is an embedded PIC switch table
10880 || (mips_pic
== EMBEDDED_PIC
&& SWITCH_TABLE (fixP
)))
10881 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
10886 /* If we are deleting this reloc entry, we must fill in the
10888 assert (fixP
->fx_size
== 2);
10890 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
10894 case BFD_RELOC_LO16
:
10895 /* When handling an embedded PIC switch statement, we can wind
10896 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
10899 if (value
+ 0x8000 > 0xffff)
10900 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
10901 _("relocation overflow"));
10902 buf
= (bfd_byte
*) fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
10903 if (target_big_endian
)
10905 md_number_to_chars ((char *) buf
, value
, 2);
10909 case BFD_RELOC_16_PCREL_S2
:
10910 if ((value
& 0x3) != 0)
10911 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
10912 _("Branch to odd address (%lx)"), (long) value
);
10914 /* Fall through. */
10916 case BFD_RELOC_16_PCREL
:
10918 * We need to save the bits in the instruction since fixup_segment()
10919 * might be deleting the relocation entry (i.e., a branch within
10920 * the current segment).
10922 if (!fixP
->fx_done
&& value
!= 0)
10924 /* If 'value' is zero, the remaining reloc code won't actually
10925 do the store, so it must be done here. This is probably
10926 a bug somewhere. */
10928 && (fixP
->fx_r_type
!= BFD_RELOC_16_PCREL_S2
10929 || fixP
->fx_addsy
== NULL
/* ??? */
10930 || ! S_IS_DEFINED (fixP
->fx_addsy
)))
10931 value
-= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
10933 value
= (offsetT
) value
>> 2;
10935 /* update old instruction data */
10936 buf
= (bfd_byte
*) (fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
);
10937 if (target_big_endian
)
10938 insn
= (buf
[0] << 24) | (buf
[1] << 16) | (buf
[2] << 8) | buf
[3];
10940 insn
= (buf
[3] << 24) | (buf
[2] << 16) | (buf
[1] << 8) | buf
[0];
10942 if (value
+ 0x8000 <= 0xffff)
10943 insn
|= value
& 0xffff;
10946 /* The branch offset is too large. If this is an
10947 unconditional branch, and we are not generating PIC code,
10948 we can convert it to an absolute jump instruction. */
10949 if (mips_pic
== NO_PIC
10951 && fixP
->fx_frag
->fr_address
>= text_section
->vma
10952 && (fixP
->fx_frag
->fr_address
10953 < text_section
->vma
+ text_section
->_raw_size
)
10954 && ((insn
& 0xffff0000) == 0x10000000 /* beq $0,$0 */
10955 || (insn
& 0xffff0000) == 0x04010000 /* bgez $0 */
10956 || (insn
& 0xffff0000) == 0x04110000)) /* bgezal $0 */
10958 if ((insn
& 0xffff0000) == 0x04110000) /* bgezal $0 */
10959 insn
= 0x0c000000; /* jal */
10961 insn
= 0x08000000; /* j */
10962 fixP
->fx_r_type
= BFD_RELOC_MIPS_JMP
;
10964 fixP
->fx_addsy
= section_symbol (text_section
);
10965 fixP
->fx_addnumber
= (value
<< 2) + md_pcrel_from (fixP
);
10969 /* FIXME. It would be possible in principle to handle
10970 conditional branches which overflow. They could be
10971 transformed into a branch around a jump. This would
10972 require setting up variant frags for each different
10973 branch type. The native MIPS assembler attempts to
10974 handle these cases, but it appears to do it
10976 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
10977 _("Branch out of range"));
10981 md_number_to_chars ((char *) buf
, (valueT
) insn
, 4);
10984 case BFD_RELOC_VTABLE_INHERIT
:
10987 && !S_IS_DEFINED (fixP
->fx_addsy
)
10988 && !S_IS_WEAK (fixP
->fx_addsy
))
10989 S_SET_WEAK (fixP
->fx_addsy
);
10992 case BFD_RELOC_VTABLE_ENTRY
:
11006 const struct mips_opcode
*p
;
11007 int treg
, sreg
, dreg
, shamt
;
11012 for (i
= 0; i
< NUMOPCODES
; ++i
)
11014 p
= &mips_opcodes
[i
];
11015 if (((oc
& p
->mask
) == p
->match
) && (p
->pinfo
!= INSN_MACRO
))
11017 printf ("%08lx %s\t", oc
, p
->name
);
11018 treg
= (oc
>> 16) & 0x1f;
11019 sreg
= (oc
>> 21) & 0x1f;
11020 dreg
= (oc
>> 11) & 0x1f;
11021 shamt
= (oc
>> 6) & 0x1f;
11023 for (args
= p
->args
;; ++args
)
11034 printf ("%c", *args
);
11038 assert (treg
== sreg
);
11039 printf ("$%d,$%d", treg
, sreg
);
11044 printf ("$%d", dreg
);
11049 printf ("$%d", treg
);
11053 printf ("0x%x", treg
);
11058 printf ("$%d", sreg
);
11062 printf ("0x%08lx", oc
& 0x1ffffff);
11069 printf ("%d", imm
);
11074 printf ("$%d", shamt
);
11085 printf (_("%08lx UNDEFINED\n"), oc
);
11096 name
= input_line_pointer
;
11097 c
= get_symbol_end ();
11098 p
= (symbolS
*) symbol_find_or_make (name
);
11099 *input_line_pointer
= c
;
11103 /* Align the current frag to a given power of two. The MIPS assembler
11104 also automatically adjusts any preceding label. */
11107 mips_align (to
, fill
, label
)
11112 mips_emit_delays (false);
11113 frag_align (to
, fill
, 0);
11114 record_alignment (now_seg
, to
);
11117 assert (S_GET_SEGMENT (label
) == now_seg
);
11118 symbol_set_frag (label
, frag_now
);
11119 S_SET_VALUE (label
, (valueT
) frag_now_fix ());
11123 /* Align to a given power of two. .align 0 turns off the automatic
11124 alignment used by the data creating pseudo-ops. */
11128 int x ATTRIBUTE_UNUSED
;
11131 register long temp_fill
;
11132 long max_alignment
= 15;
11136 o Note that the assembler pulls down any immediately preceeding label
11137 to the aligned address.
11138 o It's not documented but auto alignment is reinstated by
11139 a .align pseudo instruction.
11140 o Note also that after auto alignment is turned off the mips assembler
11141 issues an error on attempt to assemble an improperly aligned data item.
11146 temp
= get_absolute_expression ();
11147 if (temp
> max_alignment
)
11148 as_bad (_("Alignment too large: %d. assumed."), temp
= max_alignment
);
11151 as_warn (_("Alignment negative: 0 assumed."));
11154 if (*input_line_pointer
== ',')
11156 ++input_line_pointer
;
11157 temp_fill
= get_absolute_expression ();
11164 mips_align (temp
, (int) temp_fill
,
11165 insn_labels
!= NULL
? insn_labels
->label
: NULL
);
11172 demand_empty_rest_of_line ();
11176 mips_flush_pending_output ()
11178 mips_emit_delays (false);
11179 mips_clear_insn_labels ();
11188 /* When generating embedded PIC code, we only use the .text, .lit8,
11189 .sdata and .sbss sections. We change the .data and .rdata
11190 pseudo-ops to use .sdata. */
11191 if (mips_pic
== EMBEDDED_PIC
11192 && (sec
== 'd' || sec
== 'r'))
11196 /* The ELF backend needs to know that we are changing sections, so
11197 that .previous works correctly. We could do something like check
11198 for an obj_section_change_hook macro, but that might be confusing
11199 as it would not be appropriate to use it in the section changing
11200 functions in read.c, since obj-elf.c intercepts those. FIXME:
11201 This should be cleaner, somehow. */
11202 obj_elf_section_change_hook ();
11205 mips_emit_delays (false);
11215 subseg_set (bss_section
, (subsegT
) get_absolute_expression ());
11216 demand_empty_rest_of_line ();
11220 if (USE_GLOBAL_POINTER_OPT
)
11222 seg
= subseg_new (RDATA_SECTION_NAME
,
11223 (subsegT
) get_absolute_expression ());
11224 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11226 bfd_set_section_flags (stdoutput
, seg
,
11232 if (strcmp (TARGET_OS
, "elf") != 0)
11233 record_alignment (seg
, 4);
11235 demand_empty_rest_of_line ();
11239 as_bad (_("No read only data section in this object file format"));
11240 demand_empty_rest_of_line ();
11246 if (USE_GLOBAL_POINTER_OPT
)
11248 seg
= subseg_new (".sdata", (subsegT
) get_absolute_expression ());
11249 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11251 bfd_set_section_flags (stdoutput
, seg
,
11252 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
11254 if (strcmp (TARGET_OS
, "elf") != 0)
11255 record_alignment (seg
, 4);
11257 demand_empty_rest_of_line ();
11262 as_bad (_("Global pointers not supported; recompile -G 0"));
11263 demand_empty_rest_of_line ();
11272 s_change_section (ignore
)
11273 int ignore ATTRIBUTE_UNUSED
;
11275 expressionS rep_exp
;
11277 char *section_name
;
11283 int section_entry_size
;
11284 int section_alignment
;
11288 section_name
= input_line_pointer
;
11289 c
= get_symbol_end ();
11290 next_c
= input_line_pointer
+ 1;
11291 /* just after name is now '\0' */
11292 p
= input_line_pointer
;
11294 /* Do we have .section Name<,"flags"> */
11295 if (c
== '\n' || (c
== ',' && *next_c
== '"') || c
== '"')
11298 input_line_pointer
= section_name
;
11299 obj_elf_section (ignore
);
11302 input_line_pointer
++;
11304 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
11306 section_type
= get_absolute_expression ();
11309 if (*input_line_pointer
++ == ',')
11310 section_flag
= get_absolute_expression ();
11313 if (*input_line_pointer
++ == ',')
11314 section_entry_size
= get_absolute_expression ();
11316 section_entry_size
= 0;
11317 if (*input_line_pointer
++ == ',')
11318 section_alignment
= get_absolute_expression ();
11320 section_alignment
= 0;
11322 obj_elf_change_section (section_name
, section_type
, section_flag
,
11323 section_entry_size
, 0, 0, 0);
11327 mips_enable_auto_align ()
11338 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
11339 mips_emit_delays (false);
11340 if (log_size
> 0 && auto_align
)
11341 mips_align (log_size
, 0, label
);
11342 mips_clear_insn_labels ();
11343 cons (1 << log_size
);
11347 s_float_cons (type
)
11352 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
11354 mips_emit_delays (false);
11359 mips_align (3, 0, label
);
11361 mips_align (2, 0, label
);
11364 mips_clear_insn_labels ();
11369 /* Handle .globl. We need to override it because on Irix 5 you are
11372 where foo is an undefined symbol, to mean that foo should be
11373 considered to be the address of a function. */
11377 int x ATTRIBUTE_UNUSED
;
11384 name
= input_line_pointer
;
11385 c
= get_symbol_end ();
11386 symbolP
= symbol_find_or_make (name
);
11387 *input_line_pointer
= c
;
11388 SKIP_WHITESPACE ();
11390 /* On Irix 5, every global symbol that is not explicitly labelled as
11391 being a function is apparently labelled as being an object. */
11394 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
11399 secname
= input_line_pointer
;
11400 c
= get_symbol_end ();
11401 sec
= bfd_get_section_by_name (stdoutput
, secname
);
11403 as_bad (_("%s: no such section"), secname
);
11404 *input_line_pointer
= c
;
11406 if (sec
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
11407 flag
= BSF_FUNCTION
;
11410 symbol_get_bfdsym (symbolP
)->flags
|= flag
;
11412 S_SET_EXTERNAL (symbolP
);
11413 demand_empty_rest_of_line ();
11418 int x ATTRIBUTE_UNUSED
;
11423 opt
= input_line_pointer
;
11424 c
= get_symbol_end ();
11428 /* FIXME: What does this mean? */
11430 else if (strncmp (opt
, "pic", 3) == 0)
11434 i
= atoi (opt
+ 3);
11438 mips_pic
= SVR4_PIC
;
11440 as_bad (_(".option pic%d not supported"), i
);
11442 if (USE_GLOBAL_POINTER_OPT
&& mips_pic
== SVR4_PIC
)
11444 if (g_switch_seen
&& g_switch_value
!= 0)
11445 as_warn (_("-G may not be used with SVR4 PIC code"));
11446 g_switch_value
= 0;
11447 bfd_set_gp_size (stdoutput
, 0);
11451 as_warn (_("Unrecognized option \"%s\""), opt
);
11453 *input_line_pointer
= c
;
11454 demand_empty_rest_of_line ();
11457 /* This structure is used to hold a stack of .set values. */
11459 struct mips_option_stack
11461 struct mips_option_stack
*next
;
11462 struct mips_set_options options
;
11465 static struct mips_option_stack
*mips_opts_stack
;
11467 /* Handle the .set pseudo-op. */
11471 int x ATTRIBUTE_UNUSED
;
11473 char *name
= input_line_pointer
, ch
;
11475 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
11476 ++input_line_pointer
;
11477 ch
= *input_line_pointer
;
11478 *input_line_pointer
= '\0';
11480 if (strcmp (name
, "reorder") == 0)
11482 if (mips_opts
.noreorder
&& prev_nop_frag
!= NULL
)
11484 /* If we still have pending nops, we can discard them. The
11485 usual nop handling will insert any that are still
11487 prev_nop_frag
->fr_fix
-= (prev_nop_frag_holds
11488 * (mips_opts
.mips16
? 2 : 4));
11489 prev_nop_frag
= NULL
;
11491 mips_opts
.noreorder
= 0;
11493 else if (strcmp (name
, "noreorder") == 0)
11495 mips_emit_delays (true);
11496 mips_opts
.noreorder
= 1;
11497 mips_any_noreorder
= 1;
11499 else if (strcmp (name
, "at") == 0)
11501 mips_opts
.noat
= 0;
11503 else if (strcmp (name
, "noat") == 0)
11505 mips_opts
.noat
= 1;
11507 else if (strcmp (name
, "macro") == 0)
11509 mips_opts
.warn_about_macros
= 0;
11511 else if (strcmp (name
, "nomacro") == 0)
11513 if (mips_opts
.noreorder
== 0)
11514 as_bad (_("`noreorder' must be set before `nomacro'"));
11515 mips_opts
.warn_about_macros
= 1;
11517 else if (strcmp (name
, "move") == 0 || strcmp (name
, "novolatile") == 0)
11519 mips_opts
.nomove
= 0;
11521 else if (strcmp (name
, "nomove") == 0 || strcmp (name
, "volatile") == 0)
11523 mips_opts
.nomove
= 1;
11525 else if (strcmp (name
, "bopt") == 0)
11527 mips_opts
.nobopt
= 0;
11529 else if (strcmp (name
, "nobopt") == 0)
11531 mips_opts
.nobopt
= 1;
11533 else if (strcmp (name
, "mips16") == 0
11534 || strcmp (name
, "MIPS-16") == 0)
11535 mips_opts
.mips16
= 1;
11536 else if (strcmp (name
, "nomips16") == 0
11537 || strcmp (name
, "noMIPS-16") == 0)
11538 mips_opts
.mips16
= 0;
11539 else if (strcmp (name
, "mips3d") == 0)
11540 mips_opts
.ase_mips3d
= 1;
11541 else if (strcmp (name
, "nomips3d") == 0)
11542 mips_opts
.ase_mips3d
= 0;
11543 else if (strcmp (name
, "mdmx") == 0)
11544 mips_opts
.ase_mdmx
= 1;
11545 else if (strcmp (name
, "nomdmx") == 0)
11546 mips_opts
.ase_mdmx
= 0;
11547 else if (strncmp (name
, "mips", 4) == 0)
11551 /* Permit the user to change the ISA on the fly. Needless to
11552 say, misuse can cause serious problems. */
11553 isa
= atoi (name
+ 4);
11557 mips_opts
.gp32
= file_mips_gp32
;
11558 mips_opts
.fp32
= file_mips_fp32
;
11563 mips_opts
.gp32
= 1;
11564 mips_opts
.fp32
= 1;
11570 mips_opts
.gp32
= 0;
11571 mips_opts
.fp32
= 0;
11574 as_bad (_("unknown ISA level %s"), name
+ 4);
11580 case 0: mips_opts
.isa
= file_mips_isa
; break;
11581 case 1: mips_opts
.isa
= ISA_MIPS1
; break;
11582 case 2: mips_opts
.isa
= ISA_MIPS2
; break;
11583 case 3: mips_opts
.isa
= ISA_MIPS3
; break;
11584 case 4: mips_opts
.isa
= ISA_MIPS4
; break;
11585 case 5: mips_opts
.isa
= ISA_MIPS5
; break;
11586 case 32: mips_opts
.isa
= ISA_MIPS32
; break;
11587 case 64: mips_opts
.isa
= ISA_MIPS64
; break;
11588 default: as_bad (_("unknown ISA level %s"), name
+ 4); break;
11591 else if (strcmp (name
, "autoextend") == 0)
11592 mips_opts
.noautoextend
= 0;
11593 else if (strcmp (name
, "noautoextend") == 0)
11594 mips_opts
.noautoextend
= 1;
11595 else if (strcmp (name
, "push") == 0)
11597 struct mips_option_stack
*s
;
11599 s
= (struct mips_option_stack
*) xmalloc (sizeof *s
);
11600 s
->next
= mips_opts_stack
;
11601 s
->options
= mips_opts
;
11602 mips_opts_stack
= s
;
11604 else if (strcmp (name
, "pop") == 0)
11606 struct mips_option_stack
*s
;
11608 s
= mips_opts_stack
;
11610 as_bad (_(".set pop with no .set push"));
11613 /* If we're changing the reorder mode we need to handle
11614 delay slots correctly. */
11615 if (s
->options
.noreorder
&& ! mips_opts
.noreorder
)
11616 mips_emit_delays (true);
11617 else if (! s
->options
.noreorder
&& mips_opts
.noreorder
)
11619 if (prev_nop_frag
!= NULL
)
11621 prev_nop_frag
->fr_fix
-= (prev_nop_frag_holds
11622 * (mips_opts
.mips16
? 2 : 4));
11623 prev_nop_frag
= NULL
;
11627 mips_opts
= s
->options
;
11628 mips_opts_stack
= s
->next
;
11634 as_warn (_("Tried to set unrecognized symbol: %s\n"), name
);
11636 *input_line_pointer
= ch
;
11637 demand_empty_rest_of_line ();
11640 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11641 .option pic2. It means to generate SVR4 PIC calls. */
11644 s_abicalls (ignore
)
11645 int ignore ATTRIBUTE_UNUSED
;
11647 mips_pic
= SVR4_PIC
;
11648 if (USE_GLOBAL_POINTER_OPT
)
11650 if (g_switch_seen
&& g_switch_value
!= 0)
11651 as_warn (_("-G may not be used with SVR4 PIC code"));
11652 g_switch_value
= 0;
11654 bfd_set_gp_size (stdoutput
, 0);
11655 demand_empty_rest_of_line ();
11658 /* Handle the .cpload pseudo-op. This is used when generating SVR4
11659 PIC code. It sets the $gp register for the function based on the
11660 function address, which is in the register named in the argument.
11661 This uses a relocation against _gp_disp, which is handled specially
11662 by the linker. The result is:
11663 lui $gp,%hi(_gp_disp)
11664 addiu $gp,$gp,%lo(_gp_disp)
11665 addu $gp,$gp,.cpload argument
11666 The .cpload argument is normally $25 == $t9. */
11670 int ignore ATTRIBUTE_UNUSED
;
11675 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11676 .cpload is ignored. */
11677 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
11683 /* .cpload should be in a .set noreorder section. */
11684 if (mips_opts
.noreorder
== 0)
11685 as_warn (_(".cpload not in noreorder section"));
11687 ex
.X_op
= O_symbol
;
11688 ex
.X_add_symbol
= symbol_find_or_make ("_gp_disp");
11689 ex
.X_op_symbol
= NULL
;
11690 ex
.X_add_number
= 0;
11692 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
11693 symbol_get_bfdsym (ex
.X_add_symbol
)->flags
|= BSF_OBJECT
;
11695 macro_build_lui (NULL
, &icnt
, &ex
, mips_gp_register
);
11696 macro_build ((char *) NULL
, &icnt
, &ex
, "addiu", "t,r,j",
11697 mips_gp_register
, mips_gp_register
, (int) BFD_RELOC_LO16
);
11699 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "addu", "d,v,t",
11700 mips_gp_register
, mips_gp_register
, tc_get_register (0));
11702 demand_empty_rest_of_line ();
11705 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
11706 .cpsetup $reg1, offset|$reg2, label
11708 If offset is given, this results in:
11709 sd $gp, offset($sp)
11710 lui $gp, %hi(%neg(%gp_rel(label)))
11711 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11712 daddu $gp, $gp, $reg1
11714 If $reg2 is given, this results in:
11715 daddu $reg2, $gp, $0
11716 lui $gp, %hi(%neg(%gp_rel(label)))
11717 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11718 daddu $gp, $gp, $reg1
11719 $reg1 is normally $25 == $t9. */
11722 int ignore ATTRIBUTE_UNUSED
;
11724 expressionS ex_off
;
11725 expressionS ex_sym
;
11730 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
11731 We also need NewABI support. */
11732 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
11738 reg1
= tc_get_register (0);
11739 SKIP_WHITESPACE ();
11740 if (*input_line_pointer
!= ',')
11742 as_bad (_("missing argument separator ',' for .cpsetup"));
11746 ++input_line_pointer
;
11747 SKIP_WHITESPACE ();
11748 if (*input_line_pointer
== '$')
11750 mips_cpreturn_register
= tc_get_register (0);
11751 mips_cpreturn_offset
= -1;
11755 mips_cpreturn_offset
= get_absolute_expression ();
11756 mips_cpreturn_register
= -1;
11758 SKIP_WHITESPACE ();
11759 if (*input_line_pointer
!= ',')
11761 as_bad (_("missing argument separator ',' for .cpsetup"));
11765 ++input_line_pointer
;
11766 SKIP_WHITESPACE ();
11767 expression (&ex_sym
);
11769 if (mips_cpreturn_register
== -1)
11771 ex_off
.X_op
= O_constant
;
11772 ex_off
.X_add_symbol
= NULL
;
11773 ex_off
.X_op_symbol
= NULL
;
11774 ex_off
.X_add_number
= mips_cpreturn_offset
;
11776 macro_build ((char *) NULL
, &icnt
, &ex_off
, "sd", "t,o(b)",
11777 mips_gp_register
, (int) BFD_RELOC_LO16
, SP
);
11780 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "daddu",
11781 "d,v,t", mips_cpreturn_register
, mips_gp_register
, 0);
11783 /* Ensure there's room for the next two instructions, so that `f'
11784 doesn't end up with an address in the wrong frag. */
11787 macro_build ((char *) NULL
, &icnt
, &ex_sym
, "lui", "t,u", mips_gp_register
,
11788 (int) BFD_RELOC_GPREL16
);
11789 fix_new (frag_now
, f
- frag_now
->fr_literal
,
11790 0, NULL
, 0, 0, BFD_RELOC_MIPS_SUB
);
11791 fix_new (frag_now
, f
- frag_now
->fr_literal
,
11792 0, NULL
, 0, 0, BFD_RELOC_HI16_S
);
11795 macro_build ((char *) NULL
, &icnt
, &ex_sym
, "addiu", "t,r,j",
11796 mips_gp_register
, mips_gp_register
, (int) BFD_RELOC_GPREL16
);
11797 fix_new (frag_now
, f
- frag_now
->fr_literal
,
11798 0, NULL
, 0, 0, BFD_RELOC_MIPS_SUB
);
11799 fix_new (frag_now
, f
- frag_now
->fr_literal
,
11800 0, NULL
, 0, 0, BFD_RELOC_LO16
);
11802 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
11803 HAVE_64BIT_ADDRESSES
? "daddu" : "addu", "d,v,t",
11804 mips_gp_register
, mips_gp_register
, reg1
);
11806 demand_empty_rest_of_line ();
11811 int ignore ATTRIBUTE_UNUSED
;
11813 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
11814 .cplocal is ignored. */
11815 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
11821 mips_gp_register
= tc_get_register (0);
11822 demand_empty_rest_of_line ();
11825 /* Handle the .cprestore pseudo-op. This stores $gp into a given
11826 offset from $sp. The offset is remembered, and after making a PIC
11827 call $gp is restored from that location. */
11830 s_cprestore (ignore
)
11831 int ignore ATTRIBUTE_UNUSED
;
11836 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11837 .cprestore is ignored. */
11838 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
11844 mips_cprestore_offset
= get_absolute_expression ();
11845 mips_cprestore_valid
= 1;
11847 ex
.X_op
= O_constant
;
11848 ex
.X_add_symbol
= NULL
;
11849 ex
.X_op_symbol
= NULL
;
11850 ex
.X_add_number
= mips_cprestore_offset
;
11852 macro_build ((char *) NULL
, &icnt
, &ex
, HAVE_32BIT_ADDRESSES
? "sw" : "sd",
11853 "t,o(b)", mips_gp_register
, (int) BFD_RELOC_LO16
, SP
);
11855 demand_empty_rest_of_line ();
11858 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
11859 was given in the preceeding .gpsetup, it results in:
11860 ld $gp, offset($sp)
11862 If a register $reg2 was given there, it results in:
11863 daddiu $gp, $gp, $reg2
11866 s_cpreturn (ignore
)
11867 int ignore ATTRIBUTE_UNUSED
;
11872 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
11873 We also need NewABI support. */
11874 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
11880 if (mips_cpreturn_register
== -1)
11882 ex
.X_op
= O_constant
;
11883 ex
.X_add_symbol
= NULL
;
11884 ex
.X_op_symbol
= NULL
;
11885 ex
.X_add_number
= mips_cpreturn_offset
;
11887 macro_build ((char *) NULL
, &icnt
, &ex
, "ld", "t,o(b)",
11888 mips_gp_register
, (int) BFD_RELOC_LO16
, SP
);
11891 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "daddu",
11892 "d,v,t", mips_gp_register
, mips_cpreturn_register
, 0);
11894 demand_empty_rest_of_line ();
11897 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
11898 code. It sets the offset to use in gp_rel relocations. */
11902 int ignore ATTRIBUTE_UNUSED
;
11904 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
11905 We also need NewABI support. */
11906 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
11912 mips_gprel_offset
= get_absolute_expression ();
11914 demand_empty_rest_of_line ();
11917 /* Handle the .gpword pseudo-op. This is used when generating PIC
11918 code. It generates a 32 bit GP relative reloc. */
11922 int ignore ATTRIBUTE_UNUSED
;
11928 /* When not generating PIC code, this is treated as .word. */
11929 if (mips_pic
!= SVR4_PIC
)
11935 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
11936 mips_emit_delays (true);
11938 mips_align (2, 0, label
);
11939 mips_clear_insn_labels ();
11943 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
11945 as_bad (_("Unsupported use of .gpword"));
11946 ignore_rest_of_line ();
11950 md_number_to_chars (p
, (valueT
) 0, 4);
11951 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4, &ex
, false,
11952 BFD_RELOC_GPREL32
);
11954 demand_empty_rest_of_line ();
11957 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
11958 tables in SVR4 PIC code. */
11962 int ignore ATTRIBUTE_UNUSED
;
11967 /* This is ignored when not generating SVR4 PIC code or if this is NewABI
11969 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
11975 /* Add $gp to the register named as an argument. */
11976 reg
= tc_get_register (0);
11977 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
11978 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
11979 "d,v,t", reg
, reg
, mips_gp_register
);
11981 demand_empty_rest_of_line ();
11984 /* Handle the .insn pseudo-op. This marks instruction labels in
11985 mips16 mode. This permits the linker to handle them specially,
11986 such as generating jalx instructions when needed. We also make
11987 them odd for the duration of the assembly, in order to generate the
11988 right sort of code. We will make them even in the adjust_symtab
11989 routine, while leaving them marked. This is convenient for the
11990 debugger and the disassembler. The linker knows to make them odd
11995 int ignore ATTRIBUTE_UNUSED
;
11997 mips16_mark_labels ();
11999 demand_empty_rest_of_line ();
12002 /* Handle a .stabn directive. We need these in order to mark a label
12003 as being a mips16 text label correctly. Sometimes the compiler
12004 will emit a label, followed by a .stabn, and then switch sections.
12005 If the label and .stabn are in mips16 mode, then the label is
12006 really a mips16 text label. */
12013 mips16_mark_labels ();
12018 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12022 s_mips_weakext (ignore
)
12023 int ignore ATTRIBUTE_UNUSED
;
12030 name
= input_line_pointer
;
12031 c
= get_symbol_end ();
12032 symbolP
= symbol_find_or_make (name
);
12033 S_SET_WEAK (symbolP
);
12034 *input_line_pointer
= c
;
12036 SKIP_WHITESPACE ();
12038 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
12040 if (S_IS_DEFINED (symbolP
))
12042 as_bad ("ignoring attempt to redefine symbol %s",
12043 S_GET_NAME (symbolP
));
12044 ignore_rest_of_line ();
12048 if (*input_line_pointer
== ',')
12050 ++input_line_pointer
;
12051 SKIP_WHITESPACE ();
12055 if (exp
.X_op
!= O_symbol
)
12057 as_bad ("bad .weakext directive");
12058 ignore_rest_of_line ();
12061 symbol_set_value_expression (symbolP
, &exp
);
12064 demand_empty_rest_of_line ();
12067 /* Parse a register string into a number. Called from the ECOFF code
12068 to parse .frame. The argument is non-zero if this is the frame
12069 register, so that we can record it in mips_frame_reg. */
12072 tc_get_register (frame
)
12077 SKIP_WHITESPACE ();
12078 if (*input_line_pointer
++ != '$')
12080 as_warn (_("expected `$'"));
12083 else if (ISDIGIT (*input_line_pointer
))
12085 reg
= get_absolute_expression ();
12086 if (reg
< 0 || reg
>= 32)
12088 as_warn (_("Bad register number"));
12094 if (strncmp (input_line_pointer
, "ra", 2) == 0)
12097 input_line_pointer
+= 2;
12099 else if (strncmp (input_line_pointer
, "fp", 2) == 0)
12102 input_line_pointer
+= 2;
12104 else if (strncmp (input_line_pointer
, "sp", 2) == 0)
12107 input_line_pointer
+= 2;
12109 else if (strncmp (input_line_pointer
, "gp", 2) == 0)
12112 input_line_pointer
+= 2;
12114 else if (strncmp (input_line_pointer
, "at", 2) == 0)
12117 input_line_pointer
+= 2;
12119 else if (strncmp (input_line_pointer
, "kt0", 3) == 0)
12122 input_line_pointer
+= 3;
12124 else if (strncmp (input_line_pointer
, "kt1", 3) == 0)
12127 input_line_pointer
+= 3;
12129 else if (strncmp (input_line_pointer
, "zero", 4) == 0)
12132 input_line_pointer
+= 4;
12136 as_warn (_("Unrecognized register name"));
12138 while (ISALNUM(*input_line_pointer
))
12139 input_line_pointer
++;
12144 mips_frame_reg
= reg
!= 0 ? reg
: SP
;
12145 mips_frame_reg_valid
= 1;
12146 mips_cprestore_valid
= 0;
12152 md_section_align (seg
, addr
)
12156 int align
= bfd_get_section_alignment (stdoutput
, seg
);
12159 /* We don't need to align ELF sections to the full alignment.
12160 However, Irix 5 may prefer that we align them at least to a 16
12161 byte boundary. We don't bother to align the sections if we are
12162 targeted for an embedded system. */
12163 if (strcmp (TARGET_OS
, "elf") == 0)
12169 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
12172 /* Utility routine, called from above as well. If called while the
12173 input file is still being read, it's only an approximation. (For
12174 example, a symbol may later become defined which appeared to be
12175 undefined earlier.) */
12178 nopic_need_relax (sym
, before_relaxing
)
12180 int before_relaxing
;
12185 if (USE_GLOBAL_POINTER_OPT
&& g_switch_value
> 0)
12187 const char *symname
;
12190 /* Find out whether this symbol can be referenced off the $gp
12191 register. It can be if it is smaller than the -G size or if
12192 it is in the .sdata or .sbss section. Certain symbols can
12193 not be referenced off the $gp, although it appears as though
12195 symname
= S_GET_NAME (sym
);
12196 if (symname
!= (const char *) NULL
12197 && (strcmp (symname
, "eprol") == 0
12198 || strcmp (symname
, "etext") == 0
12199 || strcmp (symname
, "_gp") == 0
12200 || strcmp (symname
, "edata") == 0
12201 || strcmp (symname
, "_fbss") == 0
12202 || strcmp (symname
, "_fdata") == 0
12203 || strcmp (symname
, "_ftext") == 0
12204 || strcmp (symname
, "end") == 0
12205 || strcmp (symname
, "_gp_disp") == 0))
12207 else if ((! S_IS_DEFINED (sym
) || S_IS_COMMON (sym
))
12209 #ifndef NO_ECOFF_DEBUGGING
12210 || (symbol_get_obj (sym
)->ecoff_extern_size
!= 0
12211 && (symbol_get_obj (sym
)->ecoff_extern_size
12212 <= g_switch_value
))
12214 /* We must defer this decision until after the whole
12215 file has been read, since there might be a .extern
12216 after the first use of this symbol. */
12217 || (before_relaxing
12218 #ifndef NO_ECOFF_DEBUGGING
12219 && symbol_get_obj (sym
)->ecoff_extern_size
== 0
12221 && S_GET_VALUE (sym
) == 0)
12222 || (S_GET_VALUE (sym
) != 0
12223 && S_GET_VALUE (sym
) <= g_switch_value
)))
12227 const char *segname
;
12229 segname
= segment_name (S_GET_SEGMENT (sym
));
12230 assert (strcmp (segname
, ".lit8") != 0
12231 && strcmp (segname
, ".lit4") != 0);
12232 change
= (strcmp (segname
, ".sdata") != 0
12233 && strcmp (segname
, ".sbss") != 0
12234 && strncmp (segname
, ".sdata.", 7) != 0
12235 && strncmp (segname
, ".gnu.linkonce.s.", 16) != 0);
12240 /* We are not optimizing for the $gp register. */
12244 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12245 extended opcode. SEC is the section the frag is in. */
12248 mips16_extended_frag (fragp
, sec
, stretch
)
12254 register const struct mips16_immed_operand
*op
;
12256 int mintiny
, maxtiny
;
12260 if (RELAX_MIPS16_USER_SMALL (fragp
->fr_subtype
))
12262 if (RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
))
12265 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
12266 op
= mips16_immed_operands
;
12267 while (op
->type
!= type
)
12270 assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
12275 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
12278 maxtiny
= 1 << op
->nbits
;
12283 maxtiny
= (1 << op
->nbits
) - 1;
12288 mintiny
= - (1 << (op
->nbits
- 1));
12289 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
12292 sym_frag
= symbol_get_frag (fragp
->fr_symbol
);
12293 val
= S_GET_VALUE (fragp
->fr_symbol
);
12294 symsec
= S_GET_SEGMENT (fragp
->fr_symbol
);
12300 /* We won't have the section when we are called from
12301 mips_relax_frag. However, we will always have been called
12302 from md_estimate_size_before_relax first. If this is a
12303 branch to a different section, we mark it as such. If SEC is
12304 NULL, and the frag is not marked, then it must be a branch to
12305 the same section. */
12308 if (RELAX_MIPS16_LONG_BRANCH (fragp
->fr_subtype
))
12313 /* Must have been called from md_estimate_size_before_relax. */
12316 fragp
->fr_subtype
=
12317 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12319 /* FIXME: We should support this, and let the linker
12320 catch branches and loads that are out of range. */
12321 as_bad_where (fragp
->fr_file
, fragp
->fr_line
,
12322 _("unsupported PC relative reference to different section"));
12326 if (fragp
!= sym_frag
&& sym_frag
->fr_address
== 0)
12327 /* Assume non-extended on the first relaxation pass.
12328 The address we have calculated will be bogus if this is
12329 a forward branch to another frag, as the forward frag
12330 will have fr_address == 0. */
12334 /* In this case, we know for sure that the symbol fragment is in
12335 the same section. If the relax_marker of the symbol fragment
12336 differs from the relax_marker of this fragment, we have not
12337 yet adjusted the symbol fragment fr_address. We want to add
12338 in STRETCH in order to get a better estimate of the address.
12339 This particularly matters because of the shift bits. */
12341 && sym_frag
->relax_marker
!= fragp
->relax_marker
)
12345 /* Adjust stretch for any alignment frag. Note that if have
12346 been expanding the earlier code, the symbol may be
12347 defined in what appears to be an earlier frag. FIXME:
12348 This doesn't handle the fr_subtype field, which specifies
12349 a maximum number of bytes to skip when doing an
12351 for (f
= fragp
; f
!= NULL
&& f
!= sym_frag
; f
= f
->fr_next
)
12353 if (f
->fr_type
== rs_align
|| f
->fr_type
== rs_align_code
)
12356 stretch
= - ((- stretch
)
12357 & ~ ((1 << (int) f
->fr_offset
) - 1));
12359 stretch
&= ~ ((1 << (int) f
->fr_offset
) - 1);
12368 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
12370 /* The base address rules are complicated. The base address of
12371 a branch is the following instruction. The base address of a
12372 PC relative load or add is the instruction itself, but if it
12373 is in a delay slot (in which case it can not be extended) use
12374 the address of the instruction whose delay slot it is in. */
12375 if (type
== 'p' || type
== 'q')
12379 /* If we are currently assuming that this frag should be
12380 extended, then, the current address is two bytes
12382 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
12385 /* Ignore the low bit in the target, since it will be set
12386 for a text label. */
12387 if ((val
& 1) != 0)
12390 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
12392 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
12395 val
-= addr
& ~ ((1 << op
->shift
) - 1);
12397 /* Branch offsets have an implicit 0 in the lowest bit. */
12398 if (type
== 'p' || type
== 'q')
12401 /* If any of the shifted bits are set, we must use an extended
12402 opcode. If the address depends on the size of this
12403 instruction, this can lead to a loop, so we arrange to always
12404 use an extended opcode. We only check this when we are in
12405 the main relaxation loop, when SEC is NULL. */
12406 if ((val
& ((1 << op
->shift
) - 1)) != 0 && sec
== NULL
)
12408 fragp
->fr_subtype
=
12409 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12413 /* If we are about to mark a frag as extended because the value
12414 is precisely maxtiny + 1, then there is a chance of an
12415 infinite loop as in the following code:
12420 In this case when the la is extended, foo is 0x3fc bytes
12421 away, so the la can be shrunk, but then foo is 0x400 away, so
12422 the la must be extended. To avoid this loop, we mark the
12423 frag as extended if it was small, and is about to become
12424 extended with a value of maxtiny + 1. */
12425 if (val
== ((maxtiny
+ 1) << op
->shift
)
12426 && ! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
)
12429 fragp
->fr_subtype
=
12430 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12434 else if (symsec
!= absolute_section
&& sec
!= NULL
)
12435 as_bad_where (fragp
->fr_file
, fragp
->fr_line
, _("unsupported relocation"));
12437 if ((val
& ((1 << op
->shift
) - 1)) != 0
12438 || val
< (mintiny
<< op
->shift
)
12439 || val
> (maxtiny
<< op
->shift
))
12445 /* Estimate the size of a frag before relaxing. Unless this is the
12446 mips16, we are not really relaxing here, and the final size is
12447 encoded in the subtype information. For the mips16, we have to
12448 decide whether we are using an extended opcode or not. */
12451 md_estimate_size_before_relax (fragp
, segtype
)
12456 boolean linkonce
= false;
12458 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
12459 /* We don't want to modify the EXTENDED bit here; it might get us
12460 into infinite loops. We change it only in mips_relax_frag(). */
12461 return (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
) ? 4 : 2);
12463 if (mips_pic
== NO_PIC
)
12465 change
= nopic_need_relax (fragp
->fr_symbol
, 0);
12467 else if (mips_pic
== SVR4_PIC
)
12472 sym
= fragp
->fr_symbol
;
12474 /* Handle the case of a symbol equated to another symbol. */
12475 while (symbol_equated_reloc_p (sym
))
12479 /* It's possible to get a loop here in a badly written
12481 n
= symbol_get_value_expression (sym
)->X_add_symbol
;
12487 symsec
= S_GET_SEGMENT (sym
);
12489 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12490 if (symsec
!= segtype
&& ! S_IS_LOCAL (sym
))
12492 if ((bfd_get_section_flags (stdoutput
, symsec
) & SEC_LINK_ONCE
)
12496 /* The GNU toolchain uses an extension for ELF: a section
12497 beginning with the magic string .gnu.linkonce is a linkonce
12499 if (strncmp (segment_name (symsec
), ".gnu.linkonce",
12500 sizeof ".gnu.linkonce" - 1) == 0)
12504 /* This must duplicate the test in adjust_reloc_syms. */
12505 change
= (symsec
!= &bfd_und_section
12506 && symsec
!= &bfd_abs_section
12507 && ! bfd_is_com_section (symsec
)
12510 /* A global or weak symbol is treated as external. */
12511 && (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
12512 || (! S_IS_WEAK (sym
)
12513 && (! S_IS_EXTERNAL (sym
)
12514 || mips_pic
== EMBEDDED_PIC
)))
12523 /* Record the offset to the first reloc in the fr_opcode field.
12524 This lets md_convert_frag and tc_gen_reloc know that the code
12525 must be expanded. */
12526 fragp
->fr_opcode
= (fragp
->fr_literal
12528 - RELAX_OLD (fragp
->fr_subtype
)
12529 + RELAX_RELOC1 (fragp
->fr_subtype
));
12530 /* FIXME: This really needs as_warn_where. */
12531 if (RELAX_WARN (fragp
->fr_subtype
))
12532 as_warn (_("AT used after \".set noat\" or macro used after "
12533 "\".set nomacro\""));
12535 return RELAX_NEW (fragp
->fr_subtype
) - RELAX_OLD (fragp
->fr_subtype
);
12541 /* This is called to see whether a reloc against a defined symbol
12542 should be converted into a reloc against a section. Don't adjust
12543 MIPS16 jump relocations, so we don't have to worry about the format
12544 of the offset in the .o file. Don't adjust relocations against
12545 mips16 symbols, so that the linker can find them if it needs to set
12549 mips_fix_adjustable (fixp
)
12553 /* Prevent all adjustments to global symbols. */
12554 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
12555 && mips_pic
!= EMBEDDED_PIC
12556 && (S_IS_EXTERNAL (fixp
->fx_addsy
) || S_IS_WEAK (fixp
->fx_addsy
)))
12559 if (fixp
->fx_r_type
== BFD_RELOC_MIPS16_JMP
)
12561 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
12562 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
12564 if (fixp
->fx_addsy
== NULL
)
12567 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
12568 && S_GET_OTHER (fixp
->fx_addsy
) == STO_MIPS16
12569 && fixp
->fx_subsy
== NULL
)
12575 /* Translate internal representation of relocation info to BFD target
12579 tc_gen_reloc (section
, fixp
)
12580 asection
*section ATTRIBUTE_UNUSED
;
12583 static arelent
*retval
[4];
12585 bfd_reloc_code_real_type code
;
12587 reloc
= retval
[0] = (arelent
*) xmalloc (sizeof (arelent
));
12590 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
12591 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
12592 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
12594 if (mips_pic
== EMBEDDED_PIC
12595 && SWITCH_TABLE (fixp
))
12597 /* For a switch table entry we use a special reloc. The addend
12598 is actually the difference between the reloc address and the
12600 reloc
->addend
= reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
);
12601 if (OUTPUT_FLAVOR
!= bfd_target_ecoff_flavour
)
12602 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
12603 fixp
->fx_r_type
= BFD_RELOC_GPREL32
;
12605 else if (fixp
->fx_r_type
== BFD_RELOC_PCREL_LO16
)
12607 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
12608 reloc
->addend
= fixp
->fx_addnumber
;
12611 /* We use a special addend for an internal RELLO reloc. */
12612 if (symbol_section_p (fixp
->fx_addsy
))
12613 reloc
->addend
= reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
);
12615 reloc
->addend
= fixp
->fx_addnumber
+ reloc
->address
;
12618 else if (fixp
->fx_r_type
== BFD_RELOC_PCREL_HI16_S
)
12620 assert (fixp
->fx_next
!= NULL
12621 && fixp
->fx_next
->fx_r_type
== BFD_RELOC_PCREL_LO16
);
12623 /* The reloc is relative to the RELLO; adjust the addend
12625 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
12626 reloc
->addend
= fixp
->fx_next
->fx_addnumber
;
12629 /* We use a special addend for an internal RELHI reloc. */
12630 if (symbol_section_p (fixp
->fx_addsy
))
12631 reloc
->addend
= (fixp
->fx_next
->fx_frag
->fr_address
12632 + fixp
->fx_next
->fx_where
12633 - S_GET_VALUE (fixp
->fx_subsy
));
12635 reloc
->addend
= (fixp
->fx_addnumber
12636 + fixp
->fx_next
->fx_frag
->fr_address
12637 + fixp
->fx_next
->fx_where
);
12640 else if (fixp
->fx_pcrel
== 0 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
12641 reloc
->addend
= fixp
->fx_addnumber
;
12644 if (OUTPUT_FLAVOR
!= bfd_target_aout_flavour
)
12645 /* A gruesome hack which is a result of the gruesome gas reloc
12647 reloc
->addend
= reloc
->address
;
12649 reloc
->addend
= -reloc
->address
;
12652 /* If this is a variant frag, we may need to adjust the existing
12653 reloc and generate a new one. */
12654 if (fixp
->fx_frag
->fr_opcode
!= NULL
12655 && (fixp
->fx_r_type
== BFD_RELOC_GPREL16
12656 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT16
12657 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL16
12658 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_HI16
12659 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_LO16
12660 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_HI16
12661 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_LO16
)
12666 assert (! RELAX_MIPS16_P (fixp
->fx_frag
->fr_subtype
));
12668 /* If this is not the last reloc in this frag, then we have two
12669 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
12670 CALL_HI16/CALL_LO16, both of which are being replaced. Let
12671 the second one handle all of them. */
12672 if (fixp
->fx_next
!= NULL
12673 && fixp
->fx_frag
== fixp
->fx_next
->fx_frag
)
12675 assert ((fixp
->fx_r_type
== BFD_RELOC_GPREL16
12676 && fixp
->fx_next
->fx_r_type
== BFD_RELOC_GPREL16
)
12677 || (fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_HI16
12678 && (fixp
->fx_next
->fx_r_type
12679 == BFD_RELOC_MIPS_GOT_LO16
))
12680 || (fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_HI16
12681 && (fixp
->fx_next
->fx_r_type
12682 == BFD_RELOC_MIPS_CALL_LO16
)));
12687 fixp
->fx_where
= fixp
->fx_frag
->fr_opcode
- fixp
->fx_frag
->fr_literal
;
12688 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
12689 reloc2
= retval
[1] = (arelent
*) xmalloc (sizeof (arelent
));
12691 reloc2
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
12692 *reloc2
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
12693 reloc2
->address
= (reloc
->address
12694 + (RELAX_RELOC2 (fixp
->fx_frag
->fr_subtype
)
12695 - RELAX_RELOC1 (fixp
->fx_frag
->fr_subtype
)));
12696 reloc2
->addend
= fixp
->fx_addnumber
;
12697 reloc2
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_LO16
);
12698 assert (reloc2
->howto
!= NULL
);
12700 if (RELAX_RELOC3 (fixp
->fx_frag
->fr_subtype
))
12704 reloc3
= retval
[2] = (arelent
*) xmalloc (sizeof (arelent
));
12707 reloc3
->address
+= 4;
12710 if (mips_pic
== NO_PIC
)
12712 assert (fixp
->fx_r_type
== BFD_RELOC_GPREL16
);
12713 fixp
->fx_r_type
= BFD_RELOC_HI16_S
;
12715 else if (mips_pic
== SVR4_PIC
)
12717 switch (fixp
->fx_r_type
)
12721 case BFD_RELOC_MIPS_GOT16
:
12723 case BFD_RELOC_MIPS_CALL16
:
12724 case BFD_RELOC_MIPS_GOT_LO16
:
12725 case BFD_RELOC_MIPS_CALL_LO16
:
12726 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT16
;
12734 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
12735 entry to be used in the relocation's section offset. */
12736 if (! HAVE_NEWABI
&& fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
12738 reloc
->address
= reloc
->addend
;
12742 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
12743 fixup_segment converted a non-PC relative reloc into a PC
12744 relative reloc. In such a case, we need to convert the reloc
12746 code
= fixp
->fx_r_type
;
12747 if (fixp
->fx_pcrel
)
12752 code
= BFD_RELOC_8_PCREL
;
12755 code
= BFD_RELOC_16_PCREL
;
12758 code
= BFD_RELOC_32_PCREL
;
12761 code
= BFD_RELOC_64_PCREL
;
12763 case BFD_RELOC_8_PCREL
:
12764 case BFD_RELOC_16_PCREL
:
12765 case BFD_RELOC_32_PCREL
:
12766 case BFD_RELOC_64_PCREL
:
12767 case BFD_RELOC_16_PCREL_S2
:
12768 case BFD_RELOC_PCREL_HI16_S
:
12769 case BFD_RELOC_PCREL_LO16
:
12772 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
12773 _("Cannot make %s relocation PC relative"),
12774 bfd_get_reloc_code_name (code
));
12779 /* md_apply_fix3 has a double-subtraction hack to get
12780 bfd_install_relocation to behave nicely. GPREL relocations are
12781 handled correctly without this hack, so undo it here. We can't
12782 stop md_apply_fix3 from subtracting twice in the first place since
12783 the fake addend is required for variant frags above. */
12784 if (fixp
->fx_addsy
!= NULL
&& OUTPUT_FLAVOR
== bfd_target_elf_flavour
12785 && (code
== BFD_RELOC_GPREL16
|| code
== BFD_RELOC_MIPS16_GPREL
)
12786 && reloc
->addend
!= 0
12787 && mips_need_elf_addend_fixup (fixp
))
12788 reloc
->addend
+= S_GET_VALUE (fixp
->fx_addsy
);
12791 /* To support a PC relative reloc when generating embedded PIC code
12792 for ECOFF, we use a Cygnus extension. We check for that here to
12793 make sure that we don't let such a reloc escape normally. */
12794 if ((OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
12795 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
12796 && code
== BFD_RELOC_16_PCREL_S2
12797 && mips_pic
!= EMBEDDED_PIC
)
12798 reloc
->howto
= NULL
;
12800 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
12802 if (reloc
->howto
== NULL
)
12804 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
12805 _("Can not represent %s relocation in this object file format"),
12806 bfd_get_reloc_code_name (code
));
12813 /* Relax a machine dependent frag. This returns the amount by which
12814 the current size of the frag should change. */
12817 mips_relax_frag (fragp
, stretch
)
12821 if (! RELAX_MIPS16_P (fragp
->fr_subtype
))
12824 if (mips16_extended_frag (fragp
, NULL
, stretch
))
12826 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
12828 fragp
->fr_subtype
= RELAX_MIPS16_MARK_EXTENDED (fragp
->fr_subtype
);
12833 if (! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
12835 fragp
->fr_subtype
= RELAX_MIPS16_CLEAR_EXTENDED (fragp
->fr_subtype
);
12842 /* Convert a machine dependent frag. */
12845 md_convert_frag (abfd
, asec
, fragp
)
12846 bfd
*abfd ATTRIBUTE_UNUSED
;
12853 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
12856 register const struct mips16_immed_operand
*op
;
12857 boolean small
, ext
;
12860 unsigned long insn
;
12861 boolean use_extend
;
12862 unsigned short extend
;
12864 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
12865 op
= mips16_immed_operands
;
12866 while (op
->type
!= type
)
12869 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
12880 resolve_symbol_value (fragp
->fr_symbol
);
12881 val
= S_GET_VALUE (fragp
->fr_symbol
);
12886 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
12888 /* The rules for the base address of a PC relative reloc are
12889 complicated; see mips16_extended_frag. */
12890 if (type
== 'p' || type
== 'q')
12895 /* Ignore the low bit in the target, since it will be
12896 set for a text label. */
12897 if ((val
& 1) != 0)
12900 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
12902 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
12905 addr
&= ~ (addressT
) ((1 << op
->shift
) - 1);
12908 /* Make sure the section winds up with the alignment we have
12911 record_alignment (asec
, op
->shift
);
12915 && (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
)
12916 || RELAX_MIPS16_DSLOT (fragp
->fr_subtype
)))
12917 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
12918 _("extended instruction in delay slot"));
12920 buf
= (bfd_byte
*) (fragp
->fr_literal
+ fragp
->fr_fix
);
12922 if (target_big_endian
)
12923 insn
= bfd_getb16 (buf
);
12925 insn
= bfd_getl16 (buf
);
12927 mips16_immed (fragp
->fr_file
, fragp
->fr_line
, type
, val
,
12928 RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
),
12929 small
, ext
, &insn
, &use_extend
, &extend
);
12933 md_number_to_chars ((char *) buf
, 0xf000 | extend
, 2);
12934 fragp
->fr_fix
+= 2;
12938 md_number_to_chars ((char *) buf
, insn
, 2);
12939 fragp
->fr_fix
+= 2;
12944 if (fragp
->fr_opcode
== NULL
)
12947 old
= RELAX_OLD (fragp
->fr_subtype
);
12948 new = RELAX_NEW (fragp
->fr_subtype
);
12949 fixptr
= fragp
->fr_literal
+ fragp
->fr_fix
;
12952 memcpy (fixptr
- old
, fixptr
, new);
12954 fragp
->fr_fix
+= new - old
;
12960 /* This function is called after the relocs have been generated.
12961 We've been storing mips16 text labels as odd. Here we convert them
12962 back to even for the convenience of the debugger. */
12965 mips_frob_file_after_relocs ()
12968 unsigned int count
, i
;
12970 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
12973 syms
= bfd_get_outsymbols (stdoutput
);
12974 count
= bfd_get_symcount (stdoutput
);
12975 for (i
= 0; i
< count
; i
++, syms
++)
12977 if (elf_symbol (*syms
)->internal_elf_sym
.st_other
== STO_MIPS16
12978 && ((*syms
)->value
& 1) != 0)
12980 (*syms
)->value
&= ~1;
12981 /* If the symbol has an odd size, it was probably computed
12982 incorrectly, so adjust that as well. */
12983 if ((elf_symbol (*syms
)->internal_elf_sym
.st_size
& 1) != 0)
12984 ++elf_symbol (*syms
)->internal_elf_sym
.st_size
;
12991 /* This function is called whenever a label is defined. It is used
12992 when handling branch delays; if a branch has a label, we assume we
12993 can not move it. */
12996 mips_define_label (sym
)
12999 struct insn_label_list
*l
;
13001 if (free_insn_labels
== NULL
)
13002 l
= (struct insn_label_list
*) xmalloc (sizeof *l
);
13005 l
= free_insn_labels
;
13006 free_insn_labels
= l
->next
;
13010 l
->next
= insn_labels
;
13014 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13016 /* Some special processing for a MIPS ELF file. */
13019 mips_elf_final_processing ()
13021 /* Write out the register information. */
13022 if (mips_abi
!= N64_ABI
)
13026 s
.ri_gprmask
= mips_gprmask
;
13027 s
.ri_cprmask
[0] = mips_cprmask
[0];
13028 s
.ri_cprmask
[1] = mips_cprmask
[1];
13029 s
.ri_cprmask
[2] = mips_cprmask
[2];
13030 s
.ri_cprmask
[3] = mips_cprmask
[3];
13031 /* The gp_value field is set by the MIPS ELF backend. */
13033 bfd_mips_elf32_swap_reginfo_out (stdoutput
, &s
,
13034 ((Elf32_External_RegInfo
*)
13035 mips_regmask_frag
));
13039 Elf64_Internal_RegInfo s
;
13041 s
.ri_gprmask
= mips_gprmask
;
13043 s
.ri_cprmask
[0] = mips_cprmask
[0];
13044 s
.ri_cprmask
[1] = mips_cprmask
[1];
13045 s
.ri_cprmask
[2] = mips_cprmask
[2];
13046 s
.ri_cprmask
[3] = mips_cprmask
[3];
13047 /* The gp_value field is set by the MIPS ELF backend. */
13049 bfd_mips_elf64_swap_reginfo_out (stdoutput
, &s
,
13050 ((Elf64_External_RegInfo
*)
13051 mips_regmask_frag
));
13054 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13055 sort of BFD interface for this. */
13056 if (mips_any_noreorder
)
13057 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_NOREORDER
;
13058 if (mips_pic
!= NO_PIC
)
13059 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_PIC
;
13061 /* Set MIPS ELF flags for ASEs. */
13062 if (file_ase_mips16
)
13063 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_M16
;
13064 #if 0 /* XXX FIXME */
13065 if (file_ase_mips3d
)
13066 elf_elfheader (stdoutput
)->e_flags
|= ???;
13069 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_MDMX
;
13071 /* Set the MIPS ELF ABI flags. */
13072 if (mips_abi
== O32_ABI
&& USE_E_MIPS_ABI_O32
)
13073 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O32
;
13074 else if (mips_abi
== O64_ABI
)
13075 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O64
;
13076 else if (mips_abi
== EABI_ABI
)
13078 if (!file_mips_gp32
)
13079 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI64
;
13081 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI32
;
13083 else if (mips_abi
== N32_ABI
)
13084 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ABI2
;
13086 /* Nothing to do for N64_ABI. */
13088 if (mips_32bitmode
)
13089 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_32BITMODE
;
13092 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
13094 typedef struct proc
{
13096 unsigned long reg_mask
;
13097 unsigned long reg_offset
;
13098 unsigned long fpreg_mask
;
13099 unsigned long fpreg_offset
;
13100 unsigned long frame_offset
;
13101 unsigned long frame_reg
;
13102 unsigned long pc_reg
;
13105 static procS cur_proc
;
13106 static procS
*cur_proc_ptr
;
13107 static int numprocs
;
13109 /* Fill in an rs_align_code fragment. */
13112 mips_handle_align (fragp
)
13115 if (fragp
->fr_type
!= rs_align_code
)
13118 if (mips_opts
.mips16
)
13120 static const unsigned char be_nop
[] = { 0x65, 0x00 };
13121 static const unsigned char le_nop
[] = { 0x00, 0x65 };
13126 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
13127 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
13135 memcpy (p
, (target_big_endian
? be_nop
: le_nop
), 2);
13139 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
13150 /* check for premature end, nesting errors, etc */
13152 as_warn (_("missing .end at end of assembly"));
13161 if (*input_line_pointer
== '-')
13163 ++input_line_pointer
;
13166 if (!ISDIGIT (*input_line_pointer
))
13167 as_bad (_("expected simple number"));
13168 if (input_line_pointer
[0] == '0')
13170 if (input_line_pointer
[1] == 'x')
13172 input_line_pointer
+= 2;
13173 while (ISXDIGIT (*input_line_pointer
))
13176 val
|= hex_value (*input_line_pointer
++);
13178 return negative
? -val
: val
;
13182 ++input_line_pointer
;
13183 while (ISDIGIT (*input_line_pointer
))
13186 val
|= *input_line_pointer
++ - '0';
13188 return negative
? -val
: val
;
13191 if (!ISDIGIT (*input_line_pointer
))
13193 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13194 *input_line_pointer
, *input_line_pointer
);
13195 as_warn (_("invalid number"));
13198 while (ISDIGIT (*input_line_pointer
))
13201 val
+= *input_line_pointer
++ - '0';
13203 return negative
? -val
: val
;
13206 /* The .file directive; just like the usual .file directive, but there
13207 is an initial number which is the ECOFF file index. In the non-ECOFF
13208 case .file implies DWARF-2. */
13212 int x ATTRIBUTE_UNUSED
;
13214 static int first_file_directive
= 0;
13216 if (ECOFF_DEBUGGING
)
13225 filename
= dwarf2_directive_file (0);
13227 /* Versions of GCC up to 3.1 start files with a ".file"
13228 directive even for stabs output. Make sure that this
13229 ".file" is handled. Note that you need a version of GCC
13230 after 3.1 in order to support DWARF-2 on MIPS. */
13231 if (filename
!= NULL
&& ! first_file_directive
)
13233 (void) new_logical_line (filename
, -1);
13234 s_app_file_string (filename
);
13236 first_file_directive
= 1;
13240 /* The .loc directive, implying DWARF-2. */
13244 int x ATTRIBUTE_UNUSED
;
13246 if (!ECOFF_DEBUGGING
)
13247 dwarf2_directive_loc (0);
13250 /* The .end directive. */
13254 int x ATTRIBUTE_UNUSED
;
13259 /* Following functions need their own .frame and .cprestore directives. */
13260 mips_frame_reg_valid
= 0;
13261 mips_cprestore_valid
= 0;
13263 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
13266 demand_empty_rest_of_line ();
13271 #ifdef BFD_ASSEMBLER
13272 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
13277 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
13284 as_warn (_(".end not in text section"));
13288 as_warn (_(".end directive without a preceding .ent directive."));
13289 demand_empty_rest_of_line ();
13295 assert (S_GET_NAME (p
));
13296 if (strcmp (S_GET_NAME (p
), S_GET_NAME (cur_proc_ptr
->isym
)))
13297 as_warn (_(".end symbol does not match .ent symbol."));
13299 if (debug_type
== DEBUG_STABS
)
13300 stabs_generate_asm_endfunc (S_GET_NAME (p
),
13304 as_warn (_(".end directive missing or unknown symbol"));
13307 /* Generate a .pdr section. */
13308 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
)
13310 segT saved_seg
= now_seg
;
13311 subsegT saved_subseg
= now_subseg
;
13316 dot
= frag_now_fix ();
13318 #ifdef md_flush_pending_output
13319 md_flush_pending_output ();
13323 subseg_set (pdr_seg
, 0);
13325 /* Write the symbol. */
13326 exp
.X_op
= O_symbol
;
13327 exp
.X_add_symbol
= p
;
13328 exp
.X_add_number
= 0;
13329 emit_expr (&exp
, 4);
13331 fragp
= frag_more (7 * 4);
13333 md_number_to_chars (fragp
, (valueT
) cur_proc_ptr
->reg_mask
, 4);
13334 md_number_to_chars (fragp
+ 4, (valueT
) cur_proc_ptr
->reg_offset
, 4);
13335 md_number_to_chars (fragp
+ 8, (valueT
) cur_proc_ptr
->fpreg_mask
, 4);
13336 md_number_to_chars (fragp
+ 12, (valueT
) cur_proc_ptr
->fpreg_offset
, 4);
13337 md_number_to_chars (fragp
+ 16, (valueT
) cur_proc_ptr
->frame_offset
, 4);
13338 md_number_to_chars (fragp
+ 20, (valueT
) cur_proc_ptr
->frame_reg
, 4);
13339 md_number_to_chars (fragp
+ 24, (valueT
) cur_proc_ptr
->pc_reg
, 4);
13341 subseg_set (saved_seg
, saved_subseg
);
13343 #endif /* OBJ_ELF */
13345 cur_proc_ptr
= NULL
;
13348 /* The .aent and .ent directives. */
13357 symbolP
= get_symbol ();
13358 if (*input_line_pointer
== ',')
13359 ++input_line_pointer
;
13360 SKIP_WHITESPACE ();
13361 if (ISDIGIT (*input_line_pointer
)
13362 || *input_line_pointer
== '-')
13365 #ifdef BFD_ASSEMBLER
13366 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
13371 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
13378 as_warn (_(".ent or .aent not in text section."));
13380 if (!aent
&& cur_proc_ptr
)
13381 as_warn (_("missing .end"));
13385 /* This function needs its own .frame and .cprestore directives. */
13386 mips_frame_reg_valid
= 0;
13387 mips_cprestore_valid
= 0;
13389 cur_proc_ptr
= &cur_proc
;
13390 memset (cur_proc_ptr
, '\0', sizeof (procS
));
13392 cur_proc_ptr
->isym
= symbolP
;
13394 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
13398 if (debug_type
== DEBUG_STABS
)
13399 stabs_generate_asm_func (S_GET_NAME (symbolP
),
13400 S_GET_NAME (symbolP
));
13403 demand_empty_rest_of_line ();
13406 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
13407 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
13408 s_mips_frame is used so that we can set the PDR information correctly.
13409 We can't use the ecoff routines because they make reference to the ecoff
13410 symbol table (in the mdebug section). */
13413 s_mips_frame (ignore
)
13414 int ignore ATTRIBUTE_UNUSED
;
13417 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
)
13421 if (cur_proc_ptr
== (procS
*) NULL
)
13423 as_warn (_(".frame outside of .ent"));
13424 demand_empty_rest_of_line ();
13428 cur_proc_ptr
->frame_reg
= tc_get_register (1);
13430 SKIP_WHITESPACE ();
13431 if (*input_line_pointer
++ != ','
13432 || get_absolute_expression_and_terminator (&val
) != ',')
13434 as_warn (_("Bad .frame directive"));
13435 --input_line_pointer
;
13436 demand_empty_rest_of_line ();
13440 cur_proc_ptr
->frame_offset
= val
;
13441 cur_proc_ptr
->pc_reg
= tc_get_register (0);
13443 demand_empty_rest_of_line ();
13446 #endif /* OBJ_ELF */
13450 /* The .fmask and .mask directives. If the mdebug section is present
13451 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
13452 embedded targets, s_mips_mask is used so that we can set the PDR
13453 information correctly. We can't use the ecoff routines because they
13454 make reference to the ecoff symbol table (in the mdebug section). */
13457 s_mips_mask (reg_type
)
13461 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
)
13465 if (cur_proc_ptr
== (procS
*) NULL
)
13467 as_warn (_(".mask/.fmask outside of .ent"));
13468 demand_empty_rest_of_line ();
13472 if (get_absolute_expression_and_terminator (&mask
) != ',')
13474 as_warn (_("Bad .mask/.fmask directive"));
13475 --input_line_pointer
;
13476 demand_empty_rest_of_line ();
13480 off
= get_absolute_expression ();
13482 if (reg_type
== 'F')
13484 cur_proc_ptr
->fpreg_mask
= mask
;
13485 cur_proc_ptr
->fpreg_offset
= off
;
13489 cur_proc_ptr
->reg_mask
= mask
;
13490 cur_proc_ptr
->reg_offset
= off
;
13493 demand_empty_rest_of_line ();
13496 #endif /* OBJ_ELF */
13497 s_ignore (reg_type
);
13500 /* The .loc directive. */
13511 assert (now_seg
== text_section
);
13513 lineno
= get_number ();
13514 addroff
= frag_now_fix ();
13516 symbolP
= symbol_new ("", N_SLINE
, addroff
, frag_now
);
13517 S_SET_TYPE (symbolP
, N_SLINE
);
13518 S_SET_OTHER (symbolP
, 0);
13519 S_SET_DESC (symbolP
, lineno
);
13520 symbolP
->sy_segment
= now_seg
;
13524 /* A table describing all the processors gas knows about. Names are
13525 matched in the order listed.
13527 To ease comparison, please keep this table in the same order as
13528 gcc's mips_cpu_info_table[]. */
13529 static const struct mips_cpu_info mips_cpu_info_table
[] =
13531 /* Entries for generic ISAs */
13532 { "mips1", 1, ISA_MIPS1
, CPU_R3000
},
13533 { "mips2", 1, ISA_MIPS2
, CPU_R6000
},
13534 { "mips3", 1, ISA_MIPS3
, CPU_R4000
},
13535 { "mips4", 1, ISA_MIPS4
, CPU_R8000
},
13536 { "mips5", 1, ISA_MIPS5
, CPU_MIPS5
},
13537 { "mips32", 1, ISA_MIPS32
, CPU_MIPS32
},
13538 { "mips64", 1, ISA_MIPS64
, CPU_MIPS64
},
13541 { "r3000", 0, ISA_MIPS1
, CPU_R3000
},
13542 { "r2000", 0, ISA_MIPS1
, CPU_R3000
},
13543 { "r3900", 0, ISA_MIPS1
, CPU_R3900
},
13546 { "r6000", 0, ISA_MIPS2
, CPU_R6000
},
13549 { "r4000", 0, ISA_MIPS3
, CPU_R4000
},
13550 { "r4010", 0, ISA_MIPS2
, CPU_R4010
},
13551 { "vr4100", 0, ISA_MIPS3
, CPU_VR4100
},
13552 { "vr4111", 0, ISA_MIPS3
, CPU_R4111
},
13553 { "vr4300", 0, ISA_MIPS3
, CPU_R4300
},
13554 { "r4400", 0, ISA_MIPS3
, CPU_R4400
},
13555 { "r4600", 0, ISA_MIPS3
, CPU_R4600
},
13556 { "orion", 0, ISA_MIPS3
, CPU_R4600
},
13557 { "r4650", 0, ISA_MIPS3
, CPU_R4650
},
13560 { "r8000", 0, ISA_MIPS4
, CPU_R8000
},
13561 { "r10000", 0, ISA_MIPS4
, CPU_R10000
},
13562 { "r12000", 0, ISA_MIPS4
, CPU_R12000
},
13563 { "vr5000", 0, ISA_MIPS4
, CPU_R5000
},
13564 { "rm5200", 0, ISA_MIPS4
, CPU_R5000
},
13565 { "rm5230", 0, ISA_MIPS4
, CPU_R5000
},
13566 { "rm5231", 0, ISA_MIPS4
, CPU_R5000
},
13567 { "rm5261", 0, ISA_MIPS4
, CPU_R5000
},
13568 { "rm5721", 0, ISA_MIPS4
, CPU_R5000
},
13569 { "r7000", 0, ISA_MIPS4
, CPU_R5000
},
13572 { "4kc", 0, ISA_MIPS32
, CPU_MIPS32
, },
13573 { "4km", 0, ISA_MIPS32
, CPU_MIPS32
},
13574 { "4kp", 0, ISA_MIPS32
, CPU_MIPS32
},
13577 { "5kc", 0, ISA_MIPS64
, CPU_MIPS64
},
13578 { "20kc", 0, ISA_MIPS64
, CPU_MIPS64
},
13580 /* Broadcom SB-1 CPU core */
13581 { "sb1", 0, ISA_MIPS64
, CPU_SB1
},
13588 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
13589 with a final "000" replaced by "k". Ignore case.
13591 Note: this function is shared between GCC and GAS. */
13594 mips_strict_matching_cpu_name_p (canonical
, given
)
13595 const char *canonical
, *given
;
13597 while (*given
!= 0 && TOLOWER (*given
) == TOLOWER (*canonical
))
13598 given
++, canonical
++;
13600 return ((*given
== 0 && *canonical
== 0)
13601 || (strcmp (canonical
, "000") == 0 && strcasecmp (given
, "k") == 0));
13605 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
13606 CPU name. We've traditionally allowed a lot of variation here.
13608 Note: this function is shared between GCC and GAS. */
13611 mips_matching_cpu_name_p (canonical
, given
)
13612 const char *canonical
, *given
;
13614 /* First see if the name matches exactly, or with a final "000"
13615 turned into "k". */
13616 if (mips_strict_matching_cpu_name_p (canonical
, given
))
13619 /* If not, try comparing based on numerical designation alone.
13620 See if GIVEN is an unadorned number, or 'r' followed by a number. */
13621 if (TOLOWER (*given
) == 'r')
13623 if (!ISDIGIT (*given
))
13626 /* Skip over some well-known prefixes in the canonical name,
13627 hoping to find a number there too. */
13628 if (TOLOWER (canonical
[0]) == 'v' && TOLOWER (canonical
[1]) == 'r')
13630 else if (TOLOWER (canonical
[0]) == 'r' && TOLOWER (canonical
[1]) == 'm')
13632 else if (TOLOWER (canonical
[0]) == 'r')
13635 return mips_strict_matching_cpu_name_p (canonical
, given
);
13639 /* Parse an option that takes the name of a processor as its argument.
13640 OPTION is the name of the option and CPU_STRING is the argument.
13641 Return the corresponding processor enumeration if the CPU_STRING is
13642 recognized, otherwise report an error and return null.
13644 A similar function exists in GCC. */
13646 static const struct mips_cpu_info
*
13647 mips_parse_cpu (option
, cpu_string
)
13648 const char *option
, *cpu_string
;
13650 const struct mips_cpu_info
*p
;
13652 /* 'from-abi' selects the most compatible architecture for the given
13653 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
13654 EABIs, we have to decide whether we're using the 32-bit or 64-bit
13655 version. Look first at the -mgp options, if given, otherwise base
13656 the choice on MIPS_DEFAULT_64BIT.
13658 Treat NO_ABI like the EABIs. One reason to do this is that the
13659 plain 'mips' and 'mips64' configs have 'from-abi' as their default
13660 architecture. This code picks MIPS I for 'mips' and MIPS III for
13661 'mips64', just as we did in the days before 'from-abi'. */
13662 if (strcasecmp (cpu_string
, "from-abi") == 0)
13664 if (ABI_NEEDS_32BIT_REGS (mips_abi
))
13665 return mips_cpu_info_from_isa (ISA_MIPS1
);
13667 if (ABI_NEEDS_64BIT_REGS (mips_abi
))
13668 return mips_cpu_info_from_isa (ISA_MIPS3
);
13670 if (file_mips_gp32
>= 0)
13671 return mips_cpu_info_from_isa (file_mips_gp32
? ISA_MIPS1
: ISA_MIPS3
);
13673 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
13678 /* 'default' has traditionally been a no-op. Probably not very useful. */
13679 if (strcasecmp (cpu_string
, "default") == 0)
13682 for (p
= mips_cpu_info_table
; p
->name
!= 0; p
++)
13683 if (mips_matching_cpu_name_p (p
->name
, cpu_string
))
13686 as_bad ("Bad value (%s) for %s", cpu_string
, option
);
13690 /* Return the canonical processor information for ISA (a member of the
13691 ISA_MIPS* enumeration). */
13693 static const struct mips_cpu_info
*
13694 mips_cpu_info_from_isa (isa
)
13699 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
13700 if (mips_cpu_info_table
[i
].is_isa
13701 && isa
== mips_cpu_info_table
[i
].isa
)
13702 return (&mips_cpu_info_table
[i
]);
13708 show (stream
, string
, col_p
, first_p
)
13710 const char *string
;
13716 fprintf (stream
, "%24s", "");
13721 fprintf (stream
, ", ");
13725 if (*col_p
+ strlen (string
) > 72)
13727 fprintf (stream
, "\n%24s", "");
13731 fprintf (stream
, "%s", string
);
13732 *col_p
+= strlen (string
);
13738 md_show_usage (stream
)
13744 fprintf (stream
, _("\
13746 -membedded-pic generate embedded position independent code\n\
13747 -EB generate big endian output\n\
13748 -EL generate little endian output\n\
13749 -g, -g2 do not remove unneeded NOPs or swap branches\n\
13750 -G NUM allow referencing objects up to NUM bytes\n\
13751 implicitly with the gp register [default 8]\n"));
13752 fprintf (stream
, _("\
13753 -mips1 generate MIPS ISA I instructions\n\
13754 -mips2 generate MIPS ISA II instructions\n\
13755 -mips3 generate MIPS ISA III instructions\n\
13756 -mips4 generate MIPS ISA IV instructions\n\
13757 -mips5 generate MIPS ISA V instructions\n\
13758 -mips32 generate MIPS32 ISA instructions\n\
13759 -mips64 generate MIPS64 ISA instructions\n\
13760 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
13764 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
13765 show (stream
, mips_cpu_info_table
[i
].name
, &column
, &first
);
13766 show (stream
, "from-abi", &column
, &first
);
13767 fputc ('\n', stream
);
13769 fprintf (stream
, _("\
13770 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
13771 -no-mCPU don't generate code specific to CPU.\n\
13772 For -mCPU and -no-mCPU, CPU must be one of:\n"));
13776 show (stream
, "3900", &column
, &first
);
13777 show (stream
, "4010", &column
, &first
);
13778 show (stream
, "4100", &column
, &first
);
13779 show (stream
, "4650", &column
, &first
);
13780 fputc ('\n', stream
);
13782 fprintf (stream
, _("\
13783 -mips16 generate mips16 instructions\n\
13784 -no-mips16 do not generate mips16 instructions\n"));
13785 fprintf (stream
, _("\
13786 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
13787 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
13788 -O0 remove unneeded NOPs, do not swap branches\n\
13789 -O remove unneeded NOPs and swap branches\n\
13790 -n warn about NOPs generated from macros\n\
13791 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
13792 --trap, --no-break trap exception on div by 0 and mult overflow\n\
13793 --break, --no-trap break exception on div by 0 and mult overflow\n"));
13795 fprintf (stream
, _("\
13796 -KPIC, -call_shared generate SVR4 position independent code\n\
13797 -non_shared do not generate position independent code\n\
13798 -xgot assume a 32 bit GOT\n\
13799 -mabi=ABI create ABI conformant object file for:\n"));
13803 show (stream
, "32", &column
, &first
);
13804 show (stream
, "o64", &column
, &first
);
13805 show (stream
, "n32", &column
, &first
);
13806 show (stream
, "64", &column
, &first
);
13807 show (stream
, "eabi", &column
, &first
);
13809 fputc ('\n', stream
);
13811 fprintf (stream
, _("\
13812 -32 create o32 ABI object file (default)\n\
13813 -n32 create n32 ABI object file\n\
13814 -64 create 64 ABI object file\n"));