1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by the OSF and Ralph Campbell.
5 Written by Keith Knowles and Ralph Campbell, working independently.
6 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
9 This file is part of GAS.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include "safe-ctype.h"
38 #include "opcode/mips.h"
42 #define DBG(x) printf x
48 /* Clean up namespace so we can include obj-elf.h too. */
49 static int mips_output_flavor PARAMS ((void));
50 static int mips_output_flavor () { return OUTPUT_FLAVOR; }
51 #undef OBJ_PROCESS_STAB
58 #undef obj_frob_file_after_relocs
59 #undef obj_frob_symbol
61 #undef obj_sec_sym_ok_for_reloc
62 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
65 /* Fix any of them that we actually care about. */
67 #define OUTPUT_FLAVOR mips_output_flavor()
74 #ifndef ECOFF_DEBUGGING
75 #define NO_ECOFF_DEBUGGING
76 #define ECOFF_DEBUGGING 0
81 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
82 static char *mips_regmask_frag;
87 #define PIC_CALL_REG 25
95 #define ILLEGAL_REG (32)
97 /* Allow override of standard little-endian ECOFF format. */
99 #ifndef ECOFF_LITTLE_FORMAT
100 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
103 extern int target_big_endian;
105 /* The name of the readonly data section. */
106 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
108 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
110 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
112 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
116 /* The ABI to use. */
127 /* MIPS ABI we are using for this output file. */
128 static enum mips_abi_level file_mips_abi = NO_ABI;
130 /* This is the set of options which may be modified by the .set
131 pseudo-op. We use a struct so that .set push and .set pop are more
134 struct mips_set_options
136 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
137 if it has not been initialized. Changed by `.set mipsN', and the
138 -mipsN command line option, and the default CPU. */
140 /* Enabled Application Specific Extensions (ASEs). These are set to -1
141 if they have not been initialized. Changed by `.set <asename>', by
142 command line options, and based on the default architecture. */
144 /* Whether we are assembling for the mips16 processor. 0 if we are
145 not, 1 if we are, and -1 if the value has not been initialized.
146 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
147 -nomips16 command line options, and the default CPU. */
149 /* Non-zero if we should not reorder instructions. Changed by `.set
150 reorder' and `.set noreorder'. */
152 /* Non-zero if we should not permit the $at ($1) register to be used
153 in instructions. Changed by `.set at' and `.set noat'. */
155 /* Non-zero if we should warn when a macro instruction expands into
156 more than one machine instruction. Changed by `.set nomacro' and
158 int warn_about_macros;
159 /* Non-zero if we should not move instructions. Changed by `.set
160 move', `.set volatile', `.set nomove', and `.set novolatile'. */
162 /* Non-zero if we should not optimize branches by moving the target
163 of the branch into the delay slot. Actually, we don't perform
164 this optimization anyhow. Changed by `.set bopt' and `.set
167 /* Non-zero if we should not autoextend mips16 instructions.
168 Changed by `.set autoextend' and `.set noautoextend'. */
170 /* Restrict general purpose registers and floating point registers
171 to 32 bit. This is initially determined when -mgp32 or -mfp32
172 is passed but can changed if the assembler code uses .set mipsN. */
175 /* The ABI currently in use. This is changed by .set mipsN to loosen
176 restrictions and doesn't affect the whole file. */
177 enum mips_abi_level abi;
180 /* True if -mgp32 was passed. */
181 static int file_mips_gp32 = -1;
183 /* True if -mfp32 was passed. */
184 static int file_mips_fp32 = -1;
186 /* This is the struct we use to hold the current set of options. Note
187 that we must set the isa field to ISA_UNKNOWN and the mips16 field to
188 -1 to indicate that they have not been initialized. */
190 static struct mips_set_options mips_opts =
192 ISA_UNKNOWN, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, NO_ABI
195 /* These variables are filled in with the masks of registers used.
196 The object format code reads them and puts them in the appropriate
198 unsigned long mips_gprmask;
199 unsigned long mips_cprmask[4];
201 /* MIPS ISA we are using for this output file. */
202 static int file_mips_isa = ISA_UNKNOWN;
204 /* True if -mips3d was passed or implied by arguments passed on the
205 command line (e.g., by -march). */
206 static int file_ase_mips3d;
208 /* The argument of the -mcpu= flag. Historical for code generation. */
209 static int mips_cpu = CPU_UNKNOWN;
211 /* The argument of the -march= flag. The architecture we are assembling. */
212 static int mips_arch = CPU_UNKNOWN;
214 /* The argument of the -mtune= flag. The architecture for which we
216 static int mips_tune = CPU_UNKNOWN;
218 /* Whether we should mark the file EABI64 or EABI32. */
219 static int mips_eabi64 = 0;
221 /* If they asked for mips1 or mips2 and a cpu that is
222 mips3 or greater, then mark the object file 32BITMODE. */
223 static int mips_32bitmode = 0;
225 /* Some ISA's have delay slots for instructions which read or write
226 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
227 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
228 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
229 delay slot in this ISA. The uses of this macro assume that any
230 ISA that has delay slots for one of these, has them for all. They
231 also assume that ISAs which don't have delays for these insns, don't
232 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
233 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
235 || (ISA) == ISA_MIPS2 \
236 || (ISA) == ISA_MIPS3 \
239 /* Return true if ISA supports 64 bit gp register instructions. */
240 #define ISA_HAS_64BIT_REGS(ISA) ( \
242 || (ISA) == ISA_MIPS4 \
243 || (ISA) == ISA_MIPS5 \
244 || (ISA) == ISA_MIPS64 \
247 #define HAVE_32BIT_GPRS \
249 || mips_opts.abi == O32_ABI \
250 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
252 #define HAVE_32BIT_FPRS \
254 || mips_opts.abi == O32_ABI \
255 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
257 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
258 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
260 #define HAVE_NEWABI (mips_opts.abi == N32_ABI || mips_opts.abi == N64_ABI)
262 #define HAVE_64BIT_OBJECTS (mips_opts.abi == N64_ABI)
264 /* We can only have 64bit addresses if the object file format
266 #define HAVE_32BIT_ADDRESSES \
268 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
269 || ! HAVE_64BIT_OBJECTS) \
270 && mips_pic != EMBEDDED_PIC))
272 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
274 /* Return true if the given CPU supports the MIPS3D ASE. */
275 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
278 /* Whether the processor uses hardware interlocks to protect
279 reads from the HI and LO registers, and thus does not
280 require nops to be inserted. */
282 #define hilo_interlocks (mips_arch == CPU_R4010 \
283 || mips_arch == CPU_SB1 \
286 /* Whether the processor uses hardware interlocks to protect reads
287 from the GPRs, and thus does not require nops to be inserted. */
288 #define gpr_interlocks \
289 (mips_opts.isa != ISA_MIPS1 \
290 || mips_arch == CPU_R3900)
292 /* As with other "interlocks" this is used by hardware that has FP
293 (co-processor) interlocks. */
294 /* Itbl support may require additional care here. */
295 #define cop_interlocks (mips_arch == CPU_R4300 \
296 || mips_arch == CPU_SB1 \
299 /* Is this a mfhi or mflo instruction? */
300 #define MF_HILO_INSN(PINFO) \
301 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
303 /* MIPS PIC level. */
307 /* Do not generate PIC code. */
310 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
311 not sure what it is supposed to do. */
314 /* Generate PIC code as in the SVR4 MIPS ABI. */
317 /* Generate PIC code without using a global offset table: the data
318 segment has a maximum size of 64K, all data references are off
319 the $gp register, and all text references are PC relative. This
320 is used on some embedded systems. */
324 static enum mips_pic_level mips_pic;
326 /* Warn about all NOPS that the assembler generates. */
327 static int warn_nops = 0;
329 /* 1 if we should generate 32 bit offsets from the GP register in
330 SVR4_PIC mode. Currently has no meaning in other modes. */
331 static int mips_big_got;
333 /* 1 if trap instructions should used for overflow rather than break
335 static int mips_trap;
337 /* 1 if double width floating point constants should not be constructed
338 by assembling two single width halves into two single width floating
339 point registers which just happen to alias the double width destination
340 register. On some architectures this aliasing can be disabled by a bit
341 in the status register, and the setting of this bit cannot be determined
342 automatically at assemble time. */
343 static int mips_disable_float_construction;
345 /* Non-zero if any .set noreorder directives were used. */
347 static int mips_any_noreorder;
349 /* Non-zero if nops should be inserted when the register referenced in
350 an mfhi/mflo instruction is read in the next two instructions. */
351 static int mips_7000_hilo_fix;
353 /* The size of the small data section. */
354 static unsigned int g_switch_value = 8;
355 /* Whether the -G option was used. */
356 static int g_switch_seen = 0;
361 /* If we can determine in advance that GP optimization won't be
362 possible, we can skip the relaxation stuff that tries to produce
363 GP-relative references. This makes delay slot optimization work
366 This function can only provide a guess, but it seems to work for
367 gcc output. It needs to guess right for gcc, otherwise gcc
368 will put what it thinks is a GP-relative instruction in a branch
371 I don't know if a fix is needed for the SVR4_PIC mode. I've only
372 fixed it for the non-PIC mode. KR 95/04/07 */
373 static int nopic_need_relax PARAMS ((symbolS *, int));
375 /* handle of the OPCODE hash table */
376 static struct hash_control *op_hash = NULL;
378 /* The opcode hash table we use for the mips16. */
379 static struct hash_control *mips16_op_hash = NULL;
381 /* This array holds the chars that always start a comment. If the
382 pre-processor is disabled, these aren't very useful */
383 const char comment_chars[] = "#";
385 /* This array holds the chars that only start a comment at the beginning of
386 a line. If the line seems to have the form '# 123 filename'
387 .line and .file directives will appear in the pre-processed output */
388 /* Note that input_file.c hand checks for '#' at the beginning of the
389 first line of the input file. This is because the compiler outputs
390 #NO_APP at the beginning of its output. */
391 /* Also note that C style comments are always supported. */
392 const char line_comment_chars[] = "#";
394 /* This array holds machine specific line separator characters. */
395 const char line_separator_chars[] = ";";
397 /* Chars that can be used to separate mant from exp in floating point nums */
398 const char EXP_CHARS[] = "eE";
400 /* Chars that mean this number is a floating point constant */
403 const char FLT_CHARS[] = "rRsSfFdDxXpP";
405 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
406 changed in read.c . Ideally it shouldn't have to know about it at all,
407 but nothing is ideal around here.
410 static char *insn_error;
412 static int auto_align = 1;
414 /* When outputting SVR4 PIC code, the assembler needs to know the
415 offset in the stack frame from which to restore the $gp register.
416 This is set by the .cprestore pseudo-op, and saved in this
418 static offsetT mips_cprestore_offset = -1;
420 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
421 more optimizations, it can use a register value instead of a memory-saved
422 offset and even an other register than $gp as global pointer. */
423 static offsetT mips_cpreturn_offset = -1;
424 static int mips_cpreturn_register = -1;
425 static int mips_gp_register = GP;
427 /* Whether mips_cprestore_offset has been set in the current function
428 (or whether it has already been warned about, if not). */
429 static int mips_cprestore_valid = 0;
431 /* This is the register which holds the stack frame, as set by the
432 .frame pseudo-op. This is needed to implement .cprestore. */
433 static int mips_frame_reg = SP;
435 /* Whether mips_frame_reg has been set in the current function
436 (or whether it has already been warned about, if not). */
437 static int mips_frame_reg_valid = 0;
439 /* To output NOP instructions correctly, we need to keep information
440 about the previous two instructions. */
442 /* Whether we are optimizing. The default value of 2 means to remove
443 unneeded NOPs and swap branch instructions when possible. A value
444 of 1 means to not swap branches. A value of 0 means to always
446 static int mips_optimize = 2;
448 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
449 equivalent to seeing no -g option at all. */
450 static int mips_debug = 0;
452 /* The previous instruction. */
453 static struct mips_cl_insn prev_insn;
455 /* The instruction before prev_insn. */
456 static struct mips_cl_insn prev_prev_insn;
458 /* If we don't want information for prev_insn or prev_prev_insn, we
459 point the insn_mo field at this dummy integer. */
460 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
462 /* Non-zero if prev_insn is valid. */
463 static int prev_insn_valid;
465 /* The frag for the previous instruction. */
466 static struct frag *prev_insn_frag;
468 /* The offset into prev_insn_frag for the previous instruction. */
469 static long prev_insn_where;
471 /* The reloc type for the previous instruction, if any. */
472 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
474 /* The reloc for the previous instruction, if any. */
475 static fixS *prev_insn_fixp[3];
477 /* Non-zero if the previous instruction was in a delay slot. */
478 static int prev_insn_is_delay_slot;
480 /* Non-zero if the previous instruction was in a .set noreorder. */
481 static int prev_insn_unreordered;
483 /* Non-zero if the previous instruction uses an extend opcode (if
485 static int prev_insn_extended;
487 /* Non-zero if the previous previous instruction was in a .set
489 static int prev_prev_insn_unreordered;
491 /* If this is set, it points to a frag holding nop instructions which
492 were inserted before the start of a noreorder section. If those
493 nops turn out to be unnecessary, the size of the frag can be
495 static fragS *prev_nop_frag;
497 /* The number of nop instructions we created in prev_nop_frag. */
498 static int prev_nop_frag_holds;
500 /* The number of nop instructions that we know we need in
502 static int prev_nop_frag_required;
504 /* The number of instructions we've seen since prev_nop_frag. */
505 static int prev_nop_frag_since;
507 /* For ECOFF and ELF, relocations against symbols are done in two
508 parts, with a HI relocation and a LO relocation. Each relocation
509 has only 16 bits of space to store an addend. This means that in
510 order for the linker to handle carries correctly, it must be able
511 to locate both the HI and the LO relocation. This means that the
512 relocations must appear in order in the relocation table.
514 In order to implement this, we keep track of each unmatched HI
515 relocation. We then sort them so that they immediately precede the
516 corresponding LO relocation. */
521 struct mips_hi_fixup *next;
524 /* The section this fixup is in. */
528 /* The list of unmatched HI relocs. */
530 static struct mips_hi_fixup *mips_hi_fixup_list;
532 /* Map normal MIPS register numbers to mips16 register numbers. */
534 #define X ILLEGAL_REG
535 static const int mips32_to_16_reg_map[] =
537 X, X, 2, 3, 4, 5, 6, 7,
538 X, X, X, X, X, X, X, X,
539 0, 1, X, X, X, X, X, X,
540 X, X, X, X, X, X, X, X
544 /* Map mips16 register numbers to normal MIPS register numbers. */
546 static const unsigned int mips16_to_32_reg_map[] =
548 16, 17, 2, 3, 4, 5, 6, 7
551 /* Since the MIPS does not have multiple forms of PC relative
552 instructions, we do not have to do relaxing as is done on other
553 platforms. However, we do have to handle GP relative addressing
554 correctly, which turns out to be a similar problem.
556 Every macro that refers to a symbol can occur in (at least) two
557 forms, one with GP relative addressing and one without. For
558 example, loading a global variable into a register generally uses
559 a macro instruction like this:
561 If i can be addressed off the GP register (this is true if it is in
562 the .sbss or .sdata section, or if it is known to be smaller than
563 the -G argument) this will generate the following instruction:
565 This instruction will use a GPREL reloc. If i can not be addressed
566 off the GP register, the following instruction sequence will be used:
569 In this case the first instruction will have a HI16 reloc, and the
570 second reloc will have a LO16 reloc. Both relocs will be against
573 The issue here is that we may not know whether i is GP addressable
574 until after we see the instruction that uses it. Therefore, we
575 want to be able to choose the final instruction sequence only at
576 the end of the assembly. This is similar to the way other
577 platforms choose the size of a PC relative instruction only at the
580 When generating position independent code we do not use GP
581 addressing in quite the same way, but the issue still arises as
582 external symbols and local symbols must be handled differently.
584 We handle these issues by actually generating both possible
585 instruction sequences. The longer one is put in a frag_var with
586 type rs_machine_dependent. We encode what to do with the frag in
587 the subtype field. We encode (1) the number of existing bytes to
588 replace, (2) the number of new bytes to use, (3) the offset from
589 the start of the existing bytes to the first reloc we must generate
590 (that is, the offset is applied from the start of the existing
591 bytes after they are replaced by the new bytes, if any), (4) the
592 offset from the start of the existing bytes to the second reloc,
593 (5) whether a third reloc is needed (the third reloc is always four
594 bytes after the second reloc), and (6) whether to warn if this
595 variant is used (this is sometimes needed if .set nomacro or .set
596 noat is in effect). All these numbers are reasonably small.
598 Generating two instruction sequences must be handled carefully to
599 ensure that delay slots are handled correctly. Fortunately, there
600 are a limited number of cases. When the second instruction
601 sequence is generated, append_insn is directed to maintain the
602 existing delay slot information, so it continues to apply to any
603 code after the second instruction sequence. This means that the
604 second instruction sequence must not impose any requirements not
605 required by the first instruction sequence.
607 These variant frags are then handled in functions called by the
608 machine independent code. md_estimate_size_before_relax returns
609 the final size of the frag. md_convert_frag sets up the final form
610 of the frag. tc_gen_reloc adjust the first reloc and adds a second
612 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
616 | (((reloc1) + 64) << 9) \
617 | (((reloc2) + 64) << 2) \
618 | ((reloc3) ? (1 << 1) : 0) \
620 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
621 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
622 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
623 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
624 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
625 #define RELAX_WARN(i) ((i) & 1)
627 /* For mips16 code, we use an entirely different form of relaxation.
628 mips16 supports two versions of most instructions which take
629 immediate values: a small one which takes some small value, and a
630 larger one which takes a 16 bit value. Since branches also follow
631 this pattern, relaxing these values is required.
633 We can assemble both mips16 and normal MIPS code in a single
634 object. Therefore, we need to support this type of relaxation at
635 the same time that we support the relaxation described above. We
636 use the high bit of the subtype field to distinguish these cases.
638 The information we store for this type of relaxation is the
639 argument code found in the opcode file for this relocation, whether
640 the user explicitly requested a small or extended form, and whether
641 the relocation is in a jump or jal delay slot. That tells us the
642 size of the value, and how it should be stored. We also store
643 whether the fragment is considered to be extended or not. We also
644 store whether this is known to be a branch to a different section,
645 whether we have tried to relax this frag yet, and whether we have
646 ever extended a PC relative fragment because of a shift count. */
647 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
650 | ((small) ? 0x100 : 0) \
651 | ((ext) ? 0x200 : 0) \
652 | ((dslot) ? 0x400 : 0) \
653 | ((jal_dslot) ? 0x800 : 0))
654 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
655 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
656 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
657 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
658 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
659 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
660 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
661 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
662 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
663 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
664 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
665 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
667 /* Prototypes for static functions. */
670 #define internalError() \
671 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
673 #define internalError() as_fatal (_("MIPS internal Error"));
676 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
678 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
679 unsigned int reg, enum mips_regclass class));
680 static int reg_needs_delay PARAMS ((unsigned int));
681 static void mips16_mark_labels PARAMS ((void));
682 static void append_insn PARAMS ((char *place,
683 struct mips_cl_insn * ip,
685 bfd_reloc_code_real_type *r,
687 static void mips_no_prev_insn PARAMS ((int));
688 static void mips_emit_delays PARAMS ((boolean));
690 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
691 const char *name, const char *fmt,
694 static void macro_build ();
696 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
697 const char *, const char *,
699 static void macro_build_lui PARAMS ((char *place, int *counter,
700 expressionS * ep, int regnum));
701 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
702 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
704 static void load_register PARAMS ((int *, int, expressionS *, int));
705 static void load_address PARAMS ((int *, int, expressionS *, int, int *));
706 static void move_register PARAMS ((int *, int, int));
707 static void macro PARAMS ((struct mips_cl_insn * ip));
708 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
709 #ifdef LOSING_COMPILER
710 static void macro2 PARAMS ((struct mips_cl_insn * ip));
712 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
713 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
714 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
715 boolean, boolean, unsigned long *,
716 boolean *, unsigned short *));
717 static int my_getPercentOp PARAMS ((char **, unsigned int *, int *));
718 static int my_getSmallParser PARAMS ((char **, unsigned int *, int *));
719 static int my_getSmallExpression PARAMS ((expressionS *, char *));
720 static void my_getExpression PARAMS ((expressionS *, char *));
722 static int support_64bit_objects PARAMS((void));
724 static symbolS *get_symbol PARAMS ((void));
725 static void mips_align PARAMS ((int to, int fill, symbolS *label));
726 static void s_align PARAMS ((int));
727 static void s_change_sec PARAMS ((int));
728 static void s_cons PARAMS ((int));
729 static void s_float_cons PARAMS ((int));
730 static void s_mips_globl PARAMS ((int));
731 static void s_option PARAMS ((int));
732 static void s_mipsset PARAMS ((int));
733 static void s_abicalls PARAMS ((int));
734 static void s_cpload PARAMS ((int));
735 static void s_cpsetup PARAMS ((int));
736 static void s_cplocal PARAMS ((int));
737 static void s_cprestore PARAMS ((int));
738 static void s_cpreturn PARAMS ((int));
739 static void s_gpvalue PARAMS ((int));
740 static void s_gpword PARAMS ((int));
741 static void s_cpadd PARAMS ((int));
742 static void s_insn PARAMS ((int));
743 static void md_obj_begin PARAMS ((void));
744 static void md_obj_end PARAMS ((void));
745 static long get_number PARAMS ((void));
746 static void s_mips_ent PARAMS ((int));
747 static void s_mips_end PARAMS ((int));
748 static void s_mips_frame PARAMS ((int));
749 static void s_mips_mask PARAMS ((int));
750 static void s_mips_stab PARAMS ((int));
751 static void s_mips_weakext PARAMS ((int));
752 static void s_file PARAMS ((int));
753 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
754 static const char *mips_isa_to_str PARAMS ((int));
755 static const char *mips_cpu_to_str PARAMS ((int));
756 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
757 static void show PARAMS ((FILE *, char *, int *, int *));
759 static int mips_need_elf_addend_fixup PARAMS ((fixS *));
762 /* Return values of my_getSmallExpression(). */
769 /* Direct relocation creation by %percent_op(). */
788 /* Table and functions used to map between CPU/ISA names, and
789 ISA levels, and CPU numbers. */
793 const char *name; /* CPU or ISA name. */
794 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
795 int isa; /* ISA level. */
796 int cpu; /* CPU number (default CPU if ISA). */
799 static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *));
800 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
801 static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int));
805 The following pseudo-ops from the Kane and Heinrich MIPS book
806 should be defined here, but are currently unsupported: .alias,
807 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
809 The following pseudo-ops from the Kane and Heinrich MIPS book are
810 specific to the type of debugging information being generated, and
811 should be defined by the object format: .aent, .begin, .bend,
812 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
815 The following pseudo-ops from the Kane and Heinrich MIPS book are
816 not MIPS CPU specific, but are also not specific to the object file
817 format. This file is probably the best place to define them, but
818 they are not currently supported: .asm0, .endr, .lab, .repeat,
821 static const pseudo_typeS mips_pseudo_table[] =
823 /* MIPS specific pseudo-ops. */
824 {"option", s_option, 0},
825 {"set", s_mipsset, 0},
826 {"rdata", s_change_sec, 'r'},
827 {"sdata", s_change_sec, 's'},
828 {"livereg", s_ignore, 0},
829 {"abicalls", s_abicalls, 0},
830 {"cpload", s_cpload, 0},
831 {"cpsetup", s_cpsetup, 0},
832 {"cplocal", s_cplocal, 0},
833 {"cprestore", s_cprestore, 0},
834 {"cpreturn", s_cpreturn, 0},
835 {"gpvalue", s_gpvalue, 0},
836 {"gpword", s_gpword, 0},
837 {"cpadd", s_cpadd, 0},
840 /* Relatively generic pseudo-ops that happen to be used on MIPS
842 {"asciiz", stringer, 1},
843 {"bss", s_change_sec, 'b'},
846 {"dword", s_cons, 3},
847 {"weakext", s_mips_weakext, 0},
849 /* These pseudo-ops are defined in read.c, but must be overridden
850 here for one reason or another. */
851 {"align", s_align, 0},
853 {"data", s_change_sec, 'd'},
854 {"double", s_float_cons, 'd'},
855 {"float", s_float_cons, 'f'},
856 {"globl", s_mips_globl, 0},
857 {"global", s_mips_globl, 0},
858 {"hword", s_cons, 1},
863 {"short", s_cons, 1},
864 {"single", s_float_cons, 'f'},
865 {"stabn", s_mips_stab, 'n'},
866 {"text", s_change_sec, 't'},
869 #ifdef MIPS_STABS_ELF
870 { "extern", ecoff_directive_extern, 0},
876 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
878 /* These pseudo-ops should be defined by the object file format.
879 However, a.out doesn't support them, so we have versions here. */
880 {"aent", s_mips_ent, 1},
881 {"bgnb", s_ignore, 0},
882 {"end", s_mips_end, 0},
883 {"endb", s_ignore, 0},
884 {"ent", s_mips_ent, 0},
886 {"fmask", s_mips_mask, 'F'},
887 {"frame", s_mips_frame, 0},
888 {"loc", s_ignore, 0},
889 {"mask", s_mips_mask, 'R'},
890 {"verstamp", s_ignore, 0},
894 extern void pop_insert PARAMS ((const pseudo_typeS *));
899 pop_insert (mips_pseudo_table);
900 if (! ECOFF_DEBUGGING)
901 pop_insert (mips_nonecoff_pseudo_table);
904 /* Symbols labelling the current insn. */
906 struct insn_label_list
908 struct insn_label_list *next;
912 static struct insn_label_list *insn_labels;
913 static struct insn_label_list *free_insn_labels;
915 static void mips_clear_insn_labels PARAMS ((void));
918 mips_clear_insn_labels ()
920 register struct insn_label_list **pl;
922 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
928 static char *expr_end;
930 /* Expressions which appear in instructions. These are set by
933 static expressionS imm_expr;
934 static expressionS offset_expr;
936 /* Relocs associated with imm_expr and offset_expr. */
938 static bfd_reloc_code_real_type imm_reloc[3]
939 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
940 static bfd_reloc_code_real_type offset_reloc[3]
941 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
943 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
945 static boolean imm_unmatched_hi;
947 /* These are set by mips16_ip if an explicit extension is used. */
949 static boolean mips16_small, mips16_ext;
951 #ifdef MIPS_STABS_ELF
952 /* The pdr segment for per procedure frame/regmask info */
958 mips_isa_to_str (isa)
961 const struct mips_cpu_info *ci;
964 ci = mips_cpu_info_from_isa (isa);
968 sprintf (s, "ISA#%d", isa);
973 mips_cpu_to_str (cpu)
976 const struct mips_cpu_info *ci;
979 ci = mips_cpu_info_from_cpu (cpu);
983 sprintf (s, "CPU#%d", cpu);
987 /* The default target format to use. */
990 mips_target_format ()
992 switch (OUTPUT_FLAVOR)
994 case bfd_target_aout_flavour:
995 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
996 case bfd_target_ecoff_flavour:
997 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
998 case bfd_target_coff_flavour:
1000 case bfd_target_elf_flavour:
1002 /* This is traditional mips */
1003 return (target_big_endian
1004 ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips"
1005 : "elf32-tradbigmips")
1006 : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips"
1007 : "elf32-tradlittlemips"));
1009 return (target_big_endian
1010 ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips")
1011 : (HAVE_64BIT_OBJECTS ? "elf64-littlemips"
1012 : "elf32-littlemips"));
1020 /* This function is called once, at assembler startup time. It should
1021 set up all the tables, etc. that the MD part of the assembler will need. */
1026 register const char *retval = NULL;
1031 int mips_isa_from_cpu;
1032 int target_cpu_had_mips16 = 0;
1033 const struct mips_cpu_info *ci;
1035 /* GP relative stuff not working for PE */
1036 if (strncmp (TARGET_OS, "pe", 2) == 0
1037 && g_switch_value != 0)
1040 as_bad (_("-G not supported in this configuration."));
1045 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
1047 a = xmalloc (sizeof TARGET_CPU);
1048 strcpy (a, TARGET_CPU);
1049 a[(sizeof TARGET_CPU) - 3] = '\0';
1053 if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0)
1055 target_cpu_had_mips16 = 1;
1056 cpu += sizeof "mips16" - 1;
1059 if (mips_opts.mips16 < 0)
1060 mips_opts.mips16 = target_cpu_had_mips16;
1062 /* Backward compatibility for historic -mcpu= option. Check for
1063 incompatible options, warn if -mcpu is used. */
1064 if (mips_cpu != CPU_UNKNOWN
1065 && mips_arch != CPU_UNKNOWN
1066 && mips_cpu != mips_arch)
1068 as_fatal (_("The -mcpu option can't be used together with -march. "
1069 "Use -mtune instead of -mcpu."));
1072 if (mips_cpu != CPU_UNKNOWN
1073 && mips_tune != CPU_UNKNOWN
1074 && mips_cpu != mips_tune)
1076 as_fatal (_("The -mcpu option can't be used together with -mtune. "
1077 "Use -march instead of -mcpu."));
1081 /* For backward compatibility, let -mipsN set various defaults. */
1082 /* This code should go away, to be replaced with something rather more
1083 draconian. Until GCC 3.1 has been released for some reasonable
1084 amount of time, however, we need to support this. */
1085 if (mips_opts.isa != ISA_UNKNOWN)
1087 /* Translate -mipsN to the appropriate settings of file_mips_gp32
1088 and file_mips_fp32. Tag binaries as using the mipsN ISA. */
1089 if (file_mips_gp32 < 0)
1091 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1096 if (file_mips_fp32 < 0)
1098 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1104 ci = mips_cpu_info_from_isa (mips_opts.isa);
1105 assert (ci != NULL);
1106 /* -mipsN has higher priority than -mcpu but lower than -march. */
1107 if (mips_arch == CPU_UNKNOWN)
1108 mips_arch = ci->cpu;
1110 /* Default mips_abi. */
1111 if (mips_opts.abi == NO_ABI)
1113 if (mips_opts.isa == ISA_MIPS1 || mips_opts.isa == ISA_MIPS2)
1114 mips_opts.abi = O32_ABI;
1115 else if (mips_opts.isa == ISA_MIPS3 || mips_opts.isa == ISA_MIPS4)
1116 mips_opts.abi = O64_ABI;
1120 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1122 ci = mips_cpu_info_from_cpu (mips_cpu);
1123 assert (ci != NULL);
1124 mips_arch = ci->cpu;
1125 as_warn (_("The -mcpu option is deprecated. Please use -march and "
1126 "-mtune instead."));
1129 /* Set tune from -mcpu, not from -mipsN. */
1130 if (mips_tune == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1132 ci = mips_cpu_info_from_cpu (mips_cpu);
1133 assert (ci != NULL);
1134 mips_tune = ci->cpu;
1137 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
1138 specified on the command line, or some other value if one was.
1139 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
1140 the command line, or will be set otherwise if one was. */
1142 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1143 /* Handled above. */;
1145 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1147 ci = mips_cpu_info_from_cpu (mips_cpu);
1148 assert (ci != NULL);
1149 mips_arch = ci->cpu;
1150 as_warn (_("The -mcpu option is deprecated. Please use -march and "
1151 "-mtune instead."));
1154 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
1155 specified on the command line, or some other value if one was.
1156 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
1157 the command line, or will be set otherwise if one was. */
1159 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1161 /* We have to check if the isa is the default isa of arch. Otherwise
1162 we'll get invalid object file headers. */
1163 ci = mips_cpu_info_from_cpu (mips_arch);
1164 assert (ci != NULL);
1165 if (mips_opts.isa != ci->isa)
1167 /* This really should be an error instead of a warning, but old
1168 compilers only have -mcpu which sets both arch and tune. For
1169 now, we discard arch and preserve tune. */
1170 as_warn (_("The -march option is incompatible to -mipsN and "
1171 "therefore ignored."));
1172 if (mips_tune == CPU_UNKNOWN)
1173 mips_tune = mips_arch;
1174 ci = mips_cpu_info_from_isa (mips_opts.isa);
1175 assert (ci != NULL);
1176 mips_arch = ci->cpu;
1180 else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN)
1182 /* We have ARCH, we need ISA. */
1183 ci = mips_cpu_info_from_cpu (mips_arch);
1184 assert (ci != NULL);
1185 mips_opts.isa = ci->isa;
1187 else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1189 /* We have ISA, we need default ARCH. */
1190 ci = mips_cpu_info_from_isa (mips_opts.isa);
1191 assert (ci != NULL);
1192 mips_arch = ci->cpu;
1196 /* We need to set both ISA and ARCH from target cpu. */
1197 ci = mips_cpu_info_from_name (cpu);
1199 ci = mips_cpu_info_from_cpu (CPU_R3000);
1200 assert (ci != NULL);
1201 mips_opts.isa = ci->isa;
1202 mips_arch = ci->cpu;
1205 if (mips_tune == CPU_UNKNOWN)
1206 mips_tune = mips_arch;
1208 ci = mips_cpu_info_from_cpu (mips_arch);
1209 assert (ci != NULL);
1210 mips_isa_from_cpu = ci->isa;
1212 /* End of TARGET_CPU processing, get rid of malloced memory
1221 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
1222 as_bad (_("trap exception not supported at ISA 1"));
1224 /* Set the EABI kind based on the ISA before the user gets
1225 to change the ISA with directives. This isn't really
1226 the best, but then neither is basing the abi on the isa. */
1227 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
1228 && mips_opts.abi == EABI_ABI)
1231 /* If they asked for mips1 or mips2 and a cpu that is
1232 mips3 or greater, then mark the object file 32BITMODE. */
1233 if (mips_isa_from_cpu != ISA_UNKNOWN
1234 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
1235 && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
1238 /* If the selected architecture includes support for ASEs, enable
1239 generation of code for them. */
1240 if (mips_opts.ase_mips3d == -1 && CPU_HAS_MIPS3D (mips_arch))
1241 mips_opts.ase_mips3d = 1;
1243 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1244 as_warn (_("Could not set architecture and machine"));
1246 if (file_mips_gp32 < 0)
1248 if (file_mips_fp32 < 0)
1251 file_mips_isa = mips_opts.isa;
1252 file_mips_abi = mips_opts.abi;
1253 file_ase_mips3d = mips_opts.ase_mips3d;
1254 mips_opts.gp32 = file_mips_gp32;
1255 mips_opts.fp32 = file_mips_fp32;
1257 op_hash = hash_new ();
1259 for (i = 0; i < NUMOPCODES;)
1261 const char *name = mips_opcodes[i].name;
1263 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1266 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1267 mips_opcodes[i].name, retval);
1268 /* Probably a memory allocation problem? Give up now. */
1269 as_fatal (_("Broken assembler. No assembly attempted."));
1273 if (mips_opcodes[i].pinfo != INSN_MACRO)
1275 if (!validate_mips_insn (&mips_opcodes[i]))
1280 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1283 mips16_op_hash = hash_new ();
1286 while (i < bfd_mips16_num_opcodes)
1288 const char *name = mips16_opcodes[i].name;
1290 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1292 as_fatal (_("internal: can't hash `%s': %s"),
1293 mips16_opcodes[i].name, retval);
1296 if (mips16_opcodes[i].pinfo != INSN_MACRO
1297 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1298 != mips16_opcodes[i].match))
1300 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1301 mips16_opcodes[i].name, mips16_opcodes[i].args);
1306 while (i < bfd_mips16_num_opcodes
1307 && strcmp (mips16_opcodes[i].name, name) == 0);
1311 as_fatal (_("Broken assembler. No assembly attempted."));
1313 /* We add all the general register names to the symbol table. This
1314 helps us detect invalid uses of them. */
1315 for (i = 0; i < 32; i++)
1319 sprintf (buf, "$%d", i);
1320 symbol_table_insert (symbol_new (buf, reg_section, i,
1321 &zero_address_frag));
1323 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1324 &zero_address_frag));
1325 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1326 &zero_address_frag));
1327 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1328 &zero_address_frag));
1329 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1330 &zero_address_frag));
1331 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1332 &zero_address_frag));
1333 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1334 &zero_address_frag));
1335 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1336 &zero_address_frag));
1338 mips_no_prev_insn (false);
1341 mips_cprmask[0] = 0;
1342 mips_cprmask[1] = 0;
1343 mips_cprmask[2] = 0;
1344 mips_cprmask[3] = 0;
1346 /* set the default alignment for the text section (2**2) */
1347 record_alignment (text_section, 2);
1349 if (USE_GLOBAL_POINTER_OPT)
1350 bfd_set_gp_size (stdoutput, g_switch_value);
1352 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1354 /* On a native system, sections must be aligned to 16 byte
1355 boundaries. When configured for an embedded ELF target, we
1357 if (strcmp (TARGET_OS, "elf") != 0)
1359 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1360 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1361 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1364 /* Create a .reginfo section for register masks and a .mdebug
1365 section for debugging information. */
1373 subseg = now_subseg;
1375 /* The ABI says this section should be loaded so that the
1376 running program can access it. However, we don't load it
1377 if we are configured for an embedded target */
1378 flags = SEC_READONLY | SEC_DATA;
1379 if (strcmp (TARGET_OS, "elf") != 0)
1380 flags |= SEC_ALLOC | SEC_LOAD;
1384 sec = subseg_new (".reginfo", (subsegT) 0);
1386 (void) bfd_set_section_flags (stdoutput, sec, flags);
1387 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1390 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1395 /* The 64-bit ABI uses a .MIPS.options section rather than
1396 .reginfo section. */
1397 sec = subseg_new (".MIPS.options", (subsegT) 0);
1398 (void) bfd_set_section_flags (stdoutput, sec, flags);
1399 (void) bfd_set_section_alignment (stdoutput, sec, 3);
1402 /* Set up the option header. */
1404 Elf_Internal_Options opthdr;
1407 opthdr.kind = ODK_REGINFO;
1408 opthdr.size = (sizeof (Elf_External_Options)
1409 + sizeof (Elf64_External_RegInfo));
1412 f = frag_more (sizeof (Elf_External_Options));
1413 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1414 (Elf_External_Options *) f);
1416 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1421 if (ECOFF_DEBUGGING)
1423 sec = subseg_new (".mdebug", (subsegT) 0);
1424 (void) bfd_set_section_flags (stdoutput, sec,
1425 SEC_HAS_CONTENTS | SEC_READONLY);
1426 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1429 #ifdef MIPS_STABS_ELF
1430 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1431 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1432 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
1433 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1436 subseg_set (seg, subseg);
1440 if (! ECOFF_DEBUGGING)
1447 if (! ECOFF_DEBUGGING)
1455 struct mips_cl_insn insn;
1456 bfd_reloc_code_real_type unused_reloc[3]
1457 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1459 imm_expr.X_op = O_absent;
1460 imm_unmatched_hi = false;
1461 offset_expr.X_op = O_absent;
1462 imm_reloc[0] = BFD_RELOC_UNUSED;
1463 imm_reloc[1] = BFD_RELOC_UNUSED;
1464 imm_reloc[2] = BFD_RELOC_UNUSED;
1465 offset_reloc[0] = BFD_RELOC_UNUSED;
1466 offset_reloc[1] = BFD_RELOC_UNUSED;
1467 offset_reloc[2] = BFD_RELOC_UNUSED;
1469 if (mips_opts.mips16)
1470 mips16_ip (str, &insn);
1473 mips_ip (str, &insn);
1474 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1475 str, insn.insn_opcode));
1480 as_bad ("%s `%s'", insn_error, str);
1484 if (insn.insn_mo->pinfo == INSN_MACRO)
1486 if (mips_opts.mips16)
1487 mips16_macro (&insn);
1493 if (imm_expr.X_op != O_absent)
1494 append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi);
1495 else if (offset_expr.X_op != O_absent)
1496 append_insn (NULL, &insn, &offset_expr, offset_reloc, false);
1498 append_insn (NULL, &insn, NULL, unused_reloc, false);
1502 /* See whether instruction IP reads register REG. CLASS is the type
1506 insn_uses_reg (ip, reg, class)
1507 struct mips_cl_insn *ip;
1509 enum mips_regclass class;
1511 if (class == MIPS16_REG)
1513 assert (mips_opts.mips16);
1514 reg = mips16_to_32_reg_map[reg];
1515 class = MIPS_GR_REG;
1518 /* Don't report on general register 0, since it never changes. */
1519 if (class == MIPS_GR_REG && reg == 0)
1522 if (class == MIPS_FP_REG)
1524 assert (! mips_opts.mips16);
1525 /* If we are called with either $f0 or $f1, we must check $f0.
1526 This is not optimal, because it will introduce an unnecessary
1527 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1528 need to distinguish reading both $f0 and $f1 or just one of
1529 them. Note that we don't have to check the other way,
1530 because there is no instruction that sets both $f0 and $f1
1531 and requires a delay. */
1532 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1533 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1534 == (reg &~ (unsigned) 1)))
1536 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1537 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1538 == (reg &~ (unsigned) 1)))
1541 else if (! mips_opts.mips16)
1543 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1544 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1546 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1547 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1552 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1553 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1554 & MIPS16OP_MASK_RX)]
1557 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1558 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1559 & MIPS16OP_MASK_RY)]
1562 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1563 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1564 & MIPS16OP_MASK_MOVE32Z)]
1567 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1569 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1571 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1573 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1574 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1575 & MIPS16OP_MASK_REGR32) == reg)
1582 /* This function returns true if modifying a register requires a
1586 reg_needs_delay (reg)
1589 unsigned long prev_pinfo;
1591 prev_pinfo = prev_insn.insn_mo->pinfo;
1592 if (! mips_opts.noreorder
1593 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1594 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1595 || (! gpr_interlocks
1596 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1598 /* A load from a coprocessor or from memory. All load
1599 delays delay the use of general register rt for one
1600 instruction on the r3000. The r6000 and r4000 use
1602 /* Itbl support may require additional care here. */
1603 know (prev_pinfo & INSN_WRITE_GPR_T);
1604 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1611 /* Mark instruction labels in mips16 mode. This permits the linker to
1612 handle them specially, such as generating jalx instructions when
1613 needed. We also make them odd for the duration of the assembly, in
1614 order to generate the right sort of code. We will make them even
1615 in the adjust_symtab routine, while leaving them marked. This is
1616 convenient for the debugger and the disassembler. The linker knows
1617 to make them odd again. */
1620 mips16_mark_labels ()
1622 if (mips_opts.mips16)
1624 struct insn_label_list *l;
1627 for (l = insn_labels; l != NULL; l = l->next)
1630 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1631 S_SET_OTHER (l->label, STO_MIPS16);
1633 val = S_GET_VALUE (l->label);
1635 S_SET_VALUE (l->label, val + 1);
1640 /* Output an instruction. PLACE is where to put the instruction; if
1641 it is NULL, this uses frag_more to get room. IP is the instruction
1642 information. ADDRESS_EXPR is an operand of the instruction to be
1643 used with RELOC_TYPE. */
1646 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1648 struct mips_cl_insn *ip;
1649 expressionS *address_expr;
1650 bfd_reloc_code_real_type *reloc_type;
1651 boolean unmatched_hi;
1653 register unsigned long prev_pinfo, pinfo;
1658 /* Mark instruction labels in mips16 mode. */
1659 if (mips_opts.mips16)
1660 mips16_mark_labels ();
1662 prev_pinfo = prev_insn.insn_mo->pinfo;
1663 pinfo = ip->insn_mo->pinfo;
1665 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1669 /* If the previous insn required any delay slots, see if we need
1670 to insert a NOP or two. There are eight kinds of possible
1671 hazards, of which an instruction can have at most one type.
1672 (1) a load from memory delay
1673 (2) a load from a coprocessor delay
1674 (3) an unconditional branch delay
1675 (4) a conditional branch delay
1676 (5) a move to coprocessor register delay
1677 (6) a load coprocessor register from memory delay
1678 (7) a coprocessor condition code delay
1679 (8) a HI/LO special register delay
1681 There are a lot of optimizations we could do that we don't.
1682 In particular, we do not, in general, reorder instructions.
1683 If you use gcc with optimization, it will reorder
1684 instructions and generally do much more optimization then we
1685 do here; repeating all that work in the assembler would only
1686 benefit hand written assembly code, and does not seem worth
1689 /* This is how a NOP is emitted. */
1690 #define emit_nop() \
1692 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1693 : md_number_to_chars (frag_more (4), 0, 4))
1695 /* The previous insn might require a delay slot, depending upon
1696 the contents of the current insn. */
1697 if (! mips_opts.mips16
1698 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1699 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1700 && ! cop_interlocks)
1701 || (! gpr_interlocks
1702 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1704 /* A load from a coprocessor or from memory. All load
1705 delays delay the use of general register rt for one
1706 instruction on the r3000. The r6000 and r4000 use
1708 /* Itbl support may require additional care here. */
1709 know (prev_pinfo & INSN_WRITE_GPR_T);
1710 if (mips_optimize == 0
1711 || insn_uses_reg (ip,
1712 ((prev_insn.insn_opcode >> OP_SH_RT)
1717 else if (! mips_opts.mips16
1718 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1719 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1720 && ! cop_interlocks)
1721 || (mips_opts.isa == ISA_MIPS1
1722 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1724 /* A generic coprocessor delay. The previous instruction
1725 modified a coprocessor general or control register. If
1726 it modified a control register, we need to avoid any
1727 coprocessor instruction (this is probably not always
1728 required, but it sometimes is). If it modified a general
1729 register, we avoid using that register.
1731 On the r6000 and r4000 loading a coprocessor register
1732 from memory is interlocked, and does not require a delay.
1734 This case is not handled very well. There is no special
1735 knowledge of CP0 handling, and the coprocessors other
1736 than the floating point unit are not distinguished at
1738 /* Itbl support may require additional care here. FIXME!
1739 Need to modify this to include knowledge about
1740 user specified delays! */
1741 if (prev_pinfo & INSN_WRITE_FPR_T)
1743 if (mips_optimize == 0
1744 || insn_uses_reg (ip,
1745 ((prev_insn.insn_opcode >> OP_SH_FT)
1750 else if (prev_pinfo & INSN_WRITE_FPR_S)
1752 if (mips_optimize == 0
1753 || insn_uses_reg (ip,
1754 ((prev_insn.insn_opcode >> OP_SH_FS)
1761 /* We don't know exactly what the previous instruction
1762 does. If the current instruction uses a coprocessor
1763 register, we must insert a NOP. If previous
1764 instruction may set the condition codes, and the
1765 current instruction uses them, we must insert two
1767 /* Itbl support may require additional care here. */
1768 if (mips_optimize == 0
1769 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1770 && (pinfo & INSN_READ_COND_CODE)))
1772 else if (pinfo & INSN_COP)
1776 else if (! mips_opts.mips16
1777 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1778 && (prev_pinfo & INSN_WRITE_COND_CODE)
1779 && ! cop_interlocks)
1781 /* The previous instruction sets the coprocessor condition
1782 codes, but does not require a general coprocessor delay
1783 (this means it is a floating point comparison
1784 instruction). If this instruction uses the condition
1785 codes, we need to insert a single NOP. */
1786 /* Itbl support may require additional care here. */
1787 if (mips_optimize == 0
1788 || (pinfo & INSN_READ_COND_CODE))
1792 /* If we're fixing up mfhi/mflo for the r7000 and the
1793 previous insn was an mfhi/mflo and the current insn
1794 reads the register that the mfhi/mflo wrote to, then
1797 else if (mips_7000_hilo_fix
1798 && MF_HILO_INSN (prev_pinfo)
1799 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1806 /* If we're fixing up mfhi/mflo for the r7000 and the
1807 2nd previous insn was an mfhi/mflo and the current insn
1808 reads the register that the mfhi/mflo wrote to, then
1811 else if (mips_7000_hilo_fix
1812 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1813 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1821 else if (prev_pinfo & INSN_READ_LO)
1823 /* The previous instruction reads the LO register; if the
1824 current instruction writes to the LO register, we must
1825 insert two NOPS. Some newer processors have interlocks.
1826 Also the tx39's multiply instructions can be exectuted
1827 immediatly after a read from HI/LO (without the delay),
1828 though the tx39's divide insns still do require the
1830 if (! (hilo_interlocks
1831 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1832 && (mips_optimize == 0
1833 || (pinfo & INSN_WRITE_LO)))
1835 /* Most mips16 branch insns don't have a delay slot.
1836 If a read from LO is immediately followed by a branch
1837 to a write to LO we have a read followed by a write
1838 less than 2 insns away. We assume the target of
1839 a branch might be a write to LO, and insert a nop
1840 between a read and an immediately following branch. */
1841 else if (mips_opts.mips16
1842 && (mips_optimize == 0
1843 || (pinfo & MIPS16_INSN_BRANCH)))
1846 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1848 /* The previous instruction reads the HI register; if the
1849 current instruction writes to the HI register, we must
1850 insert a NOP. Some newer processors have interlocks.
1851 Also the note tx39's multiply above. */
1852 if (! (hilo_interlocks
1853 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1854 && (mips_optimize == 0
1855 || (pinfo & INSN_WRITE_HI)))
1857 /* Most mips16 branch insns don't have a delay slot.
1858 If a read from HI is immediately followed by a branch
1859 to a write to HI we have a read followed by a write
1860 less than 2 insns away. We assume the target of
1861 a branch might be a write to HI, and insert a nop
1862 between a read and an immediately following branch. */
1863 else if (mips_opts.mips16
1864 && (mips_optimize == 0
1865 || (pinfo & MIPS16_INSN_BRANCH)))
1869 /* If the previous instruction was in a noreorder section, then
1870 we don't want to insert the nop after all. */
1871 /* Itbl support may require additional care here. */
1872 if (prev_insn_unreordered)
1875 /* There are two cases which require two intervening
1876 instructions: 1) setting the condition codes using a move to
1877 coprocessor instruction which requires a general coprocessor
1878 delay and then reading the condition codes 2) reading the HI
1879 or LO register and then writing to it (except on processors
1880 which have interlocks). If we are not already emitting a NOP
1881 instruction, we must check for these cases compared to the
1882 instruction previous to the previous instruction. */
1883 if ((! mips_opts.mips16
1884 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1885 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1886 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1887 && (pinfo & INSN_READ_COND_CODE)
1888 && ! cop_interlocks)
1889 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1890 && (pinfo & INSN_WRITE_LO)
1891 && ! (hilo_interlocks
1892 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1893 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1894 && (pinfo & INSN_WRITE_HI)
1895 && ! (hilo_interlocks
1896 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1901 if (prev_prev_insn_unreordered)
1904 if (prev_prev_nop && nops == 0)
1907 /* If we are being given a nop instruction, don't bother with
1908 one of the nops we would otherwise output. This will only
1909 happen when a nop instruction is used with mips_optimize set
1912 && ! mips_opts.noreorder
1913 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1916 /* Now emit the right number of NOP instructions. */
1917 if (nops > 0 && ! mips_opts.noreorder)
1920 unsigned long old_frag_offset;
1922 struct insn_label_list *l;
1924 old_frag = frag_now;
1925 old_frag_offset = frag_now_fix ();
1927 for (i = 0; i < nops; i++)
1932 listing_prev_line ();
1933 /* We may be at the start of a variant frag. In case we
1934 are, make sure there is enough space for the frag
1935 after the frags created by listing_prev_line. The
1936 argument to frag_grow here must be at least as large
1937 as the argument to all other calls to frag_grow in
1938 this file. We don't have to worry about being in the
1939 middle of a variant frag, because the variants insert
1940 all needed nop instructions themselves. */
1944 for (l = insn_labels; l != NULL; l = l->next)
1948 assert (S_GET_SEGMENT (l->label) == now_seg);
1949 symbol_set_frag (l->label, frag_now);
1950 val = (valueT) frag_now_fix ();
1951 /* mips16 text labels are stored as odd. */
1952 if (mips_opts.mips16)
1954 S_SET_VALUE (l->label, val);
1957 #ifndef NO_ECOFF_DEBUGGING
1958 if (ECOFF_DEBUGGING)
1959 ecoff_fix_loc (old_frag, old_frag_offset);
1962 else if (prev_nop_frag != NULL)
1964 /* We have a frag holding nops we may be able to remove. If
1965 we don't need any nops, we can decrease the size of
1966 prev_nop_frag by the size of one instruction. If we do
1967 need some nops, we count them in prev_nops_required. */
1968 if (prev_nop_frag_since == 0)
1972 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1973 --prev_nop_frag_holds;
1976 prev_nop_frag_required += nops;
1980 if (prev_prev_nop == 0)
1982 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1983 --prev_nop_frag_holds;
1986 ++prev_nop_frag_required;
1989 if (prev_nop_frag_holds <= prev_nop_frag_required)
1990 prev_nop_frag = NULL;
1992 ++prev_nop_frag_since;
1994 /* Sanity check: by the time we reach the second instruction
1995 after prev_nop_frag, we should have used up all the nops
1996 one way or another. */
1997 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
2001 if (*reloc_type > BFD_RELOC_UNUSED)
2003 /* We need to set up a variant frag. */
2004 assert (mips_opts.mips16 && address_expr != NULL);
2005 f = frag_var (rs_machine_dependent, 4, 0,
2006 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
2007 mips16_small, mips16_ext,
2009 & INSN_UNCOND_BRANCH_DELAY),
2010 (*prev_insn_reloc_type
2011 == BFD_RELOC_MIPS16_JMP)),
2012 make_expr_symbol (address_expr), 0, NULL);
2014 else if (place != NULL)
2016 else if (mips_opts.mips16
2018 && *reloc_type != BFD_RELOC_MIPS16_JMP)
2020 /* Make sure there is enough room to swap this instruction with
2021 a following jump instruction. */
2027 if (mips_opts.mips16
2028 && mips_opts.noreorder
2029 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
2030 as_warn (_("extended instruction in delay slot"));
2035 fixp[0] = fixp[1] = fixp[2] = NULL;
2036 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
2038 if (address_expr->X_op == O_constant)
2042 switch (*reloc_type)
2045 ip->insn_opcode |= address_expr->X_add_number;
2048 case BFD_RELOC_MIPS_HIGHEST:
2049 tmp = (address_expr->X_add_number + 0x800080008000) >> 16;
2051 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2054 case BFD_RELOC_MIPS_HIGHER:
2055 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
2056 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2059 case BFD_RELOC_HI16_S:
2060 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
2064 case BFD_RELOC_HI16:
2065 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2068 case BFD_RELOC_LO16:
2069 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2072 case BFD_RELOC_MIPS_JMP:
2073 if ((address_expr->X_add_number & 3) != 0)
2074 as_bad (_("jump to misaligned address (0x%lx)"),
2075 (unsigned long) address_expr->X_add_number);
2076 if (address_expr->X_add_number & ~0xfffffff
2077 || address_expr->X_add_number > 0x7fffffc)
2078 as_bad (_("jump address range overflow (0x%lx)"),
2079 (unsigned long) address_expr->X_add_number);
2080 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2083 case BFD_RELOC_MIPS16_JMP:
2084 if ((address_expr->X_add_number & 3) != 0)
2085 as_bad (_("jump to misaligned address (0x%lx)"),
2086 (unsigned long) address_expr->X_add_number);
2087 if (address_expr->X_add_number & ~0xfffffff
2088 || address_expr->X_add_number > 0x7fffffc)
2089 as_bad (_("jump address range overflow (0x%lx)"),
2090 (unsigned long) address_expr->X_add_number);
2092 (((address_expr->X_add_number & 0x7c0000) << 3)
2093 | ((address_expr->X_add_number & 0xf800000) >> 7)
2094 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2097 case BFD_RELOC_16_PCREL:
2098 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2101 case BFD_RELOC_16_PCREL_S2:
2111 /* Don't generate a reloc if we are writing into a variant frag. */
2114 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
2116 (*reloc_type == BFD_RELOC_16_PCREL
2117 || *reloc_type == BFD_RELOC_16_PCREL_S2),
2120 /* These relocations can have an addend that won't fit in
2121 4 octets for 64bit assembly. */
2122 if (HAVE_64BIT_GPRS &&
2123 (*reloc_type == BFD_RELOC_16
2124 || *reloc_type == BFD_RELOC_32
2125 || *reloc_type == BFD_RELOC_MIPS_JMP
2126 || *reloc_type == BFD_RELOC_HI16_S
2127 || *reloc_type == BFD_RELOC_LO16
2128 || *reloc_type == BFD_RELOC_GPREL16
2129 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2130 || *reloc_type == BFD_RELOC_GPREL32
2131 || *reloc_type == BFD_RELOC_64
2132 || *reloc_type == BFD_RELOC_CTOR
2133 || *reloc_type == BFD_RELOC_MIPS_SUB
2134 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2135 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2136 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2137 || *reloc_type == BFD_RELOC_MIPS_REL16
2138 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2139 fixp[0]->fx_no_overflow = 1;
2143 struct mips_hi_fixup *hi_fixup;
2145 assert (*reloc_type == BFD_RELOC_HI16_S);
2146 hi_fixup = ((struct mips_hi_fixup *)
2147 xmalloc (sizeof (struct mips_hi_fixup)));
2148 hi_fixup->fixp = fixp[0];
2149 hi_fixup->seg = now_seg;
2150 hi_fixup->next = mips_hi_fixup_list;
2151 mips_hi_fixup_list = hi_fixup;
2154 if (reloc_type[1] != BFD_RELOC_UNUSED)
2156 /* FIXME: This symbol can be one of
2157 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
2158 address_expr->X_op = O_absent;
2159 address_expr->X_add_symbol = 0;
2160 address_expr->X_add_number = 0;
2162 fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal,
2163 4, address_expr, false,
2166 /* These relocations can have an addend that won't fit in
2167 4 octets for 64bit assembly. */
2168 if (HAVE_64BIT_GPRS &&
2169 (*reloc_type == BFD_RELOC_16
2170 || *reloc_type == BFD_RELOC_32
2171 || *reloc_type == BFD_RELOC_MIPS_JMP
2172 || *reloc_type == BFD_RELOC_HI16_S
2173 || *reloc_type == BFD_RELOC_LO16
2174 || *reloc_type == BFD_RELOC_GPREL16
2175 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2176 || *reloc_type == BFD_RELOC_GPREL32
2177 || *reloc_type == BFD_RELOC_64
2178 || *reloc_type == BFD_RELOC_CTOR
2179 || *reloc_type == BFD_RELOC_MIPS_SUB
2180 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2181 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2182 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2183 || *reloc_type == BFD_RELOC_MIPS_REL16
2184 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2185 fixp[1]->fx_no_overflow = 1;
2187 if (reloc_type[2] != BFD_RELOC_UNUSED)
2189 address_expr->X_op = O_absent;
2190 address_expr->X_add_symbol = 0;
2191 address_expr->X_add_number = 0;
2193 fixp[2] = fix_new_exp (frag_now,
2194 f - frag_now->fr_literal, 4,
2195 address_expr, false,
2198 /* These relocations can have an addend that won't fit in
2199 4 octets for 64bit assembly. */
2200 if (HAVE_64BIT_GPRS &&
2201 (*reloc_type == BFD_RELOC_16
2202 || *reloc_type == BFD_RELOC_32
2203 || *reloc_type == BFD_RELOC_MIPS_JMP
2204 || *reloc_type == BFD_RELOC_HI16_S
2205 || *reloc_type == BFD_RELOC_LO16
2206 || *reloc_type == BFD_RELOC_GPREL16
2207 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2208 || *reloc_type == BFD_RELOC_GPREL32
2209 || *reloc_type == BFD_RELOC_64
2210 || *reloc_type == BFD_RELOC_CTOR
2211 || *reloc_type == BFD_RELOC_MIPS_SUB
2212 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2213 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2214 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2215 || *reloc_type == BFD_RELOC_MIPS_REL16
2216 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2217 fixp[2]->fx_no_overflow = 1;
2224 if (! mips_opts.mips16)
2225 md_number_to_chars (f, ip->insn_opcode, 4);
2226 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2228 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2229 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2235 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2238 md_number_to_chars (f, ip->insn_opcode, 2);
2241 /* Update the register mask information. */
2242 if (! mips_opts.mips16)
2244 if (pinfo & INSN_WRITE_GPR_D)
2245 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2246 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2247 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2248 if (pinfo & INSN_READ_GPR_S)
2249 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2250 if (pinfo & INSN_WRITE_GPR_31)
2251 mips_gprmask |= 1 << 31;
2252 if (pinfo & INSN_WRITE_FPR_D)
2253 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2254 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2255 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2256 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2257 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2258 if ((pinfo & INSN_READ_FPR_R) != 0)
2259 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2260 if (pinfo & INSN_COP)
2262 /* We don't keep enough information to sort these cases out.
2263 The itbl support does keep this information however, although
2264 we currently don't support itbl fprmats as part of the cop
2265 instruction. May want to add this support in the future. */
2267 /* Never set the bit for $0, which is always zero. */
2268 mips_gprmask &= ~1 << 0;
2272 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2273 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2274 & MIPS16OP_MASK_RX);
2275 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2276 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2277 & MIPS16OP_MASK_RY);
2278 if (pinfo & MIPS16_INSN_WRITE_Z)
2279 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2280 & MIPS16OP_MASK_RZ);
2281 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2282 mips_gprmask |= 1 << TREG;
2283 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2284 mips_gprmask |= 1 << SP;
2285 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2286 mips_gprmask |= 1 << RA;
2287 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2288 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2289 if (pinfo & MIPS16_INSN_READ_Z)
2290 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2291 & MIPS16OP_MASK_MOVE32Z);
2292 if (pinfo & MIPS16_INSN_READ_GPR_X)
2293 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2294 & MIPS16OP_MASK_REGR32);
2297 if (place == NULL && ! mips_opts.noreorder)
2299 /* Filling the branch delay slot is more complex. We try to
2300 switch the branch with the previous instruction, which we can
2301 do if the previous instruction does not set up a condition
2302 that the branch tests and if the branch is not itself the
2303 target of any branch. */
2304 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2305 || (pinfo & INSN_COND_BRANCH_DELAY))
2307 if (mips_optimize < 2
2308 /* If we have seen .set volatile or .set nomove, don't
2310 || mips_opts.nomove != 0
2311 /* If we had to emit any NOP instructions, then we
2312 already know we can not swap. */
2314 /* If we don't even know the previous insn, we can not
2316 || ! prev_insn_valid
2317 /* If the previous insn is already in a branch delay
2318 slot, then we can not swap. */
2319 || prev_insn_is_delay_slot
2320 /* If the previous previous insn was in a .set
2321 noreorder, we can't swap. Actually, the MIPS
2322 assembler will swap in this situation. However, gcc
2323 configured -with-gnu-as will generate code like
2329 in which we can not swap the bne and INSN. If gcc is
2330 not configured -with-gnu-as, it does not output the
2331 .set pseudo-ops. We don't have to check
2332 prev_insn_unreordered, because prev_insn_valid will
2333 be 0 in that case. We don't want to use
2334 prev_prev_insn_valid, because we do want to be able
2335 to swap at the start of a function. */
2336 || prev_prev_insn_unreordered
2337 /* If the branch is itself the target of a branch, we
2338 can not swap. We cheat on this; all we check for is
2339 whether there is a label on this instruction. If
2340 there are any branches to anything other than a
2341 label, users must use .set noreorder. */
2342 || insn_labels != NULL
2343 /* If the previous instruction is in a variant frag, we
2344 can not do the swap. This does not apply to the
2345 mips16, which uses variant frags for different
2347 || (! mips_opts.mips16
2348 && prev_insn_frag->fr_type == rs_machine_dependent)
2349 /* If the branch reads the condition codes, we don't
2350 even try to swap, because in the sequence
2355 we can not swap, and I don't feel like handling that
2357 || (! mips_opts.mips16
2358 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2359 && (pinfo & INSN_READ_COND_CODE))
2360 /* We can not swap with an instruction that requires a
2361 delay slot, becase the target of the branch might
2362 interfere with that instruction. */
2363 || (! mips_opts.mips16
2364 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2366 /* Itbl support may require additional care here. */
2367 & (INSN_LOAD_COPROC_DELAY
2368 | INSN_COPROC_MOVE_DELAY
2369 | INSN_WRITE_COND_CODE)))
2370 || (! (hilo_interlocks
2371 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2375 || (! mips_opts.mips16
2377 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2378 || (! mips_opts.mips16
2379 && mips_opts.isa == ISA_MIPS1
2380 /* Itbl support may require additional care here. */
2381 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2382 /* We can not swap with a branch instruction. */
2384 & (INSN_UNCOND_BRANCH_DELAY
2385 | INSN_COND_BRANCH_DELAY
2386 | INSN_COND_BRANCH_LIKELY))
2387 /* We do not swap with a trap instruction, since it
2388 complicates trap handlers to have the trap
2389 instruction be in a delay slot. */
2390 || (prev_pinfo & INSN_TRAP)
2391 /* If the branch reads a register that the previous
2392 instruction sets, we can not swap. */
2393 || (! mips_opts.mips16
2394 && (prev_pinfo & INSN_WRITE_GPR_T)
2395 && insn_uses_reg (ip,
2396 ((prev_insn.insn_opcode >> OP_SH_RT)
2399 || (! mips_opts.mips16
2400 && (prev_pinfo & INSN_WRITE_GPR_D)
2401 && insn_uses_reg (ip,
2402 ((prev_insn.insn_opcode >> OP_SH_RD)
2405 || (mips_opts.mips16
2406 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2407 && insn_uses_reg (ip,
2408 ((prev_insn.insn_opcode
2410 & MIPS16OP_MASK_RX),
2412 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2413 && insn_uses_reg (ip,
2414 ((prev_insn.insn_opcode
2416 & MIPS16OP_MASK_RY),
2418 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2419 && insn_uses_reg (ip,
2420 ((prev_insn.insn_opcode
2422 & MIPS16OP_MASK_RZ),
2424 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2425 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2426 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2427 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2428 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2429 && insn_uses_reg (ip,
2430 MIPS16OP_EXTRACT_REG32R (prev_insn.
2433 /* If the branch writes a register that the previous
2434 instruction sets, we can not swap (we know that
2435 branches write only to RD or to $31). */
2436 || (! mips_opts.mips16
2437 && (prev_pinfo & INSN_WRITE_GPR_T)
2438 && (((pinfo & INSN_WRITE_GPR_D)
2439 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2440 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2441 || ((pinfo & INSN_WRITE_GPR_31)
2442 && (((prev_insn.insn_opcode >> OP_SH_RT)
2445 || (! mips_opts.mips16
2446 && (prev_pinfo & INSN_WRITE_GPR_D)
2447 && (((pinfo & INSN_WRITE_GPR_D)
2448 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2449 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2450 || ((pinfo & INSN_WRITE_GPR_31)
2451 && (((prev_insn.insn_opcode >> OP_SH_RD)
2454 || (mips_opts.mips16
2455 && (pinfo & MIPS16_INSN_WRITE_31)
2456 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2457 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2458 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2460 /* If the branch writes a register that the previous
2461 instruction reads, we can not swap (we know that
2462 branches only write to RD or to $31). */
2463 || (! mips_opts.mips16
2464 && (pinfo & INSN_WRITE_GPR_D)
2465 && insn_uses_reg (&prev_insn,
2466 ((ip->insn_opcode >> OP_SH_RD)
2469 || (! mips_opts.mips16
2470 && (pinfo & INSN_WRITE_GPR_31)
2471 && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG))
2472 || (mips_opts.mips16
2473 && (pinfo & MIPS16_INSN_WRITE_31)
2474 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2475 /* If we are generating embedded PIC code, the branch
2476 might be expanded into a sequence which uses $at, so
2477 we can't swap with an instruction which reads it. */
2478 || (mips_pic == EMBEDDED_PIC
2479 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2480 /* If the previous previous instruction has a load
2481 delay, and sets a register that the branch reads, we
2483 || (! mips_opts.mips16
2484 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2485 /* Itbl support may require additional care here. */
2486 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2487 || (! gpr_interlocks
2488 && (prev_prev_insn.insn_mo->pinfo
2489 & INSN_LOAD_MEMORY_DELAY)))
2490 && insn_uses_reg (ip,
2491 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2494 /* If one instruction sets a condition code and the
2495 other one uses a condition code, we can not swap. */
2496 || ((pinfo & INSN_READ_COND_CODE)
2497 && (prev_pinfo & INSN_WRITE_COND_CODE))
2498 || ((pinfo & INSN_WRITE_COND_CODE)
2499 && (prev_pinfo & INSN_READ_COND_CODE))
2500 /* If the previous instruction uses the PC, we can not
2502 || (mips_opts.mips16
2503 && (prev_pinfo & MIPS16_INSN_READ_PC))
2504 /* If the previous instruction was extended, we can not
2506 || (mips_opts.mips16 && prev_insn_extended)
2507 /* If the previous instruction had a fixup in mips16
2508 mode, we can not swap. This normally means that the
2509 previous instruction was a 4 byte branch anyhow. */
2510 || (mips_opts.mips16 && prev_insn_fixp[0])
2511 /* If the previous instruction is a sync, sync.l, or
2512 sync.p, we can not swap. */
2513 || (prev_pinfo & INSN_SYNC))
2515 /* We could do even better for unconditional branches to
2516 portions of this object file; we could pick up the
2517 instruction at the destination, put it in the delay
2518 slot, and bump the destination address. */
2520 /* Update the previous insn information. */
2521 prev_prev_insn = *ip;
2522 prev_insn.insn_mo = &dummy_opcode;
2526 /* It looks like we can actually do the swap. */
2527 if (! mips_opts.mips16)
2532 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2533 memcpy (temp, prev_f, 4);
2534 memcpy (prev_f, f, 4);
2535 memcpy (f, temp, 4);
2536 if (prev_insn_fixp[0])
2538 prev_insn_fixp[0]->fx_frag = frag_now;
2539 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2541 if (prev_insn_fixp[1])
2543 prev_insn_fixp[1]->fx_frag = frag_now;
2544 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2546 if (prev_insn_fixp[2])
2548 prev_insn_fixp[2]->fx_frag = frag_now;
2549 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2553 fixp[0]->fx_frag = prev_insn_frag;
2554 fixp[0]->fx_where = prev_insn_where;
2558 fixp[1]->fx_frag = prev_insn_frag;
2559 fixp[1]->fx_where = prev_insn_where;
2563 fixp[2]->fx_frag = prev_insn_frag;
2564 fixp[2]->fx_where = prev_insn_where;
2572 assert (prev_insn_fixp[0] == NULL);
2573 assert (prev_insn_fixp[1] == NULL);
2574 assert (prev_insn_fixp[2] == NULL);
2575 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2576 memcpy (temp, prev_f, 2);
2577 memcpy (prev_f, f, 2);
2578 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2580 assert (*reloc_type == BFD_RELOC_UNUSED);
2581 memcpy (f, temp, 2);
2585 memcpy (f, f + 2, 2);
2586 memcpy (f + 2, temp, 2);
2590 fixp[0]->fx_frag = prev_insn_frag;
2591 fixp[0]->fx_where = prev_insn_where;
2595 fixp[1]->fx_frag = prev_insn_frag;
2596 fixp[1]->fx_where = prev_insn_where;
2600 fixp[2]->fx_frag = prev_insn_frag;
2601 fixp[2]->fx_where = prev_insn_where;
2605 /* Update the previous insn information; leave prev_insn
2607 prev_prev_insn = *ip;
2609 prev_insn_is_delay_slot = 1;
2611 /* If that was an unconditional branch, forget the previous
2612 insn information. */
2613 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2615 prev_prev_insn.insn_mo = &dummy_opcode;
2616 prev_insn.insn_mo = &dummy_opcode;
2619 prev_insn_fixp[0] = NULL;
2620 prev_insn_fixp[1] = NULL;
2621 prev_insn_fixp[2] = NULL;
2622 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2623 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2624 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2625 prev_insn_extended = 0;
2627 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2629 /* We don't yet optimize a branch likely. What we should do
2630 is look at the target, copy the instruction found there
2631 into the delay slot, and increment the branch to jump to
2632 the next instruction. */
2634 /* Update the previous insn information. */
2635 prev_prev_insn = *ip;
2636 prev_insn.insn_mo = &dummy_opcode;
2637 prev_insn_fixp[0] = NULL;
2638 prev_insn_fixp[1] = NULL;
2639 prev_insn_fixp[2] = NULL;
2640 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2641 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2642 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2643 prev_insn_extended = 0;
2647 /* Update the previous insn information. */
2649 prev_prev_insn.insn_mo = &dummy_opcode;
2651 prev_prev_insn = prev_insn;
2654 /* Any time we see a branch, we always fill the delay slot
2655 immediately; since this insn is not a branch, we know it
2656 is not in a delay slot. */
2657 prev_insn_is_delay_slot = 0;
2659 prev_insn_fixp[0] = fixp[0];
2660 prev_insn_fixp[1] = fixp[1];
2661 prev_insn_fixp[2] = fixp[2];
2662 prev_insn_reloc_type[0] = reloc_type[0];
2663 prev_insn_reloc_type[1] = reloc_type[1];
2664 prev_insn_reloc_type[2] = reloc_type[2];
2665 if (mips_opts.mips16)
2666 prev_insn_extended = (ip->use_extend
2667 || *reloc_type > BFD_RELOC_UNUSED);
2670 prev_prev_insn_unreordered = prev_insn_unreordered;
2671 prev_insn_unreordered = 0;
2672 prev_insn_frag = frag_now;
2673 prev_insn_where = f - frag_now->fr_literal;
2674 prev_insn_valid = 1;
2676 else if (place == NULL)
2678 /* We need to record a bit of information even when we are not
2679 reordering, in order to determine the base address for mips16
2680 PC relative relocs. */
2681 prev_prev_insn = prev_insn;
2683 prev_insn_reloc_type[0] = reloc_type[0];
2684 prev_insn_reloc_type[1] = reloc_type[1];
2685 prev_insn_reloc_type[2] = reloc_type[2];
2686 prev_prev_insn_unreordered = prev_insn_unreordered;
2687 prev_insn_unreordered = 1;
2690 /* We just output an insn, so the next one doesn't have a label. */
2691 mips_clear_insn_labels ();
2693 /* We must ensure that a fixup associated with an unmatched %hi
2694 reloc does not become a variant frag. Otherwise, the
2695 rearrangement of %hi relocs in frob_file may confuse
2699 frag_wane (frag_now);
2704 /* This function forgets that there was any previous instruction or
2705 label. If PRESERVE is non-zero, it remembers enough information to
2706 know whether nops are needed before a noreorder section. */
2709 mips_no_prev_insn (preserve)
2714 prev_insn.insn_mo = &dummy_opcode;
2715 prev_prev_insn.insn_mo = &dummy_opcode;
2716 prev_nop_frag = NULL;
2717 prev_nop_frag_holds = 0;
2718 prev_nop_frag_required = 0;
2719 prev_nop_frag_since = 0;
2721 prev_insn_valid = 0;
2722 prev_insn_is_delay_slot = 0;
2723 prev_insn_unreordered = 0;
2724 prev_insn_extended = 0;
2725 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2726 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2727 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2728 prev_prev_insn_unreordered = 0;
2729 mips_clear_insn_labels ();
2732 /* This function must be called whenever we turn on noreorder or emit
2733 something other than instructions. It inserts any NOPS which might
2734 be needed by the previous instruction, and clears the information
2735 kept for the previous instructions. The INSNS parameter is true if
2736 instructions are to follow. */
2739 mips_emit_delays (insns)
2742 if (! mips_opts.noreorder)
2747 if ((! mips_opts.mips16
2748 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2749 && (! cop_interlocks
2750 && (prev_insn.insn_mo->pinfo
2751 & (INSN_LOAD_COPROC_DELAY
2752 | INSN_COPROC_MOVE_DELAY
2753 | INSN_WRITE_COND_CODE))))
2754 || (! hilo_interlocks
2755 && (prev_insn.insn_mo->pinfo
2758 || (! mips_opts.mips16
2760 && (prev_insn.insn_mo->pinfo
2761 & INSN_LOAD_MEMORY_DELAY))
2762 || (! mips_opts.mips16
2763 && mips_opts.isa == ISA_MIPS1
2764 && (prev_insn.insn_mo->pinfo
2765 & INSN_COPROC_MEMORY_DELAY)))
2767 /* Itbl support may require additional care here. */
2769 if ((! mips_opts.mips16
2770 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2771 && (! cop_interlocks
2772 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2773 || (! hilo_interlocks
2774 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2775 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2778 if (prev_insn_unreordered)
2781 else if ((! mips_opts.mips16
2782 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2783 && (! cop_interlocks
2784 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2785 || (! hilo_interlocks
2786 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2787 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2789 /* Itbl support may require additional care here. */
2790 if (! prev_prev_insn_unreordered)
2796 struct insn_label_list *l;
2800 /* Record the frag which holds the nop instructions, so
2801 that we can remove them if we don't need them. */
2802 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2803 prev_nop_frag = frag_now;
2804 prev_nop_frag_holds = nops;
2805 prev_nop_frag_required = 0;
2806 prev_nop_frag_since = 0;
2809 for (; nops > 0; --nops)
2814 /* Move on to a new frag, so that it is safe to simply
2815 decrease the size of prev_nop_frag. */
2816 frag_wane (frag_now);
2820 for (l = insn_labels; l != NULL; l = l->next)
2824 assert (S_GET_SEGMENT (l->label) == now_seg);
2825 symbol_set_frag (l->label, frag_now);
2826 val = (valueT) frag_now_fix ();
2827 /* mips16 text labels are stored as odd. */
2828 if (mips_opts.mips16)
2830 S_SET_VALUE (l->label, val);
2835 /* Mark instruction labels in mips16 mode. */
2836 if (mips_opts.mips16 && insns)
2837 mips16_mark_labels ();
2839 mips_no_prev_insn (insns);
2842 /* Build an instruction created by a macro expansion. This is passed
2843 a pointer to the count of instructions created so far, an
2844 expression, the name of the instruction to build, an operand format
2845 string, and corresponding arguments. */
2849 macro_build (char *place,
2857 macro_build (place, counter, ep, name, fmt, va_alist)
2866 struct mips_cl_insn insn;
2867 bfd_reloc_code_real_type r[3];
2871 va_start (args, fmt);
2877 * If the macro is about to expand into a second instruction,
2878 * print a warning if needed. We need to pass ip as a parameter
2879 * to generate a better warning message here...
2881 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2882 as_warn (_("Macro instruction expanded into multiple instructions"));
2885 *counter += 1; /* bump instruction counter */
2887 if (mips_opts.mips16)
2889 mips16_macro_build (place, counter, ep, name, fmt, args);
2894 r[0] = BFD_RELOC_UNUSED;
2895 r[1] = BFD_RELOC_UNUSED;
2896 r[2] = BFD_RELOC_UNUSED;
2897 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2898 assert (insn.insn_mo);
2899 assert (strcmp (name, insn.insn_mo->name) == 0);
2901 /* Search until we get a match for NAME. */
2904 if (strcmp (fmt, insn.insn_mo->args) == 0
2905 && insn.insn_mo->pinfo != INSN_MACRO
2906 && OPCODE_IS_MEMBER (insn.insn_mo,
2908 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
2910 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2914 assert (insn.insn_mo->name);
2915 assert (strcmp (name, insn.insn_mo->name) == 0);
2918 insn.insn_opcode = insn.insn_mo->match;
2934 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2938 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2943 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2948 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2953 int tmp = va_arg (args, int);
2955 insn.insn_opcode |= tmp << OP_SH_RT;
2956 insn.insn_opcode |= tmp << OP_SH_RD;
2962 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2969 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2973 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2977 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2981 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2985 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2992 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2998 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2999 assert (*r == BFD_RELOC_GPREL16
3000 || *r == BFD_RELOC_MIPS_LITERAL
3001 || *r == BFD_RELOC_MIPS_HIGHER
3002 || *r == BFD_RELOC_HI16_S
3003 || *r == BFD_RELOC_LO16
3004 || *r == BFD_RELOC_MIPS_GOT16
3005 || *r == BFD_RELOC_MIPS_CALL16
3006 || *r == BFD_RELOC_MIPS_GOT_LO16
3007 || *r == BFD_RELOC_MIPS_CALL_LO16
3008 || (ep->X_op == O_subtract
3009 && *r == BFD_RELOC_PCREL_LO16));
3013 *r = (bfd_reloc_code_real_type) va_arg (args, int);
3015 && (ep->X_op == O_constant
3016 || (ep->X_op == O_symbol
3017 && (*r == BFD_RELOC_MIPS_HIGHEST
3018 || *r == BFD_RELOC_HI16_S
3019 || *r == BFD_RELOC_HI16
3020 || *r == BFD_RELOC_GPREL16
3021 || *r == BFD_RELOC_MIPS_GOT_HI16
3022 || *r == BFD_RELOC_MIPS_CALL_HI16))
3023 || (ep->X_op == O_subtract
3024 && *r == BFD_RELOC_PCREL_HI16_S)));
3028 assert (ep != NULL);
3030 * This allows macro() to pass an immediate expression for
3031 * creating short branches without creating a symbol.
3032 * Note that the expression still might come from the assembly
3033 * input, in which case the value is not checked for range nor
3034 * is a relocation entry generated (yuck).
3036 if (ep->X_op == O_constant)
3038 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
3042 if (mips_pic == EMBEDDED_PIC)
3043 *r = BFD_RELOC_16_PCREL_S2;
3045 *r = BFD_RELOC_16_PCREL;
3049 assert (ep != NULL);
3050 *r = BFD_RELOC_MIPS_JMP;
3054 insn.insn_opcode |= va_arg (args, unsigned long);
3063 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3065 append_insn (place, &insn, ep, r, false);
3069 mips16_macro_build (place, counter, ep, name, fmt, args)
3071 int *counter ATTRIBUTE_UNUSED;
3077 struct mips_cl_insn insn;
3078 bfd_reloc_code_real_type r[3]
3079 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3081 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3082 assert (insn.insn_mo);
3083 assert (strcmp (name, insn.insn_mo->name) == 0);
3085 while (strcmp (fmt, insn.insn_mo->args) != 0
3086 || insn.insn_mo->pinfo == INSN_MACRO)
3089 assert (insn.insn_mo->name);
3090 assert (strcmp (name, insn.insn_mo->name) == 0);
3093 insn.insn_opcode = insn.insn_mo->match;
3094 insn.use_extend = false;
3113 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
3118 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
3122 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
3126 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
3136 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
3143 regno = va_arg (args, int);
3144 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3145 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3166 assert (ep != NULL);
3168 if (ep->X_op != O_constant)
3169 *r = (int) BFD_RELOC_UNUSED + c;
3172 mips16_immed (NULL, 0, c, ep->X_add_number, false, false,
3173 false, &insn.insn_opcode, &insn.use_extend,
3176 *r = BFD_RELOC_UNUSED;
3182 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3189 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3191 append_insn (place, &insn, ep, r, false);
3195 * Generate a "lui" instruction.
3198 macro_build_lui (place, counter, ep, regnum)
3204 expressionS high_expr;
3205 struct mips_cl_insn insn;
3206 bfd_reloc_code_real_type r[3]
3207 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3208 CONST char *name = "lui";
3209 CONST char *fmt = "t,u";
3211 assert (! mips_opts.mips16);
3217 high_expr.X_op = O_constant;
3218 high_expr.X_add_number = ep->X_add_number;
3221 if (high_expr.X_op == O_constant)
3223 /* we can compute the instruction now without a relocation entry */
3224 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3226 *r = BFD_RELOC_UNUSED;
3228 else if (! HAVE_NEWABI)
3230 assert (ep->X_op == O_symbol);
3231 /* _gp_disp is a special case, used from s_cpload. */
3232 assert (mips_pic == NO_PIC
3233 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
3234 *r = BFD_RELOC_HI16_S;
3238 * If the macro is about to expand into a second instruction,
3239 * print a warning if needed. We need to pass ip as a parameter
3240 * to generate a better warning message here...
3242 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3243 as_warn (_("Macro instruction expanded into multiple instructions"));
3246 *counter += 1; /* bump instruction counter */
3248 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3249 assert (insn.insn_mo);
3250 assert (strcmp (name, insn.insn_mo->name) == 0);
3251 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3253 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3254 if (*r == BFD_RELOC_UNUSED)
3256 insn.insn_opcode |= high_expr.X_add_number;
3257 append_insn (place, &insn, NULL, r, false);
3260 append_insn (place, &insn, &high_expr, r, false);
3264 * Generates code to set the $at register to true (one)
3265 * if reg is less than the immediate expression.
3268 set_at (counter, reg, unsignedp)
3273 if (imm_expr.X_op == O_constant
3274 && imm_expr.X_add_number >= -0x8000
3275 && imm_expr.X_add_number < 0x8000)
3276 macro_build ((char *) NULL, counter, &imm_expr,
3277 unsignedp ? "sltiu" : "slti",
3278 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
3281 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3282 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3283 unsignedp ? "sltu" : "slt",
3284 "d,v,t", AT, reg, AT);
3288 /* Warn if an expression is not a constant. */
3291 check_absolute_expr (ip, ex)
3292 struct mips_cl_insn *ip;
3295 if (ex->X_op == O_big)
3296 as_bad (_("unsupported large constant"));
3297 else if (ex->X_op != O_constant)
3298 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3301 /* Count the leading zeroes by performing a binary chop. This is a
3302 bulky bit of source, but performance is a LOT better for the
3303 majority of values than a simple loop to count the bits:
3304 for (lcnt = 0; (lcnt < 32); lcnt++)
3305 if ((v) & (1 << (31 - lcnt)))
3307 However it is not code size friendly, and the gain will drop a bit
3308 on certain cached systems.
3310 #define COUNT_TOP_ZEROES(v) \
3311 (((v) & ~0xffff) == 0 \
3312 ? ((v) & ~0xff) == 0 \
3313 ? ((v) & ~0xf) == 0 \
3314 ? ((v) & ~0x3) == 0 \
3315 ? ((v) & ~0x1) == 0 \
3320 : ((v) & ~0x7) == 0 \
3323 : ((v) & ~0x3f) == 0 \
3324 ? ((v) & ~0x1f) == 0 \
3327 : ((v) & ~0x7f) == 0 \
3330 : ((v) & ~0xfff) == 0 \
3331 ? ((v) & ~0x3ff) == 0 \
3332 ? ((v) & ~0x1ff) == 0 \
3335 : ((v) & ~0x7ff) == 0 \
3338 : ((v) & ~0x3fff) == 0 \
3339 ? ((v) & ~0x1fff) == 0 \
3342 : ((v) & ~0x7fff) == 0 \
3345 : ((v) & ~0xffffff) == 0 \
3346 ? ((v) & ~0xfffff) == 0 \
3347 ? ((v) & ~0x3ffff) == 0 \
3348 ? ((v) & ~0x1ffff) == 0 \
3351 : ((v) & ~0x7ffff) == 0 \
3354 : ((v) & ~0x3fffff) == 0 \
3355 ? ((v) & ~0x1fffff) == 0 \
3358 : ((v) & ~0x7fffff) == 0 \
3361 : ((v) & ~0xfffffff) == 0 \
3362 ? ((v) & ~0x3ffffff) == 0 \
3363 ? ((v) & ~0x1ffffff) == 0 \
3366 : ((v) & ~0x7ffffff) == 0 \
3369 : ((v) & ~0x3fffffff) == 0 \
3370 ? ((v) & ~0x1fffffff) == 0 \
3373 : ((v) & ~0x7fffffff) == 0 \
3377 /* Is the given value a sign-extended 32-bit value? */
3378 #define IS_SEXT_32BIT_NUM(x) \
3379 (((x) &~ (offsetT) 0x7fffffff) == 0 \
3380 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
3383 * This routine generates the least number of instructions neccessary to load
3384 * an absolute expression value into a register.
3387 load_register (counter, reg, ep, dbl)
3394 expressionS hi32, lo32;
3396 if (ep->X_op != O_big)
3398 assert (ep->X_op == O_constant);
3399 if (ep->X_add_number < 0x8000
3400 && (ep->X_add_number >= 0
3401 || (ep->X_add_number >= -0x8000
3404 || sizeof (ep->X_add_number) > 4))))
3406 /* We can handle 16 bit signed values with an addiu to
3407 $zero. No need to ever use daddiu here, since $zero and
3408 the result are always correct in 32 bit mode. */
3409 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3410 (int) BFD_RELOC_LO16);
3413 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3415 /* We can handle 16 bit unsigned values with an ori to
3417 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3418 (int) BFD_RELOC_LO16);
3421 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)
3424 || sizeof (ep->X_add_number) > 4
3425 || (ep->X_add_number & 0x80000000) == 0))
3426 || ((HAVE_32BIT_GPRS || ! dbl)
3427 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3430 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3431 == ~ (offsetT) 0xffffffff)))
3433 /* 32 bit values require an lui. */
3434 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3435 (int) BFD_RELOC_HI16);
3436 if ((ep->X_add_number & 0xffff) != 0)
3437 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3438 (int) BFD_RELOC_LO16);
3443 /* The value is larger than 32 bits. */
3445 if (HAVE_32BIT_GPRS)
3447 as_bad (_("Number (0x%lx) larger than 32 bits"),
3448 (unsigned long) ep->X_add_number);
3449 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3450 (int) BFD_RELOC_LO16);
3454 if (ep->X_op != O_big)
3457 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3458 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3459 hi32.X_add_number &= 0xffffffff;
3461 lo32.X_add_number &= 0xffffffff;
3465 assert (ep->X_add_number > 2);
3466 if (ep->X_add_number == 3)
3467 generic_bignum[3] = 0;
3468 else if (ep->X_add_number > 4)
3469 as_bad (_("Number larger than 64 bits"));
3470 lo32.X_op = O_constant;
3471 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3472 hi32.X_op = O_constant;
3473 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3476 if (hi32.X_add_number == 0)
3481 unsigned long hi, lo;
3483 if (hi32.X_add_number == (offsetT) 0xffffffff)
3485 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3487 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3488 reg, 0, (int) BFD_RELOC_LO16);
3491 if (lo32.X_add_number & 0x80000000)
3493 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3494 (int) BFD_RELOC_HI16);
3495 if (lo32.X_add_number & 0xffff)
3496 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3497 reg, reg, (int) BFD_RELOC_LO16);
3502 /* Check for 16bit shifted constant. We know that hi32 is
3503 non-zero, so start the mask on the first bit of the hi32
3508 unsigned long himask, lomask;
3512 himask = 0xffff >> (32 - shift);
3513 lomask = (0xffff << shift) & 0xffffffff;
3517 himask = 0xffff << (shift - 32);
3520 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3521 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3525 tmp.X_op = O_constant;
3527 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3528 | (lo32.X_add_number >> shift));
3530 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3531 macro_build ((char *) NULL, counter, &tmp,
3532 "ori", "t,r,i", reg, 0,
3533 (int) BFD_RELOC_LO16);
3534 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3535 (shift >= 32) ? "dsll32" : "dsll",
3537 (shift >= 32) ? shift - 32 : shift);
3542 while (shift <= (64 - 16));
3544 /* Find the bit number of the lowest one bit, and store the
3545 shifted value in hi/lo. */
3546 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3547 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3551 while ((lo & 1) == 0)
3556 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3562 while ((hi & 1) == 0)
3571 /* Optimize if the shifted value is a (power of 2) - 1. */
3572 if ((hi == 0 && ((lo + 1) & lo) == 0)
3573 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3575 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3580 /* This instruction will set the register to be all
3582 tmp.X_op = O_constant;
3583 tmp.X_add_number = (offsetT) -1;
3584 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3585 reg, 0, (int) BFD_RELOC_LO16);
3589 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3590 (bit >= 32) ? "dsll32" : "dsll",
3592 (bit >= 32) ? bit - 32 : bit);
3594 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3595 (shift >= 32) ? "dsrl32" : "dsrl",
3597 (shift >= 32) ? shift - 32 : shift);
3602 /* Sign extend hi32 before calling load_register, because we can
3603 generally get better code when we load a sign extended value. */
3604 if ((hi32.X_add_number & 0x80000000) != 0)
3605 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3606 load_register (counter, reg, &hi32, 0);
3609 if ((lo32.X_add_number & 0xffff0000) == 0)
3613 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3614 "dsll32", "d,w,<", reg, freg, 0);
3622 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3624 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3625 (int) BFD_RELOC_HI16);
3626 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3627 "dsrl32", "d,w,<", reg, reg, 0);
3633 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3634 "d,w,<", reg, freg, 16);
3638 mid16.X_add_number >>= 16;
3639 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3640 freg, (int) BFD_RELOC_LO16);
3641 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3642 "d,w,<", reg, reg, 16);
3645 if ((lo32.X_add_number & 0xffff) != 0)
3646 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3647 (int) BFD_RELOC_LO16);
3650 /* Load an address into a register. */
3653 load_address (counter, reg, ep, dbl, used_at)
3662 if (ep->X_op != O_constant
3663 && ep->X_op != O_symbol)
3665 as_bad (_("expression too complex"));
3666 ep->X_op = O_constant;
3669 if (ep->X_op == O_constant)
3671 load_register (counter, reg, ep, dbl);
3675 if (mips_pic == NO_PIC)
3677 /* If this is a reference to a GP relative symbol, we want
3678 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3680 lui $reg,<sym> (BFD_RELOC_HI16_S)
3681 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3682 If we have an addend, we always use the latter form.
3684 With 64bit address space and a usable $at we want
3685 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3686 lui $at,<sym> (BFD_RELOC_HI16_S)
3687 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3688 daddiu $at,<sym> (BFD_RELOC_LO16)
3692 If $at is already in use, we use an path which is suboptimal
3693 on superscalar processors.
3694 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3695 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3697 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3699 daddiu $reg,<sym> (BFD_RELOC_LO16)
3705 /* We don't do GP optimization for now because RELAX_ENCODE can't
3706 hold the data for such large chunks. */
3710 macro_build (p, counter, ep, "lui", "t,u",
3711 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3712 macro_build (p, counter, ep, "lui", "t,u",
3713 AT, (int) BFD_RELOC_HI16_S);
3714 macro_build (p, counter, ep, "daddiu", "t,r,j",
3715 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3716 macro_build (p, counter, ep, "daddiu", "t,r,j",
3717 AT, AT, (int) BFD_RELOC_LO16);
3718 macro_build (p, counter, (expressionS *) NULL, "dsll32",
3719 "d,w,<", reg, reg, 0);
3720 macro_build (p, counter, (expressionS *) NULL, "dadd",
3721 "d,v,t", reg, reg, AT);
3726 macro_build (p, counter, ep, "lui", "t,u",
3727 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3728 macro_build (p, counter, ep, "daddiu", "t,r,j",
3729 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3730 macro_build (p, counter, (expressionS *) NULL, "dsll",
3731 "d,w,<", reg, reg, 16);
3732 macro_build (p, counter, ep, "daddiu", "t,r,j",
3733 reg, reg, (int) BFD_RELOC_HI16_S);
3734 macro_build (p, counter, (expressionS *) NULL, "dsll",
3735 "d,w,<", reg, reg, 16);
3736 macro_build (p, counter, ep, "daddiu", "t,r,j",
3737 reg, reg, (int) BFD_RELOC_LO16);
3743 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3744 && ! nopic_need_relax (ep->X_add_symbol, 1))
3747 macro_build ((char *) NULL, counter, ep,
3748 dbl ? "daddiu" : "addiu", "t,r,j", reg, GP,
3749 (int) BFD_RELOC_GPREL16);
3750 p = frag_var (rs_machine_dependent, 8, 0,
3751 RELAX_ENCODE (4, 8, 0, 4, 0,
3752 mips_opts.warn_about_macros),
3753 ep->X_add_symbol, 0, NULL);
3755 macro_build_lui (p, counter, ep, reg);
3758 macro_build (p, counter, ep, dbl ? "daddiu" : "addiu",
3759 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3762 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3766 /* If this is a reference to an external symbol, we want
3767 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3769 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3771 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3772 If there is a constant, it must be added in after. */
3773 ex.X_add_number = ep->X_add_number;
3774 ep->X_add_number = 0;
3776 macro_build ((char *) NULL, counter, ep,
3777 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
3778 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3779 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3780 p = frag_var (rs_machine_dependent, 4, 0,
3781 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3782 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3783 macro_build (p, counter, ep,
3784 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3785 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3786 if (ex.X_add_number != 0)
3788 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3789 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3790 ex.X_op = O_constant;
3791 macro_build ((char *) NULL, counter, &ex,
3792 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3793 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3796 else if (mips_pic == SVR4_PIC)
3801 /* This is the large GOT case. If this is a reference to an
3802 external symbol, we want
3803 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3805 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3806 Otherwise, for a reference to a local symbol, we want
3807 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3809 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3810 If there is a constant, it must be added in after. */
3811 ex.X_add_number = ep->X_add_number;
3812 ep->X_add_number = 0;
3813 if (reg_needs_delay (GP))
3818 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3819 (int) BFD_RELOC_MIPS_GOT_HI16);
3820 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3821 dbl ? "daddu" : "addu", "d,v,t", reg, reg, GP);
3822 macro_build ((char *) NULL, counter, ep, dbl ? "ld" : "lw",
3823 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3824 p = frag_var (rs_machine_dependent, 12 + off, 0,
3825 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3826 mips_opts.warn_about_macros),
3827 ep->X_add_symbol, 0, NULL);
3830 /* We need a nop before loading from $gp. This special
3831 check is required because the lui which starts the main
3832 instruction stream does not refer to $gp, and so will not
3833 insert the nop which may be required. */
3834 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3837 macro_build (p, counter, ep, dbl ? "ld" : "lw",
3838 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3840 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3842 macro_build (p, counter, ep, dbl ? "daddiu" : "addiu",
3843 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3844 if (ex.X_add_number != 0)
3846 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3847 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3848 ex.X_op = O_constant;
3849 macro_build ((char *) NULL, counter, &ex, dbl ? "daddiu" : "addiu",
3850 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3853 else if (mips_pic == EMBEDDED_PIC)
3856 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3858 macro_build ((char *) NULL, counter, ep, dbl ? "daddiu" : "addiu",
3859 "t,r,j", reg, GP, (int) BFD_RELOC_GPREL16);
3865 /* Move the contents of register SOURCE into register DEST. */
3868 move_register (counter, dest, source)
3873 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3874 HAVE_32BIT_GPRS ? "addu" : "daddu",
3875 "d,v,t", dest, source, 0);
3880 * This routine implements the seemingly endless macro or synthesized
3881 * instructions and addressing modes in the mips assembly language. Many
3882 * of these macros are simple and are similar to each other. These could
3883 * probably be handled by some kind of table or grammer aproach instead of
3884 * this verbose method. Others are not simple macros but are more like
3885 * optimizing code generation.
3886 * One interesting optimization is when several store macros appear
3887 * consecutivly that would load AT with the upper half of the same address.
3888 * The ensuing load upper instructions are ommited. This implies some kind
3889 * of global optimization. We currently only optimize within a single macro.
3890 * For many of the load and store macros if the address is specified as a
3891 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3892 * first load register 'at' with zero and use it as the base register. The
3893 * mips assembler simply uses register $zero. Just one tiny optimization
3898 struct mips_cl_insn *ip;
3900 register int treg, sreg, dreg, breg;
3916 bfd_reloc_code_real_type r;
3918 int hold_mips_optimize;
3920 assert (! mips_opts.mips16);
3922 treg = (ip->insn_opcode >> 16) & 0x1f;
3923 dreg = (ip->insn_opcode >> 11) & 0x1f;
3924 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3925 mask = ip->insn_mo->mask;
3927 expr1.X_op = O_constant;
3928 expr1.X_op_symbol = NULL;
3929 expr1.X_add_symbol = NULL;
3930 expr1.X_add_number = 1;
3942 mips_emit_delays (true);
3943 ++mips_opts.noreorder;
3944 mips_any_noreorder = 1;
3946 expr1.X_add_number = 8;
3947 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3949 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
3952 move_register (&icnt, dreg, sreg);
3953 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3954 dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
3956 --mips_opts.noreorder;
3977 if (imm_expr.X_op == O_constant
3978 && imm_expr.X_add_number >= -0x8000
3979 && imm_expr.X_add_number < 0x8000)
3981 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3982 (int) BFD_RELOC_LO16);
3985 load_register (&icnt, AT, &imm_expr, dbl);
3986 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
4006 if (imm_expr.X_op == O_constant
4007 && imm_expr.X_add_number >= 0
4008 && imm_expr.X_add_number < 0x10000)
4010 if (mask != M_NOR_I)
4011 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
4012 sreg, (int) BFD_RELOC_LO16);
4015 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
4016 treg, sreg, (int) BFD_RELOC_LO16);
4017 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor",
4018 "d,v,t", treg, treg, 0);
4023 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4024 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
4042 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4044 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
4048 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4049 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
4057 macro_build ((char *) NULL, &icnt, &offset_expr,
4058 likely ? "bgezl" : "bgez", "s,p", sreg);
4063 macro_build ((char *) NULL, &icnt, &offset_expr,
4064 likely ? "blezl" : "blez", "s,p", treg);
4067 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4069 macro_build ((char *) NULL, &icnt, &offset_expr,
4070 likely ? "beql" : "beq", "s,t,p", AT, 0);
4076 /* check for > max integer */
4077 maxnum = 0x7fffffff;
4078 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4085 if (imm_expr.X_op == O_constant
4086 && imm_expr.X_add_number >= maxnum
4087 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4090 /* result is always false */
4094 as_warn (_("Branch %s is always false (nop)"),
4096 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop",
4102 as_warn (_("Branch likely %s is always false"),
4104 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
4109 if (imm_expr.X_op != O_constant)
4110 as_bad (_("Unsupported large constant"));
4111 imm_expr.X_add_number++;
4115 if (mask == M_BGEL_I)
4117 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4119 macro_build ((char *) NULL, &icnt, &offset_expr,
4120 likely ? "bgezl" : "bgez", "s,p", sreg);
4123 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4125 macro_build ((char *) NULL, &icnt, &offset_expr,
4126 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4129 maxnum = 0x7fffffff;
4130 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4137 maxnum = - maxnum - 1;
4138 if (imm_expr.X_op == O_constant
4139 && imm_expr.X_add_number <= maxnum
4140 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4143 /* result is always true */
4144 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4145 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4148 set_at (&icnt, sreg, 0);
4149 macro_build ((char *) NULL, &icnt, &offset_expr,
4150 likely ? "beql" : "beq", "s,t,p", AT, 0);
4160 macro_build ((char *) NULL, &icnt, &offset_expr,
4161 likely ? "beql" : "beq", "s,t,p", 0, treg);
4164 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4165 "d,v,t", AT, sreg, treg);
4166 macro_build ((char *) NULL, &icnt, &offset_expr,
4167 likely ? "beql" : "beq", "s,t,p", AT, 0);
4175 && imm_expr.X_op == O_constant
4176 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4178 if (imm_expr.X_op != O_constant)
4179 as_bad (_("Unsupported large constant"));
4180 imm_expr.X_add_number++;
4184 if (mask == M_BGEUL_I)
4186 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4188 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4190 macro_build ((char *) NULL, &icnt, &offset_expr,
4191 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4194 set_at (&icnt, sreg, 1);
4195 macro_build ((char *) NULL, &icnt, &offset_expr,
4196 likely ? "beql" : "beq", "s,t,p", AT, 0);
4204 macro_build ((char *) NULL, &icnt, &offset_expr,
4205 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4210 macro_build ((char *) NULL, &icnt, &offset_expr,
4211 likely ? "bltzl" : "bltz", "s,p", treg);
4214 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4216 macro_build ((char *) NULL, &icnt, &offset_expr,
4217 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4225 macro_build ((char *) NULL, &icnt, &offset_expr,
4226 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4231 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4232 "d,v,t", AT, treg, sreg);
4233 macro_build ((char *) NULL, &icnt, &offset_expr,
4234 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4242 macro_build ((char *) NULL, &icnt, &offset_expr,
4243 likely ? "blezl" : "blez", "s,p", sreg);
4248 macro_build ((char *) NULL, &icnt, &offset_expr,
4249 likely ? "bgezl" : "bgez", "s,p", treg);
4252 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4254 macro_build ((char *) NULL, &icnt, &offset_expr,
4255 likely ? "beql" : "beq", "s,t,p", AT, 0);
4261 maxnum = 0x7fffffff;
4262 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4269 if (imm_expr.X_op == O_constant
4270 && imm_expr.X_add_number >= maxnum
4271 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4273 if (imm_expr.X_op != O_constant)
4274 as_bad (_("Unsupported large constant"));
4275 imm_expr.X_add_number++;
4279 if (mask == M_BLTL_I)
4281 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4283 macro_build ((char *) NULL, &icnt, &offset_expr,
4284 likely ? "bltzl" : "bltz", "s,p", sreg);
4287 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4289 macro_build ((char *) NULL, &icnt, &offset_expr,
4290 likely ? "blezl" : "blez", "s,p", sreg);
4293 set_at (&icnt, sreg, 0);
4294 macro_build ((char *) NULL, &icnt, &offset_expr,
4295 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4303 macro_build ((char *) NULL, &icnt, &offset_expr,
4304 likely ? "beql" : "beq", "s,t,p", sreg, 0);
4309 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4310 "d,v,t", AT, treg, sreg);
4311 macro_build ((char *) NULL, &icnt, &offset_expr,
4312 likely ? "beql" : "beq", "s,t,p", AT, 0);
4320 && imm_expr.X_op == O_constant
4321 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4323 if (imm_expr.X_op != O_constant)
4324 as_bad (_("Unsupported large constant"));
4325 imm_expr.X_add_number++;
4329 if (mask == M_BLTUL_I)
4331 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4333 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4335 macro_build ((char *) NULL, &icnt, &offset_expr,
4336 likely ? "beql" : "beq",
4340 set_at (&icnt, sreg, 1);
4341 macro_build ((char *) NULL, &icnt, &offset_expr,
4342 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4350 macro_build ((char *) NULL, &icnt, &offset_expr,
4351 likely ? "bltzl" : "bltz", "s,p", sreg);
4356 macro_build ((char *) NULL, &icnt, &offset_expr,
4357 likely ? "bgtzl" : "bgtz", "s,p", treg);
4360 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4362 macro_build ((char *) NULL, &icnt, &offset_expr,
4363 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4373 macro_build ((char *) NULL, &icnt, &offset_expr,
4374 likely ? "bnel" : "bne", "s,t,p", 0, treg);
4377 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4380 macro_build ((char *) NULL, &icnt, &offset_expr,
4381 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4396 as_warn (_("Divide by zero."));
4398 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4401 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4406 mips_emit_delays (true);
4407 ++mips_opts.noreorder;
4408 mips_any_noreorder = 1;
4411 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4413 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4414 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4418 expr1.X_add_number = 8;
4419 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4420 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4421 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4422 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4425 expr1.X_add_number = -1;
4426 macro_build ((char *) NULL, &icnt, &expr1,
4427 dbl ? "daddiu" : "addiu",
4428 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
4429 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4430 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4433 expr1.X_add_number = 1;
4434 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4435 (int) BFD_RELOC_LO16);
4436 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32",
4437 "d,w,<", AT, AT, 31);
4441 expr1.X_add_number = 0x80000000;
4442 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4443 (int) BFD_RELOC_HI16);
4447 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4449 /* We want to close the noreorder block as soon as possible, so
4450 that later insns are available for delay slot filling. */
4451 --mips_opts.noreorder;
4455 expr1.X_add_number = 8;
4456 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4457 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4460 /* We want to close the noreorder block as soon as possible, so
4461 that later insns are available for delay slot filling. */
4462 --mips_opts.noreorder;
4464 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4467 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg);
4506 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4508 as_warn (_("Divide by zero."));
4510 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4513 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4517 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4519 if (strcmp (s2, "mflo") == 0)
4520 move_register (&icnt, dreg, sreg);
4522 move_register (&icnt, dreg, 0);
4525 if (imm_expr.X_op == O_constant
4526 && imm_expr.X_add_number == -1
4527 && s[strlen (s) - 1] != 'u')
4529 if (strcmp (s2, "mflo") == 0)
4531 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4532 dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4535 move_register (&icnt, dreg, 0);
4539 load_register (&icnt, AT, &imm_expr, dbl);
4540 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4542 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4561 mips_emit_delays (true);
4562 ++mips_opts.noreorder;
4563 mips_any_noreorder = 1;
4566 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4568 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4570 /* We want to close the noreorder block as soon as possible, so
4571 that later insns are available for delay slot filling. */
4572 --mips_opts.noreorder;
4576 expr1.X_add_number = 8;
4577 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4578 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4581 /* We want to close the noreorder block as soon as possible, so
4582 that later insns are available for delay slot filling. */
4583 --mips_opts.noreorder;
4584 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4587 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4593 /* Load the address of a symbol into a register. If breg is not
4594 zero, we then add a base register to it. */
4607 /* When generating embedded PIC code, we permit expressions of
4610 la $treg,foo-bar($breg)
4611 where bar is an address in the current section. These are used
4612 when getting the addresses of functions. We don't permit
4613 X_add_number to be non-zero, because if the symbol is
4614 external the relaxing code needs to know that any addend is
4615 purely the offset to X_op_symbol. */
4616 if (mips_pic == EMBEDDED_PIC
4617 && offset_expr.X_op == O_subtract
4618 && (symbol_constant_p (offset_expr.X_op_symbol)
4619 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4620 : (symbol_equated_p (offset_expr.X_op_symbol)
4622 (symbol_get_value_expression (offset_expr.X_op_symbol)
4625 && (offset_expr.X_add_number == 0
4626 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4632 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4633 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4637 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4638 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4639 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4640 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4641 "d,v,t", tempreg, tempreg, breg);
4643 macro_build ((char *) NULL, &icnt, &offset_expr,
4644 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4645 "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16);
4651 if (offset_expr.X_op != O_symbol
4652 && offset_expr.X_op != O_constant)
4654 as_bad (_("expression too complex"));
4655 offset_expr.X_op = O_constant;
4658 if (offset_expr.X_op == O_constant)
4659 load_register (&icnt, tempreg, &offset_expr,
4660 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4661 ? (dbl || HAVE_64BIT_ADDRESSES)
4662 : HAVE_64BIT_ADDRESSES));
4663 else if (mips_pic == NO_PIC)
4665 /* If this is a reference to a GP relative symbol, we want
4666 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4668 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4669 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4670 If we have a constant, we need two instructions anyhow,
4671 so we may as well always use the latter form.
4673 With 64bit address space and a usable $at we want
4674 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4675 lui $at,<sym> (BFD_RELOC_HI16_S)
4676 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4677 daddiu $at,<sym> (BFD_RELOC_LO16)
4679 dadd $tempreg,$tempreg,$at
4681 If $at is already in use, we use an path which is suboptimal
4682 on superscalar processors.
4683 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4684 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4686 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4688 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4691 if (HAVE_64BIT_ADDRESSES)
4693 /* We don't do GP optimization for now because RELAX_ENCODE can't
4694 hold the data for such large chunks. */
4698 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4699 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4700 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4701 AT, (int) BFD_RELOC_HI16_S);
4702 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4703 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4704 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4705 AT, AT, (int) BFD_RELOC_LO16);
4706 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
4707 "d,w,<", tempreg, tempreg, 0);
4708 macro_build (p, &icnt, (expressionS *) NULL, "dadd", "d,v,t",
4709 tempreg, tempreg, AT);
4714 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4715 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4716 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4717 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4718 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4719 tempreg, tempreg, 16);
4720 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4721 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
4722 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4723 tempreg, tempreg, 16);
4724 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4725 tempreg, tempreg, (int) BFD_RELOC_LO16);
4730 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4731 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4734 macro_build ((char *) NULL, &icnt, &offset_expr, "addiu",
4735 "t,r,j", tempreg, GP, (int) BFD_RELOC_GPREL16);
4736 p = frag_var (rs_machine_dependent, 8, 0,
4737 RELAX_ENCODE (4, 8, 0, 4, 0,
4738 mips_opts.warn_about_macros),
4739 offset_expr.X_add_symbol, 0, NULL);
4741 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4744 macro_build (p, &icnt, &offset_expr, "addiu",
4745 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4748 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4750 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4752 /* If this is a reference to an external symbol, and there
4753 is no constant, we want
4754 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4755 or if tempreg is PIC_CALL_REG
4756 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4757 For a local symbol, we want
4758 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4760 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4762 If we have a small constant, and this is a reference to
4763 an external symbol, we want
4764 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4766 addiu $tempreg,$tempreg,<constant>
4767 For a local symbol, we want the same instruction
4768 sequence, but we output a BFD_RELOC_LO16 reloc on the
4771 If we have a large constant, and this is a reference to
4772 an external symbol, we want
4773 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4774 lui $at,<hiconstant>
4775 addiu $at,$at,<loconstant>
4776 addu $tempreg,$tempreg,$at
4777 For a local symbol, we want the same instruction
4778 sequence, but we output a BFD_RELOC_LO16 reloc on the
4779 addiu instruction. */
4780 expr1.X_add_number = offset_expr.X_add_number;
4781 offset_expr.X_add_number = 0;
4783 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4784 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4785 macro_build ((char *) NULL, &icnt, &offset_expr,
4786 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4787 "t,o(b)", tempreg, lw_reloc_type, GP);
4788 if (expr1.X_add_number == 0)
4796 /* We're going to put in an addu instruction using
4797 tempreg, so we may as well insert the nop right
4799 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4803 p = frag_var (rs_machine_dependent, 8 - off, 0,
4804 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4806 ? mips_opts.warn_about_macros
4808 offset_expr.X_add_symbol, 0, NULL);
4811 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4814 macro_build (p, &icnt, &expr1,
4815 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4816 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4817 /* FIXME: If breg == 0, and the next instruction uses
4818 $tempreg, then if this variant case is used an extra
4819 nop will be generated. */
4821 else if (expr1.X_add_number >= -0x8000
4822 && expr1.X_add_number < 0x8000)
4824 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4826 macro_build ((char *) NULL, &icnt, &expr1,
4827 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4828 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4829 frag_var (rs_machine_dependent, 0, 0,
4830 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4831 offset_expr.X_add_symbol, 0, NULL);
4837 /* If we are going to add in a base register, and the
4838 target register and the base register are the same,
4839 then we are using AT as a temporary register. Since
4840 we want to load the constant into AT, we add our
4841 current AT (from the global offset table) and the
4842 register into the register now, and pretend we were
4843 not using a base register. */
4848 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4850 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4851 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4852 "d,v,t", treg, AT, breg);
4858 /* Set mips_optimize around the lui instruction to avoid
4859 inserting an unnecessary nop after the lw. */
4860 hold_mips_optimize = mips_optimize;
4862 macro_build_lui (NULL, &icnt, &expr1, AT);
4863 mips_optimize = hold_mips_optimize;
4865 macro_build ((char *) NULL, &icnt, &expr1,
4866 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4867 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4868 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4869 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4870 "d,v,t", tempreg, tempreg, AT);
4871 frag_var (rs_machine_dependent, 0, 0,
4872 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4873 offset_expr.X_add_symbol, 0, NULL);
4877 else if (mips_pic == SVR4_PIC)
4880 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
4881 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
4883 /* This is the large GOT case. If this is a reference to an
4884 external symbol, and there is no constant, we want
4885 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4886 addu $tempreg,$tempreg,$gp
4887 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4888 or if tempreg is PIC_CALL_REG
4889 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4890 addu $tempreg,$tempreg,$gp
4891 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4892 For a local symbol, we want
4893 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4895 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4897 If we have a small constant, and this is a reference to
4898 an external symbol, we want
4899 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4900 addu $tempreg,$tempreg,$gp
4901 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4903 addiu $tempreg,$tempreg,<constant>
4904 For a local symbol, we want
4905 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4907 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4909 If we have a large constant, and this is a reference to
4910 an external symbol, we want
4911 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4912 addu $tempreg,$tempreg,$gp
4913 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4914 lui $at,<hiconstant>
4915 addiu $at,$at,<loconstant>
4916 addu $tempreg,$tempreg,$at
4917 For a local symbol, we want
4918 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4919 lui $at,<hiconstant>
4920 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4921 addu $tempreg,$tempreg,$at
4923 expr1.X_add_number = offset_expr.X_add_number;
4924 offset_expr.X_add_number = 0;
4926 if (reg_needs_delay (GP))
4930 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4932 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
4933 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
4935 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4936 tempreg, lui_reloc_type);
4937 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4938 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4939 "d,v,t", tempreg, tempreg, GP);
4940 macro_build ((char *) NULL, &icnt, &offset_expr,
4941 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4942 "t,o(b)", tempreg, lw_reloc_type, tempreg);
4943 if (expr1.X_add_number == 0)
4951 /* We're going to put in an addu instruction using
4952 tempreg, so we may as well insert the nop right
4954 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4959 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4960 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4963 ? mips_opts.warn_about_macros
4965 offset_expr.X_add_symbol, 0, NULL);
4967 else if (expr1.X_add_number >= -0x8000
4968 && expr1.X_add_number < 0x8000)
4970 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4972 macro_build ((char *) NULL, &icnt, &expr1,
4973 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4974 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4976 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4977 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4979 ? mips_opts.warn_about_macros
4981 offset_expr.X_add_symbol, 0, NULL);
4987 /* If we are going to add in a base register, and the
4988 target register and the base register are the same,
4989 then we are using AT as a temporary register. Since
4990 we want to load the constant into AT, we add our
4991 current AT (from the global offset table) and the
4992 register into the register now, and pretend we were
4993 not using a base register. */
5001 assert (tempreg == AT);
5002 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5004 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5005 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5006 "d,v,t", treg, AT, breg);
5011 /* Set mips_optimize around the lui instruction to avoid
5012 inserting an unnecessary nop after the lw. */
5013 hold_mips_optimize = mips_optimize;
5015 macro_build_lui (NULL, &icnt, &expr1, AT);
5016 mips_optimize = hold_mips_optimize;
5018 macro_build ((char *) NULL, &icnt, &expr1,
5019 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5020 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5021 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5022 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5023 "d,v,t", dreg, dreg, AT);
5025 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
5026 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
5029 ? mips_opts.warn_about_macros
5031 offset_expr.X_add_symbol, 0, NULL);
5038 /* This is needed because this instruction uses $gp, but
5039 the first instruction on the main stream does not. */
5040 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5043 macro_build (p, &icnt, &offset_expr,
5044 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5045 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5047 if (expr1.X_add_number >= -0x8000
5048 && expr1.X_add_number < 0x8000)
5050 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5052 macro_build (p, &icnt, &expr1,
5053 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5054 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5055 /* FIXME: If add_number is 0, and there was no base
5056 register, the external symbol case ended with a load,
5057 so if the symbol turns out to not be external, and
5058 the next instruction uses tempreg, an unnecessary nop
5059 will be inserted. */
5065 /* We must add in the base register now, as in the
5066 external symbol case. */
5067 assert (tempreg == AT);
5068 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5070 macro_build (p, &icnt, (expressionS *) NULL,
5071 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5072 "d,v,t", treg, AT, breg);
5075 /* We set breg to 0 because we have arranged to add
5076 it in in both cases. */
5080 macro_build_lui (p, &icnt, &expr1, AT);
5082 macro_build (p, &icnt, &expr1,
5083 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5084 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
5086 macro_build (p, &icnt, (expressionS *) NULL,
5087 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5088 "d,v,t", tempreg, tempreg, AT);
5092 else if (mips_pic == EMBEDDED_PIC)
5095 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5097 macro_build ((char *) NULL, &icnt, &offset_expr,
5098 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5099 "t,r,j", tempreg, GP, (int) BFD_RELOC_GPREL16);
5108 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
5109 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu";
5111 s = HAVE_64BIT_ADDRESSES ? "daddu" : "addu";
5113 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
5114 "d,v,t", treg, tempreg, breg);
5123 /* The j instruction may not be used in PIC code, since it
5124 requires an absolute address. We convert it to a b
5126 if (mips_pic == NO_PIC)
5127 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
5129 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
5132 /* The jal instructions must be handled as macros because when
5133 generating PIC code they expand to multi-instruction
5134 sequences. Normally they are simple instructions. */
5139 if (mips_pic == NO_PIC
5140 || mips_pic == EMBEDDED_PIC)
5141 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5143 else if (mips_pic == SVR4_PIC)
5145 if (sreg != PIC_CALL_REG)
5146 as_warn (_("MIPS PIC call to register other than $25"));
5148 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5152 if (mips_cprestore_offset < 0)
5153 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5156 if (! mips_frame_reg_valid)
5158 as_warn (_("No .frame pseudo-op used in PIC code"));
5159 /* Quiet this warning. */
5160 mips_frame_reg_valid = 1;
5162 if (! mips_cprestore_valid)
5164 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5165 /* Quiet this warning. */
5166 mips_cprestore_valid = 1;
5168 expr1.X_add_number = mips_cprestore_offset;
5169 macro_build ((char *) NULL, &icnt, &expr1,
5170 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5171 GP, (int) BFD_RELOC_LO16, mips_frame_reg);
5181 if (mips_pic == NO_PIC)
5182 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
5183 else if (mips_pic == SVR4_PIC)
5185 /* If this is a reference to an external symbol, and we are
5186 using a small GOT, we want
5187 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5191 lw $gp,cprestore($sp)
5192 The cprestore value is set using the .cprestore
5193 pseudo-op. If we are using a big GOT, we want
5194 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5196 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5200 lw $gp,cprestore($sp)
5201 If the symbol is not external, we want
5202 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5204 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5207 lw $gp,cprestore($sp) */
5211 macro_build ((char *) NULL, &icnt, &offset_expr,
5212 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5213 "t,o(b)", PIC_CALL_REG,
5214 (int) BFD_RELOC_MIPS_CALL16, GP);
5215 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5217 p = frag_var (rs_machine_dependent, 4, 0,
5218 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5219 offset_expr.X_add_symbol, 0, NULL);
5225 if (reg_needs_delay (GP))
5229 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5230 PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16);
5231 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5232 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5233 "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP);
5234 macro_build ((char *) NULL, &icnt, &offset_expr,
5235 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5236 "t,o(b)", PIC_CALL_REG,
5237 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5238 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5240 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5241 RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel,
5243 offset_expr.X_add_symbol, 0, NULL);
5246 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5249 macro_build (p, &icnt, &offset_expr,
5250 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5251 "t,o(b)", PIC_CALL_REG,
5252 (int) BFD_RELOC_MIPS_GOT16, GP);
5254 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5257 macro_build (p, &icnt, &offset_expr,
5258 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5259 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5260 (int) BFD_RELOC_LO16);
5261 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5262 "jalr", "s", PIC_CALL_REG);
5265 if (mips_cprestore_offset < 0)
5266 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5269 if (! mips_frame_reg_valid)
5271 as_warn (_("No .frame pseudo-op used in PIC code"));
5272 /* Quiet this warning. */
5273 mips_frame_reg_valid = 1;
5275 if (! mips_cprestore_valid)
5277 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5278 /* Quiet this warning. */
5279 mips_cprestore_valid = 1;
5281 if (mips_opts.noreorder)
5282 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5284 expr1.X_add_number = mips_cprestore_offset;
5285 macro_build ((char *) NULL, &icnt, &expr1,
5286 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5287 GP, (int) BFD_RELOC_LO16, mips_frame_reg);
5291 else if (mips_pic == EMBEDDED_PIC)
5293 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
5294 /* The linker may expand the call to a longer sequence which
5295 uses $at, so we must break rather than return. */
5320 /* Itbl support may require additional care here. */
5325 /* Itbl support may require additional care here. */
5330 /* Itbl support may require additional care here. */
5335 /* Itbl support may require additional care here. */
5347 if (mips_arch == CPU_R4650)
5349 as_bad (_("opcode not supported on this processor"));
5353 /* Itbl support may require additional care here. */
5358 /* Itbl support may require additional care here. */
5363 /* Itbl support may require additional care here. */
5383 if (breg == treg || coproc || lr)
5405 /* Itbl support may require additional care here. */
5410 /* Itbl support may require additional care here. */
5415 /* Itbl support may require additional care here. */
5420 /* Itbl support may require additional care here. */
5436 if (mips_arch == CPU_R4650)
5438 as_bad (_("opcode not supported on this processor"));
5443 /* Itbl support may require additional care here. */
5447 /* Itbl support may require additional care here. */
5452 /* Itbl support may require additional care here. */
5464 /* Itbl support may require additional care here. */
5465 if (mask == M_LWC1_AB
5466 || mask == M_SWC1_AB
5467 || mask == M_LDC1_AB
5468 || mask == M_SDC1_AB
5477 /* For embedded PIC, we allow loads where the offset is calculated
5478 by subtracting a symbol in the current segment from an unknown
5479 symbol, relative to a base register, e.g.:
5480 <op> $treg, <sym>-<localsym>($breg)
5481 This is used by the compiler for switch statements. */
5482 if (mips_pic == EMBEDDED_PIC
5483 && offset_expr.X_op == O_subtract
5484 && (symbol_constant_p (offset_expr.X_op_symbol)
5485 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5486 : (symbol_equated_p (offset_expr.X_op_symbol)
5488 (symbol_get_value_expression (offset_expr.X_op_symbol)
5492 && (offset_expr.X_add_number == 0
5493 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5495 /* For this case, we output the instructions:
5496 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5497 addiu $tempreg,$tempreg,$breg
5498 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5499 If the relocation would fit entirely in 16 bits, it would be
5501 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5502 instead, but that seems quite difficult. */
5503 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5504 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
5505 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5506 ((bfd_arch_bits_per_address (stdoutput) == 32
5507 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5508 ? "addu" : "daddu"),
5509 "d,v,t", tempreg, tempreg, breg);
5510 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
5511 (int) BFD_RELOC_PCREL_LO16, tempreg);
5517 if (offset_expr.X_op != O_constant
5518 && offset_expr.X_op != O_symbol)
5520 as_bad (_("expression too complex"));
5521 offset_expr.X_op = O_constant;
5524 /* A constant expression in PIC code can be handled just as it
5525 is in non PIC code. */
5526 if (mips_pic == NO_PIC
5527 || offset_expr.X_op == O_constant)
5529 /* If this is a reference to a GP relative symbol, and there
5530 is no base register, we want
5531 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5532 Otherwise, if there is no base register, we want
5533 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5534 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5535 If we have a constant, we need two instructions anyhow,
5536 so we always use the latter form.
5538 If we have a base register, and this is a reference to a
5539 GP relative symbol, we want
5540 addu $tempreg,$breg,$gp
5541 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5543 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5544 addu $tempreg,$tempreg,$breg
5545 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5546 With a constant we always use the latter case.
5548 With 64bit address space and no base register and $at usable,
5550 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5551 lui $at,<sym> (BFD_RELOC_HI16_S)
5552 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5555 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5556 If we have a base register, we want
5557 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5558 lui $at,<sym> (BFD_RELOC_HI16_S)
5559 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5563 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5565 Without $at we can't generate the optimal path for superscalar
5566 processors here since this would require two temporary registers.
5567 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5568 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5570 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5572 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5573 If we have a base register, we want
5574 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5575 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5577 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5579 daddu $tempreg,$tempreg,$breg
5580 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5582 If we have 64-bit addresses, as an optimization, for
5583 addresses which are 32-bit constants (e.g. kseg0/kseg1
5584 addresses) we fall back to the 32-bit address generation
5585 mechanism since it is more efficient. This code should
5586 probably attempt to generate 64-bit constants more
5587 efficiently in general.
5589 if (HAVE_64BIT_ADDRESSES
5590 && !(offset_expr.X_op == O_constant
5591 && IS_SEXT_32BIT_NUM (offset_expr.X_add_number)))
5595 /* We don't do GP optimization for now because RELAX_ENCODE can't
5596 hold the data for such large chunks. */
5600 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5601 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5602 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5603 AT, (int) BFD_RELOC_HI16_S);
5604 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5605 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5607 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5608 "d,v,t", AT, AT, breg);
5609 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
5610 "d,w,<", tempreg, tempreg, 0);
5611 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5612 "d,v,t", tempreg, tempreg, AT);
5613 macro_build (p, &icnt, &offset_expr, s,
5614 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5619 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5620 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5621 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5622 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5623 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5624 "d,w,<", tempreg, tempreg, 16);
5625 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5626 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
5627 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5628 "d,w,<", tempreg, tempreg, 16);
5630 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5631 "d,v,t", tempreg, tempreg, breg);
5632 macro_build (p, &icnt, &offset_expr, s,
5633 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5641 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5642 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5647 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5648 treg, (int) BFD_RELOC_GPREL16, GP);
5649 p = frag_var (rs_machine_dependent, 8, 0,
5650 RELAX_ENCODE (4, 8, 0, 4, 0,
5651 (mips_opts.warn_about_macros
5653 && mips_opts.noat))),
5654 offset_expr.X_add_symbol, 0, NULL);
5657 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5660 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5661 (int) BFD_RELOC_LO16, tempreg);
5665 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5666 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5671 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5672 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5673 "d,v,t", tempreg, breg, GP);
5674 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5675 treg, (int) BFD_RELOC_GPREL16, tempreg);
5676 p = frag_var (rs_machine_dependent, 12, 0,
5677 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5678 offset_expr.X_add_symbol, 0, NULL);
5680 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5683 macro_build (p, &icnt, (expressionS *) NULL,
5684 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5685 "d,v,t", tempreg, tempreg, breg);
5688 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5689 (int) BFD_RELOC_LO16, tempreg);
5692 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5694 /* If this is a reference to an external symbol, we want
5695 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5697 <op> $treg,0($tempreg)
5699 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5701 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5702 <op> $treg,0($tempreg)
5703 If there is a base register, we add it to $tempreg before
5704 the <op>. If there is a constant, we stick it in the
5705 <op> instruction. We don't handle constants larger than
5706 16 bits, because we have no way to load the upper 16 bits
5707 (actually, we could handle them for the subset of cases
5708 in which we are not using $at). */
5709 assert (offset_expr.X_op == O_symbol);
5710 expr1.X_add_number = offset_expr.X_add_number;
5711 offset_expr.X_add_number = 0;
5712 if (expr1.X_add_number < -0x8000
5713 || expr1.X_add_number >= 0x8000)
5714 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5716 macro_build ((char *) NULL, &icnt, &offset_expr,
5717 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5718 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5719 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5720 p = frag_var (rs_machine_dependent, 4, 0,
5721 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5722 offset_expr.X_add_symbol, 0, NULL);
5723 macro_build (p, &icnt, &offset_expr,
5724 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5725 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5727 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5728 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5729 "d,v,t", tempreg, tempreg, breg);
5730 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5731 (int) BFD_RELOC_LO16, tempreg);
5733 else if (mips_pic == SVR4_PIC)
5737 /* If this is a reference to an external symbol, we want
5738 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5739 addu $tempreg,$tempreg,$gp
5740 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5741 <op> $treg,0($tempreg)
5743 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5745 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5746 <op> $treg,0($tempreg)
5747 If there is a base register, we add it to $tempreg before
5748 the <op>. If there is a constant, we stick it in the
5749 <op> instruction. We don't handle constants larger than
5750 16 bits, because we have no way to load the upper 16 bits
5751 (actually, we could handle them for the subset of cases
5752 in which we are not using $at). */
5753 assert (offset_expr.X_op == O_symbol);
5754 expr1.X_add_number = offset_expr.X_add_number;
5755 offset_expr.X_add_number = 0;
5756 if (expr1.X_add_number < -0x8000
5757 || expr1.X_add_number >= 0x8000)
5758 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5759 if (reg_needs_delay (GP))
5764 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5765 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5766 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5767 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5768 "d,v,t", tempreg, tempreg, GP);
5769 macro_build ((char *) NULL, &icnt, &offset_expr,
5770 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5771 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5773 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5774 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5775 offset_expr.X_add_symbol, 0, NULL);
5778 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5781 macro_build (p, &icnt, &offset_expr,
5782 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5783 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5785 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5787 macro_build (p, &icnt, &offset_expr,
5788 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5789 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5791 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5792 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5793 "d,v,t", tempreg, tempreg, breg);
5794 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5795 (int) BFD_RELOC_LO16, tempreg);
5797 else if (mips_pic == EMBEDDED_PIC)
5799 /* If there is no base register, we want
5800 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5801 If there is a base register, we want
5802 addu $tempreg,$breg,$gp
5803 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5805 assert (offset_expr.X_op == O_symbol);
5808 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5809 treg, (int) BFD_RELOC_GPREL16, GP);
5814 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5815 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5816 "d,v,t", tempreg, breg, GP);
5817 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5818 treg, (int) BFD_RELOC_GPREL16, tempreg);
5831 load_register (&icnt, treg, &imm_expr, 0);
5835 load_register (&icnt, treg, &imm_expr, 1);
5839 if (imm_expr.X_op == O_constant)
5841 load_register (&icnt, AT, &imm_expr, 0);
5842 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5843 "mtc1", "t,G", AT, treg);
5848 assert (offset_expr.X_op == O_symbol
5849 && strcmp (segment_name (S_GET_SEGMENT
5850 (offset_expr.X_add_symbol)),
5852 && offset_expr.X_add_number == 0);
5853 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5854 treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5859 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
5860 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
5861 order 32 bits of the value and the low order 32 bits are either
5862 zero or in OFFSET_EXPR. */
5863 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5865 if (HAVE_64BIT_GPRS)
5866 load_register (&icnt, treg, &imm_expr, 1);
5871 if (target_big_endian)
5883 load_register (&icnt, hreg, &imm_expr, 0);
5886 if (offset_expr.X_op == O_absent)
5887 move_register (&icnt, lreg, 0);
5890 assert (offset_expr.X_op == O_constant);
5891 load_register (&icnt, lreg, &offset_expr, 0);
5898 /* We know that sym is in the .rdata section. First we get the
5899 upper 16 bits of the address. */
5900 if (mips_pic == NO_PIC)
5902 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5904 else if (mips_pic == SVR4_PIC)
5906 macro_build ((char *) NULL, &icnt, &offset_expr,
5907 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5908 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5910 else if (mips_pic == EMBEDDED_PIC)
5912 /* For embedded PIC we pick up the entire address off $gp in
5913 a single instruction. */
5914 macro_build ((char *) NULL, &icnt, &offset_expr,
5915 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5916 "t,r,j", AT, GP, (int) BFD_RELOC_GPREL16);
5917 offset_expr.X_op = O_constant;
5918 offset_expr.X_add_number = 0;
5923 /* Now we load the register(s). */
5924 if (HAVE_64BIT_GPRS)
5925 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5926 treg, (int) BFD_RELOC_LO16, AT);
5929 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5930 treg, (int) BFD_RELOC_LO16, AT);
5933 /* FIXME: How in the world do we deal with the possible
5935 offset_expr.X_add_number += 4;
5936 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5937 treg + 1, (int) BFD_RELOC_LO16, AT);
5941 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5942 does not become a variant frag. */
5943 frag_wane (frag_now);
5949 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
5950 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
5951 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
5952 the value and the low order 32 bits are either zero or in
5954 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5956 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
5957 if (HAVE_64BIT_FPRS)
5959 assert (HAVE_64BIT_GPRS);
5960 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5961 "dmtc1", "t,S", AT, treg);
5965 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5966 "mtc1", "t,G", AT, treg + 1);
5967 if (offset_expr.X_op == O_absent)
5968 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5969 "mtc1", "t,G", 0, treg);
5972 assert (offset_expr.X_op == O_constant);
5973 load_register (&icnt, AT, &offset_expr, 0);
5974 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5975 "mtc1", "t,G", AT, treg);
5981 assert (offset_expr.X_op == O_symbol
5982 && offset_expr.X_add_number == 0);
5983 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5984 if (strcmp (s, ".lit8") == 0)
5986 if (mips_opts.isa != ISA_MIPS1)
5988 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5989 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5993 r = BFD_RELOC_MIPS_LITERAL;
5998 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5999 if (mips_pic == SVR4_PIC)
6000 macro_build ((char *) NULL, &icnt, &offset_expr,
6001 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6002 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
6005 /* FIXME: This won't work for a 64 bit address. */
6006 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6009 if (mips_opts.isa != ISA_MIPS1)
6011 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
6012 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
6014 /* To avoid confusion in tc_gen_reloc, we must ensure
6015 that this does not become a variant frag. */
6016 frag_wane (frag_now);
6027 if (mips_arch == CPU_R4650)
6029 as_bad (_("opcode not supported on this processor"));
6032 /* Even on a big endian machine $fn comes before $fn+1. We have
6033 to adjust when loading from memory. */
6036 assert (mips_opts.isa == ISA_MIPS1);
6037 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6038 target_big_endian ? treg + 1 : treg,
6040 /* FIXME: A possible overflow which I don't know how to deal
6042 offset_expr.X_add_number += 4;
6043 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6044 target_big_endian ? treg : treg + 1,
6047 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6048 does not become a variant frag. */
6049 frag_wane (frag_now);
6058 * The MIPS assembler seems to check for X_add_number not
6059 * being double aligned and generating:
6062 * addiu at,at,%lo(foo+1)
6065 * But, the resulting address is the same after relocation so why
6066 * generate the extra instruction?
6068 if (mips_arch == CPU_R4650)
6070 as_bad (_("opcode not supported on this processor"));
6073 /* Itbl support may require additional care here. */
6075 if (mips_opts.isa != ISA_MIPS1)
6086 if (mips_arch == CPU_R4650)
6088 as_bad (_("opcode not supported on this processor"));
6092 if (mips_opts.isa != ISA_MIPS1)
6100 /* Itbl support may require additional care here. */
6105 if (HAVE_64BIT_GPRS)
6116 if (HAVE_64BIT_GPRS)
6126 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6127 loads for the case of doing a pair of loads to simulate an 'ld'.
6128 This is not currently done by the compiler, and assembly coders
6129 writing embedded-pic code can cope. */
6131 if (offset_expr.X_op != O_symbol
6132 && offset_expr.X_op != O_constant)
6134 as_bad (_("expression too complex"));
6135 offset_expr.X_op = O_constant;
6138 /* Even on a big endian machine $fn comes before $fn+1. We have
6139 to adjust when loading from memory. We set coproc if we must
6140 load $fn+1 first. */
6141 /* Itbl support may require additional care here. */
6142 if (! target_big_endian)
6145 if (mips_pic == NO_PIC
6146 || offset_expr.X_op == O_constant)
6148 /* If this is a reference to a GP relative symbol, we want
6149 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6150 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6151 If we have a base register, we use this
6153 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6154 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6155 If this is not a GP relative symbol, we want
6156 lui $at,<sym> (BFD_RELOC_HI16_S)
6157 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6158 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6159 If there is a base register, we add it to $at after the
6160 lui instruction. If there is a constant, we always use
6162 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6163 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6182 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6183 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6184 "d,v,t", AT, breg, GP);
6190 /* Itbl support may require additional care here. */
6191 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6192 coproc ? treg + 1 : treg,
6193 (int) BFD_RELOC_GPREL16, tempreg);
6194 offset_expr.X_add_number += 4;
6196 /* Set mips_optimize to 2 to avoid inserting an
6198 hold_mips_optimize = mips_optimize;
6200 /* Itbl support may require additional care here. */
6201 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6202 coproc ? treg : treg + 1,
6203 (int) BFD_RELOC_GPREL16, tempreg);
6204 mips_optimize = hold_mips_optimize;
6206 p = frag_var (rs_machine_dependent, 12 + off, 0,
6207 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6208 used_at && mips_opts.noat),
6209 offset_expr.X_add_symbol, 0, NULL);
6211 /* We just generated two relocs. When tc_gen_reloc
6212 handles this case, it will skip the first reloc and
6213 handle the second. The second reloc already has an
6214 extra addend of 4, which we added above. We must
6215 subtract it out, and then subtract another 4 to make
6216 the first reloc come out right. The second reloc
6217 will come out right because we are going to add 4 to
6218 offset_expr when we build its instruction below.
6220 If we have a symbol, then we don't want to include
6221 the offset, because it will wind up being included
6222 when we generate the reloc. */
6224 if (offset_expr.X_op == O_constant)
6225 offset_expr.X_add_number -= 8;
6228 offset_expr.X_add_number = -4;
6229 offset_expr.X_op = O_constant;
6232 macro_build_lui (p, &icnt, &offset_expr, AT);
6237 macro_build (p, &icnt, (expressionS *) NULL,
6238 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6239 "d,v,t", AT, breg, AT);
6243 /* Itbl support may require additional care here. */
6244 macro_build (p, &icnt, &offset_expr, s, fmt,
6245 coproc ? treg + 1 : treg,
6246 (int) BFD_RELOC_LO16, AT);
6249 /* FIXME: How do we handle overflow here? */
6250 offset_expr.X_add_number += 4;
6251 /* Itbl support may require additional care here. */
6252 macro_build (p, &icnt, &offset_expr, s, fmt,
6253 coproc ? treg : treg + 1,
6254 (int) BFD_RELOC_LO16, AT);
6256 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6260 /* If this is a reference to an external symbol, we want
6261 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6266 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6268 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6269 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6270 If there is a base register we add it to $at before the
6271 lwc1 instructions. If there is a constant we include it
6272 in the lwc1 instructions. */
6274 expr1.X_add_number = offset_expr.X_add_number;
6275 offset_expr.X_add_number = 0;
6276 if (expr1.X_add_number < -0x8000
6277 || expr1.X_add_number >= 0x8000 - 4)
6278 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6283 frag_grow (24 + off);
6284 macro_build ((char *) NULL, &icnt, &offset_expr,
6285 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6286 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
6287 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6289 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6290 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6291 "d,v,t", AT, breg, AT);
6292 /* Itbl support may require additional care here. */
6293 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6294 coproc ? treg + 1 : treg,
6295 (int) BFD_RELOC_LO16, AT);
6296 expr1.X_add_number += 4;
6298 /* Set mips_optimize to 2 to avoid inserting an undesired
6300 hold_mips_optimize = mips_optimize;
6302 /* Itbl support may require additional care here. */
6303 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6304 coproc ? treg : treg + 1,
6305 (int) BFD_RELOC_LO16, AT);
6306 mips_optimize = hold_mips_optimize;
6308 (void) frag_var (rs_machine_dependent, 0, 0,
6309 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6310 offset_expr.X_add_symbol, 0, NULL);
6312 else if (mips_pic == SVR4_PIC)
6316 /* If this is a reference to an external symbol, we want
6317 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6319 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6324 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6326 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6327 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6328 If there is a base register we add it to $at before the
6329 lwc1 instructions. If there is a constant we include it
6330 in the lwc1 instructions. */
6332 expr1.X_add_number = offset_expr.X_add_number;
6333 offset_expr.X_add_number = 0;
6334 if (expr1.X_add_number < -0x8000
6335 || expr1.X_add_number >= 0x8000 - 4)
6336 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6337 if (reg_needs_delay (GP))
6346 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6347 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
6348 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6349 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6350 "d,v,t", AT, AT, GP);
6351 macro_build ((char *) NULL, &icnt, &offset_expr,
6352 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6353 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
6354 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6356 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6357 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6358 "d,v,t", AT, breg, AT);
6359 /* Itbl support may require additional care here. */
6360 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6361 coproc ? treg + 1 : treg,
6362 (int) BFD_RELOC_LO16, AT);
6363 expr1.X_add_number += 4;
6365 /* Set mips_optimize to 2 to avoid inserting an undesired
6367 hold_mips_optimize = mips_optimize;
6369 /* Itbl support may require additional care here. */
6370 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6371 coproc ? treg : treg + 1,
6372 (int) BFD_RELOC_LO16, AT);
6373 mips_optimize = hold_mips_optimize;
6374 expr1.X_add_number -= 4;
6376 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6377 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6378 8 + gpdel + off, 1, 0),
6379 offset_expr.X_add_symbol, 0, NULL);
6382 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6385 macro_build (p, &icnt, &offset_expr,
6386 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6387 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
6389 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6393 macro_build (p, &icnt, (expressionS *) NULL,
6394 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6395 "d,v,t", AT, breg, AT);
6398 /* Itbl support may require additional care here. */
6399 macro_build (p, &icnt, &expr1, s, fmt,
6400 coproc ? treg + 1 : treg,
6401 (int) BFD_RELOC_LO16, AT);
6403 expr1.X_add_number += 4;
6405 /* Set mips_optimize to 2 to avoid inserting an undesired
6407 hold_mips_optimize = mips_optimize;
6409 /* Itbl support may require additional care here. */
6410 macro_build (p, &icnt, &expr1, s, fmt,
6411 coproc ? treg : treg + 1,
6412 (int) BFD_RELOC_LO16, AT);
6413 mips_optimize = hold_mips_optimize;
6415 else if (mips_pic == EMBEDDED_PIC)
6417 /* If there is no base register, we use
6418 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6419 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6420 If we have a base register, we use
6422 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6423 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6432 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6433 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6434 "d,v,t", AT, breg, GP);
6439 /* Itbl support may require additional care here. */
6440 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6441 coproc ? treg + 1 : treg,
6442 (int) BFD_RELOC_GPREL16, tempreg);
6443 offset_expr.X_add_number += 4;
6444 /* Itbl support may require additional care here. */
6445 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6446 coproc ? treg : treg + 1,
6447 (int) BFD_RELOC_GPREL16, tempreg);
6463 assert (HAVE_32BIT_ADDRESSES);
6464 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6465 (int) BFD_RELOC_LO16, breg);
6466 offset_expr.X_add_number += 4;
6467 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
6468 (int) BFD_RELOC_LO16, breg);
6471 /* New code added to support COPZ instructions.
6472 This code builds table entries out of the macros in mip_opcodes.
6473 R4000 uses interlocks to handle coproc delays.
6474 Other chips (like the R3000) require nops to be inserted for delays.
6476 FIXME: Currently, we require that the user handle delays.
6477 In order to fill delay slots for non-interlocked chips,
6478 we must have a way to specify delays based on the coprocessor.
6479 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6480 What are the side-effects of the cop instruction?
6481 What cache support might we have and what are its effects?
6482 Both coprocessor & memory require delays. how long???
6483 What registers are read/set/modified?
6485 If an itbl is provided to interpret cop instructions,
6486 this knowledge can be encoded in the itbl spec. */
6500 /* For now we just do C (same as Cz). The parameter will be
6501 stored in insn_opcode by mips_ip. */
6502 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
6507 move_register (&icnt, dreg, sreg);
6510 #ifdef LOSING_COMPILER
6512 /* Try and see if this is a new itbl instruction.
6513 This code builds table entries out of the macros in mip_opcodes.
6514 FIXME: For now we just assemble the expression and pass it's
6515 value along as a 32-bit immediate.
6516 We may want to have the assembler assemble this value,
6517 so that we gain the assembler's knowledge of delay slots,
6519 Would it be more efficient to use mask (id) here? */
6520 if (itbl_have_entries
6521 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6523 s = ip->insn_mo->name;
6525 coproc = ITBL_DECODE_PNUM (immed_expr);;
6526 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
6533 as_warn (_("Macro used $at after \".set noat\""));
6538 struct mips_cl_insn *ip;
6540 register int treg, sreg, dreg, breg;
6556 bfd_reloc_code_real_type r;
6559 treg = (ip->insn_opcode >> 16) & 0x1f;
6560 dreg = (ip->insn_opcode >> 11) & 0x1f;
6561 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6562 mask = ip->insn_mo->mask;
6564 expr1.X_op = O_constant;
6565 expr1.X_op_symbol = NULL;
6566 expr1.X_add_symbol = NULL;
6567 expr1.X_add_number = 1;
6571 #endif /* LOSING_COMPILER */
6576 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6577 dbl ? "dmultu" : "multu", "s,t", sreg, treg);
6578 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6585 /* The MIPS assembler some times generates shifts and adds. I'm
6586 not trying to be that fancy. GCC should do this for us
6588 load_register (&icnt, AT, &imm_expr, dbl);
6589 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6590 dbl ? "dmult" : "mult", "s,t", sreg, AT);
6591 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6605 mips_emit_delays (true);
6606 ++mips_opts.noreorder;
6607 mips_any_noreorder = 1;
6609 load_register (&icnt, AT, &imm_expr, dbl);
6610 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6611 dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
6612 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6614 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6615 dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, 31);
6616 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6619 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6623 expr1.X_add_number = 8;
6624 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg,
6626 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6628 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6631 --mips_opts.noreorder;
6632 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg);
6645 mips_emit_delays (true);
6646 ++mips_opts.noreorder;
6647 mips_any_noreorder = 1;
6649 load_register (&icnt, AT, &imm_expr, dbl);
6650 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6651 dbl ? "dmultu" : "multu",
6652 "s,t", sreg, imm ? AT : treg);
6653 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6655 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6658 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6662 expr1.X_add_number = 8;
6663 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6664 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6666 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6669 --mips_opts.noreorder;
6673 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6674 "d,v,t", AT, 0, treg);
6675 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6676 "d,t,s", AT, sreg, AT);
6677 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6678 "d,t,s", dreg, sreg, treg);
6679 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6680 "d,v,t", dreg, dreg, AT);
6684 if (imm_expr.X_op != O_constant)
6685 as_bad (_("rotate count too large"));
6686 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
6687 AT, sreg, (int) (imm_expr.X_add_number & 0x1f));
6688 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
6689 dreg, sreg, (int) ((0 - imm_expr.X_add_number) & 0x1f));
6690 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
6695 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6696 "d,v,t", AT, 0, treg);
6697 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6698 "d,t,s", AT, sreg, AT);
6699 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6700 "d,t,s", dreg, sreg, treg);
6701 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6702 "d,v,t", dreg, dreg, AT);
6706 if (imm_expr.X_op != O_constant)
6707 as_bad (_("rotate count too large"));
6708 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
6709 AT, sreg, (int) (imm_expr.X_add_number & 0x1f));
6710 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
6711 dreg, sreg, (int) ((0 - imm_expr.X_add_number) & 0x1f));
6712 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
6717 if (mips_arch == CPU_R4650)
6719 as_bad (_("opcode not supported on this processor"));
6722 assert (mips_opts.isa == ISA_MIPS1);
6723 /* Even on a big endian machine $fn comes before $fn+1. We have
6724 to adjust when storing to memory. */
6725 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6726 target_big_endian ? treg + 1 : treg,
6727 (int) BFD_RELOC_LO16, breg);
6728 offset_expr.X_add_number += 4;
6729 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6730 target_big_endian ? treg : treg + 1,
6731 (int) BFD_RELOC_LO16, breg);
6736 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6737 treg, (int) BFD_RELOC_LO16);
6739 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6740 sreg, (int) BFD_RELOC_LO16);
6743 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6744 "d,v,t", dreg, sreg, treg);
6745 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6746 dreg, (int) BFD_RELOC_LO16);
6751 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6753 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6754 sreg, (int) BFD_RELOC_LO16);
6759 as_warn (_("Instruction %s: result is always false"),
6761 move_register (&icnt, dreg, 0);
6764 if (imm_expr.X_op == O_constant
6765 && imm_expr.X_add_number >= 0
6766 && imm_expr.X_add_number < 0x10000)
6768 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6769 sreg, (int) BFD_RELOC_LO16);
6772 else if (imm_expr.X_op == O_constant
6773 && imm_expr.X_add_number > -0x8000
6774 && imm_expr.X_add_number < 0)
6776 imm_expr.X_add_number = -imm_expr.X_add_number;
6777 macro_build ((char *) NULL, &icnt, &imm_expr,
6778 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6779 "t,r,j", dreg, sreg,
6780 (int) BFD_RELOC_LO16);
6785 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6786 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6787 "d,v,t", dreg, sreg, AT);
6790 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6791 (int) BFD_RELOC_LO16);
6796 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6802 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6804 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6805 (int) BFD_RELOC_LO16);
6808 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6810 if (imm_expr.X_op == O_constant
6811 && imm_expr.X_add_number >= -0x8000
6812 && imm_expr.X_add_number < 0x8000)
6814 macro_build ((char *) NULL, &icnt, &imm_expr,
6815 mask == M_SGE_I ? "slti" : "sltiu",
6816 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6821 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6822 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6823 mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg,
6827 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6828 (int) BFD_RELOC_LO16);
6833 case M_SGT: /* sreg > treg <==> treg < sreg */
6839 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6843 case M_SGT_I: /* sreg > I <==> I < sreg */
6849 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6850 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6854 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6860 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6862 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6863 (int) BFD_RELOC_LO16);
6866 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6872 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6873 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6875 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6876 (int) BFD_RELOC_LO16);
6880 if (imm_expr.X_op == O_constant
6881 && imm_expr.X_add_number >= -0x8000
6882 && imm_expr.X_add_number < 0x8000)
6884 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
6885 dreg, sreg, (int) BFD_RELOC_LO16);
6888 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6889 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
6894 if (imm_expr.X_op == O_constant
6895 && imm_expr.X_add_number >= -0x8000
6896 && imm_expr.X_add_number < 0x8000)
6898 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
6899 dreg, sreg, (int) BFD_RELOC_LO16);
6902 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6903 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6904 "d,v,t", dreg, sreg, AT);
6909 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6910 "d,v,t", dreg, 0, treg);
6912 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6913 "d,v,t", dreg, 0, sreg);
6916 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6917 "d,v,t", dreg, sreg, treg);
6918 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6919 "d,v,t", dreg, 0, dreg);
6924 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6926 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6927 "d,v,t", dreg, 0, sreg);
6932 as_warn (_("Instruction %s: result is always true"),
6934 macro_build ((char *) NULL, &icnt, &expr1,
6935 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6936 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
6939 if (imm_expr.X_op == O_constant
6940 && imm_expr.X_add_number >= 0
6941 && imm_expr.X_add_number < 0x10000)
6943 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
6944 dreg, sreg, (int) BFD_RELOC_LO16);
6947 else if (imm_expr.X_op == O_constant
6948 && imm_expr.X_add_number > -0x8000
6949 && imm_expr.X_add_number < 0)
6951 imm_expr.X_add_number = -imm_expr.X_add_number;
6952 macro_build ((char *) NULL, &icnt, &imm_expr,
6953 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6954 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6959 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6960 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6961 "d,v,t", dreg, sreg, AT);
6964 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6965 "d,v,t", dreg, 0, dreg);
6973 if (imm_expr.X_op == O_constant
6974 && imm_expr.X_add_number > -0x8000
6975 && imm_expr.X_add_number <= 0x8000)
6977 imm_expr.X_add_number = -imm_expr.X_add_number;
6978 macro_build ((char *) NULL, &icnt, &imm_expr,
6979 dbl ? "daddi" : "addi",
6980 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6983 load_register (&icnt, AT, &imm_expr, dbl);
6984 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6985 dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
6991 if (imm_expr.X_op == O_constant
6992 && imm_expr.X_add_number > -0x8000
6993 && imm_expr.X_add_number <= 0x8000)
6995 imm_expr.X_add_number = -imm_expr.X_add_number;
6996 macro_build ((char *) NULL, &icnt, &imm_expr,
6997 dbl ? "daddiu" : "addiu",
6998 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7001 load_register (&icnt, AT, &imm_expr, dbl);
7002 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7003 dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
7024 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7025 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg,
7031 assert (mips_opts.isa == ISA_MIPS1);
7032 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7033 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7036 * Is the double cfc1 instruction a bug in the mips assembler;
7037 * or is there a reason for it?
7039 mips_emit_delays (true);
7040 ++mips_opts.noreorder;
7041 mips_any_noreorder = 1;
7042 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7044 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7046 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7047 expr1.X_add_number = 3;
7048 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7049 (int) BFD_RELOC_LO16);
7050 expr1.X_add_number = 2;
7051 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7052 (int) BFD_RELOC_LO16);
7053 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7055 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7056 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7057 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
7058 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7060 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7061 --mips_opts.noreorder;
7070 if (offset_expr.X_add_number >= 0x7fff)
7071 as_bad (_("operand overflow"));
7072 /* avoid load delay */
7073 if (! target_big_endian)
7074 offset_expr.X_add_number += 1;
7075 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7076 (int) BFD_RELOC_LO16, breg);
7077 if (! target_big_endian)
7078 offset_expr.X_add_number -= 1;
7080 offset_expr.X_add_number += 1;
7081 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
7082 (int) BFD_RELOC_LO16, breg);
7083 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7085 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7099 if (offset_expr.X_add_number >= 0x8000 - off)
7100 as_bad (_("operand overflow"));
7101 if (! target_big_endian)
7102 offset_expr.X_add_number += off;
7103 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7104 (int) BFD_RELOC_LO16, breg);
7105 if (! target_big_endian)
7106 offset_expr.X_add_number -= off;
7108 offset_expr.X_add_number += off;
7109 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7110 (int) BFD_RELOC_LO16, breg);
7124 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7126 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7127 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7128 "d,v,t", AT, AT, breg);
7129 if (! target_big_endian)
7130 expr1.X_add_number = off;
7132 expr1.X_add_number = 0;
7133 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7134 (int) BFD_RELOC_LO16, AT);
7135 if (! target_big_endian)
7136 expr1.X_add_number = 0;
7138 expr1.X_add_number = off;
7139 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7140 (int) BFD_RELOC_LO16, AT);
7146 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7148 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7149 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7150 "d,v,t", AT, AT, breg);
7151 if (target_big_endian)
7152 expr1.X_add_number = 0;
7153 macro_build ((char *) NULL, &icnt, &expr1,
7154 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
7155 (int) BFD_RELOC_LO16, AT);
7156 if (target_big_endian)
7157 expr1.X_add_number = 1;
7159 expr1.X_add_number = 0;
7160 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7161 (int) BFD_RELOC_LO16, AT);
7162 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7164 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7169 if (offset_expr.X_add_number >= 0x7fff)
7170 as_bad (_("operand overflow"));
7171 if (target_big_endian)
7172 offset_expr.X_add_number += 1;
7173 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7174 (int) BFD_RELOC_LO16, breg);
7175 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7177 if (target_big_endian)
7178 offset_expr.X_add_number -= 1;
7180 offset_expr.X_add_number += 1;
7181 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7182 (int) BFD_RELOC_LO16, breg);
7195 if (offset_expr.X_add_number >= 0x8000 - off)
7196 as_bad (_("operand overflow"));
7197 if (! target_big_endian)
7198 offset_expr.X_add_number += off;
7199 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7200 (int) BFD_RELOC_LO16, breg);
7201 if (! target_big_endian)
7202 offset_expr.X_add_number -= off;
7204 offset_expr.X_add_number += off;
7205 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7206 (int) BFD_RELOC_LO16, breg);
7220 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7222 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7223 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7224 "d,v,t", AT, AT, breg);
7225 if (! target_big_endian)
7226 expr1.X_add_number = off;
7228 expr1.X_add_number = 0;
7229 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7230 (int) BFD_RELOC_LO16, AT);
7231 if (! target_big_endian)
7232 expr1.X_add_number = 0;
7234 expr1.X_add_number = off;
7235 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7236 (int) BFD_RELOC_LO16, AT);
7241 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7243 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7244 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7245 "d,v,t", AT, AT, breg);
7246 if (! target_big_endian)
7247 expr1.X_add_number = 0;
7248 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7249 (int) BFD_RELOC_LO16, AT);
7250 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7252 if (! target_big_endian)
7253 expr1.X_add_number = 1;
7255 expr1.X_add_number = 0;
7256 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7257 (int) BFD_RELOC_LO16, AT);
7258 if (! target_big_endian)
7259 expr1.X_add_number = 0;
7261 expr1.X_add_number = 1;
7262 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7263 (int) BFD_RELOC_LO16, AT);
7264 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7266 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7271 /* FIXME: Check if this is one of the itbl macros, since they
7272 are added dynamically. */
7273 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7277 as_warn (_("Macro used $at after \".set noat\""));
7280 /* Implement macros in mips16 mode. */
7284 struct mips_cl_insn *ip;
7287 int xreg, yreg, zreg, tmp;
7291 const char *s, *s2, *s3;
7293 mask = ip->insn_mo->mask;
7295 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7296 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7297 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7301 expr1.X_op = O_constant;
7302 expr1.X_op_symbol = NULL;
7303 expr1.X_add_symbol = NULL;
7304 expr1.X_add_number = 1;
7323 mips_emit_delays (true);
7324 ++mips_opts.noreorder;
7325 mips_any_noreorder = 1;
7326 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7327 dbl ? "ddiv" : "div",
7328 "0,x,y", xreg, yreg);
7329 expr1.X_add_number = 2;
7330 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7331 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6",
7334 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7335 since that causes an overflow. We should do that as well,
7336 but I don't see how to do the comparisons without a temporary
7338 --mips_opts.noreorder;
7339 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg);
7358 mips_emit_delays (true);
7359 ++mips_opts.noreorder;
7360 mips_any_noreorder = 1;
7361 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y",
7363 expr1.X_add_number = 2;
7364 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7365 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7367 --mips_opts.noreorder;
7368 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg);
7374 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7375 dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7376 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x",
7385 if (imm_expr.X_op != O_constant)
7386 as_bad (_("Unsupported large constant"));
7387 imm_expr.X_add_number = -imm_expr.X_add_number;
7388 macro_build ((char *) NULL, &icnt, &imm_expr,
7389 dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7393 if (imm_expr.X_op != O_constant)
7394 as_bad (_("Unsupported large constant"));
7395 imm_expr.X_add_number = -imm_expr.X_add_number;
7396 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
7401 if (imm_expr.X_op != O_constant)
7402 as_bad (_("Unsupported large constant"));
7403 imm_expr.X_add_number = -imm_expr.X_add_number;
7404 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
7427 goto do_reverse_branch;
7431 goto do_reverse_branch;
7443 goto do_reverse_branch;
7454 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
7456 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7483 goto do_addone_branch_i;
7488 goto do_addone_branch_i;
7503 goto do_addone_branch_i;
7510 if (imm_expr.X_op != O_constant)
7511 as_bad (_("Unsupported large constant"));
7512 ++imm_expr.X_add_number;
7515 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
7516 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7520 expr1.X_add_number = 0;
7521 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
7523 move_register (&icnt, xreg, yreg);
7524 expr1.X_add_number = 2;
7525 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
7526 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7527 "neg", "x,w", xreg, xreg);
7531 /* For consistency checking, verify that all bits are specified either
7532 by the match/mask part of the instruction definition, or by the
7535 validate_mips_insn (opc)
7536 const struct mips_opcode *opc;
7538 const char *p = opc->args;
7540 unsigned long used_bits = opc->mask;
7542 if ((used_bits & opc->match) != opc->match)
7544 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7545 opc->name, opc->args);
7548 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7555 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7556 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7558 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
7559 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
7560 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7561 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7563 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7564 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7566 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
7568 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
7569 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
7570 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
7571 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7572 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7573 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7574 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7575 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
7576 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7577 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
7578 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7580 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
7581 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7582 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7583 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
7585 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7586 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7587 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
7588 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7589 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7590 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7591 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7592 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7593 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7596 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
7597 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
7598 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7600 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7601 c, opc->name, opc->args);
7605 if (used_bits != 0xffffffff)
7607 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7608 ~used_bits & 0xffffffff, opc->name, opc->args);
7614 /* This routine assembles an instruction into its binary format. As a
7615 side effect, it sets one of the global variables imm_reloc or
7616 offset_reloc to the type of relocation to do if one of the operands
7617 is an address expression. */
7622 struct mips_cl_insn *ip;
7627 struct mips_opcode *insn;
7630 unsigned int lastregno = 0;
7636 /* If the instruction contains a '.', we first try to match an instruction
7637 including the '.'. Then we try again without the '.'. */
7639 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
7642 /* If we stopped on whitespace, then replace the whitespace with null for
7643 the call to hash_find. Save the character we replaced just in case we
7644 have to re-parse the instruction. */
7651 insn = (struct mips_opcode *) hash_find (op_hash, str);
7653 /* If we didn't find the instruction in the opcode table, try again, but
7654 this time with just the instruction up to, but not including the
7658 /* Restore the character we overwrite above (if any). */
7662 /* Scan up to the first '.' or whitespace. */
7664 *s != '\0' && *s != '.' && !ISSPACE (*s);
7668 /* If we did not find a '.', then we can quit now. */
7671 insn_error = "unrecognized opcode";
7675 /* Lookup the instruction in the hash table. */
7677 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7679 insn_error = "unrecognized opcode";
7689 assert (strcmp (insn->name, str) == 0);
7691 if (OPCODE_IS_MEMBER (insn,
7693 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
7699 if (insn->pinfo != INSN_MACRO)
7701 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7707 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7708 && strcmp (insn->name, insn[1].name) == 0)
7717 static char buf[100];
7719 _("opcode not supported on this processor: %s (%s)"),
7720 mips_cpu_to_str (mips_arch),
7721 mips_isa_to_str (mips_opts.isa));
7732 ip->insn_opcode = insn->match;
7734 for (args = insn->args;; ++args)
7736 s += strspn (s, " \t");
7739 case '\0': /* end of args */
7752 ip->insn_opcode |= lastregno << OP_SH_RS;
7756 ip->insn_opcode |= lastregno << OP_SH_RT;
7760 ip->insn_opcode |= lastregno << OP_SH_FT;
7764 ip->insn_opcode |= lastregno << OP_SH_FS;
7770 /* Handle optional base register.
7771 Either the base register is omitted or
7772 we must have a left paren. */
7773 /* This is dependent on the next operand specifier
7774 is a base register specification. */
7775 assert (args[1] == 'b' || args[1] == '5'
7776 || args[1] == '-' || args[1] == '4');
7780 case ')': /* these must match exactly */
7785 case '<': /* must be at least one digit */
7787 * According to the manual, if the shift amount is greater
7788 * than 31 or less than 0, then the shift amount should be
7789 * mod 32. In reality the mips assembler issues an error.
7790 * We issue a warning and mask out all but the low 5 bits.
7792 my_getExpression (&imm_expr, s);
7793 check_absolute_expr (ip, &imm_expr);
7794 if ((unsigned long) imm_expr.X_add_number > 31)
7796 as_warn (_("Improper shift amount (%ld)"),
7797 (long) imm_expr.X_add_number);
7798 imm_expr.X_add_number &= OP_MASK_SHAMT;
7800 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
7801 imm_expr.X_op = O_absent;
7805 case '>': /* shift amount minus 32 */
7806 my_getExpression (&imm_expr, s);
7807 check_absolute_expr (ip, &imm_expr);
7808 if ((unsigned long) imm_expr.X_add_number < 32
7809 || (unsigned long) imm_expr.X_add_number > 63)
7811 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
7812 imm_expr.X_op = O_absent;
7816 case 'k': /* cache code */
7817 case 'h': /* prefx code */
7818 my_getExpression (&imm_expr, s);
7819 check_absolute_expr (ip, &imm_expr);
7820 if ((unsigned long) imm_expr.X_add_number > 31)
7822 as_warn (_("Invalid value for `%s' (%lu)"),
7824 (unsigned long) imm_expr.X_add_number);
7825 imm_expr.X_add_number &= 0x1f;
7828 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7830 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7831 imm_expr.X_op = O_absent;
7835 case 'c': /* break code */
7836 my_getExpression (&imm_expr, s);
7837 check_absolute_expr (ip, &imm_expr);
7838 if ((unsigned) imm_expr.X_add_number > 1023)
7840 as_warn (_("Illegal break code (%ld)"),
7841 (long) imm_expr.X_add_number);
7842 imm_expr.X_add_number &= OP_MASK_CODE;
7844 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
7845 imm_expr.X_op = O_absent;
7849 case 'q': /* lower break code */
7850 my_getExpression (&imm_expr, s);
7851 check_absolute_expr (ip, &imm_expr);
7852 if ((unsigned) imm_expr.X_add_number > 1023)
7854 as_warn (_("Illegal lower break code (%ld)"),
7855 (long) imm_expr.X_add_number);
7856 imm_expr.X_add_number &= OP_MASK_CODE2;
7858 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
7859 imm_expr.X_op = O_absent;
7863 case 'B': /* 20-bit syscall/break code. */
7864 my_getExpression (&imm_expr, s);
7865 check_absolute_expr (ip, &imm_expr);
7866 if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE20)
7867 as_warn (_("Illegal 20-bit code (%ld)"),
7868 (long) imm_expr.X_add_number);
7869 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
7870 imm_expr.X_op = O_absent;
7874 case 'C': /* Coprocessor code */
7875 my_getExpression (&imm_expr, s);
7876 check_absolute_expr (ip, &imm_expr);
7877 if ((unsigned long) imm_expr.X_add_number >= (1<<25))
7879 as_warn (_("Coproccesor code > 25 bits (%ld)"),
7880 (long) imm_expr.X_add_number);
7881 imm_expr.X_add_number &= ((1<<25) - 1);
7883 ip->insn_opcode |= imm_expr.X_add_number;
7884 imm_expr.X_op = O_absent;
7888 case 'J': /* 19-bit wait code. */
7889 my_getExpression (&imm_expr, s);
7890 check_absolute_expr (ip, &imm_expr);
7891 if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE19)
7892 as_warn (_("Illegal 19-bit code (%ld)"),
7893 (long) imm_expr.X_add_number);
7894 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
7895 imm_expr.X_op = O_absent;
7899 case 'P': /* Performance register */
7900 my_getExpression (&imm_expr, s);
7901 check_absolute_expr (ip, &imm_expr);
7902 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
7904 as_warn (_("Invalid performance register (%ld)"),
7905 (long) imm_expr.X_add_number);
7906 imm_expr.X_add_number &= OP_MASK_PERFREG;
7908 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
7909 imm_expr.X_op = O_absent;
7913 case 'b': /* base register */
7914 case 'd': /* destination register */
7915 case 's': /* source register */
7916 case 't': /* target register */
7917 case 'r': /* both target and source */
7918 case 'v': /* both dest and source */
7919 case 'w': /* both dest and target */
7920 case 'E': /* coprocessor target register */
7921 case 'G': /* coprocessor destination register */
7922 case 'x': /* ignore register name */
7923 case 'z': /* must be zero register */
7924 case 'U': /* destination register (clo/clz). */
7939 while (ISDIGIT (*s));
7941 as_bad (_("Invalid register number (%d)"), regno);
7943 else if (*args == 'E' || *args == 'G')
7947 if (s[1] == 'f' && s[2] == 'p')
7952 else if (s[1] == 's' && s[2] == 'p')
7957 else if (s[1] == 'g' && s[2] == 'p')
7962 else if (s[1] == 'a' && s[2] == 't')
7967 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
7972 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
7977 else if (itbl_have_entries)
7982 p = s + 1; /* advance past '$' */
7983 n = itbl_get_field (&p); /* n is name */
7985 /* See if this is a register defined in an
7987 if (itbl_get_reg_val (n, &r))
7989 /* Get_field advances to the start of
7990 the next field, so we need to back
7991 rack to the end of the last field. */
7995 s = strchr (s, '\0');
8008 as_warn (_("Used $at without \".set noat\""));
8014 if (c == 'r' || c == 'v' || c == 'w')
8021 /* 'z' only matches $0. */
8022 if (c == 'z' && regno != 0)
8025 /* Now that we have assembled one operand, we use the args string
8026 * to figure out where it goes in the instruction. */
8033 ip->insn_opcode |= regno << OP_SH_RS;
8037 ip->insn_opcode |= regno << OP_SH_RD;
8040 ip->insn_opcode |= regno << OP_SH_RD;
8041 ip->insn_opcode |= regno << OP_SH_RT;
8046 ip->insn_opcode |= regno << OP_SH_RT;
8049 /* This case exists because on the r3000 trunc
8050 expands into a macro which requires a gp
8051 register. On the r6000 or r4000 it is
8052 assembled into a single instruction which
8053 ignores the register. Thus the insn version
8054 is MIPS_ISA2 and uses 'x', and the macro
8055 version is MIPS_ISA1 and uses 't'. */
8058 /* This case is for the div instruction, which
8059 acts differently if the destination argument
8060 is $0. This only matches $0, and is checked
8061 outside the switch. */
8064 /* Itbl operand; not yet implemented. FIXME ?? */
8066 /* What about all other operands like 'i', which
8067 can be specified in the opcode table? */
8077 ip->insn_opcode |= lastregno << OP_SH_RS;
8080 ip->insn_opcode |= lastregno << OP_SH_RT;
8085 case 'D': /* floating point destination register */
8086 case 'S': /* floating point source register */
8087 case 'T': /* floating point target register */
8088 case 'R': /* floating point source register */
8092 if (s[0] == '$' && s[1] == 'f'
8103 while (ISDIGIT (*s));
8106 as_bad (_("Invalid float register number (%d)"), regno);
8108 if ((regno & 1) != 0
8110 && ! (strcmp (str, "mtc1") == 0
8111 || strcmp (str, "mfc1") == 0
8112 || strcmp (str, "lwc1") == 0
8113 || strcmp (str, "swc1") == 0
8114 || strcmp (str, "l.s") == 0
8115 || strcmp (str, "s.s") == 0))
8116 as_warn (_("Float register should be even, was %d"),
8124 if (c == 'V' || c == 'W')
8134 ip->insn_opcode |= regno << OP_SH_FD;
8138 ip->insn_opcode |= regno << OP_SH_FS;
8142 ip->insn_opcode |= regno << OP_SH_FT;
8145 ip->insn_opcode |= regno << OP_SH_FR;
8155 ip->insn_opcode |= lastregno << OP_SH_FS;
8158 ip->insn_opcode |= lastregno << OP_SH_FT;
8164 my_getExpression (&imm_expr, s);
8165 if (imm_expr.X_op != O_big
8166 && imm_expr.X_op != O_constant)
8167 insn_error = _("absolute expression required");
8172 my_getExpression (&offset_expr, s);
8173 *imm_reloc = BFD_RELOC_32;
8186 unsigned char temp[8];
8188 unsigned int length;
8193 /* These only appear as the last operand in an
8194 instruction, and every instruction that accepts
8195 them in any variant accepts them in all variants.
8196 This means we don't have to worry about backing out
8197 any changes if the instruction does not match.
8199 The difference between them is the size of the
8200 floating point constant and where it goes. For 'F'
8201 and 'L' the constant is 64 bits; for 'f' and 'l' it
8202 is 32 bits. Where the constant is placed is based
8203 on how the MIPS assembler does things:
8206 f -- immediate value
8209 The .lit4 and .lit8 sections are only used if
8210 permitted by the -G argument.
8212 When generating embedded PIC code, we use the
8213 .lit8 section but not the .lit4 section (we can do
8214 .lit4 inline easily; we need to put .lit8
8215 somewhere in the data segment, and using .lit8
8216 permits the linker to eventually combine identical
8219 The code below needs to know whether the target register
8220 is 32 or 64 bits wide. It relies on the fact 'f' and
8221 'F' are used with GPR-based instructions and 'l' and
8222 'L' are used with FPR-based instructions. */
8224 f64 = *args == 'F' || *args == 'L';
8225 using_gprs = *args == 'F' || *args == 'f';
8227 save_in = input_line_pointer;
8228 input_line_pointer = s;
8229 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8231 s = input_line_pointer;
8232 input_line_pointer = save_in;
8233 if (err != NULL && *err != '\0')
8235 as_bad (_("Bad floating point constant: %s"), err);
8236 memset (temp, '\0', sizeof temp);
8237 length = f64 ? 8 : 4;
8240 assert (length == (unsigned) (f64 ? 8 : 4));
8244 && (! USE_GLOBAL_POINTER_OPT
8245 || mips_pic == EMBEDDED_PIC
8246 || g_switch_value < 4
8247 || (temp[0] == 0 && temp[1] == 0)
8248 || (temp[2] == 0 && temp[3] == 0))))
8250 imm_expr.X_op = O_constant;
8251 if (! target_big_endian)
8252 imm_expr.X_add_number = bfd_getl32 (temp);
8254 imm_expr.X_add_number = bfd_getb32 (temp);
8257 && ! mips_disable_float_construction
8258 /* Constants can only be constructed in GPRs and
8259 copied to FPRs if the GPRs are at least as wide
8260 as the FPRs. Force the constant into memory if
8261 we are using 64-bit FPRs but the GPRs are only
8264 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8265 && ((temp[0] == 0 && temp[1] == 0)
8266 || (temp[2] == 0 && temp[3] == 0))
8267 && ((temp[4] == 0 && temp[5] == 0)
8268 || (temp[6] == 0 && temp[7] == 0)))
8270 /* The value is simple enough to load with a couple of
8271 instructions. If using 32-bit registers, set
8272 imm_expr to the high order 32 bits and offset_expr to
8273 the low order 32 bits. Otherwise, set imm_expr to
8274 the entire 64 bit constant. */
8275 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8277 imm_expr.X_op = O_constant;
8278 offset_expr.X_op = O_constant;
8279 if (! target_big_endian)
8281 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8282 offset_expr.X_add_number = bfd_getl32 (temp);
8286 imm_expr.X_add_number = bfd_getb32 (temp);
8287 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8289 if (offset_expr.X_add_number == 0)
8290 offset_expr.X_op = O_absent;
8292 else if (sizeof (imm_expr.X_add_number) > 4)
8294 imm_expr.X_op = O_constant;
8295 if (! target_big_endian)
8296 imm_expr.X_add_number = bfd_getl64 (temp);
8298 imm_expr.X_add_number = bfd_getb64 (temp);
8302 imm_expr.X_op = O_big;
8303 imm_expr.X_add_number = 4;
8304 if (! target_big_endian)
8306 generic_bignum[0] = bfd_getl16 (temp);
8307 generic_bignum[1] = bfd_getl16 (temp + 2);
8308 generic_bignum[2] = bfd_getl16 (temp + 4);
8309 generic_bignum[3] = bfd_getl16 (temp + 6);
8313 generic_bignum[0] = bfd_getb16 (temp + 6);
8314 generic_bignum[1] = bfd_getb16 (temp + 4);
8315 generic_bignum[2] = bfd_getb16 (temp + 2);
8316 generic_bignum[3] = bfd_getb16 (temp);
8322 const char *newname;
8325 /* Switch to the right section. */
8327 subseg = now_subseg;
8330 default: /* unused default case avoids warnings. */
8332 newname = RDATA_SECTION_NAME;
8333 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
8334 || mips_pic == EMBEDDED_PIC)
8338 if (mips_pic == EMBEDDED_PIC)
8341 newname = RDATA_SECTION_NAME;
8344 assert (!USE_GLOBAL_POINTER_OPT
8345 || g_switch_value >= 4);
8349 new_seg = subseg_new (newname, (subsegT) 0);
8350 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
8351 bfd_set_section_flags (stdoutput, new_seg,
8356 frag_align (*args == 'l' ? 2 : 3, 0, 0);
8357 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
8358 && strcmp (TARGET_OS, "elf") != 0)
8359 record_alignment (new_seg, 4);
8361 record_alignment (new_seg, *args == 'l' ? 2 : 3);
8363 as_bad (_("Can't use floating point insn in this section"));
8365 /* Set the argument to the current address in the
8367 offset_expr.X_op = O_symbol;
8368 offset_expr.X_add_symbol =
8369 symbol_new ("L0\001", now_seg,
8370 (valueT) frag_now_fix (), frag_now);
8371 offset_expr.X_add_number = 0;
8373 /* Put the floating point number into the section. */
8374 p = frag_more ((int) length);
8375 memcpy (p, temp, length);
8377 /* Switch back to the original section. */
8378 subseg_set (seg, subseg);
8383 case 'i': /* 16 bit unsigned immediate */
8384 case 'j': /* 16 bit signed immediate */
8385 *imm_reloc = BFD_RELOC_LO16;
8386 c = my_getSmallExpression (&imm_expr, s);
8391 if (imm_expr.X_op == O_constant)
8392 imm_expr.X_add_number =
8393 (imm_expr.X_add_number >> 16) & 0xffff;
8395 else if (c == S_EX_HIGHEST)
8396 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8397 else if (c == S_EX_HIGHER)
8398 *imm_reloc = BFD_RELOC_MIPS_HIGHER;
8399 else if (c == S_EX_GP_REL)
8401 /* This occurs in NewABI only. */
8402 c = my_getSmallExpression (&imm_expr, s);
8404 as_bad (_("bad composition of relocations"));
8407 c = my_getSmallExpression (&imm_expr, s);
8409 as_bad (_("bad composition of relocations"));
8412 imm_reloc[0] = BFD_RELOC_GPREL16;
8413 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8414 imm_reloc[2] = BFD_RELOC_LO16;
8419 else if (c == S_EX_HI)
8421 *imm_reloc = BFD_RELOC_HI16_S;
8422 imm_unmatched_hi = true;
8425 *imm_reloc = BFD_RELOC_HI16;
8427 else if (imm_expr.X_op == O_constant)
8428 imm_expr.X_add_number &= 0xffff;
8432 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8433 || ((imm_expr.X_add_number < 0
8434 || imm_expr.X_add_number >= 0x10000)
8435 && imm_expr.X_op == O_constant))
8437 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8438 !strcmp (insn->name, insn[1].name))
8440 if (imm_expr.X_op == O_constant
8441 || imm_expr.X_op == O_big)
8442 as_bad (_("16 bit expression not in range 0..65535"));
8450 /* The upper bound should be 0x8000, but
8451 unfortunately the MIPS assembler accepts numbers
8452 from 0x8000 to 0xffff and sign extends them, and
8453 we want to be compatible. We only permit this
8454 extended range for an instruction which does not
8455 provide any further alternates, since those
8456 alternates may handle other cases. People should
8457 use the numbers they mean, rather than relying on
8458 a mysterious sign extension. */
8459 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8460 strcmp (insn->name, insn[1].name) == 0);
8465 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8466 || ((imm_expr.X_add_number < -0x8000
8467 || imm_expr.X_add_number >= max)
8468 && imm_expr.X_op == O_constant)
8470 && imm_expr.X_add_number < 0
8472 && imm_expr.X_unsigned
8473 && sizeof (imm_expr.X_add_number) <= 4))
8477 if (imm_expr.X_op == O_constant
8478 || imm_expr.X_op == O_big)
8479 as_bad (_("16 bit expression not in range -32768..32767"));
8485 case 'o': /* 16 bit offset */
8486 c = my_getSmallExpression (&offset_expr, s);
8488 /* If this value won't fit into a 16 bit offset, then go
8489 find a macro that will generate the 32 bit offset
8492 && (offset_expr.X_op != O_constant
8493 || offset_expr.X_add_number >= 0x8000
8494 || offset_expr.X_add_number < -0x8000))
8499 if (offset_expr.X_op != O_constant)
8501 offset_expr.X_add_number =
8502 (offset_expr.X_add_number >> 16) & 0xffff;
8504 *offset_reloc = BFD_RELOC_LO16;
8508 case 'p': /* pc relative offset */
8509 if (mips_pic == EMBEDDED_PIC)
8510 *offset_reloc = BFD_RELOC_16_PCREL_S2;
8512 *offset_reloc = BFD_RELOC_16_PCREL;
8513 my_getExpression (&offset_expr, s);
8517 case 'u': /* upper 16 bits */
8518 c = my_getSmallExpression (&imm_expr, s);
8519 *imm_reloc = BFD_RELOC_LO16;
8524 if (imm_expr.X_op == O_constant)
8525 imm_expr.X_add_number =
8526 (imm_expr.X_add_number >> 16) & 0xffff;
8527 else if (c == S_EX_HI)
8529 *imm_reloc = BFD_RELOC_HI16_S;
8530 imm_unmatched_hi = true;
8533 else if (c == S_EX_HIGHEST)
8534 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8535 else if (c == S_EX_GP_REL)
8537 /* This occurs in NewABI only. */
8538 c = my_getSmallExpression (&imm_expr, s);
8540 as_bad (_("bad composition of relocations"));
8543 c = my_getSmallExpression (&imm_expr, s);
8545 as_bad (_("bad composition of relocations"));
8548 imm_reloc[0] = BFD_RELOC_GPREL16;
8549 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8550 imm_reloc[2] = BFD_RELOC_HI16_S;
8556 *imm_reloc = BFD_RELOC_HI16;
8558 else if (imm_expr.X_op == O_constant)
8559 imm_expr.X_add_number &= 0xffff;
8561 if (imm_expr.X_op == O_constant
8562 && (imm_expr.X_add_number < 0
8563 || imm_expr.X_add_number >= 0x10000))
8564 as_bad (_("lui expression not in range 0..65535"));
8568 case 'a': /* 26 bit address */
8569 my_getExpression (&offset_expr, s);
8571 *offset_reloc = BFD_RELOC_MIPS_JMP;
8574 case 'N': /* 3 bit branch condition code */
8575 case 'M': /* 3 bit compare condition code */
8576 if (strncmp (s, "$fcc", 4) != 0)
8586 while (ISDIGIT (*s));
8588 as_bad (_("invalid condition code register $fcc%d"), regno);
8590 ip->insn_opcode |= regno << OP_SH_BCC;
8592 ip->insn_opcode |= regno << OP_SH_CCC;
8596 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
8607 while (ISDIGIT (*s));
8610 c = 8; /* Invalid sel value. */
8613 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
8614 ip->insn_opcode |= c;
8618 as_bad (_("bad char = '%c'\n"), *args);
8623 /* Args don't match. */
8624 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8625 !strcmp (insn->name, insn[1].name))
8629 insn_error = _("illegal operands");
8634 insn_error = _("illegal operands");
8639 /* This routine assembles an instruction into its binary format when
8640 assembling for the mips16. As a side effect, it sets one of the
8641 global variables imm_reloc or offset_reloc to the type of
8642 relocation to do if one of the operands is an address expression.
8643 It also sets mips16_small and mips16_ext if the user explicitly
8644 requested a small or extended instruction. */
8649 struct mips_cl_insn *ip;
8653 struct mips_opcode *insn;
8656 unsigned int lastregno = 0;
8661 mips16_small = false;
8664 for (s = str; ISLOWER (*s); ++s)
8676 if (s[1] == 't' && s[2] == ' ')
8679 mips16_small = true;
8683 else if (s[1] == 'e' && s[2] == ' ')
8692 insn_error = _("unknown opcode");
8696 if (mips_opts.noautoextend && ! mips16_ext)
8697 mips16_small = true;
8699 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
8701 insn_error = _("unrecognized opcode");
8708 assert (strcmp (insn->name, str) == 0);
8711 ip->insn_opcode = insn->match;
8712 ip->use_extend = false;
8713 imm_expr.X_op = O_absent;
8714 imm_reloc[0] = BFD_RELOC_UNUSED;
8715 imm_reloc[1] = BFD_RELOC_UNUSED;
8716 imm_reloc[2] = BFD_RELOC_UNUSED;
8717 offset_expr.X_op = O_absent;
8718 offset_reloc[0] = BFD_RELOC_UNUSED;
8719 offset_reloc[1] = BFD_RELOC_UNUSED;
8720 offset_reloc[2] = BFD_RELOC_UNUSED;
8721 for (args = insn->args; 1; ++args)
8728 /* In this switch statement we call break if we did not find
8729 a match, continue if we did find a match, or return if we
8738 /* Stuff the immediate value in now, if we can. */
8739 if (imm_expr.X_op == O_constant
8740 && *imm_reloc > BFD_RELOC_UNUSED
8741 && insn->pinfo != INSN_MACRO)
8743 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
8744 imm_expr.X_add_number, true, mips16_small,
8745 mips16_ext, &ip->insn_opcode,
8746 &ip->use_extend, &ip->extend);
8747 imm_expr.X_op = O_absent;
8748 *imm_reloc = BFD_RELOC_UNUSED;
8762 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8765 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8781 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8783 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8810 while (ISDIGIT (*s));
8813 as_bad (_("invalid register number (%d)"), regno);
8819 if (s[1] == 'f' && s[2] == 'p')
8824 else if (s[1] == 's' && s[2] == 'p')
8829 else if (s[1] == 'g' && s[2] == 'p')
8834 else if (s[1] == 'a' && s[2] == 't')
8839 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8844 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8857 if (c == 'v' || c == 'w')
8859 regno = mips16_to_32_reg_map[lastregno];
8873 regno = mips32_to_16_reg_map[regno];
8878 regno = ILLEGAL_REG;
8883 regno = ILLEGAL_REG;
8888 regno = ILLEGAL_REG;
8893 if (regno == AT && ! mips_opts.noat)
8894 as_warn (_("used $at without \".set noat\""));
8901 if (regno == ILLEGAL_REG)
8908 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
8912 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
8915 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
8918 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
8924 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
8927 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
8928 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
8938 if (strncmp (s, "$pc", 3) == 0)
8962 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
8964 /* This is %gprel(SYMBOL). We need to read SYMBOL,
8965 and generate the appropriate reloc. If the text
8966 inside %gprel is not a symbol name with an
8967 optional offset, then we generate a normal reloc
8968 and will probably fail later. */
8969 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
8970 if (imm_expr.X_op == O_symbol)
8973 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
8975 ip->use_extend = true;
8982 /* Just pick up a normal expression. */
8983 my_getExpression (&imm_expr, s);
8986 if (imm_expr.X_op == O_register)
8988 /* What we thought was an expression turned out to
8991 if (s[0] == '(' && args[1] == '(')
8993 /* It looks like the expression was omitted
8994 before a register indirection, which means
8995 that the expression is implicitly zero. We
8996 still set up imm_expr, so that we handle
8997 explicit extensions correctly. */
8998 imm_expr.X_op = O_constant;
8999 imm_expr.X_add_number = 0;
9000 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9007 /* We need to relax this instruction. */
9008 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9017 /* We use offset_reloc rather than imm_reloc for the PC
9018 relative operands. This lets macros with both
9019 immediate and address operands work correctly. */
9020 my_getExpression (&offset_expr, s);
9022 if (offset_expr.X_op == O_register)
9025 /* We need to relax this instruction. */
9026 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9030 case '6': /* break code */
9031 my_getExpression (&imm_expr, s);
9032 check_absolute_expr (ip, &imm_expr);
9033 if ((unsigned long) imm_expr.X_add_number > 63)
9035 as_warn (_("Invalid value for `%s' (%lu)"),
9037 (unsigned long) imm_expr.X_add_number);
9038 imm_expr.X_add_number &= 0x3f;
9040 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9041 imm_expr.X_op = O_absent;
9045 case 'a': /* 26 bit address */
9046 my_getExpression (&offset_expr, s);
9048 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9049 ip->insn_opcode <<= 16;
9052 case 'l': /* register list for entry macro */
9053 case 'L': /* register list for exit macro */
9063 int freg, reg1, reg2;
9065 while (*s == ' ' || *s == ',')
9069 as_bad (_("can't parse register list"));
9081 while (ISDIGIT (*s))
9103 as_bad (_("invalid register list"));
9108 while (ISDIGIT (*s))
9115 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9120 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9125 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9126 mask |= (reg2 - 3) << 3;
9127 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9128 mask |= (reg2 - 15) << 1;
9129 else if (reg1 == 31 && reg2 == 31)
9133 as_bad (_("invalid register list"));
9137 /* The mask is filled in in the opcode table for the
9138 benefit of the disassembler. We remove it before
9139 applying the actual mask. */
9140 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9141 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9145 case 'e': /* extend code */
9146 my_getExpression (&imm_expr, s);
9147 check_absolute_expr (ip, &imm_expr);
9148 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9150 as_warn (_("Invalid value for `%s' (%lu)"),
9152 (unsigned long) imm_expr.X_add_number);
9153 imm_expr.X_add_number &= 0x7ff;
9155 ip->insn_opcode |= imm_expr.X_add_number;
9156 imm_expr.X_op = O_absent;
9166 /* Args don't match. */
9167 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9168 strcmp (insn->name, insn[1].name) == 0)
9175 insn_error = _("illegal operands");
9181 /* This structure holds information we know about a mips16 immediate
9184 struct mips16_immed_operand
9186 /* The type code used in the argument string in the opcode table. */
9188 /* The number of bits in the short form of the opcode. */
9190 /* The number of bits in the extended form of the opcode. */
9192 /* The amount by which the short form is shifted when it is used;
9193 for example, the sw instruction has a shift count of 2. */
9195 /* The amount by which the short form is shifted when it is stored
9196 into the instruction code. */
9198 /* Non-zero if the short form is unsigned. */
9200 /* Non-zero if the extended form is unsigned. */
9202 /* Non-zero if the value is PC relative. */
9206 /* The mips16 immediate operand types. */
9208 static const struct mips16_immed_operand mips16_immed_operands[] =
9210 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9211 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9212 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9213 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9214 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9215 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9216 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9217 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9218 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9219 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9220 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9221 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9222 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9223 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9224 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9225 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9226 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9227 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9228 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9229 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9230 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9233 #define MIPS16_NUM_IMMED \
9234 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9236 /* Handle a mips16 instruction with an immediate value. This or's the
9237 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9238 whether an extended value is needed; if one is needed, it sets
9239 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9240 If SMALL is true, an unextended opcode was explicitly requested.
9241 If EXT is true, an extended opcode was explicitly requested. If
9242 WARN is true, warn if EXT does not match reality. */
9245 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
9254 unsigned long *insn;
9255 boolean *use_extend;
9256 unsigned short *extend;
9258 register const struct mips16_immed_operand *op;
9259 int mintiny, maxtiny;
9262 op = mips16_immed_operands;
9263 while (op->type != type)
9266 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9271 if (type == '<' || type == '>' || type == '[' || type == ']')
9274 maxtiny = 1 << op->nbits;
9279 maxtiny = (1 << op->nbits) - 1;
9284 mintiny = - (1 << (op->nbits - 1));
9285 maxtiny = (1 << (op->nbits - 1)) - 1;
9288 /* Branch offsets have an implicit 0 in the lowest bit. */
9289 if (type == 'p' || type == 'q')
9292 if ((val & ((1 << op->shift) - 1)) != 0
9293 || val < (mintiny << op->shift)
9294 || val > (maxtiny << op->shift))
9299 if (warn && ext && ! needext)
9300 as_warn_where (file, line,
9301 _("extended operand requested but not required"));
9302 if (small && needext)
9303 as_bad_where (file, line, _("invalid unextended operand value"));
9305 if (small || (! ext && ! needext))
9309 *use_extend = false;
9310 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9311 insnval <<= op->op_shift;
9316 long minext, maxext;
9322 maxext = (1 << op->extbits) - 1;
9326 minext = - (1 << (op->extbits - 1));
9327 maxext = (1 << (op->extbits - 1)) - 1;
9329 if (val < minext || val > maxext)
9330 as_bad_where (file, line,
9331 _("operand value out of range for instruction"));
9334 if (op->extbits == 16)
9336 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
9339 else if (op->extbits == 15)
9341 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
9346 extval = ((val & 0x1f) << 6) | (val & 0x20);
9350 *extend = (unsigned short) extval;
9355 static struct percent_op_match
9358 const enum small_ex_type type;
9363 {"%call_hi", S_EX_CALL_HI},
9364 {"%call_lo", S_EX_CALL_LO},
9365 {"%call16", S_EX_CALL16},
9366 {"%got_disp", S_EX_GOT_DISP},
9367 {"%got_page", S_EX_GOT_PAGE},
9368 {"%got_ofst", S_EX_GOT_OFST},
9369 {"%got_hi", S_EX_GOT_HI},
9370 {"%got_lo", S_EX_GOT_LO},
9372 {"%gp_rel", S_EX_GP_REL},
9373 {"%half", S_EX_HALF},
9374 {"%highest", S_EX_HIGHEST},
9375 {"%higher", S_EX_HIGHER},
9381 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9382 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9383 can be nested, this is handled by blanking the innermost, parsing the
9384 rest by subsequent calls. */
9387 my_getSmallParser (str, len, nestlevel)
9393 *str += strspn (*str, " \t");
9394 /* Check for expression in parentheses. */
9397 char *b = *str + 1 + strspn (*str + 1, " \t");
9400 /* Check for base register. */
9404 && (e = b + strcspn (b, ") \t"))
9405 && e - b > 1 && e - b < 4)
9408 && ((b[1] == 'f' && b[2] == 'p')
9409 || (b[1] == 's' && b[2] == 'p')
9410 || (b[1] == 'g' && b[2] == 'p')
9411 || (b[1] == 'a' && b[2] == 't')
9413 && ISDIGIT (b[2]))))
9414 || (ISDIGIT (b[1])))
9416 *len = strcspn (*str, ")") + 1;
9417 return S_EX_REGISTER;
9421 /* Check for percent_op (in parentheses). */
9422 else if (b[0] == '%')
9425 return my_getPercentOp (str, len, nestlevel);
9428 /* Some other expression in the parentheses, which can contain
9429 parentheses itself. Attempt to find the matching one. */
9435 for (s = *str + 1; *s && pcnt; s++, (*len)++)
9444 /* Check for percent_op (outside of parentheses). */
9445 else if (*str[0] == '%')
9446 return my_getPercentOp (str, len, nestlevel);
9448 /* Any other expression. */
9453 my_getPercentOp (str, len, nestlevel)
9458 char *tmp = *str + 1;
9461 while (ISALPHA (*tmp) || *tmp == '_')
9463 *tmp = TOLOWER (*tmp);
9466 while (i < (sizeof (percent_op) / sizeof (struct percent_op_match)))
9468 if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str)))
9472 int type = percent_op[i].type;
9474 /* Only %hi and %lo are allowed for OldABI. */
9475 if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO)
9478 *len = strlen (percent_op[i].str);
9487 my_getSmallExpression (ep, str)
9491 static char *oldstr = NULL;
9497 /* Don't update oldstr if the last call had nested percent_op's. We need
9498 it to parse the outer ones later. */
9505 c = my_getSmallParser (&str, &len, &nestlevel);
9506 if (c != S_EX_NONE && c != S_EX_REGISTER)
9509 while (c != S_EX_NONE && c != S_EX_REGISTER);
9513 /* A percent_op was encountered. Don't try to get an expression if
9514 it is already blanked out. */
9515 if (*(str + strspn (str + 1, " )")) != ')')
9519 /* Let my_getExpression() stop at the closing parenthesis. */
9520 save = *(str + len);
9521 *(str + len) = '\0';
9522 my_getExpression (ep, str);
9523 *(str + len) = save;
9527 /* Blank out including the % sign and the proper matching
9530 char *s = strrchr (oldstr, '%');
9533 for (end = strchr (s, '(') + 1; *end && pcnt; end++)
9537 else if (*end == ')')
9541 memset (s, ' ', end - s);
9545 expr_end = str + len;
9549 else if (c == S_EX_NONE)
9551 my_getExpression (ep, str);
9553 else if (c == S_EX_REGISTER)
9555 ep->X_op = O_constant;
9557 ep->X_add_symbol = NULL;
9558 ep->X_op_symbol = NULL;
9559 ep->X_add_number = 0;
9563 as_fatal(_("internal error"));
9567 /* All percent_op's have been handled. */
9574 my_getExpression (ep, str)
9581 save_in = input_line_pointer;
9582 input_line_pointer = str;
9584 expr_end = input_line_pointer;
9585 input_line_pointer = save_in;
9587 /* If we are in mips16 mode, and this is an expression based on `.',
9588 then we bump the value of the symbol by 1 since that is how other
9589 text symbols are handled. We don't bother to handle complex
9590 expressions, just `.' plus or minus a constant. */
9591 if (mips_opts.mips16
9592 && ep->X_op == O_symbol
9593 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
9594 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
9595 && symbol_get_frag (ep->X_add_symbol) == frag_now
9596 && symbol_constant_p (ep->X_add_symbol)
9597 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
9598 S_SET_VALUE (ep->X_add_symbol, val + 1);
9601 /* Turn a string in input_line_pointer into a floating point constant
9602 of type TYPE, and store the appropriate bytes in *LITP. The number
9603 of LITTLENUMS emitted is stored in *SIZEP. An error message is
9604 returned, or NULL on OK. */
9607 md_atof (type, litP, sizeP)
9613 LITTLENUM_TYPE words[4];
9629 return _("bad call to md_atof");
9632 t = atof_ieee (input_line_pointer, type, words);
9634 input_line_pointer = t;
9638 if (! target_big_endian)
9640 for (i = prec - 1; i >= 0; i--)
9642 md_number_to_chars (litP, (valueT) words[i], 2);
9648 for (i = 0; i < prec; i++)
9650 md_number_to_chars (litP, (valueT) words[i], 2);
9659 md_number_to_chars (buf, val, n)
9664 if (target_big_endian)
9665 number_to_chars_bigendian (buf, val, n);
9667 number_to_chars_littleendian (buf, val, n);
9671 static int support_64bit_objects(void)
9673 const char **list, **l;
9675 list = bfd_target_list ();
9676 for (l = list; *l != NULL; l++)
9678 /* This is traditional mips */
9679 if (strcmp (*l, "elf64-tradbigmips") == 0
9680 || strcmp (*l, "elf64-tradlittlemips") == 0)
9682 if (strcmp (*l, "elf64-bigmips") == 0
9683 || strcmp (*l, "elf64-littlemips") == 0)
9687 return (*l != NULL);
9689 #endif /* OBJ_ELF */
9691 CONST char *md_shortopts = "nO::g::G:";
9693 struct option md_longopts[] =
9695 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
9696 {"mips0", no_argument, NULL, OPTION_MIPS1},
9697 {"mips1", no_argument, NULL, OPTION_MIPS1},
9698 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
9699 {"mips2", no_argument, NULL, OPTION_MIPS2},
9700 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
9701 {"mips3", no_argument, NULL, OPTION_MIPS3},
9702 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
9703 {"mips4", no_argument, NULL, OPTION_MIPS4},
9704 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
9705 {"mips5", no_argument, NULL, OPTION_MIPS5},
9706 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
9707 {"mips32", no_argument, NULL, OPTION_MIPS32},
9708 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
9709 {"mips64", no_argument, NULL, OPTION_MIPS64},
9710 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
9711 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
9712 #define OPTION_TRAP (OPTION_MD_BASE + 9)
9713 {"trap", no_argument, NULL, OPTION_TRAP},
9714 {"no-break", no_argument, NULL, OPTION_TRAP},
9715 #define OPTION_BREAK (OPTION_MD_BASE + 10)
9716 {"break", no_argument, NULL, OPTION_BREAK},
9717 {"no-trap", no_argument, NULL, OPTION_BREAK},
9718 #define OPTION_EB (OPTION_MD_BASE + 11)
9719 {"EB", no_argument, NULL, OPTION_EB},
9720 #define OPTION_EL (OPTION_MD_BASE + 12)
9721 {"EL", no_argument, NULL, OPTION_EL},
9722 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
9723 {"mips16", no_argument, NULL, OPTION_MIPS16},
9724 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
9725 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
9726 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
9727 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
9728 #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 16)
9729 {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX},
9730 #define OPTION_FP32 (OPTION_MD_BASE + 17)
9731 {"mfp32", no_argument, NULL, OPTION_FP32},
9732 #define OPTION_GP32 (OPTION_MD_BASE + 18)
9733 {"mgp32", no_argument, NULL, OPTION_GP32},
9734 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
9735 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
9736 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
9737 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
9738 #define OPTION_MARCH (OPTION_MD_BASE + 21)
9739 {"march", required_argument, NULL, OPTION_MARCH},
9740 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
9741 {"mtune", required_argument, NULL, OPTION_MTUNE},
9742 #define OPTION_MCPU (OPTION_MD_BASE + 23)
9743 {"mcpu", required_argument, NULL, OPTION_MCPU},
9744 #define OPTION_M4650 (OPTION_MD_BASE + 24)
9745 {"m4650", no_argument, NULL, OPTION_M4650},
9746 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
9747 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
9748 #define OPTION_M4010 (OPTION_MD_BASE + 26)
9749 {"m4010", no_argument, NULL, OPTION_M4010},
9750 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
9751 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
9752 #define OPTION_M4100 (OPTION_MD_BASE + 28)
9753 {"m4100", no_argument, NULL, OPTION_M4100},
9754 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
9755 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
9756 #define OPTION_M3900 (OPTION_MD_BASE + 30)
9757 {"m3900", no_argument, NULL, OPTION_M3900},
9758 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
9759 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
9760 #define OPTION_GP64 (OPTION_MD_BASE + 32)
9761 {"mgp64", no_argument, NULL, OPTION_GP64},
9762 #define OPTION_MIPS3D (OPTION_MD_BASE + 33)
9763 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
9764 #define OPTION_NO_MIPS3D (OPTION_MD_BASE + 34)
9765 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
9767 #define OPTION_ELF_BASE (OPTION_MD_BASE + 35)
9768 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
9769 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
9770 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
9771 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
9772 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
9773 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
9774 {"xgot", no_argument, NULL, OPTION_XGOT},
9775 #define OPTION_MABI (OPTION_ELF_BASE + 3)
9776 {"mabi", required_argument, NULL, OPTION_MABI},
9777 #define OPTION_32 (OPTION_ELF_BASE + 4)
9778 {"32", no_argument, NULL, OPTION_32},
9779 #define OPTION_N32 (OPTION_ELF_BASE + 5)
9780 {"n32", no_argument, NULL, OPTION_N32},
9781 #define OPTION_64 (OPTION_ELF_BASE + 6)
9782 {"64", no_argument, NULL, OPTION_64},
9783 #endif /* OBJ_ELF */
9784 {NULL, no_argument, NULL, 0}
9786 size_t md_longopts_size = sizeof (md_longopts);
9789 md_parse_option (c, arg)
9795 case OPTION_CONSTRUCT_FLOATS:
9796 mips_disable_float_construction = 0;
9799 case OPTION_NO_CONSTRUCT_FLOATS:
9800 mips_disable_float_construction = 1;
9812 target_big_endian = 1;
9816 target_big_endian = 0;
9824 if (arg && arg[1] == '0')
9834 mips_debug = atoi (arg);
9835 /* When the MIPS assembler sees -g or -g2, it does not do
9836 optimizations which limit full symbolic debugging. We take
9837 that to be equivalent to -O0. */
9838 if (mips_debug == 2)
9843 mips_opts.isa = ISA_MIPS1;
9847 mips_opts.isa = ISA_MIPS2;
9851 mips_opts.isa = ISA_MIPS3;
9855 mips_opts.isa = ISA_MIPS4;
9859 mips_opts.isa = ISA_MIPS5;
9863 mips_opts.isa = ISA_MIPS32;
9867 mips_opts.isa = ISA_MIPS64;
9874 int cpu = CPU_UNKNOWN;
9876 /* Identify the processor type. */
9877 if (strcasecmp (arg, "default") != 0)
9879 const struct mips_cpu_info *ci;
9881 ci = mips_cpu_info_from_name (arg);
9882 if (ci == NULL || ci->is_isa)
9887 as_fatal (_("invalid architecture -mtune=%s"), arg);
9890 as_fatal (_("invalid architecture -march=%s"), arg);
9893 as_fatal (_("invalid architecture -mcpu=%s"), arg);
9904 if (mips_tune != CPU_UNKNOWN && mips_tune != cpu)
9905 as_warn(_("A different -mtune= was already specified, is now "
9910 if (mips_arch != CPU_UNKNOWN && mips_arch != cpu)
9911 as_warn(_("A different -march= was already specified, is now "
9916 if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu)
9917 as_warn(_("A different -mcpu= was already specified, is now "
9925 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650)
9926 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650))
9927 as_warn(_("A different -march= or -mtune= was already specified, "
9929 mips_arch = CPU_R4650;
9930 mips_tune = CPU_R4650;
9933 case OPTION_NO_M4650:
9937 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010)
9938 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010))
9939 as_warn(_("A different -march= or -mtune= was already specified, "
9941 mips_arch = CPU_R4010;
9942 mips_tune = CPU_R4010;
9945 case OPTION_NO_M4010:
9949 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100)
9950 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100))
9951 as_warn(_("A different -march= or -mtune= was already specified, "
9953 mips_arch = CPU_VR4100;
9954 mips_tune = CPU_VR4100;
9957 case OPTION_NO_M4100:
9961 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900)
9962 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900))
9963 as_warn(_("A different -march= or -mtune= was already specified, "
9965 mips_arch = CPU_R3900;
9966 mips_tune = CPU_R3900;
9969 case OPTION_NO_M3900:
9973 mips_opts.mips16 = 1;
9974 mips_no_prev_insn (false);
9977 case OPTION_NO_MIPS16:
9978 mips_opts.mips16 = 0;
9979 mips_no_prev_insn (false);
9983 mips_opts.ase_mips3d = 1;
9986 case OPTION_NO_MIPS3D:
9987 mips_opts.ase_mips3d = 0;
9990 case OPTION_MEMBEDDED_PIC:
9991 mips_pic = EMBEDDED_PIC;
9992 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
9994 as_bad (_("-G may not be used with embedded PIC code"));
9997 g_switch_value = 0x7fffffff;
10001 /* When generating ELF code, we permit -KPIC and -call_shared to
10002 select SVR4_PIC, and -non_shared to select no PIC. This is
10003 intended to be compatible with Irix 5. */
10004 case OPTION_CALL_SHARED:
10005 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10007 as_bad (_("-call_shared is supported only for ELF format"));
10010 mips_pic = SVR4_PIC;
10011 if (g_switch_seen && g_switch_value != 0)
10013 as_bad (_("-G may not be used with SVR4 PIC code"));
10016 g_switch_value = 0;
10019 case OPTION_NON_SHARED:
10020 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10022 as_bad (_("-non_shared is supported only for ELF format"));
10028 /* The -xgot option tells the assembler to use 32 offsets when
10029 accessing the got in SVR4_PIC mode. It is for Irix
10034 #endif /* OBJ_ELF */
10037 if (! USE_GLOBAL_POINTER_OPT)
10039 as_bad (_("-G is not supported for this configuration"));
10042 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10044 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10048 g_switch_value = atoi (arg);
10053 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10056 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10058 as_bad (_("-32 is supported for ELF format only"));
10061 mips_opts.abi = O32_ABI;
10065 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10067 as_bad (_("-n32 is supported for ELF format only"));
10070 mips_opts.abi = N32_ABI;
10074 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10076 as_bad (_("-64 is supported for ELF format only"));
10079 mips_opts.abi = N64_ABI;
10080 if (! support_64bit_objects())
10081 as_fatal (_("No compiled in support for 64 bit object file format"));
10083 #endif /* OBJ_ELF */
10086 file_mips_gp32 = 1;
10087 if (mips_opts.abi != O32_ABI)
10088 mips_opts.abi = NO_ABI;
10092 file_mips_gp32 = 0;
10093 if (mips_opts.abi == O32_ABI)
10094 mips_opts.abi = NO_ABI;
10098 file_mips_fp32 = 1;
10099 if (mips_opts.abi != O32_ABI)
10100 mips_opts.abi = NO_ABI;
10105 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10107 as_bad (_("-mabi is supported for ELF format only"));
10110 if (strcmp (arg, "32") == 0)
10111 mips_opts.abi = O32_ABI;
10112 else if (strcmp (arg, "o64") == 0)
10113 mips_opts.abi = O64_ABI;
10114 else if (strcmp (arg, "n32") == 0)
10115 mips_opts.abi = N32_ABI;
10116 else if (strcmp (arg, "64") == 0)
10118 mips_opts.abi = N64_ABI;
10119 if (! support_64bit_objects())
10120 as_fatal (_("No compiled in support for 64 bit object file "
10123 else if (strcmp (arg, "eabi") == 0)
10124 mips_opts.abi = EABI_ABI;
10127 as_fatal (_("invalid abi -mabi=%s"), arg);
10131 #endif /* OBJ_ELF */
10133 case OPTION_M7000_HILO_FIX:
10134 mips_7000_hilo_fix = true;
10137 case OPTION_NO_M7000_HILO_FIX:
10138 mips_7000_hilo_fix = false;
10149 show (stream, string, col_p, first_p)
10157 fprintf (stream, "%24s", "");
10162 fprintf (stream, ", ");
10166 if (*col_p + strlen (string) > 72)
10168 fprintf (stream, "\n%24s", "");
10172 fprintf (stream, "%s", string);
10173 *col_p += strlen (string);
10179 md_show_usage (stream)
10184 fprintf (stream, _("\
10186 -membedded-pic generate embedded position independent code\n\
10187 -EB generate big endian output\n\
10188 -EL generate little endian output\n\
10189 -g, -g2 do not remove unneeded NOPs or swap branches\n\
10190 -G NUM allow referencing objects up to NUM bytes\n\
10191 implicitly with the gp register [default 8]\n"));
10192 fprintf (stream, _("\
10193 -mips1 generate MIPS ISA I instructions\n\
10194 -mips2 generate MIPS ISA II instructions\n\
10195 -mips3 generate MIPS ISA III instructions\n\
10196 -mips4 generate MIPS ISA IV instructions\n\
10197 -mips5 generate MIPS ISA V instructions\n\
10198 -mips32 generate MIPS32 ISA instructions\n\
10199 -mips64 generate MIPS64 ISA instructions\n\
10200 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
10204 show (stream, "2000", &column, &first);
10205 show (stream, "3000", &column, &first);
10206 show (stream, "3900", &column, &first);
10207 show (stream, "4000", &column, &first);
10208 show (stream, "4010", &column, &first);
10209 show (stream, "4100", &column, &first);
10210 show (stream, "4111", &column, &first);
10211 show (stream, "4300", &column, &first);
10212 show (stream, "4400", &column, &first);
10213 show (stream, "4600", &column, &first);
10214 show (stream, "4650", &column, &first);
10215 show (stream, "5000", &column, &first);
10216 show (stream, "5200", &column, &first);
10217 show (stream, "5230", &column, &first);
10218 show (stream, "5231", &column, &first);
10219 show (stream, "5261", &column, &first);
10220 show (stream, "5721", &column, &first);
10221 show (stream, "6000", &column, &first);
10222 show (stream, "8000", &column, &first);
10223 show (stream, "10000", &column, &first);
10224 show (stream, "12000", &column, &first);
10225 show (stream, "sb1", &column, &first);
10226 fputc ('\n', stream);
10228 fprintf (stream, _("\
10229 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
10230 -no-mCPU don't generate code specific to CPU.\n\
10231 For -mCPU and -no-mCPU, CPU must be one of:\n"));
10235 show (stream, "3900", &column, &first);
10236 show (stream, "4010", &column, &first);
10237 show (stream, "4100", &column, &first);
10238 show (stream, "4650", &column, &first);
10239 fputc ('\n', stream);
10241 fprintf (stream, _("\
10242 -mips16 generate mips16 instructions\n\
10243 -no-mips16 do not generate mips16 instructions\n"));
10244 fprintf (stream, _("\
10245 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
10246 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
10247 -O0 remove unneeded NOPs, do not swap branches\n\
10248 -O remove unneeded NOPs and swap branches\n\
10249 -n warn about NOPs generated from macros\n\
10250 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
10251 --trap, --no-break trap exception on div by 0 and mult overflow\n\
10252 --break, --no-trap break exception on div by 0 and mult overflow\n"));
10254 fprintf (stream, _("\
10255 -KPIC, -call_shared generate SVR4 position independent code\n\
10256 -non_shared do not generate position independent code\n\
10257 -xgot assume a 32 bit GOT\n\
10258 -mabi=ABI create ABI conformant object file for:\n"));
10262 show (stream, "32", &column, &first);
10263 show (stream, "o64", &column, &first);
10264 show (stream, "n32", &column, &first);
10265 show (stream, "64", &column, &first);
10266 show (stream, "eabi", &column, &first);
10268 fputc ('\n', stream);
10270 fprintf (stream, _("\
10271 -32 create o32 ABI object file (default)\n\
10272 -n32 create n32 ABI object file\n\
10273 -64 create 64 ABI object file\n"));
10278 mips_init_after_args ()
10280 /* initialize opcodes */
10281 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10282 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10286 md_pcrel_from (fixP)
10289 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
10290 && fixP->fx_addsy != (symbolS *) NULL
10291 && ! S_IS_DEFINED (fixP->fx_addsy))
10293 /* This makes a branch to an undefined symbol be a branch to the
10294 current location. */
10295 if (mips_pic == EMBEDDED_PIC)
10301 /* return the address of the delay slot */
10302 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
10305 /* This is called before the symbol table is processed. In order to
10306 work with gcc when using mips-tfile, we must keep all local labels.
10307 However, in other cases, we want to discard them. If we were
10308 called with -g, but we didn't see any debugging information, it may
10309 mean that gcc is smuggling debugging information through to
10310 mips-tfile, in which case we must generate all local labels. */
10313 mips_frob_file_before_adjust ()
10315 #ifndef NO_ECOFF_DEBUGGING
10316 if (ECOFF_DEBUGGING
10318 && ! ecoff_debugging_seen)
10319 flag_keep_locals = 1;
10323 /* Sort any unmatched HI16_S relocs so that they immediately precede
10324 the corresponding LO reloc. This is called before md_apply_fix3 and
10325 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10326 explicit use of the %hi modifier. */
10331 struct mips_hi_fixup *l;
10333 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
10335 segment_info_type *seginfo;
10338 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
10340 /* Check quickly whether the next fixup happens to be a matching
10342 if (l->fixp->fx_next != NULL
10343 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
10344 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
10345 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
10348 /* Look through the fixups for this segment for a matching %lo.
10349 When we find one, move the %hi just in front of it. We do
10350 this in two passes. In the first pass, we try to find a
10351 unique %lo. In the second pass, we permit multiple %hi
10352 relocs for a single %lo (this is a GNU extension). */
10353 seginfo = seg_info (l->seg);
10354 for (pass = 0; pass < 2; pass++)
10359 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
10361 /* Check whether this is a %lo fixup which matches l->fixp. */
10362 if (f->fx_r_type == BFD_RELOC_LO16
10363 && f->fx_addsy == l->fixp->fx_addsy
10364 && f->fx_offset == l->fixp->fx_offset
10367 || prev->fx_r_type != BFD_RELOC_HI16_S
10368 || prev->fx_addsy != f->fx_addsy
10369 || prev->fx_offset != f->fx_offset))
10373 /* Move l->fixp before f. */
10374 for (pf = &seginfo->fix_root;
10376 pf = &(*pf)->fx_next)
10377 assert (*pf != NULL);
10379 *pf = l->fixp->fx_next;
10381 l->fixp->fx_next = f;
10383 seginfo->fix_root = l->fixp;
10385 prev->fx_next = l->fixp;
10396 #if 0 /* GCC code motion plus incomplete dead code elimination
10397 can leave a %hi without a %lo. */
10399 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
10400 _("Unmatched %%hi reloc"));
10406 /* When generating embedded PIC code we need to use a special
10407 relocation to represent the difference of two symbols in the .text
10408 section (switch tables use a difference of this sort). See
10409 include/coff/mips.h for details. This macro checks whether this
10410 fixup requires the special reloc. */
10411 #define SWITCH_TABLE(fixp) \
10412 ((fixp)->fx_r_type == BFD_RELOC_32 \
10413 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10414 && (fixp)->fx_addsy != NULL \
10415 && (fixp)->fx_subsy != NULL \
10416 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10417 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10419 /* When generating embedded PIC code we must keep all PC relative
10420 relocations, in case the linker has to relax a call. We also need
10421 to keep relocations for switch table entries.
10423 We may have combined relocations without symbols in the N32/N64 ABI.
10424 We have to prevent gas from dropping them. */
10427 mips_force_relocation (fixp)
10430 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10431 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
10435 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
10436 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
10437 || fixp->fx_r_type == BFD_RELOC_HI16_S
10438 || fixp->fx_r_type == BFD_RELOC_LO16))
10441 return (mips_pic == EMBEDDED_PIC
10443 || SWITCH_TABLE (fixp)
10444 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
10445 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
10450 mips_need_elf_addend_fixup (fixP)
10453 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
10455 if (mips_pic == EMBEDDED_PIC
10456 && S_IS_WEAK (fixP->fx_addsy))
10458 if (mips_pic != EMBEDDED_PIC
10459 && (S_IS_WEAK (fixP->fx_addsy)
10460 || S_IS_EXTERN (fixP->fx_addsy))
10461 && !S_IS_COMMON (fixP->fx_addsy))
10463 if (symbol_used_in_reloc_p (fixP->fx_addsy)
10464 && (((bfd_get_section_flags (stdoutput,
10465 S_GET_SEGMENT (fixP->fx_addsy))
10466 & SEC_LINK_ONCE) != 0)
10467 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
10469 sizeof (".gnu.linkonce") - 1)))
10475 /* Apply a fixup to the object file. */
10478 md_apply_fix3 (fixP, valP, seg)
10481 segT seg ATTRIBUTE_UNUSED;
10487 assert (fixP->fx_size == 4
10488 || fixP->fx_r_type == BFD_RELOC_16
10489 || fixP->fx_r_type == BFD_RELOC_32
10490 || fixP->fx_r_type == BFD_RELOC_MIPS_JMP
10491 || fixP->fx_r_type == BFD_RELOC_HI16_S
10492 || fixP->fx_r_type == BFD_RELOC_LO16
10493 || fixP->fx_r_type == BFD_RELOC_GPREL16
10494 || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL
10495 || fixP->fx_r_type == BFD_RELOC_GPREL32
10496 || fixP->fx_r_type == BFD_RELOC_64
10497 || fixP->fx_r_type == BFD_RELOC_CTOR
10498 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
10499 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST
10500 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER
10501 || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP
10502 || fixP->fx_r_type == BFD_RELOC_MIPS_REL16
10503 || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT
10504 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10505 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
10509 /* If we aren't adjusting this fixup to be against the section
10510 symbol, we need to adjust the value. */
10512 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
10514 if (mips_need_elf_addend_fixup (fixP))
10516 valueT symval = S_GET_VALUE (fixP->fx_addsy);
10519 if (value != 0 && ! fixP->fx_pcrel)
10521 /* In this case, the bfd_install_relocation routine will
10522 incorrectly add the symbol value back in. We just want
10523 the addend to appear in the object file. */
10526 /* Make sure the addend is still non-zero. If it became zero
10527 after the last operation, set it to a spurious value and
10528 subtract the same value from the object file's contents. */
10533 /* The in-place addends for LO16 relocations are signed;
10534 leave the matching HI16 in-place addends as zero. */
10535 if (fixP->fx_r_type != BFD_RELOC_HI16_S)
10537 reloc_howto_type *howto;
10538 bfd_vma contents, mask, field;
10540 howto = bfd_reloc_type_lookup (stdoutput,
10543 contents = bfd_get_bits (fixP->fx_frag->fr_literal
10546 target_big_endian);
10548 /* MASK has bits set where the relocation should go.
10549 FIELD is -value, shifted into the appropriate place
10550 for this relocation. */
10551 mask = 1 << (howto->bitsize - 1);
10552 mask = (((mask - 1) << 1) | 1) << howto->bitpos;
10553 field = (-value >> howto->rightshift) << howto->bitpos;
10555 bfd_put_bits ((field & mask) | (contents & ~mask),
10556 fixP->fx_frag->fr_literal + fixP->fx_where,
10558 target_big_endian);
10564 /* This code was generated using trial and error and so is
10565 fragile and not trustworthy. If you change it, you should
10566 rerun the elf-rel, elf-rel2, and empic testcases and ensure
10567 they still pass. */
10568 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
10570 value += fixP->fx_frag->fr_address + fixP->fx_where;
10572 /* BFD's REL handling, for MIPS, is _very_ weird.
10573 This gives the right results, but it can't possibly
10574 be the way things are supposed to work. */
10575 if ((fixP->fx_r_type != BFD_RELOC_16_PCREL
10576 && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
10577 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
10578 value += fixP->fx_frag->fr_address + fixP->fx_where;
10583 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */
10585 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
10588 switch (fixP->fx_r_type)
10590 case BFD_RELOC_MIPS_JMP:
10591 case BFD_RELOC_MIPS_SHIFT5:
10592 case BFD_RELOC_MIPS_SHIFT6:
10593 case BFD_RELOC_MIPS_GOT_DISP:
10594 case BFD_RELOC_MIPS_GOT_PAGE:
10595 case BFD_RELOC_MIPS_GOT_OFST:
10596 case BFD_RELOC_MIPS_SUB:
10597 case BFD_RELOC_MIPS_INSERT_A:
10598 case BFD_RELOC_MIPS_INSERT_B:
10599 case BFD_RELOC_MIPS_DELETE:
10600 case BFD_RELOC_MIPS_HIGHEST:
10601 case BFD_RELOC_MIPS_HIGHER:
10602 case BFD_RELOC_MIPS_SCN_DISP:
10603 case BFD_RELOC_MIPS_REL16:
10604 case BFD_RELOC_MIPS_RELGOT:
10605 case BFD_RELOC_MIPS_JALR:
10606 case BFD_RELOC_HI16:
10607 case BFD_RELOC_HI16_S:
10608 case BFD_RELOC_GPREL16:
10609 case BFD_RELOC_MIPS_LITERAL:
10610 case BFD_RELOC_MIPS_CALL16:
10611 case BFD_RELOC_MIPS_GOT16:
10612 case BFD_RELOC_GPREL32:
10613 case BFD_RELOC_MIPS_GOT_HI16:
10614 case BFD_RELOC_MIPS_GOT_LO16:
10615 case BFD_RELOC_MIPS_CALL_HI16:
10616 case BFD_RELOC_MIPS_CALL_LO16:
10617 case BFD_RELOC_MIPS16_GPREL:
10618 if (fixP->fx_pcrel)
10619 as_bad_where (fixP->fx_file, fixP->fx_line,
10620 _("Invalid PC relative reloc"));
10621 /* Nothing needed to do. The value comes from the reloc entry */
10624 case BFD_RELOC_MIPS16_JMP:
10625 /* We currently always generate a reloc against a symbol, which
10626 means that we don't want an addend even if the symbol is
10628 fixP->fx_addnumber = 0;
10631 case BFD_RELOC_PCREL_HI16_S:
10632 /* The addend for this is tricky if it is internal, so we just
10633 do everything here rather than in bfd_install_relocation. */
10634 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10639 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10641 /* For an external symbol adjust by the address to make it
10642 pcrel_offset. We use the address of the RELLO reloc
10643 which follows this one. */
10644 value += (fixP->fx_next->fx_frag->fr_address
10645 + fixP->fx_next->fx_where);
10647 value = ((value + 0x8000) >> 16) & 0xffff;
10648 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10649 if (target_big_endian)
10651 md_number_to_chars ((char *) buf, value, 2);
10654 case BFD_RELOC_PCREL_LO16:
10655 /* The addend for this is tricky if it is internal, so we just
10656 do everything here rather than in bfd_install_relocation. */
10657 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10662 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10663 value += fixP->fx_frag->fr_address + fixP->fx_where;
10664 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10665 if (target_big_endian)
10667 md_number_to_chars ((char *) buf, value, 2);
10671 /* This is handled like BFD_RELOC_32, but we output a sign
10672 extended value if we are only 32 bits. */
10674 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10676 if (8 <= sizeof (valueT))
10677 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10684 w1 = w2 = fixP->fx_where;
10685 if (target_big_endian)
10689 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
10690 if ((value & 0x80000000) != 0)
10694 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
10699 case BFD_RELOC_RVA:
10701 /* If we are deleting this reloc entry, we must fill in the
10702 value now. This can happen if we have a .word which is not
10703 resolved when it appears but is later defined. We also need
10704 to fill in the value if this is an embedded PIC switch table
10707 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10708 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10713 /* If we are deleting this reloc entry, we must fill in the
10715 assert (fixP->fx_size == 2);
10717 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10721 case BFD_RELOC_LO16:
10722 /* When handling an embedded PIC switch statement, we can wind
10723 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
10726 if (value + 0x8000 > 0xffff)
10727 as_bad_where (fixP->fx_file, fixP->fx_line,
10728 _("relocation overflow"));
10729 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
10730 if (target_big_endian)
10732 md_number_to_chars ((char *) buf, value, 2);
10736 case BFD_RELOC_16_PCREL_S2:
10737 if ((value & 0x3) != 0)
10738 as_bad_where (fixP->fx_file, fixP->fx_line,
10739 _("Branch to odd address (%lx)"), (long) value);
10741 /* Fall through. */
10743 case BFD_RELOC_16_PCREL:
10745 * We need to save the bits in the instruction since fixup_segment()
10746 * might be deleting the relocation entry (i.e., a branch within
10747 * the current segment).
10749 if (!fixP->fx_done && value != 0)
10751 /* If 'value' is zero, the remaining reloc code won't actually
10752 do the store, so it must be done here. This is probably
10753 a bug somewhere. */
10755 && (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
10756 || fixP->fx_addsy == NULL /* ??? */
10757 || ! S_IS_DEFINED (fixP->fx_addsy)))
10758 value -= fixP->fx_frag->fr_address + fixP->fx_where;
10760 value = (offsetT) value >> 2;
10762 /* update old instruction data */
10763 buf = (bfd_byte *) (fixP->fx_where + fixP->fx_frag->fr_literal);
10764 if (target_big_endian)
10765 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
10767 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
10769 if (value + 0x8000 <= 0xffff)
10770 insn |= value & 0xffff;
10773 /* The branch offset is too large. If this is an
10774 unconditional branch, and we are not generating PIC code,
10775 we can convert it to an absolute jump instruction. */
10776 if (mips_pic == NO_PIC
10778 && fixP->fx_frag->fr_address >= text_section->vma
10779 && (fixP->fx_frag->fr_address
10780 < text_section->vma + text_section->_raw_size)
10781 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
10782 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
10783 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
10785 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
10786 insn = 0x0c000000; /* jal */
10788 insn = 0x08000000; /* j */
10789 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
10791 fixP->fx_addsy = section_symbol (text_section);
10792 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
10796 /* FIXME. It would be possible in principle to handle
10797 conditional branches which overflow. They could be
10798 transformed into a branch around a jump. This would
10799 require setting up variant frags for each different
10800 branch type. The native MIPS assembler attempts to
10801 handle these cases, but it appears to do it
10803 as_bad_where (fixP->fx_file, fixP->fx_line,
10804 _("Branch out of range"));
10808 md_number_to_chars ((char *) buf, (valueT) insn, 4);
10811 case BFD_RELOC_VTABLE_INHERIT:
10814 && !S_IS_DEFINED (fixP->fx_addsy)
10815 && !S_IS_WEAK (fixP->fx_addsy))
10816 S_SET_WEAK (fixP->fx_addsy);
10819 case BFD_RELOC_VTABLE_ENTRY:
10833 const struct mips_opcode *p;
10834 int treg, sreg, dreg, shamt;
10839 for (i = 0; i < NUMOPCODES; ++i)
10841 p = &mips_opcodes[i];
10842 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
10844 printf ("%08lx %s\t", oc, p->name);
10845 treg = (oc >> 16) & 0x1f;
10846 sreg = (oc >> 21) & 0x1f;
10847 dreg = (oc >> 11) & 0x1f;
10848 shamt = (oc >> 6) & 0x1f;
10850 for (args = p->args;; ++args)
10861 printf ("%c", *args);
10865 assert (treg == sreg);
10866 printf ("$%d,$%d", treg, sreg);
10871 printf ("$%d", dreg);
10876 printf ("$%d", treg);
10880 printf ("0x%x", treg);
10885 printf ("$%d", sreg);
10889 printf ("0x%08lx", oc & 0x1ffffff);
10896 printf ("%d", imm);
10901 printf ("$%d", shamt);
10912 printf (_("%08lx UNDEFINED\n"), oc);
10923 name = input_line_pointer;
10924 c = get_symbol_end ();
10925 p = (symbolS *) symbol_find_or_make (name);
10926 *input_line_pointer = c;
10930 /* Align the current frag to a given power of two. The MIPS assembler
10931 also automatically adjusts any preceding label. */
10934 mips_align (to, fill, label)
10939 mips_emit_delays (false);
10940 frag_align (to, fill, 0);
10941 record_alignment (now_seg, to);
10944 assert (S_GET_SEGMENT (label) == now_seg);
10945 symbol_set_frag (label, frag_now);
10946 S_SET_VALUE (label, (valueT) frag_now_fix ());
10950 /* Align to a given power of two. .align 0 turns off the automatic
10951 alignment used by the data creating pseudo-ops. */
10955 int x ATTRIBUTE_UNUSED;
10958 register long temp_fill;
10959 long max_alignment = 15;
10963 o Note that the assembler pulls down any immediately preceeding label
10964 to the aligned address.
10965 o It's not documented but auto alignment is reinstated by
10966 a .align pseudo instruction.
10967 o Note also that after auto alignment is turned off the mips assembler
10968 issues an error on attempt to assemble an improperly aligned data item.
10973 temp = get_absolute_expression ();
10974 if (temp > max_alignment)
10975 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
10978 as_warn (_("Alignment negative: 0 assumed."));
10981 if (*input_line_pointer == ',')
10983 input_line_pointer++;
10984 temp_fill = get_absolute_expression ();
10991 mips_align (temp, (int) temp_fill,
10992 insn_labels != NULL ? insn_labels->label : NULL);
10999 demand_empty_rest_of_line ();
11003 mips_flush_pending_output ()
11005 mips_emit_delays (false);
11006 mips_clear_insn_labels ();
11015 /* When generating embedded PIC code, we only use the .text, .lit8,
11016 .sdata and .sbss sections. We change the .data and .rdata
11017 pseudo-ops to use .sdata. */
11018 if (mips_pic == EMBEDDED_PIC
11019 && (sec == 'd' || sec == 'r'))
11023 /* The ELF backend needs to know that we are changing sections, so
11024 that .previous works correctly. We could do something like check
11025 for an obj_section_change_hook macro, but that might be confusing
11026 as it would not be appropriate to use it in the section changing
11027 functions in read.c, since obj-elf.c intercepts those. FIXME:
11028 This should be cleaner, somehow. */
11029 obj_elf_section_change_hook ();
11032 mips_emit_delays (false);
11042 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11043 demand_empty_rest_of_line ();
11047 if (USE_GLOBAL_POINTER_OPT)
11049 seg = subseg_new (RDATA_SECTION_NAME,
11050 (subsegT) get_absolute_expression ());
11051 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11053 bfd_set_section_flags (stdoutput, seg,
11059 if (strcmp (TARGET_OS, "elf") != 0)
11060 record_alignment (seg, 4);
11062 demand_empty_rest_of_line ();
11066 as_bad (_("No read only data section in this object file format"));
11067 demand_empty_rest_of_line ();
11073 if (USE_GLOBAL_POINTER_OPT)
11075 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11076 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11078 bfd_set_section_flags (stdoutput, seg,
11079 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11081 if (strcmp (TARGET_OS, "elf") != 0)
11082 record_alignment (seg, 4);
11084 demand_empty_rest_of_line ();
11089 as_bad (_("Global pointers not supported; recompile -G 0"));
11090 demand_empty_rest_of_line ();
11099 mips_enable_auto_align ()
11110 label = insn_labels != NULL ? insn_labels->label : NULL;
11111 mips_emit_delays (false);
11112 if (log_size > 0 && auto_align)
11113 mips_align (log_size, 0, label);
11114 mips_clear_insn_labels ();
11115 cons (1 << log_size);
11119 s_float_cons (type)
11124 label = insn_labels != NULL ? insn_labels->label : NULL;
11126 mips_emit_delays (false);
11131 mips_align (3, 0, label);
11133 mips_align (2, 0, label);
11136 mips_clear_insn_labels ();
11141 /* Handle .globl. We need to override it because on Irix 5 you are
11144 where foo is an undefined symbol, to mean that foo should be
11145 considered to be the address of a function. */
11149 int x ATTRIBUTE_UNUSED;
11156 name = input_line_pointer;
11157 c = get_symbol_end ();
11158 symbolP = symbol_find_or_make (name);
11159 *input_line_pointer = c;
11160 SKIP_WHITESPACE ();
11162 /* On Irix 5, every global symbol that is not explicitly labelled as
11163 being a function is apparently labelled as being an object. */
11166 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11171 secname = input_line_pointer;
11172 c = get_symbol_end ();
11173 sec = bfd_get_section_by_name (stdoutput, secname);
11175 as_bad (_("%s: no such section"), secname);
11176 *input_line_pointer = c;
11178 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11179 flag = BSF_FUNCTION;
11182 symbol_get_bfdsym (symbolP)->flags |= flag;
11184 S_SET_EXTERNAL (symbolP);
11185 demand_empty_rest_of_line ();
11190 int x ATTRIBUTE_UNUSED;
11195 opt = input_line_pointer;
11196 c = get_symbol_end ();
11200 /* FIXME: What does this mean? */
11202 else if (strncmp (opt, "pic", 3) == 0)
11206 i = atoi (opt + 3);
11210 mips_pic = SVR4_PIC;
11212 as_bad (_(".option pic%d not supported"), i);
11214 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
11216 if (g_switch_seen && g_switch_value != 0)
11217 as_warn (_("-G may not be used with SVR4 PIC code"));
11218 g_switch_value = 0;
11219 bfd_set_gp_size (stdoutput, 0);
11223 as_warn (_("Unrecognized option \"%s\""), opt);
11225 *input_line_pointer = c;
11226 demand_empty_rest_of_line ();
11229 /* This structure is used to hold a stack of .set values. */
11231 struct mips_option_stack
11233 struct mips_option_stack *next;
11234 struct mips_set_options options;
11237 static struct mips_option_stack *mips_opts_stack;
11239 /* Handle the .set pseudo-op. */
11243 int x ATTRIBUTE_UNUSED;
11245 char *name = input_line_pointer, ch;
11247 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11248 input_line_pointer++;
11249 ch = *input_line_pointer;
11250 *input_line_pointer = '\0';
11252 if (strcmp (name, "reorder") == 0)
11254 if (mips_opts.noreorder && prev_nop_frag != NULL)
11256 /* If we still have pending nops, we can discard them. The
11257 usual nop handling will insert any that are still
11259 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11260 * (mips_opts.mips16 ? 2 : 4));
11261 prev_nop_frag = NULL;
11263 mips_opts.noreorder = 0;
11265 else if (strcmp (name, "noreorder") == 0)
11267 mips_emit_delays (true);
11268 mips_opts.noreorder = 1;
11269 mips_any_noreorder = 1;
11271 else if (strcmp (name, "at") == 0)
11273 mips_opts.noat = 0;
11275 else if (strcmp (name, "noat") == 0)
11277 mips_opts.noat = 1;
11279 else if (strcmp (name, "macro") == 0)
11281 mips_opts.warn_about_macros = 0;
11283 else if (strcmp (name, "nomacro") == 0)
11285 if (mips_opts.noreorder == 0)
11286 as_bad (_("`noreorder' must be set before `nomacro'"));
11287 mips_opts.warn_about_macros = 1;
11289 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11291 mips_opts.nomove = 0;
11293 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11295 mips_opts.nomove = 1;
11297 else if (strcmp (name, "bopt") == 0)
11299 mips_opts.nobopt = 0;
11301 else if (strcmp (name, "nobopt") == 0)
11303 mips_opts.nobopt = 1;
11305 else if (strcmp (name, "mips16") == 0
11306 || strcmp (name, "MIPS-16") == 0)
11307 mips_opts.mips16 = 1;
11308 else if (strcmp (name, "nomips16") == 0
11309 || strcmp (name, "noMIPS-16") == 0)
11310 mips_opts.mips16 = 0;
11311 else if (strcmp (name, "mips3d") == 0)
11312 mips_opts.ase_mips3d = 1;
11313 else if (strcmp (name, "nomips3d") == 0)
11314 mips_opts.ase_mips3d = 0;
11315 else if (strncmp (name, "mips", 4) == 0)
11319 /* Permit the user to change the ISA on the fly. Needless to
11320 say, misuse can cause serious problems. */
11321 isa = atoi (name + 4);
11325 mips_opts.gp32 = file_mips_gp32;
11326 mips_opts.fp32 = file_mips_fp32;
11327 mips_opts.abi = file_mips_abi;
11332 mips_opts.gp32 = 1;
11333 mips_opts.fp32 = 1;
11339 /* Loosen ABI register width restriction. */
11340 if (mips_opts.abi == O32_ABI)
11341 mips_opts.abi = NO_ABI;
11342 mips_opts.gp32 = 0;
11343 mips_opts.fp32 = 0;
11346 as_bad (_("unknown ISA level %s"), name + 4);
11352 case 0: mips_opts.isa = file_mips_isa; break;
11353 case 1: mips_opts.isa = ISA_MIPS1; break;
11354 case 2: mips_opts.isa = ISA_MIPS2; break;
11355 case 3: mips_opts.isa = ISA_MIPS3; break;
11356 case 4: mips_opts.isa = ISA_MIPS4; break;
11357 case 5: mips_opts.isa = ISA_MIPS5; break;
11358 case 32: mips_opts.isa = ISA_MIPS32; break;
11359 case 64: mips_opts.isa = ISA_MIPS64; break;
11360 default: as_bad (_("unknown ISA level %s"), name + 4); break;
11363 else if (strcmp (name, "autoextend") == 0)
11364 mips_opts.noautoextend = 0;
11365 else if (strcmp (name, "noautoextend") == 0)
11366 mips_opts.noautoextend = 1;
11367 else if (strcmp (name, "push") == 0)
11369 struct mips_option_stack *s;
11371 s = (struct mips_option_stack *) xmalloc (sizeof *s);
11372 s->next = mips_opts_stack;
11373 s->options = mips_opts;
11374 mips_opts_stack = s;
11376 else if (strcmp (name, "pop") == 0)
11378 struct mips_option_stack *s;
11380 s = mips_opts_stack;
11382 as_bad (_(".set pop with no .set push"));
11385 /* If we're changing the reorder mode we need to handle
11386 delay slots correctly. */
11387 if (s->options.noreorder && ! mips_opts.noreorder)
11388 mips_emit_delays (true);
11389 else if (! s->options.noreorder && mips_opts.noreorder)
11391 if (prev_nop_frag != NULL)
11393 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11394 * (mips_opts.mips16 ? 2 : 4));
11395 prev_nop_frag = NULL;
11399 mips_opts = s->options;
11400 mips_opts_stack = s->next;
11406 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
11408 *input_line_pointer = ch;
11409 demand_empty_rest_of_line ();
11412 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11413 .option pic2. It means to generate SVR4 PIC calls. */
11416 s_abicalls (ignore)
11417 int ignore ATTRIBUTE_UNUSED;
11419 mips_pic = SVR4_PIC;
11420 if (USE_GLOBAL_POINTER_OPT)
11422 if (g_switch_seen && g_switch_value != 0)
11423 as_warn (_("-G may not be used with SVR4 PIC code"));
11424 g_switch_value = 0;
11426 bfd_set_gp_size (stdoutput, 0);
11427 demand_empty_rest_of_line ();
11430 /* Handle the .cpload pseudo-op. This is used when generating SVR4
11431 PIC code. It sets the $gp register for the function based on the
11432 function address, which is in the register named in the argument.
11433 This uses a relocation against _gp_disp, which is handled specially
11434 by the linker. The result is:
11435 lui $gp,%hi(_gp_disp)
11436 addiu $gp,$gp,%lo(_gp_disp)
11437 addu $gp,$gp,.cpload argument
11438 The .cpload argument is normally $25 == $t9. */
11442 int ignore ATTRIBUTE_UNUSED;
11447 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11448 .cpload is ignored. */
11449 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11455 /* .cpload should be in a .set noreorder section. */
11456 if (mips_opts.noreorder == 0)
11457 as_warn (_(".cpload not in noreorder section"));
11459 ex.X_op = O_symbol;
11460 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
11461 ex.X_op_symbol = NULL;
11462 ex.X_add_number = 0;
11464 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
11465 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
11467 macro_build_lui (NULL, &icnt, &ex, GP);
11468 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP,
11469 (int) BFD_RELOC_LO16);
11471 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
11472 GP, GP, tc_get_register (0));
11474 demand_empty_rest_of_line ();
11477 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
11478 .cpsetup $reg1, offset|$reg2, label
11480 If offset is given, this results in:
11481 sd $gp, offset($sp)
11482 lui $gp, %hi(%neg(%gp_rel(label)))
11483 daddiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11484 addu $gp, $gp, $reg1
11486 If $reg2 is given, this results in:
11487 daddu $reg2, $gp, $0
11488 lui $gp, %hi(%neg(%gp_rel(label)))
11489 daddiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11490 addu $gp, $gp, $reg1
11494 int ignore ATTRIBUTE_UNUSED;
11496 expressionS ex_off;
11497 expressionS ex_sym;
11502 /* If we are not generating SVR4 PIC code, .cpload is ignored.
11503 We also need NewABI support. */
11504 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11510 reg1 = tc_get_register (0);
11511 SKIP_WHITESPACE ();
11512 if (*input_line_pointer != ',')
11514 as_bad (_("missing argument separator ',' for .cpsetup"));
11518 input_line_pointer++;
11519 SKIP_WHITESPACE ();
11520 if (*input_line_pointer == '$')
11521 mips_cpreturn_register = tc_get_register (0);
11523 mips_cpreturn_offset = get_absolute_expression ();
11524 SKIP_WHITESPACE ();
11525 if (*input_line_pointer != ',')
11527 as_bad (_("missing argument separator ',' for .cpsetup"));
11531 input_line_pointer++;
11532 SKIP_WHITESPACE ();
11533 sym = input_line_pointer;
11534 while (ISALNUM (*input_line_pointer))
11535 input_line_pointer++;
11536 *input_line_pointer = 0;
11538 ex_sym.X_op = O_symbol;
11539 ex_sym.X_add_symbol = symbol_find_or_make (sym);
11540 ex_sym.X_op_symbol = NULL;
11541 ex_sym.X_add_number = 0;
11543 if (mips_cpreturn_register == -1)
11545 ex_off.X_op = O_constant;
11546 ex_off.X_add_symbol = NULL;
11547 ex_off.X_op_symbol = NULL;
11548 ex_off.X_add_number = mips_cpreturn_offset;
11550 macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)",
11551 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11554 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11555 "d,v,t", mips_cpreturn_register, mips_gp_register, 0);
11557 macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
11558 (int) BFD_RELOC_GPREL16);
11559 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11560 NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11561 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11562 NULL, 0, 0, BFD_RELOC_HI16_S);
11563 macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j",
11564 mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16);
11565 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11566 NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11567 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11568 NULL, 0, 0, BFD_RELOC_LO16);
11569 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11570 "d,v,t", mips_gp_register, mips_gp_register, reg1);
11572 demand_empty_rest_of_line ();
11577 int ignore ATTRIBUTE_UNUSED;
11579 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
11580 .cplocal is ignored. */
11581 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11587 mips_gp_register = tc_get_register (0);
11590 /* Handle the .cprestore pseudo-op. This stores $gp into a given
11591 offset from $sp. The offset is remembered, and after making a PIC
11592 call $gp is restored from that location. */
11595 s_cprestore (ignore)
11596 int ignore ATTRIBUTE_UNUSED;
11601 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11602 .cprestore is ignored. */
11603 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11609 mips_cprestore_offset = get_absolute_expression ();
11610 mips_cprestore_valid = 1;
11612 ex.X_op = O_constant;
11613 ex.X_add_symbol = NULL;
11614 ex.X_op_symbol = NULL;
11615 ex.X_add_number = mips_cprestore_offset;
11617 macro_build ((char *) NULL, &icnt, &ex,
11618 HAVE_32BIT_ADDRESSES ? "sw" : "sd",
11619 "t,o(b)", GP, (int) BFD_RELOC_LO16, SP);
11621 demand_empty_rest_of_line ();
11624 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
11625 was given in the preceeding .gpsetup, it results in:
11626 ld $gp, offset($sp)
11628 If a register $reg2 was given there, it results in:
11629 daddiu $gp, $gp, $reg2
11632 s_cpreturn (ignore)
11633 int ignore ATTRIBUTE_UNUSED;
11638 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
11639 We also need NewABI support. */
11640 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11646 if (mips_cpreturn_register == -1)
11648 ex.X_op = O_constant;
11649 ex.X_add_symbol = NULL;
11650 ex.X_op_symbol = NULL;
11651 ex.X_add_number = mips_cpreturn_offset;
11653 macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)",
11654 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11657 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11658 "d,v,t", mips_gp_register, mips_cpreturn_register, 0);
11660 demand_empty_rest_of_line ();
11663 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
11664 code. It sets the offset to use in gp_rel relocations. */
11668 int ignore ATTRIBUTE_UNUSED;
11670 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
11671 We also need NewABI support. */
11672 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11678 mips_cpreturn_offset = get_absolute_expression ();
11680 demand_empty_rest_of_line ();
11683 /* Handle the .gpword pseudo-op. This is used when generating PIC
11684 code. It generates a 32 bit GP relative reloc. */
11688 int ignore ATTRIBUTE_UNUSED;
11694 /* When not generating PIC code, this is treated as .word. */
11695 if (mips_pic != SVR4_PIC)
11701 label = insn_labels != NULL ? insn_labels->label : NULL;
11702 mips_emit_delays (true);
11704 mips_align (2, 0, label);
11705 mips_clear_insn_labels ();
11709 if (ex.X_op != O_symbol || ex.X_add_number != 0)
11711 as_bad (_("Unsupported use of .gpword"));
11712 ignore_rest_of_line ();
11716 md_number_to_chars (p, (valueT) 0, 4);
11717 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0,
11718 BFD_RELOC_GPREL32);
11720 demand_empty_rest_of_line ();
11723 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
11724 tables in SVR4 PIC code. */
11728 int ignore ATTRIBUTE_UNUSED;
11733 /* This is ignored when not generating SVR4 PIC code or if this is NewABI
11735 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11741 /* Add $gp to the register named as an argument. */
11742 reg = tc_get_register (0);
11743 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11744 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
11745 "d,v,t", reg, reg, GP);
11747 demand_empty_rest_of_line ();
11750 /* Handle the .insn pseudo-op. This marks instruction labels in
11751 mips16 mode. This permits the linker to handle them specially,
11752 such as generating jalx instructions when needed. We also make
11753 them odd for the duration of the assembly, in order to generate the
11754 right sort of code. We will make them even in the adjust_symtab
11755 routine, while leaving them marked. This is convenient for the
11756 debugger and the disassembler. The linker knows to make them odd
11761 int ignore ATTRIBUTE_UNUSED;
11763 if (mips_opts.mips16)
11764 mips16_mark_labels ();
11766 demand_empty_rest_of_line ();
11769 /* Handle a .stabn directive. We need these in order to mark a label
11770 as being a mips16 text label correctly. Sometimes the compiler
11771 will emit a label, followed by a .stabn, and then switch sections.
11772 If the label and .stabn are in mips16 mode, then the label is
11773 really a mips16 text label. */
11779 if (type == 'n' && mips_opts.mips16)
11780 mips16_mark_labels ();
11785 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
11789 s_mips_weakext (ignore)
11790 int ignore ATTRIBUTE_UNUSED;
11797 name = input_line_pointer;
11798 c = get_symbol_end ();
11799 symbolP = symbol_find_or_make (name);
11800 S_SET_WEAK (symbolP);
11801 *input_line_pointer = c;
11803 SKIP_WHITESPACE ();
11805 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11807 if (S_IS_DEFINED (symbolP))
11809 as_bad ("ignoring attempt to redefine symbol %s",
11810 S_GET_NAME (symbolP));
11811 ignore_rest_of_line ();
11815 if (*input_line_pointer == ',')
11817 ++input_line_pointer;
11818 SKIP_WHITESPACE ();
11822 if (exp.X_op != O_symbol)
11824 as_bad ("bad .weakext directive");
11825 ignore_rest_of_line();
11828 symbol_set_value_expression (symbolP, &exp);
11831 demand_empty_rest_of_line ();
11834 /* Parse a register string into a number. Called from the ECOFF code
11835 to parse .frame. The argument is non-zero if this is the frame
11836 register, so that we can record it in mips_frame_reg. */
11839 tc_get_register (frame)
11844 SKIP_WHITESPACE ();
11845 if (*input_line_pointer++ != '$')
11847 as_warn (_("expected `$'"));
11850 else if (ISDIGIT (*input_line_pointer))
11852 reg = get_absolute_expression ();
11853 if (reg < 0 || reg >= 32)
11855 as_warn (_("Bad register number"));
11861 if (strncmp (input_line_pointer, "fp", 2) == 0)
11863 else if (strncmp (input_line_pointer, "sp", 2) == 0)
11865 else if (strncmp (input_line_pointer, "gp", 2) == 0)
11867 else if (strncmp (input_line_pointer, "at", 2) == 0)
11871 as_warn (_("Unrecognized register name"));
11874 input_line_pointer += 2;
11878 mips_frame_reg = reg != 0 ? reg : SP;
11879 mips_frame_reg_valid = 1;
11880 mips_cprestore_valid = 0;
11886 md_section_align (seg, addr)
11890 int align = bfd_get_section_alignment (stdoutput, seg);
11893 /* We don't need to align ELF sections to the full alignment.
11894 However, Irix 5 may prefer that we align them at least to a 16
11895 byte boundary. We don't bother to align the sections if we are
11896 targeted for an embedded system. */
11897 if (strcmp (TARGET_OS, "elf") == 0)
11903 return ((addr + (1 << align) - 1) & (-1 << align));
11906 /* Utility routine, called from above as well. If called while the
11907 input file is still being read, it's only an approximation. (For
11908 example, a symbol may later become defined which appeared to be
11909 undefined earlier.) */
11912 nopic_need_relax (sym, before_relaxing)
11914 int before_relaxing;
11919 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
11921 const char *symname;
11924 /* Find out whether this symbol can be referenced off the GP
11925 register. It can be if it is smaller than the -G size or if
11926 it is in the .sdata or .sbss section. Certain symbols can
11927 not be referenced off the GP, although it appears as though
11929 symname = S_GET_NAME (sym);
11930 if (symname != (const char *) NULL
11931 && (strcmp (symname, "eprol") == 0
11932 || strcmp (symname, "etext") == 0
11933 || strcmp (symname, "_gp") == 0
11934 || strcmp (symname, "edata") == 0
11935 || strcmp (symname, "_fbss") == 0
11936 || strcmp (symname, "_fdata") == 0
11937 || strcmp (symname, "_ftext") == 0
11938 || strcmp (symname, "end") == 0
11939 || strcmp (symname, "_gp_disp") == 0))
11941 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
11943 #ifndef NO_ECOFF_DEBUGGING
11944 || (symbol_get_obj (sym)->ecoff_extern_size != 0
11945 && (symbol_get_obj (sym)->ecoff_extern_size
11946 <= g_switch_value))
11948 /* We must defer this decision until after the whole
11949 file has been read, since there might be a .extern
11950 after the first use of this symbol. */
11951 || (before_relaxing
11952 #ifndef NO_ECOFF_DEBUGGING
11953 && symbol_get_obj (sym)->ecoff_extern_size == 0
11955 && S_GET_VALUE (sym) == 0)
11956 || (S_GET_VALUE (sym) != 0
11957 && S_GET_VALUE (sym) <= g_switch_value)))
11961 const char *segname;
11963 segname = segment_name (S_GET_SEGMENT (sym));
11964 assert (strcmp (segname, ".lit8") != 0
11965 && strcmp (segname, ".lit4") != 0);
11966 change = (strcmp (segname, ".sdata") != 0
11967 && strcmp (segname, ".sbss") != 0
11968 && strncmp (segname, ".sdata.", 7) != 0
11969 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
11974 /* We are not optimizing for the GP register. */
11978 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
11979 extended opcode. SEC is the section the frag is in. */
11982 mips16_extended_frag (fragp, sec, stretch)
11988 register const struct mips16_immed_operand *op;
11990 int mintiny, maxtiny;
11994 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
11996 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
11999 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12000 op = mips16_immed_operands;
12001 while (op->type != type)
12004 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12009 if (type == '<' || type == '>' || type == '[' || type == ']')
12012 maxtiny = 1 << op->nbits;
12017 maxtiny = (1 << op->nbits) - 1;
12022 mintiny = - (1 << (op->nbits - 1));
12023 maxtiny = (1 << (op->nbits - 1)) - 1;
12026 sym_frag = symbol_get_frag (fragp->fr_symbol);
12027 val = S_GET_VALUE (fragp->fr_symbol);
12028 symsec = S_GET_SEGMENT (fragp->fr_symbol);
12034 /* We won't have the section when we are called from
12035 mips_relax_frag. However, we will always have been called
12036 from md_estimate_size_before_relax first. If this is a
12037 branch to a different section, we mark it as such. If SEC is
12038 NULL, and the frag is not marked, then it must be a branch to
12039 the same section. */
12042 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
12047 /* Must have been called from md_estimate_size_before_relax. */
12050 fragp->fr_subtype =
12051 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12053 /* FIXME: We should support this, and let the linker
12054 catch branches and loads that are out of range. */
12055 as_bad_where (fragp->fr_file, fragp->fr_line,
12056 _("unsupported PC relative reference to different section"));
12060 if (fragp != sym_frag && sym_frag->fr_address == 0)
12061 /* Assume non-extended on the first relaxation pass.
12062 The address we have calculated will be bogus if this is
12063 a forward branch to another frag, as the forward frag
12064 will have fr_address == 0. */
12068 /* In this case, we know for sure that the symbol fragment is in
12069 the same section. If the relax_marker of the symbol fragment
12070 differs from the relax_marker of this fragment, we have not
12071 yet adjusted the symbol fragment fr_address. We want to add
12072 in STRETCH in order to get a better estimate of the address.
12073 This particularly matters because of the shift bits. */
12075 && sym_frag->relax_marker != fragp->relax_marker)
12079 /* Adjust stretch for any alignment frag. Note that if have
12080 been expanding the earlier code, the symbol may be
12081 defined in what appears to be an earlier frag. FIXME:
12082 This doesn't handle the fr_subtype field, which specifies
12083 a maximum number of bytes to skip when doing an
12085 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
12087 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
12090 stretch = - ((- stretch)
12091 & ~ ((1 << (int) f->fr_offset) - 1));
12093 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
12102 addr = fragp->fr_address + fragp->fr_fix;
12104 /* The base address rules are complicated. The base address of
12105 a branch is the following instruction. The base address of a
12106 PC relative load or add is the instruction itself, but if it
12107 is in a delay slot (in which case it can not be extended) use
12108 the address of the instruction whose delay slot it is in. */
12109 if (type == 'p' || type == 'q')
12113 /* If we are currently assuming that this frag should be
12114 extended, then, the current address is two bytes
12116 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12119 /* Ignore the low bit in the target, since it will be set
12120 for a text label. */
12121 if ((val & 1) != 0)
12124 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12126 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12129 val -= addr & ~ ((1 << op->shift) - 1);
12131 /* Branch offsets have an implicit 0 in the lowest bit. */
12132 if (type == 'p' || type == 'q')
12135 /* If any of the shifted bits are set, we must use an extended
12136 opcode. If the address depends on the size of this
12137 instruction, this can lead to a loop, so we arrange to always
12138 use an extended opcode. We only check this when we are in
12139 the main relaxation loop, when SEC is NULL. */
12140 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
12142 fragp->fr_subtype =
12143 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12147 /* If we are about to mark a frag as extended because the value
12148 is precisely maxtiny + 1, then there is a chance of an
12149 infinite loop as in the following code:
12154 In this case when the la is extended, foo is 0x3fc bytes
12155 away, so the la can be shrunk, but then foo is 0x400 away, so
12156 the la must be extended. To avoid this loop, we mark the
12157 frag as extended if it was small, and is about to become
12158 extended with a value of maxtiny + 1. */
12159 if (val == ((maxtiny + 1) << op->shift)
12160 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
12163 fragp->fr_subtype =
12164 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12168 else if (symsec != absolute_section && sec != NULL)
12169 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
12171 if ((val & ((1 << op->shift) - 1)) != 0
12172 || val < (mintiny << op->shift)
12173 || val > (maxtiny << op->shift))
12179 /* Estimate the size of a frag before relaxing. Unless this is the
12180 mips16, we are not really relaxing here, and the final size is
12181 encoded in the subtype information. For the mips16, we have to
12182 decide whether we are using an extended opcode or not. */
12185 md_estimate_size_before_relax (fragp, segtype)
12190 boolean linkonce = false;
12192 if (RELAX_MIPS16_P (fragp->fr_subtype))
12193 /* We don't want to modify the EXTENDED bit here; it might get us
12194 into infinite loops. We change it only in mips_relax_frag(). */
12195 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
12197 if (mips_pic == NO_PIC)
12199 change = nopic_need_relax (fragp->fr_symbol, 0);
12201 else if (mips_pic == SVR4_PIC)
12206 sym = fragp->fr_symbol;
12208 /* Handle the case of a symbol equated to another symbol. */
12209 while (symbol_equated_reloc_p (sym))
12213 /* It's possible to get a loop here in a badly written
12215 n = symbol_get_value_expression (sym)->X_add_symbol;
12221 symsec = S_GET_SEGMENT (sym);
12223 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12224 if (symsec != segtype && ! S_IS_LOCAL (sym))
12226 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12230 /* The GNU toolchain uses an extension for ELF: a section
12231 beginning with the magic string .gnu.linkonce is a linkonce
12233 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12234 sizeof ".gnu.linkonce" - 1) == 0)
12238 /* This must duplicate the test in adjust_reloc_syms. */
12239 change = (symsec != &bfd_und_section
12240 && symsec != &bfd_abs_section
12241 && ! bfd_is_com_section (symsec)
12244 /* A global or weak symbol is treated as external. */
12245 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12246 || (! S_IS_WEAK (sym)
12247 && (! S_IS_EXTERN (sym) || mips_pic == EMBEDDED_PIC)))
12256 /* Record the offset to the first reloc in the fr_opcode field.
12257 This lets md_convert_frag and tc_gen_reloc know that the code
12258 must be expanded. */
12259 fragp->fr_opcode = (fragp->fr_literal
12261 - RELAX_OLD (fragp->fr_subtype)
12262 + RELAX_RELOC1 (fragp->fr_subtype));
12263 /* FIXME: This really needs as_warn_where. */
12264 if (RELAX_WARN (fragp->fr_subtype))
12265 as_warn (_("AT used after \".set noat\" or macro used after "
12266 "\".set nomacro\""));
12268 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
12274 /* This is called to see whether a reloc against a defined symbol
12275 should be converted into a reloc against a section. Don't adjust
12276 MIPS16 jump relocations, so we don't have to worry about the format
12277 of the offset in the .o file. Don't adjust relocations against
12278 mips16 symbols, so that the linker can find them if it needs to set
12282 mips_fix_adjustable (fixp)
12286 /* Prevent all adjustments to global symbols. */
12287 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12288 && mips_pic != EMBEDDED_PIC
12289 && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
12292 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
12294 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12295 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12297 if (fixp->fx_addsy == NULL)
12300 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12301 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
12302 && fixp->fx_subsy == NULL)
12308 /* Translate internal representation of relocation info to BFD target
12312 tc_gen_reloc (section, fixp)
12313 asection *section ATTRIBUTE_UNUSED;
12316 static arelent *retval[4];
12318 bfd_reloc_code_real_type code;
12320 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
12323 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12324 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12325 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12327 if (mips_pic == EMBEDDED_PIC
12328 && SWITCH_TABLE (fixp))
12330 /* For a switch table entry we use a special reloc. The addend
12331 is actually the difference between the reloc address and the
12333 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12334 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
12335 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
12336 fixp->fx_r_type = BFD_RELOC_GPREL32;
12338 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
12340 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12341 reloc->addend = fixp->fx_addnumber;
12344 /* We use a special addend for an internal RELLO reloc. */
12345 if (symbol_section_p (fixp->fx_addsy))
12346 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12348 reloc->addend = fixp->fx_addnumber + reloc->address;
12351 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
12353 assert (fixp->fx_next != NULL
12354 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
12356 /* The reloc is relative to the RELLO; adjust the addend
12358 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12359 reloc->addend = fixp->fx_next->fx_addnumber;
12362 /* We use a special addend for an internal RELHI reloc. */
12363 if (symbol_section_p (fixp->fx_addsy))
12364 reloc->addend = (fixp->fx_next->fx_frag->fr_address
12365 + fixp->fx_next->fx_where
12366 - S_GET_VALUE (fixp->fx_subsy));
12368 reloc->addend = (fixp->fx_addnumber
12369 + fixp->fx_next->fx_frag->fr_address
12370 + fixp->fx_next->fx_where);
12373 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12374 reloc->addend = fixp->fx_addnumber;
12377 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
12378 /* A gruesome hack which is a result of the gruesome gas reloc
12380 reloc->addend = reloc->address;
12382 reloc->addend = -reloc->address;
12385 /* If this is a variant frag, we may need to adjust the existing
12386 reloc and generate a new one. */
12387 if (fixp->fx_frag->fr_opcode != NULL
12388 && (fixp->fx_r_type == BFD_RELOC_GPREL16
12389 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
12390 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
12391 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12392 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
12393 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12394 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
12399 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
12401 /* If this is not the last reloc in this frag, then we have two
12402 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
12403 CALL_HI16/CALL_LO16, both of which are being replaced. Let
12404 the second one handle all of them. */
12405 if (fixp->fx_next != NULL
12406 && fixp->fx_frag == fixp->fx_next->fx_frag)
12408 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
12409 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
12410 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12411 && (fixp->fx_next->fx_r_type
12412 == BFD_RELOC_MIPS_GOT_LO16))
12413 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12414 && (fixp->fx_next->fx_r_type
12415 == BFD_RELOC_MIPS_CALL_LO16)));
12420 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
12421 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12422 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
12424 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12425 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12426 reloc2->address = (reloc->address
12427 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
12428 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
12429 reloc2->addend = fixp->fx_addnumber;
12430 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
12431 assert (reloc2->howto != NULL);
12433 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
12437 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
12440 reloc3->address += 4;
12443 if (mips_pic == NO_PIC)
12445 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
12446 fixp->fx_r_type = BFD_RELOC_HI16_S;
12448 else if (mips_pic == SVR4_PIC)
12450 switch (fixp->fx_r_type)
12454 case BFD_RELOC_MIPS_GOT16:
12456 case BFD_RELOC_MIPS_CALL16:
12457 case BFD_RELOC_MIPS_GOT_LO16:
12458 case BFD_RELOC_MIPS_CALL_LO16:
12459 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
12467 /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry
12468 to be used in the relocation's section offset. */
12469 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12471 reloc->address = reloc->addend;
12475 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
12476 fixup_segment converted a non-PC relative reloc into a PC
12477 relative reloc. In such a case, we need to convert the reloc
12479 code = fixp->fx_r_type;
12480 if (fixp->fx_pcrel)
12485 code = BFD_RELOC_8_PCREL;
12488 code = BFD_RELOC_16_PCREL;
12491 code = BFD_RELOC_32_PCREL;
12494 code = BFD_RELOC_64_PCREL;
12496 case BFD_RELOC_8_PCREL:
12497 case BFD_RELOC_16_PCREL:
12498 case BFD_RELOC_32_PCREL:
12499 case BFD_RELOC_64_PCREL:
12500 case BFD_RELOC_16_PCREL_S2:
12501 case BFD_RELOC_PCREL_HI16_S:
12502 case BFD_RELOC_PCREL_LO16:
12505 as_bad_where (fixp->fx_file, fixp->fx_line,
12506 _("Cannot make %s relocation PC relative"),
12507 bfd_get_reloc_code_name (code));
12512 /* md_apply_fix3 has a double-subtraction hack to get
12513 bfd_install_relocation to behave nicely. GPREL relocations are
12514 handled correctly without this hack, so undo it here. We can't
12515 stop md_apply_fix3 from subtracting twice in the first place since
12516 the fake addend is required for variant frags above. */
12517 if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
12518 && code == BFD_RELOC_GPREL16
12519 && reloc->addend != 0
12520 && mips_need_elf_addend_fixup (fixp))
12521 reloc->addend += S_GET_VALUE (fixp->fx_addsy);
12524 /* To support a PC relative reloc when generating embedded PIC code
12525 for ECOFF, we use a Cygnus extension. We check for that here to
12526 make sure that we don't let such a reloc escape normally. */
12527 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
12528 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12529 && code == BFD_RELOC_16_PCREL_S2
12530 && mips_pic != EMBEDDED_PIC)
12531 reloc->howto = NULL;
12533 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12535 if (reloc->howto == NULL)
12537 as_bad_where (fixp->fx_file, fixp->fx_line,
12538 _("Can not represent %s relocation in this object file format"),
12539 bfd_get_reloc_code_name (code));
12546 /* Relax a machine dependent frag. This returns the amount by which
12547 the current size of the frag should change. */
12550 mips_relax_frag (fragp, stretch)
12554 if (! RELAX_MIPS16_P (fragp->fr_subtype))
12557 if (mips16_extended_frag (fragp, NULL, stretch))
12559 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12561 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
12566 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12568 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
12575 /* Convert a machine dependent frag. */
12578 md_convert_frag (abfd, asec, fragp)
12579 bfd *abfd ATTRIBUTE_UNUSED;
12586 if (RELAX_MIPS16_P (fragp->fr_subtype))
12589 register const struct mips16_immed_operand *op;
12590 boolean small, ext;
12593 unsigned long insn;
12594 boolean use_extend;
12595 unsigned short extend;
12597 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12598 op = mips16_immed_operands;
12599 while (op->type != type)
12602 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12613 resolve_symbol_value (fragp->fr_symbol);
12614 val = S_GET_VALUE (fragp->fr_symbol);
12619 addr = fragp->fr_address + fragp->fr_fix;
12621 /* The rules for the base address of a PC relative reloc are
12622 complicated; see mips16_extended_frag. */
12623 if (type == 'p' || type == 'q')
12628 /* Ignore the low bit in the target, since it will be
12629 set for a text label. */
12630 if ((val & 1) != 0)
12633 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12635 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12638 addr &= ~ (addressT) ((1 << op->shift) - 1);
12641 /* Make sure the section winds up with the alignment we have
12644 record_alignment (asec, op->shift);
12648 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
12649 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
12650 as_warn_where (fragp->fr_file, fragp->fr_line,
12651 _("extended instruction in delay slot"));
12653 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
12655 if (target_big_endian)
12656 insn = bfd_getb16 (buf);
12658 insn = bfd_getl16 (buf);
12660 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
12661 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
12662 small, ext, &insn, &use_extend, &extend);
12666 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
12667 fragp->fr_fix += 2;
12671 md_number_to_chars ((char *) buf, insn, 2);
12672 fragp->fr_fix += 2;
12677 if (fragp->fr_opcode == NULL)
12680 old = RELAX_OLD (fragp->fr_subtype);
12681 new = RELAX_NEW (fragp->fr_subtype);
12682 fixptr = fragp->fr_literal + fragp->fr_fix;
12685 memcpy (fixptr - old, fixptr, new);
12687 fragp->fr_fix += new - old;
12693 /* This function is called after the relocs have been generated.
12694 We've been storing mips16 text labels as odd. Here we convert them
12695 back to even for the convenience of the debugger. */
12698 mips_frob_file_after_relocs ()
12701 unsigned int count, i;
12703 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
12706 syms = bfd_get_outsymbols (stdoutput);
12707 count = bfd_get_symcount (stdoutput);
12708 for (i = 0; i < count; i++, syms++)
12710 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
12711 && ((*syms)->value & 1) != 0)
12713 (*syms)->value &= ~1;
12714 /* If the symbol has an odd size, it was probably computed
12715 incorrectly, so adjust that as well. */
12716 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
12717 ++elf_symbol (*syms)->internal_elf_sym.st_size;
12724 /* This function is called whenever a label is defined. It is used
12725 when handling branch delays; if a branch has a label, we assume we
12726 can not move it. */
12729 mips_define_label (sym)
12732 struct insn_label_list *l;
12734 if (free_insn_labels == NULL)
12735 l = (struct insn_label_list *) xmalloc (sizeof *l);
12738 l = free_insn_labels;
12739 free_insn_labels = l->next;
12743 l->next = insn_labels;
12747 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12749 /* Some special processing for a MIPS ELF file. */
12752 mips_elf_final_processing ()
12754 /* Write out the register information. */
12759 s.ri_gprmask = mips_gprmask;
12760 s.ri_cprmask[0] = mips_cprmask[0];
12761 s.ri_cprmask[1] = mips_cprmask[1];
12762 s.ri_cprmask[2] = mips_cprmask[2];
12763 s.ri_cprmask[3] = mips_cprmask[3];
12764 /* The gp_value field is set by the MIPS ELF backend. */
12766 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
12767 ((Elf32_External_RegInfo *)
12768 mips_regmask_frag));
12772 Elf64_Internal_RegInfo s;
12774 s.ri_gprmask = mips_gprmask;
12776 s.ri_cprmask[0] = mips_cprmask[0];
12777 s.ri_cprmask[1] = mips_cprmask[1];
12778 s.ri_cprmask[2] = mips_cprmask[2];
12779 s.ri_cprmask[3] = mips_cprmask[3];
12780 /* The gp_value field is set by the MIPS ELF backend. */
12782 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
12783 ((Elf64_External_RegInfo *)
12784 mips_regmask_frag));
12787 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
12788 sort of BFD interface for this. */
12789 if (mips_any_noreorder)
12790 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
12791 if (mips_pic != NO_PIC)
12792 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
12794 /* Set MIPS ELF flags for ASEs. */
12795 #if 0 /* XXX FIXME */
12796 if (file_ase_mips3d)
12797 elf_elfheader (stdoutput)->e_flags |= ???;
12800 /* Set the MIPS ELF ABI flags. */
12801 if (file_mips_abi == NO_ABI)
12803 else if (file_mips_abi == O32_ABI)
12804 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
12805 else if (file_mips_abi == O64_ABI)
12806 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
12807 else if (file_mips_abi == EABI_ABI)
12810 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
12812 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
12814 else if (file_mips_abi == N32_ABI)
12815 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
12817 /* Nothing to do for "64". */
12819 if (mips_32bitmode)
12820 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
12823 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
12825 typedef struct proc {
12827 unsigned long reg_mask;
12828 unsigned long reg_offset;
12829 unsigned long fpreg_mask;
12830 unsigned long fpreg_offset;
12831 unsigned long frame_offset;
12832 unsigned long frame_reg;
12833 unsigned long pc_reg;
12836 static procS cur_proc;
12837 static procS *cur_proc_ptr;
12838 static int numprocs;
12840 /* Fill in an rs_align_code fragment. */
12843 mips_handle_align (fragp)
12846 if (fragp->fr_type != rs_align_code)
12849 if (mips_opts.mips16)
12851 static const unsigned char be_nop[] = { 0x65, 0x00 };
12852 static const unsigned char le_nop[] = { 0x00, 0x65 };
12857 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
12858 p = fragp->fr_literal + fragp->fr_fix;
12863 fragp->fr_fix += 1;
12866 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
12870 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
12881 /* check for premature end, nesting errors, etc */
12883 as_warn (_("missing .end at end of assembly"));
12892 if (*input_line_pointer == '-')
12894 ++input_line_pointer;
12897 if (!ISDIGIT (*input_line_pointer))
12898 as_bad (_("expected simple number"));
12899 if (input_line_pointer[0] == '0')
12901 if (input_line_pointer[1] == 'x')
12903 input_line_pointer += 2;
12904 while (ISXDIGIT (*input_line_pointer))
12907 val |= hex_value (*input_line_pointer++);
12909 return negative ? -val : val;
12913 ++input_line_pointer;
12914 while (ISDIGIT (*input_line_pointer))
12917 val |= *input_line_pointer++ - '0';
12919 return negative ? -val : val;
12922 if (!ISDIGIT (*input_line_pointer))
12924 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
12925 *input_line_pointer, *input_line_pointer);
12926 as_warn (_("invalid number"));
12929 while (ISDIGIT (*input_line_pointer))
12932 val += *input_line_pointer++ - '0';
12934 return negative ? -val : val;
12937 /* The .file directive; just like the usual .file directive, but there
12938 is an initial number which is the ECOFF file index. */
12942 int x ATTRIBUTE_UNUSED;
12948 /* The .end directive. */
12952 int x ATTRIBUTE_UNUSED;
12957 /* Following functions need their own .frame and .cprestore directives. */
12958 mips_frame_reg_valid = 0;
12959 mips_cprestore_valid = 0;
12961 if (!is_end_of_line[(unsigned char) *input_line_pointer])
12964 demand_empty_rest_of_line ();
12969 #ifdef BFD_ASSEMBLER
12970 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
12975 if (now_seg != data_section && now_seg != bss_section)
12982 as_warn (_(".end not in text section"));
12986 as_warn (_(".end directive without a preceding .ent directive."));
12987 demand_empty_rest_of_line ();
12993 assert (S_GET_NAME (p));
12994 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
12995 as_warn (_(".end symbol does not match .ent symbol."));
12998 as_warn (_(".end directive missing or unknown symbol"));
13000 #ifdef MIPS_STABS_ELF
13002 segT saved_seg = now_seg;
13003 subsegT saved_subseg = now_subseg;
13008 dot = frag_now_fix ();
13010 #ifdef md_flush_pending_output
13011 md_flush_pending_output ();
13015 subseg_set (pdr_seg, 0);
13017 /* Write the symbol. */
13018 exp.X_op = O_symbol;
13019 exp.X_add_symbol = p;
13020 exp.X_add_number = 0;
13021 emit_expr (&exp, 4);
13023 fragp = frag_more (7 * 4);
13025 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
13026 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
13027 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
13028 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
13029 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
13030 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
13031 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
13033 subseg_set (saved_seg, saved_subseg);
13037 cur_proc_ptr = NULL;
13040 /* The .aent and .ent directives. */
13049 symbolP = get_symbol ();
13050 if (*input_line_pointer == ',')
13051 input_line_pointer++;
13052 SKIP_WHITESPACE ();
13053 if (ISDIGIT (*input_line_pointer)
13054 || *input_line_pointer == '-')
13057 #ifdef BFD_ASSEMBLER
13058 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13063 if (now_seg != data_section && now_seg != bss_section)
13070 as_warn (_(".ent or .aent not in text section."));
13072 if (!aent && cur_proc_ptr)
13073 as_warn (_("missing .end"));
13077 /* This function needs its own .frame and .cprestore directives. */
13078 mips_frame_reg_valid = 0;
13079 mips_cprestore_valid = 0;
13081 cur_proc_ptr = &cur_proc;
13082 memset (cur_proc_ptr, '\0', sizeof (procS));
13084 cur_proc_ptr->isym = symbolP;
13086 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
13091 demand_empty_rest_of_line ();
13094 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
13095 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
13096 s_mips_frame is used so that we can set the PDR information correctly.
13097 We can't use the ecoff routines because they make reference to the ecoff
13098 symbol table (in the mdebug section). */
13101 s_mips_frame (ignore)
13102 int ignore ATTRIBUTE_UNUSED;
13104 #ifdef MIPS_STABS_ELF
13108 if (cur_proc_ptr == (procS *) NULL)
13110 as_warn (_(".frame outside of .ent"));
13111 demand_empty_rest_of_line ();
13115 cur_proc_ptr->frame_reg = tc_get_register (1);
13117 SKIP_WHITESPACE ();
13118 if (*input_line_pointer++ != ','
13119 || get_absolute_expression_and_terminator (&val) != ',')
13121 as_warn (_("Bad .frame directive"));
13122 --input_line_pointer;
13123 demand_empty_rest_of_line ();
13127 cur_proc_ptr->frame_offset = val;
13128 cur_proc_ptr->pc_reg = tc_get_register (0);
13130 demand_empty_rest_of_line ();
13133 #endif /* MIPS_STABS_ELF */
13136 /* The .fmask and .mask directives. If the mdebug section is present
13137 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
13138 embedded targets, s_mips_mask is used so that we can set the PDR
13139 information correctly. We can't use the ecoff routines because they
13140 make reference to the ecoff symbol table (in the mdebug section). */
13143 s_mips_mask (reg_type)
13146 #ifdef MIPS_STABS_ELF
13149 if (cur_proc_ptr == (procS *) NULL)
13151 as_warn (_(".mask/.fmask outside of .ent"));
13152 demand_empty_rest_of_line ();
13156 if (get_absolute_expression_and_terminator (&mask) != ',')
13158 as_warn (_("Bad .mask/.fmask directive"));
13159 --input_line_pointer;
13160 demand_empty_rest_of_line ();
13164 off = get_absolute_expression ();
13166 if (reg_type == 'F')
13168 cur_proc_ptr->fpreg_mask = mask;
13169 cur_proc_ptr->fpreg_offset = off;
13173 cur_proc_ptr->reg_mask = mask;
13174 cur_proc_ptr->reg_offset = off;
13177 demand_empty_rest_of_line ();
13179 s_ignore (reg_type);
13180 #endif /* MIPS_STABS_ELF */
13183 /* The .loc directive. */
13194 assert (now_seg == text_section);
13196 lineno = get_number ();
13197 addroff = frag_now_fix ();
13199 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
13200 S_SET_TYPE (symbolP, N_SLINE);
13201 S_SET_OTHER (symbolP, 0);
13202 S_SET_DESC (symbolP, lineno);
13203 symbolP->sy_segment = now_seg;
13207 /* CPU name/ISA/number mapping table.
13209 Entries are grouped by type. The first matching CPU or ISA entry
13210 gets chosen by CPU or ISA, so it should be the 'canonical' name
13211 for that type. Entries after that within the type are sorted
13214 Case is ignored in comparison, so put the canonical entry in the
13215 appropriate case but everything else in lower case to ease eye pain. */
13216 static const struct mips_cpu_info mips_cpu_info_table[] =
13219 { "MIPS1", 1, ISA_MIPS1, CPU_R3000, },
13220 { "mips", 1, ISA_MIPS1, CPU_R3000, },
13223 { "MIPS2", 1, ISA_MIPS2, CPU_R6000, },
13226 { "MIPS3", 1, ISA_MIPS3, CPU_R4000, },
13229 { "MIPS4", 1, ISA_MIPS4, CPU_R8000, },
13232 { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, },
13233 { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, },
13236 { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, },
13237 { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, },
13238 { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, },
13239 { "4kc", 0, ISA_MIPS32, CPU_MIPS32, },
13240 { "4km", 0, ISA_MIPS32, CPU_MIPS32, },
13241 { "4kp", 0, ISA_MIPS32, CPU_MIPS32, },
13243 /* For historical reasons. */
13244 { "MIPS64", 1, ISA_MIPS3, CPU_R4000, },
13247 { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, },
13248 { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, },
13249 { "5kc", 0, ISA_MIPS64, CPU_MIPS64, },
13250 { "20kc", 0, ISA_MIPS64, CPU_MIPS64, },
13253 { "R2000", 0, ISA_MIPS1, CPU_R2000, },
13254 { "2000", 0, ISA_MIPS1, CPU_R2000, },
13255 { "2k", 0, ISA_MIPS1, CPU_R2000, },
13256 { "r2k", 0, ISA_MIPS1, CPU_R2000, },
13259 { "R3000", 0, ISA_MIPS1, CPU_R3000, },
13260 { "3000", 0, ISA_MIPS1, CPU_R3000, },
13261 { "3k", 0, ISA_MIPS1, CPU_R3000, },
13262 { "r3k", 0, ISA_MIPS1, CPU_R3000, },
13265 { "R3900", 0, ISA_MIPS1, CPU_R3900, },
13266 { "3900", 0, ISA_MIPS1, CPU_R3900, },
13267 { "mipstx39", 0, ISA_MIPS1, CPU_R3900, },
13270 { "R4000", 0, ISA_MIPS3, CPU_R4000, },
13271 { "4000", 0, ISA_MIPS3, CPU_R4000, },
13272 { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */
13273 { "r4k", 0, ISA_MIPS3, CPU_R4000, },
13276 { "R4010", 0, ISA_MIPS2, CPU_R4010, },
13277 { "4010", 0, ISA_MIPS2, CPU_R4010, },
13280 { "R4400", 0, ISA_MIPS3, CPU_R4400, },
13281 { "4400", 0, ISA_MIPS3, CPU_R4400, },
13284 { "R4600", 0, ISA_MIPS3, CPU_R4600, },
13285 { "4600", 0, ISA_MIPS3, CPU_R4600, },
13286 { "mips64orion", 0, ISA_MIPS3, CPU_R4600, },
13287 { "orion", 0, ISA_MIPS3, CPU_R4600, },
13290 { "R4650", 0, ISA_MIPS3, CPU_R4650, },
13291 { "4650", 0, ISA_MIPS3, CPU_R4650, },
13294 { "R6000", 0, ISA_MIPS2, CPU_R6000, },
13295 { "6000", 0, ISA_MIPS2, CPU_R6000, },
13296 { "6k", 0, ISA_MIPS2, CPU_R6000, },
13297 { "r6k", 0, ISA_MIPS2, CPU_R6000, },
13300 { "R8000", 0, ISA_MIPS4, CPU_R8000, },
13301 { "8000", 0, ISA_MIPS4, CPU_R8000, },
13302 { "8k", 0, ISA_MIPS4, CPU_R8000, },
13303 { "r8k", 0, ISA_MIPS4, CPU_R8000, },
13306 { "R10000", 0, ISA_MIPS4, CPU_R10000, },
13307 { "10000", 0, ISA_MIPS4, CPU_R10000, },
13308 { "10k", 0, ISA_MIPS4, CPU_R10000, },
13309 { "r10k", 0, ISA_MIPS4, CPU_R10000, },
13312 { "R12000", 0, ISA_MIPS4, CPU_R12000, },
13313 { "12000", 0, ISA_MIPS4, CPU_R12000, },
13314 { "12k", 0, ISA_MIPS4, CPU_R12000, },
13315 { "r12k", 0, ISA_MIPS4, CPU_R12000, },
13318 { "VR4100", 0, ISA_MIPS3, CPU_VR4100, },
13319 { "4100", 0, ISA_MIPS3, CPU_VR4100, },
13320 { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, },
13321 { "r4100", 0, ISA_MIPS3, CPU_VR4100, },
13324 { "VR4111", 0, ISA_MIPS3, CPU_R4111, },
13325 { "4111", 0, ISA_MIPS3, CPU_R4111, },
13326 { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, },
13327 { "r4111", 0, ISA_MIPS3, CPU_R4111, },
13330 { "VR4300", 0, ISA_MIPS3, CPU_R4300, },
13331 { "4300", 0, ISA_MIPS3, CPU_R4300, },
13332 { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, },
13333 { "r4300", 0, ISA_MIPS3, CPU_R4300, },
13336 { "VR5000", 0, ISA_MIPS4, CPU_R5000, },
13337 { "5000", 0, ISA_MIPS4, CPU_R5000, },
13338 { "5k", 0, ISA_MIPS4, CPU_R5000, },
13339 { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, },
13340 { "r5000", 0, ISA_MIPS4, CPU_R5000, },
13341 { "r5200", 0, ISA_MIPS4, CPU_R5000, },
13342 { "rm5200", 0, ISA_MIPS4, CPU_R5000, },
13343 { "r5230", 0, ISA_MIPS4, CPU_R5000, },
13344 { "rm5230", 0, ISA_MIPS4, CPU_R5000, },
13345 { "r5231", 0, ISA_MIPS4, CPU_R5000, },
13346 { "rm5231", 0, ISA_MIPS4, CPU_R5000, },
13347 { "r5261", 0, ISA_MIPS4, CPU_R5000, },
13348 { "rm5261", 0, ISA_MIPS4, CPU_R5000, },
13349 { "r5721", 0, ISA_MIPS4, CPU_R5000, },
13350 { "rm5721", 0, ISA_MIPS4, CPU_R5000, },
13351 { "r5k", 0, ISA_MIPS4, CPU_R5000, },
13352 { "r7000", 0, ISA_MIPS4, CPU_R5000, },
13354 /* Broadcom SB-1 CPU */
13355 { "SB-1", 0, ISA_MIPS64, CPU_SB1, },
13356 { "sb-1250", 0, ISA_MIPS64, CPU_SB1, },
13357 { "sb1", 0, ISA_MIPS64, CPU_SB1, },
13358 { "sb1250", 0, ISA_MIPS64, CPU_SB1, },
13361 { NULL, 0, 0, 0, },
13364 static const struct mips_cpu_info *
13365 mips_cpu_info_from_name (name)
13370 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13371 if (strcasecmp (name, mips_cpu_info_table[i].name) == 0)
13372 return (&mips_cpu_info_table[i]);
13377 static const struct mips_cpu_info *
13378 mips_cpu_info_from_isa (isa)
13383 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13384 if (mips_cpu_info_table[i].is_isa
13385 && isa == mips_cpu_info_table[i].isa)
13386 return (&mips_cpu_info_table[i]);
13391 static const struct mips_cpu_info *
13392 mips_cpu_info_from_cpu (cpu)
13397 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13398 if (!mips_cpu_info_table[i].is_isa
13399 && cpu == mips_cpu_info_table[i].cpu)
13400 return (&mips_cpu_info_table[i]);