1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by the OSF and Ralph Campbell.
5 Written by Keith Knowles and Ralph Campbell, working independently.
6 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
9 This file is part of GAS.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
39 #include "opcode/mips.h"
43 #define DBG(x) printf x
49 /* Clean up namespace so we can include obj-elf.h too. */
50 static int mips_output_flavor PARAMS ((void));
51 static int mips_output_flavor () { return OUTPUT_FLAVOR; }
52 #undef OBJ_PROCESS_STAB
59 #undef obj_frob_file_after_relocs
60 #undef obj_frob_symbol
62 #undef obj_sec_sym_ok_for_reloc
63 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
66 /* Fix any of them that we actually care about. */
68 #define OUTPUT_FLAVOR mips_output_flavor()
75 #ifndef ECOFF_DEBUGGING
76 #define NO_ECOFF_DEBUGGING
77 #define ECOFF_DEBUGGING 0
82 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
83 static char *mips_regmask_frag;
88 #define PIC_CALL_REG 25
96 #define ILLEGAL_REG (32)
98 /* Allow override of standard little-endian ECOFF format. */
100 #ifndef ECOFF_LITTLE_FORMAT
101 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
104 extern int target_big_endian;
106 /* 1 is we should use the 64 bit MIPS ELF ABI, 0 if we should use the
107 32 bit ABI. This has no meaning for ECOFF.
108 Note that the default is always 32 bit, even if "configured" for
109 64 bit [e.g. --target=mips64-elf]. */
112 /* The default target format to use. */
115 mips_target_format ()
117 switch (OUTPUT_FLAVOR)
119 case bfd_target_aout_flavour:
120 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
121 case bfd_target_ecoff_flavour:
122 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
123 case bfd_target_coff_flavour:
125 case bfd_target_elf_flavour:
127 /* This is traditional mips */
128 return (target_big_endian
129 ? (mips_64 ? "elf64-tradbigmips" : "elf32-tradbigmips")
130 : (mips_64 ? "elf64-tradlittlemips" : "elf32-tradlittlemips"));
132 return (target_big_endian
133 ? (mips_64 ? "elf64-bigmips" : "elf32-bigmips")
134 : (mips_64 ? "elf64-littlemips" : "elf32-littlemips"));
142 /* The name of the readonly data section. */
143 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
145 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
147 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
149 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
153 /* This is the set of options which may be modified by the .set
154 pseudo-op. We use a struct so that .set push and .set pop are more
157 struct mips_set_options
159 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
160 if it has not been initialized. Changed by `.set mipsN', and the
161 -mipsN command line option, and the default CPU. */
163 /* Whether we are assembling for the mips16 processor. 0 if we are
164 not, 1 if we are, and -1 if the value has not been initialized.
165 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
166 -nomips16 command line options, and the default CPU. */
168 /* Non-zero if we should not reorder instructions. Changed by `.set
169 reorder' and `.set noreorder'. */
171 /* Non-zero if we should not permit the $at ($1) register to be used
172 in instructions. Changed by `.set at' and `.set noat'. */
174 /* Non-zero if we should warn when a macro instruction expands into
175 more than one machine instruction. Changed by `.set nomacro' and
177 int warn_about_macros;
178 /* Non-zero if we should not move instructions. Changed by `.set
179 move', `.set volatile', `.set nomove', and `.set novolatile'. */
181 /* Non-zero if we should not optimize branches by moving the target
182 of the branch into the delay slot. Actually, we don't perform
183 this optimization anyhow. Changed by `.set bopt' and `.set
186 /* Non-zero if we should not autoextend mips16 instructions.
187 Changed by `.set autoextend' and `.set noautoextend'. */
191 /* This is the struct we use to hold the current set of options. Note
192 that we must set the isa field to ISA_UNKNOWN and the mips16 field to
193 -1 to indicate that they have not been initialized. */
195 static struct mips_set_options mips_opts =
197 ISA_UNKNOWN, -1, 0, 0, 0, 0, 0, 0
200 /* These variables are filled in with the masks of registers used.
201 The object format code reads them and puts them in the appropriate
203 unsigned long mips_gprmask;
204 unsigned long mips_cprmask[4];
206 /* MIPS ISA we are using for this output file. */
207 static int file_mips_isa = ISA_UNKNOWN;
209 /* The argument of the -mcpu= flag. Historical for code generation. */
210 static int mips_cpu = CPU_UNKNOWN;
212 /* The argument of the -march= flag. The architecture we are assembling. */
213 static int mips_arch = CPU_UNKNOWN;
215 /* The argument of the -mtune= flag. The architecture for which we
217 static int mips_tune = CPU_UNKNOWN;
219 /* The argument of the -mabi= flag. */
220 static char * mips_abi_string = 0;
222 /* Wether we should mark the file EABI64 or EABI32. */
223 static int mips_eabi64 = 0;
225 /* If they asked for mips1 or mips2 and a cpu that is
226 mips3 or greater, then mark the object file 32BITMODE. */
227 static int mips_32bitmode = 0;
229 /* True if -mgp32 was passed. */
230 static int mips_gp32 = 0;
232 /* Some ISA's have delay slots for instructions which read or write
233 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
234 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
235 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
236 delay slot in this ISA. The uses of this macro assume that any
237 ISA that has delay slots for one of these, has them for all. They
238 also assume that ISAs which don't have delays for these insns, don't
239 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
240 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
242 || (ISA) == ISA_MIPS2 \
243 || (ISA) == ISA_MIPS3 \
246 /* Return true if ISA supports 64 bit gp register instructions. */
247 #define ISA_HAS_64BIT_REGS(ISA) ( \
249 || (ISA) == ISA_MIPS4 \
250 || (ISA) == ISA_MIPS5 \
251 || (ISA) == ISA_MIPS64 \
254 /* Whether the processor uses hardware interlocks to protect
255 reads from the HI and LO registers, and thus does not
256 require nops to be inserted. */
258 #define hilo_interlocks (mips_arch == CPU_R4010 \
261 /* Whether the processor uses hardware interlocks to protect reads
262 from the GPRs, and thus does not require nops to be inserted. */
263 #define gpr_interlocks \
264 (mips_opts.isa != ISA_MIPS1 \
265 || mips_arch == CPU_R3900)
267 /* As with other "interlocks" this is used by hardware that has FP
268 (co-processor) interlocks. */
269 /* Itbl support may require additional care here. */
270 #define cop_interlocks (mips_arch == CPU_R4300 \
273 /* Is this a mfhi or mflo instruction? */
274 #define MF_HILO_INSN(PINFO) \
275 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
277 /* MIPS PIC level. */
281 /* Do not generate PIC code. */
284 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
285 not sure what it is supposed to do. */
288 /* Generate PIC code as in the SVR4 MIPS ABI. */
291 /* Generate PIC code without using a global offset table: the data
292 segment has a maximum size of 64K, all data references are off
293 the $gp register, and all text references are PC relative. This
294 is used on some embedded systems. */
298 static enum mips_pic_level mips_pic;
300 /* Warn about all NOPS that the assembler generates. */
301 static int warn_nops = 0;
303 /* 1 if we should generate 32 bit offsets from the GP register in
304 SVR4_PIC mode. Currently has no meaning in other modes. */
305 static int mips_big_got;
307 /* 1 if trap instructions should used for overflow rather than break
309 static int mips_trap;
311 /* 1 if double width floating point constants should not be constructed
312 by a assembling two single width halves into two single width floating
313 point registers which just happen to alias the double width destination
314 register. On some architectures this aliasing can be disabled by a bit
315 in the status register, and the setting of this bit cannot be determined
316 automatically at assemble time. */
317 static int mips_disable_float_construction;
319 /* Non-zero if any .set noreorder directives were used. */
321 static int mips_any_noreorder;
323 /* Non-zero if nops should be inserted when the register referenced in
324 an mfhi/mflo instruction is read in the next two instructions. */
325 static int mips_7000_hilo_fix;
327 /* The size of the small data section. */
328 static unsigned int g_switch_value = 8;
329 /* Whether the -G option was used. */
330 static int g_switch_seen = 0;
335 /* If we can determine in advance that GP optimization won't be
336 possible, we can skip the relaxation stuff that tries to produce
337 GP-relative references. This makes delay slot optimization work
340 This function can only provide a guess, but it seems to work for
341 gcc output. It needs to guess right for gcc, otherwise gcc
342 will put what it thinks is a GP-relative instruction in a branch
345 I don't know if a fix is needed for the SVR4_PIC mode. I've only
346 fixed it for the non-PIC mode. KR 95/04/07 */
347 static int nopic_need_relax PARAMS ((symbolS *, int));
349 /* handle of the OPCODE hash table */
350 static struct hash_control *op_hash = NULL;
352 /* The opcode hash table we use for the mips16. */
353 static struct hash_control *mips16_op_hash = NULL;
355 /* This array holds the chars that always start a comment. If the
356 pre-processor is disabled, these aren't very useful */
357 const char comment_chars[] = "#";
359 /* This array holds the chars that only start a comment at the beginning of
360 a line. If the line seems to have the form '# 123 filename'
361 .line and .file directives will appear in the pre-processed output */
362 /* Note that input_file.c hand checks for '#' at the beginning of the
363 first line of the input file. This is because the compiler outputs
364 #NO_APP at the beginning of its output. */
365 /* Also note that C style comments are always supported. */
366 const char line_comment_chars[] = "#";
368 /* This array holds machine specific line separator characters. */
369 const char line_separator_chars[] = ";";
371 /* Chars that can be used to separate mant from exp in floating point nums */
372 const char EXP_CHARS[] = "eE";
374 /* Chars that mean this number is a floating point constant */
377 const char FLT_CHARS[] = "rRsSfFdDxXpP";
379 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
380 changed in read.c . Ideally it shouldn't have to know about it at all,
381 but nothing is ideal around here.
384 static char *insn_error;
386 static int auto_align = 1;
388 /* When outputting SVR4 PIC code, the assembler needs to know the
389 offset in the stack frame from which to restore the $gp register.
390 This is set by the .cprestore pseudo-op, and saved in this
392 static offsetT mips_cprestore_offset = -1;
394 /* This is the register which holds the stack frame, as set by the
395 .frame pseudo-op. This is needed to implement .cprestore. */
396 static int mips_frame_reg = SP;
398 /* To output NOP instructions correctly, we need to keep information
399 about the previous two instructions. */
401 /* Whether we are optimizing. The default value of 2 means to remove
402 unneeded NOPs and swap branch instructions when possible. A value
403 of 1 means to not swap branches. A value of 0 means to always
405 static int mips_optimize = 2;
407 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
408 equivalent to seeing no -g option at all. */
409 static int mips_debug = 0;
411 /* The previous instruction. */
412 static struct mips_cl_insn prev_insn;
414 /* The instruction before prev_insn. */
415 static struct mips_cl_insn prev_prev_insn;
417 /* If we don't want information for prev_insn or prev_prev_insn, we
418 point the insn_mo field at this dummy integer. */
419 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
421 /* Non-zero if prev_insn is valid. */
422 static int prev_insn_valid;
424 /* The frag for the previous instruction. */
425 static struct frag *prev_insn_frag;
427 /* The offset into prev_insn_frag for the previous instruction. */
428 static long prev_insn_where;
430 /* The reloc type for the previous instruction, if any. */
431 static bfd_reloc_code_real_type prev_insn_reloc_type;
433 /* The reloc for the previous instruction, if any. */
434 static fixS *prev_insn_fixp;
436 /* Non-zero if the previous instruction was in a delay slot. */
437 static int prev_insn_is_delay_slot;
439 /* Non-zero if the previous instruction was in a .set noreorder. */
440 static int prev_insn_unreordered;
442 /* Non-zero if the previous instruction uses an extend opcode (if
444 static int prev_insn_extended;
446 /* Non-zero if the previous previous instruction was in a .set
448 static int prev_prev_insn_unreordered;
450 /* If this is set, it points to a frag holding nop instructions which
451 were inserted before the start of a noreorder section. If those
452 nops turn out to be unnecessary, the size of the frag can be
454 static fragS *prev_nop_frag;
456 /* The number of nop instructions we created in prev_nop_frag. */
457 static int prev_nop_frag_holds;
459 /* The number of nop instructions that we know we need in
461 static int prev_nop_frag_required;
463 /* The number of instructions we've seen since prev_nop_frag. */
464 static int prev_nop_frag_since;
466 /* For ECOFF and ELF, relocations against symbols are done in two
467 parts, with a HI relocation and a LO relocation. Each relocation
468 has only 16 bits of space to store an addend. This means that in
469 order for the linker to handle carries correctly, it must be able
470 to locate both the HI and the LO relocation. This means that the
471 relocations must appear in order in the relocation table.
473 In order to implement this, we keep track of each unmatched HI
474 relocation. We then sort them so that they immediately precede the
475 corresponding LO relocation. */
480 struct mips_hi_fixup *next;
483 /* The section this fixup is in. */
487 /* The list of unmatched HI relocs. */
489 static struct mips_hi_fixup *mips_hi_fixup_list;
491 /* Map normal MIPS register numbers to mips16 register numbers. */
493 #define X ILLEGAL_REG
494 static const int mips32_to_16_reg_map[] =
496 X, X, 2, 3, 4, 5, 6, 7,
497 X, X, X, X, X, X, X, X,
498 0, 1, X, X, X, X, X, X,
499 X, X, X, X, X, X, X, X
503 /* Map mips16 register numbers to normal MIPS register numbers. */
505 static const unsigned int mips16_to_32_reg_map[] =
507 16, 17, 2, 3, 4, 5, 6, 7
510 /* Since the MIPS does not have multiple forms of PC relative
511 instructions, we do not have to do relaxing as is done on other
512 platforms. However, we do have to handle GP relative addressing
513 correctly, which turns out to be a similar problem.
515 Every macro that refers to a symbol can occur in (at least) two
516 forms, one with GP relative addressing and one without. For
517 example, loading a global variable into a register generally uses
518 a macro instruction like this:
520 If i can be addressed off the GP register (this is true if it is in
521 the .sbss or .sdata section, or if it is known to be smaller than
522 the -G argument) this will generate the following instruction:
524 This instruction will use a GPREL reloc. If i can not be addressed
525 off the GP register, the following instruction sequence will be used:
528 In this case the first instruction will have a HI16 reloc, and the
529 second reloc will have a LO16 reloc. Both relocs will be against
532 The issue here is that we may not know whether i is GP addressable
533 until after we see the instruction that uses it. Therefore, we
534 want to be able to choose the final instruction sequence only at
535 the end of the assembly. This is similar to the way other
536 platforms choose the size of a PC relative instruction only at the
539 When generating position independent code we do not use GP
540 addressing in quite the same way, but the issue still arises as
541 external symbols and local symbols must be handled differently.
543 We handle these issues by actually generating both possible
544 instruction sequences. The longer one is put in a frag_var with
545 type rs_machine_dependent. We encode what to do with the frag in
546 the subtype field. We encode (1) the number of existing bytes to
547 replace, (2) the number of new bytes to use, (3) the offset from
548 the start of the existing bytes to the first reloc we must generate
549 (that is, the offset is applied from the start of the existing
550 bytes after they are replaced by the new bytes, if any), (4) the
551 offset from the start of the existing bytes to the second reloc,
552 (5) whether a third reloc is needed (the third reloc is always four
553 bytes after the second reloc), and (6) whether to warn if this
554 variant is used (this is sometimes needed if .set nomacro or .set
555 noat is in effect). All these numbers are reasonably small.
557 Generating two instruction sequences must be handled carefully to
558 ensure that delay slots are handled correctly. Fortunately, there
559 are a limited number of cases. When the second instruction
560 sequence is generated, append_insn is directed to maintain the
561 existing delay slot information, so it continues to apply to any
562 code after the second instruction sequence. This means that the
563 second instruction sequence must not impose any requirements not
564 required by the first instruction sequence.
566 These variant frags are then handled in functions called by the
567 machine independent code. md_estimate_size_before_relax returns
568 the final size of the frag. md_convert_frag sets up the final form
569 of the frag. tc_gen_reloc adjust the first reloc and adds a second
571 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
575 | (((reloc1) + 64) << 9) \
576 | (((reloc2) + 64) << 2) \
577 | ((reloc3) ? (1 << 1) : 0) \
579 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
580 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
581 #define RELAX_RELOC1(i) ((bfd_vma) (((i) >> 9) & 0x7f) - 64)
582 #define RELAX_RELOC2(i) ((bfd_vma) (((i) >> 2) & 0x7f) - 64)
583 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
584 #define RELAX_WARN(i) ((i) & 1)
586 /* For mips16 code, we use an entirely different form of relaxation.
587 mips16 supports two versions of most instructions which take
588 immediate values: a small one which takes some small value, and a
589 larger one which takes a 16 bit value. Since branches also follow
590 this pattern, relaxing these values is required.
592 We can assemble both mips16 and normal MIPS code in a single
593 object. Therefore, we need to support this type of relaxation at
594 the same time that we support the relaxation described above. We
595 use the high bit of the subtype field to distinguish these cases.
597 The information we store for this type of relaxation is the
598 argument code found in the opcode file for this relocation, whether
599 the user explicitly requested a small or extended form, and whether
600 the relocation is in a jump or jal delay slot. That tells us the
601 size of the value, and how it should be stored. We also store
602 whether the fragment is considered to be extended or not. We also
603 store whether this is known to be a branch to a different section,
604 whether we have tried to relax this frag yet, and whether we have
605 ever extended a PC relative fragment because of a shift count. */
606 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
609 | ((small) ? 0x100 : 0) \
610 | ((ext) ? 0x200 : 0) \
611 | ((dslot) ? 0x400 : 0) \
612 | ((jal_dslot) ? 0x800 : 0))
613 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
614 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
615 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
616 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
617 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
618 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
619 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
620 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
621 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
622 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
623 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
624 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
626 /* Prototypes for static functions. */
629 #define internalError() \
630 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
632 #define internalError() as_fatal (_("MIPS internal Error"));
635 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
637 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
638 unsigned int reg, enum mips_regclass class));
639 static int reg_needs_delay PARAMS ((unsigned int));
640 static void mips16_mark_labels PARAMS ((void));
641 static void append_insn PARAMS ((char *place,
642 struct mips_cl_insn * ip,
644 bfd_reloc_code_real_type r,
646 static void mips_no_prev_insn PARAMS ((int));
647 static void mips_emit_delays PARAMS ((boolean));
649 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
650 const char *name, const char *fmt,
653 static void macro_build ();
655 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
656 const char *, const char *,
658 static void macro_build_lui PARAMS ((char *place, int *counter,
659 expressionS * ep, int regnum));
660 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
661 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
663 static void load_register PARAMS ((int *, int, expressionS *, int));
664 static void load_address PARAMS ((int *counter, int reg, expressionS *ep));
665 static void macro PARAMS ((struct mips_cl_insn * ip));
666 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
667 #ifdef LOSING_COMPILER
668 static void macro2 PARAMS ((struct mips_cl_insn * ip));
670 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
671 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
672 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
673 boolean, boolean, unsigned long *,
674 boolean *, unsigned short *));
675 static int my_getSmallExpression PARAMS ((expressionS * ep, char *str));
676 static void my_getExpression PARAMS ((expressionS * ep, char *str));
677 static symbolS *get_symbol PARAMS ((void));
678 static void mips_align PARAMS ((int to, int fill, symbolS *label));
679 static void s_align PARAMS ((int));
680 static void s_change_sec PARAMS ((int));
681 static void s_cons PARAMS ((int));
682 static void s_float_cons PARAMS ((int));
683 static void s_mips_globl PARAMS ((int));
684 static void s_option PARAMS ((int));
685 static void s_mipsset PARAMS ((int));
686 static void s_abicalls PARAMS ((int));
687 static void s_cpload PARAMS ((int));
688 static void s_cprestore PARAMS ((int));
689 static void s_gpword PARAMS ((int));
690 static void s_cpadd PARAMS ((int));
691 static void s_insn PARAMS ((int));
692 static void md_obj_begin PARAMS ((void));
693 static void md_obj_end PARAMS ((void));
694 static long get_number PARAMS ((void));
695 static void s_mips_ent PARAMS ((int));
696 static void s_mips_end PARAMS ((int));
697 static void s_mips_frame PARAMS ((int));
698 static void s_mips_mask PARAMS ((int));
699 static void s_mips_stab PARAMS ((int));
700 static void s_mips_weakext PARAMS ((int));
701 static void s_file PARAMS ((int));
702 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
703 static const char *mips_isa_to_str PARAMS ((int));
704 static const char *mips_cpu_to_str PARAMS ((int));
705 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
707 /* Table and functions used to map between CPU/ISA names, and
708 ISA levels, and CPU numbers. */
712 const char *name; /* CPU or ISA name. */
713 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
714 int isa; /* ISA level. */
715 int cpu; /* CPU number (default CPU if ISA). */
718 static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *));
719 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
720 static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int));
724 The following pseudo-ops from the Kane and Heinrich MIPS book
725 should be defined here, but are currently unsupported: .alias,
726 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
728 The following pseudo-ops from the Kane and Heinrich MIPS book are
729 specific to the type of debugging information being generated, and
730 should be defined by the object format: .aent, .begin, .bend,
731 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
734 The following pseudo-ops from the Kane and Heinrich MIPS book are
735 not MIPS CPU specific, but are also not specific to the object file
736 format. This file is probably the best place to define them, but
737 they are not currently supported: .asm0, .endr, .lab, .repeat,
740 static const pseudo_typeS mips_pseudo_table[] =
742 /* MIPS specific pseudo-ops. */
743 {"option", s_option, 0},
744 {"set", s_mipsset, 0},
745 {"rdata", s_change_sec, 'r'},
746 {"sdata", s_change_sec, 's'},
747 {"livereg", s_ignore, 0},
748 {"abicalls", s_abicalls, 0},
749 {"cpload", s_cpload, 0},
750 {"cprestore", s_cprestore, 0},
751 {"gpword", s_gpword, 0},
752 {"cpadd", s_cpadd, 0},
755 /* Relatively generic pseudo-ops that happen to be used on MIPS
757 {"asciiz", stringer, 1},
758 {"bss", s_change_sec, 'b'},
761 {"dword", s_cons, 3},
762 {"weakext", s_mips_weakext, 0},
764 /* These pseudo-ops are defined in read.c, but must be overridden
765 here for one reason or another. */
766 {"align", s_align, 0},
768 {"data", s_change_sec, 'd'},
769 {"double", s_float_cons, 'd'},
770 {"float", s_float_cons, 'f'},
771 {"globl", s_mips_globl, 0},
772 {"global", s_mips_globl, 0},
773 {"hword", s_cons, 1},
778 {"short", s_cons, 1},
779 {"single", s_float_cons, 'f'},
780 {"stabn", s_mips_stab, 'n'},
781 {"text", s_change_sec, 't'},
784 #ifdef MIPS_STABS_ELF
785 { "extern", ecoff_directive_extern, 0},
791 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
793 /* These pseudo-ops should be defined by the object file format.
794 However, a.out doesn't support them, so we have versions here. */
795 {"aent", s_mips_ent, 1},
796 {"bgnb", s_ignore, 0},
797 {"end", s_mips_end, 0},
798 {"endb", s_ignore, 0},
799 {"ent", s_mips_ent, 0},
801 {"fmask", s_mips_mask, 'F'},
802 {"frame", s_mips_frame, 0},
803 {"loc", s_ignore, 0},
804 {"mask", s_mips_mask, 'R'},
805 {"verstamp", s_ignore, 0},
809 extern void pop_insert PARAMS ((const pseudo_typeS *));
814 pop_insert (mips_pseudo_table);
815 if (! ECOFF_DEBUGGING)
816 pop_insert (mips_nonecoff_pseudo_table);
819 /* Symbols labelling the current insn. */
821 struct insn_label_list
823 struct insn_label_list *next;
827 static struct insn_label_list *insn_labels;
828 static struct insn_label_list *free_insn_labels;
830 static void mips_clear_insn_labels PARAMS ((void));
833 mips_clear_insn_labels ()
835 register struct insn_label_list **pl;
837 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
843 static char *expr_end;
845 /* Expressions which appear in instructions. These are set by
848 static expressionS imm_expr;
849 static expressionS offset_expr;
851 /* Relocs associated with imm_expr and offset_expr. */
853 static bfd_reloc_code_real_type imm_reloc;
854 static bfd_reloc_code_real_type offset_reloc;
856 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
858 static boolean imm_unmatched_hi;
860 /* These are set by mips16_ip if an explicit extension is used. */
862 static boolean mips16_small, mips16_ext;
864 #ifdef MIPS_STABS_ELF
865 /* The pdr segment for per procedure frame/regmask info */
871 mips_isa_to_str (isa)
874 const struct mips_cpu_info *ci;
877 ci = mips_cpu_info_from_isa (isa);
881 sprintf (s, "ISA#%d", isa);
886 mips_cpu_to_str (cpu)
889 const struct mips_cpu_info *ci;
892 ci = mips_cpu_info_from_cpu (cpu);
896 sprintf (s, "CPU#%d", cpu);
900 /* This function is called once, at assembler startup time. It should
901 set up all the tables, etc. that the MD part of the assembler will need. */
906 register const char *retval = NULL;
911 int mips_isa_from_cpu;
912 int target_cpu_had_mips16 = 0;
913 const struct mips_cpu_info *ci;
915 /* GP relative stuff not working for PE */
916 if (strncmp (TARGET_OS, "pe", 2) == 0
917 && g_switch_value != 0)
920 as_bad (_("-G not supported in this configuration."));
925 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
927 a = xmalloc (sizeof TARGET_CPU);
928 strcpy (a, TARGET_CPU);
929 a[(sizeof TARGET_CPU) - 3] = '\0';
933 if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0)
935 target_cpu_had_mips16 = 1;
936 cpu += sizeof "mips16" - 1;
939 if (mips_opts.mips16 < 0)
940 mips_opts.mips16 = target_cpu_had_mips16;
942 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
943 specified on the command line, or some other value if one was.
944 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
945 the command line, or will be set otherwise if one was. */
946 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
948 /* We have it all. There's nothing to do. */
950 else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN)
952 /* We have ARCH, we need ISA. */
953 ci = mips_cpu_info_from_cpu (mips_arch);
955 mips_opts.isa = ci->isa;
957 else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
959 /* We have ISA, we need default ARCH. */
960 ci = mips_cpu_info_from_isa (mips_opts.isa);
964 else if (mips_arch == CPU_UNKNOWN
965 && mips_opts.isa == ISA_UNKNOWN
966 && mips_cpu != CPU_UNKNOWN)
968 /* Historic -mcpu= option. Warn. */
969 ci = mips_cpu_info_from_cpu (mips_cpu);
973 mips_opts.isa = ci->isa;
974 as_warn (_("The -mcpu option is deprecated. Please use -march and -mtune instead."));
979 /* We need to set both ISA and ARCH from target cpu. */
980 ci = mips_cpu_info_from_name (cpu);
982 ci = mips_cpu_info_from_cpu (CPU_R3000);
984 mips_opts.isa = ci->isa;
988 if (mips_tune == CPU_UNKNOWN)
989 mips_tune = mips_arch;
991 ci = mips_cpu_info_from_cpu (mips_arch);
993 mips_isa_from_cpu = ci->isa;
995 /* End of TARGET_CPU processing, get rid of malloced memory
1004 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
1005 as_bad (_("trap exception not supported at ISA 1"));
1007 /* Set the EABI kind based on the ISA before the user gets
1008 to change the ISA with directives. This isn't really
1009 the best, but then neither is basing the abi on the isa. */
1010 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
1012 && 0 == strcmp (mips_abi_string, "eabi"))
1015 /* If they asked for mips1 or mips2 and a cpu that is
1016 mips3 or greater, then mark the object file 32BITMODE. */
1017 if (mips_isa_from_cpu != ISA_UNKNOWN
1018 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
1019 && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
1022 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1023 as_warn (_("Could not set architecture and machine"));
1025 file_mips_isa = mips_opts.isa;
1027 op_hash = hash_new ();
1029 for (i = 0; i < NUMOPCODES;)
1031 const char *name = mips_opcodes[i].name;
1033 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1036 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1037 mips_opcodes[i].name, retval);
1038 /* Probably a memory allocation problem? Give up now. */
1039 as_fatal (_("Broken assembler. No assembly attempted."));
1043 if (mips_opcodes[i].pinfo != INSN_MACRO)
1045 if (!validate_mips_insn (&mips_opcodes[i]))
1050 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1053 mips16_op_hash = hash_new ();
1056 while (i < bfd_mips16_num_opcodes)
1058 const char *name = mips16_opcodes[i].name;
1060 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1062 as_fatal (_("internal: can't hash `%s': %s"),
1063 mips16_opcodes[i].name, retval);
1066 if (mips16_opcodes[i].pinfo != INSN_MACRO
1067 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1068 != mips16_opcodes[i].match))
1070 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1071 mips16_opcodes[i].name, mips16_opcodes[i].args);
1076 while (i < bfd_mips16_num_opcodes
1077 && strcmp (mips16_opcodes[i].name, name) == 0);
1081 as_fatal (_("Broken assembler. No assembly attempted."));
1083 /* We add all the general register names to the symbol table. This
1084 helps us detect invalid uses of them. */
1085 for (i = 0; i < 32; i++)
1089 sprintf (buf, "$%d", i);
1090 symbol_table_insert (symbol_new (buf, reg_section, i,
1091 &zero_address_frag));
1093 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1094 &zero_address_frag));
1095 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1096 &zero_address_frag));
1097 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1098 &zero_address_frag));
1099 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1100 &zero_address_frag));
1101 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1102 &zero_address_frag));
1103 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1104 &zero_address_frag));
1105 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1106 &zero_address_frag));
1108 mips_no_prev_insn (false);
1111 mips_cprmask[0] = 0;
1112 mips_cprmask[1] = 0;
1113 mips_cprmask[2] = 0;
1114 mips_cprmask[3] = 0;
1116 /* set the default alignment for the text section (2**2) */
1117 record_alignment (text_section, 2);
1119 if (USE_GLOBAL_POINTER_OPT)
1120 bfd_set_gp_size (stdoutput, g_switch_value);
1122 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1124 /* On a native system, sections must be aligned to 16 byte
1125 boundaries. When configured for an embedded ELF target, we
1127 if (strcmp (TARGET_OS, "elf") != 0)
1129 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1130 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1131 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1134 /* Create a .reginfo section for register masks and a .mdebug
1135 section for debugging information. */
1143 subseg = now_subseg;
1145 /* The ABI says this section should be loaded so that the
1146 running program can access it. However, we don't load it
1147 if we are configured for an embedded target */
1148 flags = SEC_READONLY | SEC_DATA;
1149 if (strcmp (TARGET_OS, "elf") != 0)
1150 flags |= SEC_ALLOC | SEC_LOAD;
1154 sec = subseg_new (".reginfo", (subsegT) 0);
1156 (void) bfd_set_section_flags (stdoutput, sec, flags);
1157 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1160 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1165 /* The 64-bit ABI uses a .MIPS.options section rather than
1166 .reginfo section. */
1167 sec = subseg_new (".MIPS.options", (subsegT) 0);
1168 (void) bfd_set_section_flags (stdoutput, sec, flags);
1169 (void) bfd_set_section_alignment (stdoutput, sec, 3);
1172 /* Set up the option header. */
1174 Elf_Internal_Options opthdr;
1177 opthdr.kind = ODK_REGINFO;
1178 opthdr.size = (sizeof (Elf_External_Options)
1179 + sizeof (Elf64_External_RegInfo));
1182 f = frag_more (sizeof (Elf_External_Options));
1183 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1184 (Elf_External_Options *) f);
1186 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1191 if (ECOFF_DEBUGGING)
1193 sec = subseg_new (".mdebug", (subsegT) 0);
1194 (void) bfd_set_section_flags (stdoutput, sec,
1195 SEC_HAS_CONTENTS | SEC_READONLY);
1196 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1199 #ifdef MIPS_STABS_ELF
1200 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1201 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1202 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
1203 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1206 subseg_set (seg, subseg);
1210 if (! ECOFF_DEBUGGING)
1217 if (! ECOFF_DEBUGGING)
1225 struct mips_cl_insn insn;
1227 imm_expr.X_op = O_absent;
1228 imm_reloc = BFD_RELOC_UNUSED;
1229 imm_unmatched_hi = false;
1230 offset_expr.X_op = O_absent;
1231 offset_reloc = BFD_RELOC_UNUSED;
1233 if (mips_opts.mips16)
1234 mips16_ip (str, &insn);
1237 mips_ip (str, &insn);
1238 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1239 str, insn.insn_opcode));
1244 as_bad ("%s `%s'", insn_error, str);
1248 if (insn.insn_mo->pinfo == INSN_MACRO)
1250 if (mips_opts.mips16)
1251 mips16_macro (&insn);
1257 if (imm_expr.X_op != O_absent)
1258 append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc,
1260 else if (offset_expr.X_op != O_absent)
1261 append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc, false);
1263 append_insn ((char *) NULL, &insn, NULL, BFD_RELOC_UNUSED, false);
1267 /* See whether instruction IP reads register REG. CLASS is the type
1271 insn_uses_reg (ip, reg, class)
1272 struct mips_cl_insn *ip;
1274 enum mips_regclass class;
1276 if (class == MIPS16_REG)
1278 assert (mips_opts.mips16);
1279 reg = mips16_to_32_reg_map[reg];
1280 class = MIPS_GR_REG;
1283 /* Don't report on general register 0, since it never changes. */
1284 if (class == MIPS_GR_REG && reg == 0)
1287 if (class == MIPS_FP_REG)
1289 assert (! mips_opts.mips16);
1290 /* If we are called with either $f0 or $f1, we must check $f0.
1291 This is not optimal, because it will introduce an unnecessary
1292 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1293 need to distinguish reading both $f0 and $f1 or just one of
1294 them. Note that we don't have to check the other way,
1295 because there is no instruction that sets both $f0 and $f1
1296 and requires a delay. */
1297 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1298 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1299 == (reg &~ (unsigned) 1)))
1301 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1302 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1303 == (reg &~ (unsigned) 1)))
1306 else if (! mips_opts.mips16)
1308 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1309 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1311 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1312 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1317 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1318 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1319 & MIPS16OP_MASK_RX)]
1322 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1323 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1324 & MIPS16OP_MASK_RY)]
1327 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1328 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1329 & MIPS16OP_MASK_MOVE32Z)]
1332 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1334 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1336 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1338 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1339 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1340 & MIPS16OP_MASK_REGR32) == reg)
1347 /* This function returns true if modifying a register requires a
1351 reg_needs_delay (reg)
1354 unsigned long prev_pinfo;
1356 prev_pinfo = prev_insn.insn_mo->pinfo;
1357 if (! mips_opts.noreorder
1358 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1359 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1360 || (! gpr_interlocks
1361 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1363 /* A load from a coprocessor or from memory. All load
1364 delays delay the use of general register rt for one
1365 instruction on the r3000. The r6000 and r4000 use
1367 /* Itbl support may require additional care here. */
1368 know (prev_pinfo & INSN_WRITE_GPR_T);
1369 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1376 /* Mark instruction labels in mips16 mode. This permits the linker to
1377 handle them specially, such as generating jalx instructions when
1378 needed. We also make them odd for the duration of the assembly, in
1379 order to generate the right sort of code. We will make them even
1380 in the adjust_symtab routine, while leaving them marked. This is
1381 convenient for the debugger and the disassembler. The linker knows
1382 to make them odd again. */
1385 mips16_mark_labels ()
1387 if (mips_opts.mips16)
1389 struct insn_label_list *l;
1392 for (l = insn_labels; l != NULL; l = l->next)
1395 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1396 S_SET_OTHER (l->label, STO_MIPS16);
1398 val = S_GET_VALUE (l->label);
1400 S_SET_VALUE (l->label, val + 1);
1405 /* Output an instruction. PLACE is where to put the instruction; if
1406 it is NULL, this uses frag_more to get room. IP is the instruction
1407 information. ADDRESS_EXPR is an operand of the instruction to be
1408 used with RELOC_TYPE. */
1411 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1413 struct mips_cl_insn *ip;
1414 expressionS *address_expr;
1415 bfd_reloc_code_real_type reloc_type;
1416 boolean unmatched_hi;
1418 register unsigned long prev_pinfo, pinfo;
1423 /* Mark instruction labels in mips16 mode. */
1424 if (mips_opts.mips16)
1425 mips16_mark_labels ();
1427 prev_pinfo = prev_insn.insn_mo->pinfo;
1428 pinfo = ip->insn_mo->pinfo;
1430 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1434 /* If the previous insn required any delay slots, see if we need
1435 to insert a NOP or two. There are eight kinds of possible
1436 hazards, of which an instruction can have at most one type.
1437 (1) a load from memory delay
1438 (2) a load from a coprocessor delay
1439 (3) an unconditional branch delay
1440 (4) a conditional branch delay
1441 (5) a move to coprocessor register delay
1442 (6) a load coprocessor register from memory delay
1443 (7) a coprocessor condition code delay
1444 (8) a HI/LO special register delay
1446 There are a lot of optimizations we could do that we don't.
1447 In particular, we do not, in general, reorder instructions.
1448 If you use gcc with optimization, it will reorder
1449 instructions and generally do much more optimization then we
1450 do here; repeating all that work in the assembler would only
1451 benefit hand written assembly code, and does not seem worth
1454 /* This is how a NOP is emitted. */
1455 #define emit_nop() \
1457 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1458 : md_number_to_chars (frag_more (4), 0, 4))
1460 /* The previous insn might require a delay slot, depending upon
1461 the contents of the current insn. */
1462 if (! mips_opts.mips16
1463 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1464 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1465 && ! cop_interlocks)
1466 || (! gpr_interlocks
1467 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1469 /* A load from a coprocessor or from memory. All load
1470 delays delay the use of general register rt for one
1471 instruction on the r3000. The r6000 and r4000 use
1473 /* Itbl support may require additional care here. */
1474 know (prev_pinfo & INSN_WRITE_GPR_T);
1475 if (mips_optimize == 0
1476 || insn_uses_reg (ip,
1477 ((prev_insn.insn_opcode >> OP_SH_RT)
1482 else if (! mips_opts.mips16
1483 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1484 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1485 && ! cop_interlocks)
1486 || (mips_opts.isa == ISA_MIPS1
1487 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1489 /* A generic coprocessor delay. The previous instruction
1490 modified a coprocessor general or control register. If
1491 it modified a control register, we need to avoid any
1492 coprocessor instruction (this is probably not always
1493 required, but it sometimes is). If it modified a general
1494 register, we avoid using that register.
1496 On the r6000 and r4000 loading a coprocessor register
1497 from memory is interlocked, and does not require a delay.
1499 This case is not handled very well. There is no special
1500 knowledge of CP0 handling, and the coprocessors other
1501 than the floating point unit are not distinguished at
1503 /* Itbl support may require additional care here. FIXME!
1504 Need to modify this to include knowledge about
1505 user specified delays! */
1506 if (prev_pinfo & INSN_WRITE_FPR_T)
1508 if (mips_optimize == 0
1509 || insn_uses_reg (ip,
1510 ((prev_insn.insn_opcode >> OP_SH_FT)
1515 else if (prev_pinfo & INSN_WRITE_FPR_S)
1517 if (mips_optimize == 0
1518 || insn_uses_reg (ip,
1519 ((prev_insn.insn_opcode >> OP_SH_FS)
1526 /* We don't know exactly what the previous instruction
1527 does. If the current instruction uses a coprocessor
1528 register, we must insert a NOP. If previous
1529 instruction may set the condition codes, and the
1530 current instruction uses them, we must insert two
1532 /* Itbl support may require additional care here. */
1533 if (mips_optimize == 0
1534 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1535 && (pinfo & INSN_READ_COND_CODE)))
1537 else if (pinfo & INSN_COP)
1541 else if (! mips_opts.mips16
1542 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1543 && (prev_pinfo & INSN_WRITE_COND_CODE)
1544 && ! cop_interlocks)
1546 /* The previous instruction sets the coprocessor condition
1547 codes, but does not require a general coprocessor delay
1548 (this means it is a floating point comparison
1549 instruction). If this instruction uses the condition
1550 codes, we need to insert a single NOP. */
1551 /* Itbl support may require additional care here. */
1552 if (mips_optimize == 0
1553 || (pinfo & INSN_READ_COND_CODE))
1557 /* If we're fixing up mfhi/mflo for the r7000 and the
1558 previous insn was an mfhi/mflo and the current insn
1559 reads the register that the mfhi/mflo wrote to, then
1562 else if (mips_7000_hilo_fix
1563 && MF_HILO_INSN (prev_pinfo)
1564 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1571 /* If we're fixing up mfhi/mflo for the r7000 and the
1572 2nd previous insn was an mfhi/mflo and the current insn
1573 reads the register that the mfhi/mflo wrote to, then
1576 else if (mips_7000_hilo_fix
1577 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1578 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1586 else if (prev_pinfo & INSN_READ_LO)
1588 /* The previous instruction reads the LO register; if the
1589 current instruction writes to the LO register, we must
1590 insert two NOPS. Some newer processors have interlocks.
1591 Also the tx39's multiply instructions can be exectuted
1592 immediatly after a read from HI/LO (without the delay),
1593 though the tx39's divide insns still do require the
1595 if (! (hilo_interlocks
1596 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1597 && (mips_optimize == 0
1598 || (pinfo & INSN_WRITE_LO)))
1600 /* Most mips16 branch insns don't have a delay slot.
1601 If a read from LO is immediately followed by a branch
1602 to a write to LO we have a read followed by a write
1603 less than 2 insns away. We assume the target of
1604 a branch might be a write to LO, and insert a nop
1605 between a read and an immediately following branch. */
1606 else if (mips_opts.mips16
1607 && (mips_optimize == 0
1608 || (pinfo & MIPS16_INSN_BRANCH)))
1611 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1613 /* The previous instruction reads the HI register; if the
1614 current instruction writes to the HI register, we must
1615 insert a NOP. Some newer processors have interlocks.
1616 Also the note tx39's multiply above. */
1617 if (! (hilo_interlocks
1618 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1619 && (mips_optimize == 0
1620 || (pinfo & INSN_WRITE_HI)))
1622 /* Most mips16 branch insns don't have a delay slot.
1623 If a read from HI is immediately followed by a branch
1624 to a write to HI we have a read followed by a write
1625 less than 2 insns away. We assume the target of
1626 a branch might be a write to HI, and insert a nop
1627 between a read and an immediately following branch. */
1628 else if (mips_opts.mips16
1629 && (mips_optimize == 0
1630 || (pinfo & MIPS16_INSN_BRANCH)))
1634 /* If the previous instruction was in a noreorder section, then
1635 we don't want to insert the nop after all. */
1636 /* Itbl support may require additional care here. */
1637 if (prev_insn_unreordered)
1640 /* There are two cases which require two intervening
1641 instructions: 1) setting the condition codes using a move to
1642 coprocessor instruction which requires a general coprocessor
1643 delay and then reading the condition codes 2) reading the HI
1644 or LO register and then writing to it (except on processors
1645 which have interlocks). If we are not already emitting a NOP
1646 instruction, we must check for these cases compared to the
1647 instruction previous to the previous instruction. */
1648 if ((! mips_opts.mips16
1649 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1650 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1651 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1652 && (pinfo & INSN_READ_COND_CODE)
1653 && ! cop_interlocks)
1654 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1655 && (pinfo & INSN_WRITE_LO)
1656 && ! (hilo_interlocks
1657 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1658 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1659 && (pinfo & INSN_WRITE_HI)
1660 && ! (hilo_interlocks
1661 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1666 if (prev_prev_insn_unreordered)
1669 if (prev_prev_nop && nops == 0)
1672 /* If we are being given a nop instruction, don't bother with
1673 one of the nops we would otherwise output. This will only
1674 happen when a nop instruction is used with mips_optimize set
1677 && ! mips_opts.noreorder
1678 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1681 /* Now emit the right number of NOP instructions. */
1682 if (nops > 0 && ! mips_opts.noreorder)
1685 unsigned long old_frag_offset;
1687 struct insn_label_list *l;
1689 old_frag = frag_now;
1690 old_frag_offset = frag_now_fix ();
1692 for (i = 0; i < nops; i++)
1697 listing_prev_line ();
1698 /* We may be at the start of a variant frag. In case we
1699 are, make sure there is enough space for the frag
1700 after the frags created by listing_prev_line. The
1701 argument to frag_grow here must be at least as large
1702 as the argument to all other calls to frag_grow in
1703 this file. We don't have to worry about being in the
1704 middle of a variant frag, because the variants insert
1705 all needed nop instructions themselves. */
1709 for (l = insn_labels; l != NULL; l = l->next)
1713 assert (S_GET_SEGMENT (l->label) == now_seg);
1714 symbol_set_frag (l->label, frag_now);
1715 val = (valueT) frag_now_fix ();
1716 /* mips16 text labels are stored as odd. */
1717 if (mips_opts.mips16)
1719 S_SET_VALUE (l->label, val);
1722 #ifndef NO_ECOFF_DEBUGGING
1723 if (ECOFF_DEBUGGING)
1724 ecoff_fix_loc (old_frag, old_frag_offset);
1727 else if (prev_nop_frag != NULL)
1729 /* We have a frag holding nops we may be able to remove. If
1730 we don't need any nops, we can decrease the size of
1731 prev_nop_frag by the size of one instruction. If we do
1732 need some nops, we count them in prev_nops_required. */
1733 if (prev_nop_frag_since == 0)
1737 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1738 --prev_nop_frag_holds;
1741 prev_nop_frag_required += nops;
1745 if (prev_prev_nop == 0)
1747 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1748 --prev_nop_frag_holds;
1751 ++prev_nop_frag_required;
1754 if (prev_nop_frag_holds <= prev_nop_frag_required)
1755 prev_nop_frag = NULL;
1757 ++prev_nop_frag_since;
1759 /* Sanity check: by the time we reach the second instruction
1760 after prev_nop_frag, we should have used up all the nops
1761 one way or another. */
1762 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1766 if (reloc_type > BFD_RELOC_UNUSED)
1768 /* We need to set up a variant frag. */
1769 assert (mips_opts.mips16 && address_expr != NULL);
1770 f = frag_var (rs_machine_dependent, 4, 0,
1771 RELAX_MIPS16_ENCODE (reloc_type - BFD_RELOC_UNUSED,
1772 mips16_small, mips16_ext,
1774 & INSN_UNCOND_BRANCH_DELAY),
1775 (prev_insn_reloc_type
1776 == BFD_RELOC_MIPS16_JMP)),
1777 make_expr_symbol (address_expr), (offsetT) 0,
1780 else if (place != NULL)
1782 else if (mips_opts.mips16
1784 && reloc_type != BFD_RELOC_MIPS16_JMP)
1786 /* Make sure there is enough room to swap this instruction with
1787 a following jump instruction. */
1793 if (mips_opts.mips16
1794 && mips_opts.noreorder
1795 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1796 as_warn (_("extended instruction in delay slot"));
1802 if (address_expr != NULL && reloc_type < BFD_RELOC_UNUSED)
1804 if (address_expr->X_op == O_constant)
1809 ip->insn_opcode |= address_expr->X_add_number;
1812 case BFD_RELOC_LO16:
1813 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1816 case BFD_RELOC_MIPS_JMP:
1817 if ((address_expr->X_add_number & 3) != 0)
1818 as_bad (_("jump to misaligned address (0x%lx)"),
1819 (unsigned long) address_expr->X_add_number);
1820 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
1823 case BFD_RELOC_MIPS16_JMP:
1824 if ((address_expr->X_add_number & 3) != 0)
1825 as_bad (_("jump to misaligned address (0x%lx)"),
1826 (unsigned long) address_expr->X_add_number);
1828 (((address_expr->X_add_number & 0x7c0000) << 3)
1829 | ((address_expr->X_add_number & 0xf800000) >> 7)
1830 | ((address_expr->X_add_number & 0x3fffc) >> 2));
1833 case BFD_RELOC_16_PCREL_S2:
1843 /* Don't generate a reloc if we are writing into a variant
1847 fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1849 reloc_type == BFD_RELOC_16_PCREL_S2,
1853 struct mips_hi_fixup *hi_fixup;
1855 assert (reloc_type == BFD_RELOC_HI16_S);
1856 hi_fixup = ((struct mips_hi_fixup *)
1857 xmalloc (sizeof (struct mips_hi_fixup)));
1858 hi_fixup->fixp = fixp;
1859 hi_fixup->seg = now_seg;
1860 hi_fixup->next = mips_hi_fixup_list;
1861 mips_hi_fixup_list = hi_fixup;
1867 if (! mips_opts.mips16)
1868 md_number_to_chars (f, ip->insn_opcode, 4);
1869 else if (reloc_type == BFD_RELOC_MIPS16_JMP)
1871 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
1872 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
1878 md_number_to_chars (f, 0xf000 | ip->extend, 2);
1881 md_number_to_chars (f, ip->insn_opcode, 2);
1884 /* Update the register mask information. */
1885 if (! mips_opts.mips16)
1887 if (pinfo & INSN_WRITE_GPR_D)
1888 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
1889 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
1890 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
1891 if (pinfo & INSN_READ_GPR_S)
1892 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
1893 if (pinfo & INSN_WRITE_GPR_31)
1894 mips_gprmask |= 1 << 31;
1895 if (pinfo & INSN_WRITE_FPR_D)
1896 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
1897 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
1898 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
1899 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
1900 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
1901 if ((pinfo & INSN_READ_FPR_R) != 0)
1902 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
1903 if (pinfo & INSN_COP)
1905 /* We don't keep enough information to sort these cases out.
1906 The itbl support does keep this information however, although
1907 we currently don't support itbl fprmats as part of the cop
1908 instruction. May want to add this support in the future. */
1910 /* Never set the bit for $0, which is always zero. */
1911 mips_gprmask &= ~1 << 0;
1915 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
1916 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
1917 & MIPS16OP_MASK_RX);
1918 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
1919 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
1920 & MIPS16OP_MASK_RY);
1921 if (pinfo & MIPS16_INSN_WRITE_Z)
1922 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
1923 & MIPS16OP_MASK_RZ);
1924 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
1925 mips_gprmask |= 1 << TREG;
1926 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
1927 mips_gprmask |= 1 << SP;
1928 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
1929 mips_gprmask |= 1 << RA;
1930 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
1931 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
1932 if (pinfo & MIPS16_INSN_READ_Z)
1933 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1934 & MIPS16OP_MASK_MOVE32Z);
1935 if (pinfo & MIPS16_INSN_READ_GPR_X)
1936 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1937 & MIPS16OP_MASK_REGR32);
1940 if (place == NULL && ! mips_opts.noreorder)
1942 /* Filling the branch delay slot is more complex. We try to
1943 switch the branch with the previous instruction, which we can
1944 do if the previous instruction does not set up a condition
1945 that the branch tests and if the branch is not itself the
1946 target of any branch. */
1947 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
1948 || (pinfo & INSN_COND_BRANCH_DELAY))
1950 if (mips_optimize < 2
1951 /* If we have seen .set volatile or .set nomove, don't
1953 || mips_opts.nomove != 0
1954 /* If we had to emit any NOP instructions, then we
1955 already know we can not swap. */
1957 /* If we don't even know the previous insn, we can not
1959 || ! prev_insn_valid
1960 /* If the previous insn is already in a branch delay
1961 slot, then we can not swap. */
1962 || prev_insn_is_delay_slot
1963 /* If the previous previous insn was in a .set
1964 noreorder, we can't swap. Actually, the MIPS
1965 assembler will swap in this situation. However, gcc
1966 configured -with-gnu-as will generate code like
1972 in which we can not swap the bne and INSN. If gcc is
1973 not configured -with-gnu-as, it does not output the
1974 .set pseudo-ops. We don't have to check
1975 prev_insn_unreordered, because prev_insn_valid will
1976 be 0 in that case. We don't want to use
1977 prev_prev_insn_valid, because we do want to be able
1978 to swap at the start of a function. */
1979 || prev_prev_insn_unreordered
1980 /* If the branch is itself the target of a branch, we
1981 can not swap. We cheat on this; all we check for is
1982 whether there is a label on this instruction. If
1983 there are any branches to anything other than a
1984 label, users must use .set noreorder. */
1985 || insn_labels != NULL
1986 /* If the previous instruction is in a variant frag, we
1987 can not do the swap. This does not apply to the
1988 mips16, which uses variant frags for different
1990 || (! mips_opts.mips16
1991 && prev_insn_frag->fr_type == rs_machine_dependent)
1992 /* If the branch reads the condition codes, we don't
1993 even try to swap, because in the sequence
1998 we can not swap, and I don't feel like handling that
2000 || (! mips_opts.mips16
2001 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2002 && (pinfo & INSN_READ_COND_CODE))
2003 /* We can not swap with an instruction that requires a
2004 delay slot, becase the target of the branch might
2005 interfere with that instruction. */
2006 || (! mips_opts.mips16
2007 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2009 /* Itbl support may require additional care here. */
2010 & (INSN_LOAD_COPROC_DELAY
2011 | INSN_COPROC_MOVE_DELAY
2012 | INSN_WRITE_COND_CODE)))
2013 || (! (hilo_interlocks
2014 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2018 || (! mips_opts.mips16
2020 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2021 || (! mips_opts.mips16
2022 && mips_opts.isa == ISA_MIPS1
2023 /* Itbl support may require additional care here. */
2024 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2025 /* We can not swap with a branch instruction. */
2027 & (INSN_UNCOND_BRANCH_DELAY
2028 | INSN_COND_BRANCH_DELAY
2029 | INSN_COND_BRANCH_LIKELY))
2030 /* We do not swap with a trap instruction, since it
2031 complicates trap handlers to have the trap
2032 instruction be in a delay slot. */
2033 || (prev_pinfo & INSN_TRAP)
2034 /* If the branch reads a register that the previous
2035 instruction sets, we can not swap. */
2036 || (! mips_opts.mips16
2037 && (prev_pinfo & INSN_WRITE_GPR_T)
2038 && insn_uses_reg (ip,
2039 ((prev_insn.insn_opcode >> OP_SH_RT)
2042 || (! mips_opts.mips16
2043 && (prev_pinfo & INSN_WRITE_GPR_D)
2044 && insn_uses_reg (ip,
2045 ((prev_insn.insn_opcode >> OP_SH_RD)
2048 || (mips_opts.mips16
2049 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2050 && insn_uses_reg (ip,
2051 ((prev_insn.insn_opcode
2053 & MIPS16OP_MASK_RX),
2055 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2056 && insn_uses_reg (ip,
2057 ((prev_insn.insn_opcode
2059 & MIPS16OP_MASK_RY),
2061 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2062 && insn_uses_reg (ip,
2063 ((prev_insn.insn_opcode
2065 & MIPS16OP_MASK_RZ),
2067 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2068 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2069 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2070 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2071 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2072 && insn_uses_reg (ip,
2073 MIPS16OP_EXTRACT_REG32R (prev_insn.
2076 /* If the branch writes a register that the previous
2077 instruction sets, we can not swap (we know that
2078 branches write only to RD or to $31). */
2079 || (! mips_opts.mips16
2080 && (prev_pinfo & INSN_WRITE_GPR_T)
2081 && (((pinfo & INSN_WRITE_GPR_D)
2082 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2083 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2084 || ((pinfo & INSN_WRITE_GPR_31)
2085 && (((prev_insn.insn_opcode >> OP_SH_RT)
2088 || (! mips_opts.mips16
2089 && (prev_pinfo & INSN_WRITE_GPR_D)
2090 && (((pinfo & INSN_WRITE_GPR_D)
2091 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2092 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2093 || ((pinfo & INSN_WRITE_GPR_31)
2094 && (((prev_insn.insn_opcode >> OP_SH_RD)
2097 || (mips_opts.mips16
2098 && (pinfo & MIPS16_INSN_WRITE_31)
2099 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2100 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2101 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2103 /* If the branch writes a register that the previous
2104 instruction reads, we can not swap (we know that
2105 branches only write to RD or to $31). */
2106 || (! mips_opts.mips16
2107 && (pinfo & INSN_WRITE_GPR_D)
2108 && insn_uses_reg (&prev_insn,
2109 ((ip->insn_opcode >> OP_SH_RD)
2112 || (! mips_opts.mips16
2113 && (pinfo & INSN_WRITE_GPR_31)
2114 && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG))
2115 || (mips_opts.mips16
2116 && (pinfo & MIPS16_INSN_WRITE_31)
2117 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2118 /* If we are generating embedded PIC code, the branch
2119 might be expanded into a sequence which uses $at, so
2120 we can't swap with an instruction which reads it. */
2121 || (mips_pic == EMBEDDED_PIC
2122 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2123 /* If the previous previous instruction has a load
2124 delay, and sets a register that the branch reads, we
2126 || (! mips_opts.mips16
2127 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2128 /* Itbl support may require additional care here. */
2129 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2130 || (! gpr_interlocks
2131 && (prev_prev_insn.insn_mo->pinfo
2132 & INSN_LOAD_MEMORY_DELAY)))
2133 && insn_uses_reg (ip,
2134 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2137 /* If one instruction sets a condition code and the
2138 other one uses a condition code, we can not swap. */
2139 || ((pinfo & INSN_READ_COND_CODE)
2140 && (prev_pinfo & INSN_WRITE_COND_CODE))
2141 || ((pinfo & INSN_WRITE_COND_CODE)
2142 && (prev_pinfo & INSN_READ_COND_CODE))
2143 /* If the previous instruction uses the PC, we can not
2145 || (mips_opts.mips16
2146 && (prev_pinfo & MIPS16_INSN_READ_PC))
2147 /* If the previous instruction was extended, we can not
2149 || (mips_opts.mips16 && prev_insn_extended)
2150 /* If the previous instruction had a fixup in mips16
2151 mode, we can not swap. This normally means that the
2152 previous instruction was a 4 byte branch anyhow. */
2153 || (mips_opts.mips16 && prev_insn_fixp)
2154 /* If the previous instruction is a sync, sync.l, or
2155 sync.p, we can not swap. */
2156 || (prev_pinfo & INSN_SYNC))
2158 /* We could do even better for unconditional branches to
2159 portions of this object file; we could pick up the
2160 instruction at the destination, put it in the delay
2161 slot, and bump the destination address. */
2163 /* Update the previous insn information. */
2164 prev_prev_insn = *ip;
2165 prev_insn.insn_mo = &dummy_opcode;
2169 /* It looks like we can actually do the swap. */
2170 if (! mips_opts.mips16)
2175 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2176 memcpy (temp, prev_f, 4);
2177 memcpy (prev_f, f, 4);
2178 memcpy (f, temp, 4);
2181 prev_insn_fixp->fx_frag = frag_now;
2182 prev_insn_fixp->fx_where = f - frag_now->fr_literal;
2186 fixp->fx_frag = prev_insn_frag;
2187 fixp->fx_where = prev_insn_where;
2195 assert (prev_insn_fixp == NULL);
2196 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2197 memcpy (temp, prev_f, 2);
2198 memcpy (prev_f, f, 2);
2199 if (reloc_type != BFD_RELOC_MIPS16_JMP)
2201 assert (reloc_type == BFD_RELOC_UNUSED);
2202 memcpy (f, temp, 2);
2206 memcpy (f, f + 2, 2);
2207 memcpy (f + 2, temp, 2);
2211 fixp->fx_frag = prev_insn_frag;
2212 fixp->fx_where = prev_insn_where;
2216 /* Update the previous insn information; leave prev_insn
2218 prev_prev_insn = *ip;
2220 prev_insn_is_delay_slot = 1;
2222 /* If that was an unconditional branch, forget the previous
2223 insn information. */
2224 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2226 prev_prev_insn.insn_mo = &dummy_opcode;
2227 prev_insn.insn_mo = &dummy_opcode;
2230 prev_insn_fixp = NULL;
2231 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2232 prev_insn_extended = 0;
2234 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2236 /* We don't yet optimize a branch likely. What we should do
2237 is look at the target, copy the instruction found there
2238 into the delay slot, and increment the branch to jump to
2239 the next instruction. */
2241 /* Update the previous insn information. */
2242 prev_prev_insn = *ip;
2243 prev_insn.insn_mo = &dummy_opcode;
2244 prev_insn_fixp = NULL;
2245 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2246 prev_insn_extended = 0;
2250 /* Update the previous insn information. */
2252 prev_prev_insn.insn_mo = &dummy_opcode;
2254 prev_prev_insn = prev_insn;
2257 /* Any time we see a branch, we always fill the delay slot
2258 immediately; since this insn is not a branch, we know it
2259 is not in a delay slot. */
2260 prev_insn_is_delay_slot = 0;
2262 prev_insn_fixp = fixp;
2263 prev_insn_reloc_type = reloc_type;
2264 if (mips_opts.mips16)
2265 prev_insn_extended = (ip->use_extend
2266 || reloc_type > BFD_RELOC_UNUSED);
2269 prev_prev_insn_unreordered = prev_insn_unreordered;
2270 prev_insn_unreordered = 0;
2271 prev_insn_frag = frag_now;
2272 prev_insn_where = f - frag_now->fr_literal;
2273 prev_insn_valid = 1;
2275 else if (place == NULL)
2277 /* We need to record a bit of information even when we are not
2278 reordering, in order to determine the base address for mips16
2279 PC relative relocs. */
2280 prev_prev_insn = prev_insn;
2282 prev_insn_reloc_type = reloc_type;
2283 prev_prev_insn_unreordered = prev_insn_unreordered;
2284 prev_insn_unreordered = 1;
2287 /* We just output an insn, so the next one doesn't have a label. */
2288 mips_clear_insn_labels ();
2290 /* We must ensure that a fixup associated with an unmatched %hi
2291 reloc does not become a variant frag. Otherwise, the
2292 rearrangement of %hi relocs in frob_file may confuse
2296 frag_wane (frag_now);
2301 /* This function forgets that there was any previous instruction or
2302 label. If PRESERVE is non-zero, it remembers enough information to
2303 know whether nops are needed before a noreorder section. */
2306 mips_no_prev_insn (preserve)
2311 prev_insn.insn_mo = &dummy_opcode;
2312 prev_prev_insn.insn_mo = &dummy_opcode;
2313 prev_nop_frag = NULL;
2314 prev_nop_frag_holds = 0;
2315 prev_nop_frag_required = 0;
2316 prev_nop_frag_since = 0;
2318 prev_insn_valid = 0;
2319 prev_insn_is_delay_slot = 0;
2320 prev_insn_unreordered = 0;
2321 prev_insn_extended = 0;
2322 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2323 prev_prev_insn_unreordered = 0;
2324 mips_clear_insn_labels ();
2327 /* This function must be called whenever we turn on noreorder or emit
2328 something other than instructions. It inserts any NOPS which might
2329 be needed by the previous instruction, and clears the information
2330 kept for the previous instructions. The INSNS parameter is true if
2331 instructions are to follow. */
2334 mips_emit_delays (insns)
2337 if (! mips_opts.noreorder)
2342 if ((! mips_opts.mips16
2343 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2344 && (! cop_interlocks
2345 && (prev_insn.insn_mo->pinfo
2346 & (INSN_LOAD_COPROC_DELAY
2347 | INSN_COPROC_MOVE_DELAY
2348 | INSN_WRITE_COND_CODE))))
2349 || (! hilo_interlocks
2350 && (prev_insn.insn_mo->pinfo
2353 || (! mips_opts.mips16
2355 && (prev_insn.insn_mo->pinfo
2356 & INSN_LOAD_MEMORY_DELAY))
2357 || (! mips_opts.mips16
2358 && mips_opts.isa == ISA_MIPS1
2359 && (prev_insn.insn_mo->pinfo
2360 & INSN_COPROC_MEMORY_DELAY)))
2362 /* Itbl support may require additional care here. */
2364 if ((! mips_opts.mips16
2365 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2366 && (! cop_interlocks
2367 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2368 || (! hilo_interlocks
2369 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2370 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2373 if (prev_insn_unreordered)
2376 else if ((! mips_opts.mips16
2377 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2378 && (! cop_interlocks
2379 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2380 || (! hilo_interlocks
2381 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2382 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2384 /* Itbl support may require additional care here. */
2385 if (! prev_prev_insn_unreordered)
2391 struct insn_label_list *l;
2395 /* Record the frag which holds the nop instructions, so
2396 that we can remove them if we don't need them. */
2397 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2398 prev_nop_frag = frag_now;
2399 prev_nop_frag_holds = nops;
2400 prev_nop_frag_required = 0;
2401 prev_nop_frag_since = 0;
2404 for (; nops > 0; --nops)
2409 /* Move on to a new frag, so that it is safe to simply
2410 decrease the size of prev_nop_frag. */
2411 frag_wane (frag_now);
2415 for (l = insn_labels; l != NULL; l = l->next)
2419 assert (S_GET_SEGMENT (l->label) == now_seg);
2420 symbol_set_frag (l->label, frag_now);
2421 val = (valueT) frag_now_fix ();
2422 /* mips16 text labels are stored as odd. */
2423 if (mips_opts.mips16)
2425 S_SET_VALUE (l->label, val);
2430 /* Mark instruction labels in mips16 mode. */
2431 if (mips_opts.mips16 && insns)
2432 mips16_mark_labels ();
2434 mips_no_prev_insn (insns);
2437 /* Build an instruction created by a macro expansion. This is passed
2438 a pointer to the count of instructions created so far, an
2439 expression, the name of the instruction to build, an operand format
2440 string, and corresponding arguments. */
2444 macro_build (char *place,
2452 macro_build (place, counter, ep, name, fmt, va_alist)
2461 struct mips_cl_insn insn;
2462 bfd_reloc_code_real_type r;
2466 va_start (args, fmt);
2472 * If the macro is about to expand into a second instruction,
2473 * print a warning if needed. We need to pass ip as a parameter
2474 * to generate a better warning message here...
2476 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2477 as_warn (_("Macro instruction expanded into multiple instructions"));
2480 *counter += 1; /* bump instruction counter */
2482 if (mips_opts.mips16)
2484 mips16_macro_build (place, counter, ep, name, fmt, args);
2489 r = BFD_RELOC_UNUSED;
2490 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2491 assert (insn.insn_mo);
2492 assert (strcmp (name, insn.insn_mo->name) == 0);
2494 /* Search until we get a match for NAME. */
2497 if (strcmp (fmt, insn.insn_mo->args) == 0
2498 && insn.insn_mo->pinfo != INSN_MACRO
2499 && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch,
2501 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2505 assert (insn.insn_mo->name);
2506 assert (strcmp (name, insn.insn_mo->name) == 0);
2509 insn.insn_opcode = insn.insn_mo->match;
2525 insn.insn_opcode |= va_arg (args, int) << 16;
2531 insn.insn_opcode |= va_arg (args, int) << 16;
2536 insn.insn_opcode |= va_arg (args, int) << 11;
2541 int tmp = va_arg (args, int);
2543 insn.insn_opcode |= tmp << 16;
2544 insn.insn_opcode |= tmp << 11;
2550 insn.insn_opcode |= va_arg (args, int) << 11;
2557 insn.insn_opcode |= va_arg (args, int) << 6;
2561 insn.insn_opcode |= va_arg (args, int) << 6;
2565 insn.insn_opcode |= va_arg (args, int) << 6;
2569 insn.insn_opcode |= va_arg (args, int) << 6;
2573 insn.insn_opcode |= va_arg (args, int) << 6;
2580 insn.insn_opcode |= va_arg (args, int) << 21;
2586 r = (bfd_reloc_code_real_type) va_arg (args, int);
2587 assert (r == BFD_RELOC_MIPS_GPREL
2588 || r == BFD_RELOC_MIPS_LITERAL
2589 || r == BFD_RELOC_LO16
2590 || r == BFD_RELOC_MIPS_GOT16
2591 || r == BFD_RELOC_MIPS_CALL16
2592 || r == BFD_RELOC_MIPS_GOT_LO16
2593 || r == BFD_RELOC_MIPS_CALL_LO16
2594 || (ep->X_op == O_subtract
2595 && r == BFD_RELOC_PCREL_LO16));
2599 r = (bfd_reloc_code_real_type) va_arg (args, int);
2601 && (ep->X_op == O_constant
2602 || (ep->X_op == O_symbol
2603 && (r == BFD_RELOC_HI16_S
2604 || r == BFD_RELOC_HI16
2605 || r == BFD_RELOC_MIPS_GOT_HI16
2606 || r == BFD_RELOC_MIPS_CALL_HI16))
2607 || (ep->X_op == O_subtract
2608 && r == BFD_RELOC_PCREL_HI16_S)));
2609 if (ep->X_op == O_constant)
2611 insn.insn_opcode |= (ep->X_add_number >> 16) & 0xffff;
2613 r = BFD_RELOC_UNUSED;
2618 assert (ep != NULL);
2620 * This allows macro() to pass an immediate expression for
2621 * creating short branches without creating a symbol.
2622 * Note that the expression still might come from the assembly
2623 * input, in which case the value is not checked for range nor
2624 * is a relocation entry generated (yuck).
2626 if (ep->X_op == O_constant)
2628 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
2632 r = BFD_RELOC_16_PCREL_S2;
2636 assert (ep != NULL);
2637 r = BFD_RELOC_MIPS_JMP;
2641 insn.insn_opcode |= va_arg (args, unsigned long);
2650 assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2652 append_insn (place, &insn, ep, r, false);
2656 mips16_macro_build (place, counter, ep, name, fmt, args)
2658 int *counter ATTRIBUTE_UNUSED;
2664 struct mips_cl_insn insn;
2665 bfd_reloc_code_real_type r;
2667 r = BFD_RELOC_UNUSED;
2668 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
2669 assert (insn.insn_mo);
2670 assert (strcmp (name, insn.insn_mo->name) == 0);
2672 while (strcmp (fmt, insn.insn_mo->args) != 0
2673 || insn.insn_mo->pinfo == INSN_MACRO)
2676 assert (insn.insn_mo->name);
2677 assert (strcmp (name, insn.insn_mo->name) == 0);
2680 insn.insn_opcode = insn.insn_mo->match;
2681 insn.use_extend = false;
2700 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
2705 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
2709 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
2713 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
2723 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
2730 regno = va_arg (args, int);
2731 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
2732 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
2753 assert (ep != NULL);
2755 if (ep->X_op != O_constant)
2756 r = BFD_RELOC_UNUSED + c;
2759 mips16_immed ((char *) NULL, 0, c, ep->X_add_number, false,
2760 false, false, &insn.insn_opcode,
2761 &insn.use_extend, &insn.extend);
2763 r = BFD_RELOC_UNUSED;
2769 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
2776 assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2778 append_insn (place, &insn, ep, r, false);
2782 * Generate a "lui" instruction.
2785 macro_build_lui (place, counter, ep, regnum)
2791 expressionS high_expr;
2792 struct mips_cl_insn insn;
2793 bfd_reloc_code_real_type r;
2794 CONST char *name = "lui";
2795 CONST char *fmt = "t,u";
2797 assert (! mips_opts.mips16);
2803 high_expr.X_op = O_constant;
2804 high_expr.X_add_number = ep->X_add_number;
2807 if (high_expr.X_op == O_constant)
2809 /* we can compute the instruction now without a relocation entry */
2810 if (high_expr.X_add_number & 0x8000)
2811 high_expr.X_add_number += 0x10000;
2812 high_expr.X_add_number =
2813 ((unsigned long) high_expr.X_add_number >> 16) & 0xffff;
2814 r = BFD_RELOC_UNUSED;
2818 assert (ep->X_op == O_symbol);
2819 /* _gp_disp is a special case, used from s_cpload. */
2820 assert (mips_pic == NO_PIC
2821 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
2822 r = BFD_RELOC_HI16_S;
2826 * If the macro is about to expand into a second instruction,
2827 * print a warning if needed. We need to pass ip as a parameter
2828 * to generate a better warning message here...
2830 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2831 as_warn (_("Macro instruction expanded into multiple instructions"));
2834 *counter += 1; /* bump instruction counter */
2836 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2837 assert (insn.insn_mo);
2838 assert (strcmp (name, insn.insn_mo->name) == 0);
2839 assert (strcmp (fmt, insn.insn_mo->args) == 0);
2841 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
2842 if (r == BFD_RELOC_UNUSED)
2844 insn.insn_opcode |= high_expr.X_add_number;
2845 append_insn (place, &insn, NULL, r, false);
2848 append_insn (place, &insn, &high_expr, r, false);
2852 * Generates code to set the $at register to true (one)
2853 * if reg is less than the immediate expression.
2856 set_at (counter, reg, unsignedp)
2861 if (imm_expr.X_op == O_constant
2862 && imm_expr.X_add_number >= -0x8000
2863 && imm_expr.X_add_number < 0x8000)
2864 macro_build ((char *) NULL, counter, &imm_expr,
2865 unsignedp ? "sltiu" : "slti",
2866 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
2869 load_register (counter, AT, &imm_expr, 0);
2870 macro_build ((char *) NULL, counter, NULL,
2871 unsignedp ? "sltu" : "slt",
2872 "d,v,t", AT, reg, AT);
2876 /* Warn if an expression is not a constant. */
2879 check_absolute_expr (ip, ex)
2880 struct mips_cl_insn *ip;
2883 if (ex->X_op == O_big)
2884 as_bad (_("unsupported large constant"));
2885 else if (ex->X_op != O_constant)
2886 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
2889 /* Count the leading zeroes by performing a binary chop. This is a
2890 bulky bit of source, but performance is a LOT better for the
2891 majority of values than a simple loop to count the bits:
2892 for (lcnt = 0; (lcnt < 32); lcnt++)
2893 if ((v) & (1 << (31 - lcnt)))
2895 However it is not code size friendly, and the gain will drop a bit
2896 on certain cached systems.
2898 #define COUNT_TOP_ZEROES(v) \
2899 (((v) & ~0xffff) == 0 \
2900 ? ((v) & ~0xff) == 0 \
2901 ? ((v) & ~0xf) == 0 \
2902 ? ((v) & ~0x3) == 0 \
2903 ? ((v) & ~0x1) == 0 \
2908 : ((v) & ~0x7) == 0 \
2911 : ((v) & ~0x3f) == 0 \
2912 ? ((v) & ~0x1f) == 0 \
2915 : ((v) & ~0x7f) == 0 \
2918 : ((v) & ~0xfff) == 0 \
2919 ? ((v) & ~0x3ff) == 0 \
2920 ? ((v) & ~0x1ff) == 0 \
2923 : ((v) & ~0x7ff) == 0 \
2926 : ((v) & ~0x3fff) == 0 \
2927 ? ((v) & ~0x1fff) == 0 \
2930 : ((v) & ~0x7fff) == 0 \
2933 : ((v) & ~0xffffff) == 0 \
2934 ? ((v) & ~0xfffff) == 0 \
2935 ? ((v) & ~0x3ffff) == 0 \
2936 ? ((v) & ~0x1ffff) == 0 \
2939 : ((v) & ~0x7ffff) == 0 \
2942 : ((v) & ~0x3fffff) == 0 \
2943 ? ((v) & ~0x1fffff) == 0 \
2946 : ((v) & ~0x7fffff) == 0 \
2949 : ((v) & ~0xfffffff) == 0 \
2950 ? ((v) & ~0x3ffffff) == 0 \
2951 ? ((v) & ~0x1ffffff) == 0 \
2954 : ((v) & ~0x7ffffff) == 0 \
2957 : ((v) & ~0x3fffffff) == 0 \
2958 ? ((v) & ~0x1fffffff) == 0 \
2961 : ((v) & ~0x7fffffff) == 0 \
2966 * This routine generates the least number of instructions neccessary to load
2967 * an absolute expression value into a register.
2970 load_register (counter, reg, ep, dbl)
2977 expressionS hi32, lo32;
2979 if (ep->X_op != O_big)
2981 assert (ep->X_op == O_constant);
2982 if (ep->X_add_number < 0x8000
2983 && (ep->X_add_number >= 0
2984 || (ep->X_add_number >= -0x8000
2987 || sizeof (ep->X_add_number) > 4))))
2989 /* We can handle 16 bit signed values with an addiu to
2990 $zero. No need to ever use daddiu here, since $zero and
2991 the result are always correct in 32 bit mode. */
2992 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
2993 (int) BFD_RELOC_LO16);
2996 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
2998 /* We can handle 16 bit unsigned values with an ori to
3000 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3001 (int) BFD_RELOC_LO16);
3004 else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0
3005 || ((ep->X_add_number &~ (offsetT) 0x7fffffff)
3006 == ~ (offsetT) 0x7fffffff))
3009 || sizeof (ep->X_add_number) > 4
3010 || (ep->X_add_number & 0x80000000) == 0))
3011 || ((! ISA_HAS_64BIT_REGS (mips_opts.isa) || ! dbl)
3012 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3013 || (! ISA_HAS_64BIT_REGS (mips_opts.isa)
3015 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3016 == ~ (offsetT) 0xffffffff)))
3018 /* 32 bit values require an lui. */
3019 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3020 (int) BFD_RELOC_HI16);
3021 if ((ep->X_add_number & 0xffff) != 0)
3022 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3023 (int) BFD_RELOC_LO16);
3028 /* The value is larger than 32 bits. */
3030 if (! ISA_HAS_64BIT_REGS (mips_opts.isa))
3032 as_bad (_("Number larger than 32 bits"));
3033 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3034 (int) BFD_RELOC_LO16);
3038 if (ep->X_op != O_big)
3041 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3042 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3043 hi32.X_add_number &= 0xffffffff;
3045 lo32.X_add_number &= 0xffffffff;
3049 assert (ep->X_add_number > 2);
3050 if (ep->X_add_number == 3)
3051 generic_bignum[3] = 0;
3052 else if (ep->X_add_number > 4)
3053 as_bad (_("Number larger than 64 bits"));
3054 lo32.X_op = O_constant;
3055 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3056 hi32.X_op = O_constant;
3057 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3060 if (hi32.X_add_number == 0)
3065 unsigned long hi, lo;
3067 if (hi32.X_add_number == 0xffffffff)
3069 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3071 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3072 reg, 0, (int) BFD_RELOC_LO16);
3075 if (lo32.X_add_number & 0x80000000)
3077 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3078 (int) BFD_RELOC_HI16);
3079 if (lo32.X_add_number & 0xffff)
3080 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3081 reg, reg, (int) BFD_RELOC_LO16);
3086 /* Check for 16bit shifted constant. We know that hi32 is
3087 non-zero, so start the mask on the first bit of the hi32
3092 unsigned long himask, lomask;
3096 himask = 0xffff >> (32 - shift);
3097 lomask = (0xffff << shift) & 0xffffffff;
3101 himask = 0xffff << (shift - 32);
3104 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3105 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3109 tmp.X_op = O_constant;
3111 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3112 | (lo32.X_add_number >> shift));
3114 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3115 macro_build ((char *) NULL, counter, &tmp,
3116 "ori", "t,r,i", reg, 0,
3117 (int) BFD_RELOC_LO16);
3118 macro_build ((char *) NULL, counter, NULL,
3119 (shift >= 32) ? "dsll32" : "dsll",
3121 (shift >= 32) ? shift - 32 : shift);
3126 while (shift <= (64 - 16));
3128 /* Find the bit number of the lowest one bit, and store the
3129 shifted value in hi/lo. */
3130 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3131 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3135 while ((lo & 1) == 0)
3140 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3146 while ((hi & 1) == 0)
3155 /* Optimize if the shifted value is a (power of 2) - 1. */
3156 if ((hi == 0 && ((lo + 1) & lo) == 0)
3157 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3159 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3164 /* This instruction will set the register to be all
3166 tmp.X_op = O_constant;
3167 tmp.X_add_number = (offsetT) -1;
3168 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3169 reg, 0, (int) BFD_RELOC_LO16);
3173 macro_build ((char *) NULL, counter, NULL,
3174 (bit >= 32) ? "dsll32" : "dsll",
3176 (bit >= 32) ? bit - 32 : bit);
3178 macro_build ((char *) NULL, counter, NULL,
3179 (shift >= 32) ? "dsrl32" : "dsrl",
3181 (shift >= 32) ? shift - 32 : shift);
3186 /* Sign extend hi32 before calling load_register, because we can
3187 generally get better code when we load a sign extended value. */
3188 if ((hi32.X_add_number & 0x80000000) != 0)
3189 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3190 load_register (counter, reg, &hi32, 0);
3193 if ((lo32.X_add_number & 0xffff0000) == 0)
3197 macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg,
3206 if ((freg == 0) && (lo32.X_add_number == 0xffffffff))
3208 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3209 (int) BFD_RELOC_HI16);
3210 macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg,
3217 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
3222 mid16.X_add_number >>= 16;
3223 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3224 freg, (int) BFD_RELOC_LO16);
3225 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
3229 if ((lo32.X_add_number & 0xffff) != 0)
3230 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3231 (int) BFD_RELOC_LO16);
3234 /* Load an address into a register. */
3237 load_address (counter, reg, ep)
3244 if (ep->X_op != O_constant
3245 && ep->X_op != O_symbol)
3247 as_bad (_("expression too complex"));
3248 ep->X_op = O_constant;
3251 if (ep->X_op == O_constant)
3253 load_register (counter, reg, ep, 0);
3257 if (mips_pic == NO_PIC)
3259 /* If this is a reference to a GP relative symbol, we want
3260 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
3262 lui $reg,<sym> (BFD_RELOC_HI16_S)
3263 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3264 If we have an addend, we always use the latter form. */
3265 if ((valueT) ep->X_add_number >= MAX_GPREL_OFFSET
3266 || nopic_need_relax (ep->X_add_symbol, 1))
3271 macro_build ((char *) NULL, counter, ep,
3272 ((bfd_arch_bits_per_address (stdoutput) == 32
3273 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3274 ? "addiu" : "daddiu"),
3275 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
3276 p = frag_var (rs_machine_dependent, 8, 0,
3277 RELAX_ENCODE (4, 8, 0, 4, 0,
3278 mips_opts.warn_about_macros),
3279 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3281 macro_build_lui (p, counter, ep, reg);
3284 macro_build (p, counter, ep,
3285 ((bfd_arch_bits_per_address (stdoutput) == 32
3286 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3287 ? "addiu" : "daddiu"),
3288 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3290 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3294 /* If this is a reference to an external symbol, we want
3295 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3297 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3299 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3300 If there is a constant, it must be added in after. */
3301 ex.X_add_number = ep->X_add_number;
3302 ep->X_add_number = 0;
3304 macro_build ((char *) NULL, counter, ep,
3305 ((bfd_arch_bits_per_address (stdoutput) == 32
3306 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3308 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3309 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3310 p = frag_var (rs_machine_dependent, 4, 0,
3311 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3312 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3313 macro_build (p, counter, ep,
3314 ((bfd_arch_bits_per_address (stdoutput) == 32
3315 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3316 ? "addiu" : "daddiu"),
3317 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3318 if (ex.X_add_number != 0)
3320 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3321 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3322 ex.X_op = O_constant;
3323 macro_build ((char *) NULL, counter, &ex,
3324 ((bfd_arch_bits_per_address (stdoutput) == 32
3325 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3326 ? "addiu" : "daddiu"),
3327 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3330 else if (mips_pic == SVR4_PIC)
3335 /* This is the large GOT case. If this is a reference to an
3336 external symbol, we want
3337 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3339 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3340 Otherwise, for a reference to a local symbol, we want
3341 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3343 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3344 If there is a constant, it must be added in after. */
3345 ex.X_add_number = ep->X_add_number;
3346 ep->X_add_number = 0;
3347 if (reg_needs_delay (GP))
3352 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3353 (int) BFD_RELOC_MIPS_GOT_HI16);
3354 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3355 ((bfd_arch_bits_per_address (stdoutput) == 32
3356 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3357 ? "addu" : "daddu"),
3358 "d,v,t", reg, reg, GP);
3359 macro_build ((char *) NULL, counter, ep,
3360 ((bfd_arch_bits_per_address (stdoutput) == 32
3361 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3363 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3364 p = frag_var (rs_machine_dependent, 12 + off, 0,
3365 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3366 mips_opts.warn_about_macros),
3367 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3370 /* We need a nop before loading from $gp. This special
3371 check is required because the lui which starts the main
3372 instruction stream does not refer to $gp, and so will not
3373 insert the nop which may be required. */
3374 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3377 macro_build (p, counter, ep,
3378 ((bfd_arch_bits_per_address (stdoutput) == 32
3379 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3381 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3383 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3385 macro_build (p, counter, ep,
3386 ((bfd_arch_bits_per_address (stdoutput) == 32
3387 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3388 ? "addiu" : "daddiu"),
3389 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3390 if (ex.X_add_number != 0)
3392 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3393 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3394 ex.X_op = O_constant;
3395 macro_build ((char *) NULL, counter, &ex,
3396 ((bfd_arch_bits_per_address (stdoutput) == 32
3397 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3398 ? "addiu" : "daddiu"),
3399 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3402 else if (mips_pic == EMBEDDED_PIC)
3405 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
3407 macro_build ((char *) NULL, counter, ep,
3408 ((bfd_arch_bits_per_address (stdoutput) == 32
3409 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3410 ? "addiu" : "daddiu"),
3411 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
3419 * This routine implements the seemingly endless macro or synthesized
3420 * instructions and addressing modes in the mips assembly language. Many
3421 * of these macros are simple and are similar to each other. These could
3422 * probably be handled by some kind of table or grammer aproach instead of
3423 * this verbose method. Others are not simple macros but are more like
3424 * optimizing code generation.
3425 * One interesting optimization is when several store macros appear
3426 * consecutivly that would load AT with the upper half of the same address.
3427 * The ensuing load upper instructions are ommited. This implies some kind
3428 * of global optimization. We currently only optimize within a single macro.
3429 * For many of the load and store macros if the address is specified as a
3430 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3431 * first load register 'at' with zero and use it as the base register. The
3432 * mips assembler simply uses register $zero. Just one tiny optimization
3437 struct mips_cl_insn *ip;
3439 register int treg, sreg, dreg, breg;
3455 bfd_reloc_code_real_type r;
3457 int hold_mips_optimize;
3459 assert (! mips_opts.mips16);
3461 treg = (ip->insn_opcode >> 16) & 0x1f;
3462 dreg = (ip->insn_opcode >> 11) & 0x1f;
3463 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3464 mask = ip->insn_mo->mask;
3466 expr1.X_op = O_constant;
3467 expr1.X_op_symbol = NULL;
3468 expr1.X_add_symbol = NULL;
3469 expr1.X_add_number = 1;
3481 mips_emit_delays (true);
3482 ++mips_opts.noreorder;
3483 mips_any_noreorder = 1;
3485 expr1.X_add_number = 8;
3486 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3488 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3490 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, sreg, 0);
3491 macro_build ((char *) NULL, &icnt, NULL,
3492 dbl ? "dsub" : "sub",
3493 "d,v,t", dreg, 0, sreg);
3495 --mips_opts.noreorder;
3516 if (imm_expr.X_op == O_constant
3517 && imm_expr.X_add_number >= -0x8000
3518 && imm_expr.X_add_number < 0x8000)
3520 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3521 (int) BFD_RELOC_LO16);
3524 load_register (&icnt, AT, &imm_expr, dbl);
3525 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
3544 if (imm_expr.X_op == O_constant
3545 && imm_expr.X_add_number >= 0
3546 && imm_expr.X_add_number < 0x10000)
3548 if (mask != M_NOR_I)
3549 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
3550 sreg, (int) BFD_RELOC_LO16);
3553 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
3554 treg, sreg, (int) BFD_RELOC_LO16);
3555 macro_build ((char *) NULL, &icnt, NULL, "nor", "d,v,t",
3561 load_register (&icnt, AT, &imm_expr, 0);
3562 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
3579 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3581 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
3585 load_register (&icnt, AT, &imm_expr, 0);
3586 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
3594 macro_build ((char *) NULL, &icnt, &offset_expr,
3595 likely ? "bgezl" : "bgez",
3601 macro_build ((char *) NULL, &icnt, &offset_expr,
3602 likely ? "blezl" : "blez",
3606 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
3607 macro_build ((char *) NULL, &icnt, &offset_expr,
3608 likely ? "beql" : "beq",
3615 /* check for > max integer */
3616 maxnum = 0x7fffffff;
3617 if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4)
3624 if (imm_expr.X_op == O_constant
3625 && imm_expr.X_add_number >= maxnum
3626 && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4))
3629 /* result is always false */
3633 as_warn (_("Branch %s is always false (nop)"),
3635 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3640 as_warn (_("Branch likely %s is always false"),
3642 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
3647 if (imm_expr.X_op != O_constant)
3648 as_bad (_("Unsupported large constant"));
3649 imm_expr.X_add_number++;
3653 if (mask == M_BGEL_I)
3655 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3657 macro_build ((char *) NULL, &icnt, &offset_expr,
3658 likely ? "bgezl" : "bgez",
3662 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3664 macro_build ((char *) NULL, &icnt, &offset_expr,
3665 likely ? "bgtzl" : "bgtz",
3669 maxnum = 0x7fffffff;
3670 if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4)
3677 maxnum = - maxnum - 1;
3678 if (imm_expr.X_op == O_constant
3679 && imm_expr.X_add_number <= maxnum
3680 && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4))
3683 /* result is always true */
3684 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
3685 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
3688 set_at (&icnt, sreg, 0);
3689 macro_build ((char *) NULL, &icnt, &offset_expr,
3690 likely ? "beql" : "beq",
3701 macro_build ((char *) NULL, &icnt, &offset_expr,
3702 likely ? "beql" : "beq",
3706 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
3708 macro_build ((char *) NULL, &icnt, &offset_expr,
3709 likely ? "beql" : "beq",
3717 || (! ISA_HAS_64BIT_REGS (mips_opts.isa)
3718 && imm_expr.X_op == O_constant
3719 && imm_expr.X_add_number == 0xffffffff))
3721 if (imm_expr.X_op != O_constant)
3722 as_bad (_("Unsupported large constant"));
3723 imm_expr.X_add_number++;
3727 if (mask == M_BGEUL_I)
3729 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3731 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3733 macro_build ((char *) NULL, &icnt, &offset_expr,
3734 likely ? "bnel" : "bne",
3738 set_at (&icnt, sreg, 1);
3739 macro_build ((char *) NULL, &icnt, &offset_expr,
3740 likely ? "beql" : "beq",
3749 macro_build ((char *) NULL, &icnt, &offset_expr,
3750 likely ? "bgtzl" : "bgtz",
3756 macro_build ((char *) NULL, &icnt, &offset_expr,
3757 likely ? "bltzl" : "bltz",
3761 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
3762 macro_build ((char *) NULL, &icnt, &offset_expr,
3763 likely ? "bnel" : "bne",
3772 macro_build ((char *) NULL, &icnt, &offset_expr,
3773 likely ? "bnel" : "bne",
3779 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
3781 macro_build ((char *) NULL, &icnt, &offset_expr,
3782 likely ? "bnel" : "bne",
3791 macro_build ((char *) NULL, &icnt, &offset_expr,
3792 likely ? "blezl" : "blez",
3798 macro_build ((char *) NULL, &icnt, &offset_expr,
3799 likely ? "bgezl" : "bgez",
3803 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
3804 macro_build ((char *) NULL, &icnt, &offset_expr,
3805 likely ? "beql" : "beq",
3812 maxnum = 0x7fffffff;
3813 if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4)
3820 if (imm_expr.X_op == O_constant
3821 && imm_expr.X_add_number >= maxnum
3822 && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4))
3824 if (imm_expr.X_op != O_constant)
3825 as_bad (_("Unsupported large constant"));
3826 imm_expr.X_add_number++;
3830 if (mask == M_BLTL_I)
3832 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3834 macro_build ((char *) NULL, &icnt, &offset_expr,
3835 likely ? "bltzl" : "bltz",
3839 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3841 macro_build ((char *) NULL, &icnt, &offset_expr,
3842 likely ? "blezl" : "blez",
3846 set_at (&icnt, sreg, 0);
3847 macro_build ((char *) NULL, &icnt, &offset_expr,
3848 likely ? "bnel" : "bne",
3857 macro_build ((char *) NULL, &icnt, &offset_expr,
3858 likely ? "beql" : "beq",
3864 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
3866 macro_build ((char *) NULL, &icnt, &offset_expr,
3867 likely ? "beql" : "beq",
3875 || (! ISA_HAS_64BIT_REGS (mips_opts.isa)
3876 && imm_expr.X_op == O_constant
3877 && imm_expr.X_add_number == 0xffffffff))
3879 if (imm_expr.X_op != O_constant)
3880 as_bad (_("Unsupported large constant"));
3881 imm_expr.X_add_number++;
3885 if (mask == M_BLTUL_I)
3887 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3889 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3891 macro_build ((char *) NULL, &icnt, &offset_expr,
3892 likely ? "beql" : "beq",
3896 set_at (&icnt, sreg, 1);
3897 macro_build ((char *) NULL, &icnt, &offset_expr,
3898 likely ? "bnel" : "bne",
3907 macro_build ((char *) NULL, &icnt, &offset_expr,
3908 likely ? "bltzl" : "bltz",
3914 macro_build ((char *) NULL, &icnt, &offset_expr,
3915 likely ? "bgtzl" : "bgtz",
3919 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
3920 macro_build ((char *) NULL, &icnt, &offset_expr,
3921 likely ? "bnel" : "bne",
3932 macro_build ((char *) NULL, &icnt, &offset_expr,
3933 likely ? "bnel" : "bne",
3937 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
3939 macro_build ((char *) NULL, &icnt, &offset_expr,
3940 likely ? "bnel" : "bne",
3956 as_warn (_("Divide by zero."));
3958 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
3960 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
3964 mips_emit_delays (true);
3965 ++mips_opts.noreorder;
3966 mips_any_noreorder = 1;
3969 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0);
3970 macro_build ((char *) NULL, &icnt, NULL,
3971 dbl ? "ddiv" : "div",
3972 "z,s,t", sreg, treg);
3976 expr1.X_add_number = 8;
3977 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
3978 macro_build ((char *) NULL, &icnt, NULL,
3979 dbl ? "ddiv" : "div",
3980 "z,s,t", sreg, treg);
3981 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
3983 expr1.X_add_number = -1;
3984 macro_build ((char *) NULL, &icnt, &expr1,
3985 dbl ? "daddiu" : "addiu",
3986 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
3987 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
3988 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
3991 expr1.X_add_number = 1;
3992 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
3993 (int) BFD_RELOC_LO16);
3994 macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT,
3999 expr1.X_add_number = 0x80000000;
4000 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4001 (int) BFD_RELOC_HI16);
4005 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", sreg, AT);
4006 /* We want to close the noreorder block as soon as possible, so
4007 that later insns are available for delay slot filling. */
4008 --mips_opts.noreorder;
4012 expr1.X_add_number = 8;
4013 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4014 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
4016 /* We want to close the noreorder block as soon as possible, so
4017 that later insns are available for delay slot filling. */
4018 --mips_opts.noreorder;
4020 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
4022 macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg);
4061 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4063 as_warn (_("Divide by zero."));
4065 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
4067 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
4070 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4072 if (strcmp (s2, "mflo") == 0)
4073 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg,
4076 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
4079 if (imm_expr.X_op == O_constant
4080 && imm_expr.X_add_number == -1
4081 && s[strlen (s) - 1] != 'u')
4083 if (strcmp (s2, "mflo") == 0)
4086 macro_build ((char *) NULL, &icnt, NULL, "dneg", "d,w", dreg,
4089 macro_build ((char *) NULL, &icnt, NULL, "neg", "d,w", dreg,
4093 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
4097 load_register (&icnt, AT, &imm_expr, dbl);
4098 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT);
4099 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
4118 mips_emit_delays (true);
4119 ++mips_opts.noreorder;
4120 mips_any_noreorder = 1;
4123 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0);
4124 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4125 /* We want to close the noreorder block as soon as possible, so
4126 that later insns are available for delay slot filling. */
4127 --mips_opts.noreorder;
4131 expr1.X_add_number = 8;
4132 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4133 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4135 /* We want to close the noreorder block as soon as possible, so
4136 that later insns are available for delay slot filling. */
4137 --mips_opts.noreorder;
4138 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
4140 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
4146 /* Load the address of a symbol into a register. If breg is not
4147 zero, we then add a base register to it. */
4149 /* When generating embedded PIC code, we permit expressions of
4152 where bar is an address in the current section. These are used
4153 when getting the addresses of functions. We don't permit
4154 X_add_number to be non-zero, because if the symbol is
4155 external the relaxing code needs to know that any addend is
4156 purely the offset to X_op_symbol. */
4157 if (mips_pic == EMBEDDED_PIC
4158 && offset_expr.X_op == O_subtract
4159 && (symbol_constant_p (offset_expr.X_op_symbol)
4160 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4161 : (symbol_equated_p (offset_expr.X_op_symbol)
4163 (symbol_get_value_expression (offset_expr.X_op_symbol)
4167 && (offset_expr.X_add_number == 0
4168 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4170 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4171 treg, (int) BFD_RELOC_PCREL_HI16_S);
4172 macro_build ((char *) NULL, &icnt, &offset_expr,
4173 ((bfd_arch_bits_per_address (stdoutput) == 32
4174 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4175 ? "addiu" : "daddiu"),
4176 "t,r,j", treg, treg, (int) BFD_RELOC_PCREL_LO16);
4180 if (offset_expr.X_op != O_symbol
4181 && offset_expr.X_op != O_constant)
4183 as_bad (_("expression too complex"));
4184 offset_expr.X_op = O_constant;
4198 if (offset_expr.X_op == O_constant)
4199 load_register (&icnt, tempreg, &offset_expr, dbl);
4200 else if (mips_pic == NO_PIC)
4202 /* If this is a reference to an GP relative symbol, we want
4203 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
4205 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4206 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4207 If we have a constant, we need two instructions anyhow,
4208 so we may as well always use the latter form. */
4209 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
4210 || nopic_need_relax (offset_expr.X_add_symbol, 1))
4215 macro_build ((char *) NULL, &icnt, &offset_expr,
4216 ((bfd_arch_bits_per_address (stdoutput) == 32
4217 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4218 ? "addiu" : "daddiu"),
4219 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
4220 p = frag_var (rs_machine_dependent, 8, 0,
4221 RELAX_ENCODE (4, 8, 0, 4, 0,
4222 mips_opts.warn_about_macros),
4223 offset_expr.X_add_symbol, (offsetT) 0,
4226 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4229 macro_build (p, &icnt, &offset_expr,
4230 ((bfd_arch_bits_per_address (stdoutput) == 32
4231 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4232 ? "addiu" : "daddiu"),
4233 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4235 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4237 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4239 /* If this is a reference to an external symbol, and there
4240 is no constant, we want
4241 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4242 or if tempreg is PIC_CALL_REG
4243 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4244 For a local symbol, we want
4245 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4247 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4249 If we have a small constant, and this is a reference to
4250 an external symbol, we want
4251 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4253 addiu $tempreg,$tempreg,<constant>
4254 For a local symbol, we want the same instruction
4255 sequence, but we output a BFD_RELOC_LO16 reloc on the
4258 If we have a large constant, and this is a reference to
4259 an external symbol, we want
4260 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4261 lui $at,<hiconstant>
4262 addiu $at,$at,<loconstant>
4263 addu $tempreg,$tempreg,$at
4264 For a local symbol, we want the same instruction
4265 sequence, but we output a BFD_RELOC_LO16 reloc on the
4266 addiu instruction. */
4267 expr1.X_add_number = offset_expr.X_add_number;
4268 offset_expr.X_add_number = 0;
4270 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4271 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4272 macro_build ((char *) NULL, &icnt, &offset_expr,
4274 "t,o(b)", tempreg, lw_reloc_type, GP);
4275 if (expr1.X_add_number == 0)
4283 /* We're going to put in an addu instruction using
4284 tempreg, so we may as well insert the nop right
4286 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4290 p = frag_var (rs_machine_dependent, 8 - off, 0,
4291 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4293 ? mips_opts.warn_about_macros
4295 offset_expr.X_add_symbol, (offsetT) 0,
4299 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4302 macro_build (p, &icnt, &expr1,
4303 ((bfd_arch_bits_per_address (stdoutput) == 32
4304 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4305 ? "addiu" : "daddiu"),
4306 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4307 /* FIXME: If breg == 0, and the next instruction uses
4308 $tempreg, then if this variant case is used an extra
4309 nop will be generated. */
4311 else if (expr1.X_add_number >= -0x8000
4312 && expr1.X_add_number < 0x8000)
4314 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4316 macro_build ((char *) NULL, &icnt, &expr1,
4317 ((bfd_arch_bits_per_address (stdoutput) == 32
4318 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4319 ? "addiu" : "daddiu"),
4320 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4321 (void) frag_var (rs_machine_dependent, 0, 0,
4322 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4323 offset_expr.X_add_symbol, (offsetT) 0,
4330 /* If we are going to add in a base register, and the
4331 target register and the base register are the same,
4332 then we are using AT as a temporary register. Since
4333 we want to load the constant into AT, we add our
4334 current AT (from the global offset table) and the
4335 register into the register now, and pretend we were
4336 not using a base register. */
4341 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4343 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4344 ((bfd_arch_bits_per_address (stdoutput) == 32
4345 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4346 ? "addu" : "daddu"),
4347 "d,v,t", treg, AT, breg);
4353 /* Set mips_optimize around the lui instruction to avoid
4354 inserting an unnecessary nop after the lw. */
4355 hold_mips_optimize = mips_optimize;
4357 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
4358 mips_optimize = hold_mips_optimize;
4360 macro_build ((char *) NULL, &icnt, &expr1,
4361 ((bfd_arch_bits_per_address (stdoutput) == 32
4362 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4363 ? "addiu" : "daddiu"),
4364 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4365 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4366 ((bfd_arch_bits_per_address (stdoutput) == 32
4367 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4368 ? "addu" : "daddu"),
4369 "d,v,t", tempreg, tempreg, AT);
4370 (void) frag_var (rs_machine_dependent, 0, 0,
4371 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4372 offset_expr.X_add_symbol, (offsetT) 0,
4377 else if (mips_pic == SVR4_PIC)
4380 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
4381 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
4383 /* This is the large GOT case. If this is a reference to an
4384 external symbol, and there is no constant, we want
4385 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4386 addu $tempreg,$tempreg,$gp
4387 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4388 or if tempreg is PIC_CALL_REG
4389 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4390 addu $tempreg,$tempreg,$gp
4391 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4392 For a local symbol, we want
4393 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4395 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4397 If we have a small constant, and this is a reference to
4398 an external symbol, we want
4399 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4400 addu $tempreg,$tempreg,$gp
4401 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4403 addiu $tempreg,$tempreg,<constant>
4404 For a local symbol, we want
4405 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4407 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4409 If we have a large constant, and this is a reference to
4410 an external symbol, we want
4411 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4412 addu $tempreg,$tempreg,$gp
4413 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4414 lui $at,<hiconstant>
4415 addiu $at,$at,<loconstant>
4416 addu $tempreg,$tempreg,$at
4417 For a local symbol, we want
4418 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4419 lui $at,<hiconstant>
4420 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4421 addu $tempreg,$tempreg,$at
4423 expr1.X_add_number = offset_expr.X_add_number;
4424 offset_expr.X_add_number = 0;
4426 if (reg_needs_delay (GP))
4430 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4432 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
4433 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
4435 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4436 tempreg, lui_reloc_type);
4437 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4438 ((bfd_arch_bits_per_address (stdoutput) == 32
4439 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4440 ? "addu" : "daddu"),
4441 "d,v,t", tempreg, tempreg, GP);
4442 macro_build ((char *) NULL, &icnt, &offset_expr,
4444 "t,o(b)", tempreg, lw_reloc_type, tempreg);
4445 if (expr1.X_add_number == 0)
4453 /* We're going to put in an addu instruction using
4454 tempreg, so we may as well insert the nop right
4456 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4461 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4462 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4465 ? mips_opts.warn_about_macros
4467 offset_expr.X_add_symbol, (offsetT) 0,
4470 else if (expr1.X_add_number >= -0x8000
4471 && expr1.X_add_number < 0x8000)
4473 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4475 macro_build ((char *) NULL, &icnt, &expr1,
4476 ((bfd_arch_bits_per_address (stdoutput) == 32
4477 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4478 ? "addiu" : "daddiu"),
4479 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4481 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4482 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4484 ? mips_opts.warn_about_macros
4486 offset_expr.X_add_symbol, (offsetT) 0,
4493 /* If we are going to add in a base register, and the
4494 target register and the base register are the same,
4495 then we are using AT as a temporary register. Since
4496 we want to load the constant into AT, we add our
4497 current AT (from the global offset table) and the
4498 register into the register now, and pretend we were
4499 not using a base register. */
4507 assert (tempreg == AT);
4508 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4510 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4511 ((bfd_arch_bits_per_address (stdoutput) == 32
4512 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4513 ? "addu" : "daddu"),
4514 "d,v,t", treg, AT, breg);
4519 /* Set mips_optimize around the lui instruction to avoid
4520 inserting an unnecessary nop after the lw. */
4521 hold_mips_optimize = mips_optimize;
4523 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
4524 mips_optimize = hold_mips_optimize;
4526 macro_build ((char *) NULL, &icnt, &expr1,
4527 ((bfd_arch_bits_per_address (stdoutput) == 32
4528 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4529 ? "addiu" : "daddiu"),
4530 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4531 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4532 ((bfd_arch_bits_per_address (stdoutput) == 32
4533 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4534 ? "addu" : "daddu"),
4535 "d,v,t", dreg, dreg, AT);
4537 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
4538 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
4541 ? mips_opts.warn_about_macros
4543 offset_expr.X_add_symbol, (offsetT) 0,
4551 /* This is needed because this instruction uses $gp, but
4552 the first instruction on the main stream does not. */
4553 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4556 macro_build (p, &icnt, &offset_expr,
4558 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
4560 if (expr1.X_add_number >= -0x8000
4561 && expr1.X_add_number < 0x8000)
4563 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4565 macro_build (p, &icnt, &expr1,
4566 ((bfd_arch_bits_per_address (stdoutput) == 32
4567 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4568 ? "addiu" : "daddiu"),
4569 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4570 /* FIXME: If add_number is 0, and there was no base
4571 register, the external symbol case ended with a load,
4572 so if the symbol turns out to not be external, and
4573 the next instruction uses tempreg, an unnecessary nop
4574 will be inserted. */
4580 /* We must add in the base register now, as in the
4581 external symbol case. */
4582 assert (tempreg == AT);
4583 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4585 macro_build (p, &icnt, (expressionS *) NULL,
4586 ((bfd_arch_bits_per_address (stdoutput) == 32
4587 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4588 ? "addu" : "daddu"),
4589 "d,v,t", treg, AT, breg);
4592 /* We set breg to 0 because we have arranged to add
4593 it in in both cases. */
4597 macro_build_lui (p, &icnt, &expr1, AT);
4599 macro_build (p, &icnt, &expr1,
4600 ((bfd_arch_bits_per_address (stdoutput) == 32
4601 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4602 ? "addiu" : "daddiu"),
4603 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4605 macro_build (p, &icnt, (expressionS *) NULL,
4606 ((bfd_arch_bits_per_address (stdoutput) == 32
4607 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4608 ? "addu" : "daddu"),
4609 "d,v,t", tempreg, tempreg, AT);
4613 else if (mips_pic == EMBEDDED_PIC)
4616 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
4618 macro_build ((char *) NULL, &icnt, &offset_expr,
4619 ((bfd_arch_bits_per_address (stdoutput) == 32
4620 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4621 ? "addiu" : "daddiu"),
4622 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
4628 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4629 ((bfd_arch_bits_per_address (stdoutput) == 32
4630 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4631 ? "addu" : "daddu"),
4632 "d,v,t", treg, tempreg, breg);
4640 /* The j instruction may not be used in PIC code, since it
4641 requires an absolute address. We convert it to a b
4643 if (mips_pic == NO_PIC)
4644 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
4646 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4649 /* The jal instructions must be handled as macros because when
4650 generating PIC code they expand to multi-instruction
4651 sequences. Normally they are simple instructions. */
4656 if (mips_pic == NO_PIC
4657 || mips_pic == EMBEDDED_PIC)
4658 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
4660 else if (mips_pic == SVR4_PIC)
4662 if (sreg != PIC_CALL_REG)
4663 as_warn (_("MIPS PIC call to register other than $25"));
4665 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
4667 if (mips_cprestore_offset < 0)
4668 as_warn (_("No .cprestore pseudo-op used in PIC code"));
4671 expr1.X_add_number = mips_cprestore_offset;
4672 macro_build ((char *) NULL, &icnt, &expr1,
4673 ((bfd_arch_bits_per_address (stdoutput) == 32
4674 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4676 "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg);
4685 if (mips_pic == NO_PIC)
4686 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
4687 else if (mips_pic == SVR4_PIC)
4689 /* If this is a reference to an external symbol, and we are
4690 using a small GOT, we want
4691 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4695 lw $gp,cprestore($sp)
4696 The cprestore value is set using the .cprestore
4697 pseudo-op. If we are using a big GOT, we want
4698 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4700 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
4704 lw $gp,cprestore($sp)
4705 If the symbol is not external, we want
4706 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4708 addiu $25,$25,<sym> (BFD_RELOC_LO16)
4711 lw $gp,cprestore($sp) */
4715 macro_build ((char *) NULL, &icnt, &offset_expr,
4716 ((bfd_arch_bits_per_address (stdoutput) == 32
4717 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4719 "t,o(b)", PIC_CALL_REG,
4720 (int) BFD_RELOC_MIPS_CALL16, GP);
4721 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4723 p = frag_var (rs_machine_dependent, 4, 0,
4724 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
4725 offset_expr.X_add_symbol, (offsetT) 0,
4732 if (reg_needs_delay (GP))
4736 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4737 PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16);
4738 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4739 ((bfd_arch_bits_per_address (stdoutput) == 32
4740 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4741 ? "addu" : "daddu"),
4742 "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP);
4743 macro_build ((char *) NULL, &icnt, &offset_expr,
4744 ((bfd_arch_bits_per_address (stdoutput) == 32
4745 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4747 "t,o(b)", PIC_CALL_REG,
4748 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
4749 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4751 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4752 RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel,
4754 offset_expr.X_add_symbol, (offsetT) 0,
4758 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4761 macro_build (p, &icnt, &offset_expr,
4762 ((bfd_arch_bits_per_address (stdoutput) == 32
4763 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4765 "t,o(b)", PIC_CALL_REG,
4766 (int) BFD_RELOC_MIPS_GOT16, GP);
4768 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4771 macro_build (p, &icnt, &offset_expr,
4772 ((bfd_arch_bits_per_address (stdoutput) == 32
4773 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4774 ? "addiu" : "daddiu"),
4775 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
4776 (int) BFD_RELOC_LO16);
4777 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4778 "jalr", "s", PIC_CALL_REG);
4779 if (mips_cprestore_offset < 0)
4780 as_warn (_("No .cprestore pseudo-op used in PIC code"));
4783 if (mips_opts.noreorder)
4784 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4786 expr1.X_add_number = mips_cprestore_offset;
4787 macro_build ((char *) NULL, &icnt, &expr1,
4788 ((bfd_arch_bits_per_address (stdoutput) == 32
4789 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4791 "t,o(b)", GP, (int) BFD_RELOC_LO16,
4795 else if (mips_pic == EMBEDDED_PIC)
4797 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
4798 /* The linker may expand the call to a longer sequence which
4799 uses $at, so we must break rather than return. */
4824 /* Itbl support may require additional care here. */
4829 /* Itbl support may require additional care here. */
4834 /* Itbl support may require additional care here. */
4839 /* Itbl support may require additional care here. */
4851 if (mips_arch == CPU_R4650)
4853 as_bad (_("opcode not supported on this processor"));
4857 /* Itbl support may require additional care here. */
4862 /* Itbl support may require additional care here. */
4867 /* Itbl support may require additional care here. */
4887 if (breg == treg || coproc || lr)
4909 /* Itbl support may require additional care here. */
4914 /* Itbl support may require additional care here. */
4919 /* Itbl support may require additional care here. */
4924 /* Itbl support may require additional care here. */
4940 if (mips_arch == CPU_R4650)
4942 as_bad (_("opcode not supported on this processor"));
4947 /* Itbl support may require additional care here. */
4951 /* Itbl support may require additional care here. */
4956 /* Itbl support may require additional care here. */
4968 /* Itbl support may require additional care here. */
4969 if (mask == M_LWC1_AB
4970 || mask == M_SWC1_AB
4971 || mask == M_LDC1_AB
4972 || mask == M_SDC1_AB
4981 if (offset_expr.X_op != O_constant
4982 && offset_expr.X_op != O_symbol)
4984 as_bad (_("expression too complex"));
4985 offset_expr.X_op = O_constant;
4988 /* A constant expression in PIC code can be handled just as it
4989 is in non PIC code. */
4990 if (mips_pic == NO_PIC
4991 || offset_expr.X_op == O_constant)
4993 /* If this is a reference to a GP relative symbol, and there
4994 is no base register, we want
4995 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
4996 Otherwise, if there is no base register, we want
4997 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4998 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
4999 If we have a constant, we need two instructions anyhow,
5000 so we always use the latter form.
5002 If we have a base register, and this is a reference to a
5003 GP relative symbol, we want
5004 addu $tempreg,$breg,$gp
5005 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
5007 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5008 addu $tempreg,$tempreg,$breg
5009 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5010 With a constant we always use the latter case. */
5013 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
5014 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5019 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5020 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
5021 p = frag_var (rs_machine_dependent, 8, 0,
5022 RELAX_ENCODE (4, 8, 0, 4, 0,
5023 (mips_opts.warn_about_macros
5025 && mips_opts.noat))),
5026 offset_expr.X_add_symbol, (offsetT) 0,
5030 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5033 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5034 (int) BFD_RELOC_LO16, tempreg);
5038 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
5039 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5044 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5045 ((bfd_arch_bits_per_address (stdoutput) == 32
5046 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5047 ? "addu" : "daddu"),
5048 "d,v,t", tempreg, breg, GP);
5049 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5050 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
5051 p = frag_var (rs_machine_dependent, 12, 0,
5052 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5053 offset_expr.X_add_symbol, (offsetT) 0,
5056 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5059 macro_build (p, &icnt, (expressionS *) NULL,
5060 ((bfd_arch_bits_per_address (stdoutput) == 32
5061 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5062 ? "addu" : "daddu"),
5063 "d,v,t", tempreg, tempreg, breg);
5066 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5067 (int) BFD_RELOC_LO16, tempreg);
5070 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5072 /* If this is a reference to an external symbol, we want
5073 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5075 <op> $treg,0($tempreg)
5077 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5079 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5080 <op> $treg,0($tempreg)
5081 If there is a base register, we add it to $tempreg before
5082 the <op>. If there is a constant, we stick it in the
5083 <op> instruction. We don't handle constants larger than
5084 16 bits, because we have no way to load the upper 16 bits
5085 (actually, we could handle them for the subset of cases
5086 in which we are not using $at). */
5087 assert (offset_expr.X_op == O_symbol);
5088 expr1.X_add_number = offset_expr.X_add_number;
5089 offset_expr.X_add_number = 0;
5090 if (expr1.X_add_number < -0x8000
5091 || expr1.X_add_number >= 0x8000)
5092 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5094 macro_build ((char *) NULL, &icnt, &offset_expr,
5095 ((bfd_arch_bits_per_address (stdoutput) == 32
5096 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5098 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5099 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5100 p = frag_var (rs_machine_dependent, 4, 0,
5101 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5102 offset_expr.X_add_symbol, (offsetT) 0,
5104 macro_build (p, &icnt, &offset_expr,
5105 ((bfd_arch_bits_per_address (stdoutput) == 32
5106 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5107 ? "addiu" : "daddiu"),
5108 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5110 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5111 ((bfd_arch_bits_per_address (stdoutput) == 32
5112 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5113 ? "addu" : "daddu"),
5114 "d,v,t", tempreg, tempreg, breg);
5115 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5116 (int) BFD_RELOC_LO16, tempreg);
5118 else if (mips_pic == SVR4_PIC)
5122 /* If this is a reference to an external symbol, we want
5123 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5124 addu $tempreg,$tempreg,$gp
5125 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5126 <op> $treg,0($tempreg)
5128 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5130 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5131 <op> $treg,0($tempreg)
5132 If there is a base register, we add it to $tempreg before
5133 the <op>. If there is a constant, we stick it in the
5134 <op> instruction. We don't handle constants larger than
5135 16 bits, because we have no way to load the upper 16 bits
5136 (actually, we could handle them for the subset of cases
5137 in which we are not using $at). */
5138 assert (offset_expr.X_op == O_symbol);
5139 expr1.X_add_number = offset_expr.X_add_number;
5140 offset_expr.X_add_number = 0;
5141 if (expr1.X_add_number < -0x8000
5142 || expr1.X_add_number >= 0x8000)
5143 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5144 if (reg_needs_delay (GP))
5149 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5150 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5151 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5152 ((bfd_arch_bits_per_address (stdoutput) == 32
5153 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5154 ? "addu" : "daddu"),
5155 "d,v,t", tempreg, tempreg, GP);
5156 macro_build ((char *) NULL, &icnt, &offset_expr,
5157 ((bfd_arch_bits_per_address (stdoutput) == 32
5158 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5160 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5162 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5163 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5164 offset_expr.X_add_symbol, (offsetT) 0, (char *) NULL);
5167 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5170 macro_build (p, &icnt, &offset_expr,
5171 ((bfd_arch_bits_per_address (stdoutput) == 32
5172 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5174 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5176 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5178 macro_build (p, &icnt, &offset_expr,
5179 ((bfd_arch_bits_per_address (stdoutput) == 32
5180 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5181 ? "addiu" : "daddiu"),
5182 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5184 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5185 ((bfd_arch_bits_per_address (stdoutput) == 32
5186 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5187 ? "addu" : "daddu"),
5188 "d,v,t", tempreg, tempreg, breg);
5189 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5190 (int) BFD_RELOC_LO16, tempreg);
5192 else if (mips_pic == EMBEDDED_PIC)
5194 /* If there is no base register, we want
5195 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
5196 If there is a base register, we want
5197 addu $tempreg,$breg,$gp
5198 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
5200 assert (offset_expr.X_op == O_symbol);
5203 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5204 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
5209 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5210 ((bfd_arch_bits_per_address (stdoutput) == 32
5211 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5212 ? "addu" : "daddu"),
5213 "d,v,t", tempreg, breg, GP);
5214 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5215 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
5228 load_register (&icnt, treg, &imm_expr, 0);
5232 load_register (&icnt, treg, &imm_expr, 1);
5236 if (imm_expr.X_op == O_constant)
5238 load_register (&icnt, AT, &imm_expr, 0);
5239 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5240 "mtc1", "t,G", AT, treg);
5245 assert (offset_expr.X_op == O_symbol
5246 && strcmp (segment_name (S_GET_SEGMENT
5247 (offset_expr.X_add_symbol)),
5249 && offset_expr.X_add_number == 0);
5250 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5251 treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5256 /* If we have a constant in IMM_EXPR, then in mips3 mode it is
5257 the entire value, and in mips1 mode it is the high order 32
5258 bits of the value and the low order 32 bits are either zero
5259 or in offset_expr. */
5260 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5262 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5263 load_register (&icnt, treg, &imm_expr, 1);
5268 if (target_big_endian)
5280 load_register (&icnt, hreg, &imm_expr, 0);
5283 if (offset_expr.X_op == O_absent)
5284 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s",
5288 assert (offset_expr.X_op == O_constant);
5289 load_register (&icnt, lreg, &offset_expr, 0);
5296 /* We know that sym is in the .rdata section. First we get the
5297 upper 16 bits of the address. */
5298 if (mips_pic == NO_PIC)
5300 /* FIXME: This won't work for a 64 bit address. */
5301 macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
5303 else if (mips_pic == SVR4_PIC)
5305 macro_build ((char *) NULL, &icnt, &offset_expr,
5306 ((bfd_arch_bits_per_address (stdoutput) == 32
5307 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5309 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5311 else if (mips_pic == EMBEDDED_PIC)
5313 /* For embedded PIC we pick up the entire address off $gp in
5314 a single instruction. */
5315 macro_build ((char *) NULL, &icnt, &offset_expr,
5316 ((bfd_arch_bits_per_address (stdoutput) == 32
5317 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5318 ? "addiu" : "daddiu"),
5319 "t,r,j", AT, GP, (int) BFD_RELOC_MIPS_GPREL);
5320 offset_expr.X_op = O_constant;
5321 offset_expr.X_add_number = 0;
5326 /* Now we load the register(s). */
5327 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5328 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5329 treg, (int) BFD_RELOC_LO16, AT);
5332 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5333 treg, (int) BFD_RELOC_LO16, AT);
5336 /* FIXME: How in the world do we deal with the possible
5338 offset_expr.X_add_number += 4;
5339 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5340 treg + 1, (int) BFD_RELOC_LO16, AT);
5344 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5345 does not become a variant frag. */
5346 frag_wane (frag_now);
5352 /* If we have a constant in IMM_EXPR, then in mips3 mode it is
5353 the entire value, and in mips1 mode it is the high order 32
5354 bits of the value and the low order 32 bits are either zero
5355 or in offset_expr. */
5356 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5358 load_register (&icnt, AT, &imm_expr, ISA_HAS_64BIT_REGS (mips_opts.isa));
5359 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5360 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5361 "dmtc1", "t,S", AT, treg);
5364 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5365 "mtc1", "t,G", AT, treg + 1);
5366 if (offset_expr.X_op == O_absent)
5367 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5368 "mtc1", "t,G", 0, treg);
5371 assert (offset_expr.X_op == O_constant);
5372 load_register (&icnt, AT, &offset_expr, 0);
5373 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5374 "mtc1", "t,G", AT, treg);
5380 assert (offset_expr.X_op == O_symbol
5381 && offset_expr.X_add_number == 0);
5382 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5383 if (strcmp (s, ".lit8") == 0)
5385 if (mips_opts.isa != ISA_MIPS1)
5387 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5388 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5392 r = BFD_RELOC_MIPS_LITERAL;
5397 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5398 if (mips_pic == SVR4_PIC)
5399 macro_build ((char *) NULL, &icnt, &offset_expr,
5400 ((bfd_arch_bits_per_address (stdoutput) == 32
5401 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5403 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5406 /* FIXME: This won't work for a 64 bit address. */
5407 macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
5410 if (mips_opts.isa != ISA_MIPS1)
5412 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5413 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
5415 /* To avoid confusion in tc_gen_reloc, we must ensure
5416 that this does not become a variant frag. */
5417 frag_wane (frag_now);
5428 if (mips_arch == CPU_R4650)
5430 as_bad (_("opcode not supported on this processor"));
5433 /* Even on a big endian machine $fn comes before $fn+1. We have
5434 to adjust when loading from memory. */
5437 assert (mips_opts.isa == ISA_MIPS1);
5438 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5439 target_big_endian ? treg + 1 : treg,
5441 /* FIXME: A possible overflow which I don't know how to deal
5443 offset_expr.X_add_number += 4;
5444 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5445 target_big_endian ? treg : treg + 1,
5448 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5449 does not become a variant frag. */
5450 frag_wane (frag_now);
5459 * The MIPS assembler seems to check for X_add_number not
5460 * being double aligned and generating:
5463 * addiu at,at,%lo(foo+1)
5466 * But, the resulting address is the same after relocation so why
5467 * generate the extra instruction?
5469 if (mips_arch == CPU_R4650)
5471 as_bad (_("opcode not supported on this processor"));
5474 /* Itbl support may require additional care here. */
5476 if (mips_opts.isa != ISA_MIPS1)
5487 if (mips_arch == CPU_R4650)
5489 as_bad (_("opcode not supported on this processor"));
5493 if (mips_opts.isa != ISA_MIPS1)
5501 /* Itbl support may require additional care here. */
5506 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5517 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5527 if (offset_expr.X_op != O_symbol
5528 && offset_expr.X_op != O_constant)
5530 as_bad (_("expression too complex"));
5531 offset_expr.X_op = O_constant;
5534 /* Even on a big endian machine $fn comes before $fn+1. We have
5535 to adjust when loading from memory. We set coproc if we must
5536 load $fn+1 first. */
5537 /* Itbl support may require additional care here. */
5538 if (! target_big_endian)
5541 if (mips_pic == NO_PIC
5542 || offset_expr.X_op == O_constant)
5544 /* If this is a reference to a GP relative symbol, we want
5545 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
5546 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
5547 If we have a base register, we use this
5549 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
5550 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
5551 If this is not a GP relative symbol, we want
5552 lui $at,<sym> (BFD_RELOC_HI16_S)
5553 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5554 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5555 If there is a base register, we add it to $at after the
5556 lui instruction. If there is a constant, we always use
5558 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
5559 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5578 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5579 ((bfd_arch_bits_per_address (stdoutput) == 32
5580 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5581 ? "addu" : "daddu"),
5582 "d,v,t", AT, breg, GP);
5588 /* Itbl support may require additional care here. */
5589 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5590 coproc ? treg + 1 : treg,
5591 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5592 offset_expr.X_add_number += 4;
5594 /* Set mips_optimize to 2 to avoid inserting an
5596 hold_mips_optimize = mips_optimize;
5598 /* Itbl support may require additional care here. */
5599 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5600 coproc ? treg : treg + 1,
5601 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5602 mips_optimize = hold_mips_optimize;
5604 p = frag_var (rs_machine_dependent, 12 + off, 0,
5605 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
5606 used_at && mips_opts.noat),
5607 offset_expr.X_add_symbol, (offsetT) 0,
5610 /* We just generated two relocs. When tc_gen_reloc
5611 handles this case, it will skip the first reloc and
5612 handle the second. The second reloc already has an
5613 extra addend of 4, which we added above. We must
5614 subtract it out, and then subtract another 4 to make
5615 the first reloc come out right. The second reloc
5616 will come out right because we are going to add 4 to
5617 offset_expr when we build its instruction below.
5619 If we have a symbol, then we don't want to include
5620 the offset, because it will wind up being included
5621 when we generate the reloc. */
5623 if (offset_expr.X_op == O_constant)
5624 offset_expr.X_add_number -= 8;
5627 offset_expr.X_add_number = -4;
5628 offset_expr.X_op = O_constant;
5631 macro_build_lui (p, &icnt, &offset_expr, AT);
5636 macro_build (p, &icnt, (expressionS *) NULL,
5637 ((bfd_arch_bits_per_address (stdoutput) == 32
5638 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5639 ? "addu" : "daddu"),
5640 "d,v,t", AT, breg, AT);
5644 /* Itbl support may require additional care here. */
5645 macro_build (p, &icnt, &offset_expr, s, fmt,
5646 coproc ? treg + 1 : treg,
5647 (int) BFD_RELOC_LO16, AT);
5650 /* FIXME: How do we handle overflow here? */
5651 offset_expr.X_add_number += 4;
5652 /* Itbl support may require additional care here. */
5653 macro_build (p, &icnt, &offset_expr, s, fmt,
5654 coproc ? treg : treg + 1,
5655 (int) BFD_RELOC_LO16, AT);
5657 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5661 /* If this is a reference to an external symbol, we want
5662 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5667 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5669 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5670 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5671 If there is a base register we add it to $at before the
5672 lwc1 instructions. If there is a constant we include it
5673 in the lwc1 instructions. */
5675 expr1.X_add_number = offset_expr.X_add_number;
5676 offset_expr.X_add_number = 0;
5677 if (expr1.X_add_number < -0x8000
5678 || expr1.X_add_number >= 0x8000 - 4)
5679 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5684 frag_grow (24 + off);
5685 macro_build ((char *) NULL, &icnt, &offset_expr,
5686 ((bfd_arch_bits_per_address (stdoutput) == 32
5687 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5689 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5690 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5692 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5693 ((bfd_arch_bits_per_address (stdoutput) == 32
5694 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5695 ? "addu" : "daddu"),
5696 "d,v,t", AT, breg, AT);
5697 /* Itbl support may require additional care here. */
5698 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5699 coproc ? treg + 1 : treg,
5700 (int) BFD_RELOC_LO16, AT);
5701 expr1.X_add_number += 4;
5703 /* Set mips_optimize to 2 to avoid inserting an undesired
5705 hold_mips_optimize = mips_optimize;
5707 /* Itbl support may require additional care here. */
5708 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5709 coproc ? treg : treg + 1,
5710 (int) BFD_RELOC_LO16, AT);
5711 mips_optimize = hold_mips_optimize;
5713 (void) frag_var (rs_machine_dependent, 0, 0,
5714 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
5715 offset_expr.X_add_symbol, (offsetT) 0,
5718 else if (mips_pic == SVR4_PIC)
5722 /* If this is a reference to an external symbol, we want
5723 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5725 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
5730 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5732 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5733 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5734 If there is a base register we add it to $at before the
5735 lwc1 instructions. If there is a constant we include it
5736 in the lwc1 instructions. */
5738 expr1.X_add_number = offset_expr.X_add_number;
5739 offset_expr.X_add_number = 0;
5740 if (expr1.X_add_number < -0x8000
5741 || expr1.X_add_number >= 0x8000 - 4)
5742 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5743 if (reg_needs_delay (GP))
5752 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5753 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
5754 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5755 ((bfd_arch_bits_per_address (stdoutput) == 32
5756 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5757 ? "addu" : "daddu"),
5758 "d,v,t", AT, AT, GP);
5759 macro_build ((char *) NULL, &icnt, &offset_expr,
5760 ((bfd_arch_bits_per_address (stdoutput) == 32
5761 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5763 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
5764 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5766 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5767 ((bfd_arch_bits_per_address (stdoutput) == 32
5768 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5769 ? "addu" : "daddu"),
5770 "d,v,t", AT, breg, AT);
5771 /* Itbl support may require additional care here. */
5772 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5773 coproc ? treg + 1 : treg,
5774 (int) BFD_RELOC_LO16, AT);
5775 expr1.X_add_number += 4;
5777 /* Set mips_optimize to 2 to avoid inserting an undesired
5779 hold_mips_optimize = mips_optimize;
5781 /* Itbl support may require additional care here. */
5782 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5783 coproc ? treg : treg + 1,
5784 (int) BFD_RELOC_LO16, AT);
5785 mips_optimize = hold_mips_optimize;
5786 expr1.X_add_number -= 4;
5788 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
5789 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
5790 8 + gpdel + off, 1, 0),
5791 offset_expr.X_add_symbol, (offsetT) 0,
5795 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5798 macro_build (p, &icnt, &offset_expr,
5799 ((bfd_arch_bits_per_address (stdoutput) == 32
5800 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5802 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5804 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5808 macro_build (p, &icnt, (expressionS *) NULL,
5809 ((bfd_arch_bits_per_address (stdoutput) == 32
5810 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5811 ? "addu" : "daddu"),
5812 "d,v,t", AT, breg, AT);
5815 /* Itbl support may require additional care here. */
5816 macro_build (p, &icnt, &expr1, s, fmt,
5817 coproc ? treg + 1 : treg,
5818 (int) BFD_RELOC_LO16, AT);
5820 expr1.X_add_number += 4;
5822 /* Set mips_optimize to 2 to avoid inserting an undesired
5824 hold_mips_optimize = mips_optimize;
5826 /* Itbl support may require additional care here. */
5827 macro_build (p, &icnt, &expr1, s, fmt,
5828 coproc ? treg : treg + 1,
5829 (int) BFD_RELOC_LO16, AT);
5830 mips_optimize = hold_mips_optimize;
5832 else if (mips_pic == EMBEDDED_PIC)
5834 /* If there is no base register, we use
5835 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
5836 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
5837 If we have a base register, we use
5839 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
5840 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
5849 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5850 ((bfd_arch_bits_per_address (stdoutput) == 32
5851 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5852 ? "addu" : "daddu"),
5853 "d,v,t", AT, breg, GP);
5858 /* Itbl support may require additional care here. */
5859 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5860 coproc ? treg + 1 : treg,
5861 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5862 offset_expr.X_add_number += 4;
5863 /* Itbl support may require additional care here. */
5864 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5865 coproc ? treg : treg + 1,
5866 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5882 assert (bfd_arch_bits_per_address (stdoutput) == 32
5883 || ! ISA_HAS_64BIT_REGS (mips_opts.isa));
5884 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
5885 (int) BFD_RELOC_LO16, breg);
5886 offset_expr.X_add_number += 4;
5887 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
5888 (int) BFD_RELOC_LO16, breg);
5891 /* New code added to support COPZ instructions.
5892 This code builds table entries out of the macros in mip_opcodes.
5893 R4000 uses interlocks to handle coproc delays.
5894 Other chips (like the R3000) require nops to be inserted for delays.
5896 FIXME: Currently, we require that the user handle delays.
5897 In order to fill delay slots for non-interlocked chips,
5898 we must have a way to specify delays based on the coprocessor.
5899 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
5900 What are the side-effects of the cop instruction?
5901 What cache support might we have and what are its effects?
5902 Both coprocessor & memory require delays. how long???
5903 What registers are read/set/modified?
5905 If an itbl is provided to interpret cop instructions,
5906 this knowledge can be encoded in the itbl spec. */
5920 /* For now we just do C (same as Cz). The parameter will be
5921 stored in insn_opcode by mips_ip. */
5922 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
5926 #ifdef LOSING_COMPILER
5928 /* Try and see if this is a new itbl instruction.
5929 This code builds table entries out of the macros in mip_opcodes.
5930 FIXME: For now we just assemble the expression and pass it's
5931 value along as a 32-bit immediate.
5932 We may want to have the assembler assemble this value,
5933 so that we gain the assembler's knowledge of delay slots,
5935 Would it be more efficient to use mask (id) here? */
5936 if (itbl_have_entries
5937 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
5939 s = ip->insn_mo->name;
5941 coproc = ITBL_DECODE_PNUM (immed_expr);;
5942 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
5949 as_warn (_("Macro used $at after \".set noat\""));
5954 struct mips_cl_insn *ip;
5956 register int treg, sreg, dreg, breg;
5972 bfd_reloc_code_real_type r;
5975 treg = (ip->insn_opcode >> 16) & 0x1f;
5976 dreg = (ip->insn_opcode >> 11) & 0x1f;
5977 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
5978 mask = ip->insn_mo->mask;
5980 expr1.X_op = O_constant;
5981 expr1.X_op_symbol = NULL;
5982 expr1.X_add_symbol = NULL;
5983 expr1.X_add_number = 1;
5987 #endif /* LOSING_COMPILER */
5992 macro_build ((char *) NULL, &icnt, NULL,
5993 dbl ? "dmultu" : "multu",
5995 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6001 /* The MIPS assembler some times generates shifts and adds. I'm
6002 not trying to be that fancy. GCC should do this for us
6004 load_register (&icnt, AT, &imm_expr, dbl);
6005 macro_build ((char *) NULL, &icnt, NULL,
6006 dbl ? "dmult" : "mult",
6008 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6021 mips_emit_delays (true);
6022 ++mips_opts.noreorder;
6023 mips_any_noreorder = 1;
6025 load_register (&icnt, AT, &imm_expr, dbl);
6026 macro_build ((char *) NULL, &icnt, NULL,
6027 dbl ? "dmult" : "mult",
6028 "s,t", sreg, imm ? AT : treg);
6029 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6030 macro_build ((char *) NULL, &icnt, NULL,
6031 dbl ? "dsra32" : "sra",
6032 "d,w,<", dreg, dreg, 31);
6033 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
6035 macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", dreg, AT);
6038 expr1.X_add_number = 8;
6039 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
6040 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
6041 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
6043 --mips_opts.noreorder;
6044 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6057 mips_emit_delays (true);
6058 ++mips_opts.noreorder;
6059 mips_any_noreorder = 1;
6061 load_register (&icnt, AT, &imm_expr, dbl);
6062 macro_build ((char *) NULL, &icnt, NULL,
6063 dbl ? "dmultu" : "multu",
6064 "s,t", sreg, imm ? AT : treg);
6065 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
6066 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6068 macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", AT, 0);
6071 expr1.X_add_number = 8;
6072 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6073 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
6074 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
6076 --mips_opts.noreorder;
6080 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
6081 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT);
6082 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg,
6084 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
6088 if (imm_expr.X_op != O_constant)
6089 as_bad (_("rotate count too large"));
6090 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg,
6091 (int) (imm_expr.X_add_number & 0x1f));
6092 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg,
6093 (int) ((0 - imm_expr.X_add_number) & 0x1f));
6094 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
6098 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
6099 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT);
6100 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg,
6102 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
6106 if (imm_expr.X_op != O_constant)
6107 as_bad (_("rotate count too large"));
6108 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg,
6109 (int) (imm_expr.X_add_number & 0x1f));
6110 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg,
6111 (int) ((0 - imm_expr.X_add_number) & 0x1f));
6112 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
6116 if (mips_arch == CPU_R4650)
6118 as_bad (_("opcode not supported on this processor"));
6121 assert (mips_opts.isa == ISA_MIPS1);
6122 /* Even on a big endian machine $fn comes before $fn+1. We have
6123 to adjust when storing to memory. */
6124 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6125 target_big_endian ? treg + 1 : treg,
6126 (int) BFD_RELOC_LO16, breg);
6127 offset_expr.X_add_number += 4;
6128 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6129 target_big_endian ? treg : treg + 1,
6130 (int) BFD_RELOC_LO16, breg);
6135 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6136 treg, (int) BFD_RELOC_LO16);
6138 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6139 sreg, (int) BFD_RELOC_LO16);
6142 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
6144 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6145 dreg, (int) BFD_RELOC_LO16);
6150 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6152 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6153 sreg, (int) BFD_RELOC_LO16);
6158 as_warn (_("Instruction %s: result is always false"),
6160 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
6163 if (imm_expr.X_op == O_constant
6164 && imm_expr.X_add_number >= 0
6165 && imm_expr.X_add_number < 0x10000)
6167 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6168 sreg, (int) BFD_RELOC_LO16);
6171 else if (imm_expr.X_op == O_constant
6172 && imm_expr.X_add_number > -0x8000
6173 && imm_expr.X_add_number < 0)
6175 imm_expr.X_add_number = -imm_expr.X_add_number;
6176 macro_build ((char *) NULL, &icnt, &imm_expr,
6177 ((bfd_arch_bits_per_address (stdoutput) == 32
6178 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6179 ? "addiu" : "daddiu"),
6180 "t,r,j", dreg, sreg,
6181 (int) BFD_RELOC_LO16);
6186 load_register (&icnt, AT, &imm_expr, 0);
6187 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
6191 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6192 (int) BFD_RELOC_LO16);
6197 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6203 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg);
6204 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6205 (int) BFD_RELOC_LO16);
6208 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6210 if (imm_expr.X_op == O_constant
6211 && imm_expr.X_add_number >= -0x8000
6212 && imm_expr.X_add_number < 0x8000)
6214 macro_build ((char *) NULL, &icnt, &imm_expr,
6215 mask == M_SGE_I ? "slti" : "sltiu",
6216 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6221 load_register (&icnt, AT, &imm_expr, 0);
6222 macro_build ((char *) NULL, &icnt, NULL,
6223 mask == M_SGE_I ? "slt" : "sltu",
6224 "d,v,t", dreg, sreg, AT);
6227 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6228 (int) BFD_RELOC_LO16);
6233 case M_SGT: /* sreg > treg <==> treg < sreg */
6239 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
6242 case M_SGT_I: /* sreg > I <==> I < sreg */
6248 load_register (&icnt, AT, &imm_expr, 0);
6249 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
6252 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6258 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
6259 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6260 (int) BFD_RELOC_LO16);
6263 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6269 load_register (&icnt, AT, &imm_expr, 0);
6270 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
6271 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6272 (int) BFD_RELOC_LO16);
6276 if (imm_expr.X_op == O_constant
6277 && imm_expr.X_add_number >= -0x8000
6278 && imm_expr.X_add_number < 0x8000)
6280 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
6281 dreg, sreg, (int) BFD_RELOC_LO16);
6284 load_register (&icnt, AT, &imm_expr, 0);
6285 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT);
6289 if (imm_expr.X_op == O_constant
6290 && imm_expr.X_add_number >= -0x8000
6291 && imm_expr.X_add_number < 0x8000)
6293 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
6294 dreg, sreg, (int) BFD_RELOC_LO16);
6297 load_register (&icnt, AT, &imm_expr, 0);
6298 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg,
6304 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
6307 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
6311 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
6313 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
6319 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6321 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
6327 as_warn (_("Instruction %s: result is always true"),
6329 macro_build ((char *) NULL, &icnt, &expr1,
6330 ((bfd_arch_bits_per_address (stdoutput) == 32
6331 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6332 ? "addiu" : "daddiu"),
6333 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
6336 if (imm_expr.X_op == O_constant
6337 && imm_expr.X_add_number >= 0
6338 && imm_expr.X_add_number < 0x10000)
6340 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
6341 dreg, sreg, (int) BFD_RELOC_LO16);
6344 else if (imm_expr.X_op == O_constant
6345 && imm_expr.X_add_number > -0x8000
6346 && imm_expr.X_add_number < 0)
6348 imm_expr.X_add_number = -imm_expr.X_add_number;
6349 macro_build ((char *) NULL, &icnt, &imm_expr,
6350 ((bfd_arch_bits_per_address (stdoutput) == 32
6351 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6352 ? "addiu" : "daddiu"),
6353 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6358 load_register (&icnt, AT, &imm_expr, 0);
6359 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
6363 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
6371 if (imm_expr.X_op == O_constant
6372 && imm_expr.X_add_number > -0x8000
6373 && imm_expr.X_add_number <= 0x8000)
6375 imm_expr.X_add_number = -imm_expr.X_add_number;
6376 macro_build ((char *) NULL, &icnt, &imm_expr,
6377 dbl ? "daddi" : "addi",
6378 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6381 load_register (&icnt, AT, &imm_expr, dbl);
6382 macro_build ((char *) NULL, &icnt, NULL,
6383 dbl ? "dsub" : "sub",
6384 "d,v,t", dreg, sreg, AT);
6390 if (imm_expr.X_op == O_constant
6391 && imm_expr.X_add_number > -0x8000
6392 && imm_expr.X_add_number <= 0x8000)
6394 imm_expr.X_add_number = -imm_expr.X_add_number;
6395 macro_build ((char *) NULL, &icnt, &imm_expr,
6396 dbl ? "daddiu" : "addiu",
6397 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6400 load_register (&icnt, AT, &imm_expr, dbl);
6401 macro_build ((char *) NULL, &icnt, NULL,
6402 dbl ? "dsubu" : "subu",
6403 "d,v,t", dreg, sreg, AT);
6424 load_register (&icnt, AT, &imm_expr, 0);
6425 macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT);
6430 assert (mips_opts.isa == ISA_MIPS1);
6431 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
6432 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
6435 * Is the double cfc1 instruction a bug in the mips assembler;
6436 * or is there a reason for it?
6438 mips_emit_delays (true);
6439 ++mips_opts.noreorder;
6440 mips_any_noreorder = 1;
6441 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
6442 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
6443 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6444 expr1.X_add_number = 3;
6445 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
6446 (int) BFD_RELOC_LO16);
6447 expr1.X_add_number = 2;
6448 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
6449 (int) BFD_RELOC_LO16);
6450 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31);
6451 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6452 macro_build ((char *) NULL, &icnt, NULL,
6453 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
6454 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31);
6455 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6456 --mips_opts.noreorder;
6465 if (offset_expr.X_add_number >= 0x7fff)
6466 as_bad (_("operand overflow"));
6467 /* avoid load delay */
6468 if (! target_big_endian)
6469 offset_expr.X_add_number += 1;
6470 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6471 (int) BFD_RELOC_LO16, breg);
6472 if (! target_big_endian)
6473 offset_expr.X_add_number -= 1;
6475 offset_expr.X_add_number += 1;
6476 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
6477 (int) BFD_RELOC_LO16, breg);
6478 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
6479 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
6492 if (offset_expr.X_add_number >= 0x8000 - off)
6493 as_bad (_("operand overflow"));
6494 if (! target_big_endian)
6495 offset_expr.X_add_number += off;
6496 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6497 (int) BFD_RELOC_LO16, breg);
6498 if (! target_big_endian)
6499 offset_expr.X_add_number -= off;
6501 offset_expr.X_add_number += off;
6502 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
6503 (int) BFD_RELOC_LO16, breg);
6516 load_address (&icnt, AT, &offset_expr);
6518 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6519 ((bfd_arch_bits_per_address (stdoutput) == 32
6520 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6521 ? "addu" : "daddu"),
6522 "d,v,t", AT, AT, breg);
6523 if (! target_big_endian)
6524 expr1.X_add_number = off;
6526 expr1.X_add_number = 0;
6527 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
6528 (int) BFD_RELOC_LO16, AT);
6529 if (! target_big_endian)
6530 expr1.X_add_number = 0;
6532 expr1.X_add_number = off;
6533 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
6534 (int) BFD_RELOC_LO16, AT);
6539 load_address (&icnt, AT, &offset_expr);
6541 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6542 ((bfd_arch_bits_per_address (stdoutput) == 32
6543 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6544 ? "addu" : "daddu"),
6545 "d,v,t", AT, AT, breg);
6546 if (target_big_endian)
6547 expr1.X_add_number = 0;
6548 macro_build ((char *) NULL, &icnt, &expr1,
6549 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
6550 (int) BFD_RELOC_LO16, AT);
6551 if (target_big_endian)
6552 expr1.X_add_number = 1;
6554 expr1.X_add_number = 0;
6555 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
6556 (int) BFD_RELOC_LO16, AT);
6557 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
6559 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
6564 if (offset_expr.X_add_number >= 0x7fff)
6565 as_bad (_("operand overflow"));
6566 if (target_big_endian)
6567 offset_expr.X_add_number += 1;
6568 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
6569 (int) BFD_RELOC_LO16, breg);
6570 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8);
6571 if (target_big_endian)
6572 offset_expr.X_add_number -= 1;
6574 offset_expr.X_add_number += 1;
6575 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
6576 (int) BFD_RELOC_LO16, breg);
6589 if (offset_expr.X_add_number >= 0x8000 - off)
6590 as_bad (_("operand overflow"));
6591 if (! target_big_endian)
6592 offset_expr.X_add_number += off;
6593 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6594 (int) BFD_RELOC_LO16, breg);
6595 if (! target_big_endian)
6596 offset_expr.X_add_number -= off;
6598 offset_expr.X_add_number += off;
6599 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
6600 (int) BFD_RELOC_LO16, breg);
6613 load_address (&icnt, AT, &offset_expr);
6615 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6616 ((bfd_arch_bits_per_address (stdoutput) == 32
6617 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6618 ? "addu" : "daddu"),
6619 "d,v,t", AT, AT, breg);
6620 if (! target_big_endian)
6621 expr1.X_add_number = off;
6623 expr1.X_add_number = 0;
6624 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
6625 (int) BFD_RELOC_LO16, AT);
6626 if (! target_big_endian)
6627 expr1.X_add_number = 0;
6629 expr1.X_add_number = off;
6630 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
6631 (int) BFD_RELOC_LO16, AT);
6635 load_address (&icnt, AT, &offset_expr);
6637 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6638 ((bfd_arch_bits_per_address (stdoutput) == 32
6639 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6640 ? "addu" : "daddu"),
6641 "d,v,t", AT, AT, breg);
6642 if (! target_big_endian)
6643 expr1.X_add_number = 0;
6644 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
6645 (int) BFD_RELOC_LO16, AT);
6646 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg,
6648 if (! target_big_endian)
6649 expr1.X_add_number = 1;
6651 expr1.X_add_number = 0;
6652 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
6653 (int) BFD_RELOC_LO16, AT);
6654 if (! target_big_endian)
6655 expr1.X_add_number = 0;
6657 expr1.X_add_number = 1;
6658 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
6659 (int) BFD_RELOC_LO16, AT);
6660 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
6662 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
6667 /* FIXME: Check if this is one of the itbl macros, since they
6668 are added dynamically. */
6669 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
6673 as_warn (_("Macro used $at after \".set noat\""));
6676 /* Implement macros in mips16 mode. */
6680 struct mips_cl_insn *ip;
6683 int xreg, yreg, zreg, tmp;
6687 const char *s, *s2, *s3;
6689 mask = ip->insn_mo->mask;
6691 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
6692 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
6693 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
6697 expr1.X_op = O_constant;
6698 expr1.X_op_symbol = NULL;
6699 expr1.X_add_symbol = NULL;
6700 expr1.X_add_number = 1;
6719 mips_emit_delays (true);
6720 ++mips_opts.noreorder;
6721 mips_any_noreorder = 1;
6722 macro_build ((char *) NULL, &icnt, NULL,
6723 dbl ? "ddiv" : "div",
6724 "0,x,y", xreg, yreg);
6725 expr1.X_add_number = 2;
6726 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
6727 macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7);
6729 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
6730 since that causes an overflow. We should do that as well,
6731 but I don't see how to do the comparisons without a temporary
6733 --mips_opts.noreorder;
6734 macro_build ((char *) NULL, &icnt, NULL, s, "x", zreg);
6753 mips_emit_delays (true);
6754 ++mips_opts.noreorder;
6755 mips_any_noreorder = 1;
6756 macro_build ((char *) NULL, &icnt, NULL, s, "0,x,y", xreg, yreg);
6757 expr1.X_add_number = 2;
6758 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
6759 macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7);
6760 --mips_opts.noreorder;
6761 macro_build ((char *) NULL, &icnt, NULL, s2, "x", zreg);
6767 macro_build ((char *) NULL, &icnt, NULL,
6768 dbl ? "dmultu" : "multu",
6770 macro_build ((char *) NULL, &icnt, NULL, "mflo", "x", zreg);
6778 if (imm_expr.X_op != O_constant)
6779 as_bad (_("Unsupported large constant"));
6780 imm_expr.X_add_number = -imm_expr.X_add_number;
6781 macro_build ((char *) NULL, &icnt, &imm_expr,
6782 dbl ? "daddiu" : "addiu",
6783 "y,x,4", yreg, xreg);
6787 if (imm_expr.X_op != O_constant)
6788 as_bad (_("Unsupported large constant"));
6789 imm_expr.X_add_number = -imm_expr.X_add_number;
6790 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
6795 if (imm_expr.X_op != O_constant)
6796 as_bad (_("Unsupported large constant"));
6797 imm_expr.X_add_number = -imm_expr.X_add_number;
6798 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
6821 goto do_reverse_branch;
6825 goto do_reverse_branch;
6837 goto do_reverse_branch;
6848 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
6850 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
6877 goto do_addone_branch_i;
6882 goto do_addone_branch_i;
6897 goto do_addone_branch_i;
6904 if (imm_expr.X_op != O_constant)
6905 as_bad (_("Unsupported large constant"));
6906 ++imm_expr.X_add_number;
6909 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
6910 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
6914 expr1.X_add_number = 0;
6915 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
6917 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6918 "move", "y,X", xreg, yreg);
6919 expr1.X_add_number = 2;
6920 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
6921 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6922 "neg", "x,w", xreg, xreg);
6926 /* For consistency checking, verify that all bits are specified either
6927 by the match/mask part of the instruction definition, or by the
6930 validate_mips_insn (opc)
6931 const struct mips_opcode *opc;
6933 const char *p = opc->args;
6935 unsigned long used_bits = opc->mask;
6937 if ((used_bits & opc->match) != opc->match)
6939 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
6940 opc->name, opc->args);
6943 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
6950 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
6951 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
6953 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
6954 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
6955 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
6956 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
6958 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
6959 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
6961 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
6963 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
6964 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
6965 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
6966 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
6967 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
6968 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
6969 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
6970 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
6971 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
6972 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
6973 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
6975 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
6976 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
6977 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
6978 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
6980 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
6981 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
6982 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
6983 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
6984 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
6985 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
6986 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
6987 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
6988 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
6991 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
6992 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
6993 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
6995 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
6996 c, opc->name, opc->args);
7000 if (used_bits != 0xffffffff)
7002 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7003 ~used_bits & 0xffffffff, opc->name, opc->args);
7009 /* This routine assembles an instruction into its binary format. As a
7010 side effect, it sets one of the global variables imm_reloc or
7011 offset_reloc to the type of relocation to do if one of the operands
7012 is an address expression. */
7017 struct mips_cl_insn *ip;
7022 struct mips_opcode *insn;
7025 unsigned int lastregno = 0;
7028 int full_opcode_match = 1;
7032 /* If the instruction contains a '.', we first try to match an instruction
7033 including the '.'. Then we try again without the '.'. */
7035 for (s = str; *s != '\0' && !isspace ((unsigned char) *s); ++s)
7038 /* If we stopped on whitespace, then replace the whitespace with null for
7039 the call to hash_find. Save the character we replaced just in case we
7040 have to re-parse the instruction. */
7041 if (isspace ((unsigned char) *s))
7047 insn = (struct mips_opcode *) hash_find (op_hash, str);
7049 /* If we didn't find the instruction in the opcode table, try again, but
7050 this time with just the instruction up to, but not including the
7054 /* Restore the character we overwrite above (if any). */
7058 /* Scan up to the first '.' or whitespace. */
7059 for (s = str; *s != '\0' && *s != '.' && !isspace ((unsigned char) *s); ++s)
7062 /* If we did not find a '.', then we can quit now. */
7065 insn_error = "unrecognized opcode";
7069 /* Lookup the instruction in the hash table. */
7071 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7073 insn_error = "unrecognized opcode";
7077 full_opcode_match = 0;
7085 assert (strcmp (insn->name, str) == 0);
7087 if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_arch, mips_gp32))
7092 if (insn->pinfo != INSN_MACRO)
7094 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7100 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7101 && strcmp (insn->name, insn[1].name) == 0)
7110 static char buf[100];
7112 _("opcode not supported on this processor: %s (%s)"),
7113 mips_cpu_to_str (mips_arch),
7114 mips_isa_to_str (mips_opts.isa));
7125 ip->insn_opcode = insn->match;
7127 for (args = insn->args;; ++args)
7133 case '\0': /* end of args */
7146 ip->insn_opcode |= lastregno << 21;
7151 ip->insn_opcode |= lastregno << 16;
7155 ip->insn_opcode |= lastregno << 11;
7161 /* Handle optional base register.
7162 Either the base register is omitted or
7163 we must have a left paren. */
7164 /* This is dependent on the next operand specifier
7165 is a base register specification. */
7166 assert (args[1] == 'b' || args[1] == '5'
7167 || args[1] == '-' || args[1] == '4');
7171 case ')': /* these must match exactly */
7176 case '<': /* must be at least one digit */
7178 * According to the manual, if the shift amount is greater
7179 * than 31 or less than 0 the the shift amount should be
7180 * mod 32. In reality the mips assembler issues an error.
7181 * We issue a warning and mask out all but the low 5 bits.
7183 my_getExpression (&imm_expr, s);
7184 check_absolute_expr (ip, &imm_expr);
7185 if ((unsigned long) imm_expr.X_add_number > 31)
7187 as_warn (_("Improper shift amount (%ld)"),
7188 (long) imm_expr.X_add_number);
7189 imm_expr.X_add_number = imm_expr.X_add_number & 0x1f;
7191 ip->insn_opcode |= imm_expr.X_add_number << 6;
7192 imm_expr.X_op = O_absent;
7196 case '>': /* shift amount minus 32 */
7197 my_getExpression (&imm_expr, s);
7198 check_absolute_expr (ip, &imm_expr);
7199 if ((unsigned long) imm_expr.X_add_number < 32
7200 || (unsigned long) imm_expr.X_add_number > 63)
7202 ip->insn_opcode |= (imm_expr.X_add_number - 32) << 6;
7203 imm_expr.X_op = O_absent;
7207 case 'k': /* cache code */
7208 case 'h': /* prefx code */
7209 my_getExpression (&imm_expr, s);
7210 check_absolute_expr (ip, &imm_expr);
7211 if ((unsigned long) imm_expr.X_add_number > 31)
7213 as_warn (_("Invalid value for `%s' (%lu)"),
7215 (unsigned long) imm_expr.X_add_number);
7216 imm_expr.X_add_number &= 0x1f;
7219 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7221 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7222 imm_expr.X_op = O_absent;
7226 case 'c': /* break code */
7227 my_getExpression (&imm_expr, s);
7228 check_absolute_expr (ip, &imm_expr);
7229 if ((unsigned) imm_expr.X_add_number > 1023)
7231 as_warn (_("Illegal break code (%ld)"),
7232 (long) imm_expr.X_add_number);
7233 imm_expr.X_add_number &= 0x3ff;
7235 ip->insn_opcode |= imm_expr.X_add_number << 16;
7236 imm_expr.X_op = O_absent;
7240 case 'q': /* lower break code */
7241 my_getExpression (&imm_expr, s);
7242 check_absolute_expr (ip, &imm_expr);
7243 if ((unsigned) imm_expr.X_add_number > 1023)
7245 as_warn (_("Illegal lower break code (%ld)"),
7246 (long) imm_expr.X_add_number);
7247 imm_expr.X_add_number &= 0x3ff;
7249 ip->insn_opcode |= imm_expr.X_add_number << 6;
7250 imm_expr.X_op = O_absent;
7254 case 'B': /* 20-bit syscall/break code. */
7255 my_getExpression (&imm_expr, s);
7256 check_absolute_expr (ip, &imm_expr);
7257 if ((unsigned) imm_expr.X_add_number > 0xfffff)
7258 as_warn (_("Illegal 20-bit code (%ld)"),
7259 (long) imm_expr.X_add_number);
7260 ip->insn_opcode |= imm_expr.X_add_number << 6;
7261 imm_expr.X_op = O_absent;
7265 case 'C': /* Coprocessor code */
7266 my_getExpression (&imm_expr, s);
7267 check_absolute_expr (ip, &imm_expr);
7268 if ((unsigned long) imm_expr.X_add_number >= (1<<25))
7270 as_warn (_("Coproccesor code > 25 bits (%ld)"),
7271 (long) imm_expr.X_add_number);
7272 imm_expr.X_add_number &= ((1<<25) - 1);
7274 ip->insn_opcode |= imm_expr.X_add_number;
7275 imm_expr.X_op = O_absent;
7279 case 'J': /* 19-bit wait code. */
7280 my_getExpression (&imm_expr, s);
7281 check_absolute_expr (ip, &imm_expr);
7282 if ((unsigned) imm_expr.X_add_number > 0x7ffff)
7283 as_warn (_("Illegal 19-bit code (%ld)"),
7284 (long) imm_expr.X_add_number);
7285 ip->insn_opcode |= imm_expr.X_add_number << 6;
7286 imm_expr.X_op = O_absent;
7290 case 'P': /* Performance register */
7291 my_getExpression (&imm_expr, s);
7292 check_absolute_expr (ip, &imm_expr);
7293 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
7295 as_warn (_("Invalidate performance regster (%ld)"),
7296 (long) imm_expr.X_add_number);
7297 imm_expr.X_add_number &= 1;
7299 ip->insn_opcode |= (imm_expr.X_add_number << 1);
7300 imm_expr.X_op = O_absent;
7304 case 'b': /* base register */
7305 case 'd': /* destination register */
7306 case 's': /* source register */
7307 case 't': /* target register */
7308 case 'r': /* both target and source */
7309 case 'v': /* both dest and source */
7310 case 'w': /* both dest and target */
7311 case 'E': /* coprocessor target register */
7312 case 'G': /* coprocessor destination register */
7313 case 'x': /* ignore register name */
7314 case 'z': /* must be zero register */
7315 case 'U': /* destination register (clo/clz). */
7320 if (isdigit ((unsigned char) s[1]))
7330 while (isdigit ((unsigned char) *s));
7332 as_bad (_("Invalid register number (%d)"), regno);
7334 else if (*args == 'E' || *args == 'G')
7338 if (s[1] == 'f' && s[2] == 'p')
7343 else if (s[1] == 's' && s[2] == 'p')
7348 else if (s[1] == 'g' && s[2] == 'p')
7353 else if (s[1] == 'a' && s[2] == 't')
7358 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
7363 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
7368 else if (itbl_have_entries)
7373 p = s + 1; /* advance past '$' */
7374 n = itbl_get_field (&p); /* n is name */
7376 /* See if this is a register defined in an
7378 if (itbl_get_reg_val (n, &r))
7380 /* Get_field advances to the start of
7381 the next field, so we need to back
7382 rack to the end of the last field. */
7386 s = strchr (s, '\0');
7399 as_warn (_("Used $at without \".set noat\""));
7405 if (c == 'r' || c == 'v' || c == 'w')
7412 /* 'z' only matches $0. */
7413 if (c == 'z' && regno != 0)
7416 /* Now that we have assembled one operand, we use the args string
7417 * to figure out where it goes in the instruction. */
7424 ip->insn_opcode |= regno << 21;
7428 ip->insn_opcode |= regno << 11;
7431 ip->insn_opcode |= regno << 11;
7432 ip->insn_opcode |= regno << 16;
7437 ip->insn_opcode |= regno << 16;
7440 /* This case exists because on the r3000 trunc
7441 expands into a macro which requires a gp
7442 register. On the r6000 or r4000 it is
7443 assembled into a single instruction which
7444 ignores the register. Thus the insn version
7445 is MIPS_ISA2 and uses 'x', and the macro
7446 version is MIPS_ISA1 and uses 't'. */
7449 /* This case is for the div instruction, which
7450 acts differently if the destination argument
7451 is $0. This only matches $0, and is checked
7452 outside the switch. */
7455 /* Itbl operand; not yet implemented. FIXME ?? */
7457 /* What about all other operands like 'i', which
7458 can be specified in the opcode table? */
7468 ip->insn_opcode |= lastregno << 21;
7471 ip->insn_opcode |= lastregno << 16;
7476 case 'D': /* floating point destination register */
7477 case 'S': /* floating point source register */
7478 case 'T': /* floating point target register */
7479 case 'R': /* floating point source register */
7483 if (s[0] == '$' && s[1] == 'f' && isdigit ((unsigned char) s[2]))
7493 while (isdigit ((unsigned char) *s));
7496 as_bad (_("Invalid float register number (%d)"), regno);
7498 if ((regno & 1) != 0
7499 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
7500 && ! (strcmp (str, "mtc1") == 0
7501 || strcmp (str, "mfc1") == 0
7502 || strcmp (str, "lwc1") == 0
7503 || strcmp (str, "swc1") == 0
7504 || strcmp (str, "l.s") == 0
7505 || strcmp (str, "s.s") == 0))
7506 as_warn (_("Float register should be even, was %d"),
7514 if (c == 'V' || c == 'W')
7524 ip->insn_opcode |= regno << 6;
7528 ip->insn_opcode |= regno << 11;
7532 ip->insn_opcode |= regno << 16;
7535 ip->insn_opcode |= regno << 21;
7545 ip->insn_opcode |= lastregno << 11;
7548 ip->insn_opcode |= lastregno << 16;
7554 my_getExpression (&imm_expr, s);
7555 if (imm_expr.X_op != O_big
7556 && imm_expr.X_op != O_constant)
7557 insn_error = _("absolute expression required");
7562 my_getExpression (&offset_expr, s);
7563 imm_reloc = BFD_RELOC_32;
7575 unsigned char temp[8];
7577 unsigned int length;
7582 /* These only appear as the last operand in an
7583 instruction, and every instruction that accepts
7584 them in any variant accepts them in all variants.
7585 This means we don't have to worry about backing out
7586 any changes if the instruction does not match.
7588 The difference between them is the size of the
7589 floating point constant and where it goes. For 'F'
7590 and 'L' the constant is 64 bits; for 'f' and 'l' it
7591 is 32 bits. Where the constant is placed is based
7592 on how the MIPS assembler does things:
7595 f -- immediate value
7598 The .lit4 and .lit8 sections are only used if
7599 permitted by the -G argument.
7601 When generating embedded PIC code, we use the
7602 .lit8 section but not the .lit4 section (we can do
7603 .lit4 inline easily; we need to put .lit8
7604 somewhere in the data segment, and using .lit8
7605 permits the linker to eventually combine identical
7608 f64 = *args == 'F' || *args == 'L';
7610 save_in = input_line_pointer;
7611 input_line_pointer = s;
7612 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
7614 s = input_line_pointer;
7615 input_line_pointer = save_in;
7616 if (err != NULL && *err != '\0')
7618 as_bad (_("Bad floating point constant: %s"), err);
7619 memset (temp, '\0', sizeof temp);
7620 length = f64 ? 8 : 4;
7623 assert (length == (unsigned) (f64 ? 8 : 4));
7627 && (! USE_GLOBAL_POINTER_OPT
7628 || mips_pic == EMBEDDED_PIC
7629 || g_switch_value < 4
7630 || (temp[0] == 0 && temp[1] == 0)
7631 || (temp[2] == 0 && temp[3] == 0))))
7633 imm_expr.X_op = O_constant;
7634 if (! target_big_endian)
7635 imm_expr.X_add_number = bfd_getl32 (temp);
7637 imm_expr.X_add_number = bfd_getb32 (temp);
7640 && ! mips_disable_float_construction
7641 && ((temp[0] == 0 && temp[1] == 0)
7642 || (temp[2] == 0 && temp[3] == 0))
7643 && ((temp[4] == 0 && temp[5] == 0)
7644 || (temp[6] == 0 && temp[7] == 0)))
7646 /* The value is simple enough to load with a
7647 couple of instructions. In mips1 mode, set
7648 imm_expr to the high order 32 bits and
7649 offset_expr to the low order 32 bits.
7650 Otherwise, set imm_expr to the entire 64 bit
7652 if (! ISA_HAS_64BIT_REGS (mips_opts.isa))
7654 imm_expr.X_op = O_constant;
7655 offset_expr.X_op = O_constant;
7656 if (! target_big_endian)
7658 imm_expr.X_add_number = bfd_getl32 (temp + 4);
7659 offset_expr.X_add_number = bfd_getl32 (temp);
7663 imm_expr.X_add_number = bfd_getb32 (temp);
7664 offset_expr.X_add_number = bfd_getb32 (temp + 4);
7666 if (offset_expr.X_add_number == 0)
7667 offset_expr.X_op = O_absent;
7669 else if (sizeof (imm_expr.X_add_number) > 4)
7671 imm_expr.X_op = O_constant;
7672 if (! target_big_endian)
7673 imm_expr.X_add_number = bfd_getl64 (temp);
7675 imm_expr.X_add_number = bfd_getb64 (temp);
7679 imm_expr.X_op = O_big;
7680 imm_expr.X_add_number = 4;
7681 if (! target_big_endian)
7683 generic_bignum[0] = bfd_getl16 (temp);
7684 generic_bignum[1] = bfd_getl16 (temp + 2);
7685 generic_bignum[2] = bfd_getl16 (temp + 4);
7686 generic_bignum[3] = bfd_getl16 (temp + 6);
7690 generic_bignum[0] = bfd_getb16 (temp + 6);
7691 generic_bignum[1] = bfd_getb16 (temp + 4);
7692 generic_bignum[2] = bfd_getb16 (temp + 2);
7693 generic_bignum[3] = bfd_getb16 (temp);
7699 const char *newname;
7702 /* Switch to the right section. */
7704 subseg = now_subseg;
7707 default: /* unused default case avoids warnings. */
7709 newname = RDATA_SECTION_NAME;
7710 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
7711 || mips_pic == EMBEDDED_PIC)
7715 if (mips_pic == EMBEDDED_PIC)
7718 newname = RDATA_SECTION_NAME;
7721 assert (!USE_GLOBAL_POINTER_OPT
7722 || g_switch_value >= 4);
7726 new_seg = subseg_new (newname, (subsegT) 0);
7727 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7728 bfd_set_section_flags (stdoutput, new_seg,
7733 frag_align (*args == 'l' ? 2 : 3, 0, 0);
7734 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
7735 && strcmp (TARGET_OS, "elf") != 0)
7736 record_alignment (new_seg, 4);
7738 record_alignment (new_seg, *args == 'l' ? 2 : 3);
7740 as_bad (_("Can't use floating point insn in this section"));
7742 /* Set the argument to the current address in the
7744 offset_expr.X_op = O_symbol;
7745 offset_expr.X_add_symbol =
7746 symbol_new ("L0\001", now_seg,
7747 (valueT) frag_now_fix (), frag_now);
7748 offset_expr.X_add_number = 0;
7750 /* Put the floating point number into the section. */
7751 p = frag_more ((int) length);
7752 memcpy (p, temp, length);
7754 /* Switch back to the original section. */
7755 subseg_set (seg, subseg);
7760 case 'i': /* 16 bit unsigned immediate */
7761 case 'j': /* 16 bit signed immediate */
7762 imm_reloc = BFD_RELOC_LO16;
7763 c = my_getSmallExpression (&imm_expr, s);
7768 if (imm_expr.X_op == O_constant)
7769 imm_expr.X_add_number =
7770 (imm_expr.X_add_number >> 16) & 0xffff;
7773 imm_reloc = BFD_RELOC_HI16_S;
7774 imm_unmatched_hi = true;
7777 imm_reloc = BFD_RELOC_HI16;
7779 else if (imm_expr.X_op == O_constant)
7780 imm_expr.X_add_number &= 0xffff;
7784 if ((c == '\0' && imm_expr.X_op != O_constant)
7785 || ((imm_expr.X_add_number < 0
7786 || imm_expr.X_add_number >= 0x10000)
7787 && imm_expr.X_op == O_constant))
7789 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7790 !strcmp (insn->name, insn[1].name))
7792 if (imm_expr.X_op == O_constant
7793 || imm_expr.X_op == O_big)
7794 as_bad (_("16 bit expression not in range 0..65535"));
7802 /* The upper bound should be 0x8000, but
7803 unfortunately the MIPS assembler accepts numbers
7804 from 0x8000 to 0xffff and sign extends them, and
7805 we want to be compatible. We only permit this
7806 extended range for an instruction which does not
7807 provide any further alternates, since those
7808 alternates may handle other cases. People should
7809 use the numbers they mean, rather than relying on
7810 a mysterious sign extension. */
7811 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7812 strcmp (insn->name, insn[1].name) == 0);
7817 if ((c == '\0' && imm_expr.X_op != O_constant)
7818 || ((imm_expr.X_add_number < -0x8000
7819 || imm_expr.X_add_number >= max)
7820 && imm_expr.X_op == O_constant)
7822 && imm_expr.X_add_number < 0
7823 && ISA_HAS_64BIT_REGS (mips_opts.isa)
7824 && imm_expr.X_unsigned
7825 && sizeof (imm_expr.X_add_number) <= 4))
7829 if (imm_expr.X_op == O_constant
7830 || imm_expr.X_op == O_big)
7831 as_bad (_("16 bit expression not in range -32768..32767"));
7837 case 'o': /* 16 bit offset */
7838 c = my_getSmallExpression (&offset_expr, s);
7840 /* If this value won't fit into a 16 bit offset, then go
7841 find a macro that will generate the 32 bit offset
7842 code pattern. As a special hack, we accept the
7843 difference of two local symbols as a constant. This
7844 is required to suppose embedded PIC switches, which
7845 use an instruction which looks like
7846 lw $4,$L12-$LS12($4)
7847 The problem with handling this in a more general
7848 fashion is that the macro function doesn't expect to
7849 see anything which can be handled in a single
7850 constant instruction. */
7852 && (offset_expr.X_op != O_constant
7853 || offset_expr.X_add_number >= 0x8000
7854 || offset_expr.X_add_number < -0x8000)
7855 && (mips_pic != EMBEDDED_PIC
7856 || offset_expr.X_op != O_subtract
7857 || (S_GET_SEGMENT (offset_expr.X_add_symbol)
7858 != S_GET_SEGMENT (offset_expr.X_op_symbol))))
7861 if (c == 'h' || c == 'H')
7863 if (offset_expr.X_op != O_constant)
7865 offset_expr.X_add_number =
7866 (offset_expr.X_add_number >> 16) & 0xffff;
7868 offset_reloc = BFD_RELOC_LO16;
7872 case 'p': /* pc relative offset */
7873 offset_reloc = BFD_RELOC_16_PCREL_S2;
7874 my_getExpression (&offset_expr, s);
7878 case 'u': /* upper 16 bits */
7879 c = my_getSmallExpression (&imm_expr, s);
7880 imm_reloc = BFD_RELOC_LO16;
7885 if (imm_expr.X_op == O_constant)
7886 imm_expr.X_add_number =
7887 (imm_expr.X_add_number >> 16) & 0xffff;
7890 imm_reloc = BFD_RELOC_HI16_S;
7891 imm_unmatched_hi = true;
7894 imm_reloc = BFD_RELOC_HI16;
7896 else if (imm_expr.X_op == O_constant)
7897 imm_expr.X_add_number &= 0xffff;
7899 if (imm_expr.X_op == O_constant
7900 && (imm_expr.X_add_number < 0
7901 || imm_expr.X_add_number >= 0x10000))
7902 as_bad (_("lui expression not in range 0..65535"));
7906 case 'a': /* 26 bit address */
7907 my_getExpression (&offset_expr, s);
7909 offset_reloc = BFD_RELOC_MIPS_JMP;
7912 case 'N': /* 3 bit branch condition code */
7913 case 'M': /* 3 bit compare condition code */
7914 if (strncmp (s, "$fcc", 4) != 0)
7924 while (isdigit ((unsigned char) *s));
7926 as_bad (_("invalid condition code register $fcc%d"), regno);
7928 ip->insn_opcode |= regno << OP_SH_BCC;
7930 ip->insn_opcode |= regno << OP_SH_CCC;
7934 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
7936 if (isdigit ((unsigned char) *s))
7945 while (isdigit ((unsigned char) *s));
7948 c = 8; /* Invalid sel value. */
7951 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
7952 ip->insn_opcode |= c;
7956 as_bad (_("bad char = '%c'\n"), *args);
7961 /* Args don't match. */
7962 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7963 !strcmp (insn->name, insn[1].name))
7967 insn_error = _("illegal operands");
7972 insn_error = _("illegal operands");
7977 /* This routine assembles an instruction into its binary format when
7978 assembling for the mips16. As a side effect, it sets one of the
7979 global variables imm_reloc or offset_reloc to the type of
7980 relocation to do if one of the operands is an address expression.
7981 It also sets mips16_small and mips16_ext if the user explicitly
7982 requested a small or extended instruction. */
7987 struct mips_cl_insn *ip;
7991 struct mips_opcode *insn;
7994 unsigned int lastregno = 0;
7999 mips16_small = false;
8002 for (s = str; islower ((unsigned char) *s); ++s)
8014 if (s[1] == 't' && s[2] == ' ')
8017 mips16_small = true;
8021 else if (s[1] == 'e' && s[2] == ' ')
8030 insn_error = _("unknown opcode");
8034 if (mips_opts.noautoextend && ! mips16_ext)
8035 mips16_small = true;
8037 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
8039 insn_error = _("unrecognized opcode");
8046 assert (strcmp (insn->name, str) == 0);
8049 ip->insn_opcode = insn->match;
8050 ip->use_extend = false;
8051 imm_expr.X_op = O_absent;
8052 imm_reloc = BFD_RELOC_UNUSED;
8053 offset_expr.X_op = O_absent;
8054 offset_reloc = BFD_RELOC_UNUSED;
8055 for (args = insn->args; 1; ++args)
8062 /* In this switch statement we call break if we did not find
8063 a match, continue if we did find a match, or return if we
8072 /* Stuff the immediate value in now, if we can. */
8073 if (imm_expr.X_op == O_constant
8074 && imm_reloc > BFD_RELOC_UNUSED
8075 && insn->pinfo != INSN_MACRO)
8077 mips16_immed ((char *) NULL, 0,
8078 imm_reloc - BFD_RELOC_UNUSED,
8079 imm_expr.X_add_number, true, mips16_small,
8080 mips16_ext, &ip->insn_opcode,
8081 &ip->use_extend, &ip->extend);
8082 imm_expr.X_op = O_absent;
8083 imm_reloc = BFD_RELOC_UNUSED;
8097 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8100 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8116 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8118 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8135 if (isdigit ((unsigned char) s[1]))
8145 while (isdigit ((unsigned char) *s));
8148 as_bad (_("invalid register number (%d)"), regno);
8154 if (s[1] == 'f' && s[2] == 'p')
8159 else if (s[1] == 's' && s[2] == 'p')
8164 else if (s[1] == 'g' && s[2] == 'p')
8169 else if (s[1] == 'a' && s[2] == 't')
8174 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8179 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8192 if (c == 'v' || c == 'w')
8194 regno = mips16_to_32_reg_map[lastregno];
8208 regno = mips32_to_16_reg_map[regno];
8213 regno = ILLEGAL_REG;
8218 regno = ILLEGAL_REG;
8223 regno = ILLEGAL_REG;
8228 if (regno == AT && ! mips_opts.noat)
8229 as_warn (_("used $at without \".set noat\""));
8236 if (regno == ILLEGAL_REG)
8243 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
8247 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
8250 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
8253 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
8259 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
8262 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
8263 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
8273 if (strncmp (s, "$pc", 3) == 0)
8297 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
8299 /* This is %gprel(SYMBOL). We need to read SYMBOL,
8300 and generate the appropriate reloc. If the text
8301 inside %gprel is not a symbol name with an
8302 optional offset, then we generate a normal reloc
8303 and will probably fail later. */
8304 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
8305 if (imm_expr.X_op == O_symbol)
8308 imm_reloc = BFD_RELOC_MIPS16_GPREL;
8310 ip->use_extend = true;
8317 /* Just pick up a normal expression. */
8318 my_getExpression (&imm_expr, s);
8321 if (imm_expr.X_op == O_register)
8323 /* What we thought was an expression turned out to
8326 if (s[0] == '(' && args[1] == '(')
8328 /* It looks like the expression was omitted
8329 before a register indirection, which means
8330 that the expression is implicitly zero. We
8331 still set up imm_expr, so that we handle
8332 explicit extensions correctly. */
8333 imm_expr.X_op = O_constant;
8334 imm_expr.X_add_number = 0;
8335 imm_reloc = (int) BFD_RELOC_UNUSED + c;
8342 /* We need to relax this instruction. */
8343 imm_reloc = (int) BFD_RELOC_UNUSED + c;
8352 /* We use offset_reloc rather than imm_reloc for the PC
8353 relative operands. This lets macros with both
8354 immediate and address operands work correctly. */
8355 my_getExpression (&offset_expr, s);
8357 if (offset_expr.X_op == O_register)
8360 /* We need to relax this instruction. */
8361 offset_reloc = (int) BFD_RELOC_UNUSED + c;
8365 case '6': /* break code */
8366 my_getExpression (&imm_expr, s);
8367 check_absolute_expr (ip, &imm_expr);
8368 if ((unsigned long) imm_expr.X_add_number > 63)
8370 as_warn (_("Invalid value for `%s' (%lu)"),
8372 (unsigned long) imm_expr.X_add_number);
8373 imm_expr.X_add_number &= 0x3f;
8375 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
8376 imm_expr.X_op = O_absent;
8380 case 'a': /* 26 bit address */
8381 my_getExpression (&offset_expr, s);
8383 offset_reloc = BFD_RELOC_MIPS16_JMP;
8384 ip->insn_opcode <<= 16;
8387 case 'l': /* register list for entry macro */
8388 case 'L': /* register list for exit macro */
8398 int freg, reg1, reg2;
8400 while (*s == ' ' || *s == ',')
8404 as_bad (_("can't parse register list"));
8416 while (isdigit ((unsigned char) *s))
8438 as_bad (_("invalid register list"));
8443 while (isdigit ((unsigned char) *s))
8450 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
8455 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
8460 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
8461 mask |= (reg2 - 3) << 3;
8462 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
8463 mask |= (reg2 - 15) << 1;
8464 else if (reg1 == 31 && reg2 == 31)
8468 as_bad (_("invalid register list"));
8472 /* The mask is filled in in the opcode table for the
8473 benefit of the disassembler. We remove it before
8474 applying the actual mask. */
8475 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
8476 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
8480 case 'e': /* extend code */
8481 my_getExpression (&imm_expr, s);
8482 check_absolute_expr (ip, &imm_expr);
8483 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
8485 as_warn (_("Invalid value for `%s' (%lu)"),
8487 (unsigned long) imm_expr.X_add_number);
8488 imm_expr.X_add_number &= 0x7ff;
8490 ip->insn_opcode |= imm_expr.X_add_number;
8491 imm_expr.X_op = O_absent;
8501 /* Args don't match. */
8502 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
8503 strcmp (insn->name, insn[1].name) == 0)
8510 insn_error = _("illegal operands");
8516 /* This structure holds information we know about a mips16 immediate
8519 struct mips16_immed_operand
8521 /* The type code used in the argument string in the opcode table. */
8523 /* The number of bits in the short form of the opcode. */
8525 /* The number of bits in the extended form of the opcode. */
8527 /* The amount by which the short form is shifted when it is used;
8528 for example, the sw instruction has a shift count of 2. */
8530 /* The amount by which the short form is shifted when it is stored
8531 into the instruction code. */
8533 /* Non-zero if the short form is unsigned. */
8535 /* Non-zero if the extended form is unsigned. */
8537 /* Non-zero if the value is PC relative. */
8541 /* The mips16 immediate operand types. */
8543 static const struct mips16_immed_operand mips16_immed_operands[] =
8545 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
8546 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
8547 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
8548 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
8549 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
8550 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
8551 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
8552 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
8553 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
8554 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
8555 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
8556 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
8557 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
8558 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
8559 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
8560 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
8561 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
8562 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
8563 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
8564 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
8565 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
8568 #define MIPS16_NUM_IMMED \
8569 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
8571 /* Handle a mips16 instruction with an immediate value. This or's the
8572 small immediate value into *INSN. It sets *USE_EXTEND to indicate
8573 whether an extended value is needed; if one is needed, it sets
8574 *EXTEND to the value. The argument type is TYPE. The value is VAL.
8575 If SMALL is true, an unextended opcode was explicitly requested.
8576 If EXT is true, an extended opcode was explicitly requested. If
8577 WARN is true, warn if EXT does not match reality. */
8580 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
8589 unsigned long *insn;
8590 boolean *use_extend;
8591 unsigned short *extend;
8593 register const struct mips16_immed_operand *op;
8594 int mintiny, maxtiny;
8597 op = mips16_immed_operands;
8598 while (op->type != type)
8601 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
8606 if (type == '<' || type == '>' || type == '[' || type == ']')
8609 maxtiny = 1 << op->nbits;
8614 maxtiny = (1 << op->nbits) - 1;
8619 mintiny = - (1 << (op->nbits - 1));
8620 maxtiny = (1 << (op->nbits - 1)) - 1;
8623 /* Branch offsets have an implicit 0 in the lowest bit. */
8624 if (type == 'p' || type == 'q')
8627 if ((val & ((1 << op->shift) - 1)) != 0
8628 || val < (mintiny << op->shift)
8629 || val > (maxtiny << op->shift))
8634 if (warn && ext && ! needext)
8635 as_warn_where (file, line,
8636 _("extended operand requested but not required"));
8637 if (small && needext)
8638 as_bad_where (file, line, _("invalid unextended operand value"));
8640 if (small || (! ext && ! needext))
8644 *use_extend = false;
8645 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
8646 insnval <<= op->op_shift;
8651 long minext, maxext;
8657 maxext = (1 << op->extbits) - 1;
8661 minext = - (1 << (op->extbits - 1));
8662 maxext = (1 << (op->extbits - 1)) - 1;
8664 if (val < minext || val > maxext)
8665 as_bad_where (file, line,
8666 _("operand value out of range for instruction"));
8669 if (op->extbits == 16)
8671 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
8674 else if (op->extbits == 15)
8676 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
8681 extval = ((val & 0x1f) << 6) | (val & 0x20);
8685 *extend = (unsigned short) extval;
8694 my_getSmallExpression (ep, str)
8705 ((str[1] == 'h' && str[2] == 'i')
8706 || (str[1] == 'H' && str[2] == 'I')
8707 || (str[1] == 'l' && str[2] == 'o'))
8719 * A small expression may be followed by a base register.
8720 * Scan to the end of this operand, and then back over a possible
8721 * base register. Then scan the small expression up to that
8722 * point. (Based on code in sparc.c...)
8724 for (sp = str; *sp && *sp != ','; sp++)
8726 if (sp - 4 >= str && sp[-1] == RP)
8728 if (isdigit ((unsigned char) sp[-2]))
8730 for (sp -= 3; sp >= str && isdigit ((unsigned char) *sp); sp--)
8732 if (*sp == '$' && sp > str && sp[-1] == LP)
8738 else if (sp - 5 >= str
8741 && ((sp[-3] == 'f' && sp[-2] == 'p')
8742 || (sp[-3] == 's' && sp[-2] == 'p')
8743 || (sp[-3] == 'g' && sp[-2] == 'p')
8744 || (sp[-3] == 'a' && sp[-2] == 't')))
8750 /* no expression means zero offset */
8753 /* %xx(reg) is an error */
8754 ep->X_op = O_absent;
8759 ep->X_op = O_constant;
8762 ep->X_add_symbol = NULL;
8763 ep->X_op_symbol = NULL;
8764 ep->X_add_number = 0;
8769 my_getExpression (ep, str);
8776 my_getExpression (ep, str);
8777 return c; /* => %hi or %lo encountered */
8781 my_getExpression (ep, str)
8788 save_in = input_line_pointer;
8789 input_line_pointer = str;
8791 expr_end = input_line_pointer;
8792 input_line_pointer = save_in;
8794 /* If we are in mips16 mode, and this is an expression based on `.',
8795 then we bump the value of the symbol by 1 since that is how other
8796 text symbols are handled. We don't bother to handle complex
8797 expressions, just `.' plus or minus a constant. */
8798 if (mips_opts.mips16
8799 && ep->X_op == O_symbol
8800 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
8801 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
8802 && symbol_get_frag (ep->X_add_symbol) == frag_now
8803 && symbol_constant_p (ep->X_add_symbol)
8804 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
8805 S_SET_VALUE (ep->X_add_symbol, val + 1);
8808 /* Turn a string in input_line_pointer into a floating point constant
8809 of type TYPE, and store the appropriate bytes in *LITP. The number
8810 of LITTLENUMS emitted is stored in *SIZEP. An error message is
8811 returned, or NULL on OK. */
8814 md_atof (type, litP, sizeP)
8820 LITTLENUM_TYPE words[4];
8836 return _("bad call to md_atof");
8839 t = atof_ieee (input_line_pointer, type, words);
8841 input_line_pointer = t;
8845 if (! target_big_endian)
8847 for (i = prec - 1; i >= 0; i--)
8849 md_number_to_chars (litP, (valueT) words[i], 2);
8855 for (i = 0; i < prec; i++)
8857 md_number_to_chars (litP, (valueT) words[i], 2);
8866 md_number_to_chars (buf, val, n)
8871 if (target_big_endian)
8872 number_to_chars_bigendian (buf, val, n);
8874 number_to_chars_littleendian (buf, val, n);
8877 CONST char *md_shortopts = "nO::g::G:";
8879 struct option md_longopts[] =
8881 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
8882 {"mips0", no_argument, NULL, OPTION_MIPS1},
8883 {"mips1", no_argument, NULL, OPTION_MIPS1},
8884 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
8885 {"mips2", no_argument, NULL, OPTION_MIPS2},
8886 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
8887 {"mips3", no_argument, NULL, OPTION_MIPS3},
8888 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
8889 {"mips4", no_argument, NULL, OPTION_MIPS4},
8890 #define OPTION_MCPU (OPTION_MD_BASE + 5)
8891 {"mcpu", required_argument, NULL, OPTION_MCPU},
8892 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 6)
8893 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
8894 #define OPTION_TRAP (OPTION_MD_BASE + 7)
8895 {"trap", no_argument, NULL, OPTION_TRAP},
8896 {"no-break", no_argument, NULL, OPTION_TRAP},
8897 #define OPTION_BREAK (OPTION_MD_BASE + 8)
8898 {"break", no_argument, NULL, OPTION_BREAK},
8899 {"no-trap", no_argument, NULL, OPTION_BREAK},
8900 #define OPTION_EB (OPTION_MD_BASE + 9)
8901 {"EB", no_argument, NULL, OPTION_EB},
8902 #define OPTION_EL (OPTION_MD_BASE + 10)
8903 {"EL", no_argument, NULL, OPTION_EL},
8904 #define OPTION_M4650 (OPTION_MD_BASE + 11)
8905 {"m4650", no_argument, NULL, OPTION_M4650},
8906 #define OPTION_NO_M4650 (OPTION_MD_BASE + 12)
8907 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
8908 #define OPTION_M4010 (OPTION_MD_BASE + 13)
8909 {"m4010", no_argument, NULL, OPTION_M4010},
8910 #define OPTION_NO_M4010 (OPTION_MD_BASE + 14)
8911 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
8912 #define OPTION_M4100 (OPTION_MD_BASE + 15)
8913 {"m4100", no_argument, NULL, OPTION_M4100},
8914 #define OPTION_NO_M4100 (OPTION_MD_BASE + 16)
8915 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
8916 #define OPTION_MIPS16 (OPTION_MD_BASE + 17)
8917 {"mips16", no_argument, NULL, OPTION_MIPS16},
8918 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 18)
8919 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
8920 #define OPTION_M3900 (OPTION_MD_BASE + 19)
8921 {"m3900", no_argument, NULL, OPTION_M3900},
8922 #define OPTION_NO_M3900 (OPTION_MD_BASE + 20)
8923 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
8924 #define OPTION_MABI (OPTION_MD_BASE + 21)
8925 {"mabi", required_argument, NULL, OPTION_MABI},
8926 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 22)
8927 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
8928 #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 23)
8929 {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX},
8930 #define OPTION_GP32 (OPTION_MD_BASE + 24)
8931 {"mgp32", no_argument, NULL, OPTION_GP32},
8932 #define OPTION_GP64 (OPTION_MD_BASE + 25)
8933 {"mgp64", no_argument, NULL, OPTION_GP64},
8934 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 26)
8935 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
8936 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 27)
8937 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
8938 #define OPTION_MIPS32 (OPTION_MD_BASE + 28)
8939 {"mips32", no_argument, NULL, OPTION_MIPS32},
8940 #define OPTION_MIPS5 (OPTION_MD_BASE + 29)
8941 {"mips5", no_argument, NULL, OPTION_MIPS5},
8942 #define OPTION_MIPS64 (OPTION_MD_BASE + 30)
8943 {"mips64", no_argument, NULL, OPTION_MIPS64},
8944 #define OPTION_MARCH (OPTION_MD_BASE + 31)
8945 {"march", required_argument, NULL, OPTION_MARCH},
8946 #define OPTION_MTUNE (OPTION_MD_BASE + 32)
8947 {"mtune", required_argument, NULL, OPTION_MTUNE},
8949 #define OPTION_ELF_BASE (OPTION_MD_BASE + 35)
8950 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
8951 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
8952 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
8953 #define OPTION_32 (OPTION_ELF_BASE + 3)
8954 #define OPTION_64 (OPTION_ELF_BASE + 4)
8955 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
8956 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
8957 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
8958 {"xgot", no_argument, NULL, OPTION_XGOT},
8959 {"32", no_argument, NULL, OPTION_32},
8960 {"64", no_argument, NULL, OPTION_64},
8963 {NULL, no_argument, NULL, 0}
8965 size_t md_longopts_size = sizeof (md_longopts);
8968 md_parse_option (c, arg)
8974 case OPTION_CONSTRUCT_FLOATS:
8975 mips_disable_float_construction = 0;
8978 case OPTION_NO_CONSTRUCT_FLOATS:
8979 mips_disable_float_construction = 1;
8991 target_big_endian = 1;
8995 target_big_endian = 0;
9003 if (arg && arg[1] == '0')
9013 mips_debug = atoi (arg);
9014 /* When the MIPS assembler sees -g or -g2, it does not do
9015 optimizations which limit full symbolic debugging. We take
9016 that to be equivalent to -O0. */
9017 if (mips_debug == 2)
9022 mips_opts.isa = ISA_MIPS1;
9026 mips_opts.isa = ISA_MIPS2;
9030 mips_opts.isa = ISA_MIPS3;
9034 mips_opts.isa = ISA_MIPS4;
9038 mips_opts.isa = ISA_MIPS5;
9042 mips_opts.isa = ISA_MIPS32;
9046 mips_opts.isa = ISA_MIPS64;
9053 int cpu = CPU_UNKNOWN;
9055 /* Identify the processor type. */
9056 if (strcasecmp (arg, "default") != 0)
9058 const struct mips_cpu_info *ci;
9060 ci = mips_cpu_info_from_name (arg);
9061 if (ci == NULL || ci->is_isa)
9066 as_fatal (_("invalid architecture -mtune=%s"), arg);
9069 as_fatal (_("invalid architecture -march=%s"), arg);
9072 as_fatal (_("invalid architecture -mcpu=%s"), arg);
9095 mips_arch = CPU_R4650;
9096 mips_tune = CPU_R4650;
9099 case OPTION_NO_M4650:
9103 mips_arch = CPU_R4010;
9104 mips_tune = CPU_R4010;
9107 case OPTION_NO_M4010:
9111 mips_arch = CPU_VR4100;
9112 mips_tune = CPU_VR4100;
9115 case OPTION_NO_M4100:
9119 mips_arch = CPU_R3900;
9120 mips_tune = CPU_R3900;
9123 case OPTION_NO_M3900:
9127 mips_opts.mips16 = 1;
9128 mips_no_prev_insn (false);
9131 case OPTION_NO_MIPS16:
9132 mips_opts.mips16 = 0;
9133 mips_no_prev_insn (false);
9136 case OPTION_MEMBEDDED_PIC:
9137 mips_pic = EMBEDDED_PIC;
9138 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
9140 as_bad (_("-G may not be used with embedded PIC code"));
9143 g_switch_value = 0x7fffffff;
9147 /* When generating ELF code, we permit -KPIC and -call_shared to
9148 select SVR4_PIC, and -non_shared to select no PIC. This is
9149 intended to be compatible with Irix 5. */
9150 case OPTION_CALL_SHARED:
9151 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9153 as_bad (_("-call_shared is supported only for ELF format"));
9156 mips_pic = SVR4_PIC;
9157 if (g_switch_seen && g_switch_value != 0)
9159 as_bad (_("-G may not be used with SVR4 PIC code"));
9165 case OPTION_NON_SHARED:
9166 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9168 as_bad (_("-non_shared is supported only for ELF format"));
9174 /* The -xgot option tells the assembler to use 32 offsets when
9175 accessing the got in SVR4_PIC mode. It is for Irix
9180 #endif /* OBJ_ELF */
9183 if (! USE_GLOBAL_POINTER_OPT)
9185 as_bad (_("-G is not supported for this configuration"));
9188 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
9190 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
9194 g_switch_value = atoi (arg);
9199 /* The -32 and -64 options tell the assembler to output the 32
9200 bit or the 64 bit MIPS ELF format. */
9207 const char **list, **l;
9209 list = bfd_target_list ();
9210 for (l = list; *l != NULL; l++)
9211 if (strcmp (*l, "elf64-bigmips") == 0
9212 || strcmp (*l, "elf64-littlemips") == 0
9213 || strcmp (*l, "elf64-tradbigmips") == 0
9214 || strcmp (*l, "elf64-tradlittlemips") == 0)
9217 as_fatal (_("No compiled in support for 64 bit object file format"));
9222 #endif /* OBJ_ELF */
9228 /* We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
9229 flag in object files because to do so would make it
9230 impossible to link with libraries compiled without "-gp32".
9231 This is unnecessarily restrictive.
9233 We could solve this problem by adding "-gp32" multilibs to
9234 gcc, but to set this flag before gcc is built with such
9235 multilibs will break too many systems. */
9251 if (strcmp (arg, "32") == 0
9252 || strcmp (arg, "n32") == 0
9253 || strcmp (arg, "64") == 0
9254 || strcmp (arg, "o64") == 0
9255 || strcmp (arg, "eabi") == 0)
9256 mips_abi_string = arg;
9259 case OPTION_M7000_HILO_FIX:
9260 mips_7000_hilo_fix = true;
9263 case OPTION_NO_M7000_HILO_FIX:
9264 mips_7000_hilo_fix = false;
9275 show (stream, string, col_p, first_p)
9283 fprintf (stream, "%24s", "");
9288 fprintf (stream, ", ");
9292 if (*col_p + strlen (string) > 72)
9294 fprintf (stream, "\n%24s", "");
9298 fprintf (stream, "%s", string);
9299 *col_p += strlen (string);
9305 md_show_usage (stream)
9310 fprintf (stream, _("\
9312 -membedded-pic generate embedded position independent code\n\
9313 -EB generate big endian output\n\
9314 -EL generate little endian output\n\
9315 -g, -g2 do not remove uneeded NOPs or swap branches\n\
9316 -G NUM allow referencing objects up to NUM bytes\n\
9317 implicitly with the gp register [default 8]\n"));
9318 fprintf (stream, _("\
9319 -mips1 generate MIPS ISA I instructions\n\
9320 -mips2 generate MIPS ISA II instructions\n\
9321 -mips3 generate MIPS ISA III instructions\n\
9322 -mips4 generate MIPS ISA IV instructions\n\
9323 -mips5 generate MIPS ISA V instructions\n\
9324 -mips32 generate MIPS32 ISA instructions\n\
9325 -mips64 generate MIPS64 ISA instructions\n\
9326 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
9330 show (stream, "2000", &column, &first);
9331 show (stream, "3000", &column, &first);
9332 show (stream, "3900", &column, &first);
9333 show (stream, "4000", &column, &first);
9334 show (stream, "4010", &column, &first);
9335 show (stream, "4100", &column, &first);
9336 show (stream, "4111", &column, &first);
9337 show (stream, "4300", &column, &first);
9338 show (stream, "4400", &column, &first);
9339 show (stream, "4600", &column, &first);
9340 show (stream, "4650", &column, &first);
9341 show (stream, "5000", &column, &first);
9342 show (stream, "5200", &column, &first);
9343 show (stream, "5230", &column, &first);
9344 show (stream, "5231", &column, &first);
9345 show (stream, "5261", &column, &first);
9346 show (stream, "5721", &column, &first);
9347 show (stream, "6000", &column, &first);
9348 show (stream, "8000", &column, &first);
9349 show (stream, "10000", &column, &first);
9350 show (stream, "12000", &column, &first);
9351 show (stream, "mips32-4k", &column, &first);
9352 show (stream, "sb-1", &column, &first);
9353 fputc ('\n', stream);
9355 fprintf (stream, _("\
9356 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
9357 -no-mCPU don't generate code specific to CPU.\n\
9358 For -mCPU and -no-mCPU, CPU must be one of:\n"));
9362 show (stream, "3900", &column, &first);
9363 show (stream, "4010", &column, &first);
9364 show (stream, "4100", &column, &first);
9365 show (stream, "4650", &column, &first);
9366 fputc ('\n', stream);
9368 fprintf (stream, _("\
9369 -mips16 generate mips16 instructions\n\
9370 -no-mips16 do not generate mips16 instructions\n"));
9371 fprintf (stream, _("\
9372 -O0 remove unneeded NOPs, do not swap branches\n\
9373 -O remove unneeded NOPs and swap branches\n\
9374 -n warn about NOPs generated from macros\n\
9375 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
9376 --trap, --no-break trap exception on div by 0 and mult overflow\n\
9377 --break, --no-trap break exception on div by 0 and mult overflow\n"));
9379 fprintf (stream, _("\
9380 -KPIC, -call_shared generate SVR4 position independent code\n\
9381 -non_shared do not generate position independent code\n\
9382 -xgot assume a 32 bit GOT\n\
9383 -32 create 32 bit object file (default)\n\
9384 -64 create 64 bit object file\n"));
9389 mips_init_after_args ()
9391 /* initialize opcodes */
9392 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
9393 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
9397 md_pcrel_from (fixP)
9400 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
9401 && fixP->fx_addsy != (symbolS *) NULL
9402 && ! S_IS_DEFINED (fixP->fx_addsy))
9404 /* This makes a branch to an undefined symbol be a branch to the
9405 current location. */
9409 /* return the address of the delay slot */
9410 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
9413 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
9414 reloc for a cons. We could use the definition there, except that
9415 we want to handle 64 bit relocs specially. */
9418 cons_fix_new_mips (frag, where, nbytes, exp)
9419 fragS *frag ATTRIBUTE_UNUSED;
9421 unsigned int nbytes;
9425 /* If we are assembling in 32 bit mode, turn an 8 byte reloc into a
9427 if (nbytes == 8 && ! mips_64)
9429 if (target_big_endian)
9435 if (nbytes != 2 && nbytes != 4 && nbytes != 8)
9436 as_bad (_("Unsupported reloc size %d"), nbytes);
9438 fix_new_exp (frag_now, where, (int) nbytes, exp, 0,
9441 : (nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64)));
9444 /* This is called before the symbol table is processed. In order to
9445 work with gcc when using mips-tfile, we must keep all local labels.
9446 However, in other cases, we want to discard them. If we were
9447 called with -g, but we didn't see any debugging information, it may
9448 mean that gcc is smuggling debugging information through to
9449 mips-tfile, in which case we must generate all local labels. */
9452 mips_frob_file_before_adjust ()
9454 #ifndef NO_ECOFF_DEBUGGING
9457 && ! ecoff_debugging_seen)
9458 flag_keep_locals = 1;
9462 /* Sort any unmatched HI16_S relocs so that they immediately precede
9463 the corresponding LO reloc. This is called before md_apply_fix and
9464 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
9465 explicit use of the %hi modifier. */
9470 struct mips_hi_fixup *l;
9472 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
9474 segment_info_type *seginfo;
9477 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
9479 /* Check quickly whether the next fixup happens to be a matching
9481 if (l->fixp->fx_next != NULL
9482 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
9483 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
9484 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
9487 /* Look through the fixups for this segment for a matching %lo.
9488 When we find one, move the %hi just in front of it. We do
9489 this in two passes. In the first pass, we try to find a
9490 unique %lo. In the second pass, we permit multiple %hi
9491 relocs for a single %lo (this is a GNU extension). */
9492 seginfo = seg_info (l->seg);
9493 for (pass = 0; pass < 2; pass++)
9498 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
9500 /* Check whether this is a %lo fixup which matches l->fixp. */
9501 if (f->fx_r_type == BFD_RELOC_LO16
9502 && f->fx_addsy == l->fixp->fx_addsy
9503 && f->fx_offset == l->fixp->fx_offset
9506 || prev->fx_r_type != BFD_RELOC_HI16_S
9507 || prev->fx_addsy != f->fx_addsy
9508 || prev->fx_offset != f->fx_offset))
9512 /* Move l->fixp before f. */
9513 for (pf = &seginfo->fix_root;
9515 pf = &(*pf)->fx_next)
9516 assert (*pf != NULL);
9518 *pf = l->fixp->fx_next;
9520 l->fixp->fx_next = f;
9522 seginfo->fix_root = l->fixp;
9524 prev->fx_next = l->fixp;
9535 #if 0 /* GCC code motion plus incomplete dead code elimination
9536 can leave a %hi without a %lo. */
9538 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
9539 _("Unmatched %%hi reloc"));
9545 /* When generating embedded PIC code we need to use a special
9546 relocation to represent the difference of two symbols in the .text
9547 section (switch tables use a difference of this sort). See
9548 include/coff/mips.h for details. This macro checks whether this
9549 fixup requires the special reloc. */
9550 #define SWITCH_TABLE(fixp) \
9551 ((fixp)->fx_r_type == BFD_RELOC_32 \
9552 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
9553 && (fixp)->fx_addsy != NULL \
9554 && (fixp)->fx_subsy != NULL \
9555 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
9556 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
9558 /* When generating embedded PIC code we must keep all PC relative
9559 relocations, in case the linker has to relax a call. We also need
9560 to keep relocations for switch table entries. */
9563 mips_force_relocation (fixp)
9566 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
9567 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
9570 return (mips_pic == EMBEDDED_PIC
9572 || SWITCH_TABLE (fixp)
9573 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
9574 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
9577 /* Apply a fixup to the object file. */
9580 md_apply_fix (fixP, valueP)
9588 assert (fixP->fx_size == 4
9589 || fixP->fx_r_type == BFD_RELOC_16
9590 || fixP->fx_r_type == BFD_RELOC_64
9591 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
9592 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
9596 /* If we aren't adjusting this fixup to be against the section
9597 symbol, we need to adjust the value. */
9599 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
9601 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16
9602 || ((S_IS_WEAK (fixP->fx_addsy)
9603 || S_IS_EXTERN (fixP->fx_addsy))
9604 && !S_IS_COMMON (fixP->fx_addsy))
9605 || (symbol_used_in_reloc_p (fixP->fx_addsy)
9606 && (((bfd_get_section_flags (stdoutput,
9607 S_GET_SEGMENT (fixP->fx_addsy))
9608 & SEC_LINK_ONCE) != 0)
9609 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
9611 sizeof (".gnu.linkonce") - 1))))
9614 valueT symval = S_GET_VALUE (fixP->fx_addsy);
9616 if (value != 0 && ! fixP->fx_pcrel)
9618 /* In this case, the bfd_install_relocation routine will
9619 incorrectly add the symbol value back in. We just want
9620 the addend to appear in the object file. */
9623 /* Make sure the addend is still non-zero. If it became zero
9624 after the last operation, set it to a spurious value and
9625 subtract the same value from the object file's contents. */
9630 /* The in-place addends for LO16 relocations are signed;
9631 leave the matching HI16 in-place addends as zero. */
9632 if (fixP->fx_r_type != BFD_RELOC_HI16_S)
9634 reloc_howto_type *howto;
9635 bfd_vma contents, mask, field;
9637 howto = bfd_reloc_type_lookup (stdoutput,
9640 contents = bfd_get_bits (fixP->fx_frag->fr_literal
9645 /* MASK has bits set where the relocation should go.
9646 FIELD is -value, shifted into the appropriate place
9647 for this relocation. */
9648 mask = 1 << (howto->bitsize - 1);
9649 mask = (((mask - 1) << 1) | 1) << howto->bitpos;
9650 field = (-value >> howto->rightshift) << howto->bitpos;
9652 bfd_put_bits ((field & mask) | (contents & ~mask),
9653 fixP->fx_frag->fr_literal + fixP->fx_where,
9661 /* This code was generated using trial and error and so is
9662 fragile and not trustworthy. If you change it, you should
9663 rerun the elf-rel, elf-rel2, and empic testcases and ensure
9665 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
9667 value += fixP->fx_frag->fr_address + fixP->fx_where;
9669 /* BFD's REL handling, for MIPS, is _very_ weird.
9670 This gives the right results, but it can't possibly
9671 be the way things are supposed to work. */
9672 if (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
9673 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
9674 value += fixP->fx_frag->fr_address + fixP->fx_where;
9679 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */
9681 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
9684 switch (fixP->fx_r_type)
9686 case BFD_RELOC_MIPS_JMP:
9687 case BFD_RELOC_HI16:
9688 case BFD_RELOC_HI16_S:
9689 case BFD_RELOC_MIPS_GPREL:
9690 case BFD_RELOC_MIPS_LITERAL:
9691 case BFD_RELOC_MIPS_CALL16:
9692 case BFD_RELOC_MIPS_GOT16:
9693 case BFD_RELOC_MIPS_GPREL32:
9694 case BFD_RELOC_MIPS_GOT_HI16:
9695 case BFD_RELOC_MIPS_GOT_LO16:
9696 case BFD_RELOC_MIPS_CALL_HI16:
9697 case BFD_RELOC_MIPS_CALL_LO16:
9698 case BFD_RELOC_MIPS16_GPREL:
9700 as_bad_where (fixP->fx_file, fixP->fx_line,
9701 _("Invalid PC relative reloc"));
9702 /* Nothing needed to do. The value comes from the reloc entry */
9705 case BFD_RELOC_MIPS16_JMP:
9706 /* We currently always generate a reloc against a symbol, which
9707 means that we don't want an addend even if the symbol is
9709 fixP->fx_addnumber = 0;
9712 case BFD_RELOC_PCREL_HI16_S:
9713 /* The addend for this is tricky if it is internal, so we just
9714 do everything here rather than in bfd_install_relocation. */
9715 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9720 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
9722 /* For an external symbol adjust by the address to make it
9723 pcrel_offset. We use the address of the RELLO reloc
9724 which follows this one. */
9725 value += (fixP->fx_next->fx_frag->fr_address
9726 + fixP->fx_next->fx_where);
9731 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9732 if (target_big_endian)
9734 md_number_to_chars (buf, value, 2);
9737 case BFD_RELOC_PCREL_LO16:
9738 /* The addend for this is tricky if it is internal, so we just
9739 do everything here rather than in bfd_install_relocation. */
9740 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9745 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
9746 value += fixP->fx_frag->fr_address + fixP->fx_where;
9747 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9748 if (target_big_endian)
9750 md_number_to_chars (buf, value, 2);
9754 /* This is handled like BFD_RELOC_32, but we output a sign
9755 extended value if we are only 32 bits. */
9757 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
9759 if (8 <= sizeof (valueT))
9760 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9767 w1 = w2 = fixP->fx_where;
9768 if (target_big_endian)
9772 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
9773 if ((value & 0x80000000) != 0)
9777 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
9784 /* If we are deleting this reloc entry, we must fill in the
9785 value now. This can happen if we have a .word which is not
9786 resolved when it appears but is later defined. We also need
9787 to fill in the value if this is an embedded PIC switch table
9790 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
9791 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9796 /* If we are deleting this reloc entry, we must fill in the
9798 assert (fixP->fx_size == 2);
9800 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9804 case BFD_RELOC_LO16:
9805 /* When handling an embedded PIC switch statement, we can wind
9806 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
9809 if (value + 0x8000 > 0xffff)
9810 as_bad_where (fixP->fx_file, fixP->fx_line,
9811 _("relocation overflow"));
9812 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9813 if (target_big_endian)
9815 md_number_to_chars (buf, value, 2);
9819 case BFD_RELOC_16_PCREL_S2:
9821 * We need to save the bits in the instruction since fixup_segment()
9822 * might be deleting the relocation entry (i.e., a branch within
9823 * the current segment).
9825 if ((value & 0x3) != 0)
9826 as_bad_where (fixP->fx_file, fixP->fx_line,
9827 _("Branch to odd address (%lx)"), (long) value);
9829 if (!fixP->fx_done && value != 0)
9831 /* If 'value' is zero, the remaining reloc code won't actually
9832 do the store, so it must be done here. This is probably
9835 value -= fixP->fx_frag->fr_address + fixP->fx_where;
9837 value = (offsetT) value >> 2;
9839 /* update old instruction data */
9840 buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal);
9841 if (target_big_endian)
9842 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
9844 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
9846 if (value + 0x8000 <= 0xffff)
9847 insn |= value & 0xffff;
9850 /* The branch offset is too large. If this is an
9851 unconditional branch, and we are not generating PIC code,
9852 we can convert it to an absolute jump instruction. */
9853 if (mips_pic == NO_PIC
9855 && fixP->fx_frag->fr_address >= text_section->vma
9856 && (fixP->fx_frag->fr_address
9857 < text_section->vma + text_section->_raw_size)
9858 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
9859 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
9860 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
9862 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
9863 insn = 0x0c000000; /* jal */
9865 insn = 0x08000000; /* j */
9866 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
9868 fixP->fx_addsy = section_symbol (text_section);
9869 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
9873 /* FIXME. It would be possible in principle to handle
9874 conditional branches which overflow. They could be
9875 transformed into a branch around a jump. This would
9876 require setting up variant frags for each different
9877 branch type. The native MIPS assembler attempts to
9878 handle these cases, but it appears to do it
9880 as_bad_where (fixP->fx_file, fixP->fx_line,
9881 _("Branch out of range"));
9885 md_number_to_chars ((char *) buf, (valueT) insn, 4);
9888 case BFD_RELOC_VTABLE_INHERIT:
9891 && !S_IS_DEFINED (fixP->fx_addsy)
9892 && !S_IS_WEAK (fixP->fx_addsy))
9893 S_SET_WEAK (fixP->fx_addsy);
9896 case BFD_RELOC_VTABLE_ENTRY:
9912 const struct mips_opcode *p;
9913 int treg, sreg, dreg, shamt;
9918 for (i = 0; i < NUMOPCODES; ++i)
9920 p = &mips_opcodes[i];
9921 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
9923 printf ("%08lx %s\t", oc, p->name);
9924 treg = (oc >> 16) & 0x1f;
9925 sreg = (oc >> 21) & 0x1f;
9926 dreg = (oc >> 11) & 0x1f;
9927 shamt = (oc >> 6) & 0x1f;
9929 for (args = p->args;; ++args)
9940 printf ("%c", *args);
9944 assert (treg == sreg);
9945 printf ("$%d,$%d", treg, sreg);
9950 printf ("$%d", dreg);
9955 printf ("$%d", treg);
9959 printf ("0x%x", treg);
9964 printf ("$%d", sreg);
9968 printf ("0x%08lx", oc & 0x1ffffff);
9980 printf ("$%d", shamt);
9991 printf (_("%08lx UNDEFINED\n"), oc);
10002 name = input_line_pointer;
10003 c = get_symbol_end ();
10004 p = (symbolS *) symbol_find_or_make (name);
10005 *input_line_pointer = c;
10009 /* Align the current frag to a given power of two. The MIPS assembler
10010 also automatically adjusts any preceding label. */
10013 mips_align (to, fill, label)
10018 mips_emit_delays (false);
10019 frag_align (to, fill, 0);
10020 record_alignment (now_seg, to);
10023 assert (S_GET_SEGMENT (label) == now_seg);
10024 symbol_set_frag (label, frag_now);
10025 S_SET_VALUE (label, (valueT) frag_now_fix ());
10029 /* Align to a given power of two. .align 0 turns off the automatic
10030 alignment used by the data creating pseudo-ops. */
10034 int x ATTRIBUTE_UNUSED;
10037 register long temp_fill;
10038 long max_alignment = 15;
10042 o Note that the assembler pulls down any immediately preceeding label
10043 to the aligned address.
10044 o It's not documented but auto alignment is reinstated by
10045 a .align pseudo instruction.
10046 o Note also that after auto alignment is turned off the mips assembler
10047 issues an error on attempt to assemble an improperly aligned data item.
10052 temp = get_absolute_expression ();
10053 if (temp > max_alignment)
10054 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
10057 as_warn (_("Alignment negative: 0 assumed."));
10060 if (*input_line_pointer == ',')
10062 input_line_pointer++;
10063 temp_fill = get_absolute_expression ();
10070 mips_align (temp, (int) temp_fill,
10071 insn_labels != NULL ? insn_labels->label : NULL);
10078 demand_empty_rest_of_line ();
10082 mips_flush_pending_output ()
10084 mips_emit_delays (false);
10085 mips_clear_insn_labels ();
10094 /* When generating embedded PIC code, we only use the .text, .lit8,
10095 .sdata and .sbss sections. We change the .data and .rdata
10096 pseudo-ops to use .sdata. */
10097 if (mips_pic == EMBEDDED_PIC
10098 && (sec == 'd' || sec == 'r'))
10102 /* The ELF backend needs to know that we are changing sections, so
10103 that .previous works correctly. We could do something like check
10104 for a obj_section_change_hook macro, but that might be confusing
10105 as it would not be appropriate to use it in the section changing
10106 functions in read.c, since obj-elf.c intercepts those. FIXME:
10107 This should be cleaner, somehow. */
10108 obj_elf_section_change_hook ();
10111 mips_emit_delays (false);
10121 subseg_set (bss_section, (subsegT) get_absolute_expression ());
10122 demand_empty_rest_of_line ();
10126 if (USE_GLOBAL_POINTER_OPT)
10128 seg = subseg_new (RDATA_SECTION_NAME,
10129 (subsegT) get_absolute_expression ());
10130 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
10132 bfd_set_section_flags (stdoutput, seg,
10138 if (strcmp (TARGET_OS, "elf") != 0)
10139 record_alignment (seg, 4);
10141 demand_empty_rest_of_line ();
10145 as_bad (_("No read only data section in this object file format"));
10146 demand_empty_rest_of_line ();
10152 if (USE_GLOBAL_POINTER_OPT)
10154 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
10155 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
10157 bfd_set_section_flags (stdoutput, seg,
10158 SEC_ALLOC | SEC_LOAD | SEC_RELOC
10160 if (strcmp (TARGET_OS, "elf") != 0)
10161 record_alignment (seg, 4);
10163 demand_empty_rest_of_line ();
10168 as_bad (_("Global pointers not supported; recompile -G 0"));
10169 demand_empty_rest_of_line ();
10178 mips_enable_auto_align ()
10189 label = insn_labels != NULL ? insn_labels->label : NULL;
10190 mips_emit_delays (false);
10191 if (log_size > 0 && auto_align)
10192 mips_align (log_size, 0, label);
10193 mips_clear_insn_labels ();
10194 cons (1 << log_size);
10198 s_float_cons (type)
10203 label = insn_labels != NULL ? insn_labels->label : NULL;
10205 mips_emit_delays (false);
10210 mips_align (3, 0, label);
10212 mips_align (2, 0, label);
10215 mips_clear_insn_labels ();
10220 /* Handle .globl. We need to override it because on Irix 5 you are
10223 where foo is an undefined symbol, to mean that foo should be
10224 considered to be the address of a function. */
10228 int x ATTRIBUTE_UNUSED;
10235 name = input_line_pointer;
10236 c = get_symbol_end ();
10237 symbolP = symbol_find_or_make (name);
10238 *input_line_pointer = c;
10239 SKIP_WHITESPACE ();
10241 /* On Irix 5, every global symbol that is not explicitly labelled as
10242 being a function is apparently labelled as being an object. */
10245 if (! is_end_of_line[(unsigned char) *input_line_pointer])
10250 secname = input_line_pointer;
10251 c = get_symbol_end ();
10252 sec = bfd_get_section_by_name (stdoutput, secname);
10254 as_bad (_("%s: no such section"), secname);
10255 *input_line_pointer = c;
10257 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
10258 flag = BSF_FUNCTION;
10261 symbol_get_bfdsym (symbolP)->flags |= flag;
10263 S_SET_EXTERNAL (symbolP);
10264 demand_empty_rest_of_line ();
10269 int x ATTRIBUTE_UNUSED;
10274 opt = input_line_pointer;
10275 c = get_symbol_end ();
10279 /* FIXME: What does this mean? */
10281 else if (strncmp (opt, "pic", 3) == 0)
10285 i = atoi (opt + 3);
10289 mips_pic = SVR4_PIC;
10291 as_bad (_(".option pic%d not supported"), i);
10293 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
10295 if (g_switch_seen && g_switch_value != 0)
10296 as_warn (_("-G may not be used with SVR4 PIC code"));
10297 g_switch_value = 0;
10298 bfd_set_gp_size (stdoutput, 0);
10302 as_warn (_("Unrecognized option \"%s\""), opt);
10304 *input_line_pointer = c;
10305 demand_empty_rest_of_line ();
10308 /* This structure is used to hold a stack of .set values. */
10310 struct mips_option_stack
10312 struct mips_option_stack *next;
10313 struct mips_set_options options;
10316 static struct mips_option_stack *mips_opts_stack;
10318 /* Handle the .set pseudo-op. */
10322 int x ATTRIBUTE_UNUSED;
10324 char *name = input_line_pointer, ch;
10326 while (!is_end_of_line[(unsigned char) *input_line_pointer])
10327 input_line_pointer++;
10328 ch = *input_line_pointer;
10329 *input_line_pointer = '\0';
10331 if (strcmp (name, "reorder") == 0)
10333 if (mips_opts.noreorder && prev_nop_frag != NULL)
10335 /* If we still have pending nops, we can discard them. The
10336 usual nop handling will insert any that are still
10338 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
10339 * (mips_opts.mips16 ? 2 : 4));
10340 prev_nop_frag = NULL;
10342 mips_opts.noreorder = 0;
10344 else if (strcmp (name, "noreorder") == 0)
10346 mips_emit_delays (true);
10347 mips_opts.noreorder = 1;
10348 mips_any_noreorder = 1;
10350 else if (strcmp (name, "at") == 0)
10352 mips_opts.noat = 0;
10354 else if (strcmp (name, "noat") == 0)
10356 mips_opts.noat = 1;
10358 else if (strcmp (name, "macro") == 0)
10360 mips_opts.warn_about_macros = 0;
10362 else if (strcmp (name, "nomacro") == 0)
10364 if (mips_opts.noreorder == 0)
10365 as_bad (_("`noreorder' must be set before `nomacro'"));
10366 mips_opts.warn_about_macros = 1;
10368 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
10370 mips_opts.nomove = 0;
10372 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
10374 mips_opts.nomove = 1;
10376 else if (strcmp (name, "bopt") == 0)
10378 mips_opts.nobopt = 0;
10380 else if (strcmp (name, "nobopt") == 0)
10382 mips_opts.nobopt = 1;
10384 else if (strcmp (name, "mips16") == 0
10385 || strcmp (name, "MIPS-16") == 0)
10386 mips_opts.mips16 = 1;
10387 else if (strcmp (name, "nomips16") == 0
10388 || strcmp (name, "noMIPS-16") == 0)
10389 mips_opts.mips16 = 0;
10390 else if (strncmp (name, "mips", 4) == 0)
10394 /* Permit the user to change the ISA on the fly. Needless to
10395 say, misuse can cause serious problems. */
10396 isa = atoi (name + 4);
10399 case 0: mips_opts.isa = file_mips_isa; break;
10400 case 1: mips_opts.isa = ISA_MIPS1; break;
10401 case 2: mips_opts.isa = ISA_MIPS2; break;
10402 case 3: mips_opts.isa = ISA_MIPS3; break;
10403 case 5: mips_opts.isa = ISA_MIPS5; break;
10404 case 4: mips_opts.isa = ISA_MIPS4; break;
10405 case 32: mips_opts.isa = ISA_MIPS32; break;
10406 case 64: mips_opts.isa = ISA_MIPS64; break;
10407 default: as_bad (_("unknown ISA level")); break;
10410 else if (strcmp (name, "autoextend") == 0)
10411 mips_opts.noautoextend = 0;
10412 else if (strcmp (name, "noautoextend") == 0)
10413 mips_opts.noautoextend = 1;
10414 else if (strcmp (name, "push") == 0)
10416 struct mips_option_stack *s;
10418 s = (struct mips_option_stack *) xmalloc (sizeof *s);
10419 s->next = mips_opts_stack;
10420 s->options = mips_opts;
10421 mips_opts_stack = s;
10423 else if (strcmp (name, "pop") == 0)
10425 struct mips_option_stack *s;
10427 s = mips_opts_stack;
10429 as_bad (_(".set pop with no .set push"));
10432 /* If we're changing the reorder mode we need to handle
10433 delay slots correctly. */
10434 if (s->options.noreorder && ! mips_opts.noreorder)
10435 mips_emit_delays (true);
10436 else if (! s->options.noreorder && mips_opts.noreorder)
10438 if (prev_nop_frag != NULL)
10440 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
10441 * (mips_opts.mips16 ? 2 : 4));
10442 prev_nop_frag = NULL;
10446 mips_opts = s->options;
10447 mips_opts_stack = s->next;
10453 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
10455 *input_line_pointer = ch;
10456 demand_empty_rest_of_line ();
10459 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
10460 .option pic2. It means to generate SVR4 PIC calls. */
10463 s_abicalls (ignore)
10464 int ignore ATTRIBUTE_UNUSED;
10466 mips_pic = SVR4_PIC;
10467 if (USE_GLOBAL_POINTER_OPT)
10469 if (g_switch_seen && g_switch_value != 0)
10470 as_warn (_("-G may not be used with SVR4 PIC code"));
10471 g_switch_value = 0;
10473 bfd_set_gp_size (stdoutput, 0);
10474 demand_empty_rest_of_line ();
10477 /* Handle the .cpload pseudo-op. This is used when generating SVR4
10478 PIC code. It sets the $gp register for the function based on the
10479 function address, which is in the register named in the argument.
10480 This uses a relocation against _gp_disp, which is handled specially
10481 by the linker. The result is:
10482 lui $gp,%hi(_gp_disp)
10483 addiu $gp,$gp,%lo(_gp_disp)
10484 addu $gp,$gp,.cpload argument
10485 The .cpload argument is normally $25 == $t9. */
10489 int ignore ATTRIBUTE_UNUSED;
10494 /* If we are not generating SVR4 PIC code, .cpload is ignored. */
10495 if (mips_pic != SVR4_PIC)
10501 /* .cpload should be a in .set noreorder section. */
10502 if (mips_opts.noreorder == 0)
10503 as_warn (_(".cpload not in noreorder section"));
10505 ex.X_op = O_symbol;
10506 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
10507 ex.X_op_symbol = NULL;
10508 ex.X_add_number = 0;
10510 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
10511 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
10513 macro_build_lui ((char *) NULL, &icnt, &ex, GP);
10514 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP,
10515 (int) BFD_RELOC_LO16);
10517 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
10518 GP, GP, tc_get_register (0));
10520 demand_empty_rest_of_line ();
10523 /* Handle the .cprestore pseudo-op. This stores $gp into a given
10524 offset from $sp. The offset is remembered, and after making a PIC
10525 call $gp is restored from that location. */
10528 s_cprestore (ignore)
10529 int ignore ATTRIBUTE_UNUSED;
10534 /* If we are not generating SVR4 PIC code, .cprestore is ignored. */
10535 if (mips_pic != SVR4_PIC)
10541 mips_cprestore_offset = get_absolute_expression ();
10543 ex.X_op = O_constant;
10544 ex.X_add_symbol = NULL;
10545 ex.X_op_symbol = NULL;
10546 ex.X_add_number = mips_cprestore_offset;
10548 macro_build ((char *) NULL, &icnt, &ex,
10549 ((bfd_arch_bits_per_address (stdoutput) == 32
10550 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
10552 "t,o(b)", GP, (int) BFD_RELOC_LO16, SP);
10554 demand_empty_rest_of_line ();
10557 /* Handle the .gpword pseudo-op. This is used when generating PIC
10558 code. It generates a 32 bit GP relative reloc. */
10562 int ignore ATTRIBUTE_UNUSED;
10568 /* When not generating PIC code, this is treated as .word. */
10569 if (mips_pic != SVR4_PIC)
10575 label = insn_labels != NULL ? insn_labels->label : NULL;
10576 mips_emit_delays (true);
10578 mips_align (2, 0, label);
10579 mips_clear_insn_labels ();
10583 if (ex.X_op != O_symbol || ex.X_add_number != 0)
10585 as_bad (_("Unsupported use of .gpword"));
10586 ignore_rest_of_line ();
10590 md_number_to_chars (p, (valueT) 0, 4);
10591 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0,
10592 BFD_RELOC_MIPS_GPREL32);
10594 demand_empty_rest_of_line ();
10597 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
10598 tables in SVR4 PIC code. */
10602 int ignore ATTRIBUTE_UNUSED;
10607 /* This is ignored when not generating SVR4 PIC code. */
10608 if (mips_pic != SVR4_PIC)
10614 /* Add $gp to the register named as an argument. */
10615 reg = tc_get_register (0);
10616 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
10617 ((bfd_arch_bits_per_address (stdoutput) == 32
10618 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
10619 ? "addu" : "daddu"),
10620 "d,v,t", reg, reg, GP);
10622 demand_empty_rest_of_line ();
10625 /* Handle the .insn pseudo-op. This marks instruction labels in
10626 mips16 mode. This permits the linker to handle them specially,
10627 such as generating jalx instructions when needed. We also make
10628 them odd for the duration of the assembly, in order to generate the
10629 right sort of code. We will make them even in the adjust_symtab
10630 routine, while leaving them marked. This is convenient for the
10631 debugger and the disassembler. The linker knows to make them odd
10636 int ignore ATTRIBUTE_UNUSED;
10638 if (mips_opts.mips16)
10639 mips16_mark_labels ();
10641 demand_empty_rest_of_line ();
10644 /* Handle a .stabn directive. We need these in order to mark a label
10645 as being a mips16 text label correctly. Sometimes the compiler
10646 will emit a label, followed by a .stabn, and then switch sections.
10647 If the label and .stabn are in mips16 mode, then the label is
10648 really a mips16 text label. */
10654 if (type == 'n' && mips_opts.mips16)
10655 mips16_mark_labels ();
10660 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
10664 s_mips_weakext (ignore)
10665 int ignore ATTRIBUTE_UNUSED;
10672 name = input_line_pointer;
10673 c = get_symbol_end ();
10674 symbolP = symbol_find_or_make (name);
10675 S_SET_WEAK (symbolP);
10676 *input_line_pointer = c;
10678 SKIP_WHITESPACE ();
10680 if (! is_end_of_line[(unsigned char) *input_line_pointer])
10682 if (S_IS_DEFINED (symbolP))
10684 as_bad ("Ignoring attempt to redefine symbol `%s'.",
10685 S_GET_NAME (symbolP));
10686 ignore_rest_of_line ();
10690 if (*input_line_pointer == ',')
10692 ++input_line_pointer;
10693 SKIP_WHITESPACE ();
10697 if (exp.X_op != O_symbol)
10699 as_bad ("bad .weakext directive");
10700 ignore_rest_of_line();
10703 symbol_set_value_expression (symbolP, &exp);
10706 demand_empty_rest_of_line ();
10709 /* Parse a register string into a number. Called from the ECOFF code
10710 to parse .frame. The argument is non-zero if this is the frame
10711 register, so that we can record it in mips_frame_reg. */
10714 tc_get_register (frame)
10719 SKIP_WHITESPACE ();
10720 if (*input_line_pointer++ != '$')
10722 as_warn (_("expected `$'"));
10725 else if (isdigit ((unsigned char) *input_line_pointer))
10727 reg = get_absolute_expression ();
10728 if (reg < 0 || reg >= 32)
10730 as_warn (_("Bad register number"));
10736 if (strncmp (input_line_pointer, "fp", 2) == 0)
10738 else if (strncmp (input_line_pointer, "sp", 2) == 0)
10740 else if (strncmp (input_line_pointer, "gp", 2) == 0)
10742 else if (strncmp (input_line_pointer, "at", 2) == 0)
10746 as_warn (_("Unrecognized register name"));
10749 input_line_pointer += 2;
10752 mips_frame_reg = reg != 0 ? reg : SP;
10757 md_section_align (seg, addr)
10761 int align = bfd_get_section_alignment (stdoutput, seg);
10764 /* We don't need to align ELF sections to the full alignment.
10765 However, Irix 5 may prefer that we align them at least to a 16
10766 byte boundary. We don't bother to align the sections if we are
10767 targeted for an embedded system. */
10768 if (strcmp (TARGET_OS, "elf") == 0)
10774 return ((addr + (1 << align) - 1) & (-1 << align));
10777 /* Utility routine, called from above as well. If called while the
10778 input file is still being read, it's only an approximation. (For
10779 example, a symbol may later become defined which appeared to be
10780 undefined earlier.) */
10783 nopic_need_relax (sym, before_relaxing)
10785 int before_relaxing;
10790 if (USE_GLOBAL_POINTER_OPT)
10792 const char *symname;
10795 /* Find out whether this symbol can be referenced off the GP
10796 register. It can be if it is smaller than the -G size or if
10797 it is in the .sdata or .sbss section. Certain symbols can
10798 not be referenced off the GP, although it appears as though
10800 symname = S_GET_NAME (sym);
10801 if (symname != (const char *) NULL
10802 && (strcmp (symname, "eprol") == 0
10803 || strcmp (symname, "etext") == 0
10804 || strcmp (symname, "_gp") == 0
10805 || strcmp (symname, "edata") == 0
10806 || strcmp (symname, "_fbss") == 0
10807 || strcmp (symname, "_fdata") == 0
10808 || strcmp (symname, "_ftext") == 0
10809 || strcmp (symname, "end") == 0
10810 || strcmp (symname, "_gp_disp") == 0))
10812 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
10814 #ifndef NO_ECOFF_DEBUGGING
10815 || (symbol_get_obj (sym)->ecoff_extern_size != 0
10816 && (symbol_get_obj (sym)->ecoff_extern_size
10817 <= g_switch_value))
10819 /* We must defer this decision until after the whole
10820 file has been read, since there might be a .extern
10821 after the first use of this symbol. */
10822 || (before_relaxing
10823 #ifndef NO_ECOFF_DEBUGGING
10824 && symbol_get_obj (sym)->ecoff_extern_size == 0
10826 && S_GET_VALUE (sym) == 0)
10827 || (S_GET_VALUE (sym) != 0
10828 && S_GET_VALUE (sym) <= g_switch_value)))
10832 const char *segname;
10834 segname = segment_name (S_GET_SEGMENT (sym));
10835 assert (strcmp (segname, ".lit8") != 0
10836 && strcmp (segname, ".lit4") != 0);
10837 change = (strcmp (segname, ".sdata") != 0
10838 && strcmp (segname, ".sbss") != 0
10839 && strncmp (segname, ".sdata.", 7) != 0
10840 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
10845 /* We are not optimizing for the GP register. */
10849 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
10850 extended opcode. SEC is the section the frag is in. */
10853 mips16_extended_frag (fragp, sec, stretch)
10859 register const struct mips16_immed_operand *op;
10861 int mintiny, maxtiny;
10865 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
10867 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
10870 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
10871 op = mips16_immed_operands;
10872 while (op->type != type)
10875 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
10880 if (type == '<' || type == '>' || type == '[' || type == ']')
10883 maxtiny = 1 << op->nbits;
10888 maxtiny = (1 << op->nbits) - 1;
10893 mintiny = - (1 << (op->nbits - 1));
10894 maxtiny = (1 << (op->nbits - 1)) - 1;
10897 sym_frag = symbol_get_frag (fragp->fr_symbol);
10898 val = S_GET_VALUE (fragp->fr_symbol);
10899 symsec = S_GET_SEGMENT (fragp->fr_symbol);
10905 /* We won't have the section when we are called from
10906 mips_relax_frag. However, we will always have been called
10907 from md_estimate_size_before_relax first. If this is a
10908 branch to a different section, we mark it as such. If SEC is
10909 NULL, and the frag is not marked, then it must be a branch to
10910 the same section. */
10913 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
10918 /* Must have been called from md_estimate_size_before_relax. */
10921 fragp->fr_subtype =
10922 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
10924 /* FIXME: We should support this, and let the linker
10925 catch branches and loads that are out of range. */
10926 as_bad_where (fragp->fr_file, fragp->fr_line,
10927 _("unsupported PC relative reference to different section"));
10931 if (fragp != sym_frag && sym_frag->fr_address == 0)
10932 /* Assume non-extended on the first relaxation pass.
10933 The address we have calculated will be bogus if this is
10934 a forward branch to another frag, as the forward frag
10935 will have fr_address == 0. */
10939 /* In this case, we know for sure that the symbol fragment is in
10940 the same section. If the relax_marker of the symbol fragment
10941 differs from the relax_marker of this fragment, we have not
10942 yet adjusted the symbol fragment fr_address. We want to add
10943 in STRETCH in order to get a better estimate of the address.
10944 This particularly matters because of the shift bits. */
10946 && sym_frag->relax_marker != fragp->relax_marker)
10950 /* Adjust stretch for any alignment frag. Note that if have
10951 been expanding the earlier code, the symbol may be
10952 defined in what appears to be an earlier frag. FIXME:
10953 This doesn't handle the fr_subtype field, which specifies
10954 a maximum number of bytes to skip when doing an
10956 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
10958 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
10961 stretch = - ((- stretch)
10962 & ~ ((1 << (int) f->fr_offset) - 1));
10964 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
10973 addr = fragp->fr_address + fragp->fr_fix;
10975 /* The base address rules are complicated. The base address of
10976 a branch is the following instruction. The base address of a
10977 PC relative load or add is the instruction itself, but if it
10978 is in a delay slot (in which case it can not be extended) use
10979 the address of the instruction whose delay slot it is in. */
10980 if (type == 'p' || type == 'q')
10984 /* If we are currently assuming that this frag should be
10985 extended, then, the current address is two bytes
10987 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
10990 /* Ignore the low bit in the target, since it will be set
10991 for a text label. */
10992 if ((val & 1) != 0)
10995 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
10997 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
11000 val -= addr & ~ ((1 << op->shift) - 1);
11002 /* Branch offsets have an implicit 0 in the lowest bit. */
11003 if (type == 'p' || type == 'q')
11006 /* If any of the shifted bits are set, we must use an extended
11007 opcode. If the address depends on the size of this
11008 instruction, this can lead to a loop, so we arrange to always
11009 use an extended opcode. We only check this when we are in
11010 the main relaxation loop, when SEC is NULL. */
11011 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
11013 fragp->fr_subtype =
11014 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
11018 /* If we are about to mark a frag as extended because the value
11019 is precisely maxtiny + 1, then there is a chance of an
11020 infinite loop as in the following code:
11025 In this case when the la is extended, foo is 0x3fc bytes
11026 away, so the la can be shrunk, but then foo is 0x400 away, so
11027 the la must be extended. To avoid this loop, we mark the
11028 frag as extended if it was small, and is about to become
11029 extended with a value of maxtiny + 1. */
11030 if (val == ((maxtiny + 1) << op->shift)
11031 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
11034 fragp->fr_subtype =
11035 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
11039 else if (symsec != absolute_section && sec != NULL)
11040 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
11042 if ((val & ((1 << op->shift) - 1)) != 0
11043 || val < (mintiny << op->shift)
11044 || val > (maxtiny << op->shift))
11050 /* Estimate the size of a frag before relaxing. Unless this is the
11051 mips16, we are not really relaxing here, and the final size is
11052 encoded in the subtype information. For the mips16, we have to
11053 decide whether we are using an extended opcode or not. */
11056 md_estimate_size_before_relax (fragp, segtype)
11061 boolean linkonce = false;
11063 if (RELAX_MIPS16_P (fragp->fr_subtype))
11065 if (mips16_extended_frag (fragp, segtype, 0))
11067 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
11072 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
11077 if (mips_pic == NO_PIC)
11079 change = nopic_need_relax (fragp->fr_symbol, 0);
11081 else if (mips_pic == SVR4_PIC)
11086 sym = fragp->fr_symbol;
11088 /* Handle the case of a symbol equated to another symbol. */
11089 while (symbol_equated_p (sym)
11090 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
11094 /* It's possible to get a loop here in a badly written
11096 n = symbol_get_value_expression (sym)->X_add_symbol;
11102 symsec = S_GET_SEGMENT (sym);
11104 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
11105 if (symsec != segtype && ! S_IS_LOCAL (sym))
11107 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
11111 /* The GNU toolchain uses an extension for ELF: a section
11112 beginning with the magic string .gnu.linkonce is a linkonce
11114 if (strncmp (segment_name (symsec), ".gnu.linkonce",
11115 sizeof ".gnu.linkonce" - 1) == 0)
11119 /* This must duplicate the test in adjust_reloc_syms. */
11120 change = (symsec != &bfd_und_section
11121 && symsec != &bfd_abs_section
11122 && ! bfd_is_com_section (symsec)
11125 /* A global or weak symbol is treated as external. */
11126 && ! (S_IS_EXTERN (sym) || S_IS_WEAK (sym))
11135 /* Record the offset to the first reloc in the fr_opcode field.
11136 This lets md_convert_frag and tc_gen_reloc know that the code
11137 must be expanded. */
11138 fragp->fr_opcode = (fragp->fr_literal
11140 - RELAX_OLD (fragp->fr_subtype)
11141 + RELAX_RELOC1 (fragp->fr_subtype));
11142 /* FIXME: This really needs as_warn_where. */
11143 if (RELAX_WARN (fragp->fr_subtype))
11144 as_warn (_("AT used after \".set noat\" or macro used after \".set nomacro\""));
11150 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
11153 /* This is called to see whether a reloc against a defined symbol
11154 should be converted into a reloc against a section. Don't adjust
11155 MIPS16 jump relocations, so we don't have to worry about the format
11156 of the offset in the .o file. Don't adjust relocations against
11157 mips16 symbols, so that the linker can find them if it needs to set
11161 mips_fix_adjustable (fixp)
11165 /* Prevent all adjustments to global symbols. */
11166 if (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy))
11169 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
11171 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11172 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11174 if (fixp->fx_addsy == NULL)
11177 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
11178 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
11179 && fixp->fx_subsy == NULL)
11185 /* Translate internal representation of relocation info to BFD target
11189 tc_gen_reloc (section, fixp)
11190 asection *section ATTRIBUTE_UNUSED;
11193 static arelent *retval[4];
11195 bfd_reloc_code_real_type code;
11197 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
11200 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11201 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11202 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11204 if (mips_pic == EMBEDDED_PIC
11205 && SWITCH_TABLE (fixp))
11207 /* For a switch table entry we use a special reloc. The addend
11208 is actually the difference between the reloc address and the
11210 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
11211 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
11212 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
11213 fixp->fx_r_type = BFD_RELOC_GPREL32;
11215 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11216 reloc->addend = fixp->fx_addnumber;
11217 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
11219 /* We use a special addend for an internal RELLO reloc. */
11220 if (symbol_section_p (fixp->fx_addsy))
11221 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
11223 reloc->addend = fixp->fx_addnumber + reloc->address;
11225 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
11227 assert (fixp->fx_next != NULL
11228 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
11229 /* We use a special addend for an internal RELHI reloc. The
11230 reloc is relative to the RELLO; adjust the addend
11232 if (symbol_section_p (fixp->fx_addsy))
11233 reloc->addend = (fixp->fx_next->fx_frag->fr_address
11234 + fixp->fx_next->fx_where
11235 - S_GET_VALUE (fixp->fx_subsy));
11237 reloc->addend = (fixp->fx_addnumber
11238 + fixp->fx_next->fx_frag->fr_address
11239 + fixp->fx_next->fx_where);
11243 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
11244 /* A gruesome hack which is a result of the gruesome gas reloc
11246 reloc->addend = reloc->address;
11248 reloc->addend = -reloc->address;
11251 /* If this is a variant frag, we may need to adjust the existing
11252 reloc and generate a new one. */
11253 if (fixp->fx_frag->fr_opcode != NULL
11254 && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
11255 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
11256 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
11257 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
11258 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
11259 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
11260 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16))
11264 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
11266 /* If this is not the last reloc in this frag, then we have two
11267 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
11268 CALL_HI16/CALL_LO16, both of which are being replaced. Let
11269 the second one handle all of them. */
11270 if (fixp->fx_next != NULL
11271 && fixp->fx_frag == fixp->fx_next->fx_frag)
11273 assert ((fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
11274 && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL)
11275 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
11276 && (fixp->fx_next->fx_r_type
11277 == BFD_RELOC_MIPS_GOT_LO16))
11278 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
11279 && (fixp->fx_next->fx_r_type
11280 == BFD_RELOC_MIPS_CALL_LO16)));
11285 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
11286 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11287 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
11289 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11290 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11291 reloc2->address = (reloc->address
11292 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
11293 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
11294 reloc2->addend = fixp->fx_addnumber;
11295 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
11296 assert (reloc2->howto != NULL);
11298 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
11302 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
11305 reloc3->address += 4;
11308 if (mips_pic == NO_PIC)
11310 assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL);
11311 fixp->fx_r_type = BFD_RELOC_HI16_S;
11313 else if (mips_pic == SVR4_PIC)
11315 switch (fixp->fx_r_type)
11319 case BFD_RELOC_MIPS_GOT16:
11321 case BFD_RELOC_MIPS_CALL16:
11322 case BFD_RELOC_MIPS_GOT_LO16:
11323 case BFD_RELOC_MIPS_CALL_LO16:
11324 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
11332 /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry
11333 to be used in the relocation's section offset. */
11334 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11336 reloc->address = reloc->addend;
11340 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
11341 fixup_segment converted a non-PC relative reloc into a PC
11342 relative reloc. In such a case, we need to convert the reloc
11344 code = fixp->fx_r_type;
11345 if (fixp->fx_pcrel)
11350 code = BFD_RELOC_8_PCREL;
11353 code = BFD_RELOC_16_PCREL;
11356 code = BFD_RELOC_32_PCREL;
11359 code = BFD_RELOC_64_PCREL;
11361 case BFD_RELOC_8_PCREL:
11362 case BFD_RELOC_16_PCREL:
11363 case BFD_RELOC_32_PCREL:
11364 case BFD_RELOC_64_PCREL:
11365 case BFD_RELOC_16_PCREL_S2:
11366 case BFD_RELOC_PCREL_HI16_S:
11367 case BFD_RELOC_PCREL_LO16:
11370 as_bad_where (fixp->fx_file, fixp->fx_line,
11371 _("Cannot make %s relocation PC relative"),
11372 bfd_get_reloc_code_name (code));
11376 /* To support a PC relative reloc when generating embedded PIC code
11377 for ECOFF, we use a Cygnus extension. We check for that here to
11378 make sure that we don't let such a reloc escape normally. */
11379 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
11380 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11381 && code == BFD_RELOC_16_PCREL_S2
11382 && mips_pic != EMBEDDED_PIC)
11383 reloc->howto = NULL;
11385 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
11387 if (reloc->howto == NULL)
11389 as_bad_where (fixp->fx_file, fixp->fx_line,
11390 _("Can not represent %s relocation in this object file format"),
11391 bfd_get_reloc_code_name (code));
11398 /* Relax a machine dependent frag. This returns the amount by which
11399 the current size of the frag should change. */
11402 mips_relax_frag (fragp, stretch)
11406 if (! RELAX_MIPS16_P (fragp->fr_subtype))
11409 if (mips16_extended_frag (fragp, (asection *) NULL, stretch))
11411 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
11413 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
11418 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
11420 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
11427 /* Convert a machine dependent frag. */
11430 md_convert_frag (abfd, asec, fragp)
11431 bfd *abfd ATTRIBUTE_UNUSED;
11438 if (RELAX_MIPS16_P (fragp->fr_subtype))
11441 register const struct mips16_immed_operand *op;
11442 boolean small, ext;
11445 unsigned long insn;
11446 boolean use_extend;
11447 unsigned short extend;
11449 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
11450 op = mips16_immed_operands;
11451 while (op->type != type)
11454 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
11465 resolve_symbol_value (fragp->fr_symbol);
11466 val = S_GET_VALUE (fragp->fr_symbol);
11471 addr = fragp->fr_address + fragp->fr_fix;
11473 /* The rules for the base address of a PC relative reloc are
11474 complicated; see mips16_extended_frag. */
11475 if (type == 'p' || type == 'q')
11480 /* Ignore the low bit in the target, since it will be
11481 set for a text label. */
11482 if ((val & 1) != 0)
11485 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
11487 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
11490 addr &= ~ (addressT) ((1 << op->shift) - 1);
11493 /* Make sure the section winds up with the alignment we have
11496 record_alignment (asec, op->shift);
11500 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
11501 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
11502 as_warn_where (fragp->fr_file, fragp->fr_line,
11503 _("extended instruction in delay slot"));
11505 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
11507 if (target_big_endian)
11508 insn = bfd_getb16 (buf);
11510 insn = bfd_getl16 (buf);
11512 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
11513 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
11514 small, ext, &insn, &use_extend, &extend);
11518 md_number_to_chars (buf, 0xf000 | extend, 2);
11519 fragp->fr_fix += 2;
11523 md_number_to_chars (buf, insn, 2);
11524 fragp->fr_fix += 2;
11529 if (fragp->fr_opcode == NULL)
11532 old = RELAX_OLD (fragp->fr_subtype);
11533 new = RELAX_NEW (fragp->fr_subtype);
11534 fixptr = fragp->fr_literal + fragp->fr_fix;
11537 memcpy (fixptr - old, fixptr, new);
11539 fragp->fr_fix += new - old;
11545 /* This function is called after the relocs have been generated.
11546 We've been storing mips16 text labels as odd. Here we convert them
11547 back to even for the convenience of the debugger. */
11550 mips_frob_file_after_relocs ()
11553 unsigned int count, i;
11555 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11558 syms = bfd_get_outsymbols (stdoutput);
11559 count = bfd_get_symcount (stdoutput);
11560 for (i = 0; i < count; i++, syms++)
11562 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
11563 && ((*syms)->value & 1) != 0)
11565 (*syms)->value &= ~1;
11566 /* If the symbol has an odd size, it was probably computed
11567 incorrectly, so adjust that as well. */
11568 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
11569 ++elf_symbol (*syms)->internal_elf_sym.st_size;
11576 /* This function is called whenever a label is defined. It is used
11577 when handling branch delays; if a branch has a label, we assume we
11578 can not move it. */
11581 mips_define_label (sym)
11584 struct insn_label_list *l;
11586 if (free_insn_labels == NULL)
11587 l = (struct insn_label_list *) xmalloc (sizeof *l);
11590 l = free_insn_labels;
11591 free_insn_labels = l->next;
11595 l->next = insn_labels;
11599 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
11601 /* Some special processing for a MIPS ELF file. */
11604 mips_elf_final_processing ()
11606 /* Write out the register information. */
11611 s.ri_gprmask = mips_gprmask;
11612 s.ri_cprmask[0] = mips_cprmask[0];
11613 s.ri_cprmask[1] = mips_cprmask[1];
11614 s.ri_cprmask[2] = mips_cprmask[2];
11615 s.ri_cprmask[3] = mips_cprmask[3];
11616 /* The gp_value field is set by the MIPS ELF backend. */
11618 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
11619 ((Elf32_External_RegInfo *)
11620 mips_regmask_frag));
11624 Elf64_Internal_RegInfo s;
11626 s.ri_gprmask = mips_gprmask;
11628 s.ri_cprmask[0] = mips_cprmask[0];
11629 s.ri_cprmask[1] = mips_cprmask[1];
11630 s.ri_cprmask[2] = mips_cprmask[2];
11631 s.ri_cprmask[3] = mips_cprmask[3];
11632 /* The gp_value field is set by the MIPS ELF backend. */
11634 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
11635 ((Elf64_External_RegInfo *)
11636 mips_regmask_frag));
11639 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
11640 sort of BFD interface for this. */
11641 if (mips_any_noreorder)
11642 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
11643 if (mips_pic != NO_PIC)
11644 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
11646 /* Set the MIPS ELF ABI flags. */
11647 if (mips_abi_string == 0)
11649 else if (strcmp (mips_abi_string, "32") == 0)
11650 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
11651 else if (strcmp (mips_abi_string, "o64") == 0)
11652 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
11653 else if (strcmp (mips_abi_string, "eabi") == 0)
11656 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
11658 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
11661 if (mips_32bitmode)
11662 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
11665 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
11667 typedef struct proc {
11669 unsigned long reg_mask;
11670 unsigned long reg_offset;
11671 unsigned long fpreg_mask;
11672 unsigned long fpreg_offset;
11673 unsigned long frame_offset;
11674 unsigned long frame_reg;
11675 unsigned long pc_reg;
11678 static procS cur_proc;
11679 static procS *cur_proc_ptr;
11680 static int numprocs;
11682 /* Fill in an rs_align_code fragment. */
11685 mips_handle_align (fragp)
11688 if (fragp->fr_type != rs_align_code)
11691 if (mips_opts.mips16)
11693 static const unsigned char be_nop[] = { 0x65, 0x00 };
11694 static const unsigned char le_nop[] = { 0x00, 0x65 };
11699 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
11700 p = fragp->fr_literal + fragp->fr_fix;
11705 fragp->fr_fix += 1;
11708 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
11712 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
11723 /* check for premature end, nesting errors, etc */
11725 as_warn (_("missing `.end' at end of assembly"));
11734 if (*input_line_pointer == '-')
11736 ++input_line_pointer;
11739 if (!isdigit ((unsigned char) *input_line_pointer))
11740 as_bad (_("Expected simple number."));
11741 if (input_line_pointer[0] == '0')
11743 if (input_line_pointer[1] == 'x')
11745 input_line_pointer += 2;
11746 while (isxdigit ((unsigned char) *input_line_pointer))
11749 val |= hex_value (*input_line_pointer++);
11751 return negative ? -val : val;
11755 ++input_line_pointer;
11756 while (isdigit ((unsigned char) *input_line_pointer))
11759 val |= *input_line_pointer++ - '0';
11761 return negative ? -val : val;
11764 if (!isdigit ((unsigned char) *input_line_pointer))
11766 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
11767 *input_line_pointer, *input_line_pointer);
11768 as_warn (_("Invalid number"));
11771 while (isdigit ((unsigned char) *input_line_pointer))
11774 val += *input_line_pointer++ - '0';
11776 return negative ? -val : val;
11779 /* The .file directive; just like the usual .file directive, but there
11780 is an initial number which is the ECOFF file index. */
11784 int x ATTRIBUTE_UNUSED;
11788 line = get_number ();
11792 /* The .end directive. */
11796 int x ATTRIBUTE_UNUSED;
11801 if (!is_end_of_line[(unsigned char) *input_line_pointer])
11804 demand_empty_rest_of_line ();
11809 #ifdef BFD_ASSEMBLER
11810 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
11815 if (now_seg != data_section && now_seg != bss_section)
11822 as_warn (_(".end not in text section"));
11826 as_warn (_(".end directive without a preceding .ent directive."));
11827 demand_empty_rest_of_line ();
11833 assert (S_GET_NAME (p));
11834 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
11835 as_warn (_(".end symbol does not match .ent symbol."));
11838 as_warn (_(".end directive missing or unknown symbol"));
11840 #ifdef MIPS_STABS_ELF
11842 segT saved_seg = now_seg;
11843 subsegT saved_subseg = now_subseg;
11848 dot = frag_now_fix ();
11850 #ifdef md_flush_pending_output
11851 md_flush_pending_output ();
11855 subseg_set (pdr_seg, 0);
11857 /* Write the symbol. */
11858 exp.X_op = O_symbol;
11859 exp.X_add_symbol = p;
11860 exp.X_add_number = 0;
11861 emit_expr (&exp, 4);
11863 fragp = frag_more (7 * 4);
11865 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
11866 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
11867 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
11868 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
11869 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
11870 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
11871 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
11873 subseg_set (saved_seg, saved_subseg);
11877 cur_proc_ptr = NULL;
11880 /* The .aent and .ent directives. */
11890 symbolP = get_symbol ();
11891 if (*input_line_pointer == ',')
11892 input_line_pointer++;
11893 SKIP_WHITESPACE ();
11894 if (isdigit ((unsigned char) *input_line_pointer)
11895 || *input_line_pointer == '-')
11896 number = get_number ();
11898 #ifdef BFD_ASSEMBLER
11899 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
11904 if (now_seg != data_section && now_seg != bss_section)
11911 as_warn (_(".ent or .aent not in text section."));
11913 if (!aent && cur_proc_ptr)
11914 as_warn (_("missing `.end'"));
11918 cur_proc_ptr = &cur_proc;
11919 memset (cur_proc_ptr, '\0', sizeof (procS));
11921 cur_proc_ptr->isym = symbolP;
11923 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
11928 demand_empty_rest_of_line ();
11931 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
11932 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
11933 s_mips_frame is used so that we can set the PDR information correctly.
11934 We can't use the ecoff routines because they make reference to the ecoff
11935 symbol table (in the mdebug section). */
11938 s_mips_frame (ignore)
11939 int ignore ATTRIBUTE_UNUSED;
11941 #ifdef MIPS_STABS_ELF
11945 if (cur_proc_ptr == (procS *) NULL)
11947 as_warn (_(".frame outside of .ent"));
11948 demand_empty_rest_of_line ();
11952 cur_proc_ptr->frame_reg = tc_get_register (1);
11954 SKIP_WHITESPACE ();
11955 if (*input_line_pointer++ != ','
11956 || get_absolute_expression_and_terminator (&val) != ',')
11958 as_warn (_("Bad .frame directive"));
11959 --input_line_pointer;
11960 demand_empty_rest_of_line ();
11964 cur_proc_ptr->frame_offset = val;
11965 cur_proc_ptr->pc_reg = tc_get_register (0);
11967 demand_empty_rest_of_line ();
11970 #endif /* MIPS_STABS_ELF */
11973 /* The .fmask and .mask directives. If the mdebug section is present
11974 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
11975 embedded targets, s_mips_mask is used so that we can set the PDR
11976 information correctly. We can't use the ecoff routines because they
11977 make reference to the ecoff symbol table (in the mdebug section). */
11980 s_mips_mask (reg_type)
11983 #ifdef MIPS_STABS_ELF
11986 if (cur_proc_ptr == (procS *) NULL)
11988 as_warn (_(".mask/.fmask outside of .ent"));
11989 demand_empty_rest_of_line ();
11993 if (get_absolute_expression_and_terminator (&mask) != ',')
11995 as_warn (_("Bad .mask/.fmask directive"));
11996 --input_line_pointer;
11997 demand_empty_rest_of_line ();
12001 off = get_absolute_expression ();
12003 if (reg_type == 'F')
12005 cur_proc_ptr->fpreg_mask = mask;
12006 cur_proc_ptr->fpreg_offset = off;
12010 cur_proc_ptr->reg_mask = mask;
12011 cur_proc_ptr->reg_offset = off;
12014 demand_empty_rest_of_line ();
12016 s_ignore (reg_type);
12017 #endif /* MIPS_STABS_ELF */
12020 /* The .loc directive. */
12031 assert (now_seg == text_section);
12033 lineno = get_number ();
12034 addroff = frag_now_fix ();
12036 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
12037 S_SET_TYPE (symbolP, N_SLINE);
12038 S_SET_OTHER (symbolP, 0);
12039 S_SET_DESC (symbolP, lineno);
12040 symbolP->sy_segment = now_seg;
12044 /* CPU name/ISA/number mapping table.
12046 Entries are grouped by type. The first matching CPU or ISA entry
12047 gets chosen by CPU or ISA, so it should be the 'canonical' name
12048 for that type. Entries after that within the type are sorted
12051 Case is ignored in comparison, so put the canonical entry in the
12052 appropriate case but everything else in lower case to ease eye pain. */
12053 static const struct mips_cpu_info mips_cpu_info_table[] =
12056 { "MIPS1", 1, ISA_MIPS1, CPU_R3000, },
12057 { "mips", 1, ISA_MIPS1, CPU_R3000, },
12060 { "MIPS2", 1, ISA_MIPS2, CPU_R6000, },
12063 { "MIPS3", 1, ISA_MIPS3, CPU_R4000, },
12066 { "MIPS4", 1, ISA_MIPS4, CPU_R8000, },
12069 { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, },
12070 { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, },
12073 { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, },
12074 { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, },
12077 /* XXX for now, MIPS64 -> MIPS3 because of history */
12078 { "MIPS64", 1, ISA_MIPS3, CPU_R4000 }, /* XXX! */
12081 { "MIPS64", 1, ISA_MIPS64, CPU_MIPS64 },
12083 { "mips64isa", 1, ISA_MIPS64, CPU_MIPS64 },
12084 { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, },
12087 { "R2000", 0, ISA_MIPS1, CPU_R2000, },
12088 { "2000", 0, ISA_MIPS1, CPU_R2000, },
12089 { "2k", 0, ISA_MIPS1, CPU_R2000, },
12090 { "r2k", 0, ISA_MIPS1, CPU_R2000, },
12093 { "R3000", 0, ISA_MIPS1, CPU_R3000, },
12094 { "3000", 0, ISA_MIPS1, CPU_R3000, },
12095 { "3k", 0, ISA_MIPS1, CPU_R3000, },
12096 { "r3k", 0, ISA_MIPS1, CPU_R3000, },
12099 { "R3900", 0, ISA_MIPS1, CPU_R3900, },
12100 { "3900", 0, ISA_MIPS1, CPU_R3900, },
12101 { "mipstx39", 0, ISA_MIPS1, CPU_R3900, },
12104 { "R4000", 0, ISA_MIPS3, CPU_R4000, },
12105 { "4000", 0, ISA_MIPS3, CPU_R4000, },
12106 { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */
12107 { "r4k", 0, ISA_MIPS3, CPU_R4000, },
12110 { "R4010", 0, ISA_MIPS2, CPU_R4010, },
12111 { "4010", 0, ISA_MIPS2, CPU_R4010, },
12114 { "R4400", 0, ISA_MIPS3, CPU_R4400, },
12115 { "4400", 0, ISA_MIPS3, CPU_R4400, },
12118 { "R4600", 0, ISA_MIPS3, CPU_R4600, },
12119 { "4600", 0, ISA_MIPS3, CPU_R4600, },
12120 { "mips64orion", 0, ISA_MIPS3, CPU_R4600, },
12121 { "orion", 0, ISA_MIPS3, CPU_R4600, },
12124 { "R4650", 0, ISA_MIPS3, CPU_R4650, },
12125 { "4650", 0, ISA_MIPS3, CPU_R4650, },
12128 { "R6000", 0, ISA_MIPS2, CPU_R6000, },
12129 { "6000", 0, ISA_MIPS2, CPU_R6000, },
12130 { "6k", 0, ISA_MIPS2, CPU_R6000, },
12131 { "r6k", 0, ISA_MIPS2, CPU_R6000, },
12134 { "R8000", 0, ISA_MIPS4, CPU_R8000, },
12135 { "8000", 0, ISA_MIPS4, CPU_R8000, },
12136 { "8k", 0, ISA_MIPS4, CPU_R8000, },
12137 { "r8k", 0, ISA_MIPS4, CPU_R8000, },
12140 { "R10000", 0, ISA_MIPS4, CPU_R10000, },
12141 { "10000", 0, ISA_MIPS4, CPU_R10000, },
12142 { "10k", 0, ISA_MIPS4, CPU_R10000, },
12143 { "r10k", 0, ISA_MIPS4, CPU_R10000, },
12146 { "R12000", 0, ISA_MIPS4, CPU_R12000, },
12147 { "12000", 0, ISA_MIPS4, CPU_R12000, },
12148 { "12k", 0, ISA_MIPS4, CPU_R12000, },
12149 { "r12k", 0, ISA_MIPS4, CPU_R12000, },
12152 { "VR4100", 0, ISA_MIPS3, CPU_VR4100, },
12153 { "4100", 0, ISA_MIPS3, CPU_VR4100, },
12154 { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, },
12155 { "r4100", 0, ISA_MIPS3, CPU_VR4100, },
12158 { "VR4111", 0, ISA_MIPS3, CPU_R4111, },
12159 { "4111", 0, ISA_MIPS3, CPU_R4111, },
12160 { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, },
12161 { "r4111", 0, ISA_MIPS3, CPU_R4111, },
12164 { "VR4300", 0, ISA_MIPS3, CPU_R4300, },
12165 { "4300", 0, ISA_MIPS3, CPU_R4300, },
12166 { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, },
12167 { "r4300", 0, ISA_MIPS3, CPU_R4300, },
12170 { "VR5000", 0, ISA_MIPS4, CPU_R5000, },
12171 { "5000", 0, ISA_MIPS4, CPU_R5000, },
12172 { "5k", 0, ISA_MIPS4, CPU_R5000, },
12173 { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, },
12174 { "r5000", 0, ISA_MIPS4, CPU_R5000, },
12175 { "r5200", 0, ISA_MIPS4, CPU_R5000, },
12176 { "rm5200", 0, ISA_MIPS4, CPU_R5000, },
12177 { "r5230", 0, ISA_MIPS4, CPU_R5000, },
12178 { "rm5230", 0, ISA_MIPS4, CPU_R5000, },
12179 { "r5231", 0, ISA_MIPS4, CPU_R5000, },
12180 { "rm5231", 0, ISA_MIPS4, CPU_R5000, },
12181 { "r5261", 0, ISA_MIPS4, CPU_R5000, },
12182 { "rm5261", 0, ISA_MIPS4, CPU_R5000, },
12183 { "r5721", 0, ISA_MIPS4, CPU_R5000, },
12184 { "rm5721", 0, ISA_MIPS4, CPU_R5000, },
12185 { "r5k", 0, ISA_MIPS4, CPU_R5000, },
12186 { "r7000", 0, ISA_MIPS4, CPU_R5000, },
12188 /* MIPS32 4K CPU */
12189 { "MIPS32-4K", 0, ISA_MIPS32, CPU_MIPS32_4K, },
12190 { "4kc", 0, ISA_MIPS32, CPU_MIPS32_4K, },
12191 { "4km", 0, ISA_MIPS32, CPU_MIPS32_4K, },
12192 { "4kp", 0, ISA_MIPS32, CPU_MIPS32_4K, },
12193 { "mips32-4kc", 0, ISA_MIPS32, CPU_MIPS32_4K, },
12194 { "mips32-4km", 0, ISA_MIPS32, CPU_MIPS32_4K, },
12195 { "mips32-4kp", 0, ISA_MIPS32, CPU_MIPS32_4K, },
12197 /* SiByte SB-1 CPU */
12198 { "SB-1", 0, ISA_MIPS64, CPU_SB1, },
12199 { "sb-1250", 0, ISA_MIPS64, CPU_SB1, },
12200 { "sb1", 0, ISA_MIPS64, CPU_SB1, },
12201 { "sb1250", 0, ISA_MIPS64, CPU_SB1, },
12204 { NULL, 0, 0, 0, },
12207 static const struct mips_cpu_info *
12208 mips_cpu_info_from_name (name)
12213 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
12214 if (strcasecmp (name, mips_cpu_info_table[i].name) == 0)
12215 return (&mips_cpu_info_table[i]);
12220 static const struct mips_cpu_info *
12221 mips_cpu_info_from_isa (isa)
12226 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
12227 if (mips_cpu_info_table[i].is_isa
12228 && isa == mips_cpu_info_table[i].isa)
12229 return (&mips_cpu_info_table[i]);
12234 static const struct mips_cpu_info *
12235 mips_cpu_info_from_cpu (cpu)
12240 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
12241 if (!mips_cpu_info_table[i].is_isa
12242 && cpu == mips_cpu_info_table[i].cpu)
12243 return (&mips_cpu_info_table[i]);