1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
3 Contributed by the OSF and Ralph Campbell.
4 Written by Keith Knowles and Ralph Campbell, working independently.
5 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
8 This file is part of GAS.
10 GAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GAS; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
38 #include "opcode/mips.h"
42 #define DBG(x) printf x
48 /* Clean up namespace so we can include obj-elf.h too. */
49 static int mips_output_flavor PARAMS ((void));
50 static int mips_output_flavor () { return OUTPUT_FLAVOR; }
51 #undef OBJ_PROCESS_STAB
57 #undef TARGET_SYMBOL_FIELDS
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. */
110 /* The default target format to use. */
112 mips_target_format ()
114 switch (OUTPUT_FLAVOR)
116 case bfd_target_aout_flavour:
117 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
118 case bfd_target_ecoff_flavour:
119 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
120 case bfd_target_elf_flavour:
121 return (target_big_endian
122 ? (mips_64 ? "elf64-bigmips" : "elf32-bigmips")
123 : (mips_64 ? "elf64-littlemips" : "elf32-littlemips"));
130 /* The name of the readonly data section. */
131 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
133 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
135 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
139 /* This is the set of options which may be modified by the .set
140 pseudo-op. We use a struct so that .set push and .set pop are more
143 struct mips_set_options
145 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
146 if it has not been initialized. Changed by `.set mipsN', and the
147 -mipsN command line option, and the default CPU. */
149 /* Whether we are assembling for the mips16 processor. 0 if we are
150 not, 1 if we are, and -1 if the value has not been initialized.
151 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
152 -nomips16 command line options, and the default CPU. */
154 /* Non-zero if we should not reorder instructions. Changed by `.set
155 reorder' and `.set noreorder'. */
157 /* Non-zero if we should not permit the $at ($1) register to be used
158 in instructions. Changed by `.set at' and `.set noat'. */
160 /* Non-zero if we should warn when a macro instruction expands into
161 more than one machine instruction. Changed by `.set nomacro' and
163 int warn_about_macros;
164 /* Non-zero if we should not move instructions. Changed by `.set
165 move', `.set volatile', `.set nomove', and `.set novolatile'. */
167 /* Non-zero if we should not optimize branches by moving the target
168 of the branch into the delay slot. Actually, we don't perform
169 this optimization anyhow. Changed by `.set bopt' and `.set
172 /* Non-zero if we should not autoextend mips16 instructions.
173 Changed by `.set autoextend' and `.set noautoextend'. */
177 /* This is the struct we use to hold the current set of options. Note
178 that we must set the isa and mips16 fields to -1 to indicate that
179 they have not been initialized. */
181 static struct mips_set_options mips_opts = { -1, -1 };
183 /* These variables are filled in with the masks of registers used.
184 The object format code reads them and puts them in the appropriate
186 unsigned long mips_gprmask;
187 unsigned long mips_cprmask[4];
189 /* MIPS ISA we are using for this output file. */
190 static int file_mips_isa;
192 /* The CPU type as a number: 2000, 3000, 4000, 4400, etc. */
193 static int mips_cpu = -1;
195 /* Whether the 4650 instructions (mad/madu) are permitted. */
196 static int mips_4650 = -1;
198 /* Whether the 4010 instructions are permitted. */
199 static int mips_4010 = -1;
201 /* Whether the 4100 MADD16 and DMADD16 are permitted. */
202 static int mips_4100 = -1;
204 /* start-sanitize-r5900 */
205 /* Whether Toshiba r5900 instructions are permitted. */
206 static int mips_5900 = -1;
207 /* end-sanitize-r5900 */
209 /* Whether Toshiba r3900 instructions are permitted. */
210 static int mips_3900 = -1;
212 /* start-sanitize-tx19 */
213 /* The tx19 (r1900) is a mips16 decoder with a tx39(r3900) behind it.
214 The tx19 related options and configuration bits are handled by
216 /* end-sanitize-tx19 */
218 /* Whether the processor uses hardware interlocks to protect
219 reads from the HI and LO registers, and thus does not
220 require nops to be inserted. */
221 #define hilo_interlocks (mips_4010 || mips_cpu == 4300 || mips_3900)
223 /* Whether the processor uses hardware interlocks to protect reads
224 from the GPRs, and thus does not require nops to be inserted. */
225 #define gpr_interlocks (mips_opts.isa >= 2 || mips_3900)
227 /* As with other "interlocks" this is used by hardware that has FP
228 (co-processor) interlocks. */
229 /* Itbl support may require additional care here. */
230 #define cop_interlocks (mips_cpu == 4300)
232 /* MIPS PIC level. */
236 /* Do not generate PIC code. */
239 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
240 not sure what it is supposed to do. */
243 /* Generate PIC code as in the SVR4 MIPS ABI. */
246 /* Generate PIC code without using a global offset table: the data
247 segment has a maximum size of 64K, all data references are off
248 the $gp register, and all text references are PC relative. This
249 is used on some embedded systems. */
253 static enum mips_pic_level mips_pic;
255 /* 1 if we should generate 32 bit offsets from the GP register in
256 SVR4_PIC mode. Currently has no meaning in other modes. */
257 static int mips_big_got;
259 /* 1 if trap instructions should used for overflow rather than break
261 static int mips_trap;
263 /* Non-zero if any .set noreorder directives were used. */
265 static int mips_any_noreorder;
267 /* The size of the small data section. */
268 static int g_switch_value = 8;
269 /* Whether the -G option was used. */
270 static int g_switch_seen = 0;
275 /* If we can determine in advance that GP optimization won't be
276 possible, we can skip the relaxation stuff that tries to produce
277 GP-relative references. This makes delay slot optimization work
280 This function can only provide a guess, but it seems to work for
281 gcc output. If it guesses wrong, the only loss should be in
282 efficiency; it shouldn't introduce any bugs.
284 I don't know if a fix is needed for the SVR4_PIC mode. I've only
285 fixed it for the non-PIC mode. KR 95/04/07 */
286 static int nopic_need_relax PARAMS ((symbolS *, int));
288 /* handle of the OPCODE hash table */
289 static struct hash_control *op_hash = NULL;
291 /* The opcode hash table we use for the mips16. */
292 static struct hash_control *mips16_op_hash = NULL;
294 /* This array holds the chars that always start a comment. If the
295 pre-processor is disabled, these aren't very useful */
296 const char comment_chars[] = "#";
298 /* This array holds the chars that only start a comment at the beginning of
299 a line. If the line seems to have the form '# 123 filename'
300 .line and .file directives will appear in the pre-processed output */
301 /* Note that input_file.c hand checks for '#' at the beginning of the
302 first line of the input file. This is because the compiler outputs
303 #NO_APP at the beginning of its output. */
304 /* Also note that C style comments are always supported. */
305 const char line_comment_chars[] = "#";
307 /* This array holds machine specific line separator characters. */
308 const char line_separator_chars[] = "";
310 /* Chars that can be used to separate mant from exp in floating point nums */
311 const char EXP_CHARS[] = "eE";
313 /* Chars that mean this number is a floating point constant */
316 const char FLT_CHARS[] = "rRsSfFdDxXpP";
318 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
319 changed in read.c . Ideally it shouldn't have to know about it at all,
320 but nothing is ideal around here.
323 static char *insn_error;
325 static int auto_align = 1;
327 /* When outputting SVR4 PIC code, the assembler needs to know the
328 offset in the stack frame from which to restore the $gp register.
329 This is set by the .cprestore pseudo-op, and saved in this
331 static offsetT mips_cprestore_offset = -1;
333 /* This is the register which holds the stack frame, as set by the
334 .frame pseudo-op. This is needed to implement .cprestore. */
335 static int mips_frame_reg = SP;
337 /* To output NOP instructions correctly, we need to keep information
338 about the previous two instructions. */
340 /* Whether we are optimizing. The default value of 2 means to remove
341 unneeded NOPs and swap branch instructions when possible. A value
342 of 1 means to not swap branches. A value of 0 means to always
344 static int mips_optimize = 2;
346 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
347 equivalent to seeing no -g option at all. */
348 static int mips_debug = 0;
350 /* The previous instruction. */
351 static struct mips_cl_insn prev_insn;
353 /* The instruction before prev_insn. */
354 static struct mips_cl_insn prev_prev_insn;
356 /* If we don't want information for prev_insn or prev_prev_insn, we
357 point the insn_mo field at this dummy integer. */
358 static const struct mips_opcode dummy_opcode = { 0 };
360 /* Non-zero if prev_insn is valid. */
361 static int prev_insn_valid;
363 /* The frag for the previous instruction. */
364 static struct frag *prev_insn_frag;
366 /* The offset into prev_insn_frag for the previous instruction. */
367 static long prev_insn_where;
369 /* The reloc type for the previous instruction, if any. */
370 static bfd_reloc_code_real_type prev_insn_reloc_type;
372 /* The reloc for the previous instruction, if any. */
373 static fixS *prev_insn_fixp;
375 /* Non-zero if the previous instruction was in a delay slot. */
376 static int prev_insn_is_delay_slot;
378 /* Non-zero if the previous instruction was in a .set noreorder. */
379 static int prev_insn_unreordered;
381 /* Non-zero if the previous instruction uses an extend opcode (if
383 static int prev_insn_extended;
385 /* Non-zero if the previous previous instruction was in a .set
387 static int prev_prev_insn_unreordered;
389 /* If this is set, it points to a frag holding nop instructions which
390 were inserted before the start of a noreorder section. If those
391 nops turn out to be unnecessary, the size of the frag can be
393 static fragS *prev_nop_frag;
395 /* The number of nop instructions we created in prev_nop_frag. */
396 static int prev_nop_frag_holds;
398 /* The number of nop instructions that we know we need in
400 static int prev_nop_frag_required;
402 /* The number of instructions we've seen since prev_nop_frag. */
403 static int prev_nop_frag_since;
405 /* For ECOFF and ELF, relocations against symbols are done in two
406 parts, with a HI relocation and a LO relocation. Each relocation
407 has only 16 bits of space to store an addend. This means that in
408 order for the linker to handle carries correctly, it must be able
409 to locate both the HI and the LO relocation. This means that the
410 relocations must appear in order in the relocation table.
412 In order to implement this, we keep track of each unmatched HI
413 relocation. We then sort them so that they immediately precede the
414 corresponding LO relocation. */
419 struct mips_hi_fixup *next;
422 /* The section this fixup is in. */
426 /* The list of unmatched HI relocs. */
428 static struct mips_hi_fixup *mips_hi_fixup_list;
430 /* Map normal MIPS register numbers to mips16 register numbers. */
432 #define X ILLEGAL_REG
433 static const int mips32_to_16_reg_map[] =
435 X, X, 2, 3, 4, 5, 6, 7,
436 X, X, X, X, X, X, X, X,
437 0, 1, X, X, X, X, X, X,
438 X, X, X, X, X, X, X, X
442 /* Map mips16 register numbers to normal MIPS register numbers. */
444 static const int mips16_to_32_reg_map[] =
446 16, 17, 2, 3, 4, 5, 6, 7
449 /* Since the MIPS does not have multiple forms of PC relative
450 instructions, we do not have to do relaxing as is done on other
451 platforms. However, we do have to handle GP relative addressing
452 correctly, which turns out to be a similar problem.
454 Every macro that refers to a symbol can occur in (at least) two
455 forms, one with GP relative addressing and one without. For
456 example, loading a global variable into a register generally uses
457 a macro instruction like this:
459 If i can be addressed off the GP register (this is true if it is in
460 the .sbss or .sdata section, or if it is known to be smaller than
461 the -G argument) this will generate the following instruction:
463 This instruction will use a GPREL reloc. If i can not be addressed
464 off the GP register, the following instruction sequence will be used:
467 In this case the first instruction will have a HI16 reloc, and the
468 second reloc will have a LO16 reloc. Both relocs will be against
471 The issue here is that we may not know whether i is GP addressable
472 until after we see the instruction that uses it. Therefore, we
473 want to be able to choose the final instruction sequence only at
474 the end of the assembly. This is similar to the way other
475 platforms choose the size of a PC relative instruction only at the
478 When generating position independent code we do not use GP
479 addressing in quite the same way, but the issue still arises as
480 external symbols and local symbols must be handled differently.
482 We handle these issues by actually generating both possible
483 instruction sequences. The longer one is put in a frag_var with
484 type rs_machine_dependent. We encode what to do with the frag in
485 the subtype field. We encode (1) the number of existing bytes to
486 replace, (2) the number of new bytes to use, (3) the offset from
487 the start of the existing bytes to the first reloc we must generate
488 (that is, the offset is applied from the start of the existing
489 bytes after they are replaced by the new bytes, if any), (4) the
490 offset from the start of the existing bytes to the second reloc,
491 (5) whether a third reloc is needed (the third reloc is always four
492 bytes after the second reloc), and (6) whether to warn if this
493 variant is used (this is sometimes needed if .set nomacro or .set
494 noat is in effect). All these numbers are reasonably small.
496 Generating two instruction sequences must be handled carefully to
497 ensure that delay slots are handled correctly. Fortunately, there
498 are a limited number of cases. When the second instruction
499 sequence is generated, append_insn is directed to maintain the
500 existing delay slot information, so it continues to apply to any
501 code after the second instruction sequence. This means that the
502 second instruction sequence must not impose any requirements not
503 required by the first instruction sequence.
505 These variant frags are then handled in functions called by the
506 machine independent code. md_estimate_size_before_relax returns
507 the final size of the frag. md_convert_frag sets up the final form
508 of the frag. tc_gen_reloc adjust the first reloc and adds a second
510 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
514 | (((reloc1) + 64) << 9) \
515 | (((reloc2) + 64) << 2) \
516 | ((reloc3) ? (1 << 1) : 0) \
518 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
519 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
520 #define RELAX_RELOC1(i) ((bfd_vma)(((i) >> 9) & 0x7f) - 64)
521 #define RELAX_RELOC2(i) ((bfd_vma)(((i) >> 2) & 0x7f) - 64)
522 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
523 #define RELAX_WARN(i) ((i) & 1)
525 /* For mips16 code, we use an entirely different form of relaxation.
526 mips16 supports two versions of most instructions which take
527 immediate values: a small one which takes some small value, and a
528 larger one which takes a 16 bit value. Since branches also follow
529 this pattern, relaxing these values is required.
531 We can assemble both mips16 and normal MIPS code in a single
532 object. Therefore, we need to support this type of relaxation at
533 the same time that we support the relaxation described above. We
534 use the high bit of the subtype field to distinguish these cases.
536 The information we store for this type of relaxation is the
537 argument code found in the opcode file for this relocation, whether
538 the user explicitly requested a small or extended form, and whether
539 the relocation is in a jump or jal delay slot. That tells us the
540 size of the value, and how it should be stored. We also store
541 whether the fragment is considered to be extended or not. We also
542 store whether this is known to be a branch to a different section,
543 whether we have tried to relax this frag yet, and whether we have
544 ever extended a PC relative fragment because of a shift count. */
545 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
548 | ((small) ? 0x100 : 0) \
549 | ((ext) ? 0x200 : 0) \
550 | ((dslot) ? 0x400 : 0) \
551 | ((jal_dslot) ? 0x800 : 0))
552 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
553 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
554 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
555 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
556 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
557 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
558 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
559 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
560 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
561 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
562 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
563 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
565 /* Prototypes for static functions. */
568 #define internalError() \
569 as_fatal ("internal Error, line %d, %s", __LINE__, __FILE__)
571 #define internalError() as_fatal ("MIPS internal Error");
574 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
576 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
577 unsigned int reg, enum mips_regclass class));
578 static int reg_needs_delay PARAMS ((int));
579 static void mips16_mark_labels PARAMS ((void));
580 static void append_insn PARAMS ((char *place,
581 struct mips_cl_insn * ip,
583 bfd_reloc_code_real_type r,
585 static void mips_no_prev_insn PARAMS ((int));
586 static void mips_emit_delays PARAMS ((boolean));
588 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
589 const char *name, const char *fmt,
592 static void macro_build ();
594 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
595 const char *, const char *,
597 static void macro_build_lui PARAMS ((char *place, int *counter,
598 expressionS * ep, int regnum));
599 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
600 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
602 static void load_register PARAMS ((int *, int, expressionS *, int));
603 static void load_address PARAMS ((int *counter, int reg, expressionS *ep));
604 static void macro PARAMS ((struct mips_cl_insn * ip));
605 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
606 #ifdef LOSING_COMPILER
607 static void macro2 PARAMS ((struct mips_cl_insn * ip));
609 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
610 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
611 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
612 boolean, boolean, unsigned long *,
613 boolean *, unsigned short *));
614 static int my_getSmallExpression PARAMS ((expressionS * ep, char *str));
615 static void my_getExpression PARAMS ((expressionS * ep, char *str));
616 static symbolS *get_symbol PARAMS ((void));
617 static void mips_align PARAMS ((int to, int fill, symbolS *label));
618 static void s_align PARAMS ((int));
619 static void s_change_sec PARAMS ((int));
620 static void s_cons PARAMS ((int));
621 static void s_float_cons PARAMS ((int));
622 static void s_mips_globl PARAMS ((int));
623 static void s_option PARAMS ((int));
624 static void s_mipsset PARAMS ((int));
625 static void s_abicalls PARAMS ((int));
626 static void s_cpload PARAMS ((int));
627 static void s_cprestore PARAMS ((int));
628 static void s_gpword PARAMS ((int));
629 static void s_cpadd PARAMS ((int));
630 static void s_insn PARAMS ((int));
631 static void md_obj_begin PARAMS ((void));
632 static void md_obj_end PARAMS ((void));
633 static long get_number PARAMS ((void));
634 static void s_ent PARAMS ((int));
635 static void s_mipsend PARAMS ((int));
636 static void s_file PARAMS ((int));
637 static void s_mips_stab PARAMS ((int));
638 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
642 The following pseudo-ops from the Kane and Heinrich MIPS book
643 should be defined here, but are currently unsupported: .alias,
644 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
646 The following pseudo-ops from the Kane and Heinrich MIPS book are
647 specific to the type of debugging information being generated, and
648 should be defined by the object format: .aent, .begin, .bend,
649 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
652 The following pseudo-ops from the Kane and Heinrich MIPS book are
653 not MIPS CPU specific, but are also not specific to the object file
654 format. This file is probably the best place to define them, but
655 they are not currently supported: .asm0, .endr, .lab, .repeat,
656 .struct, .weakext. */
658 static const pseudo_typeS mips_pseudo_table[] =
660 /* MIPS specific pseudo-ops. */
661 {"option", s_option, 0},
662 {"set", s_mipsset, 0},
663 {"rdata", s_change_sec, 'r'},
664 {"sdata", s_change_sec, 's'},
665 {"livereg", s_ignore, 0},
666 {"abicalls", s_abicalls, 0},
667 {"cpload", s_cpload, 0},
668 {"cprestore", s_cprestore, 0},
669 {"gpword", s_gpword, 0},
670 {"cpadd", s_cpadd, 0},
673 /* Relatively generic pseudo-ops that happen to be used on MIPS
675 {"asciiz", stringer, 1},
676 {"bss", s_change_sec, 'b'},
679 {"dword", s_cons, 3},
681 /* These pseudo-ops are defined in read.c, but must be overridden
682 here for one reason or another. */
683 {"align", s_align, 0},
685 {"data", s_change_sec, 'd'},
686 {"double", s_float_cons, 'd'},
687 {"float", s_float_cons, 'f'},
688 {"globl", s_mips_globl, 0},
689 {"global", s_mips_globl, 0},
690 {"hword", s_cons, 1},
695 {"short", s_cons, 1},
696 {"single", s_float_cons, 'f'},
697 {"stabn", s_mips_stab, 'n'},
698 {"text", s_change_sec, 't'},
703 static const pseudo_typeS mips_nonecoff_pseudo_table[] = {
704 /* These pseudo-ops should be defined by the object file format.
705 However, a.out doesn't support them, so we have versions here. */
707 {"bgnb", s_ignore, 0},
708 {"end", s_mipsend, 0},
709 {"endb", s_ignore, 0},
712 {"fmask", s_ignore, 'F'},
713 {"frame", s_ignore, 0},
714 {"loc", s_ignore, 0},
715 {"mask", s_ignore, 'R'},
716 {"verstamp", s_ignore, 0},
720 extern void pop_insert PARAMS ((const pseudo_typeS *));
725 pop_insert (mips_pseudo_table);
726 if (! ECOFF_DEBUGGING)
727 pop_insert (mips_nonecoff_pseudo_table);
730 /* Symbols labelling the current insn. */
732 struct insn_label_list
734 struct insn_label_list *next;
738 static struct insn_label_list *insn_labels;
739 static struct insn_label_list *free_insn_labels;
741 static void mips_clear_insn_labels PARAMS ((void));
744 mips_clear_insn_labels ()
746 register struct insn_label_list **pl;
748 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
754 static char *expr_end;
756 /* Expressions which appear in instructions. These are set by
759 static expressionS imm_expr;
760 static expressionS offset_expr;
762 /* Relocs associated with imm_expr and offset_expr. */
764 static bfd_reloc_code_real_type imm_reloc;
765 static bfd_reloc_code_real_type offset_reloc;
767 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
769 static boolean imm_unmatched_hi;
771 /* These are set by mips16_ip if an explicit extension is used. */
773 static boolean mips16_small, mips16_ext;
776 * This function is called once, at assembler startup time. It should
777 * set up all the tables, etc. that the MD part of the assembler will need.
783 register const char *retval = NULL;
784 register unsigned int i = 0;
786 if (mips_opts.isa == -1)
792 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
794 a = xmalloc (sizeof TARGET_CPU);
795 strcpy (a, TARGET_CPU);
796 a[(sizeof TARGET_CPU) - 3] = '\0';
800 if (strcmp (cpu, "mips") == 0)
806 else if (strcmp (cpu, "r3900") == 0
807 || strcmp (cpu, "mipsr3900") == 0
808 /* start-sanitize-tx19 */
809 || strcmp (cpu, "r1900") == 0
810 || strcmp (cpu, "mipstx19") == 0
811 /* end-sanitize-tx19 */
820 else if (strcmp (cpu, "r6000") == 0
821 || strcmp (cpu, "mips2") == 0)
827 else if (strcmp (cpu, "mips64") == 0
828 || strcmp (cpu, "r4000") == 0
829 || strcmp (cpu, "mips3") == 0)
835 else if (strcmp (cpu, "r4400") == 0)
841 else if (strcmp (cpu, "mips64orion") == 0
842 || strcmp (cpu, "r4600") == 0)
848 else if (strcmp (cpu, "r4650") == 0)
856 else if (strcmp (cpu, "mips64vr4300") == 0)
862 else if (strcmp (cpu, "mips64vr4100") == 0)
870 else if (strcmp (cpu, "r4010") == 0)
878 else if (strcmp (cpu, "r5000") == 0
879 || strcmp (cpu, "mips64vr5000") == 0)
885 /* start-sanitize-r5900 */
886 else if (strcmp (cpu, "r5900") == 0
887 || strcmp (cpu, "mips64r5900") == 0
888 || strcmp (cpu, "mips64r5900el") == 0)
896 /* end-sanitize-r5900 */
897 else if (strcmp (cpu, "r8000") == 0
898 || strcmp (cpu, "mips4") == 0)
904 else if (strcmp (cpu, "r10000") == 0)
910 else if (strcmp (cpu, "mips16") == 0)
914 mips_cpu = 0; /* FIXME */
927 if (mips_opts.mips16 < 0)
929 if (strncmp (TARGET_CPU, "mips16", sizeof "mips16" - 1) == 0)
930 mips_opts.mips16 = 1;
932 mips_opts.mips16 = 0;
944 /* start-sanitize-r5900 */
947 /* end-sanitize-r5900 */
952 if (mips_opts.isa < 2 && mips_trap)
953 as_bad ("trap exception not supported at ISA 1");
955 switch (mips_opts.isa)
958 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 3000);
961 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 6000);
964 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 4000);
967 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 8000);
971 as_warn ("Could not set architecture and machine");
973 file_mips_isa = mips_opts.isa;
975 op_hash = hash_new ();
977 for (i = 0; i < NUMOPCODES;)
979 const char *name = mips_opcodes[i].name;
981 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
984 fprintf (stderr, "internal error: can't hash `%s': %s\n",
985 mips_opcodes[i].name, retval);
986 as_fatal ("Broken assembler. No assembly attempted.");
990 if (mips_opcodes[i].pinfo != INSN_MACRO
991 && ((mips_opcodes[i].match & mips_opcodes[i].mask)
992 != mips_opcodes[i].match))
994 fprintf (stderr, "internal error: bad opcode: `%s' \"%s\"\n",
995 mips_opcodes[i].name, mips_opcodes[i].args);
996 as_fatal ("Broken assembler. No assembly attempted.");
1000 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1003 mips16_op_hash = hash_new ();
1006 while (i < bfd_mips16_num_opcodes)
1008 const char *name = mips16_opcodes[i].name;
1010 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1012 as_fatal ("internal error: can't hash `%s': %s\n",
1013 mips16_opcodes[i].name, retval);
1016 if (mips16_opcodes[i].pinfo != INSN_MACRO
1017 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1018 != mips16_opcodes[i].match))
1019 as_fatal ("internal error: bad opcode: `%s' \"%s\"\n",
1020 mips16_opcodes[i].name, mips16_opcodes[i].args);
1023 while (i < bfd_mips16_num_opcodes
1024 && strcmp (mips16_opcodes[i].name, name) == 0);
1027 /* We add all the general register names to the symbol table. This
1028 helps us detect invalid uses of them. */
1029 for (i = 0; i < 32; i++)
1033 sprintf (buf, "$%d", i);
1034 symbol_table_insert (symbol_new (buf, reg_section, i,
1035 &zero_address_frag));
1037 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1038 &zero_address_frag));
1039 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1040 &zero_address_frag));
1041 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1042 &zero_address_frag));
1043 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1044 &zero_address_frag));
1045 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1046 &zero_address_frag));
1047 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1048 &zero_address_frag));
1049 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1050 &zero_address_frag));
1052 mips_no_prev_insn (false);
1055 mips_cprmask[0] = 0;
1056 mips_cprmask[1] = 0;
1057 mips_cprmask[2] = 0;
1058 mips_cprmask[3] = 0;
1060 /* set the default alignment for the text section (2**2) */
1061 record_alignment (text_section, 2);
1063 if (USE_GLOBAL_POINTER_OPT)
1064 bfd_set_gp_size (stdoutput, g_switch_value);
1066 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1068 /* On a native system, sections must be aligned to 16 byte
1069 boundaries. When configured for an embedded ELF target, we
1071 if (strcmp (TARGET_OS, "elf") != 0)
1073 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1074 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1075 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1078 /* Create a .reginfo section for register masks and a .mdebug
1079 section for debugging information. */
1087 subseg = now_subseg;
1089 /* The ABI says this section should be loaded so that the
1090 running program can access it. However, we don't load it
1091 if we are configured for an embedded target */
1092 flags = SEC_READONLY | SEC_DATA;
1093 if (strcmp (TARGET_OS, "elf") != 0)
1094 flags |= SEC_ALLOC | SEC_LOAD;
1098 sec = subseg_new (".reginfo", (subsegT) 0);
1101 (void) bfd_set_section_flags (stdoutput, sec, flags);
1102 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1105 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1110 /* The 64-bit ABI uses a .MIPS.options section rather than
1111 .reginfo section. */
1112 sec = subseg_new (".MIPS.options", (subsegT) 0);
1113 (void) bfd_set_section_flags (stdoutput, sec, flags);
1114 (void) bfd_set_section_alignment (stdoutput, sec, 3);
1117 /* Set up the option header. */
1119 Elf_Internal_Options opthdr;
1122 opthdr.kind = ODK_REGINFO;
1123 opthdr.size = (sizeof (Elf_External_Options)
1124 + sizeof (Elf64_External_RegInfo));
1127 f = frag_more (sizeof (Elf_External_Options));
1128 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1129 (Elf_External_Options *) f);
1131 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1136 if (ECOFF_DEBUGGING)
1138 sec = subseg_new (".mdebug", (subsegT) 0);
1139 (void) bfd_set_section_flags (stdoutput, sec,
1140 SEC_HAS_CONTENTS | SEC_READONLY);
1141 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1144 subseg_set (seg, subseg);
1148 if (! ECOFF_DEBUGGING)
1155 if (! ECOFF_DEBUGGING)
1163 struct mips_cl_insn insn;
1165 imm_expr.X_op = O_absent;
1166 imm_reloc = BFD_RELOC_UNUSED;
1167 imm_unmatched_hi = false;
1168 offset_expr.X_op = O_absent;
1169 offset_reloc = BFD_RELOC_UNUSED;
1171 if (mips_opts.mips16)
1172 mips16_ip (str, &insn);
1175 mips_ip (str, &insn);
1176 DBG(("returned from mips_ip(%s) insn_opcode = 0x%x\n",
1177 str, insn.insn_opcode));
1182 as_bad ("%s `%s'", insn_error, str);
1186 if (insn.insn_mo->pinfo == INSN_MACRO)
1188 if (mips_opts.mips16)
1189 mips16_macro (&insn);
1195 if (imm_expr.X_op != O_absent)
1196 append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc,
1198 else if (offset_expr.X_op != O_absent)
1199 append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc, false);
1201 append_insn ((char *) NULL, &insn, NULL, BFD_RELOC_UNUSED, false);
1205 /* See whether instruction IP reads register REG. CLASS is the type
1209 insn_uses_reg (ip, reg, class)
1210 struct mips_cl_insn *ip;
1212 enum mips_regclass class;
1214 if (class == MIPS16_REG)
1216 assert (mips_opts.mips16);
1217 reg = mips16_to_32_reg_map[reg];
1218 class = MIPS_GR_REG;
1221 /* Don't report on general register 0, since it never changes. */
1222 if (class == MIPS_GR_REG && reg == 0)
1225 if (class == MIPS_FP_REG)
1227 assert (! mips_opts.mips16);
1228 /* If we are called with either $f0 or $f1, we must check $f0.
1229 This is not optimal, because it will introduce an unnecessary
1230 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1231 need to distinguish reading both $f0 and $f1 or just one of
1232 them. Note that we don't have to check the other way,
1233 because there is no instruction that sets both $f0 and $f1
1234 and requires a delay. */
1235 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1236 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1237 == (reg &~ (unsigned) 1)))
1239 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1240 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1241 == (reg &~ (unsigned) 1)))
1244 else if (! mips_opts.mips16)
1246 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1247 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1249 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1250 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1255 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1256 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1257 & MIPS16OP_MASK_RX)]
1260 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1261 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1262 & MIPS16OP_MASK_RY)]
1265 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1266 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1267 & MIPS16OP_MASK_MOVE32Z)]
1270 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1272 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1274 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1276 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1277 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1278 & MIPS16OP_MASK_REGR32) == reg)
1285 /* This function returns true if modifying a register requires a
1289 reg_needs_delay (reg)
1292 unsigned long prev_pinfo;
1294 prev_pinfo = prev_insn.insn_mo->pinfo;
1295 if (! mips_opts.noreorder
1296 && mips_opts.isa < 4
1297 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1298 || (! gpr_interlocks
1299 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1301 /* A load from a coprocessor or from memory. All load
1302 delays delay the use of general register rt for one
1303 instruction on the r3000. The r6000 and r4000 use
1305 /* Itbl support may require additional care here. */
1306 know (prev_pinfo & INSN_WRITE_GPR_T);
1307 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1314 /* Mark instruction labels in mips16 mode. This permits the linker to
1315 handle them specially, such as generating jalx instructions when
1316 needed. We also make them odd for the duration of the assembly, in
1317 order to generate the right sort of code. We will make them even
1318 in the adjust_symtab routine, while leaving them marked. This is
1319 convenient for the debugger and the disassembler. The linker knows
1320 to make them odd again. */
1323 mips16_mark_labels ()
1325 if (mips_opts.mips16)
1327 struct insn_label_list *l;
1329 for (l = insn_labels; l != NULL; l = l->next)
1332 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1333 S_SET_OTHER (l->label, STO_MIPS16);
1335 if ((l->label->sy_value.X_add_number & 1) == 0)
1336 ++l->label->sy_value.X_add_number;
1341 /* Output an instruction. PLACE is where to put the instruction; if
1342 it is NULL, this uses frag_more to get room. IP is the instruction
1343 information. ADDRESS_EXPR is an operand of the instruction to be
1344 used with RELOC_TYPE. */
1347 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1349 struct mips_cl_insn *ip;
1350 expressionS *address_expr;
1351 bfd_reloc_code_real_type reloc_type;
1352 boolean unmatched_hi;
1354 register unsigned long prev_pinfo, pinfo;
1359 /* Mark instruction labels in mips16 mode. */
1360 if (mips_opts.mips16)
1361 mips16_mark_labels ();
1363 prev_pinfo = prev_insn.insn_mo->pinfo;
1364 pinfo = ip->insn_mo->pinfo;
1366 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1370 /* If the previous insn required any delay slots, see if we need
1371 to insert a NOP or two. There are eight kinds of possible
1372 hazards, of which an instruction can have at most one type.
1373 (1) a load from memory delay
1374 (2) a load from a coprocessor delay
1375 (3) an unconditional branch delay
1376 (4) a conditional branch delay
1377 (5) a move to coprocessor register delay
1378 (6) a load coprocessor register from memory delay
1379 (7) a coprocessor condition code delay
1380 (8) a HI/LO special register delay
1382 There are a lot of optimizations we could do that we don't.
1383 In particular, we do not, in general, reorder instructions.
1384 If you use gcc with optimization, it will reorder
1385 instructions and generally do much more optimization then we
1386 do here; repeating all that work in the assembler would only
1387 benefit hand written assembly code, and does not seem worth
1390 /* This is how a NOP is emitted. */
1391 #define emit_nop() \
1393 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1394 : md_number_to_chars (frag_more (4), 0, 4))
1396 /* The previous insn might require a delay slot, depending upon
1397 the contents of the current insn. */
1398 if (! mips_opts.mips16
1399 && mips_opts.isa < 4
1400 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1401 && ! cop_interlocks)
1402 || (! gpr_interlocks
1403 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1405 /* A load from a coprocessor or from memory. All load
1406 delays delay the use of general register rt for one
1407 instruction on the r3000. The r6000 and r4000 use
1409 /* Itbl support may require additional care here. */
1410 know (prev_pinfo & INSN_WRITE_GPR_T);
1411 if (mips_optimize == 0
1412 || insn_uses_reg (ip,
1413 ((prev_insn.insn_opcode >> OP_SH_RT)
1418 else if (! mips_opts.mips16
1419 && mips_opts.isa < 4
1420 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1421 && ! cop_interlocks)
1422 || (mips_opts.isa < 2
1423 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1425 /* A generic coprocessor delay. The previous instruction
1426 modified a coprocessor general or control register. If
1427 it modified a control register, we need to avoid any
1428 coprocessor instruction (this is probably not always
1429 required, but it sometimes is). If it modified a general
1430 register, we avoid using that register.
1432 On the r6000 and r4000 loading a coprocessor register
1433 from memory is interlocked, and does not require a delay.
1435 This case is not handled very well. There is no special
1436 knowledge of CP0 handling, and the coprocessors other
1437 than the floating point unit are not distinguished at
1439 /* Itbl support may require additional care here. FIXME!
1440 Need to modify this to include knowledge about
1441 user specified delays! */
1442 if (prev_pinfo & INSN_WRITE_FPR_T)
1444 if (mips_optimize == 0
1445 || insn_uses_reg (ip,
1446 ((prev_insn.insn_opcode >> OP_SH_FT)
1451 else if (prev_pinfo & INSN_WRITE_FPR_S)
1453 if (mips_optimize == 0
1454 || insn_uses_reg (ip,
1455 ((prev_insn.insn_opcode >> OP_SH_FS)
1462 /* We don't know exactly what the previous instruction
1463 does. If the current instruction uses a coprocessor
1464 register, we must insert a NOP. If previous
1465 instruction may set the condition codes, and the
1466 current instruction uses them, we must insert two
1468 /* Itbl support may require additional care here. */
1469 if (mips_optimize == 0
1470 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1471 && (pinfo & INSN_READ_COND_CODE)))
1473 else if (pinfo & INSN_COP)
1477 else if (! mips_opts.mips16
1478 && mips_opts.isa < 4
1479 && (prev_pinfo & INSN_WRITE_COND_CODE)
1480 && ! cop_interlocks)
1482 /* The previous instruction sets the coprocessor condition
1483 codes, but does not require a general coprocessor delay
1484 (this means it is a floating point comparison
1485 instruction). If this instruction uses the condition
1486 codes, we need to insert a single NOP. */
1487 /* Itbl support may require additional care here. */
1488 if (mips_optimize == 0
1489 || (pinfo & INSN_READ_COND_CODE))
1492 else if (prev_pinfo & INSN_READ_LO)
1494 /* The previous instruction reads the LO register; if the
1495 current instruction writes to the LO register, we must
1496 insert two NOPS. Some newer processors have interlocks. */
1497 if (! hilo_interlocks
1498 && (mips_optimize == 0
1499 || (pinfo & INSN_WRITE_LO)))
1502 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1504 /* The previous instruction reads the HI register; if the
1505 current instruction writes to the HI register, we must
1506 insert a NOP. Some newer processors have interlocks. */
1507 if (! hilo_interlocks
1508 && (mips_optimize == 0
1509 || (pinfo & INSN_WRITE_HI)))
1513 /* If the previous instruction was in a noreorder section, then
1514 we don't want to insert the nop after all. */
1515 /* Itbl support may require additional care here. */
1516 if (prev_insn_unreordered)
1519 /* There are two cases which require two intervening
1520 instructions: 1) setting the condition codes using a move to
1521 coprocessor instruction which requires a general coprocessor
1522 delay and then reading the condition codes 2) reading the HI
1523 or LO register and then writing to it (except on processors
1524 which have interlocks). If we are not already emitting a NOP
1525 instruction, we must check for these cases compared to the
1526 instruction previous to the previous instruction. */
1527 if ((! mips_opts.mips16
1528 && mips_opts.isa < 4
1529 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1530 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1531 && (pinfo & INSN_READ_COND_CODE)
1532 && ! cop_interlocks)
1533 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1534 && (pinfo & INSN_WRITE_LO)
1535 && ! hilo_interlocks)
1536 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1537 && (pinfo & INSN_WRITE_HI)
1538 && ! hilo_interlocks))
1543 if (prev_prev_insn_unreordered)
1546 if (prev_prev_nop && nops == 0)
1549 /* If we are being given a nop instruction, don't bother with
1550 one of the nops we would otherwise output. This will only
1551 happen when a nop instruction is used with mips_optimize set
1554 && ! mips_opts.noreorder
1555 && ip->insn_opcode == (mips_opts.mips16 ? 0x6500 : 0))
1558 /* Now emit the right number of NOP instructions. */
1559 if (nops > 0 && ! mips_opts.noreorder)
1562 unsigned long old_frag_offset;
1564 struct insn_label_list *l;
1566 old_frag = frag_now;
1567 old_frag_offset = frag_now_fix ();
1569 for (i = 0; i < nops; i++)
1574 listing_prev_line ();
1575 /* We may be at the start of a variant frag. In case we
1576 are, make sure there is enough space for the frag
1577 after the frags created by listing_prev_line. The
1578 argument to frag_grow here must be at least as large
1579 as the argument to all other calls to frag_grow in
1580 this file. We don't have to worry about being in the
1581 middle of a variant frag, because the variants insert
1582 all needed nop instructions themselves. */
1586 for (l = insn_labels; l != NULL; l = l->next)
1588 assert (S_GET_SEGMENT (l->label) == now_seg);
1589 l->label->sy_frag = frag_now;
1590 S_SET_VALUE (l->label, (valueT) frag_now_fix ());
1591 /* mips16 text labels are stored as odd. */
1592 if (mips_opts.mips16)
1593 ++l->label->sy_value.X_add_number;
1596 #ifndef NO_ECOFF_DEBUGGING
1597 if (ECOFF_DEBUGGING)
1598 ecoff_fix_loc (old_frag, old_frag_offset);
1601 else if (prev_nop_frag != NULL)
1603 /* We have a frag holding nops we may be able to remove. If
1604 we don't need any nops, we can decrease the size of
1605 prev_nop_frag by the size of one instruction. If we do
1606 need some nops, we count them in prev_nops_required. */
1607 if (prev_nop_frag_since == 0)
1611 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1612 --prev_nop_frag_holds;
1615 prev_nop_frag_required += nops;
1619 if (prev_prev_nop == 0)
1621 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1622 --prev_nop_frag_holds;
1625 ++prev_nop_frag_required;
1628 if (prev_nop_frag_holds <= prev_nop_frag_required)
1629 prev_nop_frag = NULL;
1631 ++prev_nop_frag_since;
1633 /* Sanity check: by the time we reach the second instruction
1634 after prev_nop_frag, we should have used up all the nops
1635 one way or another. */
1636 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1640 if (reloc_type > BFD_RELOC_UNUSED)
1642 /* We need to set up a variant frag. */
1643 assert (mips_opts.mips16 && address_expr != NULL);
1644 f = frag_var (rs_machine_dependent, 4, 0,
1645 RELAX_MIPS16_ENCODE (reloc_type - BFD_RELOC_UNUSED,
1646 mips16_small, mips16_ext,
1648 & INSN_UNCOND_BRANCH_DELAY),
1649 (prev_insn_reloc_type
1650 == BFD_RELOC_MIPS16_JMP)),
1651 make_expr_symbol (address_expr), (offsetT) 0,
1654 else if (place != NULL)
1656 else if (mips_opts.mips16
1658 && reloc_type != BFD_RELOC_MIPS16_JMP)
1660 /* Make sure there is enough room to swap this instruction with
1661 a following jump instruction. */
1667 if (mips_opts.mips16
1668 && mips_opts.noreorder
1669 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1670 as_warn ("extended instruction in delay slot");
1676 if (address_expr != NULL && reloc_type < BFD_RELOC_UNUSED)
1678 if (address_expr->X_op == O_constant)
1683 ip->insn_opcode |= address_expr->X_add_number;
1686 case BFD_RELOC_LO16:
1687 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1690 case BFD_RELOC_MIPS_JMP:
1691 if ((address_expr->X_add_number & 3) != 0)
1692 as_bad ("jump to misaligned address (0x%lx)",
1693 (unsigned long) address_expr->X_add_number);
1694 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
1697 case BFD_RELOC_MIPS16_JMP:
1698 if ((address_expr->X_add_number & 3) != 0)
1699 as_bad ("jump to misaligned address (0x%lx)",
1700 (unsigned long) address_expr->X_add_number);
1702 (((address_expr->X_add_number & 0x7c0000) << 3)
1703 | ((address_expr->X_add_number & 0xf800000) >> 7)
1704 | ((address_expr->X_add_number & 0x3fffc) >> 2));
1707 case BFD_RELOC_16_PCREL_S2:
1717 /* Don't generate a reloc if we are writing into a variant
1721 fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1723 reloc_type == BFD_RELOC_16_PCREL_S2,
1727 struct mips_hi_fixup *hi_fixup;
1729 assert (reloc_type == BFD_RELOC_HI16_S);
1730 hi_fixup = ((struct mips_hi_fixup *)
1731 xmalloc (sizeof (struct mips_hi_fixup)));
1732 hi_fixup->fixp = fixp;
1733 hi_fixup->seg = now_seg;
1734 hi_fixup->next = mips_hi_fixup_list;
1735 mips_hi_fixup_list = hi_fixup;
1741 if (! mips_opts.mips16)
1742 md_number_to_chars (f, ip->insn_opcode, 4);
1743 else if (reloc_type == BFD_RELOC_MIPS16_JMP)
1745 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
1746 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
1752 md_number_to_chars (f, 0xf000 | ip->extend, 2);
1755 md_number_to_chars (f, ip->insn_opcode, 2);
1758 /* Update the register mask information. */
1759 if (! mips_opts.mips16)
1761 if (pinfo & INSN_WRITE_GPR_D)
1762 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
1763 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
1764 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
1765 if (pinfo & INSN_READ_GPR_S)
1766 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
1767 if (pinfo & INSN_WRITE_GPR_31)
1768 mips_gprmask |= 1 << 31;
1769 if (pinfo & INSN_WRITE_FPR_D)
1770 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
1771 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
1772 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
1773 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
1774 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
1775 if ((pinfo & INSN_READ_FPR_R) != 0)
1776 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
1777 if (pinfo & INSN_COP)
1779 /* We don't keep enough information to sort these cases out.
1780 The itbl support does keep this information however, although
1781 we currently don't support itbl fprmats as part of the cop
1782 instruction. May want to add this support in the future. */
1784 /* Never set the bit for $0, which is always zero. */
1785 mips_gprmask &=~ 1 << 0;
1789 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
1790 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
1791 & MIPS16OP_MASK_RX);
1792 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
1793 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
1794 & MIPS16OP_MASK_RY);
1795 if (pinfo & MIPS16_INSN_WRITE_Z)
1796 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
1797 & MIPS16OP_MASK_RZ);
1798 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
1799 mips_gprmask |= 1 << TREG;
1800 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
1801 mips_gprmask |= 1 << SP;
1802 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
1803 mips_gprmask |= 1 << RA;
1804 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
1805 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
1806 if (pinfo & MIPS16_INSN_READ_Z)
1807 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1808 & MIPS16OP_MASK_MOVE32Z);
1809 if (pinfo & MIPS16_INSN_READ_GPR_X)
1810 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1811 & MIPS16OP_MASK_REGR32);
1814 if (place == NULL && ! mips_opts.noreorder)
1816 /* Filling the branch delay slot is more complex. We try to
1817 switch the branch with the previous instruction, which we can
1818 do if the previous instruction does not set up a condition
1819 that the branch tests and if the branch is not itself the
1820 target of any branch. */
1821 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
1822 || (pinfo & INSN_COND_BRANCH_DELAY))
1824 if (mips_optimize < 2
1825 /* If we have seen .set volatile or .set nomove, don't
1827 || mips_opts.nomove != 0
1828 /* If we had to emit any NOP instructions, then we
1829 already know we can not swap. */
1831 /* If we don't even know the previous insn, we can not
1833 || ! prev_insn_valid
1834 /* If the previous insn is already in a branch delay
1835 slot, then we can not swap. */
1836 || prev_insn_is_delay_slot
1837 /* If the previous previous insn was in a .set
1838 noreorder, we can't swap. Actually, the MIPS
1839 assembler will swap in this situation. However, gcc
1840 configured -with-gnu-as will generate code like
1846 in which we can not swap the bne and INSN. If gcc is
1847 not configured -with-gnu-as, it does not output the
1848 .set pseudo-ops. We don't have to check
1849 prev_insn_unreordered, because prev_insn_valid will
1850 be 0 in that case. We don't want to use
1851 prev_prev_insn_valid, because we do want to be able
1852 to swap at the start of a function. */
1853 || prev_prev_insn_unreordered
1854 /* If the branch is itself the target of a branch, we
1855 can not swap. We cheat on this; all we check for is
1856 whether there is a label on this instruction. If
1857 there are any branches to anything other than a
1858 label, users must use .set noreorder. */
1859 || insn_labels != NULL
1860 /* If the previous instruction is in a variant frag, we
1861 can not do the swap. This does not apply to the
1862 mips16, which uses variant frags for different
1864 || (! mips_opts.mips16
1865 && prev_insn_frag->fr_type == rs_machine_dependent)
1866 /* If the branch reads the condition codes, we don't
1867 even try to swap, because in the sequence
1872 we can not swap, and I don't feel like handling that
1874 || (! mips_opts.mips16
1875 && mips_opts.isa < 4
1876 && (pinfo & INSN_READ_COND_CODE))
1877 /* We can not swap with an instruction that requires a
1878 delay slot, becase the target of the branch might
1879 interfere with that instruction. */
1880 || (! mips_opts.mips16
1881 && mips_opts.isa < 4
1883 /* Itbl support may require additional care here. */
1884 & (INSN_LOAD_COPROC_DELAY
1885 | INSN_COPROC_MOVE_DELAY
1886 | INSN_WRITE_COND_CODE)))
1887 || (! hilo_interlocks
1891 || (! mips_opts.mips16
1893 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
1894 || (! mips_opts.mips16
1895 && mips_opts.isa < 2
1896 /* Itbl support may require additional care here. */
1897 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
1898 /* We can not swap with a branch instruction. */
1900 & (INSN_UNCOND_BRANCH_DELAY
1901 | INSN_COND_BRANCH_DELAY
1902 | INSN_COND_BRANCH_LIKELY))
1903 /* We do not swap with a trap instruction, since it
1904 complicates trap handlers to have the trap
1905 instruction be in a delay slot. */
1906 || (prev_pinfo & INSN_TRAP)
1907 /* If the branch reads a register that the previous
1908 instruction sets, we can not swap. */
1909 || (! mips_opts.mips16
1910 && (prev_pinfo & INSN_WRITE_GPR_T)
1911 && insn_uses_reg (ip,
1912 ((prev_insn.insn_opcode >> OP_SH_RT)
1915 || (! mips_opts.mips16
1916 && (prev_pinfo & INSN_WRITE_GPR_D)
1917 && insn_uses_reg (ip,
1918 ((prev_insn.insn_opcode >> OP_SH_RD)
1921 || (mips_opts.mips16
1922 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
1923 && insn_uses_reg (ip,
1924 ((prev_insn.insn_opcode
1926 & MIPS16OP_MASK_RX),
1928 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
1929 && insn_uses_reg (ip,
1930 ((prev_insn.insn_opcode
1932 & MIPS16OP_MASK_RY),
1934 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
1935 && insn_uses_reg (ip,
1936 ((prev_insn.insn_opcode
1938 & MIPS16OP_MASK_RZ),
1940 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
1941 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
1942 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
1943 && insn_uses_reg (ip, RA, MIPS_GR_REG))
1944 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
1945 && insn_uses_reg (ip,
1946 MIPS16OP_EXTRACT_REG32R (prev_insn.
1949 /* If the branch writes a register that the previous
1950 instruction sets, we can not swap (we know that
1951 branches write only to RD or to $31). */
1952 || (! mips_opts.mips16
1953 && (prev_pinfo & INSN_WRITE_GPR_T)
1954 && (((pinfo & INSN_WRITE_GPR_D)
1955 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
1956 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
1957 || ((pinfo & INSN_WRITE_GPR_31)
1958 && (((prev_insn.insn_opcode >> OP_SH_RT)
1961 || (! mips_opts.mips16
1962 && (prev_pinfo & INSN_WRITE_GPR_D)
1963 && (((pinfo & INSN_WRITE_GPR_D)
1964 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
1965 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
1966 || ((pinfo & INSN_WRITE_GPR_31)
1967 && (((prev_insn.insn_opcode >> OP_SH_RD)
1970 || (mips_opts.mips16
1971 && (pinfo & MIPS16_INSN_WRITE_31)
1972 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
1973 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
1974 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
1976 /* If the branch writes a register that the previous
1977 instruction reads, we can not swap (we know that
1978 branches only write to RD or to $31). */
1979 || (! mips_opts.mips16
1980 && (pinfo & INSN_WRITE_GPR_D)
1981 && insn_uses_reg (&prev_insn,
1982 ((ip->insn_opcode >> OP_SH_RD)
1985 || (! mips_opts.mips16
1986 && (pinfo & INSN_WRITE_GPR_31)
1987 && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG))
1988 || (mips_opts.mips16
1989 && (pinfo & MIPS16_INSN_WRITE_31)
1990 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
1991 /* If we are generating embedded PIC code, the branch
1992 might be expanded into a sequence which uses $at, so
1993 we can't swap with an instruction which reads it. */
1994 || (mips_pic == EMBEDDED_PIC
1995 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
1996 /* If the previous previous instruction has a load
1997 delay, and sets a register that the branch reads, we
1999 || (! mips_opts.mips16
2000 && mips_opts.isa < 4
2001 /* Itbl support may require additional care here. */
2002 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2003 || (! gpr_interlocks
2004 && (prev_prev_insn.insn_mo->pinfo
2005 & INSN_LOAD_MEMORY_DELAY)))
2006 && insn_uses_reg (ip,
2007 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2010 /* If one instruction sets a condition code and the
2011 other one uses a condition code, we can not swap. */
2012 || ((pinfo & INSN_READ_COND_CODE)
2013 && (prev_pinfo & INSN_WRITE_COND_CODE))
2014 || ((pinfo & INSN_WRITE_COND_CODE)
2015 && (prev_pinfo & INSN_READ_COND_CODE))
2016 /* If the previous instruction uses the PC, we can not
2018 || (mips_opts.mips16
2019 && (prev_pinfo & MIPS16_INSN_READ_PC))
2020 /* If the previous instruction was extended, we can not
2022 || (mips_opts.mips16 && prev_insn_extended)
2023 /* If the previous instruction had a fixup in mips16
2024 mode, we can not swap. This normally means that the
2025 previous instruction was a 4 byte branch anyhow. */
2026 || (mips_opts.mips16 && prev_insn_fixp))
2028 /* We could do even better for unconditional branches to
2029 portions of this object file; we could pick up the
2030 instruction at the destination, put it in the delay
2031 slot, and bump the destination address. */
2033 /* Update the previous insn information. */
2034 prev_prev_insn = *ip;
2035 prev_insn.insn_mo = &dummy_opcode;
2039 /* It looks like we can actually do the swap. */
2040 if (! mips_opts.mips16)
2045 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2046 memcpy (temp, prev_f, 4);
2047 memcpy (prev_f, f, 4);
2048 memcpy (f, temp, 4);
2051 prev_insn_fixp->fx_frag = frag_now;
2052 prev_insn_fixp->fx_where = f - frag_now->fr_literal;
2056 fixp->fx_frag = prev_insn_frag;
2057 fixp->fx_where = prev_insn_where;
2065 assert (prev_insn_fixp == NULL);
2066 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2067 memcpy (temp, prev_f, 2);
2068 memcpy (prev_f, f, 2);
2069 if (reloc_type != BFD_RELOC_MIPS16_JMP)
2071 assert (reloc_type == BFD_RELOC_UNUSED);
2072 memcpy (f, temp, 2);
2076 memcpy (f, f + 2, 2);
2077 memcpy (f + 2, temp, 2);
2081 fixp->fx_frag = prev_insn_frag;
2082 fixp->fx_where = prev_insn_where;
2086 /* Update the previous insn information; leave prev_insn
2088 prev_prev_insn = *ip;
2090 prev_insn_is_delay_slot = 1;
2092 /* If that was an unconditional branch, forget the previous
2093 insn information. */
2094 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2096 prev_prev_insn.insn_mo = &dummy_opcode;
2097 prev_insn.insn_mo = &dummy_opcode;
2100 prev_insn_fixp = NULL;
2101 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2102 prev_insn_extended = 0;
2104 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2106 /* We don't yet optimize a branch likely. What we should do
2107 is look at the target, copy the instruction found there
2108 into the delay slot, and increment the branch to jump to
2109 the next instruction. */
2111 /* Update the previous insn information. */
2112 prev_prev_insn = *ip;
2113 prev_insn.insn_mo = &dummy_opcode;
2114 prev_insn_fixp = NULL;
2115 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2116 prev_insn_extended = 0;
2120 /* Update the previous insn information. */
2122 prev_prev_insn.insn_mo = &dummy_opcode;
2124 prev_prev_insn = prev_insn;
2127 /* Any time we see a branch, we always fill the delay slot
2128 immediately; since this insn is not a branch, we know it
2129 is not in a delay slot. */
2130 prev_insn_is_delay_slot = 0;
2132 prev_insn_fixp = fixp;
2133 prev_insn_reloc_type = reloc_type;
2134 if (mips_opts.mips16)
2135 prev_insn_extended = (ip->use_extend
2136 || reloc_type > BFD_RELOC_UNUSED);
2139 prev_prev_insn_unreordered = prev_insn_unreordered;
2140 prev_insn_unreordered = 0;
2141 prev_insn_frag = frag_now;
2142 prev_insn_where = f - frag_now->fr_literal;
2143 prev_insn_valid = 1;
2145 else if (place == NULL)
2147 /* We need to record a bit of information even when we are not
2148 reordering, in order to determine the base address for mips16
2149 PC relative relocs. */
2150 prev_prev_insn = prev_insn;
2152 prev_insn_reloc_type = reloc_type;
2153 prev_prev_insn_unreordered = prev_insn_unreordered;
2154 prev_insn_unreordered = 1;
2157 /* We just output an insn, so the next one doesn't have a label. */
2158 mips_clear_insn_labels ();
2161 /* This function forgets that there was any previous instruction or
2162 label. If PRESERVE is non-zero, it remembers enough information to
2163 know whether nops are needed before a noreorder section. */
2166 mips_no_prev_insn (preserve)
2171 prev_insn.insn_mo = &dummy_opcode;
2172 prev_prev_insn.insn_mo = &dummy_opcode;
2173 prev_nop_frag = NULL;
2174 prev_nop_frag_holds = 0;
2175 prev_nop_frag_required = 0;
2176 prev_nop_frag_since = 0;
2178 prev_insn_valid = 0;
2179 prev_insn_is_delay_slot = 0;
2180 prev_insn_unreordered = 0;
2181 prev_insn_extended = 0;
2182 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2183 prev_prev_insn_unreordered = 0;
2184 mips_clear_insn_labels ();
2187 /* This function must be called whenever we turn on noreorder or emit
2188 something other than instructions. It inserts any NOPS which might
2189 be needed by the previous instruction, and clears the information
2190 kept for the previous instructions. The INSNS parameter is true if
2191 instructions are to follow. */
2194 mips_emit_delays (insns)
2197 if (! mips_opts.noreorder)
2202 if ((! mips_opts.mips16
2203 && mips_opts.isa < 4
2204 && (! cop_interlocks
2205 && (prev_insn.insn_mo->pinfo
2206 & (INSN_LOAD_COPROC_DELAY
2207 | INSN_COPROC_MOVE_DELAY
2208 | INSN_WRITE_COND_CODE))))
2209 || (! hilo_interlocks
2210 && (prev_insn.insn_mo->pinfo
2213 || (! mips_opts.mips16
2215 && (prev_insn.insn_mo->pinfo
2216 & INSN_LOAD_MEMORY_DELAY))
2217 || (! mips_opts.mips16
2218 && mips_opts.isa < 2
2219 && (prev_insn.insn_mo->pinfo
2220 & INSN_COPROC_MEMORY_DELAY)))
2222 /* Itbl support may require additional care here. */
2224 if ((! mips_opts.mips16
2225 && mips_opts.isa < 4
2226 && (! cop_interlocks
2227 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2228 || (! hilo_interlocks
2229 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2230 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2233 if (prev_insn_unreordered)
2236 else if ((! mips_opts.mips16
2237 && mips_opts.isa < 4
2238 && (! cop_interlocks
2239 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2240 || (! hilo_interlocks
2241 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2242 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2244 /* Itbl support may require additional care here. */
2245 if (! prev_prev_insn_unreordered)
2251 struct insn_label_list *l;
2255 /* Record the frag which holds the nop instructions, so
2256 that we can remove them if we don't need them. */
2257 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2258 prev_nop_frag = frag_now;
2259 prev_nop_frag_holds = nops;
2260 prev_nop_frag_required = 0;
2261 prev_nop_frag_since = 0;
2264 for (; nops > 0; --nops)
2269 /* Move on to a new frag, so that it is safe to simply
2270 decrease the size of prev_nop_frag. */
2271 frag_wane (frag_now);
2275 for (l = insn_labels; l != NULL; l = l->next)
2277 assert (S_GET_SEGMENT (l->label) == now_seg);
2278 l->label->sy_frag = frag_now;
2279 S_SET_VALUE (l->label, (valueT) frag_now_fix ());
2280 /* mips16 text labels are stored as odd. */
2281 if (mips_opts.mips16)
2282 ++l->label->sy_value.X_add_number;
2287 /* Mark instruction labels in mips16 mode. */
2288 if (mips_opts.mips16 && insns)
2289 mips16_mark_labels ();
2291 mips_no_prev_insn (insns);
2294 /* Build an instruction created by a macro expansion. This is passed
2295 a pointer to the count of instructions created so far, an
2296 expression, the name of the instruction to build, an operand format
2297 string, and corresponding arguments. */
2301 macro_build (char *place,
2309 macro_build (place, counter, ep, name, fmt, va_alist)
2318 struct mips_cl_insn insn;
2319 bfd_reloc_code_real_type r;
2324 va_start (args, fmt);
2330 * If the macro is about to expand into a second instruction,
2331 * print a warning if needed. We need to pass ip as a parameter
2332 * to generate a better warning message here...
2334 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2335 as_warn ("Macro instruction expanded into multiple instructions");
2338 *counter += 1; /* bump instruction counter */
2340 if (mips_opts.mips16)
2342 mips16_macro_build (place, counter, ep, name, fmt, args);
2347 r = BFD_RELOC_UNUSED;
2348 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2349 assert (insn.insn_mo);
2350 assert (strcmp (name, insn.insn_mo->name) == 0);
2352 /* Search until we get a match for NAME. */
2355 if (insn.insn_mo->pinfo == INSN_MACRO)
2356 insn_isa = insn.insn_mo->match;
2357 else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA1)
2359 else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA2)
2361 else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA3)
2363 else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA4)
2368 if (strcmp (fmt, insn.insn_mo->args) == 0
2369 && insn.insn_mo->pinfo != INSN_MACRO
2370 && (insn_isa <= mips_opts.isa
2372 && (insn.insn_mo->membership & INSN_4650) != 0)
2374 && (insn.insn_mo->membership & INSN_4010) != 0)
2376 && (insn.insn_mo->membership & INSN_4100) != 0)
2377 /* start-sanitize-r5900 */
2379 && (insn.insn_mo->membership & INSN_5900) != 0)
2380 /* end-sanitize-r5900 */
2382 && (insn.insn_mo->membership & INSN_3900) != 0))
2383 /* start-sanitize-r5900 */
2384 && (! mips_5900 || (insn.insn_mo->pinfo & FP_D) == 0)
2385 /* end-sanitize-r5900 */
2386 && (! mips_4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2390 assert (insn.insn_mo->name);
2391 assert (strcmp (name, insn.insn_mo->name) == 0);
2394 insn.insn_opcode = insn.insn_mo->match;
2410 insn.insn_opcode |= va_arg (args, int) << 16;
2416 insn.insn_opcode |= va_arg (args, int) << 16;
2421 insn.insn_opcode |= va_arg (args, int) << 11;
2426 insn.insn_opcode |= va_arg (args, int) << 11;
2433 insn.insn_opcode |= va_arg (args, int) << 6;
2437 insn.insn_opcode |= va_arg (args, int) << 6;
2441 insn.insn_opcode |= va_arg (args, int) << 6;
2448 insn.insn_opcode |= va_arg (args, int) << 21;
2454 r = (bfd_reloc_code_real_type) va_arg (args, int);
2455 assert (r == BFD_RELOC_MIPS_GPREL
2456 || r == BFD_RELOC_MIPS_LITERAL
2457 || r == BFD_RELOC_LO16
2458 || r == BFD_RELOC_MIPS_GOT16
2459 || r == BFD_RELOC_MIPS_CALL16
2460 || r == BFD_RELOC_MIPS_GOT_LO16
2461 || r == BFD_RELOC_MIPS_CALL_LO16
2462 || (ep->X_op == O_subtract
2463 && now_seg == text_section
2464 && r == BFD_RELOC_PCREL_LO16));
2468 r = (bfd_reloc_code_real_type) va_arg (args, int);
2470 && (ep->X_op == O_constant
2471 || (ep->X_op == O_symbol
2472 && (r == BFD_RELOC_HI16_S
2473 || r == BFD_RELOC_HI16
2474 || r == BFD_RELOC_MIPS_GOT_HI16
2475 || r == BFD_RELOC_MIPS_CALL_HI16))
2476 || (ep->X_op == O_subtract
2477 && now_seg == text_section
2478 && r == BFD_RELOC_PCREL_HI16_S)));
2479 if (ep->X_op == O_constant)
2481 insn.insn_opcode |= (ep->X_add_number >> 16) & 0xffff;
2483 r = BFD_RELOC_UNUSED;
2488 assert (ep != NULL);
2490 * This allows macro() to pass an immediate expression for
2491 * creating short branches without creating a symbol.
2492 * Note that the expression still might come from the assembly
2493 * input, in which case the value is not checked for range nor
2494 * is a relocation entry generated (yuck).
2496 if (ep->X_op == O_constant)
2498 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
2502 r = BFD_RELOC_16_PCREL_S2;
2506 assert (ep != NULL);
2507 r = BFD_RELOC_MIPS_JMP;
2516 assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2518 append_insn (place, &insn, ep, r, false);
2522 mips16_macro_build (place, counter, ep, name, fmt, args)
2530 struct mips_cl_insn insn;
2531 bfd_reloc_code_real_type r;
2533 r = BFD_RELOC_UNUSED;
2534 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
2535 assert (insn.insn_mo);
2536 assert (strcmp (name, insn.insn_mo->name) == 0);
2538 while (strcmp (fmt, insn.insn_mo->args) != 0
2539 || insn.insn_mo->pinfo == INSN_MACRO)
2542 assert (insn.insn_mo->name);
2543 assert (strcmp (name, insn.insn_mo->name) == 0);
2546 insn.insn_opcode = insn.insn_mo->match;
2547 insn.use_extend = false;
2566 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
2571 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
2575 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
2579 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
2589 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
2596 regno = va_arg (args, int);
2597 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
2598 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
2619 assert (ep != NULL);
2621 if (ep->X_op != O_constant)
2622 r = BFD_RELOC_UNUSED + c;
2625 mips16_immed ((char *) NULL, 0, c, ep->X_add_number, false,
2626 false, false, &insn.insn_opcode,
2627 &insn.use_extend, &insn.extend);
2629 r = BFD_RELOC_UNUSED;
2635 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
2642 assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2644 append_insn (place, &insn, ep, r, false);
2648 * Generate a "lui" instruction.
2651 macro_build_lui (place, counter, ep, regnum)
2657 expressionS high_expr;
2658 struct mips_cl_insn insn;
2659 bfd_reloc_code_real_type r;
2660 CONST char *name = "lui";
2661 CONST char *fmt = "t,u";
2663 assert (! mips_opts.mips16);
2669 high_expr.X_op = O_constant;
2670 high_expr.X_add_number = ep->X_add_number;
2673 if (high_expr.X_op == O_constant)
2675 /* we can compute the instruction now without a relocation entry */
2676 if (high_expr.X_add_number & 0x8000)
2677 high_expr.X_add_number += 0x10000;
2678 high_expr.X_add_number =
2679 ((unsigned long) high_expr.X_add_number >> 16) & 0xffff;
2680 r = BFD_RELOC_UNUSED;
2684 assert (ep->X_op == O_symbol);
2685 /* _gp_disp is a special case, used from s_cpload. */
2686 assert (mips_pic == NO_PIC
2687 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
2688 r = BFD_RELOC_HI16_S;
2692 * If the macro is about to expand into a second instruction,
2693 * print a warning if needed. We need to pass ip as a parameter
2694 * to generate a better warning message here...
2696 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2697 as_warn ("Macro instruction expanded into multiple instructions");
2700 *counter += 1; /* bump instruction counter */
2702 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2703 assert (insn.insn_mo);
2704 assert (strcmp (name, insn.insn_mo->name) == 0);
2705 assert (strcmp (fmt, insn.insn_mo->args) == 0);
2707 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
2708 if (r == BFD_RELOC_UNUSED)
2710 insn.insn_opcode |= high_expr.X_add_number;
2711 append_insn (place, &insn, NULL, r, false);
2714 append_insn (place, &insn, &high_expr, r, false);
2718 * Generates code to set the $at register to true (one)
2719 * if reg is less than the immediate expression.
2722 set_at (counter, reg, unsignedp)
2727 if (imm_expr.X_op == O_constant
2728 && imm_expr.X_add_number >= -0x8000
2729 && imm_expr.X_add_number < 0x8000)
2730 macro_build ((char *) NULL, counter, &imm_expr,
2731 unsignedp ? "sltiu" : "slti",
2732 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
2735 load_register (counter, AT, &imm_expr, 0);
2736 macro_build ((char *) NULL, counter, NULL,
2737 unsignedp ? "sltu" : "slt",
2738 "d,v,t", AT, reg, AT);
2742 /* Warn if an expression is not a constant. */
2745 check_absolute_expr (ip, ex)
2746 struct mips_cl_insn *ip;
2749 if (ex->X_op == O_big)
2750 as_bad ("unsupported large constant");
2751 else if (ex->X_op != O_constant)
2752 as_bad ("Instruction %s requires absolute expression", ip->insn_mo->name);
2755 /* Count the leading zeroes by performing a binary chop. This is a
2756 bulky bit of source, but performance is a LOT better for the
2757 majority of values than a simple loop to count the bits:
2758 for (lcnt = 0; (lcnt < 32); lcnt++)
2759 if ((v) & (1 << (31 - lcnt)))
2761 However it is not code size friendly, and the gain will drop a bit
2762 on certain cached systems.
2764 #define COUNT_TOP_ZEROES(v) \
2765 (((v) & ~0xffff) == 0 \
2766 ? ((v) & ~0xff) == 0 \
2767 ? ((v) & ~0xf) == 0 \
2768 ? ((v) & ~0x3) == 0 \
2769 ? ((v) & ~0x1) == 0 \
2774 : ((v) & ~0x7) == 0 \
2777 : ((v) & ~0x3f) == 0 \
2778 ? ((v) & ~0x1f) == 0 \
2781 : ((v) & ~0x7f) == 0 \
2784 : ((v) & ~0xfff) == 0 \
2785 ? ((v) & ~0x3ff) == 0 \
2786 ? ((v) & ~0x1ff) == 0 \
2789 : ((v) & ~0x7ff) == 0 \
2792 : ((v) & ~0x3fff) == 0 \
2793 ? ((v) & ~0x1fff) == 0 \
2796 : ((v) & ~0x7fff) == 0 \
2799 : ((v) & ~0xffffff) == 0 \
2800 ? ((v) & ~0xfffff) == 0 \
2801 ? ((v) & ~0x3ffff) == 0 \
2802 ? ((v) & ~0x1ffff) == 0 \
2805 : ((v) & ~0x7ffff) == 0 \
2808 : ((v) & ~0x3fffff) == 0 \
2809 ? ((v) & ~0x1fffff) == 0 \
2812 : ((v) & ~0x7fffff) == 0 \
2815 : ((v) & ~0xfffffff) == 0 \
2816 ? ((v) & ~0x3ffffff) == 0 \
2817 ? ((v) & ~0x1ffffff) == 0 \
2820 : ((v) & ~0x7ffffff) == 0 \
2823 : ((v) & ~0x3fffffff) == 0 \
2824 ? ((v) & ~0x1fffffff) == 0 \
2827 : ((v) & ~0x7fffffff) == 0 \
2832 * This routine generates the least number of instructions neccessary to load
2833 * an absolute expression value into a register.
2836 load_register (counter, reg, ep, dbl)
2843 expressionS hi32, lo32;
2845 if (ep->X_op != O_big)
2847 assert (ep->X_op == O_constant);
2848 if (ep->X_add_number < 0x8000
2849 && (ep->X_add_number >= 0
2850 || (ep->X_add_number >= -0x8000
2853 || sizeof (ep->X_add_number) > 4))))
2855 /* We can handle 16 bit signed values with an addiu to
2856 $zero. No need to ever use daddiu here, since $zero and
2857 the result are always correct in 32 bit mode. */
2858 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
2859 (int) BFD_RELOC_LO16);
2862 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
2864 /* We can handle 16 bit unsigned values with an ori to
2866 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
2867 (int) BFD_RELOC_LO16);
2870 else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0
2871 || ((ep->X_add_number &~ (offsetT) 0x7fffffff)
2872 == ~ (offsetT) 0x7fffffff))
2875 || sizeof (ep->X_add_number) > 4
2876 || (ep->X_add_number & 0x80000000) == 0))
2877 || ((mips_opts.isa < 3 || ! dbl)
2878 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
2879 || (mips_opts.isa < 3
2881 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
2882 == ~ (offsetT) 0xffffffff)))
2884 /* 32 bit values require an lui. */
2885 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
2886 (int) BFD_RELOC_HI16);
2887 if ((ep->X_add_number & 0xffff) != 0)
2888 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
2889 (int) BFD_RELOC_LO16);
2894 /* The value is larger than 32 bits. */
2896 if (mips_opts.isa < 3)
2898 as_bad ("Number larger than 32 bits");
2899 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
2900 (int) BFD_RELOC_LO16);
2904 if (ep->X_op != O_big)
2907 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
2908 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
2909 hi32.X_add_number &= 0xffffffff;
2911 lo32.X_add_number &= 0xffffffff;
2915 assert (ep->X_add_number > 2);
2916 if (ep->X_add_number == 3)
2917 generic_bignum[3] = 0;
2918 else if (ep->X_add_number > 4)
2919 as_bad ("Number larger than 64 bits");
2920 lo32.X_op = O_constant;
2921 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
2922 hi32.X_op = O_constant;
2923 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
2926 if (hi32.X_add_number == 0)
2931 unsigned long hi, lo;
2933 if (hi32.X_add_number == 0xffffffff)
2935 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
2937 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
2938 reg, 0, (int) BFD_RELOC_LO16);
2941 if (lo32.X_add_number & 0x80000000)
2943 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
2944 (int) BFD_RELOC_HI16);
2945 if (lo32.X_add_number & 0xffff)
2946 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
2947 reg, reg, (int) BFD_RELOC_LO16);
2952 /* Check for 16bit shifted constant. We know that hi32 is
2953 non-zero, so start the mask on the first bit of the hi32
2958 unsigned long himask, lomask;
2962 himask = 0xffff >> (32 - shift);
2963 lomask = (0xffff << shift) & 0xffffffff;
2967 himask = 0xffff << (shift - 32);
2970 if ((hi32.X_add_number & ~ (offsetT) himask) == 0
2971 && (lo32.X_add_number & ~ (offsetT) lomask) == 0)
2975 tmp.X_op = O_constant;
2977 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
2978 | (lo32.X_add_number >> shift));
2980 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
2981 macro_build ((char *) NULL, counter, &tmp, "ori", "t,r,i", reg, 0,
2982 (int) BFD_RELOC_LO16);
2983 macro_build ((char *) NULL, counter, NULL,
2984 (shift >= 32) ? "dsll32" : "dsll",
2986 (shift >= 32) ? shift - 32 : shift);
2990 } while (shift <= (64 - 16));
2992 /* Find the bit number of the lowest one bit, and store the
2993 shifted value in hi/lo. */
2994 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
2995 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
2999 while ((lo & 1) == 0)
3004 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3010 while ((hi & 1) == 0)
3019 /* Optimize if the shifted value is a (power of 2) - 1. */
3020 if ((hi == 0 && ((lo + 1) & lo) == 0)
3021 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3023 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3028 /* This instruction will set the register to be all
3030 tmp.X_op = O_constant;
3031 tmp.X_add_number = (offsetT) -1;
3032 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3033 reg, 0, (int) BFD_RELOC_LO16);
3037 macro_build ((char *) NULL, counter, NULL,
3038 (bit >= 32) ? "dsll32" : "dsll",
3040 (bit >= 32) ? bit - 32 : bit);
3042 macro_build ((char *) NULL, counter, NULL,
3043 (shift >= 32) ? "dsrl32" : "dsrl",
3045 (shift >= 32) ? shift - 32 : shift);
3050 /* Sign extend hi32 before calling load_register, because we can
3051 generally get better code when we load a sign extended value. */
3052 if ((hi32.X_add_number & 0x80000000) != 0)
3053 hi32.X_add_number |= ~ (offsetT) 0xffffffff;
3054 load_register (counter, reg, &hi32, 0);
3057 if ((lo32.X_add_number & 0xffff0000) == 0)
3061 macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg,
3070 if ((freg == 0) && (lo32.X_add_number == 0xffffffff))
3072 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3073 (int) BFD_RELOC_HI16);
3074 macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg,
3081 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
3086 mid16.X_add_number >>= 16;
3087 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3088 freg, (int) BFD_RELOC_LO16);
3089 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
3093 if ((lo32.X_add_number & 0xffff) != 0)
3094 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3095 (int) BFD_RELOC_LO16);
3098 /* Load an address into a register. */
3101 load_address (counter, reg, ep)
3108 if (ep->X_op != O_constant
3109 && ep->X_op != O_symbol)
3111 as_bad ("expression too complex");
3112 ep->X_op = O_constant;
3115 if (ep->X_op == O_constant)
3117 load_register (counter, reg, ep, 0);
3121 if (mips_pic == NO_PIC)
3123 /* If this is a reference to a GP relative symbol, we want
3124 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
3126 lui $reg,<sym> (BFD_RELOC_HI16_S)
3127 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3128 If we have an addend, we always use the latter form. */
3129 if ((valueT) ep->X_add_number >= MAX_GPREL_OFFSET
3130 || nopic_need_relax (ep->X_add_symbol, 1))
3135 macro_build ((char *) NULL, counter, ep,
3136 mips_opts.isa < 3 ? "addiu" : "daddiu",
3137 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
3138 p = frag_var (rs_machine_dependent, 8, 0,
3139 RELAX_ENCODE (4, 8, 0, 4, 0,
3140 mips_opts.warn_about_macros),
3141 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3143 macro_build_lui (p, counter, ep, reg);
3146 macro_build (p, counter, ep,
3147 mips_opts.isa < 3 ? "addiu" : "daddiu",
3148 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3150 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3154 /* If this is a reference to an external symbol, we want
3155 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3157 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3159 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3160 If there is a constant, it must be added in after. */
3161 ex.X_add_number = ep->X_add_number;
3162 ep->X_add_number = 0;
3164 macro_build ((char *) NULL, counter, ep,
3165 mips_opts.isa < 3 ? "lw" : "ld",
3166 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3167 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3168 p = frag_var (rs_machine_dependent, 4, 0,
3169 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3170 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3171 macro_build (p, counter, ep,
3172 mips_opts.isa < 3 ? "addiu" : "daddiu",
3173 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3174 if (ex.X_add_number != 0)
3176 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3177 as_bad ("PIC code offset overflow (max 16 signed bits)");
3178 ex.X_op = O_constant;
3179 macro_build ((char *) NULL, counter, &ex,
3180 mips_opts.isa < 3 ? "addiu" : "daddiu",
3181 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3184 else if (mips_pic == SVR4_PIC)
3189 /* This is the large GOT case. If this is a reference to an
3190 external symbol, we want
3191 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3193 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3194 Otherwise, for a reference to a local symbol, we want
3195 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3197 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3198 If there is a constant, it must be added in after. */
3199 ex.X_add_number = ep->X_add_number;
3200 ep->X_add_number = 0;
3201 if (reg_needs_delay (GP))
3206 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3207 (int) BFD_RELOC_MIPS_GOT_HI16);
3208 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3209 mips_opts.isa < 3 ? "addu" : "daddu",
3210 "d,v,t", reg, reg, GP);
3211 macro_build ((char *) NULL, counter, ep,
3212 mips_opts.isa < 3 ? "lw" : "ld",
3213 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3214 p = frag_var (rs_machine_dependent, 12 + off, 0,
3215 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3216 mips_opts.warn_about_macros),
3217 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3220 /* We need a nop before loading from $gp. This special
3221 check is required because the lui which starts the main
3222 instruction stream does not refer to $gp, and so will not
3223 insert the nop which may be required. */
3224 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3227 macro_build (p, counter, ep,
3228 mips_opts.isa < 3 ? "lw" : "ld",
3229 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3231 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3233 macro_build (p, counter, ep,
3234 mips_opts.isa < 3 ? "addiu" : "daddiu",
3235 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3236 if (ex.X_add_number != 0)
3238 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3239 as_bad ("PIC code offset overflow (max 16 signed bits)");
3240 ex.X_op = O_constant;
3241 macro_build ((char *) NULL, counter, &ex,
3242 mips_opts.isa < 3 ? "addiu" : "daddiu",
3243 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3246 else if (mips_pic == EMBEDDED_PIC)
3249 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
3251 macro_build ((char *) NULL, counter, ep,
3252 mips_opts.isa < 3 ? "addiu" : "daddiu",
3253 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
3261 * This routine implements the seemingly endless macro or synthesized
3262 * instructions and addressing modes in the mips assembly language. Many
3263 * of these macros are simple and are similar to each other. These could
3264 * probably be handled by some kind of table or grammer aproach instead of
3265 * this verbose method. Others are not simple macros but are more like
3266 * optimizing code generation.
3267 * One interesting optimization is when several store macros appear
3268 * consecutivly that would load AT with the upper half of the same address.
3269 * The ensuing load upper instructions are ommited. This implies some kind
3270 * of global optimization. We currently only optimize within a single macro.
3271 * For many of the load and store macros if the address is specified as a
3272 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3273 * first load register 'at' with zero and use it as the base register. The
3274 * mips assembler simply uses register $zero. Just one tiny optimization
3279 struct mips_cl_insn *ip;
3281 register int treg, sreg, dreg, breg;
3296 bfd_reloc_code_real_type r;
3298 int hold_mips_optimize;
3300 assert (! mips_opts.mips16);
3302 treg = (ip->insn_opcode >> 16) & 0x1f;
3303 dreg = (ip->insn_opcode >> 11) & 0x1f;
3304 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3305 mask = ip->insn_mo->mask;
3307 expr1.X_op = O_constant;
3308 expr1.X_op_symbol = NULL;
3309 expr1.X_add_symbol = NULL;
3310 expr1.X_add_number = 1;
3322 mips_emit_delays (true);
3323 ++mips_opts.noreorder;
3324 mips_any_noreorder = 1;
3326 expr1.X_add_number = 8;
3327 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3329 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3331 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, sreg, 0);
3332 macro_build ((char *) NULL, &icnt, NULL,
3333 dbl ? "dsub" : "sub",
3334 "d,v,t", dreg, 0, sreg);
3336 --mips_opts.noreorder;
3357 if (imm_expr.X_op == O_constant
3358 && imm_expr.X_add_number >= -0x8000
3359 && imm_expr.X_add_number < 0x8000)
3361 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3362 (int) BFD_RELOC_LO16);
3365 load_register (&icnt, AT, &imm_expr, dbl);
3366 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
3385 if (imm_expr.X_op == O_constant
3386 && imm_expr.X_add_number >= 0
3387 && imm_expr.X_add_number < 0x10000)
3389 if (mask != M_NOR_I)
3390 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
3391 sreg, (int) BFD_RELOC_LO16);
3394 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
3395 treg, sreg, (int) BFD_RELOC_LO16);
3396 macro_build ((char *) NULL, &icnt, NULL, "nor", "d,v,t",
3402 load_register (&icnt, AT, &imm_expr, 0);
3403 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
3420 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3422 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
3426 load_register (&icnt, AT, &imm_expr, 0);
3427 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
3435 macro_build ((char *) NULL, &icnt, &offset_expr,
3436 likely ? "bgezl" : "bgez",
3442 macro_build ((char *) NULL, &icnt, &offset_expr,
3443 likely ? "blezl" : "blez",
3447 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
3448 macro_build ((char *) NULL, &icnt, &offset_expr,
3449 likely ? "beql" : "beq",
3456 /* check for > max integer */
3457 maxnum = 0x7fffffff;
3458 if (mips_opts.isa >= 3 && sizeof (maxnum) > 4)
3465 if (imm_expr.X_op == O_constant
3466 && imm_expr.X_add_number >= maxnum
3467 && (mips_opts.isa < 3 || sizeof (maxnum) > 4))
3470 /* result is always false */
3473 as_warn ("Branch %s is always false (nop)", ip->insn_mo->name);
3474 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3478 as_warn ("Branch likely %s is always false", ip->insn_mo->name);
3479 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
3484 if (imm_expr.X_op != O_constant)
3485 as_bad ("Unsupported large constant");
3486 imm_expr.X_add_number++;
3490 if (mask == M_BGEL_I)
3492 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3494 macro_build ((char *) NULL, &icnt, &offset_expr,
3495 likely ? "bgezl" : "bgez",
3499 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3501 macro_build ((char *) NULL, &icnt, &offset_expr,
3502 likely ? "bgtzl" : "bgtz",
3506 maxnum = 0x7fffffff;
3507 if (mips_opts.isa >= 3 && sizeof (maxnum) > 4)
3514 maxnum = - maxnum - 1;
3515 if (imm_expr.X_op == O_constant
3516 && imm_expr.X_add_number <= maxnum
3517 && (mips_opts.isa < 3 || sizeof (maxnum) > 4))
3520 /* result is always true */
3521 as_warn ("Branch %s is always true", ip->insn_mo->name);
3522 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
3525 set_at (&icnt, sreg, 0);
3526 macro_build ((char *) NULL, &icnt, &offset_expr,
3527 likely ? "beql" : "beq",
3538 macro_build ((char *) NULL, &icnt, &offset_expr,
3539 likely ? "beql" : "beq",
3543 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
3545 macro_build ((char *) NULL, &icnt, &offset_expr,
3546 likely ? "beql" : "beq",
3554 || (mips_opts.isa < 3
3555 && imm_expr.X_op == O_constant
3556 && imm_expr.X_add_number == 0xffffffff))
3558 if (imm_expr.X_op != O_constant)
3559 as_bad ("Unsupported large constant");
3560 imm_expr.X_add_number++;
3564 if (mask == M_BGEUL_I)
3566 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3568 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3570 macro_build ((char *) NULL, &icnt, &offset_expr,
3571 likely ? "bnel" : "bne",
3575 set_at (&icnt, sreg, 1);
3576 macro_build ((char *) NULL, &icnt, &offset_expr,
3577 likely ? "beql" : "beq",
3586 macro_build ((char *) NULL, &icnt, &offset_expr,
3587 likely ? "bgtzl" : "bgtz",
3593 macro_build ((char *) NULL, &icnt, &offset_expr,
3594 likely ? "bltzl" : "bltz",
3598 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
3599 macro_build ((char *) NULL, &icnt, &offset_expr,
3600 likely ? "bnel" : "bne",
3609 macro_build ((char *) NULL, &icnt, &offset_expr,
3610 likely ? "bnel" : "bne",
3616 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
3618 macro_build ((char *) NULL, &icnt, &offset_expr,
3619 likely ? "bnel" : "bne",
3628 macro_build ((char *) NULL, &icnt, &offset_expr,
3629 likely ? "blezl" : "blez",
3635 macro_build ((char *) NULL, &icnt, &offset_expr,
3636 likely ? "bgezl" : "bgez",
3640 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
3641 macro_build ((char *) NULL, &icnt, &offset_expr,
3642 likely ? "beql" : "beq",
3649 maxnum = 0x7fffffff;
3650 if (mips_opts.isa >= 3 && sizeof (maxnum) > 4)
3657 if (imm_expr.X_op == O_constant
3658 && imm_expr.X_add_number >= maxnum
3659 && (mips_opts.isa < 3 || sizeof (maxnum) > 4))
3661 if (imm_expr.X_op != O_constant)
3662 as_bad ("Unsupported large constant");
3663 imm_expr.X_add_number++;
3667 if (mask == M_BLTL_I)
3669 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3671 macro_build ((char *) NULL, &icnt, &offset_expr,
3672 likely ? "bltzl" : "bltz",
3676 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3678 macro_build ((char *) NULL, &icnt, &offset_expr,
3679 likely ? "blezl" : "blez",
3683 set_at (&icnt, sreg, 0);
3684 macro_build ((char *) NULL, &icnt, &offset_expr,
3685 likely ? "bnel" : "bne",
3694 macro_build ((char *) NULL, &icnt, &offset_expr,
3695 likely ? "beql" : "beq",
3701 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
3703 macro_build ((char *) NULL, &icnt, &offset_expr,
3704 likely ? "beql" : "beq",
3712 || (mips_opts.isa < 3
3713 && imm_expr.X_op == O_constant
3714 && imm_expr.X_add_number == 0xffffffff))
3716 if (imm_expr.X_op != O_constant)
3717 as_bad ("Unsupported large constant");
3718 imm_expr.X_add_number++;
3722 if (mask == M_BLTUL_I)
3724 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3726 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3728 macro_build ((char *) NULL, &icnt, &offset_expr,
3729 likely ? "beql" : "beq",
3733 set_at (&icnt, sreg, 1);
3734 macro_build ((char *) NULL, &icnt, &offset_expr,
3735 likely ? "bnel" : "bne",
3744 macro_build ((char *) NULL, &icnt, &offset_expr,
3745 likely ? "bltzl" : "bltz",
3751 macro_build ((char *) NULL, &icnt, &offset_expr,
3752 likely ? "bgtzl" : "bgtz",
3756 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
3757 macro_build ((char *) NULL, &icnt, &offset_expr,
3758 likely ? "bnel" : "bne",
3769 macro_build ((char *) NULL, &icnt, &offset_expr,
3770 likely ? "bnel" : "bne",
3774 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
3776 macro_build ((char *) NULL, &icnt, &offset_expr,
3777 likely ? "bnel" : "bne",
3793 as_warn ("Divide by zero.");
3795 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
3797 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
3801 mips_emit_delays (true);
3802 ++mips_opts.noreorder;
3803 mips_any_noreorder = 1;
3804 macro_build ((char *) NULL, &icnt, NULL,
3805 dbl ? "ddiv" : "div",
3806 "z,s,t", sreg, treg);
3808 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0);
3811 expr1.X_add_number = 8;
3812 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
3813 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3814 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
3816 expr1.X_add_number = -1;
3817 macro_build ((char *) NULL, &icnt, &expr1,
3818 dbl ? "daddiu" : "addiu",
3819 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
3820 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
3821 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
3824 expr1.X_add_number = 1;
3825 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
3826 (int) BFD_RELOC_LO16);
3827 macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT,
3832 expr1.X_add_number = 0x80000000;
3833 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
3834 (int) BFD_RELOC_HI16);
3837 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", sreg, AT);
3840 expr1.X_add_number = 8;
3841 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
3842 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3843 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
3845 --mips_opts.noreorder;
3846 macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg);
3885 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3887 as_warn ("Divide by zero.");
3889 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
3891 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
3894 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3896 if (strcmp (s2, "mflo") == 0)
3897 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg,
3900 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
3903 if (imm_expr.X_op == O_constant
3904 && imm_expr.X_add_number == -1
3905 && s[strlen (s) - 1] != 'u')
3907 if (strcmp (s2, "mflo") == 0)
3910 macro_build ((char *) NULL, &icnt, NULL, "dneg", "d,w", dreg,
3913 macro_build ((char *) NULL, &icnt, NULL, "neg", "d,w", dreg,
3917 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
3921 load_register (&icnt, AT, &imm_expr, dbl);
3922 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT);
3923 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
3942 mips_emit_delays (true);
3943 ++mips_opts.noreorder;
3944 mips_any_noreorder = 1;
3945 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
3947 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0);
3950 expr1.X_add_number = 8;
3951 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
3952 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3953 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
3955 --mips_opts.noreorder;
3956 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
3962 /* Load the address of a symbol into a register. If breg is not
3963 zero, we then add a base register to it. */
3965 /* When generating embedded PIC code, we permit expressions of
3968 where bar is an address in the .text section. These are used
3969 when getting the addresses of functions. We don't permit
3970 X_add_number to be non-zero, because if the symbol is
3971 external the relaxing code needs to know that any addend is
3972 purely the offset to X_op_symbol. */
3973 if (mips_pic == EMBEDDED_PIC
3974 && offset_expr.X_op == O_subtract
3975 && now_seg == text_section
3976 && (offset_expr.X_op_symbol->sy_value.X_op == O_constant
3977 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == text_section
3978 : (offset_expr.X_op_symbol->sy_value.X_op == O_symbol
3979 && (S_GET_SEGMENT (offset_expr.X_op_symbol
3980 ->sy_value.X_add_symbol)
3983 && offset_expr.X_add_number == 0)
3985 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
3986 treg, (int) BFD_RELOC_PCREL_HI16_S);
3987 macro_build ((char *) NULL, &icnt, &offset_expr,
3988 mips_opts.isa < 3 ? "addiu" : "daddiu",
3989 "t,r,j", treg, treg, (int) BFD_RELOC_PCREL_LO16);
3993 if (offset_expr.X_op != O_symbol
3994 && offset_expr.X_op != O_constant)
3996 as_bad ("expression too complex");
3997 offset_expr.X_op = O_constant;
4011 if (offset_expr.X_op == O_constant)
4012 load_register (&icnt, tempreg, &offset_expr, dbl);
4013 else if (mips_pic == NO_PIC)
4015 /* If this is a reference to an GP relative symbol, we want
4016 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
4018 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4019 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4020 If we have a constant, we need two instructions anyhow,
4021 so we may as well always use the latter form. */
4022 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
4023 || nopic_need_relax (offset_expr.X_add_symbol, 1))
4028 macro_build ((char *) NULL, &icnt, &offset_expr,
4029 mips_opts.isa < 3 ? "addiu" : "daddiu",
4030 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
4031 p = frag_var (rs_machine_dependent, 8, 0,
4032 RELAX_ENCODE (4, 8, 0, 4, 0,
4033 mips_opts.warn_about_macros),
4034 offset_expr.X_add_symbol, (offsetT) 0,
4037 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4040 macro_build (p, &icnt, &offset_expr,
4041 mips_opts.isa < 3 ? "addiu" : "daddiu",
4042 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4044 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4046 /* If this is a reference to an external symbol, and there
4047 is no constant, we want
4048 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4049 For a local symbol, we want
4050 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4052 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4054 If we have a small constant, and this is a reference to
4055 an external symbol, we want
4056 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4058 addiu $tempreg,$tempreg,<constant>
4059 For a local symbol, we want the same instruction
4060 sequence, but we output a BFD_RELOC_LO16 reloc on the
4063 If we have a large constant, and this is a reference to
4064 an external symbol, we want
4065 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4066 lui $at,<hiconstant>
4067 addiu $at,$at,<loconstant>
4068 addu $tempreg,$tempreg,$at
4069 For a local symbol, we want the same instruction
4070 sequence, but we output a BFD_RELOC_LO16 reloc on the
4071 addiu instruction. */
4072 expr1.X_add_number = offset_expr.X_add_number;
4073 offset_expr.X_add_number = 0;
4075 macro_build ((char *) NULL, &icnt, &offset_expr,
4077 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
4078 if (expr1.X_add_number == 0)
4086 /* We're going to put in an addu instruction using
4087 tempreg, so we may as well insert the nop right
4089 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4093 p = frag_var (rs_machine_dependent, 8 - off, 0,
4094 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4096 ? mips_opts.warn_about_macros
4098 offset_expr.X_add_symbol, (offsetT) 0,
4102 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4105 macro_build (p, &icnt, &expr1,
4106 mips_opts.isa < 3 ? "addiu" : "daddiu",
4107 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4108 /* FIXME: If breg == 0, and the next instruction uses
4109 $tempreg, then if this variant case is used an extra
4110 nop will be generated. */
4112 else if (expr1.X_add_number >= -0x8000
4113 && expr1.X_add_number < 0x8000)
4115 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4117 macro_build ((char *) NULL, &icnt, &expr1,
4118 mips_opts.isa < 3 ? "addiu" : "daddiu",
4119 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4120 (void) frag_var (rs_machine_dependent, 0, 0,
4121 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4122 offset_expr.X_add_symbol, (offsetT) 0,
4129 /* If we are going to add in a base register, and the
4130 target register and the base register are the same,
4131 then we are using AT as a temporary register. Since
4132 we want to load the constant into AT, we add our
4133 current AT (from the global offset table) and the
4134 register into the register now, and pretend we were
4135 not using a base register. */
4140 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4142 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4143 mips_opts.isa < 3 ? "addu" : "daddu",
4144 "d,v,t", treg, AT, breg);
4150 /* Set mips_optimize around the lui instruction to avoid
4151 inserting an unnecessary nop after the lw. */
4152 hold_mips_optimize = mips_optimize;
4154 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
4155 mips_optimize = hold_mips_optimize;
4157 macro_build ((char *) NULL, &icnt, &expr1,
4158 mips_opts.isa < 3 ? "addiu" : "daddiu",
4159 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4160 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4161 mips_opts.isa < 3 ? "addu" : "daddu",
4162 "d,v,t", tempreg, tempreg, AT);
4163 (void) frag_var (rs_machine_dependent, 0, 0,
4164 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4165 offset_expr.X_add_symbol, (offsetT) 0,
4170 else if (mips_pic == SVR4_PIC)
4174 /* This is the large GOT case. If this is a reference to an
4175 external symbol, and there is no constant, we want
4176 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4177 addu $tempreg,$tempreg,$gp
4178 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4179 For a local symbol, we want
4180 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4182 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4184 If we have a small constant, and this is a reference to
4185 an external symbol, we want
4186 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4187 addu $tempreg,$tempreg,$gp
4188 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4190 addiu $tempreg,$tempreg,<constant>
4191 For a local symbol, we want
4192 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4194 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4196 If we have a large constant, and this is a reference to
4197 an external symbol, we want
4198 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4199 addu $tempreg,$tempreg,$gp
4200 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4201 lui $at,<hiconstant>
4202 addiu $at,$at,<loconstant>
4203 addu $tempreg,$tempreg,$at
4204 For a local symbol, we want
4205 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4206 lui $at,<hiconstant>
4207 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4208 addu $tempreg,$tempreg,$at
4210 expr1.X_add_number = offset_expr.X_add_number;
4211 offset_expr.X_add_number = 0;
4213 if (reg_needs_delay (GP))
4217 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4218 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
4219 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4220 mips_opts.isa < 3 ? "addu" : "daddu",
4221 "d,v,t", tempreg, tempreg, GP);
4222 macro_build ((char *) NULL, &icnt, &offset_expr,
4224 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
4226 if (expr1.X_add_number == 0)
4234 /* We're going to put in an addu instruction using
4235 tempreg, so we may as well insert the nop right
4237 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4242 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4243 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4246 ? mips_opts.warn_about_macros
4248 offset_expr.X_add_symbol, (offsetT) 0,
4251 else if (expr1.X_add_number >= -0x8000
4252 && expr1.X_add_number < 0x8000)
4254 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4256 macro_build ((char *) NULL, &icnt, &expr1,
4257 mips_opts.isa < 3 ? "addiu" : "daddiu",
4258 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4260 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4261 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4263 ? mips_opts.warn_about_macros
4265 offset_expr.X_add_symbol, (offsetT) 0,
4272 /* If we are going to add in a base register, and the
4273 target register and the base register are the same,
4274 then we are using AT as a temporary register. Since
4275 we want to load the constant into AT, we add our
4276 current AT (from the global offset table) and the
4277 register into the register now, and pretend we were
4278 not using a base register. */
4286 assert (tempreg == AT);
4287 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4289 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4290 mips_opts.isa < 3 ? "addu" : "daddu",
4291 "d,v,t", treg, AT, breg);
4296 /* Set mips_optimize around the lui instruction to avoid
4297 inserting an unnecessary nop after the lw. */
4298 hold_mips_optimize = mips_optimize;
4300 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
4301 mips_optimize = hold_mips_optimize;
4303 macro_build ((char *) NULL, &icnt, &expr1,
4304 mips_opts.isa < 3 ? "addiu" : "daddiu",
4305 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4306 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4307 mips_opts.isa < 3 ? "addu" : "daddu",
4308 "d,v,t", dreg, dreg, AT);
4310 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
4311 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
4314 ? mips_opts.warn_about_macros
4316 offset_expr.X_add_symbol, (offsetT) 0,
4324 /* This is needed because this instruction uses $gp, but
4325 the first instruction on the main stream does not. */
4326 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4329 macro_build (p, &icnt, &offset_expr,
4331 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
4333 if (expr1.X_add_number >= -0x8000
4334 && expr1.X_add_number < 0x8000)
4336 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4338 macro_build (p, &icnt, &expr1,
4339 mips_opts.isa < 3 ? "addiu" : "daddiu",
4340 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4341 /* FIXME: If add_number is 0, and there was no base
4342 register, the external symbol case ended with a load,
4343 so if the symbol turns out to not be external, and
4344 the next instruction uses tempreg, an unnecessary nop
4345 will be inserted. */
4351 /* We must add in the base register now, as in the
4352 external symbol case. */
4353 assert (tempreg == AT);
4354 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4356 macro_build (p, &icnt, (expressionS *) NULL,
4357 mips_opts.isa < 3 ? "addu" : "daddu",
4358 "d,v,t", treg, AT, breg);
4361 /* We set breg to 0 because we have arranged to add
4362 it in in both cases. */
4366 macro_build_lui (p, &icnt, &expr1, AT);
4368 macro_build (p, &icnt, &expr1,
4369 mips_opts.isa < 3 ? "addiu" : "daddiu",
4370 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4372 macro_build (p, &icnt, (expressionS *) NULL,
4373 mips_opts.isa < 3 ? "addu" : "daddu",
4374 "d,v,t", tempreg, tempreg, AT);
4378 else if (mips_pic == EMBEDDED_PIC)
4381 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
4383 macro_build ((char *) NULL, &icnt, &offset_expr,
4384 mips_opts.isa < 3 ? "addiu" : "daddiu",
4385 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
4391 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4392 mips_opts.isa < 3 ? "addu" : "daddu",
4393 "d,v,t", treg, tempreg, breg);
4401 /* The j instruction may not be used in PIC code, since it
4402 requires an absolute address. We convert it to a b
4404 if (mips_pic == NO_PIC)
4405 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
4407 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4410 /* The jal instructions must be handled as macros because when
4411 generating PIC code they expand to multi-instruction
4412 sequences. Normally they are simple instructions. */
4417 if (mips_pic == NO_PIC
4418 || mips_pic == EMBEDDED_PIC)
4419 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
4421 else if (mips_pic == SVR4_PIC)
4423 if (sreg != PIC_CALL_REG)
4424 as_warn ("MIPS PIC call to register other than $25");
4426 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
4428 if (mips_cprestore_offset < 0)
4429 as_warn ("No .cprestore pseudo-op used in PIC code");
4432 expr1.X_add_number = mips_cprestore_offset;
4433 macro_build ((char *) NULL, &icnt, &expr1,
4434 mips_opts.isa < 3 ? "lw" : "ld",
4435 "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg);
4444 if (mips_pic == NO_PIC)
4445 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
4446 else if (mips_pic == SVR4_PIC)
4448 /* If this is a reference to an external symbol, and we are
4449 using a small GOT, we want
4450 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4454 lw $gp,cprestore($sp)
4455 The cprestore value is set using the .cprestore
4456 pseudo-op. If we are using a big GOT, we want
4457 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4459 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
4463 lw $gp,cprestore($sp)
4464 If the symbol is not external, we want
4465 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4467 addiu $25,$25,<sym> (BFD_RELOC_LO16)
4470 lw $gp,cprestore($sp) */
4474 macro_build ((char *) NULL, &icnt, &offset_expr,
4475 mips_opts.isa < 3 ? "lw" : "ld",
4476 "t,o(b)", PIC_CALL_REG,
4477 (int) BFD_RELOC_MIPS_CALL16, GP);
4478 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4480 p = frag_var (rs_machine_dependent, 4, 0,
4481 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
4482 offset_expr.X_add_symbol, (offsetT) 0,
4489 if (reg_needs_delay (GP))
4493 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4494 PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16);
4495 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4496 mips_opts.isa < 3 ? "addu" : "daddu",
4497 "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP);
4498 macro_build ((char *) NULL, &icnt, &offset_expr,
4499 mips_opts.isa < 3 ? "lw" : "ld",
4500 "t,o(b)", PIC_CALL_REG,
4501 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
4502 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4504 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4505 RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel,
4507 offset_expr.X_add_symbol, (offsetT) 0,
4511 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4514 macro_build (p, &icnt, &offset_expr,
4515 mips_opts.isa < 3 ? "lw" : "ld",
4516 "t,o(b)", PIC_CALL_REG,
4517 (int) BFD_RELOC_MIPS_GOT16, GP);
4519 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4522 macro_build (p, &icnt, &offset_expr,
4523 mips_opts.isa < 3 ? "addiu" : "daddiu",
4524 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
4525 (int) BFD_RELOC_LO16);
4526 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4527 "jalr", "s", PIC_CALL_REG);
4528 if (mips_cprestore_offset < 0)
4529 as_warn ("No .cprestore pseudo-op used in PIC code");
4532 if (mips_opts.noreorder)
4533 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4535 expr1.X_add_number = mips_cprestore_offset;
4536 macro_build ((char *) NULL, &icnt, &expr1,
4537 mips_opts.isa < 3 ? "lw" : "ld",
4538 "t,o(b)", GP, (int) BFD_RELOC_LO16,
4542 else if (mips_pic == EMBEDDED_PIC)
4544 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
4545 /* The linker may expand the call to a longer sequence which
4546 uses $at, so we must break rather than return. */
4571 /* Itbl support may require additional care here. */
4576 /* Itbl support may require additional care here. */
4581 /* Itbl support may require additional care here. */
4586 /* Itbl support may require additional care here. */
4599 /* Itbl support may require additional care here. */
4604 /* Itbl support may require additional care here. */
4609 /* Itbl support may require additional care here. */
4629 if (breg == treg || coproc || lr)
4651 /* Itbl support may require additional care here. */
4656 /* Itbl support may require additional care here. */
4661 /* Itbl support may require additional care here. */
4666 /* Itbl support may require additional care here. */
4684 /* Itbl support may require additional care here. */
4688 /* Itbl support may require additional care here. */
4693 /* Itbl support may require additional care here. */
4705 /* Itbl support may require additional care here. */
4706 if (mask == M_LWC1_AB
4707 || mask == M_SWC1_AB
4708 || mask == M_LDC1_AB
4709 || mask == M_SDC1_AB
4718 if (offset_expr.X_op != O_constant
4719 && offset_expr.X_op != O_symbol)
4721 as_bad ("expression too complex");
4722 offset_expr.X_op = O_constant;
4725 /* A constant expression in PIC code can be handled just as it
4726 is in non PIC code. */
4727 if (mips_pic == NO_PIC
4728 || offset_expr.X_op == O_constant)
4730 /* If this is a reference to a GP relative symbol, and there
4731 is no base register, we want
4732 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
4733 Otherwise, if there is no base register, we want
4734 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4735 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
4736 If we have a constant, we need two instructions anyhow,
4737 so we always use the latter form.
4739 If we have a base register, and this is a reference to a
4740 GP relative symbol, we want
4741 addu $tempreg,$breg,$gp
4742 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
4744 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4745 addu $tempreg,$tempreg,$breg
4746 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
4747 With a constant we always use the latter case. */
4750 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
4751 || nopic_need_relax (offset_expr.X_add_symbol, 1))
4756 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
4757 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
4758 p = frag_var (rs_machine_dependent, 8, 0,
4759 RELAX_ENCODE (4, 8, 0, 4, 0,
4760 (mips_opts.warn_about_macros
4762 && mips_opts.noat))),
4763 offset_expr.X_add_symbol, (offsetT) 0,
4767 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4770 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
4771 (int) BFD_RELOC_LO16, tempreg);
4775 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
4776 || nopic_need_relax (offset_expr.X_add_symbol, 1))
4781 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4782 mips_opts.isa < 3 ? "addu" : "daddu",
4783 "d,v,t", tempreg, breg, GP);
4784 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
4785 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
4786 p = frag_var (rs_machine_dependent, 12, 0,
4787 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
4788 offset_expr.X_add_symbol, (offsetT) 0,
4791 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4794 macro_build (p, &icnt, (expressionS *) NULL,
4795 mips_opts.isa < 3 ? "addu" : "daddu",
4796 "d,v,t", tempreg, tempreg, breg);
4799 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
4800 (int) BFD_RELOC_LO16, tempreg);
4803 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4805 /* If this is a reference to an external symbol, we want
4806 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4808 <op> $treg,0($tempreg)
4810 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4812 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4813 <op> $treg,0($tempreg)
4814 If there is a base register, we add it to $tempreg before
4815 the <op>. If there is a constant, we stick it in the
4816 <op> instruction. We don't handle constants larger than
4817 16 bits, because we have no way to load the upper 16 bits
4818 (actually, we could handle them for the subset of cases
4819 in which we are not using $at). */
4820 assert (offset_expr.X_op == O_symbol);
4821 expr1.X_add_number = offset_expr.X_add_number;
4822 offset_expr.X_add_number = 0;
4823 if (expr1.X_add_number < -0x8000
4824 || expr1.X_add_number >= 0x8000)
4825 as_bad ("PIC code offset overflow (max 16 signed bits)");
4827 macro_build ((char *) NULL, &icnt, &offset_expr,
4828 mips_opts.isa < 3 ? "lw" : "ld",
4829 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
4830 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
4831 p = frag_var (rs_machine_dependent, 4, 0,
4832 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
4833 offset_expr.X_add_symbol, (offsetT) 0,
4835 macro_build (p, &icnt, &offset_expr,
4836 mips_opts.isa < 3 ? "addiu" : "daddiu",
4837 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4839 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4840 mips_opts.isa < 3 ? "addu" : "daddu",
4841 "d,v,t", tempreg, tempreg, breg);
4842 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
4843 (int) BFD_RELOC_LO16, tempreg);
4845 else if (mips_pic == SVR4_PIC)
4849 /* If this is a reference to an external symbol, we want
4850 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4851 addu $tempreg,$tempreg,$gp
4852 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4853 <op> $treg,0($tempreg)
4855 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4857 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4858 <op> $treg,0($tempreg)
4859 If there is a base register, we add it to $tempreg before
4860 the <op>. If there is a constant, we stick it in the
4861 <op> instruction. We don't handle constants larger than
4862 16 bits, because we have no way to load the upper 16 bits
4863 (actually, we could handle them for the subset of cases
4864 in which we are not using $at). */
4865 assert (offset_expr.X_op == O_symbol);
4866 expr1.X_add_number = offset_expr.X_add_number;
4867 offset_expr.X_add_number = 0;
4868 if (expr1.X_add_number < -0x8000
4869 || expr1.X_add_number >= 0x8000)
4870 as_bad ("PIC code offset overflow (max 16 signed bits)");
4871 if (reg_needs_delay (GP))
4876 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4877 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
4878 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4879 mips_opts.isa < 3 ? "addu" : "daddu",
4880 "d,v,t", tempreg, tempreg, GP);
4881 macro_build ((char *) NULL, &icnt, &offset_expr,
4882 mips_opts.isa < 3 ? "lw" : "ld",
4883 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
4885 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4886 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
4887 offset_expr.X_add_symbol, (offsetT) 0, (char *) NULL);
4890 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4893 macro_build (p, &icnt, &offset_expr,
4894 mips_opts.isa < 3 ? "lw" : "ld",
4895 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
4897 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4899 macro_build (p, &icnt, &offset_expr,
4900 mips_opts.isa < 3 ? "addiu" : "daddiu",
4901 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4903 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4904 mips_opts.isa < 3 ? "addu" : "daddu",
4905 "d,v,t", tempreg, tempreg, breg);
4906 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
4907 (int) BFD_RELOC_LO16, tempreg);
4909 else if (mips_pic == EMBEDDED_PIC)
4911 /* If there is no base register, we want
4912 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
4913 If there is a base register, we want
4914 addu $tempreg,$breg,$gp
4915 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
4917 assert (offset_expr.X_op == O_symbol);
4920 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
4921 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
4926 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4927 mips_opts.isa < 3 ? "addu" : "daddu",
4928 "d,v,t", tempreg, breg, GP);
4929 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
4930 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
4943 load_register (&icnt, treg, &imm_expr, 0);
4947 load_register (&icnt, treg, &imm_expr, 1);
4951 if (imm_expr.X_op == O_constant)
4953 load_register (&icnt, AT, &imm_expr, 0);
4954 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4955 "mtc1", "t,G", AT, treg);
4960 assert (offset_expr.X_op == O_symbol
4961 && strcmp (segment_name (S_GET_SEGMENT
4962 (offset_expr.X_add_symbol)),
4964 && offset_expr.X_add_number == 0);
4965 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
4966 treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
4971 /* If we have a constant in IMM_EXPR, then in mips3 mode it is
4972 the entire value, and in mips1 mode it is the high order 32
4973 bits of the value and the low order 32 bits are either zero
4974 or in offset_expr. */
4975 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
4977 load_register (&icnt, treg, &imm_expr, mips_opts.isa >= 3);
4978 if (mips_opts.isa < 3 && treg != 31)
4980 if (offset_expr.X_op == O_absent)
4981 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s",
4985 assert (offset_expr.X_op == O_constant);
4986 load_register (&icnt, treg + 1, &offset_expr, 0);
4992 /* We know that sym is in the .rdata section. First we get the
4993 upper 16 bits of the address. */
4994 if (mips_pic == NO_PIC)
4996 /* FIXME: This won't work for a 64 bit address. */
4997 macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
4999 else if (mips_pic == SVR4_PIC)
5001 macro_build ((char *) NULL, &icnt, &offset_expr,
5002 mips_opts.isa < 3 ? "lw" : "ld",
5003 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5005 else if (mips_pic == EMBEDDED_PIC)
5007 /* For embedded PIC we pick up the entire address off $gp in
5008 a single instruction. */
5009 macro_build ((char *) NULL, &icnt, &offset_expr,
5010 mips_opts.isa < 3 ? "addiu" : "daddiu",
5011 "t,r,j", AT, GP, (int) BFD_RELOC_MIPS_GPREL);
5012 offset_expr.X_op = O_constant;
5013 offset_expr.X_add_number = 0;
5018 /* Now we load the register(s). */
5019 if (mips_opts.isa >= 3)
5020 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5021 treg, (int) BFD_RELOC_LO16, AT);
5024 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5025 treg, (int) BFD_RELOC_LO16, AT);
5028 /* FIXME: How in the world do we deal with the possible
5030 offset_expr.X_add_number += 4;
5031 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5032 treg + 1, (int) BFD_RELOC_LO16, AT);
5036 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5037 does not become a variant frag. */
5038 frag_wane (frag_now);
5044 /* If we have a constant in IMM_EXPR, then in mips3 mode it is
5045 the entire value, and in mips1 mode it is the high order 32
5046 bits of the value and the low order 32 bits are either zero
5047 or in offset_expr. */
5048 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5050 load_register (&icnt, AT, &imm_expr, mips_opts.isa >= 3);
5051 if (mips_opts.isa >= 3)
5052 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5053 "dmtc1", "t,S", AT, treg);
5056 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5057 "mtc1", "t,G", AT, treg + 1);
5058 if (offset_expr.X_op == O_absent)
5059 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5060 "mtc1", "t,G", 0, treg);
5063 assert (offset_expr.X_op == O_constant);
5064 load_register (&icnt, AT, &offset_expr, 0);
5065 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5066 "mtc1", "t,G", AT, treg);
5072 assert (offset_expr.X_op == O_symbol
5073 && offset_expr.X_add_number == 0);
5074 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5075 if (strcmp (s, ".lit8") == 0)
5077 if (mips_opts.isa >= 2)
5079 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5080 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5084 r = BFD_RELOC_MIPS_LITERAL;
5089 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5090 if (mips_pic == SVR4_PIC)
5091 macro_build ((char *) NULL, &icnt, &offset_expr,
5092 mips_opts.isa < 3 ? "lw" : "ld",
5093 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5096 /* FIXME: This won't work for a 64 bit address. */
5097 macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
5100 if (mips_opts.isa >= 2)
5102 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5103 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
5105 /* To avoid confusion in tc_gen_reloc, we must ensure
5106 that this does not become a variant frag. */
5107 frag_wane (frag_now);
5118 /* Even on a big endian machine $fn comes before $fn+1. We have
5119 to adjust when loading from memory. */
5122 assert (mips_opts.isa < 2);
5123 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5124 target_big_endian ? treg + 1 : treg,
5126 /* FIXME: A possible overflow which I don't know how to deal
5128 offset_expr.X_add_number += 4;
5129 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5130 target_big_endian ? treg : treg + 1,
5133 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5134 does not become a variant frag. */
5135 frag_wane (frag_now);
5144 * The MIPS assembler seems to check for X_add_number not
5145 * being double aligned and generating:
5148 * addiu at,at,%lo(foo+1)
5151 * But, the resulting address is the same after relocation so why
5152 * generate the extra instruction?
5154 /* Itbl support may require additional care here. */
5156 if (mips_opts.isa >= 2)
5167 if (mips_opts.isa >= 2)
5175 /* Itbl support may require additional care here. */
5180 if (mips_opts.isa >= 3)
5191 if (mips_opts.isa >= 3)
5201 if (offset_expr.X_op != O_symbol
5202 && offset_expr.X_op != O_constant)
5204 as_bad ("expression too complex");
5205 offset_expr.X_op = O_constant;
5208 /* Even on a big endian machine $fn comes before $fn+1. We have
5209 to adjust when loading from memory. We set coproc if we must
5210 load $fn+1 first. */
5211 /* Itbl support may require additional care here. */
5212 if (! target_big_endian)
5215 if (mips_pic == NO_PIC
5216 || offset_expr.X_op == O_constant)
5218 /* If this is a reference to a GP relative symbol, we want
5219 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
5220 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
5221 If we have a base register, we use this
5223 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
5224 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
5225 If this is not a GP relative symbol, we want
5226 lui $at,<sym> (BFD_RELOC_HI16_S)
5227 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5228 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5229 If there is a base register, we add it to $at after the
5230 lui instruction. If there is a constant, we always use
5232 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
5233 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5252 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5253 mips_opts.isa < 3 ? "addu" : "daddu",
5254 "d,v,t", AT, breg, GP);
5260 /* Itbl support may require additional care here. */
5261 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5262 coproc ? treg + 1 : treg,
5263 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5264 offset_expr.X_add_number += 4;
5266 /* Set mips_optimize to 2 to avoid inserting an
5268 hold_mips_optimize = mips_optimize;
5270 /* Itbl support may require additional care here. */
5271 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5272 coproc ? treg : treg + 1,
5273 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5274 mips_optimize = hold_mips_optimize;
5276 p = frag_var (rs_machine_dependent, 12 + off, 0,
5277 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
5278 used_at && mips_opts.noat),
5279 offset_expr.X_add_symbol, (offsetT) 0,
5282 /* We just generated two relocs. When tc_gen_reloc
5283 handles this case, it will skip the first reloc and
5284 handle the second. The second reloc already has an
5285 extra addend of 4, which we added above. We must
5286 subtract it out, and then subtract another 4 to make
5287 the first reloc come out right. The second reloc
5288 will come out right because we are going to add 4 to
5289 offset_expr when we build its instruction below.
5291 If we have a symbol, then we don't want to include
5292 the offset, because it will wind up being included
5293 when we generate the reloc. */
5295 if (offset_expr.X_op == O_constant)
5296 offset_expr.X_add_number -= 8;
5299 offset_expr.X_add_number = -4;
5300 offset_expr.X_op = O_constant;
5303 macro_build_lui (p, &icnt, &offset_expr, AT);
5308 macro_build (p, &icnt, (expressionS *) NULL,
5309 mips_opts.isa < 3 ? "addu" : "daddu",
5310 "d,v,t", AT, breg, AT);
5314 /* Itbl support may require additional care here. */
5315 macro_build (p, &icnt, &offset_expr, s, fmt,
5316 coproc ? treg + 1 : treg,
5317 (int) BFD_RELOC_LO16, AT);
5320 /* FIXME: How do we handle overflow here? */
5321 offset_expr.X_add_number += 4;
5322 /* Itbl support may require additional care here. */
5323 macro_build (p, &icnt, &offset_expr, s, fmt,
5324 coproc ? treg : treg + 1,
5325 (int) BFD_RELOC_LO16, AT);
5327 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5331 /* If this is a reference to an external symbol, we want
5332 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5337 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5339 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5340 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5341 If there is a base register we add it to $at before the
5342 lwc1 instructions. If there is a constant we include it
5343 in the lwc1 instructions. */
5345 expr1.X_add_number = offset_expr.X_add_number;
5346 offset_expr.X_add_number = 0;
5347 if (expr1.X_add_number < -0x8000
5348 || expr1.X_add_number >= 0x8000 - 4)
5349 as_bad ("PIC code offset overflow (max 16 signed bits)");
5354 frag_grow (24 + off);
5355 macro_build ((char *) NULL, &icnt, &offset_expr,
5356 mips_opts.isa < 3 ? "lw" : "ld",
5357 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5358 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5360 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5361 mips_opts.isa < 3 ? "addu" : "daddu",
5362 "d,v,t", AT, breg, AT);
5363 /* Itbl support may require additional care here. */
5364 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5365 coproc ? treg + 1 : treg,
5366 (int) BFD_RELOC_LO16, AT);
5367 expr1.X_add_number += 4;
5369 /* Set mips_optimize to 2 to avoid inserting an undesired
5371 hold_mips_optimize = mips_optimize;
5373 /* Itbl support may require additional care here. */
5374 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5375 coproc ? treg : treg + 1,
5376 (int) BFD_RELOC_LO16, AT);
5377 mips_optimize = hold_mips_optimize;
5379 (void) frag_var (rs_machine_dependent, 0, 0,
5380 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
5381 offset_expr.X_add_symbol, (offsetT) 0,
5384 else if (mips_pic == SVR4_PIC)
5388 /* If this is a reference to an external symbol, we want
5389 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5391 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
5396 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5398 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5399 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5400 If there is a base register we add it to $at before the
5401 lwc1 instructions. If there is a constant we include it
5402 in the lwc1 instructions. */
5404 expr1.X_add_number = offset_expr.X_add_number;
5405 offset_expr.X_add_number = 0;
5406 if (expr1.X_add_number < -0x8000
5407 || expr1.X_add_number >= 0x8000 - 4)
5408 as_bad ("PIC code offset overflow (max 16 signed bits)");
5409 if (reg_needs_delay (GP))
5418 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5419 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
5420 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5421 mips_opts.isa < 3 ? "addu" : "daddu",
5422 "d,v,t", AT, AT, GP);
5423 macro_build ((char *) NULL, &icnt, &offset_expr,
5424 mips_opts.isa < 3 ? "lw" : "ld",
5425 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
5426 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5428 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5429 mips_opts.isa < 3 ? "addu" : "daddu",
5430 "d,v,t", AT, breg, AT);
5431 /* Itbl support may require additional care here. */
5432 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5433 coproc ? treg + 1 : treg,
5434 (int) BFD_RELOC_LO16, AT);
5435 expr1.X_add_number += 4;
5437 /* Set mips_optimize to 2 to avoid inserting an undesired
5439 hold_mips_optimize = mips_optimize;
5441 /* Itbl support may require additional care here. */
5442 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5443 coproc ? treg : treg + 1,
5444 (int) BFD_RELOC_LO16, AT);
5445 mips_optimize = hold_mips_optimize;
5446 expr1.X_add_number -= 4;
5448 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
5449 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
5450 8 + gpdel + off, 1, 0),
5451 offset_expr.X_add_symbol, (offsetT) 0,
5455 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5458 macro_build (p, &icnt, &offset_expr,
5459 mips_opts.isa < 3 ? "lw" : "ld",
5460 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5462 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5466 macro_build (p, &icnt, (expressionS *) NULL,
5467 mips_opts.isa < 3 ? "addu" : "daddu",
5468 "d,v,t", AT, breg, AT);
5471 /* Itbl support may require additional care here. */
5472 macro_build (p, &icnt, &expr1, s, fmt,
5473 coproc ? treg + 1 : treg,
5474 (int) BFD_RELOC_LO16, AT);
5476 expr1.X_add_number += 4;
5478 /* Set mips_optimize to 2 to avoid inserting an undesired
5480 hold_mips_optimize = mips_optimize;
5482 /* Itbl support may require additional care here. */
5483 macro_build (p, &icnt, &expr1, s, fmt,
5484 coproc ? treg : treg + 1,
5485 (int) BFD_RELOC_LO16, AT);
5486 mips_optimize = hold_mips_optimize;
5488 else if (mips_pic == EMBEDDED_PIC)
5490 /* If there is no base register, we use
5491 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
5492 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
5493 If we have a base register, we use
5495 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
5496 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
5505 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5506 mips_opts.isa < 3 ? "addu" : "daddu",
5507 "d,v,t", AT, breg, GP);
5512 /* Itbl support may require additional care here. */
5513 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5514 coproc ? treg + 1 : treg,
5515 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5516 offset_expr.X_add_number += 4;
5517 /* Itbl support may require additional care here. */
5518 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5519 coproc ? treg : treg + 1,
5520 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5536 assert (mips_opts.isa < 3);
5537 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
5538 (int) BFD_RELOC_LO16, breg);
5539 offset_expr.X_add_number += 4;
5540 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
5541 (int) BFD_RELOC_LO16, breg);
5544 /* New code added to support COPZ instructions.
5545 This code builds table entries out of the macros in mip_opcodes.
5546 R4000 uses interlocks to handle coproc delays.
5547 Other chips (like the R3000) require nops to be inserted for delays.
5549 FIXME: Currently, we require that the user handle delays.
5550 In order to fill delay slots for non-interlocked chips,
5551 we must have a way to specify delays based on the coprocessor.
5552 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
5553 What are the side-effects of the cop instruction?
5554 What cache support might we have and what are its effects?
5555 Both coprocessor & memory require delays. how long???
5556 What registers are read/set/modified?
5558 If an itbl is provided to interpret cop instructions,
5559 this knowledge can be encoded in the itbl spec. */
5573 /* For now we just do C (same as Cz). */
5574 macro_build ((char *) NULL, &icnt, &offset_expr, s, "C");
5577 #ifdef LOSING_COMPILER
5579 /* Try and see if this is a new itbl instruction.
5580 This code builds table entries out of the macros in mip_opcodes.
5581 FIXME: For now we just assemble the expression and pass it's
5582 value along as a 32-bit immediate.
5583 We may want to have the assembler assemble this value,
5584 so that we gain the assembler's knowledge of delay slots,
5586 Would it be more efficient to use mask (id) here? */
5587 if (itbl_have_entries
5588 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
5590 s = ip->insn_mo->name;
5592 coproc = ITBL_DECODE_PNUM (immed_expr);;
5593 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
5600 as_warn ("Macro used $at after \".set noat\"");
5605 struct mips_cl_insn *ip;
5607 register int treg, sreg, dreg, breg;
5622 bfd_reloc_code_real_type r;
5625 treg = (ip->insn_opcode >> 16) & 0x1f;
5626 dreg = (ip->insn_opcode >> 11) & 0x1f;
5627 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
5628 mask = ip->insn_mo->mask;
5630 expr1.X_op = O_constant;
5631 expr1.X_op_symbol = NULL;
5632 expr1.X_add_symbol = NULL;
5633 expr1.X_add_number = 1;
5637 #endif /* LOSING_COMPILER */
5642 macro_build ((char *) NULL, &icnt, NULL,
5643 dbl ? "dmultu" : "multu",
5645 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
5651 /* The MIPS assembler some times generates shifts and adds. I'm
5652 not trying to be that fancy. GCC should do this for us
5654 load_register (&icnt, AT, &imm_expr, dbl);
5655 macro_build ((char *) NULL, &icnt, NULL,
5656 dbl ? "dmult" : "mult",
5658 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
5664 mips_emit_delays (true);
5665 ++mips_opts.noreorder;
5666 mips_any_noreorder = 1;
5667 macro_build ((char *) NULL, &icnt, NULL,
5668 dbl ? "dmult" : "mult",
5670 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
5671 macro_build ((char *) NULL, &icnt, NULL,
5672 dbl ? "dsra32" : "sra",
5673 "d,w,<", dreg, dreg, 31);
5674 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
5676 macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", dreg, AT);
5679 expr1.X_add_number = 8;
5680 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
5681 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
5682 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
5684 --mips_opts.noreorder;
5685 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
5691 mips_emit_delays (true);
5692 ++mips_opts.noreorder;
5693 mips_any_noreorder = 1;
5694 macro_build ((char *) NULL, &icnt, NULL,
5695 dbl ? "dmultu" : "multu",
5697 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
5698 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
5700 macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", AT, 0);
5703 expr1.X_add_number = 8;
5704 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
5705 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
5706 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
5708 --mips_opts.noreorder;
5712 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
5713 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT);
5714 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg,
5716 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
5720 if (imm_expr.X_op != O_constant)
5721 as_bad ("rotate count too large");
5722 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg,
5723 (int) (imm_expr.X_add_number & 0x1f));
5724 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg,
5725 (int) ((0 - imm_expr.X_add_number) & 0x1f));
5726 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
5730 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
5731 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT);
5732 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg,
5734 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
5738 if (imm_expr.X_op != O_constant)
5739 as_bad ("rotate count too large");
5740 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg,
5741 (int) (imm_expr.X_add_number & 0x1f));
5742 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg,
5743 (int) ((0 - imm_expr.X_add_number) & 0x1f));
5744 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
5748 assert (mips_opts.isa < 2);
5749 /* Even on a big endian machine $fn comes before $fn+1. We have
5750 to adjust when storing to memory. */
5751 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
5752 target_big_endian ? treg + 1 : treg,
5753 (int) BFD_RELOC_LO16, breg);
5754 offset_expr.X_add_number += 4;
5755 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
5756 target_big_endian ? treg : treg + 1,
5757 (int) BFD_RELOC_LO16, breg);
5762 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
5763 treg, (int) BFD_RELOC_LO16);
5765 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
5766 sreg, (int) BFD_RELOC_LO16);
5769 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
5771 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
5772 dreg, (int) BFD_RELOC_LO16);
5777 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
5779 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
5780 sreg, (int) BFD_RELOC_LO16);
5785 as_warn ("Instruction %s: result is always false",
5787 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
5790 if (imm_expr.X_op == O_constant
5791 && imm_expr.X_add_number >= 0
5792 && imm_expr.X_add_number < 0x10000)
5794 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
5795 sreg, (int) BFD_RELOC_LO16);
5798 else if (imm_expr.X_op == O_constant
5799 && imm_expr.X_add_number > -0x8000
5800 && imm_expr.X_add_number < 0)
5802 imm_expr.X_add_number = -imm_expr.X_add_number;
5803 macro_build ((char *) NULL, &icnt, &imm_expr,
5804 mips_opts.isa < 3 ? "addiu" : "daddiu",
5805 "t,r,j", dreg, sreg,
5806 (int) BFD_RELOC_LO16);
5811 load_register (&icnt, AT, &imm_expr, 0);
5812 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
5816 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
5817 (int) BFD_RELOC_LO16);
5822 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
5828 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg);
5829 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
5830 (int) BFD_RELOC_LO16);
5833 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
5835 if (imm_expr.X_op == O_constant
5836 && imm_expr.X_add_number >= -0x8000
5837 && imm_expr.X_add_number < 0x8000)
5839 macro_build ((char *) NULL, &icnt, &expr1,
5840 mask == M_SGE_I ? "slti" : "sltiu",
5841 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
5846 load_register (&icnt, AT, &imm_expr, 0);
5847 macro_build ((char *) NULL, &icnt, NULL,
5848 mask == M_SGE_I ? "slt" : "sltu",
5849 "d,v,t", dreg, sreg, AT);
5852 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
5853 (int) BFD_RELOC_LO16);
5858 case M_SGT: /* sreg > treg <==> treg < sreg */
5864 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
5867 case M_SGT_I: /* sreg > I <==> I < sreg */
5873 load_register (&icnt, AT, &imm_expr, 0);
5874 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
5877 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
5883 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
5884 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
5885 (int) BFD_RELOC_LO16);
5888 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
5894 load_register (&icnt, AT, &imm_expr, 0);
5895 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
5896 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
5897 (int) BFD_RELOC_LO16);
5901 if (imm_expr.X_op == O_constant
5902 && imm_expr.X_add_number >= -0x8000
5903 && imm_expr.X_add_number < 0x8000)
5905 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
5906 dreg, sreg, (int) BFD_RELOC_LO16);
5909 load_register (&icnt, AT, &imm_expr, 0);
5910 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT);
5914 if (imm_expr.X_op == O_constant
5915 && imm_expr.X_add_number >= -0x8000
5916 && imm_expr.X_add_number < 0x8000)
5918 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
5919 dreg, sreg, (int) BFD_RELOC_LO16);
5922 load_register (&icnt, AT, &imm_expr, 0);
5923 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg,
5929 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
5932 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
5936 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
5938 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
5944 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
5946 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
5952 as_warn ("Instruction %s: result is always true",
5954 macro_build ((char *) NULL, &icnt, &expr1,
5955 mips_opts.isa < 3 ? "addiu" : "daddiu",
5956 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
5959 if (imm_expr.X_op == O_constant
5960 && imm_expr.X_add_number >= 0
5961 && imm_expr.X_add_number < 0x10000)
5963 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
5964 dreg, sreg, (int) BFD_RELOC_LO16);
5967 else if (imm_expr.X_op == O_constant
5968 && imm_expr.X_add_number > -0x8000
5969 && imm_expr.X_add_number < 0)
5971 imm_expr.X_add_number = -imm_expr.X_add_number;
5972 macro_build ((char *) NULL, &icnt, &imm_expr,
5973 mips_opts.isa < 3 ? "addiu" : "daddiu",
5974 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
5979 load_register (&icnt, AT, &imm_expr, 0);
5980 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
5984 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
5992 if (imm_expr.X_op == O_constant
5993 && imm_expr.X_add_number > -0x8000
5994 && imm_expr.X_add_number <= 0x8000)
5996 imm_expr.X_add_number = -imm_expr.X_add_number;
5997 macro_build ((char *) NULL, &icnt, &imm_expr,
5998 dbl ? "daddi" : "addi",
5999 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6002 load_register (&icnt, AT, &imm_expr, dbl);
6003 macro_build ((char *) NULL, &icnt, NULL,
6004 dbl ? "dsub" : "sub",
6005 "d,v,t", dreg, sreg, AT);
6011 if (imm_expr.X_op == O_constant
6012 && imm_expr.X_add_number > -0x8000
6013 && imm_expr.X_add_number <= 0x8000)
6015 imm_expr.X_add_number = -imm_expr.X_add_number;
6016 macro_build ((char *) NULL, &icnt, &imm_expr,
6017 dbl ? "daddiu" : "addiu",
6018 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6021 load_register (&icnt, AT, &imm_expr, dbl);
6022 macro_build ((char *) NULL, &icnt, NULL,
6023 dbl ? "dsubu" : "subu",
6024 "d,v,t", dreg, sreg, AT);
6045 load_register (&icnt, AT, &imm_expr, 0);
6046 macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT);
6051 assert (mips_opts.isa < 2);
6052 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
6053 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
6056 * Is the double cfc1 instruction a bug in the mips assembler;
6057 * or is there a reason for it?
6059 mips_emit_delays (true);
6060 ++mips_opts.noreorder;
6061 mips_any_noreorder = 1;
6062 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
6063 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
6064 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6065 expr1.X_add_number = 3;
6066 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
6067 (int) BFD_RELOC_LO16);
6068 expr1.X_add_number = 2;
6069 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
6070 (int) BFD_RELOC_LO16);
6071 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31);
6072 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6073 macro_build ((char *) NULL, &icnt, NULL,
6074 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
6075 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31);
6076 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6077 --mips_opts.noreorder;
6086 if (offset_expr.X_add_number >= 0x7fff)
6087 as_bad ("operand overflow");
6088 /* avoid load delay */
6089 if (! target_big_endian)
6090 offset_expr.X_add_number += 1;
6091 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6092 (int) BFD_RELOC_LO16, breg);
6093 if (! target_big_endian)
6094 offset_expr.X_add_number -= 1;
6096 offset_expr.X_add_number += 1;
6097 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
6098 (int) BFD_RELOC_LO16, breg);
6099 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
6100 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
6113 if (offset_expr.X_add_number >= 0x8000 - off)
6114 as_bad ("operand overflow");
6115 if (! target_big_endian)
6116 offset_expr.X_add_number += off;
6117 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6118 (int) BFD_RELOC_LO16, breg);
6119 if (! target_big_endian)
6120 offset_expr.X_add_number -= off;
6122 offset_expr.X_add_number += off;
6123 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
6124 (int) BFD_RELOC_LO16, breg);
6137 load_address (&icnt, AT, &offset_expr);
6139 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6140 mips_opts.isa < 3 ? "addu" : "daddu",
6141 "d,v,t", AT, AT, breg);
6142 if (! target_big_endian)
6143 expr1.X_add_number = off;
6145 expr1.X_add_number = 0;
6146 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
6147 (int) BFD_RELOC_LO16, AT);
6148 if (! target_big_endian)
6149 expr1.X_add_number = 0;
6151 expr1.X_add_number = off;
6152 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
6153 (int) BFD_RELOC_LO16, AT);
6158 load_address (&icnt, AT, &offset_expr);
6160 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6161 mips_opts.isa < 3 ? "addu" : "daddu",
6162 "d,v,t", AT, AT, breg);
6163 if (target_big_endian)
6164 expr1.X_add_number = 0;
6165 macro_build ((char *) NULL, &icnt, &expr1,
6166 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
6167 (int) BFD_RELOC_LO16, AT);
6168 if (target_big_endian)
6169 expr1.X_add_number = 1;
6171 expr1.X_add_number = 0;
6172 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
6173 (int) BFD_RELOC_LO16, AT);
6174 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
6176 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
6181 if (offset_expr.X_add_number >= 0x7fff)
6182 as_bad ("operand overflow");
6183 if (target_big_endian)
6184 offset_expr.X_add_number += 1;
6185 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
6186 (int) BFD_RELOC_LO16, breg);
6187 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8);
6188 if (target_big_endian)
6189 offset_expr.X_add_number -= 1;
6191 offset_expr.X_add_number += 1;
6192 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
6193 (int) BFD_RELOC_LO16, breg);
6206 if (offset_expr.X_add_number >= 0x8000 - off)
6207 as_bad ("operand overflow");
6208 if (! target_big_endian)
6209 offset_expr.X_add_number += off;
6210 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6211 (int) BFD_RELOC_LO16, breg);
6212 if (! target_big_endian)
6213 offset_expr.X_add_number -= off;
6215 offset_expr.X_add_number += off;
6216 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
6217 (int) BFD_RELOC_LO16, breg);
6230 load_address (&icnt, AT, &offset_expr);
6232 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6233 mips_opts.isa < 3 ? "addu" : "daddu",
6234 "d,v,t", AT, AT, breg);
6235 if (! target_big_endian)
6236 expr1.X_add_number = off;
6238 expr1.X_add_number = 0;
6239 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
6240 (int) BFD_RELOC_LO16, AT);
6241 if (! target_big_endian)
6242 expr1.X_add_number = 0;
6244 expr1.X_add_number = off;
6245 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
6246 (int) BFD_RELOC_LO16, AT);
6250 load_address (&icnt, AT, &offset_expr);
6252 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6253 mips_opts.isa < 3 ? "addu" : "daddu",
6254 "d,v,t", AT, AT, breg);
6255 if (! target_big_endian)
6256 expr1.X_add_number = 0;
6257 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
6258 (int) BFD_RELOC_LO16, AT);
6259 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg,
6261 if (! target_big_endian)
6262 expr1.X_add_number = 1;
6264 expr1.X_add_number = 0;
6265 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
6266 (int) BFD_RELOC_LO16, AT);
6267 if (! target_big_endian)
6268 expr1.X_add_number = 0;
6270 expr1.X_add_number = 1;
6271 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
6272 (int) BFD_RELOC_LO16, AT);
6273 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
6275 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
6280 /* FIXME: Check if this is one of the itbl macros, since they
6281 are added dynamically. */
6282 as_bad ("Macro %s not implemented yet", ip->insn_mo->name);
6286 as_warn ("Macro used $at after \".set noat\"");
6289 /* Implement macros in mips16 mode. */
6293 struct mips_cl_insn *ip;
6296 int xreg, yreg, zreg, tmp;
6300 const char *s, *s2, *s3;
6302 mask = ip->insn_mo->mask;
6304 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
6305 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
6306 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
6310 expr1.X_op = O_constant;
6311 expr1.X_op_symbol = NULL;
6312 expr1.X_add_symbol = NULL;
6313 expr1.X_add_number = 1;
6332 mips_emit_delays (true);
6333 ++mips_opts.noreorder;
6334 mips_any_noreorder = 1;
6335 macro_build ((char *) NULL, &icnt, NULL,
6336 dbl ? "ddiv" : "div",
6337 "0,x,y", xreg, yreg);
6338 expr1.X_add_number = 2;
6339 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
6340 macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7);
6341 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
6342 since that causes an overflow. We should do that as well,
6343 but I don't see how to do the comparisons without a temporary
6345 --mips_opts.noreorder;
6346 macro_build ((char *) NULL, &icnt, NULL, s, "x", zreg);
6365 mips_emit_delays (true);
6366 ++mips_opts.noreorder;
6367 mips_any_noreorder = 1;
6368 macro_build ((char *) NULL, &icnt, NULL, s, "0,x,y", xreg, yreg);
6369 expr1.X_add_number = 2;
6370 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
6371 macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7);
6372 --mips_opts.noreorder;
6373 macro_build ((char *) NULL, &icnt, NULL, s2, "x", zreg);
6379 macro_build ((char *) NULL, &icnt, NULL,
6380 dbl ? "dmultu" : "multu",
6382 macro_build ((char *) NULL, &icnt, NULL, "mflo", "x", zreg);
6390 if (imm_expr.X_op != O_constant)
6391 as_bad ("Unsupported large constant");
6392 imm_expr.X_add_number = -imm_expr.X_add_number;
6393 macro_build ((char *) NULL, &icnt, &imm_expr,
6394 dbl ? "daddiu" : "addiu",
6395 "y,x,4", yreg, xreg);
6399 if (imm_expr.X_op != O_constant)
6400 as_bad ("Unsupported large constant");
6401 imm_expr.X_add_number = -imm_expr.X_add_number;
6402 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
6407 if (imm_expr.X_op != O_constant)
6408 as_bad ("Unsupported large constant");
6409 imm_expr.X_add_number = -imm_expr.X_add_number;
6410 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
6433 goto do_reverse_branch;
6437 goto do_reverse_branch;
6449 goto do_reverse_branch;
6460 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
6462 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
6489 goto do_addone_branch_i;
6494 goto do_addone_branch_i;
6509 goto do_addone_branch_i;
6516 if (imm_expr.X_op != O_constant)
6517 as_bad ("Unsupported large constant");
6518 ++imm_expr.X_add_number;
6521 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
6522 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
6526 expr1.X_add_number = 0;
6527 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
6529 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6530 "move", "y,X", xreg, yreg);
6531 expr1.X_add_number = 2;
6532 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
6533 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6534 "neg", "x,w", xreg, xreg);
6538 /* This routine assembles an instruction into its binary format. As a
6539 side effect, it sets one of the global variables imm_reloc or
6540 offset_reloc to the type of relocation to do if one of the operands
6541 is an address expression. */
6546 struct mips_cl_insn *ip;
6551 struct mips_opcode *insn;
6554 unsigned int lastregno = 0;
6559 for (s = str; *s != '\0' && !isspace(*s); ++s)
6564 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
6566 insn_error = "unrecognized opcode";
6575 assert (strcmp (insn->name, str) == 0);
6577 if (insn->pinfo == INSN_MACRO)
6578 insn_isa = insn->match;
6579 else if ((insn->membership & INSN_ISA) == INSN_ISA1)
6581 else if ((insn->membership & INSN_ISA) == INSN_ISA2)
6583 else if ((insn->membership & INSN_ISA) == INSN_ISA3)
6585 else if ((insn->membership & INSN_ISA) == INSN_ISA4)
6590 if (insn_isa <= mips_opts.isa)
6592 else if (insn->pinfo == INSN_MACRO)
6594 else if ((mips_4650 && (insn->membership & INSN_4650) != 0)
6595 || (mips_4010 && (insn->membership & INSN_4010) != 0)
6596 || (mips_4100 && (insn->membership & INSN_4100) != 0)
6597 /* start-sanitize-r5900 */
6598 || (mips_5900 && (insn->membership & INSN_5900) != 0)
6599 /* end-sanitize-r5900 */
6600 || (mips_3900 && (insn->membership & INSN_3900) != 0))
6603 if (mips_4650 && (insn->pinfo & FP_D) != 0)
6605 /* start-sanitize-r5900 */
6606 if (mips_5900 && (insn->pinfo & FP_D) != 0)
6608 /* end-sanitize-r5900 */
6615 if (insn + 1 < &mips_opcodes[NUMOPCODES]
6616 && strcmp (insn->name, insn[1].name) == 0)
6621 if (insn_isa <= mips_opts.isa)
6622 insn_error = "opcode not supported on this processor";
6625 static char buf[100];
6627 sprintf (buf, "opcode requires -mips%d or greater", insn_isa);
6634 ip->insn_opcode = insn->match;
6635 for (args = insn->args;; ++args)
6641 case '\0': /* end of args */
6654 ip->insn_opcode |= lastregno << 21;
6659 ip->insn_opcode |= lastregno << 16;
6663 ip->insn_opcode |= lastregno << 11;
6669 /* handle optional base register.
6670 Either the base register is omitted or
6671 we must have a left paren. */
6672 /* this is dependent on the next operand specifier
6673 is a 'b' for base register */
6674 assert (args[1] == 'b');
6678 case ')': /* these must match exactly */
6683 case '<': /* must be at least one digit */
6685 * According to the manual, if the shift amount is greater
6686 * than 31 or less than 0 the the shift amount should be
6687 * mod 32. In reality the mips assembler issues an error.
6688 * We issue a warning and mask out all but the low 5 bits.
6690 my_getExpression (&imm_expr, s);
6691 check_absolute_expr (ip, &imm_expr);
6692 if ((unsigned long) imm_expr.X_add_number > 31)
6694 as_warn ("Improper shift amount (%ld)",
6695 (long) imm_expr.X_add_number);
6696 imm_expr.X_add_number = imm_expr.X_add_number & 0x1f;
6698 ip->insn_opcode |= imm_expr.X_add_number << 6;
6699 imm_expr.X_op = O_absent;
6703 case '>': /* shift amount minus 32 */
6704 my_getExpression (&imm_expr, s);
6705 check_absolute_expr (ip, &imm_expr);
6706 if ((unsigned long) imm_expr.X_add_number < 32
6707 || (unsigned long) imm_expr.X_add_number > 63)
6709 ip->insn_opcode |= (imm_expr.X_add_number - 32) << 6;
6710 imm_expr.X_op = O_absent;
6714 case 'k': /* cache code */
6715 case 'h': /* prefx code */
6716 my_getExpression (&imm_expr, s);
6717 check_absolute_expr (ip, &imm_expr);
6718 if ((unsigned long) imm_expr.X_add_number > 31)
6720 as_warn ("Invalid value for `%s' (%lu)",
6722 (unsigned long) imm_expr.X_add_number);
6723 imm_expr.X_add_number &= 0x1f;
6726 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
6728 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
6729 imm_expr.X_op = O_absent;
6733 case 'c': /* break code */
6734 my_getExpression (&imm_expr, s);
6735 check_absolute_expr (ip, &imm_expr);
6736 if ((unsigned) imm_expr.X_add_number > 1023)
6737 as_warn ("Illegal break code (%ld)",
6738 (long) imm_expr.X_add_number);
6739 ip->insn_opcode |= imm_expr.X_add_number << 16;
6740 imm_expr.X_op = O_absent;
6744 case 'B': /* syscall code */
6745 my_getExpression (&imm_expr, s);
6746 check_absolute_expr (ip, &imm_expr);
6747 if ((unsigned) imm_expr.X_add_number > 0xfffff)
6748 as_warn ("Illegal syscall code (%ld)",
6749 (long) imm_expr.X_add_number);
6750 ip->insn_opcode |= imm_expr.X_add_number << 6;
6751 imm_expr.X_op = O_absent;
6755 case 'C': /* Coprocessor code */
6756 my_getExpression (&imm_expr, s);
6757 check_absolute_expr (ip, &imm_expr);
6758 if ((unsigned long) imm_expr.X_add_number >= (1<<25))
6760 as_warn ("Coproccesor code > 25 bits (%ld)",
6761 (long) imm_expr.X_add_number);
6762 imm_expr.X_add_number &= ((1<<25) - 1);
6764 ip->insn_opcode |= imm_expr.X_add_number;
6765 imm_expr.X_op = O_absent;
6769 case 'b': /* base register */
6770 case 'd': /* destination register */
6771 case 's': /* source register */
6772 case 't': /* target register */
6773 case 'r': /* both target and source */
6774 case 'v': /* both dest and source */
6775 case 'w': /* both dest and target */
6776 case 'E': /* coprocessor target register */
6777 case 'G': /* coprocessor destination register */
6778 case 'x': /* ignore register name */
6779 case 'z': /* must be zero register */
6793 while (isdigit (*s));
6795 as_bad ("Invalid register number (%d)", regno);
6797 else if (*args == 'E' || *args == 'G')
6801 if (s[1] == 'f' && s[2] == 'p')
6806 else if (s[1] == 's' && s[2] == 'p')
6811 else if (s[1] == 'g' && s[2] == 'p')
6816 else if (s[1] == 'a' && s[2] == 't')
6821 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
6826 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
6831 else if (itbl_have_entries)
6836 p = s+1; /* advance past '$' */
6837 n = itbl_get_field (&p); /* n is name */
6839 /* See if this is a register defined in an
6841 r = itbl_get_reg_val (n);
6844 /* Get_field advances to the start of
6845 the next field, so we need to back
6846 rack to the end of the last field. */
6850 s = strchr (s,'\0');
6863 as_warn ("Used $at without \".set noat\"");
6869 if (c == 'r' || c == 'v' || c == 'w')
6876 /* 'z' only matches $0. */
6877 if (c == 'z' && regno != 0)
6880 /* Now that we have assembled one operand, we use the args string
6881 * to figure out where it goes in the instruction. */
6888 ip->insn_opcode |= regno << 21;
6892 ip->insn_opcode |= regno << 11;
6897 ip->insn_opcode |= regno << 16;
6900 /* This case exists because on the r3000 trunc
6901 expands into a macro which requires a gp
6902 register. On the r6000 or r4000 it is
6903 assembled into a single instruction which
6904 ignores the register. Thus the insn version
6905 is MIPS_ISA2 and uses 'x', and the macro
6906 version is MIPS_ISA1 and uses 't'. */
6909 /* This case is for the div instruction, which
6910 acts differently if the destination argument
6911 is $0. This only matches $0, and is checked
6912 outside the switch. */
6915 /* Itbl operand; not yet implemented. FIXME ?? */
6917 /* What about all other operands like 'i', which
6918 can be specified in the opcode table? */
6928 ip->insn_opcode |= lastregno << 21;
6931 ip->insn_opcode |= lastregno << 16;
6936 case 'D': /* floating point destination register */
6937 case 'S': /* floating point source register */
6938 case 'T': /* floating point target register */
6939 case 'R': /* floating point source register */
6943 if (s[0] == '$' && s[1] == 'f' && isdigit (s[2]))
6953 while (isdigit (*s));
6956 as_bad ("Invalid float register number (%d)", regno);
6958 if ((regno & 1) != 0
6959 && mips_opts.isa < 3
6960 && ! (strcmp (str, "mtc1") == 0
6961 || strcmp (str, "mfc1") == 0
6962 || strcmp (str, "lwc1") == 0
6963 || strcmp (str, "swc1") == 0
6964 || strcmp (str, "l.s") == 0
6965 || strcmp (str, "s.s") == 0))
6966 as_warn ("Float register should be even, was %d",
6974 if (c == 'V' || c == 'W')
6984 ip->insn_opcode |= regno << 6;
6988 ip->insn_opcode |= regno << 11;
6992 ip->insn_opcode |= regno << 16;
6995 ip->insn_opcode |= regno << 21;
7004 ip->insn_opcode |= lastregno << 11;
7007 ip->insn_opcode |= lastregno << 16;
7013 my_getExpression (&imm_expr, s);
7014 if (imm_expr.X_op != O_big
7015 && imm_expr.X_op != O_constant)
7016 insn_error = "absolute expression required";
7021 my_getExpression (&offset_expr, s);
7022 imm_reloc = BFD_RELOC_32;
7034 unsigned char temp[8];
7036 unsigned int length;
7041 /* These only appear as the last operand in an
7042 instruction, and every instruction that accepts
7043 them in any variant accepts them in all variants.
7044 This means we don't have to worry about backing out
7045 any changes if the instruction does not match.
7047 The difference between them is the size of the
7048 floating point constant and where it goes. For 'F'
7049 and 'L' the constant is 64 bits; for 'f' and 'l' it
7050 is 32 bits. Where the constant is placed is based
7051 on how the MIPS assembler does things:
7054 f -- immediate value
7057 The .lit4 and .lit8 sections are only used if
7058 permitted by the -G argument.
7060 When generating embedded PIC code, we use the
7061 .lit8 section but not the .lit4 section (we can do
7062 .lit4 inline easily; we need to put .lit8
7063 somewhere in the data segment, and using .lit8
7064 permits the linker to eventually combine identical
7067 f64 = *args == 'F' || *args == 'L';
7069 save_in = input_line_pointer;
7070 input_line_pointer = s;
7071 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
7073 s = input_line_pointer;
7074 input_line_pointer = save_in;
7075 if (err != NULL && *err != '\0')
7077 as_bad ("Bad floating point constant: %s", err);
7078 memset (temp, '\0', sizeof temp);
7079 length = f64 ? 8 : 4;
7082 assert (length == (f64 ? 8 : 4));
7086 && (! USE_GLOBAL_POINTER_OPT
7087 || mips_pic == EMBEDDED_PIC
7088 || g_switch_value < 4
7089 || (temp[0] == 0 && temp[1] == 0)
7090 || (temp[2] == 0 && temp[3] == 0))))
7092 imm_expr.X_op = O_constant;
7093 if (! target_big_endian)
7094 imm_expr.X_add_number = bfd_getl32 (temp);
7096 imm_expr.X_add_number = bfd_getb32 (temp);
7099 && ((temp[0] == 0 && temp[1] == 0)
7100 || (temp[2] == 0 && temp[3] == 0))
7101 && ((temp[4] == 0 && temp[5] == 0)
7102 || (temp[6] == 0 && temp[7] == 0)))
7104 /* The value is simple enough to load with a
7105 couple of instructions. In mips1 mode, set
7106 imm_expr to the high order 32 bits and
7107 offset_expr to the low order 32 bits.
7108 Otherwise, set imm_expr to the entire 64 bit
7110 if (mips_opts.isa < 3)
7112 imm_expr.X_op = O_constant;
7113 offset_expr.X_op = O_constant;
7114 if (! target_big_endian)
7116 imm_expr.X_add_number = bfd_getl32 (temp + 4);
7117 offset_expr.X_add_number = bfd_getl32 (temp);
7121 imm_expr.X_add_number = bfd_getb32 (temp);
7122 offset_expr.X_add_number = bfd_getb32 (temp + 4);
7124 if (offset_expr.X_add_number == 0)
7125 offset_expr.X_op = O_absent;
7127 else if (sizeof (imm_expr.X_add_number) > 4)
7129 imm_expr.X_op = O_constant;
7130 if (! target_big_endian)
7131 imm_expr.X_add_number = bfd_getl64 (temp);
7133 imm_expr.X_add_number = bfd_getb64 (temp);
7137 imm_expr.X_op = O_big;
7138 imm_expr.X_add_number = 4;
7139 if (! target_big_endian)
7141 generic_bignum[0] = bfd_getl16 (temp);
7142 generic_bignum[1] = bfd_getl16 (temp + 2);
7143 generic_bignum[2] = bfd_getl16 (temp + 4);
7144 generic_bignum[3] = bfd_getl16 (temp + 6);
7148 generic_bignum[0] = bfd_getb16 (temp + 6);
7149 generic_bignum[1] = bfd_getb16 (temp + 4);
7150 generic_bignum[2] = bfd_getb16 (temp + 2);
7151 generic_bignum[3] = bfd_getb16 (temp);
7157 const char *newname;
7160 /* Switch to the right section. */
7162 subseg = now_subseg;
7165 default: /* unused default case avoids warnings. */
7167 newname = RDATA_SECTION_NAME;
7168 if (USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
7172 newname = RDATA_SECTION_NAME;
7175 assert (!USE_GLOBAL_POINTER_OPT
7176 || g_switch_value >= 4);
7180 new_seg = subseg_new (newname, (subsegT) 0);
7181 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7182 bfd_set_section_flags (stdoutput, new_seg,
7187 frag_align (*args == 'l' ? 2 : 3, 0, 0);
7188 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
7189 && strcmp (TARGET_OS, "elf") != 0)
7190 record_alignment (new_seg, 4);
7192 record_alignment (new_seg, *args == 'l' ? 2 : 3);
7194 as_bad ("Can't use floating point insn in this section");
7196 /* Set the argument to the current address in the
7198 offset_expr.X_op = O_symbol;
7199 offset_expr.X_add_symbol =
7200 symbol_new ("L0\001", now_seg,
7201 (valueT) frag_now_fix (), frag_now);
7202 offset_expr.X_add_number = 0;
7204 /* Put the floating point number into the section. */
7205 p = frag_more ((int) length);
7206 memcpy (p, temp, length);
7208 /* Switch back to the original section. */
7209 subseg_set (seg, subseg);
7214 case 'i': /* 16 bit unsigned immediate */
7215 case 'j': /* 16 bit signed immediate */
7216 imm_reloc = BFD_RELOC_LO16;
7217 c = my_getSmallExpression (&imm_expr, s);
7222 if (imm_expr.X_op == O_constant)
7223 imm_expr.X_add_number =
7224 (imm_expr.X_add_number >> 16) & 0xffff;
7227 imm_reloc = BFD_RELOC_HI16_S;
7228 imm_unmatched_hi = true;
7231 imm_reloc = BFD_RELOC_HI16;
7236 if ((c == '\0' && imm_expr.X_op != O_constant)
7237 || ((imm_expr.X_add_number < 0
7238 || imm_expr.X_add_number >= 0x10000)
7239 && imm_expr.X_op == O_constant))
7241 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7242 !strcmp (insn->name, insn[1].name))
7244 if (imm_expr.X_op != O_constant
7245 && imm_expr.X_op != O_big)
7246 insn_error = "absolute expression required";
7248 as_bad ("16 bit expression not in range 0..65535");
7256 /* The upper bound should be 0x8000, but
7257 unfortunately the MIPS assembler accepts numbers
7258 from 0x8000 to 0xffff and sign extends them, and
7259 we want to be compatible. We only permit this
7260 extended range for an instruction which does not
7261 provide any further alternates, since those
7262 alternates may handle other cases. People should
7263 use the numbers they mean, rather than relying on
7264 a mysterious sign extension. */
7265 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7266 strcmp (insn->name, insn[1].name) == 0);
7271 if ((c == '\0' && imm_expr.X_op != O_constant)
7272 || ((imm_expr.X_add_number < -0x8000
7273 || imm_expr.X_add_number >= max)
7274 && imm_expr.X_op == O_constant)
7276 && imm_expr.X_add_number < 0
7277 && mips_opts.isa >= 3
7278 && imm_expr.X_unsigned
7279 && sizeof (imm_expr.X_add_number) <= 4))
7283 if (imm_expr.X_op != O_constant
7284 && imm_expr.X_op != O_big)
7285 insn_error = "absolute expression required";
7287 as_bad ("16 bit expression not in range -32768..32767");
7293 case 'o': /* 16 bit offset */
7294 c = my_getSmallExpression (&offset_expr, s);
7296 /* If this value won't fit into a 16 bit offset, then go
7297 find a macro that will generate the 32 bit offset
7298 code pattern. As a special hack, we accept the
7299 difference of two local symbols as a constant. This
7300 is required to suppose embedded PIC switches, which
7301 use an instruction which looks like
7302 lw $4,$L12-$LS12($4)
7303 The problem with handling this in a more general
7304 fashion is that the macro function doesn't expect to
7305 see anything which can be handled in a single
7306 constant instruction. */
7308 && (offset_expr.X_op != O_constant
7309 || offset_expr.X_add_number >= 0x8000
7310 || offset_expr.X_add_number < -0x8000)
7311 && (mips_pic != EMBEDDED_PIC
7312 || offset_expr.X_op != O_subtract
7313 || now_seg != text_section
7314 || (S_GET_SEGMENT (offset_expr.X_op_symbol)
7318 offset_reloc = BFD_RELOC_LO16;
7319 if (c == 'h' || c == 'H')
7321 assert (offset_expr.X_op == O_constant);
7322 offset_expr.X_add_number =
7323 (offset_expr.X_add_number >> 16) & 0xffff;
7328 case 'p': /* pc relative offset */
7329 offset_reloc = BFD_RELOC_16_PCREL_S2;
7330 my_getExpression (&offset_expr, s);
7334 case 'u': /* upper 16 bits */
7335 c = my_getSmallExpression (&imm_expr, s);
7336 if (imm_expr.X_op == O_constant
7337 && (imm_expr.X_add_number < 0
7338 || imm_expr.X_add_number >= 0x10000))
7339 as_bad ("lui expression not in range 0..65535");
7340 imm_reloc = BFD_RELOC_LO16;
7345 if (imm_expr.X_op == O_constant)
7346 imm_expr.X_add_number =
7347 (imm_expr.X_add_number >> 16) & 0xffff;
7350 imm_reloc = BFD_RELOC_HI16_S;
7351 imm_unmatched_hi = true;
7354 imm_reloc = BFD_RELOC_HI16;
7360 case 'a': /* 26 bit address */
7361 my_getExpression (&offset_expr, s);
7363 offset_reloc = BFD_RELOC_MIPS_JMP;
7366 case 'N': /* 3 bit branch condition code */
7367 case 'M': /* 3 bit compare condition code */
7368 if (strncmp (s, "$fcc", 4) != 0)
7378 while (isdigit (*s));
7380 as_bad ("invalid condition code register $fcc%d", regno);
7382 ip->insn_opcode |= regno << OP_SH_BCC;
7384 ip->insn_opcode |= regno << OP_SH_CCC;
7388 fprintf (stderr, "bad char = '%c'\n", *args);
7393 /* Args don't match. */
7394 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7395 !strcmp (insn->name, insn[1].name))
7401 insn_error = "illegal operands";
7406 /* This routine assembles an instruction into its binary format when
7407 assembling for the mips16. As a side effect, it sets one of the
7408 global variables imm_reloc or offset_reloc to the type of
7409 relocation to do if one of the operands is an address expression.
7410 It also sets mips16_small and mips16_ext if the user explicitly
7411 requested a small or extended instruction. */
7416 struct mips_cl_insn *ip;
7420 struct mips_opcode *insn;
7423 unsigned int lastregno = 0;
7428 mips16_small = false;
7431 for (s = str; islower (*s); ++s)
7443 if (s[1] == 't' && s[2] == ' ')
7446 mips16_small = true;
7450 else if (s[1] == 'e' && s[2] == ' ')
7459 insn_error = "unknown opcode";
7463 if (mips_opts.noautoextend && ! mips16_ext)
7464 mips16_small = true;
7466 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
7468 insn_error = "unrecognized opcode";
7475 assert (strcmp (insn->name, str) == 0);
7478 ip->insn_opcode = insn->match;
7479 ip->use_extend = false;
7480 imm_expr.X_op = O_absent;
7481 imm_reloc = BFD_RELOC_UNUSED;
7482 offset_expr.X_op = O_absent;
7483 offset_reloc = BFD_RELOC_UNUSED;
7484 for (args = insn->args; 1; ++args)
7491 /* In this switch statement we call break if we did not find
7492 a match, continue if we did find a match, or return if we
7501 /* Stuff the immediate value in now, if we can. */
7502 if (imm_expr.X_op == O_constant
7503 && imm_reloc > BFD_RELOC_UNUSED
7504 && insn->pinfo != INSN_MACRO)
7506 mips16_immed ((char *) NULL, 0,
7507 imm_reloc - BFD_RELOC_UNUSED,
7508 imm_expr.X_add_number, true, mips16_small,
7509 mips16_ext, &ip->insn_opcode,
7510 &ip->use_extend, &ip->extend);
7511 imm_expr.X_op = O_absent;
7512 imm_reloc = BFD_RELOC_UNUSED;
7526 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
7529 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
7545 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
7547 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
7574 while (isdigit (*s));
7577 as_bad ("invalid register number (%d)", regno);
7583 if (s[1] == 'f' && s[2] == 'p')
7588 else if (s[1] == 's' && s[2] == 'p')
7593 else if (s[1] == 'g' && s[2] == 'p')
7598 else if (s[1] == 'a' && s[2] == 't')
7603 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
7608 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
7621 if (c == 'v' || c == 'w')
7623 regno = mips16_to_32_reg_map[lastregno];
7637 regno = mips32_to_16_reg_map[regno];
7642 regno = ILLEGAL_REG;
7647 regno = ILLEGAL_REG;
7652 regno = ILLEGAL_REG;
7657 if (regno == AT && ! mips_opts.noat)
7658 as_warn ("used $at without \".set noat\"");
7665 if (regno == ILLEGAL_REG)
7672 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
7676 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
7679 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
7682 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
7688 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
7691 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
7692 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
7702 if (strncmp (s, "$pc", 3) == 0)
7726 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
7728 /* This is %gprel(SYMBOL). We need to read SYMBOL,
7729 and generate the appropriate reloc. If the text
7730 inside %gprel is not a symbol name with an
7731 optional offset, then we generate a normal reloc
7732 and will probably fail later. */
7733 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
7734 if (imm_expr.X_op == O_symbol)
7737 imm_reloc = BFD_RELOC_MIPS16_GPREL;
7739 ip->use_extend = true;
7746 /* Just pick up a normal expression. */
7747 my_getExpression (&imm_expr, s);
7750 if (imm_expr.X_op == O_register)
7752 /* What we thought was an expression turned out to
7755 if (s[0] == '(' && args[1] == '(')
7757 /* It looks like the expression was omitted
7758 before a register indirection, which means
7759 that the expression is implicitly zero. We
7760 still set up imm_expr, so that we handle
7761 explicit extensions correctly. */
7762 imm_expr.X_op = O_constant;
7763 imm_expr.X_add_number = 0;
7764 imm_reloc = (int) BFD_RELOC_UNUSED + c;
7771 /* We need to relax this instruction. */
7772 imm_reloc = (int) BFD_RELOC_UNUSED + c;
7781 /* We use offset_reloc rather than imm_reloc for the PC
7782 relative operands. This lets macros with both
7783 immediate and address operands work correctly. */
7784 my_getExpression (&offset_expr, s);
7786 if (offset_expr.X_op == O_register)
7789 /* We need to relax this instruction. */
7790 offset_reloc = (int) BFD_RELOC_UNUSED + c;
7794 case '6': /* break code */
7795 my_getExpression (&imm_expr, s);
7796 check_absolute_expr (ip, &imm_expr);
7797 if ((unsigned long) imm_expr.X_add_number > 63)
7799 as_warn ("Invalid value for `%s' (%lu)",
7801 (unsigned long) imm_expr.X_add_number);
7802 imm_expr.X_add_number &= 0x3f;
7804 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
7805 imm_expr.X_op = O_absent;
7809 case 'a': /* 26 bit address */
7810 my_getExpression (&offset_expr, s);
7812 offset_reloc = BFD_RELOC_MIPS16_JMP;
7813 ip->insn_opcode <<= 16;
7816 case 'l': /* register list for entry macro */
7817 case 'L': /* register list for exit macro */
7827 int freg, reg1, reg2;
7829 while (*s == ' ' || *s == ',')
7833 as_bad ("can't parse register list");
7845 while (isdigit (*s))
7867 as_bad ("invalid register list");
7872 while (isdigit (*s))
7879 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
7884 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
7889 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
7890 mask |= (reg2 - 3) << 3;
7891 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
7892 mask |= (reg2 - 15) << 1;
7893 else if (reg1 == 31 && reg2 == 31)
7897 as_bad ("invalid register list");
7901 /* The mask is filled in in the opcode table for the
7902 benefit of the disassembler. We remove it before
7903 applying the actual mask. */
7904 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
7905 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
7909 case 'e': /* extend code */
7910 my_getExpression (&imm_expr, s);
7911 check_absolute_expr (ip, &imm_expr);
7912 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
7914 as_warn ("Invalid value for `%s' (%lu)",
7916 (unsigned long) imm_expr.X_add_number);
7917 imm_expr.X_add_number &= 0x7ff;
7919 ip->insn_opcode |= imm_expr.X_add_number;
7920 imm_expr.X_op = O_absent;
7930 /* Args don't match. */
7931 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
7932 strcmp (insn->name, insn[1].name) == 0)
7939 insn_error = "illegal operands";
7945 /* This structure holds information we know about a mips16 immediate
7948 struct mips16_immed_operand
7950 /* The type code used in the argument string in the opcode table. */
7952 /* The number of bits in the short form of the opcode. */
7954 /* The number of bits in the extended form of the opcode. */
7956 /* The amount by which the short form is shifted when it is used;
7957 for example, the sw instruction has a shift count of 2. */
7959 /* The amount by which the short form is shifted when it is stored
7960 into the instruction code. */
7962 /* Non-zero if the short form is unsigned. */
7964 /* Non-zero if the extended form is unsigned. */
7966 /* Non-zero if the value is PC relative. */
7970 /* The mips16 immediate operand types. */
7972 static const struct mips16_immed_operand mips16_immed_operands[] =
7974 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
7975 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
7976 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
7977 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
7978 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
7979 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
7980 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
7981 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
7982 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
7983 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
7984 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
7985 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
7986 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
7987 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
7988 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
7989 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
7990 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
7991 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
7992 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
7993 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
7994 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
7997 #define MIPS16_NUM_IMMED \
7998 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
8000 /* Handle a mips16 instruction with an immediate value. This or's the
8001 small immediate value into *INSN. It sets *USE_EXTEND to indicate
8002 whether an extended value is needed; if one is needed, it sets
8003 *EXTEND to the value. The argument type is TYPE. The value is VAL.
8004 If SMALL is true, an unextended opcode was explicitly requested.
8005 If EXT is true, an extended opcode was explicitly requested. If
8006 WARN is true, warn if EXT does not match reality. */
8009 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
8018 unsigned long *insn;
8019 boolean *use_extend;
8020 unsigned short *extend;
8022 register const struct mips16_immed_operand *op;
8023 int mintiny, maxtiny;
8026 op = mips16_immed_operands;
8027 while (op->type != type)
8030 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
8035 if (type == '<' || type == '>' || type == '[' || type == ']')
8038 maxtiny = 1 << op->nbits;
8043 maxtiny = (1 << op->nbits) - 1;
8048 mintiny = - (1 << (op->nbits - 1));
8049 maxtiny = (1 << (op->nbits - 1)) - 1;
8052 /* Branch offsets have an implicit 0 in the lowest bit. */
8053 if (type == 'p' || type == 'q')
8056 if ((val & ((1 << op->shift) - 1)) != 0
8057 || val < (mintiny << op->shift)
8058 || val > (maxtiny << op->shift))
8063 if (warn && ext && ! needext)
8064 as_warn_where (file, line, "extended operand requested but not required");
8065 if (small && needext)
8066 as_bad_where (file, line, "invalid unextended operand value");
8068 if (small || (! ext && ! needext))
8072 *use_extend = false;
8073 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
8074 insnval <<= op->op_shift;
8079 long minext, maxext;
8085 maxext = (1 << op->extbits) - 1;
8089 minext = - (1 << (op->extbits - 1));
8090 maxext = (1 << (op->extbits - 1)) - 1;
8092 if (val < minext || val > maxext)
8093 as_bad_where (file, line,
8094 "operand value out of range for instruction");
8097 if (op->extbits == 16)
8099 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
8102 else if (op->extbits == 15)
8104 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
8109 extval = ((val & 0x1f) << 6) | (val & 0x20);
8113 *extend = (unsigned short) extval;
8122 my_getSmallExpression (ep, str)
8133 ((str[1] == 'h' && str[2] == 'i')
8134 || (str[1] == 'H' && str[2] == 'I')
8135 || (str[1] == 'l' && str[2] == 'o'))
8147 * A small expression may be followed by a base register.
8148 * Scan to the end of this operand, and then back over a possible
8149 * base register. Then scan the small expression up to that
8150 * point. (Based on code in sparc.c...)
8152 for (sp = str; *sp && *sp != ','; sp++)
8154 if (sp - 4 >= str && sp[-1] == RP)
8156 if (isdigit (sp[-2]))
8158 for (sp -= 3; sp >= str && isdigit (*sp); sp--)
8160 if (*sp == '$' && sp > str && sp[-1] == LP)
8166 else if (sp - 5 >= str
8169 && ((sp[-3] == 'f' && sp[-2] == 'p')
8170 || (sp[-3] == 's' && sp[-2] == 'p')
8171 || (sp[-3] == 'g' && sp[-2] == 'p')
8172 || (sp[-3] == 'a' && sp[-2] == 't')))
8178 /* no expression means zero offset */
8181 /* %xx(reg) is an error */
8182 ep->X_op = O_absent;
8187 ep->X_op = O_constant;
8190 ep->X_add_symbol = NULL;
8191 ep->X_op_symbol = NULL;
8192 ep->X_add_number = 0;
8197 my_getExpression (ep, str);
8204 my_getExpression (ep, str);
8205 return c; /* => %hi or %lo encountered */
8209 my_getExpression (ep, str)
8215 save_in = input_line_pointer;
8216 input_line_pointer = str;
8218 expr_end = input_line_pointer;
8219 input_line_pointer = save_in;
8221 /* If we are in mips16 mode, and this is an expression based on `.',
8222 then we bump the value of the symbol by 1 since that is how other
8223 text symbols are handled. We don't bother to handle complex
8224 expressions, just `.' plus or minus a constant. */
8225 if (mips_opts.mips16
8226 && ep->X_op == O_symbol
8227 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
8228 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
8229 && ep->X_add_symbol->sy_frag == frag_now
8230 && ep->X_add_symbol->sy_value.X_op == O_constant
8231 && ep->X_add_symbol->sy_value.X_add_number == frag_now_fix ())
8232 ++ep->X_add_symbol->sy_value.X_add_number;
8235 /* Turn a string in input_line_pointer into a floating point constant
8236 of type type, and store the appropriate bytes in *litP. The number
8237 of LITTLENUMS emitted is stored in *sizeP . An error message is
8238 returned, or NULL on OK. */
8241 md_atof (type, litP, sizeP)
8247 LITTLENUM_TYPE words[4];
8263 return "bad call to md_atof";
8266 t = atof_ieee (input_line_pointer, type, words);
8268 input_line_pointer = t;
8272 if (! target_big_endian)
8274 for (i = prec - 1; i >= 0; i--)
8276 md_number_to_chars (litP, (valueT) words[i], 2);
8282 for (i = 0; i < prec; i++)
8284 md_number_to_chars (litP, (valueT) words[i], 2);
8293 md_number_to_chars (buf, val, n)
8298 if (target_big_endian)
8299 number_to_chars_bigendian (buf, val, n);
8301 number_to_chars_littleendian (buf, val, n);
8304 CONST char *md_shortopts = "O::g::G:";
8306 struct option md_longopts[] = {
8307 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
8308 {"mips0", no_argument, NULL, OPTION_MIPS1},
8309 {"mips1", no_argument, NULL, OPTION_MIPS1},
8310 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
8311 {"mips2", no_argument, NULL, OPTION_MIPS2},
8312 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
8313 {"mips3", no_argument, NULL, OPTION_MIPS3},
8314 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
8315 {"mips4", no_argument, NULL, OPTION_MIPS4},
8316 #define OPTION_MCPU (OPTION_MD_BASE + 5)
8317 {"mcpu", required_argument, NULL, OPTION_MCPU},
8318 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 6)
8319 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
8320 #define OPTION_TRAP (OPTION_MD_BASE + 9)
8321 {"trap", no_argument, NULL, OPTION_TRAP},
8322 {"no-break", no_argument, NULL, OPTION_TRAP},
8323 #define OPTION_BREAK (OPTION_MD_BASE + 10)
8324 {"break", no_argument, NULL, OPTION_BREAK},
8325 {"no-trap", no_argument, NULL, OPTION_BREAK},
8326 #define OPTION_EB (OPTION_MD_BASE + 11)
8327 {"EB", no_argument, NULL, OPTION_EB},
8328 #define OPTION_EL (OPTION_MD_BASE + 12)
8329 {"EL", no_argument, NULL, OPTION_EL},
8330 #define OPTION_M4650 (OPTION_MD_BASE + 13)
8331 {"m4650", no_argument, NULL, OPTION_M4650},
8332 #define OPTION_NO_M4650 (OPTION_MD_BASE + 14)
8333 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
8334 #define OPTION_M4010 (OPTION_MD_BASE + 15)
8335 {"m4010", no_argument, NULL, OPTION_M4010},
8336 #define OPTION_NO_M4010 (OPTION_MD_BASE + 16)
8337 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
8338 #define OPTION_M4100 (OPTION_MD_BASE + 17)
8339 {"m4100", no_argument, NULL, OPTION_M4100},
8340 #define OPTION_NO_M4100 (OPTION_MD_BASE + 18)
8341 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
8342 #define OPTION_MIPS16 (OPTION_MD_BASE + 22)
8343 {"mips16", no_argument, NULL, OPTION_MIPS16},
8344 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 23)
8345 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
8346 /* start-sanitize-r5900 */
8347 #define OPTION_M5900 (OPTION_MD_BASE + 24)
8348 {"m5900", no_argument, NULL, OPTION_M5900},
8349 #define OPTION_NO_M5900 (OPTION_MD_BASE + 25)
8350 {"no-m5900", no_argument, NULL, OPTION_NO_M5900},
8351 /* end-sanitize-r5900 */
8352 #define OPTION_M3900 (OPTION_MD_BASE + 26)
8353 {"m3900", no_argument, NULL, OPTION_M3900},
8354 #define OPTION_NO_M3900 (OPTION_MD_BASE + 27)
8355 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
8357 /* start-sanitize-tx19 */
8358 {"m1900", no_argument, NULL, OPTION_M3900},
8359 {"no-m1900", no_argument, NULL, OPTION_NO_M3900},
8360 /* end-sanitize-tx19 */
8362 #define OPTION_CALL_SHARED (OPTION_MD_BASE + 7)
8363 #define OPTION_NON_SHARED (OPTION_MD_BASE + 8)
8364 #define OPTION_XGOT (OPTION_MD_BASE + 19)
8365 #define OPTION_32 (OPTION_MD_BASE + 20)
8366 #define OPTION_64 (OPTION_MD_BASE + 21)
8368 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
8369 {"xgot", no_argument, NULL, OPTION_XGOT},
8370 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
8371 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
8372 {"32", no_argument, NULL, OPTION_32},
8373 {"64", no_argument, NULL, OPTION_64},
8376 {NULL, no_argument, NULL, 0}
8378 size_t md_longopts_size = sizeof(md_longopts);
8381 md_parse_option (c, arg)
8396 target_big_endian = 1;
8400 target_big_endian = 0;
8404 if (arg && arg[1] == '0')
8414 mips_debug = atoi (arg);
8415 /* When the MIPS assembler sees -g or -g2, it does not do
8416 optimizations which limit full symbolic debugging. We take
8417 that to be equivalent to -O0. */
8418 if (mips_debug == 2)
8450 /* Identify the processor type */
8452 if (strcmp (p, "default") == 0
8453 || strcmp (p, "DEFAULT") == 0)
8459 /* We need to cope with the various "vr" prefixes for the 4300
8461 if (*p == 'v' || *p == 'V')
8467 if (*p == 'r' || *p == 'R')
8474 if (strcmp (p, "10000") == 0
8475 || strcmp (p, "10k") == 0
8476 || strcmp (p, "10K") == 0)
8478 /* start-sanitize-tx19 */
8479 else if (strcmp (p, "1900") == 0)
8481 /* end-sanitize-tx19 */
8485 if (strcmp (p, "2000") == 0
8486 || strcmp (p, "2k") == 0
8487 || strcmp (p, "2K") == 0)
8492 if (strcmp (p, "3000") == 0
8493 || strcmp (p, "3k") == 0
8494 || strcmp (p, "3K") == 0)
8496 else if (strcmp (p, "3900") == 0)
8501 if (strcmp (p, "4000") == 0
8502 || strcmp (p, "4k") == 0
8503 || strcmp (p, "4K") == 0)
8505 else if (strcmp (p, "4100") == 0)
8511 else if (strcmp (p, "4300") == 0)
8513 else if (strcmp (p, "4400") == 0)
8515 else if (strcmp (p, "4600") == 0)
8517 else if (strcmp (p, "4650") == 0)
8523 else if (strcmp (p, "4010") == 0)
8532 if (strcmp (p, "5000") == 0
8533 || strcmp (p, "5k") == 0
8534 || strcmp (p, "5K") == 0)
8536 /* start-sanitize-r5900 */
8537 else if (strcmp (p, "5900") == 0)
8539 /* end-sanitize-r5900 */
8543 if (strcmp (p, "6000") == 0
8544 || strcmp (p, "6k") == 0
8545 || strcmp (p, "6K") == 0)
8550 if (strcmp (p, "8000") == 0
8551 || strcmp (p, "8k") == 0
8552 || strcmp (p, "8K") == 0)
8557 if (strcmp (p, "orion") == 0)
8562 if (sv && mips_cpu != 4300 && mips_cpu != 4100 && mips_cpu != 5000)
8564 as_bad ("ignoring invalid leading 'v' in -mcpu=%s switch", arg);
8570 as_bad ("invalid architecture -mcpu=%s", arg);
8581 case OPTION_NO_M4650:
8589 case OPTION_NO_M4010:
8597 case OPTION_NO_M4100:
8601 /* start-sanitize-r5900 */
8606 case OPTION_NO_M5900:
8609 /* end-sanitize-r5900 */
8615 case OPTION_NO_M3900:
8620 mips_opts.mips16 = 1;
8621 mips_no_prev_insn (false);
8624 case OPTION_NO_MIPS16:
8625 mips_opts.mips16 = 0;
8626 mips_no_prev_insn (false);
8629 case OPTION_MEMBEDDED_PIC:
8630 mips_pic = EMBEDDED_PIC;
8631 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
8633 as_bad ("-G may not be used with embedded PIC code");
8636 g_switch_value = 0x7fffffff;
8639 /* When generating ELF code, we permit -KPIC and -call_shared to
8640 select SVR4_PIC, and -non_shared to select no PIC. This is
8641 intended to be compatible with Irix 5. */
8642 case OPTION_CALL_SHARED:
8643 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
8645 as_bad ("-call_shared is supported only for ELF format");
8648 mips_pic = SVR4_PIC;
8649 if (g_switch_seen && g_switch_value != 0)
8651 as_bad ("-G may not be used with SVR4 PIC code");
8657 case OPTION_NON_SHARED:
8658 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
8660 as_bad ("-non_shared is supported only for ELF format");
8666 /* The -xgot option tells the assembler to use 32 offsets when
8667 accessing the got in SVR4_PIC mode. It is for Irix
8674 if (! USE_GLOBAL_POINTER_OPT)
8676 as_bad ("-G is not supported for this configuration");
8679 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
8681 as_bad ("-G may not be used with SVR4 or embedded PIC code");
8685 g_switch_value = atoi (arg);
8689 /* The -32 and -64 options tell the assembler to output the 32
8690 bit or the 64 bit MIPS ELF format. */
8697 const char **list, **l;
8699 list = bfd_target_list ();
8700 for (l = list; *l != NULL; l++)
8701 if (strcmp (*l, "elf64-bigmips") == 0
8702 || strcmp (*l, "elf64-littlemips") == 0)
8705 as_fatal ("No compiled in support for 64 bit object file format");
8719 md_show_usage (stream)
8724 -membedded-pic generate embedded position independent code\n\
8725 -EB generate big endian output\n\
8726 -EL generate little endian output\n\
8727 -g, -g2 do not remove uneeded NOPs or swap branches\n\
8728 -G NUM allow referencing objects up to NUM bytes\n\
8729 implicitly with the gp register [default 8]\n");
8731 -mips1, -mcpu=r{2,3}000 generate code for r2000 and r3000\n\
8732 -mips2, -mcpu=r6000 generate code for r6000\n\
8733 -mips3, -mcpu=r4000 generate code for r4000\n\
8734 -mips4, -mcpu=r8000 generate code for r8000\n\
8735 -mcpu=vr4300 generate code for vr4300\n\
8736 -mcpu=vr4100 generate code for vr4100\n\
8737 -m4650 permit R4650 instructions\n\
8738 -no-m4650 do not permit R4650 instructions\n\
8739 -m4010 permit R4010 instructions\n\
8740 -no-m4010 do not permit R4010 instructions\n\
8741 -m4100 permit VR4100 instructions\n\
8742 -no-m4100 do not permit VR4100 instructions\n");
8744 -mips16 generate mips16 instructions\n\
8745 -no-mips16 do not generate mips16 instructions\n");
8747 -O0 remove unneeded NOPs, do not swap branches\n\
8748 -O remove unneeded NOPs and swap branches\n\
8749 --trap, --no-break trap exception on div by 0 and mult overflow\n\
8750 --break, --no-trap break exception on div by 0 and mult overflow\n");
8753 -KPIC, -call_shared generate SVR4 position independent code\n\
8754 -non_shared do not generate position independent code\n\
8755 -xgot assume a 32 bit GOT\n\
8756 -32 create 32 bit object file (default)\n\
8757 -64 create 64 bit object file\n");
8762 mips_init_after_args ()
8764 /* initialize opcodes */
8765 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
8766 mips_opcodes = (struct mips_opcode*) mips_builtin_opcodes;
8770 md_pcrel_from (fixP)
8773 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
8774 && fixP->fx_addsy != (symbolS *) NULL
8775 && ! S_IS_DEFINED (fixP->fx_addsy))
8777 /* This makes a branch to an undefined symbol be a branch to the
8778 current location. */
8782 /* return the address of the delay slot */
8783 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
8786 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
8787 reloc for a cons. We could use the definition there, except that
8788 we want to handle 64 bit relocs specially. */
8791 cons_fix_new_mips (frag, where, nbytes, exp)
8794 unsigned int nbytes;
8798 /* If we are assembling in 32 bit mode, turn an 8 byte reloc into a
8800 if (nbytes == 8 && ! mips_64)
8802 if (target_big_endian)
8808 if (nbytes != 2 && nbytes != 4 && nbytes != 8)
8809 as_bad ("Unsupported reloc size %d", nbytes);
8811 fix_new_exp (frag_now, where, (int) nbytes, exp, 0,
8814 : (nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64)));
8817 /* This is called before the symbol table is processed. In order to
8818 work with gcc when using mips-tfile, we must keep all local labels.
8819 However, in other cases, we want to discard them. If we were
8820 called with -g, but we didn't see any debugging information, it may
8821 mean that gcc is smuggling debugging information through to
8822 mips-tfile, in which case we must generate all local labels. */
8825 mips_frob_file_before_adjust ()
8827 #ifndef NO_ECOFF_DEBUGGING
8830 && ! ecoff_debugging_seen)
8831 flag_keep_locals = 1;
8835 /* Sort any unmatched HI16_S relocs so that they immediately precede
8836 the corresponding LO reloc. This is called before md_apply_fix and
8837 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
8838 explicit use of the %hi modifier. */
8843 struct mips_hi_fixup *l;
8845 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
8847 segment_info_type *seginfo;
8850 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
8852 /* Check quickly whether the next fixup happens to be a matching
8854 if (l->fixp->fx_next != NULL
8855 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
8856 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
8857 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
8860 /* Look through the fixups for this segment for a matching %lo.
8861 When we find one, move the %hi just in front of it. We do
8862 this in two passes. In the first pass, we try to find a
8863 unique %lo. In the second pass, we permit multiple %hi
8864 relocs for a single %lo (this is a GNU extension). */
8865 seginfo = seg_info (l->seg);
8866 for (pass = 0; pass < 2; pass++)
8871 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
8873 /* Check whether this is a %lo fixup which matches l->fixp. */
8874 if (f->fx_r_type == BFD_RELOC_LO16
8875 && f->fx_addsy == l->fixp->fx_addsy
8876 && f->fx_offset == l->fixp->fx_offset
8879 || prev->fx_r_type != BFD_RELOC_HI16_S
8880 || prev->fx_addsy != f->fx_addsy
8881 || prev->fx_offset != f->fx_offset))
8885 /* Move l->fixp before f. */
8886 for (pf = &seginfo->fix_root;
8888 pf = &(*pf)->fx_next)
8889 assert (*pf != NULL);
8891 *pf = l->fixp->fx_next;
8893 l->fixp->fx_next = f;
8895 seginfo->fix_root = l->fixp;
8897 prev->fx_next = l->fixp;
8909 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
8910 "Unmatched %%hi reloc");
8915 /* When generating embedded PIC code we need to use a special
8916 relocation to represent the difference of two symbols in the .text
8917 section (switch tables use a difference of this sort). See
8918 include/coff/mips.h for details. This macro checks whether this
8919 fixup requires the special reloc. */
8920 #define SWITCH_TABLE(fixp) \
8921 ((fixp)->fx_r_type == BFD_RELOC_32 \
8922 && (fixp)->fx_addsy != NULL \
8923 && (fixp)->fx_subsy != NULL \
8924 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
8925 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
8927 /* When generating embedded PIC code we must keep all PC relative
8928 relocations, in case the linker has to relax a call. We also need
8929 to keep relocations for switch table entries. */
8933 mips_force_relocation (fixp)
8936 return (mips_pic == EMBEDDED_PIC
8938 || SWITCH_TABLE (fixp)
8939 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
8940 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
8943 /* Apply a fixup to the object file. */
8946 md_apply_fix (fixP, valueP)
8953 assert (fixP->fx_size == 4
8954 || fixP->fx_r_type == BFD_RELOC_16
8955 || fixP->fx_r_type == BFD_RELOC_64);
8959 /* If we aren't adjusting this fixup to be against the section
8960 symbol, we need to adjust the value. */
8962 if (fixP->fx_addsy != NULL
8963 && OUTPUT_FLAVOR == bfd_target_elf_flavour
8964 && S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
8966 value -= S_GET_VALUE (fixP->fx_addsy);
8967 if (value != 0 && ! fixP->fx_pcrel)
8969 /* In this case, the bfd_install_relocation routine will
8970 incorrectly add the symbol value back in. We just want
8971 the addend to appear in the object file. */
8972 value -= S_GET_VALUE (fixP->fx_addsy);
8977 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */
8979 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
8982 switch (fixP->fx_r_type)
8984 case BFD_RELOC_MIPS_JMP:
8985 case BFD_RELOC_HI16:
8986 case BFD_RELOC_HI16_S:
8987 case BFD_RELOC_MIPS_GPREL:
8988 case BFD_RELOC_MIPS_LITERAL:
8989 case BFD_RELOC_MIPS_CALL16:
8990 case BFD_RELOC_MIPS_GOT16:
8991 case BFD_RELOC_MIPS_GPREL32:
8992 case BFD_RELOC_MIPS_GOT_HI16:
8993 case BFD_RELOC_MIPS_GOT_LO16:
8994 case BFD_RELOC_MIPS_CALL_HI16:
8995 case BFD_RELOC_MIPS_CALL_LO16:
8996 case BFD_RELOC_MIPS16_GPREL:
8998 as_bad_where (fixP->fx_file, fixP->fx_line,
8999 "Invalid PC relative reloc");
9000 /* Nothing needed to do. The value comes from the reloc entry */
9003 case BFD_RELOC_MIPS16_JMP:
9004 /* We currently always generate a reloc against a symbol, which
9005 means that we don't want an addend even if the symbol is
9007 fixP->fx_addnumber = 0;
9010 case BFD_RELOC_PCREL_HI16_S:
9011 /* The addend for this is tricky if it is internal, so we just
9012 do everything here rather than in bfd_install_relocation. */
9013 if ((fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) == 0)
9015 /* For an external symbol adjust by the address to make it
9016 pcrel_offset. We use the address of the RELLO reloc
9017 which follows this one. */
9018 value += (fixP->fx_next->fx_frag->fr_address
9019 + fixP->fx_next->fx_where);
9024 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9025 if (target_big_endian)
9027 md_number_to_chars (buf, value, 2);
9030 case BFD_RELOC_PCREL_LO16:
9031 /* The addend for this is tricky if it is internal, so we just
9032 do everything here rather than in bfd_install_relocation. */
9033 if ((fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) == 0)
9034 value += fixP->fx_frag->fr_address + fixP->fx_where;
9035 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9036 if (target_big_endian)
9038 md_number_to_chars (buf, value, 2);
9042 /* This is handled like BFD_RELOC_32, but we output a sign
9043 extended value if we are only 32 bits. */
9045 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
9047 if (8 <= sizeof (valueT))
9048 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9055 w1 = w2 = fixP->fx_where;
9056 if (target_big_endian)
9060 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
9061 if ((value & 0x80000000) != 0)
9065 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
9071 /* If we are deleting this reloc entry, we must fill in the
9072 value now. This can happen if we have a .word which is not
9073 resolved when it appears but is later defined. We also need
9074 to fill in the value if this is an embedded PIC switch table
9077 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
9078 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9083 /* If we are deleting this reloc entry, we must fill in the
9085 assert (fixP->fx_size == 2);
9087 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9091 case BFD_RELOC_LO16:
9092 /* When handling an embedded PIC switch statement, we can wind
9093 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
9096 if (value < -0x8000 || value > 0x7fff)
9097 as_bad_where (fixP->fx_file, fixP->fx_line,
9098 "relocation overflow");
9099 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9100 if (target_big_endian)
9102 md_number_to_chars (buf, value, 2);
9106 case BFD_RELOC_16_PCREL_S2:
9108 * We need to save the bits in the instruction since fixup_segment()
9109 * might be deleting the relocation entry (i.e., a branch within
9110 * the current segment).
9112 if ((value & 0x3) != 0)
9113 as_bad_where (fixP->fx_file, fixP->fx_line,
9114 "Branch to odd address (%lx)", value);
9117 /* update old instruction data */
9118 buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal);
9119 if (target_big_endian)
9120 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
9122 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
9124 if (value >= -0x8000 && value < 0x8000)
9125 insn |= value & 0xffff;
9128 /* The branch offset is too large. If this is an
9129 unconditional branch, and we are not generating PIC code,
9130 we can convert it to an absolute jump instruction. */
9131 if (mips_pic == NO_PIC
9133 && fixP->fx_frag->fr_address >= text_section->vma
9134 && (fixP->fx_frag->fr_address
9135 < text_section->vma + text_section->_raw_size)
9136 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
9137 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
9138 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
9140 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
9141 insn = 0x0c000000; /* jal */
9143 insn = 0x08000000; /* j */
9144 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
9146 fixP->fx_addsy = section_symbol (text_section);
9147 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
9151 /* FIXME. It would be possible in principle to handle
9152 conditional branches which overflow. They could be
9153 transformed into a branch around a jump. This would
9154 require setting up variant frags for each different
9155 branch type. The native MIPS assembler attempts to
9156 handle these cases, but it appears to do it
9158 as_bad_where (fixP->fx_file, fixP->fx_line,
9159 "Branch out of range");
9163 md_number_to_chars ((char *) buf, (valueT) insn, 4);
9178 const struct mips_opcode *p;
9179 int treg, sreg, dreg, shamt;
9184 for (i = 0; i < NUMOPCODES; ++i)
9186 p = &mips_opcodes[i];
9187 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
9189 printf ("%08lx %s\t", oc, p->name);
9190 treg = (oc >> 16) & 0x1f;
9191 sreg = (oc >> 21) & 0x1f;
9192 dreg = (oc >> 11) & 0x1f;
9193 shamt = (oc >> 6) & 0x1f;
9195 for (args = p->args;; ++args)
9206 printf ("%c", *args);
9210 assert (treg == sreg);
9211 printf ("$%d,$%d", treg, sreg);
9216 printf ("$%d", dreg);
9221 printf ("$%d", treg);
9225 printf ("0x%x", treg);
9230 printf ("$%d", sreg);
9234 printf ("0x%08lx", oc & 0x1ffffff);
9246 printf ("$%d", shamt);
9257 printf ("%08lx UNDEFINED\n", oc);
9268 name = input_line_pointer;
9269 c = get_symbol_end ();
9270 p = (symbolS *) symbol_find_or_make (name);
9271 *input_line_pointer = c;
9275 /* Align the current frag to a given power of two. The MIPS assembler
9276 also automatically adjusts any preceding label. */
9279 mips_align (to, fill, label)
9284 mips_emit_delays (false);
9285 frag_align (to, fill, 0);
9286 record_alignment (now_seg, to);
9289 assert (S_GET_SEGMENT (label) == now_seg);
9290 label->sy_frag = frag_now;
9291 S_SET_VALUE (label, (valueT) frag_now_fix ());
9295 /* Align to a given power of two. .align 0 turns off the automatic
9296 alignment used by the data creating pseudo-ops. */
9303 register long temp_fill;
9304 long max_alignment = 15;
9308 o Note that the assembler pulls down any immediately preceeding label
9309 to the aligned address.
9310 o It's not documented but auto alignment is reinstated by
9311 a .align pseudo instruction.
9312 o Note also that after auto alignment is turned off the mips assembler
9313 issues an error on attempt to assemble an improperly aligned data item.
9318 temp = get_absolute_expression ();
9319 if (temp > max_alignment)
9320 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
9323 as_warn ("Alignment negative: 0 assumed.");
9326 if (*input_line_pointer == ',')
9328 input_line_pointer++;
9329 temp_fill = get_absolute_expression ();
9336 mips_align (temp, (int) temp_fill,
9337 insn_labels != NULL ? insn_labels->label : NULL);
9344 demand_empty_rest_of_line ();
9348 mips_flush_pending_output ()
9350 mips_emit_delays (false);
9351 mips_clear_insn_labels ();
9360 /* When generating embedded PIC code, we only use the .text, .lit8,
9361 .sdata and .sbss sections. We change the .data and .rdata
9362 pseudo-ops to use .sdata. */
9363 if (mips_pic == EMBEDDED_PIC
9364 && (sec == 'd' || sec == 'r'))
9368 /* The ELF backend needs to know that we are changing sections, so
9369 that .previous works correctly. We could do something like check
9370 for a obj_section_change_hook macro, but that might be confusing
9371 as it would not be appropriate to use it in the section changing
9372 functions in read.c, since obj-elf.c intercepts those. FIXME:
9373 This should be cleaner, somehow. */
9374 obj_elf_section_change_hook ();
9377 mips_emit_delays (false);
9387 subseg_set (bss_section, (subsegT) get_absolute_expression ());
9388 demand_empty_rest_of_line ();
9392 if (USE_GLOBAL_POINTER_OPT)
9394 seg = subseg_new (RDATA_SECTION_NAME,
9395 (subsegT) get_absolute_expression ());
9396 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
9398 bfd_set_section_flags (stdoutput, seg,
9404 if (strcmp (TARGET_OS, "elf") != 0)
9405 bfd_set_section_alignment (stdoutput, seg, 4);
9407 demand_empty_rest_of_line ();
9411 as_bad ("No read only data section in this object file format");
9412 demand_empty_rest_of_line ();
9418 if (USE_GLOBAL_POINTER_OPT)
9420 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
9421 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
9423 bfd_set_section_flags (stdoutput, seg,
9424 SEC_ALLOC | SEC_LOAD | SEC_RELOC
9426 if (strcmp (TARGET_OS, "elf") != 0)
9427 bfd_set_section_alignment (stdoutput, seg, 4);
9429 demand_empty_rest_of_line ();
9434 as_bad ("Global pointers not supported; recompile -G 0");
9435 demand_empty_rest_of_line ();
9444 mips_enable_auto_align ()
9455 label = insn_labels != NULL ? insn_labels->label : NULL;
9456 mips_emit_delays (false);
9457 if (log_size > 0 && auto_align)
9458 mips_align (log_size, 0, label);
9459 mips_clear_insn_labels ();
9460 cons (1 << log_size);
9469 label = insn_labels != NULL ? insn_labels->label : NULL;
9471 mips_emit_delays (false);
9475 mips_align (3, 0, label);
9477 mips_align (2, 0, label);
9479 mips_clear_insn_labels ();
9484 /* Handle .globl. We need to override it because on Irix 5 you are
9487 where foo is an undefined symbol, to mean that foo should be
9488 considered to be the address of a function. */
9499 name = input_line_pointer;
9500 c = get_symbol_end ();
9501 symbolP = symbol_find_or_make (name);
9502 *input_line_pointer = c;
9505 /* On Irix 5, every global symbol that is not explicitly labelled as
9506 being a function is apparently labelled as being an object. */
9509 if (! is_end_of_line[(unsigned char) *input_line_pointer])
9514 secname = input_line_pointer;
9515 c = get_symbol_end ();
9516 sec = bfd_get_section_by_name (stdoutput, secname);
9518 as_bad ("%s: no such section", secname);
9519 *input_line_pointer = c;
9521 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
9522 flag = BSF_FUNCTION;
9525 symbolP->bsym->flags |= flag;
9527 S_SET_EXTERNAL (symbolP);
9528 demand_empty_rest_of_line ();
9538 opt = input_line_pointer;
9539 c = get_symbol_end ();
9543 /* FIXME: What does this mean? */
9545 else if (strncmp (opt, "pic", 3) == 0)
9553 mips_pic = SVR4_PIC;
9555 as_bad (".option pic%d not supported", i);
9557 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
9559 if (g_switch_seen && g_switch_value != 0)
9560 as_warn ("-G may not be used with SVR4 PIC code");
9562 bfd_set_gp_size (stdoutput, 0);
9566 as_warn ("Unrecognized option \"%s\"", opt);
9568 *input_line_pointer = c;
9569 demand_empty_rest_of_line ();
9572 /* This structure is used to hold a stack of .set values. */
9574 struct mips_option_stack
9576 struct mips_option_stack *next;
9577 struct mips_set_options options;
9580 static struct mips_option_stack *mips_opts_stack;
9582 /* Handle the .set pseudo-op. */
9588 char *name = input_line_pointer, ch;
9590 while (!is_end_of_line[(unsigned char) *input_line_pointer])
9591 input_line_pointer++;
9592 ch = *input_line_pointer;
9593 *input_line_pointer = '\0';
9595 if (strcmp (name, "reorder") == 0)
9597 if (mips_opts.noreorder && prev_nop_frag != NULL)
9599 /* If we still have pending nops, we can discard them. The
9600 usual nop handling will insert any that are still
9602 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
9603 * (mips_opts.mips16 ? 2 : 4));
9604 prev_nop_frag = NULL;
9606 mips_opts.noreorder = 0;
9608 else if (strcmp (name, "noreorder") == 0)
9610 mips_emit_delays (true);
9611 mips_opts.noreorder = 1;
9612 mips_any_noreorder = 1;
9614 else if (strcmp (name, "at") == 0)
9618 else if (strcmp (name, "noat") == 0)
9622 else if (strcmp (name, "macro") == 0)
9624 mips_opts.warn_about_macros = 0;
9626 else if (strcmp (name, "nomacro") == 0)
9628 if (mips_opts.noreorder == 0)
9629 as_bad ("`noreorder' must be set before `nomacro'");
9630 mips_opts.warn_about_macros = 1;
9632 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
9634 mips_opts.nomove = 0;
9636 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
9638 mips_opts.nomove = 1;
9640 else if (strcmp (name, "bopt") == 0)
9642 mips_opts.nobopt = 0;
9644 else if (strcmp (name, "nobopt") == 0)
9646 mips_opts.nobopt = 1;
9648 else if (strcmp (name, "mips16") == 0
9649 || strcmp (name, "MIPS-16") == 0)
9650 mips_opts.mips16 = 1;
9651 else if (strcmp (name, "nomips16") == 0
9652 || strcmp (name, "noMIPS-16") == 0)
9653 mips_opts.mips16 = 0;
9654 else if (strncmp (name, "mips", 4) == 0)
9658 /* Permit the user to change the ISA on the fly. Needless to
9659 say, misuse can cause serious problems. */
9660 isa = atoi (name + 4);
9662 mips_opts.isa = file_mips_isa;
9663 else if (isa < 1 || isa > 4)
9664 as_bad ("unknown ISA level");
9666 mips_opts.isa = isa;
9668 else if (strcmp (name, "autoextend") == 0)
9669 mips_opts.noautoextend = 0;
9670 else if (strcmp (name, "noautoextend") == 0)
9671 mips_opts.noautoextend = 1;
9672 else if (strcmp (name, "push") == 0)
9674 struct mips_option_stack *s;
9676 s = (struct mips_option_stack *) xmalloc (sizeof *s);
9677 s->next = mips_opts_stack;
9678 s->options = mips_opts;
9679 mips_opts_stack = s;
9681 else if (strcmp (name, "pop") == 0)
9683 struct mips_option_stack *s;
9685 s = mips_opts_stack;
9687 as_bad (".set pop with no .set push");
9690 /* If we're changing the reorder mode we need to handle
9691 delay slots correctly. */
9692 if (s->options.noreorder && ! mips_opts.noreorder)
9693 mips_emit_delays (true);
9694 else if (! s->options.noreorder && mips_opts.noreorder)
9696 if (prev_nop_frag != NULL)
9698 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
9699 * (mips_opts.mips16 ? 2 : 4));
9700 prev_nop_frag = NULL;
9704 mips_opts = s->options;
9705 mips_opts_stack = s->next;
9711 as_warn ("Tried to set unrecognized symbol: %s\n", name);
9713 *input_line_pointer = ch;
9714 demand_empty_rest_of_line ();
9717 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
9718 .option pic2. It means to generate SVR4 PIC calls. */
9724 mips_pic = SVR4_PIC;
9725 if (USE_GLOBAL_POINTER_OPT)
9727 if (g_switch_seen && g_switch_value != 0)
9728 as_warn ("-G may not be used with SVR4 PIC code");
9731 bfd_set_gp_size (stdoutput, 0);
9732 demand_empty_rest_of_line ();
9735 /* Handle the .cpload pseudo-op. This is used when generating SVR4
9736 PIC code. It sets the $gp register for the function based on the
9737 function address, which is in the register named in the argument.
9738 This uses a relocation against _gp_disp, which is handled specially
9739 by the linker. The result is:
9740 lui $gp,%hi(_gp_disp)
9741 addiu $gp,$gp,%lo(_gp_disp)
9742 addu $gp,$gp,.cpload argument
9743 The .cpload argument is normally $25 == $t9. */
9752 /* If we are not generating SVR4 PIC code, .cpload is ignored. */
9753 if (mips_pic != SVR4_PIC)
9759 /* .cpload should be a in .set noreorder section. */
9760 if (mips_opts.noreorder == 0)
9761 as_warn (".cpload not in noreorder section");
9764 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
9765 ex.X_op_symbol = NULL;
9766 ex.X_add_number = 0;
9768 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
9769 ex.X_add_symbol->bsym->flags |= BSF_OBJECT;
9771 macro_build_lui ((char *) NULL, &icnt, &ex, GP);
9772 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP,
9773 (int) BFD_RELOC_LO16);
9775 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
9776 GP, GP, tc_get_register (0));
9778 demand_empty_rest_of_line ();
9781 /* Handle the .cprestore pseudo-op. This stores $gp into a given
9782 offset from $sp. The offset is remembered, and after making a PIC
9783 call $gp is restored from that location. */
9786 s_cprestore (ignore)
9792 /* If we are not generating SVR4 PIC code, .cprestore is ignored. */
9793 if (mips_pic != SVR4_PIC)
9799 mips_cprestore_offset = get_absolute_expression ();
9801 ex.X_op = O_constant;
9802 ex.X_add_symbol = NULL;
9803 ex.X_op_symbol = NULL;
9804 ex.X_add_number = mips_cprestore_offset;
9806 macro_build ((char *) NULL, &icnt, &ex,
9807 mips_opts.isa < 3 ? "sw" : "sd",
9808 "t,o(b)", GP, (int) BFD_RELOC_LO16, SP);
9810 demand_empty_rest_of_line ();
9813 /* Handle the .gpword pseudo-op. This is used when generating PIC
9814 code. It generates a 32 bit GP relative reloc. */
9824 /* When not generating PIC code, this is treated as .word. */
9825 if (mips_pic != SVR4_PIC)
9831 label = insn_labels != NULL ? insn_labels->label : NULL;
9832 mips_emit_delays (true);
9834 mips_align (2, 0, label);
9835 mips_clear_insn_labels ();
9839 if (ex.X_op != O_symbol || ex.X_add_number != 0)
9841 as_bad ("Unsupported use of .gpword");
9842 ignore_rest_of_line ();
9846 md_number_to_chars (p, (valueT) 0, 4);
9847 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0,
9848 BFD_RELOC_MIPS_GPREL32);
9850 demand_empty_rest_of_line ();
9853 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
9854 tables in SVR4 PIC code. */
9863 /* This is ignored when not generating SVR4 PIC code. */
9864 if (mips_pic != SVR4_PIC)
9870 /* Add $gp to the register named as an argument. */
9871 reg = tc_get_register (0);
9872 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
9873 mips_opts.isa < 3 ? "addu" : "daddu",
9874 "d,v,t", reg, reg, GP);
9876 demand_empty_rest_of_line ();
9879 /* Handle the .insn pseudo-op. This marks instruction labels in
9880 mips16 mode. This permits the linker to handle them specially,
9881 such as generating jalx instructions when needed. We also make
9882 them odd for the duration of the assembly, in order to generate the
9883 right sort of code. We will make them even in the adjust_symtab
9884 routine, while leaving them marked. This is convenient for the
9885 debugger and the disassembler. The linker knows to make them odd
9892 if (mips_opts.mips16)
9893 mips16_mark_labels ();
9895 demand_empty_rest_of_line ();
9898 /* Handle a .stabn directive. We need these in order to mark a label
9899 as being a mips16 text label correctly. Sometimes the compiler
9900 will emit a label, followed by a .stabn, and then switch sections.
9901 If the label and .stabn are in mips16 mode, then the label is
9902 really a mips16 text label. */
9908 if (type == 'n' && mips_opts.mips16)
9909 mips16_mark_labels ();
9914 /* Parse a register string into a number. Called from the ECOFF code
9915 to parse .frame. The argument is non-zero if this is the frame
9916 register, so that we can record it in mips_frame_reg. */
9919 tc_get_register (frame)
9925 if (*input_line_pointer++ != '$')
9927 as_warn ("expected `$'");
9930 else if (isdigit ((unsigned char) *input_line_pointer))
9932 reg = get_absolute_expression ();
9933 if (reg < 0 || reg >= 32)
9935 as_warn ("Bad register number");
9941 if (strncmp (input_line_pointer, "fp", 2) == 0)
9943 else if (strncmp (input_line_pointer, "sp", 2) == 0)
9945 else if (strncmp (input_line_pointer, "gp", 2) == 0)
9947 else if (strncmp (input_line_pointer, "at", 2) == 0)
9951 as_warn ("Unrecognized register name");
9954 input_line_pointer += 2;
9957 mips_frame_reg = reg != 0 ? reg : SP;
9962 md_section_align (seg, addr)
9966 int align = bfd_get_section_alignment (stdoutput, seg);
9969 /* We don't need to align ELF sections to the full alignment.
9970 However, Irix 5 may prefer that we align them at least to a 16
9971 byte boundary. We don't bother to align the sections if we are
9972 targeted for an embedded system. */
9973 if (strcmp (TARGET_OS, "elf") == 0)
9979 return ((addr + (1 << align) - 1) & (-1 << align));
9982 /* Utility routine, called from above as well. If called while the
9983 input file is still being read, it's only an approximation. (For
9984 example, a symbol may later become defined which appeared to be
9985 undefined earlier.) */
9988 nopic_need_relax (sym, before_relaxing)
9990 int before_relaxing;
9995 if (USE_GLOBAL_POINTER_OPT)
9997 const char *symname;
10000 /* Find out whether this symbol can be referenced off the GP
10001 register. It can be if it is smaller than the -G size or if
10002 it is in the .sdata or .sbss section. Certain symbols can
10003 not be referenced off the GP, although it appears as though
10005 symname = S_GET_NAME (sym);
10006 if (symname != (const char *) NULL
10007 && (strcmp (symname, "eprol") == 0
10008 || strcmp (symname, "etext") == 0
10009 || strcmp (symname, "_gp") == 0
10010 || strcmp (symname, "edata") == 0
10011 || strcmp (symname, "_fbss") == 0
10012 || strcmp (symname, "_fdata") == 0
10013 || strcmp (symname, "_ftext") == 0
10014 || strcmp (symname, "end") == 0
10015 || strcmp (symname, "_gp_disp") == 0))
10017 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
10019 #ifndef NO_ECOFF_DEBUGGING
10020 || (sym->ecoff_extern_size != 0
10021 && sym->ecoff_extern_size <= g_switch_value)
10023 /* We must defer this decision until after the whole
10024 file has been read, since there might be a .extern
10025 after the first use of this symbol. */
10026 || (before_relaxing
10027 #ifndef NO_ECOFF_DEBUGGING
10028 && sym->ecoff_extern_size == 0
10030 && S_GET_VALUE (sym) == 0)
10031 || (S_GET_VALUE (sym) != 0
10032 && S_GET_VALUE (sym) <= g_switch_value)))
10036 const char *segname;
10038 segname = segment_name (S_GET_SEGMENT (sym));
10039 assert (strcmp (segname, ".lit8") != 0
10040 && strcmp (segname, ".lit4") != 0);
10041 change = (strcmp (segname, ".sdata") != 0
10042 && strcmp (segname, ".sbss") != 0);
10047 /* We are not optimizing for the GP register. */
10051 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
10052 extended opcode. SEC is the section the frag is in. */
10055 mips16_extended_frag (fragp, sec, stretch)
10061 register const struct mips16_immed_operand *op;
10063 int mintiny, maxtiny;
10066 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
10068 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
10071 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
10072 op = mips16_immed_operands;
10073 while (op->type != type)
10076 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
10081 if (type == '<' || type == '>' || type == '[' || type == ']')
10084 maxtiny = 1 << op->nbits;
10089 maxtiny = (1 << op->nbits) - 1;
10094 mintiny = - (1 << (op->nbits - 1));
10095 maxtiny = (1 << (op->nbits - 1)) - 1;
10098 /* We can't call S_GET_VALUE here, because we don't want to lock in
10099 a particular frag address. */
10100 if (fragp->fr_symbol->sy_value.X_op == O_constant)
10102 val = (fragp->fr_symbol->sy_value.X_add_number
10103 + fragp->fr_symbol->sy_frag->fr_address);
10104 symsec = S_GET_SEGMENT (fragp->fr_symbol);
10106 else if (fragp->fr_symbol->sy_value.X_op == O_symbol
10107 && (fragp->fr_symbol->sy_value.X_add_symbol->sy_value.X_op
10110 val = (fragp->fr_symbol->sy_value.X_add_symbol->sy_value.X_add_number
10111 + fragp->fr_symbol->sy_value.X_add_symbol->sy_frag->fr_address
10112 + fragp->fr_symbol->sy_value.X_add_number
10113 + fragp->fr_symbol->sy_frag->fr_address);
10114 symsec = S_GET_SEGMENT (fragp->fr_symbol->sy_value.X_add_symbol);
10123 /* We won't have the section when we are called from
10124 mips_relax_frag. However, we will always have been called
10125 from md_estimate_size_before_relax first. If this is a
10126 branch to a different section, we mark it as such. If SEC is
10127 NULL, and the frag is not marked, then it must be a branch to
10128 the same section. */
10131 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
10138 fragp->fr_subtype =
10139 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
10141 /* FIXME: We should support this, and let the linker
10142 catch branches and loads that are out of range. */
10143 as_bad_where (fragp->fr_file, fragp->fr_line,
10144 "unsupported PC relative reference to different section");
10150 /* In this case, we know for sure that the symbol fragment is in
10151 the same section. If the fr_address of the symbol fragment
10152 is greater then the address of this fragment we want to add
10153 in STRETCH in order to get a better estimate of the address.
10154 This particularly matters because of the shift bits. */
10156 && fragp->fr_symbol->sy_frag->fr_address >= fragp->fr_address)
10160 /* Adjust stretch for any alignment frag. Note that if have
10161 been expanding the earlier code, the symbol may be
10162 defined in what appears to be an earlier frag. FIXME:
10163 This doesn't handle the fr_subtype field, which specifies
10164 a maximum number of bytes to skip when doing an
10167 f != NULL && f != fragp->fr_symbol->sy_frag;
10170 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
10173 stretch = - ((- stretch)
10174 & ~ ((1 << (int) f->fr_offset) - 1));
10176 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
10185 addr = fragp->fr_address + fragp->fr_fix;
10187 /* The base address rules are complicated. The base address of
10188 a branch is the following instruction. The base address of a
10189 PC relative load or add is the instruction itself, but if it
10190 is in a delay slot (in which case it can not be extended) use
10191 the address of the instruction whose delay slot it is in. */
10192 if (type == 'p' || type == 'q')
10196 /* If we are currently assuming that this frag should be
10197 extended, then, the current address is two bytes
10199 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
10202 /* Ignore the low bit in the target, since it will be set
10203 for a text label. */
10204 if ((val & 1) != 0)
10207 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
10209 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
10212 val -= addr & ~ ((1 << op->shift) - 1);
10214 /* Branch offsets have an implicit 0 in the lowest bit. */
10215 if (type == 'p' || type == 'q')
10218 /* If any of the shifted bits are set, we must use an extended
10219 opcode. If the address depends on the size of this
10220 instruction, this can lead to a loop, so we arrange to always
10221 use an extended opcode. We only check this when we are in
10222 the main relaxation loop, when SEC is NULL. */
10223 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
10225 fragp->fr_subtype =
10226 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
10230 /* If we are about to mark a frag as extended because the value
10231 is precisely maxtiny + 1, then there is a chance of an
10232 infinite loop as in the following code:
10237 In this case when the la is extended, foo is 0x3fc bytes
10238 away, so the la can be shrunk, but then foo is 0x400 away, so
10239 the la must be extended. To avoid this loop, we mark the
10240 frag as extended if it was small, and is about to become
10241 extended with a value of maxtiny + 1. */
10242 if (val == ((maxtiny + 1) << op->shift)
10243 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
10246 fragp->fr_subtype =
10247 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
10251 else if (symsec != absolute_section && sec != NULL)
10252 as_bad_where (fragp->fr_file, fragp->fr_line, "unsupported relocation");
10254 if ((val & ((1 << op->shift) - 1)) != 0
10255 || val < (mintiny << op->shift)
10256 || val > (maxtiny << op->shift))
10262 /* Estimate the size of a frag before relaxing. Unless this is the
10263 mips16, we are not really relaxing here, and the final size is
10264 encoded in the subtype information. For the mips16, we have to
10265 decide whether we are using an extended opcode or not. */
10269 md_estimate_size_before_relax (fragp, segtype)
10275 if (RELAX_MIPS16_P (fragp->fr_subtype))
10277 if (mips16_extended_frag (fragp, segtype, 0))
10279 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
10284 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
10289 if (mips_pic == NO_PIC)
10291 change = nopic_need_relax (fragp->fr_symbol, 0);
10293 else if (mips_pic == SVR4_PIC)
10298 sym = fragp->fr_symbol;
10300 /* Handle the case of a symbol equated to another symbol. */
10301 while (sym->sy_value.X_op == O_symbol
10302 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
10306 /* It's possible to get a loop here in a badly written
10308 n = sym->sy_value.X_add_symbol;
10314 symsec = S_GET_SEGMENT (sym);
10316 /* This must duplicate the test in adjust_reloc_syms. */
10317 change = (symsec != &bfd_und_section
10318 && symsec != &bfd_abs_section
10319 && ! bfd_is_com_section (symsec));
10326 /* Record the offset to the first reloc in the fr_opcode field.
10327 This lets md_convert_frag and tc_gen_reloc know that the code
10328 must be expanded. */
10329 fragp->fr_opcode = (fragp->fr_literal
10331 - RELAX_OLD (fragp->fr_subtype)
10332 + RELAX_RELOC1 (fragp->fr_subtype));
10333 /* FIXME: This really needs as_warn_where. */
10334 if (RELAX_WARN (fragp->fr_subtype))
10335 as_warn ("AT used after \".set noat\" or macro used after \".set nomacro\"");
10341 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
10344 /* This is called to see whether a reloc against a defined symbol
10345 should be converted into a reloc against a section. Don't adjust
10346 MIPS16 jump relocations, so we don't have to worry about the format
10347 of the offset in the .o file. Don't adjust relocations against
10348 mips16 symbols, so that the linker can find them if it needs to set
10352 mips_fix_adjustable (fixp)
10355 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
10357 if (fixp->fx_addsy == NULL)
10360 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10361 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
10362 && fixp->fx_subsy == NULL)
10368 /* Translate internal representation of relocation info to BFD target
10372 tc_gen_reloc (section, fixp)
10376 static arelent *retval[4];
10378 bfd_reloc_code_real_type code;
10380 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
10383 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
10384 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10386 if (mips_pic == EMBEDDED_PIC
10387 && SWITCH_TABLE (fixp))
10389 /* For a switch table entry we use a special reloc. The addend
10390 is actually the difference between the reloc address and the
10392 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
10393 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
10394 as_fatal ("Double check fx_r_type in tc-mips.c:tc_gen_reloc");
10395 fixp->fx_r_type = BFD_RELOC_GPREL32;
10397 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
10399 /* We use a special addend for an internal RELLO reloc. */
10400 if (fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM)
10401 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
10403 reloc->addend = fixp->fx_addnumber + reloc->address;
10405 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
10407 assert (fixp->fx_next != NULL
10408 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
10409 /* We use a special addend for an internal RELHI reloc. The
10410 reloc is relative to the RELLO; adjust the addend
10412 if (fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM)
10413 reloc->addend = (fixp->fx_next->fx_frag->fr_address
10414 + fixp->fx_next->fx_where
10415 - S_GET_VALUE (fixp->fx_subsy));
10417 reloc->addend = (fixp->fx_addnumber
10418 + fixp->fx_next->fx_frag->fr_address
10419 + fixp->fx_next->fx_where);
10421 else if (fixp->fx_pcrel == 0)
10422 reloc->addend = fixp->fx_addnumber;
10425 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
10426 /* A gruesome hack which is a result of the gruesome gas reloc
10428 reloc->addend = reloc->address;
10430 reloc->addend = -reloc->address;
10433 /* If this is a variant frag, we may need to adjust the existing
10434 reloc and generate a new one. */
10435 if (fixp->fx_frag->fr_opcode != NULL
10436 && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
10437 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
10438 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
10439 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
10440 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
10441 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
10442 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16))
10446 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
10448 /* If this is not the last reloc in this frag, then we have two
10449 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
10450 CALL_HI16/CALL_LO16, both of which are being replaced. Let
10451 the second one handle all of them. */
10452 if (fixp->fx_next != NULL
10453 && fixp->fx_frag == fixp->fx_next->fx_frag)
10455 assert ((fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
10456 && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL)
10457 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
10458 && (fixp->fx_next->fx_r_type
10459 == BFD_RELOC_MIPS_GOT_LO16))
10460 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
10461 && (fixp->fx_next->fx_r_type
10462 == BFD_RELOC_MIPS_CALL_LO16)));
10467 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
10468 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10469 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
10471 reloc2->sym_ptr_ptr = &fixp->fx_addsy->bsym;
10472 reloc2->address = (reloc->address
10473 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
10474 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
10475 reloc2->addend = fixp->fx_addnumber;
10476 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
10477 assert (reloc2->howto != NULL);
10479 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
10483 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
10486 reloc3->address += 4;
10489 if (mips_pic == NO_PIC)
10491 assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL);
10492 fixp->fx_r_type = BFD_RELOC_HI16_S;
10494 else if (mips_pic == SVR4_PIC)
10496 switch (fixp->fx_r_type)
10500 case BFD_RELOC_MIPS_GOT16:
10502 case BFD_RELOC_MIPS_CALL16:
10503 case BFD_RELOC_MIPS_GOT_LO16:
10504 case BFD_RELOC_MIPS_CALL_LO16:
10505 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
10513 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
10514 fixup_segment converted a non-PC relative reloc into a PC
10515 relative reloc. In such a case, we need to convert the reloc
10517 code = fixp->fx_r_type;
10518 if (fixp->fx_pcrel)
10523 code = BFD_RELOC_8_PCREL;
10526 code = BFD_RELOC_16_PCREL;
10529 code = BFD_RELOC_32_PCREL;
10532 code = BFD_RELOC_64_PCREL;
10534 case BFD_RELOC_8_PCREL:
10535 case BFD_RELOC_16_PCREL:
10536 case BFD_RELOC_32_PCREL:
10537 case BFD_RELOC_64_PCREL:
10538 case BFD_RELOC_16_PCREL_S2:
10539 case BFD_RELOC_PCREL_HI16_S:
10540 case BFD_RELOC_PCREL_LO16:
10543 as_bad_where (fixp->fx_file, fixp->fx_line,
10544 "Cannot make %s relocation PC relative",
10545 bfd_get_reloc_code_name (code));
10549 /* To support a PC relative reloc when generating embedded PIC code
10550 for ECOFF, we use a Cygnus extension. We check for that here to
10551 make sure that we don't let such a reloc escape normally. */
10552 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
10553 && code == BFD_RELOC_16_PCREL_S2
10554 && mips_pic != EMBEDDED_PIC)
10555 reloc->howto = NULL;
10557 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
10559 if (reloc->howto == NULL)
10561 as_bad_where (fixp->fx_file, fixp->fx_line,
10562 "Can not represent %s relocation in this object file format",
10563 bfd_get_reloc_code_name (code));
10570 /* Relax a machine dependent frag. This returns the amount by which
10571 the current size of the frag should change. */
10574 mips_relax_frag (fragp, stretch)
10578 if (! RELAX_MIPS16_P (fragp->fr_subtype))
10581 if (mips16_extended_frag (fragp, (asection *) NULL, stretch))
10583 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
10585 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
10590 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
10592 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
10599 /* Convert a machine dependent frag. */
10602 md_convert_frag (abfd, asec, fragp)
10610 if (RELAX_MIPS16_P (fragp->fr_subtype))
10613 register const struct mips16_immed_operand *op;
10614 boolean small, ext;
10617 unsigned long insn;
10618 boolean use_extend;
10619 unsigned short extend;
10621 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
10622 op = mips16_immed_operands;
10623 while (op->type != type)
10626 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
10637 resolve_symbol_value (fragp->fr_symbol, 1);
10638 val = S_GET_VALUE (fragp->fr_symbol);
10643 addr = fragp->fr_address + fragp->fr_fix;
10645 /* The rules for the base address of a PC relative reloc are
10646 complicated; see mips16_extended_frag. */
10647 if (type == 'p' || type == 'q')
10652 /* Ignore the low bit in the target, since it will be
10653 set for a text label. */
10654 if ((val & 1) != 0)
10657 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
10659 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
10662 addr &= ~ (addressT) ((1 << op->shift) - 1);
10665 /* Make sure the section winds up with the alignment we have
10668 record_alignment (asec, op->shift);
10672 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
10673 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
10674 as_warn_where (fragp->fr_file, fragp->fr_line,
10675 "extended instruction in delay slot");
10677 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
10679 if (target_big_endian)
10680 insn = bfd_getb16 (buf);
10682 insn = bfd_getl16 (buf);
10684 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
10685 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
10686 small, ext, &insn, &use_extend, &extend);
10690 md_number_to_chars (buf, 0xf000 | extend, 2);
10691 fragp->fr_fix += 2;
10695 md_number_to_chars (buf, insn, 2);
10696 fragp->fr_fix += 2;
10701 if (fragp->fr_opcode == NULL)
10704 old = RELAX_OLD (fragp->fr_subtype);
10705 new = RELAX_NEW (fragp->fr_subtype);
10706 fixptr = fragp->fr_literal + fragp->fr_fix;
10709 memcpy (fixptr - old, fixptr, new);
10711 fragp->fr_fix += new - old;
10717 /* This function is called after the relocs have been generated.
10718 We've been storing mips16 text labels as odd. Here we convert them
10719 back to even for the convenience of the debugger. */
10722 mips_frob_file_after_relocs ()
10725 unsigned int count, i;
10727 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10730 syms = bfd_get_outsymbols (stdoutput);
10731 count = bfd_get_symcount (stdoutput);
10732 for (i = 0; i < count; i++, syms++)
10734 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
10735 && ((*syms)->value & 1) != 0)
10737 (*syms)->value &= ~1;
10738 /* If the symbol has an odd size, it was probably computed
10739 incorrectly, so adjust that as well. */
10740 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
10741 ++elf_symbol (*syms)->internal_elf_sym.st_size;
10748 /* This function is called whenever a label is defined. It is used
10749 when handling branch delays; if a branch has a label, we assume we
10750 can not move it. */
10753 mips_define_label (sym)
10756 struct insn_label_list *l;
10758 if (free_insn_labels == NULL)
10759 l = (struct insn_label_list *) xmalloc (sizeof *l);
10762 l = free_insn_labels;
10763 free_insn_labels = l->next;
10767 l->next = insn_labels;
10771 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
10773 /* Some special processing for a MIPS ELF file. */
10776 mips_elf_final_processing ()
10778 /* Write out the register information. */
10783 s.ri_gprmask = mips_gprmask;
10784 s.ri_cprmask[0] = mips_cprmask[0];
10785 s.ri_cprmask[1] = mips_cprmask[1];
10786 s.ri_cprmask[2] = mips_cprmask[2];
10787 s.ri_cprmask[3] = mips_cprmask[3];
10788 /* The gp_value field is set by the MIPS ELF backend. */
10790 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
10791 ((Elf32_External_RegInfo *)
10792 mips_regmask_frag));
10796 Elf64_Internal_RegInfo s;
10798 s.ri_gprmask = mips_gprmask;
10800 s.ri_cprmask[0] = mips_cprmask[0];
10801 s.ri_cprmask[1] = mips_cprmask[1];
10802 s.ri_cprmask[2] = mips_cprmask[2];
10803 s.ri_cprmask[3] = mips_cprmask[3];
10804 /* The gp_value field is set by the MIPS ELF backend. */
10806 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
10807 ((Elf64_External_RegInfo *)
10808 mips_regmask_frag));
10811 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
10812 sort of BFD interface for this. */
10813 if (mips_any_noreorder)
10814 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
10815 if (mips_pic != NO_PIC)
10816 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
10819 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
10821 /* These functions should really be defined by the object file format,
10822 since they are related to debugging information. However, this
10823 code has to work for the a.out format, which does not define them,
10824 so we provide simple versions here. These don't actually generate
10825 any debugging information, but they do simple checking and someday
10826 somebody may make them useful. */
10830 struct loc *loc_next;
10831 unsigned long loc_fileno;
10832 unsigned long loc_lineno;
10833 unsigned long loc_offset;
10834 unsigned short loc_delta;
10835 unsigned short loc_count;
10842 typedef struct proc
10844 struct proc *proc_next;
10845 struct symbol *proc_isym;
10846 struct symbol *proc_end;
10847 unsigned long proc_reg_mask;
10848 unsigned long proc_reg_offset;
10849 unsigned long proc_fpreg_mask;
10850 unsigned long proc_fpreg_offset;
10851 unsigned long proc_frameoffset;
10852 unsigned long proc_framereg;
10853 unsigned long proc_pcreg;
10855 struct file *proc_file;
10860 typedef struct file
10862 struct file *file_next;
10863 unsigned long file_fileno;
10864 struct symbol *file_symbol;
10865 struct symbol *file_end;
10866 struct proc *file_proc;
10871 static struct obstack proc_frags;
10872 static procS *proc_lastP;
10873 static procS *proc_rootP;
10874 static int numprocs;
10879 obstack_begin (&proc_frags, 0x2000);
10885 /* check for premature end, nesting errors, etc */
10886 if (proc_lastP && proc_lastP->proc_end == NULL)
10887 as_warn ("missing `.end' at end of assembly");
10896 if (*input_line_pointer == '-')
10898 ++input_line_pointer;
10901 if (!isdigit (*input_line_pointer))
10902 as_bad ("Expected simple number.");
10903 if (input_line_pointer[0] == '0')
10905 if (input_line_pointer[1] == 'x')
10907 input_line_pointer += 2;
10908 while (isxdigit (*input_line_pointer))
10911 val |= hex_value (*input_line_pointer++);
10913 return negative ? -val : val;
10917 ++input_line_pointer;
10918 while (isdigit (*input_line_pointer))
10921 val |= *input_line_pointer++ - '0';
10923 return negative ? -val : val;
10926 if (!isdigit (*input_line_pointer))
10928 printf (" *input_line_pointer == '%c' 0x%02x\n",
10929 *input_line_pointer, *input_line_pointer);
10930 as_warn ("Invalid number");
10933 while (isdigit (*input_line_pointer))
10936 val += *input_line_pointer++ - '0';
10938 return negative ? -val : val;
10941 /* The .file directive; just like the usual .file directive, but there
10942 is an initial number which is the ECOFF file index. */
10950 line = get_number ();
10955 /* The .end directive. */
10963 if (!is_end_of_line[(unsigned char) *input_line_pointer])
10966 demand_empty_rest_of_line ();
10970 if (now_seg != text_section)
10971 as_warn (".end not in text section");
10974 as_warn (".end and no .ent seen yet.");
10980 assert (S_GET_NAME (p));
10981 if (strcmp (S_GET_NAME (p), S_GET_NAME (proc_lastP->proc_isym)))
10982 as_warn (".end symbol does not match .ent symbol.");
10985 proc_lastP->proc_end = (symbolS *) 1;
10988 /* The .aent and .ent directives. */
10998 symbolP = get_symbol ();
10999 if (*input_line_pointer == ',')
11000 input_line_pointer++;
11001 SKIP_WHITESPACE ();
11002 if (isdigit (*input_line_pointer) || *input_line_pointer == '-')
11003 number = get_number ();
11004 if (now_seg != text_section)
11005 as_warn (".ent or .aent not in text section.");
11007 if (!aent && proc_lastP && proc_lastP->proc_end == NULL)
11008 as_warn ("missing `.end'");
11012 procP = (procS *) obstack_alloc (&proc_frags, sizeof (*procP));
11013 procP->proc_isym = symbolP;
11014 procP->proc_reg_mask = 0;
11015 procP->proc_reg_offset = 0;
11016 procP->proc_fpreg_mask = 0;
11017 procP->proc_fpreg_offset = 0;
11018 procP->proc_frameoffset = 0;
11019 procP->proc_framereg = 0;
11020 procP->proc_pcreg = 0;
11021 procP->proc_end = NULL;
11022 procP->proc_next = NULL;
11024 proc_lastP->proc_next = procP;
11026 proc_rootP = procP;
11027 proc_lastP = procP;
11030 demand_empty_rest_of_line ();
11033 /* The .frame directive. */
11046 frame_reg = tc_get_register (1);
11047 if (*input_line_pointer == ',')
11048 input_line_pointer++;
11049 frame_off = get_absolute_expression ();
11050 if (*input_line_pointer == ',')
11051 input_line_pointer++;
11052 pcreg = tc_get_register (0);
11054 /* bob third eye */
11055 assert (proc_rootP);
11056 proc_rootP->proc_framereg = frame_reg;
11057 proc_rootP->proc_frameoffset = frame_off;
11058 proc_rootP->proc_pcreg = pcreg;
11059 /* bob macho .frame */
11061 /* We don't have to write out a frame stab for unoptimized code. */
11062 if (!(frame_reg == FP && frame_off == 0))
11065 as_warn ("No .ent for .frame to use.");
11066 (void) sprintf (str, "R%d;%d", frame_reg, frame_off);
11067 symP = symbol_new (str, N_VFP, 0, frag_now);
11068 S_SET_TYPE (symP, N_RMASK);
11069 S_SET_OTHER (symP, 0);
11070 S_SET_DESC (symP, 0);
11071 symP->sy_forward = proc_lastP->proc_isym;
11072 /* bob perhaps I should have used pseudo set */
11074 demand_empty_rest_of_line ();
11078 /* The .fmask and .mask directives. */
11085 char str[100], *strP;
11091 mask = get_number ();
11092 if (*input_line_pointer == ',')
11093 input_line_pointer++;
11094 off = get_absolute_expression ();
11096 /* bob only for coff */
11097 assert (proc_rootP);
11098 if (reg_type == 'F')
11100 proc_rootP->proc_fpreg_mask = mask;
11101 proc_rootP->proc_fpreg_offset = off;
11105 proc_rootP->proc_reg_mask = mask;
11106 proc_rootP->proc_reg_offset = off;
11109 /* bob macho .mask + .fmask */
11111 /* We don't have to write out a mask stab if no saved regs. */
11115 as_warn ("No .ent for .mask to use.");
11117 for (i = 0; i < 32; i++)
11121 sprintf (strP, "%c%d,", reg_type, i);
11122 strP += strlen (strP);
11126 sprintf (strP, ";%d,", off);
11127 symP = symbol_new (str, N_RMASK, 0, frag_now);
11128 S_SET_TYPE (symP, N_RMASK);
11129 S_SET_OTHER (symP, 0);
11130 S_SET_DESC (symP, 0);
11131 symP->sy_forward = proc_lastP->proc_isym;
11132 /* bob perhaps I should have used pseudo set */
11137 /* The .loc directive. */
11148 assert (now_seg == text_section);
11150 lineno = get_number ();
11151 addroff = frag_now_fix ();
11153 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
11154 S_SET_TYPE (symbolP, N_SLINE);
11155 S_SET_OTHER (symbolP, 0);
11156 S_SET_DESC (symbolP, lineno);
11157 symbolP->sy_segment = now_seg;