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 \
271 /* Return true if ISA supports 64-bit right rotate (dror et al.)
273 #define ISA_HAS_DROR(ISA) ( \
277 /* Return true if ISA supports 32-bit right rotate (ror et al.)
279 #define ISA_HAS_ROR(ISA) ( \
280 (ISA) == ISA_MIPS32R2 \
283 #define HAVE_32BIT_GPRS \
284 (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
286 #define HAVE_32BIT_FPRS \
287 (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
289 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
290 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
292 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
294 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
296 /* We can only have 64bit addresses if the object file format
298 #define HAVE_32BIT_ADDRESSES \
300 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
301 || ! HAVE_64BIT_OBJECTS) \
302 && mips_pic != EMBEDDED_PIC))
304 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
305 #define HAVE_64BIT_ADDRESS_CONSTANTS (HAVE_64BIT_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 /* Similiar 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 offset_expr
;
1032 /* Relocs associated with imm_expr and offset_expr. */
1034 static bfd_reloc_code_real_type imm_reloc
[3]
1035 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1036 static bfd_reloc_code_real_type offset_reloc
[3]
1037 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1039 /* These are set by mips16_ip if an explicit extension is used. */
1041 static bfd_boolean mips16_small
, mips16_ext
;
1044 /* The pdr segment for per procedure frame/regmask info. Not used for
1047 static segT pdr_seg
;
1050 /* The default target format to use. */
1053 mips_target_format (void)
1055 switch (OUTPUT_FLAVOR
)
1057 case bfd_target_aout_flavour
:
1058 return target_big_endian
? "a.out-mips-big" : "a.out-mips-little";
1059 case bfd_target_ecoff_flavour
:
1060 return target_big_endian
? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT
;
1061 case bfd_target_coff_flavour
:
1063 case bfd_target_elf_flavour
:
1065 /* This is traditional mips. */
1066 return (target_big_endian
1067 ? (HAVE_64BIT_OBJECTS
1068 ? "elf64-tradbigmips"
1070 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1071 : (HAVE_64BIT_OBJECTS
1072 ? "elf64-tradlittlemips"
1074 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1076 return (target_big_endian
1077 ? (HAVE_64BIT_OBJECTS
1080 ? "elf32-nbigmips" : "elf32-bigmips"))
1081 : (HAVE_64BIT_OBJECTS
1082 ? "elf64-littlemips"
1084 ? "elf32-nlittlemips" : "elf32-littlemips")));
1092 /* This function is called once, at assembler startup time. It should
1093 set up all the tables, etc. that the MD part of the assembler will need. */
1098 register const char *retval
= NULL
;
1102 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_mips
, file_mips_arch
))
1103 as_warn (_("Could not set architecture and machine"));
1105 op_hash
= hash_new ();
1107 for (i
= 0; i
< NUMOPCODES
;)
1109 const char *name
= mips_opcodes
[i
].name
;
1111 retval
= hash_insert (op_hash
, name
, (void *) &mips_opcodes
[i
]);
1114 fprintf (stderr
, _("internal error: can't hash `%s': %s\n"),
1115 mips_opcodes
[i
].name
, retval
);
1116 /* Probably a memory allocation problem? Give up now. */
1117 as_fatal (_("Broken assembler. No assembly attempted."));
1121 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
)
1123 if (!validate_mips_insn (&mips_opcodes
[i
]))
1128 while ((i
< NUMOPCODES
) && !strcmp (mips_opcodes
[i
].name
, name
));
1131 mips16_op_hash
= hash_new ();
1134 while (i
< bfd_mips16_num_opcodes
)
1136 const char *name
= mips16_opcodes
[i
].name
;
1138 retval
= hash_insert (mips16_op_hash
, name
, (void *) &mips16_opcodes
[i
]);
1140 as_fatal (_("internal: can't hash `%s': %s"),
1141 mips16_opcodes
[i
].name
, retval
);
1144 if (mips16_opcodes
[i
].pinfo
!= INSN_MACRO
1145 && ((mips16_opcodes
[i
].match
& mips16_opcodes
[i
].mask
)
1146 != mips16_opcodes
[i
].match
))
1148 fprintf (stderr
, _("internal error: bad mips16 opcode: %s %s\n"),
1149 mips16_opcodes
[i
].name
, mips16_opcodes
[i
].args
);
1154 while (i
< bfd_mips16_num_opcodes
1155 && strcmp (mips16_opcodes
[i
].name
, name
) == 0);
1159 as_fatal (_("Broken assembler. No assembly attempted."));
1161 /* We add all the general register names to the symbol table. This
1162 helps us detect invalid uses of them. */
1163 for (i
= 0; i
< 32; i
++)
1167 sprintf (buf
, "$%d", i
);
1168 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
1169 &zero_address_frag
));
1171 symbol_table_insert (symbol_new ("$ra", reg_section
, RA
,
1172 &zero_address_frag
));
1173 symbol_table_insert (symbol_new ("$fp", reg_section
, FP
,
1174 &zero_address_frag
));
1175 symbol_table_insert (symbol_new ("$sp", reg_section
, SP
,
1176 &zero_address_frag
));
1177 symbol_table_insert (symbol_new ("$gp", reg_section
, GP
,
1178 &zero_address_frag
));
1179 symbol_table_insert (symbol_new ("$at", reg_section
, AT
,
1180 &zero_address_frag
));
1181 symbol_table_insert (symbol_new ("$kt0", reg_section
, KT0
,
1182 &zero_address_frag
));
1183 symbol_table_insert (symbol_new ("$kt1", reg_section
, KT1
,
1184 &zero_address_frag
));
1185 symbol_table_insert (symbol_new ("$zero", reg_section
, ZERO
,
1186 &zero_address_frag
));
1187 symbol_table_insert (symbol_new ("$pc", reg_section
, -1,
1188 &zero_address_frag
));
1190 /* If we don't add these register names to the symbol table, they
1191 may end up being added as regular symbols by operand(), and then
1192 make it to the object file as undefined in case they're not
1193 regarded as local symbols. They're local in o32, since `$' is a
1194 local symbol prefix, but not in n32 or n64. */
1195 for (i
= 0; i
< 8; i
++)
1199 sprintf (buf
, "$fcc%i", i
);
1200 symbol_table_insert (symbol_new (buf
, reg_section
, -1,
1201 &zero_address_frag
));
1204 mips_no_prev_insn (FALSE
);
1207 mips_cprmask
[0] = 0;
1208 mips_cprmask
[1] = 0;
1209 mips_cprmask
[2] = 0;
1210 mips_cprmask
[3] = 0;
1212 /* set the default alignment for the text section (2**2) */
1213 record_alignment (text_section
, 2);
1215 if (USE_GLOBAL_POINTER_OPT
)
1216 bfd_set_gp_size (stdoutput
, g_switch_value
);
1218 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1220 /* On a native system, sections must be aligned to 16 byte
1221 boundaries. When configured for an embedded ELF target, we
1223 if (strcmp (TARGET_OS
, "elf") != 0)
1225 (void) bfd_set_section_alignment (stdoutput
, text_section
, 4);
1226 (void) bfd_set_section_alignment (stdoutput
, data_section
, 4);
1227 (void) bfd_set_section_alignment (stdoutput
, bss_section
, 4);
1230 /* Create a .reginfo section for register masks and a .mdebug
1231 section for debugging information. */
1239 subseg
= now_subseg
;
1241 /* The ABI says this section should be loaded so that the
1242 running program can access it. However, we don't load it
1243 if we are configured for an embedded target */
1244 flags
= SEC_READONLY
| SEC_DATA
;
1245 if (strcmp (TARGET_OS
, "elf") != 0)
1246 flags
|= SEC_ALLOC
| SEC_LOAD
;
1248 if (mips_abi
!= N64_ABI
)
1250 sec
= subseg_new (".reginfo", (subsegT
) 0);
1252 bfd_set_section_flags (stdoutput
, sec
, flags
);
1253 bfd_set_section_alignment (stdoutput
, sec
, HAVE_NEWABI
? 3 : 2);
1256 mips_regmask_frag
= frag_more (sizeof (Elf32_External_RegInfo
));
1261 /* The 64-bit ABI uses a .MIPS.options section rather than
1262 .reginfo section. */
1263 sec
= subseg_new (".MIPS.options", (subsegT
) 0);
1264 bfd_set_section_flags (stdoutput
, sec
, flags
);
1265 bfd_set_section_alignment (stdoutput
, sec
, 3);
1268 /* Set up the option header. */
1270 Elf_Internal_Options opthdr
;
1273 opthdr
.kind
= ODK_REGINFO
;
1274 opthdr
.size
= (sizeof (Elf_External_Options
)
1275 + sizeof (Elf64_External_RegInfo
));
1278 f
= frag_more (sizeof (Elf_External_Options
));
1279 bfd_mips_elf_swap_options_out (stdoutput
, &opthdr
,
1280 (Elf_External_Options
*) f
);
1282 mips_regmask_frag
= frag_more (sizeof (Elf64_External_RegInfo
));
1287 if (ECOFF_DEBUGGING
)
1289 sec
= subseg_new (".mdebug", (subsegT
) 0);
1290 (void) bfd_set_section_flags (stdoutput
, sec
,
1291 SEC_HAS_CONTENTS
| SEC_READONLY
);
1292 (void) bfd_set_section_alignment (stdoutput
, sec
, 2);
1295 else if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& mips_flag_pdr
)
1297 pdr_seg
= subseg_new (".pdr", (subsegT
) 0);
1298 (void) bfd_set_section_flags (stdoutput
, pdr_seg
,
1299 SEC_READONLY
| SEC_RELOC
1301 (void) bfd_set_section_alignment (stdoutput
, pdr_seg
, 2);
1305 subseg_set (seg
, subseg
);
1309 if (! ECOFF_DEBUGGING
)
1316 if (! ECOFF_DEBUGGING
)
1321 md_assemble (char *str
)
1323 struct mips_cl_insn insn
;
1324 bfd_reloc_code_real_type unused_reloc
[3]
1325 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1327 imm_expr
.X_op
= O_absent
;
1328 offset_expr
.X_op
= O_absent
;
1329 imm_reloc
[0] = BFD_RELOC_UNUSED
;
1330 imm_reloc
[1] = BFD_RELOC_UNUSED
;
1331 imm_reloc
[2] = BFD_RELOC_UNUSED
;
1332 offset_reloc
[0] = BFD_RELOC_UNUSED
;
1333 offset_reloc
[1] = BFD_RELOC_UNUSED
;
1334 offset_reloc
[2] = BFD_RELOC_UNUSED
;
1336 if (mips_opts
.mips16
)
1337 mips16_ip (str
, &insn
);
1340 mips_ip (str
, &insn
);
1341 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1342 str
, insn
.insn_opcode
));
1347 as_bad ("%s `%s'", insn_error
, str
);
1351 if (insn
.insn_mo
->pinfo
== INSN_MACRO
)
1353 if (mips_opts
.mips16
)
1354 mips16_macro (&insn
);
1360 if (imm_expr
.X_op
!= O_absent
)
1361 append_insn (NULL
, &insn
, &imm_expr
, imm_reloc
);
1362 else if (offset_expr
.X_op
!= O_absent
)
1363 append_insn (NULL
, &insn
, &offset_expr
, offset_reloc
);
1365 append_insn (NULL
, &insn
, NULL
, unused_reloc
);
1369 /* Return true if the given relocation might need a matching %lo().
1370 Note that R_MIPS_GOT16 relocations only need a matching %lo() when
1371 applied to local symbols. */
1373 static inline bfd_boolean
1374 reloc_needs_lo_p (bfd_reloc_code_real_type reloc
)
1376 return (reloc
== BFD_RELOC_HI16_S
1377 || reloc
== BFD_RELOC_MIPS_GOT16
);
1380 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
1383 static inline bfd_boolean
1384 fixup_has_matching_lo_p (fixS
*fixp
)
1386 return (fixp
->fx_next
!= NULL
1387 && fixp
->fx_next
->fx_r_type
== BFD_RELOC_LO16
1388 && fixp
->fx_addsy
== fixp
->fx_next
->fx_addsy
1389 && fixp
->fx_offset
== fixp
->fx_next
->fx_offset
);
1392 /* See whether instruction IP reads register REG. CLASS is the type
1396 insn_uses_reg (struct mips_cl_insn
*ip
, unsigned int reg
,
1397 enum mips_regclass
class)
1399 if (class == MIPS16_REG
)
1401 assert (mips_opts
.mips16
);
1402 reg
= mips16_to_32_reg_map
[reg
];
1403 class = MIPS_GR_REG
;
1406 /* Don't report on general register ZERO, since it never changes. */
1407 if (class == MIPS_GR_REG
&& reg
== ZERO
)
1410 if (class == MIPS_FP_REG
)
1412 assert (! mips_opts
.mips16
);
1413 /* If we are called with either $f0 or $f1, we must check $f0.
1414 This is not optimal, because it will introduce an unnecessary
1415 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1416 need to distinguish reading both $f0 and $f1 or just one of
1417 them. Note that we don't have to check the other way,
1418 because there is no instruction that sets both $f0 and $f1
1419 and requires a delay. */
1420 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_S
)
1421 && ((((ip
->insn_opcode
>> OP_SH_FS
) & OP_MASK_FS
) &~(unsigned)1)
1422 == (reg
&~ (unsigned) 1)))
1424 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_T
)
1425 && ((((ip
->insn_opcode
>> OP_SH_FT
) & OP_MASK_FT
) &~(unsigned)1)
1426 == (reg
&~ (unsigned) 1)))
1429 else if (! mips_opts
.mips16
)
1431 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_S
)
1432 && ((ip
->insn_opcode
>> OP_SH_RS
) & OP_MASK_RS
) == reg
)
1434 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_T
)
1435 && ((ip
->insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
) == reg
)
1440 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_X
)
1441 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_RX
)
1442 & MIPS16OP_MASK_RX
)]
1445 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Y
)
1446 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_RY
)
1447 & MIPS16OP_MASK_RY
)]
1450 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Z
)
1451 && (mips16_to_32_reg_map
[((ip
->insn_opcode
>> MIPS16OP_SH_MOVE32Z
)
1452 & MIPS16OP_MASK_MOVE32Z
)]
1455 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_T
) && reg
== TREG
)
1457 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_SP
) && reg
== SP
)
1459 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_31
) && reg
== RA
)
1461 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_GPR_X
)
1462 && ((ip
->insn_opcode
>> MIPS16OP_SH_REGR32
)
1463 & MIPS16OP_MASK_REGR32
) == reg
)
1470 /* This function returns true if modifying a register requires a
1474 reg_needs_delay (unsigned int reg
)
1476 unsigned long prev_pinfo
;
1478 prev_pinfo
= prev_insn
.insn_mo
->pinfo
;
1479 if (! mips_opts
.noreorder
1480 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1481 && ((prev_pinfo
& INSN_LOAD_COPROC_DELAY
)
1482 || (! gpr_interlocks
1483 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))))
1485 /* A load from a coprocessor or from memory. All load
1486 delays delay the use of general register rt for one
1487 instruction on the r3000. The r6000 and r4000 use
1489 /* Itbl support may require additional care here. */
1490 know (prev_pinfo
& INSN_WRITE_GPR_T
);
1491 if (reg
== ((prev_insn
.insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
))
1498 /* Mark instruction labels in mips16 mode. This permits the linker to
1499 handle them specially, such as generating jalx instructions when
1500 needed. We also make them odd for the duration of the assembly, in
1501 order to generate the right sort of code. We will make them even
1502 in the adjust_symtab routine, while leaving them marked. This is
1503 convenient for the debugger and the disassembler. The linker knows
1504 to make them odd again. */
1507 mips16_mark_labels (void)
1509 if (mips_opts
.mips16
)
1511 struct insn_label_list
*l
;
1514 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
1517 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1518 S_SET_OTHER (l
->label
, STO_MIPS16
);
1520 val
= S_GET_VALUE (l
->label
);
1522 S_SET_VALUE (l
->label
, val
+ 1);
1527 /* Output an instruction. PLACE is where to put the instruction; if
1528 it is NULL, this uses frag_more to get room. IP is the instruction
1529 information. ADDRESS_EXPR is an operand of the instruction to be
1530 used with RELOC_TYPE. */
1533 append_insn (char *place
, struct mips_cl_insn
*ip
, expressionS
*address_expr
,
1534 bfd_reloc_code_real_type
*reloc_type
)
1536 register unsigned long prev_pinfo
, pinfo
;
1540 bfd_boolean force_new_frag
= FALSE
;
1542 /* Mark instruction labels in mips16 mode. */
1543 mips16_mark_labels ();
1545 prev_pinfo
= prev_insn
.insn_mo
->pinfo
;
1546 pinfo
= ip
->insn_mo
->pinfo
;
1548 if (place
== NULL
&& (! mips_opts
.noreorder
|| prev_nop_frag
!= NULL
))
1552 /* If the previous insn required any delay slots, see if we need
1553 to insert a NOP or two. There are eight kinds of possible
1554 hazards, of which an instruction can have at most one type.
1555 (1) a load from memory delay
1556 (2) a load from a coprocessor delay
1557 (3) an unconditional branch delay
1558 (4) a conditional branch delay
1559 (5) a move to coprocessor register delay
1560 (6) a load coprocessor register from memory delay
1561 (7) a coprocessor condition code delay
1562 (8) a HI/LO special register delay
1564 There are a lot of optimizations we could do that we don't.
1565 In particular, we do not, in general, reorder instructions.
1566 If you use gcc with optimization, it will reorder
1567 instructions and generally do much more optimization then we
1568 do here; repeating all that work in the assembler would only
1569 benefit hand written assembly code, and does not seem worth
1572 /* This is how a NOP is emitted. */
1573 #define emit_nop() \
1575 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1576 : md_number_to_chars (frag_more (4), 0, 4))
1578 /* The previous insn might require a delay slot, depending upon
1579 the contents of the current insn. */
1580 if (! mips_opts
.mips16
1581 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1582 && (((prev_pinfo
& INSN_LOAD_COPROC_DELAY
)
1583 && ! cop_interlocks
)
1584 || (! gpr_interlocks
1585 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))))
1587 /* A load from a coprocessor or from memory. All load
1588 delays delay the use of general register rt for one
1589 instruction on the r3000. The r6000 and r4000 use
1591 /* Itbl support may require additional care here. */
1592 know (prev_pinfo
& INSN_WRITE_GPR_T
);
1593 if (mips_optimize
== 0
1594 || insn_uses_reg (ip
,
1595 ((prev_insn
.insn_opcode
>> OP_SH_RT
)
1600 else if (! mips_opts
.mips16
1601 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1602 && (((prev_pinfo
& INSN_COPROC_MOVE_DELAY
)
1603 && ! cop_interlocks
)
1604 || (mips_opts
.isa
== ISA_MIPS1
1605 && (prev_pinfo
& INSN_COPROC_MEMORY_DELAY
))))
1607 /* A generic coprocessor delay. The previous instruction
1608 modified a coprocessor general or control register. If
1609 it modified a control register, we need to avoid any
1610 coprocessor instruction (this is probably not always
1611 required, but it sometimes is). If it modified a general
1612 register, we avoid using that register.
1614 On the r6000 and r4000 loading a coprocessor register
1615 from memory is interlocked, and does not require a delay.
1617 This case is not handled very well. There is no special
1618 knowledge of CP0 handling, and the coprocessors other
1619 than the floating point unit are not distinguished at
1621 /* Itbl support may require additional care here. FIXME!
1622 Need to modify this to include knowledge about
1623 user specified delays! */
1624 if (prev_pinfo
& INSN_WRITE_FPR_T
)
1626 if (mips_optimize
== 0
1627 || insn_uses_reg (ip
,
1628 ((prev_insn
.insn_opcode
>> OP_SH_FT
)
1633 else if (prev_pinfo
& INSN_WRITE_FPR_S
)
1635 if (mips_optimize
== 0
1636 || insn_uses_reg (ip
,
1637 ((prev_insn
.insn_opcode
>> OP_SH_FS
)
1644 /* We don't know exactly what the previous instruction
1645 does. If the current instruction uses a coprocessor
1646 register, we must insert a NOP. If previous
1647 instruction may set the condition codes, and the
1648 current instruction uses them, we must insert two
1650 /* Itbl support may require additional care here. */
1651 if (mips_optimize
== 0
1652 || ((prev_pinfo
& INSN_WRITE_COND_CODE
)
1653 && (pinfo
& INSN_READ_COND_CODE
)))
1655 else if (pinfo
& INSN_COP
)
1659 else if (! mips_opts
.mips16
1660 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1661 && (prev_pinfo
& INSN_WRITE_COND_CODE
)
1662 && ! cop_interlocks
)
1664 /* The previous instruction sets the coprocessor condition
1665 codes, but does not require a general coprocessor delay
1666 (this means it is a floating point comparison
1667 instruction). If this instruction uses the condition
1668 codes, we need to insert a single NOP. */
1669 /* Itbl support may require additional care here. */
1670 if (mips_optimize
== 0
1671 || (pinfo
& INSN_READ_COND_CODE
))
1675 /* If we're fixing up mfhi/mflo for the r7000 and the
1676 previous insn was an mfhi/mflo and the current insn
1677 reads the register that the mfhi/mflo wrote to, then
1680 else if (mips_7000_hilo_fix
1681 && MF_HILO_INSN (prev_pinfo
)
1682 && insn_uses_reg (ip
, ((prev_insn
.insn_opcode
>> OP_SH_RD
)
1689 /* If we're fixing up mfhi/mflo for the r7000 and the
1690 2nd previous insn was an mfhi/mflo and the current insn
1691 reads the register that the mfhi/mflo wrote to, then
1694 else if (mips_7000_hilo_fix
1695 && MF_HILO_INSN (prev_prev_insn
.insn_opcode
)
1696 && insn_uses_reg (ip
, ((prev_prev_insn
.insn_opcode
>> OP_SH_RD
)
1704 else if (prev_pinfo
& INSN_READ_LO
)
1706 /* The previous instruction reads the LO register; if the
1707 current instruction writes to the LO register, we must
1708 insert two NOPS. Some newer processors have interlocks.
1709 Also the tx39's multiply instructions can be exectuted
1710 immediatly after a read from HI/LO (without the delay),
1711 though the tx39's divide insns still do require the
1713 if (! (hilo_interlocks
1714 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
1715 && (mips_optimize
== 0
1716 || (pinfo
& INSN_WRITE_LO
)))
1718 /* Most mips16 branch insns don't have a delay slot.
1719 If a read from LO is immediately followed by a branch
1720 to a write to LO we have a read followed by a write
1721 less than 2 insns away. We assume the target of
1722 a branch might be a write to LO, and insert a nop
1723 between a read and an immediately following branch. */
1724 else if (mips_opts
.mips16
1725 && (mips_optimize
== 0
1726 || (pinfo
& MIPS16_INSN_BRANCH
)))
1729 else if (prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
1731 /* The previous instruction reads the HI register; if the
1732 current instruction writes to the HI register, we must
1733 insert a NOP. Some newer processors have interlocks.
1734 Also the note tx39's multiply above. */
1735 if (! (hilo_interlocks
1736 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
1737 && (mips_optimize
== 0
1738 || (pinfo
& INSN_WRITE_HI
)))
1740 /* Most mips16 branch insns don't have a delay slot.
1741 If a read from HI is immediately followed by a branch
1742 to a write to HI we have a read followed by a write
1743 less than 2 insns away. We assume the target of
1744 a branch might be a write to HI, and insert a nop
1745 between a read and an immediately following branch. */
1746 else if (mips_opts
.mips16
1747 && (mips_optimize
== 0
1748 || (pinfo
& MIPS16_INSN_BRANCH
)))
1752 /* If the previous instruction was in a noreorder section, then
1753 we don't want to insert the nop after all. */
1754 /* Itbl support may require additional care here. */
1755 if (prev_insn_unreordered
)
1758 /* There are two cases which require two intervening
1759 instructions: 1) setting the condition codes using a move to
1760 coprocessor instruction which requires a general coprocessor
1761 delay and then reading the condition codes 2) reading the HI
1762 or LO register and then writing to it (except on processors
1763 which have interlocks). If we are not already emitting a NOP
1764 instruction, we must check for these cases compared to the
1765 instruction previous to the previous instruction. */
1766 if ((! mips_opts
.mips16
1767 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
1768 && (prev_prev_insn
.insn_mo
->pinfo
& INSN_COPROC_MOVE_DELAY
)
1769 && (prev_prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
)
1770 && (pinfo
& INSN_READ_COND_CODE
)
1771 && ! cop_interlocks
)
1772 || ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
)
1773 && (pinfo
& INSN_WRITE_LO
)
1774 && ! (hilo_interlocks
1775 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
))))
1776 || ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
1777 && (pinfo
& INSN_WRITE_HI
)
1778 && ! (hilo_interlocks
1779 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))))
1784 if (prev_prev_insn_unreordered
)
1787 if (prev_prev_nop
&& nops
== 0)
1790 if (mips_fix_4122_bugs
&& prev_insn
.insn_mo
->name
)
1792 /* We're out of bits in pinfo, so we must resort to string
1793 ops here. Shortcuts are selected based on opcodes being
1794 limited to the VR4122 instruction set. */
1796 const char *pn
= prev_insn
.insn_mo
->name
;
1797 const char *tn
= ip
->insn_mo
->name
;
1798 if (strncmp(pn
, "macc", 4) == 0
1799 || strncmp(pn
, "dmacc", 5) == 0)
1801 /* Errata 21 - [D]DIV[U] after [D]MACC */
1802 if (strstr (tn
, "div"))
1807 /* Errata 23 - Continuous DMULT[U]/DMACC instructions */
1808 if (pn
[0] == 'd' /* dmacc */
1809 && (strncmp(tn
, "dmult", 5) == 0
1810 || strncmp(tn
, "dmacc", 5) == 0))
1815 /* Errata 24 - MT{LO,HI} after [D]MACC */
1816 if (strcmp (tn
, "mtlo") == 0
1817 || strcmp (tn
, "mthi") == 0)
1823 else if (strncmp(pn
, "dmult", 5) == 0
1824 && (strncmp(tn
, "dmult", 5) == 0
1825 || strncmp(tn
, "dmacc", 5) == 0))
1827 /* Here is the rest of errata 23. */
1830 if (nops
< min_nops
)
1834 /* If we are being given a nop instruction, don't bother with
1835 one of the nops we would otherwise output. This will only
1836 happen when a nop instruction is used with mips_optimize set
1839 && ! mips_opts
.noreorder
1840 && ip
->insn_opcode
== (unsigned) (mips_opts
.mips16
? 0x6500 : 0))
1843 /* Now emit the right number of NOP instructions. */
1844 if (nops
> 0 && ! mips_opts
.noreorder
)
1847 unsigned long old_frag_offset
;
1849 struct insn_label_list
*l
;
1851 old_frag
= frag_now
;
1852 old_frag_offset
= frag_now_fix ();
1854 for (i
= 0; i
< nops
; i
++)
1859 listing_prev_line ();
1860 /* We may be at the start of a variant frag. In case we
1861 are, make sure there is enough space for the frag
1862 after the frags created by listing_prev_line. The
1863 argument to frag_grow here must be at least as large
1864 as the argument to all other calls to frag_grow in
1865 this file. We don't have to worry about being in the
1866 middle of a variant frag, because the variants insert
1867 all needed nop instructions themselves. */
1871 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
1875 assert (S_GET_SEGMENT (l
->label
) == now_seg
);
1876 symbol_set_frag (l
->label
, frag_now
);
1877 val
= (valueT
) frag_now_fix ();
1878 /* mips16 text labels are stored as odd. */
1879 if (mips_opts
.mips16
)
1881 S_SET_VALUE (l
->label
, val
);
1884 #ifndef NO_ECOFF_DEBUGGING
1885 if (ECOFF_DEBUGGING
)
1886 ecoff_fix_loc (old_frag
, old_frag_offset
);
1889 else if (prev_nop_frag
!= NULL
)
1891 /* We have a frag holding nops we may be able to remove. If
1892 we don't need any nops, we can decrease the size of
1893 prev_nop_frag by the size of one instruction. If we do
1894 need some nops, we count them in prev_nops_required. */
1895 if (prev_nop_frag_since
== 0)
1899 prev_nop_frag
->fr_fix
-= mips_opts
.mips16
? 2 : 4;
1900 --prev_nop_frag_holds
;
1903 prev_nop_frag_required
+= nops
;
1907 if (prev_prev_nop
== 0)
1909 prev_nop_frag
->fr_fix
-= mips_opts
.mips16
? 2 : 4;
1910 --prev_nop_frag_holds
;
1913 ++prev_nop_frag_required
;
1916 if (prev_nop_frag_holds
<= prev_nop_frag_required
)
1917 prev_nop_frag
= NULL
;
1919 ++prev_nop_frag_since
;
1921 /* Sanity check: by the time we reach the second instruction
1922 after prev_nop_frag, we should have used up all the nops
1923 one way or another. */
1924 assert (prev_nop_frag_since
<= 1 || prev_nop_frag
== NULL
);
1930 && *reloc_type
== BFD_RELOC_16_PCREL_S2
1931 && (pinfo
& INSN_UNCOND_BRANCH_DELAY
|| pinfo
& INSN_COND_BRANCH_DELAY
1932 || pinfo
& INSN_COND_BRANCH_LIKELY
)
1933 && mips_relax_branch
1934 /* Don't try branch relaxation within .set nomacro, or within
1935 .set noat if we use $at for PIC computations. If it turns
1936 out that the branch was out-of-range, we'll get an error. */
1937 && !mips_opts
.warn_about_macros
1938 && !(mips_opts
.noat
&& mips_pic
!= NO_PIC
)
1939 && !mips_opts
.mips16
)
1941 f
= frag_var (rs_machine_dependent
,
1942 relaxed_branch_length
1944 (pinfo
& INSN_UNCOND_BRANCH_DELAY
) ? -1
1945 : (pinfo
& INSN_COND_BRANCH_LIKELY
) ? 1 : 0), 4,
1947 (pinfo
& INSN_UNCOND_BRANCH_DELAY
,
1948 pinfo
& INSN_COND_BRANCH_LIKELY
,
1949 pinfo
& INSN_WRITE_GPR_31
,
1951 address_expr
->X_add_symbol
,
1952 address_expr
->X_add_number
,
1954 *reloc_type
= BFD_RELOC_UNUSED
;
1956 else if (*reloc_type
> BFD_RELOC_UNUSED
)
1958 /* We need to set up a variant frag. */
1959 assert (mips_opts
.mips16
&& address_expr
!= NULL
);
1960 f
= frag_var (rs_machine_dependent
, 4, 0,
1961 RELAX_MIPS16_ENCODE (*reloc_type
- BFD_RELOC_UNUSED
,
1962 mips16_small
, mips16_ext
,
1964 & INSN_UNCOND_BRANCH_DELAY
),
1965 (*prev_insn_reloc_type
1966 == BFD_RELOC_MIPS16_JMP
)),
1967 make_expr_symbol (address_expr
), 0, NULL
);
1969 else if (place
!= NULL
)
1971 else if (mips_opts
.mips16
1973 && *reloc_type
!= BFD_RELOC_MIPS16_JMP
)
1975 /* Make sure there is enough room to swap this instruction with
1976 a following jump instruction. */
1982 if (mips_opts
.mips16
1983 && mips_opts
.noreorder
1984 && (prev_pinfo
& INSN_UNCOND_BRANCH_DELAY
) != 0)
1985 as_warn (_("extended instruction in delay slot"));
1990 fixp
[0] = fixp
[1] = fixp
[2] = NULL
;
1991 if (address_expr
!= NULL
&& *reloc_type
< BFD_RELOC_UNUSED
)
1993 if (address_expr
->X_op
== O_constant
)
1997 switch (*reloc_type
)
2000 ip
->insn_opcode
|= address_expr
->X_add_number
;
2003 case BFD_RELOC_MIPS_HIGHEST
:
2004 tmp
= (address_expr
->X_add_number
2005 + ((valueT
) 0x8000 << 32) + 0x80008000) >> 16;
2007 ip
->insn_opcode
|= (tmp
>> 16) & 0xffff;
2010 case BFD_RELOC_MIPS_HIGHER
:
2011 tmp
= (address_expr
->X_add_number
+ 0x80008000) >> 16;
2012 ip
->insn_opcode
|= (tmp
>> 16) & 0xffff;
2015 case BFD_RELOC_HI16_S
:
2016 ip
->insn_opcode
|= ((address_expr
->X_add_number
+ 0x8000)
2020 case BFD_RELOC_HI16
:
2021 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 16) & 0xffff;
2024 case BFD_RELOC_LO16
:
2025 case BFD_RELOC_MIPS_GOT_DISP
:
2026 ip
->insn_opcode
|= address_expr
->X_add_number
& 0xffff;
2029 case BFD_RELOC_MIPS_JMP
:
2030 if ((address_expr
->X_add_number
& 3) != 0)
2031 as_bad (_("jump to misaligned address (0x%lx)"),
2032 (unsigned long) address_expr
->X_add_number
);
2033 if (address_expr
->X_add_number
& ~0xfffffff)
2034 as_bad (_("jump address range overflow (0x%lx)"),
2035 (unsigned long) address_expr
->X_add_number
);
2036 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 2) & 0x3ffffff;
2039 case BFD_RELOC_MIPS16_JMP
:
2040 if ((address_expr
->X_add_number
& 3) != 0)
2041 as_bad (_("jump to misaligned address (0x%lx)"),
2042 (unsigned long) address_expr
->X_add_number
);
2043 if (address_expr
->X_add_number
& ~0xfffffff)
2044 as_bad (_("jump address range overflow (0x%lx)"),
2045 (unsigned long) address_expr
->X_add_number
);
2047 (((address_expr
->X_add_number
& 0x7c0000) << 3)
2048 | ((address_expr
->X_add_number
& 0xf800000) >> 7)
2049 | ((address_expr
->X_add_number
& 0x3fffc) >> 2));
2052 case BFD_RELOC_16_PCREL_S2
:
2062 /* Don't generate a reloc if we are writing into a variant frag. */
2065 reloc_howto_type
*howto
;
2068 /* In a compound relocation, it is the final (outermost)
2069 operator that determines the relocated field. */
2070 for (i
= 1; i
< 3; i
++)
2071 if (reloc_type
[i
] == BFD_RELOC_UNUSED
)
2074 howto
= bfd_reloc_type_lookup (stdoutput
, reloc_type
[i
- 1]);
2075 fixp
[0] = fix_new_exp (frag_now
, f
- frag_now
->fr_literal
,
2076 bfd_get_reloc_size(howto
),
2078 reloc_type
[0] == BFD_RELOC_16_PCREL_S2
,
2081 /* These relocations can have an addend that won't fit in
2082 4 octets for 64bit assembly. */
2084 && ! howto
->partial_inplace
2085 && (reloc_type
[0] == BFD_RELOC_16
2086 || reloc_type
[0] == BFD_RELOC_32
2087 || reloc_type
[0] == BFD_RELOC_MIPS_JMP
2088 || reloc_type
[0] == BFD_RELOC_HI16_S
2089 || reloc_type
[0] == BFD_RELOC_LO16
2090 || reloc_type
[0] == BFD_RELOC_GPREL16
2091 || reloc_type
[0] == BFD_RELOC_MIPS_LITERAL
2092 || reloc_type
[0] == BFD_RELOC_GPREL32
2093 || reloc_type
[0] == BFD_RELOC_64
2094 || reloc_type
[0] == BFD_RELOC_CTOR
2095 || reloc_type
[0] == BFD_RELOC_MIPS_SUB
2096 || reloc_type
[0] == BFD_RELOC_MIPS_HIGHEST
2097 || reloc_type
[0] == BFD_RELOC_MIPS_HIGHER
2098 || reloc_type
[0] == BFD_RELOC_MIPS_SCN_DISP
2099 || reloc_type
[0] == BFD_RELOC_MIPS_REL16
2100 || reloc_type
[0] == BFD_RELOC_MIPS_RELGOT
))
2101 fixp
[0]->fx_no_overflow
= 1;
2103 if (reloc_needs_lo_p (*reloc_type
))
2105 struct mips_hi_fixup
*hi_fixup
;
2107 /* Reuse the last entry if it already has a matching %lo. */
2108 hi_fixup
= mips_hi_fixup_list
;
2110 || !fixup_has_matching_lo_p (hi_fixup
->fixp
))
2112 hi_fixup
= ((struct mips_hi_fixup
*)
2113 xmalloc (sizeof (struct mips_hi_fixup
)));
2114 hi_fixup
->next
= mips_hi_fixup_list
;
2115 mips_hi_fixup_list
= hi_fixup
;
2117 hi_fixup
->fixp
= fixp
[0];
2118 hi_fixup
->seg
= now_seg
;
2121 /* Add fixups for the second and third relocations, if given.
2122 Note that the ABI allows the second relocation to be
2123 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
2124 moment we only use RSS_UNDEF, but we could add support
2125 for the others if it ever becomes necessary. */
2126 for (i
= 1; i
< 3; i
++)
2127 if (reloc_type
[i
] != BFD_RELOC_UNUSED
)
2129 address_expr
->X_op
= O_absent
;
2130 address_expr
->X_add_symbol
= 0;
2131 address_expr
->X_add_number
= 0;
2133 fixp
[i
] = fix_new_exp (frag_now
, fixp
[0]->fx_where
,
2134 fixp
[0]->fx_size
, address_expr
,
2135 FALSE
, reloc_type
[i
]);
2141 if (! mips_opts
.mips16
)
2143 md_number_to_chars (f
, ip
->insn_opcode
, 4);
2145 dwarf2_emit_insn (4);
2148 else if (*reloc_type
== BFD_RELOC_MIPS16_JMP
)
2150 md_number_to_chars (f
, ip
->insn_opcode
>> 16, 2);
2151 md_number_to_chars (f
+ 2, ip
->insn_opcode
& 0xffff, 2);
2153 dwarf2_emit_insn (4);
2160 md_number_to_chars (f
, 0xf000 | ip
->extend
, 2);
2163 md_number_to_chars (f
, ip
->insn_opcode
, 2);
2165 dwarf2_emit_insn (ip
->use_extend
? 4 : 2);
2169 /* Update the register mask information. */
2170 if (! mips_opts
.mips16
)
2172 if (pinfo
& INSN_WRITE_GPR_D
)
2173 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
);
2174 if ((pinfo
& (INSN_WRITE_GPR_T
| INSN_READ_GPR_T
)) != 0)
2175 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
);
2176 if (pinfo
& INSN_READ_GPR_S
)
2177 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> OP_SH_RS
) & OP_MASK_RS
);
2178 if (pinfo
& INSN_WRITE_GPR_31
)
2179 mips_gprmask
|= 1 << RA
;
2180 if (pinfo
& INSN_WRITE_FPR_D
)
2181 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FD
) & OP_MASK_FD
);
2182 if ((pinfo
& (INSN_WRITE_FPR_S
| INSN_READ_FPR_S
)) != 0)
2183 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FS
) & OP_MASK_FS
);
2184 if ((pinfo
& (INSN_WRITE_FPR_T
| INSN_READ_FPR_T
)) != 0)
2185 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FT
) & OP_MASK_FT
);
2186 if ((pinfo
& INSN_READ_FPR_R
) != 0)
2187 mips_cprmask
[1] |= 1 << ((ip
->insn_opcode
>> OP_SH_FR
) & OP_MASK_FR
);
2188 if (pinfo
& INSN_COP
)
2190 /* We don't keep enough information to sort these cases out.
2191 The itbl support does keep this information however, although
2192 we currently don't support itbl fprmats as part of the cop
2193 instruction. May want to add this support in the future. */
2195 /* Never set the bit for $0, which is always zero. */
2196 mips_gprmask
&= ~1 << 0;
2200 if (pinfo
& (MIPS16_INSN_WRITE_X
| MIPS16_INSN_READ_X
))
2201 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RX
)
2202 & MIPS16OP_MASK_RX
);
2203 if (pinfo
& (MIPS16_INSN_WRITE_Y
| MIPS16_INSN_READ_Y
))
2204 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RY
)
2205 & MIPS16OP_MASK_RY
);
2206 if (pinfo
& MIPS16_INSN_WRITE_Z
)
2207 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_RZ
)
2208 & MIPS16OP_MASK_RZ
);
2209 if (pinfo
& (MIPS16_INSN_WRITE_T
| MIPS16_INSN_READ_T
))
2210 mips_gprmask
|= 1 << TREG
;
2211 if (pinfo
& (MIPS16_INSN_WRITE_SP
| MIPS16_INSN_READ_SP
))
2212 mips_gprmask
|= 1 << SP
;
2213 if (pinfo
& (MIPS16_INSN_WRITE_31
| MIPS16_INSN_READ_31
))
2214 mips_gprmask
|= 1 << RA
;
2215 if (pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2216 mips_gprmask
|= 1 << MIPS16OP_EXTRACT_REG32R (ip
->insn_opcode
);
2217 if (pinfo
& MIPS16_INSN_READ_Z
)
2218 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_MOVE32Z
)
2219 & MIPS16OP_MASK_MOVE32Z
);
2220 if (pinfo
& MIPS16_INSN_READ_GPR_X
)
2221 mips_gprmask
|= 1 << ((ip
->insn_opcode
>> MIPS16OP_SH_REGR32
)
2222 & MIPS16OP_MASK_REGR32
);
2225 if (place
== NULL
&& ! mips_opts
.noreorder
)
2227 /* Filling the branch delay slot is more complex. We try to
2228 switch the branch with the previous instruction, which we can
2229 do if the previous instruction does not set up a condition
2230 that the branch tests and if the branch is not itself the
2231 target of any branch. */
2232 if ((pinfo
& INSN_UNCOND_BRANCH_DELAY
)
2233 || (pinfo
& INSN_COND_BRANCH_DELAY
))
2235 if (mips_optimize
< 2
2236 /* If we have seen .set volatile or .set nomove, don't
2238 || mips_opts
.nomove
!= 0
2239 /* If we had to emit any NOP instructions, then we
2240 already know we can not swap. */
2242 /* If we don't even know the previous insn, we can not
2244 || ! prev_insn_valid
2245 /* If the previous insn is already in a branch delay
2246 slot, then we can not swap. */
2247 || prev_insn_is_delay_slot
2248 /* If the previous previous insn was in a .set
2249 noreorder, we can't swap. Actually, the MIPS
2250 assembler will swap in this situation. However, gcc
2251 configured -with-gnu-as will generate code like
2257 in which we can not swap the bne and INSN. If gcc is
2258 not configured -with-gnu-as, it does not output the
2259 .set pseudo-ops. We don't have to check
2260 prev_insn_unreordered, because prev_insn_valid will
2261 be 0 in that case. We don't want to use
2262 prev_prev_insn_valid, because we do want to be able
2263 to swap at the start of a function. */
2264 || prev_prev_insn_unreordered
2265 /* If the branch is itself the target of a branch, we
2266 can not swap. We cheat on this; all we check for is
2267 whether there is a label on this instruction. If
2268 there are any branches to anything other than a
2269 label, users must use .set noreorder. */
2270 || insn_labels
!= NULL
2271 /* If the previous instruction is in a variant frag, we
2272 can not do the swap. This does not apply to the
2273 mips16, which uses variant frags for different
2275 || (! mips_opts
.mips16
2276 && prev_insn_frag
->fr_type
== rs_machine_dependent
)
2277 /* If the branch reads the condition codes, we don't
2278 even try to swap, because in the sequence
2283 we can not swap, and I don't feel like handling that
2285 || (! mips_opts
.mips16
2286 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2287 && (pinfo
& INSN_READ_COND_CODE
))
2288 /* We can not swap with an instruction that requires a
2289 delay slot, becase the target of the branch might
2290 interfere with that instruction. */
2291 || (! mips_opts
.mips16
2292 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2294 /* Itbl support may require additional care here. */
2295 & (INSN_LOAD_COPROC_DELAY
2296 | INSN_COPROC_MOVE_DELAY
2297 | INSN_WRITE_COND_CODE
)))
2298 || (! (hilo_interlocks
2299 || (mips_tune
== CPU_R3900
&& (pinfo
& INSN_MULT
)))
2303 || (! mips_opts
.mips16
2305 && (prev_pinfo
& INSN_LOAD_MEMORY_DELAY
))
2306 || (! mips_opts
.mips16
2307 && mips_opts
.isa
== ISA_MIPS1
2308 /* Itbl support may require additional care here. */
2309 && (prev_pinfo
& INSN_COPROC_MEMORY_DELAY
))
2310 /* We can not swap with a branch instruction. */
2312 & (INSN_UNCOND_BRANCH_DELAY
2313 | INSN_COND_BRANCH_DELAY
2314 | INSN_COND_BRANCH_LIKELY
))
2315 /* We do not swap with a trap instruction, since it
2316 complicates trap handlers to have the trap
2317 instruction be in a delay slot. */
2318 || (prev_pinfo
& INSN_TRAP
)
2319 /* If the branch reads a register that the previous
2320 instruction sets, we can not swap. */
2321 || (! mips_opts
.mips16
2322 && (prev_pinfo
& INSN_WRITE_GPR_T
)
2323 && insn_uses_reg (ip
,
2324 ((prev_insn
.insn_opcode
>> OP_SH_RT
)
2327 || (! mips_opts
.mips16
2328 && (prev_pinfo
& INSN_WRITE_GPR_D
)
2329 && insn_uses_reg (ip
,
2330 ((prev_insn
.insn_opcode
>> OP_SH_RD
)
2333 || (mips_opts
.mips16
2334 && (((prev_pinfo
& MIPS16_INSN_WRITE_X
)
2335 && insn_uses_reg (ip
,
2336 ((prev_insn
.insn_opcode
2338 & MIPS16OP_MASK_RX
),
2340 || ((prev_pinfo
& MIPS16_INSN_WRITE_Y
)
2341 && insn_uses_reg (ip
,
2342 ((prev_insn
.insn_opcode
2344 & MIPS16OP_MASK_RY
),
2346 || ((prev_pinfo
& MIPS16_INSN_WRITE_Z
)
2347 && insn_uses_reg (ip
,
2348 ((prev_insn
.insn_opcode
2350 & MIPS16OP_MASK_RZ
),
2352 || ((prev_pinfo
& MIPS16_INSN_WRITE_T
)
2353 && insn_uses_reg (ip
, TREG
, MIPS_GR_REG
))
2354 || ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
2355 && insn_uses_reg (ip
, RA
, MIPS_GR_REG
))
2356 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2357 && insn_uses_reg (ip
,
2358 MIPS16OP_EXTRACT_REG32R (prev_insn
.
2361 /* If the branch writes a register that the previous
2362 instruction sets, we can not swap (we know that
2363 branches write only to RD or to $31). */
2364 || (! mips_opts
.mips16
2365 && (prev_pinfo
& INSN_WRITE_GPR_T
)
2366 && (((pinfo
& INSN_WRITE_GPR_D
)
2367 && (((prev_insn
.insn_opcode
>> OP_SH_RT
) & OP_MASK_RT
)
2368 == ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)))
2369 || ((pinfo
& INSN_WRITE_GPR_31
)
2370 && (((prev_insn
.insn_opcode
>> OP_SH_RT
)
2373 || (! mips_opts
.mips16
2374 && (prev_pinfo
& INSN_WRITE_GPR_D
)
2375 && (((pinfo
& INSN_WRITE_GPR_D
)
2376 && (((prev_insn
.insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)
2377 == ((ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
)))
2378 || ((pinfo
& INSN_WRITE_GPR_31
)
2379 && (((prev_insn
.insn_opcode
>> OP_SH_RD
)
2382 || (mips_opts
.mips16
2383 && (pinfo
& MIPS16_INSN_WRITE_31
)
2384 && ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
2385 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2386 && (MIPS16OP_EXTRACT_REG32R (prev_insn
.insn_opcode
)
2388 /* If the branch writes a register that the previous
2389 instruction reads, we can not swap (we know that
2390 branches only write to RD or to $31). */
2391 || (! mips_opts
.mips16
2392 && (pinfo
& INSN_WRITE_GPR_D
)
2393 && insn_uses_reg (&prev_insn
,
2394 ((ip
->insn_opcode
>> OP_SH_RD
)
2397 || (! mips_opts
.mips16
2398 && (pinfo
& INSN_WRITE_GPR_31
)
2399 && insn_uses_reg (&prev_insn
, RA
, MIPS_GR_REG
))
2400 || (mips_opts
.mips16
2401 && (pinfo
& MIPS16_INSN_WRITE_31
)
2402 && insn_uses_reg (&prev_insn
, RA
, MIPS_GR_REG
))
2403 /* If we are generating embedded PIC code, the branch
2404 might be expanded into a sequence which uses $at, so
2405 we can't swap with an instruction which reads it. */
2406 || (mips_pic
== EMBEDDED_PIC
2407 && insn_uses_reg (&prev_insn
, AT
, MIPS_GR_REG
))
2408 /* If the previous previous instruction has a load
2409 delay, and sets a register that the branch reads, we
2411 || (! mips_opts
.mips16
2412 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2413 /* Itbl support may require additional care here. */
2414 && ((prev_prev_insn
.insn_mo
->pinfo
& INSN_LOAD_COPROC_DELAY
)
2415 || (! gpr_interlocks
2416 && (prev_prev_insn
.insn_mo
->pinfo
2417 & INSN_LOAD_MEMORY_DELAY
)))
2418 && insn_uses_reg (ip
,
2419 ((prev_prev_insn
.insn_opcode
>> OP_SH_RT
)
2422 /* If one instruction sets a condition code and the
2423 other one uses a condition code, we can not swap. */
2424 || ((pinfo
& INSN_READ_COND_CODE
)
2425 && (prev_pinfo
& INSN_WRITE_COND_CODE
))
2426 || ((pinfo
& INSN_WRITE_COND_CODE
)
2427 && (prev_pinfo
& INSN_READ_COND_CODE
))
2428 /* If the previous instruction uses the PC, we can not
2430 || (mips_opts
.mips16
2431 && (prev_pinfo
& MIPS16_INSN_READ_PC
))
2432 /* If the previous instruction was extended, we can not
2434 || (mips_opts
.mips16
&& prev_insn_extended
)
2435 /* If the previous instruction had a fixup in mips16
2436 mode, we can not swap. This normally means that the
2437 previous instruction was a 4 byte branch anyhow. */
2438 || (mips_opts
.mips16
&& prev_insn_fixp
[0])
2439 /* If the previous instruction is a sync, sync.l, or
2440 sync.p, we can not swap. */
2441 || (prev_pinfo
& INSN_SYNC
))
2443 /* We could do even better for unconditional branches to
2444 portions of this object file; we could pick up the
2445 instruction at the destination, put it in the delay
2446 slot, and bump the destination address. */
2448 /* Update the previous insn information. */
2449 prev_prev_insn
= *ip
;
2450 prev_insn
.insn_mo
= &dummy_opcode
;
2454 /* It looks like we can actually do the swap. */
2455 if (! mips_opts
.mips16
)
2460 prev_f
= prev_insn_frag
->fr_literal
+ prev_insn_where
;
2461 memcpy (temp
, prev_f
, 4);
2462 memcpy (prev_f
, f
, 4);
2463 memcpy (f
, temp
, 4);
2464 if (prev_insn_fixp
[0])
2466 prev_insn_fixp
[0]->fx_frag
= frag_now
;
2467 prev_insn_fixp
[0]->fx_where
= f
- frag_now
->fr_literal
;
2469 if (prev_insn_fixp
[1])
2471 prev_insn_fixp
[1]->fx_frag
= frag_now
;
2472 prev_insn_fixp
[1]->fx_where
= f
- frag_now
->fr_literal
;
2474 if (prev_insn_fixp
[2])
2476 prev_insn_fixp
[2]->fx_frag
= frag_now
;
2477 prev_insn_fixp
[2]->fx_where
= f
- frag_now
->fr_literal
;
2479 if (prev_insn_fixp
[0] && HAVE_NEWABI
2480 && prev_insn_frag
!= frag_now
2481 && (prev_insn_fixp
[0]->fx_r_type
2482 == BFD_RELOC_MIPS_GOT_DISP
2483 || (prev_insn_fixp
[0]->fx_r_type
2484 == BFD_RELOC_MIPS_CALL16
)))
2486 /* To avoid confusion in tc_gen_reloc, we must
2487 ensure that this does not become a variant
2489 force_new_frag
= TRUE
;
2493 fixp
[0]->fx_frag
= prev_insn_frag
;
2494 fixp
[0]->fx_where
= prev_insn_where
;
2498 fixp
[1]->fx_frag
= prev_insn_frag
;
2499 fixp
[1]->fx_where
= prev_insn_where
;
2503 fixp
[2]->fx_frag
= prev_insn_frag
;
2504 fixp
[2]->fx_where
= prev_insn_where
;
2512 assert (prev_insn_fixp
[0] == NULL
);
2513 assert (prev_insn_fixp
[1] == NULL
);
2514 assert (prev_insn_fixp
[2] == NULL
);
2515 prev_f
= prev_insn_frag
->fr_literal
+ prev_insn_where
;
2516 memcpy (temp
, prev_f
, 2);
2517 memcpy (prev_f
, f
, 2);
2518 if (*reloc_type
!= BFD_RELOC_MIPS16_JMP
)
2520 assert (*reloc_type
== BFD_RELOC_UNUSED
);
2521 memcpy (f
, temp
, 2);
2525 memcpy (f
, f
+ 2, 2);
2526 memcpy (f
+ 2, temp
, 2);
2530 fixp
[0]->fx_frag
= prev_insn_frag
;
2531 fixp
[0]->fx_where
= prev_insn_where
;
2535 fixp
[1]->fx_frag
= prev_insn_frag
;
2536 fixp
[1]->fx_where
= prev_insn_where
;
2540 fixp
[2]->fx_frag
= prev_insn_frag
;
2541 fixp
[2]->fx_where
= prev_insn_where
;
2545 /* Update the previous insn information; leave prev_insn
2547 prev_prev_insn
= *ip
;
2549 prev_insn_is_delay_slot
= 1;
2551 /* If that was an unconditional branch, forget the previous
2552 insn information. */
2553 if (pinfo
& INSN_UNCOND_BRANCH_DELAY
)
2555 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2556 prev_insn
.insn_mo
= &dummy_opcode
;
2559 prev_insn_fixp
[0] = NULL
;
2560 prev_insn_fixp
[1] = NULL
;
2561 prev_insn_fixp
[2] = NULL
;
2562 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2563 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2564 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2565 prev_insn_extended
= 0;
2567 else if (pinfo
& INSN_COND_BRANCH_LIKELY
)
2569 /* We don't yet optimize a branch likely. What we should do
2570 is look at the target, copy the instruction found there
2571 into the delay slot, and increment the branch to jump to
2572 the next instruction. */
2574 /* Update the previous insn information. */
2575 prev_prev_insn
= *ip
;
2576 prev_insn
.insn_mo
= &dummy_opcode
;
2577 prev_insn_fixp
[0] = NULL
;
2578 prev_insn_fixp
[1] = NULL
;
2579 prev_insn_fixp
[2] = NULL
;
2580 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2581 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2582 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2583 prev_insn_extended
= 0;
2587 /* Update the previous insn information. */
2589 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2591 prev_prev_insn
= prev_insn
;
2594 /* Any time we see a branch, we always fill the delay slot
2595 immediately; since this insn is not a branch, we know it
2596 is not in a delay slot. */
2597 prev_insn_is_delay_slot
= 0;
2599 prev_insn_fixp
[0] = fixp
[0];
2600 prev_insn_fixp
[1] = fixp
[1];
2601 prev_insn_fixp
[2] = fixp
[2];
2602 prev_insn_reloc_type
[0] = reloc_type
[0];
2603 prev_insn_reloc_type
[1] = reloc_type
[1];
2604 prev_insn_reloc_type
[2] = reloc_type
[2];
2605 if (mips_opts
.mips16
)
2606 prev_insn_extended
= (ip
->use_extend
2607 || *reloc_type
> BFD_RELOC_UNUSED
);
2610 prev_prev_insn_unreordered
= prev_insn_unreordered
;
2611 prev_insn_unreordered
= 0;
2612 prev_insn_frag
= frag_now
;
2613 prev_insn_where
= f
- frag_now
->fr_literal
;
2614 prev_insn_valid
= 1;
2616 else if (place
== NULL
)
2618 /* We need to record a bit of information even when we are not
2619 reordering, in order to determine the base address for mips16
2620 PC relative relocs. */
2621 prev_prev_insn
= prev_insn
;
2623 prev_insn_reloc_type
[0] = reloc_type
[0];
2624 prev_insn_reloc_type
[1] = reloc_type
[1];
2625 prev_insn_reloc_type
[2] = reloc_type
[2];
2626 prev_prev_insn_unreordered
= prev_insn_unreordered
;
2627 prev_insn_unreordered
= 1;
2630 /* We just output an insn, so the next one doesn't have a label. */
2631 mips_clear_insn_labels ();
2633 /* We must ensure that the frag to which an instruction that was
2634 moved from a non-variant frag doesn't become a variant frag,
2635 otherwise tc_gen_reloc may get confused. */
2638 frag_wane (frag_now
);
2643 /* This function forgets that there was any previous instruction or
2644 label. If PRESERVE is non-zero, it remembers enough information to
2645 know whether nops are needed before a noreorder section. */
2648 mips_no_prev_insn (int preserve
)
2652 prev_insn
.insn_mo
= &dummy_opcode
;
2653 prev_prev_insn
.insn_mo
= &dummy_opcode
;
2654 prev_nop_frag
= NULL
;
2655 prev_nop_frag_holds
= 0;
2656 prev_nop_frag_required
= 0;
2657 prev_nop_frag_since
= 0;
2659 prev_insn_valid
= 0;
2660 prev_insn_is_delay_slot
= 0;
2661 prev_insn_unreordered
= 0;
2662 prev_insn_extended
= 0;
2663 prev_insn_reloc_type
[0] = BFD_RELOC_UNUSED
;
2664 prev_insn_reloc_type
[1] = BFD_RELOC_UNUSED
;
2665 prev_insn_reloc_type
[2] = BFD_RELOC_UNUSED
;
2666 prev_prev_insn_unreordered
= 0;
2667 mips_clear_insn_labels ();
2670 /* This function must be called whenever we turn on noreorder or emit
2671 something other than instructions. It inserts any NOPS which might
2672 be needed by the previous instruction, and clears the information
2673 kept for the previous instructions. The INSNS parameter is true if
2674 instructions are to follow. */
2677 mips_emit_delays (bfd_boolean insns
)
2679 if (! mips_opts
.noreorder
)
2684 if ((! mips_opts
.mips16
2685 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2686 && (! cop_interlocks
2687 && (prev_insn
.insn_mo
->pinfo
2688 & (INSN_LOAD_COPROC_DELAY
2689 | INSN_COPROC_MOVE_DELAY
2690 | INSN_WRITE_COND_CODE
))))
2691 || (! hilo_interlocks
2692 && (prev_insn
.insn_mo
->pinfo
2695 || (! mips_opts
.mips16
2697 && (prev_insn
.insn_mo
->pinfo
2698 & INSN_LOAD_MEMORY_DELAY
))
2699 || (! mips_opts
.mips16
2700 && mips_opts
.isa
== ISA_MIPS1
2701 && (prev_insn
.insn_mo
->pinfo
2702 & INSN_COPROC_MEMORY_DELAY
)))
2704 /* Itbl support may require additional care here. */
2706 if ((! mips_opts
.mips16
2707 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2708 && (! cop_interlocks
2709 && prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
))
2710 || (! hilo_interlocks
2711 && ((prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
2712 || (prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
))))
2715 if (prev_insn_unreordered
)
2718 else if ((! mips_opts
.mips16
2719 && ISA_HAS_COPROC_DELAYS (mips_opts
.isa
)
2720 && (! cop_interlocks
2721 && prev_prev_insn
.insn_mo
->pinfo
& INSN_WRITE_COND_CODE
))
2722 || (! hilo_interlocks
2723 && ((prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_HI
)
2724 || (prev_prev_insn
.insn_mo
->pinfo
& INSN_READ_LO
))))
2726 /* Itbl support may require additional care here. */
2727 if (! prev_prev_insn_unreordered
)
2731 if (mips_fix_4122_bugs
&& prev_insn
.insn_mo
->name
)
2734 const char *pn
= prev_insn
.insn_mo
->name
;
2735 if (strncmp(pn
, "macc", 4) == 0
2736 || strncmp(pn
, "dmacc", 5) == 0
2737 || strncmp(pn
, "dmult", 5) == 0)
2741 if (nops
< min_nops
)
2747 struct insn_label_list
*l
;
2751 /* Record the frag which holds the nop instructions, so
2752 that we can remove them if we don't need them. */
2753 frag_grow (mips_opts
.mips16
? nops
* 2 : nops
* 4);
2754 prev_nop_frag
= frag_now
;
2755 prev_nop_frag_holds
= nops
;
2756 prev_nop_frag_required
= 0;
2757 prev_nop_frag_since
= 0;
2760 for (; nops
> 0; --nops
)
2765 /* Move on to a new frag, so that it is safe to simply
2766 decrease the size of prev_nop_frag. */
2767 frag_wane (frag_now
);
2771 for (l
= insn_labels
; l
!= NULL
; l
= l
->next
)
2775 assert (S_GET_SEGMENT (l
->label
) == now_seg
);
2776 symbol_set_frag (l
->label
, frag_now
);
2777 val
= (valueT
) frag_now_fix ();
2778 /* mips16 text labels are stored as odd. */
2779 if (mips_opts
.mips16
)
2781 S_SET_VALUE (l
->label
, val
);
2786 /* Mark instruction labels in mips16 mode. */
2788 mips16_mark_labels ();
2790 mips_no_prev_insn (insns
);
2793 /* Build an instruction created by a macro expansion. This is passed
2794 a pointer to the count of instructions created so far, an
2795 expression, the name of the instruction to build, an operand format
2796 string, and corresponding arguments. */
2799 macro_build (char *place
, int *counter
, expressionS
*ep
, const char *name
,
2800 const char *fmt
, ...)
2802 struct mips_cl_insn insn
;
2803 bfd_reloc_code_real_type r
[3];
2806 va_start (args
, fmt
);
2809 * If the macro is about to expand into a second instruction,
2810 * print a warning if needed. We need to pass ip as a parameter
2811 * to generate a better warning message here...
2813 if (mips_opts
.warn_about_macros
&& place
== NULL
&& *counter
== 1)
2814 as_warn (_("Macro instruction expanded into multiple instructions"));
2817 * If the macro is about to expand into a second instruction,
2818 * and it is in a delay slot, print a warning.
2822 && mips_opts
.noreorder
2823 && (prev_prev_insn
.insn_mo
->pinfo
2824 & (INSN_UNCOND_BRANCH_DELAY
| INSN_COND_BRANCH_DELAY
2825 | INSN_COND_BRANCH_LIKELY
)) != 0)
2826 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2829 ++*counter
; /* bump instruction counter */
2831 if (mips_opts
.mips16
)
2833 mips16_macro_build (place
, counter
, ep
, name
, fmt
, args
);
2838 r
[0] = BFD_RELOC_UNUSED
;
2839 r
[1] = BFD_RELOC_UNUSED
;
2840 r
[2] = BFD_RELOC_UNUSED
;
2841 insn
.insn_mo
= (struct mips_opcode
*) hash_find (op_hash
, name
);
2842 assert (insn
.insn_mo
);
2843 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
2845 /* Search until we get a match for NAME. */
2848 /* It is assumed here that macros will never generate
2849 MDMX or MIPS-3D instructions. */
2850 if (strcmp (fmt
, insn
.insn_mo
->args
) == 0
2851 && insn
.insn_mo
->pinfo
!= INSN_MACRO
2852 && OPCODE_IS_MEMBER (insn
.insn_mo
,
2854 | (file_ase_mips16
? INSN_MIPS16
: 0)),
2856 && (mips_opts
.arch
!= CPU_R4650
|| (insn
.insn_mo
->pinfo
& FP_D
) == 0))
2860 assert (insn
.insn_mo
->name
);
2861 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
2864 insn
.insn_opcode
= insn
.insn_mo
->match
;
2880 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RT
;
2884 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE
;
2889 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FT
;
2895 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RD
;
2900 int tmp
= va_arg (args
, int);
2902 insn
.insn_opcode
|= tmp
<< OP_SH_RT
;
2903 insn
.insn_opcode
|= tmp
<< OP_SH_RD
;
2909 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FS
;
2916 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_SHAMT
;
2920 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_FD
;
2924 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE20
;
2928 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE19
;
2932 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_CODE2
;
2939 insn
.insn_opcode
|= va_arg (args
, int) << OP_SH_RS
;
2945 *r
= (bfd_reloc_code_real_type
) va_arg (args
, int);
2946 assert (*r
== BFD_RELOC_GPREL16
2947 || *r
== BFD_RELOC_MIPS_LITERAL
2948 || *r
== BFD_RELOC_MIPS_HIGHER
2949 || *r
== BFD_RELOC_HI16_S
2950 || *r
== BFD_RELOC_LO16
2951 || *r
== BFD_RELOC_MIPS_GOT16
2952 || *r
== BFD_RELOC_MIPS_CALL16
2953 || *r
== BFD_RELOC_MIPS_GOT_DISP
2954 || *r
== BFD_RELOC_MIPS_GOT_PAGE
2955 || *r
== BFD_RELOC_MIPS_GOT_OFST
2956 || *r
== BFD_RELOC_MIPS_GOT_LO16
2957 || *r
== BFD_RELOC_MIPS_CALL_LO16
2958 || (ep
->X_op
== O_subtract
2959 && *r
== BFD_RELOC_PCREL_LO16
));
2963 *r
= (bfd_reloc_code_real_type
) va_arg (args
, int);
2965 && (ep
->X_op
== O_constant
2966 || (ep
->X_op
== O_symbol
2967 && (*r
== BFD_RELOC_MIPS_HIGHEST
2968 || *r
== BFD_RELOC_HI16_S
2969 || *r
== BFD_RELOC_HI16
2970 || *r
== BFD_RELOC_GPREL16
2971 || *r
== BFD_RELOC_MIPS_GOT_HI16
2972 || *r
== BFD_RELOC_MIPS_CALL_HI16
))
2973 || (ep
->X_op
== O_subtract
2974 && *r
== BFD_RELOC_PCREL_HI16_S
)));
2978 assert (ep
!= NULL
);
2980 * This allows macro() to pass an immediate expression for
2981 * creating short branches without creating a symbol.
2982 * Note that the expression still might come from the assembly
2983 * input, in which case the value is not checked for range nor
2984 * is a relocation entry generated (yuck).
2986 if (ep
->X_op
== O_constant
)
2988 insn
.insn_opcode
|= (ep
->X_add_number
>> 2) & 0xffff;
2992 *r
= BFD_RELOC_16_PCREL_S2
;
2996 assert (ep
!= NULL
);
2997 *r
= BFD_RELOC_MIPS_JMP
;
3001 insn
.insn_opcode
|= va_arg (args
, unsigned long);
3010 assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3012 append_insn (place
, &insn
, ep
, r
);
3016 mips16_macro_build (char *place
, int *counter ATTRIBUTE_UNUSED
,
3017 expressionS
*ep
, const char *name
, const char *fmt
,
3020 struct mips_cl_insn insn
;
3021 bfd_reloc_code_real_type r
[3]
3022 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3024 insn
.insn_mo
= (struct mips_opcode
*) hash_find (mips16_op_hash
, name
);
3025 assert (insn
.insn_mo
);
3026 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
3028 while (strcmp (fmt
, insn
.insn_mo
->args
) != 0
3029 || insn
.insn_mo
->pinfo
== INSN_MACRO
)
3032 assert (insn
.insn_mo
->name
);
3033 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
3036 insn
.insn_opcode
= insn
.insn_mo
->match
;
3037 insn
.use_extend
= FALSE
;
3056 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RY
;
3061 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RX
;
3065 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_RZ
;
3069 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_MOVE32Z
;
3079 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_REGR32
;
3086 regno
= va_arg (args
, int);
3087 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
3088 insn
.insn_opcode
|= regno
<< MIPS16OP_SH_REG32R
;
3109 assert (ep
!= NULL
);
3111 if (ep
->X_op
!= O_constant
)
3112 *r
= (int) BFD_RELOC_UNUSED
+ c
;
3115 mips16_immed (NULL
, 0, c
, ep
->X_add_number
, FALSE
, FALSE
,
3116 FALSE
, &insn
.insn_opcode
, &insn
.use_extend
,
3119 *r
= BFD_RELOC_UNUSED
;
3125 insn
.insn_opcode
|= va_arg (args
, int) << MIPS16OP_SH_IMM6
;
3132 assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3134 append_insn (place
, &insn
, ep
, r
);
3138 * Generate a "jalr" instruction with a relocation hint to the called
3139 * function. This occurs in NewABI PIC code.
3142 macro_build_jalr (int icnt
, expressionS
*ep
)
3151 macro_build (NULL
, &icnt
, NULL
, "jalr", "d,s", RA
, PIC_CALL_REG
);
3153 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
,
3154 4, ep
, FALSE
, BFD_RELOC_MIPS_JALR
);
3158 * Generate a "lui" instruction.
3161 macro_build_lui (char *place
, int *counter
, expressionS
*ep
, int regnum
)
3163 expressionS high_expr
;
3164 struct mips_cl_insn insn
;
3165 bfd_reloc_code_real_type r
[3]
3166 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3167 const char *name
= "lui";
3168 const char *fmt
= "t,u";
3170 assert (! mips_opts
.mips16
);
3176 high_expr
.X_op
= O_constant
;
3177 high_expr
.X_add_number
= ep
->X_add_number
;
3180 if (high_expr
.X_op
== O_constant
)
3182 /* we can compute the instruction now without a relocation entry */
3183 high_expr
.X_add_number
= ((high_expr
.X_add_number
+ 0x8000)
3185 *r
= BFD_RELOC_UNUSED
;
3189 assert (ep
->X_op
== O_symbol
);
3190 /* _gp_disp is a special case, used from s_cpload. */
3191 assert (mips_pic
== NO_PIC
3193 && strcmp (S_GET_NAME (ep
->X_add_symbol
), "_gp_disp") == 0));
3194 *r
= BFD_RELOC_HI16_S
;
3198 * If the macro is about to expand into a second instruction,
3199 * print a warning if needed. We need to pass ip as a parameter
3200 * to generate a better warning message here...
3202 if (mips_opts
.warn_about_macros
&& place
== NULL
&& *counter
== 1)
3203 as_warn (_("Macro instruction expanded into multiple instructions"));
3206 ++*counter
; /* bump instruction counter */
3208 insn
.insn_mo
= (struct mips_opcode
*) hash_find (op_hash
, name
);
3209 assert (insn
.insn_mo
);
3210 assert (strcmp (name
, insn
.insn_mo
->name
) == 0);
3211 assert (strcmp (fmt
, insn
.insn_mo
->args
) == 0);
3213 insn
.insn_opcode
= insn
.insn_mo
->match
| (regnum
<< OP_SH_RT
);
3214 if (*r
== BFD_RELOC_UNUSED
)
3216 insn
.insn_opcode
|= high_expr
.X_add_number
;
3217 append_insn (place
, &insn
, NULL
, r
);
3220 append_insn (place
, &insn
, &high_expr
, r
);
3223 /* Generate a sequence of instructions to do a load or store from a constant
3224 offset off of a base register (breg) into/from a target register (treg),
3225 using AT if necessary. */
3227 macro_build_ldst_constoffset (char *place
, int *counter
, expressionS
*ep
,
3228 const char *op
, int treg
, int breg
)
3230 assert (ep
->X_op
== O_constant
);
3232 /* Right now, this routine can only handle signed 32-bit contants. */
3233 if (! IS_SEXT_32BIT_NUM(ep
->X_add_number
))
3234 as_warn (_("operand overflow"));
3236 if (IS_SEXT_16BIT_NUM(ep
->X_add_number
))
3238 /* Signed 16-bit offset will fit in the op. Easy! */
3239 macro_build (place
, counter
, ep
, op
, "t,o(b)", treg
, BFD_RELOC_LO16
,
3244 /* 32-bit offset, need multiple instructions and AT, like:
3245 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3246 addu $tempreg,$tempreg,$breg
3247 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3248 to handle the complete offset. */
3249 macro_build_lui (place
, counter
, ep
, AT
);
3252 macro_build (place
, counter
, NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
,
3256 macro_build (place
, counter
, ep
, op
, "t,o(b)", treg
, BFD_RELOC_LO16
,
3260 as_warn (_("Macro used $at after \".set noat\""));
3265 * Generates code to set the $at register to true (one)
3266 * if reg is less than the immediate expression.
3269 set_at (int *counter
, int reg
, int unsignedp
)
3271 if (imm_expr
.X_op
== O_constant
3272 && imm_expr
.X_add_number
>= -0x8000
3273 && imm_expr
.X_add_number
< 0x8000)
3274 macro_build (NULL
, counter
, &imm_expr
, unsignedp
? "sltiu" : "slti",
3275 "t,r,j", AT
, reg
, BFD_RELOC_LO16
);
3278 load_register (counter
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
3279 macro_build (NULL
, counter
, NULL
, unsignedp
? "sltu" : "slt",
3280 "d,v,t", AT
, reg
, AT
);
3284 /* Warn if an expression is not a constant. */
3287 check_absolute_expr (struct mips_cl_insn
*ip
, expressionS
*ex
)
3289 if (ex
->X_op
== O_big
)
3290 as_bad (_("unsupported large constant"));
3291 else if (ex
->X_op
!= O_constant
)
3292 as_bad (_("Instruction %s requires absolute expression"), ip
->insn_mo
->name
);
3295 /* Count the leading zeroes by performing a binary chop. This is a
3296 bulky bit of source, but performance is a LOT better for the
3297 majority of values than a simple loop to count the bits:
3298 for (lcnt = 0; (lcnt < 32); lcnt++)
3299 if ((v) & (1 << (31 - lcnt)))
3301 However it is not code size friendly, and the gain will drop a bit
3302 on certain cached systems.
3304 #define COUNT_TOP_ZEROES(v) \
3305 (((v) & ~0xffff) == 0 \
3306 ? ((v) & ~0xff) == 0 \
3307 ? ((v) & ~0xf) == 0 \
3308 ? ((v) & ~0x3) == 0 \
3309 ? ((v) & ~0x1) == 0 \
3314 : ((v) & ~0x7) == 0 \
3317 : ((v) & ~0x3f) == 0 \
3318 ? ((v) & ~0x1f) == 0 \
3321 : ((v) & ~0x7f) == 0 \
3324 : ((v) & ~0xfff) == 0 \
3325 ? ((v) & ~0x3ff) == 0 \
3326 ? ((v) & ~0x1ff) == 0 \
3329 : ((v) & ~0x7ff) == 0 \
3332 : ((v) & ~0x3fff) == 0 \
3333 ? ((v) & ~0x1fff) == 0 \
3336 : ((v) & ~0x7fff) == 0 \
3339 : ((v) & ~0xffffff) == 0 \
3340 ? ((v) & ~0xfffff) == 0 \
3341 ? ((v) & ~0x3ffff) == 0 \
3342 ? ((v) & ~0x1ffff) == 0 \
3345 : ((v) & ~0x7ffff) == 0 \
3348 : ((v) & ~0x3fffff) == 0 \
3349 ? ((v) & ~0x1fffff) == 0 \
3352 : ((v) & ~0x7fffff) == 0 \
3355 : ((v) & ~0xfffffff) == 0 \
3356 ? ((v) & ~0x3ffffff) == 0 \
3357 ? ((v) & ~0x1ffffff) == 0 \
3360 : ((v) & ~0x7ffffff) == 0 \
3363 : ((v) & ~0x3fffffff) == 0 \
3364 ? ((v) & ~0x1fffffff) == 0 \
3367 : ((v) & ~0x7fffffff) == 0 \
3372 * This routine generates the least number of instructions neccessary to load
3373 * an absolute expression value into a register.
3376 load_register (int *counter
, int reg
, expressionS
*ep
, int dbl
)
3379 expressionS hi32
, lo32
;
3381 if (ep
->X_op
!= O_big
)
3383 assert (ep
->X_op
== O_constant
);
3384 if (ep
->X_add_number
< 0x8000
3385 && (ep
->X_add_number
>= 0
3386 || (ep
->X_add_number
>= -0x8000
3389 || sizeof (ep
->X_add_number
) > 4))))
3391 /* We can handle 16 bit signed values with an addiu to
3392 $zero. No need to ever use daddiu here, since $zero and
3393 the result are always correct in 32 bit mode. */
3394 macro_build (NULL
, counter
, ep
, "addiu", "t,r,j", reg
, 0,
3398 else if (ep
->X_add_number
>= 0 && ep
->X_add_number
< 0x10000)
3400 /* We can handle 16 bit unsigned values with an ori to
3402 macro_build (NULL
, counter
, ep
, "ori", "t,r,i", reg
, 0,
3406 else if ((IS_SEXT_32BIT_NUM (ep
->X_add_number
)
3409 || sizeof (ep
->X_add_number
) > 4
3410 || (ep
->X_add_number
& 0x80000000) == 0))
3411 || ((HAVE_32BIT_GPRS
|| ! dbl
)
3412 && (ep
->X_add_number
&~ (offsetT
) 0xffffffff) == 0)
3415 && ((ep
->X_add_number
&~ (offsetT
) 0xffffffff)
3416 == ~ (offsetT
) 0xffffffff)))
3418 /* 32 bit values require an lui. */
3419 macro_build (NULL
, counter
, ep
, "lui", "t,u", reg
, BFD_RELOC_HI16
);
3420 if ((ep
->X_add_number
& 0xffff) != 0)
3421 macro_build (NULL
, counter
, ep
, "ori", "t,r,i", reg
, reg
,
3427 /* The value is larger than 32 bits. */
3429 if (HAVE_32BIT_GPRS
)
3431 as_bad (_("Number (0x%lx) larger than 32 bits"),
3432 (unsigned long) ep
->X_add_number
);
3433 macro_build (NULL
, counter
, ep
, "addiu", "t,r,j", reg
, 0,
3438 if (ep
->X_op
!= O_big
)
3441 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
3442 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
3443 hi32
.X_add_number
&= 0xffffffff;
3445 lo32
.X_add_number
&= 0xffffffff;
3449 assert (ep
->X_add_number
> 2);
3450 if (ep
->X_add_number
== 3)
3451 generic_bignum
[3] = 0;
3452 else if (ep
->X_add_number
> 4)
3453 as_bad (_("Number larger than 64 bits"));
3454 lo32
.X_op
= O_constant
;
3455 lo32
.X_add_number
= generic_bignum
[0] + (generic_bignum
[1] << 16);
3456 hi32
.X_op
= O_constant
;
3457 hi32
.X_add_number
= generic_bignum
[2] + (generic_bignum
[3] << 16);
3460 if (hi32
.X_add_number
== 0)
3465 unsigned long hi
, lo
;
3467 if (hi32
.X_add_number
== (offsetT
) 0xffffffff)
3469 if ((lo32
.X_add_number
& 0xffff8000) == 0xffff8000)
3471 macro_build (NULL
, counter
, &lo32
, "addiu", "t,r,j", reg
, 0,
3475 if (lo32
.X_add_number
& 0x80000000)
3477 macro_build (NULL
, counter
, &lo32
, "lui", "t,u", reg
,
3479 if (lo32
.X_add_number
& 0xffff)
3480 macro_build (NULL
, counter
, &lo32
, "ori", "t,r,i", reg
, reg
,
3486 /* Check for 16bit shifted constant. We know that hi32 is
3487 non-zero, so start the mask on the first bit of the hi32
3492 unsigned long himask
, lomask
;
3496 himask
= 0xffff >> (32 - shift
);
3497 lomask
= (0xffff << shift
) & 0xffffffff;
3501 himask
= 0xffff << (shift
- 32);
3504 if ((hi32
.X_add_number
& ~(offsetT
) himask
) == 0
3505 && (lo32
.X_add_number
& ~(offsetT
) lomask
) == 0)
3509 tmp
.X_op
= O_constant
;
3511 tmp
.X_add_number
= ((hi32
.X_add_number
<< (32 - shift
))
3512 | (lo32
.X_add_number
>> shift
));
3514 tmp
.X_add_number
= hi32
.X_add_number
>> (shift
- 32);
3515 macro_build (NULL
, counter
, &tmp
, "ori", "t,r,i", reg
, 0,
3517 macro_build (NULL
, counter
, NULL
,
3518 (shift
>= 32) ? "dsll32" : "dsll",
3520 (shift
>= 32) ? shift
- 32 : shift
);
3525 while (shift
<= (64 - 16));
3527 /* Find the bit number of the lowest one bit, and store the
3528 shifted value in hi/lo. */
3529 hi
= (unsigned long) (hi32
.X_add_number
& 0xffffffff);
3530 lo
= (unsigned long) (lo32
.X_add_number
& 0xffffffff);
3534 while ((lo
& 1) == 0)
3539 lo
|= (hi
& (((unsigned long) 1 << bit
) - 1)) << (32 - bit
);
3545 while ((hi
& 1) == 0)
3554 /* Optimize if the shifted value is a (power of 2) - 1. */
3555 if ((hi
== 0 && ((lo
+ 1) & lo
) == 0)
3556 || (lo
== 0xffffffff && ((hi
+ 1) & hi
) == 0))
3558 shift
= COUNT_TOP_ZEROES ((unsigned int) hi32
.X_add_number
);
3563 /* This instruction will set the register to be all
3565 tmp
.X_op
= O_constant
;
3566 tmp
.X_add_number
= (offsetT
) -1;
3567 macro_build (NULL
, counter
, &tmp
, "addiu", "t,r,j", reg
, 0,
3572 macro_build (NULL
, counter
, NULL
,
3573 (bit
>= 32) ? "dsll32" : "dsll",
3575 (bit
>= 32) ? bit
- 32 : bit
);
3577 macro_build (NULL
, counter
, NULL
,
3578 (shift
>= 32) ? "dsrl32" : "dsrl",
3580 (shift
>= 32) ? shift
- 32 : shift
);
3585 /* Sign extend hi32 before calling load_register, because we can
3586 generally get better code when we load a sign extended value. */
3587 if ((hi32
.X_add_number
& 0x80000000) != 0)
3588 hi32
.X_add_number
|= ~(offsetT
) 0xffffffff;
3589 load_register (counter
, reg
, &hi32
, 0);
3592 if ((lo32
.X_add_number
& 0xffff0000) == 0)
3596 macro_build (NULL
, counter
, NULL
, "dsll32", "d,w,<", reg
, freg
, 0);
3604 if ((freg
== 0) && (lo32
.X_add_number
== (offsetT
) 0xffffffff))
3606 macro_build (NULL
, counter
, &lo32
, "lui", "t,u", reg
,
3608 macro_build (NULL
, counter
, NULL
, "dsrl32", "d,w,<", reg
, reg
, 0);
3614 macro_build (NULL
, counter
, NULL
, "dsll", "d,w,<", reg
, freg
, 16);
3618 mid16
.X_add_number
>>= 16;
3619 macro_build (NULL
, counter
, &mid16
, "ori", "t,r,i", reg
, freg
,
3621 macro_build (NULL
, counter
, NULL
, "dsll", "d,w,<", reg
, reg
, 16);
3624 if ((lo32
.X_add_number
& 0xffff) != 0)
3625 macro_build (NULL
, counter
, &lo32
, "ori", "t,r,i", reg
, freg
,
3629 /* Load an address into a register. */
3632 load_address (int *counter
, int reg
, expressionS
*ep
, int *used_at
)
3636 if (ep
->X_op
!= O_constant
3637 && ep
->X_op
!= O_symbol
)
3639 as_bad (_("expression too complex"));
3640 ep
->X_op
= O_constant
;
3643 if (ep
->X_op
== O_constant
)
3645 load_register (counter
, reg
, ep
, HAVE_64BIT_ADDRESSES
);
3649 if (mips_pic
== NO_PIC
)
3651 /* If this is a reference to a GP relative symbol, we want
3652 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3654 lui $reg,<sym> (BFD_RELOC_HI16_S)
3655 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3656 If we have an addend, we always use the latter form.
3658 With 64bit address space and a usable $at we want
3659 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3660 lui $at,<sym> (BFD_RELOC_HI16_S)
3661 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3662 daddiu $at,<sym> (BFD_RELOC_LO16)
3666 If $at is already in use, we use a path which is suboptimal
3667 on superscalar processors.
3668 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3669 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3671 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3673 daddiu $reg,<sym> (BFD_RELOC_LO16)
3675 if (HAVE_64BIT_ADDRESSES
)
3677 /* We don't do GP optimization for now because RELAX_ENCODE can't
3678 hold the data for such large chunks. */
3680 if (*used_at
== 0 && ! mips_opts
.noat
)
3682 macro_build (p
, counter
, ep
, "lui", "t,u",
3683 reg
, BFD_RELOC_MIPS_HIGHEST
);
3684 macro_build (p
, counter
, ep
, "lui", "t,u",
3685 AT
, BFD_RELOC_HI16_S
);
3686 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3687 reg
, reg
, BFD_RELOC_MIPS_HIGHER
);
3688 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3689 AT
, AT
, BFD_RELOC_LO16
);
3690 macro_build (p
, counter
, NULL
, "dsll32", "d,w,<", reg
, reg
, 0);
3691 macro_build (p
, counter
, NULL
, "daddu", "d,v,t", reg
, reg
, AT
);
3696 macro_build (p
, counter
, ep
, "lui", "t,u",
3697 reg
, BFD_RELOC_MIPS_HIGHEST
);
3698 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3699 reg
, reg
, BFD_RELOC_MIPS_HIGHER
);
3700 macro_build (p
, counter
, NULL
, "dsll", "d,w,<", reg
, reg
, 16);
3701 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3702 reg
, reg
, BFD_RELOC_HI16_S
);
3703 macro_build (p
, counter
, NULL
, "dsll", "d,w,<", reg
, reg
, 16);
3704 macro_build (p
, counter
, ep
, "daddiu", "t,r,j",
3705 reg
, reg
, BFD_RELOC_LO16
);
3710 if ((valueT
) ep
->X_add_number
<= MAX_GPREL_OFFSET
3711 && ! nopic_need_relax (ep
->X_add_symbol
, 1))
3714 macro_build (NULL
, counter
, ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
,
3715 mips_gp_register
, BFD_RELOC_GPREL16
);
3716 p
= frag_var (rs_machine_dependent
, 8, 0,
3717 RELAX_ENCODE (4, 8, 0, 4, 0,
3718 mips_opts
.warn_about_macros
),
3719 ep
->X_add_symbol
, 0, NULL
);
3721 macro_build_lui (p
, counter
, ep
, reg
);
3724 macro_build (p
, counter
, ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
3728 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
3732 /* If this is a reference to an external symbol, we want
3733 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3735 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3737 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3738 If there is a constant, it must be added in after.
3740 If we have NewABI, we want
3741 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
3742 unless we're referencing a global symbol with a non-zero
3743 offset, in which case cst must be added separately. */
3748 if (ep
->X_add_number
)
3750 frag_now
->tc_frag_data
.tc_fr_offset
=
3751 ex
.X_add_number
= ep
->X_add_number
;
3752 ep
->X_add_number
= 0;
3753 macro_build (NULL
, counter
, ep
, ADDRESS_LOAD_INSN
, "t,o(b)",
3754 reg
, BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
3755 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
3756 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3757 ex
.X_op
= O_constant
;
3758 macro_build (NULL
, counter
, &ex
, ADDRESS_ADDI_INSN
, "t,r,j",
3759 reg
, reg
, BFD_RELOC_LO16
);
3760 p
= frag_var (rs_machine_dependent
, 8, 0,
3761 RELAX_ENCODE (8, 4, 0, 0, 0,
3762 mips_opts
.warn_about_macros
),
3763 ep
->X_add_symbol
, 0, NULL
);
3764 ep
->X_add_number
= ex
.X_add_number
;
3767 macro_build (p
, counter
, ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
3768 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
3772 /* To avoid confusion in tc_gen_reloc, we must ensure
3773 that this does not become a variant frag. */
3774 frag_wane (frag_now
);
3780 ex
.X_add_number
= ep
->X_add_number
;
3781 ep
->X_add_number
= 0;
3783 macro_build (NULL
, counter
, ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
3784 BFD_RELOC_MIPS_GOT16
,
3786 macro_build (NULL
, counter
, NULL
, "nop", "");
3787 p
= frag_var (rs_machine_dependent
, 4, 0,
3788 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts
.warn_about_macros
),
3789 ep
->X_add_symbol
, 0, NULL
);
3790 macro_build (p
, counter
, ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
3793 if (ex
.X_add_number
!= 0)
3795 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
3796 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3797 ex
.X_op
= O_constant
;
3798 macro_build (NULL
, counter
, &ex
, ADDRESS_ADDI_INSN
, "t,r,j",
3799 reg
, reg
, BFD_RELOC_LO16
);
3803 else if (mips_pic
== SVR4_PIC
)
3808 /* This is the large GOT case. If this is a reference to an
3809 external symbol, we want
3810 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3812 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3814 Otherwise, for a reference to a local symbol in old ABI, we want
3815 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3817 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3818 If there is a constant, it must be added in after.
3820 In the NewABI, for local symbols, with or without offsets, we want:
3821 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3822 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3828 frag_now
->tc_frag_data
.tc_fr_offset
=
3829 ex
.X_add_number
= ep
->X_add_number
;
3830 ep
->X_add_number
= 0;
3831 macro_build (NULL
, counter
, ep
, "lui", "t,u", reg
,
3832 BFD_RELOC_MIPS_GOT_HI16
);
3833 macro_build (NULL
, counter
, NULL
, ADDRESS_ADD_INSN
, "d,v,t", reg
,
3834 reg
, mips_gp_register
);
3835 macro_build (NULL
, counter
, ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
3836 BFD_RELOC_MIPS_GOT_LO16
, reg
);
3837 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
3838 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3839 else if (ex
.X_add_number
)
3841 ex
.X_op
= O_constant
;
3842 macro_build (NULL
, counter
, &ex
, ADDRESS_ADDI_INSN
, "t,r,j",
3843 reg
, reg
, BFD_RELOC_LO16
);
3846 ep
->X_add_number
= ex
.X_add_number
;
3847 p
= frag_var (rs_machine_dependent
, 8, 0,
3848 RELAX_ENCODE (ex
.X_add_number
? 16 : 12, 8, 0, 4, 0,
3849 mips_opts
.warn_about_macros
),
3850 ep
->X_add_symbol
, 0, NULL
);
3851 macro_build (p
, counter
, ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
3852 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
3853 macro_build (p
+ 4, counter
, ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
,
3854 reg
, BFD_RELOC_MIPS_GOT_OFST
);
3858 ex
.X_add_number
= ep
->X_add_number
;
3859 ep
->X_add_number
= 0;
3860 if (reg_needs_delay (mips_gp_register
))
3865 macro_build (NULL
, counter
, ep
, "lui", "t,u", reg
,
3866 BFD_RELOC_MIPS_GOT_HI16
);
3867 macro_build (NULL
, counter
, NULL
, ADDRESS_ADD_INSN
, "d,v,t", reg
,
3868 reg
, mips_gp_register
);
3869 macro_build (NULL
, counter
, ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
3870 BFD_RELOC_MIPS_GOT_LO16
, reg
);
3871 p
= frag_var (rs_machine_dependent
, 12 + off
, 0,
3872 RELAX_ENCODE (12, 12 + off
, off
, 8 + off
, 0,
3873 mips_opts
.warn_about_macros
),
3874 ep
->X_add_symbol
, 0, NULL
);
3877 /* We need a nop before loading from $gp. This special
3878 check is required because the lui which starts the main
3879 instruction stream does not refer to $gp, and so will not
3880 insert the nop which may be required. */
3881 macro_build (p
, counter
, NULL
, "nop", "");
3884 macro_build (p
, counter
, ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
3885 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
3887 macro_build (p
, counter
, NULL
, "nop", "");
3889 macro_build (p
, counter
, ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
3892 if (ex
.X_add_number
!= 0)
3894 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
3895 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3896 ex
.X_op
= O_constant
;
3897 macro_build (NULL
, counter
, &ex
, ADDRESS_ADDI_INSN
, "t,r,j",
3898 reg
, reg
, BFD_RELOC_LO16
);
3902 else if (mips_pic
== EMBEDDED_PIC
)
3905 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3907 macro_build (NULL
, counter
, ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
,
3908 mips_gp_register
, BFD_RELOC_GPREL16
);
3914 /* Move the contents of register SOURCE into register DEST. */
3917 move_register (int *counter
, int dest
, int source
)
3919 macro_build (NULL
, counter
, NULL
, HAVE_32BIT_GPRS
? "addu" : "daddu",
3920 "d,v,t", dest
, source
, 0);
3925 * This routine implements the seemingly endless macro or synthesized
3926 * instructions and addressing modes in the mips assembly language. Many
3927 * of these macros are simple and are similar to each other. These could
3928 * probably be handled by some kind of table or grammer aproach instead of
3929 * this verbose method. Others are not simple macros but are more like
3930 * optimizing code generation.
3931 * One interesting optimization is when several store macros appear
3932 * consecutivly that would load AT with the upper half of the same address.
3933 * The ensuing load upper instructions are ommited. This implies some kind
3934 * of global optimization. We currently only optimize within a single macro.
3935 * For many of the load and store macros if the address is specified as a
3936 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3937 * first load register 'at' with zero and use it as the base register. The
3938 * mips assembler simply uses register $zero. Just one tiny optimization
3942 macro (struct mips_cl_insn
*ip
)
3944 register int treg
, sreg
, dreg
, breg
;
3960 bfd_reloc_code_real_type r
;
3961 int hold_mips_optimize
;
3963 assert (! mips_opts
.mips16
);
3965 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
3966 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
3967 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
3968 mask
= ip
->insn_mo
->mask
;
3970 expr1
.X_op
= O_constant
;
3971 expr1
.X_op_symbol
= NULL
;
3972 expr1
.X_add_symbol
= NULL
;
3973 expr1
.X_add_number
= 1;
3975 /* Umatched fixups should not be put in the same frag as a relaxable
3976 macro. For example, suppose we have:
3980 addiu $4,$4,%lo(l1) # 3
3982 If instructions 1 and 2 were put in the same frag, md_frob_file would
3983 move the fixup for #1 after the fixups for the "unrelaxed" version of
3984 #2. This would confuse tc_gen_reloc, which expects the relocations
3985 for #2 to be the last for that frag.
3987 Also, if tc_gen_reloc sees certain relocations in a variant frag,
3988 it assumes that they belong to a relaxable macro. We mustn't put
3989 other uses of such relocations into a variant frag.
3991 To avoid both problems, finish the current frag it contains a
3992 %reloc() operator. The macro then goes into a new frag. */
3993 if (prev_reloc_op_frag
== frag_now
)
3995 frag_wane (frag_now
);
4009 mips_emit_delays (TRUE
);
4010 ++mips_opts
.noreorder
;
4011 mips_any_noreorder
= 1;
4013 expr1
.X_add_number
= 8;
4014 macro_build (NULL
, &icnt
, &expr1
, "bgez", "s,p", sreg
);
4016 macro_build (NULL
, &icnt
, NULL
, "nop", "", 0);
4018 move_register (&icnt
, dreg
, sreg
);
4019 macro_build (NULL
, &icnt
, NULL
, dbl
? "dsub" : "sub", "d,v,t", dreg
, 0,
4022 --mips_opts
.noreorder
;
4043 if (imm_expr
.X_op
== O_constant
4044 && imm_expr
.X_add_number
>= -0x8000
4045 && imm_expr
.X_add_number
< 0x8000)
4047 macro_build (NULL
, &icnt
, &imm_expr
, s
, "t,r,j", treg
, sreg
,
4051 load_register (&icnt
, AT
, &imm_expr
, dbl
);
4052 macro_build (NULL
, &icnt
, NULL
, s2
, "d,v,t", treg
, sreg
, AT
);
4071 if (imm_expr
.X_op
== O_constant
4072 && imm_expr
.X_add_number
>= 0
4073 && imm_expr
.X_add_number
< 0x10000)
4075 if (mask
!= M_NOR_I
)
4076 macro_build (NULL
, &icnt
, &imm_expr
, s
, "t,r,i", treg
, sreg
,
4080 macro_build (NULL
, &icnt
, &imm_expr
, "ori", "t,r,i", treg
, sreg
,
4082 macro_build (NULL
, &icnt
, NULL
, "nor", "d,v,t", treg
, treg
, 0);
4087 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4088 macro_build (NULL
, &icnt
, NULL
, s2
, "d,v,t", treg
, sreg
, AT
);
4105 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4107 macro_build (NULL
, &icnt
, &offset_expr
, s
, "s,t,p", sreg
, 0);
4110 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4111 macro_build (NULL
, &icnt
, &offset_expr
, s
, "s,t,p", sreg
, AT
);
4119 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bgezl" : "bgez",
4125 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "blezl" : "blez",
4129 macro_build (NULL
, &icnt
, NULL
, "slt", "d,v,t", AT
, sreg
, treg
);
4130 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4137 /* check for > max integer */
4138 maxnum
= 0x7fffffff;
4139 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4146 if (imm_expr
.X_op
== O_constant
4147 && imm_expr
.X_add_number
>= maxnum
4148 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4151 /* result is always false */
4155 as_warn (_("Branch %s is always false (nop)"),
4157 macro_build (NULL
, &icnt
, NULL
, "nop", "", 0);
4162 as_warn (_("Branch likely %s is always false"),
4164 macro_build (NULL
, &icnt
, &offset_expr
, "bnel", "s,t,p", 0, 0);
4168 if (imm_expr
.X_op
!= O_constant
)
4169 as_bad (_("Unsupported large constant"));
4170 ++imm_expr
.X_add_number
;
4174 if (mask
== M_BGEL_I
)
4176 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4178 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bgezl" : "bgez",
4182 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4184 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bgtzl" : "bgtz",
4188 maxnum
= 0x7fffffff;
4189 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4196 maxnum
= - maxnum
- 1;
4197 if (imm_expr
.X_op
== O_constant
4198 && imm_expr
.X_add_number
<= maxnum
4199 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4202 /* result is always true */
4203 as_warn (_("Branch %s is always true"), ip
->insn_mo
->name
);
4204 macro_build (NULL
, &icnt
, &offset_expr
, "b", "p");
4207 set_at (&icnt
, sreg
, 0);
4208 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4219 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4223 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", AT
, sreg
, treg
);
4224 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4233 && imm_expr
.X_op
== O_constant
4234 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
4236 if (imm_expr
.X_op
!= O_constant
)
4237 as_bad (_("Unsupported large constant"));
4238 ++imm_expr
.X_add_number
;
4242 if (mask
== M_BGEUL_I
)
4244 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4246 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4248 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4252 set_at (&icnt
, sreg
, 1);
4253 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4262 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bgtzl" : "bgtz",
4268 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bltzl" : "bltz",
4272 macro_build (NULL
, &icnt
, NULL
, "slt", "d,v,t", AT
, treg
, sreg
);
4273 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4282 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4288 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", AT
, treg
, sreg
);
4289 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4298 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "blezl" : "blez",
4304 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bgezl" : "bgez",
4308 macro_build (NULL
, &icnt
, NULL
, "slt", "d,v,t", AT
, treg
, sreg
);
4309 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4316 maxnum
= 0x7fffffff;
4317 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4324 if (imm_expr
.X_op
== O_constant
4325 && imm_expr
.X_add_number
>= maxnum
4326 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4328 if (imm_expr
.X_op
!= O_constant
)
4329 as_bad (_("Unsupported large constant"));
4330 ++imm_expr
.X_add_number
;
4334 if (mask
== M_BLTL_I
)
4336 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4338 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bltzl" : "bltz",
4342 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4344 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "blezl" : "blez",
4348 set_at (&icnt
, sreg
, 0);
4349 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4358 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4364 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", AT
, treg
, sreg
);
4365 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4374 && imm_expr
.X_op
== O_constant
4375 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
4377 if (imm_expr
.X_op
!= O_constant
)
4378 as_bad (_("Unsupported large constant"));
4379 ++imm_expr
.X_add_number
;
4383 if (mask
== M_BLTUL_I
)
4385 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4387 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4389 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "beql" : "beq",
4393 set_at (&icnt
, sreg
, 1);
4394 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4403 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bltzl" : "bltz",
4409 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bgtzl" : "bgtz",
4413 macro_build (NULL
, &icnt
, NULL
, "slt", "d,v,t", AT
, sreg
, treg
);
4414 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4425 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4429 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", AT
, sreg
, treg
);
4430 macro_build (NULL
, &icnt
, &offset_expr
, likely
? "bnel" : "bne",
4446 as_warn (_("Divide by zero."));
4448 macro_build (NULL
, &icnt
, NULL
, "teq", "s,t,q", 0, 0, 7);
4450 macro_build (NULL
, &icnt
, NULL
, "break", "c", 7);
4454 mips_emit_delays (TRUE
);
4455 ++mips_opts
.noreorder
;
4456 mips_any_noreorder
= 1;
4459 macro_build (NULL
, &icnt
, NULL
, "teq", "s,t,q", treg
, 0, 7);
4460 macro_build (NULL
, &icnt
, NULL
, dbl
? "ddiv" : "div", "z,s,t",
4465 expr1
.X_add_number
= 8;
4466 macro_build (NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, 0);
4467 macro_build (NULL
, &icnt
, NULL
, dbl
? "ddiv" : "div", "z,s,t",
4469 macro_build (NULL
, &icnt
,NULL
, "break", "c", 7);
4471 expr1
.X_add_number
= -1;
4472 macro_build (NULL
, &icnt
, &expr1
, dbl
? "daddiu" : "addiu", "t,r,j",
4473 AT
, 0, BFD_RELOC_LO16
);
4474 expr1
.X_add_number
= mips_trap
? (dbl
? 12 : 8) : (dbl
? 20 : 16);
4475 macro_build (NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, AT
);
4478 expr1
.X_add_number
= 1;
4479 macro_build (NULL
, &icnt
, &expr1
, "daddiu", "t,r,j", AT
, 0,
4481 macro_build (NULL
, &icnt
, NULL
, "dsll32", "d,w,<", AT
, AT
, 31);
4485 expr1
.X_add_number
= 0x80000000;
4486 macro_build (NULL
, &icnt
, &expr1
, "lui", "t,u", AT
,
4491 macro_build (NULL
, &icnt
, NULL
, "teq", "s,t,q", sreg
, AT
, 6);
4492 /* We want to close the noreorder block as soon as possible, so
4493 that later insns are available for delay slot filling. */
4494 --mips_opts
.noreorder
;
4498 expr1
.X_add_number
= 8;
4499 macro_build (NULL
, &icnt
, &expr1
, "bne", "s,t,p", sreg
, AT
);
4500 macro_build (NULL
, &icnt
, NULL
, "nop", "", 0);
4502 /* We want to close the noreorder block as soon as possible, so
4503 that later insns are available for delay slot filling. */
4504 --mips_opts
.noreorder
;
4506 macro_build (NULL
, &icnt
, NULL
, "break", "c", 6);
4508 macro_build (NULL
, &icnt
, NULL
, s
, "d", dreg
);
4547 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4549 as_warn (_("Divide by zero."));
4551 macro_build (NULL
, &icnt
, NULL
, "teq", "s,t,q", 0, 0, 7);
4553 macro_build (NULL
, &icnt
, NULL
, "break", "c", 7);
4556 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4558 if (strcmp (s2
, "mflo") == 0)
4559 move_register (&icnt
, dreg
, sreg
);
4561 move_register (&icnt
, dreg
, 0);
4564 if (imm_expr
.X_op
== O_constant
4565 && imm_expr
.X_add_number
== -1
4566 && s
[strlen (s
) - 1] != 'u')
4568 if (strcmp (s2
, "mflo") == 0)
4570 macro_build (NULL
, &icnt
, NULL
, dbl
? "dneg" : "neg", "d,w",
4574 move_register (&icnt
, dreg
, 0);
4578 load_register (&icnt
, AT
, &imm_expr
, dbl
);
4579 macro_build (NULL
, &icnt
, NULL
, s
, "z,s,t", sreg
, AT
);
4580 macro_build (NULL
, &icnt
, NULL
, s2
, "d", dreg
);
4599 mips_emit_delays (TRUE
);
4600 ++mips_opts
.noreorder
;
4601 mips_any_noreorder
= 1;
4604 macro_build (NULL
, &icnt
, NULL
, "teq", "s,t,q", treg
, 0, 7);
4605 macro_build (NULL
, &icnt
, NULL
, s
, "z,s,t", sreg
, treg
);
4606 /* We want to close the noreorder block as soon as possible, so
4607 that later insns are available for delay slot filling. */
4608 --mips_opts
.noreorder
;
4612 expr1
.X_add_number
= 8;
4613 macro_build (NULL
, &icnt
, &expr1
, "bne", "s,t,p", treg
, 0);
4614 macro_build (NULL
, &icnt
, NULL
, s
, "z,s,t", sreg
, treg
);
4616 /* We want to close the noreorder block as soon as possible, so
4617 that later insns are available for delay slot filling. */
4618 --mips_opts
.noreorder
;
4619 macro_build (NULL
, &icnt
, NULL
, "break", "c", 7);
4621 macro_build (NULL
, &icnt
, NULL
, s2
, "d", dreg
);
4627 /* Load the address of a symbol into a register. If breg is not
4628 zero, we then add a base register to it. */
4630 if (dbl
&& HAVE_32BIT_GPRS
)
4631 as_warn (_("dla used to load 32-bit register"));
4633 if (! dbl
&& HAVE_64BIT_OBJECTS
)
4634 as_warn (_("la used to load 64-bit address"));
4636 if (offset_expr
.X_op
== O_constant
4637 && offset_expr
.X_add_number
>= -0x8000
4638 && offset_expr
.X_add_number
< 0x8000)
4640 macro_build (NULL
, &icnt
, &offset_expr
,
4641 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddiu" : "addiu",
4642 "t,r,j", treg
, sreg
, BFD_RELOC_LO16
);
4657 /* When generating embedded PIC code, we permit expressions of
4660 la $treg,foo-bar($breg)
4661 where bar is an address in the current section. These are used
4662 when getting the addresses of functions. We don't permit
4663 X_add_number to be non-zero, because if the symbol is
4664 external the relaxing code needs to know that any addend is
4665 purely the offset to X_op_symbol. */
4666 if (mips_pic
== EMBEDDED_PIC
4667 && offset_expr
.X_op
== O_subtract
4668 && (symbol_constant_p (offset_expr
.X_op_symbol
)
4669 ? S_GET_SEGMENT (offset_expr
.X_op_symbol
) == now_seg
4670 : (symbol_equated_p (offset_expr
.X_op_symbol
)
4672 (symbol_get_value_expression (offset_expr
.X_op_symbol
)
4675 && (offset_expr
.X_add_number
== 0
4676 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
))
4682 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u", tempreg
,
4683 BFD_RELOC_PCREL_HI16_S
);
4687 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u", tempreg
,
4688 BFD_RELOC_PCREL_HI16_S
);
4689 macro_build (NULL
, &icnt
, NULL
,
4690 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddu" : "addu",
4691 "d,v,t", tempreg
, tempreg
, breg
);
4693 macro_build (NULL
, &icnt
, &offset_expr
,
4694 (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddiu" : "addiu",
4695 "t,r,j", treg
, tempreg
, BFD_RELOC_PCREL_LO16
);
4701 if (offset_expr
.X_op
!= O_symbol
4702 && offset_expr
.X_op
!= O_constant
)
4704 as_bad (_("expression too complex"));
4705 offset_expr
.X_op
= O_constant
;
4708 if (offset_expr
.X_op
== O_constant
)
4709 load_register (&icnt
, tempreg
, &offset_expr
,
4710 ((mips_pic
== EMBEDDED_PIC
|| mips_pic
== NO_PIC
)
4711 ? (dbl
|| HAVE_64BIT_ADDRESSES
)
4712 : HAVE_64BIT_ADDRESSES
));
4713 else if (mips_pic
== NO_PIC
)
4715 /* If this is a reference to a GP relative symbol, we want
4716 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4718 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4719 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4720 If we have a constant, we need two instructions anyhow,
4721 so we may as well always use the latter form.
4723 With 64bit address space and a usable $at we want
4724 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4725 lui $at,<sym> (BFD_RELOC_HI16_S)
4726 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4727 daddiu $at,<sym> (BFD_RELOC_LO16)
4729 daddu $tempreg,$tempreg,$at
4731 If $at is already in use, we use a path which is suboptimal
4732 on superscalar processors.
4733 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4734 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4736 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4738 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4741 if (HAVE_64BIT_ADDRESSES
)
4743 /* We don't do GP optimization for now because RELAX_ENCODE can't
4744 hold the data for such large chunks. */
4746 if (used_at
== 0 && ! mips_opts
.noat
)
4748 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4749 tempreg
, BFD_RELOC_MIPS_HIGHEST
);
4750 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4751 AT
, BFD_RELOC_HI16_S
);
4752 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4753 tempreg
, tempreg
, BFD_RELOC_MIPS_HIGHER
);
4754 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4755 AT
, AT
, BFD_RELOC_LO16
);
4756 macro_build (p
, &icnt
, NULL
, "dsll32", "d,w,<",
4757 tempreg
, tempreg
, 0);
4758 macro_build (p
, &icnt
, NULL
, "daddu", "d,v,t",
4759 tempreg
, tempreg
, AT
);
4764 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
4765 tempreg
, BFD_RELOC_MIPS_HIGHEST
);
4766 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4767 tempreg
, tempreg
, BFD_RELOC_MIPS_HIGHER
);
4768 macro_build (p
, &icnt
, NULL
, "dsll", "d,w,<",
4769 tempreg
, tempreg
, 16);
4770 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4771 tempreg
, tempreg
, BFD_RELOC_HI16_S
);
4772 macro_build (p
, &icnt
, NULL
, "dsll", "d,w,<",
4773 tempreg
, tempreg
, 16);
4774 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
4775 tempreg
, tempreg
, BFD_RELOC_LO16
);
4780 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
4781 && ! nopic_need_relax (offset_expr
.X_add_symbol
, 1))
4784 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
,
4785 "t,r,j", tempreg
, mips_gp_register
,
4787 p
= frag_var (rs_machine_dependent
, 8, 0,
4788 RELAX_ENCODE (4, 8, 0, 4, 0,
4789 mips_opts
.warn_about_macros
),
4790 offset_expr
.X_add_symbol
, 0, NULL
);
4792 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
4795 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
,
4796 "t,r,j", tempreg
, tempreg
, BFD_RELOC_LO16
);
4799 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
&& ! HAVE_NEWABI
)
4801 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
4803 /* If this is a reference to an external symbol, and there
4804 is no constant, we want
4805 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4806 or if tempreg is PIC_CALL_REG
4807 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4808 For a local symbol, we want
4809 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4811 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4813 If we have a small constant, and this is a reference to
4814 an external symbol, we want
4815 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4817 addiu $tempreg,$tempreg,<constant>
4818 For a local symbol, we want the same instruction
4819 sequence, but we output a BFD_RELOC_LO16 reloc on the
4822 If we have a large constant, and this is a reference to
4823 an external symbol, we want
4824 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4825 lui $at,<hiconstant>
4826 addiu $at,$at,<loconstant>
4827 addu $tempreg,$tempreg,$at
4828 For a local symbol, we want the same instruction
4829 sequence, but we output a BFD_RELOC_LO16 reloc on the
4833 expr1
.X_add_number
= offset_expr
.X_add_number
;
4834 offset_expr
.X_add_number
= 0;
4836 if (expr1
.X_add_number
== 0 && tempreg
== PIC_CALL_REG
)
4837 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL16
;
4838 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
4839 tempreg
, lw_reloc_type
, mips_gp_register
);
4840 if (expr1
.X_add_number
== 0)
4849 /* We're going to put in an addu instruction using
4850 tempreg, so we may as well insert the nop right
4852 macro_build (NULL
, &icnt
, NULL
, "nop", "");
4855 p
= frag_var (rs_machine_dependent
, 8 - off
, 0,
4856 RELAX_ENCODE (0, 8 - off
, -4 - off
, 4 - off
, 0,
4858 ? mips_opts
.warn_about_macros
4860 offset_expr
.X_add_symbol
, 0, NULL
);
4863 macro_build (p
, &icnt
, NULL
, "nop", "");
4866 macro_build (p
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
,
4867 "t,r,j", tempreg
, tempreg
, BFD_RELOC_LO16
);
4868 /* FIXME: If breg == 0, and the next instruction uses
4869 $tempreg, then if this variant case is used an extra
4870 nop will be generated. */
4872 else if (expr1
.X_add_number
>= -0x8000
4873 && expr1
.X_add_number
< 0x8000)
4875 macro_build (NULL
, &icnt
, NULL
, "nop", "");
4876 macro_build (NULL
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
,
4877 "t,r,j", tempreg
, tempreg
, BFD_RELOC_LO16
);
4878 frag_var (rs_machine_dependent
, 0, 0,
4879 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4880 offset_expr
.X_add_symbol
, 0, NULL
);
4886 /* If we are going to add in a base register, and the
4887 target register and the base register are the same,
4888 then we are using AT as a temporary register. Since
4889 we want to load the constant into AT, we add our
4890 current AT (from the global offset table) and the
4891 register into the register now, and pretend we were
4892 not using a base register. */
4897 macro_build (NULL
, &icnt
, NULL
, "nop", "");
4898 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
4905 /* Set mips_optimize around the lui instruction to avoid
4906 inserting an unnecessary nop after the lw. */
4907 hold_mips_optimize
= mips_optimize
;
4909 macro_build_lui (NULL
, &icnt
, &expr1
, AT
);
4910 mips_optimize
= hold_mips_optimize
;
4912 macro_build (NULL
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
4913 AT
, AT
, BFD_RELOC_LO16
);
4914 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
4915 tempreg
, tempreg
, AT
);
4916 frag_var (rs_machine_dependent
, 0, 0,
4917 RELAX_ENCODE (0, 0, -16 + off1
, -8, 0, 0),
4918 offset_expr
.X_add_symbol
, 0, NULL
);
4922 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
&& HAVE_NEWABI
)
4925 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_DISP
;
4928 /* If this is a reference to an external, and there is no
4929 constant, or local symbol (*), with or without a
4931 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4932 or if tempreg is PIC_CALL_REG
4933 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4935 If we have a small constant, and this is a reference to
4936 an external symbol, we want
4937 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4938 addiu $tempreg,$tempreg,<constant>
4940 If we have a large constant, and this is a reference to
4941 an external symbol, we want
4942 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4943 lui $at,<hiconstant>
4944 addiu $at,$at,<loconstant>
4945 addu $tempreg,$tempreg,$at
4947 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
4948 local symbols, even though it introduces an additional
4952 if (offset_expr
.X_add_number
== 0 && tempreg
== PIC_CALL_REG
)
4953 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL16
;
4954 if (offset_expr
.X_add_number
)
4956 frag_now
->tc_frag_data
.tc_fr_offset
=
4957 expr1
.X_add_number
= offset_expr
.X_add_number
;
4958 offset_expr
.X_add_number
= 0;
4960 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
4961 "t,o(b)", tempreg
, lw_reloc_type
,
4964 if (expr1
.X_add_number
>= -0x8000
4965 && expr1
.X_add_number
< 0x8000)
4967 macro_build (NULL
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
,
4968 "t,r,j", tempreg
, tempreg
, BFD_RELOC_LO16
);
4969 p
= frag_var (rs_machine_dependent
, 4, 0,
4970 RELAX_ENCODE (8, 4, 0, 0, 0, 0),
4971 offset_expr
.X_add_symbol
, 0, NULL
);
4973 else if (IS_SEXT_32BIT_NUM (expr1
.X_add_number
))
4977 /* If we are going to add in a base register, and the
4978 target register and the base register are the same,
4979 then we are using AT as a temporary register. Since
4980 we want to load the constant into AT, we add our
4981 current AT (from the global offset table) and the
4982 register into the register now, and pretend we were
4983 not using a base register. */
4988 assert (tempreg
== AT
);
4989 macro_build (NULL
, &icnt
,NULL
, ADDRESS_ADD_INSN
,
4990 "d,v,t", treg
, AT
, breg
);
4995 macro_build_lui (NULL
, &icnt
, &expr1
, AT
);
4996 macro_build (NULL
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
,
4997 "t,r,j", AT
, AT
, BFD_RELOC_LO16
);
4998 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5001 p
= frag_var (rs_machine_dependent
, 4 + adj
, 0,
5002 RELAX_ENCODE (16 + adj
, 4 + adj
,
5004 offset_expr
.X_add_symbol
, 0, NULL
);
5009 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5011 offset_expr
.X_add_number
= expr1
.X_add_number
;
5013 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5014 "t,o(b)", tempreg
, BFD_RELOC_MIPS_GOT_DISP
,
5018 macro_build (p
+ 4, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5019 treg
, tempreg
, breg
);
5026 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5027 "t,o(b)", tempreg
, lw_reloc_type
,
5029 if (lw_reloc_type
!= BFD_RELOC_MIPS_GOT_DISP
)
5030 p
= frag_var (rs_machine_dependent
, 0, 0,
5031 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5032 offset_expr
.X_add_symbol
, 0, NULL
);
5037 /* To avoid confusion in tc_gen_reloc, we must ensure
5038 that this does not become a variant frag. */
5039 frag_wane (frag_now
);
5043 else if (mips_pic
== SVR4_PIC
&& ! HAVE_NEWABI
)
5047 int lui_reloc_type
= (int) BFD_RELOC_MIPS_GOT_HI16
;
5048 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_LO16
;
5049 int local_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
5051 /* This is the large GOT case. If this is a reference to an
5052 external symbol, and there is no constant, we want
5053 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5054 addu $tempreg,$tempreg,$gp
5055 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5056 or if tempreg is PIC_CALL_REG
5057 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5058 addu $tempreg,$tempreg,$gp
5059 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5060 For a local symbol, we want
5061 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5063 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5065 If we have a small constant, and this is a reference to
5066 an external symbol, we want
5067 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5068 addu $tempreg,$tempreg,$gp
5069 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5071 addiu $tempreg,$tempreg,<constant>
5072 For a local symbol, we want
5073 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5075 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5077 If we have a large constant, and this is a reference to
5078 an external symbol, we want
5079 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5080 addu $tempreg,$tempreg,$gp
5081 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5082 lui $at,<hiconstant>
5083 addiu $at,$at,<loconstant>
5084 addu $tempreg,$tempreg,$at
5085 For a local symbol, we want
5086 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5087 lui $at,<hiconstant>
5088 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5089 addu $tempreg,$tempreg,$at
5092 expr1
.X_add_number
= offset_expr
.X_add_number
;
5093 offset_expr
.X_add_number
= 0;
5095 if (reg_needs_delay (mips_gp_register
))
5099 if (expr1
.X_add_number
== 0 && tempreg
== PIC_CALL_REG
)
5101 lui_reloc_type
= (int) BFD_RELOC_MIPS_CALL_HI16
;
5102 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL_LO16
;
5104 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5105 tempreg
, lui_reloc_type
);
5106 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5107 tempreg
, tempreg
, mips_gp_register
);
5108 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5109 tempreg
, lw_reloc_type
, tempreg
);
5110 if (expr1
.X_add_number
== 0)
5118 /* We're going to put in an addu instruction using
5119 tempreg, so we may as well insert the nop right
5121 macro_build (NULL
, &icnt
, NULL
, "nop", "");
5125 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5126 RELAX_ENCODE (12 + off
, 12 + gpdel
, gpdel
,
5129 ? mips_opts
.warn_about_macros
5131 offset_expr
.X_add_symbol
, 0, NULL
);
5133 else if (expr1
.X_add_number
>= -0x8000
5134 && expr1
.X_add_number
< 0x8000)
5136 macro_build (NULL
, &icnt
, NULL
, "nop", "");
5137 macro_build (NULL
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5138 tempreg
, tempreg
, BFD_RELOC_LO16
);
5140 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5141 RELAX_ENCODE (20, 12 + gpdel
, gpdel
, 8 + gpdel
, 0,
5143 ? mips_opts
.warn_about_macros
5145 offset_expr
.X_add_symbol
, 0, NULL
);
5151 /* If we are going to add in a base register, and the
5152 target register and the base register are the same,
5153 then we are using AT as a temporary register. Since
5154 we want to load the constant into AT, we add our
5155 current AT (from the global offset table) and the
5156 register into the register now, and pretend we were
5157 not using a base register. */
5165 assert (tempreg
== AT
);
5166 macro_build (NULL
, &icnt
, NULL
, "nop", "");
5167 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5173 /* Set mips_optimize around the lui instruction to avoid
5174 inserting an unnecessary nop after the lw. */
5175 hold_mips_optimize
= mips_optimize
;
5177 macro_build_lui (NULL
, &icnt
, &expr1
, AT
);
5178 mips_optimize
= hold_mips_optimize
;
5180 macro_build (NULL
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5181 AT
, AT
, BFD_RELOC_LO16
);
5182 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5185 p
= frag_var (rs_machine_dependent
, 16 + gpdel
+ adj
, 0,
5186 RELAX_ENCODE (24 + adj
, 16 + gpdel
+ adj
, gpdel
,
5189 ? mips_opts
.warn_about_macros
5191 offset_expr
.X_add_symbol
, 0, NULL
);
5198 /* This is needed because this instruction uses $gp, but
5199 the first instruction on the main stream does not. */
5200 macro_build (p
, &icnt
, NULL
, "nop", "");
5204 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5205 tempreg
, local_reloc_type
, mips_gp_register
);
5207 if (expr1
.X_add_number
>= -0x8000
5208 && expr1
.X_add_number
< 0x8000)
5210 macro_build (p
, &icnt
, NULL
, "nop", "");
5212 macro_build (p
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
,
5213 "t,r,j", tempreg
, tempreg
, BFD_RELOC_LO16
);
5214 /* FIXME: If add_number is 0, and there was no base
5215 register, the external symbol case ended with a load,
5216 so if the symbol turns out to not be external, and
5217 the next instruction uses tempreg, an unnecessary nop
5218 will be inserted. */
5224 /* We must add in the base register now, as in the
5225 external symbol case. */
5226 assert (tempreg
== AT
);
5227 macro_build (p
, &icnt
, NULL
, "nop", "");
5229 macro_build (p
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5233 /* We set breg to 0 because we have arranged to add
5234 it in in both cases. */
5238 macro_build_lui (p
, &icnt
, &expr1
, AT
);
5240 macro_build (p
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5241 AT
, AT
, BFD_RELOC_LO16
);
5243 macro_build (p
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5244 tempreg
, tempreg
, AT
);
5248 else if (mips_pic
== SVR4_PIC
&& HAVE_NEWABI
)
5251 int lui_reloc_type
= (int) BFD_RELOC_MIPS_GOT_HI16
;
5252 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_LO16
;
5255 /* This is the large GOT case. If this is a reference to an
5256 external symbol, and there is no constant, we want
5257 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5258 add $tempreg,$tempreg,$gp
5259 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5260 or if tempreg is PIC_CALL_REG
5261 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5262 add $tempreg,$tempreg,$gp
5263 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5265 If we have a small constant, and this is a reference to
5266 an external symbol, we want
5267 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5268 add $tempreg,$tempreg,$gp
5269 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5270 addi $tempreg,$tempreg,<constant>
5272 If we have a large constant, and this is a reference to
5273 an external symbol, we want
5274 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5275 addu $tempreg,$tempreg,$gp
5276 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5277 lui $at,<hiconstant>
5278 addi $at,$at,<loconstant>
5279 add $tempreg,$tempreg,$at
5281 If we have NewABI, and we know it's a local symbol, we want
5282 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5283 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5284 otherwise we have to resort to GOT_HI16/GOT_LO16. */
5288 frag_now
->tc_frag_data
.tc_fr_offset
=
5289 expr1
.X_add_number
= offset_expr
.X_add_number
;
5290 offset_expr
.X_add_number
= 0;
5292 if (expr1
.X_add_number
== 0 && tempreg
== PIC_CALL_REG
)
5294 lui_reloc_type
= (int) BFD_RELOC_MIPS_CALL_HI16
;
5295 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL_LO16
;
5297 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5298 tempreg
, lui_reloc_type
);
5299 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5300 tempreg
, tempreg
, mips_gp_register
);
5301 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5302 "t,o(b)", tempreg
, lw_reloc_type
, tempreg
);
5304 if (expr1
.X_add_number
== 0)
5306 p
= frag_var (rs_machine_dependent
, 8, 0,
5307 RELAX_ENCODE (12, 8, 0, 4, 0,
5308 mips_opts
.warn_about_macros
),
5309 offset_expr
.X_add_symbol
, 0, NULL
);
5311 else if (expr1
.X_add_number
>= -0x8000
5312 && expr1
.X_add_number
< 0x8000)
5314 macro_build (NULL
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5315 tempreg
, tempreg
, BFD_RELOC_LO16
);
5316 p
= frag_var (rs_machine_dependent
, 8, 0,
5317 RELAX_ENCODE (16, 8, 0, 4, 0,
5318 mips_opts
.warn_about_macros
),
5319 offset_expr
.X_add_symbol
, 0, NULL
);
5321 else if (IS_SEXT_32BIT_NUM (expr1
.X_add_number
))
5325 /* If we are going to add in a base register, and the
5326 target register and the base register are the same,
5327 then we are using AT as a temporary register. Since
5328 we want to load the constant into AT, we add our
5329 current AT (from the global offset table) and the
5330 register into the register now, and pretend we were
5331 not using a base register. */
5336 assert (tempreg
== AT
);
5337 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5343 /* Set mips_optimize around the lui instruction to avoid
5344 inserting an unnecessary nop after the lw. */
5345 macro_build_lui (NULL
, &icnt
, &expr1
, AT
);
5346 macro_build (NULL
, &icnt
, &expr1
, ADDRESS_ADDI_INSN
,
5347 "t,r,j", AT
, AT
, BFD_RELOC_LO16
);
5348 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5351 p
= frag_var (rs_machine_dependent
, 8 + adj
, 0,
5352 RELAX_ENCODE (24 + adj
, 8 + adj
,
5355 ? mips_opts
.warn_about_macros
5357 offset_expr
.X_add_symbol
, 0, NULL
);
5362 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5364 offset_expr
.X_add_number
= expr1
.X_add_number
;
5365 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5366 tempreg
, BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
5367 macro_build (p
+ 4, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5368 tempreg
, tempreg
, BFD_RELOC_MIPS_GOT_OFST
);
5371 macro_build (p
+ 8, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5372 treg
, tempreg
, breg
);
5377 else if (mips_pic
== EMBEDDED_PIC
)
5380 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5382 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5383 tempreg
, mips_gp_register
, BFD_RELOC_GPREL16
);
5392 if (mips_pic
== EMBEDDED_PIC
|| mips_pic
== NO_PIC
)
5393 s
= (dbl
|| HAVE_64BIT_ADDRESSES
) ? "daddu" : "addu";
5395 s
= ADDRESS_ADD_INSN
;
5397 macro_build (NULL
, &icnt
, NULL
, s
, "d,v,t", treg
, tempreg
, breg
);
5406 /* The j instruction may not be used in PIC code, since it
5407 requires an absolute address. We convert it to a b
5409 if (mips_pic
== NO_PIC
)
5410 macro_build (NULL
, &icnt
, &offset_expr
, "j", "a");
5412 macro_build (NULL
, &icnt
, &offset_expr
, "b", "p");
5415 /* The jal instructions must be handled as macros because when
5416 generating PIC code they expand to multi-instruction
5417 sequences. Normally they are simple instructions. */
5422 if (mips_pic
== NO_PIC
5423 || mips_pic
== EMBEDDED_PIC
)
5424 macro_build (NULL
, &icnt
, NULL
, "jalr", "d,s", dreg
, sreg
);
5425 else if (mips_pic
== SVR4_PIC
)
5427 if (sreg
!= PIC_CALL_REG
)
5428 as_warn (_("MIPS PIC call to register other than $25"));
5430 macro_build (NULL
, &icnt
, NULL
, "jalr", "d,s", dreg
, sreg
);
5433 if (mips_cprestore_offset
< 0)
5434 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5437 if (! mips_frame_reg_valid
)
5439 as_warn (_("No .frame pseudo-op used in PIC code"));
5440 /* Quiet this warning. */
5441 mips_frame_reg_valid
= 1;
5443 if (! mips_cprestore_valid
)
5445 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5446 /* Quiet this warning. */
5447 mips_cprestore_valid
= 1;
5449 expr1
.X_add_number
= mips_cprestore_offset
;
5450 macro_build_ldst_constoffset (NULL
, &icnt
, &expr1
,
5463 if (mips_pic
== NO_PIC
)
5464 macro_build (NULL
, &icnt
, &offset_expr
, "jal", "a");
5465 else if (mips_pic
== SVR4_PIC
)
5469 /* If this is a reference to an external symbol, and we are
5470 using a small GOT, we want
5471 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5475 lw $gp,cprestore($sp)
5476 The cprestore value is set using the .cprestore
5477 pseudo-op. If we are using a big GOT, we want
5478 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5480 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5484 lw $gp,cprestore($sp)
5485 If the symbol is not external, we want
5486 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5488 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5491 lw $gp,cprestore($sp)
5493 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
5494 sequences above, minus nops, unless the symbol is local,
5495 which enables us to use GOT_PAGE/GOT_OFST (big got) or
5502 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5503 "t,o(b)", PIC_CALL_REG
, BFD_RELOC_MIPS_CALL16
,
5505 frag_var (rs_machine_dependent
, 0, 0,
5506 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5507 offset_expr
.X_add_symbol
, 0, NULL
);
5512 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5513 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL_HI16
);
5514 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5515 PIC_CALL_REG
, PIC_CALL_REG
, mips_gp_register
);
5516 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5517 "t,o(b)", PIC_CALL_REG
,
5518 BFD_RELOC_MIPS_CALL_LO16
, PIC_CALL_REG
);
5519 p
= frag_var (rs_machine_dependent
, 8, 0,
5520 RELAX_ENCODE (12, 8, 0, 4, 0, 0),
5521 offset_expr
.X_add_symbol
, 0, NULL
);
5522 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5523 "t,o(b)", PIC_CALL_REG
,
5524 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
5525 macro_build (p
+ 4, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
,
5526 "t,r,j", PIC_CALL_REG
, PIC_CALL_REG
,
5527 BFD_RELOC_MIPS_GOT_OFST
);
5530 macro_build_jalr (icnt
, &offset_expr
);
5537 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5538 "t,o(b)", PIC_CALL_REG
, BFD_RELOC_MIPS_CALL16
,
5540 macro_build (NULL
, &icnt
, NULL
, "nop", "");
5541 p
= frag_var (rs_machine_dependent
, 4, 0,
5542 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5543 offset_expr
.X_add_symbol
, 0, NULL
);
5549 if (reg_needs_delay (mips_gp_register
))
5553 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u",
5554 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL_HI16
);
5555 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5556 PIC_CALL_REG
, PIC_CALL_REG
, mips_gp_register
);
5557 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5558 "t,o(b)", PIC_CALL_REG
,
5559 BFD_RELOC_MIPS_CALL_LO16
, PIC_CALL_REG
);
5560 macro_build (NULL
, &icnt
, NULL
, "nop", "");
5561 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
5562 RELAX_ENCODE (16, 12 + gpdel
, gpdel
,
5564 offset_expr
.X_add_symbol
, 0, NULL
);
5567 macro_build (p
, &icnt
, NULL
, "nop", "");
5570 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
5571 "t,o(b)", PIC_CALL_REG
, BFD_RELOC_MIPS_GOT16
,
5574 macro_build (p
, &icnt
, NULL
, "nop", "");
5577 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
,
5578 "t,r,j", PIC_CALL_REG
, PIC_CALL_REG
,
5580 macro_build_jalr (icnt
, &offset_expr
);
5582 if (mips_cprestore_offset
< 0)
5583 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5586 if (! mips_frame_reg_valid
)
5588 as_warn (_("No .frame pseudo-op used in PIC code"));
5589 /* Quiet this warning. */
5590 mips_frame_reg_valid
= 1;
5592 if (! mips_cprestore_valid
)
5594 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5595 /* Quiet this warning. */
5596 mips_cprestore_valid
= 1;
5598 if (mips_opts
.noreorder
)
5599 macro_build (NULL
, &icnt
, NULL
, "nop", "");
5600 expr1
.X_add_number
= mips_cprestore_offset
;
5601 macro_build_ldst_constoffset (NULL
, &icnt
, &expr1
,
5608 else if (mips_pic
== EMBEDDED_PIC
)
5610 macro_build (NULL
, &icnt
, &offset_expr
, "bal", "p");
5611 /* The linker may expand the call to a longer sequence which
5612 uses $at, so we must break rather than return. */
5637 /* Itbl support may require additional care here. */
5642 /* Itbl support may require additional care here. */
5647 /* Itbl support may require additional care here. */
5652 /* Itbl support may require additional care here. */
5664 if (mips_opts
.arch
== CPU_R4650
)
5666 as_bad (_("opcode not supported on this processor"));
5670 /* Itbl support may require additional care here. */
5675 /* Itbl support may require additional care here. */
5680 /* Itbl support may require additional care here. */
5700 if (breg
== treg
|| coproc
|| lr
)
5722 /* Itbl support may require additional care here. */
5727 /* Itbl support may require additional care here. */
5732 /* Itbl support may require additional care here. */
5737 /* Itbl support may require additional care here. */
5753 if (mips_opts
.arch
== CPU_R4650
)
5755 as_bad (_("opcode not supported on this processor"));
5760 /* Itbl support may require additional care here. */
5764 /* Itbl support may require additional care here. */
5769 /* Itbl support may require additional care here. */
5781 /* Itbl support may require additional care here. */
5782 if (mask
== M_LWC1_AB
5783 || mask
== M_SWC1_AB
5784 || mask
== M_LDC1_AB
5785 || mask
== M_SDC1_AB
5794 /* For embedded PIC, we allow loads where the offset is calculated
5795 by subtracting a symbol in the current segment from an unknown
5796 symbol, relative to a base register, e.g.:
5797 <op> $treg, <sym>-<localsym>($breg)
5798 This is used by the compiler for switch statements. */
5799 if (mips_pic
== EMBEDDED_PIC
5800 && offset_expr
.X_op
== O_subtract
5801 && (symbol_constant_p (offset_expr
.X_op_symbol
)
5802 ? S_GET_SEGMENT (offset_expr
.X_op_symbol
) == now_seg
5803 : (symbol_equated_p (offset_expr
.X_op_symbol
)
5805 (symbol_get_value_expression (offset_expr
.X_op_symbol
)
5809 && (offset_expr
.X_add_number
== 0
5810 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
))
5812 /* For this case, we output the instructions:
5813 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5814 addiu $tempreg,$tempreg,$breg
5815 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5816 If the relocation would fit entirely in 16 bits, it would be
5818 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5819 instead, but that seems quite difficult. */
5820 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u", tempreg
,
5821 BFD_RELOC_PCREL_HI16_S
);
5822 macro_build (NULL
, &icnt
, NULL
,
5823 ((bfd_arch_bits_per_address (stdoutput
) == 32
5824 || ! ISA_HAS_64BIT_REGS (mips_opts
.isa
))
5825 ? "addu" : "daddu"),
5826 "d,v,t", tempreg
, tempreg
, breg
);
5827 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5828 BFD_RELOC_PCREL_LO16
, tempreg
);
5834 if (offset_expr
.X_op
!= O_constant
5835 && offset_expr
.X_op
!= O_symbol
)
5837 as_bad (_("expression too complex"));
5838 offset_expr
.X_op
= O_constant
;
5841 /* A constant expression in PIC code can be handled just as it
5842 is in non PIC code. */
5843 if (mips_pic
== NO_PIC
5844 || offset_expr
.X_op
== O_constant
)
5848 /* If this is a reference to a GP relative symbol, and there
5849 is no base register, we want
5850 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5851 Otherwise, if there is no base register, we want
5852 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5853 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5854 If we have a constant, we need two instructions anyhow,
5855 so we always use the latter form.
5857 If we have a base register, and this is a reference to a
5858 GP relative symbol, we want
5859 addu $tempreg,$breg,$gp
5860 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5862 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5863 addu $tempreg,$tempreg,$breg
5864 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5865 With a constant we always use the latter case.
5867 With 64bit address space and no base register and $at usable,
5869 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5870 lui $at,<sym> (BFD_RELOC_HI16_S)
5871 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5874 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5875 If we have a base register, we want
5876 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5877 lui $at,<sym> (BFD_RELOC_HI16_S)
5878 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5882 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5884 Without $at we can't generate the optimal path for superscalar
5885 processors here since this would require two temporary registers.
5886 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5887 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5889 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5891 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5892 If we have a base register, we want
5893 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5894 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5896 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5898 daddu $tempreg,$tempreg,$breg
5899 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5901 If we have 64-bit addresses, as an optimization, for
5902 addresses which are 32-bit constants (e.g. kseg0/kseg1
5903 addresses) we fall back to the 32-bit address generation
5904 mechanism since it is more efficient. Note that due to
5905 the signed offset used by memory operations, the 32-bit
5906 range is shifted down by 32768 here. This code should
5907 probably attempt to generate 64-bit constants more
5908 efficiently in general.
5910 As an extension for architectures with 64-bit registers,
5911 we don't truncate 64-bit addresses given as literal
5912 constants down to 32 bits, to support existing practice
5913 in the mips64 Linux (the kernel), that compiles source
5914 files with -mabi=64, assembling them as o32 or n32 (with
5915 -Wa,-32 or -Wa,-n32). This is not beautiful, but since
5916 the whole kernel is loaded into a memory region that is
5917 addressible with sign-extended 32-bit addresses, it is
5918 wasteful to compute the upper 32 bits of every
5919 non-literal address, that takes more space and time.
5920 Some day this should probably be implemented as an
5921 assembler option, such that the kernel doesn't have to
5922 use such ugly hacks, even though it will still have to
5923 end up converting the binary to ELF32 for a number of
5924 platforms whose boot loaders don't support ELF64
5926 if ((offset_expr
.X_op
!= O_constant
&& HAVE_64BIT_ADDRESSES
)
5927 || (offset_expr
.X_op
== O_constant
5928 && !IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
+ 0x8000)
5929 && HAVE_64BIT_ADDRESS_CONSTANTS
))
5933 /* We don't do GP optimization for now because RELAX_ENCODE can't
5934 hold the data for such large chunks. */
5936 if (used_at
== 0 && ! mips_opts
.noat
)
5938 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5939 tempreg
, BFD_RELOC_MIPS_HIGHEST
);
5940 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5941 AT
, BFD_RELOC_HI16_S
);
5942 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5943 tempreg
, tempreg
, BFD_RELOC_MIPS_HIGHER
);
5945 macro_build (p
, &icnt
, NULL
, "daddu", "d,v,t",
5947 macro_build (p
, &icnt
, NULL
, "dsll32", "d,w,<",
5948 tempreg
, tempreg
, 0);
5949 macro_build (p
, &icnt
, NULL
, "daddu", "d,v,t",
5950 tempreg
, tempreg
, AT
);
5951 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5952 BFD_RELOC_LO16
, tempreg
);
5957 macro_build (p
, &icnt
, &offset_expr
, "lui", "t,u",
5958 tempreg
, BFD_RELOC_MIPS_HIGHEST
);
5959 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5960 tempreg
, tempreg
, BFD_RELOC_MIPS_HIGHER
);
5961 macro_build (p
, &icnt
, NULL
, "dsll", "d,w,<",
5962 tempreg
, tempreg
, 16);
5963 macro_build (p
, &icnt
, &offset_expr
, "daddiu", "t,r,j",
5964 tempreg
, tempreg
, BFD_RELOC_HI16_S
);
5965 macro_build (p
, &icnt
, NULL
, "dsll", "d,w,<",
5966 tempreg
, tempreg
, 16);
5968 macro_build (p
, &icnt
, NULL
, "daddu", "d,v,t",
5969 tempreg
, tempreg
, breg
);
5970 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5971 BFD_RELOC_LO16
, tempreg
);
5976 else if (offset_expr
.X_op
== O_constant
5977 && !HAVE_64BIT_ADDRESS_CONSTANTS
5978 && !IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
))
5979 as_bad (_("load/store address overflow (max 32 bits)"));
5983 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
5984 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5989 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
, treg
,
5990 BFD_RELOC_GPREL16
, mips_gp_register
);
5991 p
= frag_var (rs_machine_dependent
, 8, 0,
5992 RELAX_ENCODE (4, 8, 0, 4, 0,
5993 (mips_opts
.warn_about_macros
5995 && mips_opts
.noat
))),
5996 offset_expr
.X_add_symbol
, 0, NULL
);
5999 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
6002 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
, treg
,
6003 BFD_RELOC_LO16
, tempreg
);
6007 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
6008 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6013 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6014 tempreg
, breg
, mips_gp_register
);
6015 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
, treg
,
6016 BFD_RELOC_GPREL16
, tempreg
);
6017 p
= frag_var (rs_machine_dependent
, 12, 0,
6018 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
6019 offset_expr
.X_add_symbol
, 0, NULL
);
6021 macro_build_lui (p
, &icnt
, &offset_expr
, tempreg
);
6024 macro_build (p
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6025 tempreg
, tempreg
, breg
);
6028 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
, treg
,
6029 BFD_RELOC_LO16
, tempreg
);
6032 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
6035 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
6037 /* If this is a reference to an external symbol, we want
6038 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6040 <op> $treg,0($tempreg)
6042 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6044 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6045 <op> $treg,0($tempreg)
6048 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6049 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6051 If there is a base register, we add it to $tempreg before
6052 the <op>. If there is a constant, we stick it in the
6053 <op> instruction. We don't handle constants larger than
6054 16 bits, because we have no way to load the upper 16 bits
6055 (actually, we could handle them for the subset of cases
6056 in which we are not using $at). */
6057 assert (offset_expr
.X_op
== O_symbol
);
6060 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
6061 "t,o(b)", tempreg
, BFD_RELOC_MIPS_GOT_PAGE
,
6064 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6065 tempreg
, tempreg
, breg
);
6066 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
, treg
,
6067 BFD_RELOC_MIPS_GOT_OFST
, tempreg
);
6074 expr1
.X_add_number
= offset_expr
.X_add_number
;
6075 offset_expr
.X_add_number
= 0;
6076 if (expr1
.X_add_number
< -0x8000
6077 || expr1
.X_add_number
>= 0x8000)
6078 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6080 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6081 tempreg
, lw_reloc_type
, mips_gp_register
);
6082 macro_build (NULL
, &icnt
, NULL
, "nop", "");
6083 p
= frag_var (rs_machine_dependent
, 4, 0,
6084 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
6085 offset_expr
.X_add_symbol
, 0, NULL
);
6086 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
,
6087 "t,r,j", tempreg
, tempreg
, BFD_RELOC_LO16
);
6089 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6090 tempreg
, tempreg
, breg
);
6091 macro_build (NULL
, &icnt
, &expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
,
6094 else if (mips_pic
== SVR4_PIC
&& ! HAVE_NEWABI
)
6099 /* If this is a reference to an external symbol, we want
6100 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6101 addu $tempreg,$tempreg,$gp
6102 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6103 <op> $treg,0($tempreg)
6105 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6107 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6108 <op> $treg,0($tempreg)
6109 If there is a base register, we add it to $tempreg before
6110 the <op>. If there is a constant, we stick it in the
6111 <op> instruction. We don't handle constants larger than
6112 16 bits, because we have no way to load the upper 16 bits
6113 (actually, we could handle them for the subset of cases
6114 in which we are not using $at). */
6115 assert (offset_expr
.X_op
== O_symbol
);
6116 expr1
.X_add_number
= offset_expr
.X_add_number
;
6117 offset_expr
.X_add_number
= 0;
6118 if (expr1
.X_add_number
< -0x8000
6119 || expr1
.X_add_number
>= 0x8000)
6120 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6121 if (reg_needs_delay (mips_gp_register
))
6126 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u", tempreg
,
6127 BFD_RELOC_MIPS_GOT_HI16
);
6128 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6129 tempreg
, tempreg
, mips_gp_register
);
6130 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6131 tempreg
, BFD_RELOC_MIPS_GOT_LO16
, tempreg
);
6132 p
= frag_var (rs_machine_dependent
, 12 + gpdel
, 0,
6133 RELAX_ENCODE (12, 12 + gpdel
, gpdel
, 8 + gpdel
, 0, 0),
6134 offset_expr
.X_add_symbol
, 0, NULL
);
6137 macro_build (p
, &icnt
, NULL
, "nop", "");
6140 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6141 tempreg
, BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6143 macro_build (p
, &icnt
, NULL
, "nop", "");
6145 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
6146 tempreg
, tempreg
, BFD_RELOC_LO16
);
6148 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6149 tempreg
, tempreg
, breg
);
6150 macro_build (NULL
, &icnt
, &expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
,
6153 else if (mips_pic
== SVR4_PIC
&& HAVE_NEWABI
)
6156 int bregsz
= breg
!= 0 ? 4 : 0;
6158 /* If this is a reference to an external symbol, we want
6159 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6160 add $tempreg,$tempreg,$gp
6161 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6162 <op> $treg,<ofst>($tempreg)
6163 Otherwise, for local symbols, we want:
6164 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6165 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6166 assert (offset_expr
.X_op
== O_symbol
);
6167 frag_now
->tc_frag_data
.tc_fr_offset
=
6168 expr1
.X_add_number
= offset_expr
.X_add_number
;
6169 offset_expr
.X_add_number
= 0;
6170 if (expr1
.X_add_number
< -0x8000
6171 || expr1
.X_add_number
>= 0x8000)
6172 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6174 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u", tempreg
,
6175 BFD_RELOC_MIPS_GOT_HI16
);
6176 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6177 tempreg
, tempreg
, mips_gp_register
);
6178 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6179 tempreg
, BFD_RELOC_MIPS_GOT_LO16
, tempreg
);
6181 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6182 tempreg
, tempreg
, breg
);
6183 macro_build (NULL
, &icnt
, &expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
,
6186 offset_expr
.X_add_number
= expr1
.X_add_number
;
6187 p
= frag_var (rs_machine_dependent
, 12 + bregsz
, 0,
6188 RELAX_ENCODE (16 + bregsz
, 8 + bregsz
,
6189 0, 4 + bregsz
, 0, 0),
6190 offset_expr
.X_add_symbol
, 0, NULL
);
6191 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6192 tempreg
, BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
6194 macro_build (p
+ 4, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6195 tempreg
, tempreg
, breg
);
6196 macro_build (p
+ 4 + bregsz
, &icnt
, &offset_expr
, s
, fmt
, treg
,
6197 BFD_RELOC_MIPS_GOT_OFST
, tempreg
);
6199 else if (mips_pic
== EMBEDDED_PIC
)
6201 /* If there is no base register, we want
6202 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6203 If there is a base register, we want
6204 addu $tempreg,$breg,$gp
6205 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6207 assert (offset_expr
.X_op
== O_symbol
);
6210 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
, treg
,
6211 BFD_RELOC_GPREL16
, mips_gp_register
);
6216 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6217 tempreg
, breg
, mips_gp_register
);
6218 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
, treg
,
6219 BFD_RELOC_GPREL16
, tempreg
);
6232 load_register (&icnt
, treg
, &imm_expr
, 0);
6236 load_register (&icnt
, treg
, &imm_expr
, 1);
6240 if (imm_expr
.X_op
== O_constant
)
6242 load_register (&icnt
, AT
, &imm_expr
, 0);
6243 macro_build (NULL
, &icnt
, NULL
, "mtc1", "t,G", AT
, treg
);
6248 assert (offset_expr
.X_op
== O_symbol
6249 && strcmp (segment_name (S_GET_SEGMENT
6250 (offset_expr
.X_add_symbol
)),
6252 && offset_expr
.X_add_number
== 0);
6253 macro_build (NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)", treg
,
6254 BFD_RELOC_MIPS_LITERAL
, mips_gp_register
);
6259 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6260 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6261 order 32 bits of the value and the low order 32 bits are either
6262 zero or in OFFSET_EXPR. */
6263 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
6265 if (HAVE_64BIT_GPRS
)
6266 load_register (&icnt
, treg
, &imm_expr
, 1);
6271 if (target_big_endian
)
6283 load_register (&icnt
, hreg
, &imm_expr
, 0);
6286 if (offset_expr
.X_op
== O_absent
)
6287 move_register (&icnt
, lreg
, 0);
6290 assert (offset_expr
.X_op
== O_constant
);
6291 load_register (&icnt
, lreg
, &offset_expr
, 0);
6298 /* We know that sym is in the .rdata section. First we get the
6299 upper 16 bits of the address. */
6300 if (mips_pic
== NO_PIC
)
6302 macro_build_lui (NULL
, &icnt
, &offset_expr
, AT
);
6304 else if (mips_pic
== SVR4_PIC
)
6306 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6307 AT
, BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6309 else if (mips_pic
== EMBEDDED_PIC
)
6311 /* For embedded PIC we pick up the entire address off $gp in
6312 a single instruction. */
6313 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
6314 AT
, mips_gp_register
, BFD_RELOC_GPREL16
);
6315 offset_expr
.X_op
= O_constant
;
6316 offset_expr
.X_add_number
= 0;
6321 /* Now we load the register(s). */
6322 if (HAVE_64BIT_GPRS
)
6323 macro_build (NULL
, &icnt
, &offset_expr
, "ld", "t,o(b)", treg
,
6324 BFD_RELOC_LO16
, AT
);
6327 macro_build (NULL
, &icnt
, &offset_expr
, "lw", "t,o(b)", treg
,
6328 BFD_RELOC_LO16
, AT
);
6331 /* FIXME: How in the world do we deal with the possible
6333 offset_expr
.X_add_number
+= 4;
6334 macro_build (NULL
, &icnt
, &offset_expr
, "lw", "t,o(b)",
6335 treg
+ 1, BFD_RELOC_LO16
, AT
);
6339 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6340 does not become a variant frag. */
6341 frag_wane (frag_now
);
6347 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6348 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6349 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6350 the value and the low order 32 bits are either zero or in
6352 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
6354 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_FPRS
);
6355 if (HAVE_64BIT_FPRS
)
6357 assert (HAVE_64BIT_GPRS
);
6358 macro_build (NULL
, &icnt
, NULL
, "dmtc1", "t,S", AT
, treg
);
6362 macro_build (NULL
, &icnt
, NULL
, "mtc1", "t,G", AT
, treg
+ 1);
6363 if (offset_expr
.X_op
== O_absent
)
6364 macro_build (NULL
, &icnt
, NULL
, "mtc1", "t,G", 0, treg
);
6367 assert (offset_expr
.X_op
== O_constant
);
6368 load_register (&icnt
, AT
, &offset_expr
, 0);
6369 macro_build (NULL
, &icnt
, NULL
, "mtc1", "t,G", AT
, treg
);
6375 assert (offset_expr
.X_op
== O_symbol
6376 && offset_expr
.X_add_number
== 0);
6377 s
= segment_name (S_GET_SEGMENT (offset_expr
.X_add_symbol
));
6378 if (strcmp (s
, ".lit8") == 0)
6380 if (mips_opts
.isa
!= ISA_MIPS1
)
6382 macro_build (NULL
, &icnt
, &offset_expr
, "ldc1", "T,o(b)", treg
,
6383 BFD_RELOC_MIPS_LITERAL
, mips_gp_register
);
6386 breg
= mips_gp_register
;
6387 r
= BFD_RELOC_MIPS_LITERAL
;
6392 assert (strcmp (s
, RDATA_SECTION_NAME
) == 0);
6393 if (mips_pic
== SVR4_PIC
)
6394 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
,
6395 "t,o(b)", AT
, BFD_RELOC_MIPS_GOT16
,
6399 /* FIXME: This won't work for a 64 bit address. */
6400 macro_build_lui (NULL
, &icnt
, &offset_expr
, AT
);
6403 if (mips_opts
.isa
!= ISA_MIPS1
)
6405 macro_build (NULL
, &icnt
, &offset_expr
, "ldc1", "T,o(b)", treg
,
6406 BFD_RELOC_LO16
, AT
);
6408 /* To avoid confusion in tc_gen_reloc, we must ensure
6409 that this does not become a variant frag. */
6410 frag_wane (frag_now
);
6421 if (mips_opts
.arch
== CPU_R4650
)
6423 as_bad (_("opcode not supported on this processor"));
6426 /* Even on a big endian machine $fn comes before $fn+1. We have
6427 to adjust when loading from memory. */
6430 assert (mips_opts
.isa
== ISA_MIPS1
);
6431 macro_build (NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)",
6432 target_big_endian
? treg
+ 1 : treg
, r
, breg
);
6433 /* FIXME: A possible overflow which I don't know how to deal
6435 offset_expr
.X_add_number
+= 4;
6436 macro_build (NULL
, &icnt
, &offset_expr
, "lwc1", "T,o(b)",
6437 target_big_endian
? treg
: treg
+ 1, r
, breg
);
6439 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6440 does not become a variant frag. */
6441 frag_wane (frag_now
);
6450 * The MIPS assembler seems to check for X_add_number not
6451 * being double aligned and generating:
6454 * addiu at,at,%lo(foo+1)
6457 * But, the resulting address is the same after relocation so why
6458 * generate the extra instruction?
6460 if (mips_opts
.arch
== CPU_R4650
)
6462 as_bad (_("opcode not supported on this processor"));
6465 /* Itbl support may require additional care here. */
6467 if (mips_opts
.isa
!= ISA_MIPS1
)
6478 if (mips_opts
.arch
== CPU_R4650
)
6480 as_bad (_("opcode not supported on this processor"));
6484 if (mips_opts
.isa
!= ISA_MIPS1
)
6492 /* Itbl support may require additional care here. */
6497 if (HAVE_64BIT_GPRS
)
6508 if (HAVE_64BIT_GPRS
)
6518 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6519 loads for the case of doing a pair of loads to simulate an 'ld'.
6520 This is not currently done by the compiler, and assembly coders
6521 writing embedded-pic code can cope. */
6523 if (offset_expr
.X_op
!= O_symbol
6524 && offset_expr
.X_op
!= O_constant
)
6526 as_bad (_("expression too complex"));
6527 offset_expr
.X_op
= O_constant
;
6530 /* Even on a big endian machine $fn comes before $fn+1. We have
6531 to adjust when loading from memory. We set coproc if we must
6532 load $fn+1 first. */
6533 /* Itbl support may require additional care here. */
6534 if (! target_big_endian
)
6537 if (mips_pic
== NO_PIC
6538 || offset_expr
.X_op
== O_constant
)
6542 /* If this is a reference to a GP relative symbol, we want
6543 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6544 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6545 If we have a base register, we use this
6547 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6548 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6549 If this is not a GP relative symbol, we want
6550 lui $at,<sym> (BFD_RELOC_HI16_S)
6551 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6552 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6553 If there is a base register, we add it to $at after the
6554 lui instruction. If there is a constant, we always use
6556 if ((valueT
) offset_expr
.X_add_number
> MAX_GPREL_OFFSET
6557 || nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6569 tempreg
= mips_gp_register
;
6576 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6577 AT
, breg
, mips_gp_register
);
6583 /* Itbl support may require additional care here. */
6584 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
,
6585 coproc
? treg
+ 1 : treg
,
6586 BFD_RELOC_GPREL16
, tempreg
);
6587 offset_expr
.X_add_number
+= 4;
6589 /* Set mips_optimize to 2 to avoid inserting an
6591 hold_mips_optimize
= mips_optimize
;
6593 /* Itbl support may require additional care here. */
6594 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
,
6595 coproc
? treg
: treg
+ 1,
6596 BFD_RELOC_GPREL16
, tempreg
);
6597 mips_optimize
= hold_mips_optimize
;
6599 p
= frag_var (rs_machine_dependent
, 12 + off
, 0,
6600 RELAX_ENCODE (8 + off
, 12 + off
, 0, 4 + off
, 1,
6601 used_at
&& mips_opts
.noat
),
6602 offset_expr
.X_add_symbol
, 0, NULL
);
6604 /* We just generated two relocs. When tc_gen_reloc
6605 handles this case, it will skip the first reloc and
6606 handle the second. The second reloc already has an
6607 extra addend of 4, which we added above. We must
6608 subtract it out, and then subtract another 4 to make
6609 the first reloc come out right. The second reloc
6610 will come out right because we are going to add 4 to
6611 offset_expr when we build its instruction below.
6613 If we have a symbol, then we don't want to include
6614 the offset, because it will wind up being included
6615 when we generate the reloc. */
6617 if (offset_expr
.X_op
== O_constant
)
6618 offset_expr
.X_add_number
-= 8;
6621 offset_expr
.X_add_number
= -4;
6622 offset_expr
.X_op
= O_constant
;
6625 macro_build_lui (p
, &icnt
, &offset_expr
, AT
);
6630 macro_build (p
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6635 /* Itbl support may require additional care here. */
6636 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
,
6637 coproc
? treg
+ 1 : treg
,
6638 BFD_RELOC_LO16
, AT
);
6641 /* FIXME: How do we handle overflow here? */
6642 offset_expr
.X_add_number
+= 4;
6643 /* Itbl support may require additional care here. */
6644 macro_build (p
, &icnt
, &offset_expr
, s
, fmt
,
6645 coproc
? treg
: treg
+ 1,
6646 BFD_RELOC_LO16
, AT
);
6648 else if (mips_pic
== SVR4_PIC
&& ! mips_big_got
)
6652 /* If this is a reference to an external symbol, we want
6653 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6658 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6660 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6661 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6662 If there is a base register we add it to $at before the
6663 lwc1 instructions. If there is a constant we include it
6664 in the lwc1 instructions. */
6666 expr1
.X_add_number
= offset_expr
.X_add_number
;
6667 offset_expr
.X_add_number
= 0;
6668 if (expr1
.X_add_number
< -0x8000
6669 || expr1
.X_add_number
>= 0x8000 - 4)
6670 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6675 frag_grow (24 + off
);
6676 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6677 AT
, BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6678 macro_build (NULL
, &icnt
, NULL
, "nop", "");
6680 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6682 /* Itbl support may require additional care here. */
6683 macro_build (NULL
, &icnt
, &expr1
, s
, fmt
, coproc
? treg
+ 1 : treg
,
6684 BFD_RELOC_LO16
, AT
);
6685 expr1
.X_add_number
+= 4;
6687 /* Set mips_optimize to 2 to avoid inserting an undesired
6689 hold_mips_optimize
= mips_optimize
;
6691 /* Itbl support may require additional care here. */
6692 macro_build (NULL
, &icnt
, &expr1
, s
, fmt
, coproc
? treg
: treg
+ 1,
6693 BFD_RELOC_LO16
, AT
);
6694 mips_optimize
= hold_mips_optimize
;
6696 (void) frag_var (rs_machine_dependent
, 0, 0,
6697 RELAX_ENCODE (0, 0, -16 - off
, -8, 1, 0),
6698 offset_expr
.X_add_symbol
, 0, NULL
);
6700 else if (mips_pic
== SVR4_PIC
)
6705 /* If this is a reference to an external symbol, we want
6706 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6708 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6713 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6715 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6716 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6717 If there is a base register we add it to $at before the
6718 lwc1 instructions. If there is a constant we include it
6719 in the lwc1 instructions. */
6721 expr1
.X_add_number
= offset_expr
.X_add_number
;
6722 offset_expr
.X_add_number
= 0;
6723 if (expr1
.X_add_number
< -0x8000
6724 || expr1
.X_add_number
>= 0x8000 - 4)
6725 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6726 if (reg_needs_delay (mips_gp_register
))
6735 macro_build (NULL
, &icnt
, &offset_expr
, "lui", "t,u", AT
,
6736 BFD_RELOC_MIPS_GOT_HI16
);
6737 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6738 AT
, AT
, mips_gp_register
);
6739 macro_build (NULL
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6740 AT
, BFD_RELOC_MIPS_GOT_LO16
, AT
);
6741 macro_build (NULL
, &icnt
, NULL
, "nop", "");
6743 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6745 /* Itbl support may require additional care here. */
6746 macro_build (NULL
, &icnt
, &expr1
, s
, fmt
, coproc
? treg
+ 1 : treg
,
6747 BFD_RELOC_LO16
, AT
);
6748 expr1
.X_add_number
+= 4;
6750 /* Set mips_optimize to 2 to avoid inserting an undesired
6752 hold_mips_optimize
= mips_optimize
;
6754 /* Itbl support may require additional care here. */
6755 macro_build (NULL
, &icnt
, &expr1
, s
, fmt
, coproc
? treg
: treg
+ 1,
6756 BFD_RELOC_LO16
, AT
);
6757 mips_optimize
= hold_mips_optimize
;
6758 expr1
.X_add_number
-= 4;
6760 p
= frag_var (rs_machine_dependent
, 16 + gpdel
+ off
, 0,
6761 RELAX_ENCODE (24 + off
, 16 + gpdel
+ off
, gpdel
,
6762 8 + gpdel
+ off
, 1, 0),
6763 offset_expr
.X_add_symbol
, 0, NULL
);
6766 macro_build (p
, &icnt
, NULL
, "nop", "");
6769 macro_build (p
, &icnt
, &offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6770 AT
, BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6772 macro_build (p
, &icnt
, NULL
, "nop", "");
6776 macro_build (p
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6780 /* Itbl support may require additional care here. */
6781 macro_build (p
, &icnt
, &expr1
, s
, fmt
, coproc
? treg
+ 1 : treg
,
6782 BFD_RELOC_LO16
, AT
);
6784 expr1
.X_add_number
+= 4;
6786 /* Set mips_optimize to 2 to avoid inserting an undesired
6788 hold_mips_optimize
= mips_optimize
;
6790 /* Itbl support may require additional care here. */
6791 macro_build (p
, &icnt
, &expr1
, s
, fmt
, coproc
? treg
: treg
+ 1,
6792 BFD_RELOC_LO16
, AT
);
6793 mips_optimize
= hold_mips_optimize
;
6795 else if (mips_pic
== EMBEDDED_PIC
)
6797 /* If there is no base register, we use
6798 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6799 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6800 If we have a base register, we use
6802 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6803 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6807 tempreg
= mips_gp_register
;
6812 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6813 AT
, breg
, mips_gp_register
);
6818 /* Itbl support may require additional care here. */
6819 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
,
6820 coproc
? treg
+ 1 : treg
,
6821 BFD_RELOC_GPREL16
, tempreg
);
6822 offset_expr
.X_add_number
+= 4;
6823 /* Itbl support may require additional care here. */
6824 macro_build (NULL
, &icnt
, &offset_expr
, s
, fmt
,
6825 coproc
? treg
: treg
+ 1,
6826 BFD_RELOC_GPREL16
, tempreg
);
6842 assert (HAVE_32BIT_ADDRESSES
);
6843 macro_build (NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
6844 BFD_RELOC_LO16
, breg
);
6845 offset_expr
.X_add_number
+= 4;
6846 macro_build (NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
+ 1,
6847 BFD_RELOC_LO16
, breg
);
6850 /* New code added to support COPZ instructions.
6851 This code builds table entries out of the macros in mip_opcodes.
6852 R4000 uses interlocks to handle coproc delays.
6853 Other chips (like the R3000) require nops to be inserted for delays.
6855 FIXME: Currently, we require that the user handle delays.
6856 In order to fill delay slots for non-interlocked chips,
6857 we must have a way to specify delays based on the coprocessor.
6858 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6859 What are the side-effects of the cop instruction?
6860 What cache support might we have and what are its effects?
6861 Both coprocessor & memory require delays. how long???
6862 What registers are read/set/modified?
6864 If an itbl is provided to interpret cop instructions,
6865 this knowledge can be encoded in the itbl spec. */
6879 /* For now we just do C (same as Cz). The parameter will be
6880 stored in insn_opcode by mips_ip. */
6881 macro_build (NULL
, &icnt
, NULL
, s
, "C", ip
->insn_opcode
);
6885 move_register (&icnt
, dreg
, sreg
);
6888 #ifdef LOSING_COMPILER
6890 /* Try and see if this is a new itbl instruction.
6891 This code builds table entries out of the macros in mip_opcodes.
6892 FIXME: For now we just assemble the expression and pass it's
6893 value along as a 32-bit immediate.
6894 We may want to have the assembler assemble this value,
6895 so that we gain the assembler's knowledge of delay slots,
6897 Would it be more efficient to use mask (id) here? */
6898 if (itbl_have_entries
6899 && (immed_expr
= itbl_assemble (ip
->insn_mo
->name
, "")))
6901 s
= ip
->insn_mo
->name
;
6903 coproc
= ITBL_DECODE_PNUM (immed_expr
);;
6904 macro_build (NULL
, &icnt
, &immed_expr
, s
, "C");
6911 as_warn (_("Macro used $at after \".set noat\""));
6915 macro2 (struct mips_cl_insn
*ip
)
6917 register int treg
, sreg
, dreg
, breg
;
6933 bfd_reloc_code_real_type r
;
6936 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
6937 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
6938 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
6939 mask
= ip
->insn_mo
->mask
;
6941 expr1
.X_op
= O_constant
;
6942 expr1
.X_op_symbol
= NULL
;
6943 expr1
.X_add_symbol
= NULL
;
6944 expr1
.X_add_number
= 1;
6948 #endif /* LOSING_COMPILER */
6953 macro_build (NULL
, &icnt
, NULL
, dbl
? "dmultu" : "multu", "s,t",
6955 macro_build (NULL
, &icnt
, NULL
, "mflo", "d", dreg
);
6961 /* The MIPS assembler some times generates shifts and adds. I'm
6962 not trying to be that fancy. GCC should do this for us
6964 load_register (&icnt
, AT
, &imm_expr
, dbl
);
6965 macro_build (NULL
, &icnt
, NULL
, dbl
? "dmult" : "mult", "s,t",
6967 macro_build (NULL
, &icnt
, NULL
, "mflo", "d", dreg
);
6980 mips_emit_delays (TRUE
);
6981 ++mips_opts
.noreorder
;
6982 mips_any_noreorder
= 1;
6984 load_register (&icnt
, AT
, &imm_expr
, dbl
);
6985 macro_build (NULL
, &icnt
, NULL
, dbl
? "dmult" : "mult", "s,t",
6986 sreg
, imm
? AT
: treg
);
6987 macro_build (NULL
, &icnt
, NULL
, "mflo", "d", dreg
);
6988 macro_build (NULL
, &icnt
, NULL
, dbl
? "dsra32" : "sra", "d,w,<",
6990 macro_build (NULL
, &icnt
, NULL
, "mfhi", "d", AT
);
6992 macro_build (NULL
, &icnt
, NULL
, "tne", "s,t,q", dreg
, AT
, 6);
6995 expr1
.X_add_number
= 8;
6996 macro_build (NULL
, &icnt
, &expr1
, "beq", "s,t,p", dreg
, AT
);
6997 macro_build (NULL
, &icnt
, NULL
, "nop", "", 0);
6998 macro_build (NULL
, &icnt
, NULL
, "break", "c", 6);
7000 --mips_opts
.noreorder
;
7001 macro_build (NULL
, &icnt
, NULL
, "mflo", "d", dreg
);
7014 mips_emit_delays (TRUE
);
7015 ++mips_opts
.noreorder
;
7016 mips_any_noreorder
= 1;
7018 load_register (&icnt
, AT
, &imm_expr
, dbl
);
7019 macro_build (NULL
, &icnt
, NULL
, dbl
? "dmultu" : "multu", "s,t",
7020 sreg
, imm
? AT
: treg
);
7021 macro_build (NULL
, &icnt
, NULL
, "mfhi", "d", AT
);
7022 macro_build (NULL
, &icnt
, NULL
, "mflo", "d", dreg
);
7024 macro_build (NULL
, &icnt
, NULL
, "tne", "s,t,q", AT
, 0, 6);
7027 expr1
.X_add_number
= 8;
7028 macro_build (NULL
, &icnt
, &expr1
, "beq", "s,t,p", AT
, 0);
7029 macro_build (NULL
, &icnt
, NULL
, "nop", "", 0);
7030 macro_build (NULL
, &icnt
, NULL
, "break", "c", 6);
7032 --mips_opts
.noreorder
;
7036 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7048 macro_build (NULL
, &icnt
, NULL
, "dnegu", "d,w", tempreg
, treg
);
7049 macro_build (NULL
, &icnt
, NULL
, "drorv", "d,t,s", dreg
, sreg
,
7055 macro_build (NULL
, &icnt
, NULL
, "dsubu", "d,v,t", AT
, 0, treg
);
7056 macro_build (NULL
, &icnt
, NULL
, "dsrlv", "d,t,s", AT
, sreg
, AT
);
7057 macro_build (NULL
, &icnt
, NULL
, "dsllv", "d,t,s", dreg
, sreg
, treg
);
7058 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7062 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7074 macro_build (NULL
, &icnt
, NULL
, "negu", "d,w", tempreg
, treg
);
7075 macro_build (NULL
, &icnt
, NULL
, "rorv", "d,t,s", dreg
, sreg
,
7081 macro_build (NULL
, &icnt
, NULL
, "subu", "d,v,t", AT
, 0, treg
);
7082 macro_build (NULL
, &icnt
, NULL
, "srlv", "d,t,s", AT
, sreg
, AT
);
7083 macro_build (NULL
, &icnt
, NULL
, "sllv", "d,t,s", dreg
, sreg
, treg
);
7084 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7092 if (imm_expr
.X_op
!= O_constant
)
7093 as_bad (_("Improper rotate count"));
7094 rot
= imm_expr
.X_add_number
& 0x3f;
7095 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7097 rot
= (64 - rot
) & 0x3f;
7099 macro_build (NULL
, &icnt
, NULL
, "dror32", "d,w,<",
7100 dreg
, sreg
, rot
- 32);
7102 macro_build (NULL
, &icnt
, NULL
, "dror", "d,w,<",
7108 macro_build (NULL
, &icnt
, NULL
, "dsrl", "d,w,<", dreg
, sreg
, 0);
7111 l
= (rot
< 0x20) ? "dsll" : "dsll32";
7112 r
= ((0x40 - rot
) < 0x20) ? "dsrl" : "dsrl32";
7114 macro_build (NULL
, &icnt
, NULL
, l
, "d,w,<", AT
, sreg
, rot
);
7115 macro_build (NULL
, &icnt
, NULL
, r
, "d,w,<", dreg
, sreg
,
7116 (0x20 - rot
) & 0x1f);
7117 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7125 if (imm_expr
.X_op
!= O_constant
)
7126 as_bad (_("Improper rotate count"));
7127 rot
= imm_expr
.X_add_number
& 0x1f;
7128 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7130 macro_build (NULL
, &icnt
, NULL
, "ror", "d,w,<", dreg
, sreg
,
7136 macro_build (NULL
, &icnt
, NULL
, "srl", "d,w,<", dreg
, sreg
, 0);
7139 macro_build (NULL
, &icnt
, NULL
, "sll", "d,w,<", AT
, sreg
, rot
);
7140 macro_build (NULL
, &icnt
, NULL
, "srl", "d,w,<", dreg
, sreg
,
7141 (0x20 - rot
) & 0x1f);
7142 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7147 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7149 macro_build (NULL
, &icnt
, NULL
, "drorv", "d,t,s", dreg
, sreg
, treg
);
7152 macro_build (NULL
, &icnt
,NULL
, "dsubu", "d,v,t", AT
, 0, treg
);
7153 macro_build (NULL
, &icnt
, NULL
, "dsllv", "d,t,s", AT
, sreg
, AT
);
7154 macro_build (NULL
, &icnt
, NULL
, "dsrlv", "d,t,s", dreg
, sreg
, treg
);
7155 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7159 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7161 macro_build (NULL
, &icnt
, NULL
, "rorv", "d,t,s", dreg
, sreg
, treg
);
7164 macro_build (NULL
, &icnt
, NULL
, "subu", "d,v,t", AT
, 0, treg
);
7165 macro_build (NULL
, &icnt
, NULL
, "sllv", "d,t,s", AT
, sreg
, AT
);
7166 macro_build (NULL
, &icnt
, NULL
, "srlv", "d,t,s", dreg
, sreg
, treg
);
7167 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7175 if (imm_expr
.X_op
!= O_constant
)
7176 as_bad (_("Improper rotate count"));
7177 rot
= imm_expr
.X_add_number
& 0x3f;
7178 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7181 macro_build (NULL
, &icnt
, NULL
, "dror32", "d,w,<",
7182 dreg
, sreg
, rot
- 32);
7184 macro_build (NULL
, &icnt
, NULL
, "dror", "d,w,<",
7190 macro_build (NULL
, &icnt
, NULL
, "dsrl", "d,w,<", dreg
, sreg
, 0);
7193 r
= (rot
< 0x20) ? "dsrl" : "dsrl32";
7194 l
= ((0x40 - rot
) < 0x20) ? "dsll" : "dsll32";
7196 macro_build ( NULL
, &icnt
,NULL
, r
, "d,w,<", AT
, sreg
, rot
);
7197 macro_build (NULL
, &icnt
, NULL
, l
, "d,w,<", dreg
, sreg
,
7198 (0x20 - rot
) & 0x1f);
7199 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7207 if (imm_expr
.X_op
!= O_constant
)
7208 as_bad (_("Improper rotate count"));
7209 rot
= imm_expr
.X_add_number
& 0x1f;
7210 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7212 macro_build (NULL
, &icnt
, NULL
, "ror", "d,w,<", dreg
, sreg
, rot
);
7217 macro_build (NULL
, &icnt
, NULL
, "srl", "d,w,<", dreg
, sreg
, 0);
7220 macro_build (NULL
, &icnt
, NULL
, "srl", "d,w,<", AT
, sreg
, rot
);
7221 macro_build (NULL
, &icnt
, NULL
, "sll", "d,w,<", dreg
, sreg
,
7222 (0x20 - rot
) & 0x1f);
7223 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7228 if (mips_opts
.arch
== CPU_R4650
)
7230 as_bad (_("opcode not supported on this processor"));
7233 assert (mips_opts
.isa
== ISA_MIPS1
);
7234 /* Even on a big endian machine $fn comes before $fn+1. We have
7235 to adjust when storing to memory. */
7236 macro_build (NULL
, &icnt
, &offset_expr
, "swc1", "T,o(b)",
7237 target_big_endian
? treg
+ 1 : treg
,
7238 BFD_RELOC_LO16
, breg
);
7239 offset_expr
.X_add_number
+= 4;
7240 macro_build (NULL
, &icnt
, &offset_expr
, "swc1", "T,o(b)",
7241 target_big_endian
? treg
: treg
+ 1,
7242 BFD_RELOC_LO16
, breg
);
7247 macro_build (NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
, treg
,
7250 macro_build (NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
, sreg
,
7254 macro_build (NULL
, &icnt
, NULL
, "xor", "d,v,t", dreg
, sreg
, treg
);
7255 macro_build (NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
, dreg
,
7261 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
7263 macro_build (NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
, sreg
,
7269 as_warn (_("Instruction %s: result is always false"),
7271 move_register (&icnt
, dreg
, 0);
7274 if (imm_expr
.X_op
== O_constant
7275 && imm_expr
.X_add_number
>= 0
7276 && imm_expr
.X_add_number
< 0x10000)
7278 macro_build (NULL
, &icnt
, &imm_expr
, "xori", "t,r,i", dreg
, sreg
,
7282 else if (imm_expr
.X_op
== O_constant
7283 && imm_expr
.X_add_number
> -0x8000
7284 && imm_expr
.X_add_number
< 0)
7286 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7287 macro_build (NULL
, &icnt
, &imm_expr
,
7288 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7289 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7294 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7295 macro_build (NULL
, &icnt
, NULL
, "xor", "d,v,t", dreg
, sreg
, AT
);
7298 macro_build (NULL
, &icnt
, &expr1
, "sltiu", "t,r,j", dreg
, dreg
,
7304 case M_SGE
: /* sreg >= treg <==> not (sreg < treg) */
7310 macro_build (NULL
, &icnt
, NULL
, s
, "d,v,t", dreg
, sreg
, treg
);
7311 macro_build (NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
7315 case M_SGE_I
: /* sreg >= I <==> not (sreg < I) */
7317 if (imm_expr
.X_op
== O_constant
7318 && imm_expr
.X_add_number
>= -0x8000
7319 && imm_expr
.X_add_number
< 0x8000)
7321 macro_build (NULL
, &icnt
, &imm_expr
,
7322 mask
== M_SGE_I
? "slti" : "sltiu",
7323 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7328 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7329 macro_build (NULL
, &icnt
, NULL
, mask
== M_SGE_I
? "slt" : "sltu",
7330 "d,v,t", dreg
, sreg
, AT
);
7333 macro_build (NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
7339 case M_SGT
: /* sreg > treg <==> treg < sreg */
7345 macro_build (NULL
, &icnt
, NULL
, s
, "d,v,t", dreg
, treg
, sreg
);
7348 case M_SGT_I
: /* sreg > I <==> I < sreg */
7354 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7355 macro_build (NULL
, &icnt
, NULL
, s
, "d,v,t", dreg
, AT
, sreg
);
7358 case M_SLE
: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7364 macro_build (NULL
, &icnt
, NULL
, s
, "d,v,t", dreg
, treg
, sreg
);
7365 macro_build (NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
7369 case M_SLE_I
: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7375 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7376 macro_build (NULL
, &icnt
, NULL
, s
, "d,v,t", dreg
, AT
, sreg
);
7377 macro_build (NULL
, &icnt
, &expr1
, "xori", "t,r,i", dreg
, dreg
,
7382 if (imm_expr
.X_op
== O_constant
7383 && imm_expr
.X_add_number
>= -0x8000
7384 && imm_expr
.X_add_number
< 0x8000)
7386 macro_build (NULL
, &icnt
, &imm_expr
, "slti", "t,r,j", dreg
, sreg
,
7390 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7391 macro_build (NULL
, &icnt
, NULL
, "slt", "d,v,t", dreg
, sreg
, AT
);
7395 if (imm_expr
.X_op
== O_constant
7396 && imm_expr
.X_add_number
>= -0x8000
7397 && imm_expr
.X_add_number
< 0x8000)
7399 macro_build (NULL
, &icnt
, &imm_expr
, "sltiu", "t,r,j", dreg
, sreg
,
7403 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7404 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", dreg
, sreg
, AT
);
7409 macro_build (NULL
, &icnt
,NULL
, "sltu","d,v,t", dreg
, 0, treg
);
7411 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", dreg
, 0, sreg
);
7414 macro_build (NULL
, &icnt
, NULL
, "xor", "d,v,t", dreg
, sreg
, treg
);
7415 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", dreg
, 0, dreg
);
7420 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
7422 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", dreg
, 0, sreg
);
7427 as_warn (_("Instruction %s: result is always true"),
7429 macro_build (NULL
, &icnt
, &expr1
,
7430 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7431 "t,r,j", dreg
, 0, BFD_RELOC_LO16
);
7434 if (imm_expr
.X_op
== O_constant
7435 && imm_expr
.X_add_number
>= 0
7436 && imm_expr
.X_add_number
< 0x10000)
7438 macro_build (NULL
, &icnt
, &imm_expr
, "xori", "t,r,i", dreg
, sreg
,
7442 else if (imm_expr
.X_op
== O_constant
7443 && imm_expr
.X_add_number
> -0x8000
7444 && imm_expr
.X_add_number
< 0)
7446 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7447 macro_build (NULL
, &icnt
, &imm_expr
,
7448 HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7449 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7454 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7455 macro_build (NULL
, &icnt
, NULL
, "xor", "d,v,t", dreg
, sreg
, AT
);
7458 macro_build (NULL
, &icnt
, NULL
, "sltu", "d,v,t", dreg
, 0, dreg
);
7466 if (imm_expr
.X_op
== O_constant
7467 && imm_expr
.X_add_number
> -0x8000
7468 && imm_expr
.X_add_number
<= 0x8000)
7470 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7471 macro_build (NULL
, &icnt
, &imm_expr
, dbl
? "daddi" : "addi",
7472 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7475 load_register (&icnt
, AT
, &imm_expr
, dbl
);
7476 macro_build (NULL
, &icnt
, NULL
, dbl
? "dsub" : "sub", "d,v,t",
7483 if (imm_expr
.X_op
== O_constant
7484 && imm_expr
.X_add_number
> -0x8000
7485 && imm_expr
.X_add_number
<= 0x8000)
7487 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7488 macro_build (NULL
, &icnt
, &imm_expr
, dbl
? "daddiu" : "addiu",
7489 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7492 load_register (&icnt
, AT
, &imm_expr
, dbl
);
7493 macro_build (NULL
, &icnt
, NULL
, dbl
? "dsubu" : "subu", "d,v,t",
7515 load_register (&icnt
, AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7516 macro_build (NULL
, &icnt
, NULL
, s
, "s,t", sreg
, AT
);
7521 assert (mips_opts
.isa
== ISA_MIPS1
);
7522 sreg
= (ip
->insn_opcode
>> 11) & 0x1f; /* floating reg */
7523 dreg
= (ip
->insn_opcode
>> 06) & 0x1f; /* floating reg */
7526 * Is the double cfc1 instruction a bug in the mips assembler;
7527 * or is there a reason for it?
7529 mips_emit_delays (TRUE
);
7530 ++mips_opts
.noreorder
;
7531 mips_any_noreorder
= 1;
7532 macro_build (NULL
, &icnt
, NULL
, "cfc1", "t,G", treg
, RA
);
7533 macro_build (NULL
, &icnt
, NULL
, "cfc1", "t,G", treg
, RA
);
7534 macro_build (NULL
, &icnt
, NULL
, "nop", "");
7535 expr1
.X_add_number
= 3;
7536 macro_build (NULL
, &icnt
, &expr1
, "ori", "t,r,i", AT
, treg
,
7538 expr1
.X_add_number
= 2;
7539 macro_build (NULL
, &icnt
, &expr1
, "xori", "t,r,i", AT
, AT
,
7541 macro_build (NULL
, &icnt
, NULL
, "ctc1", "t,G", AT
, RA
);
7542 macro_build (NULL
, &icnt
, NULL
, "nop", "");
7543 macro_build (NULL
, &icnt
, NULL
,
7544 mask
== M_TRUNCWD
? "cvt.w.d" : "cvt.w.s",
7546 macro_build (NULL
, &icnt
, NULL
, "ctc1", "t,G", treg
, RA
);
7547 macro_build (NULL
, &icnt
, NULL
, "nop", "");
7548 --mips_opts
.noreorder
;
7557 if (offset_expr
.X_add_number
>= 0x7fff)
7558 as_bad (_("operand overflow"));
7559 if (! target_big_endian
)
7560 ++offset_expr
.X_add_number
;
7561 macro_build (NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", AT
,
7562 BFD_RELOC_LO16
, breg
);
7563 if (! target_big_endian
)
7564 --offset_expr
.X_add_number
;
7566 ++offset_expr
.X_add_number
;
7567 macro_build (NULL
, &icnt
, &offset_expr
, "lbu", "t,o(b)", treg
,
7568 BFD_RELOC_LO16
, breg
);
7569 macro_build (NULL
, &icnt
, NULL
, "sll", "d,w,<", AT
, AT
, 8);
7570 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", treg
, treg
, AT
);
7583 if (offset_expr
.X_add_number
>= 0x8000 - off
)
7584 as_bad (_("operand overflow"));
7589 if (! target_big_endian
)
7590 offset_expr
.X_add_number
+= off
;
7591 macro_build (NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", tempreg
,
7592 BFD_RELOC_LO16
, breg
);
7593 if (! target_big_endian
)
7594 offset_expr
.X_add_number
-= off
;
7596 offset_expr
.X_add_number
+= off
;
7597 macro_build (NULL
, &icnt
, &offset_expr
, s2
, "t,o(b)", tempreg
,
7598 BFD_RELOC_LO16
, breg
);
7600 /* If necessary, move the result in tempreg the final destination. */
7601 if (treg
== tempreg
)
7603 /* Protect second load's delay slot. */
7604 if (!gpr_interlocks
)
7605 macro_build (NULL
, &icnt
, NULL
, "nop", "");
7606 move_register (&icnt
, treg
, tempreg
);
7620 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7622 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
7624 if (! target_big_endian
)
7625 expr1
.X_add_number
= off
;
7627 expr1
.X_add_number
= 0;
7628 macro_build (NULL
, &icnt
, &expr1
, s
, "t,o(b)", treg
,
7629 BFD_RELOC_LO16
, AT
);
7630 if (! target_big_endian
)
7631 expr1
.X_add_number
= 0;
7633 expr1
.X_add_number
= off
;
7634 macro_build (NULL
, &icnt
, &expr1
, s2
, "t,o(b)", treg
,
7635 BFD_RELOC_LO16
, AT
);
7641 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7643 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
7645 if (target_big_endian
)
7646 expr1
.X_add_number
= 0;
7647 macro_build (NULL
, &icnt
, &expr1
,
7648 mask
== M_ULH_A
? "lb" : "lbu", "t,o(b)",
7649 treg
, BFD_RELOC_LO16
, AT
);
7650 if (target_big_endian
)
7651 expr1
.X_add_number
= 1;
7653 expr1
.X_add_number
= 0;
7654 macro_build (NULL
, &icnt
, &expr1
, "lbu", "t,o(b)",
7655 AT
, BFD_RELOC_LO16
, AT
);
7656 macro_build (NULL
, &icnt
, NULL
, "sll", "d,w,<", treg
, treg
, 8);
7657 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", treg
, treg
, AT
);
7661 if (offset_expr
.X_add_number
>= 0x7fff)
7662 as_bad (_("operand overflow"));
7663 if (target_big_endian
)
7664 ++offset_expr
.X_add_number
;
7665 macro_build (NULL
, &icnt
, &offset_expr
, "sb", "t,o(b)", treg
,
7666 BFD_RELOC_LO16
, breg
);
7667 macro_build (NULL
, &icnt
, NULL
, "srl", "d,w,<", AT
, treg
, 8);
7668 if (target_big_endian
)
7669 --offset_expr
.X_add_number
;
7671 ++offset_expr
.X_add_number
;
7672 macro_build (NULL
, &icnt
, &offset_expr
, "sb", "t,o(b)", AT
,
7673 BFD_RELOC_LO16
, breg
);
7686 if (offset_expr
.X_add_number
>= 0x8000 - off
)
7687 as_bad (_("operand overflow"));
7688 if (! target_big_endian
)
7689 offset_expr
.X_add_number
+= off
;
7690 macro_build (NULL
, &icnt
, &offset_expr
, s
, "t,o(b)", treg
,
7691 BFD_RELOC_LO16
, breg
);
7692 if (! target_big_endian
)
7693 offset_expr
.X_add_number
-= off
;
7695 offset_expr
.X_add_number
+= off
;
7696 macro_build (NULL
, &icnt
, &offset_expr
, s2
, "t,o(b)", treg
,
7697 BFD_RELOC_LO16
, breg
);
7711 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7713 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
7715 if (! target_big_endian
)
7716 expr1
.X_add_number
= off
;
7718 expr1
.X_add_number
= 0;
7719 macro_build (NULL
, &icnt
, &expr1
, s
, "t,o(b)", treg
,
7720 BFD_RELOC_LO16
, AT
);
7721 if (! target_big_endian
)
7722 expr1
.X_add_number
= 0;
7724 expr1
.X_add_number
= off
;
7725 macro_build (NULL
, &icnt
, &expr1
, s2
, "t,o(b)", treg
,
7726 BFD_RELOC_LO16
, AT
);
7731 load_address (&icnt
, AT
, &offset_expr
, &used_at
);
7733 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
7735 if (! target_big_endian
)
7736 expr1
.X_add_number
= 0;
7737 macro_build (NULL
, &icnt
, &expr1
, "sb", "t,o(b)", treg
,
7738 BFD_RELOC_LO16
, AT
);
7739 macro_build (NULL
, &icnt
, NULL
, "srl", "d,w,<", treg
, treg
, 8);
7740 if (! target_big_endian
)
7741 expr1
.X_add_number
= 1;
7743 expr1
.X_add_number
= 0;
7744 macro_build (NULL
, &icnt
, &expr1
, "sb", "t,o(b)", treg
,
7745 BFD_RELOC_LO16
, AT
);
7746 if (! target_big_endian
)
7747 expr1
.X_add_number
= 0;
7749 expr1
.X_add_number
= 1;
7750 macro_build (NULL
, &icnt
, &expr1
, "lbu", "t,o(b)", AT
,
7751 BFD_RELOC_LO16
, AT
);
7752 macro_build (NULL
, &icnt
, NULL
, "sll", "d,w,<", treg
, treg
, 8);
7753 macro_build (NULL
, &icnt
, NULL
, "or", "d,v,t", treg
, treg
, AT
);
7757 /* FIXME: Check if this is one of the itbl macros, since they
7758 are added dynamically. */
7759 as_bad (_("Macro %s not implemented yet"), ip
->insn_mo
->name
);
7763 as_warn (_("Macro used $at after \".set noat\""));
7766 /* Implement macros in mips16 mode. */
7769 mips16_macro (struct mips_cl_insn
*ip
)
7772 int xreg
, yreg
, zreg
, tmp
;
7776 const char *s
, *s2
, *s3
;
7778 mask
= ip
->insn_mo
->mask
;
7780 xreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RX
) & MIPS16OP_MASK_RX
;
7781 yreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RY
) & MIPS16OP_MASK_RY
;
7782 zreg
= (ip
->insn_opcode
>> MIPS16OP_SH_RZ
) & MIPS16OP_MASK_RZ
;
7786 expr1
.X_op
= O_constant
;
7787 expr1
.X_op_symbol
= NULL
;
7788 expr1
.X_add_symbol
= NULL
;
7789 expr1
.X_add_number
= 1;
7808 mips_emit_delays (TRUE
);
7809 ++mips_opts
.noreorder
;
7810 mips_any_noreorder
= 1;
7811 macro_build (NULL
, &icnt
, NULL
, dbl
? "ddiv" : "div", "0,x,y",
7813 expr1
.X_add_number
= 2;
7814 macro_build (NULL
, &icnt
, &expr1
, "bnez", "x,p", yreg
);
7815 macro_build (NULL
, &icnt
, NULL
, "break", "6", 7);
7817 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7818 since that causes an overflow. We should do that as well,
7819 but I don't see how to do the comparisons without a temporary
7821 --mips_opts
.noreorder
;
7822 macro_build (NULL
, &icnt
, NULL
, s
, "x", zreg
);
7841 mips_emit_delays (TRUE
);
7842 ++mips_opts
.noreorder
;
7843 mips_any_noreorder
= 1;
7844 macro_build (NULL
, &icnt
, NULL
, s
, "0,x,y", xreg
, yreg
);
7845 expr1
.X_add_number
= 2;
7846 macro_build (NULL
, &icnt
, &expr1
, "bnez", "x,p", yreg
);
7847 macro_build (NULL
, &icnt
, NULL
, "break", "6", 7);
7848 --mips_opts
.noreorder
;
7849 macro_build (NULL
, &icnt
, NULL
, s2
, "x", zreg
);
7855 macro_build (NULL
, &icnt
, NULL
, dbl
? "dmultu" : "multu", "x,y",
7857 macro_build (NULL
, &icnt
, NULL
, "mflo", "x", zreg
);
7865 if (imm_expr
.X_op
!= O_constant
)
7866 as_bad (_("Unsupported large constant"));
7867 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7868 macro_build (NULL
, &icnt
, &imm_expr
, dbl
? "daddiu" : "addiu", "y,x,4",
7873 if (imm_expr
.X_op
!= O_constant
)
7874 as_bad (_("Unsupported large constant"));
7875 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7876 macro_build (NULL
, &icnt
, &imm_expr
, "addiu", "x,k", xreg
);
7880 if (imm_expr
.X_op
!= O_constant
)
7881 as_bad (_("Unsupported large constant"));
7882 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7883 macro_build (NULL
, &icnt
, &imm_expr
, "daddiu", "y,j", yreg
);
7905 goto do_reverse_branch
;
7909 goto do_reverse_branch
;
7921 goto do_reverse_branch
;
7932 macro_build (NULL
, &icnt
, NULL
, s
, "x,y", xreg
, yreg
);
7933 macro_build (NULL
, &icnt
, &offset_expr
, s2
, "p");
7960 goto do_addone_branch_i
;
7965 goto do_addone_branch_i
;
7980 goto do_addone_branch_i
;
7987 if (imm_expr
.X_op
!= O_constant
)
7988 as_bad (_("Unsupported large constant"));
7989 ++imm_expr
.X_add_number
;
7992 macro_build (NULL
, &icnt
, &imm_expr
, s
, s3
, xreg
);
7993 macro_build (NULL
, &icnt
, &offset_expr
, s2
, "p");
7997 expr1
.X_add_number
= 0;
7998 macro_build (NULL
, &icnt
, &expr1
, "slti", "x,8", yreg
);
8000 move_register (&icnt
, xreg
, yreg
);
8001 expr1
.X_add_number
= 2;
8002 macro_build (NULL
, &icnt
, &expr1
, "bteqz", "p");
8003 macro_build (NULL
, &icnt
, NULL
, "neg", "x,w", xreg
, xreg
);
8007 /* For consistency checking, verify that all bits are specified either
8008 by the match/mask part of the instruction definition, or by the
8011 validate_mips_insn (const struct mips_opcode
*opc
)
8013 const char *p
= opc
->args
;
8015 unsigned long used_bits
= opc
->mask
;
8017 if ((used_bits
& opc
->match
) != opc
->match
)
8019 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
8020 opc
->name
, opc
->args
);
8023 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
8033 case 'A': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8034 case 'B': USE_BITS (OP_MASK_INSMSB
, OP_SH_INSMSB
); break;
8035 case 'C': USE_BITS (OP_MASK_EXTMSBD
, OP_SH_EXTMSBD
); break;
8036 case 'D': USE_BITS (OP_MASK_RD
, OP_SH_RD
);
8037 USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
8039 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8040 c
, opc
->name
, opc
->args
);
8044 case '<': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8045 case '>': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8047 case 'B': USE_BITS (OP_MASK_CODE20
, OP_SH_CODE20
); break;
8048 case 'C': USE_BITS (OP_MASK_COPZ
, OP_SH_COPZ
); break;
8049 case 'D': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
8050 case 'E': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8052 case 'G': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8053 case 'H': USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
8055 case 'J': USE_BITS (OP_MASK_CODE19
, OP_SH_CODE19
); break;
8056 case 'K': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8058 case 'M': USE_BITS (OP_MASK_CCC
, OP_SH_CCC
); break;
8059 case 'N': USE_BITS (OP_MASK_BCC
, OP_SH_BCC
); break;
8060 case 'O': USE_BITS (OP_MASK_ALN
, OP_SH_ALN
); break;
8061 case 'Q': USE_BITS (OP_MASK_VSEL
, OP_SH_VSEL
);
8062 USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8063 case 'R': USE_BITS (OP_MASK_FR
, OP_SH_FR
); break;
8064 case 'S': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8065 case 'T': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8066 case 'V': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8067 case 'W': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8068 case 'X': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
8069 case 'Y': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8070 case 'Z': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8071 case 'a': USE_BITS (OP_MASK_TARGET
, OP_SH_TARGET
); break;
8072 case 'b': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8073 case 'c': USE_BITS (OP_MASK_CODE
, OP_SH_CODE
); break;
8074 case 'd': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8076 case 'h': USE_BITS (OP_MASK_PREFX
, OP_SH_PREFX
); break;
8077 case 'i': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
8078 case 'j': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8079 case 'k': USE_BITS (OP_MASK_CACHE
, OP_SH_CACHE
); break;
8081 case 'o': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8082 case 'p': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8083 case 'q': USE_BITS (OP_MASK_CODE2
, OP_SH_CODE2
); break;
8084 case 'r': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8085 case 's': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8086 case 't': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8087 case 'u': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
8088 case 'v': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8089 case 'w': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8092 case 'P': USE_BITS (OP_MASK_PERFREG
, OP_SH_PERFREG
); break;
8093 case 'U': USE_BITS (OP_MASK_RD
, OP_SH_RD
);
8094 USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8095 case 'e': USE_BITS (OP_MASK_VECBYTE
, OP_SH_VECBYTE
); break;
8096 case '%': USE_BITS (OP_MASK_VECALIGN
, OP_SH_VECALIGN
); break;
8100 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
8101 c
, opc
->name
, opc
->args
);
8105 if (used_bits
!= 0xffffffff)
8107 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
8108 ~used_bits
& 0xffffffff, opc
->name
, opc
->args
);
8114 /* This routine assembles an instruction into its binary format. As a
8115 side effect, it sets one of the global variables imm_reloc or
8116 offset_reloc to the type of relocation to do if one of the operands
8117 is an address expression. */
8120 mips_ip (char *str
, struct mips_cl_insn
*ip
)
8125 struct mips_opcode
*insn
;
8128 unsigned int lastregno
= 0;
8129 unsigned int lastpos
= 0;
8130 unsigned int limlo
, limhi
;
8136 /* If the instruction contains a '.', we first try to match an instruction
8137 including the '.'. Then we try again without the '.'. */
8139 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); ++s
)
8142 /* If we stopped on whitespace, then replace the whitespace with null for
8143 the call to hash_find. Save the character we replaced just in case we
8144 have to re-parse the instruction. */
8151 insn
= (struct mips_opcode
*) hash_find (op_hash
, str
);
8153 /* If we didn't find the instruction in the opcode table, try again, but
8154 this time with just the instruction up to, but not including the
8158 /* Restore the character we overwrite above (if any). */
8162 /* Scan up to the first '.' or whitespace. */
8164 *s
!= '\0' && *s
!= '.' && !ISSPACE (*s
);
8168 /* If we did not find a '.', then we can quit now. */
8171 insn_error
= "unrecognized opcode";
8175 /* Lookup the instruction in the hash table. */
8177 if ((insn
= (struct mips_opcode
*) hash_find (op_hash
, str
)) == NULL
)
8179 insn_error
= "unrecognized opcode";
8189 assert (strcmp (insn
->name
, str
) == 0);
8191 if (OPCODE_IS_MEMBER (insn
,
8193 | (file_ase_mips16
? INSN_MIPS16
: 0)
8194 | (mips_opts
.ase_mdmx
? INSN_MDMX
: 0)
8195 | (mips_opts
.ase_mips3d
? INSN_MIPS3D
: 0)),
8201 if (insn
->pinfo
!= INSN_MACRO
)
8203 if (mips_opts
.arch
== CPU_R4650
&& (insn
->pinfo
& FP_D
) != 0)
8209 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
]
8210 && strcmp (insn
->name
, insn
[1].name
) == 0)
8219 static char buf
[100];
8221 _("opcode not supported on this processor: %s (%s)"),
8222 mips_cpu_info_from_arch (mips_opts
.arch
)->name
,
8223 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
8233 ip
->insn_opcode
= insn
->match
;
8235 for (args
= insn
->args
;; ++args
)
8239 s
+= strspn (s
, " \t");
8243 case '\0': /* end of args */
8256 ip
->insn_opcode
|= lastregno
<< OP_SH_RS
;
8260 ip
->insn_opcode
|= lastregno
<< OP_SH_RT
;
8264 ip
->insn_opcode
|= lastregno
<< OP_SH_FT
;
8268 ip
->insn_opcode
|= lastregno
<< OP_SH_FS
;
8274 /* Handle optional base register.
8275 Either the base register is omitted or
8276 we must have a left paren. */
8277 /* This is dependent on the next operand specifier
8278 is a base register specification. */
8279 assert (args
[1] == 'b' || args
[1] == '5'
8280 || args
[1] == '-' || args
[1] == '4');
8284 case ')': /* these must match exactly */
8291 case '+': /* Opcode extension character. */
8294 case 'A': /* ins/ext position, becomes LSB. */
8297 my_getExpression (&imm_expr
, s
);
8298 check_absolute_expr (ip
, &imm_expr
);
8299 if ((unsigned long) imm_expr
.X_add_number
< limlo
8300 || (unsigned long) imm_expr
.X_add_number
> limhi
)
8302 as_bad (_("Improper position (%lu)"),
8303 (unsigned long) imm_expr
.X_add_number
);
8304 imm_expr
.X_add_number
= limlo
;
8306 lastpos
= imm_expr
.X_add_number
;
8307 ip
->insn_opcode
|= (imm_expr
.X_add_number
8308 & OP_MASK_SHAMT
) << OP_SH_SHAMT
;
8309 imm_expr
.X_op
= O_absent
;
8313 case 'B': /* ins size, becomes MSB. */
8316 my_getExpression (&imm_expr
, s
);
8317 check_absolute_expr (ip
, &imm_expr
);
8318 /* Check for negative input so that small negative numbers
8319 will not succeed incorrectly. The checks against
8320 (pos+size) transitively check "size" itself,
8321 assuming that "pos" is reasonable. */
8322 if ((long) imm_expr
.X_add_number
< 0
8323 || ((unsigned long) imm_expr
.X_add_number
8325 || ((unsigned long) imm_expr
.X_add_number
8328 as_bad (_("Improper insert size (%lu, position %lu)"),
8329 (unsigned long) imm_expr
.X_add_number
,
8330 (unsigned long) lastpos
);
8331 imm_expr
.X_add_number
= limlo
- lastpos
;
8333 ip
->insn_opcode
|= ((lastpos
+ imm_expr
.X_add_number
- 1)
8334 & OP_MASK_INSMSB
) << OP_SH_INSMSB
;
8335 imm_expr
.X_op
= O_absent
;
8339 case 'C': /* ext size, becomes MSBD. */
8342 my_getExpression (&imm_expr
, s
);
8343 check_absolute_expr (ip
, &imm_expr
);
8344 /* Check for negative input so that small negative numbers
8345 will not succeed incorrectly. The checks against
8346 (pos+size) transitively check "size" itself,
8347 assuming that "pos" is reasonable. */
8348 if ((long) imm_expr
.X_add_number
< 0
8349 || ((unsigned long) imm_expr
.X_add_number
8351 || ((unsigned long) imm_expr
.X_add_number
8354 as_bad (_("Improper extract size (%lu, position %lu)"),
8355 (unsigned long) imm_expr
.X_add_number
,
8356 (unsigned long) lastpos
);
8357 imm_expr
.X_add_number
= limlo
- lastpos
;
8359 ip
->insn_opcode
|= ((imm_expr
.X_add_number
- 1)
8360 & OP_MASK_EXTMSBD
) << OP_SH_EXTMSBD
;
8361 imm_expr
.X_op
= O_absent
;
8366 /* +D is for disassembly only; never match. */
8370 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8371 *args
, insn
->name
, insn
->args
);
8372 /* Further processing is fruitless. */
8377 case '<': /* must be at least one digit */
8379 * According to the manual, if the shift amount is greater
8380 * than 31 or less than 0, then the shift amount should be
8381 * mod 32. In reality the mips assembler issues an error.
8382 * We issue a warning and mask out all but the low 5 bits.
8384 my_getExpression (&imm_expr
, s
);
8385 check_absolute_expr (ip
, &imm_expr
);
8386 if ((unsigned long) imm_expr
.X_add_number
> 31)
8388 as_warn (_("Improper shift amount (%lu)"),
8389 (unsigned long) imm_expr
.X_add_number
);
8390 imm_expr
.X_add_number
&= OP_MASK_SHAMT
;
8392 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_SHAMT
;
8393 imm_expr
.X_op
= O_absent
;
8397 case '>': /* shift amount minus 32 */
8398 my_getExpression (&imm_expr
, s
);
8399 check_absolute_expr (ip
, &imm_expr
);
8400 if ((unsigned long) imm_expr
.X_add_number
< 32
8401 || (unsigned long) imm_expr
.X_add_number
> 63)
8403 ip
->insn_opcode
|= (imm_expr
.X_add_number
- 32) << OP_SH_SHAMT
;
8404 imm_expr
.X_op
= O_absent
;
8408 case 'k': /* cache code */
8409 case 'h': /* prefx code */
8410 my_getExpression (&imm_expr
, s
);
8411 check_absolute_expr (ip
, &imm_expr
);
8412 if ((unsigned long) imm_expr
.X_add_number
> 31)
8414 as_warn (_("Invalid value for `%s' (%lu)"),
8416 (unsigned long) imm_expr
.X_add_number
);
8417 imm_expr
.X_add_number
&= 0x1f;
8420 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CACHE
;
8422 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_PREFX
;
8423 imm_expr
.X_op
= O_absent
;
8427 case 'c': /* break code */
8428 my_getExpression (&imm_expr
, s
);
8429 check_absolute_expr (ip
, &imm_expr
);
8430 if ((unsigned long) imm_expr
.X_add_number
> 1023)
8432 as_warn (_("Illegal break code (%lu)"),
8433 (unsigned long) imm_expr
.X_add_number
);
8434 imm_expr
.X_add_number
&= OP_MASK_CODE
;
8436 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE
;
8437 imm_expr
.X_op
= O_absent
;
8441 case 'q': /* lower break code */
8442 my_getExpression (&imm_expr
, s
);
8443 check_absolute_expr (ip
, &imm_expr
);
8444 if ((unsigned long) imm_expr
.X_add_number
> 1023)
8446 as_warn (_("Illegal lower break code (%lu)"),
8447 (unsigned long) imm_expr
.X_add_number
);
8448 imm_expr
.X_add_number
&= OP_MASK_CODE2
;
8450 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE2
;
8451 imm_expr
.X_op
= O_absent
;
8455 case 'B': /* 20-bit syscall/break code. */
8456 my_getExpression (&imm_expr
, s
);
8457 check_absolute_expr (ip
, &imm_expr
);
8458 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE20
)
8459 as_warn (_("Illegal 20-bit code (%lu)"),
8460 (unsigned long) imm_expr
.X_add_number
);
8461 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE20
;
8462 imm_expr
.X_op
= O_absent
;
8466 case 'C': /* Coprocessor code */
8467 my_getExpression (&imm_expr
, s
);
8468 check_absolute_expr (ip
, &imm_expr
);
8469 if ((unsigned long) imm_expr
.X_add_number
>= (1 << 25))
8471 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8472 (unsigned long) imm_expr
.X_add_number
);
8473 imm_expr
.X_add_number
&= ((1 << 25) - 1);
8475 ip
->insn_opcode
|= imm_expr
.X_add_number
;
8476 imm_expr
.X_op
= O_absent
;
8480 case 'J': /* 19-bit wait code. */
8481 my_getExpression (&imm_expr
, s
);
8482 check_absolute_expr (ip
, &imm_expr
);
8483 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE19
)
8484 as_warn (_("Illegal 19-bit code (%lu)"),
8485 (unsigned long) imm_expr
.X_add_number
);
8486 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_CODE19
;
8487 imm_expr
.X_op
= O_absent
;
8491 case 'P': /* Performance register */
8492 my_getExpression (&imm_expr
, s
);
8493 check_absolute_expr (ip
, &imm_expr
);
8494 if (imm_expr
.X_add_number
!= 0 && imm_expr
.X_add_number
!= 1)
8496 as_warn (_("Invalid performance register (%lu)"),
8497 (unsigned long) imm_expr
.X_add_number
);
8498 imm_expr
.X_add_number
&= OP_MASK_PERFREG
;
8500 ip
->insn_opcode
|= (imm_expr
.X_add_number
<< OP_SH_PERFREG
);
8501 imm_expr
.X_op
= O_absent
;
8505 case 'b': /* base register */
8506 case 'd': /* destination register */
8507 case 's': /* source register */
8508 case 't': /* target register */
8509 case 'r': /* both target and source */
8510 case 'v': /* both dest and source */
8511 case 'w': /* both dest and target */
8512 case 'E': /* coprocessor target register */
8513 case 'G': /* coprocessor destination register */
8514 case 'K': /* 'rdhwr' destination register */
8515 case 'x': /* ignore register name */
8516 case 'z': /* must be zero register */
8517 case 'U': /* destination register (clo/clz). */
8532 while (ISDIGIT (*s
));
8534 as_bad (_("Invalid register number (%d)"), regno
);
8536 else if (*args
== 'E' || *args
== 'G' || *args
== 'K')
8540 if (s
[1] == 'r' && s
[2] == 'a')
8545 else if (s
[1] == 'f' && s
[2] == 'p')
8550 else if (s
[1] == 's' && s
[2] == 'p')
8555 else if (s
[1] == 'g' && s
[2] == 'p')
8560 else if (s
[1] == 'a' && s
[2] == 't')
8565 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '0')
8570 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '1')
8575 else if (s
[1] == 'z' && s
[2] == 'e' && s
[3] == 'r' && s
[4] == 'o')
8580 else if (itbl_have_entries
)
8585 p
= s
+ 1; /* advance past '$' */
8586 n
= itbl_get_field (&p
); /* n is name */
8588 /* See if this is a register defined in an
8590 if (itbl_get_reg_val (n
, &r
))
8592 /* Get_field advances to the start of
8593 the next field, so we need to back
8594 rack to the end of the last field. */
8598 s
= strchr (s
, '\0');
8612 as_warn (_("Used $at without \".set noat\""));
8618 if (c
== 'r' || c
== 'v' || c
== 'w')
8625 /* 'z' only matches $0. */
8626 if (c
== 'z' && regno
!= 0)
8629 /* Now that we have assembled one operand, we use the args string
8630 * to figure out where it goes in the instruction. */
8637 ip
->insn_opcode
|= regno
<< OP_SH_RS
;
8642 ip
->insn_opcode
|= regno
<< OP_SH_RD
;
8645 ip
->insn_opcode
|= regno
<< OP_SH_RD
;
8646 ip
->insn_opcode
|= regno
<< OP_SH_RT
;
8651 ip
->insn_opcode
|= regno
<< OP_SH_RT
;
8654 /* This case exists because on the r3000 trunc
8655 expands into a macro which requires a gp
8656 register. On the r6000 or r4000 it is
8657 assembled into a single instruction which
8658 ignores the register. Thus the insn version
8659 is MIPS_ISA2 and uses 'x', and the macro
8660 version is MIPS_ISA1 and uses 't'. */
8663 /* This case is for the div instruction, which
8664 acts differently if the destination argument
8665 is $0. This only matches $0, and is checked
8666 outside the switch. */
8669 /* Itbl operand; not yet implemented. FIXME ?? */
8671 /* What about all other operands like 'i', which
8672 can be specified in the opcode table? */
8682 ip
->insn_opcode
|= lastregno
<< OP_SH_RS
;
8685 ip
->insn_opcode
|= lastregno
<< OP_SH_RT
;
8690 case 'O': /* MDMX alignment immediate constant. */
8691 my_getExpression (&imm_expr
, s
);
8692 check_absolute_expr (ip
, &imm_expr
);
8693 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_ALN
)
8695 as_warn ("Improper align amount (%ld), using low bits",
8696 (long) imm_expr
.X_add_number
);
8697 imm_expr
.X_add_number
&= OP_MASK_ALN
;
8699 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_ALN
;
8700 imm_expr
.X_op
= O_absent
;
8704 case 'Q': /* MDMX vector, element sel, or const. */
8707 /* MDMX Immediate. */
8708 my_getExpression (&imm_expr
, s
);
8709 check_absolute_expr (ip
, &imm_expr
);
8710 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_FT
)
8712 as_warn (_("Invalid MDMX Immediate (%ld)"),
8713 (long) imm_expr
.X_add_number
);
8714 imm_expr
.X_add_number
&= OP_MASK_FT
;
8716 imm_expr
.X_add_number
&= OP_MASK_FT
;
8717 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
8718 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_QH
<< OP_SH_VSEL
;
8720 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_OB
<< OP_SH_VSEL
;
8721 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_FT
;
8722 imm_expr
.X_op
= O_absent
;
8726 /* Not MDMX Immediate. Fall through. */
8727 case 'X': /* MDMX destination register. */
8728 case 'Y': /* MDMX source register. */
8729 case 'Z': /* MDMX target register. */
8731 case 'D': /* floating point destination register */
8732 case 'S': /* floating point source register */
8733 case 'T': /* floating point target register */
8734 case 'R': /* floating point source register */
8738 /* Accept $fN for FP and MDMX register numbers, and in
8739 addition accept $vN for MDMX register numbers. */
8740 if ((s
[0] == '$' && s
[1] == 'f' && ISDIGIT (s
[2]))
8741 || (is_mdmx
!= 0 && s
[0] == '$' && s
[1] == 'v'
8752 while (ISDIGIT (*s
));
8755 as_bad (_("Invalid float register number (%d)"), regno
);
8757 if ((regno
& 1) != 0
8759 && ! (strcmp (str
, "mtc1") == 0
8760 || strcmp (str
, "mfc1") == 0
8761 || strcmp (str
, "lwc1") == 0
8762 || strcmp (str
, "swc1") == 0
8763 || strcmp (str
, "l.s") == 0
8764 || strcmp (str
, "s.s") == 0))
8765 as_warn (_("Float register should be even, was %d"),
8773 if (c
== 'V' || c
== 'W')
8784 ip
->insn_opcode
|= regno
<< OP_SH_FD
;
8789 ip
->insn_opcode
|= regno
<< OP_SH_FS
;
8792 /* This is like 'Z', but also needs to fix the MDMX
8793 vector/scalar select bits. Note that the
8794 scalar immediate case is handled above. */
8797 int is_qh
= (ip
->insn_opcode
& (1 << OP_SH_VSEL
));
8798 int max_el
= (is_qh
? 3 : 7);
8800 my_getExpression(&imm_expr
, s
);
8801 check_absolute_expr (ip
, &imm_expr
);
8803 if (imm_expr
.X_add_number
> max_el
)
8804 as_bad(_("Bad element selector %ld"),
8805 (long) imm_expr
.X_add_number
);
8806 imm_expr
.X_add_number
&= max_el
;
8807 ip
->insn_opcode
|= (imm_expr
.X_add_number
8811 as_warn(_("Expecting ']' found '%s'"), s
);
8817 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
8818 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_QH
8821 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_OB
<<
8828 ip
->insn_opcode
|= regno
<< OP_SH_FT
;
8831 ip
->insn_opcode
|= regno
<< OP_SH_FR
;
8841 ip
->insn_opcode
|= lastregno
<< OP_SH_FS
;
8844 ip
->insn_opcode
|= lastregno
<< OP_SH_FT
;
8850 my_getExpression (&imm_expr
, s
);
8851 if (imm_expr
.X_op
!= O_big
8852 && imm_expr
.X_op
!= O_constant
)
8853 insn_error
= _("absolute expression required");
8858 my_getExpression (&offset_expr
, s
);
8859 *imm_reloc
= BFD_RELOC_32
;
8872 unsigned char temp
[8];
8874 unsigned int length
;
8879 /* These only appear as the last operand in an
8880 instruction, and every instruction that accepts
8881 them in any variant accepts them in all variants.
8882 This means we don't have to worry about backing out
8883 any changes if the instruction does not match.
8885 The difference between them is the size of the
8886 floating point constant and where it goes. For 'F'
8887 and 'L' the constant is 64 bits; for 'f' and 'l' it
8888 is 32 bits. Where the constant is placed is based
8889 on how the MIPS assembler does things:
8892 f -- immediate value
8895 The .lit4 and .lit8 sections are only used if
8896 permitted by the -G argument.
8898 When generating embedded PIC code, we use the
8899 .lit8 section but not the .lit4 section (we can do
8900 .lit4 inline easily; we need to put .lit8
8901 somewhere in the data segment, and using .lit8
8902 permits the linker to eventually combine identical
8905 The code below needs to know whether the target register
8906 is 32 or 64 bits wide. It relies on the fact 'f' and
8907 'F' are used with GPR-based instructions and 'l' and
8908 'L' are used with FPR-based instructions. */
8910 f64
= *args
== 'F' || *args
== 'L';
8911 using_gprs
= *args
== 'F' || *args
== 'f';
8913 save_in
= input_line_pointer
;
8914 input_line_pointer
= s
;
8915 err
= md_atof (f64
? 'd' : 'f', (char *) temp
, &len
);
8917 s
= input_line_pointer
;
8918 input_line_pointer
= save_in
;
8919 if (err
!= NULL
&& *err
!= '\0')
8921 as_bad (_("Bad floating point constant: %s"), err
);
8922 memset (temp
, '\0', sizeof temp
);
8923 length
= f64
? 8 : 4;
8926 assert (length
== (unsigned) (f64
? 8 : 4));
8930 && (! USE_GLOBAL_POINTER_OPT
8931 || mips_pic
== EMBEDDED_PIC
8932 || g_switch_value
< 4
8933 || (temp
[0] == 0 && temp
[1] == 0)
8934 || (temp
[2] == 0 && temp
[3] == 0))))
8936 imm_expr
.X_op
= O_constant
;
8937 if (! target_big_endian
)
8938 imm_expr
.X_add_number
= bfd_getl32 (temp
);
8940 imm_expr
.X_add_number
= bfd_getb32 (temp
);
8943 && ! mips_disable_float_construction
8944 /* Constants can only be constructed in GPRs and
8945 copied to FPRs if the GPRs are at least as wide
8946 as the FPRs. Force the constant into memory if
8947 we are using 64-bit FPRs but the GPRs are only
8950 || ! (HAVE_64BIT_FPRS
&& HAVE_32BIT_GPRS
))
8951 && ((temp
[0] == 0 && temp
[1] == 0)
8952 || (temp
[2] == 0 && temp
[3] == 0))
8953 && ((temp
[4] == 0 && temp
[5] == 0)
8954 || (temp
[6] == 0 && temp
[7] == 0)))
8956 /* The value is simple enough to load with a couple of
8957 instructions. If using 32-bit registers, set
8958 imm_expr to the high order 32 bits and offset_expr to
8959 the low order 32 bits. Otherwise, set imm_expr to
8960 the entire 64 bit constant. */
8961 if (using_gprs
? HAVE_32BIT_GPRS
: HAVE_32BIT_FPRS
)
8963 imm_expr
.X_op
= O_constant
;
8964 offset_expr
.X_op
= O_constant
;
8965 if (! target_big_endian
)
8967 imm_expr
.X_add_number
= bfd_getl32 (temp
+ 4);
8968 offset_expr
.X_add_number
= bfd_getl32 (temp
);
8972 imm_expr
.X_add_number
= bfd_getb32 (temp
);
8973 offset_expr
.X_add_number
= bfd_getb32 (temp
+ 4);
8975 if (offset_expr
.X_add_number
== 0)
8976 offset_expr
.X_op
= O_absent
;
8978 else if (sizeof (imm_expr
.X_add_number
) > 4)
8980 imm_expr
.X_op
= O_constant
;
8981 if (! target_big_endian
)
8982 imm_expr
.X_add_number
= bfd_getl64 (temp
);
8984 imm_expr
.X_add_number
= bfd_getb64 (temp
);
8988 imm_expr
.X_op
= O_big
;
8989 imm_expr
.X_add_number
= 4;
8990 if (! target_big_endian
)
8992 generic_bignum
[0] = bfd_getl16 (temp
);
8993 generic_bignum
[1] = bfd_getl16 (temp
+ 2);
8994 generic_bignum
[2] = bfd_getl16 (temp
+ 4);
8995 generic_bignum
[3] = bfd_getl16 (temp
+ 6);
8999 generic_bignum
[0] = bfd_getb16 (temp
+ 6);
9000 generic_bignum
[1] = bfd_getb16 (temp
+ 4);
9001 generic_bignum
[2] = bfd_getb16 (temp
+ 2);
9002 generic_bignum
[3] = bfd_getb16 (temp
);
9008 const char *newname
;
9011 /* Switch to the right section. */
9013 subseg
= now_subseg
;
9016 default: /* unused default case avoids warnings. */
9018 newname
= RDATA_SECTION_NAME
;
9019 if ((USE_GLOBAL_POINTER_OPT
&& g_switch_value
>= 8)
9020 || mips_pic
== EMBEDDED_PIC
)
9024 if (mips_pic
== EMBEDDED_PIC
)
9027 newname
= RDATA_SECTION_NAME
;
9030 assert (!USE_GLOBAL_POINTER_OPT
9031 || g_switch_value
>= 4);
9035 new_seg
= subseg_new (newname
, (subsegT
) 0);
9036 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
9037 bfd_set_section_flags (stdoutput
, new_seg
,
9042 frag_align (*args
== 'l' ? 2 : 3, 0, 0);
9043 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
9044 && strcmp (TARGET_OS
, "elf") != 0)
9045 record_alignment (new_seg
, 4);
9047 record_alignment (new_seg
, *args
== 'l' ? 2 : 3);
9049 as_bad (_("Can't use floating point insn in this section"));
9051 /* Set the argument to the current address in the
9053 offset_expr
.X_op
= O_symbol
;
9054 offset_expr
.X_add_symbol
=
9055 symbol_new ("L0\001", now_seg
,
9056 (valueT
) frag_now_fix (), frag_now
);
9057 offset_expr
.X_add_number
= 0;
9059 /* Put the floating point number into the section. */
9060 p
= frag_more ((int) length
);
9061 memcpy (p
, temp
, length
);
9063 /* Switch back to the original section. */
9064 subseg_set (seg
, subseg
);
9069 case 'i': /* 16 bit unsigned immediate */
9070 case 'j': /* 16 bit signed immediate */
9071 *imm_reloc
= BFD_RELOC_LO16
;
9072 if (my_getSmallExpression (&imm_expr
, imm_reloc
, s
) == 0)
9075 offsetT minval
, maxval
;
9077 more
= (insn
+ 1 < &mips_opcodes
[NUMOPCODES
]
9078 && strcmp (insn
->name
, insn
[1].name
) == 0);
9080 /* If the expression was written as an unsigned number,
9081 only treat it as signed if there are no more
9085 && sizeof (imm_expr
.X_add_number
) <= 4
9086 && imm_expr
.X_op
== O_constant
9087 && imm_expr
.X_add_number
< 0
9088 && imm_expr
.X_unsigned
9092 /* For compatibility with older assemblers, we accept
9093 0x8000-0xffff as signed 16-bit numbers when only
9094 signed numbers are allowed. */
9096 minval
= 0, maxval
= 0xffff;
9098 minval
= -0x8000, maxval
= 0x7fff;
9100 minval
= -0x8000, maxval
= 0xffff;
9102 if (imm_expr
.X_op
!= O_constant
9103 || imm_expr
.X_add_number
< minval
9104 || imm_expr
.X_add_number
> maxval
)
9108 if (imm_expr
.X_op
== O_constant
9109 || imm_expr
.X_op
== O_big
)
9110 as_bad (_("expression out of range"));
9116 case 'o': /* 16 bit offset */
9117 /* Check whether there is only a single bracketed expression
9118 left. If so, it must be the base register and the
9119 constant must be zero. */
9120 if (*s
== '(' && strchr (s
+ 1, '(') == 0)
9122 offset_expr
.X_op
= O_constant
;
9123 offset_expr
.X_add_number
= 0;
9127 /* If this value won't fit into a 16 bit offset, then go
9128 find a macro that will generate the 32 bit offset
9130 if (my_getSmallExpression (&offset_expr
, offset_reloc
, s
) == 0
9131 && (offset_expr
.X_op
!= O_constant
9132 || offset_expr
.X_add_number
>= 0x8000
9133 || offset_expr
.X_add_number
< -0x8000))
9139 case 'p': /* pc relative offset */
9140 *offset_reloc
= BFD_RELOC_16_PCREL_S2
;
9141 my_getExpression (&offset_expr
, s
);
9145 case 'u': /* upper 16 bits */
9146 if (my_getSmallExpression (&imm_expr
, imm_reloc
, s
) == 0
9147 && imm_expr
.X_op
== O_constant
9148 && (imm_expr
.X_add_number
< 0
9149 || imm_expr
.X_add_number
>= 0x10000))
9150 as_bad (_("lui expression not in range 0..65535"));
9154 case 'a': /* 26 bit address */
9155 my_getExpression (&offset_expr
, s
);
9157 *offset_reloc
= BFD_RELOC_MIPS_JMP
;
9160 case 'N': /* 3 bit branch condition code */
9161 case 'M': /* 3 bit compare condition code */
9162 if (strncmp (s
, "$fcc", 4) != 0)
9172 while (ISDIGIT (*s
));
9174 as_bad (_("invalid condition code register $fcc%d"), regno
);
9176 ip
->insn_opcode
|= regno
<< OP_SH_BCC
;
9178 ip
->insn_opcode
|= regno
<< OP_SH_CCC
;
9182 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
9193 while (ISDIGIT (*s
));
9196 c
= 8; /* Invalid sel value. */
9199 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9200 ip
->insn_opcode
|= c
;
9204 /* Must be at least one digit. */
9205 my_getExpression (&imm_expr
, s
);
9206 check_absolute_expr (ip
, &imm_expr
);
9208 if ((unsigned long) imm_expr
.X_add_number
9209 > (unsigned long) OP_MASK_VECBYTE
)
9211 as_bad (_("bad byte vector index (%ld)"),
9212 (long) imm_expr
.X_add_number
);
9213 imm_expr
.X_add_number
= 0;
9216 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_VECBYTE
;
9217 imm_expr
.X_op
= O_absent
;
9222 my_getExpression (&imm_expr
, s
);
9223 check_absolute_expr (ip
, &imm_expr
);
9225 if ((unsigned long) imm_expr
.X_add_number
9226 > (unsigned long) OP_MASK_VECALIGN
)
9228 as_bad (_("bad byte vector index (%ld)"),
9229 (long) imm_expr
.X_add_number
);
9230 imm_expr
.X_add_number
= 0;
9233 ip
->insn_opcode
|= imm_expr
.X_add_number
<< OP_SH_VECALIGN
;
9234 imm_expr
.X_op
= O_absent
;
9239 as_bad (_("bad char = '%c'\n"), *args
);
9244 /* Args don't match. */
9245 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
9246 !strcmp (insn
->name
, insn
[1].name
))
9250 insn_error
= _("illegal operands");
9255 insn_error
= _("illegal operands");
9260 /* This routine assembles an instruction into its binary format when
9261 assembling for the mips16. As a side effect, it sets one of the
9262 global variables imm_reloc or offset_reloc to the type of
9263 relocation to do if one of the operands is an address expression.
9264 It also sets mips16_small and mips16_ext if the user explicitly
9265 requested a small or extended instruction. */
9268 mips16_ip (char *str
, struct mips_cl_insn
*ip
)
9272 struct mips_opcode
*insn
;
9275 unsigned int lastregno
= 0;
9280 mips16_small
= FALSE
;
9283 for (s
= str
; ISLOWER (*s
); ++s
)
9295 if (s
[1] == 't' && s
[2] == ' ')
9298 mips16_small
= TRUE
;
9302 else if (s
[1] == 'e' && s
[2] == ' ')
9311 insn_error
= _("unknown opcode");
9315 if (mips_opts
.noautoextend
&& ! mips16_ext
)
9316 mips16_small
= TRUE
;
9318 if ((insn
= (struct mips_opcode
*) hash_find (mips16_op_hash
, str
)) == NULL
)
9320 insn_error
= _("unrecognized opcode");
9327 assert (strcmp (insn
->name
, str
) == 0);
9330 ip
->insn_opcode
= insn
->match
;
9331 ip
->use_extend
= FALSE
;
9332 imm_expr
.X_op
= O_absent
;
9333 imm_reloc
[0] = BFD_RELOC_UNUSED
;
9334 imm_reloc
[1] = BFD_RELOC_UNUSED
;
9335 imm_reloc
[2] = BFD_RELOC_UNUSED
;
9336 offset_expr
.X_op
= O_absent
;
9337 offset_reloc
[0] = BFD_RELOC_UNUSED
;
9338 offset_reloc
[1] = BFD_RELOC_UNUSED
;
9339 offset_reloc
[2] = BFD_RELOC_UNUSED
;
9340 for (args
= insn
->args
; 1; ++args
)
9347 /* In this switch statement we call break if we did not find
9348 a match, continue if we did find a match, or return if we
9357 /* Stuff the immediate value in now, if we can. */
9358 if (imm_expr
.X_op
== O_constant
9359 && *imm_reloc
> BFD_RELOC_UNUSED
9360 && insn
->pinfo
!= INSN_MACRO
)
9362 mips16_immed (NULL
, 0, *imm_reloc
- BFD_RELOC_UNUSED
,
9363 imm_expr
.X_add_number
, TRUE
, mips16_small
,
9364 mips16_ext
, &ip
->insn_opcode
,
9365 &ip
->use_extend
, &ip
->extend
);
9366 imm_expr
.X_op
= O_absent
;
9367 *imm_reloc
= BFD_RELOC_UNUSED
;
9381 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RX
;
9384 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RY
;
9400 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RX
;
9402 ip
->insn_opcode
|= lastregno
<< MIPS16OP_SH_RY
;
9429 while (ISDIGIT (*s
));
9432 as_bad (_("invalid register number (%d)"), regno
);
9438 if (s
[1] == 'r' && s
[2] == 'a')
9443 else if (s
[1] == 'f' && s
[2] == 'p')
9448 else if (s
[1] == 's' && s
[2] == 'p')
9453 else if (s
[1] == 'g' && s
[2] == 'p')
9458 else if (s
[1] == 'a' && s
[2] == 't')
9463 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '0')
9468 else if (s
[1] == 'k' && s
[2] == 't' && s
[3] == '1')
9473 else if (s
[1] == 'z' && s
[2] == 'e' && s
[3] == 'r' && s
[4] == 'o')
9486 if (c
== 'v' || c
== 'w')
9488 regno
= mips16_to_32_reg_map
[lastregno
];
9502 regno
= mips32_to_16_reg_map
[regno
];
9507 regno
= ILLEGAL_REG
;
9512 regno
= ILLEGAL_REG
;
9517 regno
= ILLEGAL_REG
;
9522 if (regno
== AT
&& ! mips_opts
.noat
)
9523 as_warn (_("used $at without \".set noat\""));
9530 if (regno
== ILLEGAL_REG
)
9537 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RX
;
9541 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RY
;
9544 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_RZ
;
9547 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_MOVE32Z
;
9553 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_REGR32
;
9556 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
9557 ip
->insn_opcode
|= regno
<< MIPS16OP_SH_REG32R
;
9567 if (strncmp (s
, "$pc", 3) == 0)
9591 && strncmp (s
+ 1, "gprel(", sizeof "gprel(" - 1) == 0)
9593 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9594 and generate the appropriate reloc. If the text
9595 inside %gprel is not a symbol name with an
9596 optional offset, then we generate a normal reloc
9597 and will probably fail later. */
9598 my_getExpression (&imm_expr
, s
+ sizeof "%gprel" - 1);
9599 if (imm_expr
.X_op
== O_symbol
)
9602 *imm_reloc
= BFD_RELOC_MIPS16_GPREL
;
9604 ip
->use_extend
= TRUE
;
9611 /* Just pick up a normal expression. */
9612 my_getExpression (&imm_expr
, s
);
9615 if (imm_expr
.X_op
== O_register
)
9617 /* What we thought was an expression turned out to
9620 if (s
[0] == '(' && args
[1] == '(')
9622 /* It looks like the expression was omitted
9623 before a register indirection, which means
9624 that the expression is implicitly zero. We
9625 still set up imm_expr, so that we handle
9626 explicit extensions correctly. */
9627 imm_expr
.X_op
= O_constant
;
9628 imm_expr
.X_add_number
= 0;
9629 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9636 /* We need to relax this instruction. */
9637 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9646 /* We use offset_reloc rather than imm_reloc for the PC
9647 relative operands. This lets macros with both
9648 immediate and address operands work correctly. */
9649 my_getExpression (&offset_expr
, s
);
9651 if (offset_expr
.X_op
== O_register
)
9654 /* We need to relax this instruction. */
9655 *offset_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
9659 case '6': /* break code */
9660 my_getExpression (&imm_expr
, s
);
9661 check_absolute_expr (ip
, &imm_expr
);
9662 if ((unsigned long) imm_expr
.X_add_number
> 63)
9664 as_warn (_("Invalid value for `%s' (%lu)"),
9666 (unsigned long) imm_expr
.X_add_number
);
9667 imm_expr
.X_add_number
&= 0x3f;
9669 ip
->insn_opcode
|= imm_expr
.X_add_number
<< MIPS16OP_SH_IMM6
;
9670 imm_expr
.X_op
= O_absent
;
9674 case 'a': /* 26 bit address */
9675 my_getExpression (&offset_expr
, s
);
9677 *offset_reloc
= BFD_RELOC_MIPS16_JMP
;
9678 ip
->insn_opcode
<<= 16;
9681 case 'l': /* register list for entry macro */
9682 case 'L': /* register list for exit macro */
9692 int freg
, reg1
, reg2
;
9694 while (*s
== ' ' || *s
== ',')
9698 as_bad (_("can't parse register list"));
9710 while (ISDIGIT (*s
))
9732 as_bad (_("invalid register list"));
9737 while (ISDIGIT (*s
))
9744 if (freg
&& reg1
== 0 && reg2
== 0 && c
== 'L')
9749 else if (freg
&& reg1
== 0 && reg2
== 1 && c
== 'L')
9754 else if (reg1
== 4 && reg2
>= 4 && reg2
<= 7 && c
!= 'L')
9755 mask
|= (reg2
- 3) << 3;
9756 else if (reg1
== 16 && reg2
>= 16 && reg2
<= 17)
9757 mask
|= (reg2
- 15) << 1;
9758 else if (reg1
== RA
&& reg2
== RA
)
9762 as_bad (_("invalid register list"));
9766 /* The mask is filled in in the opcode table for the
9767 benefit of the disassembler. We remove it before
9768 applying the actual mask. */
9769 ip
->insn_opcode
&= ~ ((7 << 3) << MIPS16OP_SH_IMM6
);
9770 ip
->insn_opcode
|= mask
<< MIPS16OP_SH_IMM6
;
9774 case 'e': /* extend code */
9775 my_getExpression (&imm_expr
, s
);
9776 check_absolute_expr (ip
, &imm_expr
);
9777 if ((unsigned long) imm_expr
.X_add_number
> 0x7ff)
9779 as_warn (_("Invalid value for `%s' (%lu)"),
9781 (unsigned long) imm_expr
.X_add_number
);
9782 imm_expr
.X_add_number
&= 0x7ff;
9784 ip
->insn_opcode
|= imm_expr
.X_add_number
;
9785 imm_expr
.X_op
= O_absent
;
9795 /* Args don't match. */
9796 if (insn
+ 1 < &mips16_opcodes
[bfd_mips16_num_opcodes
] &&
9797 strcmp (insn
->name
, insn
[1].name
) == 0)
9804 insn_error
= _("illegal operands");
9810 /* This structure holds information we know about a mips16 immediate
9813 struct mips16_immed_operand
9815 /* The type code used in the argument string in the opcode table. */
9817 /* The number of bits in the short form of the opcode. */
9819 /* The number of bits in the extended form of the opcode. */
9821 /* The amount by which the short form is shifted when it is used;
9822 for example, the sw instruction has a shift count of 2. */
9824 /* The amount by which the short form is shifted when it is stored
9825 into the instruction code. */
9827 /* Non-zero if the short form is unsigned. */
9829 /* Non-zero if the extended form is unsigned. */
9831 /* Non-zero if the value is PC relative. */
9835 /* The mips16 immediate operand types. */
9837 static const struct mips16_immed_operand mips16_immed_operands
[] =
9839 { '<', 3, 5, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
9840 { '>', 3, 5, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
9841 { '[', 3, 6, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
9842 { ']', 3, 6, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
9843 { '4', 4, 15, 0, MIPS16OP_SH_IMM4
, 0, 0, 0 },
9844 { '5', 5, 16, 0, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9845 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9846 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9847 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 0 },
9848 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5
, 0, 0, 0 },
9849 { '8', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9850 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9851 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8
, 1, 0, 0 },
9852 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 1, 0 },
9853 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 0 },
9854 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8
, 0, 0, 0 },
9855 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
9856 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
9857 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 1 },
9858 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 1 },
9859 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 1 }
9862 #define MIPS16_NUM_IMMED \
9863 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9865 /* Handle a mips16 instruction with an immediate value. This or's the
9866 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9867 whether an extended value is needed; if one is needed, it sets
9868 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9869 If SMALL is true, an unextended opcode was explicitly requested.
9870 If EXT is true, an extended opcode was explicitly requested. If
9871 WARN is true, warn if EXT does not match reality. */
9874 mips16_immed (char *file
, unsigned int line
, int type
, offsetT val
,
9875 bfd_boolean warn
, bfd_boolean small
, bfd_boolean ext
,
9876 unsigned long *insn
, bfd_boolean
*use_extend
,
9877 unsigned short *extend
)
9879 register const struct mips16_immed_operand
*op
;
9880 int mintiny
, maxtiny
;
9881 bfd_boolean needext
;
9883 op
= mips16_immed_operands
;
9884 while (op
->type
!= type
)
9887 assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
9892 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
9895 maxtiny
= 1 << op
->nbits
;
9900 maxtiny
= (1 << op
->nbits
) - 1;
9905 mintiny
= - (1 << (op
->nbits
- 1));
9906 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
9909 /* Branch offsets have an implicit 0 in the lowest bit. */
9910 if (type
== 'p' || type
== 'q')
9913 if ((val
& ((1 << op
->shift
) - 1)) != 0
9914 || val
< (mintiny
<< op
->shift
)
9915 || val
> (maxtiny
<< op
->shift
))
9920 if (warn
&& ext
&& ! needext
)
9921 as_warn_where (file
, line
,
9922 _("extended operand requested but not required"));
9923 if (small
&& needext
)
9924 as_bad_where (file
, line
, _("invalid unextended operand value"));
9926 if (small
|| (! ext
&& ! needext
))
9930 *use_extend
= FALSE
;
9931 insnval
= ((val
>> op
->shift
) & ((1 << op
->nbits
) - 1));
9932 insnval
<<= op
->op_shift
;
9937 long minext
, maxext
;
9943 maxext
= (1 << op
->extbits
) - 1;
9947 minext
= - (1 << (op
->extbits
- 1));
9948 maxext
= (1 << (op
->extbits
- 1)) - 1;
9950 if (val
< minext
|| val
> maxext
)
9951 as_bad_where (file
, line
,
9952 _("operand value out of range for instruction"));
9955 if (op
->extbits
== 16)
9957 extval
= ((val
>> 11) & 0x1f) | (val
& 0x7e0);
9960 else if (op
->extbits
== 15)
9962 extval
= ((val
>> 11) & 0xf) | (val
& 0x7f0);
9967 extval
= ((val
& 0x1f) << 6) | (val
& 0x20);
9971 *extend
= (unsigned short) extval
;
9976 static const struct percent_op_match
9979 bfd_reloc_code_real_type reloc
;
9982 {"%lo", BFD_RELOC_LO16
},
9984 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16
},
9985 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16
},
9986 {"%call16", BFD_RELOC_MIPS_CALL16
},
9987 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP
},
9988 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE
},
9989 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST
},
9990 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16
},
9991 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16
},
9992 {"%got", BFD_RELOC_MIPS_GOT16
},
9993 {"%gp_rel", BFD_RELOC_GPREL16
},
9994 {"%half", BFD_RELOC_16
},
9995 {"%highest", BFD_RELOC_MIPS_HIGHEST
},
9996 {"%higher", BFD_RELOC_MIPS_HIGHER
},
9997 {"%neg", BFD_RELOC_MIPS_SUB
},
9999 {"%hi", BFD_RELOC_HI16_S
}
10003 /* Return true if *STR points to a relocation operator. When returning true,
10004 move *STR over the operator and store its relocation code in *RELOC.
10005 Leave both *STR and *RELOC alone when returning false. */
10008 parse_relocation (char **str
, bfd_reloc_code_real_type
*reloc
)
10012 for (i
= 0; i
< ARRAY_SIZE (percent_op
); i
++)
10013 if (strncasecmp (*str
, percent_op
[i
].str
, strlen (percent_op
[i
].str
)) == 0)
10015 *str
+= strlen (percent_op
[i
].str
);
10016 *reloc
= percent_op
[i
].reloc
;
10018 /* Check whether the output BFD supports this relocation.
10019 If not, issue an error and fall back on something safe. */
10020 if (!bfd_reloc_type_lookup (stdoutput
, percent_op
[i
].reloc
))
10022 as_bad ("relocation %s isn't supported by the current ABI",
10023 percent_op
[i
].str
);
10024 *reloc
= BFD_RELOC_LO16
;
10032 /* Parse string STR as a 16-bit relocatable operand. Store the
10033 expression in *EP and the relocations in the array starting
10034 at RELOC. Return the number of relocation operators used.
10036 On exit, EXPR_END points to the first character after the expression.
10037 If no relocation operators are used, RELOC[0] is set to BFD_RELOC_LO16. */
10040 my_getSmallExpression (expressionS
*ep
, bfd_reloc_code_real_type
*reloc
,
10043 bfd_reloc_code_real_type reversed_reloc
[3];
10044 size_t reloc_index
, i
;
10045 int crux_depth
, str_depth
;
10048 /* Search for the start of the main expression, recoding relocations
10049 in REVERSED_RELOC. End the loop with CRUX pointing to the start
10050 of the main expression and with CRUX_DEPTH containing the number
10051 of open brackets at that point. */
10058 crux_depth
= str_depth
;
10060 /* Skip over whitespace and brackets, keeping count of the number
10062 while (*str
== ' ' || *str
== '\t' || *str
== '(')
10067 && reloc_index
< (HAVE_NEWABI
? 3 : 1)
10068 && parse_relocation (&str
, &reversed_reloc
[reloc_index
]));
10070 my_getExpression (ep
, crux
);
10073 /* Match every open bracket. */
10074 while (crux_depth
> 0 && (*str
== ')' || *str
== ' ' || *str
== '\t'))
10078 if (crux_depth
> 0)
10079 as_bad ("unclosed '('");
10083 if (reloc_index
== 0)
10084 reloc
[0] = BFD_RELOC_LO16
;
10087 prev_reloc_op_frag
= frag_now
;
10088 for (i
= 0; i
< reloc_index
; i
++)
10089 reloc
[i
] = reversed_reloc
[reloc_index
- 1 - i
];
10092 return reloc_index
;
10096 my_getExpression (expressionS
*ep
, char *str
)
10101 save_in
= input_line_pointer
;
10102 input_line_pointer
= str
;
10104 expr_end
= input_line_pointer
;
10105 input_line_pointer
= save_in
;
10107 /* If we are in mips16 mode, and this is an expression based on `.',
10108 then we bump the value of the symbol by 1 since that is how other
10109 text symbols are handled. We don't bother to handle complex
10110 expressions, just `.' plus or minus a constant. */
10111 if (mips_opts
.mips16
10112 && ep
->X_op
== O_symbol
10113 && strcmp (S_GET_NAME (ep
->X_add_symbol
), FAKE_LABEL_NAME
) == 0
10114 && S_GET_SEGMENT (ep
->X_add_symbol
) == now_seg
10115 && symbol_get_frag (ep
->X_add_symbol
) == frag_now
10116 && symbol_constant_p (ep
->X_add_symbol
)
10117 && (val
= S_GET_VALUE (ep
->X_add_symbol
)) == frag_now_fix ())
10118 S_SET_VALUE (ep
->X_add_symbol
, val
+ 1);
10121 /* Turn a string in input_line_pointer into a floating point constant
10122 of type TYPE, and store the appropriate bytes in *LITP. The number
10123 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10124 returned, or NULL on OK. */
10127 md_atof (int type
, char *litP
, int *sizeP
)
10130 LITTLENUM_TYPE words
[4];
10146 return _("bad call to md_atof");
10149 t
= atof_ieee (input_line_pointer
, type
, words
);
10151 input_line_pointer
= t
;
10155 if (! target_big_endian
)
10157 for (i
= prec
- 1; i
>= 0; i
--)
10159 md_number_to_chars (litP
, words
[i
], 2);
10165 for (i
= 0; i
< prec
; i
++)
10167 md_number_to_chars (litP
, words
[i
], 2);
10176 md_number_to_chars (char *buf
, valueT val
, int n
)
10178 if (target_big_endian
)
10179 number_to_chars_bigendian (buf
, val
, n
);
10181 number_to_chars_littleendian (buf
, val
, n
);
10185 static int support_64bit_objects(void)
10187 const char **list
, **l
;
10190 list
= bfd_target_list ();
10191 for (l
= list
; *l
!= NULL
; l
++)
10193 /* This is traditional mips */
10194 if (strcmp (*l
, "elf64-tradbigmips") == 0
10195 || strcmp (*l
, "elf64-tradlittlemips") == 0)
10197 if (strcmp (*l
, "elf64-bigmips") == 0
10198 || strcmp (*l
, "elf64-littlemips") == 0)
10201 yes
= (*l
!= NULL
);
10205 #endif /* OBJ_ELF */
10207 const char *md_shortopts
= "nO::g::G:";
10209 struct option md_longopts
[] =
10211 /* Options which specify architecture. */
10212 #define OPTION_ARCH_BASE (OPTION_MD_BASE)
10213 #define OPTION_MARCH (OPTION_ARCH_BASE + 0)
10214 {"march", required_argument
, NULL
, OPTION_MARCH
},
10215 #define OPTION_MTUNE (OPTION_ARCH_BASE + 1)
10216 {"mtune", required_argument
, NULL
, OPTION_MTUNE
},
10217 #define OPTION_MIPS1 (OPTION_ARCH_BASE + 2)
10218 {"mips0", no_argument
, NULL
, OPTION_MIPS1
},
10219 {"mips1", no_argument
, NULL
, OPTION_MIPS1
},
10220 #define OPTION_MIPS2 (OPTION_ARCH_BASE + 3)
10221 {"mips2", no_argument
, NULL
, OPTION_MIPS2
},
10222 #define OPTION_MIPS3 (OPTION_ARCH_BASE + 4)
10223 {"mips3", no_argument
, NULL
, OPTION_MIPS3
},
10224 #define OPTION_MIPS4 (OPTION_ARCH_BASE + 5)
10225 {"mips4", no_argument
, NULL
, OPTION_MIPS4
},
10226 #define OPTION_MIPS5 (OPTION_ARCH_BASE + 6)
10227 {"mips5", no_argument
, NULL
, OPTION_MIPS5
},
10228 #define OPTION_MIPS32 (OPTION_ARCH_BASE + 7)
10229 {"mips32", no_argument
, NULL
, OPTION_MIPS32
},
10230 #define OPTION_MIPS64 (OPTION_ARCH_BASE + 8)
10231 {"mips64", no_argument
, NULL
, OPTION_MIPS64
},
10232 #define OPTION_MIPS32R2 (OPTION_ARCH_BASE + 9)
10233 {"mips32r2", no_argument
, NULL
, OPTION_MIPS32R2
},
10235 /* Options which specify Application Specific Extensions (ASEs). */
10236 #define OPTION_ASE_BASE (OPTION_ARCH_BASE + 10)
10237 #define OPTION_MIPS16 (OPTION_ASE_BASE + 0)
10238 {"mips16", no_argument
, NULL
, OPTION_MIPS16
},
10239 #define OPTION_NO_MIPS16 (OPTION_ASE_BASE + 1)
10240 {"no-mips16", no_argument
, NULL
, OPTION_NO_MIPS16
},
10241 #define OPTION_MIPS3D (OPTION_ASE_BASE + 2)
10242 {"mips3d", no_argument
, NULL
, OPTION_MIPS3D
},
10243 #define OPTION_NO_MIPS3D (OPTION_ASE_BASE + 3)
10244 {"no-mips3d", no_argument
, NULL
, OPTION_NO_MIPS3D
},
10245 #define OPTION_MDMX (OPTION_ASE_BASE + 4)
10246 {"mdmx", no_argument
, NULL
, OPTION_MDMX
},
10247 #define OPTION_NO_MDMX (OPTION_ASE_BASE + 5)
10248 {"no-mdmx", no_argument
, NULL
, OPTION_NO_MDMX
},
10250 /* Old-style architecture options. Don't add more of these. */
10251 #define OPTION_COMPAT_ARCH_BASE (OPTION_ASE_BASE + 6)
10252 #define OPTION_M4650 (OPTION_COMPAT_ARCH_BASE + 0)
10253 {"m4650", no_argument
, NULL
, OPTION_M4650
},
10254 #define OPTION_NO_M4650 (OPTION_COMPAT_ARCH_BASE + 1)
10255 {"no-m4650", no_argument
, NULL
, OPTION_NO_M4650
},
10256 #define OPTION_M4010 (OPTION_COMPAT_ARCH_BASE + 2)
10257 {"m4010", no_argument
, NULL
, OPTION_M4010
},
10258 #define OPTION_NO_M4010 (OPTION_COMPAT_ARCH_BASE + 3)
10259 {"no-m4010", no_argument
, NULL
, OPTION_NO_M4010
},
10260 #define OPTION_M4100 (OPTION_COMPAT_ARCH_BASE + 4)
10261 {"m4100", no_argument
, NULL
, OPTION_M4100
},
10262 #define OPTION_NO_M4100 (OPTION_COMPAT_ARCH_BASE + 5)
10263 {"no-m4100", no_argument
, NULL
, OPTION_NO_M4100
},
10264 #define OPTION_M3900 (OPTION_COMPAT_ARCH_BASE + 6)
10265 {"m3900", no_argument
, NULL
, OPTION_M3900
},
10266 #define OPTION_NO_M3900 (OPTION_COMPAT_ARCH_BASE + 7)
10267 {"no-m3900", no_argument
, NULL
, OPTION_NO_M3900
},
10269 /* Options which enable bug fixes. */
10270 #define OPTION_FIX_BASE (OPTION_COMPAT_ARCH_BASE + 8)
10271 #define OPTION_M7000_HILO_FIX (OPTION_FIX_BASE + 0)
10272 {"mfix7000", no_argument
, NULL
, OPTION_M7000_HILO_FIX
},
10273 #define OPTION_MNO_7000_HILO_FIX (OPTION_FIX_BASE + 1)
10274 {"no-fix-7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
10275 {"mno-fix7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
10276 #define OPTION_FIX_VR4122 (OPTION_FIX_BASE + 2)
10277 #define OPTION_NO_FIX_VR4122 (OPTION_FIX_BASE + 3)
10278 {"mfix-vr4122-bugs", no_argument
, NULL
, OPTION_FIX_VR4122
},
10279 {"no-mfix-vr4122-bugs", no_argument
, NULL
, OPTION_NO_FIX_VR4122
},
10281 /* Miscellaneous options. */
10282 #define OPTION_MISC_BASE (OPTION_FIX_BASE + 4)
10283 #define OPTION_MEMBEDDED_PIC (OPTION_MISC_BASE + 0)
10284 {"membedded-pic", no_argument
, NULL
, OPTION_MEMBEDDED_PIC
},
10285 #define OPTION_TRAP (OPTION_MISC_BASE + 1)
10286 {"trap", no_argument
, NULL
, OPTION_TRAP
},
10287 {"no-break", no_argument
, NULL
, OPTION_TRAP
},
10288 #define OPTION_BREAK (OPTION_MISC_BASE + 2)
10289 {"break", no_argument
, NULL
, OPTION_BREAK
},
10290 {"no-trap", no_argument
, NULL
, OPTION_BREAK
},
10291 #define OPTION_EB (OPTION_MISC_BASE + 3)
10292 {"EB", no_argument
, NULL
, OPTION_EB
},
10293 #define OPTION_EL (OPTION_MISC_BASE + 4)
10294 {"EL", no_argument
, NULL
, OPTION_EL
},
10295 #define OPTION_FP32 (OPTION_MISC_BASE + 5)
10296 {"mfp32", no_argument
, NULL
, OPTION_FP32
},
10297 #define OPTION_GP32 (OPTION_MISC_BASE + 6)
10298 {"mgp32", no_argument
, NULL
, OPTION_GP32
},
10299 #define OPTION_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 7)
10300 {"construct-floats", no_argument
, NULL
, OPTION_CONSTRUCT_FLOATS
},
10301 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 8)
10302 {"no-construct-floats", no_argument
, NULL
, OPTION_NO_CONSTRUCT_FLOATS
},
10303 #define OPTION_FP64 (OPTION_MISC_BASE + 9)
10304 {"mfp64", no_argument
, NULL
, OPTION_FP64
},
10305 #define OPTION_GP64 (OPTION_MISC_BASE + 10)
10306 {"mgp64", no_argument
, NULL
, OPTION_GP64
},
10307 #define OPTION_RELAX_BRANCH (OPTION_MISC_BASE + 11)
10308 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 12)
10309 {"relax-branch", no_argument
, NULL
, OPTION_RELAX_BRANCH
},
10310 {"no-relax-branch", no_argument
, NULL
, OPTION_NO_RELAX_BRANCH
},
10312 /* ELF-specific options. */
10314 #define OPTION_ELF_BASE (OPTION_MISC_BASE + 13)
10315 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10316 {"KPIC", no_argument
, NULL
, OPTION_CALL_SHARED
},
10317 {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
10318 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10319 {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
10320 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10321 {"xgot", no_argument
, NULL
, OPTION_XGOT
},
10322 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10323 {"mabi", required_argument
, NULL
, OPTION_MABI
},
10324 #define OPTION_32 (OPTION_ELF_BASE + 4)
10325 {"32", no_argument
, NULL
, OPTION_32
},
10326 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10327 {"n32", no_argument
, NULL
, OPTION_N32
},
10328 #define OPTION_64 (OPTION_ELF_BASE + 6)
10329 {"64", no_argument
, NULL
, OPTION_64
},
10330 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10331 {"mdebug", no_argument
, NULL
, OPTION_MDEBUG
},
10332 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10333 {"no-mdebug", no_argument
, NULL
, OPTION_NO_MDEBUG
},
10334 #define OPTION_PDR (OPTION_ELF_BASE + 9)
10335 {"mpdr", no_argument
, NULL
, OPTION_PDR
},
10336 #define OPTION_NO_PDR (OPTION_ELF_BASE + 10)
10337 {"mno-pdr", no_argument
, NULL
, OPTION_NO_PDR
},
10338 #endif /* OBJ_ELF */
10340 {NULL
, no_argument
, NULL
, 0}
10342 size_t md_longopts_size
= sizeof (md_longopts
);
10344 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10345 NEW_VALUE. Warn if another value was already specified. Note:
10346 we have to defer parsing the -march and -mtune arguments in order
10347 to handle 'from-abi' correctly, since the ABI might be specified
10348 in a later argument. */
10351 mips_set_option_string (const char **string_ptr
, const char *new_value
)
10353 if (*string_ptr
!= 0 && strcasecmp (*string_ptr
, new_value
) != 0)
10354 as_warn (_("A different %s was already specified, is now %s"),
10355 string_ptr
== &mips_arch_string
? "-march" : "-mtune",
10358 *string_ptr
= new_value
;
10362 md_parse_option (int c
, char *arg
)
10366 case OPTION_CONSTRUCT_FLOATS
:
10367 mips_disable_float_construction
= 0;
10370 case OPTION_NO_CONSTRUCT_FLOATS
:
10371 mips_disable_float_construction
= 1;
10383 target_big_endian
= 1;
10387 target_big_endian
= 0;
10395 if (arg
&& arg
[1] == '0')
10405 mips_debug
= atoi (arg
);
10406 /* When the MIPS assembler sees -g or -g2, it does not do
10407 optimizations which limit full symbolic debugging. We take
10408 that to be equivalent to -O0. */
10409 if (mips_debug
== 2)
10414 file_mips_isa
= ISA_MIPS1
;
10418 file_mips_isa
= ISA_MIPS2
;
10422 file_mips_isa
= ISA_MIPS3
;
10426 file_mips_isa
= ISA_MIPS4
;
10430 file_mips_isa
= ISA_MIPS5
;
10433 case OPTION_MIPS32
:
10434 file_mips_isa
= ISA_MIPS32
;
10437 case OPTION_MIPS32R2
:
10438 file_mips_isa
= ISA_MIPS32R2
;
10441 case OPTION_MIPS64
:
10442 file_mips_isa
= ISA_MIPS64
;
10446 mips_set_option_string (&mips_tune_string
, arg
);
10450 mips_set_option_string (&mips_arch_string
, arg
);
10454 mips_set_option_string (&mips_arch_string
, "4650");
10455 mips_set_option_string (&mips_tune_string
, "4650");
10458 case OPTION_NO_M4650
:
10462 mips_set_option_string (&mips_arch_string
, "4010");
10463 mips_set_option_string (&mips_tune_string
, "4010");
10466 case OPTION_NO_M4010
:
10470 mips_set_option_string (&mips_arch_string
, "4100");
10471 mips_set_option_string (&mips_tune_string
, "4100");
10474 case OPTION_NO_M4100
:
10478 mips_set_option_string (&mips_arch_string
, "3900");
10479 mips_set_option_string (&mips_tune_string
, "3900");
10482 case OPTION_NO_M3900
:
10486 mips_opts
.ase_mdmx
= 1;
10489 case OPTION_NO_MDMX
:
10490 mips_opts
.ase_mdmx
= 0;
10493 case OPTION_MIPS16
:
10494 mips_opts
.mips16
= 1;
10495 mips_no_prev_insn (FALSE
);
10498 case OPTION_NO_MIPS16
:
10499 mips_opts
.mips16
= 0;
10500 mips_no_prev_insn (FALSE
);
10503 case OPTION_MIPS3D
:
10504 mips_opts
.ase_mips3d
= 1;
10507 case OPTION_NO_MIPS3D
:
10508 mips_opts
.ase_mips3d
= 0;
10511 case OPTION_MEMBEDDED_PIC
:
10512 mips_pic
= EMBEDDED_PIC
;
10513 if (USE_GLOBAL_POINTER_OPT
&& g_switch_seen
)
10515 as_bad (_("-G may not be used with embedded PIC code"));
10518 g_switch_value
= 0x7fffffff;
10521 case OPTION_FIX_VR4122
:
10522 mips_fix_4122_bugs
= 1;
10525 case OPTION_NO_FIX_VR4122
:
10526 mips_fix_4122_bugs
= 0;
10529 case OPTION_RELAX_BRANCH
:
10530 mips_relax_branch
= 1;
10533 case OPTION_NO_RELAX_BRANCH
:
10534 mips_relax_branch
= 0;
10538 /* When generating ELF code, we permit -KPIC and -call_shared to
10539 select SVR4_PIC, and -non_shared to select no PIC. This is
10540 intended to be compatible with Irix 5. */
10541 case OPTION_CALL_SHARED
:
10542 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10544 as_bad (_("-call_shared is supported only for ELF format"));
10547 mips_pic
= SVR4_PIC
;
10548 mips_abicalls
= TRUE
;
10549 if (g_switch_seen
&& g_switch_value
!= 0)
10551 as_bad (_("-G may not be used with SVR4 PIC code"));
10554 g_switch_value
= 0;
10557 case OPTION_NON_SHARED
:
10558 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10560 as_bad (_("-non_shared is supported only for ELF format"));
10564 mips_abicalls
= FALSE
;
10567 /* The -xgot option tells the assembler to use 32 offsets when
10568 accessing the got in SVR4_PIC mode. It is for Irix
10573 #endif /* OBJ_ELF */
10576 if (! USE_GLOBAL_POINTER_OPT
)
10578 as_bad (_("-G is not supported for this configuration"));
10581 else if (mips_pic
== SVR4_PIC
|| mips_pic
== EMBEDDED_PIC
)
10583 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10587 g_switch_value
= atoi (arg
);
10592 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10595 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10597 as_bad (_("-32 is supported for ELF format only"));
10600 mips_abi
= O32_ABI
;
10604 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10606 as_bad (_("-n32 is supported for ELF format only"));
10609 mips_abi
= N32_ABI
;
10613 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10615 as_bad (_("-64 is supported for ELF format only"));
10618 mips_abi
= N64_ABI
;
10619 if (! support_64bit_objects())
10620 as_fatal (_("No compiled in support for 64 bit object file format"));
10622 #endif /* OBJ_ELF */
10625 file_mips_gp32
= 1;
10629 file_mips_gp32
= 0;
10633 file_mips_fp32
= 1;
10637 file_mips_fp32
= 0;
10642 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
10644 as_bad (_("-mabi is supported for ELF format only"));
10647 if (strcmp (arg
, "32") == 0)
10648 mips_abi
= O32_ABI
;
10649 else if (strcmp (arg
, "o64") == 0)
10650 mips_abi
= O64_ABI
;
10651 else if (strcmp (arg
, "n32") == 0)
10652 mips_abi
= N32_ABI
;
10653 else if (strcmp (arg
, "64") == 0)
10655 mips_abi
= N64_ABI
;
10656 if (! support_64bit_objects())
10657 as_fatal (_("No compiled in support for 64 bit object file "
10660 else if (strcmp (arg
, "eabi") == 0)
10661 mips_abi
= EABI_ABI
;
10664 as_fatal (_("invalid abi -mabi=%s"), arg
);
10668 #endif /* OBJ_ELF */
10670 case OPTION_M7000_HILO_FIX
:
10671 mips_7000_hilo_fix
= TRUE
;
10674 case OPTION_MNO_7000_HILO_FIX
:
10675 mips_7000_hilo_fix
= FALSE
;
10679 case OPTION_MDEBUG
:
10680 mips_flag_mdebug
= TRUE
;
10683 case OPTION_NO_MDEBUG
:
10684 mips_flag_mdebug
= FALSE
;
10688 mips_flag_pdr
= TRUE
;
10691 case OPTION_NO_PDR
:
10692 mips_flag_pdr
= FALSE
;
10694 #endif /* OBJ_ELF */
10703 /* Set up globals to generate code for the ISA or processor
10704 described by INFO. */
10707 mips_set_architecture (const struct mips_cpu_info
*info
)
10711 file_mips_arch
= info
->cpu
;
10712 mips_opts
.arch
= info
->cpu
;
10713 mips_opts
.isa
= info
->isa
;
10718 /* Likewise for tuning. */
10721 mips_set_tune (const struct mips_cpu_info
*info
)
10724 mips_tune
= info
->cpu
;
10729 mips_after_parse_args (void)
10731 const struct mips_cpu_info
*arch_info
= 0;
10732 const struct mips_cpu_info
*tune_info
= 0;
10734 /* GP relative stuff not working for PE */
10735 if (strncmp (TARGET_OS
, "pe", 2) == 0
10736 && g_switch_value
!= 0)
10739 as_bad (_("-G not supported in this configuration."));
10740 g_switch_value
= 0;
10743 if (mips_abi
== NO_ABI
)
10744 mips_abi
= MIPS_DEFAULT_ABI
;
10746 /* The following code determines the architecture and register size.
10747 Similar code was added to GCC 3.3 (see override_options() in
10748 config/mips/mips.c). The GAS and GCC code should be kept in sync
10749 as much as possible. */
10751 if (mips_arch_string
!= 0)
10752 arch_info
= mips_parse_cpu ("-march", mips_arch_string
);
10754 if (file_mips_isa
!= ISA_UNKNOWN
)
10756 /* Handle -mipsN. At this point, file_mips_isa contains the
10757 ISA level specified by -mipsN, while arch_info->isa contains
10758 the -march selection (if any). */
10759 if (arch_info
!= 0)
10761 /* -march takes precedence over -mipsN, since it is more descriptive.
10762 There's no harm in specifying both as long as the ISA levels
10764 if (file_mips_isa
!= arch_info
->isa
)
10765 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
10766 mips_cpu_info_from_isa (file_mips_isa
)->name
,
10767 mips_cpu_info_from_isa (arch_info
->isa
)->name
);
10770 arch_info
= mips_cpu_info_from_isa (file_mips_isa
);
10773 if (arch_info
== 0)
10774 arch_info
= mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT
);
10776 if (ABI_NEEDS_64BIT_REGS (mips_abi
) && !ISA_HAS_64BIT_REGS (arch_info
->isa
))
10777 as_bad ("-march=%s is not compatible with the selected ABI",
10780 mips_set_architecture (arch_info
);
10782 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
10783 if (mips_tune_string
!= 0)
10784 tune_info
= mips_parse_cpu ("-mtune", mips_tune_string
);
10786 if (tune_info
== 0)
10787 mips_set_tune (arch_info
);
10789 mips_set_tune (tune_info
);
10791 if (file_mips_gp32
>= 0)
10793 /* The user specified the size of the integer registers. Make sure
10794 it agrees with the ABI and ISA. */
10795 if (file_mips_gp32
== 0 && !ISA_HAS_64BIT_REGS (mips_opts
.isa
))
10796 as_bad (_("-mgp64 used with a 32-bit processor"));
10797 else if (file_mips_gp32
== 1 && ABI_NEEDS_64BIT_REGS (mips_abi
))
10798 as_bad (_("-mgp32 used with a 64-bit ABI"));
10799 else if (file_mips_gp32
== 0 && ABI_NEEDS_32BIT_REGS (mips_abi
))
10800 as_bad (_("-mgp64 used with a 32-bit ABI"));
10804 /* Infer the integer register size from the ABI and processor.
10805 Restrict ourselves to 32-bit registers if that's all the
10806 processor has, or if the ABI cannot handle 64-bit registers. */
10807 file_mips_gp32
= (ABI_NEEDS_32BIT_REGS (mips_abi
)
10808 || !ISA_HAS_64BIT_REGS (mips_opts
.isa
));
10811 /* ??? GAS treats single-float processors as though they had 64-bit
10812 float registers (although it complains when double-precision
10813 instructions are used). As things stand, saying they have 32-bit
10814 registers would lead to spurious "register must be even" messages.
10815 So here we assume float registers are always the same size as
10816 integer ones, unless the user says otherwise. */
10817 if (file_mips_fp32
< 0)
10818 file_mips_fp32
= file_mips_gp32
;
10820 /* End of GCC-shared inference code. */
10822 /* This flag is set when we have a 64-bit capable CPU but use only
10823 32-bit wide registers. Note that EABI does not use it. */
10824 if (ISA_HAS_64BIT_REGS (mips_opts
.isa
)
10825 && ((mips_abi
== NO_ABI
&& file_mips_gp32
== 1)
10826 || mips_abi
== O32_ABI
))
10827 mips_32bitmode
= 1;
10829 if (mips_opts
.isa
== ISA_MIPS1
&& mips_trap
)
10830 as_bad (_("trap exception not supported at ISA 1"));
10832 /* If the selected architecture includes support for ASEs, enable
10833 generation of code for them. */
10834 if (mips_opts
.mips16
== -1)
10835 mips_opts
.mips16
= (CPU_HAS_MIPS16 (file_mips_arch
)) ? 1 : 0;
10836 if (mips_opts
.ase_mips3d
== -1)
10837 mips_opts
.ase_mips3d
= (CPU_HAS_MIPS3D (file_mips_arch
)) ? 1 : 0;
10838 if (mips_opts
.ase_mdmx
== -1)
10839 mips_opts
.ase_mdmx
= (CPU_HAS_MDMX (file_mips_arch
)) ? 1 : 0;
10841 file_mips_isa
= mips_opts
.isa
;
10842 file_ase_mips16
= mips_opts
.mips16
;
10843 file_ase_mips3d
= mips_opts
.ase_mips3d
;
10844 file_ase_mdmx
= mips_opts
.ase_mdmx
;
10845 mips_opts
.gp32
= file_mips_gp32
;
10846 mips_opts
.fp32
= file_mips_fp32
;
10848 if (mips_flag_mdebug
< 0)
10850 #ifdef OBJ_MAYBE_ECOFF
10851 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
)
10852 mips_flag_mdebug
= 1;
10854 #endif /* OBJ_MAYBE_ECOFF */
10855 mips_flag_mdebug
= 0;
10860 mips_init_after_args (void)
10862 /* initialize opcodes */
10863 bfd_mips_num_opcodes
= bfd_mips_num_builtin_opcodes
;
10864 mips_opcodes
= (struct mips_opcode
*) mips_builtin_opcodes
;
10868 md_pcrel_from (fixS
*fixP
)
10870 valueT addr
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
10871 switch (fixP
->fx_r_type
)
10873 case BFD_RELOC_16_PCREL_S2
:
10874 case BFD_RELOC_MIPS_JMP
:
10875 /* Return the address of the delay slot. */
10882 /* This is called before the symbol table is processed. In order to
10883 work with gcc when using mips-tfile, we must keep all local labels.
10884 However, in other cases, we want to discard them. If we were
10885 called with -g, but we didn't see any debugging information, it may
10886 mean that gcc is smuggling debugging information through to
10887 mips-tfile, in which case we must generate all local labels. */
10890 mips_frob_file_before_adjust (void)
10892 #ifndef NO_ECOFF_DEBUGGING
10893 if (ECOFF_DEBUGGING
10895 && ! ecoff_debugging_seen
)
10896 flag_keep_locals
= 1;
10900 /* Sort any unmatched HI16_S relocs so that they immediately precede
10901 the corresponding LO reloc. This is called before md_apply_fix3 and
10902 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10903 explicit use of the %hi modifier. */
10906 mips_frob_file (void)
10908 struct mips_hi_fixup
*l
;
10910 for (l
= mips_hi_fixup_list
; l
!= NULL
; l
= l
->next
)
10912 segment_info_type
*seginfo
;
10915 assert (reloc_needs_lo_p (l
->fixp
->fx_r_type
));
10917 /* If a GOT16 relocation turns out to be against a global symbol,
10918 there isn't supposed to be a matching LO. */
10919 if (l
->fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT16
10920 && !pic_need_relax (l
->fixp
->fx_addsy
, l
->seg
))
10923 /* Check quickly whether the next fixup happens to be a matching %lo. */
10924 if (fixup_has_matching_lo_p (l
->fixp
))
10927 /* Look through the fixups for this segment for a matching %lo.
10928 When we find one, move the %hi just in front of it. We do
10929 this in two passes. In the first pass, we try to find a
10930 unique %lo. In the second pass, we permit multiple %hi
10931 relocs for a single %lo (this is a GNU extension). */
10932 seginfo
= seg_info (l
->seg
);
10933 for (pass
= 0; pass
< 2; pass
++)
10938 for (f
= seginfo
->fix_root
; f
!= NULL
; f
= f
->fx_next
)
10940 /* Check whether this is a %lo fixup which matches l->fixp. */
10941 if (f
->fx_r_type
== BFD_RELOC_LO16
10942 && f
->fx_addsy
== l
->fixp
->fx_addsy
10943 && f
->fx_offset
== l
->fixp
->fx_offset
10946 || !reloc_needs_lo_p (prev
->fx_r_type
)
10947 || !fixup_has_matching_lo_p (prev
)))
10951 /* Move l->fixp before f. */
10952 for (pf
= &seginfo
->fix_root
;
10954 pf
= &(*pf
)->fx_next
)
10955 assert (*pf
!= NULL
);
10957 *pf
= l
->fixp
->fx_next
;
10959 l
->fixp
->fx_next
= f
;
10961 seginfo
->fix_root
= l
->fixp
;
10963 prev
->fx_next
= l
->fixp
;
10974 #if 0 /* GCC code motion plus incomplete dead code elimination
10975 can leave a %hi without a %lo. */
10977 as_warn_where (l
->fixp
->fx_file
, l
->fixp
->fx_line
,
10978 _("Unmatched %%hi reloc"));
10984 /* When generating embedded PIC code we need to use a special
10985 relocation to represent the difference of two symbols in the .text
10986 section (switch tables use a difference of this sort). See
10987 include/coff/mips.h for details. This macro checks whether this
10988 fixup requires the special reloc. */
10989 #define SWITCH_TABLE(fixp) \
10990 ((fixp)->fx_r_type == BFD_RELOC_32 \
10991 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10992 && (fixp)->fx_addsy != NULL \
10993 && (fixp)->fx_subsy != NULL \
10994 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10995 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10997 /* When generating embedded PIC code we must keep all PC relative
10998 relocations, in case the linker has to relax a call. We also need
10999 to keep relocations for switch table entries.
11001 We may have combined relocations without symbols in the N32/N64 ABI.
11002 We have to prevent gas from dropping them. */
11005 mips_force_relocation (fixS
*fixp
)
11007 if (generic_force_reloc (fixp
))
11011 && S_GET_SEGMENT (fixp
->fx_addsy
) == bfd_abs_section_ptr
11012 && (fixp
->fx_r_type
== BFD_RELOC_MIPS_SUB
11013 || fixp
->fx_r_type
== BFD_RELOC_HI16_S
11014 || fixp
->fx_r_type
== BFD_RELOC_LO16
))
11017 return (mips_pic
== EMBEDDED_PIC
11019 || SWITCH_TABLE (fixp
)
11020 || fixp
->fx_r_type
== BFD_RELOC_PCREL_HI16_S
11021 || fixp
->fx_r_type
== BFD_RELOC_PCREL_LO16
));
11024 /* This hook is called before a fix is simplified. We don't really
11025 decide whether to skip a fix here. Rather, we turn global symbols
11026 used as branch targets into local symbols, such that they undergo
11027 simplification. We can only do this if the symbol is defined and
11028 it is in the same section as the branch. If this doesn't hold, we
11029 emit a better error message than just saying the relocation is not
11030 valid for the selected object format.
11032 FIXP is the fix-up we're going to try to simplify, SEG is the
11033 segment in which the fix up occurs. The return value should be
11034 non-zero to indicate the fix-up is valid for further
11035 simplifications. */
11038 mips_validate_fix (struct fix
*fixP
, asection
*seg
)
11040 /* There's a lot of discussion on whether it should be possible to
11041 use R_MIPS_PC16 to represent branch relocations. The outcome
11042 seems to be that it can, but gas/bfd are very broken in creating
11043 RELA relocations for this, so for now we only accept branches to
11044 symbols in the same section. Anything else is of dubious value,
11045 since there's no guarantee that at link time the symbol would be
11046 in range. Even for branches to local symbols this is arguably
11047 wrong, since it we assume the symbol is not going to be
11048 overridden, which should be possible per ELF library semantics,
11049 but then, there isn't a dynamic relocation that could be used to
11050 this effect, and the target would likely be out of range as well.
11052 Unfortunately, it seems that there is too much code out there
11053 that relies on branches to symbols that are global to be resolved
11054 as if they were local, like the IRIX tools do, so we do it as
11055 well, but with a warning so that people are reminded to fix their
11056 code. If we ever get back to using R_MIPS_PC16 for branch
11057 targets, this entire block should go away (and probably the
11058 whole function). */
11060 if (fixP
->fx_r_type
== BFD_RELOC_16_PCREL_S2
11061 && (((OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
11062 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11063 && mips_pic
!= EMBEDDED_PIC
)
11064 || bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_16_PCREL_S2
) == NULL
)
11067 if (! S_IS_DEFINED (fixP
->fx_addsy
))
11069 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11070 _("Cannot branch to undefined symbol."));
11071 /* Avoid any further errors about this fixup. */
11074 else if (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)
11076 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11077 _("Cannot branch to symbol in another section."));
11080 else if (S_IS_EXTERNAL (fixP
->fx_addsy
))
11082 symbolS
*sym
= fixP
->fx_addsy
;
11084 if (mips_pic
== SVR4_PIC
)
11085 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
11086 _("Pretending global symbol used as branch target is local."));
11088 fixP
->fx_addsy
= symbol_create (S_GET_NAME (sym
),
11089 S_GET_SEGMENT (sym
),
11091 symbol_get_frag (sym
));
11092 copy_symbol_attributes (fixP
->fx_addsy
, sym
);
11093 S_CLEAR_EXTERNAL (fixP
->fx_addsy
);
11094 assert (symbol_resolved_p (sym
));
11095 symbol_mark_resolved (fixP
->fx_addsy
);
11104 mips_need_elf_addend_fixup (fixS
*fixP
)
11106 if (S_GET_OTHER (fixP
->fx_addsy
) == STO_MIPS16
)
11108 if (mips_pic
== EMBEDDED_PIC
11109 && S_IS_WEAK (fixP
->fx_addsy
))
11111 if (mips_pic
!= EMBEDDED_PIC
11112 && (S_IS_WEAK (fixP
->fx_addsy
)
11113 || S_IS_EXTERNAL (fixP
->fx_addsy
))
11114 && !S_IS_COMMON (fixP
->fx_addsy
))
11116 if (((bfd_get_section_flags (stdoutput
,
11117 S_GET_SEGMENT (fixP
->fx_addsy
))
11118 & (SEC_LINK_ONCE
| SEC_MERGE
)) != 0)
11119 || !strncmp (segment_name (S_GET_SEGMENT (fixP
->fx_addsy
)),
11121 sizeof (".gnu.linkonce") - 1))
11127 /* Apply a fixup to the object file. */
11130 md_apply_fix3 (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
11134 static int previous_fx_r_type
= 0;
11135 reloc_howto_type
*howto
;
11137 /* We ignore generic BFD relocations we don't know about. */
11138 howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
11142 assert (fixP
->fx_size
== 4
11143 || fixP
->fx_r_type
== BFD_RELOC_16
11144 || fixP
->fx_r_type
== BFD_RELOC_64
11145 || fixP
->fx_r_type
== BFD_RELOC_CTOR
11146 || fixP
->fx_r_type
== BFD_RELOC_MIPS_SUB
11147 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
11148 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
);
11150 buf
= (bfd_byte
*) (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
);
11152 /* If we aren't adjusting this fixup to be against the section
11153 symbol, we need to adjust the value. */
11155 if (fixP
->fx_addsy
!= NULL
&& OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11157 if (mips_need_elf_addend_fixup (fixP
)
11158 && howto
->partial_inplace
11159 && fixP
->fx_r_type
!= BFD_RELOC_GPREL16
11160 && fixP
->fx_r_type
!= BFD_RELOC_GPREL32
11161 && fixP
->fx_r_type
!= BFD_RELOC_MIPS16_GPREL
)
11163 /* In this case, the bfd_install_relocation routine will
11164 incorrectly add the symbol value back in. We just want
11165 the addend to appear in the object file.
11167 The condition above used to include
11168 "&& (! fixP->fx_pcrel || howto->pcrel_offset)".
11170 However, howto can't be trusted here, because we
11171 might change the reloc type in tc_gen_reloc. We can
11172 check howto->partial_inplace because that conversion
11173 happens to preserve howto->partial_inplace; but it
11174 does not preserve howto->pcrel_offset. I've just
11175 eliminated the check, because all MIPS PC-relative
11176 relocations are marked howto->pcrel_offset.
11178 howto->pcrel_offset was originally added for
11179 R_MIPS_PC16, which is generated for code like
11188 *valP
-= S_GET_VALUE (fixP
->fx_addsy
);
11191 /* This code was generated using trial and error and so is
11192 fragile and not trustworthy. If you change it, you should
11193 rerun the elf-rel, elf-rel2, and empic testcases and ensure
11194 they still pass. */
11195 if (fixP
->fx_pcrel
)
11197 *valP
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
11199 /* BFD's REL handling, for MIPS, is _very_ weird.
11200 This gives the right results, but it can't possibly
11201 be the way things are supposed to work. */
11202 *valP
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
11207 /* We are not done if this is a composite relocation to set up gp. */
11208 if (fixP
->fx_addsy
== NULL
&& ! fixP
->fx_pcrel
11209 && !(fixP
->fx_r_type
== BFD_RELOC_MIPS_SUB
11210 || (fixP
->fx_r_type
== BFD_RELOC_64
11211 && (previous_fx_r_type
== BFD_RELOC_GPREL32
11212 || previous_fx_r_type
== BFD_RELOC_GPREL16
))
11213 || (previous_fx_r_type
== BFD_RELOC_MIPS_SUB
11214 && (fixP
->fx_r_type
== BFD_RELOC_HI16_S
11215 || fixP
->fx_r_type
== BFD_RELOC_LO16
))))
11217 previous_fx_r_type
= fixP
->fx_r_type
;
11219 switch (fixP
->fx_r_type
)
11221 case BFD_RELOC_MIPS_JMP
:
11222 case BFD_RELOC_MIPS_SHIFT5
:
11223 case BFD_RELOC_MIPS_SHIFT6
:
11224 case BFD_RELOC_MIPS_GOT_DISP
:
11225 case BFD_RELOC_MIPS_GOT_PAGE
:
11226 case BFD_RELOC_MIPS_GOT_OFST
:
11227 case BFD_RELOC_MIPS_SUB
:
11228 case BFD_RELOC_MIPS_INSERT_A
:
11229 case BFD_RELOC_MIPS_INSERT_B
:
11230 case BFD_RELOC_MIPS_DELETE
:
11231 case BFD_RELOC_MIPS_HIGHEST
:
11232 case BFD_RELOC_MIPS_HIGHER
:
11233 case BFD_RELOC_MIPS_SCN_DISP
:
11234 case BFD_RELOC_MIPS_REL16
:
11235 case BFD_RELOC_MIPS_RELGOT
:
11236 case BFD_RELOC_MIPS_JALR
:
11237 case BFD_RELOC_HI16
:
11238 case BFD_RELOC_HI16_S
:
11239 case BFD_RELOC_GPREL16
:
11240 case BFD_RELOC_MIPS_LITERAL
:
11241 case BFD_RELOC_MIPS_CALL16
:
11242 case BFD_RELOC_MIPS_GOT16
:
11243 case BFD_RELOC_GPREL32
:
11244 case BFD_RELOC_MIPS_GOT_HI16
:
11245 case BFD_RELOC_MIPS_GOT_LO16
:
11246 case BFD_RELOC_MIPS_CALL_HI16
:
11247 case BFD_RELOC_MIPS_CALL_LO16
:
11248 case BFD_RELOC_MIPS16_GPREL
:
11249 if (fixP
->fx_pcrel
)
11250 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11251 _("Invalid PC relative reloc"));
11252 /* Nothing needed to do. The value comes from the reloc entry */
11255 case BFD_RELOC_MIPS16_JMP
:
11256 /* We currently always generate a reloc against a symbol, which
11257 means that we don't want an addend even if the symbol is
11262 case BFD_RELOC_PCREL_HI16_S
:
11263 /* The addend for this is tricky if it is internal, so we just
11264 do everything here rather than in bfd_install_relocation. */
11265 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& !fixP
->fx_done
)
11268 && (symbol_get_bfdsym (fixP
->fx_addsy
)->flags
& BSF_SECTION_SYM
) == 0)
11270 /* For an external symbol adjust by the address to make it
11271 pcrel_offset. We use the address of the RELLO reloc
11272 which follows this one. */
11273 *valP
+= (fixP
->fx_next
->fx_frag
->fr_address
11274 + fixP
->fx_next
->fx_where
);
11276 *valP
= ((*valP
+ 0x8000) >> 16) & 0xffff;
11277 if (target_big_endian
)
11279 md_number_to_chars (buf
, *valP
, 2);
11282 case BFD_RELOC_PCREL_LO16
:
11283 /* The addend for this is tricky if it is internal, so we just
11284 do everything here rather than in bfd_install_relocation. */
11285 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& !fixP
->fx_done
)
11288 && (symbol_get_bfdsym (fixP
->fx_addsy
)->flags
& BSF_SECTION_SYM
) == 0)
11289 *valP
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
11290 if (target_big_endian
)
11292 md_number_to_chars (buf
, *valP
, 2);
11296 /* This is handled like BFD_RELOC_32, but we output a sign
11297 extended value if we are only 32 bits. */
11299 || (mips_pic
== EMBEDDED_PIC
&& SWITCH_TABLE (fixP
)))
11301 if (8 <= sizeof (valueT
))
11302 md_number_to_chars (buf
, *valP
, 8);
11307 if ((*valP
& 0x80000000) != 0)
11311 md_number_to_chars ((char *)(buf
+ target_big_endian
? 4 : 0),
11313 md_number_to_chars ((char *)(buf
+ target_big_endian
? 0 : 4),
11319 case BFD_RELOC_RVA
:
11321 /* If we are deleting this reloc entry, we must fill in the
11322 value now. This can happen if we have a .word which is not
11323 resolved when it appears but is later defined. We also need
11324 to fill in the value if this is an embedded PIC switch table
11327 || (mips_pic
== EMBEDDED_PIC
&& SWITCH_TABLE (fixP
)))
11328 md_number_to_chars (buf
, *valP
, 4);
11332 /* If we are deleting this reloc entry, we must fill in the
11334 assert (fixP
->fx_size
== 2);
11336 md_number_to_chars (buf
, *valP
, 2);
11339 case BFD_RELOC_LO16
:
11340 /* When handling an embedded PIC switch statement, we can wind
11341 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11344 if (*valP
+ 0x8000 > 0xffff)
11345 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11346 _("relocation overflow"));
11347 if (target_big_endian
)
11349 md_number_to_chars (buf
, *valP
, 2);
11353 case BFD_RELOC_16_PCREL_S2
:
11354 if ((*valP
& 0x3) != 0)
11355 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11356 _("Branch to odd address (%lx)"), (long) *valP
);
11359 * We need to save the bits in the instruction since fixup_segment()
11360 * might be deleting the relocation entry (i.e., a branch within
11361 * the current segment).
11363 if (! fixP
->fx_done
)
11366 /* update old instruction data */
11367 if (target_big_endian
)
11368 insn
= (buf
[0] << 24) | (buf
[1] << 16) | (buf
[2] << 8) | buf
[3];
11370 insn
= (buf
[3] << 24) | (buf
[2] << 16) | (buf
[1] << 8) | buf
[0];
11372 if (*valP
+ 0x20000 <= 0x3ffff)
11374 insn
|= (*valP
>> 2) & 0xffff;
11375 md_number_to_chars (buf
, insn
, 4);
11377 else if (mips_pic
== NO_PIC
11379 && fixP
->fx_frag
->fr_address
>= text_section
->vma
11380 && (fixP
->fx_frag
->fr_address
11381 < text_section
->vma
+ text_section
->_raw_size
)
11382 && ((insn
& 0xffff0000) == 0x10000000 /* beq $0,$0 */
11383 || (insn
& 0xffff0000) == 0x04010000 /* bgez $0 */
11384 || (insn
& 0xffff0000) == 0x04110000)) /* bgezal $0 */
11386 /* The branch offset is too large. If this is an
11387 unconditional branch, and we are not generating PIC code,
11388 we can convert it to an absolute jump instruction. */
11389 if ((insn
& 0xffff0000) == 0x04110000) /* bgezal $0 */
11390 insn
= 0x0c000000; /* jal */
11392 insn
= 0x08000000; /* j */
11393 fixP
->fx_r_type
= BFD_RELOC_MIPS_JMP
;
11395 fixP
->fx_addsy
= section_symbol (text_section
);
11396 *valP
+= md_pcrel_from (fixP
);
11397 md_number_to_chars (buf
, insn
, 4);
11401 /* If we got here, we have branch-relaxation disabled,
11402 and there's nothing we can do to fix this instruction
11403 without turning it into a longer sequence. */
11404 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11405 _("Branch out of range"));
11409 case BFD_RELOC_VTABLE_INHERIT
:
11412 && !S_IS_DEFINED (fixP
->fx_addsy
)
11413 && !S_IS_WEAK (fixP
->fx_addsy
))
11414 S_SET_WEAK (fixP
->fx_addsy
);
11417 case BFD_RELOC_VTABLE_ENTRY
:
11425 /* Remember value for tc_gen_reloc. */
11426 fixP
->fx_addnumber
= *valP
;
11431 printInsn (unsigned long oc
)
11433 const struct mips_opcode
*p
;
11434 int treg
, sreg
, dreg
, shamt
;
11439 for (i
= 0; i
< NUMOPCODES
; ++i
)
11441 p
= &mips_opcodes
[i
];
11442 if (((oc
& p
->mask
) == p
->match
) && (p
->pinfo
!= INSN_MACRO
))
11444 printf ("%08lx %s\t", oc
, p
->name
);
11445 treg
= (oc
>> 16) & 0x1f;
11446 sreg
= (oc
>> 21) & 0x1f;
11447 dreg
= (oc
>> 11) & 0x1f;
11448 shamt
= (oc
>> 6) & 0x1f;
11450 for (args
= p
->args
;; ++args
)
11461 printf ("%c", *args
);
11465 assert (treg
== sreg
);
11466 printf ("$%d,$%d", treg
, sreg
);
11471 printf ("$%d", dreg
);
11476 printf ("$%d", treg
);
11480 printf ("0x%x", treg
);
11485 printf ("$%d", sreg
);
11489 printf ("0x%08lx", oc
& 0x1ffffff);
11496 printf ("%d", imm
);
11501 printf ("$%d", shamt
);
11512 printf (_("%08lx UNDEFINED\n"), oc
);
11523 name
= input_line_pointer
;
11524 c
= get_symbol_end ();
11525 p
= (symbolS
*) symbol_find_or_make (name
);
11526 *input_line_pointer
= c
;
11530 /* Align the current frag to a given power of two. The MIPS assembler
11531 also automatically adjusts any preceding label. */
11534 mips_align (int to
, int fill
, symbolS
*label
)
11536 mips_emit_delays (FALSE
);
11537 frag_align (to
, fill
, 0);
11538 record_alignment (now_seg
, to
);
11541 assert (S_GET_SEGMENT (label
) == now_seg
);
11542 symbol_set_frag (label
, frag_now
);
11543 S_SET_VALUE (label
, (valueT
) frag_now_fix ());
11547 /* Align to a given power of two. .align 0 turns off the automatic
11548 alignment used by the data creating pseudo-ops. */
11551 s_align (int x ATTRIBUTE_UNUSED
)
11554 register long temp_fill
;
11555 long max_alignment
= 15;
11559 o Note that the assembler pulls down any immediately preceeding label
11560 to the aligned address.
11561 o It's not documented but auto alignment is reinstated by
11562 a .align pseudo instruction.
11563 o Note also that after auto alignment is turned off the mips assembler
11564 issues an error on attempt to assemble an improperly aligned data item.
11569 temp
= get_absolute_expression ();
11570 if (temp
> max_alignment
)
11571 as_bad (_("Alignment too large: %d. assumed."), temp
= max_alignment
);
11574 as_warn (_("Alignment negative: 0 assumed."));
11577 if (*input_line_pointer
== ',')
11579 ++input_line_pointer
;
11580 temp_fill
= get_absolute_expression ();
11587 mips_align (temp
, (int) temp_fill
,
11588 insn_labels
!= NULL
? insn_labels
->label
: NULL
);
11595 demand_empty_rest_of_line ();
11599 mips_flush_pending_output (void)
11601 mips_emit_delays (FALSE
);
11602 mips_clear_insn_labels ();
11606 s_change_sec (int sec
)
11610 /* When generating embedded PIC code, we only use the .text, .lit8,
11611 .sdata and .sbss sections. We change the .data and .rdata
11612 pseudo-ops to use .sdata. */
11613 if (mips_pic
== EMBEDDED_PIC
11614 && (sec
== 'd' || sec
== 'r'))
11618 /* The ELF backend needs to know that we are changing sections, so
11619 that .previous works correctly. We could do something like check
11620 for an obj_section_change_hook macro, but that might be confusing
11621 as it would not be appropriate to use it in the section changing
11622 functions in read.c, since obj-elf.c intercepts those. FIXME:
11623 This should be cleaner, somehow. */
11624 obj_elf_section_change_hook ();
11627 mips_emit_delays (FALSE
);
11637 subseg_set (bss_section
, (subsegT
) get_absolute_expression ());
11638 demand_empty_rest_of_line ();
11642 if (USE_GLOBAL_POINTER_OPT
)
11644 seg
= subseg_new (RDATA_SECTION_NAME
,
11645 (subsegT
) get_absolute_expression ());
11646 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11648 bfd_set_section_flags (stdoutput
, seg
,
11654 if (strcmp (TARGET_OS
, "elf") != 0)
11655 record_alignment (seg
, 4);
11657 demand_empty_rest_of_line ();
11661 as_bad (_("No read only data section in this object file format"));
11662 demand_empty_rest_of_line ();
11668 if (USE_GLOBAL_POINTER_OPT
)
11670 seg
= subseg_new (".sdata", (subsegT
) get_absolute_expression ());
11671 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
11673 bfd_set_section_flags (stdoutput
, seg
,
11674 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
11676 if (strcmp (TARGET_OS
, "elf") != 0)
11677 record_alignment (seg
, 4);
11679 demand_empty_rest_of_line ();
11684 as_bad (_("Global pointers not supported; recompile -G 0"));
11685 demand_empty_rest_of_line ();
11694 s_change_section (int ignore ATTRIBUTE_UNUSED
)
11697 char *section_name
;
11702 int section_entry_size
;
11703 int section_alignment
;
11705 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
11708 section_name
= input_line_pointer
;
11709 c
= get_symbol_end ();
11711 next_c
= *(input_line_pointer
+ 1);
11713 /* Do we have .section Name<,"flags">? */
11714 if (c
!= ',' || (c
== ',' && next_c
== '"'))
11716 /* just after name is now '\0'. */
11717 *input_line_pointer
= c
;
11718 input_line_pointer
= section_name
;
11719 obj_elf_section (ignore
);
11722 input_line_pointer
++;
11724 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
11726 section_type
= get_absolute_expression ();
11729 if (*input_line_pointer
++ == ',')
11730 section_flag
= get_absolute_expression ();
11733 if (*input_line_pointer
++ == ',')
11734 section_entry_size
= get_absolute_expression ();
11736 section_entry_size
= 0;
11737 if (*input_line_pointer
++ == ',')
11738 section_alignment
= get_absolute_expression ();
11740 section_alignment
= 0;
11742 section_name
= xstrdup (section_name
);
11744 obj_elf_change_section (section_name
, section_type
, section_flag
,
11745 section_entry_size
, 0, 0, 0);
11747 if (now_seg
->name
!= section_name
)
11748 free (section_name
);
11749 #endif /* OBJ_ELF */
11753 mips_enable_auto_align (void)
11759 s_cons (int log_size
)
11763 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
11764 mips_emit_delays (FALSE
);
11765 if (log_size
> 0 && auto_align
)
11766 mips_align (log_size
, 0, label
);
11767 mips_clear_insn_labels ();
11768 cons (1 << log_size
);
11772 s_float_cons (int type
)
11776 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
11778 mips_emit_delays (FALSE
);
11783 mips_align (3, 0, label
);
11785 mips_align (2, 0, label
);
11788 mips_clear_insn_labels ();
11793 /* Handle .globl. We need to override it because on Irix 5 you are
11796 where foo is an undefined symbol, to mean that foo should be
11797 considered to be the address of a function. */
11800 s_mips_globl (int x ATTRIBUTE_UNUSED
)
11807 name
= input_line_pointer
;
11808 c
= get_symbol_end ();
11809 symbolP
= symbol_find_or_make (name
);
11810 *input_line_pointer
= c
;
11811 SKIP_WHITESPACE ();
11813 /* On Irix 5, every global symbol that is not explicitly labelled as
11814 being a function is apparently labelled as being an object. */
11817 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
11822 secname
= input_line_pointer
;
11823 c
= get_symbol_end ();
11824 sec
= bfd_get_section_by_name (stdoutput
, secname
);
11826 as_bad (_("%s: no such section"), secname
);
11827 *input_line_pointer
= c
;
11829 if (sec
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
11830 flag
= BSF_FUNCTION
;
11833 symbol_get_bfdsym (symbolP
)->flags
|= flag
;
11835 S_SET_EXTERNAL (symbolP
);
11836 demand_empty_rest_of_line ();
11840 s_option (int x ATTRIBUTE_UNUSED
)
11845 opt
= input_line_pointer
;
11846 c
= get_symbol_end ();
11850 /* FIXME: What does this mean? */
11852 else if (strncmp (opt
, "pic", 3) == 0)
11856 i
= atoi (opt
+ 3);
11861 mips_pic
= SVR4_PIC
;
11862 mips_abicalls
= TRUE
;
11865 as_bad (_(".option pic%d not supported"), i
);
11867 if (USE_GLOBAL_POINTER_OPT
&& mips_pic
== SVR4_PIC
)
11869 if (g_switch_seen
&& g_switch_value
!= 0)
11870 as_warn (_("-G may not be used with SVR4 PIC code"));
11871 g_switch_value
= 0;
11872 bfd_set_gp_size (stdoutput
, 0);
11876 as_warn (_("Unrecognized option \"%s\""), opt
);
11878 *input_line_pointer
= c
;
11879 demand_empty_rest_of_line ();
11882 /* This structure is used to hold a stack of .set values. */
11884 struct mips_option_stack
11886 struct mips_option_stack
*next
;
11887 struct mips_set_options options
;
11890 static struct mips_option_stack
*mips_opts_stack
;
11892 /* Handle the .set pseudo-op. */
11895 s_mipsset (int x ATTRIBUTE_UNUSED
)
11897 char *name
= input_line_pointer
, ch
;
11899 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
11900 ++input_line_pointer
;
11901 ch
= *input_line_pointer
;
11902 *input_line_pointer
= '\0';
11904 if (strcmp (name
, "reorder") == 0)
11906 if (mips_opts
.noreorder
&& prev_nop_frag
!= NULL
)
11908 /* If we still have pending nops, we can discard them. The
11909 usual nop handling will insert any that are still
11911 prev_nop_frag
->fr_fix
-= (prev_nop_frag_holds
11912 * (mips_opts
.mips16
? 2 : 4));
11913 prev_nop_frag
= NULL
;
11915 mips_opts
.noreorder
= 0;
11917 else if (strcmp (name
, "noreorder") == 0)
11919 mips_emit_delays (TRUE
);
11920 mips_opts
.noreorder
= 1;
11921 mips_any_noreorder
= 1;
11923 else if (strcmp (name
, "at") == 0)
11925 mips_opts
.noat
= 0;
11927 else if (strcmp (name
, "noat") == 0)
11929 mips_opts
.noat
= 1;
11931 else if (strcmp (name
, "macro") == 0)
11933 mips_opts
.warn_about_macros
= 0;
11935 else if (strcmp (name
, "nomacro") == 0)
11937 if (mips_opts
.noreorder
== 0)
11938 as_bad (_("`noreorder' must be set before `nomacro'"));
11939 mips_opts
.warn_about_macros
= 1;
11941 else if (strcmp (name
, "move") == 0 || strcmp (name
, "novolatile") == 0)
11943 mips_opts
.nomove
= 0;
11945 else if (strcmp (name
, "nomove") == 0 || strcmp (name
, "volatile") == 0)
11947 mips_opts
.nomove
= 1;
11949 else if (strcmp (name
, "bopt") == 0)
11951 mips_opts
.nobopt
= 0;
11953 else if (strcmp (name
, "nobopt") == 0)
11955 mips_opts
.nobopt
= 1;
11957 else if (strcmp (name
, "mips16") == 0
11958 || strcmp (name
, "MIPS-16") == 0)
11959 mips_opts
.mips16
= 1;
11960 else if (strcmp (name
, "nomips16") == 0
11961 || strcmp (name
, "noMIPS-16") == 0)
11962 mips_opts
.mips16
= 0;
11963 else if (strcmp (name
, "mips3d") == 0)
11964 mips_opts
.ase_mips3d
= 1;
11965 else if (strcmp (name
, "nomips3d") == 0)
11966 mips_opts
.ase_mips3d
= 0;
11967 else if (strcmp (name
, "mdmx") == 0)
11968 mips_opts
.ase_mdmx
= 1;
11969 else if (strcmp (name
, "nomdmx") == 0)
11970 mips_opts
.ase_mdmx
= 0;
11971 else if (strncmp (name
, "mips", 4) == 0 || strncmp (name
, "arch=", 5) == 0)
11975 /* Permit the user to change the ISA and architecture on the fly.
11976 Needless to say, misuse can cause serious problems. */
11977 if (strcmp (name
, "mips0") == 0)
11980 mips_opts
.isa
= file_mips_isa
;
11982 else if (strcmp (name
, "mips1") == 0)
11983 mips_opts
.isa
= ISA_MIPS1
;
11984 else if (strcmp (name
, "mips2") == 0)
11985 mips_opts
.isa
= ISA_MIPS2
;
11986 else if (strcmp (name
, "mips3") == 0)
11987 mips_opts
.isa
= ISA_MIPS3
;
11988 else if (strcmp (name
, "mips4") == 0)
11989 mips_opts
.isa
= ISA_MIPS4
;
11990 else if (strcmp (name
, "mips5") == 0)
11991 mips_opts
.isa
= ISA_MIPS5
;
11992 else if (strcmp (name
, "mips32") == 0)
11993 mips_opts
.isa
= ISA_MIPS32
;
11994 else if (strcmp (name
, "mips32r2") == 0)
11995 mips_opts
.isa
= ISA_MIPS32R2
;
11996 else if (strcmp (name
, "mips64") == 0)
11997 mips_opts
.isa
= ISA_MIPS64
;
11998 else if (strcmp (name
, "arch=default") == 0)
12001 mips_opts
.arch
= file_mips_arch
;
12002 mips_opts
.isa
= file_mips_isa
;
12004 else if (strncmp (name
, "arch=", 5) == 0)
12006 const struct mips_cpu_info
*p
;
12008 p
= mips_parse_cpu("internal use", name
+ 5);
12010 as_bad (_("unknown architecture %s"), name
+ 5);
12013 mips_opts
.arch
= p
->cpu
;
12014 mips_opts
.isa
= p
->isa
;
12018 as_bad (_("unknown ISA level %s"), name
+ 4);
12020 switch (mips_opts
.isa
)
12028 mips_opts
.gp32
= 1;
12029 mips_opts
.fp32
= 1;
12035 mips_opts
.gp32
= 0;
12036 mips_opts
.fp32
= 0;
12039 as_bad (_("unknown ISA level %s"), name
+ 4);
12044 mips_opts
.gp32
= file_mips_gp32
;
12045 mips_opts
.fp32
= file_mips_fp32
;
12048 else if (strcmp (name
, "autoextend") == 0)
12049 mips_opts
.noautoextend
= 0;
12050 else if (strcmp (name
, "noautoextend") == 0)
12051 mips_opts
.noautoextend
= 1;
12052 else if (strcmp (name
, "push") == 0)
12054 struct mips_option_stack
*s
;
12056 s
= (struct mips_option_stack
*) xmalloc (sizeof *s
);
12057 s
->next
= mips_opts_stack
;
12058 s
->options
= mips_opts
;
12059 mips_opts_stack
= s
;
12061 else if (strcmp (name
, "pop") == 0)
12063 struct mips_option_stack
*s
;
12065 s
= mips_opts_stack
;
12067 as_bad (_(".set pop with no .set push"));
12070 /* If we're changing the reorder mode we need to handle
12071 delay slots correctly. */
12072 if (s
->options
.noreorder
&& ! mips_opts
.noreorder
)
12073 mips_emit_delays (TRUE
);
12074 else if (! s
->options
.noreorder
&& mips_opts
.noreorder
)
12076 if (prev_nop_frag
!= NULL
)
12078 prev_nop_frag
->fr_fix
-= (prev_nop_frag_holds
12079 * (mips_opts
.mips16
? 2 : 4));
12080 prev_nop_frag
= NULL
;
12084 mips_opts
= s
->options
;
12085 mips_opts_stack
= s
->next
;
12091 as_warn (_("Tried to set unrecognized symbol: %s\n"), name
);
12093 *input_line_pointer
= ch
;
12094 demand_empty_rest_of_line ();
12097 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
12098 .option pic2. It means to generate SVR4 PIC calls. */
12101 s_abicalls (int ignore ATTRIBUTE_UNUSED
)
12103 mips_pic
= SVR4_PIC
;
12104 mips_abicalls
= TRUE
;
12105 if (USE_GLOBAL_POINTER_OPT
)
12107 if (g_switch_seen
&& g_switch_value
!= 0)
12108 as_warn (_("-G may not be used with SVR4 PIC code"));
12109 g_switch_value
= 0;
12111 bfd_set_gp_size (stdoutput
, 0);
12112 demand_empty_rest_of_line ();
12115 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12116 PIC code. It sets the $gp register for the function based on the
12117 function address, which is in the register named in the argument.
12118 This uses a relocation against _gp_disp, which is handled specially
12119 by the linker. The result is:
12120 lui $gp,%hi(_gp_disp)
12121 addiu $gp,$gp,%lo(_gp_disp)
12122 addu $gp,$gp,.cpload argument
12123 The .cpload argument is normally $25 == $t9. */
12126 s_cpload (int ignore ATTRIBUTE_UNUSED
)
12131 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12132 .cpload is ignored. */
12133 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
12139 /* .cpload should be in a .set noreorder section. */
12140 if (mips_opts
.noreorder
== 0)
12141 as_warn (_(".cpload not in noreorder section"));
12143 ex
.X_op
= O_symbol
;
12144 ex
.X_add_symbol
= symbol_find_or_make ("_gp_disp");
12145 ex
.X_op_symbol
= NULL
;
12146 ex
.X_add_number
= 0;
12148 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12149 symbol_get_bfdsym (ex
.X_add_symbol
)->flags
|= BSF_OBJECT
;
12151 macro_build_lui (NULL
, &icnt
, &ex
, mips_gp_register
);
12152 macro_build (NULL
, &icnt
, &ex
, "addiu", "t,r,j", mips_gp_register
,
12153 mips_gp_register
, BFD_RELOC_LO16
);
12155 macro_build (NULL
, &icnt
, NULL
, "addu", "d,v,t", mips_gp_register
,
12156 mips_gp_register
, tc_get_register (0));
12158 demand_empty_rest_of_line ();
12161 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12162 .cpsetup $reg1, offset|$reg2, label
12164 If offset is given, this results in:
12165 sd $gp, offset($sp)
12166 lui $gp, %hi(%neg(%gp_rel(label)))
12167 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12168 daddu $gp, $gp, $reg1
12170 If $reg2 is given, this results in:
12171 daddu $reg2, $gp, $0
12172 lui $gp, %hi(%neg(%gp_rel(label)))
12173 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12174 daddu $gp, $gp, $reg1
12175 $reg1 is normally $25 == $t9. */
12177 s_cpsetup (int ignore ATTRIBUTE_UNUSED
)
12179 expressionS ex_off
;
12180 expressionS ex_sym
;
12185 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12186 We also need NewABI support. */
12187 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12193 reg1
= tc_get_register (0);
12194 SKIP_WHITESPACE ();
12195 if (*input_line_pointer
!= ',')
12197 as_bad (_("missing argument separator ',' for .cpsetup"));
12201 ++input_line_pointer
;
12202 SKIP_WHITESPACE ();
12203 if (*input_line_pointer
== '$')
12205 mips_cpreturn_register
= tc_get_register (0);
12206 mips_cpreturn_offset
= -1;
12210 mips_cpreturn_offset
= get_absolute_expression ();
12211 mips_cpreturn_register
= -1;
12213 SKIP_WHITESPACE ();
12214 if (*input_line_pointer
!= ',')
12216 as_bad (_("missing argument separator ',' for .cpsetup"));
12220 ++input_line_pointer
;
12221 SKIP_WHITESPACE ();
12222 expression (&ex_sym
);
12224 if (mips_cpreturn_register
== -1)
12226 ex_off
.X_op
= O_constant
;
12227 ex_off
.X_add_symbol
= NULL
;
12228 ex_off
.X_op_symbol
= NULL
;
12229 ex_off
.X_add_number
= mips_cpreturn_offset
;
12231 macro_build (NULL
, &icnt
, &ex_off
, "sd", "t,o(b)", mips_gp_register
,
12232 BFD_RELOC_LO16
, SP
);
12235 macro_build (NULL
, &icnt
, NULL
, "daddu", "d,v,t", mips_cpreturn_register
,
12236 mips_gp_register
, 0);
12238 /* Ensure there's room for the next two instructions, so that `f'
12239 doesn't end up with an address in the wrong frag. */
12242 macro_build (NULL
, &icnt
, &ex_sym
, "lui", "t,u", mips_gp_register
,
12243 BFD_RELOC_GPREL16
);
12244 fix_new (frag_now
, f
- frag_now
->fr_literal
,
12245 8, NULL
, 0, 0, BFD_RELOC_MIPS_SUB
);
12246 fix_new (frag_now
, f
- frag_now
->fr_literal
,
12247 4, NULL
, 0, 0, BFD_RELOC_HI16_S
);
12250 macro_build (NULL
, &icnt
, &ex_sym
, "addiu", "t,r,j", mips_gp_register
,
12251 mips_gp_register
, BFD_RELOC_GPREL16
);
12252 fix_new (frag_now
, f
- frag_now
->fr_literal
,
12253 8, NULL
, 0, 0, BFD_RELOC_MIPS_SUB
);
12254 fix_new (frag_now
, f
- frag_now
->fr_literal
,
12255 4, NULL
, 0, 0, BFD_RELOC_LO16
);
12257 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t", mips_gp_register
,
12258 mips_gp_register
, reg1
);
12260 demand_empty_rest_of_line ();
12264 s_cplocal (int ignore ATTRIBUTE_UNUSED
)
12266 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12267 .cplocal is ignored. */
12268 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12274 mips_gp_register
= tc_get_register (0);
12275 demand_empty_rest_of_line ();
12278 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12279 offset from $sp. The offset is remembered, and after making a PIC
12280 call $gp is restored from that location. */
12283 s_cprestore (int ignore ATTRIBUTE_UNUSED
)
12288 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12289 .cprestore is ignored. */
12290 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
12296 mips_cprestore_offset
= get_absolute_expression ();
12297 mips_cprestore_valid
= 1;
12299 ex
.X_op
= O_constant
;
12300 ex
.X_add_symbol
= NULL
;
12301 ex
.X_op_symbol
= NULL
;
12302 ex
.X_add_number
= mips_cprestore_offset
;
12304 macro_build_ldst_constoffset (NULL
, &icnt
, &ex
, ADDRESS_STORE_INSN
,
12305 mips_gp_register
, SP
);
12307 demand_empty_rest_of_line ();
12310 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12311 was given in the preceeding .gpsetup, it results in:
12312 ld $gp, offset($sp)
12314 If a register $reg2 was given there, it results in:
12315 daddiu $gp, $gp, $reg2
12318 s_cpreturn (int ignore ATTRIBUTE_UNUSED
)
12323 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12324 We also need NewABI support. */
12325 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12331 if (mips_cpreturn_register
== -1)
12333 ex
.X_op
= O_constant
;
12334 ex
.X_add_symbol
= NULL
;
12335 ex
.X_op_symbol
= NULL
;
12336 ex
.X_add_number
= mips_cpreturn_offset
;
12338 macro_build (NULL
, &icnt
, &ex
, "ld", "t,o(b)", mips_gp_register
,
12339 BFD_RELOC_LO16
, SP
);
12342 macro_build (NULL
, &icnt
, NULL
, "daddu", "d,v,t", mips_gp_register
,
12343 mips_cpreturn_register
, 0);
12345 demand_empty_rest_of_line ();
12348 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12349 code. It sets the offset to use in gp_rel relocations. */
12352 s_gpvalue (int ignore ATTRIBUTE_UNUSED
)
12354 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12355 We also need NewABI support. */
12356 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12362 mips_gprel_offset
= get_absolute_expression ();
12364 demand_empty_rest_of_line ();
12367 /* Handle the .gpword pseudo-op. This is used when generating PIC
12368 code. It generates a 32 bit GP relative reloc. */
12371 s_gpword (int ignore ATTRIBUTE_UNUSED
)
12377 /* When not generating PIC code, this is treated as .word. */
12378 if (mips_pic
!= SVR4_PIC
)
12384 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
12385 mips_emit_delays (TRUE
);
12387 mips_align (2, 0, label
);
12388 mips_clear_insn_labels ();
12392 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
12394 as_bad (_("Unsupported use of .gpword"));
12395 ignore_rest_of_line ();
12399 md_number_to_chars (p
, 0, 4);
12400 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4, &ex
, FALSE
,
12401 BFD_RELOC_GPREL32
);
12403 demand_empty_rest_of_line ();
12407 s_gpdword (int ignore ATTRIBUTE_UNUSED
)
12413 /* When not generating PIC code, this is treated as .dword. */
12414 if (mips_pic
!= SVR4_PIC
)
12420 label
= insn_labels
!= NULL
? insn_labels
->label
: NULL
;
12421 mips_emit_delays (TRUE
);
12423 mips_align (3, 0, label
);
12424 mips_clear_insn_labels ();
12428 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
12430 as_bad (_("Unsupported use of .gpdword"));
12431 ignore_rest_of_line ();
12435 md_number_to_chars (p
, 0, 8);
12436 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4, &ex
, FALSE
,
12437 BFD_RELOC_GPREL32
);
12439 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12440 ex
.X_op
= O_absent
;
12441 ex
.X_add_symbol
= 0;
12442 ex
.X_add_number
= 0;
12443 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 8, &ex
, FALSE
,
12446 demand_empty_rest_of_line ();
12449 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12450 tables in SVR4 PIC code. */
12453 s_cpadd (int ignore ATTRIBUTE_UNUSED
)
12458 /* This is ignored when not generating SVR4 PIC code. */
12459 if (mips_pic
!= SVR4_PIC
)
12465 /* Add $gp to the register named as an argument. */
12466 reg
= tc_get_register (0);
12467 macro_build (NULL
, &icnt
, NULL
, ADDRESS_ADD_INSN
, "d,v,t",
12468 reg
, reg
, mips_gp_register
);
12470 demand_empty_rest_of_line ();
12473 /* Handle the .insn pseudo-op. This marks instruction labels in
12474 mips16 mode. This permits the linker to handle them specially,
12475 such as generating jalx instructions when needed. We also make
12476 them odd for the duration of the assembly, in order to generate the
12477 right sort of code. We will make them even in the adjust_symtab
12478 routine, while leaving them marked. This is convenient for the
12479 debugger and the disassembler. The linker knows to make them odd
12483 s_insn (int ignore ATTRIBUTE_UNUSED
)
12485 mips16_mark_labels ();
12487 demand_empty_rest_of_line ();
12490 /* Handle a .stabn directive. We need these in order to mark a label
12491 as being a mips16 text label correctly. Sometimes the compiler
12492 will emit a label, followed by a .stabn, and then switch sections.
12493 If the label and .stabn are in mips16 mode, then the label is
12494 really a mips16 text label. */
12497 s_mips_stab (int type
)
12500 mips16_mark_labels ();
12505 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12509 s_mips_weakext (int ignore ATTRIBUTE_UNUSED
)
12516 name
= input_line_pointer
;
12517 c
= get_symbol_end ();
12518 symbolP
= symbol_find_or_make (name
);
12519 S_SET_WEAK (symbolP
);
12520 *input_line_pointer
= c
;
12522 SKIP_WHITESPACE ();
12524 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
12526 if (S_IS_DEFINED (symbolP
))
12528 as_bad ("ignoring attempt to redefine symbol %s",
12529 S_GET_NAME (symbolP
));
12530 ignore_rest_of_line ();
12534 if (*input_line_pointer
== ',')
12536 ++input_line_pointer
;
12537 SKIP_WHITESPACE ();
12541 if (exp
.X_op
!= O_symbol
)
12543 as_bad ("bad .weakext directive");
12544 ignore_rest_of_line ();
12547 symbol_set_value_expression (symbolP
, &exp
);
12550 demand_empty_rest_of_line ();
12553 /* Parse a register string into a number. Called from the ECOFF code
12554 to parse .frame. The argument is non-zero if this is the frame
12555 register, so that we can record it in mips_frame_reg. */
12558 tc_get_register (int frame
)
12562 SKIP_WHITESPACE ();
12563 if (*input_line_pointer
++ != '$')
12565 as_warn (_("expected `$'"));
12568 else if (ISDIGIT (*input_line_pointer
))
12570 reg
= get_absolute_expression ();
12571 if (reg
< 0 || reg
>= 32)
12573 as_warn (_("Bad register number"));
12579 if (strncmp (input_line_pointer
, "ra", 2) == 0)
12582 input_line_pointer
+= 2;
12584 else if (strncmp (input_line_pointer
, "fp", 2) == 0)
12587 input_line_pointer
+= 2;
12589 else if (strncmp (input_line_pointer
, "sp", 2) == 0)
12592 input_line_pointer
+= 2;
12594 else if (strncmp (input_line_pointer
, "gp", 2) == 0)
12597 input_line_pointer
+= 2;
12599 else if (strncmp (input_line_pointer
, "at", 2) == 0)
12602 input_line_pointer
+= 2;
12604 else if (strncmp (input_line_pointer
, "kt0", 3) == 0)
12607 input_line_pointer
+= 3;
12609 else if (strncmp (input_line_pointer
, "kt1", 3) == 0)
12612 input_line_pointer
+= 3;
12614 else if (strncmp (input_line_pointer
, "zero", 4) == 0)
12617 input_line_pointer
+= 4;
12621 as_warn (_("Unrecognized register name"));
12623 while (ISALNUM(*input_line_pointer
))
12624 input_line_pointer
++;
12629 mips_frame_reg
= reg
!= 0 ? reg
: SP
;
12630 mips_frame_reg_valid
= 1;
12631 mips_cprestore_valid
= 0;
12637 md_section_align (asection
*seg
, valueT addr
)
12639 int align
= bfd_get_section_alignment (stdoutput
, seg
);
12642 /* We don't need to align ELF sections to the full alignment.
12643 However, Irix 5 may prefer that we align them at least to a 16
12644 byte boundary. We don't bother to align the sections if we are
12645 targeted for an embedded system. */
12646 if (strcmp (TARGET_OS
, "elf") == 0)
12652 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
12655 /* Utility routine, called from above as well. If called while the
12656 input file is still being read, it's only an approximation. (For
12657 example, a symbol may later become defined which appeared to be
12658 undefined earlier.) */
12661 nopic_need_relax (symbolS
*sym
, int before_relaxing
)
12666 if (USE_GLOBAL_POINTER_OPT
&& g_switch_value
> 0)
12668 const char *symname
;
12671 /* Find out whether this symbol can be referenced off the $gp
12672 register. It can be if it is smaller than the -G size or if
12673 it is in the .sdata or .sbss section. Certain symbols can
12674 not be referenced off the $gp, although it appears as though
12676 symname
= S_GET_NAME (sym
);
12677 if (symname
!= (const char *) NULL
12678 && (strcmp (symname
, "eprol") == 0
12679 || strcmp (symname
, "etext") == 0
12680 || strcmp (symname
, "_gp") == 0
12681 || strcmp (symname
, "edata") == 0
12682 || strcmp (symname
, "_fbss") == 0
12683 || strcmp (symname
, "_fdata") == 0
12684 || strcmp (symname
, "_ftext") == 0
12685 || strcmp (symname
, "end") == 0
12686 || strcmp (symname
, "_gp_disp") == 0))
12688 else if ((! S_IS_DEFINED (sym
) || S_IS_COMMON (sym
))
12690 #ifndef NO_ECOFF_DEBUGGING
12691 || (symbol_get_obj (sym
)->ecoff_extern_size
!= 0
12692 && (symbol_get_obj (sym
)->ecoff_extern_size
12693 <= g_switch_value
))
12695 /* We must defer this decision until after the whole
12696 file has been read, since there might be a .extern
12697 after the first use of this symbol. */
12698 || (before_relaxing
12699 #ifndef NO_ECOFF_DEBUGGING
12700 && symbol_get_obj (sym
)->ecoff_extern_size
== 0
12702 && S_GET_VALUE (sym
) == 0)
12703 || (S_GET_VALUE (sym
) != 0
12704 && S_GET_VALUE (sym
) <= g_switch_value
)))
12708 const char *segname
;
12710 segname
= segment_name (S_GET_SEGMENT (sym
));
12711 assert (strcmp (segname
, ".lit8") != 0
12712 && strcmp (segname
, ".lit4") != 0);
12713 change
= (strcmp (segname
, ".sdata") != 0
12714 && strcmp (segname
, ".sbss") != 0
12715 && strncmp (segname
, ".sdata.", 7) != 0
12716 && strncmp (segname
, ".gnu.linkonce.s.", 16) != 0);
12721 /* We are not optimizing for the $gp register. */
12726 /* Return true if the given symbol should be considered local for SVR4 PIC. */
12729 pic_need_relax (symbolS
*sym
, asection
*segtype
)
12732 bfd_boolean linkonce
;
12734 /* Handle the case of a symbol equated to another symbol. */
12735 while (symbol_equated_reloc_p (sym
))
12739 /* It's possible to get a loop here in a badly written
12741 n
= symbol_get_value_expression (sym
)->X_add_symbol
;
12747 symsec
= S_GET_SEGMENT (sym
);
12749 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12751 if (symsec
!= segtype
&& ! S_IS_LOCAL (sym
))
12753 if ((bfd_get_section_flags (stdoutput
, symsec
) & SEC_LINK_ONCE
)
12757 /* The GNU toolchain uses an extension for ELF: a section
12758 beginning with the magic string .gnu.linkonce is a linkonce
12760 if (strncmp (segment_name (symsec
), ".gnu.linkonce",
12761 sizeof ".gnu.linkonce" - 1) == 0)
12765 /* This must duplicate the test in adjust_reloc_syms. */
12766 return (symsec
!= &bfd_und_section
12767 && symsec
!= &bfd_abs_section
12768 && ! bfd_is_com_section (symsec
)
12771 /* A global or weak symbol is treated as external. */
12772 && (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
12773 || (! S_IS_WEAK (sym
)
12774 && (! S_IS_EXTERNAL (sym
)
12775 || mips_pic
== EMBEDDED_PIC
)))
12781 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12782 extended opcode. SEC is the section the frag is in. */
12785 mips16_extended_frag (fragS
*fragp
, asection
*sec
, long stretch
)
12788 register const struct mips16_immed_operand
*op
;
12790 int mintiny
, maxtiny
;
12794 if (RELAX_MIPS16_USER_SMALL (fragp
->fr_subtype
))
12796 if (RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
))
12799 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
12800 op
= mips16_immed_operands
;
12801 while (op
->type
!= type
)
12804 assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
12809 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
12812 maxtiny
= 1 << op
->nbits
;
12817 maxtiny
= (1 << op
->nbits
) - 1;
12822 mintiny
= - (1 << (op
->nbits
- 1));
12823 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
12826 sym_frag
= symbol_get_frag (fragp
->fr_symbol
);
12827 val
= S_GET_VALUE (fragp
->fr_symbol
);
12828 symsec
= S_GET_SEGMENT (fragp
->fr_symbol
);
12834 /* We won't have the section when we are called from
12835 mips_relax_frag. However, we will always have been called
12836 from md_estimate_size_before_relax first. If this is a
12837 branch to a different section, we mark it as such. If SEC is
12838 NULL, and the frag is not marked, then it must be a branch to
12839 the same section. */
12842 if (RELAX_MIPS16_LONG_BRANCH (fragp
->fr_subtype
))
12847 /* Must have been called from md_estimate_size_before_relax. */
12850 fragp
->fr_subtype
=
12851 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12853 /* FIXME: We should support this, and let the linker
12854 catch branches and loads that are out of range. */
12855 as_bad_where (fragp
->fr_file
, fragp
->fr_line
,
12856 _("unsupported PC relative reference to different section"));
12860 if (fragp
!= sym_frag
&& sym_frag
->fr_address
== 0)
12861 /* Assume non-extended on the first relaxation pass.
12862 The address we have calculated will be bogus if this is
12863 a forward branch to another frag, as the forward frag
12864 will have fr_address == 0. */
12868 /* In this case, we know for sure that the symbol fragment is in
12869 the same section. If the relax_marker of the symbol fragment
12870 differs from the relax_marker of this fragment, we have not
12871 yet adjusted the symbol fragment fr_address. We want to add
12872 in STRETCH in order to get a better estimate of the address.
12873 This particularly matters because of the shift bits. */
12875 && sym_frag
->relax_marker
!= fragp
->relax_marker
)
12879 /* Adjust stretch for any alignment frag. Note that if have
12880 been expanding the earlier code, the symbol may be
12881 defined in what appears to be an earlier frag. FIXME:
12882 This doesn't handle the fr_subtype field, which specifies
12883 a maximum number of bytes to skip when doing an
12885 for (f
= fragp
; f
!= NULL
&& f
!= sym_frag
; f
= f
->fr_next
)
12887 if (f
->fr_type
== rs_align
|| f
->fr_type
== rs_align_code
)
12890 stretch
= - ((- stretch
)
12891 & ~ ((1 << (int) f
->fr_offset
) - 1));
12893 stretch
&= ~ ((1 << (int) f
->fr_offset
) - 1);
12902 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
12904 /* The base address rules are complicated. The base address of
12905 a branch is the following instruction. The base address of a
12906 PC relative load or add is the instruction itself, but if it
12907 is in a delay slot (in which case it can not be extended) use
12908 the address of the instruction whose delay slot it is in. */
12909 if (type
== 'p' || type
== 'q')
12913 /* If we are currently assuming that this frag should be
12914 extended, then, the current address is two bytes
12916 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
12919 /* Ignore the low bit in the target, since it will be set
12920 for a text label. */
12921 if ((val
& 1) != 0)
12924 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
12926 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
12929 val
-= addr
& ~ ((1 << op
->shift
) - 1);
12931 /* Branch offsets have an implicit 0 in the lowest bit. */
12932 if (type
== 'p' || type
== 'q')
12935 /* If any of the shifted bits are set, we must use an extended
12936 opcode. If the address depends on the size of this
12937 instruction, this can lead to a loop, so we arrange to always
12938 use an extended opcode. We only check this when we are in
12939 the main relaxation loop, when SEC is NULL. */
12940 if ((val
& ((1 << op
->shift
) - 1)) != 0 && sec
== NULL
)
12942 fragp
->fr_subtype
=
12943 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12947 /* If we are about to mark a frag as extended because the value
12948 is precisely maxtiny + 1, then there is a chance of an
12949 infinite loop as in the following code:
12954 In this case when the la is extended, foo is 0x3fc bytes
12955 away, so the la can be shrunk, but then foo is 0x400 away, so
12956 the la must be extended. To avoid this loop, we mark the
12957 frag as extended if it was small, and is about to become
12958 extended with a value of maxtiny + 1. */
12959 if (val
== ((maxtiny
+ 1) << op
->shift
)
12960 && ! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
)
12963 fragp
->fr_subtype
=
12964 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
12968 else if (symsec
!= absolute_section
&& sec
!= NULL
)
12969 as_bad_where (fragp
->fr_file
, fragp
->fr_line
, _("unsupported relocation"));
12971 if ((val
& ((1 << op
->shift
) - 1)) != 0
12972 || val
< (mintiny
<< op
->shift
)
12973 || val
> (maxtiny
<< op
->shift
))
12979 /* Compute the length of a branch sequence, and adjust the
12980 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
12981 worst-case length is computed, with UPDATE being used to indicate
12982 whether an unconditional (-1), branch-likely (+1) or regular (0)
12983 branch is to be computed. */
12985 relaxed_branch_length (fragS
*fragp
, asection
*sec
, int update
)
12987 bfd_boolean toofar
;
12991 && S_IS_DEFINED (fragp
->fr_symbol
)
12992 && sec
== S_GET_SEGMENT (fragp
->fr_symbol
))
12997 val
= S_GET_VALUE (fragp
->fr_symbol
) + fragp
->fr_offset
;
12999 addr
= fragp
->fr_address
+ fragp
->fr_fix
+ 4;
13003 toofar
= val
< - (0x8000 << 2) || val
>= (0x8000 << 2);
13006 /* If the symbol is not defined or it's in a different segment,
13007 assume the user knows what's going on and emit a short
13013 if (fragp
&& update
&& toofar
!= RELAX_BRANCH_TOOFAR (fragp
->fr_subtype
))
13015 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp
->fr_subtype
),
13016 RELAX_BRANCH_LIKELY (fragp
->fr_subtype
),
13017 RELAX_BRANCH_LINK (fragp
->fr_subtype
),
13023 if (fragp
? RELAX_BRANCH_LIKELY (fragp
->fr_subtype
) : (update
> 0))
13026 if (mips_pic
!= NO_PIC
)
13028 /* Additional space for PIC loading of target address. */
13030 if (mips_opts
.isa
== ISA_MIPS1
)
13031 /* Additional space for $at-stabilizing nop. */
13035 /* If branch is conditional. */
13036 if (fragp
? !RELAX_BRANCH_UNCOND (fragp
->fr_subtype
) : (update
>= 0))
13043 /* Estimate the size of a frag before relaxing. Unless this is the
13044 mips16, we are not really relaxing here, and the final size is
13045 encoded in the subtype information. For the mips16, we have to
13046 decide whether we are using an extended opcode or not. */
13049 md_estimate_size_before_relax (fragS
*fragp
, asection
*segtype
)
13053 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
13056 fragp
->fr_var
= relaxed_branch_length (fragp
, segtype
, FALSE
);
13058 return fragp
->fr_var
;
13061 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
13062 /* We don't want to modify the EXTENDED bit here; it might get us
13063 into infinite loops. We change it only in mips_relax_frag(). */
13064 return (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
) ? 4 : 2);
13066 if (mips_pic
== NO_PIC
)
13067 change
= nopic_need_relax (fragp
->fr_symbol
, 0);
13068 else if (mips_pic
== SVR4_PIC
)
13069 change
= pic_need_relax (fragp
->fr_symbol
, segtype
);
13075 /* Record the offset to the first reloc in the fr_opcode field.
13076 This lets md_convert_frag and tc_gen_reloc know that the code
13077 must be expanded. */
13078 fragp
->fr_opcode
= (fragp
->fr_literal
13080 - RELAX_OLD (fragp
->fr_subtype
)
13081 + RELAX_RELOC1 (fragp
->fr_subtype
));
13082 /* FIXME: This really needs as_warn_where. */
13083 if (RELAX_WARN (fragp
->fr_subtype
))
13084 as_warn (_("AT used after \".set noat\" or macro used after "
13085 "\".set nomacro\""));
13087 return RELAX_NEW (fragp
->fr_subtype
) - RELAX_OLD (fragp
->fr_subtype
);
13093 /* This is called to see whether a reloc against a defined symbol
13094 should be converted into a reloc against a section. Don't adjust
13095 MIPS16 jump relocations, so we don't have to worry about the format
13096 of the offset in the .o file. Don't adjust relocations against
13097 mips16 symbols, so that the linker can find them if it needs to set
13101 mips_fix_adjustable (fixS
*fixp
)
13103 if (fixp
->fx_r_type
== BFD_RELOC_MIPS16_JMP
)
13106 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
13107 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
13110 if (fixp
->fx_addsy
== NULL
)
13114 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
13115 && S_GET_OTHER (fixp
->fx_addsy
) == STO_MIPS16
13116 && fixp
->fx_subsy
== NULL
)
13123 /* Translate internal representation of relocation info to BFD target
13127 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
13129 static arelent
*retval
[4];
13131 bfd_reloc_code_real_type code
;
13133 memset (retval
, 0, sizeof(retval
));
13134 reloc
= retval
[0] = (arelent
*) xcalloc (1, sizeof (arelent
));
13135 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
13136 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
13137 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
13139 if (mips_pic
== EMBEDDED_PIC
13140 && SWITCH_TABLE (fixp
))
13142 /* For a switch table entry we use a special reloc. The addend
13143 is actually the difference between the reloc address and the
13145 reloc
->addend
= reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
);
13146 if (OUTPUT_FLAVOR
!= bfd_target_ecoff_flavour
)
13147 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
13148 fixp
->fx_r_type
= BFD_RELOC_GPREL32
;
13150 else if (fixp
->fx_r_type
== BFD_RELOC_PCREL_LO16
)
13152 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
13153 reloc
->addend
= fixp
->fx_addnumber
;
13156 /* We use a special addend for an internal RELLO reloc. */
13157 if (symbol_section_p (fixp
->fx_addsy
))
13158 reloc
->addend
= reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
);
13160 reloc
->addend
= fixp
->fx_addnumber
+ reloc
->address
;
13163 else if (fixp
->fx_r_type
== BFD_RELOC_PCREL_HI16_S
)
13165 assert (fixp
->fx_next
!= NULL
13166 && fixp
->fx_next
->fx_r_type
== BFD_RELOC_PCREL_LO16
);
13168 /* The reloc is relative to the RELLO; adjust the addend
13170 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
13171 reloc
->addend
= fixp
->fx_next
->fx_addnumber
;
13174 /* We use a special addend for an internal RELHI reloc. */
13175 if (symbol_section_p (fixp
->fx_addsy
))
13176 reloc
->addend
= (fixp
->fx_next
->fx_frag
->fr_address
13177 + fixp
->fx_next
->fx_where
13178 - S_GET_VALUE (fixp
->fx_subsy
));
13180 reloc
->addend
= (fixp
->fx_addnumber
13181 + fixp
->fx_next
->fx_frag
->fr_address
13182 + fixp
->fx_next
->fx_where
);
13185 else if (fixp
->fx_pcrel
== 0 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
13186 reloc
->addend
= fixp
->fx_addnumber
;
13189 if (OUTPUT_FLAVOR
!= bfd_target_aout_flavour
)
13190 /* A gruesome hack which is a result of the gruesome gas reloc
13192 reloc
->addend
= reloc
->address
;
13194 reloc
->addend
= -reloc
->address
;
13197 /* If this is a variant frag, we may need to adjust the existing
13198 reloc and generate a new one. */
13199 if (fixp
->fx_frag
->fr_opcode
!= NULL
13200 && ((fixp
->fx_r_type
== BFD_RELOC_GPREL16
13202 || (fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_DISP
13204 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT16
13205 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL16
13206 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_HI16
13207 || fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_LO16
13208 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_HI16
13209 || fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_LO16
)
13214 assert (! RELAX_MIPS16_P (fixp
->fx_frag
->fr_subtype
));
13216 /* If this is not the last reloc in this frag, then we have two
13217 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
13218 CALL_HI16/CALL_LO16, both of which are being replaced. Let
13219 the second one handle all of them. */
13220 if (fixp
->fx_next
!= NULL
13221 && fixp
->fx_frag
== fixp
->fx_next
->fx_frag
)
13223 assert ((fixp
->fx_r_type
== BFD_RELOC_GPREL16
13224 && fixp
->fx_next
->fx_r_type
== BFD_RELOC_GPREL16
)
13225 || (fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT_HI16
13226 && (fixp
->fx_next
->fx_r_type
13227 == BFD_RELOC_MIPS_GOT_LO16
))
13228 || (fixp
->fx_r_type
== BFD_RELOC_MIPS_CALL_HI16
13229 && (fixp
->fx_next
->fx_r_type
13230 == BFD_RELOC_MIPS_CALL_LO16
)));
13235 fixp
->fx_where
= fixp
->fx_frag
->fr_opcode
- fixp
->fx_frag
->fr_literal
;
13236 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
13237 reloc
->addend
+= fixp
->fx_frag
->tc_frag_data
.tc_fr_offset
;
13238 reloc2
= retval
[1] = (arelent
*) xmalloc (sizeof (arelent
));
13239 reloc2
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
13240 *reloc2
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
13241 reloc2
->address
= (reloc
->address
13242 + (RELAX_RELOC2 (fixp
->fx_frag
->fr_subtype
)
13243 - RELAX_RELOC1 (fixp
->fx_frag
->fr_subtype
)));
13244 reloc2
->addend
= fixp
->fx_addnumber
- S_GET_VALUE (fixp
->fx_addsy
)
13245 + fixp
->fx_frag
->tc_frag_data
.tc_fr_offset
;
13246 reloc2
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_LO16
);
13247 assert (reloc2
->howto
!= NULL
);
13249 if (RELAX_RELOC3 (fixp
->fx_frag
->fr_subtype
))
13253 reloc3
= retval
[2] = (arelent
*) xmalloc (sizeof (arelent
));
13255 reloc3
->address
+= 4;
13258 if (mips_pic
== NO_PIC
)
13260 assert (fixp
->fx_r_type
== BFD_RELOC_GPREL16
);
13261 fixp
->fx_r_type
= BFD_RELOC_HI16_S
;
13263 else if (mips_pic
== SVR4_PIC
)
13265 switch (fixp
->fx_r_type
)
13269 case BFD_RELOC_MIPS_GOT16
:
13271 case BFD_RELOC_MIPS_GOT_LO16
:
13272 case BFD_RELOC_MIPS_CALL_LO16
:
13275 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT_PAGE
;
13276 reloc2
->howto
= bfd_reloc_type_lookup
13277 (stdoutput
, BFD_RELOC_MIPS_GOT_OFST
);
13280 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT16
;
13282 case BFD_RELOC_MIPS_CALL16
:
13283 case BFD_RELOC_MIPS_GOT_OFST
:
13284 case BFD_RELOC_MIPS_GOT_DISP
:
13287 /* It may seem nonsensical to relax GOT_DISP to
13288 GOT_DISP, but we're actually turning a GOT_DISP
13289 without offset into a GOT_DISP with an offset,
13290 getting rid of the separate addition, which we can
13291 do when the symbol is found to be local. */
13292 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT_DISP
;
13296 fixp
->fx_r_type
= BFD_RELOC_MIPS_GOT16
;
13304 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13305 entry to be used in the relocation's section offset. */
13306 if (! HAVE_NEWABI
&& fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
13308 reloc
->address
= reloc
->addend
;
13312 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
13313 fixup_segment converted a non-PC relative reloc into a PC
13314 relative reloc. In such a case, we need to convert the reloc
13316 code
= fixp
->fx_r_type
;
13317 if (fixp
->fx_pcrel
)
13322 code
= BFD_RELOC_8_PCREL
;
13325 code
= BFD_RELOC_16_PCREL
;
13328 code
= BFD_RELOC_32_PCREL
;
13331 code
= BFD_RELOC_64_PCREL
;
13333 case BFD_RELOC_8_PCREL
:
13334 case BFD_RELOC_16_PCREL
:
13335 case BFD_RELOC_32_PCREL
:
13336 case BFD_RELOC_64_PCREL
:
13337 case BFD_RELOC_16_PCREL_S2
:
13338 case BFD_RELOC_PCREL_HI16_S
:
13339 case BFD_RELOC_PCREL_LO16
:
13342 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
13343 _("Cannot make %s relocation PC relative"),
13344 bfd_get_reloc_code_name (code
));
13348 /* To support a PC relative reloc when generating embedded PIC code
13349 for ECOFF, we use a Cygnus extension. We check for that here to
13350 make sure that we don't let such a reloc escape normally. */
13351 if ((OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
13352 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
13353 && code
== BFD_RELOC_16_PCREL_S2
13354 && mips_pic
!= EMBEDDED_PIC
)
13355 reloc
->howto
= NULL
;
13357 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
13359 if (reloc
->howto
== NULL
)
13361 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
13362 _("Can not represent %s relocation in this object file format"),
13363 bfd_get_reloc_code_name (code
));
13370 /* Relax a machine dependent frag. This returns the amount by which
13371 the current size of the frag should change. */
13374 mips_relax_frag (asection
*sec
, fragS
*fragp
, long stretch
)
13376 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
13378 offsetT old_var
= fragp
->fr_var
;
13380 fragp
->fr_var
= relaxed_branch_length (fragp
, sec
, TRUE
);
13382 return fragp
->fr_var
- old_var
;
13385 if (! RELAX_MIPS16_P (fragp
->fr_subtype
))
13388 if (mips16_extended_frag (fragp
, NULL
, stretch
))
13390 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13392 fragp
->fr_subtype
= RELAX_MIPS16_MARK_EXTENDED (fragp
->fr_subtype
);
13397 if (! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13399 fragp
->fr_subtype
= RELAX_MIPS16_CLEAR_EXTENDED (fragp
->fr_subtype
);
13406 /* Convert a machine dependent frag. */
13409 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec
, fragS
*fragp
)
13414 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
13417 unsigned long insn
;
13421 buf
= (bfd_byte
*)fragp
->fr_literal
+ fragp
->fr_fix
;
13423 if (target_big_endian
)
13424 insn
= bfd_getb32 (buf
);
13426 insn
= bfd_getl32 (buf
);
13428 if (!RELAX_BRANCH_TOOFAR (fragp
->fr_subtype
))
13430 /* We generate a fixup instead of applying it right now
13431 because, if there are linker relaxations, we're going to
13432 need the relocations. */
13433 exp
.X_op
= O_symbol
;
13434 exp
.X_add_symbol
= fragp
->fr_symbol
;
13435 exp
.X_add_number
= fragp
->fr_offset
;
13437 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13439 BFD_RELOC_16_PCREL_S2
);
13440 fixp
->fx_file
= fragp
->fr_file
;
13441 fixp
->fx_line
= fragp
->fr_line
;
13443 md_number_to_chars (buf
, insn
, 4);
13450 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
13451 _("relaxed out-of-range branch into a jump"));
13453 if (RELAX_BRANCH_UNCOND (fragp
->fr_subtype
))
13456 if (!RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13458 /* Reverse the branch. */
13459 switch ((insn
>> 28) & 0xf)
13462 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13463 have the condition reversed by tweaking a single
13464 bit, and their opcodes all have 0x4???????. */
13465 assert ((insn
& 0xf1000000) == 0x41000000);
13466 insn
^= 0x00010000;
13470 /* bltz 0x04000000 bgez 0x04010000
13471 bltzal 0x04100000 bgezal 0x04110000 */
13472 assert ((insn
& 0xfc0e0000) == 0x04000000);
13473 insn
^= 0x00010000;
13477 /* beq 0x10000000 bne 0x14000000
13478 blez 0x18000000 bgtz 0x1c000000 */
13479 insn
^= 0x04000000;
13487 if (RELAX_BRANCH_LINK (fragp
->fr_subtype
))
13489 /* Clear the and-link bit. */
13490 assert ((insn
& 0xfc1c0000) == 0x04100000);
13492 /* bltzal 0x04100000 bgezal 0x04110000
13493 bltzall 0x04120000 bgezall 0x04130000 */
13494 insn
&= ~0x00100000;
13497 /* Branch over the branch (if the branch was likely) or the
13498 full jump (not likely case). Compute the offset from the
13499 current instruction to branch to. */
13500 if (RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13504 /* How many bytes in instructions we've already emitted? */
13505 i
= buf
- (bfd_byte
*)fragp
->fr_literal
- fragp
->fr_fix
;
13506 /* How many bytes in instructions from here to the end? */
13507 i
= fragp
->fr_var
- i
;
13509 /* Convert to instruction count. */
13511 /* Branch counts from the next instruction. */
13514 /* Branch over the jump. */
13515 md_number_to_chars (buf
, insn
, 4);
13519 md_number_to_chars (buf
, 0, 4);
13522 if (RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13524 /* beql $0, $0, 2f */
13526 /* Compute the PC offset from the current instruction to
13527 the end of the variable frag. */
13528 /* How many bytes in instructions we've already emitted? */
13529 i
= buf
- (bfd_byte
*)fragp
->fr_literal
- fragp
->fr_fix
;
13530 /* How many bytes in instructions from here to the end? */
13531 i
= fragp
->fr_var
- i
;
13532 /* Convert to instruction count. */
13534 /* Don't decrement i, because we want to branch over the
13538 md_number_to_chars (buf
, insn
, 4);
13541 md_number_to_chars (buf
, 0, 4);
13546 if (mips_pic
== NO_PIC
)
13549 insn
= (RELAX_BRANCH_LINK (fragp
->fr_subtype
)
13550 ? 0x0c000000 : 0x08000000);
13551 exp
.X_op
= O_symbol
;
13552 exp
.X_add_symbol
= fragp
->fr_symbol
;
13553 exp
.X_add_number
= fragp
->fr_offset
;
13555 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13556 4, &exp
, 0, BFD_RELOC_MIPS_JMP
);
13557 fixp
->fx_file
= fragp
->fr_file
;
13558 fixp
->fx_line
= fragp
->fr_line
;
13560 md_number_to_chars (buf
, insn
, 4);
13565 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13566 insn
= HAVE_64BIT_ADDRESSES
? 0xdf810000 : 0x8f810000;
13567 exp
.X_op
= O_symbol
;
13568 exp
.X_add_symbol
= fragp
->fr_symbol
;
13569 exp
.X_add_number
= fragp
->fr_offset
;
13571 if (fragp
->fr_offset
)
13573 exp
.X_add_symbol
= make_expr_symbol (&exp
);
13574 exp
.X_add_number
= 0;
13577 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13578 4, &exp
, 0, BFD_RELOC_MIPS_GOT16
);
13579 fixp
->fx_file
= fragp
->fr_file
;
13580 fixp
->fx_line
= fragp
->fr_line
;
13582 md_number_to_chars (buf
, insn
, 4);
13585 if (mips_opts
.isa
== ISA_MIPS1
)
13588 md_number_to_chars (buf
, 0, 4);
13592 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
13593 insn
= HAVE_64BIT_ADDRESSES
? 0x64210000 : 0x24210000;
13595 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13596 4, &exp
, 0, BFD_RELOC_LO16
);
13597 fixp
->fx_file
= fragp
->fr_file
;
13598 fixp
->fx_line
= fragp
->fr_line
;
13600 md_number_to_chars (buf
, insn
, 4);
13604 if (RELAX_BRANCH_LINK (fragp
->fr_subtype
))
13609 md_number_to_chars (buf
, insn
, 4);
13614 assert (buf
== (bfd_byte
*)fragp
->fr_literal
13615 + fragp
->fr_fix
+ fragp
->fr_var
);
13617 fragp
->fr_fix
+= fragp
->fr_var
;
13622 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
13625 register const struct mips16_immed_operand
*op
;
13626 bfd_boolean small
, ext
;
13629 unsigned long insn
;
13630 bfd_boolean use_extend
;
13631 unsigned short extend
;
13633 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
13634 op
= mips16_immed_operands
;
13635 while (op
->type
!= type
)
13638 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13649 resolve_symbol_value (fragp
->fr_symbol
);
13650 val
= S_GET_VALUE (fragp
->fr_symbol
);
13655 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
13657 /* The rules for the base address of a PC relative reloc are
13658 complicated; see mips16_extended_frag. */
13659 if (type
== 'p' || type
== 'q')
13664 /* Ignore the low bit in the target, since it will be
13665 set for a text label. */
13666 if ((val
& 1) != 0)
13669 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
13671 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
13674 addr
&= ~ (addressT
) ((1 << op
->shift
) - 1);
13677 /* Make sure the section winds up with the alignment we have
13680 record_alignment (asec
, op
->shift
);
13684 && (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
)
13685 || RELAX_MIPS16_DSLOT (fragp
->fr_subtype
)))
13686 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
13687 _("extended instruction in delay slot"));
13689 buf
= (bfd_byte
*) (fragp
->fr_literal
+ fragp
->fr_fix
);
13691 if (target_big_endian
)
13692 insn
= bfd_getb16 (buf
);
13694 insn
= bfd_getl16 (buf
);
13696 mips16_immed (fragp
->fr_file
, fragp
->fr_line
, type
, val
,
13697 RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
),
13698 small
, ext
, &insn
, &use_extend
, &extend
);
13702 md_number_to_chars (buf
, 0xf000 | extend
, 2);
13703 fragp
->fr_fix
+= 2;
13707 md_number_to_chars (buf
, insn
, 2);
13708 fragp
->fr_fix
+= 2;
13713 if (fragp
->fr_opcode
== NULL
)
13716 old
= RELAX_OLD (fragp
->fr_subtype
);
13717 new = RELAX_NEW (fragp
->fr_subtype
);
13718 fixptr
= fragp
->fr_literal
+ fragp
->fr_fix
;
13721 memmove (fixptr
- old
, fixptr
, new);
13723 fragp
->fr_fix
+= new - old
;
13729 /* This function is called after the relocs have been generated.
13730 We've been storing mips16 text labels as odd. Here we convert them
13731 back to even for the convenience of the debugger. */
13734 mips_frob_file_after_relocs (void)
13737 unsigned int count
, i
;
13739 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
13742 syms
= bfd_get_outsymbols (stdoutput
);
13743 count
= bfd_get_symcount (stdoutput
);
13744 for (i
= 0; i
< count
; i
++, syms
++)
13746 if (elf_symbol (*syms
)->internal_elf_sym
.st_other
== STO_MIPS16
13747 && ((*syms
)->value
& 1) != 0)
13749 (*syms
)->value
&= ~1;
13750 /* If the symbol has an odd size, it was probably computed
13751 incorrectly, so adjust that as well. */
13752 if ((elf_symbol (*syms
)->internal_elf_sym
.st_size
& 1) != 0)
13753 ++elf_symbol (*syms
)->internal_elf_sym
.st_size
;
13760 /* This function is called whenever a label is defined. It is used
13761 when handling branch delays; if a branch has a label, we assume we
13762 can not move it. */
13765 mips_define_label (symbolS
*sym
)
13767 struct insn_label_list
*l
;
13769 if (free_insn_labels
== NULL
)
13770 l
= (struct insn_label_list
*) xmalloc (sizeof *l
);
13773 l
= free_insn_labels
;
13774 free_insn_labels
= l
->next
;
13778 l
->next
= insn_labels
;
13782 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13784 /* Some special processing for a MIPS ELF file. */
13787 mips_elf_final_processing (void)
13789 /* Write out the register information. */
13790 if (mips_abi
!= N64_ABI
)
13794 s
.ri_gprmask
= mips_gprmask
;
13795 s
.ri_cprmask
[0] = mips_cprmask
[0];
13796 s
.ri_cprmask
[1] = mips_cprmask
[1];
13797 s
.ri_cprmask
[2] = mips_cprmask
[2];
13798 s
.ri_cprmask
[3] = mips_cprmask
[3];
13799 /* The gp_value field is set by the MIPS ELF backend. */
13801 bfd_mips_elf32_swap_reginfo_out (stdoutput
, &s
,
13802 ((Elf32_External_RegInfo
*)
13803 mips_regmask_frag
));
13807 Elf64_Internal_RegInfo s
;
13809 s
.ri_gprmask
= mips_gprmask
;
13811 s
.ri_cprmask
[0] = mips_cprmask
[0];
13812 s
.ri_cprmask
[1] = mips_cprmask
[1];
13813 s
.ri_cprmask
[2] = mips_cprmask
[2];
13814 s
.ri_cprmask
[3] = mips_cprmask
[3];
13815 /* The gp_value field is set by the MIPS ELF backend. */
13817 bfd_mips_elf64_swap_reginfo_out (stdoutput
, &s
,
13818 ((Elf64_External_RegInfo
*)
13819 mips_regmask_frag
));
13822 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13823 sort of BFD interface for this. */
13824 if (mips_any_noreorder
)
13825 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_NOREORDER
;
13826 if (mips_pic
!= NO_PIC
)
13828 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_PIC
;
13829 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_CPIC
;
13832 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_CPIC
;
13834 /* Set MIPS ELF flags for ASEs. */
13835 if (file_ase_mips16
)
13836 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_M16
;
13837 #if 0 /* XXX FIXME */
13838 if (file_ase_mips3d
)
13839 elf_elfheader (stdoutput
)->e_flags
|= ???;
13842 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_MDMX
;
13844 /* Set the MIPS ELF ABI flags. */
13845 if (mips_abi
== O32_ABI
&& USE_E_MIPS_ABI_O32
)
13846 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O32
;
13847 else if (mips_abi
== O64_ABI
)
13848 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O64
;
13849 else if (mips_abi
== EABI_ABI
)
13851 if (!file_mips_gp32
)
13852 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI64
;
13854 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI32
;
13856 else if (mips_abi
== N32_ABI
)
13857 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ABI2
;
13859 /* Nothing to do for N64_ABI. */
13861 if (mips_32bitmode
)
13862 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_32BITMODE
;
13865 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
13867 typedef struct proc
{
13869 unsigned long reg_mask
;
13870 unsigned long reg_offset
;
13871 unsigned long fpreg_mask
;
13872 unsigned long fpreg_offset
;
13873 unsigned long frame_offset
;
13874 unsigned long frame_reg
;
13875 unsigned long pc_reg
;
13878 static procS cur_proc
;
13879 static procS
*cur_proc_ptr
;
13880 static int numprocs
;
13882 /* Fill in an rs_align_code fragment. */
13885 mips_handle_align (fragS
*fragp
)
13887 if (fragp
->fr_type
!= rs_align_code
)
13890 if (mips_opts
.mips16
)
13892 static const unsigned char be_nop
[] = { 0x65, 0x00 };
13893 static const unsigned char le_nop
[] = { 0x00, 0x65 };
13898 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
13899 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
13907 memcpy (p
, (target_big_endian
? be_nop
: le_nop
), 2);
13911 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
13915 md_obj_begin (void)
13922 /* check for premature end, nesting errors, etc */
13924 as_warn (_("missing .end at end of assembly"));
13933 if (*input_line_pointer
== '-')
13935 ++input_line_pointer
;
13938 if (!ISDIGIT (*input_line_pointer
))
13939 as_bad (_("expected simple number"));
13940 if (input_line_pointer
[0] == '0')
13942 if (input_line_pointer
[1] == 'x')
13944 input_line_pointer
+= 2;
13945 while (ISXDIGIT (*input_line_pointer
))
13948 val
|= hex_value (*input_line_pointer
++);
13950 return negative
? -val
: val
;
13954 ++input_line_pointer
;
13955 while (ISDIGIT (*input_line_pointer
))
13958 val
|= *input_line_pointer
++ - '0';
13960 return negative
? -val
: val
;
13963 if (!ISDIGIT (*input_line_pointer
))
13965 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13966 *input_line_pointer
, *input_line_pointer
);
13967 as_warn (_("invalid number"));
13970 while (ISDIGIT (*input_line_pointer
))
13973 val
+= *input_line_pointer
++ - '0';
13975 return negative
? -val
: val
;
13978 /* The .file directive; just like the usual .file directive, but there
13979 is an initial number which is the ECOFF file index. In the non-ECOFF
13980 case .file implies DWARF-2. */
13983 s_mips_file (int x ATTRIBUTE_UNUSED
)
13985 static int first_file_directive
= 0;
13987 if (ECOFF_DEBUGGING
)
13996 filename
= dwarf2_directive_file (0);
13998 /* Versions of GCC up to 3.1 start files with a ".file"
13999 directive even for stabs output. Make sure that this
14000 ".file" is handled. Note that you need a version of GCC
14001 after 3.1 in order to support DWARF-2 on MIPS. */
14002 if (filename
!= NULL
&& ! first_file_directive
)
14004 (void) new_logical_line (filename
, -1);
14005 s_app_file_string (filename
);
14007 first_file_directive
= 1;
14011 /* The .loc directive, implying DWARF-2. */
14014 s_mips_loc (int x ATTRIBUTE_UNUSED
)
14016 if (!ECOFF_DEBUGGING
)
14017 dwarf2_directive_loc (0);
14020 /* The .end directive. */
14023 s_mips_end (int x ATTRIBUTE_UNUSED
)
14027 /* Following functions need their own .frame and .cprestore directives. */
14028 mips_frame_reg_valid
= 0;
14029 mips_cprestore_valid
= 0;
14031 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
14034 demand_empty_rest_of_line ();
14039 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) == 0)
14040 as_warn (_(".end not in text section"));
14044 as_warn (_(".end directive without a preceding .ent directive."));
14045 demand_empty_rest_of_line ();
14051 assert (S_GET_NAME (p
));
14052 if (strcmp (S_GET_NAME (p
), S_GET_NAME (cur_proc_ptr
->isym
)))
14053 as_warn (_(".end symbol does not match .ent symbol."));
14055 if (debug_type
== DEBUG_STABS
)
14056 stabs_generate_asm_endfunc (S_GET_NAME (p
),
14060 as_warn (_(".end directive missing or unknown symbol"));
14063 /* Generate a .pdr section. */
14064 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
14067 segT saved_seg
= now_seg
;
14068 subsegT saved_subseg
= now_subseg
;
14073 dot
= frag_now_fix ();
14075 #ifdef md_flush_pending_output
14076 md_flush_pending_output ();
14080 subseg_set (pdr_seg
, 0);
14082 /* Write the symbol. */
14083 exp
.X_op
= O_symbol
;
14084 exp
.X_add_symbol
= p
;
14085 exp
.X_add_number
= 0;
14086 emit_expr (&exp
, 4);
14088 fragp
= frag_more (7 * 4);
14090 md_number_to_chars (fragp
, cur_proc_ptr
->reg_mask
, 4);
14091 md_number_to_chars (fragp
+ 4, cur_proc_ptr
->reg_offset
, 4);
14092 md_number_to_chars (fragp
+ 8, cur_proc_ptr
->fpreg_mask
, 4);
14093 md_number_to_chars (fragp
+ 12, cur_proc_ptr
->fpreg_offset
, 4);
14094 md_number_to_chars (fragp
+ 16, cur_proc_ptr
->frame_offset
, 4);
14095 md_number_to_chars (fragp
+ 20, cur_proc_ptr
->frame_reg
, 4);
14096 md_number_to_chars (fragp
+ 24, cur_proc_ptr
->pc_reg
, 4);
14098 subseg_set (saved_seg
, saved_subseg
);
14100 #endif /* OBJ_ELF */
14102 cur_proc_ptr
= NULL
;
14105 /* The .aent and .ent directives. */
14108 s_mips_ent (int aent
)
14112 symbolP
= get_symbol ();
14113 if (*input_line_pointer
== ',')
14114 ++input_line_pointer
;
14115 SKIP_WHITESPACE ();
14116 if (ISDIGIT (*input_line_pointer
)
14117 || *input_line_pointer
== '-')
14120 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) == 0)
14121 as_warn (_(".ent or .aent not in text section."));
14123 if (!aent
&& cur_proc_ptr
)
14124 as_warn (_("missing .end"));
14128 /* This function needs its own .frame and .cprestore directives. */
14129 mips_frame_reg_valid
= 0;
14130 mips_cprestore_valid
= 0;
14132 cur_proc_ptr
= &cur_proc
;
14133 memset (cur_proc_ptr
, '\0', sizeof (procS
));
14135 cur_proc_ptr
->isym
= symbolP
;
14137 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
14141 if (debug_type
== DEBUG_STABS
)
14142 stabs_generate_asm_func (S_GET_NAME (symbolP
),
14143 S_GET_NAME (symbolP
));
14146 demand_empty_rest_of_line ();
14149 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
14150 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
14151 s_mips_frame is used so that we can set the PDR information correctly.
14152 We can't use the ecoff routines because they make reference to the ecoff
14153 symbol table (in the mdebug section). */
14156 s_mips_frame (int ignore ATTRIBUTE_UNUSED
)
14159 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
)
14163 if (cur_proc_ptr
== (procS
*) NULL
)
14165 as_warn (_(".frame outside of .ent"));
14166 demand_empty_rest_of_line ();
14170 cur_proc_ptr
->frame_reg
= tc_get_register (1);
14172 SKIP_WHITESPACE ();
14173 if (*input_line_pointer
++ != ','
14174 || get_absolute_expression_and_terminator (&val
) != ',')
14176 as_warn (_("Bad .frame directive"));
14177 --input_line_pointer
;
14178 demand_empty_rest_of_line ();
14182 cur_proc_ptr
->frame_offset
= val
;
14183 cur_proc_ptr
->pc_reg
= tc_get_register (0);
14185 demand_empty_rest_of_line ();
14188 #endif /* OBJ_ELF */
14192 /* The .fmask and .mask directives. If the mdebug section is present
14193 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14194 embedded targets, s_mips_mask is used so that we can set the PDR
14195 information correctly. We can't use the ecoff routines because they
14196 make reference to the ecoff symbol table (in the mdebug section). */
14199 s_mips_mask (int reg_type
)
14202 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
&& ! ECOFF_DEBUGGING
)
14206 if (cur_proc_ptr
== (procS
*) NULL
)
14208 as_warn (_(".mask/.fmask outside of .ent"));
14209 demand_empty_rest_of_line ();
14213 if (get_absolute_expression_and_terminator (&mask
) != ',')
14215 as_warn (_("Bad .mask/.fmask directive"));
14216 --input_line_pointer
;
14217 demand_empty_rest_of_line ();
14221 off
= get_absolute_expression ();
14223 if (reg_type
== 'F')
14225 cur_proc_ptr
->fpreg_mask
= mask
;
14226 cur_proc_ptr
->fpreg_offset
= off
;
14230 cur_proc_ptr
->reg_mask
= mask
;
14231 cur_proc_ptr
->reg_offset
= off
;
14234 demand_empty_rest_of_line ();
14237 #endif /* OBJ_ELF */
14238 s_ignore (reg_type
);
14241 /* The .loc directive. */
14251 assert (now_seg
== text_section
);
14253 lineno
= get_number ();
14254 addroff
= frag_now_fix ();
14256 symbolP
= symbol_new ("", N_SLINE
, addroff
, frag_now
);
14257 S_SET_TYPE (symbolP
, N_SLINE
);
14258 S_SET_OTHER (symbolP
, 0);
14259 S_SET_DESC (symbolP
, lineno
);
14260 symbolP
->sy_segment
= now_seg
;
14264 /* A table describing all the processors gas knows about. Names are
14265 matched in the order listed.
14267 To ease comparison, please keep this table in the same order as
14268 gcc's mips_cpu_info_table[]. */
14269 static const struct mips_cpu_info mips_cpu_info_table
[] =
14271 /* Entries for generic ISAs */
14272 { "mips1", 1, ISA_MIPS1
, CPU_R3000
},
14273 { "mips2", 1, ISA_MIPS2
, CPU_R6000
},
14274 { "mips3", 1, ISA_MIPS3
, CPU_R4000
},
14275 { "mips4", 1, ISA_MIPS4
, CPU_R8000
},
14276 { "mips5", 1, ISA_MIPS5
, CPU_MIPS5
},
14277 { "mips32", 1, ISA_MIPS32
, CPU_MIPS32
},
14278 { "mips32r2", 1, ISA_MIPS32R2
, CPU_MIPS32R2
},
14279 { "mips64", 1, ISA_MIPS64
, CPU_MIPS64
},
14282 { "r3000", 0, ISA_MIPS1
, CPU_R3000
},
14283 { "r2000", 0, ISA_MIPS1
, CPU_R3000
},
14284 { "r3900", 0, ISA_MIPS1
, CPU_R3900
},
14287 { "r6000", 0, ISA_MIPS2
, CPU_R6000
},
14290 { "r4000", 0, ISA_MIPS3
, CPU_R4000
},
14291 { "r4010", 0, ISA_MIPS2
, CPU_R4010
},
14292 { "vr4100", 0, ISA_MIPS3
, CPU_VR4100
},
14293 { "vr4111", 0, ISA_MIPS3
, CPU_R4111
},
14294 { "vr4120", 0, ISA_MIPS3
, CPU_VR4120
},
14295 { "vr4130", 0, ISA_MIPS3
, CPU_VR4120
},
14296 { "vr4181", 0, ISA_MIPS3
, CPU_R4111
},
14297 { "vr4300", 0, ISA_MIPS3
, CPU_R4300
},
14298 { "r4400", 0, ISA_MIPS3
, CPU_R4400
},
14299 { "r4600", 0, ISA_MIPS3
, CPU_R4600
},
14300 { "orion", 0, ISA_MIPS3
, CPU_R4600
},
14301 { "r4650", 0, ISA_MIPS3
, CPU_R4650
},
14304 { "r8000", 0, ISA_MIPS4
, CPU_R8000
},
14305 { "r10000", 0, ISA_MIPS4
, CPU_R10000
},
14306 { "r12000", 0, ISA_MIPS4
, CPU_R12000
},
14307 { "vr5000", 0, ISA_MIPS4
, CPU_R5000
},
14308 { "vr5400", 0, ISA_MIPS4
, CPU_VR5400
},
14309 { "vr5500", 0, ISA_MIPS4
, CPU_VR5500
},
14310 { "rm5200", 0, ISA_MIPS4
, CPU_R5000
},
14311 { "rm5230", 0, ISA_MIPS4
, CPU_R5000
},
14312 { "rm5231", 0, ISA_MIPS4
, CPU_R5000
},
14313 { "rm5261", 0, ISA_MIPS4
, CPU_R5000
},
14314 { "rm5721", 0, ISA_MIPS4
, CPU_R5000
},
14315 { "rm7000", 0, ISA_MIPS4
, CPU_RM7000
},
14316 { "rm9000", 0, ISA_MIPS4
, CPU_RM7000
},
14319 { "4kc", 0, ISA_MIPS32
, CPU_MIPS32
},
14320 { "4km", 0, ISA_MIPS32
, CPU_MIPS32
},
14321 { "4kp", 0, ISA_MIPS32
, CPU_MIPS32
},
14324 { "5kc", 0, ISA_MIPS64
, CPU_MIPS64
},
14325 { "20kc", 0, ISA_MIPS64
, CPU_MIPS64
},
14327 /* Broadcom SB-1 CPU core */
14328 { "sb1", 0, ISA_MIPS64
, CPU_SB1
},
14335 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14336 with a final "000" replaced by "k". Ignore case.
14338 Note: this function is shared between GCC and GAS. */
14341 mips_strict_matching_cpu_name_p (const char *canonical
, const char *given
)
14343 while (*given
!= 0 && TOLOWER (*given
) == TOLOWER (*canonical
))
14344 given
++, canonical
++;
14346 return ((*given
== 0 && *canonical
== 0)
14347 || (strcmp (canonical
, "000") == 0 && strcasecmp (given
, "k") == 0));
14351 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14352 CPU name. We've traditionally allowed a lot of variation here.
14354 Note: this function is shared between GCC and GAS. */
14357 mips_matching_cpu_name_p (const char *canonical
, const char *given
)
14359 /* First see if the name matches exactly, or with a final "000"
14360 turned into "k". */
14361 if (mips_strict_matching_cpu_name_p (canonical
, given
))
14364 /* If not, try comparing based on numerical designation alone.
14365 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14366 if (TOLOWER (*given
) == 'r')
14368 if (!ISDIGIT (*given
))
14371 /* Skip over some well-known prefixes in the canonical name,
14372 hoping to find a number there too. */
14373 if (TOLOWER (canonical
[0]) == 'v' && TOLOWER (canonical
[1]) == 'r')
14375 else if (TOLOWER (canonical
[0]) == 'r' && TOLOWER (canonical
[1]) == 'm')
14377 else if (TOLOWER (canonical
[0]) == 'r')
14380 return mips_strict_matching_cpu_name_p (canonical
, given
);
14384 /* Parse an option that takes the name of a processor as its argument.
14385 OPTION is the name of the option and CPU_STRING is the argument.
14386 Return the corresponding processor enumeration if the CPU_STRING is
14387 recognized, otherwise report an error and return null.
14389 A similar function exists in GCC. */
14391 static const struct mips_cpu_info
*
14392 mips_parse_cpu (const char *option
, const char *cpu_string
)
14394 const struct mips_cpu_info
*p
;
14396 /* 'from-abi' selects the most compatible architecture for the given
14397 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14398 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14399 version. Look first at the -mgp options, if given, otherwise base
14400 the choice on MIPS_DEFAULT_64BIT.
14402 Treat NO_ABI like the EABIs. One reason to do this is that the
14403 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14404 architecture. This code picks MIPS I for 'mips' and MIPS III for
14405 'mips64', just as we did in the days before 'from-abi'. */
14406 if (strcasecmp (cpu_string
, "from-abi") == 0)
14408 if (ABI_NEEDS_32BIT_REGS (mips_abi
))
14409 return mips_cpu_info_from_isa (ISA_MIPS1
);
14411 if (ABI_NEEDS_64BIT_REGS (mips_abi
))
14412 return mips_cpu_info_from_isa (ISA_MIPS3
);
14414 if (file_mips_gp32
>= 0)
14415 return mips_cpu_info_from_isa (file_mips_gp32
? ISA_MIPS1
: ISA_MIPS3
);
14417 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14422 /* 'default' has traditionally been a no-op. Probably not very useful. */
14423 if (strcasecmp (cpu_string
, "default") == 0)
14426 for (p
= mips_cpu_info_table
; p
->name
!= 0; p
++)
14427 if (mips_matching_cpu_name_p (p
->name
, cpu_string
))
14430 as_bad ("Bad value (%s) for %s", cpu_string
, option
);
14434 /* Return the canonical processor information for ISA (a member of the
14435 ISA_MIPS* enumeration). */
14437 static const struct mips_cpu_info
*
14438 mips_cpu_info_from_isa (int isa
)
14442 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
14443 if (mips_cpu_info_table
[i
].is_isa
14444 && isa
== mips_cpu_info_table
[i
].isa
)
14445 return (&mips_cpu_info_table
[i
]);
14450 static const struct mips_cpu_info
*
14451 mips_cpu_info_from_arch (int arch
)
14455 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
14456 if (arch
== mips_cpu_info_table
[i
].cpu
)
14457 return (&mips_cpu_info_table
[i
]);
14463 show (FILE *stream
, const char *string
, int *col_p
, int *first_p
)
14467 fprintf (stream
, "%24s", "");
14472 fprintf (stream
, ", ");
14476 if (*col_p
+ strlen (string
) > 72)
14478 fprintf (stream
, "\n%24s", "");
14482 fprintf (stream
, "%s", string
);
14483 *col_p
+= strlen (string
);
14489 md_show_usage (FILE *stream
)
14494 fprintf (stream
, _("\
14496 -membedded-pic generate embedded position independent code\n\
14497 -EB generate big endian output\n\
14498 -EL generate little endian output\n\
14499 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14500 -G NUM allow referencing objects up to NUM bytes\n\
14501 implicitly with the gp register [default 8]\n"));
14502 fprintf (stream
, _("\
14503 -mips1 generate MIPS ISA I instructions\n\
14504 -mips2 generate MIPS ISA II instructions\n\
14505 -mips3 generate MIPS ISA III instructions\n\
14506 -mips4 generate MIPS ISA IV instructions\n\
14507 -mips5 generate MIPS ISA V instructions\n\
14508 -mips32 generate MIPS32 ISA instructions\n\
14509 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
14510 -mips64 generate MIPS64 ISA instructions\n\
14511 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14515 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
14516 show (stream
, mips_cpu_info_table
[i
].name
, &column
, &first
);
14517 show (stream
, "from-abi", &column
, &first
);
14518 fputc ('\n', stream
);
14520 fprintf (stream
, _("\
14521 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14522 -no-mCPU don't generate code specific to CPU.\n\
14523 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14527 show (stream
, "3900", &column
, &first
);
14528 show (stream
, "4010", &column
, &first
);
14529 show (stream
, "4100", &column
, &first
);
14530 show (stream
, "4650", &column
, &first
);
14531 fputc ('\n', stream
);
14533 fprintf (stream
, _("\
14534 -mips16 generate mips16 instructions\n\
14535 -no-mips16 do not generate mips16 instructions\n"));
14536 fprintf (stream
, _("\
14537 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14538 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14539 -O0 remove unneeded NOPs, do not swap branches\n\
14540 -O remove unneeded NOPs and swap branches\n\
14541 -n warn about NOPs generated from macros\n\
14542 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14543 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14544 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14546 fprintf (stream
, _("\
14547 -KPIC, -call_shared generate SVR4 position independent code\n\
14548 -non_shared do not generate position independent code\n\
14549 -xgot assume a 32 bit GOT\n\
14550 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
14551 -mabi=ABI create ABI conformant object file for:\n"));
14555 show (stream
, "32", &column
, &first
);
14556 show (stream
, "o64", &column
, &first
);
14557 show (stream
, "n32", &column
, &first
);
14558 show (stream
, "64", &column
, &first
);
14559 show (stream
, "eabi", &column
, &first
);
14561 fputc ('\n', stream
);
14563 fprintf (stream
, _("\
14564 -32 create o32 ABI object file (default)\n\
14565 -n32 create n32 ABI object file\n\
14566 -64 create 64 ABI object file\n"));
14571 mips_dwarf2_format (void)
14573 if (mips_abi
== N64_ABI
)
14576 return dwarf2_format_64bit_irix
;
14578 return dwarf2_format_64bit
;
14582 return dwarf2_format_32bit
;