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 \
289 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
291 /* Return true if the given CPU supports the MIPS3D ASE. */
292 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
295 /* Return true if the given CPU supports the MDMX ASE. */
296 #define CPU_HAS_MDMX(cpu) (false \
299 /* True if CPU has a dror instruction. */
300 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
302 /* True if CPU has a ror instruction. */
303 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
305 /* Whether the processor uses hardware interlocks to protect
306 reads from the HI and LO registers, and thus does not
307 require nops to be inserted. */
309 #define hilo_interlocks (mips_arch == CPU_R4010 \
310 || mips_arch == CPU_VR5500 \
311 || mips_arch == CPU_SB1 \
314 /* Whether the processor uses hardware interlocks to protect reads
315 from the GPRs, and thus does not require nops to be inserted. */
316 #define gpr_interlocks \
317 (mips_opts.isa != ISA_MIPS1 \
318 || mips_arch == CPU_VR5400 \
319 || mips_arch == CPU_VR5500 \
320 || mips_arch == CPU_R3900)
322 /* As with other "interlocks" this is used by hardware that has FP
323 (co-processor) interlocks. */
324 /* Itbl support may require additional care here. */
325 #define cop_interlocks (mips_arch == CPU_R4300 \
326 || mips_arch == CPU_VR5400 \
327 || mips_arch == CPU_VR5500 \
328 || mips_arch == CPU_SB1 \
331 /* Is this a mfhi or mflo instruction? */
332 #define MF_HILO_INSN(PINFO) \
333 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
335 /* MIPS PIC level. */
337 enum mips_pic_level mips_pic
;
339 /* Warn about all NOPS that the assembler generates. */
340 static int warn_nops
= 0;
342 /* 1 if we should generate 32 bit offsets from the $gp register in
343 SVR4_PIC mode. Currently has no meaning in other modes. */
344 static int mips_big_got
= 0;
346 /* 1 if trap instructions should used for overflow rather than break
348 static int mips_trap
= 0;
350 /* 1 if double width floating point constants should not be constructed
351 by assembling two single width halves into two single width floating
352 point registers which just happen to alias the double width destination
353 register. On some architectures this aliasing can be disabled by a bit
354 in the status register, and the setting of this bit cannot be determined
355 automatically at assemble time. */
356 static int mips_disable_float_construction
;
358 /* Non-zero if any .set noreorder directives were used. */
360 static int mips_any_noreorder
;
362 /* Non-zero if nops should be inserted when the register referenced in
363 an mfhi/mflo instruction is read in the next two instructions. */
364 static int mips_7000_hilo_fix
;
366 /* The size of the small data section. */
367 static unsigned int g_switch_value
= 8;
368 /* Whether the -G option was used. */
369 static int g_switch_seen
= 0;
374 /* If we can determine in advance that GP optimization won't be
375 possible, we can skip the relaxation stuff that tries to produce
376 GP-relative references. This makes delay slot optimization work
379 This function can only provide a guess, but it seems to work for
380 gcc output. It needs to guess right for gcc, otherwise gcc
381 will put what it thinks is a GP-relative instruction in a branch
384 I don't know if a fix is needed for the SVR4_PIC mode. I've only
385 fixed it for the non-PIC mode. KR 95/04/07 */
386 static int nopic_need_relax
PARAMS ((symbolS
*, int));
388 /* handle of the OPCODE hash table */
389 static struct hash_control
*op_hash
= NULL
;
391 /* The opcode hash table we use for the mips16. */
392 static struct hash_control
*mips16_op_hash
= NULL
;
394 /* This array holds the chars that always start a comment. If the
395 pre-processor is disabled, these aren't very useful */
396 const char comment_chars
[] = "#";
398 /* This array holds the chars that only start a comment at the beginning of
399 a line. If the line seems to have the form '# 123 filename'
400 .line and .file directives will appear in the pre-processed output */
401 /* Note that input_file.c hand checks for '#' at the beginning of the
402 first line of the input file. This is because the compiler outputs
403 #NO_APP at the beginning of its output. */
404 /* Also note that C style comments are always supported. */
405 const char line_comment_chars
[] = "#";
407 /* This array holds machine specific line separator characters. */
408 const char line_separator_chars
[] = ";";
410 /* Chars that can be used to separate mant from exp in floating point nums */
411 const char EXP_CHARS
[] = "eE";
413 /* Chars that mean this number is a floating point constant */
416 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
418 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
419 changed in read.c . Ideally it shouldn't have to know about it at all,
420 but nothing is ideal around here.
423 static char *insn_error
;
425 static int auto_align
= 1;
427 /* When outputting SVR4 PIC code, the assembler needs to know the
428 offset in the stack frame from which to restore the $gp register.
429 This is set by the .cprestore pseudo-op, and saved in this
431 static offsetT mips_cprestore_offset
= -1;
433 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
434 more optimizations, it can use a register value instead of a memory-saved
435 offset and even an other register than $gp as global pointer. */
436 static offsetT mips_cpreturn_offset
= -1;
437 static int mips_cpreturn_register
= -1;
438 static int mips_gp_register
= GP
;
439 static int mips_gprel_offset
= 0;
441 /* Whether mips_cprestore_offset has been set in the current function
442 (or whether it has already been warned about, if not). */
443 static int mips_cprestore_valid
= 0;
445 /* This is the register which holds the stack frame, as set by the
446 .frame pseudo-op. This is needed to implement .cprestore. */
447 static int mips_frame_reg
= SP
;
449 /* Whether mips_frame_reg has been set in the current function
450 (or whether it has already been warned about, if not). */
451 static int mips_frame_reg_valid
= 0;
453 /* To output NOP instructions correctly, we need to keep information
454 about the previous two instructions. */
456 /* Whether we are optimizing. The default value of 2 means to remove
457 unneeded NOPs and swap branch instructions when possible. A value
458 of 1 means to not swap branches. A value of 0 means to always
460 static int mips_optimize
= 2;
462 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
463 equivalent to seeing no -g option at all. */
464 static int mips_debug
= 0;
466 /* The previous instruction. */
467 static struct mips_cl_insn prev_insn
;
469 /* The instruction before prev_insn. */
470 static struct mips_cl_insn prev_prev_insn
;
472 /* If we don't want information for prev_insn or prev_prev_insn, we
473 point the insn_mo field at this dummy integer. */
474 static const struct mips_opcode dummy_opcode
= { NULL
, NULL
, 0, 0, 0, 0 };
476 /* Non-zero if prev_insn is valid. */
477 static int prev_insn_valid
;
479 /* The frag for the previous instruction. */
480 static struct frag
*prev_insn_frag
;
482 /* The offset into prev_insn_frag for the previous instruction. */
483 static long prev_insn_where
;
485 /* The reloc type for the previous instruction, if any. */
486 static bfd_reloc_code_real_type prev_insn_reloc_type
[3];
488 /* The reloc for the previous instruction, if any. */
489 static fixS
*prev_insn_fixp
[3];
491 /* Non-zero if the previous instruction was in a delay slot. */
492 static int prev_insn_is_delay_slot
;
494 /* Non-zero if the previous instruction was in a .set noreorder. */
495 static int prev_insn_unreordered
;
497 /* Non-zero if the previous instruction uses an extend opcode (if
499 static int prev_insn_extended
;
501 /* Non-zero if the previous previous instruction was in a .set
503 static int prev_prev_insn_unreordered
;
505 /* If this is set, it points to a frag holding nop instructions which
506 were inserted before the start of a noreorder section. If those
507 nops turn out to be unnecessary, the size of the frag can be
509 static fragS
*prev_nop_frag
;
511 /* The number of nop instructions we created in prev_nop_frag. */
512 static int prev_nop_frag_holds
;
514 /* The number of nop instructions that we know we need in
516 static int prev_nop_frag_required
;
518 /* The number of instructions we've seen since prev_nop_frag. */
519 static int prev_nop_frag_since
;
521 /* For ECOFF and ELF, relocations against symbols are done in two
522 parts, with a HI relocation and a LO relocation. Each relocation
523 has only 16 bits of space to store an addend. This means that in
524 order for the linker to handle carries correctly, it must be able
525 to locate both the HI and the LO relocation. This means that the
526 relocations must appear in order in the relocation table.
528 In order to implement this, we keep track of each unmatched HI
529 relocation. We then sort them so that they immediately precede the
530 corresponding LO relocation. */
535 struct mips_hi_fixup
*next
;
538 /* The section this fixup is in. */
542 /* The list of unmatched HI relocs. */
544 static struct mips_hi_fixup
*mips_hi_fixup_list
;
546 /* Map normal MIPS register numbers to mips16 register numbers. */
548 #define X ILLEGAL_REG
549 static const int mips32_to_16_reg_map
[] =
551 X
, X
, 2, 3, 4, 5, 6, 7,
552 X
, X
, X
, X
, X
, X
, X
, X
,
553 0, 1, X
, X
, X
, X
, X
, X
,
554 X
, X
, X
, X
, X
, X
, X
, X
558 /* Map mips16 register numbers to normal MIPS register numbers. */
560 static const unsigned int mips16_to_32_reg_map
[] =
562 16, 17, 2, 3, 4, 5, 6, 7
565 static int mips_fix_4122_bugs
;
567 /* We don't relax branches by default, since this causes us to expand
568 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
569 fail to compute the offset before expanding the macro to the most
570 efficient expansion. */
572 static int mips_relax_branch
;
574 /* Since the MIPS does not have multiple forms of PC relative
575 instructions, we do not have to do relaxing as is done on other
576 platforms. However, we do have to handle GP relative addressing
577 correctly, which turns out to be a similar problem.
579 Every macro that refers to a symbol can occur in (at least) two
580 forms, one with GP relative addressing and one without. For
581 example, loading a global variable into a register generally uses
582 a macro instruction like this:
584 If i can be addressed off the GP register (this is true if it is in
585 the .sbss or .sdata section, or if it is known to be smaller than
586 the -G argument) this will generate the following instruction:
588 This instruction will use a GPREL reloc. If i can not be addressed
589 off the GP register, the following instruction sequence will be used:
592 In this case the first instruction will have a HI16 reloc, and the
593 second reloc will have a LO16 reloc. Both relocs will be against
596 The issue here is that we may not know whether i is GP addressable
597 until after we see the instruction that uses it. Therefore, we
598 want to be able to choose the final instruction sequence only at
599 the end of the assembly. This is similar to the way other
600 platforms choose the size of a PC relative instruction only at the
603 When generating position independent code we do not use GP
604 addressing in quite the same way, but the issue still arises as
605 external symbols and local symbols must be handled differently.
607 We handle these issues by actually generating both possible
608 instruction sequences. The longer one is put in a frag_var with
609 type rs_machine_dependent. We encode what to do with the frag in
610 the subtype field. We encode (1) the number of existing bytes to
611 replace, (2) the number of new bytes to use, (3) the offset from
612 the start of the existing bytes to the first reloc we must generate
613 (that is, the offset is applied from the start of the existing
614 bytes after they are replaced by the new bytes, if any), (4) the
615 offset from the start of the existing bytes to the second reloc,
616 (5) whether a third reloc is needed (the third reloc is always four
617 bytes after the second reloc), and (6) whether to warn if this
618 variant is used (this is sometimes needed if .set nomacro or .set
619 noat is in effect). All these numbers are reasonably small.
621 Generating two instruction sequences must be handled carefully to
622 ensure that delay slots are handled correctly. Fortunately, there
623 are a limited number of cases. When the second instruction
624 sequence is generated, append_insn is directed to maintain the
625 existing delay slot information, so it continues to apply to any
626 code after the second instruction sequence. This means that the
627 second instruction sequence must not impose any requirements not
628 required by the first instruction sequence.
630 These variant frags are then handled in functions called by the
631 machine independent code. md_estimate_size_before_relax returns
632 the final size of the frag. md_convert_frag sets up the final form
633 of the frag. tc_gen_reloc adjust the first reloc and adds a second
635 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
639 | (((reloc1) + 64) << 9) \
640 | (((reloc2) + 64) << 2) \
641 | ((reloc3) ? (1 << 1) : 0) \
643 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
644 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
645 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
646 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
647 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
648 #define RELAX_WARN(i) ((i) & 1)
650 /* Branch without likely bit. If label is out of range, we turn:
652 beq reg1, reg2, label
662 with the following opcode replacements:
669 bltzal <-> bgezal (with jal label instead of j label)
671 Even though keeping the delay slot instruction in the delay slot of
672 the branch would be more efficient, it would be very tricky to do
673 correctly, because we'd have to introduce a variable frag *after*
674 the delay slot instruction, and expand that instead. Let's do it
675 the easy way for now, even if the branch-not-taken case now costs
676 one additional instruction. Out-of-range branches are not supposed
677 to be common, anyway.
679 Branch likely. If label is out of range, we turn:
681 beql reg1, reg2, label
682 delay slot (annulled if branch not taken)
691 delay slot (executed only if branch taken)
694 It would be possible to generate a shorter sequence by losing the
695 likely bit, generating something like:
700 delay slot (executed only if branch taken)
712 bltzall -> bgezal (with jal label instead of j label)
713 bgezall -> bltzal (ditto)
716 but it's not clear that it would actually improve performance. */
717 #define RELAX_BRANCH_ENCODE(reloc_s2, uncond, likely, link, toofar) \
720 | ((toofar) ? 1 : 0) \
722 | ((likely) ? 4 : 0) \
723 | ((uncond) ? 8 : 0) \
724 | ((reloc_s2) ? 16 : 0)))
725 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
726 #define RELAX_BRANCH_RELOC_S2(i) (((i) & 16) != 0)
727 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
728 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
729 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
730 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1))
732 /* For mips16 code, we use an entirely different form of relaxation.
733 mips16 supports two versions of most instructions which take
734 immediate values: a small one which takes some small value, and a
735 larger one which takes a 16 bit value. Since branches also follow
736 this pattern, relaxing these values is required.
738 We can assemble both mips16 and normal MIPS code in a single
739 object. Therefore, we need to support this type of relaxation at
740 the same time that we support the relaxation described above. We
741 use the high bit of the subtype field to distinguish these cases.
743 The information we store for this type of relaxation is the
744 argument code found in the opcode file for this relocation, whether
745 the user explicitly requested a small or extended form, and whether
746 the relocation is in a jump or jal delay slot. That tells us the
747 size of the value, and how it should be stored. We also store
748 whether the fragment is considered to be extended or not. We also
749 store whether this is known to be a branch to a different section,
750 whether we have tried to relax this frag yet, and whether we have
751 ever extended a PC relative fragment because of a shift count. */
752 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
755 | ((small) ? 0x100 : 0) \
756 | ((ext) ? 0x200 : 0) \
757 | ((dslot) ? 0x400 : 0) \
758 | ((jal_dslot) ? 0x800 : 0))
759 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
760 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
761 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
762 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
763 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
764 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
765 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
766 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
767 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
768 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
769 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
770 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
772 /* Is the given value a sign-extended 32-bit value? */
773 #define IS_SEXT_32BIT_NUM(x) \
774 (((x) &~ (offsetT) 0x7fffffff) == 0 \
775 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
777 /* Is the given value a sign-extended 16-bit value? */
778 #define IS_SEXT_16BIT_NUM(x) \
779 (((x) &~ (offsetT) 0x7fff) == 0 \
780 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
783 /* Prototypes for static functions. */
786 #define internalError() \
787 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
789 #define internalError() as_fatal (_("MIPS internal Error"));
792 enum mips_regclass
{ MIPS_GR_REG
, MIPS_FP_REG
, MIPS16_REG
};
794 static int insn_uses_reg
PARAMS ((struct mips_cl_insn
*ip
,
795 unsigned int reg
, enum mips_regclass
class));
796 static int reg_needs_delay
PARAMS ((unsigned int));
797 static void mips16_mark_labels
PARAMS ((void));
798 static void append_insn
PARAMS ((char *place
,
799 struct mips_cl_insn
* ip
,
801 bfd_reloc_code_real_type
*r
,
803 static void mips_no_prev_insn
PARAMS ((int));
804 static void mips_emit_delays
PARAMS ((boolean
));
806 static void macro_build
PARAMS ((char *place
, int *counter
, expressionS
* ep
,
807 const char *name
, const char *fmt
,
810 static void macro_build ();
812 static void mips16_macro_build
PARAMS ((char *, int *, expressionS
*,
813 const char *, const char *,
815 static void macro_build_jalr
PARAMS ((int, expressionS
*));
816 static void macro_build_lui
PARAMS ((char *place
, int *counter
,
817 expressionS
* ep
, int regnum
));
818 static void macro_build_ldst_constoffset
PARAMS ((char *place
, int *counter
,
819 expressionS
* ep
, const char *op
,
820 int valreg
, int breg
));
821 static void set_at
PARAMS ((int *counter
, int reg
, int unsignedp
));
822 static void check_absolute_expr
PARAMS ((struct mips_cl_insn
* ip
,
824 static void load_register
PARAMS ((int *, int, expressionS
*, int));
825 static void load_address
PARAMS ((int *, int, expressionS
*, int *));
826 static void move_register
PARAMS ((int *, int, int));
827 static void macro
PARAMS ((struct mips_cl_insn
* ip
));
828 static void mips16_macro
PARAMS ((struct mips_cl_insn
* ip
));
829 #ifdef LOSING_COMPILER
830 static void macro2
PARAMS ((struct mips_cl_insn
* ip
));
832 static void mips_ip
PARAMS ((char *str
, struct mips_cl_insn
* ip
));
833 static void mips16_ip
PARAMS ((char *str
, struct mips_cl_insn
* ip
));
834 static void mips16_immed
PARAMS ((char *, unsigned int, int, offsetT
, boolean
,
835 boolean
, boolean
, unsigned long *,
836 boolean
*, unsigned short *));
837 static int my_getPercentOp
PARAMS ((char **, unsigned int *, int *));
838 static int my_getSmallParser
PARAMS ((char **, unsigned int *, int *));
839 static int my_getSmallExpression
PARAMS ((expressionS
*, char *));
840 static void my_getExpression
PARAMS ((expressionS
*, char *));
842 static int support_64bit_objects
PARAMS((void));
844 static void mips_set_option_string
PARAMS ((const char **, const char *));
845 static symbolS
*get_symbol
PARAMS ((void));
846 static void mips_align
PARAMS ((int to
, int fill
, symbolS
*label
));
847 static void s_align
PARAMS ((int));
848 static void s_change_sec
PARAMS ((int));
849 static void s_change_section
PARAMS ((int));
850 static void s_cons
PARAMS ((int));
851 static void s_float_cons
PARAMS ((int));
852 static void s_mips_globl
PARAMS ((int));
853 static void s_option
PARAMS ((int));
854 static void s_mipsset
PARAMS ((int));
855 static void s_abicalls
PARAMS ((int));
856 static void s_cpload
PARAMS ((int));
857 static void s_cpsetup
PARAMS ((int));
858 static void s_cplocal
PARAMS ((int));
859 static void s_cprestore
PARAMS ((int));
860 static void s_cpreturn
PARAMS ((int));
861 static void s_gpvalue
PARAMS ((int));
862 static void s_gpword
PARAMS ((int));
863 static void s_gpdword
PARAMS ((int));
864 static void s_cpadd
PARAMS ((int));
865 static void s_insn
PARAMS ((int));
866 static void md_obj_begin
PARAMS ((void));
867 static void md_obj_end
PARAMS ((void));
868 static long get_number
PARAMS ((void));
869 static void s_mips_ent
PARAMS ((int));
870 static void s_mips_end
PARAMS ((int));
871 static void s_mips_frame
PARAMS ((int));
872 static void s_mips_mask
PARAMS ((int));
873 static void s_mips_stab
PARAMS ((int));
874 static void s_mips_weakext
PARAMS ((int));
875 static void s_mips_file
PARAMS ((int));
876 static void s_mips_loc
PARAMS ((int));
877 static int mips16_extended_frag
PARAMS ((fragS
*, asection
*, long));
878 static int relaxed_branch_length (fragS
*, asection
*, int);
879 static int validate_mips_insn
PARAMS ((const struct mips_opcode
*));
880 static void show
PARAMS ((FILE *, const char *, int *, int *));
882 static int mips_need_elf_addend_fixup
PARAMS ((fixS
*));
885 /* Return values of my_getSmallExpression(). */
892 /* Direct relocation creation by %percent_op(). */
911 /* Table and functions used to map between CPU/ISA names, and
912 ISA levels, and CPU numbers. */
916 const char *name
; /* CPU or ISA name. */
917 int is_isa
; /* Is this an ISA? (If 0, a CPU.) */
918 int isa
; /* ISA level. */
919 int cpu
; /* CPU number (default CPU if ISA). */
922 static void mips_set_architecture
PARAMS ((const struct mips_cpu_info
*));
923 static void mips_set_tune
PARAMS ((const struct mips_cpu_info
*));
924 static boolean mips_strict_matching_cpu_name_p
PARAMS ((const char *,
926 static boolean mips_matching_cpu_name_p
PARAMS ((const char *, const char *));
927 static const struct mips_cpu_info
*mips_parse_cpu
PARAMS ((const char *,
929 static const struct mips_cpu_info
*mips_cpu_info_from_isa
PARAMS ((int));
933 The following pseudo-ops from the Kane and Heinrich MIPS book
934 should be defined here, but are currently unsupported: .alias,
935 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
937 The following pseudo-ops from the Kane and Heinrich MIPS book are
938 specific to the type of debugging information being generated, and
939 should be defined by the object format: .aent, .begin, .bend,
940 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
943 The following pseudo-ops from the Kane and Heinrich MIPS book are
944 not MIPS CPU specific, but are also not specific to the object file
945 format. This file is probably the best place to define them, but
946 they are not currently supported: .asm0, .endr, .lab, .repeat,
949 static const pseudo_typeS mips_pseudo_table
[] =
951 /* MIPS specific pseudo-ops. */
952 {"option", s_option
, 0},
953 {"set", s_mipsset
, 0},
954 {"rdata", s_change_sec
, 'r'},
955 {"sdata", s_change_sec
, 's'},
956 {"livereg", s_ignore
, 0},
957 {"abicalls", s_abicalls
, 0},
958 {"cpload", s_cpload
, 0},
959 {"cpsetup", s_cpsetup
, 0},
960 {"cplocal", s_cplocal
, 0},
961 {"cprestore", s_cprestore
, 0},
962 {"cpreturn", s_cpreturn
, 0},
963 {"gpvalue", s_gpvalue
, 0},
964 {"gpword", s_gpword
, 0},
965 {"gpdword", s_gpdword
, 0},
966 {"cpadd", s_cpadd
, 0},
969 /* Relatively generic pseudo-ops that happen to be used on MIPS
971 {"asciiz", stringer
, 1},
972 {"bss", s_change_sec
, 'b'},
975 {"dword", s_cons
, 3},
976 {"weakext", s_mips_weakext
, 0},
978 /* These pseudo-ops are defined in read.c, but must be overridden
979 here for one reason or another. */
980 {"align", s_align
, 0},
982 {"data", s_change_sec
, 'd'},
983 {"double", s_float_cons
, 'd'},
984 {"float", s_float_cons
, 'f'},
985 {"globl", s_mips_globl
, 0},
986 {"global", s_mips_globl
, 0},
987 {"hword", s_cons
, 1},
992 {"section", s_change_section
, 0},
993 {"short", s_cons
, 1},
994 {"single", s_float_cons
, 'f'},
995 {"stabn", s_mips_stab
, 'n'},
996 {"text", s_change_sec
, 't'},
999 { "extern", ecoff_directive_extern
, 0},
1004 static const pseudo_typeS mips_nonecoff_pseudo_table
[] =
1006 /* These pseudo-ops should be defined by the object file format.
1007 However, a.out doesn't support them, so we have versions here. */
1008 {"aent", s_mips_ent
, 1},
1009 {"bgnb", s_ignore
, 0},
1010 {"end", s_mips_end
, 0},
1011 {"endb", s_ignore
, 0},
1012 {"ent", s_mips_ent
, 0},
1013 {"file", s_mips_file
, 0},
1014 {"fmask", s_mips_mask
, 'F'},
1015 {"frame", s_mips_frame
, 0},
1016 {"loc", s_mips_loc
, 0},
1017 {"mask", s_mips_mask
, 'R'},
1018 {"verstamp", s_ignore
, 0},
1022 extern void pop_insert
PARAMS ((const pseudo_typeS
*));
1027 pop_insert (mips_pseudo_table
);
1028 if (! ECOFF_DEBUGGING
)
1029 pop_insert (mips_nonecoff_pseudo_table
);
1032 /* Symbols labelling the current insn. */
1034 struct insn_label_list
1036 struct insn_label_list
*next
;
1040 static struct insn_label_list
*insn_labels
;
1041 static struct insn_label_list
*free_insn_labels
;
1043 static void mips_clear_insn_labels
PARAMS ((void));
1046 mips_clear_insn_labels ()
1048 register struct insn_label_list
**pl
;
1050 for (pl
= &free_insn_labels
; *pl
!= NULL
; pl
= &(*pl
)->next
)
1056 static char *expr_end
;
1058 /* Expressions which appear in instructions. These are set by
1061 static expressionS imm_expr
;
1062 static expressionS offset_expr
;
1064 /* Relocs associated with imm_expr and offset_expr. */
1066 static bfd_reloc_code_real_type imm_reloc
[3]
1067 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1068 static bfd_reloc_code_real_type offset_reloc
[3]
1069 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1071 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
1073 static boolean imm_unmatched_hi
;
1075 /* These are set by mips16_ip if an explicit extension is used. */
1077 static boolean mips16_small
, mips16_ext
;
1080 /* The pdr segment for per procedure frame/regmask info. Not used for
1083 static segT pdr_seg
;
1086 /* The default target format to use. */
1089 mips_target_format ()
1091 switch (OUTPUT_FLAVOR
)
1093 case bfd_target_aout_flavour
:
1094 return target_big_endian
? "a.out-mips-big" : "a.out-mips-little";
1095 case bfd_target_ecoff_flavour
:
1096 return target_big_endian
? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT
;
1097 case bfd_target_coff_flavour
:
1099 case bfd_target_elf_flavour
:
1101 /* This is traditional mips. */
1102 return (target_big_endian
1103 ? (HAVE_64BIT_OBJECTS
1104 ? "elf64-tradbigmips"
1106 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1107 : (HAVE_64BIT_OBJECTS
1108 ? "elf64-tradlittlemips"
1110 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1112 return (target_big_endian
1113 ? (HAVE_64BIT_OBJECTS
1116 ? "elf32-nbigmips" : "elf32-bigmips"))
1117 : (HAVE_64BIT_OBJECTS
1118 ? "elf64-littlemips"
1120 ? "elf32-nlittlemips" : "elf32-littlemips")));
1128 /* This function is called once, at assembler startup time. It should
1129 set up all the tables, etc. that the MD part of the assembler will need. */
1134 register const char *retval
= NULL
;
1138 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_mips
, mips_arch
))
1139 as_warn (_("Could not set architecture and machine"));
1141 op_hash
= hash_new ();
1143 for (i
= 0; i
< NUMOPCODES
;)
1145 const char *name
= mips_opcodes
[i
].name
;
1147 retval
= hash_insert (op_hash
, name
, (PTR
) &mips_opcodes
[i
]);
1150 fprintf (stderr
, _("internal error: can't hash `%s': %s\n"),
1151 mips_opcodes
[i
].name
, retval
);
1152 /* Probably a memory allocation problem? Give up now. */
1153 as_fatal (_("Broken assembler. No assembly attempted."));
1157 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
)
1159 if (!validate_mips_insn (&mips_opcodes
[i
]))
1164 while ((i
< NUMOPCODES
) && !strcmp (mips_opcodes
[i
].name
, name
));
1167 mips16_op_hash
= hash_new ();
1170 while (i
< bfd_mips16_num_opcodes
)
1172 const char *name
= mips16_opcodes
[i
].name
;
1174 retval
= hash_insert (mips16_op_hash
, name
, (PTR
) &mips16_opcodes
[i
]);
1176 as_fatal (_("internal: can't hash `%s': %s"),
1177 mips16_opcodes
[i
].name
, retval
);
1180 if (mips16_opcodes
[i
].pinfo
!= INSN_MACRO
1181 && ((mips16_opcodes
[i
].match
& mips16_opcodes
[i
].mask
)
1182 != mips16_opcodes
[i
].match
))
1184 fprintf (stderr
, _("internal error: bad mips16 opcode: %s %s\n"),
1185 mips16_opcodes
[i
].name
, mips16_opcodes
[i
].args
);
1190 while (i
< bfd_mips16_num_opcodes
1191 && strcmp (mips16_opcodes
[i
].name
, name
) == 0);
1195 as_fatal (_("Broken assembler. No assembly attempted."));
1197 /* We add all the general register names to the symbol table. This
1198 helps us detect invalid uses of them. */
1199 for (i
= 0; i
< 32; i
++)
1203 sprintf (buf
, "$%d", i
);
1204 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
1205 &zero_address_frag
));
1207 symbol_table_insert (symbol_new ("$ra", reg_section
, RA
,
1208 &zero_address_frag
));
1209 symbol_table_insert (symbol_new ("$fp", reg_section
, FP
,
1210 &zero_address_frag
));
1211 symbol_table_insert (symbol_new ("$sp", reg_section
, SP
,
1212 &zero_address_frag
));
1213 symbol_table_insert (symbol_new ("$gp", reg_section
, GP
,
1214 &zero_address_frag
));
1215 symbol_table_insert (symbol_new ("$at", reg_section
, AT
,
1216 &zero_address_frag
));
1217 symbol_table_insert (symbol_new ("$kt0", reg_section
, KT0
,
1218 &zero_address_frag
));
1219 symbol_table_insert (symbol_new ("$kt1", reg_section
, KT1
,
1220 &zero_address_frag
));
1221 symbol_table_insert (symbol_new ("$zero", reg_section
, ZERO
,
1222 &zero_address_frag
));
1223 symbol_table_insert (symbol_new ("$pc", reg_section
, -1,
1224 &zero_address_frag
));
1226 mips_no_prev_insn (false);
1229 mips_cprmask
[0] = 0;
1230 mips_cprmask
[1] = 0;
1231 mips_cprmask
[2] = 0;
1232 mips_cprmask
[3] = 0;
1234 /* set the default alignment for the text section (2**2) */
1235 record_alignment (text_section
, 2);
1237 if (USE_GLOBAL_POINTER_OPT
)
1238 bfd_set_gp_size (stdoutput
, g_switch_value
);
1240 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1242 /* On a native system, sections must be aligned to 16 byte
1243 boundaries. When configured for an embedded ELF target, we
1245 if (strcmp (TARGET_OS
, "elf") != 0)
1247 (void) bfd_set_section_alignment (stdoutput
, text_section
, 4);
1248 (void) bfd_set_section_alignment (stdoutput
, data_section
, 4);
1249 (void) bfd_set_section_alignment (stdoutput
, bss_section
, 4);
1252 /* Create a .reginfo section for register masks and a .mdebug
1253 section for debugging information. */
1261 subseg
= now_subseg
;
1263 /* The ABI says this section should be loaded so that the
1264 running program can access it. However, we don't load it
1265 if we are configured for an embedded target */
1266 flags
= SEC_READONLY
| SEC_DATA
;
1267 if (strcmp (TARGET_OS
, "elf") != 0)
1268 flags
|= SEC_ALLOC
| SEC_LOAD
;
1270 if (mips_abi
!= N64_ABI
)
1272 sec
= subseg_new (".reginfo", (subsegT
) 0);
1274 bfd_set_section_flags (stdoutput
, sec
, flags
);
1275 bfd_set_section_alignment (stdoutput
, sec
, HAVE_NEWABI
? 3 : 2);
1278 mips_regmask_frag
= frag_more (sizeof (Elf32_External_RegInfo
));
1283 /* The 64-bit ABI uses a .MIPS.options section rather than
1284 .reginfo section. */
1285 sec
= subseg_new (".MIPS.options", (subsegT
) 0);
1286 bfd_set_section_flags (stdoutput
, sec
, flags
);
1287 bfd_set_section_alignment (stdoutput
, sec
, 3);
1290 /* Set up the option header. */
1292 Elf_Internal_Options opthdr
;
1295 opthdr
.kind
= ODK_REGINFO
;
1296 opthdr
.size
= (sizeof (Elf_External_Options
)
1297 + sizeof (Elf64_External_RegInfo
));
1300 f
= frag_more (sizeof (Elf_External_Options
));
1301 bfd_mips_elf_swap_options_out (stdoutput
, &opthdr
,
1302 (Elf_External_Options
*) f
);
1304 mips_regmask_frag
= frag_more (sizeof (Elf64_External_RegInfo
));
1309 if (ECOFF_DEBUGGING
)
1311 sec
= subseg_new (".mdebug", (subsegT
) 0);
1312 (void) bfd_set_section_flags (stdoutput
, sec
,
1313 SEC_HAS_CONTENTS
| SEC_READONLY
);
1314 (void) bfd_set_section_alignment (stdoutput
, sec
, 2);
1317 else if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1319 pdr_seg
= subseg_new (".pdr", (subsegT
) 0);
1320 (void) bfd_set_section_flags (stdoutput
, pdr_seg
,
1321 SEC_READONLY
| SEC_RELOC
1323 (void) bfd_set_section_alignment (stdoutput
, pdr_seg
, 2);
1327 subseg_set (seg
, subseg
);
1331 if (! ECOFF_DEBUGGING
)
1338 if (! ECOFF_DEBUGGING
)
1346 struct mips_cl_insn insn
;
1347 bfd_reloc_code_real_type unused_reloc
[3]
1348 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1350 imm_expr
.X_op
= O_absent
;
1351 imm_unmatched_hi
= false;
1352 offset_expr
.X_op
= O_absent
;
1353 imm_reloc
[0] = BFD_RELOC_UNUSED
;
1354 imm_reloc
[1] = BFD_RELOC_UNUSED
;
1355 imm_reloc
[2] = BFD_RELOC_UNUSED
;
1356 offset_reloc
[0] = BFD_RELOC_UNUSED
;
1357 offset_reloc
[1] = BFD_RELOC_UNUSED
;
1358 offset_reloc
[2] = BFD_RELOC_UNUSED
;
1360 if (mips_opts
.mips16
)
1361 mips16_ip (str
, &insn
);
1364 mips_ip (str
, &insn
);
1365 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1366 str
, insn
.insn_opcode
));
1371 as_bad ("%s `%s'", insn_error
, str
);
1375 if (insn
.insn_mo
->pinfo
== INSN_MACRO
)
1377 if (mips_opts
.mips16
)
1378 mips16_macro (&insn
);
1384 if (imm_expr
.X_op
!= O_absent
)
1385 append_insn (NULL
, &insn
, &imm_expr
, imm_reloc
, imm_unmatched_hi
);
1386 else if (offset_expr
.X_op
!= O_absent
)
1387 append_insn (NULL
, &insn
, &offset_expr
, offset_reloc
, false);
1389 append_insn (NULL
, &insn
, NULL
, unused_reloc
, false);
1393 /* See whether instruction IP reads register REG. CLASS is the type
1397 insn_uses_reg (ip
, reg
, class)
1398 struct mips_cl_insn
*ip
;
1400 enum mips_regclass
class;
1402 if (class == MIPS16_REG
)
1404 assert (mips_opts
.mips16
);
1405 reg
= mips16_to_32_reg_map
[reg
];
1406 class = MIPS_GR_REG
;
1409 /* Don't report on general register ZERO, since it never changes. */
1410 if (class == MIPS_GR_REG
&& reg
== ZERO
)
1413 if (class == MIPS_FP_REG
)
1415 assert (! mips_opts
.mips16
);
1416 /* If we are called with either $f0 or $f1, we must check $f0.
1417 This is not optimal, because it will introduce an unnecessary
1418 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1419 need to distinguish reading both $f0 and $f1 or just one of
1420 them. Note that we don't have to check the other way,
1421 because there is no instruction that sets both $f0 and $f1
1422 and requires a delay. */
1423 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_S
)
1424 && ((((ip
->insn_opcode
>> OP_SH_FS
) & OP_MASK_FS
) &~(unsigned)1)
1425 == (reg
&~ (unsigned) 1)))
1427 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_T
)
1428 && ((((ip
->insn_opcode
>> OP_SH_FT
) & OP_MASK_FT
) &~(unsigned)1)
1429 == (reg
&~ (unsigned) 1)))
1432 else if (! mips_opts
.mips16
)
1434 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_S
)
1435 && ((ip
->insn_opcode
>> OP_SH_RS
) & OP_MASK_RS
) == reg
)
1437 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_T
)
1438 && ((ip
->insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
) == reg
)
1443 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_X
)
1444 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_RX
)
1445 & MIPS16OP_MASK_RX
)]
1448 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Y
)
1449 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_RY
)
1450 & MIPS16OP_MASK_RY
)]
1453 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Z
)
1454 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_MOVE32Z
)
1455 & MIPS16OP_MASK_MOVE32Z
)]
1458 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_T
) && reg
== TREG
)
1460 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_SP
) && reg
== SP
)
1462 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_31
) && reg
== RA
)
1464 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_GPR_X
)
1465 && ((ip
->insn_opcode
>> MIPS16OP_SH_REGR32
)
1466 & MIPS16OP_MASK_REGR32
) == reg
)
1473 /* This function returns true if modifying a register requires a
1477 reg_needs_delay (reg
)
1480 unsigned long prev_pinfo
;
1482 prev_pinfo
= prev_insn
.insn_mo
->pinfo
;
1483 if (! mips_opts
.noreorder
1484 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1485 && ((prev_pinfo
& INSN_LOAD_COPROC_DELAY
)
1486 || (! gpr_interlocks
1487 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))))
1489 /* A load from a coprocessor or from memory. All load
1490 delays delay the use of general register rt for one
1491 instruction on the r3000. The r6000 and r4000 use
1493 /* Itbl support may require additional care here. */
1494 know (prev_pinfo
& INSN_WRITE_GPR_T
);
1495 if (reg
== ((prev_insn
.insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
))
1502 /* Mark instruction labels in mips16 mode. This permits the linker to
1503 handle them specially, such as generating jalx instructions when
1504 needed. We also make them odd for the duration of the assembly, in
1505 order to generate the right sort of code. We will make them even
1506 in the adjust_symtab routine, while leaving them marked. This is
1507 convenient for the debugger and the disassembler. The linker knows
1508 to make them odd again. */
1511 mips16_mark_labels ()
1513 if (mips_opts
.mips16
)
1515 struct insn_label_list
*l
;
1518 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
1521 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1522 S_SET_OTHER (l
->label
, STO_MIPS16
);
1524 val
= S_GET_VALUE (l
->label
);
1526 S_SET_VALUE (l
->label
, val
+ 1);
1531 /* Output an instruction. PLACE is where to put the instruction; if
1532 it is NULL, this uses frag_more to get room. IP is the instruction
1533 information. ADDRESS_EXPR is an operand of the instruction to be
1534 used with RELOC_TYPE. */
1537 append_insn (place
, ip
, address_expr
, reloc_type
, unmatched_hi
)
1539 struct mips_cl_insn
*ip
;
1540 expressionS
*address_expr
;
1541 bfd_reloc_code_real_type
*reloc_type
;
1542 boolean unmatched_hi
;
1544 register unsigned long prev_pinfo
, pinfo
;
1549 /* Mark instruction labels in mips16 mode. */
1550 mips16_mark_labels ();
1552 prev_pinfo
= prev_insn
.insn_mo
->pinfo
;
1553 pinfo
= ip
->insn_mo
->pinfo
;
1555 if (place
== NULL
&& (! mips_opts
.noreorder
|| prev_nop_frag
!= NULL
))
1559 /* If the previous insn required any delay slots, see if we need
1560 to insert a NOP or two. There are eight kinds of possible
1561 hazards, of which an instruction can have at most one type.
1562 (1) a load from memory delay
1563 (2) a load from a coprocessor delay
1564 (3) an unconditional branch delay
1565 (4) a conditional branch delay
1566 (5) a move to coprocessor register delay
1567 (6) a load coprocessor register from memory delay
1568 (7) a coprocessor condition code delay
1569 (8) a HI/LO special register delay
1571 There are a lot of optimizations we could do that we don't.
1572 In particular, we do not, in general, reorder instructions.
1573 If you use gcc with optimization, it will reorder
1574 instructions and generally do much more optimization then we
1575 do here; repeating all that work in the assembler would only
1576 benefit hand written assembly code, and does not seem worth
1579 /* This is how a NOP is emitted. */
1580 #define emit_nop() \
1582 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1583 : md_number_to_chars (frag_more (4), 0, 4))
1585 /* The previous insn might require a delay slot, depending upon
1586 the contents of the current insn. */
1587 if (! mips_opts
.mips16
1588 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1589 && (((prev_pinfo
& INSN_LOAD_COPROC_DELAY
)
1590 && ! cop_interlocks
)
1591 || (! gpr_interlocks
1592 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))))
1594 /* A load from a coprocessor or from memory. All load
1595 delays delay the use of general register rt for one
1596 instruction on the r3000. The r6000 and r4000 use
1598 /* Itbl support may require additional care here. */
1599 know (prev_pinfo
& INSN_WRITE_GPR_T
);
1600 if (mips_optimize
== 0
1601 || insn_uses_reg (ip
,
1602 ((prev_insn
.insn_opcode
>> OP_SH_RT
)
1607 else if (! mips_opts
.mips16
1608 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1609 && (((prev_pinfo
& INSN_COPROC_MOVE_DELAY
)
1610 && ! cop_interlocks
)
1611 || (mips_opts
.isa
== ISA_MIPS1
1612 && (prev_pinfo
& INSN_COPROC_MEMORY_DELAY
))))
1614 /* A generic coprocessor delay. The previous instruction
1615 modified a coprocessor general or control register. If
1616 it modified a control register, we need to avoid any
1617 coprocessor instruction (this is probably not always
1618 required, but it sometimes is). If it modified a general
1619 register, we avoid using that register.
1621 On the r6000 and r4000 loading a coprocessor register
1622 from memory is interlocked, and does not require a delay.
1624 This case is not handled very well. There is no special
1625 knowledge of CP0 handling, and the coprocessors other
1626 than the floating point unit are not distinguished at
1628 /* Itbl support may require additional care here. FIXME!
1629 Need to modify this to include knowledge about
1630 user specified delays! */
1631 if (prev_pinfo
& INSN_WRITE_FPR_T
)
1633 if (mips_optimize
== 0
1634 || insn_uses_reg (ip
,
1635 ((prev_insn
.insn_opcode
>> OP_SH_FT
)
1640 else if (prev_pinfo
& INSN_WRITE_FPR_S
)
1642 if (mips_optimize
== 0
1643 || insn_uses_reg (ip
,
1644 ((prev_insn
.insn_opcode
>> OP_SH_FS
)
1651 /* We don't know exactly what the previous instruction
1652 does. If the current instruction uses a coprocessor
1653 register, we must insert a NOP. If previous
1654 instruction may set the condition codes, and the
1655 current instruction uses them, we must insert two
1657 /* Itbl support may require additional care here. */
1658 if (mips_optimize
== 0
1659 || ((prev_pinfo
& INSN_WRITE_COND_CODE
)
1660 && (pinfo
& INSN_READ_COND_CODE
)))
1662 else if (pinfo
& INSN_COP
)
1666 else if (! mips_opts
.mips16
1667 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1668 && (prev_pinfo
& INSN_WRITE_COND_CODE
)
1669 && ! cop_interlocks
)
1671 /* The previous instruction sets the coprocessor condition
1672 codes, but does not require a general coprocessor delay
1673 (this means it is a floating point comparison
1674 instruction). If this instruction uses the condition
1675 codes, we need to insert a single NOP. */
1676 /* Itbl support may require additional care here. */
1677 if (mips_optimize
== 0
1678 || (pinfo
& INSN_READ_COND_CODE
))
1682 /* If we're fixing up mfhi/mflo for the r7000 and the
1683 previous insn was an mfhi/mflo and the current insn
1684 reads the register that the mfhi/mflo wrote to, then
1687 else if (mips_7000_hilo_fix
1688 && MF_HILO_INSN (prev_pinfo
)
1689 && insn_uses_reg (ip
, ((prev_insn
.insn_opcode
>> OP_SH_RD
)
1696 /* If we're fixing up mfhi/mflo for the r7000 and the
1697 2nd previous insn was an mfhi/mflo and the current insn
1698 reads the register that the mfhi/mflo wrote to, then
1701 else if (mips_7000_hilo_fix
1702 && MF_HILO_INSN (prev_prev_insn
.insn_opcode
)
1703 && insn_uses_reg (ip
, ((prev_prev_insn
.insn_opcode
>> OP_SH_RD
)
1711 else if (prev_pinfo
& INSN_READ_LO
)
1713 /* The previous instruction reads the LO register; if the
1714 current instruction writes to the LO register, we must
1715 insert two NOPS. Some newer processors have interlocks.
1716 Also the tx39's multiply instructions can be exectuted
1717 immediatly after a read from HI/LO (without the delay),
1718 though the tx39's divide insns still do require the
1720 if (! (hilo_interlocks
1721 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
1722 && (mips_optimize
== 0
1723 || (pinfo
& INSN_WRITE_LO
)))
1725 /* Most mips16 branch insns don't have a delay slot.
1726 If a read from LO is immediately followed by a branch
1727 to a write to LO we have a read followed by a write
1728 less than 2 insns away. We assume the target of
1729 a branch might be a write to LO, and insert a nop
1730 between a read and an immediately following branch. */
1731 else if (mips_opts
.mips16
1732 && (mips_optimize
== 0
1733 || (pinfo
& MIPS16_INSN_BRANCH
)))
1736 else if (prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
1738 /* The previous instruction reads the HI register; if the
1739 current instruction writes to the HI register, we must
1740 insert a NOP. Some newer processors have interlocks.
1741 Also the note tx39's multiply above. */
1742 if (! (hilo_interlocks
1743 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
1744 && (mips_optimize
== 0
1745 || (pinfo
& INSN_WRITE_HI
)))
1747 /* Most mips16 branch insns don't have a delay slot.
1748 If a read from HI is immediately followed by a branch
1749 to a write to HI we have a read followed by a write
1750 less than 2 insns away. We assume the target of
1751 a branch might be a write to HI, and insert a nop
1752 between a read and an immediately following branch. */
1753 else if (mips_opts
.mips16
1754 && (mips_optimize
== 0
1755 || (pinfo
& MIPS16_INSN_BRANCH
)))
1759 /* If the previous instruction was in a noreorder section, then
1760 we don't want to insert the nop after all. */
1761 /* Itbl support may require additional care here. */
1762 if (prev_insn_unreordered
)
1765 /* There are two cases which require two intervening
1766 instructions: 1) setting the condition codes using a move to
1767 coprocessor instruction which requires a general coprocessor
1768 delay and then reading the condition codes 2) reading the HI
1769 or LO register and then writing to it (except on processors
1770 which have interlocks). If we are not already emitting a NOP
1771 instruction, we must check for these cases compared to the
1772 instruction previous to the previous instruction. */
1773 if ((! mips_opts
.mips16
1774 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1775 && (prev_prev_insn
.insn_mo
->pinfo
& INSN_COPROC_MOVE_DELAY
)
1776 && (prev_prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
)
1777 && (pinfo
& INSN_READ_COND_CODE
)
1778 && ! cop_interlocks
)
1779 || ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
)
1780 && (pinfo
& INSN_WRITE_LO
)
1781 && ! (hilo_interlocks
1782 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
))))
1783 || ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
1784 && (pinfo
& INSN_WRITE_HI
)
1785 && ! (hilo_interlocks
1786 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))))
1791 if (prev_prev_insn_unreordered
)
1794 if (prev_prev_nop
&& nops
== 0)
1797 if (mips_fix_4122_bugs
&& prev_insn
.insn_mo
->name
)
1799 /* We're out of bits in pinfo, so we must resort to string
1800 ops here. Shortcuts are selected based on opcodes being
1801 limited to the VR4122 instruction set. */
1803 const char *pn
= prev_insn
.insn_mo
->name
;
1804 const char *tn
= ip
->insn_mo
->name
;
1805 if (strncmp(pn
, "macc", 4) == 0
1806 || strncmp(pn
, "dmacc", 5) == 0)
1808 /* Errata 21 - [D]DIV[U] after [D]MACC */
1809 if (strstr (tn
, "div"))
1814 /* Errata 23 - Continuous DMULT[U]/DMACC instructions */
1815 if (pn
[0] == 'd' /* dmacc */
1816 && (strncmp(tn
, "dmult", 5) == 0
1817 || strncmp(tn
, "dmacc", 5) == 0))
1822 /* Errata 24 - MT{LO,HI} after [D]MACC */
1823 if (strcmp (tn
, "mtlo") == 0
1824 || strcmp (tn
, "mthi") == 0)
1830 else if (strncmp(pn
, "dmult", 5) == 0
1831 && (strncmp(tn
, "dmult", 5) == 0
1832 || strncmp(tn
, "dmacc", 5) == 0))
1834 /* Here is the rest of errata 23. */
1837 if (nops
< min_nops
)
1841 /* If we are being given a nop instruction, don't bother with
1842 one of the nops we would otherwise output. This will only
1843 happen when a nop instruction is used with mips_optimize set
1846 && ! mips_opts
.noreorder
1847 && ip
->insn_opcode
== (unsigned) (mips_opts
.mips16
? 0x6500 : 0))
1850 /* Now emit the right number of NOP instructions. */
1851 if (nops
> 0 && ! mips_opts
.noreorder
)
1854 unsigned long old_frag_offset
;
1856 struct insn_label_list
*l
;
1858 old_frag
= frag_now
;
1859 old_frag_offset
= frag_now_fix ();
1861 for (i
= 0; i
< nops
; i
++)
1866 listing_prev_line ();
1867 /* We may be at the start of a variant frag. In case we
1868 are, make sure there is enough space for the frag
1869 after the frags created by listing_prev_line. The
1870 argument to frag_grow here must be at least as large
1871 as the argument to all other calls to frag_grow in
1872 this file. We don't have to worry about being in the
1873 middle of a variant frag, because the variants insert
1874 all needed nop instructions themselves. */
1878 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
1882 assert (S_GET_SEGMENT (l
->label
) == now_seg
);
1883 symbol_set_frag (l
->label
, frag_now
);
1884 val
= (valueT
) frag_now_fix ();
1885 /* mips16 text labels are stored as odd. */
1886 if (mips_opts
.mips16
)
1888 S_SET_VALUE (l
->label
, val
);
1891 #ifndef NO_ECOFF_DEBUGGING
1892 if (ECOFF_DEBUGGING
)
1893 ecoff_fix_loc (old_frag
, old_frag_offset
);
1896 else if (prev_nop_frag
!= NULL
)
1898 /* We have a frag holding nops we may be able to remove. If
1899 we don't need any nops, we can decrease the size of
1900 prev_nop_frag by the size of one instruction. If we do
1901 need some nops, we count them in prev_nops_required. */
1902 if (prev_nop_frag_since
== 0)
1906 prev_nop_frag
->fr_fix
-= mips_opts
.mips16
? 2 : 4;
1907 --prev_nop_frag_holds
;
1910 prev_nop_frag_required
+= nops
;
1914 if (prev_prev_nop
== 0)
1916 prev_nop_frag
->fr_fix
-= mips_opts
.mips16
? 2 : 4;
1917 --prev_nop_frag_holds
;
1920 ++prev_nop_frag_required
;
1923 if (prev_nop_frag_holds
<= prev_nop_frag_required
)
1924 prev_nop_frag
= NULL
;
1926 ++prev_nop_frag_since
;
1928 /* Sanity check: by the time we reach the second instruction
1929 after prev_nop_frag, we should have used up all the nops
1930 one way or another. */
1931 assert (prev_nop_frag_since
<= 1 || prev_nop_frag
== NULL
);
1937 && ((*reloc_type
== BFD_RELOC_16_PCREL
1938 && address_expr
->X_op
!= O_constant
)
1939 || *reloc_type
== BFD_RELOC_16_PCREL_S2
)
1940 && (pinfo
& INSN_UNCOND_BRANCH_DELAY
|| pinfo
& INSN_COND_BRANCH_DELAY
1941 || pinfo
& INSN_COND_BRANCH_LIKELY
)
1942 && mips_relax_branch
1943 /* Don't try branch relaxation within .set nomacro, or within
1944 .set noat if we use $at for PIC computations. If it turns
1945 out that the branch was out-of-range, we'll get an error. */
1946 && !mips_opts
.warn_about_macros
1947 && !(mips_opts
.noat
&& mips_pic
!= NO_PIC
)
1948 && !mips_opts
.mips16
)
1950 f
= frag_var (rs_machine_dependent
,
1951 relaxed_branch_length
1953 (pinfo
& INSN_UNCOND_BRANCH_DELAY
) ? -1
1954 : (pinfo
& INSN_COND_BRANCH_LIKELY
) ? 1 : 0), 4,
1956 (*reloc_type
== BFD_RELOC_16_PCREL_S2
,
1957 pinfo
& INSN_UNCOND_BRANCH_DELAY
,
1958 pinfo
& INSN_COND_BRANCH_LIKELY
,
1959 pinfo
& INSN_WRITE_GPR_31
,
1961 address_expr
->X_add_symbol
,
1962 address_expr
->X_add_number
,
1964 *reloc_type
= BFD_RELOC_UNUSED
;
1966 else if (*reloc_type
> BFD_RELOC_UNUSED
)
1968 /* We need to set up a variant frag. */
1969 assert (mips_opts
.mips16
&& address_expr
!= NULL
);
1970 f
= frag_var (rs_machine_dependent
, 4, 0,
1971 RELAX_MIPS16_ENCODE (*reloc_type
- BFD_RELOC_UNUSED
,
1972 mips16_small
, mips16_ext
,
1974 & INSN_UNCOND_BRANCH_DELAY
),
1975 (*prev_insn_reloc_type
1976 == BFD_RELOC_MIPS16_JMP
)),
1977 make_expr_symbol (address_expr
), 0, NULL
);
1979 else if (place
!= NULL
)
1981 else if (mips_opts
.mips16
1983 && *reloc_type
!= BFD_RELOC_MIPS16_JMP
)
1985 /* Make sure there is enough room to swap this instruction with
1986 a following jump instruction. */
1992 if (mips_opts
.mips16
1993 && mips_opts
.noreorder
1994 && (prev_pinfo
& INSN_UNCOND_BRANCH_DELAY
) != 0)
1995 as_warn (_("extended instruction in delay slot"));
2000 fixp
[0] = fixp
[1] = fixp
[2] = NULL
;
2001 if (address_expr
!= NULL
&& *reloc_type
< BFD_RELOC_UNUSED
)
2003 if (address_expr
->X_op
== O_constant
)
2007 switch (*reloc_type
)
2010 ip
->insn_opcode
|= address_expr
->X_add_number
;
2013 case BFD_RELOC_MIPS_HIGHEST
:
2014 tmp
= (address_expr
->X_add_number
+ 0x800080008000) >> 16;
2016 ip
->insn_opcode
|= (tmp
>> 16) & 0xffff;
2019 case BFD_RELOC_MIPS_HIGHER
:
2020 tmp
= (address_expr
->X_add_number
+ 0x80008000) >> 16;
2021 ip
->insn_opcode
|= (tmp
>> 16) & 0xffff;
2024 case BFD_RELOC_HI16_S
:
2025 ip
->insn_opcode
|= ((address_expr
->X_add_number
+ 0x8000)
2029 case BFD_RELOC_HI16
:
2030 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 16) & 0xffff;
2033 case BFD_RELOC_LO16
:
2034 case BFD_RELOC_MIPS_GOT_DISP
:
2035 ip
->insn_opcode
|= address_expr
->X_add_number
& 0xffff;
2038 case BFD_RELOC_MIPS_JMP
:
2039 if ((address_expr
->X_add_number
& 3) != 0)
2040 as_bad (_("jump to misaligned address (0x%lx)"),
2041 (unsigned long) address_expr
->X_add_number
);
2042 if (address_expr
->X_add_number
& ~0xfffffff)
2043 as_bad (_("jump address range overflow (0x%lx)"),
2044 (unsigned long) address_expr
->X_add_number
);
2045 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 2) & 0x3ffffff;
2048 case BFD_RELOC_MIPS16_JMP
:
2049 if ((address_expr
->X_add_number
& 3) != 0)
2050 as_bad (_("jump to misaligned address (0x%lx)"),
2051 (unsigned long) address_expr
->X_add_number
);
2052 if (address_expr
->X_add_number
& ~0xfffffff)
2053 as_bad (_("jump address range overflow (0x%lx)"),
2054 (unsigned long) address_expr
->X_add_number
);
2056 (((address_expr
->X_add_number
& 0x7c0000) << 3)
2057 | ((address_expr
->X_add_number
& 0xf800000) >> 7)
2058 | ((address_expr
->X_add_number
& 0x3fffc) >> 2));
2061 case BFD_RELOC_16_PCREL
:
2062 ip
->insn_opcode
|= address_expr
->X_add_number
& 0xffff;
2065 case BFD_RELOC_16_PCREL_S2
:
2075 /* Don't generate a reloc if we are writing into a variant frag. */
2078 fixp
[0] = fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
2080 (*reloc_type
== BFD_RELOC_16_PCREL
2081 || *reloc_type
== BFD_RELOC_16_PCREL_S2
),
2084 /* These relocations can have an addend that won't fit in
2085 4 octets for 64bit assembly. */
2086 if (HAVE_64BIT_GPRS
&&
2087 (*reloc_type
== BFD_RELOC_16
2088 || *reloc_type
== BFD_RELOC_32
2089 || *reloc_type
== BFD_RELOC_MIPS_JMP
2090 || *reloc_type
== BFD_RELOC_HI16_S
2091 || *reloc_type
== BFD_RELOC_LO16
2092 || *reloc_type
== BFD_RELOC_GPREL16
2093 || *reloc_type
== BFD_RELOC_MIPS_LITERAL
2094 || *reloc_type
== BFD_RELOC_GPREL32
2095 || *reloc_type
== BFD_RELOC_64
2096 || *reloc_type
== BFD_RELOC_CTOR
2097 || *reloc_type
== BFD_RELOC_MIPS_SUB
2098 || *reloc_type
== BFD_RELOC_MIPS_HIGHEST
2099 || *reloc_type
== BFD_RELOC_MIPS_HIGHER
2100 || *reloc_type
== BFD_RELOC_MIPS_SCN_DISP
2101 || *reloc_type
== BFD_RELOC_MIPS_REL16
2102 || *reloc_type
== BFD_RELOC_MIPS_RELGOT
))
2103 fixp
[0]->fx_no_overflow
= 1;
2107 struct mips_hi_fixup
*hi_fixup
;
2109 assert (*reloc_type
== BFD_RELOC_HI16_S
);
2110 hi_fixup
= ((struct mips_hi_fixup
*)
2111 xmalloc (sizeof (struct mips_hi_fixup
)));
2112 hi_fixup
->fixp
= fixp
[0];
2113 hi_fixup
->seg
= now_seg
;
2114 hi_fixup
->next
= mips_hi_fixup_list
;
2115 mips_hi_fixup_list
= hi_fixup
;
2118 if (reloc_type
[1] != BFD_RELOC_UNUSED
)
2120 /* FIXME: This symbol can be one of
2121 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
2122 address_expr
->X_op
= O_absent
;
2123 address_expr
->X_add_symbol
= 0;
2124 address_expr
->X_add_number
= 0;
2126 fixp
[1] = fix_new_exp (frag_now
, f
- frag_now
->fr_literal
,
2127 4, address_expr
, false,
2130 /* These relocations can have an addend that won't fit in
2131 4 octets for 64bit assembly. */
2132 if (HAVE_64BIT_GPRS
&&
2133 (*reloc_type
== BFD_RELOC_16
2134 || *reloc_type
== BFD_RELOC_32
2135 || *reloc_type
== BFD_RELOC_MIPS_JMP
2136 || *reloc_type
== BFD_RELOC_HI16_S
2137 || *reloc_type
== BFD_RELOC_LO16
2138 || *reloc_type
== BFD_RELOC_GPREL16
2139 || *reloc_type
== BFD_RELOC_MIPS_LITERAL
2140 || *reloc_type
== BFD_RELOC_GPREL32
2141 || *reloc_type
== BFD_RELOC_64
2142 || *reloc_type
== BFD_RELOC_CTOR
2143 || *reloc_type
== BFD_RELOC_MIPS_SUB
2144 || *reloc_type
== BFD_RELOC_MIPS_HIGHEST
2145 || *reloc_type
== BFD_RELOC_MIPS_HIGHER
2146 || *reloc_type
== BFD_RELOC_MIPS_SCN_DISP
2147 || *reloc_type
== BFD_RELOC_MIPS_REL16
2148 || *reloc_type
== BFD_RELOC_MIPS_RELGOT
))
2149 fixp
[1]->fx_no_overflow
= 1;
2151 if (reloc_type
[2] != BFD_RELOC_UNUSED
)
2153 address_expr
->X_op
= O_absent
;
2154 address_expr
->X_add_symbol
= 0;
2155 address_expr
->X_add_number
= 0;
2157 fixp
[2] = fix_new_exp (frag_now
,
2158 f
- frag_now
->fr_literal
, 4,
2159 address_expr
, false,
2162 /* These relocations can have an addend that won't fit in
2163 4 octets for 64bit assembly. */
2164 if (HAVE_64BIT_GPRS
&&
2165 (*reloc_type
== BFD_RELOC_16
2166 || *reloc_type
== BFD_RELOC_32
2167 || *reloc_type
== BFD_RELOC_MIPS_JMP
2168 || *reloc_type
== BFD_RELOC_HI16_S
2169 || *reloc_type
== BFD_RELOC_LO16
2170 || *reloc_type
== BFD_RELOC_GPREL16
2171 || *reloc_type
== BFD_RELOC_MIPS_LITERAL
2172 || *reloc_type
== BFD_RELOC_GPREL32
2173 || *reloc_type
== BFD_RELOC_64
2174 || *reloc_type
== BFD_RELOC_CTOR
2175 || *reloc_type
== BFD_RELOC_MIPS_SUB
2176 || *reloc_type
== BFD_RELOC_MIPS_HIGHEST
2177 || *reloc_type
== BFD_RELOC_MIPS_HIGHER
2178 || *reloc_type
== BFD_RELOC_MIPS_SCN_DISP
2179 || *reloc_type
== BFD_RELOC_MIPS_REL16
2180 || *reloc_type
== BFD_RELOC_MIPS_RELGOT
))
2181 fixp
[2]->fx_no_overflow
= 1;
2188 if (! mips_opts
.mips16
)
2190 md_number_to_chars (f
, ip
->insn_opcode
, 4);
2192 dwarf2_emit_insn (4);
2195 else if (*reloc_type
== BFD_RELOC_MIPS16_JMP
)
2197 md_number_to_chars (f
, ip
->insn_opcode
>> 16, 2);
2198 md_number_to_chars (f
+ 2, ip
->insn_opcode
& 0xffff, 2);
2200 dwarf2_emit_insn (4);
2207 md_number_to_chars (f
, 0xf000 | ip
->extend
, 2);
2210 md_number_to_chars (f
, ip
->insn_opcode
, 2);
2212 dwarf2_emit_insn (ip
->use_extend
? 4 : 2);
2216 /* Update the register mask information. */
2217 if (! mips_opts
.mips16
)
2219 if (pinfo
& INSN_WRITE_GPR_D
)
2220 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
);
2221 if ((pinfo
& (INSN_WRITE_GPR_T
| INSN_READ_GPR_T
)) != 0)
2222 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
);
2223 if (pinfo
& INSN_READ_GPR_S
)
2224 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RS
) & OP_MASK_RS
);
2225 if (pinfo
& INSN_WRITE_GPR_31
)
2226 mips_gprmask
|= 1 << RA
;
2227 if (pinfo
& INSN_WRITE_FPR_D
)
2228 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FD
) & OP_MASK_FD
);
2229 if ((pinfo
& (INSN_WRITE_FPR_S
| INSN_READ_FPR_S
)) != 0)
2230 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FS
) & OP_MASK_FS
);
2231 if ((pinfo
& (INSN_WRITE_FPR_T
| INSN_READ_FPR_T
)) != 0)
2232 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FT
) & OP_MASK_FT
);
2233 if ((pinfo
& INSN_READ_FPR_R
) != 0)
2234 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FR
) & OP_MASK_FR
);
2235 if (pinfo
& INSN_COP
)
2237 /* We don't keep enough information to sort these cases out.
2238 The itbl support does keep this information however, although
2239 we currently don't support itbl fprmats as part of the cop
2240 instruction. May want to add this support in the future. */
2242 /* Never set the bit for $0, which is always zero. */
2243 mips_gprmask
&= ~1 << 0;
2247 if (pinfo
& (MIPS16_INSN_WRITE_X
| MIPS16_INSN_READ_X
))
2248 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RX
)
2249 & MIPS16OP_MASK_RX
);
2250 if (pinfo
& (MIPS16_INSN_WRITE_Y
| MIPS16_INSN_READ_Y
))
2251 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RY
)
2252 & MIPS16OP_MASK_RY
);
2253 if (pinfo
& MIPS16_INSN_WRITE_Z
)
2254 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RZ
)
2255 & MIPS16OP_MASK_RZ
);
2256 if (pinfo
& (MIPS16_INSN_WRITE_T
| MIPS16_INSN_READ_T
))
2257 mips_gprmask
|= 1 << TREG
;
2258 if (pinfo
& (MIPS16_INSN_WRITE_SP
| MIPS16_INSN_READ_SP
))
2259 mips_gprmask
|= 1 << SP
;
2260 if (pinfo
& (MIPS16_INSN_WRITE_31
| MIPS16_INSN_READ_31
))
2261 mips_gprmask
|= 1 << RA
;
2262 if (pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2263 mips_gprmask
|= 1 << MIPS16OP_EXTRACT_REG32R (ip
->insn_opcode
);
2264 if (pinfo
& MIPS16_INSN_READ_Z
)
2265 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_MOVE32Z
)
2266 & MIPS16OP_MASK_MOVE32Z
);
2267 if (pinfo
& MIPS16_INSN_READ_GPR_X
)
2268 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_REGR32
)
2269 & MIPS16OP_MASK_REGR32
);
2272 if (place
== NULL
&& ! mips_opts
.noreorder
)
2274 /* Filling the branch delay slot is more complex. We try to
2275 switch the branch with the previous instruction, which we can
2276 do if the previous instruction does not set up a condition
2277 that the branch tests and if the branch is not itself the
2278 target of any branch. */
2279 if ((pinfo
& INSN_UNCOND_BRANCH_DELAY
)
2280 || (pinfo
& INSN_COND_BRANCH_DELAY
))
2282 if (mips_optimize
< 2
2283 /* If we have seen .set volatile or .set nomove, don't
2285 || mips_opts
.nomove
!= 0
2286 /* If we had to emit any NOP instructions, then we
2287 already know we can not swap. */
2289 /* If we don't even know the previous insn, we can not
2291 || ! prev_insn_valid
2292 /* If the previous insn is already in a branch delay
2293 slot, then we can not swap. */
2294 || prev_insn_is_delay_slot
2295 /* If the previous previous insn was in a .set
2296 noreorder, we can't swap. Actually, the MIPS
2297 assembler will swap in this situation. However, gcc
2298 configured -with-gnu-as will generate code like
2304 in which we can not swap the bne and INSN. If gcc is
2305 not configured -with-gnu-as, it does not output the
2306 .set pseudo-ops. We don't have to check
2307 prev_insn_unreordered, because prev_insn_valid will
2308 be 0 in that case. We don't want to use
2309 prev_prev_insn_valid, because we do want to be able
2310 to swap at the start of a function. */
2311 || prev_prev_insn_unreordered
2312 /* If the branch is itself the target of a branch, we
2313 can not swap. We cheat on this; all we check for is
2314 whether there is a label on this instruction. If
2315 there are any branches to anything other than a
2316 label, users must use .set noreorder. */
2317 || insn_labels
!= NULL
2318 /* If the previous instruction is in a variant frag, we
2319 can not do the swap. This does not apply to the
2320 mips16, which uses variant frags for different
2322 || (! mips_opts
.mips16
2323 && prev_insn_frag
->fr_type
== rs_machine_dependent
)
2324 /* If the branch reads the condition codes, we don't
2325 even try to swap, because in the sequence
2330 we can not swap, and I don't feel like handling that
2332 || (! mips_opts
.mips16
2333 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2334 && (pinfo
& INSN_READ_COND_CODE
))
2335 /* We can not swap with an instruction that requires a
2336 delay slot, becase the target of the branch might
2337 interfere with that instruction. */
2338 || (! mips_opts
.mips16
2339 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2341 /* Itbl support may require additional care here. */
2342 & (INSN_LOAD_COPROC_DELAY
2343 | INSN_COPROC_MOVE_DELAY
2344 | INSN_WRITE_COND_CODE
)))
2345 || (! (hilo_interlocks
2346 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
2350 || (! mips_opts
.mips16
2352 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))
2353 || (! mips_opts
.mips16
2354 && mips_opts
.isa
== ISA_MIPS1
2355 /* Itbl support may require additional care here. */
2356 && (prev_pinfo
& INSN_COPROC_MEMORY_DELAY
))
2357 /* We can not swap with a branch instruction. */
2359 & (INSN_UNCOND_BRANCH_DELAY
2360 | INSN_COND_BRANCH_DELAY
2361 | INSN_COND_BRANCH_LIKELY
))
2362 /* We do not swap with a trap instruction, since it
2363 complicates trap handlers to have the trap
2364 instruction be in a delay slot. */
2365 || (prev_pinfo
& INSN_TRAP
)
2366 /* If the branch reads a register that the previous
2367 instruction sets, we can not swap. */
2368 || (! mips_opts
.mips16
2369 && (prev_pinfo
& INSN_WRITE_GPR_T
)
2370 && insn_uses_reg (ip
,
2371 ((prev_insn
.insn_opcode
>> OP_SH_RT
)
2374 || (! mips_opts
.mips16
2375 && (prev_pinfo
& INSN_WRITE_GPR_D
)
2376 && insn_uses_reg (ip
,
2377 ((prev_insn
.insn_opcode
>> OP_SH_RD
)
2380 || (mips_opts
.mips16
2381 && (((prev_pinfo
& MIPS16_INSN_WRITE_X
)
2382 && insn_uses_reg (ip
,
2383 ((prev_insn
.insn_opcode
2385 & MIPS16OP_MASK_RX
),
2387 || ((prev_pinfo
& MIPS16_INSN_WRITE_Y
)
2388 && insn_uses_reg (ip
,
2389 ((prev_insn
.insn_opcode
2391 & MIPS16OP_MASK_RY
),
2393 || ((prev_pinfo
& MIPS16_INSN_WRITE_Z
)
2394 && insn_uses_reg (ip
,
2395 ((prev_insn
.insn_opcode
2397 & MIPS16OP_MASK_RZ
),
2399 || ((prev_pinfo
& MIPS16_INSN_WRITE_T
)
2400 && insn_uses_reg (ip
, TREG
, MIPS_GR_REG
))
2401 || ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
2402 && insn_uses_reg (ip
, RA
, MIPS_GR_REG
))
2403 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2404 && insn_uses_reg (ip
,
2405 MIPS16OP_EXTRACT_REG32R (prev_insn
.
2408 /* If the branch writes a register that the previous
2409 instruction sets, we can not swap (we know that
2410 branches write only to RD or to $31). */
2411 || (! mips_opts
.mips16
2412 && (prev_pinfo
& INSN_WRITE_GPR_T
)
2413 && (((pinfo
& INSN_WRITE_GPR_D
)
2414 && (((prev_insn
.insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
)
2415 == ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)))
2416 || ((pinfo
& INSN_WRITE_GPR_31
)
2417 && (((prev_insn
.insn_opcode
>> OP_SH_RT
)
2420 || (! mips_opts
.mips16
2421 && (prev_pinfo
& INSN_WRITE_GPR_D
)
2422 && (((pinfo
& INSN_WRITE_GPR_D
)
2423 && (((prev_insn
.insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)
2424 == ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)))
2425 || ((pinfo
& INSN_WRITE_GPR_31
)
2426 && (((prev_insn
.insn_opcode
>> OP_SH_RD
)
2429 || (mips_opts
.mips16
2430 && (pinfo
& MIPS16_INSN_WRITE_31
)
2431 && ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
2432 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2433 && (MIPS16OP_EXTRACT_REG32R (prev_insn
.insn_opcode
)
2435 /* If the branch writes a register that the previous
2436 instruction reads, we can not swap (we know that
2437 branches only write to RD or to $31). */
2438 || (! mips_opts
.mips16
2439 && (pinfo
& INSN_WRITE_GPR_D
)
2440 && insn_uses_reg (&prev_insn
,
2441 ((ip
->insn_opcode
>> OP_SH_RD
)
2444 || (! mips_opts
.mips16
2445 && (pinfo
& INSN_WRITE_GPR_31
)
2446 && insn_uses_reg (&prev_insn
, RA
, MIPS_GR_REG
))
2447 || (mips_opts
.mips16
2448 && (pinfo
& MIPS16_INSN_WRITE_31
)
2449 && insn_uses_reg (&prev_insn
, RA
, MIPS_GR_REG
))
2450 /* If we are generating embedded PIC code, the branch
2451 might be expanded into a sequence which uses $at, so
2452 we can't swap with an instruction which reads it. */
2453 || (mips_pic
== EMBEDDED_PIC
2454 && insn_uses_reg (&prev_insn
, AT
, MIPS_GR_REG
))
2455 /* If the previous previous instruction has a load
2456 delay, and sets a register that the branch reads, we
2458 || (! mips_opts
.mips16
2459 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2460 /* Itbl support may require additional care here. */
2461 && ((prev_prev_insn
.insn_mo
->pinfo
& INSN_LOAD_COPROC_DELAY
)
2462 || (! gpr_interlocks
2463 && (prev_prev_insn
.insn_mo
->pinfo
2464 & INSN_LOAD_MEMORY_DELAY
)))
2465 && insn_uses_reg (ip
,
2466 ((prev_prev_insn
.insn_opcode
>> OP_SH_RT
)
2469 /* If one instruction sets a condition code and the
2470 other one uses a condition code, we can not swap. */
2471 || ((pinfo
& INSN_READ_COND_CODE
)
2472 && (prev_pinfo
& INSN_WRITE_COND_CODE
))
2473 || ((pinfo
& INSN_WRITE_COND_CODE
)
2474 && (prev_pinfo
& INSN_READ_COND_CODE
))
2475 /* If the previous instruction uses the PC, we can not
2477 || (mips_opts
.mips16
2478 && (prev_pinfo
& MIPS16_INSN_READ_PC
))
2479 /* If the previous instruction was extended, we can not
2481 || (mips_opts
.mips16
&& prev_insn_extended
)
2482 /* If the previous instruction had a fixup in mips16
2483 mode, we can not swap. This normally means that the
2484 previous instruction was a 4 byte branch anyhow. */
2485 || (mips_opts
.mips16
&& prev_insn_fixp
[0])
2486 /* If the previous instruction is a sync, sync.l, or
2487 sync.p, we can not swap. */
2488 || (prev_pinfo
& INSN_SYNC
))
2490 /* We could do even better for unconditional branches to
2491 portions of this object file; we could pick up the
2492 instruction at the destination, put it in the delay
2493 slot, and bump the destination address. */
2495 /* Update the previous insn information. */
2496 prev_prev_insn
= *ip
;
2497 prev_insn
.insn_mo
= &dummy_opcode
;
2501 /* It looks like we can actually do the swap. */
2502 if (! mips_opts
.mips16
)
2507 prev_f
= prev_insn_frag
->fr_literal
+ prev_insn_where
;
2508 memcpy (temp
, prev_f
, 4);
2509 memcpy (prev_f
, f
, 4);
2510 memcpy (f
, temp
, 4);
2511 if (prev_insn_fixp
[0])
2513 prev_insn_fixp
[0]->fx_frag
= frag_now
;
2514 prev_insn_fixp
[0]->fx_where
= f
- frag_now
->fr_literal
;
2516 if (prev_insn_fixp
[1])
2518 prev_insn_fixp
[1]->fx_frag
= frag_now
;
2519 prev_insn_fixp
[1]->fx_where
= f
- frag_now
->fr_literal
;
2521 if (prev_insn_fixp
[2])
2523 prev_insn_fixp
[2]->fx_frag
= frag_now
;
2524 prev_insn_fixp
[2]->fx_where
= f
- frag_now
->fr_literal
;
2528 fixp
[0]->fx_frag
= prev_insn_frag
;
2529 fixp
[0]->fx_where
= prev_insn_where
;
2533 fixp
[1]->fx_frag
= prev_insn_frag
;
2534 fixp
[1]->fx_where
= prev_insn_where
;
2538 fixp
[2]->fx_frag
= prev_insn_frag
;
2539 fixp
[2]->fx_where
= prev_insn_where
;
2547 assert (prev_insn_fixp
[0] == NULL
);
2548 assert (prev_insn_fixp
[1] == NULL
);
2549 assert (prev_insn_fixp
[2] == NULL
);
2550 prev_f
= prev_insn_frag
->fr_literal
+ prev_insn_where
;
2551 memcpy (temp
, prev_f
, 2);
2552 memcpy (prev_f
, f
, 2);
2553 if (*reloc_type
!= BFD_RELOC_MIPS16_JMP
)
2555 assert (*reloc_type
== BFD_RELOC_UNUSED
);
2556 memcpy (f
, temp
, 2);
2560 memcpy (f
, f
+ 2, 2);
2561 memcpy (f
+ 2, temp
, 2);
2565 fixp
[0]->fx_frag
= prev_insn_frag
;
2566 fixp
[0]->fx_where
= prev_insn_where
;
2570 fixp
[1]->fx_frag
= prev_insn_frag
;
2571 fixp
[1]->fx_where
= prev_insn_where
;
2575 fixp
[2]->fx_frag
= prev_insn_frag
;
2576 fixp
[2]->fx_where
= prev_insn_where
;
2580 /* Update the previous insn information; leave prev_insn
2582 prev_prev_insn
= *ip
;
2584 prev_insn_is_delay_slot
= 1;
2586 /* If that was an unconditional branch, forget the previous
2587 insn information. */
2588 if (pinfo
& INSN_UNCOND_BRANCH_DELAY
)
2590 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2591 prev_insn
.insn_mo
= &dummy_opcode
;
2594 prev_insn_fixp
[0] = NULL
;
2595 prev_insn_fixp
[1] = NULL
;
2596 prev_insn_fixp
[2] = NULL
;
2597 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2598 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2599 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2600 prev_insn_extended
= 0;
2602 else if (pinfo
& INSN_COND_BRANCH_LIKELY
)
2604 /* We don't yet optimize a branch likely. What we should do
2605 is look at the target, copy the instruction found there
2606 into the delay slot, and increment the branch to jump to
2607 the next instruction. */
2609 /* Update the previous insn information. */
2610 prev_prev_insn
= *ip
;
2611 prev_insn
.insn_mo
= &dummy_opcode
;
2612 prev_insn_fixp
[0] = NULL
;
2613 prev_insn_fixp
[1] = NULL
;
2614 prev_insn_fixp
[2] = NULL
;
2615 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2616 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2617 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2618 prev_insn_extended
= 0;
2622 /* Update the previous insn information. */
2624 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2626 prev_prev_insn
= prev_insn
;
2629 /* Any time we see a branch, we always fill the delay slot
2630 immediately; since this insn is not a branch, we know it
2631 is not in a delay slot. */
2632 prev_insn_is_delay_slot
= 0;
2634 prev_insn_fixp
[0] = fixp
[0];
2635 prev_insn_fixp
[1] = fixp
[1];
2636 prev_insn_fixp
[2] = fixp
[2];
2637 prev_insn_reloc_type
[0] = reloc_type
[0];
2638 prev_insn_reloc_type
[1] = reloc_type
[1];
2639 prev_insn_reloc_type
[2] = reloc_type
[2];
2640 if (mips_opts
.mips16
)
2641 prev_insn_extended
= (ip
->use_extend
2642 || *reloc_type
> BFD_RELOC_UNUSED
);
2645 prev_prev_insn_unreordered
= prev_insn_unreordered
;
2646 prev_insn_unreordered
= 0;
2647 prev_insn_frag
= frag_now
;
2648 prev_insn_where
= f
- frag_now
->fr_literal
;
2649 prev_insn_valid
= 1;
2651 else if (place
== NULL
)
2653 /* We need to record a bit of information even when we are not
2654 reordering, in order to determine the base address for mips16
2655 PC relative relocs. */
2656 prev_prev_insn
= prev_insn
;
2658 prev_insn_reloc_type
[0] = reloc_type
[0];
2659 prev_insn_reloc_type
[1] = reloc_type
[1];
2660 prev_insn_reloc_type
[2] = reloc_type
[2];
2661 prev_prev_insn_unreordered
= prev_insn_unreordered
;
2662 prev_insn_unreordered
= 1;
2665 /* We just output an insn, so the next one doesn't have a label. */
2666 mips_clear_insn_labels ();
2668 /* We must ensure that a fixup associated with an unmatched %hi
2669 reloc does not become a variant frag. Otherwise, the
2670 rearrangement of %hi relocs in frob_file may confuse
2674 frag_wane (frag_now
);
2679 /* This function forgets that there was any previous instruction or
2680 label. If PRESERVE is non-zero, it remembers enough information to
2681 know whether nops are needed before a noreorder section. */
2684 mips_no_prev_insn (preserve
)
2689 prev_insn
.insn_mo
= &dummy_opcode
;
2690 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2691 prev_nop_frag
= NULL
;
2692 prev_nop_frag_holds
= 0;
2693 prev_nop_frag_required
= 0;
2694 prev_nop_frag_since
= 0;
2696 prev_insn_valid
= 0;
2697 prev_insn_is_delay_slot
= 0;
2698 prev_insn_unreordered
= 0;
2699 prev_insn_extended
= 0;
2700 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2701 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2702 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2703 prev_prev_insn_unreordered
= 0;
2704 mips_clear_insn_labels ();
2707 /* This function must be called whenever we turn on noreorder or emit
2708 something other than instructions. It inserts any NOPS which might
2709 be needed by the previous instruction, and clears the information
2710 kept for the previous instructions. The INSNS parameter is true if
2711 instructions are to follow. */
2714 mips_emit_delays (insns
)
2717 if (! mips_opts
.noreorder
)
2722 if ((! mips_opts
.mips16
2723 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2724 && (! cop_interlocks
2725 && (prev_insn
.insn_mo
->pinfo
2726 & (INSN_LOAD_COPROC_DELAY
2727 | INSN_COPROC_MOVE_DELAY
2728 | INSN_WRITE_COND_CODE
))))
2729 || (! hilo_interlocks
2730 && (prev_insn
.insn_mo
->pinfo
2733 || (! mips_opts
.mips16
2735 && (prev_insn
.insn_mo
->pinfo
2736 & INSN_LOAD_MEMORY_DELAY
))
2737 || (! mips_opts
.mips16
2738 && mips_opts
.isa
== ISA_MIPS1
2739 && (prev_insn
.insn_mo
->pinfo
2740 & INSN_COPROC_MEMORY_DELAY
)))
2742 /* Itbl support may require additional care here. */
2744 if ((! mips_opts
.mips16
2745 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2746 && (! cop_interlocks
2747 && prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
))
2748 || (! hilo_interlocks
2749 && ((prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
2750 || (prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
))))
2753 if (prev_insn_unreordered
)
2756 else if ((! mips_opts
.mips16
2757 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2758 && (! cop_interlocks
2759 && prev_prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
))
2760 || (! hilo_interlocks
2761 && ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
2762 || (prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
))))
2764 /* Itbl support may require additional care here. */
2765 if (! prev_prev_insn_unreordered
)
2769 if (mips_fix_4122_bugs
&& prev_insn
.insn_mo
->name
)
2772 const char *pn
= prev_insn
.insn_mo
->name
;
2773 if (strncmp(pn
, "macc", 4) == 0
2774 || strncmp(pn
, "dmacc", 5) == 0
2775 || strncmp(pn
, "dmult", 5) == 0)
2779 if (nops
< min_nops
)
2785 struct insn_label_list
*l
;
2789 /* Record the frag which holds the nop instructions, so
2790 that we can remove them if we don't need them. */
2791 frag_grow (mips_opts
.mips16
? nops
* 2 : nops
* 4);
2792 prev_nop_frag
= frag_now
;
2793 prev_nop_frag_holds
= nops
;
2794 prev_nop_frag_required
= 0;
2795 prev_nop_frag_since
= 0;
2798 for (; nops
> 0; --nops
)
2803 /* Move on to a new frag, so that it is safe to simply
2804 decrease the size of prev_nop_frag. */
2805 frag_wane (frag_now
);
2809 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
2813 assert (S_GET_SEGMENT (l
->label
) == now_seg
);
2814 symbol_set_frag (l
->label
, frag_now
);
2815 val
= (valueT
) frag_now_fix ();
2816 /* mips16 text labels are stored as odd. */
2817 if (mips_opts
.mips16
)
2819 S_SET_VALUE (l
->label
, val
);
2824 /* Mark instruction labels in mips16 mode. */
2826 mips16_mark_labels ();
2828 mips_no_prev_insn (insns
);
2831 /* Build an instruction created by a macro expansion. This is passed
2832 a pointer to the count of instructions created so far, an
2833 expression, the name of the instruction to build, an operand format
2834 string, and corresponding arguments. */
2838 macro_build (char *place
,
2846 macro_build (place
, counter
, ep
, name
, fmt
, va_alist
)
2855 struct mips_cl_insn insn
;
2856 bfd_reloc_code_real_type r
[3];
2860 va_start (args
, fmt
);
2866 * If the macro is about to expand into a second instruction,
2867 * print a warning if needed. We need to pass ip as a parameter
2868 * to generate a better warning message here...
2870 if (mips_opts
.warn_about_macros
&& place
== NULL
&& *counter
== 1)
2871 as_warn (_("Macro instruction expanded into multiple instructions"));
2874 * If the macro is about to expand into a second instruction,
2875 * and it is in a delay slot, print a warning.
2879 && mips_opts
.noreorder
2880 && (prev_prev_insn
.insn_mo
->pinfo
2881 & (INSN_UNCOND_BRANCH_DELAY
| INSN_COND_BRANCH_DELAY
2882 | INSN_COND_BRANCH_LIKELY
)) != 0)
2883 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2886 ++*counter
; /* bump instruction counter */
2888 if (mips_opts
.mips16
)
2890 mips16_macro_build (place
, counter
, ep
, name
, fmt
, args
);
2895 r
[0] = BFD_RELOC_UNUSED
;
2896 r
[1] = BFD_RELOC_UNUSED
;
2897 r
[2] = BFD_RELOC_UNUSED
;
2898 insn
.insn_mo
= (struct mips_opcode
*) hash_find (op_hash
, name
);
2899 assert (insn
.insn_mo
);
2900 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
2902 /* Search until we get a match for NAME. */
2905 /* It is assumed here that macros will never generate
2906 MDMX or MIPS-3D instructions. */
2907 if (strcmp (fmt
, insn
.insn_mo
->args
) == 0
2908 && insn
.insn_mo
->pinfo
!= INSN_MACRO
2909 && OPCODE_IS_MEMBER (insn
.insn_mo
,
2911 | (file_ase_mips16
? INSN_MIPS16
: 0)),
2913 && (mips_arch
!= CPU_R4650
|| (insn
.insn_mo
->pinfo
& FP_D
) == 0))
2917 assert (insn
.insn_mo
->name
);
2918 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
2921 insn
.insn_opcode
= insn
.insn_mo
->match
;
2937 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RT
;
2941 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE
;
2946 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FT
;
2951 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RD
;
2956 int tmp
= va_arg (args
, int);
2958 insn
.insn_opcode
|= tmp
<< OP_SH_RT
;
2959 insn
.insn_opcode
|= tmp
<< OP_SH_RD
;
2965 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FS
;
2972 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_SHAMT
;
2976 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FD
;
2980 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE20
;
2984 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE19
;
2988 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE2
;
2995 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RS
;
3001 *r
= (bfd_reloc_code_real_type
) va_arg (args
, int);
3002 assert (*r
== BFD_RELOC_GPREL16
3003 || *r
== BFD_RELOC_MIPS_LITERAL
3004 || *r
== BFD_RELOC_MIPS_HIGHER
3005 || *r
== BFD_RELOC_HI16_S
3006 || *r
== BFD_RELOC_LO16
3007 || *r
== BFD_RELOC_MIPS_GOT16
3008 || *r
== BFD_RELOC_MIPS_CALL16
3009 || *r
== BFD_RELOC_MIPS_GOT_DISP
3010 || *r
== BFD_RELOC_MIPS_GOT_PAGE
3011 || *r
== BFD_RELOC_MIPS_GOT_OFST
3012 || *r
== BFD_RELOC_MIPS_GOT_LO16
3013 || *r
== BFD_RELOC_MIPS_CALL_LO16
3014 || (ep
->X_op
== O_subtract
3015 && *r
== BFD_RELOC_PCREL_LO16
));
3019 *r
= (bfd_reloc_code_real_type
) va_arg (args
, int);
3021 && (ep
->X_op
== O_constant
3022 || (ep
->X_op
== O_symbol
3023 && (*r
== BFD_RELOC_MIPS_HIGHEST
3024 || *r
== BFD_RELOC_HI16_S
3025 || *r
== BFD_RELOC_HI16
3026 || *r
== BFD_RELOC_GPREL16
3027 || *r
== BFD_RELOC_MIPS_GOT_HI16
3028 || *r
== BFD_RELOC_MIPS_CALL_HI16
))
3029 || (ep
->X_op
== O_subtract
3030 && *r
== BFD_RELOC_PCREL_HI16_S
)));
3034 assert (ep
!= NULL
);
3036 * This allows macro() to pass an immediate expression for
3037 * creating short branches without creating a symbol.
3038 * Note that the expression still might come from the assembly
3039 * input, in which case the value is not checked for range nor
3040 * is a relocation entry generated (yuck).
3042 if (ep
->X_op
== O_constant
)
3044 insn
.insn_opcode
|= (ep
->X_add_number
>> 2) & 0xffff;
3048 if (mips_pic
== EMBEDDED_PIC
)
3049 *r
= BFD_RELOC_16_PCREL_S2
;
3051 *r
= BFD_RELOC_16_PCREL
;
3055 assert (ep
!= NULL
);
3056 *r
= BFD_RELOC_MIPS_JMP
;
3060 insn
.insn_opcode
|= va_arg (args
, unsigned long);
3069 assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3071 append_insn (place
, &insn
, ep
, r
, false);
3075 mips16_macro_build (place
, counter
, ep
, name
, fmt
, args
)
3077 int *counter ATTRIBUTE_UNUSED
;
3083 struct mips_cl_insn insn
;
3084 bfd_reloc_code_real_type r
[3]
3085 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3087 insn
.insn_mo
= (struct mips_opcode
*) hash_find (mips16_op_hash
, name
);
3088 assert (insn
.insn_mo
);
3089 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
3091 while (strcmp (fmt
, insn
.insn_mo
->args
) != 0
3092 || insn
.insn_mo
->pinfo
== INSN_MACRO
)
3095 assert (insn
.insn_mo
->name
);
3096 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
3099 insn
.insn_opcode
= insn
.insn_mo
->match
;
3100 insn
.use_extend
= false;
3119 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RY
;
3124 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RX
;
3128 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RZ
;
3132 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_MOVE32Z
;
3142 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_REGR32
;
3149 regno
= va_arg (args
, int);
3150 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
3151 insn
.insn_opcode
|= regno
<< MIPS16OP_SH_REG32R
;
3172 assert (ep
!= NULL
);
3174 if (ep
->X_op
!= O_constant
)
3175 *r
= (int) BFD_RELOC_UNUSED
+ c
;
3178 mips16_immed (NULL
, 0, c
, ep
->X_add_number
, false, false,
3179 false, &insn
.insn_opcode
, &insn
.use_extend
,
3182 *r
= BFD_RELOC_UNUSED
;
3188 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_IMM6
;
3195 assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3197 append_insn (place
, &insn
, ep
, r
, false);
3201 * Generate a "jalr" instruction with a relocation hint to the called
3202 * function. This occurs in NewABI PIC code.
3205 macro_build_jalr (icnt
, ep
)
3216 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "jalr", "d,s",
3219 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
,
3220 0, ep
, false, BFD_RELOC_MIPS_JALR
);
3224 * Generate a "lui" instruction.
3227 macro_build_lui (place
, counter
, ep
, regnum
)
3233 expressionS high_expr
;
3234 struct mips_cl_insn insn
;
3235 bfd_reloc_code_real_type r
[3]
3236 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3237 const char *name
= "lui";
3238 const char *fmt
= "t,u";
3240 assert (! mips_opts
.mips16
);
3246 high_expr
.X_op
= O_constant
;
3247 high_expr
.X_add_number
= ep
->X_add_number
;
3250 if (high_expr
.X_op
== O_constant
)
3252 /* we can compute the instruction now without a relocation entry */
3253 high_expr
.X_add_number
= ((high_expr
.X_add_number
+ 0x8000)
3255 *r
= BFD_RELOC_UNUSED
;
3257 else if (! HAVE_NEWABI
)
3259 assert (ep
->X_op
== O_symbol
);
3260 /* _gp_disp is a special case, used from s_cpload. */
3261 assert (mips_pic
== NO_PIC
3262 || strcmp (S_GET_NAME (ep
->X_add_symbol
), "_gp_disp") == 0);
3263 *r
= BFD_RELOC_HI16_S
;
3267 * If the macro is about to expand into a second instruction,
3268 * print a warning if needed. We need to pass ip as a parameter
3269 * to generate a better warning message here...
3271 if (mips_opts
.warn_about_macros
&& place
== NULL
&& *counter
== 1)
3272 as_warn (_("Macro instruction expanded into multiple instructions"));
3275 ++*counter
; /* bump instruction counter */
3277 insn
.insn_mo
= (struct mips_opcode
*) hash_find (op_hash
, name
);
3278 assert (insn
.insn_mo
);
3279 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
3280 assert (strcmp (fmt
, insn
.insn_mo
->args
) == 0);
3282 insn
.insn_opcode
= insn
.insn_mo
->match
| (regnum
<< OP_SH_RT
);
3283 if (*r
== BFD_RELOC_UNUSED
)
3285 insn
.insn_opcode
|= high_expr
.X_add_number
;
3286 append_insn (place
, &insn
, NULL
, r
, false);
3289 append_insn (place
, &insn
, &high_expr
, r
, false);
3292 /* Generate a sequence of instructions to do a load or store from a constant
3293 offset off of a base register (breg) into/from a target register (treg),
3294 using AT if necessary. */
3296 macro_build_ldst_constoffset (place
, counter
, ep
, op
, treg
, breg
)
3303 assert (ep
->X_op
== O_constant
);
3305 /* Right now, this routine can only handle signed 32-bit contants. */
3306 if (! IS_SEXT_32BIT_NUM(ep
->X_add_number
))
3307 as_warn (_("operand overflow"));
3309 if (IS_SEXT_16BIT_NUM(ep
->X_add_number
))
3311 /* Signed 16-bit offset will fit in the op. Easy! */
3312 macro_build (place
, counter
, ep
, op
, "t,o(b)", treg
,
3313 (int) BFD_RELOC_LO16
, breg
);
3317 /* 32-bit offset, need multiple instructions and AT, like:
3318 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3319 addu $tempreg,$tempreg,$breg
3320 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3321 to handle the complete offset. */
3322 macro_build_lui (place
, counter
, ep
, AT
);
3325 macro_build (place
, counter
, (expressionS
*) NULL
,
3326 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
3327 "d,v,t", AT
, AT
, breg
);
3330 macro_build (place
, counter
, ep
, op
, "t,o(b)", treg
,
3331 (int) BFD_RELOC_LO16
, AT
);
3334 as_warn (_("Macro used $at after \".set noat\""));
3339 * Generates code to set the $at register to true (one)
3340 * if reg is less than the immediate expression.
3343 set_at (counter
, reg
, unsignedp
)
3348 if (imm_expr
.X_op
== O_constant
3349 && imm_expr
.X_add_number
>= -0x8000
3350 && imm_expr
.X_add_number
< 0x8000)
3351 macro_build ((char *) NULL
, counter
, &imm_expr
,
3352 unsignedp
? "sltiu" : "slti",
3353 "t,r,j", AT
, reg
, (int) BFD_RELOC_LO16
);
3356 load_register (counter
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
3357 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3358 unsignedp
? "sltu" : "slt",
3359 "d,v,t", AT
, reg
, AT
);
3363 /* Warn if an expression is not a constant. */
3366 check_absolute_expr (ip
, ex
)
3367 struct mips_cl_insn
*ip
;
3370 if (ex
->X_op
== O_big
)
3371 as_bad (_("unsupported large constant"));
3372 else if (ex
->X_op
!= O_constant
)
3373 as_bad (_("Instruction %s requires absolute expression"), ip
->insn_mo
->name
);
3376 /* Count the leading zeroes by performing a binary chop. This is a
3377 bulky bit of source, but performance is a LOT better for the
3378 majority of values than a simple loop to count the bits:
3379 for (lcnt = 0; (lcnt < 32); lcnt++)
3380 if ((v) & (1 << (31 - lcnt)))
3382 However it is not code size friendly, and the gain will drop a bit
3383 on certain cached systems.
3385 #define COUNT_TOP_ZEROES(v) \
3386 (((v) & ~0xffff) == 0 \
3387 ? ((v) & ~0xff) == 0 \
3388 ? ((v) & ~0xf) == 0 \
3389 ? ((v) & ~0x3) == 0 \
3390 ? ((v) & ~0x1) == 0 \
3395 : ((v) & ~0x7) == 0 \
3398 : ((v) & ~0x3f) == 0 \
3399 ? ((v) & ~0x1f) == 0 \
3402 : ((v) & ~0x7f) == 0 \
3405 : ((v) & ~0xfff) == 0 \
3406 ? ((v) & ~0x3ff) == 0 \
3407 ? ((v) & ~0x1ff) == 0 \
3410 : ((v) & ~0x7ff) == 0 \
3413 : ((v) & ~0x3fff) == 0 \
3414 ? ((v) & ~0x1fff) == 0 \
3417 : ((v) & ~0x7fff) == 0 \
3420 : ((v) & ~0xffffff) == 0 \
3421 ? ((v) & ~0xfffff) == 0 \
3422 ? ((v) & ~0x3ffff) == 0 \
3423 ? ((v) & ~0x1ffff) == 0 \
3426 : ((v) & ~0x7ffff) == 0 \
3429 : ((v) & ~0x3fffff) == 0 \
3430 ? ((v) & ~0x1fffff) == 0 \
3433 : ((v) & ~0x7fffff) == 0 \
3436 : ((v) & ~0xfffffff) == 0 \
3437 ? ((v) & ~0x3ffffff) == 0 \
3438 ? ((v) & ~0x1ffffff) == 0 \
3441 : ((v) & ~0x7ffffff) == 0 \
3444 : ((v) & ~0x3fffffff) == 0 \
3445 ? ((v) & ~0x1fffffff) == 0 \
3448 : ((v) & ~0x7fffffff) == 0 \
3453 * This routine generates the least number of instructions neccessary to load
3454 * an absolute expression value into a register.
3457 load_register (counter
, reg
, ep
, dbl
)
3464 expressionS hi32
, lo32
;
3466 if (ep
->X_op
!= O_big
)
3468 assert (ep
->X_op
== O_constant
);
3469 if (ep
->X_add_number
< 0x8000
3470 && (ep
->X_add_number
>= 0
3471 || (ep
->X_add_number
>= -0x8000
3474 || sizeof (ep
->X_add_number
) > 4))))
3476 /* We can handle 16 bit signed values with an addiu to
3477 $zero. No need to ever use daddiu here, since $zero and
3478 the result are always correct in 32 bit mode. */
3479 macro_build ((char *) NULL
, counter
, ep
, "addiu", "t,r,j", reg
, 0,
3480 (int) BFD_RELOC_LO16
);
3483 else if (ep
->X_add_number
>= 0 && ep
->X_add_number
< 0x10000)
3485 /* We can handle 16 bit unsigned values with an ori to
3487 macro_build ((char *) NULL
, counter
, ep
, "ori", "t,r,i", reg
, 0,
3488 (int) BFD_RELOC_LO16
);
3491 else if ((IS_SEXT_32BIT_NUM (ep
->X_add_number
)
3494 || sizeof (ep
->X_add_number
) > 4
3495 || (ep
->X_add_number
& 0x80000000) == 0))
3496 || ((HAVE_32BIT_GPRS
|| ! dbl
)
3497 && (ep
->X_add_number
&~ (offsetT
) 0xffffffff) == 0)
3500 && ((ep
->X_add_number
&~ (offsetT
) 0xffffffff)
3501 == ~ (offsetT
) 0xffffffff)))
3503 /* 32 bit values require an lui. */
3504 macro_build ((char *) NULL
, counter
, ep
, "lui", "t,u", reg
,
3505 (int) BFD_RELOC_HI16
);
3506 if ((ep
->X_add_number
& 0xffff) != 0)
3507 macro_build ((char *) NULL
, counter
, ep
, "ori", "t,r,i", reg
, reg
,
3508 (int) BFD_RELOC_LO16
);
3513 /* The value is larger than 32 bits. */
3515 if (HAVE_32BIT_GPRS
)
3517 as_bad (_("Number (0x%lx) larger than 32 bits"),
3518 (unsigned long) ep
->X_add_number
);
3519 macro_build ((char *) NULL
, counter
, ep
, "addiu", "t,r,j", reg
, 0,
3520 (int) BFD_RELOC_LO16
);
3524 if (ep
->X_op
!= O_big
)
3527 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
3528 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
3529 hi32
.X_add_number
&= 0xffffffff;
3531 lo32
.X_add_number
&= 0xffffffff;
3535 assert (ep
->X_add_number
> 2);
3536 if (ep
->X_add_number
== 3)
3537 generic_bignum
[3] = 0;
3538 else if (ep
->X_add_number
> 4)
3539 as_bad (_("Number larger than 64 bits"));
3540 lo32
.X_op
= O_constant
;
3541 lo32
.X_add_number
= generic_bignum
[0] + (generic_bignum
[1] << 16);
3542 hi32
.X_op
= O_constant
;
3543 hi32
.X_add_number
= generic_bignum
[2] + (generic_bignum
[3] << 16);
3546 if (hi32
.X_add_number
== 0)
3551 unsigned long hi
, lo
;
3553 if (hi32
.X_add_number
== (offsetT
) 0xffffffff)
3555 if ((lo32
.X_add_number
& 0xffff8000) == 0xffff8000)
3557 macro_build ((char *) NULL
, counter
, &lo32
, "addiu", "t,r,j",
3558 reg
, 0, (int) BFD_RELOC_LO16
);
3561 if (lo32
.X_add_number
& 0x80000000)
3563 macro_build ((char *) NULL
, counter
, &lo32
, "lui", "t,u", reg
,
3564 (int) BFD_RELOC_HI16
);
3565 if (lo32
.X_add_number
& 0xffff)
3566 macro_build ((char *) NULL
, counter
, &lo32
, "ori", "t,r,i",
3567 reg
, reg
, (int) BFD_RELOC_LO16
);
3572 /* Check for 16bit shifted constant. We know that hi32 is
3573 non-zero, so start the mask on the first bit of the hi32
3578 unsigned long himask
, lomask
;
3582 himask
= 0xffff >> (32 - shift
);
3583 lomask
= (0xffff << shift
) & 0xffffffff;
3587 himask
= 0xffff << (shift
- 32);
3590 if ((hi32
.X_add_number
& ~(offsetT
) himask
) == 0
3591 && (lo32
.X_add_number
& ~(offsetT
) lomask
) == 0)
3595 tmp
.X_op
= O_constant
;
3597 tmp
.X_add_number
= ((hi32
.X_add_number
<< (32 - shift
))
3598 | (lo32
.X_add_number
>> shift
));
3600 tmp
.X_add_number
= hi32
.X_add_number
>> (shift
- 32);
3601 macro_build ((char *) NULL
, counter
, &tmp
,
3602 "ori", "t,r,i", reg
, 0,
3603 (int) BFD_RELOC_LO16
);
3604 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3605 (shift
>= 32) ? "dsll32" : "dsll",
3607 (shift
>= 32) ? shift
- 32 : shift
);
3612 while (shift
<= (64 - 16));
3614 /* Find the bit number of the lowest one bit, and store the
3615 shifted value in hi/lo. */
3616 hi
= (unsigned long) (hi32
.X_add_number
& 0xffffffff);
3617 lo
= (unsigned long) (lo32
.X_add_number
& 0xffffffff);
3621 while ((lo
& 1) == 0)
3626 lo
|= (hi
& (((unsigned long) 1 << bit
) - 1)) << (32 - bit
);
3632 while ((hi
& 1) == 0)
3641 /* Optimize if the shifted value is a (power of 2) - 1. */
3642 if ((hi
== 0 && ((lo
+ 1) & lo
) == 0)
3643 || (lo
== 0xffffffff && ((hi
+ 1) & hi
) == 0))
3645 shift
= COUNT_TOP_ZEROES ((unsigned int) hi32
.X_add_number
);
3650 /* This instruction will set the register to be all
3652 tmp
.X_op
= O_constant
;
3653 tmp
.X_add_number
= (offsetT
) -1;
3654 macro_build ((char *) NULL
, counter
, &tmp
, "addiu", "t,r,j",
3655 reg
, 0, (int) BFD_RELOC_LO16
);
3659 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3660 (bit
>= 32) ? "dsll32" : "dsll",
3662 (bit
>= 32) ? bit
- 32 : bit
);
3664 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3665 (shift
>= 32) ? "dsrl32" : "dsrl",
3667 (shift
>= 32) ? shift
- 32 : shift
);
3672 /* Sign extend hi32 before calling load_register, because we can
3673 generally get better code when we load a sign extended value. */
3674 if ((hi32
.X_add_number
& 0x80000000) != 0)
3675 hi32
.X_add_number
|= ~(offsetT
) 0xffffffff;
3676 load_register (counter
, reg
, &hi32
, 0);
3679 if ((lo32
.X_add_number
& 0xffff0000) == 0)
3683 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3684 "dsll32", "d,w,<", reg
, freg
, 0);
3692 if ((freg
== 0) && (lo32
.X_add_number
== (offsetT
) 0xffffffff))
3694 macro_build ((char *) NULL
, counter
, &lo32
, "lui", "t,u", reg
,
3695 (int) BFD_RELOC_HI16
);
3696 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3697 "dsrl32", "d,w,<", reg
, reg
, 0);
3703 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
, "dsll",
3704 "d,w,<", reg
, freg
, 16);
3708 mid16
.X_add_number
>>= 16;
3709 macro_build ((char *) NULL
, counter
, &mid16
, "ori", "t,r,i", reg
,
3710 freg
, (int) BFD_RELOC_LO16
);
3711 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
, "dsll",
3712 "d,w,<", reg
, reg
, 16);
3715 if ((lo32
.X_add_number
& 0xffff) != 0)
3716 macro_build ((char *) NULL
, counter
, &lo32
, "ori", "t,r,i", reg
, freg
,
3717 (int) BFD_RELOC_LO16
);
3720 /* Load an address into a register. */
3723 load_address (counter
, reg
, ep
, used_at
)
3731 if (ep
->X_op
!= O_constant
3732 && ep
->X_op
!= O_symbol
)
3734 as_bad (_("expression too complex"));
3735 ep
->X_op
= O_constant
;
3738 if (ep
->X_op
== O_constant
)
3740 load_register (counter
, reg
, ep
, HAVE_64BIT_ADDRESSES
);
3744 if (mips_pic
== NO_PIC
)
3746 /* If this is a reference to a GP relative symbol, we want
3747 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3749 lui $reg,<sym> (BFD_RELOC_HI16_S)
3750 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3751 If we have an addend, we always use the latter form.
3753 With 64bit address space and a usable $at we want
3754 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3755 lui $at,<sym> (BFD_RELOC_HI16_S)
3756 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3757 daddiu $at,<sym> (BFD_RELOC_LO16)
3761 If $at is already in use, we use an path which is suboptimal
3762 on superscalar processors.
3763 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3764 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3766 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3768 daddiu $reg,<sym> (BFD_RELOC_LO16)
3770 if (HAVE_64BIT_ADDRESSES
)
3772 /* We don't do GP optimization for now because RELAX_ENCODE can't
3773 hold the data for such large chunks. */
3775 if (*used_at
== 0 && ! mips_opts
.noat
)
3777 macro_build (p
, counter
, ep
, "lui", "t,u",
3778 reg
, (int) BFD_RELOC_MIPS_HIGHEST
);
3779 macro_build (p
, counter
, ep
, "lui", "t,u",
3780 AT
, (int) BFD_RELOC_HI16_S
);
3781 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3782 reg
, reg
, (int) BFD_RELOC_MIPS_HIGHER
);
3783 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3784 AT
, AT
, (int) BFD_RELOC_LO16
);
3785 macro_build (p
, counter
, (expressionS
*) NULL
, "dsll32",
3786 "d,w,<", reg
, reg
, 0);
3787 macro_build (p
, counter
, (expressionS
*) NULL
, "daddu",
3788 "d,v,t", reg
, reg
, AT
);
3793 macro_build (p
, counter
, ep
, "lui", "t,u",
3794 reg
, (int) BFD_RELOC_MIPS_HIGHEST
);
3795 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3796 reg
, reg
, (int) BFD_RELOC_MIPS_HIGHER
);
3797 macro_build (p
, counter
, (expressionS
*) NULL
, "dsll",
3798 "d,w,<", reg
, reg
, 16);
3799 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3800 reg
, reg
, (int) BFD_RELOC_HI16_S
);
3801 macro_build (p
, counter
, (expressionS
*) NULL
, "dsll",
3802 "d,w,<", reg
, reg
, 16);
3803 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3804 reg
, reg
, (int) BFD_RELOC_LO16
);
3809 if ((valueT
) ep
->X_add_number
<= MAX_GPREL_OFFSET
3810 && ! nopic_need_relax (ep
->X_add_symbol
, 1))
3813 macro_build ((char *) NULL
, counter
, ep
,
3814 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu", "t,r,j",
3815 reg
, mips_gp_register
, (int) BFD_RELOC_GPREL16
);
3816 p
= frag_var (rs_machine_dependent
, 8, 0,
3817 RELAX_ENCODE (4, 8, 0, 4, 0,
3818 mips_opts
.warn_about_macros
),
3819 ep
->X_add_symbol
, 0, NULL
);
3821 macro_build_lui (p
, counter
, ep
, reg
);
3824 macro_build (p
, counter
, ep
,
3825 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3826 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3829 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
3833 /* If this is a reference to an external symbol, we want
3834 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3836 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3838 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3839 If we have NewABI, we want
3840 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
3841 If there is a constant, it must be added in after. */
3842 ex
.X_add_number
= ep
->X_add_number
;
3843 ep
->X_add_number
= 0;
3847 macro_build ((char *) NULL
, counter
, ep
,
3848 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", reg
,
3849 (int) BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
3853 macro_build ((char *) NULL
, counter
, ep
,
3854 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)",
3855 reg
, (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
3856 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
, "nop", "");
3857 p
= frag_var (rs_machine_dependent
, 4, 0,
3858 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts
.warn_about_macros
),
3859 ep
->X_add_symbol
, (offsetT
) 0, (char *) NULL
);
3860 macro_build (p
, counter
, ep
,
3861 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3862 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3865 if (ex
.X_add_number
!= 0)
3867 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
3868 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3869 ex
.X_op
= O_constant
;
3870 macro_build ((char *) NULL
, counter
, &ex
,
3871 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3872 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3875 else if (mips_pic
== SVR4_PIC
)
3880 /* This is the large GOT case. If this is a reference to an
3881 external symbol, we want
3882 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3884 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3885 Otherwise, for a reference to a local symbol, we want
3886 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3888 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3889 If we have NewABI, we want
3890 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3891 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3892 If there is a constant, it must be added in after. */
3893 ex
.X_add_number
= ep
->X_add_number
;
3894 ep
->X_add_number
= 0;
3897 macro_build ((char *) NULL
, counter
, ep
,
3898 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", reg
,
3899 (int) BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
3900 macro_build (p
, counter
, ep
,
3901 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu", "t,r,j",
3902 reg
, reg
, (int) BFD_RELOC_MIPS_GOT_OFST
);
3906 if (reg_needs_delay (mips_gp_register
))
3911 macro_build ((char *) NULL
, counter
, ep
, "lui", "t,u", reg
,
3912 (int) BFD_RELOC_MIPS_GOT_HI16
);
3913 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3914 HAVE_32BIT_ADDRESSES
? "addu" : "daddu", "d,v,t", reg
,
3915 reg
, mips_gp_register
);
3916 macro_build ((char *) NULL
, counter
, ep
,
3917 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
3918 "t,o(b)", reg
, (int) BFD_RELOC_MIPS_GOT_LO16
, reg
);
3919 p
= frag_var (rs_machine_dependent
, 12 + off
, 0,
3920 RELAX_ENCODE (12, 12 + off
, off
, 8 + off
, 0,
3921 mips_opts
.warn_about_macros
),
3922 ep
->X_add_symbol
, 0, NULL
);
3925 /* We need a nop before loading from $gp. This special
3926 check is required because the lui which starts the main
3927 instruction stream does not refer to $gp, and so will not
3928 insert the nop which may be required. */
3929 macro_build (p
, counter
, (expressionS
*) NULL
, "nop", "");
3932 macro_build (p
, counter
, ep
,
3933 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", reg
,
3934 (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
3936 macro_build (p
, counter
, (expressionS
*) NULL
, "nop", "");
3938 macro_build (p
, counter
, ep
,
3939 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3940 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3943 if (ex
.X_add_number
!= 0)
3945 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
3946 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3947 ex
.X_op
= O_constant
;
3948 macro_build ((char *) NULL
, counter
, &ex
,
3949 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3950 "t,r,j", reg
, reg
, (int) BFD_RELOC_LO16
);
3953 else if (mips_pic
== EMBEDDED_PIC
)
3956 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3958 macro_build ((char *) NULL
, counter
, ep
,
3959 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
3960 "t,r,j", reg
, mips_gp_register
, (int) BFD_RELOC_GPREL16
);
3966 /* Move the contents of register SOURCE into register DEST. */
3969 move_register (counter
, dest
, source
)
3974 macro_build ((char *) NULL
, counter
, (expressionS
*) NULL
,
3975 HAVE_32BIT_GPRS
? "addu" : "daddu",
3976 "d,v,t", dest
, source
, 0);
3981 * This routine implements the seemingly endless macro or synthesized
3982 * instructions and addressing modes in the mips assembly language. Many
3983 * of these macros are simple and are similar to each other. These could
3984 * probably be handled by some kind of table or grammer aproach instead of
3985 * this verbose method. Others are not simple macros but are more like
3986 * optimizing code generation.
3987 * One interesting optimization is when several store macros appear
3988 * consecutivly that would load AT with the upper half of the same address.
3989 * The ensuing load upper instructions are ommited. This implies some kind
3990 * of global optimization. We currently only optimize within a single macro.
3991 * For many of the load and store macros if the address is specified as a
3992 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3993 * first load register 'at' with zero and use it as the base register. The
3994 * mips assembler simply uses register $zero. Just one tiny optimization
3999 struct mips_cl_insn
*ip
;
4001 register int treg
, sreg
, dreg
, breg
;
4017 bfd_reloc_code_real_type r
;
4018 int hold_mips_optimize
;
4020 assert (! mips_opts
.mips16
);
4022 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
4023 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
4024 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
4025 mask
= ip
->insn_mo
->mask
;
4027 expr1
.X_op
= O_constant
;
4028 expr1
.X_op_symbol
= NULL
;
4029 expr1
.X_add_symbol
= NULL
;
4030 expr1
.X_add_number
= 1;
4042 mips_emit_delays (true);
4043 ++mips_opts
.noreorder
;
4044 mips_any_noreorder
= 1;
4046 expr1
.X_add_number
= 8;
4047 macro_build ((char *) NULL
, &icnt
, &expr1
, "bgez", "s,p", sreg
);
4049 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "",
4052 move_register (&icnt
, dreg
, sreg
);
4053 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4054 dbl
? "dsub" : "sub", "d,v,t", dreg
, 0, sreg
);
4056 --mips_opts
.noreorder
;
4077 if (imm_expr
.X_op
== O_constant
4078 && imm_expr
.X_add_number
>= -0x8000
4079 && imm_expr
.X_add_number
< 0x8000)
4081 macro_build ((char *) NULL
, &icnt
, &imm_expr
, s
, "t,r,j", treg
, sreg
,
4082 (int) BFD_RELOC_LO16
);
4085 load_register (&icnt
, AT
, &imm_expr
, dbl
);
4086 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "d,v,t",
4106 if (imm_expr
.X_op
== O_constant
4107 && imm_expr
.X_add_number
>= 0
4108 && imm_expr
.X_add_number
< 0x10000)
4110 if (mask
!= M_NOR_I
)
4111 macro_build ((char *) NULL
, &icnt
, &imm_expr
, s
, "t,r,i", treg
,
4112 sreg
, (int) BFD_RELOC_LO16
);
4115 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "ori", "t,r,i",
4116 treg
, sreg
, (int) BFD_RELOC_LO16
);
4117 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nor",
4118 "d,v,t", treg
, treg
, 0);
4123 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4124 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "d,v,t",
4142 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4144 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "s,t,p", sreg
,
4148 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4149 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "s,t,p", sreg
, AT
);
4157 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4158 likely
? "bgezl" : "bgez", "s,p", sreg
);
4163 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4164 likely
? "blezl" : "blez", "s,p", treg
);
4167 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
4169 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4170 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4176 /* check for > max integer */
4177 maxnum
= 0x7fffffff;
4178 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4185 if (imm_expr
.X_op
== O_constant
4186 && imm_expr
.X_add_number
>= maxnum
4187 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4190 /* result is always false */
4194 as_warn (_("Branch %s is always false (nop)"),
4196 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop",
4202 as_warn (_("Branch likely %s is always false"),
4204 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "bnel",
4209 if (imm_expr
.X_op
!= O_constant
)
4210 as_bad (_("Unsupported large constant"));
4211 ++imm_expr
.X_add_number
;
4215 if (mask
== M_BGEL_I
)
4217 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4219 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4220 likely
? "bgezl" : "bgez", "s,p", sreg
);
4223 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4225 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4226 likely
? "bgtzl" : "bgtz", "s,p", sreg
);
4229 maxnum
= 0x7fffffff;
4230 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4237 maxnum
= - maxnum
- 1;
4238 if (imm_expr
.X_op
== O_constant
4239 && imm_expr
.X_add_number
<= maxnum
4240 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4243 /* result is always true */
4244 as_warn (_("Branch %s is always true"), ip
->insn_mo
->name
);
4245 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "b", "p");
4248 set_at (&icnt
, sreg
, 0);
4249 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4250 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4260 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4261 likely
? "beql" : "beq", "s,t,p", 0, treg
);
4264 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
4265 "d,v,t", AT
, sreg
, treg
);
4266 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4267 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4275 && imm_expr
.X_op
== O_constant
4276 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
4278 if (imm_expr
.X_op
!= O_constant
)
4279 as_bad (_("Unsupported large constant"));
4280 ++imm_expr
.X_add_number
;
4284 if (mask
== M_BGEUL_I
)
4286 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4288 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4290 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4291 likely
? "bnel" : "bne", "s,t,p", sreg
, 0);
4294 set_at (&icnt
, sreg
, 1);
4295 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4296 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4304 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4305 likely
? "bgtzl" : "bgtz", "s,p", sreg
);
4310 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4311 likely
? "bltzl" : "bltz", "s,p", treg
);
4314 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
4316 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4317 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4325 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4326 likely
? "bnel" : "bne", "s,t,p", sreg
, 0);
4331 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
4332 "d,v,t", AT
, treg
, sreg
);
4333 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4334 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4342 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4343 likely
? "blezl" : "blez", "s,p", sreg
);
4348 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4349 likely
? "bgezl" : "bgez", "s,p", treg
);
4352 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
4354 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4355 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4361 maxnum
= 0x7fffffff;
4362 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4369 if (imm_expr
.X_op
== O_constant
4370 && imm_expr
.X_add_number
>= maxnum
4371 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4373 if (imm_expr
.X_op
!= O_constant
)
4374 as_bad (_("Unsupported large constant"));
4375 ++imm_expr
.X_add_number
;
4379 if (mask
== M_BLTL_I
)
4381 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4383 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4384 likely
? "bltzl" : "bltz", "s,p", sreg
);
4387 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4389 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4390 likely
? "blezl" : "blez", "s,p", sreg
);
4393 set_at (&icnt
, sreg
, 0);
4394 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4395 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4403 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4404 likely
? "beql" : "beq", "s,t,p", sreg
, 0);
4409 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
4410 "d,v,t", AT
, treg
, sreg
);
4411 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4412 likely
? "beql" : "beq", "s,t,p", AT
, 0);
4420 && imm_expr
.X_op
== O_constant
4421 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
4423 if (imm_expr
.X_op
!= O_constant
)
4424 as_bad (_("Unsupported large constant"));
4425 ++imm_expr
.X_add_number
;
4429 if (mask
== M_BLTUL_I
)
4431 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4433 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4435 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4436 likely
? "beql" : "beq",
4440 set_at (&icnt
, sreg
, 1);
4441 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4442 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4450 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4451 likely
? "bltzl" : "bltz", "s,p", sreg
);
4456 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4457 likely
? "bgtzl" : "bgtz", "s,p", treg
);
4460 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
4462 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4463 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4473 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4474 likely
? "bnel" : "bne", "s,t,p", 0, treg
);
4477 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
4480 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4481 likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4496 as_warn (_("Divide by zero."));
4498 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4501 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4506 mips_emit_delays (true);
4507 ++mips_opts
.noreorder
;
4508 mips_any_noreorder
= 1;
4511 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4512 "s,t,q", treg
, 0, 7);
4513 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4514 dbl
? "ddiv" : "div", "z,s,t", sreg
, treg
);
4518 expr1
.X_add_number
= 8;
4519 macro_build ((char *) NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, 0);
4520 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4521 dbl
? "ddiv" : "div", "z,s,t", sreg
, treg
);
4522 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4525 expr1
.X_add_number
= -1;
4526 macro_build ((char *) NULL
, &icnt
, &expr1
,
4527 dbl
? "daddiu" : "addiu",
4528 "t,r,j", AT
, 0, (int) BFD_RELOC_LO16
);
4529 expr1
.X_add_number
= mips_trap
? (dbl
? 12 : 8) : (dbl
? 20 : 16);
4530 macro_build ((char *) NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, AT
);
4533 expr1
.X_add_number
= 1;
4534 macro_build ((char *) NULL
, &icnt
, &expr1
, "daddiu", "t,r,j", AT
, 0,
4535 (int) BFD_RELOC_LO16
);
4536 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsll32",
4537 "d,w,<", AT
, AT
, 31);
4541 expr1
.X_add_number
= 0x80000000;
4542 macro_build ((char *) NULL
, &icnt
, &expr1
, "lui", "t,u", AT
,
4543 (int) BFD_RELOC_HI16
);
4547 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4548 "s,t,q", sreg
, AT
, 6);
4549 /* We want to close the noreorder block as soon as possible, so
4550 that later insns are available for delay slot filling. */
4551 --mips_opts
.noreorder
;
4555 expr1
.X_add_number
= 8;
4556 macro_build ((char *) NULL
, &icnt
, &expr1
, "bne", "s,t,p", sreg
, AT
);
4557 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "",
4560 /* We want to close the noreorder block as soon as possible, so
4561 that later insns are available for delay slot filling. */
4562 --mips_opts
.noreorder
;
4564 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4567 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d", dreg
);
4606 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4608 as_warn (_("Divide by zero."));
4610 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4613 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4617 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4619 if (strcmp (s2
, "mflo") == 0)
4620 move_register (&icnt
, dreg
, sreg
);
4622 move_register (&icnt
, dreg
, 0);
4625 if (imm_expr
.X_op
== O_constant
4626 && imm_expr
.X_add_number
== -1
4627 && s
[strlen (s
) - 1] != 'u')
4629 if (strcmp (s2
, "mflo") == 0)
4631 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4632 dbl
? "dneg" : "neg", "d,w", dreg
, sreg
);
4635 move_register (&icnt
, dreg
, 0);
4639 load_register (&icnt
, AT
, &imm_expr
, dbl
);
4640 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "z,s,t",
4642 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "d", dreg
);
4661 mips_emit_delays (true);
4662 ++mips_opts
.noreorder
;
4663 mips_any_noreorder
= 1;
4666 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "teq",
4667 "s,t,q", treg
, 0, 7);
4668 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "z,s,t",
4670 /* We want to close the noreorder block as soon as possible, so
4671 that later insns are available for delay slot filling. */
4672 --mips_opts
.noreorder
;
4676 expr1
.X_add_number
= 8;
4677 macro_build ((char *) NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, 0);
4678 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "z,s,t",
4681 /* We want to close the noreorder block as soon as possible, so
4682 that later insns are available for delay slot filling. */
4683 --mips_opts
.noreorder
;
4684 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
4687 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "d", dreg
);
4693 /* Load the address of a symbol into a register. If breg is not
4694 zero, we then add a base register to it. */
4696 if (dbl
&& HAVE_32BIT_GPRS
)
4697 as_warn (_("dla used to load 32-bit register"));
4699 if (! dbl
&& HAVE_64BIT_OBJECTS
)
4700 as_warn (_("la used to load 64-bit address"));
4702 if (offset_expr
.X_op
== O_constant
4703 && offset_expr
.X_add_number
>= -0x8000
4704 && offset_expr
.X_add_number
< 0x8000)
4706 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4707 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddiu" : "addiu",
4708 "t,r,j", treg
, sreg
, (int) BFD_RELOC_LO16
);
4723 /* When generating embedded PIC code, we permit expressions of
4726 la $treg,foo-bar($breg)
4727 where bar is an address in the current section. These are used
4728 when getting the addresses of functions. We don't permit
4729 X_add_number to be non-zero, because if the symbol is
4730 external the relaxing code needs to know that any addend is
4731 purely the offset to X_op_symbol. */
4732 if (mips_pic
== EMBEDDED_PIC
4733 && offset_expr
.X_op
== O_subtract
4734 && (symbol_constant_p (offset_expr
.X_op_symbol
)
4735 ? S_GET_SEGMENT (offset_expr
.X_op_symbol
) == now_seg
4736 : (symbol_equated_p (offset_expr
.X_op_symbol
)
4738 (symbol_get_value_expression (offset_expr
.X_op_symbol
)
4741 && (offset_expr
.X_add_number
== 0
4742 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
))
4748 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
4749 tempreg
, (int) BFD_RELOC_PCREL_HI16_S
);
4753 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
4754 tempreg
, (int) BFD_RELOC_PCREL_HI16_S
);
4755 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4756 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddu" : "addu",
4757 "d,v,t", tempreg
, tempreg
, breg
);
4759 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4760 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddiu" : "addiu",
4761 "t,r,j", treg
, tempreg
, (int) BFD_RELOC_PCREL_LO16
);
4767 if (offset_expr
.X_op
!= O_symbol
4768 && offset_expr
.X_op
!= O_constant
)
4770 as_bad (_("expression too complex"));
4771 offset_expr
.X_op
= O_constant
;
4774 if (offset_expr
.X_op
== O_constant
)
4775 load_register (&icnt
, tempreg
, &offset_expr
,
4776 ((mips_pic
== EMBEDDED_PIC
|| mips_pic
== NO_PIC
)
4777 ? (dbl
|| HAVE_64BIT_ADDRESSES
)
4778 : HAVE_64BIT_ADDRESSES
));
4779 else if (mips_pic
== NO_PIC
)
4781 /* If this is a reference to a GP relative symbol, we want
4782 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4784 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4785 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4786 If we have a constant, we need two instructions anyhow,
4787 so we may as well always use the latter form.
4789 With 64bit address space and a usable $at we want
4790 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4791 lui $at,<sym> (BFD_RELOC_HI16_S)
4792 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4793 daddiu $at,<sym> (BFD_RELOC_LO16)
4795 daddu $tempreg,$tempreg,$at
4797 If $at is already in use, we use an path which is suboptimal
4798 on superscalar processors.
4799 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4800 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4802 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4804 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4807 if (HAVE_64BIT_ADDRESSES
)
4809 /* We don't do GP optimization for now because RELAX_ENCODE can't
4810 hold the data for such large chunks. */
4812 if (used_at
== 0 && ! mips_opts
.noat
)
4814 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4815 tempreg
, (int) BFD_RELOC_MIPS_HIGHEST
);
4816 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4817 AT
, (int) BFD_RELOC_HI16_S
);
4818 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4819 tempreg
, tempreg
, (int) BFD_RELOC_MIPS_HIGHER
);
4820 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4821 AT
, AT
, (int) BFD_RELOC_LO16
);
4822 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll32",
4823 "d,w,<", tempreg
, tempreg
, 0);
4824 macro_build (p
, &icnt
, (expressionS
*) NULL
, "daddu",
4825 "d,v,t", tempreg
, tempreg
, AT
);
4830 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4831 tempreg
, (int) BFD_RELOC_MIPS_HIGHEST
);
4832 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4833 tempreg
, tempreg
, (int) BFD_RELOC_MIPS_HIGHER
);
4834 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll", "d,w,<",
4835 tempreg
, tempreg
, 16);
4836 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4837 tempreg
, tempreg
, (int) BFD_RELOC_HI16_S
);
4838 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll", "d,w,<",
4839 tempreg
, tempreg
, 16);
4840 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4841 tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4846 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
4847 && ! nopic_need_relax (offset_expr
.X_add_symbol
, 1))
4850 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "addiu",
4851 "t,r,j", tempreg
, mips_gp_register
,
4852 (int) BFD_RELOC_GPREL16
);
4853 p
= frag_var (rs_machine_dependent
, 8, 0,
4854 RELAX_ENCODE (4, 8, 0, 4, 0,
4855 mips_opts
.warn_about_macros
),
4856 offset_expr
.X_add_symbol
, 0, NULL
);
4858 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
4861 macro_build (p
, &icnt
, &offset_expr
, "addiu",
4862 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4865 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
4867 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
4869 /* If this is a reference to an external symbol, and there
4870 is no constant, we want
4871 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4872 or if tempreg is PIC_CALL_REG
4873 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4874 For a local symbol, we want
4875 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4877 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4879 If we have a small constant, and this is a reference to
4880 an external symbol, we want
4881 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4883 addiu $tempreg,$tempreg,<constant>
4884 For a local symbol, we want the same instruction
4885 sequence, but we output a BFD_RELOC_LO16 reloc on the
4888 If we have a large constant, and this is a reference to
4889 an external symbol, we want
4890 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4891 lui $at,<hiconstant>
4892 addiu $at,$at,<loconstant>
4893 addu $tempreg,$tempreg,$at
4894 For a local symbol, we want the same instruction
4895 sequence, but we output a BFD_RELOC_LO16 reloc on the
4898 For NewABI, we want for local or external data addresses
4899 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4900 For a local function symbol, we want
4901 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
4903 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
4906 expr1
.X_add_number
= offset_expr
.X_add_number
;
4907 offset_expr
.X_add_number
= 0;
4909 if (expr1
.X_add_number
== 0 && tempreg
== PIC_CALL_REG
)
4910 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL16
;
4911 else if (HAVE_NEWABI
)
4912 lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_DISP
;
4913 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
4914 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
4915 "t,o(b)", tempreg
, lw_reloc_type
, mips_gp_register
);
4916 if (expr1
.X_add_number
== 0)
4925 /* We're going to put in an addu instruction using
4926 tempreg, so we may as well insert the nop right
4928 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4932 p
= frag_var (rs_machine_dependent
, 8 - off
, 0,
4933 RELAX_ENCODE (0, 8 - off
, -4 - off
, 4 - off
, 0,
4935 ? mips_opts
.warn_about_macros
4937 offset_expr
.X_add_symbol
, 0, NULL
);
4940 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
4943 macro_build (p
, &icnt
, &expr1
,
4944 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4945 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4946 /* FIXME: If breg == 0, and the next instruction uses
4947 $tempreg, then if this variant case is used an extra
4948 nop will be generated. */
4950 else if (expr1
.X_add_number
>= -0x8000
4951 && expr1
.X_add_number
< 0x8000)
4953 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4955 macro_build ((char *) NULL
, &icnt
, &expr1
,
4956 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4957 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
4958 frag_var (rs_machine_dependent
, 0, 0,
4959 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4960 offset_expr
.X_add_symbol
, 0, NULL
);
4966 /* If we are going to add in a base register, and the
4967 target register and the base register are the same,
4968 then we are using AT as a temporary register. Since
4969 we want to load the constant into AT, we add our
4970 current AT (from the global offset table) and the
4971 register into the register now, and pretend we were
4972 not using a base register. */
4977 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4979 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4980 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4981 "d,v,t", treg
, AT
, breg
);
4987 /* Set mips_optimize around the lui instruction to avoid
4988 inserting an unnecessary nop after the lw. */
4989 hold_mips_optimize
= mips_optimize
;
4991 macro_build_lui (NULL
, &icnt
, &expr1
, AT
);
4992 mips_optimize
= hold_mips_optimize
;
4994 macro_build ((char *) NULL
, &icnt
, &expr1
,
4995 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
4996 "t,r,j", AT
, AT
, (int) BFD_RELOC_LO16
);
4997 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
4998 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
4999 "d,v,t", tempreg
, tempreg
, AT
);
5000 frag_var (rs_machine_dependent
, 0, 0,
5001 RELAX_ENCODE (0, 0, -16 + off1
, -8, 0, 0),
5002 offset_expr
.X_add_symbol
, 0, NULL
);
5006 else if (mips_pic
== SVR4_PIC
)
5010 int lui_reloc_type
= (int) BFD_RELOC_MIPS_GOT_HI16
;
5011 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_LO16
;
5012 int local_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
5014 /* This is the large GOT case. If this is a reference to an
5015 external symbol, and there is no constant, we want
5016 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5017 addu $tempreg,$tempreg,$gp
5018 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5019 or if tempreg is PIC_CALL_REG
5020 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5021 addu $tempreg,$tempreg,$gp
5022 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5023 For a local symbol, we want
5024 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5026 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5028 If we have a small constant, and this is a reference to
5029 an external symbol, we want
5030 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5031 addu $tempreg,$tempreg,$gp
5032 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5034 addiu $tempreg,$tempreg,<constant>
5035 For a local symbol, we want
5036 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5038 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5040 If we have a large constant, and this is a reference to
5041 an external symbol, we want
5042 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5043 addu $tempreg,$tempreg,$gp
5044 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5045 lui $at,<hiconstant>
5046 addiu $at,$at,<loconstant>
5047 addu $tempreg,$tempreg,$at
5048 For a local symbol, we want
5049 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5050 lui $at,<hiconstant>
5051 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5052 addu $tempreg,$tempreg,$at
5054 For NewABI, we want for local data addresses
5055 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5058 expr1
.X_add_number
= offset_expr
.X_add_number
;
5059 offset_expr
.X_add_number
= 0;
5061 if (reg_needs_delay (mips_gp_register
))
5065 if (expr1
.X_add_number
== 0 && tempreg
== PIC_CALL_REG
)
5067 lui_reloc_type
= (int) BFD_RELOC_MIPS_CALL_HI16
;
5068 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL_LO16
;
5070 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5071 tempreg
, lui_reloc_type
);
5072 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5073 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5074 "d,v,t", tempreg
, tempreg
, mips_gp_register
);
5075 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5076 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5077 "t,o(b)", tempreg
, lw_reloc_type
, tempreg
);
5078 if (expr1
.X_add_number
== 0)
5086 /* We're going to put in an addu instruction using
5087 tempreg, so we may as well insert the nop right
5089 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5094 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5095 RELAX_ENCODE (12 + off
, 12 + gpdel
, gpdel
,
5098 ? mips_opts
.warn_about_macros
5100 offset_expr
.X_add_symbol
, 0, NULL
);
5102 else if (expr1
.X_add_number
>= -0x8000
5103 && expr1
.X_add_number
< 0x8000)
5105 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5107 macro_build ((char *) NULL
, &icnt
, &expr1
,
5108 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5109 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
5111 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5112 RELAX_ENCODE (20, 12 + gpdel
, gpdel
, 8 + gpdel
, 0,
5114 ? mips_opts
.warn_about_macros
5116 offset_expr
.X_add_symbol
, 0, NULL
);
5122 /* If we are going to add in a base register, and the
5123 target register and the base register are the same,
5124 then we are using AT as a temporary register. Since
5125 we want to load the constant into AT, we add our
5126 current AT (from the global offset table) and the
5127 register into the register now, and pretend we were
5128 not using a base register. */
5136 assert (tempreg
== AT
);
5137 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5139 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5140 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5141 "d,v,t", treg
, AT
, breg
);
5146 /* Set mips_optimize around the lui instruction to avoid
5147 inserting an unnecessary nop after the lw. */
5148 hold_mips_optimize
= mips_optimize
;
5150 macro_build_lui (NULL
, &icnt
, &expr1
, AT
);
5151 mips_optimize
= hold_mips_optimize
;
5153 macro_build ((char *) NULL
, &icnt
, &expr1
,
5154 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5155 "t,r,j", AT
, AT
, (int) BFD_RELOC_LO16
);
5156 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5157 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5158 "d,v,t", dreg
, dreg
, AT
);
5160 p
= frag_var (rs_machine_dependent
, 16 + gpdel
+ adj
, 0,
5161 RELAX_ENCODE (24 + adj
, 16 + gpdel
+ adj
, gpdel
,
5164 ? mips_opts
.warn_about_macros
5166 offset_expr
.X_add_symbol
, 0, NULL
);
5173 /* This is needed because this instruction uses $gp, but
5174 the first instruction on the main stream does not. */
5175 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5180 local_reloc_type
= (int) BFD_RELOC_MIPS_GOT_DISP
;
5181 macro_build (p
, &icnt
, &offset_expr
,
5182 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5187 if (expr1
.X_add_number
== 0 && HAVE_NEWABI
)
5189 /* BFD_RELOC_MIPS_GOT_DISP is sufficient for newabi */
5192 if (expr1
.X_add_number
>= -0x8000
5193 && expr1
.X_add_number
< 0x8000)
5195 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5197 macro_build (p
, &icnt
, &expr1
,
5198 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5199 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
5200 /* FIXME: If add_number is 0, and there was no base
5201 register, the external symbol case ended with a load,
5202 so if the symbol turns out to not be external, and
5203 the next instruction uses tempreg, an unnecessary nop
5204 will be inserted. */
5210 /* We must add in the base register now, as in the
5211 external symbol case. */
5212 assert (tempreg
== AT
);
5213 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5215 macro_build (p
, &icnt
, (expressionS
*) NULL
,
5216 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5217 "d,v,t", treg
, AT
, breg
);
5220 /* We set breg to 0 because we have arranged to add
5221 it in in both cases. */
5225 macro_build_lui (p
, &icnt
, &expr1
, AT
);
5227 macro_build (p
, &icnt
, &expr1
,
5228 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5229 "t,r,j", AT
, AT
, (int) BFD_RELOC_LO16
);
5231 macro_build (p
, &icnt
, (expressionS
*) NULL
,
5232 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5233 "d,v,t", tempreg
, tempreg
, AT
);
5237 else if (mips_pic
== EMBEDDED_PIC
)
5240 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5242 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5243 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu", "t,r,j",
5244 tempreg
, mips_gp_register
, (int) BFD_RELOC_GPREL16
);
5253 if (mips_pic
== EMBEDDED_PIC
|| mips_pic
== NO_PIC
)
5254 s
= (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddu" : "addu";
5256 s
= HAVE_64BIT_ADDRESSES
? "daddu" : "addu";
5258 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
,
5259 "d,v,t", treg
, tempreg
, breg
);
5268 /* The j instruction may not be used in PIC code, since it
5269 requires an absolute address. We convert it to a b
5271 if (mips_pic
== NO_PIC
)
5272 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "j", "a");
5274 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "b", "p");
5277 /* The jal instructions must be handled as macros because when
5278 generating PIC code they expand to multi-instruction
5279 sequences. Normally they are simple instructions. */
5284 if (mips_pic
== NO_PIC
5285 || mips_pic
== EMBEDDED_PIC
)
5286 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "jalr",
5288 else if (mips_pic
== SVR4_PIC
)
5290 if (sreg
!= PIC_CALL_REG
)
5291 as_warn (_("MIPS PIC call to register other than $25"));
5293 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "jalr",
5297 if (mips_cprestore_offset
< 0)
5298 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5301 if (! mips_frame_reg_valid
)
5303 as_warn (_("No .frame pseudo-op used in PIC code"));
5304 /* Quiet this warning. */
5305 mips_frame_reg_valid
= 1;
5307 if (! mips_cprestore_valid
)
5309 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5310 /* Quiet this warning. */
5311 mips_cprestore_valid
= 1;
5313 expr1
.X_add_number
= mips_cprestore_offset
;
5314 macro_build_ldst_constoffset ((char *) NULL
, &icnt
, &expr1
,
5315 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5316 mips_gp_register
, mips_frame_reg
);
5326 if (mips_pic
== NO_PIC
)
5327 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "jal", "a");
5328 else if (mips_pic
== SVR4_PIC
)
5332 /* If this is a reference to an external symbol, and we are
5333 using a small GOT, we want
5334 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5338 lw $gp,cprestore($sp)
5339 The cprestore value is set using the .cprestore
5340 pseudo-op. If we are using a big GOT, we want
5341 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5343 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5347 lw $gp,cprestore($sp)
5348 If the symbol is not external, we want
5349 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5351 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5354 lw $gp,cprestore($sp)
5356 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5357 jalr $ra,$25 (BFD_RELOC_MIPS_JALR)
5361 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5362 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5363 "t,o(b)", PIC_CALL_REG
,
5364 (int) BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5365 macro_build_jalr (icnt
, &offset_expr
);
5372 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5373 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5374 "t,o(b)", PIC_CALL_REG
,
5375 (int) BFD_RELOC_MIPS_CALL16
, mips_gp_register
);
5376 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5378 p
= frag_var (rs_machine_dependent
, 4, 0,
5379 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5380 offset_expr
.X_add_symbol
, 0, NULL
);
5386 if (reg_needs_delay (mips_gp_register
))
5390 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui",
5391 "t,u", PIC_CALL_REG
,
5392 (int) BFD_RELOC_MIPS_CALL_HI16
);
5393 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5394 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5395 "d,v,t", PIC_CALL_REG
, PIC_CALL_REG
,
5397 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5398 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5399 "t,o(b)", PIC_CALL_REG
,
5400 (int) BFD_RELOC_MIPS_CALL_LO16
, PIC_CALL_REG
);
5401 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5403 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5404 RELAX_ENCODE (16, 12 + gpdel
, gpdel
,
5406 offset_expr
.X_add_symbol
, 0, NULL
);
5409 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5412 macro_build (p
, &icnt
, &offset_expr
,
5413 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5414 "t,o(b)", PIC_CALL_REG
,
5415 (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
5417 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5420 macro_build (p
, &icnt
, &offset_expr
,
5421 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5422 "t,r,j", PIC_CALL_REG
, PIC_CALL_REG
,
5423 (int) BFD_RELOC_LO16
);
5424 macro_build_jalr (icnt
, &offset_expr
);
5426 if (mips_cprestore_offset
< 0)
5427 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5430 if (! mips_frame_reg_valid
)
5432 as_warn (_("No .frame pseudo-op used in PIC code"));
5433 /* Quiet this warning. */
5434 mips_frame_reg_valid
= 1;
5436 if (! mips_cprestore_valid
)
5438 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5439 /* Quiet this warning. */
5440 mips_cprestore_valid
= 1;
5442 if (mips_opts
.noreorder
)
5443 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5445 expr1
.X_add_number
= mips_cprestore_offset
;
5446 macro_build_ldst_constoffset ((char *) NULL
, &icnt
, &expr1
,
5447 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5448 mips_gp_register
, mips_frame_reg
);
5452 else if (mips_pic
== EMBEDDED_PIC
)
5454 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "bal", "p");
5455 /* The linker may expand the call to a longer sequence which
5456 uses $at, so we must break rather than return. */
5481 /* Itbl support may require additional care here. */
5486 /* Itbl support may require additional care here. */
5491 /* Itbl support may require additional care here. */
5496 /* Itbl support may require additional care here. */
5508 if (mips_arch
== CPU_R4650
)
5510 as_bad (_("opcode not supported on this processor"));
5514 /* Itbl support may require additional care here. */
5519 /* Itbl support may require additional care here. */
5524 /* Itbl support may require additional care here. */
5544 if (breg
== treg
|| coproc
|| lr
)
5566 /* Itbl support may require additional care here. */
5571 /* Itbl support may require additional care here. */
5576 /* Itbl support may require additional care here. */
5581 /* Itbl support may require additional care here. */
5597 if (mips_arch
== CPU_R4650
)
5599 as_bad (_("opcode not supported on this processor"));
5604 /* Itbl support may require additional care here. */
5608 /* Itbl support may require additional care here. */
5613 /* Itbl support may require additional care here. */
5625 /* Itbl support may require additional care here. */
5626 if (mask
== M_LWC1_AB
5627 || mask
== M_SWC1_AB
5628 || mask
== M_LDC1_AB
5629 || mask
== M_SDC1_AB
5638 /* For embedded PIC, we allow loads where the offset is calculated
5639 by subtracting a symbol in the current segment from an unknown
5640 symbol, relative to a base register, e.g.:
5641 <op> $treg, <sym>-<localsym>($breg)
5642 This is used by the compiler for switch statements. */
5643 if (mips_pic
== EMBEDDED_PIC
5644 && offset_expr
.X_op
== O_subtract
5645 && (symbol_constant_p (offset_expr
.X_op_symbol
)
5646 ? S_GET_SEGMENT (offset_expr
.X_op_symbol
) == now_seg
5647 : (symbol_equated_p (offset_expr
.X_op_symbol
)
5649 (symbol_get_value_expression (offset_expr
.X_op_symbol
)
5653 && (offset_expr
.X_add_number
== 0
5654 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
))
5656 /* For this case, we output the instructions:
5657 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5658 addiu $tempreg,$tempreg,$breg
5659 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5660 If the relocation would fit entirely in 16 bits, it would be
5662 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5663 instead, but that seems quite difficult. */
5664 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5665 tempreg
, (int) BFD_RELOC_PCREL_HI16_S
);
5666 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5667 ((bfd_arch_bits_per_address (stdoutput
) == 32
5668 || ! ISA_HAS_64BIT_REGS (mips_opts
.isa
))
5669 ? "addu" : "daddu"),
5670 "d,v,t", tempreg
, tempreg
, breg
);
5671 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5672 (int) BFD_RELOC_PCREL_LO16
, tempreg
);
5678 if (offset_expr
.X_op
!= O_constant
5679 && offset_expr
.X_op
!= O_symbol
)
5681 as_bad (_("expression too complex"));
5682 offset_expr
.X_op
= O_constant
;
5685 /* A constant expression in PIC code can be handled just as it
5686 is in non PIC code. */
5687 if (mips_pic
== NO_PIC
5688 || offset_expr
.X_op
== O_constant
)
5692 /* If this is a reference to a GP relative symbol, and there
5693 is no base register, we want
5694 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5695 Otherwise, if there is no base register, we want
5696 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5697 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5698 If we have a constant, we need two instructions anyhow,
5699 so we always use the latter form.
5701 If we have a base register, and this is a reference to a
5702 GP relative symbol, we want
5703 addu $tempreg,$breg,$gp
5704 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5706 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5707 addu $tempreg,$tempreg,$breg
5708 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5709 With a constant we always use the latter case.
5711 With 64bit address space and no base register and $at usable,
5713 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5714 lui $at,<sym> (BFD_RELOC_HI16_S)
5715 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5718 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5719 If we have a base register, we want
5720 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5721 lui $at,<sym> (BFD_RELOC_HI16_S)
5722 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5726 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5728 Without $at we can't generate the optimal path for superscalar
5729 processors here since this would require two temporary registers.
5730 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5731 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5733 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5735 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5736 If we have a base register, we want
5737 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5738 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5740 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5742 daddu $tempreg,$tempreg,$breg
5743 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5745 If we have 64-bit addresses, as an optimization, for
5746 addresses which are 32-bit constants (e.g. kseg0/kseg1
5747 addresses) we fall back to the 32-bit address generation
5748 mechanism since it is more efficient. Note that due to
5749 the signed offset used by memory operations, the 32-bit
5750 range is shifted down by 32768 here. This code should
5751 probably attempt to generate 64-bit constants more
5752 efficiently in general.
5754 if (HAVE_64BIT_ADDRESSES
5755 && !(offset_expr
.X_op
== O_constant
5756 && IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
+ 0x8000)))
5760 /* We don't do GP optimization for now because RELAX_ENCODE can't
5761 hold the data for such large chunks. */
5763 if (used_at
== 0 && ! mips_opts
.noat
)
5765 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5766 tempreg
, (int) BFD_RELOC_MIPS_HIGHEST
);
5767 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5768 AT
, (int) BFD_RELOC_HI16_S
);
5769 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5770 tempreg
, tempreg
, (int) BFD_RELOC_MIPS_HIGHER
);
5772 macro_build (p
, &icnt
, (expressionS
*) NULL
, "daddu",
5773 "d,v,t", AT
, AT
, breg
);
5774 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll32",
5775 "d,w,<", tempreg
, tempreg
, 0);
5776 macro_build (p
, &icnt
, (expressionS
*) NULL
, "daddu",
5777 "d,v,t", tempreg
, tempreg
, AT
);
5778 macro_build (p
, &icnt
, &offset_expr
, s
,
5779 fmt
, treg
, (int) BFD_RELOC_LO16
, tempreg
);
5784 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5785 tempreg
, (int) BFD_RELOC_MIPS_HIGHEST
);
5786 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5787 tempreg
, tempreg
, (int) BFD_RELOC_MIPS_HIGHER
);
5788 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll",
5789 "d,w,<", tempreg
, tempreg
, 16);
5790 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5791 tempreg
, tempreg
, (int) BFD_RELOC_HI16_S
);
5792 macro_build (p
, &icnt
, (expressionS
*) NULL
, "dsll",
5793 "d,w,<", tempreg
, tempreg
, 16);
5795 macro_build (p
, &icnt
, (expressionS
*) NULL
, "daddu",
5796 "d,v,t", tempreg
, tempreg
, breg
);
5797 macro_build (p
, &icnt
, &offset_expr
, s
,
5798 fmt
, treg
, (int) BFD_RELOC_LO16
, tempreg
);
5806 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
5807 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5812 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
5813 treg
, (int) BFD_RELOC_GPREL16
,
5815 p
= frag_var (rs_machine_dependent
, 8, 0,
5816 RELAX_ENCODE (4, 8, 0, 4, 0,
5817 (mips_opts
.warn_about_macros
5819 && mips_opts
.noat
))),
5820 offset_expr
.X_add_symbol
, 0, NULL
);
5823 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
5826 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5827 (int) BFD_RELOC_LO16
, tempreg
);
5831 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
5832 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5837 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5838 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5839 "d,v,t", tempreg
, breg
, mips_gp_register
);
5840 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
5841 treg
, (int) BFD_RELOC_GPREL16
, tempreg
);
5842 p
= frag_var (rs_machine_dependent
, 12, 0,
5843 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5844 offset_expr
.X_add_symbol
, 0, NULL
);
5846 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
5849 macro_build (p
, &icnt
, (expressionS
*) NULL
,
5850 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5851 "d,v,t", tempreg
, tempreg
, breg
);
5854 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5855 (int) BFD_RELOC_LO16
, tempreg
);
5858 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
5861 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
5863 /* If this is a reference to an external symbol, we want
5864 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5866 <op> $treg,0($tempreg)
5868 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5870 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5871 <op> $treg,0($tempreg)
5872 If we have NewABI, we want
5873 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5874 If there is a base register, we add it to $tempreg before
5875 the <op>. If there is a constant, we stick it in the
5876 <op> instruction. We don't handle constants larger than
5877 16 bits, because we have no way to load the upper 16 bits
5878 (actually, we could handle them for the subset of cases
5879 in which we are not using $at). */
5880 assert (offset_expr
.X_op
== O_symbol
);
5881 expr1
.X_add_number
= offset_expr
.X_add_number
;
5882 offset_expr
.X_add_number
= 0;
5884 lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_DISP
;
5885 if (expr1
.X_add_number
< -0x8000
5886 || expr1
.X_add_number
>= 0x8000)
5887 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5889 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5890 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", tempreg
,
5891 (int) lw_reloc_type
, mips_gp_register
);
5892 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
5893 p
= frag_var (rs_machine_dependent
, 4, 0,
5894 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5895 offset_expr
.X_add_symbol
, 0, NULL
);
5896 macro_build (p
, &icnt
, &offset_expr
,
5897 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5898 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
5900 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5901 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5902 "d,v,t", tempreg
, tempreg
, breg
);
5903 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
, treg
,
5904 (int) BFD_RELOC_LO16
, tempreg
);
5906 else if (mips_pic
== SVR4_PIC
)
5911 /* If this is a reference to an external symbol, we want
5912 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5913 addu $tempreg,$tempreg,$gp
5914 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5915 <op> $treg,0($tempreg)
5917 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5919 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5920 <op> $treg,0($tempreg)
5921 If there is a base register, we add it to $tempreg before
5922 the <op>. If there is a constant, we stick it in the
5923 <op> instruction. We don't handle constants larger than
5924 16 bits, because we have no way to load the upper 16 bits
5925 (actually, we could handle them for the subset of cases
5926 in which we are not using $at).
5929 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5930 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5931 <op> $treg,0($tempreg)
5933 assert (offset_expr
.X_op
== O_symbol
);
5934 expr1
.X_add_number
= offset_expr
.X_add_number
;
5935 offset_expr
.X_add_number
= 0;
5936 if (expr1
.X_add_number
< -0x8000
5937 || expr1
.X_add_number
>= 0x8000)
5938 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5941 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5942 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5943 "t,o(b)", tempreg
, BFD_RELOC_MIPS_GOT_PAGE
,
5945 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5946 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5947 "t,r,j", tempreg
, tempreg
,
5948 BFD_RELOC_MIPS_GOT_OFST
);
5950 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5951 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5952 "d,v,t", tempreg
, tempreg
, breg
);
5953 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
, treg
,
5954 (int) BFD_RELOC_LO16
, tempreg
);
5961 if (reg_needs_delay (mips_gp_register
))
5966 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5967 tempreg
, (int) BFD_RELOC_MIPS_GOT_HI16
);
5968 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5969 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5970 "d,v,t", tempreg
, tempreg
, mips_gp_register
);
5971 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
5972 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5973 "t,o(b)", tempreg
, (int) BFD_RELOC_MIPS_GOT_LO16
,
5975 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5976 RELAX_ENCODE (12, 12 + gpdel
, gpdel
, 8 + gpdel
, 0, 0),
5977 offset_expr
.X_add_symbol
, 0, NULL
);
5980 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5983 macro_build (p
, &icnt
, &offset_expr
,
5984 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
5985 "t,o(b)", tempreg
, (int) BFD_RELOC_MIPS_GOT16
,
5988 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
5990 macro_build (p
, &icnt
, &offset_expr
,
5991 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu",
5992 "t,r,j", tempreg
, tempreg
, (int) BFD_RELOC_LO16
);
5994 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
5995 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
5996 "d,v,t", tempreg
, tempreg
, breg
);
5997 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
, treg
,
5998 (int) BFD_RELOC_LO16
, tempreg
);
6000 else if (mips_pic
== EMBEDDED_PIC
)
6002 /* If there is no base register, we want
6003 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6004 If there is a base register, we want
6005 addu $tempreg,$breg,$gp
6006 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6008 assert (offset_expr
.X_op
== O_symbol
);
6011 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6012 treg
, (int) BFD_RELOC_GPREL16
, mips_gp_register
);
6017 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6018 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6019 "d,v,t", tempreg
, breg
, mips_gp_register
);
6020 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6021 treg
, (int) BFD_RELOC_GPREL16
, tempreg
);
6034 load_register (&icnt
, treg
, &imm_expr
, 0);
6038 load_register (&icnt
, treg
, &imm_expr
, 1);
6042 if (imm_expr
.X_op
== O_constant
)
6044 load_register (&icnt
, AT
, &imm_expr
, 0);
6045 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6046 "mtc1", "t,G", AT
, treg
);
6051 assert (offset_expr
.X_op
== O_symbol
6052 && strcmp (segment_name (S_GET_SEGMENT
6053 (offset_expr
.X_add_symbol
)),
6055 && offset_expr
.X_add_number
== 0);
6056 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)",
6057 treg
, (int) BFD_RELOC_MIPS_LITERAL
, mips_gp_register
);
6062 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6063 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6064 order 32 bits of the value and the low order 32 bits are either
6065 zero or in OFFSET_EXPR. */
6066 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
6068 if (HAVE_64BIT_GPRS
)
6069 load_register (&icnt
, treg
, &imm_expr
, 1);
6074 if (target_big_endian
)
6086 load_register (&icnt
, hreg
, &imm_expr
, 0);
6089 if (offset_expr
.X_op
== O_absent
)
6090 move_register (&icnt
, lreg
, 0);
6093 assert (offset_expr
.X_op
== O_constant
);
6094 load_register (&icnt
, lreg
, &offset_expr
, 0);
6101 /* We know that sym is in the .rdata section. First we get the
6102 upper 16 bits of the address. */
6103 if (mips_pic
== NO_PIC
)
6105 macro_build_lui (NULL
, &icnt
, &offset_expr
, AT
);
6107 else if (mips_pic
== SVR4_PIC
)
6109 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
6110 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
6111 "t,o(b)", AT
, (int) BFD_RELOC_MIPS_GOT16
,
6114 else if (mips_pic
== EMBEDDED_PIC
)
6116 /* For embedded PIC we pick up the entire address off $gp in
6117 a single instruction. */
6118 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
6119 HAVE_32BIT_ADDRESSES
? "addiu" : "daddiu", "t,r,j", AT
,
6120 mips_gp_register
, (int) BFD_RELOC_GPREL16
);
6121 offset_expr
.X_op
= O_constant
;
6122 offset_expr
.X_add_number
= 0;
6127 /* Now we load the register(s). */
6128 if (HAVE_64BIT_GPRS
)
6129 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "ld", "t,o(b)",
6130 treg
, (int) BFD_RELOC_LO16
, AT
);
6133 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lw", "t,o(b)",
6134 treg
, (int) BFD_RELOC_LO16
, AT
);
6137 /* FIXME: How in the world do we deal with the possible
6139 offset_expr
.X_add_number
+= 4;
6140 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lw", "t,o(b)",
6141 treg
+ 1, (int) BFD_RELOC_LO16
, AT
);
6145 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6146 does not become a variant frag. */
6147 frag_wane (frag_now
);
6153 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6154 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6155 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6156 the value and the low order 32 bits are either zero or in
6158 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
6160 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_FPRS
);
6161 if (HAVE_64BIT_FPRS
)
6163 assert (HAVE_64BIT_GPRS
);
6164 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6165 "dmtc1", "t,S", AT
, treg
);
6169 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6170 "mtc1", "t,G", AT
, treg
+ 1);
6171 if (offset_expr
.X_op
== O_absent
)
6172 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6173 "mtc1", "t,G", 0, treg
);
6176 assert (offset_expr
.X_op
== O_constant
);
6177 load_register (&icnt
, AT
, &offset_expr
, 0);
6178 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6179 "mtc1", "t,G", AT
, treg
);
6185 assert (offset_expr
.X_op
== O_symbol
6186 && offset_expr
.X_add_number
== 0);
6187 s
= segment_name (S_GET_SEGMENT (offset_expr
.X_add_symbol
));
6188 if (strcmp (s
, ".lit8") == 0)
6190 if (mips_opts
.isa
!= ISA_MIPS1
)
6192 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "ldc1",
6193 "T,o(b)", treg
, (int) BFD_RELOC_MIPS_LITERAL
,
6197 breg
= mips_gp_register
;
6198 r
= BFD_RELOC_MIPS_LITERAL
;
6203 assert (strcmp (s
, RDATA_SECTION_NAME
) == 0);
6204 if (mips_pic
== SVR4_PIC
)
6205 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
6206 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
6207 "t,o(b)", AT
, (int) BFD_RELOC_MIPS_GOT16
,
6211 /* FIXME: This won't work for a 64 bit address. */
6212 macro_build_lui (NULL
, &icnt
, &offset_expr
, AT
);
6215 if (mips_opts
.isa
!= ISA_MIPS1
)
6217 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "ldc1",
6218 "T,o(b)", treg
, (int) BFD_RELOC_LO16
, AT
);
6220 /* To avoid confusion in tc_gen_reloc, we must ensure
6221 that this does not become a variant frag. */
6222 frag_wane (frag_now
);
6233 if (mips_arch
== CPU_R4650
)
6235 as_bad (_("opcode not supported on this processor"));
6238 /* Even on a big endian machine $fn comes before $fn+1. We have
6239 to adjust when loading from memory. */
6242 assert (mips_opts
.isa
== ISA_MIPS1
);
6243 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)",
6244 target_big_endian
? treg
+ 1 : treg
,
6246 /* FIXME: A possible overflow which I don't know how to deal
6248 offset_expr
.X_add_number
+= 4;
6249 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)",
6250 target_big_endian
? treg
: treg
+ 1,
6253 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6254 does not become a variant frag. */
6255 frag_wane (frag_now
);
6264 * The MIPS assembler seems to check for X_add_number not
6265 * being double aligned and generating:
6268 * addiu at,at,%lo(foo+1)
6271 * But, the resulting address is the same after relocation so why
6272 * generate the extra instruction?
6274 if (mips_arch
== CPU_R4650
)
6276 as_bad (_("opcode not supported on this processor"));
6279 /* Itbl support may require additional care here. */
6281 if (mips_opts
.isa
!= ISA_MIPS1
)
6292 if (mips_arch
== CPU_R4650
)
6294 as_bad (_("opcode not supported on this processor"));
6298 if (mips_opts
.isa
!= ISA_MIPS1
)
6306 /* Itbl support may require additional care here. */
6311 if (HAVE_64BIT_GPRS
)
6322 if (HAVE_64BIT_GPRS
)
6332 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6333 loads for the case of doing a pair of loads to simulate an 'ld'.
6334 This is not currently done by the compiler, and assembly coders
6335 writing embedded-pic code can cope. */
6337 if (offset_expr
.X_op
!= O_symbol
6338 && offset_expr
.X_op
!= O_constant
)
6340 as_bad (_("expression too complex"));
6341 offset_expr
.X_op
= O_constant
;
6344 /* Even on a big endian machine $fn comes before $fn+1. We have
6345 to adjust when loading from memory. We set coproc if we must
6346 load $fn+1 first. */
6347 /* Itbl support may require additional care here. */
6348 if (! target_big_endian
)
6351 if (mips_pic
== NO_PIC
6352 || offset_expr
.X_op
== O_constant
)
6356 /* If this is a reference to a GP relative symbol, we want
6357 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6358 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6359 If we have a base register, we use this
6361 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6362 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6363 If this is not a GP relative symbol, we want
6364 lui $at,<sym> (BFD_RELOC_HI16_S)
6365 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6366 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6367 If there is a base register, we add it to $at after the
6368 lui instruction. If there is a constant, we always use
6370 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
6371 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6383 tempreg
= mips_gp_register
;
6390 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6391 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6392 "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;
6404 /* Set mips_optimize to 2 to avoid inserting an
6406 hold_mips_optimize
= mips_optimize
;
6408 /* Itbl support may require additional care here. */
6409 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6410 coproc
? treg
: treg
+ 1,
6411 (int) BFD_RELOC_GPREL16
, tempreg
);
6412 mips_optimize
= hold_mips_optimize
;
6414 p
= frag_var (rs_machine_dependent
, 12 + off
, 0,
6415 RELAX_ENCODE (8 + off
, 12 + off
, 0, 4 + off
, 1,
6416 used_at
&& mips_opts
.noat
),
6417 offset_expr
.X_add_symbol
, 0, NULL
);
6419 /* We just generated two relocs. When tc_gen_reloc
6420 handles this case, it will skip the first reloc and
6421 handle the second. The second reloc already has an
6422 extra addend of 4, which we added above. We must
6423 subtract it out, and then subtract another 4 to make
6424 the first reloc come out right. The second reloc
6425 will come out right because we are going to add 4 to
6426 offset_expr when we build its instruction below.
6428 If we have a symbol, then we don't want to include
6429 the offset, because it will wind up being included
6430 when we generate the reloc. */
6432 if (offset_expr
.X_op
== O_constant
)
6433 offset_expr
.X_add_number
-= 8;
6436 offset_expr
.X_add_number
= -4;
6437 offset_expr
.X_op
= O_constant
;
6440 macro_build_lui (p
, &icnt
, &offset_expr
, AT
);
6445 macro_build (p
, &icnt
, (expressionS
*) NULL
,
6446 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6447 "d,v,t", AT
, breg
, AT
);
6451 /* Itbl support may require additional care here. */
6452 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
,
6453 coproc
? treg
+ 1 : treg
,
6454 (int) BFD_RELOC_LO16
, AT
);
6457 /* FIXME: How do we handle overflow here? */
6458 offset_expr
.X_add_number
+= 4;
6459 /* Itbl support may require additional care here. */
6460 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
,
6461 coproc
? treg
: treg
+ 1,
6462 (int) BFD_RELOC_LO16
, AT
);
6464 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
6468 /* If this is a reference to an external symbol, we want
6469 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6474 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6476 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6477 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6478 If there is a base register we add it to $at before the
6479 lwc1 instructions. If there is a constant we include it
6480 in the lwc1 instructions. */
6482 expr1
.X_add_number
= offset_expr
.X_add_number
;
6483 offset_expr
.X_add_number
= 0;
6484 if (expr1
.X_add_number
< -0x8000
6485 || expr1
.X_add_number
>= 0x8000 - 4)
6486 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6491 frag_grow (24 + off
);
6492 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
6493 HAVE_32BIT_ADDRESSES
? "lw" : "ld", "t,o(b)", AT
,
6494 (int) BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6495 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
6497 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6498 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6499 "d,v,t", AT
, breg
, AT
);
6500 /* Itbl support may require additional care here. */
6501 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
,
6502 coproc
? treg
+ 1 : treg
,
6503 (int) BFD_RELOC_LO16
, AT
);
6504 expr1
.X_add_number
+= 4;
6506 /* Set mips_optimize to 2 to avoid inserting an undesired
6508 hold_mips_optimize
= mips_optimize
;
6510 /* Itbl support may require additional care here. */
6511 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
,
6512 coproc
? treg
: treg
+ 1,
6513 (int) BFD_RELOC_LO16
, AT
);
6514 mips_optimize
= hold_mips_optimize
;
6516 (void) frag_var (rs_machine_dependent
, 0, 0,
6517 RELAX_ENCODE (0, 0, -16 - off
, -8, 1, 0),
6518 offset_expr
.X_add_symbol
, 0, NULL
);
6520 else if (mips_pic
== SVR4_PIC
)
6525 /* If this is a reference to an external symbol, we want
6526 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6528 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6533 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6535 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6536 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6537 If there is a base register we add it to $at before the
6538 lwc1 instructions. If there is a constant we include it
6539 in the lwc1 instructions. */
6541 expr1
.X_add_number
= offset_expr
.X_add_number
;
6542 offset_expr
.X_add_number
= 0;
6543 if (expr1
.X_add_number
< -0x8000
6544 || expr1
.X_add_number
>= 0x8000 - 4)
6545 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6546 if (reg_needs_delay (mips_gp_register
))
6555 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lui", "t,u",
6556 AT
, (int) BFD_RELOC_MIPS_GOT_HI16
);
6557 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6558 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6559 "d,v,t", AT
, AT
, mips_gp_register
);
6560 macro_build ((char *) NULL
, &icnt
, &offset_expr
,
6561 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
6562 "t,o(b)", AT
, (int) BFD_RELOC_MIPS_GOT_LO16
, AT
);
6563 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
6565 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6566 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6567 "d,v,t", AT
, breg
, AT
);
6568 /* Itbl support may require additional care here. */
6569 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
,
6570 coproc
? treg
+ 1 : treg
,
6571 (int) BFD_RELOC_LO16
, AT
);
6572 expr1
.X_add_number
+= 4;
6574 /* Set mips_optimize to 2 to avoid inserting an undesired
6576 hold_mips_optimize
= mips_optimize
;
6578 /* Itbl support may require additional care here. */
6579 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, fmt
,
6580 coproc
? treg
: treg
+ 1,
6581 (int) BFD_RELOC_LO16
, AT
);
6582 mips_optimize
= hold_mips_optimize
;
6583 expr1
.X_add_number
-= 4;
6585 p
= frag_var (rs_machine_dependent
, 16 + gpdel
+ off
, 0,
6586 RELAX_ENCODE (24 + off
, 16 + gpdel
+ off
, gpdel
,
6587 8 + gpdel
+ off
, 1, 0),
6588 offset_expr
.X_add_symbol
, 0, NULL
);
6591 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
6594 macro_build (p
, &icnt
, &offset_expr
,
6595 HAVE_32BIT_ADDRESSES
? "lw" : "ld",
6596 "t,o(b)", AT
, (int) BFD_RELOC_MIPS_GOT16
,
6599 macro_build (p
, &icnt
, (expressionS
*) NULL
, "nop", "");
6603 macro_build (p
, &icnt
, (expressionS
*) NULL
,
6604 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6605 "d,v,t", AT
, breg
, AT
);
6608 /* Itbl support may require additional care here. */
6609 macro_build (p
, &icnt
, &expr1
, s
, fmt
,
6610 coproc
? treg
+ 1 : treg
,
6611 (int) BFD_RELOC_LO16
, AT
);
6613 expr1
.X_add_number
+= 4;
6615 /* Set mips_optimize to 2 to avoid inserting an undesired
6617 hold_mips_optimize
= mips_optimize
;
6619 /* Itbl support may require additional care here. */
6620 macro_build (p
, &icnt
, &expr1
, s
, fmt
,
6621 coproc
? treg
: treg
+ 1,
6622 (int) BFD_RELOC_LO16
, AT
);
6623 mips_optimize
= hold_mips_optimize
;
6625 else if (mips_pic
== EMBEDDED_PIC
)
6627 /* If there is no base register, we use
6628 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6629 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6630 If we have a base register, we use
6632 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6633 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6637 tempreg
= mips_gp_register
;
6642 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6643 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
6644 "d,v,t", AT
, breg
, mips_gp_register
);
6649 /* Itbl support may require additional care here. */
6650 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6651 coproc
? treg
+ 1 : treg
,
6652 (int) BFD_RELOC_GPREL16
, tempreg
);
6653 offset_expr
.X_add_number
+= 4;
6654 /* Itbl support may require additional care here. */
6655 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, fmt
,
6656 coproc
? treg
: treg
+ 1,
6657 (int) BFD_RELOC_GPREL16
, tempreg
);
6673 assert (HAVE_32BIT_ADDRESSES
);
6674 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
6675 (int) BFD_RELOC_LO16
, breg
);
6676 offset_expr
.X_add_number
+= 4;
6677 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
+ 1,
6678 (int) BFD_RELOC_LO16
, breg
);
6681 /* New code added to support COPZ instructions.
6682 This code builds table entries out of the macros in mip_opcodes.
6683 R4000 uses interlocks to handle coproc delays.
6684 Other chips (like the R3000) require nops to be inserted for delays.
6686 FIXME: Currently, we require that the user handle delays.
6687 In order to fill delay slots for non-interlocked chips,
6688 we must have a way to specify delays based on the coprocessor.
6689 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6690 What are the side-effects of the cop instruction?
6691 What cache support might we have and what are its effects?
6692 Both coprocessor & memory require delays. how long???
6693 What registers are read/set/modified?
6695 If an itbl is provided to interpret cop instructions,
6696 this knowledge can be encoded in the itbl spec. */
6710 /* For now we just do C (same as Cz). The parameter will be
6711 stored in insn_opcode by mips_ip. */
6712 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "C",
6717 move_register (&icnt
, dreg
, sreg
);
6720 #ifdef LOSING_COMPILER
6722 /* Try and see if this is a new itbl instruction.
6723 This code builds table entries out of the macros in mip_opcodes.
6724 FIXME: For now we just assemble the expression and pass it's
6725 value along as a 32-bit immediate.
6726 We may want to have the assembler assemble this value,
6727 so that we gain the assembler's knowledge of delay slots,
6729 Would it be more efficient to use mask (id) here? */
6730 if (itbl_have_entries
6731 && (immed_expr
= itbl_assemble (ip
->insn_mo
->name
, "")))
6733 s
= ip
->insn_mo
->name
;
6735 coproc
= ITBL_DECODE_PNUM (immed_expr
);;
6736 macro_build ((char *) NULL
, &icnt
, &immed_expr
, s
, "C");
6743 as_warn (_("Macro used $at after \".set noat\""));
6748 struct mips_cl_insn
*ip
;
6750 register int treg
, sreg
, dreg
, breg
;
6766 bfd_reloc_code_real_type r
;
6769 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
6770 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
6771 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
6772 mask
= ip
->insn_mo
->mask
;
6774 expr1
.X_op
= O_constant
;
6775 expr1
.X_op_symbol
= NULL
;
6776 expr1
.X_add_symbol
= NULL
;
6777 expr1
.X_add_number
= 1;
6781 #endif /* LOSING_COMPILER */
6786 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6787 dbl
? "dmultu" : "multu", "s,t", sreg
, treg
);
6788 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d",
6795 /* The MIPS assembler some times generates shifts and adds. I'm
6796 not trying to be that fancy. GCC should do this for us
6798 load_register (&icnt
, AT
, &imm_expr
, dbl
);
6799 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6800 dbl
? "dmult" : "mult", "s,t", sreg
, AT
);
6801 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d",
6815 mips_emit_delays (true);
6816 ++mips_opts
.noreorder
;
6817 mips_any_noreorder
= 1;
6819 load_register (&icnt
, AT
, &imm_expr
, dbl
);
6820 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6821 dbl
? "dmult" : "mult", "s,t", sreg
, imm
? AT
: treg
);
6822 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d",
6824 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6825 dbl
? "dsra32" : "sra", "d,w,<", dreg
, dreg
, RA
);
6826 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mfhi", "d",
6829 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "tne",
6830 "s,t,q", dreg
, AT
, 6);
6833 expr1
.X_add_number
= 8;
6834 macro_build ((char *) NULL
, &icnt
, &expr1
, "beq", "s,t,p", dreg
,
6836 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "",
6838 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
6841 --mips_opts
.noreorder
;
6842 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d", dreg
);
6855 mips_emit_delays (true);
6856 ++mips_opts
.noreorder
;
6857 mips_any_noreorder
= 1;
6859 load_register (&icnt
, AT
, &imm_expr
, dbl
);
6860 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
6861 dbl
? "dmultu" : "multu",
6862 "s,t", sreg
, imm
? AT
: treg
);
6863 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mfhi", "d",
6865 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "d",
6868 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "tne",
6872 expr1
.X_add_number
= 8;
6873 macro_build ((char *) NULL
, &icnt
, &expr1
, "beq", "s,t,p", AT
, 0);
6874 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "",
6876 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
6879 --mips_opts
.noreorder
;
6883 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsubu",
6884 "d,v,t", AT
, 0, treg
);
6885 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsrlv",
6886 "d,t,s", AT
, sreg
, AT
);
6887 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsllv",
6888 "d,t,s", dreg
, sreg
, treg
);
6889 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6890 "d,v,t", dreg
, dreg
, AT
);
6894 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "subu",
6895 "d,v,t", AT
, 0, treg
);
6896 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srlv",
6897 "d,t,s", AT
, sreg
, AT
);
6898 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sllv",
6899 "d,t,s", dreg
, sreg
, treg
);
6900 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6901 "d,v,t", dreg
, dreg
, AT
);
6908 if (imm_expr
.X_op
!= O_constant
)
6909 as_bad (_("rotate count too large"));
6910 rot
= imm_expr
.X_add_number
& 0x3f;
6911 if (CPU_HAS_DROR (mips_arch
))
6913 rot
= (64 - rot
) & 0x3f;
6915 macro_build ((char *) NULL
, &icnt
, NULL
, "dror32",
6916 "d,w,<", dreg
, sreg
, rot
- 32);
6918 macro_build ((char *) NULL
, &icnt
, NULL
, "dror",
6919 "d,w,<", dreg
, sreg
, rot
);
6923 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsrl",
6924 "d,w,<", dreg
, sreg
, 0);
6929 l
= (rot
< 0x20) ? "dsll" : "dsll32";
6930 r
= ((0x40 - rot
) < 0x20) ? "dsrl" : "dsrl32";
6932 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, l
,
6933 "d,w,<", AT
, sreg
, rot
);
6934 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, r
,
6935 "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
6936 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6937 "d,v,t", dreg
, dreg
, AT
);
6946 if (imm_expr
.X_op
!= O_constant
)
6947 as_bad (_("rotate count too large"));
6948 rot
= imm_expr
.X_add_number
& 0x1f;
6949 if (CPU_HAS_ROR (mips_arch
))
6951 macro_build ((char *) NULL
, &icnt
, NULL
, "ror",
6952 "d,w,<", dreg
, sreg
, (32 - rot
) & 0x1f);
6956 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl",
6957 "d,w,<", dreg
, sreg
, 0);
6960 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll",
6961 "d,w,<", AT
, sreg
, rot
);
6962 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl",
6963 "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
6964 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6965 "d,v,t", dreg
, dreg
, AT
);
6971 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsubu",
6972 "d,v,t", AT
, 0, treg
);
6973 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsllv",
6974 "d,t,s", AT
, sreg
, AT
);
6975 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsrlv",
6976 "d,t,s", dreg
, sreg
, treg
);
6977 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6978 "d,v,t", dreg
, dreg
, AT
);
6982 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "subu",
6983 "d,v,t", AT
, 0, treg
);
6984 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sllv",
6985 "d,t,s", AT
, sreg
, AT
);
6986 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srlv",
6987 "d,t,s", dreg
, sreg
, treg
);
6988 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
6989 "d,v,t", dreg
, dreg
, AT
);
6996 if (imm_expr
.X_op
!= O_constant
)
6997 as_bad (_("rotate count too large"));
6998 rot
= imm_expr
.X_add_number
& 0x3f;
7000 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "dsrl",
7001 "d,w,<", dreg
, sreg
, 0);
7006 r
= (rot
< 0x20) ? "dsrl" : "dsrl32";
7007 l
= ((0x40 - rot
) < 0x20) ? "dsll" : "dsll32";
7009 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, r
,
7010 "d,w,<", AT
, sreg
, rot
);
7011 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, l
,
7012 "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7013 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
7014 "d,v,t", dreg
, dreg
, AT
);
7023 if (imm_expr
.X_op
!= O_constant
)
7024 as_bad (_("rotate count too large"));
7025 rot
= imm_expr
.X_add_number
& 0x1f;
7027 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl",
7028 "d,w,<", dreg
, sreg
, 0);
7031 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl",
7032 "d,w,<", AT
, sreg
, rot
);
7033 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll",
7034 "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7035 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or",
7036 "d,v,t", dreg
, dreg
, AT
);
7042 if (mips_arch
== CPU_R4650
)
7044 as_bad (_("opcode not supported on this processor"));
7047 assert (mips_opts
.isa
== ISA_MIPS1
);
7048 /* Even on a big endian machine $fn comes before $fn+1. We have
7049 to adjust when storing to memory. */
7050 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "swc1", "T,o(b)",
7051 target_big_endian
? treg
+ 1 : treg
,
7052 (int) BFD_RELOC_LO16
, breg
);
7053 offset_expr
.X_add_number
+= 4;
7054 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "swc1", "T,o(b)",
7055 target_big_endian
? treg
: treg
+ 1,
7056 (int) BFD_RELOC_LO16
, breg
);
7061 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
,
7062 treg
, (int) BFD_RELOC_LO16
);
7064 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
,
7065 sreg
, (int) BFD_RELOC_LO16
);
7068 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "xor",
7069 "d,v,t", dreg
, sreg
, treg
);
7070 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
,
7071 dreg
, (int) BFD_RELOC_LO16
);
7076 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
7078 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
,
7079 sreg
, (int) BFD_RELOC_LO16
);
7084 as_warn (_("Instruction %s: result is always false"),
7086 move_register (&icnt
, dreg
, 0);
7089 if (imm_expr
.X_op
== O_constant
7090 && imm_expr
.X_add_number
>= 0
7091 && imm_expr
.X_add_number
< 0x10000)
7093 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "xori", "t,r,i", dreg
,
7094 sreg
, (int) BFD_RELOC_LO16
);
7097 else if (imm_expr
.X_op
== O_constant
7098 && imm_expr
.X_add_number
> -0x8000
7099 && imm_expr
.X_add_number
< 0)
7101 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7102 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7103 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7104 "t,r,j", dreg
, sreg
,
7105 (int) BFD_RELOC_LO16
);
7110 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7111 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "xor",
7112 "d,v,t", dreg
, sreg
, AT
);
7115 macro_build ((char *) NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
, dreg
,
7116 (int) BFD_RELOC_LO16
);
7121 case M_SGE
: /* sreg >= treg <==> not (sreg < treg) */
7127 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
7129 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
7130 (int) BFD_RELOC_LO16
);
7133 case M_SGE_I
: /* sreg >= I <==> not (sreg < I) */
7135 if (imm_expr
.X_op
== O_constant
7136 && imm_expr
.X_add_number
>= -0x8000
7137 && imm_expr
.X_add_number
< 0x8000)
7139 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7140 mask
== M_SGE_I
? "slti" : "sltiu",
7141 "t,r,j", dreg
, sreg
, (int) BFD_RELOC_LO16
);
7146 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7147 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7148 mask
== M_SGE_I
? "slt" : "sltu", "d,v,t", dreg
, sreg
,
7152 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
7153 (int) BFD_RELOC_LO16
);
7158 case M_SGT
: /* sreg > treg <==> treg < sreg */
7164 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
7168 case M_SGT_I
: /* sreg > I <==> I < sreg */
7174 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7175 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
7179 case M_SLE
: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7185 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
7187 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
7188 (int) BFD_RELOC_LO16
);
7191 case M_SLE_I
: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7197 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7198 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "d,v,t",
7200 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
7201 (int) BFD_RELOC_LO16
);
7205 if (imm_expr
.X_op
== O_constant
7206 && imm_expr
.X_add_number
>= -0x8000
7207 && imm_expr
.X_add_number
< 0x8000)
7209 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "slti", "t,r,j",
7210 dreg
, sreg
, (int) BFD_RELOC_LO16
);
7213 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7214 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "slt", "d,v,t",
7219 if (imm_expr
.X_op
== O_constant
7220 && imm_expr
.X_add_number
>= -0x8000
7221 && imm_expr
.X_add_number
< 0x8000)
7223 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "sltiu", "t,r,j",
7224 dreg
, sreg
, (int) BFD_RELOC_LO16
);
7227 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7228 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
7229 "d,v,t", dreg
, sreg
, AT
);
7234 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
7235 "d,v,t", dreg
, 0, treg
);
7237 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
7238 "d,v,t", dreg
, 0, sreg
);
7241 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "xor",
7242 "d,v,t", dreg
, sreg
, treg
);
7243 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
7244 "d,v,t", dreg
, 0, dreg
);
7249 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
7251 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
7252 "d,v,t", dreg
, 0, sreg
);
7257 as_warn (_("Instruction %s: result is always true"),
7259 macro_build ((char *) NULL
, &icnt
, &expr1
,
7260 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7261 "t,r,j", dreg
, 0, (int) BFD_RELOC_LO16
);
7264 if (imm_expr
.X_op
== O_constant
7265 && imm_expr
.X_add_number
>= 0
7266 && imm_expr
.X_add_number
< 0x10000)
7268 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "xori", "t,r,i",
7269 dreg
, sreg
, (int) BFD_RELOC_LO16
);
7272 else if (imm_expr
.X_op
== O_constant
7273 && imm_expr
.X_add_number
> -0x8000
7274 && imm_expr
.X_add_number
< 0)
7276 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7277 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7278 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7279 "t,r,j", dreg
, sreg
, (int) BFD_RELOC_LO16
);
7284 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7285 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "xor",
7286 "d,v,t", dreg
, sreg
, AT
);
7289 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sltu",
7290 "d,v,t", dreg
, 0, dreg
);
7298 if (imm_expr
.X_op
== O_constant
7299 && imm_expr
.X_add_number
> -0x8000
7300 && imm_expr
.X_add_number
<= 0x8000)
7302 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7303 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7304 dbl
? "daddi" : "addi",
7305 "t,r,j", dreg
, sreg
, (int) BFD_RELOC_LO16
);
7308 load_register (&icnt
, AT
, &imm_expr
, dbl
);
7309 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7310 dbl
? "dsub" : "sub", "d,v,t", dreg
, sreg
, AT
);
7316 if (imm_expr
.X_op
== O_constant
7317 && imm_expr
.X_add_number
> -0x8000
7318 && imm_expr
.X_add_number
<= 0x8000)
7320 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7321 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7322 dbl
? "daddiu" : "addiu",
7323 "t,r,j", dreg
, sreg
, (int) BFD_RELOC_LO16
);
7326 load_register (&icnt
, AT
, &imm_expr
, dbl
);
7327 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7328 dbl
? "dsubu" : "subu", "d,v,t", dreg
, sreg
, AT
);
7349 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7350 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "s,t", sreg
,
7356 assert (mips_opts
.isa
== ISA_MIPS1
);
7357 sreg
= (ip
->insn_opcode
>> 11) & 0x1f; /* floating reg */
7358 dreg
= (ip
->insn_opcode
>> 06) & 0x1f; /* floating reg */
7361 * Is the double cfc1 instruction a bug in the mips assembler;
7362 * or is there a reason for it?
7364 mips_emit_delays (true);
7365 ++mips_opts
.noreorder
;
7366 mips_any_noreorder
= 1;
7367 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "cfc1", "t,G",
7369 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "cfc1", "t,G",
7371 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
7372 expr1
.X_add_number
= 3;
7373 macro_build ((char *) NULL
, &icnt
, &expr1
, "ori", "t,r,i", AT
, treg
,
7374 (int) BFD_RELOC_LO16
);
7375 expr1
.X_add_number
= 2;
7376 macro_build ((char *) NULL
, &icnt
, &expr1
, "xori", "t,r,i", AT
, AT
,
7377 (int) BFD_RELOC_LO16
);
7378 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "ctc1", "t,G",
7380 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
7381 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7382 mask
== M_TRUNCWD
? "cvt.w.d" : "cvt.w.s", "D,S", dreg
, sreg
);
7383 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "ctc1", "t,G",
7385 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "nop", "");
7386 --mips_opts
.noreorder
;
7395 if (offset_expr
.X_add_number
>= 0x7fff)
7396 as_bad (_("operand overflow"));
7397 /* avoid load delay */
7398 if (! target_big_endian
)
7399 ++offset_expr
.X_add_number
;
7400 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
7401 (int) BFD_RELOC_LO16
, breg
);
7402 if (! target_big_endian
)
7403 --offset_expr
.X_add_number
;
7405 ++offset_expr
.X_add_number
;
7406 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "lbu", "t,o(b)", AT
,
7407 (int) BFD_RELOC_LO16
, breg
);
7408 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll", "d,w,<",
7410 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or", "d,v,t",
7424 if (offset_expr
.X_add_number
>= 0x8000 - off
)
7425 as_bad (_("operand overflow"));
7426 if (! target_big_endian
)
7427 offset_expr
.X_add_number
+= off
;
7428 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
7429 (int) BFD_RELOC_LO16
, breg
);
7430 if (! target_big_endian
)
7431 offset_expr
.X_add_number
-= off
;
7433 offset_expr
.X_add_number
+= off
;
7434 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s2
, "t,o(b)", treg
,
7435 (int) BFD_RELOC_LO16
, breg
);
7449 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7451 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7452 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
7453 "d,v,t", AT
, AT
, breg
);
7454 if (! target_big_endian
)
7455 expr1
.X_add_number
= off
;
7457 expr1
.X_add_number
= 0;
7458 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, "t,o(b)", treg
,
7459 (int) BFD_RELOC_LO16
, AT
);
7460 if (! target_big_endian
)
7461 expr1
.X_add_number
= 0;
7463 expr1
.X_add_number
= off
;
7464 macro_build ((char *) NULL
, &icnt
, &expr1
, s2
, "t,o(b)", treg
,
7465 (int) BFD_RELOC_LO16
, AT
);
7471 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7473 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7474 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
7475 "d,v,t", AT
, AT
, breg
);
7476 if (target_big_endian
)
7477 expr1
.X_add_number
= 0;
7478 macro_build ((char *) NULL
, &icnt
, &expr1
,
7479 mask
== M_ULH_A
? "lb" : "lbu", "t,o(b)", treg
,
7480 (int) BFD_RELOC_LO16
, AT
);
7481 if (target_big_endian
)
7482 expr1
.X_add_number
= 1;
7484 expr1
.X_add_number
= 0;
7485 macro_build ((char *) NULL
, &icnt
, &expr1
, "lbu", "t,o(b)", AT
,
7486 (int) BFD_RELOC_LO16
, AT
);
7487 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll", "d,w,<",
7489 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or", "d,v,t",
7494 if (offset_expr
.X_add_number
>= 0x7fff)
7495 as_bad (_("operand overflow"));
7496 if (target_big_endian
)
7497 ++offset_expr
.X_add_number
;
7498 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "sb", "t,o(b)", treg
,
7499 (int) BFD_RELOC_LO16
, breg
);
7500 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl", "d,w,<",
7502 if (target_big_endian
)
7503 --offset_expr
.X_add_number
;
7505 ++offset_expr
.X_add_number
;
7506 macro_build ((char *) NULL
, &icnt
, &offset_expr
, "sb", "t,o(b)", AT
,
7507 (int) BFD_RELOC_LO16
, breg
);
7520 if (offset_expr
.X_add_number
>= 0x8000 - off
)
7521 as_bad (_("operand overflow"));
7522 if (! target_big_endian
)
7523 offset_expr
.X_add_number
+= off
;
7524 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
7525 (int) BFD_RELOC_LO16
, breg
);
7526 if (! target_big_endian
)
7527 offset_expr
.X_add_number
-= off
;
7529 offset_expr
.X_add_number
+= off
;
7530 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s2
, "t,o(b)", treg
,
7531 (int) BFD_RELOC_LO16
, breg
);
7545 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7547 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7548 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
7549 "d,v,t", AT
, AT
, breg
);
7550 if (! target_big_endian
)
7551 expr1
.X_add_number
= off
;
7553 expr1
.X_add_number
= 0;
7554 macro_build ((char *) NULL
, &icnt
, &expr1
, s
, "t,o(b)", treg
,
7555 (int) BFD_RELOC_LO16
, AT
);
7556 if (! target_big_endian
)
7557 expr1
.X_add_number
= 0;
7559 expr1
.X_add_number
= off
;
7560 macro_build ((char *) NULL
, &icnt
, &expr1
, s2
, "t,o(b)", treg
,
7561 (int) BFD_RELOC_LO16
, AT
);
7566 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7568 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7569 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
7570 "d,v,t", AT
, AT
, breg
);
7571 if (! target_big_endian
)
7572 expr1
.X_add_number
= 0;
7573 macro_build ((char *) NULL
, &icnt
, &expr1
, "sb", "t,o(b)", treg
,
7574 (int) BFD_RELOC_LO16
, AT
);
7575 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "srl", "d,w,<",
7577 if (! target_big_endian
)
7578 expr1
.X_add_number
= 1;
7580 expr1
.X_add_number
= 0;
7581 macro_build ((char *) NULL
, &icnt
, &expr1
, "sb", "t,o(b)", treg
,
7582 (int) BFD_RELOC_LO16
, AT
);
7583 if (! target_big_endian
)
7584 expr1
.X_add_number
= 0;
7586 expr1
.X_add_number
= 1;
7587 macro_build ((char *) NULL
, &icnt
, &expr1
, "lbu", "t,o(b)", AT
,
7588 (int) BFD_RELOC_LO16
, AT
);
7589 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "sll", "d,w,<",
7591 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "or", "d,v,t",
7596 /* FIXME: Check if this is one of the itbl macros, since they
7597 are added dynamically. */
7598 as_bad (_("Macro %s not implemented yet"), ip
->insn_mo
->name
);
7602 as_warn (_("Macro used $at after \".set noat\""));
7605 /* Implement macros in mips16 mode. */
7609 struct mips_cl_insn
*ip
;
7612 int xreg
, yreg
, zreg
, tmp
;
7616 const char *s
, *s2
, *s3
;
7618 mask
= ip
->insn_mo
->mask
;
7620 xreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RX
) & MIPS16OP_MASK_RX
;
7621 yreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RY
) & MIPS16OP_MASK_RY
;
7622 zreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RZ
) & MIPS16OP_MASK_RZ
;
7626 expr1
.X_op
= O_constant
;
7627 expr1
.X_op_symbol
= NULL
;
7628 expr1
.X_add_symbol
= NULL
;
7629 expr1
.X_add_number
= 1;
7648 mips_emit_delays (true);
7649 ++mips_opts
.noreorder
;
7650 mips_any_noreorder
= 1;
7651 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7652 dbl
? "ddiv" : "div",
7653 "0,x,y", xreg
, yreg
);
7654 expr1
.X_add_number
= 2;
7655 macro_build ((char *) NULL
, &icnt
, &expr1
, "bnez", "x,p", yreg
);
7656 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break", "6",
7659 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7660 since that causes an overflow. We should do that as well,
7661 but I don't see how to do the comparisons without a temporary
7663 --mips_opts
.noreorder
;
7664 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "x", zreg
);
7683 mips_emit_delays (true);
7684 ++mips_opts
.noreorder
;
7685 mips_any_noreorder
= 1;
7686 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "0,x,y",
7688 expr1
.X_add_number
= 2;
7689 macro_build ((char *) NULL
, &icnt
, &expr1
, "bnez", "x,p", yreg
);
7690 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "break",
7692 --mips_opts
.noreorder
;
7693 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s2
, "x", zreg
);
7699 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7700 dbl
? "dmultu" : "multu", "x,y", xreg
, yreg
);
7701 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "mflo", "x",
7710 if (imm_expr
.X_op
!= O_constant
)
7711 as_bad (_("Unsupported large constant"));
7712 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7713 macro_build ((char *) NULL
, &icnt
, &imm_expr
,
7714 dbl
? "daddiu" : "addiu", "y,x,4", yreg
, xreg
);
7718 if (imm_expr
.X_op
!= O_constant
)
7719 as_bad (_("Unsupported large constant"));
7720 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7721 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "addiu",
7726 if (imm_expr
.X_op
!= O_constant
)
7727 as_bad (_("Unsupported large constant"));
7728 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7729 macro_build ((char *) NULL
, &icnt
, &imm_expr
, "daddiu",
7752 goto do_reverse_branch
;
7756 goto do_reverse_branch
;
7768 goto do_reverse_branch
;
7779 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, s
, "x,y",
7781 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s2
, "p");
7808 goto do_addone_branch_i
;
7813 goto do_addone_branch_i
;
7828 goto do_addone_branch_i
;
7835 if (imm_expr
.X_op
!= O_constant
)
7836 as_bad (_("Unsupported large constant"));
7837 ++imm_expr
.X_add_number
;
7840 macro_build ((char *) NULL
, &icnt
, &imm_expr
, s
, s3
, xreg
);
7841 macro_build ((char *) NULL
, &icnt
, &offset_expr
, s2
, "p");
7845 expr1
.X_add_number
= 0;
7846 macro_build ((char *) NULL
, &icnt
, &expr1
, "slti", "x,8", yreg
);
7848 move_register (&icnt
, xreg
, yreg
);
7849 expr1
.X_add_number
= 2;
7850 macro_build ((char *) NULL
, &icnt
, &expr1
, "bteqz", "p");
7851 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
7852 "neg", "x,w", xreg
, xreg
);
7856 /* For consistency checking, verify that all bits are specified either
7857 by the match/mask part of the instruction definition, or by the
7860 validate_mips_insn (opc
)
7861 const struct mips_opcode
*opc
;
7863 const char *p
= opc
->args
;
7865 unsigned long used_bits
= opc
->mask
;
7867 if ((used_bits
& opc
->match
) != opc
->match
)
7869 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7870 opc
->name
, opc
->args
);
7873 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7880 case '<': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
7881 case '>': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
7883 case 'B': USE_BITS (OP_MASK_CODE20
, OP_SH_CODE20
); break;
7884 case 'C': USE_BITS (OP_MASK_COPZ
, OP_SH_COPZ
); break;
7885 case 'D': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
7886 case 'E': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
7888 case 'G': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
7889 case 'H': USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
7891 case 'J': USE_BITS (OP_MASK_CODE19
, OP_SH_CODE19
); break;
7893 case 'M': USE_BITS (OP_MASK_CCC
, OP_SH_CCC
); break;
7894 case 'N': USE_BITS (OP_MASK_BCC
, OP_SH_BCC
); break;
7895 case 'O': USE_BITS (OP_MASK_ALN
, OP_SH_ALN
); break;
7896 case 'Q': USE_BITS (OP_MASK_VSEL
, OP_SH_VSEL
);
7897 USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
7898 case 'R': USE_BITS (OP_MASK_FR
, OP_SH_FR
); break;
7899 case 'S': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
7900 case 'T': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
7901 case 'V': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
7902 case 'W': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
7903 case 'X': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
7904 case 'Y': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
7905 case 'Z': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
7906 case 'a': USE_BITS (OP_MASK_TARGET
, OP_SH_TARGET
); break;
7907 case 'b': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
7908 case 'c': USE_BITS (OP_MASK_CODE
, OP_SH_CODE
); break;
7909 case 'd': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
7911 case 'h': USE_BITS (OP_MASK_PREFX
, OP_SH_PREFX
); break;
7912 case 'i': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
7913 case 'j': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
7914 case 'k': USE_BITS (OP_MASK_CACHE
, OP_SH_CACHE
); break;
7916 case 'o': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
7917 case 'p': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
7918 case 'q': USE_BITS (OP_MASK_CODE2
, OP_SH_CODE2
); break;
7919 case 'r': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
7920 case 's': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
7921 case 't': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
7922 case 'u': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
7923 case 'v': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
7924 case 'w': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
7927 case 'P': USE_BITS (OP_MASK_PERFREG
, OP_SH_PERFREG
); break;
7928 case 'U': USE_BITS (OP_MASK_RD
, OP_SH_RD
);
7929 USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
7930 case 'e': USE_BITS (OP_MASK_VECBYTE
, OP_SH_VECBYTE
); break;
7931 case '%': USE_BITS (OP_MASK_VECALIGN
, OP_SH_VECALIGN
); break;
7935 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7936 c
, opc
->name
, opc
->args
);
7940 if (used_bits
!= 0xffffffff)
7942 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7943 ~used_bits
& 0xffffffff, opc
->name
, opc
->args
);
7949 /* This routine assembles an instruction into its binary format. As a
7950 side effect, it sets one of the global variables imm_reloc or
7951 offset_reloc to the type of relocation to do if one of the operands
7952 is an address expression. */
7957 struct mips_cl_insn
*ip
;
7962 struct mips_opcode
*insn
;
7965 unsigned int lastregno
= 0;
7971 /* If the instruction contains a '.', we first try to match an instruction
7972 including the '.'. Then we try again without the '.'. */
7974 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); ++s
)
7977 /* If we stopped on whitespace, then replace the whitespace with null for
7978 the call to hash_find. Save the character we replaced just in case we
7979 have to re-parse the instruction. */
7986 insn
= (struct mips_opcode
*) hash_find (op_hash
, str
);
7988 /* If we didn't find the instruction in the opcode table, try again, but
7989 this time with just the instruction up to, but not including the
7993 /* Restore the character we overwrite above (if any). */
7997 /* Scan up to the first '.' or whitespace. */
7999 *s
!= '\0' && *s
!= '.' && !ISSPACE (*s
);
8003 /* If we did not find a '.', then we can quit now. */
8006 insn_error
= "unrecognized opcode";
8010 /* Lookup the instruction in the hash table. */
8012 if ((insn
= (struct mips_opcode
*) hash_find (op_hash
, str
)) == NULL
)
8014 insn_error
= "unrecognized opcode";
8024 assert (strcmp (insn
->name
, str
) == 0);
8026 if (OPCODE_IS_MEMBER (insn
,
8028 | (file_ase_mips16
? INSN_MIPS16
: 0)
8029 | (mips_opts
.ase_mdmx
? INSN_MDMX
: 0)
8030 | (mips_opts
.ase_mips3d
? INSN_MIPS3D
: 0)),
8036 if (insn
->pinfo
!= INSN_MACRO
)
8038 if (mips_arch
== CPU_R4650
&& (insn
->pinfo
& FP_D
) != 0)
8044 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
]
8045 && strcmp (insn
->name
, insn
[1].name
) == 0)
8054 static char buf
[100];
8055 if (mips_arch_info
->is_isa
)
8057 _("opcode not supported at this ISA level (%s)"),
8058 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
8061 _("opcode not supported on this processor: %s (%s)"),
8062 mips_arch_info
->name
,
8063 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
8073 ip
->insn_opcode
= insn
->match
;
8075 for (args
= insn
->args
;; ++args
)
8079 s
+= strspn (s
, " \t");
8083 case '\0': /* end of args */
8096 ip
->insn_opcode
|= lastregno
<< OP_SH_RS
;
8100 ip
->insn_opcode
|= lastregno
<< OP_SH_RT
;
8104 ip
->insn_opcode
|= lastregno
<< OP_SH_FT
;
8108 ip
->insn_opcode
|= lastregno
<< OP_SH_FS
;
8114 /* Handle optional base register.
8115 Either the base register is omitted or
8116 we must have a left paren. */
8117 /* This is dependent on the next operand specifier
8118 is a base register specification. */
8119 assert (args
[1] == 'b' || args
[1] == '5'
8120 || args
[1] == '-' || args
[1] == '4');
8124 case ')': /* these must match exactly */
8131 case '<': /* must be at least one digit */
8133 * According to the manual, if the shift amount is greater
8134 * than 31 or less than 0, then the shift amount should be
8135 * mod 32. In reality the mips assembler issues an error.
8136 * We issue a warning and mask out all but the low 5 bits.
8138 my_getExpression (&imm_expr
, s
);
8139 check_absolute_expr (ip
, &imm_expr
);
8140 if ((unsigned long) imm_expr
.X_add_number
> 31)
8142 as_warn (_("Improper shift amount (%lu)"),
8143 (unsigned long) imm_expr
.X_add_number
);
8144 imm_expr
.X_add_number
&= OP_MASK_SHAMT
;
8146 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_SHAMT
;
8147 imm_expr
.X_op
= O_absent
;
8151 case '>': /* shift amount minus 32 */
8152 my_getExpression (&imm_expr
, s
);
8153 check_absolute_expr (ip
, &imm_expr
);
8154 if ((unsigned long) imm_expr
.X_add_number
< 32
8155 || (unsigned long) imm_expr
.X_add_number
> 63)
8157 ip
->insn_opcode
|= (imm_expr
.X_add_number
- 32) << OP_SH_SHAMT
;
8158 imm_expr
.X_op
= O_absent
;
8162 case 'k': /* cache code */
8163 case 'h': /* prefx code */
8164 my_getExpression (&imm_expr
, s
);
8165 check_absolute_expr (ip
, &imm_expr
);
8166 if ((unsigned long) imm_expr
.X_add_number
> 31)
8168 as_warn (_("Invalid value for `%s' (%lu)"),
8170 (unsigned long) imm_expr
.X_add_number
);
8171 imm_expr
.X_add_number
&= 0x1f;
8174 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CACHE
;
8176 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_PREFX
;
8177 imm_expr
.X_op
= O_absent
;
8181 case 'c': /* break code */
8182 my_getExpression (&imm_expr
, s
);
8183 check_absolute_expr (ip
, &imm_expr
);
8184 if ((unsigned long) imm_expr
.X_add_number
> 1023)
8186 as_warn (_("Illegal break code (%lu)"),
8187 (unsigned long) imm_expr
.X_add_number
);
8188 imm_expr
.X_add_number
&= OP_MASK_CODE
;
8190 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE
;
8191 imm_expr
.X_op
= O_absent
;
8195 case 'q': /* lower break code */
8196 my_getExpression (&imm_expr
, s
);
8197 check_absolute_expr (ip
, &imm_expr
);
8198 if ((unsigned long) imm_expr
.X_add_number
> 1023)
8200 as_warn (_("Illegal lower break code (%lu)"),
8201 (unsigned long) imm_expr
.X_add_number
);
8202 imm_expr
.X_add_number
&= OP_MASK_CODE2
;
8204 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE2
;
8205 imm_expr
.X_op
= O_absent
;
8209 case 'B': /* 20-bit syscall/break code. */
8210 my_getExpression (&imm_expr
, s
);
8211 check_absolute_expr (ip
, &imm_expr
);
8212 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE20
)
8213 as_warn (_("Illegal 20-bit code (%lu)"),
8214 (unsigned long) imm_expr
.X_add_number
);
8215 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE20
;
8216 imm_expr
.X_op
= O_absent
;
8220 case 'C': /* Coprocessor code */
8221 my_getExpression (&imm_expr
, s
);
8222 check_absolute_expr (ip
, &imm_expr
);
8223 if ((unsigned long) imm_expr
.X_add_number
>= (1 << 25))
8225 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8226 (unsigned long) imm_expr
.X_add_number
);
8227 imm_expr
.X_add_number
&= ((1 << 25) - 1);
8229 ip
->insn_opcode
|= imm_expr
.X_add_number
;
8230 imm_expr
.X_op
= O_absent
;
8234 case 'J': /* 19-bit wait code. */
8235 my_getExpression (&imm_expr
, s
);
8236 check_absolute_expr (ip
, &imm_expr
);
8237 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE19
)
8238 as_warn (_("Illegal 19-bit code (%lu)"),
8239 (unsigned long) imm_expr
.X_add_number
);
8240 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE19
;
8241 imm_expr
.X_op
= O_absent
;
8245 case 'P': /* Performance register */
8246 my_getExpression (&imm_expr
, s
);
8247 check_absolute_expr (ip
, &imm_expr
);
8248 if (imm_expr
.X_add_number
!= 0 && imm_expr
.X_add_number
!= 1)
8250 as_warn (_("Invalid performance register (%lu)"),
8251 (unsigned long) imm_expr
.X_add_number
);
8252 imm_expr
.X_add_number
&= OP_MASK_PERFREG
;
8254 ip
->insn_opcode
|= (imm_expr
.X_add_number
<< OP_SH_PERFREG
);
8255 imm_expr
.X_op
= O_absent
;
8259 case 'b': /* base register */
8260 case 'd': /* destination register */
8261 case 's': /* source register */
8262 case 't': /* target register */
8263 case 'r': /* both target and source */
8264 case 'v': /* both dest and source */
8265 case 'w': /* both dest and target */
8266 case 'E': /* coprocessor target register */
8267 case 'G': /* coprocessor destination register */
8268 case 'x': /* ignore register name */
8269 case 'z': /* must be zero register */
8270 case 'U': /* destination register (clo/clz). */
8285 while (ISDIGIT (*s
));
8287 as_bad (_("Invalid register number (%d)"), regno
);
8289 else if (*args
== 'E' || *args
== 'G')
8293 if (s
[1] == 'r' && s
[2] == 'a')
8298 else if (s
[1] == 'f' && s
[2] == 'p')
8303 else if (s
[1] == 's' && s
[2] == 'p')
8308 else if (s
[1] == 'g' && s
[2] == 'p')
8313 else if (s
[1] == 'a' && s
[2] == 't')
8318 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '0')
8323 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '1')
8328 else if (s
[1] == 'z' && s
[2] == 'e' && s
[3] == 'r' && s
[4] == 'o')
8333 else if (itbl_have_entries
)
8338 p
= s
+ 1; /* advance past '$' */
8339 n
= itbl_get_field (&p
); /* n is name */
8341 /* See if this is a register defined in an
8343 if (itbl_get_reg_val (n
, &r
))
8345 /* Get_field advances to the start of
8346 the next field, so we need to back
8347 rack to the end of the last field. */
8351 s
= strchr (s
, '\0');
8364 as_warn (_("Used $at without \".set noat\""));
8370 if (c
== 'r' || c
== 'v' || c
== 'w')
8377 /* 'z' only matches $0. */
8378 if (c
== 'z' && regno
!= 0)
8381 /* Now that we have assembled one operand, we use the args string
8382 * to figure out where it goes in the instruction. */
8389 ip
->insn_opcode
|= regno
<< OP_SH_RS
;
8393 ip
->insn_opcode
|= regno
<< OP_SH_RD
;
8396 ip
->insn_opcode
|= regno
<< OP_SH_RD
;
8397 ip
->insn_opcode
|= regno
<< OP_SH_RT
;
8402 ip
->insn_opcode
|= regno
<< OP_SH_RT
;
8405 /* This case exists because on the r3000 trunc
8406 expands into a macro which requires a gp
8407 register. On the r6000 or r4000 it is
8408 assembled into a single instruction which
8409 ignores the register. Thus the insn version
8410 is MIPS_ISA2 and uses 'x', and the macro
8411 version is MIPS_ISA1 and uses 't'. */
8414 /* This case is for the div instruction, which
8415 acts differently if the destination argument
8416 is $0. This only matches $0, and is checked
8417 outside the switch. */
8420 /* Itbl operand; not yet implemented. FIXME ?? */
8422 /* What about all other operands like 'i', which
8423 can be specified in the opcode table? */
8433 ip
->insn_opcode
|= lastregno
<< OP_SH_RS
;
8436 ip
->insn_opcode
|= lastregno
<< OP_SH_RT
;
8441 case 'O': /* MDMX alignment immediate constant. */
8442 my_getExpression (&imm_expr
, s
);
8443 check_absolute_expr (ip
, &imm_expr
);
8444 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_ALN
)
8446 as_warn ("Improper align amount (%ld), using low bits",
8447 (long) imm_expr
.X_add_number
);
8448 imm_expr
.X_add_number
&= OP_MASK_ALN
;
8450 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_ALN
;
8451 imm_expr
.X_op
= O_absent
;
8455 case 'Q': /* MDMX vector, element sel, or const. */
8458 /* MDMX Immediate. */
8459 my_getExpression (&imm_expr
, s
);
8460 check_absolute_expr (ip
, &imm_expr
);
8461 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_FT
)
8463 as_warn (_("Invalid MDMX Immediate (%ld)"),
8464 (long) imm_expr
.X_add_number
);
8465 imm_expr
.X_add_number
&= OP_MASK_FT
;
8467 imm_expr
.X_add_number
&= OP_MASK_FT
;
8468 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
8469 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_QH
<< OP_SH_VSEL
;
8471 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_OB
<< OP_SH_VSEL
;
8472 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_FT
;
8473 imm_expr
.X_op
= O_absent
;
8477 /* Not MDMX Immediate. Fall through. */
8478 case 'X': /* MDMX destination register. */
8479 case 'Y': /* MDMX source register. */
8480 case 'Z': /* MDMX target register. */
8482 case 'D': /* floating point destination register */
8483 case 'S': /* floating point source register */
8484 case 'T': /* floating point target register */
8485 case 'R': /* floating point source register */
8489 /* Accept $fN for FP and MDMX register numbers, and in
8490 addition accept $vN for MDMX register numbers. */
8491 if ((s
[0] == '$' && s
[1] == 'f' && ISDIGIT (s
[2]))
8492 || (is_mdmx
!= 0 && s
[0] == '$' && s
[1] == 'v'
8503 while (ISDIGIT (*s
));
8506 as_bad (_("Invalid float register number (%d)"), regno
);
8508 if ((regno
& 1) != 0
8510 && ! (strcmp (str
, "mtc1") == 0
8511 || strcmp (str
, "mfc1") == 0
8512 || strcmp (str
, "lwc1") == 0
8513 || strcmp (str
, "swc1") == 0
8514 || strcmp (str
, "l.s") == 0
8515 || strcmp (str
, "s.s") == 0))
8516 as_warn (_("Float register should be even, was %d"),
8524 if (c
== 'V' || c
== 'W')
8535 ip
->insn_opcode
|= regno
<< OP_SH_FD
;
8540 ip
->insn_opcode
|= regno
<< OP_SH_FS
;
8543 /* This is like 'Z', but also needs to fix the MDMX
8544 vector/scalar select bits. Note that the
8545 scalar immediate case is handled above. */
8548 int is_qh
= (ip
->insn_opcode
& (1 << OP_SH_VSEL
));
8549 int max_el
= (is_qh
? 3 : 7);
8551 my_getExpression(&imm_expr
, s
);
8552 check_absolute_expr (ip
, &imm_expr
);
8554 if (imm_expr
.X_add_number
> max_el
)
8555 as_bad(_("Bad element selector %ld"),
8556 (long) imm_expr
.X_add_number
);
8557 imm_expr
.X_add_number
&= max_el
;
8558 ip
->insn_opcode
|= (imm_expr
.X_add_number
8562 as_warn(_("Expecting ']' found '%s'"), s
);
8568 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
8569 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_QH
8572 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_OB
<<
8579 ip
->insn_opcode
|= regno
<< OP_SH_FT
;
8582 ip
->insn_opcode
|= regno
<< OP_SH_FR
;
8592 ip
->insn_opcode
|= lastregno
<< OP_SH_FS
;
8595 ip
->insn_opcode
|= lastregno
<< OP_SH_FT
;
8601 my_getExpression (&imm_expr
, s
);
8602 if (imm_expr
.X_op
!= O_big
8603 && imm_expr
.X_op
!= O_constant
)
8604 insn_error
= _("absolute expression required");
8609 my_getExpression (&offset_expr
, s
);
8610 *imm_reloc
= BFD_RELOC_32
;
8623 unsigned char temp
[8];
8625 unsigned int length
;
8630 /* These only appear as the last operand in an
8631 instruction, and every instruction that accepts
8632 them in any variant accepts them in all variants.
8633 This means we don't have to worry about backing out
8634 any changes if the instruction does not match.
8636 The difference between them is the size of the
8637 floating point constant and where it goes. For 'F'
8638 and 'L' the constant is 64 bits; for 'f' and 'l' it
8639 is 32 bits. Where the constant is placed is based
8640 on how the MIPS assembler does things:
8643 f -- immediate value
8646 The .lit4 and .lit8 sections are only used if
8647 permitted by the -G argument.
8649 When generating embedded PIC code, we use the
8650 .lit8 section but not the .lit4 section (we can do
8651 .lit4 inline easily; we need to put .lit8
8652 somewhere in the data segment, and using .lit8
8653 permits the linker to eventually combine identical
8656 The code below needs to know whether the target register
8657 is 32 or 64 bits wide. It relies on the fact 'f' and
8658 'F' are used with GPR-based instructions and 'l' and
8659 'L' are used with FPR-based instructions. */
8661 f64
= *args
== 'F' || *args
== 'L';
8662 using_gprs
= *args
== 'F' || *args
== 'f';
8664 save_in
= input_line_pointer
;
8665 input_line_pointer
= s
;
8666 err
= md_atof (f64
? 'd' : 'f', (char *) temp
, &len
);
8668 s
= input_line_pointer
;
8669 input_line_pointer
= save_in
;
8670 if (err
!= NULL
&& *err
!= '\0')
8672 as_bad (_("Bad floating point constant: %s"), err
);
8673 memset (temp
, '\0', sizeof temp
);
8674 length
= f64
? 8 : 4;
8677 assert (length
== (unsigned) (f64
? 8 : 4));
8681 && (! USE_GLOBAL_POINTER_OPT
8682 || mips_pic
== EMBEDDED_PIC
8683 || g_switch_value
< 4
8684 || (temp
[0] == 0 && temp
[1] == 0)
8685 || (temp
[2] == 0 && temp
[3] == 0))))
8687 imm_expr
.X_op
= O_constant
;
8688 if (! target_big_endian
)
8689 imm_expr
.X_add_number
= bfd_getl32 (temp
);
8691 imm_expr
.X_add_number
= bfd_getb32 (temp
);
8694 && ! mips_disable_float_construction
8695 /* Constants can only be constructed in GPRs and
8696 copied to FPRs if the GPRs are at least as wide
8697 as the FPRs. Force the constant into memory if
8698 we are using 64-bit FPRs but the GPRs are only
8701 || ! (HAVE_64BIT_FPRS
&& HAVE_32BIT_GPRS
))
8702 && ((temp
[0] == 0 && temp
[1] == 0)
8703 || (temp
[2] == 0 && temp
[3] == 0))
8704 && ((temp
[4] == 0 && temp
[5] == 0)
8705 || (temp
[6] == 0 && temp
[7] == 0)))
8707 /* The value is simple enough to load with a couple of
8708 instructions. If using 32-bit registers, set
8709 imm_expr to the high order 32 bits and offset_expr to
8710 the low order 32 bits. Otherwise, set imm_expr to
8711 the entire 64 bit constant. */
8712 if (using_gprs
? HAVE_32BIT_GPRS
: HAVE_32BIT_FPRS
)
8714 imm_expr
.X_op
= O_constant
;
8715 offset_expr
.X_op
= O_constant
;
8716 if (! target_big_endian
)
8718 imm_expr
.X_add_number
= bfd_getl32 (temp
+ 4);
8719 offset_expr
.X_add_number
= bfd_getl32 (temp
);
8723 imm_expr
.X_add_number
= bfd_getb32 (temp
);
8724 offset_expr
.X_add_number
= bfd_getb32 (temp
+ 4);
8726 if (offset_expr
.X_add_number
== 0)
8727 offset_expr
.X_op
= O_absent
;
8729 else if (sizeof (imm_expr
.X_add_number
) > 4)
8731 imm_expr
.X_op
= O_constant
;
8732 if (! target_big_endian
)
8733 imm_expr
.X_add_number
= bfd_getl64 (temp
);
8735 imm_expr
.X_add_number
= bfd_getb64 (temp
);
8739 imm_expr
.X_op
= O_big
;
8740 imm_expr
.X_add_number
= 4;
8741 if (! target_big_endian
)
8743 generic_bignum
[0] = bfd_getl16 (temp
);
8744 generic_bignum
[1] = bfd_getl16 (temp
+ 2);
8745 generic_bignum
[2] = bfd_getl16 (temp
+ 4);
8746 generic_bignum
[3] = bfd_getl16 (temp
+ 6);
8750 generic_bignum
[0] = bfd_getb16 (temp
+ 6);
8751 generic_bignum
[1] = bfd_getb16 (temp
+ 4);
8752 generic_bignum
[2] = bfd_getb16 (temp
+ 2);
8753 generic_bignum
[3] = bfd_getb16 (temp
);
8759 const char *newname
;
8762 /* Switch to the right section. */
8764 subseg
= now_subseg
;
8767 default: /* unused default case avoids warnings. */
8769 newname
= RDATA_SECTION_NAME
;
8770 if ((USE_GLOBAL_POINTER_OPT
&& g_switch_value
>= 8)
8771 || mips_pic
== EMBEDDED_PIC
)
8775 if (mips_pic
== EMBEDDED_PIC
)
8778 newname
= RDATA_SECTION_NAME
;
8781 assert (!USE_GLOBAL_POINTER_OPT
8782 || g_switch_value
>= 4);
8786 new_seg
= subseg_new (newname
, (subsegT
) 0);
8787 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
8788 bfd_set_section_flags (stdoutput
, new_seg
,
8793 frag_align (*args
== 'l' ? 2 : 3, 0, 0);
8794 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
8795 && strcmp (TARGET_OS
, "elf") != 0)
8796 record_alignment (new_seg
, 4);
8798 record_alignment (new_seg
, *args
== 'l' ? 2 : 3);
8800 as_bad (_("Can't use floating point insn in this section"));
8802 /* Set the argument to the current address in the
8804 offset_expr
.X_op
= O_symbol
;
8805 offset_expr
.X_add_symbol
=
8806 symbol_new ("L0\001", now_seg
,
8807 (valueT
) frag_now_fix (), frag_now
);
8808 offset_expr
.X_add_number
= 0;
8810 /* Put the floating point number into the section. */
8811 p
= frag_more ((int) length
);
8812 memcpy (p
, temp
, length
);
8814 /* Switch back to the original section. */
8815 subseg_set (seg
, subseg
);
8820 case 'i': /* 16 bit unsigned immediate */
8821 case 'j': /* 16 bit signed immediate */
8822 *imm_reloc
= BFD_RELOC_LO16
;
8823 c
= my_getSmallExpression (&imm_expr
, s
);
8830 *imm_reloc
= BFD_RELOC_HI16_S
;
8831 imm_unmatched_hi
= true;
8834 else if (c
== S_EX_HIGHEST
)
8835 *imm_reloc
= BFD_RELOC_MIPS_HIGHEST
;
8836 else if (c
== S_EX_HIGHER
)
8837 *imm_reloc
= BFD_RELOC_MIPS_HIGHER
;
8838 else if (c
== S_EX_GP_REL
)
8840 /* This occurs in NewABI only. */
8841 c
= my_getSmallExpression (&imm_expr
, s
);
8843 as_bad (_("bad composition of relocations"));
8846 c
= my_getSmallExpression (&imm_expr
, s
);
8848 as_bad (_("bad composition of relocations"));
8851 imm_reloc
[0] = BFD_RELOC_GPREL16
;
8852 imm_reloc
[1] = BFD_RELOC_MIPS_SUB
;
8853 imm_reloc
[2] = BFD_RELOC_LO16
;
8859 *imm_reloc
= BFD_RELOC_HI16
;
8861 else if (imm_expr
.X_op
== O_constant
)
8862 imm_expr
.X_add_number
&= 0xffff;
8866 if ((c
== S_EX_NONE
&& imm_expr
.X_op
!= O_constant
)
8867 || ((imm_expr
.X_add_number
< 0
8868 || imm_expr
.X_add_number
>= 0x10000)
8869 && imm_expr
.X_op
== O_constant
))
8871 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
8872 !strcmp (insn
->name
, insn
[1].name
))
8874 if (imm_expr
.X_op
== O_constant
8875 || imm_expr
.X_op
== O_big
)
8876 as_bad (_("16 bit expression not in range 0..65535"));
8884 /* The upper bound should be 0x8000, but
8885 unfortunately the MIPS assembler accepts numbers
8886 from 0x8000 to 0xffff and sign extends them, and
8887 we want to be compatible. We only permit this
8888 extended range for an instruction which does not
8889 provide any further alternates, since those
8890 alternates may handle other cases. People should
8891 use the numbers they mean, rather than relying on
8892 a mysterious sign extension. */
8893 more
= (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
8894 strcmp (insn
->name
, insn
[1].name
) == 0);
8899 if ((c
== S_EX_NONE
&& imm_expr
.X_op
!= O_constant
)
8900 || ((imm_expr
.X_add_number
< -0x8000
8901 || imm_expr
.X_add_number
>= max
)
8902 && imm_expr
.X_op
== O_constant
)
8904 && imm_expr
.X_add_number
< 0
8906 && imm_expr
.X_unsigned
8907 && sizeof (imm_expr
.X_add_number
) <= 4))
8911 if (imm_expr
.X_op
== O_constant
8912 || imm_expr
.X_op
== O_big
)
8913 as_bad (_("16 bit expression not in range -32768..32767"));
8919 case 'o': /* 16 bit offset */
8920 c
= my_getSmallExpression (&offset_expr
, s
);
8922 /* If this value won't fit into a 16 bit offset, then go
8923 find a macro that will generate the 32 bit offset
8926 && (offset_expr
.X_op
!= O_constant
8927 || offset_expr
.X_add_number
>= 0x8000
8928 || offset_expr
.X_add_number
< -0x8000))
8933 if (offset_expr
.X_op
!= O_constant
)
8935 offset_expr
.X_add_number
=
8936 (offset_expr
.X_add_number
>> 16) & 0xffff;
8938 *offset_reloc
= BFD_RELOC_LO16
;
8942 case 'p': /* pc relative offset */
8943 if (mips_pic
== EMBEDDED_PIC
)
8944 *offset_reloc
= BFD_RELOC_16_PCREL_S2
;
8946 *offset_reloc
= BFD_RELOC_16_PCREL
;
8947 my_getExpression (&offset_expr
, s
);
8951 case 'u': /* upper 16 bits */
8952 c
= my_getSmallExpression (&imm_expr
, s
);
8953 *imm_reloc
= BFD_RELOC_LO16
;
8960 *imm_reloc
= BFD_RELOC_HI16_S
;
8961 imm_unmatched_hi
= true;
8964 else if (c
== S_EX_HIGHEST
)
8965 *imm_reloc
= BFD_RELOC_MIPS_HIGHEST
;
8966 else if (c
== S_EX_GP_REL
)
8968 /* This occurs in NewABI only. */
8969 c
= my_getSmallExpression (&imm_expr
, s
);
8971 as_bad (_("bad composition of relocations"));
8974 c
= my_getSmallExpression (&imm_expr
, s
);
8976 as_bad (_("bad composition of relocations"));
8979 imm_reloc
[0] = BFD_RELOC_GPREL16
;
8980 imm_reloc
[1] = BFD_RELOC_MIPS_SUB
;
8981 imm_reloc
[2] = BFD_RELOC_HI16_S
;
8987 *imm_reloc
= BFD_RELOC_HI16
;
8989 else if (imm_expr
.X_op
== O_constant
)
8990 imm_expr
.X_add_number
&= 0xffff;
8992 else if (imm_expr
.X_op
== O_constant
8993 && (imm_expr
.X_add_number
< 0
8994 || imm_expr
.X_add_number
>= 0x10000))
8995 as_bad (_("lui expression not in range 0..65535"));
8999 case 'a': /* 26 bit address */
9000 my_getExpression (&offset_expr
, s
);
9002 *offset_reloc
= BFD_RELOC_MIPS_JMP
;
9005 case 'N': /* 3 bit branch condition code */
9006 case 'M': /* 3 bit compare condition code */
9007 if (strncmp (s
, "$fcc", 4) != 0)
9017 while (ISDIGIT (*s
));
9019 as_bad (_("invalid condition code register $fcc%d"), regno
);
9021 ip
->insn_opcode
|= regno
<< OP_SH_BCC
;
9023 ip
->insn_opcode
|= regno
<< OP_SH_CCC
;
9027 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
9038 while (ISDIGIT (*s
));
9041 c
= 8; /* Invalid sel value. */
9044 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9045 ip
->insn_opcode
|= c
;
9049 /* Must be at least one digit. */
9050 my_getExpression (&imm_expr
, s
);
9051 check_absolute_expr (ip
, &imm_expr
);
9053 if ((unsigned long) imm_expr
.X_add_number
9054 > (unsigned long) OP_MASK_VECBYTE
)
9056 as_bad (_("bad byte vector index (%ld)"),
9057 (long) imm_expr
.X_add_number
);
9058 imm_expr
.X_add_number
= 0;
9061 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_VECBYTE
;
9062 imm_expr
.X_op
= O_absent
;
9067 my_getExpression (&imm_expr
, s
);
9068 check_absolute_expr (ip
, &imm_expr
);
9070 if ((unsigned long) imm_expr
.X_add_number
9071 > (unsigned long) OP_MASK_VECALIGN
)
9073 as_bad (_("bad byte vector index (%ld)"),
9074 (long) imm_expr
.X_add_number
);
9075 imm_expr
.X_add_number
= 0;
9078 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_VECALIGN
;
9079 imm_expr
.X_op
= O_absent
;
9084 as_bad (_("bad char = '%c'\n"), *args
);
9089 /* Args don't match. */
9090 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
9091 !strcmp (insn
->name
, insn
[1].name
))
9095 insn_error
= _("illegal operands");
9100 insn_error
= _("illegal operands");
9105 /* This routine assembles an instruction into its binary format when
9106 assembling for the mips16. As a side effect, it sets one of the
9107 global variables imm_reloc or offset_reloc to the type of
9108 relocation to do if one of the operands is an address expression.
9109 It also sets mips16_small and mips16_ext if the user explicitly
9110 requested a small or extended instruction. */
9115 struct mips_cl_insn
*ip
;
9119 struct mips_opcode
*insn
;
9122 unsigned int lastregno
= 0;
9127 mips16_small
= false;
9130 for (s
= str
; ISLOWER (*s
); ++s
)
9142 if (s
[1] == 't' && s
[2] == ' ')
9145 mips16_small
= true;
9149 else if (s
[1] == 'e' && s
[2] == ' ')
9158 insn_error
= _("unknown opcode");
9162 if (mips_opts
.noautoextend
&& ! mips16_ext
)
9163 mips16_small
= true;
9165 if ((insn
= (struct mips_opcode
*) hash_find (mips16_op_hash
, str
)) == NULL
)
9167 insn_error
= _("unrecognized opcode");
9174 assert (strcmp (insn
->name
, str
) == 0);
9177 ip
->insn_opcode
= insn
->match
;
9178 ip
->use_extend
= false;
9179 imm_expr
.X_op
= O_absent
;
9180 imm_reloc
[0] = BFD_RELOC_UNUSED
;
9181 imm_reloc
[1] = BFD_RELOC_UNUSED
;
9182 imm_reloc
[2] = BFD_RELOC_UNUSED
;
9183 offset_expr
.X_op
= O_absent
;
9184 offset_reloc
[0] = BFD_RELOC_UNUSED
;
9185 offset_reloc
[1] = BFD_RELOC_UNUSED
;
9186 offset_reloc
[2] = BFD_RELOC_UNUSED
;
9187 for (args
= insn
->args
; 1; ++args
)
9194 /* In this switch statement we call break if we did not find
9195 a match, continue if we did find a match, or return if we
9204 /* Stuff the immediate value in now, if we can. */
9205 if (imm_expr
.X_op
== O_constant
9206 && *imm_reloc
> BFD_RELOC_UNUSED
9207 && insn
->pinfo
!= INSN_MACRO
)
9209 mips16_immed (NULL
, 0, *imm_reloc
- BFD_RELOC_UNUSED
,
9210 imm_expr
.X_add_number
, true, mips16_small
,
9211 mips16_ext
, &ip
->insn_opcode
,
9212 &ip
->use_extend
, &ip
->extend
);
9213 imm_expr
.X_op
= O_absent
;
9214 *imm_reloc
= BFD_RELOC_UNUSED
;
9228 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RX
;
9231 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RY
;
9247 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RX
;
9249 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RY
;
9276 while (ISDIGIT (*s
));
9279 as_bad (_("invalid register number (%d)"), regno
);
9285 if (s
[1] == 'r' && s
[2] == 'a')
9290 else if (s
[1] == 'f' && s
[2] == 'p')
9295 else if (s
[1] == 's' && s
[2] == 'p')
9300 else if (s
[1] == 'g' && s
[2] == 'p')
9305 else if (s
[1] == 'a' && s
[2] == 't')
9310 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '0')
9315 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '1')
9320 else if (s
[1] == 'z' && s
[2] == 'e' && s
[3] == 'r' && s
[4] == 'o')
9333 if (c
== 'v' || c
== 'w')
9335 regno
= mips16_to_32_reg_map
[lastregno
];
9349 regno
= mips32_to_16_reg_map
[regno
];
9354 regno
= ILLEGAL_REG
;
9359 regno
= ILLEGAL_REG
;
9364 regno
= ILLEGAL_REG
;
9369 if (regno
== AT
&& ! mips_opts
.noat
)
9370 as_warn (_("used $at without \".set noat\""));
9377 if (regno
== ILLEGAL_REG
)
9384 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RX
;
9388 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RY
;
9391 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RZ
;
9394 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_MOVE32Z
;
9400 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_REGR32
;
9403 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
9404 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_REG32R
;
9414 if (strncmp (s
, "$pc", 3) == 0)
9438 && strncmp (s
+ 1, "gprel(", sizeof "gprel(" - 1) == 0)
9440 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9441 and generate the appropriate reloc. If the text
9442 inside %gprel is not a symbol name with an
9443 optional offset, then we generate a normal reloc
9444 and will probably fail later. */
9445 my_getExpression (&imm_expr
, s
+ sizeof "%gprel" - 1);
9446 if (imm_expr
.X_op
== O_symbol
)
9449 *imm_reloc
= BFD_RELOC_MIPS16_GPREL
;
9451 ip
->use_extend
= true;
9458 /* Just pick up a normal expression. */
9459 my_getExpression (&imm_expr
, s
);
9462 if (imm_expr
.X_op
== O_register
)
9464 /* What we thought was an expression turned out to
9467 if (s
[0] == '(' && args
[1] == '(')
9469 /* It looks like the expression was omitted
9470 before a register indirection, which means
9471 that the expression is implicitly zero. We
9472 still set up imm_expr, so that we handle
9473 explicit extensions correctly. */
9474 imm_expr
.X_op
= O_constant
;
9475 imm_expr
.X_add_number
= 0;
9476 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9483 /* We need to relax this instruction. */
9484 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9493 /* We use offset_reloc rather than imm_reloc for the PC
9494 relative operands. This lets macros with both
9495 immediate and address operands work correctly. */
9496 my_getExpression (&offset_expr
, s
);
9498 if (offset_expr
.X_op
== O_register
)
9501 /* We need to relax this instruction. */
9502 *offset_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9506 case '6': /* break code */
9507 my_getExpression (&imm_expr
, s
);
9508 check_absolute_expr (ip
, &imm_expr
);
9509 if ((unsigned long) imm_expr
.X_add_number
> 63)
9511 as_warn (_("Invalid value for `%s' (%lu)"),
9513 (unsigned long) imm_expr
.X_add_number
);
9514 imm_expr
.X_add_number
&= 0x3f;
9516 ip
->insn_opcode
|= imm_expr
.X_add_number
<< MIPS16OP_SH_IMM6
;
9517 imm_expr
.X_op
= O_absent
;
9521 case 'a': /* 26 bit address */
9522 my_getExpression (&offset_expr
, s
);
9524 *offset_reloc
= BFD_RELOC_MIPS16_JMP
;
9525 ip
->insn_opcode
<<= 16;
9528 case 'l': /* register list for entry macro */
9529 case 'L': /* register list for exit macro */
9539 int freg
, reg1
, reg2
;
9541 while (*s
== ' ' || *s
== ',')
9545 as_bad (_("can't parse register list"));
9557 while (ISDIGIT (*s
))
9579 as_bad (_("invalid register list"));
9584 while (ISDIGIT (*s
))
9591 if (freg
&& reg1
== 0 && reg2
== 0 && c
== 'L')
9596 else if (freg
&& reg1
== 0 && reg2
== 1 && c
== 'L')
9601 else if (reg1
== 4 && reg2
>= 4 && reg2
<= 7 && c
!= 'L')
9602 mask
|= (reg2
- 3) << 3;
9603 else if (reg1
== 16 && reg2
>= 16 && reg2
<= 17)
9604 mask
|= (reg2
- 15) << 1;
9605 else if (reg1
== RA
&& reg2
== RA
)
9609 as_bad (_("invalid register list"));
9613 /* The mask is filled in in the opcode table for the
9614 benefit of the disassembler. We remove it before
9615 applying the actual mask. */
9616 ip
->insn_opcode
&= ~ ((7 << 3) << MIPS16OP_SH_IMM6
);
9617 ip
->insn_opcode
|= mask
<< MIPS16OP_SH_IMM6
;
9621 case 'e': /* extend code */
9622 my_getExpression (&imm_expr
, s
);
9623 check_absolute_expr (ip
, &imm_expr
);
9624 if ((unsigned long) imm_expr
.X_add_number
> 0x7ff)
9626 as_warn (_("Invalid value for `%s' (%lu)"),
9628 (unsigned long) imm_expr
.X_add_number
);
9629 imm_expr
.X_add_number
&= 0x7ff;
9631 ip
->insn_opcode
|= imm_expr
.X_add_number
;
9632 imm_expr
.X_op
= O_absent
;
9642 /* Args don't match. */
9643 if (insn
+ 1 < &mips16_opcodes
[bfd_mips16_num_opcodes
] &&
9644 strcmp (insn
->name
, insn
[1].name
) == 0)
9651 insn_error
= _("illegal operands");
9657 /* This structure holds information we know about a mips16 immediate
9660 struct mips16_immed_operand
9662 /* The type code used in the argument string in the opcode table. */
9664 /* The number of bits in the short form of the opcode. */
9666 /* The number of bits in the extended form of the opcode. */
9668 /* The amount by which the short form is shifted when it is used;
9669 for example, the sw instruction has a shift count of 2. */
9671 /* The amount by which the short form is shifted when it is stored
9672 into the instruction code. */
9674 /* Non-zero if the short form is unsigned. */
9676 /* Non-zero if the extended form is unsigned. */
9678 /* Non-zero if the value is PC relative. */
9682 /* The mips16 immediate operand types. */
9684 static const struct mips16_immed_operand mips16_immed_operands
[] =
9686 { '<', 3, 5, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
9687 { '>', 3, 5, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
9688 { '[', 3, 6, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
9689 { ']', 3, 6, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
9690 { '4', 4, 15, 0, MIPS16OP_SH_IMM4
, 0, 0, 0 },
9691 { '5', 5, 16, 0, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9692 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9693 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9694 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9695 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5
, 0, 0, 0 },
9696 { '8', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9697 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9698 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9699 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 1, 0 },
9700 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 0 },
9701 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8
, 0, 0, 0 },
9702 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
9703 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
9704 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 1 },
9705 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 1 },
9706 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 1 }
9709 #define MIPS16_NUM_IMMED \
9710 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9712 /* Handle a mips16 instruction with an immediate value. This or's the
9713 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9714 whether an extended value is needed; if one is needed, it sets
9715 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9716 If SMALL is true, an unextended opcode was explicitly requested.
9717 If EXT is true, an extended opcode was explicitly requested. If
9718 WARN is true, warn if EXT does not match reality. */
9721 mips16_immed (file
, line
, type
, val
, warn
, small
, ext
, insn
, use_extend
,
9730 unsigned long *insn
;
9731 boolean
*use_extend
;
9732 unsigned short *extend
;
9734 register const struct mips16_immed_operand
*op
;
9735 int mintiny
, maxtiny
;
9738 op
= mips16_immed_operands
;
9739 while (op
->type
!= type
)
9742 assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
9747 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
9750 maxtiny
= 1 << op
->nbits
;
9755 maxtiny
= (1 << op
->nbits
) - 1;
9760 mintiny
= - (1 << (op
->nbits
- 1));
9761 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
9764 /* Branch offsets have an implicit 0 in the lowest bit. */
9765 if (type
== 'p' || type
== 'q')
9768 if ((val
& ((1 << op
->shift
) - 1)) != 0
9769 || val
< (mintiny
<< op
->shift
)
9770 || val
> (maxtiny
<< op
->shift
))
9775 if (warn
&& ext
&& ! needext
)
9776 as_warn_where (file
, line
,
9777 _("extended operand requested but not required"));
9778 if (small
&& needext
)
9779 as_bad_where (file
, line
, _("invalid unextended operand value"));
9781 if (small
|| (! ext
&& ! needext
))
9785 *use_extend
= false;
9786 insnval
= ((val
>> op
->shift
) & ((1 << op
->nbits
) - 1));
9787 insnval
<<= op
->op_shift
;
9792 long minext
, maxext
;
9798 maxext
= (1 << op
->extbits
) - 1;
9802 minext
= - (1 << (op
->extbits
- 1));
9803 maxext
= (1 << (op
->extbits
- 1)) - 1;
9805 if (val
< minext
|| val
> maxext
)
9806 as_bad_where (file
, line
,
9807 _("operand value out of range for instruction"));
9810 if (op
->extbits
== 16)
9812 extval
= ((val
>> 11) & 0x1f) | (val
& 0x7e0);
9815 else if (op
->extbits
== 15)
9817 extval
= ((val
>> 11) & 0xf) | (val
& 0x7f0);
9822 extval
= ((val
& 0x1f) << 6) | (val
& 0x20);
9826 *extend
= (unsigned short) extval
;
9831 static struct percent_op_match
9834 const enum small_ex_type type
;
9839 {"%call_hi", S_EX_CALL_HI
},
9840 {"%call_lo", S_EX_CALL_LO
},
9841 {"%call16", S_EX_CALL16
},
9842 {"%got_disp", S_EX_GOT_DISP
},
9843 {"%got_page", S_EX_GOT_PAGE
},
9844 {"%got_ofst", S_EX_GOT_OFST
},
9845 {"%got_hi", S_EX_GOT_HI
},
9846 {"%got_lo", S_EX_GOT_LO
},
9848 {"%gp_rel", S_EX_GP_REL
},
9849 {"%half", S_EX_HALF
},
9850 {"%highest", S_EX_HIGHEST
},
9851 {"%higher", S_EX_HIGHER
},
9857 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9858 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9859 can be nested, this is handled by blanking the innermost, parsing the
9860 rest by subsequent calls. */
9863 my_getSmallParser (str
, len
, nestlevel
)
9869 *str
+= strspn (*str
, " \t");
9870 /* Check for expression in parentheses. */
9873 char *b
= *str
+ 1 + strspn (*str
+ 1, " \t");
9876 /* Check for base register. */
9880 && (e
= b
+ strcspn (b
, ") \t"))
9881 && e
- b
> 1 && e
- b
< 4)
9884 && ((b
[1] == 'f' && b
[2] == 'p')
9885 || (b
[1] == 's' && b
[2] == 'p')
9886 || (b
[1] == 'g' && b
[2] == 'p')
9887 || (b
[1] == 'a' && b
[2] == 't')
9889 && ISDIGIT (b
[2]))))
9890 || (ISDIGIT (b
[1])))
9892 *len
= strcspn (*str
, ")") + 1;
9893 return S_EX_REGISTER
;
9897 /* Check for percent_op (in parentheses). */
9898 else if (b
[0] == '%')
9901 return my_getPercentOp (str
, len
, nestlevel
);
9904 /* Some other expression in the parentheses, which can contain
9905 parentheses itself. Attempt to find the matching one. */
9911 for (s
= *str
+ 1; *s
&& pcnt
; s
++, (*len
)++)
9920 /* Check for percent_op (outside of parentheses). */
9921 else if (*str
[0] == '%')
9922 return my_getPercentOp (str
, len
, nestlevel
);
9924 /* Any other expression. */
9929 my_getPercentOp (str
, len
, nestlevel
)
9934 char *tmp
= *str
+ 1;
9937 while (ISALPHA (*tmp
) || *tmp
== '_')
9939 *tmp
= TOLOWER (*tmp
);
9942 while (i
< (sizeof (percent_op
) / sizeof (struct percent_op_match
)))
9944 if (strncmp (*str
, percent_op
[i
].str
, strlen (percent_op
[i
].str
)))
9948 int type
= percent_op
[i
].type
;
9950 /* Only %hi and %lo are allowed for OldABI. */
9951 if (! HAVE_NEWABI
&& type
!= S_EX_HI
&& type
!= S_EX_LO
)
9954 *len
= strlen (percent_op
[i
].str
);
9963 my_getSmallExpression (ep
, str
)
9967 static char *oldstr
= NULL
;
9973 /* Don't update oldstr if the last call had nested percent_op's. We need
9974 it to parse the outer ones later. */
9981 c
= my_getSmallParser (&str
, &len
, &nestlevel
);
9982 if (c
!= S_EX_NONE
&& c
!= S_EX_REGISTER
)
9985 while (c
!= S_EX_NONE
&& c
!= S_EX_REGISTER
);
9989 /* A percent_op was encountered. Don't try to get an expression if
9990 it is already blanked out. */
9991 if (*(str
+ strspn (str
+ 1, " )")) != ')')
9995 /* Let my_getExpression() stop at the closing parenthesis. */
9996 save
= *(str
+ len
);
9997 *(str
+ len
) = '\0';
9998 my_getExpression (ep
, str
);
9999 *(str
+ len
) = save
;
10003 /* Blank out including the % sign and the proper matching
10006 char *s
= strrchr (oldstr
, '%');
10009 for (end
= strchr (s
, '(') + 1; *end
&& pcnt
; end
++)
10013 else if (*end
== ')')
10017 memset (s
, ' ', end
- s
);
10021 expr_end
= str
+ len
;
10025 else if (c
== S_EX_NONE
)
10027 my_getExpression (ep
, str
);
10029 else if (c
== S_EX_REGISTER
)
10031 ep
->X_op
= O_constant
;
10033 ep
->X_add_symbol
= NULL
;
10034 ep
->X_op_symbol
= NULL
;
10035 ep
->X_add_number
= 0;
10039 as_fatal (_("internal error"));
10042 if (nestlevel
<= 0)
10043 /* All percent_op's have been handled. */
10050 my_getExpression (ep
, str
)
10057 save_in
= input_line_pointer
;
10058 input_line_pointer
= str
;
10060 expr_end
= input_line_pointer
;
10061 input_line_pointer
= save_in
;
10063 /* If we are in mips16 mode, and this is an expression based on `.',
10064 then we bump the value of the symbol by 1 since that is how other
10065 text symbols are handled. We don't bother to handle complex
10066 expressions, just `.' plus or minus a constant. */
10067 if (mips_opts
.mips16
10068 && ep
->X_op
== O_symbol
10069 && strcmp (S_GET_NAME (ep
->X_add_symbol
), FAKE_LABEL_NAME
) == 0
10070 && S_GET_SEGMENT (ep
->X_add_symbol
) == now_seg
10071 && symbol_get_frag (ep
->X_add_symbol
) == frag_now
10072 && symbol_constant_p (ep
->X_add_symbol
)
10073 && (val
= S_GET_VALUE (ep
->X_add_symbol
)) == frag_now_fix ())
10074 S_SET_VALUE (ep
->X_add_symbol
, val
+ 1);
10077 /* Turn a string in input_line_pointer into a floating point constant
10078 of type TYPE, and store the appropriate bytes in *LITP. The number
10079 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10080 returned, or NULL on OK. */
10083 md_atof (type
, litP
, sizeP
)
10089 LITTLENUM_TYPE words
[4];
10105 return _("bad call to md_atof");
10108 t
= atof_ieee (input_line_pointer
, type
, words
);
10110 input_line_pointer
= t
;
10114 if (! target_big_endian
)
10116 for (i
= prec
- 1; i
>= 0; i
--)
10118 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
10124 for (i
= 0; i
< prec
; i
++)
10126 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
10135 md_number_to_chars (buf
, val
, n
)
10140 if (target_big_endian
)
10141 number_to_chars_bigendian (buf
, val
, n
);
10143 number_to_chars_littleendian (buf
, val
, n
);
10147 static int support_64bit_objects(void)
10149 const char **list
, **l
;
10151 list
= bfd_target_list ();
10152 for (l
= list
; *l
!= NULL
; l
++)
10154 /* This is traditional mips */
10155 if (strcmp (*l
, "elf64-tradbigmips") == 0
10156 || strcmp (*l
, "elf64-tradlittlemips") == 0)
10158 if (strcmp (*l
, "elf64-bigmips") == 0
10159 || strcmp (*l
, "elf64-littlemips") == 0)
10163 return (*l
!= NULL
);
10165 #endif /* OBJ_ELF */
10167 const char *md_shortopts
= "nO::g::G:";
10169 struct option md_longopts
[] =
10171 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
10172 {"mips0", no_argument
, NULL
, OPTION_MIPS1
},
10173 {"mips1", no_argument
, NULL
, OPTION_MIPS1
},
10174 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
10175 {"mips2", no_argument
, NULL
, OPTION_MIPS2
},
10176 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
10177 {"mips3", no_argument
, NULL
, OPTION_MIPS3
},
10178 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
10179 {"mips4", no_argument
, NULL
, OPTION_MIPS4
},
10180 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
10181 {"mips5", no_argument
, NULL
, OPTION_MIPS5
},
10182 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
10183 {"mips32", no_argument
, NULL
, OPTION_MIPS32
},
10184 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
10185 {"mips64", no_argument
, NULL
, OPTION_MIPS64
},
10186 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
10187 {"membedded-pic", no_argument
, NULL
, OPTION_MEMBEDDED_PIC
},
10188 #define OPTION_TRAP (OPTION_MD_BASE + 9)
10189 {"trap", no_argument
, NULL
, OPTION_TRAP
},
10190 {"no-break", no_argument
, NULL
, OPTION_TRAP
},
10191 #define OPTION_BREAK (OPTION_MD_BASE + 10)
10192 {"break", no_argument
, NULL
, OPTION_BREAK
},
10193 {"no-trap", no_argument
, NULL
, OPTION_BREAK
},
10194 #define OPTION_EB (OPTION_MD_BASE + 11)
10195 {"EB", no_argument
, NULL
, OPTION_EB
},
10196 #define OPTION_EL (OPTION_MD_BASE + 12)
10197 {"EL", no_argument
, NULL
, OPTION_EL
},
10198 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
10199 {"mips16", no_argument
, NULL
, OPTION_MIPS16
},
10200 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
10201 {"no-mips16", no_argument
, NULL
, OPTION_NO_MIPS16
},
10202 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
10203 {"mfix7000", no_argument
, NULL
, OPTION_M7000_HILO_FIX
},
10204 #define OPTION_MNO_7000_HILO_FIX (OPTION_MD_BASE + 16)
10205 {"no-fix-7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
10206 {"mno-fix7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
10207 #define OPTION_FP32 (OPTION_MD_BASE + 17)
10208 {"mfp32", no_argument
, NULL
, OPTION_FP32
},
10209 #define OPTION_GP32 (OPTION_MD_BASE + 18)
10210 {"mgp32", no_argument
, NULL
, OPTION_GP32
},
10211 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
10212 {"construct-floats", no_argument
, NULL
, OPTION_CONSTRUCT_FLOATS
},
10213 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
10214 {"no-construct-floats", no_argument
, NULL
, OPTION_NO_CONSTRUCT_FLOATS
},
10215 #define OPTION_MARCH (OPTION_MD_BASE + 21)
10216 {"march", required_argument
, NULL
, OPTION_MARCH
},
10217 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
10218 {"mtune", required_argument
, NULL
, OPTION_MTUNE
},
10219 #define OPTION_FP64 (OPTION_MD_BASE + 23)
10220 {"mfp64", no_argument
, NULL
, OPTION_FP64
},
10221 #define OPTION_M4650 (OPTION_MD_BASE + 24)
10222 {"m4650", no_argument
, NULL
, OPTION_M4650
},
10223 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
10224 {"no-m4650", no_argument
, NULL
, OPTION_NO_M4650
},
10225 #define OPTION_M4010 (OPTION_MD_BASE + 26)
10226 {"m4010", no_argument
, NULL
, OPTION_M4010
},
10227 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
10228 {"no-m4010", no_argument
, NULL
, OPTION_NO_M4010
},
10229 #define OPTION_M4100 (OPTION_MD_BASE + 28)
10230 {"m4100", no_argument
, NULL
, OPTION_M4100
},
10231 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
10232 {"no-m4100", no_argument
, NULL
, OPTION_NO_M4100
},
10233 #define OPTION_M3900 (OPTION_MD_BASE + 30)
10234 {"m3900", no_argument
, NULL
, OPTION_M3900
},
10235 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
10236 {"no-m3900", no_argument
, NULL
, OPTION_NO_M3900
},
10237 #define OPTION_GP64 (OPTION_MD_BASE + 32)
10238 {"mgp64", no_argument
, NULL
, OPTION_GP64
},
10239 #define OPTION_MIPS3D (OPTION_MD_BASE + 33)
10240 {"mips3d", no_argument
, NULL
, OPTION_MIPS3D
},
10241 #define OPTION_NO_MIPS3D (OPTION_MD_BASE + 34)
10242 {"no-mips3d", no_argument
, NULL
, OPTION_NO_MIPS3D
},
10243 #define OPTION_MDMX (OPTION_MD_BASE + 35)
10244 {"mdmx", no_argument
, NULL
, OPTION_MDMX
},
10245 #define OPTION_NO_MDMX (OPTION_MD_BASE + 36)
10246 {"no-mdmx", no_argument
, NULL
, OPTION_NO_MDMX
},
10247 #define OPTION_FIX_VR4122 (OPTION_MD_BASE + 37)
10248 #define OPTION_NO_FIX_VR4122 (OPTION_MD_BASE + 38)
10249 {"mfix-vr4122-bugs", no_argument
, NULL
, OPTION_FIX_VR4122
},
10250 {"no-mfix-vr4122-bugs", no_argument
, NULL
, OPTION_NO_FIX_VR4122
},
10251 #define OPTION_RELAX_BRANCH (OPTION_MD_BASE + 39)
10252 #define OPTION_NO_RELAX_BRANCH (OPTION_MD_BASE + 40)
10253 {"relax-branch", no_argument
, NULL
, OPTION_RELAX_BRANCH
},
10254 {"no-relax-branch", no_argument
, NULL
, OPTION_NO_RELAX_BRANCH
},
10256 #define OPTION_ELF_BASE (OPTION_MD_BASE + 41)
10257 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10258 {"KPIC", no_argument
, NULL
, OPTION_CALL_SHARED
},
10259 {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
10260 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10261 {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
10262 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10263 {"xgot", no_argument
, NULL
, OPTION_XGOT
},
10264 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10265 {"mabi", required_argument
, NULL
, OPTION_MABI
},
10266 #define OPTION_32 (OPTION_ELF_BASE + 4)
10267 {"32", no_argument
, NULL
, OPTION_32
},
10268 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10269 {"n32", no_argument
, NULL
, OPTION_N32
},
10270 #define OPTION_64 (OPTION_ELF_BASE + 6)
10271 {"64", no_argument
, NULL
, OPTION_64
},
10272 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10273 {"mdebug", no_argument
, NULL
, OPTION_MDEBUG
},
10274 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10275 {"no-mdebug", no_argument
, NULL
, OPTION_NO_MDEBUG
},
10276 #endif /* OBJ_ELF */
10277 {NULL
, no_argument
, NULL
, 0}
10279 size_t md_longopts_size
= sizeof (md_longopts
);
10281 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10282 NEW_VALUE. Warn if another value was already specified. Note:
10283 we have to defer parsing the -march and -mtune arguments in order
10284 to handle 'from-abi' correctly, since the ABI might be specified
10285 in a later argument. */
10288 mips_set_option_string (string_ptr
, new_value
)
10289 const char **string_ptr
, *new_value
;
10291 if (*string_ptr
!= 0 && strcasecmp (*string_ptr
, new_value
) != 0)
10292 as_warn (_("A different %s was already specified, is now %s"),
10293 string_ptr
== &mips_arch_string
? "-march" : "-mtune",
10296 *string_ptr
= new_value
;
10300 md_parse_option (c
, arg
)
10306 case OPTION_CONSTRUCT_FLOATS
:
10307 mips_disable_float_construction
= 0;
10310 case OPTION_NO_CONSTRUCT_FLOATS
:
10311 mips_disable_float_construction
= 1;
10323 target_big_endian
= 1;
10327 target_big_endian
= 0;
10335 if (arg
&& arg
[1] == '0')
10345 mips_debug
= atoi (arg
);
10346 /* When the MIPS assembler sees -g or -g2, it does not do
10347 optimizations which limit full symbolic debugging. We take
10348 that to be equivalent to -O0. */
10349 if (mips_debug
== 2)
10354 file_mips_isa
= ISA_MIPS1
;
10358 file_mips_isa
= ISA_MIPS2
;
10362 file_mips_isa
= ISA_MIPS3
;
10366 file_mips_isa
= ISA_MIPS4
;
10370 file_mips_isa
= ISA_MIPS5
;
10373 case OPTION_MIPS32
:
10374 file_mips_isa
= ISA_MIPS32
;
10377 case OPTION_MIPS64
:
10378 file_mips_isa
= ISA_MIPS64
;
10382 mips_set_option_string (&mips_tune_string
, arg
);
10386 mips_set_option_string (&mips_arch_string
, arg
);
10390 mips_set_option_string (&mips_arch_string
, "4650");
10391 mips_set_option_string (&mips_tune_string
, "4650");
10394 case OPTION_NO_M4650
:
10398 mips_set_option_string (&mips_arch_string
, "4010");
10399 mips_set_option_string (&mips_tune_string
, "4010");
10402 case OPTION_NO_M4010
:
10406 mips_set_option_string (&mips_arch_string
, "4100");
10407 mips_set_option_string (&mips_tune_string
, "4100");
10410 case OPTION_NO_M4100
:
10414 mips_set_option_string (&mips_arch_string
, "3900");
10415 mips_set_option_string (&mips_tune_string
, "3900");
10418 case OPTION_NO_M3900
:
10422 mips_opts
.ase_mdmx
= 1;
10425 case OPTION_NO_MDMX
:
10426 mips_opts
.ase_mdmx
= 0;
10429 case OPTION_MIPS16
:
10430 mips_opts
.mips16
= 1;
10431 mips_no_prev_insn (false);
10434 case OPTION_NO_MIPS16
:
10435 mips_opts
.mips16
= 0;
10436 mips_no_prev_insn (false);
10439 case OPTION_MIPS3D
:
10440 mips_opts
.ase_mips3d
= 1;
10443 case OPTION_NO_MIPS3D
:
10444 mips_opts
.ase_mips3d
= 0;
10447 case OPTION_MEMBEDDED_PIC
:
10448 mips_pic
= EMBEDDED_PIC
;
10449 if (USE_GLOBAL_POINTER_OPT
&& g_switch_seen
)
10451 as_bad (_("-G may not be used with embedded PIC code"));
10454 g_switch_value
= 0x7fffffff;
10457 case OPTION_FIX_VR4122
:
10458 mips_fix_4122_bugs
= 1;
10461 case OPTION_NO_FIX_VR4122
:
10462 mips_fix_4122_bugs
= 0;
10465 case OPTION_RELAX_BRANCH
:
10466 mips_relax_branch
= 1;
10469 case OPTION_NO_RELAX_BRANCH
:
10470 mips_relax_branch
= 0;
10474 /* When generating ELF code, we permit -KPIC and -call_shared to
10475 select SVR4_PIC, and -non_shared to select no PIC. This is
10476 intended to be compatible with Irix 5. */
10477 case OPTION_CALL_SHARED
:
10478 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10480 as_bad (_("-call_shared is supported only for ELF format"));
10483 mips_pic
= SVR4_PIC
;
10484 if (g_switch_seen
&& g_switch_value
!= 0)
10486 as_bad (_("-G may not be used with SVR4 PIC code"));
10489 g_switch_value
= 0;
10492 case OPTION_NON_SHARED
:
10493 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10495 as_bad (_("-non_shared is supported only for ELF format"));
10501 /* The -xgot option tells the assembler to use 32 offsets when
10502 accessing the got in SVR4_PIC mode. It is for Irix
10507 #endif /* OBJ_ELF */
10510 if (! USE_GLOBAL_POINTER_OPT
)
10512 as_bad (_("-G is not supported for this configuration"));
10515 else if (mips_pic
== SVR4_PIC
|| mips_pic
== EMBEDDED_PIC
)
10517 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10521 g_switch_value
= atoi (arg
);
10526 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10529 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10531 as_bad (_("-32 is supported for ELF format only"));
10534 mips_abi
= O32_ABI
;
10538 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10540 as_bad (_("-n32 is supported for ELF format only"));
10543 mips_abi
= N32_ABI
;
10547 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10549 as_bad (_("-64 is supported for ELF format only"));
10552 mips_abi
= N64_ABI
;
10553 if (! support_64bit_objects())
10554 as_fatal (_("No compiled in support for 64 bit object file format"));
10556 #endif /* OBJ_ELF */
10559 file_mips_gp32
= 1;
10563 file_mips_gp32
= 0;
10567 file_mips_fp32
= 1;
10571 file_mips_fp32
= 0;
10576 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10578 as_bad (_("-mabi is supported for ELF format only"));
10581 if (strcmp (arg
, "32") == 0)
10582 mips_abi
= O32_ABI
;
10583 else if (strcmp (arg
, "o64") == 0)
10584 mips_abi
= O64_ABI
;
10585 else if (strcmp (arg
, "n32") == 0)
10586 mips_abi
= N32_ABI
;
10587 else if (strcmp (arg
, "64") == 0)
10589 mips_abi
= N64_ABI
;
10590 if (! support_64bit_objects())
10591 as_fatal (_("No compiled in support for 64 bit object file "
10594 else if (strcmp (arg
, "eabi") == 0)
10595 mips_abi
= EABI_ABI
;
10598 as_fatal (_("invalid abi -mabi=%s"), arg
);
10602 #endif /* OBJ_ELF */
10604 case OPTION_M7000_HILO_FIX
:
10605 mips_7000_hilo_fix
= true;
10608 case OPTION_MNO_7000_HILO_FIX
:
10609 mips_7000_hilo_fix
= false;
10613 case OPTION_MDEBUG
:
10614 mips_flag_mdebug
= true;
10617 case OPTION_NO_MDEBUG
:
10618 mips_flag_mdebug
= false;
10620 #endif /* OBJ_ELF */
10629 /* Set up globals to generate code for the ISA or processor
10630 described by INFO. */
10633 mips_set_architecture (info
)
10634 const struct mips_cpu_info
*info
;
10638 mips_arch_info
= info
;
10639 mips_arch
= info
->cpu
;
10640 mips_opts
.isa
= info
->isa
;
10645 /* Likewise for tuning. */
10648 mips_set_tune (info
)
10649 const struct mips_cpu_info
*info
;
10653 mips_tune_info
= info
;
10654 mips_tune
= info
->cpu
;
10660 mips_after_parse_args ()
10662 /* GP relative stuff not working for PE */
10663 if (strncmp (TARGET_OS
, "pe", 2) == 0
10664 && g_switch_value
!= 0)
10667 as_bad (_("-G not supported in this configuration."));
10668 g_switch_value
= 0;
10671 /* The following code determines the architecture and register size.
10672 Similar code was added to GCC 3.3 (see override_options() in
10673 config/mips/mips.c). The GAS and GCC code should be kept in sync
10674 as much as possible. */
10676 if (mips_arch_string
!= 0)
10677 mips_set_architecture (mips_parse_cpu ("-march", mips_arch_string
));
10679 if (mips_tune_string
!= 0)
10680 mips_set_tune (mips_parse_cpu ("-mtune", mips_tune_string
));
10682 if (file_mips_isa
!= ISA_UNKNOWN
)
10684 /* Handle -mipsN. At this point, file_mips_isa contains the
10685 ISA level specified by -mipsN, while mips_opts.isa contains
10686 the -march selection (if any). */
10687 if (mips_arch_info
!= 0)
10689 /* -march takes precedence over -mipsN, since it is more descriptive.
10690 There's no harm in specifying both as long as the ISA levels
10692 if (file_mips_isa
!= mips_opts
.isa
)
10693 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
10694 mips_cpu_info_from_isa (file_mips_isa
)->name
,
10695 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
10698 mips_set_architecture (mips_cpu_info_from_isa (file_mips_isa
));
10701 if (mips_arch_info
== 0)
10702 mips_set_architecture (mips_parse_cpu ("default CPU",
10703 MIPS_CPU_STRING_DEFAULT
));
10705 if (ABI_NEEDS_64BIT_REGS (mips_abi
) && !ISA_HAS_64BIT_REGS (mips_opts
.isa
))
10706 as_bad ("-march=%s is not compatible with the selected ABI",
10707 mips_arch_info
->name
);
10709 /* Optimize for mips_arch, unless -mtune selects a different processor. */
10710 if (mips_tune_info
== 0)
10711 mips_set_tune (mips_arch_info
);
10713 if (file_mips_gp32
>= 0)
10715 /* The user specified the size of the integer registers. Make sure
10716 it agrees with the ABI and ISA. */
10717 if (file_mips_gp32
== 0 && !ISA_HAS_64BIT_REGS (mips_opts
.isa
))
10718 as_bad (_("-mgp64 used with a 32-bit processor"));
10719 else if (file_mips_gp32
== 1 && ABI_NEEDS_64BIT_REGS (mips_abi
))
10720 as_bad (_("-mgp32 used with a 64-bit ABI"));
10721 else if (file_mips_gp32
== 0 && ABI_NEEDS_32BIT_REGS (mips_abi
))
10722 as_bad (_("-mgp64 used with a 32-bit ABI"));
10726 /* Infer the integer register size from the ABI and processor.
10727 Restrict ourselves to 32-bit registers if that's all the
10728 processor has, or if the ABI cannot handle 64-bit registers. */
10729 file_mips_gp32
= (ABI_NEEDS_32BIT_REGS (mips_abi
)
10730 || !ISA_HAS_64BIT_REGS (mips_opts
.isa
));
10733 /* ??? GAS treats single-float processors as though they had 64-bit
10734 float registers (although it complains when double-precision
10735 instructions are used). As things stand, saying they have 32-bit
10736 registers would lead to spurious "register must be even" messages.
10737 So here we assume float registers are always the same size as
10738 integer ones, unless the user says otherwise. */
10739 if (file_mips_fp32
< 0)
10740 file_mips_fp32
= file_mips_gp32
;
10742 /* End of GCC-shared inference code. */
10744 /* ??? When do we want this flag to be set? Who uses it? */
10745 if (file_mips_gp32
== 1
10746 && mips_abi
== NO_ABI
10747 && ISA_HAS_64BIT_REGS (mips_opts
.isa
))
10748 mips_32bitmode
= 1;
10750 if (mips_opts
.isa
== ISA_MIPS1
&& mips_trap
)
10751 as_bad (_("trap exception not supported at ISA 1"));
10753 /* If the selected architecture includes support for ASEs, enable
10754 generation of code for them. */
10755 if (mips_opts
.mips16
== -1)
10756 mips_opts
.mips16
= (CPU_HAS_MIPS16 (mips_arch
)) ? 1 : 0;
10757 if (mips_opts
.ase_mips3d
== -1)
10758 mips_opts
.ase_mips3d
= (CPU_HAS_MIPS3D (mips_arch
)) ? 1 : 0;
10759 if (mips_opts
.ase_mdmx
== -1)
10760 mips_opts
.ase_mdmx
= (CPU_HAS_MDMX (mips_arch
)) ? 1 : 0;
10762 file_mips_isa
= mips_opts
.isa
;
10763 file_ase_mips16
= mips_opts
.mips16
;
10764 file_ase_mips3d
= mips_opts
.ase_mips3d
;
10765 file_ase_mdmx
= mips_opts
.ase_mdmx
;
10766 mips_opts
.gp32
= file_mips_gp32
;
10767 mips_opts
.fp32
= file_mips_fp32
;
10769 if (mips_flag_mdebug
< 0)
10771 #ifdef OBJ_MAYBE_ECOFF
10772 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
)
10773 mips_flag_mdebug
= 1;
10775 #endif /* OBJ_MAYBE_ECOFF */
10776 mips_flag_mdebug
= 0;
10781 mips_init_after_args ()
10783 /* initialize opcodes */
10784 bfd_mips_num_opcodes
= bfd_mips_num_builtin_opcodes
;
10785 mips_opcodes
= (struct mips_opcode
*) mips_builtin_opcodes
;
10789 md_pcrel_from (fixP
)
10792 if (OUTPUT_FLAVOR
!= bfd_target_aout_flavour
10793 && fixP
->fx_addsy
!= (symbolS
*) NULL
10794 && ! S_IS_DEFINED (fixP
->fx_addsy
))
10796 /* This makes a branch to an undefined symbol be a branch to the
10797 current location. */
10798 if (mips_pic
== EMBEDDED_PIC
)
10804 /* Return the address of the delay slot. */
10805 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
10808 /* This is called before the symbol table is processed. In order to
10809 work with gcc when using mips-tfile, we must keep all local labels.
10810 However, in other cases, we want to discard them. If we were
10811 called with -g, but we didn't see any debugging information, it may
10812 mean that gcc is smuggling debugging information through to
10813 mips-tfile, in which case we must generate all local labels. */
10816 mips_frob_file_before_adjust ()
10818 #ifndef NO_ECOFF_DEBUGGING
10819 if (ECOFF_DEBUGGING
10821 && ! ecoff_debugging_seen
)
10822 flag_keep_locals
= 1;
10826 /* Sort any unmatched HI16_S relocs so that they immediately precede
10827 the corresponding LO reloc. This is called before md_apply_fix3 and
10828 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10829 explicit use of the %hi modifier. */
10834 struct mips_hi_fixup
*l
;
10836 for (l
= mips_hi_fixup_list
; l
!= NULL
; l
= l
->next
)
10838 segment_info_type
*seginfo
;
10841 assert (l
->fixp
->fx_r_type
== BFD_RELOC_HI16_S
);
10843 /* Check quickly whether the next fixup happens to be a matching
10845 if (l
->fixp
->fx_next
!= NULL
10846 && l
->fixp
->fx_next
->fx_r_type
== BFD_RELOC_LO16
10847 && l
->fixp
->fx_addsy
== l
->fixp
->fx_next
->fx_addsy
10848 && l
->fixp
->fx_offset
== l
->fixp
->fx_next
->fx_offset
)
10851 /* Look through the fixups for this segment for a matching %lo.
10852 When we find one, move the %hi just in front of it. We do
10853 this in two passes. In the first pass, we try to find a
10854 unique %lo. In the second pass, we permit multiple %hi
10855 relocs for a single %lo (this is a GNU extension). */
10856 seginfo
= seg_info (l
->seg
);
10857 for (pass
= 0; pass
< 2; pass
++)
10862 for (f
= seginfo
->fix_root
; f
!= NULL
; f
= f
->fx_next
)
10864 /* Check whether this is a %lo fixup which matches l->fixp. */
10865 if (f
->fx_r_type
== BFD_RELOC_LO16
10866 && f
->fx_addsy
== l
->fixp
->fx_addsy
10867 && f
->fx_offset
== l
->fixp
->fx_offset
10870 || prev
->fx_r_type
!= BFD_RELOC_HI16_S
10871 || prev
->fx_addsy
!= f
->fx_addsy
10872 || prev
->fx_offset
!= f
->fx_offset
))
10876 /* Move l->fixp before f. */
10877 for (pf
= &seginfo
->fix_root
;
10879 pf
= &(*pf
)->fx_next
)
10880 assert (*pf
!= NULL
);
10882 *pf
= l
->fixp
->fx_next
;
10884 l
->fixp
->fx_next
= f
;
10886 seginfo
->fix_root
= l
->fixp
;
10888 prev
->fx_next
= l
->fixp
;
10899 #if 0 /* GCC code motion plus incomplete dead code elimination
10900 can leave a %hi without a %lo. */
10902 as_warn_where (l
->fixp
->fx_file
, l
->fixp
->fx_line
,
10903 _("Unmatched %%hi reloc"));
10909 /* When generating embedded PIC code we need to use a special
10910 relocation to represent the difference of two symbols in the .text
10911 section (switch tables use a difference of this sort). See
10912 include/coff/mips.h for details. This macro checks whether this
10913 fixup requires the special reloc. */
10914 #define SWITCH_TABLE(fixp) \
10915 ((fixp)->fx_r_type == BFD_RELOC_32 \
10916 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10917 && (fixp)->fx_addsy != NULL \
10918 && (fixp)->fx_subsy != NULL \
10919 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10920 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10922 /* When generating embedded PIC code we must keep all PC relative
10923 relocations, in case the linker has to relax a call. We also need
10924 to keep relocations for switch table entries.
10926 We may have combined relocations without symbols in the N32/N64 ABI.
10927 We have to prevent gas from dropping them. */
10930 mips_force_relocation (fixp
)
10933 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
10934 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
10935 || S_FORCE_RELOC (fixp
->fx_addsy
))
10939 && S_GET_SEGMENT (fixp
->fx_addsy
) == bfd_abs_section_ptr
10940 && (fixp
->fx_r_type
== BFD_RELOC_MIPS_SUB
10941 || fixp
->fx_r_type
== BFD_RELOC_HI16_S
10942 || fixp
->fx_r_type
== BFD_RELOC_LO16
))
10945 return (mips_pic
== EMBEDDED_PIC
10947 || SWITCH_TABLE (fixp
)
10948 || fixp
->fx_r_type
== BFD_RELOC_PCREL_HI16_S
10949 || fixp
->fx_r_type
== BFD_RELOC_PCREL_LO16
));
10954 mips_need_elf_addend_fixup (fixP
)
10957 if (S_GET_OTHER (fixP
->fx_addsy
) == STO_MIPS16
)
10959 if (mips_pic
== EMBEDDED_PIC
10960 && S_IS_WEAK (fixP
->fx_addsy
))
10962 if (mips_pic
!= EMBEDDED_PIC
10963 && (S_IS_WEAK (fixP
->fx_addsy
)
10964 || S_IS_EXTERNAL (fixP
->fx_addsy
))
10965 && !S_IS_COMMON (fixP
->fx_addsy
))
10967 if (symbol_used_in_reloc_p (fixP
->fx_addsy
)
10968 && (((bfd_get_section_flags (stdoutput
,
10969 S_GET_SEGMENT (fixP
->fx_addsy
))
10970 & SEC_LINK_ONCE
) != 0)
10971 || !strncmp (segment_name (S_GET_SEGMENT (fixP
->fx_addsy
)),
10973 sizeof (".gnu.linkonce") - 1)))
10979 /* Apply a fixup to the object file. */
10982 md_apply_fix3 (fixP
, valP
, seg
)
10985 segT seg ATTRIBUTE_UNUSED
;
10990 static int previous_fx_r_type
= 0;
10992 /* FIXME: Maybe just return for all reloc types not listed below?
10993 Eric Christopher says: "This is stupid, please rewrite md_apply_fix3. */
10994 if (fixP
->fx_r_type
== BFD_RELOC_8
)
10997 assert (fixP
->fx_size
== 4
10998 || fixP
->fx_r_type
== BFD_RELOC_16
10999 || fixP
->fx_r_type
== BFD_RELOC_32
11000 || fixP
->fx_r_type
== BFD_RELOC_MIPS_JMP
11001 || fixP
->fx_r_type
== BFD_RELOC_HI16_S
11002 || fixP
->fx_r_type
== BFD_RELOC_LO16
11003 || fixP
->fx_r_type
== BFD_RELOC_GPREL16
11004 || fixP
->fx_r_type
== BFD_RELOC_MIPS_LITERAL
11005 || fixP
->fx_r_type
== BFD_RELOC_GPREL32
11006 || fixP
->fx_r_type
== BFD_RELOC_64
11007 || fixP
->fx_r_type
== BFD_RELOC_CTOR
11008 || fixP
->fx_r_type
== BFD_RELOC_MIPS_SUB
11009 || fixP
->fx_r_type
== BFD_RELOC_MIPS_HIGHEST
11010 || fixP
->fx_r_type
== BFD_RELOC_MIPS_HIGHER
11011 || fixP
->fx_r_type
== BFD_RELOC_MIPS_SCN_DISP
11012 || fixP
->fx_r_type
== BFD_RELOC_MIPS_REL16
11013 || fixP
->fx_r_type
== BFD_RELOC_MIPS_RELGOT
11014 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
11015 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
11016 || fixP
->fx_r_type
== BFD_RELOC_MIPS_JALR
);
11020 /* If we aren't adjusting this fixup to be against the section
11021 symbol, we need to adjust the value. */
11023 if (fixP
->fx_addsy
!= NULL
&& OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11025 if (mips_need_elf_addend_fixup (fixP
))
11027 reloc_howto_type
*howto
;
11028 valueT symval
= S_GET_VALUE (fixP
->fx_addsy
);
11032 howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
11033 if (value
!= 0 && howto
->partial_inplace
11034 && (! fixP
->fx_pcrel
|| howto
->pcrel_offset
))
11036 /* In this case, the bfd_install_relocation routine will
11037 incorrectly add the symbol value back in. We just want
11038 the addend to appear in the object file.
11040 howto->pcrel_offset is added for R_MIPS_PC16, which is
11041 generated for code like
11052 /* Make sure the addend is still non-zero. If it became zero
11053 after the last operation, set it to a spurious value and
11054 subtract the same value from the object file's contents. */
11059 /* The in-place addends for LO16 relocations are signed;
11060 leave the matching HI16 in-place addends as zero. */
11061 if (fixP
->fx_r_type
!= BFD_RELOC_HI16_S
)
11063 bfd_vma contents
, mask
, field
;
11065 contents
= bfd_get_bits (fixP
->fx_frag
->fr_literal
11068 target_big_endian
);
11070 /* MASK has bits set where the relocation should go.
11071 FIELD is -value, shifted into the appropriate place
11072 for this relocation. */
11073 mask
= 1 << (howto
->bitsize
- 1);
11074 mask
= (((mask
- 1) << 1) | 1) << howto
->bitpos
;
11075 field
= (-value
>> howto
->rightshift
) << howto
->bitpos
;
11077 bfd_put_bits ((field
& mask
) | (contents
& ~mask
),
11078 fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
11080 target_big_endian
);
11086 /* This code was generated using trial and error and so is
11087 fragile and not trustworthy. If you change it, you should
11088 rerun the elf-rel, elf-rel2, and empic testcases and ensure
11089 they still pass. */
11090 if (fixP
->fx_pcrel
|| fixP
->fx_subsy
!= NULL
)
11092 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
11094 /* BFD's REL handling, for MIPS, is _very_ weird.
11095 This gives the right results, but it can't possibly
11096 be the way things are supposed to work. */
11097 if ((fixP
->fx_r_type
!= BFD_RELOC_16_PCREL
11098 && fixP
->fx_r_type
!= BFD_RELOC_16_PCREL_S2
)
11099 || S_GET_SEGMENT (fixP
->fx_addsy
) != undefined_section
)
11100 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
11105 fixP
->fx_addnumber
= value
; /* Remember value for tc_gen_reloc. */
11107 /* We are not done if this is a composite relocation to set up gp. */
11108 if (fixP
->fx_addsy
== NULL
&& ! fixP
->fx_pcrel
11109 && !(fixP
->fx_r_type
== BFD_RELOC_MIPS_SUB
11110 || (fixP
->fx_r_type
== BFD_RELOC_64
11111 && (previous_fx_r_type
== BFD_RELOC_GPREL32
11112 || previous_fx_r_type
== BFD_RELOC_GPREL16
))
11113 || (previous_fx_r_type
== BFD_RELOC_MIPS_SUB
11114 && (fixP
->fx_r_type
== BFD_RELOC_HI16_S
11115 || fixP
->fx_r_type
== BFD_RELOC_LO16
))))
11117 previous_fx_r_type
= fixP
->fx_r_type
;
11119 switch (fixP
->fx_r_type
)
11121 case BFD_RELOC_MIPS_JMP
:
11122 case BFD_RELOC_MIPS_SHIFT5
:
11123 case BFD_RELOC_MIPS_SHIFT6
:
11124 case BFD_RELOC_MIPS_GOT_DISP
:
11125 case BFD_RELOC_MIPS_GOT_PAGE
:
11126 case BFD_RELOC_MIPS_GOT_OFST
:
11127 case BFD_RELOC_MIPS_SUB
:
11128 case BFD_RELOC_MIPS_INSERT_A
:
11129 case BFD_RELOC_MIPS_INSERT_B
:
11130 case BFD_RELOC_MIPS_DELETE
:
11131 case BFD_RELOC_MIPS_HIGHEST
:
11132 case BFD_RELOC_MIPS_HIGHER
:
11133 case BFD_RELOC_MIPS_SCN_DISP
:
11134 case BFD_RELOC_MIPS_REL16
:
11135 case BFD_RELOC_MIPS_RELGOT
:
11136 case BFD_RELOC_MIPS_JALR
:
11137 case BFD_RELOC_HI16
:
11138 case BFD_RELOC_HI16_S
:
11139 case BFD_RELOC_GPREL16
:
11140 case BFD_RELOC_MIPS_LITERAL
:
11141 case BFD_RELOC_MIPS_CALL16
:
11142 case BFD_RELOC_MIPS_GOT16
:
11143 case BFD_RELOC_GPREL32
:
11144 case BFD_RELOC_MIPS_GOT_HI16
:
11145 case BFD_RELOC_MIPS_GOT_LO16
:
11146 case BFD_RELOC_MIPS_CALL_HI16
:
11147 case BFD_RELOC_MIPS_CALL_LO16
:
11148 case BFD_RELOC_MIPS16_GPREL
:
11149 if (fixP
->fx_pcrel
)
11150 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11151 _("Invalid PC relative reloc"));
11152 /* Nothing needed to do. The value comes from the reloc entry */
11155 case BFD_RELOC_MIPS16_JMP
:
11156 /* We currently always generate a reloc against a symbol, which
11157 means that we don't want an addend even if the symbol is
11159 fixP
->fx_addnumber
= 0;
11162 case BFD_RELOC_PCREL_HI16_S
:
11163 /* The addend for this is tricky if it is internal, so we just
11164 do everything here rather than in bfd_install_relocation. */
11165 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
11170 && (symbol_get_bfdsym (fixP
->fx_addsy
)->flags
& BSF_SECTION_SYM
) == 0)
11172 /* For an external symbol adjust by the address to make it
11173 pcrel_offset. We use the address of the RELLO reloc
11174 which follows this one. */
11175 value
+= (fixP
->fx_next
->fx_frag
->fr_address
11176 + fixP
->fx_next
->fx_where
);
11178 value
= ((value
+ 0x8000) >> 16) & 0xffff;
11179 buf
= (bfd_byte
*) fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
11180 if (target_big_endian
)
11182 md_number_to_chars ((char *) buf
, value
, 2);
11185 case BFD_RELOC_PCREL_LO16
:
11186 /* The addend for this is tricky if it is internal, so we just
11187 do everything here rather than in bfd_install_relocation. */
11188 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
11193 && (symbol_get_bfdsym (fixP
->fx_addsy
)->flags
& BSF_SECTION_SYM
) == 0)
11194 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
11195 buf
= (bfd_byte
*) fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
11196 if (target_big_endian
)
11198 md_number_to_chars ((char *) buf
, value
, 2);
11202 /* This is handled like BFD_RELOC_32, but we output a sign
11203 extended value if we are only 32 bits. */
11205 || (mips_pic
== EMBEDDED_PIC
&& SWITCH_TABLE (fixP
)))
11207 if (8 <= sizeof (valueT
))
11208 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
11215 w1
= w2
= fixP
->fx_where
;
11216 if (target_big_endian
)
11220 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ w1
, value
, 4);
11221 if ((value
& 0x80000000) != 0)
11225 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ w2
, hiv
, 4);
11230 case BFD_RELOC_RVA
:
11232 /* If we are deleting this reloc entry, we must fill in the
11233 value now. This can happen if we have a .word which is not
11234 resolved when it appears but is later defined. We also need
11235 to fill in the value if this is an embedded PIC switch table
11238 || (mips_pic
== EMBEDDED_PIC
&& SWITCH_TABLE (fixP
)))
11239 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
11244 /* If we are deleting this reloc entry, we must fill in the
11246 assert (fixP
->fx_size
== 2);
11248 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
11252 case BFD_RELOC_LO16
:
11253 /* When handling an embedded PIC switch statement, we can wind
11254 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11257 if (value
+ 0x8000 > 0xffff)
11258 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11259 _("relocation overflow"));
11260 buf
= (bfd_byte
*) fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
11261 if (target_big_endian
)
11263 md_number_to_chars ((char *) buf
, value
, 2);
11267 case BFD_RELOC_16_PCREL_S2
:
11268 if ((value
& 0x3) != 0)
11269 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11270 _("Branch to odd address (%lx)"), (long) value
);
11272 /* Fall through. */
11274 case BFD_RELOC_16_PCREL
:
11276 * We need to save the bits in the instruction since fixup_segment()
11277 * might be deleting the relocation entry (i.e., a branch within
11278 * the current segment).
11280 if (!fixP
->fx_done
&& value
!= 0)
11282 /* If 'value' is zero, the remaining reloc code won't actually
11283 do the store, so it must be done here. This is probably
11284 a bug somewhere. */
11286 && (fixP
->fx_r_type
!= BFD_RELOC_16_PCREL_S2
11287 || fixP
->fx_addsy
== NULL
/* ??? */
11288 || ! S_IS_DEFINED (fixP
->fx_addsy
)))
11289 value
-= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
11291 value
= (offsetT
) value
>> 2;
11293 /* update old instruction data */
11294 buf
= (bfd_byte
*) (fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
);
11295 if (target_big_endian
)
11296 insn
= (buf
[0] << 24) | (buf
[1] << 16) | (buf
[2] << 8) | buf
[3];
11298 insn
= (buf
[3] << 24) | (buf
[2] << 16) | (buf
[1] << 8) | buf
[0];
11300 if (value
+ 0x8000 <= 0xffff)
11301 insn
|= value
& 0xffff;
11304 /* The branch offset is too large. If this is an
11305 unconditional branch, and we are not generating PIC code,
11306 we can convert it to an absolute jump instruction. */
11307 if (mips_pic
== NO_PIC
11309 && fixP
->fx_frag
->fr_address
>= text_section
->vma
11310 && (fixP
->fx_frag
->fr_address
11311 < text_section
->vma
+ text_section
->_raw_size
)
11312 && ((insn
& 0xffff0000) == 0x10000000 /* beq $0,$0 */
11313 || (insn
& 0xffff0000) == 0x04010000 /* bgez $0 */
11314 || (insn
& 0xffff0000) == 0x04110000)) /* bgezal $0 */
11316 if ((insn
& 0xffff0000) == 0x04110000) /* bgezal $0 */
11317 insn
= 0x0c000000; /* jal */
11319 insn
= 0x08000000; /* j */
11320 fixP
->fx_r_type
= BFD_RELOC_MIPS_JMP
;
11322 fixP
->fx_addsy
= section_symbol (text_section
);
11323 fixP
->fx_addnumber
= (value
<< 2) + md_pcrel_from (fixP
);
11327 /* If we got here, we have branch-relaxation disabled,
11328 and there's nothing we can do to fix this instruction
11329 without turning it into a longer sequence. */
11330 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11331 _("Branch out of range"));
11335 md_number_to_chars ((char *) buf
, (valueT
) insn
, 4);
11338 case BFD_RELOC_VTABLE_INHERIT
:
11341 && !S_IS_DEFINED (fixP
->fx_addsy
)
11342 && !S_IS_WEAK (fixP
->fx_addsy
))
11343 S_SET_WEAK (fixP
->fx_addsy
);
11346 case BFD_RELOC_VTABLE_ENTRY
:
11360 const struct mips_opcode
*p
;
11361 int treg
, sreg
, dreg
, shamt
;
11366 for (i
= 0; i
< NUMOPCODES
; ++i
)
11368 p
= &mips_opcodes
[i
];
11369 if (((oc
& p
->mask
) == p
->match
) && (p
->pinfo
!= INSN_MACRO
))
11371 printf ("%08lx %s\t", oc
, p
->name
);
11372 treg
= (oc
>> 16) & 0x1f;
11373 sreg
= (oc
>> 21) & 0x1f;
11374 dreg
= (oc
>> 11) & 0x1f;
11375 shamt
= (oc
>> 6) & 0x1f;
11377 for (args
= p
->args
;; ++args
)
11388 printf ("%c", *args
);
11392 assert (treg
== sreg
);
11393 printf ("$%d,$%d", treg
, sreg
);
11398 printf ("$%d", dreg
);
11403 printf ("$%d", treg
);
11407 printf ("0x%x", treg
);
11412 printf ("$%d", sreg
);
11416 printf ("0x%08lx", oc
& 0x1ffffff);
11423 printf ("%d", imm
);
11428 printf ("$%d", shamt
);
11439 printf (_("%08lx UNDEFINED\n"), oc
);
11450 name
= input_line_pointer
;
11451 c
= get_symbol_end ();
11452 p
= (symbolS
*) symbol_find_or_make (name
);
11453 *input_line_pointer
= c
;
11457 /* Align the current frag to a given power of two. The MIPS assembler
11458 also automatically adjusts any preceding label. */
11461 mips_align (to
, fill
, label
)
11466 mips_emit_delays (false);
11467 frag_align (to
, fill
, 0);
11468 record_alignment (now_seg
, to
);
11471 assert (S_GET_SEGMENT (label
) == now_seg
);
11472 symbol_set_frag (label
, frag_now
);
11473 S_SET_VALUE (label
, (valueT
) frag_now_fix ());
11477 /* Align to a given power of two. .align 0 turns off the automatic
11478 alignment used by the data creating pseudo-ops. */
11482 int x ATTRIBUTE_UNUSED
;
11485 register long temp_fill
;
11486 long max_alignment
= 15;
11490 o Note that the assembler pulls down any immediately preceeding label
11491 to the aligned address.
11492 o It's not documented but auto alignment is reinstated by
11493 a .align pseudo instruction.
11494 o Note also that after auto alignment is turned off the mips assembler
11495 issues an error on attempt to assemble an improperly aligned data item.
11500 temp
= get_absolute_expression ();
11501 if (temp
> max_alignment
)
11502 as_bad (_("Alignment too large: %d. assumed."), temp
= max_alignment
);
11505 as_warn (_("Alignment negative: 0 assumed."));
11508 if (*input_line_pointer
== ',')
11510 ++input_line_pointer
;
11511 temp_fill
= get_absolute_expression ();
11518 mips_align (temp
, (int) temp_fill
,
11519 insn_labels
!= NULL
? insn_labels
->label
: NULL
);
11526 demand_empty_rest_of_line ();
11530 mips_flush_pending_output ()
11532 mips_emit_delays (false);
11533 mips_clear_insn_labels ();
11542 /* When generating embedded PIC code, we only use the .text, .lit8,
11543 .sdata and .sbss sections. We change the .data and .rdata
11544 pseudo-ops to use .sdata. */
11545 if (mips_pic
== EMBEDDED_PIC
11546 && (sec
== 'd' || sec
== 'r'))
11550 /* The ELF backend needs to know that we are changing sections, so
11551 that .previous works correctly. We could do something like check
11552 for an obj_section_change_hook macro, but that might be confusing
11553 as it would not be appropriate to use it in the section changing
11554 functions in read.c, since obj-elf.c intercepts those. FIXME:
11555 This should be cleaner, somehow. */
11556 obj_elf_section_change_hook ();
11559 mips_emit_delays (false);
11569 subseg_set (bss_section
, (subsegT
) get_absolute_expression ());
11570 demand_empty_rest_of_line ();
11574 if (USE_GLOBAL_POINTER_OPT
)
11576 seg
= subseg_new (RDATA_SECTION_NAME
,
11577 (subsegT
) get_absolute_expression ());
11578 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11580 bfd_set_section_flags (stdoutput
, seg
,
11586 if (strcmp (TARGET_OS
, "elf") != 0)
11587 record_alignment (seg
, 4);
11589 demand_empty_rest_of_line ();
11593 as_bad (_("No read only data section in this object file format"));
11594 demand_empty_rest_of_line ();
11600 if (USE_GLOBAL_POINTER_OPT
)
11602 seg
= subseg_new (".sdata", (subsegT
) get_absolute_expression ());
11603 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11605 bfd_set_section_flags (stdoutput
, seg
,
11606 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
11608 if (strcmp (TARGET_OS
, "elf") != 0)
11609 record_alignment (seg
, 4);
11611 demand_empty_rest_of_line ();
11616 as_bad (_("Global pointers not supported; recompile -G 0"));
11617 demand_empty_rest_of_line ();
11626 s_change_section (ignore
)
11627 int ignore ATTRIBUTE_UNUSED
;
11630 char *section_name
;
11635 int section_entry_size
;
11636 int section_alignment
;
11638 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
11641 section_name
= input_line_pointer
;
11642 c
= get_symbol_end ();
11643 next_c
= *(input_line_pointer
+ 1);
11645 /* Do we have .section Name<,"flags">? */
11646 if (c
!= ',' || (c
== ',' && next_c
== '"'))
11648 /* just after name is now '\0'. */
11649 *input_line_pointer
= c
;
11650 input_line_pointer
= section_name
;
11651 obj_elf_section (ignore
);
11654 input_line_pointer
++;
11656 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
11658 section_type
= get_absolute_expression ();
11661 if (*input_line_pointer
++ == ',')
11662 section_flag
= get_absolute_expression ();
11665 if (*input_line_pointer
++ == ',')
11666 section_entry_size
= get_absolute_expression ();
11668 section_entry_size
= 0;
11669 if (*input_line_pointer
++ == ',')
11670 section_alignment
= get_absolute_expression ();
11672 section_alignment
= 0;
11674 obj_elf_change_section (section_name
, section_type
, section_flag
,
11675 section_entry_size
, 0, 0, 0);
11676 #endif /* OBJ_ELF */
11680 mips_enable_auto_align ()
11691 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
11692 mips_emit_delays (false);
11693 if (log_size
> 0 && auto_align
)
11694 mips_align (log_size
, 0, label
);
11695 mips_clear_insn_labels ();
11696 cons (1 << log_size
);
11700 s_float_cons (type
)
11705 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
11707 mips_emit_delays (false);
11712 mips_align (3, 0, label
);
11714 mips_align (2, 0, label
);
11717 mips_clear_insn_labels ();
11722 /* Handle .globl. We need to override it because on Irix 5 you are
11725 where foo is an undefined symbol, to mean that foo should be
11726 considered to be the address of a function. */
11730 int x ATTRIBUTE_UNUSED
;
11737 name
= input_line_pointer
;
11738 c
= get_symbol_end ();
11739 symbolP
= symbol_find_or_make (name
);
11740 *input_line_pointer
= c
;
11741 SKIP_WHITESPACE ();
11743 /* On Irix 5, every global symbol that is not explicitly labelled as
11744 being a function is apparently labelled as being an object. */
11747 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
11752 secname
= input_line_pointer
;
11753 c
= get_symbol_end ();
11754 sec
= bfd_get_section_by_name (stdoutput
, secname
);
11756 as_bad (_("%s: no such section"), secname
);
11757 *input_line_pointer
= c
;
11759 if (sec
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
11760 flag
= BSF_FUNCTION
;
11763 symbol_get_bfdsym (symbolP
)->flags
|= flag
;
11765 S_SET_EXTERNAL (symbolP
);
11766 demand_empty_rest_of_line ();
11771 int x ATTRIBUTE_UNUSED
;
11776 opt
= input_line_pointer
;
11777 c
= get_symbol_end ();
11781 /* FIXME: What does this mean? */
11783 else if (strncmp (opt
, "pic", 3) == 0)
11787 i
= atoi (opt
+ 3);
11791 mips_pic
= SVR4_PIC
;
11793 as_bad (_(".option pic%d not supported"), i
);
11795 if (USE_GLOBAL_POINTER_OPT
&& mips_pic
== SVR4_PIC
)
11797 if (g_switch_seen
&& g_switch_value
!= 0)
11798 as_warn (_("-G may not be used with SVR4 PIC code"));
11799 g_switch_value
= 0;
11800 bfd_set_gp_size (stdoutput
, 0);
11804 as_warn (_("Unrecognized option \"%s\""), opt
);
11806 *input_line_pointer
= c
;
11807 demand_empty_rest_of_line ();
11810 /* This structure is used to hold a stack of .set values. */
11812 struct mips_option_stack
11814 struct mips_option_stack
*next
;
11815 struct mips_set_options options
;
11818 static struct mips_option_stack
*mips_opts_stack
;
11820 /* Handle the .set pseudo-op. */
11824 int x ATTRIBUTE_UNUSED
;
11826 char *name
= input_line_pointer
, ch
;
11828 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
11829 ++input_line_pointer
;
11830 ch
= *input_line_pointer
;
11831 *input_line_pointer
= '\0';
11833 if (strcmp (name
, "reorder") == 0)
11835 if (mips_opts
.noreorder
&& prev_nop_frag
!= NULL
)
11837 /* If we still have pending nops, we can discard them. The
11838 usual nop handling will insert any that are still
11840 prev_nop_frag
->fr_fix
-= (prev_nop_frag_holds
11841 * (mips_opts
.mips16
? 2 : 4));
11842 prev_nop_frag
= NULL
;
11844 mips_opts
.noreorder
= 0;
11846 else if (strcmp (name
, "noreorder") == 0)
11848 mips_emit_delays (true);
11849 mips_opts
.noreorder
= 1;
11850 mips_any_noreorder
= 1;
11852 else if (strcmp (name
, "at") == 0)
11854 mips_opts
.noat
= 0;
11856 else if (strcmp (name
, "noat") == 0)
11858 mips_opts
.noat
= 1;
11860 else if (strcmp (name
, "macro") == 0)
11862 mips_opts
.warn_about_macros
= 0;
11864 else if (strcmp (name
, "nomacro") == 0)
11866 if (mips_opts
.noreorder
== 0)
11867 as_bad (_("`noreorder' must be set before `nomacro'"));
11868 mips_opts
.warn_about_macros
= 1;
11870 else if (strcmp (name
, "move") == 0 || strcmp (name
, "novolatile") == 0)
11872 mips_opts
.nomove
= 0;
11874 else if (strcmp (name
, "nomove") == 0 || strcmp (name
, "volatile") == 0)
11876 mips_opts
.nomove
= 1;
11878 else if (strcmp (name
, "bopt") == 0)
11880 mips_opts
.nobopt
= 0;
11882 else if (strcmp (name
, "nobopt") == 0)
11884 mips_opts
.nobopt
= 1;
11886 else if (strcmp (name
, "mips16") == 0
11887 || strcmp (name
, "MIPS-16") == 0)
11888 mips_opts
.mips16
= 1;
11889 else if (strcmp (name
, "nomips16") == 0
11890 || strcmp (name
, "noMIPS-16") == 0)
11891 mips_opts
.mips16
= 0;
11892 else if (strcmp (name
, "mips3d") == 0)
11893 mips_opts
.ase_mips3d
= 1;
11894 else if (strcmp (name
, "nomips3d") == 0)
11895 mips_opts
.ase_mips3d
= 0;
11896 else if (strcmp (name
, "mdmx") == 0)
11897 mips_opts
.ase_mdmx
= 1;
11898 else if (strcmp (name
, "nomdmx") == 0)
11899 mips_opts
.ase_mdmx
= 0;
11900 else if (strncmp (name
, "mips", 4) == 0)
11904 /* Permit the user to change the ISA on the fly. Needless to
11905 say, misuse can cause serious problems. */
11906 isa
= atoi (name
+ 4);
11910 mips_opts
.gp32
= file_mips_gp32
;
11911 mips_opts
.fp32
= file_mips_fp32
;
11916 mips_opts
.gp32
= 1;
11917 mips_opts
.fp32
= 1;
11923 mips_opts
.gp32
= 0;
11924 mips_opts
.fp32
= 0;
11927 as_bad (_("unknown ISA level %s"), name
+ 4);
11933 case 0: mips_opts
.isa
= file_mips_isa
; break;
11934 case 1: mips_opts
.isa
= ISA_MIPS1
; break;
11935 case 2: mips_opts
.isa
= ISA_MIPS2
; break;
11936 case 3: mips_opts
.isa
= ISA_MIPS3
; break;
11937 case 4: mips_opts
.isa
= ISA_MIPS4
; break;
11938 case 5: mips_opts
.isa
= ISA_MIPS5
; break;
11939 case 32: mips_opts
.isa
= ISA_MIPS32
; break;
11940 case 64: mips_opts
.isa
= ISA_MIPS64
; break;
11941 default: as_bad (_("unknown ISA level %s"), name
+ 4); break;
11944 else if (strcmp (name
, "autoextend") == 0)
11945 mips_opts
.noautoextend
= 0;
11946 else if (strcmp (name
, "noautoextend") == 0)
11947 mips_opts
.noautoextend
= 1;
11948 else if (strcmp (name
, "push") == 0)
11950 struct mips_option_stack
*s
;
11952 s
= (struct mips_option_stack
*) xmalloc (sizeof *s
);
11953 s
->next
= mips_opts_stack
;
11954 s
->options
= mips_opts
;
11955 mips_opts_stack
= s
;
11957 else if (strcmp (name
, "pop") == 0)
11959 struct mips_option_stack
*s
;
11961 s
= mips_opts_stack
;
11963 as_bad (_(".set pop with no .set push"));
11966 /* If we're changing the reorder mode we need to handle
11967 delay slots correctly. */
11968 if (s
->options
.noreorder
&& ! mips_opts
.noreorder
)
11969 mips_emit_delays (true);
11970 else if (! s
->options
.noreorder
&& mips_opts
.noreorder
)
11972 if (prev_nop_frag
!= NULL
)
11974 prev_nop_frag
->fr_fix
-= (prev_nop_frag_holds
11975 * (mips_opts
.mips16
? 2 : 4));
11976 prev_nop_frag
= NULL
;
11980 mips_opts
= s
->options
;
11981 mips_opts_stack
= s
->next
;
11987 as_warn (_("Tried to set unrecognized symbol: %s\n"), name
);
11989 *input_line_pointer
= ch
;
11990 demand_empty_rest_of_line ();
11993 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11994 .option pic2. It means to generate SVR4 PIC calls. */
11997 s_abicalls (ignore
)
11998 int ignore ATTRIBUTE_UNUSED
;
12000 mips_pic
= SVR4_PIC
;
12001 if (USE_GLOBAL_POINTER_OPT
)
12003 if (g_switch_seen
&& g_switch_value
!= 0)
12004 as_warn (_("-G may not be used with SVR4 PIC code"));
12005 g_switch_value
= 0;
12007 bfd_set_gp_size (stdoutput
, 0);
12008 demand_empty_rest_of_line ();
12011 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12012 PIC code. It sets the $gp register for the function based on the
12013 function address, which is in the register named in the argument.
12014 This uses a relocation against _gp_disp, which is handled specially
12015 by the linker. The result is:
12016 lui $gp,%hi(_gp_disp)
12017 addiu $gp,$gp,%lo(_gp_disp)
12018 addu $gp,$gp,.cpload argument
12019 The .cpload argument is normally $25 == $t9. */
12023 int ignore ATTRIBUTE_UNUSED
;
12028 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12029 .cpload is ignored. */
12030 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
12036 /* .cpload should be in a .set noreorder section. */
12037 if (mips_opts
.noreorder
== 0)
12038 as_warn (_(".cpload not in noreorder section"));
12040 ex
.X_op
= O_symbol
;
12041 ex
.X_add_symbol
= symbol_find_or_make ("_gp_disp");
12042 ex
.X_op_symbol
= NULL
;
12043 ex
.X_add_number
= 0;
12045 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12046 symbol_get_bfdsym (ex
.X_add_symbol
)->flags
|= BSF_OBJECT
;
12048 macro_build_lui (NULL
, &icnt
, &ex
, mips_gp_register
);
12049 macro_build ((char *) NULL
, &icnt
, &ex
, "addiu", "t,r,j",
12050 mips_gp_register
, mips_gp_register
, (int) BFD_RELOC_LO16
);
12052 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "addu", "d,v,t",
12053 mips_gp_register
, mips_gp_register
, tc_get_register (0));
12055 demand_empty_rest_of_line ();
12058 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12059 .cpsetup $reg1, offset|$reg2, label
12061 If offset is given, this results in:
12062 sd $gp, offset($sp)
12063 lui $gp, %hi(%neg(%gp_rel(label)))
12064 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12065 daddu $gp, $gp, $reg1
12067 If $reg2 is given, this results in:
12068 daddu $reg2, $gp, $0
12069 lui $gp, %hi(%neg(%gp_rel(label)))
12070 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12071 daddu $gp, $gp, $reg1
12072 $reg1 is normally $25 == $t9. */
12075 int ignore ATTRIBUTE_UNUSED
;
12077 expressionS ex_off
;
12078 expressionS ex_sym
;
12083 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12084 We also need NewABI support. */
12085 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12091 reg1
= tc_get_register (0);
12092 SKIP_WHITESPACE ();
12093 if (*input_line_pointer
!= ',')
12095 as_bad (_("missing argument separator ',' for .cpsetup"));
12099 ++input_line_pointer
;
12100 SKIP_WHITESPACE ();
12101 if (*input_line_pointer
== '$')
12103 mips_cpreturn_register
= tc_get_register (0);
12104 mips_cpreturn_offset
= -1;
12108 mips_cpreturn_offset
= get_absolute_expression ();
12109 mips_cpreturn_register
= -1;
12111 SKIP_WHITESPACE ();
12112 if (*input_line_pointer
!= ',')
12114 as_bad (_("missing argument separator ',' for .cpsetup"));
12118 ++input_line_pointer
;
12119 SKIP_WHITESPACE ();
12120 expression (&ex_sym
);
12122 if (mips_cpreturn_register
== -1)
12124 ex_off
.X_op
= O_constant
;
12125 ex_off
.X_add_symbol
= NULL
;
12126 ex_off
.X_op_symbol
= NULL
;
12127 ex_off
.X_add_number
= mips_cpreturn_offset
;
12129 macro_build ((char *) NULL
, &icnt
, &ex_off
, "sd", "t,o(b)",
12130 mips_gp_register
, (int) BFD_RELOC_LO16
, SP
);
12133 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "daddu",
12134 "d,v,t", mips_cpreturn_register
, mips_gp_register
, 0);
12136 /* Ensure there's room for the next two instructions, so that `f'
12137 doesn't end up with an address in the wrong frag. */
12140 macro_build ((char *) NULL
, &icnt
, &ex_sym
, "lui", "t,u", mips_gp_register
,
12141 (int) BFD_RELOC_GPREL16
);
12142 fix_new (frag_now
, f
- frag_now
->fr_literal
,
12143 0, NULL
, 0, 0, BFD_RELOC_MIPS_SUB
);
12144 fix_new (frag_now
, f
- frag_now
->fr_literal
,
12145 0, NULL
, 0, 0, BFD_RELOC_HI16_S
);
12148 macro_build ((char *) NULL
, &icnt
, &ex_sym
, "addiu", "t,r,j",
12149 mips_gp_register
, mips_gp_register
, (int) BFD_RELOC_GPREL16
);
12150 fix_new (frag_now
, f
- frag_now
->fr_literal
,
12151 0, NULL
, 0, 0, BFD_RELOC_MIPS_SUB
);
12152 fix_new (frag_now
, f
- frag_now
->fr_literal
,
12153 0, NULL
, 0, 0, BFD_RELOC_LO16
);
12155 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
12156 HAVE_64BIT_ADDRESSES
? "daddu" : "addu", "d,v,t",
12157 mips_gp_register
, mips_gp_register
, reg1
);
12159 demand_empty_rest_of_line ();
12164 int ignore ATTRIBUTE_UNUSED
;
12166 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12167 .cplocal is ignored. */
12168 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12174 mips_gp_register
= tc_get_register (0);
12175 demand_empty_rest_of_line ();
12178 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12179 offset from $sp. The offset is remembered, and after making a PIC
12180 call $gp is restored from that location. */
12183 s_cprestore (ignore
)
12184 int ignore ATTRIBUTE_UNUSED
;
12189 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12190 .cprestore is ignored. */
12191 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
12197 mips_cprestore_offset
= get_absolute_expression ();
12198 mips_cprestore_valid
= 1;
12200 ex
.X_op
= O_constant
;
12201 ex
.X_add_symbol
= NULL
;
12202 ex
.X_op_symbol
= NULL
;
12203 ex
.X_add_number
= mips_cprestore_offset
;
12205 macro_build_ldst_constoffset ((char *) NULL
, &icnt
, &ex
,
12206 HAVE_32BIT_ADDRESSES
? "sw" : "sd",
12207 mips_gp_register
, SP
);
12209 demand_empty_rest_of_line ();
12212 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12213 was given in the preceeding .gpsetup, it results in:
12214 ld $gp, offset($sp)
12216 If a register $reg2 was given there, it results in:
12217 daddiu $gp, $gp, $reg2
12220 s_cpreturn (ignore
)
12221 int ignore ATTRIBUTE_UNUSED
;
12226 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12227 We also need NewABI support. */
12228 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12234 if (mips_cpreturn_register
== -1)
12236 ex
.X_op
= O_constant
;
12237 ex
.X_add_symbol
= NULL
;
12238 ex
.X_op_symbol
= NULL
;
12239 ex
.X_add_number
= mips_cpreturn_offset
;
12241 macro_build ((char *) NULL
, &icnt
, &ex
, "ld", "t,o(b)",
12242 mips_gp_register
, (int) BFD_RELOC_LO16
, SP
);
12245 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
, "daddu",
12246 "d,v,t", mips_gp_register
, mips_cpreturn_register
, 0);
12248 demand_empty_rest_of_line ();
12251 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12252 code. It sets the offset to use in gp_rel relocations. */
12256 int ignore ATTRIBUTE_UNUSED
;
12258 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12259 We also need NewABI support. */
12260 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12266 mips_gprel_offset
= get_absolute_expression ();
12268 demand_empty_rest_of_line ();
12271 /* Handle the .gpword pseudo-op. This is used when generating PIC
12272 code. It generates a 32 bit GP relative reloc. */
12276 int ignore ATTRIBUTE_UNUSED
;
12282 /* When not generating PIC code, this is treated as .word. */
12283 if (mips_pic
!= SVR4_PIC
)
12289 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
12290 mips_emit_delays (true);
12292 mips_align (2, 0, label
);
12293 mips_clear_insn_labels ();
12297 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
12299 as_bad (_("Unsupported use of .gpword"));
12300 ignore_rest_of_line ();
12304 md_number_to_chars (p
, (valueT
) 0, 4);
12305 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4, &ex
, false,
12306 BFD_RELOC_GPREL32
);
12308 demand_empty_rest_of_line ();
12313 int ignore ATTRIBUTE_UNUSED
;
12319 /* When not generating PIC code, this is treated as .dword. */
12320 if (mips_pic
!= SVR4_PIC
)
12326 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
12327 mips_emit_delays (true);
12329 mips_align (3, 0, label
);
12330 mips_clear_insn_labels ();
12334 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
12336 as_bad (_("Unsupported use of .gpdword"));
12337 ignore_rest_of_line ();
12341 md_number_to_chars (p
, (valueT
) 0, 8);
12342 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 8, &ex
, false,
12343 BFD_RELOC_GPREL32
);
12345 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12346 ex
.X_op
= O_absent
;
12347 ex
.X_add_symbol
= 0;
12348 ex
.X_add_number
= 0;
12349 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 8, &ex
, false,
12352 demand_empty_rest_of_line ();
12355 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12356 tables in SVR4 PIC code. */
12360 int ignore ATTRIBUTE_UNUSED
;
12365 /* This is ignored when not generating SVR4 PIC code. */
12366 if (mips_pic
!= SVR4_PIC
)
12372 /* Add $gp to the register named as an argument. */
12373 reg
= tc_get_register (0);
12374 macro_build ((char *) NULL
, &icnt
, (expressionS
*) NULL
,
12375 HAVE_32BIT_ADDRESSES
? "addu" : "daddu",
12376 "d,v,t", reg
, reg
, mips_gp_register
);
12378 demand_empty_rest_of_line ();
12381 /* Handle the .insn pseudo-op. This marks instruction labels in
12382 mips16 mode. This permits the linker to handle them specially,
12383 such as generating jalx instructions when needed. We also make
12384 them odd for the duration of the assembly, in order to generate the
12385 right sort of code. We will make them even in the adjust_symtab
12386 routine, while leaving them marked. This is convenient for the
12387 debugger and the disassembler. The linker knows to make them odd
12392 int ignore ATTRIBUTE_UNUSED
;
12394 mips16_mark_labels ();
12396 demand_empty_rest_of_line ();
12399 /* Handle a .stabn directive. We need these in order to mark a label
12400 as being a mips16 text label correctly. Sometimes the compiler
12401 will emit a label, followed by a .stabn, and then switch sections.
12402 If the label and .stabn are in mips16 mode, then the label is
12403 really a mips16 text label. */
12410 mips16_mark_labels ();
12415 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12419 s_mips_weakext (ignore
)
12420 int ignore ATTRIBUTE_UNUSED
;
12427 name
= input_line_pointer
;
12428 c
= get_symbol_end ();
12429 symbolP
= symbol_find_or_make (name
);
12430 S_SET_WEAK (symbolP
);
12431 *input_line_pointer
= c
;
12433 SKIP_WHITESPACE ();
12435 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
12437 if (S_IS_DEFINED (symbolP
))
12439 as_bad ("ignoring attempt to redefine symbol %s",
12440 S_GET_NAME (symbolP
));
12441 ignore_rest_of_line ();
12445 if (*input_line_pointer
== ',')
12447 ++input_line_pointer
;
12448 SKIP_WHITESPACE ();
12452 if (exp
.X_op
!= O_symbol
)
12454 as_bad ("bad .weakext directive");
12455 ignore_rest_of_line ();
12458 symbol_set_value_expression (symbolP
, &exp
);
12461 demand_empty_rest_of_line ();
12464 /* Parse a register string into a number. Called from the ECOFF code
12465 to parse .frame. The argument is non-zero if this is the frame
12466 register, so that we can record it in mips_frame_reg. */
12469 tc_get_register (frame
)
12474 SKIP_WHITESPACE ();
12475 if (*input_line_pointer
++ != '$')
12477 as_warn (_("expected `$'"));
12480 else if (ISDIGIT (*input_line_pointer
))
12482 reg
= get_absolute_expression ();
12483 if (reg
< 0 || reg
>= 32)
12485 as_warn (_("Bad register number"));
12491 if (strncmp (input_line_pointer
, "ra", 2) == 0)
12494 input_line_pointer
+= 2;
12496 else if (strncmp (input_line_pointer
, "fp", 2) == 0)
12499 input_line_pointer
+= 2;
12501 else if (strncmp (input_line_pointer
, "sp", 2) == 0)
12504 input_line_pointer
+= 2;
12506 else if (strncmp (input_line_pointer
, "gp", 2) == 0)
12509 input_line_pointer
+= 2;
12511 else if (strncmp (input_line_pointer
, "at", 2) == 0)
12514 input_line_pointer
+= 2;
12516 else if (strncmp (input_line_pointer
, "kt0", 3) == 0)
12519 input_line_pointer
+= 3;
12521 else if (strncmp (input_line_pointer
, "kt1", 3) == 0)
12524 input_line_pointer
+= 3;
12526 else if (strncmp (input_line_pointer
, "zero", 4) == 0)
12529 input_line_pointer
+= 4;
12533 as_warn (_("Unrecognized register name"));
12535 while (ISALNUM(*input_line_pointer
))
12536 input_line_pointer
++;
12541 mips_frame_reg
= reg
!= 0 ? reg
: SP
;
12542 mips_frame_reg_valid
= 1;
12543 mips_cprestore_valid
= 0;
12549 md_section_align (seg
, addr
)
12553 int align
= bfd_get_section_alignment (stdoutput
, seg
);
12556 /* We don't need to align ELF sections to the full alignment.
12557 However, Irix 5 may prefer that we align them at least to a 16
12558 byte boundary. We don't bother to align the sections if we are
12559 targeted for an embedded system. */
12560 if (strcmp (TARGET_OS
, "elf") == 0)
12566 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
12569 /* Utility routine, called from above as well. If called while the
12570 input file is still being read, it's only an approximation. (For
12571 example, a symbol may later become defined which appeared to be
12572 undefined earlier.) */
12575 nopic_need_relax (sym
, before_relaxing
)
12577 int before_relaxing
;
12582 if (USE_GLOBAL_POINTER_OPT
&& g_switch_value
> 0)
12584 const char *symname
;
12587 /* Find out whether this symbol can be referenced off the $gp
12588 register. It can be if it is smaller than the -G size or if
12589 it is in the .sdata or .sbss section. Certain symbols can
12590 not be referenced off the $gp, although it appears as though
12592 symname
= S_GET_NAME (sym
);
12593 if (symname
!= (const char *) NULL
12594 && (strcmp (symname
, "eprol") == 0
12595 || strcmp (symname
, "etext") == 0
12596 || strcmp (symname
, "_gp") == 0
12597 || strcmp (symname
, "edata") == 0
12598 || strcmp (symname
, "_fbss") == 0
12599 || strcmp (symname
, "_fdata") == 0
12600 || strcmp (symname
, "_ftext") == 0
12601 || strcmp (symname
, "end") == 0
12602 || strcmp (symname
, "_gp_disp") == 0))
12604 else if ((! S_IS_DEFINED (sym
) || S_IS_COMMON (sym
))
12606 #ifndef NO_ECOFF_DEBUGGING
12607 || (symbol_get_obj (sym
)->ecoff_extern_size
!= 0
12608 && (symbol_get_obj (sym
)->ecoff_extern_size
12609 <= g_switch_value
))
12611 /* We must defer this decision until after the whole
12612 file has been read, since there might be a .extern
12613 after the first use of this symbol. */
12614 || (before_relaxing
12615 #ifndef NO_ECOFF_DEBUGGING
12616 && symbol_get_obj (sym
)->ecoff_extern_size
== 0
12618 && S_GET_VALUE (sym
) == 0)
12619 || (S_GET_VALUE (sym
) != 0
12620 && S_GET_VALUE (sym
) <= g_switch_value
)))
12624 const char *segname
;
12626 segname
= segment_name (S_GET_SEGMENT (sym
));
12627 assert (strcmp (segname
, ".lit8") != 0
12628 && strcmp (segname
, ".lit4") != 0);
12629 change
= (strcmp (segname
, ".sdata") != 0
12630 && strcmp (segname
, ".sbss") != 0
12631 && strncmp (segname
, ".sdata.", 7) != 0
12632 && strncmp (segname
, ".gnu.linkonce.s.", 16) != 0);
12637 /* We are not optimizing for the $gp register. */
12641 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12642 extended opcode. SEC is the section the frag is in. */
12645 mips16_extended_frag (fragp
, sec
, stretch
)
12651 register const struct mips16_immed_operand
*op
;
12653 int mintiny
, maxtiny
;
12657 if (RELAX_MIPS16_USER_SMALL (fragp
->fr_subtype
))
12659 if (RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
))
12662 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
12663 op
= mips16_immed_operands
;
12664 while (op
->type
!= type
)
12667 assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
12672 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
12675 maxtiny
= 1 << op
->nbits
;
12680 maxtiny
= (1 << op
->nbits
) - 1;
12685 mintiny
= - (1 << (op
->nbits
- 1));
12686 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
12689 sym_frag
= symbol_get_frag (fragp
->fr_symbol
);
12690 val
= S_GET_VALUE (fragp
->fr_symbol
);
12691 symsec
= S_GET_SEGMENT (fragp
->fr_symbol
);
12697 /* We won't have the section when we are called from
12698 mips_relax_frag. However, we will always have been called
12699 from md_estimate_size_before_relax first. If this is a
12700 branch to a different section, we mark it as such. If SEC is
12701 NULL, and the frag is not marked, then it must be a branch to
12702 the same section. */
12705 if (RELAX_MIPS16_LONG_BRANCH (fragp
->fr_subtype
))
12710 /* Must have been called from md_estimate_size_before_relax. */
12713 fragp
->fr_subtype
=
12714 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12716 /* FIXME: We should support this, and let the linker
12717 catch branches and loads that are out of range. */
12718 as_bad_where (fragp
->fr_file
, fragp
->fr_line
,
12719 _("unsupported PC relative reference to different section"));
12723 if (fragp
!= sym_frag
&& sym_frag
->fr_address
== 0)
12724 /* Assume non-extended on the first relaxation pass.
12725 The address we have calculated will be bogus if this is
12726 a forward branch to another frag, as the forward frag
12727 will have fr_address == 0. */
12731 /* In this case, we know for sure that the symbol fragment is in
12732 the same section. If the relax_marker of the symbol fragment
12733 differs from the relax_marker of this fragment, we have not
12734 yet adjusted the symbol fragment fr_address. We want to add
12735 in STRETCH in order to get a better estimate of the address.
12736 This particularly matters because of the shift bits. */
12738 && sym_frag
->relax_marker
!= fragp
->relax_marker
)
12742 /* Adjust stretch for any alignment frag. Note that if have
12743 been expanding the earlier code, the symbol may be
12744 defined in what appears to be an earlier frag. FIXME:
12745 This doesn't handle the fr_subtype field, which specifies
12746 a maximum number of bytes to skip when doing an
12748 for (f
= fragp
; f
!= NULL
&& f
!= sym_frag
; f
= f
->fr_next
)
12750 if (f
->fr_type
== rs_align
|| f
->fr_type
== rs_align_code
)
12753 stretch
= - ((- stretch
)
12754 & ~ ((1 << (int) f
->fr_offset
) - 1));
12756 stretch
&= ~ ((1 << (int) f
->fr_offset
) - 1);
12765 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
12767 /* The base address rules are complicated. The base address of
12768 a branch is the following instruction. The base address of a
12769 PC relative load or add is the instruction itself, but if it
12770 is in a delay slot (in which case it can not be extended) use
12771 the address of the instruction whose delay slot it is in. */
12772 if (type
== 'p' || type
== 'q')
12776 /* If we are currently assuming that this frag should be
12777 extended, then, the current address is two bytes
12779 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
12782 /* Ignore the low bit in the target, since it will be set
12783 for a text label. */
12784 if ((val
& 1) != 0)
12787 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
12789 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
12792 val
-= addr
& ~ ((1 << op
->shift
) - 1);
12794 /* Branch offsets have an implicit 0 in the lowest bit. */
12795 if (type
== 'p' || type
== 'q')
12798 /* If any of the shifted bits are set, we must use an extended
12799 opcode. If the address depends on the size of this
12800 instruction, this can lead to a loop, so we arrange to always
12801 use an extended opcode. We only check this when we are in
12802 the main relaxation loop, when SEC is NULL. */
12803 if ((val
& ((1 << op
->shift
) - 1)) != 0 && sec
== NULL
)
12805 fragp
->fr_subtype
=
12806 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12810 /* If we are about to mark a frag as extended because the value
12811 is precisely maxtiny + 1, then there is a chance of an
12812 infinite loop as in the following code:
12817 In this case when the la is extended, foo is 0x3fc bytes
12818 away, so the la can be shrunk, but then foo is 0x400 away, so
12819 the la must be extended. To avoid this loop, we mark the
12820 frag as extended if it was small, and is about to become
12821 extended with a value of maxtiny + 1. */
12822 if (val
== ((maxtiny
+ 1) << op
->shift
)
12823 && ! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
)
12826 fragp
->fr_subtype
=
12827 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12831 else if (symsec
!= absolute_section
&& sec
!= NULL
)
12832 as_bad_where (fragp
->fr_file
, fragp
->fr_line
, _("unsupported relocation"));
12834 if ((val
& ((1 << op
->shift
) - 1)) != 0
12835 || val
< (mintiny
<< op
->shift
)
12836 || val
> (maxtiny
<< op
->shift
))
12842 /* Compute the length of a branch sequence, and adjust the
12843 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
12844 worst-case length is computed, with UPDATE being used to indicate
12845 whether an unconditional (-1), branch-likely (+1) or regular (0)
12846 branch is to be computed. */
12848 relaxed_branch_length (fragp
, sec
, update
)
12857 && S_IS_DEFINED (fragp
->fr_symbol
)
12858 && sec
== S_GET_SEGMENT (fragp
->fr_symbol
))
12863 val
= S_GET_VALUE (fragp
->fr_symbol
) + fragp
->fr_offset
;
12865 addr
= fragp
->fr_address
+ fragp
->fr_fix
+ 4;
12869 toofar
= val
< - (0x8000 << 2) || val
>= (0x8000 << 2);
12872 /* If the symbol is not defined or it's in a different segment,
12873 assume the user knows what's going on and emit a short
12879 if (fragp
&& update
&& toofar
!= RELAX_BRANCH_TOOFAR (fragp
->fr_subtype
))
12881 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_RELOC_S2 (fragp
->fr_subtype
),
12882 RELAX_BRANCH_UNCOND (fragp
->fr_subtype
),
12883 RELAX_BRANCH_LIKELY (fragp
->fr_subtype
),
12884 RELAX_BRANCH_LINK (fragp
->fr_subtype
),
12890 if (fragp
? RELAX_BRANCH_LIKELY (fragp
->fr_subtype
) : (update
> 0))
12893 if (mips_pic
!= NO_PIC
)
12895 /* Additional space for PIC loading of target address. */
12897 if (mips_opts
.isa
== ISA_MIPS1
)
12898 /* Additional space for $at-stabilizing nop. */
12902 /* If branch is conditional. */
12903 if (fragp
? !RELAX_BRANCH_UNCOND (fragp
->fr_subtype
) : (update
>= 0))
12910 /* Estimate the size of a frag before relaxing. Unless this is the
12911 mips16, we are not really relaxing here, and the final size is
12912 encoded in the subtype information. For the mips16, we have to
12913 decide whether we are using an extended opcode or not. */
12916 md_estimate_size_before_relax (fragp
, segtype
)
12921 boolean linkonce
= false;
12923 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
12926 fragp
->fr_var
= relaxed_branch_length (fragp
, segtype
, false);
12928 return fragp
->fr_var
;
12931 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
12932 /* We don't want to modify the EXTENDED bit here; it might get us
12933 into infinite loops. We change it only in mips_relax_frag(). */
12934 return (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
) ? 4 : 2);
12936 if (mips_pic
== NO_PIC
)
12938 change
= nopic_need_relax (fragp
->fr_symbol
, 0);
12940 else if (mips_pic
== SVR4_PIC
)
12945 sym
= fragp
->fr_symbol
;
12947 /* Handle the case of a symbol equated to another symbol. */
12948 while (symbol_equated_reloc_p (sym
))
12952 /* It's possible to get a loop here in a badly written
12954 n
= symbol_get_value_expression (sym
)->X_add_symbol
;
12960 symsec
= S_GET_SEGMENT (sym
);
12962 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12963 if (symsec
!= segtype
&& ! S_IS_LOCAL (sym
))
12965 if ((bfd_get_section_flags (stdoutput
, symsec
) & SEC_LINK_ONCE
)
12969 /* The GNU toolchain uses an extension for ELF: a section
12970 beginning with the magic string .gnu.linkonce is a linkonce
12972 if (strncmp (segment_name (symsec
), ".gnu.linkonce",
12973 sizeof ".gnu.linkonce" - 1) == 0)
12977 /* This must duplicate the test in adjust_reloc_syms. */
12978 change
= (symsec
!= &bfd_und_section
12979 && symsec
!= &bfd_abs_section
12980 && ! bfd_is_com_section (symsec
)
12983 /* A global or weak symbol is treated as external. */
12984 && (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
12985 || (! S_IS_WEAK (sym
)
12986 && (! S_IS_EXTERNAL (sym
)
12987 || mips_pic
== EMBEDDED_PIC
)))
12996 /* Record the offset to the first reloc in the fr_opcode field.
12997 This lets md_convert_frag and tc_gen_reloc know that the code
12998 must be expanded. */
12999 fragp
->fr_opcode
= (fragp
->fr_literal
13001 - RELAX_OLD (fragp
->fr_subtype
)
13002 + RELAX_RELOC1 (fragp
->fr_subtype
));
13003 /* FIXME: This really needs as_warn_where. */
13004 if (RELAX_WARN (fragp
->fr_subtype
))
13005 as_warn (_("AT used after \".set noat\" or macro used after "
13006 "\".set nomacro\""));
13008 return RELAX_NEW (fragp
->fr_subtype
) - RELAX_OLD (fragp
->fr_subtype
);
13014 /* This is called to see whether a reloc against a defined symbol
13015 should be converted into a reloc against a section. Don't adjust
13016 MIPS16 jump relocations, so we don't have to worry about the format
13017 of the offset in the .o file. Don't adjust relocations against
13018 mips16 symbols, so that the linker can find them if it needs to set
13022 mips_fix_adjustable (fixp
)
13025 if (fixp
->fx_r_type
== BFD_RELOC_MIPS16_JMP
)
13028 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
13029 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
13032 if (fixp
->fx_addsy
== NULL
)
13036 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
13037 && S_GET_OTHER (fixp
->fx_addsy
) == STO_MIPS16
13038 && fixp
->fx_subsy
== NULL
)
13045 /* Translate internal representation of relocation info to BFD target
13049 tc_gen_reloc (section
, fixp
)
13050 asection
*section ATTRIBUTE_UNUSED
;
13053 static arelent
*retval
[4];
13055 bfd_reloc_code_real_type code
;
13057 reloc
= retval
[0] = (arelent
*) xmalloc (sizeof (arelent
));
13060 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
13061 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
13062 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
13064 if (mips_pic
== EMBEDDED_PIC
13065 && SWITCH_TABLE (fixp
))
13067 /* For a switch table entry we use a special reloc. The addend
13068 is actually the difference between the reloc address and the
13070 reloc
->addend
= reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
);
13071 if (OUTPUT_FLAVOR
!= bfd_target_ecoff_flavour
)
13072 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
13073 fixp
->fx_r_type
= BFD_RELOC_GPREL32
;
13075 else if (fixp
->fx_r_type
== BFD_RELOC_PCREL_LO16
)
13077 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
13078 reloc
->addend
= fixp
->fx_addnumber
;
13081 /* We use a special addend for an internal RELLO reloc. */
13082 if (symbol_section_p (fixp
->fx_addsy
))
13083 reloc
->addend
= reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
);
13085 reloc
->addend
= fixp
->fx_addnumber
+ reloc
->address
;
13088 else if (fixp
->fx_r_type
== BFD_RELOC_PCREL_HI16_S
)
13090 assert (fixp
->fx_next
!= NULL
13091 && fixp
->fx_next
->fx_r_type
== BFD_RELOC_PCREL_LO16
);
13093 /* The reloc is relative to the RELLO; adjust the addend
13095 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
13096 reloc
->addend
= fixp
->fx_next
->fx_addnumber
;
13099 /* We use a special addend for an internal RELHI reloc. */
13100 if (symbol_section_p (fixp
->fx_addsy
))
13101 reloc
->addend
= (fixp
->fx_next
->fx_frag
->fr_address
13102 + fixp
->fx_next
->fx_where
13103 - S_GET_VALUE (fixp
->fx_subsy
));
13105 reloc
->addend
= (fixp
->fx_addnumber
13106 + fixp
->fx_next
->fx_frag
->fr_address
13107 + fixp
->fx_next
->fx_where
);
13110 else if (fixp
->fx_pcrel
== 0 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
13111 reloc
->addend
= fixp
->fx_addnumber
;
13114 if (OUTPUT_FLAVOR
!= bfd_target_aout_flavour
)
13115 /* A gruesome hack which is a result of the gruesome gas reloc
13117 reloc
->addend
= reloc
->address
;
13119 reloc
->addend
= -reloc
->address
;
13122 /* If this is a variant frag, we may need to adjust the existing
13123 reloc and generate a new one. */
13124 if (fixp
->fx_frag
->fr_opcode
!= NULL
13125 && ((fixp
->fx_r_type
== BFD_RELOC_GPREL16
13127 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT16
13128 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL16
13129 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_HI16
13130 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_LO16
13131 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_HI16
13132 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_LO16
)
13137 assert (! RELAX_MIPS16_P (fixp
->fx_frag
->fr_subtype
));
13139 /* If this is not the last reloc in this frag, then we have two
13140 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
13141 CALL_HI16/CALL_LO16, both of which are being replaced. Let
13142 the second one handle all of them. */
13143 if (fixp
->fx_next
!= NULL
13144 && fixp
->fx_frag
== fixp
->fx_next
->fx_frag
)
13146 assert ((fixp
->fx_r_type
== BFD_RELOC_GPREL16
13147 && fixp
->fx_next
->fx_r_type
== BFD_RELOC_GPREL16
)
13148 || (fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_HI16
13149 && (fixp
->fx_next
->fx_r_type
13150 == BFD_RELOC_MIPS_GOT_LO16
))
13151 || (fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_HI16
13152 && (fixp
->fx_next
->fx_r_type
13153 == BFD_RELOC_MIPS_CALL_LO16
)));
13158 fixp
->fx_where
= fixp
->fx_frag
->fr_opcode
- fixp
->fx_frag
->fr_literal
;
13159 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
13160 reloc2
= retval
[1] = (arelent
*) xmalloc (sizeof (arelent
));
13162 reloc2
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
13163 *reloc2
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
13164 reloc2
->address
= (reloc
->address
13165 + (RELAX_RELOC2 (fixp
->fx_frag
->fr_subtype
)
13166 - RELAX_RELOC1 (fixp
->fx_frag
->fr_subtype
)));
13167 reloc2
->addend
= fixp
->fx_addnumber
;
13168 reloc2
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_LO16
);
13169 assert (reloc2
->howto
!= NULL
);
13171 if (RELAX_RELOC3 (fixp
->fx_frag
->fr_subtype
))
13175 reloc3
= retval
[2] = (arelent
*) xmalloc (sizeof (arelent
));
13178 reloc3
->address
+= 4;
13181 if (mips_pic
== NO_PIC
)
13183 assert (fixp
->fx_r_type
== BFD_RELOC_GPREL16
);
13184 fixp
->fx_r_type
= BFD_RELOC_HI16_S
;
13186 else if (mips_pic
== SVR4_PIC
)
13188 switch (fixp
->fx_r_type
)
13192 case BFD_RELOC_MIPS_GOT16
:
13194 case BFD_RELOC_MIPS_GOT_LO16
:
13195 case BFD_RELOC_MIPS_CALL_LO16
:
13196 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT16
;
13198 case BFD_RELOC_MIPS_CALL16
:
13201 /* BFD_RELOC_MIPS_GOT16;*/
13202 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT_PAGE
;
13203 reloc2
->howto
= bfd_reloc_type_lookup
13204 (stdoutput
, BFD_RELOC_MIPS_GOT_OFST
);
13207 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT16
;
13214 /* newabi uses R_MIPS_GOT_DISP for local symbols */
13215 if (HAVE_NEWABI
&& BFD_RELOC_MIPS_GOT_LO16
)
13217 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT_DISP
;
13222 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13223 entry to be used in the relocation's section offset. */
13224 if (! HAVE_NEWABI
&& fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
13226 reloc
->address
= reloc
->addend
;
13230 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
13231 fixup_segment converted a non-PC relative reloc into a PC
13232 relative reloc. In such a case, we need to convert the reloc
13234 code
= fixp
->fx_r_type
;
13235 if (fixp
->fx_pcrel
)
13240 code
= BFD_RELOC_8_PCREL
;
13243 code
= BFD_RELOC_16_PCREL
;
13246 code
= BFD_RELOC_32_PCREL
;
13249 code
= BFD_RELOC_64_PCREL
;
13251 case BFD_RELOC_8_PCREL
:
13252 case BFD_RELOC_16_PCREL
:
13253 case BFD_RELOC_32_PCREL
:
13254 case BFD_RELOC_64_PCREL
:
13255 case BFD_RELOC_16_PCREL_S2
:
13256 case BFD_RELOC_PCREL_HI16_S
:
13257 case BFD_RELOC_PCREL_LO16
:
13260 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
13261 _("Cannot make %s relocation PC relative"),
13262 bfd_get_reloc_code_name (code
));
13267 /* md_apply_fix3 has a double-subtraction hack to get
13268 bfd_install_relocation to behave nicely. GPREL relocations are
13269 handled correctly without this hack, so undo it here. We can't
13270 stop md_apply_fix3 from subtracting twice in the first place since
13271 the fake addend is required for variant frags above. */
13272 if (fixp
->fx_addsy
!= NULL
&& OUTPUT_FLAVOR
== bfd_target_elf_flavour
13273 && (code
== BFD_RELOC_GPREL16
|| code
== BFD_RELOC_MIPS16_GPREL
)
13274 && reloc
->addend
!= 0
13275 && mips_need_elf_addend_fixup (fixp
))
13276 reloc
->addend
+= S_GET_VALUE (fixp
->fx_addsy
);
13279 /* To support a PC relative reloc when generating embedded PIC code
13280 for ECOFF, we use a Cygnus extension. We check for that here to
13281 make sure that we don't let such a reloc escape normally. */
13282 if ((OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
13283 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
13284 && code
== BFD_RELOC_16_PCREL_S2
13285 && mips_pic
!= EMBEDDED_PIC
)
13286 reloc
->howto
= NULL
;
13288 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
13290 if (reloc
->howto
== NULL
)
13292 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
13293 _("Can not represent %s relocation in this object file format"),
13294 bfd_get_reloc_code_name (code
));
13301 /* Relax a machine dependent frag. This returns the amount by which
13302 the current size of the frag should change. */
13305 mips_relax_frag (sec
, fragp
, stretch
)
13310 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
13312 offsetT old_var
= fragp
->fr_var
;
13314 fragp
->fr_var
= relaxed_branch_length (fragp
, sec
, true);
13316 return fragp
->fr_var
- old_var
;
13319 if (! RELAX_MIPS16_P (fragp
->fr_subtype
))
13322 if (mips16_extended_frag (fragp
, NULL
, stretch
))
13324 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13326 fragp
->fr_subtype
= RELAX_MIPS16_MARK_EXTENDED (fragp
->fr_subtype
);
13331 if (! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13333 fragp
->fr_subtype
= RELAX_MIPS16_CLEAR_EXTENDED (fragp
->fr_subtype
);
13340 /* Convert a machine dependent frag. */
13343 md_convert_frag (abfd
, asec
, fragp
)
13344 bfd
*abfd ATTRIBUTE_UNUSED
;
13351 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
13354 unsigned long insn
;
13358 buf
= (bfd_byte
*)fragp
->fr_literal
+ fragp
->fr_fix
;
13360 if (target_big_endian
)
13361 insn
= bfd_getb32 (buf
);
13363 insn
= bfd_getl32 (buf
);
13365 if (!RELAX_BRANCH_TOOFAR (fragp
->fr_subtype
))
13367 /* We generate a fixup instead of applying it right now
13368 because, if there are linker relaxations, we're going to
13369 need the relocations. */
13370 exp
.X_op
= O_symbol
;
13371 exp
.X_add_symbol
= fragp
->fr_symbol
;
13372 exp
.X_add_number
= fragp
->fr_offset
;
13374 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13376 RELAX_BRANCH_RELOC_S2 (fragp
->fr_subtype
)
13377 ? BFD_RELOC_16_PCREL_S2
13378 : BFD_RELOC_16_PCREL
);
13379 fixp
->fx_file
= fragp
->fr_file
;
13380 fixp
->fx_line
= fragp
->fr_line
;
13382 md_number_to_chars ((char *)buf
, insn
, 4);
13389 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
13390 _("relaxed out-of-range branch into a jump"));
13392 if (RELAX_BRANCH_UNCOND (fragp
->fr_subtype
))
13395 if (!RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13397 /* Reverse the branch. */
13398 switch ((insn
>> 28) & 0xf)
13401 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13402 have the condition reversed by tweaking a single
13403 bit, and their opcodes all have 0x4???????. */
13404 assert ((insn
& 0xf1000000) == 0x41000000);
13405 insn
^= 0x00010000;
13409 /* bltz 0x04000000 bgez 0x04010000
13410 bltzal 0x04100000 bgezal 0x04110000 */
13411 assert ((insn
& 0xfc0e0000) == 0x04000000);
13412 insn
^= 0x00010000;
13416 /* beq 0x10000000 bne 0x14000000
13417 blez 0x18000000 bgtz 0x1c000000 */
13418 insn
^= 0x04000000;
13426 if (RELAX_BRANCH_LINK (fragp
->fr_subtype
))
13428 /* Clear the and-link bit. */
13429 assert ((insn
& 0xfc1c0000) == 0x04100000);
13431 /* bltzal 0x04100000 bgezal 0x04110000
13432 bltzall 0x04120000 bgezall 0x04130000 */
13433 insn
&= ~0x00100000;
13436 /* Branch over the branch (if the branch was likely) or the
13437 full jump (not likely case). Compute the offset from the
13438 current instruction to branch to. */
13439 if (RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13443 /* How many bytes in instructions we've already emitted? */
13444 i
= buf
- (bfd_byte
*)fragp
->fr_literal
- fragp
->fr_fix
;
13445 /* How many bytes in instructions from here to the end? */
13446 i
= fragp
->fr_var
- i
;
13448 /* Convert to instruction count. */
13450 /* Branch counts from the next instruction. */
13453 /* Branch over the jump. */
13454 md_number_to_chars ((char *)buf
, insn
, 4);
13458 md_number_to_chars ((char*)buf
, 0, 4);
13461 if (RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13463 /* beql $0, $0, 2f */
13465 /* Compute the PC offset from the current instruction to
13466 the end of the variable frag. */
13467 /* How many bytes in instructions we've already emitted? */
13468 i
= buf
- (bfd_byte
*)fragp
->fr_literal
- fragp
->fr_fix
;
13469 /* How many bytes in instructions from here to the end? */
13470 i
= fragp
->fr_var
- i
;
13471 /* Convert to instruction count. */
13473 /* Don't decrement i, because we want to branch over the
13477 md_number_to_chars ((char *)buf
, insn
, 4);
13480 md_number_to_chars ((char *)buf
, 0, 4);
13485 if (mips_pic
== NO_PIC
)
13488 insn
= (RELAX_BRANCH_LINK (fragp
->fr_subtype
)
13489 ? 0x0c000000 : 0x08000000);
13490 exp
.X_op
= O_symbol
;
13491 exp
.X_add_symbol
= fragp
->fr_symbol
;
13492 exp
.X_add_number
= fragp
->fr_offset
;
13494 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13495 4, &exp
, 0, BFD_RELOC_MIPS_JMP
);
13496 fixp
->fx_file
= fragp
->fr_file
;
13497 fixp
->fx_line
= fragp
->fr_line
;
13499 md_number_to_chars ((char*)buf
, insn
, 4);
13504 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13505 insn
= HAVE_64BIT_ADDRESSES
? 0xdf810000 : 0x8f810000;
13506 exp
.X_op
= O_symbol
;
13507 exp
.X_add_symbol
= fragp
->fr_symbol
;
13508 exp
.X_add_number
= fragp
->fr_offset
;
13510 if (fragp
->fr_offset
)
13512 exp
.X_add_symbol
= make_expr_symbol (&exp
);
13513 exp
.X_add_number
= 0;
13516 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13517 4, &exp
, 0, BFD_RELOC_MIPS_GOT16
);
13518 fixp
->fx_file
= fragp
->fr_file
;
13519 fixp
->fx_line
= fragp
->fr_line
;
13521 md_number_to_chars ((char*)buf
, insn
, 4);
13524 if (mips_opts
.isa
== ISA_MIPS1
)
13527 md_number_to_chars ((char*)buf
, 0, 4);
13531 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
13532 insn
= HAVE_64BIT_ADDRESSES
? 0x64210000 : 0x24210000;
13534 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13535 4, &exp
, 0, BFD_RELOC_LO16
);
13536 fixp
->fx_file
= fragp
->fr_file
;
13537 fixp
->fx_line
= fragp
->fr_line
;
13539 md_number_to_chars ((char*)buf
, insn
, 4);
13543 if (RELAX_BRANCH_LINK (fragp
->fr_subtype
))
13548 md_number_to_chars ((char*)buf
, insn
, 4);
13553 assert (buf
== (bfd_byte
*)fragp
->fr_literal
13554 + fragp
->fr_fix
+ fragp
->fr_var
);
13556 fragp
->fr_fix
+= fragp
->fr_var
;
13561 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
13564 register const struct mips16_immed_operand
*op
;
13565 boolean small
, ext
;
13568 unsigned long insn
;
13569 boolean use_extend
;
13570 unsigned short extend
;
13572 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
13573 op
= mips16_immed_operands
;
13574 while (op
->type
!= type
)
13577 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13588 resolve_symbol_value (fragp
->fr_symbol
);
13589 val
= S_GET_VALUE (fragp
->fr_symbol
);
13594 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
13596 /* The rules for the base address of a PC relative reloc are
13597 complicated; see mips16_extended_frag. */
13598 if (type
== 'p' || type
== 'q')
13603 /* Ignore the low bit in the target, since it will be
13604 set for a text label. */
13605 if ((val
& 1) != 0)
13608 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
13610 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
13613 addr
&= ~ (addressT
) ((1 << op
->shift
) - 1);
13616 /* Make sure the section winds up with the alignment we have
13619 record_alignment (asec
, op
->shift
);
13623 && (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
)
13624 || RELAX_MIPS16_DSLOT (fragp
->fr_subtype
)))
13625 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
13626 _("extended instruction in delay slot"));
13628 buf
= (bfd_byte
*) (fragp
->fr_literal
+ fragp
->fr_fix
);
13630 if (target_big_endian
)
13631 insn
= bfd_getb16 (buf
);
13633 insn
= bfd_getl16 (buf
);
13635 mips16_immed (fragp
->fr_file
, fragp
->fr_line
, type
, val
,
13636 RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
),
13637 small
, ext
, &insn
, &use_extend
, &extend
);
13641 md_number_to_chars ((char *) buf
, 0xf000 | extend
, 2);
13642 fragp
->fr_fix
+= 2;
13646 md_number_to_chars ((char *) buf
, insn
, 2);
13647 fragp
->fr_fix
+= 2;
13652 if (fragp
->fr_opcode
== NULL
)
13655 old
= RELAX_OLD (fragp
->fr_subtype
);
13656 new = RELAX_NEW (fragp
->fr_subtype
);
13657 fixptr
= fragp
->fr_literal
+ fragp
->fr_fix
;
13660 memcpy (fixptr
- old
, fixptr
, new);
13662 fragp
->fr_fix
+= new - old
;
13668 /* This function is called after the relocs have been generated.
13669 We've been storing mips16 text labels as odd. Here we convert them
13670 back to even for the convenience of the debugger. */
13673 mips_frob_file_after_relocs ()
13676 unsigned int count
, i
;
13678 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
13681 syms
= bfd_get_outsymbols (stdoutput
);
13682 count
= bfd_get_symcount (stdoutput
);
13683 for (i
= 0; i
< count
; i
++, syms
++)
13685 if (elf_symbol (*syms
)->internal_elf_sym
.st_other
== STO_MIPS16
13686 && ((*syms
)->value
& 1) != 0)
13688 (*syms
)->value
&= ~1;
13689 /* If the symbol has an odd size, it was probably computed
13690 incorrectly, so adjust that as well. */
13691 if ((elf_symbol (*syms
)->internal_elf_sym
.st_size
& 1) != 0)
13692 ++elf_symbol (*syms
)->internal_elf_sym
.st_size
;
13699 /* This function is called whenever a label is defined. It is used
13700 when handling branch delays; if a branch has a label, we assume we
13701 can not move it. */
13704 mips_define_label (sym
)
13707 struct insn_label_list
*l
;
13709 if (free_insn_labels
== NULL
)
13710 l
= (struct insn_label_list
*) xmalloc (sizeof *l
);
13713 l
= free_insn_labels
;
13714 free_insn_labels
= l
->next
;
13718 l
->next
= insn_labels
;
13722 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13724 /* Some special processing for a MIPS ELF file. */
13727 mips_elf_final_processing ()
13729 /* Write out the register information. */
13730 if (mips_abi
!= N64_ABI
)
13734 s
.ri_gprmask
= mips_gprmask
;
13735 s
.ri_cprmask
[0] = mips_cprmask
[0];
13736 s
.ri_cprmask
[1] = mips_cprmask
[1];
13737 s
.ri_cprmask
[2] = mips_cprmask
[2];
13738 s
.ri_cprmask
[3] = mips_cprmask
[3];
13739 /* The gp_value field is set by the MIPS ELF backend. */
13741 bfd_mips_elf32_swap_reginfo_out (stdoutput
, &s
,
13742 ((Elf32_External_RegInfo
*)
13743 mips_regmask_frag
));
13747 Elf64_Internal_RegInfo s
;
13749 s
.ri_gprmask
= mips_gprmask
;
13751 s
.ri_cprmask
[0] = mips_cprmask
[0];
13752 s
.ri_cprmask
[1] = mips_cprmask
[1];
13753 s
.ri_cprmask
[2] = mips_cprmask
[2];
13754 s
.ri_cprmask
[3] = mips_cprmask
[3];
13755 /* The gp_value field is set by the MIPS ELF backend. */
13757 bfd_mips_elf64_swap_reginfo_out (stdoutput
, &s
,
13758 ((Elf64_External_RegInfo
*)
13759 mips_regmask_frag
));
13762 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13763 sort of BFD interface for this. */
13764 if (mips_any_noreorder
)
13765 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_NOREORDER
;
13766 if (mips_pic
!= NO_PIC
)
13767 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_PIC
;
13769 /* Set MIPS ELF flags for ASEs. */
13770 if (file_ase_mips16
)
13771 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_M16
;
13772 #if 0 /* XXX FIXME */
13773 if (file_ase_mips3d
)
13774 elf_elfheader (stdoutput
)->e_flags
|= ???;
13777 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_MDMX
;
13779 /* Set the MIPS ELF ABI flags. */
13780 if (mips_abi
== O32_ABI
&& USE_E_MIPS_ABI_O32
)
13781 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O32
;
13782 else if (mips_abi
== O64_ABI
)
13783 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O64
;
13784 else if (mips_abi
== EABI_ABI
)
13786 if (!file_mips_gp32
)
13787 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI64
;
13789 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI32
;
13791 else if (mips_abi
== N32_ABI
)
13792 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ABI2
;
13794 /* Nothing to do for N64_ABI. */
13796 if (mips_32bitmode
)
13797 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_32BITMODE
;
13800 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
13802 typedef struct proc
{
13804 unsigned long reg_mask
;
13805 unsigned long reg_offset
;
13806 unsigned long fpreg_mask
;
13807 unsigned long fpreg_offset
;
13808 unsigned long frame_offset
;
13809 unsigned long frame_reg
;
13810 unsigned long pc_reg
;
13813 static procS cur_proc
;
13814 static procS
*cur_proc_ptr
;
13815 static int numprocs
;
13817 /* Fill in an rs_align_code fragment. */
13820 mips_handle_align (fragp
)
13823 if (fragp
->fr_type
!= rs_align_code
)
13826 if (mips_opts
.mips16
)
13828 static const unsigned char be_nop
[] = { 0x65, 0x00 };
13829 static const unsigned char le_nop
[] = { 0x00, 0x65 };
13834 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
13835 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
13843 memcpy (p
, (target_big_endian
? be_nop
: le_nop
), 2);
13847 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
13858 /* check for premature end, nesting errors, etc */
13860 as_warn (_("missing .end at end of assembly"));
13869 if (*input_line_pointer
== '-')
13871 ++input_line_pointer
;
13874 if (!ISDIGIT (*input_line_pointer
))
13875 as_bad (_("expected simple number"));
13876 if (input_line_pointer
[0] == '0')
13878 if (input_line_pointer
[1] == 'x')
13880 input_line_pointer
+= 2;
13881 while (ISXDIGIT (*input_line_pointer
))
13884 val
|= hex_value (*input_line_pointer
++);
13886 return negative
? -val
: val
;
13890 ++input_line_pointer
;
13891 while (ISDIGIT (*input_line_pointer
))
13894 val
|= *input_line_pointer
++ - '0';
13896 return negative
? -val
: val
;
13899 if (!ISDIGIT (*input_line_pointer
))
13901 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13902 *input_line_pointer
, *input_line_pointer
);
13903 as_warn (_("invalid number"));
13906 while (ISDIGIT (*input_line_pointer
))
13909 val
+= *input_line_pointer
++ - '0';
13911 return negative
? -val
: val
;
13914 /* The .file directive; just like the usual .file directive, but there
13915 is an initial number which is the ECOFF file index. In the non-ECOFF
13916 case .file implies DWARF-2. */
13920 int x ATTRIBUTE_UNUSED
;
13922 static int first_file_directive
= 0;
13924 if (ECOFF_DEBUGGING
)
13933 filename
= dwarf2_directive_file (0);
13935 /* Versions of GCC up to 3.1 start files with a ".file"
13936 directive even for stabs output. Make sure that this
13937 ".file" is handled. Note that you need a version of GCC
13938 after 3.1 in order to support DWARF-2 on MIPS. */
13939 if (filename
!= NULL
&& ! first_file_directive
)
13941 (void) new_logical_line (filename
, -1);
13942 s_app_file_string (filename
);
13944 first_file_directive
= 1;
13948 /* The .loc directive, implying DWARF-2. */
13952 int x ATTRIBUTE_UNUSED
;
13954 if (!ECOFF_DEBUGGING
)
13955 dwarf2_directive_loc (0);
13958 /* The .end directive. */
13962 int x ATTRIBUTE_UNUSED
;
13967 /* Following functions need their own .frame and .cprestore directives. */
13968 mips_frame_reg_valid
= 0;
13969 mips_cprestore_valid
= 0;
13971 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
13974 demand_empty_rest_of_line ();
13979 #ifdef BFD_ASSEMBLER
13980 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
13985 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
13992 as_warn (_(".end not in text section"));
13996 as_warn (_(".end directive without a preceding .ent directive."));
13997 demand_empty_rest_of_line ();
14003 assert (S_GET_NAME (p
));
14004 if (strcmp (S_GET_NAME (p
), S_GET_NAME (cur_proc_ptr
->isym
)))
14005 as_warn (_(".end symbol does not match .ent symbol."));
14007 if (debug_type
== DEBUG_STABS
)
14008 stabs_generate_asm_endfunc (S_GET_NAME (p
),
14012 as_warn (_(".end directive missing or unknown symbol"));
14015 /* Generate a .pdr section. */
14016 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
)
14018 segT saved_seg
= now_seg
;
14019 subsegT saved_subseg
= now_subseg
;
14024 dot
= frag_now_fix ();
14026 #ifdef md_flush_pending_output
14027 md_flush_pending_output ();
14031 subseg_set (pdr_seg
, 0);
14033 /* Write the symbol. */
14034 exp
.X_op
= O_symbol
;
14035 exp
.X_add_symbol
= p
;
14036 exp
.X_add_number
= 0;
14037 emit_expr (&exp
, 4);
14039 fragp
= frag_more (7 * 4);
14041 md_number_to_chars (fragp
, (valueT
) cur_proc_ptr
->reg_mask
, 4);
14042 md_number_to_chars (fragp
+ 4, (valueT
) cur_proc_ptr
->reg_offset
, 4);
14043 md_number_to_chars (fragp
+ 8, (valueT
) cur_proc_ptr
->fpreg_mask
, 4);
14044 md_number_to_chars (fragp
+ 12, (valueT
) cur_proc_ptr
->fpreg_offset
, 4);
14045 md_number_to_chars (fragp
+ 16, (valueT
) cur_proc_ptr
->frame_offset
, 4);
14046 md_number_to_chars (fragp
+ 20, (valueT
) cur_proc_ptr
->frame_reg
, 4);
14047 md_number_to_chars (fragp
+ 24, (valueT
) cur_proc_ptr
->pc_reg
, 4);
14049 subseg_set (saved_seg
, saved_subseg
);
14051 #endif /* OBJ_ELF */
14053 cur_proc_ptr
= NULL
;
14056 /* The .aent and .ent directives. */
14065 symbolP
= get_symbol ();
14066 if (*input_line_pointer
== ',')
14067 ++input_line_pointer
;
14068 SKIP_WHITESPACE ();
14069 if (ISDIGIT (*input_line_pointer
)
14070 || *input_line_pointer
== '-')
14073 #ifdef BFD_ASSEMBLER
14074 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
14079 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
14086 as_warn (_(".ent or .aent not in text section."));
14088 if (!aent
&& cur_proc_ptr
)
14089 as_warn (_("missing .end"));
14093 /* This function needs its own .frame and .cprestore directives. */
14094 mips_frame_reg_valid
= 0;
14095 mips_cprestore_valid
= 0;
14097 cur_proc_ptr
= &cur_proc
;
14098 memset (cur_proc_ptr
, '\0', sizeof (procS
));
14100 cur_proc_ptr
->isym
= symbolP
;
14102 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
14106 if (debug_type
== DEBUG_STABS
)
14107 stabs_generate_asm_func (S_GET_NAME (symbolP
),
14108 S_GET_NAME (symbolP
));
14111 demand_empty_rest_of_line ();
14114 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
14115 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
14116 s_mips_frame is used so that we can set the PDR information correctly.
14117 We can't use the ecoff routines because they make reference to the ecoff
14118 symbol table (in the mdebug section). */
14121 s_mips_frame (ignore
)
14122 int ignore ATTRIBUTE_UNUSED
;
14125 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
)
14129 if (cur_proc_ptr
== (procS
*) NULL
)
14131 as_warn (_(".frame outside of .ent"));
14132 demand_empty_rest_of_line ();
14136 cur_proc_ptr
->frame_reg
= tc_get_register (1);
14138 SKIP_WHITESPACE ();
14139 if (*input_line_pointer
++ != ','
14140 || get_absolute_expression_and_terminator (&val
) != ',')
14142 as_warn (_("Bad .frame directive"));
14143 --input_line_pointer
;
14144 demand_empty_rest_of_line ();
14148 cur_proc_ptr
->frame_offset
= val
;
14149 cur_proc_ptr
->pc_reg
= tc_get_register (0);
14151 demand_empty_rest_of_line ();
14154 #endif /* OBJ_ELF */
14158 /* The .fmask and .mask directives. If the mdebug section is present
14159 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14160 embedded targets, s_mips_mask is used so that we can set the PDR
14161 information correctly. We can't use the ecoff routines because they
14162 make reference to the ecoff symbol table (in the mdebug section). */
14165 s_mips_mask (reg_type
)
14169 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
)
14173 if (cur_proc_ptr
== (procS
*) NULL
)
14175 as_warn (_(".mask/.fmask outside of .ent"));
14176 demand_empty_rest_of_line ();
14180 if (get_absolute_expression_and_terminator (&mask
) != ',')
14182 as_warn (_("Bad .mask/.fmask directive"));
14183 --input_line_pointer
;
14184 demand_empty_rest_of_line ();
14188 off
= get_absolute_expression ();
14190 if (reg_type
== 'F')
14192 cur_proc_ptr
->fpreg_mask
= mask
;
14193 cur_proc_ptr
->fpreg_offset
= off
;
14197 cur_proc_ptr
->reg_mask
= mask
;
14198 cur_proc_ptr
->reg_offset
= off
;
14201 demand_empty_rest_of_line ();
14204 #endif /* OBJ_ELF */
14205 s_ignore (reg_type
);
14208 /* The .loc directive. */
14219 assert (now_seg
== text_section
);
14221 lineno
= get_number ();
14222 addroff
= frag_now_fix ();
14224 symbolP
= symbol_new ("", N_SLINE
, addroff
, frag_now
);
14225 S_SET_TYPE (symbolP
, N_SLINE
);
14226 S_SET_OTHER (symbolP
, 0);
14227 S_SET_DESC (symbolP
, lineno
);
14228 symbolP
->sy_segment
= now_seg
;
14232 /* A table describing all the processors gas knows about. Names are
14233 matched in the order listed.
14235 To ease comparison, please keep this table in the same order as
14236 gcc's mips_cpu_info_table[]. */
14237 static const struct mips_cpu_info mips_cpu_info_table
[] =
14239 /* Entries for generic ISAs */
14240 { "mips1", 1, ISA_MIPS1
, CPU_R3000
},
14241 { "mips2", 1, ISA_MIPS2
, CPU_R6000
},
14242 { "mips3", 1, ISA_MIPS3
, CPU_R4000
},
14243 { "mips4", 1, ISA_MIPS4
, CPU_R8000
},
14244 { "mips5", 1, ISA_MIPS5
, CPU_MIPS5
},
14245 { "mips32", 1, ISA_MIPS32
, CPU_MIPS32
},
14246 { "mips64", 1, ISA_MIPS64
, CPU_MIPS64
},
14249 { "r3000", 0, ISA_MIPS1
, CPU_R3000
},
14250 { "r2000", 0, ISA_MIPS1
, CPU_R3000
},
14251 { "r3900", 0, ISA_MIPS1
, CPU_R3900
},
14254 { "r6000", 0, ISA_MIPS2
, CPU_R6000
},
14257 { "r4000", 0, ISA_MIPS3
, CPU_R4000
},
14258 { "r4010", 0, ISA_MIPS2
, CPU_R4010
},
14259 { "vr4100", 0, ISA_MIPS3
, CPU_VR4100
},
14260 { "vr4111", 0, ISA_MIPS3
, CPU_R4111
},
14261 { "vr4120", 0, ISA_MIPS3
, CPU_VR4120
},
14262 { "vr4130", 0, ISA_MIPS3
, CPU_VR4120
},
14263 { "vr4181", 0, ISA_MIPS3
, CPU_R4111
},
14264 { "vr4300", 0, ISA_MIPS3
, CPU_R4300
},
14265 { "r4400", 0, ISA_MIPS3
, CPU_R4400
},
14266 { "r4600", 0, ISA_MIPS3
, CPU_R4600
},
14267 { "orion", 0, ISA_MIPS3
, CPU_R4600
},
14268 { "r4650", 0, ISA_MIPS3
, CPU_R4650
},
14271 { "r8000", 0, ISA_MIPS4
, CPU_R8000
},
14272 { "r10000", 0, ISA_MIPS4
, CPU_R10000
},
14273 { "r12000", 0, ISA_MIPS4
, CPU_R12000
},
14274 { "vr5000", 0, ISA_MIPS4
, CPU_R5000
},
14275 { "vr5400", 0, ISA_MIPS4
, CPU_VR5400
},
14276 { "vr5500", 0, ISA_MIPS4
, CPU_VR5500
},
14277 { "rm5200", 0, ISA_MIPS4
, CPU_R5000
},
14278 { "rm5230", 0, ISA_MIPS4
, CPU_R5000
},
14279 { "rm5231", 0, ISA_MIPS4
, CPU_R5000
},
14280 { "rm5261", 0, ISA_MIPS4
, CPU_R5000
},
14281 { "rm5721", 0, ISA_MIPS4
, CPU_R5000
},
14282 { "r7000", 0, ISA_MIPS4
, CPU_R5000
},
14285 { "4kc", 0, ISA_MIPS32
, CPU_MIPS32
, },
14286 { "4km", 0, ISA_MIPS32
, CPU_MIPS32
},
14287 { "4kp", 0, ISA_MIPS32
, CPU_MIPS32
},
14290 { "5kc", 0, ISA_MIPS64
, CPU_MIPS64
},
14291 { "20kc", 0, ISA_MIPS64
, CPU_MIPS64
},
14293 /* Broadcom SB-1 CPU core */
14294 { "sb1", 0, ISA_MIPS64
, CPU_SB1
},
14301 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14302 with a final "000" replaced by "k". Ignore case.
14304 Note: this function is shared between GCC and GAS. */
14307 mips_strict_matching_cpu_name_p (canonical
, given
)
14308 const char *canonical
, *given
;
14310 while (*given
!= 0 && TOLOWER (*given
) == TOLOWER (*canonical
))
14311 given
++, canonical
++;
14313 return ((*given
== 0 && *canonical
== 0)
14314 || (strcmp (canonical
, "000") == 0 && strcasecmp (given
, "k") == 0));
14318 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14319 CPU name. We've traditionally allowed a lot of variation here.
14321 Note: this function is shared between GCC and GAS. */
14324 mips_matching_cpu_name_p (canonical
, given
)
14325 const char *canonical
, *given
;
14327 /* First see if the name matches exactly, or with a final "000"
14328 turned into "k". */
14329 if (mips_strict_matching_cpu_name_p (canonical
, given
))
14332 /* If not, try comparing based on numerical designation alone.
14333 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14334 if (TOLOWER (*given
) == 'r')
14336 if (!ISDIGIT (*given
))
14339 /* Skip over some well-known prefixes in the canonical name,
14340 hoping to find a number there too. */
14341 if (TOLOWER (canonical
[0]) == 'v' && TOLOWER (canonical
[1]) == 'r')
14343 else if (TOLOWER (canonical
[0]) == 'r' && TOLOWER (canonical
[1]) == 'm')
14345 else if (TOLOWER (canonical
[0]) == 'r')
14348 return mips_strict_matching_cpu_name_p (canonical
, given
);
14352 /* Parse an option that takes the name of a processor as its argument.
14353 OPTION is the name of the option and CPU_STRING is the argument.
14354 Return the corresponding processor enumeration if the CPU_STRING is
14355 recognized, otherwise report an error and return null.
14357 A similar function exists in GCC. */
14359 static const struct mips_cpu_info
*
14360 mips_parse_cpu (option
, cpu_string
)
14361 const char *option
, *cpu_string
;
14363 const struct mips_cpu_info
*p
;
14365 /* 'from-abi' selects the most compatible architecture for the given
14366 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14367 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14368 version. Look first at the -mgp options, if given, otherwise base
14369 the choice on MIPS_DEFAULT_64BIT.
14371 Treat NO_ABI like the EABIs. One reason to do this is that the
14372 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14373 architecture. This code picks MIPS I for 'mips' and MIPS III for
14374 'mips64', just as we did in the days before 'from-abi'. */
14375 if (strcasecmp (cpu_string
, "from-abi") == 0)
14377 if (ABI_NEEDS_32BIT_REGS (mips_abi
))
14378 return mips_cpu_info_from_isa (ISA_MIPS1
);
14380 if (ABI_NEEDS_64BIT_REGS (mips_abi
))
14381 return mips_cpu_info_from_isa (ISA_MIPS3
);
14383 if (file_mips_gp32
>= 0)
14384 return mips_cpu_info_from_isa (file_mips_gp32
? ISA_MIPS1
: ISA_MIPS3
);
14386 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14391 /* 'default' has traditionally been a no-op. Probably not very useful. */
14392 if (strcasecmp (cpu_string
, "default") == 0)
14395 for (p
= mips_cpu_info_table
; p
->name
!= 0; p
++)
14396 if (mips_matching_cpu_name_p (p
->name
, cpu_string
))
14399 as_bad ("Bad value (%s) for %s", cpu_string
, option
);
14403 /* Return the canonical processor information for ISA (a member of the
14404 ISA_MIPS* enumeration). */
14406 static const struct mips_cpu_info
*
14407 mips_cpu_info_from_isa (isa
)
14412 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
14413 if (mips_cpu_info_table
[i
].is_isa
14414 && isa
== mips_cpu_info_table
[i
].isa
)
14415 return (&mips_cpu_info_table
[i
]);
14421 show (stream
, string
, col_p
, first_p
)
14423 const char *string
;
14429 fprintf (stream
, "%24s", "");
14434 fprintf (stream
, ", ");
14438 if (*col_p
+ strlen (string
) > 72)
14440 fprintf (stream
, "\n%24s", "");
14444 fprintf (stream
, "%s", string
);
14445 *col_p
+= strlen (string
);
14451 md_show_usage (stream
)
14457 fprintf (stream
, _("\
14459 -membedded-pic generate embedded position independent code\n\
14460 -EB generate big endian output\n\
14461 -EL generate little endian output\n\
14462 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14463 -G NUM allow referencing objects up to NUM bytes\n\
14464 implicitly with the gp register [default 8]\n"));
14465 fprintf (stream
, _("\
14466 -mips1 generate MIPS ISA I instructions\n\
14467 -mips2 generate MIPS ISA II instructions\n\
14468 -mips3 generate MIPS ISA III instructions\n\
14469 -mips4 generate MIPS ISA IV instructions\n\
14470 -mips5 generate MIPS ISA V instructions\n\
14471 -mips32 generate MIPS32 ISA instructions\n\
14472 -mips64 generate MIPS64 ISA instructions\n\
14473 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14477 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
14478 show (stream
, mips_cpu_info_table
[i
].name
, &column
, &first
);
14479 show (stream
, "from-abi", &column
, &first
);
14480 fputc ('\n', stream
);
14482 fprintf (stream
, _("\
14483 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14484 -no-mCPU don't generate code specific to CPU.\n\
14485 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14489 show (stream
, "3900", &column
, &first
);
14490 show (stream
, "4010", &column
, &first
);
14491 show (stream
, "4100", &column
, &first
);
14492 show (stream
, "4650", &column
, &first
);
14493 fputc ('\n', stream
);
14495 fprintf (stream
, _("\
14496 -mips16 generate mips16 instructions\n\
14497 -no-mips16 do not generate mips16 instructions\n"));
14498 fprintf (stream
, _("\
14499 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14500 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14501 -O0 remove unneeded NOPs, do not swap branches\n\
14502 -O remove unneeded NOPs and swap branches\n\
14503 -n warn about NOPs generated from macros\n\
14504 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14505 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14506 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14508 fprintf (stream
, _("\
14509 -KPIC, -call_shared generate SVR4 position independent code\n\
14510 -non_shared do not generate position independent code\n\
14511 -xgot assume a 32 bit GOT\n\
14512 -mabi=ABI create ABI conformant object file for:\n"));
14516 show (stream
, "32", &column
, &first
);
14517 show (stream
, "o64", &column
, &first
);
14518 show (stream
, "n32", &column
, &first
);
14519 show (stream
, "64", &column
, &first
);
14520 show (stream
, "eabi", &column
, &first
);
14522 fputc ('\n', stream
);
14524 fprintf (stream
, _("\
14525 -32 create o32 ABI object file (default)\n\
14526 -n32 create n32 ABI object file\n\
14527 -64 create 64 ABI object file\n"));