1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by the OSF and Ralph Campbell.
5 Written by Keith Knowles and Ralph Campbell, working independently.
6 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
9 This file is part of GAS.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include "safe-ctype.h"
33 #include "opcode/mips.h"
35 #include "dwarf2dbg.h"
38 #define DBG(x) printf x
44 /* Clean up namespace so we can include obj-elf.h too. */
45 static int mips_output_flavor (void);
46 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
47 #undef OBJ_PROCESS_STAB
54 #undef obj_frob_file_after_relocs
55 #undef obj_frob_symbol
57 #undef obj_sec_sym_ok_for_reloc
58 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
61 /* Fix any of them that we actually care about. */
63 #define OUTPUT_FLAVOR mips_output_flavor()
70 #ifndef ECOFF_DEBUGGING
71 #define NO_ECOFF_DEBUGGING
72 #define ECOFF_DEBUGGING 0
75 int mips_flag_mdebug = -1;
77 /* Control generation of .pdr sections. Off by default on IRIX: the native
78 linker doesn't know about and discards them, but relocations against them
79 remain, leading to rld crashes. */
81 int mips_flag_pdr = FALSE;
83 int mips_flag_pdr = TRUE;
88 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
89 static char *mips_regmask_frag;
95 #define PIC_CALL_REG 25
103 #define ILLEGAL_REG (32)
105 /* Allow override of standard little-endian ECOFF format. */
107 #ifndef ECOFF_LITTLE_FORMAT
108 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
111 extern int target_big_endian;
113 /* The name of the readonly data section. */
114 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
116 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
118 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
120 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
124 /* The ABI to use. */
135 /* MIPS ABI we are using for this output file. */
136 static enum mips_abi_level mips_abi = NO_ABI;
138 /* Whether or not we have code that can call pic code. */
139 int mips_abicalls = FALSE;
141 /* This is the set of options which may be modified by the .set
142 pseudo-op. We use a struct so that .set push and .set pop are more
145 struct mips_set_options
147 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
148 if it has not been initialized. Changed by `.set mipsN', and the
149 -mipsN command line option, and the default CPU. */
151 /* Enabled Application Specific Extensions (ASEs). These are set to -1
152 if they have not been initialized. Changed by `.set <asename>', by
153 command line options, and based on the default architecture. */
156 /* Whether we are assembling for the mips16 processor. 0 if we are
157 not, 1 if we are, and -1 if the value has not been initialized.
158 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
159 -nomips16 command line options, and the default CPU. */
161 /* Non-zero if we should not reorder instructions. Changed by `.set
162 reorder' and `.set noreorder'. */
164 /* Non-zero if we should not permit the $at ($1) register to be used
165 in instructions. Changed by `.set at' and `.set noat'. */
167 /* Non-zero if we should warn when a macro instruction expands into
168 more than one machine instruction. Changed by `.set nomacro' and
170 int warn_about_macros;
171 /* Non-zero if we should not move instructions. Changed by `.set
172 move', `.set volatile', `.set nomove', and `.set novolatile'. */
174 /* Non-zero if we should not optimize branches by moving the target
175 of the branch into the delay slot. Actually, we don't perform
176 this optimization anyhow. Changed by `.set bopt' and `.set
179 /* Non-zero if we should not autoextend mips16 instructions.
180 Changed by `.set autoextend' and `.set noautoextend'. */
182 /* Restrict general purpose registers and floating point registers
183 to 32 bit. This is initially determined when -mgp32 or -mfp32
184 is passed but can changed if the assembler code uses .set mipsN. */
187 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
188 command line option, and the default CPU. */
192 /* True if -mgp32 was passed. */
193 static int file_mips_gp32 = -1;
195 /* True if -mfp32 was passed. */
196 static int file_mips_fp32 = -1;
198 /* This is the struct we use to hold the current set of options. Note
199 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
200 -1 to indicate that they have not been initialized. */
202 static struct mips_set_options mips_opts =
204 ISA_UNKNOWN, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, CPU_UNKNOWN
207 /* These variables are filled in with the masks of registers used.
208 The object format code reads them and puts them in the appropriate
210 unsigned long mips_gprmask;
211 unsigned long mips_cprmask[4];
213 /* MIPS ISA we are using for this output file. */
214 static int file_mips_isa = ISA_UNKNOWN;
216 /* True if -mips16 was passed or implied by arguments passed on the
217 command line (e.g., by -march). */
218 static int file_ase_mips16;
220 /* True if -mips3d was passed or implied by arguments passed on the
221 command line (e.g., by -march). */
222 static int file_ase_mips3d;
224 /* True if -mdmx was passed or implied by arguments passed on the
225 command line (e.g., by -march). */
226 static int file_ase_mdmx;
228 /* The argument of the -march= flag. The architecture we are assembling. */
229 static int file_mips_arch = CPU_UNKNOWN;
230 static const char *mips_arch_string;
232 /* The argument of the -mtune= flag. The architecture for which we
234 static int mips_tune = CPU_UNKNOWN;
235 static const char *mips_tune_string;
237 /* True when generating 32-bit code for a 64-bit processor. */
238 static int mips_32bitmode = 0;
240 /* Some ISA's have delay slots for instructions which read or write
241 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
242 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
243 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
244 delay slot in this ISA. The uses of this macro assume that any
245 ISA that has delay slots for one of these, has them for all. They
246 also assume that ISAs which don't have delays for these insns, don't
247 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
248 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
250 || (ISA) == ISA_MIPS2 \
251 || (ISA) == ISA_MIPS3 \
254 /* True if the given ABI requires 32-bit registers. */
255 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
257 /* Likewise 64-bit registers. */
258 #define ABI_NEEDS_64BIT_REGS(ABI) \
260 || (ABI) == N64_ABI \
263 /* Return true if ISA supports 64 bit gp register instructions. */
264 #define ISA_HAS_64BIT_REGS(ISA) ( \
266 || (ISA) == ISA_MIPS4 \
267 || (ISA) == ISA_MIPS5 \
268 || (ISA) == ISA_MIPS64 \
269 || (ISA) == ISA_MIPS64R2 \
272 /* Return true if ISA supports 64-bit right rotate (dror et al.)
274 #define ISA_HAS_DROR(ISA) ( \
275 (ISA) == ISA_MIPS64R2 \
278 /* Return true if ISA supports 32-bit right rotate (ror et al.)
280 #define ISA_HAS_ROR(ISA) ( \
281 (ISA) == ISA_MIPS32R2 \
282 || (ISA) == ISA_MIPS64R2 \
285 #define HAVE_32BIT_GPRS \
286 (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
288 #define HAVE_32BIT_FPRS \
289 (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
291 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
292 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
294 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
296 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
298 /* We can only have 64bit addresses if the object file format
300 #define HAVE_32BIT_ADDRESSES \
302 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
303 || ! HAVE_64BIT_OBJECTS) \
304 && mips_pic != EMBEDDED_PIC))
306 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
308 /* Addresses are loaded in different ways, depending on the address size
309 in use. The n32 ABI Documentation also mandates the use of additions
310 with overflow checking, but existing implementations don't follow it. */
311 #define ADDRESS_ADD_INSN \
312 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
314 #define ADDRESS_ADDI_INSN \
315 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
317 #define ADDRESS_LOAD_INSN \
318 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
320 #define ADDRESS_STORE_INSN \
321 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
323 /* Return true if the given CPU supports the MIPS16 ASE. */
324 #define CPU_HAS_MIPS16(cpu) \
325 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
326 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
328 /* Return true if the given CPU supports the MIPS3D ASE. */
329 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
332 /* Return true if the given CPU supports the MDMX ASE. */
333 #define CPU_HAS_MDMX(cpu) (FALSE \
336 /* True if CPU has a dror instruction. */
337 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
339 /* True if CPU has a ror instruction. */
340 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
342 /* Whether the processor uses hardware interlocks to protect
343 reads from the HI and LO registers, and thus does not
344 require nops to be inserted. */
346 #define hilo_interlocks (mips_opts.arch == CPU_R4010 \
347 || mips_opts.arch == CPU_VR5500 \
348 || mips_opts.arch == CPU_RM7000 \
349 || mips_opts.arch == CPU_SB1 \
352 /* Whether the processor uses hardware interlocks to protect reads
353 from the GPRs, and thus does not require nops to be inserted. */
354 #define gpr_interlocks \
355 (mips_opts.isa != ISA_MIPS1 \
356 || mips_opts.arch == CPU_VR5400 \
357 || mips_opts.arch == CPU_VR5500 \
358 || mips_opts.arch == CPU_R3900)
360 /* As with other "interlocks" this is used by hardware that has FP
361 (co-processor) interlocks. */
362 /* Itbl support may require additional care here. */
363 #define cop_interlocks (mips_opts.arch == CPU_R4300 \
364 || mips_opts.arch == CPU_VR5400 \
365 || mips_opts.arch == CPU_VR5500 \
366 || mips_opts.arch == CPU_SB1 \
369 /* Is this a mfhi or mflo instruction? */
370 #define MF_HILO_INSN(PINFO) \
371 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
373 /* MIPS PIC level. */
375 enum mips_pic_level mips_pic;
377 /* Warn about all NOPS that the assembler generates. */
378 static int warn_nops = 0;
380 /* 1 if we should generate 32 bit offsets from the $gp register in
381 SVR4_PIC mode. Currently has no meaning in other modes. */
382 static int mips_big_got = 0;
384 /* 1 if trap instructions should used for overflow rather than break
386 static int mips_trap = 0;
388 /* 1 if double width floating point constants should not be constructed
389 by assembling two single width halves into two single width floating
390 point registers which just happen to alias the double width destination
391 register. On some architectures this aliasing can be disabled by a bit
392 in the status register, and the setting of this bit cannot be determined
393 automatically at assemble time. */
394 static int mips_disable_float_construction;
396 /* Non-zero if any .set noreorder directives were used. */
398 static int mips_any_noreorder;
400 /* Non-zero if nops should be inserted when the register referenced in
401 an mfhi/mflo instruction is read in the next two instructions. */
402 static int mips_7000_hilo_fix;
404 /* The size of the small data section. */
405 static unsigned int g_switch_value = 8;
406 /* Whether the -G option was used. */
407 static int g_switch_seen = 0;
412 /* If we can determine in advance that GP optimization won't be
413 possible, we can skip the relaxation stuff that tries to produce
414 GP-relative references. This makes delay slot optimization work
417 This function can only provide a guess, but it seems to work for
418 gcc output. It needs to guess right for gcc, otherwise gcc
419 will put what it thinks is a GP-relative instruction in a branch
422 I don't know if a fix is needed for the SVR4_PIC mode. I've only
423 fixed it for the non-PIC mode. KR 95/04/07 */
424 static int nopic_need_relax (symbolS *, int);
426 /* handle of the OPCODE hash table */
427 static struct hash_control *op_hash = NULL;
429 /* The opcode hash table we use for the mips16. */
430 static struct hash_control *mips16_op_hash = NULL;
432 /* This array holds the chars that always start a comment. If the
433 pre-processor is disabled, these aren't very useful */
434 const char comment_chars[] = "#";
436 /* This array holds the chars that only start a comment at the beginning of
437 a line. If the line seems to have the form '# 123 filename'
438 .line and .file directives will appear in the pre-processed output */
439 /* Note that input_file.c hand checks for '#' at the beginning of the
440 first line of the input file. This is because the compiler outputs
441 #NO_APP at the beginning of its output. */
442 /* Also note that C style comments are always supported. */
443 const char line_comment_chars[] = "#";
445 /* This array holds machine specific line separator characters. */
446 const char line_separator_chars[] = ";";
448 /* Chars that can be used to separate mant from exp in floating point nums */
449 const char EXP_CHARS[] = "eE";
451 /* Chars that mean this number is a floating point constant */
454 const char FLT_CHARS[] = "rRsSfFdDxXpP";
456 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
457 changed in read.c . Ideally it shouldn't have to know about it at all,
458 but nothing is ideal around here.
461 static char *insn_error;
463 static int auto_align = 1;
465 /* When outputting SVR4 PIC code, the assembler needs to know the
466 offset in the stack frame from which to restore the $gp register.
467 This is set by the .cprestore pseudo-op, and saved in this
469 static offsetT mips_cprestore_offset = -1;
471 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
472 more optimizations, it can use a register value instead of a memory-saved
473 offset and even an other register than $gp as global pointer. */
474 static offsetT mips_cpreturn_offset = -1;
475 static int mips_cpreturn_register = -1;
476 static int mips_gp_register = GP;
477 static int mips_gprel_offset = 0;
479 /* Whether mips_cprestore_offset has been set in the current function
480 (or whether it has already been warned about, if not). */
481 static int mips_cprestore_valid = 0;
483 /* This is the register which holds the stack frame, as set by the
484 .frame pseudo-op. This is needed to implement .cprestore. */
485 static int mips_frame_reg = SP;
487 /* Whether mips_frame_reg has been set in the current function
488 (or whether it has already been warned about, if not). */
489 static int mips_frame_reg_valid = 0;
491 /* To output NOP instructions correctly, we need to keep information
492 about the previous two instructions. */
494 /* Whether we are optimizing. The default value of 2 means to remove
495 unneeded NOPs and swap branch instructions when possible. A value
496 of 1 means to not swap branches. A value of 0 means to always
498 static int mips_optimize = 2;
500 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
501 equivalent to seeing no -g option at all. */
502 static int mips_debug = 0;
504 /* The previous instruction. */
505 static struct mips_cl_insn prev_insn;
507 /* The instruction before prev_insn. */
508 static struct mips_cl_insn prev_prev_insn;
510 /* If we don't want information for prev_insn or prev_prev_insn, we
511 point the insn_mo field at this dummy integer. */
512 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
514 /* Non-zero if prev_insn is valid. */
515 static int prev_insn_valid;
517 /* The frag for the previous instruction. */
518 static struct frag *prev_insn_frag;
520 /* The offset into prev_insn_frag for the previous instruction. */
521 static long prev_insn_where;
523 /* The reloc type for the previous instruction, if any. */
524 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
526 /* The reloc for the previous instruction, if any. */
527 static fixS *prev_insn_fixp[3];
529 /* Non-zero if the previous instruction was in a delay slot. */
530 static int prev_insn_is_delay_slot;
532 /* Non-zero if the previous instruction was in a .set noreorder. */
533 static int prev_insn_unreordered;
535 /* Non-zero if the previous instruction uses an extend opcode (if
537 static int prev_insn_extended;
539 /* Non-zero if the previous previous instruction was in a .set
541 static int prev_prev_insn_unreordered;
543 /* If this is set, it points to a frag holding nop instructions which
544 were inserted before the start of a noreorder section. If those
545 nops turn out to be unnecessary, the size of the frag can be
547 static fragS *prev_nop_frag;
549 /* The number of nop instructions we created in prev_nop_frag. */
550 static int prev_nop_frag_holds;
552 /* The number of nop instructions that we know we need in
554 static int prev_nop_frag_required;
556 /* The number of instructions we've seen since prev_nop_frag. */
557 static int prev_nop_frag_since;
559 /* For ECOFF and ELF, relocations against symbols are done in two
560 parts, with a HI relocation and a LO relocation. Each relocation
561 has only 16 bits of space to store an addend. This means that in
562 order for the linker to handle carries correctly, it must be able
563 to locate both the HI and the LO relocation. This means that the
564 relocations must appear in order in the relocation table.
566 In order to implement this, we keep track of each unmatched HI
567 relocation. We then sort them so that they immediately precede the
568 corresponding LO relocation. */
573 struct mips_hi_fixup *next;
576 /* The section this fixup is in. */
580 /* The list of unmatched HI relocs. */
582 static struct mips_hi_fixup *mips_hi_fixup_list;
584 /* The frag containing the last explicit relocation operator.
585 Null if explicit relocations have not been used. */
587 static fragS *prev_reloc_op_frag;
589 /* Map normal MIPS register numbers to mips16 register numbers. */
591 #define X ILLEGAL_REG
592 static const int mips32_to_16_reg_map[] =
594 X, X, 2, 3, 4, 5, 6, 7,
595 X, X, X, X, X, X, X, X,
596 0, 1, X, X, X, X, X, X,
597 X, X, X, X, X, X, X, X
601 /* Map mips16 register numbers to normal MIPS register numbers. */
603 static const unsigned int mips16_to_32_reg_map[] =
605 16, 17, 2, 3, 4, 5, 6, 7
608 static int mips_fix_4122_bugs;
610 /* We don't relax branches by default, since this causes us to expand
611 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
612 fail to compute the offset before expanding the macro to the most
613 efficient expansion. */
615 static int mips_relax_branch;
617 /* Since the MIPS does not have multiple forms of PC relative
618 instructions, we do not have to do relaxing as is done on other
619 platforms. However, we do have to handle GP relative addressing
620 correctly, which turns out to be a similar problem.
622 Every macro that refers to a symbol can occur in (at least) two
623 forms, one with GP relative addressing and one without. For
624 example, loading a global variable into a register generally uses
625 a macro instruction like this:
627 If i can be addressed off the GP register (this is true if it is in
628 the .sbss or .sdata section, or if it is known to be smaller than
629 the -G argument) this will generate the following instruction:
631 This instruction will use a GPREL reloc. If i can not be addressed
632 off the GP register, the following instruction sequence will be used:
635 In this case the first instruction will have a HI16 reloc, and the
636 second reloc will have a LO16 reloc. Both relocs will be against
639 The issue here is that we may not know whether i is GP addressable
640 until after we see the instruction that uses it. Therefore, we
641 want to be able to choose the final instruction sequence only at
642 the end of the assembly. This is similar to the way other
643 platforms choose the size of a PC relative instruction only at the
646 When generating position independent code we do not use GP
647 addressing in quite the same way, but the issue still arises as
648 external symbols and local symbols must be handled differently.
650 We handle these issues by actually generating both possible
651 instruction sequences. The longer one is put in a frag_var with
652 type rs_machine_dependent. We encode what to do with the frag in
653 the subtype field. We encode (1) the number of existing bytes to
654 replace, (2) the number of new bytes to use, (3) the offset from
655 the start of the existing bytes to the first reloc we must generate
656 (that is, the offset is applied from the start of the existing
657 bytes after they are replaced by the new bytes, if any), (4) the
658 offset from the start of the existing bytes to the second reloc,
659 (5) whether a third reloc is needed (the third reloc is always four
660 bytes after the second reloc), and (6) whether to warn if this
661 variant is used (this is sometimes needed if .set nomacro or .set
662 noat is in effect). All these numbers are reasonably small.
664 Generating two instruction sequences must be handled carefully to
665 ensure that delay slots are handled correctly. Fortunately, there
666 are a limited number of cases. When the second instruction
667 sequence is generated, append_insn is directed to maintain the
668 existing delay slot information, so it continues to apply to any
669 code after the second instruction sequence. This means that the
670 second instruction sequence must not impose any requirements not
671 required by the first instruction sequence.
673 These variant frags are then handled in functions called by the
674 machine independent code. md_estimate_size_before_relax returns
675 the final size of the frag. md_convert_frag sets up the final form
676 of the frag. tc_gen_reloc adjust the first reloc and adds a second
678 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
682 | (((reloc1) + 64) << 9) \
683 | (((reloc2) + 64) << 2) \
684 | ((reloc3) ? (1 << 1) : 0) \
686 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
687 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
688 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
689 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
690 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
691 #define RELAX_WARN(i) ((i) & 1)
693 /* Branch without likely bit. If label is out of range, we turn:
695 beq reg1, reg2, label
705 with the following opcode replacements:
712 bltzal <-> bgezal (with jal label instead of j label)
714 Even though keeping the delay slot instruction in the delay slot of
715 the branch would be more efficient, it would be very tricky to do
716 correctly, because we'd have to introduce a variable frag *after*
717 the delay slot instruction, and expand that instead. Let's do it
718 the easy way for now, even if the branch-not-taken case now costs
719 one additional instruction. Out-of-range branches are not supposed
720 to be common, anyway.
722 Branch likely. If label is out of range, we turn:
724 beql reg1, reg2, label
725 delay slot (annulled if branch not taken)
734 delay slot (executed only if branch taken)
737 It would be possible to generate a shorter sequence by losing the
738 likely bit, generating something like:
743 delay slot (executed only if branch taken)
755 bltzall -> bgezal (with jal label instead of j label)
756 bgezall -> bltzal (ditto)
759 but it's not clear that it would actually improve performance. */
760 #define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
763 | ((toofar) ? 1 : 0) \
765 | ((likely) ? 4 : 0) \
766 | ((uncond) ? 8 : 0)))
767 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
768 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
769 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
770 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
771 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1) != 0)
773 /* For mips16 code, we use an entirely different form of relaxation.
774 mips16 supports two versions of most instructions which take
775 immediate values: a small one which takes some small value, and a
776 larger one which takes a 16 bit value. Since branches also follow
777 this pattern, relaxing these values is required.
779 We can assemble both mips16 and normal MIPS code in a single
780 object. Therefore, we need to support this type of relaxation at
781 the same time that we support the relaxation described above. We
782 use the high bit of the subtype field to distinguish these cases.
784 The information we store for this type of relaxation is the
785 argument code found in the opcode file for this relocation, whether
786 the user explicitly requested a small or extended form, and whether
787 the relocation is in a jump or jal delay slot. That tells us the
788 size of the value, and how it should be stored. We also store
789 whether the fragment is considered to be extended or not. We also
790 store whether this is known to be a branch to a different section,
791 whether we have tried to relax this frag yet, and whether we have
792 ever extended a PC relative fragment because of a shift count. */
793 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
796 | ((small) ? 0x100 : 0) \
797 | ((ext) ? 0x200 : 0) \
798 | ((dslot) ? 0x400 : 0) \
799 | ((jal_dslot) ? 0x800 : 0))
800 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
801 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
802 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
803 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
804 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
805 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
806 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
807 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
808 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
809 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
810 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
811 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
813 /* Is the given value a sign-extended 32-bit value? */
814 #define IS_SEXT_32BIT_NUM(x) \
815 (((x) &~ (offsetT) 0x7fffffff) == 0 \
816 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
818 /* Is the given value a sign-extended 16-bit value? */
819 #define IS_SEXT_16BIT_NUM(x) \
820 (((x) &~ (offsetT) 0x7fff) == 0 \
821 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
824 /* Prototypes for static functions. */
826 #define internalError() \
827 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
829 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
831 static void append_insn
832 (char *place, struct mips_cl_insn *ip, expressionS *p,
833 bfd_reloc_code_real_type *r);
834 static void mips_no_prev_insn (int);
835 static void mips16_macro_build
836 (char *, int *, expressionS *, const char *, const char *, va_list);
837 static void load_register (int *, int, expressionS *, int);
838 static void macro (struct mips_cl_insn * ip);
839 static void mips16_macro (struct mips_cl_insn * ip);
840 #ifdef LOSING_COMPILER
841 static void macro2 (struct mips_cl_insn * ip);
843 static void mips_ip (char *str, struct mips_cl_insn * ip);
844 static void mips16_ip (char *str, struct mips_cl_insn * ip);
845 static void mips16_immed
846 (char *, unsigned int, int, offsetT, bfd_boolean, bfd_boolean, bfd_boolean,
847 unsigned long *, bfd_boolean *, unsigned short *);
848 static size_t my_getSmallExpression
849 (expressionS *, bfd_reloc_code_real_type *, char *);
850 static void my_getExpression (expressionS *, char *);
851 static void s_align (int);
852 static void s_change_sec (int);
853 static void s_change_section (int);
854 static void s_cons (int);
855 static void s_float_cons (int);
856 static void s_mips_globl (int);
857 static void s_option (int);
858 static void s_mipsset (int);
859 static void s_abicalls (int);
860 static void s_cpload (int);
861 static void s_cpsetup (int);
862 static void s_cplocal (int);
863 static void s_cprestore (int);
864 static void s_cpreturn (int);
865 static void s_gpvalue (int);
866 static void s_gpword (int);
867 static void s_gpdword (int);
868 static void s_cpadd (int);
869 static void s_insn (int);
870 static void md_obj_begin (void);
871 static void md_obj_end (void);
872 static void s_mips_ent (int);
873 static void s_mips_end (int);
874 static void s_mips_frame (int);
875 static void s_mips_mask (int reg_type);
876 static void s_mips_stab (int);
877 static void s_mips_weakext (int);
878 static void s_mips_file (int);
879 static void s_mips_loc (int);
880 static bfd_boolean pic_need_relax (symbolS *, asection *);
881 static int relaxed_branch_length (fragS *, asection *, int);
882 static int validate_mips_insn (const struct mips_opcode *);
884 /* Table and functions used to map between CPU/ISA names, and
885 ISA levels, and CPU numbers. */
889 const char *name; /* CPU or ISA name. */
890 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
891 int isa; /* ISA level. */
892 int cpu; /* CPU number (default CPU if ISA). */
895 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
896 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
897 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
901 The following pseudo-ops from the Kane and Heinrich MIPS book
902 should be defined here, but are currently unsupported: .alias,
903 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
905 The following pseudo-ops from the Kane and Heinrich MIPS book are
906 specific to the type of debugging information being generated, and
907 should be defined by the object format: .aent, .begin, .bend,
908 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
911 The following pseudo-ops from the Kane and Heinrich MIPS book are
912 not MIPS CPU specific, but are also not specific to the object file
913 format. This file is probably the best place to define them, but
914 they are not currently supported: .asm0, .endr, .lab, .repeat,
917 static const pseudo_typeS mips_pseudo_table[] =
919 /* MIPS specific pseudo-ops. */
920 {"option", s_option, 0},
921 {"set", s_mipsset, 0},
922 {"rdata", s_change_sec, 'r'},
923 {"sdata", s_change_sec, 's'},
924 {"livereg", s_ignore, 0},
925 {"abicalls", s_abicalls, 0},
926 {"cpload", s_cpload, 0},
927 {"cpsetup", s_cpsetup, 0},
928 {"cplocal", s_cplocal, 0},
929 {"cprestore", s_cprestore, 0},
930 {"cpreturn", s_cpreturn, 0},
931 {"gpvalue", s_gpvalue, 0},
932 {"gpword", s_gpword, 0},
933 {"gpdword", s_gpdword, 0},
934 {"cpadd", s_cpadd, 0},
937 /* Relatively generic pseudo-ops that happen to be used on MIPS
939 {"asciiz", stringer, 1},
940 {"bss", s_change_sec, 'b'},
943 {"dword", s_cons, 3},
944 {"weakext", s_mips_weakext, 0},
946 /* These pseudo-ops are defined in read.c, but must be overridden
947 here for one reason or another. */
948 {"align", s_align, 0},
950 {"data", s_change_sec, 'd'},
951 {"double", s_float_cons, 'd'},
952 {"float", s_float_cons, 'f'},
953 {"globl", s_mips_globl, 0},
954 {"global", s_mips_globl, 0},
955 {"hword", s_cons, 1},
960 {"section", s_change_section, 0},
961 {"short", s_cons, 1},
962 {"single", s_float_cons, 'f'},
963 {"stabn", s_mips_stab, 'n'},
964 {"text", s_change_sec, 't'},
967 { "extern", ecoff_directive_extern, 0},
972 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
974 /* These pseudo-ops should be defined by the object file format.
975 However, a.out doesn't support them, so we have versions here. */
976 {"aent", s_mips_ent, 1},
977 {"bgnb", s_ignore, 0},
978 {"end", s_mips_end, 0},
979 {"endb", s_ignore, 0},
980 {"ent", s_mips_ent, 0},
981 {"file", s_mips_file, 0},
982 {"fmask", s_mips_mask, 'F'},
983 {"frame", s_mips_frame, 0},
984 {"loc", s_mips_loc, 0},
985 {"mask", s_mips_mask, 'R'},
986 {"verstamp", s_ignore, 0},
990 extern void pop_insert (const pseudo_typeS *);
993 mips_pop_insert (void)
995 pop_insert (mips_pseudo_table);
996 if (! ECOFF_DEBUGGING)
997 pop_insert (mips_nonecoff_pseudo_table);
1000 /* Symbols labelling the current insn. */
1002 struct insn_label_list
1004 struct insn_label_list *next;
1008 static struct insn_label_list *insn_labels;
1009 static struct insn_label_list *free_insn_labels;
1011 static void mips_clear_insn_labels (void);
1014 mips_clear_insn_labels (void)
1016 register struct insn_label_list **pl;
1018 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1024 static char *expr_end;
1026 /* Expressions which appear in instructions. These are set by
1029 static expressionS imm_expr;
1030 static expressionS imm2_expr;
1031 static expressionS offset_expr;
1033 /* Relocs associated with imm_expr and offset_expr. */
1035 static bfd_reloc_code_real_type imm_reloc[3]
1036 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1037 static bfd_reloc_code_real_type offset_reloc[3]
1038 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1040 /* These are set by mips16_ip if an explicit extension is used. */
1042 static bfd_boolean mips16_small, mips16_ext;
1045 /* The pdr segment for per procedure frame/regmask info. Not used for
1048 static segT pdr_seg;
1051 /* The default target format to use. */
1054 mips_target_format (void)
1056 switch (OUTPUT_FLAVOR)
1058 case bfd_target_aout_flavour:
1059 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
1060 case bfd_target_ecoff_flavour:
1061 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1062 case bfd_target_coff_flavour:
1064 case bfd_target_elf_flavour:
1066 /* This is traditional mips. */
1067 return (target_big_endian
1068 ? (HAVE_64BIT_OBJECTS
1069 ? "elf64-tradbigmips"
1071 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1072 : (HAVE_64BIT_OBJECTS
1073 ? "elf64-tradlittlemips"
1075 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1077 return (target_big_endian
1078 ? (HAVE_64BIT_OBJECTS
1081 ? "elf32-nbigmips" : "elf32-bigmips"))
1082 : (HAVE_64BIT_OBJECTS
1083 ? "elf64-littlemips"
1085 ? "elf32-nlittlemips" : "elf32-littlemips")));
1093 /* This function is called once, at assembler startup time. It should
1094 set up all the tables, etc. that the MD part of the assembler will need. */
1099 register const char *retval = NULL;
1103 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
1104 as_warn (_("Could not set architecture and machine"));
1106 op_hash = hash_new ();
1108 for (i = 0; i < NUMOPCODES;)
1110 const char *name = mips_opcodes[i].name;
1112 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
1115 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1116 mips_opcodes[i].name, retval);
1117 /* Probably a memory allocation problem? Give up now. */
1118 as_fatal (_("Broken assembler. No assembly attempted."));
1122 if (mips_opcodes[i].pinfo != INSN_MACRO)
1124 if (!validate_mips_insn (&mips_opcodes[i]))
1129 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1132 mips16_op_hash = hash_new ();
1135 while (i < bfd_mips16_num_opcodes)
1137 const char *name = mips16_opcodes[i].name;
1139 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
1141 as_fatal (_("internal: can't hash `%s': %s"),
1142 mips16_opcodes[i].name, retval);
1145 if (mips16_opcodes[i].pinfo != INSN_MACRO
1146 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1147 != mips16_opcodes[i].match))
1149 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1150 mips16_opcodes[i].name, mips16_opcodes[i].args);
1155 while (i < bfd_mips16_num_opcodes
1156 && strcmp (mips16_opcodes[i].name, name) == 0);
1160 as_fatal (_("Broken assembler. No assembly attempted."));
1162 /* We add all the general register names to the symbol table. This
1163 helps us detect invalid uses of them. */
1164 for (i = 0; i < 32; i++)
1168 sprintf (buf, "$%d", i);
1169 symbol_table_insert (symbol_new (buf, reg_section, i,
1170 &zero_address_frag));
1172 symbol_table_insert (symbol_new ("$ra", reg_section, RA,
1173 &zero_address_frag));
1174 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1175 &zero_address_frag));
1176 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1177 &zero_address_frag));
1178 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1179 &zero_address_frag));
1180 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1181 &zero_address_frag));
1182 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1183 &zero_address_frag));
1184 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1185 &zero_address_frag));
1186 symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
1187 &zero_address_frag));
1188 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1189 &zero_address_frag));
1191 /* If we don't add these register names to the symbol table, they
1192 may end up being added as regular symbols by operand(), and then
1193 make it to the object file as undefined in case they're not
1194 regarded as local symbols. They're local in o32, since `$' is a
1195 local symbol prefix, but not in n32 or n64. */
1196 for (i = 0; i < 8; i++)
1200 sprintf (buf, "$fcc%i", i);
1201 symbol_table_insert (symbol_new (buf, reg_section, -1,
1202 &zero_address_frag));
1205 mips_no_prev_insn (FALSE);
1208 mips_cprmask[0] = 0;
1209 mips_cprmask[1] = 0;
1210 mips_cprmask[2] = 0;
1211 mips_cprmask[3] = 0;
1213 /* set the default alignment for the text section (2**2) */
1214 record_alignment (text_section, 2);
1216 if (USE_GLOBAL_POINTER_OPT)
1217 bfd_set_gp_size (stdoutput, g_switch_value);
1219 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1221 /* On a native system, sections must be aligned to 16 byte
1222 boundaries. When configured for an embedded ELF target, we
1224 if (strcmp (TARGET_OS, "elf") != 0)
1226 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1227 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1228 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1231 /* Create a .reginfo section for register masks and a .mdebug
1232 section for debugging information. */
1240 subseg = now_subseg;
1242 /* The ABI says this section should be loaded so that the
1243 running program can access it. However, we don't load it
1244 if we are configured for an embedded target */
1245 flags = SEC_READONLY | SEC_DATA;
1246 if (strcmp (TARGET_OS, "elf") != 0)
1247 flags |= SEC_ALLOC | SEC_LOAD;
1249 if (mips_abi != N64_ABI)
1251 sec = subseg_new (".reginfo", (subsegT) 0);
1253 bfd_set_section_flags (stdoutput, sec, flags);
1254 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1257 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1262 /* The 64-bit ABI uses a .MIPS.options section rather than
1263 .reginfo section. */
1264 sec = subseg_new (".MIPS.options", (subsegT) 0);
1265 bfd_set_section_flags (stdoutput, sec, flags);
1266 bfd_set_section_alignment (stdoutput, sec, 3);
1269 /* Set up the option header. */
1271 Elf_Internal_Options opthdr;
1274 opthdr.kind = ODK_REGINFO;
1275 opthdr.size = (sizeof (Elf_External_Options)
1276 + sizeof (Elf64_External_RegInfo));
1279 f = frag_more (sizeof (Elf_External_Options));
1280 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1281 (Elf_External_Options *) f);
1283 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1288 if (ECOFF_DEBUGGING)
1290 sec = subseg_new (".mdebug", (subsegT) 0);
1291 (void) bfd_set_section_flags (stdoutput, sec,
1292 SEC_HAS_CONTENTS | SEC_READONLY);
1293 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1296 else if (OUTPUT_FLAVOR == bfd_target_elf_flavour && mips_flag_pdr)
1298 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1299 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1300 SEC_READONLY | SEC_RELOC
1302 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1306 subseg_set (seg, subseg);
1310 if (! ECOFF_DEBUGGING)
1317 if (! ECOFF_DEBUGGING)
1322 md_assemble (char *str)
1324 struct mips_cl_insn insn;
1325 bfd_reloc_code_real_type unused_reloc[3]
1326 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1328 imm_expr.X_op = O_absent;
1329 imm2_expr.X_op = O_absent;
1330 offset_expr.X_op = O_absent;
1331 imm_reloc[0] = BFD_RELOC_UNUSED;
1332 imm_reloc[1] = BFD_RELOC_UNUSED;
1333 imm_reloc[2] = BFD_RELOC_UNUSED;
1334 offset_reloc[0] = BFD_RELOC_UNUSED;
1335 offset_reloc[1] = BFD_RELOC_UNUSED;
1336 offset_reloc[2] = BFD_RELOC_UNUSED;
1338 if (mips_opts.mips16)
1339 mips16_ip (str, &insn);
1342 mips_ip (str, &insn);
1343 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1344 str, insn.insn_opcode));
1349 as_bad ("%s `%s'", insn_error, str);
1353 if (insn.insn_mo->pinfo == INSN_MACRO)
1355 if (mips_opts.mips16)
1356 mips16_macro (&insn);
1362 if (imm_expr.X_op != O_absent)
1363 append_insn (NULL, &insn, &imm_expr, imm_reloc);
1364 else if (offset_expr.X_op != O_absent)
1365 append_insn (NULL, &insn, &offset_expr, offset_reloc);
1367 append_insn (NULL, &insn, NULL, unused_reloc);
1371 /* Return true if the given relocation might need a matching %lo().
1372 Note that R_MIPS_GOT16 relocations only need a matching %lo() when
1373 applied to local symbols. */
1375 static inline bfd_boolean
1376 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
1378 return (reloc == BFD_RELOC_HI16_S
1379 || reloc == BFD_RELOC_MIPS_GOT16);
1382 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
1385 static inline bfd_boolean
1386 fixup_has_matching_lo_p (fixS *fixp)
1388 return (fixp->fx_next != NULL
1389 && fixp->fx_next->fx_r_type == BFD_RELOC_LO16
1390 && fixp->fx_addsy == fixp->fx_next->fx_addsy
1391 && fixp->fx_offset == fixp->fx_next->fx_offset);
1394 /* See whether instruction IP reads register REG. CLASS is the type
1398 insn_uses_reg (struct mips_cl_insn *ip, unsigned int reg,
1399 enum mips_regclass class)
1401 if (class == MIPS16_REG)
1403 assert (mips_opts.mips16);
1404 reg = mips16_to_32_reg_map[reg];
1405 class = MIPS_GR_REG;
1408 /* Don't report on general register ZERO, since it never changes. */
1409 if (class == MIPS_GR_REG && reg == ZERO)
1412 if (class == MIPS_FP_REG)
1414 assert (! mips_opts.mips16);
1415 /* If we are called with either $f0 or $f1, we must check $f0.
1416 This is not optimal, because it will introduce an unnecessary
1417 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1418 need to distinguish reading both $f0 and $f1 or just one of
1419 them. Note that we don't have to check the other way,
1420 because there is no instruction that sets both $f0 and $f1
1421 and requires a delay. */
1422 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1423 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1424 == (reg &~ (unsigned) 1)))
1426 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1427 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1428 == (reg &~ (unsigned) 1)))
1431 else if (! mips_opts.mips16)
1433 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1434 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1436 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1437 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1442 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1443 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1444 & MIPS16OP_MASK_RX)]
1447 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1448 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1449 & MIPS16OP_MASK_RY)]
1452 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1453 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1454 & MIPS16OP_MASK_MOVE32Z)]
1457 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1459 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1461 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1463 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1464 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1465 & MIPS16OP_MASK_REGR32) == reg)
1472 /* This function returns true if modifying a register requires a
1476 reg_needs_delay (unsigned int reg)
1478 unsigned long prev_pinfo;
1480 prev_pinfo = prev_insn.insn_mo->pinfo;
1481 if (! mips_opts.noreorder
1482 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1483 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1484 || (! gpr_interlocks
1485 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1487 /* A load from a coprocessor or from memory. All load
1488 delays delay the use of general register rt for one
1489 instruction on the r3000. The r6000 and r4000 use
1491 /* Itbl support may require additional care here. */
1492 know (prev_pinfo & INSN_WRITE_GPR_T);
1493 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1500 /* Mark instruction labels in mips16 mode. This permits the linker to
1501 handle them specially, such as generating jalx instructions when
1502 needed. We also make them odd for the duration of the assembly, in
1503 order to generate the right sort of code. We will make them even
1504 in the adjust_symtab routine, while leaving them marked. This is
1505 convenient for the debugger and the disassembler. The linker knows
1506 to make them odd again. */
1509 mips16_mark_labels (void)
1511 if (mips_opts.mips16)
1513 struct insn_label_list *l;
1516 for (l = insn_labels; l != NULL; l = l->next)
1519 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1520 S_SET_OTHER (l->label, STO_MIPS16);
1522 val = S_GET_VALUE (l->label);
1524 S_SET_VALUE (l->label, val + 1);
1529 /* Output an instruction. PLACE is where to put the instruction; if
1530 it is NULL, this uses frag_more to get room. IP is the instruction
1531 information. ADDRESS_EXPR is an operand of the instruction to be
1532 used with RELOC_TYPE. */
1535 append_insn (char *place, struct mips_cl_insn *ip, expressionS *address_expr,
1536 bfd_reloc_code_real_type *reloc_type)
1538 register unsigned long prev_pinfo, pinfo;
1542 bfd_boolean force_new_frag = FALSE;
1544 /* Mark instruction labels in mips16 mode. */
1545 mips16_mark_labels ();
1547 prev_pinfo = prev_insn.insn_mo->pinfo;
1548 pinfo = ip->insn_mo->pinfo;
1550 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1554 /* If the previous insn required any delay slots, see if we need
1555 to insert a NOP or two. There are eight kinds of possible
1556 hazards, of which an instruction can have at most one type.
1557 (1) a load from memory delay
1558 (2) a load from a coprocessor delay
1559 (3) an unconditional branch delay
1560 (4) a conditional branch delay
1561 (5) a move to coprocessor register delay
1562 (6) a load coprocessor register from memory delay
1563 (7) a coprocessor condition code delay
1564 (8) a HI/LO special register delay
1566 There are a lot of optimizations we could do that we don't.
1567 In particular, we do not, in general, reorder instructions.
1568 If you use gcc with optimization, it will reorder
1569 instructions and generally do much more optimization then we
1570 do here; repeating all that work in the assembler would only
1571 benefit hand written assembly code, and does not seem worth
1574 /* This is how a NOP is emitted. */
1575 #define emit_nop() \
1577 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1578 : md_number_to_chars (frag_more (4), 0, 4))
1580 /* The previous insn might require a delay slot, depending upon
1581 the contents of the current insn. */
1582 if (! mips_opts.mips16
1583 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1584 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1585 && ! cop_interlocks)
1586 || (! gpr_interlocks
1587 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1589 /* A load from a coprocessor or from memory. All load
1590 delays delay the use of general register rt for one
1591 instruction on the r3000. The r6000 and r4000 use
1593 /* Itbl support may require additional care here. */
1594 know (prev_pinfo & INSN_WRITE_GPR_T);
1595 if (mips_optimize == 0
1596 || insn_uses_reg (ip,
1597 ((prev_insn.insn_opcode >> OP_SH_RT)
1602 else if (! mips_opts.mips16
1603 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1604 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1605 && ! cop_interlocks)
1606 || (mips_opts.isa == ISA_MIPS1
1607 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1609 /* A generic coprocessor delay. The previous instruction
1610 modified a coprocessor general or control register. If
1611 it modified a control register, we need to avoid any
1612 coprocessor instruction (this is probably not always
1613 required, but it sometimes is). If it modified a general
1614 register, we avoid using that register.
1616 On the r6000 and r4000 loading a coprocessor register
1617 from memory is interlocked, and does not require a delay.
1619 This case is not handled very well. There is no special
1620 knowledge of CP0 handling, and the coprocessors other
1621 than the floating point unit are not distinguished at
1623 /* Itbl support may require additional care here. FIXME!
1624 Need to modify this to include knowledge about
1625 user specified delays! */
1626 if (prev_pinfo & INSN_WRITE_FPR_T)
1628 if (mips_optimize == 0
1629 || insn_uses_reg (ip,
1630 ((prev_insn.insn_opcode >> OP_SH_FT)
1635 else if (prev_pinfo & INSN_WRITE_FPR_S)
1637 if (mips_optimize == 0
1638 || insn_uses_reg (ip,
1639 ((prev_insn.insn_opcode >> OP_SH_FS)
1646 /* We don't know exactly what the previous instruction
1647 does. If the current instruction uses a coprocessor
1648 register, we must insert a NOP. If previous
1649 instruction may set the condition codes, and the
1650 current instruction uses them, we must insert two
1652 /* Itbl support may require additional care here. */
1653 if (mips_optimize == 0
1654 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1655 && (pinfo & INSN_READ_COND_CODE)))
1657 else if (pinfo & INSN_COP)
1661 else if (! mips_opts.mips16
1662 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1663 && (prev_pinfo & INSN_WRITE_COND_CODE)
1664 && ! cop_interlocks)
1666 /* The previous instruction sets the coprocessor condition
1667 codes, but does not require a general coprocessor delay
1668 (this means it is a floating point comparison
1669 instruction). If this instruction uses the condition
1670 codes, we need to insert a single NOP. */
1671 /* Itbl support may require additional care here. */
1672 if (mips_optimize == 0
1673 || (pinfo & INSN_READ_COND_CODE))
1677 /* If we're fixing up mfhi/mflo for the r7000 and the
1678 previous insn was an mfhi/mflo and the current insn
1679 reads the register that the mfhi/mflo wrote to, then
1682 else if (mips_7000_hilo_fix
1683 && MF_HILO_INSN (prev_pinfo)
1684 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1691 /* If we're fixing up mfhi/mflo for the r7000 and the
1692 2nd previous insn was an mfhi/mflo and the current insn
1693 reads the register that the mfhi/mflo wrote to, then
1696 else if (mips_7000_hilo_fix
1697 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1698 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1706 else if (prev_pinfo & INSN_READ_LO)
1708 /* The previous instruction reads the LO register; if the
1709 current instruction writes to the LO register, we must
1710 insert two NOPS. Some newer processors have interlocks.
1711 Also the tx39's multiply instructions can be executed
1712 immediately after a read from HI/LO (without the delay),
1713 though the tx39's divide insns still do require the
1715 if (! (hilo_interlocks
1716 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1717 && (mips_optimize == 0
1718 || (pinfo & INSN_WRITE_LO)))
1720 /* Most mips16 branch insns don't have a delay slot.
1721 If a read from LO is immediately followed by a branch
1722 to a write to LO we have a read followed by a write
1723 less than 2 insns away. We assume the target of
1724 a branch might be a write to LO, and insert a nop
1725 between a read and an immediately following branch. */
1726 else if (mips_opts.mips16
1727 && (mips_optimize == 0
1728 || (pinfo & MIPS16_INSN_BRANCH)))
1731 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1733 /* The previous instruction reads the HI register; if the
1734 current instruction writes to the HI register, we must
1735 insert a NOP. Some newer processors have interlocks.
1736 Also the note tx39's multiply above. */
1737 if (! (hilo_interlocks
1738 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1739 && (mips_optimize == 0
1740 || (pinfo & INSN_WRITE_HI)))
1742 /* Most mips16 branch insns don't have a delay slot.
1743 If a read from HI is immediately followed by a branch
1744 to a write to HI we have a read followed by a write
1745 less than 2 insns away. We assume the target of
1746 a branch might be a write to HI, and insert a nop
1747 between a read and an immediately following branch. */
1748 else if (mips_opts.mips16
1749 && (mips_optimize == 0
1750 || (pinfo & MIPS16_INSN_BRANCH)))
1754 /* If the previous instruction was in a noreorder section, then
1755 we don't want to insert the nop after all. */
1756 /* Itbl support may require additional care here. */
1757 if (prev_insn_unreordered)
1760 /* There are two cases which require two intervening
1761 instructions: 1) setting the condition codes using a move to
1762 coprocessor instruction which requires a general coprocessor
1763 delay and then reading the condition codes 2) reading the HI
1764 or LO register and then writing to it (except on processors
1765 which have interlocks). If we are not already emitting a NOP
1766 instruction, we must check for these cases compared to the
1767 instruction previous to the previous instruction. */
1768 if ((! mips_opts.mips16
1769 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1770 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1771 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1772 && (pinfo & INSN_READ_COND_CODE)
1773 && ! cop_interlocks)
1774 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1775 && (pinfo & INSN_WRITE_LO)
1776 && ! (hilo_interlocks
1777 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1778 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1779 && (pinfo & INSN_WRITE_HI)
1780 && ! (hilo_interlocks
1781 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1786 if (prev_prev_insn_unreordered)
1789 if (prev_prev_nop && nops == 0)
1792 if (mips_fix_4122_bugs && prev_insn.insn_mo->name)
1794 /* We're out of bits in pinfo, so we must resort to string
1795 ops here. Shortcuts are selected based on opcodes being
1796 limited to the VR4122 instruction set. */
1798 const char *pn = prev_insn.insn_mo->name;
1799 const char *tn = ip->insn_mo->name;
1800 if (strncmp(pn, "macc", 4) == 0
1801 || strncmp(pn, "dmacc", 5) == 0)
1803 /* Errata 21 - [D]DIV[U] after [D]MACC */
1804 if (strstr (tn, "div"))
1809 /* Errata 23 - Continuous DMULT[U]/DMACC instructions */
1810 if (pn[0] == 'd' /* dmacc */
1811 && (strncmp(tn, "dmult", 5) == 0
1812 || strncmp(tn, "dmacc", 5) == 0))
1817 /* Errata 24 - MT{LO,HI} after [D]MACC */
1818 if (strcmp (tn, "mtlo") == 0
1819 || strcmp (tn, "mthi") == 0)
1825 else if (strncmp(pn, "dmult", 5) == 0
1826 && (strncmp(tn, "dmult", 5) == 0
1827 || strncmp(tn, "dmacc", 5) == 0))
1829 /* Here is the rest of errata 23. */
1832 if (nops < min_nops)
1836 /* If we are being given a nop instruction, don't bother with
1837 one of the nops we would otherwise output. This will only
1838 happen when a nop instruction is used with mips_optimize set
1841 && ! mips_opts.noreorder
1842 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1845 /* Now emit the right number of NOP instructions. */
1846 if (nops > 0 && ! mips_opts.noreorder)
1849 unsigned long old_frag_offset;
1851 struct insn_label_list *l;
1853 old_frag = frag_now;
1854 old_frag_offset = frag_now_fix ();
1856 for (i = 0; i < nops; i++)
1861 listing_prev_line ();
1862 /* We may be at the start of a variant frag. In case we
1863 are, make sure there is enough space for the frag
1864 after the frags created by listing_prev_line. The
1865 argument to frag_grow here must be at least as large
1866 as the argument to all other calls to frag_grow in
1867 this file. We don't have to worry about being in the
1868 middle of a variant frag, because the variants insert
1869 all needed nop instructions themselves. */
1873 for (l = insn_labels; l != NULL; l = l->next)
1877 assert (S_GET_SEGMENT (l->label) == now_seg);
1878 symbol_set_frag (l->label, frag_now);
1879 val = (valueT) frag_now_fix ();
1880 /* mips16 text labels are stored as odd. */
1881 if (mips_opts.mips16)
1883 S_SET_VALUE (l->label, val);
1886 #ifndef NO_ECOFF_DEBUGGING
1887 if (ECOFF_DEBUGGING)
1888 ecoff_fix_loc (old_frag, old_frag_offset);
1891 else if (prev_nop_frag != NULL)
1893 /* We have a frag holding nops we may be able to remove. If
1894 we don't need any nops, we can decrease the size of
1895 prev_nop_frag by the size of one instruction. If we do
1896 need some nops, we count them in prev_nops_required. */
1897 if (prev_nop_frag_since == 0)
1901 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1902 --prev_nop_frag_holds;
1905 prev_nop_frag_required += nops;
1909 if (prev_prev_nop == 0)
1911 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1912 --prev_nop_frag_holds;
1915 ++prev_nop_frag_required;
1918 if (prev_nop_frag_holds <= prev_nop_frag_required)
1919 prev_nop_frag = NULL;
1921 ++prev_nop_frag_since;
1923 /* Sanity check: by the time we reach the second instruction
1924 after prev_nop_frag, we should have used up all the nops
1925 one way or another. */
1926 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1932 && *reloc_type == BFD_RELOC_16_PCREL_S2
1933 && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY
1934 || pinfo & INSN_COND_BRANCH_LIKELY)
1935 && mips_relax_branch
1936 /* Don't try branch relaxation within .set nomacro, or within
1937 .set noat if we use $at for PIC computations. If it turns
1938 out that the branch was out-of-range, we'll get an error. */
1939 && !mips_opts.warn_about_macros
1940 && !(mips_opts.noat && mips_pic != NO_PIC)
1941 && !mips_opts.mips16)
1943 f = frag_var (rs_machine_dependent,
1944 relaxed_branch_length
1946 (pinfo & INSN_UNCOND_BRANCH_DELAY) ? -1
1947 : (pinfo & INSN_COND_BRANCH_LIKELY) ? 1 : 0), 4,
1949 (pinfo & INSN_UNCOND_BRANCH_DELAY,
1950 pinfo & INSN_COND_BRANCH_LIKELY,
1951 pinfo & INSN_WRITE_GPR_31,
1953 address_expr->X_add_symbol,
1954 address_expr->X_add_number,
1956 *reloc_type = BFD_RELOC_UNUSED;
1958 else if (*reloc_type > BFD_RELOC_UNUSED)
1960 /* We need to set up a variant frag. */
1961 assert (mips_opts.mips16 && address_expr != NULL);
1962 f = frag_var (rs_machine_dependent, 4, 0,
1963 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
1964 mips16_small, mips16_ext,
1966 & INSN_UNCOND_BRANCH_DELAY),
1967 (*prev_insn_reloc_type
1968 == BFD_RELOC_MIPS16_JMP)),
1969 make_expr_symbol (address_expr), 0, NULL);
1971 else if (place != NULL)
1973 else if (mips_opts.mips16
1975 && *reloc_type != BFD_RELOC_MIPS16_JMP)
1977 /* Make sure there is enough room to swap this instruction with
1978 a following jump instruction. */
1984 if (mips_opts.mips16
1985 && mips_opts.noreorder
1986 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1987 as_warn (_("extended instruction in delay slot"));
1992 fixp[0] = fixp[1] = fixp[2] = NULL;
1993 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
1995 if (address_expr->X_op == O_constant)
1999 switch (*reloc_type)
2002 ip->insn_opcode |= address_expr->X_add_number;
2005 case BFD_RELOC_MIPS_HIGHEST:
2006 tmp = (address_expr->X_add_number
2007 + ((valueT) 0x8000 << 32) + 0x80008000) >> 16;
2009 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2012 case BFD_RELOC_MIPS_HIGHER:
2013 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
2014 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2017 case BFD_RELOC_HI16_S:
2018 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
2022 case BFD_RELOC_HI16:
2023 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2026 case BFD_RELOC_LO16:
2027 case BFD_RELOC_MIPS_GOT_DISP:
2028 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2031 case BFD_RELOC_MIPS_JMP:
2032 if ((address_expr->X_add_number & 3) != 0)
2033 as_bad (_("jump to misaligned address (0x%lx)"),
2034 (unsigned long) address_expr->X_add_number);
2035 if (address_expr->X_add_number & ~0xfffffff)
2036 as_bad (_("jump address range overflow (0x%lx)"),
2037 (unsigned long) address_expr->X_add_number);
2038 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2041 case BFD_RELOC_MIPS16_JMP:
2042 if ((address_expr->X_add_number & 3) != 0)
2043 as_bad (_("jump to misaligned address (0x%lx)"),
2044 (unsigned long) address_expr->X_add_number);
2045 if (address_expr->X_add_number & ~0xfffffff)
2046 as_bad (_("jump address range overflow (0x%lx)"),
2047 (unsigned long) address_expr->X_add_number);
2049 (((address_expr->X_add_number & 0x7c0000) << 3)
2050 | ((address_expr->X_add_number & 0xf800000) >> 7)
2051 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2054 case BFD_RELOC_16_PCREL_S2:
2064 /* Don't generate a reloc if we are writing into a variant frag. */
2067 reloc_howto_type *howto;
2070 /* In a compound relocation, it is the final (outermost)
2071 operator that determines the relocated field. */
2072 for (i = 1; i < 3; i++)
2073 if (reloc_type[i] == BFD_RELOC_UNUSED)
2076 howto = bfd_reloc_type_lookup (stdoutput, reloc_type[i - 1]);
2077 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal,
2078 bfd_get_reloc_size(howto),
2080 reloc_type[0] == BFD_RELOC_16_PCREL_S2,
2083 /* These relocations can have an addend that won't fit in
2084 4 octets for 64bit assembly. */
2086 && ! howto->partial_inplace
2087 && (reloc_type[0] == BFD_RELOC_16
2088 || reloc_type[0] == BFD_RELOC_32
2089 || reloc_type[0] == BFD_RELOC_MIPS_JMP
2090 || reloc_type[0] == BFD_RELOC_HI16_S
2091 || reloc_type[0] == BFD_RELOC_LO16
2092 || reloc_type[0] == BFD_RELOC_GPREL16
2093 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
2094 || reloc_type[0] == BFD_RELOC_GPREL32
2095 || reloc_type[0] == BFD_RELOC_64
2096 || reloc_type[0] == BFD_RELOC_CTOR
2097 || reloc_type[0] == BFD_RELOC_MIPS_SUB
2098 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
2099 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
2100 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
2101 || reloc_type[0] == BFD_RELOC_MIPS_REL16
2102 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT))
2103 fixp[0]->fx_no_overflow = 1;
2105 if (reloc_needs_lo_p (*reloc_type))
2107 struct mips_hi_fixup *hi_fixup;
2109 /* Reuse the last entry if it already has a matching %lo. */
2110 hi_fixup = mips_hi_fixup_list;
2112 || !fixup_has_matching_lo_p (hi_fixup->fixp))
2114 hi_fixup = ((struct mips_hi_fixup *)
2115 xmalloc (sizeof (struct mips_hi_fixup)));
2116 hi_fixup->next = mips_hi_fixup_list;
2117 mips_hi_fixup_list = hi_fixup;
2119 hi_fixup->fixp = fixp[0];
2120 hi_fixup->seg = now_seg;
2123 /* Add fixups for the second and third relocations, if given.
2124 Note that the ABI allows the second relocation to be
2125 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
2126 moment we only use RSS_UNDEF, but we could add support
2127 for the others if it ever becomes necessary. */
2128 for (i = 1; i < 3; i++)
2129 if (reloc_type[i] != BFD_RELOC_UNUSED)
2131 address_expr->X_op = O_absent;
2132 address_expr->X_add_symbol = 0;
2133 address_expr->X_add_number = 0;
2135 fixp[i] = fix_new_exp (frag_now, fixp[0]->fx_where,
2136 fixp[0]->fx_size, address_expr,
2137 FALSE, reloc_type[i]);
2143 if (! mips_opts.mips16)
2145 md_number_to_chars (f, ip->insn_opcode, 4);
2147 dwarf2_emit_insn (4);
2150 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2152 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2153 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2155 dwarf2_emit_insn (4);
2162 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2165 md_number_to_chars (f, ip->insn_opcode, 2);
2167 dwarf2_emit_insn (ip->use_extend ? 4 : 2);
2171 /* Update the register mask information. */
2172 if (! mips_opts.mips16)
2174 if (pinfo & INSN_WRITE_GPR_D)
2175 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2176 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2177 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2178 if (pinfo & INSN_READ_GPR_S)
2179 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2180 if (pinfo & INSN_WRITE_GPR_31)
2181 mips_gprmask |= 1 << RA;
2182 if (pinfo & INSN_WRITE_FPR_D)
2183 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2184 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2185 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2186 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2187 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2188 if ((pinfo & INSN_READ_FPR_R) != 0)
2189 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2190 if (pinfo & INSN_COP)
2192 /* We don't keep enough information to sort these cases out.
2193 The itbl support does keep this information however, although
2194 we currently don't support itbl fprmats as part of the cop
2195 instruction. May want to add this support in the future. */
2197 /* Never set the bit for $0, which is always zero. */
2198 mips_gprmask &= ~1 << 0;
2202 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2203 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2204 & MIPS16OP_MASK_RX);
2205 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2206 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2207 & MIPS16OP_MASK_RY);
2208 if (pinfo & MIPS16_INSN_WRITE_Z)
2209 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2210 & MIPS16OP_MASK_RZ);
2211 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2212 mips_gprmask |= 1 << TREG;
2213 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2214 mips_gprmask |= 1 << SP;
2215 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2216 mips_gprmask |= 1 << RA;
2217 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2218 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2219 if (pinfo & MIPS16_INSN_READ_Z)
2220 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2221 & MIPS16OP_MASK_MOVE32Z);
2222 if (pinfo & MIPS16_INSN_READ_GPR_X)
2223 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2224 & MIPS16OP_MASK_REGR32);
2227 if (place == NULL && ! mips_opts.noreorder)
2229 /* Filling the branch delay slot is more complex. We try to
2230 switch the branch with the previous instruction, which we can
2231 do if the previous instruction does not set up a condition
2232 that the branch tests and if the branch is not itself the
2233 target of any branch. */
2234 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2235 || (pinfo & INSN_COND_BRANCH_DELAY))
2237 if (mips_optimize < 2
2238 /* If we have seen .set volatile or .set nomove, don't
2240 || mips_opts.nomove != 0
2241 /* If we had to emit any NOP instructions, then we
2242 already know we can not swap. */
2244 /* If we don't even know the previous insn, we can not
2246 || ! prev_insn_valid
2247 /* If the previous insn is already in a branch delay
2248 slot, then we can not swap. */
2249 || prev_insn_is_delay_slot
2250 /* If the previous previous insn was in a .set
2251 noreorder, we can't swap. Actually, the MIPS
2252 assembler will swap in this situation. However, gcc
2253 configured -with-gnu-as will generate code like
2259 in which we can not swap the bne and INSN. If gcc is
2260 not configured -with-gnu-as, it does not output the
2261 .set pseudo-ops. We don't have to check
2262 prev_insn_unreordered, because prev_insn_valid will
2263 be 0 in that case. We don't want to use
2264 prev_prev_insn_valid, because we do want to be able
2265 to swap at the start of a function. */
2266 || prev_prev_insn_unreordered
2267 /* If the branch is itself the target of a branch, we
2268 can not swap. We cheat on this; all we check for is
2269 whether there is a label on this instruction. If
2270 there are any branches to anything other than a
2271 label, users must use .set noreorder. */
2272 || insn_labels != NULL
2273 /* If the previous instruction is in a variant frag, we
2274 can not do the swap. This does not apply to the
2275 mips16, which uses variant frags for different
2277 || (! mips_opts.mips16
2278 && prev_insn_frag->fr_type == rs_machine_dependent)
2279 /* If the branch reads the condition codes, we don't
2280 even try to swap, because in the sequence
2285 we can not swap, and I don't feel like handling that
2287 || (! mips_opts.mips16
2288 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2289 && (pinfo & INSN_READ_COND_CODE))
2290 /* We can not swap with an instruction that requires a
2291 delay slot, because the target of the branch might
2292 interfere with that instruction. */
2293 || (! mips_opts.mips16
2294 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2296 /* Itbl support may require additional care here. */
2297 & (INSN_LOAD_COPROC_DELAY
2298 | INSN_COPROC_MOVE_DELAY
2299 | INSN_WRITE_COND_CODE)))
2300 || (! (hilo_interlocks
2301 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2305 || (! mips_opts.mips16
2307 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2308 || (! mips_opts.mips16
2309 && mips_opts.isa == ISA_MIPS1
2310 /* Itbl support may require additional care here. */
2311 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2312 /* We can not swap with a branch instruction. */
2314 & (INSN_UNCOND_BRANCH_DELAY
2315 | INSN_COND_BRANCH_DELAY
2316 | INSN_COND_BRANCH_LIKELY))
2317 /* We do not swap with a trap instruction, since it
2318 complicates trap handlers to have the trap
2319 instruction be in a delay slot. */
2320 || (prev_pinfo & INSN_TRAP)
2321 /* If the branch reads a register that the previous
2322 instruction sets, we can not swap. */
2323 || (! mips_opts.mips16
2324 && (prev_pinfo & INSN_WRITE_GPR_T)
2325 && insn_uses_reg (ip,
2326 ((prev_insn.insn_opcode >> OP_SH_RT)
2329 || (! mips_opts.mips16
2330 && (prev_pinfo & INSN_WRITE_GPR_D)
2331 && insn_uses_reg (ip,
2332 ((prev_insn.insn_opcode >> OP_SH_RD)
2335 || (mips_opts.mips16
2336 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2337 && insn_uses_reg (ip,
2338 ((prev_insn.insn_opcode
2340 & MIPS16OP_MASK_RX),
2342 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2343 && insn_uses_reg (ip,
2344 ((prev_insn.insn_opcode
2346 & MIPS16OP_MASK_RY),
2348 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2349 && insn_uses_reg (ip,
2350 ((prev_insn.insn_opcode
2352 & MIPS16OP_MASK_RZ),
2354 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2355 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2356 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2357 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2358 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2359 && insn_uses_reg (ip,
2360 MIPS16OP_EXTRACT_REG32R (prev_insn.
2363 /* If the branch writes a register that the previous
2364 instruction sets, we can not swap (we know that
2365 branches write only to RD or to $31). */
2366 || (! mips_opts.mips16
2367 && (prev_pinfo & INSN_WRITE_GPR_T)
2368 && (((pinfo & INSN_WRITE_GPR_D)
2369 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2370 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2371 || ((pinfo & INSN_WRITE_GPR_31)
2372 && (((prev_insn.insn_opcode >> OP_SH_RT)
2375 || (! mips_opts.mips16
2376 && (prev_pinfo & INSN_WRITE_GPR_D)
2377 && (((pinfo & INSN_WRITE_GPR_D)
2378 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2379 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2380 || ((pinfo & INSN_WRITE_GPR_31)
2381 && (((prev_insn.insn_opcode >> OP_SH_RD)
2384 || (mips_opts.mips16
2385 && (pinfo & MIPS16_INSN_WRITE_31)
2386 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2387 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2388 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2390 /* If the branch writes a register that the previous
2391 instruction reads, we can not swap (we know that
2392 branches only write to RD or to $31). */
2393 || (! mips_opts.mips16
2394 && (pinfo & INSN_WRITE_GPR_D)
2395 && insn_uses_reg (&prev_insn,
2396 ((ip->insn_opcode >> OP_SH_RD)
2399 || (! mips_opts.mips16
2400 && (pinfo & INSN_WRITE_GPR_31)
2401 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2402 || (mips_opts.mips16
2403 && (pinfo & MIPS16_INSN_WRITE_31)
2404 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2405 /* If we are generating embedded PIC code, the branch
2406 might be expanded into a sequence which uses $at, so
2407 we can't swap with an instruction which reads it. */
2408 || (mips_pic == EMBEDDED_PIC
2409 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2410 /* If the previous previous instruction has a load
2411 delay, and sets a register that the branch reads, we
2413 || (! mips_opts.mips16
2414 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2415 /* Itbl support may require additional care here. */
2416 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2417 || (! gpr_interlocks
2418 && (prev_prev_insn.insn_mo->pinfo
2419 & INSN_LOAD_MEMORY_DELAY)))
2420 && insn_uses_reg (ip,
2421 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2424 /* If one instruction sets a condition code and the
2425 other one uses a condition code, we can not swap. */
2426 || ((pinfo & INSN_READ_COND_CODE)
2427 && (prev_pinfo & INSN_WRITE_COND_CODE))
2428 || ((pinfo & INSN_WRITE_COND_CODE)
2429 && (prev_pinfo & INSN_READ_COND_CODE))
2430 /* If the previous instruction uses the PC, we can not
2432 || (mips_opts.mips16
2433 && (prev_pinfo & MIPS16_INSN_READ_PC))
2434 /* If the previous instruction was extended, we can not
2436 || (mips_opts.mips16 && prev_insn_extended)
2437 /* If the previous instruction had a fixup in mips16
2438 mode, we can not swap. This normally means that the
2439 previous instruction was a 4 byte branch anyhow. */
2440 || (mips_opts.mips16 && prev_insn_fixp[0])
2441 /* If the previous instruction is a sync, sync.l, or
2442 sync.p, we can not swap. */
2443 || (prev_pinfo & INSN_SYNC))
2445 /* We could do even better for unconditional branches to
2446 portions of this object file; we could pick up the
2447 instruction at the destination, put it in the delay
2448 slot, and bump the destination address. */
2450 /* Update the previous insn information. */
2451 prev_prev_insn = *ip;
2452 prev_insn.insn_mo = &dummy_opcode;
2456 /* It looks like we can actually do the swap. */
2457 if (! mips_opts.mips16)
2462 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2463 memcpy (temp, prev_f, 4);
2464 memcpy (prev_f, f, 4);
2465 memcpy (f, temp, 4);
2466 if (prev_insn_fixp[0])
2468 prev_insn_fixp[0]->fx_frag = frag_now;
2469 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2471 if (prev_insn_fixp[1])
2473 prev_insn_fixp[1]->fx_frag = frag_now;
2474 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2476 if (prev_insn_fixp[2])
2478 prev_insn_fixp[2]->fx_frag = frag_now;
2479 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2481 if (prev_insn_fixp[0] && HAVE_NEWABI
2482 && prev_insn_frag != frag_now
2483 && (prev_insn_fixp[0]->fx_r_type
2484 == BFD_RELOC_MIPS_GOT_DISP
2485 || (prev_insn_fixp[0]->fx_r_type
2486 == BFD_RELOC_MIPS_CALL16)))
2488 /* To avoid confusion in tc_gen_reloc, we must
2489 ensure that this does not become a variant
2491 force_new_frag = TRUE;
2495 fixp[0]->fx_frag = prev_insn_frag;
2496 fixp[0]->fx_where = prev_insn_where;
2500 fixp[1]->fx_frag = prev_insn_frag;
2501 fixp[1]->fx_where = prev_insn_where;
2505 fixp[2]->fx_frag = prev_insn_frag;
2506 fixp[2]->fx_where = prev_insn_where;
2514 assert (prev_insn_fixp[0] == NULL);
2515 assert (prev_insn_fixp[1] == NULL);
2516 assert (prev_insn_fixp[2] == NULL);
2517 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2518 memcpy (temp, prev_f, 2);
2519 memcpy (prev_f, f, 2);
2520 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2522 assert (*reloc_type == BFD_RELOC_UNUSED);
2523 memcpy (f, temp, 2);
2527 memcpy (f, f + 2, 2);
2528 memcpy (f + 2, temp, 2);
2532 fixp[0]->fx_frag = prev_insn_frag;
2533 fixp[0]->fx_where = prev_insn_where;
2537 fixp[1]->fx_frag = prev_insn_frag;
2538 fixp[1]->fx_where = prev_insn_where;
2542 fixp[2]->fx_frag = prev_insn_frag;
2543 fixp[2]->fx_where = prev_insn_where;
2547 /* Update the previous insn information; leave prev_insn
2549 prev_prev_insn = *ip;
2551 prev_insn_is_delay_slot = 1;
2553 /* If that was an unconditional branch, forget the previous
2554 insn information. */
2555 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2557 prev_prev_insn.insn_mo = &dummy_opcode;
2558 prev_insn.insn_mo = &dummy_opcode;
2561 prev_insn_fixp[0] = NULL;
2562 prev_insn_fixp[1] = NULL;
2563 prev_insn_fixp[2] = NULL;
2564 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2565 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2566 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2567 prev_insn_extended = 0;
2569 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2571 /* We don't yet optimize a branch likely. What we should do
2572 is look at the target, copy the instruction found there
2573 into the delay slot, and increment the branch to jump to
2574 the next instruction. */
2576 /* Update the previous insn information. */
2577 prev_prev_insn = *ip;
2578 prev_insn.insn_mo = &dummy_opcode;
2579 prev_insn_fixp[0] = NULL;
2580 prev_insn_fixp[1] = NULL;
2581 prev_insn_fixp[2] = NULL;
2582 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2583 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2584 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2585 prev_insn_extended = 0;
2589 /* Update the previous insn information. */
2591 prev_prev_insn.insn_mo = &dummy_opcode;
2593 prev_prev_insn = prev_insn;
2596 /* Any time we see a branch, we always fill the delay slot
2597 immediately; since this insn is not a branch, we know it
2598 is not in a delay slot. */
2599 prev_insn_is_delay_slot = 0;
2601 prev_insn_fixp[0] = fixp[0];
2602 prev_insn_fixp[1] = fixp[1];
2603 prev_insn_fixp[2] = fixp[2];
2604 prev_insn_reloc_type[0] = reloc_type[0];
2605 prev_insn_reloc_type[1] = reloc_type[1];
2606 prev_insn_reloc_type[2] = reloc_type[2];
2607 if (mips_opts.mips16)
2608 prev_insn_extended = (ip->use_extend
2609 || *reloc_type > BFD_RELOC_UNUSED);
2612 prev_prev_insn_unreordered = prev_insn_unreordered;
2613 prev_insn_unreordered = 0;
2614 prev_insn_frag = frag_now;
2615 prev_insn_where = f - frag_now->fr_literal;
2616 prev_insn_valid = 1;
2618 else if (place == NULL)
2620 /* We need to record a bit of information even when we are not
2621 reordering, in order to determine the base address for mips16
2622 PC relative relocs. */
2623 prev_prev_insn = prev_insn;
2625 prev_insn_reloc_type[0] = reloc_type[0];
2626 prev_insn_reloc_type[1] = reloc_type[1];
2627 prev_insn_reloc_type[2] = reloc_type[2];
2628 prev_prev_insn_unreordered = prev_insn_unreordered;
2629 prev_insn_unreordered = 1;
2632 /* We just output an insn, so the next one doesn't have a label. */
2633 mips_clear_insn_labels ();
2635 /* We must ensure that the frag to which an instruction that was
2636 moved from a non-variant frag doesn't become a variant frag,
2637 otherwise tc_gen_reloc may get confused. */
2640 frag_wane (frag_now);
2645 /* This function forgets that there was any previous instruction or
2646 label. If PRESERVE is non-zero, it remembers enough information to
2647 know whether nops are needed before a noreorder section. */
2650 mips_no_prev_insn (int preserve)
2654 prev_insn.insn_mo = &dummy_opcode;
2655 prev_prev_insn.insn_mo = &dummy_opcode;
2656 prev_nop_frag = NULL;
2657 prev_nop_frag_holds = 0;
2658 prev_nop_frag_required = 0;
2659 prev_nop_frag_since = 0;
2661 prev_insn_valid = 0;
2662 prev_insn_is_delay_slot = 0;
2663 prev_insn_unreordered = 0;
2664 prev_insn_extended = 0;
2665 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2666 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2667 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2668 prev_prev_insn_unreordered = 0;
2669 mips_clear_insn_labels ();
2672 /* This function must be called whenever we turn on noreorder or emit
2673 something other than instructions. It inserts any NOPS which might
2674 be needed by the previous instruction, and clears the information
2675 kept for the previous instructions. The INSNS parameter is true if
2676 instructions are to follow. */
2679 mips_emit_delays (bfd_boolean insns)
2681 if (! mips_opts.noreorder)
2686 if ((! mips_opts.mips16
2687 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2688 && (! cop_interlocks
2689 && (prev_insn.insn_mo->pinfo
2690 & (INSN_LOAD_COPROC_DELAY
2691 | INSN_COPROC_MOVE_DELAY
2692 | INSN_WRITE_COND_CODE))))
2693 || (! hilo_interlocks
2694 && (prev_insn.insn_mo->pinfo
2697 || (! mips_opts.mips16
2699 && (prev_insn.insn_mo->pinfo
2700 & INSN_LOAD_MEMORY_DELAY))
2701 || (! mips_opts.mips16
2702 && mips_opts.isa == ISA_MIPS1
2703 && (prev_insn.insn_mo->pinfo
2704 & INSN_COPROC_MEMORY_DELAY)))
2706 /* Itbl support may require additional care here. */
2708 if ((! mips_opts.mips16
2709 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2710 && (! cop_interlocks
2711 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2712 || (! hilo_interlocks
2713 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2714 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2717 if (prev_insn_unreordered)
2720 else if ((! mips_opts.mips16
2721 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2722 && (! cop_interlocks
2723 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2724 || (! hilo_interlocks
2725 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2726 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2728 /* Itbl support may require additional care here. */
2729 if (! prev_prev_insn_unreordered)
2733 if (mips_fix_4122_bugs && prev_insn.insn_mo->name)
2736 const char *pn = prev_insn.insn_mo->name;
2737 if (strncmp(pn, "macc", 4) == 0
2738 || strncmp(pn, "dmacc", 5) == 0
2739 || strncmp(pn, "dmult", 5) == 0)
2743 if (nops < min_nops)
2749 struct insn_label_list *l;
2753 /* Record the frag which holds the nop instructions, so
2754 that we can remove them if we don't need them. */
2755 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2756 prev_nop_frag = frag_now;
2757 prev_nop_frag_holds = nops;
2758 prev_nop_frag_required = 0;
2759 prev_nop_frag_since = 0;
2762 for (; nops > 0; --nops)
2767 /* Move on to a new frag, so that it is safe to simply
2768 decrease the size of prev_nop_frag. */
2769 frag_wane (frag_now);
2773 for (l = insn_labels; l != NULL; l = l->next)
2777 assert (S_GET_SEGMENT (l->label) == now_seg);
2778 symbol_set_frag (l->label, frag_now);
2779 val = (valueT) frag_now_fix ();
2780 /* mips16 text labels are stored as odd. */
2781 if (mips_opts.mips16)
2783 S_SET_VALUE (l->label, val);
2788 /* Mark instruction labels in mips16 mode. */
2790 mips16_mark_labels ();
2792 mips_no_prev_insn (insns);
2795 /* Build an instruction created by a macro expansion. This is passed
2796 a pointer to the count of instructions created so far, an
2797 expression, the name of the instruction to build, an operand format
2798 string, and corresponding arguments. */
2801 macro_build (char *place, int *counter, expressionS *ep, const char *name,
2802 const char *fmt, ...)
2804 struct mips_cl_insn insn;
2805 bfd_reloc_code_real_type r[3];
2808 va_start (args, fmt);
2811 * If the macro is about to expand into a second instruction,
2812 * print a warning if needed. We need to pass ip as a parameter
2813 * to generate a better warning message here...
2815 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2816 as_warn (_("Macro instruction expanded into multiple instructions"));
2819 * If the macro is about to expand into a second instruction,
2820 * and it is in a delay slot, print a warning.
2824 && mips_opts.noreorder
2825 && (prev_prev_insn.insn_mo->pinfo
2826 & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY
2827 | INSN_COND_BRANCH_LIKELY)) != 0)
2828 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2831 ++*counter; /* bump instruction counter */
2833 if (mips_opts.mips16)
2835 mips16_macro_build (place, counter, ep, name, fmt, args);
2840 r[0] = BFD_RELOC_UNUSED;
2841 r[1] = BFD_RELOC_UNUSED;
2842 r[2] = BFD_RELOC_UNUSED;
2843 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2844 assert (insn.insn_mo);
2845 assert (strcmp (name, insn.insn_mo->name) == 0);
2847 /* Search until we get a match for NAME. */
2850 /* It is assumed here that macros will never generate
2851 MDMX or MIPS-3D instructions. */
2852 if (strcmp (fmt, insn.insn_mo->args) == 0
2853 && insn.insn_mo->pinfo != INSN_MACRO
2854 && OPCODE_IS_MEMBER (insn.insn_mo,
2856 | (file_ase_mips16 ? INSN_MIPS16 : 0)),
2858 && (mips_opts.arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2862 assert (insn.insn_mo->name);
2863 assert (strcmp (name, insn.insn_mo->name) == 0);
2866 insn.insn_opcode = insn.insn_mo->match;
2884 insn.insn_opcode |= (va_arg (args, int)
2885 & OP_MASK_SHAMT) << OP_SH_SHAMT;
2890 /* Note that in the macro case, these arguments are already
2891 in MSB form. (When handling the instruction in the
2892 non-macro case, these arguments are sizes from which
2893 MSB values must be calculated.) */
2894 insn.insn_opcode |= (va_arg (args, int)
2895 & OP_MASK_INSMSB) << OP_SH_INSMSB;
2901 /* Note that in the macro case, these arguments are already
2902 in MSBD form. (When handling the instruction in the
2903 non-macro case, these arguments are sizes from which
2904 MSBD values must be calculated.) */
2905 insn.insn_opcode |= (va_arg (args, int)
2906 & OP_MASK_EXTMSBD) << OP_SH_EXTMSBD;
2917 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2921 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2926 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2932 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2937 int tmp = va_arg (args, int);
2939 insn.insn_opcode |= tmp << OP_SH_RT;
2940 insn.insn_opcode |= tmp << OP_SH_RD;
2946 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2953 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2957 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2961 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2965 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2969 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2976 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2982 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2983 assert (*r == BFD_RELOC_GPREL16
2984 || *r == BFD_RELOC_MIPS_LITERAL
2985 || *r == BFD_RELOC_MIPS_HIGHER
2986 || *r == BFD_RELOC_HI16_S
2987 || *r == BFD_RELOC_LO16
2988 || *r == BFD_RELOC_MIPS_GOT16
2989 || *r == BFD_RELOC_MIPS_CALL16
2990 || *r == BFD_RELOC_MIPS_GOT_DISP
2991 || *r == BFD_RELOC_MIPS_GOT_PAGE
2992 || *r == BFD_RELOC_MIPS_GOT_OFST
2993 || *r == BFD_RELOC_MIPS_GOT_LO16
2994 || *r == BFD_RELOC_MIPS_CALL_LO16
2995 || (ep->X_op == O_subtract
2996 && *r == BFD_RELOC_PCREL_LO16));
3000 *r = (bfd_reloc_code_real_type) va_arg (args, int);
3002 && (ep->X_op == O_constant
3003 || (ep->X_op == O_symbol
3004 && (*r == BFD_RELOC_MIPS_HIGHEST
3005 || *r == BFD_RELOC_HI16_S
3006 || *r == BFD_RELOC_HI16
3007 || *r == BFD_RELOC_GPREL16
3008 || *r == BFD_RELOC_MIPS_GOT_HI16
3009 || *r == BFD_RELOC_MIPS_CALL_HI16))
3010 || (ep->X_op == O_subtract
3011 && *r == BFD_RELOC_PCREL_HI16_S)));
3015 assert (ep != NULL);
3017 * This allows macro() to pass an immediate expression for
3018 * creating short branches without creating a symbol.
3019 * Note that the expression still might come from the assembly
3020 * input, in which case the value is not checked for range nor
3021 * is a relocation entry generated (yuck).
3023 if (ep->X_op == O_constant)
3025 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
3029 *r = BFD_RELOC_16_PCREL_S2;
3033 assert (ep != NULL);
3034 *r = BFD_RELOC_MIPS_JMP;
3038 insn.insn_opcode |= va_arg (args, unsigned long);
3047 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3049 append_insn (place, &insn, ep, r);
3053 mips16_macro_build (char *place, int *counter ATTRIBUTE_UNUSED,
3054 expressionS *ep, const char *name, const char *fmt,
3057 struct mips_cl_insn insn;
3058 bfd_reloc_code_real_type r[3]
3059 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3061 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3062 assert (insn.insn_mo);
3063 assert (strcmp (name, insn.insn_mo->name) == 0);
3065 while (strcmp (fmt, insn.insn_mo->args) != 0
3066 || insn.insn_mo->pinfo == INSN_MACRO)
3069 assert (insn.insn_mo->name);
3070 assert (strcmp (name, insn.insn_mo->name) == 0);
3073 insn.insn_opcode = insn.insn_mo->match;
3074 insn.use_extend = FALSE;
3093 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
3098 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
3102 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
3106 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
3116 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
3123 regno = va_arg (args, int);
3124 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3125 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3146 assert (ep != NULL);
3148 if (ep->X_op != O_constant)
3149 *r = (int) BFD_RELOC_UNUSED + c;
3152 mips16_immed (NULL, 0, c, ep->X_add_number, FALSE, FALSE,
3153 FALSE, &insn.insn_opcode, &insn.use_extend,
3156 *r = BFD_RELOC_UNUSED;
3162 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3169 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3171 append_insn (place, &insn, ep, r);
3175 * Generate a "jalr" instruction with a relocation hint to the called
3176 * function. This occurs in NewABI PIC code.
3179 macro_build_jalr (int icnt, expressionS *ep)
3188 macro_build (NULL, &icnt, NULL, "jalr", "d,s", RA, PIC_CALL_REG);
3190 fix_new_exp (frag_now, f - frag_now->fr_literal,
3191 4, ep, FALSE, BFD_RELOC_MIPS_JALR);
3195 * Generate a "lui" instruction.
3198 macro_build_lui (char *place, int *counter, expressionS *ep, int regnum)
3200 expressionS high_expr;
3201 struct mips_cl_insn insn;
3202 bfd_reloc_code_real_type r[3]
3203 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3204 const char *name = "lui";
3205 const char *fmt = "t,u";
3207 assert (! mips_opts.mips16);
3213 high_expr.X_op = O_constant;
3214 high_expr.X_add_number = ep->X_add_number;
3217 if (high_expr.X_op == O_constant)
3219 /* we can compute the instruction now without a relocation entry */
3220 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3222 *r = BFD_RELOC_UNUSED;
3226 assert (ep->X_op == O_symbol);
3227 /* _gp_disp is a special case, used from s_cpload. */
3228 assert (mips_pic == NO_PIC
3230 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0));
3231 *r = BFD_RELOC_HI16_S;
3235 * If the macro is about to expand into a second instruction,
3236 * print a warning if needed. We need to pass ip as a parameter
3237 * to generate a better warning message here...
3239 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3240 as_warn (_("Macro instruction expanded into multiple instructions"));
3243 ++*counter; /* bump instruction counter */
3245 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3246 assert (insn.insn_mo);
3247 assert (strcmp (name, insn.insn_mo->name) == 0);
3248 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3250 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3251 if (*r == BFD_RELOC_UNUSED)
3253 insn.insn_opcode |= high_expr.X_add_number;
3254 append_insn (place, &insn, NULL, r);
3257 append_insn (place, &insn, &high_expr, r);
3260 /* Generate a sequence of instructions to do a load or store from a constant
3261 offset off of a base register (breg) into/from a target register (treg),
3262 using AT if necessary. */
3264 macro_build_ldst_constoffset (char *place, int *counter, expressionS *ep,
3265 const char *op, int treg, int breg, int dbl)
3267 assert (ep->X_op == O_constant);
3269 /* Sign-extending 32-bit constants makes their handling easier. */
3270 if (! dbl && ! ((ep->X_add_number & ~((bfd_vma) 0x7fffffff))
3271 == ~((bfd_vma) 0x7fffffff)))
3273 if (ep->X_add_number & ~((bfd_vma) 0xffffffff))
3274 as_bad (_("constant too large"));
3276 ep->X_add_number = (((ep->X_add_number & 0xffffffff) ^ 0x80000000)
3280 /* Right now, this routine can only handle signed 32-bit constants. */
3281 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
3282 as_warn (_("operand overflow"));
3284 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
3286 /* Signed 16-bit offset will fit in the op. Easy! */
3287 macro_build (place, counter, ep, op, "t,o(b)", treg, BFD_RELOC_LO16,
3292 /* 32-bit offset, need multiple instructions and AT, like:
3293 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3294 addu $tempreg,$tempreg,$breg
3295 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3296 to handle the complete offset. */
3297 macro_build_lui (place, counter, ep, AT);
3300 macro_build (place, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT,
3304 macro_build (place, counter, ep, op, "t,o(b)", treg, BFD_RELOC_LO16,
3308 as_warn (_("Macro used $at after \".set noat\""));
3313 * Generates code to set the $at register to true (one)
3314 * if reg is less than the immediate expression.
3317 set_at (int *counter, int reg, int unsignedp)
3319 if (imm_expr.X_op == O_constant
3320 && imm_expr.X_add_number >= -0x8000
3321 && imm_expr.X_add_number < 0x8000)
3322 macro_build (NULL, counter, &imm_expr, unsignedp ? "sltiu" : "slti",
3323 "t,r,j", AT, reg, BFD_RELOC_LO16);
3326 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3327 macro_build (NULL, counter, NULL, unsignedp ? "sltu" : "slt",
3328 "d,v,t", AT, reg, AT);
3333 normalize_constant_expr (expressionS *ex)
3335 if (ex->X_op == O_constant && HAVE_32BIT_GPRS)
3336 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
3340 /* Warn if an expression is not a constant. */
3343 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
3345 if (ex->X_op == O_big)
3346 as_bad (_("unsupported large constant"));
3347 else if (ex->X_op != O_constant)
3348 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3350 normalize_constant_expr (ex);
3353 /* Count the leading zeroes by performing a binary chop. This is a
3354 bulky bit of source, but performance is a LOT better for the
3355 majority of values than a simple loop to count the bits:
3356 for (lcnt = 0; (lcnt < 32); lcnt++)
3357 if ((v) & (1 << (31 - lcnt)))
3359 However it is not code size friendly, and the gain will drop a bit
3360 on certain cached systems.
3362 #define COUNT_TOP_ZEROES(v) \
3363 (((v) & ~0xffff) == 0 \
3364 ? ((v) & ~0xff) == 0 \
3365 ? ((v) & ~0xf) == 0 \
3366 ? ((v) & ~0x3) == 0 \
3367 ? ((v) & ~0x1) == 0 \
3372 : ((v) & ~0x7) == 0 \
3375 : ((v) & ~0x3f) == 0 \
3376 ? ((v) & ~0x1f) == 0 \
3379 : ((v) & ~0x7f) == 0 \
3382 : ((v) & ~0xfff) == 0 \
3383 ? ((v) & ~0x3ff) == 0 \
3384 ? ((v) & ~0x1ff) == 0 \
3387 : ((v) & ~0x7ff) == 0 \
3390 : ((v) & ~0x3fff) == 0 \
3391 ? ((v) & ~0x1fff) == 0 \
3394 : ((v) & ~0x7fff) == 0 \
3397 : ((v) & ~0xffffff) == 0 \
3398 ? ((v) & ~0xfffff) == 0 \
3399 ? ((v) & ~0x3ffff) == 0 \
3400 ? ((v) & ~0x1ffff) == 0 \
3403 : ((v) & ~0x7ffff) == 0 \
3406 : ((v) & ~0x3fffff) == 0 \
3407 ? ((v) & ~0x1fffff) == 0 \
3410 : ((v) & ~0x7fffff) == 0 \
3413 : ((v) & ~0xfffffff) == 0 \
3414 ? ((v) & ~0x3ffffff) == 0 \
3415 ? ((v) & ~0x1ffffff) == 0 \
3418 : ((v) & ~0x7ffffff) == 0 \
3421 : ((v) & ~0x3fffffff) == 0 \
3422 ? ((v) & ~0x1fffffff) == 0 \
3425 : ((v) & ~0x7fffffff) == 0 \
3430 * This routine generates the least number of instructions necessary to load
3431 * an absolute expression value into a register.
3434 load_register (int *counter, int reg, expressionS *ep, int dbl)
3437 expressionS hi32, lo32;
3439 if (ep->X_op != O_big)
3441 assert (ep->X_op == O_constant);
3443 /* Sign-extending 32-bit constants makes their handling easier. */
3444 if (! dbl && ! ((ep->X_add_number & ~((bfd_vma) 0x7fffffff))
3445 == ~((bfd_vma) 0x7fffffff)))
3447 if (ep->X_add_number & ~((bfd_vma) 0xffffffff))
3448 as_bad (_("constant too large"));
3450 ep->X_add_number = (((ep->X_add_number & 0xffffffff) ^ 0x80000000)
3454 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
3456 /* We can handle 16 bit signed values with an addiu to
3457 $zero. No need to ever use daddiu here, since $zero and
3458 the result are always correct in 32 bit mode. */
3459 macro_build (NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3463 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3465 /* We can handle 16 bit unsigned values with an ori to
3467 macro_build (NULL, counter, ep, "ori", "t,r,i", reg, 0,
3471 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
3473 /* 32 bit values require an lui. */
3474 macro_build (NULL, counter, ep, "lui", "t,u", reg, BFD_RELOC_HI16);
3475 if ((ep->X_add_number & 0xffff) != 0)
3476 macro_build (NULL, counter, ep, "ori", "t,r,i", reg, reg,
3482 /* The value is larger than 32 bits. */
3484 if (HAVE_32BIT_GPRS)
3486 as_bad (_("Number (0x%lx) larger than 32 bits"),
3487 (unsigned long) ep->X_add_number);
3488 macro_build (NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3493 if (ep->X_op != O_big)
3496 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3497 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3498 hi32.X_add_number &= 0xffffffff;
3500 lo32.X_add_number &= 0xffffffff;
3504 assert (ep->X_add_number > 2);
3505 if (ep->X_add_number == 3)
3506 generic_bignum[3] = 0;
3507 else if (ep->X_add_number > 4)
3508 as_bad (_("Number larger than 64 bits"));
3509 lo32.X_op = O_constant;
3510 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3511 hi32.X_op = O_constant;
3512 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3515 if (hi32.X_add_number == 0)
3520 unsigned long hi, lo;
3522 if (hi32.X_add_number == (offsetT) 0xffffffff)
3524 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3526 macro_build (NULL, counter, &lo32, "addiu", "t,r,j", reg, 0,
3530 if (lo32.X_add_number & 0x80000000)
3532 macro_build (NULL, counter, &lo32, "lui", "t,u", reg,
3534 if (lo32.X_add_number & 0xffff)
3535 macro_build (NULL, counter, &lo32, "ori", "t,r,i", reg, reg,
3541 /* Check for 16bit shifted constant. We know that hi32 is
3542 non-zero, so start the mask on the first bit of the hi32
3547 unsigned long himask, lomask;
3551 himask = 0xffff >> (32 - shift);
3552 lomask = (0xffff << shift) & 0xffffffff;
3556 himask = 0xffff << (shift - 32);
3559 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3560 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3564 tmp.X_op = O_constant;
3566 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3567 | (lo32.X_add_number >> shift));
3569 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3570 macro_build (NULL, counter, &tmp, "ori", "t,r,i", reg, 0,
3572 macro_build (NULL, counter, NULL,
3573 (shift >= 32) ? "dsll32" : "dsll",
3575 (shift >= 32) ? shift - 32 : shift);
3580 while (shift <= (64 - 16));
3582 /* Find the bit number of the lowest one bit, and store the
3583 shifted value in hi/lo. */
3584 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3585 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3589 while ((lo & 1) == 0)
3594 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3600 while ((hi & 1) == 0)
3609 /* Optimize if the shifted value is a (power of 2) - 1. */
3610 if ((hi == 0 && ((lo + 1) & lo) == 0)
3611 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3613 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3618 /* This instruction will set the register to be all
3620 tmp.X_op = O_constant;
3621 tmp.X_add_number = (offsetT) -1;
3622 macro_build (NULL, counter, &tmp, "addiu", "t,r,j", reg, 0,
3627 macro_build (NULL, counter, NULL,
3628 (bit >= 32) ? "dsll32" : "dsll",
3630 (bit >= 32) ? bit - 32 : bit);
3632 macro_build (NULL, counter, NULL,
3633 (shift >= 32) ? "dsrl32" : "dsrl",
3635 (shift >= 32) ? shift - 32 : shift);
3640 /* Sign extend hi32 before calling load_register, because we can
3641 generally get better code when we load a sign extended value. */
3642 if ((hi32.X_add_number & 0x80000000) != 0)
3643 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3644 load_register (counter, reg, &hi32, 0);
3647 if ((lo32.X_add_number & 0xffff0000) == 0)
3651 macro_build (NULL, counter, NULL, "dsll32", "d,w,<", reg, freg, 0);
3659 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3661 macro_build (NULL, counter, &lo32, "lui", "t,u", reg,
3663 macro_build (NULL, counter, NULL, "dsrl32", "d,w,<", reg, reg, 0);
3669 macro_build (NULL, counter, NULL, "dsll", "d,w,<", reg, freg, 16);
3673 mid16.X_add_number >>= 16;
3674 macro_build (NULL, counter, &mid16, "ori", "t,r,i", reg, freg,
3676 macro_build (NULL, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3679 if ((lo32.X_add_number & 0xffff) != 0)
3680 macro_build (NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3684 /* Load an address into a register. */
3687 load_address (int *counter, int reg, expressionS *ep, int *used_at)
3691 if (ep->X_op != O_constant
3692 && ep->X_op != O_symbol)
3694 as_bad (_("expression too complex"));
3695 ep->X_op = O_constant;
3698 if (ep->X_op == O_constant)
3700 load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES);
3704 if (mips_pic == NO_PIC)
3706 /* If this is a reference to a GP relative symbol, we want
3707 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3709 lui $reg,<sym> (BFD_RELOC_HI16_S)
3710 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3711 If we have an addend, we always use the latter form.
3713 With 64bit address space and a usable $at we want
3714 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3715 lui $at,<sym> (BFD_RELOC_HI16_S)
3716 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3717 daddiu $at,<sym> (BFD_RELOC_LO16)
3721 If $at is already in use, we use a path which is suboptimal
3722 on superscalar processors.
3723 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3724 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3726 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3728 daddiu $reg,<sym> (BFD_RELOC_LO16)
3730 if (HAVE_64BIT_ADDRESSES)
3732 /* We don't do GP optimization for now because RELAX_ENCODE can't
3733 hold the data for such large chunks. */
3735 if (*used_at == 0 && ! mips_opts.noat)
3737 macro_build (p, counter, ep, "lui", "t,u",
3738 reg, BFD_RELOC_MIPS_HIGHEST);
3739 macro_build (p, counter, ep, "lui", "t,u",
3740 AT, BFD_RELOC_HI16_S);
3741 macro_build (p, counter, ep, "daddiu", "t,r,j",
3742 reg, reg, BFD_RELOC_MIPS_HIGHER);
3743 macro_build (p, counter, ep, "daddiu", "t,r,j",
3744 AT, AT, BFD_RELOC_LO16);
3745 macro_build (p, counter, NULL, "dsll32", "d,w,<", reg, reg, 0);
3746 macro_build (p, counter, NULL, "daddu", "d,v,t", reg, reg, AT);
3751 macro_build (p, counter, ep, "lui", "t,u",
3752 reg, BFD_RELOC_MIPS_HIGHEST);
3753 macro_build (p, counter, ep, "daddiu", "t,r,j",
3754 reg, reg, BFD_RELOC_MIPS_HIGHER);
3755 macro_build (p, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3756 macro_build (p, counter, ep, "daddiu", "t,r,j",
3757 reg, reg, BFD_RELOC_HI16_S);
3758 macro_build (p, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3759 macro_build (p, counter, ep, "daddiu", "t,r,j",
3760 reg, reg, BFD_RELOC_LO16);
3765 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3766 && ! nopic_need_relax (ep->X_add_symbol, 1))
3769 macro_build (NULL, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3770 mips_gp_register, BFD_RELOC_GPREL16);
3771 p = frag_var (rs_machine_dependent, 8, 0,
3772 RELAX_ENCODE (4, 8, 0, 4, 0,
3773 mips_opts.warn_about_macros),
3774 ep->X_add_symbol, 0, NULL);
3776 macro_build_lui (p, counter, ep, reg);
3779 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3783 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3787 /* If this is a reference to an external symbol, we want
3788 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3790 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3792 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3793 If there is a constant, it must be added in after.
3795 If we have NewABI, we want
3796 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
3797 unless we're referencing a global symbol with a non-zero
3798 offset, in which case cst must be added separately. */
3803 if (ep->X_add_number)
3805 frag_now->tc_frag_data.tc_fr_offset =
3806 ex.X_add_number = ep->X_add_number;
3807 ep->X_add_number = 0;
3808 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)",
3809 reg, BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3810 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3811 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3812 ex.X_op = O_constant;
3813 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3814 reg, reg, BFD_RELOC_LO16);
3815 p = frag_var (rs_machine_dependent, 8, 0,
3816 RELAX_ENCODE (8, 4, 0, 0, 0,
3817 mips_opts.warn_about_macros),
3818 ep->X_add_symbol, 0, NULL);
3819 ep->X_add_number = ex.X_add_number;
3822 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3823 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3827 /* To avoid confusion in tc_gen_reloc, we must ensure
3828 that this does not become a variant frag. */
3829 frag_wane (frag_now);
3835 ex.X_add_number = ep->X_add_number;
3836 ep->X_add_number = 0;
3838 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3839 BFD_RELOC_MIPS_GOT16,
3841 macro_build (NULL, counter, NULL, "nop", "");
3842 p = frag_var (rs_machine_dependent, 4, 0,
3843 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3844 ep->X_add_symbol, 0, NULL);
3845 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3848 if (ex.X_add_number != 0)
3850 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3851 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3852 ex.X_op = O_constant;
3853 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3854 reg, reg, BFD_RELOC_LO16);
3858 else if (mips_pic == SVR4_PIC)
3863 /* This is the large GOT case. If this is a reference to an
3864 external symbol, we want
3865 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3867 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3869 Otherwise, for a reference to a local symbol in old ABI, we want
3870 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3872 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3873 If there is a constant, it must be added in after.
3875 In the NewABI, for local symbols, with or without offsets, we want:
3876 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3877 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3883 frag_now->tc_frag_data.tc_fr_offset =
3884 ex.X_add_number = ep->X_add_number;
3885 ep->X_add_number = 0;
3886 macro_build (NULL, counter, ep, "lui", "t,u", reg,
3887 BFD_RELOC_MIPS_GOT_HI16);
3888 macro_build (NULL, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", reg,
3889 reg, mips_gp_register);
3890 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3891 BFD_RELOC_MIPS_GOT_LO16, reg);
3892 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3893 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3894 else if (ex.X_add_number)
3896 ex.X_op = O_constant;
3897 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3898 reg, reg, BFD_RELOC_LO16);
3901 ep->X_add_number = ex.X_add_number;
3902 p = frag_var (rs_machine_dependent, 8, 0,
3903 RELAX_ENCODE (ex.X_add_number ? 16 : 12, 8, 0, 4, 0,
3904 mips_opts.warn_about_macros),
3905 ep->X_add_symbol, 0, NULL);
3906 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3907 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
3908 macro_build (p + 4, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3909 reg, BFD_RELOC_MIPS_GOT_OFST);
3913 ex.X_add_number = ep->X_add_number;
3914 ep->X_add_number = 0;
3915 if (reg_needs_delay (mips_gp_register))
3920 macro_build (NULL, counter, ep, "lui", "t,u", reg,
3921 BFD_RELOC_MIPS_GOT_HI16);
3922 macro_build (NULL, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", reg,
3923 reg, mips_gp_register);
3924 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3925 BFD_RELOC_MIPS_GOT_LO16, reg);
3926 p = frag_var (rs_machine_dependent, 12 + off, 0,
3927 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3928 mips_opts.warn_about_macros),
3929 ep->X_add_symbol, 0, NULL);
3932 /* We need a nop before loading from $gp. This special
3933 check is required because the lui which starts the main
3934 instruction stream does not refer to $gp, and so will not
3935 insert the nop which may be required. */
3936 macro_build (p, counter, NULL, "nop", "");
3939 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3940 BFD_RELOC_MIPS_GOT16, mips_gp_register);
3942 macro_build (p, counter, NULL, "nop", "");
3944 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3947 if (ex.X_add_number != 0)
3949 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3950 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3951 ex.X_op = O_constant;
3952 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3953 reg, reg, BFD_RELOC_LO16);
3957 else if (mips_pic == EMBEDDED_PIC)
3960 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3962 macro_build (NULL, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3963 mips_gp_register, BFD_RELOC_GPREL16);
3969 /* Move the contents of register SOURCE into register DEST. */
3972 move_register (int *counter, int dest, int source)
3974 macro_build (NULL, counter, NULL, HAVE_32BIT_GPRS ? "addu" : "daddu",
3975 "d,v,t", dest, source, 0);
3980 * This routine implements the seemingly endless macro or synthesized
3981 * instructions and addressing modes in the mips assembly language. Many
3982 * of these macros are simple and are similar to each other. These could
3983 * probably be handled by some kind of table or grammar approach instead of
3984 * this verbose method. Others are not simple macros but are more like
3985 * optimizing code generation.
3986 * One interesting optimization is when several store macros appear
3987 * consecutively that would load AT with the upper half of the same address.
3988 * The ensuing load upper instructions are ommited. This implies some kind
3989 * of global optimization. We currently only optimize within a single macro.
3990 * For many of the load and store macros if the address is specified as a
3991 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3992 * first load register 'at' with zero and use it as the base register. The
3993 * mips assembler simply uses register $zero. Just one tiny optimization
3997 macro (struct mips_cl_insn *ip)
3999 register int treg, sreg, dreg, breg;
4016 bfd_reloc_code_real_type r;
4017 int hold_mips_optimize;
4019 assert (! mips_opts.mips16);
4021 treg = (ip->insn_opcode >> 16) & 0x1f;
4022 dreg = (ip->insn_opcode >> 11) & 0x1f;
4023 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
4024 mask = ip->insn_mo->mask;
4026 expr1.X_op = O_constant;
4027 expr1.X_op_symbol = NULL;
4028 expr1.X_add_symbol = NULL;
4029 expr1.X_add_number = 1;
4031 /* Unmatched fixups should not be put in the same frag as a relaxable
4032 macro. For example, suppose we have:
4036 addiu $4,$4,%lo(l1) # 3
4038 If instructions 1 and 2 were put in the same frag, md_frob_file would
4039 move the fixup for #1 after the fixups for the "unrelaxed" version of
4040 #2. This would confuse tc_gen_reloc, which expects the relocations
4041 for #2 to be the last for that frag.
4043 Also, if tc_gen_reloc sees certain relocations in a variant frag,
4044 it assumes that they belong to a relaxable macro. We mustn't put
4045 other uses of such relocations into a variant frag.
4047 To avoid both problems, finish the current frag it contains a
4048 %reloc() operator. The macro then goes into a new frag. */
4049 if (prev_reloc_op_frag == frag_now)
4051 frag_wane (frag_now);
4065 mips_emit_delays (TRUE);
4066 ++mips_opts.noreorder;
4067 mips_any_noreorder = 1;
4069 expr1.X_add_number = 8;
4070 macro_build (NULL, &icnt, &expr1, "bgez", "s,p", sreg);
4072 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4074 move_register (&icnt, dreg, sreg);
4075 macro_build (NULL, &icnt, NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0,
4078 --mips_opts.noreorder;
4099 if (imm_expr.X_op == O_constant
4100 && imm_expr.X_add_number >= -0x8000
4101 && imm_expr.X_add_number < 0x8000)
4103 macro_build (NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
4107 load_register (&icnt, AT, &imm_expr, dbl);
4108 macro_build (NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
4127 if (imm_expr.X_op == O_constant
4128 && imm_expr.X_add_number >= 0
4129 && imm_expr.X_add_number < 0x10000)
4131 if (mask != M_NOR_I)
4132 macro_build (NULL, &icnt, &imm_expr, s, "t,r,i", treg, sreg,
4136 macro_build (NULL, &icnt, &imm_expr, "ori", "t,r,i", treg, sreg,
4138 macro_build (NULL, &icnt, NULL, "nor", "d,v,t", treg, treg, 0);
4143 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4144 macro_build (NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
4161 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4163 macro_build (NULL, &icnt, &offset_expr, s, "s,t,p", sreg, 0);
4166 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4167 macro_build (NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
4175 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4181 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4185 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
4186 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4193 /* check for > max integer */
4194 maxnum = 0x7fffffff;
4195 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4202 if (imm_expr.X_op == O_constant
4203 && imm_expr.X_add_number >= maxnum
4204 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4207 /* result is always false */
4211 as_warn (_("Branch %s is always false (nop)"),
4213 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4218 as_warn (_("Branch likely %s is always false"),
4220 macro_build (NULL, &icnt, &offset_expr, "bnel", "s,t,p", 0, 0);
4224 if (imm_expr.X_op != O_constant)
4225 as_bad (_("Unsupported large constant"));
4226 ++imm_expr.X_add_number;
4230 if (mask == M_BGEL_I)
4232 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4234 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4238 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4240 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4244 maxnum = 0x7fffffff;
4245 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4252 maxnum = - maxnum - 1;
4253 if (imm_expr.X_op == O_constant
4254 && imm_expr.X_add_number <= maxnum
4255 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4258 /* result is always true */
4259 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4260 macro_build (NULL, &icnt, &offset_expr, "b", "p");
4263 set_at (&icnt, sreg, 0);
4264 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4275 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4279 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, treg);
4280 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4289 && imm_expr.X_op == O_constant
4290 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4292 if (imm_expr.X_op != O_constant)
4293 as_bad (_("Unsupported large constant"));
4294 ++imm_expr.X_add_number;
4298 if (mask == M_BGEUL_I)
4300 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4302 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4304 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4308 set_at (&icnt, sreg, 1);
4309 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4318 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4324 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4328 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
4329 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4338 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4344 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, sreg);
4345 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4354 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4360 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4364 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
4365 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4372 maxnum = 0x7fffffff;
4373 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4380 if (imm_expr.X_op == O_constant
4381 && imm_expr.X_add_number >= maxnum
4382 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4384 if (imm_expr.X_op != O_constant)
4385 as_bad (_("Unsupported large constant"));
4386 ++imm_expr.X_add_number;
4390 if (mask == M_BLTL_I)
4392 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4394 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4398 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4400 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4404 set_at (&icnt, sreg, 0);
4405 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4414 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4420 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, sreg);
4421 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4430 && imm_expr.X_op == O_constant
4431 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4433 if (imm_expr.X_op != O_constant)
4434 as_bad (_("Unsupported large constant"));
4435 ++imm_expr.X_add_number;
4439 if (mask == M_BLTUL_I)
4441 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4443 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4445 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4449 set_at (&icnt, sreg, 1);
4450 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4459 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4465 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4469 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
4470 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4481 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4485 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, treg);
4486 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4495 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
4497 as_bad (_("Unsupported large constant"));
4502 pos = (unsigned long) imm_expr.X_add_number;
4503 size = (unsigned long) imm2_expr.X_add_number;
4508 as_bad (_("Improper position (%lu)"), pos);
4511 if (size == 0 || size > 64
4512 || (pos + size - 1) > 63)
4514 as_bad (_("Improper extract size (%lu, position %lu)"),
4519 if (size <= 32 && pos < 32)
4524 else if (size <= 32)
4534 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
4535 fmt, treg, sreg, pos, size - 1);
4544 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
4546 as_bad (_("Unsupported large constant"));
4551 pos = (unsigned long) imm_expr.X_add_number;
4552 size = (unsigned long) imm2_expr.X_add_number;
4557 as_bad (_("Improper position (%lu)"), pos);
4560 if (size == 0 || size > 64
4561 || (pos + size - 1) > 63)
4563 as_bad (_("Improper insert size (%lu, position %lu)"),
4568 if (pos < 32 && (pos + size - 1) < 32)
4583 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
4584 fmt, treg, sreg, pos, pos + size - 1);
4600 as_warn (_("Divide by zero."));
4602 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", 0, 0, 7);
4604 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4608 mips_emit_delays (TRUE);
4609 ++mips_opts.noreorder;
4610 mips_any_noreorder = 1;
4613 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", treg, 0, 7);
4614 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "z,s,t",
4619 expr1.X_add_number = 8;
4620 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4621 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "z,s,t",
4623 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4625 expr1.X_add_number = -1;
4626 macro_build (NULL, &icnt, &expr1, dbl ? "daddiu" : "addiu", "t,r,j",
4627 AT, 0, BFD_RELOC_LO16);
4628 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4629 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4632 expr1.X_add_number = 1;
4633 macro_build (NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4635 macro_build (NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT, 31);
4639 expr1.X_add_number = 0x80000000;
4640 macro_build (NULL, &icnt, &expr1, "lui", "t,u", AT,
4645 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", sreg, AT, 6);
4646 /* We want to close the noreorder block as soon as possible, so
4647 that later insns are available for delay slot filling. */
4648 --mips_opts.noreorder;
4652 expr1.X_add_number = 8;
4653 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4654 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4656 /* We want to close the noreorder block as soon as possible, so
4657 that later insns are available for delay slot filling. */
4658 --mips_opts.noreorder;
4660 macro_build (NULL, &icnt, NULL, "break", "c", 6);
4662 macro_build (NULL, &icnt, NULL, s, "d", dreg);
4701 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4703 as_warn (_("Divide by zero."));
4705 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", 0, 0, 7);
4707 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4710 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4712 if (strcmp (s2, "mflo") == 0)
4713 move_register (&icnt, dreg, sreg);
4715 move_register (&icnt, dreg, 0);
4718 if (imm_expr.X_op == O_constant
4719 && imm_expr.X_add_number == -1
4720 && s[strlen (s) - 1] != 'u')
4722 if (strcmp (s2, "mflo") == 0)
4724 macro_build (NULL, &icnt, NULL, dbl ? "dneg" : "neg", "d,w",
4728 move_register (&icnt, dreg, 0);
4732 load_register (&icnt, AT, &imm_expr, dbl);
4733 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, AT);
4734 macro_build (NULL, &icnt, NULL, s2, "d", dreg);
4753 mips_emit_delays (TRUE);
4754 ++mips_opts.noreorder;
4755 mips_any_noreorder = 1;
4758 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", treg, 0, 7);
4759 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4760 /* We want to close the noreorder block as soon as possible, so
4761 that later insns are available for delay slot filling. */
4762 --mips_opts.noreorder;
4766 expr1.X_add_number = 8;
4767 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4768 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4770 /* We want to close the noreorder block as soon as possible, so
4771 that later insns are available for delay slot filling. */
4772 --mips_opts.noreorder;
4773 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4775 macro_build (NULL, &icnt, NULL, s2, "d", dreg);
4787 /* Load the address of a symbol into a register. If breg is not
4788 zero, we then add a base register to it. */
4790 if (dbl && HAVE_32BIT_GPRS)
4791 as_warn (_("dla used to load 32-bit register"));
4793 if (! dbl && HAVE_64BIT_OBJECTS)
4794 as_warn (_("la used to load 64-bit address"));
4796 if (offset_expr.X_op == O_constant
4797 && offset_expr.X_add_number >= -0x8000
4798 && offset_expr.X_add_number < 0x8000)
4800 macro_build (NULL, &icnt, &offset_expr,
4801 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4802 "t,r,j", treg, sreg, BFD_RELOC_LO16);
4817 /* When generating embedded PIC code, we permit expressions of
4820 la $treg,foo-bar($breg)
4821 where bar is an address in the current section. These are used
4822 when getting the addresses of functions. We don't permit
4823 X_add_number to be non-zero, because if the symbol is
4824 external the relaxing code needs to know that any addend is
4825 purely the offset to X_op_symbol. */
4826 if (mips_pic == EMBEDDED_PIC
4827 && offset_expr.X_op == O_subtract
4828 && (symbol_constant_p (offset_expr.X_op_symbol)
4829 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4830 : (symbol_equated_p (offset_expr.X_op_symbol)
4832 (symbol_get_value_expression (offset_expr.X_op_symbol)
4835 && (offset_expr.X_add_number == 0
4836 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4842 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
4843 BFD_RELOC_PCREL_HI16_S);
4847 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
4848 BFD_RELOC_PCREL_HI16_S);
4849 macro_build (NULL, &icnt, NULL,
4850 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4851 "d,v,t", tempreg, tempreg, breg);
4853 macro_build (NULL, &icnt, &offset_expr,
4854 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4855 "t,r,j", treg, tempreg, BFD_RELOC_PCREL_LO16);
4861 if (offset_expr.X_op != O_symbol
4862 && offset_expr.X_op != O_constant)
4864 as_bad (_("expression too complex"));
4865 offset_expr.X_op = O_constant;
4868 if (offset_expr.X_op == O_constant)
4869 load_register (&icnt, tempreg, &offset_expr,
4870 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4871 ? (dbl || HAVE_64BIT_ADDRESSES)
4872 : HAVE_64BIT_ADDRESSES));
4873 else if (mips_pic == NO_PIC)
4875 /* If this is a reference to a GP relative symbol, we want
4876 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4878 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4879 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4880 If we have a constant, we need two instructions anyhow,
4881 so we may as well always use the latter form.
4883 With 64bit address space and a usable $at we want
4884 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4885 lui $at,<sym> (BFD_RELOC_HI16_S)
4886 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4887 daddiu $at,<sym> (BFD_RELOC_LO16)
4889 daddu $tempreg,$tempreg,$at
4891 If $at is already in use, we use a path which is suboptimal
4892 on superscalar processors.
4893 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4894 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4896 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4898 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4901 if (HAVE_64BIT_ADDRESSES)
4903 /* We don't do GP optimization for now because RELAX_ENCODE can't
4904 hold the data for such large chunks. */
4906 if (used_at == 0 && ! mips_opts.noat)
4908 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4909 tempreg, BFD_RELOC_MIPS_HIGHEST);
4910 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4911 AT, BFD_RELOC_HI16_S);
4912 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4913 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
4914 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4915 AT, AT, BFD_RELOC_LO16);
4916 macro_build (p, &icnt, NULL, "dsll32", "d,w,<",
4917 tempreg, tempreg, 0);
4918 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
4919 tempreg, tempreg, AT);
4924 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4925 tempreg, BFD_RELOC_MIPS_HIGHEST);
4926 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4927 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
4928 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
4929 tempreg, tempreg, 16);
4930 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4931 tempreg, tempreg, BFD_RELOC_HI16_S);
4932 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
4933 tempreg, tempreg, 16);
4934 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4935 tempreg, tempreg, BFD_RELOC_LO16);
4940 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4941 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4944 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
4945 "t,r,j", tempreg, mips_gp_register,
4947 p = frag_var (rs_machine_dependent, 8, 0,
4948 RELAX_ENCODE (4, 8, 0, 4, 0,
4949 mips_opts.warn_about_macros),
4950 offset_expr.X_add_symbol, 0, NULL);
4952 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4955 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
4956 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
4959 else if (mips_pic == SVR4_PIC && ! mips_big_got && ! HAVE_NEWABI)
4961 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4963 /* If this is a reference to an external symbol, and there
4964 is no constant, we want
4965 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4966 or for lca or if tempreg is PIC_CALL_REG
4967 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4968 For a local symbol, we want
4969 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4971 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4973 If we have a small constant, and this is a reference to
4974 an external symbol, we want
4975 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4977 addiu $tempreg,$tempreg,<constant>
4978 For a local symbol, we want the same instruction
4979 sequence, but we output a BFD_RELOC_LO16 reloc on the
4982 If we have a large constant, and this is a reference to
4983 an external symbol, we want
4984 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4985 lui $at,<hiconstant>
4986 addiu $at,$at,<loconstant>
4987 addu $tempreg,$tempreg,$at
4988 For a local symbol, we want the same instruction
4989 sequence, but we output a BFD_RELOC_LO16 reloc on the
4993 expr1.X_add_number = offset_expr.X_add_number;
4994 offset_expr.X_add_number = 0;
4996 if (expr1.X_add_number == 0 && breg == 0
4997 && (call || tempreg == PIC_CALL_REG))
4998 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4999 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5000 tempreg, lw_reloc_type, mips_gp_register);
5001 if (expr1.X_add_number == 0)
5010 /* We're going to put in an addu instruction using
5011 tempreg, so we may as well insert the nop right
5013 macro_build (NULL, &icnt, NULL, "nop", "");
5016 p = frag_var (rs_machine_dependent, 8 - off, 0,
5017 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
5019 ? mips_opts.warn_about_macros
5021 offset_expr.X_add_symbol, 0, NULL);
5024 macro_build (p, &icnt, NULL, "nop", "");
5027 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
5028 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5029 /* FIXME: If breg == 0, and the next instruction uses
5030 $tempreg, then if this variant case is used an extra
5031 nop will be generated. */
5033 else if (expr1.X_add_number >= -0x8000
5034 && expr1.X_add_number < 0x8000)
5036 macro_build (NULL, &icnt, NULL, "nop", "");
5037 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5038 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5039 frag_var (rs_machine_dependent, 0, 0,
5040 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
5041 offset_expr.X_add_symbol, 0, NULL);
5047 /* If we are going to add in a base register, and the
5048 target register and the base register are the same,
5049 then we are using AT as a temporary register. Since
5050 we want to load the constant into AT, we add our
5051 current AT (from the global offset table) and the
5052 register into the register now, and pretend we were
5053 not using a base register. */
5058 macro_build (NULL, &icnt, NULL, "nop", "");
5059 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5066 /* Set mips_optimize around the lui instruction to avoid
5067 inserting an unnecessary nop after the lw. */
5068 hold_mips_optimize = mips_optimize;
5070 macro_build_lui (NULL, &icnt, &expr1, AT);
5071 mips_optimize = hold_mips_optimize;
5073 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5074 AT, AT, BFD_RELOC_LO16);
5075 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5076 tempreg, tempreg, AT);
5077 frag_var (rs_machine_dependent, 0, 0,
5078 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
5079 offset_expr.X_add_symbol, 0, NULL);
5083 else if (mips_pic == SVR4_PIC && ! mips_big_got && HAVE_NEWABI)
5086 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_DISP;
5089 /* If this is a reference to an external, and there is no
5090 constant, or local symbol (*), with or without a
5092 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5093 or for lca or if tempreg is PIC_CALL_REG
5094 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5096 If we have a small constant, and this is a reference to
5097 an external symbol, we want
5098 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5099 addiu $tempreg,$tempreg,<constant>
5101 If we have a large constant, and this is a reference to
5102 an external symbol, we want
5103 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5104 lui $at,<hiconstant>
5105 addiu $at,$at,<loconstant>
5106 addu $tempreg,$tempreg,$at
5108 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
5109 local symbols, even though it introduces an additional
5113 if (offset_expr.X_add_number == 0 && breg == 0
5114 && (call || tempreg == PIC_CALL_REG))
5115 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
5116 if (offset_expr.X_add_number)
5118 frag_now->tc_frag_data.tc_fr_offset =
5119 expr1.X_add_number = offset_expr.X_add_number;
5120 offset_expr.X_add_number = 0;
5122 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5123 "t,o(b)", tempreg, lw_reloc_type,
5126 if (expr1.X_add_number >= -0x8000
5127 && expr1.X_add_number < 0x8000)
5129 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5130 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5131 p = frag_var (rs_machine_dependent, 4, 0,
5132 RELAX_ENCODE (8, 4, 0, 0, 0, 0),
5133 offset_expr.X_add_symbol, 0, NULL);
5135 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
5139 /* If we are going to add in a base register, and the
5140 target register and the base register are the same,
5141 then we are using AT as a temporary register. Since
5142 we want to load the constant into AT, we add our
5143 current AT (from the global offset table) and the
5144 register into the register now, and pretend we were
5145 not using a base register. */
5150 assert (tempreg == AT);
5151 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN,
5152 "d,v,t", treg, AT, breg);
5157 macro_build_lui (NULL, &icnt, &expr1, AT);
5158 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5159 "t,r,j", AT, AT, BFD_RELOC_LO16);
5160 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5163 p = frag_var (rs_machine_dependent, 4 + adj, 0,
5164 RELAX_ENCODE (16 + adj, 4 + adj,
5166 offset_expr.X_add_symbol, 0, NULL);
5171 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5173 offset_expr.X_add_number = expr1.X_add_number;
5175 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5176 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_DISP,
5180 macro_build (p + 4, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5181 treg, tempreg, breg);
5188 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5189 "t,o(b)", tempreg, lw_reloc_type,
5191 if (lw_reloc_type != BFD_RELOC_MIPS_GOT_DISP)
5192 p = frag_var (rs_machine_dependent, 0, 0,
5193 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5194 offset_expr.X_add_symbol, 0, NULL);
5199 /* To avoid confusion in tc_gen_reloc, we must ensure
5200 that this does not become a variant frag. */
5201 frag_wane (frag_now);
5205 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
5209 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5210 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5211 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
5213 /* This is the large GOT case. If this is a reference to an
5214 external symbol, and there is no constant, we want
5215 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5216 addu $tempreg,$tempreg,$gp
5217 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5218 or for lca or if tempreg is PIC_CALL_REG
5219 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5220 addu $tempreg,$tempreg,$gp
5221 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5222 For a local symbol, we want
5223 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5225 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5227 If we have a small constant, and this is a reference to
5228 an external symbol, we want
5229 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5230 addu $tempreg,$tempreg,$gp
5231 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5233 addiu $tempreg,$tempreg,<constant>
5234 For a local symbol, we want
5235 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5237 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5239 If we have a large constant, and this is a reference to
5240 an external symbol, we want
5241 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5242 addu $tempreg,$tempreg,$gp
5243 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5244 lui $at,<hiconstant>
5245 addiu $at,$at,<loconstant>
5246 addu $tempreg,$tempreg,$at
5247 For a local symbol, we want
5248 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5249 lui $at,<hiconstant>
5250 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5251 addu $tempreg,$tempreg,$at
5254 expr1.X_add_number = offset_expr.X_add_number;
5255 offset_expr.X_add_number = 0;
5257 if (reg_needs_delay (mips_gp_register))
5261 if (expr1.X_add_number == 0 && breg == 0
5262 && (call || tempreg == PIC_CALL_REG))
5264 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5265 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5267 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5268 tempreg, lui_reloc_type);
5269 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5270 tempreg, tempreg, mips_gp_register);
5271 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5272 tempreg, lw_reloc_type, tempreg);
5273 if (expr1.X_add_number == 0)
5281 /* We're going to put in an addu instruction using
5282 tempreg, so we may as well insert the nop right
5284 macro_build (NULL, &icnt, NULL, "nop", "");
5288 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5289 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
5292 ? mips_opts.warn_about_macros
5294 offset_expr.X_add_symbol, 0, NULL);
5296 else if (expr1.X_add_number >= -0x8000
5297 && expr1.X_add_number < 0x8000)
5299 macro_build (NULL, &icnt, NULL, "nop", "");
5300 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5301 tempreg, tempreg, BFD_RELOC_LO16);
5303 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5304 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
5306 ? mips_opts.warn_about_macros
5308 offset_expr.X_add_symbol, 0, NULL);
5314 /* If we are going to add in a base register, and the
5315 target register and the base register are the same,
5316 then we are using AT as a temporary register. Since
5317 we want to load the constant into AT, we add our
5318 current AT (from the global offset table) and the
5319 register into the register now, and pretend we were
5320 not using a base register. */
5328 assert (tempreg == AT);
5329 macro_build (NULL, &icnt, NULL, "nop", "");
5330 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5336 /* Set mips_optimize around the lui instruction to avoid
5337 inserting an unnecessary nop after the lw. */
5338 hold_mips_optimize = mips_optimize;
5340 macro_build_lui (NULL, &icnt, &expr1, AT);
5341 mips_optimize = hold_mips_optimize;
5343 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5344 AT, AT, BFD_RELOC_LO16);
5345 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5348 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
5349 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
5352 ? mips_opts.warn_about_macros
5354 offset_expr.X_add_symbol, 0, NULL);
5361 /* This is needed because this instruction uses $gp, but
5362 the first instruction on the main stream does not. */
5363 macro_build (p, &icnt, NULL, "nop", "");
5367 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5368 tempreg, local_reloc_type, mips_gp_register);
5370 if (expr1.X_add_number >= -0x8000
5371 && expr1.X_add_number < 0x8000)
5373 macro_build (p, &icnt, NULL, "nop", "");
5375 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
5376 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5377 /* FIXME: If add_number is 0, and there was no base
5378 register, the external symbol case ended with a load,
5379 so if the symbol turns out to not be external, and
5380 the next instruction uses tempreg, an unnecessary nop
5381 will be inserted. */
5387 /* We must add in the base register now, as in the
5388 external symbol case. */
5389 assert (tempreg == AT);
5390 macro_build (p, &icnt, NULL, "nop", "");
5392 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5396 /* We set breg to 0 because we have arranged to add
5397 it in in both cases. */
5401 macro_build_lui (p, &icnt, &expr1, AT);
5403 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5404 AT, AT, BFD_RELOC_LO16);
5406 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5407 tempreg, tempreg, AT);
5411 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
5414 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5415 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5418 /* This is the large GOT case. If this is a reference to an
5419 external symbol, and there is no constant, we want
5420 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5421 add $tempreg,$tempreg,$gp
5422 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5423 or for lca or if tempreg is PIC_CALL_REG
5424 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5425 add $tempreg,$tempreg,$gp
5426 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5428 If we have a small constant, and this is a reference to
5429 an external symbol, we want
5430 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5431 add $tempreg,$tempreg,$gp
5432 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5433 addi $tempreg,$tempreg,<constant>
5435 If we have a large constant, and this is a reference to
5436 an external symbol, we want
5437 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5438 addu $tempreg,$tempreg,$gp
5439 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5440 lui $at,<hiconstant>
5441 addi $at,$at,<loconstant>
5442 add $tempreg,$tempreg,$at
5444 If we have NewABI, and we know it's a local symbol, we want
5445 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5446 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5447 otherwise we have to resort to GOT_HI16/GOT_LO16. */
5451 frag_now->tc_frag_data.tc_fr_offset =
5452 expr1.X_add_number = offset_expr.X_add_number;
5453 offset_expr.X_add_number = 0;
5455 if (expr1.X_add_number == 0 && breg == 0
5456 && (call || tempreg == PIC_CALL_REG))
5458 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5459 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5461 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5462 tempreg, lui_reloc_type);
5463 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5464 tempreg, tempreg, mips_gp_register);
5465 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5466 "t,o(b)", tempreg, lw_reloc_type, tempreg);
5468 if (expr1.X_add_number == 0)
5470 p = frag_var (rs_machine_dependent, 8, 0,
5471 RELAX_ENCODE (12, 8, 0, 4, 0,
5472 mips_opts.warn_about_macros),
5473 offset_expr.X_add_symbol, 0, NULL);
5475 else if (expr1.X_add_number >= -0x8000
5476 && expr1.X_add_number < 0x8000)
5478 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5479 tempreg, tempreg, BFD_RELOC_LO16);
5480 p = frag_var (rs_machine_dependent, 8, 0,
5481 RELAX_ENCODE (16, 8, 0, 4, 0,
5482 mips_opts.warn_about_macros),
5483 offset_expr.X_add_symbol, 0, NULL);
5485 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
5489 /* If we are going to add in a base register, and the
5490 target register and the base register are the same,
5491 then we are using AT as a temporary register. Since
5492 we want to load the constant into AT, we add our
5493 current AT (from the global offset table) and the
5494 register into the register now, and pretend we were
5495 not using a base register. */
5500 assert (tempreg == AT);
5501 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5507 /* Set mips_optimize around the lui instruction to avoid
5508 inserting an unnecessary nop after the lw. */
5509 macro_build_lui (NULL, &icnt, &expr1, AT);
5510 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5511 "t,r,j", AT, AT, BFD_RELOC_LO16);
5512 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5515 p = frag_var (rs_machine_dependent, 8 + adj, 0,
5516 RELAX_ENCODE (24 + adj, 8 + adj,
5519 ? mips_opts.warn_about_macros
5521 offset_expr.X_add_symbol, 0, NULL);
5526 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5528 offset_expr.X_add_number = expr1.X_add_number;
5529 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5530 tempreg, BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5531 macro_build (p + 4, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5532 tempreg, tempreg, BFD_RELOC_MIPS_GOT_OFST);
5535 macro_build (p + 8, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5536 treg, tempreg, breg);
5541 else if (mips_pic == EMBEDDED_PIC)
5544 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5546 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5547 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
5556 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
5557 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu";
5559 s = ADDRESS_ADD_INSN;
5561 macro_build (NULL, &icnt, NULL, s, "d,v,t", treg, tempreg, breg);
5570 /* The j instruction may not be used in PIC code, since it
5571 requires an absolute address. We convert it to a b
5573 if (mips_pic == NO_PIC)
5574 macro_build (NULL, &icnt, &offset_expr, "j", "a");
5576 macro_build (NULL, &icnt, &offset_expr, "b", "p");
5579 /* The jal instructions must be handled as macros because when
5580 generating PIC code they expand to multi-instruction
5581 sequences. Normally they are simple instructions. */
5586 if (mips_pic == NO_PIC
5587 || mips_pic == EMBEDDED_PIC)
5588 macro_build (NULL, &icnt, NULL, "jalr", "d,s", dreg, sreg);
5589 else if (mips_pic == SVR4_PIC)
5591 if (sreg != PIC_CALL_REG)
5592 as_warn (_("MIPS PIC call to register other than $25"));
5594 macro_build (NULL, &icnt, NULL, "jalr", "d,s", dreg, sreg);
5597 if (mips_cprestore_offset < 0)
5598 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5601 if (! mips_frame_reg_valid)
5603 as_warn (_("No .frame pseudo-op used in PIC code"));
5604 /* Quiet this warning. */
5605 mips_frame_reg_valid = 1;
5607 if (! mips_cprestore_valid)
5609 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5610 /* Quiet this warning. */
5611 mips_cprestore_valid = 1;
5613 expr1.X_add_number = mips_cprestore_offset;
5614 macro_build_ldst_constoffset (NULL, &icnt, &expr1,
5618 HAVE_64BIT_ADDRESSES);
5628 if (mips_pic == NO_PIC)
5629 macro_build (NULL, &icnt, &offset_expr, "jal", "a");
5630 else if (mips_pic == SVR4_PIC)
5634 /* If this is a reference to an external symbol, and we are
5635 using a small GOT, we want
5636 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5640 lw $gp,cprestore($sp)
5641 The cprestore value is set using the .cprestore
5642 pseudo-op. If we are using a big GOT, we want
5643 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5645 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5649 lw $gp,cprestore($sp)
5650 If the symbol is not external, we want
5651 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5653 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5656 lw $gp,cprestore($sp)
5658 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
5659 sequences above, minus nops, unless the symbol is local,
5660 which enables us to use GOT_PAGE/GOT_OFST (big got) or
5667 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5668 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5670 frag_var (rs_machine_dependent, 0, 0,
5671 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5672 offset_expr.X_add_symbol, 0, NULL);
5677 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5678 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_HI16);
5679 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5680 PIC_CALL_REG, PIC_CALL_REG, mips_gp_register);
5681 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5682 "t,o(b)", PIC_CALL_REG,
5683 BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5684 p = frag_var (rs_machine_dependent, 8, 0,
5685 RELAX_ENCODE (12, 8, 0, 4, 0, 0),
5686 offset_expr.X_add_symbol, 0, NULL);
5687 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5688 "t,o(b)", PIC_CALL_REG,
5689 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5690 macro_build (p + 4, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5691 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5692 BFD_RELOC_MIPS_GOT_OFST);
5695 macro_build_jalr (icnt, &offset_expr);
5702 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5703 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5705 macro_build (NULL, &icnt, NULL, "nop", "");
5706 p = frag_var (rs_machine_dependent, 4, 0,
5707 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5708 offset_expr.X_add_symbol, 0, NULL);
5714 if (reg_needs_delay (mips_gp_register))
5718 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5719 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_HI16);
5720 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5721 PIC_CALL_REG, PIC_CALL_REG, mips_gp_register);
5722 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5723 "t,o(b)", PIC_CALL_REG,
5724 BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5725 macro_build (NULL, &icnt, NULL, "nop", "");
5726 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5727 RELAX_ENCODE (16, 12 + gpdel, gpdel,
5729 offset_expr.X_add_symbol, 0, NULL);
5732 macro_build (p, &icnt, NULL, "nop", "");
5735 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5736 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
5739 macro_build (p, &icnt, NULL, "nop", "");
5742 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5743 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5745 macro_build_jalr (icnt, &offset_expr);
5747 if (mips_cprestore_offset < 0)
5748 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5751 if (! mips_frame_reg_valid)
5753 as_warn (_("No .frame pseudo-op used in PIC code"));
5754 /* Quiet this warning. */
5755 mips_frame_reg_valid = 1;
5757 if (! mips_cprestore_valid)
5759 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5760 /* Quiet this warning. */
5761 mips_cprestore_valid = 1;
5763 if (mips_opts.noreorder)
5764 macro_build (NULL, &icnt, NULL, "nop", "");
5765 expr1.X_add_number = mips_cprestore_offset;
5766 macro_build_ldst_constoffset (NULL, &icnt, &expr1,
5770 HAVE_64BIT_ADDRESSES);
5774 else if (mips_pic == EMBEDDED_PIC)
5776 macro_build (NULL, &icnt, &offset_expr, "bal", "p");
5777 /* The linker may expand the call to a longer sequence which
5778 uses $at, so we must break rather than return. */
5803 /* Itbl support may require additional care here. */
5808 /* Itbl support may require additional care here. */
5813 /* Itbl support may require additional care here. */
5818 /* Itbl support may require additional care here. */
5830 if (mips_opts.arch == CPU_R4650)
5832 as_bad (_("opcode not supported on this processor"));
5836 /* Itbl support may require additional care here. */
5841 /* Itbl support may require additional care here. */
5846 /* Itbl support may require additional care here. */
5866 if (breg == treg || coproc || lr)
5888 /* Itbl support may require additional care here. */
5893 /* Itbl support may require additional care here. */
5898 /* Itbl support may require additional care here. */
5903 /* Itbl support may require additional care here. */
5919 if (mips_opts.arch == CPU_R4650)
5921 as_bad (_("opcode not supported on this processor"));
5926 /* Itbl support may require additional care here. */
5930 /* Itbl support may require additional care here. */
5935 /* Itbl support may require additional care here. */
5947 /* Itbl support may require additional care here. */
5948 if (mask == M_LWC1_AB
5949 || mask == M_SWC1_AB
5950 || mask == M_LDC1_AB
5951 || mask == M_SDC1_AB
5960 /* Sign-extending 32-bit constants makes their handling easier.
5961 The HAVE_64BIT_GPRS... part is due to the linux kernel hack
5963 if ((! HAVE_64BIT_ADDRESSES
5964 && (! HAVE_64BIT_GPRS && offset_expr.X_op == O_constant))
5965 && (offset_expr.X_op == O_constant)
5966 && ! ((offset_expr.X_add_number & ~((bfd_vma) 0x7fffffff))
5967 == ~((bfd_vma) 0x7fffffff)))
5969 if (offset_expr.X_add_number & ~((bfd_vma) 0xffffffff))
5970 as_bad (_("constant too large"));
5972 offset_expr.X_add_number = (((offset_expr.X_add_number & 0xffffffff)
5973 ^ 0x80000000) - 0x80000000);
5976 /* For embedded PIC, we allow loads where the offset is calculated
5977 by subtracting a symbol in the current segment from an unknown
5978 symbol, relative to a base register, e.g.:
5979 <op> $treg, <sym>-<localsym>($breg)
5980 This is used by the compiler for switch statements. */
5981 if (mips_pic == EMBEDDED_PIC
5982 && offset_expr.X_op == O_subtract
5983 && (symbol_constant_p (offset_expr.X_op_symbol)
5984 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5985 : (symbol_equated_p (offset_expr.X_op_symbol)
5987 (symbol_get_value_expression (offset_expr.X_op_symbol)
5991 && (offset_expr.X_add_number == 0
5992 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5994 /* For this case, we output the instructions:
5995 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5996 addiu $tempreg,$tempreg,$breg
5997 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5998 If the relocation would fit entirely in 16 bits, it would be
6000 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
6001 instead, but that seems quite difficult. */
6002 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
6003 BFD_RELOC_PCREL_HI16_S);
6004 macro_build (NULL, &icnt, NULL,
6005 ((bfd_arch_bits_per_address (stdoutput) == 32
6006 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6007 ? "addu" : "daddu"),
6008 "d,v,t", tempreg, tempreg, breg);
6009 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6010 BFD_RELOC_PCREL_LO16, tempreg);
6016 if (offset_expr.X_op != O_constant
6017 && offset_expr.X_op != O_symbol)
6019 as_bad (_("expression too complex"));
6020 offset_expr.X_op = O_constant;
6023 /* A constant expression in PIC code can be handled just as it
6024 is in non PIC code. */
6025 if (mips_pic == NO_PIC
6026 || offset_expr.X_op == O_constant)
6030 /* If this is a reference to a GP relative symbol, and there
6031 is no base register, we want
6032 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6033 Otherwise, if there is no base register, we want
6034 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6035 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6036 If we have a constant, we need two instructions anyhow,
6037 so we always use the latter form.
6039 If we have a base register, and this is a reference to a
6040 GP relative symbol, we want
6041 addu $tempreg,$breg,$gp
6042 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6044 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6045 addu $tempreg,$tempreg,$breg
6046 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6047 With a constant we always use the latter case.
6049 With 64bit address space and no base register and $at usable,
6051 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6052 lui $at,<sym> (BFD_RELOC_HI16_S)
6053 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6056 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6057 If we have a base register, we want
6058 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6059 lui $at,<sym> (BFD_RELOC_HI16_S)
6060 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6064 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6066 Without $at we can't generate the optimal path for superscalar
6067 processors here since this would require two temporary registers.
6068 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6069 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6071 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6073 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6074 If we have a base register, we want
6075 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6076 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6078 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6080 daddu $tempreg,$tempreg,$breg
6081 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6083 If we have 64-bit addresses, as an optimization, for
6084 addresses which are 32-bit constants (e.g. kseg0/kseg1
6085 addresses) we fall back to the 32-bit address generation
6086 mechanism since it is more efficient. Note that due to
6087 the signed offset used by memory operations, the 32-bit
6088 range is shifted down by 32768 here. This code should
6089 probably attempt to generate 64-bit constants more
6090 efficiently in general.
6092 As an extension for architectures with 64-bit registers,
6093 we don't truncate 64-bit addresses given as literal
6094 constants down to 32 bits, to support existing practice
6095 in the mips64 Linux (the kernel), that compiles source
6096 files with -mabi=64, assembling them as o32 or n32 (with
6097 -Wa,-32 or -Wa,-n32). This is not beautiful, but since
6098 the whole kernel is loaded into a memory region that is
6099 addressable with sign-extended 32-bit addresses, it is
6100 wasteful to compute the upper 32 bits of every
6101 non-literal address, that takes more space and time.
6102 Some day this should probably be implemented as an
6103 assembler option, such that the kernel doesn't have to
6104 use such ugly hacks, even though it will still have to
6105 end up converting the binary to ELF32 for a number of
6106 platforms whose boot loaders don't support ELF64
6108 if ((HAVE_64BIT_ADDRESSES
6109 && ! (offset_expr.X_op == O_constant
6110 && IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000)))
6112 && offset_expr.X_op == O_constant
6113 && ! IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000)))
6117 /* We don't do GP optimization for now because RELAX_ENCODE can't
6118 hold the data for such large chunks. */
6120 if (used_at == 0 && ! mips_opts.noat)
6122 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6123 tempreg, BFD_RELOC_MIPS_HIGHEST);
6124 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6125 AT, BFD_RELOC_HI16_S);
6126 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6127 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
6129 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
6131 macro_build (p, &icnt, NULL, "dsll32", "d,w,<",
6132 tempreg, tempreg, 0);
6133 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
6134 tempreg, tempreg, AT);
6135 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6136 BFD_RELOC_LO16, tempreg);
6141 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6142 tempreg, BFD_RELOC_MIPS_HIGHEST);
6143 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6144 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
6145 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
6146 tempreg, tempreg, 16);
6147 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6148 tempreg, tempreg, BFD_RELOC_HI16_S);
6149 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
6150 tempreg, tempreg, 16);
6152 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
6153 tempreg, tempreg, breg);
6154 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6155 BFD_RELOC_LO16, tempreg);
6161 if (offset_expr.X_op == O_constant
6162 && ! IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000))
6163 as_bad (_("load/store address overflow (max 32 bits)"));
6167 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6168 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6173 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6174 BFD_RELOC_GPREL16, mips_gp_register);
6175 p = frag_var (rs_machine_dependent, 8, 0,
6176 RELAX_ENCODE (4, 8, 0, 4, 0,
6177 (mips_opts.warn_about_macros
6179 && mips_opts.noat))),
6180 offset_expr.X_add_symbol, 0, NULL);
6183 macro_build_lui (p, &icnt, &offset_expr, tempreg);
6186 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6187 BFD_RELOC_LO16, tempreg);
6191 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6192 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6197 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6198 tempreg, breg, mips_gp_register);
6199 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6200 BFD_RELOC_GPREL16, tempreg);
6201 p = frag_var (rs_machine_dependent, 12, 0,
6202 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
6203 offset_expr.X_add_symbol, 0, NULL);
6205 macro_build_lui (p, &icnt, &offset_expr, tempreg);
6208 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6209 tempreg, tempreg, breg);
6212 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6213 BFD_RELOC_LO16, tempreg);
6216 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6219 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
6221 /* If this is a reference to an external symbol, we want
6222 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6224 <op> $treg,0($tempreg)
6226 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6228 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6229 <op> $treg,0($tempreg)
6232 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6233 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6235 If there is a base register, we add it to $tempreg before
6236 the <op>. If there is a constant, we stick it in the
6237 <op> instruction. We don't handle constants larger than
6238 16 bits, because we have no way to load the upper 16 bits
6239 (actually, we could handle them for the subset of cases
6240 in which we are not using $at). */
6241 assert (offset_expr.X_op == O_symbol);
6244 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6245 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_PAGE,
6248 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6249 tempreg, tempreg, breg);
6250 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6251 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6258 expr1.X_add_number = offset_expr.X_add_number;
6259 offset_expr.X_add_number = 0;
6260 if (expr1.X_add_number < -0x8000
6261 || expr1.X_add_number >= 0x8000)
6262 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6264 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6265 tempreg, lw_reloc_type, mips_gp_register);
6266 macro_build (NULL, &icnt, NULL, "nop", "");
6267 p = frag_var (rs_machine_dependent, 4, 0,
6268 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
6269 offset_expr.X_add_symbol, 0, NULL);
6270 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
6271 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
6273 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6274 tempreg, tempreg, breg);
6275 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6278 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
6283 /* If this is a reference to an external symbol, we want
6284 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6285 addu $tempreg,$tempreg,$gp
6286 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6287 <op> $treg,0($tempreg)
6289 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6291 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6292 <op> $treg,0($tempreg)
6293 If there is a base register, we add it to $tempreg before
6294 the <op>. If there is a constant, we stick it in the
6295 <op> instruction. We don't handle constants larger than
6296 16 bits, because we have no way to load the upper 16 bits
6297 (actually, we could handle them for the subset of cases
6298 in which we are not using $at). */
6299 assert (offset_expr.X_op == O_symbol);
6300 expr1.X_add_number = offset_expr.X_add_number;
6301 offset_expr.X_add_number = 0;
6302 if (expr1.X_add_number < -0x8000
6303 || expr1.X_add_number >= 0x8000)
6304 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6305 if (reg_needs_delay (mips_gp_register))
6310 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
6311 BFD_RELOC_MIPS_GOT_HI16);
6312 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6313 tempreg, tempreg, mips_gp_register);
6314 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6315 tempreg, BFD_RELOC_MIPS_GOT_LO16, tempreg);
6316 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
6317 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
6318 offset_expr.X_add_symbol, 0, NULL);
6321 macro_build (p, &icnt, NULL, "nop", "");
6324 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6325 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6327 macro_build (p, &icnt, NULL, "nop", "");
6329 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
6330 tempreg, tempreg, BFD_RELOC_LO16);
6332 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6333 tempreg, tempreg, breg);
6334 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6337 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
6340 int bregsz = breg != 0 ? 4 : 0;
6342 /* If this is a reference to an external symbol, we want
6343 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6344 add $tempreg,$tempreg,$gp
6345 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6346 <op> $treg,<ofst>($tempreg)
6347 Otherwise, for local symbols, we want:
6348 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6349 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6350 assert (offset_expr.X_op == O_symbol);
6352 frag_now->tc_frag_data.tc_fr_offset =
6353 expr1.X_add_number = offset_expr.X_add_number;
6354 offset_expr.X_add_number = 0;
6355 if (expr1.X_add_number < -0x8000
6356 || expr1.X_add_number >= 0x8000)
6357 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6358 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
6359 BFD_RELOC_MIPS_GOT_HI16);
6360 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6361 tempreg, tempreg, mips_gp_register);
6362 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6363 tempreg, BFD_RELOC_MIPS_GOT_LO16, tempreg);
6365 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6366 tempreg, tempreg, breg);
6367 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6370 offset_expr.X_add_number = expr1.X_add_number;
6371 p = frag_var (rs_machine_dependent, 12 + bregsz, 0,
6372 RELAX_ENCODE (16 + bregsz, 8 + bregsz,
6373 0, 4 + bregsz, 0, 0),
6374 offset_expr.X_add_symbol, 0, NULL);
6375 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6376 tempreg, BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6378 macro_build (p + 4, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6379 tempreg, tempreg, breg);
6380 macro_build (p + 4 + bregsz, &icnt, &offset_expr, s, fmt, treg,
6381 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6383 else if (mips_pic == EMBEDDED_PIC)
6385 /* If there is no base register, we want
6386 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6387 If there is a base register, we want
6388 addu $tempreg,$breg,$gp
6389 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6391 assert (offset_expr.X_op == O_symbol);
6394 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6395 BFD_RELOC_GPREL16, mips_gp_register);
6400 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6401 tempreg, breg, mips_gp_register);
6402 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6403 BFD_RELOC_GPREL16, tempreg);
6416 load_register (&icnt, treg, &imm_expr, 0);
6420 load_register (&icnt, treg, &imm_expr, 1);
6424 if (imm_expr.X_op == O_constant)
6426 load_register (&icnt, AT, &imm_expr, 0);
6427 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg);
6432 assert (offset_expr.X_op == O_symbol
6433 && strcmp (segment_name (S_GET_SEGMENT
6434 (offset_expr.X_add_symbol)),
6436 && offset_expr.X_add_number == 0);
6437 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", treg,
6438 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6443 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6444 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6445 order 32 bits of the value and the low order 32 bits are either
6446 zero or in OFFSET_EXPR. */
6447 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6449 if (HAVE_64BIT_GPRS)
6450 load_register (&icnt, treg, &imm_expr, 1);
6455 if (target_big_endian)
6467 load_register (&icnt, hreg, &imm_expr, 0);
6470 if (offset_expr.X_op == O_absent)
6471 move_register (&icnt, lreg, 0);
6474 assert (offset_expr.X_op == O_constant);
6475 load_register (&icnt, lreg, &offset_expr, 0);
6482 /* We know that sym is in the .rdata section. First we get the
6483 upper 16 bits of the address. */
6484 if (mips_pic == NO_PIC)
6486 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6488 else if (mips_pic == SVR4_PIC)
6490 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6491 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6493 else if (mips_pic == EMBEDDED_PIC)
6495 /* For embedded PIC we pick up the entire address off $gp in
6496 a single instruction. */
6497 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
6498 AT, mips_gp_register, BFD_RELOC_GPREL16);
6499 offset_expr.X_op = O_constant;
6500 offset_expr.X_add_number = 0;
6505 /* Now we load the register(s). */
6506 if (HAVE_64BIT_GPRS)
6507 macro_build (NULL, &icnt, &offset_expr, "ld", "t,o(b)", treg,
6508 BFD_RELOC_LO16, AT);
6511 macro_build (NULL, &icnt, &offset_expr, "lw", "t,o(b)", treg,
6512 BFD_RELOC_LO16, AT);
6515 /* FIXME: How in the world do we deal with the possible
6517 offset_expr.X_add_number += 4;
6518 macro_build (NULL, &icnt, &offset_expr, "lw", "t,o(b)",
6519 treg + 1, BFD_RELOC_LO16, AT);
6523 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6524 does not become a variant frag. */
6525 frag_wane (frag_now);
6531 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6532 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6533 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6534 the value and the low order 32 bits are either zero or in
6536 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6538 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
6539 if (HAVE_64BIT_FPRS)
6541 assert (HAVE_64BIT_GPRS);
6542 macro_build (NULL, &icnt, NULL, "dmtc1", "t,S", AT, treg);
6546 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg + 1);
6547 if (offset_expr.X_op == O_absent)
6548 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", 0, treg);
6551 assert (offset_expr.X_op == O_constant);
6552 load_register (&icnt, AT, &offset_expr, 0);
6553 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg);
6559 assert (offset_expr.X_op == O_symbol
6560 && offset_expr.X_add_number == 0);
6561 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
6562 if (strcmp (s, ".lit8") == 0)
6564 if (mips_opts.isa != ISA_MIPS1)
6566 macro_build (NULL, &icnt, &offset_expr, "ldc1", "T,o(b)", treg,
6567 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6570 breg = mips_gp_register;
6571 r = BFD_RELOC_MIPS_LITERAL;
6576 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
6577 if (mips_pic == SVR4_PIC)
6578 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6579 "t,o(b)", AT, BFD_RELOC_MIPS_GOT16,
6583 /* FIXME: This won't work for a 64 bit address. */
6584 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6587 if (mips_opts.isa != ISA_MIPS1)
6589 macro_build (NULL, &icnt, &offset_expr, "ldc1", "T,o(b)", treg,
6590 BFD_RELOC_LO16, AT);
6592 /* To avoid confusion in tc_gen_reloc, we must ensure
6593 that this does not become a variant frag. */
6594 frag_wane (frag_now);
6605 if (mips_opts.arch == CPU_R4650)
6607 as_bad (_("opcode not supported on this processor"));
6610 /* Even on a big endian machine $fn comes before $fn+1. We have
6611 to adjust when loading from memory. */
6614 assert (mips_opts.isa == ISA_MIPS1);
6615 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6616 target_big_endian ? treg + 1 : treg, r, breg);
6617 /* FIXME: A possible overflow which I don't know how to deal
6619 offset_expr.X_add_number += 4;
6620 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6621 target_big_endian ? treg : treg + 1, r, breg);
6623 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6624 does not become a variant frag. */
6625 frag_wane (frag_now);
6634 * The MIPS assembler seems to check for X_add_number not
6635 * being double aligned and generating:
6638 * addiu at,at,%lo(foo+1)
6641 * But, the resulting address is the same after relocation so why
6642 * generate the extra instruction?
6644 if (mips_opts.arch == CPU_R4650)
6646 as_bad (_("opcode not supported on this processor"));
6649 /* Itbl support may require additional care here. */
6651 if (mips_opts.isa != ISA_MIPS1)
6662 if (mips_opts.arch == CPU_R4650)
6664 as_bad (_("opcode not supported on this processor"));
6668 if (mips_opts.isa != ISA_MIPS1)
6676 /* Itbl support may require additional care here. */
6681 if (HAVE_64BIT_GPRS)
6692 if (HAVE_64BIT_GPRS)
6702 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6703 loads for the case of doing a pair of loads to simulate an 'ld'.
6704 This is not currently done by the compiler, and assembly coders
6705 writing embedded-pic code can cope. */
6707 if (offset_expr.X_op != O_symbol
6708 && offset_expr.X_op != O_constant)
6710 as_bad (_("expression too complex"));
6711 offset_expr.X_op = O_constant;
6714 /* Even on a big endian machine $fn comes before $fn+1. We have
6715 to adjust when loading from memory. We set coproc if we must
6716 load $fn+1 first. */
6717 /* Itbl support may require additional care here. */
6718 if (! target_big_endian)
6721 if (mips_pic == NO_PIC
6722 || offset_expr.X_op == O_constant)
6726 /* If this is a reference to a GP relative symbol, we want
6727 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6728 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6729 If we have a base register, we use this
6731 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6732 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6733 If this is not a GP relative symbol, we want
6734 lui $at,<sym> (BFD_RELOC_HI16_S)
6735 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6736 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6737 If there is a base register, we add it to $at after the
6738 lui instruction. If there is a constant, we always use
6740 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6741 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6753 tempreg = mips_gp_register;
6760 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6761 AT, breg, mips_gp_register);
6767 /* Itbl support may require additional care here. */
6768 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6769 coproc ? treg + 1 : treg,
6770 BFD_RELOC_GPREL16, tempreg);
6771 offset_expr.X_add_number += 4;
6773 /* Set mips_optimize to 2 to avoid inserting an
6775 hold_mips_optimize = mips_optimize;
6777 /* Itbl support may require additional care here. */
6778 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6779 coproc ? treg : treg + 1,
6780 BFD_RELOC_GPREL16, tempreg);
6781 mips_optimize = hold_mips_optimize;
6783 p = frag_var (rs_machine_dependent, 12 + off, 0,
6784 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6785 used_at && mips_opts.noat),
6786 offset_expr.X_add_symbol, 0, NULL);
6788 /* We just generated two relocs. When tc_gen_reloc
6789 handles this case, it will skip the first reloc and
6790 handle the second. The second reloc already has an
6791 extra addend of 4, which we added above. We must
6792 subtract it out, and then subtract another 4 to make
6793 the first reloc come out right. The second reloc
6794 will come out right because we are going to add 4 to
6795 offset_expr when we build its instruction below.
6797 If we have a symbol, then we don't want to include
6798 the offset, because it will wind up being included
6799 when we generate the reloc. */
6801 if (offset_expr.X_op == O_constant)
6802 offset_expr.X_add_number -= 8;
6805 offset_expr.X_add_number = -4;
6806 offset_expr.X_op = O_constant;
6809 macro_build_lui (p, &icnt, &offset_expr, AT);
6814 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6819 /* Itbl support may require additional care here. */
6820 macro_build (p, &icnt, &offset_expr, s, fmt,
6821 coproc ? treg + 1 : treg,
6822 BFD_RELOC_LO16, AT);
6825 /* FIXME: How do we handle overflow here? */
6826 offset_expr.X_add_number += 4;
6827 /* Itbl support may require additional care here. */
6828 macro_build (p, &icnt, &offset_expr, s, fmt,
6829 coproc ? treg : treg + 1,
6830 BFD_RELOC_LO16, AT);
6832 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6836 /* If this is a reference to an external symbol, we want
6837 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6842 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6844 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6845 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6846 If there is a base register we add it to $at before the
6847 lwc1 instructions. If there is a constant we include it
6848 in the lwc1 instructions. */
6850 expr1.X_add_number = offset_expr.X_add_number;
6851 offset_expr.X_add_number = 0;
6852 if (expr1.X_add_number < -0x8000
6853 || expr1.X_add_number >= 0x8000 - 4)
6854 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6859 frag_grow (24 + off);
6860 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6861 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6862 macro_build (NULL, &icnt, NULL, "nop", "");
6864 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6866 /* Itbl support may require additional care here. */
6867 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6868 BFD_RELOC_LO16, AT);
6869 expr1.X_add_number += 4;
6871 /* Set mips_optimize to 2 to avoid inserting an undesired
6873 hold_mips_optimize = mips_optimize;
6875 /* Itbl support may require additional care here. */
6876 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6877 BFD_RELOC_LO16, AT);
6878 mips_optimize = hold_mips_optimize;
6880 (void) frag_var (rs_machine_dependent, 0, 0,
6881 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6882 offset_expr.X_add_symbol, 0, NULL);
6884 else if (mips_pic == SVR4_PIC)
6889 /* If this is a reference to an external symbol, we want
6890 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6892 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6897 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6899 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6900 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6901 If there is a base register we add it to $at before the
6902 lwc1 instructions. If there is a constant we include it
6903 in the lwc1 instructions. */
6905 expr1.X_add_number = offset_expr.X_add_number;
6906 offset_expr.X_add_number = 0;
6907 if (expr1.X_add_number < -0x8000
6908 || expr1.X_add_number >= 0x8000 - 4)
6909 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6910 if (reg_needs_delay (mips_gp_register))
6919 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", AT,
6920 BFD_RELOC_MIPS_GOT_HI16);
6921 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6922 AT, AT, mips_gp_register);
6923 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6924 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
6925 macro_build (NULL, &icnt, NULL, "nop", "");
6927 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6929 /* Itbl support may require additional care here. */
6930 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6931 BFD_RELOC_LO16, AT);
6932 expr1.X_add_number += 4;
6934 /* Set mips_optimize to 2 to avoid inserting an undesired
6936 hold_mips_optimize = mips_optimize;
6938 /* Itbl support may require additional care here. */
6939 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6940 BFD_RELOC_LO16, AT);
6941 mips_optimize = hold_mips_optimize;
6942 expr1.X_add_number -= 4;
6944 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6945 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6946 8 + gpdel + off, 1, 0),
6947 offset_expr.X_add_symbol, 0, NULL);
6950 macro_build (p, &icnt, NULL, "nop", "");
6953 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6954 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6956 macro_build (p, &icnt, NULL, "nop", "");
6960 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6964 /* Itbl support may require additional care here. */
6965 macro_build (p, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6966 BFD_RELOC_LO16, AT);
6968 expr1.X_add_number += 4;
6970 /* Set mips_optimize to 2 to avoid inserting an undesired
6972 hold_mips_optimize = mips_optimize;
6974 /* Itbl support may require additional care here. */
6975 macro_build (p, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6976 BFD_RELOC_LO16, AT);
6977 mips_optimize = hold_mips_optimize;
6979 else if (mips_pic == EMBEDDED_PIC)
6981 /* If there is no base register, we use
6982 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6983 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6984 If we have a base register, we use
6986 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6987 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6991 tempreg = mips_gp_register;
6996 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6997 AT, breg, mips_gp_register);
7002 /* Itbl support may require additional care here. */
7003 macro_build (NULL, &icnt, &offset_expr, s, fmt,
7004 coproc ? treg + 1 : treg,
7005 BFD_RELOC_GPREL16, tempreg);
7006 offset_expr.X_add_number += 4;
7007 /* Itbl support may require additional care here. */
7008 macro_build (NULL, &icnt, &offset_expr, s, fmt,
7009 coproc ? treg : treg + 1,
7010 BFD_RELOC_GPREL16, tempreg);
7026 assert (HAVE_32BIT_ADDRESSES);
7027 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7028 BFD_RELOC_LO16, breg);
7029 offset_expr.X_add_number += 4;
7030 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
7031 BFD_RELOC_LO16, breg);
7034 /* New code added to support COPZ instructions.
7035 This code builds table entries out of the macros in mip_opcodes.
7036 R4000 uses interlocks to handle coproc delays.
7037 Other chips (like the R3000) require nops to be inserted for delays.
7039 FIXME: Currently, we require that the user handle delays.
7040 In order to fill delay slots for non-interlocked chips,
7041 we must have a way to specify delays based on the coprocessor.
7042 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
7043 What are the side-effects of the cop instruction?
7044 What cache support might we have and what are its effects?
7045 Both coprocessor & memory require delays. how long???
7046 What registers are read/set/modified?
7048 If an itbl is provided to interpret cop instructions,
7049 this knowledge can be encoded in the itbl spec. */
7063 /* For now we just do C (same as Cz). The parameter will be
7064 stored in insn_opcode by mips_ip. */
7065 macro_build (NULL, &icnt, NULL, s, "C", ip->insn_opcode);
7069 move_register (&icnt, dreg, sreg);
7072 #ifdef LOSING_COMPILER
7074 /* Try and see if this is a new itbl instruction.
7075 This code builds table entries out of the macros in mip_opcodes.
7076 FIXME: For now we just assemble the expression and pass it's
7077 value along as a 32-bit immediate.
7078 We may want to have the assembler assemble this value,
7079 so that we gain the assembler's knowledge of delay slots,
7081 Would it be more efficient to use mask (id) here? */
7082 if (itbl_have_entries
7083 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
7085 s = ip->insn_mo->name;
7087 coproc = ITBL_DECODE_PNUM (immed_expr);;
7088 macro_build (NULL, &icnt, &immed_expr, s, "C");
7095 as_warn (_("Macro used $at after \".set noat\""));
7099 macro2 (struct mips_cl_insn *ip)
7101 register int treg, sreg, dreg, breg;
7117 bfd_reloc_code_real_type r;
7120 treg = (ip->insn_opcode >> 16) & 0x1f;
7121 dreg = (ip->insn_opcode >> 11) & 0x1f;
7122 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
7123 mask = ip->insn_mo->mask;
7125 expr1.X_op = O_constant;
7126 expr1.X_op_symbol = NULL;
7127 expr1.X_add_symbol = NULL;
7128 expr1.X_add_number = 1;
7132 #endif /* LOSING_COMPILER */
7137 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "s,t",
7139 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7145 /* The MIPS assembler some times generates shifts and adds. I'm
7146 not trying to be that fancy. GCC should do this for us
7148 load_register (&icnt, AT, &imm_expr, dbl);
7149 macro_build (NULL, &icnt, NULL, dbl ? "dmult" : "mult", "s,t",
7151 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7164 mips_emit_delays (TRUE);
7165 ++mips_opts.noreorder;
7166 mips_any_noreorder = 1;
7168 load_register (&icnt, AT, &imm_expr, dbl);
7169 macro_build (NULL, &icnt, NULL, dbl ? "dmult" : "mult", "s,t",
7170 sreg, imm ? AT : treg);
7171 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7172 macro_build (NULL, &icnt, NULL, dbl ? "dsra32" : "sra", "d,w,<",
7174 macro_build (NULL, &icnt, NULL, "mfhi", "d", AT);
7176 macro_build (NULL, &icnt, NULL, "tne", "s,t,q", dreg, AT, 6);
7179 expr1.X_add_number = 8;
7180 macro_build (NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
7181 macro_build (NULL, &icnt, NULL, "nop", "", 0);
7182 macro_build (NULL, &icnt, NULL, "break", "c", 6);
7184 --mips_opts.noreorder;
7185 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7198 mips_emit_delays (TRUE);
7199 ++mips_opts.noreorder;
7200 mips_any_noreorder = 1;
7202 load_register (&icnt, AT, &imm_expr, dbl);
7203 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "s,t",
7204 sreg, imm ? AT : treg);
7205 macro_build (NULL, &icnt, NULL, "mfhi", "d", AT);
7206 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7208 macro_build (NULL, &icnt, NULL, "tne", "s,t,q", AT, 0, 6);
7211 expr1.X_add_number = 8;
7212 macro_build (NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
7213 macro_build (NULL, &icnt, NULL, "nop", "", 0);
7214 macro_build (NULL, &icnt, NULL, "break", "c", 6);
7216 --mips_opts.noreorder;
7220 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7232 macro_build (NULL, &icnt, NULL, "dnegu", "d,w", tempreg, treg);
7233 macro_build (NULL, &icnt, NULL, "drorv", "d,t,s", dreg, sreg,
7239 macro_build (NULL, &icnt, NULL, "dsubu", "d,v,t", AT, 0, treg);
7240 macro_build (NULL, &icnt, NULL, "dsrlv", "d,t,s", AT, sreg, AT);
7241 macro_build (NULL, &icnt, NULL, "dsllv", "d,t,s", dreg, sreg, treg);
7242 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7246 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7258 macro_build (NULL, &icnt, NULL, "negu", "d,w", tempreg, treg);
7259 macro_build (NULL, &icnt, NULL, "rorv", "d,t,s", dreg, sreg,
7265 macro_build (NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
7266 macro_build (NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT);
7267 macro_build (NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg, treg);
7268 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7276 if (imm_expr.X_op != O_constant)
7277 as_bad (_("Improper rotate count"));
7278 rot = imm_expr.X_add_number & 0x3f;
7279 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7281 rot = (64 - rot) & 0x3f;
7283 macro_build (NULL, &icnt, NULL, "dror32", "d,w,<",
7284 dreg, sreg, rot - 32);
7286 macro_build (NULL, &icnt, NULL, "dror", "d,w,<",
7292 macro_build (NULL, &icnt, NULL, "dsrl", "d,w,<", dreg, sreg, 0);
7295 l = (rot < 0x20) ? "dsll" : "dsll32";
7296 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
7298 macro_build (NULL, &icnt, NULL, l, "d,w,<", AT, sreg, rot);
7299 macro_build (NULL, &icnt, NULL, r, "d,w,<", dreg, sreg,
7300 (0x20 - rot) & 0x1f);
7301 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7309 if (imm_expr.X_op != O_constant)
7310 as_bad (_("Improper rotate count"));
7311 rot = imm_expr.X_add_number & 0x1f;
7312 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7314 macro_build (NULL, &icnt, NULL, "ror", "d,w,<", dreg, sreg,
7320 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, 0);
7323 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg, rot);
7324 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg,
7325 (0x20 - rot) & 0x1f);
7326 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7331 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7333 macro_build (NULL, &icnt, NULL, "drorv", "d,t,s", dreg, sreg, treg);
7336 macro_build (NULL, &icnt, NULL, "dsubu", "d,v,t", AT, 0, treg);
7337 macro_build (NULL, &icnt, NULL, "dsllv", "d,t,s", AT, sreg, AT);
7338 macro_build (NULL, &icnt, NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
7339 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7343 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7345 macro_build (NULL, &icnt, NULL, "rorv", "d,t,s", dreg, sreg, treg);
7348 macro_build (NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
7349 macro_build (NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT);
7350 macro_build (NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg, treg);
7351 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7359 if (imm_expr.X_op != O_constant)
7360 as_bad (_("Improper rotate count"));
7361 rot = imm_expr.X_add_number & 0x3f;
7362 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7365 macro_build (NULL, &icnt, NULL, "dror32", "d,w,<",
7366 dreg, sreg, rot - 32);
7368 macro_build (NULL, &icnt, NULL, "dror", "d,w,<",
7374 macro_build (NULL, &icnt, NULL, "dsrl", "d,w,<", dreg, sreg, 0);
7377 r = (rot < 0x20) ? "dsrl" : "dsrl32";
7378 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
7380 macro_build (NULL, &icnt, NULL, r, "d,w,<", AT, sreg, rot);
7381 macro_build (NULL, &icnt, NULL, l, "d,w,<", dreg, sreg,
7382 (0x20 - rot) & 0x1f);
7383 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7391 if (imm_expr.X_op != O_constant)
7392 as_bad (_("Improper rotate count"));
7393 rot = imm_expr.X_add_number & 0x1f;
7394 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7396 macro_build (NULL, &icnt, NULL, "ror", "d,w,<", dreg, sreg, rot);
7401 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, 0);
7404 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg, rot);
7405 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg,
7406 (0x20 - rot) & 0x1f);
7407 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7412 if (mips_opts.arch == CPU_R4650)
7414 as_bad (_("opcode not supported on this processor"));
7417 assert (mips_opts.isa == ISA_MIPS1);
7418 /* Even on a big endian machine $fn comes before $fn+1. We have
7419 to adjust when storing to memory. */
7420 macro_build (NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
7421 target_big_endian ? treg + 1 : treg,
7422 BFD_RELOC_LO16, breg);
7423 offset_expr.X_add_number += 4;
7424 macro_build (NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
7425 target_big_endian ? treg : treg + 1,
7426 BFD_RELOC_LO16, breg);
7431 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, treg,
7434 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, sreg,
7438 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, treg);
7439 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
7445 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7447 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, sreg,
7453 as_warn (_("Instruction %s: result is always false"),
7455 move_register (&icnt, dreg, 0);
7458 if (imm_expr.X_op == O_constant
7459 && imm_expr.X_add_number >= 0
7460 && imm_expr.X_add_number < 0x10000)
7462 macro_build (NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, sreg,
7466 else if (imm_expr.X_op == O_constant
7467 && imm_expr.X_add_number > -0x8000
7468 && imm_expr.X_add_number < 0)
7470 imm_expr.X_add_number = -imm_expr.X_add_number;
7471 macro_build (NULL, &icnt, &imm_expr,
7472 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7473 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7478 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7479 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, AT);
7482 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
7488 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
7494 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg);
7495 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7499 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
7501 if (imm_expr.X_op == O_constant
7502 && imm_expr.X_add_number >= -0x8000
7503 && imm_expr.X_add_number < 0x8000)
7505 macro_build (NULL, &icnt, &imm_expr,
7506 mask == M_SGE_I ? "slti" : "sltiu",
7507 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7512 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7513 macro_build (NULL, &icnt, NULL, mask == M_SGE_I ? "slt" : "sltu",
7514 "d,v,t", dreg, sreg, AT);
7517 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7523 case M_SGT: /* sreg > treg <==> treg < sreg */
7529 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
7532 case M_SGT_I: /* sreg > I <==> I < sreg */
7538 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7539 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
7542 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7548 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
7549 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7553 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7559 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7560 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
7561 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7566 if (imm_expr.X_op == O_constant
7567 && imm_expr.X_add_number >= -0x8000
7568 && imm_expr.X_add_number < 0x8000)
7570 macro_build (NULL, &icnt, &imm_expr, "slti", "t,r,j", dreg, sreg,
7574 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7575 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT);
7579 if (imm_expr.X_op == O_constant
7580 && imm_expr.X_add_number >= -0x8000
7581 && imm_expr.X_add_number < 0x8000)
7583 macro_build (NULL, &icnt, &imm_expr, "sltiu", "t,r,j", dreg, sreg,
7587 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7588 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg, AT);
7593 macro_build (NULL, &icnt, NULL, "sltu","d,v,t", dreg, 0, treg);
7595 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, sreg);
7598 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, treg);
7599 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
7604 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7606 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, sreg);
7611 as_warn (_("Instruction %s: result is always true"),
7613 macro_build (NULL, &icnt, &expr1,
7614 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7615 "t,r,j", dreg, 0, BFD_RELOC_LO16);
7618 if (imm_expr.X_op == O_constant
7619 && imm_expr.X_add_number >= 0
7620 && imm_expr.X_add_number < 0x10000)
7622 macro_build (NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, sreg,
7626 else if (imm_expr.X_op == O_constant
7627 && imm_expr.X_add_number > -0x8000
7628 && imm_expr.X_add_number < 0)
7630 imm_expr.X_add_number = -imm_expr.X_add_number;
7631 macro_build (NULL, &icnt, &imm_expr,
7632 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7633 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7638 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7639 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, AT);
7642 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
7650 if (imm_expr.X_op == O_constant
7651 && imm_expr.X_add_number > -0x8000
7652 && imm_expr.X_add_number <= 0x8000)
7654 imm_expr.X_add_number = -imm_expr.X_add_number;
7655 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddi" : "addi",
7656 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7659 load_register (&icnt, AT, &imm_expr, dbl);
7660 macro_build (NULL, &icnt, NULL, dbl ? "dsub" : "sub", "d,v,t",
7667 if (imm_expr.X_op == O_constant
7668 && imm_expr.X_add_number > -0x8000
7669 && imm_expr.X_add_number <= 0x8000)
7671 imm_expr.X_add_number = -imm_expr.X_add_number;
7672 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddiu" : "addiu",
7673 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7676 load_register (&icnt, AT, &imm_expr, dbl);
7677 macro_build (NULL, &icnt, NULL, dbl ? "dsubu" : "subu", "d,v,t",
7699 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7700 macro_build (NULL, &icnt, NULL, s, "s,t", sreg, AT);
7705 assert (mips_opts.isa == ISA_MIPS1);
7706 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7707 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7710 * Is the double cfc1 instruction a bug in the mips assembler;
7711 * or is there a reason for it?
7713 mips_emit_delays (TRUE);
7714 ++mips_opts.noreorder;
7715 mips_any_noreorder = 1;
7716 macro_build (NULL, &icnt, NULL, "cfc1", "t,G", treg, RA);
7717 macro_build (NULL, &icnt, NULL, "cfc1", "t,G", treg, RA);
7718 macro_build (NULL, &icnt, NULL, "nop", "");
7719 expr1.X_add_number = 3;
7720 macro_build (NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7722 expr1.X_add_number = 2;
7723 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7725 macro_build (NULL, &icnt, NULL, "ctc1", "t,G", AT, RA);
7726 macro_build (NULL, &icnt, NULL, "nop", "");
7727 macro_build (NULL, &icnt, NULL,
7728 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s",
7730 macro_build (NULL, &icnt, NULL, "ctc1", "t,G", treg, RA);
7731 macro_build (NULL, &icnt, NULL, "nop", "");
7732 --mips_opts.noreorder;
7741 if (offset_expr.X_add_number >= 0x7fff)
7742 as_bad (_("operand overflow"));
7743 if (! target_big_endian)
7744 ++offset_expr.X_add_number;
7745 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", AT,
7746 BFD_RELOC_LO16, breg);
7747 if (! target_big_endian)
7748 --offset_expr.X_add_number;
7750 ++offset_expr.X_add_number;
7751 macro_build (NULL, &icnt, &offset_expr, "lbu", "t,o(b)", treg,
7752 BFD_RELOC_LO16, breg);
7753 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", AT, AT, 8);
7754 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7767 if (offset_expr.X_add_number >= 0x8000 - off)
7768 as_bad (_("operand overflow"));
7773 if (! target_big_endian)
7774 offset_expr.X_add_number += off;
7775 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", tempreg,
7776 BFD_RELOC_LO16, breg);
7777 if (! target_big_endian)
7778 offset_expr.X_add_number -= off;
7780 offset_expr.X_add_number += off;
7781 macro_build (NULL, &icnt, &offset_expr, s2, "t,o(b)", tempreg,
7782 BFD_RELOC_LO16, breg);
7784 /* If necessary, move the result in tempreg the final destination. */
7785 if (treg == tempreg)
7787 /* Protect second load's delay slot. */
7788 if (!gpr_interlocks)
7789 macro_build (NULL, &icnt, NULL, "nop", "");
7790 move_register (&icnt, treg, tempreg);
7804 load_address (&icnt, AT, &offset_expr, &used_at);
7806 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7808 if (! target_big_endian)
7809 expr1.X_add_number = off;
7811 expr1.X_add_number = 0;
7812 macro_build (NULL, &icnt, &expr1, s, "t,o(b)", treg,
7813 BFD_RELOC_LO16, AT);
7814 if (! target_big_endian)
7815 expr1.X_add_number = 0;
7817 expr1.X_add_number = off;
7818 macro_build (NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7819 BFD_RELOC_LO16, AT);
7825 load_address (&icnt, AT, &offset_expr, &used_at);
7827 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7829 if (target_big_endian)
7830 expr1.X_add_number = 0;
7831 macro_build (NULL, &icnt, &expr1,
7832 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)",
7833 treg, BFD_RELOC_LO16, AT);
7834 if (target_big_endian)
7835 expr1.X_add_number = 1;
7837 expr1.X_add_number = 0;
7838 macro_build (NULL, &icnt, &expr1, "lbu", "t,o(b)",
7839 AT, BFD_RELOC_LO16, AT);
7840 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
7841 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7845 if (offset_expr.X_add_number >= 0x7fff)
7846 as_bad (_("operand overflow"));
7847 if (target_big_endian)
7848 ++offset_expr.X_add_number;
7849 macro_build (NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7850 BFD_RELOC_LO16, breg);
7851 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8);
7852 if (target_big_endian)
7853 --offset_expr.X_add_number;
7855 ++offset_expr.X_add_number;
7856 macro_build (NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7857 BFD_RELOC_LO16, breg);
7870 if (offset_expr.X_add_number >= 0x8000 - off)
7871 as_bad (_("operand overflow"));
7872 if (! target_big_endian)
7873 offset_expr.X_add_number += off;
7874 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7875 BFD_RELOC_LO16, breg);
7876 if (! target_big_endian)
7877 offset_expr.X_add_number -= off;
7879 offset_expr.X_add_number += off;
7880 macro_build (NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7881 BFD_RELOC_LO16, breg);
7895 load_address (&icnt, AT, &offset_expr, &used_at);
7897 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7899 if (! target_big_endian)
7900 expr1.X_add_number = off;
7902 expr1.X_add_number = 0;
7903 macro_build (NULL, &icnt, &expr1, s, "t,o(b)", treg,
7904 BFD_RELOC_LO16, AT);
7905 if (! target_big_endian)
7906 expr1.X_add_number = 0;
7908 expr1.X_add_number = off;
7909 macro_build (NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7910 BFD_RELOC_LO16, AT);
7915 load_address (&icnt, AT, &offset_expr, &used_at);
7917 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7919 if (! target_big_endian)
7920 expr1.X_add_number = 0;
7921 macro_build (NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7922 BFD_RELOC_LO16, AT);
7923 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", treg, treg, 8);
7924 if (! target_big_endian)
7925 expr1.X_add_number = 1;
7927 expr1.X_add_number = 0;
7928 macro_build (NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7929 BFD_RELOC_LO16, AT);
7930 if (! target_big_endian)
7931 expr1.X_add_number = 0;
7933 expr1.X_add_number = 1;
7934 macro_build (NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7935 BFD_RELOC_LO16, AT);
7936 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
7937 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7941 /* FIXME: Check if this is one of the itbl macros, since they
7942 are added dynamically. */
7943 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7947 as_warn (_("Macro used $at after \".set noat\""));
7950 /* Implement macros in mips16 mode. */
7953 mips16_macro (struct mips_cl_insn *ip)
7956 int xreg, yreg, zreg, tmp;
7960 const char *s, *s2, *s3;
7962 mask = ip->insn_mo->mask;
7964 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7965 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7966 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7970 expr1.X_op = O_constant;
7971 expr1.X_op_symbol = NULL;
7972 expr1.X_add_symbol = NULL;
7973 expr1.X_add_number = 1;
7992 mips_emit_delays (TRUE);
7993 ++mips_opts.noreorder;
7994 mips_any_noreorder = 1;
7995 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "0,x,y",
7997 expr1.X_add_number = 2;
7998 macro_build (NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7999 macro_build (NULL, &icnt, NULL, "break", "6", 7);
8001 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
8002 since that causes an overflow. We should do that as well,
8003 but I don't see how to do the comparisons without a temporary
8005 --mips_opts.noreorder;
8006 macro_build (NULL, &icnt, NULL, s, "x", zreg);
8025 mips_emit_delays (TRUE);
8026 ++mips_opts.noreorder;
8027 mips_any_noreorder = 1;
8028 macro_build (NULL, &icnt, NULL, s, "0,x,y", xreg, yreg);
8029 expr1.X_add_number = 2;
8030 macro_build (NULL, &icnt, &expr1, "bnez", "x,p", yreg);
8031 macro_build (NULL, &icnt, NULL, "break", "6", 7);
8032 --mips_opts.noreorder;
8033 macro_build (NULL, &icnt, NULL, s2, "x", zreg);
8039 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "x,y",
8041 macro_build (NULL, &icnt, NULL, "mflo", "x", zreg);
8049 if (imm_expr.X_op != O_constant)
8050 as_bad (_("Unsupported large constant"));
8051 imm_expr.X_add_number = -imm_expr.X_add_number;
8052 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddiu" : "addiu", "y,x,4",
8057 if (imm_expr.X_op != O_constant)
8058 as_bad (_("Unsupported large constant"));
8059 imm_expr.X_add_number = -imm_expr.X_add_number;
8060 macro_build (NULL, &icnt, &imm_expr, "addiu", "x,k", xreg);
8064 if (imm_expr.X_op != O_constant)
8065 as_bad (_("Unsupported large constant"));
8066 imm_expr.X_add_number = -imm_expr.X_add_number;
8067 macro_build (NULL, &icnt, &imm_expr, "daddiu", "y,j", yreg);
8089 goto do_reverse_branch;
8093 goto do_reverse_branch;
8105 goto do_reverse_branch;
8116 macro_build (NULL, &icnt, NULL, s, "x,y", xreg, yreg);
8117 macro_build (NULL, &icnt, &offset_expr, s2, "p");
8144 goto do_addone_branch_i;
8149 goto do_addone_branch_i;
8164 goto do_addone_branch_i;
8171 if (imm_expr.X_op != O_constant)
8172 as_bad (_("Unsupported large constant"));
8173 ++imm_expr.X_add_number;
8176 macro_build (NULL, &icnt, &imm_expr, s, s3, xreg);
8177 macro_build (NULL, &icnt, &offset_expr, s2, "p");
8181 expr1.X_add_number = 0;
8182 macro_build (NULL, &icnt, &expr1, "slti", "x,8", yreg);
8184 move_register (&icnt, xreg, yreg);
8185 expr1.X_add_number = 2;
8186 macro_build (NULL, &icnt, &expr1, "bteqz", "p");
8187 macro_build (NULL, &icnt, NULL, "neg", "x,w", xreg, xreg);
8191 /* For consistency checking, verify that all bits are specified either
8192 by the match/mask part of the instruction definition, or by the
8195 validate_mips_insn (const struct mips_opcode *opc)
8197 const char *p = opc->args;
8199 unsigned long used_bits = opc->mask;
8201 if ((used_bits & opc->match) != opc->match)
8203 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
8204 opc->name, opc->args);
8207 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
8217 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8218 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
8219 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8220 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
8221 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8222 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8223 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
8224 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8225 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8228 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8229 c, opc->name, opc->args);
8233 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8234 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8236 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
8237 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
8238 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8239 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8241 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8242 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8244 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
8245 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8247 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
8248 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
8249 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
8250 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
8251 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8252 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
8253 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8254 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8255 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8256 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8257 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8258 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8259 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8260 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
8261 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8262 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
8263 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8265 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
8266 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8267 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8268 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
8270 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8271 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8272 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
8273 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8274 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8275 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8276 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8277 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8278 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8281 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
8282 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
8283 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8284 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
8285 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
8289 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
8290 c, opc->name, opc->args);
8294 if (used_bits != 0xffffffff)
8296 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
8297 ~used_bits & 0xffffffff, opc->name, opc->args);
8303 /* This routine assembles an instruction into its binary format. As a
8304 side effect, it sets one of the global variables imm_reloc or
8305 offset_reloc to the type of relocation to do if one of the operands
8306 is an address expression. */
8309 mips_ip (char *str, struct mips_cl_insn *ip)
8314 struct mips_opcode *insn;
8317 unsigned int lastregno = 0;
8318 unsigned int lastpos = 0;
8319 unsigned int limlo, limhi;
8325 /* If the instruction contains a '.', we first try to match an instruction
8326 including the '.'. Then we try again without the '.'. */
8328 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
8331 /* If we stopped on whitespace, then replace the whitespace with null for
8332 the call to hash_find. Save the character we replaced just in case we
8333 have to re-parse the instruction. */
8340 insn = (struct mips_opcode *) hash_find (op_hash, str);
8342 /* If we didn't find the instruction in the opcode table, try again, but
8343 this time with just the instruction up to, but not including the
8347 /* Restore the character we overwrite above (if any). */
8351 /* Scan up to the first '.' or whitespace. */
8353 *s != '\0' && *s != '.' && !ISSPACE (*s);
8357 /* If we did not find a '.', then we can quit now. */
8360 insn_error = "unrecognized opcode";
8364 /* Lookup the instruction in the hash table. */
8366 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
8368 insn_error = "unrecognized opcode";
8378 assert (strcmp (insn->name, str) == 0);
8380 if (OPCODE_IS_MEMBER (insn,
8382 | (file_ase_mips16 ? INSN_MIPS16 : 0)
8383 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
8384 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
8390 if (insn->pinfo != INSN_MACRO)
8392 if (mips_opts.arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
8398 if (insn + 1 < &mips_opcodes[NUMOPCODES]
8399 && strcmp (insn->name, insn[1].name) == 0)
8408 static char buf[100];
8410 _("opcode not supported on this processor: %s (%s)"),
8411 mips_cpu_info_from_arch (mips_opts.arch)->name,
8412 mips_cpu_info_from_isa (mips_opts.isa)->name);
8422 ip->insn_opcode = insn->match;
8424 for (args = insn->args;; ++args)
8428 s += strspn (s, " \t");
8432 case '\0': /* end of args */
8445 ip->insn_opcode |= lastregno << OP_SH_RS;
8449 ip->insn_opcode |= lastregno << OP_SH_RT;
8453 ip->insn_opcode |= lastregno << OP_SH_FT;
8457 ip->insn_opcode |= lastregno << OP_SH_FS;
8463 /* Handle optional base register.
8464 Either the base register is omitted or
8465 we must have a left paren. */
8466 /* This is dependent on the next operand specifier
8467 is a base register specification. */
8468 assert (args[1] == 'b' || args[1] == '5'
8469 || args[1] == '-' || args[1] == '4');
8473 case ')': /* these must match exactly */
8480 case '+': /* Opcode extension character. */
8483 case 'A': /* ins/ext position, becomes LSB. */
8492 my_getExpression (&imm_expr, s);
8493 check_absolute_expr (ip, &imm_expr);
8494 if ((unsigned long) imm_expr.X_add_number < limlo
8495 || (unsigned long) imm_expr.X_add_number > limhi)
8497 as_bad (_("Improper position (%lu)"),
8498 (unsigned long) imm_expr.X_add_number);
8499 imm_expr.X_add_number = limlo;
8501 lastpos = imm_expr.X_add_number;
8502 ip->insn_opcode |= (imm_expr.X_add_number
8503 & OP_MASK_SHAMT) << OP_SH_SHAMT;
8504 imm_expr.X_op = O_absent;
8508 case 'B': /* ins size, becomes MSB. */
8517 my_getExpression (&imm_expr, s);
8518 check_absolute_expr (ip, &imm_expr);
8519 /* Check for negative input so that small negative numbers
8520 will not succeed incorrectly. The checks against
8521 (pos+size) transitively check "size" itself,
8522 assuming that "pos" is reasonable. */
8523 if ((long) imm_expr.X_add_number < 0
8524 || ((unsigned long) imm_expr.X_add_number
8526 || ((unsigned long) imm_expr.X_add_number
8529 as_bad (_("Improper insert size (%lu, position %lu)"),
8530 (unsigned long) imm_expr.X_add_number,
8531 (unsigned long) lastpos);
8532 imm_expr.X_add_number = limlo - lastpos;
8534 ip->insn_opcode |= ((lastpos + imm_expr.X_add_number - 1)
8535 & OP_MASK_INSMSB) << OP_SH_INSMSB;
8536 imm_expr.X_op = O_absent;
8540 case 'C': /* ext size, becomes MSBD. */
8553 my_getExpression (&imm_expr, s);
8554 check_absolute_expr (ip, &imm_expr);
8555 /* Check for negative input so that small negative numbers
8556 will not succeed incorrectly. The checks against
8557 (pos+size) transitively check "size" itself,
8558 assuming that "pos" is reasonable. */
8559 if ((long) imm_expr.X_add_number < 0
8560 || ((unsigned long) imm_expr.X_add_number
8562 || ((unsigned long) imm_expr.X_add_number
8565 as_bad (_("Improper extract size (%lu, position %lu)"),
8566 (unsigned long) imm_expr.X_add_number,
8567 (unsigned long) lastpos);
8568 imm_expr.X_add_number = limlo - lastpos;
8570 ip->insn_opcode |= ((imm_expr.X_add_number - 1)
8571 & OP_MASK_EXTMSBD) << OP_SH_EXTMSBD;
8572 imm_expr.X_op = O_absent;
8577 /* +D is for disassembly only; never match. */
8581 /* "+I" is like "I", except that imm2_expr is used. */
8582 my_getExpression (&imm2_expr, s);
8583 if (imm2_expr.X_op != O_big
8584 && imm2_expr.X_op != O_constant)
8585 insn_error = _("absolute expression required");
8586 normalize_constant_expr (&imm2_expr);
8591 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8592 *args, insn->name, insn->args);
8593 /* Further processing is fruitless. */
8598 case '<': /* must be at least one digit */
8600 * According to the manual, if the shift amount is greater
8601 * than 31 or less than 0, then the shift amount should be
8602 * mod 32. In reality the mips assembler issues an error.
8603 * We issue a warning and mask out all but the low 5 bits.
8605 my_getExpression (&imm_expr, s);
8606 check_absolute_expr (ip, &imm_expr);
8607 if ((unsigned long) imm_expr.X_add_number > 31)
8609 as_warn (_("Improper shift amount (%lu)"),
8610 (unsigned long) imm_expr.X_add_number);
8611 imm_expr.X_add_number &= OP_MASK_SHAMT;
8613 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
8614 imm_expr.X_op = O_absent;
8618 case '>': /* shift amount minus 32 */
8619 my_getExpression (&imm_expr, s);
8620 check_absolute_expr (ip, &imm_expr);
8621 if ((unsigned long) imm_expr.X_add_number < 32
8622 || (unsigned long) imm_expr.X_add_number > 63)
8624 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
8625 imm_expr.X_op = O_absent;
8629 case 'k': /* cache code */
8630 case 'h': /* prefx code */
8631 my_getExpression (&imm_expr, s);
8632 check_absolute_expr (ip, &imm_expr);
8633 if ((unsigned long) imm_expr.X_add_number > 31)
8635 as_warn (_("Invalid value for `%s' (%lu)"),
8637 (unsigned long) imm_expr.X_add_number);
8638 imm_expr.X_add_number &= 0x1f;
8641 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
8643 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
8644 imm_expr.X_op = O_absent;
8648 case 'c': /* break code */
8649 my_getExpression (&imm_expr, s);
8650 check_absolute_expr (ip, &imm_expr);
8651 if ((unsigned long) imm_expr.X_add_number > 1023)
8653 as_warn (_("Illegal break code (%lu)"),
8654 (unsigned long) imm_expr.X_add_number);
8655 imm_expr.X_add_number &= OP_MASK_CODE;
8657 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
8658 imm_expr.X_op = O_absent;
8662 case 'q': /* lower break code */
8663 my_getExpression (&imm_expr, s);
8664 check_absolute_expr (ip, &imm_expr);
8665 if ((unsigned long) imm_expr.X_add_number > 1023)
8667 as_warn (_("Illegal lower break code (%lu)"),
8668 (unsigned long) imm_expr.X_add_number);
8669 imm_expr.X_add_number &= OP_MASK_CODE2;
8671 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
8672 imm_expr.X_op = O_absent;
8676 case 'B': /* 20-bit syscall/break code. */
8677 my_getExpression (&imm_expr, s);
8678 check_absolute_expr (ip, &imm_expr);
8679 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
8680 as_warn (_("Illegal 20-bit code (%lu)"),
8681 (unsigned long) imm_expr.X_add_number);
8682 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
8683 imm_expr.X_op = O_absent;
8687 case 'C': /* Coprocessor code */
8688 my_getExpression (&imm_expr, s);
8689 check_absolute_expr (ip, &imm_expr);
8690 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
8692 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8693 (unsigned long) imm_expr.X_add_number);
8694 imm_expr.X_add_number &= ((1 << 25) - 1);
8696 ip->insn_opcode |= imm_expr.X_add_number;
8697 imm_expr.X_op = O_absent;
8701 case 'J': /* 19-bit wait code. */
8702 my_getExpression (&imm_expr, s);
8703 check_absolute_expr (ip, &imm_expr);
8704 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
8705 as_warn (_("Illegal 19-bit code (%lu)"),
8706 (unsigned long) imm_expr.X_add_number);
8707 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
8708 imm_expr.X_op = O_absent;
8712 case 'P': /* Performance register */
8713 my_getExpression (&imm_expr, s);
8714 check_absolute_expr (ip, &imm_expr);
8715 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
8717 as_warn (_("Invalid performance register (%lu)"),
8718 (unsigned long) imm_expr.X_add_number);
8719 imm_expr.X_add_number &= OP_MASK_PERFREG;
8721 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
8722 imm_expr.X_op = O_absent;
8726 case 'b': /* base register */
8727 case 'd': /* destination register */
8728 case 's': /* source register */
8729 case 't': /* target register */
8730 case 'r': /* both target and source */
8731 case 'v': /* both dest and source */
8732 case 'w': /* both dest and target */
8733 case 'E': /* coprocessor target register */
8734 case 'G': /* coprocessor destination register */
8735 case 'K': /* 'rdhwr' destination register */
8736 case 'x': /* ignore register name */
8737 case 'z': /* must be zero register */
8738 case 'U': /* destination register (clo/clz). */
8753 while (ISDIGIT (*s));
8755 as_bad (_("Invalid register number (%d)"), regno);
8757 else if (*args == 'E' || *args == 'G' || *args == 'K')
8761 if (s[1] == 'r' && s[2] == 'a')
8766 else if (s[1] == 'f' && s[2] == 'p')
8771 else if (s[1] == 's' && s[2] == 'p')
8776 else if (s[1] == 'g' && s[2] == 'p')
8781 else if (s[1] == 'a' && s[2] == 't')
8786 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8791 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8796 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8801 else if (itbl_have_entries)
8806 p = s + 1; /* advance past '$' */
8807 n = itbl_get_field (&p); /* n is name */
8809 /* See if this is a register defined in an
8811 if (itbl_get_reg_val (n, &r))
8813 /* Get_field advances to the start of
8814 the next field, so we need to back
8815 rack to the end of the last field. */
8819 s = strchr (s, '\0');
8833 as_warn (_("Used $at without \".set noat\""));
8839 if (c == 'r' || c == 'v' || c == 'w')
8846 /* 'z' only matches $0. */
8847 if (c == 'z' && regno != 0)
8850 /* Now that we have assembled one operand, we use the args string
8851 * to figure out where it goes in the instruction. */
8858 ip->insn_opcode |= regno << OP_SH_RS;
8863 ip->insn_opcode |= regno << OP_SH_RD;
8866 ip->insn_opcode |= regno << OP_SH_RD;
8867 ip->insn_opcode |= regno << OP_SH_RT;
8872 ip->insn_opcode |= regno << OP_SH_RT;
8875 /* This case exists because on the r3000 trunc
8876 expands into a macro which requires a gp
8877 register. On the r6000 or r4000 it is
8878 assembled into a single instruction which
8879 ignores the register. Thus the insn version
8880 is MIPS_ISA2 and uses 'x', and the macro
8881 version is MIPS_ISA1 and uses 't'. */
8884 /* This case is for the div instruction, which
8885 acts differently if the destination argument
8886 is $0. This only matches $0, and is checked
8887 outside the switch. */
8890 /* Itbl operand; not yet implemented. FIXME ?? */
8892 /* What about all other operands like 'i', which
8893 can be specified in the opcode table? */
8903 ip->insn_opcode |= lastregno << OP_SH_RS;
8906 ip->insn_opcode |= lastregno << OP_SH_RT;
8911 case 'O': /* MDMX alignment immediate constant. */
8912 my_getExpression (&imm_expr, s);
8913 check_absolute_expr (ip, &imm_expr);
8914 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
8916 as_warn ("Improper align amount (%ld), using low bits",
8917 (long) imm_expr.X_add_number);
8918 imm_expr.X_add_number &= OP_MASK_ALN;
8920 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_ALN;
8921 imm_expr.X_op = O_absent;
8925 case 'Q': /* MDMX vector, element sel, or const. */
8928 /* MDMX Immediate. */
8929 my_getExpression (&imm_expr, s);
8930 check_absolute_expr (ip, &imm_expr);
8931 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
8933 as_warn (_("Invalid MDMX Immediate (%ld)"),
8934 (long) imm_expr.X_add_number);
8935 imm_expr.X_add_number &= OP_MASK_FT;
8937 imm_expr.X_add_number &= OP_MASK_FT;
8938 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8939 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
8941 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
8942 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_FT;
8943 imm_expr.X_op = O_absent;
8947 /* Not MDMX Immediate. Fall through. */
8948 case 'X': /* MDMX destination register. */
8949 case 'Y': /* MDMX source register. */
8950 case 'Z': /* MDMX target register. */
8952 case 'D': /* floating point destination register */
8953 case 'S': /* floating point source register */
8954 case 'T': /* floating point target register */
8955 case 'R': /* floating point source register */
8959 /* Accept $fN for FP and MDMX register numbers, and in
8960 addition accept $vN for MDMX register numbers. */
8961 if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2]))
8962 || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v'
8973 while (ISDIGIT (*s));
8976 as_bad (_("Invalid float register number (%d)"), regno);
8978 if ((regno & 1) != 0
8980 && ! (strcmp (str, "mtc1") == 0
8981 || strcmp (str, "mfc1") == 0
8982 || strcmp (str, "lwc1") == 0
8983 || strcmp (str, "swc1") == 0
8984 || strcmp (str, "l.s") == 0
8985 || strcmp (str, "s.s") == 0))
8986 as_warn (_("Float register should be even, was %d"),
8994 if (c == 'V' || c == 'W')
9005 ip->insn_opcode |= regno << OP_SH_FD;
9010 ip->insn_opcode |= regno << OP_SH_FS;
9013 /* This is like 'Z', but also needs to fix the MDMX
9014 vector/scalar select bits. Note that the
9015 scalar immediate case is handled above. */
9018 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
9019 int max_el = (is_qh ? 3 : 7);
9021 my_getExpression(&imm_expr, s);
9022 check_absolute_expr (ip, &imm_expr);
9024 if (imm_expr.X_add_number > max_el)
9025 as_bad(_("Bad element selector %ld"),
9026 (long) imm_expr.X_add_number);
9027 imm_expr.X_add_number &= max_el;
9028 ip->insn_opcode |= (imm_expr.X_add_number
9032 as_warn(_("Expecting ']' found '%s'"), s);
9038 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
9039 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
9042 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
9049 ip->insn_opcode |= regno << OP_SH_FT;
9052 ip->insn_opcode |= regno << OP_SH_FR;
9062 ip->insn_opcode |= lastregno << OP_SH_FS;
9065 ip->insn_opcode |= lastregno << OP_SH_FT;
9071 my_getExpression (&imm_expr, s);
9072 if (imm_expr.X_op != O_big
9073 && imm_expr.X_op != O_constant)
9074 insn_error = _("absolute expression required");
9075 normalize_constant_expr (&imm_expr);
9080 my_getExpression (&offset_expr, s);
9081 *imm_reloc = BFD_RELOC_32;
9094 unsigned char temp[8];
9096 unsigned int length;
9101 /* These only appear as the last operand in an
9102 instruction, and every instruction that accepts
9103 them in any variant accepts them in all variants.
9104 This means we don't have to worry about backing out
9105 any changes if the instruction does not match.
9107 The difference between them is the size of the
9108 floating point constant and where it goes. For 'F'
9109 and 'L' the constant is 64 bits; for 'f' and 'l' it
9110 is 32 bits. Where the constant is placed is based
9111 on how the MIPS assembler does things:
9114 f -- immediate value
9117 The .lit4 and .lit8 sections are only used if
9118 permitted by the -G argument.
9120 When generating embedded PIC code, we use the
9121 .lit8 section but not the .lit4 section (we can do
9122 .lit4 inline easily; we need to put .lit8
9123 somewhere in the data segment, and using .lit8
9124 permits the linker to eventually combine identical
9127 The code below needs to know whether the target register
9128 is 32 or 64 bits wide. It relies on the fact 'f' and
9129 'F' are used with GPR-based instructions and 'l' and
9130 'L' are used with FPR-based instructions. */
9132 f64 = *args == 'F' || *args == 'L';
9133 using_gprs = *args == 'F' || *args == 'f';
9135 save_in = input_line_pointer;
9136 input_line_pointer = s;
9137 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
9139 s = input_line_pointer;
9140 input_line_pointer = save_in;
9141 if (err != NULL && *err != '\0')
9143 as_bad (_("Bad floating point constant: %s"), err);
9144 memset (temp, '\0', sizeof temp);
9145 length = f64 ? 8 : 4;
9148 assert (length == (unsigned) (f64 ? 8 : 4));
9152 && (! USE_GLOBAL_POINTER_OPT
9153 || mips_pic == EMBEDDED_PIC
9154 || g_switch_value < 4
9155 || (temp[0] == 0 && temp[1] == 0)
9156 || (temp[2] == 0 && temp[3] == 0))))
9158 imm_expr.X_op = O_constant;
9159 if (! target_big_endian)
9160 imm_expr.X_add_number = bfd_getl32 (temp);
9162 imm_expr.X_add_number = bfd_getb32 (temp);
9165 && ! mips_disable_float_construction
9166 /* Constants can only be constructed in GPRs and
9167 copied to FPRs if the GPRs are at least as wide
9168 as the FPRs. Force the constant into memory if
9169 we are using 64-bit FPRs but the GPRs are only
9172 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
9173 && ((temp[0] == 0 && temp[1] == 0)
9174 || (temp[2] == 0 && temp[3] == 0))
9175 && ((temp[4] == 0 && temp[5] == 0)
9176 || (temp[6] == 0 && temp[7] == 0)))
9178 /* The value is simple enough to load with a couple of
9179 instructions. If using 32-bit registers, set
9180 imm_expr to the high order 32 bits and offset_expr to
9181 the low order 32 bits. Otherwise, set imm_expr to
9182 the entire 64 bit constant. */
9183 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
9185 imm_expr.X_op = O_constant;
9186 offset_expr.X_op = O_constant;
9187 if (! target_big_endian)
9189 imm_expr.X_add_number = bfd_getl32 (temp + 4);
9190 offset_expr.X_add_number = bfd_getl32 (temp);
9194 imm_expr.X_add_number = bfd_getb32 (temp);
9195 offset_expr.X_add_number = bfd_getb32 (temp + 4);
9197 if (offset_expr.X_add_number == 0)
9198 offset_expr.X_op = O_absent;
9200 else if (sizeof (imm_expr.X_add_number) > 4)
9202 imm_expr.X_op = O_constant;
9203 if (! target_big_endian)
9204 imm_expr.X_add_number = bfd_getl64 (temp);
9206 imm_expr.X_add_number = bfd_getb64 (temp);
9210 imm_expr.X_op = O_big;
9211 imm_expr.X_add_number = 4;
9212 if (! target_big_endian)
9214 generic_bignum[0] = bfd_getl16 (temp);
9215 generic_bignum[1] = bfd_getl16 (temp + 2);
9216 generic_bignum[2] = bfd_getl16 (temp + 4);
9217 generic_bignum[3] = bfd_getl16 (temp + 6);
9221 generic_bignum[0] = bfd_getb16 (temp + 6);
9222 generic_bignum[1] = bfd_getb16 (temp + 4);
9223 generic_bignum[2] = bfd_getb16 (temp + 2);
9224 generic_bignum[3] = bfd_getb16 (temp);
9230 const char *newname;
9233 /* Switch to the right section. */
9235 subseg = now_subseg;
9238 default: /* unused default case avoids warnings. */
9240 newname = RDATA_SECTION_NAME;
9241 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
9242 || mips_pic == EMBEDDED_PIC)
9246 if (mips_pic == EMBEDDED_PIC)
9249 newname = RDATA_SECTION_NAME;
9252 assert (!USE_GLOBAL_POINTER_OPT
9253 || g_switch_value >= 4);
9257 new_seg = subseg_new (newname, (subsegT) 0);
9258 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
9259 bfd_set_section_flags (stdoutput, new_seg,
9264 frag_align (*args == 'l' ? 2 : 3, 0, 0);
9265 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9266 && strcmp (TARGET_OS, "elf") != 0)
9267 record_alignment (new_seg, 4);
9269 record_alignment (new_seg, *args == 'l' ? 2 : 3);
9271 as_bad (_("Can't use floating point insn in this section"));
9273 /* Set the argument to the current address in the
9275 offset_expr.X_op = O_symbol;
9276 offset_expr.X_add_symbol =
9277 symbol_new ("L0\001", now_seg,
9278 (valueT) frag_now_fix (), frag_now);
9279 offset_expr.X_add_number = 0;
9281 /* Put the floating point number into the section. */
9282 p = frag_more ((int) length);
9283 memcpy (p, temp, length);
9285 /* Switch back to the original section. */
9286 subseg_set (seg, subseg);
9291 case 'i': /* 16 bit unsigned immediate */
9292 case 'j': /* 16 bit signed immediate */
9293 *imm_reloc = BFD_RELOC_LO16;
9294 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
9297 offsetT minval, maxval;
9299 more = (insn + 1 < &mips_opcodes[NUMOPCODES]
9300 && strcmp (insn->name, insn[1].name) == 0);
9302 /* If the expression was written as an unsigned number,
9303 only treat it as signed if there are no more
9307 && sizeof (imm_expr.X_add_number) <= 4
9308 && imm_expr.X_op == O_constant
9309 && imm_expr.X_add_number < 0
9310 && imm_expr.X_unsigned
9314 /* For compatibility with older assemblers, we accept
9315 0x8000-0xffff as signed 16-bit numbers when only
9316 signed numbers are allowed. */
9318 minval = 0, maxval = 0xffff;
9320 minval = -0x8000, maxval = 0x7fff;
9322 minval = -0x8000, maxval = 0xffff;
9324 if (imm_expr.X_op != O_constant
9325 || imm_expr.X_add_number < minval
9326 || imm_expr.X_add_number > maxval)
9330 if (imm_expr.X_op == O_constant
9331 || imm_expr.X_op == O_big)
9332 as_bad (_("expression out of range"));
9338 case 'o': /* 16 bit offset */
9339 /* Check whether there is only a single bracketed expression
9340 left. If so, it must be the base register and the
9341 constant must be zero. */
9342 if (*s == '(' && strchr (s + 1, '(') == 0)
9344 offset_expr.X_op = O_constant;
9345 offset_expr.X_add_number = 0;
9349 /* If this value won't fit into a 16 bit offset, then go
9350 find a macro that will generate the 32 bit offset
9352 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
9353 && (offset_expr.X_op != O_constant
9354 || offset_expr.X_add_number >= 0x8000
9355 || offset_expr.X_add_number < -0x8000))
9361 case 'p': /* pc relative offset */
9362 *offset_reloc = BFD_RELOC_16_PCREL_S2;
9363 my_getExpression (&offset_expr, s);
9367 case 'u': /* upper 16 bits */
9368 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
9369 && imm_expr.X_op == O_constant
9370 && (imm_expr.X_add_number < 0
9371 || imm_expr.X_add_number >= 0x10000))
9372 as_bad (_("lui expression not in range 0..65535"));
9376 case 'a': /* 26 bit address */
9377 my_getExpression (&offset_expr, s);
9379 *offset_reloc = BFD_RELOC_MIPS_JMP;
9382 case 'N': /* 3 bit branch condition code */
9383 case 'M': /* 3 bit compare condition code */
9384 if (strncmp (s, "$fcc", 4) != 0)
9394 while (ISDIGIT (*s));
9396 as_bad (_("Invalid condition code register $fcc%d"), regno);
9397 if ((strcmp(str + strlen(str) - 3, ".ps") == 0
9398 || strcmp(str + strlen(str) - 5, "any2f") == 0
9399 || strcmp(str + strlen(str) - 5, "any2t") == 0)
9400 && (regno & 1) != 0)
9401 as_warn(_("Condition code register should be even for %s, was %d"),
9403 if ((strcmp(str + strlen(str) - 5, "any4f") == 0
9404 || strcmp(str + strlen(str) - 5, "any4t") == 0)
9405 && (regno & 3) != 0)
9406 as_warn(_("Condition code register should be 0 or 4 for %s, was %d"),
9409 ip->insn_opcode |= regno << OP_SH_BCC;
9411 ip->insn_opcode |= regno << OP_SH_CCC;
9415 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
9426 while (ISDIGIT (*s));
9429 c = 8; /* Invalid sel value. */
9432 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9433 ip->insn_opcode |= c;
9437 /* Must be at least one digit. */
9438 my_getExpression (&imm_expr, s);
9439 check_absolute_expr (ip, &imm_expr);
9441 if ((unsigned long) imm_expr.X_add_number
9442 > (unsigned long) OP_MASK_VECBYTE)
9444 as_bad (_("bad byte vector index (%ld)"),
9445 (long) imm_expr.X_add_number);
9446 imm_expr.X_add_number = 0;
9449 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECBYTE;
9450 imm_expr.X_op = O_absent;
9455 my_getExpression (&imm_expr, s);
9456 check_absolute_expr (ip, &imm_expr);
9458 if ((unsigned long) imm_expr.X_add_number
9459 > (unsigned long) OP_MASK_VECALIGN)
9461 as_bad (_("bad byte vector index (%ld)"),
9462 (long) imm_expr.X_add_number);
9463 imm_expr.X_add_number = 0;
9466 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECALIGN;
9467 imm_expr.X_op = O_absent;
9472 as_bad (_("bad char = '%c'\n"), *args);
9477 /* Args don't match. */
9478 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
9479 !strcmp (insn->name, insn[1].name))
9483 insn_error = _("illegal operands");
9488 insn_error = _("illegal operands");
9493 /* This routine assembles an instruction into its binary format when
9494 assembling for the mips16. As a side effect, it sets one of the
9495 global variables imm_reloc or offset_reloc to the type of
9496 relocation to do if one of the operands is an address expression.
9497 It also sets mips16_small and mips16_ext if the user explicitly
9498 requested a small or extended instruction. */
9501 mips16_ip (char *str, struct mips_cl_insn *ip)
9505 struct mips_opcode *insn;
9508 unsigned int lastregno = 0;
9513 mips16_small = FALSE;
9516 for (s = str; ISLOWER (*s); ++s)
9528 if (s[1] == 't' && s[2] == ' ')
9531 mips16_small = TRUE;
9535 else if (s[1] == 'e' && s[2] == ' ')
9544 insn_error = _("unknown opcode");
9548 if (mips_opts.noautoextend && ! mips16_ext)
9549 mips16_small = TRUE;
9551 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
9553 insn_error = _("unrecognized opcode");
9560 assert (strcmp (insn->name, str) == 0);
9563 ip->insn_opcode = insn->match;
9564 ip->use_extend = FALSE;
9565 imm_expr.X_op = O_absent;
9566 imm_reloc[0] = BFD_RELOC_UNUSED;
9567 imm_reloc[1] = BFD_RELOC_UNUSED;
9568 imm_reloc[2] = BFD_RELOC_UNUSED;
9569 imm2_expr.X_op = O_absent;
9570 offset_expr.X_op = O_absent;
9571 offset_reloc[0] = BFD_RELOC_UNUSED;
9572 offset_reloc[1] = BFD_RELOC_UNUSED;
9573 offset_reloc[2] = BFD_RELOC_UNUSED;
9574 for (args = insn->args; 1; ++args)
9581 /* In this switch statement we call break if we did not find
9582 a match, continue if we did find a match, or return if we
9591 /* Stuff the immediate value in now, if we can. */
9592 if (imm_expr.X_op == O_constant
9593 && *imm_reloc > BFD_RELOC_UNUSED
9594 && insn->pinfo != INSN_MACRO)
9596 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
9597 imm_expr.X_add_number, TRUE, mips16_small,
9598 mips16_ext, &ip->insn_opcode,
9599 &ip->use_extend, &ip->extend);
9600 imm_expr.X_op = O_absent;
9601 *imm_reloc = BFD_RELOC_UNUSED;
9615 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9618 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9634 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9636 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9663 while (ISDIGIT (*s));
9666 as_bad (_("invalid register number (%d)"), regno);
9672 if (s[1] == 'r' && s[2] == 'a')
9677 else if (s[1] == 'f' && s[2] == 'p')
9682 else if (s[1] == 's' && s[2] == 'p')
9687 else if (s[1] == 'g' && s[2] == 'p')
9692 else if (s[1] == 'a' && s[2] == 't')
9697 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
9702 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
9707 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
9720 if (c == 'v' || c == 'w')
9722 regno = mips16_to_32_reg_map[lastregno];
9736 regno = mips32_to_16_reg_map[regno];
9741 regno = ILLEGAL_REG;
9746 regno = ILLEGAL_REG;
9751 regno = ILLEGAL_REG;
9756 if (regno == AT && ! mips_opts.noat)
9757 as_warn (_("used $at without \".set noat\""));
9764 if (regno == ILLEGAL_REG)
9771 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
9775 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
9778 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
9781 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
9787 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
9790 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9791 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
9801 if (strncmp (s, "$pc", 3) == 0)
9825 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
9827 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9828 and generate the appropriate reloc. If the text
9829 inside %gprel is not a symbol name with an
9830 optional offset, then we generate a normal reloc
9831 and will probably fail later. */
9832 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
9833 if (imm_expr.X_op == O_symbol)
9836 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
9838 ip->use_extend = TRUE;
9845 /* Just pick up a normal expression. */
9846 my_getExpression (&imm_expr, s);
9849 if (imm_expr.X_op == O_register)
9851 /* What we thought was an expression turned out to
9854 if (s[0] == '(' && args[1] == '(')
9856 /* It looks like the expression was omitted
9857 before a register indirection, which means
9858 that the expression is implicitly zero. We
9859 still set up imm_expr, so that we handle
9860 explicit extensions correctly. */
9861 imm_expr.X_op = O_constant;
9862 imm_expr.X_add_number = 0;
9863 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9870 /* We need to relax this instruction. */
9871 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9880 /* We use offset_reloc rather than imm_reloc for the PC
9881 relative operands. This lets macros with both
9882 immediate and address operands work correctly. */
9883 my_getExpression (&offset_expr, s);
9885 if (offset_expr.X_op == O_register)
9888 /* We need to relax this instruction. */
9889 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9893 case '6': /* break code */
9894 my_getExpression (&imm_expr, s);
9895 check_absolute_expr (ip, &imm_expr);
9896 if ((unsigned long) imm_expr.X_add_number > 63)
9898 as_warn (_("Invalid value for `%s' (%lu)"),
9900 (unsigned long) imm_expr.X_add_number);
9901 imm_expr.X_add_number &= 0x3f;
9903 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9904 imm_expr.X_op = O_absent;
9908 case 'a': /* 26 bit address */
9909 my_getExpression (&offset_expr, s);
9911 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9912 ip->insn_opcode <<= 16;
9915 case 'l': /* register list for entry macro */
9916 case 'L': /* register list for exit macro */
9926 int freg, reg1, reg2;
9928 while (*s == ' ' || *s == ',')
9932 as_bad (_("can't parse register list"));
9944 while (ISDIGIT (*s))
9966 as_bad (_("invalid register list"));
9971 while (ISDIGIT (*s))
9978 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9983 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9988 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9989 mask |= (reg2 - 3) << 3;
9990 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9991 mask |= (reg2 - 15) << 1;
9992 else if (reg1 == RA && reg2 == RA)
9996 as_bad (_("invalid register list"));
10000 /* The mask is filled in in the opcode table for the
10001 benefit of the disassembler. We remove it before
10002 applying the actual mask. */
10003 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
10004 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
10008 case 'e': /* extend code */
10009 my_getExpression (&imm_expr, s);
10010 check_absolute_expr (ip, &imm_expr);
10011 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
10013 as_warn (_("Invalid value for `%s' (%lu)"),
10015 (unsigned long) imm_expr.X_add_number);
10016 imm_expr.X_add_number &= 0x7ff;
10018 ip->insn_opcode |= imm_expr.X_add_number;
10019 imm_expr.X_op = O_absent;
10029 /* Args don't match. */
10030 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
10031 strcmp (insn->name, insn[1].name) == 0)
10038 insn_error = _("illegal operands");
10044 /* This structure holds information we know about a mips16 immediate
10047 struct mips16_immed_operand
10049 /* The type code used in the argument string in the opcode table. */
10051 /* The number of bits in the short form of the opcode. */
10053 /* The number of bits in the extended form of the opcode. */
10055 /* The amount by which the short form is shifted when it is used;
10056 for example, the sw instruction has a shift count of 2. */
10058 /* The amount by which the short form is shifted when it is stored
10059 into the instruction code. */
10061 /* Non-zero if the short form is unsigned. */
10063 /* Non-zero if the extended form is unsigned. */
10065 /* Non-zero if the value is PC relative. */
10069 /* The mips16 immediate operand types. */
10071 static const struct mips16_immed_operand mips16_immed_operands[] =
10073 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
10074 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
10075 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
10076 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
10077 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
10078 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
10079 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
10080 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
10081 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
10082 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
10083 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
10084 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
10085 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
10086 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
10087 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
10088 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
10089 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
10090 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
10091 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
10092 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
10093 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
10096 #define MIPS16_NUM_IMMED \
10097 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
10099 /* Handle a mips16 instruction with an immediate value. This or's the
10100 small immediate value into *INSN. It sets *USE_EXTEND to indicate
10101 whether an extended value is needed; if one is needed, it sets
10102 *EXTEND to the value. The argument type is TYPE. The value is VAL.
10103 If SMALL is true, an unextended opcode was explicitly requested.
10104 If EXT is true, an extended opcode was explicitly requested. If
10105 WARN is true, warn if EXT does not match reality. */
10108 mips16_immed (char *file, unsigned int line, int type, offsetT val,
10109 bfd_boolean warn, bfd_boolean small, bfd_boolean ext,
10110 unsigned long *insn, bfd_boolean *use_extend,
10111 unsigned short *extend)
10113 register const struct mips16_immed_operand *op;
10114 int mintiny, maxtiny;
10115 bfd_boolean needext;
10117 op = mips16_immed_operands;
10118 while (op->type != type)
10121 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
10126 if (type == '<' || type == '>' || type == '[' || type == ']')
10129 maxtiny = 1 << op->nbits;
10134 maxtiny = (1 << op->nbits) - 1;
10139 mintiny = - (1 << (op->nbits - 1));
10140 maxtiny = (1 << (op->nbits - 1)) - 1;
10143 /* Branch offsets have an implicit 0 in the lowest bit. */
10144 if (type == 'p' || type == 'q')
10147 if ((val & ((1 << op->shift) - 1)) != 0
10148 || val < (mintiny << op->shift)
10149 || val > (maxtiny << op->shift))
10154 if (warn && ext && ! needext)
10155 as_warn_where (file, line,
10156 _("extended operand requested but not required"));
10157 if (small && needext)
10158 as_bad_where (file, line, _("invalid unextended operand value"));
10160 if (small || (! ext && ! needext))
10164 *use_extend = FALSE;
10165 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
10166 insnval <<= op->op_shift;
10171 long minext, maxext;
10177 maxext = (1 << op->extbits) - 1;
10181 minext = - (1 << (op->extbits - 1));
10182 maxext = (1 << (op->extbits - 1)) - 1;
10184 if (val < minext || val > maxext)
10185 as_bad_where (file, line,
10186 _("operand value out of range for instruction"));
10188 *use_extend = TRUE;
10189 if (op->extbits == 16)
10191 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
10194 else if (op->extbits == 15)
10196 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
10201 extval = ((val & 0x1f) << 6) | (val & 0x20);
10205 *extend = (unsigned short) extval;
10210 static const struct percent_op_match
10213 bfd_reloc_code_real_type reloc;
10216 {"%lo", BFD_RELOC_LO16},
10218 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
10219 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
10220 {"%call16", BFD_RELOC_MIPS_CALL16},
10221 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
10222 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
10223 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
10224 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
10225 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
10226 {"%got", BFD_RELOC_MIPS_GOT16},
10227 {"%gp_rel", BFD_RELOC_GPREL16},
10228 {"%half", BFD_RELOC_16},
10229 {"%highest", BFD_RELOC_MIPS_HIGHEST},
10230 {"%higher", BFD_RELOC_MIPS_HIGHER},
10231 {"%neg", BFD_RELOC_MIPS_SUB},
10233 {"%hi", BFD_RELOC_HI16_S}
10237 /* Return true if *STR points to a relocation operator. When returning true,
10238 move *STR over the operator and store its relocation code in *RELOC.
10239 Leave both *STR and *RELOC alone when returning false. */
10242 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
10246 for (i = 0; i < ARRAY_SIZE (percent_op); i++)
10247 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
10249 *str += strlen (percent_op[i].str);
10250 *reloc = percent_op[i].reloc;
10252 /* Check whether the output BFD supports this relocation.
10253 If not, issue an error and fall back on something safe. */
10254 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
10256 as_bad ("relocation %s isn't supported by the current ABI",
10257 percent_op[i].str);
10258 *reloc = BFD_RELOC_LO16;
10266 /* Parse string STR as a 16-bit relocatable operand. Store the
10267 expression in *EP and the relocations in the array starting
10268 at RELOC. Return the number of relocation operators used.
10270 On exit, EXPR_END points to the first character after the expression.
10271 If no relocation operators are used, RELOC[0] is set to BFD_RELOC_LO16. */
10274 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
10277 bfd_reloc_code_real_type reversed_reloc[3];
10278 size_t reloc_index, i;
10279 int crux_depth, str_depth;
10282 /* Search for the start of the main expression, recoding relocations
10283 in REVERSED_RELOC. End the loop with CRUX pointing to the start
10284 of the main expression and with CRUX_DEPTH containing the number
10285 of open brackets at that point. */
10292 crux_depth = str_depth;
10294 /* Skip over whitespace and brackets, keeping count of the number
10296 while (*str == ' ' || *str == '\t' || *str == '(')
10301 && reloc_index < (HAVE_NEWABI ? 3 : 1)
10302 && parse_relocation (&str, &reversed_reloc[reloc_index]));
10304 my_getExpression (ep, crux);
10307 /* Match every open bracket. */
10308 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
10312 if (crux_depth > 0)
10313 as_bad ("unclosed '('");
10317 if (reloc_index == 0)
10318 reloc[0] = BFD_RELOC_LO16;
10321 prev_reloc_op_frag = frag_now;
10322 for (i = 0; i < reloc_index; i++)
10323 reloc[i] = reversed_reloc[reloc_index - 1 - i];
10326 return reloc_index;
10330 my_getExpression (expressionS *ep, char *str)
10335 save_in = input_line_pointer;
10336 input_line_pointer = str;
10338 expr_end = input_line_pointer;
10339 input_line_pointer = save_in;
10341 /* If we are in mips16 mode, and this is an expression based on `.',
10342 then we bump the value of the symbol by 1 since that is how other
10343 text symbols are handled. We don't bother to handle complex
10344 expressions, just `.' plus or minus a constant. */
10345 if (mips_opts.mips16
10346 && ep->X_op == O_symbol
10347 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
10348 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
10349 && symbol_get_frag (ep->X_add_symbol) == frag_now
10350 && symbol_constant_p (ep->X_add_symbol)
10351 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
10352 S_SET_VALUE (ep->X_add_symbol, val + 1);
10355 /* Turn a string in input_line_pointer into a floating point constant
10356 of type TYPE, and store the appropriate bytes in *LITP. The number
10357 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10358 returned, or NULL on OK. */
10361 md_atof (int type, char *litP, int *sizeP)
10364 LITTLENUM_TYPE words[4];
10380 return _("bad call to md_atof");
10383 t = atof_ieee (input_line_pointer, type, words);
10385 input_line_pointer = t;
10389 if (! target_big_endian)
10391 for (i = prec - 1; i >= 0; i--)
10393 md_number_to_chars (litP, words[i], 2);
10399 for (i = 0; i < prec; i++)
10401 md_number_to_chars (litP, words[i], 2);
10410 md_number_to_chars (char *buf, valueT val, int n)
10412 if (target_big_endian)
10413 number_to_chars_bigendian (buf, val, n);
10415 number_to_chars_littleendian (buf, val, n);
10419 static int support_64bit_objects(void)
10421 const char **list, **l;
10424 list = bfd_target_list ();
10425 for (l = list; *l != NULL; l++)
10427 /* This is traditional mips */
10428 if (strcmp (*l, "elf64-tradbigmips") == 0
10429 || strcmp (*l, "elf64-tradlittlemips") == 0)
10431 if (strcmp (*l, "elf64-bigmips") == 0
10432 || strcmp (*l, "elf64-littlemips") == 0)
10435 yes = (*l != NULL);
10439 #endif /* OBJ_ELF */
10441 const char *md_shortopts = "nO::g::G:";
10443 struct option md_longopts[] =
10445 /* Options which specify architecture. */
10446 #define OPTION_ARCH_BASE (OPTION_MD_BASE)
10447 #define OPTION_MARCH (OPTION_ARCH_BASE + 0)
10448 {"march", required_argument, NULL, OPTION_MARCH},
10449 #define OPTION_MTUNE (OPTION_ARCH_BASE + 1)
10450 {"mtune", required_argument, NULL, OPTION_MTUNE},
10451 #define OPTION_MIPS1 (OPTION_ARCH_BASE + 2)
10452 {"mips0", no_argument, NULL, OPTION_MIPS1},
10453 {"mips1", no_argument, NULL, OPTION_MIPS1},
10454 #define OPTION_MIPS2 (OPTION_ARCH_BASE + 3)
10455 {"mips2", no_argument, NULL, OPTION_MIPS2},
10456 #define OPTION_MIPS3 (OPTION_ARCH_BASE + 4)
10457 {"mips3", no_argument, NULL, OPTION_MIPS3},
10458 #define OPTION_MIPS4 (OPTION_ARCH_BASE + 5)
10459 {"mips4", no_argument, NULL, OPTION_MIPS4},
10460 #define OPTION_MIPS5 (OPTION_ARCH_BASE + 6)
10461 {"mips5", no_argument, NULL, OPTION_MIPS5},
10462 #define OPTION_MIPS32 (OPTION_ARCH_BASE + 7)
10463 {"mips32", no_argument, NULL, OPTION_MIPS32},
10464 #define OPTION_MIPS64 (OPTION_ARCH_BASE + 8)
10465 {"mips64", no_argument, NULL, OPTION_MIPS64},
10466 #define OPTION_MIPS32R2 (OPTION_ARCH_BASE + 9)
10467 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
10468 #define OPTION_MIPS64R2 (OPTION_ARCH_BASE + 10)
10469 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
10471 /* Options which specify Application Specific Extensions (ASEs). */
10472 #define OPTION_ASE_BASE (OPTION_ARCH_BASE + 11)
10473 #define OPTION_MIPS16 (OPTION_ASE_BASE + 0)
10474 {"mips16", no_argument, NULL, OPTION_MIPS16},
10475 #define OPTION_NO_MIPS16 (OPTION_ASE_BASE + 1)
10476 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
10477 #define OPTION_MIPS3D (OPTION_ASE_BASE + 2)
10478 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
10479 #define OPTION_NO_MIPS3D (OPTION_ASE_BASE + 3)
10480 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
10481 #define OPTION_MDMX (OPTION_ASE_BASE + 4)
10482 {"mdmx", no_argument, NULL, OPTION_MDMX},
10483 #define OPTION_NO_MDMX (OPTION_ASE_BASE + 5)
10484 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
10486 /* Old-style architecture options. Don't add more of these. */
10487 #define OPTION_COMPAT_ARCH_BASE (OPTION_ASE_BASE + 6)
10488 #define OPTION_M4650 (OPTION_COMPAT_ARCH_BASE + 0)
10489 {"m4650", no_argument, NULL, OPTION_M4650},
10490 #define OPTION_NO_M4650 (OPTION_COMPAT_ARCH_BASE + 1)
10491 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
10492 #define OPTION_M4010 (OPTION_COMPAT_ARCH_BASE + 2)
10493 {"m4010", no_argument, NULL, OPTION_M4010},
10494 #define OPTION_NO_M4010 (OPTION_COMPAT_ARCH_BASE + 3)
10495 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
10496 #define OPTION_M4100 (OPTION_COMPAT_ARCH_BASE + 4)
10497 {"m4100", no_argument, NULL, OPTION_M4100},
10498 #define OPTION_NO_M4100 (OPTION_COMPAT_ARCH_BASE + 5)
10499 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
10500 #define OPTION_M3900 (OPTION_COMPAT_ARCH_BASE + 6)
10501 {"m3900", no_argument, NULL, OPTION_M3900},
10502 #define OPTION_NO_M3900 (OPTION_COMPAT_ARCH_BASE + 7)
10503 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
10505 /* Options which enable bug fixes. */
10506 #define OPTION_FIX_BASE (OPTION_COMPAT_ARCH_BASE + 8)
10507 #define OPTION_M7000_HILO_FIX (OPTION_FIX_BASE + 0)
10508 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
10509 #define OPTION_MNO_7000_HILO_FIX (OPTION_FIX_BASE + 1)
10510 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10511 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10512 #define OPTION_FIX_VR4122 (OPTION_FIX_BASE + 2)
10513 #define OPTION_NO_FIX_VR4122 (OPTION_FIX_BASE + 3)
10514 {"mfix-vr4122-bugs", no_argument, NULL, OPTION_FIX_VR4122},
10515 {"no-mfix-vr4122-bugs", no_argument, NULL, OPTION_NO_FIX_VR4122},
10517 /* Miscellaneous options. */
10518 #define OPTION_MISC_BASE (OPTION_FIX_BASE + 4)
10519 #define OPTION_MEMBEDDED_PIC (OPTION_MISC_BASE + 0)
10520 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
10521 #define OPTION_TRAP (OPTION_MISC_BASE + 1)
10522 {"trap", no_argument, NULL, OPTION_TRAP},
10523 {"no-break", no_argument, NULL, OPTION_TRAP},
10524 #define OPTION_BREAK (OPTION_MISC_BASE + 2)
10525 {"break", no_argument, NULL, OPTION_BREAK},
10526 {"no-trap", no_argument, NULL, OPTION_BREAK},
10527 #define OPTION_EB (OPTION_MISC_BASE + 3)
10528 {"EB", no_argument, NULL, OPTION_EB},
10529 #define OPTION_EL (OPTION_MISC_BASE + 4)
10530 {"EL", no_argument, NULL, OPTION_EL},
10531 #define OPTION_FP32 (OPTION_MISC_BASE + 5)
10532 {"mfp32", no_argument, NULL, OPTION_FP32},
10533 #define OPTION_GP32 (OPTION_MISC_BASE + 6)
10534 {"mgp32", no_argument, NULL, OPTION_GP32},
10535 #define OPTION_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 7)
10536 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
10537 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 8)
10538 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
10539 #define OPTION_FP64 (OPTION_MISC_BASE + 9)
10540 {"mfp64", no_argument, NULL, OPTION_FP64},
10541 #define OPTION_GP64 (OPTION_MISC_BASE + 10)
10542 {"mgp64", no_argument, NULL, OPTION_GP64},
10543 #define OPTION_RELAX_BRANCH (OPTION_MISC_BASE + 11)
10544 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 12)
10545 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
10546 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
10548 /* ELF-specific options. */
10550 #define OPTION_ELF_BASE (OPTION_MISC_BASE + 13)
10551 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10552 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
10553 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
10554 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10555 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
10556 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10557 {"xgot", no_argument, NULL, OPTION_XGOT},
10558 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10559 {"mabi", required_argument, NULL, OPTION_MABI},
10560 #define OPTION_32 (OPTION_ELF_BASE + 4)
10561 {"32", no_argument, NULL, OPTION_32},
10562 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10563 {"n32", no_argument, NULL, OPTION_N32},
10564 #define OPTION_64 (OPTION_ELF_BASE + 6)
10565 {"64", no_argument, NULL, OPTION_64},
10566 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10567 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
10568 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10569 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
10570 #define OPTION_PDR (OPTION_ELF_BASE + 9)
10571 {"mpdr", no_argument, NULL, OPTION_PDR},
10572 #define OPTION_NO_PDR (OPTION_ELF_BASE + 10)
10573 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
10574 #endif /* OBJ_ELF */
10576 {NULL, no_argument, NULL, 0}
10578 size_t md_longopts_size = sizeof (md_longopts);
10580 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10581 NEW_VALUE. Warn if another value was already specified. Note:
10582 we have to defer parsing the -march and -mtune arguments in order
10583 to handle 'from-abi' correctly, since the ABI might be specified
10584 in a later argument. */
10587 mips_set_option_string (const char **string_ptr, const char *new_value)
10589 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
10590 as_warn (_("A different %s was already specified, is now %s"),
10591 string_ptr == &mips_arch_string ? "-march" : "-mtune",
10594 *string_ptr = new_value;
10598 md_parse_option (int c, char *arg)
10602 case OPTION_CONSTRUCT_FLOATS:
10603 mips_disable_float_construction = 0;
10606 case OPTION_NO_CONSTRUCT_FLOATS:
10607 mips_disable_float_construction = 1;
10619 target_big_endian = 1;
10623 target_big_endian = 0;
10631 if (arg && arg[1] == '0')
10641 mips_debug = atoi (arg);
10642 /* When the MIPS assembler sees -g or -g2, it does not do
10643 optimizations which limit full symbolic debugging. We take
10644 that to be equivalent to -O0. */
10645 if (mips_debug == 2)
10650 file_mips_isa = ISA_MIPS1;
10654 file_mips_isa = ISA_MIPS2;
10658 file_mips_isa = ISA_MIPS3;
10662 file_mips_isa = ISA_MIPS4;
10666 file_mips_isa = ISA_MIPS5;
10669 case OPTION_MIPS32:
10670 file_mips_isa = ISA_MIPS32;
10673 case OPTION_MIPS32R2:
10674 file_mips_isa = ISA_MIPS32R2;
10677 case OPTION_MIPS64R2:
10678 file_mips_isa = ISA_MIPS64R2;
10681 case OPTION_MIPS64:
10682 file_mips_isa = ISA_MIPS64;
10686 mips_set_option_string (&mips_tune_string, arg);
10690 mips_set_option_string (&mips_arch_string, arg);
10694 mips_set_option_string (&mips_arch_string, "4650");
10695 mips_set_option_string (&mips_tune_string, "4650");
10698 case OPTION_NO_M4650:
10702 mips_set_option_string (&mips_arch_string, "4010");
10703 mips_set_option_string (&mips_tune_string, "4010");
10706 case OPTION_NO_M4010:
10710 mips_set_option_string (&mips_arch_string, "4100");
10711 mips_set_option_string (&mips_tune_string, "4100");
10714 case OPTION_NO_M4100:
10718 mips_set_option_string (&mips_arch_string, "3900");
10719 mips_set_option_string (&mips_tune_string, "3900");
10722 case OPTION_NO_M3900:
10726 mips_opts.ase_mdmx = 1;
10729 case OPTION_NO_MDMX:
10730 mips_opts.ase_mdmx = 0;
10733 case OPTION_MIPS16:
10734 mips_opts.mips16 = 1;
10735 mips_no_prev_insn (FALSE);
10738 case OPTION_NO_MIPS16:
10739 mips_opts.mips16 = 0;
10740 mips_no_prev_insn (FALSE);
10743 case OPTION_MIPS3D:
10744 mips_opts.ase_mips3d = 1;
10747 case OPTION_NO_MIPS3D:
10748 mips_opts.ase_mips3d = 0;
10751 case OPTION_MEMBEDDED_PIC:
10752 mips_pic = EMBEDDED_PIC;
10753 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
10755 as_bad (_("-G may not be used with embedded PIC code"));
10758 g_switch_value = 0x7fffffff;
10761 case OPTION_FIX_VR4122:
10762 mips_fix_4122_bugs = 1;
10765 case OPTION_NO_FIX_VR4122:
10766 mips_fix_4122_bugs = 0;
10769 case OPTION_RELAX_BRANCH:
10770 mips_relax_branch = 1;
10773 case OPTION_NO_RELAX_BRANCH:
10774 mips_relax_branch = 0;
10778 /* When generating ELF code, we permit -KPIC and -call_shared to
10779 select SVR4_PIC, and -non_shared to select no PIC. This is
10780 intended to be compatible with Irix 5. */
10781 case OPTION_CALL_SHARED:
10782 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10784 as_bad (_("-call_shared is supported only for ELF format"));
10787 mips_pic = SVR4_PIC;
10788 mips_abicalls = TRUE;
10789 if (g_switch_seen && g_switch_value != 0)
10791 as_bad (_("-G may not be used with SVR4 PIC code"));
10794 g_switch_value = 0;
10797 case OPTION_NON_SHARED:
10798 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10800 as_bad (_("-non_shared is supported only for ELF format"));
10804 mips_abicalls = FALSE;
10807 /* The -xgot option tells the assembler to use 32 offsets when
10808 accessing the got in SVR4_PIC mode. It is for Irix
10813 #endif /* OBJ_ELF */
10816 if (! USE_GLOBAL_POINTER_OPT)
10818 as_bad (_("-G is not supported for this configuration"));
10821 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10823 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10827 g_switch_value = atoi (arg);
10832 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10835 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10837 as_bad (_("-32 is supported for ELF format only"));
10840 mips_abi = O32_ABI;
10844 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10846 as_bad (_("-n32 is supported for ELF format only"));
10849 mips_abi = N32_ABI;
10853 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10855 as_bad (_("-64 is supported for ELF format only"));
10858 mips_abi = N64_ABI;
10859 if (! support_64bit_objects())
10860 as_fatal (_("No compiled in support for 64 bit object file format"));
10862 #endif /* OBJ_ELF */
10865 file_mips_gp32 = 1;
10869 file_mips_gp32 = 0;
10873 file_mips_fp32 = 1;
10877 file_mips_fp32 = 0;
10882 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10884 as_bad (_("-mabi is supported for ELF format only"));
10887 if (strcmp (arg, "32") == 0)
10888 mips_abi = O32_ABI;
10889 else if (strcmp (arg, "o64") == 0)
10890 mips_abi = O64_ABI;
10891 else if (strcmp (arg, "n32") == 0)
10892 mips_abi = N32_ABI;
10893 else if (strcmp (arg, "64") == 0)
10895 mips_abi = N64_ABI;
10896 if (! support_64bit_objects())
10897 as_fatal (_("No compiled in support for 64 bit object file "
10900 else if (strcmp (arg, "eabi") == 0)
10901 mips_abi = EABI_ABI;
10904 as_fatal (_("invalid abi -mabi=%s"), arg);
10908 #endif /* OBJ_ELF */
10910 case OPTION_M7000_HILO_FIX:
10911 mips_7000_hilo_fix = TRUE;
10914 case OPTION_MNO_7000_HILO_FIX:
10915 mips_7000_hilo_fix = FALSE;
10919 case OPTION_MDEBUG:
10920 mips_flag_mdebug = TRUE;
10923 case OPTION_NO_MDEBUG:
10924 mips_flag_mdebug = FALSE;
10928 mips_flag_pdr = TRUE;
10931 case OPTION_NO_PDR:
10932 mips_flag_pdr = FALSE;
10934 #endif /* OBJ_ELF */
10943 /* Set up globals to generate code for the ISA or processor
10944 described by INFO. */
10947 mips_set_architecture (const struct mips_cpu_info *info)
10951 file_mips_arch = info->cpu;
10952 mips_opts.arch = info->cpu;
10953 mips_opts.isa = info->isa;
10958 /* Likewise for tuning. */
10961 mips_set_tune (const struct mips_cpu_info *info)
10964 mips_tune = info->cpu;
10969 mips_after_parse_args (void)
10971 const struct mips_cpu_info *arch_info = 0;
10972 const struct mips_cpu_info *tune_info = 0;
10974 /* GP relative stuff not working for PE */
10975 if (strncmp (TARGET_OS, "pe", 2) == 0
10976 && g_switch_value != 0)
10979 as_bad (_("-G not supported in this configuration."));
10980 g_switch_value = 0;
10983 if (mips_abi == NO_ABI)
10984 mips_abi = MIPS_DEFAULT_ABI;
10986 /* The following code determines the architecture and register size.
10987 Similar code was added to GCC 3.3 (see override_options() in
10988 config/mips/mips.c). The GAS and GCC code should be kept in sync
10989 as much as possible. */
10991 if (mips_arch_string != 0)
10992 arch_info = mips_parse_cpu ("-march", mips_arch_string);
10994 if (file_mips_isa != ISA_UNKNOWN)
10996 /* Handle -mipsN. At this point, file_mips_isa contains the
10997 ISA level specified by -mipsN, while arch_info->isa contains
10998 the -march selection (if any). */
10999 if (arch_info != 0)
11001 /* -march takes precedence over -mipsN, since it is more descriptive.
11002 There's no harm in specifying both as long as the ISA levels
11004 if (file_mips_isa != arch_info->isa)
11005 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
11006 mips_cpu_info_from_isa (file_mips_isa)->name,
11007 mips_cpu_info_from_isa (arch_info->isa)->name);
11010 arch_info = mips_cpu_info_from_isa (file_mips_isa);
11013 if (arch_info == 0)
11014 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
11016 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
11017 as_bad ("-march=%s is not compatible with the selected ABI",
11020 mips_set_architecture (arch_info);
11022 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
11023 if (mips_tune_string != 0)
11024 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
11026 if (tune_info == 0)
11027 mips_set_tune (arch_info);
11029 mips_set_tune (tune_info);
11031 if (file_mips_gp32 >= 0)
11033 /* The user specified the size of the integer registers. Make sure
11034 it agrees with the ABI and ISA. */
11035 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
11036 as_bad (_("-mgp64 used with a 32-bit processor"));
11037 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
11038 as_bad (_("-mgp32 used with a 64-bit ABI"));
11039 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
11040 as_bad (_("-mgp64 used with a 32-bit ABI"));
11044 /* Infer the integer register size from the ABI and processor.
11045 Restrict ourselves to 32-bit registers if that's all the
11046 processor has, or if the ABI cannot handle 64-bit registers. */
11047 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
11048 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
11051 /* ??? GAS treats single-float processors as though they had 64-bit
11052 float registers (although it complains when double-precision
11053 instructions are used). As things stand, saying they have 32-bit
11054 registers would lead to spurious "register must be even" messages.
11055 So here we assume float registers are always the same size as
11056 integer ones, unless the user says otherwise. */
11057 if (file_mips_fp32 < 0)
11058 file_mips_fp32 = file_mips_gp32;
11060 /* End of GCC-shared inference code. */
11062 /* This flag is set when we have a 64-bit capable CPU but use only
11063 32-bit wide registers. Note that EABI does not use it. */
11064 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
11065 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
11066 || mips_abi == O32_ABI))
11067 mips_32bitmode = 1;
11069 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
11070 as_bad (_("trap exception not supported at ISA 1"));
11072 /* If the selected architecture includes support for ASEs, enable
11073 generation of code for them. */
11074 if (mips_opts.mips16 == -1)
11075 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
11076 if (mips_opts.ase_mips3d == -1)
11077 mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (file_mips_arch)) ? 1 : 0;
11078 if (mips_opts.ase_mdmx == -1)
11079 mips_opts.ase_mdmx = (CPU_HAS_MDMX (file_mips_arch)) ? 1 : 0;
11081 file_mips_isa = mips_opts.isa;
11082 file_ase_mips16 = mips_opts.mips16;
11083 file_ase_mips3d = mips_opts.ase_mips3d;
11084 file_ase_mdmx = mips_opts.ase_mdmx;
11085 mips_opts.gp32 = file_mips_gp32;
11086 mips_opts.fp32 = file_mips_fp32;
11088 if (mips_flag_mdebug < 0)
11090 #ifdef OBJ_MAYBE_ECOFF
11091 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
11092 mips_flag_mdebug = 1;
11094 #endif /* OBJ_MAYBE_ECOFF */
11095 mips_flag_mdebug = 0;
11100 mips_init_after_args (void)
11102 /* initialize opcodes */
11103 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
11104 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
11108 md_pcrel_from (fixS *fixP)
11110 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
11111 switch (fixP->fx_r_type)
11113 case BFD_RELOC_16_PCREL_S2:
11114 case BFD_RELOC_MIPS_JMP:
11115 /* Return the address of the delay slot. */
11122 /* This is called before the symbol table is processed. In order to
11123 work with gcc when using mips-tfile, we must keep all local labels.
11124 However, in other cases, we want to discard them. If we were
11125 called with -g, but we didn't see any debugging information, it may
11126 mean that gcc is smuggling debugging information through to
11127 mips-tfile, in which case we must generate all local labels. */
11130 mips_frob_file_before_adjust (void)
11132 #ifndef NO_ECOFF_DEBUGGING
11133 if (ECOFF_DEBUGGING
11135 && ! ecoff_debugging_seen)
11136 flag_keep_locals = 1;
11140 /* Sort any unmatched HI16_S relocs so that they immediately precede
11141 the corresponding LO reloc. This is called before md_apply_fix3 and
11142 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
11143 explicit use of the %hi modifier. */
11146 mips_frob_file (void)
11148 struct mips_hi_fixup *l;
11150 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
11152 segment_info_type *seginfo;
11155 assert (reloc_needs_lo_p (l->fixp->fx_r_type));
11157 /* If a GOT16 relocation turns out to be against a global symbol,
11158 there isn't supposed to be a matching LO. */
11159 if (l->fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
11160 && !pic_need_relax (l->fixp->fx_addsy, l->seg))
11163 /* Check quickly whether the next fixup happens to be a matching %lo. */
11164 if (fixup_has_matching_lo_p (l->fixp))
11167 /* Look through the fixups for this segment for a matching %lo.
11168 When we find one, move the %hi just in front of it. We do
11169 this in two passes. In the first pass, we try to find a
11170 unique %lo. In the second pass, we permit multiple %hi
11171 relocs for a single %lo (this is a GNU extension). */
11172 seginfo = seg_info (l->seg);
11173 for (pass = 0; pass < 2; pass++)
11178 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
11180 /* Check whether this is a %lo fixup which matches l->fixp. */
11181 if (f->fx_r_type == BFD_RELOC_LO16
11182 && f->fx_addsy == l->fixp->fx_addsy
11183 && f->fx_offset == l->fixp->fx_offset
11186 || !reloc_needs_lo_p (prev->fx_r_type)
11187 || !fixup_has_matching_lo_p (prev)))
11191 /* Move l->fixp before f. */
11192 for (pf = &seginfo->fix_root;
11194 pf = &(*pf)->fx_next)
11195 assert (*pf != NULL);
11197 *pf = l->fixp->fx_next;
11199 l->fixp->fx_next = f;
11201 seginfo->fix_root = l->fixp;
11203 prev->fx_next = l->fixp;
11214 #if 0 /* GCC code motion plus incomplete dead code elimination
11215 can leave a %hi without a %lo. */
11217 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
11218 _("Unmatched %%hi reloc"));
11224 /* When generating embedded PIC code we need to use a special
11225 relocation to represent the difference of two symbols in the .text
11226 section (switch tables use a difference of this sort). See
11227 include/coff/mips.h for details. This macro checks whether this
11228 fixup requires the special reloc. */
11229 #define SWITCH_TABLE(fixp) \
11230 ((fixp)->fx_r_type == BFD_RELOC_32 \
11231 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
11232 && (fixp)->fx_addsy != NULL \
11233 && (fixp)->fx_subsy != NULL \
11234 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
11235 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
11237 /* When generating embedded PIC code we must keep all PC relative
11238 relocations, in case the linker has to relax a call. We also need
11239 to keep relocations for switch table entries.
11241 We may have combined relocations without symbols in the N32/N64 ABI.
11242 We have to prevent gas from dropping them. */
11245 mips_force_relocation (fixS *fixp)
11247 if (generic_force_reloc (fixp))
11251 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
11252 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
11253 || fixp->fx_r_type == BFD_RELOC_HI16_S
11254 || fixp->fx_r_type == BFD_RELOC_LO16))
11257 return (mips_pic == EMBEDDED_PIC
11259 || SWITCH_TABLE (fixp)
11260 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
11261 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
11264 /* This hook is called before a fix is simplified. We don't really
11265 decide whether to skip a fix here. Rather, we turn global symbols
11266 used as branch targets into local symbols, such that they undergo
11267 simplification. We can only do this if the symbol is defined and
11268 it is in the same section as the branch. If this doesn't hold, we
11269 emit a better error message than just saying the relocation is not
11270 valid for the selected object format.
11272 FIXP is the fix-up we're going to try to simplify, SEG is the
11273 segment in which the fix up occurs. The return value should be
11274 non-zero to indicate the fix-up is valid for further
11275 simplifications. */
11278 mips_validate_fix (struct fix *fixP, asection *seg)
11280 /* There's a lot of discussion on whether it should be possible to
11281 use R_MIPS_PC16 to represent branch relocations. The outcome
11282 seems to be that it can, but gas/bfd are very broken in creating
11283 RELA relocations for this, so for now we only accept branches to
11284 symbols in the same section. Anything else is of dubious value,
11285 since there's no guarantee that at link time the symbol would be
11286 in range. Even for branches to local symbols this is arguably
11287 wrong, since it we assume the symbol is not going to be
11288 overridden, which should be possible per ELF library semantics,
11289 but then, there isn't a dynamic relocation that could be used to
11290 this effect, and the target would likely be out of range as well.
11292 Unfortunately, it seems that there is too much code out there
11293 that relies on branches to symbols that are global to be resolved
11294 as if they were local, like the IRIX tools do, so we do it as
11295 well, but with a warning so that people are reminded to fix their
11296 code. If we ever get back to using R_MIPS_PC16 for branch
11297 targets, this entire block should go away (and probably the
11298 whole function). */
11300 if (fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
11301 && (((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
11302 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11303 && mips_pic != EMBEDDED_PIC)
11304 || bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16_PCREL_S2) == NULL)
11307 if (! S_IS_DEFINED (fixP->fx_addsy))
11309 as_bad_where (fixP->fx_file, fixP->fx_line,
11310 _("Cannot branch to undefined symbol."));
11311 /* Avoid any further errors about this fixup. */
11314 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
11316 as_bad_where (fixP->fx_file, fixP->fx_line,
11317 _("Cannot branch to symbol in another section."));
11320 else if (S_IS_EXTERNAL (fixP->fx_addsy))
11322 symbolS *sym = fixP->fx_addsy;
11324 if (mips_pic == SVR4_PIC)
11325 as_warn_where (fixP->fx_file, fixP->fx_line,
11326 _("Pretending global symbol used as branch target is local."));
11328 fixP->fx_addsy = symbol_create (S_GET_NAME (sym),
11329 S_GET_SEGMENT (sym),
11331 symbol_get_frag (sym));
11332 copy_symbol_attributes (fixP->fx_addsy, sym);
11333 S_CLEAR_EXTERNAL (fixP->fx_addsy);
11334 assert (symbol_resolved_p (sym));
11335 symbol_mark_resolved (fixP->fx_addsy);
11344 mips_need_elf_addend_fixup (fixS *fixP)
11346 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
11348 if (mips_pic == EMBEDDED_PIC
11349 && S_IS_WEAK (fixP->fx_addsy))
11351 if (mips_pic != EMBEDDED_PIC
11352 && (S_IS_WEAK (fixP->fx_addsy)
11353 || S_IS_EXTERNAL (fixP->fx_addsy))
11354 && !S_IS_COMMON (fixP->fx_addsy))
11356 if (((bfd_get_section_flags (stdoutput,
11357 S_GET_SEGMENT (fixP->fx_addsy))
11358 & (SEC_LINK_ONCE | SEC_MERGE)) != 0)
11359 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
11361 sizeof (".gnu.linkonce") - 1))
11367 /* Apply a fixup to the object file. */
11370 md_apply_fix3 (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
11374 static int previous_fx_r_type = 0;
11375 reloc_howto_type *howto;
11377 /* We ignore generic BFD relocations we don't know about. */
11378 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
11382 assert (fixP->fx_size == 4
11383 || fixP->fx_r_type == BFD_RELOC_16
11384 || fixP->fx_r_type == BFD_RELOC_64
11385 || fixP->fx_r_type == BFD_RELOC_CTOR
11386 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11387 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11388 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
11390 buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
11392 /* If we aren't adjusting this fixup to be against the section
11393 symbol, we need to adjust the value. */
11395 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
11397 if (mips_need_elf_addend_fixup (fixP)
11398 && howto->partial_inplace
11399 && fixP->fx_r_type != BFD_RELOC_GPREL16
11400 && fixP->fx_r_type != BFD_RELOC_GPREL32
11401 && fixP->fx_r_type != BFD_RELOC_MIPS16_GPREL)
11403 /* In this case, the bfd_install_relocation routine will
11404 incorrectly add the symbol value back in. We just want
11405 the addend to appear in the object file.
11407 The condition above used to include
11408 "&& (! fixP->fx_pcrel || howto->pcrel_offset)".
11410 However, howto can't be trusted here, because we
11411 might change the reloc type in tc_gen_reloc. We can
11412 check howto->partial_inplace because that conversion
11413 happens to preserve howto->partial_inplace; but it
11414 does not preserve howto->pcrel_offset. I've just
11415 eliminated the check, because all MIPS PC-relative
11416 relocations are marked howto->pcrel_offset.
11418 howto->pcrel_offset was originally added for
11419 R_MIPS_PC16, which is generated for code like
11428 *valP -= S_GET_VALUE (fixP->fx_addsy);
11431 /* This code was generated using trial and error and so is
11432 fragile and not trustworthy. If you change it, you should
11433 rerun the elf-rel, elf-rel2, and empic testcases and ensure
11434 they still pass. */
11435 if (fixP->fx_pcrel)
11437 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11439 /* BFD's REL handling, for MIPS, is _very_ weird.
11440 This gives the right results, but it can't possibly
11441 be the way things are supposed to work. */
11442 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11447 /* We are not done if this is a composite relocation to set up gp. */
11448 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel
11449 && !(fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11450 || (fixP->fx_r_type == BFD_RELOC_64
11451 && (previous_fx_r_type == BFD_RELOC_GPREL32
11452 || previous_fx_r_type == BFD_RELOC_GPREL16))
11453 || (previous_fx_r_type == BFD_RELOC_MIPS_SUB
11454 && (fixP->fx_r_type == BFD_RELOC_HI16_S
11455 || fixP->fx_r_type == BFD_RELOC_LO16))))
11457 previous_fx_r_type = fixP->fx_r_type;
11459 switch (fixP->fx_r_type)
11461 case BFD_RELOC_MIPS_JMP:
11462 case BFD_RELOC_MIPS_SHIFT5:
11463 case BFD_RELOC_MIPS_SHIFT6:
11464 case BFD_RELOC_MIPS_GOT_DISP:
11465 case BFD_RELOC_MIPS_GOT_PAGE:
11466 case BFD_RELOC_MIPS_GOT_OFST:
11467 case BFD_RELOC_MIPS_SUB:
11468 case BFD_RELOC_MIPS_INSERT_A:
11469 case BFD_RELOC_MIPS_INSERT_B:
11470 case BFD_RELOC_MIPS_DELETE:
11471 case BFD_RELOC_MIPS_HIGHEST:
11472 case BFD_RELOC_MIPS_HIGHER:
11473 case BFD_RELOC_MIPS_SCN_DISP:
11474 case BFD_RELOC_MIPS_REL16:
11475 case BFD_RELOC_MIPS_RELGOT:
11476 case BFD_RELOC_MIPS_JALR:
11477 case BFD_RELOC_HI16:
11478 case BFD_RELOC_HI16_S:
11479 case BFD_RELOC_GPREL16:
11480 case BFD_RELOC_MIPS_LITERAL:
11481 case BFD_RELOC_MIPS_CALL16:
11482 case BFD_RELOC_MIPS_GOT16:
11483 case BFD_RELOC_GPREL32:
11484 case BFD_RELOC_MIPS_GOT_HI16:
11485 case BFD_RELOC_MIPS_GOT_LO16:
11486 case BFD_RELOC_MIPS_CALL_HI16:
11487 case BFD_RELOC_MIPS_CALL_LO16:
11488 case BFD_RELOC_MIPS16_GPREL:
11489 if (fixP->fx_pcrel)
11490 as_bad_where (fixP->fx_file, fixP->fx_line,
11491 _("Invalid PC relative reloc"));
11492 /* Nothing needed to do. The value comes from the reloc entry */
11495 case BFD_RELOC_MIPS16_JMP:
11496 /* We currently always generate a reloc against a symbol, which
11497 means that we don't want an addend even if the symbol is
11502 case BFD_RELOC_PCREL_HI16_S:
11503 /* The addend for this is tricky if it is internal, so we just
11504 do everything here rather than in bfd_install_relocation. */
11505 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && !fixP->fx_done)
11508 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11510 /* For an external symbol adjust by the address to make it
11511 pcrel_offset. We use the address of the RELLO reloc
11512 which follows this one. */
11513 *valP += (fixP->fx_next->fx_frag->fr_address
11514 + fixP->fx_next->fx_where);
11516 *valP = ((*valP + 0x8000) >> 16) & 0xffff;
11517 if (target_big_endian)
11519 md_number_to_chars (buf, *valP, 2);
11522 case BFD_RELOC_PCREL_LO16:
11523 /* The addend for this is tricky if it is internal, so we just
11524 do everything here rather than in bfd_install_relocation. */
11525 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && !fixP->fx_done)
11528 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11529 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11530 if (target_big_endian)
11532 md_number_to_chars (buf, *valP, 2);
11536 /* This is handled like BFD_RELOC_32, but we output a sign
11537 extended value if we are only 32 bits. */
11539 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11541 if (8 <= sizeof (valueT))
11542 md_number_to_chars (buf, *valP, 8);
11547 if ((*valP & 0x80000000) != 0)
11551 md_number_to_chars ((char *)(buf + target_big_endian ? 4 : 0),
11553 md_number_to_chars ((char *)(buf + target_big_endian ? 0 : 4),
11559 case BFD_RELOC_RVA:
11561 /* If we are deleting this reloc entry, we must fill in the
11562 value now. This can happen if we have a .word which is not
11563 resolved when it appears but is later defined. We also need
11564 to fill in the value if this is an embedded PIC switch table
11567 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11568 md_number_to_chars (buf, *valP, 4);
11572 /* If we are deleting this reloc entry, we must fill in the
11574 assert (fixP->fx_size == 2);
11576 md_number_to_chars (buf, *valP, 2);
11579 case BFD_RELOC_LO16:
11580 /* When handling an embedded PIC switch statement, we can wind
11581 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11584 if (*valP + 0x8000 > 0xffff)
11585 as_bad_where (fixP->fx_file, fixP->fx_line,
11586 _("relocation overflow"));
11587 if (target_big_endian)
11589 md_number_to_chars (buf, *valP, 2);
11593 case BFD_RELOC_16_PCREL_S2:
11594 if ((*valP & 0x3) != 0)
11595 as_bad_where (fixP->fx_file, fixP->fx_line,
11596 _("Branch to odd address (%lx)"), (long) *valP);
11599 * We need to save the bits in the instruction since fixup_segment()
11600 * might be deleting the relocation entry (i.e., a branch within
11601 * the current segment).
11603 if (! fixP->fx_done)
11606 /* update old instruction data */
11607 if (target_big_endian)
11608 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
11610 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
11612 if (*valP + 0x20000 <= 0x3ffff)
11614 insn |= (*valP >> 2) & 0xffff;
11615 md_number_to_chars (buf, insn, 4);
11617 else if (mips_pic == NO_PIC
11619 && fixP->fx_frag->fr_address >= text_section->vma
11620 && (fixP->fx_frag->fr_address
11621 < text_section->vma + text_section->_raw_size)
11622 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
11623 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
11624 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
11626 /* The branch offset is too large. If this is an
11627 unconditional branch, and we are not generating PIC code,
11628 we can convert it to an absolute jump instruction. */
11629 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
11630 insn = 0x0c000000; /* jal */
11632 insn = 0x08000000; /* j */
11633 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
11635 fixP->fx_addsy = section_symbol (text_section);
11636 *valP += md_pcrel_from (fixP);
11637 md_number_to_chars (buf, insn, 4);
11641 /* If we got here, we have branch-relaxation disabled,
11642 and there's nothing we can do to fix this instruction
11643 without turning it into a longer sequence. */
11644 as_bad_where (fixP->fx_file, fixP->fx_line,
11645 _("Branch out of range"));
11649 case BFD_RELOC_VTABLE_INHERIT:
11652 && !S_IS_DEFINED (fixP->fx_addsy)
11653 && !S_IS_WEAK (fixP->fx_addsy))
11654 S_SET_WEAK (fixP->fx_addsy);
11657 case BFD_RELOC_VTABLE_ENTRY:
11665 /* Remember value for tc_gen_reloc. */
11666 fixP->fx_addnumber = *valP;
11671 printInsn (unsigned long oc)
11673 const struct mips_opcode *p;
11674 int treg, sreg, dreg, shamt;
11679 for (i = 0; i < NUMOPCODES; ++i)
11681 p = &mips_opcodes[i];
11682 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
11684 printf ("%08lx %s\t", oc, p->name);
11685 treg = (oc >> 16) & 0x1f;
11686 sreg = (oc >> 21) & 0x1f;
11687 dreg = (oc >> 11) & 0x1f;
11688 shamt = (oc >> 6) & 0x1f;
11690 for (args = p->args;; ++args)
11701 printf ("%c", *args);
11705 assert (treg == sreg);
11706 printf ("$%d,$%d", treg, sreg);
11711 printf ("$%d", dreg);
11716 printf ("$%d", treg);
11720 printf ("0x%x", treg);
11725 printf ("$%d", sreg);
11729 printf ("0x%08lx", oc & 0x1ffffff);
11736 printf ("%d", imm);
11741 printf ("$%d", shamt);
11752 printf (_("%08lx UNDEFINED\n"), oc);
11763 name = input_line_pointer;
11764 c = get_symbol_end ();
11765 p = (symbolS *) symbol_find_or_make (name);
11766 *input_line_pointer = c;
11770 /* Align the current frag to a given power of two. The MIPS assembler
11771 also automatically adjusts any preceding label. */
11774 mips_align (int to, int fill, symbolS *label)
11776 mips_emit_delays (FALSE);
11777 frag_align (to, fill, 0);
11778 record_alignment (now_seg, to);
11781 assert (S_GET_SEGMENT (label) == now_seg);
11782 symbol_set_frag (label, frag_now);
11783 S_SET_VALUE (label, (valueT) frag_now_fix ());
11787 /* Align to a given power of two. .align 0 turns off the automatic
11788 alignment used by the data creating pseudo-ops. */
11791 s_align (int x ATTRIBUTE_UNUSED)
11794 register long temp_fill;
11795 long max_alignment = 15;
11799 o Note that the assembler pulls down any immediately preceding label
11800 to the aligned address.
11801 o It's not documented but auto alignment is reinstated by
11802 a .align pseudo instruction.
11803 o Note also that after auto alignment is turned off the mips assembler
11804 issues an error on attempt to assemble an improperly aligned data item.
11809 temp = get_absolute_expression ();
11810 if (temp > max_alignment)
11811 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11814 as_warn (_("Alignment negative: 0 assumed."));
11817 if (*input_line_pointer == ',')
11819 ++input_line_pointer;
11820 temp_fill = get_absolute_expression ();
11827 mips_align (temp, (int) temp_fill,
11828 insn_labels != NULL ? insn_labels->label : NULL);
11835 demand_empty_rest_of_line ();
11839 mips_flush_pending_output (void)
11841 mips_emit_delays (FALSE);
11842 mips_clear_insn_labels ();
11846 s_change_sec (int sec)
11850 /* When generating embedded PIC code, we only use the .text, .lit8,
11851 .sdata and .sbss sections. We change the .data and .rdata
11852 pseudo-ops to use .sdata. */
11853 if (mips_pic == EMBEDDED_PIC
11854 && (sec == 'd' || sec == 'r'))
11858 /* The ELF backend needs to know that we are changing sections, so
11859 that .previous works correctly. We could do something like check
11860 for an obj_section_change_hook macro, but that might be confusing
11861 as it would not be appropriate to use it in the section changing
11862 functions in read.c, since obj-elf.c intercepts those. FIXME:
11863 This should be cleaner, somehow. */
11864 obj_elf_section_change_hook ();
11867 mips_emit_delays (FALSE);
11877 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11878 demand_empty_rest_of_line ();
11882 if (USE_GLOBAL_POINTER_OPT)
11884 seg = subseg_new (RDATA_SECTION_NAME,
11885 (subsegT) get_absolute_expression ());
11886 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11888 bfd_set_section_flags (stdoutput, seg,
11894 if (strcmp (TARGET_OS, "elf") != 0)
11895 record_alignment (seg, 4);
11897 demand_empty_rest_of_line ();
11901 as_bad (_("No read only data section in this object file format"));
11902 demand_empty_rest_of_line ();
11908 if (USE_GLOBAL_POINTER_OPT)
11910 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11911 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11913 bfd_set_section_flags (stdoutput, seg,
11914 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11916 if (strcmp (TARGET_OS, "elf") != 0)
11917 record_alignment (seg, 4);
11919 demand_empty_rest_of_line ();
11924 as_bad (_("Global pointers not supported; recompile -G 0"));
11925 demand_empty_rest_of_line ();
11934 s_change_section (int ignore ATTRIBUTE_UNUSED)
11937 char *section_name;
11942 int section_entry_size;
11943 int section_alignment;
11945 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11948 section_name = input_line_pointer;
11949 c = get_symbol_end ();
11951 next_c = *(input_line_pointer + 1);
11953 /* Do we have .section Name<,"flags">? */
11954 if (c != ',' || (c == ',' && next_c == '"'))
11956 /* just after name is now '\0'. */
11957 *input_line_pointer = c;
11958 input_line_pointer = section_name;
11959 obj_elf_section (ignore);
11962 input_line_pointer++;
11964 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
11966 section_type = get_absolute_expression ();
11969 if (*input_line_pointer++ == ',')
11970 section_flag = get_absolute_expression ();
11973 if (*input_line_pointer++ == ',')
11974 section_entry_size = get_absolute_expression ();
11976 section_entry_size = 0;
11977 if (*input_line_pointer++ == ',')
11978 section_alignment = get_absolute_expression ();
11980 section_alignment = 0;
11982 section_name = xstrdup (section_name);
11984 obj_elf_change_section (section_name, section_type, section_flag,
11985 section_entry_size, 0, 0, 0);
11987 if (now_seg->name != section_name)
11988 free (section_name);
11989 #endif /* OBJ_ELF */
11993 mips_enable_auto_align (void)
11999 s_cons (int log_size)
12003 label = insn_labels != NULL ? insn_labels->label : NULL;
12004 mips_emit_delays (FALSE);
12005 if (log_size > 0 && auto_align)
12006 mips_align (log_size, 0, label);
12007 mips_clear_insn_labels ();
12008 cons (1 << log_size);
12012 s_float_cons (int type)
12016 label = insn_labels != NULL ? insn_labels->label : NULL;
12018 mips_emit_delays (FALSE);
12023 mips_align (3, 0, label);
12025 mips_align (2, 0, label);
12028 mips_clear_insn_labels ();
12033 /* Handle .globl. We need to override it because on Irix 5 you are
12036 where foo is an undefined symbol, to mean that foo should be
12037 considered to be the address of a function. */
12040 s_mips_globl (int x ATTRIBUTE_UNUSED)
12047 name = input_line_pointer;
12048 c = get_symbol_end ();
12049 symbolP = symbol_find_or_make (name);
12050 *input_line_pointer = c;
12051 SKIP_WHITESPACE ();
12053 /* On Irix 5, every global symbol that is not explicitly labelled as
12054 being a function is apparently labelled as being an object. */
12057 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12062 secname = input_line_pointer;
12063 c = get_symbol_end ();
12064 sec = bfd_get_section_by_name (stdoutput, secname);
12066 as_bad (_("%s: no such section"), secname);
12067 *input_line_pointer = c;
12069 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
12070 flag = BSF_FUNCTION;
12073 symbol_get_bfdsym (symbolP)->flags |= flag;
12075 S_SET_EXTERNAL (symbolP);
12076 demand_empty_rest_of_line ();
12080 s_option (int x ATTRIBUTE_UNUSED)
12085 opt = input_line_pointer;
12086 c = get_symbol_end ();
12090 /* FIXME: What does this mean? */
12092 else if (strncmp (opt, "pic", 3) == 0)
12096 i = atoi (opt + 3);
12101 mips_pic = SVR4_PIC;
12102 mips_abicalls = TRUE;
12105 as_bad (_(".option pic%d not supported"), i);
12107 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
12109 if (g_switch_seen && g_switch_value != 0)
12110 as_warn (_("-G may not be used with SVR4 PIC code"));
12111 g_switch_value = 0;
12112 bfd_set_gp_size (stdoutput, 0);
12116 as_warn (_("Unrecognized option \"%s\""), opt);
12118 *input_line_pointer = c;
12119 demand_empty_rest_of_line ();
12122 /* This structure is used to hold a stack of .set values. */
12124 struct mips_option_stack
12126 struct mips_option_stack *next;
12127 struct mips_set_options options;
12130 static struct mips_option_stack *mips_opts_stack;
12132 /* Handle the .set pseudo-op. */
12135 s_mipsset (int x ATTRIBUTE_UNUSED)
12137 char *name = input_line_pointer, ch;
12139 while (!is_end_of_line[(unsigned char) *input_line_pointer])
12140 ++input_line_pointer;
12141 ch = *input_line_pointer;
12142 *input_line_pointer = '\0';
12144 if (strcmp (name, "reorder") == 0)
12146 if (mips_opts.noreorder && prev_nop_frag != NULL)
12148 /* If we still have pending nops, we can discard them. The
12149 usual nop handling will insert any that are still
12151 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
12152 * (mips_opts.mips16 ? 2 : 4));
12153 prev_nop_frag = NULL;
12155 mips_opts.noreorder = 0;
12157 else if (strcmp (name, "noreorder") == 0)
12159 mips_emit_delays (TRUE);
12160 mips_opts.noreorder = 1;
12161 mips_any_noreorder = 1;
12163 else if (strcmp (name, "at") == 0)
12165 mips_opts.noat = 0;
12167 else if (strcmp (name, "noat") == 0)
12169 mips_opts.noat = 1;
12171 else if (strcmp (name, "macro") == 0)
12173 mips_opts.warn_about_macros = 0;
12175 else if (strcmp (name, "nomacro") == 0)
12177 if (mips_opts.noreorder == 0)
12178 as_bad (_("`noreorder' must be set before `nomacro'"));
12179 mips_opts.warn_about_macros = 1;
12181 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
12183 mips_opts.nomove = 0;
12185 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
12187 mips_opts.nomove = 1;
12189 else if (strcmp (name, "bopt") == 0)
12191 mips_opts.nobopt = 0;
12193 else if (strcmp (name, "nobopt") == 0)
12195 mips_opts.nobopt = 1;
12197 else if (strcmp (name, "mips16") == 0
12198 || strcmp (name, "MIPS-16") == 0)
12199 mips_opts.mips16 = 1;
12200 else if (strcmp (name, "nomips16") == 0
12201 || strcmp (name, "noMIPS-16") == 0)
12202 mips_opts.mips16 = 0;
12203 else if (strcmp (name, "mips3d") == 0)
12204 mips_opts.ase_mips3d = 1;
12205 else if (strcmp (name, "nomips3d") == 0)
12206 mips_opts.ase_mips3d = 0;
12207 else if (strcmp (name, "mdmx") == 0)
12208 mips_opts.ase_mdmx = 1;
12209 else if (strcmp (name, "nomdmx") == 0)
12210 mips_opts.ase_mdmx = 0;
12211 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
12215 /* Permit the user to change the ISA and architecture on the fly.
12216 Needless to say, misuse can cause serious problems. */
12217 if (strcmp (name, "mips0") == 0)
12220 mips_opts.isa = file_mips_isa;
12222 else if (strcmp (name, "mips1") == 0)
12223 mips_opts.isa = ISA_MIPS1;
12224 else if (strcmp (name, "mips2") == 0)
12225 mips_opts.isa = ISA_MIPS2;
12226 else if (strcmp (name, "mips3") == 0)
12227 mips_opts.isa = ISA_MIPS3;
12228 else if (strcmp (name, "mips4") == 0)
12229 mips_opts.isa = ISA_MIPS4;
12230 else if (strcmp (name, "mips5") == 0)
12231 mips_opts.isa = ISA_MIPS5;
12232 else if (strcmp (name, "mips32") == 0)
12233 mips_opts.isa = ISA_MIPS32;
12234 else if (strcmp (name, "mips32r2") == 0)
12235 mips_opts.isa = ISA_MIPS32R2;
12236 else if (strcmp (name, "mips64") == 0)
12237 mips_opts.isa = ISA_MIPS64;
12238 else if (strcmp (name, "mips64r2") == 0)
12239 mips_opts.isa = ISA_MIPS64R2;
12240 else if (strcmp (name, "arch=default") == 0)
12243 mips_opts.arch = file_mips_arch;
12244 mips_opts.isa = file_mips_isa;
12246 else if (strncmp (name, "arch=", 5) == 0)
12248 const struct mips_cpu_info *p;
12250 p = mips_parse_cpu("internal use", name + 5);
12252 as_bad (_("unknown architecture %s"), name + 5);
12255 mips_opts.arch = p->cpu;
12256 mips_opts.isa = p->isa;
12260 as_bad (_("unknown ISA level %s"), name + 4);
12262 switch (mips_opts.isa)
12270 mips_opts.gp32 = 1;
12271 mips_opts.fp32 = 1;
12278 mips_opts.gp32 = 0;
12279 mips_opts.fp32 = 0;
12282 as_bad (_("unknown ISA level %s"), name + 4);
12287 mips_opts.gp32 = file_mips_gp32;
12288 mips_opts.fp32 = file_mips_fp32;
12291 else if (strcmp (name, "autoextend") == 0)
12292 mips_opts.noautoextend = 0;
12293 else if (strcmp (name, "noautoextend") == 0)
12294 mips_opts.noautoextend = 1;
12295 else if (strcmp (name, "push") == 0)
12297 struct mips_option_stack *s;
12299 s = (struct mips_option_stack *) xmalloc (sizeof *s);
12300 s->next = mips_opts_stack;
12301 s->options = mips_opts;
12302 mips_opts_stack = s;
12304 else if (strcmp (name, "pop") == 0)
12306 struct mips_option_stack *s;
12308 s = mips_opts_stack;
12310 as_bad (_(".set pop with no .set push"));
12313 /* If we're changing the reorder mode we need to handle
12314 delay slots correctly. */
12315 if (s->options.noreorder && ! mips_opts.noreorder)
12316 mips_emit_delays (TRUE);
12317 else if (! s->options.noreorder && mips_opts.noreorder)
12319 if (prev_nop_frag != NULL)
12321 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
12322 * (mips_opts.mips16 ? 2 : 4));
12323 prev_nop_frag = NULL;
12327 mips_opts = s->options;
12328 mips_opts_stack = s->next;
12334 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
12336 *input_line_pointer = ch;
12337 demand_empty_rest_of_line ();
12340 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
12341 .option pic2. It means to generate SVR4 PIC calls. */
12344 s_abicalls (int ignore ATTRIBUTE_UNUSED)
12346 mips_pic = SVR4_PIC;
12347 mips_abicalls = TRUE;
12348 if (USE_GLOBAL_POINTER_OPT)
12350 if (g_switch_seen && g_switch_value != 0)
12351 as_warn (_("-G may not be used with SVR4 PIC code"));
12352 g_switch_value = 0;
12354 bfd_set_gp_size (stdoutput, 0);
12355 demand_empty_rest_of_line ();
12358 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12359 PIC code. It sets the $gp register for the function based on the
12360 function address, which is in the register named in the argument.
12361 This uses a relocation against _gp_disp, which is handled specially
12362 by the linker. The result is:
12363 lui $gp,%hi(_gp_disp)
12364 addiu $gp,$gp,%lo(_gp_disp)
12365 addu $gp,$gp,.cpload argument
12366 The .cpload argument is normally $25 == $t9. */
12369 s_cpload (int ignore ATTRIBUTE_UNUSED)
12374 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12375 .cpload is ignored. */
12376 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12382 /* .cpload should be in a .set noreorder section. */
12383 if (mips_opts.noreorder == 0)
12384 as_warn (_(".cpload not in noreorder section"));
12386 ex.X_op = O_symbol;
12387 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
12388 ex.X_op_symbol = NULL;
12389 ex.X_add_number = 0;
12391 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12392 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
12394 macro_build_lui (NULL, &icnt, &ex, mips_gp_register);
12395 macro_build (NULL, &icnt, &ex, "addiu", "t,r,j", mips_gp_register,
12396 mips_gp_register, BFD_RELOC_LO16);
12398 macro_build (NULL, &icnt, NULL, "addu", "d,v,t", mips_gp_register,
12399 mips_gp_register, tc_get_register (0));
12401 demand_empty_rest_of_line ();
12404 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12405 .cpsetup $reg1, offset|$reg2, label
12407 If offset is given, this results in:
12408 sd $gp, offset($sp)
12409 lui $gp, %hi(%neg(%gp_rel(label)))
12410 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12411 daddu $gp, $gp, $reg1
12413 If $reg2 is given, this results in:
12414 daddu $reg2, $gp, $0
12415 lui $gp, %hi(%neg(%gp_rel(label)))
12416 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12417 daddu $gp, $gp, $reg1
12418 $reg1 is normally $25 == $t9. */
12420 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
12422 expressionS ex_off;
12423 expressionS ex_sym;
12428 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12429 We also need NewABI support. */
12430 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12436 reg1 = tc_get_register (0);
12437 SKIP_WHITESPACE ();
12438 if (*input_line_pointer != ',')
12440 as_bad (_("missing argument separator ',' for .cpsetup"));
12444 ++input_line_pointer;
12445 SKIP_WHITESPACE ();
12446 if (*input_line_pointer == '$')
12448 mips_cpreturn_register = tc_get_register (0);
12449 mips_cpreturn_offset = -1;
12453 mips_cpreturn_offset = get_absolute_expression ();
12454 mips_cpreturn_register = -1;
12456 SKIP_WHITESPACE ();
12457 if (*input_line_pointer != ',')
12459 as_bad (_("missing argument separator ',' for .cpsetup"));
12463 ++input_line_pointer;
12464 SKIP_WHITESPACE ();
12465 expression (&ex_sym);
12467 if (mips_cpreturn_register == -1)
12469 ex_off.X_op = O_constant;
12470 ex_off.X_add_symbol = NULL;
12471 ex_off.X_op_symbol = NULL;
12472 ex_off.X_add_number = mips_cpreturn_offset;
12474 macro_build (NULL, &icnt, &ex_off, "sd", "t,o(b)", mips_gp_register,
12475 BFD_RELOC_LO16, SP);
12478 macro_build (NULL, &icnt, NULL, "daddu", "d,v,t", mips_cpreturn_register,
12479 mips_gp_register, 0);
12481 /* Ensure there's room for the next two instructions, so that `f'
12482 doesn't end up with an address in the wrong frag. */
12485 macro_build (NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
12486 BFD_RELOC_GPREL16);
12487 fix_new (frag_now, f - frag_now->fr_literal,
12488 8, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
12489 fix_new (frag_now, f - frag_now->fr_literal,
12490 4, NULL, 0, 0, BFD_RELOC_HI16_S);
12493 macro_build (NULL, &icnt, &ex_sym, "addiu", "t,r,j", mips_gp_register,
12494 mips_gp_register, BFD_RELOC_GPREL16);
12495 fix_new (frag_now, f - frag_now->fr_literal,
12496 8, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
12497 fix_new (frag_now, f - frag_now->fr_literal,
12498 4, NULL, 0, 0, BFD_RELOC_LO16);
12500 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
12501 mips_gp_register, reg1);
12503 demand_empty_rest_of_line ();
12507 s_cplocal (int ignore ATTRIBUTE_UNUSED)
12509 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12510 .cplocal is ignored. */
12511 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12517 mips_gp_register = tc_get_register (0);
12518 demand_empty_rest_of_line ();
12521 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12522 offset from $sp. The offset is remembered, and after making a PIC
12523 call $gp is restored from that location. */
12526 s_cprestore (int ignore ATTRIBUTE_UNUSED)
12531 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12532 .cprestore is ignored. */
12533 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12539 mips_cprestore_offset = get_absolute_expression ();
12540 mips_cprestore_valid = 1;
12542 ex.X_op = O_constant;
12543 ex.X_add_symbol = NULL;
12544 ex.X_op_symbol = NULL;
12545 ex.X_add_number = mips_cprestore_offset;
12547 macro_build_ldst_constoffset (NULL, &icnt, &ex, ADDRESS_STORE_INSN,
12548 mips_gp_register, SP, HAVE_64BIT_ADDRESSES);
12550 demand_empty_rest_of_line ();
12553 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12554 was given in the preceding .cpsetup, it results in:
12555 ld $gp, offset($sp)
12557 If a register $reg2 was given there, it results in:
12558 daddu $gp, $reg2, $0
12561 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
12566 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12567 We also need NewABI support. */
12568 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12574 if (mips_cpreturn_register == -1)
12576 ex.X_op = O_constant;
12577 ex.X_add_symbol = NULL;
12578 ex.X_op_symbol = NULL;
12579 ex.X_add_number = mips_cpreturn_offset;
12581 macro_build (NULL, &icnt, &ex, "ld", "t,o(b)", mips_gp_register,
12582 BFD_RELOC_LO16, SP);
12585 macro_build (NULL, &icnt, NULL, "daddu", "d,v,t", mips_gp_register,
12586 mips_cpreturn_register, 0);
12588 demand_empty_rest_of_line ();
12591 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12592 code. It sets the offset to use in gp_rel relocations. */
12595 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
12597 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12598 We also need NewABI support. */
12599 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12605 mips_gprel_offset = get_absolute_expression ();
12607 demand_empty_rest_of_line ();
12610 /* Handle the .gpword pseudo-op. This is used when generating PIC
12611 code. It generates a 32 bit GP relative reloc. */
12614 s_gpword (int ignore ATTRIBUTE_UNUSED)
12620 /* When not generating PIC code, this is treated as .word. */
12621 if (mips_pic != SVR4_PIC)
12627 label = insn_labels != NULL ? insn_labels->label : NULL;
12628 mips_emit_delays (TRUE);
12630 mips_align (2, 0, label);
12631 mips_clear_insn_labels ();
12635 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12637 as_bad (_("Unsupported use of .gpword"));
12638 ignore_rest_of_line ();
12642 md_number_to_chars (p, 0, 4);
12643 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12644 BFD_RELOC_GPREL32);
12646 demand_empty_rest_of_line ();
12650 s_gpdword (int ignore ATTRIBUTE_UNUSED)
12656 /* When not generating PIC code, this is treated as .dword. */
12657 if (mips_pic != SVR4_PIC)
12663 label = insn_labels != NULL ? insn_labels->label : NULL;
12664 mips_emit_delays (TRUE);
12666 mips_align (3, 0, label);
12667 mips_clear_insn_labels ();
12671 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12673 as_bad (_("Unsupported use of .gpdword"));
12674 ignore_rest_of_line ();
12678 md_number_to_chars (p, 0, 8);
12679 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12680 BFD_RELOC_GPREL32);
12682 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12683 ex.X_op = O_absent;
12684 ex.X_add_symbol = 0;
12685 ex.X_add_number = 0;
12686 fix_new_exp (frag_now, p - frag_now->fr_literal, 8, &ex, FALSE,
12689 demand_empty_rest_of_line ();
12692 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12693 tables in SVR4 PIC code. */
12696 s_cpadd (int ignore ATTRIBUTE_UNUSED)
12701 /* This is ignored when not generating SVR4 PIC code. */
12702 if (mips_pic != SVR4_PIC)
12708 /* Add $gp to the register named as an argument. */
12709 reg = tc_get_register (0);
12710 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
12711 reg, reg, mips_gp_register);
12713 demand_empty_rest_of_line ();
12716 /* Handle the .insn pseudo-op. This marks instruction labels in
12717 mips16 mode. This permits the linker to handle them specially,
12718 such as generating jalx instructions when needed. We also make
12719 them odd for the duration of the assembly, in order to generate the
12720 right sort of code. We will make them even in the adjust_symtab
12721 routine, while leaving them marked. This is convenient for the
12722 debugger and the disassembler. The linker knows to make them odd
12726 s_insn (int ignore ATTRIBUTE_UNUSED)
12728 mips16_mark_labels ();
12730 demand_empty_rest_of_line ();
12733 /* Handle a .stabn directive. We need these in order to mark a label
12734 as being a mips16 text label correctly. Sometimes the compiler
12735 will emit a label, followed by a .stabn, and then switch sections.
12736 If the label and .stabn are in mips16 mode, then the label is
12737 really a mips16 text label. */
12740 s_mips_stab (int type)
12743 mips16_mark_labels ();
12748 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12752 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
12759 name = input_line_pointer;
12760 c = get_symbol_end ();
12761 symbolP = symbol_find_or_make (name);
12762 S_SET_WEAK (symbolP);
12763 *input_line_pointer = c;
12765 SKIP_WHITESPACE ();
12767 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12769 if (S_IS_DEFINED (symbolP))
12771 as_bad ("ignoring attempt to redefine symbol %s",
12772 S_GET_NAME (symbolP));
12773 ignore_rest_of_line ();
12777 if (*input_line_pointer == ',')
12779 ++input_line_pointer;
12780 SKIP_WHITESPACE ();
12784 if (exp.X_op != O_symbol)
12786 as_bad ("bad .weakext directive");
12787 ignore_rest_of_line ();
12790 symbol_set_value_expression (symbolP, &exp);
12793 demand_empty_rest_of_line ();
12796 /* Parse a register string into a number. Called from the ECOFF code
12797 to parse .frame. The argument is non-zero if this is the frame
12798 register, so that we can record it in mips_frame_reg. */
12801 tc_get_register (int frame)
12805 SKIP_WHITESPACE ();
12806 if (*input_line_pointer++ != '$')
12808 as_warn (_("expected `$'"));
12811 else if (ISDIGIT (*input_line_pointer))
12813 reg = get_absolute_expression ();
12814 if (reg < 0 || reg >= 32)
12816 as_warn (_("Bad register number"));
12822 if (strncmp (input_line_pointer, "ra", 2) == 0)
12825 input_line_pointer += 2;
12827 else if (strncmp (input_line_pointer, "fp", 2) == 0)
12830 input_line_pointer += 2;
12832 else if (strncmp (input_line_pointer, "sp", 2) == 0)
12835 input_line_pointer += 2;
12837 else if (strncmp (input_line_pointer, "gp", 2) == 0)
12840 input_line_pointer += 2;
12842 else if (strncmp (input_line_pointer, "at", 2) == 0)
12845 input_line_pointer += 2;
12847 else if (strncmp (input_line_pointer, "kt0", 3) == 0)
12850 input_line_pointer += 3;
12852 else if (strncmp (input_line_pointer, "kt1", 3) == 0)
12855 input_line_pointer += 3;
12857 else if (strncmp (input_line_pointer, "zero", 4) == 0)
12860 input_line_pointer += 4;
12864 as_warn (_("Unrecognized register name"));
12866 while (ISALNUM(*input_line_pointer))
12867 input_line_pointer++;
12872 mips_frame_reg = reg != 0 ? reg : SP;
12873 mips_frame_reg_valid = 1;
12874 mips_cprestore_valid = 0;
12880 md_section_align (asection *seg, valueT addr)
12882 int align = bfd_get_section_alignment (stdoutput, seg);
12885 /* We don't need to align ELF sections to the full alignment.
12886 However, Irix 5 may prefer that we align them at least to a 16
12887 byte boundary. We don't bother to align the sections if we are
12888 targeted for an embedded system. */
12889 if (strcmp (TARGET_OS, "elf") == 0)
12895 return ((addr + (1 << align) - 1) & (-1 << align));
12898 /* Utility routine, called from above as well. If called while the
12899 input file is still being read, it's only an approximation. (For
12900 example, a symbol may later become defined which appeared to be
12901 undefined earlier.) */
12904 nopic_need_relax (symbolS *sym, int before_relaxing)
12909 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
12911 const char *symname;
12914 /* Find out whether this symbol can be referenced off the $gp
12915 register. It can be if it is smaller than the -G size or if
12916 it is in the .sdata or .sbss section. Certain symbols can
12917 not be referenced off the $gp, although it appears as though
12919 symname = S_GET_NAME (sym);
12920 if (symname != (const char *) NULL
12921 && (strcmp (symname, "eprol") == 0
12922 || strcmp (symname, "etext") == 0
12923 || strcmp (symname, "_gp") == 0
12924 || strcmp (symname, "edata") == 0
12925 || strcmp (symname, "_fbss") == 0
12926 || strcmp (symname, "_fdata") == 0
12927 || strcmp (symname, "_ftext") == 0
12928 || strcmp (symname, "end") == 0
12929 || strcmp (symname, "_gp_disp") == 0))
12931 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12933 #ifndef NO_ECOFF_DEBUGGING
12934 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12935 && (symbol_get_obj (sym)->ecoff_extern_size
12936 <= g_switch_value))
12938 /* We must defer this decision until after the whole
12939 file has been read, since there might be a .extern
12940 after the first use of this symbol. */
12941 || (before_relaxing
12942 #ifndef NO_ECOFF_DEBUGGING
12943 && symbol_get_obj (sym)->ecoff_extern_size == 0
12945 && S_GET_VALUE (sym) == 0)
12946 || (S_GET_VALUE (sym) != 0
12947 && S_GET_VALUE (sym) <= g_switch_value)))
12951 const char *segname;
12953 segname = segment_name (S_GET_SEGMENT (sym));
12954 assert (strcmp (segname, ".lit8") != 0
12955 && strcmp (segname, ".lit4") != 0);
12956 change = (strcmp (segname, ".sdata") != 0
12957 && strcmp (segname, ".sbss") != 0
12958 && strncmp (segname, ".sdata.", 7) != 0
12959 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12964 /* We are not optimizing for the $gp register. */
12969 /* Return true if the given symbol should be considered local for SVR4 PIC. */
12972 pic_need_relax (symbolS *sym, asection *segtype)
12975 bfd_boolean linkonce;
12977 /* Handle the case of a symbol equated to another symbol. */
12978 while (symbol_equated_reloc_p (sym))
12982 /* It's possible to get a loop here in a badly written
12984 n = symbol_get_value_expression (sym)->X_add_symbol;
12990 symsec = S_GET_SEGMENT (sym);
12992 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12994 if (symsec != segtype && ! S_IS_LOCAL (sym))
12996 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
13000 /* The GNU toolchain uses an extension for ELF: a section
13001 beginning with the magic string .gnu.linkonce is a linkonce
13003 if (strncmp (segment_name (symsec), ".gnu.linkonce",
13004 sizeof ".gnu.linkonce" - 1) == 0)
13008 /* This must duplicate the test in adjust_reloc_syms. */
13009 return (symsec != &bfd_und_section
13010 && symsec != &bfd_abs_section
13011 && ! bfd_is_com_section (symsec)
13014 /* A global or weak symbol is treated as external. */
13015 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
13016 || (! S_IS_WEAK (sym)
13017 && (! S_IS_EXTERNAL (sym)
13018 || mips_pic == EMBEDDED_PIC)))
13024 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
13025 extended opcode. SEC is the section the frag is in. */
13028 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
13031 register const struct mips16_immed_operand *op;
13033 int mintiny, maxtiny;
13037 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
13039 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
13042 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13043 op = mips16_immed_operands;
13044 while (op->type != type)
13047 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
13052 if (type == '<' || type == '>' || type == '[' || type == ']')
13055 maxtiny = 1 << op->nbits;
13060 maxtiny = (1 << op->nbits) - 1;
13065 mintiny = - (1 << (op->nbits - 1));
13066 maxtiny = (1 << (op->nbits - 1)) - 1;
13069 sym_frag = symbol_get_frag (fragp->fr_symbol);
13070 val = S_GET_VALUE (fragp->fr_symbol);
13071 symsec = S_GET_SEGMENT (fragp->fr_symbol);
13077 /* We won't have the section when we are called from
13078 mips_relax_frag. However, we will always have been called
13079 from md_estimate_size_before_relax first. If this is a
13080 branch to a different section, we mark it as such. If SEC is
13081 NULL, and the frag is not marked, then it must be a branch to
13082 the same section. */
13085 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
13090 /* Must have been called from md_estimate_size_before_relax. */
13093 fragp->fr_subtype =
13094 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13096 /* FIXME: We should support this, and let the linker
13097 catch branches and loads that are out of range. */
13098 as_bad_where (fragp->fr_file, fragp->fr_line,
13099 _("unsupported PC relative reference to different section"));
13103 if (fragp != sym_frag && sym_frag->fr_address == 0)
13104 /* Assume non-extended on the first relaxation pass.
13105 The address we have calculated will be bogus if this is
13106 a forward branch to another frag, as the forward frag
13107 will have fr_address == 0. */
13111 /* In this case, we know for sure that the symbol fragment is in
13112 the same section. If the relax_marker of the symbol fragment
13113 differs from the relax_marker of this fragment, we have not
13114 yet adjusted the symbol fragment fr_address. We want to add
13115 in STRETCH in order to get a better estimate of the address.
13116 This particularly matters because of the shift bits. */
13118 && sym_frag->relax_marker != fragp->relax_marker)
13122 /* Adjust stretch for any alignment frag. Note that if have
13123 been expanding the earlier code, the symbol may be
13124 defined in what appears to be an earlier frag. FIXME:
13125 This doesn't handle the fr_subtype field, which specifies
13126 a maximum number of bytes to skip when doing an
13128 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
13130 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
13133 stretch = - ((- stretch)
13134 & ~ ((1 << (int) f->fr_offset) - 1));
13136 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
13145 addr = fragp->fr_address + fragp->fr_fix;
13147 /* The base address rules are complicated. The base address of
13148 a branch is the following instruction. The base address of a
13149 PC relative load or add is the instruction itself, but if it
13150 is in a delay slot (in which case it can not be extended) use
13151 the address of the instruction whose delay slot it is in. */
13152 if (type == 'p' || type == 'q')
13156 /* If we are currently assuming that this frag should be
13157 extended, then, the current address is two bytes
13159 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13162 /* Ignore the low bit in the target, since it will be set
13163 for a text label. */
13164 if ((val & 1) != 0)
13167 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13169 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13172 val -= addr & ~ ((1 << op->shift) - 1);
13174 /* Branch offsets have an implicit 0 in the lowest bit. */
13175 if (type == 'p' || type == 'q')
13178 /* If any of the shifted bits are set, we must use an extended
13179 opcode. If the address depends on the size of this
13180 instruction, this can lead to a loop, so we arrange to always
13181 use an extended opcode. We only check this when we are in
13182 the main relaxation loop, when SEC is NULL. */
13183 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
13185 fragp->fr_subtype =
13186 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13190 /* If we are about to mark a frag as extended because the value
13191 is precisely maxtiny + 1, then there is a chance of an
13192 infinite loop as in the following code:
13197 In this case when the la is extended, foo is 0x3fc bytes
13198 away, so the la can be shrunk, but then foo is 0x400 away, so
13199 the la must be extended. To avoid this loop, we mark the
13200 frag as extended if it was small, and is about to become
13201 extended with a value of maxtiny + 1. */
13202 if (val == ((maxtiny + 1) << op->shift)
13203 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
13206 fragp->fr_subtype =
13207 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13211 else if (symsec != absolute_section && sec != NULL)
13212 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
13214 if ((val & ((1 << op->shift) - 1)) != 0
13215 || val < (mintiny << op->shift)
13216 || val > (maxtiny << op->shift))
13222 /* Compute the length of a branch sequence, and adjust the
13223 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
13224 worst-case length is computed, with UPDATE being used to indicate
13225 whether an unconditional (-1), branch-likely (+1) or regular (0)
13226 branch is to be computed. */
13228 relaxed_branch_length (fragS *fragp, asection *sec, int update)
13230 bfd_boolean toofar;
13234 && S_IS_DEFINED (fragp->fr_symbol)
13235 && sec == S_GET_SEGMENT (fragp->fr_symbol))
13240 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
13242 addr = fragp->fr_address + fragp->fr_fix + 4;
13246 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
13249 /* If the symbol is not defined or it's in a different segment,
13250 assume the user knows what's going on and emit a short
13256 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13258 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp->fr_subtype),
13259 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
13260 RELAX_BRANCH_LINK (fragp->fr_subtype),
13266 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
13269 if (mips_pic != NO_PIC)
13271 /* Additional space for PIC loading of target address. */
13273 if (mips_opts.isa == ISA_MIPS1)
13274 /* Additional space for $at-stabilizing nop. */
13278 /* If branch is conditional. */
13279 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
13286 /* Estimate the size of a frag before relaxing. Unless this is the
13287 mips16, we are not really relaxing here, and the final size is
13288 encoded in the subtype information. For the mips16, we have to
13289 decide whether we are using an extended opcode or not. */
13292 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
13296 if (RELAX_BRANCH_P (fragp->fr_subtype))
13299 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
13301 return fragp->fr_var;
13304 if (RELAX_MIPS16_P (fragp->fr_subtype))
13305 /* We don't want to modify the EXTENDED bit here; it might get us
13306 into infinite loops. We change it only in mips_relax_frag(). */
13307 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
13309 if (mips_pic == NO_PIC)
13310 change = nopic_need_relax (fragp->fr_symbol, 0);
13311 else if (mips_pic == SVR4_PIC)
13312 change = pic_need_relax (fragp->fr_symbol, segtype);
13318 /* Record the offset to the first reloc in the fr_opcode field.
13319 This lets md_convert_frag and tc_gen_reloc know that the code
13320 must be expanded. */
13321 fragp->fr_opcode = (fragp->fr_literal
13323 - RELAX_OLD (fragp->fr_subtype)
13324 + RELAX_RELOC1 (fragp->fr_subtype));
13325 /* FIXME: This really needs as_warn_where. */
13326 if (RELAX_WARN (fragp->fr_subtype))
13327 as_warn (_("AT used after \".set noat\" or macro used after "
13328 "\".set nomacro\""));
13330 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
13336 /* This is called to see whether a reloc against a defined symbol
13337 should be converted into a reloc against a section. Don't adjust
13338 MIPS16 jump relocations, so we don't have to worry about the format
13339 of the offset in the .o file. Don't adjust relocations against
13340 mips16 symbols, so that the linker can find them if it needs to set
13344 mips_fix_adjustable (fixS *fixp)
13346 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
13349 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
13350 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13353 if (fixp->fx_addsy == NULL)
13357 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
13358 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
13359 && fixp->fx_subsy == NULL)
13366 /* Translate internal representation of relocation info to BFD target
13370 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
13372 static arelent *retval[4];
13374 bfd_reloc_code_real_type code;
13376 memset (retval, 0, sizeof(retval));
13377 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
13378 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13379 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13380 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13382 if (mips_pic == EMBEDDED_PIC
13383 && SWITCH_TABLE (fixp))
13385 /* For a switch table entry we use a special reloc. The addend
13386 is actually the difference between the reloc address and the
13388 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
13389 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
13390 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
13391 fixp->fx_r_type = BFD_RELOC_GPREL32;
13393 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
13395 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
13396 reloc->addend = fixp->fx_addnumber;
13399 /* We use a special addend for an internal RELLO reloc. */
13400 if (symbol_section_p (fixp->fx_addsy))
13401 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
13403 reloc->addend = fixp->fx_addnumber + reloc->address;
13406 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
13408 assert (fixp->fx_next != NULL
13409 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
13411 /* The reloc is relative to the RELLO; adjust the addend
13413 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
13414 reloc->addend = fixp->fx_next->fx_addnumber;
13417 /* We use a special addend for an internal RELHI reloc. */
13418 if (symbol_section_p (fixp->fx_addsy))
13419 reloc->addend = (fixp->fx_next->fx_frag->fr_address
13420 + fixp->fx_next->fx_where
13421 - S_GET_VALUE (fixp->fx_subsy));
13423 reloc->addend = (fixp->fx_addnumber
13424 + fixp->fx_next->fx_frag->fr_address
13425 + fixp->fx_next->fx_where);
13428 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
13429 reloc->addend = fixp->fx_addnumber;
13432 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
13433 /* A gruesome hack which is a result of the gruesome gas reloc
13435 reloc->addend = reloc->address;
13437 reloc->addend = -reloc->address;
13440 /* If this is a variant frag, we may need to adjust the existing
13441 reloc and generate a new one. */
13442 if (fixp->fx_frag->fr_opcode != NULL
13443 && ((fixp->fx_r_type == BFD_RELOC_GPREL16
13445 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_DISP
13447 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
13448 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
13449 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
13450 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
13451 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
13452 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
13457 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
13459 /* If this is not the last reloc in this frag, then we have two
13460 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
13461 CALL_HI16/CALL_LO16, both of which are being replaced. Let
13462 the second one handle all of them. */
13463 if (fixp->fx_next != NULL
13464 && fixp->fx_frag == fixp->fx_next->fx_frag)
13466 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
13467 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
13468 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
13469 && (fixp->fx_next->fx_r_type
13470 == BFD_RELOC_MIPS_GOT_LO16))
13471 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
13472 && (fixp->fx_next->fx_r_type
13473 == BFD_RELOC_MIPS_CALL_LO16)));
13478 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
13479 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13480 reloc->addend += fixp->fx_frag->tc_frag_data.tc_fr_offset;
13481 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
13482 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13483 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13484 reloc2->address = (reloc->address
13485 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
13486 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
13487 reloc2->addend = fixp->fx_addnumber - S_GET_VALUE (fixp->fx_addsy)
13488 + fixp->fx_frag->tc_frag_data.tc_fr_offset;
13489 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
13490 assert (reloc2->howto != NULL);
13492 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
13496 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
13498 reloc3->address += 4;
13501 if (mips_pic == NO_PIC)
13503 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
13504 fixp->fx_r_type = BFD_RELOC_HI16_S;
13506 else if (mips_pic == SVR4_PIC)
13508 switch (fixp->fx_r_type)
13512 case BFD_RELOC_MIPS_GOT16:
13514 case BFD_RELOC_MIPS_GOT_LO16:
13515 case BFD_RELOC_MIPS_CALL_LO16:
13518 fixp->fx_r_type = BFD_RELOC_MIPS_GOT_PAGE;
13519 reloc2->howto = bfd_reloc_type_lookup
13520 (stdoutput, BFD_RELOC_MIPS_GOT_OFST);
13523 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
13525 case BFD_RELOC_MIPS_CALL16:
13526 case BFD_RELOC_MIPS_GOT_OFST:
13527 case BFD_RELOC_MIPS_GOT_DISP:
13530 /* It may seem nonsensical to relax GOT_DISP to
13531 GOT_DISP, but we're actually turning a GOT_DISP
13532 without offset into a GOT_DISP with an offset,
13533 getting rid of the separate addition, which we can
13534 do when the symbol is found to be local. */
13535 fixp->fx_r_type = BFD_RELOC_MIPS_GOT_DISP;
13539 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
13547 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13548 entry to be used in the relocation's section offset. */
13549 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13551 reloc->address = reloc->addend;
13555 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
13556 fixup_segment converted a non-PC relative reloc into a PC
13557 relative reloc. In such a case, we need to convert the reloc
13559 code = fixp->fx_r_type;
13560 if (fixp->fx_pcrel)
13565 code = BFD_RELOC_8_PCREL;
13568 code = BFD_RELOC_16_PCREL;
13571 code = BFD_RELOC_32_PCREL;
13574 code = BFD_RELOC_64_PCREL;
13576 case BFD_RELOC_8_PCREL:
13577 case BFD_RELOC_16_PCREL:
13578 case BFD_RELOC_32_PCREL:
13579 case BFD_RELOC_64_PCREL:
13580 case BFD_RELOC_16_PCREL_S2:
13581 case BFD_RELOC_PCREL_HI16_S:
13582 case BFD_RELOC_PCREL_LO16:
13585 as_bad_where (fixp->fx_file, fixp->fx_line,
13586 _("Cannot make %s relocation PC relative"),
13587 bfd_get_reloc_code_name (code));
13591 /* To support a PC relative reloc when generating embedded PIC code
13592 for ECOFF, we use a Cygnus extension. We check for that here to
13593 make sure that we don't let such a reloc escape normally. */
13594 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
13595 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
13596 && code == BFD_RELOC_16_PCREL_S2
13597 && mips_pic != EMBEDDED_PIC)
13598 reloc->howto = NULL;
13600 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
13602 if (reloc->howto == NULL)
13604 as_bad_where (fixp->fx_file, fixp->fx_line,
13605 _("Can not represent %s relocation in this object file format"),
13606 bfd_get_reloc_code_name (code));
13613 /* Relax a machine dependent frag. This returns the amount by which
13614 the current size of the frag should change. */
13617 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
13619 if (RELAX_BRANCH_P (fragp->fr_subtype))
13621 offsetT old_var = fragp->fr_var;
13623 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
13625 return fragp->fr_var - old_var;
13628 if (! RELAX_MIPS16_P (fragp->fr_subtype))
13631 if (mips16_extended_frag (fragp, NULL, stretch))
13633 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13635 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
13640 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13642 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
13649 /* Convert a machine dependent frag. */
13652 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
13657 if (RELAX_BRANCH_P (fragp->fr_subtype))
13660 unsigned long insn;
13664 buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
13666 if (target_big_endian)
13667 insn = bfd_getb32 (buf);
13669 insn = bfd_getl32 (buf);
13671 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13673 /* We generate a fixup instead of applying it right now
13674 because, if there are linker relaxations, we're going to
13675 need the relocations. */
13676 exp.X_op = O_symbol;
13677 exp.X_add_symbol = fragp->fr_symbol;
13678 exp.X_add_number = fragp->fr_offset;
13680 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13682 BFD_RELOC_16_PCREL_S2);
13683 fixp->fx_file = fragp->fr_file;
13684 fixp->fx_line = fragp->fr_line;
13686 md_number_to_chars (buf, insn, 4);
13693 as_warn_where (fragp->fr_file, fragp->fr_line,
13694 _("relaxed out-of-range branch into a jump"));
13696 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
13699 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13701 /* Reverse the branch. */
13702 switch ((insn >> 28) & 0xf)
13705 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13706 have the condition reversed by tweaking a single
13707 bit, and their opcodes all have 0x4???????. */
13708 assert ((insn & 0xf1000000) == 0x41000000);
13709 insn ^= 0x00010000;
13713 /* bltz 0x04000000 bgez 0x04010000
13714 bltzal 0x04100000 bgezal 0x04110000 */
13715 assert ((insn & 0xfc0e0000) == 0x04000000);
13716 insn ^= 0x00010000;
13720 /* beq 0x10000000 bne 0x14000000
13721 blez 0x18000000 bgtz 0x1c000000 */
13722 insn ^= 0x04000000;
13730 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13732 /* Clear the and-link bit. */
13733 assert ((insn & 0xfc1c0000) == 0x04100000);
13735 /* bltzal 0x04100000 bgezal 0x04110000
13736 bltzall 0x04120000 bgezall 0x04130000 */
13737 insn &= ~0x00100000;
13740 /* Branch over the branch (if the branch was likely) or the
13741 full jump (not likely case). Compute the offset from the
13742 current instruction to branch to. */
13743 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13747 /* How many bytes in instructions we've already emitted? */
13748 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13749 /* How many bytes in instructions from here to the end? */
13750 i = fragp->fr_var - i;
13752 /* Convert to instruction count. */
13754 /* Branch counts from the next instruction. */
13757 /* Branch over the jump. */
13758 md_number_to_chars (buf, insn, 4);
13762 md_number_to_chars (buf, 0, 4);
13765 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13767 /* beql $0, $0, 2f */
13769 /* Compute the PC offset from the current instruction to
13770 the end of the variable frag. */
13771 /* How many bytes in instructions we've already emitted? */
13772 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13773 /* How many bytes in instructions from here to the end? */
13774 i = fragp->fr_var - i;
13775 /* Convert to instruction count. */
13777 /* Don't decrement i, because we want to branch over the
13781 md_number_to_chars (buf, insn, 4);
13784 md_number_to_chars (buf, 0, 4);
13789 if (mips_pic == NO_PIC)
13792 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
13793 ? 0x0c000000 : 0x08000000);
13794 exp.X_op = O_symbol;
13795 exp.X_add_symbol = fragp->fr_symbol;
13796 exp.X_add_number = fragp->fr_offset;
13798 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13799 4, &exp, 0, BFD_RELOC_MIPS_JMP);
13800 fixp->fx_file = fragp->fr_file;
13801 fixp->fx_line = fragp->fr_line;
13803 md_number_to_chars (buf, insn, 4);
13808 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13809 insn = HAVE_64BIT_ADDRESSES ? 0xdf810000 : 0x8f810000;
13810 exp.X_op = O_symbol;
13811 exp.X_add_symbol = fragp->fr_symbol;
13812 exp.X_add_number = fragp->fr_offset;
13814 if (fragp->fr_offset)
13816 exp.X_add_symbol = make_expr_symbol (&exp);
13817 exp.X_add_number = 0;
13820 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13821 4, &exp, 0, BFD_RELOC_MIPS_GOT16);
13822 fixp->fx_file = fragp->fr_file;
13823 fixp->fx_line = fragp->fr_line;
13825 md_number_to_chars (buf, insn, 4);
13828 if (mips_opts.isa == ISA_MIPS1)
13831 md_number_to_chars (buf, 0, 4);
13835 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
13836 insn = HAVE_64BIT_ADDRESSES ? 0x64210000 : 0x24210000;
13838 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13839 4, &exp, 0, BFD_RELOC_LO16);
13840 fixp->fx_file = fragp->fr_file;
13841 fixp->fx_line = fragp->fr_line;
13843 md_number_to_chars (buf, insn, 4);
13847 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13852 md_number_to_chars (buf, insn, 4);
13857 assert (buf == (bfd_byte *)fragp->fr_literal
13858 + fragp->fr_fix + fragp->fr_var);
13860 fragp->fr_fix += fragp->fr_var;
13865 if (RELAX_MIPS16_P (fragp->fr_subtype))
13868 register const struct mips16_immed_operand *op;
13869 bfd_boolean small, ext;
13872 unsigned long insn;
13873 bfd_boolean use_extend;
13874 unsigned short extend;
13876 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13877 op = mips16_immed_operands;
13878 while (op->type != type)
13881 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13892 resolve_symbol_value (fragp->fr_symbol);
13893 val = S_GET_VALUE (fragp->fr_symbol);
13898 addr = fragp->fr_address + fragp->fr_fix;
13900 /* The rules for the base address of a PC relative reloc are
13901 complicated; see mips16_extended_frag. */
13902 if (type == 'p' || type == 'q')
13907 /* Ignore the low bit in the target, since it will be
13908 set for a text label. */
13909 if ((val & 1) != 0)
13912 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13914 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13917 addr &= ~ (addressT) ((1 << op->shift) - 1);
13920 /* Make sure the section winds up with the alignment we have
13923 record_alignment (asec, op->shift);
13927 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
13928 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
13929 as_warn_where (fragp->fr_file, fragp->fr_line,
13930 _("extended instruction in delay slot"));
13932 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
13934 if (target_big_endian)
13935 insn = bfd_getb16 (buf);
13937 insn = bfd_getl16 (buf);
13939 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
13940 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
13941 small, ext, &insn, &use_extend, &extend);
13945 md_number_to_chars (buf, 0xf000 | extend, 2);
13946 fragp->fr_fix += 2;
13950 md_number_to_chars (buf, insn, 2);
13951 fragp->fr_fix += 2;
13956 if (fragp->fr_opcode == NULL)
13959 old = RELAX_OLD (fragp->fr_subtype);
13960 new = RELAX_NEW (fragp->fr_subtype);
13961 fixptr = fragp->fr_literal + fragp->fr_fix;
13964 memmove (fixptr - old, fixptr, new);
13966 fragp->fr_fix += new - old;
13972 /* This function is called after the relocs have been generated.
13973 We've been storing mips16 text labels as odd. Here we convert them
13974 back to even for the convenience of the debugger. */
13977 mips_frob_file_after_relocs (void)
13980 unsigned int count, i;
13982 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
13985 syms = bfd_get_outsymbols (stdoutput);
13986 count = bfd_get_symcount (stdoutput);
13987 for (i = 0; i < count; i++, syms++)
13989 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
13990 && ((*syms)->value & 1) != 0)
13992 (*syms)->value &= ~1;
13993 /* If the symbol has an odd size, it was probably computed
13994 incorrectly, so adjust that as well. */
13995 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
13996 ++elf_symbol (*syms)->internal_elf_sym.st_size;
14003 /* This function is called whenever a label is defined. It is used
14004 when handling branch delays; if a branch has a label, we assume we
14005 can not move it. */
14008 mips_define_label (symbolS *sym)
14010 struct insn_label_list *l;
14012 if (free_insn_labels == NULL)
14013 l = (struct insn_label_list *) xmalloc (sizeof *l);
14016 l = free_insn_labels;
14017 free_insn_labels = l->next;
14021 l->next = insn_labels;
14025 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14027 /* Some special processing for a MIPS ELF file. */
14030 mips_elf_final_processing (void)
14032 /* Write out the register information. */
14033 if (mips_abi != N64_ABI)
14037 s.ri_gprmask = mips_gprmask;
14038 s.ri_cprmask[0] = mips_cprmask[0];
14039 s.ri_cprmask[1] = mips_cprmask[1];
14040 s.ri_cprmask[2] = mips_cprmask[2];
14041 s.ri_cprmask[3] = mips_cprmask[3];
14042 /* The gp_value field is set by the MIPS ELF backend. */
14044 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
14045 ((Elf32_External_RegInfo *)
14046 mips_regmask_frag));
14050 Elf64_Internal_RegInfo s;
14052 s.ri_gprmask = mips_gprmask;
14054 s.ri_cprmask[0] = mips_cprmask[0];
14055 s.ri_cprmask[1] = mips_cprmask[1];
14056 s.ri_cprmask[2] = mips_cprmask[2];
14057 s.ri_cprmask[3] = mips_cprmask[3];
14058 /* The gp_value field is set by the MIPS ELF backend. */
14060 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
14061 ((Elf64_External_RegInfo *)
14062 mips_regmask_frag));
14065 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
14066 sort of BFD interface for this. */
14067 if (mips_any_noreorder)
14068 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
14069 if (mips_pic != NO_PIC)
14071 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
14072 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
14075 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
14077 /* Set MIPS ELF flags for ASEs. */
14078 if (file_ase_mips16)
14079 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
14080 #if 0 /* XXX FIXME */
14081 if (file_ase_mips3d)
14082 elf_elfheader (stdoutput)->e_flags |= ???;
14085 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
14087 /* Set the MIPS ELF ABI flags. */
14088 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
14089 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
14090 else if (mips_abi == O64_ABI)
14091 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
14092 else if (mips_abi == EABI_ABI)
14094 if (!file_mips_gp32)
14095 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
14097 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
14099 else if (mips_abi == N32_ABI)
14100 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
14102 /* Nothing to do for N64_ABI. */
14104 if (mips_32bitmode)
14105 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
14108 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
14110 typedef struct proc {
14112 unsigned long reg_mask;
14113 unsigned long reg_offset;
14114 unsigned long fpreg_mask;
14115 unsigned long fpreg_offset;
14116 unsigned long frame_offset;
14117 unsigned long frame_reg;
14118 unsigned long pc_reg;
14121 static procS cur_proc;
14122 static procS *cur_proc_ptr;
14123 static int numprocs;
14125 /* Fill in an rs_align_code fragment. */
14128 mips_handle_align (fragS *fragp)
14130 if (fragp->fr_type != rs_align_code)
14133 if (mips_opts.mips16)
14135 static const unsigned char be_nop[] = { 0x65, 0x00 };
14136 static const unsigned char le_nop[] = { 0x00, 0x65 };
14141 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
14142 p = fragp->fr_literal + fragp->fr_fix;
14150 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
14154 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
14158 md_obj_begin (void)
14165 /* check for premature end, nesting errors, etc */
14167 as_warn (_("missing .end at end of assembly"));
14176 if (*input_line_pointer == '-')
14178 ++input_line_pointer;
14181 if (!ISDIGIT (*input_line_pointer))
14182 as_bad (_("expected simple number"));
14183 if (input_line_pointer[0] == '0')
14185 if (input_line_pointer[1] == 'x')
14187 input_line_pointer += 2;
14188 while (ISXDIGIT (*input_line_pointer))
14191 val |= hex_value (*input_line_pointer++);
14193 return negative ? -val : val;
14197 ++input_line_pointer;
14198 while (ISDIGIT (*input_line_pointer))
14201 val |= *input_line_pointer++ - '0';
14203 return negative ? -val : val;
14206 if (!ISDIGIT (*input_line_pointer))
14208 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
14209 *input_line_pointer, *input_line_pointer);
14210 as_warn (_("invalid number"));
14213 while (ISDIGIT (*input_line_pointer))
14216 val += *input_line_pointer++ - '0';
14218 return negative ? -val : val;
14221 /* The .file directive; just like the usual .file directive, but there
14222 is an initial number which is the ECOFF file index. In the non-ECOFF
14223 case .file implies DWARF-2. */
14226 s_mips_file (int x ATTRIBUTE_UNUSED)
14228 static int first_file_directive = 0;
14230 if (ECOFF_DEBUGGING)
14239 filename = dwarf2_directive_file (0);
14241 /* Versions of GCC up to 3.1 start files with a ".file"
14242 directive even for stabs output. Make sure that this
14243 ".file" is handled. Note that you need a version of GCC
14244 after 3.1 in order to support DWARF-2 on MIPS. */
14245 if (filename != NULL && ! first_file_directive)
14247 (void) new_logical_line (filename, -1);
14248 s_app_file_string (filename);
14250 first_file_directive = 1;
14254 /* The .loc directive, implying DWARF-2. */
14257 s_mips_loc (int x ATTRIBUTE_UNUSED)
14259 if (!ECOFF_DEBUGGING)
14260 dwarf2_directive_loc (0);
14263 /* The .end directive. */
14266 s_mips_end (int x ATTRIBUTE_UNUSED)
14270 /* Following functions need their own .frame and .cprestore directives. */
14271 mips_frame_reg_valid = 0;
14272 mips_cprestore_valid = 0;
14274 if (!is_end_of_line[(unsigned char) *input_line_pointer])
14277 demand_empty_rest_of_line ();
14282 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14283 as_warn (_(".end not in text section"));
14287 as_warn (_(".end directive without a preceding .ent directive."));
14288 demand_empty_rest_of_line ();
14294 assert (S_GET_NAME (p));
14295 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
14296 as_warn (_(".end symbol does not match .ent symbol."));
14298 if (debug_type == DEBUG_STABS)
14299 stabs_generate_asm_endfunc (S_GET_NAME (p),
14303 as_warn (_(".end directive missing or unknown symbol"));
14306 /* Generate a .pdr section. */
14307 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING
14310 segT saved_seg = now_seg;
14311 subsegT saved_subseg = now_subseg;
14316 dot = frag_now_fix ();
14318 #ifdef md_flush_pending_output
14319 md_flush_pending_output ();
14323 subseg_set (pdr_seg, 0);
14325 /* Write the symbol. */
14326 exp.X_op = O_symbol;
14327 exp.X_add_symbol = p;
14328 exp.X_add_number = 0;
14329 emit_expr (&exp, 4);
14331 fragp = frag_more (7 * 4);
14333 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
14334 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
14335 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
14336 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
14337 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
14338 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
14339 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
14341 subseg_set (saved_seg, saved_subseg);
14343 #endif /* OBJ_ELF */
14345 cur_proc_ptr = NULL;
14348 /* The .aent and .ent directives. */
14351 s_mips_ent (int aent)
14355 symbolP = get_symbol ();
14356 if (*input_line_pointer == ',')
14357 ++input_line_pointer;
14358 SKIP_WHITESPACE ();
14359 if (ISDIGIT (*input_line_pointer)
14360 || *input_line_pointer == '-')
14363 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14364 as_warn (_(".ent or .aent not in text section."));
14366 if (!aent && cur_proc_ptr)
14367 as_warn (_("missing .end"));
14371 /* This function needs its own .frame and .cprestore directives. */
14372 mips_frame_reg_valid = 0;
14373 mips_cprestore_valid = 0;
14375 cur_proc_ptr = &cur_proc;
14376 memset (cur_proc_ptr, '\0', sizeof (procS));
14378 cur_proc_ptr->isym = symbolP;
14380 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
14384 if (debug_type == DEBUG_STABS)
14385 stabs_generate_asm_func (S_GET_NAME (symbolP),
14386 S_GET_NAME (symbolP));
14389 demand_empty_rest_of_line ();
14392 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
14393 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
14394 s_mips_frame is used so that we can set the PDR information correctly.
14395 We can't use the ecoff routines because they make reference to the ecoff
14396 symbol table (in the mdebug section). */
14399 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
14402 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14406 if (cur_proc_ptr == (procS *) NULL)
14408 as_warn (_(".frame outside of .ent"));
14409 demand_empty_rest_of_line ();
14413 cur_proc_ptr->frame_reg = tc_get_register (1);
14415 SKIP_WHITESPACE ();
14416 if (*input_line_pointer++ != ','
14417 || get_absolute_expression_and_terminator (&val) != ',')
14419 as_warn (_("Bad .frame directive"));
14420 --input_line_pointer;
14421 demand_empty_rest_of_line ();
14425 cur_proc_ptr->frame_offset = val;
14426 cur_proc_ptr->pc_reg = tc_get_register (0);
14428 demand_empty_rest_of_line ();
14431 #endif /* OBJ_ELF */
14435 /* The .fmask and .mask directives. If the mdebug section is present
14436 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14437 embedded targets, s_mips_mask is used so that we can set the PDR
14438 information correctly. We can't use the ecoff routines because they
14439 make reference to the ecoff symbol table (in the mdebug section). */
14442 s_mips_mask (int reg_type)
14445 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14449 if (cur_proc_ptr == (procS *) NULL)
14451 as_warn (_(".mask/.fmask outside of .ent"));
14452 demand_empty_rest_of_line ();
14456 if (get_absolute_expression_and_terminator (&mask) != ',')
14458 as_warn (_("Bad .mask/.fmask directive"));
14459 --input_line_pointer;
14460 demand_empty_rest_of_line ();
14464 off = get_absolute_expression ();
14466 if (reg_type == 'F')
14468 cur_proc_ptr->fpreg_mask = mask;
14469 cur_proc_ptr->fpreg_offset = off;
14473 cur_proc_ptr->reg_mask = mask;
14474 cur_proc_ptr->reg_offset = off;
14477 demand_empty_rest_of_line ();
14480 #endif /* OBJ_ELF */
14481 s_ignore (reg_type);
14484 /* The .loc directive. */
14494 assert (now_seg == text_section);
14496 lineno = get_number ();
14497 addroff = frag_now_fix ();
14499 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
14500 S_SET_TYPE (symbolP, N_SLINE);
14501 S_SET_OTHER (symbolP, 0);
14502 S_SET_DESC (symbolP, lineno);
14503 symbolP->sy_segment = now_seg;
14507 /* A table describing all the processors gas knows about. Names are
14508 matched in the order listed.
14510 To ease comparison, please keep this table in the same order as
14511 gcc's mips_cpu_info_table[]. */
14512 static const struct mips_cpu_info mips_cpu_info_table[] =
14514 /* Entries for generic ISAs */
14515 { "mips1", 1, ISA_MIPS1, CPU_R3000 },
14516 { "mips2", 1, ISA_MIPS2, CPU_R6000 },
14517 { "mips3", 1, ISA_MIPS3, CPU_R4000 },
14518 { "mips4", 1, ISA_MIPS4, CPU_R8000 },
14519 { "mips5", 1, ISA_MIPS5, CPU_MIPS5 },
14520 { "mips32", 1, ISA_MIPS32, CPU_MIPS32 },
14521 { "mips32r2", 1, ISA_MIPS32R2, CPU_MIPS32R2 },
14522 { "mips64", 1, ISA_MIPS64, CPU_MIPS64 },
14523 { "mips64r2", 1, ISA_MIPS64R2, CPU_MIPS64R2 },
14526 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
14527 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
14528 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
14531 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
14534 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
14535 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
14536 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
14537 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
14538 { "vr4120", 0, ISA_MIPS3, CPU_VR4120 },
14539 { "vr4130", 0, ISA_MIPS3, CPU_VR4120 },
14540 { "vr4181", 0, ISA_MIPS3, CPU_R4111 },
14541 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
14542 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
14543 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
14544 { "orion", 0, ISA_MIPS3, CPU_R4600 },
14545 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
14548 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
14549 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
14550 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
14551 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
14552 { "vr5400", 0, ISA_MIPS4, CPU_VR5400 },
14553 { "vr5500", 0, ISA_MIPS4, CPU_VR5500 },
14554 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
14555 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
14556 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
14557 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
14558 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
14559 { "rm7000", 0, ISA_MIPS4, CPU_RM7000 },
14560 { "rm9000", 0, ISA_MIPS4, CPU_RM7000 },
14563 { "4kc", 0, ISA_MIPS32, CPU_MIPS32 },
14564 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
14565 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
14568 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
14569 { "20kc", 0, ISA_MIPS64, CPU_MIPS64 },
14571 /* Broadcom SB-1 CPU core */
14572 { "sb1", 0, ISA_MIPS64, CPU_SB1 },
14579 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14580 with a final "000" replaced by "k". Ignore case.
14582 Note: this function is shared between GCC and GAS. */
14585 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
14587 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
14588 given++, canonical++;
14590 return ((*given == 0 && *canonical == 0)
14591 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
14595 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14596 CPU name. We've traditionally allowed a lot of variation here.
14598 Note: this function is shared between GCC and GAS. */
14601 mips_matching_cpu_name_p (const char *canonical, const char *given)
14603 /* First see if the name matches exactly, or with a final "000"
14604 turned into "k". */
14605 if (mips_strict_matching_cpu_name_p (canonical, given))
14608 /* If not, try comparing based on numerical designation alone.
14609 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14610 if (TOLOWER (*given) == 'r')
14612 if (!ISDIGIT (*given))
14615 /* Skip over some well-known prefixes in the canonical name,
14616 hoping to find a number there too. */
14617 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
14619 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
14621 else if (TOLOWER (canonical[0]) == 'r')
14624 return mips_strict_matching_cpu_name_p (canonical, given);
14628 /* Parse an option that takes the name of a processor as its argument.
14629 OPTION is the name of the option and CPU_STRING is the argument.
14630 Return the corresponding processor enumeration if the CPU_STRING is
14631 recognized, otherwise report an error and return null.
14633 A similar function exists in GCC. */
14635 static const struct mips_cpu_info *
14636 mips_parse_cpu (const char *option, const char *cpu_string)
14638 const struct mips_cpu_info *p;
14640 /* 'from-abi' selects the most compatible architecture for the given
14641 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14642 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14643 version. Look first at the -mgp options, if given, otherwise base
14644 the choice on MIPS_DEFAULT_64BIT.
14646 Treat NO_ABI like the EABIs. One reason to do this is that the
14647 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14648 architecture. This code picks MIPS I for 'mips' and MIPS III for
14649 'mips64', just as we did in the days before 'from-abi'. */
14650 if (strcasecmp (cpu_string, "from-abi") == 0)
14652 if (ABI_NEEDS_32BIT_REGS (mips_abi))
14653 return mips_cpu_info_from_isa (ISA_MIPS1);
14655 if (ABI_NEEDS_64BIT_REGS (mips_abi))
14656 return mips_cpu_info_from_isa (ISA_MIPS3);
14658 if (file_mips_gp32 >= 0)
14659 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
14661 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14666 /* 'default' has traditionally been a no-op. Probably not very useful. */
14667 if (strcasecmp (cpu_string, "default") == 0)
14670 for (p = mips_cpu_info_table; p->name != 0; p++)
14671 if (mips_matching_cpu_name_p (p->name, cpu_string))
14674 as_bad ("Bad value (%s) for %s", cpu_string, option);
14678 /* Return the canonical processor information for ISA (a member of the
14679 ISA_MIPS* enumeration). */
14681 static const struct mips_cpu_info *
14682 mips_cpu_info_from_isa (int isa)
14686 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14687 if (mips_cpu_info_table[i].is_isa
14688 && isa == mips_cpu_info_table[i].isa)
14689 return (&mips_cpu_info_table[i]);
14694 static const struct mips_cpu_info *
14695 mips_cpu_info_from_arch (int arch)
14699 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14700 if (arch == mips_cpu_info_table[i].cpu)
14701 return (&mips_cpu_info_table[i]);
14707 show (FILE *stream, const char *string, int *col_p, int *first_p)
14711 fprintf (stream, "%24s", "");
14716 fprintf (stream, ", ");
14720 if (*col_p + strlen (string) > 72)
14722 fprintf (stream, "\n%24s", "");
14726 fprintf (stream, "%s", string);
14727 *col_p += strlen (string);
14733 md_show_usage (FILE *stream)
14738 fprintf (stream, _("\
14740 -membedded-pic generate embedded position independent code\n\
14741 -EB generate big endian output\n\
14742 -EL generate little endian output\n\
14743 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14744 -G NUM allow referencing objects up to NUM bytes\n\
14745 implicitly with the gp register [default 8]\n"));
14746 fprintf (stream, _("\
14747 -mips1 generate MIPS ISA I instructions\n\
14748 -mips2 generate MIPS ISA II instructions\n\
14749 -mips3 generate MIPS ISA III instructions\n\
14750 -mips4 generate MIPS ISA IV instructions\n\
14751 -mips5 generate MIPS ISA V instructions\n\
14752 -mips32 generate MIPS32 ISA instructions\n\
14753 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
14754 -mips64 generate MIPS64 ISA instructions\n\
14755 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
14756 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14760 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14761 show (stream, mips_cpu_info_table[i].name, &column, &first);
14762 show (stream, "from-abi", &column, &first);
14763 fputc ('\n', stream);
14765 fprintf (stream, _("\
14766 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14767 -no-mCPU don't generate code specific to CPU.\n\
14768 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14772 show (stream, "3900", &column, &first);
14773 show (stream, "4010", &column, &first);
14774 show (stream, "4100", &column, &first);
14775 show (stream, "4650", &column, &first);
14776 fputc ('\n', stream);
14778 fprintf (stream, _("\
14779 -mips16 generate mips16 instructions\n\
14780 -no-mips16 do not generate mips16 instructions\n"));
14781 fprintf (stream, _("\
14782 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14783 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14784 -O0 remove unneeded NOPs, do not swap branches\n\
14785 -O remove unneeded NOPs and swap branches\n\
14786 -n warn about NOPs generated from macros\n\
14787 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14788 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14789 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14791 fprintf (stream, _("\
14792 -KPIC, -call_shared generate SVR4 position independent code\n\
14793 -non_shared do not generate position independent code\n\
14794 -xgot assume a 32 bit GOT\n\
14795 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
14796 -mabi=ABI create ABI conformant object file for:\n"));
14800 show (stream, "32", &column, &first);
14801 show (stream, "o64", &column, &first);
14802 show (stream, "n32", &column, &first);
14803 show (stream, "64", &column, &first);
14804 show (stream, "eabi", &column, &first);
14806 fputc ('\n', stream);
14808 fprintf (stream, _("\
14809 -32 create o32 ABI object file (default)\n\
14810 -n32 create n32 ABI object file\n\
14811 -64 create 64 ABI object file\n"));
14816 mips_dwarf2_format (void)
14818 if (mips_abi == N64_ABI)
14821 return dwarf2_format_64bit_irix;
14823 return dwarf2_format_64bit;
14827 return dwarf2_format_32bit;