1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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"
33 #include "opcode/mips.h"
35 #include "dwarf2dbg.h"
38 #define DBG(x) printf x
44 /* Clean up namespace so we can include obj-elf.h too. */
45 static int mips_output_flavor (void);
46 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
47 #undef OBJ_PROCESS_STAB
54 #undef obj_frob_file_after_relocs
55 #undef obj_frob_symbol
57 #undef obj_sec_sym_ok_for_reloc
58 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
61 /* Fix any of them that we actually care about. */
63 #define OUTPUT_FLAVOR mips_output_flavor()
70 #ifndef ECOFF_DEBUGGING
71 #define NO_ECOFF_DEBUGGING
72 #define ECOFF_DEBUGGING 0
75 int mips_flag_mdebug = -1;
79 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
80 static char *mips_regmask_frag;
86 #define PIC_CALL_REG 25
94 #define ILLEGAL_REG (32)
96 /* Allow override of standard little-endian ECOFF format. */
98 #ifndef ECOFF_LITTLE_FORMAT
99 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
102 extern int target_big_endian;
104 /* The name of the readonly data section. */
105 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
107 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
109 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
111 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
115 /* The ABI to use. */
126 /* MIPS ABI we are using for this output file. */
127 static enum mips_abi_level mips_abi = NO_ABI;
129 /* Whether or not we have code that can call pic code. */
130 int mips_abicalls = FALSE;
132 /* This is the set of options which may be modified by the .set
133 pseudo-op. We use a struct so that .set push and .set pop are more
136 struct mips_set_options
138 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
139 if it has not been initialized. Changed by `.set mipsN', and the
140 -mipsN command line option, and the default CPU. */
142 /* Enabled Application Specific Extensions (ASEs). These are set to -1
143 if they have not been initialized. Changed by `.set <asename>', by
144 command line options, and based on the default architecture. */
147 /* Whether we are assembling for the mips16 processor. 0 if we are
148 not, 1 if we are, and -1 if the value has not been initialized.
149 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
150 -nomips16 command line options, and the default CPU. */
152 /* Non-zero if we should not reorder instructions. Changed by `.set
153 reorder' and `.set noreorder'. */
155 /* Non-zero if we should not permit the $at ($1) register to be used
156 in instructions. Changed by `.set at' and `.set noat'. */
158 /* Non-zero if we should warn when a macro instruction expands into
159 more than one machine instruction. Changed by `.set nomacro' and
161 int warn_about_macros;
162 /* Non-zero if we should not move instructions. Changed by `.set
163 move', `.set volatile', `.set nomove', and `.set novolatile'. */
165 /* Non-zero if we should not optimize branches by moving the target
166 of the branch into the delay slot. Actually, we don't perform
167 this optimization anyhow. Changed by `.set bopt' and `.set
170 /* Non-zero if we should not autoextend mips16 instructions.
171 Changed by `.set autoextend' and `.set noautoextend'. */
173 /* Restrict general purpose registers and floating point registers
174 to 32 bit. This is initially determined when -mgp32 or -mfp32
175 is passed but can changed if the assembler code uses .set mipsN. */
178 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
179 command line option, and the default CPU. */
183 /* True if -mgp32 was passed. */
184 static int file_mips_gp32 = -1;
186 /* True if -mfp32 was passed. */
187 static int file_mips_fp32 = -1;
189 /* This is the struct we use to hold the current set of options. Note
190 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
191 -1 to indicate that they have not been initialized. */
193 static struct mips_set_options mips_opts =
195 ISA_UNKNOWN, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, CPU_UNKNOWN
198 /* These variables are filled in with the masks of registers used.
199 The object format code reads them and puts them in the appropriate
201 unsigned long mips_gprmask;
202 unsigned long mips_cprmask[4];
204 /* MIPS ISA we are using for this output file. */
205 static int file_mips_isa = ISA_UNKNOWN;
207 /* True if -mips16 was passed or implied by arguments passed on the
208 command line (e.g., by -march). */
209 static int file_ase_mips16;
211 /* True if -mips3d was passed or implied by arguments passed on the
212 command line (e.g., by -march). */
213 static int file_ase_mips3d;
215 /* True if -mdmx was passed or implied by arguments passed on the
216 command line (e.g., by -march). */
217 static int file_ase_mdmx;
219 /* The argument of the -march= flag. The architecture we are assembling. */
220 static int file_mips_arch = CPU_UNKNOWN;
221 static const char *mips_arch_string;
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;
228 /* True when generating 32-bit code for a 64-bit processor. */
229 static int mips_32bitmode = 0;
231 /* Some ISA's have delay slots for instructions which read or write
232 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
233 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
234 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
235 delay slot in this ISA. The uses of this macro assume that any
236 ISA that has delay slots for one of these, has them for all. They
237 also assume that ISAs which don't have delays for these insns, don't
238 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
239 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
241 || (ISA) == ISA_MIPS2 \
242 || (ISA) == ISA_MIPS3 \
245 /* True if the given ABI requires 32-bit registers. */
246 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
248 /* Likewise 64-bit registers. */
249 #define ABI_NEEDS_64BIT_REGS(ABI) \
251 || (ABI) == N64_ABI \
254 /* Return true if ISA supports 64 bit gp register instructions. */
255 #define ISA_HAS_64BIT_REGS(ISA) ( \
257 || (ISA) == ISA_MIPS4 \
258 || (ISA) == ISA_MIPS5 \
259 || (ISA) == ISA_MIPS64 \
262 /* Return true if ISA supports 64-bit right rotate (dror et al.)
264 #define ISA_HAS_DROR(ISA) ( \
268 /* Return true if ISA supports 32-bit right rotate (ror et al.)
270 #define ISA_HAS_ROR(ISA) ( \
271 (ISA) == ISA_MIPS32R2 \
274 #define HAVE_32BIT_GPRS \
275 (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
277 #define HAVE_32BIT_FPRS \
278 (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
280 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
281 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
283 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
285 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
287 /* We can only have 64bit addresses if the object file format
289 #define HAVE_32BIT_ADDRESSES \
291 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
292 || ! HAVE_64BIT_OBJECTS) \
293 && mips_pic != EMBEDDED_PIC))
295 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
296 #define HAVE_64BIT_ADDRESS_CONSTANTS (HAVE_64BIT_ADDRESSES \
299 /* Addresses are loaded in different ways, depending on the address size
300 in use. The n32 ABI Documentation also mandates the use of additions
301 with overflow checking, but existing implementations don't follow it. */
302 #define ADDRESS_ADD_INSN \
303 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
305 #define ADDRESS_ADDI_INSN \
306 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
308 #define ADDRESS_LOAD_INSN \
309 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
311 #define ADDRESS_STORE_INSN \
312 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
314 /* Return true if the given CPU supports the MIPS16 ASE. */
315 #define CPU_HAS_MIPS16(cpu) \
316 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
317 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
319 /* Return true if the given CPU supports the MIPS3D ASE. */
320 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
323 /* Return true if the given CPU supports the MDMX ASE. */
324 #define CPU_HAS_MDMX(cpu) (FALSE \
327 /* True if CPU has a dror instruction. */
328 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
330 /* True if CPU has a ror instruction. */
331 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
333 /* Whether the processor uses hardware interlocks to protect
334 reads from the HI and LO registers, and thus does not
335 require nops to be inserted. */
337 #define hilo_interlocks (mips_opts.arch == CPU_R4010 \
338 || mips_opts.arch == CPU_VR5500 \
339 || mips_opts.arch == CPU_SB1 \
342 /* Whether the processor uses hardware interlocks to protect reads
343 from the GPRs, and thus does not require nops to be inserted. */
344 #define gpr_interlocks \
345 (mips_opts.isa != ISA_MIPS1 \
346 || mips_opts.arch == CPU_VR5400 \
347 || mips_opts.arch == CPU_VR5500 \
348 || mips_opts.arch == CPU_R3900)
350 /* As with other "interlocks" this is used by hardware that has FP
351 (co-processor) interlocks. */
352 /* Itbl support may require additional care here. */
353 #define cop_interlocks (mips_opts.arch == CPU_R4300 \
354 || mips_opts.arch == CPU_VR5400 \
355 || mips_opts.arch == CPU_VR5500 \
356 || mips_opts.arch == CPU_SB1 \
359 /* Is this a mfhi or mflo instruction? */
360 #define MF_HILO_INSN(PINFO) \
361 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
363 /* MIPS PIC level. */
365 enum mips_pic_level mips_pic;
367 /* Warn about all NOPS that the assembler generates. */
368 static int warn_nops = 0;
370 /* 1 if we should generate 32 bit offsets from the $gp register in
371 SVR4_PIC mode. Currently has no meaning in other modes. */
372 static int mips_big_got = 0;
374 /* 1 if trap instructions should used for overflow rather than break
376 static int mips_trap = 0;
378 /* 1 if double width floating point constants should not be constructed
379 by assembling two single width halves into two single width floating
380 point registers which just happen to alias the double width destination
381 register. On some architectures this aliasing can be disabled by a bit
382 in the status register, and the setting of this bit cannot be determined
383 automatically at assemble time. */
384 static int mips_disable_float_construction;
386 /* Non-zero if any .set noreorder directives were used. */
388 static int mips_any_noreorder;
390 /* Non-zero if nops should be inserted when the register referenced in
391 an mfhi/mflo instruction is read in the next two instructions. */
392 static int mips_7000_hilo_fix;
394 /* The size of the small data section. */
395 static unsigned int g_switch_value = 8;
396 /* Whether the -G option was used. */
397 static int g_switch_seen = 0;
402 /* If we can determine in advance that GP optimization won't be
403 possible, we can skip the relaxation stuff that tries to produce
404 GP-relative references. This makes delay slot optimization work
407 This function can only provide a guess, but it seems to work for
408 gcc output. It needs to guess right for gcc, otherwise gcc
409 will put what it thinks is a GP-relative instruction in a branch
412 I don't know if a fix is needed for the SVR4_PIC mode. I've only
413 fixed it for the non-PIC mode. KR 95/04/07 */
414 static int nopic_need_relax (symbolS *, int);
416 /* handle of the OPCODE hash table */
417 static struct hash_control *op_hash = NULL;
419 /* The opcode hash table we use for the mips16. */
420 static struct hash_control *mips16_op_hash = NULL;
422 /* This array holds the chars that always start a comment. If the
423 pre-processor is disabled, these aren't very useful */
424 const char comment_chars[] = "#";
426 /* This array holds the chars that only start a comment at the beginning of
427 a line. If the line seems to have the form '# 123 filename'
428 .line and .file directives will appear in the pre-processed output */
429 /* Note that input_file.c hand checks for '#' at the beginning of the
430 first line of the input file. This is because the compiler outputs
431 #NO_APP at the beginning of its output. */
432 /* Also note that C style comments are always supported. */
433 const char line_comment_chars[] = "#";
435 /* This array holds machine specific line separator characters. */
436 const char line_separator_chars[] = ";";
438 /* Chars that can be used to separate mant from exp in floating point nums */
439 const char EXP_CHARS[] = "eE";
441 /* Chars that mean this number is a floating point constant */
444 const char FLT_CHARS[] = "rRsSfFdDxXpP";
446 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
447 changed in read.c . Ideally it shouldn't have to know about it at all,
448 but nothing is ideal around here.
451 static char *insn_error;
453 static int auto_align = 1;
455 /* When outputting SVR4 PIC code, the assembler needs to know the
456 offset in the stack frame from which to restore the $gp register.
457 This is set by the .cprestore pseudo-op, and saved in this
459 static offsetT mips_cprestore_offset = -1;
461 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
462 more optimizations, it can use a register value instead of a memory-saved
463 offset and even an other register than $gp as global pointer. */
464 static offsetT mips_cpreturn_offset = -1;
465 static int mips_cpreturn_register = -1;
466 static int mips_gp_register = GP;
467 static int mips_gprel_offset = 0;
469 /* Whether mips_cprestore_offset has been set in the current function
470 (or whether it has already been warned about, if not). */
471 static int mips_cprestore_valid = 0;
473 /* This is the register which holds the stack frame, as set by the
474 .frame pseudo-op. This is needed to implement .cprestore. */
475 static int mips_frame_reg = SP;
477 /* Whether mips_frame_reg has been set in the current function
478 (or whether it has already been warned about, if not). */
479 static int mips_frame_reg_valid = 0;
481 /* To output NOP instructions correctly, we need to keep information
482 about the previous two instructions. */
484 /* Whether we are optimizing. The default value of 2 means to remove
485 unneeded NOPs and swap branch instructions when possible. A value
486 of 1 means to not swap branches. A value of 0 means to always
488 static int mips_optimize = 2;
490 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
491 equivalent to seeing no -g option at all. */
492 static int mips_debug = 0;
494 /* The previous instruction. */
495 static struct mips_cl_insn prev_insn;
497 /* The instruction before prev_insn. */
498 static struct mips_cl_insn prev_prev_insn;
500 /* If we don't want information for prev_insn or prev_prev_insn, we
501 point the insn_mo field at this dummy integer. */
502 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
504 /* Non-zero if prev_insn is valid. */
505 static int prev_insn_valid;
507 /* The frag for the previous instruction. */
508 static struct frag *prev_insn_frag;
510 /* The offset into prev_insn_frag for the previous instruction. */
511 static long prev_insn_where;
513 /* The reloc type for the previous instruction, if any. */
514 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
516 /* The reloc for the previous instruction, if any. */
517 static fixS *prev_insn_fixp[3];
519 /* Non-zero if the previous instruction was in a delay slot. */
520 static int prev_insn_is_delay_slot;
522 /* Non-zero if the previous instruction was in a .set noreorder. */
523 static int prev_insn_unreordered;
525 /* Non-zero if the previous instruction uses an extend opcode (if
527 static int prev_insn_extended;
529 /* Non-zero if the previous previous instruction was in a .set
531 static int prev_prev_insn_unreordered;
533 /* If this is set, it points to a frag holding nop instructions which
534 were inserted before the start of a noreorder section. If those
535 nops turn out to be unnecessary, the size of the frag can be
537 static fragS *prev_nop_frag;
539 /* The number of nop instructions we created in prev_nop_frag. */
540 static int prev_nop_frag_holds;
542 /* The number of nop instructions that we know we need in
544 static int prev_nop_frag_required;
546 /* The number of instructions we've seen since prev_nop_frag. */
547 static int prev_nop_frag_since;
549 /* For ECOFF and ELF, relocations against symbols are done in two
550 parts, with a HI relocation and a LO relocation. Each relocation
551 has only 16 bits of space to store an addend. This means that in
552 order for the linker to handle carries correctly, it must be able
553 to locate both the HI and the LO relocation. This means that the
554 relocations must appear in order in the relocation table.
556 In order to implement this, we keep track of each unmatched HI
557 relocation. We then sort them so that they immediately precede the
558 corresponding LO relocation. */
563 struct mips_hi_fixup *next;
566 /* The section this fixup is in. */
570 /* The list of unmatched HI relocs. */
572 static struct mips_hi_fixup *mips_hi_fixup_list;
574 /* The frag containing the last explicit relocation operator.
575 Null if explicit relocations have not been used. */
577 static fragS *prev_reloc_op_frag;
579 /* Map normal MIPS register numbers to mips16 register numbers. */
581 #define X ILLEGAL_REG
582 static const int mips32_to_16_reg_map[] =
584 X, X, 2, 3, 4, 5, 6, 7,
585 X, X, X, X, X, X, X, X,
586 0, 1, X, X, X, X, X, X,
587 X, X, X, X, X, X, X, X
591 /* Map mips16 register numbers to normal MIPS register numbers. */
593 static const unsigned int mips16_to_32_reg_map[] =
595 16, 17, 2, 3, 4, 5, 6, 7
598 static int mips_fix_4122_bugs;
600 /* We don't relax branches by default, since this causes us to expand
601 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
602 fail to compute the offset before expanding the macro to the most
603 efficient expansion. */
605 static int mips_relax_branch;
607 /* Since the MIPS does not have multiple forms of PC relative
608 instructions, we do not have to do relaxing as is done on other
609 platforms. However, we do have to handle GP relative addressing
610 correctly, which turns out to be a similar problem.
612 Every macro that refers to a symbol can occur in (at least) two
613 forms, one with GP relative addressing and one without. For
614 example, loading a global variable into a register generally uses
615 a macro instruction like this:
617 If i can be addressed off the GP register (this is true if it is in
618 the .sbss or .sdata section, or if it is known to be smaller than
619 the -G argument) this will generate the following instruction:
621 This instruction will use a GPREL reloc. If i can not be addressed
622 off the GP register, the following instruction sequence will be used:
625 In this case the first instruction will have a HI16 reloc, and the
626 second reloc will have a LO16 reloc. Both relocs will be against
629 The issue here is that we may not know whether i is GP addressable
630 until after we see the instruction that uses it. Therefore, we
631 want to be able to choose the final instruction sequence only at
632 the end of the assembly. This is similar to the way other
633 platforms choose the size of a PC relative instruction only at the
636 When generating position independent code we do not use GP
637 addressing in quite the same way, but the issue still arises as
638 external symbols and local symbols must be handled differently.
640 We handle these issues by actually generating both possible
641 instruction sequences. The longer one is put in a frag_var with
642 type rs_machine_dependent. We encode what to do with the frag in
643 the subtype field. We encode (1) the number of existing bytes to
644 replace, (2) the number of new bytes to use, (3) the offset from
645 the start of the existing bytes to the first reloc we must generate
646 (that is, the offset is applied from the start of the existing
647 bytes after they are replaced by the new bytes, if any), (4) the
648 offset from the start of the existing bytes to the second reloc,
649 (5) whether a third reloc is needed (the third reloc is always four
650 bytes after the second reloc), and (6) whether to warn if this
651 variant is used (this is sometimes needed if .set nomacro or .set
652 noat is in effect). All these numbers are reasonably small.
654 Generating two instruction sequences must be handled carefully to
655 ensure that delay slots are handled correctly. Fortunately, there
656 are a limited number of cases. When the second instruction
657 sequence is generated, append_insn is directed to maintain the
658 existing delay slot information, so it continues to apply to any
659 code after the second instruction sequence. This means that the
660 second instruction sequence must not impose any requirements not
661 required by the first instruction sequence.
663 These variant frags are then handled in functions called by the
664 machine independent code. md_estimate_size_before_relax returns
665 the final size of the frag. md_convert_frag sets up the final form
666 of the frag. tc_gen_reloc adjust the first reloc and adds a second
668 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
672 | (((reloc1) + 64) << 9) \
673 | (((reloc2) + 64) << 2) \
674 | ((reloc3) ? (1 << 1) : 0) \
676 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
677 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
678 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
679 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
680 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
681 #define RELAX_WARN(i) ((i) & 1)
683 /* Branch without likely bit. If label is out of range, we turn:
685 beq reg1, reg2, label
695 with the following opcode replacements:
702 bltzal <-> bgezal (with jal label instead of j label)
704 Even though keeping the delay slot instruction in the delay slot of
705 the branch would be more efficient, it would be very tricky to do
706 correctly, because we'd have to introduce a variable frag *after*
707 the delay slot instruction, and expand that instead. Let's do it
708 the easy way for now, even if the branch-not-taken case now costs
709 one additional instruction. Out-of-range branches are not supposed
710 to be common, anyway.
712 Branch likely. If label is out of range, we turn:
714 beql reg1, reg2, label
715 delay slot (annulled if branch not taken)
724 delay slot (executed only if branch taken)
727 It would be possible to generate a shorter sequence by losing the
728 likely bit, generating something like:
733 delay slot (executed only if branch taken)
745 bltzall -> bgezal (with jal label instead of j label)
746 bgezall -> bltzal (ditto)
749 but it's not clear that it would actually improve performance. */
750 #define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
753 | ((toofar) ? 1 : 0) \
755 | ((likely) ? 4 : 0) \
756 | ((uncond) ? 8 : 0)))
757 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
758 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
759 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
760 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
761 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1) != 0)
763 /* For mips16 code, we use an entirely different form of relaxation.
764 mips16 supports two versions of most instructions which take
765 immediate values: a small one which takes some small value, and a
766 larger one which takes a 16 bit value. Since branches also follow
767 this pattern, relaxing these values is required.
769 We can assemble both mips16 and normal MIPS code in a single
770 object. Therefore, we need to support this type of relaxation at
771 the same time that we support the relaxation described above. We
772 use the high bit of the subtype field to distinguish these cases.
774 The information we store for this type of relaxation is the
775 argument code found in the opcode file for this relocation, whether
776 the user explicitly requested a small or extended form, and whether
777 the relocation is in a jump or jal delay slot. That tells us the
778 size of the value, and how it should be stored. We also store
779 whether the fragment is considered to be extended or not. We also
780 store whether this is known to be a branch to a different section,
781 whether we have tried to relax this frag yet, and whether we have
782 ever extended a PC relative fragment because of a shift count. */
783 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
786 | ((small) ? 0x100 : 0) \
787 | ((ext) ? 0x200 : 0) \
788 | ((dslot) ? 0x400 : 0) \
789 | ((jal_dslot) ? 0x800 : 0))
790 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
791 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
792 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
793 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
794 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
795 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
796 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
797 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
798 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
799 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
800 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
801 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
803 /* Is the given value a sign-extended 32-bit value? */
804 #define IS_SEXT_32BIT_NUM(x) \
805 (((x) &~ (offsetT) 0x7fffffff) == 0 \
806 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
808 /* Is the given value a sign-extended 16-bit value? */
809 #define IS_SEXT_16BIT_NUM(x) \
810 (((x) &~ (offsetT) 0x7fff) == 0 \
811 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
814 /* Prototypes for static functions. */
816 #define internalError() \
817 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
819 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
821 static void append_insn
822 (char *place, struct mips_cl_insn *ip, expressionS *p,
823 bfd_reloc_code_real_type *r);
824 static void mips_no_prev_insn (int);
825 static void mips16_macro_build
826 (char *, int *, expressionS *, const char *, const char *, va_list);
827 static void load_register (int *, int, expressionS *, int);
828 static void macro (struct mips_cl_insn * ip);
829 static void mips16_macro (struct mips_cl_insn * ip);
830 #ifdef LOSING_COMPILER
831 static void macro2 (struct mips_cl_insn * ip);
833 static void mips_ip (char *str, struct mips_cl_insn * ip);
834 static void mips16_ip (char *str, struct mips_cl_insn * ip);
835 static void mips16_immed
836 (char *, unsigned int, int, offsetT, bfd_boolean, bfd_boolean, bfd_boolean,
837 unsigned long *, bfd_boolean *, unsigned short *);
838 static size_t my_getSmallExpression
839 (expressionS *, bfd_reloc_code_real_type *, char *);
840 static void my_getExpression (expressionS *, char *);
841 static void s_align (int);
842 static void s_change_sec (int);
843 static void s_change_section (int);
844 static void s_cons (int);
845 static void s_float_cons (int);
846 static void s_mips_globl (int);
847 static void s_option (int);
848 static void s_mipsset (int);
849 static void s_abicalls (int);
850 static void s_cpload (int);
851 static void s_cpsetup (int);
852 static void s_cplocal (int);
853 static void s_cprestore (int);
854 static void s_cpreturn (int);
855 static void s_gpvalue (int);
856 static void s_gpword (int);
857 static void s_gpdword (int);
858 static void s_cpadd (int);
859 static void s_insn (int);
860 static void md_obj_begin (void);
861 static void md_obj_end (void);
862 static void s_mips_ent (int);
863 static void s_mips_end (int);
864 static void s_mips_frame (int);
865 static void s_mips_mask (int reg_type);
866 static void s_mips_stab (int);
867 static void s_mips_weakext (int);
868 static void s_mips_file (int);
869 static void s_mips_loc (int);
870 static bfd_boolean pic_need_relax (symbolS *, asection *);
871 static int relaxed_branch_length (fragS *, asection *, int);
872 static int validate_mips_insn (const struct mips_opcode *);
874 /* Table and functions used to map between CPU/ISA names, and
875 ISA levels, and CPU numbers. */
879 const char *name; /* CPU or ISA name. */
880 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
881 int isa; /* ISA level. */
882 int cpu; /* CPU number (default CPU if ISA). */
885 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
886 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
887 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
891 The following pseudo-ops from the Kane and Heinrich MIPS book
892 should be defined here, but are currently unsupported: .alias,
893 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
895 The following pseudo-ops from the Kane and Heinrich MIPS book are
896 specific to the type of debugging information being generated, and
897 should be defined by the object format: .aent, .begin, .bend,
898 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
901 The following pseudo-ops from the Kane and Heinrich MIPS book are
902 not MIPS CPU specific, but are also not specific to the object file
903 format. This file is probably the best place to define them, but
904 they are not currently supported: .asm0, .endr, .lab, .repeat,
907 static const pseudo_typeS mips_pseudo_table[] =
909 /* MIPS specific pseudo-ops. */
910 {"option", s_option, 0},
911 {"set", s_mipsset, 0},
912 {"rdata", s_change_sec, 'r'},
913 {"sdata", s_change_sec, 's'},
914 {"livereg", s_ignore, 0},
915 {"abicalls", s_abicalls, 0},
916 {"cpload", s_cpload, 0},
917 {"cpsetup", s_cpsetup, 0},
918 {"cplocal", s_cplocal, 0},
919 {"cprestore", s_cprestore, 0},
920 {"cpreturn", s_cpreturn, 0},
921 {"gpvalue", s_gpvalue, 0},
922 {"gpword", s_gpword, 0},
923 {"gpdword", s_gpdword, 0},
924 {"cpadd", s_cpadd, 0},
927 /* Relatively generic pseudo-ops that happen to be used on MIPS
929 {"asciiz", stringer, 1},
930 {"bss", s_change_sec, 'b'},
933 {"dword", s_cons, 3},
934 {"weakext", s_mips_weakext, 0},
936 /* These pseudo-ops are defined in read.c, but must be overridden
937 here for one reason or another. */
938 {"align", s_align, 0},
940 {"data", s_change_sec, 'd'},
941 {"double", s_float_cons, 'd'},
942 {"float", s_float_cons, 'f'},
943 {"globl", s_mips_globl, 0},
944 {"global", s_mips_globl, 0},
945 {"hword", s_cons, 1},
950 {"section", s_change_section, 0},
951 {"short", s_cons, 1},
952 {"single", s_float_cons, 'f'},
953 {"stabn", s_mips_stab, 'n'},
954 {"text", s_change_sec, 't'},
957 { "extern", ecoff_directive_extern, 0},
962 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
964 /* These pseudo-ops should be defined by the object file format.
965 However, a.out doesn't support them, so we have versions here. */
966 {"aent", s_mips_ent, 1},
967 {"bgnb", s_ignore, 0},
968 {"end", s_mips_end, 0},
969 {"endb", s_ignore, 0},
970 {"ent", s_mips_ent, 0},
971 {"file", s_mips_file, 0},
972 {"fmask", s_mips_mask, 'F'},
973 {"frame", s_mips_frame, 0},
974 {"loc", s_mips_loc, 0},
975 {"mask", s_mips_mask, 'R'},
976 {"verstamp", s_ignore, 0},
980 extern void pop_insert (const pseudo_typeS *);
983 mips_pop_insert (void)
985 pop_insert (mips_pseudo_table);
986 if (! ECOFF_DEBUGGING)
987 pop_insert (mips_nonecoff_pseudo_table);
990 /* Symbols labelling the current insn. */
992 struct insn_label_list
994 struct insn_label_list *next;
998 static struct insn_label_list *insn_labels;
999 static struct insn_label_list *free_insn_labels;
1001 static void mips_clear_insn_labels (void);
1004 mips_clear_insn_labels (void)
1006 register struct insn_label_list **pl;
1008 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1014 static char *expr_end;
1016 /* Expressions which appear in instructions. These are set by
1019 static expressionS imm_expr;
1020 static expressionS offset_expr;
1022 /* Relocs associated with imm_expr and offset_expr. */
1024 static bfd_reloc_code_real_type imm_reloc[3]
1025 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1026 static bfd_reloc_code_real_type offset_reloc[3]
1027 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1029 /* These are set by mips16_ip if an explicit extension is used. */
1031 static bfd_boolean mips16_small, mips16_ext;
1034 /* The pdr segment for per procedure frame/regmask info. Not used for
1037 static segT pdr_seg;
1040 /* The default target format to use. */
1043 mips_target_format (void)
1045 switch (OUTPUT_FLAVOR)
1047 case bfd_target_aout_flavour:
1048 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
1049 case bfd_target_ecoff_flavour:
1050 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1051 case bfd_target_coff_flavour:
1053 case bfd_target_elf_flavour:
1055 /* This is traditional mips. */
1056 return (target_big_endian
1057 ? (HAVE_64BIT_OBJECTS
1058 ? "elf64-tradbigmips"
1060 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1061 : (HAVE_64BIT_OBJECTS
1062 ? "elf64-tradlittlemips"
1064 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1066 return (target_big_endian
1067 ? (HAVE_64BIT_OBJECTS
1070 ? "elf32-nbigmips" : "elf32-bigmips"))
1071 : (HAVE_64BIT_OBJECTS
1072 ? "elf64-littlemips"
1074 ? "elf32-nlittlemips" : "elf32-littlemips")));
1082 /* This function is called once, at assembler startup time. It should
1083 set up all the tables, etc. that the MD part of the assembler will need. */
1088 register const char *retval = NULL;
1092 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
1093 as_warn (_("Could not set architecture and machine"));
1095 op_hash = hash_new ();
1097 for (i = 0; i < NUMOPCODES;)
1099 const char *name = mips_opcodes[i].name;
1101 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
1104 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1105 mips_opcodes[i].name, retval);
1106 /* Probably a memory allocation problem? Give up now. */
1107 as_fatal (_("Broken assembler. No assembly attempted."));
1111 if (mips_opcodes[i].pinfo != INSN_MACRO)
1113 if (!validate_mips_insn (&mips_opcodes[i]))
1118 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1121 mips16_op_hash = hash_new ();
1124 while (i < bfd_mips16_num_opcodes)
1126 const char *name = mips16_opcodes[i].name;
1128 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
1130 as_fatal (_("internal: can't hash `%s': %s"),
1131 mips16_opcodes[i].name, retval);
1134 if (mips16_opcodes[i].pinfo != INSN_MACRO
1135 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1136 != mips16_opcodes[i].match))
1138 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1139 mips16_opcodes[i].name, mips16_opcodes[i].args);
1144 while (i < bfd_mips16_num_opcodes
1145 && strcmp (mips16_opcodes[i].name, name) == 0);
1149 as_fatal (_("Broken assembler. No assembly attempted."));
1151 /* We add all the general register names to the symbol table. This
1152 helps us detect invalid uses of them. */
1153 for (i = 0; i < 32; i++)
1157 sprintf (buf, "$%d", i);
1158 symbol_table_insert (symbol_new (buf, reg_section, i,
1159 &zero_address_frag));
1161 symbol_table_insert (symbol_new ("$ra", reg_section, RA,
1162 &zero_address_frag));
1163 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1164 &zero_address_frag));
1165 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1166 &zero_address_frag));
1167 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1168 &zero_address_frag));
1169 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1170 &zero_address_frag));
1171 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1172 &zero_address_frag));
1173 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1174 &zero_address_frag));
1175 symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
1176 &zero_address_frag));
1177 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1178 &zero_address_frag));
1180 /* If we don't add these register names to the symbol table, they
1181 may end up being added as regular symbols by operand(), and then
1182 make it to the object file as undefined in case they're not
1183 regarded as local symbols. They're local in o32, since `$' is a
1184 local symbol prefix, but not in n32 or n64. */
1185 for (i = 0; i < 8; i++)
1189 sprintf (buf, "$fcc%i", i);
1190 symbol_table_insert (symbol_new (buf, reg_section, -1,
1191 &zero_address_frag));
1194 mips_no_prev_insn (FALSE);
1197 mips_cprmask[0] = 0;
1198 mips_cprmask[1] = 0;
1199 mips_cprmask[2] = 0;
1200 mips_cprmask[3] = 0;
1202 /* set the default alignment for the text section (2**2) */
1203 record_alignment (text_section, 2);
1205 if (USE_GLOBAL_POINTER_OPT)
1206 bfd_set_gp_size (stdoutput, g_switch_value);
1208 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1210 /* On a native system, sections must be aligned to 16 byte
1211 boundaries. When configured for an embedded ELF target, we
1213 if (strcmp (TARGET_OS, "elf") != 0)
1215 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1216 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1217 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1220 /* Create a .reginfo section for register masks and a .mdebug
1221 section for debugging information. */
1229 subseg = now_subseg;
1231 /* The ABI says this section should be loaded so that the
1232 running program can access it. However, we don't load it
1233 if we are configured for an embedded target */
1234 flags = SEC_READONLY | SEC_DATA;
1235 if (strcmp (TARGET_OS, "elf") != 0)
1236 flags |= SEC_ALLOC | SEC_LOAD;
1238 if (mips_abi != N64_ABI)
1240 sec = subseg_new (".reginfo", (subsegT) 0);
1242 bfd_set_section_flags (stdoutput, sec, flags);
1243 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1246 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1251 /* The 64-bit ABI uses a .MIPS.options section rather than
1252 .reginfo section. */
1253 sec = subseg_new (".MIPS.options", (subsegT) 0);
1254 bfd_set_section_flags (stdoutput, sec, flags);
1255 bfd_set_section_alignment (stdoutput, sec, 3);
1258 /* Set up the option header. */
1260 Elf_Internal_Options opthdr;
1263 opthdr.kind = ODK_REGINFO;
1264 opthdr.size = (sizeof (Elf_External_Options)
1265 + sizeof (Elf64_External_RegInfo));
1268 f = frag_more (sizeof (Elf_External_Options));
1269 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1270 (Elf_External_Options *) f);
1272 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1277 if (ECOFF_DEBUGGING)
1279 sec = subseg_new (".mdebug", (subsegT) 0);
1280 (void) bfd_set_section_flags (stdoutput, sec,
1281 SEC_HAS_CONTENTS | SEC_READONLY);
1282 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1285 else if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1287 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1288 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1289 SEC_READONLY | SEC_RELOC
1291 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1295 subseg_set (seg, subseg);
1299 if (! ECOFF_DEBUGGING)
1306 if (! ECOFF_DEBUGGING)
1311 md_assemble (char *str)
1313 struct mips_cl_insn insn;
1314 bfd_reloc_code_real_type unused_reloc[3]
1315 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1317 imm_expr.X_op = O_absent;
1318 offset_expr.X_op = O_absent;
1319 imm_reloc[0] = BFD_RELOC_UNUSED;
1320 imm_reloc[1] = BFD_RELOC_UNUSED;
1321 imm_reloc[2] = BFD_RELOC_UNUSED;
1322 offset_reloc[0] = BFD_RELOC_UNUSED;
1323 offset_reloc[1] = BFD_RELOC_UNUSED;
1324 offset_reloc[2] = BFD_RELOC_UNUSED;
1326 if (mips_opts.mips16)
1327 mips16_ip (str, &insn);
1330 mips_ip (str, &insn);
1331 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1332 str, insn.insn_opcode));
1337 as_bad ("%s `%s'", insn_error, str);
1341 if (insn.insn_mo->pinfo == INSN_MACRO)
1343 if (mips_opts.mips16)
1344 mips16_macro (&insn);
1350 if (imm_expr.X_op != O_absent)
1351 append_insn (NULL, &insn, &imm_expr, imm_reloc);
1352 else if (offset_expr.X_op != O_absent)
1353 append_insn (NULL, &insn, &offset_expr, offset_reloc);
1355 append_insn (NULL, &insn, NULL, unused_reloc);
1359 /* Return true if the given relocation might need a matching %lo().
1360 Note that R_MIPS_GOT16 relocations only need a matching %lo() when
1361 applied to local symbols. */
1363 static inline bfd_boolean
1364 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
1366 return (reloc == BFD_RELOC_HI16_S
1367 || reloc == BFD_RELOC_MIPS_GOT16);
1370 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
1373 static inline bfd_boolean
1374 fixup_has_matching_lo_p (fixS *fixp)
1376 return (fixp->fx_next != NULL
1377 && fixp->fx_next->fx_r_type == BFD_RELOC_LO16
1378 && fixp->fx_addsy == fixp->fx_next->fx_addsy
1379 && fixp->fx_offset == fixp->fx_next->fx_offset);
1382 /* See whether instruction IP reads register REG. CLASS is the type
1386 insn_uses_reg (struct mips_cl_insn *ip, unsigned int reg,
1387 enum mips_regclass class)
1389 if (class == MIPS16_REG)
1391 assert (mips_opts.mips16);
1392 reg = mips16_to_32_reg_map[reg];
1393 class = MIPS_GR_REG;
1396 /* Don't report on general register ZERO, since it never changes. */
1397 if (class == MIPS_GR_REG && reg == ZERO)
1400 if (class == MIPS_FP_REG)
1402 assert (! mips_opts.mips16);
1403 /* If we are called with either $f0 or $f1, we must check $f0.
1404 This is not optimal, because it will introduce an unnecessary
1405 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1406 need to distinguish reading both $f0 and $f1 or just one of
1407 them. Note that we don't have to check the other way,
1408 because there is no instruction that sets both $f0 and $f1
1409 and requires a delay. */
1410 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1411 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1412 == (reg &~ (unsigned) 1)))
1414 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1415 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1416 == (reg &~ (unsigned) 1)))
1419 else if (! mips_opts.mips16)
1421 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1422 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1424 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1425 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1430 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1431 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1432 & MIPS16OP_MASK_RX)]
1435 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1436 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1437 & MIPS16OP_MASK_RY)]
1440 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1441 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1442 & MIPS16OP_MASK_MOVE32Z)]
1445 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1447 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1449 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1451 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1452 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1453 & MIPS16OP_MASK_REGR32) == reg)
1460 /* This function returns true if modifying a register requires a
1464 reg_needs_delay (unsigned int reg)
1466 unsigned long prev_pinfo;
1468 prev_pinfo = prev_insn.insn_mo->pinfo;
1469 if (! mips_opts.noreorder
1470 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1471 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1472 || (! gpr_interlocks
1473 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1475 /* A load from a coprocessor or from memory. All load
1476 delays delay the use of general register rt for one
1477 instruction on the r3000. The r6000 and r4000 use
1479 /* Itbl support may require additional care here. */
1480 know (prev_pinfo & INSN_WRITE_GPR_T);
1481 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1488 /* Mark instruction labels in mips16 mode. This permits the linker to
1489 handle them specially, such as generating jalx instructions when
1490 needed. We also make them odd for the duration of the assembly, in
1491 order to generate the right sort of code. We will make them even
1492 in the adjust_symtab routine, while leaving them marked. This is
1493 convenient for the debugger and the disassembler. The linker knows
1494 to make them odd again. */
1497 mips16_mark_labels (void)
1499 if (mips_opts.mips16)
1501 struct insn_label_list *l;
1504 for (l = insn_labels; l != NULL; l = l->next)
1507 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1508 S_SET_OTHER (l->label, STO_MIPS16);
1510 val = S_GET_VALUE (l->label);
1512 S_SET_VALUE (l->label, val + 1);
1517 /* Output an instruction. PLACE is where to put the instruction; if
1518 it is NULL, this uses frag_more to get room. IP is the instruction
1519 information. ADDRESS_EXPR is an operand of the instruction to be
1520 used with RELOC_TYPE. */
1523 append_insn (char *place, struct mips_cl_insn *ip, expressionS *address_expr,
1524 bfd_reloc_code_real_type *reloc_type)
1526 register unsigned long prev_pinfo, pinfo;
1530 bfd_boolean force_new_frag = FALSE;
1532 /* Mark instruction labels in mips16 mode. */
1533 mips16_mark_labels ();
1535 prev_pinfo = prev_insn.insn_mo->pinfo;
1536 pinfo = ip->insn_mo->pinfo;
1538 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1542 /* If the previous insn required any delay slots, see if we need
1543 to insert a NOP or two. There are eight kinds of possible
1544 hazards, of which an instruction can have at most one type.
1545 (1) a load from memory delay
1546 (2) a load from a coprocessor delay
1547 (3) an unconditional branch delay
1548 (4) a conditional branch delay
1549 (5) a move to coprocessor register delay
1550 (6) a load coprocessor register from memory delay
1551 (7) a coprocessor condition code delay
1552 (8) a HI/LO special register delay
1554 There are a lot of optimizations we could do that we don't.
1555 In particular, we do not, in general, reorder instructions.
1556 If you use gcc with optimization, it will reorder
1557 instructions and generally do much more optimization then we
1558 do here; repeating all that work in the assembler would only
1559 benefit hand written assembly code, and does not seem worth
1562 /* This is how a NOP is emitted. */
1563 #define emit_nop() \
1565 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1566 : md_number_to_chars (frag_more (4), 0, 4))
1568 /* The previous insn might require a delay slot, depending upon
1569 the contents of the current insn. */
1570 if (! mips_opts.mips16
1571 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1572 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1573 && ! cop_interlocks)
1574 || (! gpr_interlocks
1575 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1577 /* A load from a coprocessor or from memory. All load
1578 delays delay the use of general register rt for one
1579 instruction on the r3000. The r6000 and r4000 use
1581 /* Itbl support may require additional care here. */
1582 know (prev_pinfo & INSN_WRITE_GPR_T);
1583 if (mips_optimize == 0
1584 || insn_uses_reg (ip,
1585 ((prev_insn.insn_opcode >> OP_SH_RT)
1590 else if (! mips_opts.mips16
1591 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1592 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1593 && ! cop_interlocks)
1594 || (mips_opts.isa == ISA_MIPS1
1595 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1597 /* A generic coprocessor delay. The previous instruction
1598 modified a coprocessor general or control register. If
1599 it modified a control register, we need to avoid any
1600 coprocessor instruction (this is probably not always
1601 required, but it sometimes is). If it modified a general
1602 register, we avoid using that register.
1604 On the r6000 and r4000 loading a coprocessor register
1605 from memory is interlocked, and does not require a delay.
1607 This case is not handled very well. There is no special
1608 knowledge of CP0 handling, and the coprocessors other
1609 than the floating point unit are not distinguished at
1611 /* Itbl support may require additional care here. FIXME!
1612 Need to modify this to include knowledge about
1613 user specified delays! */
1614 if (prev_pinfo & INSN_WRITE_FPR_T)
1616 if (mips_optimize == 0
1617 || insn_uses_reg (ip,
1618 ((prev_insn.insn_opcode >> OP_SH_FT)
1623 else if (prev_pinfo & INSN_WRITE_FPR_S)
1625 if (mips_optimize == 0
1626 || insn_uses_reg (ip,
1627 ((prev_insn.insn_opcode >> OP_SH_FS)
1634 /* We don't know exactly what the previous instruction
1635 does. If the current instruction uses a coprocessor
1636 register, we must insert a NOP. If previous
1637 instruction may set the condition codes, and the
1638 current instruction uses them, we must insert two
1640 /* Itbl support may require additional care here. */
1641 if (mips_optimize == 0
1642 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1643 && (pinfo & INSN_READ_COND_CODE)))
1645 else if (pinfo & INSN_COP)
1649 else if (! mips_opts.mips16
1650 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1651 && (prev_pinfo & INSN_WRITE_COND_CODE)
1652 && ! cop_interlocks)
1654 /* The previous instruction sets the coprocessor condition
1655 codes, but does not require a general coprocessor delay
1656 (this means it is a floating point comparison
1657 instruction). If this instruction uses the condition
1658 codes, we need to insert a single NOP. */
1659 /* Itbl support may require additional care here. */
1660 if (mips_optimize == 0
1661 || (pinfo & INSN_READ_COND_CODE))
1665 /* If we're fixing up mfhi/mflo for the r7000 and the
1666 previous insn was an mfhi/mflo and the current insn
1667 reads the register that the mfhi/mflo wrote to, then
1670 else if (mips_7000_hilo_fix
1671 && MF_HILO_INSN (prev_pinfo)
1672 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1679 /* If we're fixing up mfhi/mflo for the r7000 and the
1680 2nd previous insn was an mfhi/mflo and the current insn
1681 reads the register that the mfhi/mflo wrote to, then
1684 else if (mips_7000_hilo_fix
1685 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1686 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1694 else if (prev_pinfo & INSN_READ_LO)
1696 /* The previous instruction reads the LO register; if the
1697 current instruction writes to the LO register, we must
1698 insert two NOPS. Some newer processors have interlocks.
1699 Also the tx39's multiply instructions can be exectuted
1700 immediatly after a read from HI/LO (without the delay),
1701 though the tx39's divide insns still do require the
1703 if (! (hilo_interlocks
1704 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1705 && (mips_optimize == 0
1706 || (pinfo & INSN_WRITE_LO)))
1708 /* Most mips16 branch insns don't have a delay slot.
1709 If a read from LO is immediately followed by a branch
1710 to a write to LO we have a read followed by a write
1711 less than 2 insns away. We assume the target of
1712 a branch might be a write to LO, and insert a nop
1713 between a read and an immediately following branch. */
1714 else if (mips_opts.mips16
1715 && (mips_optimize == 0
1716 || (pinfo & MIPS16_INSN_BRANCH)))
1719 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1721 /* The previous instruction reads the HI register; if the
1722 current instruction writes to the HI register, we must
1723 insert a NOP. Some newer processors have interlocks.
1724 Also the note tx39's multiply above. */
1725 if (! (hilo_interlocks
1726 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1727 && (mips_optimize == 0
1728 || (pinfo & INSN_WRITE_HI)))
1730 /* Most mips16 branch insns don't have a delay slot.
1731 If a read from HI is immediately followed by a branch
1732 to a write to HI we have a read followed by a write
1733 less than 2 insns away. We assume the target of
1734 a branch might be a write to HI, and insert a nop
1735 between a read and an immediately following branch. */
1736 else if (mips_opts.mips16
1737 && (mips_optimize == 0
1738 || (pinfo & MIPS16_INSN_BRANCH)))
1742 /* If the previous instruction was in a noreorder section, then
1743 we don't want to insert the nop after all. */
1744 /* Itbl support may require additional care here. */
1745 if (prev_insn_unreordered)
1748 /* There are two cases which require two intervening
1749 instructions: 1) setting the condition codes using a move to
1750 coprocessor instruction which requires a general coprocessor
1751 delay and then reading the condition codes 2) reading the HI
1752 or LO register and then writing to it (except on processors
1753 which have interlocks). If we are not already emitting a NOP
1754 instruction, we must check for these cases compared to the
1755 instruction previous to the previous instruction. */
1756 if ((! mips_opts.mips16
1757 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1758 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1759 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1760 && (pinfo & INSN_READ_COND_CODE)
1761 && ! cop_interlocks)
1762 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1763 && (pinfo & INSN_WRITE_LO)
1764 && ! (hilo_interlocks
1765 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1766 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1767 && (pinfo & INSN_WRITE_HI)
1768 && ! (hilo_interlocks
1769 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1774 if (prev_prev_insn_unreordered)
1777 if (prev_prev_nop && nops == 0)
1780 if (mips_fix_4122_bugs && prev_insn.insn_mo->name)
1782 /* We're out of bits in pinfo, so we must resort to string
1783 ops here. Shortcuts are selected based on opcodes being
1784 limited to the VR4122 instruction set. */
1786 const char *pn = prev_insn.insn_mo->name;
1787 const char *tn = ip->insn_mo->name;
1788 if (strncmp(pn, "macc", 4) == 0
1789 || strncmp(pn, "dmacc", 5) == 0)
1791 /* Errata 21 - [D]DIV[U] after [D]MACC */
1792 if (strstr (tn, "div"))
1797 /* Errata 23 - Continuous DMULT[U]/DMACC instructions */
1798 if (pn[0] == 'd' /* dmacc */
1799 && (strncmp(tn, "dmult", 5) == 0
1800 || strncmp(tn, "dmacc", 5) == 0))
1805 /* Errata 24 - MT{LO,HI} after [D]MACC */
1806 if (strcmp (tn, "mtlo") == 0
1807 || strcmp (tn, "mthi") == 0)
1813 else if (strncmp(pn, "dmult", 5) == 0
1814 && (strncmp(tn, "dmult", 5) == 0
1815 || strncmp(tn, "dmacc", 5) == 0))
1817 /* Here is the rest of errata 23. */
1820 if (nops < min_nops)
1824 /* If we are being given a nop instruction, don't bother with
1825 one of the nops we would otherwise output. This will only
1826 happen when a nop instruction is used with mips_optimize set
1829 && ! mips_opts.noreorder
1830 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1833 /* Now emit the right number of NOP instructions. */
1834 if (nops > 0 && ! mips_opts.noreorder)
1837 unsigned long old_frag_offset;
1839 struct insn_label_list *l;
1841 old_frag = frag_now;
1842 old_frag_offset = frag_now_fix ();
1844 for (i = 0; i < nops; i++)
1849 listing_prev_line ();
1850 /* We may be at the start of a variant frag. In case we
1851 are, make sure there is enough space for the frag
1852 after the frags created by listing_prev_line. The
1853 argument to frag_grow here must be at least as large
1854 as the argument to all other calls to frag_grow in
1855 this file. We don't have to worry about being in the
1856 middle of a variant frag, because the variants insert
1857 all needed nop instructions themselves. */
1861 for (l = insn_labels; l != NULL; l = l->next)
1865 assert (S_GET_SEGMENT (l->label) == now_seg);
1866 symbol_set_frag (l->label, frag_now);
1867 val = (valueT) frag_now_fix ();
1868 /* mips16 text labels are stored as odd. */
1869 if (mips_opts.mips16)
1871 S_SET_VALUE (l->label, val);
1874 #ifndef NO_ECOFF_DEBUGGING
1875 if (ECOFF_DEBUGGING)
1876 ecoff_fix_loc (old_frag, old_frag_offset);
1879 else if (prev_nop_frag != NULL)
1881 /* We have a frag holding nops we may be able to remove. If
1882 we don't need any nops, we can decrease the size of
1883 prev_nop_frag by the size of one instruction. If we do
1884 need some nops, we count them in prev_nops_required. */
1885 if (prev_nop_frag_since == 0)
1889 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1890 --prev_nop_frag_holds;
1893 prev_nop_frag_required += nops;
1897 if (prev_prev_nop == 0)
1899 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1900 --prev_nop_frag_holds;
1903 ++prev_nop_frag_required;
1906 if (prev_nop_frag_holds <= prev_nop_frag_required)
1907 prev_nop_frag = NULL;
1909 ++prev_nop_frag_since;
1911 /* Sanity check: by the time we reach the second instruction
1912 after prev_nop_frag, we should have used up all the nops
1913 one way or another. */
1914 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1920 && *reloc_type == BFD_RELOC_16_PCREL_S2
1921 && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY
1922 || pinfo & INSN_COND_BRANCH_LIKELY)
1923 && mips_relax_branch
1924 /* Don't try branch relaxation within .set nomacro, or within
1925 .set noat if we use $at for PIC computations. If it turns
1926 out that the branch was out-of-range, we'll get an error. */
1927 && !mips_opts.warn_about_macros
1928 && !(mips_opts.noat && mips_pic != NO_PIC)
1929 && !mips_opts.mips16)
1931 f = frag_var (rs_machine_dependent,
1932 relaxed_branch_length
1934 (pinfo & INSN_UNCOND_BRANCH_DELAY) ? -1
1935 : (pinfo & INSN_COND_BRANCH_LIKELY) ? 1 : 0), 4,
1937 (pinfo & INSN_UNCOND_BRANCH_DELAY,
1938 pinfo & INSN_COND_BRANCH_LIKELY,
1939 pinfo & INSN_WRITE_GPR_31,
1941 address_expr->X_add_symbol,
1942 address_expr->X_add_number,
1944 *reloc_type = BFD_RELOC_UNUSED;
1946 else if (*reloc_type > BFD_RELOC_UNUSED)
1948 /* We need to set up a variant frag. */
1949 assert (mips_opts.mips16 && address_expr != NULL);
1950 f = frag_var (rs_machine_dependent, 4, 0,
1951 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
1952 mips16_small, mips16_ext,
1954 & INSN_UNCOND_BRANCH_DELAY),
1955 (*prev_insn_reloc_type
1956 == BFD_RELOC_MIPS16_JMP)),
1957 make_expr_symbol (address_expr), 0, NULL);
1959 else if (place != NULL)
1961 else if (mips_opts.mips16
1963 && *reloc_type != BFD_RELOC_MIPS16_JMP)
1965 /* Make sure there is enough room to swap this instruction with
1966 a following jump instruction. */
1972 if (mips_opts.mips16
1973 && mips_opts.noreorder
1974 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1975 as_warn (_("extended instruction in delay slot"));
1980 fixp[0] = fixp[1] = fixp[2] = NULL;
1981 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
1983 if (address_expr->X_op == O_constant)
1987 switch (*reloc_type)
1990 ip->insn_opcode |= address_expr->X_add_number;
1993 case BFD_RELOC_MIPS_HIGHEST:
1994 tmp = (address_expr->X_add_number
1995 + ((valueT) 0x8000 << 32) + 0x80008000) >> 16;
1997 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2000 case BFD_RELOC_MIPS_HIGHER:
2001 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
2002 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2005 case BFD_RELOC_HI16_S:
2006 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
2010 case BFD_RELOC_HI16:
2011 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2014 case BFD_RELOC_LO16:
2015 case BFD_RELOC_MIPS_GOT_DISP:
2016 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2019 case BFD_RELOC_MIPS_JMP:
2020 if ((address_expr->X_add_number & 3) != 0)
2021 as_bad (_("jump to misaligned address (0x%lx)"),
2022 (unsigned long) address_expr->X_add_number);
2023 if (address_expr->X_add_number & ~0xfffffff)
2024 as_bad (_("jump address range overflow (0x%lx)"),
2025 (unsigned long) address_expr->X_add_number);
2026 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2029 case BFD_RELOC_MIPS16_JMP:
2030 if ((address_expr->X_add_number & 3) != 0)
2031 as_bad (_("jump to misaligned address (0x%lx)"),
2032 (unsigned long) address_expr->X_add_number);
2033 if (address_expr->X_add_number & ~0xfffffff)
2034 as_bad (_("jump address range overflow (0x%lx)"),
2035 (unsigned long) address_expr->X_add_number);
2037 (((address_expr->X_add_number & 0x7c0000) << 3)
2038 | ((address_expr->X_add_number & 0xf800000) >> 7)
2039 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2042 case BFD_RELOC_16_PCREL_S2:
2052 /* Don't generate a reloc if we are writing into a variant frag. */
2055 reloc_howto_type *howto;
2058 /* In a compound relocation, it is the final (outermost)
2059 operator that determines the relocated field. */
2060 for (i = 1; i < 3; i++)
2061 if (reloc_type[i] == BFD_RELOC_UNUSED)
2064 howto = bfd_reloc_type_lookup (stdoutput, reloc_type[i - 1]);
2065 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal,
2066 bfd_get_reloc_size(howto),
2068 reloc_type[0] == BFD_RELOC_16_PCREL_S2,
2071 /* These relocations can have an addend that won't fit in
2072 4 octets for 64bit assembly. */
2074 && ! howto->partial_inplace
2075 && (reloc_type[0] == BFD_RELOC_16
2076 || reloc_type[0] == BFD_RELOC_32
2077 || reloc_type[0] == BFD_RELOC_MIPS_JMP
2078 || reloc_type[0] == BFD_RELOC_HI16_S
2079 || reloc_type[0] == BFD_RELOC_LO16
2080 || reloc_type[0] == BFD_RELOC_GPREL16
2081 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
2082 || reloc_type[0] == BFD_RELOC_GPREL32
2083 || reloc_type[0] == BFD_RELOC_64
2084 || reloc_type[0] == BFD_RELOC_CTOR
2085 || reloc_type[0] == BFD_RELOC_MIPS_SUB
2086 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
2087 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
2088 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
2089 || reloc_type[0] == BFD_RELOC_MIPS_REL16
2090 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT))
2091 fixp[0]->fx_no_overflow = 1;
2093 if (reloc_needs_lo_p (*reloc_type))
2095 struct mips_hi_fixup *hi_fixup;
2097 /* Reuse the last entry if it already has a matching %lo. */
2098 hi_fixup = mips_hi_fixup_list;
2100 || !fixup_has_matching_lo_p (hi_fixup->fixp))
2102 hi_fixup = ((struct mips_hi_fixup *)
2103 xmalloc (sizeof (struct mips_hi_fixup)));
2104 hi_fixup->next = mips_hi_fixup_list;
2105 mips_hi_fixup_list = hi_fixup;
2107 hi_fixup->fixp = fixp[0];
2108 hi_fixup->seg = now_seg;
2111 /* Add fixups for the second and third relocations, if given.
2112 Note that the ABI allows the second relocation to be
2113 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
2114 moment we only use RSS_UNDEF, but we could add support
2115 for the others if it ever becomes necessary. */
2116 for (i = 1; i < 3; i++)
2117 if (reloc_type[i] != BFD_RELOC_UNUSED)
2119 address_expr->X_op = O_absent;
2120 address_expr->X_add_symbol = 0;
2121 address_expr->X_add_number = 0;
2123 fixp[i] = fix_new_exp (frag_now, fixp[0]->fx_where,
2124 fixp[0]->fx_size, address_expr,
2125 FALSE, reloc_type[i]);
2131 if (! mips_opts.mips16)
2133 md_number_to_chars (f, ip->insn_opcode, 4);
2135 dwarf2_emit_insn (4);
2138 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2140 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2141 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2143 dwarf2_emit_insn (4);
2150 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2153 md_number_to_chars (f, ip->insn_opcode, 2);
2155 dwarf2_emit_insn (ip->use_extend ? 4 : 2);
2159 /* Update the register mask information. */
2160 if (! mips_opts.mips16)
2162 if (pinfo & INSN_WRITE_GPR_D)
2163 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2164 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2165 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2166 if (pinfo & INSN_READ_GPR_S)
2167 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2168 if (pinfo & INSN_WRITE_GPR_31)
2169 mips_gprmask |= 1 << RA;
2170 if (pinfo & INSN_WRITE_FPR_D)
2171 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2172 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2173 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2174 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2175 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2176 if ((pinfo & INSN_READ_FPR_R) != 0)
2177 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2178 if (pinfo & INSN_COP)
2180 /* We don't keep enough information to sort these cases out.
2181 The itbl support does keep this information however, although
2182 we currently don't support itbl fprmats as part of the cop
2183 instruction. May want to add this support in the future. */
2185 /* Never set the bit for $0, which is always zero. */
2186 mips_gprmask &= ~1 << 0;
2190 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2191 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2192 & MIPS16OP_MASK_RX);
2193 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2194 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2195 & MIPS16OP_MASK_RY);
2196 if (pinfo & MIPS16_INSN_WRITE_Z)
2197 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2198 & MIPS16OP_MASK_RZ);
2199 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2200 mips_gprmask |= 1 << TREG;
2201 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2202 mips_gprmask |= 1 << SP;
2203 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2204 mips_gprmask |= 1 << RA;
2205 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2206 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2207 if (pinfo & MIPS16_INSN_READ_Z)
2208 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2209 & MIPS16OP_MASK_MOVE32Z);
2210 if (pinfo & MIPS16_INSN_READ_GPR_X)
2211 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2212 & MIPS16OP_MASK_REGR32);
2215 if (place == NULL && ! mips_opts.noreorder)
2217 /* Filling the branch delay slot is more complex. We try to
2218 switch the branch with the previous instruction, which we can
2219 do if the previous instruction does not set up a condition
2220 that the branch tests and if the branch is not itself the
2221 target of any branch. */
2222 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2223 || (pinfo & INSN_COND_BRANCH_DELAY))
2225 if (mips_optimize < 2
2226 /* If we have seen .set volatile or .set nomove, don't
2228 || mips_opts.nomove != 0
2229 /* If we had to emit any NOP instructions, then we
2230 already know we can not swap. */
2232 /* If we don't even know the previous insn, we can not
2234 || ! prev_insn_valid
2235 /* If the previous insn is already in a branch delay
2236 slot, then we can not swap. */
2237 || prev_insn_is_delay_slot
2238 /* If the previous previous insn was in a .set
2239 noreorder, we can't swap. Actually, the MIPS
2240 assembler will swap in this situation. However, gcc
2241 configured -with-gnu-as will generate code like
2247 in which we can not swap the bne and INSN. If gcc is
2248 not configured -with-gnu-as, it does not output the
2249 .set pseudo-ops. We don't have to check
2250 prev_insn_unreordered, because prev_insn_valid will
2251 be 0 in that case. We don't want to use
2252 prev_prev_insn_valid, because we do want to be able
2253 to swap at the start of a function. */
2254 || prev_prev_insn_unreordered
2255 /* If the branch is itself the target of a branch, we
2256 can not swap. We cheat on this; all we check for is
2257 whether there is a label on this instruction. If
2258 there are any branches to anything other than a
2259 label, users must use .set noreorder. */
2260 || insn_labels != NULL
2261 /* If the previous instruction is in a variant frag, we
2262 can not do the swap. This does not apply to the
2263 mips16, which uses variant frags for different
2265 || (! mips_opts.mips16
2266 && prev_insn_frag->fr_type == rs_machine_dependent)
2267 /* If the branch reads the condition codes, we don't
2268 even try to swap, because in the sequence
2273 we can not swap, and I don't feel like handling that
2275 || (! mips_opts.mips16
2276 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2277 && (pinfo & INSN_READ_COND_CODE))
2278 /* We can not swap with an instruction that requires a
2279 delay slot, becase the target of the branch might
2280 interfere with that instruction. */
2281 || (! mips_opts.mips16
2282 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2284 /* Itbl support may require additional care here. */
2285 & (INSN_LOAD_COPROC_DELAY
2286 | INSN_COPROC_MOVE_DELAY
2287 | INSN_WRITE_COND_CODE)))
2288 || (! (hilo_interlocks
2289 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2293 || (! mips_opts.mips16
2295 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2296 || (! mips_opts.mips16
2297 && mips_opts.isa == ISA_MIPS1
2298 /* Itbl support may require additional care here. */
2299 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2300 /* We can not swap with a branch instruction. */
2302 & (INSN_UNCOND_BRANCH_DELAY
2303 | INSN_COND_BRANCH_DELAY
2304 | INSN_COND_BRANCH_LIKELY))
2305 /* We do not swap with a trap instruction, since it
2306 complicates trap handlers to have the trap
2307 instruction be in a delay slot. */
2308 || (prev_pinfo & INSN_TRAP)
2309 /* If the branch reads a register that the previous
2310 instruction sets, we can not swap. */
2311 || (! mips_opts.mips16
2312 && (prev_pinfo & INSN_WRITE_GPR_T)
2313 && insn_uses_reg (ip,
2314 ((prev_insn.insn_opcode >> OP_SH_RT)
2317 || (! mips_opts.mips16
2318 && (prev_pinfo & INSN_WRITE_GPR_D)
2319 && insn_uses_reg (ip,
2320 ((prev_insn.insn_opcode >> OP_SH_RD)
2323 || (mips_opts.mips16
2324 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2325 && insn_uses_reg (ip,
2326 ((prev_insn.insn_opcode
2328 & MIPS16OP_MASK_RX),
2330 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2331 && insn_uses_reg (ip,
2332 ((prev_insn.insn_opcode
2334 & MIPS16OP_MASK_RY),
2336 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2337 && insn_uses_reg (ip,
2338 ((prev_insn.insn_opcode
2340 & MIPS16OP_MASK_RZ),
2342 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2343 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2344 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2345 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2346 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2347 && insn_uses_reg (ip,
2348 MIPS16OP_EXTRACT_REG32R (prev_insn.
2351 /* If the branch writes a register that the previous
2352 instruction sets, we can not swap (we know that
2353 branches write only to RD or to $31). */
2354 || (! mips_opts.mips16
2355 && (prev_pinfo & INSN_WRITE_GPR_T)
2356 && (((pinfo & INSN_WRITE_GPR_D)
2357 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2358 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2359 || ((pinfo & INSN_WRITE_GPR_31)
2360 && (((prev_insn.insn_opcode >> OP_SH_RT)
2363 || (! mips_opts.mips16
2364 && (prev_pinfo & INSN_WRITE_GPR_D)
2365 && (((pinfo & INSN_WRITE_GPR_D)
2366 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2367 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2368 || ((pinfo & INSN_WRITE_GPR_31)
2369 && (((prev_insn.insn_opcode >> OP_SH_RD)
2372 || (mips_opts.mips16
2373 && (pinfo & MIPS16_INSN_WRITE_31)
2374 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2375 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2376 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2378 /* If the branch writes a register that the previous
2379 instruction reads, we can not swap (we know that
2380 branches only write to RD or to $31). */
2381 || (! mips_opts.mips16
2382 && (pinfo & INSN_WRITE_GPR_D)
2383 && insn_uses_reg (&prev_insn,
2384 ((ip->insn_opcode >> OP_SH_RD)
2387 || (! mips_opts.mips16
2388 && (pinfo & INSN_WRITE_GPR_31)
2389 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2390 || (mips_opts.mips16
2391 && (pinfo & MIPS16_INSN_WRITE_31)
2392 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2393 /* If we are generating embedded PIC code, the branch
2394 might be expanded into a sequence which uses $at, so
2395 we can't swap with an instruction which reads it. */
2396 || (mips_pic == EMBEDDED_PIC
2397 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2398 /* If the previous previous instruction has a load
2399 delay, and sets a register that the branch reads, we
2401 || (! mips_opts.mips16
2402 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2403 /* Itbl support may require additional care here. */
2404 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2405 || (! gpr_interlocks
2406 && (prev_prev_insn.insn_mo->pinfo
2407 & INSN_LOAD_MEMORY_DELAY)))
2408 && insn_uses_reg (ip,
2409 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2412 /* If one instruction sets a condition code and the
2413 other one uses a condition code, we can not swap. */
2414 || ((pinfo & INSN_READ_COND_CODE)
2415 && (prev_pinfo & INSN_WRITE_COND_CODE))
2416 || ((pinfo & INSN_WRITE_COND_CODE)
2417 && (prev_pinfo & INSN_READ_COND_CODE))
2418 /* If the previous instruction uses the PC, we can not
2420 || (mips_opts.mips16
2421 && (prev_pinfo & MIPS16_INSN_READ_PC))
2422 /* If the previous instruction was extended, we can not
2424 || (mips_opts.mips16 && prev_insn_extended)
2425 /* If the previous instruction had a fixup in mips16
2426 mode, we can not swap. This normally means that the
2427 previous instruction was a 4 byte branch anyhow. */
2428 || (mips_opts.mips16 && prev_insn_fixp[0])
2429 /* If the previous instruction is a sync, sync.l, or
2430 sync.p, we can not swap. */
2431 || (prev_pinfo & INSN_SYNC))
2433 /* We could do even better for unconditional branches to
2434 portions of this object file; we could pick up the
2435 instruction at the destination, put it in the delay
2436 slot, and bump the destination address. */
2438 /* Update the previous insn information. */
2439 prev_prev_insn = *ip;
2440 prev_insn.insn_mo = &dummy_opcode;
2444 /* It looks like we can actually do the swap. */
2445 if (! mips_opts.mips16)
2450 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2451 memcpy (temp, prev_f, 4);
2452 memcpy (prev_f, f, 4);
2453 memcpy (f, temp, 4);
2454 if (prev_insn_fixp[0])
2456 prev_insn_fixp[0]->fx_frag = frag_now;
2457 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2459 if (prev_insn_fixp[1])
2461 prev_insn_fixp[1]->fx_frag = frag_now;
2462 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2464 if (prev_insn_fixp[2])
2466 prev_insn_fixp[2]->fx_frag = frag_now;
2467 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2469 if (prev_insn_fixp[0] && HAVE_NEWABI
2470 && prev_insn_frag != frag_now
2471 && (prev_insn_fixp[0]->fx_r_type
2472 == BFD_RELOC_MIPS_GOT_DISP
2473 || (prev_insn_fixp[0]->fx_r_type
2474 == BFD_RELOC_MIPS_CALL16)))
2476 /* To avoid confusion in tc_gen_reloc, we must
2477 ensure that this does not become a variant
2479 force_new_frag = TRUE;
2483 fixp[0]->fx_frag = prev_insn_frag;
2484 fixp[0]->fx_where = prev_insn_where;
2488 fixp[1]->fx_frag = prev_insn_frag;
2489 fixp[1]->fx_where = prev_insn_where;
2493 fixp[2]->fx_frag = prev_insn_frag;
2494 fixp[2]->fx_where = prev_insn_where;
2502 assert (prev_insn_fixp[0] == NULL);
2503 assert (prev_insn_fixp[1] == NULL);
2504 assert (prev_insn_fixp[2] == NULL);
2505 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2506 memcpy (temp, prev_f, 2);
2507 memcpy (prev_f, f, 2);
2508 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2510 assert (*reloc_type == BFD_RELOC_UNUSED);
2511 memcpy (f, temp, 2);
2515 memcpy (f, f + 2, 2);
2516 memcpy (f + 2, temp, 2);
2520 fixp[0]->fx_frag = prev_insn_frag;
2521 fixp[0]->fx_where = prev_insn_where;
2525 fixp[1]->fx_frag = prev_insn_frag;
2526 fixp[1]->fx_where = prev_insn_where;
2530 fixp[2]->fx_frag = prev_insn_frag;
2531 fixp[2]->fx_where = prev_insn_where;
2535 /* Update the previous insn information; leave prev_insn
2537 prev_prev_insn = *ip;
2539 prev_insn_is_delay_slot = 1;
2541 /* If that was an unconditional branch, forget the previous
2542 insn information. */
2543 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2545 prev_prev_insn.insn_mo = &dummy_opcode;
2546 prev_insn.insn_mo = &dummy_opcode;
2549 prev_insn_fixp[0] = NULL;
2550 prev_insn_fixp[1] = NULL;
2551 prev_insn_fixp[2] = NULL;
2552 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2553 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2554 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2555 prev_insn_extended = 0;
2557 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2559 /* We don't yet optimize a branch likely. What we should do
2560 is look at the target, copy the instruction found there
2561 into the delay slot, and increment the branch to jump to
2562 the next instruction. */
2564 /* Update the previous insn information. */
2565 prev_prev_insn = *ip;
2566 prev_insn.insn_mo = &dummy_opcode;
2567 prev_insn_fixp[0] = NULL;
2568 prev_insn_fixp[1] = NULL;
2569 prev_insn_fixp[2] = NULL;
2570 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2571 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2572 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2573 prev_insn_extended = 0;
2577 /* Update the previous insn information. */
2579 prev_prev_insn.insn_mo = &dummy_opcode;
2581 prev_prev_insn = prev_insn;
2584 /* Any time we see a branch, we always fill the delay slot
2585 immediately; since this insn is not a branch, we know it
2586 is not in a delay slot. */
2587 prev_insn_is_delay_slot = 0;
2589 prev_insn_fixp[0] = fixp[0];
2590 prev_insn_fixp[1] = fixp[1];
2591 prev_insn_fixp[2] = fixp[2];
2592 prev_insn_reloc_type[0] = reloc_type[0];
2593 prev_insn_reloc_type[1] = reloc_type[1];
2594 prev_insn_reloc_type[2] = reloc_type[2];
2595 if (mips_opts.mips16)
2596 prev_insn_extended = (ip->use_extend
2597 || *reloc_type > BFD_RELOC_UNUSED);
2600 prev_prev_insn_unreordered = prev_insn_unreordered;
2601 prev_insn_unreordered = 0;
2602 prev_insn_frag = frag_now;
2603 prev_insn_where = f - frag_now->fr_literal;
2604 prev_insn_valid = 1;
2606 else if (place == NULL)
2608 /* We need to record a bit of information even when we are not
2609 reordering, in order to determine the base address for mips16
2610 PC relative relocs. */
2611 prev_prev_insn = prev_insn;
2613 prev_insn_reloc_type[0] = reloc_type[0];
2614 prev_insn_reloc_type[1] = reloc_type[1];
2615 prev_insn_reloc_type[2] = reloc_type[2];
2616 prev_prev_insn_unreordered = prev_insn_unreordered;
2617 prev_insn_unreordered = 1;
2620 /* We just output an insn, so the next one doesn't have a label. */
2621 mips_clear_insn_labels ();
2623 /* We must ensure that the frag to which an instruction that was
2624 moved from a non-variant frag doesn't become a variant frag,
2625 otherwise tc_gen_reloc may get confused. */
2628 frag_wane (frag_now);
2633 /* This function forgets that there was any previous instruction or
2634 label. If PRESERVE is non-zero, it remembers enough information to
2635 know whether nops are needed before a noreorder section. */
2638 mips_no_prev_insn (int preserve)
2642 prev_insn.insn_mo = &dummy_opcode;
2643 prev_prev_insn.insn_mo = &dummy_opcode;
2644 prev_nop_frag = NULL;
2645 prev_nop_frag_holds = 0;
2646 prev_nop_frag_required = 0;
2647 prev_nop_frag_since = 0;
2649 prev_insn_valid = 0;
2650 prev_insn_is_delay_slot = 0;
2651 prev_insn_unreordered = 0;
2652 prev_insn_extended = 0;
2653 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2654 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2655 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2656 prev_prev_insn_unreordered = 0;
2657 mips_clear_insn_labels ();
2660 /* This function must be called whenever we turn on noreorder or emit
2661 something other than instructions. It inserts any NOPS which might
2662 be needed by the previous instruction, and clears the information
2663 kept for the previous instructions. The INSNS parameter is true if
2664 instructions are to follow. */
2667 mips_emit_delays (bfd_boolean insns)
2669 if (! mips_opts.noreorder)
2674 if ((! mips_opts.mips16
2675 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2676 && (! cop_interlocks
2677 && (prev_insn.insn_mo->pinfo
2678 & (INSN_LOAD_COPROC_DELAY
2679 | INSN_COPROC_MOVE_DELAY
2680 | INSN_WRITE_COND_CODE))))
2681 || (! hilo_interlocks
2682 && (prev_insn.insn_mo->pinfo
2685 || (! mips_opts.mips16
2687 && (prev_insn.insn_mo->pinfo
2688 & INSN_LOAD_MEMORY_DELAY))
2689 || (! mips_opts.mips16
2690 && mips_opts.isa == ISA_MIPS1
2691 && (prev_insn.insn_mo->pinfo
2692 & INSN_COPROC_MEMORY_DELAY)))
2694 /* Itbl support may require additional care here. */
2696 if ((! mips_opts.mips16
2697 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2698 && (! cop_interlocks
2699 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2700 || (! hilo_interlocks
2701 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2702 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2705 if (prev_insn_unreordered)
2708 else if ((! mips_opts.mips16
2709 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2710 && (! cop_interlocks
2711 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2712 || (! hilo_interlocks
2713 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2714 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2716 /* Itbl support may require additional care here. */
2717 if (! prev_prev_insn_unreordered)
2721 if (mips_fix_4122_bugs && prev_insn.insn_mo->name)
2724 const char *pn = prev_insn.insn_mo->name;
2725 if (strncmp(pn, "macc", 4) == 0
2726 || strncmp(pn, "dmacc", 5) == 0
2727 || strncmp(pn, "dmult", 5) == 0)
2731 if (nops < min_nops)
2737 struct insn_label_list *l;
2741 /* Record the frag which holds the nop instructions, so
2742 that we can remove them if we don't need them. */
2743 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2744 prev_nop_frag = frag_now;
2745 prev_nop_frag_holds = nops;
2746 prev_nop_frag_required = 0;
2747 prev_nop_frag_since = 0;
2750 for (; nops > 0; --nops)
2755 /* Move on to a new frag, so that it is safe to simply
2756 decrease the size of prev_nop_frag. */
2757 frag_wane (frag_now);
2761 for (l = insn_labels; l != NULL; l = l->next)
2765 assert (S_GET_SEGMENT (l->label) == now_seg);
2766 symbol_set_frag (l->label, frag_now);
2767 val = (valueT) frag_now_fix ();
2768 /* mips16 text labels are stored as odd. */
2769 if (mips_opts.mips16)
2771 S_SET_VALUE (l->label, val);
2776 /* Mark instruction labels in mips16 mode. */
2778 mips16_mark_labels ();
2780 mips_no_prev_insn (insns);
2783 /* Build an instruction created by a macro expansion. This is passed
2784 a pointer to the count of instructions created so far, an
2785 expression, the name of the instruction to build, an operand format
2786 string, and corresponding arguments. */
2789 macro_build (char *place, int *counter, expressionS *ep, const char *name,
2790 const char *fmt, ...)
2792 struct mips_cl_insn insn;
2793 bfd_reloc_code_real_type r[3];
2796 va_start (args, fmt);
2799 * If the macro is about to expand into a second instruction,
2800 * print a warning if needed. We need to pass ip as a parameter
2801 * to generate a better warning message here...
2803 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2804 as_warn (_("Macro instruction expanded into multiple instructions"));
2807 * If the macro is about to expand into a second instruction,
2808 * and it is in a delay slot, print a warning.
2812 && mips_opts.noreorder
2813 && (prev_prev_insn.insn_mo->pinfo
2814 & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY
2815 | INSN_COND_BRANCH_LIKELY)) != 0)
2816 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2819 ++*counter; /* bump instruction counter */
2821 if (mips_opts.mips16)
2823 mips16_macro_build (place, counter, ep, name, fmt, args);
2828 r[0] = BFD_RELOC_UNUSED;
2829 r[1] = BFD_RELOC_UNUSED;
2830 r[2] = BFD_RELOC_UNUSED;
2831 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2832 assert (insn.insn_mo);
2833 assert (strcmp (name, insn.insn_mo->name) == 0);
2835 /* Search until we get a match for NAME. */
2838 /* It is assumed here that macros will never generate
2839 MDMX or MIPS-3D instructions. */
2840 if (strcmp (fmt, insn.insn_mo->args) == 0
2841 && insn.insn_mo->pinfo != INSN_MACRO
2842 && OPCODE_IS_MEMBER (insn.insn_mo,
2844 | (file_ase_mips16 ? INSN_MIPS16 : 0)),
2846 && (mips_opts.arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2850 assert (insn.insn_mo->name);
2851 assert (strcmp (name, insn.insn_mo->name) == 0);
2854 insn.insn_opcode = insn.insn_mo->match;
2870 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2874 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2879 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2885 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2890 int tmp = va_arg (args, int);
2892 insn.insn_opcode |= tmp << OP_SH_RT;
2893 insn.insn_opcode |= tmp << OP_SH_RD;
2899 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2906 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2910 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2914 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2918 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2922 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2929 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2935 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2936 assert (*r == BFD_RELOC_GPREL16
2937 || *r == BFD_RELOC_MIPS_LITERAL
2938 || *r == BFD_RELOC_MIPS_HIGHER
2939 || *r == BFD_RELOC_HI16_S
2940 || *r == BFD_RELOC_LO16
2941 || *r == BFD_RELOC_MIPS_GOT16
2942 || *r == BFD_RELOC_MIPS_CALL16
2943 || *r == BFD_RELOC_MIPS_GOT_DISP
2944 || *r == BFD_RELOC_MIPS_GOT_PAGE
2945 || *r == BFD_RELOC_MIPS_GOT_OFST
2946 || *r == BFD_RELOC_MIPS_GOT_LO16
2947 || *r == BFD_RELOC_MIPS_CALL_LO16
2948 || (ep->X_op == O_subtract
2949 && *r == BFD_RELOC_PCREL_LO16));
2953 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2955 && (ep->X_op == O_constant
2956 || (ep->X_op == O_symbol
2957 && (*r == BFD_RELOC_MIPS_HIGHEST
2958 || *r == BFD_RELOC_HI16_S
2959 || *r == BFD_RELOC_HI16
2960 || *r == BFD_RELOC_GPREL16
2961 || *r == BFD_RELOC_MIPS_GOT_HI16
2962 || *r == BFD_RELOC_MIPS_CALL_HI16))
2963 || (ep->X_op == O_subtract
2964 && *r == BFD_RELOC_PCREL_HI16_S)));
2968 assert (ep != NULL);
2970 * This allows macro() to pass an immediate expression for
2971 * creating short branches without creating a symbol.
2972 * Note that the expression still might come from the assembly
2973 * input, in which case the value is not checked for range nor
2974 * is a relocation entry generated (yuck).
2976 if (ep->X_op == O_constant)
2978 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
2982 *r = BFD_RELOC_16_PCREL_S2;
2986 assert (ep != NULL);
2987 *r = BFD_RELOC_MIPS_JMP;
2991 insn.insn_opcode |= va_arg (args, unsigned long);
3000 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3002 append_insn (place, &insn, ep, r);
3006 mips16_macro_build (char *place, int *counter ATTRIBUTE_UNUSED,
3007 expressionS *ep, const char *name, const char *fmt,
3010 struct mips_cl_insn insn;
3011 bfd_reloc_code_real_type r[3]
3012 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3014 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3015 assert (insn.insn_mo);
3016 assert (strcmp (name, insn.insn_mo->name) == 0);
3018 while (strcmp (fmt, insn.insn_mo->args) != 0
3019 || insn.insn_mo->pinfo == INSN_MACRO)
3022 assert (insn.insn_mo->name);
3023 assert (strcmp (name, insn.insn_mo->name) == 0);
3026 insn.insn_opcode = insn.insn_mo->match;
3027 insn.use_extend = FALSE;
3046 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
3051 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
3055 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
3059 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
3069 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
3076 regno = va_arg (args, int);
3077 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3078 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3099 assert (ep != NULL);
3101 if (ep->X_op != O_constant)
3102 *r = (int) BFD_RELOC_UNUSED + c;
3105 mips16_immed (NULL, 0, c, ep->X_add_number, FALSE, FALSE,
3106 FALSE, &insn.insn_opcode, &insn.use_extend,
3109 *r = BFD_RELOC_UNUSED;
3115 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3122 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3124 append_insn (place, &insn, ep, r);
3128 * Generate a "jalr" instruction with a relocation hint to the called
3129 * function. This occurs in NewABI PIC code.
3132 macro_build_jalr (int icnt, expressionS *ep)
3141 macro_build (NULL, &icnt, NULL, "jalr", "d,s", RA, PIC_CALL_REG);
3143 fix_new_exp (frag_now, f - frag_now->fr_literal,
3144 4, ep, FALSE, BFD_RELOC_MIPS_JALR);
3148 * Generate a "lui" instruction.
3151 macro_build_lui (char *place, int *counter, expressionS *ep, int regnum)
3153 expressionS high_expr;
3154 struct mips_cl_insn insn;
3155 bfd_reloc_code_real_type r[3]
3156 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3157 const char *name = "lui";
3158 const char *fmt = "t,u";
3160 assert (! mips_opts.mips16);
3166 high_expr.X_op = O_constant;
3167 high_expr.X_add_number = ep->X_add_number;
3170 if (high_expr.X_op == O_constant)
3172 /* we can compute the instruction now without a relocation entry */
3173 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3175 *r = BFD_RELOC_UNUSED;
3179 assert (ep->X_op == O_symbol);
3180 /* _gp_disp is a special case, used from s_cpload. */
3181 assert (mips_pic == NO_PIC
3183 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0));
3184 *r = BFD_RELOC_HI16_S;
3188 * If the macro is about to expand into a second instruction,
3189 * print a warning if needed. We need to pass ip as a parameter
3190 * to generate a better warning message here...
3192 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3193 as_warn (_("Macro instruction expanded into multiple instructions"));
3196 ++*counter; /* bump instruction counter */
3198 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3199 assert (insn.insn_mo);
3200 assert (strcmp (name, insn.insn_mo->name) == 0);
3201 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3203 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3204 if (*r == BFD_RELOC_UNUSED)
3206 insn.insn_opcode |= high_expr.X_add_number;
3207 append_insn (place, &insn, NULL, r);
3210 append_insn (place, &insn, &high_expr, r);
3213 /* Generate a sequence of instructions to do a load or store from a constant
3214 offset off of a base register (breg) into/from a target register (treg),
3215 using AT if necessary. */
3217 macro_build_ldst_constoffset (char *place, int *counter, expressionS *ep,
3218 const char *op, int treg, int breg)
3220 assert (ep->X_op == O_constant);
3222 /* Right now, this routine can only handle signed 32-bit contants. */
3223 if (! IS_SEXT_32BIT_NUM(ep->X_add_number))
3224 as_warn (_("operand overflow"));
3226 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
3228 /* Signed 16-bit offset will fit in the op. Easy! */
3229 macro_build (place, counter, ep, op, "t,o(b)", treg, BFD_RELOC_LO16,
3234 /* 32-bit offset, need multiple instructions and AT, like:
3235 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3236 addu $tempreg,$tempreg,$breg
3237 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3238 to handle the complete offset. */
3239 macro_build_lui (place, counter, ep, AT);
3242 macro_build (place, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT,
3246 macro_build (place, counter, ep, op, "t,o(b)", treg, BFD_RELOC_LO16,
3250 as_warn (_("Macro used $at after \".set noat\""));
3255 * Generates code to set the $at register to true (one)
3256 * if reg is less than the immediate expression.
3259 set_at (int *counter, int reg, int unsignedp)
3261 if (imm_expr.X_op == O_constant
3262 && imm_expr.X_add_number >= -0x8000
3263 && imm_expr.X_add_number < 0x8000)
3264 macro_build (NULL, counter, &imm_expr, unsignedp ? "sltiu" : "slti",
3265 "t,r,j", AT, reg, BFD_RELOC_LO16);
3268 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3269 macro_build (NULL, counter, NULL, unsignedp ? "sltu" : "slt",
3270 "d,v,t", AT, reg, AT);
3274 /* Warn if an expression is not a constant. */
3277 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
3279 if (ex->X_op == O_big)
3280 as_bad (_("unsupported large constant"));
3281 else if (ex->X_op != O_constant)
3282 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3285 /* Count the leading zeroes by performing a binary chop. This is a
3286 bulky bit of source, but performance is a LOT better for the
3287 majority of values than a simple loop to count the bits:
3288 for (lcnt = 0; (lcnt < 32); lcnt++)
3289 if ((v) & (1 << (31 - lcnt)))
3291 However it is not code size friendly, and the gain will drop a bit
3292 on certain cached systems.
3294 #define COUNT_TOP_ZEROES(v) \
3295 (((v) & ~0xffff) == 0 \
3296 ? ((v) & ~0xff) == 0 \
3297 ? ((v) & ~0xf) == 0 \
3298 ? ((v) & ~0x3) == 0 \
3299 ? ((v) & ~0x1) == 0 \
3304 : ((v) & ~0x7) == 0 \
3307 : ((v) & ~0x3f) == 0 \
3308 ? ((v) & ~0x1f) == 0 \
3311 : ((v) & ~0x7f) == 0 \
3314 : ((v) & ~0xfff) == 0 \
3315 ? ((v) & ~0x3ff) == 0 \
3316 ? ((v) & ~0x1ff) == 0 \
3319 : ((v) & ~0x7ff) == 0 \
3322 : ((v) & ~0x3fff) == 0 \
3323 ? ((v) & ~0x1fff) == 0 \
3326 : ((v) & ~0x7fff) == 0 \
3329 : ((v) & ~0xffffff) == 0 \
3330 ? ((v) & ~0xfffff) == 0 \
3331 ? ((v) & ~0x3ffff) == 0 \
3332 ? ((v) & ~0x1ffff) == 0 \
3335 : ((v) & ~0x7ffff) == 0 \
3338 : ((v) & ~0x3fffff) == 0 \
3339 ? ((v) & ~0x1fffff) == 0 \
3342 : ((v) & ~0x7fffff) == 0 \
3345 : ((v) & ~0xfffffff) == 0 \
3346 ? ((v) & ~0x3ffffff) == 0 \
3347 ? ((v) & ~0x1ffffff) == 0 \
3350 : ((v) & ~0x7ffffff) == 0 \
3353 : ((v) & ~0x3fffffff) == 0 \
3354 ? ((v) & ~0x1fffffff) == 0 \
3357 : ((v) & ~0x7fffffff) == 0 \
3362 * This routine generates the least number of instructions neccessary to load
3363 * an absolute expression value into a register.
3366 load_register (int *counter, int reg, expressionS *ep, int dbl)
3369 expressionS hi32, lo32;
3371 if (ep->X_op != O_big)
3373 assert (ep->X_op == O_constant);
3374 if (ep->X_add_number < 0x8000
3375 && (ep->X_add_number >= 0
3376 || (ep->X_add_number >= -0x8000
3379 || sizeof (ep->X_add_number) > 4))))
3381 /* We can handle 16 bit signed values with an addiu to
3382 $zero. No need to ever use daddiu here, since $zero and
3383 the result are always correct in 32 bit mode. */
3384 macro_build (NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3388 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3390 /* We can handle 16 bit unsigned values with an ori to
3392 macro_build (NULL, counter, ep, "ori", "t,r,i", reg, 0,
3396 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)
3399 || sizeof (ep->X_add_number) > 4
3400 || (ep->X_add_number & 0x80000000) == 0))
3401 || ((HAVE_32BIT_GPRS || ! dbl)
3402 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3405 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3406 == ~ (offsetT) 0xffffffff)))
3408 /* 32 bit values require an lui. */
3409 macro_build (NULL, counter, ep, "lui", "t,u", reg, BFD_RELOC_HI16);
3410 if ((ep->X_add_number & 0xffff) != 0)
3411 macro_build (NULL, counter, ep, "ori", "t,r,i", reg, reg,
3417 /* The value is larger than 32 bits. */
3419 if (HAVE_32BIT_GPRS)
3421 as_bad (_("Number (0x%lx) larger than 32 bits"),
3422 (unsigned long) ep->X_add_number);
3423 macro_build (NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3428 if (ep->X_op != O_big)
3431 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3432 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3433 hi32.X_add_number &= 0xffffffff;
3435 lo32.X_add_number &= 0xffffffff;
3439 assert (ep->X_add_number > 2);
3440 if (ep->X_add_number == 3)
3441 generic_bignum[3] = 0;
3442 else if (ep->X_add_number > 4)
3443 as_bad (_("Number larger than 64 bits"));
3444 lo32.X_op = O_constant;
3445 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3446 hi32.X_op = O_constant;
3447 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3450 if (hi32.X_add_number == 0)
3455 unsigned long hi, lo;
3457 if (hi32.X_add_number == (offsetT) 0xffffffff)
3459 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3461 macro_build (NULL, counter, &lo32, "addiu", "t,r,j", reg, 0,
3465 if (lo32.X_add_number & 0x80000000)
3467 macro_build (NULL, counter, &lo32, "lui", "t,u", reg,
3469 if (lo32.X_add_number & 0xffff)
3470 macro_build (NULL, counter, &lo32, "ori", "t,r,i", reg, reg,
3476 /* Check for 16bit shifted constant. We know that hi32 is
3477 non-zero, so start the mask on the first bit of the hi32
3482 unsigned long himask, lomask;
3486 himask = 0xffff >> (32 - shift);
3487 lomask = (0xffff << shift) & 0xffffffff;
3491 himask = 0xffff << (shift - 32);
3494 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3495 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3499 tmp.X_op = O_constant;
3501 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3502 | (lo32.X_add_number >> shift));
3504 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3505 macro_build (NULL, counter, &tmp, "ori", "t,r,i", reg, 0,
3507 macro_build (NULL, counter, NULL,
3508 (shift >= 32) ? "dsll32" : "dsll",
3510 (shift >= 32) ? shift - 32 : shift);
3515 while (shift <= (64 - 16));
3517 /* Find the bit number of the lowest one bit, and store the
3518 shifted value in hi/lo. */
3519 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3520 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3524 while ((lo & 1) == 0)
3529 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3535 while ((hi & 1) == 0)
3544 /* Optimize if the shifted value is a (power of 2) - 1. */
3545 if ((hi == 0 && ((lo + 1) & lo) == 0)
3546 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3548 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3553 /* This instruction will set the register to be all
3555 tmp.X_op = O_constant;
3556 tmp.X_add_number = (offsetT) -1;
3557 macro_build (NULL, counter, &tmp, "addiu", "t,r,j", reg, 0,
3562 macro_build (NULL, counter, NULL,
3563 (bit >= 32) ? "dsll32" : "dsll",
3565 (bit >= 32) ? bit - 32 : bit);
3567 macro_build (NULL, counter, NULL,
3568 (shift >= 32) ? "dsrl32" : "dsrl",
3570 (shift >= 32) ? shift - 32 : shift);
3575 /* Sign extend hi32 before calling load_register, because we can
3576 generally get better code when we load a sign extended value. */
3577 if ((hi32.X_add_number & 0x80000000) != 0)
3578 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3579 load_register (counter, reg, &hi32, 0);
3582 if ((lo32.X_add_number & 0xffff0000) == 0)
3586 macro_build (NULL, counter, NULL, "dsll32", "d,w,<", reg, freg, 0);
3594 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3596 macro_build (NULL, counter, &lo32, "lui", "t,u", reg,
3598 macro_build (NULL, counter, NULL, "dsrl32", "d,w,<", reg, reg, 0);
3604 macro_build (NULL, counter, NULL, "dsll", "d,w,<", reg, freg, 16);
3608 mid16.X_add_number >>= 16;
3609 macro_build (NULL, counter, &mid16, "ori", "t,r,i", reg, freg,
3611 macro_build (NULL, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3614 if ((lo32.X_add_number & 0xffff) != 0)
3615 macro_build (NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3619 /* Load an address into a register. */
3622 load_address (int *counter, int reg, expressionS *ep, int *used_at)
3626 if (ep->X_op != O_constant
3627 && ep->X_op != O_symbol)
3629 as_bad (_("expression too complex"));
3630 ep->X_op = O_constant;
3633 if (ep->X_op == O_constant)
3635 load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES);
3639 if (mips_pic == NO_PIC)
3641 /* If this is a reference to a GP relative symbol, we want
3642 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3644 lui $reg,<sym> (BFD_RELOC_HI16_S)
3645 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3646 If we have an addend, we always use the latter form.
3648 With 64bit address space and a usable $at we want
3649 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3650 lui $at,<sym> (BFD_RELOC_HI16_S)
3651 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3652 daddiu $at,<sym> (BFD_RELOC_LO16)
3656 If $at is already in use, we use a path which is suboptimal
3657 on superscalar processors.
3658 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3659 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3661 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3663 daddiu $reg,<sym> (BFD_RELOC_LO16)
3665 if (HAVE_64BIT_ADDRESSES)
3667 /* We don't do GP optimization for now because RELAX_ENCODE can't
3668 hold the data for such large chunks. */
3670 if (*used_at == 0 && ! mips_opts.noat)
3672 macro_build (p, counter, ep, "lui", "t,u",
3673 reg, BFD_RELOC_MIPS_HIGHEST);
3674 macro_build (p, counter, ep, "lui", "t,u",
3675 AT, BFD_RELOC_HI16_S);
3676 macro_build (p, counter, ep, "daddiu", "t,r,j",
3677 reg, reg, BFD_RELOC_MIPS_HIGHER);
3678 macro_build (p, counter, ep, "daddiu", "t,r,j",
3679 AT, AT, BFD_RELOC_LO16);
3680 macro_build (p, counter, NULL, "dsll32", "d,w,<", reg, reg, 0);
3681 macro_build (p, counter, NULL, "daddu", "d,v,t", reg, reg, AT);
3686 macro_build (p, counter, ep, "lui", "t,u",
3687 reg, BFD_RELOC_MIPS_HIGHEST);
3688 macro_build (p, counter, ep, "daddiu", "t,r,j",
3689 reg, reg, BFD_RELOC_MIPS_HIGHER);
3690 macro_build (p, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3691 macro_build (p, counter, ep, "daddiu", "t,r,j",
3692 reg, reg, BFD_RELOC_HI16_S);
3693 macro_build (p, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3694 macro_build (p, counter, ep, "daddiu", "t,r,j",
3695 reg, reg, BFD_RELOC_LO16);
3700 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3701 && ! nopic_need_relax (ep->X_add_symbol, 1))
3704 macro_build (NULL, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3705 mips_gp_register, BFD_RELOC_GPREL16);
3706 p = frag_var (rs_machine_dependent, 8, 0,
3707 RELAX_ENCODE (4, 8, 0, 4, 0,
3708 mips_opts.warn_about_macros),
3709 ep->X_add_symbol, 0, NULL);
3711 macro_build_lui (p, counter, ep, reg);
3714 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3718 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3722 /* If this is a reference to an external symbol, we want
3723 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3725 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3727 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3728 If there is a constant, it must be added in after.
3730 If we have NewABI, we want
3731 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
3732 unless we're referencing a global symbol with a non-zero
3733 offset, in which case cst must be added separately. */
3738 if (ep->X_add_number)
3740 frag_now->tc_frag_data.tc_fr_offset =
3741 ex.X_add_number = ep->X_add_number;
3742 ep->X_add_number = 0;
3743 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)",
3744 reg, BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3745 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3746 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3747 ex.X_op = O_constant;
3748 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3749 reg, reg, BFD_RELOC_LO16);
3750 p = frag_var (rs_machine_dependent, 8, 0,
3751 RELAX_ENCODE (8, 4, 0, 0, 0,
3752 mips_opts.warn_about_macros),
3753 ep->X_add_symbol, 0, NULL);
3754 ep->X_add_number = ex.X_add_number;
3757 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3758 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3762 /* To avoid confusion in tc_gen_reloc, we must ensure
3763 that this does not become a variant frag. */
3764 frag_wane (frag_now);
3770 ex.X_add_number = ep->X_add_number;
3771 ep->X_add_number = 0;
3773 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3774 BFD_RELOC_MIPS_GOT16,
3776 macro_build (NULL, counter, NULL, "nop", "");
3777 p = frag_var (rs_machine_dependent, 4, 0,
3778 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3779 ep->X_add_symbol, 0, NULL);
3780 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3783 if (ex.X_add_number != 0)
3785 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3786 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3787 ex.X_op = O_constant;
3788 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3789 reg, reg, BFD_RELOC_LO16);
3793 else if (mips_pic == SVR4_PIC)
3798 /* This is the large GOT case. If this is a reference to an
3799 external symbol, we want
3800 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3802 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3804 Otherwise, for a reference to a local symbol in old ABI, we want
3805 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3807 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3808 If there is a constant, it must be added in after.
3810 In the NewABI, for local symbols, with or without offsets, we want:
3811 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3812 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3818 frag_now->tc_frag_data.tc_fr_offset =
3819 ex.X_add_number = ep->X_add_number;
3820 ep->X_add_number = 0;
3821 macro_build (NULL, counter, ep, "lui", "t,u", reg,
3822 BFD_RELOC_MIPS_GOT_HI16);
3823 macro_build (NULL, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", reg,
3824 reg, mips_gp_register);
3825 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3826 BFD_RELOC_MIPS_GOT_LO16, reg);
3827 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3828 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3829 else if (ex.X_add_number)
3831 ex.X_op = O_constant;
3832 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3833 reg, reg, BFD_RELOC_LO16);
3836 ep->X_add_number = ex.X_add_number;
3837 p = frag_var (rs_machine_dependent, 8, 0,
3838 RELAX_ENCODE (ex.X_add_number ? 16 : 12, 8, 0, 4, 0,
3839 mips_opts.warn_about_macros),
3840 ep->X_add_symbol, 0, NULL);
3841 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3842 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
3843 macro_build (p + 4, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3844 reg, BFD_RELOC_MIPS_GOT_OFST);
3848 ex.X_add_number = ep->X_add_number;
3849 ep->X_add_number = 0;
3850 if (reg_needs_delay (mips_gp_register))
3855 macro_build (NULL, counter, ep, "lui", "t,u", reg,
3856 BFD_RELOC_MIPS_GOT_HI16);
3857 macro_build (NULL, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", reg,
3858 reg, mips_gp_register);
3859 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3860 BFD_RELOC_MIPS_GOT_LO16, reg);
3861 p = frag_var (rs_machine_dependent, 12 + off, 0,
3862 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3863 mips_opts.warn_about_macros),
3864 ep->X_add_symbol, 0, NULL);
3867 /* We need a nop before loading from $gp. This special
3868 check is required because the lui which starts the main
3869 instruction stream does not refer to $gp, and so will not
3870 insert the nop which may be required. */
3871 macro_build (p, counter, NULL, "nop", "");
3874 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3875 BFD_RELOC_MIPS_GOT16, mips_gp_register);
3877 macro_build (p, counter, NULL, "nop", "");
3879 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3882 if (ex.X_add_number != 0)
3884 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3885 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3886 ex.X_op = O_constant;
3887 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3888 reg, reg, BFD_RELOC_LO16);
3892 else if (mips_pic == EMBEDDED_PIC)
3895 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3897 macro_build (NULL, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3898 mips_gp_register, BFD_RELOC_GPREL16);
3904 /* Move the contents of register SOURCE into register DEST. */
3907 move_register (int *counter, int dest, int source)
3909 macro_build (NULL, counter, NULL, HAVE_32BIT_GPRS ? "addu" : "daddu",
3910 "d,v,t", dest, source, 0);
3915 * This routine implements the seemingly endless macro or synthesized
3916 * instructions and addressing modes in the mips assembly language. Many
3917 * of these macros are simple and are similar to each other. These could
3918 * probably be handled by some kind of table or grammer aproach instead of
3919 * this verbose method. Others are not simple macros but are more like
3920 * optimizing code generation.
3921 * One interesting optimization is when several store macros appear
3922 * consecutivly that would load AT with the upper half of the same address.
3923 * The ensuing load upper instructions are ommited. This implies some kind
3924 * of global optimization. We currently only optimize within a single macro.
3925 * For many of the load and store macros if the address is specified as a
3926 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3927 * first load register 'at' with zero and use it as the base register. The
3928 * mips assembler simply uses register $zero. Just one tiny optimization
3932 macro (struct mips_cl_insn *ip)
3934 register int treg, sreg, dreg, breg;
3950 bfd_reloc_code_real_type r;
3951 int hold_mips_optimize;
3953 assert (! mips_opts.mips16);
3955 treg = (ip->insn_opcode >> 16) & 0x1f;
3956 dreg = (ip->insn_opcode >> 11) & 0x1f;
3957 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3958 mask = ip->insn_mo->mask;
3960 expr1.X_op = O_constant;
3961 expr1.X_op_symbol = NULL;
3962 expr1.X_add_symbol = NULL;
3963 expr1.X_add_number = 1;
3965 /* Umatched fixups should not be put in the same frag as a relaxable
3966 macro. For example, suppose we have:
3970 addiu $4,$4,%lo(l1) # 3
3972 If instructions 1 and 2 were put in the same frag, md_frob_file would
3973 move the fixup for #1 after the fixups for the "unrelaxed" version of
3974 #2. This would confuse tc_gen_reloc, which expects the relocations
3975 for #2 to be the last for that frag.
3977 Also, if tc_gen_reloc sees certain relocations in a variant frag,
3978 it assumes that they belong to a relaxable macro. We mustn't put
3979 other uses of such relocations into a variant frag.
3981 To avoid both problems, finish the current frag it contains a
3982 %reloc() operator. The macro then goes into a new frag. */
3983 if (prev_reloc_op_frag == frag_now)
3985 frag_wane (frag_now);
3999 mips_emit_delays (TRUE);
4000 ++mips_opts.noreorder;
4001 mips_any_noreorder = 1;
4003 expr1.X_add_number = 8;
4004 macro_build (NULL, &icnt, &expr1, "bgez", "s,p", sreg);
4006 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4008 move_register (&icnt, dreg, sreg);
4009 macro_build (NULL, &icnt, NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0,
4012 --mips_opts.noreorder;
4033 if (imm_expr.X_op == O_constant
4034 && imm_expr.X_add_number >= -0x8000
4035 && imm_expr.X_add_number < 0x8000)
4037 macro_build (NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
4041 load_register (&icnt, AT, &imm_expr, dbl);
4042 macro_build (NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
4061 if (imm_expr.X_op == O_constant
4062 && imm_expr.X_add_number >= 0
4063 && imm_expr.X_add_number < 0x10000)
4065 if (mask != M_NOR_I)
4066 macro_build (NULL, &icnt, &imm_expr, s, "t,r,i", treg, sreg,
4070 macro_build (NULL, &icnt, &imm_expr, "ori", "t,r,i", treg, sreg,
4072 macro_build (NULL, &icnt, NULL, "nor", "d,v,t", treg, treg, 0);
4077 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4078 macro_build (NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
4095 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4097 macro_build (NULL, &icnt, &offset_expr, s, "s,t,p", sreg, 0);
4100 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4101 macro_build (NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
4109 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4115 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4119 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
4120 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4127 /* check for > max integer */
4128 maxnum = 0x7fffffff;
4129 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4136 if (imm_expr.X_op == O_constant
4137 && imm_expr.X_add_number >= maxnum
4138 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4141 /* result is always false */
4145 as_warn (_("Branch %s is always false (nop)"),
4147 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4152 as_warn (_("Branch likely %s is always false"),
4154 macro_build (NULL, &icnt, &offset_expr, "bnel", "s,t,p", 0, 0);
4158 if (imm_expr.X_op != O_constant)
4159 as_bad (_("Unsupported large constant"));
4160 ++imm_expr.X_add_number;
4164 if (mask == M_BGEL_I)
4166 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4168 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4172 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4174 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4178 maxnum = 0x7fffffff;
4179 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4186 maxnum = - maxnum - 1;
4187 if (imm_expr.X_op == O_constant
4188 && imm_expr.X_add_number <= maxnum
4189 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4192 /* result is always true */
4193 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4194 macro_build (NULL, &icnt, &offset_expr, "b", "p");
4197 set_at (&icnt, sreg, 0);
4198 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4209 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4213 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, treg);
4214 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4223 && imm_expr.X_op == O_constant
4224 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4226 if (imm_expr.X_op != O_constant)
4227 as_bad (_("Unsupported large constant"));
4228 ++imm_expr.X_add_number;
4232 if (mask == M_BGEUL_I)
4234 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4236 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4238 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4242 set_at (&icnt, sreg, 1);
4243 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4252 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4258 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4262 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
4263 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4272 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4278 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, sreg);
4279 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4288 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4294 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4298 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
4299 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4306 maxnum = 0x7fffffff;
4307 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4314 if (imm_expr.X_op == O_constant
4315 && imm_expr.X_add_number >= maxnum
4316 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4318 if (imm_expr.X_op != O_constant)
4319 as_bad (_("Unsupported large constant"));
4320 ++imm_expr.X_add_number;
4324 if (mask == M_BLTL_I)
4326 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4328 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4332 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4334 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4338 set_at (&icnt, sreg, 0);
4339 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4348 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4354 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, sreg);
4355 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4364 && imm_expr.X_op == O_constant
4365 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4367 if (imm_expr.X_op != O_constant)
4368 as_bad (_("Unsupported large constant"));
4369 ++imm_expr.X_add_number;
4373 if (mask == M_BLTUL_I)
4375 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4377 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4379 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4383 set_at (&icnt, sreg, 1);
4384 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4393 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4399 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4403 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
4404 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4415 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4419 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, treg);
4420 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4436 as_warn (_("Divide by zero."));
4438 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", 0, 0, 7);
4440 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4444 mips_emit_delays (TRUE);
4445 ++mips_opts.noreorder;
4446 mips_any_noreorder = 1;
4449 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", treg, 0, 7);
4450 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "z,s,t",
4455 expr1.X_add_number = 8;
4456 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4457 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "z,s,t",
4459 macro_build (NULL, &icnt,NULL, "break", "c", 7);
4461 expr1.X_add_number = -1;
4462 macro_build (NULL, &icnt, &expr1, dbl ? "daddiu" : "addiu", "t,r,j",
4463 AT, 0, BFD_RELOC_LO16);
4464 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4465 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4468 expr1.X_add_number = 1;
4469 macro_build (NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4471 macro_build (NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT, 31);
4475 expr1.X_add_number = 0x80000000;
4476 macro_build (NULL, &icnt, &expr1, "lui", "t,u", AT,
4481 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", sreg, AT, 6);
4482 /* We want to close the noreorder block as soon as possible, so
4483 that later insns are available for delay slot filling. */
4484 --mips_opts.noreorder;
4488 expr1.X_add_number = 8;
4489 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4490 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4492 /* We want to close the noreorder block as soon as possible, so
4493 that later insns are available for delay slot filling. */
4494 --mips_opts.noreorder;
4496 macro_build (NULL, &icnt, NULL, "break", "c", 6);
4498 macro_build (NULL, &icnt, NULL, s, "d", dreg);
4537 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4539 as_warn (_("Divide by zero."));
4541 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", 0, 0, 7);
4543 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4546 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4548 if (strcmp (s2, "mflo") == 0)
4549 move_register (&icnt, dreg, sreg);
4551 move_register (&icnt, dreg, 0);
4554 if (imm_expr.X_op == O_constant
4555 && imm_expr.X_add_number == -1
4556 && s[strlen (s) - 1] != 'u')
4558 if (strcmp (s2, "mflo") == 0)
4560 macro_build (NULL, &icnt, NULL, dbl ? "dneg" : "neg", "d,w",
4564 move_register (&icnt, dreg, 0);
4568 load_register (&icnt, AT, &imm_expr, dbl);
4569 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, AT);
4570 macro_build (NULL, &icnt, NULL, s2, "d", dreg);
4589 mips_emit_delays (TRUE);
4590 ++mips_opts.noreorder;
4591 mips_any_noreorder = 1;
4594 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", treg, 0, 7);
4595 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4596 /* We want to close the noreorder block as soon as possible, so
4597 that later insns are available for delay slot filling. */
4598 --mips_opts.noreorder;
4602 expr1.X_add_number = 8;
4603 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4604 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4606 /* We want to close the noreorder block as soon as possible, so
4607 that later insns are available for delay slot filling. */
4608 --mips_opts.noreorder;
4609 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4611 macro_build (NULL, &icnt, NULL, s2, "d", dreg);
4617 /* Load the address of a symbol into a register. If breg is not
4618 zero, we then add a base register to it. */
4620 if (dbl && HAVE_32BIT_GPRS)
4621 as_warn (_("dla used to load 32-bit register"));
4623 if (! dbl && HAVE_64BIT_OBJECTS)
4624 as_warn (_("la used to load 64-bit address"));
4626 if (offset_expr.X_op == O_constant
4627 && offset_expr.X_add_number >= -0x8000
4628 && offset_expr.X_add_number < 0x8000)
4630 macro_build (NULL, &icnt, &offset_expr,
4631 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4632 "t,r,j", treg, sreg, BFD_RELOC_LO16);
4647 /* When generating embedded PIC code, we permit expressions of
4650 la $treg,foo-bar($breg)
4651 where bar is an address in the current section. These are used
4652 when getting the addresses of functions. We don't permit
4653 X_add_number to be non-zero, because if the symbol is
4654 external the relaxing code needs to know that any addend is
4655 purely the offset to X_op_symbol. */
4656 if (mips_pic == EMBEDDED_PIC
4657 && offset_expr.X_op == O_subtract
4658 && (symbol_constant_p (offset_expr.X_op_symbol)
4659 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4660 : (symbol_equated_p (offset_expr.X_op_symbol)
4662 (symbol_get_value_expression (offset_expr.X_op_symbol)
4665 && (offset_expr.X_add_number == 0
4666 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4672 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
4673 BFD_RELOC_PCREL_HI16_S);
4677 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
4678 BFD_RELOC_PCREL_HI16_S);
4679 macro_build (NULL, &icnt, NULL,
4680 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4681 "d,v,t", tempreg, tempreg, breg);
4683 macro_build (NULL, &icnt, &offset_expr,
4684 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4685 "t,r,j", treg, tempreg, BFD_RELOC_PCREL_LO16);
4691 if (offset_expr.X_op != O_symbol
4692 && offset_expr.X_op != O_constant)
4694 as_bad (_("expression too complex"));
4695 offset_expr.X_op = O_constant;
4698 if (offset_expr.X_op == O_constant)
4699 load_register (&icnt, tempreg, &offset_expr,
4700 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4701 ? (dbl || HAVE_64BIT_ADDRESSES)
4702 : HAVE_64BIT_ADDRESSES));
4703 else if (mips_pic == NO_PIC)
4705 /* If this is a reference to a GP relative symbol, we want
4706 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4708 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4709 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4710 If we have a constant, we need two instructions anyhow,
4711 so we may as well always use the latter form.
4713 With 64bit address space and a usable $at we want
4714 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4715 lui $at,<sym> (BFD_RELOC_HI16_S)
4716 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4717 daddiu $at,<sym> (BFD_RELOC_LO16)
4719 daddu $tempreg,$tempreg,$at
4721 If $at is already in use, we use a path which is suboptimal
4722 on superscalar processors.
4723 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4724 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4726 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4728 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4731 if (HAVE_64BIT_ADDRESSES)
4733 /* We don't do GP optimization for now because RELAX_ENCODE can't
4734 hold the data for such large chunks. */
4736 if (used_at == 0 && ! mips_opts.noat)
4738 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4739 tempreg, BFD_RELOC_MIPS_HIGHEST);
4740 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4741 AT, BFD_RELOC_HI16_S);
4742 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4743 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
4744 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4745 AT, AT, BFD_RELOC_LO16);
4746 macro_build (p, &icnt, NULL, "dsll32", "d,w,<",
4747 tempreg, tempreg, 0);
4748 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
4749 tempreg, tempreg, AT);
4754 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4755 tempreg, BFD_RELOC_MIPS_HIGHEST);
4756 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4757 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
4758 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
4759 tempreg, tempreg, 16);
4760 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4761 tempreg, tempreg, BFD_RELOC_HI16_S);
4762 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
4763 tempreg, tempreg, 16);
4764 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4765 tempreg, tempreg, BFD_RELOC_LO16);
4770 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4771 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4774 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
4775 "t,r,j", tempreg, mips_gp_register,
4777 p = frag_var (rs_machine_dependent, 8, 0,
4778 RELAX_ENCODE (4, 8, 0, 4, 0,
4779 mips_opts.warn_about_macros),
4780 offset_expr.X_add_symbol, 0, NULL);
4782 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4785 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
4786 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
4789 else if (mips_pic == SVR4_PIC && ! mips_big_got && ! HAVE_NEWABI)
4791 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4793 /* If this is a reference to an external symbol, and there
4794 is no constant, we want
4795 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4796 or if tempreg is PIC_CALL_REG
4797 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4798 For a local symbol, we want
4799 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4801 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4803 If we have a small constant, and this is a reference to
4804 an external symbol, we want
4805 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4807 addiu $tempreg,$tempreg,<constant>
4808 For a local symbol, we want the same instruction
4809 sequence, but we output a BFD_RELOC_LO16 reloc on the
4812 If we have a large constant, and this is a reference to
4813 an external symbol, we want
4814 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4815 lui $at,<hiconstant>
4816 addiu $at,$at,<loconstant>
4817 addu $tempreg,$tempreg,$at
4818 For a local symbol, we want the same instruction
4819 sequence, but we output a BFD_RELOC_LO16 reloc on the
4823 expr1.X_add_number = offset_expr.X_add_number;
4824 offset_expr.X_add_number = 0;
4826 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4827 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4828 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
4829 tempreg, lw_reloc_type, mips_gp_register);
4830 if (expr1.X_add_number == 0)
4839 /* We're going to put in an addu instruction using
4840 tempreg, so we may as well insert the nop right
4842 macro_build (NULL, &icnt, NULL, "nop", "");
4845 p = frag_var (rs_machine_dependent, 8 - off, 0,
4846 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4848 ? mips_opts.warn_about_macros
4850 offset_expr.X_add_symbol, 0, NULL);
4853 macro_build (p, &icnt, NULL, "nop", "");
4856 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
4857 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
4858 /* FIXME: If breg == 0, and the next instruction uses
4859 $tempreg, then if this variant case is used an extra
4860 nop will be generated. */
4862 else if (expr1.X_add_number >= -0x8000
4863 && expr1.X_add_number < 0x8000)
4865 macro_build (NULL, &icnt, NULL, "nop", "");
4866 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
4867 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
4868 frag_var (rs_machine_dependent, 0, 0,
4869 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4870 offset_expr.X_add_symbol, 0, NULL);
4876 /* If we are going to add in a base register, and the
4877 target register and the base register are the same,
4878 then we are using AT as a temporary register. Since
4879 we want to load the constant into AT, we add our
4880 current AT (from the global offset table) and the
4881 register into the register now, and pretend we were
4882 not using a base register. */
4887 macro_build (NULL, &icnt, NULL, "nop", "");
4888 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
4895 /* Set mips_optimize around the lui instruction to avoid
4896 inserting an unnecessary nop after the lw. */
4897 hold_mips_optimize = mips_optimize;
4899 macro_build_lui (NULL, &icnt, &expr1, AT);
4900 mips_optimize = hold_mips_optimize;
4902 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
4903 AT, AT, BFD_RELOC_LO16);
4904 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
4905 tempreg, tempreg, AT);
4906 frag_var (rs_machine_dependent, 0, 0,
4907 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4908 offset_expr.X_add_symbol, 0, NULL);
4912 else if (mips_pic == SVR4_PIC && ! mips_big_got && HAVE_NEWABI)
4915 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_DISP;
4918 /* If this is a reference to an external, and there is no
4919 constant, or local symbol (*), with or without a
4921 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4922 or if tempreg is PIC_CALL_REG
4923 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4925 If we have a small constant, and this is a reference to
4926 an external symbol, we want
4927 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4928 addiu $tempreg,$tempreg,<constant>
4930 If we have a large constant, and this is a reference to
4931 an external symbol, we want
4932 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4933 lui $at,<hiconstant>
4934 addiu $at,$at,<loconstant>
4935 addu $tempreg,$tempreg,$at
4937 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
4938 local symbols, even though it introduces an additional
4942 if (offset_expr.X_add_number == 0 && tempreg == PIC_CALL_REG)
4943 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4944 if (offset_expr.X_add_number)
4946 frag_now->tc_frag_data.tc_fr_offset =
4947 expr1.X_add_number = offset_expr.X_add_number;
4948 offset_expr.X_add_number = 0;
4950 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
4951 "t,o(b)", tempreg, lw_reloc_type,
4954 if (expr1.X_add_number >= -0x8000
4955 && expr1.X_add_number < 0x8000)
4957 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
4958 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
4959 p = frag_var (rs_machine_dependent, 4, 0,
4960 RELAX_ENCODE (8, 4, 0, 0, 0, 0),
4961 offset_expr.X_add_symbol, 0, NULL);
4963 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number))
4967 /* If we are going to add in a base register, and the
4968 target register and the base register are the same,
4969 then we are using AT as a temporary register. Since
4970 we want to load the constant into AT, we add our
4971 current AT (from the global offset table) and the
4972 register into the register now, and pretend we were
4973 not using a base register. */
4978 assert (tempreg == AT);
4979 macro_build (NULL, &icnt,NULL, ADDRESS_ADD_INSN,
4980 "d,v,t", treg, AT, breg);
4985 macro_build_lui (NULL, &icnt, &expr1, AT);
4986 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
4987 "t,r,j", AT, AT, BFD_RELOC_LO16);
4988 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
4991 p = frag_var (rs_machine_dependent, 4 + adj, 0,
4992 RELAX_ENCODE (16 + adj, 4 + adj,
4994 offset_expr.X_add_symbol, 0, NULL);
4999 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5001 offset_expr.X_add_number = expr1.X_add_number;
5003 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5004 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_DISP,
5008 macro_build (p + 4, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5009 treg, tempreg, breg);
5016 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5017 "t,o(b)", tempreg, lw_reloc_type,
5019 if (lw_reloc_type != BFD_RELOC_MIPS_GOT_DISP)
5020 p = frag_var (rs_machine_dependent, 0, 0,
5021 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5022 offset_expr.X_add_symbol, 0, NULL);
5027 /* To avoid confusion in tc_gen_reloc, we must ensure
5028 that this does not become a variant frag. */
5029 frag_wane (frag_now);
5033 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
5037 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5038 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5039 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
5041 /* This is the large GOT case. If this is a reference to an
5042 external symbol, and there is no constant, we want
5043 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5044 addu $tempreg,$tempreg,$gp
5045 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5046 or if tempreg is PIC_CALL_REG
5047 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5048 addu $tempreg,$tempreg,$gp
5049 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5050 For a local symbol, we want
5051 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5053 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5055 If we have a small constant, and this is a reference to
5056 an external symbol, we want
5057 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5058 addu $tempreg,$tempreg,$gp
5059 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5061 addiu $tempreg,$tempreg,<constant>
5062 For a local symbol, we want
5063 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5065 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5067 If we have a large constant, and this is a reference to
5068 an external symbol, we want
5069 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5070 addu $tempreg,$tempreg,$gp
5071 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5072 lui $at,<hiconstant>
5073 addiu $at,$at,<loconstant>
5074 addu $tempreg,$tempreg,$at
5075 For a local symbol, we want
5076 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5077 lui $at,<hiconstant>
5078 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5079 addu $tempreg,$tempreg,$at
5082 expr1.X_add_number = offset_expr.X_add_number;
5083 offset_expr.X_add_number = 0;
5085 if (reg_needs_delay (mips_gp_register))
5089 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
5091 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5092 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5094 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5095 tempreg, lui_reloc_type);
5096 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5097 tempreg, tempreg, mips_gp_register);
5098 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5099 tempreg, lw_reloc_type, tempreg);
5100 if (expr1.X_add_number == 0)
5108 /* We're going to put in an addu instruction using
5109 tempreg, so we may as well insert the nop right
5111 macro_build (NULL, &icnt, NULL, "nop", "");
5115 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5116 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
5119 ? mips_opts.warn_about_macros
5121 offset_expr.X_add_symbol, 0, NULL);
5123 else if (expr1.X_add_number >= -0x8000
5124 && expr1.X_add_number < 0x8000)
5126 macro_build (NULL, &icnt, NULL, "nop", "");
5127 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5128 tempreg, tempreg, BFD_RELOC_LO16);
5130 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5131 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
5133 ? mips_opts.warn_about_macros
5135 offset_expr.X_add_symbol, 0, NULL);
5141 /* If we are going to add in a base register, and the
5142 target register and the base register are the same,
5143 then we are using AT as a temporary register. Since
5144 we want to load the constant into AT, we add our
5145 current AT (from the global offset table) and the
5146 register into the register now, and pretend we were
5147 not using a base register. */
5155 assert (tempreg == AT);
5156 macro_build (NULL, &icnt, NULL, "nop", "");
5157 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5163 /* Set mips_optimize around the lui instruction to avoid
5164 inserting an unnecessary nop after the lw. */
5165 hold_mips_optimize = mips_optimize;
5167 macro_build_lui (NULL, &icnt, &expr1, AT);
5168 mips_optimize = hold_mips_optimize;
5170 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5171 AT, AT, BFD_RELOC_LO16);
5172 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5175 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
5176 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
5179 ? mips_opts.warn_about_macros
5181 offset_expr.X_add_symbol, 0, NULL);
5188 /* This is needed because this instruction uses $gp, but
5189 the first instruction on the main stream does not. */
5190 macro_build (p, &icnt, NULL, "nop", "");
5194 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5195 tempreg, local_reloc_type, mips_gp_register);
5197 if (expr1.X_add_number >= -0x8000
5198 && expr1.X_add_number < 0x8000)
5200 macro_build (p, &icnt, NULL, "nop", "");
5202 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
5203 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5204 /* FIXME: If add_number is 0, and there was no base
5205 register, the external symbol case ended with a load,
5206 so if the symbol turns out to not be external, and
5207 the next instruction uses tempreg, an unnecessary nop
5208 will be inserted. */
5214 /* We must add in the base register now, as in the
5215 external symbol case. */
5216 assert (tempreg == AT);
5217 macro_build (p, &icnt, NULL, "nop", "");
5219 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5223 /* We set breg to 0 because we have arranged to add
5224 it in in both cases. */
5228 macro_build_lui (p, &icnt, &expr1, AT);
5230 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5231 AT, AT, BFD_RELOC_LO16);
5233 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5234 tempreg, tempreg, AT);
5238 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
5241 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5242 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5245 /* This is the large GOT case. If this is a reference to an
5246 external symbol, and there is no constant, we want
5247 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5248 add $tempreg,$tempreg,$gp
5249 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5250 or if tempreg is PIC_CALL_REG
5251 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5252 add $tempreg,$tempreg,$gp
5253 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5255 If we have a small constant, and this is a reference to
5256 an external symbol, we want
5257 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5258 add $tempreg,$tempreg,$gp
5259 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5260 addi $tempreg,$tempreg,<constant>
5262 If we have a large constant, and this is a reference to
5263 an external symbol, we want
5264 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5265 addu $tempreg,$tempreg,$gp
5266 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5267 lui $at,<hiconstant>
5268 addi $at,$at,<loconstant>
5269 add $tempreg,$tempreg,$at
5271 If we have NewABI, and we know it's a local symbol, we want
5272 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5273 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5274 otherwise we have to resort to GOT_HI16/GOT_LO16. */
5278 frag_now->tc_frag_data.tc_fr_offset =
5279 expr1.X_add_number = offset_expr.X_add_number;
5280 offset_expr.X_add_number = 0;
5282 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
5284 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5285 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5287 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5288 tempreg, lui_reloc_type);
5289 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5290 tempreg, tempreg, mips_gp_register);
5291 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5292 "t,o(b)", tempreg, lw_reloc_type, tempreg);
5294 if (expr1.X_add_number == 0)
5296 p = frag_var (rs_machine_dependent, 8, 0,
5297 RELAX_ENCODE (12, 8, 0, 4, 0,
5298 mips_opts.warn_about_macros),
5299 offset_expr.X_add_symbol, 0, NULL);
5301 else if (expr1.X_add_number >= -0x8000
5302 && expr1.X_add_number < 0x8000)
5304 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5305 tempreg, tempreg, BFD_RELOC_LO16);
5306 p = frag_var (rs_machine_dependent, 8, 0,
5307 RELAX_ENCODE (16, 8, 0, 4, 0,
5308 mips_opts.warn_about_macros),
5309 offset_expr.X_add_symbol, 0, NULL);
5311 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number))
5315 /* If we are going to add in a base register, and the
5316 target register and the base register are the same,
5317 then we are using AT as a temporary register. Since
5318 we want to load the constant into AT, we add our
5319 current AT (from the global offset table) and the
5320 register into the register now, and pretend we were
5321 not using a base register. */
5326 assert (tempreg == AT);
5327 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5333 /* Set mips_optimize around the lui instruction to avoid
5334 inserting an unnecessary nop after the lw. */
5335 macro_build_lui (NULL, &icnt, &expr1, AT);
5336 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5337 "t,r,j", AT, AT, BFD_RELOC_LO16);
5338 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5341 p = frag_var (rs_machine_dependent, 8 + adj, 0,
5342 RELAX_ENCODE (24 + adj, 8 + adj,
5345 ? mips_opts.warn_about_macros
5347 offset_expr.X_add_symbol, 0, NULL);
5352 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5354 offset_expr.X_add_number = expr1.X_add_number;
5355 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5356 tempreg, BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5357 macro_build (p + 4, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5358 tempreg, tempreg, BFD_RELOC_MIPS_GOT_OFST);
5361 macro_build (p + 8, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5362 treg, tempreg, breg);
5367 else if (mips_pic == EMBEDDED_PIC)
5370 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5372 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5373 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
5382 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
5383 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu";
5385 s = ADDRESS_ADD_INSN;
5387 macro_build (NULL, &icnt, NULL, s, "d,v,t", treg, tempreg, breg);
5396 /* The j instruction may not be used in PIC code, since it
5397 requires an absolute address. We convert it to a b
5399 if (mips_pic == NO_PIC)
5400 macro_build (NULL, &icnt, &offset_expr, "j", "a");
5402 macro_build (NULL, &icnt, &offset_expr, "b", "p");
5405 /* The jal instructions must be handled as macros because when
5406 generating PIC code they expand to multi-instruction
5407 sequences. Normally they are simple instructions. */
5412 if (mips_pic == NO_PIC
5413 || mips_pic == EMBEDDED_PIC)
5414 macro_build (NULL, &icnt, NULL, "jalr", "d,s", dreg, sreg);
5415 else if (mips_pic == SVR4_PIC)
5417 if (sreg != PIC_CALL_REG)
5418 as_warn (_("MIPS PIC call to register other than $25"));
5420 macro_build (NULL, &icnt, NULL, "jalr", "d,s", dreg, sreg);
5423 if (mips_cprestore_offset < 0)
5424 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5427 if (! mips_frame_reg_valid)
5429 as_warn (_("No .frame pseudo-op used in PIC code"));
5430 /* Quiet this warning. */
5431 mips_frame_reg_valid = 1;
5433 if (! mips_cprestore_valid)
5435 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5436 /* Quiet this warning. */
5437 mips_cprestore_valid = 1;
5439 expr1.X_add_number = mips_cprestore_offset;
5440 macro_build_ldst_constoffset (NULL, &icnt, &expr1,
5453 if (mips_pic == NO_PIC)
5454 macro_build (NULL, &icnt, &offset_expr, "jal", "a");
5455 else if (mips_pic == SVR4_PIC)
5459 /* If this is a reference to an external symbol, and we are
5460 using a small GOT, we want
5461 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5465 lw $gp,cprestore($sp)
5466 The cprestore value is set using the .cprestore
5467 pseudo-op. If we are using a big GOT, we want
5468 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5470 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5474 lw $gp,cprestore($sp)
5475 If the symbol is not external, we want
5476 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5478 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5481 lw $gp,cprestore($sp)
5483 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
5484 sequences above, minus nops, unless the symbol is local,
5485 which enables us to use GOT_PAGE/GOT_OFST (big got) or
5492 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5493 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5495 frag_var (rs_machine_dependent, 0, 0,
5496 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5497 offset_expr.X_add_symbol, 0, NULL);
5502 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5503 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_HI16);
5504 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5505 PIC_CALL_REG, PIC_CALL_REG, mips_gp_register);
5506 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5507 "t,o(b)", PIC_CALL_REG,
5508 BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5509 p = frag_var (rs_machine_dependent, 8, 0,
5510 RELAX_ENCODE (12, 8, 0, 4, 0, 0),
5511 offset_expr.X_add_symbol, 0, NULL);
5512 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5513 "t,o(b)", PIC_CALL_REG,
5514 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5515 macro_build (p + 4, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5516 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5517 BFD_RELOC_MIPS_GOT_OFST);
5520 macro_build_jalr (icnt, &offset_expr);
5527 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5528 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5530 macro_build (NULL, &icnt, NULL, "nop", "");
5531 p = frag_var (rs_machine_dependent, 4, 0,
5532 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5533 offset_expr.X_add_symbol, 0, NULL);
5539 if (reg_needs_delay (mips_gp_register))
5543 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5544 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_HI16);
5545 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5546 PIC_CALL_REG, PIC_CALL_REG, mips_gp_register);
5547 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5548 "t,o(b)", PIC_CALL_REG,
5549 BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5550 macro_build (NULL, &icnt, NULL, "nop", "");
5551 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5552 RELAX_ENCODE (16, 12 + gpdel, gpdel,
5554 offset_expr.X_add_symbol, 0, NULL);
5557 macro_build (p, &icnt, NULL, "nop", "");
5560 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5561 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
5564 macro_build (p, &icnt, NULL, "nop", "");
5567 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5568 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5570 macro_build_jalr (icnt, &offset_expr);
5572 if (mips_cprestore_offset < 0)
5573 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5576 if (! mips_frame_reg_valid)
5578 as_warn (_("No .frame pseudo-op used in PIC code"));
5579 /* Quiet this warning. */
5580 mips_frame_reg_valid = 1;
5582 if (! mips_cprestore_valid)
5584 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5585 /* Quiet this warning. */
5586 mips_cprestore_valid = 1;
5588 if (mips_opts.noreorder)
5589 macro_build (NULL, &icnt, NULL, "nop", "");
5590 expr1.X_add_number = mips_cprestore_offset;
5591 macro_build_ldst_constoffset (NULL, &icnt, &expr1,
5598 else if (mips_pic == EMBEDDED_PIC)
5600 macro_build (NULL, &icnt, &offset_expr, "bal", "p");
5601 /* The linker may expand the call to a longer sequence which
5602 uses $at, so we must break rather than return. */
5627 /* Itbl support may require additional care here. */
5632 /* Itbl support may require additional care here. */
5637 /* Itbl support may require additional care here. */
5642 /* Itbl support may require additional care here. */
5654 if (mips_opts.arch == CPU_R4650)
5656 as_bad (_("opcode not supported on this processor"));
5660 /* Itbl support may require additional care here. */
5665 /* Itbl support may require additional care here. */
5670 /* Itbl support may require additional care here. */
5690 if (breg == treg || coproc || lr)
5712 /* Itbl support may require additional care here. */
5717 /* Itbl support may require additional care here. */
5722 /* Itbl support may require additional care here. */
5727 /* Itbl support may require additional care here. */
5743 if (mips_opts.arch == CPU_R4650)
5745 as_bad (_("opcode not supported on this processor"));
5750 /* Itbl support may require additional care here. */
5754 /* Itbl support may require additional care here. */
5759 /* Itbl support may require additional care here. */
5771 /* Itbl support may require additional care here. */
5772 if (mask == M_LWC1_AB
5773 || mask == M_SWC1_AB
5774 || mask == M_LDC1_AB
5775 || mask == M_SDC1_AB
5784 /* For embedded PIC, we allow loads where the offset is calculated
5785 by subtracting a symbol in the current segment from an unknown
5786 symbol, relative to a base register, e.g.:
5787 <op> $treg, <sym>-<localsym>($breg)
5788 This is used by the compiler for switch statements. */
5789 if (mips_pic == EMBEDDED_PIC
5790 && offset_expr.X_op == O_subtract
5791 && (symbol_constant_p (offset_expr.X_op_symbol)
5792 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5793 : (symbol_equated_p (offset_expr.X_op_symbol)
5795 (symbol_get_value_expression (offset_expr.X_op_symbol)
5799 && (offset_expr.X_add_number == 0
5800 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5802 /* For this case, we output the instructions:
5803 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5804 addiu $tempreg,$tempreg,$breg
5805 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5806 If the relocation would fit entirely in 16 bits, it would be
5808 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5809 instead, but that seems quite difficult. */
5810 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
5811 BFD_RELOC_PCREL_HI16_S);
5812 macro_build (NULL, &icnt, NULL,
5813 ((bfd_arch_bits_per_address (stdoutput) == 32
5814 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5815 ? "addu" : "daddu"),
5816 "d,v,t", tempreg, tempreg, breg);
5817 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
5818 BFD_RELOC_PCREL_LO16, tempreg);
5824 if (offset_expr.X_op != O_constant
5825 && offset_expr.X_op != O_symbol)
5827 as_bad (_("expression too complex"));
5828 offset_expr.X_op = O_constant;
5831 /* A constant expression in PIC code can be handled just as it
5832 is in non PIC code. */
5833 if (mips_pic == NO_PIC
5834 || offset_expr.X_op == O_constant)
5838 /* If this is a reference to a GP relative symbol, and there
5839 is no base register, we want
5840 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5841 Otherwise, if there is no base register, we want
5842 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5843 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5844 If we have a constant, we need two instructions anyhow,
5845 so we always use the latter form.
5847 If we have a base register, and this is a reference to a
5848 GP relative symbol, we want
5849 addu $tempreg,$breg,$gp
5850 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5852 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5853 addu $tempreg,$tempreg,$breg
5854 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5855 With a constant we always use the latter case.
5857 With 64bit address space and no base register and $at usable,
5859 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5860 lui $at,<sym> (BFD_RELOC_HI16_S)
5861 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5864 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5865 If we have a base register, we want
5866 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5867 lui $at,<sym> (BFD_RELOC_HI16_S)
5868 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5872 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5874 Without $at we can't generate the optimal path for superscalar
5875 processors here since this would require two temporary registers.
5876 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5877 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5879 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5881 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5882 If we have a base register, we want
5883 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5884 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5886 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5888 daddu $tempreg,$tempreg,$breg
5889 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5891 If we have 64-bit addresses, as an optimization, for
5892 addresses which are 32-bit constants (e.g. kseg0/kseg1
5893 addresses) we fall back to the 32-bit address generation
5894 mechanism since it is more efficient. Note that due to
5895 the signed offset used by memory operations, the 32-bit
5896 range is shifted down by 32768 here. This code should
5897 probably attempt to generate 64-bit constants more
5898 efficiently in general.
5900 As an extension for architectures with 64-bit registers,
5901 we don't truncate 64-bit addresses given as literal
5902 constants down to 32 bits, to support existing practice
5903 in the mips64 Linux (the kernel), that compiles source
5904 files with -mabi=64, assembling them as o32 or n32 (with
5905 -Wa,-32 or -Wa,-n32). This is not beautiful, but since
5906 the whole kernel is loaded into a memory region that is
5907 addressible with sign-extended 32-bit addresses, it is
5908 wasteful to compute the upper 32 bits of every
5909 non-literal address, that takes more space and time.
5910 Some day this should probably be implemented as an
5911 assembler option, such that the kernel doesn't have to
5912 use such ugly hacks, even though it will still have to
5913 end up converting the binary to ELF32 for a number of
5914 platforms whose boot loaders don't support ELF64
5916 if ((offset_expr.X_op != O_constant && HAVE_64BIT_ADDRESSES)
5917 || (offset_expr.X_op == O_constant
5918 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000)
5919 && HAVE_64BIT_ADDRESS_CONSTANTS))
5923 /* We don't do GP optimization for now because RELAX_ENCODE can't
5924 hold the data for such large chunks. */
5926 if (used_at == 0 && ! mips_opts.noat)
5928 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5929 tempreg, BFD_RELOC_MIPS_HIGHEST);
5930 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5931 AT, BFD_RELOC_HI16_S);
5932 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5933 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
5935 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
5937 macro_build (p, &icnt, NULL, "dsll32", "d,w,<",
5938 tempreg, tempreg, 0);
5939 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
5940 tempreg, tempreg, AT);
5941 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5942 BFD_RELOC_LO16, tempreg);
5947 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5948 tempreg, BFD_RELOC_MIPS_HIGHEST);
5949 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5950 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
5951 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
5952 tempreg, tempreg, 16);
5953 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5954 tempreg, tempreg, BFD_RELOC_HI16_S);
5955 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
5956 tempreg, tempreg, 16);
5958 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
5959 tempreg, tempreg, breg);
5960 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5961 BFD_RELOC_LO16, tempreg);
5966 else if (offset_expr.X_op == O_constant
5967 && !HAVE_64BIT_ADDRESS_CONSTANTS
5968 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
5969 as_bad (_("load/store address overflow (max 32 bits)"));
5973 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5974 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5979 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
5980 BFD_RELOC_GPREL16, mips_gp_register);
5981 p = frag_var (rs_machine_dependent, 8, 0,
5982 RELAX_ENCODE (4, 8, 0, 4, 0,
5983 (mips_opts.warn_about_macros
5985 && mips_opts.noat))),
5986 offset_expr.X_add_symbol, 0, NULL);
5989 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5992 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5993 BFD_RELOC_LO16, tempreg);
5997 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5998 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6003 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6004 tempreg, breg, mips_gp_register);
6005 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6006 BFD_RELOC_GPREL16, tempreg);
6007 p = frag_var (rs_machine_dependent, 12, 0,
6008 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
6009 offset_expr.X_add_symbol, 0, NULL);
6011 macro_build_lui (p, &icnt, &offset_expr, tempreg);
6014 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6015 tempreg, tempreg, breg);
6018 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6019 BFD_RELOC_LO16, tempreg);
6022 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6025 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
6027 /* If this is a reference to an external symbol, we want
6028 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6030 <op> $treg,0($tempreg)
6032 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6034 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6035 <op> $treg,0($tempreg)
6038 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6039 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6041 If there is a base register, we add it to $tempreg before
6042 the <op>. If there is a constant, we stick it in the
6043 <op> instruction. We don't handle constants larger than
6044 16 bits, because we have no way to load the upper 16 bits
6045 (actually, we could handle them for the subset of cases
6046 in which we are not using $at). */
6047 assert (offset_expr.X_op == O_symbol);
6050 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6051 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_PAGE,
6054 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6055 tempreg, tempreg, breg);
6056 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6057 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6064 expr1.X_add_number = offset_expr.X_add_number;
6065 offset_expr.X_add_number = 0;
6066 if (expr1.X_add_number < -0x8000
6067 || expr1.X_add_number >= 0x8000)
6068 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6070 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6071 tempreg, lw_reloc_type, mips_gp_register);
6072 macro_build (NULL, &icnt, NULL, "nop", "");
6073 p = frag_var (rs_machine_dependent, 4, 0,
6074 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
6075 offset_expr.X_add_symbol, 0, NULL);
6076 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
6077 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
6079 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6080 tempreg, tempreg, breg);
6081 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6084 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
6089 /* If this is a reference to an external symbol, we want
6090 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6091 addu $tempreg,$tempreg,$gp
6092 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6093 <op> $treg,0($tempreg)
6095 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6097 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6098 <op> $treg,0($tempreg)
6099 If there is a base register, we add it to $tempreg before
6100 the <op>. If there is a constant, we stick it in the
6101 <op> instruction. We don't handle constants larger than
6102 16 bits, because we have no way to load the upper 16 bits
6103 (actually, we could handle them for the subset of cases
6104 in which we are not using $at). */
6105 assert (offset_expr.X_op == O_symbol);
6106 expr1.X_add_number = offset_expr.X_add_number;
6107 offset_expr.X_add_number = 0;
6108 if (expr1.X_add_number < -0x8000
6109 || expr1.X_add_number >= 0x8000)
6110 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6111 if (reg_needs_delay (mips_gp_register))
6116 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
6117 BFD_RELOC_MIPS_GOT_HI16);
6118 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6119 tempreg, tempreg, mips_gp_register);
6120 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6121 tempreg, BFD_RELOC_MIPS_GOT_LO16, tempreg);
6122 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
6123 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
6124 offset_expr.X_add_symbol, 0, NULL);
6127 macro_build (p, &icnt, NULL, "nop", "");
6130 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6131 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6133 macro_build (p, &icnt, NULL, "nop", "");
6135 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
6136 tempreg, tempreg, BFD_RELOC_LO16);
6138 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6139 tempreg, tempreg, breg);
6140 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6143 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
6146 int bregsz = breg != 0 ? 4 : 0;
6148 /* If this is a reference to an external symbol, we want
6149 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6150 add $tempreg,$tempreg,$gp
6151 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6152 <op> $treg,<ofst>($tempreg)
6153 Otherwise, for local symbols, we want:
6154 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6155 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6156 assert (offset_expr.X_op == O_symbol);
6157 frag_now->tc_frag_data.tc_fr_offset =
6158 expr1.X_add_number = offset_expr.X_add_number;
6159 offset_expr.X_add_number = 0;
6160 if (expr1.X_add_number < -0x8000
6161 || expr1.X_add_number >= 0x8000)
6162 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6164 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
6165 BFD_RELOC_MIPS_GOT_HI16);
6166 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6167 tempreg, tempreg, mips_gp_register);
6168 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6169 tempreg, BFD_RELOC_MIPS_GOT_LO16, tempreg);
6171 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6172 tempreg, tempreg, breg);
6173 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6176 offset_expr.X_add_number = expr1.X_add_number;
6177 p = frag_var (rs_machine_dependent, 12 + bregsz, 0,
6178 RELAX_ENCODE (16 + bregsz, 8 + bregsz,
6179 0, 4 + bregsz, 0, 0),
6180 offset_expr.X_add_symbol, 0, NULL);
6181 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6182 tempreg, BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6184 macro_build (p + 4, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6185 tempreg, tempreg, breg);
6186 macro_build (p + 4 + bregsz, &icnt, &offset_expr, s, fmt, treg,
6187 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6189 else if (mips_pic == EMBEDDED_PIC)
6191 /* If there is no base register, we want
6192 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6193 If there is a base register, we want
6194 addu $tempreg,$breg,$gp
6195 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6197 assert (offset_expr.X_op == O_symbol);
6200 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6201 BFD_RELOC_GPREL16, mips_gp_register);
6206 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6207 tempreg, breg, mips_gp_register);
6208 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6209 BFD_RELOC_GPREL16, tempreg);
6222 load_register (&icnt, treg, &imm_expr, 0);
6226 load_register (&icnt, treg, &imm_expr, 1);
6230 if (imm_expr.X_op == O_constant)
6232 load_register (&icnt, AT, &imm_expr, 0);
6233 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg);
6238 assert (offset_expr.X_op == O_symbol
6239 && strcmp (segment_name (S_GET_SEGMENT
6240 (offset_expr.X_add_symbol)),
6242 && offset_expr.X_add_number == 0);
6243 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", treg,
6244 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6249 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6250 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6251 order 32 bits of the value and the low order 32 bits are either
6252 zero or in OFFSET_EXPR. */
6253 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6255 if (HAVE_64BIT_GPRS)
6256 load_register (&icnt, treg, &imm_expr, 1);
6261 if (target_big_endian)
6273 load_register (&icnt, hreg, &imm_expr, 0);
6276 if (offset_expr.X_op == O_absent)
6277 move_register (&icnt, lreg, 0);
6280 assert (offset_expr.X_op == O_constant);
6281 load_register (&icnt, lreg, &offset_expr, 0);
6288 /* We know that sym is in the .rdata section. First we get the
6289 upper 16 bits of the address. */
6290 if (mips_pic == NO_PIC)
6292 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6294 else if (mips_pic == SVR4_PIC)
6296 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6297 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6299 else if (mips_pic == EMBEDDED_PIC)
6301 /* For embedded PIC we pick up the entire address off $gp in
6302 a single instruction. */
6303 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
6304 AT, mips_gp_register, BFD_RELOC_GPREL16);
6305 offset_expr.X_op = O_constant;
6306 offset_expr.X_add_number = 0;
6311 /* Now we load the register(s). */
6312 if (HAVE_64BIT_GPRS)
6313 macro_build (NULL, &icnt, &offset_expr, "ld", "t,o(b)", treg,
6314 BFD_RELOC_LO16, AT);
6317 macro_build (NULL, &icnt, &offset_expr, "lw", "t,o(b)", treg,
6318 BFD_RELOC_LO16, AT);
6321 /* FIXME: How in the world do we deal with the possible
6323 offset_expr.X_add_number += 4;
6324 macro_build (NULL, &icnt, &offset_expr, "lw", "t,o(b)",
6325 treg + 1, BFD_RELOC_LO16, AT);
6329 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6330 does not become a variant frag. */
6331 frag_wane (frag_now);
6337 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6338 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6339 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6340 the value and the low order 32 bits are either zero or in
6342 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6344 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
6345 if (HAVE_64BIT_FPRS)
6347 assert (HAVE_64BIT_GPRS);
6348 macro_build (NULL, &icnt, NULL, "dmtc1", "t,S", AT, treg);
6352 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg + 1);
6353 if (offset_expr.X_op == O_absent)
6354 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", 0, treg);
6357 assert (offset_expr.X_op == O_constant);
6358 load_register (&icnt, AT, &offset_expr, 0);
6359 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg);
6365 assert (offset_expr.X_op == O_symbol
6366 && offset_expr.X_add_number == 0);
6367 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
6368 if (strcmp (s, ".lit8") == 0)
6370 if (mips_opts.isa != ISA_MIPS1)
6372 macro_build (NULL, &icnt, &offset_expr, "ldc1", "T,o(b)", treg,
6373 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6376 breg = mips_gp_register;
6377 r = BFD_RELOC_MIPS_LITERAL;
6382 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
6383 if (mips_pic == SVR4_PIC)
6384 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6385 "t,o(b)", AT, BFD_RELOC_MIPS_GOT16,
6389 /* FIXME: This won't work for a 64 bit address. */
6390 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6393 if (mips_opts.isa != ISA_MIPS1)
6395 macro_build (NULL, &icnt, &offset_expr, "ldc1", "T,o(b)", treg,
6396 BFD_RELOC_LO16, AT);
6398 /* To avoid confusion in tc_gen_reloc, we must ensure
6399 that this does not become a variant frag. */
6400 frag_wane (frag_now);
6411 if (mips_opts.arch == CPU_R4650)
6413 as_bad (_("opcode not supported on this processor"));
6416 /* Even on a big endian machine $fn comes before $fn+1. We have
6417 to adjust when loading from memory. */
6420 assert (mips_opts.isa == ISA_MIPS1);
6421 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6422 target_big_endian ? treg + 1 : treg, r, breg);
6423 /* FIXME: A possible overflow which I don't know how to deal
6425 offset_expr.X_add_number += 4;
6426 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6427 target_big_endian ? treg : treg + 1, r, breg);
6429 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6430 does not become a variant frag. */
6431 frag_wane (frag_now);
6440 * The MIPS assembler seems to check for X_add_number not
6441 * being double aligned and generating:
6444 * addiu at,at,%lo(foo+1)
6447 * But, the resulting address is the same after relocation so why
6448 * generate the extra instruction?
6450 if (mips_opts.arch == CPU_R4650)
6452 as_bad (_("opcode not supported on this processor"));
6455 /* Itbl support may require additional care here. */
6457 if (mips_opts.isa != ISA_MIPS1)
6468 if (mips_opts.arch == CPU_R4650)
6470 as_bad (_("opcode not supported on this processor"));
6474 if (mips_opts.isa != ISA_MIPS1)
6482 /* Itbl support may require additional care here. */
6487 if (HAVE_64BIT_GPRS)
6498 if (HAVE_64BIT_GPRS)
6508 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6509 loads for the case of doing a pair of loads to simulate an 'ld'.
6510 This is not currently done by the compiler, and assembly coders
6511 writing embedded-pic code can cope. */
6513 if (offset_expr.X_op != O_symbol
6514 && offset_expr.X_op != O_constant)
6516 as_bad (_("expression too complex"));
6517 offset_expr.X_op = O_constant;
6520 /* Even on a big endian machine $fn comes before $fn+1. We have
6521 to adjust when loading from memory. We set coproc if we must
6522 load $fn+1 first. */
6523 /* Itbl support may require additional care here. */
6524 if (! target_big_endian)
6527 if (mips_pic == NO_PIC
6528 || offset_expr.X_op == O_constant)
6532 /* If this is a reference to a GP relative symbol, we want
6533 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6534 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6535 If we have a base register, we use this
6537 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6538 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6539 If this is not a GP relative symbol, we want
6540 lui $at,<sym> (BFD_RELOC_HI16_S)
6541 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6542 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6543 If there is a base register, we add it to $at after the
6544 lui instruction. If there is a constant, we always use
6546 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6547 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6559 tempreg = mips_gp_register;
6566 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6567 AT, breg, mips_gp_register);
6573 /* Itbl support may require additional care here. */
6574 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6575 coproc ? treg + 1 : treg,
6576 BFD_RELOC_GPREL16, tempreg);
6577 offset_expr.X_add_number += 4;
6579 /* Set mips_optimize to 2 to avoid inserting an
6581 hold_mips_optimize = mips_optimize;
6583 /* Itbl support may require additional care here. */
6584 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6585 coproc ? treg : treg + 1,
6586 BFD_RELOC_GPREL16, tempreg);
6587 mips_optimize = hold_mips_optimize;
6589 p = frag_var (rs_machine_dependent, 12 + off, 0,
6590 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6591 used_at && mips_opts.noat),
6592 offset_expr.X_add_symbol, 0, NULL);
6594 /* We just generated two relocs. When tc_gen_reloc
6595 handles this case, it will skip the first reloc and
6596 handle the second. The second reloc already has an
6597 extra addend of 4, which we added above. We must
6598 subtract it out, and then subtract another 4 to make
6599 the first reloc come out right. The second reloc
6600 will come out right because we are going to add 4 to
6601 offset_expr when we build its instruction below.
6603 If we have a symbol, then we don't want to include
6604 the offset, because it will wind up being included
6605 when we generate the reloc. */
6607 if (offset_expr.X_op == O_constant)
6608 offset_expr.X_add_number -= 8;
6611 offset_expr.X_add_number = -4;
6612 offset_expr.X_op = O_constant;
6615 macro_build_lui (p, &icnt, &offset_expr, AT);
6620 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6625 /* Itbl support may require additional care here. */
6626 macro_build (p, &icnt, &offset_expr, s, fmt,
6627 coproc ? treg + 1 : treg,
6628 BFD_RELOC_LO16, AT);
6631 /* FIXME: How do we handle overflow here? */
6632 offset_expr.X_add_number += 4;
6633 /* Itbl support may require additional care here. */
6634 macro_build (p, &icnt, &offset_expr, s, fmt,
6635 coproc ? treg : treg + 1,
6636 BFD_RELOC_LO16, AT);
6638 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6642 /* If this is a reference to an external symbol, we want
6643 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6648 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6650 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6651 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6652 If there is a base register we add it to $at before the
6653 lwc1 instructions. If there is a constant we include it
6654 in the lwc1 instructions. */
6656 expr1.X_add_number = offset_expr.X_add_number;
6657 offset_expr.X_add_number = 0;
6658 if (expr1.X_add_number < -0x8000
6659 || expr1.X_add_number >= 0x8000 - 4)
6660 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6665 frag_grow (24 + off);
6666 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6667 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6668 macro_build (NULL, &icnt, NULL, "nop", "");
6670 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6672 /* Itbl support may require additional care here. */
6673 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6674 BFD_RELOC_LO16, AT);
6675 expr1.X_add_number += 4;
6677 /* Set mips_optimize to 2 to avoid inserting an undesired
6679 hold_mips_optimize = mips_optimize;
6681 /* Itbl support may require additional care here. */
6682 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6683 BFD_RELOC_LO16, AT);
6684 mips_optimize = hold_mips_optimize;
6686 (void) frag_var (rs_machine_dependent, 0, 0,
6687 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6688 offset_expr.X_add_symbol, 0, NULL);
6690 else if (mips_pic == SVR4_PIC)
6695 /* If this is a reference to an external symbol, we want
6696 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6698 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6703 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6705 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6706 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6707 If there is a base register we add it to $at before the
6708 lwc1 instructions. If there is a constant we include it
6709 in the lwc1 instructions. */
6711 expr1.X_add_number = offset_expr.X_add_number;
6712 offset_expr.X_add_number = 0;
6713 if (expr1.X_add_number < -0x8000
6714 || expr1.X_add_number >= 0x8000 - 4)
6715 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6716 if (reg_needs_delay (mips_gp_register))
6725 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", AT,
6726 BFD_RELOC_MIPS_GOT_HI16);
6727 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6728 AT, AT, mips_gp_register);
6729 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6730 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
6731 macro_build (NULL, &icnt, NULL, "nop", "");
6733 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6735 /* Itbl support may require additional care here. */
6736 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6737 BFD_RELOC_LO16, AT);
6738 expr1.X_add_number += 4;
6740 /* Set mips_optimize to 2 to avoid inserting an undesired
6742 hold_mips_optimize = mips_optimize;
6744 /* Itbl support may require additional care here. */
6745 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6746 BFD_RELOC_LO16, AT);
6747 mips_optimize = hold_mips_optimize;
6748 expr1.X_add_number -= 4;
6750 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6751 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6752 8 + gpdel + off, 1, 0),
6753 offset_expr.X_add_symbol, 0, NULL);
6756 macro_build (p, &icnt, NULL, "nop", "");
6759 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6760 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6762 macro_build (p, &icnt, NULL, "nop", "");
6766 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6770 /* Itbl support may require additional care here. */
6771 macro_build (p, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6772 BFD_RELOC_LO16, AT);
6774 expr1.X_add_number += 4;
6776 /* Set mips_optimize to 2 to avoid inserting an undesired
6778 hold_mips_optimize = mips_optimize;
6780 /* Itbl support may require additional care here. */
6781 macro_build (p, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6782 BFD_RELOC_LO16, AT);
6783 mips_optimize = hold_mips_optimize;
6785 else if (mips_pic == EMBEDDED_PIC)
6787 /* If there is no base register, we use
6788 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6789 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6790 If we have a base register, we use
6792 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6793 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6797 tempreg = mips_gp_register;
6802 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6803 AT, breg, mips_gp_register);
6808 /* Itbl support may require additional care here. */
6809 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6810 coproc ? treg + 1 : treg,
6811 BFD_RELOC_GPREL16, tempreg);
6812 offset_expr.X_add_number += 4;
6813 /* Itbl support may require additional care here. */
6814 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6815 coproc ? treg : treg + 1,
6816 BFD_RELOC_GPREL16, tempreg);
6832 assert (HAVE_32BIT_ADDRESSES);
6833 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6834 BFD_RELOC_LO16, breg);
6835 offset_expr.X_add_number += 4;
6836 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
6837 BFD_RELOC_LO16, breg);
6840 /* New code added to support COPZ instructions.
6841 This code builds table entries out of the macros in mip_opcodes.
6842 R4000 uses interlocks to handle coproc delays.
6843 Other chips (like the R3000) require nops to be inserted for delays.
6845 FIXME: Currently, we require that the user handle delays.
6846 In order to fill delay slots for non-interlocked chips,
6847 we must have a way to specify delays based on the coprocessor.
6848 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6849 What are the side-effects of the cop instruction?
6850 What cache support might we have and what are its effects?
6851 Both coprocessor & memory require delays. how long???
6852 What registers are read/set/modified?
6854 If an itbl is provided to interpret cop instructions,
6855 this knowledge can be encoded in the itbl spec. */
6869 /* For now we just do C (same as Cz). The parameter will be
6870 stored in insn_opcode by mips_ip. */
6871 macro_build (NULL, &icnt, NULL, s, "C", ip->insn_opcode);
6875 move_register (&icnt, dreg, sreg);
6878 #ifdef LOSING_COMPILER
6880 /* Try and see if this is a new itbl instruction.
6881 This code builds table entries out of the macros in mip_opcodes.
6882 FIXME: For now we just assemble the expression and pass it's
6883 value along as a 32-bit immediate.
6884 We may want to have the assembler assemble this value,
6885 so that we gain the assembler's knowledge of delay slots,
6887 Would it be more efficient to use mask (id) here? */
6888 if (itbl_have_entries
6889 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6891 s = ip->insn_mo->name;
6893 coproc = ITBL_DECODE_PNUM (immed_expr);;
6894 macro_build (NULL, &icnt, &immed_expr, s, "C");
6901 as_warn (_("Macro used $at after \".set noat\""));
6905 macro2 (struct mips_cl_insn *ip)
6907 register int treg, sreg, dreg, breg;
6923 bfd_reloc_code_real_type r;
6926 treg = (ip->insn_opcode >> 16) & 0x1f;
6927 dreg = (ip->insn_opcode >> 11) & 0x1f;
6928 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6929 mask = ip->insn_mo->mask;
6931 expr1.X_op = O_constant;
6932 expr1.X_op_symbol = NULL;
6933 expr1.X_add_symbol = NULL;
6934 expr1.X_add_number = 1;
6938 #endif /* LOSING_COMPILER */
6943 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "s,t",
6945 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
6951 /* The MIPS assembler some times generates shifts and adds. I'm
6952 not trying to be that fancy. GCC should do this for us
6954 load_register (&icnt, AT, &imm_expr, dbl);
6955 macro_build (NULL, &icnt, NULL, dbl ? "dmult" : "mult", "s,t",
6957 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
6970 mips_emit_delays (TRUE);
6971 ++mips_opts.noreorder;
6972 mips_any_noreorder = 1;
6974 load_register (&icnt, AT, &imm_expr, dbl);
6975 macro_build (NULL, &icnt, NULL, dbl ? "dmult" : "mult", "s,t",
6976 sreg, imm ? AT : treg);
6977 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
6978 macro_build (NULL, &icnt, NULL, dbl ? "dsra32" : "sra", "d,w,<",
6980 macro_build (NULL, &icnt, NULL, "mfhi", "d", AT);
6982 macro_build (NULL, &icnt, NULL, "tne", "s,t,q", dreg, AT, 6);
6985 expr1.X_add_number = 8;
6986 macro_build (NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
6987 macro_build (NULL, &icnt, NULL, "nop", "", 0);
6988 macro_build (NULL, &icnt, NULL, "break", "c", 6);
6990 --mips_opts.noreorder;
6991 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7004 mips_emit_delays (TRUE);
7005 ++mips_opts.noreorder;
7006 mips_any_noreorder = 1;
7008 load_register (&icnt, AT, &imm_expr, dbl);
7009 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "s,t",
7010 sreg, imm ? AT : treg);
7011 macro_build (NULL, &icnt, NULL, "mfhi", "d", AT);
7012 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7014 macro_build (NULL, &icnt, NULL, "tne", "s,t,q", AT, 0, 6);
7017 expr1.X_add_number = 8;
7018 macro_build (NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
7019 macro_build (NULL, &icnt, NULL, "nop", "", 0);
7020 macro_build (NULL, &icnt, NULL, "break", "c", 6);
7022 --mips_opts.noreorder;
7026 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7038 macro_build (NULL, &icnt, NULL, "dnegu", "d,w", tempreg, treg);
7039 macro_build (NULL, &icnt, NULL, "drorv", "d,t,s", dreg, sreg,
7045 macro_build (NULL, &icnt, NULL, "dsubu", "d,v,t", AT, 0, treg);
7046 macro_build (NULL, &icnt, NULL, "dsrlv", "d,t,s", AT, sreg, AT);
7047 macro_build (NULL, &icnt, NULL, "dsllv", "d,t,s", dreg, sreg, treg);
7048 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7052 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7064 macro_build (NULL, &icnt, NULL, "negu", "d,w", tempreg, treg);
7065 macro_build (NULL, &icnt, NULL, "rorv", "d,t,s", dreg, sreg,
7071 macro_build (NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
7072 macro_build (NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT);
7073 macro_build (NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg, treg);
7074 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7082 if (imm_expr.X_op != O_constant)
7083 as_bad (_("Improper rotate count"));
7084 rot = imm_expr.X_add_number & 0x3f;
7085 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7087 rot = (64 - rot) & 0x3f;
7089 macro_build (NULL, &icnt, NULL, "dror32", "d,w,<",
7090 dreg, sreg, rot - 32);
7092 macro_build (NULL, &icnt, NULL, "dror", "d,w,<",
7098 macro_build (NULL, &icnt, NULL, "dsrl", "d,w,<", dreg, sreg, 0);
7101 l = (rot < 0x20) ? "dsll" : "dsll32";
7102 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
7104 macro_build (NULL, &icnt, NULL, l, "d,w,<", AT, sreg, rot);
7105 macro_build (NULL, &icnt, NULL, r, "d,w,<", dreg, sreg,
7106 (0x20 - rot) & 0x1f);
7107 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7115 if (imm_expr.X_op != O_constant)
7116 as_bad (_("Improper rotate count"));
7117 rot = imm_expr.X_add_number & 0x1f;
7118 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7120 macro_build (NULL, &icnt, NULL, "ror", "d,w,<", dreg, sreg,
7126 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, 0);
7129 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg, rot);
7130 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg,
7131 (0x20 - rot) & 0x1f);
7132 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7137 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7139 macro_build (NULL, &icnt, NULL, "drorv", "d,t,s", dreg, sreg, treg);
7142 macro_build (NULL, &icnt,NULL, "dsubu", "d,v,t", AT, 0, treg);
7143 macro_build (NULL, &icnt, NULL, "dsllv", "d,t,s", AT, sreg, AT);
7144 macro_build (NULL, &icnt, NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
7145 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7149 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7151 macro_build (NULL, &icnt, NULL, "rorv", "d,t,s", dreg, sreg, treg);
7154 macro_build (NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
7155 macro_build (NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT);
7156 macro_build (NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg, treg);
7157 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7165 if (imm_expr.X_op != O_constant)
7166 as_bad (_("Improper rotate count"));
7167 rot = imm_expr.X_add_number & 0x3f;
7168 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7171 macro_build (NULL, &icnt, NULL, "dror32", "d,w,<",
7172 dreg, sreg, rot - 32);
7174 macro_build (NULL, &icnt, NULL, "dror", "d,w,<",
7180 macro_build (NULL, &icnt, NULL, "dsrl", "d,w,<", dreg, sreg, 0);
7183 r = (rot < 0x20) ? "dsrl" : "dsrl32";
7184 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
7186 macro_build ( NULL, &icnt,NULL, r, "d,w,<", AT, sreg, rot);
7187 macro_build (NULL, &icnt, NULL, l, "d,w,<", dreg, sreg,
7188 (0x20 - rot) & 0x1f);
7189 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7197 if (imm_expr.X_op != O_constant)
7198 as_bad (_("Improper rotate count"));
7199 rot = imm_expr.X_add_number & 0x1f;
7200 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7202 macro_build (NULL, &icnt, NULL, "ror", "d,w,<", dreg, sreg, rot);
7207 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, 0);
7210 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg, rot);
7211 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg,
7212 (0x20 - rot) & 0x1f);
7213 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7218 if (mips_opts.arch == CPU_R4650)
7220 as_bad (_("opcode not supported on this processor"));
7223 assert (mips_opts.isa == ISA_MIPS1);
7224 /* Even on a big endian machine $fn comes before $fn+1. We have
7225 to adjust when storing to memory. */
7226 macro_build (NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
7227 target_big_endian ? treg + 1 : treg,
7228 BFD_RELOC_LO16, breg);
7229 offset_expr.X_add_number += 4;
7230 macro_build (NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
7231 target_big_endian ? treg : treg + 1,
7232 BFD_RELOC_LO16, breg);
7237 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, treg,
7240 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, sreg,
7244 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, treg);
7245 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
7251 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7253 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, sreg,
7259 as_warn (_("Instruction %s: result is always false"),
7261 move_register (&icnt, dreg, 0);
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 (NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, sreg,
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 (NULL, &icnt, &imm_expr,
7278 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7279 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7284 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7285 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, AT);
7288 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
7294 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
7300 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg);
7301 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7305 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
7307 if (imm_expr.X_op == O_constant
7308 && imm_expr.X_add_number >= -0x8000
7309 && imm_expr.X_add_number < 0x8000)
7311 macro_build (NULL, &icnt, &imm_expr,
7312 mask == M_SGE_I ? "slti" : "sltiu",
7313 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7318 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7319 macro_build (NULL, &icnt, NULL, mask == M_SGE_I ? "slt" : "sltu",
7320 "d,v,t", dreg, sreg, AT);
7323 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7329 case M_SGT: /* sreg > treg <==> treg < sreg */
7335 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
7338 case M_SGT_I: /* sreg > I <==> I < sreg */
7344 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7345 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
7348 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7354 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
7355 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7359 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7365 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7366 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
7367 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7372 if (imm_expr.X_op == O_constant
7373 && imm_expr.X_add_number >= -0x8000
7374 && imm_expr.X_add_number < 0x8000)
7376 macro_build (NULL, &icnt, &imm_expr, "slti", "t,r,j", dreg, sreg,
7380 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7381 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT);
7385 if (imm_expr.X_op == O_constant
7386 && imm_expr.X_add_number >= -0x8000
7387 && imm_expr.X_add_number < 0x8000)
7389 macro_build (NULL, &icnt, &imm_expr, "sltiu", "t,r,j", dreg, sreg,
7393 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7394 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg, AT);
7399 macro_build (NULL, &icnt,NULL, "sltu","d,v,t", dreg, 0, treg);
7401 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, sreg);
7404 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, treg);
7405 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
7410 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7412 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, sreg);
7417 as_warn (_("Instruction %s: result is always true"),
7419 macro_build (NULL, &icnt, &expr1,
7420 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7421 "t,r,j", dreg, 0, BFD_RELOC_LO16);
7424 if (imm_expr.X_op == O_constant
7425 && imm_expr.X_add_number >= 0
7426 && imm_expr.X_add_number < 0x10000)
7428 macro_build (NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, sreg,
7432 else if (imm_expr.X_op == O_constant
7433 && imm_expr.X_add_number > -0x8000
7434 && imm_expr.X_add_number < 0)
7436 imm_expr.X_add_number = -imm_expr.X_add_number;
7437 macro_build (NULL, &icnt, &imm_expr,
7438 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7439 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7444 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7445 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, AT);
7448 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
7456 if (imm_expr.X_op == O_constant
7457 && imm_expr.X_add_number > -0x8000
7458 && imm_expr.X_add_number <= 0x8000)
7460 imm_expr.X_add_number = -imm_expr.X_add_number;
7461 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddi" : "addi",
7462 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7465 load_register (&icnt, AT, &imm_expr, dbl);
7466 macro_build (NULL, &icnt, NULL, dbl ? "dsub" : "sub", "d,v,t",
7473 if (imm_expr.X_op == O_constant
7474 && imm_expr.X_add_number > -0x8000
7475 && imm_expr.X_add_number <= 0x8000)
7477 imm_expr.X_add_number = -imm_expr.X_add_number;
7478 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddiu" : "addiu",
7479 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7482 load_register (&icnt, AT, &imm_expr, dbl);
7483 macro_build (NULL, &icnt, NULL, dbl ? "dsubu" : "subu", "d,v,t",
7505 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7506 macro_build (NULL, &icnt, NULL, s, "s,t", sreg, AT);
7511 assert (mips_opts.isa == ISA_MIPS1);
7512 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7513 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7516 * Is the double cfc1 instruction a bug in the mips assembler;
7517 * or is there a reason for it?
7519 mips_emit_delays (TRUE);
7520 ++mips_opts.noreorder;
7521 mips_any_noreorder = 1;
7522 macro_build (NULL, &icnt, NULL, "cfc1", "t,G", treg, RA);
7523 macro_build (NULL, &icnt, NULL, "cfc1", "t,G", treg, RA);
7524 macro_build (NULL, &icnt, NULL, "nop", "");
7525 expr1.X_add_number = 3;
7526 macro_build (NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7528 expr1.X_add_number = 2;
7529 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7531 macro_build (NULL, &icnt, NULL, "ctc1", "t,G", AT, RA);
7532 macro_build (NULL, &icnt, NULL, "nop", "");
7533 macro_build (NULL, &icnt, NULL,
7534 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s",
7536 macro_build (NULL, &icnt, NULL, "ctc1", "t,G", treg, RA);
7537 macro_build (NULL, &icnt, NULL, "nop", "");
7538 --mips_opts.noreorder;
7547 if (offset_expr.X_add_number >= 0x7fff)
7548 as_bad (_("operand overflow"));
7549 if (! target_big_endian)
7550 ++offset_expr.X_add_number;
7551 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", AT,
7552 BFD_RELOC_LO16, breg);
7553 if (! target_big_endian)
7554 --offset_expr.X_add_number;
7556 ++offset_expr.X_add_number;
7557 macro_build (NULL, &icnt, &offset_expr, "lbu", "t,o(b)", treg,
7558 BFD_RELOC_LO16, breg);
7559 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", AT, AT, 8);
7560 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7573 if (offset_expr.X_add_number >= 0x8000 - off)
7574 as_bad (_("operand overflow"));
7579 if (! target_big_endian)
7580 offset_expr.X_add_number += off;
7581 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", tempreg,
7582 BFD_RELOC_LO16, breg);
7583 if (! target_big_endian)
7584 offset_expr.X_add_number -= off;
7586 offset_expr.X_add_number += off;
7587 macro_build (NULL, &icnt, &offset_expr, s2, "t,o(b)", tempreg,
7588 BFD_RELOC_LO16, breg);
7590 /* If necessary, move the result in tempreg the final destination. */
7591 if (treg == tempreg)
7593 /* Protect second load's delay slot. */
7594 if (!gpr_interlocks)
7595 macro_build (NULL, &icnt, NULL, "nop", "");
7596 move_register (&icnt, treg, tempreg);
7610 load_address (&icnt, AT, &offset_expr, &used_at);
7612 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7614 if (! target_big_endian)
7615 expr1.X_add_number = off;
7617 expr1.X_add_number = 0;
7618 macro_build (NULL, &icnt, &expr1, s, "t,o(b)", treg,
7619 BFD_RELOC_LO16, AT);
7620 if (! target_big_endian)
7621 expr1.X_add_number = 0;
7623 expr1.X_add_number = off;
7624 macro_build (NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7625 BFD_RELOC_LO16, AT);
7631 load_address (&icnt, AT, &offset_expr, &used_at);
7633 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7635 if (target_big_endian)
7636 expr1.X_add_number = 0;
7637 macro_build (NULL, &icnt, &expr1,
7638 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)",
7639 treg, BFD_RELOC_LO16, AT);
7640 if (target_big_endian)
7641 expr1.X_add_number = 1;
7643 expr1.X_add_number = 0;
7644 macro_build (NULL, &icnt, &expr1, "lbu", "t,o(b)",
7645 AT, BFD_RELOC_LO16, AT);
7646 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
7647 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7651 if (offset_expr.X_add_number >= 0x7fff)
7652 as_bad (_("operand overflow"));
7653 if (target_big_endian)
7654 ++offset_expr.X_add_number;
7655 macro_build (NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7656 BFD_RELOC_LO16, breg);
7657 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8);
7658 if (target_big_endian)
7659 --offset_expr.X_add_number;
7661 ++offset_expr.X_add_number;
7662 macro_build (NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7663 BFD_RELOC_LO16, breg);
7676 if (offset_expr.X_add_number >= 0x8000 - off)
7677 as_bad (_("operand overflow"));
7678 if (! target_big_endian)
7679 offset_expr.X_add_number += off;
7680 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7681 BFD_RELOC_LO16, breg);
7682 if (! target_big_endian)
7683 offset_expr.X_add_number -= off;
7685 offset_expr.X_add_number += off;
7686 macro_build (NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7687 BFD_RELOC_LO16, breg);
7701 load_address (&icnt, AT, &offset_expr, &used_at);
7703 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7705 if (! target_big_endian)
7706 expr1.X_add_number = off;
7708 expr1.X_add_number = 0;
7709 macro_build (NULL, &icnt, &expr1, s, "t,o(b)", treg,
7710 BFD_RELOC_LO16, AT);
7711 if (! target_big_endian)
7712 expr1.X_add_number = 0;
7714 expr1.X_add_number = off;
7715 macro_build (NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7716 BFD_RELOC_LO16, AT);
7721 load_address (&icnt, AT, &offset_expr, &used_at);
7723 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7725 if (! target_big_endian)
7726 expr1.X_add_number = 0;
7727 macro_build (NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7728 BFD_RELOC_LO16, AT);
7729 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", treg, treg, 8);
7730 if (! target_big_endian)
7731 expr1.X_add_number = 1;
7733 expr1.X_add_number = 0;
7734 macro_build (NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7735 BFD_RELOC_LO16, AT);
7736 if (! target_big_endian)
7737 expr1.X_add_number = 0;
7739 expr1.X_add_number = 1;
7740 macro_build (NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7741 BFD_RELOC_LO16, AT);
7742 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
7743 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7747 /* FIXME: Check if this is one of the itbl macros, since they
7748 are added dynamically. */
7749 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7753 as_warn (_("Macro used $at after \".set noat\""));
7756 /* Implement macros in mips16 mode. */
7759 mips16_macro (struct mips_cl_insn *ip)
7762 int xreg, yreg, zreg, tmp;
7766 const char *s, *s2, *s3;
7768 mask = ip->insn_mo->mask;
7770 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7771 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7772 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7776 expr1.X_op = O_constant;
7777 expr1.X_op_symbol = NULL;
7778 expr1.X_add_symbol = NULL;
7779 expr1.X_add_number = 1;
7798 mips_emit_delays (TRUE);
7799 ++mips_opts.noreorder;
7800 mips_any_noreorder = 1;
7801 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "0,x,y",
7803 expr1.X_add_number = 2;
7804 macro_build (NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7805 macro_build (NULL, &icnt, NULL, "break", "6", 7);
7807 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7808 since that causes an overflow. We should do that as well,
7809 but I don't see how to do the comparisons without a temporary
7811 --mips_opts.noreorder;
7812 macro_build (NULL, &icnt, NULL, s, "x", zreg);
7831 mips_emit_delays (TRUE);
7832 ++mips_opts.noreorder;
7833 mips_any_noreorder = 1;
7834 macro_build (NULL, &icnt, NULL, s, "0,x,y", xreg, yreg);
7835 expr1.X_add_number = 2;
7836 macro_build (NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7837 macro_build (NULL, &icnt, NULL, "break", "6", 7);
7838 --mips_opts.noreorder;
7839 macro_build (NULL, &icnt, NULL, s2, "x", zreg);
7845 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "x,y",
7847 macro_build (NULL, &icnt, NULL, "mflo", "x", zreg);
7855 if (imm_expr.X_op != O_constant)
7856 as_bad (_("Unsupported large constant"));
7857 imm_expr.X_add_number = -imm_expr.X_add_number;
7858 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddiu" : "addiu", "y,x,4",
7863 if (imm_expr.X_op != O_constant)
7864 as_bad (_("Unsupported large constant"));
7865 imm_expr.X_add_number = -imm_expr.X_add_number;
7866 macro_build (NULL, &icnt, &imm_expr, "addiu", "x,k", xreg);
7870 if (imm_expr.X_op != O_constant)
7871 as_bad (_("Unsupported large constant"));
7872 imm_expr.X_add_number = -imm_expr.X_add_number;
7873 macro_build (NULL, &icnt, &imm_expr, "daddiu", "y,j", yreg);
7895 goto do_reverse_branch;
7899 goto do_reverse_branch;
7911 goto do_reverse_branch;
7922 macro_build (NULL, &icnt, NULL, s, "x,y", xreg, yreg);
7923 macro_build (NULL, &icnt, &offset_expr, s2, "p");
7950 goto do_addone_branch_i;
7955 goto do_addone_branch_i;
7970 goto do_addone_branch_i;
7977 if (imm_expr.X_op != O_constant)
7978 as_bad (_("Unsupported large constant"));
7979 ++imm_expr.X_add_number;
7982 macro_build (NULL, &icnt, &imm_expr, s, s3, xreg);
7983 macro_build (NULL, &icnt, &offset_expr, s2, "p");
7987 expr1.X_add_number = 0;
7988 macro_build (NULL, &icnt, &expr1, "slti", "x,8", yreg);
7990 move_register (&icnt, xreg, yreg);
7991 expr1.X_add_number = 2;
7992 macro_build (NULL, &icnt, &expr1, "bteqz", "p");
7993 macro_build (NULL, &icnt, NULL, "neg", "x,w", xreg, xreg);
7997 /* For consistency checking, verify that all bits are specified either
7998 by the match/mask part of the instruction definition, or by the
8001 validate_mips_insn (const struct mips_opcode *opc)
8003 const char *p = opc->args;
8005 unsigned long used_bits = opc->mask;
8007 if ((used_bits & opc->match) != opc->match)
8009 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
8010 opc->name, opc->args);
8013 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
8023 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8024 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
8025 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8026 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
8027 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8029 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8030 c, opc->name, opc->args);
8034 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8035 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8037 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
8038 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
8039 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8040 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8042 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8043 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8045 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
8046 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8048 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
8049 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
8050 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
8051 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
8052 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8053 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
8054 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8055 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8056 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8057 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8058 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8059 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8060 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8061 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
8062 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8063 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
8064 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8066 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
8067 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8068 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8069 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
8071 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8072 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8073 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
8074 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8075 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8076 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8077 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8078 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8079 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8082 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
8083 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
8084 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8085 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
8086 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
8090 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
8091 c, opc->name, opc->args);
8095 if (used_bits != 0xffffffff)
8097 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
8098 ~used_bits & 0xffffffff, opc->name, opc->args);
8104 /* This routine assembles an instruction into its binary format. As a
8105 side effect, it sets one of the global variables imm_reloc or
8106 offset_reloc to the type of relocation to do if one of the operands
8107 is an address expression. */
8110 mips_ip (char *str, struct mips_cl_insn *ip)
8115 struct mips_opcode *insn;
8118 unsigned int lastregno = 0;
8119 unsigned int lastpos = 0;
8120 unsigned int limlo, limhi;
8126 /* If the instruction contains a '.', we first try to match an instruction
8127 including the '.'. Then we try again without the '.'. */
8129 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
8132 /* If we stopped on whitespace, then replace the whitespace with null for
8133 the call to hash_find. Save the character we replaced just in case we
8134 have to re-parse the instruction. */
8141 insn = (struct mips_opcode *) hash_find (op_hash, str);
8143 /* If we didn't find the instruction in the opcode table, try again, but
8144 this time with just the instruction up to, but not including the
8148 /* Restore the character we overwrite above (if any). */
8152 /* Scan up to the first '.' or whitespace. */
8154 *s != '\0' && *s != '.' && !ISSPACE (*s);
8158 /* If we did not find a '.', then we can quit now. */
8161 insn_error = "unrecognized opcode";
8165 /* Lookup the instruction in the hash table. */
8167 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
8169 insn_error = "unrecognized opcode";
8179 assert (strcmp (insn->name, str) == 0);
8181 if (OPCODE_IS_MEMBER (insn,
8183 | (file_ase_mips16 ? INSN_MIPS16 : 0)
8184 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
8185 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
8191 if (insn->pinfo != INSN_MACRO)
8193 if (mips_opts.arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
8199 if (insn + 1 < &mips_opcodes[NUMOPCODES]
8200 && strcmp (insn->name, insn[1].name) == 0)
8209 static char buf[100];
8211 _("opcode not supported on this processor: %s (%s)"),
8212 mips_cpu_info_from_arch (mips_opts.arch)->name,
8213 mips_cpu_info_from_isa (mips_opts.isa)->name);
8223 ip->insn_opcode = insn->match;
8225 for (args = insn->args;; ++args)
8229 s += strspn (s, " \t");
8233 case '\0': /* end of args */
8246 ip->insn_opcode |= lastregno << OP_SH_RS;
8250 ip->insn_opcode |= lastregno << OP_SH_RT;
8254 ip->insn_opcode |= lastregno << OP_SH_FT;
8258 ip->insn_opcode |= lastregno << OP_SH_FS;
8264 /* Handle optional base register.
8265 Either the base register is omitted or
8266 we must have a left paren. */
8267 /* This is dependent on the next operand specifier
8268 is a base register specification. */
8269 assert (args[1] == 'b' || args[1] == '5'
8270 || args[1] == '-' || args[1] == '4');
8274 case ')': /* these must match exactly */
8281 case '+': /* Opcode extension character. */
8284 case 'A': /* ins/ext position, becomes LSB. */
8287 my_getExpression (&imm_expr, s);
8288 check_absolute_expr (ip, &imm_expr);
8289 if ((unsigned long) imm_expr.X_add_number < limlo
8290 || (unsigned long) imm_expr.X_add_number > limhi)
8292 as_bad (_("Improper position (%lu)"),
8293 (unsigned long) imm_expr.X_add_number);
8294 imm_expr.X_add_number = limlo;
8296 lastpos = imm_expr.X_add_number;
8297 ip->insn_opcode |= (imm_expr.X_add_number
8298 & OP_MASK_SHAMT) << OP_SH_SHAMT;
8299 imm_expr.X_op = O_absent;
8303 case 'B': /* ins size, becomes MSB. */
8306 my_getExpression (&imm_expr, s);
8307 check_absolute_expr (ip, &imm_expr);
8308 /* Check for negative input so that small negative numbers
8309 will not succeed incorrectly. The checks against
8310 (pos+size) transitively check "size" itself,
8311 assuming that "pos" is reasonable. */
8312 if ((long) imm_expr.X_add_number < 0
8313 || ((unsigned long) imm_expr.X_add_number
8315 || ((unsigned long) imm_expr.X_add_number
8318 as_bad (_("Improper insert size (%lu, position %lu)"),
8319 (unsigned long) imm_expr.X_add_number,
8320 (unsigned long) lastpos);
8321 imm_expr.X_add_number = limlo - lastpos;
8323 ip->insn_opcode |= ((lastpos + imm_expr.X_add_number - 1)
8324 & OP_MASK_INSMSB) << OP_SH_INSMSB;
8325 imm_expr.X_op = O_absent;
8329 case 'C': /* ext size, becomes MSBD. */
8332 my_getExpression (&imm_expr, s);
8333 check_absolute_expr (ip, &imm_expr);
8334 /* Check for negative input so that small negative numbers
8335 will not succeed incorrectly. The checks against
8336 (pos+size) transitively check "size" itself,
8337 assuming that "pos" is reasonable. */
8338 if ((long) imm_expr.X_add_number < 0
8339 || ((unsigned long) imm_expr.X_add_number
8341 || ((unsigned long) imm_expr.X_add_number
8344 as_bad (_("Improper extract size (%lu, position %lu)"),
8345 (unsigned long) imm_expr.X_add_number,
8346 (unsigned long) lastpos);
8347 imm_expr.X_add_number = limlo - lastpos;
8349 ip->insn_opcode |= ((imm_expr.X_add_number - 1)
8350 & OP_MASK_EXTMSBD) << OP_SH_EXTMSBD;
8351 imm_expr.X_op = O_absent;
8356 /* +D is for disassembly only; never match. */
8360 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8361 *args, insn->name, insn->args);
8362 /* Further processing is fruitless. */
8367 case '<': /* must be at least one digit */
8369 * According to the manual, if the shift amount is greater
8370 * than 31 or less than 0, then the shift amount should be
8371 * mod 32. In reality the mips assembler issues an error.
8372 * We issue a warning and mask out all but the low 5 bits.
8374 my_getExpression (&imm_expr, s);
8375 check_absolute_expr (ip, &imm_expr);
8376 if ((unsigned long) imm_expr.X_add_number > 31)
8378 as_warn (_("Improper shift amount (%lu)"),
8379 (unsigned long) imm_expr.X_add_number);
8380 imm_expr.X_add_number &= OP_MASK_SHAMT;
8382 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
8383 imm_expr.X_op = O_absent;
8387 case '>': /* shift amount minus 32 */
8388 my_getExpression (&imm_expr, s);
8389 check_absolute_expr (ip, &imm_expr);
8390 if ((unsigned long) imm_expr.X_add_number < 32
8391 || (unsigned long) imm_expr.X_add_number > 63)
8393 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
8394 imm_expr.X_op = O_absent;
8398 case 'k': /* cache code */
8399 case 'h': /* prefx code */
8400 my_getExpression (&imm_expr, s);
8401 check_absolute_expr (ip, &imm_expr);
8402 if ((unsigned long) imm_expr.X_add_number > 31)
8404 as_warn (_("Invalid value for `%s' (%lu)"),
8406 (unsigned long) imm_expr.X_add_number);
8407 imm_expr.X_add_number &= 0x1f;
8410 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
8412 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
8413 imm_expr.X_op = O_absent;
8417 case 'c': /* break code */
8418 my_getExpression (&imm_expr, s);
8419 check_absolute_expr (ip, &imm_expr);
8420 if ((unsigned long) imm_expr.X_add_number > 1023)
8422 as_warn (_("Illegal break code (%lu)"),
8423 (unsigned long) imm_expr.X_add_number);
8424 imm_expr.X_add_number &= OP_MASK_CODE;
8426 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
8427 imm_expr.X_op = O_absent;
8431 case 'q': /* lower break code */
8432 my_getExpression (&imm_expr, s);
8433 check_absolute_expr (ip, &imm_expr);
8434 if ((unsigned long) imm_expr.X_add_number > 1023)
8436 as_warn (_("Illegal lower break code (%lu)"),
8437 (unsigned long) imm_expr.X_add_number);
8438 imm_expr.X_add_number &= OP_MASK_CODE2;
8440 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
8441 imm_expr.X_op = O_absent;
8445 case 'B': /* 20-bit syscall/break code. */
8446 my_getExpression (&imm_expr, s);
8447 check_absolute_expr (ip, &imm_expr);
8448 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
8449 as_warn (_("Illegal 20-bit code (%lu)"),
8450 (unsigned long) imm_expr.X_add_number);
8451 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
8452 imm_expr.X_op = O_absent;
8456 case 'C': /* Coprocessor code */
8457 my_getExpression (&imm_expr, s);
8458 check_absolute_expr (ip, &imm_expr);
8459 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
8461 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8462 (unsigned long) imm_expr.X_add_number);
8463 imm_expr.X_add_number &= ((1 << 25) - 1);
8465 ip->insn_opcode |= imm_expr.X_add_number;
8466 imm_expr.X_op = O_absent;
8470 case 'J': /* 19-bit wait code. */
8471 my_getExpression (&imm_expr, s);
8472 check_absolute_expr (ip, &imm_expr);
8473 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
8474 as_warn (_("Illegal 19-bit code (%lu)"),
8475 (unsigned long) imm_expr.X_add_number);
8476 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
8477 imm_expr.X_op = O_absent;
8481 case 'P': /* Performance register */
8482 my_getExpression (&imm_expr, s);
8483 check_absolute_expr (ip, &imm_expr);
8484 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
8486 as_warn (_("Invalid performance register (%lu)"),
8487 (unsigned long) imm_expr.X_add_number);
8488 imm_expr.X_add_number &= OP_MASK_PERFREG;
8490 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
8491 imm_expr.X_op = O_absent;
8495 case 'b': /* base register */
8496 case 'd': /* destination register */
8497 case 's': /* source register */
8498 case 't': /* target register */
8499 case 'r': /* both target and source */
8500 case 'v': /* both dest and source */
8501 case 'w': /* both dest and target */
8502 case 'E': /* coprocessor target register */
8503 case 'G': /* coprocessor destination register */
8504 case 'K': /* 'rdhwr' destination register */
8505 case 'x': /* ignore register name */
8506 case 'z': /* must be zero register */
8507 case 'U': /* destination register (clo/clz). */
8522 while (ISDIGIT (*s));
8524 as_bad (_("Invalid register number (%d)"), regno);
8526 else if (*args == 'E' || *args == 'G' || *args == 'K')
8530 if (s[1] == 'r' && s[2] == 'a')
8535 else if (s[1] == 'f' && s[2] == 'p')
8540 else if (s[1] == 's' && s[2] == 'p')
8545 else if (s[1] == 'g' && s[2] == 'p')
8550 else if (s[1] == 'a' && s[2] == 't')
8555 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8560 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8565 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8570 else if (itbl_have_entries)
8575 p = s + 1; /* advance past '$' */
8576 n = itbl_get_field (&p); /* n is name */
8578 /* See if this is a register defined in an
8580 if (itbl_get_reg_val (n, &r))
8582 /* Get_field advances to the start of
8583 the next field, so we need to back
8584 rack to the end of the last field. */
8588 s = strchr (s, '\0');
8602 as_warn (_("Used $at without \".set noat\""));
8608 if (c == 'r' || c == 'v' || c == 'w')
8615 /* 'z' only matches $0. */
8616 if (c == 'z' && regno != 0)
8619 /* Now that we have assembled one operand, we use the args string
8620 * to figure out where it goes in the instruction. */
8627 ip->insn_opcode |= regno << OP_SH_RS;
8632 ip->insn_opcode |= regno << OP_SH_RD;
8635 ip->insn_opcode |= regno << OP_SH_RD;
8636 ip->insn_opcode |= regno << OP_SH_RT;
8641 ip->insn_opcode |= regno << OP_SH_RT;
8644 /* This case exists because on the r3000 trunc
8645 expands into a macro which requires a gp
8646 register. On the r6000 or r4000 it is
8647 assembled into a single instruction which
8648 ignores the register. Thus the insn version
8649 is MIPS_ISA2 and uses 'x', and the macro
8650 version is MIPS_ISA1 and uses 't'. */
8653 /* This case is for the div instruction, which
8654 acts differently if the destination argument
8655 is $0. This only matches $0, and is checked
8656 outside the switch. */
8659 /* Itbl operand; not yet implemented. FIXME ?? */
8661 /* What about all other operands like 'i', which
8662 can be specified in the opcode table? */
8672 ip->insn_opcode |= lastregno << OP_SH_RS;
8675 ip->insn_opcode |= lastregno << OP_SH_RT;
8680 case 'O': /* MDMX alignment immediate constant. */
8681 my_getExpression (&imm_expr, s);
8682 check_absolute_expr (ip, &imm_expr);
8683 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
8685 as_warn ("Improper align amount (%ld), using low bits",
8686 (long) imm_expr.X_add_number);
8687 imm_expr.X_add_number &= OP_MASK_ALN;
8689 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_ALN;
8690 imm_expr.X_op = O_absent;
8694 case 'Q': /* MDMX vector, element sel, or const. */
8697 /* MDMX Immediate. */
8698 my_getExpression (&imm_expr, s);
8699 check_absolute_expr (ip, &imm_expr);
8700 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
8702 as_warn (_("Invalid MDMX Immediate (%ld)"),
8703 (long) imm_expr.X_add_number);
8704 imm_expr.X_add_number &= OP_MASK_FT;
8706 imm_expr.X_add_number &= OP_MASK_FT;
8707 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8708 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
8710 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
8711 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_FT;
8712 imm_expr.X_op = O_absent;
8716 /* Not MDMX Immediate. Fall through. */
8717 case 'X': /* MDMX destination register. */
8718 case 'Y': /* MDMX source register. */
8719 case 'Z': /* MDMX target register. */
8721 case 'D': /* floating point destination register */
8722 case 'S': /* floating point source register */
8723 case 'T': /* floating point target register */
8724 case 'R': /* floating point source register */
8728 /* Accept $fN for FP and MDMX register numbers, and in
8729 addition accept $vN for MDMX register numbers. */
8730 if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2]))
8731 || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v'
8742 while (ISDIGIT (*s));
8745 as_bad (_("Invalid float register number (%d)"), regno);
8747 if ((regno & 1) != 0
8749 && ! (strcmp (str, "mtc1") == 0
8750 || strcmp (str, "mfc1") == 0
8751 || strcmp (str, "lwc1") == 0
8752 || strcmp (str, "swc1") == 0
8753 || strcmp (str, "l.s") == 0
8754 || strcmp (str, "s.s") == 0))
8755 as_warn (_("Float register should be even, was %d"),
8763 if (c == 'V' || c == 'W')
8774 ip->insn_opcode |= regno << OP_SH_FD;
8779 ip->insn_opcode |= regno << OP_SH_FS;
8782 /* This is like 'Z', but also needs to fix the MDMX
8783 vector/scalar select bits. Note that the
8784 scalar immediate case is handled above. */
8787 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
8788 int max_el = (is_qh ? 3 : 7);
8790 my_getExpression(&imm_expr, s);
8791 check_absolute_expr (ip, &imm_expr);
8793 if (imm_expr.X_add_number > max_el)
8794 as_bad(_("Bad element selector %ld"),
8795 (long) imm_expr.X_add_number);
8796 imm_expr.X_add_number &= max_el;
8797 ip->insn_opcode |= (imm_expr.X_add_number
8801 as_warn(_("Expecting ']' found '%s'"), s);
8807 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8808 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
8811 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
8818 ip->insn_opcode |= regno << OP_SH_FT;
8821 ip->insn_opcode |= regno << OP_SH_FR;
8831 ip->insn_opcode |= lastregno << OP_SH_FS;
8834 ip->insn_opcode |= lastregno << OP_SH_FT;
8840 my_getExpression (&imm_expr, s);
8841 if (imm_expr.X_op != O_big
8842 && imm_expr.X_op != O_constant)
8843 insn_error = _("absolute expression required");
8848 my_getExpression (&offset_expr, s);
8849 *imm_reloc = BFD_RELOC_32;
8862 unsigned char temp[8];
8864 unsigned int length;
8869 /* These only appear as the last operand in an
8870 instruction, and every instruction that accepts
8871 them in any variant accepts them in all variants.
8872 This means we don't have to worry about backing out
8873 any changes if the instruction does not match.
8875 The difference between them is the size of the
8876 floating point constant and where it goes. For 'F'
8877 and 'L' the constant is 64 bits; for 'f' and 'l' it
8878 is 32 bits. Where the constant is placed is based
8879 on how the MIPS assembler does things:
8882 f -- immediate value
8885 The .lit4 and .lit8 sections are only used if
8886 permitted by the -G argument.
8888 When generating embedded PIC code, we use the
8889 .lit8 section but not the .lit4 section (we can do
8890 .lit4 inline easily; we need to put .lit8
8891 somewhere in the data segment, and using .lit8
8892 permits the linker to eventually combine identical
8895 The code below needs to know whether the target register
8896 is 32 or 64 bits wide. It relies on the fact 'f' and
8897 'F' are used with GPR-based instructions and 'l' and
8898 'L' are used with FPR-based instructions. */
8900 f64 = *args == 'F' || *args == 'L';
8901 using_gprs = *args == 'F' || *args == 'f';
8903 save_in = input_line_pointer;
8904 input_line_pointer = s;
8905 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8907 s = input_line_pointer;
8908 input_line_pointer = save_in;
8909 if (err != NULL && *err != '\0')
8911 as_bad (_("Bad floating point constant: %s"), err);
8912 memset (temp, '\0', sizeof temp);
8913 length = f64 ? 8 : 4;
8916 assert (length == (unsigned) (f64 ? 8 : 4));
8920 && (! USE_GLOBAL_POINTER_OPT
8921 || mips_pic == EMBEDDED_PIC
8922 || g_switch_value < 4
8923 || (temp[0] == 0 && temp[1] == 0)
8924 || (temp[2] == 0 && temp[3] == 0))))
8926 imm_expr.X_op = O_constant;
8927 if (! target_big_endian)
8928 imm_expr.X_add_number = bfd_getl32 (temp);
8930 imm_expr.X_add_number = bfd_getb32 (temp);
8933 && ! mips_disable_float_construction
8934 /* Constants can only be constructed in GPRs and
8935 copied to FPRs if the GPRs are at least as wide
8936 as the FPRs. Force the constant into memory if
8937 we are using 64-bit FPRs but the GPRs are only
8940 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8941 && ((temp[0] == 0 && temp[1] == 0)
8942 || (temp[2] == 0 && temp[3] == 0))
8943 && ((temp[4] == 0 && temp[5] == 0)
8944 || (temp[6] == 0 && temp[7] == 0)))
8946 /* The value is simple enough to load with a couple of
8947 instructions. If using 32-bit registers, set
8948 imm_expr to the high order 32 bits and offset_expr to
8949 the low order 32 bits. Otherwise, set imm_expr to
8950 the entire 64 bit constant. */
8951 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8953 imm_expr.X_op = O_constant;
8954 offset_expr.X_op = O_constant;
8955 if (! target_big_endian)
8957 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8958 offset_expr.X_add_number = bfd_getl32 (temp);
8962 imm_expr.X_add_number = bfd_getb32 (temp);
8963 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8965 if (offset_expr.X_add_number == 0)
8966 offset_expr.X_op = O_absent;
8968 else if (sizeof (imm_expr.X_add_number) > 4)
8970 imm_expr.X_op = O_constant;
8971 if (! target_big_endian)
8972 imm_expr.X_add_number = bfd_getl64 (temp);
8974 imm_expr.X_add_number = bfd_getb64 (temp);
8978 imm_expr.X_op = O_big;
8979 imm_expr.X_add_number = 4;
8980 if (! target_big_endian)
8982 generic_bignum[0] = bfd_getl16 (temp);
8983 generic_bignum[1] = bfd_getl16 (temp + 2);
8984 generic_bignum[2] = bfd_getl16 (temp + 4);
8985 generic_bignum[3] = bfd_getl16 (temp + 6);
8989 generic_bignum[0] = bfd_getb16 (temp + 6);
8990 generic_bignum[1] = bfd_getb16 (temp + 4);
8991 generic_bignum[2] = bfd_getb16 (temp + 2);
8992 generic_bignum[3] = bfd_getb16 (temp);
8998 const char *newname;
9001 /* Switch to the right section. */
9003 subseg = now_subseg;
9006 default: /* unused default case avoids warnings. */
9008 newname = RDATA_SECTION_NAME;
9009 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
9010 || mips_pic == EMBEDDED_PIC)
9014 if (mips_pic == EMBEDDED_PIC)
9017 newname = RDATA_SECTION_NAME;
9020 assert (!USE_GLOBAL_POINTER_OPT
9021 || g_switch_value >= 4);
9025 new_seg = subseg_new (newname, (subsegT) 0);
9026 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
9027 bfd_set_section_flags (stdoutput, new_seg,
9032 frag_align (*args == 'l' ? 2 : 3, 0, 0);
9033 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9034 && strcmp (TARGET_OS, "elf") != 0)
9035 record_alignment (new_seg, 4);
9037 record_alignment (new_seg, *args == 'l' ? 2 : 3);
9039 as_bad (_("Can't use floating point insn in this section"));
9041 /* Set the argument to the current address in the
9043 offset_expr.X_op = O_symbol;
9044 offset_expr.X_add_symbol =
9045 symbol_new ("L0\001", now_seg,
9046 (valueT) frag_now_fix (), frag_now);
9047 offset_expr.X_add_number = 0;
9049 /* Put the floating point number into the section. */
9050 p = frag_more ((int) length);
9051 memcpy (p, temp, length);
9053 /* Switch back to the original section. */
9054 subseg_set (seg, subseg);
9059 case 'i': /* 16 bit unsigned immediate */
9060 case 'j': /* 16 bit signed immediate */
9061 *imm_reloc = BFD_RELOC_LO16;
9062 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
9065 offsetT minval, maxval;
9067 more = (insn + 1 < &mips_opcodes[NUMOPCODES]
9068 && strcmp (insn->name, insn[1].name) == 0);
9070 /* If the expression was written as an unsigned number,
9071 only treat it as signed if there are no more
9075 && sizeof (imm_expr.X_add_number) <= 4
9076 && imm_expr.X_op == O_constant
9077 && imm_expr.X_add_number < 0
9078 && imm_expr.X_unsigned
9082 /* For compatibility with older assemblers, we accept
9083 0x8000-0xffff as signed 16-bit numbers when only
9084 signed numbers are allowed. */
9086 minval = 0, maxval = 0xffff;
9088 minval = -0x8000, maxval = 0x7fff;
9090 minval = -0x8000, maxval = 0xffff;
9092 if (imm_expr.X_op != O_constant
9093 || imm_expr.X_add_number < minval
9094 || imm_expr.X_add_number > maxval)
9098 if (imm_expr.X_op == O_constant
9099 || imm_expr.X_op == O_big)
9100 as_bad (_("expression out of range"));
9106 case 'o': /* 16 bit offset */
9107 /* Check whether there is only a single bracketed expression
9108 left. If so, it must be the base register and the
9109 constant must be zero. */
9110 if (*s == '(' && strchr (s + 1, '(') == 0)
9112 offset_expr.X_op = O_constant;
9113 offset_expr.X_add_number = 0;
9117 /* If this value won't fit into a 16 bit offset, then go
9118 find a macro that will generate the 32 bit offset
9120 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
9121 && (offset_expr.X_op != O_constant
9122 || offset_expr.X_add_number >= 0x8000
9123 || offset_expr.X_add_number < -0x8000))
9129 case 'p': /* pc relative offset */
9130 *offset_reloc = BFD_RELOC_16_PCREL_S2;
9131 my_getExpression (&offset_expr, s);
9135 case 'u': /* upper 16 bits */
9136 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
9137 && imm_expr.X_op == O_constant
9138 && (imm_expr.X_add_number < 0
9139 || imm_expr.X_add_number >= 0x10000))
9140 as_bad (_("lui expression not in range 0..65535"));
9144 case 'a': /* 26 bit address */
9145 my_getExpression (&offset_expr, s);
9147 *offset_reloc = BFD_RELOC_MIPS_JMP;
9150 case 'N': /* 3 bit branch condition code */
9151 case 'M': /* 3 bit compare condition code */
9152 if (strncmp (s, "$fcc", 4) != 0)
9162 while (ISDIGIT (*s));
9164 as_bad (_("invalid condition code register $fcc%d"), regno);
9166 ip->insn_opcode |= regno << OP_SH_BCC;
9168 ip->insn_opcode |= regno << OP_SH_CCC;
9172 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
9183 while (ISDIGIT (*s));
9186 c = 8; /* Invalid sel value. */
9189 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9190 ip->insn_opcode |= c;
9194 /* Must be at least one digit. */
9195 my_getExpression (&imm_expr, s);
9196 check_absolute_expr (ip, &imm_expr);
9198 if ((unsigned long) imm_expr.X_add_number
9199 > (unsigned long) OP_MASK_VECBYTE)
9201 as_bad (_("bad byte vector index (%ld)"),
9202 (long) imm_expr.X_add_number);
9203 imm_expr.X_add_number = 0;
9206 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECBYTE;
9207 imm_expr.X_op = O_absent;
9212 my_getExpression (&imm_expr, s);
9213 check_absolute_expr (ip, &imm_expr);
9215 if ((unsigned long) imm_expr.X_add_number
9216 > (unsigned long) OP_MASK_VECALIGN)
9218 as_bad (_("bad byte vector index (%ld)"),
9219 (long) imm_expr.X_add_number);
9220 imm_expr.X_add_number = 0;
9223 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECALIGN;
9224 imm_expr.X_op = O_absent;
9229 as_bad (_("bad char = '%c'\n"), *args);
9234 /* Args don't match. */
9235 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
9236 !strcmp (insn->name, insn[1].name))
9240 insn_error = _("illegal operands");
9245 insn_error = _("illegal operands");
9250 /* This routine assembles an instruction into its binary format when
9251 assembling for the mips16. As a side effect, it sets one of the
9252 global variables imm_reloc or offset_reloc to the type of
9253 relocation to do if one of the operands is an address expression.
9254 It also sets mips16_small and mips16_ext if the user explicitly
9255 requested a small or extended instruction. */
9258 mips16_ip (char *str, struct mips_cl_insn *ip)
9262 struct mips_opcode *insn;
9265 unsigned int lastregno = 0;
9270 mips16_small = FALSE;
9273 for (s = str; ISLOWER (*s); ++s)
9285 if (s[1] == 't' && s[2] == ' ')
9288 mips16_small = TRUE;
9292 else if (s[1] == 'e' && s[2] == ' ')
9301 insn_error = _("unknown opcode");
9305 if (mips_opts.noautoextend && ! mips16_ext)
9306 mips16_small = TRUE;
9308 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
9310 insn_error = _("unrecognized opcode");
9317 assert (strcmp (insn->name, str) == 0);
9320 ip->insn_opcode = insn->match;
9321 ip->use_extend = FALSE;
9322 imm_expr.X_op = O_absent;
9323 imm_reloc[0] = BFD_RELOC_UNUSED;
9324 imm_reloc[1] = BFD_RELOC_UNUSED;
9325 imm_reloc[2] = BFD_RELOC_UNUSED;
9326 offset_expr.X_op = O_absent;
9327 offset_reloc[0] = BFD_RELOC_UNUSED;
9328 offset_reloc[1] = BFD_RELOC_UNUSED;
9329 offset_reloc[2] = BFD_RELOC_UNUSED;
9330 for (args = insn->args; 1; ++args)
9337 /* In this switch statement we call break if we did not find
9338 a match, continue if we did find a match, or return if we
9347 /* Stuff the immediate value in now, if we can. */
9348 if (imm_expr.X_op == O_constant
9349 && *imm_reloc > BFD_RELOC_UNUSED
9350 && insn->pinfo != INSN_MACRO)
9352 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
9353 imm_expr.X_add_number, TRUE, mips16_small,
9354 mips16_ext, &ip->insn_opcode,
9355 &ip->use_extend, &ip->extend);
9356 imm_expr.X_op = O_absent;
9357 *imm_reloc = BFD_RELOC_UNUSED;
9371 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9374 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9390 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9392 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9419 while (ISDIGIT (*s));
9422 as_bad (_("invalid register number (%d)"), regno);
9428 if (s[1] == 'r' && s[2] == 'a')
9433 else if (s[1] == 'f' && s[2] == 'p')
9438 else if (s[1] == 's' && s[2] == 'p')
9443 else if (s[1] == 'g' && s[2] == 'p')
9448 else if (s[1] == 'a' && s[2] == 't')
9453 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
9458 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
9463 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
9476 if (c == 'v' || c == 'w')
9478 regno = mips16_to_32_reg_map[lastregno];
9492 regno = mips32_to_16_reg_map[regno];
9497 regno = ILLEGAL_REG;
9502 regno = ILLEGAL_REG;
9507 regno = ILLEGAL_REG;
9512 if (regno == AT && ! mips_opts.noat)
9513 as_warn (_("used $at without \".set noat\""));
9520 if (regno == ILLEGAL_REG)
9527 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
9531 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
9534 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
9537 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
9543 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
9546 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9547 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
9557 if (strncmp (s, "$pc", 3) == 0)
9581 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
9583 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9584 and generate the appropriate reloc. If the text
9585 inside %gprel is not a symbol name with an
9586 optional offset, then we generate a normal reloc
9587 and will probably fail later. */
9588 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
9589 if (imm_expr.X_op == O_symbol)
9592 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
9594 ip->use_extend = TRUE;
9601 /* Just pick up a normal expression. */
9602 my_getExpression (&imm_expr, s);
9605 if (imm_expr.X_op == O_register)
9607 /* What we thought was an expression turned out to
9610 if (s[0] == '(' && args[1] == '(')
9612 /* It looks like the expression was omitted
9613 before a register indirection, which means
9614 that the expression is implicitly zero. We
9615 still set up imm_expr, so that we handle
9616 explicit extensions correctly. */
9617 imm_expr.X_op = O_constant;
9618 imm_expr.X_add_number = 0;
9619 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9626 /* We need to relax this instruction. */
9627 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9636 /* We use offset_reloc rather than imm_reloc for the PC
9637 relative operands. This lets macros with both
9638 immediate and address operands work correctly. */
9639 my_getExpression (&offset_expr, s);
9641 if (offset_expr.X_op == O_register)
9644 /* We need to relax this instruction. */
9645 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9649 case '6': /* break code */
9650 my_getExpression (&imm_expr, s);
9651 check_absolute_expr (ip, &imm_expr);
9652 if ((unsigned long) imm_expr.X_add_number > 63)
9654 as_warn (_("Invalid value for `%s' (%lu)"),
9656 (unsigned long) imm_expr.X_add_number);
9657 imm_expr.X_add_number &= 0x3f;
9659 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9660 imm_expr.X_op = O_absent;
9664 case 'a': /* 26 bit address */
9665 my_getExpression (&offset_expr, s);
9667 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9668 ip->insn_opcode <<= 16;
9671 case 'l': /* register list for entry macro */
9672 case 'L': /* register list for exit macro */
9682 int freg, reg1, reg2;
9684 while (*s == ' ' || *s == ',')
9688 as_bad (_("can't parse register list"));
9700 while (ISDIGIT (*s))
9722 as_bad (_("invalid register list"));
9727 while (ISDIGIT (*s))
9734 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9739 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9744 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9745 mask |= (reg2 - 3) << 3;
9746 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9747 mask |= (reg2 - 15) << 1;
9748 else if (reg1 == RA && reg2 == RA)
9752 as_bad (_("invalid register list"));
9756 /* The mask is filled in in the opcode table for the
9757 benefit of the disassembler. We remove it before
9758 applying the actual mask. */
9759 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9760 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9764 case 'e': /* extend code */
9765 my_getExpression (&imm_expr, s);
9766 check_absolute_expr (ip, &imm_expr);
9767 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9769 as_warn (_("Invalid value for `%s' (%lu)"),
9771 (unsigned long) imm_expr.X_add_number);
9772 imm_expr.X_add_number &= 0x7ff;
9774 ip->insn_opcode |= imm_expr.X_add_number;
9775 imm_expr.X_op = O_absent;
9785 /* Args don't match. */
9786 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9787 strcmp (insn->name, insn[1].name) == 0)
9794 insn_error = _("illegal operands");
9800 /* This structure holds information we know about a mips16 immediate
9803 struct mips16_immed_operand
9805 /* The type code used in the argument string in the opcode table. */
9807 /* The number of bits in the short form of the opcode. */
9809 /* The number of bits in the extended form of the opcode. */
9811 /* The amount by which the short form is shifted when it is used;
9812 for example, the sw instruction has a shift count of 2. */
9814 /* The amount by which the short form is shifted when it is stored
9815 into the instruction code. */
9817 /* Non-zero if the short form is unsigned. */
9819 /* Non-zero if the extended form is unsigned. */
9821 /* Non-zero if the value is PC relative. */
9825 /* The mips16 immediate operand types. */
9827 static const struct mips16_immed_operand mips16_immed_operands[] =
9829 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9830 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9831 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9832 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9833 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9834 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9835 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9836 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9837 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9838 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9839 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9840 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9841 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9842 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9843 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9844 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9845 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9846 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9847 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9848 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9849 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9852 #define MIPS16_NUM_IMMED \
9853 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9855 /* Handle a mips16 instruction with an immediate value. This or's the
9856 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9857 whether an extended value is needed; if one is needed, it sets
9858 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9859 If SMALL is true, an unextended opcode was explicitly requested.
9860 If EXT is true, an extended opcode was explicitly requested. If
9861 WARN is true, warn if EXT does not match reality. */
9864 mips16_immed (char *file, unsigned int line, int type, offsetT val,
9865 bfd_boolean warn, bfd_boolean small, bfd_boolean ext,
9866 unsigned long *insn, bfd_boolean *use_extend,
9867 unsigned short *extend)
9869 register const struct mips16_immed_operand *op;
9870 int mintiny, maxtiny;
9871 bfd_boolean needext;
9873 op = mips16_immed_operands;
9874 while (op->type != type)
9877 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9882 if (type == '<' || type == '>' || type == '[' || type == ']')
9885 maxtiny = 1 << op->nbits;
9890 maxtiny = (1 << op->nbits) - 1;
9895 mintiny = - (1 << (op->nbits - 1));
9896 maxtiny = (1 << (op->nbits - 1)) - 1;
9899 /* Branch offsets have an implicit 0 in the lowest bit. */
9900 if (type == 'p' || type == 'q')
9903 if ((val & ((1 << op->shift) - 1)) != 0
9904 || val < (mintiny << op->shift)
9905 || val > (maxtiny << op->shift))
9910 if (warn && ext && ! needext)
9911 as_warn_where (file, line,
9912 _("extended operand requested but not required"));
9913 if (small && needext)
9914 as_bad_where (file, line, _("invalid unextended operand value"));
9916 if (small || (! ext && ! needext))
9920 *use_extend = FALSE;
9921 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9922 insnval <<= op->op_shift;
9927 long minext, maxext;
9933 maxext = (1 << op->extbits) - 1;
9937 minext = - (1 << (op->extbits - 1));
9938 maxext = (1 << (op->extbits - 1)) - 1;
9940 if (val < minext || val > maxext)
9941 as_bad_where (file, line,
9942 _("operand value out of range for instruction"));
9945 if (op->extbits == 16)
9947 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
9950 else if (op->extbits == 15)
9952 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
9957 extval = ((val & 0x1f) << 6) | (val & 0x20);
9961 *extend = (unsigned short) extval;
9966 static const struct percent_op_match
9969 bfd_reloc_code_real_type reloc;
9972 {"%lo", BFD_RELOC_LO16},
9974 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
9975 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
9976 {"%call16", BFD_RELOC_MIPS_CALL16},
9977 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
9978 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
9979 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
9980 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
9981 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
9982 {"%got", BFD_RELOC_MIPS_GOT16},
9983 {"%gp_rel", BFD_RELOC_GPREL16},
9984 {"%half", BFD_RELOC_16},
9985 {"%highest", BFD_RELOC_MIPS_HIGHEST},
9986 {"%higher", BFD_RELOC_MIPS_HIGHER},
9987 {"%neg", BFD_RELOC_MIPS_SUB},
9989 {"%hi", BFD_RELOC_HI16_S}
9993 /* Return true if *STR points to a relocation operator. When returning true,
9994 move *STR over the operator and store its relocation code in *RELOC.
9995 Leave both *STR and *RELOC alone when returning false. */
9998 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
10002 for (i = 0; i < ARRAY_SIZE (percent_op); i++)
10003 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
10005 *str += strlen (percent_op[i].str);
10006 *reloc = percent_op[i].reloc;
10008 /* Check whether the output BFD supports this relocation.
10009 If not, issue an error and fall back on something safe. */
10010 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
10012 as_bad ("relocation %s isn't supported by the current ABI",
10013 percent_op[i].str);
10014 *reloc = BFD_RELOC_LO16;
10022 /* Parse string STR as a 16-bit relocatable operand. Store the
10023 expression in *EP and the relocations in the array starting
10024 at RELOC. Return the number of relocation operators used.
10026 On exit, EXPR_END points to the first character after the expression.
10027 If no relocation operators are used, RELOC[0] is set to BFD_RELOC_LO16. */
10030 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
10033 bfd_reloc_code_real_type reversed_reloc[3];
10034 size_t reloc_index, i;
10035 int crux_depth, str_depth;
10038 /* Search for the start of the main expression, recoding relocations
10039 in REVERSED_RELOC. End the loop with CRUX pointing to the start
10040 of the main expression and with CRUX_DEPTH containing the number
10041 of open brackets at that point. */
10048 crux_depth = str_depth;
10050 /* Skip over whitespace and brackets, keeping count of the number
10052 while (*str == ' ' || *str == '\t' || *str == '(')
10057 && reloc_index < (HAVE_NEWABI ? 3 : 1)
10058 && parse_relocation (&str, &reversed_reloc[reloc_index]));
10060 my_getExpression (ep, crux);
10063 /* Match every open bracket. */
10064 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
10068 if (crux_depth > 0)
10069 as_bad ("unclosed '('");
10073 if (reloc_index == 0)
10074 reloc[0] = BFD_RELOC_LO16;
10077 prev_reloc_op_frag = frag_now;
10078 for (i = 0; i < reloc_index; i++)
10079 reloc[i] = reversed_reloc[reloc_index - 1 - i];
10082 return reloc_index;
10086 my_getExpression (expressionS *ep, char *str)
10091 save_in = input_line_pointer;
10092 input_line_pointer = str;
10094 expr_end = input_line_pointer;
10095 input_line_pointer = save_in;
10097 /* If we are in mips16 mode, and this is an expression based on `.',
10098 then we bump the value of the symbol by 1 since that is how other
10099 text symbols are handled. We don't bother to handle complex
10100 expressions, just `.' plus or minus a constant. */
10101 if (mips_opts.mips16
10102 && ep->X_op == O_symbol
10103 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
10104 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
10105 && symbol_get_frag (ep->X_add_symbol) == frag_now
10106 && symbol_constant_p (ep->X_add_symbol)
10107 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
10108 S_SET_VALUE (ep->X_add_symbol, val + 1);
10111 /* Turn a string in input_line_pointer into a floating point constant
10112 of type TYPE, and store the appropriate bytes in *LITP. The number
10113 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10114 returned, or NULL on OK. */
10117 md_atof (int type, char *litP, int *sizeP)
10120 LITTLENUM_TYPE words[4];
10136 return _("bad call to md_atof");
10139 t = atof_ieee (input_line_pointer, type, words);
10141 input_line_pointer = t;
10145 if (! target_big_endian)
10147 for (i = prec - 1; i >= 0; i--)
10149 md_number_to_chars (litP, words[i], 2);
10155 for (i = 0; i < prec; i++)
10157 md_number_to_chars (litP, words[i], 2);
10166 md_number_to_chars (char *buf, valueT val, int n)
10168 if (target_big_endian)
10169 number_to_chars_bigendian (buf, val, n);
10171 number_to_chars_littleendian (buf, val, n);
10175 static int support_64bit_objects(void)
10177 const char **list, **l;
10180 list = bfd_target_list ();
10181 for (l = list; *l != NULL; l++)
10183 /* This is traditional mips */
10184 if (strcmp (*l, "elf64-tradbigmips") == 0
10185 || strcmp (*l, "elf64-tradlittlemips") == 0)
10187 if (strcmp (*l, "elf64-bigmips") == 0
10188 || strcmp (*l, "elf64-littlemips") == 0)
10191 yes = (*l != NULL);
10195 #endif /* OBJ_ELF */
10197 const char *md_shortopts = "nO::g::G:";
10199 struct option md_longopts[] =
10201 /* Options which specify architecture. */
10202 #define OPTION_ARCH_BASE (OPTION_MD_BASE)
10203 #define OPTION_MARCH (OPTION_ARCH_BASE + 0)
10204 {"march", required_argument, NULL, OPTION_MARCH},
10205 #define OPTION_MTUNE (OPTION_ARCH_BASE + 1)
10206 {"mtune", required_argument, NULL, OPTION_MTUNE},
10207 #define OPTION_MIPS1 (OPTION_ARCH_BASE + 2)
10208 {"mips0", no_argument, NULL, OPTION_MIPS1},
10209 {"mips1", no_argument, NULL, OPTION_MIPS1},
10210 #define OPTION_MIPS2 (OPTION_ARCH_BASE + 3)
10211 {"mips2", no_argument, NULL, OPTION_MIPS2},
10212 #define OPTION_MIPS3 (OPTION_ARCH_BASE + 4)
10213 {"mips3", no_argument, NULL, OPTION_MIPS3},
10214 #define OPTION_MIPS4 (OPTION_ARCH_BASE + 5)
10215 {"mips4", no_argument, NULL, OPTION_MIPS4},
10216 #define OPTION_MIPS5 (OPTION_ARCH_BASE + 6)
10217 {"mips5", no_argument, NULL, OPTION_MIPS5},
10218 #define OPTION_MIPS32 (OPTION_ARCH_BASE + 7)
10219 {"mips32", no_argument, NULL, OPTION_MIPS32},
10220 #define OPTION_MIPS64 (OPTION_ARCH_BASE + 8)
10221 {"mips64", no_argument, NULL, OPTION_MIPS64},
10222 #define OPTION_MIPS32R2 (OPTION_ARCH_BASE + 9)
10223 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
10225 /* Options which specify Application Specific Extensions (ASEs). */
10226 #define OPTION_ASE_BASE (OPTION_ARCH_BASE + 10)
10227 #define OPTION_MIPS16 (OPTION_ASE_BASE + 0)
10228 {"mips16", no_argument, NULL, OPTION_MIPS16},
10229 #define OPTION_NO_MIPS16 (OPTION_ASE_BASE + 1)
10230 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
10231 #define OPTION_MIPS3D (OPTION_ASE_BASE + 2)
10232 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
10233 #define OPTION_NO_MIPS3D (OPTION_ASE_BASE + 3)
10234 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
10235 #define OPTION_MDMX (OPTION_ASE_BASE + 4)
10236 {"mdmx", no_argument, NULL, OPTION_MDMX},
10237 #define OPTION_NO_MDMX (OPTION_ASE_BASE + 5)
10238 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
10240 /* Old-style architecture options. Don't add more of these. */
10241 #define OPTION_COMPAT_ARCH_BASE (OPTION_ASE_BASE + 6)
10242 #define OPTION_M4650 (OPTION_COMPAT_ARCH_BASE + 0)
10243 {"m4650", no_argument, NULL, OPTION_M4650},
10244 #define OPTION_NO_M4650 (OPTION_COMPAT_ARCH_BASE + 1)
10245 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
10246 #define OPTION_M4010 (OPTION_COMPAT_ARCH_BASE + 2)
10247 {"m4010", no_argument, NULL, OPTION_M4010},
10248 #define OPTION_NO_M4010 (OPTION_COMPAT_ARCH_BASE + 3)
10249 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
10250 #define OPTION_M4100 (OPTION_COMPAT_ARCH_BASE + 4)
10251 {"m4100", no_argument, NULL, OPTION_M4100},
10252 #define OPTION_NO_M4100 (OPTION_COMPAT_ARCH_BASE + 5)
10253 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
10254 #define OPTION_M3900 (OPTION_COMPAT_ARCH_BASE + 6)
10255 {"m3900", no_argument, NULL, OPTION_M3900},
10256 #define OPTION_NO_M3900 (OPTION_COMPAT_ARCH_BASE + 7)
10257 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
10259 /* Options which enable bug fixes. */
10260 #define OPTION_FIX_BASE (OPTION_COMPAT_ARCH_BASE + 8)
10261 #define OPTION_M7000_HILO_FIX (OPTION_FIX_BASE + 0)
10262 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
10263 #define OPTION_MNO_7000_HILO_FIX (OPTION_FIX_BASE + 1)
10264 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10265 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10266 #define OPTION_FIX_VR4122 (OPTION_FIX_BASE + 2)
10267 #define OPTION_NO_FIX_VR4122 (OPTION_FIX_BASE + 3)
10268 {"mfix-vr4122-bugs", no_argument, NULL, OPTION_FIX_VR4122},
10269 {"no-mfix-vr4122-bugs", no_argument, NULL, OPTION_NO_FIX_VR4122},
10271 /* Miscellaneous options. */
10272 #define OPTION_MISC_BASE (OPTION_FIX_BASE + 4)
10273 #define OPTION_MEMBEDDED_PIC (OPTION_MISC_BASE + 0)
10274 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
10275 #define OPTION_TRAP (OPTION_MISC_BASE + 1)
10276 {"trap", no_argument, NULL, OPTION_TRAP},
10277 {"no-break", no_argument, NULL, OPTION_TRAP},
10278 #define OPTION_BREAK (OPTION_MISC_BASE + 2)
10279 {"break", no_argument, NULL, OPTION_BREAK},
10280 {"no-trap", no_argument, NULL, OPTION_BREAK},
10281 #define OPTION_EB (OPTION_MISC_BASE + 3)
10282 {"EB", no_argument, NULL, OPTION_EB},
10283 #define OPTION_EL (OPTION_MISC_BASE + 4)
10284 {"EL", no_argument, NULL, OPTION_EL},
10285 #define OPTION_FP32 (OPTION_MISC_BASE + 5)
10286 {"mfp32", no_argument, NULL, OPTION_FP32},
10287 #define OPTION_GP32 (OPTION_MISC_BASE + 6)
10288 {"mgp32", no_argument, NULL, OPTION_GP32},
10289 #define OPTION_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 7)
10290 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
10291 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 8)
10292 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
10293 #define OPTION_FP64 (OPTION_MISC_BASE + 9)
10294 {"mfp64", no_argument, NULL, OPTION_FP64},
10295 #define OPTION_GP64 (OPTION_MISC_BASE + 10)
10296 {"mgp64", no_argument, NULL, OPTION_GP64},
10297 #define OPTION_RELAX_BRANCH (OPTION_MISC_BASE + 11)
10298 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 12)
10299 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
10300 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
10302 /* ELF-specific options. */
10304 #define OPTION_ELF_BASE (OPTION_MISC_BASE + 13)
10305 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10306 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
10307 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
10308 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10309 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
10310 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10311 {"xgot", no_argument, NULL, OPTION_XGOT},
10312 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10313 {"mabi", required_argument, NULL, OPTION_MABI},
10314 #define OPTION_32 (OPTION_ELF_BASE + 4)
10315 {"32", no_argument, NULL, OPTION_32},
10316 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10317 {"n32", no_argument, NULL, OPTION_N32},
10318 #define OPTION_64 (OPTION_ELF_BASE + 6)
10319 {"64", no_argument, NULL, OPTION_64},
10320 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10321 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
10322 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10323 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
10324 #endif /* OBJ_ELF */
10326 {NULL, no_argument, NULL, 0}
10328 size_t md_longopts_size = sizeof (md_longopts);
10330 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10331 NEW_VALUE. Warn if another value was already specified. Note:
10332 we have to defer parsing the -march and -mtune arguments in order
10333 to handle 'from-abi' correctly, since the ABI might be specified
10334 in a later argument. */
10337 mips_set_option_string (const char **string_ptr, const char *new_value)
10339 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
10340 as_warn (_("A different %s was already specified, is now %s"),
10341 string_ptr == &mips_arch_string ? "-march" : "-mtune",
10344 *string_ptr = new_value;
10348 md_parse_option (int c, char *arg)
10352 case OPTION_CONSTRUCT_FLOATS:
10353 mips_disable_float_construction = 0;
10356 case OPTION_NO_CONSTRUCT_FLOATS:
10357 mips_disable_float_construction = 1;
10369 target_big_endian = 1;
10373 target_big_endian = 0;
10381 if (arg && arg[1] == '0')
10391 mips_debug = atoi (arg);
10392 /* When the MIPS assembler sees -g or -g2, it does not do
10393 optimizations which limit full symbolic debugging. We take
10394 that to be equivalent to -O0. */
10395 if (mips_debug == 2)
10400 file_mips_isa = ISA_MIPS1;
10404 file_mips_isa = ISA_MIPS2;
10408 file_mips_isa = ISA_MIPS3;
10412 file_mips_isa = ISA_MIPS4;
10416 file_mips_isa = ISA_MIPS5;
10419 case OPTION_MIPS32:
10420 file_mips_isa = ISA_MIPS32;
10423 case OPTION_MIPS32R2:
10424 file_mips_isa = ISA_MIPS32R2;
10427 case OPTION_MIPS64:
10428 file_mips_isa = ISA_MIPS64;
10432 mips_set_option_string (&mips_tune_string, arg);
10436 mips_set_option_string (&mips_arch_string, arg);
10440 mips_set_option_string (&mips_arch_string, "4650");
10441 mips_set_option_string (&mips_tune_string, "4650");
10444 case OPTION_NO_M4650:
10448 mips_set_option_string (&mips_arch_string, "4010");
10449 mips_set_option_string (&mips_tune_string, "4010");
10452 case OPTION_NO_M4010:
10456 mips_set_option_string (&mips_arch_string, "4100");
10457 mips_set_option_string (&mips_tune_string, "4100");
10460 case OPTION_NO_M4100:
10464 mips_set_option_string (&mips_arch_string, "3900");
10465 mips_set_option_string (&mips_tune_string, "3900");
10468 case OPTION_NO_M3900:
10472 mips_opts.ase_mdmx = 1;
10475 case OPTION_NO_MDMX:
10476 mips_opts.ase_mdmx = 0;
10479 case OPTION_MIPS16:
10480 mips_opts.mips16 = 1;
10481 mips_no_prev_insn (FALSE);
10484 case OPTION_NO_MIPS16:
10485 mips_opts.mips16 = 0;
10486 mips_no_prev_insn (FALSE);
10489 case OPTION_MIPS3D:
10490 mips_opts.ase_mips3d = 1;
10493 case OPTION_NO_MIPS3D:
10494 mips_opts.ase_mips3d = 0;
10497 case OPTION_MEMBEDDED_PIC:
10498 mips_pic = EMBEDDED_PIC;
10499 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
10501 as_bad (_("-G may not be used with embedded PIC code"));
10504 g_switch_value = 0x7fffffff;
10507 case OPTION_FIX_VR4122:
10508 mips_fix_4122_bugs = 1;
10511 case OPTION_NO_FIX_VR4122:
10512 mips_fix_4122_bugs = 0;
10515 case OPTION_RELAX_BRANCH:
10516 mips_relax_branch = 1;
10519 case OPTION_NO_RELAX_BRANCH:
10520 mips_relax_branch = 0;
10524 /* When generating ELF code, we permit -KPIC and -call_shared to
10525 select SVR4_PIC, and -non_shared to select no PIC. This is
10526 intended to be compatible with Irix 5. */
10527 case OPTION_CALL_SHARED:
10528 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10530 as_bad (_("-call_shared is supported only for ELF format"));
10533 mips_pic = SVR4_PIC;
10534 mips_abicalls = TRUE;
10535 if (g_switch_seen && g_switch_value != 0)
10537 as_bad (_("-G may not be used with SVR4 PIC code"));
10540 g_switch_value = 0;
10543 case OPTION_NON_SHARED:
10544 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10546 as_bad (_("-non_shared is supported only for ELF format"));
10550 mips_abicalls = FALSE;
10553 /* The -xgot option tells the assembler to use 32 offsets when
10554 accessing the got in SVR4_PIC mode. It is for Irix
10559 #endif /* OBJ_ELF */
10562 if (! USE_GLOBAL_POINTER_OPT)
10564 as_bad (_("-G is not supported for this configuration"));
10567 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10569 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10573 g_switch_value = atoi (arg);
10578 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10581 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10583 as_bad (_("-32 is supported for ELF format only"));
10586 mips_abi = O32_ABI;
10590 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10592 as_bad (_("-n32 is supported for ELF format only"));
10595 mips_abi = N32_ABI;
10599 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10601 as_bad (_("-64 is supported for ELF format only"));
10604 mips_abi = N64_ABI;
10605 if (! support_64bit_objects())
10606 as_fatal (_("No compiled in support for 64 bit object file format"));
10608 #endif /* OBJ_ELF */
10611 file_mips_gp32 = 1;
10615 file_mips_gp32 = 0;
10619 file_mips_fp32 = 1;
10623 file_mips_fp32 = 0;
10628 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10630 as_bad (_("-mabi is supported for ELF format only"));
10633 if (strcmp (arg, "32") == 0)
10634 mips_abi = O32_ABI;
10635 else if (strcmp (arg, "o64") == 0)
10636 mips_abi = O64_ABI;
10637 else if (strcmp (arg, "n32") == 0)
10638 mips_abi = N32_ABI;
10639 else if (strcmp (arg, "64") == 0)
10641 mips_abi = N64_ABI;
10642 if (! support_64bit_objects())
10643 as_fatal (_("No compiled in support for 64 bit object file "
10646 else if (strcmp (arg, "eabi") == 0)
10647 mips_abi = EABI_ABI;
10650 as_fatal (_("invalid abi -mabi=%s"), arg);
10654 #endif /* OBJ_ELF */
10656 case OPTION_M7000_HILO_FIX:
10657 mips_7000_hilo_fix = TRUE;
10660 case OPTION_MNO_7000_HILO_FIX:
10661 mips_7000_hilo_fix = FALSE;
10665 case OPTION_MDEBUG:
10666 mips_flag_mdebug = TRUE;
10669 case OPTION_NO_MDEBUG:
10670 mips_flag_mdebug = FALSE;
10672 #endif /* OBJ_ELF */
10681 /* Set up globals to generate code for the ISA or processor
10682 described by INFO. */
10685 mips_set_architecture (const struct mips_cpu_info *info)
10689 file_mips_arch = info->cpu;
10690 mips_opts.arch = info->cpu;
10691 mips_opts.isa = info->isa;
10696 /* Likewise for tuning. */
10699 mips_set_tune (const struct mips_cpu_info *info)
10702 mips_tune = info->cpu;
10707 mips_after_parse_args (void)
10709 const struct mips_cpu_info *arch_info = 0;
10710 const struct mips_cpu_info *tune_info = 0;
10712 /* GP relative stuff not working for PE */
10713 if (strncmp (TARGET_OS, "pe", 2) == 0
10714 && g_switch_value != 0)
10717 as_bad (_("-G not supported in this configuration."));
10718 g_switch_value = 0;
10721 if (mips_abi == NO_ABI)
10722 mips_abi = MIPS_DEFAULT_ABI;
10724 /* The following code determines the architecture and register size.
10725 Similar code was added to GCC 3.3 (see override_options() in
10726 config/mips/mips.c). The GAS and GCC code should be kept in sync
10727 as much as possible. */
10729 if (mips_arch_string != 0)
10730 arch_info = mips_parse_cpu ("-march", mips_arch_string);
10732 if (file_mips_isa != ISA_UNKNOWN)
10734 /* Handle -mipsN. At this point, file_mips_isa contains the
10735 ISA level specified by -mipsN, while arch_info->isa contains
10736 the -march selection (if any). */
10737 if (arch_info != 0)
10739 /* -march takes precedence over -mipsN, since it is more descriptive.
10740 There's no harm in specifying both as long as the ISA levels
10742 if (file_mips_isa != arch_info->isa)
10743 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
10744 mips_cpu_info_from_isa (file_mips_isa)->name,
10745 mips_cpu_info_from_isa (arch_info->isa)->name);
10748 arch_info = mips_cpu_info_from_isa (file_mips_isa);
10751 if (arch_info == 0)
10752 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
10754 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
10755 as_bad ("-march=%s is not compatible with the selected ABI",
10758 mips_set_architecture (arch_info);
10760 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
10761 if (mips_tune_string != 0)
10762 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
10764 if (tune_info == 0)
10765 mips_set_tune (arch_info);
10767 mips_set_tune (tune_info);
10769 if (file_mips_gp32 >= 0)
10771 /* The user specified the size of the integer registers. Make sure
10772 it agrees with the ABI and ISA. */
10773 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
10774 as_bad (_("-mgp64 used with a 32-bit processor"));
10775 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
10776 as_bad (_("-mgp32 used with a 64-bit ABI"));
10777 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
10778 as_bad (_("-mgp64 used with a 32-bit ABI"));
10782 /* Infer the integer register size from the ABI and processor.
10783 Restrict ourselves to 32-bit registers if that's all the
10784 processor has, or if the ABI cannot handle 64-bit registers. */
10785 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
10786 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
10789 /* ??? GAS treats single-float processors as though they had 64-bit
10790 float registers (although it complains when double-precision
10791 instructions are used). As things stand, saying they have 32-bit
10792 registers would lead to spurious "register must be even" messages.
10793 So here we assume float registers are always the same size as
10794 integer ones, unless the user says otherwise. */
10795 if (file_mips_fp32 < 0)
10796 file_mips_fp32 = file_mips_gp32;
10798 /* End of GCC-shared inference code. */
10800 /* This flag is set when we have a 64-bit capable CPU but use only
10801 32-bit wide registers. Note that EABI does not use it. */
10802 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
10803 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
10804 || mips_abi == O32_ABI))
10805 mips_32bitmode = 1;
10807 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
10808 as_bad (_("trap exception not supported at ISA 1"));
10810 /* If the selected architecture includes support for ASEs, enable
10811 generation of code for them. */
10812 if (mips_opts.mips16 == -1)
10813 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
10814 if (mips_opts.ase_mips3d == -1)
10815 mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (file_mips_arch)) ? 1 : 0;
10816 if (mips_opts.ase_mdmx == -1)
10817 mips_opts.ase_mdmx = (CPU_HAS_MDMX (file_mips_arch)) ? 1 : 0;
10819 file_mips_isa = mips_opts.isa;
10820 file_ase_mips16 = mips_opts.mips16;
10821 file_ase_mips3d = mips_opts.ase_mips3d;
10822 file_ase_mdmx = mips_opts.ase_mdmx;
10823 mips_opts.gp32 = file_mips_gp32;
10824 mips_opts.fp32 = file_mips_fp32;
10826 if (mips_flag_mdebug < 0)
10828 #ifdef OBJ_MAYBE_ECOFF
10829 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
10830 mips_flag_mdebug = 1;
10832 #endif /* OBJ_MAYBE_ECOFF */
10833 mips_flag_mdebug = 0;
10838 mips_init_after_args (void)
10840 /* initialize opcodes */
10841 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10842 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10846 md_pcrel_from (fixS *fixP)
10848 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
10849 switch (fixP->fx_r_type)
10851 case BFD_RELOC_16_PCREL_S2:
10852 case BFD_RELOC_MIPS_JMP:
10853 /* Return the address of the delay slot. */
10860 /* This is called before the symbol table is processed. In order to
10861 work with gcc when using mips-tfile, we must keep all local labels.
10862 However, in other cases, we want to discard them. If we were
10863 called with -g, but we didn't see any debugging information, it may
10864 mean that gcc is smuggling debugging information through to
10865 mips-tfile, in which case we must generate all local labels. */
10868 mips_frob_file_before_adjust (void)
10870 #ifndef NO_ECOFF_DEBUGGING
10871 if (ECOFF_DEBUGGING
10873 && ! ecoff_debugging_seen)
10874 flag_keep_locals = 1;
10878 /* Sort any unmatched HI16_S relocs so that they immediately precede
10879 the corresponding LO reloc. This is called before md_apply_fix3 and
10880 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10881 explicit use of the %hi modifier. */
10884 mips_frob_file (void)
10886 struct mips_hi_fixup *l;
10888 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
10890 segment_info_type *seginfo;
10893 assert (reloc_needs_lo_p (l->fixp->fx_r_type));
10895 /* If a GOT16 relocation turns out to be against a global symbol,
10896 there isn't supposed to be a matching LO. */
10897 if (l->fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
10898 && !pic_need_relax (l->fixp->fx_addsy, l->seg))
10901 /* Check quickly whether the next fixup happens to be a matching %lo. */
10902 if (fixup_has_matching_lo_p (l->fixp))
10905 /* Look through the fixups for this segment for a matching %lo.
10906 When we find one, move the %hi just in front of it. We do
10907 this in two passes. In the first pass, we try to find a
10908 unique %lo. In the second pass, we permit multiple %hi
10909 relocs for a single %lo (this is a GNU extension). */
10910 seginfo = seg_info (l->seg);
10911 for (pass = 0; pass < 2; pass++)
10916 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
10918 /* Check whether this is a %lo fixup which matches l->fixp. */
10919 if (f->fx_r_type == BFD_RELOC_LO16
10920 && f->fx_addsy == l->fixp->fx_addsy
10921 && f->fx_offset == l->fixp->fx_offset
10924 || !reloc_needs_lo_p (prev->fx_r_type)
10925 || !fixup_has_matching_lo_p (prev)))
10929 /* Move l->fixp before f. */
10930 for (pf = &seginfo->fix_root;
10932 pf = &(*pf)->fx_next)
10933 assert (*pf != NULL);
10935 *pf = l->fixp->fx_next;
10937 l->fixp->fx_next = f;
10939 seginfo->fix_root = l->fixp;
10941 prev->fx_next = l->fixp;
10952 #if 0 /* GCC code motion plus incomplete dead code elimination
10953 can leave a %hi without a %lo. */
10955 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
10956 _("Unmatched %%hi reloc"));
10962 /* When generating embedded PIC code we need to use a special
10963 relocation to represent the difference of two symbols in the .text
10964 section (switch tables use a difference of this sort). See
10965 include/coff/mips.h for details. This macro checks whether this
10966 fixup requires the special reloc. */
10967 #define SWITCH_TABLE(fixp) \
10968 ((fixp)->fx_r_type == BFD_RELOC_32 \
10969 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10970 && (fixp)->fx_addsy != NULL \
10971 && (fixp)->fx_subsy != NULL \
10972 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10973 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10975 /* When generating embedded PIC code we must keep all PC relative
10976 relocations, in case the linker has to relax a call. We also need
10977 to keep relocations for switch table entries.
10979 We may have combined relocations without symbols in the N32/N64 ABI.
10980 We have to prevent gas from dropping them. */
10983 mips_force_relocation (fixS *fixp)
10985 if (generic_force_reloc (fixp))
10989 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
10990 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
10991 || fixp->fx_r_type == BFD_RELOC_HI16_S
10992 || fixp->fx_r_type == BFD_RELOC_LO16))
10995 return (mips_pic == EMBEDDED_PIC
10997 || SWITCH_TABLE (fixp)
10998 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
10999 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
11002 /* This hook is called before a fix is simplified. We don't really
11003 decide whether to skip a fix here. Rather, we turn global symbols
11004 used as branch targets into local symbols, such that they undergo
11005 simplification. We can only do this if the symbol is defined and
11006 it is in the same section as the branch. If this doesn't hold, we
11007 emit a better error message than just saying the relocation is not
11008 valid for the selected object format.
11010 FIXP is the fix-up we're going to try to simplify, SEG is the
11011 segment in which the fix up occurs. The return value should be
11012 non-zero to indicate the fix-up is valid for further
11013 simplifications. */
11016 mips_validate_fix (struct fix *fixP, asection *seg)
11018 /* There's a lot of discussion on whether it should be possible to
11019 use R_MIPS_PC16 to represent branch relocations. The outcome
11020 seems to be that it can, but gas/bfd are very broken in creating
11021 RELA relocations for this, so for now we only accept branches to
11022 symbols in the same section. Anything else is of dubious value,
11023 since there's no guarantee that at link time the symbol would be
11024 in range. Even for branches to local symbols this is arguably
11025 wrong, since it we assume the symbol is not going to be
11026 overridden, which should be possible per ELF library semantics,
11027 but then, there isn't a dynamic relocation that could be used to
11028 this effect, and the target would likely be out of range as well.
11030 Unfortunately, it seems that there is too much code out there
11031 that relies on branches to symbols that are global to be resolved
11032 as if they were local, like the IRIX tools do, so we do it as
11033 well, but with a warning so that people are reminded to fix their
11034 code. If we ever get back to using R_MIPS_PC16 for branch
11035 targets, this entire block should go away (and probably the
11036 whole function). */
11038 if (fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
11039 && (((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
11040 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11041 && mips_pic != EMBEDDED_PIC)
11042 || bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16_PCREL_S2) == NULL)
11045 if (! S_IS_DEFINED (fixP->fx_addsy))
11047 as_bad_where (fixP->fx_file, fixP->fx_line,
11048 _("Cannot branch to undefined symbol."));
11049 /* Avoid any further errors about this fixup. */
11052 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
11054 as_bad_where (fixP->fx_file, fixP->fx_line,
11055 _("Cannot branch to symbol in another section."));
11058 else if (S_IS_EXTERNAL (fixP->fx_addsy))
11060 symbolS *sym = fixP->fx_addsy;
11062 if (mips_pic == SVR4_PIC)
11063 as_warn_where (fixP->fx_file, fixP->fx_line,
11064 _("Pretending global symbol used as branch target is local."));
11066 fixP->fx_addsy = symbol_create (S_GET_NAME (sym),
11067 S_GET_SEGMENT (sym),
11069 symbol_get_frag (sym));
11070 copy_symbol_attributes (fixP->fx_addsy, sym);
11071 S_CLEAR_EXTERNAL (fixP->fx_addsy);
11072 assert (symbol_resolved_p (sym));
11073 symbol_mark_resolved (fixP->fx_addsy);
11082 mips_need_elf_addend_fixup (fixS *fixP)
11084 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
11086 if (mips_pic == EMBEDDED_PIC
11087 && S_IS_WEAK (fixP->fx_addsy))
11089 if (mips_pic != EMBEDDED_PIC
11090 && (S_IS_WEAK (fixP->fx_addsy)
11091 || S_IS_EXTERNAL (fixP->fx_addsy))
11092 && !S_IS_COMMON (fixP->fx_addsy))
11094 if (((bfd_get_section_flags (stdoutput,
11095 S_GET_SEGMENT (fixP->fx_addsy))
11096 & (SEC_LINK_ONCE | SEC_MERGE)) != 0)
11097 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
11099 sizeof (".gnu.linkonce") - 1))
11105 /* Apply a fixup to the object file. */
11108 md_apply_fix3 (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
11112 static int previous_fx_r_type = 0;
11113 reloc_howto_type *howto;
11115 /* We ignore generic BFD relocations we don't know about. */
11116 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
11120 assert (fixP->fx_size == 4
11121 || fixP->fx_r_type == BFD_RELOC_16
11122 || fixP->fx_r_type == BFD_RELOC_64
11123 || fixP->fx_r_type == BFD_RELOC_CTOR
11124 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11125 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11126 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
11128 buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
11130 /* If we aren't adjusting this fixup to be against the section
11131 symbol, we need to adjust the value. */
11133 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
11135 if (mips_need_elf_addend_fixup (fixP)
11136 && howto->partial_inplace
11137 && fixP->fx_r_type != BFD_RELOC_GPREL16
11138 && fixP->fx_r_type != BFD_RELOC_GPREL32
11139 && fixP->fx_r_type != BFD_RELOC_MIPS16_GPREL)
11141 /* In this case, the bfd_install_relocation routine will
11142 incorrectly add the symbol value back in. We just want
11143 the addend to appear in the object file.
11145 The condition above used to include
11146 "&& (! fixP->fx_pcrel || howto->pcrel_offset)".
11148 However, howto can't be trusted here, because we
11149 might change the reloc type in tc_gen_reloc. We can
11150 check howto->partial_inplace because that conversion
11151 happens to preserve howto->partial_inplace; but it
11152 does not preserve howto->pcrel_offset. I've just
11153 eliminated the check, because all MIPS PC-relative
11154 relocations are marked howto->pcrel_offset.
11156 howto->pcrel_offset was originally added for
11157 R_MIPS_PC16, which is generated for code like
11166 *valP -= S_GET_VALUE (fixP->fx_addsy);
11169 /* This code was generated using trial and error and so is
11170 fragile and not trustworthy. If you change it, you should
11171 rerun the elf-rel, elf-rel2, and empic testcases and ensure
11172 they still pass. */
11173 if (fixP->fx_pcrel)
11175 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11177 /* BFD's REL handling, for MIPS, is _very_ weird.
11178 This gives the right results, but it can't possibly
11179 be the way things are supposed to work. */
11180 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11185 /* We are not done if this is a composite relocation to set up gp. */
11186 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel
11187 && !(fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11188 || (fixP->fx_r_type == BFD_RELOC_64
11189 && (previous_fx_r_type == BFD_RELOC_GPREL32
11190 || previous_fx_r_type == BFD_RELOC_GPREL16))
11191 || (previous_fx_r_type == BFD_RELOC_MIPS_SUB
11192 && (fixP->fx_r_type == BFD_RELOC_HI16_S
11193 || fixP->fx_r_type == BFD_RELOC_LO16))))
11195 previous_fx_r_type = fixP->fx_r_type;
11197 switch (fixP->fx_r_type)
11199 case BFD_RELOC_MIPS_JMP:
11200 case BFD_RELOC_MIPS_SHIFT5:
11201 case BFD_RELOC_MIPS_SHIFT6:
11202 case BFD_RELOC_MIPS_GOT_DISP:
11203 case BFD_RELOC_MIPS_GOT_PAGE:
11204 case BFD_RELOC_MIPS_GOT_OFST:
11205 case BFD_RELOC_MIPS_SUB:
11206 case BFD_RELOC_MIPS_INSERT_A:
11207 case BFD_RELOC_MIPS_INSERT_B:
11208 case BFD_RELOC_MIPS_DELETE:
11209 case BFD_RELOC_MIPS_HIGHEST:
11210 case BFD_RELOC_MIPS_HIGHER:
11211 case BFD_RELOC_MIPS_SCN_DISP:
11212 case BFD_RELOC_MIPS_REL16:
11213 case BFD_RELOC_MIPS_RELGOT:
11214 case BFD_RELOC_MIPS_JALR:
11215 case BFD_RELOC_HI16:
11216 case BFD_RELOC_HI16_S:
11217 case BFD_RELOC_GPREL16:
11218 case BFD_RELOC_MIPS_LITERAL:
11219 case BFD_RELOC_MIPS_CALL16:
11220 case BFD_RELOC_MIPS_GOT16:
11221 case BFD_RELOC_GPREL32:
11222 case BFD_RELOC_MIPS_GOT_HI16:
11223 case BFD_RELOC_MIPS_GOT_LO16:
11224 case BFD_RELOC_MIPS_CALL_HI16:
11225 case BFD_RELOC_MIPS_CALL_LO16:
11226 case BFD_RELOC_MIPS16_GPREL:
11227 if (fixP->fx_pcrel)
11228 as_bad_where (fixP->fx_file, fixP->fx_line,
11229 _("Invalid PC relative reloc"));
11230 /* Nothing needed to do. The value comes from the reloc entry */
11233 case BFD_RELOC_MIPS16_JMP:
11234 /* We currently always generate a reloc against a symbol, which
11235 means that we don't want an addend even if the symbol is
11240 case BFD_RELOC_PCREL_HI16_S:
11241 /* The addend for this is tricky if it is internal, so we just
11242 do everything here rather than in bfd_install_relocation. */
11243 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && !fixP->fx_done)
11246 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11248 /* For an external symbol adjust by the address to make it
11249 pcrel_offset. We use the address of the RELLO reloc
11250 which follows this one. */
11251 *valP += (fixP->fx_next->fx_frag->fr_address
11252 + fixP->fx_next->fx_where);
11254 *valP = ((*valP + 0x8000) >> 16) & 0xffff;
11255 if (target_big_endian)
11257 md_number_to_chars (buf, *valP, 2);
11260 case BFD_RELOC_PCREL_LO16:
11261 /* The addend for this is tricky if it is internal, so we just
11262 do everything here rather than in bfd_install_relocation. */
11263 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && !fixP->fx_done)
11266 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11267 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11268 if (target_big_endian)
11270 md_number_to_chars (buf, *valP, 2);
11274 /* This is handled like BFD_RELOC_32, but we output a sign
11275 extended value if we are only 32 bits. */
11277 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11279 if (8 <= sizeof (valueT))
11280 md_number_to_chars (buf, *valP, 8);
11285 if ((*valP & 0x80000000) != 0)
11289 md_number_to_chars ((char *)(buf + target_big_endian ? 4 : 0),
11291 md_number_to_chars ((char *)(buf + target_big_endian ? 0 : 4),
11297 case BFD_RELOC_RVA:
11299 /* If we are deleting this reloc entry, we must fill in the
11300 value now. This can happen if we have a .word which is not
11301 resolved when it appears but is later defined. We also need
11302 to fill in the value if this is an embedded PIC switch table
11305 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11306 md_number_to_chars (buf, *valP, 4);
11310 /* If we are deleting this reloc entry, we must fill in the
11312 assert (fixP->fx_size == 2);
11314 md_number_to_chars (buf, *valP, 2);
11317 case BFD_RELOC_LO16:
11318 /* When handling an embedded PIC switch statement, we can wind
11319 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11322 if (*valP + 0x8000 > 0xffff)
11323 as_bad_where (fixP->fx_file, fixP->fx_line,
11324 _("relocation overflow"));
11325 if (target_big_endian)
11327 md_number_to_chars (buf, *valP, 2);
11331 case BFD_RELOC_16_PCREL_S2:
11332 if ((*valP & 0x3) != 0)
11333 as_bad_where (fixP->fx_file, fixP->fx_line,
11334 _("Branch to odd address (%lx)"), (long) *valP);
11337 * We need to save the bits in the instruction since fixup_segment()
11338 * might be deleting the relocation entry (i.e., a branch within
11339 * the current segment).
11341 if (! fixP->fx_done)
11344 /* update old instruction data */
11345 if (target_big_endian)
11346 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
11348 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
11350 if (*valP + 0x20000 <= 0x3ffff)
11352 insn |= (*valP >> 2) & 0xffff;
11353 md_number_to_chars (buf, insn, 4);
11355 else if (mips_pic == NO_PIC
11357 && fixP->fx_frag->fr_address >= text_section->vma
11358 && (fixP->fx_frag->fr_address
11359 < text_section->vma + text_section->_raw_size)
11360 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
11361 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
11362 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
11364 /* The branch offset is too large. If this is an
11365 unconditional branch, and we are not generating PIC code,
11366 we can convert it to an absolute jump instruction. */
11367 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
11368 insn = 0x0c000000; /* jal */
11370 insn = 0x08000000; /* j */
11371 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
11373 fixP->fx_addsy = section_symbol (text_section);
11374 *valP += md_pcrel_from (fixP);
11375 md_number_to_chars (buf, insn, 4);
11379 /* If we got here, we have branch-relaxation disabled,
11380 and there's nothing we can do to fix this instruction
11381 without turning it into a longer sequence. */
11382 as_bad_where (fixP->fx_file, fixP->fx_line,
11383 _("Branch out of range"));
11387 case BFD_RELOC_VTABLE_INHERIT:
11390 && !S_IS_DEFINED (fixP->fx_addsy)
11391 && !S_IS_WEAK (fixP->fx_addsy))
11392 S_SET_WEAK (fixP->fx_addsy);
11395 case BFD_RELOC_VTABLE_ENTRY:
11403 /* Remember value for tc_gen_reloc. */
11404 fixP->fx_addnumber = *valP;
11409 printInsn (unsigned long oc)
11411 const struct mips_opcode *p;
11412 int treg, sreg, dreg, shamt;
11417 for (i = 0; i < NUMOPCODES; ++i)
11419 p = &mips_opcodes[i];
11420 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
11422 printf ("%08lx %s\t", oc, p->name);
11423 treg = (oc >> 16) & 0x1f;
11424 sreg = (oc >> 21) & 0x1f;
11425 dreg = (oc >> 11) & 0x1f;
11426 shamt = (oc >> 6) & 0x1f;
11428 for (args = p->args;; ++args)
11439 printf ("%c", *args);
11443 assert (treg == sreg);
11444 printf ("$%d,$%d", treg, sreg);
11449 printf ("$%d", dreg);
11454 printf ("$%d", treg);
11458 printf ("0x%x", treg);
11463 printf ("$%d", sreg);
11467 printf ("0x%08lx", oc & 0x1ffffff);
11474 printf ("%d", imm);
11479 printf ("$%d", shamt);
11490 printf (_("%08lx UNDEFINED\n"), oc);
11501 name = input_line_pointer;
11502 c = get_symbol_end ();
11503 p = (symbolS *) symbol_find_or_make (name);
11504 *input_line_pointer = c;
11508 /* Align the current frag to a given power of two. The MIPS assembler
11509 also automatically adjusts any preceding label. */
11512 mips_align (int to, int fill, symbolS *label)
11514 mips_emit_delays (FALSE);
11515 frag_align (to, fill, 0);
11516 record_alignment (now_seg, to);
11519 assert (S_GET_SEGMENT (label) == now_seg);
11520 symbol_set_frag (label, frag_now);
11521 S_SET_VALUE (label, (valueT) frag_now_fix ());
11525 /* Align to a given power of two. .align 0 turns off the automatic
11526 alignment used by the data creating pseudo-ops. */
11529 s_align (int x ATTRIBUTE_UNUSED)
11532 register long temp_fill;
11533 long max_alignment = 15;
11537 o Note that the assembler pulls down any immediately preceeding label
11538 to the aligned address.
11539 o It's not documented but auto alignment is reinstated by
11540 a .align pseudo instruction.
11541 o Note also that after auto alignment is turned off the mips assembler
11542 issues an error on attempt to assemble an improperly aligned data item.
11547 temp = get_absolute_expression ();
11548 if (temp > max_alignment)
11549 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11552 as_warn (_("Alignment negative: 0 assumed."));
11555 if (*input_line_pointer == ',')
11557 ++input_line_pointer;
11558 temp_fill = get_absolute_expression ();
11565 mips_align (temp, (int) temp_fill,
11566 insn_labels != NULL ? insn_labels->label : NULL);
11573 demand_empty_rest_of_line ();
11577 mips_flush_pending_output (void)
11579 mips_emit_delays (FALSE);
11580 mips_clear_insn_labels ();
11584 s_change_sec (int sec)
11588 /* When generating embedded PIC code, we only use the .text, .lit8,
11589 .sdata and .sbss sections. We change the .data and .rdata
11590 pseudo-ops to use .sdata. */
11591 if (mips_pic == EMBEDDED_PIC
11592 && (sec == 'd' || sec == 'r'))
11596 /* The ELF backend needs to know that we are changing sections, so
11597 that .previous works correctly. We could do something like check
11598 for an obj_section_change_hook macro, but that might be confusing
11599 as it would not be appropriate to use it in the section changing
11600 functions in read.c, since obj-elf.c intercepts those. FIXME:
11601 This should be cleaner, somehow. */
11602 obj_elf_section_change_hook ();
11605 mips_emit_delays (FALSE);
11615 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11616 demand_empty_rest_of_line ();
11620 if (USE_GLOBAL_POINTER_OPT)
11622 seg = subseg_new (RDATA_SECTION_NAME,
11623 (subsegT) get_absolute_expression ());
11624 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11626 bfd_set_section_flags (stdoutput, seg,
11632 if (strcmp (TARGET_OS, "elf") != 0)
11633 record_alignment (seg, 4);
11635 demand_empty_rest_of_line ();
11639 as_bad (_("No read only data section in this object file format"));
11640 demand_empty_rest_of_line ();
11646 if (USE_GLOBAL_POINTER_OPT)
11648 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11649 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11651 bfd_set_section_flags (stdoutput, seg,
11652 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11654 if (strcmp (TARGET_OS, "elf") != 0)
11655 record_alignment (seg, 4);
11657 demand_empty_rest_of_line ();
11662 as_bad (_("Global pointers not supported; recompile -G 0"));
11663 demand_empty_rest_of_line ();
11672 s_change_section (int ignore ATTRIBUTE_UNUSED)
11675 char *section_name;
11680 int section_entry_size;
11681 int section_alignment;
11683 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11686 section_name = input_line_pointer;
11687 c = get_symbol_end ();
11689 next_c = *(input_line_pointer + 1);
11691 /* Do we have .section Name<,"flags">? */
11692 if (c != ',' || (c == ',' && next_c == '"'))
11694 /* just after name is now '\0'. */
11695 *input_line_pointer = c;
11696 input_line_pointer = section_name;
11697 obj_elf_section (ignore);
11700 input_line_pointer++;
11702 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
11704 section_type = get_absolute_expression ();
11707 if (*input_line_pointer++ == ',')
11708 section_flag = get_absolute_expression ();
11711 if (*input_line_pointer++ == ',')
11712 section_entry_size = get_absolute_expression ();
11714 section_entry_size = 0;
11715 if (*input_line_pointer++ == ',')
11716 section_alignment = get_absolute_expression ();
11718 section_alignment = 0;
11720 section_name = xstrdup (section_name);
11722 obj_elf_change_section (section_name, section_type, section_flag,
11723 section_entry_size, 0, 0, 0);
11725 if (now_seg->name != section_name)
11726 free (section_name);
11727 #endif /* OBJ_ELF */
11731 mips_enable_auto_align (void)
11737 s_cons (int log_size)
11741 label = insn_labels != NULL ? insn_labels->label : NULL;
11742 mips_emit_delays (FALSE);
11743 if (log_size > 0 && auto_align)
11744 mips_align (log_size, 0, label);
11745 mips_clear_insn_labels ();
11746 cons (1 << log_size);
11750 s_float_cons (int type)
11754 label = insn_labels != NULL ? insn_labels->label : NULL;
11756 mips_emit_delays (FALSE);
11761 mips_align (3, 0, label);
11763 mips_align (2, 0, label);
11766 mips_clear_insn_labels ();
11771 /* Handle .globl. We need to override it because on Irix 5 you are
11774 where foo is an undefined symbol, to mean that foo should be
11775 considered to be the address of a function. */
11778 s_mips_globl (int x ATTRIBUTE_UNUSED)
11785 name = input_line_pointer;
11786 c = get_symbol_end ();
11787 symbolP = symbol_find_or_make (name);
11788 *input_line_pointer = c;
11789 SKIP_WHITESPACE ();
11791 /* On Irix 5, every global symbol that is not explicitly labelled as
11792 being a function is apparently labelled as being an object. */
11795 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11800 secname = input_line_pointer;
11801 c = get_symbol_end ();
11802 sec = bfd_get_section_by_name (stdoutput, secname);
11804 as_bad (_("%s: no such section"), secname);
11805 *input_line_pointer = c;
11807 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11808 flag = BSF_FUNCTION;
11811 symbol_get_bfdsym (symbolP)->flags |= flag;
11813 S_SET_EXTERNAL (symbolP);
11814 demand_empty_rest_of_line ();
11818 s_option (int x ATTRIBUTE_UNUSED)
11823 opt = input_line_pointer;
11824 c = get_symbol_end ();
11828 /* FIXME: What does this mean? */
11830 else if (strncmp (opt, "pic", 3) == 0)
11834 i = atoi (opt + 3);
11839 mips_pic = SVR4_PIC;
11840 mips_abicalls = TRUE;
11843 as_bad (_(".option pic%d not supported"), i);
11845 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
11847 if (g_switch_seen && g_switch_value != 0)
11848 as_warn (_("-G may not be used with SVR4 PIC code"));
11849 g_switch_value = 0;
11850 bfd_set_gp_size (stdoutput, 0);
11854 as_warn (_("Unrecognized option \"%s\""), opt);
11856 *input_line_pointer = c;
11857 demand_empty_rest_of_line ();
11860 /* This structure is used to hold a stack of .set values. */
11862 struct mips_option_stack
11864 struct mips_option_stack *next;
11865 struct mips_set_options options;
11868 static struct mips_option_stack *mips_opts_stack;
11870 /* Handle the .set pseudo-op. */
11873 s_mipsset (int x ATTRIBUTE_UNUSED)
11875 char *name = input_line_pointer, ch;
11877 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11878 ++input_line_pointer;
11879 ch = *input_line_pointer;
11880 *input_line_pointer = '\0';
11882 if (strcmp (name, "reorder") == 0)
11884 if (mips_opts.noreorder && prev_nop_frag != NULL)
11886 /* If we still have pending nops, we can discard them. The
11887 usual nop handling will insert any that are still
11889 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11890 * (mips_opts.mips16 ? 2 : 4));
11891 prev_nop_frag = NULL;
11893 mips_opts.noreorder = 0;
11895 else if (strcmp (name, "noreorder") == 0)
11897 mips_emit_delays (TRUE);
11898 mips_opts.noreorder = 1;
11899 mips_any_noreorder = 1;
11901 else if (strcmp (name, "at") == 0)
11903 mips_opts.noat = 0;
11905 else if (strcmp (name, "noat") == 0)
11907 mips_opts.noat = 1;
11909 else if (strcmp (name, "macro") == 0)
11911 mips_opts.warn_about_macros = 0;
11913 else if (strcmp (name, "nomacro") == 0)
11915 if (mips_opts.noreorder == 0)
11916 as_bad (_("`noreorder' must be set before `nomacro'"));
11917 mips_opts.warn_about_macros = 1;
11919 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11921 mips_opts.nomove = 0;
11923 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11925 mips_opts.nomove = 1;
11927 else if (strcmp (name, "bopt") == 0)
11929 mips_opts.nobopt = 0;
11931 else if (strcmp (name, "nobopt") == 0)
11933 mips_opts.nobopt = 1;
11935 else if (strcmp (name, "mips16") == 0
11936 || strcmp (name, "MIPS-16") == 0)
11937 mips_opts.mips16 = 1;
11938 else if (strcmp (name, "nomips16") == 0
11939 || strcmp (name, "noMIPS-16") == 0)
11940 mips_opts.mips16 = 0;
11941 else if (strcmp (name, "mips3d") == 0)
11942 mips_opts.ase_mips3d = 1;
11943 else if (strcmp (name, "nomips3d") == 0)
11944 mips_opts.ase_mips3d = 0;
11945 else if (strcmp (name, "mdmx") == 0)
11946 mips_opts.ase_mdmx = 1;
11947 else if (strcmp (name, "nomdmx") == 0)
11948 mips_opts.ase_mdmx = 0;
11949 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
11953 /* Permit the user to change the ISA and architecture on the fly.
11954 Needless to say, misuse can cause serious problems. */
11955 if (strcmp (name, "mips0") == 0)
11958 mips_opts.isa = file_mips_isa;
11960 else if (strcmp (name, "mips1") == 0)
11961 mips_opts.isa = ISA_MIPS1;
11962 else if (strcmp (name, "mips2") == 0)
11963 mips_opts.isa = ISA_MIPS2;
11964 else if (strcmp (name, "mips3") == 0)
11965 mips_opts.isa = ISA_MIPS3;
11966 else if (strcmp (name, "mips4") == 0)
11967 mips_opts.isa = ISA_MIPS4;
11968 else if (strcmp (name, "mips5") == 0)
11969 mips_opts.isa = ISA_MIPS5;
11970 else if (strcmp (name, "mips32") == 0)
11971 mips_opts.isa = ISA_MIPS32;
11972 else if (strcmp (name, "mips32r2") == 0)
11973 mips_opts.isa = ISA_MIPS32R2;
11974 else if (strcmp (name, "mips64") == 0)
11975 mips_opts.isa = ISA_MIPS64;
11976 else if (strcmp (name, "arch=default") == 0)
11979 mips_opts.arch = file_mips_arch;
11980 mips_opts.isa = file_mips_isa;
11982 else if (strncmp (name, "arch=", 5) == 0)
11984 const struct mips_cpu_info *p;
11986 p = mips_parse_cpu("internal use", name + 5);
11988 as_bad (_("unknown architecture %s"), name + 5);
11991 mips_opts.arch = p->cpu;
11992 mips_opts.isa = p->isa;
11996 as_bad (_("unknown ISA level %s"), name + 4);
11998 switch (mips_opts.isa)
12006 mips_opts.gp32 = 1;
12007 mips_opts.fp32 = 1;
12013 mips_opts.gp32 = 0;
12014 mips_opts.fp32 = 0;
12017 as_bad (_("unknown ISA level %s"), name + 4);
12022 mips_opts.gp32 = file_mips_gp32;
12023 mips_opts.fp32 = file_mips_fp32;
12026 else if (strcmp (name, "autoextend") == 0)
12027 mips_opts.noautoextend = 0;
12028 else if (strcmp (name, "noautoextend") == 0)
12029 mips_opts.noautoextend = 1;
12030 else if (strcmp (name, "push") == 0)
12032 struct mips_option_stack *s;
12034 s = (struct mips_option_stack *) xmalloc (sizeof *s);
12035 s->next = mips_opts_stack;
12036 s->options = mips_opts;
12037 mips_opts_stack = s;
12039 else if (strcmp (name, "pop") == 0)
12041 struct mips_option_stack *s;
12043 s = mips_opts_stack;
12045 as_bad (_(".set pop with no .set push"));
12048 /* If we're changing the reorder mode we need to handle
12049 delay slots correctly. */
12050 if (s->options.noreorder && ! mips_opts.noreorder)
12051 mips_emit_delays (TRUE);
12052 else if (! s->options.noreorder && mips_opts.noreorder)
12054 if (prev_nop_frag != NULL)
12056 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
12057 * (mips_opts.mips16 ? 2 : 4));
12058 prev_nop_frag = NULL;
12062 mips_opts = s->options;
12063 mips_opts_stack = s->next;
12069 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
12071 *input_line_pointer = ch;
12072 demand_empty_rest_of_line ();
12075 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
12076 .option pic2. It means to generate SVR4 PIC calls. */
12079 s_abicalls (int ignore ATTRIBUTE_UNUSED)
12081 mips_pic = SVR4_PIC;
12082 mips_abicalls = TRUE;
12083 if (USE_GLOBAL_POINTER_OPT)
12085 if (g_switch_seen && g_switch_value != 0)
12086 as_warn (_("-G may not be used with SVR4 PIC code"));
12087 g_switch_value = 0;
12089 bfd_set_gp_size (stdoutput, 0);
12090 demand_empty_rest_of_line ();
12093 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12094 PIC code. It sets the $gp register for the function based on the
12095 function address, which is in the register named in the argument.
12096 This uses a relocation against _gp_disp, which is handled specially
12097 by the linker. The result is:
12098 lui $gp,%hi(_gp_disp)
12099 addiu $gp,$gp,%lo(_gp_disp)
12100 addu $gp,$gp,.cpload argument
12101 The .cpload argument is normally $25 == $t9. */
12104 s_cpload (int ignore ATTRIBUTE_UNUSED)
12109 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12110 .cpload is ignored. */
12111 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12117 /* .cpload should be in a .set noreorder section. */
12118 if (mips_opts.noreorder == 0)
12119 as_warn (_(".cpload not in noreorder section"));
12121 ex.X_op = O_symbol;
12122 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
12123 ex.X_op_symbol = NULL;
12124 ex.X_add_number = 0;
12126 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12127 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
12129 macro_build_lui (NULL, &icnt, &ex, mips_gp_register);
12130 macro_build (NULL, &icnt, &ex, "addiu", "t,r,j", mips_gp_register,
12131 mips_gp_register, BFD_RELOC_LO16);
12133 macro_build (NULL, &icnt, NULL, "addu", "d,v,t", mips_gp_register,
12134 mips_gp_register, tc_get_register (0));
12136 demand_empty_rest_of_line ();
12139 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12140 .cpsetup $reg1, offset|$reg2, label
12142 If offset is given, this results in:
12143 sd $gp, offset($sp)
12144 lui $gp, %hi(%neg(%gp_rel(label)))
12145 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12146 daddu $gp, $gp, $reg1
12148 If $reg2 is given, this results in:
12149 daddu $reg2, $gp, $0
12150 lui $gp, %hi(%neg(%gp_rel(label)))
12151 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12152 daddu $gp, $gp, $reg1
12153 $reg1 is normally $25 == $t9. */
12155 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
12157 expressionS ex_off;
12158 expressionS ex_sym;
12163 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12164 We also need NewABI support. */
12165 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12171 reg1 = tc_get_register (0);
12172 SKIP_WHITESPACE ();
12173 if (*input_line_pointer != ',')
12175 as_bad (_("missing argument separator ',' for .cpsetup"));
12179 ++input_line_pointer;
12180 SKIP_WHITESPACE ();
12181 if (*input_line_pointer == '$')
12183 mips_cpreturn_register = tc_get_register (0);
12184 mips_cpreturn_offset = -1;
12188 mips_cpreturn_offset = get_absolute_expression ();
12189 mips_cpreturn_register = -1;
12191 SKIP_WHITESPACE ();
12192 if (*input_line_pointer != ',')
12194 as_bad (_("missing argument separator ',' for .cpsetup"));
12198 ++input_line_pointer;
12199 SKIP_WHITESPACE ();
12200 expression (&ex_sym);
12202 if (mips_cpreturn_register == -1)
12204 ex_off.X_op = O_constant;
12205 ex_off.X_add_symbol = NULL;
12206 ex_off.X_op_symbol = NULL;
12207 ex_off.X_add_number = mips_cpreturn_offset;
12209 macro_build (NULL, &icnt, &ex_off, "sd", "t,o(b)", mips_gp_register,
12210 BFD_RELOC_LO16, SP);
12213 macro_build (NULL, &icnt, NULL, "daddu", "d,v,t", mips_cpreturn_register,
12214 mips_gp_register, 0);
12216 /* Ensure there's room for the next two instructions, so that `f'
12217 doesn't end up with an address in the wrong frag. */
12220 macro_build (NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
12221 BFD_RELOC_GPREL16);
12222 fix_new (frag_now, f - frag_now->fr_literal,
12223 8, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
12224 fix_new (frag_now, f - frag_now->fr_literal,
12225 4, NULL, 0, 0, BFD_RELOC_HI16_S);
12228 macro_build (NULL, &icnt, &ex_sym, "addiu", "t,r,j", mips_gp_register,
12229 mips_gp_register, BFD_RELOC_GPREL16);
12230 fix_new (frag_now, f - frag_now->fr_literal,
12231 8, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
12232 fix_new (frag_now, f - frag_now->fr_literal,
12233 4, NULL, 0, 0, BFD_RELOC_LO16);
12235 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
12236 mips_gp_register, reg1);
12238 demand_empty_rest_of_line ();
12242 s_cplocal (int ignore ATTRIBUTE_UNUSED)
12244 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12245 .cplocal is ignored. */
12246 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12252 mips_gp_register = tc_get_register (0);
12253 demand_empty_rest_of_line ();
12256 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12257 offset from $sp. The offset is remembered, and after making a PIC
12258 call $gp is restored from that location. */
12261 s_cprestore (int ignore ATTRIBUTE_UNUSED)
12266 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12267 .cprestore is ignored. */
12268 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12274 mips_cprestore_offset = get_absolute_expression ();
12275 mips_cprestore_valid = 1;
12277 ex.X_op = O_constant;
12278 ex.X_add_symbol = NULL;
12279 ex.X_op_symbol = NULL;
12280 ex.X_add_number = mips_cprestore_offset;
12282 macro_build_ldst_constoffset (NULL, &icnt, &ex, ADDRESS_STORE_INSN,
12283 mips_gp_register, SP);
12285 demand_empty_rest_of_line ();
12288 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12289 was given in the preceeding .gpsetup, it results in:
12290 ld $gp, offset($sp)
12292 If a register $reg2 was given there, it results in:
12293 daddiu $gp, $gp, $reg2
12296 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
12301 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12302 We also need NewABI support. */
12303 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12309 if (mips_cpreturn_register == -1)
12311 ex.X_op = O_constant;
12312 ex.X_add_symbol = NULL;
12313 ex.X_op_symbol = NULL;
12314 ex.X_add_number = mips_cpreturn_offset;
12316 macro_build (NULL, &icnt, &ex, "ld", "t,o(b)", mips_gp_register,
12317 BFD_RELOC_LO16, SP);
12320 macro_build (NULL, &icnt, NULL, "daddu", "d,v,t", mips_gp_register,
12321 mips_cpreturn_register, 0);
12323 demand_empty_rest_of_line ();
12326 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12327 code. It sets the offset to use in gp_rel relocations. */
12330 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
12332 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12333 We also need NewABI support. */
12334 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12340 mips_gprel_offset = get_absolute_expression ();
12342 demand_empty_rest_of_line ();
12345 /* Handle the .gpword pseudo-op. This is used when generating PIC
12346 code. It generates a 32 bit GP relative reloc. */
12349 s_gpword (int ignore ATTRIBUTE_UNUSED)
12355 /* When not generating PIC code, this is treated as .word. */
12356 if (mips_pic != SVR4_PIC)
12362 label = insn_labels != NULL ? insn_labels->label : NULL;
12363 mips_emit_delays (TRUE);
12365 mips_align (2, 0, label);
12366 mips_clear_insn_labels ();
12370 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12372 as_bad (_("Unsupported use of .gpword"));
12373 ignore_rest_of_line ();
12377 md_number_to_chars (p, 0, 4);
12378 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12379 BFD_RELOC_GPREL32);
12381 demand_empty_rest_of_line ();
12385 s_gpdword (int ignore ATTRIBUTE_UNUSED)
12391 /* When not generating PIC code, this is treated as .dword. */
12392 if (mips_pic != SVR4_PIC)
12398 label = insn_labels != NULL ? insn_labels->label : NULL;
12399 mips_emit_delays (TRUE);
12401 mips_align (3, 0, label);
12402 mips_clear_insn_labels ();
12406 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12408 as_bad (_("Unsupported use of .gpdword"));
12409 ignore_rest_of_line ();
12413 md_number_to_chars (p, 0, 8);
12414 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12415 BFD_RELOC_GPREL32);
12417 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12418 ex.X_op = O_absent;
12419 ex.X_add_symbol = 0;
12420 ex.X_add_number = 0;
12421 fix_new_exp (frag_now, p - frag_now->fr_literal, 8, &ex, FALSE,
12424 demand_empty_rest_of_line ();
12427 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12428 tables in SVR4 PIC code. */
12431 s_cpadd (int ignore ATTRIBUTE_UNUSED)
12436 /* This is ignored when not generating SVR4 PIC code. */
12437 if (mips_pic != SVR4_PIC)
12443 /* Add $gp to the register named as an argument. */
12444 reg = tc_get_register (0);
12445 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
12446 reg, reg, mips_gp_register);
12448 demand_empty_rest_of_line ();
12451 /* Handle the .insn pseudo-op. This marks instruction labels in
12452 mips16 mode. This permits the linker to handle them specially,
12453 such as generating jalx instructions when needed. We also make
12454 them odd for the duration of the assembly, in order to generate the
12455 right sort of code. We will make them even in the adjust_symtab
12456 routine, while leaving them marked. This is convenient for the
12457 debugger and the disassembler. The linker knows to make them odd
12461 s_insn (int ignore ATTRIBUTE_UNUSED)
12463 mips16_mark_labels ();
12465 demand_empty_rest_of_line ();
12468 /* Handle a .stabn directive. We need these in order to mark a label
12469 as being a mips16 text label correctly. Sometimes the compiler
12470 will emit a label, followed by a .stabn, and then switch sections.
12471 If the label and .stabn are in mips16 mode, then the label is
12472 really a mips16 text label. */
12475 s_mips_stab (int type)
12478 mips16_mark_labels ();
12483 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12487 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
12494 name = input_line_pointer;
12495 c = get_symbol_end ();
12496 symbolP = symbol_find_or_make (name);
12497 S_SET_WEAK (symbolP);
12498 *input_line_pointer = c;
12500 SKIP_WHITESPACE ();
12502 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12504 if (S_IS_DEFINED (symbolP))
12506 as_bad ("ignoring attempt to redefine symbol %s",
12507 S_GET_NAME (symbolP));
12508 ignore_rest_of_line ();
12512 if (*input_line_pointer == ',')
12514 ++input_line_pointer;
12515 SKIP_WHITESPACE ();
12519 if (exp.X_op != O_symbol)
12521 as_bad ("bad .weakext directive");
12522 ignore_rest_of_line ();
12525 symbol_set_value_expression (symbolP, &exp);
12528 demand_empty_rest_of_line ();
12531 /* Parse a register string into a number. Called from the ECOFF code
12532 to parse .frame. The argument is non-zero if this is the frame
12533 register, so that we can record it in mips_frame_reg. */
12536 tc_get_register (int frame)
12540 SKIP_WHITESPACE ();
12541 if (*input_line_pointer++ != '$')
12543 as_warn (_("expected `$'"));
12546 else if (ISDIGIT (*input_line_pointer))
12548 reg = get_absolute_expression ();
12549 if (reg < 0 || reg >= 32)
12551 as_warn (_("Bad register number"));
12557 if (strncmp (input_line_pointer, "ra", 2) == 0)
12560 input_line_pointer += 2;
12562 else if (strncmp (input_line_pointer, "fp", 2) == 0)
12565 input_line_pointer += 2;
12567 else if (strncmp (input_line_pointer, "sp", 2) == 0)
12570 input_line_pointer += 2;
12572 else if (strncmp (input_line_pointer, "gp", 2) == 0)
12575 input_line_pointer += 2;
12577 else if (strncmp (input_line_pointer, "at", 2) == 0)
12580 input_line_pointer += 2;
12582 else if (strncmp (input_line_pointer, "kt0", 3) == 0)
12585 input_line_pointer += 3;
12587 else if (strncmp (input_line_pointer, "kt1", 3) == 0)
12590 input_line_pointer += 3;
12592 else if (strncmp (input_line_pointer, "zero", 4) == 0)
12595 input_line_pointer += 4;
12599 as_warn (_("Unrecognized register name"));
12601 while (ISALNUM(*input_line_pointer))
12602 input_line_pointer++;
12607 mips_frame_reg = reg != 0 ? reg : SP;
12608 mips_frame_reg_valid = 1;
12609 mips_cprestore_valid = 0;
12615 md_section_align (asection *seg, valueT addr)
12617 int align = bfd_get_section_alignment (stdoutput, seg);
12620 /* We don't need to align ELF sections to the full alignment.
12621 However, Irix 5 may prefer that we align them at least to a 16
12622 byte boundary. We don't bother to align the sections if we are
12623 targeted for an embedded system. */
12624 if (strcmp (TARGET_OS, "elf") == 0)
12630 return ((addr + (1 << align) - 1) & (-1 << align));
12633 /* Utility routine, called from above as well. If called while the
12634 input file is still being read, it's only an approximation. (For
12635 example, a symbol may later become defined which appeared to be
12636 undefined earlier.) */
12639 nopic_need_relax (symbolS *sym, int before_relaxing)
12644 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
12646 const char *symname;
12649 /* Find out whether this symbol can be referenced off the $gp
12650 register. It can be if it is smaller than the -G size or if
12651 it is in the .sdata or .sbss section. Certain symbols can
12652 not be referenced off the $gp, although it appears as though
12654 symname = S_GET_NAME (sym);
12655 if (symname != (const char *) NULL
12656 && (strcmp (symname, "eprol") == 0
12657 || strcmp (symname, "etext") == 0
12658 || strcmp (symname, "_gp") == 0
12659 || strcmp (symname, "edata") == 0
12660 || strcmp (symname, "_fbss") == 0
12661 || strcmp (symname, "_fdata") == 0
12662 || strcmp (symname, "_ftext") == 0
12663 || strcmp (symname, "end") == 0
12664 || strcmp (symname, "_gp_disp") == 0))
12666 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12668 #ifndef NO_ECOFF_DEBUGGING
12669 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12670 && (symbol_get_obj (sym)->ecoff_extern_size
12671 <= g_switch_value))
12673 /* We must defer this decision until after the whole
12674 file has been read, since there might be a .extern
12675 after the first use of this symbol. */
12676 || (before_relaxing
12677 #ifndef NO_ECOFF_DEBUGGING
12678 && symbol_get_obj (sym)->ecoff_extern_size == 0
12680 && S_GET_VALUE (sym) == 0)
12681 || (S_GET_VALUE (sym) != 0
12682 && S_GET_VALUE (sym) <= g_switch_value)))
12686 const char *segname;
12688 segname = segment_name (S_GET_SEGMENT (sym));
12689 assert (strcmp (segname, ".lit8") != 0
12690 && strcmp (segname, ".lit4") != 0);
12691 change = (strcmp (segname, ".sdata") != 0
12692 && strcmp (segname, ".sbss") != 0
12693 && strncmp (segname, ".sdata.", 7) != 0
12694 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12699 /* We are not optimizing for the $gp register. */
12704 /* Return true if the given symbol should be considered local for SVR4 PIC. */
12707 pic_need_relax (symbolS *sym, asection *segtype)
12710 bfd_boolean linkonce;
12712 /* Handle the case of a symbol equated to another symbol. */
12713 while (symbol_equated_reloc_p (sym))
12717 /* It's possible to get a loop here in a badly written
12719 n = symbol_get_value_expression (sym)->X_add_symbol;
12725 symsec = S_GET_SEGMENT (sym);
12727 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12729 if (symsec != segtype && ! S_IS_LOCAL (sym))
12731 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12735 /* The GNU toolchain uses an extension for ELF: a section
12736 beginning with the magic string .gnu.linkonce is a linkonce
12738 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12739 sizeof ".gnu.linkonce" - 1) == 0)
12743 /* This must duplicate the test in adjust_reloc_syms. */
12744 return (symsec != &bfd_und_section
12745 && symsec != &bfd_abs_section
12746 && ! bfd_is_com_section (symsec)
12749 /* A global or weak symbol is treated as external. */
12750 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12751 || (! S_IS_WEAK (sym)
12752 && (! S_IS_EXTERNAL (sym)
12753 || mips_pic == EMBEDDED_PIC)))
12759 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12760 extended opcode. SEC is the section the frag is in. */
12763 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
12766 register const struct mips16_immed_operand *op;
12768 int mintiny, maxtiny;
12772 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
12774 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
12777 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12778 op = mips16_immed_operands;
12779 while (op->type != type)
12782 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12787 if (type == '<' || type == '>' || type == '[' || type == ']')
12790 maxtiny = 1 << op->nbits;
12795 maxtiny = (1 << op->nbits) - 1;
12800 mintiny = - (1 << (op->nbits - 1));
12801 maxtiny = (1 << (op->nbits - 1)) - 1;
12804 sym_frag = symbol_get_frag (fragp->fr_symbol);
12805 val = S_GET_VALUE (fragp->fr_symbol);
12806 symsec = S_GET_SEGMENT (fragp->fr_symbol);
12812 /* We won't have the section when we are called from
12813 mips_relax_frag. However, we will always have been called
12814 from md_estimate_size_before_relax first. If this is a
12815 branch to a different section, we mark it as such. If SEC is
12816 NULL, and the frag is not marked, then it must be a branch to
12817 the same section. */
12820 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
12825 /* Must have been called from md_estimate_size_before_relax. */
12828 fragp->fr_subtype =
12829 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12831 /* FIXME: We should support this, and let the linker
12832 catch branches and loads that are out of range. */
12833 as_bad_where (fragp->fr_file, fragp->fr_line,
12834 _("unsupported PC relative reference to different section"));
12838 if (fragp != sym_frag && sym_frag->fr_address == 0)
12839 /* Assume non-extended on the first relaxation pass.
12840 The address we have calculated will be bogus if this is
12841 a forward branch to another frag, as the forward frag
12842 will have fr_address == 0. */
12846 /* In this case, we know for sure that the symbol fragment is in
12847 the same section. If the relax_marker of the symbol fragment
12848 differs from the relax_marker of this fragment, we have not
12849 yet adjusted the symbol fragment fr_address. We want to add
12850 in STRETCH in order to get a better estimate of the address.
12851 This particularly matters because of the shift bits. */
12853 && sym_frag->relax_marker != fragp->relax_marker)
12857 /* Adjust stretch for any alignment frag. Note that if have
12858 been expanding the earlier code, the symbol may be
12859 defined in what appears to be an earlier frag. FIXME:
12860 This doesn't handle the fr_subtype field, which specifies
12861 a maximum number of bytes to skip when doing an
12863 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
12865 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
12868 stretch = - ((- stretch)
12869 & ~ ((1 << (int) f->fr_offset) - 1));
12871 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
12880 addr = fragp->fr_address + fragp->fr_fix;
12882 /* The base address rules are complicated. The base address of
12883 a branch is the following instruction. The base address of a
12884 PC relative load or add is the instruction itself, but if it
12885 is in a delay slot (in which case it can not be extended) use
12886 the address of the instruction whose delay slot it is in. */
12887 if (type == 'p' || type == 'q')
12891 /* If we are currently assuming that this frag should be
12892 extended, then, the current address is two bytes
12894 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12897 /* Ignore the low bit in the target, since it will be set
12898 for a text label. */
12899 if ((val & 1) != 0)
12902 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12904 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12907 val -= addr & ~ ((1 << op->shift) - 1);
12909 /* Branch offsets have an implicit 0 in the lowest bit. */
12910 if (type == 'p' || type == 'q')
12913 /* If any of the shifted bits are set, we must use an extended
12914 opcode. If the address depends on the size of this
12915 instruction, this can lead to a loop, so we arrange to always
12916 use an extended opcode. We only check this when we are in
12917 the main relaxation loop, when SEC is NULL. */
12918 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
12920 fragp->fr_subtype =
12921 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12925 /* If we are about to mark a frag as extended because the value
12926 is precisely maxtiny + 1, then there is a chance of an
12927 infinite loop as in the following code:
12932 In this case when the la is extended, foo is 0x3fc bytes
12933 away, so the la can be shrunk, but then foo is 0x400 away, so
12934 the la must be extended. To avoid this loop, we mark the
12935 frag as extended if it was small, and is about to become
12936 extended with a value of maxtiny + 1. */
12937 if (val == ((maxtiny + 1) << op->shift)
12938 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
12941 fragp->fr_subtype =
12942 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12946 else if (symsec != absolute_section && sec != NULL)
12947 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
12949 if ((val & ((1 << op->shift) - 1)) != 0
12950 || val < (mintiny << op->shift)
12951 || val > (maxtiny << op->shift))
12957 /* Compute the length of a branch sequence, and adjust the
12958 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
12959 worst-case length is computed, with UPDATE being used to indicate
12960 whether an unconditional (-1), branch-likely (+1) or regular (0)
12961 branch is to be computed. */
12963 relaxed_branch_length (fragS *fragp, asection *sec, int update)
12965 bfd_boolean toofar;
12969 && S_IS_DEFINED (fragp->fr_symbol)
12970 && sec == S_GET_SEGMENT (fragp->fr_symbol))
12975 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
12977 addr = fragp->fr_address + fragp->fr_fix + 4;
12981 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
12984 /* If the symbol is not defined or it's in a different segment,
12985 assume the user knows what's going on and emit a short
12991 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
12993 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp->fr_subtype),
12994 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
12995 RELAX_BRANCH_LINK (fragp->fr_subtype),
13001 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
13004 if (mips_pic != NO_PIC)
13006 /* Additional space for PIC loading of target address. */
13008 if (mips_opts.isa == ISA_MIPS1)
13009 /* Additional space for $at-stabilizing nop. */
13013 /* If branch is conditional. */
13014 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
13021 /* Estimate the size of a frag before relaxing. Unless this is the
13022 mips16, we are not really relaxing here, and the final size is
13023 encoded in the subtype information. For the mips16, we have to
13024 decide whether we are using an extended opcode or not. */
13027 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
13031 if (RELAX_BRANCH_P (fragp->fr_subtype))
13034 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
13036 return fragp->fr_var;
13039 if (RELAX_MIPS16_P (fragp->fr_subtype))
13040 /* We don't want to modify the EXTENDED bit here; it might get us
13041 into infinite loops. We change it only in mips_relax_frag(). */
13042 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
13044 if (mips_pic == NO_PIC)
13045 change = nopic_need_relax (fragp->fr_symbol, 0);
13046 else if (mips_pic == SVR4_PIC)
13047 change = pic_need_relax (fragp->fr_symbol, segtype);
13053 /* Record the offset to the first reloc in the fr_opcode field.
13054 This lets md_convert_frag and tc_gen_reloc know that the code
13055 must be expanded. */
13056 fragp->fr_opcode = (fragp->fr_literal
13058 - RELAX_OLD (fragp->fr_subtype)
13059 + RELAX_RELOC1 (fragp->fr_subtype));
13060 /* FIXME: This really needs as_warn_where. */
13061 if (RELAX_WARN (fragp->fr_subtype))
13062 as_warn (_("AT used after \".set noat\" or macro used after "
13063 "\".set nomacro\""));
13065 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
13071 /* This is called to see whether a reloc against a defined symbol
13072 should be converted into a reloc against a section. Don't adjust
13073 MIPS16 jump relocations, so we don't have to worry about the format
13074 of the offset in the .o file. Don't adjust relocations against
13075 mips16 symbols, so that the linker can find them if it needs to set
13079 mips_fix_adjustable (fixS *fixp)
13081 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
13084 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
13085 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13088 if (fixp->fx_addsy == NULL)
13092 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
13093 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
13094 && fixp->fx_subsy == NULL)
13101 /* Translate internal representation of relocation info to BFD target
13105 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
13107 static arelent *retval[4];
13109 bfd_reloc_code_real_type code;
13111 memset (retval, 0, sizeof(retval));
13112 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
13113 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13114 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13115 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13117 if (mips_pic == EMBEDDED_PIC
13118 && SWITCH_TABLE (fixp))
13120 /* For a switch table entry we use a special reloc. The addend
13121 is actually the difference between the reloc address and the
13123 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
13124 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
13125 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
13126 fixp->fx_r_type = BFD_RELOC_GPREL32;
13128 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
13130 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
13131 reloc->addend = fixp->fx_addnumber;
13134 /* We use a special addend for an internal RELLO reloc. */
13135 if (symbol_section_p (fixp->fx_addsy))
13136 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
13138 reloc->addend = fixp->fx_addnumber + reloc->address;
13141 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
13143 assert (fixp->fx_next != NULL
13144 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
13146 /* The reloc is relative to the RELLO; adjust the addend
13148 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
13149 reloc->addend = fixp->fx_next->fx_addnumber;
13152 /* We use a special addend for an internal RELHI reloc. */
13153 if (symbol_section_p (fixp->fx_addsy))
13154 reloc->addend = (fixp->fx_next->fx_frag->fr_address
13155 + fixp->fx_next->fx_where
13156 - S_GET_VALUE (fixp->fx_subsy));
13158 reloc->addend = (fixp->fx_addnumber
13159 + fixp->fx_next->fx_frag->fr_address
13160 + fixp->fx_next->fx_where);
13163 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
13164 reloc->addend = fixp->fx_addnumber;
13167 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
13168 /* A gruesome hack which is a result of the gruesome gas reloc
13170 reloc->addend = reloc->address;
13172 reloc->addend = -reloc->address;
13175 /* If this is a variant frag, we may need to adjust the existing
13176 reloc and generate a new one. */
13177 if (fixp->fx_frag->fr_opcode != NULL
13178 && ((fixp->fx_r_type == BFD_RELOC_GPREL16
13180 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_DISP
13182 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
13183 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
13184 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
13185 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
13186 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
13187 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
13192 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
13194 /* If this is not the last reloc in this frag, then we have two
13195 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
13196 CALL_HI16/CALL_LO16, both of which are being replaced. Let
13197 the second one handle all of them. */
13198 if (fixp->fx_next != NULL
13199 && fixp->fx_frag == fixp->fx_next->fx_frag)
13201 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
13202 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
13203 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
13204 && (fixp->fx_next->fx_r_type
13205 == BFD_RELOC_MIPS_GOT_LO16))
13206 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
13207 && (fixp->fx_next->fx_r_type
13208 == BFD_RELOC_MIPS_CALL_LO16)));
13213 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
13214 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13215 reloc->addend += fixp->fx_frag->tc_frag_data.tc_fr_offset;
13216 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
13217 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13218 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13219 reloc2->address = (reloc->address
13220 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
13221 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
13222 reloc2->addend = fixp->fx_addnumber - S_GET_VALUE (fixp->fx_addsy)
13223 + fixp->fx_frag->tc_frag_data.tc_fr_offset;
13224 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
13225 assert (reloc2->howto != NULL);
13227 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
13231 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
13233 reloc3->address += 4;
13236 if (mips_pic == NO_PIC)
13238 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
13239 fixp->fx_r_type = BFD_RELOC_HI16_S;
13241 else if (mips_pic == SVR4_PIC)
13243 switch (fixp->fx_r_type)
13247 case BFD_RELOC_MIPS_GOT16:
13249 case BFD_RELOC_MIPS_GOT_LO16:
13250 case BFD_RELOC_MIPS_CALL_LO16:
13253 fixp->fx_r_type = BFD_RELOC_MIPS_GOT_PAGE;
13254 reloc2->howto = bfd_reloc_type_lookup
13255 (stdoutput, BFD_RELOC_MIPS_GOT_OFST);
13258 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
13260 case BFD_RELOC_MIPS_CALL16:
13261 case BFD_RELOC_MIPS_GOT_OFST:
13262 case BFD_RELOC_MIPS_GOT_DISP:
13265 /* It may seem nonsensical to relax GOT_DISP to
13266 GOT_DISP, but we're actually turning a GOT_DISP
13267 without offset into a GOT_DISP with an offset,
13268 getting rid of the separate addition, which we can
13269 do when the symbol is found to be local. */
13270 fixp->fx_r_type = BFD_RELOC_MIPS_GOT_DISP;
13274 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
13282 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13283 entry to be used in the relocation's section offset. */
13284 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13286 reloc->address = reloc->addend;
13290 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
13291 fixup_segment converted a non-PC relative reloc into a PC
13292 relative reloc. In such a case, we need to convert the reloc
13294 code = fixp->fx_r_type;
13295 if (fixp->fx_pcrel)
13300 code = BFD_RELOC_8_PCREL;
13303 code = BFD_RELOC_16_PCREL;
13306 code = BFD_RELOC_32_PCREL;
13309 code = BFD_RELOC_64_PCREL;
13311 case BFD_RELOC_8_PCREL:
13312 case BFD_RELOC_16_PCREL:
13313 case BFD_RELOC_32_PCREL:
13314 case BFD_RELOC_64_PCREL:
13315 case BFD_RELOC_16_PCREL_S2:
13316 case BFD_RELOC_PCREL_HI16_S:
13317 case BFD_RELOC_PCREL_LO16:
13320 as_bad_where (fixp->fx_file, fixp->fx_line,
13321 _("Cannot make %s relocation PC relative"),
13322 bfd_get_reloc_code_name (code));
13326 /* To support a PC relative reloc when generating embedded PIC code
13327 for ECOFF, we use a Cygnus extension. We check for that here to
13328 make sure that we don't let such a reloc escape normally. */
13329 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
13330 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
13331 && code == BFD_RELOC_16_PCREL_S2
13332 && mips_pic != EMBEDDED_PIC)
13333 reloc->howto = NULL;
13335 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
13337 if (reloc->howto == NULL)
13339 as_bad_where (fixp->fx_file, fixp->fx_line,
13340 _("Can not represent %s relocation in this object file format"),
13341 bfd_get_reloc_code_name (code));
13348 /* Relax a machine dependent frag. This returns the amount by which
13349 the current size of the frag should change. */
13352 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
13354 if (RELAX_BRANCH_P (fragp->fr_subtype))
13356 offsetT old_var = fragp->fr_var;
13358 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
13360 return fragp->fr_var - old_var;
13363 if (! RELAX_MIPS16_P (fragp->fr_subtype))
13366 if (mips16_extended_frag (fragp, NULL, stretch))
13368 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13370 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
13375 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13377 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
13384 /* Convert a machine dependent frag. */
13387 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
13392 if (RELAX_BRANCH_P (fragp->fr_subtype))
13395 unsigned long insn;
13399 buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
13401 if (target_big_endian)
13402 insn = bfd_getb32 (buf);
13404 insn = bfd_getl32 (buf);
13406 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13408 /* We generate a fixup instead of applying it right now
13409 because, if there are linker relaxations, we're going to
13410 need the relocations. */
13411 exp.X_op = O_symbol;
13412 exp.X_add_symbol = fragp->fr_symbol;
13413 exp.X_add_number = fragp->fr_offset;
13415 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13417 BFD_RELOC_16_PCREL_S2);
13418 fixp->fx_file = fragp->fr_file;
13419 fixp->fx_line = fragp->fr_line;
13421 md_number_to_chars (buf, insn, 4);
13428 as_warn_where (fragp->fr_file, fragp->fr_line,
13429 _("relaxed out-of-range branch into a jump"));
13431 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
13434 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13436 /* Reverse the branch. */
13437 switch ((insn >> 28) & 0xf)
13440 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13441 have the condition reversed by tweaking a single
13442 bit, and their opcodes all have 0x4???????. */
13443 assert ((insn & 0xf1000000) == 0x41000000);
13444 insn ^= 0x00010000;
13448 /* bltz 0x04000000 bgez 0x04010000
13449 bltzal 0x04100000 bgezal 0x04110000 */
13450 assert ((insn & 0xfc0e0000) == 0x04000000);
13451 insn ^= 0x00010000;
13455 /* beq 0x10000000 bne 0x14000000
13456 blez 0x18000000 bgtz 0x1c000000 */
13457 insn ^= 0x04000000;
13465 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13467 /* Clear the and-link bit. */
13468 assert ((insn & 0xfc1c0000) == 0x04100000);
13470 /* bltzal 0x04100000 bgezal 0x04110000
13471 bltzall 0x04120000 bgezall 0x04130000 */
13472 insn &= ~0x00100000;
13475 /* Branch over the branch (if the branch was likely) or the
13476 full jump (not likely case). Compute the offset from the
13477 current instruction to branch to. */
13478 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13482 /* How many bytes in instructions we've already emitted? */
13483 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13484 /* How many bytes in instructions from here to the end? */
13485 i = fragp->fr_var - i;
13487 /* Convert to instruction count. */
13489 /* Branch counts from the next instruction. */
13492 /* Branch over the jump. */
13493 md_number_to_chars (buf, insn, 4);
13497 md_number_to_chars (buf, 0, 4);
13500 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13502 /* beql $0, $0, 2f */
13504 /* Compute the PC offset from the current instruction to
13505 the end of the variable frag. */
13506 /* How many bytes in instructions we've already emitted? */
13507 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13508 /* How many bytes in instructions from here to the end? */
13509 i = fragp->fr_var - i;
13510 /* Convert to instruction count. */
13512 /* Don't decrement i, because we want to branch over the
13516 md_number_to_chars (buf, insn, 4);
13519 md_number_to_chars (buf, 0, 4);
13524 if (mips_pic == NO_PIC)
13527 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
13528 ? 0x0c000000 : 0x08000000);
13529 exp.X_op = O_symbol;
13530 exp.X_add_symbol = fragp->fr_symbol;
13531 exp.X_add_number = fragp->fr_offset;
13533 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13534 4, &exp, 0, BFD_RELOC_MIPS_JMP);
13535 fixp->fx_file = fragp->fr_file;
13536 fixp->fx_line = fragp->fr_line;
13538 md_number_to_chars (buf, insn, 4);
13543 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13544 insn = HAVE_64BIT_ADDRESSES ? 0xdf810000 : 0x8f810000;
13545 exp.X_op = O_symbol;
13546 exp.X_add_symbol = fragp->fr_symbol;
13547 exp.X_add_number = fragp->fr_offset;
13549 if (fragp->fr_offset)
13551 exp.X_add_symbol = make_expr_symbol (&exp);
13552 exp.X_add_number = 0;
13555 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13556 4, &exp, 0, BFD_RELOC_MIPS_GOT16);
13557 fixp->fx_file = fragp->fr_file;
13558 fixp->fx_line = fragp->fr_line;
13560 md_number_to_chars (buf, insn, 4);
13563 if (mips_opts.isa == ISA_MIPS1)
13566 md_number_to_chars (buf, 0, 4);
13570 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
13571 insn = HAVE_64BIT_ADDRESSES ? 0x64210000 : 0x24210000;
13573 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13574 4, &exp, 0, BFD_RELOC_LO16);
13575 fixp->fx_file = fragp->fr_file;
13576 fixp->fx_line = fragp->fr_line;
13578 md_number_to_chars (buf, insn, 4);
13582 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13587 md_number_to_chars (buf, insn, 4);
13592 assert (buf == (bfd_byte *)fragp->fr_literal
13593 + fragp->fr_fix + fragp->fr_var);
13595 fragp->fr_fix += fragp->fr_var;
13600 if (RELAX_MIPS16_P (fragp->fr_subtype))
13603 register const struct mips16_immed_operand *op;
13604 bfd_boolean small, ext;
13607 unsigned long insn;
13608 bfd_boolean use_extend;
13609 unsigned short extend;
13611 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13612 op = mips16_immed_operands;
13613 while (op->type != type)
13616 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13627 resolve_symbol_value (fragp->fr_symbol);
13628 val = S_GET_VALUE (fragp->fr_symbol);
13633 addr = fragp->fr_address + fragp->fr_fix;
13635 /* The rules for the base address of a PC relative reloc are
13636 complicated; see mips16_extended_frag. */
13637 if (type == 'p' || type == 'q')
13642 /* Ignore the low bit in the target, since it will be
13643 set for a text label. */
13644 if ((val & 1) != 0)
13647 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13649 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13652 addr &= ~ (addressT) ((1 << op->shift) - 1);
13655 /* Make sure the section winds up with the alignment we have
13658 record_alignment (asec, op->shift);
13662 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
13663 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
13664 as_warn_where (fragp->fr_file, fragp->fr_line,
13665 _("extended instruction in delay slot"));
13667 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
13669 if (target_big_endian)
13670 insn = bfd_getb16 (buf);
13672 insn = bfd_getl16 (buf);
13674 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
13675 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
13676 small, ext, &insn, &use_extend, &extend);
13680 md_number_to_chars (buf, 0xf000 | extend, 2);
13681 fragp->fr_fix += 2;
13685 md_number_to_chars (buf, insn, 2);
13686 fragp->fr_fix += 2;
13691 if (fragp->fr_opcode == NULL)
13694 old = RELAX_OLD (fragp->fr_subtype);
13695 new = RELAX_NEW (fragp->fr_subtype);
13696 fixptr = fragp->fr_literal + fragp->fr_fix;
13699 memmove (fixptr - old, fixptr, new);
13701 fragp->fr_fix += new - old;
13707 /* This function is called after the relocs have been generated.
13708 We've been storing mips16 text labels as odd. Here we convert them
13709 back to even for the convenience of the debugger. */
13712 mips_frob_file_after_relocs (void)
13715 unsigned int count, i;
13717 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
13720 syms = bfd_get_outsymbols (stdoutput);
13721 count = bfd_get_symcount (stdoutput);
13722 for (i = 0; i < count; i++, syms++)
13724 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
13725 && ((*syms)->value & 1) != 0)
13727 (*syms)->value &= ~1;
13728 /* If the symbol has an odd size, it was probably computed
13729 incorrectly, so adjust that as well. */
13730 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
13731 ++elf_symbol (*syms)->internal_elf_sym.st_size;
13738 /* This function is called whenever a label is defined. It is used
13739 when handling branch delays; if a branch has a label, we assume we
13740 can not move it. */
13743 mips_define_label (symbolS *sym)
13745 struct insn_label_list *l;
13747 if (free_insn_labels == NULL)
13748 l = (struct insn_label_list *) xmalloc (sizeof *l);
13751 l = free_insn_labels;
13752 free_insn_labels = l->next;
13756 l->next = insn_labels;
13760 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13762 /* Some special processing for a MIPS ELF file. */
13765 mips_elf_final_processing (void)
13767 /* Write out the register information. */
13768 if (mips_abi != N64_ABI)
13772 s.ri_gprmask = mips_gprmask;
13773 s.ri_cprmask[0] = mips_cprmask[0];
13774 s.ri_cprmask[1] = mips_cprmask[1];
13775 s.ri_cprmask[2] = mips_cprmask[2];
13776 s.ri_cprmask[3] = mips_cprmask[3];
13777 /* The gp_value field is set by the MIPS ELF backend. */
13779 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
13780 ((Elf32_External_RegInfo *)
13781 mips_regmask_frag));
13785 Elf64_Internal_RegInfo s;
13787 s.ri_gprmask = mips_gprmask;
13789 s.ri_cprmask[0] = mips_cprmask[0];
13790 s.ri_cprmask[1] = mips_cprmask[1];
13791 s.ri_cprmask[2] = mips_cprmask[2];
13792 s.ri_cprmask[3] = mips_cprmask[3];
13793 /* The gp_value field is set by the MIPS ELF backend. */
13795 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
13796 ((Elf64_External_RegInfo *)
13797 mips_regmask_frag));
13800 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13801 sort of BFD interface for this. */
13802 if (mips_any_noreorder)
13803 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
13804 if (mips_pic != NO_PIC)
13806 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
13807 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
13810 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
13812 /* Set MIPS ELF flags for ASEs. */
13813 if (file_ase_mips16)
13814 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
13815 #if 0 /* XXX FIXME */
13816 if (file_ase_mips3d)
13817 elf_elfheader (stdoutput)->e_flags |= ???;
13820 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
13822 /* Set the MIPS ELF ABI flags. */
13823 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
13824 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
13825 else if (mips_abi == O64_ABI)
13826 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
13827 else if (mips_abi == EABI_ABI)
13829 if (!file_mips_gp32)
13830 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
13832 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
13834 else if (mips_abi == N32_ABI)
13835 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
13837 /* Nothing to do for N64_ABI. */
13839 if (mips_32bitmode)
13840 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
13843 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
13845 typedef struct proc {
13847 unsigned long reg_mask;
13848 unsigned long reg_offset;
13849 unsigned long fpreg_mask;
13850 unsigned long fpreg_offset;
13851 unsigned long frame_offset;
13852 unsigned long frame_reg;
13853 unsigned long pc_reg;
13856 static procS cur_proc;
13857 static procS *cur_proc_ptr;
13858 static int numprocs;
13860 /* Fill in an rs_align_code fragment. */
13863 mips_handle_align (fragS *fragp)
13865 if (fragp->fr_type != rs_align_code)
13868 if (mips_opts.mips16)
13870 static const unsigned char be_nop[] = { 0x65, 0x00 };
13871 static const unsigned char le_nop[] = { 0x00, 0x65 };
13876 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
13877 p = fragp->fr_literal + fragp->fr_fix;
13885 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
13889 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
13893 md_obj_begin (void)
13900 /* check for premature end, nesting errors, etc */
13902 as_warn (_("missing .end at end of assembly"));
13911 if (*input_line_pointer == '-')
13913 ++input_line_pointer;
13916 if (!ISDIGIT (*input_line_pointer))
13917 as_bad (_("expected simple number"));
13918 if (input_line_pointer[0] == '0')
13920 if (input_line_pointer[1] == 'x')
13922 input_line_pointer += 2;
13923 while (ISXDIGIT (*input_line_pointer))
13926 val |= hex_value (*input_line_pointer++);
13928 return negative ? -val : val;
13932 ++input_line_pointer;
13933 while (ISDIGIT (*input_line_pointer))
13936 val |= *input_line_pointer++ - '0';
13938 return negative ? -val : val;
13941 if (!ISDIGIT (*input_line_pointer))
13943 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13944 *input_line_pointer, *input_line_pointer);
13945 as_warn (_("invalid number"));
13948 while (ISDIGIT (*input_line_pointer))
13951 val += *input_line_pointer++ - '0';
13953 return negative ? -val : val;
13956 /* The .file directive; just like the usual .file directive, but there
13957 is an initial number which is the ECOFF file index. In the non-ECOFF
13958 case .file implies DWARF-2. */
13961 s_mips_file (int x ATTRIBUTE_UNUSED)
13963 static int first_file_directive = 0;
13965 if (ECOFF_DEBUGGING)
13974 filename = dwarf2_directive_file (0);
13976 /* Versions of GCC up to 3.1 start files with a ".file"
13977 directive even for stabs output. Make sure that this
13978 ".file" is handled. Note that you need a version of GCC
13979 after 3.1 in order to support DWARF-2 on MIPS. */
13980 if (filename != NULL && ! first_file_directive)
13982 (void) new_logical_line (filename, -1);
13983 s_app_file_string (filename);
13985 first_file_directive = 1;
13989 /* The .loc directive, implying DWARF-2. */
13992 s_mips_loc (int x ATTRIBUTE_UNUSED)
13994 if (!ECOFF_DEBUGGING)
13995 dwarf2_directive_loc (0);
13998 /* The .end directive. */
14001 s_mips_end (int x ATTRIBUTE_UNUSED)
14005 /* Following functions need their own .frame and .cprestore directives. */
14006 mips_frame_reg_valid = 0;
14007 mips_cprestore_valid = 0;
14009 if (!is_end_of_line[(unsigned char) *input_line_pointer])
14012 demand_empty_rest_of_line ();
14017 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14018 as_warn (_(".end not in text section"));
14022 as_warn (_(".end directive without a preceding .ent directive."));
14023 demand_empty_rest_of_line ();
14029 assert (S_GET_NAME (p));
14030 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
14031 as_warn (_(".end symbol does not match .ent symbol."));
14033 if (debug_type == DEBUG_STABS)
14034 stabs_generate_asm_endfunc (S_GET_NAME (p),
14038 as_warn (_(".end directive missing or unknown symbol"));
14041 /* Generate a .pdr section. */
14042 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14044 segT saved_seg = now_seg;
14045 subsegT saved_subseg = now_subseg;
14050 dot = frag_now_fix ();
14052 #ifdef md_flush_pending_output
14053 md_flush_pending_output ();
14057 subseg_set (pdr_seg, 0);
14059 /* Write the symbol. */
14060 exp.X_op = O_symbol;
14061 exp.X_add_symbol = p;
14062 exp.X_add_number = 0;
14063 emit_expr (&exp, 4);
14065 fragp = frag_more (7 * 4);
14067 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
14068 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
14069 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
14070 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
14071 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
14072 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
14073 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
14075 subseg_set (saved_seg, saved_subseg);
14077 #endif /* OBJ_ELF */
14079 cur_proc_ptr = NULL;
14082 /* The .aent and .ent directives. */
14085 s_mips_ent (int aent)
14089 symbolP = get_symbol ();
14090 if (*input_line_pointer == ',')
14091 ++input_line_pointer;
14092 SKIP_WHITESPACE ();
14093 if (ISDIGIT (*input_line_pointer)
14094 || *input_line_pointer == '-')
14097 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14098 as_warn (_(".ent or .aent not in text section."));
14100 if (!aent && cur_proc_ptr)
14101 as_warn (_("missing .end"));
14105 /* This function needs its own .frame and .cprestore directives. */
14106 mips_frame_reg_valid = 0;
14107 mips_cprestore_valid = 0;
14109 cur_proc_ptr = &cur_proc;
14110 memset (cur_proc_ptr, '\0', sizeof (procS));
14112 cur_proc_ptr->isym = symbolP;
14114 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
14118 if (debug_type == DEBUG_STABS)
14119 stabs_generate_asm_func (S_GET_NAME (symbolP),
14120 S_GET_NAME (symbolP));
14123 demand_empty_rest_of_line ();
14126 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
14127 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
14128 s_mips_frame is used so that we can set the PDR information correctly.
14129 We can't use the ecoff routines because they make reference to the ecoff
14130 symbol table (in the mdebug section). */
14133 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
14136 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14140 if (cur_proc_ptr == (procS *) NULL)
14142 as_warn (_(".frame outside of .ent"));
14143 demand_empty_rest_of_line ();
14147 cur_proc_ptr->frame_reg = tc_get_register (1);
14149 SKIP_WHITESPACE ();
14150 if (*input_line_pointer++ != ','
14151 || get_absolute_expression_and_terminator (&val) != ',')
14153 as_warn (_("Bad .frame directive"));
14154 --input_line_pointer;
14155 demand_empty_rest_of_line ();
14159 cur_proc_ptr->frame_offset = val;
14160 cur_proc_ptr->pc_reg = tc_get_register (0);
14162 demand_empty_rest_of_line ();
14165 #endif /* OBJ_ELF */
14169 /* The .fmask and .mask directives. If the mdebug section is present
14170 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14171 embedded targets, s_mips_mask is used so that we can set the PDR
14172 information correctly. We can't use the ecoff routines because they
14173 make reference to the ecoff symbol table (in the mdebug section). */
14176 s_mips_mask (int reg_type)
14179 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14183 if (cur_proc_ptr == (procS *) NULL)
14185 as_warn (_(".mask/.fmask outside of .ent"));
14186 demand_empty_rest_of_line ();
14190 if (get_absolute_expression_and_terminator (&mask) != ',')
14192 as_warn (_("Bad .mask/.fmask directive"));
14193 --input_line_pointer;
14194 demand_empty_rest_of_line ();
14198 off = get_absolute_expression ();
14200 if (reg_type == 'F')
14202 cur_proc_ptr->fpreg_mask = mask;
14203 cur_proc_ptr->fpreg_offset = off;
14207 cur_proc_ptr->reg_mask = mask;
14208 cur_proc_ptr->reg_offset = off;
14211 demand_empty_rest_of_line ();
14214 #endif /* OBJ_ELF */
14215 s_ignore (reg_type);
14218 /* The .loc directive. */
14228 assert (now_seg == text_section);
14230 lineno = get_number ();
14231 addroff = frag_now_fix ();
14233 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
14234 S_SET_TYPE (symbolP, N_SLINE);
14235 S_SET_OTHER (symbolP, 0);
14236 S_SET_DESC (symbolP, lineno);
14237 symbolP->sy_segment = now_seg;
14241 /* A table describing all the processors gas knows about. Names are
14242 matched in the order listed.
14244 To ease comparison, please keep this table in the same order as
14245 gcc's mips_cpu_info_table[]. */
14246 static const struct mips_cpu_info mips_cpu_info_table[] =
14248 /* Entries for generic ISAs */
14249 { "mips1", 1, ISA_MIPS1, CPU_R3000 },
14250 { "mips2", 1, ISA_MIPS2, CPU_R6000 },
14251 { "mips3", 1, ISA_MIPS3, CPU_R4000 },
14252 { "mips4", 1, ISA_MIPS4, CPU_R8000 },
14253 { "mips5", 1, ISA_MIPS5, CPU_MIPS5 },
14254 { "mips32", 1, ISA_MIPS32, CPU_MIPS32 },
14255 { "mips32r2", 1, ISA_MIPS32R2, CPU_MIPS32R2 },
14256 { "mips64", 1, ISA_MIPS64, CPU_MIPS64 },
14259 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
14260 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
14261 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
14264 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
14267 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
14268 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
14269 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
14270 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
14271 { "vr4120", 0, ISA_MIPS3, CPU_VR4120 },
14272 { "vr4130", 0, ISA_MIPS3, CPU_VR4120 },
14273 { "vr4181", 0, ISA_MIPS3, CPU_R4111 },
14274 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
14275 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
14276 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
14277 { "orion", 0, ISA_MIPS3, CPU_R4600 },
14278 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
14281 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
14282 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
14283 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
14284 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
14285 { "vr5400", 0, ISA_MIPS4, CPU_VR5400 },
14286 { "vr5500", 0, ISA_MIPS4, CPU_VR5500 },
14287 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
14288 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
14289 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
14290 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
14291 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
14292 { "r7000", 0, ISA_MIPS4, CPU_R5000 },
14295 { "4kc", 0, ISA_MIPS32, CPU_MIPS32 },
14296 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
14297 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
14300 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
14301 { "20kc", 0, ISA_MIPS64, CPU_MIPS64 },
14303 /* Broadcom SB-1 CPU core */
14304 { "sb1", 0, ISA_MIPS64, CPU_SB1 },
14311 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14312 with a final "000" replaced by "k". Ignore case.
14314 Note: this function is shared between GCC and GAS. */
14317 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
14319 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
14320 given++, canonical++;
14322 return ((*given == 0 && *canonical == 0)
14323 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
14327 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14328 CPU name. We've traditionally allowed a lot of variation here.
14330 Note: this function is shared between GCC and GAS. */
14333 mips_matching_cpu_name_p (const char *canonical, const char *given)
14335 /* First see if the name matches exactly, or with a final "000"
14336 turned into "k". */
14337 if (mips_strict_matching_cpu_name_p (canonical, given))
14340 /* If not, try comparing based on numerical designation alone.
14341 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14342 if (TOLOWER (*given) == 'r')
14344 if (!ISDIGIT (*given))
14347 /* Skip over some well-known prefixes in the canonical name,
14348 hoping to find a number there too. */
14349 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
14351 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
14353 else if (TOLOWER (canonical[0]) == 'r')
14356 return mips_strict_matching_cpu_name_p (canonical, given);
14360 /* Parse an option that takes the name of a processor as its argument.
14361 OPTION is the name of the option and CPU_STRING is the argument.
14362 Return the corresponding processor enumeration if the CPU_STRING is
14363 recognized, otherwise report an error and return null.
14365 A similar function exists in GCC. */
14367 static const struct mips_cpu_info *
14368 mips_parse_cpu (const char *option, const char *cpu_string)
14370 const struct mips_cpu_info *p;
14372 /* 'from-abi' selects the most compatible architecture for the given
14373 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14374 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14375 version. Look first at the -mgp options, if given, otherwise base
14376 the choice on MIPS_DEFAULT_64BIT.
14378 Treat NO_ABI like the EABIs. One reason to do this is that the
14379 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14380 architecture. This code picks MIPS I for 'mips' and MIPS III for
14381 'mips64', just as we did in the days before 'from-abi'. */
14382 if (strcasecmp (cpu_string, "from-abi") == 0)
14384 if (ABI_NEEDS_32BIT_REGS (mips_abi))
14385 return mips_cpu_info_from_isa (ISA_MIPS1);
14387 if (ABI_NEEDS_64BIT_REGS (mips_abi))
14388 return mips_cpu_info_from_isa (ISA_MIPS3);
14390 if (file_mips_gp32 >= 0)
14391 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
14393 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14398 /* 'default' has traditionally been a no-op. Probably not very useful. */
14399 if (strcasecmp (cpu_string, "default") == 0)
14402 for (p = mips_cpu_info_table; p->name != 0; p++)
14403 if (mips_matching_cpu_name_p (p->name, cpu_string))
14406 as_bad ("Bad value (%s) for %s", cpu_string, option);
14410 /* Return the canonical processor information for ISA (a member of the
14411 ISA_MIPS* enumeration). */
14413 static const struct mips_cpu_info *
14414 mips_cpu_info_from_isa (int isa)
14418 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14419 if (mips_cpu_info_table[i].is_isa
14420 && isa == mips_cpu_info_table[i].isa)
14421 return (&mips_cpu_info_table[i]);
14426 static const struct mips_cpu_info *
14427 mips_cpu_info_from_arch (int arch)
14431 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14432 if (arch == mips_cpu_info_table[i].cpu)
14433 return (&mips_cpu_info_table[i]);
14439 show (FILE *stream, const char *string, int *col_p, int *first_p)
14443 fprintf (stream, "%24s", "");
14448 fprintf (stream, ", ");
14452 if (*col_p + strlen (string) > 72)
14454 fprintf (stream, "\n%24s", "");
14458 fprintf (stream, "%s", string);
14459 *col_p += strlen (string);
14465 md_show_usage (FILE *stream)
14470 fprintf (stream, _("\
14472 -membedded-pic generate embedded position independent code\n\
14473 -EB generate big endian output\n\
14474 -EL generate little endian output\n\
14475 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14476 -G NUM allow referencing objects up to NUM bytes\n\
14477 implicitly with the gp register [default 8]\n"));
14478 fprintf (stream, _("\
14479 -mips1 generate MIPS ISA I instructions\n\
14480 -mips2 generate MIPS ISA II instructions\n\
14481 -mips3 generate MIPS ISA III instructions\n\
14482 -mips4 generate MIPS ISA IV instructions\n\
14483 -mips5 generate MIPS ISA V instructions\n\
14484 -mips32 generate MIPS32 ISA instructions\n\
14485 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
14486 -mips64 generate MIPS64 ISA instructions\n\
14487 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14491 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14492 show (stream, mips_cpu_info_table[i].name, &column, &first);
14493 show (stream, "from-abi", &column, &first);
14494 fputc ('\n', stream);
14496 fprintf (stream, _("\
14497 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14498 -no-mCPU don't generate code specific to CPU.\n\
14499 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14503 show (stream, "3900", &column, &first);
14504 show (stream, "4010", &column, &first);
14505 show (stream, "4100", &column, &first);
14506 show (stream, "4650", &column, &first);
14507 fputc ('\n', stream);
14509 fprintf (stream, _("\
14510 -mips16 generate mips16 instructions\n\
14511 -no-mips16 do not generate mips16 instructions\n"));
14512 fprintf (stream, _("\
14513 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14514 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14515 -O0 remove unneeded NOPs, do not swap branches\n\
14516 -O remove unneeded NOPs and swap branches\n\
14517 -n warn about NOPs generated from macros\n\
14518 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14519 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14520 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14522 fprintf (stream, _("\
14523 -KPIC, -call_shared generate SVR4 position independent code\n\
14524 -non_shared do not generate position independent code\n\
14525 -xgot assume a 32 bit GOT\n\
14526 -mabi=ABI create ABI conformant object file for:\n"));
14530 show (stream, "32", &column, &first);
14531 show (stream, "o64", &column, &first);
14532 show (stream, "n32", &column, &first);
14533 show (stream, "64", &column, &first);
14534 show (stream, "eabi", &column, &first);
14536 fputc ('\n', stream);
14538 fprintf (stream, _("\
14539 -32 create o32 ABI object file (default)\n\
14540 -n32 create n32 ABI object file\n\
14541 -64 create 64 ABI object file\n"));
14546 mips_dwarf2_format (void)
14548 if (mips_abi == N64_ABI)
14551 return dwarf2_format_64bit_irix;
14553 return dwarf2_format_64bit;
14557 return dwarf2_format_32bit;