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"
38 #include "opcode/mips.h"
40 #include "dwarf2dbg.h"
43 #define DBG(x) printf x
49 /* Clean up namespace so we can include obj-elf.h too. */
50 static int mips_output_flavor PARAMS ((void));
51 static int mips_output_flavor () { return OUTPUT_FLAVOR; }
52 #undef OBJ_PROCESS_STAB
59 #undef obj_frob_file_after_relocs
60 #undef obj_frob_symbol
62 #undef obj_sec_sym_ok_for_reloc
63 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
66 /* Fix any of them that we actually care about. */
68 #define OUTPUT_FLAVOR mips_output_flavor()
75 #ifndef ECOFF_DEBUGGING
76 #define NO_ECOFF_DEBUGGING
77 #define ECOFF_DEBUGGING 0
80 int mips_flag_mdebug = -1;
84 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
85 static char *mips_regmask_frag;
91 #define PIC_CALL_REG 25
99 #define ILLEGAL_REG (32)
101 /* Allow override of standard little-endian ECOFF format. */
103 #ifndef ECOFF_LITTLE_FORMAT
104 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
107 extern int target_big_endian;
109 /* The name of the readonly data section. */
110 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
112 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
114 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
116 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
120 /* The ABI to use. */
131 /* MIPS ABI we are using for this output file. */
132 static enum mips_abi_level mips_abi = NO_ABI;
134 /* Whether or not we have code that can call pic code. */
135 int mips_abicalls = FALSE;
137 /* This is the set of options which may be modified by the .set
138 pseudo-op. We use a struct so that .set push and .set pop are more
141 struct mips_set_options
143 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
144 if it has not been initialized. Changed by `.set mipsN', and the
145 -mipsN command line option, and the default CPU. */
147 /* Enabled Application Specific Extensions (ASEs). These are set to -1
148 if they have not been initialized. Changed by `.set <asename>', by
149 command line options, and based on the default architecture. */
152 /* Whether we are assembling for the mips16 processor. 0 if we are
153 not, 1 if we are, and -1 if the value has not been initialized.
154 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
155 -nomips16 command line options, and the default CPU. */
157 /* Non-zero if we should not reorder instructions. Changed by `.set
158 reorder' and `.set noreorder'. */
160 /* Non-zero if we should not permit the $at ($1) register to be used
161 in instructions. Changed by `.set at' and `.set noat'. */
163 /* Non-zero if we should warn when a macro instruction expands into
164 more than one machine instruction. Changed by `.set nomacro' and
166 int warn_about_macros;
167 /* Non-zero if we should not move instructions. Changed by `.set
168 move', `.set volatile', `.set nomove', and `.set novolatile'. */
170 /* Non-zero if we should not optimize branches by moving the target
171 of the branch into the delay slot. Actually, we don't perform
172 this optimization anyhow. Changed by `.set bopt' and `.set
175 /* Non-zero if we should not autoextend mips16 instructions.
176 Changed by `.set autoextend' and `.set noautoextend'. */
178 /* Restrict general purpose registers and floating point registers
179 to 32 bit. This is initially determined when -mgp32 or -mfp32
180 is passed but can changed if the assembler code uses .set mipsN. */
185 /* True if -mgp32 was passed. */
186 static int file_mips_gp32 = -1;
188 /* True if -mfp32 was passed. */
189 static int file_mips_fp32 = -1;
191 /* This is the struct we use to hold the current set of options. Note
192 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
193 -1 to indicate that they have not been initialized. */
195 static struct mips_set_options mips_opts =
197 ISA_UNKNOWN, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0
200 /* These variables are filled in with the masks of registers used.
201 The object format code reads them and puts them in the appropriate
203 unsigned long mips_gprmask;
204 unsigned long mips_cprmask[4];
206 /* MIPS ISA we are using for this output file. */
207 static int file_mips_isa = ISA_UNKNOWN;
209 /* True if -mips16 was passed or implied by arguments passed on the
210 command line (e.g., by -march). */
211 static int file_ase_mips16;
213 /* True if -mips3d was passed or implied by arguments passed on the
214 command line (e.g., by -march). */
215 static int file_ase_mips3d;
217 /* True if -mdmx was passed or implied by arguments passed on the
218 command line (e.g., by -march). */
219 static int file_ase_mdmx;
221 /* The argument of the -march= flag. The architecture we are assembling. */
222 static int mips_arch = CPU_UNKNOWN;
223 static const char *mips_arch_string;
224 static const struct mips_cpu_info *mips_arch_info;
226 /* The argument of the -mtune= flag. The architecture for which we
228 static int mips_tune = CPU_UNKNOWN;
229 static const char *mips_tune_string;
230 static const struct mips_cpu_info *mips_tune_info;
232 /* True when generating 32-bit code for a 64-bit processor. */
233 static int mips_32bitmode = 0;
235 /* Some ISA's have delay slots for instructions which read or write
236 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
237 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
238 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
239 delay slot in this ISA. The uses of this macro assume that any
240 ISA that has delay slots for one of these, has them for all. They
241 also assume that ISAs which don't have delays for these insns, don't
242 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
243 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
245 || (ISA) == ISA_MIPS2 \
246 || (ISA) == ISA_MIPS3 \
249 /* True if the given ABI requires 32-bit registers. */
250 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
252 /* Likewise 64-bit registers. */
253 #define ABI_NEEDS_64BIT_REGS(ABI) \
255 || (ABI) == N64_ABI \
258 /* Return true if ISA supports 64 bit gp register instructions. */
259 #define ISA_HAS_64BIT_REGS(ISA) ( \
261 || (ISA) == ISA_MIPS4 \
262 || (ISA) == ISA_MIPS5 \
263 || (ISA) == ISA_MIPS64 \
266 /* Return true if ISA supports 64-bit right rotate (dror et al.)
268 #define ISA_HAS_DROR(ISA) ( \
272 /* Return true if ISA supports 32-bit right rotate (ror et al.)
274 #define ISA_HAS_ROR(ISA) ( \
275 (ISA) == ISA_MIPS32R2 \
278 #define HAVE_32BIT_GPRS \
279 (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
281 #define HAVE_32BIT_FPRS \
282 (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
284 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
285 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
287 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
289 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
291 /* We can only have 64bit addresses if the object file format
293 #define HAVE_32BIT_ADDRESSES \
295 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
296 || ! HAVE_64BIT_OBJECTS) \
297 && mips_pic != EMBEDDED_PIC))
299 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
300 #define HAVE_64BIT_ADDRESS_CONSTANTS (HAVE_64BIT_ADDRESSES \
303 /* Addresses are loaded in different ways, depending on the address
304 size in use and the ABI. N32_ABI uses additions with overflow
305 checking, this allows to catch code generation errors which would
306 distort the proper sign extension of the 64-bit wide registers. */
307 #define ADDRESS_ADD_INSN \
308 (HAVE_32BIT_ADDRESSES ? (HAVE_NEWABI ? "add" : "addu") : "daddu")
310 #define ADDRESS_ADDI_INSN \
311 (HAVE_32BIT_ADDRESSES ? (HAVE_NEWABI ? "addi" : "addiu") : "daddiu")
313 #define ADDRESS_LOAD_INSN \
314 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
316 #define ADDRESS_STORE_INSN \
317 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
319 /* Return true if the given CPU supports the MIPS16 ASE. */
320 #define CPU_HAS_MIPS16(cpu) \
321 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
322 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
324 /* Return true if the given CPU supports the MIPS3D ASE. */
325 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
328 /* Return true if the given CPU supports the MDMX ASE. */
329 #define CPU_HAS_MDMX(cpu) (FALSE \
332 /* True if CPU has a dror instruction. */
333 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
335 /* True if CPU has a ror instruction. */
336 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
338 /* Whether the processor uses hardware interlocks to protect
339 reads from the HI and LO registers, and thus does not
340 require nops to be inserted. */
342 #define hilo_interlocks (mips_arch == CPU_R4010 \
343 || mips_arch == CPU_VR5500 \
344 || mips_arch == CPU_SB1 \
347 /* Whether the processor uses hardware interlocks to protect reads
348 from the GPRs, and thus does not require nops to be inserted. */
349 #define gpr_interlocks \
350 (mips_opts.isa != ISA_MIPS1 \
351 || mips_arch == CPU_VR5400 \
352 || mips_arch == CPU_VR5500 \
353 || mips_arch == CPU_R3900)
355 /* As with other "interlocks" this is used by hardware that has FP
356 (co-processor) interlocks. */
357 /* Itbl support may require additional care here. */
358 #define cop_interlocks (mips_arch == CPU_R4300 \
359 || mips_arch == CPU_VR5400 \
360 || mips_arch == CPU_VR5500 \
361 || mips_arch == CPU_SB1 \
364 /* Is this a mfhi or mflo instruction? */
365 #define MF_HILO_INSN(PINFO) \
366 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
368 /* MIPS PIC level. */
370 enum mips_pic_level mips_pic;
372 /* Warn about all NOPS that the assembler generates. */
373 static int warn_nops = 0;
375 /* 1 if we should generate 32 bit offsets from the $gp register in
376 SVR4_PIC mode. Currently has no meaning in other modes. */
377 static int mips_big_got = 0;
379 /* 1 if trap instructions should used for overflow rather than break
381 static int mips_trap = 0;
383 /* 1 if double width floating point constants should not be constructed
384 by assembling two single width halves into two single width floating
385 point registers which just happen to alias the double width destination
386 register. On some architectures this aliasing can be disabled by a bit
387 in the status register, and the setting of this bit cannot be determined
388 automatically at assemble time. */
389 static int mips_disable_float_construction;
391 /* Non-zero if any .set noreorder directives were used. */
393 static int mips_any_noreorder;
395 /* Non-zero if nops should be inserted when the register referenced in
396 an mfhi/mflo instruction is read in the next two instructions. */
397 static int mips_7000_hilo_fix;
399 /* The size of the small data section. */
400 static unsigned int g_switch_value = 8;
401 /* Whether the -G option was used. */
402 static int g_switch_seen = 0;
407 /* If we can determine in advance that GP optimization won't be
408 possible, we can skip the relaxation stuff that tries to produce
409 GP-relative references. This makes delay slot optimization work
412 This function can only provide a guess, but it seems to work for
413 gcc output. It needs to guess right for gcc, otherwise gcc
414 will put what it thinks is a GP-relative instruction in a branch
417 I don't know if a fix is needed for the SVR4_PIC mode. I've only
418 fixed it for the non-PIC mode. KR 95/04/07 */
419 static int nopic_need_relax PARAMS ((symbolS *, int));
421 /* handle of the OPCODE hash table */
422 static struct hash_control *op_hash = NULL;
424 /* The opcode hash table we use for the mips16. */
425 static struct hash_control *mips16_op_hash = NULL;
427 /* This array holds the chars that always start a comment. If the
428 pre-processor is disabled, these aren't very useful */
429 const char comment_chars[] = "#";
431 /* This array holds the chars that only start a comment at the beginning of
432 a line. If the line seems to have the form '# 123 filename'
433 .line and .file directives will appear in the pre-processed output */
434 /* Note that input_file.c hand checks for '#' at the beginning of the
435 first line of the input file. This is because the compiler outputs
436 #NO_APP at the beginning of its output. */
437 /* Also note that C style comments are always supported. */
438 const char line_comment_chars[] = "#";
440 /* This array holds machine specific line separator characters. */
441 const char line_separator_chars[] = ";";
443 /* Chars that can be used to separate mant from exp in floating point nums */
444 const char EXP_CHARS[] = "eE";
446 /* Chars that mean this number is a floating point constant */
449 const char FLT_CHARS[] = "rRsSfFdDxXpP";
451 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
452 changed in read.c . Ideally it shouldn't have to know about it at all,
453 but nothing is ideal around here.
456 static char *insn_error;
458 static int auto_align = 1;
460 /* When outputting SVR4 PIC code, the assembler needs to know the
461 offset in the stack frame from which to restore the $gp register.
462 This is set by the .cprestore pseudo-op, and saved in this
464 static offsetT mips_cprestore_offset = -1;
466 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
467 more optimizations, it can use a register value instead of a memory-saved
468 offset and even an other register than $gp as global pointer. */
469 static offsetT mips_cpreturn_offset = -1;
470 static int mips_cpreturn_register = -1;
471 static int mips_gp_register = GP;
472 static int mips_gprel_offset = 0;
474 /* Whether mips_cprestore_offset has been set in the current function
475 (or whether it has already been warned about, if not). */
476 static int mips_cprestore_valid = 0;
478 /* This is the register which holds the stack frame, as set by the
479 .frame pseudo-op. This is needed to implement .cprestore. */
480 static int mips_frame_reg = SP;
482 /* Whether mips_frame_reg has been set in the current function
483 (or whether it has already been warned about, if not). */
484 static int mips_frame_reg_valid = 0;
486 /* To output NOP instructions correctly, we need to keep information
487 about the previous two instructions. */
489 /* Whether we are optimizing. The default value of 2 means to remove
490 unneeded NOPs and swap branch instructions when possible. A value
491 of 1 means to not swap branches. A value of 0 means to always
493 static int mips_optimize = 2;
495 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
496 equivalent to seeing no -g option at all. */
497 static int mips_debug = 0;
499 /* The previous instruction. */
500 static struct mips_cl_insn prev_insn;
502 /* The instruction before prev_insn. */
503 static struct mips_cl_insn prev_prev_insn;
505 /* If we don't want information for prev_insn or prev_prev_insn, we
506 point the insn_mo field at this dummy integer. */
507 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
509 /* Non-zero if prev_insn is valid. */
510 static int prev_insn_valid;
512 /* The frag for the previous instruction. */
513 static struct frag *prev_insn_frag;
515 /* The offset into prev_insn_frag for the previous instruction. */
516 static long prev_insn_where;
518 /* The reloc type for the previous instruction, if any. */
519 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
521 /* The reloc for the previous instruction, if any. */
522 static fixS *prev_insn_fixp[3];
524 /* Non-zero if the previous instruction was in a delay slot. */
525 static int prev_insn_is_delay_slot;
527 /* Non-zero if the previous instruction was in a .set noreorder. */
528 static int prev_insn_unreordered;
530 /* Non-zero if the previous instruction uses an extend opcode (if
532 static int prev_insn_extended;
534 /* Non-zero if the previous previous instruction was in a .set
536 static int prev_prev_insn_unreordered;
538 /* If this is set, it points to a frag holding nop instructions which
539 were inserted before the start of a noreorder section. If those
540 nops turn out to be unnecessary, the size of the frag can be
542 static fragS *prev_nop_frag;
544 /* The number of nop instructions we created in prev_nop_frag. */
545 static int prev_nop_frag_holds;
547 /* The number of nop instructions that we know we need in
549 static int prev_nop_frag_required;
551 /* The number of instructions we've seen since prev_nop_frag. */
552 static int prev_nop_frag_since;
554 /* For ECOFF and ELF, relocations against symbols are done in two
555 parts, with a HI relocation and a LO relocation. Each relocation
556 has only 16 bits of space to store an addend. This means that in
557 order for the linker to handle carries correctly, it must be able
558 to locate both the HI and the LO relocation. This means that the
559 relocations must appear in order in the relocation table.
561 In order to implement this, we keep track of each unmatched HI
562 relocation. We then sort them so that they immediately precede the
563 corresponding LO relocation. */
568 struct mips_hi_fixup *next;
571 /* The section this fixup is in. */
575 /* The list of unmatched HI relocs. */
577 static struct mips_hi_fixup *mips_hi_fixup_list;
579 /* The frag containing the last explicit relocation operator.
580 Null if explicit relocations have not been used. */
582 static fragS *prev_reloc_op_frag;
584 /* Map normal MIPS register numbers to mips16 register numbers. */
586 #define X ILLEGAL_REG
587 static const int mips32_to_16_reg_map[] =
589 X, X, 2, 3, 4, 5, 6, 7,
590 X, X, X, X, X, X, X, X,
591 0, 1, X, X, X, X, X, X,
592 X, X, X, X, X, X, X, X
596 /* Map mips16 register numbers to normal MIPS register numbers. */
598 static const unsigned int mips16_to_32_reg_map[] =
600 16, 17, 2, 3, 4, 5, 6, 7
603 static int mips_fix_4122_bugs;
605 /* We don't relax branches by default, since this causes us to expand
606 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
607 fail to compute the offset before expanding the macro to the most
608 efficient expansion. */
610 static int mips_relax_branch;
612 /* Since the MIPS does not have multiple forms of PC relative
613 instructions, we do not have to do relaxing as is done on other
614 platforms. However, we do have to handle GP relative addressing
615 correctly, which turns out to be a similar problem.
617 Every macro that refers to a symbol can occur in (at least) two
618 forms, one with GP relative addressing and one without. For
619 example, loading a global variable into a register generally uses
620 a macro instruction like this:
622 If i can be addressed off the GP register (this is true if it is in
623 the .sbss or .sdata section, or if it is known to be smaller than
624 the -G argument) this will generate the following instruction:
626 This instruction will use a GPREL reloc. If i can not be addressed
627 off the GP register, the following instruction sequence will be used:
630 In this case the first instruction will have a HI16 reloc, and the
631 second reloc will have a LO16 reloc. Both relocs will be against
634 The issue here is that we may not know whether i is GP addressable
635 until after we see the instruction that uses it. Therefore, we
636 want to be able to choose the final instruction sequence only at
637 the end of the assembly. This is similar to the way other
638 platforms choose the size of a PC relative instruction only at the
641 When generating position independent code we do not use GP
642 addressing in quite the same way, but the issue still arises as
643 external symbols and local symbols must be handled differently.
645 We handle these issues by actually generating both possible
646 instruction sequences. The longer one is put in a frag_var with
647 type rs_machine_dependent. We encode what to do with the frag in
648 the subtype field. We encode (1) the number of existing bytes to
649 replace, (2) the number of new bytes to use, (3) the offset from
650 the start of the existing bytes to the first reloc we must generate
651 (that is, the offset is applied from the start of the existing
652 bytes after they are replaced by the new bytes, if any), (4) the
653 offset from the start of the existing bytes to the second reloc,
654 (5) whether a third reloc is needed (the third reloc is always four
655 bytes after the second reloc), and (6) whether to warn if this
656 variant is used (this is sometimes needed if .set nomacro or .set
657 noat is in effect). All these numbers are reasonably small.
659 Generating two instruction sequences must be handled carefully to
660 ensure that delay slots are handled correctly. Fortunately, there
661 are a limited number of cases. When the second instruction
662 sequence is generated, append_insn is directed to maintain the
663 existing delay slot information, so it continues to apply to any
664 code after the second instruction sequence. This means that the
665 second instruction sequence must not impose any requirements not
666 required by the first instruction sequence.
668 These variant frags are then handled in functions called by the
669 machine independent code. md_estimate_size_before_relax returns
670 the final size of the frag. md_convert_frag sets up the final form
671 of the frag. tc_gen_reloc adjust the first reloc and adds a second
673 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
677 | (((reloc1) + 64) << 9) \
678 | (((reloc2) + 64) << 2) \
679 | ((reloc3) ? (1 << 1) : 0) \
681 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
682 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
683 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
684 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
685 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
686 #define RELAX_WARN(i) ((i) & 1)
688 /* Branch without likely bit. If label is out of range, we turn:
690 beq reg1, reg2, label
700 with the following opcode replacements:
707 bltzal <-> bgezal (with jal label instead of j label)
709 Even though keeping the delay slot instruction in the delay slot of
710 the branch would be more efficient, it would be very tricky to do
711 correctly, because we'd have to introduce a variable frag *after*
712 the delay slot instruction, and expand that instead. Let's do it
713 the easy way for now, even if the branch-not-taken case now costs
714 one additional instruction. Out-of-range branches are not supposed
715 to be common, anyway.
717 Branch likely. If label is out of range, we turn:
719 beql reg1, reg2, label
720 delay slot (annulled if branch not taken)
729 delay slot (executed only if branch taken)
732 It would be possible to generate a shorter sequence by losing the
733 likely bit, generating something like:
738 delay slot (executed only if branch taken)
750 bltzall -> bgezal (with jal label instead of j label)
751 bgezall -> bltzal (ditto)
754 but it's not clear that it would actually improve performance. */
755 #define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
758 | ((toofar) ? 1 : 0) \
760 | ((likely) ? 4 : 0) \
761 | ((uncond) ? 8 : 0)))
762 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
763 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
764 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
765 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
766 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1) != 0)
768 /* For mips16 code, we use an entirely different form of relaxation.
769 mips16 supports two versions of most instructions which take
770 immediate values: a small one which takes some small value, and a
771 larger one which takes a 16 bit value. Since branches also follow
772 this pattern, relaxing these values is required.
774 We can assemble both mips16 and normal MIPS code in a single
775 object. Therefore, we need to support this type of relaxation at
776 the same time that we support the relaxation described above. We
777 use the high bit of the subtype field to distinguish these cases.
779 The information we store for this type of relaxation is the
780 argument code found in the opcode file for this relocation, whether
781 the user explicitly requested a small or extended form, and whether
782 the relocation is in a jump or jal delay slot. That tells us the
783 size of the value, and how it should be stored. We also store
784 whether the fragment is considered to be extended or not. We also
785 store whether this is known to be a branch to a different section,
786 whether we have tried to relax this frag yet, and whether we have
787 ever extended a PC relative fragment because of a shift count. */
788 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
791 | ((small) ? 0x100 : 0) \
792 | ((ext) ? 0x200 : 0) \
793 | ((dslot) ? 0x400 : 0) \
794 | ((jal_dslot) ? 0x800 : 0))
795 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
796 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
797 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
798 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
799 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
800 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
801 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
802 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
803 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
804 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
805 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
806 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
808 /* Is the given value a sign-extended 32-bit value? */
809 #define IS_SEXT_32BIT_NUM(x) \
810 (((x) &~ (offsetT) 0x7fffffff) == 0 \
811 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
813 /* Is the given value a sign-extended 16-bit value? */
814 #define IS_SEXT_16BIT_NUM(x) \
815 (((x) &~ (offsetT) 0x7fff) == 0 \
816 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
819 /* Prototypes for static functions. */
822 #define internalError() \
823 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
825 #define internalError() as_fatal (_("MIPS internal Error"));
828 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
830 static inline bfd_boolean reloc_needs_lo_p
831 PARAMS ((bfd_reloc_code_real_type));
832 static inline bfd_boolean fixup_has_matching_lo_p
834 static int insn_uses_reg
835 PARAMS ((struct mips_cl_insn *ip, unsigned int reg,
836 enum mips_regclass class));
837 static int reg_needs_delay
838 PARAMS ((unsigned int));
839 static void mips16_mark_labels
841 static void append_insn
842 PARAMS ((char *place, struct mips_cl_insn * ip, expressionS * p,
843 bfd_reloc_code_real_type *r));
844 static void mips_no_prev_insn
846 static void mips_emit_delays
847 PARAMS ((bfd_boolean));
849 static void macro_build
850 PARAMS ((char *place, int *counter, expressionS * ep, const char *name,
851 const char *fmt, ...));
853 static void macro_build ();
855 static void mips16_macro_build
856 PARAMS ((char *, int *, expressionS *, const char *, const char *, va_list));
857 static void macro_build_jalr
858 PARAMS ((int, expressionS *));
859 static void macro_build_lui
860 PARAMS ((char *place, int *counter, expressionS * ep, int regnum));
861 static void macro_build_ldst_constoffset
862 PARAMS ((char *place, int *counter, expressionS * ep, const char *op,
863 int valreg, int breg));
865 PARAMS ((int *counter, int reg, int unsignedp));
866 static void check_absolute_expr
867 PARAMS ((struct mips_cl_insn * ip, expressionS *));
868 static void load_register
869 PARAMS ((int *, int, expressionS *, int));
870 static void load_address
871 PARAMS ((int *, int, expressionS *, int *));
872 static void move_register
873 PARAMS ((int *, int, int));
875 PARAMS ((struct mips_cl_insn * ip));
876 static void mips16_macro
877 PARAMS ((struct mips_cl_insn * ip));
878 #ifdef LOSING_COMPILER
880 PARAMS ((struct mips_cl_insn * ip));
883 PARAMS ((char *str, struct mips_cl_insn * ip));
884 static void mips16_ip
885 PARAMS ((char *str, struct mips_cl_insn * ip));
886 static void mips16_immed
887 PARAMS ((char *, unsigned int, int, offsetT, bfd_boolean, bfd_boolean,
888 bfd_boolean, unsigned long *, bfd_boolean *, unsigned short *));
889 static bfd_boolean parse_relocation
890 PARAMS ((char **, bfd_reloc_code_real_type *));
891 static size_t my_getSmallExpression
892 PARAMS ((expressionS *, bfd_reloc_code_real_type *, char *));
893 static void my_getExpression
894 PARAMS ((expressionS *, char *));
896 static int support_64bit_objects
899 static void mips_set_option_string
900 PARAMS ((const char **, const char *));
901 static symbolS *get_symbol
903 static void mips_align
904 PARAMS ((int to, int fill, symbolS *label));
907 static void s_change_sec
909 static void s_change_section
913 static void s_float_cons
915 static void s_mips_globl
919 static void s_mipsset
921 static void s_abicalls
925 static void s_cpsetup
927 static void s_cplocal
929 static void s_cprestore
931 static void s_cpreturn
933 static void s_gpvalue
937 static void s_gpdword
943 static void md_obj_begin
945 static void md_obj_end
947 static long get_number
949 static void s_mips_ent
951 static void s_mips_end
953 static void s_mips_frame
955 static void s_mips_mask
957 static void s_mips_stab
959 static void s_mips_weakext
961 static void s_mips_file
963 static void s_mips_loc
965 static bfd_boolean pic_need_relax
966 PARAMS ((symbolS *, asection *));
967 static int mips16_extended_frag
968 PARAMS ((fragS *, asection *, long));
969 static int relaxed_branch_length (fragS *, asection *, int);
970 static int validate_mips_insn
971 PARAMS ((const struct mips_opcode *));
973 PARAMS ((FILE *, const char *, int *, int *));
975 static int mips_need_elf_addend_fixup
979 /* Table and functions used to map between CPU/ISA names, and
980 ISA levels, and CPU numbers. */
984 const char *name; /* CPU or ISA name. */
985 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
986 int isa; /* ISA level. */
987 int cpu; /* CPU number (default CPU if ISA). */
990 static void mips_set_architecture
991 PARAMS ((const struct mips_cpu_info *));
992 static void mips_set_tune
993 PARAMS ((const struct mips_cpu_info *));
994 static bfd_boolean mips_strict_matching_cpu_name_p
995 PARAMS ((const char *, const char *));
996 static bfd_boolean mips_matching_cpu_name_p
997 PARAMS ((const char *, const char *));
998 static const struct mips_cpu_info *mips_parse_cpu
999 PARAMS ((const char *, const char *));
1000 static const struct mips_cpu_info *mips_cpu_info_from_isa
1005 The following pseudo-ops from the Kane and Heinrich MIPS book
1006 should be defined here, but are currently unsupported: .alias,
1007 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1009 The following pseudo-ops from the Kane and Heinrich MIPS book are
1010 specific to the type of debugging information being generated, and
1011 should be defined by the object format: .aent, .begin, .bend,
1012 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1015 The following pseudo-ops from the Kane and Heinrich MIPS book are
1016 not MIPS CPU specific, but are also not specific to the object file
1017 format. This file is probably the best place to define them, but
1018 they are not currently supported: .asm0, .endr, .lab, .repeat,
1021 static const pseudo_typeS mips_pseudo_table[] =
1023 /* MIPS specific pseudo-ops. */
1024 {"option", s_option, 0},
1025 {"set", s_mipsset, 0},
1026 {"rdata", s_change_sec, 'r'},
1027 {"sdata", s_change_sec, 's'},
1028 {"livereg", s_ignore, 0},
1029 {"abicalls", s_abicalls, 0},
1030 {"cpload", s_cpload, 0},
1031 {"cpsetup", s_cpsetup, 0},
1032 {"cplocal", s_cplocal, 0},
1033 {"cprestore", s_cprestore, 0},
1034 {"cpreturn", s_cpreturn, 0},
1035 {"gpvalue", s_gpvalue, 0},
1036 {"gpword", s_gpword, 0},
1037 {"gpdword", s_gpdword, 0},
1038 {"cpadd", s_cpadd, 0},
1039 {"insn", s_insn, 0},
1041 /* Relatively generic pseudo-ops that happen to be used on MIPS
1043 {"asciiz", stringer, 1},
1044 {"bss", s_change_sec, 'b'},
1046 {"half", s_cons, 1},
1047 {"dword", s_cons, 3},
1048 {"weakext", s_mips_weakext, 0},
1050 /* These pseudo-ops are defined in read.c, but must be overridden
1051 here for one reason or another. */
1052 {"align", s_align, 0},
1053 {"byte", s_cons, 0},
1054 {"data", s_change_sec, 'd'},
1055 {"double", s_float_cons, 'd'},
1056 {"float", s_float_cons, 'f'},
1057 {"globl", s_mips_globl, 0},
1058 {"global", s_mips_globl, 0},
1059 {"hword", s_cons, 1},
1061 {"long", s_cons, 2},
1062 {"octa", s_cons, 4},
1063 {"quad", s_cons, 3},
1064 {"section", s_change_section, 0},
1065 {"short", s_cons, 1},
1066 {"single", s_float_cons, 'f'},
1067 {"stabn", s_mips_stab, 'n'},
1068 {"text", s_change_sec, 't'},
1069 {"word", s_cons, 2},
1071 { "extern", ecoff_directive_extern, 0},
1076 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1078 /* These pseudo-ops should be defined by the object file format.
1079 However, a.out doesn't support them, so we have versions here. */
1080 {"aent", s_mips_ent, 1},
1081 {"bgnb", s_ignore, 0},
1082 {"end", s_mips_end, 0},
1083 {"endb", s_ignore, 0},
1084 {"ent", s_mips_ent, 0},
1085 {"file", s_mips_file, 0},
1086 {"fmask", s_mips_mask, 'F'},
1087 {"frame", s_mips_frame, 0},
1088 {"loc", s_mips_loc, 0},
1089 {"mask", s_mips_mask, 'R'},
1090 {"verstamp", s_ignore, 0},
1094 extern void pop_insert PARAMS ((const pseudo_typeS *));
1099 pop_insert (mips_pseudo_table);
1100 if (! ECOFF_DEBUGGING)
1101 pop_insert (mips_nonecoff_pseudo_table);
1104 /* Symbols labelling the current insn. */
1106 struct insn_label_list
1108 struct insn_label_list *next;
1112 static struct insn_label_list *insn_labels;
1113 static struct insn_label_list *free_insn_labels;
1115 static void mips_clear_insn_labels PARAMS ((void));
1118 mips_clear_insn_labels ()
1120 register struct insn_label_list **pl;
1122 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1128 static char *expr_end;
1130 /* Expressions which appear in instructions. These are set by
1133 static expressionS imm_expr;
1134 static expressionS offset_expr;
1136 /* Relocs associated with imm_expr and offset_expr. */
1138 static bfd_reloc_code_real_type imm_reloc[3]
1139 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1140 static bfd_reloc_code_real_type offset_reloc[3]
1141 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1143 /* These are set by mips16_ip if an explicit extension is used. */
1145 static bfd_boolean mips16_small, mips16_ext;
1148 /* The pdr segment for per procedure frame/regmask info. Not used for
1151 static segT pdr_seg;
1154 /* The default target format to use. */
1157 mips_target_format ()
1159 switch (OUTPUT_FLAVOR)
1161 case bfd_target_aout_flavour:
1162 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
1163 case bfd_target_ecoff_flavour:
1164 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1165 case bfd_target_coff_flavour:
1167 case bfd_target_elf_flavour:
1169 /* This is traditional mips. */
1170 return (target_big_endian
1171 ? (HAVE_64BIT_OBJECTS
1172 ? "elf64-tradbigmips"
1174 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1175 : (HAVE_64BIT_OBJECTS
1176 ? "elf64-tradlittlemips"
1178 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1180 return (target_big_endian
1181 ? (HAVE_64BIT_OBJECTS
1184 ? "elf32-nbigmips" : "elf32-bigmips"))
1185 : (HAVE_64BIT_OBJECTS
1186 ? "elf64-littlemips"
1188 ? "elf32-nlittlemips" : "elf32-littlemips")));
1196 /* This function is called once, at assembler startup time. It should
1197 set up all the tables, etc. that the MD part of the assembler will need. */
1202 register const char *retval = NULL;
1206 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1207 as_warn (_("Could not set architecture and machine"));
1209 op_hash = hash_new ();
1211 for (i = 0; i < NUMOPCODES;)
1213 const char *name = mips_opcodes[i].name;
1215 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1218 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1219 mips_opcodes[i].name, retval);
1220 /* Probably a memory allocation problem? Give up now. */
1221 as_fatal (_("Broken assembler. No assembly attempted."));
1225 if (mips_opcodes[i].pinfo != INSN_MACRO)
1227 if (!validate_mips_insn (&mips_opcodes[i]))
1232 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1235 mips16_op_hash = hash_new ();
1238 while (i < bfd_mips16_num_opcodes)
1240 const char *name = mips16_opcodes[i].name;
1242 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1244 as_fatal (_("internal: can't hash `%s': %s"),
1245 mips16_opcodes[i].name, retval);
1248 if (mips16_opcodes[i].pinfo != INSN_MACRO
1249 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1250 != mips16_opcodes[i].match))
1252 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1253 mips16_opcodes[i].name, mips16_opcodes[i].args);
1258 while (i < bfd_mips16_num_opcodes
1259 && strcmp (mips16_opcodes[i].name, name) == 0);
1263 as_fatal (_("Broken assembler. No assembly attempted."));
1265 /* We add all the general register names to the symbol table. This
1266 helps us detect invalid uses of them. */
1267 for (i = 0; i < 32; i++)
1271 sprintf (buf, "$%d", i);
1272 symbol_table_insert (symbol_new (buf, reg_section, i,
1273 &zero_address_frag));
1275 symbol_table_insert (symbol_new ("$ra", reg_section, RA,
1276 &zero_address_frag));
1277 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1278 &zero_address_frag));
1279 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1280 &zero_address_frag));
1281 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1282 &zero_address_frag));
1283 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1284 &zero_address_frag));
1285 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1286 &zero_address_frag));
1287 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1288 &zero_address_frag));
1289 symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
1290 &zero_address_frag));
1291 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1292 &zero_address_frag));
1294 /* If we don't add these register names to the symbol table, they
1295 may end up being added as regular symbols by operand(), and then
1296 make it to the object file as undefined in case they're not
1297 regarded as local symbols. They're local in o32, since `$' is a
1298 local symbol prefix, but not in n32 or n64. */
1299 for (i = 0; i < 8; i++)
1303 sprintf (buf, "$fcc%i", i);
1304 symbol_table_insert (symbol_new (buf, reg_section, -1,
1305 &zero_address_frag));
1308 mips_no_prev_insn (FALSE);
1311 mips_cprmask[0] = 0;
1312 mips_cprmask[1] = 0;
1313 mips_cprmask[2] = 0;
1314 mips_cprmask[3] = 0;
1316 /* set the default alignment for the text section (2**2) */
1317 record_alignment (text_section, 2);
1319 if (USE_GLOBAL_POINTER_OPT)
1320 bfd_set_gp_size (stdoutput, g_switch_value);
1322 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1324 /* On a native system, sections must be aligned to 16 byte
1325 boundaries. When configured for an embedded ELF target, we
1327 if (strcmp (TARGET_OS, "elf") != 0)
1329 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1330 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1331 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1334 /* Create a .reginfo section for register masks and a .mdebug
1335 section for debugging information. */
1343 subseg = now_subseg;
1345 /* The ABI says this section should be loaded so that the
1346 running program can access it. However, we don't load it
1347 if we are configured for an embedded target */
1348 flags = SEC_READONLY | SEC_DATA;
1349 if (strcmp (TARGET_OS, "elf") != 0)
1350 flags |= SEC_ALLOC | SEC_LOAD;
1352 if (mips_abi != N64_ABI)
1354 sec = subseg_new (".reginfo", (subsegT) 0);
1356 bfd_set_section_flags (stdoutput, sec, flags);
1357 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1360 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1365 /* The 64-bit ABI uses a .MIPS.options section rather than
1366 .reginfo section. */
1367 sec = subseg_new (".MIPS.options", (subsegT) 0);
1368 bfd_set_section_flags (stdoutput, sec, flags);
1369 bfd_set_section_alignment (stdoutput, sec, 3);
1372 /* Set up the option header. */
1374 Elf_Internal_Options opthdr;
1377 opthdr.kind = ODK_REGINFO;
1378 opthdr.size = (sizeof (Elf_External_Options)
1379 + sizeof (Elf64_External_RegInfo));
1382 f = frag_more (sizeof (Elf_External_Options));
1383 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1384 (Elf_External_Options *) f);
1386 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1391 if (ECOFF_DEBUGGING)
1393 sec = subseg_new (".mdebug", (subsegT) 0);
1394 (void) bfd_set_section_flags (stdoutput, sec,
1395 SEC_HAS_CONTENTS | SEC_READONLY);
1396 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1399 else if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1401 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1402 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1403 SEC_READONLY | SEC_RELOC
1405 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1409 subseg_set (seg, subseg);
1413 if (! ECOFF_DEBUGGING)
1420 if (! ECOFF_DEBUGGING)
1428 struct mips_cl_insn insn;
1429 bfd_reloc_code_real_type unused_reloc[3]
1430 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1432 imm_expr.X_op = O_absent;
1433 offset_expr.X_op = O_absent;
1434 imm_reloc[0] = BFD_RELOC_UNUSED;
1435 imm_reloc[1] = BFD_RELOC_UNUSED;
1436 imm_reloc[2] = BFD_RELOC_UNUSED;
1437 offset_reloc[0] = BFD_RELOC_UNUSED;
1438 offset_reloc[1] = BFD_RELOC_UNUSED;
1439 offset_reloc[2] = BFD_RELOC_UNUSED;
1441 if (mips_opts.mips16)
1442 mips16_ip (str, &insn);
1445 mips_ip (str, &insn);
1446 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1447 str, insn.insn_opcode));
1452 as_bad ("%s `%s'", insn_error, str);
1456 if (insn.insn_mo->pinfo == INSN_MACRO)
1458 if (mips_opts.mips16)
1459 mips16_macro (&insn);
1465 if (imm_expr.X_op != O_absent)
1466 append_insn (NULL, &insn, &imm_expr, imm_reloc);
1467 else if (offset_expr.X_op != O_absent)
1468 append_insn (NULL, &insn, &offset_expr, offset_reloc);
1470 append_insn (NULL, &insn, NULL, unused_reloc);
1474 /* Return true if the given relocation might need a matching %lo().
1475 Note that R_MIPS_GOT16 relocations only need a matching %lo() when
1476 applied to local symbols. */
1478 static inline bfd_boolean
1479 reloc_needs_lo_p (reloc)
1480 bfd_reloc_code_real_type reloc;
1482 return (reloc == BFD_RELOC_HI16_S
1483 || reloc == BFD_RELOC_MIPS_GOT16);
1486 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
1489 static inline bfd_boolean
1490 fixup_has_matching_lo_p (fixp)
1493 return (fixp->fx_next != NULL
1494 && fixp->fx_next->fx_r_type == BFD_RELOC_LO16
1495 && fixp->fx_addsy == fixp->fx_next->fx_addsy
1496 && fixp->fx_offset == fixp->fx_next->fx_offset);
1499 /* See whether instruction IP reads register REG. CLASS is the type
1503 insn_uses_reg (ip, reg, class)
1504 struct mips_cl_insn *ip;
1506 enum mips_regclass class;
1508 if (class == MIPS16_REG)
1510 assert (mips_opts.mips16);
1511 reg = mips16_to_32_reg_map[reg];
1512 class = MIPS_GR_REG;
1515 /* Don't report on general register ZERO, since it never changes. */
1516 if (class == MIPS_GR_REG && reg == ZERO)
1519 if (class == MIPS_FP_REG)
1521 assert (! mips_opts.mips16);
1522 /* If we are called with either $f0 or $f1, we must check $f0.
1523 This is not optimal, because it will introduce an unnecessary
1524 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1525 need to distinguish reading both $f0 and $f1 or just one of
1526 them. Note that we don't have to check the other way,
1527 because there is no instruction that sets both $f0 and $f1
1528 and requires a delay. */
1529 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1530 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1531 == (reg &~ (unsigned) 1)))
1533 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1534 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1535 == (reg &~ (unsigned) 1)))
1538 else if (! mips_opts.mips16)
1540 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1541 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1543 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1544 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1549 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1550 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1551 & MIPS16OP_MASK_RX)]
1554 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1555 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1556 & MIPS16OP_MASK_RY)]
1559 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1560 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1561 & MIPS16OP_MASK_MOVE32Z)]
1564 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1566 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1568 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1570 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1571 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1572 & MIPS16OP_MASK_REGR32) == reg)
1579 /* This function returns true if modifying a register requires a
1583 reg_needs_delay (reg)
1586 unsigned long prev_pinfo;
1588 prev_pinfo = prev_insn.insn_mo->pinfo;
1589 if (! mips_opts.noreorder
1590 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1591 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1592 || (! gpr_interlocks
1593 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1595 /* A load from a coprocessor or from memory. All load
1596 delays delay the use of general register rt for one
1597 instruction on the r3000. The r6000 and r4000 use
1599 /* Itbl support may require additional care here. */
1600 know (prev_pinfo & INSN_WRITE_GPR_T);
1601 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1608 /* Mark instruction labels in mips16 mode. This permits the linker to
1609 handle them specially, such as generating jalx instructions when
1610 needed. We also make them odd for the duration of the assembly, in
1611 order to generate the right sort of code. We will make them even
1612 in the adjust_symtab routine, while leaving them marked. This is
1613 convenient for the debugger and the disassembler. The linker knows
1614 to make them odd again. */
1617 mips16_mark_labels ()
1619 if (mips_opts.mips16)
1621 struct insn_label_list *l;
1624 for (l = insn_labels; l != NULL; l = l->next)
1627 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1628 S_SET_OTHER (l->label, STO_MIPS16);
1630 val = S_GET_VALUE (l->label);
1632 S_SET_VALUE (l->label, val + 1);
1637 /* Output an instruction. PLACE is where to put the instruction; if
1638 it is NULL, this uses frag_more to get room. IP is the instruction
1639 information. ADDRESS_EXPR is an operand of the instruction to be
1640 used with RELOC_TYPE. */
1643 append_insn (place, ip, address_expr, reloc_type)
1645 struct mips_cl_insn *ip;
1646 expressionS *address_expr;
1647 bfd_reloc_code_real_type *reloc_type;
1649 register unsigned long prev_pinfo, pinfo;
1653 bfd_boolean force_new_frag = FALSE;
1655 /* Mark instruction labels in mips16 mode. */
1656 mips16_mark_labels ();
1658 prev_pinfo = prev_insn.insn_mo->pinfo;
1659 pinfo = ip->insn_mo->pinfo;
1661 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1665 /* If the previous insn required any delay slots, see if we need
1666 to insert a NOP or two. There are eight kinds of possible
1667 hazards, of which an instruction can have at most one type.
1668 (1) a load from memory delay
1669 (2) a load from a coprocessor delay
1670 (3) an unconditional branch delay
1671 (4) a conditional branch delay
1672 (5) a move to coprocessor register delay
1673 (6) a load coprocessor register from memory delay
1674 (7) a coprocessor condition code delay
1675 (8) a HI/LO special register delay
1677 There are a lot of optimizations we could do that we don't.
1678 In particular, we do not, in general, reorder instructions.
1679 If you use gcc with optimization, it will reorder
1680 instructions and generally do much more optimization then we
1681 do here; repeating all that work in the assembler would only
1682 benefit hand written assembly code, and does not seem worth
1685 /* This is how a NOP is emitted. */
1686 #define emit_nop() \
1688 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1689 : md_number_to_chars (frag_more (4), 0, 4))
1691 /* The previous insn might require a delay slot, depending upon
1692 the contents of the current insn. */
1693 if (! mips_opts.mips16
1694 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1695 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1696 && ! cop_interlocks)
1697 || (! gpr_interlocks
1698 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1700 /* A load from a coprocessor or from memory. All load
1701 delays delay the use of general register rt for one
1702 instruction on the r3000. The r6000 and r4000 use
1704 /* Itbl support may require additional care here. */
1705 know (prev_pinfo & INSN_WRITE_GPR_T);
1706 if (mips_optimize == 0
1707 || insn_uses_reg (ip,
1708 ((prev_insn.insn_opcode >> OP_SH_RT)
1713 else if (! mips_opts.mips16
1714 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1715 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1716 && ! cop_interlocks)
1717 || (mips_opts.isa == ISA_MIPS1
1718 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1720 /* A generic coprocessor delay. The previous instruction
1721 modified a coprocessor general or control register. If
1722 it modified a control register, we need to avoid any
1723 coprocessor instruction (this is probably not always
1724 required, but it sometimes is). If it modified a general
1725 register, we avoid using that register.
1727 On the r6000 and r4000 loading a coprocessor register
1728 from memory is interlocked, and does not require a delay.
1730 This case is not handled very well. There is no special
1731 knowledge of CP0 handling, and the coprocessors other
1732 than the floating point unit are not distinguished at
1734 /* Itbl support may require additional care here. FIXME!
1735 Need to modify this to include knowledge about
1736 user specified delays! */
1737 if (prev_pinfo & INSN_WRITE_FPR_T)
1739 if (mips_optimize == 0
1740 || insn_uses_reg (ip,
1741 ((prev_insn.insn_opcode >> OP_SH_FT)
1746 else if (prev_pinfo & INSN_WRITE_FPR_S)
1748 if (mips_optimize == 0
1749 || insn_uses_reg (ip,
1750 ((prev_insn.insn_opcode >> OP_SH_FS)
1757 /* We don't know exactly what the previous instruction
1758 does. If the current instruction uses a coprocessor
1759 register, we must insert a NOP. If previous
1760 instruction may set the condition codes, and the
1761 current instruction uses them, we must insert two
1763 /* Itbl support may require additional care here. */
1764 if (mips_optimize == 0
1765 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1766 && (pinfo & INSN_READ_COND_CODE)))
1768 else if (pinfo & INSN_COP)
1772 else if (! mips_opts.mips16
1773 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1774 && (prev_pinfo & INSN_WRITE_COND_CODE)
1775 && ! cop_interlocks)
1777 /* The previous instruction sets the coprocessor condition
1778 codes, but does not require a general coprocessor delay
1779 (this means it is a floating point comparison
1780 instruction). If this instruction uses the condition
1781 codes, we need to insert a single NOP. */
1782 /* Itbl support may require additional care here. */
1783 if (mips_optimize == 0
1784 || (pinfo & INSN_READ_COND_CODE))
1788 /* If we're fixing up mfhi/mflo for the r7000 and the
1789 previous insn was an mfhi/mflo and the current insn
1790 reads the register that the mfhi/mflo wrote to, then
1793 else if (mips_7000_hilo_fix
1794 && MF_HILO_INSN (prev_pinfo)
1795 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1802 /* If we're fixing up mfhi/mflo for the r7000 and the
1803 2nd previous insn was an mfhi/mflo and the current insn
1804 reads the register that the mfhi/mflo wrote to, then
1807 else if (mips_7000_hilo_fix
1808 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1809 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1817 else if (prev_pinfo & INSN_READ_LO)
1819 /* The previous instruction reads the LO register; if the
1820 current instruction writes to the LO register, we must
1821 insert two NOPS. Some newer processors have interlocks.
1822 Also the tx39's multiply instructions can be exectuted
1823 immediatly after a read from HI/LO (without the delay),
1824 though the tx39's divide insns still do require the
1826 if (! (hilo_interlocks
1827 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1828 && (mips_optimize == 0
1829 || (pinfo & INSN_WRITE_LO)))
1831 /* Most mips16 branch insns don't have a delay slot.
1832 If a read from LO is immediately followed by a branch
1833 to a write to LO we have a read followed by a write
1834 less than 2 insns away. We assume the target of
1835 a branch might be a write to LO, and insert a nop
1836 between a read and an immediately following branch. */
1837 else if (mips_opts.mips16
1838 && (mips_optimize == 0
1839 || (pinfo & MIPS16_INSN_BRANCH)))
1842 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1844 /* The previous instruction reads the HI register; if the
1845 current instruction writes to the HI register, we must
1846 insert a NOP. Some newer processors have interlocks.
1847 Also the note tx39's multiply above. */
1848 if (! (hilo_interlocks
1849 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1850 && (mips_optimize == 0
1851 || (pinfo & INSN_WRITE_HI)))
1853 /* Most mips16 branch insns don't have a delay slot.
1854 If a read from HI is immediately followed by a branch
1855 to a write to HI we have a read followed by a write
1856 less than 2 insns away. We assume the target of
1857 a branch might be a write to HI, and insert a nop
1858 between a read and an immediately following branch. */
1859 else if (mips_opts.mips16
1860 && (mips_optimize == 0
1861 || (pinfo & MIPS16_INSN_BRANCH)))
1865 /* If the previous instruction was in a noreorder section, then
1866 we don't want to insert the nop after all. */
1867 /* Itbl support may require additional care here. */
1868 if (prev_insn_unreordered)
1871 /* There are two cases which require two intervening
1872 instructions: 1) setting the condition codes using a move to
1873 coprocessor instruction which requires a general coprocessor
1874 delay and then reading the condition codes 2) reading the HI
1875 or LO register and then writing to it (except on processors
1876 which have interlocks). If we are not already emitting a NOP
1877 instruction, we must check for these cases compared to the
1878 instruction previous to the previous instruction. */
1879 if ((! mips_opts.mips16
1880 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1881 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1882 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1883 && (pinfo & INSN_READ_COND_CODE)
1884 && ! cop_interlocks)
1885 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1886 && (pinfo & INSN_WRITE_LO)
1887 && ! (hilo_interlocks
1888 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1889 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1890 && (pinfo & INSN_WRITE_HI)
1891 && ! (hilo_interlocks
1892 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1897 if (prev_prev_insn_unreordered)
1900 if (prev_prev_nop && nops == 0)
1903 if (mips_fix_4122_bugs && prev_insn.insn_mo->name)
1905 /* We're out of bits in pinfo, so we must resort to string
1906 ops here. Shortcuts are selected based on opcodes being
1907 limited to the VR4122 instruction set. */
1909 const char *pn = prev_insn.insn_mo->name;
1910 const char *tn = ip->insn_mo->name;
1911 if (strncmp(pn, "macc", 4) == 0
1912 || strncmp(pn, "dmacc", 5) == 0)
1914 /* Errata 21 - [D]DIV[U] after [D]MACC */
1915 if (strstr (tn, "div"))
1920 /* Errata 23 - Continuous DMULT[U]/DMACC instructions */
1921 if (pn[0] == 'd' /* dmacc */
1922 && (strncmp(tn, "dmult", 5) == 0
1923 || strncmp(tn, "dmacc", 5) == 0))
1928 /* Errata 24 - MT{LO,HI} after [D]MACC */
1929 if (strcmp (tn, "mtlo") == 0
1930 || strcmp (tn, "mthi") == 0)
1936 else if (strncmp(pn, "dmult", 5) == 0
1937 && (strncmp(tn, "dmult", 5) == 0
1938 || strncmp(tn, "dmacc", 5) == 0))
1940 /* Here is the rest of errata 23. */
1943 if (nops < min_nops)
1947 /* If we are being given a nop instruction, don't bother with
1948 one of the nops we would otherwise output. This will only
1949 happen when a nop instruction is used with mips_optimize set
1952 && ! mips_opts.noreorder
1953 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1956 /* Now emit the right number of NOP instructions. */
1957 if (nops > 0 && ! mips_opts.noreorder)
1960 unsigned long old_frag_offset;
1962 struct insn_label_list *l;
1964 old_frag = frag_now;
1965 old_frag_offset = frag_now_fix ();
1967 for (i = 0; i < nops; i++)
1972 listing_prev_line ();
1973 /* We may be at the start of a variant frag. In case we
1974 are, make sure there is enough space for the frag
1975 after the frags created by listing_prev_line. The
1976 argument to frag_grow here must be at least as large
1977 as the argument to all other calls to frag_grow in
1978 this file. We don't have to worry about being in the
1979 middle of a variant frag, because the variants insert
1980 all needed nop instructions themselves. */
1984 for (l = insn_labels; l != NULL; l = l->next)
1988 assert (S_GET_SEGMENT (l->label) == now_seg);
1989 symbol_set_frag (l->label, frag_now);
1990 val = (valueT) frag_now_fix ();
1991 /* mips16 text labels are stored as odd. */
1992 if (mips_opts.mips16)
1994 S_SET_VALUE (l->label, val);
1997 #ifndef NO_ECOFF_DEBUGGING
1998 if (ECOFF_DEBUGGING)
1999 ecoff_fix_loc (old_frag, old_frag_offset);
2002 else if (prev_nop_frag != NULL)
2004 /* We have a frag holding nops we may be able to remove. If
2005 we don't need any nops, we can decrease the size of
2006 prev_nop_frag by the size of one instruction. If we do
2007 need some nops, we count them in prev_nops_required. */
2008 if (prev_nop_frag_since == 0)
2012 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
2013 --prev_nop_frag_holds;
2016 prev_nop_frag_required += nops;
2020 if (prev_prev_nop == 0)
2022 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
2023 --prev_nop_frag_holds;
2026 ++prev_nop_frag_required;
2029 if (prev_nop_frag_holds <= prev_nop_frag_required)
2030 prev_nop_frag = NULL;
2032 ++prev_nop_frag_since;
2034 /* Sanity check: by the time we reach the second instruction
2035 after prev_nop_frag, we should have used up all the nops
2036 one way or another. */
2037 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
2043 && *reloc_type == BFD_RELOC_16_PCREL_S2
2044 && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY
2045 || pinfo & INSN_COND_BRANCH_LIKELY)
2046 && mips_relax_branch
2047 /* Don't try branch relaxation within .set nomacro, or within
2048 .set noat if we use $at for PIC computations. If it turns
2049 out that the branch was out-of-range, we'll get an error. */
2050 && !mips_opts.warn_about_macros
2051 && !(mips_opts.noat && mips_pic != NO_PIC)
2052 && !mips_opts.mips16)
2054 f = frag_var (rs_machine_dependent,
2055 relaxed_branch_length
2057 (pinfo & INSN_UNCOND_BRANCH_DELAY) ? -1
2058 : (pinfo & INSN_COND_BRANCH_LIKELY) ? 1 : 0), 4,
2060 (pinfo & INSN_UNCOND_BRANCH_DELAY,
2061 pinfo & INSN_COND_BRANCH_LIKELY,
2062 pinfo & INSN_WRITE_GPR_31,
2064 address_expr->X_add_symbol,
2065 address_expr->X_add_number,
2067 *reloc_type = BFD_RELOC_UNUSED;
2069 else if (*reloc_type > BFD_RELOC_UNUSED)
2071 /* We need to set up a variant frag. */
2072 assert (mips_opts.mips16 && address_expr != NULL);
2073 f = frag_var (rs_machine_dependent, 4, 0,
2074 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
2075 mips16_small, mips16_ext,
2077 & INSN_UNCOND_BRANCH_DELAY),
2078 (*prev_insn_reloc_type
2079 == BFD_RELOC_MIPS16_JMP)),
2080 make_expr_symbol (address_expr), 0, NULL);
2082 else if (place != NULL)
2084 else if (mips_opts.mips16
2086 && *reloc_type != BFD_RELOC_MIPS16_JMP)
2088 /* Make sure there is enough room to swap this instruction with
2089 a following jump instruction. */
2095 if (mips_opts.mips16
2096 && mips_opts.noreorder
2097 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
2098 as_warn (_("extended instruction in delay slot"));
2103 fixp[0] = fixp[1] = fixp[2] = NULL;
2104 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
2106 if (address_expr->X_op == O_constant)
2110 switch (*reloc_type)
2113 ip->insn_opcode |= address_expr->X_add_number;
2116 case BFD_RELOC_MIPS_HIGHEST:
2117 tmp = (address_expr->X_add_number + 0x800080008000) >> 16;
2119 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2122 case BFD_RELOC_MIPS_HIGHER:
2123 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
2124 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2127 case BFD_RELOC_HI16_S:
2128 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
2132 case BFD_RELOC_HI16:
2133 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2136 case BFD_RELOC_LO16:
2137 case BFD_RELOC_MIPS_GOT_DISP:
2138 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2141 case BFD_RELOC_MIPS_JMP:
2142 if ((address_expr->X_add_number & 3) != 0)
2143 as_bad (_("jump to misaligned address (0x%lx)"),
2144 (unsigned long) address_expr->X_add_number);
2145 if (address_expr->X_add_number & ~0xfffffff)
2146 as_bad (_("jump address range overflow (0x%lx)"),
2147 (unsigned long) address_expr->X_add_number);
2148 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2151 case BFD_RELOC_MIPS16_JMP:
2152 if ((address_expr->X_add_number & 3) != 0)
2153 as_bad (_("jump to misaligned address (0x%lx)"),
2154 (unsigned long) address_expr->X_add_number);
2155 if (address_expr->X_add_number & ~0xfffffff)
2156 as_bad (_("jump address range overflow (0x%lx)"),
2157 (unsigned long) address_expr->X_add_number);
2159 (((address_expr->X_add_number & 0x7c0000) << 3)
2160 | ((address_expr->X_add_number & 0xf800000) >> 7)
2161 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2164 case BFD_RELOC_16_PCREL_S2:
2174 /* Don't generate a reloc if we are writing into a variant frag. */
2177 reloc_howto_type *howto;
2180 /* In a compound relocation, it is the final (outermost)
2181 operator that determines the relocated field. */
2182 for (i = 1; i < 3; i++)
2183 if (reloc_type[i] == BFD_RELOC_UNUSED)
2186 howto = bfd_reloc_type_lookup (stdoutput, reloc_type[i - 1]);
2187 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal,
2188 bfd_get_reloc_size(howto),
2190 reloc_type[0] == BFD_RELOC_16_PCREL_S2,
2193 /* These relocations can have an addend that won't fit in
2194 4 octets for 64bit assembly. */
2196 && ! howto->partial_inplace
2197 && (reloc_type[0] == BFD_RELOC_16
2198 || reloc_type[0] == BFD_RELOC_32
2199 || reloc_type[0] == BFD_RELOC_MIPS_JMP
2200 || reloc_type[0] == BFD_RELOC_HI16_S
2201 || reloc_type[0] == BFD_RELOC_LO16
2202 || reloc_type[0] == BFD_RELOC_GPREL16
2203 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
2204 || reloc_type[0] == BFD_RELOC_GPREL32
2205 || reloc_type[0] == BFD_RELOC_64
2206 || reloc_type[0] == BFD_RELOC_CTOR
2207 || reloc_type[0] == BFD_RELOC_MIPS_SUB
2208 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
2209 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
2210 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
2211 || reloc_type[0] == BFD_RELOC_MIPS_REL16
2212 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT))
2213 fixp[0]->fx_no_overflow = 1;
2215 if (reloc_needs_lo_p (*reloc_type))
2217 struct mips_hi_fixup *hi_fixup;
2219 /* Reuse the last entry if it already has a matching %lo. */
2220 hi_fixup = mips_hi_fixup_list;
2222 || !fixup_has_matching_lo_p (hi_fixup->fixp))
2224 hi_fixup = ((struct mips_hi_fixup *)
2225 xmalloc (sizeof (struct mips_hi_fixup)));
2226 hi_fixup->next = mips_hi_fixup_list;
2227 mips_hi_fixup_list = hi_fixup;
2229 hi_fixup->fixp = fixp[0];
2230 hi_fixup->seg = now_seg;
2233 /* Add fixups for the second and third relocations, if given.
2234 Note that the ABI allows the second relocation to be
2235 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
2236 moment we only use RSS_UNDEF, but we could add support
2237 for the others if it ever becomes necessary. */
2238 for (i = 1; i < 3; i++)
2239 if (reloc_type[i] != BFD_RELOC_UNUSED)
2241 address_expr->X_op = O_absent;
2242 address_expr->X_add_symbol = 0;
2243 address_expr->X_add_number = 0;
2245 fixp[i] = fix_new_exp (frag_now, fixp[0]->fx_where,
2246 fixp[0]->fx_size, address_expr,
2247 FALSE, reloc_type[i]);
2253 if (! mips_opts.mips16)
2255 md_number_to_chars (f, ip->insn_opcode, 4);
2257 dwarf2_emit_insn (4);
2260 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2262 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2263 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2265 dwarf2_emit_insn (4);
2272 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2275 md_number_to_chars (f, ip->insn_opcode, 2);
2277 dwarf2_emit_insn (ip->use_extend ? 4 : 2);
2281 /* Update the register mask information. */
2282 if (! mips_opts.mips16)
2284 if (pinfo & INSN_WRITE_GPR_D)
2285 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2286 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2287 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2288 if (pinfo & INSN_READ_GPR_S)
2289 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2290 if (pinfo & INSN_WRITE_GPR_31)
2291 mips_gprmask |= 1 << RA;
2292 if (pinfo & INSN_WRITE_FPR_D)
2293 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2294 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2295 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2296 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2297 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2298 if ((pinfo & INSN_READ_FPR_R) != 0)
2299 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2300 if (pinfo & INSN_COP)
2302 /* We don't keep enough information to sort these cases out.
2303 The itbl support does keep this information however, although
2304 we currently don't support itbl fprmats as part of the cop
2305 instruction. May want to add this support in the future. */
2307 /* Never set the bit for $0, which is always zero. */
2308 mips_gprmask &= ~1 << 0;
2312 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2313 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2314 & MIPS16OP_MASK_RX);
2315 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2316 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2317 & MIPS16OP_MASK_RY);
2318 if (pinfo & MIPS16_INSN_WRITE_Z)
2319 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2320 & MIPS16OP_MASK_RZ);
2321 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2322 mips_gprmask |= 1 << TREG;
2323 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2324 mips_gprmask |= 1 << SP;
2325 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2326 mips_gprmask |= 1 << RA;
2327 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2328 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2329 if (pinfo & MIPS16_INSN_READ_Z)
2330 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2331 & MIPS16OP_MASK_MOVE32Z);
2332 if (pinfo & MIPS16_INSN_READ_GPR_X)
2333 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2334 & MIPS16OP_MASK_REGR32);
2337 if (place == NULL && ! mips_opts.noreorder)
2339 /* Filling the branch delay slot is more complex. We try to
2340 switch the branch with the previous instruction, which we can
2341 do if the previous instruction does not set up a condition
2342 that the branch tests and if the branch is not itself the
2343 target of any branch. */
2344 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2345 || (pinfo & INSN_COND_BRANCH_DELAY))
2347 if (mips_optimize < 2
2348 /* If we have seen .set volatile or .set nomove, don't
2350 || mips_opts.nomove != 0
2351 /* If we had to emit any NOP instructions, then we
2352 already know we can not swap. */
2354 /* If we don't even know the previous insn, we can not
2356 || ! prev_insn_valid
2357 /* If the previous insn is already in a branch delay
2358 slot, then we can not swap. */
2359 || prev_insn_is_delay_slot
2360 /* If the previous previous insn was in a .set
2361 noreorder, we can't swap. Actually, the MIPS
2362 assembler will swap in this situation. However, gcc
2363 configured -with-gnu-as will generate code like
2369 in which we can not swap the bne and INSN. If gcc is
2370 not configured -with-gnu-as, it does not output the
2371 .set pseudo-ops. We don't have to check
2372 prev_insn_unreordered, because prev_insn_valid will
2373 be 0 in that case. We don't want to use
2374 prev_prev_insn_valid, because we do want to be able
2375 to swap at the start of a function. */
2376 || prev_prev_insn_unreordered
2377 /* If the branch is itself the target of a branch, we
2378 can not swap. We cheat on this; all we check for is
2379 whether there is a label on this instruction. If
2380 there are any branches to anything other than a
2381 label, users must use .set noreorder. */
2382 || insn_labels != NULL
2383 /* If the previous instruction is in a variant frag, we
2384 can not do the swap. This does not apply to the
2385 mips16, which uses variant frags for different
2387 || (! mips_opts.mips16
2388 && prev_insn_frag->fr_type == rs_machine_dependent)
2389 /* If the branch reads the condition codes, we don't
2390 even try to swap, because in the sequence
2395 we can not swap, and I don't feel like handling that
2397 || (! mips_opts.mips16
2398 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2399 && (pinfo & INSN_READ_COND_CODE))
2400 /* We can not swap with an instruction that requires a
2401 delay slot, becase the target of the branch might
2402 interfere with that instruction. */
2403 || (! mips_opts.mips16
2404 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2406 /* Itbl support may require additional care here. */
2407 & (INSN_LOAD_COPROC_DELAY
2408 | INSN_COPROC_MOVE_DELAY
2409 | INSN_WRITE_COND_CODE)))
2410 || (! (hilo_interlocks
2411 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2415 || (! mips_opts.mips16
2417 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2418 || (! mips_opts.mips16
2419 && mips_opts.isa == ISA_MIPS1
2420 /* Itbl support may require additional care here. */
2421 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2422 /* We can not swap with a branch instruction. */
2424 & (INSN_UNCOND_BRANCH_DELAY
2425 | INSN_COND_BRANCH_DELAY
2426 | INSN_COND_BRANCH_LIKELY))
2427 /* We do not swap with a trap instruction, since it
2428 complicates trap handlers to have the trap
2429 instruction be in a delay slot. */
2430 || (prev_pinfo & INSN_TRAP)
2431 /* If the branch reads a register that the previous
2432 instruction sets, we can not swap. */
2433 || (! mips_opts.mips16
2434 && (prev_pinfo & INSN_WRITE_GPR_T)
2435 && insn_uses_reg (ip,
2436 ((prev_insn.insn_opcode >> OP_SH_RT)
2439 || (! mips_opts.mips16
2440 && (prev_pinfo & INSN_WRITE_GPR_D)
2441 && insn_uses_reg (ip,
2442 ((prev_insn.insn_opcode >> OP_SH_RD)
2445 || (mips_opts.mips16
2446 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2447 && insn_uses_reg (ip,
2448 ((prev_insn.insn_opcode
2450 & MIPS16OP_MASK_RX),
2452 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2453 && insn_uses_reg (ip,
2454 ((prev_insn.insn_opcode
2456 & MIPS16OP_MASK_RY),
2458 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2459 && insn_uses_reg (ip,
2460 ((prev_insn.insn_opcode
2462 & MIPS16OP_MASK_RZ),
2464 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2465 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2466 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2467 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2468 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2469 && insn_uses_reg (ip,
2470 MIPS16OP_EXTRACT_REG32R (prev_insn.
2473 /* If the branch writes a register that the previous
2474 instruction sets, we can not swap (we know that
2475 branches write only to RD or to $31). */
2476 || (! mips_opts.mips16
2477 && (prev_pinfo & INSN_WRITE_GPR_T)
2478 && (((pinfo & INSN_WRITE_GPR_D)
2479 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2480 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2481 || ((pinfo & INSN_WRITE_GPR_31)
2482 && (((prev_insn.insn_opcode >> OP_SH_RT)
2485 || (! mips_opts.mips16
2486 && (prev_pinfo & INSN_WRITE_GPR_D)
2487 && (((pinfo & INSN_WRITE_GPR_D)
2488 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2489 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2490 || ((pinfo & INSN_WRITE_GPR_31)
2491 && (((prev_insn.insn_opcode >> OP_SH_RD)
2494 || (mips_opts.mips16
2495 && (pinfo & MIPS16_INSN_WRITE_31)
2496 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2497 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2498 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2500 /* If the branch writes a register that the previous
2501 instruction reads, we can not swap (we know that
2502 branches only write to RD or to $31). */
2503 || (! mips_opts.mips16
2504 && (pinfo & INSN_WRITE_GPR_D)
2505 && insn_uses_reg (&prev_insn,
2506 ((ip->insn_opcode >> OP_SH_RD)
2509 || (! mips_opts.mips16
2510 && (pinfo & INSN_WRITE_GPR_31)
2511 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2512 || (mips_opts.mips16
2513 && (pinfo & MIPS16_INSN_WRITE_31)
2514 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2515 /* If we are generating embedded PIC code, the branch
2516 might be expanded into a sequence which uses $at, so
2517 we can't swap with an instruction which reads it. */
2518 || (mips_pic == EMBEDDED_PIC
2519 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2520 /* If the previous previous instruction has a load
2521 delay, and sets a register that the branch reads, we
2523 || (! mips_opts.mips16
2524 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2525 /* Itbl support may require additional care here. */
2526 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2527 || (! gpr_interlocks
2528 && (prev_prev_insn.insn_mo->pinfo
2529 & INSN_LOAD_MEMORY_DELAY)))
2530 && insn_uses_reg (ip,
2531 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2534 /* If one instruction sets a condition code and the
2535 other one uses a condition code, we can not swap. */
2536 || ((pinfo & INSN_READ_COND_CODE)
2537 && (prev_pinfo & INSN_WRITE_COND_CODE))
2538 || ((pinfo & INSN_WRITE_COND_CODE)
2539 && (prev_pinfo & INSN_READ_COND_CODE))
2540 /* If the previous instruction uses the PC, we can not
2542 || (mips_opts.mips16
2543 && (prev_pinfo & MIPS16_INSN_READ_PC))
2544 /* If the previous instruction was extended, we can not
2546 || (mips_opts.mips16 && prev_insn_extended)
2547 /* If the previous instruction had a fixup in mips16
2548 mode, we can not swap. This normally means that the
2549 previous instruction was a 4 byte branch anyhow. */
2550 || (mips_opts.mips16 && prev_insn_fixp[0])
2551 /* If the previous instruction is a sync, sync.l, or
2552 sync.p, we can not swap. */
2553 || (prev_pinfo & INSN_SYNC))
2555 /* We could do even better for unconditional branches to
2556 portions of this object file; we could pick up the
2557 instruction at the destination, put it in the delay
2558 slot, and bump the destination address. */
2560 /* Update the previous insn information. */
2561 prev_prev_insn = *ip;
2562 prev_insn.insn_mo = &dummy_opcode;
2566 /* It looks like we can actually do the swap. */
2567 if (! mips_opts.mips16)
2572 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2573 memcpy (temp, prev_f, 4);
2574 memcpy (prev_f, f, 4);
2575 memcpy (f, temp, 4);
2576 if (prev_insn_fixp[0])
2578 prev_insn_fixp[0]->fx_frag = frag_now;
2579 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2581 if (prev_insn_fixp[1])
2583 prev_insn_fixp[1]->fx_frag = frag_now;
2584 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2586 if (prev_insn_fixp[2])
2588 prev_insn_fixp[2]->fx_frag = frag_now;
2589 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2591 if (prev_insn_fixp[0] && HAVE_NEWABI
2592 && prev_insn_frag != frag_now
2593 && (prev_insn_fixp[0]->fx_r_type
2594 == BFD_RELOC_MIPS_GOT_DISP
2595 || (prev_insn_fixp[0]->fx_r_type
2596 == BFD_RELOC_MIPS_CALL16)))
2598 /* To avoid confusion in tc_gen_reloc, we must
2599 ensure that this does not become a variant
2601 force_new_frag = TRUE;
2605 fixp[0]->fx_frag = prev_insn_frag;
2606 fixp[0]->fx_where = prev_insn_where;
2610 fixp[1]->fx_frag = prev_insn_frag;
2611 fixp[1]->fx_where = prev_insn_where;
2615 fixp[2]->fx_frag = prev_insn_frag;
2616 fixp[2]->fx_where = prev_insn_where;
2624 assert (prev_insn_fixp[0] == NULL);
2625 assert (prev_insn_fixp[1] == NULL);
2626 assert (prev_insn_fixp[2] == NULL);
2627 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2628 memcpy (temp, prev_f, 2);
2629 memcpy (prev_f, f, 2);
2630 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2632 assert (*reloc_type == BFD_RELOC_UNUSED);
2633 memcpy (f, temp, 2);
2637 memcpy (f, f + 2, 2);
2638 memcpy (f + 2, temp, 2);
2642 fixp[0]->fx_frag = prev_insn_frag;
2643 fixp[0]->fx_where = prev_insn_where;
2647 fixp[1]->fx_frag = prev_insn_frag;
2648 fixp[1]->fx_where = prev_insn_where;
2652 fixp[2]->fx_frag = prev_insn_frag;
2653 fixp[2]->fx_where = prev_insn_where;
2657 /* Update the previous insn information; leave prev_insn
2659 prev_prev_insn = *ip;
2661 prev_insn_is_delay_slot = 1;
2663 /* If that was an unconditional branch, forget the previous
2664 insn information. */
2665 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2667 prev_prev_insn.insn_mo = &dummy_opcode;
2668 prev_insn.insn_mo = &dummy_opcode;
2671 prev_insn_fixp[0] = NULL;
2672 prev_insn_fixp[1] = NULL;
2673 prev_insn_fixp[2] = NULL;
2674 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2675 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2676 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2677 prev_insn_extended = 0;
2679 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2681 /* We don't yet optimize a branch likely. What we should do
2682 is look at the target, copy the instruction found there
2683 into the delay slot, and increment the branch to jump to
2684 the next instruction. */
2686 /* Update the previous insn information. */
2687 prev_prev_insn = *ip;
2688 prev_insn.insn_mo = &dummy_opcode;
2689 prev_insn_fixp[0] = NULL;
2690 prev_insn_fixp[1] = NULL;
2691 prev_insn_fixp[2] = NULL;
2692 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2693 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2694 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2695 prev_insn_extended = 0;
2699 /* Update the previous insn information. */
2701 prev_prev_insn.insn_mo = &dummy_opcode;
2703 prev_prev_insn = prev_insn;
2706 /* Any time we see a branch, we always fill the delay slot
2707 immediately; since this insn is not a branch, we know it
2708 is not in a delay slot. */
2709 prev_insn_is_delay_slot = 0;
2711 prev_insn_fixp[0] = fixp[0];
2712 prev_insn_fixp[1] = fixp[1];
2713 prev_insn_fixp[2] = fixp[2];
2714 prev_insn_reloc_type[0] = reloc_type[0];
2715 prev_insn_reloc_type[1] = reloc_type[1];
2716 prev_insn_reloc_type[2] = reloc_type[2];
2717 if (mips_opts.mips16)
2718 prev_insn_extended = (ip->use_extend
2719 || *reloc_type > BFD_RELOC_UNUSED);
2722 prev_prev_insn_unreordered = prev_insn_unreordered;
2723 prev_insn_unreordered = 0;
2724 prev_insn_frag = frag_now;
2725 prev_insn_where = f - frag_now->fr_literal;
2726 prev_insn_valid = 1;
2728 else if (place == NULL)
2730 /* We need to record a bit of information even when we are not
2731 reordering, in order to determine the base address for mips16
2732 PC relative relocs. */
2733 prev_prev_insn = prev_insn;
2735 prev_insn_reloc_type[0] = reloc_type[0];
2736 prev_insn_reloc_type[1] = reloc_type[1];
2737 prev_insn_reloc_type[2] = reloc_type[2];
2738 prev_prev_insn_unreordered = prev_insn_unreordered;
2739 prev_insn_unreordered = 1;
2742 /* We just output an insn, so the next one doesn't have a label. */
2743 mips_clear_insn_labels ();
2745 /* We must ensure that the frag to which an instruction that was
2746 moved from a non-variant frag doesn't become a variant frag,
2747 otherwise tc_gen_reloc may get confused. */
2750 frag_wane (frag_now);
2755 /* This function forgets that there was any previous instruction or
2756 label. If PRESERVE is non-zero, it remembers enough information to
2757 know whether nops are needed before a noreorder section. */
2760 mips_no_prev_insn (preserve)
2765 prev_insn.insn_mo = &dummy_opcode;
2766 prev_prev_insn.insn_mo = &dummy_opcode;
2767 prev_nop_frag = NULL;
2768 prev_nop_frag_holds = 0;
2769 prev_nop_frag_required = 0;
2770 prev_nop_frag_since = 0;
2772 prev_insn_valid = 0;
2773 prev_insn_is_delay_slot = 0;
2774 prev_insn_unreordered = 0;
2775 prev_insn_extended = 0;
2776 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2777 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2778 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2779 prev_prev_insn_unreordered = 0;
2780 mips_clear_insn_labels ();
2783 /* This function must be called whenever we turn on noreorder or emit
2784 something other than instructions. It inserts any NOPS which might
2785 be needed by the previous instruction, and clears the information
2786 kept for the previous instructions. The INSNS parameter is true if
2787 instructions are to follow. */
2790 mips_emit_delays (insns)
2793 if (! mips_opts.noreorder)
2798 if ((! mips_opts.mips16
2799 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2800 && (! cop_interlocks
2801 && (prev_insn.insn_mo->pinfo
2802 & (INSN_LOAD_COPROC_DELAY
2803 | INSN_COPROC_MOVE_DELAY
2804 | INSN_WRITE_COND_CODE))))
2805 || (! hilo_interlocks
2806 && (prev_insn.insn_mo->pinfo
2809 || (! mips_opts.mips16
2811 && (prev_insn.insn_mo->pinfo
2812 & INSN_LOAD_MEMORY_DELAY))
2813 || (! mips_opts.mips16
2814 && mips_opts.isa == ISA_MIPS1
2815 && (prev_insn.insn_mo->pinfo
2816 & INSN_COPROC_MEMORY_DELAY)))
2818 /* Itbl support may require additional care here. */
2820 if ((! mips_opts.mips16
2821 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2822 && (! cop_interlocks
2823 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2824 || (! hilo_interlocks
2825 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2826 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2829 if (prev_insn_unreordered)
2832 else if ((! mips_opts.mips16
2833 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2834 && (! cop_interlocks
2835 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2836 || (! hilo_interlocks
2837 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2838 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2840 /* Itbl support may require additional care here. */
2841 if (! prev_prev_insn_unreordered)
2845 if (mips_fix_4122_bugs && prev_insn.insn_mo->name)
2848 const char *pn = prev_insn.insn_mo->name;
2849 if (strncmp(pn, "macc", 4) == 0
2850 || strncmp(pn, "dmacc", 5) == 0
2851 || strncmp(pn, "dmult", 5) == 0)
2855 if (nops < min_nops)
2861 struct insn_label_list *l;
2865 /* Record the frag which holds the nop instructions, so
2866 that we can remove them if we don't need them. */
2867 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2868 prev_nop_frag = frag_now;
2869 prev_nop_frag_holds = nops;
2870 prev_nop_frag_required = 0;
2871 prev_nop_frag_since = 0;
2874 for (; nops > 0; --nops)
2879 /* Move on to a new frag, so that it is safe to simply
2880 decrease the size of prev_nop_frag. */
2881 frag_wane (frag_now);
2885 for (l = insn_labels; l != NULL; l = l->next)
2889 assert (S_GET_SEGMENT (l->label) == now_seg);
2890 symbol_set_frag (l->label, frag_now);
2891 val = (valueT) frag_now_fix ();
2892 /* mips16 text labels are stored as odd. */
2893 if (mips_opts.mips16)
2895 S_SET_VALUE (l->label, val);
2900 /* Mark instruction labels in mips16 mode. */
2902 mips16_mark_labels ();
2904 mips_no_prev_insn (insns);
2907 /* Build an instruction created by a macro expansion. This is passed
2908 a pointer to the count of instructions created so far, an
2909 expression, the name of the instruction to build, an operand format
2910 string, and corresponding arguments. */
2914 macro_build (char *place,
2922 macro_build (place, counter, ep, name, fmt, va_alist)
2931 struct mips_cl_insn insn;
2932 bfd_reloc_code_real_type r[3];
2936 va_start (args, fmt);
2942 * If the macro is about to expand into a second instruction,
2943 * print a warning if needed. We need to pass ip as a parameter
2944 * to generate a better warning message here...
2946 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2947 as_warn (_("Macro instruction expanded into multiple instructions"));
2950 * If the macro is about to expand into a second instruction,
2951 * and it is in a delay slot, print a warning.
2955 && mips_opts.noreorder
2956 && (prev_prev_insn.insn_mo->pinfo
2957 & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY
2958 | INSN_COND_BRANCH_LIKELY)) != 0)
2959 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2962 ++*counter; /* bump instruction counter */
2964 if (mips_opts.mips16)
2966 mips16_macro_build (place, counter, ep, name, fmt, args);
2971 r[0] = BFD_RELOC_UNUSED;
2972 r[1] = BFD_RELOC_UNUSED;
2973 r[2] = BFD_RELOC_UNUSED;
2974 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2975 assert (insn.insn_mo);
2976 assert (strcmp (name, insn.insn_mo->name) == 0);
2978 /* Search until we get a match for NAME. */
2981 /* It is assumed here that macros will never generate
2982 MDMX or MIPS-3D instructions. */
2983 if (strcmp (fmt, insn.insn_mo->args) == 0
2984 && insn.insn_mo->pinfo != INSN_MACRO
2985 && OPCODE_IS_MEMBER (insn.insn_mo,
2987 | (file_ase_mips16 ? INSN_MIPS16 : 0)),
2989 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2993 assert (insn.insn_mo->name);
2994 assert (strcmp (name, insn.insn_mo->name) == 0);
2997 insn.insn_opcode = insn.insn_mo->match;
3013 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
3017 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
3022 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
3028 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
3033 int tmp = va_arg (args, int);
3035 insn.insn_opcode |= tmp << OP_SH_RT;
3036 insn.insn_opcode |= tmp << OP_SH_RD;
3042 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
3049 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
3053 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
3057 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
3061 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
3065 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
3072 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
3078 *r = (bfd_reloc_code_real_type) va_arg (args, int);
3079 assert (*r == BFD_RELOC_GPREL16
3080 || *r == BFD_RELOC_MIPS_LITERAL
3081 || *r == BFD_RELOC_MIPS_HIGHER
3082 || *r == BFD_RELOC_HI16_S
3083 || *r == BFD_RELOC_LO16
3084 || *r == BFD_RELOC_MIPS_GOT16
3085 || *r == BFD_RELOC_MIPS_CALL16
3086 || *r == BFD_RELOC_MIPS_GOT_DISP
3087 || *r == BFD_RELOC_MIPS_GOT_PAGE
3088 || *r == BFD_RELOC_MIPS_GOT_OFST
3089 || *r == BFD_RELOC_MIPS_GOT_LO16
3090 || *r == BFD_RELOC_MIPS_CALL_LO16
3091 || (ep->X_op == O_subtract
3092 && *r == BFD_RELOC_PCREL_LO16));
3096 *r = (bfd_reloc_code_real_type) va_arg (args, int);
3098 && (ep->X_op == O_constant
3099 || (ep->X_op == O_symbol
3100 && (*r == BFD_RELOC_MIPS_HIGHEST
3101 || *r == BFD_RELOC_HI16_S
3102 || *r == BFD_RELOC_HI16
3103 || *r == BFD_RELOC_GPREL16
3104 || *r == BFD_RELOC_MIPS_GOT_HI16
3105 || *r == BFD_RELOC_MIPS_CALL_HI16))
3106 || (ep->X_op == O_subtract
3107 && *r == BFD_RELOC_PCREL_HI16_S)));
3111 assert (ep != NULL);
3113 * This allows macro() to pass an immediate expression for
3114 * creating short branches without creating a symbol.
3115 * Note that the expression still might come from the assembly
3116 * input, in which case the value is not checked for range nor
3117 * is a relocation entry generated (yuck).
3119 if (ep->X_op == O_constant)
3121 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
3125 *r = BFD_RELOC_16_PCREL_S2;
3129 assert (ep != NULL);
3130 *r = BFD_RELOC_MIPS_JMP;
3134 insn.insn_opcode |= va_arg (args, unsigned long);
3143 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3145 append_insn (place, &insn, ep, r);
3149 mips16_macro_build (place, counter, ep, name, fmt, args)
3151 int *counter ATTRIBUTE_UNUSED;
3157 struct mips_cl_insn insn;
3158 bfd_reloc_code_real_type r[3]
3159 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3161 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3162 assert (insn.insn_mo);
3163 assert (strcmp (name, insn.insn_mo->name) == 0);
3165 while (strcmp (fmt, insn.insn_mo->args) != 0
3166 || insn.insn_mo->pinfo == INSN_MACRO)
3169 assert (insn.insn_mo->name);
3170 assert (strcmp (name, insn.insn_mo->name) == 0);
3173 insn.insn_opcode = insn.insn_mo->match;
3174 insn.use_extend = FALSE;
3193 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
3198 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
3202 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
3206 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
3216 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
3223 regno = va_arg (args, int);
3224 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3225 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3246 assert (ep != NULL);
3248 if (ep->X_op != O_constant)
3249 *r = (int) BFD_RELOC_UNUSED + c;
3252 mips16_immed (NULL, 0, c, ep->X_add_number, FALSE, FALSE,
3253 FALSE, &insn.insn_opcode, &insn.use_extend,
3256 *r = BFD_RELOC_UNUSED;
3262 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3269 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3271 append_insn (place, &insn, ep, r);
3275 * Generate a "jalr" instruction with a relocation hint to the called
3276 * function. This occurs in NewABI PIC code.
3279 macro_build_jalr (icnt, ep)
3290 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", "d,s",
3293 fix_new_exp (frag_now, f - frag_now->fr_literal,
3294 4, ep, FALSE, BFD_RELOC_MIPS_JALR);
3298 * Generate a "lui" instruction.
3301 macro_build_lui (place, counter, ep, regnum)
3307 expressionS high_expr;
3308 struct mips_cl_insn insn;
3309 bfd_reloc_code_real_type r[3]
3310 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3311 const char *name = "lui";
3312 const char *fmt = "t,u";
3314 assert (! mips_opts.mips16);
3320 high_expr.X_op = O_constant;
3321 high_expr.X_add_number = ep->X_add_number;
3324 if (high_expr.X_op == O_constant)
3326 /* we can compute the instruction now without a relocation entry */
3327 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3329 *r = BFD_RELOC_UNUSED;
3333 assert (ep->X_op == O_symbol);
3334 /* _gp_disp is a special case, used from s_cpload. */
3335 assert (mips_pic == NO_PIC
3337 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0));
3338 *r = BFD_RELOC_HI16_S;
3342 * If the macro is about to expand into a second instruction,
3343 * print a warning if needed. We need to pass ip as a parameter
3344 * to generate a better warning message here...
3346 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3347 as_warn (_("Macro instruction expanded into multiple instructions"));
3350 ++*counter; /* bump instruction counter */
3352 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3353 assert (insn.insn_mo);
3354 assert (strcmp (name, insn.insn_mo->name) == 0);
3355 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3357 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3358 if (*r == BFD_RELOC_UNUSED)
3360 insn.insn_opcode |= high_expr.X_add_number;
3361 append_insn (place, &insn, NULL, r);
3364 append_insn (place, &insn, &high_expr, r);
3367 /* Generate a sequence of instructions to do a load or store from a constant
3368 offset off of a base register (breg) into/from a target register (treg),
3369 using AT if necessary. */
3371 macro_build_ldst_constoffset (place, counter, ep, op, treg, breg)
3378 assert (ep->X_op == O_constant);
3380 /* Right now, this routine can only handle signed 32-bit contants. */
3381 if (! IS_SEXT_32BIT_NUM(ep->X_add_number))
3382 as_warn (_("operand overflow"));
3384 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
3386 /* Signed 16-bit offset will fit in the op. Easy! */
3387 macro_build (place, counter, ep, op, "t,o(b)", treg,
3388 (int) BFD_RELOC_LO16, breg);
3392 /* 32-bit offset, need multiple instructions and AT, like:
3393 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3394 addu $tempreg,$tempreg,$breg
3395 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3396 to handle the complete offset. */
3397 macro_build_lui (place, counter, ep, AT);
3400 macro_build (place, counter, (expressionS *) NULL, ADDRESS_ADD_INSN,
3401 "d,v,t", AT, AT, breg);
3404 macro_build (place, counter, ep, op, "t,o(b)", treg,
3405 (int) BFD_RELOC_LO16, AT);
3408 as_warn (_("Macro used $at after \".set noat\""));
3413 * Generates code to set the $at register to true (one)
3414 * if reg is less than the immediate expression.
3417 set_at (counter, reg, unsignedp)
3422 if (imm_expr.X_op == O_constant
3423 && imm_expr.X_add_number >= -0x8000
3424 && imm_expr.X_add_number < 0x8000)
3425 macro_build ((char *) NULL, counter, &imm_expr,
3426 unsignedp ? "sltiu" : "slti",
3427 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
3430 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3431 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3432 unsignedp ? "sltu" : "slt",
3433 "d,v,t", AT, reg, AT);
3437 /* Warn if an expression is not a constant. */
3440 check_absolute_expr (ip, ex)
3441 struct mips_cl_insn *ip;
3444 if (ex->X_op == O_big)
3445 as_bad (_("unsupported large constant"));
3446 else if (ex->X_op != O_constant)
3447 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3450 /* Count the leading zeroes by performing a binary chop. This is a
3451 bulky bit of source, but performance is a LOT better for the
3452 majority of values than a simple loop to count the bits:
3453 for (lcnt = 0; (lcnt < 32); lcnt++)
3454 if ((v) & (1 << (31 - lcnt)))
3456 However it is not code size friendly, and the gain will drop a bit
3457 on certain cached systems.
3459 #define COUNT_TOP_ZEROES(v) \
3460 (((v) & ~0xffff) == 0 \
3461 ? ((v) & ~0xff) == 0 \
3462 ? ((v) & ~0xf) == 0 \
3463 ? ((v) & ~0x3) == 0 \
3464 ? ((v) & ~0x1) == 0 \
3469 : ((v) & ~0x7) == 0 \
3472 : ((v) & ~0x3f) == 0 \
3473 ? ((v) & ~0x1f) == 0 \
3476 : ((v) & ~0x7f) == 0 \
3479 : ((v) & ~0xfff) == 0 \
3480 ? ((v) & ~0x3ff) == 0 \
3481 ? ((v) & ~0x1ff) == 0 \
3484 : ((v) & ~0x7ff) == 0 \
3487 : ((v) & ~0x3fff) == 0 \
3488 ? ((v) & ~0x1fff) == 0 \
3491 : ((v) & ~0x7fff) == 0 \
3494 : ((v) & ~0xffffff) == 0 \
3495 ? ((v) & ~0xfffff) == 0 \
3496 ? ((v) & ~0x3ffff) == 0 \
3497 ? ((v) & ~0x1ffff) == 0 \
3500 : ((v) & ~0x7ffff) == 0 \
3503 : ((v) & ~0x3fffff) == 0 \
3504 ? ((v) & ~0x1fffff) == 0 \
3507 : ((v) & ~0x7fffff) == 0 \
3510 : ((v) & ~0xfffffff) == 0 \
3511 ? ((v) & ~0x3ffffff) == 0 \
3512 ? ((v) & ~0x1ffffff) == 0 \
3515 : ((v) & ~0x7ffffff) == 0 \
3518 : ((v) & ~0x3fffffff) == 0 \
3519 ? ((v) & ~0x1fffffff) == 0 \
3522 : ((v) & ~0x7fffffff) == 0 \
3527 * This routine generates the least number of instructions neccessary to load
3528 * an absolute expression value into a register.
3531 load_register (counter, reg, ep, dbl)
3538 expressionS hi32, lo32;
3540 if (ep->X_op != O_big)
3542 assert (ep->X_op == O_constant);
3543 if (ep->X_add_number < 0x8000
3544 && (ep->X_add_number >= 0
3545 || (ep->X_add_number >= -0x8000
3548 || sizeof (ep->X_add_number) > 4))))
3550 /* We can handle 16 bit signed values with an addiu to
3551 $zero. No need to ever use daddiu here, since $zero and
3552 the result are always correct in 32 bit mode. */
3553 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3554 (int) BFD_RELOC_LO16);
3557 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3559 /* We can handle 16 bit unsigned values with an ori to
3561 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3562 (int) BFD_RELOC_LO16);
3565 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)
3568 || sizeof (ep->X_add_number) > 4
3569 || (ep->X_add_number & 0x80000000) == 0))
3570 || ((HAVE_32BIT_GPRS || ! dbl)
3571 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3574 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3575 == ~ (offsetT) 0xffffffff)))
3577 /* 32 bit values require an lui. */
3578 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3579 (int) BFD_RELOC_HI16);
3580 if ((ep->X_add_number & 0xffff) != 0)
3581 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3582 (int) BFD_RELOC_LO16);
3587 /* The value is larger than 32 bits. */
3589 if (HAVE_32BIT_GPRS)
3591 as_bad (_("Number (0x%lx) larger than 32 bits"),
3592 (unsigned long) ep->X_add_number);
3593 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3594 (int) BFD_RELOC_LO16);
3598 if (ep->X_op != O_big)
3601 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3602 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3603 hi32.X_add_number &= 0xffffffff;
3605 lo32.X_add_number &= 0xffffffff;
3609 assert (ep->X_add_number > 2);
3610 if (ep->X_add_number == 3)
3611 generic_bignum[3] = 0;
3612 else if (ep->X_add_number > 4)
3613 as_bad (_("Number larger than 64 bits"));
3614 lo32.X_op = O_constant;
3615 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3616 hi32.X_op = O_constant;
3617 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3620 if (hi32.X_add_number == 0)
3625 unsigned long hi, lo;
3627 if (hi32.X_add_number == (offsetT) 0xffffffff)
3629 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3631 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3632 reg, 0, (int) BFD_RELOC_LO16);
3635 if (lo32.X_add_number & 0x80000000)
3637 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3638 (int) BFD_RELOC_HI16);
3639 if (lo32.X_add_number & 0xffff)
3640 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3641 reg, reg, (int) BFD_RELOC_LO16);
3646 /* Check for 16bit shifted constant. We know that hi32 is
3647 non-zero, so start the mask on the first bit of the hi32
3652 unsigned long himask, lomask;
3656 himask = 0xffff >> (32 - shift);
3657 lomask = (0xffff << shift) & 0xffffffff;
3661 himask = 0xffff << (shift - 32);
3664 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3665 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3669 tmp.X_op = O_constant;
3671 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3672 | (lo32.X_add_number >> shift));
3674 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3675 macro_build ((char *) NULL, counter, &tmp,
3676 "ori", "t,r,i", reg, 0,
3677 (int) BFD_RELOC_LO16);
3678 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3679 (shift >= 32) ? "dsll32" : "dsll",
3681 (shift >= 32) ? shift - 32 : shift);
3686 while (shift <= (64 - 16));
3688 /* Find the bit number of the lowest one bit, and store the
3689 shifted value in hi/lo. */
3690 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3691 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3695 while ((lo & 1) == 0)
3700 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3706 while ((hi & 1) == 0)
3715 /* Optimize if the shifted value is a (power of 2) - 1. */
3716 if ((hi == 0 && ((lo + 1) & lo) == 0)
3717 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3719 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3724 /* This instruction will set the register to be all
3726 tmp.X_op = O_constant;
3727 tmp.X_add_number = (offsetT) -1;
3728 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3729 reg, 0, (int) BFD_RELOC_LO16);
3733 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3734 (bit >= 32) ? "dsll32" : "dsll",
3736 (bit >= 32) ? bit - 32 : bit);
3738 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3739 (shift >= 32) ? "dsrl32" : "dsrl",
3741 (shift >= 32) ? shift - 32 : shift);
3746 /* Sign extend hi32 before calling load_register, because we can
3747 generally get better code when we load a sign extended value. */
3748 if ((hi32.X_add_number & 0x80000000) != 0)
3749 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3750 load_register (counter, reg, &hi32, 0);
3753 if ((lo32.X_add_number & 0xffff0000) == 0)
3757 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3758 "dsll32", "d,w,<", reg, freg, 0);
3766 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3768 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3769 (int) BFD_RELOC_HI16);
3770 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3771 "dsrl32", "d,w,<", reg, reg, 0);
3777 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3778 "d,w,<", reg, freg, 16);
3782 mid16.X_add_number >>= 16;
3783 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3784 freg, (int) BFD_RELOC_LO16);
3785 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3786 "d,w,<", reg, reg, 16);
3789 if ((lo32.X_add_number & 0xffff) != 0)
3790 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3791 (int) BFD_RELOC_LO16);
3794 /* Load an address into a register. */
3797 load_address (counter, reg, ep, used_at)
3805 if (ep->X_op != O_constant
3806 && ep->X_op != O_symbol)
3808 as_bad (_("expression too complex"));
3809 ep->X_op = O_constant;
3812 if (ep->X_op == O_constant)
3814 load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES);
3818 if (mips_pic == NO_PIC)
3820 /* If this is a reference to a GP relative symbol, we want
3821 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3823 lui $reg,<sym> (BFD_RELOC_HI16_S)
3824 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3825 If we have an addend, we always use the latter form.
3827 With 64bit address space and a usable $at we want
3828 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3829 lui $at,<sym> (BFD_RELOC_HI16_S)
3830 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3831 daddiu $at,<sym> (BFD_RELOC_LO16)
3835 If $at is already in use, we use a path which is suboptimal
3836 on superscalar processors.
3837 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3838 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3840 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3842 daddiu $reg,<sym> (BFD_RELOC_LO16)
3844 if (HAVE_64BIT_ADDRESSES)
3846 /* We don't do GP optimization for now because RELAX_ENCODE can't
3847 hold the data for such large chunks. */
3849 if (*used_at == 0 && ! mips_opts.noat)
3851 macro_build (p, counter, ep, "lui", "t,u",
3852 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3853 macro_build (p, counter, ep, "lui", "t,u",
3854 AT, (int) BFD_RELOC_HI16_S);
3855 macro_build (p, counter, ep, "daddiu", "t,r,j",
3856 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3857 macro_build (p, counter, ep, "daddiu", "t,r,j",
3858 AT, AT, (int) BFD_RELOC_LO16);
3859 macro_build (p, counter, (expressionS *) NULL, "dsll32",
3860 "d,w,<", reg, reg, 0);
3861 macro_build (p, counter, (expressionS *) NULL, "daddu",
3862 "d,v,t", reg, reg, AT);
3867 macro_build (p, counter, ep, "lui", "t,u",
3868 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3869 macro_build (p, counter, ep, "daddiu", "t,r,j",
3870 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3871 macro_build (p, counter, (expressionS *) NULL, "dsll",
3872 "d,w,<", reg, reg, 16);
3873 macro_build (p, counter, ep, "daddiu", "t,r,j",
3874 reg, reg, (int) BFD_RELOC_HI16_S);
3875 macro_build (p, counter, (expressionS *) NULL, "dsll",
3876 "d,w,<", reg, reg, 16);
3877 macro_build (p, counter, ep, "daddiu", "t,r,j",
3878 reg, reg, (int) BFD_RELOC_LO16);
3883 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3884 && ! nopic_need_relax (ep->X_add_symbol, 1))
3887 macro_build ((char *) NULL, counter, ep, ADDRESS_ADDI_INSN,
3888 "t,r,j", reg, mips_gp_register,
3889 (int) BFD_RELOC_GPREL16);
3890 p = frag_var (rs_machine_dependent, 8, 0,
3891 RELAX_ENCODE (4, 8, 0, 4, 0,
3892 mips_opts.warn_about_macros),
3893 ep->X_add_symbol, 0, NULL);
3895 macro_build_lui (p, counter, ep, reg);
3898 macro_build (p, counter, ep, ADDRESS_ADDI_INSN,
3899 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3902 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3906 /* If this is a reference to an external symbol, we want
3907 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3909 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3911 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3912 If there is a constant, it must be added in after.
3914 If we have NewABI, we want
3915 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
3916 unless we're referencing a global symbol with a non-zero
3917 offset, in which case cst must be added separately. */
3922 if (ep->X_add_number)
3924 frag_now->tc_frag_data.tc_fr_offset =
3925 ex.X_add_number = ep->X_add_number;
3926 ep->X_add_number = 0;
3927 macro_build ((char *) NULL, counter, ep, ADDRESS_LOAD_INSN,
3928 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_DISP,
3930 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3931 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3932 ex.X_op = O_constant;
3933 macro_build ((char *) NULL, counter, &ex, ADDRESS_ADDI_INSN,
3934 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3935 p = frag_var (rs_machine_dependent, 8, 0,
3936 RELAX_ENCODE (8, 4, 0, 0, 0,
3937 mips_opts.warn_about_macros),
3938 ep->X_add_symbol, 0, (char *) NULL);
3939 ep->X_add_number = ex.X_add_number;
3942 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3943 (int) BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3947 /* To avoid confusion in tc_gen_reloc, we must ensure
3948 that this does not become a variant frag. */
3949 frag_wane (frag_now);
3955 ex.X_add_number = ep->X_add_number;
3956 ep->X_add_number = 0;
3958 macro_build ((char *) NULL, counter, ep, ADDRESS_LOAD_INSN,
3959 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16,
3961 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3962 p = frag_var (rs_machine_dependent, 4, 0,
3963 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3964 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3965 macro_build (p, counter, ep, ADDRESS_ADDI_INSN,
3966 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3968 if (ex.X_add_number != 0)
3970 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3971 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3972 ex.X_op = O_constant;
3973 macro_build ((char *) NULL, counter, &ex, ADDRESS_ADDI_INSN,
3974 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3978 else if (mips_pic == SVR4_PIC)
3983 /* This is the large GOT case. If this is a reference to an
3984 external symbol, we want
3985 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3987 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3989 Otherwise, for a reference to a local symbol in old ABI, we want
3990 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3992 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3993 If there is a constant, it must be added in after.
3995 In the NewABI, for local symbols, with or without offsets, we want:
3996 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3997 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
4003 frag_now->tc_frag_data.tc_fr_offset =
4004 ex.X_add_number = ep->X_add_number;
4005 ep->X_add_number = 0;
4006 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
4007 (int) BFD_RELOC_MIPS_GOT_HI16);
4008 macro_build ((char *) NULL, counter, (expressionS *) NULL,
4009 ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
4010 macro_build ((char *) NULL, counter, ep, ADDRESS_LOAD_INSN,
4011 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
4012 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
4013 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4014 else if (ex.X_add_number)
4016 ex.X_op = O_constant;
4017 macro_build ((char *) NULL, counter, &ex, ADDRESS_ADDI_INSN,
4018 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
4021 ep->X_add_number = ex.X_add_number;
4022 p = frag_var (rs_machine_dependent, 8, 0,
4023 RELAX_ENCODE (ex.X_add_number ? 16 : 12, 8, 0, 4, 0,
4024 mips_opts.warn_about_macros),
4025 ep->X_add_symbol, 0, (char *) NULL);
4026 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
4027 (int) BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
4028 macro_build (p + 4, counter, ep, ADDRESS_ADDI_INSN, "t,r,j",
4029 reg, reg, (int) BFD_RELOC_MIPS_GOT_OFST);
4033 ex.X_add_number = ep->X_add_number;
4034 ep->X_add_number = 0;
4035 if (reg_needs_delay (mips_gp_register))
4040 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
4041 (int) BFD_RELOC_MIPS_GOT_HI16);
4042 macro_build ((char *) NULL, counter, (expressionS *) NULL,
4043 ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
4044 macro_build ((char *) NULL, counter, ep, ADDRESS_LOAD_INSN,
4045 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
4046 p = frag_var (rs_machine_dependent, 12 + off, 0,
4047 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
4048 mips_opts.warn_about_macros),
4049 ep->X_add_symbol, 0, NULL);
4052 /* We need a nop before loading from $gp. This special
4053 check is required because the lui which starts the main
4054 instruction stream does not refer to $gp, and so will not
4055 insert the nop which may be required. */
4056 macro_build (p, counter, (expressionS *) NULL, "nop", "");
4059 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
4060 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
4062 macro_build (p, counter, (expressionS *) NULL, "nop", "");
4064 macro_build (p, counter, ep, ADDRESS_ADDI_INSN,
4065 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
4067 if (ex.X_add_number != 0)
4069 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
4070 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4071 ex.X_op = O_constant;
4072 macro_build ((char *) NULL, counter, &ex, ADDRESS_ADDI_INSN,
4073 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
4077 else if (mips_pic == EMBEDDED_PIC)
4080 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
4082 macro_build ((char *) NULL, counter, ep, ADDRESS_ADDI_INSN,
4083 "t,r,j", reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
4089 /* Move the contents of register SOURCE into register DEST. */
4092 move_register (counter, dest, source)
4097 macro_build ((char *) NULL, counter, (expressionS *) NULL,
4098 HAVE_32BIT_GPRS ? "addu" : "daddu",
4099 "d,v,t", dest, source, 0);
4104 * This routine implements the seemingly endless macro or synthesized
4105 * instructions and addressing modes in the mips assembly language. Many
4106 * of these macros are simple and are similar to each other. These could
4107 * probably be handled by some kind of table or grammer aproach instead of
4108 * this verbose method. Others are not simple macros but are more like
4109 * optimizing code generation.
4110 * One interesting optimization is when several store macros appear
4111 * consecutivly that would load AT with the upper half of the same address.
4112 * The ensuing load upper instructions are ommited. This implies some kind
4113 * of global optimization. We currently only optimize within a single macro.
4114 * For many of the load and store macros if the address is specified as a
4115 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
4116 * first load register 'at' with zero and use it as the base register. The
4117 * mips assembler simply uses register $zero. Just one tiny optimization
4122 struct mips_cl_insn *ip;
4124 register int treg, sreg, dreg, breg;
4140 bfd_reloc_code_real_type r;
4141 int hold_mips_optimize;
4143 assert (! mips_opts.mips16);
4145 treg = (ip->insn_opcode >> 16) & 0x1f;
4146 dreg = (ip->insn_opcode >> 11) & 0x1f;
4147 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
4148 mask = ip->insn_mo->mask;
4150 expr1.X_op = O_constant;
4151 expr1.X_op_symbol = NULL;
4152 expr1.X_add_symbol = NULL;
4153 expr1.X_add_number = 1;
4155 /* Umatched fixups should not be put in the same frag as a relaxable
4156 macro. For example, suppose we have:
4160 addiu $4,$4,%lo(l1) # 3
4162 If instructions 1 and 2 were put in the same frag, md_frob_file would
4163 move the fixup for #1 after the fixups for the "unrelaxed" version of
4164 #2. This would confuse tc_gen_reloc, which expects the relocations
4165 for #2 to be the last for that frag.
4167 Also, if tc_gen_reloc sees certain relocations in a variant frag,
4168 it assumes that they belong to a relaxable macro. We mustn't put
4169 other uses of such relocations into a variant frag.
4171 To avoid both problems, finish the current frag it contains a
4172 %reloc() operator. The macro then goes into a new frag. */
4173 if (prev_reloc_op_frag == frag_now)
4175 frag_wane (frag_now);
4189 mips_emit_delays (TRUE);
4190 ++mips_opts.noreorder;
4191 mips_any_noreorder = 1;
4193 expr1.X_add_number = 8;
4194 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
4196 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4199 move_register (&icnt, dreg, sreg);
4200 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4201 dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
4203 --mips_opts.noreorder;
4224 if (imm_expr.X_op == O_constant
4225 && imm_expr.X_add_number >= -0x8000
4226 && imm_expr.X_add_number < 0x8000)
4228 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
4229 (int) BFD_RELOC_LO16);
4232 load_register (&icnt, AT, &imm_expr, dbl);
4233 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
4253 if (imm_expr.X_op == O_constant
4254 && imm_expr.X_add_number >= 0
4255 && imm_expr.X_add_number < 0x10000)
4257 if (mask != M_NOR_I)
4258 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
4259 sreg, (int) BFD_RELOC_LO16);
4262 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
4263 treg, sreg, (int) BFD_RELOC_LO16);
4264 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor",
4265 "d,v,t", treg, treg, 0);
4270 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4271 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
4289 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4291 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
4295 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4296 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
4304 macro_build ((char *) NULL, &icnt, &offset_expr,
4305 likely ? "bgezl" : "bgez", "s,p", sreg);
4310 macro_build ((char *) NULL, &icnt, &offset_expr,
4311 likely ? "blezl" : "blez", "s,p", treg);
4314 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4316 macro_build ((char *) NULL, &icnt, &offset_expr,
4317 likely ? "beql" : "beq", "s,t,p", AT, 0);
4323 /* check for > max integer */
4324 maxnum = 0x7fffffff;
4325 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4332 if (imm_expr.X_op == O_constant
4333 && imm_expr.X_add_number >= maxnum
4334 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4337 /* result is always false */
4341 as_warn (_("Branch %s is always false (nop)"),
4343 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop",
4349 as_warn (_("Branch likely %s is always false"),
4351 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
4356 if (imm_expr.X_op != O_constant)
4357 as_bad (_("Unsupported large constant"));
4358 ++imm_expr.X_add_number;
4362 if (mask == M_BGEL_I)
4364 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4366 macro_build ((char *) NULL, &icnt, &offset_expr,
4367 likely ? "bgezl" : "bgez", "s,p", sreg);
4370 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4372 macro_build ((char *) NULL, &icnt, &offset_expr,
4373 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4376 maxnum = 0x7fffffff;
4377 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4384 maxnum = - maxnum - 1;
4385 if (imm_expr.X_op == O_constant
4386 && imm_expr.X_add_number <= maxnum
4387 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4390 /* result is always true */
4391 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4392 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4395 set_at (&icnt, sreg, 0);
4396 macro_build ((char *) NULL, &icnt, &offset_expr,
4397 likely ? "beql" : "beq", "s,t,p", AT, 0);
4407 macro_build ((char *) NULL, &icnt, &offset_expr,
4408 likely ? "beql" : "beq", "s,t,p", 0, treg);
4411 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4412 "d,v,t", AT, sreg, treg);
4413 macro_build ((char *) NULL, &icnt, &offset_expr,
4414 likely ? "beql" : "beq", "s,t,p", AT, 0);
4422 && imm_expr.X_op == O_constant
4423 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4425 if (imm_expr.X_op != O_constant)
4426 as_bad (_("Unsupported large constant"));
4427 ++imm_expr.X_add_number;
4431 if (mask == M_BGEUL_I)
4433 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4435 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4437 macro_build ((char *) NULL, &icnt, &offset_expr,
4438 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4441 set_at (&icnt, sreg, 1);
4442 macro_build ((char *) NULL, &icnt, &offset_expr,
4443 likely ? "beql" : "beq", "s,t,p", AT, 0);
4451 macro_build ((char *) NULL, &icnt, &offset_expr,
4452 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4457 macro_build ((char *) NULL, &icnt, &offset_expr,
4458 likely ? "bltzl" : "bltz", "s,p", treg);
4461 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4463 macro_build ((char *) NULL, &icnt, &offset_expr,
4464 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4472 macro_build ((char *) NULL, &icnt, &offset_expr,
4473 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4478 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4479 "d,v,t", AT, treg, sreg);
4480 macro_build ((char *) NULL, &icnt, &offset_expr,
4481 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4489 macro_build ((char *) NULL, &icnt, &offset_expr,
4490 likely ? "blezl" : "blez", "s,p", sreg);
4495 macro_build ((char *) NULL, &icnt, &offset_expr,
4496 likely ? "bgezl" : "bgez", "s,p", treg);
4499 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4501 macro_build ((char *) NULL, &icnt, &offset_expr,
4502 likely ? "beql" : "beq", "s,t,p", AT, 0);
4508 maxnum = 0x7fffffff;
4509 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4516 if (imm_expr.X_op == O_constant
4517 && imm_expr.X_add_number >= maxnum
4518 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4520 if (imm_expr.X_op != O_constant)
4521 as_bad (_("Unsupported large constant"));
4522 ++imm_expr.X_add_number;
4526 if (mask == M_BLTL_I)
4528 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4530 macro_build ((char *) NULL, &icnt, &offset_expr,
4531 likely ? "bltzl" : "bltz", "s,p", sreg);
4534 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4536 macro_build ((char *) NULL, &icnt, &offset_expr,
4537 likely ? "blezl" : "blez", "s,p", sreg);
4540 set_at (&icnt, sreg, 0);
4541 macro_build ((char *) NULL, &icnt, &offset_expr,
4542 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4550 macro_build ((char *) NULL, &icnt, &offset_expr,
4551 likely ? "beql" : "beq", "s,t,p", sreg, 0);
4556 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4557 "d,v,t", AT, treg, sreg);
4558 macro_build ((char *) NULL, &icnt, &offset_expr,
4559 likely ? "beql" : "beq", "s,t,p", AT, 0);
4567 && imm_expr.X_op == O_constant
4568 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4570 if (imm_expr.X_op != O_constant)
4571 as_bad (_("Unsupported large constant"));
4572 ++imm_expr.X_add_number;
4576 if (mask == M_BLTUL_I)
4578 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4580 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4582 macro_build ((char *) NULL, &icnt, &offset_expr,
4583 likely ? "beql" : "beq",
4587 set_at (&icnt, sreg, 1);
4588 macro_build ((char *) NULL, &icnt, &offset_expr,
4589 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4597 macro_build ((char *) NULL, &icnt, &offset_expr,
4598 likely ? "bltzl" : "bltz", "s,p", sreg);
4603 macro_build ((char *) NULL, &icnt, &offset_expr,
4604 likely ? "bgtzl" : "bgtz", "s,p", treg);
4607 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4609 macro_build ((char *) NULL, &icnt, &offset_expr,
4610 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4620 macro_build ((char *) NULL, &icnt, &offset_expr,
4621 likely ? "bnel" : "bne", "s,t,p", 0, treg);
4624 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4627 macro_build ((char *) NULL, &icnt, &offset_expr,
4628 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4643 as_warn (_("Divide by zero."));
4645 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4648 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4653 mips_emit_delays (TRUE);
4654 ++mips_opts.noreorder;
4655 mips_any_noreorder = 1;
4658 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4659 "s,t,q", treg, 0, 7);
4660 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4661 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4665 expr1.X_add_number = 8;
4666 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4667 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4668 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4669 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4672 expr1.X_add_number = -1;
4673 macro_build ((char *) NULL, &icnt, &expr1,
4674 dbl ? "daddiu" : "addiu",
4675 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
4676 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4677 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4680 expr1.X_add_number = 1;
4681 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4682 (int) BFD_RELOC_LO16);
4683 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32",
4684 "d,w,<", AT, AT, 31);
4688 expr1.X_add_number = 0x80000000;
4689 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4690 (int) BFD_RELOC_HI16);
4694 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4695 "s,t,q", sreg, AT, 6);
4696 /* We want to close the noreorder block as soon as possible, so
4697 that later insns are available for delay slot filling. */
4698 --mips_opts.noreorder;
4702 expr1.X_add_number = 8;
4703 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4704 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4707 /* We want to close the noreorder block as soon as possible, so
4708 that later insns are available for delay slot filling. */
4709 --mips_opts.noreorder;
4711 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4714 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg);
4753 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4755 as_warn (_("Divide by zero."));
4757 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4760 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4764 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4766 if (strcmp (s2, "mflo") == 0)
4767 move_register (&icnt, dreg, sreg);
4769 move_register (&icnt, dreg, 0);
4772 if (imm_expr.X_op == O_constant
4773 && imm_expr.X_add_number == -1
4774 && s[strlen (s) - 1] != 'u')
4776 if (strcmp (s2, "mflo") == 0)
4778 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4779 dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4782 move_register (&icnt, dreg, 0);
4786 load_register (&icnt, AT, &imm_expr, dbl);
4787 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4789 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4808 mips_emit_delays (TRUE);
4809 ++mips_opts.noreorder;
4810 mips_any_noreorder = 1;
4813 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4814 "s,t,q", treg, 0, 7);
4815 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4817 /* We want to close the noreorder block as soon as possible, so
4818 that later insns are available for delay slot filling. */
4819 --mips_opts.noreorder;
4823 expr1.X_add_number = 8;
4824 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4825 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4828 /* We want to close the noreorder block as soon as possible, so
4829 that later insns are available for delay slot filling. */
4830 --mips_opts.noreorder;
4831 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4834 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4840 /* Load the address of a symbol into a register. If breg is not
4841 zero, we then add a base register to it. */
4843 if (dbl && HAVE_32BIT_GPRS)
4844 as_warn (_("dla used to load 32-bit register"));
4846 if (! dbl && HAVE_64BIT_OBJECTS)
4847 as_warn (_("la used to load 64-bit address"));
4849 if (offset_expr.X_op == O_constant
4850 && offset_expr.X_add_number >= -0x8000
4851 && offset_expr.X_add_number < 0x8000)
4853 macro_build ((char *) NULL, &icnt, &offset_expr,
4854 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" :
4855 HAVE_NEWABI ? "addi" : "addiu",
4856 "t,r,j", treg, sreg, (int) BFD_RELOC_LO16);
4871 /* When generating embedded PIC code, we permit expressions of
4874 la $treg,foo-bar($breg)
4875 where bar is an address in the current section. These are used
4876 when getting the addresses of functions. We don't permit
4877 X_add_number to be non-zero, because if the symbol is
4878 external the relaxing code needs to know that any addend is
4879 purely the offset to X_op_symbol. */
4880 if (mips_pic == EMBEDDED_PIC
4881 && offset_expr.X_op == O_subtract
4882 && (symbol_constant_p (offset_expr.X_op_symbol)
4883 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4884 : (symbol_equated_p (offset_expr.X_op_symbol)
4886 (symbol_get_value_expression (offset_expr.X_op_symbol)
4889 && (offset_expr.X_add_number == 0
4890 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4896 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4897 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4901 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4902 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4903 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4904 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4905 "d,v,t", tempreg, tempreg, breg);
4907 macro_build ((char *) NULL, &icnt, &offset_expr,
4908 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4909 "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16);
4915 if (offset_expr.X_op != O_symbol
4916 && offset_expr.X_op != O_constant)
4918 as_bad (_("expression too complex"));
4919 offset_expr.X_op = O_constant;
4922 if (offset_expr.X_op == O_constant)
4923 load_register (&icnt, tempreg, &offset_expr,
4924 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4925 ? (dbl || HAVE_64BIT_ADDRESSES)
4926 : HAVE_64BIT_ADDRESSES));
4927 else if (mips_pic == NO_PIC)
4929 /* If this is a reference to a GP relative symbol, we want
4930 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4932 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4933 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4934 If we have a constant, we need two instructions anyhow,
4935 so we may as well always use the latter form.
4937 With 64bit address space and a usable $at we want
4938 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4939 lui $at,<sym> (BFD_RELOC_HI16_S)
4940 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4941 daddiu $at,<sym> (BFD_RELOC_LO16)
4943 daddu $tempreg,$tempreg,$at
4945 If $at is already in use, we use a path which is suboptimal
4946 on superscalar processors.
4947 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4948 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4950 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4952 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4955 if (HAVE_64BIT_ADDRESSES)
4957 /* We don't do GP optimization for now because RELAX_ENCODE can't
4958 hold the data for such large chunks. */
4960 if (used_at == 0 && ! mips_opts.noat)
4962 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4963 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4964 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4965 AT, (int) BFD_RELOC_HI16_S);
4966 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4967 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4968 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4969 AT, AT, (int) BFD_RELOC_LO16);
4970 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
4971 "d,w,<", tempreg, tempreg, 0);
4972 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
4973 "d,v,t", tempreg, tempreg, AT);
4978 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4979 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4980 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4981 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4982 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4983 tempreg, tempreg, 16);
4984 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4985 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
4986 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4987 tempreg, tempreg, 16);
4988 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4989 tempreg, tempreg, (int) BFD_RELOC_LO16);
4994 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4995 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4998 macro_build ((char *) NULL, &icnt, &offset_expr,
4999 ADDRESS_ADDI_INSN, "t,r,j", tempreg,
5000 mips_gp_register, (int) BFD_RELOC_GPREL16);
5001 p = frag_var (rs_machine_dependent, 8, 0,
5002 RELAX_ENCODE (4, 8, 0, 4, 0,
5003 mips_opts.warn_about_macros),
5004 offset_expr.X_add_symbol, 0, NULL);
5006 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5009 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5010 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5013 else if (mips_pic == SVR4_PIC && ! mips_big_got && ! HAVE_NEWABI)
5015 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
5017 /* If this is a reference to an external symbol, and there
5018 is no constant, we want
5019 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5020 or if tempreg is PIC_CALL_REG
5021 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5022 For a local symbol, we want
5023 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5025 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5027 If we have a small constant, and this is a reference to
5028 an external symbol, we want
5029 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5031 addiu $tempreg,$tempreg,<constant>
5032 For a local symbol, we want the same instruction
5033 sequence, but we output a BFD_RELOC_LO16 reloc on the
5036 If we have a large constant, and this is a reference to
5037 an external symbol, we want
5038 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5039 lui $at,<hiconstant>
5040 addiu $at,$at,<loconstant>
5041 addu $tempreg,$tempreg,$at
5042 For a local symbol, we want the same instruction
5043 sequence, but we output a BFD_RELOC_LO16 reloc on the
5047 expr1.X_add_number = offset_expr.X_add_number;
5048 offset_expr.X_add_number = 0;
5050 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
5051 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
5052 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5053 "t,o(b)", tempreg, lw_reloc_type, mips_gp_register);
5054 if (expr1.X_add_number == 0)
5063 /* We're going to put in an addu instruction using
5064 tempreg, so we may as well insert the nop right
5066 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5070 p = frag_var (rs_machine_dependent, 8 - off, 0,
5071 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
5073 ? mips_opts.warn_about_macros
5075 offset_expr.X_add_symbol, 0, NULL);
5078 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5081 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
5082 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5083 /* FIXME: If breg == 0, and the next instruction uses
5084 $tempreg, then if this variant case is used an extra
5085 nop will be generated. */
5087 else if (expr1.X_add_number >= -0x8000
5088 && expr1.X_add_number < 0x8000)
5090 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5092 macro_build ((char *) NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5093 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5094 frag_var (rs_machine_dependent, 0, 0,
5095 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
5096 offset_expr.X_add_symbol, 0, NULL);
5102 /* If we are going to add in a base register, and the
5103 target register and the base register are the same,
5104 then we are using AT as a temporary register. Since
5105 we want to load the constant into AT, we add our
5106 current AT (from the global offset table) and the
5107 register into the register now, and pretend we were
5108 not using a base register. */
5113 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5115 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5116 ADDRESS_ADD_INSN, "d,v,t", treg, AT, breg);
5122 /* Set mips_optimize around the lui instruction to avoid
5123 inserting an unnecessary nop after the lw. */
5124 hold_mips_optimize = mips_optimize;
5126 macro_build_lui (NULL, &icnt, &expr1, AT);
5127 mips_optimize = hold_mips_optimize;
5129 macro_build ((char *) NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5130 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5131 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5132 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, AT);
5133 frag_var (rs_machine_dependent, 0, 0,
5134 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
5135 offset_expr.X_add_symbol, 0, NULL);
5139 else if (mips_pic == SVR4_PIC && ! mips_big_got && HAVE_NEWABI)
5142 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_DISP;
5145 /* If this is a reference to an external, and there is no
5146 constant, or local symbol (*), with or without a
5148 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5149 or if tempreg is PIC_CALL_REG
5150 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5152 If we have a small constant, and this is a reference to
5153 an external symbol, we want
5154 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5155 addiu $tempreg,$tempreg,<constant>
5157 If we have a large constant, and this is a reference to
5158 an external symbol, we want
5159 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5160 lui $at,<hiconstant>
5161 addiu $at,$at,<loconstant>
5162 addu $tempreg,$tempreg,$at
5164 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
5165 local symbols, even though it introduces an additional
5169 if (offset_expr.X_add_number == 0 && tempreg == PIC_CALL_REG)
5170 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
5171 if (offset_expr.X_add_number)
5173 frag_now->tc_frag_data.tc_fr_offset =
5174 expr1.X_add_number = offset_expr.X_add_number;
5175 offset_expr.X_add_number = 0;
5177 macro_build ((char *) NULL, &icnt, &offset_expr,
5178 ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5179 lw_reloc_type, mips_gp_register);
5181 if (expr1.X_add_number >= -0x8000
5182 && expr1.X_add_number < 0x8000)
5184 macro_build ((char *) NULL, &icnt, &expr1,
5185 ADDRESS_ADDI_INSN, "t,r,j", tempreg, tempreg,
5186 (int) BFD_RELOC_LO16);
5187 p = frag_var (rs_machine_dependent, 4, 0,
5188 RELAX_ENCODE (8, 4, 0, 0, 0, 0),
5189 offset_expr.X_add_symbol, 0, NULL);
5191 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number))
5195 /* If we are going to add in a base register, and the
5196 target register and the base register are the same,
5197 then we are using AT as a temporary register. Since
5198 we want to load the constant into AT, we add our
5199 current AT (from the global offset table) and the
5200 register into the register now, and pretend we were
5201 not using a base register. */
5206 assert (tempreg == AT);
5207 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5208 ADDRESS_ADD_INSN, "d,v,t", treg, AT, breg);
5213 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
5214 macro_build ((char *) NULL, &icnt, &expr1,
5215 ADDRESS_ADDI_INSN, "t,r,j", AT, AT,
5216 (int) BFD_RELOC_LO16);
5217 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5218 ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
5220 p = frag_var (rs_machine_dependent, 4 + adj, 0,
5221 RELAX_ENCODE (16 + adj, 4 + adj,
5223 offset_expr.X_add_symbol, 0, NULL);
5228 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5230 offset_expr.X_add_number = expr1.X_add_number;
5232 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5233 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_DISP,
5237 macro_build (p + 4, &icnt, (expressionS *) NULL,
5238 ADDRESS_ADD_INSN, "d,v,t",
5239 treg, tempreg, breg);
5246 macro_build ((char *) NULL, &icnt, &offset_expr,
5247 ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5248 lw_reloc_type, mips_gp_register);
5249 if (lw_reloc_type != BFD_RELOC_MIPS_GOT_DISP)
5250 p = frag_var (rs_machine_dependent, 0, 0,
5251 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5252 offset_expr.X_add_symbol, 0, NULL);
5257 /* To avoid confusion in tc_gen_reloc, we must ensure
5258 that this does not become a variant frag. */
5259 frag_wane (frag_now);
5263 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
5267 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5268 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5269 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
5271 /* This is the large GOT case. If this is a reference to an
5272 external symbol, and there is no constant, we want
5273 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5274 addu $tempreg,$tempreg,$gp
5275 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5276 or if tempreg is PIC_CALL_REG
5277 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5278 addu $tempreg,$tempreg,$gp
5279 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5280 For a local symbol, we want
5281 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5283 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5285 If we have a small constant, and this is a reference to
5286 an external symbol, we want
5287 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5288 addu $tempreg,$tempreg,$gp
5289 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5291 addiu $tempreg,$tempreg,<constant>
5292 For a local symbol, we want
5293 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5295 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5297 If we have a large constant, and this is a reference to
5298 an external symbol, we want
5299 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5300 addu $tempreg,$tempreg,$gp
5301 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5302 lui $at,<hiconstant>
5303 addiu $at,$at,<loconstant>
5304 addu $tempreg,$tempreg,$at
5305 For a local symbol, we want
5306 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5307 lui $at,<hiconstant>
5308 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5309 addu $tempreg,$tempreg,$at
5312 expr1.X_add_number = offset_expr.X_add_number;
5313 offset_expr.X_add_number = 0;
5315 if (reg_needs_delay (mips_gp_register))
5319 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
5321 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5322 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5324 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5325 tempreg, lui_reloc_type);
5326 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5327 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
5329 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5330 "t,o(b)", tempreg, lw_reloc_type, tempreg);
5331 if (expr1.X_add_number == 0)
5339 /* We're going to put in an addu instruction using
5340 tempreg, so we may as well insert the nop right
5342 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5347 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5348 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
5351 ? mips_opts.warn_about_macros
5353 offset_expr.X_add_symbol, 0, NULL);
5355 else if (expr1.X_add_number >= -0x8000
5356 && expr1.X_add_number < 0x8000)
5358 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5360 macro_build ((char *) NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5361 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5363 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5364 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
5366 ? mips_opts.warn_about_macros
5368 offset_expr.X_add_symbol, 0, NULL);
5374 /* If we are going to add in a base register, and the
5375 target register and the base register are the same,
5376 then we are using AT as a temporary register. Since
5377 we want to load the constant into AT, we add our
5378 current AT (from the global offset table) and the
5379 register into the register now, and pretend we were
5380 not using a base register. */
5388 assert (tempreg == AT);
5389 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5391 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5392 ADDRESS_ADD_INSN, "d,v,t", treg, AT, breg);
5397 /* Set mips_optimize around the lui instruction to avoid
5398 inserting an unnecessary nop after the lw. */
5399 hold_mips_optimize = mips_optimize;
5401 macro_build_lui (NULL, &icnt, &expr1, AT);
5402 mips_optimize = hold_mips_optimize;
5404 macro_build ((char *) NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5405 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5406 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5407 ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
5409 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
5410 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
5413 ? mips_opts.warn_about_macros
5415 offset_expr.X_add_symbol, 0, NULL);
5422 /* This is needed because this instruction uses $gp, but
5423 the first instruction on the main stream does not. */
5424 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5428 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5429 tempreg, local_reloc_type, mips_gp_register);
5431 if (expr1.X_add_number >= -0x8000
5432 && expr1.X_add_number < 0x8000)
5434 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5436 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
5437 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5438 /* FIXME: If add_number is 0, and there was no base
5439 register, the external symbol case ended with a load,
5440 so if the symbol turns out to not be external, and
5441 the next instruction uses tempreg, an unnecessary nop
5442 will be inserted. */
5448 /* We must add in the base register now, as in the
5449 external symbol case. */
5450 assert (tempreg == AT);
5451 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5453 macro_build (p, &icnt, (expressionS *) NULL,
5454 ADDRESS_ADD_INSN, "d,v,t", treg, AT, breg);
5457 /* We set breg to 0 because we have arranged to add
5458 it in in both cases. */
5462 macro_build_lui (p, &icnt, &expr1, AT);
5464 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
5465 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5467 macro_build (p, &icnt, (expressionS *) NULL, ADDRESS_ADD_INSN,
5468 "d,v,t", tempreg, tempreg, AT);
5472 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
5475 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5476 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5479 /* This is the large GOT case. If this is a reference to an
5480 external symbol, and there is no constant, we want
5481 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5482 add $tempreg,$tempreg,$gp
5483 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5484 or if tempreg is PIC_CALL_REG
5485 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5486 add $tempreg,$tempreg,$gp
5487 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5489 If we have a small constant, and this is a reference to
5490 an external symbol, we want
5491 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5492 add $tempreg,$tempreg,$gp
5493 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5494 addi $tempreg,$tempreg,<constant>
5496 If we have a large constant, and this is a reference to
5497 an external symbol, we want
5498 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5499 addu $tempreg,$tempreg,$gp
5500 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5501 lui $at,<hiconstant>
5502 addi $at,$at,<loconstant>
5503 add $tempreg,$tempreg,$at
5505 If we have NewABI, and we know it's a local symbol, we want
5506 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5507 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5508 otherwise we have to resort to GOT_HI16/GOT_LO16. */
5512 frag_now->tc_frag_data.tc_fr_offset =
5513 expr1.X_add_number = offset_expr.X_add_number;
5514 offset_expr.X_add_number = 0;
5516 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
5518 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5519 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5521 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5522 tempreg, lui_reloc_type);
5523 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5524 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
5526 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5527 "t,o(b)", tempreg, lw_reloc_type, tempreg);
5529 if (expr1.X_add_number == 0)
5531 p = frag_var (rs_machine_dependent, 8, 0,
5532 RELAX_ENCODE (12, 8, 0, 4, 0,
5533 mips_opts.warn_about_macros),
5534 offset_expr.X_add_symbol, 0, NULL);
5536 else if (expr1.X_add_number >= -0x8000
5537 && expr1.X_add_number < 0x8000)
5539 macro_build ((char *) NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5540 "t,r,j", tempreg, tempreg,
5541 (int) BFD_RELOC_LO16);
5542 p = frag_var (rs_machine_dependent, 8, 0,
5543 RELAX_ENCODE (16, 8, 0, 4, 0,
5544 mips_opts.warn_about_macros),
5545 offset_expr.X_add_symbol, 0, NULL);
5547 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number))
5551 /* If we are going to add in a base register, and the
5552 target register and the base register are the same,
5553 then we are using AT as a temporary register. Since
5554 we want to load the constant into AT, we add our
5555 current AT (from the global offset table) and the
5556 register into the register now, and pretend we were
5557 not using a base register. */
5562 assert (tempreg == AT);
5563 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5564 ADDRESS_ADD_INSN, "d,v,t", treg, AT, breg);
5569 /* Set mips_optimize around the lui instruction to avoid
5570 inserting an unnecessary nop after the lw. */
5571 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
5572 macro_build ((char *) NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5573 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5574 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5575 ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
5577 p = frag_var (rs_machine_dependent, 8 + adj, 0,
5578 RELAX_ENCODE (24 + adj, 8 + adj,
5581 ? mips_opts.warn_about_macros
5583 offset_expr.X_add_symbol, 0, NULL);
5588 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5590 offset_expr.X_add_number = expr1.X_add_number;
5591 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5592 tempreg, (int) BFD_RELOC_MIPS_GOT_PAGE,
5594 macro_build (p + 4, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5595 tempreg, tempreg, (int) BFD_RELOC_MIPS_GOT_OFST);
5598 macro_build (p + 8, &icnt, (expressionS *) NULL,
5599 ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
5604 else if (mips_pic == EMBEDDED_PIC)
5607 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5609 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5610 "t,r,j", tempreg, mips_gp_register,
5611 (int) BFD_RELOC_GPREL16);
5620 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
5621 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" :
5622 HAVE_NEWABI ? "add" : "addu";
5624 s = ADDRESS_ADD_INSN;
5626 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
5627 "d,v,t", treg, tempreg, breg);
5636 /* The j instruction may not be used in PIC code, since it
5637 requires an absolute address. We convert it to a b
5639 if (mips_pic == NO_PIC)
5640 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
5642 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
5645 /* The jal instructions must be handled as macros because when
5646 generating PIC code they expand to multi-instruction
5647 sequences. Normally they are simple instructions. */
5652 if (mips_pic == NO_PIC
5653 || mips_pic == EMBEDDED_PIC)
5654 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5656 else if (mips_pic == SVR4_PIC)
5658 if (sreg != PIC_CALL_REG)
5659 as_warn (_("MIPS PIC call to register other than $25"));
5661 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5665 if (mips_cprestore_offset < 0)
5666 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5669 if (! mips_frame_reg_valid)
5671 as_warn (_("No .frame pseudo-op used in PIC code"));
5672 /* Quiet this warning. */
5673 mips_frame_reg_valid = 1;
5675 if (! mips_cprestore_valid)
5677 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5678 /* Quiet this warning. */
5679 mips_cprestore_valid = 1;
5681 expr1.X_add_number = mips_cprestore_offset;
5682 macro_build_ldst_constoffset ((char *) NULL, &icnt, &expr1,
5695 if (mips_pic == NO_PIC)
5696 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
5697 else if (mips_pic == SVR4_PIC)
5701 /* If this is a reference to an external symbol, and we are
5702 using a small GOT, we want
5703 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5707 lw $gp,cprestore($sp)
5708 The cprestore value is set using the .cprestore
5709 pseudo-op. If we are using a big GOT, we want
5710 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5712 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5716 lw $gp,cprestore($sp)
5717 If the symbol is not external, we want
5718 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5720 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5723 lw $gp,cprestore($sp)
5725 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
5726 sequences above, minus nops, unless the symbol is local,
5727 which enables us to use GOT_PAGE/GOT_OFST (big got) or
5734 macro_build ((char *) NULL, &icnt, &offset_expr,
5735 ADDRESS_LOAD_INSN, "t,o(b)", PIC_CALL_REG,
5736 (int) BFD_RELOC_MIPS_CALL16,
5738 frag_var (rs_machine_dependent, 0, 0,
5739 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5740 offset_expr.X_add_symbol, 0, NULL);
5745 macro_build ((char *) NULL, &icnt, &offset_expr, "lui",
5746 "t,u", PIC_CALL_REG,
5747 (int) BFD_RELOC_MIPS_CALL_HI16);
5748 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5749 ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
5750 PIC_CALL_REG, mips_gp_register);
5751 macro_build ((char *) NULL, &icnt, &offset_expr,
5752 ADDRESS_LOAD_INSN, "t,o(b)", PIC_CALL_REG,
5753 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5754 p = frag_var (rs_machine_dependent, 8, 0,
5755 RELAX_ENCODE (12, 8, 0, 4, 0, 0),
5756 offset_expr.X_add_symbol, 0, NULL);
5757 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5758 "t,o(b)", PIC_CALL_REG,
5759 (int) BFD_RELOC_MIPS_GOT_PAGE,
5761 macro_build (p + 4, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5762 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5763 (int) BFD_RELOC_MIPS_GOT_OFST);
5766 macro_build_jalr (icnt, &offset_expr);
5773 macro_build ((char *) NULL, &icnt, &offset_expr,
5774 ADDRESS_LOAD_INSN, "t,o(b)", PIC_CALL_REG,
5775 (int) BFD_RELOC_MIPS_CALL16, mips_gp_register);
5776 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5778 p = frag_var (rs_machine_dependent, 4, 0,
5779 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5780 offset_expr.X_add_symbol, 0, NULL);
5786 if (reg_needs_delay (mips_gp_register))
5790 macro_build ((char *) NULL, &icnt, &offset_expr, "lui",
5791 "t,u", PIC_CALL_REG,
5792 (int) BFD_RELOC_MIPS_CALL_HI16);
5793 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5794 ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
5795 PIC_CALL_REG, mips_gp_register);
5796 macro_build ((char *) NULL, &icnt, &offset_expr,
5797 ADDRESS_LOAD_INSN, "t,o(b)", PIC_CALL_REG,
5798 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5799 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5801 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5802 RELAX_ENCODE (16, 12 + gpdel, gpdel,
5804 offset_expr.X_add_symbol, 0, NULL);
5807 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5810 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5811 "t,o(b)", PIC_CALL_REG,
5812 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
5814 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5817 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5818 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5819 (int) BFD_RELOC_LO16);
5820 macro_build_jalr (icnt, &offset_expr);
5822 if (mips_cprestore_offset < 0)
5823 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5826 if (! mips_frame_reg_valid)
5828 as_warn (_("No .frame pseudo-op used in PIC code"));
5829 /* Quiet this warning. */
5830 mips_frame_reg_valid = 1;
5832 if (! mips_cprestore_valid)
5834 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5835 /* Quiet this warning. */
5836 mips_cprestore_valid = 1;
5838 if (mips_opts.noreorder)
5839 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5841 expr1.X_add_number = mips_cprestore_offset;
5842 macro_build_ldst_constoffset ((char *) NULL, &icnt, &expr1,
5849 else if (mips_pic == EMBEDDED_PIC)
5851 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
5852 /* The linker may expand the call to a longer sequence which
5853 uses $at, so we must break rather than return. */
5878 /* Itbl support may require additional care here. */
5883 /* Itbl support may require additional care here. */
5888 /* Itbl support may require additional care here. */
5893 /* Itbl support may require additional care here. */
5905 if (mips_arch == CPU_R4650)
5907 as_bad (_("opcode not supported on this processor"));
5911 /* Itbl support may require additional care here. */
5916 /* Itbl support may require additional care here. */
5921 /* Itbl support may require additional care here. */
5941 if (breg == treg || coproc || lr)
5963 /* Itbl support may require additional care here. */
5968 /* Itbl support may require additional care here. */
5973 /* Itbl support may require additional care here. */
5978 /* Itbl support may require additional care here. */
5994 if (mips_arch == CPU_R4650)
5996 as_bad (_("opcode not supported on this processor"));
6001 /* Itbl support may require additional care here. */
6005 /* Itbl support may require additional care here. */
6010 /* Itbl support may require additional care here. */
6022 /* Itbl support may require additional care here. */
6023 if (mask == M_LWC1_AB
6024 || mask == M_SWC1_AB
6025 || mask == M_LDC1_AB
6026 || mask == M_SDC1_AB
6035 /* For embedded PIC, we allow loads where the offset is calculated
6036 by subtracting a symbol in the current segment from an unknown
6037 symbol, relative to a base register, e.g.:
6038 <op> $treg, <sym>-<localsym>($breg)
6039 This is used by the compiler for switch statements. */
6040 if (mips_pic == EMBEDDED_PIC
6041 && offset_expr.X_op == O_subtract
6042 && (symbol_constant_p (offset_expr.X_op_symbol)
6043 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
6044 : (symbol_equated_p (offset_expr.X_op_symbol)
6046 (symbol_get_value_expression (offset_expr.X_op_symbol)
6050 && (offset_expr.X_add_number == 0
6051 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
6053 /* For this case, we output the instructions:
6054 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
6055 addiu $tempreg,$tempreg,$breg
6056 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
6057 If the relocation would fit entirely in 16 bits, it would be
6059 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
6060 instead, but that seems quite difficult. */
6061 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6062 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
6063 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6064 ((bfd_arch_bits_per_address (stdoutput) == 32
6065 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6066 ? HAVE_NEWABI ? "add" : "addu" : "daddu"),
6067 "d,v,t", tempreg, tempreg, breg);
6068 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
6069 (int) BFD_RELOC_PCREL_LO16, tempreg);
6075 if (offset_expr.X_op != O_constant
6076 && offset_expr.X_op != O_symbol)
6078 as_bad (_("expression too complex"));
6079 offset_expr.X_op = O_constant;
6082 /* A constant expression in PIC code can be handled just as it
6083 is in non PIC code. */
6084 if (mips_pic == NO_PIC
6085 || offset_expr.X_op == O_constant)
6089 /* If this is a reference to a GP relative symbol, and there
6090 is no base register, we want
6091 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6092 Otherwise, if there is no base register, we want
6093 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6094 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6095 If we have a constant, we need two instructions anyhow,
6096 so we always use the latter form.
6098 If we have a base register, and this is a reference to a
6099 GP relative symbol, we want
6100 addu $tempreg,$breg,$gp
6101 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6103 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6104 addu $tempreg,$tempreg,$breg
6105 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6106 With a constant we always use the latter case.
6108 With 64bit address space and no base register and $at usable,
6110 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6111 lui $at,<sym> (BFD_RELOC_HI16_S)
6112 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6115 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6116 If we have a base register, we want
6117 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6118 lui $at,<sym> (BFD_RELOC_HI16_S)
6119 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6123 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6125 Without $at we can't generate the optimal path for superscalar
6126 processors here since this would require two temporary registers.
6127 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6128 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6130 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6132 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6133 If we have a base register, we want
6134 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6135 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6137 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6139 daddu $tempreg,$tempreg,$breg
6140 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6142 If we have 64-bit addresses, as an optimization, for
6143 addresses which are 32-bit constants (e.g. kseg0/kseg1
6144 addresses) we fall back to the 32-bit address generation
6145 mechanism since it is more efficient. Note that due to
6146 the signed offset used by memory operations, the 32-bit
6147 range is shifted down by 32768 here. This code should
6148 probably attempt to generate 64-bit constants more
6149 efficiently in general.
6151 As an extension for architectures with 64-bit registers,
6152 we don't truncate 64-bit addresses given as literal
6153 constants down to 32 bits, to support existing practice
6154 in the mips64 Linux (the kernel), that compiles source
6155 files with -mabi=64, assembling them as o32 or n32 (with
6156 -Wa,-32 or -Wa,-n32). This is not beautiful, but since
6157 the whole kernel is loaded into a memory region that is
6158 addressible with sign-extended 32-bit addresses, it is
6159 wasteful to compute the upper 32 bits of every
6160 non-literal address, that takes more space and time.
6161 Some day this should probably be implemented as an
6162 assembler option, such that the kernel doesn't have to
6163 use such ugly hacks, even though it will still have to
6164 end up converting the binary to ELF32 for a number of
6165 platforms whose boot loaders don't support ELF64
6167 if ((offset_expr.X_op != O_constant && HAVE_64BIT_ADDRESSES)
6168 || (offset_expr.X_op == O_constant
6169 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000)
6170 && HAVE_64BIT_ADDRESS_CONSTANTS))
6174 /* We don't do GP optimization for now because RELAX_ENCODE can't
6175 hold the data for such large chunks. */
6177 if (used_at == 0 && ! mips_opts.noat)
6179 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6180 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
6181 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6182 AT, (int) BFD_RELOC_HI16_S);
6183 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6184 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
6186 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
6187 "d,v,t", AT, AT, breg);
6188 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
6189 "d,w,<", tempreg, tempreg, 0);
6190 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
6191 "d,v,t", tempreg, tempreg, AT);
6192 macro_build (p, &icnt, &offset_expr, s,
6193 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
6198 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6199 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
6200 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6201 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
6202 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
6203 "d,w,<", tempreg, tempreg, 16);
6204 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6205 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
6206 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
6207 "d,w,<", tempreg, tempreg, 16);
6209 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
6210 "d,v,t", tempreg, tempreg, breg);
6211 macro_build (p, &icnt, &offset_expr, s,
6212 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
6217 else if (offset_expr.X_op == O_constant
6218 && !HAVE_64BIT_ADDRESS_CONSTANTS
6219 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
6220 as_bad (_("load/store address overflow (max 32 bits)"));
6224 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6225 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6230 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6231 treg, (int) BFD_RELOC_GPREL16,
6233 p = frag_var (rs_machine_dependent, 8, 0,
6234 RELAX_ENCODE (4, 8, 0, 4, 0,
6235 (mips_opts.warn_about_macros
6237 && mips_opts.noat))),
6238 offset_expr.X_add_symbol, 0, NULL);
6241 macro_build_lui (p, &icnt, &offset_expr, tempreg);
6244 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6245 (int) BFD_RELOC_LO16, tempreg);
6249 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6250 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6255 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6256 ADDRESS_ADD_INSN, "d,v,t", tempreg, breg,
6258 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6259 treg, (int) BFD_RELOC_GPREL16, tempreg);
6260 p = frag_var (rs_machine_dependent, 12, 0,
6261 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
6262 offset_expr.X_add_symbol, 0, NULL);
6264 macro_build_lui (p, &icnt, &offset_expr, tempreg);
6267 macro_build (p, &icnt, (expressionS *) NULL, ADDRESS_ADD_INSN,
6268 "d,v,t", tempreg, tempreg, breg);
6271 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6272 (int) BFD_RELOC_LO16, tempreg);
6275 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6278 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
6280 /* If this is a reference to an external symbol, we want
6281 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6283 <op> $treg,0($tempreg)
6285 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6287 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6288 <op> $treg,0($tempreg)
6291 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6292 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6294 If there is a base register, we add it to $tempreg before
6295 the <op>. If there is a constant, we stick it in the
6296 <op> instruction. We don't handle constants larger than
6297 16 bits, because we have no way to load the upper 16 bits
6298 (actually, we could handle them for the subset of cases
6299 in which we are not using $at). */
6300 assert (offset_expr.X_op == O_symbol);
6303 macro_build ((char *) NULL, &icnt, &offset_expr,
6304 ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6305 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6307 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6308 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
6310 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
6311 (int) BFD_RELOC_MIPS_GOT_OFST, tempreg);
6318 expr1.X_add_number = offset_expr.X_add_number;
6319 offset_expr.X_add_number = 0;
6320 if (expr1.X_add_number < -0x8000
6321 || expr1.X_add_number >= 0x8000)
6322 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6324 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6325 "t,o(b)", tempreg, (int) lw_reloc_type,
6327 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6328 p = frag_var (rs_machine_dependent, 4, 0,
6329 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
6330 offset_expr.X_add_symbol, 0, NULL);
6331 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
6332 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
6334 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6335 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, breg);
6336 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
6337 (int) BFD_RELOC_LO16, tempreg);
6339 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
6344 /* If this is a reference to an external symbol, we want
6345 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6346 addu $tempreg,$tempreg,$gp
6347 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6348 <op> $treg,0($tempreg)
6350 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6352 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6353 <op> $treg,0($tempreg)
6354 If there is a base register, we add it to $tempreg before
6355 the <op>. If there is a constant, we stick it in the
6356 <op> instruction. We don't handle constants larger than
6357 16 bits, because we have no way to load the upper 16 bits
6358 (actually, we could handle them for the subset of cases
6359 in which we are not using $at). */
6360 assert (offset_expr.X_op == O_symbol);
6361 expr1.X_add_number = offset_expr.X_add_number;
6362 offset_expr.X_add_number = 0;
6363 if (expr1.X_add_number < -0x8000
6364 || expr1.X_add_number >= 0x8000)
6365 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6366 if (reg_needs_delay (mips_gp_register))
6371 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6372 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
6373 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6374 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
6376 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6377 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
6379 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
6380 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
6381 offset_expr.X_add_symbol, 0, NULL);
6384 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6387 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6388 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
6391 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6393 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
6394 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
6396 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6397 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, breg);
6398 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
6399 (int) BFD_RELOC_LO16, tempreg);
6401 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
6404 int bregsz = breg != 0 ? 4 : 0;
6406 /* If this is a reference to an external symbol, we want
6407 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6408 add $tempreg,$tempreg,$gp
6409 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6410 <op> $treg,<ofst>($tempreg)
6411 Otherwise, for local symbols, we want:
6412 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6413 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6414 assert (offset_expr.X_op == O_symbol);
6415 frag_now->tc_frag_data.tc_fr_offset =
6416 expr1.X_add_number = offset_expr.X_add_number;
6417 offset_expr.X_add_number = 0;
6418 if (expr1.X_add_number < -0x8000
6419 || expr1.X_add_number >= 0x8000)
6420 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6422 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6423 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
6424 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6425 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
6427 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6428 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
6431 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6432 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, breg);
6433 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
6434 (int) BFD_RELOC_LO16, tempreg);
6436 offset_expr.X_add_number = expr1.X_add_number;
6437 p = frag_var (rs_machine_dependent, 12 + bregsz, 0,
6438 RELAX_ENCODE (16 + bregsz, 8 + bregsz,
6439 0, 4 + bregsz, 0, 0),
6440 offset_expr.X_add_symbol, 0, NULL);
6441 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6442 tempreg, (int) BFD_RELOC_MIPS_GOT_PAGE,
6445 macro_build (p + 4, &icnt, (expressionS *) NULL,
6446 ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, breg);
6447 macro_build (p + 4 + bregsz, &icnt, &offset_expr, s, fmt, treg,
6448 (int) BFD_RELOC_MIPS_GOT_OFST, tempreg);
6450 else if (mips_pic == EMBEDDED_PIC)
6452 /* If there is no base register, we want
6453 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6454 If there is a base register, we want
6455 addu $tempreg,$breg,$gp
6456 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6458 assert (offset_expr.X_op == O_symbol);
6461 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6462 treg, (int) BFD_RELOC_GPREL16, mips_gp_register);
6467 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6468 ADDRESS_ADD_INSN, "d,v,t", tempreg, breg,
6470 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6471 treg, (int) BFD_RELOC_GPREL16, tempreg);
6484 load_register (&icnt, treg, &imm_expr, 0);
6488 load_register (&icnt, treg, &imm_expr, 1);
6492 if (imm_expr.X_op == O_constant)
6494 load_register (&icnt, AT, &imm_expr, 0);
6495 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6496 "mtc1", "t,G", AT, treg);
6501 assert (offset_expr.X_op == O_symbol
6502 && strcmp (segment_name (S_GET_SEGMENT
6503 (offset_expr.X_add_symbol)),
6505 && offset_expr.X_add_number == 0);
6506 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6507 treg, (int) BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6512 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6513 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6514 order 32 bits of the value and the low order 32 bits are either
6515 zero or in OFFSET_EXPR. */
6516 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6518 if (HAVE_64BIT_GPRS)
6519 load_register (&icnt, treg, &imm_expr, 1);
6524 if (target_big_endian)
6536 load_register (&icnt, hreg, &imm_expr, 0);
6539 if (offset_expr.X_op == O_absent)
6540 move_register (&icnt, lreg, 0);
6543 assert (offset_expr.X_op == O_constant);
6544 load_register (&icnt, lreg, &offset_expr, 0);
6551 /* We know that sym is in the .rdata section. First we get the
6552 upper 16 bits of the address. */
6553 if (mips_pic == NO_PIC)
6555 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6557 else if (mips_pic == SVR4_PIC)
6559 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6560 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
6563 else if (mips_pic == EMBEDDED_PIC)
6565 /* For embedded PIC we pick up the entire address off $gp in
6566 a single instruction. */
6567 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
6568 "t,r,j", AT, mips_gp_register,
6569 (int) BFD_RELOC_GPREL16);
6570 offset_expr.X_op = O_constant;
6571 offset_expr.X_add_number = 0;
6576 /* Now we load the register(s). */
6577 if (HAVE_64BIT_GPRS)
6578 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
6579 treg, (int) BFD_RELOC_LO16, AT);
6582 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
6583 treg, (int) BFD_RELOC_LO16, AT);
6586 /* FIXME: How in the world do we deal with the possible
6588 offset_expr.X_add_number += 4;
6589 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
6590 treg + 1, (int) BFD_RELOC_LO16, AT);
6594 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6595 does not become a variant frag. */
6596 frag_wane (frag_now);
6602 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6603 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6604 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6605 the value and the low order 32 bits are either zero or in
6607 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6609 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
6610 if (HAVE_64BIT_FPRS)
6612 assert (HAVE_64BIT_GPRS);
6613 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6614 "dmtc1", "t,S", AT, treg);
6618 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6619 "mtc1", "t,G", AT, treg + 1);
6620 if (offset_expr.X_op == O_absent)
6621 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6622 "mtc1", "t,G", 0, treg);
6625 assert (offset_expr.X_op == O_constant);
6626 load_register (&icnt, AT, &offset_expr, 0);
6627 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6628 "mtc1", "t,G", AT, treg);
6634 assert (offset_expr.X_op == O_symbol
6635 && offset_expr.X_add_number == 0);
6636 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
6637 if (strcmp (s, ".lit8") == 0)
6639 if (mips_opts.isa != ISA_MIPS1)
6641 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
6642 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL,
6646 breg = mips_gp_register;
6647 r = BFD_RELOC_MIPS_LITERAL;
6652 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
6653 if (mips_pic == SVR4_PIC)
6654 macro_build ((char *) NULL, &icnt, &offset_expr,
6655 ADDRESS_LOAD_INSN, "t,o(b)", AT,
6656 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
6659 /* FIXME: This won't work for a 64 bit address. */
6660 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6663 if (mips_opts.isa != ISA_MIPS1)
6665 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
6666 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
6668 /* To avoid confusion in tc_gen_reloc, we must ensure
6669 that this does not become a variant frag. */
6670 frag_wane (frag_now);
6681 if (mips_arch == CPU_R4650)
6683 as_bad (_("opcode not supported on this processor"));
6686 /* Even on a big endian machine $fn comes before $fn+1. We have
6687 to adjust when loading from memory. */
6690 assert (mips_opts.isa == ISA_MIPS1);
6691 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6692 target_big_endian ? treg + 1 : treg,
6694 /* FIXME: A possible overflow which I don't know how to deal
6696 offset_expr.X_add_number += 4;
6697 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6698 target_big_endian ? treg : treg + 1,
6701 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6702 does not become a variant frag. */
6703 frag_wane (frag_now);
6712 * The MIPS assembler seems to check for X_add_number not
6713 * being double aligned and generating:
6716 * addiu at,at,%lo(foo+1)
6719 * But, the resulting address is the same after relocation so why
6720 * generate the extra instruction?
6722 if (mips_arch == CPU_R4650)
6724 as_bad (_("opcode not supported on this processor"));
6727 /* Itbl support may require additional care here. */
6729 if (mips_opts.isa != ISA_MIPS1)
6740 if (mips_arch == CPU_R4650)
6742 as_bad (_("opcode not supported on this processor"));
6746 if (mips_opts.isa != ISA_MIPS1)
6754 /* Itbl support may require additional care here. */
6759 if (HAVE_64BIT_GPRS)
6770 if (HAVE_64BIT_GPRS)
6780 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6781 loads for the case of doing a pair of loads to simulate an 'ld'.
6782 This is not currently done by the compiler, and assembly coders
6783 writing embedded-pic code can cope. */
6785 if (offset_expr.X_op != O_symbol
6786 && offset_expr.X_op != O_constant)
6788 as_bad (_("expression too complex"));
6789 offset_expr.X_op = O_constant;
6792 /* Even on a big endian machine $fn comes before $fn+1. We have
6793 to adjust when loading from memory. We set coproc if we must
6794 load $fn+1 first. */
6795 /* Itbl support may require additional care here. */
6796 if (! target_big_endian)
6799 if (mips_pic == NO_PIC
6800 || offset_expr.X_op == O_constant)
6804 /* If this is a reference to a GP relative symbol, we want
6805 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6806 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6807 If we have a base register, we use this
6809 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6810 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6811 If this is not a GP relative symbol, we want
6812 lui $at,<sym> (BFD_RELOC_HI16_S)
6813 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6814 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6815 If there is a base register, we add it to $at after the
6816 lui instruction. If there is a constant, we always use
6818 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6819 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6831 tempreg = mips_gp_register;
6838 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6839 ADDRESS_ADD_INSN, "d,v,t", AT, breg,
6846 /* Itbl support may require additional care here. */
6847 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6848 coproc ? treg + 1 : treg,
6849 (int) BFD_RELOC_GPREL16, tempreg);
6850 offset_expr.X_add_number += 4;
6852 /* Set mips_optimize to 2 to avoid inserting an
6854 hold_mips_optimize = mips_optimize;
6856 /* Itbl support may require additional care here. */
6857 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6858 coproc ? treg : treg + 1,
6859 (int) BFD_RELOC_GPREL16, tempreg);
6860 mips_optimize = hold_mips_optimize;
6862 p = frag_var (rs_machine_dependent, 12 + off, 0,
6863 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6864 used_at && mips_opts.noat),
6865 offset_expr.X_add_symbol, 0, NULL);
6867 /* We just generated two relocs. When tc_gen_reloc
6868 handles this case, it will skip the first reloc and
6869 handle the second. The second reloc already has an
6870 extra addend of 4, which we added above. We must
6871 subtract it out, and then subtract another 4 to make
6872 the first reloc come out right. The second reloc
6873 will come out right because we are going to add 4 to
6874 offset_expr when we build its instruction below.
6876 If we have a symbol, then we don't want to include
6877 the offset, because it will wind up being included
6878 when we generate the reloc. */
6880 if (offset_expr.X_op == O_constant)
6881 offset_expr.X_add_number -= 8;
6884 offset_expr.X_add_number = -4;
6885 offset_expr.X_op = O_constant;
6888 macro_build_lui (p, &icnt, &offset_expr, AT);
6893 macro_build (p, &icnt, (expressionS *) NULL, ADDRESS_ADD_INSN,
6894 "d,v,t", AT, breg, AT);
6898 /* Itbl support may require additional care here. */
6899 macro_build (p, &icnt, &offset_expr, s, fmt,
6900 coproc ? treg + 1 : treg,
6901 (int) BFD_RELOC_LO16, AT);
6904 /* FIXME: How do we handle overflow here? */
6905 offset_expr.X_add_number += 4;
6906 /* Itbl support may require additional care here. */
6907 macro_build (p, &icnt, &offset_expr, s, fmt,
6908 coproc ? treg : treg + 1,
6909 (int) BFD_RELOC_LO16, AT);
6911 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6915 /* If this is a reference to an external symbol, we want
6916 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6921 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6923 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6924 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6925 If there is a base register we add it to $at before the
6926 lwc1 instructions. If there is a constant we include it
6927 in the lwc1 instructions. */
6929 expr1.X_add_number = offset_expr.X_add_number;
6930 offset_expr.X_add_number = 0;
6931 if (expr1.X_add_number < -0x8000
6932 || expr1.X_add_number >= 0x8000 - 4)
6933 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6938 frag_grow (24 + off);
6939 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6940 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
6942 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6944 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6945 ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6946 /* Itbl support may require additional care here. */
6947 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6948 coproc ? treg + 1 : treg,
6949 (int) BFD_RELOC_LO16, AT);
6950 expr1.X_add_number += 4;
6952 /* Set mips_optimize to 2 to avoid inserting an undesired
6954 hold_mips_optimize = mips_optimize;
6956 /* Itbl support may require additional care here. */
6957 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6958 coproc ? treg : treg + 1,
6959 (int) BFD_RELOC_LO16, AT);
6960 mips_optimize = hold_mips_optimize;
6962 (void) frag_var (rs_machine_dependent, 0, 0,
6963 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6964 offset_expr.X_add_symbol, 0, NULL);
6966 else if (mips_pic == SVR4_PIC)
6971 /* If this is a reference to an external symbol, we want
6972 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6974 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6979 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6981 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6982 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6983 If there is a base register we add it to $at before the
6984 lwc1 instructions. If there is a constant we include it
6985 in the lwc1 instructions. */
6987 expr1.X_add_number = offset_expr.X_add_number;
6988 offset_expr.X_add_number = 0;
6989 if (expr1.X_add_number < -0x8000
6990 || expr1.X_add_number >= 0x8000 - 4)
6991 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6992 if (reg_needs_delay (mips_gp_register))
7001 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
7002 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
7003 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7004 ADDRESS_ADD_INSN, "d,v,t", AT, AT, mips_gp_register);
7005 macro_build ((char *) NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
7006 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
7007 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7009 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7010 ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
7011 /* Itbl support may require additional care here. */
7012 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
7013 coproc ? treg + 1 : treg,
7014 (int) BFD_RELOC_LO16, AT);
7015 expr1.X_add_number += 4;
7017 /* Set mips_optimize to 2 to avoid inserting an undesired
7019 hold_mips_optimize = mips_optimize;
7021 /* Itbl support may require additional care here. */
7022 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
7023 coproc ? treg : treg + 1,
7024 (int) BFD_RELOC_LO16, AT);
7025 mips_optimize = hold_mips_optimize;
7026 expr1.X_add_number -= 4;
7028 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
7029 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
7030 8 + gpdel + off, 1, 0),
7031 offset_expr.X_add_symbol, 0, NULL);
7034 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
7037 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
7038 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
7041 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
7045 macro_build (p, &icnt, (expressionS *) NULL, ADDRESS_ADD_INSN,
7046 "d,v,t", AT, breg, AT);
7049 /* Itbl support may require additional care here. */
7050 macro_build (p, &icnt, &expr1, s, fmt,
7051 coproc ? treg + 1 : treg,
7052 (int) BFD_RELOC_LO16, AT);
7054 expr1.X_add_number += 4;
7056 /* Set mips_optimize to 2 to avoid inserting an undesired
7058 hold_mips_optimize = mips_optimize;
7060 /* Itbl support may require additional care here. */
7061 macro_build (p, &icnt, &expr1, s, fmt,
7062 coproc ? treg : treg + 1,
7063 (int) BFD_RELOC_LO16, AT);
7064 mips_optimize = hold_mips_optimize;
7066 else if (mips_pic == EMBEDDED_PIC)
7068 /* If there is no base register, we use
7069 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
7070 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
7071 If we have a base register, we use
7073 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
7074 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
7078 tempreg = mips_gp_register;
7083 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7084 ADDRESS_ADD_INSN, "d,v,t", AT, breg,
7090 /* Itbl support may require additional care here. */
7091 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
7092 coproc ? treg + 1 : treg,
7093 (int) BFD_RELOC_GPREL16, tempreg);
7094 offset_expr.X_add_number += 4;
7095 /* Itbl support may require additional care here. */
7096 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
7097 coproc ? treg : treg + 1,
7098 (int) BFD_RELOC_GPREL16, tempreg);
7114 assert (HAVE_32BIT_ADDRESSES);
7115 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7116 (int) BFD_RELOC_LO16, breg);
7117 offset_expr.X_add_number += 4;
7118 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
7119 (int) BFD_RELOC_LO16, breg);
7122 /* New code added to support COPZ instructions.
7123 This code builds table entries out of the macros in mip_opcodes.
7124 R4000 uses interlocks to handle coproc delays.
7125 Other chips (like the R3000) require nops to be inserted for delays.
7127 FIXME: Currently, we require that the user handle delays.
7128 In order to fill delay slots for non-interlocked chips,
7129 we must have a way to specify delays based on the coprocessor.
7130 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
7131 What are the side-effects of the cop instruction?
7132 What cache support might we have and what are its effects?
7133 Both coprocessor & memory require delays. how long???
7134 What registers are read/set/modified?
7136 If an itbl is provided to interpret cop instructions,
7137 this knowledge can be encoded in the itbl spec. */
7151 /* For now we just do C (same as Cz). The parameter will be
7152 stored in insn_opcode by mips_ip. */
7153 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
7158 move_register (&icnt, dreg, sreg);
7161 #ifdef LOSING_COMPILER
7163 /* Try and see if this is a new itbl instruction.
7164 This code builds table entries out of the macros in mip_opcodes.
7165 FIXME: For now we just assemble the expression and pass it's
7166 value along as a 32-bit immediate.
7167 We may want to have the assembler assemble this value,
7168 so that we gain the assembler's knowledge of delay slots,
7170 Would it be more efficient to use mask (id) here? */
7171 if (itbl_have_entries
7172 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
7174 s = ip->insn_mo->name;
7176 coproc = ITBL_DECODE_PNUM (immed_expr);;
7177 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
7184 as_warn (_("Macro used $at after \".set noat\""));
7189 struct mips_cl_insn *ip;
7191 register int treg, sreg, dreg, breg;
7207 bfd_reloc_code_real_type r;
7210 treg = (ip->insn_opcode >> 16) & 0x1f;
7211 dreg = (ip->insn_opcode >> 11) & 0x1f;
7212 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
7213 mask = ip->insn_mo->mask;
7215 expr1.X_op = O_constant;
7216 expr1.X_op_symbol = NULL;
7217 expr1.X_add_symbol = NULL;
7218 expr1.X_add_number = 1;
7222 #endif /* LOSING_COMPILER */
7227 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7228 dbl ? "dmultu" : "multu", "s,t", sreg, treg);
7229 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
7236 /* The MIPS assembler some times generates shifts and adds. I'm
7237 not trying to be that fancy. GCC should do this for us
7239 load_register (&icnt, AT, &imm_expr, dbl);
7240 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7241 dbl ? "dmult" : "mult", "s,t", sreg, AT);
7242 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
7256 mips_emit_delays (TRUE);
7257 ++mips_opts.noreorder;
7258 mips_any_noreorder = 1;
7260 load_register (&icnt, AT, &imm_expr, dbl);
7261 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7262 dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
7263 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
7265 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7266 dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA);
7267 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
7270 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne",
7271 "s,t,q", dreg, AT, 6);
7274 expr1.X_add_number = 8;
7275 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg,
7277 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
7279 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7282 --mips_opts.noreorder;
7283 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg);
7296 mips_emit_delays (TRUE);
7297 ++mips_opts.noreorder;
7298 mips_any_noreorder = 1;
7300 load_register (&icnt, AT, &imm_expr, dbl);
7301 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7302 dbl ? "dmultu" : "multu",
7303 "s,t", sreg, imm ? AT : treg);
7304 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
7306 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
7309 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne",
7313 expr1.X_add_number = 8;
7314 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
7315 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
7317 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7320 --mips_opts.noreorder;
7324 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_arch))
7336 macro_build ((char *) NULL, &icnt, NULL, "dnegu",
7337 "d,w", tempreg, treg);
7338 macro_build ((char *) NULL, &icnt, NULL, "drorv",
7339 "d,t,s", dreg, sreg, tempreg);
7344 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
7345 "d,v,t", AT, 0, treg);
7346 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
7347 "d,t,s", AT, sreg, AT);
7348 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
7349 "d,t,s", dreg, sreg, treg);
7350 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
7351 "d,v,t", dreg, dreg, AT);
7355 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_arch))
7367 macro_build ((char *) NULL, &icnt, NULL, "negu",
7368 "d,w", tempreg, treg);
7369 macro_build ((char *) NULL, &icnt, NULL, "rorv",
7370 "d,t,s", dreg, sreg, tempreg);
7375 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
7376 "d,v,t", AT, 0, treg);
7377 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
7378 "d,t,s", AT, sreg, AT);
7379 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
7380 "d,t,s", dreg, sreg, treg);
7381 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
7382 "d,v,t", dreg, dreg, AT);
7390 if (imm_expr.X_op != O_constant)
7391 as_bad (_("Improper rotate count"));
7392 rot = imm_expr.X_add_number & 0x3f;
7393 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_arch))
7395 rot = (64 - rot) & 0x3f;
7397 macro_build ((char *) NULL, &icnt, NULL, "dror32",
7398 "d,w,<", dreg, sreg, rot - 32);
7400 macro_build ((char *) NULL, &icnt, NULL, "dror",
7401 "d,w,<", dreg, sreg, rot);
7406 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrl",
7407 "d,w,<", dreg, sreg, 0);
7410 l = (rot < 0x20) ? "dsll" : "dsll32";
7411 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
7413 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
7414 "d,w,<", AT, sreg, rot);
7415 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
7416 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7417 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
7418 "d,v,t", dreg, dreg, AT);
7426 if (imm_expr.X_op != O_constant)
7427 as_bad (_("Improper rotate count"));
7428 rot = imm_expr.X_add_number & 0x1f;
7429 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_arch))
7431 macro_build ((char *) NULL, &icnt, NULL, "ror",
7432 "d,w,<", dreg, sreg, (32 - rot) & 0x1f);
7437 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
7438 "d,w,<", dreg, sreg, 0);
7441 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
7442 "d,w,<", AT, sreg, rot);
7443 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
7444 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7445 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
7446 "d,v,t", dreg, dreg, AT);
7451 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_arch))
7453 macro_build ((char *) NULL, &icnt, NULL, "drorv",
7454 "d,t,s", dreg, sreg, treg);
7457 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
7458 "d,v,t", AT, 0, treg);
7459 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
7460 "d,t,s", AT, sreg, AT);
7461 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
7462 "d,t,s", dreg, sreg, treg);
7463 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
7464 "d,v,t", dreg, dreg, AT);
7468 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_arch))
7470 macro_build ((char *) NULL, &icnt, NULL, "rorv",
7471 "d,t,s", dreg, sreg, treg);
7474 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
7475 "d,v,t", AT, 0, treg);
7476 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
7477 "d,t,s", AT, sreg, AT);
7478 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
7479 "d,t,s", dreg, sreg, treg);
7480 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
7481 "d,v,t", dreg, dreg, AT);
7489 if (imm_expr.X_op != O_constant)
7490 as_bad (_("Improper rotate count"));
7491 rot = imm_expr.X_add_number & 0x3f;
7492 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_arch))
7495 macro_build ((char *) NULL, &icnt, NULL, "dror32",
7496 "d,w,<", dreg, sreg, rot - 32);
7498 macro_build ((char *) NULL, &icnt, NULL, "dror",
7499 "d,w,<", dreg, sreg, rot);
7504 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrl",
7505 "d,w,<", dreg, sreg, 0);
7508 r = (rot < 0x20) ? "dsrl" : "dsrl32";
7509 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
7511 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
7512 "d,w,<", AT, sreg, rot);
7513 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
7514 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7515 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
7516 "d,v,t", dreg, dreg, AT);
7524 if (imm_expr.X_op != O_constant)
7525 as_bad (_("Improper rotate count"));
7526 rot = imm_expr.X_add_number & 0x1f;
7527 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_arch))
7529 macro_build ((char *) NULL, &icnt, NULL, "ror",
7530 "d,w,<", dreg, sreg, rot);
7535 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
7536 "d,w,<", dreg, sreg, 0);
7539 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
7540 "d,w,<", AT, sreg, rot);
7541 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
7542 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7543 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
7544 "d,v,t", dreg, dreg, AT);
7549 if (mips_arch == CPU_R4650)
7551 as_bad (_("opcode not supported on this processor"));
7554 assert (mips_opts.isa == ISA_MIPS1);
7555 /* Even on a big endian machine $fn comes before $fn+1. We have
7556 to adjust when storing to memory. */
7557 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
7558 target_big_endian ? treg + 1 : treg,
7559 (int) BFD_RELOC_LO16, breg);
7560 offset_expr.X_add_number += 4;
7561 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
7562 target_big_endian ? treg : treg + 1,
7563 (int) BFD_RELOC_LO16, breg);
7568 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
7569 treg, (int) BFD_RELOC_LO16);
7571 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
7572 sreg, (int) BFD_RELOC_LO16);
7575 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
7576 "d,v,t", dreg, sreg, treg);
7577 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
7578 dreg, (int) BFD_RELOC_LO16);
7583 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7585 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
7586 sreg, (int) BFD_RELOC_LO16);
7591 as_warn (_("Instruction %s: result is always false"),
7593 move_register (&icnt, dreg, 0);
7596 if (imm_expr.X_op == O_constant
7597 && imm_expr.X_add_number >= 0
7598 && imm_expr.X_add_number < 0x10000)
7600 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
7601 sreg, (int) BFD_RELOC_LO16);
7604 else if (imm_expr.X_op == O_constant
7605 && imm_expr.X_add_number > -0x8000
7606 && imm_expr.X_add_number < 0)
7608 imm_expr.X_add_number = -imm_expr.X_add_number;
7609 macro_build ((char *) NULL, &icnt, &imm_expr,
7610 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7611 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7616 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7617 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
7618 "d,v,t", dreg, sreg, AT);
7621 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
7622 (int) BFD_RELOC_LO16);
7627 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
7633 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
7635 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7636 (int) BFD_RELOC_LO16);
7639 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
7641 if (imm_expr.X_op == O_constant
7642 && imm_expr.X_add_number >= -0x8000
7643 && imm_expr.X_add_number < 0x8000)
7645 macro_build ((char *) NULL, &icnt, &imm_expr,
7646 mask == M_SGE_I ? "slti" : "sltiu",
7647 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7652 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7653 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7654 mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg,
7658 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7659 (int) BFD_RELOC_LO16);
7664 case M_SGT: /* sreg > treg <==> treg < sreg */
7670 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
7674 case M_SGT_I: /* sreg > I <==> I < sreg */
7680 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7681 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
7685 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7691 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
7693 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7694 (int) BFD_RELOC_LO16);
7697 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7703 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7704 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
7706 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7707 (int) BFD_RELOC_LO16);
7711 if (imm_expr.X_op == O_constant
7712 && imm_expr.X_add_number >= -0x8000
7713 && imm_expr.X_add_number < 0x8000)
7715 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
7716 dreg, sreg, (int) BFD_RELOC_LO16);
7719 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7720 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
7725 if (imm_expr.X_op == O_constant
7726 && imm_expr.X_add_number >= -0x8000
7727 && imm_expr.X_add_number < 0x8000)
7729 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
7730 dreg, sreg, (int) BFD_RELOC_LO16);
7733 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7734 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7735 "d,v,t", dreg, sreg, AT);
7740 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7741 "d,v,t", dreg, 0, treg);
7743 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7744 "d,v,t", dreg, 0, sreg);
7747 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
7748 "d,v,t", dreg, sreg, treg);
7749 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7750 "d,v,t", dreg, 0, dreg);
7755 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7757 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7758 "d,v,t", dreg, 0, sreg);
7763 as_warn (_("Instruction %s: result is always true"),
7765 macro_build ((char *) NULL, &icnt, &expr1,
7766 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7767 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
7770 if (imm_expr.X_op == O_constant
7771 && imm_expr.X_add_number >= 0
7772 && imm_expr.X_add_number < 0x10000)
7774 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
7775 dreg, sreg, (int) BFD_RELOC_LO16);
7778 else if (imm_expr.X_op == O_constant
7779 && imm_expr.X_add_number > -0x8000
7780 && imm_expr.X_add_number < 0)
7782 imm_expr.X_add_number = -imm_expr.X_add_number;
7783 macro_build ((char *) NULL, &icnt, &imm_expr,
7784 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7785 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7790 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7791 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
7792 "d,v,t", dreg, sreg, AT);
7795 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7796 "d,v,t", dreg, 0, dreg);
7804 if (imm_expr.X_op == O_constant
7805 && imm_expr.X_add_number > -0x8000
7806 && imm_expr.X_add_number <= 0x8000)
7808 imm_expr.X_add_number = -imm_expr.X_add_number;
7809 macro_build ((char *) NULL, &icnt, &imm_expr,
7810 dbl ? "daddi" : "addi",
7811 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7814 load_register (&icnt, AT, &imm_expr, dbl);
7815 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7816 dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
7822 if (imm_expr.X_op == O_constant
7823 && imm_expr.X_add_number > -0x8000
7824 && imm_expr.X_add_number <= 0x8000)
7826 imm_expr.X_add_number = -imm_expr.X_add_number;
7827 macro_build ((char *) NULL, &icnt, &imm_expr,
7828 dbl ? "daddiu" : "addiu",
7829 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7832 load_register (&icnt, AT, &imm_expr, dbl);
7833 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7834 dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
7855 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7856 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg,
7862 assert (mips_opts.isa == ISA_MIPS1);
7863 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7864 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7867 * Is the double cfc1 instruction a bug in the mips assembler;
7868 * or is there a reason for it?
7870 mips_emit_delays (TRUE);
7871 ++mips_opts.noreorder;
7872 mips_any_noreorder = 1;
7873 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7875 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7877 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7878 expr1.X_add_number = 3;
7879 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7880 (int) BFD_RELOC_LO16);
7881 expr1.X_add_number = 2;
7882 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7883 (int) BFD_RELOC_LO16);
7884 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7886 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7887 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7888 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
7889 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7891 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7892 --mips_opts.noreorder;
7901 if (offset_expr.X_add_number >= 0x7fff)
7902 as_bad (_("operand overflow"));
7903 if (! target_big_endian)
7904 ++offset_expr.X_add_number;
7905 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", AT,
7906 (int) BFD_RELOC_LO16, breg);
7907 if (! target_big_endian)
7908 --offset_expr.X_add_number;
7910 ++offset_expr.X_add_number;
7911 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", treg,
7912 (int) BFD_RELOC_LO16, breg);
7913 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7915 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7929 if (offset_expr.X_add_number >= 0x8000 - off)
7930 as_bad (_("operand overflow"));
7935 if (! target_big_endian)
7936 offset_expr.X_add_number += off;
7937 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", tempreg,
7938 (int) BFD_RELOC_LO16, breg);
7939 if (! target_big_endian)
7940 offset_expr.X_add_number -= off;
7942 offset_expr.X_add_number += off;
7943 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", tempreg,
7944 (int) BFD_RELOC_LO16, breg);
7946 /* If necessary, move the result in tempreg the final destination. */
7947 if (treg == tempreg)
7949 /* Protect second load's delay slot. */
7950 if (!gpr_interlocks)
7951 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7952 move_register (&icnt, treg, tempreg);
7966 load_address (&icnt, AT, &offset_expr, &used_at);
7968 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7969 ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7970 if (! target_big_endian)
7971 expr1.X_add_number = off;
7973 expr1.X_add_number = 0;
7974 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7975 (int) BFD_RELOC_LO16, AT);
7976 if (! target_big_endian)
7977 expr1.X_add_number = 0;
7979 expr1.X_add_number = off;
7980 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7981 (int) BFD_RELOC_LO16, AT);
7987 load_address (&icnt, AT, &offset_expr, &used_at);
7989 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7990 ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7991 if (target_big_endian)
7992 expr1.X_add_number = 0;
7993 macro_build ((char *) NULL, &icnt, &expr1,
7994 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
7995 (int) BFD_RELOC_LO16, AT);
7996 if (target_big_endian)
7997 expr1.X_add_number = 1;
7999 expr1.X_add_number = 0;
8000 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
8001 (int) BFD_RELOC_LO16, AT);
8002 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
8004 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
8009 if (offset_expr.X_add_number >= 0x7fff)
8010 as_bad (_("operand overflow"));
8011 if (target_big_endian)
8012 ++offset_expr.X_add_number;
8013 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
8014 (int) BFD_RELOC_LO16, breg);
8015 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
8017 if (target_big_endian)
8018 --offset_expr.X_add_number;
8020 ++offset_expr.X_add_number;
8021 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
8022 (int) BFD_RELOC_LO16, breg);
8035 if (offset_expr.X_add_number >= 0x8000 - off)
8036 as_bad (_("operand overflow"));
8037 if (! target_big_endian)
8038 offset_expr.X_add_number += off;
8039 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
8040 (int) BFD_RELOC_LO16, breg);
8041 if (! target_big_endian)
8042 offset_expr.X_add_number -= off;
8044 offset_expr.X_add_number += off;
8045 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
8046 (int) BFD_RELOC_LO16, breg);
8060 load_address (&icnt, AT, &offset_expr, &used_at);
8062 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
8063 ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
8064 if (! target_big_endian)
8065 expr1.X_add_number = off;
8067 expr1.X_add_number = 0;
8068 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
8069 (int) BFD_RELOC_LO16, AT);
8070 if (! target_big_endian)
8071 expr1.X_add_number = 0;
8073 expr1.X_add_number = off;
8074 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
8075 (int) BFD_RELOC_LO16, AT);
8080 load_address (&icnt, AT, &offset_expr, &used_at);
8082 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
8083 ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
8084 if (! target_big_endian)
8085 expr1.X_add_number = 0;
8086 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
8087 (int) BFD_RELOC_LO16, AT);
8088 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
8090 if (! target_big_endian)
8091 expr1.X_add_number = 1;
8093 expr1.X_add_number = 0;
8094 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
8095 (int) BFD_RELOC_LO16, AT);
8096 if (! target_big_endian)
8097 expr1.X_add_number = 0;
8099 expr1.X_add_number = 1;
8100 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
8101 (int) BFD_RELOC_LO16, AT);
8102 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
8104 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
8109 /* FIXME: Check if this is one of the itbl macros, since they
8110 are added dynamically. */
8111 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
8115 as_warn (_("Macro used $at after \".set noat\""));
8118 /* Implement macros in mips16 mode. */
8122 struct mips_cl_insn *ip;
8125 int xreg, yreg, zreg, tmp;
8129 const char *s, *s2, *s3;
8131 mask = ip->insn_mo->mask;
8133 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
8134 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
8135 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
8139 expr1.X_op = O_constant;
8140 expr1.X_op_symbol = NULL;
8141 expr1.X_add_symbol = NULL;
8142 expr1.X_add_number = 1;
8161 mips_emit_delays (TRUE);
8162 ++mips_opts.noreorder;
8163 mips_any_noreorder = 1;
8164 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
8165 dbl ? "ddiv" : "div",
8166 "0,x,y", xreg, yreg);
8167 expr1.X_add_number = 2;
8168 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
8169 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6",
8172 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
8173 since that causes an overflow. We should do that as well,
8174 but I don't see how to do the comparisons without a temporary
8176 --mips_opts.noreorder;
8177 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg);
8196 mips_emit_delays (TRUE);
8197 ++mips_opts.noreorder;
8198 mips_any_noreorder = 1;
8199 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y",
8201 expr1.X_add_number = 2;
8202 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
8203 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
8205 --mips_opts.noreorder;
8206 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg);
8212 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
8213 dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
8214 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x",
8223 if (imm_expr.X_op != O_constant)
8224 as_bad (_("Unsupported large constant"));
8225 imm_expr.X_add_number = -imm_expr.X_add_number;
8226 macro_build ((char *) NULL, &icnt, &imm_expr,
8227 dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
8231 if (imm_expr.X_op != O_constant)
8232 as_bad (_("Unsupported large constant"));
8233 imm_expr.X_add_number = -imm_expr.X_add_number;
8234 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
8239 if (imm_expr.X_op != O_constant)
8240 as_bad (_("Unsupported large constant"));
8241 imm_expr.X_add_number = -imm_expr.X_add_number;
8242 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
8265 goto do_reverse_branch;
8269 goto do_reverse_branch;
8281 goto do_reverse_branch;
8292 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
8294 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
8321 goto do_addone_branch_i;
8326 goto do_addone_branch_i;
8341 goto do_addone_branch_i;
8348 if (imm_expr.X_op != O_constant)
8349 as_bad (_("Unsupported large constant"));
8350 ++imm_expr.X_add_number;
8353 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
8354 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
8358 expr1.X_add_number = 0;
8359 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
8361 move_register (&icnt, xreg, yreg);
8362 expr1.X_add_number = 2;
8363 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
8364 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
8365 "neg", "x,w", xreg, xreg);
8369 /* For consistency checking, verify that all bits are specified either
8370 by the match/mask part of the instruction definition, or by the
8373 validate_mips_insn (opc)
8374 const struct mips_opcode *opc;
8376 const char *p = opc->args;
8378 unsigned long used_bits = opc->mask;
8380 if ((used_bits & opc->match) != opc->match)
8382 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
8383 opc->name, opc->args);
8386 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
8396 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8397 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
8398 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8399 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
8400 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8402 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8403 c, opc->name, opc->args);
8407 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8408 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8410 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
8411 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
8412 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8413 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8415 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8416 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8418 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
8419 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8421 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
8422 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
8423 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
8424 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
8425 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8426 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
8427 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8428 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8429 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8430 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8431 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8432 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8433 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8434 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
8435 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8436 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
8437 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8439 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
8440 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8441 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8442 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
8444 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8445 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8446 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
8447 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8448 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8449 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8450 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8451 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8452 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8455 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
8456 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
8457 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8458 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
8459 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
8463 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
8464 c, opc->name, opc->args);
8468 if (used_bits != 0xffffffff)
8470 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
8471 ~used_bits & 0xffffffff, opc->name, opc->args);
8477 /* This routine assembles an instruction into its binary format. As a
8478 side effect, it sets one of the global variables imm_reloc or
8479 offset_reloc to the type of relocation to do if one of the operands
8480 is an address expression. */
8485 struct mips_cl_insn *ip;
8490 struct mips_opcode *insn;
8493 unsigned int lastregno = 0;
8494 unsigned int lastpos = 0;
8495 unsigned int limlo, limhi;
8501 /* If the instruction contains a '.', we first try to match an instruction
8502 including the '.'. Then we try again without the '.'. */
8504 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
8507 /* If we stopped on whitespace, then replace the whitespace with null for
8508 the call to hash_find. Save the character we replaced just in case we
8509 have to re-parse the instruction. */
8516 insn = (struct mips_opcode *) hash_find (op_hash, str);
8518 /* If we didn't find the instruction in the opcode table, try again, but
8519 this time with just the instruction up to, but not including the
8523 /* Restore the character we overwrite above (if any). */
8527 /* Scan up to the first '.' or whitespace. */
8529 *s != '\0' && *s != '.' && !ISSPACE (*s);
8533 /* If we did not find a '.', then we can quit now. */
8536 insn_error = "unrecognized opcode";
8540 /* Lookup the instruction in the hash table. */
8542 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
8544 insn_error = "unrecognized opcode";
8554 assert (strcmp (insn->name, str) == 0);
8556 if (OPCODE_IS_MEMBER (insn,
8558 | (file_ase_mips16 ? INSN_MIPS16 : 0)
8559 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
8560 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
8566 if (insn->pinfo != INSN_MACRO)
8568 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
8574 if (insn + 1 < &mips_opcodes[NUMOPCODES]
8575 && strcmp (insn->name, insn[1].name) == 0)
8584 static char buf[100];
8585 if (mips_arch_info->is_isa)
8587 _("opcode not supported at this ISA level (%s)"),
8588 mips_cpu_info_from_isa (mips_opts.isa)->name);
8591 _("opcode not supported on this processor: %s (%s)"),
8592 mips_arch_info->name,
8593 mips_cpu_info_from_isa (mips_opts.isa)->name);
8603 ip->insn_opcode = insn->match;
8605 for (args = insn->args;; ++args)
8609 s += strspn (s, " \t");
8613 case '\0': /* end of args */
8626 ip->insn_opcode |= lastregno << OP_SH_RS;
8630 ip->insn_opcode |= lastregno << OP_SH_RT;
8634 ip->insn_opcode |= lastregno << OP_SH_FT;
8638 ip->insn_opcode |= lastregno << OP_SH_FS;
8644 /* Handle optional base register.
8645 Either the base register is omitted or
8646 we must have a left paren. */
8647 /* This is dependent on the next operand specifier
8648 is a base register specification. */
8649 assert (args[1] == 'b' || args[1] == '5'
8650 || args[1] == '-' || args[1] == '4');
8654 case ')': /* these must match exactly */
8661 case '+': /* Opcode extension character. */
8664 case 'A': /* ins/ext position, becomes LSB. */
8667 my_getExpression (&imm_expr, s);
8668 check_absolute_expr (ip, &imm_expr);
8669 if ((unsigned long) imm_expr.X_add_number < limlo
8670 || (unsigned long) imm_expr.X_add_number > limhi)
8672 as_bad (_("Improper position (%lu)"),
8673 (unsigned long) imm_expr.X_add_number);
8674 imm_expr.X_add_number = limlo;
8676 lastpos = imm_expr.X_add_number;
8677 ip->insn_opcode |= (imm_expr.X_add_number
8678 & OP_MASK_SHAMT) << OP_SH_SHAMT;
8679 imm_expr.X_op = O_absent;
8683 case 'B': /* ins size, becomes MSB. */
8686 my_getExpression (&imm_expr, s);
8687 check_absolute_expr (ip, &imm_expr);
8688 /* Check for negative input so that small negative numbers
8689 will not succeed incorrectly. The checks against
8690 (pos+size) transitively check "size" itself,
8691 assuming that "pos" is reasonable. */
8692 if ((long) imm_expr.X_add_number < 0
8693 || ((unsigned long) imm_expr.X_add_number
8695 || ((unsigned long) imm_expr.X_add_number
8698 as_bad (_("Improper insert size (%lu, position %lu)"),
8699 (unsigned long) imm_expr.X_add_number,
8700 (unsigned long) lastpos);
8701 imm_expr.X_add_number = limlo - lastpos;
8703 ip->insn_opcode |= ((lastpos + imm_expr.X_add_number - 1)
8704 & OP_MASK_INSMSB) << OP_SH_INSMSB;
8705 imm_expr.X_op = O_absent;
8709 case 'C': /* ext size, becomes MSBD. */
8712 my_getExpression (&imm_expr, s);
8713 check_absolute_expr (ip, &imm_expr);
8714 /* Check for negative input so that small negative numbers
8715 will not succeed incorrectly. The checks against
8716 (pos+size) transitively check "size" itself,
8717 assuming that "pos" is reasonable. */
8718 if ((long) imm_expr.X_add_number < 0
8719 || ((unsigned long) imm_expr.X_add_number
8721 || ((unsigned long) imm_expr.X_add_number
8724 as_bad (_("Improper extract size (%lu, position %lu)"),
8725 (unsigned long) imm_expr.X_add_number,
8726 (unsigned long) lastpos);
8727 imm_expr.X_add_number = limlo - lastpos;
8729 ip->insn_opcode |= ((imm_expr.X_add_number - 1)
8730 & OP_MASK_EXTMSBD) << OP_SH_EXTMSBD;
8731 imm_expr.X_op = O_absent;
8736 /* +D is for disassembly only; never match. */
8740 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8741 *args, insn->name, insn->args);
8742 /* Further processing is fruitless. */
8747 case '<': /* must be at least one digit */
8749 * According to the manual, if the shift amount is greater
8750 * than 31 or less than 0, then the shift amount should be
8751 * mod 32. In reality the mips assembler issues an error.
8752 * We issue a warning and mask out all but the low 5 bits.
8754 my_getExpression (&imm_expr, s);
8755 check_absolute_expr (ip, &imm_expr);
8756 if ((unsigned long) imm_expr.X_add_number > 31)
8758 as_warn (_("Improper shift amount (%lu)"),
8759 (unsigned long) imm_expr.X_add_number);
8760 imm_expr.X_add_number &= OP_MASK_SHAMT;
8762 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
8763 imm_expr.X_op = O_absent;
8767 case '>': /* shift amount minus 32 */
8768 my_getExpression (&imm_expr, s);
8769 check_absolute_expr (ip, &imm_expr);
8770 if ((unsigned long) imm_expr.X_add_number < 32
8771 || (unsigned long) imm_expr.X_add_number > 63)
8773 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
8774 imm_expr.X_op = O_absent;
8778 case 'k': /* cache code */
8779 case 'h': /* prefx code */
8780 my_getExpression (&imm_expr, s);
8781 check_absolute_expr (ip, &imm_expr);
8782 if ((unsigned long) imm_expr.X_add_number > 31)
8784 as_warn (_("Invalid value for `%s' (%lu)"),
8786 (unsigned long) imm_expr.X_add_number);
8787 imm_expr.X_add_number &= 0x1f;
8790 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
8792 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
8793 imm_expr.X_op = O_absent;
8797 case 'c': /* break code */
8798 my_getExpression (&imm_expr, s);
8799 check_absolute_expr (ip, &imm_expr);
8800 if ((unsigned long) imm_expr.X_add_number > 1023)
8802 as_warn (_("Illegal break code (%lu)"),
8803 (unsigned long) imm_expr.X_add_number);
8804 imm_expr.X_add_number &= OP_MASK_CODE;
8806 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
8807 imm_expr.X_op = O_absent;
8811 case 'q': /* lower break code */
8812 my_getExpression (&imm_expr, s);
8813 check_absolute_expr (ip, &imm_expr);
8814 if ((unsigned long) imm_expr.X_add_number > 1023)
8816 as_warn (_("Illegal lower break code (%lu)"),
8817 (unsigned long) imm_expr.X_add_number);
8818 imm_expr.X_add_number &= OP_MASK_CODE2;
8820 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
8821 imm_expr.X_op = O_absent;
8825 case 'B': /* 20-bit syscall/break code. */
8826 my_getExpression (&imm_expr, s);
8827 check_absolute_expr (ip, &imm_expr);
8828 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
8829 as_warn (_("Illegal 20-bit code (%lu)"),
8830 (unsigned long) imm_expr.X_add_number);
8831 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
8832 imm_expr.X_op = O_absent;
8836 case 'C': /* Coprocessor code */
8837 my_getExpression (&imm_expr, s);
8838 check_absolute_expr (ip, &imm_expr);
8839 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
8841 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8842 (unsigned long) imm_expr.X_add_number);
8843 imm_expr.X_add_number &= ((1 << 25) - 1);
8845 ip->insn_opcode |= imm_expr.X_add_number;
8846 imm_expr.X_op = O_absent;
8850 case 'J': /* 19-bit wait code. */
8851 my_getExpression (&imm_expr, s);
8852 check_absolute_expr (ip, &imm_expr);
8853 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
8854 as_warn (_("Illegal 19-bit code (%lu)"),
8855 (unsigned long) imm_expr.X_add_number);
8856 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
8857 imm_expr.X_op = O_absent;
8861 case 'P': /* Performance register */
8862 my_getExpression (&imm_expr, s);
8863 check_absolute_expr (ip, &imm_expr);
8864 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
8866 as_warn (_("Invalid performance register (%lu)"),
8867 (unsigned long) imm_expr.X_add_number);
8868 imm_expr.X_add_number &= OP_MASK_PERFREG;
8870 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
8871 imm_expr.X_op = O_absent;
8875 case 'b': /* base register */
8876 case 'd': /* destination register */
8877 case 's': /* source register */
8878 case 't': /* target register */
8879 case 'r': /* both target and source */
8880 case 'v': /* both dest and source */
8881 case 'w': /* both dest and target */
8882 case 'E': /* coprocessor target register */
8883 case 'G': /* coprocessor destination register */
8884 case 'K': /* 'rdhwr' destination register */
8885 case 'x': /* ignore register name */
8886 case 'z': /* must be zero register */
8887 case 'U': /* destination register (clo/clz). */
8902 while (ISDIGIT (*s));
8904 as_bad (_("Invalid register number (%d)"), regno);
8906 else if (*args == 'E' || *args == 'G' || *args == 'K')
8910 if (s[1] == 'r' && s[2] == 'a')
8915 else if (s[1] == 'f' && s[2] == 'p')
8920 else if (s[1] == 's' && s[2] == 'p')
8925 else if (s[1] == 'g' && s[2] == 'p')
8930 else if (s[1] == 'a' && s[2] == 't')
8935 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8940 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8945 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8950 else if (itbl_have_entries)
8955 p = s + 1; /* advance past '$' */
8956 n = itbl_get_field (&p); /* n is name */
8958 /* See if this is a register defined in an
8960 if (itbl_get_reg_val (n, &r))
8962 /* Get_field advances to the start of
8963 the next field, so we need to back
8964 rack to the end of the last field. */
8968 s = strchr (s, '\0');
8982 as_warn (_("Used $at without \".set noat\""));
8988 if (c == 'r' || c == 'v' || c == 'w')
8995 /* 'z' only matches $0. */
8996 if (c == 'z' && regno != 0)
8999 /* Now that we have assembled one operand, we use the args string
9000 * to figure out where it goes in the instruction. */
9007 ip->insn_opcode |= regno << OP_SH_RS;
9012 ip->insn_opcode |= regno << OP_SH_RD;
9015 ip->insn_opcode |= regno << OP_SH_RD;
9016 ip->insn_opcode |= regno << OP_SH_RT;
9021 ip->insn_opcode |= regno << OP_SH_RT;
9024 /* This case exists because on the r3000 trunc
9025 expands into a macro which requires a gp
9026 register. On the r6000 or r4000 it is
9027 assembled into a single instruction which
9028 ignores the register. Thus the insn version
9029 is MIPS_ISA2 and uses 'x', and the macro
9030 version is MIPS_ISA1 and uses 't'. */
9033 /* This case is for the div instruction, which
9034 acts differently if the destination argument
9035 is $0. This only matches $0, and is checked
9036 outside the switch. */
9039 /* Itbl operand; not yet implemented. FIXME ?? */
9041 /* What about all other operands like 'i', which
9042 can be specified in the opcode table? */
9052 ip->insn_opcode |= lastregno << OP_SH_RS;
9055 ip->insn_opcode |= lastregno << OP_SH_RT;
9060 case 'O': /* MDMX alignment immediate constant. */
9061 my_getExpression (&imm_expr, s);
9062 check_absolute_expr (ip, &imm_expr);
9063 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
9065 as_warn ("Improper align amount (%ld), using low bits",
9066 (long) imm_expr.X_add_number);
9067 imm_expr.X_add_number &= OP_MASK_ALN;
9069 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_ALN;
9070 imm_expr.X_op = O_absent;
9074 case 'Q': /* MDMX vector, element sel, or const. */
9077 /* MDMX Immediate. */
9078 my_getExpression (&imm_expr, s);
9079 check_absolute_expr (ip, &imm_expr);
9080 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
9082 as_warn (_("Invalid MDMX Immediate (%ld)"),
9083 (long) imm_expr.X_add_number);
9084 imm_expr.X_add_number &= OP_MASK_FT;
9086 imm_expr.X_add_number &= OP_MASK_FT;
9087 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
9088 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
9090 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
9091 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_FT;
9092 imm_expr.X_op = O_absent;
9096 /* Not MDMX Immediate. Fall through. */
9097 case 'X': /* MDMX destination register. */
9098 case 'Y': /* MDMX source register. */
9099 case 'Z': /* MDMX target register. */
9101 case 'D': /* floating point destination register */
9102 case 'S': /* floating point source register */
9103 case 'T': /* floating point target register */
9104 case 'R': /* floating point source register */
9108 /* Accept $fN for FP and MDMX register numbers, and in
9109 addition accept $vN for MDMX register numbers. */
9110 if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2]))
9111 || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v'
9122 while (ISDIGIT (*s));
9125 as_bad (_("Invalid float register number (%d)"), regno);
9127 if ((regno & 1) != 0
9129 && ! (strcmp (str, "mtc1") == 0
9130 || strcmp (str, "mfc1") == 0
9131 || strcmp (str, "lwc1") == 0
9132 || strcmp (str, "swc1") == 0
9133 || strcmp (str, "l.s") == 0
9134 || strcmp (str, "s.s") == 0))
9135 as_warn (_("Float register should be even, was %d"),
9143 if (c == 'V' || c == 'W')
9154 ip->insn_opcode |= regno << OP_SH_FD;
9159 ip->insn_opcode |= regno << OP_SH_FS;
9162 /* This is like 'Z', but also needs to fix the MDMX
9163 vector/scalar select bits. Note that the
9164 scalar immediate case is handled above. */
9167 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
9168 int max_el = (is_qh ? 3 : 7);
9170 my_getExpression(&imm_expr, s);
9171 check_absolute_expr (ip, &imm_expr);
9173 if (imm_expr.X_add_number > max_el)
9174 as_bad(_("Bad element selector %ld"),
9175 (long) imm_expr.X_add_number);
9176 imm_expr.X_add_number &= max_el;
9177 ip->insn_opcode |= (imm_expr.X_add_number
9181 as_warn(_("Expecting ']' found '%s'"), s);
9187 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
9188 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
9191 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
9198 ip->insn_opcode |= regno << OP_SH_FT;
9201 ip->insn_opcode |= regno << OP_SH_FR;
9211 ip->insn_opcode |= lastregno << OP_SH_FS;
9214 ip->insn_opcode |= lastregno << OP_SH_FT;
9220 my_getExpression (&imm_expr, s);
9221 if (imm_expr.X_op != O_big
9222 && imm_expr.X_op != O_constant)
9223 insn_error = _("absolute expression required");
9228 my_getExpression (&offset_expr, s);
9229 *imm_reloc = BFD_RELOC_32;
9242 unsigned char temp[8];
9244 unsigned int length;
9249 /* These only appear as the last operand in an
9250 instruction, and every instruction that accepts
9251 them in any variant accepts them in all variants.
9252 This means we don't have to worry about backing out
9253 any changes if the instruction does not match.
9255 The difference between them is the size of the
9256 floating point constant and where it goes. For 'F'
9257 and 'L' the constant is 64 bits; for 'f' and 'l' it
9258 is 32 bits. Where the constant is placed is based
9259 on how the MIPS assembler does things:
9262 f -- immediate value
9265 The .lit4 and .lit8 sections are only used if
9266 permitted by the -G argument.
9268 When generating embedded PIC code, we use the
9269 .lit8 section but not the .lit4 section (we can do
9270 .lit4 inline easily; we need to put .lit8
9271 somewhere in the data segment, and using .lit8
9272 permits the linker to eventually combine identical
9275 The code below needs to know whether the target register
9276 is 32 or 64 bits wide. It relies on the fact 'f' and
9277 'F' are used with GPR-based instructions and 'l' and
9278 'L' are used with FPR-based instructions. */
9280 f64 = *args == 'F' || *args == 'L';
9281 using_gprs = *args == 'F' || *args == 'f';
9283 save_in = input_line_pointer;
9284 input_line_pointer = s;
9285 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
9287 s = input_line_pointer;
9288 input_line_pointer = save_in;
9289 if (err != NULL && *err != '\0')
9291 as_bad (_("Bad floating point constant: %s"), err);
9292 memset (temp, '\0', sizeof temp);
9293 length = f64 ? 8 : 4;
9296 assert (length == (unsigned) (f64 ? 8 : 4));
9300 && (! USE_GLOBAL_POINTER_OPT
9301 || mips_pic == EMBEDDED_PIC
9302 || g_switch_value < 4
9303 || (temp[0] == 0 && temp[1] == 0)
9304 || (temp[2] == 0 && temp[3] == 0))))
9306 imm_expr.X_op = O_constant;
9307 if (! target_big_endian)
9308 imm_expr.X_add_number = bfd_getl32 (temp);
9310 imm_expr.X_add_number = bfd_getb32 (temp);
9313 && ! mips_disable_float_construction
9314 /* Constants can only be constructed in GPRs and
9315 copied to FPRs if the GPRs are at least as wide
9316 as the FPRs. Force the constant into memory if
9317 we are using 64-bit FPRs but the GPRs are only
9320 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
9321 && ((temp[0] == 0 && temp[1] == 0)
9322 || (temp[2] == 0 && temp[3] == 0))
9323 && ((temp[4] == 0 && temp[5] == 0)
9324 || (temp[6] == 0 && temp[7] == 0)))
9326 /* The value is simple enough to load with a couple of
9327 instructions. If using 32-bit registers, set
9328 imm_expr to the high order 32 bits and offset_expr to
9329 the low order 32 bits. Otherwise, set imm_expr to
9330 the entire 64 bit constant. */
9331 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
9333 imm_expr.X_op = O_constant;
9334 offset_expr.X_op = O_constant;
9335 if (! target_big_endian)
9337 imm_expr.X_add_number = bfd_getl32 (temp + 4);
9338 offset_expr.X_add_number = bfd_getl32 (temp);
9342 imm_expr.X_add_number = bfd_getb32 (temp);
9343 offset_expr.X_add_number = bfd_getb32 (temp + 4);
9345 if (offset_expr.X_add_number == 0)
9346 offset_expr.X_op = O_absent;
9348 else if (sizeof (imm_expr.X_add_number) > 4)
9350 imm_expr.X_op = O_constant;
9351 if (! target_big_endian)
9352 imm_expr.X_add_number = bfd_getl64 (temp);
9354 imm_expr.X_add_number = bfd_getb64 (temp);
9358 imm_expr.X_op = O_big;
9359 imm_expr.X_add_number = 4;
9360 if (! target_big_endian)
9362 generic_bignum[0] = bfd_getl16 (temp);
9363 generic_bignum[1] = bfd_getl16 (temp + 2);
9364 generic_bignum[2] = bfd_getl16 (temp + 4);
9365 generic_bignum[3] = bfd_getl16 (temp + 6);
9369 generic_bignum[0] = bfd_getb16 (temp + 6);
9370 generic_bignum[1] = bfd_getb16 (temp + 4);
9371 generic_bignum[2] = bfd_getb16 (temp + 2);
9372 generic_bignum[3] = bfd_getb16 (temp);
9378 const char *newname;
9381 /* Switch to the right section. */
9383 subseg = now_subseg;
9386 default: /* unused default case avoids warnings. */
9388 newname = RDATA_SECTION_NAME;
9389 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
9390 || mips_pic == EMBEDDED_PIC)
9394 if (mips_pic == EMBEDDED_PIC)
9397 newname = RDATA_SECTION_NAME;
9400 assert (!USE_GLOBAL_POINTER_OPT
9401 || g_switch_value >= 4);
9405 new_seg = subseg_new (newname, (subsegT) 0);
9406 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
9407 bfd_set_section_flags (stdoutput, new_seg,
9412 frag_align (*args == 'l' ? 2 : 3, 0, 0);
9413 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9414 && strcmp (TARGET_OS, "elf") != 0)
9415 record_alignment (new_seg, 4);
9417 record_alignment (new_seg, *args == 'l' ? 2 : 3);
9419 as_bad (_("Can't use floating point insn in this section"));
9421 /* Set the argument to the current address in the
9423 offset_expr.X_op = O_symbol;
9424 offset_expr.X_add_symbol =
9425 symbol_new ("L0\001", now_seg,
9426 (valueT) frag_now_fix (), frag_now);
9427 offset_expr.X_add_number = 0;
9429 /* Put the floating point number into the section. */
9430 p = frag_more ((int) length);
9431 memcpy (p, temp, length);
9433 /* Switch back to the original section. */
9434 subseg_set (seg, subseg);
9439 case 'i': /* 16 bit unsigned immediate */
9440 case 'j': /* 16 bit signed immediate */
9441 *imm_reloc = BFD_RELOC_LO16;
9442 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
9445 offsetT minval, maxval;
9447 more = (insn + 1 < &mips_opcodes[NUMOPCODES]
9448 && strcmp (insn->name, insn[1].name) == 0);
9450 /* If the expression was written as an unsigned number,
9451 only treat it as signed if there are no more
9455 && sizeof (imm_expr.X_add_number) <= 4
9456 && imm_expr.X_op == O_constant
9457 && imm_expr.X_add_number < 0
9458 && imm_expr.X_unsigned
9462 /* For compatibility with older assemblers, we accept
9463 0x8000-0xffff as signed 16-bit numbers when only
9464 signed numbers are allowed. */
9466 minval = 0, maxval = 0xffff;
9468 minval = -0x8000, maxval = 0x7fff;
9470 minval = -0x8000, maxval = 0xffff;
9472 if (imm_expr.X_op != O_constant
9473 || imm_expr.X_add_number < minval
9474 || imm_expr.X_add_number > maxval)
9478 if (imm_expr.X_op == O_constant
9479 || imm_expr.X_op == O_big)
9480 as_bad (_("expression out of range"));
9486 case 'o': /* 16 bit offset */
9487 /* Check whether there is only a single bracketed expression
9488 left. If so, it must be the base register and the
9489 constant must be zero. */
9490 if (*s == '(' && strchr (s + 1, '(') == 0)
9492 offset_expr.X_op = O_constant;
9493 offset_expr.X_add_number = 0;
9497 /* If this value won't fit into a 16 bit offset, then go
9498 find a macro that will generate the 32 bit offset
9500 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
9501 && (offset_expr.X_op != O_constant
9502 || offset_expr.X_add_number >= 0x8000
9503 || offset_expr.X_add_number < -0x8000))
9509 case 'p': /* pc relative offset */
9510 *offset_reloc = BFD_RELOC_16_PCREL_S2;
9511 my_getExpression (&offset_expr, s);
9515 case 'u': /* upper 16 bits */
9516 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
9517 && imm_expr.X_op == O_constant
9518 && (imm_expr.X_add_number < 0
9519 || imm_expr.X_add_number >= 0x10000))
9520 as_bad (_("lui expression not in range 0..65535"));
9524 case 'a': /* 26 bit address */
9525 my_getExpression (&offset_expr, s);
9527 *offset_reloc = BFD_RELOC_MIPS_JMP;
9530 case 'N': /* 3 bit branch condition code */
9531 case 'M': /* 3 bit compare condition code */
9532 if (strncmp (s, "$fcc", 4) != 0)
9542 while (ISDIGIT (*s));
9544 as_bad (_("invalid condition code register $fcc%d"), regno);
9546 ip->insn_opcode |= regno << OP_SH_BCC;
9548 ip->insn_opcode |= regno << OP_SH_CCC;
9552 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
9563 while (ISDIGIT (*s));
9566 c = 8; /* Invalid sel value. */
9569 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9570 ip->insn_opcode |= c;
9574 /* Must be at least one digit. */
9575 my_getExpression (&imm_expr, s);
9576 check_absolute_expr (ip, &imm_expr);
9578 if ((unsigned long) imm_expr.X_add_number
9579 > (unsigned long) OP_MASK_VECBYTE)
9581 as_bad (_("bad byte vector index (%ld)"),
9582 (long) imm_expr.X_add_number);
9583 imm_expr.X_add_number = 0;
9586 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECBYTE;
9587 imm_expr.X_op = O_absent;
9592 my_getExpression (&imm_expr, s);
9593 check_absolute_expr (ip, &imm_expr);
9595 if ((unsigned long) imm_expr.X_add_number
9596 > (unsigned long) OP_MASK_VECALIGN)
9598 as_bad (_("bad byte vector index (%ld)"),
9599 (long) imm_expr.X_add_number);
9600 imm_expr.X_add_number = 0;
9603 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECALIGN;
9604 imm_expr.X_op = O_absent;
9609 as_bad (_("bad char = '%c'\n"), *args);
9614 /* Args don't match. */
9615 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
9616 !strcmp (insn->name, insn[1].name))
9620 insn_error = _("illegal operands");
9625 insn_error = _("illegal operands");
9630 /* This routine assembles an instruction into its binary format when
9631 assembling for the mips16. As a side effect, it sets one of the
9632 global variables imm_reloc or offset_reloc to the type of
9633 relocation to do if one of the operands is an address expression.
9634 It also sets mips16_small and mips16_ext if the user explicitly
9635 requested a small or extended instruction. */
9640 struct mips_cl_insn *ip;
9644 struct mips_opcode *insn;
9647 unsigned int lastregno = 0;
9652 mips16_small = FALSE;
9655 for (s = str; ISLOWER (*s); ++s)
9667 if (s[1] == 't' && s[2] == ' ')
9670 mips16_small = TRUE;
9674 else if (s[1] == 'e' && s[2] == ' ')
9683 insn_error = _("unknown opcode");
9687 if (mips_opts.noautoextend && ! mips16_ext)
9688 mips16_small = TRUE;
9690 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
9692 insn_error = _("unrecognized opcode");
9699 assert (strcmp (insn->name, str) == 0);
9702 ip->insn_opcode = insn->match;
9703 ip->use_extend = FALSE;
9704 imm_expr.X_op = O_absent;
9705 imm_reloc[0] = BFD_RELOC_UNUSED;
9706 imm_reloc[1] = BFD_RELOC_UNUSED;
9707 imm_reloc[2] = BFD_RELOC_UNUSED;
9708 offset_expr.X_op = O_absent;
9709 offset_reloc[0] = BFD_RELOC_UNUSED;
9710 offset_reloc[1] = BFD_RELOC_UNUSED;
9711 offset_reloc[2] = BFD_RELOC_UNUSED;
9712 for (args = insn->args; 1; ++args)
9719 /* In this switch statement we call break if we did not find
9720 a match, continue if we did find a match, or return if we
9729 /* Stuff the immediate value in now, if we can. */
9730 if (imm_expr.X_op == O_constant
9731 && *imm_reloc > BFD_RELOC_UNUSED
9732 && insn->pinfo != INSN_MACRO)
9734 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
9735 imm_expr.X_add_number, TRUE, mips16_small,
9736 mips16_ext, &ip->insn_opcode,
9737 &ip->use_extend, &ip->extend);
9738 imm_expr.X_op = O_absent;
9739 *imm_reloc = BFD_RELOC_UNUSED;
9753 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9756 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9772 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9774 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9801 while (ISDIGIT (*s));
9804 as_bad (_("invalid register number (%d)"), regno);
9810 if (s[1] == 'r' && s[2] == 'a')
9815 else if (s[1] == 'f' && s[2] == 'p')
9820 else if (s[1] == 's' && s[2] == 'p')
9825 else if (s[1] == 'g' && s[2] == 'p')
9830 else if (s[1] == 'a' && s[2] == 't')
9835 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
9840 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
9845 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
9858 if (c == 'v' || c == 'w')
9860 regno = mips16_to_32_reg_map[lastregno];
9874 regno = mips32_to_16_reg_map[regno];
9879 regno = ILLEGAL_REG;
9884 regno = ILLEGAL_REG;
9889 regno = ILLEGAL_REG;
9894 if (regno == AT && ! mips_opts.noat)
9895 as_warn (_("used $at without \".set noat\""));
9902 if (regno == ILLEGAL_REG)
9909 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
9913 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
9916 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
9919 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
9925 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
9928 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9929 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
9939 if (strncmp (s, "$pc", 3) == 0)
9963 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
9965 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9966 and generate the appropriate reloc. If the text
9967 inside %gprel is not a symbol name with an
9968 optional offset, then we generate a normal reloc
9969 and will probably fail later. */
9970 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
9971 if (imm_expr.X_op == O_symbol)
9974 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
9976 ip->use_extend = TRUE;
9983 /* Just pick up a normal expression. */
9984 my_getExpression (&imm_expr, s);
9987 if (imm_expr.X_op == O_register)
9989 /* What we thought was an expression turned out to
9992 if (s[0] == '(' && args[1] == '(')
9994 /* It looks like the expression was omitted
9995 before a register indirection, which means
9996 that the expression is implicitly zero. We
9997 still set up imm_expr, so that we handle
9998 explicit extensions correctly. */
9999 imm_expr.X_op = O_constant;
10000 imm_expr.X_add_number = 0;
10001 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
10008 /* We need to relax this instruction. */
10009 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
10018 /* We use offset_reloc rather than imm_reloc for the PC
10019 relative operands. This lets macros with both
10020 immediate and address operands work correctly. */
10021 my_getExpression (&offset_expr, s);
10023 if (offset_expr.X_op == O_register)
10026 /* We need to relax this instruction. */
10027 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
10031 case '6': /* break code */
10032 my_getExpression (&imm_expr, s);
10033 check_absolute_expr (ip, &imm_expr);
10034 if ((unsigned long) imm_expr.X_add_number > 63)
10036 as_warn (_("Invalid value for `%s' (%lu)"),
10038 (unsigned long) imm_expr.X_add_number);
10039 imm_expr.X_add_number &= 0x3f;
10041 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
10042 imm_expr.X_op = O_absent;
10046 case 'a': /* 26 bit address */
10047 my_getExpression (&offset_expr, s);
10049 *offset_reloc = BFD_RELOC_MIPS16_JMP;
10050 ip->insn_opcode <<= 16;
10053 case 'l': /* register list for entry macro */
10054 case 'L': /* register list for exit macro */
10064 int freg, reg1, reg2;
10066 while (*s == ' ' || *s == ',')
10070 as_bad (_("can't parse register list"));
10082 while (ISDIGIT (*s))
10104 as_bad (_("invalid register list"));
10109 while (ISDIGIT (*s))
10116 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
10118 mask &= ~ (7 << 3);
10121 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
10123 mask &= ~ (7 << 3);
10126 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
10127 mask |= (reg2 - 3) << 3;
10128 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
10129 mask |= (reg2 - 15) << 1;
10130 else if (reg1 == RA && reg2 == RA)
10134 as_bad (_("invalid register list"));
10138 /* The mask is filled in in the opcode table for the
10139 benefit of the disassembler. We remove it before
10140 applying the actual mask. */
10141 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
10142 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
10146 case 'e': /* extend code */
10147 my_getExpression (&imm_expr, s);
10148 check_absolute_expr (ip, &imm_expr);
10149 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
10151 as_warn (_("Invalid value for `%s' (%lu)"),
10153 (unsigned long) imm_expr.X_add_number);
10154 imm_expr.X_add_number &= 0x7ff;
10156 ip->insn_opcode |= imm_expr.X_add_number;
10157 imm_expr.X_op = O_absent;
10167 /* Args don't match. */
10168 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
10169 strcmp (insn->name, insn[1].name) == 0)
10176 insn_error = _("illegal operands");
10182 /* This structure holds information we know about a mips16 immediate
10185 struct mips16_immed_operand
10187 /* The type code used in the argument string in the opcode table. */
10189 /* The number of bits in the short form of the opcode. */
10191 /* The number of bits in the extended form of the opcode. */
10193 /* The amount by which the short form is shifted when it is used;
10194 for example, the sw instruction has a shift count of 2. */
10196 /* The amount by which the short form is shifted when it is stored
10197 into the instruction code. */
10199 /* Non-zero if the short form is unsigned. */
10201 /* Non-zero if the extended form is unsigned. */
10203 /* Non-zero if the value is PC relative. */
10207 /* The mips16 immediate operand types. */
10209 static const struct mips16_immed_operand mips16_immed_operands[] =
10211 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
10212 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
10213 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
10214 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
10215 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
10216 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
10217 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
10218 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
10219 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
10220 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
10221 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
10222 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
10223 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
10224 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
10225 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
10226 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
10227 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
10228 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
10229 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
10230 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
10231 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
10234 #define MIPS16_NUM_IMMED \
10235 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
10237 /* Handle a mips16 instruction with an immediate value. This or's the
10238 small immediate value into *INSN. It sets *USE_EXTEND to indicate
10239 whether an extended value is needed; if one is needed, it sets
10240 *EXTEND to the value. The argument type is TYPE. The value is VAL.
10241 If SMALL is true, an unextended opcode was explicitly requested.
10242 If EXT is true, an extended opcode was explicitly requested. If
10243 WARN is true, warn if EXT does not match reality. */
10246 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
10255 unsigned long *insn;
10256 bfd_boolean *use_extend;
10257 unsigned short *extend;
10259 register const struct mips16_immed_operand *op;
10260 int mintiny, maxtiny;
10261 bfd_boolean needext;
10263 op = mips16_immed_operands;
10264 while (op->type != type)
10267 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
10272 if (type == '<' || type == '>' || type == '[' || type == ']')
10275 maxtiny = 1 << op->nbits;
10280 maxtiny = (1 << op->nbits) - 1;
10285 mintiny = - (1 << (op->nbits - 1));
10286 maxtiny = (1 << (op->nbits - 1)) - 1;
10289 /* Branch offsets have an implicit 0 in the lowest bit. */
10290 if (type == 'p' || type == 'q')
10293 if ((val & ((1 << op->shift) - 1)) != 0
10294 || val < (mintiny << op->shift)
10295 || val > (maxtiny << op->shift))
10300 if (warn && ext && ! needext)
10301 as_warn_where (file, line,
10302 _("extended operand requested but not required"));
10303 if (small && needext)
10304 as_bad_where (file, line, _("invalid unextended operand value"));
10306 if (small || (! ext && ! needext))
10310 *use_extend = FALSE;
10311 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
10312 insnval <<= op->op_shift;
10317 long minext, maxext;
10323 maxext = (1 << op->extbits) - 1;
10327 minext = - (1 << (op->extbits - 1));
10328 maxext = (1 << (op->extbits - 1)) - 1;
10330 if (val < minext || val > maxext)
10331 as_bad_where (file, line,
10332 _("operand value out of range for instruction"));
10334 *use_extend = TRUE;
10335 if (op->extbits == 16)
10337 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
10340 else if (op->extbits == 15)
10342 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
10347 extval = ((val & 0x1f) << 6) | (val & 0x20);
10351 *extend = (unsigned short) extval;
10356 static const struct percent_op_match
10359 bfd_reloc_code_real_type reloc;
10362 {"%lo", BFD_RELOC_LO16},
10364 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
10365 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
10366 {"%call16", BFD_RELOC_MIPS_CALL16},
10367 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
10368 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
10369 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
10370 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
10371 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
10372 {"%got", BFD_RELOC_MIPS_GOT16},
10373 {"%gp_rel", BFD_RELOC_GPREL16},
10374 {"%half", BFD_RELOC_16},
10375 {"%highest", BFD_RELOC_MIPS_HIGHEST},
10376 {"%higher", BFD_RELOC_MIPS_HIGHER},
10377 {"%neg", BFD_RELOC_MIPS_SUB},
10379 {"%hi", BFD_RELOC_HI16_S}
10383 /* Return true if *STR points to a relocation operator. When returning true,
10384 move *STR over the operator and store its relocation code in *RELOC.
10385 Leave both *STR and *RELOC alone when returning false. */
10388 parse_relocation (str, reloc)
10390 bfd_reloc_code_real_type *reloc;
10394 for (i = 0; i < ARRAY_SIZE (percent_op); i++)
10395 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
10397 *str += strlen (percent_op[i].str);
10398 *reloc = percent_op[i].reloc;
10400 /* Check whether the output BFD supports this relocation.
10401 If not, issue an error and fall back on something safe. */
10402 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
10404 as_bad ("relocation %s isn't supported by the current ABI",
10405 percent_op[i].str);
10406 *reloc = BFD_RELOC_LO16;
10414 /* Parse string STR as a 16-bit relocatable operand. Store the
10415 expression in *EP and the relocations in the array starting
10416 at RELOC. Return the number of relocation operators used.
10418 On exit, EXPR_END points to the first character after the expression.
10419 If no relocation operators are used, RELOC[0] is set to BFD_RELOC_LO16. */
10422 my_getSmallExpression (ep, reloc, str)
10424 bfd_reloc_code_real_type *reloc;
10427 bfd_reloc_code_real_type reversed_reloc[3];
10428 size_t reloc_index, i;
10429 int crux_depth, str_depth;
10432 /* Search for the start of the main expression, recoding relocations
10433 in REVERSED_RELOC. End the loop with CRUX pointing to the start
10434 of the main expression and with CRUX_DEPTH containing the number
10435 of open brackets at that point. */
10442 crux_depth = str_depth;
10444 /* Skip over whitespace and brackets, keeping count of the number
10446 while (*str == ' ' || *str == '\t' || *str == '(')
10451 && reloc_index < (HAVE_NEWABI ? 3 : 1)
10452 && parse_relocation (&str, &reversed_reloc[reloc_index]));
10454 my_getExpression (ep, crux);
10457 /* Match every open bracket. */
10458 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
10462 if (crux_depth > 0)
10463 as_bad ("unclosed '('");
10467 if (reloc_index == 0)
10468 reloc[0] = BFD_RELOC_LO16;
10471 prev_reloc_op_frag = frag_now;
10472 for (i = 0; i < reloc_index; i++)
10473 reloc[i] = reversed_reloc[reloc_index - 1 - i];
10476 return reloc_index;
10480 my_getExpression (ep, str)
10487 save_in = input_line_pointer;
10488 input_line_pointer = str;
10490 expr_end = input_line_pointer;
10491 input_line_pointer = save_in;
10493 /* If we are in mips16 mode, and this is an expression based on `.',
10494 then we bump the value of the symbol by 1 since that is how other
10495 text symbols are handled. We don't bother to handle complex
10496 expressions, just `.' plus or minus a constant. */
10497 if (mips_opts.mips16
10498 && ep->X_op == O_symbol
10499 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
10500 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
10501 && symbol_get_frag (ep->X_add_symbol) == frag_now
10502 && symbol_constant_p (ep->X_add_symbol)
10503 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
10504 S_SET_VALUE (ep->X_add_symbol, val + 1);
10507 /* Turn a string in input_line_pointer into a floating point constant
10508 of type TYPE, and store the appropriate bytes in *LITP. The number
10509 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10510 returned, or NULL on OK. */
10513 md_atof (type, litP, sizeP)
10519 LITTLENUM_TYPE words[4];
10535 return _("bad call to md_atof");
10538 t = atof_ieee (input_line_pointer, type, words);
10540 input_line_pointer = t;
10544 if (! target_big_endian)
10546 for (i = prec - 1; i >= 0; i--)
10548 md_number_to_chars (litP, (valueT) words[i], 2);
10554 for (i = 0; i < prec; i++)
10556 md_number_to_chars (litP, (valueT) words[i], 2);
10565 md_number_to_chars (buf, val, n)
10570 if (target_big_endian)
10571 number_to_chars_bigendian (buf, val, n);
10573 number_to_chars_littleendian (buf, val, n);
10577 static int support_64bit_objects(void)
10579 const char **list, **l;
10582 list = bfd_target_list ();
10583 for (l = list; *l != NULL; l++)
10585 /* This is traditional mips */
10586 if (strcmp (*l, "elf64-tradbigmips") == 0
10587 || strcmp (*l, "elf64-tradlittlemips") == 0)
10589 if (strcmp (*l, "elf64-bigmips") == 0
10590 || strcmp (*l, "elf64-littlemips") == 0)
10593 yes = (*l != NULL);
10597 #endif /* OBJ_ELF */
10599 const char *md_shortopts = "nO::g::G:";
10601 struct option md_longopts[] =
10603 /* Options which specify architecture. */
10604 #define OPTION_ARCH_BASE (OPTION_MD_BASE)
10605 #define OPTION_MARCH (OPTION_ARCH_BASE + 0)
10606 {"march", required_argument, NULL, OPTION_MARCH},
10607 #define OPTION_MTUNE (OPTION_ARCH_BASE + 1)
10608 {"mtune", required_argument, NULL, OPTION_MTUNE},
10609 #define OPTION_MIPS1 (OPTION_ARCH_BASE + 2)
10610 {"mips0", no_argument, NULL, OPTION_MIPS1},
10611 {"mips1", no_argument, NULL, OPTION_MIPS1},
10612 #define OPTION_MIPS2 (OPTION_ARCH_BASE + 3)
10613 {"mips2", no_argument, NULL, OPTION_MIPS2},
10614 #define OPTION_MIPS3 (OPTION_ARCH_BASE + 4)
10615 {"mips3", no_argument, NULL, OPTION_MIPS3},
10616 #define OPTION_MIPS4 (OPTION_ARCH_BASE + 5)
10617 {"mips4", no_argument, NULL, OPTION_MIPS4},
10618 #define OPTION_MIPS5 (OPTION_ARCH_BASE + 6)
10619 {"mips5", no_argument, NULL, OPTION_MIPS5},
10620 #define OPTION_MIPS32 (OPTION_ARCH_BASE + 7)
10621 {"mips32", no_argument, NULL, OPTION_MIPS32},
10622 #define OPTION_MIPS64 (OPTION_ARCH_BASE + 8)
10623 {"mips64", no_argument, NULL, OPTION_MIPS64},
10624 #define OPTION_MIPS32R2 (OPTION_ARCH_BASE + 9)
10625 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
10627 /* Options which specify Application Specific Extensions (ASEs). */
10628 #define OPTION_ASE_BASE (OPTION_ARCH_BASE + 10)
10629 #define OPTION_MIPS16 (OPTION_ASE_BASE + 0)
10630 {"mips16", no_argument, NULL, OPTION_MIPS16},
10631 #define OPTION_NO_MIPS16 (OPTION_ASE_BASE + 1)
10632 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
10633 #define OPTION_MIPS3D (OPTION_ASE_BASE + 2)
10634 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
10635 #define OPTION_NO_MIPS3D (OPTION_ASE_BASE + 3)
10636 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
10637 #define OPTION_MDMX (OPTION_ASE_BASE + 4)
10638 {"mdmx", no_argument, NULL, OPTION_MDMX},
10639 #define OPTION_NO_MDMX (OPTION_ASE_BASE + 5)
10640 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
10642 /* Old-style architecture options. Don't add more of these. */
10643 #define OPTION_COMPAT_ARCH_BASE (OPTION_ASE_BASE + 6)
10644 #define OPTION_M4650 (OPTION_COMPAT_ARCH_BASE + 0)
10645 {"m4650", no_argument, NULL, OPTION_M4650},
10646 #define OPTION_NO_M4650 (OPTION_COMPAT_ARCH_BASE + 1)
10647 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
10648 #define OPTION_M4010 (OPTION_COMPAT_ARCH_BASE + 2)
10649 {"m4010", no_argument, NULL, OPTION_M4010},
10650 #define OPTION_NO_M4010 (OPTION_COMPAT_ARCH_BASE + 3)
10651 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
10652 #define OPTION_M4100 (OPTION_COMPAT_ARCH_BASE + 4)
10653 {"m4100", no_argument, NULL, OPTION_M4100},
10654 #define OPTION_NO_M4100 (OPTION_COMPAT_ARCH_BASE + 5)
10655 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
10656 #define OPTION_M3900 (OPTION_COMPAT_ARCH_BASE + 6)
10657 {"m3900", no_argument, NULL, OPTION_M3900},
10658 #define OPTION_NO_M3900 (OPTION_COMPAT_ARCH_BASE + 7)
10659 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
10661 /* Options which enable bug fixes. */
10662 #define OPTION_FIX_BASE (OPTION_COMPAT_ARCH_BASE + 8)
10663 #define OPTION_M7000_HILO_FIX (OPTION_FIX_BASE + 0)
10664 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
10665 #define OPTION_MNO_7000_HILO_FIX (OPTION_FIX_BASE + 1)
10666 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10667 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10668 #define OPTION_FIX_VR4122 (OPTION_FIX_BASE + 2)
10669 #define OPTION_NO_FIX_VR4122 (OPTION_FIX_BASE + 3)
10670 {"mfix-vr4122-bugs", no_argument, NULL, OPTION_FIX_VR4122},
10671 {"no-mfix-vr4122-bugs", no_argument, NULL, OPTION_NO_FIX_VR4122},
10673 /* Miscellaneous options. */
10674 #define OPTION_MISC_BASE (OPTION_FIX_BASE + 4)
10675 #define OPTION_MEMBEDDED_PIC (OPTION_MISC_BASE + 0)
10676 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
10677 #define OPTION_TRAP (OPTION_MISC_BASE + 1)
10678 {"trap", no_argument, NULL, OPTION_TRAP},
10679 {"no-break", no_argument, NULL, OPTION_TRAP},
10680 #define OPTION_BREAK (OPTION_MISC_BASE + 2)
10681 {"break", no_argument, NULL, OPTION_BREAK},
10682 {"no-trap", no_argument, NULL, OPTION_BREAK},
10683 #define OPTION_EB (OPTION_MISC_BASE + 3)
10684 {"EB", no_argument, NULL, OPTION_EB},
10685 #define OPTION_EL (OPTION_MISC_BASE + 4)
10686 {"EL", no_argument, NULL, OPTION_EL},
10687 #define OPTION_FP32 (OPTION_MISC_BASE + 5)
10688 {"mfp32", no_argument, NULL, OPTION_FP32},
10689 #define OPTION_GP32 (OPTION_MISC_BASE + 6)
10690 {"mgp32", no_argument, NULL, OPTION_GP32},
10691 #define OPTION_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 7)
10692 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
10693 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 8)
10694 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
10695 #define OPTION_FP64 (OPTION_MISC_BASE + 9)
10696 {"mfp64", no_argument, NULL, OPTION_FP64},
10697 #define OPTION_GP64 (OPTION_MISC_BASE + 10)
10698 {"mgp64", no_argument, NULL, OPTION_GP64},
10699 #define OPTION_RELAX_BRANCH (OPTION_MISC_BASE + 11)
10700 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 12)
10701 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
10702 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
10704 /* ELF-specific options. */
10706 #define OPTION_ELF_BASE (OPTION_MISC_BASE + 13)
10707 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10708 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
10709 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
10710 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10711 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
10712 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10713 {"xgot", no_argument, NULL, OPTION_XGOT},
10714 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10715 {"mabi", required_argument, NULL, OPTION_MABI},
10716 #define OPTION_32 (OPTION_ELF_BASE + 4)
10717 {"32", no_argument, NULL, OPTION_32},
10718 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10719 {"n32", no_argument, NULL, OPTION_N32},
10720 #define OPTION_64 (OPTION_ELF_BASE + 6)
10721 {"64", no_argument, NULL, OPTION_64},
10722 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10723 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
10724 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10725 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
10726 #endif /* OBJ_ELF */
10728 {NULL, no_argument, NULL, 0}
10730 size_t md_longopts_size = sizeof (md_longopts);
10732 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10733 NEW_VALUE. Warn if another value was already specified. Note:
10734 we have to defer parsing the -march and -mtune arguments in order
10735 to handle 'from-abi' correctly, since the ABI might be specified
10736 in a later argument. */
10739 mips_set_option_string (string_ptr, new_value)
10740 const char **string_ptr, *new_value;
10742 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
10743 as_warn (_("A different %s was already specified, is now %s"),
10744 string_ptr == &mips_arch_string ? "-march" : "-mtune",
10747 *string_ptr = new_value;
10751 md_parse_option (c, arg)
10757 case OPTION_CONSTRUCT_FLOATS:
10758 mips_disable_float_construction = 0;
10761 case OPTION_NO_CONSTRUCT_FLOATS:
10762 mips_disable_float_construction = 1;
10774 target_big_endian = 1;
10778 target_big_endian = 0;
10786 if (arg && arg[1] == '0')
10796 mips_debug = atoi (arg);
10797 /* When the MIPS assembler sees -g or -g2, it does not do
10798 optimizations which limit full symbolic debugging. We take
10799 that to be equivalent to -O0. */
10800 if (mips_debug == 2)
10805 file_mips_isa = ISA_MIPS1;
10809 file_mips_isa = ISA_MIPS2;
10813 file_mips_isa = ISA_MIPS3;
10817 file_mips_isa = ISA_MIPS4;
10821 file_mips_isa = ISA_MIPS5;
10824 case OPTION_MIPS32:
10825 file_mips_isa = ISA_MIPS32;
10828 case OPTION_MIPS32R2:
10829 file_mips_isa = ISA_MIPS32R2;
10832 case OPTION_MIPS64:
10833 file_mips_isa = ISA_MIPS64;
10837 mips_set_option_string (&mips_tune_string, arg);
10841 mips_set_option_string (&mips_arch_string, arg);
10845 mips_set_option_string (&mips_arch_string, "4650");
10846 mips_set_option_string (&mips_tune_string, "4650");
10849 case OPTION_NO_M4650:
10853 mips_set_option_string (&mips_arch_string, "4010");
10854 mips_set_option_string (&mips_tune_string, "4010");
10857 case OPTION_NO_M4010:
10861 mips_set_option_string (&mips_arch_string, "4100");
10862 mips_set_option_string (&mips_tune_string, "4100");
10865 case OPTION_NO_M4100:
10869 mips_set_option_string (&mips_arch_string, "3900");
10870 mips_set_option_string (&mips_tune_string, "3900");
10873 case OPTION_NO_M3900:
10877 mips_opts.ase_mdmx = 1;
10880 case OPTION_NO_MDMX:
10881 mips_opts.ase_mdmx = 0;
10884 case OPTION_MIPS16:
10885 mips_opts.mips16 = 1;
10886 mips_no_prev_insn (FALSE);
10889 case OPTION_NO_MIPS16:
10890 mips_opts.mips16 = 0;
10891 mips_no_prev_insn (FALSE);
10894 case OPTION_MIPS3D:
10895 mips_opts.ase_mips3d = 1;
10898 case OPTION_NO_MIPS3D:
10899 mips_opts.ase_mips3d = 0;
10902 case OPTION_MEMBEDDED_PIC:
10903 mips_pic = EMBEDDED_PIC;
10904 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
10906 as_bad (_("-G may not be used with embedded PIC code"));
10909 g_switch_value = 0x7fffffff;
10912 case OPTION_FIX_VR4122:
10913 mips_fix_4122_bugs = 1;
10916 case OPTION_NO_FIX_VR4122:
10917 mips_fix_4122_bugs = 0;
10920 case OPTION_RELAX_BRANCH:
10921 mips_relax_branch = 1;
10924 case OPTION_NO_RELAX_BRANCH:
10925 mips_relax_branch = 0;
10929 /* When generating ELF code, we permit -KPIC and -call_shared to
10930 select SVR4_PIC, and -non_shared to select no PIC. This is
10931 intended to be compatible with Irix 5. */
10932 case OPTION_CALL_SHARED:
10933 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10935 as_bad (_("-call_shared is supported only for ELF format"));
10938 mips_pic = SVR4_PIC;
10939 mips_abicalls = TRUE;
10940 if (g_switch_seen && g_switch_value != 0)
10942 as_bad (_("-G may not be used with SVR4 PIC code"));
10945 g_switch_value = 0;
10948 case OPTION_NON_SHARED:
10949 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10951 as_bad (_("-non_shared is supported only for ELF format"));
10955 mips_abicalls = FALSE;
10958 /* The -xgot option tells the assembler to use 32 offsets when
10959 accessing the got in SVR4_PIC mode. It is for Irix
10964 #endif /* OBJ_ELF */
10967 if (! USE_GLOBAL_POINTER_OPT)
10969 as_bad (_("-G is not supported for this configuration"));
10972 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10974 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10978 g_switch_value = atoi (arg);
10983 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10986 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10988 as_bad (_("-32 is supported for ELF format only"));
10991 mips_abi = O32_ABI;
10995 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10997 as_bad (_("-n32 is supported for ELF format only"));
11000 mips_abi = N32_ABI;
11004 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11006 as_bad (_("-64 is supported for ELF format only"));
11009 mips_abi = N64_ABI;
11010 if (! support_64bit_objects())
11011 as_fatal (_("No compiled in support for 64 bit object file format"));
11013 #endif /* OBJ_ELF */
11016 file_mips_gp32 = 1;
11020 file_mips_gp32 = 0;
11024 file_mips_fp32 = 1;
11028 file_mips_fp32 = 0;
11033 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11035 as_bad (_("-mabi is supported for ELF format only"));
11038 if (strcmp (arg, "32") == 0)
11039 mips_abi = O32_ABI;
11040 else if (strcmp (arg, "o64") == 0)
11041 mips_abi = O64_ABI;
11042 else if (strcmp (arg, "n32") == 0)
11043 mips_abi = N32_ABI;
11044 else if (strcmp (arg, "64") == 0)
11046 mips_abi = N64_ABI;
11047 if (! support_64bit_objects())
11048 as_fatal (_("No compiled in support for 64 bit object file "
11051 else if (strcmp (arg, "eabi") == 0)
11052 mips_abi = EABI_ABI;
11055 as_fatal (_("invalid abi -mabi=%s"), arg);
11059 #endif /* OBJ_ELF */
11061 case OPTION_M7000_HILO_FIX:
11062 mips_7000_hilo_fix = TRUE;
11065 case OPTION_MNO_7000_HILO_FIX:
11066 mips_7000_hilo_fix = FALSE;
11070 case OPTION_MDEBUG:
11071 mips_flag_mdebug = TRUE;
11074 case OPTION_NO_MDEBUG:
11075 mips_flag_mdebug = FALSE;
11077 #endif /* OBJ_ELF */
11086 /* Set up globals to generate code for the ISA or processor
11087 described by INFO. */
11090 mips_set_architecture (info)
11091 const struct mips_cpu_info *info;
11095 mips_arch_info = info;
11096 mips_arch = info->cpu;
11097 mips_opts.isa = info->isa;
11102 /* Likewise for tuning. */
11105 mips_set_tune (info)
11106 const struct mips_cpu_info *info;
11110 mips_tune_info = info;
11111 mips_tune = info->cpu;
11117 mips_after_parse_args ()
11119 /* GP relative stuff not working for PE */
11120 if (strncmp (TARGET_OS, "pe", 2) == 0
11121 && g_switch_value != 0)
11124 as_bad (_("-G not supported in this configuration."));
11125 g_switch_value = 0;
11128 if (mips_abi == NO_ABI)
11129 mips_abi = MIPS_DEFAULT_ABI;
11131 /* The following code determines the architecture and register size.
11132 Similar code was added to GCC 3.3 (see override_options() in
11133 config/mips/mips.c). The GAS and GCC code should be kept in sync
11134 as much as possible. */
11136 if (mips_arch_string != 0)
11137 mips_set_architecture (mips_parse_cpu ("-march", mips_arch_string));
11139 if (mips_tune_string != 0)
11140 mips_set_tune (mips_parse_cpu ("-mtune", mips_tune_string));
11142 if (file_mips_isa != ISA_UNKNOWN)
11144 /* Handle -mipsN. At this point, file_mips_isa contains the
11145 ISA level specified by -mipsN, while mips_opts.isa contains
11146 the -march selection (if any). */
11147 if (mips_arch_info != 0)
11149 /* -march takes precedence over -mipsN, since it is more descriptive.
11150 There's no harm in specifying both as long as the ISA levels
11152 if (file_mips_isa != mips_opts.isa)
11153 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
11154 mips_cpu_info_from_isa (file_mips_isa)->name,
11155 mips_cpu_info_from_isa (mips_opts.isa)->name);
11158 mips_set_architecture (mips_cpu_info_from_isa (file_mips_isa));
11161 if (mips_arch_info == 0)
11162 mips_set_architecture (mips_parse_cpu ("default CPU",
11163 MIPS_CPU_STRING_DEFAULT));
11165 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (mips_opts.isa))
11166 as_bad ("-march=%s is not compatible with the selected ABI",
11167 mips_arch_info->name);
11169 /* Optimize for mips_arch, unless -mtune selects a different processor. */
11170 if (mips_tune_info == 0)
11171 mips_set_tune (mips_arch_info);
11173 if (file_mips_gp32 >= 0)
11175 /* The user specified the size of the integer registers. Make sure
11176 it agrees with the ABI and ISA. */
11177 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
11178 as_bad (_("-mgp64 used with a 32-bit processor"));
11179 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
11180 as_bad (_("-mgp32 used with a 64-bit ABI"));
11181 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
11182 as_bad (_("-mgp64 used with a 32-bit ABI"));
11186 /* Infer the integer register size from the ABI and processor.
11187 Restrict ourselves to 32-bit registers if that's all the
11188 processor has, or if the ABI cannot handle 64-bit registers. */
11189 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
11190 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
11193 /* ??? GAS treats single-float processors as though they had 64-bit
11194 float registers (although it complains when double-precision
11195 instructions are used). As things stand, saying they have 32-bit
11196 registers would lead to spurious "register must be even" messages.
11197 So here we assume float registers are always the same size as
11198 integer ones, unless the user says otherwise. */
11199 if (file_mips_fp32 < 0)
11200 file_mips_fp32 = file_mips_gp32;
11202 /* End of GCC-shared inference code. */
11204 /* ??? When do we want this flag to be set? Who uses it? */
11205 if (file_mips_gp32 == 1
11206 && mips_abi == NO_ABI
11207 && ISA_HAS_64BIT_REGS (mips_opts.isa))
11208 mips_32bitmode = 1;
11210 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
11211 as_bad (_("trap exception not supported at ISA 1"));
11213 /* If the selected architecture includes support for ASEs, enable
11214 generation of code for them. */
11215 if (mips_opts.mips16 == -1)
11216 mips_opts.mips16 = (CPU_HAS_MIPS16 (mips_arch)) ? 1 : 0;
11217 if (mips_opts.ase_mips3d == -1)
11218 mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (mips_arch)) ? 1 : 0;
11219 if (mips_opts.ase_mdmx == -1)
11220 mips_opts.ase_mdmx = (CPU_HAS_MDMX (mips_arch)) ? 1 : 0;
11222 file_mips_isa = mips_opts.isa;
11223 file_ase_mips16 = mips_opts.mips16;
11224 file_ase_mips3d = mips_opts.ase_mips3d;
11225 file_ase_mdmx = mips_opts.ase_mdmx;
11226 mips_opts.gp32 = file_mips_gp32;
11227 mips_opts.fp32 = file_mips_fp32;
11229 if (mips_flag_mdebug < 0)
11231 #ifdef OBJ_MAYBE_ECOFF
11232 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
11233 mips_flag_mdebug = 1;
11235 #endif /* OBJ_MAYBE_ECOFF */
11236 mips_flag_mdebug = 0;
11241 mips_init_after_args ()
11243 /* initialize opcodes */
11244 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
11245 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
11249 md_pcrel_from (fixP)
11252 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
11253 switch (fixP->fx_r_type)
11255 case BFD_RELOC_16_PCREL_S2:
11256 case BFD_RELOC_MIPS_JMP:
11257 /* Return the address of the delay slot. */
11264 /* This is called before the symbol table is processed. In order to
11265 work with gcc when using mips-tfile, we must keep all local labels.
11266 However, in other cases, we want to discard them. If we were
11267 called with -g, but we didn't see any debugging information, it may
11268 mean that gcc is smuggling debugging information through to
11269 mips-tfile, in which case we must generate all local labels. */
11272 mips_frob_file_before_adjust ()
11274 #ifndef NO_ECOFF_DEBUGGING
11275 if (ECOFF_DEBUGGING
11277 && ! ecoff_debugging_seen)
11278 flag_keep_locals = 1;
11282 /* Sort any unmatched HI16_S relocs so that they immediately precede
11283 the corresponding LO reloc. This is called before md_apply_fix3 and
11284 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
11285 explicit use of the %hi modifier. */
11290 struct mips_hi_fixup *l;
11292 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
11294 segment_info_type *seginfo;
11297 assert (reloc_needs_lo_p (l->fixp->fx_r_type));
11299 /* If a GOT16 relocation turns out to be against a global symbol,
11300 there isn't supposed to be a matching LO. */
11301 if (l->fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
11302 && !pic_need_relax (l->fixp->fx_addsy, l->seg))
11305 /* Check quickly whether the next fixup happens to be a matching %lo. */
11306 if (fixup_has_matching_lo_p (l->fixp))
11309 /* Look through the fixups for this segment for a matching %lo.
11310 When we find one, move the %hi just in front of it. We do
11311 this in two passes. In the first pass, we try to find a
11312 unique %lo. In the second pass, we permit multiple %hi
11313 relocs for a single %lo (this is a GNU extension). */
11314 seginfo = seg_info (l->seg);
11315 for (pass = 0; pass < 2; pass++)
11320 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
11322 /* Check whether this is a %lo fixup which matches l->fixp. */
11323 if (f->fx_r_type == BFD_RELOC_LO16
11324 && f->fx_addsy == l->fixp->fx_addsy
11325 && f->fx_offset == l->fixp->fx_offset
11328 || !reloc_needs_lo_p (prev->fx_r_type)
11329 || !fixup_has_matching_lo_p (prev)))
11333 /* Move l->fixp before f. */
11334 for (pf = &seginfo->fix_root;
11336 pf = &(*pf)->fx_next)
11337 assert (*pf != NULL);
11339 *pf = l->fixp->fx_next;
11341 l->fixp->fx_next = f;
11343 seginfo->fix_root = l->fixp;
11345 prev->fx_next = l->fixp;
11356 #if 0 /* GCC code motion plus incomplete dead code elimination
11357 can leave a %hi without a %lo. */
11359 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
11360 _("Unmatched %%hi reloc"));
11366 /* When generating embedded PIC code we need to use a special
11367 relocation to represent the difference of two symbols in the .text
11368 section (switch tables use a difference of this sort). See
11369 include/coff/mips.h for details. This macro checks whether this
11370 fixup requires the special reloc. */
11371 #define SWITCH_TABLE(fixp) \
11372 ((fixp)->fx_r_type == BFD_RELOC_32 \
11373 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
11374 && (fixp)->fx_addsy != NULL \
11375 && (fixp)->fx_subsy != NULL \
11376 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
11377 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
11379 /* When generating embedded PIC code we must keep all PC relative
11380 relocations, in case the linker has to relax a call. We also need
11381 to keep relocations for switch table entries.
11383 We may have combined relocations without symbols in the N32/N64 ABI.
11384 We have to prevent gas from dropping them. */
11387 mips_force_relocation (fixp)
11390 if (generic_force_reloc (fixp))
11394 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
11395 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
11396 || fixp->fx_r_type == BFD_RELOC_HI16_S
11397 || fixp->fx_r_type == BFD_RELOC_LO16))
11400 return (mips_pic == EMBEDDED_PIC
11402 || SWITCH_TABLE (fixp)
11403 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
11404 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
11407 /* This hook is called before a fix is simplified. We don't really
11408 decide whether to skip a fix here. Rather, we turn global symbols
11409 used as branch targets into local symbols, such that they undergo
11410 simplification. We can only do this if the symbol is defined and
11411 it is in the same section as the branch. If this doesn't hold, we
11412 emit a better error message than just saying the relocation is not
11413 valid for the selected object format.
11415 FIXP is the fix-up we're going to try to simplify, SEG is the
11416 segment in which the fix up occurs. The return value should be
11417 non-zero to indicate the fix-up is valid for further
11418 simplifications. */
11421 mips_validate_fix (fixP, seg)
11425 /* There's a lot of discussion on whether it should be possible to
11426 use R_MIPS_PC16 to represent branch relocations. The outcome
11427 seems to be that it can, but gas/bfd are very broken in creating
11428 RELA relocations for this, so for now we only accept branches to
11429 symbols in the same section. Anything else is of dubious value,
11430 since there's no guarantee that at link time the symbol would be
11431 in range. Even for branches to local symbols this is arguably
11432 wrong, since it we assume the symbol is not going to be
11433 overridden, which should be possible per ELF library semantics,
11434 but then, there isn't a dynamic relocation that could be used to
11435 this effect, and the target would likely be out of range as well.
11437 Unfortunately, it seems that there is too much code out there
11438 that relies on branches to symbols that are global to be resolved
11439 as if they were local, like the IRIX tools do, so we do it as
11440 well, but with a warning so that people are reminded to fix their
11441 code. If we ever get back to using R_MIPS_PC16 for branch
11442 targets, this entire block should go away (and probably the
11443 whole function). */
11445 if (fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
11446 && (((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
11447 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11448 && mips_pic != EMBEDDED_PIC)
11449 || bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16_PCREL_S2) == NULL)
11452 if (! S_IS_DEFINED (fixP->fx_addsy))
11454 as_bad_where (fixP->fx_file, fixP->fx_line,
11455 _("Cannot branch to undefined symbol."));
11456 /* Avoid any further errors about this fixup. */
11459 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
11461 as_bad_where (fixP->fx_file, fixP->fx_line,
11462 _("Cannot branch to symbol in another section."));
11465 else if (S_IS_EXTERNAL (fixP->fx_addsy))
11467 symbolS *sym = fixP->fx_addsy;
11469 as_warn_where (fixP->fx_file, fixP->fx_line,
11470 _("Pretending global symbol used as branch target is local."));
11472 fixP->fx_addsy = symbol_create (S_GET_NAME (sym),
11473 S_GET_SEGMENT (sym),
11475 symbol_get_frag (sym));
11476 copy_symbol_attributes (fixP->fx_addsy, sym);
11477 S_CLEAR_EXTERNAL (fixP->fx_addsy);
11478 assert (symbol_resolved_p (sym));
11479 symbol_mark_resolved (fixP->fx_addsy);
11488 mips_need_elf_addend_fixup (fixP)
11491 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
11493 if (mips_pic == EMBEDDED_PIC
11494 && S_IS_WEAK (fixP->fx_addsy))
11496 if (mips_pic != EMBEDDED_PIC
11497 && (S_IS_WEAK (fixP->fx_addsy)
11498 || S_IS_EXTERNAL (fixP->fx_addsy))
11499 && !S_IS_COMMON (fixP->fx_addsy))
11501 if (((bfd_get_section_flags (stdoutput,
11502 S_GET_SEGMENT (fixP->fx_addsy))
11503 & (SEC_LINK_ONCE | SEC_MERGE)) != 0)
11504 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
11506 sizeof (".gnu.linkonce") - 1))
11512 /* Apply a fixup to the object file. */
11515 md_apply_fix3 (fixP, valP, seg)
11518 segT seg ATTRIBUTE_UNUSED;
11522 static int previous_fx_r_type = 0;
11523 reloc_howto_type *howto;
11525 /* We ignore generic BFD relocations we don't know about. */
11526 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
11530 assert (fixP->fx_size == 4
11531 || fixP->fx_r_type == BFD_RELOC_16
11532 || fixP->fx_r_type == BFD_RELOC_64
11533 || fixP->fx_r_type == BFD_RELOC_CTOR
11534 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11535 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11536 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
11538 buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
11540 /* If we aren't adjusting this fixup to be against the section
11541 symbol, we need to adjust the value. */
11543 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
11545 if (mips_need_elf_addend_fixup (fixP)
11546 && howto->partial_inplace
11547 && fixP->fx_r_type != BFD_RELOC_GPREL16
11548 && fixP->fx_r_type != BFD_RELOC_GPREL32
11549 && fixP->fx_r_type != BFD_RELOC_MIPS16_GPREL)
11551 /* In this case, the bfd_install_relocation routine will
11552 incorrectly add the symbol value back in. We just want
11553 the addend to appear in the object file.
11555 The condition above used to include
11556 "&& (! fixP->fx_pcrel || howto->pcrel_offset)".
11558 However, howto can't be trusted here, because we
11559 might change the reloc type in tc_gen_reloc. We can
11560 check howto->partial_inplace because that conversion
11561 happens to preserve howto->partial_inplace; but it
11562 does not preserve howto->pcrel_offset. I've just
11563 eliminated the check, because all MIPS PC-relative
11564 relocations are marked howto->pcrel_offset.
11566 howto->pcrel_offset was originally added for
11567 R_MIPS_PC16, which is generated for code like
11576 *valP -= S_GET_VALUE (fixP->fx_addsy);
11579 /* This code was generated using trial and error and so is
11580 fragile and not trustworthy. If you change it, you should
11581 rerun the elf-rel, elf-rel2, and empic testcases and ensure
11582 they still pass. */
11583 if (fixP->fx_pcrel)
11585 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11587 /* BFD's REL handling, for MIPS, is _very_ weird.
11588 This gives the right results, but it can't possibly
11589 be the way things are supposed to work. */
11590 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11595 /* We are not done if this is a composite relocation to set up gp. */
11596 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel
11597 && !(fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11598 || (fixP->fx_r_type == BFD_RELOC_64
11599 && (previous_fx_r_type == BFD_RELOC_GPREL32
11600 || previous_fx_r_type == BFD_RELOC_GPREL16))
11601 || (previous_fx_r_type == BFD_RELOC_MIPS_SUB
11602 && (fixP->fx_r_type == BFD_RELOC_HI16_S
11603 || fixP->fx_r_type == BFD_RELOC_LO16))))
11605 previous_fx_r_type = fixP->fx_r_type;
11607 switch (fixP->fx_r_type)
11609 case BFD_RELOC_MIPS_JMP:
11610 case BFD_RELOC_MIPS_SHIFT5:
11611 case BFD_RELOC_MIPS_SHIFT6:
11612 case BFD_RELOC_MIPS_GOT_DISP:
11613 case BFD_RELOC_MIPS_GOT_PAGE:
11614 case BFD_RELOC_MIPS_GOT_OFST:
11615 case BFD_RELOC_MIPS_SUB:
11616 case BFD_RELOC_MIPS_INSERT_A:
11617 case BFD_RELOC_MIPS_INSERT_B:
11618 case BFD_RELOC_MIPS_DELETE:
11619 case BFD_RELOC_MIPS_HIGHEST:
11620 case BFD_RELOC_MIPS_HIGHER:
11621 case BFD_RELOC_MIPS_SCN_DISP:
11622 case BFD_RELOC_MIPS_REL16:
11623 case BFD_RELOC_MIPS_RELGOT:
11624 case BFD_RELOC_MIPS_JALR:
11625 case BFD_RELOC_HI16:
11626 case BFD_RELOC_HI16_S:
11627 case BFD_RELOC_GPREL16:
11628 case BFD_RELOC_MIPS_LITERAL:
11629 case BFD_RELOC_MIPS_CALL16:
11630 case BFD_RELOC_MIPS_GOT16:
11631 case BFD_RELOC_GPREL32:
11632 case BFD_RELOC_MIPS_GOT_HI16:
11633 case BFD_RELOC_MIPS_GOT_LO16:
11634 case BFD_RELOC_MIPS_CALL_HI16:
11635 case BFD_RELOC_MIPS_CALL_LO16:
11636 case BFD_RELOC_MIPS16_GPREL:
11637 if (fixP->fx_pcrel)
11638 as_bad_where (fixP->fx_file, fixP->fx_line,
11639 _("Invalid PC relative reloc"));
11640 /* Nothing needed to do. The value comes from the reloc entry */
11643 case BFD_RELOC_MIPS16_JMP:
11644 /* We currently always generate a reloc against a symbol, which
11645 means that we don't want an addend even if the symbol is
11650 case BFD_RELOC_PCREL_HI16_S:
11651 /* The addend for this is tricky if it is internal, so we just
11652 do everything here rather than in bfd_install_relocation. */
11653 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && !fixP->fx_done)
11656 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11658 /* For an external symbol adjust by the address to make it
11659 pcrel_offset. We use the address of the RELLO reloc
11660 which follows this one. */
11661 *valP += (fixP->fx_next->fx_frag->fr_address
11662 + fixP->fx_next->fx_where);
11664 *valP = ((*valP + 0x8000) >> 16) & 0xffff;
11665 if (target_big_endian)
11667 md_number_to_chars ((char *) buf, *valP, 2);
11670 case BFD_RELOC_PCREL_LO16:
11671 /* The addend for this is tricky if it is internal, so we just
11672 do everything here rather than in bfd_install_relocation. */
11673 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && !fixP->fx_done)
11676 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11677 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11678 if (target_big_endian)
11680 md_number_to_chars ((char *) buf, *valP, 2);
11684 /* This is handled like BFD_RELOC_32, but we output a sign
11685 extended value if we are only 32 bits. */
11687 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11689 if (8 <= sizeof (valueT))
11690 md_number_to_chars (buf, *valP, 8);
11695 if ((*valP & 0x80000000) != 0)
11699 md_number_to_chars ((char *)(buf + target_big_endian ? 4 : 0),
11701 md_number_to_chars ((char *)(buf + target_big_endian ? 0 : 4),
11707 case BFD_RELOC_RVA:
11709 /* If we are deleting this reloc entry, we must fill in the
11710 value now. This can happen if we have a .word which is not
11711 resolved when it appears but is later defined. We also need
11712 to fill in the value if this is an embedded PIC switch table
11715 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11716 md_number_to_chars (buf, *valP, 4);
11720 /* If we are deleting this reloc entry, we must fill in the
11722 assert (fixP->fx_size == 2);
11724 md_number_to_chars (buf, *valP, 2);
11727 case BFD_RELOC_LO16:
11728 /* When handling an embedded PIC switch statement, we can wind
11729 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11732 if (*valP + 0x8000 > 0xffff)
11733 as_bad_where (fixP->fx_file, fixP->fx_line,
11734 _("relocation overflow"));
11735 if (target_big_endian)
11737 md_number_to_chars ((char *) buf, *valP, 2);
11741 case BFD_RELOC_16_PCREL_S2:
11742 if ((*valP & 0x3) != 0)
11743 as_bad_where (fixP->fx_file, fixP->fx_line,
11744 _("Branch to odd address (%lx)"), (long) *valP);
11747 * We need to save the bits in the instruction since fixup_segment()
11748 * might be deleting the relocation entry (i.e., a branch within
11749 * the current segment).
11751 if (! fixP->fx_done)
11754 /* update old instruction data */
11755 if (target_big_endian)
11756 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
11758 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
11760 if (*valP + 0x20000 <= 0x3ffff)
11762 insn |= (*valP >> 2) & 0xffff;
11763 md_number_to_chars ((char *) buf, (valueT) insn, 4);
11765 else if (mips_pic == NO_PIC
11767 && fixP->fx_frag->fr_address >= text_section->vma
11768 && (fixP->fx_frag->fr_address
11769 < text_section->vma + text_section->_raw_size)
11770 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
11771 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
11772 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
11774 /* The branch offset is too large. If this is an
11775 unconditional branch, and we are not generating PIC code,
11776 we can convert it to an absolute jump instruction. */
11777 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
11778 insn = 0x0c000000; /* jal */
11780 insn = 0x08000000; /* j */
11781 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
11783 fixP->fx_addsy = section_symbol (text_section);
11784 *valP += md_pcrel_from (fixP);
11785 md_number_to_chars ((char *) buf, (valueT) insn, 4);
11789 /* If we got here, we have branch-relaxation disabled,
11790 and there's nothing we can do to fix this instruction
11791 without turning it into a longer sequence. */
11792 as_bad_where (fixP->fx_file, fixP->fx_line,
11793 _("Branch out of range"));
11797 case BFD_RELOC_VTABLE_INHERIT:
11800 && !S_IS_DEFINED (fixP->fx_addsy)
11801 && !S_IS_WEAK (fixP->fx_addsy))
11802 S_SET_WEAK (fixP->fx_addsy);
11805 case BFD_RELOC_VTABLE_ENTRY:
11813 /* Remember value for tc_gen_reloc. */
11814 fixP->fx_addnumber = *valP;
11822 const struct mips_opcode *p;
11823 int treg, sreg, dreg, shamt;
11828 for (i = 0; i < NUMOPCODES; ++i)
11830 p = &mips_opcodes[i];
11831 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
11833 printf ("%08lx %s\t", oc, p->name);
11834 treg = (oc >> 16) & 0x1f;
11835 sreg = (oc >> 21) & 0x1f;
11836 dreg = (oc >> 11) & 0x1f;
11837 shamt = (oc >> 6) & 0x1f;
11839 for (args = p->args;; ++args)
11850 printf ("%c", *args);
11854 assert (treg == sreg);
11855 printf ("$%d,$%d", treg, sreg);
11860 printf ("$%d", dreg);
11865 printf ("$%d", treg);
11869 printf ("0x%x", treg);
11874 printf ("$%d", sreg);
11878 printf ("0x%08lx", oc & 0x1ffffff);
11885 printf ("%d", imm);
11890 printf ("$%d", shamt);
11901 printf (_("%08lx UNDEFINED\n"), oc);
11912 name = input_line_pointer;
11913 c = get_symbol_end ();
11914 p = (symbolS *) symbol_find_or_make (name);
11915 *input_line_pointer = c;
11919 /* Align the current frag to a given power of two. The MIPS assembler
11920 also automatically adjusts any preceding label. */
11923 mips_align (to, fill, label)
11928 mips_emit_delays (FALSE);
11929 frag_align (to, fill, 0);
11930 record_alignment (now_seg, to);
11933 assert (S_GET_SEGMENT (label) == now_seg);
11934 symbol_set_frag (label, frag_now);
11935 S_SET_VALUE (label, (valueT) frag_now_fix ());
11939 /* Align to a given power of two. .align 0 turns off the automatic
11940 alignment used by the data creating pseudo-ops. */
11944 int x ATTRIBUTE_UNUSED;
11947 register long temp_fill;
11948 long max_alignment = 15;
11952 o Note that the assembler pulls down any immediately preceeding label
11953 to the aligned address.
11954 o It's not documented but auto alignment is reinstated by
11955 a .align pseudo instruction.
11956 o Note also that after auto alignment is turned off the mips assembler
11957 issues an error on attempt to assemble an improperly aligned data item.
11962 temp = get_absolute_expression ();
11963 if (temp > max_alignment)
11964 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11967 as_warn (_("Alignment negative: 0 assumed."));
11970 if (*input_line_pointer == ',')
11972 ++input_line_pointer;
11973 temp_fill = get_absolute_expression ();
11980 mips_align (temp, (int) temp_fill,
11981 insn_labels != NULL ? insn_labels->label : NULL);
11988 demand_empty_rest_of_line ();
11992 mips_flush_pending_output ()
11994 mips_emit_delays (FALSE);
11995 mips_clear_insn_labels ();
12004 /* When generating embedded PIC code, we only use the .text, .lit8,
12005 .sdata and .sbss sections. We change the .data and .rdata
12006 pseudo-ops to use .sdata. */
12007 if (mips_pic == EMBEDDED_PIC
12008 && (sec == 'd' || sec == 'r'))
12012 /* The ELF backend needs to know that we are changing sections, so
12013 that .previous works correctly. We could do something like check
12014 for an obj_section_change_hook macro, but that might be confusing
12015 as it would not be appropriate to use it in the section changing
12016 functions in read.c, since obj-elf.c intercepts those. FIXME:
12017 This should be cleaner, somehow. */
12018 obj_elf_section_change_hook ();
12021 mips_emit_delays (FALSE);
12031 subseg_set (bss_section, (subsegT) get_absolute_expression ());
12032 demand_empty_rest_of_line ();
12036 if (USE_GLOBAL_POINTER_OPT)
12038 seg = subseg_new (RDATA_SECTION_NAME,
12039 (subsegT) get_absolute_expression ());
12040 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12042 bfd_set_section_flags (stdoutput, seg,
12048 if (strcmp (TARGET_OS, "elf") != 0)
12049 record_alignment (seg, 4);
12051 demand_empty_rest_of_line ();
12055 as_bad (_("No read only data section in this object file format"));
12056 demand_empty_rest_of_line ();
12062 if (USE_GLOBAL_POINTER_OPT)
12064 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
12065 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12067 bfd_set_section_flags (stdoutput, seg,
12068 SEC_ALLOC | SEC_LOAD | SEC_RELOC
12070 if (strcmp (TARGET_OS, "elf") != 0)
12071 record_alignment (seg, 4);
12073 demand_empty_rest_of_line ();
12078 as_bad (_("Global pointers not supported; recompile -G 0"));
12079 demand_empty_rest_of_line ();
12088 s_change_section (ignore)
12089 int ignore ATTRIBUTE_UNUSED;
12092 char *section_name;
12097 int section_entry_size;
12098 int section_alignment;
12100 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
12103 section_name = input_line_pointer;
12104 c = get_symbol_end ();
12106 next_c = *(input_line_pointer + 1);
12108 /* Do we have .section Name<,"flags">? */
12109 if (c != ',' || (c == ',' && next_c == '"'))
12111 /* just after name is now '\0'. */
12112 *input_line_pointer = c;
12113 input_line_pointer = section_name;
12114 obj_elf_section (ignore);
12117 input_line_pointer++;
12119 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
12121 section_type = get_absolute_expression ();
12124 if (*input_line_pointer++ == ',')
12125 section_flag = get_absolute_expression ();
12128 if (*input_line_pointer++ == ',')
12129 section_entry_size = get_absolute_expression ();
12131 section_entry_size = 0;
12132 if (*input_line_pointer++ == ',')
12133 section_alignment = get_absolute_expression ();
12135 section_alignment = 0;
12137 section_name = xstrdup (section_name);
12139 obj_elf_change_section (section_name, section_type, section_flag,
12140 section_entry_size, 0, 0, 0);
12142 if (now_seg->name != section_name)
12143 free (section_name);
12144 #endif /* OBJ_ELF */
12148 mips_enable_auto_align ()
12159 label = insn_labels != NULL ? insn_labels->label : NULL;
12160 mips_emit_delays (FALSE);
12161 if (log_size > 0 && auto_align)
12162 mips_align (log_size, 0, label);
12163 mips_clear_insn_labels ();
12164 cons (1 << log_size);
12168 s_float_cons (type)
12173 label = insn_labels != NULL ? insn_labels->label : NULL;
12175 mips_emit_delays (FALSE);
12180 mips_align (3, 0, label);
12182 mips_align (2, 0, label);
12185 mips_clear_insn_labels ();
12190 /* Handle .globl. We need to override it because on Irix 5 you are
12193 where foo is an undefined symbol, to mean that foo should be
12194 considered to be the address of a function. */
12198 int x ATTRIBUTE_UNUSED;
12205 name = input_line_pointer;
12206 c = get_symbol_end ();
12207 symbolP = symbol_find_or_make (name);
12208 *input_line_pointer = c;
12209 SKIP_WHITESPACE ();
12211 /* On Irix 5, every global symbol that is not explicitly labelled as
12212 being a function is apparently labelled as being an object. */
12215 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12220 secname = input_line_pointer;
12221 c = get_symbol_end ();
12222 sec = bfd_get_section_by_name (stdoutput, secname);
12224 as_bad (_("%s: no such section"), secname);
12225 *input_line_pointer = c;
12227 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
12228 flag = BSF_FUNCTION;
12231 symbol_get_bfdsym (symbolP)->flags |= flag;
12233 S_SET_EXTERNAL (symbolP);
12234 demand_empty_rest_of_line ();
12239 int x ATTRIBUTE_UNUSED;
12244 opt = input_line_pointer;
12245 c = get_symbol_end ();
12249 /* FIXME: What does this mean? */
12251 else if (strncmp (opt, "pic", 3) == 0)
12255 i = atoi (opt + 3);
12260 mips_pic = SVR4_PIC;
12261 mips_abicalls = TRUE;
12264 as_bad (_(".option pic%d not supported"), i);
12266 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
12268 if (g_switch_seen && g_switch_value != 0)
12269 as_warn (_("-G may not be used with SVR4 PIC code"));
12270 g_switch_value = 0;
12271 bfd_set_gp_size (stdoutput, 0);
12275 as_warn (_("Unrecognized option \"%s\""), opt);
12277 *input_line_pointer = c;
12278 demand_empty_rest_of_line ();
12281 /* This structure is used to hold a stack of .set values. */
12283 struct mips_option_stack
12285 struct mips_option_stack *next;
12286 struct mips_set_options options;
12289 static struct mips_option_stack *mips_opts_stack;
12291 /* Handle the .set pseudo-op. */
12295 int x ATTRIBUTE_UNUSED;
12297 char *name = input_line_pointer, ch;
12299 while (!is_end_of_line[(unsigned char) *input_line_pointer])
12300 ++input_line_pointer;
12301 ch = *input_line_pointer;
12302 *input_line_pointer = '\0';
12304 if (strcmp (name, "reorder") == 0)
12306 if (mips_opts.noreorder && prev_nop_frag != NULL)
12308 /* If we still have pending nops, we can discard them. The
12309 usual nop handling will insert any that are still
12311 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
12312 * (mips_opts.mips16 ? 2 : 4));
12313 prev_nop_frag = NULL;
12315 mips_opts.noreorder = 0;
12317 else if (strcmp (name, "noreorder") == 0)
12319 mips_emit_delays (TRUE);
12320 mips_opts.noreorder = 1;
12321 mips_any_noreorder = 1;
12323 else if (strcmp (name, "at") == 0)
12325 mips_opts.noat = 0;
12327 else if (strcmp (name, "noat") == 0)
12329 mips_opts.noat = 1;
12331 else if (strcmp (name, "macro") == 0)
12333 mips_opts.warn_about_macros = 0;
12335 else if (strcmp (name, "nomacro") == 0)
12337 if (mips_opts.noreorder == 0)
12338 as_bad (_("`noreorder' must be set before `nomacro'"));
12339 mips_opts.warn_about_macros = 1;
12341 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
12343 mips_opts.nomove = 0;
12345 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
12347 mips_opts.nomove = 1;
12349 else if (strcmp (name, "bopt") == 0)
12351 mips_opts.nobopt = 0;
12353 else if (strcmp (name, "nobopt") == 0)
12355 mips_opts.nobopt = 1;
12357 else if (strcmp (name, "mips16") == 0
12358 || strcmp (name, "MIPS-16") == 0)
12359 mips_opts.mips16 = 1;
12360 else if (strcmp (name, "nomips16") == 0
12361 || strcmp (name, "noMIPS-16") == 0)
12362 mips_opts.mips16 = 0;
12363 else if (strcmp (name, "mips3d") == 0)
12364 mips_opts.ase_mips3d = 1;
12365 else if (strcmp (name, "nomips3d") == 0)
12366 mips_opts.ase_mips3d = 0;
12367 else if (strcmp (name, "mdmx") == 0)
12368 mips_opts.ase_mdmx = 1;
12369 else if (strcmp (name, "nomdmx") == 0)
12370 mips_opts.ase_mdmx = 0;
12371 else if (strncmp (name, "mips", 4) == 0)
12375 /* Permit the user to change the ISA on the fly. Needless to
12376 say, misuse can cause serious problems. */
12377 if (strcmp (name, "mips0") == 0)
12380 mips_opts.isa = file_mips_isa;
12382 else if (strcmp (name, "mips1") == 0)
12383 mips_opts.isa = ISA_MIPS1;
12384 else if (strcmp (name, "mips2") == 0)
12385 mips_opts.isa = ISA_MIPS2;
12386 else if (strcmp (name, "mips3") == 0)
12387 mips_opts.isa = ISA_MIPS3;
12388 else if (strcmp (name, "mips4") == 0)
12389 mips_opts.isa = ISA_MIPS4;
12390 else if (strcmp (name, "mips5") == 0)
12391 mips_opts.isa = ISA_MIPS5;
12392 else if (strcmp (name, "mips32") == 0)
12393 mips_opts.isa = ISA_MIPS32;
12394 else if (strcmp (name, "mips32r2") == 0)
12395 mips_opts.isa = ISA_MIPS32R2;
12396 else if (strcmp (name, "mips64") == 0)
12397 mips_opts.isa = ISA_MIPS64;
12399 as_bad (_("unknown ISA level %s"), name + 4);
12401 switch (mips_opts.isa)
12409 mips_opts.gp32 = 1;
12410 mips_opts.fp32 = 1;
12416 mips_opts.gp32 = 0;
12417 mips_opts.fp32 = 0;
12420 as_bad (_("unknown ISA level %s"), name + 4);
12425 mips_opts.gp32 = file_mips_gp32;
12426 mips_opts.fp32 = file_mips_fp32;
12429 else if (strcmp (name, "autoextend") == 0)
12430 mips_opts.noautoextend = 0;
12431 else if (strcmp (name, "noautoextend") == 0)
12432 mips_opts.noautoextend = 1;
12433 else if (strcmp (name, "push") == 0)
12435 struct mips_option_stack *s;
12437 s = (struct mips_option_stack *) xmalloc (sizeof *s);
12438 s->next = mips_opts_stack;
12439 s->options = mips_opts;
12440 mips_opts_stack = s;
12442 else if (strcmp (name, "pop") == 0)
12444 struct mips_option_stack *s;
12446 s = mips_opts_stack;
12448 as_bad (_(".set pop with no .set push"));
12451 /* If we're changing the reorder mode we need to handle
12452 delay slots correctly. */
12453 if (s->options.noreorder && ! mips_opts.noreorder)
12454 mips_emit_delays (TRUE);
12455 else if (! s->options.noreorder && mips_opts.noreorder)
12457 if (prev_nop_frag != NULL)
12459 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
12460 * (mips_opts.mips16 ? 2 : 4));
12461 prev_nop_frag = NULL;
12465 mips_opts = s->options;
12466 mips_opts_stack = s->next;
12472 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
12474 *input_line_pointer = ch;
12475 demand_empty_rest_of_line ();
12478 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
12479 .option pic2. It means to generate SVR4 PIC calls. */
12482 s_abicalls (ignore)
12483 int ignore ATTRIBUTE_UNUSED;
12485 mips_pic = SVR4_PIC;
12486 mips_abicalls = TRUE;
12487 if (USE_GLOBAL_POINTER_OPT)
12489 if (g_switch_seen && g_switch_value != 0)
12490 as_warn (_("-G may not be used with SVR4 PIC code"));
12491 g_switch_value = 0;
12493 bfd_set_gp_size (stdoutput, 0);
12494 demand_empty_rest_of_line ();
12497 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12498 PIC code. It sets the $gp register for the function based on the
12499 function address, which is in the register named in the argument.
12500 This uses a relocation against _gp_disp, which is handled specially
12501 by the linker. The result is:
12502 lui $gp,%hi(_gp_disp)
12503 addiu $gp,$gp,%lo(_gp_disp)
12504 addu $gp,$gp,.cpload argument
12505 The .cpload argument is normally $25 == $t9. */
12509 int ignore ATTRIBUTE_UNUSED;
12514 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12515 .cpload is ignored. */
12516 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12522 /* .cpload should be in a .set noreorder section. */
12523 if (mips_opts.noreorder == 0)
12524 as_warn (_(".cpload not in noreorder section"));
12526 ex.X_op = O_symbol;
12527 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
12528 ex.X_op_symbol = NULL;
12529 ex.X_add_number = 0;
12531 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12532 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
12534 macro_build_lui (NULL, &icnt, &ex, mips_gp_register);
12535 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j",
12536 mips_gp_register, mips_gp_register, (int) BFD_RELOC_LO16);
12538 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
12539 mips_gp_register, mips_gp_register, tc_get_register (0));
12541 demand_empty_rest_of_line ();
12544 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12545 .cpsetup $reg1, offset|$reg2, label
12547 If offset is given, this results in:
12548 sd $gp, offset($sp)
12549 lui $gp, %hi(%neg(%gp_rel(label)))
12550 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12551 daddu $gp, $gp, $reg1
12553 If $reg2 is given, this results in:
12554 daddu $reg2, $gp, $0
12555 lui $gp, %hi(%neg(%gp_rel(label)))
12556 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12557 daddu $gp, $gp, $reg1
12558 $reg1 is normally $25 == $t9. */
12561 int ignore ATTRIBUTE_UNUSED;
12563 expressionS ex_off;
12564 expressionS ex_sym;
12569 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12570 We also need NewABI support. */
12571 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12577 reg1 = tc_get_register (0);
12578 SKIP_WHITESPACE ();
12579 if (*input_line_pointer != ',')
12581 as_bad (_("missing argument separator ',' for .cpsetup"));
12585 ++input_line_pointer;
12586 SKIP_WHITESPACE ();
12587 if (*input_line_pointer == '$')
12589 mips_cpreturn_register = tc_get_register (0);
12590 mips_cpreturn_offset = -1;
12594 mips_cpreturn_offset = get_absolute_expression ();
12595 mips_cpreturn_register = -1;
12597 SKIP_WHITESPACE ();
12598 if (*input_line_pointer != ',')
12600 as_bad (_("missing argument separator ',' for .cpsetup"));
12604 ++input_line_pointer;
12605 SKIP_WHITESPACE ();
12606 expression (&ex_sym);
12608 if (mips_cpreturn_register == -1)
12610 ex_off.X_op = O_constant;
12611 ex_off.X_add_symbol = NULL;
12612 ex_off.X_op_symbol = NULL;
12613 ex_off.X_add_number = mips_cpreturn_offset;
12615 macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)",
12616 mips_gp_register, (int) BFD_RELOC_LO16, SP);
12619 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
12620 "d,v,t", mips_cpreturn_register, mips_gp_register, 0);
12622 /* Ensure there's room for the next two instructions, so that `f'
12623 doesn't end up with an address in the wrong frag. */
12626 macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
12627 (int) BFD_RELOC_GPREL16);
12628 fix_new (frag_now, f - frag_now->fr_literal,
12629 8, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
12630 fix_new (frag_now, f - frag_now->fr_literal,
12631 4, NULL, 0, 0, BFD_RELOC_HI16_S);
12634 macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j",
12635 mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16);
12636 fix_new (frag_now, f - frag_now->fr_literal,
12637 8, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
12638 fix_new (frag_now, f - frag_now->fr_literal,
12639 4, NULL, 0, 0, BFD_RELOC_LO16);
12641 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, ADDRESS_ADD_INSN,
12642 "d,v,t", mips_gp_register, mips_gp_register, reg1);
12644 demand_empty_rest_of_line ();
12649 int ignore ATTRIBUTE_UNUSED;
12651 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12652 .cplocal is ignored. */
12653 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12659 mips_gp_register = tc_get_register (0);
12660 demand_empty_rest_of_line ();
12663 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12664 offset from $sp. The offset is remembered, and after making a PIC
12665 call $gp is restored from that location. */
12668 s_cprestore (ignore)
12669 int ignore ATTRIBUTE_UNUSED;
12674 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12675 .cprestore is ignored. */
12676 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12682 mips_cprestore_offset = get_absolute_expression ();
12683 mips_cprestore_valid = 1;
12685 ex.X_op = O_constant;
12686 ex.X_add_symbol = NULL;
12687 ex.X_op_symbol = NULL;
12688 ex.X_add_number = mips_cprestore_offset;
12690 macro_build_ldst_constoffset ((char *) NULL, &icnt, &ex, ADDRESS_STORE_INSN,
12691 mips_gp_register, SP);
12693 demand_empty_rest_of_line ();
12696 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12697 was given in the preceeding .gpsetup, it results in:
12698 ld $gp, offset($sp)
12700 If a register $reg2 was given there, it results in:
12701 daddiu $gp, $gp, $reg2
12704 s_cpreturn (ignore)
12705 int ignore ATTRIBUTE_UNUSED;
12710 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12711 We also need NewABI support. */
12712 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12718 if (mips_cpreturn_register == -1)
12720 ex.X_op = O_constant;
12721 ex.X_add_symbol = NULL;
12722 ex.X_op_symbol = NULL;
12723 ex.X_add_number = mips_cpreturn_offset;
12725 macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)",
12726 mips_gp_register, (int) BFD_RELOC_LO16, SP);
12729 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
12730 "d,v,t", mips_gp_register, mips_cpreturn_register, 0);
12732 demand_empty_rest_of_line ();
12735 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12736 code. It sets the offset to use in gp_rel relocations. */
12740 int ignore ATTRIBUTE_UNUSED;
12742 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12743 We also need NewABI support. */
12744 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12750 mips_gprel_offset = get_absolute_expression ();
12752 demand_empty_rest_of_line ();
12755 /* Handle the .gpword pseudo-op. This is used when generating PIC
12756 code. It generates a 32 bit GP relative reloc. */
12760 int ignore ATTRIBUTE_UNUSED;
12766 /* When not generating PIC code, this is treated as .word. */
12767 if (mips_pic != SVR4_PIC)
12773 label = insn_labels != NULL ? insn_labels->label : NULL;
12774 mips_emit_delays (TRUE);
12776 mips_align (2, 0, label);
12777 mips_clear_insn_labels ();
12781 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12783 as_bad (_("Unsupported use of .gpword"));
12784 ignore_rest_of_line ();
12788 md_number_to_chars (p, (valueT) 0, 4);
12789 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12790 BFD_RELOC_GPREL32);
12792 demand_empty_rest_of_line ();
12797 int ignore ATTRIBUTE_UNUSED;
12803 /* When not generating PIC code, this is treated as .dword. */
12804 if (mips_pic != SVR4_PIC)
12810 label = insn_labels != NULL ? insn_labels->label : NULL;
12811 mips_emit_delays (TRUE);
12813 mips_align (3, 0, label);
12814 mips_clear_insn_labels ();
12818 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12820 as_bad (_("Unsupported use of .gpdword"));
12821 ignore_rest_of_line ();
12825 md_number_to_chars (p, (valueT) 0, 8);
12826 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12827 BFD_RELOC_GPREL32);
12829 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12830 ex.X_op = O_absent;
12831 ex.X_add_symbol = 0;
12832 ex.X_add_number = 0;
12833 fix_new_exp (frag_now, p - frag_now->fr_literal, 8, &ex, FALSE,
12836 demand_empty_rest_of_line ();
12839 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12840 tables in SVR4 PIC code. */
12844 int ignore ATTRIBUTE_UNUSED;
12849 /* This is ignored when not generating SVR4 PIC code. */
12850 if (mips_pic != SVR4_PIC)
12856 /* Add $gp to the register named as an argument. */
12857 reg = tc_get_register (0);
12858 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, ADDRESS_ADD_INSN,
12859 "d,v,t", reg, reg, mips_gp_register);
12861 demand_empty_rest_of_line ();
12864 /* Handle the .insn pseudo-op. This marks instruction labels in
12865 mips16 mode. This permits the linker to handle them specially,
12866 such as generating jalx instructions when needed. We also make
12867 them odd for the duration of the assembly, in order to generate the
12868 right sort of code. We will make them even in the adjust_symtab
12869 routine, while leaving them marked. This is convenient for the
12870 debugger and the disassembler. The linker knows to make them odd
12875 int ignore ATTRIBUTE_UNUSED;
12877 mips16_mark_labels ();
12879 demand_empty_rest_of_line ();
12882 /* Handle a .stabn directive. We need these in order to mark a label
12883 as being a mips16 text label correctly. Sometimes the compiler
12884 will emit a label, followed by a .stabn, and then switch sections.
12885 If the label and .stabn are in mips16 mode, then the label is
12886 really a mips16 text label. */
12893 mips16_mark_labels ();
12898 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12902 s_mips_weakext (ignore)
12903 int ignore ATTRIBUTE_UNUSED;
12910 name = input_line_pointer;
12911 c = get_symbol_end ();
12912 symbolP = symbol_find_or_make (name);
12913 S_SET_WEAK (symbolP);
12914 *input_line_pointer = c;
12916 SKIP_WHITESPACE ();
12918 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12920 if (S_IS_DEFINED (symbolP))
12922 as_bad ("ignoring attempt to redefine symbol %s",
12923 S_GET_NAME (symbolP));
12924 ignore_rest_of_line ();
12928 if (*input_line_pointer == ',')
12930 ++input_line_pointer;
12931 SKIP_WHITESPACE ();
12935 if (exp.X_op != O_symbol)
12937 as_bad ("bad .weakext directive");
12938 ignore_rest_of_line ();
12941 symbol_set_value_expression (symbolP, &exp);
12944 demand_empty_rest_of_line ();
12947 /* Parse a register string into a number. Called from the ECOFF code
12948 to parse .frame. The argument is non-zero if this is the frame
12949 register, so that we can record it in mips_frame_reg. */
12952 tc_get_register (frame)
12957 SKIP_WHITESPACE ();
12958 if (*input_line_pointer++ != '$')
12960 as_warn (_("expected `$'"));
12963 else if (ISDIGIT (*input_line_pointer))
12965 reg = get_absolute_expression ();
12966 if (reg < 0 || reg >= 32)
12968 as_warn (_("Bad register number"));
12974 if (strncmp (input_line_pointer, "ra", 2) == 0)
12977 input_line_pointer += 2;
12979 else if (strncmp (input_line_pointer, "fp", 2) == 0)
12982 input_line_pointer += 2;
12984 else if (strncmp (input_line_pointer, "sp", 2) == 0)
12987 input_line_pointer += 2;
12989 else if (strncmp (input_line_pointer, "gp", 2) == 0)
12992 input_line_pointer += 2;
12994 else if (strncmp (input_line_pointer, "at", 2) == 0)
12997 input_line_pointer += 2;
12999 else if (strncmp (input_line_pointer, "kt0", 3) == 0)
13002 input_line_pointer += 3;
13004 else if (strncmp (input_line_pointer, "kt1", 3) == 0)
13007 input_line_pointer += 3;
13009 else if (strncmp (input_line_pointer, "zero", 4) == 0)
13012 input_line_pointer += 4;
13016 as_warn (_("Unrecognized register name"));
13018 while (ISALNUM(*input_line_pointer))
13019 input_line_pointer++;
13024 mips_frame_reg = reg != 0 ? reg : SP;
13025 mips_frame_reg_valid = 1;
13026 mips_cprestore_valid = 0;
13032 md_section_align (seg, addr)
13036 int align = bfd_get_section_alignment (stdoutput, seg);
13039 /* We don't need to align ELF sections to the full alignment.
13040 However, Irix 5 may prefer that we align them at least to a 16
13041 byte boundary. We don't bother to align the sections if we are
13042 targeted for an embedded system. */
13043 if (strcmp (TARGET_OS, "elf") == 0)
13049 return ((addr + (1 << align) - 1) & (-1 << align));
13052 /* Utility routine, called from above as well. If called while the
13053 input file is still being read, it's only an approximation. (For
13054 example, a symbol may later become defined which appeared to be
13055 undefined earlier.) */
13058 nopic_need_relax (sym, before_relaxing)
13060 int before_relaxing;
13065 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
13067 const char *symname;
13070 /* Find out whether this symbol can be referenced off the $gp
13071 register. It can be if it is smaller than the -G size or if
13072 it is in the .sdata or .sbss section. Certain symbols can
13073 not be referenced off the $gp, although it appears as though
13075 symname = S_GET_NAME (sym);
13076 if (symname != (const char *) NULL
13077 && (strcmp (symname, "eprol") == 0
13078 || strcmp (symname, "etext") == 0
13079 || strcmp (symname, "_gp") == 0
13080 || strcmp (symname, "edata") == 0
13081 || strcmp (symname, "_fbss") == 0
13082 || strcmp (symname, "_fdata") == 0
13083 || strcmp (symname, "_ftext") == 0
13084 || strcmp (symname, "end") == 0
13085 || strcmp (symname, "_gp_disp") == 0))
13087 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
13089 #ifndef NO_ECOFF_DEBUGGING
13090 || (symbol_get_obj (sym)->ecoff_extern_size != 0
13091 && (symbol_get_obj (sym)->ecoff_extern_size
13092 <= g_switch_value))
13094 /* We must defer this decision until after the whole
13095 file has been read, since there might be a .extern
13096 after the first use of this symbol. */
13097 || (before_relaxing
13098 #ifndef NO_ECOFF_DEBUGGING
13099 && symbol_get_obj (sym)->ecoff_extern_size == 0
13101 && S_GET_VALUE (sym) == 0)
13102 || (S_GET_VALUE (sym) != 0
13103 && S_GET_VALUE (sym) <= g_switch_value)))
13107 const char *segname;
13109 segname = segment_name (S_GET_SEGMENT (sym));
13110 assert (strcmp (segname, ".lit8") != 0
13111 && strcmp (segname, ".lit4") != 0);
13112 change = (strcmp (segname, ".sdata") != 0
13113 && strcmp (segname, ".sbss") != 0
13114 && strncmp (segname, ".sdata.", 7) != 0
13115 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
13120 /* We are not optimizing for the $gp register. */
13125 /* Return true if the given symbol should be considered local for SVR4 PIC. */
13128 pic_need_relax (sym, segtype)
13133 bfd_boolean linkonce;
13135 /* Handle the case of a symbol equated to another symbol. */
13136 while (symbol_equated_reloc_p (sym))
13140 /* It's possible to get a loop here in a badly written
13142 n = symbol_get_value_expression (sym)->X_add_symbol;
13148 symsec = S_GET_SEGMENT (sym);
13150 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
13152 if (symsec != segtype && ! S_IS_LOCAL (sym))
13154 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
13158 /* The GNU toolchain uses an extension for ELF: a section
13159 beginning with the magic string .gnu.linkonce is a linkonce
13161 if (strncmp (segment_name (symsec), ".gnu.linkonce",
13162 sizeof ".gnu.linkonce" - 1) == 0)
13166 /* This must duplicate the test in adjust_reloc_syms. */
13167 return (symsec != &bfd_und_section
13168 && symsec != &bfd_abs_section
13169 && ! bfd_is_com_section (symsec)
13172 /* A global or weak symbol is treated as external. */
13173 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
13174 || (! S_IS_WEAK (sym)
13175 && (! S_IS_EXTERNAL (sym)
13176 || mips_pic == EMBEDDED_PIC)))
13182 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
13183 extended opcode. SEC is the section the frag is in. */
13186 mips16_extended_frag (fragp, sec, stretch)
13192 register const struct mips16_immed_operand *op;
13194 int mintiny, maxtiny;
13198 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
13200 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
13203 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13204 op = mips16_immed_operands;
13205 while (op->type != type)
13208 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
13213 if (type == '<' || type == '>' || type == '[' || type == ']')
13216 maxtiny = 1 << op->nbits;
13221 maxtiny = (1 << op->nbits) - 1;
13226 mintiny = - (1 << (op->nbits - 1));
13227 maxtiny = (1 << (op->nbits - 1)) - 1;
13230 sym_frag = symbol_get_frag (fragp->fr_symbol);
13231 val = S_GET_VALUE (fragp->fr_symbol);
13232 symsec = S_GET_SEGMENT (fragp->fr_symbol);
13238 /* We won't have the section when we are called from
13239 mips_relax_frag. However, we will always have been called
13240 from md_estimate_size_before_relax first. If this is a
13241 branch to a different section, we mark it as such. If SEC is
13242 NULL, and the frag is not marked, then it must be a branch to
13243 the same section. */
13246 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
13251 /* Must have been called from md_estimate_size_before_relax. */
13254 fragp->fr_subtype =
13255 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13257 /* FIXME: We should support this, and let the linker
13258 catch branches and loads that are out of range. */
13259 as_bad_where (fragp->fr_file, fragp->fr_line,
13260 _("unsupported PC relative reference to different section"));
13264 if (fragp != sym_frag && sym_frag->fr_address == 0)
13265 /* Assume non-extended on the first relaxation pass.
13266 The address we have calculated will be bogus if this is
13267 a forward branch to another frag, as the forward frag
13268 will have fr_address == 0. */
13272 /* In this case, we know for sure that the symbol fragment is in
13273 the same section. If the relax_marker of the symbol fragment
13274 differs from the relax_marker of this fragment, we have not
13275 yet adjusted the symbol fragment fr_address. We want to add
13276 in STRETCH in order to get a better estimate of the address.
13277 This particularly matters because of the shift bits. */
13279 && sym_frag->relax_marker != fragp->relax_marker)
13283 /* Adjust stretch for any alignment frag. Note that if have
13284 been expanding the earlier code, the symbol may be
13285 defined in what appears to be an earlier frag. FIXME:
13286 This doesn't handle the fr_subtype field, which specifies
13287 a maximum number of bytes to skip when doing an
13289 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
13291 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
13294 stretch = - ((- stretch)
13295 & ~ ((1 << (int) f->fr_offset) - 1));
13297 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
13306 addr = fragp->fr_address + fragp->fr_fix;
13308 /* The base address rules are complicated. The base address of
13309 a branch is the following instruction. The base address of a
13310 PC relative load or add is the instruction itself, but if it
13311 is in a delay slot (in which case it can not be extended) use
13312 the address of the instruction whose delay slot it is in. */
13313 if (type == 'p' || type == 'q')
13317 /* If we are currently assuming that this frag should be
13318 extended, then, the current address is two bytes
13320 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13323 /* Ignore the low bit in the target, since it will be set
13324 for a text label. */
13325 if ((val & 1) != 0)
13328 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13330 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13333 val -= addr & ~ ((1 << op->shift) - 1);
13335 /* Branch offsets have an implicit 0 in the lowest bit. */
13336 if (type == 'p' || type == 'q')
13339 /* If any of the shifted bits are set, we must use an extended
13340 opcode. If the address depends on the size of this
13341 instruction, this can lead to a loop, so we arrange to always
13342 use an extended opcode. We only check this when we are in
13343 the main relaxation loop, when SEC is NULL. */
13344 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
13346 fragp->fr_subtype =
13347 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13351 /* If we are about to mark a frag as extended because the value
13352 is precisely maxtiny + 1, then there is a chance of an
13353 infinite loop as in the following code:
13358 In this case when the la is extended, foo is 0x3fc bytes
13359 away, so the la can be shrunk, but then foo is 0x400 away, so
13360 the la must be extended. To avoid this loop, we mark the
13361 frag as extended if it was small, and is about to become
13362 extended with a value of maxtiny + 1. */
13363 if (val == ((maxtiny + 1) << op->shift)
13364 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
13367 fragp->fr_subtype =
13368 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13372 else if (symsec != absolute_section && sec != NULL)
13373 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
13375 if ((val & ((1 << op->shift) - 1)) != 0
13376 || val < (mintiny << op->shift)
13377 || val > (maxtiny << op->shift))
13383 /* Compute the length of a branch sequence, and adjust the
13384 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
13385 worst-case length is computed, with UPDATE being used to indicate
13386 whether an unconditional (-1), branch-likely (+1) or regular (0)
13387 branch is to be computed. */
13389 relaxed_branch_length (fragp, sec, update)
13394 bfd_boolean toofar;
13398 && S_IS_DEFINED (fragp->fr_symbol)
13399 && sec == S_GET_SEGMENT (fragp->fr_symbol))
13404 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
13406 addr = fragp->fr_address + fragp->fr_fix + 4;
13410 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
13413 /* If the symbol is not defined or it's in a different segment,
13414 assume the user knows what's going on and emit a short
13420 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13422 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp->fr_subtype),
13423 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
13424 RELAX_BRANCH_LINK (fragp->fr_subtype),
13430 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
13433 if (mips_pic != NO_PIC)
13435 /* Additional space for PIC loading of target address. */
13437 if (mips_opts.isa == ISA_MIPS1)
13438 /* Additional space for $at-stabilizing nop. */
13442 /* If branch is conditional. */
13443 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
13450 /* Estimate the size of a frag before relaxing. Unless this is the
13451 mips16, we are not really relaxing here, and the final size is
13452 encoded in the subtype information. For the mips16, we have to
13453 decide whether we are using an extended opcode or not. */
13456 md_estimate_size_before_relax (fragp, segtype)
13462 if (RELAX_BRANCH_P (fragp->fr_subtype))
13465 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
13467 return fragp->fr_var;
13470 if (RELAX_MIPS16_P (fragp->fr_subtype))
13471 /* We don't want to modify the EXTENDED bit here; it might get us
13472 into infinite loops. We change it only in mips_relax_frag(). */
13473 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
13475 if (mips_pic == NO_PIC)
13476 change = nopic_need_relax (fragp->fr_symbol, 0);
13477 else if (mips_pic == SVR4_PIC)
13478 change = pic_need_relax (fragp->fr_symbol, segtype);
13484 /* Record the offset to the first reloc in the fr_opcode field.
13485 This lets md_convert_frag and tc_gen_reloc know that the code
13486 must be expanded. */
13487 fragp->fr_opcode = (fragp->fr_literal
13489 - RELAX_OLD (fragp->fr_subtype)
13490 + RELAX_RELOC1 (fragp->fr_subtype));
13491 /* FIXME: This really needs as_warn_where. */
13492 if (RELAX_WARN (fragp->fr_subtype))
13493 as_warn (_("AT used after \".set noat\" or macro used after "
13494 "\".set nomacro\""));
13496 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
13502 /* This is called to see whether a reloc against a defined symbol
13503 should be converted into a reloc against a section. Don't adjust
13504 MIPS16 jump relocations, so we don't have to worry about the format
13505 of the offset in the .o file. Don't adjust relocations against
13506 mips16 symbols, so that the linker can find them if it needs to set
13510 mips_fix_adjustable (fixp)
13513 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
13516 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
13517 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13520 if (fixp->fx_addsy == NULL)
13524 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
13525 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
13526 && fixp->fx_subsy == NULL)
13533 /* Translate internal representation of relocation info to BFD target
13537 tc_gen_reloc (section, fixp)
13538 asection *section ATTRIBUTE_UNUSED;
13541 static arelent *retval[4];
13543 bfd_reloc_code_real_type code;
13545 memset (retval, 0, sizeof(retval));
13546 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
13547 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13548 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13549 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13551 if (mips_pic == EMBEDDED_PIC
13552 && SWITCH_TABLE (fixp))
13554 /* For a switch table entry we use a special reloc. The addend
13555 is actually the difference between the reloc address and the
13557 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
13558 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
13559 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
13560 fixp->fx_r_type = BFD_RELOC_GPREL32;
13562 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
13564 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
13565 reloc->addend = fixp->fx_addnumber;
13568 /* We use a special addend for an internal RELLO reloc. */
13569 if (symbol_section_p (fixp->fx_addsy))
13570 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
13572 reloc->addend = fixp->fx_addnumber + reloc->address;
13575 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
13577 assert (fixp->fx_next != NULL
13578 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
13580 /* The reloc is relative to the RELLO; adjust the addend
13582 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
13583 reloc->addend = fixp->fx_next->fx_addnumber;
13586 /* We use a special addend for an internal RELHI reloc. */
13587 if (symbol_section_p (fixp->fx_addsy))
13588 reloc->addend = (fixp->fx_next->fx_frag->fr_address
13589 + fixp->fx_next->fx_where
13590 - S_GET_VALUE (fixp->fx_subsy));
13592 reloc->addend = (fixp->fx_addnumber
13593 + fixp->fx_next->fx_frag->fr_address
13594 + fixp->fx_next->fx_where);
13597 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
13598 reloc->addend = fixp->fx_addnumber;
13601 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
13602 /* A gruesome hack which is a result of the gruesome gas reloc
13604 reloc->addend = reloc->address;
13606 reloc->addend = -reloc->address;
13609 /* If this is a variant frag, we may need to adjust the existing
13610 reloc and generate a new one. */
13611 if (fixp->fx_frag->fr_opcode != NULL
13612 && ((fixp->fx_r_type == BFD_RELOC_GPREL16
13614 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_DISP
13616 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
13617 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
13618 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
13619 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
13620 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
13621 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
13626 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
13628 /* If this is not the last reloc in this frag, then we have two
13629 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
13630 CALL_HI16/CALL_LO16, both of which are being replaced. Let
13631 the second one handle all of them. */
13632 if (fixp->fx_next != NULL
13633 && fixp->fx_frag == fixp->fx_next->fx_frag)
13635 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
13636 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
13637 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
13638 && (fixp->fx_next->fx_r_type
13639 == BFD_RELOC_MIPS_GOT_LO16))
13640 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
13641 && (fixp->fx_next->fx_r_type
13642 == BFD_RELOC_MIPS_CALL_LO16)));
13647 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
13648 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13649 reloc->addend += fixp->fx_frag->tc_frag_data.tc_fr_offset;
13650 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
13651 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13652 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13653 reloc2->address = (reloc->address
13654 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
13655 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
13656 reloc2->addend = fixp->fx_addnumber - S_GET_VALUE (fixp->fx_addsy)
13657 + fixp->fx_frag->tc_frag_data.tc_fr_offset;
13658 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
13659 assert (reloc2->howto != NULL);
13661 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
13665 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
13667 reloc3->address += 4;
13670 if (mips_pic == NO_PIC)
13672 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
13673 fixp->fx_r_type = BFD_RELOC_HI16_S;
13675 else if (mips_pic == SVR4_PIC)
13677 switch (fixp->fx_r_type)
13681 case BFD_RELOC_MIPS_GOT16:
13683 case BFD_RELOC_MIPS_GOT_LO16:
13684 case BFD_RELOC_MIPS_CALL_LO16:
13687 fixp->fx_r_type = BFD_RELOC_MIPS_GOT_PAGE;
13688 reloc2->howto = bfd_reloc_type_lookup
13689 (stdoutput, BFD_RELOC_MIPS_GOT_OFST);
13692 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
13694 case BFD_RELOC_MIPS_CALL16:
13695 case BFD_RELOC_MIPS_GOT_OFST:
13696 case BFD_RELOC_MIPS_GOT_DISP:
13699 /* It may seem nonsensical to relax GOT_DISP to
13700 GOT_DISP, but we're actually turning a GOT_DISP
13701 without offset into a GOT_DISP with an offset,
13702 getting rid of the separate addition, which we can
13703 do when the symbol is found to be local. */
13704 fixp->fx_r_type = BFD_RELOC_MIPS_GOT_DISP;
13708 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
13716 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13717 entry to be used in the relocation's section offset. */
13718 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13720 reloc->address = reloc->addend;
13724 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
13725 fixup_segment converted a non-PC relative reloc into a PC
13726 relative reloc. In such a case, we need to convert the reloc
13728 code = fixp->fx_r_type;
13729 if (fixp->fx_pcrel)
13734 code = BFD_RELOC_8_PCREL;
13737 code = BFD_RELOC_16_PCREL;
13740 code = BFD_RELOC_32_PCREL;
13743 code = BFD_RELOC_64_PCREL;
13745 case BFD_RELOC_8_PCREL:
13746 case BFD_RELOC_16_PCREL:
13747 case BFD_RELOC_32_PCREL:
13748 case BFD_RELOC_64_PCREL:
13749 case BFD_RELOC_16_PCREL_S2:
13750 case BFD_RELOC_PCREL_HI16_S:
13751 case BFD_RELOC_PCREL_LO16:
13754 as_bad_where (fixp->fx_file, fixp->fx_line,
13755 _("Cannot make %s relocation PC relative"),
13756 bfd_get_reloc_code_name (code));
13760 /* To support a PC relative reloc when generating embedded PIC code
13761 for ECOFF, we use a Cygnus extension. We check for that here to
13762 make sure that we don't let such a reloc escape normally. */
13763 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
13764 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
13765 && code == BFD_RELOC_16_PCREL_S2
13766 && mips_pic != EMBEDDED_PIC)
13767 reloc->howto = NULL;
13769 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
13771 if (reloc->howto == NULL)
13773 as_bad_where (fixp->fx_file, fixp->fx_line,
13774 _("Can not represent %s relocation in this object file format"),
13775 bfd_get_reloc_code_name (code));
13782 /* Relax a machine dependent frag. This returns the amount by which
13783 the current size of the frag should change. */
13786 mips_relax_frag (sec, fragp, stretch)
13791 if (RELAX_BRANCH_P (fragp->fr_subtype))
13793 offsetT old_var = fragp->fr_var;
13795 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
13797 return fragp->fr_var - old_var;
13800 if (! RELAX_MIPS16_P (fragp->fr_subtype))
13803 if (mips16_extended_frag (fragp, NULL, stretch))
13805 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13807 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
13812 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13814 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
13821 /* Convert a machine dependent frag. */
13824 md_convert_frag (abfd, asec, fragp)
13825 bfd *abfd ATTRIBUTE_UNUSED;
13832 if (RELAX_BRANCH_P (fragp->fr_subtype))
13835 unsigned long insn;
13839 buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
13841 if (target_big_endian)
13842 insn = bfd_getb32 (buf);
13844 insn = bfd_getl32 (buf);
13846 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13848 /* We generate a fixup instead of applying it right now
13849 because, if there are linker relaxations, we're going to
13850 need the relocations. */
13851 exp.X_op = O_symbol;
13852 exp.X_add_symbol = fragp->fr_symbol;
13853 exp.X_add_number = fragp->fr_offset;
13855 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13857 BFD_RELOC_16_PCREL_S2);
13858 fixp->fx_file = fragp->fr_file;
13859 fixp->fx_line = fragp->fr_line;
13861 md_number_to_chars ((char *)buf, insn, 4);
13868 as_warn_where (fragp->fr_file, fragp->fr_line,
13869 _("relaxed out-of-range branch into a jump"));
13871 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
13874 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13876 /* Reverse the branch. */
13877 switch ((insn >> 28) & 0xf)
13880 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13881 have the condition reversed by tweaking a single
13882 bit, and their opcodes all have 0x4???????. */
13883 assert ((insn & 0xf1000000) == 0x41000000);
13884 insn ^= 0x00010000;
13888 /* bltz 0x04000000 bgez 0x04010000
13889 bltzal 0x04100000 bgezal 0x04110000 */
13890 assert ((insn & 0xfc0e0000) == 0x04000000);
13891 insn ^= 0x00010000;
13895 /* beq 0x10000000 bne 0x14000000
13896 blez 0x18000000 bgtz 0x1c000000 */
13897 insn ^= 0x04000000;
13905 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13907 /* Clear the and-link bit. */
13908 assert ((insn & 0xfc1c0000) == 0x04100000);
13910 /* bltzal 0x04100000 bgezal 0x04110000
13911 bltzall 0x04120000 bgezall 0x04130000 */
13912 insn &= ~0x00100000;
13915 /* Branch over the branch (if the branch was likely) or the
13916 full jump (not likely case). Compute the offset from the
13917 current instruction to branch to. */
13918 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13922 /* How many bytes in instructions we've already emitted? */
13923 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13924 /* How many bytes in instructions from here to the end? */
13925 i = fragp->fr_var - i;
13927 /* Convert to instruction count. */
13929 /* Branch counts from the next instruction. */
13932 /* Branch over the jump. */
13933 md_number_to_chars ((char *)buf, insn, 4);
13937 md_number_to_chars ((char*)buf, 0, 4);
13940 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13942 /* beql $0, $0, 2f */
13944 /* Compute the PC offset from the current instruction to
13945 the end of the variable frag. */
13946 /* How many bytes in instructions we've already emitted? */
13947 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13948 /* How many bytes in instructions from here to the end? */
13949 i = fragp->fr_var - i;
13950 /* Convert to instruction count. */
13952 /* Don't decrement i, because we want to branch over the
13956 md_number_to_chars ((char *)buf, insn, 4);
13959 md_number_to_chars ((char *)buf, 0, 4);
13964 if (mips_pic == NO_PIC)
13967 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
13968 ? 0x0c000000 : 0x08000000);
13969 exp.X_op = O_symbol;
13970 exp.X_add_symbol = fragp->fr_symbol;
13971 exp.X_add_number = fragp->fr_offset;
13973 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13974 4, &exp, 0, BFD_RELOC_MIPS_JMP);
13975 fixp->fx_file = fragp->fr_file;
13976 fixp->fx_line = fragp->fr_line;
13978 md_number_to_chars ((char*)buf, insn, 4);
13983 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13984 insn = HAVE_64BIT_ADDRESSES ? 0xdf810000 : 0x8f810000;
13985 exp.X_op = O_symbol;
13986 exp.X_add_symbol = fragp->fr_symbol;
13987 exp.X_add_number = fragp->fr_offset;
13989 if (fragp->fr_offset)
13991 exp.X_add_symbol = make_expr_symbol (&exp);
13992 exp.X_add_number = 0;
13995 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13996 4, &exp, 0, BFD_RELOC_MIPS_GOT16);
13997 fixp->fx_file = fragp->fr_file;
13998 fixp->fx_line = fragp->fr_line;
14000 md_number_to_chars ((char*)buf, insn, 4);
14003 if (mips_opts.isa == ISA_MIPS1)
14006 md_number_to_chars ((char*)buf, 0, 4);
14010 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
14011 insn = HAVE_64BIT_ADDRESSES ? 0x64210000 : 0x24210000;
14013 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
14014 4, &exp, 0, BFD_RELOC_LO16);
14015 fixp->fx_file = fragp->fr_file;
14016 fixp->fx_line = fragp->fr_line;
14018 md_number_to_chars ((char*)buf, insn, 4);
14022 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
14027 md_number_to_chars ((char*)buf, insn, 4);
14032 assert (buf == (bfd_byte *)fragp->fr_literal
14033 + fragp->fr_fix + fragp->fr_var);
14035 fragp->fr_fix += fragp->fr_var;
14040 if (RELAX_MIPS16_P (fragp->fr_subtype))
14043 register const struct mips16_immed_operand *op;
14044 bfd_boolean small, ext;
14047 unsigned long insn;
14048 bfd_boolean use_extend;
14049 unsigned short extend;
14051 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
14052 op = mips16_immed_operands;
14053 while (op->type != type)
14056 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
14067 resolve_symbol_value (fragp->fr_symbol);
14068 val = S_GET_VALUE (fragp->fr_symbol);
14073 addr = fragp->fr_address + fragp->fr_fix;
14075 /* The rules for the base address of a PC relative reloc are
14076 complicated; see mips16_extended_frag. */
14077 if (type == 'p' || type == 'q')
14082 /* Ignore the low bit in the target, since it will be
14083 set for a text label. */
14084 if ((val & 1) != 0)
14087 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
14089 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
14092 addr &= ~ (addressT) ((1 << op->shift) - 1);
14095 /* Make sure the section winds up with the alignment we have
14098 record_alignment (asec, op->shift);
14102 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
14103 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
14104 as_warn_where (fragp->fr_file, fragp->fr_line,
14105 _("extended instruction in delay slot"));
14107 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
14109 if (target_big_endian)
14110 insn = bfd_getb16 (buf);
14112 insn = bfd_getl16 (buf);
14114 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
14115 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
14116 small, ext, &insn, &use_extend, &extend);
14120 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
14121 fragp->fr_fix += 2;
14125 md_number_to_chars ((char *) buf, insn, 2);
14126 fragp->fr_fix += 2;
14131 if (fragp->fr_opcode == NULL)
14134 old = RELAX_OLD (fragp->fr_subtype);
14135 new = RELAX_NEW (fragp->fr_subtype);
14136 fixptr = fragp->fr_literal + fragp->fr_fix;
14139 memmove (fixptr - old, fixptr, new);
14141 fragp->fr_fix += new - old;
14147 /* This function is called after the relocs have been generated.
14148 We've been storing mips16 text labels as odd. Here we convert them
14149 back to even for the convenience of the debugger. */
14152 mips_frob_file_after_relocs ()
14155 unsigned int count, i;
14157 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
14160 syms = bfd_get_outsymbols (stdoutput);
14161 count = bfd_get_symcount (stdoutput);
14162 for (i = 0; i < count; i++, syms++)
14164 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
14165 && ((*syms)->value & 1) != 0)
14167 (*syms)->value &= ~1;
14168 /* If the symbol has an odd size, it was probably computed
14169 incorrectly, so adjust that as well. */
14170 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
14171 ++elf_symbol (*syms)->internal_elf_sym.st_size;
14178 /* This function is called whenever a label is defined. It is used
14179 when handling branch delays; if a branch has a label, we assume we
14180 can not move it. */
14183 mips_define_label (sym)
14186 struct insn_label_list *l;
14188 if (free_insn_labels == NULL)
14189 l = (struct insn_label_list *) xmalloc (sizeof *l);
14192 l = free_insn_labels;
14193 free_insn_labels = l->next;
14197 l->next = insn_labels;
14201 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14203 /* Some special processing for a MIPS ELF file. */
14206 mips_elf_final_processing ()
14208 /* Write out the register information. */
14209 if (mips_abi != N64_ABI)
14213 s.ri_gprmask = mips_gprmask;
14214 s.ri_cprmask[0] = mips_cprmask[0];
14215 s.ri_cprmask[1] = mips_cprmask[1];
14216 s.ri_cprmask[2] = mips_cprmask[2];
14217 s.ri_cprmask[3] = mips_cprmask[3];
14218 /* The gp_value field is set by the MIPS ELF backend. */
14220 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
14221 ((Elf32_External_RegInfo *)
14222 mips_regmask_frag));
14226 Elf64_Internal_RegInfo s;
14228 s.ri_gprmask = mips_gprmask;
14230 s.ri_cprmask[0] = mips_cprmask[0];
14231 s.ri_cprmask[1] = mips_cprmask[1];
14232 s.ri_cprmask[2] = mips_cprmask[2];
14233 s.ri_cprmask[3] = mips_cprmask[3];
14234 /* The gp_value field is set by the MIPS ELF backend. */
14236 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
14237 ((Elf64_External_RegInfo *)
14238 mips_regmask_frag));
14241 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
14242 sort of BFD interface for this. */
14243 if (mips_any_noreorder)
14244 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
14245 if (mips_pic != NO_PIC)
14247 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
14248 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
14251 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
14253 /* Set MIPS ELF flags for ASEs. */
14254 if (file_ase_mips16)
14255 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
14256 #if 0 /* XXX FIXME */
14257 if (file_ase_mips3d)
14258 elf_elfheader (stdoutput)->e_flags |= ???;
14261 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
14263 /* Set the MIPS ELF ABI flags. */
14264 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
14265 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
14266 else if (mips_abi == O64_ABI)
14267 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
14268 else if (mips_abi == EABI_ABI)
14270 if (!file_mips_gp32)
14271 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
14273 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
14275 else if (mips_abi == N32_ABI)
14276 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
14278 /* Nothing to do for N64_ABI. */
14280 if (mips_32bitmode)
14281 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
14284 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
14286 typedef struct proc {
14288 unsigned long reg_mask;
14289 unsigned long reg_offset;
14290 unsigned long fpreg_mask;
14291 unsigned long fpreg_offset;
14292 unsigned long frame_offset;
14293 unsigned long frame_reg;
14294 unsigned long pc_reg;
14297 static procS cur_proc;
14298 static procS *cur_proc_ptr;
14299 static int numprocs;
14301 /* Fill in an rs_align_code fragment. */
14304 mips_handle_align (fragp)
14307 if (fragp->fr_type != rs_align_code)
14310 if (mips_opts.mips16)
14312 static const unsigned char be_nop[] = { 0x65, 0x00 };
14313 static const unsigned char le_nop[] = { 0x00, 0x65 };
14318 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
14319 p = fragp->fr_literal + fragp->fr_fix;
14327 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
14331 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
14342 /* check for premature end, nesting errors, etc */
14344 as_warn (_("missing .end at end of assembly"));
14353 if (*input_line_pointer == '-')
14355 ++input_line_pointer;
14358 if (!ISDIGIT (*input_line_pointer))
14359 as_bad (_("expected simple number"));
14360 if (input_line_pointer[0] == '0')
14362 if (input_line_pointer[1] == 'x')
14364 input_line_pointer += 2;
14365 while (ISXDIGIT (*input_line_pointer))
14368 val |= hex_value (*input_line_pointer++);
14370 return negative ? -val : val;
14374 ++input_line_pointer;
14375 while (ISDIGIT (*input_line_pointer))
14378 val |= *input_line_pointer++ - '0';
14380 return negative ? -val : val;
14383 if (!ISDIGIT (*input_line_pointer))
14385 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
14386 *input_line_pointer, *input_line_pointer);
14387 as_warn (_("invalid number"));
14390 while (ISDIGIT (*input_line_pointer))
14393 val += *input_line_pointer++ - '0';
14395 return negative ? -val : val;
14398 /* The .file directive; just like the usual .file directive, but there
14399 is an initial number which is the ECOFF file index. In the non-ECOFF
14400 case .file implies DWARF-2. */
14404 int x ATTRIBUTE_UNUSED;
14406 static int first_file_directive = 0;
14408 if (ECOFF_DEBUGGING)
14417 filename = dwarf2_directive_file (0);
14419 /* Versions of GCC up to 3.1 start files with a ".file"
14420 directive even for stabs output. Make sure that this
14421 ".file" is handled. Note that you need a version of GCC
14422 after 3.1 in order to support DWARF-2 on MIPS. */
14423 if (filename != NULL && ! first_file_directive)
14425 (void) new_logical_line (filename, -1);
14426 s_app_file_string (filename);
14428 first_file_directive = 1;
14432 /* The .loc directive, implying DWARF-2. */
14436 int x ATTRIBUTE_UNUSED;
14438 if (!ECOFF_DEBUGGING)
14439 dwarf2_directive_loc (0);
14442 /* The .end directive. */
14446 int x ATTRIBUTE_UNUSED;
14450 /* Following functions need their own .frame and .cprestore directives. */
14451 mips_frame_reg_valid = 0;
14452 mips_cprestore_valid = 0;
14454 if (!is_end_of_line[(unsigned char) *input_line_pointer])
14457 demand_empty_rest_of_line ();
14462 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14463 as_warn (_(".end not in text section"));
14467 as_warn (_(".end directive without a preceding .ent directive."));
14468 demand_empty_rest_of_line ();
14474 assert (S_GET_NAME (p));
14475 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
14476 as_warn (_(".end symbol does not match .ent symbol."));
14478 if (debug_type == DEBUG_STABS)
14479 stabs_generate_asm_endfunc (S_GET_NAME (p),
14483 as_warn (_(".end directive missing or unknown symbol"));
14486 /* Generate a .pdr section. */
14487 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14489 segT saved_seg = now_seg;
14490 subsegT saved_subseg = now_subseg;
14495 dot = frag_now_fix ();
14497 #ifdef md_flush_pending_output
14498 md_flush_pending_output ();
14502 subseg_set (pdr_seg, 0);
14504 /* Write the symbol. */
14505 exp.X_op = O_symbol;
14506 exp.X_add_symbol = p;
14507 exp.X_add_number = 0;
14508 emit_expr (&exp, 4);
14510 fragp = frag_more (7 * 4);
14512 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
14513 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
14514 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
14515 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
14516 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
14517 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
14518 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
14520 subseg_set (saved_seg, saved_subseg);
14522 #endif /* OBJ_ELF */
14524 cur_proc_ptr = NULL;
14527 /* The .aent and .ent directives. */
14535 symbolP = get_symbol ();
14536 if (*input_line_pointer == ',')
14537 ++input_line_pointer;
14538 SKIP_WHITESPACE ();
14539 if (ISDIGIT (*input_line_pointer)
14540 || *input_line_pointer == '-')
14543 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14544 as_warn (_(".ent or .aent not in text section."));
14546 if (!aent && cur_proc_ptr)
14547 as_warn (_("missing .end"));
14551 /* This function needs its own .frame and .cprestore directives. */
14552 mips_frame_reg_valid = 0;
14553 mips_cprestore_valid = 0;
14555 cur_proc_ptr = &cur_proc;
14556 memset (cur_proc_ptr, '\0', sizeof (procS));
14558 cur_proc_ptr->isym = symbolP;
14560 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
14564 if (debug_type == DEBUG_STABS)
14565 stabs_generate_asm_func (S_GET_NAME (symbolP),
14566 S_GET_NAME (symbolP));
14569 demand_empty_rest_of_line ();
14572 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
14573 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
14574 s_mips_frame is used so that we can set the PDR information correctly.
14575 We can't use the ecoff routines because they make reference to the ecoff
14576 symbol table (in the mdebug section). */
14579 s_mips_frame (ignore)
14580 int ignore ATTRIBUTE_UNUSED;
14583 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14587 if (cur_proc_ptr == (procS *) NULL)
14589 as_warn (_(".frame outside of .ent"));
14590 demand_empty_rest_of_line ();
14594 cur_proc_ptr->frame_reg = tc_get_register (1);
14596 SKIP_WHITESPACE ();
14597 if (*input_line_pointer++ != ','
14598 || get_absolute_expression_and_terminator (&val) != ',')
14600 as_warn (_("Bad .frame directive"));
14601 --input_line_pointer;
14602 demand_empty_rest_of_line ();
14606 cur_proc_ptr->frame_offset = val;
14607 cur_proc_ptr->pc_reg = tc_get_register (0);
14609 demand_empty_rest_of_line ();
14612 #endif /* OBJ_ELF */
14616 /* The .fmask and .mask directives. If the mdebug section is present
14617 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14618 embedded targets, s_mips_mask is used so that we can set the PDR
14619 information correctly. We can't use the ecoff routines because they
14620 make reference to the ecoff symbol table (in the mdebug section). */
14623 s_mips_mask (reg_type)
14627 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14631 if (cur_proc_ptr == (procS *) NULL)
14633 as_warn (_(".mask/.fmask outside of .ent"));
14634 demand_empty_rest_of_line ();
14638 if (get_absolute_expression_and_terminator (&mask) != ',')
14640 as_warn (_("Bad .mask/.fmask directive"));
14641 --input_line_pointer;
14642 demand_empty_rest_of_line ();
14646 off = get_absolute_expression ();
14648 if (reg_type == 'F')
14650 cur_proc_ptr->fpreg_mask = mask;
14651 cur_proc_ptr->fpreg_offset = off;
14655 cur_proc_ptr->reg_mask = mask;
14656 cur_proc_ptr->reg_offset = off;
14659 demand_empty_rest_of_line ();
14662 #endif /* OBJ_ELF */
14663 s_ignore (reg_type);
14666 /* The .loc directive. */
14677 assert (now_seg == text_section);
14679 lineno = get_number ();
14680 addroff = frag_now_fix ();
14682 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
14683 S_SET_TYPE (symbolP, N_SLINE);
14684 S_SET_OTHER (symbolP, 0);
14685 S_SET_DESC (symbolP, lineno);
14686 symbolP->sy_segment = now_seg;
14690 /* A table describing all the processors gas knows about. Names are
14691 matched in the order listed.
14693 To ease comparison, please keep this table in the same order as
14694 gcc's mips_cpu_info_table[]. */
14695 static const struct mips_cpu_info mips_cpu_info_table[] =
14697 /* Entries for generic ISAs */
14698 { "mips1", 1, ISA_MIPS1, CPU_R3000 },
14699 { "mips2", 1, ISA_MIPS2, CPU_R6000 },
14700 { "mips3", 1, ISA_MIPS3, CPU_R4000 },
14701 { "mips4", 1, ISA_MIPS4, CPU_R8000 },
14702 { "mips5", 1, ISA_MIPS5, CPU_MIPS5 },
14703 { "mips32", 1, ISA_MIPS32, CPU_MIPS32 },
14704 { "mips32r2", 1, ISA_MIPS32R2, CPU_MIPS32R2 },
14705 { "mips64", 1, ISA_MIPS64, CPU_MIPS64 },
14708 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
14709 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
14710 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
14713 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
14716 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
14717 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
14718 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
14719 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
14720 { "vr4120", 0, ISA_MIPS3, CPU_VR4120 },
14721 { "vr4130", 0, ISA_MIPS3, CPU_VR4120 },
14722 { "vr4181", 0, ISA_MIPS3, CPU_R4111 },
14723 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
14724 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
14725 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
14726 { "orion", 0, ISA_MIPS3, CPU_R4600 },
14727 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
14730 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
14731 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
14732 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
14733 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
14734 { "vr5400", 0, ISA_MIPS4, CPU_VR5400 },
14735 { "vr5500", 0, ISA_MIPS4, CPU_VR5500 },
14736 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
14737 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
14738 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
14739 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
14740 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
14741 { "r7000", 0, ISA_MIPS4, CPU_R5000 },
14744 { "4kc", 0, ISA_MIPS32, CPU_MIPS32, },
14745 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
14746 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
14749 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
14750 { "20kc", 0, ISA_MIPS64, CPU_MIPS64 },
14752 /* Broadcom SB-1 CPU core */
14753 { "sb1", 0, ISA_MIPS64, CPU_SB1 },
14760 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14761 with a final "000" replaced by "k". Ignore case.
14763 Note: this function is shared between GCC and GAS. */
14766 mips_strict_matching_cpu_name_p (canonical, given)
14767 const char *canonical, *given;
14769 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
14770 given++, canonical++;
14772 return ((*given == 0 && *canonical == 0)
14773 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
14777 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14778 CPU name. We've traditionally allowed a lot of variation here.
14780 Note: this function is shared between GCC and GAS. */
14783 mips_matching_cpu_name_p (canonical, given)
14784 const char *canonical, *given;
14786 /* First see if the name matches exactly, or with a final "000"
14787 turned into "k". */
14788 if (mips_strict_matching_cpu_name_p (canonical, given))
14791 /* If not, try comparing based on numerical designation alone.
14792 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14793 if (TOLOWER (*given) == 'r')
14795 if (!ISDIGIT (*given))
14798 /* Skip over some well-known prefixes in the canonical name,
14799 hoping to find a number there too. */
14800 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
14802 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
14804 else if (TOLOWER (canonical[0]) == 'r')
14807 return mips_strict_matching_cpu_name_p (canonical, given);
14811 /* Parse an option that takes the name of a processor as its argument.
14812 OPTION is the name of the option and CPU_STRING is the argument.
14813 Return the corresponding processor enumeration if the CPU_STRING is
14814 recognized, otherwise report an error and return null.
14816 A similar function exists in GCC. */
14818 static const struct mips_cpu_info *
14819 mips_parse_cpu (option, cpu_string)
14820 const char *option, *cpu_string;
14822 const struct mips_cpu_info *p;
14824 /* 'from-abi' selects the most compatible architecture for the given
14825 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14826 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14827 version. Look first at the -mgp options, if given, otherwise base
14828 the choice on MIPS_DEFAULT_64BIT.
14830 Treat NO_ABI like the EABIs. One reason to do this is that the
14831 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14832 architecture. This code picks MIPS I for 'mips' and MIPS III for
14833 'mips64', just as we did in the days before 'from-abi'. */
14834 if (strcasecmp (cpu_string, "from-abi") == 0)
14836 if (ABI_NEEDS_32BIT_REGS (mips_abi))
14837 return mips_cpu_info_from_isa (ISA_MIPS1);
14839 if (ABI_NEEDS_64BIT_REGS (mips_abi))
14840 return mips_cpu_info_from_isa (ISA_MIPS3);
14842 if (file_mips_gp32 >= 0)
14843 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
14845 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14850 /* 'default' has traditionally been a no-op. Probably not very useful. */
14851 if (strcasecmp (cpu_string, "default") == 0)
14854 for (p = mips_cpu_info_table; p->name != 0; p++)
14855 if (mips_matching_cpu_name_p (p->name, cpu_string))
14858 as_bad ("Bad value (%s) for %s", cpu_string, option);
14862 /* Return the canonical processor information for ISA (a member of the
14863 ISA_MIPS* enumeration). */
14865 static const struct mips_cpu_info *
14866 mips_cpu_info_from_isa (isa)
14871 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14872 if (mips_cpu_info_table[i].is_isa
14873 && isa == mips_cpu_info_table[i].isa)
14874 return (&mips_cpu_info_table[i]);
14880 show (stream, string, col_p, first_p)
14882 const char *string;
14888 fprintf (stream, "%24s", "");
14893 fprintf (stream, ", ");
14897 if (*col_p + strlen (string) > 72)
14899 fprintf (stream, "\n%24s", "");
14903 fprintf (stream, "%s", string);
14904 *col_p += strlen (string);
14910 md_show_usage (stream)
14916 fprintf (stream, _("\
14918 -membedded-pic generate embedded position independent code\n\
14919 -EB generate big endian output\n\
14920 -EL generate little endian output\n\
14921 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14922 -G NUM allow referencing objects up to NUM bytes\n\
14923 implicitly with the gp register [default 8]\n"));
14924 fprintf (stream, _("\
14925 -mips1 generate MIPS ISA I instructions\n\
14926 -mips2 generate MIPS ISA II instructions\n\
14927 -mips3 generate MIPS ISA III instructions\n\
14928 -mips4 generate MIPS ISA IV instructions\n\
14929 -mips5 generate MIPS ISA V instructions\n\
14930 -mips32 generate MIPS32 ISA instructions\n\
14931 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
14932 -mips64 generate MIPS64 ISA instructions\n\
14933 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14937 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14938 show (stream, mips_cpu_info_table[i].name, &column, &first);
14939 show (stream, "from-abi", &column, &first);
14940 fputc ('\n', stream);
14942 fprintf (stream, _("\
14943 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14944 -no-mCPU don't generate code specific to CPU.\n\
14945 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14949 show (stream, "3900", &column, &first);
14950 show (stream, "4010", &column, &first);
14951 show (stream, "4100", &column, &first);
14952 show (stream, "4650", &column, &first);
14953 fputc ('\n', stream);
14955 fprintf (stream, _("\
14956 -mips16 generate mips16 instructions\n\
14957 -no-mips16 do not generate mips16 instructions\n"));
14958 fprintf (stream, _("\
14959 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14960 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14961 -O0 remove unneeded NOPs, do not swap branches\n\
14962 -O remove unneeded NOPs and swap branches\n\
14963 -n warn about NOPs generated from macros\n\
14964 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14965 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14966 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14968 fprintf (stream, _("\
14969 -KPIC, -call_shared generate SVR4 position independent code\n\
14970 -non_shared do not generate position independent code\n\
14971 -xgot assume a 32 bit GOT\n\
14972 -mabi=ABI create ABI conformant object file for:\n"));
14976 show (stream, "32", &column, &first);
14977 show (stream, "o64", &column, &first);
14978 show (stream, "n32", &column, &first);
14979 show (stream, "64", &column, &first);
14980 show (stream, "eabi", &column, &first);
14982 fputc ('\n', stream);
14984 fprintf (stream, _("\
14985 -32 create o32 ABI object file (default)\n\
14986 -n32 create n32 ABI object file\n\
14987 -64 create 64 ABI object file\n"));
14992 mips_dwarf2_format ()
14994 if (mips_abi == N64_ABI)
14997 return dwarf2_format_64bit_irix;
14999 return dwarf2_format_64bit;
15003 return dwarf2_format_32bit;