1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004 Free Software Foundation, Inc.
4 Contributed by the OSF and Ralph Campbell.
5 Written by Keith Knowles and Ralph Campbell, working independently.
6 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
9 This file is part of GAS.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include "safe-ctype.h"
33 #include "opcode/mips.h"
35 #include "dwarf2dbg.h"
38 #define DBG(x) printf x
44 /* Clean up namespace so we can include obj-elf.h too. */
45 static int mips_output_flavor (void);
46 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
47 #undef OBJ_PROCESS_STAB
54 #undef obj_frob_file_after_relocs
55 #undef obj_frob_symbol
57 #undef obj_sec_sym_ok_for_reloc
58 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
61 /* Fix any of them that we actually care about. */
63 #define OUTPUT_FLAVOR mips_output_flavor()
70 #ifndef ECOFF_DEBUGGING
71 #define NO_ECOFF_DEBUGGING
72 #define ECOFF_DEBUGGING 0
75 int mips_flag_mdebug = -1;
77 /* Control generation of .pdr sections. Off by default on IRIX: the native
78 linker doesn't know about and discards them, but relocations against them
79 remain, leading to rld crashes. */
81 int mips_flag_pdr = FALSE;
83 int mips_flag_pdr = TRUE;
88 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
89 static char *mips_regmask_frag;
95 #define PIC_CALL_REG 25
103 #define ILLEGAL_REG (32)
105 /* Allow override of standard little-endian ECOFF format. */
107 #ifndef ECOFF_LITTLE_FORMAT
108 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
111 extern int target_big_endian;
113 /* The name of the readonly data section. */
114 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
116 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
118 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
120 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
124 /* The ABI to use. */
135 /* MIPS ABI we are using for this output file. */
136 static enum mips_abi_level mips_abi = NO_ABI;
138 /* Whether or not we have code that can call pic code. */
139 int mips_abicalls = FALSE;
141 /* This is the set of options which may be modified by the .set
142 pseudo-op. We use a struct so that .set push and .set pop are more
145 struct mips_set_options
147 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
148 if it has not been initialized. Changed by `.set mipsN', and the
149 -mipsN command line option, and the default CPU. */
151 /* Enabled Application Specific Extensions (ASEs). These are set to -1
152 if they have not been initialized. Changed by `.set <asename>', by
153 command line options, and based on the default architecture. */
156 /* Whether we are assembling for the mips16 processor. 0 if we are
157 not, 1 if we are, and -1 if the value has not been initialized.
158 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
159 -nomips16 command line options, and the default CPU. */
161 /* Non-zero if we should not reorder instructions. Changed by `.set
162 reorder' and `.set noreorder'. */
164 /* Non-zero if we should not permit the $at ($1) register to be used
165 in instructions. Changed by `.set at' and `.set noat'. */
167 /* Non-zero if we should warn when a macro instruction expands into
168 more than one machine instruction. Changed by `.set nomacro' and
170 int warn_about_macros;
171 /* Non-zero if we should not move instructions. Changed by `.set
172 move', `.set volatile', `.set nomove', and `.set novolatile'. */
174 /* Non-zero if we should not optimize branches by moving the target
175 of the branch into the delay slot. Actually, we don't perform
176 this optimization anyhow. Changed by `.set bopt' and `.set
179 /* Non-zero if we should not autoextend mips16 instructions.
180 Changed by `.set autoextend' and `.set noautoextend'. */
182 /* Restrict general purpose registers and floating point registers
183 to 32 bit. This is initially determined when -mgp32 or -mfp32
184 is passed but can changed if the assembler code uses .set mipsN. */
187 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
188 command line option, and the default CPU. */
192 /* True if -mgp32 was passed. */
193 static int file_mips_gp32 = -1;
195 /* True if -mfp32 was passed. */
196 static int file_mips_fp32 = -1;
198 /* This is the struct we use to hold the current set of options. Note
199 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
200 -1 to indicate that they have not been initialized. */
202 static struct mips_set_options mips_opts =
204 ISA_UNKNOWN, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, CPU_UNKNOWN
207 /* These variables are filled in with the masks of registers used.
208 The object format code reads them and puts them in the appropriate
210 unsigned long mips_gprmask;
211 unsigned long mips_cprmask[4];
213 /* MIPS ISA we are using for this output file. */
214 static int file_mips_isa = ISA_UNKNOWN;
216 /* True if -mips16 was passed or implied by arguments passed on the
217 command line (e.g., by -march). */
218 static int file_ase_mips16;
220 /* True if -mips3d was passed or implied by arguments passed on the
221 command line (e.g., by -march). */
222 static int file_ase_mips3d;
224 /* True if -mdmx was passed or implied by arguments passed on the
225 command line (e.g., by -march). */
226 static int file_ase_mdmx;
228 /* The argument of the -march= flag. The architecture we are assembling. */
229 static int file_mips_arch = CPU_UNKNOWN;
230 static const char *mips_arch_string;
232 /* The argument of the -mtune= flag. The architecture for which we
234 static int mips_tune = CPU_UNKNOWN;
235 static const char *mips_tune_string;
237 /* True when generating 32-bit code for a 64-bit processor. */
238 static int mips_32bitmode = 0;
240 /* True if the given ABI requires 32-bit registers. */
241 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
243 /* Likewise 64-bit registers. */
244 #define ABI_NEEDS_64BIT_REGS(ABI) \
246 || (ABI) == N64_ABI \
249 /* Return true if ISA supports 64 bit gp register instructions. */
250 #define ISA_HAS_64BIT_REGS(ISA) ( \
252 || (ISA) == ISA_MIPS4 \
253 || (ISA) == ISA_MIPS5 \
254 || (ISA) == ISA_MIPS64 \
255 || (ISA) == ISA_MIPS64R2 \
258 /* Return true if ISA supports 64-bit right rotate (dror et al.)
260 #define ISA_HAS_DROR(ISA) ( \
261 (ISA) == ISA_MIPS64R2 \
264 /* Return true if ISA supports 32-bit right rotate (ror et al.)
266 #define ISA_HAS_ROR(ISA) ( \
267 (ISA) == ISA_MIPS32R2 \
268 || (ISA) == ISA_MIPS64R2 \
271 #define HAVE_32BIT_GPRS \
272 (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
274 #define HAVE_32BIT_FPRS \
275 (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
277 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
278 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
280 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
282 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
284 /* We can only have 64bit addresses if the object file format
286 #define HAVE_32BIT_ADDRESSES \
288 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
289 || ! HAVE_64BIT_OBJECTS) \
290 && mips_pic != EMBEDDED_PIC))
292 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
294 /* Addresses are loaded in different ways, depending on the address size
295 in use. The n32 ABI Documentation also mandates the use of additions
296 with overflow checking, but existing implementations don't follow it. */
297 #define ADDRESS_ADD_INSN \
298 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
300 #define ADDRESS_ADDI_INSN \
301 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
303 #define ADDRESS_LOAD_INSN \
304 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
306 #define ADDRESS_STORE_INSN \
307 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
309 /* Return true if the given CPU supports the MIPS16 ASE. */
310 #define CPU_HAS_MIPS16(cpu) \
311 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
312 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
314 /* Return true if the given CPU supports the MIPS3D ASE. */
315 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
318 /* Return true if the given CPU supports the MDMX ASE. */
319 #define CPU_HAS_MDMX(cpu) (FALSE \
322 /* True if CPU has a dror instruction. */
323 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
325 /* True if CPU has a ror instruction. */
326 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
328 /* Whether the processor uses hardware interlocks to protect
329 reads from the HI and LO registers, and thus does not
330 require nops to be inserted. */
332 #define hilo_interlocks (mips_opts.arch == CPU_R4010 \
333 || mips_opts.arch == CPU_VR5500 \
334 || mips_opts.arch == CPU_RM7000 \
335 || mips_opts.arch == CPU_SB1 \
338 /* Whether the processor uses hardware interlocks to protect reads
339 from the GPRs after they are loaded from memory, and thus does not
340 require nops to be inserted. This applies to instructions marked
341 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
343 #define gpr_interlocks \
344 (mips_opts.isa != ISA_MIPS1 \
345 || mips_opts.arch == CPU_VR5400 \
346 || mips_opts.arch == CPU_VR5500 \
347 || mips_opts.arch == CPU_R3900)
349 /* Whether the processor uses hardware interlocks to avoid delays
350 required by coprocessor instructions, and thus does not require
351 nops to be inserted. This applies to instructions marked
352 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
353 between instructions marked INSN_WRITE_COND_CODE and ones marked
354 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
355 levels I, II, and III. */
356 /* Itbl support may require additional care here. */
357 #define cop_interlocks \
358 ((mips_opts.isa != ISA_MIPS1 \
359 && mips_opts.isa != ISA_MIPS2 \
360 && mips_opts.isa != ISA_MIPS3) \
361 || mips_opts.arch == CPU_R4300 \
362 || mips_opts.arch == CPU_VR5400 \
363 || mips_opts.arch == CPU_VR5500 \
364 || mips_opts.arch == CPU_SB1 \
367 /* Whether the processor uses hardware interlocks to protect reads
368 from coprocessor registers after they are loaded from memory, and
369 thus does not require nops to be inserted. This applies to
370 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
371 requires at MIPS ISA level I. */
372 #define cop_mem_interlocks (mips_opts.isa != ISA_MIPS1)
374 /* Is this a mfhi or mflo instruction? */
375 #define MF_HILO_INSN(PINFO) \
376 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
378 /* MIPS PIC level. */
380 enum mips_pic_level mips_pic;
382 /* 1 if we should generate 32 bit offsets from the $gp register in
383 SVR4_PIC mode. Currently has no meaning in other modes. */
384 static int mips_big_got = 0;
386 /* 1 if trap instructions should used for overflow rather than break
388 static int mips_trap = 0;
390 /* 1 if double width floating point constants should not be constructed
391 by assembling two single width halves into two single width floating
392 point registers which just happen to alias the double width destination
393 register. On some architectures this aliasing can be disabled by a bit
394 in the status register, and the setting of this bit cannot be determined
395 automatically at assemble time. */
396 static int mips_disable_float_construction;
398 /* Non-zero if any .set noreorder directives were used. */
400 static int mips_any_noreorder;
402 /* Non-zero if nops should be inserted when the register referenced in
403 an mfhi/mflo instruction is read in the next two instructions. */
404 static int mips_7000_hilo_fix;
406 /* The size of the small data section. */
407 static unsigned int g_switch_value = 8;
408 /* Whether the -G option was used. */
409 static int g_switch_seen = 0;
414 /* If we can determine in advance that GP optimization won't be
415 possible, we can skip the relaxation stuff that tries to produce
416 GP-relative references. This makes delay slot optimization work
419 This function can only provide a guess, but it seems to work for
420 gcc output. It needs to guess right for gcc, otherwise gcc
421 will put what it thinks is a GP-relative instruction in a branch
424 I don't know if a fix is needed for the SVR4_PIC mode. I've only
425 fixed it for the non-PIC mode. KR 95/04/07 */
426 static int nopic_need_relax (symbolS *, int);
428 /* handle of the OPCODE hash table */
429 static struct hash_control *op_hash = NULL;
431 /* The opcode hash table we use for the mips16. */
432 static struct hash_control *mips16_op_hash = NULL;
434 /* This array holds the chars that always start a comment. If the
435 pre-processor is disabled, these aren't very useful */
436 const char comment_chars[] = "#";
438 /* This array holds the chars that only start a comment at the beginning of
439 a line. If the line seems to have the form '# 123 filename'
440 .line and .file directives will appear in the pre-processed output */
441 /* Note that input_file.c hand checks for '#' at the beginning of the
442 first line of the input file. This is because the compiler outputs
443 #NO_APP at the beginning of its output. */
444 /* Also note that C style comments are always supported. */
445 const char line_comment_chars[] = "#";
447 /* This array holds machine specific line separator characters. */
448 const char line_separator_chars[] = ";";
450 /* Chars that can be used to separate mant from exp in floating point nums */
451 const char EXP_CHARS[] = "eE";
453 /* Chars that mean this number is a floating point constant */
456 const char FLT_CHARS[] = "rRsSfFdDxXpP";
458 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
459 changed in read.c . Ideally it shouldn't have to know about it at all,
460 but nothing is ideal around here.
463 static char *insn_error;
465 static int auto_align = 1;
467 /* When outputting SVR4 PIC code, the assembler needs to know the
468 offset in the stack frame from which to restore the $gp register.
469 This is set by the .cprestore pseudo-op, and saved in this
471 static offsetT mips_cprestore_offset = -1;
473 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
474 more optimizations, it can use a register value instead of a memory-saved
475 offset and even an other register than $gp as global pointer. */
476 static offsetT mips_cpreturn_offset = -1;
477 static int mips_cpreturn_register = -1;
478 static int mips_gp_register = GP;
479 static int mips_gprel_offset = 0;
481 /* Whether mips_cprestore_offset has been set in the current function
482 (or whether it has already been warned about, if not). */
483 static int mips_cprestore_valid = 0;
485 /* This is the register which holds the stack frame, as set by the
486 .frame pseudo-op. This is needed to implement .cprestore. */
487 static int mips_frame_reg = SP;
489 /* Whether mips_frame_reg has been set in the current function
490 (or whether it has already been warned about, if not). */
491 static int mips_frame_reg_valid = 0;
493 /* To output NOP instructions correctly, we need to keep information
494 about the previous two instructions. */
496 /* Whether we are optimizing. The default value of 2 means to remove
497 unneeded NOPs and swap branch instructions when possible. A value
498 of 1 means to not swap branches. A value of 0 means to always
500 static int mips_optimize = 2;
502 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
503 equivalent to seeing no -g option at all. */
504 static int mips_debug = 0;
506 /* The previous instruction. */
507 static struct mips_cl_insn prev_insn;
509 /* The instruction before prev_insn. */
510 static struct mips_cl_insn prev_prev_insn;
512 /* If we don't want information for prev_insn or prev_prev_insn, we
513 point the insn_mo field at this dummy integer. */
514 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
516 /* Non-zero if prev_insn is valid. */
517 static int prev_insn_valid;
519 /* The frag for the previous instruction. */
520 static struct frag *prev_insn_frag;
522 /* The offset into prev_insn_frag for the previous instruction. */
523 static long prev_insn_where;
525 /* The reloc type for the previous instruction, if any. */
526 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
528 /* The reloc for the previous instruction, if any. */
529 static fixS *prev_insn_fixp[3];
531 /* Non-zero if the previous instruction was in a delay slot. */
532 static int prev_insn_is_delay_slot;
534 /* Non-zero if the previous instruction was in a .set noreorder. */
535 static int prev_insn_unreordered;
537 /* Non-zero if the previous instruction uses an extend opcode (if
539 static int prev_insn_extended;
541 /* Non-zero if the previous previous instruction was in a .set
543 static int prev_prev_insn_unreordered;
545 /* If this is set, it points to a frag holding nop instructions which
546 were inserted before the start of a noreorder section. If those
547 nops turn out to be unnecessary, the size of the frag can be
549 static fragS *prev_nop_frag;
551 /* The number of nop instructions we created in prev_nop_frag. */
552 static int prev_nop_frag_holds;
554 /* The number of nop instructions that we know we need in
556 static int prev_nop_frag_required;
558 /* The number of instructions we've seen since prev_nop_frag. */
559 static int prev_nop_frag_since;
561 /* For ECOFF and ELF, relocations against symbols are done in two
562 parts, with a HI relocation and a LO relocation. Each relocation
563 has only 16 bits of space to store an addend. This means that in
564 order for the linker to handle carries correctly, it must be able
565 to locate both the HI and the LO relocation. This means that the
566 relocations must appear in order in the relocation table.
568 In order to implement this, we keep track of each unmatched HI
569 relocation. We then sort them so that they immediately precede the
570 corresponding LO relocation. */
575 struct mips_hi_fixup *next;
578 /* The section this fixup is in. */
582 /* The list of unmatched HI relocs. */
584 static struct mips_hi_fixup *mips_hi_fixup_list;
586 /* The frag containing the last explicit relocation operator.
587 Null if explicit relocations have not been used. */
589 static fragS *prev_reloc_op_frag;
591 /* Map normal MIPS register numbers to mips16 register numbers. */
593 #define X ILLEGAL_REG
594 static const int mips32_to_16_reg_map[] =
596 X, X, 2, 3, 4, 5, 6, 7,
597 X, X, X, X, X, X, X, X,
598 0, 1, X, X, X, X, X, X,
599 X, X, X, X, X, X, X, X
603 /* Map mips16 register numbers to normal MIPS register numbers. */
605 static const unsigned int mips16_to_32_reg_map[] =
607 16, 17, 2, 3, 4, 5, 6, 7
610 static int mips_fix_4122_bugs;
612 /* We don't relax branches by default, since this causes us to expand
613 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
614 fail to compute the offset before expanding the macro to the most
615 efficient expansion. */
617 static int mips_relax_branch;
619 /* Since the MIPS does not have multiple forms of PC relative
620 instructions, we do not have to do relaxing as is done on other
621 platforms. However, we do have to handle GP relative addressing
622 correctly, which turns out to be a similar problem.
624 Every macro that refers to a symbol can occur in (at least) two
625 forms, one with GP relative addressing and one without. For
626 example, loading a global variable into a register generally uses
627 a macro instruction like this:
629 If i can be addressed off the GP register (this is true if it is in
630 the .sbss or .sdata section, or if it is known to be smaller than
631 the -G argument) this will generate the following instruction:
633 This instruction will use a GPREL reloc. If i can not be addressed
634 off the GP register, the following instruction sequence will be used:
637 In this case the first instruction will have a HI16 reloc, and the
638 second reloc will have a LO16 reloc. Both relocs will be against
641 The issue here is that we may not know whether i is GP addressable
642 until after we see the instruction that uses it. Therefore, we
643 want to be able to choose the final instruction sequence only at
644 the end of the assembly. This is similar to the way other
645 platforms choose the size of a PC relative instruction only at the
648 When generating position independent code we do not use GP
649 addressing in quite the same way, but the issue still arises as
650 external symbols and local symbols must be handled differently.
652 We handle these issues by actually generating both possible
653 instruction sequences. The longer one is put in a frag_var with
654 type rs_machine_dependent. We encode what to do with the frag in
655 the subtype field. We encode (1) the number of existing bytes to
656 replace, (2) the number of new bytes to use, (3) the offset from
657 the start of the existing bytes to the first reloc we must generate
658 (that is, the offset is applied from the start of the existing
659 bytes after they are replaced by the new bytes, if any), (4) the
660 offset from the start of the existing bytes to the second reloc,
661 (5) whether a third reloc is needed (the third reloc is always four
662 bytes after the second reloc), and (6) whether to warn if this
663 variant is used (this is sometimes needed if .set nomacro or .set
664 noat is in effect). All these numbers are reasonably small.
666 Generating two instruction sequences must be handled carefully to
667 ensure that delay slots are handled correctly. Fortunately, there
668 are a limited number of cases. When the second instruction
669 sequence is generated, append_insn is directed to maintain the
670 existing delay slot information, so it continues to apply to any
671 code after the second instruction sequence. This means that the
672 second instruction sequence must not impose any requirements not
673 required by the first instruction sequence.
675 These variant frags are then handled in functions called by the
676 machine independent code. md_estimate_size_before_relax returns
677 the final size of the frag. md_convert_frag sets up the final form
678 of the frag. tc_gen_reloc adjust the first reloc and adds a second
680 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
684 | (((reloc1) + 64) << 9) \
685 | (((reloc2) + 64) << 2) \
686 | ((reloc3) ? (1 << 1) : 0) \
688 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
689 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
690 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
691 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
692 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
693 #define RELAX_WARN(i) ((i) & 1)
695 /* Branch without likely bit. If label is out of range, we turn:
697 beq reg1, reg2, label
707 with the following opcode replacements:
714 bltzal <-> bgezal (with jal label instead of j label)
716 Even though keeping the delay slot instruction in the delay slot of
717 the branch would be more efficient, it would be very tricky to do
718 correctly, because we'd have to introduce a variable frag *after*
719 the delay slot instruction, and expand that instead. Let's do it
720 the easy way for now, even if the branch-not-taken case now costs
721 one additional instruction. Out-of-range branches are not supposed
722 to be common, anyway.
724 Branch likely. If label is out of range, we turn:
726 beql reg1, reg2, label
727 delay slot (annulled if branch not taken)
736 delay slot (executed only if branch taken)
739 It would be possible to generate a shorter sequence by losing the
740 likely bit, generating something like:
745 delay slot (executed only if branch taken)
757 bltzall -> bgezal (with jal label instead of j label)
758 bgezall -> bltzal (ditto)
761 but it's not clear that it would actually improve performance. */
762 #define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
765 | ((toofar) ? 1 : 0) \
767 | ((likely) ? 4 : 0) \
768 | ((uncond) ? 8 : 0)))
769 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
770 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
771 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
772 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
773 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1) != 0)
775 /* For mips16 code, we use an entirely different form of relaxation.
776 mips16 supports two versions of most instructions which take
777 immediate values: a small one which takes some small value, and a
778 larger one which takes a 16 bit value. Since branches also follow
779 this pattern, relaxing these values is required.
781 We can assemble both mips16 and normal MIPS code in a single
782 object. Therefore, we need to support this type of relaxation at
783 the same time that we support the relaxation described above. We
784 use the high bit of the subtype field to distinguish these cases.
786 The information we store for this type of relaxation is the
787 argument code found in the opcode file for this relocation, whether
788 the user explicitly requested a small or extended form, and whether
789 the relocation is in a jump or jal delay slot. That tells us the
790 size of the value, and how it should be stored. We also store
791 whether the fragment is considered to be extended or not. We also
792 store whether this is known to be a branch to a different section,
793 whether we have tried to relax this frag yet, and whether we have
794 ever extended a PC relative fragment because of a shift count. */
795 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
798 | ((small) ? 0x100 : 0) \
799 | ((ext) ? 0x200 : 0) \
800 | ((dslot) ? 0x400 : 0) \
801 | ((jal_dslot) ? 0x800 : 0))
802 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
803 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
804 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
805 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
806 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
807 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
808 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
809 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
810 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
811 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
812 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
813 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
815 /* Is the given value a sign-extended 32-bit value? */
816 #define IS_SEXT_32BIT_NUM(x) \
817 (((x) &~ (offsetT) 0x7fffffff) == 0 \
818 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
820 /* Is the given value a sign-extended 16-bit value? */
821 #define IS_SEXT_16BIT_NUM(x) \
822 (((x) &~ (offsetT) 0x7fff) == 0 \
823 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
826 /* Prototypes for static functions. */
828 #define internalError() \
829 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
831 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
833 static void append_insn
834 (char *place, struct mips_cl_insn *ip, expressionS *p,
835 bfd_reloc_code_real_type *r);
836 static void mips_no_prev_insn (int);
837 static void mips16_macro_build
838 (char *, int *, expressionS *, const char *, const char *, va_list);
839 static void load_register (int *, int, expressionS *, int);
840 static void macro (struct mips_cl_insn * ip);
841 static void mips16_macro (struct mips_cl_insn * ip);
842 #ifdef LOSING_COMPILER
843 static void macro2 (struct mips_cl_insn * ip);
845 static void mips_ip (char *str, struct mips_cl_insn * ip);
846 static void mips16_ip (char *str, struct mips_cl_insn * ip);
847 static void mips16_immed
848 (char *, unsigned int, int, offsetT, bfd_boolean, bfd_boolean, bfd_boolean,
849 unsigned long *, bfd_boolean *, unsigned short *);
850 static size_t my_getSmallExpression
851 (expressionS *, bfd_reloc_code_real_type *, char *);
852 static void my_getExpression (expressionS *, char *);
853 static void s_align (int);
854 static void s_change_sec (int);
855 static void s_change_section (int);
856 static void s_cons (int);
857 static void s_float_cons (int);
858 static void s_mips_globl (int);
859 static void s_option (int);
860 static void s_mipsset (int);
861 static void s_abicalls (int);
862 static void s_cpload (int);
863 static void s_cpsetup (int);
864 static void s_cplocal (int);
865 static void s_cprestore (int);
866 static void s_cpreturn (int);
867 static void s_gpvalue (int);
868 static void s_gpword (int);
869 static void s_gpdword (int);
870 static void s_cpadd (int);
871 static void s_insn (int);
872 static void md_obj_begin (void);
873 static void md_obj_end (void);
874 static void s_mips_ent (int);
875 static void s_mips_end (int);
876 static void s_mips_frame (int);
877 static void s_mips_mask (int reg_type);
878 static void s_mips_stab (int);
879 static void s_mips_weakext (int);
880 static void s_mips_file (int);
881 static void s_mips_loc (int);
882 static bfd_boolean pic_need_relax (symbolS *, asection *);
883 static int relaxed_branch_length (fragS *, asection *, int);
884 static int validate_mips_insn (const struct mips_opcode *);
886 /* Table and functions used to map between CPU/ISA names, and
887 ISA levels, and CPU numbers. */
891 const char *name; /* CPU or ISA name. */
892 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
893 int isa; /* ISA level. */
894 int cpu; /* CPU number (default CPU if ISA). */
897 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
898 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
899 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
903 The following pseudo-ops from the Kane and Heinrich MIPS book
904 should be defined here, but are currently unsupported: .alias,
905 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
907 The following pseudo-ops from the Kane and Heinrich MIPS book are
908 specific to the type of debugging information being generated, and
909 should be defined by the object format: .aent, .begin, .bend,
910 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
913 The following pseudo-ops from the Kane and Heinrich MIPS book are
914 not MIPS CPU specific, but are also not specific to the object file
915 format. This file is probably the best place to define them, but
916 they are not currently supported: .asm0, .endr, .lab, .repeat,
919 static const pseudo_typeS mips_pseudo_table[] =
921 /* MIPS specific pseudo-ops. */
922 {"option", s_option, 0},
923 {"set", s_mipsset, 0},
924 {"rdata", s_change_sec, 'r'},
925 {"sdata", s_change_sec, 's'},
926 {"livereg", s_ignore, 0},
927 {"abicalls", s_abicalls, 0},
928 {"cpload", s_cpload, 0},
929 {"cpsetup", s_cpsetup, 0},
930 {"cplocal", s_cplocal, 0},
931 {"cprestore", s_cprestore, 0},
932 {"cpreturn", s_cpreturn, 0},
933 {"gpvalue", s_gpvalue, 0},
934 {"gpword", s_gpword, 0},
935 {"gpdword", s_gpdword, 0},
936 {"cpadd", s_cpadd, 0},
939 /* Relatively generic pseudo-ops that happen to be used on MIPS
941 {"asciiz", stringer, 1},
942 {"bss", s_change_sec, 'b'},
945 {"dword", s_cons, 3},
946 {"weakext", s_mips_weakext, 0},
948 /* These pseudo-ops are defined in read.c, but must be overridden
949 here for one reason or another. */
950 {"align", s_align, 0},
952 {"data", s_change_sec, 'd'},
953 {"double", s_float_cons, 'd'},
954 {"float", s_float_cons, 'f'},
955 {"globl", s_mips_globl, 0},
956 {"global", s_mips_globl, 0},
957 {"hword", s_cons, 1},
962 {"section", s_change_section, 0},
963 {"short", s_cons, 1},
964 {"single", s_float_cons, 'f'},
965 {"stabn", s_mips_stab, 'n'},
966 {"text", s_change_sec, 't'},
969 { "extern", ecoff_directive_extern, 0},
974 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
976 /* These pseudo-ops should be defined by the object file format.
977 However, a.out doesn't support them, so we have versions here. */
978 {"aent", s_mips_ent, 1},
979 {"bgnb", s_ignore, 0},
980 {"end", s_mips_end, 0},
981 {"endb", s_ignore, 0},
982 {"ent", s_mips_ent, 0},
983 {"file", s_mips_file, 0},
984 {"fmask", s_mips_mask, 'F'},
985 {"frame", s_mips_frame, 0},
986 {"loc", s_mips_loc, 0},
987 {"mask", s_mips_mask, 'R'},
988 {"verstamp", s_ignore, 0},
992 extern void pop_insert (const pseudo_typeS *);
995 mips_pop_insert (void)
997 pop_insert (mips_pseudo_table);
998 if (! ECOFF_DEBUGGING)
999 pop_insert (mips_nonecoff_pseudo_table);
1002 /* Symbols labelling the current insn. */
1004 struct insn_label_list
1006 struct insn_label_list *next;
1010 static struct insn_label_list *insn_labels;
1011 static struct insn_label_list *free_insn_labels;
1013 static void mips_clear_insn_labels (void);
1016 mips_clear_insn_labels (void)
1018 register struct insn_label_list **pl;
1020 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1026 static char *expr_end;
1028 /* Expressions which appear in instructions. These are set by
1031 static expressionS imm_expr;
1032 static expressionS imm2_expr;
1033 static expressionS offset_expr;
1035 /* Relocs associated with imm_expr and offset_expr. */
1037 static bfd_reloc_code_real_type imm_reloc[3]
1038 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1039 static bfd_reloc_code_real_type offset_reloc[3]
1040 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1042 /* These are set by mips16_ip if an explicit extension is used. */
1044 static bfd_boolean mips16_small, mips16_ext;
1047 /* The pdr segment for per procedure frame/regmask info. Not used for
1050 static segT pdr_seg;
1053 /* The default target format to use. */
1056 mips_target_format (void)
1058 switch (OUTPUT_FLAVOR)
1060 case bfd_target_aout_flavour:
1061 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
1062 case bfd_target_ecoff_flavour:
1063 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1064 case bfd_target_coff_flavour:
1066 case bfd_target_elf_flavour:
1068 /* This is traditional mips. */
1069 return (target_big_endian
1070 ? (HAVE_64BIT_OBJECTS
1071 ? "elf64-tradbigmips"
1073 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1074 : (HAVE_64BIT_OBJECTS
1075 ? "elf64-tradlittlemips"
1077 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1079 return (target_big_endian
1080 ? (HAVE_64BIT_OBJECTS
1083 ? "elf32-nbigmips" : "elf32-bigmips"))
1084 : (HAVE_64BIT_OBJECTS
1085 ? "elf64-littlemips"
1087 ? "elf32-nlittlemips" : "elf32-littlemips")));
1095 /* This function is called once, at assembler startup time. It should
1096 set up all the tables, etc. that the MD part of the assembler will need. */
1101 register const char *retval = NULL;
1105 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
1106 as_warn (_("Could not set architecture and machine"));
1108 op_hash = hash_new ();
1110 for (i = 0; i < NUMOPCODES;)
1112 const char *name = mips_opcodes[i].name;
1114 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
1117 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1118 mips_opcodes[i].name, retval);
1119 /* Probably a memory allocation problem? Give up now. */
1120 as_fatal (_("Broken assembler. No assembly attempted."));
1124 if (mips_opcodes[i].pinfo != INSN_MACRO)
1126 if (!validate_mips_insn (&mips_opcodes[i]))
1131 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1134 mips16_op_hash = hash_new ();
1137 while (i < bfd_mips16_num_opcodes)
1139 const char *name = mips16_opcodes[i].name;
1141 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
1143 as_fatal (_("internal: can't hash `%s': %s"),
1144 mips16_opcodes[i].name, retval);
1147 if (mips16_opcodes[i].pinfo != INSN_MACRO
1148 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1149 != mips16_opcodes[i].match))
1151 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1152 mips16_opcodes[i].name, mips16_opcodes[i].args);
1157 while (i < bfd_mips16_num_opcodes
1158 && strcmp (mips16_opcodes[i].name, name) == 0);
1162 as_fatal (_("Broken assembler. No assembly attempted."));
1164 /* We add all the general register names to the symbol table. This
1165 helps us detect invalid uses of them. */
1166 for (i = 0; i < 32; i++)
1170 sprintf (buf, "$%d", i);
1171 symbol_table_insert (symbol_new (buf, reg_section, i,
1172 &zero_address_frag));
1174 symbol_table_insert (symbol_new ("$ra", reg_section, RA,
1175 &zero_address_frag));
1176 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1177 &zero_address_frag));
1178 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1179 &zero_address_frag));
1180 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1181 &zero_address_frag));
1182 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1183 &zero_address_frag));
1184 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1185 &zero_address_frag));
1186 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1187 &zero_address_frag));
1188 symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
1189 &zero_address_frag));
1190 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1191 &zero_address_frag));
1193 /* If we don't add these register names to the symbol table, they
1194 may end up being added as regular symbols by operand(), and then
1195 make it to the object file as undefined in case they're not
1196 regarded as local symbols. They're local in o32, since `$' is a
1197 local symbol prefix, but not in n32 or n64. */
1198 for (i = 0; i < 8; i++)
1202 sprintf (buf, "$fcc%i", i);
1203 symbol_table_insert (symbol_new (buf, reg_section, -1,
1204 &zero_address_frag));
1207 mips_no_prev_insn (FALSE);
1210 mips_cprmask[0] = 0;
1211 mips_cprmask[1] = 0;
1212 mips_cprmask[2] = 0;
1213 mips_cprmask[3] = 0;
1215 /* set the default alignment for the text section (2**2) */
1216 record_alignment (text_section, 2);
1218 if (USE_GLOBAL_POINTER_OPT)
1219 bfd_set_gp_size (stdoutput, g_switch_value);
1221 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1223 /* On a native system, sections must be aligned to 16 byte
1224 boundaries. When configured for an embedded ELF target, we
1226 if (strcmp (TARGET_OS, "elf") != 0)
1228 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1229 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1230 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1233 /* Create a .reginfo section for register masks and a .mdebug
1234 section for debugging information. */
1242 subseg = now_subseg;
1244 /* The ABI says this section should be loaded so that the
1245 running program can access it. However, we don't load it
1246 if we are configured for an embedded target */
1247 flags = SEC_READONLY | SEC_DATA;
1248 if (strcmp (TARGET_OS, "elf") != 0)
1249 flags |= SEC_ALLOC | SEC_LOAD;
1251 if (mips_abi != N64_ABI)
1253 sec = subseg_new (".reginfo", (subsegT) 0);
1255 bfd_set_section_flags (stdoutput, sec, flags);
1256 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1259 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1264 /* The 64-bit ABI uses a .MIPS.options section rather than
1265 .reginfo section. */
1266 sec = subseg_new (".MIPS.options", (subsegT) 0);
1267 bfd_set_section_flags (stdoutput, sec, flags);
1268 bfd_set_section_alignment (stdoutput, sec, 3);
1271 /* Set up the option header. */
1273 Elf_Internal_Options opthdr;
1276 opthdr.kind = ODK_REGINFO;
1277 opthdr.size = (sizeof (Elf_External_Options)
1278 + sizeof (Elf64_External_RegInfo));
1281 f = frag_more (sizeof (Elf_External_Options));
1282 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1283 (Elf_External_Options *) f);
1285 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1290 if (ECOFF_DEBUGGING)
1292 sec = subseg_new (".mdebug", (subsegT) 0);
1293 (void) bfd_set_section_flags (stdoutput, sec,
1294 SEC_HAS_CONTENTS | SEC_READONLY);
1295 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1298 else if (OUTPUT_FLAVOR == bfd_target_elf_flavour && mips_flag_pdr)
1300 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1301 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1302 SEC_READONLY | SEC_RELOC
1304 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1308 subseg_set (seg, subseg);
1312 if (! ECOFF_DEBUGGING)
1319 if (! ECOFF_DEBUGGING)
1324 md_assemble (char *str)
1326 struct mips_cl_insn insn;
1327 bfd_reloc_code_real_type unused_reloc[3]
1328 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1330 imm_expr.X_op = O_absent;
1331 imm2_expr.X_op = O_absent;
1332 offset_expr.X_op = O_absent;
1333 imm_reloc[0] = BFD_RELOC_UNUSED;
1334 imm_reloc[1] = BFD_RELOC_UNUSED;
1335 imm_reloc[2] = BFD_RELOC_UNUSED;
1336 offset_reloc[0] = BFD_RELOC_UNUSED;
1337 offset_reloc[1] = BFD_RELOC_UNUSED;
1338 offset_reloc[2] = BFD_RELOC_UNUSED;
1340 if (mips_opts.mips16)
1341 mips16_ip (str, &insn);
1344 mips_ip (str, &insn);
1345 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1346 str, insn.insn_opcode));
1351 as_bad ("%s `%s'", insn_error, str);
1355 if (insn.insn_mo->pinfo == INSN_MACRO)
1357 if (mips_opts.mips16)
1358 mips16_macro (&insn);
1364 if (imm_expr.X_op != O_absent)
1365 append_insn (NULL, &insn, &imm_expr, imm_reloc);
1366 else if (offset_expr.X_op != O_absent)
1367 append_insn (NULL, &insn, &offset_expr, offset_reloc);
1369 append_insn (NULL, &insn, NULL, unused_reloc);
1373 /* Return true if the given relocation might need a matching %lo().
1374 Note that R_MIPS_GOT16 relocations only need a matching %lo() when
1375 applied to local symbols. */
1377 static inline bfd_boolean
1378 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
1380 return (reloc == BFD_RELOC_HI16_S
1381 || reloc == BFD_RELOC_MIPS_GOT16);
1384 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
1387 static inline bfd_boolean
1388 fixup_has_matching_lo_p (fixS *fixp)
1390 return (fixp->fx_next != NULL
1391 && fixp->fx_next->fx_r_type == BFD_RELOC_LO16
1392 && fixp->fx_addsy == fixp->fx_next->fx_addsy
1393 && fixp->fx_offset == fixp->fx_next->fx_offset);
1396 /* See whether instruction IP reads register REG. CLASS is the type
1400 insn_uses_reg (struct mips_cl_insn *ip, unsigned int reg,
1401 enum mips_regclass class)
1403 if (class == MIPS16_REG)
1405 assert (mips_opts.mips16);
1406 reg = mips16_to_32_reg_map[reg];
1407 class = MIPS_GR_REG;
1410 /* Don't report on general register ZERO, since it never changes. */
1411 if (class == MIPS_GR_REG && reg == ZERO)
1414 if (class == MIPS_FP_REG)
1416 assert (! mips_opts.mips16);
1417 /* If we are called with either $f0 or $f1, we must check $f0.
1418 This is not optimal, because it will introduce an unnecessary
1419 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1420 need to distinguish reading both $f0 and $f1 or just one of
1421 them. Note that we don't have to check the other way,
1422 because there is no instruction that sets both $f0 and $f1
1423 and requires a delay. */
1424 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1425 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1426 == (reg &~ (unsigned) 1)))
1428 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1429 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1430 == (reg &~ (unsigned) 1)))
1433 else if (! mips_opts.mips16)
1435 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1436 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1438 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1439 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1444 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1445 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1446 & MIPS16OP_MASK_RX)]
1449 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1450 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1451 & MIPS16OP_MASK_RY)]
1454 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1455 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1456 & MIPS16OP_MASK_MOVE32Z)]
1459 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1461 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1463 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1465 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1466 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1467 & MIPS16OP_MASK_REGR32) == reg)
1474 /* This function returns true if modifying a register requires a
1478 reg_needs_delay (unsigned int reg)
1480 unsigned long prev_pinfo;
1482 prev_pinfo = prev_insn.insn_mo->pinfo;
1483 if (! mips_opts.noreorder
1484 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
1485 && ! gpr_interlocks)
1486 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1487 && ! cop_interlocks)))
1489 /* A load from a coprocessor or from memory. All load delays
1490 delay the use of general register rt for one instruction. */
1491 /* Itbl support may require additional care here. */
1492 know (prev_pinfo & INSN_WRITE_GPR_T);
1493 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1500 /* Mark instruction labels in mips16 mode. This permits the linker to
1501 handle them specially, such as generating jalx instructions when
1502 needed. We also make them odd for the duration of the assembly, in
1503 order to generate the right sort of code. We will make them even
1504 in the adjust_symtab routine, while leaving them marked. This is
1505 convenient for the debugger and the disassembler. The linker knows
1506 to make them odd again. */
1509 mips16_mark_labels (void)
1511 if (mips_opts.mips16)
1513 struct insn_label_list *l;
1516 for (l = insn_labels; l != NULL; l = l->next)
1519 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1520 S_SET_OTHER (l->label, STO_MIPS16);
1522 val = S_GET_VALUE (l->label);
1524 S_SET_VALUE (l->label, val + 1);
1529 /* Output an instruction. PLACE is where to put the instruction; if
1530 it is NULL, this uses frag_more to get room. IP is the instruction
1531 information. ADDRESS_EXPR is an operand of the instruction to be
1532 used with RELOC_TYPE. */
1535 append_insn (char *place, struct mips_cl_insn *ip, expressionS *address_expr,
1536 bfd_reloc_code_real_type *reloc_type)
1538 register unsigned long prev_pinfo, pinfo;
1542 bfd_boolean force_new_frag = FALSE;
1544 /* Mark instruction labels in mips16 mode. */
1545 mips16_mark_labels ();
1547 prev_pinfo = prev_insn.insn_mo->pinfo;
1548 pinfo = ip->insn_mo->pinfo;
1550 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1554 /* If the previous insn required any delay slots, see if we need
1555 to insert a NOP or two. There are eight kinds of possible
1556 hazards, of which an instruction can have at most one type.
1557 (1) a load from memory delay
1558 (2) a load from a coprocessor delay
1559 (3) an unconditional branch delay
1560 (4) a conditional branch delay
1561 (5) a move to coprocessor register delay
1562 (6) a load coprocessor register from memory delay
1563 (7) a coprocessor condition code delay
1564 (8) a HI/LO special register delay
1566 There are a lot of optimizations we could do that we don't.
1567 In particular, we do not, in general, reorder instructions.
1568 If you use gcc with optimization, it will reorder
1569 instructions and generally do much more optimization then we
1570 do here; repeating all that work in the assembler would only
1571 benefit hand written assembly code, and does not seem worth
1574 /* This is how a NOP is emitted. */
1575 #define emit_nop() \
1577 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1578 : md_number_to_chars (frag_more (4), 0, 4))
1580 /* The previous insn might require a delay slot, depending upon
1581 the contents of the current insn. */
1582 if (! mips_opts.mips16
1583 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
1584 && ! gpr_interlocks)
1585 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1586 && ! cop_interlocks)))
1588 /* A load from a coprocessor or from memory. All load
1589 delays delay the use of general register rt for one
1591 /* Itbl support may require additional care here. */
1592 know (prev_pinfo & INSN_WRITE_GPR_T);
1593 if (mips_optimize == 0
1594 || insn_uses_reg (ip,
1595 ((prev_insn.insn_opcode >> OP_SH_RT)
1600 else if (! mips_opts.mips16
1601 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1602 && ! cop_interlocks)
1603 || ((prev_pinfo & INSN_COPROC_MEMORY_DELAY)
1604 && ! cop_mem_interlocks)))
1606 /* A generic coprocessor delay. The previous instruction
1607 modified a coprocessor general or control register. If
1608 it modified a control register, we need to avoid any
1609 coprocessor instruction (this is probably not always
1610 required, but it sometimes is). If it modified a general
1611 register, we avoid using that register.
1613 This case is not handled very well. There is no special
1614 knowledge of CP0 handling, and the coprocessors other
1615 than the floating point unit are not distinguished at
1617 /* Itbl support may require additional care here. FIXME!
1618 Need to modify this to include knowledge about
1619 user specified delays! */
1620 if (prev_pinfo & INSN_WRITE_FPR_T)
1622 if (mips_optimize == 0
1623 || insn_uses_reg (ip,
1624 ((prev_insn.insn_opcode >> OP_SH_FT)
1629 else if (prev_pinfo & INSN_WRITE_FPR_S)
1631 if (mips_optimize == 0
1632 || insn_uses_reg (ip,
1633 ((prev_insn.insn_opcode >> OP_SH_FS)
1640 /* We don't know exactly what the previous instruction
1641 does. If the current instruction uses a coprocessor
1642 register, we must insert a NOP. If previous
1643 instruction may set the condition codes, and the
1644 current instruction uses them, we must insert two
1646 /* Itbl support may require additional care here. */
1647 if (mips_optimize == 0
1648 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1649 && (pinfo & INSN_READ_COND_CODE)))
1651 else if (pinfo & INSN_COP)
1655 else if (! mips_opts.mips16
1656 && (prev_pinfo & INSN_WRITE_COND_CODE)
1657 && ! cop_interlocks)
1659 /* The previous instruction sets the coprocessor condition
1660 codes, but does not require a general coprocessor delay
1661 (this means it is a floating point comparison
1662 instruction). If this instruction uses the condition
1663 codes, we need to insert a single NOP. */
1664 /* Itbl support may require additional care here. */
1665 if (mips_optimize == 0
1666 || (pinfo & INSN_READ_COND_CODE))
1670 /* If we're fixing up mfhi/mflo for the r7000 and the
1671 previous insn was an mfhi/mflo and the current insn
1672 reads the register that the mfhi/mflo wrote to, then
1675 else if (mips_7000_hilo_fix
1676 && MF_HILO_INSN (prev_pinfo)
1677 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1684 /* If we're fixing up mfhi/mflo for the r7000 and the
1685 2nd previous insn was an mfhi/mflo and the current insn
1686 reads the register that the mfhi/mflo wrote to, then
1689 else if (mips_7000_hilo_fix
1690 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1691 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1699 else if (prev_pinfo & INSN_READ_LO)
1701 /* The previous instruction reads the LO register; if the
1702 current instruction writes to the LO register, we must
1703 insert two NOPS. Some newer processors have interlocks.
1704 Also the tx39's multiply instructions can be executed
1705 immediately after a read from HI/LO (without the delay),
1706 though the tx39's divide insns still do require the
1708 if (! (hilo_interlocks
1709 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1710 && (mips_optimize == 0
1711 || (pinfo & INSN_WRITE_LO)))
1713 /* Most mips16 branch insns don't have a delay slot.
1714 If a read from LO is immediately followed by a branch
1715 to a write to LO we have a read followed by a write
1716 less than 2 insns away. We assume the target of
1717 a branch might be a write to LO, and insert a nop
1718 between a read and an immediately following branch. */
1719 else if (mips_opts.mips16
1720 && (mips_optimize == 0
1721 || (pinfo & MIPS16_INSN_BRANCH)))
1724 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1726 /* The previous instruction reads the HI register; if the
1727 current instruction writes to the HI register, we must
1728 insert a NOP. Some newer processors have interlocks.
1729 Also the note tx39's multiply above. */
1730 if (! (hilo_interlocks
1731 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1732 && (mips_optimize == 0
1733 || (pinfo & INSN_WRITE_HI)))
1735 /* Most mips16 branch insns don't have a delay slot.
1736 If a read from HI is immediately followed by a branch
1737 to a write to HI we have a read followed by a write
1738 less than 2 insns away. We assume the target of
1739 a branch might be a write to HI, and insert a nop
1740 between a read and an immediately following branch. */
1741 else if (mips_opts.mips16
1742 && (mips_optimize == 0
1743 || (pinfo & MIPS16_INSN_BRANCH)))
1747 /* If the previous instruction was in a noreorder section, then
1748 we don't want to insert the nop after all. */
1749 /* Itbl support may require additional care here. */
1750 if (prev_insn_unreordered)
1753 /* There are two cases which require two intervening
1754 instructions: 1) setting the condition codes using a move to
1755 coprocessor instruction which requires a general coprocessor
1756 delay and then reading the condition codes 2) reading the HI
1757 or LO register and then writing to it (except on processors
1758 which have interlocks). If we are not already emitting a NOP
1759 instruction, we must check for these cases compared to the
1760 instruction previous to the previous instruction. */
1761 if ((! mips_opts.mips16
1762 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1763 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1764 && (pinfo & INSN_READ_COND_CODE)
1765 && ! cop_interlocks)
1766 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1767 && (pinfo & INSN_WRITE_LO)
1768 && ! (hilo_interlocks
1769 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1770 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1771 && (pinfo & INSN_WRITE_HI)
1772 && ! (hilo_interlocks
1773 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1778 if (prev_prev_insn_unreordered)
1781 if (prev_prev_nop && nops == 0)
1784 if (mips_fix_4122_bugs && prev_insn.insn_mo->name)
1786 /* We're out of bits in pinfo, so we must resort to string
1787 ops here. Shortcuts are selected based on opcodes being
1788 limited to the VR4122 instruction set. */
1790 const char *pn = prev_insn.insn_mo->name;
1791 const char *tn = ip->insn_mo->name;
1792 if (strncmp(pn, "macc", 4) == 0
1793 || strncmp(pn, "dmacc", 5) == 0)
1795 /* Errata 21 - [D]DIV[U] after [D]MACC */
1796 if (strstr (tn, "div"))
1801 /* Errata 23 - Continuous DMULT[U]/DMACC instructions */
1802 if (pn[0] == 'd' /* dmacc */
1803 && (strncmp(tn, "dmult", 5) == 0
1804 || strncmp(tn, "dmacc", 5) == 0))
1809 /* Errata 24 - MT{LO,HI} after [D]MACC */
1810 if (strcmp (tn, "mtlo") == 0
1811 || strcmp (tn, "mthi") == 0)
1817 else if (strncmp(pn, "dmult", 5) == 0
1818 && (strncmp(tn, "dmult", 5) == 0
1819 || strncmp(tn, "dmacc", 5) == 0))
1821 /* Here is the rest of errata 23. */
1824 if (nops < min_nops)
1828 /* If we are being given a nop instruction, don't bother with
1829 one of the nops we would otherwise output. This will only
1830 happen when a nop instruction is used with mips_optimize set
1833 && ! mips_opts.noreorder
1834 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1837 /* Now emit the right number of NOP instructions. */
1838 if (nops > 0 && ! mips_opts.noreorder)
1841 unsigned long old_frag_offset;
1843 struct insn_label_list *l;
1845 old_frag = frag_now;
1846 old_frag_offset = frag_now_fix ();
1848 for (i = 0; i < nops; i++)
1853 listing_prev_line ();
1854 /* We may be at the start of a variant frag. In case we
1855 are, make sure there is enough space for the frag
1856 after the frags created by listing_prev_line. The
1857 argument to frag_grow here must be at least as large
1858 as the argument to all other calls to frag_grow in
1859 this file. We don't have to worry about being in the
1860 middle of a variant frag, because the variants insert
1861 all needed nop instructions themselves. */
1865 for (l = insn_labels; l != NULL; l = l->next)
1869 assert (S_GET_SEGMENT (l->label) == now_seg);
1870 symbol_set_frag (l->label, frag_now);
1871 val = (valueT) frag_now_fix ();
1872 /* mips16 text labels are stored as odd. */
1873 if (mips_opts.mips16)
1875 S_SET_VALUE (l->label, val);
1878 #ifndef NO_ECOFF_DEBUGGING
1879 if (ECOFF_DEBUGGING)
1880 ecoff_fix_loc (old_frag, old_frag_offset);
1883 else if (prev_nop_frag != NULL)
1885 /* We have a frag holding nops we may be able to remove. If
1886 we don't need any nops, we can decrease the size of
1887 prev_nop_frag by the size of one instruction. If we do
1888 need some nops, we count them in prev_nops_required. */
1889 if (prev_nop_frag_since == 0)
1893 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1894 --prev_nop_frag_holds;
1897 prev_nop_frag_required += nops;
1901 if (prev_prev_nop == 0)
1903 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1904 --prev_nop_frag_holds;
1907 ++prev_nop_frag_required;
1910 if (prev_nop_frag_holds <= prev_nop_frag_required)
1911 prev_nop_frag = NULL;
1913 ++prev_nop_frag_since;
1915 /* Sanity check: by the time we reach the second instruction
1916 after prev_nop_frag, we should have used up all the nops
1917 one way or another. */
1918 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1924 && *reloc_type == BFD_RELOC_16_PCREL_S2
1925 && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY
1926 || pinfo & INSN_COND_BRANCH_LIKELY)
1927 && mips_relax_branch
1928 /* Don't try branch relaxation within .set nomacro, or within
1929 .set noat if we use $at for PIC computations. If it turns
1930 out that the branch was out-of-range, we'll get an error. */
1931 && !mips_opts.warn_about_macros
1932 && !(mips_opts.noat && mips_pic != NO_PIC)
1933 && !mips_opts.mips16)
1935 f = frag_var (rs_machine_dependent,
1936 relaxed_branch_length
1938 (pinfo & INSN_UNCOND_BRANCH_DELAY) ? -1
1939 : (pinfo & INSN_COND_BRANCH_LIKELY) ? 1 : 0), 4,
1941 (pinfo & INSN_UNCOND_BRANCH_DELAY,
1942 pinfo & INSN_COND_BRANCH_LIKELY,
1943 pinfo & INSN_WRITE_GPR_31,
1945 address_expr->X_add_symbol,
1946 address_expr->X_add_number,
1948 *reloc_type = BFD_RELOC_UNUSED;
1950 else if (*reloc_type > BFD_RELOC_UNUSED)
1952 /* We need to set up a variant frag. */
1953 assert (mips_opts.mips16 && address_expr != NULL);
1954 f = frag_var (rs_machine_dependent, 4, 0,
1955 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
1956 mips16_small, mips16_ext,
1958 & INSN_UNCOND_BRANCH_DELAY),
1959 (*prev_insn_reloc_type
1960 == BFD_RELOC_MIPS16_JMP)),
1961 make_expr_symbol (address_expr), 0, NULL);
1963 else if (place != NULL)
1965 else if (mips_opts.mips16
1967 && *reloc_type != BFD_RELOC_MIPS16_JMP)
1969 /* Make sure there is enough room to swap this instruction with
1970 a following jump instruction. */
1976 if (mips_opts.mips16
1977 && mips_opts.noreorder
1978 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1979 as_warn (_("extended instruction in delay slot"));
1984 fixp[0] = fixp[1] = fixp[2] = NULL;
1985 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
1987 if (address_expr->X_op == O_constant)
1991 switch (*reloc_type)
1994 ip->insn_opcode |= address_expr->X_add_number;
1997 case BFD_RELOC_MIPS_HIGHEST:
1998 tmp = (address_expr->X_add_number
1999 + ((valueT) 0x8000 << 32) + 0x80008000) >> 16;
2001 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2004 case BFD_RELOC_MIPS_HIGHER:
2005 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
2006 ip->insn_opcode |= (tmp >> 16) & 0xffff;
2009 case BFD_RELOC_HI16_S:
2010 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
2014 case BFD_RELOC_HI16:
2015 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2018 case BFD_RELOC_LO16:
2019 case BFD_RELOC_MIPS_GOT_DISP:
2020 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2023 case BFD_RELOC_MIPS_JMP:
2024 if ((address_expr->X_add_number & 3) != 0)
2025 as_bad (_("jump to misaligned address (0x%lx)"),
2026 (unsigned long) address_expr->X_add_number);
2027 if (address_expr->X_add_number & ~0xfffffff)
2028 as_bad (_("jump address range overflow (0x%lx)"),
2029 (unsigned long) address_expr->X_add_number);
2030 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2033 case BFD_RELOC_MIPS16_JMP:
2034 if ((address_expr->X_add_number & 3) != 0)
2035 as_bad (_("jump to misaligned address (0x%lx)"),
2036 (unsigned long) address_expr->X_add_number);
2037 if (address_expr->X_add_number & ~0xfffffff)
2038 as_bad (_("jump address range overflow (0x%lx)"),
2039 (unsigned long) address_expr->X_add_number);
2041 (((address_expr->X_add_number & 0x7c0000) << 3)
2042 | ((address_expr->X_add_number & 0xf800000) >> 7)
2043 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2046 case BFD_RELOC_16_PCREL_S2:
2056 /* Don't generate a reloc if we are writing into a variant frag. */
2059 reloc_howto_type *howto;
2062 /* In a compound relocation, it is the final (outermost)
2063 operator that determines the relocated field. */
2064 for (i = 1; i < 3; i++)
2065 if (reloc_type[i] == BFD_RELOC_UNUSED)
2068 howto = bfd_reloc_type_lookup (stdoutput, reloc_type[i - 1]);
2069 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal,
2070 bfd_get_reloc_size(howto),
2072 reloc_type[0] == BFD_RELOC_16_PCREL_S2,
2075 /* These relocations can have an addend that won't fit in
2076 4 octets for 64bit assembly. */
2078 && ! howto->partial_inplace
2079 && (reloc_type[0] == BFD_RELOC_16
2080 || reloc_type[0] == BFD_RELOC_32
2081 || reloc_type[0] == BFD_RELOC_MIPS_JMP
2082 || reloc_type[0] == BFD_RELOC_HI16_S
2083 || reloc_type[0] == BFD_RELOC_LO16
2084 || reloc_type[0] == BFD_RELOC_GPREL16
2085 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
2086 || reloc_type[0] == BFD_RELOC_GPREL32
2087 || reloc_type[0] == BFD_RELOC_64
2088 || reloc_type[0] == BFD_RELOC_CTOR
2089 || reloc_type[0] == BFD_RELOC_MIPS_SUB
2090 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
2091 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
2092 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
2093 || reloc_type[0] == BFD_RELOC_MIPS_REL16
2094 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT))
2095 fixp[0]->fx_no_overflow = 1;
2097 if (reloc_needs_lo_p (*reloc_type))
2099 struct mips_hi_fixup *hi_fixup;
2101 /* Reuse the last entry if it already has a matching %lo. */
2102 hi_fixup = mips_hi_fixup_list;
2104 || !fixup_has_matching_lo_p (hi_fixup->fixp))
2106 hi_fixup = ((struct mips_hi_fixup *)
2107 xmalloc (sizeof (struct mips_hi_fixup)));
2108 hi_fixup->next = mips_hi_fixup_list;
2109 mips_hi_fixup_list = hi_fixup;
2111 hi_fixup->fixp = fixp[0];
2112 hi_fixup->seg = now_seg;
2115 /* Add fixups for the second and third relocations, if given.
2116 Note that the ABI allows the second relocation to be
2117 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
2118 moment we only use RSS_UNDEF, but we could add support
2119 for the others if it ever becomes necessary. */
2120 for (i = 1; i < 3; i++)
2121 if (reloc_type[i] != BFD_RELOC_UNUSED)
2123 address_expr->X_op = O_absent;
2124 address_expr->X_add_symbol = 0;
2125 address_expr->X_add_number = 0;
2127 fixp[i] = fix_new_exp (frag_now, fixp[0]->fx_where,
2128 fixp[0]->fx_size, address_expr,
2129 FALSE, reloc_type[i]);
2135 if (! mips_opts.mips16)
2137 md_number_to_chars (f, ip->insn_opcode, 4);
2139 dwarf2_emit_insn (4);
2142 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2144 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2145 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2147 dwarf2_emit_insn (4);
2154 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2157 md_number_to_chars (f, ip->insn_opcode, 2);
2159 dwarf2_emit_insn (ip->use_extend ? 4 : 2);
2163 /* Update the register mask information. */
2164 if (! mips_opts.mips16)
2166 if (pinfo & INSN_WRITE_GPR_D)
2167 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2168 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2169 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2170 if (pinfo & INSN_READ_GPR_S)
2171 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2172 if (pinfo & INSN_WRITE_GPR_31)
2173 mips_gprmask |= 1 << RA;
2174 if (pinfo & INSN_WRITE_FPR_D)
2175 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2176 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2177 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2178 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2179 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2180 if ((pinfo & INSN_READ_FPR_R) != 0)
2181 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2182 if (pinfo & INSN_COP)
2184 /* We don't keep enough information to sort these cases out.
2185 The itbl support does keep this information however, although
2186 we currently don't support itbl fprmats as part of the cop
2187 instruction. May want to add this support in the future. */
2189 /* Never set the bit for $0, which is always zero. */
2190 mips_gprmask &= ~1 << 0;
2194 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2195 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2196 & MIPS16OP_MASK_RX);
2197 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2198 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2199 & MIPS16OP_MASK_RY);
2200 if (pinfo & MIPS16_INSN_WRITE_Z)
2201 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2202 & MIPS16OP_MASK_RZ);
2203 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2204 mips_gprmask |= 1 << TREG;
2205 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2206 mips_gprmask |= 1 << SP;
2207 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2208 mips_gprmask |= 1 << RA;
2209 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2210 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2211 if (pinfo & MIPS16_INSN_READ_Z)
2212 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2213 & MIPS16OP_MASK_MOVE32Z);
2214 if (pinfo & MIPS16_INSN_READ_GPR_X)
2215 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2216 & MIPS16OP_MASK_REGR32);
2219 if (place == NULL && ! mips_opts.noreorder)
2221 /* Filling the branch delay slot is more complex. We try to
2222 switch the branch with the previous instruction, which we can
2223 do if the previous instruction does not set up a condition
2224 that the branch tests and if the branch is not itself the
2225 target of any branch. */
2226 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2227 || (pinfo & INSN_COND_BRANCH_DELAY))
2229 if (mips_optimize < 2
2230 /* If we have seen .set volatile or .set nomove, don't
2232 || mips_opts.nomove != 0
2233 /* If we had to emit any NOP instructions, then we
2234 already know we can not swap. */
2236 /* If we don't even know the previous insn, we can not
2238 || ! prev_insn_valid
2239 /* If the previous insn is already in a branch delay
2240 slot, then we can not swap. */
2241 || prev_insn_is_delay_slot
2242 /* If the previous previous insn was in a .set
2243 noreorder, we can't swap. Actually, the MIPS
2244 assembler will swap in this situation. However, gcc
2245 configured -with-gnu-as will generate code like
2251 in which we can not swap the bne and INSN. If gcc is
2252 not configured -with-gnu-as, it does not output the
2253 .set pseudo-ops. We don't have to check
2254 prev_insn_unreordered, because prev_insn_valid will
2255 be 0 in that case. We don't want to use
2256 prev_prev_insn_valid, because we do want to be able
2257 to swap at the start of a function. */
2258 || prev_prev_insn_unreordered
2259 /* If the branch is itself the target of a branch, we
2260 can not swap. We cheat on this; all we check for is
2261 whether there is a label on this instruction. If
2262 there are any branches to anything other than a
2263 label, users must use .set noreorder. */
2264 || insn_labels != NULL
2265 /* If the previous instruction is in a variant frag, we
2266 can not do the swap. This does not apply to the
2267 mips16, which uses variant frags for different
2269 || (! mips_opts.mips16
2270 && prev_insn_frag->fr_type == rs_machine_dependent)
2271 /* If the branch reads the condition codes, we don't
2272 even try to swap, because in the sequence
2277 we can not swap, and I don't feel like handling that
2279 || (! mips_opts.mips16
2280 && (pinfo & INSN_READ_COND_CODE)
2281 && ! cop_interlocks)
2282 /* We can not swap with an instruction that requires a
2283 delay slot, because the target of the branch might
2284 interfere with that instruction. */
2285 || (! mips_opts.mips16
2287 /* Itbl support may require additional care here. */
2288 & (INSN_LOAD_COPROC_DELAY
2289 | INSN_COPROC_MOVE_DELAY
2290 | INSN_WRITE_COND_CODE))
2291 && ! cop_interlocks)
2292 || (! (hilo_interlocks
2293 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2297 || (! mips_opts.mips16
2298 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)
2299 && ! gpr_interlocks)
2300 || (! mips_opts.mips16
2301 /* Itbl support may require additional care here. */
2302 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)
2303 && ! cop_mem_interlocks)
2304 /* We can not swap with a branch instruction. */
2306 & (INSN_UNCOND_BRANCH_DELAY
2307 | INSN_COND_BRANCH_DELAY
2308 | INSN_COND_BRANCH_LIKELY))
2309 /* We do not swap with a trap instruction, since it
2310 complicates trap handlers to have the trap
2311 instruction be in a delay slot. */
2312 || (prev_pinfo & INSN_TRAP)
2313 /* If the branch reads a register that the previous
2314 instruction sets, we can not swap. */
2315 || (! mips_opts.mips16
2316 && (prev_pinfo & INSN_WRITE_GPR_T)
2317 && insn_uses_reg (ip,
2318 ((prev_insn.insn_opcode >> OP_SH_RT)
2321 || (! mips_opts.mips16
2322 && (prev_pinfo & INSN_WRITE_GPR_D)
2323 && insn_uses_reg (ip,
2324 ((prev_insn.insn_opcode >> OP_SH_RD)
2327 || (mips_opts.mips16
2328 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2329 && insn_uses_reg (ip,
2330 ((prev_insn.insn_opcode
2332 & MIPS16OP_MASK_RX),
2334 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2335 && insn_uses_reg (ip,
2336 ((prev_insn.insn_opcode
2338 & MIPS16OP_MASK_RY),
2340 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2341 && insn_uses_reg (ip,
2342 ((prev_insn.insn_opcode
2344 & MIPS16OP_MASK_RZ),
2346 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2347 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2348 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2349 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2350 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2351 && insn_uses_reg (ip,
2352 MIPS16OP_EXTRACT_REG32R (prev_insn.
2355 /* If the branch writes a register that the previous
2356 instruction sets, we can not swap (we know that
2357 branches write only to RD or to $31). */
2358 || (! mips_opts.mips16
2359 && (prev_pinfo & INSN_WRITE_GPR_T)
2360 && (((pinfo & INSN_WRITE_GPR_D)
2361 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2362 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2363 || ((pinfo & INSN_WRITE_GPR_31)
2364 && (((prev_insn.insn_opcode >> OP_SH_RT)
2367 || (! mips_opts.mips16
2368 && (prev_pinfo & INSN_WRITE_GPR_D)
2369 && (((pinfo & INSN_WRITE_GPR_D)
2370 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2371 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2372 || ((pinfo & INSN_WRITE_GPR_31)
2373 && (((prev_insn.insn_opcode >> OP_SH_RD)
2376 || (mips_opts.mips16
2377 && (pinfo & MIPS16_INSN_WRITE_31)
2378 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2379 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2380 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2382 /* If the branch writes a register that the previous
2383 instruction reads, we can not swap (we know that
2384 branches only write to RD or to $31). */
2385 || (! mips_opts.mips16
2386 && (pinfo & INSN_WRITE_GPR_D)
2387 && insn_uses_reg (&prev_insn,
2388 ((ip->insn_opcode >> OP_SH_RD)
2391 || (! mips_opts.mips16
2392 && (pinfo & INSN_WRITE_GPR_31)
2393 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2394 || (mips_opts.mips16
2395 && (pinfo & MIPS16_INSN_WRITE_31)
2396 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2397 /* If we are generating embedded PIC code, the branch
2398 might be expanded into a sequence which uses $at, so
2399 we can't swap with an instruction which reads it. */
2400 || (mips_pic == EMBEDDED_PIC
2401 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2402 /* If the previous previous instruction has a load
2403 delay, and sets a register that the branch reads, we
2405 || (! mips_opts.mips16
2406 /* Itbl support may require additional care here. */
2407 && (((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2408 && ! cop_interlocks)
2409 || ((prev_prev_insn.insn_mo->pinfo
2410 & INSN_LOAD_MEMORY_DELAY)
2411 && ! gpr_interlocks))
2412 && insn_uses_reg (ip,
2413 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2416 /* If one instruction sets a condition code and the
2417 other one uses a condition code, we can not swap. */
2418 || ((pinfo & INSN_READ_COND_CODE)
2419 && (prev_pinfo & INSN_WRITE_COND_CODE))
2420 || ((pinfo & INSN_WRITE_COND_CODE)
2421 && (prev_pinfo & INSN_READ_COND_CODE))
2422 /* If the previous instruction uses the PC, we can not
2424 || (mips_opts.mips16
2425 && (prev_pinfo & MIPS16_INSN_READ_PC))
2426 /* If the previous instruction was extended, we can not
2428 || (mips_opts.mips16 && prev_insn_extended)
2429 /* If the previous instruction had a fixup in mips16
2430 mode, we can not swap. This normally means that the
2431 previous instruction was a 4 byte branch anyhow. */
2432 || (mips_opts.mips16 && prev_insn_fixp[0])
2433 /* If the previous instruction is a sync, sync.l, or
2434 sync.p, we can not swap. */
2435 || (prev_pinfo & INSN_SYNC))
2437 /* We could do even better for unconditional branches to
2438 portions of this object file; we could pick up the
2439 instruction at the destination, put it in the delay
2440 slot, and bump the destination address. */
2442 /* Update the previous insn information. */
2443 prev_prev_insn = *ip;
2444 prev_insn.insn_mo = &dummy_opcode;
2448 /* It looks like we can actually do the swap. */
2449 if (! mips_opts.mips16)
2454 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2455 memcpy (temp, prev_f, 4);
2456 memcpy (prev_f, f, 4);
2457 memcpy (f, temp, 4);
2458 if (prev_insn_fixp[0])
2460 prev_insn_fixp[0]->fx_frag = frag_now;
2461 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2463 if (prev_insn_fixp[1])
2465 prev_insn_fixp[1]->fx_frag = frag_now;
2466 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2468 if (prev_insn_fixp[2])
2470 prev_insn_fixp[2]->fx_frag = frag_now;
2471 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2473 if (prev_insn_fixp[0] && HAVE_NEWABI
2474 && prev_insn_frag != frag_now
2475 && (prev_insn_fixp[0]->fx_r_type
2476 == BFD_RELOC_MIPS_GOT_DISP
2477 || (prev_insn_fixp[0]->fx_r_type
2478 == BFD_RELOC_MIPS_CALL16)))
2480 /* To avoid confusion in tc_gen_reloc, we must
2481 ensure that this does not become a variant
2483 force_new_frag = TRUE;
2487 fixp[0]->fx_frag = prev_insn_frag;
2488 fixp[0]->fx_where = prev_insn_where;
2492 fixp[1]->fx_frag = prev_insn_frag;
2493 fixp[1]->fx_where = prev_insn_where;
2497 fixp[2]->fx_frag = prev_insn_frag;
2498 fixp[2]->fx_where = prev_insn_where;
2506 assert (prev_insn_fixp[0] == NULL);
2507 assert (prev_insn_fixp[1] == NULL);
2508 assert (prev_insn_fixp[2] == NULL);
2509 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2510 memcpy (temp, prev_f, 2);
2511 memcpy (prev_f, f, 2);
2512 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2514 assert (*reloc_type == BFD_RELOC_UNUSED);
2515 memcpy (f, temp, 2);
2519 memcpy (f, f + 2, 2);
2520 memcpy (f + 2, temp, 2);
2524 fixp[0]->fx_frag = prev_insn_frag;
2525 fixp[0]->fx_where = prev_insn_where;
2529 fixp[1]->fx_frag = prev_insn_frag;
2530 fixp[1]->fx_where = prev_insn_where;
2534 fixp[2]->fx_frag = prev_insn_frag;
2535 fixp[2]->fx_where = prev_insn_where;
2539 /* Update the previous insn information; leave prev_insn
2541 prev_prev_insn = *ip;
2543 prev_insn_is_delay_slot = 1;
2545 /* If that was an unconditional branch, forget the previous
2546 insn information. */
2547 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2549 prev_prev_insn.insn_mo = &dummy_opcode;
2550 prev_insn.insn_mo = &dummy_opcode;
2553 prev_insn_fixp[0] = NULL;
2554 prev_insn_fixp[1] = NULL;
2555 prev_insn_fixp[2] = NULL;
2556 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2557 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2558 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2559 prev_insn_extended = 0;
2561 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2563 /* We don't yet optimize a branch likely. What we should do
2564 is look at the target, copy the instruction found there
2565 into the delay slot, and increment the branch to jump to
2566 the next instruction. */
2568 /* Update the previous insn information. */
2569 prev_prev_insn = *ip;
2570 prev_insn.insn_mo = &dummy_opcode;
2571 prev_insn_fixp[0] = NULL;
2572 prev_insn_fixp[1] = NULL;
2573 prev_insn_fixp[2] = NULL;
2574 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2575 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2576 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2577 prev_insn_extended = 0;
2581 /* Update the previous insn information. */
2583 prev_prev_insn.insn_mo = &dummy_opcode;
2585 prev_prev_insn = prev_insn;
2588 /* Any time we see a branch, we always fill the delay slot
2589 immediately; since this insn is not a branch, we know it
2590 is not in a delay slot. */
2591 prev_insn_is_delay_slot = 0;
2593 prev_insn_fixp[0] = fixp[0];
2594 prev_insn_fixp[1] = fixp[1];
2595 prev_insn_fixp[2] = fixp[2];
2596 prev_insn_reloc_type[0] = reloc_type[0];
2597 prev_insn_reloc_type[1] = reloc_type[1];
2598 prev_insn_reloc_type[2] = reloc_type[2];
2599 if (mips_opts.mips16)
2600 prev_insn_extended = (ip->use_extend
2601 || *reloc_type > BFD_RELOC_UNUSED);
2604 prev_prev_insn_unreordered = prev_insn_unreordered;
2605 prev_insn_unreordered = 0;
2606 prev_insn_frag = frag_now;
2607 prev_insn_where = f - frag_now->fr_literal;
2608 prev_insn_valid = 1;
2610 else if (place == NULL)
2612 /* We need to record a bit of information even when we are not
2613 reordering, in order to determine the base address for mips16
2614 PC relative relocs. */
2615 prev_prev_insn = prev_insn;
2617 prev_insn_reloc_type[0] = reloc_type[0];
2618 prev_insn_reloc_type[1] = reloc_type[1];
2619 prev_insn_reloc_type[2] = reloc_type[2];
2620 prev_prev_insn_unreordered = prev_insn_unreordered;
2621 prev_insn_unreordered = 1;
2624 /* We just output an insn, so the next one doesn't have a label. */
2625 mips_clear_insn_labels ();
2627 /* We must ensure that the frag to which an instruction that was
2628 moved from a non-variant frag doesn't become a variant frag,
2629 otherwise tc_gen_reloc may get confused. */
2632 frag_wane (frag_now);
2637 /* This function forgets that there was any previous instruction or
2638 label. If PRESERVE is non-zero, it remembers enough information to
2639 know whether nops are needed before a noreorder section. */
2642 mips_no_prev_insn (int preserve)
2646 prev_insn.insn_mo = &dummy_opcode;
2647 prev_prev_insn.insn_mo = &dummy_opcode;
2648 prev_nop_frag = NULL;
2649 prev_nop_frag_holds = 0;
2650 prev_nop_frag_required = 0;
2651 prev_nop_frag_since = 0;
2653 prev_insn_valid = 0;
2654 prev_insn_is_delay_slot = 0;
2655 prev_insn_unreordered = 0;
2656 prev_insn_extended = 0;
2657 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2658 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2659 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2660 prev_prev_insn_unreordered = 0;
2661 mips_clear_insn_labels ();
2664 /* This function must be called whenever we turn on noreorder or emit
2665 something other than instructions. It inserts any NOPS which might
2666 be needed by the previous instruction, and clears the information
2667 kept for the previous instructions. The INSNS parameter is true if
2668 instructions are to follow. */
2671 mips_emit_delays (bfd_boolean insns)
2673 if (! mips_opts.noreorder)
2678 if ((! mips_opts.mips16
2679 && ((prev_insn.insn_mo->pinfo
2680 & (INSN_LOAD_COPROC_DELAY
2681 | INSN_COPROC_MOVE_DELAY
2682 | INSN_WRITE_COND_CODE))
2683 && ! cop_interlocks))
2684 || (! hilo_interlocks
2685 && (prev_insn.insn_mo->pinfo
2688 || (! mips_opts.mips16
2689 && (prev_insn.insn_mo->pinfo & INSN_LOAD_MEMORY_DELAY)
2690 && ! gpr_interlocks)
2691 || (! mips_opts.mips16
2692 && (prev_insn.insn_mo->pinfo & INSN_COPROC_MEMORY_DELAY)
2693 && ! cop_mem_interlocks))
2695 /* Itbl support may require additional care here. */
2697 if ((! mips_opts.mips16
2698 && ((prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
2699 && ! cop_interlocks))
2700 || (! hilo_interlocks
2701 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2702 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2705 if (prev_insn_unreordered)
2708 else if ((! mips_opts.mips16
2709 && ((prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
2710 && ! cop_interlocks))
2711 || (! hilo_interlocks
2712 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2713 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2715 /* Itbl support may require additional care here. */
2716 if (! prev_prev_insn_unreordered)
2720 if (mips_fix_4122_bugs && prev_insn.insn_mo->name)
2723 const char *pn = prev_insn.insn_mo->name;
2724 if (strncmp(pn, "macc", 4) == 0
2725 || strncmp(pn, "dmacc", 5) == 0
2726 || strncmp(pn, "dmult", 5) == 0)
2730 if (nops < min_nops)
2736 struct insn_label_list *l;
2740 /* Record the frag which holds the nop instructions, so
2741 that we can remove them if we don't need them. */
2742 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2743 prev_nop_frag = frag_now;
2744 prev_nop_frag_holds = nops;
2745 prev_nop_frag_required = 0;
2746 prev_nop_frag_since = 0;
2749 for (; nops > 0; --nops)
2754 /* Move on to a new frag, so that it is safe to simply
2755 decrease the size of prev_nop_frag. */
2756 frag_wane (frag_now);
2760 for (l = insn_labels; l != NULL; l = l->next)
2764 assert (S_GET_SEGMENT (l->label) == now_seg);
2765 symbol_set_frag (l->label, frag_now);
2766 val = (valueT) frag_now_fix ();
2767 /* mips16 text labels are stored as odd. */
2768 if (mips_opts.mips16)
2770 S_SET_VALUE (l->label, val);
2775 /* Mark instruction labels in mips16 mode. */
2777 mips16_mark_labels ();
2779 mips_no_prev_insn (insns);
2782 /* Build an instruction created by a macro expansion. This is passed
2783 a pointer to the count of instructions created so far, an
2784 expression, the name of the instruction to build, an operand format
2785 string, and corresponding arguments. */
2788 macro_build (char *place, int *counter, expressionS *ep, const char *name,
2789 const char *fmt, ...)
2791 struct mips_cl_insn insn;
2792 bfd_reloc_code_real_type r[3];
2795 va_start (args, fmt);
2798 * If the macro is about to expand into a second instruction,
2799 * print a warning if needed. We need to pass ip as a parameter
2800 * to generate a better warning message here...
2802 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2803 as_warn (_("Macro instruction expanded into multiple instructions"));
2806 * If the macro is about to expand into a second instruction,
2807 * and it is in a delay slot, print a warning.
2811 && mips_opts.noreorder
2812 && (prev_prev_insn.insn_mo->pinfo
2813 & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY
2814 | INSN_COND_BRANCH_LIKELY)) != 0)
2815 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2818 ++*counter; /* bump instruction counter */
2820 if (mips_opts.mips16)
2822 mips16_macro_build (place, counter, ep, name, fmt, args);
2827 r[0] = BFD_RELOC_UNUSED;
2828 r[1] = BFD_RELOC_UNUSED;
2829 r[2] = BFD_RELOC_UNUSED;
2830 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2831 assert (insn.insn_mo);
2832 assert (strcmp (name, insn.insn_mo->name) == 0);
2834 /* Search until we get a match for NAME. */
2837 /* It is assumed here that macros will never generate
2838 MDMX or MIPS-3D instructions. */
2839 if (strcmp (fmt, insn.insn_mo->args) == 0
2840 && insn.insn_mo->pinfo != INSN_MACRO
2841 && OPCODE_IS_MEMBER (insn.insn_mo,
2843 | (file_ase_mips16 ? INSN_MIPS16 : 0)),
2845 && (mips_opts.arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2849 assert (insn.insn_mo->name);
2850 assert (strcmp (name, insn.insn_mo->name) == 0);
2853 insn.insn_opcode = insn.insn_mo->match;
2871 insn.insn_opcode |= (va_arg (args, int)
2872 & OP_MASK_SHAMT) << OP_SH_SHAMT;
2877 /* Note that in the macro case, these arguments are already
2878 in MSB form. (When handling the instruction in the
2879 non-macro case, these arguments are sizes from which
2880 MSB values must be calculated.) */
2881 insn.insn_opcode |= (va_arg (args, int)
2882 & OP_MASK_INSMSB) << OP_SH_INSMSB;
2888 /* Note that in the macro case, these arguments are already
2889 in MSBD form. (When handling the instruction in the
2890 non-macro case, these arguments are sizes from which
2891 MSBD values must be calculated.) */
2892 insn.insn_opcode |= (va_arg (args, int)
2893 & OP_MASK_EXTMSBD) << OP_SH_EXTMSBD;
2904 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2908 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2913 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2919 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2924 int tmp = va_arg (args, int);
2926 insn.insn_opcode |= tmp << OP_SH_RT;
2927 insn.insn_opcode |= tmp << OP_SH_RD;
2933 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2940 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2944 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2948 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2952 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2956 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2963 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2969 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2970 assert (*r == BFD_RELOC_GPREL16
2971 || *r == BFD_RELOC_MIPS_LITERAL
2972 || *r == BFD_RELOC_MIPS_HIGHER
2973 || *r == BFD_RELOC_HI16_S
2974 || *r == BFD_RELOC_LO16
2975 || *r == BFD_RELOC_MIPS_GOT16
2976 || *r == BFD_RELOC_MIPS_CALL16
2977 || *r == BFD_RELOC_MIPS_GOT_DISP
2978 || *r == BFD_RELOC_MIPS_GOT_PAGE
2979 || *r == BFD_RELOC_MIPS_GOT_OFST
2980 || *r == BFD_RELOC_MIPS_GOT_LO16
2981 || *r == BFD_RELOC_MIPS_CALL_LO16
2982 || (ep->X_op == O_subtract
2983 && *r == BFD_RELOC_PCREL_LO16));
2987 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2989 && (ep->X_op == O_constant
2990 || (ep->X_op == O_symbol
2991 && (*r == BFD_RELOC_MIPS_HIGHEST
2992 || *r == BFD_RELOC_HI16_S
2993 || *r == BFD_RELOC_HI16
2994 || *r == BFD_RELOC_GPREL16
2995 || *r == BFD_RELOC_MIPS_GOT_HI16
2996 || *r == BFD_RELOC_MIPS_CALL_HI16))
2997 || (ep->X_op == O_subtract
2998 && *r == BFD_RELOC_PCREL_HI16_S)));
3002 assert (ep != NULL);
3004 * This allows macro() to pass an immediate expression for
3005 * creating short branches without creating a symbol.
3006 * Note that the expression still might come from the assembly
3007 * input, in which case the value is not checked for range nor
3008 * is a relocation entry generated (yuck).
3010 if (ep->X_op == O_constant)
3012 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
3016 *r = BFD_RELOC_16_PCREL_S2;
3020 assert (ep != NULL);
3021 *r = BFD_RELOC_MIPS_JMP;
3025 insn.insn_opcode |= va_arg (args, unsigned long);
3034 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3036 append_insn (place, &insn, ep, r);
3040 mips16_macro_build (char *place, int *counter ATTRIBUTE_UNUSED,
3041 expressionS *ep, const char *name, const char *fmt,
3044 struct mips_cl_insn insn;
3045 bfd_reloc_code_real_type r[3]
3046 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3048 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3049 assert (insn.insn_mo);
3050 assert (strcmp (name, insn.insn_mo->name) == 0);
3052 while (strcmp (fmt, insn.insn_mo->args) != 0
3053 || insn.insn_mo->pinfo == INSN_MACRO)
3056 assert (insn.insn_mo->name);
3057 assert (strcmp (name, insn.insn_mo->name) == 0);
3060 insn.insn_opcode = insn.insn_mo->match;
3061 insn.use_extend = FALSE;
3080 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
3085 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
3089 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
3093 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
3103 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
3110 regno = va_arg (args, int);
3111 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3112 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3133 assert (ep != NULL);
3135 if (ep->X_op != O_constant)
3136 *r = (int) BFD_RELOC_UNUSED + c;
3139 mips16_immed (NULL, 0, c, ep->X_add_number, FALSE, FALSE,
3140 FALSE, &insn.insn_opcode, &insn.use_extend,
3143 *r = BFD_RELOC_UNUSED;
3149 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3156 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3158 append_insn (place, &insn, ep, r);
3162 * Generate a "jalr" instruction with a relocation hint to the called
3163 * function. This occurs in NewABI PIC code.
3166 macro_build_jalr (int icnt, expressionS *ep)
3175 macro_build (NULL, &icnt, NULL, "jalr", "d,s", RA, PIC_CALL_REG);
3177 fix_new_exp (frag_now, f - frag_now->fr_literal,
3178 4, ep, FALSE, BFD_RELOC_MIPS_JALR);
3182 * Generate a "lui" instruction.
3185 macro_build_lui (char *place, int *counter, expressionS *ep, int regnum)
3187 expressionS high_expr;
3188 struct mips_cl_insn insn;
3189 bfd_reloc_code_real_type r[3]
3190 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3191 const char *name = "lui";
3192 const char *fmt = "t,u";
3194 assert (! mips_opts.mips16);
3200 high_expr.X_op = O_constant;
3201 high_expr.X_add_number = ep->X_add_number;
3204 if (high_expr.X_op == O_constant)
3206 /* we can compute the instruction now without a relocation entry */
3207 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3209 *r = BFD_RELOC_UNUSED;
3213 assert (ep->X_op == O_symbol);
3214 /* _gp_disp is a special case, used from s_cpload. */
3215 assert (mips_pic == NO_PIC
3217 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0));
3218 *r = BFD_RELOC_HI16_S;
3222 * If the macro is about to expand into a second instruction,
3223 * print a warning if needed. We need to pass ip as a parameter
3224 * to generate a better warning message here...
3226 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3227 as_warn (_("Macro instruction expanded into multiple instructions"));
3230 ++*counter; /* bump instruction counter */
3232 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3233 assert (insn.insn_mo);
3234 assert (strcmp (name, insn.insn_mo->name) == 0);
3235 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3237 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3238 if (*r == BFD_RELOC_UNUSED)
3240 insn.insn_opcode |= high_expr.X_add_number;
3241 append_insn (place, &insn, NULL, r);
3244 append_insn (place, &insn, &high_expr, r);
3247 /* Generate a sequence of instructions to do a load or store from a constant
3248 offset off of a base register (breg) into/from a target register (treg),
3249 using AT if necessary. */
3251 macro_build_ldst_constoffset (char *place, int *counter, expressionS *ep,
3252 const char *op, int treg, int breg, int dbl)
3254 assert (ep->X_op == O_constant);
3256 /* Sign-extending 32-bit constants makes their handling easier. */
3257 if (! dbl && ! ((ep->X_add_number & ~((bfd_vma) 0x7fffffff))
3258 == ~((bfd_vma) 0x7fffffff)))
3260 if (ep->X_add_number & ~((bfd_vma) 0xffffffff))
3261 as_bad (_("constant too large"));
3263 ep->X_add_number = (((ep->X_add_number & 0xffffffff) ^ 0x80000000)
3267 /* Right now, this routine can only handle signed 32-bit constants. */
3268 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
3269 as_warn (_("operand overflow"));
3271 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
3273 /* Signed 16-bit offset will fit in the op. Easy! */
3274 macro_build (place, counter, ep, op, "t,o(b)", treg, BFD_RELOC_LO16,
3279 /* 32-bit offset, need multiple instructions and AT, like:
3280 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3281 addu $tempreg,$tempreg,$breg
3282 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3283 to handle the complete offset. */
3284 macro_build_lui (place, counter, ep, AT);
3287 macro_build (place, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT,
3291 macro_build (place, counter, ep, op, "t,o(b)", treg, BFD_RELOC_LO16,
3295 as_warn (_("Macro used $at after \".set noat\""));
3300 * Generates code to set the $at register to true (one)
3301 * if reg is less than the immediate expression.
3304 set_at (int *counter, int reg, int unsignedp)
3306 if (imm_expr.X_op == O_constant
3307 && imm_expr.X_add_number >= -0x8000
3308 && imm_expr.X_add_number < 0x8000)
3309 macro_build (NULL, counter, &imm_expr, unsignedp ? "sltiu" : "slti",
3310 "t,r,j", AT, reg, BFD_RELOC_LO16);
3313 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3314 macro_build (NULL, counter, NULL, unsignedp ? "sltu" : "slt",
3315 "d,v,t", AT, reg, AT);
3320 normalize_constant_expr (expressionS *ex)
3322 if (ex->X_op == O_constant && HAVE_32BIT_GPRS)
3323 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
3327 /* Warn if an expression is not a constant. */
3330 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
3332 if (ex->X_op == O_big)
3333 as_bad (_("unsupported large constant"));
3334 else if (ex->X_op != O_constant)
3335 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3337 normalize_constant_expr (ex);
3340 /* Count the leading zeroes by performing a binary chop. This is a
3341 bulky bit of source, but performance is a LOT better for the
3342 majority of values than a simple loop to count the bits:
3343 for (lcnt = 0; (lcnt < 32); lcnt++)
3344 if ((v) & (1 << (31 - lcnt)))
3346 However it is not code size friendly, and the gain will drop a bit
3347 on certain cached systems.
3349 #define COUNT_TOP_ZEROES(v) \
3350 (((v) & ~0xffff) == 0 \
3351 ? ((v) & ~0xff) == 0 \
3352 ? ((v) & ~0xf) == 0 \
3353 ? ((v) & ~0x3) == 0 \
3354 ? ((v) & ~0x1) == 0 \
3359 : ((v) & ~0x7) == 0 \
3362 : ((v) & ~0x3f) == 0 \
3363 ? ((v) & ~0x1f) == 0 \
3366 : ((v) & ~0x7f) == 0 \
3369 : ((v) & ~0xfff) == 0 \
3370 ? ((v) & ~0x3ff) == 0 \
3371 ? ((v) & ~0x1ff) == 0 \
3374 : ((v) & ~0x7ff) == 0 \
3377 : ((v) & ~0x3fff) == 0 \
3378 ? ((v) & ~0x1fff) == 0 \
3381 : ((v) & ~0x7fff) == 0 \
3384 : ((v) & ~0xffffff) == 0 \
3385 ? ((v) & ~0xfffff) == 0 \
3386 ? ((v) & ~0x3ffff) == 0 \
3387 ? ((v) & ~0x1ffff) == 0 \
3390 : ((v) & ~0x7ffff) == 0 \
3393 : ((v) & ~0x3fffff) == 0 \
3394 ? ((v) & ~0x1fffff) == 0 \
3397 : ((v) & ~0x7fffff) == 0 \
3400 : ((v) & ~0xfffffff) == 0 \
3401 ? ((v) & ~0x3ffffff) == 0 \
3402 ? ((v) & ~0x1ffffff) == 0 \
3405 : ((v) & ~0x7ffffff) == 0 \
3408 : ((v) & ~0x3fffffff) == 0 \
3409 ? ((v) & ~0x1fffffff) == 0 \
3412 : ((v) & ~0x7fffffff) == 0 \
3417 * This routine generates the least number of instructions necessary to load
3418 * an absolute expression value into a register.
3421 load_register (int *counter, int reg, expressionS *ep, int dbl)
3424 expressionS hi32, lo32;
3426 if (ep->X_op != O_big)
3428 assert (ep->X_op == O_constant);
3430 /* Sign-extending 32-bit constants makes their handling easier. */
3431 if (! dbl && ! ((ep->X_add_number & ~((bfd_vma) 0x7fffffff))
3432 == ~((bfd_vma) 0x7fffffff)))
3434 if (ep->X_add_number & ~((bfd_vma) 0xffffffff))
3435 as_bad (_("constant too large"));
3437 ep->X_add_number = (((ep->X_add_number & 0xffffffff) ^ 0x80000000)
3441 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
3443 /* We can handle 16 bit signed values with an addiu to
3444 $zero. No need to ever use daddiu here, since $zero and
3445 the result are always correct in 32 bit mode. */
3446 macro_build (NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3450 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3452 /* We can handle 16 bit unsigned values with an ori to
3454 macro_build (NULL, counter, ep, "ori", "t,r,i", reg, 0,
3458 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
3460 /* 32 bit values require an lui. */
3461 macro_build (NULL, counter, ep, "lui", "t,u", reg, BFD_RELOC_HI16);
3462 if ((ep->X_add_number & 0xffff) != 0)
3463 macro_build (NULL, counter, ep, "ori", "t,r,i", reg, reg,
3469 /* The value is larger than 32 bits. */
3471 if (HAVE_32BIT_GPRS)
3473 as_bad (_("Number (0x%lx) larger than 32 bits"),
3474 (unsigned long) ep->X_add_number);
3475 macro_build (NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3480 if (ep->X_op != O_big)
3483 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3484 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3485 hi32.X_add_number &= 0xffffffff;
3487 lo32.X_add_number &= 0xffffffff;
3491 assert (ep->X_add_number > 2);
3492 if (ep->X_add_number == 3)
3493 generic_bignum[3] = 0;
3494 else if (ep->X_add_number > 4)
3495 as_bad (_("Number larger than 64 bits"));
3496 lo32.X_op = O_constant;
3497 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3498 hi32.X_op = O_constant;
3499 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3502 if (hi32.X_add_number == 0)
3507 unsigned long hi, lo;
3509 if (hi32.X_add_number == (offsetT) 0xffffffff)
3511 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3513 macro_build (NULL, counter, &lo32, "addiu", "t,r,j", reg, 0,
3517 if (lo32.X_add_number & 0x80000000)
3519 macro_build (NULL, counter, &lo32, "lui", "t,u", reg,
3521 if (lo32.X_add_number & 0xffff)
3522 macro_build (NULL, counter, &lo32, "ori", "t,r,i", reg, reg,
3528 /* Check for 16bit shifted constant. We know that hi32 is
3529 non-zero, so start the mask on the first bit of the hi32
3534 unsigned long himask, lomask;
3538 himask = 0xffff >> (32 - shift);
3539 lomask = (0xffff << shift) & 0xffffffff;
3543 himask = 0xffff << (shift - 32);
3546 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3547 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3551 tmp.X_op = O_constant;
3553 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3554 | (lo32.X_add_number >> shift));
3556 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3557 macro_build (NULL, counter, &tmp, "ori", "t,r,i", reg, 0,
3559 macro_build (NULL, counter, NULL,
3560 (shift >= 32) ? "dsll32" : "dsll",
3562 (shift >= 32) ? shift - 32 : shift);
3567 while (shift <= (64 - 16));
3569 /* Find the bit number of the lowest one bit, and store the
3570 shifted value in hi/lo. */
3571 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3572 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3576 while ((lo & 1) == 0)
3581 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3587 while ((hi & 1) == 0)
3596 /* Optimize if the shifted value is a (power of 2) - 1. */
3597 if ((hi == 0 && ((lo + 1) & lo) == 0)
3598 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3600 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3605 /* This instruction will set the register to be all
3607 tmp.X_op = O_constant;
3608 tmp.X_add_number = (offsetT) -1;
3609 macro_build (NULL, counter, &tmp, "addiu", "t,r,j", reg, 0,
3614 macro_build (NULL, counter, NULL,
3615 (bit >= 32) ? "dsll32" : "dsll",
3617 (bit >= 32) ? bit - 32 : bit);
3619 macro_build (NULL, counter, NULL,
3620 (shift >= 32) ? "dsrl32" : "dsrl",
3622 (shift >= 32) ? shift - 32 : shift);
3627 /* Sign extend hi32 before calling load_register, because we can
3628 generally get better code when we load a sign extended value. */
3629 if ((hi32.X_add_number & 0x80000000) != 0)
3630 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3631 load_register (counter, reg, &hi32, 0);
3634 if ((lo32.X_add_number & 0xffff0000) == 0)
3638 macro_build (NULL, counter, NULL, "dsll32", "d,w,<", reg, freg, 0);
3646 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3648 macro_build (NULL, counter, &lo32, "lui", "t,u", reg,
3650 macro_build (NULL, counter, NULL, "dsrl32", "d,w,<", reg, reg, 0);
3656 macro_build (NULL, counter, NULL, "dsll", "d,w,<", reg, freg, 16);
3660 mid16.X_add_number >>= 16;
3661 macro_build (NULL, counter, &mid16, "ori", "t,r,i", reg, freg,
3663 macro_build (NULL, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3666 if ((lo32.X_add_number & 0xffff) != 0)
3667 macro_build (NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3671 /* Load an address into a register. */
3674 load_address (int *counter, int reg, expressionS *ep, int *used_at)
3678 if (ep->X_op != O_constant
3679 && ep->X_op != O_symbol)
3681 as_bad (_("expression too complex"));
3682 ep->X_op = O_constant;
3685 if (ep->X_op == O_constant)
3687 load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES);
3691 if (mips_pic == NO_PIC)
3693 /* If this is a reference to a GP relative symbol, we want
3694 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3696 lui $reg,<sym> (BFD_RELOC_HI16_S)
3697 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3698 If we have an addend, we always use the latter form.
3700 With 64bit address space and a usable $at we want
3701 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3702 lui $at,<sym> (BFD_RELOC_HI16_S)
3703 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3704 daddiu $at,<sym> (BFD_RELOC_LO16)
3708 If $at is already in use, we use a path which is suboptimal
3709 on superscalar processors.
3710 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3711 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3713 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3715 daddiu $reg,<sym> (BFD_RELOC_LO16)
3717 if (HAVE_64BIT_ADDRESSES)
3719 /* We don't do GP optimization for now because RELAX_ENCODE can't
3720 hold the data for such large chunks. */
3722 if (*used_at == 0 && ! mips_opts.noat)
3724 macro_build (p, counter, ep, "lui", "t,u",
3725 reg, BFD_RELOC_MIPS_HIGHEST);
3726 macro_build (p, counter, ep, "lui", "t,u",
3727 AT, BFD_RELOC_HI16_S);
3728 macro_build (p, counter, ep, "daddiu", "t,r,j",
3729 reg, reg, BFD_RELOC_MIPS_HIGHER);
3730 macro_build (p, counter, ep, "daddiu", "t,r,j",
3731 AT, AT, BFD_RELOC_LO16);
3732 macro_build (p, counter, NULL, "dsll32", "d,w,<", reg, reg, 0);
3733 macro_build (p, counter, NULL, "daddu", "d,v,t", reg, reg, AT);
3738 macro_build (p, counter, ep, "lui", "t,u",
3739 reg, BFD_RELOC_MIPS_HIGHEST);
3740 macro_build (p, counter, ep, "daddiu", "t,r,j",
3741 reg, reg, BFD_RELOC_MIPS_HIGHER);
3742 macro_build (p, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3743 macro_build (p, counter, ep, "daddiu", "t,r,j",
3744 reg, reg, BFD_RELOC_HI16_S);
3745 macro_build (p, counter, NULL, "dsll", "d,w,<", reg, reg, 16);
3746 macro_build (p, counter, ep, "daddiu", "t,r,j",
3747 reg, reg, BFD_RELOC_LO16);
3752 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3753 && ! nopic_need_relax (ep->X_add_symbol, 1))
3756 macro_build (NULL, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3757 mips_gp_register, BFD_RELOC_GPREL16);
3758 p = frag_var (rs_machine_dependent, 8, 0,
3759 RELAX_ENCODE (4, 8, 0, 4, 0,
3760 mips_opts.warn_about_macros),
3761 ep->X_add_symbol, 0, NULL);
3763 macro_build_lui (p, counter, ep, reg);
3766 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3770 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3774 /* If this is a reference to an external symbol, we want
3775 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3777 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3779 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3780 If there is a constant, it must be added in after.
3782 If we have NewABI, we want
3783 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
3784 unless we're referencing a global symbol with a non-zero
3785 offset, in which case cst must be added separately. */
3790 if (ep->X_add_number)
3792 frag_now->tc_frag_data.tc_fr_offset =
3793 ex.X_add_number = ep->X_add_number;
3794 ep->X_add_number = 0;
3795 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)",
3796 reg, BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3797 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3798 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3799 ex.X_op = O_constant;
3800 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3801 reg, reg, BFD_RELOC_LO16);
3802 p = frag_var (rs_machine_dependent, 8, 0,
3803 RELAX_ENCODE (8, 4, 0, 0, 0,
3804 mips_opts.warn_about_macros),
3805 ep->X_add_symbol, 0, NULL);
3806 ep->X_add_number = ex.X_add_number;
3809 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3810 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3814 /* To avoid confusion in tc_gen_reloc, we must ensure
3815 that this does not become a variant frag. */
3816 frag_wane (frag_now);
3822 ex.X_add_number = ep->X_add_number;
3823 ep->X_add_number = 0;
3825 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3826 BFD_RELOC_MIPS_GOT16,
3828 macro_build (NULL, counter, NULL, "nop", "");
3829 p = frag_var (rs_machine_dependent, 4, 0,
3830 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3831 ep->X_add_symbol, 0, NULL);
3832 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3835 if (ex.X_add_number != 0)
3837 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3838 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3839 ex.X_op = O_constant;
3840 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3841 reg, reg, BFD_RELOC_LO16);
3845 else if (mips_pic == SVR4_PIC)
3850 /* This is the large GOT case. If this is a reference to an
3851 external symbol, we want
3852 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3854 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3856 Otherwise, for a reference to a local symbol in old ABI, we want
3857 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3859 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3860 If there is a constant, it must be added in after.
3862 In the NewABI, for local symbols, with or without offsets, we want:
3863 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3864 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3870 frag_now->tc_frag_data.tc_fr_offset =
3871 ex.X_add_number = ep->X_add_number;
3872 ep->X_add_number = 0;
3873 macro_build (NULL, counter, ep, "lui", "t,u", reg,
3874 BFD_RELOC_MIPS_GOT_HI16);
3875 macro_build (NULL, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", reg,
3876 reg, mips_gp_register);
3877 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3878 BFD_RELOC_MIPS_GOT_LO16, reg);
3879 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3880 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3881 else if (ex.X_add_number)
3883 ex.X_op = O_constant;
3884 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3885 reg, reg, BFD_RELOC_LO16);
3888 ep->X_add_number = ex.X_add_number;
3889 p = frag_var (rs_machine_dependent, 8, 0,
3890 RELAX_ENCODE (ex.X_add_number ? 16 : 12, 8, 0, 4, 0,
3891 mips_opts.warn_about_macros),
3892 ep->X_add_symbol, 0, NULL);
3893 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3894 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
3895 macro_build (p + 4, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3896 reg, BFD_RELOC_MIPS_GOT_OFST);
3900 ex.X_add_number = ep->X_add_number;
3901 ep->X_add_number = 0;
3902 if (reg_needs_delay (mips_gp_register))
3907 macro_build (NULL, counter, ep, "lui", "t,u", reg,
3908 BFD_RELOC_MIPS_GOT_HI16);
3909 macro_build (NULL, counter, NULL, ADDRESS_ADD_INSN, "d,v,t", reg,
3910 reg, mips_gp_register);
3911 macro_build (NULL, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3912 BFD_RELOC_MIPS_GOT_LO16, reg);
3913 p = frag_var (rs_machine_dependent, 12 + off, 0,
3914 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3915 mips_opts.warn_about_macros),
3916 ep->X_add_symbol, 0, NULL);
3919 /* We need a nop before loading from $gp. This special
3920 check is required because the lui which starts the main
3921 instruction stream does not refer to $gp, and so will not
3922 insert the nop which may be required. */
3923 macro_build (p, counter, NULL, "nop", "");
3926 macro_build (p, counter, ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3927 BFD_RELOC_MIPS_GOT16, mips_gp_register);
3929 macro_build (p, counter, NULL, "nop", "");
3931 macro_build (p, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3934 if (ex.X_add_number != 0)
3936 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3937 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3938 ex.X_op = O_constant;
3939 macro_build (NULL, counter, &ex, ADDRESS_ADDI_INSN, "t,r,j",
3940 reg, reg, BFD_RELOC_LO16);
3944 else if (mips_pic == EMBEDDED_PIC)
3947 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3949 macro_build (NULL, counter, ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3950 mips_gp_register, BFD_RELOC_GPREL16);
3956 /* Move the contents of register SOURCE into register DEST. */
3959 move_register (int *counter, int dest, int source)
3961 macro_build (NULL, counter, NULL, HAVE_32BIT_GPRS ? "addu" : "daddu",
3962 "d,v,t", dest, source, 0);
3967 * This routine implements the seemingly endless macro or synthesized
3968 * instructions and addressing modes in the mips assembly language. Many
3969 * of these macros are simple and are similar to each other. These could
3970 * probably be handled by some kind of table or grammar approach instead of
3971 * this verbose method. Others are not simple macros but are more like
3972 * optimizing code generation.
3973 * One interesting optimization is when several store macros appear
3974 * consecutively that would load AT with the upper half of the same address.
3975 * The ensuing load upper instructions are ommited. This implies some kind
3976 * of global optimization. We currently only optimize within a single macro.
3977 * For many of the load and store macros if the address is specified as a
3978 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3979 * first load register 'at' with zero and use it as the base register. The
3980 * mips assembler simply uses register $zero. Just one tiny optimization
3984 macro (struct mips_cl_insn *ip)
3986 register int treg, sreg, dreg, breg;
4003 bfd_reloc_code_real_type r;
4004 int hold_mips_optimize;
4006 assert (! mips_opts.mips16);
4008 treg = (ip->insn_opcode >> 16) & 0x1f;
4009 dreg = (ip->insn_opcode >> 11) & 0x1f;
4010 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
4011 mask = ip->insn_mo->mask;
4013 expr1.X_op = O_constant;
4014 expr1.X_op_symbol = NULL;
4015 expr1.X_add_symbol = NULL;
4016 expr1.X_add_number = 1;
4018 /* Unmatched fixups should not be put in the same frag as a relaxable
4019 macro. For example, suppose we have:
4023 addiu $4,$4,%lo(l1) # 3
4025 If instructions 1 and 2 were put in the same frag, md_frob_file would
4026 move the fixup for #1 after the fixups for the "unrelaxed" version of
4027 #2. This would confuse tc_gen_reloc, which expects the relocations
4028 for #2 to be the last for that frag.
4030 Also, if tc_gen_reloc sees certain relocations in a variant frag,
4031 it assumes that they belong to a relaxable macro. We mustn't put
4032 other uses of such relocations into a variant frag.
4034 To avoid both problems, finish the current frag it contains a
4035 %reloc() operator. The macro then goes into a new frag. */
4036 if (prev_reloc_op_frag == frag_now)
4038 frag_wane (frag_now);
4052 mips_emit_delays (TRUE);
4053 ++mips_opts.noreorder;
4054 mips_any_noreorder = 1;
4056 expr1.X_add_number = 8;
4057 macro_build (NULL, &icnt, &expr1, "bgez", "s,p", sreg);
4059 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4061 move_register (&icnt, dreg, sreg);
4062 macro_build (NULL, &icnt, NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0,
4065 --mips_opts.noreorder;
4086 if (imm_expr.X_op == O_constant
4087 && imm_expr.X_add_number >= -0x8000
4088 && imm_expr.X_add_number < 0x8000)
4090 macro_build (NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
4094 load_register (&icnt, AT, &imm_expr, dbl);
4095 macro_build (NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
4114 if (imm_expr.X_op == O_constant
4115 && imm_expr.X_add_number >= 0
4116 && imm_expr.X_add_number < 0x10000)
4118 if (mask != M_NOR_I)
4119 macro_build (NULL, &icnt, &imm_expr, s, "t,r,i", treg, sreg,
4123 macro_build (NULL, &icnt, &imm_expr, "ori", "t,r,i", treg, sreg,
4125 macro_build (NULL, &icnt, NULL, "nor", "d,v,t", treg, treg, 0);
4130 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4131 macro_build (NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
4148 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4150 macro_build (NULL, &icnt, &offset_expr, s, "s,t,p", sreg, 0);
4153 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
4154 macro_build (NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
4162 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4168 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4172 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
4173 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4180 /* check for > max integer */
4181 maxnum = 0x7fffffff;
4182 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4189 if (imm_expr.X_op == O_constant
4190 && imm_expr.X_add_number >= maxnum
4191 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4194 /* result is always false */
4196 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4198 macro_build (NULL, &icnt, &offset_expr, "bnel", "s,t,p", 0, 0);
4201 if (imm_expr.X_op != O_constant)
4202 as_bad (_("Unsupported large constant"));
4203 ++imm_expr.X_add_number;
4207 if (mask == M_BGEL_I)
4209 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4211 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4215 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4217 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4221 maxnum = 0x7fffffff;
4222 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4229 maxnum = - maxnum - 1;
4230 if (imm_expr.X_op == O_constant
4231 && imm_expr.X_add_number <= maxnum
4232 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4235 /* result is always true */
4236 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4237 macro_build (NULL, &icnt, &offset_expr, "b", "p");
4240 set_at (&icnt, sreg, 0);
4241 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4252 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4256 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, treg);
4257 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4266 && imm_expr.X_op == O_constant
4267 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4269 if (imm_expr.X_op != O_constant)
4270 as_bad (_("Unsupported large constant"));
4271 ++imm_expr.X_add_number;
4275 if (mask == M_BGEUL_I)
4277 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4279 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4281 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4285 set_at (&icnt, sreg, 1);
4286 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4295 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4301 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4305 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
4306 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4315 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4321 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, sreg);
4322 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4331 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4337 macro_build (NULL, &icnt, &offset_expr, likely ? "bgezl" : "bgez",
4341 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
4342 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4349 maxnum = 0x7fffffff;
4350 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4357 if (imm_expr.X_op == O_constant
4358 && imm_expr.X_add_number >= maxnum
4359 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4361 if (imm_expr.X_op != O_constant)
4362 as_bad (_("Unsupported large constant"));
4363 ++imm_expr.X_add_number;
4367 if (mask == M_BLTL_I)
4369 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4371 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4375 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4377 macro_build (NULL, &icnt, &offset_expr, likely ? "blezl" : "blez",
4381 set_at (&icnt, sreg, 0);
4382 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4391 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4397 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, sreg);
4398 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4407 && imm_expr.X_op == O_constant
4408 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4410 if (imm_expr.X_op != O_constant)
4411 as_bad (_("Unsupported large constant"));
4412 ++imm_expr.X_add_number;
4416 if (mask == M_BLTUL_I)
4418 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4420 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4422 macro_build (NULL, &icnt, &offset_expr, likely ? "beql" : "beq",
4426 set_at (&icnt, sreg, 1);
4427 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4436 macro_build (NULL, &icnt, &offset_expr, likely ? "bltzl" : "bltz",
4442 macro_build (NULL, &icnt, &offset_expr, likely ? "bgtzl" : "bgtz",
4446 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
4447 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4458 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4462 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, treg);
4463 macro_build (NULL, &icnt, &offset_expr, likely ? "bnel" : "bne",
4472 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
4474 as_bad (_("Unsupported large constant"));
4479 pos = (unsigned long) imm_expr.X_add_number;
4480 size = (unsigned long) imm2_expr.X_add_number;
4485 as_bad (_("Improper position (%lu)"), pos);
4488 if (size == 0 || size > 64
4489 || (pos + size - 1) > 63)
4491 as_bad (_("Improper extract size (%lu, position %lu)"),
4496 if (size <= 32 && pos < 32)
4501 else if (size <= 32)
4511 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
4512 fmt, treg, sreg, pos, size - 1);
4521 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
4523 as_bad (_("Unsupported large constant"));
4528 pos = (unsigned long) imm_expr.X_add_number;
4529 size = (unsigned long) imm2_expr.X_add_number;
4534 as_bad (_("Improper position (%lu)"), pos);
4537 if (size == 0 || size > 64
4538 || (pos + size - 1) > 63)
4540 as_bad (_("Improper insert size (%lu, position %lu)"),
4545 if (pos < 32 && (pos + size - 1) < 32)
4560 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
4561 fmt, treg, sreg, pos, pos + size - 1);
4577 as_warn (_("Divide by zero."));
4579 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", 0, 0, 7);
4581 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4585 mips_emit_delays (TRUE);
4586 ++mips_opts.noreorder;
4587 mips_any_noreorder = 1;
4590 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", treg, 0, 7);
4591 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "z,s,t",
4596 expr1.X_add_number = 8;
4597 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4598 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "z,s,t",
4600 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4602 expr1.X_add_number = -1;
4603 macro_build (NULL, &icnt, &expr1, dbl ? "daddiu" : "addiu", "t,r,j",
4604 AT, 0, BFD_RELOC_LO16);
4605 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4606 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4609 expr1.X_add_number = 1;
4610 macro_build (NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4612 macro_build (NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT, 31);
4616 expr1.X_add_number = 0x80000000;
4617 macro_build (NULL, &icnt, &expr1, "lui", "t,u", AT,
4622 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", sreg, AT, 6);
4623 /* We want to close the noreorder block as soon as possible, so
4624 that later insns are available for delay slot filling. */
4625 --mips_opts.noreorder;
4629 expr1.X_add_number = 8;
4630 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4631 macro_build (NULL, &icnt, NULL, "nop", "", 0);
4633 /* We want to close the noreorder block as soon as possible, so
4634 that later insns are available for delay slot filling. */
4635 --mips_opts.noreorder;
4637 macro_build (NULL, &icnt, NULL, "break", "c", 6);
4639 macro_build (NULL, &icnt, NULL, s, "d", dreg);
4678 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4680 as_warn (_("Divide by zero."));
4682 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", 0, 0, 7);
4684 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4687 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4689 if (strcmp (s2, "mflo") == 0)
4690 move_register (&icnt, dreg, sreg);
4692 move_register (&icnt, dreg, 0);
4695 if (imm_expr.X_op == O_constant
4696 && imm_expr.X_add_number == -1
4697 && s[strlen (s) - 1] != 'u')
4699 if (strcmp (s2, "mflo") == 0)
4701 macro_build (NULL, &icnt, NULL, dbl ? "dneg" : "neg", "d,w",
4705 move_register (&icnt, dreg, 0);
4709 load_register (&icnt, AT, &imm_expr, dbl);
4710 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, AT);
4711 macro_build (NULL, &icnt, NULL, s2, "d", dreg);
4730 mips_emit_delays (TRUE);
4731 ++mips_opts.noreorder;
4732 mips_any_noreorder = 1;
4735 macro_build (NULL, &icnt, NULL, "teq", "s,t,q", treg, 0, 7);
4736 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4737 /* We want to close the noreorder block as soon as possible, so
4738 that later insns are available for delay slot filling. */
4739 --mips_opts.noreorder;
4743 expr1.X_add_number = 8;
4744 macro_build (NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4745 macro_build (NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4747 /* We want to close the noreorder block as soon as possible, so
4748 that later insns are available for delay slot filling. */
4749 --mips_opts.noreorder;
4750 macro_build (NULL, &icnt, NULL, "break", "c", 7);
4752 macro_build (NULL, &icnt, NULL, s2, "d", dreg);
4764 /* Load the address of a symbol into a register. If breg is not
4765 zero, we then add a base register to it. */
4767 if (dbl && HAVE_32BIT_GPRS)
4768 as_warn (_("dla used to load 32-bit register"));
4770 if (! dbl && HAVE_64BIT_OBJECTS)
4771 as_warn (_("la used to load 64-bit address"));
4773 if (offset_expr.X_op == O_constant
4774 && offset_expr.X_add_number >= -0x8000
4775 && offset_expr.X_add_number < 0x8000)
4777 macro_build (NULL, &icnt, &offset_expr,
4778 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4779 "t,r,j", treg, sreg, BFD_RELOC_LO16);
4794 /* When generating embedded PIC code, we permit expressions of
4797 la $treg,foo-bar($breg)
4798 where bar is an address in the current section. These are used
4799 when getting the addresses of functions. We don't permit
4800 X_add_number to be non-zero, because if the symbol is
4801 external the relaxing code needs to know that any addend is
4802 purely the offset to X_op_symbol. */
4803 if (mips_pic == EMBEDDED_PIC
4804 && offset_expr.X_op == O_subtract
4805 && (symbol_constant_p (offset_expr.X_op_symbol)
4806 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4807 : (symbol_equated_p (offset_expr.X_op_symbol)
4809 (symbol_get_value_expression (offset_expr.X_op_symbol)
4812 && (offset_expr.X_add_number == 0
4813 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4819 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
4820 BFD_RELOC_PCREL_HI16_S);
4824 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
4825 BFD_RELOC_PCREL_HI16_S);
4826 macro_build (NULL, &icnt, NULL,
4827 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4828 "d,v,t", tempreg, tempreg, breg);
4830 macro_build (NULL, &icnt, &offset_expr,
4831 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4832 "t,r,j", treg, tempreg, BFD_RELOC_PCREL_LO16);
4838 if (offset_expr.X_op != O_symbol
4839 && offset_expr.X_op != O_constant)
4841 as_bad (_("expression too complex"));
4842 offset_expr.X_op = O_constant;
4845 if (offset_expr.X_op == O_constant)
4846 load_register (&icnt, tempreg, &offset_expr,
4847 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4848 ? (dbl || HAVE_64BIT_ADDRESSES)
4849 : HAVE_64BIT_ADDRESSES));
4850 else if (mips_pic == NO_PIC)
4852 /* If this is a reference to a GP relative symbol, we want
4853 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4855 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4856 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4857 If we have a constant, we need two instructions anyhow,
4858 so we may as well always use the latter form.
4860 With 64bit address space and a usable $at we want
4861 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4862 lui $at,<sym> (BFD_RELOC_HI16_S)
4863 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4864 daddiu $at,<sym> (BFD_RELOC_LO16)
4866 daddu $tempreg,$tempreg,$at
4868 If $at is already in use, we use a path which is suboptimal
4869 on superscalar processors.
4870 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4871 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4873 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4875 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4878 if (HAVE_64BIT_ADDRESSES)
4880 /* We don't do GP optimization for now because RELAX_ENCODE can't
4881 hold the data for such large chunks. */
4883 if (used_at == 0 && ! mips_opts.noat)
4885 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4886 tempreg, BFD_RELOC_MIPS_HIGHEST);
4887 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4888 AT, BFD_RELOC_HI16_S);
4889 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4890 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
4891 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4892 AT, AT, BFD_RELOC_LO16);
4893 macro_build (p, &icnt, NULL, "dsll32", "d,w,<",
4894 tempreg, tempreg, 0);
4895 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
4896 tempreg, tempreg, AT);
4901 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4902 tempreg, BFD_RELOC_MIPS_HIGHEST);
4903 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4904 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
4905 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
4906 tempreg, tempreg, 16);
4907 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4908 tempreg, tempreg, BFD_RELOC_HI16_S);
4909 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
4910 tempreg, tempreg, 16);
4911 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4912 tempreg, tempreg, BFD_RELOC_LO16);
4917 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4918 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4921 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
4922 "t,r,j", tempreg, mips_gp_register,
4924 p = frag_var (rs_machine_dependent, 8, 0,
4925 RELAX_ENCODE (4, 8, 0, 4, 0,
4926 mips_opts.warn_about_macros),
4927 offset_expr.X_add_symbol, 0, NULL);
4929 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4932 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
4933 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
4936 else if (mips_pic == SVR4_PIC && ! mips_big_got && ! HAVE_NEWABI)
4938 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4940 /* If this is a reference to an external symbol, and there
4941 is no constant, we want
4942 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4943 or for lca or if tempreg is PIC_CALL_REG
4944 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4945 For a local symbol, we want
4946 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4948 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4950 If we have a small constant, and this is a reference to
4951 an external symbol, we want
4952 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4954 addiu $tempreg,$tempreg,<constant>
4955 For a local symbol, we want the same instruction
4956 sequence, but we output a BFD_RELOC_LO16 reloc on the
4959 If we have a large constant, and this is a reference to
4960 an external symbol, we want
4961 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4962 lui $at,<hiconstant>
4963 addiu $at,$at,<loconstant>
4964 addu $tempreg,$tempreg,$at
4965 For a local symbol, we want the same instruction
4966 sequence, but we output a BFD_RELOC_LO16 reloc on the
4970 expr1.X_add_number = offset_expr.X_add_number;
4971 offset_expr.X_add_number = 0;
4973 if (expr1.X_add_number == 0 && breg == 0
4974 && (call || tempreg == PIC_CALL_REG))
4975 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4976 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
4977 tempreg, lw_reloc_type, mips_gp_register);
4978 if (expr1.X_add_number == 0)
4987 /* We're going to put in an addu instruction using
4988 tempreg, so we may as well insert the nop right
4990 macro_build (NULL, &icnt, NULL, "nop", "");
4993 p = frag_var (rs_machine_dependent, 8 - off, 0,
4994 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4996 ? mips_opts.warn_about_macros
4998 offset_expr.X_add_symbol, 0, NULL);
5001 macro_build (p, &icnt, NULL, "nop", "");
5004 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
5005 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5006 /* FIXME: If breg == 0, and the next instruction uses
5007 $tempreg, then if this variant case is used an extra
5008 nop will be generated. */
5010 else if (expr1.X_add_number >= -0x8000
5011 && expr1.X_add_number < 0x8000)
5013 macro_build (NULL, &icnt, NULL, "nop", "");
5014 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5015 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5016 frag_var (rs_machine_dependent, 0, 0,
5017 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
5018 offset_expr.X_add_symbol, 0, NULL);
5024 /* If we are going to add in a base register, and the
5025 target register and the base register are the same,
5026 then we are using AT as a temporary register. Since
5027 we want to load the constant into AT, we add our
5028 current AT (from the global offset table) and the
5029 register into the register now, and pretend we were
5030 not using a base register. */
5035 macro_build (NULL, &icnt, NULL, "nop", "");
5036 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5043 /* Set mips_optimize around the lui instruction to avoid
5044 inserting an unnecessary nop after the lw. */
5045 hold_mips_optimize = mips_optimize;
5047 macro_build_lui (NULL, &icnt, &expr1, AT);
5048 mips_optimize = hold_mips_optimize;
5050 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5051 AT, AT, BFD_RELOC_LO16);
5052 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5053 tempreg, tempreg, AT);
5054 frag_var (rs_machine_dependent, 0, 0,
5055 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
5056 offset_expr.X_add_symbol, 0, NULL);
5060 else if (mips_pic == SVR4_PIC && ! mips_big_got && HAVE_NEWABI)
5063 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_DISP;
5066 /* If this is a reference to an external, and there is no
5067 constant, or local symbol (*), with or without a
5069 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5070 or for lca or if tempreg is PIC_CALL_REG
5071 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5073 If we have a small constant, and this is a reference to
5074 an external symbol, we want
5075 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5076 addiu $tempreg,$tempreg,<constant>
5078 If we have a large constant, and this is a reference to
5079 an external symbol, we want
5080 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5081 lui $at,<hiconstant>
5082 addiu $at,$at,<loconstant>
5083 addu $tempreg,$tempreg,$at
5085 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
5086 local symbols, even though it introduces an additional
5090 if (offset_expr.X_add_number == 0 && breg == 0
5091 && (call || tempreg == PIC_CALL_REG))
5092 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
5093 if (offset_expr.X_add_number)
5095 frag_now->tc_frag_data.tc_fr_offset =
5096 expr1.X_add_number = offset_expr.X_add_number;
5097 offset_expr.X_add_number = 0;
5099 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5100 "t,o(b)", tempreg, lw_reloc_type,
5103 if (expr1.X_add_number >= -0x8000
5104 && expr1.X_add_number < 0x8000)
5106 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5107 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5108 p = frag_var (rs_machine_dependent, 4, 0,
5109 RELAX_ENCODE (8, 4, 0, 0, 0, 0),
5110 offset_expr.X_add_symbol, 0, NULL);
5112 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
5116 /* If we are going to add in a base register, and the
5117 target register and the base register are the same,
5118 then we are using AT as a temporary register. Since
5119 we want to load the constant into AT, we add our
5120 current AT (from the global offset table) and the
5121 register into the register now, and pretend we were
5122 not using a base register. */
5127 assert (tempreg == AT);
5128 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN,
5129 "d,v,t", treg, AT, breg);
5134 macro_build_lui (NULL, &icnt, &expr1, AT);
5135 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5136 "t,r,j", AT, AT, BFD_RELOC_LO16);
5137 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5140 p = frag_var (rs_machine_dependent, 4 + adj, 0,
5141 RELAX_ENCODE (16 + adj, 4 + adj,
5143 offset_expr.X_add_symbol, 0, NULL);
5148 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5150 offset_expr.X_add_number = expr1.X_add_number;
5152 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5153 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_DISP,
5157 macro_build (p + 4, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5158 treg, tempreg, breg);
5165 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5166 "t,o(b)", tempreg, lw_reloc_type,
5168 if (lw_reloc_type != BFD_RELOC_MIPS_GOT_DISP)
5169 p = frag_var (rs_machine_dependent, 0, 0,
5170 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5171 offset_expr.X_add_symbol, 0, NULL);
5176 /* To avoid confusion in tc_gen_reloc, we must ensure
5177 that this does not become a variant frag. */
5178 frag_wane (frag_now);
5182 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
5186 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5187 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5188 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
5190 /* This is the large GOT case. If this is a reference to an
5191 external symbol, and there is no constant, we want
5192 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5193 addu $tempreg,$tempreg,$gp
5194 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5195 or for lca or if tempreg is PIC_CALL_REG
5196 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5197 addu $tempreg,$tempreg,$gp
5198 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5199 For a local symbol, we want
5200 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5202 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5204 If we have a small constant, and this is a reference to
5205 an external symbol, we want
5206 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5207 addu $tempreg,$tempreg,$gp
5208 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5210 addiu $tempreg,$tempreg,<constant>
5211 For a local symbol, we want
5212 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5214 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5216 If we have a large constant, and this is a reference to
5217 an external symbol, we want
5218 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5219 addu $tempreg,$tempreg,$gp
5220 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5221 lui $at,<hiconstant>
5222 addiu $at,$at,<loconstant>
5223 addu $tempreg,$tempreg,$at
5224 For a local symbol, we want
5225 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5226 lui $at,<hiconstant>
5227 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5228 addu $tempreg,$tempreg,$at
5231 expr1.X_add_number = offset_expr.X_add_number;
5232 offset_expr.X_add_number = 0;
5234 if (reg_needs_delay (mips_gp_register))
5238 if (expr1.X_add_number == 0 && breg == 0
5239 && (call || tempreg == PIC_CALL_REG))
5241 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5242 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5244 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5245 tempreg, lui_reloc_type);
5246 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5247 tempreg, tempreg, mips_gp_register);
5248 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5249 tempreg, lw_reloc_type, tempreg);
5250 if (expr1.X_add_number == 0)
5258 /* We're going to put in an addu instruction using
5259 tempreg, so we may as well insert the nop right
5261 macro_build (NULL, &icnt, NULL, "nop", "");
5265 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5266 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
5269 ? mips_opts.warn_about_macros
5271 offset_expr.X_add_symbol, 0, NULL);
5273 else if (expr1.X_add_number >= -0x8000
5274 && expr1.X_add_number < 0x8000)
5276 macro_build (NULL, &icnt, NULL, "nop", "");
5277 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5278 tempreg, tempreg, BFD_RELOC_LO16);
5280 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5281 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
5283 ? mips_opts.warn_about_macros
5285 offset_expr.X_add_symbol, 0, NULL);
5291 /* If we are going to add in a base register, and the
5292 target register and the base register are the same,
5293 then we are using AT as a temporary register. Since
5294 we want to load the constant into AT, we add our
5295 current AT (from the global offset table) and the
5296 register into the register now, and pretend we were
5297 not using a base register. */
5305 assert (tempreg == AT);
5306 macro_build (NULL, &icnt, NULL, "nop", "");
5307 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5313 /* Set mips_optimize around the lui instruction to avoid
5314 inserting an unnecessary nop after the lw. */
5315 hold_mips_optimize = mips_optimize;
5317 macro_build_lui (NULL, &icnt, &expr1, AT);
5318 mips_optimize = hold_mips_optimize;
5320 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5321 AT, AT, BFD_RELOC_LO16);
5322 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5325 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
5326 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
5329 ? mips_opts.warn_about_macros
5331 offset_expr.X_add_symbol, 0, NULL);
5338 /* This is needed because this instruction uses $gp, but
5339 the first instruction on the main stream does not. */
5340 macro_build (p, &icnt, NULL, "nop", "");
5344 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5345 tempreg, local_reloc_type, mips_gp_register);
5347 if (expr1.X_add_number >= -0x8000
5348 && expr1.X_add_number < 0x8000)
5350 macro_build (p, &icnt, NULL, "nop", "");
5352 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN,
5353 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
5354 /* FIXME: If add_number is 0, and there was no base
5355 register, the external symbol case ended with a load,
5356 so if the symbol turns out to not be external, and
5357 the next instruction uses tempreg, an unnecessary nop
5358 will be inserted. */
5364 /* We must add in the base register now, as in the
5365 external symbol case. */
5366 assert (tempreg == AT);
5367 macro_build (p, &icnt, NULL, "nop", "");
5369 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5373 /* We set breg to 0 because we have arranged to add
5374 it in in both cases. */
5378 macro_build_lui (p, &icnt, &expr1, AT);
5380 macro_build (p, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5381 AT, AT, BFD_RELOC_LO16);
5383 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5384 tempreg, tempreg, AT);
5388 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
5391 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5392 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5395 /* This is the large GOT case. If this is a reference to an
5396 external symbol, and there is no constant, we want
5397 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5398 add $tempreg,$tempreg,$gp
5399 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5400 or for lca or if tempreg is PIC_CALL_REG
5401 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5402 add $tempreg,$tempreg,$gp
5403 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5405 If we have a small constant, and this is a reference to
5406 an external symbol, we want
5407 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5408 add $tempreg,$tempreg,$gp
5409 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5410 addi $tempreg,$tempreg,<constant>
5412 If we have a large constant, and this is a reference to
5413 an external symbol, we want
5414 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5415 addu $tempreg,$tempreg,$gp
5416 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5417 lui $at,<hiconstant>
5418 addi $at,$at,<loconstant>
5419 add $tempreg,$tempreg,$at
5421 If we have NewABI, and we know it's a local symbol, we want
5422 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5423 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5424 otherwise we have to resort to GOT_HI16/GOT_LO16. */
5428 frag_now->tc_frag_data.tc_fr_offset =
5429 expr1.X_add_number = offset_expr.X_add_number;
5430 offset_expr.X_add_number = 0;
5432 if (expr1.X_add_number == 0 && breg == 0
5433 && (call || tempreg == PIC_CALL_REG))
5435 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5436 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5438 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5439 tempreg, lui_reloc_type);
5440 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5441 tempreg, tempreg, mips_gp_register);
5442 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5443 "t,o(b)", tempreg, lw_reloc_type, tempreg);
5445 if (expr1.X_add_number == 0)
5447 p = frag_var (rs_machine_dependent, 8, 0,
5448 RELAX_ENCODE (12, 8, 0, 4, 0,
5449 mips_opts.warn_about_macros),
5450 offset_expr.X_add_symbol, 0, NULL);
5452 else if (expr1.X_add_number >= -0x8000
5453 && expr1.X_add_number < 0x8000)
5455 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN, "t,r,j",
5456 tempreg, tempreg, BFD_RELOC_LO16);
5457 p = frag_var (rs_machine_dependent, 8, 0,
5458 RELAX_ENCODE (16, 8, 0, 4, 0,
5459 mips_opts.warn_about_macros),
5460 offset_expr.X_add_symbol, 0, NULL);
5462 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
5466 /* If we are going to add in a base register, and the
5467 target register and the base register are the same,
5468 then we are using AT as a temporary register. Since
5469 we want to load the constant into AT, we add our
5470 current AT (from the global offset table) and the
5471 register into the register now, and pretend we were
5472 not using a base register. */
5477 assert (tempreg == AT);
5478 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5484 /* Set mips_optimize around the lui instruction to avoid
5485 inserting an unnecessary nop after the lw. */
5486 macro_build_lui (NULL, &icnt, &expr1, AT);
5487 macro_build (NULL, &icnt, &expr1, ADDRESS_ADDI_INSN,
5488 "t,r,j", AT, AT, BFD_RELOC_LO16);
5489 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5492 p = frag_var (rs_machine_dependent, 8 + adj, 0,
5493 RELAX_ENCODE (24 + adj, 8 + adj,
5496 ? mips_opts.warn_about_macros
5498 offset_expr.X_add_symbol, 0, NULL);
5503 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5505 offset_expr.X_add_number = expr1.X_add_number;
5506 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5507 tempreg, BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5508 macro_build (p + 4, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5509 tempreg, tempreg, BFD_RELOC_MIPS_GOT_OFST);
5512 macro_build (p + 8, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5513 treg, tempreg, breg);
5518 else if (mips_pic == EMBEDDED_PIC)
5521 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5523 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5524 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
5533 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
5534 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu";
5536 s = ADDRESS_ADD_INSN;
5538 macro_build (NULL, &icnt, NULL, s, "d,v,t", treg, tempreg, breg);
5547 /* The j instruction may not be used in PIC code, since it
5548 requires an absolute address. We convert it to a b
5550 if (mips_pic == NO_PIC)
5551 macro_build (NULL, &icnt, &offset_expr, "j", "a");
5553 macro_build (NULL, &icnt, &offset_expr, "b", "p");
5556 /* The jal instructions must be handled as macros because when
5557 generating PIC code they expand to multi-instruction
5558 sequences. Normally they are simple instructions. */
5563 if (mips_pic == NO_PIC
5564 || mips_pic == EMBEDDED_PIC)
5565 macro_build (NULL, &icnt, NULL, "jalr", "d,s", dreg, sreg);
5566 else if (mips_pic == SVR4_PIC)
5568 if (sreg != PIC_CALL_REG)
5569 as_warn (_("MIPS PIC call to register other than $25"));
5571 macro_build (NULL, &icnt, NULL, "jalr", "d,s", dreg, sreg);
5574 if (mips_cprestore_offset < 0)
5575 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5578 if (! mips_frame_reg_valid)
5580 as_warn (_("No .frame pseudo-op used in PIC code"));
5581 /* Quiet this warning. */
5582 mips_frame_reg_valid = 1;
5584 if (! mips_cprestore_valid)
5586 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5587 /* Quiet this warning. */
5588 mips_cprestore_valid = 1;
5590 expr1.X_add_number = mips_cprestore_offset;
5591 macro_build_ldst_constoffset (NULL, &icnt, &expr1,
5595 HAVE_64BIT_ADDRESSES);
5605 if (mips_pic == NO_PIC)
5606 macro_build (NULL, &icnt, &offset_expr, "jal", "a");
5607 else if (mips_pic == SVR4_PIC)
5611 /* If this is a reference to an external symbol, and we are
5612 using a small GOT, we want
5613 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5617 lw $gp,cprestore($sp)
5618 The cprestore value is set using the .cprestore
5619 pseudo-op. If we are using a big GOT, we want
5620 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5622 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5626 lw $gp,cprestore($sp)
5627 If the symbol is not external, we want
5628 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5630 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5633 lw $gp,cprestore($sp)
5635 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
5636 sequences above, minus nops, unless the symbol is local,
5637 which enables us to use GOT_PAGE/GOT_OFST (big got) or
5644 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5645 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5647 frag_var (rs_machine_dependent, 0, 0,
5648 RELAX_ENCODE (0, 0, -4, 0, 0, 0),
5649 offset_expr.X_add_symbol, 0, NULL);
5654 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5655 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_HI16);
5656 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5657 PIC_CALL_REG, PIC_CALL_REG, mips_gp_register);
5658 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5659 "t,o(b)", PIC_CALL_REG,
5660 BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5661 p = frag_var (rs_machine_dependent, 8, 0,
5662 RELAX_ENCODE (12, 8, 0, 4, 0, 0),
5663 offset_expr.X_add_symbol, 0, NULL);
5664 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5665 "t,o(b)", PIC_CALL_REG,
5666 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5667 macro_build (p + 4, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5668 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5669 BFD_RELOC_MIPS_GOT_OFST);
5672 macro_build_jalr (icnt, &offset_expr);
5679 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5680 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5682 macro_build (NULL, &icnt, NULL, "nop", "");
5683 p = frag_var (rs_machine_dependent, 4, 0,
5684 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5685 offset_expr.X_add_symbol, 0, NULL);
5691 if (reg_needs_delay (mips_gp_register))
5695 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u",
5696 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_HI16);
5697 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
5698 PIC_CALL_REG, PIC_CALL_REG, mips_gp_register);
5699 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5700 "t,o(b)", PIC_CALL_REG,
5701 BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5702 macro_build (NULL, &icnt, NULL, "nop", "");
5703 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5704 RELAX_ENCODE (16, 12 + gpdel, gpdel,
5706 offset_expr.X_add_symbol, 0, NULL);
5709 macro_build (p, &icnt, NULL, "nop", "");
5712 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
5713 "t,o(b)", PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
5716 macro_build (p, &icnt, NULL, "nop", "");
5719 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
5720 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5722 macro_build_jalr (icnt, &offset_expr);
5724 if (mips_cprestore_offset < 0)
5725 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5728 if (! mips_frame_reg_valid)
5730 as_warn (_("No .frame pseudo-op used in PIC code"));
5731 /* Quiet this warning. */
5732 mips_frame_reg_valid = 1;
5734 if (! mips_cprestore_valid)
5736 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5737 /* Quiet this warning. */
5738 mips_cprestore_valid = 1;
5740 if (mips_opts.noreorder)
5741 macro_build (NULL, &icnt, NULL, "nop", "");
5742 expr1.X_add_number = mips_cprestore_offset;
5743 macro_build_ldst_constoffset (NULL, &icnt, &expr1,
5747 HAVE_64BIT_ADDRESSES);
5751 else if (mips_pic == EMBEDDED_PIC)
5753 macro_build (NULL, &icnt, &offset_expr, "bal", "p");
5754 /* The linker may expand the call to a longer sequence which
5755 uses $at, so we must break rather than return. */
5780 /* Itbl support may require additional care here. */
5785 /* Itbl support may require additional care here. */
5790 /* Itbl support may require additional care here. */
5795 /* Itbl support may require additional care here. */
5807 if (mips_opts.arch == CPU_R4650)
5809 as_bad (_("opcode not supported on this processor"));
5813 /* Itbl support may require additional care here. */
5818 /* Itbl support may require additional care here. */
5823 /* Itbl support may require additional care here. */
5843 if (breg == treg || coproc || lr)
5865 /* Itbl support may require additional care here. */
5870 /* Itbl support may require additional care here. */
5875 /* Itbl support may require additional care here. */
5880 /* Itbl support may require additional care here. */
5896 if (mips_opts.arch == CPU_R4650)
5898 as_bad (_("opcode not supported on this processor"));
5903 /* Itbl support may require additional care here. */
5907 /* Itbl support may require additional care here. */
5912 /* Itbl support may require additional care here. */
5924 /* Itbl support may require additional care here. */
5925 if (mask == M_LWC1_AB
5926 || mask == M_SWC1_AB
5927 || mask == M_LDC1_AB
5928 || mask == M_SDC1_AB
5937 /* Sign-extending 32-bit constants makes their handling easier.
5938 The HAVE_64BIT_GPRS... part is due to the linux kernel hack
5940 if ((! HAVE_64BIT_ADDRESSES
5941 && (! HAVE_64BIT_GPRS && offset_expr.X_op == O_constant))
5942 && (offset_expr.X_op == O_constant)
5943 && ! ((offset_expr.X_add_number & ~((bfd_vma) 0x7fffffff))
5944 == ~((bfd_vma) 0x7fffffff)))
5946 if (offset_expr.X_add_number & ~((bfd_vma) 0xffffffff))
5947 as_bad (_("constant too large"));
5949 offset_expr.X_add_number = (((offset_expr.X_add_number & 0xffffffff)
5950 ^ 0x80000000) - 0x80000000);
5953 /* For embedded PIC, we allow loads where the offset is calculated
5954 by subtracting a symbol in the current segment from an unknown
5955 symbol, relative to a base register, e.g.:
5956 <op> $treg, <sym>-<localsym>($breg)
5957 This is used by the compiler for switch statements. */
5958 if (mips_pic == EMBEDDED_PIC
5959 && offset_expr.X_op == O_subtract
5960 && (symbol_constant_p (offset_expr.X_op_symbol)
5961 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5962 : (symbol_equated_p (offset_expr.X_op_symbol)
5964 (symbol_get_value_expression (offset_expr.X_op_symbol)
5968 && (offset_expr.X_add_number == 0
5969 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5971 /* For this case, we output the instructions:
5972 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5973 addiu $tempreg,$tempreg,$breg
5974 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5975 If the relocation would fit entirely in 16 bits, it would be
5977 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5978 instead, but that seems quite difficult. */
5979 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
5980 BFD_RELOC_PCREL_HI16_S);
5981 macro_build (NULL, &icnt, NULL,
5982 ((bfd_arch_bits_per_address (stdoutput) == 32
5983 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5984 ? "addu" : "daddu"),
5985 "d,v,t", tempreg, tempreg, breg);
5986 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
5987 BFD_RELOC_PCREL_LO16, tempreg);
5993 if (offset_expr.X_op != O_constant
5994 && offset_expr.X_op != O_symbol)
5996 as_bad (_("expression too complex"));
5997 offset_expr.X_op = O_constant;
6000 /* A constant expression in PIC code can be handled just as it
6001 is in non PIC code. */
6002 if (mips_pic == NO_PIC
6003 || offset_expr.X_op == O_constant)
6007 /* If this is a reference to a GP relative symbol, and there
6008 is no base register, we want
6009 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6010 Otherwise, if there is no base register, we want
6011 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6012 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6013 If we have a constant, we need two instructions anyhow,
6014 so we always use the latter form.
6016 If we have a base register, and this is a reference to a
6017 GP relative symbol, we want
6018 addu $tempreg,$breg,$gp
6019 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6021 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6022 addu $tempreg,$tempreg,$breg
6023 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6024 With a constant we always use the latter case.
6026 With 64bit address space and no base register and $at usable,
6028 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6029 lui $at,<sym> (BFD_RELOC_HI16_S)
6030 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6033 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6034 If we have a base register, we want
6035 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6036 lui $at,<sym> (BFD_RELOC_HI16_S)
6037 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6041 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6043 Without $at we can't generate the optimal path for superscalar
6044 processors here since this would require two temporary registers.
6045 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6046 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6048 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6050 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6051 If we have a base register, we want
6052 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6053 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6055 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6057 daddu $tempreg,$tempreg,$breg
6058 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6060 If we have 64-bit addresses, as an optimization, for
6061 addresses which are 32-bit constants (e.g. kseg0/kseg1
6062 addresses) we fall back to the 32-bit address generation
6063 mechanism since it is more efficient. Note that due to
6064 the signed offset used by memory operations, the 32-bit
6065 range is shifted down by 32768 here. This code should
6066 probably attempt to generate 64-bit constants more
6067 efficiently in general.
6069 As an extension for architectures with 64-bit registers,
6070 we don't truncate 64-bit addresses given as literal
6071 constants down to 32 bits, to support existing practice
6072 in the mips64 Linux (the kernel), that compiles source
6073 files with -mabi=64, assembling them as o32 or n32 (with
6074 -Wa,-32 or -Wa,-n32). This is not beautiful, but since
6075 the whole kernel is loaded into a memory region that is
6076 addressable with sign-extended 32-bit addresses, it is
6077 wasteful to compute the upper 32 bits of every
6078 non-literal address, that takes more space and time.
6079 Some day this should probably be implemented as an
6080 assembler option, such that the kernel doesn't have to
6081 use such ugly hacks, even though it will still have to
6082 end up converting the binary to ELF32 for a number of
6083 platforms whose boot loaders don't support ELF64
6085 if ((HAVE_64BIT_ADDRESSES
6086 && ! (offset_expr.X_op == O_constant
6087 && IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000)))
6089 && offset_expr.X_op == O_constant
6090 && ! IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000)))
6094 /* We don't do GP optimization for now because RELAX_ENCODE can't
6095 hold the data for such large chunks. */
6097 if (used_at == 0 && ! mips_opts.noat)
6099 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6100 tempreg, BFD_RELOC_MIPS_HIGHEST);
6101 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6102 AT, BFD_RELOC_HI16_S);
6103 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6104 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
6106 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
6108 macro_build (p, &icnt, NULL, "dsll32", "d,w,<",
6109 tempreg, tempreg, 0);
6110 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
6111 tempreg, tempreg, AT);
6112 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6113 BFD_RELOC_LO16, tempreg);
6118 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
6119 tempreg, BFD_RELOC_MIPS_HIGHEST);
6120 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6121 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
6122 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
6123 tempreg, tempreg, 16);
6124 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
6125 tempreg, tempreg, BFD_RELOC_HI16_S);
6126 macro_build (p, &icnt, NULL, "dsll", "d,w,<",
6127 tempreg, tempreg, 16);
6129 macro_build (p, &icnt, NULL, "daddu", "d,v,t",
6130 tempreg, tempreg, breg);
6131 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6132 BFD_RELOC_LO16, tempreg);
6138 if (offset_expr.X_op == O_constant
6139 && ! IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000))
6140 as_bad (_("load/store address overflow (max 32 bits)"));
6144 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6145 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6150 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6151 BFD_RELOC_GPREL16, mips_gp_register);
6152 p = frag_var (rs_machine_dependent, 8, 0,
6153 RELAX_ENCODE (4, 8, 0, 4, 0,
6154 (mips_opts.warn_about_macros
6156 && mips_opts.noat))),
6157 offset_expr.X_add_symbol, 0, NULL);
6160 macro_build_lui (p, &icnt, &offset_expr, tempreg);
6163 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6164 BFD_RELOC_LO16, tempreg);
6168 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6169 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6174 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6175 tempreg, breg, mips_gp_register);
6176 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6177 BFD_RELOC_GPREL16, tempreg);
6178 p = frag_var (rs_machine_dependent, 12, 0,
6179 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
6180 offset_expr.X_add_symbol, 0, NULL);
6182 macro_build_lui (p, &icnt, &offset_expr, tempreg);
6185 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6186 tempreg, tempreg, breg);
6189 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
6190 BFD_RELOC_LO16, tempreg);
6193 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6196 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
6198 /* If this is a reference to an external symbol, we want
6199 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6201 <op> $treg,0($tempreg)
6203 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6205 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6206 <op> $treg,0($tempreg)
6209 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6210 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6212 If there is a base register, we add it to $tempreg before
6213 the <op>. If there is a constant, we stick it in the
6214 <op> instruction. We don't handle constants larger than
6215 16 bits, because we have no way to load the upper 16 bits
6216 (actually, we could handle them for the subset of cases
6217 in which we are not using $at). */
6218 assert (offset_expr.X_op == O_symbol);
6221 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6222 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_PAGE,
6225 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6226 tempreg, tempreg, breg);
6227 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6228 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6235 expr1.X_add_number = offset_expr.X_add_number;
6236 offset_expr.X_add_number = 0;
6237 if (expr1.X_add_number < -0x8000
6238 || expr1.X_add_number >= 0x8000)
6239 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6241 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6242 tempreg, lw_reloc_type, mips_gp_register);
6243 macro_build (NULL, &icnt, NULL, "nop", "");
6244 p = frag_var (rs_machine_dependent, 4, 0,
6245 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
6246 offset_expr.X_add_symbol, 0, NULL);
6247 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN,
6248 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
6250 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6251 tempreg, tempreg, breg);
6252 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6255 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
6260 /* If this is a reference to an external symbol, we want
6261 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6262 addu $tempreg,$tempreg,$gp
6263 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6264 <op> $treg,0($tempreg)
6266 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6268 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6269 <op> $treg,0($tempreg)
6270 If there is a base register, we add it to $tempreg before
6271 the <op>. If there is a constant, we stick it in the
6272 <op> instruction. We don't handle constants larger than
6273 16 bits, because we have no way to load the upper 16 bits
6274 (actually, we could handle them for the subset of cases
6275 in which we are not using $at). */
6276 assert (offset_expr.X_op == O_symbol);
6277 expr1.X_add_number = offset_expr.X_add_number;
6278 offset_expr.X_add_number = 0;
6279 if (expr1.X_add_number < -0x8000
6280 || expr1.X_add_number >= 0x8000)
6281 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6282 if (reg_needs_delay (mips_gp_register))
6287 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
6288 BFD_RELOC_MIPS_GOT_HI16);
6289 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6290 tempreg, tempreg, mips_gp_register);
6291 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6292 tempreg, BFD_RELOC_MIPS_GOT_LO16, tempreg);
6293 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
6294 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
6295 offset_expr.X_add_symbol, 0, NULL);
6298 macro_build (p, &icnt, NULL, "nop", "");
6301 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6302 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6304 macro_build (p, &icnt, NULL, "nop", "");
6306 macro_build (p, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
6307 tempreg, tempreg, BFD_RELOC_LO16);
6309 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6310 tempreg, tempreg, breg);
6311 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6314 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
6317 int bregsz = breg != 0 ? 4 : 0;
6319 /* If this is a reference to an external symbol, we want
6320 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6321 add $tempreg,$tempreg,$gp
6322 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6323 <op> $treg,<ofst>($tempreg)
6324 Otherwise, for local symbols, we want:
6325 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6326 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6327 assert (offset_expr.X_op == O_symbol);
6329 frag_now->tc_frag_data.tc_fr_offset =
6330 expr1.X_add_number = offset_expr.X_add_number;
6331 offset_expr.X_add_number = 0;
6332 if (expr1.X_add_number < -0x8000
6333 || expr1.X_add_number >= 0x8000)
6334 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6335 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", tempreg,
6336 BFD_RELOC_MIPS_GOT_HI16);
6337 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6338 tempreg, tempreg, mips_gp_register);
6339 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6340 tempreg, BFD_RELOC_MIPS_GOT_LO16, tempreg);
6342 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6343 tempreg, tempreg, breg);
6344 macro_build (NULL, &icnt, &expr1, s, fmt, treg, BFD_RELOC_LO16,
6347 offset_expr.X_add_number = expr1.X_add_number;
6348 p = frag_var (rs_machine_dependent, 12 + bregsz, 0,
6349 RELAX_ENCODE (16 + bregsz, 8 + bregsz,
6350 0, 4 + bregsz, 0, 0),
6351 offset_expr.X_add_symbol, 0, NULL);
6352 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6353 tempreg, BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6355 macro_build (p + 4, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6356 tempreg, tempreg, breg);
6357 macro_build (p + 4 + bregsz, &icnt, &offset_expr, s, fmt, treg,
6358 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6360 else if (mips_pic == EMBEDDED_PIC)
6362 /* If there is no base register, we want
6363 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6364 If there is a base register, we want
6365 addu $tempreg,$breg,$gp
6366 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6368 assert (offset_expr.X_op == O_symbol);
6371 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6372 BFD_RELOC_GPREL16, mips_gp_register);
6377 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6378 tempreg, breg, mips_gp_register);
6379 macro_build (NULL, &icnt, &offset_expr, s, fmt, treg,
6380 BFD_RELOC_GPREL16, tempreg);
6393 load_register (&icnt, treg, &imm_expr, 0);
6397 load_register (&icnt, treg, &imm_expr, 1);
6401 if (imm_expr.X_op == O_constant)
6403 load_register (&icnt, AT, &imm_expr, 0);
6404 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg);
6409 assert (offset_expr.X_op == O_symbol
6410 && strcmp (segment_name (S_GET_SEGMENT
6411 (offset_expr.X_add_symbol)),
6413 && offset_expr.X_add_number == 0);
6414 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", treg,
6415 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6420 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6421 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6422 order 32 bits of the value and the low order 32 bits are either
6423 zero or in OFFSET_EXPR. */
6424 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6426 if (HAVE_64BIT_GPRS)
6427 load_register (&icnt, treg, &imm_expr, 1);
6432 if (target_big_endian)
6444 load_register (&icnt, hreg, &imm_expr, 0);
6447 if (offset_expr.X_op == O_absent)
6448 move_register (&icnt, lreg, 0);
6451 assert (offset_expr.X_op == O_constant);
6452 load_register (&icnt, lreg, &offset_expr, 0);
6459 /* We know that sym is in the .rdata section. First we get the
6460 upper 16 bits of the address. */
6461 if (mips_pic == NO_PIC)
6463 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6465 else if (mips_pic == SVR4_PIC)
6467 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6468 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6470 else if (mips_pic == EMBEDDED_PIC)
6472 /* For embedded PIC we pick up the entire address off $gp in
6473 a single instruction. */
6474 macro_build (NULL, &icnt, &offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
6475 AT, mips_gp_register, BFD_RELOC_GPREL16);
6476 offset_expr.X_op = O_constant;
6477 offset_expr.X_add_number = 0;
6482 /* Now we load the register(s). */
6483 if (HAVE_64BIT_GPRS)
6484 macro_build (NULL, &icnt, &offset_expr, "ld", "t,o(b)", treg,
6485 BFD_RELOC_LO16, AT);
6488 macro_build (NULL, &icnt, &offset_expr, "lw", "t,o(b)", treg,
6489 BFD_RELOC_LO16, AT);
6492 /* FIXME: How in the world do we deal with the possible
6494 offset_expr.X_add_number += 4;
6495 macro_build (NULL, &icnt, &offset_expr, "lw", "t,o(b)",
6496 treg + 1, BFD_RELOC_LO16, AT);
6500 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6501 does not become a variant frag. */
6502 frag_wane (frag_now);
6508 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6509 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6510 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6511 the value and the low order 32 bits are either zero or in
6513 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6515 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
6516 if (HAVE_64BIT_FPRS)
6518 assert (HAVE_64BIT_GPRS);
6519 macro_build (NULL, &icnt, NULL, "dmtc1", "t,S", AT, treg);
6523 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg + 1);
6524 if (offset_expr.X_op == O_absent)
6525 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", 0, treg);
6528 assert (offset_expr.X_op == O_constant);
6529 load_register (&icnt, AT, &offset_expr, 0);
6530 macro_build (NULL, &icnt, NULL, "mtc1", "t,G", AT, treg);
6536 assert (offset_expr.X_op == O_symbol
6537 && offset_expr.X_add_number == 0);
6538 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
6539 if (strcmp (s, ".lit8") == 0)
6541 if (mips_opts.isa != ISA_MIPS1)
6543 macro_build (NULL, &icnt, &offset_expr, "ldc1", "T,o(b)", treg,
6544 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6547 breg = mips_gp_register;
6548 r = BFD_RELOC_MIPS_LITERAL;
6553 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
6554 if (mips_pic == SVR4_PIC)
6555 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN,
6556 "t,o(b)", AT, BFD_RELOC_MIPS_GOT16,
6560 /* FIXME: This won't work for a 64 bit address. */
6561 macro_build_lui (NULL, &icnt, &offset_expr, AT);
6564 if (mips_opts.isa != ISA_MIPS1)
6566 macro_build (NULL, &icnt, &offset_expr, "ldc1", "T,o(b)", treg,
6567 BFD_RELOC_LO16, AT);
6569 /* To avoid confusion in tc_gen_reloc, we must ensure
6570 that this does not become a variant frag. */
6571 frag_wane (frag_now);
6582 if (mips_opts.arch == CPU_R4650)
6584 as_bad (_("opcode not supported on this processor"));
6587 /* Even on a big endian machine $fn comes before $fn+1. We have
6588 to adjust when loading from memory. */
6591 assert (mips_opts.isa == ISA_MIPS1);
6592 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6593 target_big_endian ? treg + 1 : treg, r, breg);
6594 /* FIXME: A possible overflow which I don't know how to deal
6596 offset_expr.X_add_number += 4;
6597 macro_build (NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
6598 target_big_endian ? treg : treg + 1, r, breg);
6600 /* To avoid confusion in tc_gen_reloc, we must ensure that this
6601 does not become a variant frag. */
6602 frag_wane (frag_now);
6611 * The MIPS assembler seems to check for X_add_number not
6612 * being double aligned and generating:
6615 * addiu at,at,%lo(foo+1)
6618 * But, the resulting address is the same after relocation so why
6619 * generate the extra instruction?
6621 if (mips_opts.arch == CPU_R4650)
6623 as_bad (_("opcode not supported on this processor"));
6626 /* Itbl support may require additional care here. */
6628 if (mips_opts.isa != ISA_MIPS1)
6639 if (mips_opts.arch == CPU_R4650)
6641 as_bad (_("opcode not supported on this processor"));
6645 if (mips_opts.isa != ISA_MIPS1)
6653 /* Itbl support may require additional care here. */
6658 if (HAVE_64BIT_GPRS)
6669 if (HAVE_64BIT_GPRS)
6679 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6680 loads for the case of doing a pair of loads to simulate an 'ld'.
6681 This is not currently done by the compiler, and assembly coders
6682 writing embedded-pic code can cope. */
6684 if (offset_expr.X_op != O_symbol
6685 && offset_expr.X_op != O_constant)
6687 as_bad (_("expression too complex"));
6688 offset_expr.X_op = O_constant;
6691 /* Even on a big endian machine $fn comes before $fn+1. We have
6692 to adjust when loading from memory. We set coproc if we must
6693 load $fn+1 first. */
6694 /* Itbl support may require additional care here. */
6695 if (! target_big_endian)
6698 if (mips_pic == NO_PIC
6699 || offset_expr.X_op == O_constant)
6703 /* If this is a reference to a GP relative symbol, we want
6704 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6705 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6706 If we have a base register, we use this
6708 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6709 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6710 If this is not a GP relative symbol, we want
6711 lui $at,<sym> (BFD_RELOC_HI16_S)
6712 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6713 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6714 If there is a base register, we add it to $at after the
6715 lui instruction. If there is a constant, we always use
6717 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6718 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6730 tempreg = mips_gp_register;
6737 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6738 AT, breg, mips_gp_register);
6744 /* Itbl support may require additional care here. */
6745 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6746 coproc ? treg + 1 : treg,
6747 BFD_RELOC_GPREL16, tempreg);
6748 offset_expr.X_add_number += 4;
6750 /* Set mips_optimize to 2 to avoid inserting an
6752 hold_mips_optimize = mips_optimize;
6754 /* Itbl support may require additional care here. */
6755 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6756 coproc ? treg : treg + 1,
6757 BFD_RELOC_GPREL16, tempreg);
6758 mips_optimize = hold_mips_optimize;
6760 p = frag_var (rs_machine_dependent, 12 + off, 0,
6761 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6762 used_at && mips_opts.noat),
6763 offset_expr.X_add_symbol, 0, NULL);
6765 /* We just generated two relocs. When tc_gen_reloc
6766 handles this case, it will skip the first reloc and
6767 handle the second. The second reloc already has an
6768 extra addend of 4, which we added above. We must
6769 subtract it out, and then subtract another 4 to make
6770 the first reloc come out right. The second reloc
6771 will come out right because we are going to add 4 to
6772 offset_expr when we build its instruction below.
6774 If we have a symbol, then we don't want to include
6775 the offset, because it will wind up being included
6776 when we generate the reloc. */
6778 if (offset_expr.X_op == O_constant)
6779 offset_expr.X_add_number -= 8;
6782 offset_expr.X_add_number = -4;
6783 offset_expr.X_op = O_constant;
6786 macro_build_lui (p, &icnt, &offset_expr, AT);
6791 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6796 /* Itbl support may require additional care here. */
6797 macro_build (p, &icnt, &offset_expr, s, fmt,
6798 coproc ? treg + 1 : treg,
6799 BFD_RELOC_LO16, AT);
6802 /* FIXME: How do we handle overflow here? */
6803 offset_expr.X_add_number += 4;
6804 /* Itbl support may require additional care here. */
6805 macro_build (p, &icnt, &offset_expr, s, fmt,
6806 coproc ? treg : treg + 1,
6807 BFD_RELOC_LO16, AT);
6809 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6813 /* If this is a reference to an external symbol, we want
6814 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6819 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6821 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6822 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6823 If there is a base register we add it to $at before the
6824 lwc1 instructions. If there is a constant we include it
6825 in the lwc1 instructions. */
6827 expr1.X_add_number = offset_expr.X_add_number;
6828 offset_expr.X_add_number = 0;
6829 if (expr1.X_add_number < -0x8000
6830 || expr1.X_add_number >= 0x8000 - 4)
6831 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6836 frag_grow (24 + off);
6837 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6838 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6839 macro_build (NULL, &icnt, NULL, "nop", "");
6841 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6843 /* Itbl support may require additional care here. */
6844 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6845 BFD_RELOC_LO16, AT);
6846 expr1.X_add_number += 4;
6848 /* Set mips_optimize to 2 to avoid inserting an undesired
6850 hold_mips_optimize = mips_optimize;
6852 /* Itbl support may require additional care here. */
6853 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6854 BFD_RELOC_LO16, AT);
6855 mips_optimize = hold_mips_optimize;
6857 (void) frag_var (rs_machine_dependent, 0, 0,
6858 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6859 offset_expr.X_add_symbol, 0, NULL);
6861 else if (mips_pic == SVR4_PIC)
6866 /* If this is a reference to an external symbol, we want
6867 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6869 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6874 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6876 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6877 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6878 If there is a base register we add it to $at before the
6879 lwc1 instructions. If there is a constant we include it
6880 in the lwc1 instructions. */
6882 expr1.X_add_number = offset_expr.X_add_number;
6883 offset_expr.X_add_number = 0;
6884 if (expr1.X_add_number < -0x8000
6885 || expr1.X_add_number >= 0x8000 - 4)
6886 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6887 if (reg_needs_delay (mips_gp_register))
6896 macro_build (NULL, &icnt, &offset_expr, "lui", "t,u", AT,
6897 BFD_RELOC_MIPS_GOT_HI16);
6898 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6899 AT, AT, mips_gp_register);
6900 macro_build (NULL, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6901 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
6902 macro_build (NULL, &icnt, NULL, "nop", "");
6904 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6906 /* Itbl support may require additional care here. */
6907 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6908 BFD_RELOC_LO16, AT);
6909 expr1.X_add_number += 4;
6911 /* Set mips_optimize to 2 to avoid inserting an undesired
6913 hold_mips_optimize = mips_optimize;
6915 /* Itbl support may require additional care here. */
6916 macro_build (NULL, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6917 BFD_RELOC_LO16, AT);
6918 mips_optimize = hold_mips_optimize;
6919 expr1.X_add_number -= 4;
6921 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6922 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6923 8 + gpdel + off, 1, 0),
6924 offset_expr.X_add_symbol, 0, NULL);
6927 macro_build (p, &icnt, NULL, "nop", "");
6930 macro_build (p, &icnt, &offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6931 AT, BFD_RELOC_MIPS_GOT16, mips_gp_register);
6933 macro_build (p, &icnt, NULL, "nop", "");
6937 macro_build (p, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6941 /* Itbl support may require additional care here. */
6942 macro_build (p, &icnt, &expr1, s, fmt, coproc ? treg + 1 : treg,
6943 BFD_RELOC_LO16, AT);
6945 expr1.X_add_number += 4;
6947 /* Set mips_optimize to 2 to avoid inserting an undesired
6949 hold_mips_optimize = mips_optimize;
6951 /* Itbl support may require additional care here. */
6952 macro_build (p, &icnt, &expr1, s, fmt, coproc ? treg : treg + 1,
6953 BFD_RELOC_LO16, AT);
6954 mips_optimize = hold_mips_optimize;
6956 else if (mips_pic == EMBEDDED_PIC)
6958 /* If there is no base register, we use
6959 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6960 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6961 If we have a base register, we use
6963 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6964 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6968 tempreg = mips_gp_register;
6973 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
6974 AT, breg, mips_gp_register);
6979 /* Itbl support may require additional care here. */
6980 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6981 coproc ? treg + 1 : treg,
6982 BFD_RELOC_GPREL16, tempreg);
6983 offset_expr.X_add_number += 4;
6984 /* Itbl support may require additional care here. */
6985 macro_build (NULL, &icnt, &offset_expr, s, fmt,
6986 coproc ? treg : treg + 1,
6987 BFD_RELOC_GPREL16, tempreg);
7003 assert (HAVE_32BIT_ADDRESSES);
7004 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7005 BFD_RELOC_LO16, breg);
7006 offset_expr.X_add_number += 4;
7007 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
7008 BFD_RELOC_LO16, breg);
7011 /* New code added to support COPZ instructions.
7012 This code builds table entries out of the macros in mip_opcodes.
7013 R4000 uses interlocks to handle coproc delays.
7014 Other chips (like the R3000) require nops to be inserted for delays.
7016 FIXME: Currently, we require that the user handle delays.
7017 In order to fill delay slots for non-interlocked chips,
7018 we must have a way to specify delays based on the coprocessor.
7019 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
7020 What are the side-effects of the cop instruction?
7021 What cache support might we have and what are its effects?
7022 Both coprocessor & memory require delays. how long???
7023 What registers are read/set/modified?
7025 If an itbl is provided to interpret cop instructions,
7026 this knowledge can be encoded in the itbl spec. */
7040 /* For now we just do C (same as Cz). The parameter will be
7041 stored in insn_opcode by mips_ip. */
7042 macro_build (NULL, &icnt, NULL, s, "C", ip->insn_opcode);
7046 move_register (&icnt, dreg, sreg);
7049 #ifdef LOSING_COMPILER
7051 /* Try and see if this is a new itbl instruction.
7052 This code builds table entries out of the macros in mip_opcodes.
7053 FIXME: For now we just assemble the expression and pass it's
7054 value along as a 32-bit immediate.
7055 We may want to have the assembler assemble this value,
7056 so that we gain the assembler's knowledge of delay slots,
7058 Would it be more efficient to use mask (id) here? */
7059 if (itbl_have_entries
7060 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
7062 s = ip->insn_mo->name;
7064 coproc = ITBL_DECODE_PNUM (immed_expr);;
7065 macro_build (NULL, &icnt, &immed_expr, s, "C");
7072 as_warn (_("Macro used $at after \".set noat\""));
7076 macro2 (struct mips_cl_insn *ip)
7078 register int treg, sreg, dreg, breg;
7094 bfd_reloc_code_real_type r;
7097 treg = (ip->insn_opcode >> 16) & 0x1f;
7098 dreg = (ip->insn_opcode >> 11) & 0x1f;
7099 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
7100 mask = ip->insn_mo->mask;
7102 expr1.X_op = O_constant;
7103 expr1.X_op_symbol = NULL;
7104 expr1.X_add_symbol = NULL;
7105 expr1.X_add_number = 1;
7109 #endif /* LOSING_COMPILER */
7114 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "s,t",
7116 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7122 /* The MIPS assembler some times generates shifts and adds. I'm
7123 not trying to be that fancy. GCC should do this for us
7125 load_register (&icnt, AT, &imm_expr, dbl);
7126 macro_build (NULL, &icnt, NULL, dbl ? "dmult" : "mult", "s,t",
7128 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7141 mips_emit_delays (TRUE);
7142 ++mips_opts.noreorder;
7143 mips_any_noreorder = 1;
7145 load_register (&icnt, AT, &imm_expr, dbl);
7146 macro_build (NULL, &icnt, NULL, dbl ? "dmult" : "mult", "s,t",
7147 sreg, imm ? AT : treg);
7148 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7149 macro_build (NULL, &icnt, NULL, dbl ? "dsra32" : "sra", "d,w,<",
7151 macro_build (NULL, &icnt, NULL, "mfhi", "d", AT);
7153 macro_build (NULL, &icnt, NULL, "tne", "s,t,q", dreg, AT, 6);
7156 expr1.X_add_number = 8;
7157 macro_build (NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
7158 macro_build (NULL, &icnt, NULL, "nop", "", 0);
7159 macro_build (NULL, &icnt, NULL, "break", "c", 6);
7161 --mips_opts.noreorder;
7162 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7175 mips_emit_delays (TRUE);
7176 ++mips_opts.noreorder;
7177 mips_any_noreorder = 1;
7179 load_register (&icnt, AT, &imm_expr, dbl);
7180 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "s,t",
7181 sreg, imm ? AT : treg);
7182 macro_build (NULL, &icnt, NULL, "mfhi", "d", AT);
7183 macro_build (NULL, &icnt, NULL, "mflo", "d", dreg);
7185 macro_build (NULL, &icnt, NULL, "tne", "s,t,q", AT, 0, 6);
7188 expr1.X_add_number = 8;
7189 macro_build (NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
7190 macro_build (NULL, &icnt, NULL, "nop", "", 0);
7191 macro_build (NULL, &icnt, NULL, "break", "c", 6);
7193 --mips_opts.noreorder;
7197 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7209 macro_build (NULL, &icnt, NULL, "dnegu", "d,w", tempreg, treg);
7210 macro_build (NULL, &icnt, NULL, "drorv", "d,t,s", dreg, sreg,
7216 macro_build (NULL, &icnt, NULL, "dsubu", "d,v,t", AT, 0, treg);
7217 macro_build (NULL, &icnt, NULL, "dsrlv", "d,t,s", AT, sreg, AT);
7218 macro_build (NULL, &icnt, NULL, "dsllv", "d,t,s", dreg, sreg, treg);
7219 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7223 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7235 macro_build (NULL, &icnt, NULL, "negu", "d,w", tempreg, treg);
7236 macro_build (NULL, &icnt, NULL, "rorv", "d,t,s", dreg, sreg,
7242 macro_build (NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
7243 macro_build (NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT);
7244 macro_build (NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg, treg);
7245 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7253 if (imm_expr.X_op != O_constant)
7254 as_bad (_("Improper rotate count"));
7255 rot = imm_expr.X_add_number & 0x3f;
7256 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7258 rot = (64 - rot) & 0x3f;
7260 macro_build (NULL, &icnt, NULL, "dror32", "d,w,<",
7261 dreg, sreg, rot - 32);
7263 macro_build (NULL, &icnt, NULL, "dror", "d,w,<",
7269 macro_build (NULL, &icnt, NULL, "dsrl", "d,w,<", dreg, sreg, 0);
7272 l = (rot < 0x20) ? "dsll" : "dsll32";
7273 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
7275 macro_build (NULL, &icnt, NULL, l, "d,w,<", AT, sreg, rot);
7276 macro_build (NULL, &icnt, NULL, r, "d,w,<", dreg, sreg,
7277 (0x20 - rot) & 0x1f);
7278 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7286 if (imm_expr.X_op != O_constant)
7287 as_bad (_("Improper rotate count"));
7288 rot = imm_expr.X_add_number & 0x1f;
7289 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7291 macro_build (NULL, &icnt, NULL, "ror", "d,w,<", dreg, sreg,
7297 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, 0);
7300 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg, rot);
7301 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg,
7302 (0x20 - rot) & 0x1f);
7303 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7308 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7310 macro_build (NULL, &icnt, NULL, "drorv", "d,t,s", dreg, sreg, treg);
7313 macro_build (NULL, &icnt, NULL, "dsubu", "d,v,t", AT, 0, treg);
7314 macro_build (NULL, &icnt, NULL, "dsllv", "d,t,s", AT, sreg, AT);
7315 macro_build (NULL, &icnt, NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
7316 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7320 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7322 macro_build (NULL, &icnt, NULL, "rorv", "d,t,s", dreg, sreg, treg);
7325 macro_build (NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
7326 macro_build (NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT);
7327 macro_build (NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg, treg);
7328 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7336 if (imm_expr.X_op != O_constant)
7337 as_bad (_("Improper rotate count"));
7338 rot = imm_expr.X_add_number & 0x3f;
7339 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7342 macro_build (NULL, &icnt, NULL, "dror32", "d,w,<",
7343 dreg, sreg, rot - 32);
7345 macro_build (NULL, &icnt, NULL, "dror", "d,w,<",
7351 macro_build (NULL, &icnt, NULL, "dsrl", "d,w,<", dreg, sreg, 0);
7354 r = (rot < 0x20) ? "dsrl" : "dsrl32";
7355 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
7357 macro_build (NULL, &icnt, NULL, r, "d,w,<", AT, sreg, rot);
7358 macro_build (NULL, &icnt, NULL, l, "d,w,<", dreg, sreg,
7359 (0x20 - rot) & 0x1f);
7360 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7368 if (imm_expr.X_op != O_constant)
7369 as_bad (_("Improper rotate count"));
7370 rot = imm_expr.X_add_number & 0x1f;
7371 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7373 macro_build (NULL, &icnt, NULL, "ror", "d,w,<", dreg, sreg, rot);
7378 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, 0);
7381 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg, rot);
7382 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg,
7383 (0x20 - rot) & 0x1f);
7384 macro_build (NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
7389 if (mips_opts.arch == CPU_R4650)
7391 as_bad (_("opcode not supported on this processor"));
7394 assert (mips_opts.isa == ISA_MIPS1);
7395 /* Even on a big endian machine $fn comes before $fn+1. We have
7396 to adjust when storing to memory. */
7397 macro_build (NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
7398 target_big_endian ? treg + 1 : treg,
7399 BFD_RELOC_LO16, breg);
7400 offset_expr.X_add_number += 4;
7401 macro_build (NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
7402 target_big_endian ? treg : treg + 1,
7403 BFD_RELOC_LO16, breg);
7408 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, treg,
7411 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, sreg,
7415 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, treg);
7416 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
7422 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7424 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, sreg,
7430 as_warn (_("Instruction %s: result is always false"),
7432 move_register (&icnt, dreg, 0);
7435 if (imm_expr.X_op == O_constant
7436 && imm_expr.X_add_number >= 0
7437 && imm_expr.X_add_number < 0x10000)
7439 macro_build (NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, sreg,
7443 else if (imm_expr.X_op == O_constant
7444 && imm_expr.X_add_number > -0x8000
7445 && imm_expr.X_add_number < 0)
7447 imm_expr.X_add_number = -imm_expr.X_add_number;
7448 macro_build (NULL, &icnt, &imm_expr,
7449 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7450 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7455 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7456 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, AT);
7459 macro_build (NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
7465 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
7471 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg);
7472 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7476 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
7478 if (imm_expr.X_op == O_constant
7479 && imm_expr.X_add_number >= -0x8000
7480 && imm_expr.X_add_number < 0x8000)
7482 macro_build (NULL, &icnt, &imm_expr,
7483 mask == M_SGE_I ? "slti" : "sltiu",
7484 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7489 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7490 macro_build (NULL, &icnt, NULL, mask == M_SGE_I ? "slt" : "sltu",
7491 "d,v,t", dreg, sreg, AT);
7494 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7500 case M_SGT: /* sreg > treg <==> treg < sreg */
7506 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
7509 case M_SGT_I: /* sreg > I <==> I < sreg */
7515 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7516 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
7519 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7525 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
7526 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7530 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7536 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7537 macro_build (NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
7538 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
7543 if (imm_expr.X_op == O_constant
7544 && imm_expr.X_add_number >= -0x8000
7545 && imm_expr.X_add_number < 0x8000)
7547 macro_build (NULL, &icnt, &imm_expr, "slti", "t,r,j", dreg, sreg,
7551 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7552 macro_build (NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT);
7556 if (imm_expr.X_op == O_constant
7557 && imm_expr.X_add_number >= -0x8000
7558 && imm_expr.X_add_number < 0x8000)
7560 macro_build (NULL, &icnt, &imm_expr, "sltiu", "t,r,j", dreg, sreg,
7564 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7565 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg, AT);
7570 macro_build (NULL, &icnt, NULL, "sltu","d,v,t", dreg, 0, treg);
7572 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, sreg);
7575 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, treg);
7576 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
7581 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7583 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, sreg);
7588 as_warn (_("Instruction %s: result is always true"),
7590 macro_build (NULL, &icnt, &expr1,
7591 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7592 "t,r,j", dreg, 0, BFD_RELOC_LO16);
7595 if (imm_expr.X_op == O_constant
7596 && imm_expr.X_add_number >= 0
7597 && imm_expr.X_add_number < 0x10000)
7599 macro_build (NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, sreg,
7603 else if (imm_expr.X_op == O_constant
7604 && imm_expr.X_add_number > -0x8000
7605 && imm_expr.X_add_number < 0)
7607 imm_expr.X_add_number = -imm_expr.X_add_number;
7608 macro_build (NULL, &icnt, &imm_expr,
7609 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7610 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7615 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7616 macro_build (NULL, &icnt, NULL, "xor", "d,v,t", dreg, sreg, AT);
7619 macro_build (NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
7627 if (imm_expr.X_op == O_constant
7628 && imm_expr.X_add_number > -0x8000
7629 && imm_expr.X_add_number <= 0x8000)
7631 imm_expr.X_add_number = -imm_expr.X_add_number;
7632 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddi" : "addi",
7633 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7636 load_register (&icnt, AT, &imm_expr, dbl);
7637 macro_build (NULL, &icnt, NULL, dbl ? "dsub" : "sub", "d,v,t",
7644 if (imm_expr.X_op == O_constant
7645 && imm_expr.X_add_number > -0x8000
7646 && imm_expr.X_add_number <= 0x8000)
7648 imm_expr.X_add_number = -imm_expr.X_add_number;
7649 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddiu" : "addiu",
7650 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7653 load_register (&icnt, AT, &imm_expr, dbl);
7654 macro_build (NULL, &icnt, NULL, dbl ? "dsubu" : "subu", "d,v,t",
7676 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7677 macro_build (NULL, &icnt, NULL, s, "s,t", sreg, AT);
7682 assert (mips_opts.isa == ISA_MIPS1);
7683 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7684 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7687 * Is the double cfc1 instruction a bug in the mips assembler;
7688 * or is there a reason for it?
7690 mips_emit_delays (TRUE);
7691 ++mips_opts.noreorder;
7692 mips_any_noreorder = 1;
7693 macro_build (NULL, &icnt, NULL, "cfc1", "t,G", treg, RA);
7694 macro_build (NULL, &icnt, NULL, "cfc1", "t,G", treg, RA);
7695 macro_build (NULL, &icnt, NULL, "nop", "");
7696 expr1.X_add_number = 3;
7697 macro_build (NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7699 expr1.X_add_number = 2;
7700 macro_build (NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7702 macro_build (NULL, &icnt, NULL, "ctc1", "t,G", AT, RA);
7703 macro_build (NULL, &icnt, NULL, "nop", "");
7704 macro_build (NULL, &icnt, NULL,
7705 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s",
7707 macro_build (NULL, &icnt, NULL, "ctc1", "t,G", treg, RA);
7708 macro_build (NULL, &icnt, NULL, "nop", "");
7709 --mips_opts.noreorder;
7718 if (offset_expr.X_add_number >= 0x7fff)
7719 as_bad (_("operand overflow"));
7720 if (! target_big_endian)
7721 ++offset_expr.X_add_number;
7722 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", AT,
7723 BFD_RELOC_LO16, breg);
7724 if (! target_big_endian)
7725 --offset_expr.X_add_number;
7727 ++offset_expr.X_add_number;
7728 macro_build (NULL, &icnt, &offset_expr, "lbu", "t,o(b)", treg,
7729 BFD_RELOC_LO16, breg);
7730 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", AT, AT, 8);
7731 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7744 if (offset_expr.X_add_number >= 0x8000 - off)
7745 as_bad (_("operand overflow"));
7750 if (! target_big_endian)
7751 offset_expr.X_add_number += off;
7752 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", tempreg,
7753 BFD_RELOC_LO16, breg);
7754 if (! target_big_endian)
7755 offset_expr.X_add_number -= off;
7757 offset_expr.X_add_number += off;
7758 macro_build (NULL, &icnt, &offset_expr, s2, "t,o(b)", tempreg,
7759 BFD_RELOC_LO16, breg);
7761 /* If necessary, move the result in tempreg the final destination. */
7762 if (treg == tempreg)
7764 /* Protect second load's delay slot. */
7765 if (!gpr_interlocks)
7766 macro_build (NULL, &icnt, NULL, "nop", "");
7767 move_register (&icnt, treg, tempreg);
7781 load_address (&icnt, AT, &offset_expr, &used_at);
7783 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7785 if (! target_big_endian)
7786 expr1.X_add_number = off;
7788 expr1.X_add_number = 0;
7789 macro_build (NULL, &icnt, &expr1, s, "t,o(b)", treg,
7790 BFD_RELOC_LO16, AT);
7791 if (! target_big_endian)
7792 expr1.X_add_number = 0;
7794 expr1.X_add_number = off;
7795 macro_build (NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7796 BFD_RELOC_LO16, AT);
7802 load_address (&icnt, AT, &offset_expr, &used_at);
7804 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7806 if (target_big_endian)
7807 expr1.X_add_number = 0;
7808 macro_build (NULL, &icnt, &expr1,
7809 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)",
7810 treg, BFD_RELOC_LO16, AT);
7811 if (target_big_endian)
7812 expr1.X_add_number = 1;
7814 expr1.X_add_number = 0;
7815 macro_build (NULL, &icnt, &expr1, "lbu", "t,o(b)",
7816 AT, BFD_RELOC_LO16, AT);
7817 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
7818 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7822 if (offset_expr.X_add_number >= 0x7fff)
7823 as_bad (_("operand overflow"));
7824 if (target_big_endian)
7825 ++offset_expr.X_add_number;
7826 macro_build (NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7827 BFD_RELOC_LO16, breg);
7828 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8);
7829 if (target_big_endian)
7830 --offset_expr.X_add_number;
7832 ++offset_expr.X_add_number;
7833 macro_build (NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7834 BFD_RELOC_LO16, breg);
7847 if (offset_expr.X_add_number >= 0x8000 - off)
7848 as_bad (_("operand overflow"));
7849 if (! target_big_endian)
7850 offset_expr.X_add_number += off;
7851 macro_build (NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7852 BFD_RELOC_LO16, breg);
7853 if (! target_big_endian)
7854 offset_expr.X_add_number -= off;
7856 offset_expr.X_add_number += off;
7857 macro_build (NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7858 BFD_RELOC_LO16, breg);
7872 load_address (&icnt, AT, &offset_expr, &used_at);
7874 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7876 if (! target_big_endian)
7877 expr1.X_add_number = off;
7879 expr1.X_add_number = 0;
7880 macro_build (NULL, &icnt, &expr1, s, "t,o(b)", treg,
7881 BFD_RELOC_LO16, AT);
7882 if (! target_big_endian)
7883 expr1.X_add_number = 0;
7885 expr1.X_add_number = off;
7886 macro_build (NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7887 BFD_RELOC_LO16, AT);
7892 load_address (&icnt, AT, &offset_expr, &used_at);
7894 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
7896 if (! target_big_endian)
7897 expr1.X_add_number = 0;
7898 macro_build (NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7899 BFD_RELOC_LO16, AT);
7900 macro_build (NULL, &icnt, NULL, "srl", "d,w,<", treg, treg, 8);
7901 if (! target_big_endian)
7902 expr1.X_add_number = 1;
7904 expr1.X_add_number = 0;
7905 macro_build (NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7906 BFD_RELOC_LO16, AT);
7907 if (! target_big_endian)
7908 expr1.X_add_number = 0;
7910 expr1.X_add_number = 1;
7911 macro_build (NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7912 BFD_RELOC_LO16, AT);
7913 macro_build (NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
7914 macro_build (NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
7918 /* FIXME: Check if this is one of the itbl macros, since they
7919 are added dynamically. */
7920 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7924 as_warn (_("Macro used $at after \".set noat\""));
7927 /* Implement macros in mips16 mode. */
7930 mips16_macro (struct mips_cl_insn *ip)
7933 int xreg, yreg, zreg, tmp;
7937 const char *s, *s2, *s3;
7939 mask = ip->insn_mo->mask;
7941 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7942 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7943 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7947 expr1.X_op = O_constant;
7948 expr1.X_op_symbol = NULL;
7949 expr1.X_add_symbol = NULL;
7950 expr1.X_add_number = 1;
7969 mips_emit_delays (TRUE);
7970 ++mips_opts.noreorder;
7971 mips_any_noreorder = 1;
7972 macro_build (NULL, &icnt, NULL, dbl ? "ddiv" : "div", "0,x,y",
7974 expr1.X_add_number = 2;
7975 macro_build (NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7976 macro_build (NULL, &icnt, NULL, "break", "6", 7);
7978 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7979 since that causes an overflow. We should do that as well,
7980 but I don't see how to do the comparisons without a temporary
7982 --mips_opts.noreorder;
7983 macro_build (NULL, &icnt, NULL, s, "x", zreg);
8002 mips_emit_delays (TRUE);
8003 ++mips_opts.noreorder;
8004 mips_any_noreorder = 1;
8005 macro_build (NULL, &icnt, NULL, s, "0,x,y", xreg, yreg);
8006 expr1.X_add_number = 2;
8007 macro_build (NULL, &icnt, &expr1, "bnez", "x,p", yreg);
8008 macro_build (NULL, &icnt, NULL, "break", "6", 7);
8009 --mips_opts.noreorder;
8010 macro_build (NULL, &icnt, NULL, s2, "x", zreg);
8016 macro_build (NULL, &icnt, NULL, dbl ? "dmultu" : "multu", "x,y",
8018 macro_build (NULL, &icnt, NULL, "mflo", "x", zreg);
8026 if (imm_expr.X_op != O_constant)
8027 as_bad (_("Unsupported large constant"));
8028 imm_expr.X_add_number = -imm_expr.X_add_number;
8029 macro_build (NULL, &icnt, &imm_expr, dbl ? "daddiu" : "addiu", "y,x,4",
8034 if (imm_expr.X_op != O_constant)
8035 as_bad (_("Unsupported large constant"));
8036 imm_expr.X_add_number = -imm_expr.X_add_number;
8037 macro_build (NULL, &icnt, &imm_expr, "addiu", "x,k", xreg);
8041 if (imm_expr.X_op != O_constant)
8042 as_bad (_("Unsupported large constant"));
8043 imm_expr.X_add_number = -imm_expr.X_add_number;
8044 macro_build (NULL, &icnt, &imm_expr, "daddiu", "y,j", yreg);
8066 goto do_reverse_branch;
8070 goto do_reverse_branch;
8082 goto do_reverse_branch;
8093 macro_build (NULL, &icnt, NULL, s, "x,y", xreg, yreg);
8094 macro_build (NULL, &icnt, &offset_expr, s2, "p");
8121 goto do_addone_branch_i;
8126 goto do_addone_branch_i;
8141 goto do_addone_branch_i;
8148 if (imm_expr.X_op != O_constant)
8149 as_bad (_("Unsupported large constant"));
8150 ++imm_expr.X_add_number;
8153 macro_build (NULL, &icnt, &imm_expr, s, s3, xreg);
8154 macro_build (NULL, &icnt, &offset_expr, s2, "p");
8158 expr1.X_add_number = 0;
8159 macro_build (NULL, &icnt, &expr1, "slti", "x,8", yreg);
8161 move_register (&icnt, xreg, yreg);
8162 expr1.X_add_number = 2;
8163 macro_build (NULL, &icnt, &expr1, "bteqz", "p");
8164 macro_build (NULL, &icnt, NULL, "neg", "x,w", xreg, xreg);
8168 /* For consistency checking, verify that all bits are specified either
8169 by the match/mask part of the instruction definition, or by the
8172 validate_mips_insn (const struct mips_opcode *opc)
8174 const char *p = opc->args;
8176 unsigned long used_bits = opc->mask;
8178 if ((used_bits & opc->match) != opc->match)
8180 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
8181 opc->name, opc->args);
8184 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
8194 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8195 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
8196 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8197 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
8198 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8199 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8200 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
8201 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8202 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8205 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8206 c, opc->name, opc->args);
8210 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8211 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8213 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
8214 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
8215 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8216 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8218 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8219 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8221 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
8222 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8224 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
8225 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
8226 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
8227 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
8228 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8229 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
8230 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8231 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8232 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8233 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8234 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8235 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8236 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8237 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
8238 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8239 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
8240 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8242 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
8243 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8244 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8245 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
8247 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8248 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8249 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
8250 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8251 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8252 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8253 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8254 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8255 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8258 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
8259 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
8260 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8261 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
8262 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
8266 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
8267 c, opc->name, opc->args);
8271 if (used_bits != 0xffffffff)
8273 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
8274 ~used_bits & 0xffffffff, opc->name, opc->args);
8280 /* This routine assembles an instruction into its binary format. As a
8281 side effect, it sets one of the global variables imm_reloc or
8282 offset_reloc to the type of relocation to do if one of the operands
8283 is an address expression. */
8286 mips_ip (char *str, struct mips_cl_insn *ip)
8291 struct mips_opcode *insn;
8294 unsigned int lastregno = 0;
8295 unsigned int lastpos = 0;
8296 unsigned int limlo, limhi;
8302 /* If the instruction contains a '.', we first try to match an instruction
8303 including the '.'. Then we try again without the '.'. */
8305 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
8308 /* If we stopped on whitespace, then replace the whitespace with null for
8309 the call to hash_find. Save the character we replaced just in case we
8310 have to re-parse the instruction. */
8317 insn = (struct mips_opcode *) hash_find (op_hash, str);
8319 /* If we didn't find the instruction in the opcode table, try again, but
8320 this time with just the instruction up to, but not including the
8324 /* Restore the character we overwrite above (if any). */
8328 /* Scan up to the first '.' or whitespace. */
8330 *s != '\0' && *s != '.' && !ISSPACE (*s);
8334 /* If we did not find a '.', then we can quit now. */
8337 insn_error = "unrecognized opcode";
8341 /* Lookup the instruction in the hash table. */
8343 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
8345 insn_error = "unrecognized opcode";
8355 assert (strcmp (insn->name, str) == 0);
8357 if (OPCODE_IS_MEMBER (insn,
8359 | (file_ase_mips16 ? INSN_MIPS16 : 0)
8360 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
8361 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
8367 if (insn->pinfo != INSN_MACRO)
8369 if (mips_opts.arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
8375 if (insn + 1 < &mips_opcodes[NUMOPCODES]
8376 && strcmp (insn->name, insn[1].name) == 0)
8385 static char buf[100];
8387 _("opcode not supported on this processor: %s (%s)"),
8388 mips_cpu_info_from_arch (mips_opts.arch)->name,
8389 mips_cpu_info_from_isa (mips_opts.isa)->name);
8399 ip->insn_opcode = insn->match;
8401 for (args = insn->args;; ++args)
8405 s += strspn (s, " \t");
8409 case '\0': /* end of args */
8422 ip->insn_opcode |= lastregno << OP_SH_RS;
8426 ip->insn_opcode |= lastregno << OP_SH_RT;
8430 ip->insn_opcode |= lastregno << OP_SH_FT;
8434 ip->insn_opcode |= lastregno << OP_SH_FS;
8440 /* Handle optional base register.
8441 Either the base register is omitted or
8442 we must have a left paren. */
8443 /* This is dependent on the next operand specifier
8444 is a base register specification. */
8445 assert (args[1] == 'b' || args[1] == '5'
8446 || args[1] == '-' || args[1] == '4');
8450 case ')': /* these must match exactly */
8457 case '+': /* Opcode extension character. */
8460 case 'A': /* ins/ext position, becomes LSB. */
8469 my_getExpression (&imm_expr, s);
8470 check_absolute_expr (ip, &imm_expr);
8471 if ((unsigned long) imm_expr.X_add_number < limlo
8472 || (unsigned long) imm_expr.X_add_number > limhi)
8474 as_bad (_("Improper position (%lu)"),
8475 (unsigned long) imm_expr.X_add_number);
8476 imm_expr.X_add_number = limlo;
8478 lastpos = imm_expr.X_add_number;
8479 ip->insn_opcode |= (imm_expr.X_add_number
8480 & OP_MASK_SHAMT) << OP_SH_SHAMT;
8481 imm_expr.X_op = O_absent;
8485 case 'B': /* ins size, becomes MSB. */
8494 my_getExpression (&imm_expr, s);
8495 check_absolute_expr (ip, &imm_expr);
8496 /* Check for negative input so that small negative numbers
8497 will not succeed incorrectly. The checks against
8498 (pos+size) transitively check "size" itself,
8499 assuming that "pos" is reasonable. */
8500 if ((long) imm_expr.X_add_number < 0
8501 || ((unsigned long) imm_expr.X_add_number
8503 || ((unsigned long) imm_expr.X_add_number
8506 as_bad (_("Improper insert size (%lu, position %lu)"),
8507 (unsigned long) imm_expr.X_add_number,
8508 (unsigned long) lastpos);
8509 imm_expr.X_add_number = limlo - lastpos;
8511 ip->insn_opcode |= ((lastpos + imm_expr.X_add_number - 1)
8512 & OP_MASK_INSMSB) << OP_SH_INSMSB;
8513 imm_expr.X_op = O_absent;
8517 case 'C': /* ext size, becomes MSBD. */
8530 my_getExpression (&imm_expr, s);
8531 check_absolute_expr (ip, &imm_expr);
8532 /* Check for negative input so that small negative numbers
8533 will not succeed incorrectly. The checks against
8534 (pos+size) transitively check "size" itself,
8535 assuming that "pos" is reasonable. */
8536 if ((long) imm_expr.X_add_number < 0
8537 || ((unsigned long) imm_expr.X_add_number
8539 || ((unsigned long) imm_expr.X_add_number
8542 as_bad (_("Improper extract size (%lu, position %lu)"),
8543 (unsigned long) imm_expr.X_add_number,
8544 (unsigned long) lastpos);
8545 imm_expr.X_add_number = limlo - lastpos;
8547 ip->insn_opcode |= ((imm_expr.X_add_number - 1)
8548 & OP_MASK_EXTMSBD) << OP_SH_EXTMSBD;
8549 imm_expr.X_op = O_absent;
8554 /* +D is for disassembly only; never match. */
8558 /* "+I" is like "I", except that imm2_expr is used. */
8559 my_getExpression (&imm2_expr, s);
8560 if (imm2_expr.X_op != O_big
8561 && imm2_expr.X_op != O_constant)
8562 insn_error = _("absolute expression required");
8563 normalize_constant_expr (&imm2_expr);
8568 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8569 *args, insn->name, insn->args);
8570 /* Further processing is fruitless. */
8575 case '<': /* must be at least one digit */
8577 * According to the manual, if the shift amount is greater
8578 * than 31 or less than 0, then the shift amount should be
8579 * mod 32. In reality the mips assembler issues an error.
8580 * We issue a warning and mask out all but the low 5 bits.
8582 my_getExpression (&imm_expr, s);
8583 check_absolute_expr (ip, &imm_expr);
8584 if ((unsigned long) imm_expr.X_add_number > 31)
8586 as_warn (_("Improper shift amount (%lu)"),
8587 (unsigned long) imm_expr.X_add_number);
8588 imm_expr.X_add_number &= OP_MASK_SHAMT;
8590 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
8591 imm_expr.X_op = O_absent;
8595 case '>': /* shift amount minus 32 */
8596 my_getExpression (&imm_expr, s);
8597 check_absolute_expr (ip, &imm_expr);
8598 if ((unsigned long) imm_expr.X_add_number < 32
8599 || (unsigned long) imm_expr.X_add_number > 63)
8601 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
8602 imm_expr.X_op = O_absent;
8606 case 'k': /* cache code */
8607 case 'h': /* prefx code */
8608 my_getExpression (&imm_expr, s);
8609 check_absolute_expr (ip, &imm_expr);
8610 if ((unsigned long) imm_expr.X_add_number > 31)
8612 as_warn (_("Invalid value for `%s' (%lu)"),
8614 (unsigned long) imm_expr.X_add_number);
8615 imm_expr.X_add_number &= 0x1f;
8618 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
8620 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
8621 imm_expr.X_op = O_absent;
8625 case 'c': /* break code */
8626 my_getExpression (&imm_expr, s);
8627 check_absolute_expr (ip, &imm_expr);
8628 if ((unsigned long) imm_expr.X_add_number > 1023)
8630 as_warn (_("Illegal break code (%lu)"),
8631 (unsigned long) imm_expr.X_add_number);
8632 imm_expr.X_add_number &= OP_MASK_CODE;
8634 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
8635 imm_expr.X_op = O_absent;
8639 case 'q': /* lower break code */
8640 my_getExpression (&imm_expr, s);
8641 check_absolute_expr (ip, &imm_expr);
8642 if ((unsigned long) imm_expr.X_add_number > 1023)
8644 as_warn (_("Illegal lower break code (%lu)"),
8645 (unsigned long) imm_expr.X_add_number);
8646 imm_expr.X_add_number &= OP_MASK_CODE2;
8648 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
8649 imm_expr.X_op = O_absent;
8653 case 'B': /* 20-bit syscall/break code. */
8654 my_getExpression (&imm_expr, s);
8655 check_absolute_expr (ip, &imm_expr);
8656 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
8657 as_warn (_("Illegal 20-bit code (%lu)"),
8658 (unsigned long) imm_expr.X_add_number);
8659 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
8660 imm_expr.X_op = O_absent;
8664 case 'C': /* Coprocessor code */
8665 my_getExpression (&imm_expr, s);
8666 check_absolute_expr (ip, &imm_expr);
8667 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
8669 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8670 (unsigned long) imm_expr.X_add_number);
8671 imm_expr.X_add_number &= ((1 << 25) - 1);
8673 ip->insn_opcode |= imm_expr.X_add_number;
8674 imm_expr.X_op = O_absent;
8678 case 'J': /* 19-bit wait code. */
8679 my_getExpression (&imm_expr, s);
8680 check_absolute_expr (ip, &imm_expr);
8681 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
8682 as_warn (_("Illegal 19-bit code (%lu)"),
8683 (unsigned long) imm_expr.X_add_number);
8684 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
8685 imm_expr.X_op = O_absent;
8689 case 'P': /* Performance register */
8690 my_getExpression (&imm_expr, s);
8691 check_absolute_expr (ip, &imm_expr);
8692 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
8694 as_warn (_("Invalid performance register (%lu)"),
8695 (unsigned long) imm_expr.X_add_number);
8696 imm_expr.X_add_number &= OP_MASK_PERFREG;
8698 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
8699 imm_expr.X_op = O_absent;
8703 case 'b': /* base register */
8704 case 'd': /* destination register */
8705 case 's': /* source register */
8706 case 't': /* target register */
8707 case 'r': /* both target and source */
8708 case 'v': /* both dest and source */
8709 case 'w': /* both dest and target */
8710 case 'E': /* coprocessor target register */
8711 case 'G': /* coprocessor destination register */
8712 case 'K': /* 'rdhwr' destination register */
8713 case 'x': /* ignore register name */
8714 case 'z': /* must be zero register */
8715 case 'U': /* destination register (clo/clz). */
8730 while (ISDIGIT (*s));
8732 as_bad (_("Invalid register number (%d)"), regno);
8734 else if (*args == 'E' || *args == 'G' || *args == 'K')
8738 if (s[1] == 'r' && s[2] == 'a')
8743 else if (s[1] == 'f' && s[2] == 'p')
8748 else if (s[1] == 's' && s[2] == 'p')
8753 else if (s[1] == 'g' && s[2] == 'p')
8758 else if (s[1] == 'a' && s[2] == 't')
8763 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8768 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8773 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8778 else if (itbl_have_entries)
8783 p = s + 1; /* advance past '$' */
8784 n = itbl_get_field (&p); /* n is name */
8786 /* See if this is a register defined in an
8788 if (itbl_get_reg_val (n, &r))
8790 /* Get_field advances to the start of
8791 the next field, so we need to back
8792 rack to the end of the last field. */
8796 s = strchr (s, '\0');
8810 as_warn (_("Used $at without \".set noat\""));
8816 if (c == 'r' || c == 'v' || c == 'w')
8823 /* 'z' only matches $0. */
8824 if (c == 'z' && regno != 0)
8827 /* Now that we have assembled one operand, we use the args string
8828 * to figure out where it goes in the instruction. */
8835 ip->insn_opcode |= regno << OP_SH_RS;
8840 ip->insn_opcode |= regno << OP_SH_RD;
8843 ip->insn_opcode |= regno << OP_SH_RD;
8844 ip->insn_opcode |= regno << OP_SH_RT;
8849 ip->insn_opcode |= regno << OP_SH_RT;
8852 /* This case exists because on the r3000 trunc
8853 expands into a macro which requires a gp
8854 register. On the r6000 or r4000 it is
8855 assembled into a single instruction which
8856 ignores the register. Thus the insn version
8857 is MIPS_ISA2 and uses 'x', and the macro
8858 version is MIPS_ISA1 and uses 't'. */
8861 /* This case is for the div instruction, which
8862 acts differently if the destination argument
8863 is $0. This only matches $0, and is checked
8864 outside the switch. */
8867 /* Itbl operand; not yet implemented. FIXME ?? */
8869 /* What about all other operands like 'i', which
8870 can be specified in the opcode table? */
8880 ip->insn_opcode |= lastregno << OP_SH_RS;
8883 ip->insn_opcode |= lastregno << OP_SH_RT;
8888 case 'O': /* MDMX alignment immediate constant. */
8889 my_getExpression (&imm_expr, s);
8890 check_absolute_expr (ip, &imm_expr);
8891 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
8893 as_warn ("Improper align amount (%ld), using low bits",
8894 (long) imm_expr.X_add_number);
8895 imm_expr.X_add_number &= OP_MASK_ALN;
8897 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_ALN;
8898 imm_expr.X_op = O_absent;
8902 case 'Q': /* MDMX vector, element sel, or const. */
8905 /* MDMX Immediate. */
8906 my_getExpression (&imm_expr, s);
8907 check_absolute_expr (ip, &imm_expr);
8908 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
8910 as_warn (_("Invalid MDMX Immediate (%ld)"),
8911 (long) imm_expr.X_add_number);
8912 imm_expr.X_add_number &= OP_MASK_FT;
8914 imm_expr.X_add_number &= OP_MASK_FT;
8915 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8916 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
8918 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
8919 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_FT;
8920 imm_expr.X_op = O_absent;
8924 /* Not MDMX Immediate. Fall through. */
8925 case 'X': /* MDMX destination register. */
8926 case 'Y': /* MDMX source register. */
8927 case 'Z': /* MDMX target register. */
8929 case 'D': /* floating point destination register */
8930 case 'S': /* floating point source register */
8931 case 'T': /* floating point target register */
8932 case 'R': /* floating point source register */
8936 /* Accept $fN for FP and MDMX register numbers, and in
8937 addition accept $vN for MDMX register numbers. */
8938 if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2]))
8939 || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v'
8950 while (ISDIGIT (*s));
8953 as_bad (_("Invalid float register number (%d)"), regno);
8955 if ((regno & 1) != 0
8957 && ! (strcmp (str, "mtc1") == 0
8958 || strcmp (str, "mfc1") == 0
8959 || strcmp (str, "lwc1") == 0
8960 || strcmp (str, "swc1") == 0
8961 || strcmp (str, "l.s") == 0
8962 || strcmp (str, "s.s") == 0))
8963 as_warn (_("Float register should be even, was %d"),
8971 if (c == 'V' || c == 'W')
8982 ip->insn_opcode |= regno << OP_SH_FD;
8987 ip->insn_opcode |= regno << OP_SH_FS;
8990 /* This is like 'Z', but also needs to fix the MDMX
8991 vector/scalar select bits. Note that the
8992 scalar immediate case is handled above. */
8995 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
8996 int max_el = (is_qh ? 3 : 7);
8998 my_getExpression(&imm_expr, s);
8999 check_absolute_expr (ip, &imm_expr);
9001 if (imm_expr.X_add_number > max_el)
9002 as_bad(_("Bad element selector %ld"),
9003 (long) imm_expr.X_add_number);
9004 imm_expr.X_add_number &= max_el;
9005 ip->insn_opcode |= (imm_expr.X_add_number
9009 as_warn(_("Expecting ']' found '%s'"), s);
9015 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
9016 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
9019 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
9026 ip->insn_opcode |= regno << OP_SH_FT;
9029 ip->insn_opcode |= regno << OP_SH_FR;
9039 ip->insn_opcode |= lastregno << OP_SH_FS;
9042 ip->insn_opcode |= lastregno << OP_SH_FT;
9048 my_getExpression (&imm_expr, s);
9049 if (imm_expr.X_op != O_big
9050 && imm_expr.X_op != O_constant)
9051 insn_error = _("absolute expression required");
9052 normalize_constant_expr (&imm_expr);
9057 my_getExpression (&offset_expr, s);
9058 *imm_reloc = BFD_RELOC_32;
9071 unsigned char temp[8];
9073 unsigned int length;
9078 /* These only appear as the last operand in an
9079 instruction, and every instruction that accepts
9080 them in any variant accepts them in all variants.
9081 This means we don't have to worry about backing out
9082 any changes if the instruction does not match.
9084 The difference between them is the size of the
9085 floating point constant and where it goes. For 'F'
9086 and 'L' the constant is 64 bits; for 'f' and 'l' it
9087 is 32 bits. Where the constant is placed is based
9088 on how the MIPS assembler does things:
9091 f -- immediate value
9094 The .lit4 and .lit8 sections are only used if
9095 permitted by the -G argument.
9097 When generating embedded PIC code, we use the
9098 .lit8 section but not the .lit4 section (we can do
9099 .lit4 inline easily; we need to put .lit8
9100 somewhere in the data segment, and using .lit8
9101 permits the linker to eventually combine identical
9104 The code below needs to know whether the target register
9105 is 32 or 64 bits wide. It relies on the fact 'f' and
9106 'F' are used with GPR-based instructions and 'l' and
9107 'L' are used with FPR-based instructions. */
9109 f64 = *args == 'F' || *args == 'L';
9110 using_gprs = *args == 'F' || *args == 'f';
9112 save_in = input_line_pointer;
9113 input_line_pointer = s;
9114 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
9116 s = input_line_pointer;
9117 input_line_pointer = save_in;
9118 if (err != NULL && *err != '\0')
9120 as_bad (_("Bad floating point constant: %s"), err);
9121 memset (temp, '\0', sizeof temp);
9122 length = f64 ? 8 : 4;
9125 assert (length == (unsigned) (f64 ? 8 : 4));
9129 && (! USE_GLOBAL_POINTER_OPT
9130 || mips_pic == EMBEDDED_PIC
9131 || g_switch_value < 4
9132 || (temp[0] == 0 && temp[1] == 0)
9133 || (temp[2] == 0 && temp[3] == 0))))
9135 imm_expr.X_op = O_constant;
9136 if (! target_big_endian)
9137 imm_expr.X_add_number = bfd_getl32 (temp);
9139 imm_expr.X_add_number = bfd_getb32 (temp);
9142 && ! mips_disable_float_construction
9143 /* Constants can only be constructed in GPRs and
9144 copied to FPRs if the GPRs are at least as wide
9145 as the FPRs. Force the constant into memory if
9146 we are using 64-bit FPRs but the GPRs are only
9149 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
9150 && ((temp[0] == 0 && temp[1] == 0)
9151 || (temp[2] == 0 && temp[3] == 0))
9152 && ((temp[4] == 0 && temp[5] == 0)
9153 || (temp[6] == 0 && temp[7] == 0)))
9155 /* The value is simple enough to load with a couple of
9156 instructions. If using 32-bit registers, set
9157 imm_expr to the high order 32 bits and offset_expr to
9158 the low order 32 bits. Otherwise, set imm_expr to
9159 the entire 64 bit constant. */
9160 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
9162 imm_expr.X_op = O_constant;
9163 offset_expr.X_op = O_constant;
9164 if (! target_big_endian)
9166 imm_expr.X_add_number = bfd_getl32 (temp + 4);
9167 offset_expr.X_add_number = bfd_getl32 (temp);
9171 imm_expr.X_add_number = bfd_getb32 (temp);
9172 offset_expr.X_add_number = bfd_getb32 (temp + 4);
9174 if (offset_expr.X_add_number == 0)
9175 offset_expr.X_op = O_absent;
9177 else if (sizeof (imm_expr.X_add_number) > 4)
9179 imm_expr.X_op = O_constant;
9180 if (! target_big_endian)
9181 imm_expr.X_add_number = bfd_getl64 (temp);
9183 imm_expr.X_add_number = bfd_getb64 (temp);
9187 imm_expr.X_op = O_big;
9188 imm_expr.X_add_number = 4;
9189 if (! target_big_endian)
9191 generic_bignum[0] = bfd_getl16 (temp);
9192 generic_bignum[1] = bfd_getl16 (temp + 2);
9193 generic_bignum[2] = bfd_getl16 (temp + 4);
9194 generic_bignum[3] = bfd_getl16 (temp + 6);
9198 generic_bignum[0] = bfd_getb16 (temp + 6);
9199 generic_bignum[1] = bfd_getb16 (temp + 4);
9200 generic_bignum[2] = bfd_getb16 (temp + 2);
9201 generic_bignum[3] = bfd_getb16 (temp);
9207 const char *newname;
9210 /* Switch to the right section. */
9212 subseg = now_subseg;
9215 default: /* unused default case avoids warnings. */
9217 newname = RDATA_SECTION_NAME;
9218 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
9219 || mips_pic == EMBEDDED_PIC)
9223 if (mips_pic == EMBEDDED_PIC)
9226 newname = RDATA_SECTION_NAME;
9229 assert (!USE_GLOBAL_POINTER_OPT
9230 || g_switch_value >= 4);
9234 new_seg = subseg_new (newname, (subsegT) 0);
9235 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
9236 bfd_set_section_flags (stdoutput, new_seg,
9241 frag_align (*args == 'l' ? 2 : 3, 0, 0);
9242 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9243 && strcmp (TARGET_OS, "elf") != 0)
9244 record_alignment (new_seg, 4);
9246 record_alignment (new_seg, *args == 'l' ? 2 : 3);
9248 as_bad (_("Can't use floating point insn in this section"));
9250 /* Set the argument to the current address in the
9252 offset_expr.X_op = O_symbol;
9253 offset_expr.X_add_symbol =
9254 symbol_new ("L0\001", now_seg,
9255 (valueT) frag_now_fix (), frag_now);
9256 offset_expr.X_add_number = 0;
9258 /* Put the floating point number into the section. */
9259 p = frag_more ((int) length);
9260 memcpy (p, temp, length);
9262 /* Switch back to the original section. */
9263 subseg_set (seg, subseg);
9268 case 'i': /* 16 bit unsigned immediate */
9269 case 'j': /* 16 bit signed immediate */
9270 *imm_reloc = BFD_RELOC_LO16;
9271 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
9274 offsetT minval, maxval;
9276 more = (insn + 1 < &mips_opcodes[NUMOPCODES]
9277 && strcmp (insn->name, insn[1].name) == 0);
9279 /* If the expression was written as an unsigned number,
9280 only treat it as signed if there are no more
9284 && sizeof (imm_expr.X_add_number) <= 4
9285 && imm_expr.X_op == O_constant
9286 && imm_expr.X_add_number < 0
9287 && imm_expr.X_unsigned
9291 /* For compatibility with older assemblers, we accept
9292 0x8000-0xffff as signed 16-bit numbers when only
9293 signed numbers are allowed. */
9295 minval = 0, maxval = 0xffff;
9297 minval = -0x8000, maxval = 0x7fff;
9299 minval = -0x8000, maxval = 0xffff;
9301 if (imm_expr.X_op != O_constant
9302 || imm_expr.X_add_number < minval
9303 || imm_expr.X_add_number > maxval)
9307 if (imm_expr.X_op == O_constant
9308 || imm_expr.X_op == O_big)
9309 as_bad (_("expression out of range"));
9315 case 'o': /* 16 bit offset */
9316 /* Check whether there is only a single bracketed expression
9317 left. If so, it must be the base register and the
9318 constant must be zero. */
9319 if (*s == '(' && strchr (s + 1, '(') == 0)
9321 offset_expr.X_op = O_constant;
9322 offset_expr.X_add_number = 0;
9326 /* If this value won't fit into a 16 bit offset, then go
9327 find a macro that will generate the 32 bit offset
9329 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
9330 && (offset_expr.X_op != O_constant
9331 || offset_expr.X_add_number >= 0x8000
9332 || offset_expr.X_add_number < -0x8000))
9338 case 'p': /* pc relative offset */
9339 *offset_reloc = BFD_RELOC_16_PCREL_S2;
9340 my_getExpression (&offset_expr, s);
9344 case 'u': /* upper 16 bits */
9345 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
9346 && imm_expr.X_op == O_constant
9347 && (imm_expr.X_add_number < 0
9348 || imm_expr.X_add_number >= 0x10000))
9349 as_bad (_("lui expression not in range 0..65535"));
9353 case 'a': /* 26 bit address */
9354 my_getExpression (&offset_expr, s);
9356 *offset_reloc = BFD_RELOC_MIPS_JMP;
9359 case 'N': /* 3 bit branch condition code */
9360 case 'M': /* 3 bit compare condition code */
9361 if (strncmp (s, "$fcc", 4) != 0)
9371 while (ISDIGIT (*s));
9373 as_bad (_("Invalid condition code register $fcc%d"), regno);
9374 if ((strcmp(str + strlen(str) - 3, ".ps") == 0
9375 || strcmp(str + strlen(str) - 5, "any2f") == 0
9376 || strcmp(str + strlen(str) - 5, "any2t") == 0)
9377 && (regno & 1) != 0)
9378 as_warn(_("Condition code register should be even for %s, was %d"),
9380 if ((strcmp(str + strlen(str) - 5, "any4f") == 0
9381 || strcmp(str + strlen(str) - 5, "any4t") == 0)
9382 && (regno & 3) != 0)
9383 as_warn(_("Condition code register should be 0 or 4 for %s, was %d"),
9386 ip->insn_opcode |= regno << OP_SH_BCC;
9388 ip->insn_opcode |= regno << OP_SH_CCC;
9392 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
9403 while (ISDIGIT (*s));
9406 c = 8; /* Invalid sel value. */
9409 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9410 ip->insn_opcode |= c;
9414 /* Must be at least one digit. */
9415 my_getExpression (&imm_expr, s);
9416 check_absolute_expr (ip, &imm_expr);
9418 if ((unsigned long) imm_expr.X_add_number
9419 > (unsigned long) OP_MASK_VECBYTE)
9421 as_bad (_("bad byte vector index (%ld)"),
9422 (long) imm_expr.X_add_number);
9423 imm_expr.X_add_number = 0;
9426 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECBYTE;
9427 imm_expr.X_op = O_absent;
9432 my_getExpression (&imm_expr, s);
9433 check_absolute_expr (ip, &imm_expr);
9435 if ((unsigned long) imm_expr.X_add_number
9436 > (unsigned long) OP_MASK_VECALIGN)
9438 as_bad (_("bad byte vector index (%ld)"),
9439 (long) imm_expr.X_add_number);
9440 imm_expr.X_add_number = 0;
9443 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECALIGN;
9444 imm_expr.X_op = O_absent;
9449 as_bad (_("bad char = '%c'\n"), *args);
9454 /* Args don't match. */
9455 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
9456 !strcmp (insn->name, insn[1].name))
9460 insn_error = _("illegal operands");
9465 insn_error = _("illegal operands");
9470 /* This routine assembles an instruction into its binary format when
9471 assembling for the mips16. As a side effect, it sets one of the
9472 global variables imm_reloc or offset_reloc to the type of
9473 relocation to do if one of the operands is an address expression.
9474 It also sets mips16_small and mips16_ext if the user explicitly
9475 requested a small or extended instruction. */
9478 mips16_ip (char *str, struct mips_cl_insn *ip)
9482 struct mips_opcode *insn;
9485 unsigned int lastregno = 0;
9490 mips16_small = FALSE;
9493 for (s = str; ISLOWER (*s); ++s)
9505 if (s[1] == 't' && s[2] == ' ')
9508 mips16_small = TRUE;
9512 else if (s[1] == 'e' && s[2] == ' ')
9521 insn_error = _("unknown opcode");
9525 if (mips_opts.noautoextend && ! mips16_ext)
9526 mips16_small = TRUE;
9528 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
9530 insn_error = _("unrecognized opcode");
9537 assert (strcmp (insn->name, str) == 0);
9540 ip->insn_opcode = insn->match;
9541 ip->use_extend = FALSE;
9542 imm_expr.X_op = O_absent;
9543 imm_reloc[0] = BFD_RELOC_UNUSED;
9544 imm_reloc[1] = BFD_RELOC_UNUSED;
9545 imm_reloc[2] = BFD_RELOC_UNUSED;
9546 imm2_expr.X_op = O_absent;
9547 offset_expr.X_op = O_absent;
9548 offset_reloc[0] = BFD_RELOC_UNUSED;
9549 offset_reloc[1] = BFD_RELOC_UNUSED;
9550 offset_reloc[2] = BFD_RELOC_UNUSED;
9551 for (args = insn->args; 1; ++args)
9558 /* In this switch statement we call break if we did not find
9559 a match, continue if we did find a match, or return if we
9568 /* Stuff the immediate value in now, if we can. */
9569 if (imm_expr.X_op == O_constant
9570 && *imm_reloc > BFD_RELOC_UNUSED
9571 && insn->pinfo != INSN_MACRO)
9573 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
9574 imm_expr.X_add_number, TRUE, mips16_small,
9575 mips16_ext, &ip->insn_opcode,
9576 &ip->use_extend, &ip->extend);
9577 imm_expr.X_op = O_absent;
9578 *imm_reloc = BFD_RELOC_UNUSED;
9592 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9595 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9611 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9613 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9640 while (ISDIGIT (*s));
9643 as_bad (_("invalid register number (%d)"), regno);
9649 if (s[1] == 'r' && s[2] == 'a')
9654 else if (s[1] == 'f' && s[2] == 'p')
9659 else if (s[1] == 's' && s[2] == 'p')
9664 else if (s[1] == 'g' && s[2] == 'p')
9669 else if (s[1] == 'a' && s[2] == 't')
9674 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
9679 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
9684 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
9697 if (c == 'v' || c == 'w')
9699 regno = mips16_to_32_reg_map[lastregno];
9713 regno = mips32_to_16_reg_map[regno];
9718 regno = ILLEGAL_REG;
9723 regno = ILLEGAL_REG;
9728 regno = ILLEGAL_REG;
9733 if (regno == AT && ! mips_opts.noat)
9734 as_warn (_("used $at without \".set noat\""));
9741 if (regno == ILLEGAL_REG)
9748 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
9752 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
9755 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
9758 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
9764 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
9767 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9768 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
9778 if (strncmp (s, "$pc", 3) == 0)
9802 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
9804 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9805 and generate the appropriate reloc. If the text
9806 inside %gprel is not a symbol name with an
9807 optional offset, then we generate a normal reloc
9808 and will probably fail later. */
9809 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
9810 if (imm_expr.X_op == O_symbol)
9813 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
9815 ip->use_extend = TRUE;
9822 /* Just pick up a normal expression. */
9823 my_getExpression (&imm_expr, s);
9826 if (imm_expr.X_op == O_register)
9828 /* What we thought was an expression turned out to
9831 if (s[0] == '(' && args[1] == '(')
9833 /* It looks like the expression was omitted
9834 before a register indirection, which means
9835 that the expression is implicitly zero. We
9836 still set up imm_expr, so that we handle
9837 explicit extensions correctly. */
9838 imm_expr.X_op = O_constant;
9839 imm_expr.X_add_number = 0;
9840 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9847 /* We need to relax this instruction. */
9848 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9857 /* We use offset_reloc rather than imm_reloc for the PC
9858 relative operands. This lets macros with both
9859 immediate and address operands work correctly. */
9860 my_getExpression (&offset_expr, s);
9862 if (offset_expr.X_op == O_register)
9865 /* We need to relax this instruction. */
9866 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9870 case '6': /* break code */
9871 my_getExpression (&imm_expr, s);
9872 check_absolute_expr (ip, &imm_expr);
9873 if ((unsigned long) imm_expr.X_add_number > 63)
9875 as_warn (_("Invalid value for `%s' (%lu)"),
9877 (unsigned long) imm_expr.X_add_number);
9878 imm_expr.X_add_number &= 0x3f;
9880 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9881 imm_expr.X_op = O_absent;
9885 case 'a': /* 26 bit address */
9886 my_getExpression (&offset_expr, s);
9888 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9889 ip->insn_opcode <<= 16;
9892 case 'l': /* register list for entry macro */
9893 case 'L': /* register list for exit macro */
9903 int freg, reg1, reg2;
9905 while (*s == ' ' || *s == ',')
9909 as_bad (_("can't parse register list"));
9921 while (ISDIGIT (*s))
9943 as_bad (_("invalid register list"));
9948 while (ISDIGIT (*s))
9955 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9960 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9965 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9966 mask |= (reg2 - 3) << 3;
9967 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9968 mask |= (reg2 - 15) << 1;
9969 else if (reg1 == RA && reg2 == RA)
9973 as_bad (_("invalid register list"));
9977 /* The mask is filled in in the opcode table for the
9978 benefit of the disassembler. We remove it before
9979 applying the actual mask. */
9980 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9981 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9985 case 'e': /* extend code */
9986 my_getExpression (&imm_expr, s);
9987 check_absolute_expr (ip, &imm_expr);
9988 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9990 as_warn (_("Invalid value for `%s' (%lu)"),
9992 (unsigned long) imm_expr.X_add_number);
9993 imm_expr.X_add_number &= 0x7ff;
9995 ip->insn_opcode |= imm_expr.X_add_number;
9996 imm_expr.X_op = O_absent;
10006 /* Args don't match. */
10007 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
10008 strcmp (insn->name, insn[1].name) == 0)
10015 insn_error = _("illegal operands");
10021 /* This structure holds information we know about a mips16 immediate
10024 struct mips16_immed_operand
10026 /* The type code used in the argument string in the opcode table. */
10028 /* The number of bits in the short form of the opcode. */
10030 /* The number of bits in the extended form of the opcode. */
10032 /* The amount by which the short form is shifted when it is used;
10033 for example, the sw instruction has a shift count of 2. */
10035 /* The amount by which the short form is shifted when it is stored
10036 into the instruction code. */
10038 /* Non-zero if the short form is unsigned. */
10040 /* Non-zero if the extended form is unsigned. */
10042 /* Non-zero if the value is PC relative. */
10046 /* The mips16 immediate operand types. */
10048 static const struct mips16_immed_operand mips16_immed_operands[] =
10050 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
10051 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
10052 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
10053 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
10054 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
10055 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
10056 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
10057 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
10058 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
10059 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
10060 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
10061 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
10062 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
10063 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
10064 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
10065 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
10066 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
10067 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
10068 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
10069 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
10070 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
10073 #define MIPS16_NUM_IMMED \
10074 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
10076 /* Handle a mips16 instruction with an immediate value. This or's the
10077 small immediate value into *INSN. It sets *USE_EXTEND to indicate
10078 whether an extended value is needed; if one is needed, it sets
10079 *EXTEND to the value. The argument type is TYPE. The value is VAL.
10080 If SMALL is true, an unextended opcode was explicitly requested.
10081 If EXT is true, an extended opcode was explicitly requested. If
10082 WARN is true, warn if EXT does not match reality. */
10085 mips16_immed (char *file, unsigned int line, int type, offsetT val,
10086 bfd_boolean warn, bfd_boolean small, bfd_boolean ext,
10087 unsigned long *insn, bfd_boolean *use_extend,
10088 unsigned short *extend)
10090 register const struct mips16_immed_operand *op;
10091 int mintiny, maxtiny;
10092 bfd_boolean needext;
10094 op = mips16_immed_operands;
10095 while (op->type != type)
10098 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
10103 if (type == '<' || type == '>' || type == '[' || type == ']')
10106 maxtiny = 1 << op->nbits;
10111 maxtiny = (1 << op->nbits) - 1;
10116 mintiny = - (1 << (op->nbits - 1));
10117 maxtiny = (1 << (op->nbits - 1)) - 1;
10120 /* Branch offsets have an implicit 0 in the lowest bit. */
10121 if (type == 'p' || type == 'q')
10124 if ((val & ((1 << op->shift) - 1)) != 0
10125 || val < (mintiny << op->shift)
10126 || val > (maxtiny << op->shift))
10131 if (warn && ext && ! needext)
10132 as_warn_where (file, line,
10133 _("extended operand requested but not required"));
10134 if (small && needext)
10135 as_bad_where (file, line, _("invalid unextended operand value"));
10137 if (small || (! ext && ! needext))
10141 *use_extend = FALSE;
10142 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
10143 insnval <<= op->op_shift;
10148 long minext, maxext;
10154 maxext = (1 << op->extbits) - 1;
10158 minext = - (1 << (op->extbits - 1));
10159 maxext = (1 << (op->extbits - 1)) - 1;
10161 if (val < minext || val > maxext)
10162 as_bad_where (file, line,
10163 _("operand value out of range for instruction"));
10165 *use_extend = TRUE;
10166 if (op->extbits == 16)
10168 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
10171 else if (op->extbits == 15)
10173 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
10178 extval = ((val & 0x1f) << 6) | (val & 0x20);
10182 *extend = (unsigned short) extval;
10187 static const struct percent_op_match
10190 bfd_reloc_code_real_type reloc;
10193 {"%lo", BFD_RELOC_LO16},
10195 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
10196 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
10197 {"%call16", BFD_RELOC_MIPS_CALL16},
10198 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
10199 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
10200 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
10201 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
10202 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
10203 {"%got", BFD_RELOC_MIPS_GOT16},
10204 {"%gp_rel", BFD_RELOC_GPREL16},
10205 {"%half", BFD_RELOC_16},
10206 {"%highest", BFD_RELOC_MIPS_HIGHEST},
10207 {"%higher", BFD_RELOC_MIPS_HIGHER},
10208 {"%neg", BFD_RELOC_MIPS_SUB},
10210 {"%hi", BFD_RELOC_HI16_S}
10214 /* Return true if *STR points to a relocation operator. When returning true,
10215 move *STR over the operator and store its relocation code in *RELOC.
10216 Leave both *STR and *RELOC alone when returning false. */
10219 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
10223 for (i = 0; i < ARRAY_SIZE (percent_op); i++)
10224 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
10226 *str += strlen (percent_op[i].str);
10227 *reloc = percent_op[i].reloc;
10229 /* Check whether the output BFD supports this relocation.
10230 If not, issue an error and fall back on something safe. */
10231 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
10233 as_bad ("relocation %s isn't supported by the current ABI",
10234 percent_op[i].str);
10235 *reloc = BFD_RELOC_LO16;
10243 /* Parse string STR as a 16-bit relocatable operand. Store the
10244 expression in *EP and the relocations in the array starting
10245 at RELOC. Return the number of relocation operators used.
10247 On exit, EXPR_END points to the first character after the expression.
10248 If no relocation operators are used, RELOC[0] is set to BFD_RELOC_LO16. */
10251 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
10254 bfd_reloc_code_real_type reversed_reloc[3];
10255 size_t reloc_index, i;
10256 int crux_depth, str_depth;
10259 /* Search for the start of the main expression, recoding relocations
10260 in REVERSED_RELOC. End the loop with CRUX pointing to the start
10261 of the main expression and with CRUX_DEPTH containing the number
10262 of open brackets at that point. */
10269 crux_depth = str_depth;
10271 /* Skip over whitespace and brackets, keeping count of the number
10273 while (*str == ' ' || *str == '\t' || *str == '(')
10278 && reloc_index < (HAVE_NEWABI ? 3 : 1)
10279 && parse_relocation (&str, &reversed_reloc[reloc_index]));
10281 my_getExpression (ep, crux);
10284 /* Match every open bracket. */
10285 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
10289 if (crux_depth > 0)
10290 as_bad ("unclosed '('");
10294 if (reloc_index == 0)
10295 reloc[0] = BFD_RELOC_LO16;
10298 prev_reloc_op_frag = frag_now;
10299 for (i = 0; i < reloc_index; i++)
10300 reloc[i] = reversed_reloc[reloc_index - 1 - i];
10303 return reloc_index;
10307 my_getExpression (expressionS *ep, char *str)
10312 save_in = input_line_pointer;
10313 input_line_pointer = str;
10315 expr_end = input_line_pointer;
10316 input_line_pointer = save_in;
10318 /* If we are in mips16 mode, and this is an expression based on `.',
10319 then we bump the value of the symbol by 1 since that is how other
10320 text symbols are handled. We don't bother to handle complex
10321 expressions, just `.' plus or minus a constant. */
10322 if (mips_opts.mips16
10323 && ep->X_op == O_symbol
10324 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
10325 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
10326 && symbol_get_frag (ep->X_add_symbol) == frag_now
10327 && symbol_constant_p (ep->X_add_symbol)
10328 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
10329 S_SET_VALUE (ep->X_add_symbol, val + 1);
10332 /* Turn a string in input_line_pointer into a floating point constant
10333 of type TYPE, and store the appropriate bytes in *LITP. The number
10334 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10335 returned, or NULL on OK. */
10338 md_atof (int type, char *litP, int *sizeP)
10341 LITTLENUM_TYPE words[4];
10357 return _("bad call to md_atof");
10360 t = atof_ieee (input_line_pointer, type, words);
10362 input_line_pointer = t;
10366 if (! target_big_endian)
10368 for (i = prec - 1; i >= 0; i--)
10370 md_number_to_chars (litP, words[i], 2);
10376 for (i = 0; i < prec; i++)
10378 md_number_to_chars (litP, words[i], 2);
10387 md_number_to_chars (char *buf, valueT val, int n)
10389 if (target_big_endian)
10390 number_to_chars_bigendian (buf, val, n);
10392 number_to_chars_littleendian (buf, val, n);
10396 static int support_64bit_objects(void)
10398 const char **list, **l;
10401 list = bfd_target_list ();
10402 for (l = list; *l != NULL; l++)
10404 /* This is traditional mips */
10405 if (strcmp (*l, "elf64-tradbigmips") == 0
10406 || strcmp (*l, "elf64-tradlittlemips") == 0)
10408 if (strcmp (*l, "elf64-bigmips") == 0
10409 || strcmp (*l, "elf64-littlemips") == 0)
10412 yes = (*l != NULL);
10416 #endif /* OBJ_ELF */
10418 const char *md_shortopts = "O::g::G:";
10420 struct option md_longopts[] =
10422 /* Options which specify architecture. */
10423 #define OPTION_ARCH_BASE (OPTION_MD_BASE)
10424 #define OPTION_MARCH (OPTION_ARCH_BASE + 0)
10425 {"march", required_argument, NULL, OPTION_MARCH},
10426 #define OPTION_MTUNE (OPTION_ARCH_BASE + 1)
10427 {"mtune", required_argument, NULL, OPTION_MTUNE},
10428 #define OPTION_MIPS1 (OPTION_ARCH_BASE + 2)
10429 {"mips0", no_argument, NULL, OPTION_MIPS1},
10430 {"mips1", no_argument, NULL, OPTION_MIPS1},
10431 #define OPTION_MIPS2 (OPTION_ARCH_BASE + 3)
10432 {"mips2", no_argument, NULL, OPTION_MIPS2},
10433 #define OPTION_MIPS3 (OPTION_ARCH_BASE + 4)
10434 {"mips3", no_argument, NULL, OPTION_MIPS3},
10435 #define OPTION_MIPS4 (OPTION_ARCH_BASE + 5)
10436 {"mips4", no_argument, NULL, OPTION_MIPS4},
10437 #define OPTION_MIPS5 (OPTION_ARCH_BASE + 6)
10438 {"mips5", no_argument, NULL, OPTION_MIPS5},
10439 #define OPTION_MIPS32 (OPTION_ARCH_BASE + 7)
10440 {"mips32", no_argument, NULL, OPTION_MIPS32},
10441 #define OPTION_MIPS64 (OPTION_ARCH_BASE + 8)
10442 {"mips64", no_argument, NULL, OPTION_MIPS64},
10443 #define OPTION_MIPS32R2 (OPTION_ARCH_BASE + 9)
10444 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
10445 #define OPTION_MIPS64R2 (OPTION_ARCH_BASE + 10)
10446 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
10448 /* Options which specify Application Specific Extensions (ASEs). */
10449 #define OPTION_ASE_BASE (OPTION_ARCH_BASE + 11)
10450 #define OPTION_MIPS16 (OPTION_ASE_BASE + 0)
10451 {"mips16", no_argument, NULL, OPTION_MIPS16},
10452 #define OPTION_NO_MIPS16 (OPTION_ASE_BASE + 1)
10453 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
10454 #define OPTION_MIPS3D (OPTION_ASE_BASE + 2)
10455 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
10456 #define OPTION_NO_MIPS3D (OPTION_ASE_BASE + 3)
10457 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
10458 #define OPTION_MDMX (OPTION_ASE_BASE + 4)
10459 {"mdmx", no_argument, NULL, OPTION_MDMX},
10460 #define OPTION_NO_MDMX (OPTION_ASE_BASE + 5)
10461 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
10463 /* Old-style architecture options. Don't add more of these. */
10464 #define OPTION_COMPAT_ARCH_BASE (OPTION_ASE_BASE + 6)
10465 #define OPTION_M4650 (OPTION_COMPAT_ARCH_BASE + 0)
10466 {"m4650", no_argument, NULL, OPTION_M4650},
10467 #define OPTION_NO_M4650 (OPTION_COMPAT_ARCH_BASE + 1)
10468 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
10469 #define OPTION_M4010 (OPTION_COMPAT_ARCH_BASE + 2)
10470 {"m4010", no_argument, NULL, OPTION_M4010},
10471 #define OPTION_NO_M4010 (OPTION_COMPAT_ARCH_BASE + 3)
10472 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
10473 #define OPTION_M4100 (OPTION_COMPAT_ARCH_BASE + 4)
10474 {"m4100", no_argument, NULL, OPTION_M4100},
10475 #define OPTION_NO_M4100 (OPTION_COMPAT_ARCH_BASE + 5)
10476 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
10477 #define OPTION_M3900 (OPTION_COMPAT_ARCH_BASE + 6)
10478 {"m3900", no_argument, NULL, OPTION_M3900},
10479 #define OPTION_NO_M3900 (OPTION_COMPAT_ARCH_BASE + 7)
10480 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
10482 /* Options which enable bug fixes. */
10483 #define OPTION_FIX_BASE (OPTION_COMPAT_ARCH_BASE + 8)
10484 #define OPTION_M7000_HILO_FIX (OPTION_FIX_BASE + 0)
10485 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
10486 #define OPTION_MNO_7000_HILO_FIX (OPTION_FIX_BASE + 1)
10487 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10488 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10489 #define OPTION_FIX_VR4122 (OPTION_FIX_BASE + 2)
10490 #define OPTION_NO_FIX_VR4122 (OPTION_FIX_BASE + 3)
10491 {"mfix-vr4122-bugs", no_argument, NULL, OPTION_FIX_VR4122},
10492 {"no-mfix-vr4122-bugs", no_argument, NULL, OPTION_NO_FIX_VR4122},
10494 /* Miscellaneous options. */
10495 #define OPTION_MISC_BASE (OPTION_FIX_BASE + 4)
10496 #define OPTION_MEMBEDDED_PIC (OPTION_MISC_BASE + 0)
10497 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
10498 #define OPTION_TRAP (OPTION_MISC_BASE + 1)
10499 {"trap", no_argument, NULL, OPTION_TRAP},
10500 {"no-break", no_argument, NULL, OPTION_TRAP},
10501 #define OPTION_BREAK (OPTION_MISC_BASE + 2)
10502 {"break", no_argument, NULL, OPTION_BREAK},
10503 {"no-trap", no_argument, NULL, OPTION_BREAK},
10504 #define OPTION_EB (OPTION_MISC_BASE + 3)
10505 {"EB", no_argument, NULL, OPTION_EB},
10506 #define OPTION_EL (OPTION_MISC_BASE + 4)
10507 {"EL", no_argument, NULL, OPTION_EL},
10508 #define OPTION_FP32 (OPTION_MISC_BASE + 5)
10509 {"mfp32", no_argument, NULL, OPTION_FP32},
10510 #define OPTION_GP32 (OPTION_MISC_BASE + 6)
10511 {"mgp32", no_argument, NULL, OPTION_GP32},
10512 #define OPTION_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 7)
10513 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
10514 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 8)
10515 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
10516 #define OPTION_FP64 (OPTION_MISC_BASE + 9)
10517 {"mfp64", no_argument, NULL, OPTION_FP64},
10518 #define OPTION_GP64 (OPTION_MISC_BASE + 10)
10519 {"mgp64", no_argument, NULL, OPTION_GP64},
10520 #define OPTION_RELAX_BRANCH (OPTION_MISC_BASE + 11)
10521 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 12)
10522 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
10523 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
10525 /* ELF-specific options. */
10527 #define OPTION_ELF_BASE (OPTION_MISC_BASE + 13)
10528 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10529 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
10530 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
10531 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10532 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
10533 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10534 {"xgot", no_argument, NULL, OPTION_XGOT},
10535 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10536 {"mabi", required_argument, NULL, OPTION_MABI},
10537 #define OPTION_32 (OPTION_ELF_BASE + 4)
10538 {"32", no_argument, NULL, OPTION_32},
10539 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10540 {"n32", no_argument, NULL, OPTION_N32},
10541 #define OPTION_64 (OPTION_ELF_BASE + 6)
10542 {"64", no_argument, NULL, OPTION_64},
10543 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10544 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
10545 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10546 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
10547 #define OPTION_PDR (OPTION_ELF_BASE + 9)
10548 {"mpdr", no_argument, NULL, OPTION_PDR},
10549 #define OPTION_NO_PDR (OPTION_ELF_BASE + 10)
10550 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
10551 #endif /* OBJ_ELF */
10553 {NULL, no_argument, NULL, 0}
10555 size_t md_longopts_size = sizeof (md_longopts);
10557 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10558 NEW_VALUE. Warn if another value was already specified. Note:
10559 we have to defer parsing the -march and -mtune arguments in order
10560 to handle 'from-abi' correctly, since the ABI might be specified
10561 in a later argument. */
10564 mips_set_option_string (const char **string_ptr, const char *new_value)
10566 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
10567 as_warn (_("A different %s was already specified, is now %s"),
10568 string_ptr == &mips_arch_string ? "-march" : "-mtune",
10571 *string_ptr = new_value;
10575 md_parse_option (int c, char *arg)
10579 case OPTION_CONSTRUCT_FLOATS:
10580 mips_disable_float_construction = 0;
10583 case OPTION_NO_CONSTRUCT_FLOATS:
10584 mips_disable_float_construction = 1;
10596 target_big_endian = 1;
10600 target_big_endian = 0;
10604 if (arg && arg[1] == '0')
10614 mips_debug = atoi (arg);
10615 /* When the MIPS assembler sees -g or -g2, it does not do
10616 optimizations which limit full symbolic debugging. We take
10617 that to be equivalent to -O0. */
10618 if (mips_debug == 2)
10623 file_mips_isa = ISA_MIPS1;
10627 file_mips_isa = ISA_MIPS2;
10631 file_mips_isa = ISA_MIPS3;
10635 file_mips_isa = ISA_MIPS4;
10639 file_mips_isa = ISA_MIPS5;
10642 case OPTION_MIPS32:
10643 file_mips_isa = ISA_MIPS32;
10646 case OPTION_MIPS32R2:
10647 file_mips_isa = ISA_MIPS32R2;
10650 case OPTION_MIPS64R2:
10651 file_mips_isa = ISA_MIPS64R2;
10654 case OPTION_MIPS64:
10655 file_mips_isa = ISA_MIPS64;
10659 mips_set_option_string (&mips_tune_string, arg);
10663 mips_set_option_string (&mips_arch_string, arg);
10667 mips_set_option_string (&mips_arch_string, "4650");
10668 mips_set_option_string (&mips_tune_string, "4650");
10671 case OPTION_NO_M4650:
10675 mips_set_option_string (&mips_arch_string, "4010");
10676 mips_set_option_string (&mips_tune_string, "4010");
10679 case OPTION_NO_M4010:
10683 mips_set_option_string (&mips_arch_string, "4100");
10684 mips_set_option_string (&mips_tune_string, "4100");
10687 case OPTION_NO_M4100:
10691 mips_set_option_string (&mips_arch_string, "3900");
10692 mips_set_option_string (&mips_tune_string, "3900");
10695 case OPTION_NO_M3900:
10699 mips_opts.ase_mdmx = 1;
10702 case OPTION_NO_MDMX:
10703 mips_opts.ase_mdmx = 0;
10706 case OPTION_MIPS16:
10707 mips_opts.mips16 = 1;
10708 mips_no_prev_insn (FALSE);
10711 case OPTION_NO_MIPS16:
10712 mips_opts.mips16 = 0;
10713 mips_no_prev_insn (FALSE);
10716 case OPTION_MIPS3D:
10717 mips_opts.ase_mips3d = 1;
10720 case OPTION_NO_MIPS3D:
10721 mips_opts.ase_mips3d = 0;
10724 case OPTION_MEMBEDDED_PIC:
10725 mips_pic = EMBEDDED_PIC;
10726 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
10728 as_bad (_("-G may not be used with embedded PIC code"));
10731 g_switch_value = 0x7fffffff;
10734 case OPTION_FIX_VR4122:
10735 mips_fix_4122_bugs = 1;
10738 case OPTION_NO_FIX_VR4122:
10739 mips_fix_4122_bugs = 0;
10742 case OPTION_RELAX_BRANCH:
10743 mips_relax_branch = 1;
10746 case OPTION_NO_RELAX_BRANCH:
10747 mips_relax_branch = 0;
10751 /* When generating ELF code, we permit -KPIC and -call_shared to
10752 select SVR4_PIC, and -non_shared to select no PIC. This is
10753 intended to be compatible with Irix 5. */
10754 case OPTION_CALL_SHARED:
10755 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10757 as_bad (_("-call_shared is supported only for ELF format"));
10760 mips_pic = SVR4_PIC;
10761 mips_abicalls = TRUE;
10762 if (g_switch_seen && g_switch_value != 0)
10764 as_bad (_("-G may not be used with SVR4 PIC code"));
10767 g_switch_value = 0;
10770 case OPTION_NON_SHARED:
10771 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10773 as_bad (_("-non_shared is supported only for ELF format"));
10777 mips_abicalls = FALSE;
10780 /* The -xgot option tells the assembler to use 32 offsets when
10781 accessing the got in SVR4_PIC mode. It is for Irix
10786 #endif /* OBJ_ELF */
10789 if (! USE_GLOBAL_POINTER_OPT)
10791 as_bad (_("-G is not supported for this configuration"));
10794 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10796 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10800 g_switch_value = atoi (arg);
10805 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10808 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10810 as_bad (_("-32 is supported for ELF format only"));
10813 mips_abi = O32_ABI;
10817 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10819 as_bad (_("-n32 is supported for ELF format only"));
10822 mips_abi = N32_ABI;
10826 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10828 as_bad (_("-64 is supported for ELF format only"));
10831 mips_abi = N64_ABI;
10832 if (! support_64bit_objects())
10833 as_fatal (_("No compiled in support for 64 bit object file format"));
10835 #endif /* OBJ_ELF */
10838 file_mips_gp32 = 1;
10842 file_mips_gp32 = 0;
10846 file_mips_fp32 = 1;
10850 file_mips_fp32 = 0;
10855 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10857 as_bad (_("-mabi is supported for ELF format only"));
10860 if (strcmp (arg, "32") == 0)
10861 mips_abi = O32_ABI;
10862 else if (strcmp (arg, "o64") == 0)
10863 mips_abi = O64_ABI;
10864 else if (strcmp (arg, "n32") == 0)
10865 mips_abi = N32_ABI;
10866 else if (strcmp (arg, "64") == 0)
10868 mips_abi = N64_ABI;
10869 if (! support_64bit_objects())
10870 as_fatal (_("No compiled in support for 64 bit object file "
10873 else if (strcmp (arg, "eabi") == 0)
10874 mips_abi = EABI_ABI;
10877 as_fatal (_("invalid abi -mabi=%s"), arg);
10881 #endif /* OBJ_ELF */
10883 case OPTION_M7000_HILO_FIX:
10884 mips_7000_hilo_fix = TRUE;
10887 case OPTION_MNO_7000_HILO_FIX:
10888 mips_7000_hilo_fix = FALSE;
10892 case OPTION_MDEBUG:
10893 mips_flag_mdebug = TRUE;
10896 case OPTION_NO_MDEBUG:
10897 mips_flag_mdebug = FALSE;
10901 mips_flag_pdr = TRUE;
10904 case OPTION_NO_PDR:
10905 mips_flag_pdr = FALSE;
10907 #endif /* OBJ_ELF */
10916 /* Set up globals to generate code for the ISA or processor
10917 described by INFO. */
10920 mips_set_architecture (const struct mips_cpu_info *info)
10924 file_mips_arch = info->cpu;
10925 mips_opts.arch = info->cpu;
10926 mips_opts.isa = info->isa;
10931 /* Likewise for tuning. */
10934 mips_set_tune (const struct mips_cpu_info *info)
10937 mips_tune = info->cpu;
10942 mips_after_parse_args (void)
10944 const struct mips_cpu_info *arch_info = 0;
10945 const struct mips_cpu_info *tune_info = 0;
10947 /* GP relative stuff not working for PE */
10948 if (strncmp (TARGET_OS, "pe", 2) == 0
10949 && g_switch_value != 0)
10952 as_bad (_("-G not supported in this configuration."));
10953 g_switch_value = 0;
10956 if (mips_abi == NO_ABI)
10957 mips_abi = MIPS_DEFAULT_ABI;
10959 /* The following code determines the architecture and register size.
10960 Similar code was added to GCC 3.3 (see override_options() in
10961 config/mips/mips.c). The GAS and GCC code should be kept in sync
10962 as much as possible. */
10964 if (mips_arch_string != 0)
10965 arch_info = mips_parse_cpu ("-march", mips_arch_string);
10967 if (file_mips_isa != ISA_UNKNOWN)
10969 /* Handle -mipsN. At this point, file_mips_isa contains the
10970 ISA level specified by -mipsN, while arch_info->isa contains
10971 the -march selection (if any). */
10972 if (arch_info != 0)
10974 /* -march takes precedence over -mipsN, since it is more descriptive.
10975 There's no harm in specifying both as long as the ISA levels
10977 if (file_mips_isa != arch_info->isa)
10978 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
10979 mips_cpu_info_from_isa (file_mips_isa)->name,
10980 mips_cpu_info_from_isa (arch_info->isa)->name);
10983 arch_info = mips_cpu_info_from_isa (file_mips_isa);
10986 if (arch_info == 0)
10987 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
10989 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
10990 as_bad ("-march=%s is not compatible with the selected ABI",
10993 mips_set_architecture (arch_info);
10995 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
10996 if (mips_tune_string != 0)
10997 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
10999 if (tune_info == 0)
11000 mips_set_tune (arch_info);
11002 mips_set_tune (tune_info);
11004 if (file_mips_gp32 >= 0)
11006 /* The user specified the size of the integer registers. Make sure
11007 it agrees with the ABI and ISA. */
11008 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
11009 as_bad (_("-mgp64 used with a 32-bit processor"));
11010 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
11011 as_bad (_("-mgp32 used with a 64-bit ABI"));
11012 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
11013 as_bad (_("-mgp64 used with a 32-bit ABI"));
11017 /* Infer the integer register size from the ABI and processor.
11018 Restrict ourselves to 32-bit registers if that's all the
11019 processor has, or if the ABI cannot handle 64-bit registers. */
11020 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
11021 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
11024 /* ??? GAS treats single-float processors as though they had 64-bit
11025 float registers (although it complains when double-precision
11026 instructions are used). As things stand, saying they have 32-bit
11027 registers would lead to spurious "register must be even" messages.
11028 So here we assume float registers are always the same size as
11029 integer ones, unless the user says otherwise. */
11030 if (file_mips_fp32 < 0)
11031 file_mips_fp32 = file_mips_gp32;
11033 /* End of GCC-shared inference code. */
11035 /* This flag is set when we have a 64-bit capable CPU but use only
11036 32-bit wide registers. Note that EABI does not use it. */
11037 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
11038 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
11039 || mips_abi == O32_ABI))
11040 mips_32bitmode = 1;
11042 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
11043 as_bad (_("trap exception not supported at ISA 1"));
11045 /* If the selected architecture includes support for ASEs, enable
11046 generation of code for them. */
11047 if (mips_opts.mips16 == -1)
11048 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
11049 if (mips_opts.ase_mips3d == -1)
11050 mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (file_mips_arch)) ? 1 : 0;
11051 if (mips_opts.ase_mdmx == -1)
11052 mips_opts.ase_mdmx = (CPU_HAS_MDMX (file_mips_arch)) ? 1 : 0;
11054 file_mips_isa = mips_opts.isa;
11055 file_ase_mips16 = mips_opts.mips16;
11056 file_ase_mips3d = mips_opts.ase_mips3d;
11057 file_ase_mdmx = mips_opts.ase_mdmx;
11058 mips_opts.gp32 = file_mips_gp32;
11059 mips_opts.fp32 = file_mips_fp32;
11061 if (mips_flag_mdebug < 0)
11063 #ifdef OBJ_MAYBE_ECOFF
11064 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
11065 mips_flag_mdebug = 1;
11067 #endif /* OBJ_MAYBE_ECOFF */
11068 mips_flag_mdebug = 0;
11073 mips_init_after_args (void)
11075 /* initialize opcodes */
11076 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
11077 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
11081 md_pcrel_from (fixS *fixP)
11083 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
11084 switch (fixP->fx_r_type)
11086 case BFD_RELOC_16_PCREL_S2:
11087 case BFD_RELOC_MIPS_JMP:
11088 /* Return the address of the delay slot. */
11095 /* This is called before the symbol table is processed. In order to
11096 work with gcc when using mips-tfile, we must keep all local labels.
11097 However, in other cases, we want to discard them. If we were
11098 called with -g, but we didn't see any debugging information, it may
11099 mean that gcc is smuggling debugging information through to
11100 mips-tfile, in which case we must generate all local labels. */
11103 mips_frob_file_before_adjust (void)
11105 #ifndef NO_ECOFF_DEBUGGING
11106 if (ECOFF_DEBUGGING
11108 && ! ecoff_debugging_seen)
11109 flag_keep_locals = 1;
11113 /* Sort any unmatched HI16_S relocs so that they immediately precede
11114 the corresponding LO reloc. This is called before md_apply_fix3 and
11115 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
11116 explicit use of the %hi modifier. */
11119 mips_frob_file (void)
11121 struct mips_hi_fixup *l;
11123 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
11125 segment_info_type *seginfo;
11128 assert (reloc_needs_lo_p (l->fixp->fx_r_type));
11130 /* If a GOT16 relocation turns out to be against a global symbol,
11131 there isn't supposed to be a matching LO. */
11132 if (l->fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
11133 && !pic_need_relax (l->fixp->fx_addsy, l->seg))
11136 /* Check quickly whether the next fixup happens to be a matching %lo. */
11137 if (fixup_has_matching_lo_p (l->fixp))
11140 /* Look through the fixups for this segment for a matching %lo.
11141 When we find one, move the %hi just in front of it. We do
11142 this in two passes. In the first pass, we try to find a
11143 unique %lo. In the second pass, we permit multiple %hi
11144 relocs for a single %lo (this is a GNU extension). */
11145 seginfo = seg_info (l->seg);
11146 for (pass = 0; pass < 2; pass++)
11151 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
11153 /* Check whether this is a %lo fixup which matches l->fixp. */
11154 if (f->fx_r_type == BFD_RELOC_LO16
11155 && f->fx_addsy == l->fixp->fx_addsy
11156 && f->fx_offset == l->fixp->fx_offset
11159 || !reloc_needs_lo_p (prev->fx_r_type)
11160 || !fixup_has_matching_lo_p (prev)))
11164 /* Move l->fixp before f. */
11165 for (pf = &seginfo->fix_root;
11167 pf = &(*pf)->fx_next)
11168 assert (*pf != NULL);
11170 *pf = l->fixp->fx_next;
11172 l->fixp->fx_next = f;
11174 seginfo->fix_root = l->fixp;
11176 prev->fx_next = l->fixp;
11187 #if 0 /* GCC code motion plus incomplete dead code elimination
11188 can leave a %hi without a %lo. */
11190 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
11191 _("Unmatched %%hi reloc"));
11197 /* When generating embedded PIC code we need to use a special
11198 relocation to represent the difference of two symbols in the .text
11199 section (switch tables use a difference of this sort). See
11200 include/coff/mips.h for details. This macro checks whether this
11201 fixup requires the special reloc. */
11202 #define SWITCH_TABLE(fixp) \
11203 ((fixp)->fx_r_type == BFD_RELOC_32 \
11204 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
11205 && (fixp)->fx_addsy != NULL \
11206 && (fixp)->fx_subsy != NULL \
11207 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
11208 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
11210 /* When generating embedded PIC code we must keep all PC relative
11211 relocations, in case the linker has to relax a call. We also need
11212 to keep relocations for switch table entries.
11214 We may have combined relocations without symbols in the N32/N64 ABI.
11215 We have to prevent gas from dropping them. */
11218 mips_force_relocation (fixS *fixp)
11220 if (generic_force_reloc (fixp))
11224 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
11225 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
11226 || fixp->fx_r_type == BFD_RELOC_HI16_S
11227 || fixp->fx_r_type == BFD_RELOC_LO16))
11230 return (mips_pic == EMBEDDED_PIC
11232 || SWITCH_TABLE (fixp)
11233 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
11234 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
11237 /* This hook is called before a fix is simplified. We don't really
11238 decide whether to skip a fix here. Rather, we turn global symbols
11239 used as branch targets into local symbols, such that they undergo
11240 simplification. We can only do this if the symbol is defined and
11241 it is in the same section as the branch. If this doesn't hold, we
11242 emit a better error message than just saying the relocation is not
11243 valid for the selected object format.
11245 FIXP is the fix-up we're going to try to simplify, SEG is the
11246 segment in which the fix up occurs. The return value should be
11247 non-zero to indicate the fix-up is valid for further
11248 simplifications. */
11251 mips_validate_fix (struct fix *fixP, asection *seg)
11253 /* There's a lot of discussion on whether it should be possible to
11254 use R_MIPS_PC16 to represent branch relocations. The outcome
11255 seems to be that it can, but gas/bfd are very broken in creating
11256 RELA relocations for this, so for now we only accept branches to
11257 symbols in the same section. Anything else is of dubious value,
11258 since there's no guarantee that at link time the symbol would be
11259 in range. Even for branches to local symbols this is arguably
11260 wrong, since it we assume the symbol is not going to be
11261 overridden, which should be possible per ELF library semantics,
11262 but then, there isn't a dynamic relocation that could be used to
11263 this effect, and the target would likely be out of range as well.
11265 Unfortunately, it seems that there is too much code out there
11266 that relies on branches to symbols that are global to be resolved
11267 as if they were local, like the IRIX tools do, so we do it as
11268 well, but with a warning so that people are reminded to fix their
11269 code. If we ever get back to using R_MIPS_PC16 for branch
11270 targets, this entire block should go away (and probably the
11271 whole function). */
11273 if (fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
11274 && (((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
11275 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11276 && mips_pic != EMBEDDED_PIC)
11277 || bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16_PCREL_S2) == NULL)
11280 if (! S_IS_DEFINED (fixP->fx_addsy))
11282 as_bad_where (fixP->fx_file, fixP->fx_line,
11283 _("Cannot branch to undefined symbol."));
11284 /* Avoid any further errors about this fixup. */
11287 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
11289 as_bad_where (fixP->fx_file, fixP->fx_line,
11290 _("Cannot branch to symbol in another section."));
11293 else if (S_IS_EXTERNAL (fixP->fx_addsy))
11295 symbolS *sym = fixP->fx_addsy;
11297 if (mips_pic == SVR4_PIC)
11298 as_warn_where (fixP->fx_file, fixP->fx_line,
11299 _("Pretending global symbol used as branch target is local."));
11301 fixP->fx_addsy = symbol_create (S_GET_NAME (sym),
11302 S_GET_SEGMENT (sym),
11304 symbol_get_frag (sym));
11305 copy_symbol_attributes (fixP->fx_addsy, sym);
11306 S_CLEAR_EXTERNAL (fixP->fx_addsy);
11307 assert (symbol_resolved_p (sym));
11308 symbol_mark_resolved (fixP->fx_addsy);
11315 /* Apply a fixup to the object file. */
11318 md_apply_fix3 (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
11322 static int previous_fx_r_type = 0;
11323 reloc_howto_type *howto;
11325 /* We ignore generic BFD relocations we don't know about. */
11326 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
11330 assert (fixP->fx_size == 4
11331 || fixP->fx_r_type == BFD_RELOC_16
11332 || fixP->fx_r_type == BFD_RELOC_64
11333 || fixP->fx_r_type == BFD_RELOC_CTOR
11334 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11335 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11336 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
11338 buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
11340 /* We are not done if this is a composite relocation to set up gp. */
11341 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel
11342 && !(fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11343 || (fixP->fx_r_type == BFD_RELOC_64
11344 && (previous_fx_r_type == BFD_RELOC_GPREL32
11345 || previous_fx_r_type == BFD_RELOC_GPREL16))
11346 || (previous_fx_r_type == BFD_RELOC_MIPS_SUB
11347 && (fixP->fx_r_type == BFD_RELOC_HI16_S
11348 || fixP->fx_r_type == BFD_RELOC_LO16))))
11350 previous_fx_r_type = fixP->fx_r_type;
11352 switch (fixP->fx_r_type)
11354 case BFD_RELOC_MIPS_JMP:
11355 case BFD_RELOC_MIPS_SHIFT5:
11356 case BFD_RELOC_MIPS_SHIFT6:
11357 case BFD_RELOC_MIPS_GOT_DISP:
11358 case BFD_RELOC_MIPS_GOT_PAGE:
11359 case BFD_RELOC_MIPS_GOT_OFST:
11360 case BFD_RELOC_MIPS_SUB:
11361 case BFD_RELOC_MIPS_INSERT_A:
11362 case BFD_RELOC_MIPS_INSERT_B:
11363 case BFD_RELOC_MIPS_DELETE:
11364 case BFD_RELOC_MIPS_HIGHEST:
11365 case BFD_RELOC_MIPS_HIGHER:
11366 case BFD_RELOC_MIPS_SCN_DISP:
11367 case BFD_RELOC_MIPS_REL16:
11368 case BFD_RELOC_MIPS_RELGOT:
11369 case BFD_RELOC_MIPS_JALR:
11370 case BFD_RELOC_HI16:
11371 case BFD_RELOC_HI16_S:
11372 case BFD_RELOC_GPREL16:
11373 case BFD_RELOC_MIPS_LITERAL:
11374 case BFD_RELOC_MIPS_CALL16:
11375 case BFD_RELOC_MIPS_GOT16:
11376 case BFD_RELOC_GPREL32:
11377 case BFD_RELOC_MIPS_GOT_HI16:
11378 case BFD_RELOC_MIPS_GOT_LO16:
11379 case BFD_RELOC_MIPS_CALL_HI16:
11380 case BFD_RELOC_MIPS_CALL_LO16:
11381 case BFD_RELOC_MIPS16_GPREL:
11382 if (fixP->fx_pcrel)
11383 as_bad_where (fixP->fx_file, fixP->fx_line,
11384 _("Invalid PC relative reloc"));
11385 /* Nothing needed to do. The value comes from the reloc entry */
11388 case BFD_RELOC_MIPS16_JMP:
11389 /* We currently always generate a reloc against a symbol, which
11390 means that we don't want an addend even if the symbol is
11395 case BFD_RELOC_PCREL_HI16_S:
11396 /* The addend for this is tricky if it is internal, so we just
11397 do everything here rather than in bfd_install_relocation. */
11398 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && !fixP->fx_done)
11401 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11403 /* For an external symbol adjust by the address to make it
11404 pcrel_offset. We use the address of the RELLO reloc
11405 which follows this one. */
11406 *valP += (fixP->fx_next->fx_frag->fr_address
11407 + fixP->fx_next->fx_where);
11409 *valP = ((*valP + 0x8000) >> 16) & 0xffff;
11410 if (target_big_endian)
11412 md_number_to_chars (buf, *valP, 2);
11415 case BFD_RELOC_PCREL_LO16:
11416 /* The addend for this is tricky if it is internal, so we just
11417 do everything here rather than in bfd_install_relocation. */
11418 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && !fixP->fx_done)
11421 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11422 *valP += fixP->fx_frag->fr_address + fixP->fx_where;
11423 if (target_big_endian)
11425 md_number_to_chars (buf, *valP, 2);
11429 /* This is handled like BFD_RELOC_32, but we output a sign
11430 extended value if we are only 32 bits. */
11432 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11434 if (8 <= sizeof (valueT))
11435 md_number_to_chars (buf, *valP, 8);
11440 if ((*valP & 0x80000000) != 0)
11444 md_number_to_chars ((char *)(buf + target_big_endian ? 4 : 0),
11446 md_number_to_chars ((char *)(buf + target_big_endian ? 0 : 4),
11452 case BFD_RELOC_RVA:
11454 /* If we are deleting this reloc entry, we must fill in the
11455 value now. This can happen if we have a .word which is not
11456 resolved when it appears but is later defined. We also need
11457 to fill in the value if this is an embedded PIC switch table
11460 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11461 md_number_to_chars (buf, *valP, 4);
11465 /* If we are deleting this reloc entry, we must fill in the
11467 assert (fixP->fx_size == 2);
11469 md_number_to_chars (buf, *valP, 2);
11472 case BFD_RELOC_LO16:
11473 /* When handling an embedded PIC switch statement, we can wind
11474 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11477 if (*valP + 0x8000 > 0xffff)
11478 as_bad_where (fixP->fx_file, fixP->fx_line,
11479 _("relocation overflow"));
11480 if (target_big_endian)
11482 md_number_to_chars (buf, *valP, 2);
11486 case BFD_RELOC_16_PCREL_S2:
11487 if ((*valP & 0x3) != 0)
11488 as_bad_where (fixP->fx_file, fixP->fx_line,
11489 _("Branch to odd address (%lx)"), (long) *valP);
11492 * We need to save the bits in the instruction since fixup_segment()
11493 * might be deleting the relocation entry (i.e., a branch within
11494 * the current segment).
11496 if (! fixP->fx_done)
11499 /* update old instruction data */
11500 if (target_big_endian)
11501 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
11503 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
11505 if (*valP + 0x20000 <= 0x3ffff)
11507 insn |= (*valP >> 2) & 0xffff;
11508 md_number_to_chars (buf, insn, 4);
11510 else if (mips_pic == NO_PIC
11512 && fixP->fx_frag->fr_address >= text_section->vma
11513 && (fixP->fx_frag->fr_address
11514 < text_section->vma + text_section->_raw_size)
11515 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
11516 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
11517 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
11519 /* The branch offset is too large. If this is an
11520 unconditional branch, and we are not generating PIC code,
11521 we can convert it to an absolute jump instruction. */
11522 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
11523 insn = 0x0c000000; /* jal */
11525 insn = 0x08000000; /* j */
11526 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
11528 fixP->fx_addsy = section_symbol (text_section);
11529 *valP += md_pcrel_from (fixP);
11530 md_number_to_chars (buf, insn, 4);
11534 /* If we got here, we have branch-relaxation disabled,
11535 and there's nothing we can do to fix this instruction
11536 without turning it into a longer sequence. */
11537 as_bad_where (fixP->fx_file, fixP->fx_line,
11538 _("Branch out of range"));
11542 case BFD_RELOC_VTABLE_INHERIT:
11545 && !S_IS_DEFINED (fixP->fx_addsy)
11546 && !S_IS_WEAK (fixP->fx_addsy))
11547 S_SET_WEAK (fixP->fx_addsy);
11550 case BFD_RELOC_VTABLE_ENTRY:
11558 /* Remember value for tc_gen_reloc. */
11559 fixP->fx_addnumber = *valP;
11564 printInsn (unsigned long oc)
11566 const struct mips_opcode *p;
11567 int treg, sreg, dreg, shamt;
11572 for (i = 0; i < NUMOPCODES; ++i)
11574 p = &mips_opcodes[i];
11575 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
11577 printf ("%08lx %s\t", oc, p->name);
11578 treg = (oc >> 16) & 0x1f;
11579 sreg = (oc >> 21) & 0x1f;
11580 dreg = (oc >> 11) & 0x1f;
11581 shamt = (oc >> 6) & 0x1f;
11583 for (args = p->args;; ++args)
11594 printf ("%c", *args);
11598 assert (treg == sreg);
11599 printf ("$%d,$%d", treg, sreg);
11604 printf ("$%d", dreg);
11609 printf ("$%d", treg);
11613 printf ("0x%x", treg);
11618 printf ("$%d", sreg);
11622 printf ("0x%08lx", oc & 0x1ffffff);
11629 printf ("%d", imm);
11634 printf ("$%d", shamt);
11645 printf (_("%08lx UNDEFINED\n"), oc);
11656 name = input_line_pointer;
11657 c = get_symbol_end ();
11658 p = (symbolS *) symbol_find_or_make (name);
11659 *input_line_pointer = c;
11663 /* Align the current frag to a given power of two. The MIPS assembler
11664 also automatically adjusts any preceding label. */
11667 mips_align (int to, int fill, symbolS *label)
11669 mips_emit_delays (FALSE);
11670 frag_align (to, fill, 0);
11671 record_alignment (now_seg, to);
11674 assert (S_GET_SEGMENT (label) == now_seg);
11675 symbol_set_frag (label, frag_now);
11676 S_SET_VALUE (label, (valueT) frag_now_fix ());
11680 /* Align to a given power of two. .align 0 turns off the automatic
11681 alignment used by the data creating pseudo-ops. */
11684 s_align (int x ATTRIBUTE_UNUSED)
11687 register long temp_fill;
11688 long max_alignment = 15;
11692 o Note that the assembler pulls down any immediately preceding label
11693 to the aligned address.
11694 o It's not documented but auto alignment is reinstated by
11695 a .align pseudo instruction.
11696 o Note also that after auto alignment is turned off the mips assembler
11697 issues an error on attempt to assemble an improperly aligned data item.
11702 temp = get_absolute_expression ();
11703 if (temp > max_alignment)
11704 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11707 as_warn (_("Alignment negative: 0 assumed."));
11710 if (*input_line_pointer == ',')
11712 ++input_line_pointer;
11713 temp_fill = get_absolute_expression ();
11720 mips_align (temp, (int) temp_fill,
11721 insn_labels != NULL ? insn_labels->label : NULL);
11728 demand_empty_rest_of_line ();
11732 mips_flush_pending_output (void)
11734 mips_emit_delays (FALSE);
11735 mips_clear_insn_labels ();
11739 s_change_sec (int sec)
11743 /* When generating embedded PIC code, we only use the .text, .lit8,
11744 .sdata and .sbss sections. We change the .data and .rdata
11745 pseudo-ops to use .sdata. */
11746 if (mips_pic == EMBEDDED_PIC
11747 && (sec == 'd' || sec == 'r'))
11751 /* The ELF backend needs to know that we are changing sections, so
11752 that .previous works correctly. We could do something like check
11753 for an obj_section_change_hook macro, but that might be confusing
11754 as it would not be appropriate to use it in the section changing
11755 functions in read.c, since obj-elf.c intercepts those. FIXME:
11756 This should be cleaner, somehow. */
11757 obj_elf_section_change_hook ();
11760 mips_emit_delays (FALSE);
11770 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11771 demand_empty_rest_of_line ();
11775 if (USE_GLOBAL_POINTER_OPT)
11777 seg = subseg_new (RDATA_SECTION_NAME,
11778 (subsegT) get_absolute_expression ());
11779 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11781 bfd_set_section_flags (stdoutput, seg,
11787 if (strcmp (TARGET_OS, "elf") != 0)
11788 record_alignment (seg, 4);
11790 demand_empty_rest_of_line ();
11794 as_bad (_("No read only data section in this object file format"));
11795 demand_empty_rest_of_line ();
11801 if (USE_GLOBAL_POINTER_OPT)
11803 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11804 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11806 bfd_set_section_flags (stdoutput, seg,
11807 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11809 if (strcmp (TARGET_OS, "elf") != 0)
11810 record_alignment (seg, 4);
11812 demand_empty_rest_of_line ();
11817 as_bad (_("Global pointers not supported; recompile -G 0"));
11818 demand_empty_rest_of_line ();
11827 s_change_section (int ignore ATTRIBUTE_UNUSED)
11830 char *section_name;
11835 int section_entry_size;
11836 int section_alignment;
11838 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11841 section_name = input_line_pointer;
11842 c = get_symbol_end ();
11844 next_c = *(input_line_pointer + 1);
11846 /* Do we have .section Name<,"flags">? */
11847 if (c != ',' || (c == ',' && next_c == '"'))
11849 /* just after name is now '\0'. */
11850 *input_line_pointer = c;
11851 input_line_pointer = section_name;
11852 obj_elf_section (ignore);
11855 input_line_pointer++;
11857 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
11859 section_type = get_absolute_expression ();
11862 if (*input_line_pointer++ == ',')
11863 section_flag = get_absolute_expression ();
11866 if (*input_line_pointer++ == ',')
11867 section_entry_size = get_absolute_expression ();
11869 section_entry_size = 0;
11870 if (*input_line_pointer++ == ',')
11871 section_alignment = get_absolute_expression ();
11873 section_alignment = 0;
11875 section_name = xstrdup (section_name);
11877 /* When using the generic form of .section (as implemented by obj-elf.c),
11878 there's no way to set the section type to SHT_MIPS_DWARF. Users have
11879 traditionally had to fall back on the more common @progbits instead.
11881 There's nothing really harmful in this, since bfd will correct
11882 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
11883 means that, for backwards compatibiltiy, the special_section entries
11884 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
11886 Even so, we shouldn't force users of the MIPS .section syntax to
11887 incorrectly label the sections as SHT_PROGBITS. The best compromise
11888 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
11889 generic type-checking code. */
11890 if (section_type == SHT_MIPS_DWARF)
11891 section_type = SHT_PROGBITS;
11893 obj_elf_change_section (section_name, section_type, section_flag,
11894 section_entry_size, 0, 0, 0);
11896 if (now_seg->name != section_name)
11897 free (section_name);
11898 #endif /* OBJ_ELF */
11902 mips_enable_auto_align (void)
11908 s_cons (int log_size)
11912 label = insn_labels != NULL ? insn_labels->label : NULL;
11913 mips_emit_delays (FALSE);
11914 if (log_size > 0 && auto_align)
11915 mips_align (log_size, 0, label);
11916 mips_clear_insn_labels ();
11917 cons (1 << log_size);
11921 s_float_cons (int type)
11925 label = insn_labels != NULL ? insn_labels->label : NULL;
11927 mips_emit_delays (FALSE);
11932 mips_align (3, 0, label);
11934 mips_align (2, 0, label);
11937 mips_clear_insn_labels ();
11942 /* Handle .globl. We need to override it because on Irix 5 you are
11945 where foo is an undefined symbol, to mean that foo should be
11946 considered to be the address of a function. */
11949 s_mips_globl (int x ATTRIBUTE_UNUSED)
11956 name = input_line_pointer;
11957 c = get_symbol_end ();
11958 symbolP = symbol_find_or_make (name);
11959 *input_line_pointer = c;
11960 SKIP_WHITESPACE ();
11962 /* On Irix 5, every global symbol that is not explicitly labelled as
11963 being a function is apparently labelled as being an object. */
11966 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11971 secname = input_line_pointer;
11972 c = get_symbol_end ();
11973 sec = bfd_get_section_by_name (stdoutput, secname);
11975 as_bad (_("%s: no such section"), secname);
11976 *input_line_pointer = c;
11978 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11979 flag = BSF_FUNCTION;
11982 symbol_get_bfdsym (symbolP)->flags |= flag;
11984 S_SET_EXTERNAL (symbolP);
11985 demand_empty_rest_of_line ();
11989 s_option (int x ATTRIBUTE_UNUSED)
11994 opt = input_line_pointer;
11995 c = get_symbol_end ();
11999 /* FIXME: What does this mean? */
12001 else if (strncmp (opt, "pic", 3) == 0)
12005 i = atoi (opt + 3);
12010 mips_pic = SVR4_PIC;
12011 mips_abicalls = TRUE;
12014 as_bad (_(".option pic%d not supported"), i);
12016 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
12018 if (g_switch_seen && g_switch_value != 0)
12019 as_warn (_("-G may not be used with SVR4 PIC code"));
12020 g_switch_value = 0;
12021 bfd_set_gp_size (stdoutput, 0);
12025 as_warn (_("Unrecognized option \"%s\""), opt);
12027 *input_line_pointer = c;
12028 demand_empty_rest_of_line ();
12031 /* This structure is used to hold a stack of .set values. */
12033 struct mips_option_stack
12035 struct mips_option_stack *next;
12036 struct mips_set_options options;
12039 static struct mips_option_stack *mips_opts_stack;
12041 /* Handle the .set pseudo-op. */
12044 s_mipsset (int x ATTRIBUTE_UNUSED)
12046 char *name = input_line_pointer, ch;
12048 while (!is_end_of_line[(unsigned char) *input_line_pointer])
12049 ++input_line_pointer;
12050 ch = *input_line_pointer;
12051 *input_line_pointer = '\0';
12053 if (strcmp (name, "reorder") == 0)
12055 if (mips_opts.noreorder && prev_nop_frag != NULL)
12057 /* If we still have pending nops, we can discard them. The
12058 usual nop handling will insert any that are still
12060 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
12061 * (mips_opts.mips16 ? 2 : 4));
12062 prev_nop_frag = NULL;
12064 mips_opts.noreorder = 0;
12066 else if (strcmp (name, "noreorder") == 0)
12068 mips_emit_delays (TRUE);
12069 mips_opts.noreorder = 1;
12070 mips_any_noreorder = 1;
12072 else if (strcmp (name, "at") == 0)
12074 mips_opts.noat = 0;
12076 else if (strcmp (name, "noat") == 0)
12078 mips_opts.noat = 1;
12080 else if (strcmp (name, "macro") == 0)
12082 mips_opts.warn_about_macros = 0;
12084 else if (strcmp (name, "nomacro") == 0)
12086 if (mips_opts.noreorder == 0)
12087 as_bad (_("`noreorder' must be set before `nomacro'"));
12088 mips_opts.warn_about_macros = 1;
12090 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
12092 mips_opts.nomove = 0;
12094 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
12096 mips_opts.nomove = 1;
12098 else if (strcmp (name, "bopt") == 0)
12100 mips_opts.nobopt = 0;
12102 else if (strcmp (name, "nobopt") == 0)
12104 mips_opts.nobopt = 1;
12106 else if (strcmp (name, "mips16") == 0
12107 || strcmp (name, "MIPS-16") == 0)
12108 mips_opts.mips16 = 1;
12109 else if (strcmp (name, "nomips16") == 0
12110 || strcmp (name, "noMIPS-16") == 0)
12111 mips_opts.mips16 = 0;
12112 else if (strcmp (name, "mips3d") == 0)
12113 mips_opts.ase_mips3d = 1;
12114 else if (strcmp (name, "nomips3d") == 0)
12115 mips_opts.ase_mips3d = 0;
12116 else if (strcmp (name, "mdmx") == 0)
12117 mips_opts.ase_mdmx = 1;
12118 else if (strcmp (name, "nomdmx") == 0)
12119 mips_opts.ase_mdmx = 0;
12120 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
12124 /* Permit the user to change the ISA and architecture on the fly.
12125 Needless to say, misuse can cause serious problems. */
12126 if (strcmp (name, "mips0") == 0)
12129 mips_opts.isa = file_mips_isa;
12131 else if (strcmp (name, "mips1") == 0)
12132 mips_opts.isa = ISA_MIPS1;
12133 else if (strcmp (name, "mips2") == 0)
12134 mips_opts.isa = ISA_MIPS2;
12135 else if (strcmp (name, "mips3") == 0)
12136 mips_opts.isa = ISA_MIPS3;
12137 else if (strcmp (name, "mips4") == 0)
12138 mips_opts.isa = ISA_MIPS4;
12139 else if (strcmp (name, "mips5") == 0)
12140 mips_opts.isa = ISA_MIPS5;
12141 else if (strcmp (name, "mips32") == 0)
12142 mips_opts.isa = ISA_MIPS32;
12143 else if (strcmp (name, "mips32r2") == 0)
12144 mips_opts.isa = ISA_MIPS32R2;
12145 else if (strcmp (name, "mips64") == 0)
12146 mips_opts.isa = ISA_MIPS64;
12147 else if (strcmp (name, "mips64r2") == 0)
12148 mips_opts.isa = ISA_MIPS64R2;
12149 else if (strcmp (name, "arch=default") == 0)
12152 mips_opts.arch = file_mips_arch;
12153 mips_opts.isa = file_mips_isa;
12155 else if (strncmp (name, "arch=", 5) == 0)
12157 const struct mips_cpu_info *p;
12159 p = mips_parse_cpu("internal use", name + 5);
12161 as_bad (_("unknown architecture %s"), name + 5);
12164 mips_opts.arch = p->cpu;
12165 mips_opts.isa = p->isa;
12169 as_bad (_("unknown ISA level %s"), name + 4);
12171 switch (mips_opts.isa)
12179 mips_opts.gp32 = 1;
12180 mips_opts.fp32 = 1;
12187 mips_opts.gp32 = 0;
12188 mips_opts.fp32 = 0;
12191 as_bad (_("unknown ISA level %s"), name + 4);
12196 mips_opts.gp32 = file_mips_gp32;
12197 mips_opts.fp32 = file_mips_fp32;
12200 else if (strcmp (name, "autoextend") == 0)
12201 mips_opts.noautoextend = 0;
12202 else if (strcmp (name, "noautoextend") == 0)
12203 mips_opts.noautoextend = 1;
12204 else if (strcmp (name, "push") == 0)
12206 struct mips_option_stack *s;
12208 s = (struct mips_option_stack *) xmalloc (sizeof *s);
12209 s->next = mips_opts_stack;
12210 s->options = mips_opts;
12211 mips_opts_stack = s;
12213 else if (strcmp (name, "pop") == 0)
12215 struct mips_option_stack *s;
12217 s = mips_opts_stack;
12219 as_bad (_(".set pop with no .set push"));
12222 /* If we're changing the reorder mode we need to handle
12223 delay slots correctly. */
12224 if (s->options.noreorder && ! mips_opts.noreorder)
12225 mips_emit_delays (TRUE);
12226 else if (! s->options.noreorder && mips_opts.noreorder)
12228 if (prev_nop_frag != NULL)
12230 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
12231 * (mips_opts.mips16 ? 2 : 4));
12232 prev_nop_frag = NULL;
12236 mips_opts = s->options;
12237 mips_opts_stack = s->next;
12243 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
12245 *input_line_pointer = ch;
12246 demand_empty_rest_of_line ();
12249 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
12250 .option pic2. It means to generate SVR4 PIC calls. */
12253 s_abicalls (int ignore ATTRIBUTE_UNUSED)
12255 mips_pic = SVR4_PIC;
12256 mips_abicalls = TRUE;
12257 if (USE_GLOBAL_POINTER_OPT)
12259 if (g_switch_seen && g_switch_value != 0)
12260 as_warn (_("-G may not be used with SVR4 PIC code"));
12261 g_switch_value = 0;
12263 bfd_set_gp_size (stdoutput, 0);
12264 demand_empty_rest_of_line ();
12267 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12268 PIC code. It sets the $gp register for the function based on the
12269 function address, which is in the register named in the argument.
12270 This uses a relocation against _gp_disp, which is handled specially
12271 by the linker. The result is:
12272 lui $gp,%hi(_gp_disp)
12273 addiu $gp,$gp,%lo(_gp_disp)
12274 addu $gp,$gp,.cpload argument
12275 The .cpload argument is normally $25 == $t9. */
12278 s_cpload (int ignore ATTRIBUTE_UNUSED)
12283 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12284 .cpload is ignored. */
12285 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12291 /* .cpload should be in a .set noreorder section. */
12292 if (mips_opts.noreorder == 0)
12293 as_warn (_(".cpload not in noreorder section"));
12295 ex.X_op = O_symbol;
12296 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
12297 ex.X_op_symbol = NULL;
12298 ex.X_add_number = 0;
12300 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12301 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
12303 macro_build_lui (NULL, &icnt, &ex, mips_gp_register);
12304 macro_build (NULL, &icnt, &ex, "addiu", "t,r,j", mips_gp_register,
12305 mips_gp_register, BFD_RELOC_LO16);
12307 macro_build (NULL, &icnt, NULL, "addu", "d,v,t", mips_gp_register,
12308 mips_gp_register, tc_get_register (0));
12310 demand_empty_rest_of_line ();
12313 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12314 .cpsetup $reg1, offset|$reg2, label
12316 If offset is given, this results in:
12317 sd $gp, offset($sp)
12318 lui $gp, %hi(%neg(%gp_rel(label)))
12319 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12320 daddu $gp, $gp, $reg1
12322 If $reg2 is given, this results in:
12323 daddu $reg2, $gp, $0
12324 lui $gp, %hi(%neg(%gp_rel(label)))
12325 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12326 daddu $gp, $gp, $reg1
12327 $reg1 is normally $25 == $t9. */
12329 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
12331 expressionS ex_off;
12332 expressionS ex_sym;
12337 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12338 We also need NewABI support. */
12339 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12345 reg1 = tc_get_register (0);
12346 SKIP_WHITESPACE ();
12347 if (*input_line_pointer != ',')
12349 as_bad (_("missing argument separator ',' for .cpsetup"));
12353 ++input_line_pointer;
12354 SKIP_WHITESPACE ();
12355 if (*input_line_pointer == '$')
12357 mips_cpreturn_register = tc_get_register (0);
12358 mips_cpreturn_offset = -1;
12362 mips_cpreturn_offset = get_absolute_expression ();
12363 mips_cpreturn_register = -1;
12365 SKIP_WHITESPACE ();
12366 if (*input_line_pointer != ',')
12368 as_bad (_("missing argument separator ',' for .cpsetup"));
12372 ++input_line_pointer;
12373 SKIP_WHITESPACE ();
12374 expression (&ex_sym);
12376 if (mips_cpreturn_register == -1)
12378 ex_off.X_op = O_constant;
12379 ex_off.X_add_symbol = NULL;
12380 ex_off.X_op_symbol = NULL;
12381 ex_off.X_add_number = mips_cpreturn_offset;
12383 macro_build (NULL, &icnt, &ex_off, "sd", "t,o(b)", mips_gp_register,
12384 BFD_RELOC_LO16, SP);
12387 macro_build (NULL, &icnt, NULL, "daddu", "d,v,t", mips_cpreturn_register,
12388 mips_gp_register, 0);
12390 /* Ensure there's room for the next two instructions, so that `f'
12391 doesn't end up with an address in the wrong frag. */
12394 macro_build (NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
12395 BFD_RELOC_GPREL16);
12396 fix_new (frag_now, f - frag_now->fr_literal,
12397 8, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
12398 fix_new (frag_now, f - frag_now->fr_literal,
12399 4, NULL, 0, 0, BFD_RELOC_HI16_S);
12402 macro_build (NULL, &icnt, &ex_sym, "addiu", "t,r,j", mips_gp_register,
12403 mips_gp_register, BFD_RELOC_GPREL16);
12404 fix_new (frag_now, f - frag_now->fr_literal,
12405 8, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
12406 fix_new (frag_now, f - frag_now->fr_literal,
12407 4, NULL, 0, 0, BFD_RELOC_LO16);
12409 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
12410 mips_gp_register, reg1);
12412 demand_empty_rest_of_line ();
12416 s_cplocal (int ignore ATTRIBUTE_UNUSED)
12418 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12419 .cplocal is ignored. */
12420 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12426 mips_gp_register = tc_get_register (0);
12427 demand_empty_rest_of_line ();
12430 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12431 offset from $sp. The offset is remembered, and after making a PIC
12432 call $gp is restored from that location. */
12435 s_cprestore (int ignore ATTRIBUTE_UNUSED)
12440 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12441 .cprestore is ignored. */
12442 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12448 mips_cprestore_offset = get_absolute_expression ();
12449 mips_cprestore_valid = 1;
12451 ex.X_op = O_constant;
12452 ex.X_add_symbol = NULL;
12453 ex.X_op_symbol = NULL;
12454 ex.X_add_number = mips_cprestore_offset;
12456 macro_build_ldst_constoffset (NULL, &icnt, &ex, ADDRESS_STORE_INSN,
12457 mips_gp_register, SP, HAVE_64BIT_ADDRESSES);
12459 demand_empty_rest_of_line ();
12462 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12463 was given in the preceding .cpsetup, it results in:
12464 ld $gp, offset($sp)
12466 If a register $reg2 was given there, it results in:
12467 daddu $gp, $reg2, $0
12470 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
12475 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12476 We also need NewABI support. */
12477 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12483 if (mips_cpreturn_register == -1)
12485 ex.X_op = O_constant;
12486 ex.X_add_symbol = NULL;
12487 ex.X_op_symbol = NULL;
12488 ex.X_add_number = mips_cpreturn_offset;
12490 macro_build (NULL, &icnt, &ex, "ld", "t,o(b)", mips_gp_register,
12491 BFD_RELOC_LO16, SP);
12494 macro_build (NULL, &icnt, NULL, "daddu", "d,v,t", mips_gp_register,
12495 mips_cpreturn_register, 0);
12497 demand_empty_rest_of_line ();
12500 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12501 code. It sets the offset to use in gp_rel relocations. */
12504 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
12506 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12507 We also need NewABI support. */
12508 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12514 mips_gprel_offset = get_absolute_expression ();
12516 demand_empty_rest_of_line ();
12519 /* Handle the .gpword pseudo-op. This is used when generating PIC
12520 code. It generates a 32 bit GP relative reloc. */
12523 s_gpword (int ignore ATTRIBUTE_UNUSED)
12529 /* When not generating PIC code, this is treated as .word. */
12530 if (mips_pic != SVR4_PIC)
12536 label = insn_labels != NULL ? insn_labels->label : NULL;
12537 mips_emit_delays (TRUE);
12539 mips_align (2, 0, label);
12540 mips_clear_insn_labels ();
12544 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12546 as_bad (_("Unsupported use of .gpword"));
12547 ignore_rest_of_line ();
12551 md_number_to_chars (p, 0, 4);
12552 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12553 BFD_RELOC_GPREL32);
12555 demand_empty_rest_of_line ();
12559 s_gpdword (int ignore ATTRIBUTE_UNUSED)
12565 /* When not generating PIC code, this is treated as .dword. */
12566 if (mips_pic != SVR4_PIC)
12572 label = insn_labels != NULL ? insn_labels->label : NULL;
12573 mips_emit_delays (TRUE);
12575 mips_align (3, 0, label);
12576 mips_clear_insn_labels ();
12580 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12582 as_bad (_("Unsupported use of .gpdword"));
12583 ignore_rest_of_line ();
12587 md_number_to_chars (p, 0, 8);
12588 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12589 BFD_RELOC_GPREL32);
12591 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12592 ex.X_op = O_absent;
12593 ex.X_add_symbol = 0;
12594 ex.X_add_number = 0;
12595 fix_new_exp (frag_now, p - frag_now->fr_literal, 8, &ex, FALSE,
12598 demand_empty_rest_of_line ();
12601 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12602 tables in SVR4 PIC code. */
12605 s_cpadd (int ignore ATTRIBUTE_UNUSED)
12610 /* This is ignored when not generating SVR4 PIC code. */
12611 if (mips_pic != SVR4_PIC)
12617 /* Add $gp to the register named as an argument. */
12618 reg = tc_get_register (0);
12619 macro_build (NULL, &icnt, NULL, ADDRESS_ADD_INSN, "d,v,t",
12620 reg, reg, mips_gp_register);
12622 demand_empty_rest_of_line ();
12625 /* Handle the .insn pseudo-op. This marks instruction labels in
12626 mips16 mode. This permits the linker to handle them specially,
12627 such as generating jalx instructions when needed. We also make
12628 them odd for the duration of the assembly, in order to generate the
12629 right sort of code. We will make them even in the adjust_symtab
12630 routine, while leaving them marked. This is convenient for the
12631 debugger and the disassembler. The linker knows to make them odd
12635 s_insn (int ignore ATTRIBUTE_UNUSED)
12637 mips16_mark_labels ();
12639 demand_empty_rest_of_line ();
12642 /* Handle a .stabn directive. We need these in order to mark a label
12643 as being a mips16 text label correctly. Sometimes the compiler
12644 will emit a label, followed by a .stabn, and then switch sections.
12645 If the label and .stabn are in mips16 mode, then the label is
12646 really a mips16 text label. */
12649 s_mips_stab (int type)
12652 mips16_mark_labels ();
12657 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12661 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
12668 name = input_line_pointer;
12669 c = get_symbol_end ();
12670 symbolP = symbol_find_or_make (name);
12671 S_SET_WEAK (symbolP);
12672 *input_line_pointer = c;
12674 SKIP_WHITESPACE ();
12676 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12678 if (S_IS_DEFINED (symbolP))
12680 as_bad ("ignoring attempt to redefine symbol %s",
12681 S_GET_NAME (symbolP));
12682 ignore_rest_of_line ();
12686 if (*input_line_pointer == ',')
12688 ++input_line_pointer;
12689 SKIP_WHITESPACE ();
12693 if (exp.X_op != O_symbol)
12695 as_bad ("bad .weakext directive");
12696 ignore_rest_of_line ();
12699 symbol_set_value_expression (symbolP, &exp);
12702 demand_empty_rest_of_line ();
12705 /* Parse a register string into a number. Called from the ECOFF code
12706 to parse .frame. The argument is non-zero if this is the frame
12707 register, so that we can record it in mips_frame_reg. */
12710 tc_get_register (int frame)
12714 SKIP_WHITESPACE ();
12715 if (*input_line_pointer++ != '$')
12717 as_warn (_("expected `$'"));
12720 else if (ISDIGIT (*input_line_pointer))
12722 reg = get_absolute_expression ();
12723 if (reg < 0 || reg >= 32)
12725 as_warn (_("Bad register number"));
12731 if (strncmp (input_line_pointer, "ra", 2) == 0)
12734 input_line_pointer += 2;
12736 else if (strncmp (input_line_pointer, "fp", 2) == 0)
12739 input_line_pointer += 2;
12741 else if (strncmp (input_line_pointer, "sp", 2) == 0)
12744 input_line_pointer += 2;
12746 else if (strncmp (input_line_pointer, "gp", 2) == 0)
12749 input_line_pointer += 2;
12751 else if (strncmp (input_line_pointer, "at", 2) == 0)
12754 input_line_pointer += 2;
12756 else if (strncmp (input_line_pointer, "kt0", 3) == 0)
12759 input_line_pointer += 3;
12761 else if (strncmp (input_line_pointer, "kt1", 3) == 0)
12764 input_line_pointer += 3;
12766 else if (strncmp (input_line_pointer, "zero", 4) == 0)
12769 input_line_pointer += 4;
12773 as_warn (_("Unrecognized register name"));
12775 while (ISALNUM(*input_line_pointer))
12776 input_line_pointer++;
12781 mips_frame_reg = reg != 0 ? reg : SP;
12782 mips_frame_reg_valid = 1;
12783 mips_cprestore_valid = 0;
12789 md_section_align (asection *seg, valueT addr)
12791 int align = bfd_get_section_alignment (stdoutput, seg);
12794 /* We don't need to align ELF sections to the full alignment.
12795 However, Irix 5 may prefer that we align them at least to a 16
12796 byte boundary. We don't bother to align the sections if we are
12797 targeted for an embedded system. */
12798 if (strcmp (TARGET_OS, "elf") == 0)
12804 return ((addr + (1 << align) - 1) & (-1 << align));
12807 /* Utility routine, called from above as well. If called while the
12808 input file is still being read, it's only an approximation. (For
12809 example, a symbol may later become defined which appeared to be
12810 undefined earlier.) */
12813 nopic_need_relax (symbolS *sym, int before_relaxing)
12818 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
12820 const char *symname;
12823 /* Find out whether this symbol can be referenced off the $gp
12824 register. It can be if it is smaller than the -G size or if
12825 it is in the .sdata or .sbss section. Certain symbols can
12826 not be referenced off the $gp, although it appears as though
12828 symname = S_GET_NAME (sym);
12829 if (symname != (const char *) NULL
12830 && (strcmp (symname, "eprol") == 0
12831 || strcmp (symname, "etext") == 0
12832 || strcmp (symname, "_gp") == 0
12833 || strcmp (symname, "edata") == 0
12834 || strcmp (symname, "_fbss") == 0
12835 || strcmp (symname, "_fdata") == 0
12836 || strcmp (symname, "_ftext") == 0
12837 || strcmp (symname, "end") == 0
12838 || strcmp (symname, "_gp_disp") == 0))
12840 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12842 #ifndef NO_ECOFF_DEBUGGING
12843 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12844 && (symbol_get_obj (sym)->ecoff_extern_size
12845 <= g_switch_value))
12847 /* We must defer this decision until after the whole
12848 file has been read, since there might be a .extern
12849 after the first use of this symbol. */
12850 || (before_relaxing
12851 #ifndef NO_ECOFF_DEBUGGING
12852 && symbol_get_obj (sym)->ecoff_extern_size == 0
12854 && S_GET_VALUE (sym) == 0)
12855 || (S_GET_VALUE (sym) != 0
12856 && S_GET_VALUE (sym) <= g_switch_value)))
12860 const char *segname;
12862 segname = segment_name (S_GET_SEGMENT (sym));
12863 assert (strcmp (segname, ".lit8") != 0
12864 && strcmp (segname, ".lit4") != 0);
12865 change = (strcmp (segname, ".sdata") != 0
12866 && strcmp (segname, ".sbss") != 0
12867 && strncmp (segname, ".sdata.", 7) != 0
12868 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12873 /* We are not optimizing for the $gp register. */
12878 /* Return true if the given symbol should be considered local for SVR4 PIC. */
12881 pic_need_relax (symbolS *sym, asection *segtype)
12884 bfd_boolean linkonce;
12886 /* Handle the case of a symbol equated to another symbol. */
12887 while (symbol_equated_reloc_p (sym))
12891 /* It's possible to get a loop here in a badly written
12893 n = symbol_get_value_expression (sym)->X_add_symbol;
12899 symsec = S_GET_SEGMENT (sym);
12901 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12903 if (symsec != segtype && ! S_IS_LOCAL (sym))
12905 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12909 /* The GNU toolchain uses an extension for ELF: a section
12910 beginning with the magic string .gnu.linkonce is a linkonce
12912 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12913 sizeof ".gnu.linkonce" - 1) == 0)
12917 /* This must duplicate the test in adjust_reloc_syms. */
12918 return (symsec != &bfd_und_section
12919 && symsec != &bfd_abs_section
12920 && ! bfd_is_com_section (symsec)
12923 /* A global or weak symbol is treated as external. */
12924 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12925 || (! S_IS_WEAK (sym)
12926 && (! S_IS_EXTERNAL (sym)
12927 || mips_pic == EMBEDDED_PIC)))
12933 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12934 extended opcode. SEC is the section the frag is in. */
12937 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
12940 register const struct mips16_immed_operand *op;
12942 int mintiny, maxtiny;
12946 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
12948 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
12951 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12952 op = mips16_immed_operands;
12953 while (op->type != type)
12956 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12961 if (type == '<' || type == '>' || type == '[' || type == ']')
12964 maxtiny = 1 << op->nbits;
12969 maxtiny = (1 << op->nbits) - 1;
12974 mintiny = - (1 << (op->nbits - 1));
12975 maxtiny = (1 << (op->nbits - 1)) - 1;
12978 sym_frag = symbol_get_frag (fragp->fr_symbol);
12979 val = S_GET_VALUE (fragp->fr_symbol);
12980 symsec = S_GET_SEGMENT (fragp->fr_symbol);
12986 /* We won't have the section when we are called from
12987 mips_relax_frag. However, we will always have been called
12988 from md_estimate_size_before_relax first. If this is a
12989 branch to a different section, we mark it as such. If SEC is
12990 NULL, and the frag is not marked, then it must be a branch to
12991 the same section. */
12994 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
12999 /* Must have been called from md_estimate_size_before_relax. */
13002 fragp->fr_subtype =
13003 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13005 /* FIXME: We should support this, and let the linker
13006 catch branches and loads that are out of range. */
13007 as_bad_where (fragp->fr_file, fragp->fr_line,
13008 _("unsupported PC relative reference to different section"));
13012 if (fragp != sym_frag && sym_frag->fr_address == 0)
13013 /* Assume non-extended on the first relaxation pass.
13014 The address we have calculated will be bogus if this is
13015 a forward branch to another frag, as the forward frag
13016 will have fr_address == 0. */
13020 /* In this case, we know for sure that the symbol fragment is in
13021 the same section. If the relax_marker of the symbol fragment
13022 differs from the relax_marker of this fragment, we have not
13023 yet adjusted the symbol fragment fr_address. We want to add
13024 in STRETCH in order to get a better estimate of the address.
13025 This particularly matters because of the shift bits. */
13027 && sym_frag->relax_marker != fragp->relax_marker)
13031 /* Adjust stretch for any alignment frag. Note that if have
13032 been expanding the earlier code, the symbol may be
13033 defined in what appears to be an earlier frag. FIXME:
13034 This doesn't handle the fr_subtype field, which specifies
13035 a maximum number of bytes to skip when doing an
13037 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
13039 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
13042 stretch = - ((- stretch)
13043 & ~ ((1 << (int) f->fr_offset) - 1));
13045 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
13054 addr = fragp->fr_address + fragp->fr_fix;
13056 /* The base address rules are complicated. The base address of
13057 a branch is the following instruction. The base address of a
13058 PC relative load or add is the instruction itself, but if it
13059 is in a delay slot (in which case it can not be extended) use
13060 the address of the instruction whose delay slot it is in. */
13061 if (type == 'p' || type == 'q')
13065 /* If we are currently assuming that this frag should be
13066 extended, then, the current address is two bytes
13068 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13071 /* Ignore the low bit in the target, since it will be set
13072 for a text label. */
13073 if ((val & 1) != 0)
13076 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13078 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13081 val -= addr & ~ ((1 << op->shift) - 1);
13083 /* Branch offsets have an implicit 0 in the lowest bit. */
13084 if (type == 'p' || type == 'q')
13087 /* If any of the shifted bits are set, we must use an extended
13088 opcode. If the address depends on the size of this
13089 instruction, this can lead to a loop, so we arrange to always
13090 use an extended opcode. We only check this when we are in
13091 the main relaxation loop, when SEC is NULL. */
13092 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
13094 fragp->fr_subtype =
13095 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13099 /* If we are about to mark a frag as extended because the value
13100 is precisely maxtiny + 1, then there is a chance of an
13101 infinite loop as in the following code:
13106 In this case when the la is extended, foo is 0x3fc bytes
13107 away, so the la can be shrunk, but then foo is 0x400 away, so
13108 the la must be extended. To avoid this loop, we mark the
13109 frag as extended if it was small, and is about to become
13110 extended with a value of maxtiny + 1. */
13111 if (val == ((maxtiny + 1) << op->shift)
13112 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
13115 fragp->fr_subtype =
13116 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13120 else if (symsec != absolute_section && sec != NULL)
13121 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
13123 if ((val & ((1 << op->shift) - 1)) != 0
13124 || val < (mintiny << op->shift)
13125 || val > (maxtiny << op->shift))
13131 /* Compute the length of a branch sequence, and adjust the
13132 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
13133 worst-case length is computed, with UPDATE being used to indicate
13134 whether an unconditional (-1), branch-likely (+1) or regular (0)
13135 branch is to be computed. */
13137 relaxed_branch_length (fragS *fragp, asection *sec, int update)
13139 bfd_boolean toofar;
13143 && S_IS_DEFINED (fragp->fr_symbol)
13144 && sec == S_GET_SEGMENT (fragp->fr_symbol))
13149 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
13151 addr = fragp->fr_address + fragp->fr_fix + 4;
13155 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
13158 /* If the symbol is not defined or it's in a different segment,
13159 assume the user knows what's going on and emit a short
13165 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13167 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp->fr_subtype),
13168 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
13169 RELAX_BRANCH_LINK (fragp->fr_subtype),
13175 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
13178 if (mips_pic != NO_PIC)
13180 /* Additional space for PIC loading of target address. */
13182 if (mips_opts.isa == ISA_MIPS1)
13183 /* Additional space for $at-stabilizing nop. */
13187 /* If branch is conditional. */
13188 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
13195 /* Estimate the size of a frag before relaxing. Unless this is the
13196 mips16, we are not really relaxing here, and the final size is
13197 encoded in the subtype information. For the mips16, we have to
13198 decide whether we are using an extended opcode or not. */
13201 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
13205 if (RELAX_BRANCH_P (fragp->fr_subtype))
13208 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
13210 return fragp->fr_var;
13213 if (RELAX_MIPS16_P (fragp->fr_subtype))
13214 /* We don't want to modify the EXTENDED bit here; it might get us
13215 into infinite loops. We change it only in mips_relax_frag(). */
13216 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
13218 if (mips_pic == NO_PIC)
13219 change = nopic_need_relax (fragp->fr_symbol, 0);
13220 else if (mips_pic == SVR4_PIC)
13221 change = pic_need_relax (fragp->fr_symbol, segtype);
13227 /* Record the offset to the first reloc in the fr_opcode field.
13228 This lets md_convert_frag and tc_gen_reloc know that the code
13229 must be expanded. */
13230 fragp->fr_opcode = (fragp->fr_literal
13232 - RELAX_OLD (fragp->fr_subtype)
13233 + RELAX_RELOC1 (fragp->fr_subtype));
13234 /* FIXME: This really needs as_warn_where. */
13235 if (RELAX_WARN (fragp->fr_subtype))
13236 as_warn (_("AT used after \".set noat\" or macro used after "
13237 "\".set nomacro\""));
13239 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
13245 /* This is called to see whether a reloc against a defined symbol
13246 should be converted into a reloc against a section. Don't adjust
13247 MIPS16 jump relocations, so we don't have to worry about the format
13248 of the offset in the .o file. Don't adjust relocations against
13249 mips16 symbols, so that the linker can find them if it needs to set
13253 mips_fix_adjustable (fixS *fixp)
13255 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
13258 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
13259 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13262 if (fixp->fx_addsy == NULL)
13266 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
13267 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
13268 && fixp->fx_subsy == NULL)
13275 /* Translate internal representation of relocation info to BFD target
13279 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
13281 static arelent *retval[4];
13283 bfd_reloc_code_real_type code;
13285 memset (retval, 0, sizeof(retval));
13286 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
13287 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13288 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13289 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13291 if (mips_pic == EMBEDDED_PIC
13292 && SWITCH_TABLE (fixp))
13294 /* For a switch table entry we use a special reloc. The addend
13295 is actually the difference between the reloc address and the
13297 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
13298 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
13299 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
13300 fixp->fx_r_type = BFD_RELOC_GPREL32;
13302 else if (fixp->fx_pcrel)
13304 bfd_vma pcrel_address;
13306 /* Set PCREL_ADDRESS to this relocation's "PC". The PC for high
13307 high-part relocs is the address of the low-part reloc. */
13308 if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
13310 assert (fixp->fx_next != NULL
13311 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
13312 pcrel_address = (fixp->fx_next->fx_where
13313 + fixp->fx_next->fx_frag->fr_address);
13316 pcrel_address = reloc->address;
13318 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
13320 /* At this point, fx_addnumber is "symbol offset - pcrel_address".
13321 Relocations want only the symbol offset. */
13322 reloc->addend = fixp->fx_addnumber + pcrel_address;
13324 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16
13325 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
13327 /* We use a special addend for an internal RELLO or RELHI reloc. */
13328 if (symbol_section_p (fixp->fx_addsy))
13329 reloc->addend = pcrel_address - S_GET_VALUE (fixp->fx_subsy);
13331 reloc->addend = fixp->fx_addnumber + pcrel_address;
13335 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
13336 /* A gruesome hack which is a result of the gruesome gas reloc
13338 reloc->addend = pcrel_address;
13340 reloc->addend = -pcrel_address;
13344 reloc->addend = fixp->fx_addnumber;
13346 /* If this is a variant frag, we may need to adjust the existing
13347 reloc and generate a new one. */
13348 if (fixp->fx_frag->fr_opcode != NULL
13349 && ((fixp->fx_r_type == BFD_RELOC_GPREL16
13351 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_DISP
13353 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
13354 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
13355 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
13356 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
13357 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
13358 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
13363 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
13365 /* If this is not the last reloc in this frag, then we have two
13366 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
13367 CALL_HI16/CALL_LO16, both of which are being replaced. Let
13368 the second one handle all of them. */
13369 if (fixp->fx_next != NULL
13370 && fixp->fx_frag == fixp->fx_next->fx_frag)
13372 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
13373 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
13374 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
13375 && (fixp->fx_next->fx_r_type
13376 == BFD_RELOC_MIPS_GOT_LO16))
13377 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
13378 && (fixp->fx_next->fx_r_type
13379 == BFD_RELOC_MIPS_CALL_LO16)));
13384 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
13385 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13386 reloc->addend += fixp->fx_frag->tc_frag_data.tc_fr_offset;
13387 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
13388 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13389 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13390 reloc2->address = (reloc->address
13391 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
13392 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
13393 reloc2->addend = reloc->addend;
13394 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
13395 assert (reloc2->howto != NULL);
13397 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
13401 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
13403 reloc3->address += 4;
13406 if (mips_pic == NO_PIC)
13408 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
13409 fixp->fx_r_type = BFD_RELOC_HI16_S;
13411 else if (mips_pic == SVR4_PIC)
13413 switch (fixp->fx_r_type)
13417 case BFD_RELOC_MIPS_GOT16:
13419 case BFD_RELOC_MIPS_GOT_LO16:
13420 case BFD_RELOC_MIPS_CALL_LO16:
13423 fixp->fx_r_type = BFD_RELOC_MIPS_GOT_PAGE;
13424 reloc2->howto = bfd_reloc_type_lookup
13425 (stdoutput, BFD_RELOC_MIPS_GOT_OFST);
13428 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
13430 case BFD_RELOC_MIPS_CALL16:
13431 case BFD_RELOC_MIPS_GOT_OFST:
13432 case BFD_RELOC_MIPS_GOT_DISP:
13435 /* It may seem nonsensical to relax GOT_DISP to
13436 GOT_DISP, but we're actually turning a GOT_DISP
13437 without offset into a GOT_DISP with an offset,
13438 getting rid of the separate addition, which we can
13439 do when the symbol is found to be local. */
13440 fixp->fx_r_type = BFD_RELOC_MIPS_GOT_DISP;
13444 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
13452 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13453 entry to be used in the relocation's section offset. */
13454 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13456 reloc->address = reloc->addend;
13460 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
13461 fixup_segment converted a non-PC relative reloc into a PC
13462 relative reloc. In such a case, we need to convert the reloc
13464 code = fixp->fx_r_type;
13465 if (fixp->fx_pcrel)
13470 code = BFD_RELOC_8_PCREL;
13473 code = BFD_RELOC_16_PCREL;
13476 code = BFD_RELOC_32_PCREL;
13479 code = BFD_RELOC_64_PCREL;
13481 case BFD_RELOC_8_PCREL:
13482 case BFD_RELOC_16_PCREL:
13483 case BFD_RELOC_32_PCREL:
13484 case BFD_RELOC_64_PCREL:
13485 case BFD_RELOC_16_PCREL_S2:
13486 case BFD_RELOC_PCREL_HI16_S:
13487 case BFD_RELOC_PCREL_LO16:
13490 as_bad_where (fixp->fx_file, fixp->fx_line,
13491 _("Cannot make %s relocation PC relative"),
13492 bfd_get_reloc_code_name (code));
13496 /* To support a PC relative reloc when generating embedded PIC code
13497 for ECOFF, we use a Cygnus extension. We check for that here to
13498 make sure that we don't let such a reloc escape normally. */
13499 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
13500 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
13501 && code == BFD_RELOC_16_PCREL_S2
13502 && mips_pic != EMBEDDED_PIC)
13503 reloc->howto = NULL;
13505 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
13507 if (reloc->howto == NULL)
13509 as_bad_where (fixp->fx_file, fixp->fx_line,
13510 _("Can not represent %s relocation in this object file format"),
13511 bfd_get_reloc_code_name (code));
13518 /* Relax a machine dependent frag. This returns the amount by which
13519 the current size of the frag should change. */
13522 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
13524 if (RELAX_BRANCH_P (fragp->fr_subtype))
13526 offsetT old_var = fragp->fr_var;
13528 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
13530 return fragp->fr_var - old_var;
13533 if (! RELAX_MIPS16_P (fragp->fr_subtype))
13536 if (mips16_extended_frag (fragp, NULL, stretch))
13538 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13540 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
13545 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13547 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
13554 /* Convert a machine dependent frag. */
13557 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
13562 if (RELAX_BRANCH_P (fragp->fr_subtype))
13565 unsigned long insn;
13569 buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
13571 if (target_big_endian)
13572 insn = bfd_getb32 (buf);
13574 insn = bfd_getl32 (buf);
13576 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13578 /* We generate a fixup instead of applying it right now
13579 because, if there are linker relaxations, we're going to
13580 need the relocations. */
13581 exp.X_op = O_symbol;
13582 exp.X_add_symbol = fragp->fr_symbol;
13583 exp.X_add_number = fragp->fr_offset;
13585 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13587 BFD_RELOC_16_PCREL_S2);
13588 fixp->fx_file = fragp->fr_file;
13589 fixp->fx_line = fragp->fr_line;
13591 md_number_to_chars (buf, insn, 4);
13598 as_warn_where (fragp->fr_file, fragp->fr_line,
13599 _("relaxed out-of-range branch into a jump"));
13601 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
13604 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13606 /* Reverse the branch. */
13607 switch ((insn >> 28) & 0xf)
13610 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13611 have the condition reversed by tweaking a single
13612 bit, and their opcodes all have 0x4???????. */
13613 assert ((insn & 0xf1000000) == 0x41000000);
13614 insn ^= 0x00010000;
13618 /* bltz 0x04000000 bgez 0x04010000
13619 bltzal 0x04100000 bgezal 0x04110000 */
13620 assert ((insn & 0xfc0e0000) == 0x04000000);
13621 insn ^= 0x00010000;
13625 /* beq 0x10000000 bne 0x14000000
13626 blez 0x18000000 bgtz 0x1c000000 */
13627 insn ^= 0x04000000;
13635 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13637 /* Clear the and-link bit. */
13638 assert ((insn & 0xfc1c0000) == 0x04100000);
13640 /* bltzal 0x04100000 bgezal 0x04110000
13641 bltzall 0x04120000 bgezall 0x04130000 */
13642 insn &= ~0x00100000;
13645 /* Branch over the branch (if the branch was likely) or the
13646 full jump (not likely case). Compute the offset from the
13647 current instruction to branch to. */
13648 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13652 /* How many bytes in instructions we've already emitted? */
13653 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13654 /* How many bytes in instructions from here to the end? */
13655 i = fragp->fr_var - i;
13657 /* Convert to instruction count. */
13659 /* Branch counts from the next instruction. */
13662 /* Branch over the jump. */
13663 md_number_to_chars (buf, insn, 4);
13667 md_number_to_chars (buf, 0, 4);
13670 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13672 /* beql $0, $0, 2f */
13674 /* Compute the PC offset from the current instruction to
13675 the end of the variable frag. */
13676 /* How many bytes in instructions we've already emitted? */
13677 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13678 /* How many bytes in instructions from here to the end? */
13679 i = fragp->fr_var - i;
13680 /* Convert to instruction count. */
13682 /* Don't decrement i, because we want to branch over the
13686 md_number_to_chars (buf, insn, 4);
13689 md_number_to_chars (buf, 0, 4);
13694 if (mips_pic == NO_PIC)
13697 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
13698 ? 0x0c000000 : 0x08000000);
13699 exp.X_op = O_symbol;
13700 exp.X_add_symbol = fragp->fr_symbol;
13701 exp.X_add_number = fragp->fr_offset;
13703 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13704 4, &exp, 0, BFD_RELOC_MIPS_JMP);
13705 fixp->fx_file = fragp->fr_file;
13706 fixp->fx_line = fragp->fr_line;
13708 md_number_to_chars (buf, insn, 4);
13713 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13714 insn = HAVE_64BIT_ADDRESSES ? 0xdf810000 : 0x8f810000;
13715 exp.X_op = O_symbol;
13716 exp.X_add_symbol = fragp->fr_symbol;
13717 exp.X_add_number = fragp->fr_offset;
13719 if (fragp->fr_offset)
13721 exp.X_add_symbol = make_expr_symbol (&exp);
13722 exp.X_add_number = 0;
13725 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13726 4, &exp, 0, BFD_RELOC_MIPS_GOT16);
13727 fixp->fx_file = fragp->fr_file;
13728 fixp->fx_line = fragp->fr_line;
13730 md_number_to_chars (buf, insn, 4);
13733 if (mips_opts.isa == ISA_MIPS1)
13736 md_number_to_chars (buf, 0, 4);
13740 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
13741 insn = HAVE_64BIT_ADDRESSES ? 0x64210000 : 0x24210000;
13743 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13744 4, &exp, 0, BFD_RELOC_LO16);
13745 fixp->fx_file = fragp->fr_file;
13746 fixp->fx_line = fragp->fr_line;
13748 md_number_to_chars (buf, insn, 4);
13752 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13757 md_number_to_chars (buf, insn, 4);
13762 assert (buf == (bfd_byte *)fragp->fr_literal
13763 + fragp->fr_fix + fragp->fr_var);
13765 fragp->fr_fix += fragp->fr_var;
13770 if (RELAX_MIPS16_P (fragp->fr_subtype))
13773 register const struct mips16_immed_operand *op;
13774 bfd_boolean small, ext;
13777 unsigned long insn;
13778 bfd_boolean use_extend;
13779 unsigned short extend;
13781 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13782 op = mips16_immed_operands;
13783 while (op->type != type)
13786 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13797 resolve_symbol_value (fragp->fr_symbol);
13798 val = S_GET_VALUE (fragp->fr_symbol);
13803 addr = fragp->fr_address + fragp->fr_fix;
13805 /* The rules for the base address of a PC relative reloc are
13806 complicated; see mips16_extended_frag. */
13807 if (type == 'p' || type == 'q')
13812 /* Ignore the low bit in the target, since it will be
13813 set for a text label. */
13814 if ((val & 1) != 0)
13817 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13819 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13822 addr &= ~ (addressT) ((1 << op->shift) - 1);
13825 /* Make sure the section winds up with the alignment we have
13828 record_alignment (asec, op->shift);
13832 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
13833 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
13834 as_warn_where (fragp->fr_file, fragp->fr_line,
13835 _("extended instruction in delay slot"));
13837 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
13839 if (target_big_endian)
13840 insn = bfd_getb16 (buf);
13842 insn = bfd_getl16 (buf);
13844 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
13845 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
13846 small, ext, &insn, &use_extend, &extend);
13850 md_number_to_chars (buf, 0xf000 | extend, 2);
13851 fragp->fr_fix += 2;
13855 md_number_to_chars (buf, insn, 2);
13856 fragp->fr_fix += 2;
13861 if (fragp->fr_opcode == NULL)
13864 old = RELAX_OLD (fragp->fr_subtype);
13865 new = RELAX_NEW (fragp->fr_subtype);
13866 fixptr = fragp->fr_literal + fragp->fr_fix;
13869 memmove (fixptr - old, fixptr, new);
13871 fragp->fr_fix += new - old;
13877 /* This function is called after the relocs have been generated.
13878 We've been storing mips16 text labels as odd. Here we convert them
13879 back to even for the convenience of the debugger. */
13882 mips_frob_file_after_relocs (void)
13885 unsigned int count, i;
13887 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
13890 syms = bfd_get_outsymbols (stdoutput);
13891 count = bfd_get_symcount (stdoutput);
13892 for (i = 0; i < count; i++, syms++)
13894 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
13895 && ((*syms)->value & 1) != 0)
13897 (*syms)->value &= ~1;
13898 /* If the symbol has an odd size, it was probably computed
13899 incorrectly, so adjust that as well. */
13900 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
13901 ++elf_symbol (*syms)->internal_elf_sym.st_size;
13908 /* This function is called whenever a label is defined. It is used
13909 when handling branch delays; if a branch has a label, we assume we
13910 can not move it. */
13913 mips_define_label (symbolS *sym)
13915 struct insn_label_list *l;
13917 if (free_insn_labels == NULL)
13918 l = (struct insn_label_list *) xmalloc (sizeof *l);
13921 l = free_insn_labels;
13922 free_insn_labels = l->next;
13926 l->next = insn_labels;
13930 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13932 /* Some special processing for a MIPS ELF file. */
13935 mips_elf_final_processing (void)
13937 /* Write out the register information. */
13938 if (mips_abi != N64_ABI)
13942 s.ri_gprmask = mips_gprmask;
13943 s.ri_cprmask[0] = mips_cprmask[0];
13944 s.ri_cprmask[1] = mips_cprmask[1];
13945 s.ri_cprmask[2] = mips_cprmask[2];
13946 s.ri_cprmask[3] = mips_cprmask[3];
13947 /* The gp_value field is set by the MIPS ELF backend. */
13949 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
13950 ((Elf32_External_RegInfo *)
13951 mips_regmask_frag));
13955 Elf64_Internal_RegInfo s;
13957 s.ri_gprmask = mips_gprmask;
13959 s.ri_cprmask[0] = mips_cprmask[0];
13960 s.ri_cprmask[1] = mips_cprmask[1];
13961 s.ri_cprmask[2] = mips_cprmask[2];
13962 s.ri_cprmask[3] = mips_cprmask[3];
13963 /* The gp_value field is set by the MIPS ELF backend. */
13965 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
13966 ((Elf64_External_RegInfo *)
13967 mips_regmask_frag));
13970 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13971 sort of BFD interface for this. */
13972 if (mips_any_noreorder)
13973 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
13974 if (mips_pic != NO_PIC)
13976 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
13977 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
13980 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
13982 /* Set MIPS ELF flags for ASEs. */
13983 if (file_ase_mips16)
13984 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
13985 #if 0 /* XXX FIXME */
13986 if (file_ase_mips3d)
13987 elf_elfheader (stdoutput)->e_flags |= ???;
13990 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
13992 /* Set the MIPS ELF ABI flags. */
13993 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
13994 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
13995 else if (mips_abi == O64_ABI)
13996 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
13997 else if (mips_abi == EABI_ABI)
13999 if (!file_mips_gp32)
14000 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
14002 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
14004 else if (mips_abi == N32_ABI)
14005 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
14007 /* Nothing to do for N64_ABI. */
14009 if (mips_32bitmode)
14010 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
14013 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
14015 typedef struct proc {
14017 unsigned long reg_mask;
14018 unsigned long reg_offset;
14019 unsigned long fpreg_mask;
14020 unsigned long fpreg_offset;
14021 unsigned long frame_offset;
14022 unsigned long frame_reg;
14023 unsigned long pc_reg;
14026 static procS cur_proc;
14027 static procS *cur_proc_ptr;
14028 static int numprocs;
14030 /* Fill in an rs_align_code fragment. */
14033 mips_handle_align (fragS *fragp)
14035 if (fragp->fr_type != rs_align_code)
14038 if (mips_opts.mips16)
14040 static const unsigned char be_nop[] = { 0x65, 0x00 };
14041 static const unsigned char le_nop[] = { 0x00, 0x65 };
14046 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
14047 p = fragp->fr_literal + fragp->fr_fix;
14055 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
14059 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
14063 md_obj_begin (void)
14070 /* check for premature end, nesting errors, etc */
14072 as_warn (_("missing .end at end of assembly"));
14081 if (*input_line_pointer == '-')
14083 ++input_line_pointer;
14086 if (!ISDIGIT (*input_line_pointer))
14087 as_bad (_("expected simple number"));
14088 if (input_line_pointer[0] == '0')
14090 if (input_line_pointer[1] == 'x')
14092 input_line_pointer += 2;
14093 while (ISXDIGIT (*input_line_pointer))
14096 val |= hex_value (*input_line_pointer++);
14098 return negative ? -val : val;
14102 ++input_line_pointer;
14103 while (ISDIGIT (*input_line_pointer))
14106 val |= *input_line_pointer++ - '0';
14108 return negative ? -val : val;
14111 if (!ISDIGIT (*input_line_pointer))
14113 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
14114 *input_line_pointer, *input_line_pointer);
14115 as_warn (_("invalid number"));
14118 while (ISDIGIT (*input_line_pointer))
14121 val += *input_line_pointer++ - '0';
14123 return negative ? -val : val;
14126 /* The .file directive; just like the usual .file directive, but there
14127 is an initial number which is the ECOFF file index. In the non-ECOFF
14128 case .file implies DWARF-2. */
14131 s_mips_file (int x ATTRIBUTE_UNUSED)
14133 static int first_file_directive = 0;
14135 if (ECOFF_DEBUGGING)
14144 filename = dwarf2_directive_file (0);
14146 /* Versions of GCC up to 3.1 start files with a ".file"
14147 directive even for stabs output. Make sure that this
14148 ".file" is handled. Note that you need a version of GCC
14149 after 3.1 in order to support DWARF-2 on MIPS. */
14150 if (filename != NULL && ! first_file_directive)
14152 (void) new_logical_line (filename, -1);
14153 s_app_file_string (filename);
14155 first_file_directive = 1;
14159 /* The .loc directive, implying DWARF-2. */
14162 s_mips_loc (int x ATTRIBUTE_UNUSED)
14164 if (!ECOFF_DEBUGGING)
14165 dwarf2_directive_loc (0);
14168 /* The .end directive. */
14171 s_mips_end (int x ATTRIBUTE_UNUSED)
14175 /* Following functions need their own .frame and .cprestore directives. */
14176 mips_frame_reg_valid = 0;
14177 mips_cprestore_valid = 0;
14179 if (!is_end_of_line[(unsigned char) *input_line_pointer])
14182 demand_empty_rest_of_line ();
14187 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14188 as_warn (_(".end not in text section"));
14192 as_warn (_(".end directive without a preceding .ent directive."));
14193 demand_empty_rest_of_line ();
14199 assert (S_GET_NAME (p));
14200 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
14201 as_warn (_(".end symbol does not match .ent symbol."));
14203 if (debug_type == DEBUG_STABS)
14204 stabs_generate_asm_endfunc (S_GET_NAME (p),
14208 as_warn (_(".end directive missing or unknown symbol"));
14211 /* Generate a .pdr section. */
14212 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING
14215 segT saved_seg = now_seg;
14216 subsegT saved_subseg = now_subseg;
14221 dot = frag_now_fix ();
14223 #ifdef md_flush_pending_output
14224 md_flush_pending_output ();
14228 subseg_set (pdr_seg, 0);
14230 /* Write the symbol. */
14231 exp.X_op = O_symbol;
14232 exp.X_add_symbol = p;
14233 exp.X_add_number = 0;
14234 emit_expr (&exp, 4);
14236 fragp = frag_more (7 * 4);
14238 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
14239 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
14240 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
14241 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
14242 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
14243 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
14244 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
14246 subseg_set (saved_seg, saved_subseg);
14248 #endif /* OBJ_ELF */
14250 cur_proc_ptr = NULL;
14253 /* The .aent and .ent directives. */
14256 s_mips_ent (int aent)
14260 symbolP = get_symbol ();
14261 if (*input_line_pointer == ',')
14262 ++input_line_pointer;
14263 SKIP_WHITESPACE ();
14264 if (ISDIGIT (*input_line_pointer)
14265 || *input_line_pointer == '-')
14268 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14269 as_warn (_(".ent or .aent not in text section."));
14271 if (!aent && cur_proc_ptr)
14272 as_warn (_("missing .end"));
14276 /* This function needs its own .frame and .cprestore directives. */
14277 mips_frame_reg_valid = 0;
14278 mips_cprestore_valid = 0;
14280 cur_proc_ptr = &cur_proc;
14281 memset (cur_proc_ptr, '\0', sizeof (procS));
14283 cur_proc_ptr->isym = symbolP;
14285 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
14289 if (debug_type == DEBUG_STABS)
14290 stabs_generate_asm_func (S_GET_NAME (symbolP),
14291 S_GET_NAME (symbolP));
14294 demand_empty_rest_of_line ();
14297 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
14298 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
14299 s_mips_frame is used so that we can set the PDR information correctly.
14300 We can't use the ecoff routines because they make reference to the ecoff
14301 symbol table (in the mdebug section). */
14304 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
14307 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14311 if (cur_proc_ptr == (procS *) NULL)
14313 as_warn (_(".frame outside of .ent"));
14314 demand_empty_rest_of_line ();
14318 cur_proc_ptr->frame_reg = tc_get_register (1);
14320 SKIP_WHITESPACE ();
14321 if (*input_line_pointer++ != ','
14322 || get_absolute_expression_and_terminator (&val) != ',')
14324 as_warn (_("Bad .frame directive"));
14325 --input_line_pointer;
14326 demand_empty_rest_of_line ();
14330 cur_proc_ptr->frame_offset = val;
14331 cur_proc_ptr->pc_reg = tc_get_register (0);
14333 demand_empty_rest_of_line ();
14336 #endif /* OBJ_ELF */
14340 /* The .fmask and .mask directives. If the mdebug section is present
14341 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14342 embedded targets, s_mips_mask is used so that we can set the PDR
14343 information correctly. We can't use the ecoff routines because they
14344 make reference to the ecoff symbol table (in the mdebug section). */
14347 s_mips_mask (int reg_type)
14350 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14354 if (cur_proc_ptr == (procS *) NULL)
14356 as_warn (_(".mask/.fmask outside of .ent"));
14357 demand_empty_rest_of_line ();
14361 if (get_absolute_expression_and_terminator (&mask) != ',')
14363 as_warn (_("Bad .mask/.fmask directive"));
14364 --input_line_pointer;
14365 demand_empty_rest_of_line ();
14369 off = get_absolute_expression ();
14371 if (reg_type == 'F')
14373 cur_proc_ptr->fpreg_mask = mask;
14374 cur_proc_ptr->fpreg_offset = off;
14378 cur_proc_ptr->reg_mask = mask;
14379 cur_proc_ptr->reg_offset = off;
14382 demand_empty_rest_of_line ();
14385 #endif /* OBJ_ELF */
14386 s_ignore (reg_type);
14389 /* The .loc directive. */
14399 assert (now_seg == text_section);
14401 lineno = get_number ();
14402 addroff = frag_now_fix ();
14404 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
14405 S_SET_TYPE (symbolP, N_SLINE);
14406 S_SET_OTHER (symbolP, 0);
14407 S_SET_DESC (symbolP, lineno);
14408 symbolP->sy_segment = now_seg;
14412 /* A table describing all the processors gas knows about. Names are
14413 matched in the order listed.
14415 To ease comparison, please keep this table in the same order as
14416 gcc's mips_cpu_info_table[]. */
14417 static const struct mips_cpu_info mips_cpu_info_table[] =
14419 /* Entries for generic ISAs */
14420 { "mips1", 1, ISA_MIPS1, CPU_R3000 },
14421 { "mips2", 1, ISA_MIPS2, CPU_R6000 },
14422 { "mips3", 1, ISA_MIPS3, CPU_R4000 },
14423 { "mips4", 1, ISA_MIPS4, CPU_R8000 },
14424 { "mips5", 1, ISA_MIPS5, CPU_MIPS5 },
14425 { "mips32", 1, ISA_MIPS32, CPU_MIPS32 },
14426 { "mips32r2", 1, ISA_MIPS32R2, CPU_MIPS32R2 },
14427 { "mips64", 1, ISA_MIPS64, CPU_MIPS64 },
14428 { "mips64r2", 1, ISA_MIPS64R2, CPU_MIPS64R2 },
14431 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
14432 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
14433 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
14436 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
14439 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
14440 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
14441 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
14442 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
14443 { "vr4120", 0, ISA_MIPS3, CPU_VR4120 },
14444 { "vr4130", 0, ISA_MIPS3, CPU_VR4120 },
14445 { "vr4181", 0, ISA_MIPS3, CPU_R4111 },
14446 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
14447 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
14448 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
14449 { "orion", 0, ISA_MIPS3, CPU_R4600 },
14450 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
14453 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
14454 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
14455 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
14456 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
14457 { "vr5400", 0, ISA_MIPS4, CPU_VR5400 },
14458 { "vr5500", 0, ISA_MIPS4, CPU_VR5500 },
14459 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
14460 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
14461 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
14462 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
14463 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
14464 { "rm7000", 0, ISA_MIPS4, CPU_RM7000 },
14465 { "rm9000", 0, ISA_MIPS4, CPU_RM7000 },
14468 { "4kc", 0, ISA_MIPS32, CPU_MIPS32 },
14469 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
14470 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
14473 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
14474 { "20kc", 0, ISA_MIPS64, CPU_MIPS64 },
14476 /* Broadcom SB-1 CPU core */
14477 { "sb1", 0, ISA_MIPS64, CPU_SB1 },
14484 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14485 with a final "000" replaced by "k". Ignore case.
14487 Note: this function is shared between GCC and GAS. */
14490 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
14492 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
14493 given++, canonical++;
14495 return ((*given == 0 && *canonical == 0)
14496 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
14500 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14501 CPU name. We've traditionally allowed a lot of variation here.
14503 Note: this function is shared between GCC and GAS. */
14506 mips_matching_cpu_name_p (const char *canonical, const char *given)
14508 /* First see if the name matches exactly, or with a final "000"
14509 turned into "k". */
14510 if (mips_strict_matching_cpu_name_p (canonical, given))
14513 /* If not, try comparing based on numerical designation alone.
14514 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14515 if (TOLOWER (*given) == 'r')
14517 if (!ISDIGIT (*given))
14520 /* Skip over some well-known prefixes in the canonical name,
14521 hoping to find a number there too. */
14522 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
14524 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
14526 else if (TOLOWER (canonical[0]) == 'r')
14529 return mips_strict_matching_cpu_name_p (canonical, given);
14533 /* Parse an option that takes the name of a processor as its argument.
14534 OPTION is the name of the option and CPU_STRING is the argument.
14535 Return the corresponding processor enumeration if the CPU_STRING is
14536 recognized, otherwise report an error and return null.
14538 A similar function exists in GCC. */
14540 static const struct mips_cpu_info *
14541 mips_parse_cpu (const char *option, const char *cpu_string)
14543 const struct mips_cpu_info *p;
14545 /* 'from-abi' selects the most compatible architecture for the given
14546 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14547 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14548 version. Look first at the -mgp options, if given, otherwise base
14549 the choice on MIPS_DEFAULT_64BIT.
14551 Treat NO_ABI like the EABIs. One reason to do this is that the
14552 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14553 architecture. This code picks MIPS I for 'mips' and MIPS III for
14554 'mips64', just as we did in the days before 'from-abi'. */
14555 if (strcasecmp (cpu_string, "from-abi") == 0)
14557 if (ABI_NEEDS_32BIT_REGS (mips_abi))
14558 return mips_cpu_info_from_isa (ISA_MIPS1);
14560 if (ABI_NEEDS_64BIT_REGS (mips_abi))
14561 return mips_cpu_info_from_isa (ISA_MIPS3);
14563 if (file_mips_gp32 >= 0)
14564 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
14566 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14571 /* 'default' has traditionally been a no-op. Probably not very useful. */
14572 if (strcasecmp (cpu_string, "default") == 0)
14575 for (p = mips_cpu_info_table; p->name != 0; p++)
14576 if (mips_matching_cpu_name_p (p->name, cpu_string))
14579 as_bad ("Bad value (%s) for %s", cpu_string, option);
14583 /* Return the canonical processor information for ISA (a member of the
14584 ISA_MIPS* enumeration). */
14586 static const struct mips_cpu_info *
14587 mips_cpu_info_from_isa (int isa)
14591 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14592 if (mips_cpu_info_table[i].is_isa
14593 && isa == mips_cpu_info_table[i].isa)
14594 return (&mips_cpu_info_table[i]);
14599 static const struct mips_cpu_info *
14600 mips_cpu_info_from_arch (int arch)
14604 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14605 if (arch == mips_cpu_info_table[i].cpu)
14606 return (&mips_cpu_info_table[i]);
14612 show (FILE *stream, const char *string, int *col_p, int *first_p)
14616 fprintf (stream, "%24s", "");
14621 fprintf (stream, ", ");
14625 if (*col_p + strlen (string) > 72)
14627 fprintf (stream, "\n%24s", "");
14631 fprintf (stream, "%s", string);
14632 *col_p += strlen (string);
14638 md_show_usage (FILE *stream)
14643 fprintf (stream, _("\
14645 -membedded-pic generate embedded position independent code\n\
14646 -EB generate big endian output\n\
14647 -EL generate little endian output\n\
14648 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14649 -G NUM allow referencing objects up to NUM bytes\n\
14650 implicitly with the gp register [default 8]\n"));
14651 fprintf (stream, _("\
14652 -mips1 generate MIPS ISA I instructions\n\
14653 -mips2 generate MIPS ISA II instructions\n\
14654 -mips3 generate MIPS ISA III instructions\n\
14655 -mips4 generate MIPS ISA IV instructions\n\
14656 -mips5 generate MIPS ISA V instructions\n\
14657 -mips32 generate MIPS32 ISA instructions\n\
14658 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
14659 -mips64 generate MIPS64 ISA instructions\n\
14660 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
14661 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14665 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14666 show (stream, mips_cpu_info_table[i].name, &column, &first);
14667 show (stream, "from-abi", &column, &first);
14668 fputc ('\n', stream);
14670 fprintf (stream, _("\
14671 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14672 -no-mCPU don't generate code specific to CPU.\n\
14673 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14677 show (stream, "3900", &column, &first);
14678 show (stream, "4010", &column, &first);
14679 show (stream, "4100", &column, &first);
14680 show (stream, "4650", &column, &first);
14681 fputc ('\n', stream);
14683 fprintf (stream, _("\
14684 -mips16 generate mips16 instructions\n\
14685 -no-mips16 do not generate mips16 instructions\n"));
14686 fprintf (stream, _("\
14687 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14688 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14689 -O0 remove unneeded NOPs, do not swap branches\n\
14690 -O remove unneeded NOPs and swap branches\n\
14691 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14692 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14693 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14695 fprintf (stream, _("\
14696 -KPIC, -call_shared generate SVR4 position independent code\n\
14697 -non_shared do not generate position independent code\n\
14698 -xgot assume a 32 bit GOT\n\
14699 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
14700 -mabi=ABI create ABI conformant object file for:\n"));
14704 show (stream, "32", &column, &first);
14705 show (stream, "o64", &column, &first);
14706 show (stream, "n32", &column, &first);
14707 show (stream, "64", &column, &first);
14708 show (stream, "eabi", &column, &first);
14710 fputc ('\n', stream);
14712 fprintf (stream, _("\
14713 -32 create o32 ABI object file (default)\n\
14714 -n32 create n32 ABI object file\n\
14715 -64 create 64 ABI object file\n"));
14720 mips_dwarf2_format (void)
14722 if (mips_abi == N64_ABI)
14725 return dwarf2_format_64bit_irix;
14727 return dwarf2_format_64bit;
14731 return dwarf2_format_32bit;