1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright (C) 1993, 94, 95, 96, 97, 98, 1999, 2000 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
58 #undef obj_frob_file_after_relocs
59 #undef obj_frob_symbol
61 #undef obj_sec_sym_ok_for_reloc
62 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
65 /* Fix any of them that we actually care about. */
67 #define OUTPUT_FLAVOR mips_output_flavor()
74 #ifndef ECOFF_DEBUGGING
75 #define NO_ECOFF_DEBUGGING
76 #define ECOFF_DEBUGGING 0
81 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
82 static char *mips_regmask_frag;
87 #define PIC_CALL_REG 25
95 #define ILLEGAL_REG (32)
97 /* Allow override of standard little-endian ECOFF format. */
99 #ifndef ECOFF_LITTLE_FORMAT
100 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
103 extern int target_big_endian;
105 /* 1 is we should use the 64 bit MIPS ELF ABI, 0 if we should use the
106 32 bit ABI. This has no meaning for ECOFF.
107 Note that the default is always 32 bit, even if "configured" for
108 64 bit [e.g. --target=mips64-elf]. */
111 /* The default target format to use. */
113 mips_target_format ()
115 switch (OUTPUT_FLAVOR)
117 case bfd_target_aout_flavour:
118 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
119 case bfd_target_ecoff_flavour:
120 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
121 case bfd_target_coff_flavour:
123 case bfd_target_elf_flavour:
125 /* This is traditional mips */
126 return (target_big_endian
127 ? "elf32-tradbigmips" : "elf32-tradlittlemips");
129 return (target_big_endian
130 ? (mips_64 ? "elf64-bigmips" : "elf32-bigmips")
131 : (mips_64 ? "elf64-littlemips" : "elf32-littlemips"));
139 /* The name of the readonly data section. */
140 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
142 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
144 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
146 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
150 /* This is the set of options which may be modified by the .set
151 pseudo-op. We use a struct so that .set push and .set pop are more
154 struct mips_set_options
156 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
157 if it has not been initialized. Changed by `.set mipsN', and the
158 -mipsN command line option, and the default CPU. */
160 /* Whether we are assembling for the mips16 processor. 0 if we are
161 not, 1 if we are, and -1 if the value has not been initialized.
162 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
163 -nomips16 command line options, and the default CPU. */
165 /* Non-zero if we should not reorder instructions. Changed by `.set
166 reorder' and `.set noreorder'. */
168 /* Non-zero if we should not permit the $at ($1) register to be used
169 in instructions. Changed by `.set at' and `.set noat'. */
171 /* Non-zero if we should warn when a macro instruction expands into
172 more than one machine instruction. Changed by `.set nomacro' and
174 int warn_about_macros;
175 /* Non-zero if we should not move instructions. Changed by `.set
176 move', `.set volatile', `.set nomove', and `.set novolatile'. */
178 /* Non-zero if we should not optimize branches by moving the target
179 of the branch into the delay slot. Actually, we don't perform
180 this optimization anyhow. Changed by `.set bopt' and `.set
183 /* Non-zero if we should not autoextend mips16 instructions.
184 Changed by `.set autoextend' and `.set noautoextend'. */
188 /* This is the struct we use to hold the current set of options. Note
189 that we must set the isa and mips16 fields to -1 to indicate that
190 they have not been initialized. */
192 static struct mips_set_options mips_opts = { -1, -1, 0, 0, 0, 0, 0, 0 };
194 /* These variables are filled in with the masks of registers used.
195 The object format code reads them and puts them in the appropriate
197 unsigned long mips_gprmask;
198 unsigned long mips_cprmask[4];
200 /* MIPS ISA we are using for this output file. */
201 static int file_mips_isa;
203 /* The CPU type as a number: 2000, 3000, 4000, 4400, etc. */
204 static int mips_cpu = -1;
206 /* The argument of the -mabi= flag. */
207 static char* mips_abi_string = 0;
209 /* Wether we should mark the file EABI64 or EABI32. */
210 static int mips_eabi64 = 0;
212 /* If they asked for mips1 or mips2 and a cpu that is
213 mips3 or greater, then mark the object file 32BITMODE. */
214 static int mips_32bitmode = 0;
216 /* True if -mgp32 was passed. */
217 static int mips_gp32 = 0;
219 /* Some ISA's have delay slots for instructions which read or write
220 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
221 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
222 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
223 delay slot in this ISA. The uses of this macro assume that any
224 ISA that has delay slots for one of these, has them for all. They
225 also assume that ISAs which don't have delays for these insns, don't
226 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
227 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
233 /* Return true if ISA supports 64 bit gp register instructions. */
234 #define ISA_HAS_64BIT_REGS(ISA) ( \
239 /* Whether the processor uses hardware interlocks to protect
240 reads from the HI and LO registers, and thus does not
241 require nops to be inserted.
243 FIXME: GCC makes a distinction between -mcpu=FOO and -mFOO:
244 -mcpu=FOO schedules for FOO, but still produces code that meets the
245 requirements of MIPS ISA I. For example, it won't generate any
246 FOO-specific instructions, and it will still assume that any
247 scheduling hazards described in MIPS ISA I are there, even if FOO
248 has interlocks. -mFOO gives GCC permission to generate code that
249 will only run on a FOO; it will generate FOO-specific instructions,
250 and assume interlocks provided by a FOO.
252 However, GAS currently doesn't make this distinction; before Jan 28
253 1999, GAS's -mcpu=FOO implied -mFOO, which violates GCC's
254 assumptions. The GCC driver passes these flags through to GAS, so
255 if GAS actually does anything that doesn't meet MIPS ISA I with
256 -mFOO, then GCC's -mcpu=FOO flag isn't going to work.
258 And furthermore, it did not assume that -mFOO implied -mcpu=FOO,
259 which seems senseless --- why generate code which will only run on
260 a FOO, but schedule for something else?
262 So now, at least, -mcpu=FOO and -mFOO are exactly equivalent.
264 -- Jim Blandy <jimb@cygnus.com> */
266 #define hilo_interlocks (mips_cpu == 4010 \
269 /* Whether the processor uses hardware interlocks to protect reads
270 from the GPRs, and thus does not require nops to be inserted. */
271 #define gpr_interlocks \
272 (mips_opts.isa != 1 \
275 /* As with other "interlocks" this is used by hardware that has FP
276 (co-processor) interlocks. */
277 /* Itbl support may require additional care here. */
278 #define cop_interlocks (mips_cpu == 4300 \
281 /* Is this a mfhi or mflo instruction? */
282 #define MF_HILO_INSN(PINFO) \
283 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
285 /* MIPS PIC level. */
289 /* Do not generate PIC code. */
292 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
293 not sure what it is supposed to do. */
296 /* Generate PIC code as in the SVR4 MIPS ABI. */
299 /* Generate PIC code without using a global offset table: the data
300 segment has a maximum size of 64K, all data references are off
301 the $gp register, and all text references are PC relative. This
302 is used on some embedded systems. */
306 static enum mips_pic_level mips_pic;
308 /* 1 if we should generate 32 bit offsets from the GP register in
309 SVR4_PIC mode. Currently has no meaning in other modes. */
310 static int mips_big_got;
312 /* 1 if trap instructions should used for overflow rather than break
314 static int mips_trap;
316 /* 1 if double width floating point constants should not be constructed
317 by a assembling two single width halves into two single width floating
318 point registers which just happen to alias the double width destination
319 register. On some architectures this aliasing can be disabled by a bit
320 in the status register, and the setting of this bit cannot be determined
321 automatically at assemble time. */
322 static int mips_disable_float_construction;
324 /* Non-zero if any .set noreorder directives were used. */
326 static int mips_any_noreorder;
328 /* Non-zero if nops should be inserted when the register referenced in
329 an mfhi/mflo instruction is read in the next two instructions. */
330 static int mips_7000_hilo_fix;
332 /* The size of the small data section. */
333 static int g_switch_value = 8;
334 /* Whether the -G option was used. */
335 static int g_switch_seen = 0;
340 /* If we can determine in advance that GP optimization won't be
341 possible, we can skip the relaxation stuff that tries to produce
342 GP-relative references. This makes delay slot optimization work
345 This function can only provide a guess, but it seems to work for
346 gcc output. It needs to guess right for gcc, otherwise gcc
347 will put what it thinks is a GP-relative instruction in a branch
350 I don't know if a fix is needed for the SVR4_PIC mode. I've only
351 fixed it for the non-PIC mode. KR 95/04/07 */
352 static int nopic_need_relax PARAMS ((symbolS *, int));
354 /* handle of the OPCODE hash table */
355 static struct hash_control *op_hash = NULL;
357 /* The opcode hash table we use for the mips16. */
358 static struct hash_control *mips16_op_hash = NULL;
360 /* This array holds the chars that always start a comment. If the
361 pre-processor is disabled, these aren't very useful */
362 const char comment_chars[] = "#";
364 /* This array holds the chars that only start a comment at the beginning of
365 a line. If the line seems to have the form '# 123 filename'
366 .line and .file directives will appear in the pre-processed output */
367 /* Note that input_file.c hand checks for '#' at the beginning of the
368 first line of the input file. This is because the compiler outputs
369 #NO_APP at the beginning of its output. */
370 /* Also note that C style comments are always supported. */
371 const char line_comment_chars[] = "#";
373 /* This array holds machine specific line separator characters. */
374 const char line_separator_chars[] = ";";
376 /* Chars that can be used to separate mant from exp in floating point nums */
377 const char EXP_CHARS[] = "eE";
379 /* Chars that mean this number is a floating point constant */
382 const char FLT_CHARS[] = "rRsSfFdDxXpP";
384 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
385 changed in read.c . Ideally it shouldn't have to know about it at all,
386 but nothing is ideal around here.
389 static char *insn_error;
391 static int auto_align = 1;
393 /* When outputting SVR4 PIC code, the assembler needs to know the
394 offset in the stack frame from which to restore the $gp register.
395 This is set by the .cprestore pseudo-op, and saved in this
397 static offsetT mips_cprestore_offset = -1;
399 /* This is the register which holds the stack frame, as set by the
400 .frame pseudo-op. This is needed to implement .cprestore. */
401 static int mips_frame_reg = SP;
403 /* To output NOP instructions correctly, we need to keep information
404 about the previous two instructions. */
406 /* Whether we are optimizing. The default value of 2 means to remove
407 unneeded NOPs and swap branch instructions when possible. A value
408 of 1 means to not swap branches. A value of 0 means to always
410 static int mips_optimize = 2;
412 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
413 equivalent to seeing no -g option at all. */
414 static int mips_debug = 0;
416 /* The previous instruction. */
417 static struct mips_cl_insn prev_insn;
419 /* The instruction before prev_insn. */
420 static struct mips_cl_insn prev_prev_insn;
422 /* If we don't want information for prev_insn or prev_prev_insn, we
423 point the insn_mo field at this dummy integer. */
424 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
426 /* Non-zero if prev_insn is valid. */
427 static int prev_insn_valid;
429 /* The frag for the previous instruction. */
430 static struct frag *prev_insn_frag;
432 /* The offset into prev_insn_frag for the previous instruction. */
433 static long prev_insn_where;
435 /* The reloc type for the previous instruction, if any. */
436 static bfd_reloc_code_real_type prev_insn_reloc_type;
438 /* The reloc for the previous instruction, if any. */
439 static fixS *prev_insn_fixp;
441 /* Non-zero if the previous instruction was in a delay slot. */
442 static int prev_insn_is_delay_slot;
444 /* Non-zero if the previous instruction was in a .set noreorder. */
445 static int prev_insn_unreordered;
447 /* Non-zero if the previous instruction uses an extend opcode (if
449 static int prev_insn_extended;
451 /* Non-zero if the previous previous instruction was in a .set
453 static int prev_prev_insn_unreordered;
455 /* If this is set, it points to a frag holding nop instructions which
456 were inserted before the start of a noreorder section. If those
457 nops turn out to be unnecessary, the size of the frag can be
459 static fragS *prev_nop_frag;
461 /* The number of nop instructions we created in prev_nop_frag. */
462 static int prev_nop_frag_holds;
464 /* The number of nop instructions that we know we need in
466 static int prev_nop_frag_required;
468 /* The number of instructions we've seen since prev_nop_frag. */
469 static int prev_nop_frag_since;
471 /* For ECOFF and ELF, relocations against symbols are done in two
472 parts, with a HI relocation and a LO relocation. Each relocation
473 has only 16 bits of space to store an addend. This means that in
474 order for the linker to handle carries correctly, it must be able
475 to locate both the HI and the LO relocation. This means that the
476 relocations must appear in order in the relocation table.
478 In order to implement this, we keep track of each unmatched HI
479 relocation. We then sort them so that they immediately precede the
480 corresponding LO relocation. */
485 struct mips_hi_fixup *next;
488 /* The section this fixup is in. */
492 /* The list of unmatched HI relocs. */
494 static struct mips_hi_fixup *mips_hi_fixup_list;
496 /* Map normal MIPS register numbers to mips16 register numbers. */
498 #define X ILLEGAL_REG
499 static const int mips32_to_16_reg_map[] =
501 X, X, 2, 3, 4, 5, 6, 7,
502 X, X, X, X, X, X, X, X,
503 0, 1, X, X, X, X, X, X,
504 X, X, X, X, X, X, X, X
508 /* Map mips16 register numbers to normal MIPS register numbers. */
510 static const int mips16_to_32_reg_map[] =
512 16, 17, 2, 3, 4, 5, 6, 7
515 /* Since the MIPS does not have multiple forms of PC relative
516 instructions, we do not have to do relaxing as is done on other
517 platforms. However, we do have to handle GP relative addressing
518 correctly, which turns out to be a similar problem.
520 Every macro that refers to a symbol can occur in (at least) two
521 forms, one with GP relative addressing and one without. For
522 example, loading a global variable into a register generally uses
523 a macro instruction like this:
525 If i can be addressed off the GP register (this is true if it is in
526 the .sbss or .sdata section, or if it is known to be smaller than
527 the -G argument) this will generate the following instruction:
529 This instruction will use a GPREL reloc. If i can not be addressed
530 off the GP register, the following instruction sequence will be used:
533 In this case the first instruction will have a HI16 reloc, and the
534 second reloc will have a LO16 reloc. Both relocs will be against
537 The issue here is that we may not know whether i is GP addressable
538 until after we see the instruction that uses it. Therefore, we
539 want to be able to choose the final instruction sequence only at
540 the end of the assembly. This is similar to the way other
541 platforms choose the size of a PC relative instruction only at the
544 When generating position independent code we do not use GP
545 addressing in quite the same way, but the issue still arises as
546 external symbols and local symbols must be handled differently.
548 We handle these issues by actually generating both possible
549 instruction sequences. The longer one is put in a frag_var with
550 type rs_machine_dependent. We encode what to do with the frag in
551 the subtype field. We encode (1) the number of existing bytes to
552 replace, (2) the number of new bytes to use, (3) the offset from
553 the start of the existing bytes to the first reloc we must generate
554 (that is, the offset is applied from the start of the existing
555 bytes after they are replaced by the new bytes, if any), (4) the
556 offset from the start of the existing bytes to the second reloc,
557 (5) whether a third reloc is needed (the third reloc is always four
558 bytes after the second reloc), and (6) whether to warn if this
559 variant is used (this is sometimes needed if .set nomacro or .set
560 noat is in effect). All these numbers are reasonably small.
562 Generating two instruction sequences must be handled carefully to
563 ensure that delay slots are handled correctly. Fortunately, there
564 are a limited number of cases. When the second instruction
565 sequence is generated, append_insn is directed to maintain the
566 existing delay slot information, so it continues to apply to any
567 code after the second instruction sequence. This means that the
568 second instruction sequence must not impose any requirements not
569 required by the first instruction sequence.
571 These variant frags are then handled in functions called by the
572 machine independent code. md_estimate_size_before_relax returns
573 the final size of the frag. md_convert_frag sets up the final form
574 of the frag. tc_gen_reloc adjust the first reloc and adds a second
576 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
580 | (((reloc1) + 64) << 9) \
581 | (((reloc2) + 64) << 2) \
582 | ((reloc3) ? (1 << 1) : 0) \
584 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
585 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
586 #define RELAX_RELOC1(i) ((bfd_vma)(((i) >> 9) & 0x7f) - 64)
587 #define RELAX_RELOC2(i) ((bfd_vma)(((i) >> 2) & 0x7f) - 64)
588 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
589 #define RELAX_WARN(i) ((i) & 1)
591 /* For mips16 code, we use an entirely different form of relaxation.
592 mips16 supports two versions of most instructions which take
593 immediate values: a small one which takes some small value, and a
594 larger one which takes a 16 bit value. Since branches also follow
595 this pattern, relaxing these values is required.
597 We can assemble both mips16 and normal MIPS code in a single
598 object. Therefore, we need to support this type of relaxation at
599 the same time that we support the relaxation described above. We
600 use the high bit of the subtype field to distinguish these cases.
602 The information we store for this type of relaxation is the
603 argument code found in the opcode file for this relocation, whether
604 the user explicitly requested a small or extended form, and whether
605 the relocation is in a jump or jal delay slot. That tells us the
606 size of the value, and how it should be stored. We also store
607 whether the fragment is considered to be extended or not. We also
608 store whether this is known to be a branch to a different section,
609 whether we have tried to relax this frag yet, and whether we have
610 ever extended a PC relative fragment because of a shift count. */
611 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
614 | ((small) ? 0x100 : 0) \
615 | ((ext) ? 0x200 : 0) \
616 | ((dslot) ? 0x400 : 0) \
617 | ((jal_dslot) ? 0x800 : 0))
618 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
619 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
620 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
621 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
622 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
623 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
624 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
625 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
626 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
627 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
628 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
629 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
631 /* Prototypes for static functions. */
634 #define internalError() \
635 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
637 #define internalError() as_fatal (_("MIPS internal Error"));
640 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
642 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
643 unsigned int reg, enum mips_regclass class));
644 static int reg_needs_delay PARAMS ((int));
645 static void mips16_mark_labels PARAMS ((void));
646 static void append_insn PARAMS ((char *place,
647 struct mips_cl_insn * ip,
649 bfd_reloc_code_real_type r,
651 static void mips_no_prev_insn PARAMS ((int));
652 static void mips_emit_delays PARAMS ((boolean));
654 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
655 const char *name, const char *fmt,
658 static void macro_build ();
660 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
661 const char *, const char *,
663 static void macro_build_lui PARAMS ((char *place, int *counter,
664 expressionS * ep, int regnum));
665 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
666 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
668 static void load_register PARAMS ((int *, int, expressionS *, int));
669 static void load_address PARAMS ((int *counter, int reg, expressionS *ep));
670 static void macro PARAMS ((struct mips_cl_insn * ip));
671 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
672 #ifdef LOSING_COMPILER
673 static void macro2 PARAMS ((struct mips_cl_insn * ip));
675 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
676 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
677 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
678 boolean, boolean, unsigned long *,
679 boolean *, unsigned short *));
680 static int my_getSmallExpression PARAMS ((expressionS * ep, char *str));
681 static void my_getExpression PARAMS ((expressionS * ep, char *str));
682 static symbolS *get_symbol PARAMS ((void));
683 static void mips_align PARAMS ((int to, int fill, symbolS *label));
684 static void s_align PARAMS ((int));
685 static void s_change_sec PARAMS ((int));
686 static void s_cons PARAMS ((int));
687 static void s_float_cons PARAMS ((int));
688 static void s_mips_globl PARAMS ((int));
689 static void s_option PARAMS ((int));
690 static void s_mipsset PARAMS ((int));
691 static void s_abicalls PARAMS ((int));
692 static void s_cpload PARAMS ((int));
693 static void s_cprestore PARAMS ((int));
694 static void s_gpword PARAMS ((int));
695 static void s_cpadd PARAMS ((int));
696 static void s_insn PARAMS ((int));
697 static void md_obj_begin PARAMS ((void));
698 static void md_obj_end PARAMS ((void));
699 static long get_number PARAMS ((void));
700 static void s_mips_ent PARAMS ((int));
701 static void s_mips_end PARAMS ((int));
702 static void s_mips_frame PARAMS ((int));
703 static void s_mips_mask PARAMS ((int));
704 static void s_mips_stab PARAMS ((int));
705 static void s_mips_weakext PARAMS ((int));
706 static void s_file PARAMS ((int));
707 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
709 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
713 The following pseudo-ops from the Kane and Heinrich MIPS book
714 should be defined here, but are currently unsupported: .alias,
715 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
717 The following pseudo-ops from the Kane and Heinrich MIPS book are
718 specific to the type of debugging information being generated, and
719 should be defined by the object format: .aent, .begin, .bend,
720 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
723 The following pseudo-ops from the Kane and Heinrich MIPS book are
724 not MIPS CPU specific, but are also not specific to the object file
725 format. This file is probably the best place to define them, but
726 they are not currently supported: .asm0, .endr, .lab, .repeat,
729 static const pseudo_typeS mips_pseudo_table[] =
731 /* MIPS specific pseudo-ops. */
732 {"option", s_option, 0},
733 {"set", s_mipsset, 0},
734 {"rdata", s_change_sec, 'r'},
735 {"sdata", s_change_sec, 's'},
736 {"livereg", s_ignore, 0},
737 {"abicalls", s_abicalls, 0},
738 {"cpload", s_cpload, 0},
739 {"cprestore", s_cprestore, 0},
740 {"gpword", s_gpword, 0},
741 {"cpadd", s_cpadd, 0},
744 /* Relatively generic pseudo-ops that happen to be used on MIPS
746 {"asciiz", stringer, 1},
747 {"bss", s_change_sec, 'b'},
750 {"dword", s_cons, 3},
751 {"weakext", s_mips_weakext, 0},
753 /* These pseudo-ops are defined in read.c, but must be overridden
754 here for one reason or another. */
755 {"align", s_align, 0},
757 {"data", s_change_sec, 'd'},
758 {"double", s_float_cons, 'd'},
759 {"float", s_float_cons, 'f'},
760 {"globl", s_mips_globl, 0},
761 {"global", s_mips_globl, 0},
762 {"hword", s_cons, 1},
767 {"short", s_cons, 1},
768 {"single", s_float_cons, 'f'},
769 {"stabn", s_mips_stab, 'n'},
770 {"text", s_change_sec, 't'},
775 static const pseudo_typeS mips_nonecoff_pseudo_table[] = {
776 /* These pseudo-ops should be defined by the object file format.
777 However, a.out doesn't support them, so we have versions here. */
778 {"aent", s_mips_ent, 1},
779 {"bgnb", s_ignore, 0},
780 {"end", s_mips_end, 0},
781 {"endb", s_ignore, 0},
782 {"ent", s_mips_ent, 0},
784 {"fmask", s_mips_mask, 'F'},
785 {"frame", s_mips_frame, 0},
786 {"loc", s_ignore, 0},
787 {"mask", s_mips_mask, 'R'},
788 {"verstamp", s_ignore, 0},
792 extern void pop_insert PARAMS ((const pseudo_typeS *));
797 pop_insert (mips_pseudo_table);
798 if (! ECOFF_DEBUGGING)
799 pop_insert (mips_nonecoff_pseudo_table);
802 /* Symbols labelling the current insn. */
804 struct insn_label_list
806 struct insn_label_list *next;
810 static struct insn_label_list *insn_labels;
811 static struct insn_label_list *free_insn_labels;
813 static void mips_clear_insn_labels PARAMS ((void));
816 mips_clear_insn_labels ()
818 register struct insn_label_list **pl;
820 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
826 static char *expr_end;
828 /* Expressions which appear in instructions. These are set by
831 static expressionS imm_expr;
832 static expressionS offset_expr;
834 /* Relocs associated with imm_expr and offset_expr. */
836 static bfd_reloc_code_real_type imm_reloc;
837 static bfd_reloc_code_real_type offset_reloc;
839 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
841 static boolean imm_unmatched_hi;
843 /* These are set by mips16_ip if an explicit extension is used. */
845 static boolean mips16_small, mips16_ext;
847 #ifdef MIPS_STABS_ELF
848 /* The pdr segment for per procedure frame/regmask info */
854 * This function is called once, at assembler startup time. It should
855 * set up all the tables, etc. that the MD part of the assembler will need.
861 register const char *retval = NULL;
862 register unsigned int i = 0;
866 int mips_isa_from_cpu;
868 /* GP relative stuff not working for PE */
869 if (strncmp (TARGET_OS, "pe", 2) == 0
870 && g_switch_value != 0)
873 as_bad (_("-G not supported in this configuration."));
878 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
880 a = xmalloc (sizeof TARGET_CPU);
881 strcpy (a, TARGET_CPU);
882 a[(sizeof TARGET_CPU) - 3] = '\0';
888 /* Set mips_cpu based on TARGET_CPU, unless TARGET_CPU is
889 just the generic 'mips', in which case set mips_cpu based
890 on the given ISA, if any. */
892 if (strcmp (cpu, "mips") == 0)
894 if (mips_opts.isa < 0)
897 else if (mips_opts.isa == 2)
900 else if (mips_opts.isa == 3)
903 else if (mips_opts.isa == 4)
910 else if (strcmp (cpu, "r3900") == 0
911 || strcmp (cpu, "mipstx39") == 0
915 else if (strcmp (cpu, "r6000") == 0
916 || strcmp (cpu, "mips2") == 0)
919 else if (strcmp (cpu, "mips64") == 0
920 || strcmp (cpu, "r4000") == 0
921 || strcmp (cpu, "mips3") == 0)
924 else if (strcmp (cpu, "r4400") == 0)
927 else if (strcmp (cpu, "mips64orion") == 0
928 || strcmp (cpu, "r4600") == 0)
931 else if (strcmp (cpu, "r4650") == 0)
934 else if (strcmp (cpu, "mips64vr4300") == 0)
937 else if (strcmp (cpu, "mips64vr4111") == 0)
940 else if (strcmp (cpu, "mips64vr4100") == 0)
943 else if (strcmp (cpu, "r4010") == 0)
946 else if (strcmp (cpu, "r5000") == 0
947 || strcmp (cpu, "mips64vr5000") == 0)
950 else if (strcmp (cpu, "r8000") == 0
951 || strcmp (cpu, "mips4") == 0)
954 else if (strcmp (cpu, "r10000") == 0)
957 else if (strcmp (cpu, "mips16") == 0)
958 mips_cpu = 0; /* FIXME */
966 mips_isa_from_cpu = 1;
968 else if (mips_cpu == 6000
970 mips_isa_from_cpu = 2;
972 else if (mips_cpu == 4000
979 mips_isa_from_cpu = 3;
981 else if (mips_cpu == 5000
983 || mips_cpu == 10000)
984 mips_isa_from_cpu = 4;
987 mips_isa_from_cpu = -1;
989 if (mips_opts.isa == -1)
991 if (mips_isa_from_cpu != -1)
992 mips_opts.isa = mips_isa_from_cpu;
997 if (mips_opts.mips16 < 0)
999 if (strncmp (TARGET_CPU, "mips16", sizeof "mips16" - 1) == 0)
1000 mips_opts.mips16 = 1;
1002 mips_opts.mips16 = 0;
1005 /* End of TARGET_CPU processing, get rid of malloced memory
1014 if (mips_opts.isa == 1 && mips_trap)
1015 as_bad (_("trap exception not supported at ISA 1"));
1017 /* Set the EABI kind based on the ISA before the user gets
1018 to change the ISA with directives. This isn't really
1019 the best, but then neither is basing the abi on the isa. */
1020 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
1022 && 0 == strcmp (mips_abi_string,"eabi"))
1025 if (mips_cpu != 0 && mips_cpu != -1)
1027 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_cpu);
1029 /* If they asked for mips1 or mips2 and a cpu that is
1030 mips3 or greater, then mark the object file 32BITMODE. */
1031 if (mips_isa_from_cpu != -1
1032 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
1033 && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
1038 switch (mips_opts.isa)
1041 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 3000);
1044 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 6000);
1047 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 4000);
1050 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 8000);
1056 as_warn (_("Could not set architecture and machine"));
1058 file_mips_isa = mips_opts.isa;
1060 op_hash = hash_new ();
1062 for (i = 0; i < NUMOPCODES;)
1064 const char *name = mips_opcodes[i].name;
1066 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1069 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1070 mips_opcodes[i].name, retval);
1071 /* Probably a memory allocation problem? Give up now. */
1072 as_fatal (_("Broken assembler. No assembly attempted."));
1076 if (mips_opcodes[i].pinfo != INSN_MACRO)
1078 if (!validate_mips_insn (&mips_opcodes[i]))
1083 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1086 mips16_op_hash = hash_new ();
1089 while (i < bfd_mips16_num_opcodes)
1091 const char *name = mips16_opcodes[i].name;
1093 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1095 as_fatal (_("internal: can't hash `%s': %s"),
1096 mips16_opcodes[i].name, retval);
1099 if (mips16_opcodes[i].pinfo != INSN_MACRO
1100 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1101 != mips16_opcodes[i].match))
1103 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1104 mips16_opcodes[i].name, mips16_opcodes[i].args);
1109 while (i < bfd_mips16_num_opcodes
1110 && strcmp (mips16_opcodes[i].name, name) == 0);
1114 as_fatal (_("Broken assembler. No assembly attempted."));
1116 /* We add all the general register names to the symbol table. This
1117 helps us detect invalid uses of them. */
1118 for (i = 0; i < 32; i++)
1122 sprintf (buf, "$%d", i);
1123 symbol_table_insert (symbol_new (buf, reg_section, i,
1124 &zero_address_frag));
1126 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1127 &zero_address_frag));
1128 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1129 &zero_address_frag));
1130 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1131 &zero_address_frag));
1132 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1133 &zero_address_frag));
1134 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1135 &zero_address_frag));
1136 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1137 &zero_address_frag));
1138 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1139 &zero_address_frag));
1141 mips_no_prev_insn (false);
1144 mips_cprmask[0] = 0;
1145 mips_cprmask[1] = 0;
1146 mips_cprmask[2] = 0;
1147 mips_cprmask[3] = 0;
1149 /* set the default alignment for the text section (2**2) */
1150 record_alignment (text_section, 2);
1152 if (USE_GLOBAL_POINTER_OPT)
1153 bfd_set_gp_size (stdoutput, g_switch_value);
1155 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1157 /* On a native system, sections must be aligned to 16 byte
1158 boundaries. When configured for an embedded ELF target, we
1160 if (strcmp (TARGET_OS, "elf") != 0)
1162 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1163 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1164 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1167 /* Create a .reginfo section for register masks and a .mdebug
1168 section for debugging information. */
1176 subseg = now_subseg;
1178 /* The ABI says this section should be loaded so that the
1179 running program can access it. However, we don't load it
1180 if we are configured for an embedded target */
1181 flags = SEC_READONLY | SEC_DATA;
1182 if (strcmp (TARGET_OS, "elf") != 0)
1183 flags |= SEC_ALLOC | SEC_LOAD;
1187 sec = subseg_new (".reginfo", (subsegT) 0);
1189 (void) bfd_set_section_flags (stdoutput, sec, flags);
1190 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1193 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1198 /* The 64-bit ABI uses a .MIPS.options section rather than
1199 .reginfo section. */
1200 sec = subseg_new (".MIPS.options", (subsegT) 0);
1201 (void) bfd_set_section_flags (stdoutput, sec, flags);
1202 (void) bfd_set_section_alignment (stdoutput, sec, 3);
1205 /* Set up the option header. */
1207 Elf_Internal_Options opthdr;
1210 opthdr.kind = ODK_REGINFO;
1211 opthdr.size = (sizeof (Elf_External_Options)
1212 + sizeof (Elf64_External_RegInfo));
1215 f = frag_more (sizeof (Elf_External_Options));
1216 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1217 (Elf_External_Options *) f);
1219 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1224 if (ECOFF_DEBUGGING)
1226 sec = subseg_new (".mdebug", (subsegT) 0);
1227 (void) bfd_set_section_flags (stdoutput, sec,
1228 SEC_HAS_CONTENTS | SEC_READONLY);
1229 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1232 #ifdef MIPS_STABS_ELF
1233 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1234 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1235 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
1236 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1239 subseg_set (seg, subseg);
1243 if (! ECOFF_DEBUGGING)
1250 if (! ECOFF_DEBUGGING)
1258 struct mips_cl_insn insn;
1260 imm_expr.X_op = O_absent;
1261 imm_reloc = BFD_RELOC_UNUSED;
1262 imm_unmatched_hi = false;
1263 offset_expr.X_op = O_absent;
1264 offset_reloc = BFD_RELOC_UNUSED;
1266 if (mips_opts.mips16)
1267 mips16_ip (str, &insn);
1270 mips_ip (str, &insn);
1271 DBG((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1272 str, insn.insn_opcode));
1277 as_bad ("%s `%s'", insn_error, str);
1281 if (insn.insn_mo->pinfo == INSN_MACRO)
1283 if (mips_opts.mips16)
1284 mips16_macro (&insn);
1290 if (imm_expr.X_op != O_absent)
1291 append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc,
1293 else if (offset_expr.X_op != O_absent)
1294 append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc, false);
1296 append_insn ((char *) NULL, &insn, NULL, BFD_RELOC_UNUSED, false);
1300 /* See whether instruction IP reads register REG. CLASS is the type
1304 insn_uses_reg (ip, reg, class)
1305 struct mips_cl_insn *ip;
1307 enum mips_regclass class;
1309 if (class == MIPS16_REG)
1311 assert (mips_opts.mips16);
1312 reg = mips16_to_32_reg_map[reg];
1313 class = MIPS_GR_REG;
1316 /* Don't report on general register 0, since it never changes. */
1317 if (class == MIPS_GR_REG && reg == 0)
1320 if (class == MIPS_FP_REG)
1322 assert (! mips_opts.mips16);
1323 /* If we are called with either $f0 or $f1, we must check $f0.
1324 This is not optimal, because it will introduce an unnecessary
1325 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1326 need to distinguish reading both $f0 and $f1 or just one of
1327 them. Note that we don't have to check the other way,
1328 because there is no instruction that sets both $f0 and $f1
1329 and requires a delay. */
1330 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1331 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1332 == (reg &~ (unsigned) 1)))
1334 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1335 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1336 == (reg &~ (unsigned) 1)))
1339 else if (! mips_opts.mips16)
1341 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1342 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1344 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1345 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1350 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1351 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1352 & MIPS16OP_MASK_RX)]
1355 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1356 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1357 & MIPS16OP_MASK_RY)]
1360 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1361 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1362 & MIPS16OP_MASK_MOVE32Z)]
1365 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1367 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1369 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1371 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1372 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1373 & MIPS16OP_MASK_REGR32) == reg)
1380 /* This function returns true if modifying a register requires a
1384 reg_needs_delay (reg)
1387 unsigned long prev_pinfo;
1389 prev_pinfo = prev_insn.insn_mo->pinfo;
1390 if (! mips_opts.noreorder
1391 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1392 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1393 || (! gpr_interlocks
1394 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1396 /* A load from a coprocessor or from memory. All load
1397 delays delay the use of general register rt for one
1398 instruction on the r3000. The r6000 and r4000 use
1400 /* Itbl support may require additional care here. */
1401 know (prev_pinfo & INSN_WRITE_GPR_T);
1402 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1409 /* Mark instruction labels in mips16 mode. This permits the linker to
1410 handle them specially, such as generating jalx instructions when
1411 needed. We also make them odd for the duration of the assembly, in
1412 order to generate the right sort of code. We will make them even
1413 in the adjust_symtab routine, while leaving them marked. This is
1414 convenient for the debugger and the disassembler. The linker knows
1415 to make them odd again. */
1418 mips16_mark_labels ()
1420 if (mips_opts.mips16)
1422 struct insn_label_list *l;
1424 for (l = insn_labels; l != NULL; l = l->next)
1427 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1428 S_SET_OTHER (l->label, STO_MIPS16);
1430 if ((S_GET_VALUE (l->label) & 1) == 0)
1431 S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1);
1436 /* Output an instruction. PLACE is where to put the instruction; if
1437 it is NULL, this uses frag_more to get room. IP is the instruction
1438 information. ADDRESS_EXPR is an operand of the instruction to be
1439 used with RELOC_TYPE. */
1442 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1444 struct mips_cl_insn *ip;
1445 expressionS *address_expr;
1446 bfd_reloc_code_real_type reloc_type;
1447 boolean unmatched_hi;
1449 register unsigned long prev_pinfo, pinfo;
1454 /* Mark instruction labels in mips16 mode. */
1455 if (mips_opts.mips16)
1456 mips16_mark_labels ();
1458 prev_pinfo = prev_insn.insn_mo->pinfo;
1459 pinfo = ip->insn_mo->pinfo;
1461 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1465 /* If the previous insn required any delay slots, see if we need
1466 to insert a NOP or two. There are eight kinds of possible
1467 hazards, of which an instruction can have at most one type.
1468 (1) a load from memory delay
1469 (2) a load from a coprocessor delay
1470 (3) an unconditional branch delay
1471 (4) a conditional branch delay
1472 (5) a move to coprocessor register delay
1473 (6) a load coprocessor register from memory delay
1474 (7) a coprocessor condition code delay
1475 (8) a HI/LO special register delay
1477 There are a lot of optimizations we could do that we don't.
1478 In particular, we do not, in general, reorder instructions.
1479 If you use gcc with optimization, it will reorder
1480 instructions and generally do much more optimization then we
1481 do here; repeating all that work in the assembler would only
1482 benefit hand written assembly code, and does not seem worth
1485 /* This is how a NOP is emitted. */
1486 #define emit_nop() \
1488 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1489 : md_number_to_chars (frag_more (4), 0, 4))
1491 /* The previous insn might require a delay slot, depending upon
1492 the contents of the current insn. */
1493 if (! mips_opts.mips16
1494 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1495 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1496 && ! cop_interlocks)
1497 || (! gpr_interlocks
1498 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1500 /* A load from a coprocessor or from memory. All load
1501 delays delay the use of general register rt for one
1502 instruction on the r3000. The r6000 and r4000 use
1504 /* Itbl support may require additional care here. */
1505 know (prev_pinfo & INSN_WRITE_GPR_T);
1506 if (mips_optimize == 0
1507 || insn_uses_reg (ip,
1508 ((prev_insn.insn_opcode >> OP_SH_RT)
1513 else if (! mips_opts.mips16
1514 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1515 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1516 && ! cop_interlocks)
1517 || (mips_opts.isa == 1
1518 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1520 /* A generic coprocessor delay. The previous instruction
1521 modified a coprocessor general or control register. If
1522 it modified a control register, we need to avoid any
1523 coprocessor instruction (this is probably not always
1524 required, but it sometimes is). If it modified a general
1525 register, we avoid using that register.
1527 On the r6000 and r4000 loading a coprocessor register
1528 from memory is interlocked, and does not require a delay.
1530 This case is not handled very well. There is no special
1531 knowledge of CP0 handling, and the coprocessors other
1532 than the floating point unit are not distinguished at
1534 /* Itbl support may require additional care here. FIXME!
1535 Need to modify this to include knowledge about
1536 user specified delays! */
1537 if (prev_pinfo & INSN_WRITE_FPR_T)
1539 if (mips_optimize == 0
1540 || insn_uses_reg (ip,
1541 ((prev_insn.insn_opcode >> OP_SH_FT)
1546 else if (prev_pinfo & INSN_WRITE_FPR_S)
1548 if (mips_optimize == 0
1549 || insn_uses_reg (ip,
1550 ((prev_insn.insn_opcode >> OP_SH_FS)
1557 /* We don't know exactly what the previous instruction
1558 does. If the current instruction uses a coprocessor
1559 register, we must insert a NOP. If previous
1560 instruction may set the condition codes, and the
1561 current instruction uses them, we must insert two
1563 /* Itbl support may require additional care here. */
1564 if (mips_optimize == 0
1565 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1566 && (pinfo & INSN_READ_COND_CODE)))
1568 else if (pinfo & INSN_COP)
1572 else if (! mips_opts.mips16
1573 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1574 && (prev_pinfo & INSN_WRITE_COND_CODE)
1575 && ! cop_interlocks)
1577 /* The previous instruction sets the coprocessor condition
1578 codes, but does not require a general coprocessor delay
1579 (this means it is a floating point comparison
1580 instruction). If this instruction uses the condition
1581 codes, we need to insert a single NOP. */
1582 /* Itbl support may require additional care here. */
1583 if (mips_optimize == 0
1584 || (pinfo & INSN_READ_COND_CODE))
1588 /* If we're fixing up mfhi/mflo for the r7000 and the
1589 previous insn was an mfhi/mflo and the current insn
1590 reads the register that the mfhi/mflo wrote to, then
1593 else if (mips_7000_hilo_fix
1594 && MF_HILO_INSN (prev_pinfo)
1595 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1603 /* If we're fixing up mfhi/mflo for the r7000 and the
1604 2nd previous insn was an mfhi/mflo and the current insn
1605 reads the register that the mfhi/mflo wrote to, then
1608 else if (mips_7000_hilo_fix
1609 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1610 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1618 else if (prev_pinfo & INSN_READ_LO)
1620 /* The previous instruction reads the LO register; if the
1621 current instruction writes to the LO register, we must
1622 insert two NOPS. Some newer processors have interlocks.
1623 Also the tx39's multiply instructions can be exectuted
1624 immediatly after a read from HI/LO (without the delay),
1625 though the tx39's divide insns still do require the
1627 if (! (hilo_interlocks
1628 || (mips_cpu == 3900 && (pinfo & INSN_MULT)))
1629 && (mips_optimize == 0
1630 || (pinfo & INSN_WRITE_LO)))
1632 /* Most mips16 branch insns don't have a delay slot.
1633 If a read from LO is immediately followed by a branch
1634 to a write to LO we have a read followed by a write
1635 less than 2 insns away. We assume the target of
1636 a branch might be a write to LO, and insert a nop
1637 between a read and an immediately following branch. */
1638 else if (mips_opts.mips16
1639 && (mips_optimize == 0
1640 || (pinfo & MIPS16_INSN_BRANCH)))
1643 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1645 /* The previous instruction reads the HI register; if the
1646 current instruction writes to the HI register, we must
1647 insert a NOP. Some newer processors have interlocks.
1648 Also the note tx39's multiply above. */
1649 if (! (hilo_interlocks
1650 || (mips_cpu == 3900 && (pinfo & INSN_MULT)))
1651 && (mips_optimize == 0
1652 || (pinfo & INSN_WRITE_HI)))
1654 /* Most mips16 branch insns don't have a delay slot.
1655 If a read from HI is immediately followed by a branch
1656 to a write to HI we have a read followed by a write
1657 less than 2 insns away. We assume the target of
1658 a branch might be a write to HI, and insert a nop
1659 between a read and an immediately following branch. */
1660 else if (mips_opts.mips16
1661 && (mips_optimize == 0
1662 || (pinfo & MIPS16_INSN_BRANCH)))
1666 /* If the previous instruction was in a noreorder section, then
1667 we don't want to insert the nop after all. */
1668 /* Itbl support may require additional care here. */
1669 if (prev_insn_unreordered)
1672 /* There are two cases which require two intervening
1673 instructions: 1) setting the condition codes using a move to
1674 coprocessor instruction which requires a general coprocessor
1675 delay and then reading the condition codes 2) reading the HI
1676 or LO register and then writing to it (except on processors
1677 which have interlocks). If we are not already emitting a NOP
1678 instruction, we must check for these cases compared to the
1679 instruction previous to the previous instruction. */
1680 if ((! mips_opts.mips16
1681 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1682 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1683 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1684 && (pinfo & INSN_READ_COND_CODE)
1685 && ! cop_interlocks)
1686 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1687 && (pinfo & INSN_WRITE_LO)
1688 && ! (hilo_interlocks
1689 || (mips_cpu == 3900 && (pinfo & INSN_MULT))))
1690 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1691 && (pinfo & INSN_WRITE_HI)
1692 && ! (hilo_interlocks
1693 || (mips_cpu == 3900 && (pinfo & INSN_MULT)))))
1698 if (prev_prev_insn_unreordered)
1701 if (prev_prev_nop && nops == 0)
1704 /* If we are being given a nop instruction, don't bother with
1705 one of the nops we would otherwise output. This will only
1706 happen when a nop instruction is used with mips_optimize set
1709 && ! mips_opts.noreorder
1710 && ip->insn_opcode == (mips_opts.mips16 ? 0x6500 : 0))
1713 /* Now emit the right number of NOP instructions. */
1714 if (nops > 0 && ! mips_opts.noreorder)
1717 unsigned long old_frag_offset;
1719 struct insn_label_list *l;
1721 old_frag = frag_now;
1722 old_frag_offset = frag_now_fix ();
1724 for (i = 0; i < nops; i++)
1729 listing_prev_line ();
1730 /* We may be at the start of a variant frag. In case we
1731 are, make sure there is enough space for the frag
1732 after the frags created by listing_prev_line. The
1733 argument to frag_grow here must be at least as large
1734 as the argument to all other calls to frag_grow in
1735 this file. We don't have to worry about being in the
1736 middle of a variant frag, because the variants insert
1737 all needed nop instructions themselves. */
1741 for (l = insn_labels; l != NULL; l = l->next)
1743 assert (S_GET_SEGMENT (l->label) == now_seg);
1744 symbol_set_frag (l->label, frag_now);
1745 S_SET_VALUE (l->label, (valueT) frag_now_fix ());
1746 /* mips16 text labels are stored as odd. */
1747 if (mips_opts.mips16)
1748 S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1);
1751 #ifndef NO_ECOFF_DEBUGGING
1752 if (ECOFF_DEBUGGING)
1753 ecoff_fix_loc (old_frag, old_frag_offset);
1756 else if (prev_nop_frag != NULL)
1758 /* We have a frag holding nops we may be able to remove. If
1759 we don't need any nops, we can decrease the size of
1760 prev_nop_frag by the size of one instruction. If we do
1761 need some nops, we count them in prev_nops_required. */
1762 if (prev_nop_frag_since == 0)
1766 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1767 --prev_nop_frag_holds;
1770 prev_nop_frag_required += nops;
1774 if (prev_prev_nop == 0)
1776 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1777 --prev_nop_frag_holds;
1780 ++prev_nop_frag_required;
1783 if (prev_nop_frag_holds <= prev_nop_frag_required)
1784 prev_nop_frag = NULL;
1786 ++prev_nop_frag_since;
1788 /* Sanity check: by the time we reach the second instruction
1789 after prev_nop_frag, we should have used up all the nops
1790 one way or another. */
1791 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1795 if (reloc_type > BFD_RELOC_UNUSED)
1797 /* We need to set up a variant frag. */
1798 assert (mips_opts.mips16 && address_expr != NULL);
1799 f = frag_var (rs_machine_dependent, 4, 0,
1800 RELAX_MIPS16_ENCODE (reloc_type - BFD_RELOC_UNUSED,
1801 mips16_small, mips16_ext,
1803 & INSN_UNCOND_BRANCH_DELAY),
1804 (prev_insn_reloc_type
1805 == BFD_RELOC_MIPS16_JMP)),
1806 make_expr_symbol (address_expr), (offsetT) 0,
1809 else if (place != NULL)
1811 else if (mips_opts.mips16
1813 && reloc_type != BFD_RELOC_MIPS16_JMP)
1815 /* Make sure there is enough room to swap this instruction with
1816 a following jump instruction. */
1822 if (mips_opts.mips16
1823 && mips_opts.noreorder
1824 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1825 as_warn (_("extended instruction in delay slot"));
1831 if (address_expr != NULL && reloc_type < BFD_RELOC_UNUSED)
1833 if (address_expr->X_op == O_constant)
1838 ip->insn_opcode |= address_expr->X_add_number;
1841 case BFD_RELOC_LO16:
1842 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1845 case BFD_RELOC_MIPS_JMP:
1846 if ((address_expr->X_add_number & 3) != 0)
1847 as_bad (_("jump to misaligned address (0x%lx)"),
1848 (unsigned long) address_expr->X_add_number);
1849 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
1852 case BFD_RELOC_MIPS16_JMP:
1853 if ((address_expr->X_add_number & 3) != 0)
1854 as_bad (_("jump to misaligned address (0x%lx)"),
1855 (unsigned long) address_expr->X_add_number);
1857 (((address_expr->X_add_number & 0x7c0000) << 3)
1858 | ((address_expr->X_add_number & 0xf800000) >> 7)
1859 | ((address_expr->X_add_number & 0x3fffc) >> 2));
1862 case BFD_RELOC_16_PCREL_S2:
1872 /* Don't generate a reloc if we are writing into a variant
1876 fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1878 reloc_type == BFD_RELOC_16_PCREL_S2,
1882 struct mips_hi_fixup *hi_fixup;
1884 assert (reloc_type == BFD_RELOC_HI16_S);
1885 hi_fixup = ((struct mips_hi_fixup *)
1886 xmalloc (sizeof (struct mips_hi_fixup)));
1887 hi_fixup->fixp = fixp;
1888 hi_fixup->seg = now_seg;
1889 hi_fixup->next = mips_hi_fixup_list;
1890 mips_hi_fixup_list = hi_fixup;
1896 if (! mips_opts.mips16)
1897 md_number_to_chars (f, ip->insn_opcode, 4);
1898 else if (reloc_type == BFD_RELOC_MIPS16_JMP)
1900 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
1901 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
1907 md_number_to_chars (f, 0xf000 | ip->extend, 2);
1910 md_number_to_chars (f, ip->insn_opcode, 2);
1913 /* Update the register mask information. */
1914 if (! mips_opts.mips16)
1916 if (pinfo & INSN_WRITE_GPR_D)
1917 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
1918 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
1919 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
1920 if (pinfo & INSN_READ_GPR_S)
1921 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
1922 if (pinfo & INSN_WRITE_GPR_31)
1923 mips_gprmask |= 1 << 31;
1924 if (pinfo & INSN_WRITE_FPR_D)
1925 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
1926 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
1927 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
1928 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
1929 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
1930 if ((pinfo & INSN_READ_FPR_R) != 0)
1931 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
1932 if (pinfo & INSN_COP)
1934 /* We don't keep enough information to sort these cases out.
1935 The itbl support does keep this information however, although
1936 we currently don't support itbl fprmats as part of the cop
1937 instruction. May want to add this support in the future. */
1939 /* Never set the bit for $0, which is always zero. */
1940 mips_gprmask &=~ 1 << 0;
1944 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
1945 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
1946 & MIPS16OP_MASK_RX);
1947 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
1948 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
1949 & MIPS16OP_MASK_RY);
1950 if (pinfo & MIPS16_INSN_WRITE_Z)
1951 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
1952 & MIPS16OP_MASK_RZ);
1953 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
1954 mips_gprmask |= 1 << TREG;
1955 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
1956 mips_gprmask |= 1 << SP;
1957 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
1958 mips_gprmask |= 1 << RA;
1959 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
1960 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
1961 if (pinfo & MIPS16_INSN_READ_Z)
1962 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1963 & MIPS16OP_MASK_MOVE32Z);
1964 if (pinfo & MIPS16_INSN_READ_GPR_X)
1965 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1966 & MIPS16OP_MASK_REGR32);
1969 if (place == NULL && ! mips_opts.noreorder)
1971 /* Filling the branch delay slot is more complex. We try to
1972 switch the branch with the previous instruction, which we can
1973 do if the previous instruction does not set up a condition
1974 that the branch tests and if the branch is not itself the
1975 target of any branch. */
1976 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
1977 || (pinfo & INSN_COND_BRANCH_DELAY))
1979 if (mips_optimize < 2
1980 /* If we have seen .set volatile or .set nomove, don't
1982 || mips_opts.nomove != 0
1983 /* If we had to emit any NOP instructions, then we
1984 already know we can not swap. */
1986 /* If we don't even know the previous insn, we can not
1988 || ! prev_insn_valid
1989 /* If the previous insn is already in a branch delay
1990 slot, then we can not swap. */
1991 || prev_insn_is_delay_slot
1992 /* If the previous previous insn was in a .set
1993 noreorder, we can't swap. Actually, the MIPS
1994 assembler will swap in this situation. However, gcc
1995 configured -with-gnu-as will generate code like
2001 in which we can not swap the bne and INSN. If gcc is
2002 not configured -with-gnu-as, it does not output the
2003 .set pseudo-ops. We don't have to check
2004 prev_insn_unreordered, because prev_insn_valid will
2005 be 0 in that case. We don't want to use
2006 prev_prev_insn_valid, because we do want to be able
2007 to swap at the start of a function. */
2008 || prev_prev_insn_unreordered
2009 /* If the branch is itself the target of a branch, we
2010 can not swap. We cheat on this; all we check for is
2011 whether there is a label on this instruction. If
2012 there are any branches to anything other than a
2013 label, users must use .set noreorder. */
2014 || insn_labels != NULL
2015 /* If the previous instruction is in a variant frag, we
2016 can not do the swap. This does not apply to the
2017 mips16, which uses variant frags for different
2019 || (! mips_opts.mips16
2020 && prev_insn_frag->fr_type == rs_machine_dependent)
2021 /* If the branch reads the condition codes, we don't
2022 even try to swap, because in the sequence
2027 we can not swap, and I don't feel like handling that
2029 || (! mips_opts.mips16
2030 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2031 && (pinfo & INSN_READ_COND_CODE))
2032 /* We can not swap with an instruction that requires a
2033 delay slot, becase the target of the branch might
2034 interfere with that instruction. */
2035 || (! mips_opts.mips16
2036 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2038 /* Itbl support may require additional care here. */
2039 & (INSN_LOAD_COPROC_DELAY
2040 | INSN_COPROC_MOVE_DELAY
2041 | INSN_WRITE_COND_CODE)))
2042 || (! (hilo_interlocks
2043 || (mips_cpu == 3900 && (pinfo & INSN_MULT)))
2047 || (! mips_opts.mips16
2049 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2050 || (! mips_opts.mips16
2051 && mips_opts.isa == 1
2052 /* Itbl support may require additional care here. */
2053 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2054 /* We can not swap with a branch instruction. */
2056 & (INSN_UNCOND_BRANCH_DELAY
2057 | INSN_COND_BRANCH_DELAY
2058 | INSN_COND_BRANCH_LIKELY))
2059 /* We do not swap with a trap instruction, since it
2060 complicates trap handlers to have the trap
2061 instruction be in a delay slot. */
2062 || (prev_pinfo & INSN_TRAP)
2063 /* If the branch reads a register that the previous
2064 instruction sets, we can not swap. */
2065 || (! mips_opts.mips16
2066 && (prev_pinfo & INSN_WRITE_GPR_T)
2067 && insn_uses_reg (ip,
2068 ((prev_insn.insn_opcode >> OP_SH_RT)
2071 || (! mips_opts.mips16
2072 && (prev_pinfo & INSN_WRITE_GPR_D)
2073 && insn_uses_reg (ip,
2074 ((prev_insn.insn_opcode >> OP_SH_RD)
2077 || (mips_opts.mips16
2078 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2079 && insn_uses_reg (ip,
2080 ((prev_insn.insn_opcode
2082 & MIPS16OP_MASK_RX),
2084 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2085 && insn_uses_reg (ip,
2086 ((prev_insn.insn_opcode
2088 & MIPS16OP_MASK_RY),
2090 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2091 && insn_uses_reg (ip,
2092 ((prev_insn.insn_opcode
2094 & MIPS16OP_MASK_RZ),
2096 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2097 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2098 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2099 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2100 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2101 && insn_uses_reg (ip,
2102 MIPS16OP_EXTRACT_REG32R (prev_insn.
2105 /* If the branch writes a register that the previous
2106 instruction sets, we can not swap (we know that
2107 branches write only to RD or to $31). */
2108 || (! mips_opts.mips16
2109 && (prev_pinfo & INSN_WRITE_GPR_T)
2110 && (((pinfo & INSN_WRITE_GPR_D)
2111 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2112 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2113 || ((pinfo & INSN_WRITE_GPR_31)
2114 && (((prev_insn.insn_opcode >> OP_SH_RT)
2117 || (! mips_opts.mips16
2118 && (prev_pinfo & INSN_WRITE_GPR_D)
2119 && (((pinfo & INSN_WRITE_GPR_D)
2120 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2121 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2122 || ((pinfo & INSN_WRITE_GPR_31)
2123 && (((prev_insn.insn_opcode >> OP_SH_RD)
2126 || (mips_opts.mips16
2127 && (pinfo & MIPS16_INSN_WRITE_31)
2128 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2129 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2130 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2132 /* If the branch writes a register that the previous
2133 instruction reads, we can not swap (we know that
2134 branches only write to RD or to $31). */
2135 || (! mips_opts.mips16
2136 && (pinfo & INSN_WRITE_GPR_D)
2137 && insn_uses_reg (&prev_insn,
2138 ((ip->insn_opcode >> OP_SH_RD)
2141 || (! mips_opts.mips16
2142 && (pinfo & INSN_WRITE_GPR_31)
2143 && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG))
2144 || (mips_opts.mips16
2145 && (pinfo & MIPS16_INSN_WRITE_31)
2146 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2147 /* If we are generating embedded PIC code, the branch
2148 might be expanded into a sequence which uses $at, so
2149 we can't swap with an instruction which reads it. */
2150 || (mips_pic == EMBEDDED_PIC
2151 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2152 /* If the previous previous instruction has a load
2153 delay, and sets a register that the branch reads, we
2155 || (! mips_opts.mips16
2156 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2157 /* Itbl support may require additional care here. */
2158 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2159 || (! gpr_interlocks
2160 && (prev_prev_insn.insn_mo->pinfo
2161 & INSN_LOAD_MEMORY_DELAY)))
2162 && insn_uses_reg (ip,
2163 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2166 /* If one instruction sets a condition code and the
2167 other one uses a condition code, we can not swap. */
2168 || ((pinfo & INSN_READ_COND_CODE)
2169 && (prev_pinfo & INSN_WRITE_COND_CODE))
2170 || ((pinfo & INSN_WRITE_COND_CODE)
2171 && (prev_pinfo & INSN_READ_COND_CODE))
2172 /* If the previous instruction uses the PC, we can not
2174 || (mips_opts.mips16
2175 && (prev_pinfo & MIPS16_INSN_READ_PC))
2176 /* If the previous instruction was extended, we can not
2178 || (mips_opts.mips16 && prev_insn_extended)
2179 /* If the previous instruction had a fixup in mips16
2180 mode, we can not swap. This normally means that the
2181 previous instruction was a 4 byte branch anyhow. */
2182 || (mips_opts.mips16 && prev_insn_fixp)
2183 /* If the previous instruction is a sync, sync.l, or
2184 sync.p, we can not swap. */
2185 || (prev_pinfo & INSN_SYNC))
2187 /* We could do even better for unconditional branches to
2188 portions of this object file; we could pick up the
2189 instruction at the destination, put it in the delay
2190 slot, and bump the destination address. */
2192 /* Update the previous insn information. */
2193 prev_prev_insn = *ip;
2194 prev_insn.insn_mo = &dummy_opcode;
2198 /* It looks like we can actually do the swap. */
2199 if (! mips_opts.mips16)
2204 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2205 memcpy (temp, prev_f, 4);
2206 memcpy (prev_f, f, 4);
2207 memcpy (f, temp, 4);
2210 prev_insn_fixp->fx_frag = frag_now;
2211 prev_insn_fixp->fx_where = f - frag_now->fr_literal;
2215 fixp->fx_frag = prev_insn_frag;
2216 fixp->fx_where = prev_insn_where;
2224 assert (prev_insn_fixp == NULL);
2225 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2226 memcpy (temp, prev_f, 2);
2227 memcpy (prev_f, f, 2);
2228 if (reloc_type != BFD_RELOC_MIPS16_JMP)
2230 assert (reloc_type == BFD_RELOC_UNUSED);
2231 memcpy (f, temp, 2);
2235 memcpy (f, f + 2, 2);
2236 memcpy (f + 2, temp, 2);
2240 fixp->fx_frag = prev_insn_frag;
2241 fixp->fx_where = prev_insn_where;
2245 /* Update the previous insn information; leave prev_insn
2247 prev_prev_insn = *ip;
2249 prev_insn_is_delay_slot = 1;
2251 /* If that was an unconditional branch, forget the previous
2252 insn information. */
2253 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2255 prev_prev_insn.insn_mo = &dummy_opcode;
2256 prev_insn.insn_mo = &dummy_opcode;
2259 prev_insn_fixp = NULL;
2260 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2261 prev_insn_extended = 0;
2263 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2265 /* We don't yet optimize a branch likely. What we should do
2266 is look at the target, copy the instruction found there
2267 into the delay slot, and increment the branch to jump to
2268 the next instruction. */
2270 /* Update the previous insn information. */
2271 prev_prev_insn = *ip;
2272 prev_insn.insn_mo = &dummy_opcode;
2273 prev_insn_fixp = NULL;
2274 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2275 prev_insn_extended = 0;
2279 /* Update the previous insn information. */
2281 prev_prev_insn.insn_mo = &dummy_opcode;
2283 prev_prev_insn = prev_insn;
2286 /* Any time we see a branch, we always fill the delay slot
2287 immediately; since this insn is not a branch, we know it
2288 is not in a delay slot. */
2289 prev_insn_is_delay_slot = 0;
2291 prev_insn_fixp = fixp;
2292 prev_insn_reloc_type = reloc_type;
2293 if (mips_opts.mips16)
2294 prev_insn_extended = (ip->use_extend
2295 || reloc_type > BFD_RELOC_UNUSED);
2298 prev_prev_insn_unreordered = prev_insn_unreordered;
2299 prev_insn_unreordered = 0;
2300 prev_insn_frag = frag_now;
2301 prev_insn_where = f - frag_now->fr_literal;
2302 prev_insn_valid = 1;
2304 else if (place == NULL)
2306 /* We need to record a bit of information even when we are not
2307 reordering, in order to determine the base address for mips16
2308 PC relative relocs. */
2309 prev_prev_insn = prev_insn;
2311 prev_insn_reloc_type = reloc_type;
2312 prev_prev_insn_unreordered = prev_insn_unreordered;
2313 prev_insn_unreordered = 1;
2316 /* We just output an insn, so the next one doesn't have a label. */
2317 mips_clear_insn_labels ();
2319 /* We must ensure that a fixup associated with an unmatched %hi
2320 reloc does not become a variant frag. Otherwise, the
2321 rearrangement of %hi relocs in frob_file may confuse
2325 frag_wane (frag_now);
2330 /* This function forgets that there was any previous instruction or
2331 label. If PRESERVE is non-zero, it remembers enough information to
2332 know whether nops are needed before a noreorder section. */
2335 mips_no_prev_insn (preserve)
2340 prev_insn.insn_mo = &dummy_opcode;
2341 prev_prev_insn.insn_mo = &dummy_opcode;
2342 prev_nop_frag = NULL;
2343 prev_nop_frag_holds = 0;
2344 prev_nop_frag_required = 0;
2345 prev_nop_frag_since = 0;
2347 prev_insn_valid = 0;
2348 prev_insn_is_delay_slot = 0;
2349 prev_insn_unreordered = 0;
2350 prev_insn_extended = 0;
2351 prev_insn_reloc_type = BFD_RELOC_UNUSED;
2352 prev_prev_insn_unreordered = 0;
2353 mips_clear_insn_labels ();
2356 /* This function must be called whenever we turn on noreorder or emit
2357 something other than instructions. It inserts any NOPS which might
2358 be needed by the previous instruction, and clears the information
2359 kept for the previous instructions. The INSNS parameter is true if
2360 instructions are to follow. */
2363 mips_emit_delays (insns)
2366 if (! mips_opts.noreorder)
2371 if ((! mips_opts.mips16
2372 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2373 && (! cop_interlocks
2374 && (prev_insn.insn_mo->pinfo
2375 & (INSN_LOAD_COPROC_DELAY
2376 | INSN_COPROC_MOVE_DELAY
2377 | INSN_WRITE_COND_CODE))))
2378 || (! hilo_interlocks
2379 && (prev_insn.insn_mo->pinfo
2382 || (! mips_opts.mips16
2384 && (prev_insn.insn_mo->pinfo
2385 & INSN_LOAD_MEMORY_DELAY))
2386 || (! mips_opts.mips16
2387 && mips_opts.isa == 1
2388 && (prev_insn.insn_mo->pinfo
2389 & INSN_COPROC_MEMORY_DELAY)))
2391 /* Itbl support may require additional care here. */
2393 if ((! mips_opts.mips16
2394 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2395 && (! cop_interlocks
2396 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2397 || (! hilo_interlocks
2398 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2399 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2402 if (prev_insn_unreordered)
2405 else if ((! mips_opts.mips16
2406 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2407 && (! cop_interlocks
2408 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2409 || (! hilo_interlocks
2410 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2411 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2413 /* Itbl support may require additional care here. */
2414 if (! prev_prev_insn_unreordered)
2420 struct insn_label_list *l;
2424 /* Record the frag which holds the nop instructions, so
2425 that we can remove them if we don't need them. */
2426 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2427 prev_nop_frag = frag_now;
2428 prev_nop_frag_holds = nops;
2429 prev_nop_frag_required = 0;
2430 prev_nop_frag_since = 0;
2433 for (; nops > 0; --nops)
2438 /* Move on to a new frag, so that it is safe to simply
2439 decrease the size of prev_nop_frag. */
2440 frag_wane (frag_now);
2444 for (l = insn_labels; l != NULL; l = l->next)
2446 assert (S_GET_SEGMENT (l->label) == now_seg);
2447 symbol_set_frag (l->label, frag_now);
2448 S_SET_VALUE (l->label, (valueT) frag_now_fix ());
2449 /* mips16 text labels are stored as odd. */
2450 if (mips_opts.mips16)
2451 S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1);
2456 /* Mark instruction labels in mips16 mode. */
2457 if (mips_opts.mips16 && insns)
2458 mips16_mark_labels ();
2460 mips_no_prev_insn (insns);
2463 /* Build an instruction created by a macro expansion. This is passed
2464 a pointer to the count of instructions created so far, an
2465 expression, the name of the instruction to build, an operand format
2466 string, and corresponding arguments. */
2470 macro_build (char *place,
2478 macro_build (place, counter, ep, name, fmt, va_alist)
2487 struct mips_cl_insn insn;
2488 bfd_reloc_code_real_type r;
2492 va_start (args, fmt);
2498 * If the macro is about to expand into a second instruction,
2499 * print a warning if needed. We need to pass ip as a parameter
2500 * to generate a better warning message here...
2502 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2503 as_warn (_("Macro instruction expanded into multiple instructions"));
2506 *counter += 1; /* bump instruction counter */
2508 if (mips_opts.mips16)
2510 mips16_macro_build (place, counter, ep, name, fmt, args);
2515 r = BFD_RELOC_UNUSED;
2516 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2517 assert (insn.insn_mo);
2518 assert (strcmp (name, insn.insn_mo->name) == 0);
2520 /* Search until we get a match for NAME. */
2523 if (strcmp (fmt, insn.insn_mo->args) == 0
2524 && insn.insn_mo->pinfo != INSN_MACRO
2525 && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_cpu,
2527 && (mips_cpu != 4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2531 assert (insn.insn_mo->name);
2532 assert (strcmp (name, insn.insn_mo->name) == 0);
2535 insn.insn_opcode = insn.insn_mo->match;
2551 insn.insn_opcode |= va_arg (args, int) << 16;
2557 insn.insn_opcode |= va_arg (args, int) << 16;
2562 insn.insn_opcode |= va_arg (args, int) << 11;
2567 insn.insn_opcode |= va_arg (args, int) << 11;
2574 insn.insn_opcode |= va_arg (args, int) << 6;
2578 insn.insn_opcode |= va_arg (args, int) << 6;
2582 insn.insn_opcode |= va_arg (args, int) << 6;
2586 insn.insn_opcode |= va_arg (args, int) << 6;
2593 insn.insn_opcode |= va_arg (args, int) << 21;
2599 r = (bfd_reloc_code_real_type) va_arg (args, int);
2600 assert (r == BFD_RELOC_MIPS_GPREL
2601 || r == BFD_RELOC_MIPS_LITERAL
2602 || r == BFD_RELOC_LO16
2603 || r == BFD_RELOC_MIPS_GOT16
2604 || r == BFD_RELOC_MIPS_CALL16
2605 || r == BFD_RELOC_MIPS_GOT_LO16
2606 || r == BFD_RELOC_MIPS_CALL_LO16
2607 || (ep->X_op == O_subtract
2608 && r == BFD_RELOC_PCREL_LO16));
2612 r = (bfd_reloc_code_real_type) va_arg (args, int);
2614 && (ep->X_op == O_constant
2615 || (ep->X_op == O_symbol
2616 && (r == BFD_RELOC_HI16_S
2617 || r == BFD_RELOC_HI16
2618 || r == BFD_RELOC_MIPS_GOT_HI16
2619 || r == BFD_RELOC_MIPS_CALL_HI16))
2620 || (ep->X_op == O_subtract
2621 && r == BFD_RELOC_PCREL_HI16_S)));
2622 if (ep->X_op == O_constant)
2624 insn.insn_opcode |= (ep->X_add_number >> 16) & 0xffff;
2626 r = BFD_RELOC_UNUSED;
2631 assert (ep != NULL);
2633 * This allows macro() to pass an immediate expression for
2634 * creating short branches without creating a symbol.
2635 * Note that the expression still might come from the assembly
2636 * input, in which case the value is not checked for range nor
2637 * is a relocation entry generated (yuck).
2639 if (ep->X_op == O_constant)
2641 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
2645 r = BFD_RELOC_16_PCREL_S2;
2649 assert (ep != NULL);
2650 r = BFD_RELOC_MIPS_JMP;
2654 insn.insn_opcode |= va_arg (args, unsigned long);
2663 assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2665 append_insn (place, &insn, ep, r, false);
2669 mips16_macro_build (place, counter, ep, name, fmt, args)
2671 int *counter ATTRIBUTE_UNUSED;
2677 struct mips_cl_insn insn;
2678 bfd_reloc_code_real_type r;
2680 r = BFD_RELOC_UNUSED;
2681 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
2682 assert (insn.insn_mo);
2683 assert (strcmp (name, insn.insn_mo->name) == 0);
2685 while (strcmp (fmt, insn.insn_mo->args) != 0
2686 || insn.insn_mo->pinfo == INSN_MACRO)
2689 assert (insn.insn_mo->name);
2690 assert (strcmp (name, insn.insn_mo->name) == 0);
2693 insn.insn_opcode = insn.insn_mo->match;
2694 insn.use_extend = false;
2713 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
2718 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
2722 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
2726 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
2736 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
2743 regno = va_arg (args, int);
2744 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
2745 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
2766 assert (ep != NULL);
2768 if (ep->X_op != O_constant)
2769 r = BFD_RELOC_UNUSED + c;
2772 mips16_immed ((char *) NULL, 0, c, ep->X_add_number, false,
2773 false, false, &insn.insn_opcode,
2774 &insn.use_extend, &insn.extend);
2776 r = BFD_RELOC_UNUSED;
2782 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
2789 assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2791 append_insn (place, &insn, ep, r, false);
2795 * Generate a "lui" instruction.
2798 macro_build_lui (place, counter, ep, regnum)
2804 expressionS high_expr;
2805 struct mips_cl_insn insn;
2806 bfd_reloc_code_real_type r;
2807 CONST char *name = "lui";
2808 CONST char *fmt = "t,u";
2810 assert (! mips_opts.mips16);
2816 high_expr.X_op = O_constant;
2817 high_expr.X_add_number = ep->X_add_number;
2820 if (high_expr.X_op == O_constant)
2822 /* we can compute the instruction now without a relocation entry */
2823 if (high_expr.X_add_number & 0x8000)
2824 high_expr.X_add_number += 0x10000;
2825 high_expr.X_add_number =
2826 ((unsigned long) high_expr.X_add_number >> 16) & 0xffff;
2827 r = BFD_RELOC_UNUSED;
2831 assert (ep->X_op == O_symbol);
2832 /* _gp_disp is a special case, used from s_cpload. */
2833 assert (mips_pic == NO_PIC
2834 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
2835 r = BFD_RELOC_HI16_S;
2839 * If the macro is about to expand into a second instruction,
2840 * print a warning if needed. We need to pass ip as a parameter
2841 * to generate a better warning message here...
2843 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2844 as_warn (_("Macro instruction expanded into multiple instructions"));
2847 *counter += 1; /* bump instruction counter */
2849 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2850 assert (insn.insn_mo);
2851 assert (strcmp (name, insn.insn_mo->name) == 0);
2852 assert (strcmp (fmt, insn.insn_mo->args) == 0);
2854 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
2855 if (r == BFD_RELOC_UNUSED)
2857 insn.insn_opcode |= high_expr.X_add_number;
2858 append_insn (place, &insn, NULL, r, false);
2861 append_insn (place, &insn, &high_expr, r, false);
2865 * Generates code to set the $at register to true (one)
2866 * if reg is less than the immediate expression.
2869 set_at (counter, reg, unsignedp)
2874 if (imm_expr.X_op == O_constant
2875 && imm_expr.X_add_number >= -0x8000
2876 && imm_expr.X_add_number < 0x8000)
2877 macro_build ((char *) NULL, counter, &imm_expr,
2878 unsignedp ? "sltiu" : "slti",
2879 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
2882 load_register (counter, AT, &imm_expr, 0);
2883 macro_build ((char *) NULL, counter, NULL,
2884 unsignedp ? "sltu" : "slt",
2885 "d,v,t", AT, reg, AT);
2889 /* Warn if an expression is not a constant. */
2892 check_absolute_expr (ip, ex)
2893 struct mips_cl_insn *ip;
2896 if (ex->X_op == O_big)
2897 as_bad (_("unsupported large constant"));
2898 else if (ex->X_op != O_constant)
2899 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
2902 /* Count the leading zeroes by performing a binary chop. This is a
2903 bulky bit of source, but performance is a LOT better for the
2904 majority of values than a simple loop to count the bits:
2905 for (lcnt = 0; (lcnt < 32); lcnt++)
2906 if ((v) & (1 << (31 - lcnt)))
2908 However it is not code size friendly, and the gain will drop a bit
2909 on certain cached systems.
2911 #define COUNT_TOP_ZEROES(v) \
2912 (((v) & ~0xffff) == 0 \
2913 ? ((v) & ~0xff) == 0 \
2914 ? ((v) & ~0xf) == 0 \
2915 ? ((v) & ~0x3) == 0 \
2916 ? ((v) & ~0x1) == 0 \
2921 : ((v) & ~0x7) == 0 \
2924 : ((v) & ~0x3f) == 0 \
2925 ? ((v) & ~0x1f) == 0 \
2928 : ((v) & ~0x7f) == 0 \
2931 : ((v) & ~0xfff) == 0 \
2932 ? ((v) & ~0x3ff) == 0 \
2933 ? ((v) & ~0x1ff) == 0 \
2936 : ((v) & ~0x7ff) == 0 \
2939 : ((v) & ~0x3fff) == 0 \
2940 ? ((v) & ~0x1fff) == 0 \
2943 : ((v) & ~0x7fff) == 0 \
2946 : ((v) & ~0xffffff) == 0 \
2947 ? ((v) & ~0xfffff) == 0 \
2948 ? ((v) & ~0x3ffff) == 0 \
2949 ? ((v) & ~0x1ffff) == 0 \
2952 : ((v) & ~0x7ffff) == 0 \
2955 : ((v) & ~0x3fffff) == 0 \
2956 ? ((v) & ~0x1fffff) == 0 \
2959 : ((v) & ~0x7fffff) == 0 \
2962 : ((v) & ~0xfffffff) == 0 \
2963 ? ((v) & ~0x3ffffff) == 0 \
2964 ? ((v) & ~0x1ffffff) == 0 \
2967 : ((v) & ~0x7ffffff) == 0 \
2970 : ((v) & ~0x3fffffff) == 0 \
2971 ? ((v) & ~0x1fffffff) == 0 \
2974 : ((v) & ~0x7fffffff) == 0 \
2979 * This routine generates the least number of instructions neccessary to load
2980 * an absolute expression value into a register.
2983 load_register (counter, reg, ep, dbl)
2990 expressionS hi32, lo32;
2992 if (ep->X_op != O_big)
2994 assert (ep->X_op == O_constant);
2995 if (ep->X_add_number < 0x8000
2996 && (ep->X_add_number >= 0
2997 || (ep->X_add_number >= -0x8000
3000 || sizeof (ep->X_add_number) > 4))))
3002 /* We can handle 16 bit signed values with an addiu to
3003 $zero. No need to ever use daddiu here, since $zero and
3004 the result are always correct in 32 bit mode. */
3005 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3006 (int) BFD_RELOC_LO16);
3009 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3011 /* We can handle 16 bit unsigned values with an ori to
3013 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3014 (int) BFD_RELOC_LO16);
3017 else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0
3018 || ((ep->X_add_number &~ (offsetT) 0x7fffffff)
3019 == ~ (offsetT) 0x7fffffff))
3022 || sizeof (ep->X_add_number) > 4
3023 || (ep->X_add_number & 0x80000000) == 0))
3024 || ((! ISA_HAS_64BIT_REGS (mips_opts.isa) || ! dbl)
3025 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3026 || (! ISA_HAS_64BIT_REGS (mips_opts.isa)
3028 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3029 == ~ (offsetT) 0xffffffff)))
3031 /* 32 bit values require an lui. */
3032 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3033 (int) BFD_RELOC_HI16);
3034 if ((ep->X_add_number & 0xffff) != 0)
3035 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3036 (int) BFD_RELOC_LO16);
3041 /* The value is larger than 32 bits. */
3043 if (! ISA_HAS_64BIT_REGS (mips_opts.isa))
3045 as_bad (_("Number larger than 32 bits"));
3046 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3047 (int) BFD_RELOC_LO16);
3051 if (ep->X_op != O_big)
3054 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3055 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3056 hi32.X_add_number &= 0xffffffff;
3058 lo32.X_add_number &= 0xffffffff;
3062 assert (ep->X_add_number > 2);
3063 if (ep->X_add_number == 3)
3064 generic_bignum[3] = 0;
3065 else if (ep->X_add_number > 4)
3066 as_bad (_("Number larger than 64 bits"));
3067 lo32.X_op = O_constant;
3068 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3069 hi32.X_op = O_constant;
3070 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3073 if (hi32.X_add_number == 0)
3078 unsigned long hi, lo;
3080 if (hi32.X_add_number == 0xffffffff)
3082 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3084 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3085 reg, 0, (int) BFD_RELOC_LO16);
3088 if (lo32.X_add_number & 0x80000000)
3090 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3091 (int) BFD_RELOC_HI16);
3092 if (lo32.X_add_number & 0xffff)
3093 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3094 reg, reg, (int) BFD_RELOC_LO16);
3099 /* Check for 16bit shifted constant. We know that hi32 is
3100 non-zero, so start the mask on the first bit of the hi32
3105 unsigned long himask, lomask;
3109 himask = 0xffff >> (32 - shift);
3110 lomask = (0xffff << shift) & 0xffffffff;
3114 himask = 0xffff << (shift - 32);
3117 if ((hi32.X_add_number & ~ (offsetT) himask) == 0
3118 && (lo32.X_add_number & ~ (offsetT) lomask) == 0)
3122 tmp.X_op = O_constant;
3124 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3125 | (lo32.X_add_number >> shift));
3127 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3128 macro_build ((char *) NULL, counter, &tmp, "ori", "t,r,i", reg, 0,
3129 (int) BFD_RELOC_LO16);
3130 macro_build ((char *) NULL, counter, NULL,
3131 (shift >= 32) ? "dsll32" : "dsll",
3133 (shift >= 32) ? shift - 32 : shift);
3137 } while (shift <= (64 - 16));
3139 /* Find the bit number of the lowest one bit, and store the
3140 shifted value in hi/lo. */
3141 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3142 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3146 while ((lo & 1) == 0)
3151 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3157 while ((hi & 1) == 0)
3166 /* Optimize if the shifted value is a (power of 2) - 1. */
3167 if ((hi == 0 && ((lo + 1) & lo) == 0)
3168 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3170 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3175 /* This instruction will set the register to be all
3177 tmp.X_op = O_constant;
3178 tmp.X_add_number = (offsetT) -1;
3179 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3180 reg, 0, (int) BFD_RELOC_LO16);
3184 macro_build ((char *) NULL, counter, NULL,
3185 (bit >= 32) ? "dsll32" : "dsll",
3187 (bit >= 32) ? bit - 32 : bit);
3189 macro_build ((char *) NULL, counter, NULL,
3190 (shift >= 32) ? "dsrl32" : "dsrl",
3192 (shift >= 32) ? shift - 32 : shift);
3197 /* Sign extend hi32 before calling load_register, because we can
3198 generally get better code when we load a sign extended value. */
3199 if ((hi32.X_add_number & 0x80000000) != 0)
3200 hi32.X_add_number |= ~ (offsetT) 0xffffffff;
3201 load_register (counter, reg, &hi32, 0);
3204 if ((lo32.X_add_number & 0xffff0000) == 0)
3208 macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg,
3217 if ((freg == 0) && (lo32.X_add_number == 0xffffffff))
3219 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3220 (int) BFD_RELOC_HI16);
3221 macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg,
3228 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
3233 mid16.X_add_number >>= 16;
3234 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3235 freg, (int) BFD_RELOC_LO16);
3236 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
3240 if ((lo32.X_add_number & 0xffff) != 0)
3241 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3242 (int) BFD_RELOC_LO16);
3245 /* Load an address into a register. */
3248 load_address (counter, reg, ep)
3255 if (ep->X_op != O_constant
3256 && ep->X_op != O_symbol)
3258 as_bad (_("expression too complex"));
3259 ep->X_op = O_constant;
3262 if (ep->X_op == O_constant)
3264 load_register (counter, reg, ep, 0);
3268 if (mips_pic == NO_PIC)
3270 /* If this is a reference to a GP relative symbol, we want
3271 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
3273 lui $reg,<sym> (BFD_RELOC_HI16_S)
3274 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3275 If we have an addend, we always use the latter form. */
3276 if ((valueT) ep->X_add_number >= MAX_GPREL_OFFSET
3277 || nopic_need_relax (ep->X_add_symbol, 1))
3282 macro_build ((char *) NULL, counter, ep,
3283 ((bfd_arch_bits_per_address (stdoutput) == 32
3284 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3285 ? "addiu" : "daddiu"),
3286 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
3287 p = frag_var (rs_machine_dependent, 8, 0,
3288 RELAX_ENCODE (4, 8, 0, 4, 0,
3289 mips_opts.warn_about_macros),
3290 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3292 macro_build_lui (p, counter, ep, reg);
3295 macro_build (p, counter, ep,
3296 ((bfd_arch_bits_per_address (stdoutput) == 32
3297 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3298 ? "addiu" : "daddiu"),
3299 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3301 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3305 /* If this is a reference to an external symbol, we want
3306 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3308 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3310 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3311 If there is a constant, it must be added in after. */
3312 ex.X_add_number = ep->X_add_number;
3313 ep->X_add_number = 0;
3315 macro_build ((char *) NULL, counter, ep,
3316 ((bfd_arch_bits_per_address (stdoutput) == 32
3317 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3319 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3320 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3321 p = frag_var (rs_machine_dependent, 4, 0,
3322 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3323 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3324 macro_build (p, counter, ep,
3325 ((bfd_arch_bits_per_address (stdoutput) == 32
3326 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3327 ? "addiu" : "daddiu"),
3328 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3329 if (ex.X_add_number != 0)
3331 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3332 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3333 ex.X_op = O_constant;
3334 macro_build ((char *) NULL, counter, &ex,
3335 ((bfd_arch_bits_per_address (stdoutput) == 32
3336 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3337 ? "addiu" : "daddiu"),
3338 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3341 else if (mips_pic == SVR4_PIC)
3346 /* This is the large GOT case. If this is a reference to an
3347 external symbol, we want
3348 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3350 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3351 Otherwise, for a reference to a local symbol, we want
3352 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3354 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3355 If there is a constant, it must be added in after. */
3356 ex.X_add_number = ep->X_add_number;
3357 ep->X_add_number = 0;
3358 if (reg_needs_delay (GP))
3363 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3364 (int) BFD_RELOC_MIPS_GOT_HI16);
3365 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3366 ((bfd_arch_bits_per_address (stdoutput) == 32
3367 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3368 ? "addu" : "daddu"),
3369 "d,v,t", reg, reg, GP);
3370 macro_build ((char *) NULL, counter, ep,
3371 ((bfd_arch_bits_per_address (stdoutput) == 32
3372 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3374 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3375 p = frag_var (rs_machine_dependent, 12 + off, 0,
3376 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3377 mips_opts.warn_about_macros),
3378 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3381 /* We need a nop before loading from $gp. This special
3382 check is required because the lui which starts the main
3383 instruction stream does not refer to $gp, and so will not
3384 insert the nop which may be required. */
3385 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3388 macro_build (p, counter, ep,
3389 ((bfd_arch_bits_per_address (stdoutput) == 32
3390 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3392 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3394 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3396 macro_build (p, counter, ep,
3397 ((bfd_arch_bits_per_address (stdoutput) == 32
3398 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3399 ? "addiu" : "daddiu"),
3400 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3401 if (ex.X_add_number != 0)
3403 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3404 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3405 ex.X_op = O_constant;
3406 macro_build ((char *) NULL, counter, &ex,
3407 ((bfd_arch_bits_per_address (stdoutput) == 32
3408 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3409 ? "addiu" : "daddiu"),
3410 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3413 else if (mips_pic == EMBEDDED_PIC)
3416 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
3418 macro_build ((char *) NULL, counter, ep,
3419 ((bfd_arch_bits_per_address (stdoutput) == 32
3420 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
3421 ? "addiu" : "daddiu"),
3422 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
3430 * This routine implements the seemingly endless macro or synthesized
3431 * instructions and addressing modes in the mips assembly language. Many
3432 * of these macros are simple and are similar to each other. These could
3433 * probably be handled by some kind of table or grammer aproach instead of
3434 * this verbose method. Others are not simple macros but are more like
3435 * optimizing code generation.
3436 * One interesting optimization is when several store macros appear
3437 * consecutivly that would load AT with the upper half of the same address.
3438 * The ensuing load upper instructions are ommited. This implies some kind
3439 * of global optimization. We currently only optimize within a single macro.
3440 * For many of the load and store macros if the address is specified as a
3441 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3442 * first load register 'at' with zero and use it as the base register. The
3443 * mips assembler simply uses register $zero. Just one tiny optimization
3448 struct mips_cl_insn *ip;
3450 register int treg, sreg, dreg, breg;
3466 bfd_reloc_code_real_type r;
3468 int hold_mips_optimize;
3470 assert (! mips_opts.mips16);
3472 treg = (ip->insn_opcode >> 16) & 0x1f;
3473 dreg = (ip->insn_opcode >> 11) & 0x1f;
3474 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3475 mask = ip->insn_mo->mask;
3477 expr1.X_op = O_constant;
3478 expr1.X_op_symbol = NULL;
3479 expr1.X_add_symbol = NULL;
3480 expr1.X_add_number = 1;
3492 mips_emit_delays (true);
3493 ++mips_opts.noreorder;
3494 mips_any_noreorder = 1;
3496 expr1.X_add_number = 8;
3497 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3499 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3501 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, sreg, 0);
3502 macro_build ((char *) NULL, &icnt, NULL,
3503 dbl ? "dsub" : "sub",
3504 "d,v,t", dreg, 0, sreg);
3506 --mips_opts.noreorder;
3527 if (imm_expr.X_op == O_constant
3528 && imm_expr.X_add_number >= -0x8000
3529 && imm_expr.X_add_number < 0x8000)
3531 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3532 (int) BFD_RELOC_LO16);
3535 load_register (&icnt, AT, &imm_expr, dbl);
3536 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
3555 if (imm_expr.X_op == O_constant
3556 && imm_expr.X_add_number >= 0
3557 && imm_expr.X_add_number < 0x10000)
3559 if (mask != M_NOR_I)
3560 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
3561 sreg, (int) BFD_RELOC_LO16);
3564 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
3565 treg, sreg, (int) BFD_RELOC_LO16);
3566 macro_build ((char *) NULL, &icnt, NULL, "nor", "d,v,t",
3572 load_register (&icnt, AT, &imm_expr, 0);
3573 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
3590 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3592 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
3596 load_register (&icnt, AT, &imm_expr, 0);
3597 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
3605 macro_build ((char *) NULL, &icnt, &offset_expr,
3606 likely ? "bgezl" : "bgez",
3612 macro_build ((char *) NULL, &icnt, &offset_expr,
3613 likely ? "blezl" : "blez",
3617 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
3618 macro_build ((char *) NULL, &icnt, &offset_expr,
3619 likely ? "beql" : "beq",
3626 /* check for > max integer */
3627 maxnum = 0x7fffffff;
3628 if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4)
3635 if (imm_expr.X_op == O_constant
3636 && imm_expr.X_add_number >= maxnum
3637 && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4))
3640 /* result is always false */
3643 as_warn (_("Branch %s is always false (nop)"), ip->insn_mo->name);
3644 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3648 as_warn (_("Branch likely %s is always false"), ip->insn_mo->name);
3649 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
3654 if (imm_expr.X_op != O_constant)
3655 as_bad (_("Unsupported large constant"));
3656 imm_expr.X_add_number++;
3660 if (mask == M_BGEL_I)
3662 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3664 macro_build ((char *) NULL, &icnt, &offset_expr,
3665 likely ? "bgezl" : "bgez",
3669 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3671 macro_build ((char *) NULL, &icnt, &offset_expr,
3672 likely ? "bgtzl" : "bgtz",
3676 maxnum = 0x7fffffff;
3677 if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4)
3684 maxnum = - maxnum - 1;
3685 if (imm_expr.X_op == O_constant
3686 && imm_expr.X_add_number <= maxnum
3687 && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4))
3690 /* result is always true */
3691 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
3692 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
3695 set_at (&icnt, sreg, 0);
3696 macro_build ((char *) NULL, &icnt, &offset_expr,
3697 likely ? "beql" : "beq",
3708 macro_build ((char *) NULL, &icnt, &offset_expr,
3709 likely ? "beql" : "beq",
3713 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
3715 macro_build ((char *) NULL, &icnt, &offset_expr,
3716 likely ? "beql" : "beq",
3724 || (! ISA_HAS_64BIT_REGS (mips_opts.isa)
3725 && imm_expr.X_op == O_constant
3726 && imm_expr.X_add_number == 0xffffffff))
3728 if (imm_expr.X_op != O_constant)
3729 as_bad (_("Unsupported large constant"));
3730 imm_expr.X_add_number++;
3734 if (mask == M_BGEUL_I)
3736 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3738 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3740 macro_build ((char *) NULL, &icnt, &offset_expr,
3741 likely ? "bnel" : "bne",
3745 set_at (&icnt, sreg, 1);
3746 macro_build ((char *) NULL, &icnt, &offset_expr,
3747 likely ? "beql" : "beq",
3756 macro_build ((char *) NULL, &icnt, &offset_expr,
3757 likely ? "bgtzl" : "bgtz",
3763 macro_build ((char *) NULL, &icnt, &offset_expr,
3764 likely ? "bltzl" : "bltz",
3768 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
3769 macro_build ((char *) NULL, &icnt, &offset_expr,
3770 likely ? "bnel" : "bne",
3779 macro_build ((char *) NULL, &icnt, &offset_expr,
3780 likely ? "bnel" : "bne",
3786 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
3788 macro_build ((char *) NULL, &icnt, &offset_expr,
3789 likely ? "bnel" : "bne",
3798 macro_build ((char *) NULL, &icnt, &offset_expr,
3799 likely ? "blezl" : "blez",
3805 macro_build ((char *) NULL, &icnt, &offset_expr,
3806 likely ? "bgezl" : "bgez",
3810 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
3811 macro_build ((char *) NULL, &icnt, &offset_expr,
3812 likely ? "beql" : "beq",
3819 maxnum = 0x7fffffff;
3820 if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4)
3827 if (imm_expr.X_op == O_constant
3828 && imm_expr.X_add_number >= maxnum
3829 && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4))
3831 if (imm_expr.X_op != O_constant)
3832 as_bad (_("Unsupported large constant"));
3833 imm_expr.X_add_number++;
3837 if (mask == M_BLTL_I)
3839 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3841 macro_build ((char *) NULL, &icnt, &offset_expr,
3842 likely ? "bltzl" : "bltz",
3846 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3848 macro_build ((char *) NULL, &icnt, &offset_expr,
3849 likely ? "blezl" : "blez",
3853 set_at (&icnt, sreg, 0);
3854 macro_build ((char *) NULL, &icnt, &offset_expr,
3855 likely ? "bnel" : "bne",
3864 macro_build ((char *) NULL, &icnt, &offset_expr,
3865 likely ? "beql" : "beq",
3871 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
3873 macro_build ((char *) NULL, &icnt, &offset_expr,
3874 likely ? "beql" : "beq",
3882 || (! ISA_HAS_64BIT_REGS (mips_opts.isa)
3883 && imm_expr.X_op == O_constant
3884 && imm_expr.X_add_number == 0xffffffff))
3886 if (imm_expr.X_op != O_constant)
3887 as_bad (_("Unsupported large constant"));
3888 imm_expr.X_add_number++;
3892 if (mask == M_BLTUL_I)
3894 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3896 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3898 macro_build ((char *) NULL, &icnt, &offset_expr,
3899 likely ? "beql" : "beq",
3903 set_at (&icnt, sreg, 1);
3904 macro_build ((char *) NULL, &icnt, &offset_expr,
3905 likely ? "bnel" : "bne",
3914 macro_build ((char *) NULL, &icnt, &offset_expr,
3915 likely ? "bltzl" : "bltz",
3921 macro_build ((char *) NULL, &icnt, &offset_expr,
3922 likely ? "bgtzl" : "bgtz",
3926 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
3927 macro_build ((char *) NULL, &icnt, &offset_expr,
3928 likely ? "bnel" : "bne",
3939 macro_build ((char *) NULL, &icnt, &offset_expr,
3940 likely ? "bnel" : "bne",
3944 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
3946 macro_build ((char *) NULL, &icnt, &offset_expr,
3947 likely ? "bnel" : "bne",
3963 as_warn (_("Divide by zero."));
3965 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
3967 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
3971 mips_emit_delays (true);
3972 ++mips_opts.noreorder;
3973 mips_any_noreorder = 1;
3976 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0);
3977 macro_build ((char *) NULL, &icnt, NULL,
3978 dbl ? "ddiv" : "div",
3979 "z,s,t", sreg, treg);
3983 expr1.X_add_number = 8;
3984 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
3985 macro_build ((char *) NULL, &icnt, NULL,
3986 dbl ? "ddiv" : "div",
3987 "z,s,t", sreg, treg);
3988 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
3990 expr1.X_add_number = -1;
3991 macro_build ((char *) NULL, &icnt, &expr1,
3992 dbl ? "daddiu" : "addiu",
3993 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
3994 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
3995 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
3998 expr1.X_add_number = 1;
3999 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4000 (int) BFD_RELOC_LO16);
4001 macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT,
4006 expr1.X_add_number = 0x80000000;
4007 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4008 (int) BFD_RELOC_HI16);
4012 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", sreg, AT);
4013 /* We want to close the noreorder block as soon as possible, so
4014 that later insns are available for delay slot filling. */
4015 --mips_opts.noreorder;
4019 expr1.X_add_number = 8;
4020 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4021 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
4023 /* We want to close the noreorder block as soon as possible, so
4024 that later insns are available for delay slot filling. */
4025 --mips_opts.noreorder;
4027 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
4029 macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg);
4068 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4070 as_warn (_("Divide by zero."));
4072 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
4074 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
4077 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4079 if (strcmp (s2, "mflo") == 0)
4080 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg,
4083 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
4086 if (imm_expr.X_op == O_constant
4087 && imm_expr.X_add_number == -1
4088 && s[strlen (s) - 1] != 'u')
4090 if (strcmp (s2, "mflo") == 0)
4093 macro_build ((char *) NULL, &icnt, NULL, "dneg", "d,w", dreg,
4096 macro_build ((char *) NULL, &icnt, NULL, "neg", "d,w", dreg,
4100 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
4104 load_register (&icnt, AT, &imm_expr, dbl);
4105 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT);
4106 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
4125 mips_emit_delays (true);
4126 ++mips_opts.noreorder;
4127 mips_any_noreorder = 1;
4130 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0);
4131 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4132 /* We want to close the noreorder block as soon as possible, so
4133 that later insns are available for delay slot filling. */
4134 --mips_opts.noreorder;
4138 expr1.X_add_number = 8;
4139 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4140 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
4142 /* We want to close the noreorder block as soon as possible, so
4143 that later insns are available for delay slot filling. */
4144 --mips_opts.noreorder;
4145 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
4147 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
4153 /* Load the address of a symbol into a register. If breg is not
4154 zero, we then add a base register to it. */
4156 /* When generating embedded PIC code, we permit expressions of
4159 where bar is an address in the current section. These are used
4160 when getting the addresses of functions. We don't permit
4161 X_add_number to be non-zero, because if the symbol is
4162 external the relaxing code needs to know that any addend is
4163 purely the offset to X_op_symbol. */
4164 if (mips_pic == EMBEDDED_PIC
4165 && offset_expr.X_op == O_subtract
4166 && (symbol_constant_p (offset_expr.X_op_symbol)
4167 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4168 : (symbol_equated_p (offset_expr.X_op_symbol)
4170 (symbol_get_value_expression (offset_expr.X_op_symbol)
4174 && (offset_expr.X_add_number == 0
4175 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4177 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4178 treg, (int) BFD_RELOC_PCREL_HI16_S);
4179 macro_build ((char *) NULL, &icnt, &offset_expr,
4180 ((bfd_arch_bits_per_address (stdoutput) == 32
4181 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4182 ? "addiu" : "daddiu"),
4183 "t,r,j", treg, treg, (int) BFD_RELOC_PCREL_LO16);
4187 if (offset_expr.X_op != O_symbol
4188 && offset_expr.X_op != O_constant)
4190 as_bad (_("expression too complex"));
4191 offset_expr.X_op = O_constant;
4205 if (offset_expr.X_op == O_constant)
4206 load_register (&icnt, tempreg, &offset_expr, dbl);
4207 else if (mips_pic == NO_PIC)
4209 /* If this is a reference to an GP relative symbol, we want
4210 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
4212 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4213 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4214 If we have a constant, we need two instructions anyhow,
4215 so we may as well always use the latter form. */
4216 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
4217 || nopic_need_relax (offset_expr.X_add_symbol, 1))
4222 macro_build ((char *) NULL, &icnt, &offset_expr,
4223 ((bfd_arch_bits_per_address (stdoutput) == 32
4224 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4225 ? "addiu" : "daddiu"),
4226 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
4227 p = frag_var (rs_machine_dependent, 8, 0,
4228 RELAX_ENCODE (4, 8, 0, 4, 0,
4229 mips_opts.warn_about_macros),
4230 offset_expr.X_add_symbol, (offsetT) 0,
4233 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4236 macro_build (p, &icnt, &offset_expr,
4237 ((bfd_arch_bits_per_address (stdoutput) == 32
4238 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4239 ? "addiu" : "daddiu"),
4240 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4242 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4244 /* If this is a reference to an external symbol, and there
4245 is no constant, we want
4246 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4247 For a local symbol, we want
4248 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4250 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4252 If we have a small constant, and this is a reference to
4253 an external symbol, we want
4254 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4256 addiu $tempreg,$tempreg,<constant>
4257 For a local symbol, we want the same instruction
4258 sequence, but we output a BFD_RELOC_LO16 reloc on the
4261 If we have a large constant, and this is a reference to
4262 an external symbol, we want
4263 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4264 lui $at,<hiconstant>
4265 addiu $at,$at,<loconstant>
4266 addu $tempreg,$tempreg,$at
4267 For a local symbol, we want the same instruction
4268 sequence, but we output a BFD_RELOC_LO16 reloc on the
4269 addiu instruction. */
4270 expr1.X_add_number = offset_expr.X_add_number;
4271 offset_expr.X_add_number = 0;
4273 macro_build ((char *) NULL, &icnt, &offset_expr,
4275 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
4276 if (expr1.X_add_number == 0)
4284 /* We're going to put in an addu instruction using
4285 tempreg, so we may as well insert the nop right
4287 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4291 p = frag_var (rs_machine_dependent, 8 - off, 0,
4292 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4294 ? mips_opts.warn_about_macros
4296 offset_expr.X_add_symbol, (offsetT) 0,
4300 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4303 macro_build (p, &icnt, &expr1,
4304 ((bfd_arch_bits_per_address (stdoutput) == 32
4305 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4306 ? "addiu" : "daddiu"),
4307 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4308 /* FIXME: If breg == 0, and the next instruction uses
4309 $tempreg, then if this variant case is used an extra
4310 nop will be generated. */
4312 else if (expr1.X_add_number >= -0x8000
4313 && expr1.X_add_number < 0x8000)
4315 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4317 macro_build ((char *) NULL, &icnt, &expr1,
4318 ((bfd_arch_bits_per_address (stdoutput) == 32
4319 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4320 ? "addiu" : "daddiu"),
4321 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4322 (void) frag_var (rs_machine_dependent, 0, 0,
4323 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4324 offset_expr.X_add_symbol, (offsetT) 0,
4331 /* If we are going to add in a base register, and the
4332 target register and the base register are the same,
4333 then we are using AT as a temporary register. Since
4334 we want to load the constant into AT, we add our
4335 current AT (from the global offset table) and the
4336 register into the register now, and pretend we were
4337 not using a base register. */
4342 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4344 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4345 ((bfd_arch_bits_per_address (stdoutput) == 32
4346 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4347 ? "addu" : "daddu"),
4348 "d,v,t", treg, AT, breg);
4354 /* Set mips_optimize around the lui instruction to avoid
4355 inserting an unnecessary nop after the lw. */
4356 hold_mips_optimize = mips_optimize;
4358 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
4359 mips_optimize = hold_mips_optimize;
4361 macro_build ((char *) NULL, &icnt, &expr1,
4362 ((bfd_arch_bits_per_address (stdoutput) == 32
4363 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4364 ? "addiu" : "daddiu"),
4365 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4366 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4367 ((bfd_arch_bits_per_address (stdoutput) == 32
4368 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4369 ? "addu" : "daddu"),
4370 "d,v,t", tempreg, tempreg, AT);
4371 (void) frag_var (rs_machine_dependent, 0, 0,
4372 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4373 offset_expr.X_add_symbol, (offsetT) 0,
4378 else if (mips_pic == SVR4_PIC)
4382 /* This is the large GOT case. If this is a reference to an
4383 external symbol, and there is no constant, we want
4384 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4385 addu $tempreg,$tempreg,$gp
4386 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4387 For a local symbol, we want
4388 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4390 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4392 If we have a small constant, and this is a reference to
4393 an external symbol, we want
4394 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4395 addu $tempreg,$tempreg,$gp
4396 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4398 addiu $tempreg,$tempreg,<constant>
4399 For a local symbol, we want
4400 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4402 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4404 If we have a large constant, and this is a reference to
4405 an external symbol, we want
4406 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4407 addu $tempreg,$tempreg,$gp
4408 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4409 lui $at,<hiconstant>
4410 addiu $at,$at,<loconstant>
4411 addu $tempreg,$tempreg,$at
4412 For a local symbol, we want
4413 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4414 lui $at,<hiconstant>
4415 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4416 addu $tempreg,$tempreg,$at
4418 expr1.X_add_number = offset_expr.X_add_number;
4419 offset_expr.X_add_number = 0;
4421 if (reg_needs_delay (GP))
4425 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4426 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
4427 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4428 ((bfd_arch_bits_per_address (stdoutput) == 32
4429 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4430 ? "addu" : "daddu"),
4431 "d,v,t", tempreg, tempreg, GP);
4432 macro_build ((char *) NULL, &icnt, &offset_expr,
4434 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
4436 if (expr1.X_add_number == 0)
4444 /* We're going to put in an addu instruction using
4445 tempreg, so we may as well insert the nop right
4447 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4452 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4453 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4456 ? mips_opts.warn_about_macros
4458 offset_expr.X_add_symbol, (offsetT) 0,
4461 else if (expr1.X_add_number >= -0x8000
4462 && expr1.X_add_number < 0x8000)
4464 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4466 macro_build ((char *) NULL, &icnt, &expr1,
4467 ((bfd_arch_bits_per_address (stdoutput) == 32
4468 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4469 ? "addiu" : "daddiu"),
4470 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4472 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4473 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4475 ? mips_opts.warn_about_macros
4477 offset_expr.X_add_symbol, (offsetT) 0,
4484 /* If we are going to add in a base register, and the
4485 target register and the base register are the same,
4486 then we are using AT as a temporary register. Since
4487 we want to load the constant into AT, we add our
4488 current AT (from the global offset table) and the
4489 register into the register now, and pretend we were
4490 not using a base register. */
4498 assert (tempreg == AT);
4499 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4501 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4502 ((bfd_arch_bits_per_address (stdoutput) == 32
4503 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4504 ? "addu" : "daddu"),
4505 "d,v,t", treg, AT, breg);
4510 /* Set mips_optimize around the lui instruction to avoid
4511 inserting an unnecessary nop after the lw. */
4512 hold_mips_optimize = mips_optimize;
4514 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
4515 mips_optimize = hold_mips_optimize;
4517 macro_build ((char *) NULL, &icnt, &expr1,
4518 ((bfd_arch_bits_per_address (stdoutput) == 32
4519 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4520 ? "addiu" : "daddiu"),
4521 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4522 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4523 ((bfd_arch_bits_per_address (stdoutput) == 32
4524 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4525 ? "addu" : "daddu"),
4526 "d,v,t", dreg, dreg, AT);
4528 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
4529 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
4532 ? mips_opts.warn_about_macros
4534 offset_expr.X_add_symbol, (offsetT) 0,
4542 /* This is needed because this instruction uses $gp, but
4543 the first instruction on the main stream does not. */
4544 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4547 macro_build (p, &icnt, &offset_expr,
4549 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
4551 if (expr1.X_add_number >= -0x8000
4552 && expr1.X_add_number < 0x8000)
4554 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4556 macro_build (p, &icnt, &expr1,
4557 ((bfd_arch_bits_per_address (stdoutput) == 32
4558 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4559 ? "addiu" : "daddiu"),
4560 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4561 /* FIXME: If add_number is 0, and there was no base
4562 register, the external symbol case ended with a load,
4563 so if the symbol turns out to not be external, and
4564 the next instruction uses tempreg, an unnecessary nop
4565 will be inserted. */
4571 /* We must add in the base register now, as in the
4572 external symbol case. */
4573 assert (tempreg == AT);
4574 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4576 macro_build (p, &icnt, (expressionS *) NULL,
4577 ((bfd_arch_bits_per_address (stdoutput) == 32
4578 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4579 ? "addu" : "daddu"),
4580 "d,v,t", treg, AT, breg);
4583 /* We set breg to 0 because we have arranged to add
4584 it in in both cases. */
4588 macro_build_lui (p, &icnt, &expr1, AT);
4590 macro_build (p, &icnt, &expr1,
4591 ((bfd_arch_bits_per_address (stdoutput) == 32
4592 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4593 ? "addiu" : "daddiu"),
4594 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4596 macro_build (p, &icnt, (expressionS *) NULL,
4597 ((bfd_arch_bits_per_address (stdoutput) == 32
4598 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4599 ? "addu" : "daddu"),
4600 "d,v,t", tempreg, tempreg, AT);
4604 else if (mips_pic == EMBEDDED_PIC)
4607 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
4609 macro_build ((char *) NULL, &icnt, &offset_expr,
4610 ((bfd_arch_bits_per_address (stdoutput) == 32
4611 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4612 ? "addiu" : "daddiu"),
4613 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
4619 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4620 ((bfd_arch_bits_per_address (stdoutput) == 32
4621 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4622 ? "addu" : "daddu"),
4623 "d,v,t", treg, tempreg, breg);
4631 /* The j instruction may not be used in PIC code, since it
4632 requires an absolute address. We convert it to a b
4634 if (mips_pic == NO_PIC)
4635 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
4637 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4640 /* The jal instructions must be handled as macros because when
4641 generating PIC code they expand to multi-instruction
4642 sequences. Normally they are simple instructions. */
4647 if (mips_pic == NO_PIC
4648 || mips_pic == EMBEDDED_PIC)
4649 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
4651 else if (mips_pic == SVR4_PIC)
4653 if (sreg != PIC_CALL_REG)
4654 as_warn (_("MIPS PIC call to register other than $25"));
4656 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
4658 if (mips_cprestore_offset < 0)
4659 as_warn (_("No .cprestore pseudo-op used in PIC code"));
4662 expr1.X_add_number = mips_cprestore_offset;
4663 macro_build ((char *) NULL, &icnt, &expr1,
4664 ((bfd_arch_bits_per_address (stdoutput) == 32
4665 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4667 "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg);
4676 if (mips_pic == NO_PIC)
4677 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
4678 else if (mips_pic == SVR4_PIC)
4680 /* If this is a reference to an external symbol, and we are
4681 using a small GOT, we want
4682 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4686 lw $gp,cprestore($sp)
4687 The cprestore value is set using the .cprestore
4688 pseudo-op. If we are using a big GOT, we want
4689 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4691 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
4695 lw $gp,cprestore($sp)
4696 If the symbol is not external, we want
4697 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4699 addiu $25,$25,<sym> (BFD_RELOC_LO16)
4702 lw $gp,cprestore($sp) */
4706 macro_build ((char *) NULL, &icnt, &offset_expr,
4707 ((bfd_arch_bits_per_address (stdoutput) == 32
4708 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4710 "t,o(b)", PIC_CALL_REG,
4711 (int) BFD_RELOC_MIPS_CALL16, GP);
4712 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4714 p = frag_var (rs_machine_dependent, 4, 0,
4715 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
4716 offset_expr.X_add_symbol, (offsetT) 0,
4723 if (reg_needs_delay (GP))
4727 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4728 PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16);
4729 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4730 ((bfd_arch_bits_per_address (stdoutput) == 32
4731 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4732 ? "addu" : "daddu"),
4733 "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP);
4734 macro_build ((char *) NULL, &icnt, &offset_expr,
4735 ((bfd_arch_bits_per_address (stdoutput) == 32
4736 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4738 "t,o(b)", PIC_CALL_REG,
4739 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
4740 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4742 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4743 RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel,
4745 offset_expr.X_add_symbol, (offsetT) 0,
4749 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4752 macro_build (p, &icnt, &offset_expr,
4753 ((bfd_arch_bits_per_address (stdoutput) == 32
4754 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4756 "t,o(b)", PIC_CALL_REG,
4757 (int) BFD_RELOC_MIPS_GOT16, GP);
4759 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4762 macro_build (p, &icnt, &offset_expr,
4763 ((bfd_arch_bits_per_address (stdoutput) == 32
4764 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4765 ? "addiu" : "daddiu"),
4766 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
4767 (int) BFD_RELOC_LO16);
4768 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4769 "jalr", "s", PIC_CALL_REG);
4770 if (mips_cprestore_offset < 0)
4771 as_warn (_("No .cprestore pseudo-op used in PIC code"));
4774 if (mips_opts.noreorder)
4775 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4777 expr1.X_add_number = mips_cprestore_offset;
4778 macro_build ((char *) NULL, &icnt, &expr1,
4779 ((bfd_arch_bits_per_address (stdoutput) == 32
4780 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
4782 "t,o(b)", GP, (int) BFD_RELOC_LO16,
4786 else if (mips_pic == EMBEDDED_PIC)
4788 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
4789 /* The linker may expand the call to a longer sequence which
4790 uses $at, so we must break rather than return. */
4815 /* Itbl support may require additional care here. */
4820 /* Itbl support may require additional care here. */
4825 /* Itbl support may require additional care here. */
4830 /* Itbl support may require additional care here. */
4842 if (mips_cpu == 4650)
4844 as_bad (_("opcode not supported on this processor"));
4848 /* Itbl support may require additional care here. */
4853 /* Itbl support may require additional care here. */
4858 /* Itbl support may require additional care here. */
4878 if (breg == treg || coproc || lr)
4900 /* Itbl support may require additional care here. */
4905 /* Itbl support may require additional care here. */
4910 /* Itbl support may require additional care here. */
4915 /* Itbl support may require additional care here. */
4931 if (mips_cpu == 4650)
4933 as_bad (_("opcode not supported on this processor"));
4938 /* Itbl support may require additional care here. */
4942 /* Itbl support may require additional care here. */
4947 /* Itbl support may require additional care here. */
4959 /* Itbl support may require additional care here. */
4960 if (mask == M_LWC1_AB
4961 || mask == M_SWC1_AB
4962 || mask == M_LDC1_AB
4963 || mask == M_SDC1_AB
4972 if (offset_expr.X_op != O_constant
4973 && offset_expr.X_op != O_symbol)
4975 as_bad (_("expression too complex"));
4976 offset_expr.X_op = O_constant;
4979 /* A constant expression in PIC code can be handled just as it
4980 is in non PIC code. */
4981 if (mips_pic == NO_PIC
4982 || offset_expr.X_op == O_constant)
4984 /* If this is a reference to a GP relative symbol, and there
4985 is no base register, we want
4986 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
4987 Otherwise, if there is no base register, we want
4988 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4989 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
4990 If we have a constant, we need two instructions anyhow,
4991 so we always use the latter form.
4993 If we have a base register, and this is a reference to a
4994 GP relative symbol, we want
4995 addu $tempreg,$breg,$gp
4996 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
4998 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4999 addu $tempreg,$tempreg,$breg
5000 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5001 With a constant we always use the latter case. */
5004 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
5005 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5010 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5011 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
5012 p = frag_var (rs_machine_dependent, 8, 0,
5013 RELAX_ENCODE (4, 8, 0, 4, 0,
5014 (mips_opts.warn_about_macros
5016 && mips_opts.noat))),
5017 offset_expr.X_add_symbol, (offsetT) 0,
5021 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5024 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5025 (int) BFD_RELOC_LO16, tempreg);
5029 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
5030 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5035 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5036 ((bfd_arch_bits_per_address (stdoutput) == 32
5037 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5038 ? "addu" : "daddu"),
5039 "d,v,t", tempreg, breg, GP);
5040 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5041 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
5042 p = frag_var (rs_machine_dependent, 12, 0,
5043 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5044 offset_expr.X_add_symbol, (offsetT) 0,
5047 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5050 macro_build (p, &icnt, (expressionS *) NULL,
5051 ((bfd_arch_bits_per_address (stdoutput) == 32
5052 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5053 ? "addu" : "daddu"),
5054 "d,v,t", tempreg, tempreg, breg);
5057 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5058 (int) BFD_RELOC_LO16, tempreg);
5061 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5063 /* If this is a reference to an external symbol, we want
5064 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5066 <op> $treg,0($tempreg)
5068 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5070 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5071 <op> $treg,0($tempreg)
5072 If there is a base register, we add it to $tempreg before
5073 the <op>. If there is a constant, we stick it in the
5074 <op> instruction. We don't handle constants larger than
5075 16 bits, because we have no way to load the upper 16 bits
5076 (actually, we could handle them for the subset of cases
5077 in which we are not using $at). */
5078 assert (offset_expr.X_op == O_symbol);
5079 expr1.X_add_number = offset_expr.X_add_number;
5080 offset_expr.X_add_number = 0;
5081 if (expr1.X_add_number < -0x8000
5082 || expr1.X_add_number >= 0x8000)
5083 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5085 macro_build ((char *) NULL, &icnt, &offset_expr,
5086 ((bfd_arch_bits_per_address (stdoutput) == 32
5087 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5089 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5090 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5091 p = frag_var (rs_machine_dependent, 4, 0,
5092 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5093 offset_expr.X_add_symbol, (offsetT) 0,
5095 macro_build (p, &icnt, &offset_expr,
5096 ((bfd_arch_bits_per_address (stdoutput) == 32
5097 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5098 ? "addiu" : "daddiu"),
5099 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5101 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5102 ((bfd_arch_bits_per_address (stdoutput) == 32
5103 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5104 ? "addu" : "daddu"),
5105 "d,v,t", tempreg, tempreg, breg);
5106 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5107 (int) BFD_RELOC_LO16, tempreg);
5109 else if (mips_pic == SVR4_PIC)
5113 /* If this is a reference to an external symbol, we want
5114 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5115 addu $tempreg,$tempreg,$gp
5116 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5117 <op> $treg,0($tempreg)
5119 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5121 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5122 <op> $treg,0($tempreg)
5123 If there is a base register, we add it to $tempreg before
5124 the <op>. If there is a constant, we stick it in the
5125 <op> instruction. We don't handle constants larger than
5126 16 bits, because we have no way to load the upper 16 bits
5127 (actually, we could handle them for the subset of cases
5128 in which we are not using $at). */
5129 assert (offset_expr.X_op == O_symbol);
5130 expr1.X_add_number = offset_expr.X_add_number;
5131 offset_expr.X_add_number = 0;
5132 if (expr1.X_add_number < -0x8000
5133 || expr1.X_add_number >= 0x8000)
5134 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5135 if (reg_needs_delay (GP))
5140 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5141 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5142 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5143 ((bfd_arch_bits_per_address (stdoutput) == 32
5144 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5145 ? "addu" : "daddu"),
5146 "d,v,t", tempreg, tempreg, GP);
5147 macro_build ((char *) NULL, &icnt, &offset_expr,
5148 ((bfd_arch_bits_per_address (stdoutput) == 32
5149 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5151 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5153 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5154 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5155 offset_expr.X_add_symbol, (offsetT) 0, (char *) NULL);
5158 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5161 macro_build (p, &icnt, &offset_expr,
5162 ((bfd_arch_bits_per_address (stdoutput) == 32
5163 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5165 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5167 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5169 macro_build (p, &icnt, &offset_expr,
5170 ((bfd_arch_bits_per_address (stdoutput) == 32
5171 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5172 ? "addiu" : "daddiu"),
5173 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5175 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5176 ((bfd_arch_bits_per_address (stdoutput) == 32
5177 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5178 ? "addu" : "daddu"),
5179 "d,v,t", tempreg, tempreg, breg);
5180 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5181 (int) BFD_RELOC_LO16, tempreg);
5183 else if (mips_pic == EMBEDDED_PIC)
5185 /* If there is no base register, we want
5186 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
5187 If there is a base register, we want
5188 addu $tempreg,$breg,$gp
5189 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
5191 assert (offset_expr.X_op == O_symbol);
5194 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5195 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
5200 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5201 ((bfd_arch_bits_per_address (stdoutput) == 32
5202 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5203 ? "addu" : "daddu"),
5204 "d,v,t", tempreg, breg, GP);
5205 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5206 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
5219 load_register (&icnt, treg, &imm_expr, 0);
5223 load_register (&icnt, treg, &imm_expr, 1);
5227 if (imm_expr.X_op == O_constant)
5229 load_register (&icnt, AT, &imm_expr, 0);
5230 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5231 "mtc1", "t,G", AT, treg);
5236 assert (offset_expr.X_op == O_symbol
5237 && strcmp (segment_name (S_GET_SEGMENT
5238 (offset_expr.X_add_symbol)),
5240 && offset_expr.X_add_number == 0);
5241 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5242 treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5247 /* If we have a constant in IMM_EXPR, then in mips3 mode it is
5248 the entire value, and in mips1 mode it is the high order 32
5249 bits of the value and the low order 32 bits are either zero
5250 or in offset_expr. */
5251 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5253 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5254 load_register (&icnt, treg, &imm_expr, 1);
5259 if (target_big_endian)
5271 load_register (&icnt, hreg, &imm_expr, 0);
5274 if (offset_expr.X_op == O_absent)
5275 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s",
5279 assert (offset_expr.X_op == O_constant);
5280 load_register (&icnt, lreg, &offset_expr, 0);
5287 /* We know that sym is in the .rdata section. First we get the
5288 upper 16 bits of the address. */
5289 if (mips_pic == NO_PIC)
5291 /* FIXME: This won't work for a 64 bit address. */
5292 macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
5294 else if (mips_pic == SVR4_PIC)
5296 macro_build ((char *) NULL, &icnt, &offset_expr,
5297 ((bfd_arch_bits_per_address (stdoutput) == 32
5298 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5300 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5302 else if (mips_pic == EMBEDDED_PIC)
5304 /* For embedded PIC we pick up the entire address off $gp in
5305 a single instruction. */
5306 macro_build ((char *) NULL, &icnt, &offset_expr,
5307 ((bfd_arch_bits_per_address (stdoutput) == 32
5308 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5309 ? "addiu" : "daddiu"),
5310 "t,r,j", AT, GP, (int) BFD_RELOC_MIPS_GPREL);
5311 offset_expr.X_op = O_constant;
5312 offset_expr.X_add_number = 0;
5317 /* Now we load the register(s). */
5318 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5319 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5320 treg, (int) BFD_RELOC_LO16, AT);
5323 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5324 treg, (int) BFD_RELOC_LO16, AT);
5327 /* FIXME: How in the world do we deal with the possible
5329 offset_expr.X_add_number += 4;
5330 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5331 treg + 1, (int) BFD_RELOC_LO16, AT);
5335 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5336 does not become a variant frag. */
5337 frag_wane (frag_now);
5343 /* If we have a constant in IMM_EXPR, then in mips3 mode it is
5344 the entire value, and in mips1 mode it is the high order 32
5345 bits of the value and the low order 32 bits are either zero
5346 or in offset_expr. */
5347 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5349 load_register (&icnt, AT, &imm_expr, ISA_HAS_64BIT_REGS (mips_opts.isa));
5350 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5351 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5352 "dmtc1", "t,S", AT, treg);
5355 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5356 "mtc1", "t,G", AT, treg + 1);
5357 if (offset_expr.X_op == O_absent)
5358 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5359 "mtc1", "t,G", 0, treg);
5362 assert (offset_expr.X_op == O_constant);
5363 load_register (&icnt, AT, &offset_expr, 0);
5364 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5365 "mtc1", "t,G", AT, treg);
5371 assert (offset_expr.X_op == O_symbol
5372 && offset_expr.X_add_number == 0);
5373 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5374 if (strcmp (s, ".lit8") == 0)
5376 if (mips_opts.isa != 1)
5378 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5379 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5383 r = BFD_RELOC_MIPS_LITERAL;
5388 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5389 if (mips_pic == SVR4_PIC)
5390 macro_build ((char *) NULL, &icnt, &offset_expr,
5391 ((bfd_arch_bits_per_address (stdoutput) == 32
5392 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5394 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5397 /* FIXME: This won't work for a 64 bit address. */
5398 macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
5401 if (mips_opts.isa != 1)
5403 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5404 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
5406 /* To avoid confusion in tc_gen_reloc, we must ensure
5407 that this does not become a variant frag. */
5408 frag_wane (frag_now);
5419 if (mips_cpu == 4650)
5421 as_bad (_("opcode not supported on this processor"));
5424 /* Even on a big endian machine $fn comes before $fn+1. We have
5425 to adjust when loading from memory. */
5428 assert (mips_opts.isa == 1);
5429 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5430 target_big_endian ? treg + 1 : treg,
5432 /* FIXME: A possible overflow which I don't know how to deal
5434 offset_expr.X_add_number += 4;
5435 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5436 target_big_endian ? treg : treg + 1,
5439 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5440 does not become a variant frag. */
5441 frag_wane (frag_now);
5450 * The MIPS assembler seems to check for X_add_number not
5451 * being double aligned and generating:
5454 * addiu at,at,%lo(foo+1)
5457 * But, the resulting address is the same after relocation so why
5458 * generate the extra instruction?
5460 if (mips_cpu == 4650)
5462 as_bad (_("opcode not supported on this processor"));
5465 /* Itbl support may require additional care here. */
5467 if (mips_opts.isa != 1)
5478 if (mips_cpu == 4650)
5480 as_bad (_("opcode not supported on this processor"));
5484 if (mips_opts.isa != 1)
5492 /* Itbl support may require additional care here. */
5497 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5508 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
5518 if (offset_expr.X_op != O_symbol
5519 && offset_expr.X_op != O_constant)
5521 as_bad (_("expression too complex"));
5522 offset_expr.X_op = O_constant;
5525 /* Even on a big endian machine $fn comes before $fn+1. We have
5526 to adjust when loading from memory. We set coproc if we must
5527 load $fn+1 first. */
5528 /* Itbl support may require additional care here. */
5529 if (! target_big_endian)
5532 if (mips_pic == NO_PIC
5533 || offset_expr.X_op == O_constant)
5535 /* If this is a reference to a GP relative symbol, we want
5536 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
5537 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
5538 If we have a base register, we use this
5540 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
5541 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
5542 If this is not a GP relative symbol, we want
5543 lui $at,<sym> (BFD_RELOC_HI16_S)
5544 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5545 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5546 If there is a base register, we add it to $at after the
5547 lui instruction. If there is a constant, we always use
5549 if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET
5550 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5569 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5570 ((bfd_arch_bits_per_address (stdoutput) == 32
5571 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5572 ? "addu" : "daddu"),
5573 "d,v,t", AT, breg, GP);
5579 /* Itbl support may require additional care here. */
5580 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5581 coproc ? treg + 1 : treg,
5582 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5583 offset_expr.X_add_number += 4;
5585 /* Set mips_optimize to 2 to avoid inserting an
5587 hold_mips_optimize = mips_optimize;
5589 /* Itbl support may require additional care here. */
5590 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5591 coproc ? treg : treg + 1,
5592 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5593 mips_optimize = hold_mips_optimize;
5595 p = frag_var (rs_machine_dependent, 12 + off, 0,
5596 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
5597 used_at && mips_opts.noat),
5598 offset_expr.X_add_symbol, (offsetT) 0,
5601 /* We just generated two relocs. When tc_gen_reloc
5602 handles this case, it will skip the first reloc and
5603 handle the second. The second reloc already has an
5604 extra addend of 4, which we added above. We must
5605 subtract it out, and then subtract another 4 to make
5606 the first reloc come out right. The second reloc
5607 will come out right because we are going to add 4 to
5608 offset_expr when we build its instruction below.
5610 If we have a symbol, then we don't want to include
5611 the offset, because it will wind up being included
5612 when we generate the reloc. */
5614 if (offset_expr.X_op == O_constant)
5615 offset_expr.X_add_number -= 8;
5618 offset_expr.X_add_number = -4;
5619 offset_expr.X_op = O_constant;
5622 macro_build_lui (p, &icnt, &offset_expr, AT);
5627 macro_build (p, &icnt, (expressionS *) NULL,
5628 ((bfd_arch_bits_per_address (stdoutput) == 32
5629 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5630 ? "addu" : "daddu"),
5631 "d,v,t", AT, breg, AT);
5635 /* Itbl support may require additional care here. */
5636 macro_build (p, &icnt, &offset_expr, s, fmt,
5637 coproc ? treg + 1 : treg,
5638 (int) BFD_RELOC_LO16, AT);
5641 /* FIXME: How do we handle overflow here? */
5642 offset_expr.X_add_number += 4;
5643 /* Itbl support may require additional care here. */
5644 macro_build (p, &icnt, &offset_expr, s, fmt,
5645 coproc ? treg : treg + 1,
5646 (int) BFD_RELOC_LO16, AT);
5648 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5652 /* If this is a reference to an external symbol, we want
5653 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5658 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5660 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5661 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5662 If there is a base register we add it to $at before the
5663 lwc1 instructions. If there is a constant we include it
5664 in the lwc1 instructions. */
5666 expr1.X_add_number = offset_expr.X_add_number;
5667 offset_expr.X_add_number = 0;
5668 if (expr1.X_add_number < -0x8000
5669 || expr1.X_add_number >= 0x8000 - 4)
5670 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5675 frag_grow (24 + off);
5676 macro_build ((char *) NULL, &icnt, &offset_expr,
5677 ((bfd_arch_bits_per_address (stdoutput) == 32
5678 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5680 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5681 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5683 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5684 ((bfd_arch_bits_per_address (stdoutput) == 32
5685 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5686 ? "addu" : "daddu"),
5687 "d,v,t", AT, breg, AT);
5688 /* Itbl support may require additional care here. */
5689 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5690 coproc ? treg + 1 : treg,
5691 (int) BFD_RELOC_LO16, AT);
5692 expr1.X_add_number += 4;
5694 /* Set mips_optimize to 2 to avoid inserting an undesired
5696 hold_mips_optimize = mips_optimize;
5698 /* Itbl support may require additional care here. */
5699 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5700 coproc ? treg : treg + 1,
5701 (int) BFD_RELOC_LO16, AT);
5702 mips_optimize = hold_mips_optimize;
5704 (void) frag_var (rs_machine_dependent, 0, 0,
5705 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
5706 offset_expr.X_add_symbol, (offsetT) 0,
5709 else if (mips_pic == SVR4_PIC)
5713 /* If this is a reference to an external symbol, we want
5714 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5716 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
5721 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5723 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
5724 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
5725 If there is a base register we add it to $at before the
5726 lwc1 instructions. If there is a constant we include it
5727 in the lwc1 instructions. */
5729 expr1.X_add_number = offset_expr.X_add_number;
5730 offset_expr.X_add_number = 0;
5731 if (expr1.X_add_number < -0x8000
5732 || expr1.X_add_number >= 0x8000 - 4)
5733 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5734 if (reg_needs_delay (GP))
5743 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5744 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
5745 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5746 ((bfd_arch_bits_per_address (stdoutput) == 32
5747 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5748 ? "addu" : "daddu"),
5749 "d,v,t", AT, AT, GP);
5750 macro_build ((char *) NULL, &icnt, &offset_expr,
5751 ((bfd_arch_bits_per_address (stdoutput) == 32
5752 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5754 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
5755 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5757 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5758 ((bfd_arch_bits_per_address (stdoutput) == 32
5759 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5760 ? "addu" : "daddu"),
5761 "d,v,t", AT, breg, AT);
5762 /* Itbl support may require additional care here. */
5763 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5764 coproc ? treg + 1 : treg,
5765 (int) BFD_RELOC_LO16, AT);
5766 expr1.X_add_number += 4;
5768 /* Set mips_optimize to 2 to avoid inserting an undesired
5770 hold_mips_optimize = mips_optimize;
5772 /* Itbl support may require additional care here. */
5773 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
5774 coproc ? treg : treg + 1,
5775 (int) BFD_RELOC_LO16, AT);
5776 mips_optimize = hold_mips_optimize;
5777 expr1.X_add_number -= 4;
5779 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
5780 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
5781 8 + gpdel + off, 1, 0),
5782 offset_expr.X_add_symbol, (offsetT) 0,
5786 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5789 macro_build (p, &icnt, &offset_expr,
5790 ((bfd_arch_bits_per_address (stdoutput) == 32
5791 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5793 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5795 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5799 macro_build (p, &icnt, (expressionS *) NULL,
5800 ((bfd_arch_bits_per_address (stdoutput) == 32
5801 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5802 ? "addu" : "daddu"),
5803 "d,v,t", AT, breg, AT);
5806 /* Itbl support may require additional care here. */
5807 macro_build (p, &icnt, &expr1, s, fmt,
5808 coproc ? treg + 1 : treg,
5809 (int) BFD_RELOC_LO16, AT);
5811 expr1.X_add_number += 4;
5813 /* Set mips_optimize to 2 to avoid inserting an undesired
5815 hold_mips_optimize = mips_optimize;
5817 /* Itbl support may require additional care here. */
5818 macro_build (p, &icnt, &expr1, s, fmt,
5819 coproc ? treg : treg + 1,
5820 (int) BFD_RELOC_LO16, AT);
5821 mips_optimize = hold_mips_optimize;
5823 else if (mips_pic == EMBEDDED_PIC)
5825 /* If there is no base register, we use
5826 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
5827 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
5828 If we have a base register, we use
5830 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
5831 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
5840 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5841 ((bfd_arch_bits_per_address (stdoutput) == 32
5842 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5843 ? "addu" : "daddu"),
5844 "d,v,t", AT, breg, GP);
5849 /* Itbl support may require additional care here. */
5850 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5851 coproc ? treg + 1 : treg,
5852 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5853 offset_expr.X_add_number += 4;
5854 /* Itbl support may require additional care here. */
5855 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5856 coproc ? treg : treg + 1,
5857 (int) BFD_RELOC_MIPS_GPREL, tempreg);
5873 assert (bfd_arch_bits_per_address (stdoutput) == 32
5874 || ! ISA_HAS_64BIT_REGS (mips_opts.isa));
5875 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
5876 (int) BFD_RELOC_LO16, breg);
5877 offset_expr.X_add_number += 4;
5878 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
5879 (int) BFD_RELOC_LO16, breg);
5882 /* New code added to support COPZ instructions.
5883 This code builds table entries out of the macros in mip_opcodes.
5884 R4000 uses interlocks to handle coproc delays.
5885 Other chips (like the R3000) require nops to be inserted for delays.
5887 FIXME: Currently, we require that the user handle delays.
5888 In order to fill delay slots for non-interlocked chips,
5889 we must have a way to specify delays based on the coprocessor.
5890 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
5891 What are the side-effects of the cop instruction?
5892 What cache support might we have and what are its effects?
5893 Both coprocessor & memory require delays. how long???
5894 What registers are read/set/modified?
5896 If an itbl is provided to interpret cop instructions,
5897 this knowledge can be encoded in the itbl spec. */
5911 /* For now we just do C (same as Cz). The parameter will be
5912 stored in insn_opcode by mips_ip. */
5913 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
5917 #ifdef LOSING_COMPILER
5919 /* Try and see if this is a new itbl instruction.
5920 This code builds table entries out of the macros in mip_opcodes.
5921 FIXME: For now we just assemble the expression and pass it's
5922 value along as a 32-bit immediate.
5923 We may want to have the assembler assemble this value,
5924 so that we gain the assembler's knowledge of delay slots,
5926 Would it be more efficient to use mask (id) here? */
5927 if (itbl_have_entries
5928 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
5930 s = ip->insn_mo->name;
5932 coproc = ITBL_DECODE_PNUM (immed_expr);;
5933 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
5940 as_warn (_("Macro used $at after \".set noat\""));
5945 struct mips_cl_insn *ip;
5947 register int treg, sreg, dreg, breg;
5963 bfd_reloc_code_real_type r;
5966 treg = (ip->insn_opcode >> 16) & 0x1f;
5967 dreg = (ip->insn_opcode >> 11) & 0x1f;
5968 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
5969 mask = ip->insn_mo->mask;
5971 expr1.X_op = O_constant;
5972 expr1.X_op_symbol = NULL;
5973 expr1.X_add_symbol = NULL;
5974 expr1.X_add_number = 1;
5978 #endif /* LOSING_COMPILER */
5983 macro_build ((char *) NULL, &icnt, NULL,
5984 dbl ? "dmultu" : "multu",
5986 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
5992 /* The MIPS assembler some times generates shifts and adds. I'm
5993 not trying to be that fancy. GCC should do this for us
5995 load_register (&icnt, AT, &imm_expr, dbl);
5996 macro_build ((char *) NULL, &icnt, NULL,
5997 dbl ? "dmult" : "mult",
5999 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6012 mips_emit_delays (true);
6013 ++mips_opts.noreorder;
6014 mips_any_noreorder = 1;
6016 load_register (&icnt, AT, &imm_expr, dbl);
6017 macro_build ((char *) NULL, &icnt, NULL,
6018 dbl ? "dmult" : "mult",
6019 "s,t", sreg, imm ? AT : treg);
6020 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6021 macro_build ((char *) NULL, &icnt, NULL,
6022 dbl ? "dsra32" : "sra",
6023 "d,w,<", dreg, dreg, 31);
6024 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
6026 macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", dreg, AT);
6029 expr1.X_add_number = 8;
6030 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
6031 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
6032 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
6034 --mips_opts.noreorder;
6035 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6048 mips_emit_delays (true);
6049 ++mips_opts.noreorder;
6050 mips_any_noreorder = 1;
6052 load_register (&icnt, AT, &imm_expr, dbl);
6053 macro_build ((char *) NULL, &icnt, NULL,
6054 dbl ? "dmultu" : "multu",
6055 "s,t", sreg, imm ? AT : treg);
6056 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
6057 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
6059 macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", AT, 0);
6062 expr1.X_add_number = 8;
6063 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6064 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
6065 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
6067 --mips_opts.noreorder;
6071 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
6072 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT);
6073 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg,
6075 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
6079 if (imm_expr.X_op != O_constant)
6080 as_bad (_("rotate count too large"));
6081 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg,
6082 (int) (imm_expr.X_add_number & 0x1f));
6083 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg,
6084 (int) ((0 - imm_expr.X_add_number) & 0x1f));
6085 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
6089 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
6090 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT);
6091 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg,
6093 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
6097 if (imm_expr.X_op != O_constant)
6098 as_bad (_("rotate count too large"));
6099 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg,
6100 (int) (imm_expr.X_add_number & 0x1f));
6101 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg,
6102 (int) ((0 - imm_expr.X_add_number) & 0x1f));
6103 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
6107 if (mips_cpu == 4650)
6109 as_bad (_("opcode not supported on this processor"));
6112 assert (mips_opts.isa == 1);
6113 /* Even on a big endian machine $fn comes before $fn+1. We have
6114 to adjust when storing to memory. */
6115 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6116 target_big_endian ? treg + 1 : treg,
6117 (int) BFD_RELOC_LO16, breg);
6118 offset_expr.X_add_number += 4;
6119 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6120 target_big_endian ? treg : treg + 1,
6121 (int) BFD_RELOC_LO16, breg);
6126 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6127 treg, (int) BFD_RELOC_LO16);
6129 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6130 sreg, (int) BFD_RELOC_LO16);
6133 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
6135 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6136 dreg, (int) BFD_RELOC_LO16);
6141 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6143 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6144 sreg, (int) BFD_RELOC_LO16);
6149 as_warn (_("Instruction %s: result is always false"),
6151 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
6154 if (imm_expr.X_op == O_constant
6155 && imm_expr.X_add_number >= 0
6156 && imm_expr.X_add_number < 0x10000)
6158 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6159 sreg, (int) BFD_RELOC_LO16);
6162 else if (imm_expr.X_op == O_constant
6163 && imm_expr.X_add_number > -0x8000
6164 && imm_expr.X_add_number < 0)
6166 imm_expr.X_add_number = -imm_expr.X_add_number;
6167 macro_build ((char *) NULL, &icnt, &imm_expr,
6168 ((bfd_arch_bits_per_address (stdoutput) == 32
6169 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6170 ? "addiu" : "daddiu"),
6171 "t,r,j", dreg, sreg,
6172 (int) BFD_RELOC_LO16);
6177 load_register (&icnt, AT, &imm_expr, 0);
6178 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
6182 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6183 (int) BFD_RELOC_LO16);
6188 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6194 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg);
6195 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6196 (int) BFD_RELOC_LO16);
6199 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6201 if (imm_expr.X_op == O_constant
6202 && imm_expr.X_add_number >= -0x8000
6203 && imm_expr.X_add_number < 0x8000)
6205 macro_build ((char *) NULL, &icnt, &imm_expr,
6206 mask == M_SGE_I ? "slti" : "sltiu",
6207 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6212 load_register (&icnt, AT, &imm_expr, 0);
6213 macro_build ((char *) NULL, &icnt, NULL,
6214 mask == M_SGE_I ? "slt" : "sltu",
6215 "d,v,t", dreg, sreg, AT);
6218 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6219 (int) BFD_RELOC_LO16);
6224 case M_SGT: /* sreg > treg <==> treg < sreg */
6230 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
6233 case M_SGT_I: /* sreg > I <==> I < sreg */
6239 load_register (&icnt, AT, &imm_expr, 0);
6240 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
6243 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6249 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
6250 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6251 (int) BFD_RELOC_LO16);
6254 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6260 load_register (&icnt, AT, &imm_expr, 0);
6261 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
6262 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6263 (int) BFD_RELOC_LO16);
6267 if (imm_expr.X_op == O_constant
6268 && imm_expr.X_add_number >= -0x8000
6269 && imm_expr.X_add_number < 0x8000)
6271 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
6272 dreg, sreg, (int) BFD_RELOC_LO16);
6275 load_register (&icnt, AT, &imm_expr, 0);
6276 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT);
6280 if (imm_expr.X_op == O_constant
6281 && imm_expr.X_add_number >= -0x8000
6282 && imm_expr.X_add_number < 0x8000)
6284 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
6285 dreg, sreg, (int) BFD_RELOC_LO16);
6288 load_register (&icnt, AT, &imm_expr, 0);
6289 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg,
6295 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
6298 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
6302 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
6304 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
6310 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6312 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
6318 as_warn (_("Instruction %s: result is always true"),
6320 macro_build ((char *) NULL, &icnt, &expr1,
6321 ((bfd_arch_bits_per_address (stdoutput) == 32
6322 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6323 ? "addiu" : "daddiu"),
6324 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
6327 if (imm_expr.X_op == O_constant
6328 && imm_expr.X_add_number >= 0
6329 && imm_expr.X_add_number < 0x10000)
6331 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
6332 dreg, sreg, (int) BFD_RELOC_LO16);
6335 else if (imm_expr.X_op == O_constant
6336 && imm_expr.X_add_number > -0x8000
6337 && imm_expr.X_add_number < 0)
6339 imm_expr.X_add_number = -imm_expr.X_add_number;
6340 macro_build ((char *) NULL, &icnt, &imm_expr,
6341 ((bfd_arch_bits_per_address (stdoutput) == 32
6342 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6343 ? "addiu" : "daddiu"),
6344 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6349 load_register (&icnt, AT, &imm_expr, 0);
6350 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
6354 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
6362 if (imm_expr.X_op == O_constant
6363 && imm_expr.X_add_number > -0x8000
6364 && imm_expr.X_add_number <= 0x8000)
6366 imm_expr.X_add_number = -imm_expr.X_add_number;
6367 macro_build ((char *) NULL, &icnt, &imm_expr,
6368 dbl ? "daddi" : "addi",
6369 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6372 load_register (&icnt, AT, &imm_expr, dbl);
6373 macro_build ((char *) NULL, &icnt, NULL,
6374 dbl ? "dsub" : "sub",
6375 "d,v,t", dreg, sreg, AT);
6381 if (imm_expr.X_op == O_constant
6382 && imm_expr.X_add_number > -0x8000
6383 && imm_expr.X_add_number <= 0x8000)
6385 imm_expr.X_add_number = -imm_expr.X_add_number;
6386 macro_build ((char *) NULL, &icnt, &imm_expr,
6387 dbl ? "daddiu" : "addiu",
6388 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6391 load_register (&icnt, AT, &imm_expr, dbl);
6392 macro_build ((char *) NULL, &icnt, NULL,
6393 dbl ? "dsubu" : "subu",
6394 "d,v,t", dreg, sreg, AT);
6415 load_register (&icnt, AT, &imm_expr, 0);
6416 macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT);
6421 assert (mips_opts.isa == 1);
6422 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
6423 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
6426 * Is the double cfc1 instruction a bug in the mips assembler;
6427 * or is there a reason for it?
6429 mips_emit_delays (true);
6430 ++mips_opts.noreorder;
6431 mips_any_noreorder = 1;
6432 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
6433 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
6434 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6435 expr1.X_add_number = 3;
6436 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
6437 (int) BFD_RELOC_LO16);
6438 expr1.X_add_number = 2;
6439 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
6440 (int) BFD_RELOC_LO16);
6441 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31);
6442 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6443 macro_build ((char *) NULL, &icnt, NULL,
6444 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
6445 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31);
6446 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
6447 --mips_opts.noreorder;
6456 if (offset_expr.X_add_number >= 0x7fff)
6457 as_bad (_("operand overflow"));
6458 /* avoid load delay */
6459 if (! target_big_endian)
6460 offset_expr.X_add_number += 1;
6461 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6462 (int) BFD_RELOC_LO16, breg);
6463 if (! target_big_endian)
6464 offset_expr.X_add_number -= 1;
6466 offset_expr.X_add_number += 1;
6467 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
6468 (int) BFD_RELOC_LO16, breg);
6469 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
6470 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
6483 if (offset_expr.X_add_number >= 0x8000 - off)
6484 as_bad (_("operand overflow"));
6485 if (! target_big_endian)
6486 offset_expr.X_add_number += off;
6487 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6488 (int) BFD_RELOC_LO16, breg);
6489 if (! target_big_endian)
6490 offset_expr.X_add_number -= off;
6492 offset_expr.X_add_number += off;
6493 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
6494 (int) BFD_RELOC_LO16, breg);
6507 load_address (&icnt, AT, &offset_expr);
6509 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6510 ((bfd_arch_bits_per_address (stdoutput) == 32
6511 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6512 ? "addu" : "daddu"),
6513 "d,v,t", AT, AT, breg);
6514 if (! target_big_endian)
6515 expr1.X_add_number = off;
6517 expr1.X_add_number = 0;
6518 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
6519 (int) BFD_RELOC_LO16, AT);
6520 if (! target_big_endian)
6521 expr1.X_add_number = 0;
6523 expr1.X_add_number = off;
6524 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
6525 (int) BFD_RELOC_LO16, AT);
6530 load_address (&icnt, AT, &offset_expr);
6532 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6533 ((bfd_arch_bits_per_address (stdoutput) == 32
6534 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6535 ? "addu" : "daddu"),
6536 "d,v,t", AT, AT, breg);
6537 if (target_big_endian)
6538 expr1.X_add_number = 0;
6539 macro_build ((char *) NULL, &icnt, &expr1,
6540 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
6541 (int) BFD_RELOC_LO16, AT);
6542 if (target_big_endian)
6543 expr1.X_add_number = 1;
6545 expr1.X_add_number = 0;
6546 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
6547 (int) BFD_RELOC_LO16, AT);
6548 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
6550 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
6555 if (offset_expr.X_add_number >= 0x7fff)
6556 as_bad (_("operand overflow"));
6557 if (target_big_endian)
6558 offset_expr.X_add_number += 1;
6559 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
6560 (int) BFD_RELOC_LO16, breg);
6561 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8);
6562 if (target_big_endian)
6563 offset_expr.X_add_number -= 1;
6565 offset_expr.X_add_number += 1;
6566 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
6567 (int) BFD_RELOC_LO16, breg);
6580 if (offset_expr.X_add_number >= 0x8000 - off)
6581 as_bad (_("operand overflow"));
6582 if (! target_big_endian)
6583 offset_expr.X_add_number += off;
6584 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6585 (int) BFD_RELOC_LO16, breg);
6586 if (! target_big_endian)
6587 offset_expr.X_add_number -= off;
6589 offset_expr.X_add_number += off;
6590 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
6591 (int) BFD_RELOC_LO16, breg);
6604 load_address (&icnt, AT, &offset_expr);
6606 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6607 ((bfd_arch_bits_per_address (stdoutput) == 32
6608 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6609 ? "addu" : "daddu"),
6610 "d,v,t", AT, AT, breg);
6611 if (! target_big_endian)
6612 expr1.X_add_number = off;
6614 expr1.X_add_number = 0;
6615 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
6616 (int) BFD_RELOC_LO16, AT);
6617 if (! target_big_endian)
6618 expr1.X_add_number = 0;
6620 expr1.X_add_number = off;
6621 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
6622 (int) BFD_RELOC_LO16, AT);
6626 load_address (&icnt, AT, &offset_expr);
6628 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6629 ((bfd_arch_bits_per_address (stdoutput) == 32
6630 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
6631 ? "addu" : "daddu"),
6632 "d,v,t", AT, AT, breg);
6633 if (! target_big_endian)
6634 expr1.X_add_number = 0;
6635 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
6636 (int) BFD_RELOC_LO16, AT);
6637 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg,
6639 if (! target_big_endian)
6640 expr1.X_add_number = 1;
6642 expr1.X_add_number = 0;
6643 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
6644 (int) BFD_RELOC_LO16, AT);
6645 if (! target_big_endian)
6646 expr1.X_add_number = 0;
6648 expr1.X_add_number = 1;
6649 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
6650 (int) BFD_RELOC_LO16, AT);
6651 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
6653 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
6658 /* FIXME: Check if this is one of the itbl macros, since they
6659 are added dynamically. */
6660 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
6664 as_warn (_("Macro used $at after \".set noat\""));
6667 /* Implement macros in mips16 mode. */
6671 struct mips_cl_insn *ip;
6674 int xreg, yreg, zreg, tmp;
6678 const char *s, *s2, *s3;
6680 mask = ip->insn_mo->mask;
6682 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
6683 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
6684 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
6688 expr1.X_op = O_constant;
6689 expr1.X_op_symbol = NULL;
6690 expr1.X_add_symbol = NULL;
6691 expr1.X_add_number = 1;
6710 mips_emit_delays (true);
6711 ++mips_opts.noreorder;
6712 mips_any_noreorder = 1;
6713 macro_build ((char *) NULL, &icnt, NULL,
6714 dbl ? "ddiv" : "div",
6715 "0,x,y", xreg, yreg);
6716 expr1.X_add_number = 2;
6717 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
6718 macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7);
6720 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
6721 since that causes an overflow. We should do that as well,
6722 but I don't see how to do the comparisons without a temporary
6724 --mips_opts.noreorder;
6725 macro_build ((char *) NULL, &icnt, NULL, s, "x", zreg);
6744 mips_emit_delays (true);
6745 ++mips_opts.noreorder;
6746 mips_any_noreorder = 1;
6747 macro_build ((char *) NULL, &icnt, NULL, s, "0,x,y", xreg, yreg);
6748 expr1.X_add_number = 2;
6749 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
6750 macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7);
6751 --mips_opts.noreorder;
6752 macro_build ((char *) NULL, &icnt, NULL, s2, "x", zreg);
6758 macro_build ((char *) NULL, &icnt, NULL,
6759 dbl ? "dmultu" : "multu",
6761 macro_build ((char *) NULL, &icnt, NULL, "mflo", "x", zreg);
6769 if (imm_expr.X_op != O_constant)
6770 as_bad (_("Unsupported large constant"));
6771 imm_expr.X_add_number = -imm_expr.X_add_number;
6772 macro_build ((char *) NULL, &icnt, &imm_expr,
6773 dbl ? "daddiu" : "addiu",
6774 "y,x,4", yreg, xreg);
6778 if (imm_expr.X_op != O_constant)
6779 as_bad (_("Unsupported large constant"));
6780 imm_expr.X_add_number = -imm_expr.X_add_number;
6781 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
6786 if (imm_expr.X_op != O_constant)
6787 as_bad (_("Unsupported large constant"));
6788 imm_expr.X_add_number = -imm_expr.X_add_number;
6789 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
6812 goto do_reverse_branch;
6816 goto do_reverse_branch;
6828 goto do_reverse_branch;
6839 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
6841 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
6868 goto do_addone_branch_i;
6873 goto do_addone_branch_i;
6888 goto do_addone_branch_i;
6895 if (imm_expr.X_op != O_constant)
6896 as_bad (_("Unsupported large constant"));
6897 ++imm_expr.X_add_number;
6900 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
6901 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
6905 expr1.X_add_number = 0;
6906 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
6908 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6909 "move", "y,X", xreg, yreg);
6910 expr1.X_add_number = 2;
6911 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
6912 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6913 "neg", "x,w", xreg, xreg);
6917 /* For consistency checking, verify that all bits are specified either
6918 by the match/mask part of the instruction definition, or by the
6921 validate_mips_insn (opc)
6922 const struct mips_opcode *opc;
6924 const char *p = opc->args;
6926 unsigned long used_bits = opc->mask;
6928 if ((used_bits & opc->match) != opc->match)
6930 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
6931 opc->name, opc->args);
6934 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
6941 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
6942 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
6944 case 'B': USE_BITS (OP_MASK_SYSCALL, OP_SH_SYSCALL); break;
6945 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
6946 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
6947 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
6949 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
6952 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
6953 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
6954 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
6955 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
6956 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
6957 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
6958 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
6959 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
6960 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
6961 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
6962 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
6964 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
6965 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
6966 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
6967 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
6969 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
6970 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
6971 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
6972 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
6973 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
6974 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
6975 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
6976 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
6977 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
6980 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
6982 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
6983 c, opc->name, opc->args);
6987 if (used_bits != 0xffffffff)
6989 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
6990 ~used_bits & 0xffffffff, opc->name, opc->args);
6996 /* This routine assembles an instruction into its binary format. As a
6997 side effect, it sets one of the global variables imm_reloc or
6998 offset_reloc to the type of relocation to do if one of the operands
6999 is an address expression. */
7004 struct mips_cl_insn *ip;
7009 struct mips_opcode *insn;
7012 unsigned int lastregno = 0;
7015 int full_opcode_match = 1;
7019 /* If the instruction contains a '.', we first try to match an instruction
7020 including the '.'. Then we try again without the '.'. */
7022 for (s = str; *s != '\0' && !isspace ((unsigned char) *s); ++s)
7025 /* If we stopped on whitespace, then replace the whitespace with null for
7026 the call to hash_find. Save the character we replaced just in case we
7027 have to re-parse the instruction. */
7028 if (isspace ((unsigned char) *s))
7034 insn = (struct mips_opcode *) hash_find (op_hash, str);
7036 /* If we didn't find the instruction in the opcode table, try again, but
7037 this time with just the instruction up to, but not including the
7041 /* Restore the character we overwrite above (if any). */
7045 /* Scan up to the first '.' or whitespace. */
7046 for (s = str; *s != '\0' && *s != '.' && !isspace ((unsigned char) *s); ++s)
7049 /* If we did not find a '.', then we can quit now. */
7052 insn_error = "unrecognized opcode";
7056 /* Lookup the instruction in the hash table. */
7058 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7060 insn_error = "unrecognized opcode";
7064 full_opcode_match = 0;
7072 assert (strcmp (insn->name, str) == 0);
7074 if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_cpu, mips_gp32))
7079 if (insn->pinfo != INSN_MACRO)
7081 if (mips_cpu == 4650 && (insn->pinfo & FP_D) != 0)
7087 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7088 && strcmp (insn->name, insn[1].name) == 0)
7095 static char buf[100];
7097 _("opcode not supported on this processor: %d (MIPS%d)"),
7098 mips_cpu, mips_opts.isa);
7106 ip->insn_opcode = insn->match;
7107 for (args = insn->args;; ++args)
7113 case '\0': /* end of args */
7126 ip->insn_opcode |= lastregno << 21;
7131 ip->insn_opcode |= lastregno << 16;
7135 ip->insn_opcode |= lastregno << 11;
7141 /* Handle optional base register.
7142 Either the base register is omitted or
7143 we must have a left paren. */
7144 /* This is dependent on the next operand specifier
7145 is a base register specification. */
7146 assert (args[1] == 'b' || args[1] == '5'
7147 || args[1] == '-' || args[1] == '4');
7151 case ')': /* these must match exactly */
7156 case '<': /* must be at least one digit */
7158 * According to the manual, if the shift amount is greater
7159 * than 31 or less than 0 the the shift amount should be
7160 * mod 32. In reality the mips assembler issues an error.
7161 * We issue a warning and mask out all but the low 5 bits.
7163 my_getExpression (&imm_expr, s);
7164 check_absolute_expr (ip, &imm_expr);
7165 if ((unsigned long) imm_expr.X_add_number > 31)
7167 as_warn (_("Improper shift amount (%ld)"),
7168 (long) imm_expr.X_add_number);
7169 imm_expr.X_add_number = imm_expr.X_add_number & 0x1f;
7171 ip->insn_opcode |= imm_expr.X_add_number << 6;
7172 imm_expr.X_op = O_absent;
7176 case '>': /* shift amount minus 32 */
7177 my_getExpression (&imm_expr, s);
7178 check_absolute_expr (ip, &imm_expr);
7179 if ((unsigned long) imm_expr.X_add_number < 32
7180 || (unsigned long) imm_expr.X_add_number > 63)
7182 ip->insn_opcode |= (imm_expr.X_add_number - 32) << 6;
7183 imm_expr.X_op = O_absent;
7187 case 'k': /* cache code */
7188 case 'h': /* prefx code */
7189 my_getExpression (&imm_expr, s);
7190 check_absolute_expr (ip, &imm_expr);
7191 if ((unsigned long) imm_expr.X_add_number > 31)
7193 as_warn (_("Invalid value for `%s' (%lu)"),
7195 (unsigned long) imm_expr.X_add_number);
7196 imm_expr.X_add_number &= 0x1f;
7199 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7201 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7202 imm_expr.X_op = O_absent;
7206 case 'c': /* break code */
7207 my_getExpression (&imm_expr, s);
7208 check_absolute_expr (ip, &imm_expr);
7209 if ((unsigned) imm_expr.X_add_number > 1023)
7211 as_warn (_("Illegal break code (%ld)"),
7212 (long) imm_expr.X_add_number);
7213 imm_expr.X_add_number &= 0x3ff;
7215 ip->insn_opcode |= imm_expr.X_add_number << 16;
7216 imm_expr.X_op = O_absent;
7220 case 'q': /* lower break code */
7221 my_getExpression (&imm_expr, s);
7222 check_absolute_expr (ip, &imm_expr);
7223 if ((unsigned) imm_expr.X_add_number > 1023)
7225 as_warn (_("Illegal lower break code (%ld)"),
7226 (long) imm_expr.X_add_number);
7227 imm_expr.X_add_number &= 0x3ff;
7229 ip->insn_opcode |= imm_expr.X_add_number << 6;
7230 imm_expr.X_op = O_absent;
7234 case 'B': /* syscall code */
7235 my_getExpression (&imm_expr, s);
7236 check_absolute_expr (ip, &imm_expr);
7237 if ((unsigned) imm_expr.X_add_number > 0xfffff)
7238 as_warn (_("Illegal syscall code (%ld)"),
7239 (long) imm_expr.X_add_number);
7240 ip->insn_opcode |= imm_expr.X_add_number << 6;
7241 imm_expr.X_op = O_absent;
7245 case 'C': /* Coprocessor code */
7246 my_getExpression (&imm_expr, s);
7247 check_absolute_expr (ip, &imm_expr);
7248 if ((unsigned long) imm_expr.X_add_number >= (1<<25))
7250 as_warn (_("Coproccesor code > 25 bits (%ld)"),
7251 (long) imm_expr.X_add_number);
7252 imm_expr.X_add_number &= ((1<<25) - 1);
7254 ip->insn_opcode |= imm_expr.X_add_number;
7255 imm_expr.X_op = O_absent;
7259 case 'P': /* Performance register */
7260 my_getExpression (&imm_expr, s);
7261 check_absolute_expr (ip, &imm_expr);
7262 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
7264 as_warn (_("Invalidate performance regster (%ld)"),
7265 (long) imm_expr.X_add_number);
7266 imm_expr.X_add_number &= 1;
7268 ip->insn_opcode |= (imm_expr.X_add_number << 1);
7269 imm_expr.X_op = O_absent;
7273 case 'b': /* base register */
7274 case 'd': /* destination register */
7275 case 's': /* source register */
7276 case 't': /* target register */
7277 case 'r': /* both target and source */
7278 case 'v': /* both dest and source */
7279 case 'w': /* both dest and target */
7280 case 'E': /* coprocessor target register */
7281 case 'G': /* coprocessor destination register */
7282 case 'x': /* ignore register name */
7283 case 'z': /* must be zero register */
7288 if (isdigit ((unsigned char) s[1]))
7298 while (isdigit ((unsigned char) *s));
7300 as_bad (_("Invalid register number (%d)"), regno);
7302 else if (*args == 'E' || *args == 'G')
7306 if (s[1] == 'f' && s[2] == 'p')
7311 else if (s[1] == 's' && s[2] == 'p')
7316 else if (s[1] == 'g' && s[2] == 'p')
7321 else if (s[1] == 'a' && s[2] == 't')
7326 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
7331 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
7336 else if (itbl_have_entries)
7341 p = s + 1; /* advance past '$' */
7342 n = itbl_get_field (&p); /* n is name */
7344 /* See if this is a register defined in an
7346 if (itbl_get_reg_val (n, &r))
7348 /* Get_field advances to the start of
7349 the next field, so we need to back
7350 rack to the end of the last field. */
7354 s = strchr (s, '\0');
7367 as_warn (_("Used $at without \".set noat\""));
7373 if (c == 'r' || c == 'v' || c == 'w')
7380 /* 'z' only matches $0. */
7381 if (c == 'z' && regno != 0)
7384 /* Now that we have assembled one operand, we use the args string
7385 * to figure out where it goes in the instruction. */
7392 ip->insn_opcode |= regno << 21;
7396 ip->insn_opcode |= regno << 11;
7401 ip->insn_opcode |= regno << 16;
7404 /* This case exists because on the r3000 trunc
7405 expands into a macro which requires a gp
7406 register. On the r6000 or r4000 it is
7407 assembled into a single instruction which
7408 ignores the register. Thus the insn version
7409 is MIPS_ISA2 and uses 'x', and the macro
7410 version is MIPS_ISA1 and uses 't'. */
7413 /* This case is for the div instruction, which
7414 acts differently if the destination argument
7415 is $0. This only matches $0, and is checked
7416 outside the switch. */
7419 /* Itbl operand; not yet implemented. FIXME ?? */
7421 /* What about all other operands like 'i', which
7422 can be specified in the opcode table? */
7432 ip->insn_opcode |= lastregno << 21;
7435 ip->insn_opcode |= lastregno << 16;
7440 case 'D': /* floating point destination register */
7441 case 'S': /* floating point source register */
7442 case 'T': /* floating point target register */
7443 case 'R': /* floating point source register */
7447 if (s[0] == '$' && s[1] == 'f' && isdigit ((unsigned char) s[2]))
7457 while (isdigit ((unsigned char) *s));
7460 as_bad (_("Invalid float register number (%d)"), regno);
7462 if ((regno & 1) != 0
7463 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
7464 && ! (strcmp (str, "mtc1") == 0
7465 || strcmp (str, "mfc1") == 0
7466 || strcmp (str, "lwc1") == 0
7467 || strcmp (str, "swc1") == 0
7468 || strcmp (str, "l.s") == 0
7469 || strcmp (str, "s.s") == 0))
7470 as_warn (_("Float register should be even, was %d"),
7478 if (c == 'V' || c == 'W')
7488 ip->insn_opcode |= regno << 6;
7492 ip->insn_opcode |= regno << 11;
7496 ip->insn_opcode |= regno << 16;
7499 ip->insn_opcode |= regno << 21;
7509 ip->insn_opcode |= lastregno << 11;
7512 ip->insn_opcode |= lastregno << 16;
7518 my_getExpression (&imm_expr, s);
7519 if (imm_expr.X_op != O_big
7520 && imm_expr.X_op != O_constant)
7521 insn_error = _("absolute expression required");
7526 my_getExpression (&offset_expr, s);
7527 imm_reloc = BFD_RELOC_32;
7539 unsigned char temp[8];
7541 unsigned int length;
7546 /* These only appear as the last operand in an
7547 instruction, and every instruction that accepts
7548 them in any variant accepts them in all variants.
7549 This means we don't have to worry about backing out
7550 any changes if the instruction does not match.
7552 The difference between them is the size of the
7553 floating point constant and where it goes. For 'F'
7554 and 'L' the constant is 64 bits; for 'f' and 'l' it
7555 is 32 bits. Where the constant is placed is based
7556 on how the MIPS assembler does things:
7559 f -- immediate value
7562 The .lit4 and .lit8 sections are only used if
7563 permitted by the -G argument.
7565 When generating embedded PIC code, we use the
7566 .lit8 section but not the .lit4 section (we can do
7567 .lit4 inline easily; we need to put .lit8
7568 somewhere in the data segment, and using .lit8
7569 permits the linker to eventually combine identical
7572 f64 = *args == 'F' || *args == 'L';
7574 save_in = input_line_pointer;
7575 input_line_pointer = s;
7576 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
7578 s = input_line_pointer;
7579 input_line_pointer = save_in;
7580 if (err != NULL && *err != '\0')
7582 as_bad (_("Bad floating point constant: %s"), err);
7583 memset (temp, '\0', sizeof temp);
7584 length = f64 ? 8 : 4;
7587 assert (length == (f64 ? 8 : 4));
7591 && (! USE_GLOBAL_POINTER_OPT
7592 || mips_pic == EMBEDDED_PIC
7593 || g_switch_value < 4
7594 || (temp[0] == 0 && temp[1] == 0)
7595 || (temp[2] == 0 && temp[3] == 0))))
7597 imm_expr.X_op = O_constant;
7598 if (! target_big_endian)
7599 imm_expr.X_add_number = bfd_getl32 (temp);
7601 imm_expr.X_add_number = bfd_getb32 (temp);
7604 && ! mips_disable_float_construction
7605 && ((temp[0] == 0 && temp[1] == 0)
7606 || (temp[2] == 0 && temp[3] == 0))
7607 && ((temp[4] == 0 && temp[5] == 0)
7608 || (temp[6] == 0 && temp[7] == 0)))
7610 /* The value is simple enough to load with a
7611 couple of instructions. In mips1 mode, set
7612 imm_expr to the high order 32 bits and
7613 offset_expr to the low order 32 bits.
7614 Otherwise, set imm_expr to the entire 64 bit
7616 if (! ISA_HAS_64BIT_REGS (mips_opts.isa))
7618 imm_expr.X_op = O_constant;
7619 offset_expr.X_op = O_constant;
7620 if (! target_big_endian)
7622 imm_expr.X_add_number = bfd_getl32 (temp + 4);
7623 offset_expr.X_add_number = bfd_getl32 (temp);
7627 imm_expr.X_add_number = bfd_getb32 (temp);
7628 offset_expr.X_add_number = bfd_getb32 (temp + 4);
7630 if (offset_expr.X_add_number == 0)
7631 offset_expr.X_op = O_absent;
7633 else if (sizeof (imm_expr.X_add_number) > 4)
7635 imm_expr.X_op = O_constant;
7636 if (! target_big_endian)
7637 imm_expr.X_add_number = bfd_getl64 (temp);
7639 imm_expr.X_add_number = bfd_getb64 (temp);
7643 imm_expr.X_op = O_big;
7644 imm_expr.X_add_number = 4;
7645 if (! target_big_endian)
7647 generic_bignum[0] = bfd_getl16 (temp);
7648 generic_bignum[1] = bfd_getl16 (temp + 2);
7649 generic_bignum[2] = bfd_getl16 (temp + 4);
7650 generic_bignum[3] = bfd_getl16 (temp + 6);
7654 generic_bignum[0] = bfd_getb16 (temp + 6);
7655 generic_bignum[1] = bfd_getb16 (temp + 4);
7656 generic_bignum[2] = bfd_getb16 (temp + 2);
7657 generic_bignum[3] = bfd_getb16 (temp);
7663 const char *newname;
7666 /* Switch to the right section. */
7668 subseg = now_subseg;
7671 default: /* unused default case avoids warnings. */
7673 newname = RDATA_SECTION_NAME;
7674 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
7675 || mips_pic == EMBEDDED_PIC)
7679 if (mips_pic == EMBEDDED_PIC)
7682 newname = RDATA_SECTION_NAME;
7685 assert (!USE_GLOBAL_POINTER_OPT
7686 || g_switch_value >= 4);
7690 new_seg = subseg_new (newname, (subsegT) 0);
7691 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7692 bfd_set_section_flags (stdoutput, new_seg,
7697 frag_align (*args == 'l' ? 2 : 3, 0, 0);
7698 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
7699 && strcmp (TARGET_OS, "elf") != 0)
7700 record_alignment (new_seg, 4);
7702 record_alignment (new_seg, *args == 'l' ? 2 : 3);
7704 as_bad (_("Can't use floating point insn in this section"));
7706 /* Set the argument to the current address in the
7708 offset_expr.X_op = O_symbol;
7709 offset_expr.X_add_symbol =
7710 symbol_new ("L0\001", now_seg,
7711 (valueT) frag_now_fix (), frag_now);
7712 offset_expr.X_add_number = 0;
7714 /* Put the floating point number into the section. */
7715 p = frag_more ((int) length);
7716 memcpy (p, temp, length);
7718 /* Switch back to the original section. */
7719 subseg_set (seg, subseg);
7724 case 'i': /* 16 bit unsigned immediate */
7725 case 'j': /* 16 bit signed immediate */
7726 imm_reloc = BFD_RELOC_LO16;
7727 c = my_getSmallExpression (&imm_expr, s);
7732 if (imm_expr.X_op == O_constant)
7733 imm_expr.X_add_number =
7734 (imm_expr.X_add_number >> 16) & 0xffff;
7737 imm_reloc = BFD_RELOC_HI16_S;
7738 imm_unmatched_hi = true;
7741 imm_reloc = BFD_RELOC_HI16;
7743 else if (imm_expr.X_op == O_constant)
7744 imm_expr.X_add_number &= 0xffff;
7748 if ((c == '\0' && imm_expr.X_op != O_constant)
7749 || ((imm_expr.X_add_number < 0
7750 || imm_expr.X_add_number >= 0x10000)
7751 && imm_expr.X_op == O_constant))
7753 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7754 !strcmp (insn->name, insn[1].name))
7756 if (imm_expr.X_op == O_constant
7757 || imm_expr.X_op == O_big)
7758 as_bad (_("16 bit expression not in range 0..65535"));
7766 /* The upper bound should be 0x8000, but
7767 unfortunately the MIPS assembler accepts numbers
7768 from 0x8000 to 0xffff and sign extends them, and
7769 we want to be compatible. We only permit this
7770 extended range for an instruction which does not
7771 provide any further alternates, since those
7772 alternates may handle other cases. People should
7773 use the numbers they mean, rather than relying on
7774 a mysterious sign extension. */
7775 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7776 strcmp (insn->name, insn[1].name) == 0);
7781 if ((c == '\0' && imm_expr.X_op != O_constant)
7782 || ((imm_expr.X_add_number < -0x8000
7783 || imm_expr.X_add_number >= max)
7784 && imm_expr.X_op == O_constant)
7786 && imm_expr.X_add_number < 0
7787 && ISA_HAS_64BIT_REGS (mips_opts.isa)
7788 && imm_expr.X_unsigned
7789 && sizeof (imm_expr.X_add_number) <= 4))
7793 if (imm_expr.X_op == O_constant
7794 || imm_expr.X_op == O_big)
7795 as_bad (_("16 bit expression not in range -32768..32767"));
7801 case 'o': /* 16 bit offset */
7802 c = my_getSmallExpression (&offset_expr, s);
7804 /* If this value won't fit into a 16 bit offset, then go
7805 find a macro that will generate the 32 bit offset
7806 code pattern. As a special hack, we accept the
7807 difference of two local symbols as a constant. This
7808 is required to suppose embedded PIC switches, which
7809 use an instruction which looks like
7810 lw $4,$L12-$LS12($4)
7811 The problem with handling this in a more general
7812 fashion is that the macro function doesn't expect to
7813 see anything which can be handled in a single
7814 constant instruction. */
7816 && (offset_expr.X_op != O_constant
7817 || offset_expr.X_add_number >= 0x8000
7818 || offset_expr.X_add_number < -0x8000)
7819 && (mips_pic != EMBEDDED_PIC
7820 || offset_expr.X_op != O_subtract
7821 || (S_GET_SEGMENT (offset_expr.X_op_symbol)
7825 if (c == 'h' || c == 'H')
7827 if (offset_expr.X_op != O_constant)
7829 offset_expr.X_add_number =
7830 (offset_expr.X_add_number >> 16) & 0xffff;
7832 offset_reloc = BFD_RELOC_LO16;
7836 case 'p': /* pc relative offset */
7837 offset_reloc = BFD_RELOC_16_PCREL_S2;
7838 my_getExpression (&offset_expr, s);
7842 case 'u': /* upper 16 bits */
7843 c = my_getSmallExpression (&imm_expr, s);
7844 imm_reloc = BFD_RELOC_LO16;
7849 if (imm_expr.X_op == O_constant)
7850 imm_expr.X_add_number =
7851 (imm_expr.X_add_number >> 16) & 0xffff;
7854 imm_reloc = BFD_RELOC_HI16_S;
7855 imm_unmatched_hi = true;
7858 imm_reloc = BFD_RELOC_HI16;
7860 else if (imm_expr.X_op == O_constant)
7861 imm_expr.X_add_number &= 0xffff;
7863 if (imm_expr.X_op == O_constant
7864 && (imm_expr.X_add_number < 0
7865 || imm_expr.X_add_number >= 0x10000))
7866 as_bad (_("lui expression not in range 0..65535"));
7870 case 'a': /* 26 bit address */
7871 my_getExpression (&offset_expr, s);
7873 offset_reloc = BFD_RELOC_MIPS_JMP;
7876 case 'N': /* 3 bit branch condition code */
7877 case 'M': /* 3 bit compare condition code */
7878 if (strncmp (s, "$fcc", 4) != 0)
7888 while (isdigit ((unsigned char) *s));
7890 as_bad (_("invalid condition code register $fcc%d"), regno);
7892 ip->insn_opcode |= regno << OP_SH_BCC;
7894 ip->insn_opcode |= regno << OP_SH_CCC;
7898 as_bad (_("bad char = '%c'\n"), *args);
7903 /* Args don't match. */
7904 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
7905 !strcmp (insn->name, insn[1].name))
7911 insn_error = _("illegal operands");
7916 /* This routine assembles an instruction into its binary format when
7917 assembling for the mips16. As a side effect, it sets one of the
7918 global variables imm_reloc or offset_reloc to the type of
7919 relocation to do if one of the operands is an address expression.
7920 It also sets mips16_small and mips16_ext if the user explicitly
7921 requested a small or extended instruction. */
7926 struct mips_cl_insn *ip;
7930 struct mips_opcode *insn;
7933 unsigned int lastregno = 0;
7938 mips16_small = false;
7941 for (s = str; islower ((unsigned char) *s); ++s)
7953 if (s[1] == 't' && s[2] == ' ')
7956 mips16_small = true;
7960 else if (s[1] == 'e' && s[2] == ' ')
7969 insn_error = _("unknown opcode");
7973 if (mips_opts.noautoextend && ! mips16_ext)
7974 mips16_small = true;
7976 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
7978 insn_error = _("unrecognized opcode");
7985 assert (strcmp (insn->name, str) == 0);
7988 ip->insn_opcode = insn->match;
7989 ip->use_extend = false;
7990 imm_expr.X_op = O_absent;
7991 imm_reloc = BFD_RELOC_UNUSED;
7992 offset_expr.X_op = O_absent;
7993 offset_reloc = BFD_RELOC_UNUSED;
7994 for (args = insn->args; 1; ++args)
8001 /* In this switch statement we call break if we did not find
8002 a match, continue if we did find a match, or return if we
8011 /* Stuff the immediate value in now, if we can. */
8012 if (imm_expr.X_op == O_constant
8013 && imm_reloc > BFD_RELOC_UNUSED
8014 && insn->pinfo != INSN_MACRO)
8016 mips16_immed ((char *) NULL, 0,
8017 imm_reloc - BFD_RELOC_UNUSED,
8018 imm_expr.X_add_number, true, mips16_small,
8019 mips16_ext, &ip->insn_opcode,
8020 &ip->use_extend, &ip->extend);
8021 imm_expr.X_op = O_absent;
8022 imm_reloc = BFD_RELOC_UNUSED;
8036 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8039 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8055 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8057 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8074 if (isdigit ((unsigned char) s[1]))
8084 while (isdigit ((unsigned char) *s));
8087 as_bad (_("invalid register number (%d)"), regno);
8093 if (s[1] == 'f' && s[2] == 'p')
8098 else if (s[1] == 's' && s[2] == 'p')
8103 else if (s[1] == 'g' && s[2] == 'p')
8108 else if (s[1] == 'a' && s[2] == 't')
8113 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8118 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8131 if (c == 'v' || c == 'w')
8133 regno = mips16_to_32_reg_map[lastregno];
8147 regno = mips32_to_16_reg_map[regno];
8152 regno = ILLEGAL_REG;
8157 regno = ILLEGAL_REG;
8162 regno = ILLEGAL_REG;
8167 if (regno == AT && ! mips_opts.noat)
8168 as_warn (_("used $at without \".set noat\""));
8175 if (regno == ILLEGAL_REG)
8182 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
8186 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
8189 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
8192 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
8198 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
8201 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
8202 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
8212 if (strncmp (s, "$pc", 3) == 0)
8236 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
8238 /* This is %gprel(SYMBOL). We need to read SYMBOL,
8239 and generate the appropriate reloc. If the text
8240 inside %gprel is not a symbol name with an
8241 optional offset, then we generate a normal reloc
8242 and will probably fail later. */
8243 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
8244 if (imm_expr.X_op == O_symbol)
8247 imm_reloc = BFD_RELOC_MIPS16_GPREL;
8249 ip->use_extend = true;
8256 /* Just pick up a normal expression. */
8257 my_getExpression (&imm_expr, s);
8260 if (imm_expr.X_op == O_register)
8262 /* What we thought was an expression turned out to
8265 if (s[0] == '(' && args[1] == '(')
8267 /* It looks like the expression was omitted
8268 before a register indirection, which means
8269 that the expression is implicitly zero. We
8270 still set up imm_expr, so that we handle
8271 explicit extensions correctly. */
8272 imm_expr.X_op = O_constant;
8273 imm_expr.X_add_number = 0;
8274 imm_reloc = (int) BFD_RELOC_UNUSED + c;
8281 /* We need to relax this instruction. */
8282 imm_reloc = (int) BFD_RELOC_UNUSED + c;
8291 /* We use offset_reloc rather than imm_reloc for the PC
8292 relative operands. This lets macros with both
8293 immediate and address operands work correctly. */
8294 my_getExpression (&offset_expr, s);
8296 if (offset_expr.X_op == O_register)
8299 /* We need to relax this instruction. */
8300 offset_reloc = (int) BFD_RELOC_UNUSED + c;
8304 case '6': /* break code */
8305 my_getExpression (&imm_expr, s);
8306 check_absolute_expr (ip, &imm_expr);
8307 if ((unsigned long) imm_expr.X_add_number > 63)
8309 as_warn (_("Invalid value for `%s' (%lu)"),
8311 (unsigned long) imm_expr.X_add_number);
8312 imm_expr.X_add_number &= 0x3f;
8314 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
8315 imm_expr.X_op = O_absent;
8319 case 'a': /* 26 bit address */
8320 my_getExpression (&offset_expr, s);
8322 offset_reloc = BFD_RELOC_MIPS16_JMP;
8323 ip->insn_opcode <<= 16;
8326 case 'l': /* register list for entry macro */
8327 case 'L': /* register list for exit macro */
8337 int freg, reg1, reg2;
8339 while (*s == ' ' || *s == ',')
8343 as_bad (_("can't parse register list"));
8355 while (isdigit ((unsigned char) *s))
8377 as_bad (_("invalid register list"));
8382 while (isdigit ((unsigned char) *s))
8389 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
8394 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
8399 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
8400 mask |= (reg2 - 3) << 3;
8401 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
8402 mask |= (reg2 - 15) << 1;
8403 else if (reg1 == 31 && reg2 == 31)
8407 as_bad (_("invalid register list"));
8411 /* The mask is filled in in the opcode table for the
8412 benefit of the disassembler. We remove it before
8413 applying the actual mask. */
8414 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
8415 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
8419 case 'e': /* extend code */
8420 my_getExpression (&imm_expr, s);
8421 check_absolute_expr (ip, &imm_expr);
8422 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
8424 as_warn (_("Invalid value for `%s' (%lu)"),
8426 (unsigned long) imm_expr.X_add_number);
8427 imm_expr.X_add_number &= 0x7ff;
8429 ip->insn_opcode |= imm_expr.X_add_number;
8430 imm_expr.X_op = O_absent;
8440 /* Args don't match. */
8441 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
8442 strcmp (insn->name, insn[1].name) == 0)
8449 insn_error = _("illegal operands");
8455 /* This structure holds information we know about a mips16 immediate
8458 struct mips16_immed_operand
8460 /* The type code used in the argument string in the opcode table. */
8462 /* The number of bits in the short form of the opcode. */
8464 /* The number of bits in the extended form of the opcode. */
8466 /* The amount by which the short form is shifted when it is used;
8467 for example, the sw instruction has a shift count of 2. */
8469 /* The amount by which the short form is shifted when it is stored
8470 into the instruction code. */
8472 /* Non-zero if the short form is unsigned. */
8474 /* Non-zero if the extended form is unsigned. */
8476 /* Non-zero if the value is PC relative. */
8480 /* The mips16 immediate operand types. */
8482 static const struct mips16_immed_operand mips16_immed_operands[] =
8484 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
8485 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
8486 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
8487 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
8488 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
8489 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
8490 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
8491 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
8492 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
8493 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
8494 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
8495 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
8496 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
8497 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
8498 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
8499 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
8500 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
8501 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
8502 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
8503 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
8504 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
8507 #define MIPS16_NUM_IMMED \
8508 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
8510 /* Handle a mips16 instruction with an immediate value. This or's the
8511 small immediate value into *INSN. It sets *USE_EXTEND to indicate
8512 whether an extended value is needed; if one is needed, it sets
8513 *EXTEND to the value. The argument type is TYPE. The value is VAL.
8514 If SMALL is true, an unextended opcode was explicitly requested.
8515 If EXT is true, an extended opcode was explicitly requested. If
8516 WARN is true, warn if EXT does not match reality. */
8519 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
8528 unsigned long *insn;
8529 boolean *use_extend;
8530 unsigned short *extend;
8532 register const struct mips16_immed_operand *op;
8533 int mintiny, maxtiny;
8536 op = mips16_immed_operands;
8537 while (op->type != type)
8540 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
8545 if (type == '<' || type == '>' || type == '[' || type == ']')
8548 maxtiny = 1 << op->nbits;
8553 maxtiny = (1 << op->nbits) - 1;
8558 mintiny = - (1 << (op->nbits - 1));
8559 maxtiny = (1 << (op->nbits - 1)) - 1;
8562 /* Branch offsets have an implicit 0 in the lowest bit. */
8563 if (type == 'p' || type == 'q')
8566 if ((val & ((1 << op->shift) - 1)) != 0
8567 || val < (mintiny << op->shift)
8568 || val > (maxtiny << op->shift))
8573 if (warn && ext && ! needext)
8574 as_warn_where (file, line, _("extended operand requested but not required"));
8575 if (small && needext)
8576 as_bad_where (file, line, _("invalid unextended operand value"));
8578 if (small || (! ext && ! needext))
8582 *use_extend = false;
8583 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
8584 insnval <<= op->op_shift;
8589 long minext, maxext;
8595 maxext = (1 << op->extbits) - 1;
8599 minext = - (1 << (op->extbits - 1));
8600 maxext = (1 << (op->extbits - 1)) - 1;
8602 if (val < minext || val > maxext)
8603 as_bad_where (file, line,
8604 _("operand value out of range for instruction"));
8607 if (op->extbits == 16)
8609 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
8612 else if (op->extbits == 15)
8614 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
8619 extval = ((val & 0x1f) << 6) | (val & 0x20);
8623 *extend = (unsigned short) extval;
8632 my_getSmallExpression (ep, str)
8643 ((str[1] == 'h' && str[2] == 'i')
8644 || (str[1] == 'H' && str[2] == 'I')
8645 || (str[1] == 'l' && str[2] == 'o'))
8657 * A small expression may be followed by a base register.
8658 * Scan to the end of this operand, and then back over a possible
8659 * base register. Then scan the small expression up to that
8660 * point. (Based on code in sparc.c...)
8662 for (sp = str; *sp && *sp != ','; sp++)
8664 if (sp - 4 >= str && sp[-1] == RP)
8666 if (isdigit ((unsigned char) sp[-2]))
8668 for (sp -= 3; sp >= str && isdigit ((unsigned char) *sp); sp--)
8670 if (*sp == '$' && sp > str && sp[-1] == LP)
8676 else if (sp - 5 >= str
8679 && ((sp[-3] == 'f' && sp[-2] == 'p')
8680 || (sp[-3] == 's' && sp[-2] == 'p')
8681 || (sp[-3] == 'g' && sp[-2] == 'p')
8682 || (sp[-3] == 'a' && sp[-2] == 't')))
8688 /* no expression means zero offset */
8691 /* %xx(reg) is an error */
8692 ep->X_op = O_absent;
8697 ep->X_op = O_constant;
8700 ep->X_add_symbol = NULL;
8701 ep->X_op_symbol = NULL;
8702 ep->X_add_number = 0;
8707 my_getExpression (ep, str);
8714 my_getExpression (ep, str);
8715 return c; /* => %hi or %lo encountered */
8719 my_getExpression (ep, str)
8725 save_in = input_line_pointer;
8726 input_line_pointer = str;
8728 expr_end = input_line_pointer;
8729 input_line_pointer = save_in;
8731 /* If we are in mips16 mode, and this is an expression based on `.',
8732 then we bump the value of the symbol by 1 since that is how other
8733 text symbols are handled. We don't bother to handle complex
8734 expressions, just `.' plus or minus a constant. */
8735 if (mips_opts.mips16
8736 && ep->X_op == O_symbol
8737 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
8738 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
8739 && symbol_get_frag (ep->X_add_symbol) == frag_now
8740 && symbol_constant_p (ep->X_add_symbol)
8741 && S_GET_VALUE (ep->X_add_symbol) == frag_now_fix ())
8742 S_SET_VALUE (ep->X_add_symbol, S_GET_VALUE (ep->X_add_symbol) + 1);
8745 /* Turn a string in input_line_pointer into a floating point constant
8746 of type TYPE, and store the appropriate bytes in *LITP. The number
8747 of LITTLENUMS emitted is stored in *SIZEP. An error message is
8748 returned, or NULL on OK. */
8751 md_atof (type, litP, sizeP)
8757 LITTLENUM_TYPE words[4];
8773 return _("bad call to md_atof");
8776 t = atof_ieee (input_line_pointer, type, words);
8778 input_line_pointer = t;
8782 if (! target_big_endian)
8784 for (i = prec - 1; i >= 0; i--)
8786 md_number_to_chars (litP, (valueT) words[i], 2);
8792 for (i = 0; i < prec; i++)
8794 md_number_to_chars (litP, (valueT) words[i], 2);
8803 md_number_to_chars (buf, val, n)
8808 if (target_big_endian)
8809 number_to_chars_bigendian (buf, val, n);
8811 number_to_chars_littleendian (buf, val, n);
8814 CONST char *md_shortopts = "O::g::G:";
8816 struct option md_longopts[] = {
8817 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
8818 {"mips0", no_argument, NULL, OPTION_MIPS1},
8819 {"mips1", no_argument, NULL, OPTION_MIPS1},
8820 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
8821 {"mips2", no_argument, NULL, OPTION_MIPS2},
8822 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
8823 {"mips3", no_argument, NULL, OPTION_MIPS3},
8824 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
8825 {"mips4", no_argument, NULL, OPTION_MIPS4},
8826 #define OPTION_MCPU (OPTION_MD_BASE + 5)
8827 {"mcpu", required_argument, NULL, OPTION_MCPU},
8828 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 6)
8829 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
8831 #define OPTION_CALL_SHARED (OPTION_MD_BASE + 7)
8832 #define OPTION_NON_SHARED (OPTION_MD_BASE + 8)
8834 #define OPTION_TRAP (OPTION_MD_BASE + 9)
8835 {"trap", no_argument, NULL, OPTION_TRAP},
8836 {"no-break", no_argument, NULL, OPTION_TRAP},
8837 #define OPTION_BREAK (OPTION_MD_BASE + 10)
8838 {"break", no_argument, NULL, OPTION_BREAK},
8839 {"no-trap", no_argument, NULL, OPTION_BREAK},
8840 #define OPTION_EB (OPTION_MD_BASE + 11)
8841 {"EB", no_argument, NULL, OPTION_EB},
8842 #define OPTION_EL (OPTION_MD_BASE + 12)
8843 {"EL", no_argument, NULL, OPTION_EL},
8844 #define OPTION_M4650 (OPTION_MD_BASE + 13)
8845 {"m4650", no_argument, NULL, OPTION_M4650},
8846 #define OPTION_NO_M4650 (OPTION_MD_BASE + 14)
8847 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
8848 #define OPTION_M4010 (OPTION_MD_BASE + 15)
8849 {"m4010", no_argument, NULL, OPTION_M4010},
8850 #define OPTION_NO_M4010 (OPTION_MD_BASE + 16)
8851 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
8852 #define OPTION_M4100 (OPTION_MD_BASE + 17)
8853 {"m4100", no_argument, NULL, OPTION_M4100},
8854 #define OPTION_NO_M4100 (OPTION_MD_BASE + 18)
8855 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
8857 #define OPTION_XGOT (OPTION_MD_BASE + 19)
8858 #define OPTION_32 (OPTION_MD_BASE + 20)
8859 #define OPTION_64 (OPTION_MD_BASE + 21)
8861 #define OPTION_MIPS16 (OPTION_MD_BASE + 22)
8862 {"mips16", no_argument, NULL, OPTION_MIPS16},
8863 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 23)
8864 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
8866 #define OPTION_M3900 (OPTION_MD_BASE + 26)
8867 {"m3900", no_argument, NULL, OPTION_M3900},
8868 #define OPTION_NO_M3900 (OPTION_MD_BASE + 27)
8869 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
8871 #define OPTION_MABI (OPTION_MD_BASE + 38)
8872 {"mabi", required_argument, NULL, OPTION_MABI},
8874 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 39)
8875 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
8876 #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 40)
8877 {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX},
8880 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
8881 {"xgot", no_argument, NULL, OPTION_XGOT},
8882 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
8883 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
8884 {"32", no_argument, NULL, OPTION_32},
8885 {"64", no_argument, NULL, OPTION_64},
8888 #define OPTION_GP32 (OPTION_MD_BASE + 41)
8889 #define OPTION_GP64 (OPTION_MD_BASE + 42)
8890 {"mgp32", no_argument, NULL, OPTION_GP32},
8891 {"mgp64", no_argument, NULL, OPTION_GP64},
8893 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 43)
8894 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
8896 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 44)
8897 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
8899 {NULL, no_argument, NULL, 0}
8901 size_t md_longopts_size = sizeof(md_longopts);
8904 md_parse_option (c, arg)
8910 case OPTION_CONSTRUCT_FLOATS:
8911 mips_disable_float_construction = 0;
8914 case OPTION_NO_CONSTRUCT_FLOATS:
8915 mips_disable_float_construction = 1;
8927 target_big_endian = 1;
8931 target_big_endian = 0;
8935 if (arg && arg[1] == '0')
8945 mips_debug = atoi (arg);
8946 /* When the MIPS assembler sees -g or -g2, it does not do
8947 optimizations which limit full symbolic debugging. We take
8948 that to be equivalent to -O0. */
8949 if (mips_debug == 2)
8973 /* Identify the processor type */
8975 if (strcmp (p, "default") == 0
8976 || strcmp (p, "DEFAULT") == 0)
8982 /* We need to cope with the various "vr" prefixes for the 4300
8984 if (*p == 'v' || *p == 'V')
8990 if (*p == 'r' || *p == 'R')
8997 if (strcmp (p, "10000") == 0
8998 || strcmp (p, "10k") == 0
8999 || strcmp (p, "10K") == 0)
9004 if (strcmp (p, "2000") == 0
9005 || strcmp (p, "2k") == 0
9006 || strcmp (p, "2K") == 0)
9011 if (strcmp (p, "3000") == 0
9012 || strcmp (p, "3k") == 0
9013 || strcmp (p, "3K") == 0)
9015 else if (strcmp (p, "3900") == 0)
9020 if (strcmp (p, "4000") == 0
9021 || strcmp (p, "4k") == 0
9022 || strcmp (p, "4K") == 0)
9024 else if (strcmp (p, "4100") == 0)
9026 else if (strcmp (p, "4111") == 0)
9028 else if (strcmp (p, "4300") == 0)
9030 else if (strcmp (p, "4400") == 0)
9032 else if (strcmp (p, "4600") == 0)
9034 else if (strcmp (p, "4650") == 0)
9036 else if (strcmp (p, "4010") == 0)
9041 if (strcmp (p, "5000") == 0
9042 || strcmp (p, "5k") == 0
9043 || strcmp (p, "5K") == 0)
9048 if (strcmp (p, "6000") == 0
9049 || strcmp (p, "6k") == 0
9050 || strcmp (p, "6K") == 0)
9055 if (strcmp (p, "8000") == 0
9056 || strcmp (p, "8k") == 0
9057 || strcmp (p, "8K") == 0)
9062 if (strcmp (p, "orion") == 0)
9068 switch (atoi (p + 1))
9084 && (mips_cpu != 4300
9087 && mips_cpu != 5000))
9089 as_bad (_("ignoring invalid leading 'v' in -mcpu=%s switch"), arg);
9095 as_bad (_("invalid architecture -mcpu=%s"), arg);
9106 case OPTION_NO_M4650:
9113 case OPTION_NO_M4010:
9120 case OPTION_NO_M4100:
9127 case OPTION_NO_M3900:
9131 mips_opts.mips16 = 1;
9132 mips_no_prev_insn (false);
9135 case OPTION_NO_MIPS16:
9136 mips_opts.mips16 = 0;
9137 mips_no_prev_insn (false);
9140 case OPTION_MEMBEDDED_PIC:
9141 mips_pic = EMBEDDED_PIC;
9142 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
9144 as_bad (_("-G may not be used with embedded PIC code"));
9147 g_switch_value = 0x7fffffff;
9150 /* When generating ELF code, we permit -KPIC and -call_shared to
9151 select SVR4_PIC, and -non_shared to select no PIC. This is
9152 intended to be compatible with Irix 5. */
9153 case OPTION_CALL_SHARED:
9154 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9156 as_bad (_("-call_shared is supported only for ELF format"));
9159 mips_pic = SVR4_PIC;
9160 if (g_switch_seen && g_switch_value != 0)
9162 as_bad (_("-G may not be used with SVR4 PIC code"));
9168 case OPTION_NON_SHARED:
9169 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9171 as_bad (_("-non_shared is supported only for ELF format"));
9177 /* The -xgot option tells the assembler to use 32 offsets when
9178 accessing the got in SVR4_PIC mode. It is for Irix
9185 if (! USE_GLOBAL_POINTER_OPT)
9187 as_bad (_("-G is not supported for this configuration"));
9190 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
9192 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
9196 g_switch_value = atoi (arg);
9200 /* The -32 and -64 options tell the assembler to output the 32
9201 bit or the 64 bit MIPS ELF format. */
9208 const char **list, **l;
9210 list = bfd_target_list ();
9211 for (l = list; *l != NULL; l++)
9212 if (strcmp (*l, "elf64-bigmips") == 0
9213 || strcmp (*l, "elf64-littlemips") == 0)
9216 as_fatal (_("No compiled in support for 64 bit object file format"));
9226 /* We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
9227 flag in object files because to do so would make it
9228 impossible to link with libraries compiled without "-gp32".
9229 This is unnecessarily restrictive.
9231 We could solve this problem by adding "-gp32" multilibs to
9232 gcc, but to set this flag before gcc is built with such
9233 multilibs will break too many systems. */
9235 /* mips_32bitmode = 1; */
9241 /* mips_32bitmode = 0; */
9245 if (strcmp (arg,"32") == 0
9246 || strcmp (arg,"n32") == 0
9247 || strcmp (arg,"64") == 0
9248 || strcmp (arg,"o64") == 0
9249 || strcmp (arg,"eabi") == 0)
9250 mips_abi_string = arg;
9253 case OPTION_M7000_HILO_FIX:
9254 mips_7000_hilo_fix = true;
9257 case OPTION_NO_M7000_HILO_FIX:
9258 mips_7000_hilo_fix = false;
9269 show (stream, string, col_p, first_p)
9277 fprintf (stream, "%24s", "");
9282 fprintf (stream, ", ");
9286 if (*col_p + strlen (string) > 72)
9288 fprintf (stream, "\n%24s", "");
9292 fprintf (stream, "%s", string);
9293 *col_p += strlen (string);
9299 md_show_usage (stream)
9304 fprintf(stream, _("\
9306 -membedded-pic generate embedded position independent code\n\
9307 -EB generate big endian output\n\
9308 -EL generate little endian output\n\
9309 -g, -g2 do not remove uneeded NOPs or swap branches\n\
9310 -G NUM allow referencing objects up to NUM bytes\n\
9311 implicitly with the gp register [default 8]\n"));
9312 fprintf(stream, _("\
9313 -mips1 generate MIPS ISA I instructions\n\
9314 -mips2 generate MIPS ISA II instructions\n\
9315 -mips3 generate MIPS ISA III instructions\n\
9316 -mips4 generate MIPS ISA IV instructions\n\
9317 -mcpu=CPU generate code for CPU, where CPU is one of:\n"));
9321 show (stream, "2000", &column, &first);
9322 show (stream, "3000", &column, &first);
9323 show (stream, "3900", &column, &first);
9324 show (stream, "4000", &column, &first);
9325 show (stream, "4010", &column, &first);
9326 show (stream, "4100", &column, &first);
9327 show (stream, "4111", &column, &first);
9328 show (stream, "4300", &column, &first);
9329 show (stream, "4400", &column, &first);
9330 show (stream, "4600", &column, &first);
9331 show (stream, "4650", &column, &first);
9332 show (stream, "5000", &column, &first);
9333 show (stream, "6000", &column, &first);
9334 show (stream, "8000", &column, &first);
9335 show (stream, "10000", &column, &first);
9336 fputc ('\n', stream);
9338 fprintf (stream, _("\
9339 -mCPU equivalent to -mcpu=CPU.\n\
9340 -no-mCPU don't generate code specific to CPU.\n\
9341 For -mCPU and -no-mCPU, CPU must be one of:\n"));
9345 show (stream, "3900", &column, &first);
9346 show (stream, "4010", &column, &first);
9347 show (stream, "4100", &column, &first);
9348 show (stream, "4650", &column, &first);
9349 fputc ('\n', stream);
9351 fprintf(stream, _("\
9352 -mips16 generate mips16 instructions\n\
9353 -no-mips16 do not generate mips16 instructions\n"));
9354 fprintf(stream, _("\
9355 -O0 remove unneeded NOPs, do not swap branches\n\
9356 -O remove unneeded NOPs and swap branches\n\
9357 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
9358 --trap, --no-break trap exception on div by 0 and mult overflow\n\
9359 --break, --no-trap break exception on div by 0 and mult overflow\n"));
9361 fprintf(stream, _("\
9362 -KPIC, -call_shared generate SVR4 position independent code\n\
9363 -non_shared do not generate position independent code\n\
9364 -xgot assume a 32 bit GOT\n\
9365 -32 create 32 bit object file (default)\n\
9366 -64 create 64 bit object file\n"));
9371 mips_init_after_args ()
9373 /* initialize opcodes */
9374 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
9375 mips_opcodes = (struct mips_opcode*) mips_builtin_opcodes;
9379 md_pcrel_from (fixP)
9382 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
9383 && fixP->fx_addsy != (symbolS *) NULL
9384 && ! S_IS_DEFINED (fixP->fx_addsy))
9386 /* This makes a branch to an undefined symbol be a branch to the
9387 current location. */
9391 /* return the address of the delay slot */
9392 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
9395 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
9396 reloc for a cons. We could use the definition there, except that
9397 we want to handle 64 bit relocs specially. */
9400 cons_fix_new_mips (frag, where, nbytes, exp)
9401 fragS *frag ATTRIBUTE_UNUSED;
9403 unsigned int nbytes;
9407 /* If we are assembling in 32 bit mode, turn an 8 byte reloc into a
9409 if (nbytes == 8 && ! mips_64)
9411 if (target_big_endian)
9417 if (nbytes != 2 && nbytes != 4 && nbytes != 8)
9418 as_bad (_("Unsupported reloc size %d"), nbytes);
9420 fix_new_exp (frag_now, where, (int) nbytes, exp, 0,
9423 : (nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64)));
9426 /* This is called before the symbol table is processed. In order to
9427 work with gcc when using mips-tfile, we must keep all local labels.
9428 However, in other cases, we want to discard them. If we were
9429 called with -g, but we didn't see any debugging information, it may
9430 mean that gcc is smuggling debugging information through to
9431 mips-tfile, in which case we must generate all local labels. */
9434 mips_frob_file_before_adjust ()
9436 #ifndef NO_ECOFF_DEBUGGING
9439 && ! ecoff_debugging_seen)
9440 flag_keep_locals = 1;
9444 /* Sort any unmatched HI16_S relocs so that they immediately precede
9445 the corresponding LO reloc. This is called before md_apply_fix and
9446 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
9447 explicit use of the %hi modifier. */
9452 struct mips_hi_fixup *l;
9454 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
9456 segment_info_type *seginfo;
9459 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
9461 /* Check quickly whether the next fixup happens to be a matching
9463 if (l->fixp->fx_next != NULL
9464 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
9465 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
9466 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
9469 /* Look through the fixups for this segment for a matching %lo.
9470 When we find one, move the %hi just in front of it. We do
9471 this in two passes. In the first pass, we try to find a
9472 unique %lo. In the second pass, we permit multiple %hi
9473 relocs for a single %lo (this is a GNU extension). */
9474 seginfo = seg_info (l->seg);
9475 for (pass = 0; pass < 2; pass++)
9480 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
9482 /* Check whether this is a %lo fixup which matches l->fixp. */
9483 if (f->fx_r_type == BFD_RELOC_LO16
9484 && f->fx_addsy == l->fixp->fx_addsy
9485 && f->fx_offset == l->fixp->fx_offset
9488 || prev->fx_r_type != BFD_RELOC_HI16_S
9489 || prev->fx_addsy != f->fx_addsy
9490 || prev->fx_offset != f->fx_offset))
9494 /* Move l->fixp before f. */
9495 for (pf = &seginfo->fix_root;
9497 pf = &(*pf)->fx_next)
9498 assert (*pf != NULL);
9500 *pf = l->fixp->fx_next;
9502 l->fixp->fx_next = f;
9504 seginfo->fix_root = l->fixp;
9506 prev->fx_next = l->fixp;
9517 #if 0 /* GCC code motion plus incomplete dead code elimination
9518 can leave a %hi without a %lo. */
9520 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
9521 _("Unmatched %%hi reloc"));
9527 /* When generating embedded PIC code we need to use a special
9528 relocation to represent the difference of two symbols in the .text
9529 section (switch tables use a difference of this sort). See
9530 include/coff/mips.h for details. This macro checks whether this
9531 fixup requires the special reloc. */
9532 #define SWITCH_TABLE(fixp) \
9533 ((fixp)->fx_r_type == BFD_RELOC_32 \
9534 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
9535 && (fixp)->fx_addsy != NULL \
9536 && (fixp)->fx_subsy != NULL \
9537 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
9538 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
9540 /* When generating embedded PIC code we must keep all PC relative
9541 relocations, in case the linker has to relax a call. We also need
9542 to keep relocations for switch table entries. */
9546 mips_force_relocation (fixp)
9549 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
9550 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
9553 return (mips_pic == EMBEDDED_PIC
9555 || SWITCH_TABLE (fixp)
9556 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
9557 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
9560 /* Apply a fixup to the object file. */
9563 md_apply_fix (fixP, valueP)
9570 assert (fixP->fx_size == 4
9571 || fixP->fx_r_type == BFD_RELOC_16
9572 || fixP->fx_r_type == BFD_RELOC_64
9573 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
9574 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
9578 /* If we aren't adjusting this fixup to be against the section
9579 symbol, we need to adjust the value. */
9581 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
9583 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16
9584 || S_IS_WEAK (fixP->fx_addsy)
9585 || (symbol_used_in_reloc_p (fixP->fx_addsy)
9586 && (((bfd_get_section_flags (stdoutput,
9587 S_GET_SEGMENT (fixP->fx_addsy))
9588 & SEC_LINK_ONCE) != 0)
9589 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
9591 sizeof (".gnu.linkonce") - 1))))
9594 value -= S_GET_VALUE (fixP->fx_addsy);
9595 if (value != 0 && ! fixP->fx_pcrel)
9597 /* In this case, the bfd_install_relocation routine will
9598 incorrectly add the symbol value back in. We just want
9599 the addend to appear in the object file.
9600 FIXME: If this makes VALUE zero, we're toast. */
9601 value -= S_GET_VALUE (fixP->fx_addsy);
9605 /* This code was generated using trial and error and so is
9606 fragile and not trustworthy. If you change it, you should
9607 rerun the elf-rel, elf-rel2, and empic testcases and ensure
9609 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
9611 value += fixP->fx_frag->fr_address + fixP->fx_where;
9613 /* BFD's REL handling, for MIPS, is _very_ weird.
9614 This gives the right results, but it can't possibly
9615 be the way things are supposed to work. */
9616 if (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
9617 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
9618 value += fixP->fx_frag->fr_address + fixP->fx_where;
9623 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */
9625 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
9628 switch (fixP->fx_r_type)
9630 case BFD_RELOC_MIPS_JMP:
9631 case BFD_RELOC_HI16:
9632 case BFD_RELOC_HI16_S:
9633 case BFD_RELOC_MIPS_GPREL:
9634 case BFD_RELOC_MIPS_LITERAL:
9635 case BFD_RELOC_MIPS_CALL16:
9636 case BFD_RELOC_MIPS_GOT16:
9637 case BFD_RELOC_MIPS_GPREL32:
9638 case BFD_RELOC_MIPS_GOT_HI16:
9639 case BFD_RELOC_MIPS_GOT_LO16:
9640 case BFD_RELOC_MIPS_CALL_HI16:
9641 case BFD_RELOC_MIPS_CALL_LO16:
9642 case BFD_RELOC_MIPS16_GPREL:
9644 as_bad_where (fixP->fx_file, fixP->fx_line,
9645 _("Invalid PC relative reloc"));
9646 /* Nothing needed to do. The value comes from the reloc entry */
9649 case BFD_RELOC_MIPS16_JMP:
9650 /* We currently always generate a reloc against a symbol, which
9651 means that we don't want an addend even if the symbol is
9653 fixP->fx_addnumber = 0;
9656 case BFD_RELOC_PCREL_HI16_S:
9657 /* The addend for this is tricky if it is internal, so we just
9658 do everything here rather than in bfd_install_relocation. */
9659 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9664 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
9666 /* For an external symbol adjust by the address to make it
9667 pcrel_offset. We use the address of the RELLO reloc
9668 which follows this one. */
9669 value += (fixP->fx_next->fx_frag->fr_address
9670 + fixP->fx_next->fx_where);
9675 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9676 if (target_big_endian)
9678 md_number_to_chars (buf, value, 2);
9681 case BFD_RELOC_PCREL_LO16:
9682 /* The addend for this is tricky if it is internal, so we just
9683 do everything here rather than in bfd_install_relocation. */
9684 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9689 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
9690 value += fixP->fx_frag->fr_address + fixP->fx_where;
9691 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9692 if (target_big_endian)
9694 md_number_to_chars (buf, value, 2);
9698 /* This is handled like BFD_RELOC_32, but we output a sign
9699 extended value if we are only 32 bits. */
9701 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
9703 if (8 <= sizeof (valueT))
9704 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9711 w1 = w2 = fixP->fx_where;
9712 if (target_big_endian)
9716 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
9717 if ((value & 0x80000000) != 0)
9721 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
9728 /* If we are deleting this reloc entry, we must fill in the
9729 value now. This can happen if we have a .word which is not
9730 resolved when it appears but is later defined. We also need
9731 to fill in the value if this is an embedded PIC switch table
9734 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
9735 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9740 /* If we are deleting this reloc entry, we must fill in the
9742 assert (fixP->fx_size == 2);
9744 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
9748 case BFD_RELOC_LO16:
9749 /* When handling an embedded PIC switch statement, we can wind
9750 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
9753 if (value < -0x8000 || value > 0x7fff)
9754 as_bad_where (fixP->fx_file, fixP->fx_line,
9755 _("relocation overflow"));
9756 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
9757 if (target_big_endian)
9759 md_number_to_chars (buf, value, 2);
9763 case BFD_RELOC_16_PCREL_S2:
9765 * We need to save the bits in the instruction since fixup_segment()
9766 * might be deleting the relocation entry (i.e., a branch within
9767 * the current segment).
9769 if ((value & 0x3) != 0)
9770 as_bad_where (fixP->fx_file, fixP->fx_line,
9771 _("Branch to odd address (%lx)"), value);
9773 if (!fixP->fx_done && value != 0)
9775 /* If 'value' is zero, the remaining reloc code won't actually
9776 do the store, so it must be done here. This is probably
9779 value -= fixP->fx_frag->fr_address + fixP->fx_where;
9783 /* update old instruction data */
9784 buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal);
9785 if (target_big_endian)
9786 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
9788 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
9790 if (value >= -0x8000 && value < 0x8000)
9791 insn |= value & 0xffff;
9794 /* The branch offset is too large. If this is an
9795 unconditional branch, and we are not generating PIC code,
9796 we can convert it to an absolute jump instruction. */
9797 if (mips_pic == NO_PIC
9799 && fixP->fx_frag->fr_address >= text_section->vma
9800 && (fixP->fx_frag->fr_address
9801 < text_section->vma + text_section->_raw_size)
9802 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
9803 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
9804 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
9806 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
9807 insn = 0x0c000000; /* jal */
9809 insn = 0x08000000; /* j */
9810 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
9812 fixP->fx_addsy = section_symbol (text_section);
9813 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
9817 /* FIXME. It would be possible in principle to handle
9818 conditional branches which overflow. They could be
9819 transformed into a branch around a jump. This would
9820 require setting up variant frags for each different
9821 branch type. The native MIPS assembler attempts to
9822 handle these cases, but it appears to do it
9824 as_bad_where (fixP->fx_file, fixP->fx_line,
9825 _("Branch out of range"));
9829 md_number_to_chars ((char *) buf, (valueT) insn, 4);
9832 case BFD_RELOC_VTABLE_INHERIT:
9835 && !S_IS_DEFINED (fixP->fx_addsy)
9836 && !S_IS_WEAK (fixP->fx_addsy))
9837 S_SET_WEAK (fixP->fx_addsy);
9840 case BFD_RELOC_VTABLE_ENTRY:
9856 const struct mips_opcode *p;
9857 int treg, sreg, dreg, shamt;
9862 for (i = 0; i < NUMOPCODES; ++i)
9864 p = &mips_opcodes[i];
9865 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
9867 printf ("%08lx %s\t", oc, p->name);
9868 treg = (oc >> 16) & 0x1f;
9869 sreg = (oc >> 21) & 0x1f;
9870 dreg = (oc >> 11) & 0x1f;
9871 shamt = (oc >> 6) & 0x1f;
9873 for (args = p->args;; ++args)
9884 printf ("%c", *args);
9888 assert (treg == sreg);
9889 printf ("$%d,$%d", treg, sreg);
9894 printf ("$%d", dreg);
9899 printf ("$%d", treg);
9903 printf ("0x%x", treg);
9908 printf ("$%d", sreg);
9912 printf ("0x%08lx", oc & 0x1ffffff);
9924 printf ("$%d", shamt);
9935 printf (_("%08lx UNDEFINED\n"), oc);
9946 name = input_line_pointer;
9947 c = get_symbol_end ();
9948 p = (symbolS *) symbol_find_or_make (name);
9949 *input_line_pointer = c;
9953 /* Align the current frag to a given power of two. The MIPS assembler
9954 also automatically adjusts any preceding label. */
9957 mips_align (to, fill, label)
9962 mips_emit_delays (false);
9963 frag_align (to, fill, 0);
9964 record_alignment (now_seg, to);
9967 assert (S_GET_SEGMENT (label) == now_seg);
9968 symbol_set_frag (label, frag_now);
9969 S_SET_VALUE (label, (valueT) frag_now_fix ());
9973 /* Align to a given power of two. .align 0 turns off the automatic
9974 alignment used by the data creating pseudo-ops. */
9978 int x ATTRIBUTE_UNUSED;
9981 register long temp_fill;
9982 long max_alignment = 15;
9986 o Note that the assembler pulls down any immediately preceeding label
9987 to the aligned address.
9988 o It's not documented but auto alignment is reinstated by
9989 a .align pseudo instruction.
9990 o Note also that after auto alignment is turned off the mips assembler
9991 issues an error on attempt to assemble an improperly aligned data item.
9996 temp = get_absolute_expression ();
9997 if (temp > max_alignment)
9998 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
10001 as_warn (_("Alignment negative: 0 assumed."));
10004 if (*input_line_pointer == ',')
10006 input_line_pointer++;
10007 temp_fill = get_absolute_expression ();
10014 mips_align (temp, (int) temp_fill,
10015 insn_labels != NULL ? insn_labels->label : NULL);
10022 demand_empty_rest_of_line ();
10026 mips_flush_pending_output ()
10028 mips_emit_delays (false);
10029 mips_clear_insn_labels ();
10038 /* When generating embedded PIC code, we only use the .text, .lit8,
10039 .sdata and .sbss sections. We change the .data and .rdata
10040 pseudo-ops to use .sdata. */
10041 if (mips_pic == EMBEDDED_PIC
10042 && (sec == 'd' || sec == 'r'))
10046 /* The ELF backend needs to know that we are changing sections, so
10047 that .previous works correctly. We could do something like check
10048 for a obj_section_change_hook macro, but that might be confusing
10049 as it would not be appropriate to use it in the section changing
10050 functions in read.c, since obj-elf.c intercepts those. FIXME:
10051 This should be cleaner, somehow. */
10052 obj_elf_section_change_hook ();
10055 mips_emit_delays (false);
10065 subseg_set (bss_section, (subsegT) get_absolute_expression ());
10066 demand_empty_rest_of_line ();
10070 if (USE_GLOBAL_POINTER_OPT)
10072 seg = subseg_new (RDATA_SECTION_NAME,
10073 (subsegT) get_absolute_expression ());
10074 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
10076 bfd_set_section_flags (stdoutput, seg,
10082 if (strcmp (TARGET_OS, "elf") != 0)
10083 record_alignment (seg, 4);
10085 demand_empty_rest_of_line ();
10089 as_bad (_("No read only data section in this object file format"));
10090 demand_empty_rest_of_line ();
10096 if (USE_GLOBAL_POINTER_OPT)
10098 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
10099 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
10101 bfd_set_section_flags (stdoutput, seg,
10102 SEC_ALLOC | SEC_LOAD | SEC_RELOC
10104 if (strcmp (TARGET_OS, "elf") != 0)
10105 record_alignment (seg, 4);
10107 demand_empty_rest_of_line ();
10112 as_bad (_("Global pointers not supported; recompile -G 0"));
10113 demand_empty_rest_of_line ();
10122 mips_enable_auto_align ()
10133 label = insn_labels != NULL ? insn_labels->label : NULL;
10134 mips_emit_delays (false);
10135 if (log_size > 0 && auto_align)
10136 mips_align (log_size, 0, label);
10137 mips_clear_insn_labels ();
10138 cons (1 << log_size);
10142 s_float_cons (type)
10147 label = insn_labels != NULL ? insn_labels->label : NULL;
10149 mips_emit_delays (false);
10154 mips_align (3, 0, label);
10156 mips_align (2, 0, label);
10159 mips_clear_insn_labels ();
10164 /* Handle .globl. We need to override it because on Irix 5 you are
10167 where foo is an undefined symbol, to mean that foo should be
10168 considered to be the address of a function. */
10172 int x ATTRIBUTE_UNUSED;
10179 name = input_line_pointer;
10180 c = get_symbol_end ();
10181 symbolP = symbol_find_or_make (name);
10182 *input_line_pointer = c;
10183 SKIP_WHITESPACE ();
10185 /* On Irix 5, every global symbol that is not explicitly labelled as
10186 being a function is apparently labelled as being an object. */
10189 if (! is_end_of_line[(unsigned char) *input_line_pointer])
10194 secname = input_line_pointer;
10195 c = get_symbol_end ();
10196 sec = bfd_get_section_by_name (stdoutput, secname);
10198 as_bad (_("%s: no such section"), secname);
10199 *input_line_pointer = c;
10201 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
10202 flag = BSF_FUNCTION;
10205 symbol_get_bfdsym (symbolP)->flags |= flag;
10207 S_SET_EXTERNAL (symbolP);
10208 demand_empty_rest_of_line ();
10213 int x ATTRIBUTE_UNUSED;
10218 opt = input_line_pointer;
10219 c = get_symbol_end ();
10223 /* FIXME: What does this mean? */
10225 else if (strncmp (opt, "pic", 3) == 0)
10229 i = atoi (opt + 3);
10233 mips_pic = SVR4_PIC;
10235 as_bad (_(".option pic%d not supported"), i);
10237 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
10239 if (g_switch_seen && g_switch_value != 0)
10240 as_warn (_("-G may not be used with SVR4 PIC code"));
10241 g_switch_value = 0;
10242 bfd_set_gp_size (stdoutput, 0);
10246 as_warn (_("Unrecognized option \"%s\""), opt);
10248 *input_line_pointer = c;
10249 demand_empty_rest_of_line ();
10252 /* This structure is used to hold a stack of .set values. */
10254 struct mips_option_stack
10256 struct mips_option_stack *next;
10257 struct mips_set_options options;
10260 static struct mips_option_stack *mips_opts_stack;
10262 /* Handle the .set pseudo-op. */
10266 int x ATTRIBUTE_UNUSED;
10268 char *name = input_line_pointer, ch;
10270 while (!is_end_of_line[(unsigned char) *input_line_pointer])
10271 input_line_pointer++;
10272 ch = *input_line_pointer;
10273 *input_line_pointer = '\0';
10275 if (strcmp (name, "reorder") == 0)
10277 if (mips_opts.noreorder && prev_nop_frag != NULL)
10279 /* If we still have pending nops, we can discard them. The
10280 usual nop handling will insert any that are still
10282 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
10283 * (mips_opts.mips16 ? 2 : 4));
10284 prev_nop_frag = NULL;
10286 mips_opts.noreorder = 0;
10288 else if (strcmp (name, "noreorder") == 0)
10290 mips_emit_delays (true);
10291 mips_opts.noreorder = 1;
10292 mips_any_noreorder = 1;
10294 else if (strcmp (name, "at") == 0)
10296 mips_opts.noat = 0;
10298 else if (strcmp (name, "noat") == 0)
10300 mips_opts.noat = 1;
10302 else if (strcmp (name, "macro") == 0)
10304 mips_opts.warn_about_macros = 0;
10306 else if (strcmp (name, "nomacro") == 0)
10308 if (mips_opts.noreorder == 0)
10309 as_bad (_("`noreorder' must be set before `nomacro'"));
10310 mips_opts.warn_about_macros = 1;
10312 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
10314 mips_opts.nomove = 0;
10316 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
10318 mips_opts.nomove = 1;
10320 else if (strcmp (name, "bopt") == 0)
10322 mips_opts.nobopt = 0;
10324 else if (strcmp (name, "nobopt") == 0)
10326 mips_opts.nobopt = 1;
10328 else if (strcmp (name, "mips16") == 0
10329 || strcmp (name, "MIPS-16") == 0)
10330 mips_opts.mips16 = 1;
10331 else if (strcmp (name, "nomips16") == 0
10332 || strcmp (name, "noMIPS-16") == 0)
10333 mips_opts.mips16 = 0;
10334 else if (strncmp (name, "mips", 4) == 0)
10338 /* Permit the user to change the ISA on the fly. Needless to
10339 say, misuse can cause serious problems. */
10340 isa = atoi (name + 4);
10342 mips_opts.isa = file_mips_isa;
10343 else if (isa < 1 || isa > 4)
10344 as_bad (_("unknown ISA level"));
10346 mips_opts.isa = isa;
10348 else if (strcmp (name, "autoextend") == 0)
10349 mips_opts.noautoextend = 0;
10350 else if (strcmp (name, "noautoextend") == 0)
10351 mips_opts.noautoextend = 1;
10352 else if (strcmp (name, "push") == 0)
10354 struct mips_option_stack *s;
10356 s = (struct mips_option_stack *) xmalloc (sizeof *s);
10357 s->next = mips_opts_stack;
10358 s->options = mips_opts;
10359 mips_opts_stack = s;
10361 else if (strcmp (name, "pop") == 0)
10363 struct mips_option_stack *s;
10365 s = mips_opts_stack;
10367 as_bad (_(".set pop with no .set push"));
10370 /* If we're changing the reorder mode we need to handle
10371 delay slots correctly. */
10372 if (s->options.noreorder && ! mips_opts.noreorder)
10373 mips_emit_delays (true);
10374 else if (! s->options.noreorder && mips_opts.noreorder)
10376 if (prev_nop_frag != NULL)
10378 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
10379 * (mips_opts.mips16 ? 2 : 4));
10380 prev_nop_frag = NULL;
10384 mips_opts = s->options;
10385 mips_opts_stack = s->next;
10391 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
10393 *input_line_pointer = ch;
10394 demand_empty_rest_of_line ();
10397 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
10398 .option pic2. It means to generate SVR4 PIC calls. */
10401 s_abicalls (ignore)
10402 int ignore ATTRIBUTE_UNUSED;
10404 mips_pic = SVR4_PIC;
10405 if (USE_GLOBAL_POINTER_OPT)
10407 if (g_switch_seen && g_switch_value != 0)
10408 as_warn (_("-G may not be used with SVR4 PIC code"));
10409 g_switch_value = 0;
10411 bfd_set_gp_size (stdoutput, 0);
10412 demand_empty_rest_of_line ();
10415 /* Handle the .cpload pseudo-op. This is used when generating SVR4
10416 PIC code. It sets the $gp register for the function based on the
10417 function address, which is in the register named in the argument.
10418 This uses a relocation against _gp_disp, which is handled specially
10419 by the linker. The result is:
10420 lui $gp,%hi(_gp_disp)
10421 addiu $gp,$gp,%lo(_gp_disp)
10422 addu $gp,$gp,.cpload argument
10423 The .cpload argument is normally $25 == $t9. */
10427 int ignore ATTRIBUTE_UNUSED;
10432 /* If we are not generating SVR4 PIC code, .cpload is ignored. */
10433 if (mips_pic != SVR4_PIC)
10439 /* .cpload should be a in .set noreorder section. */
10440 if (mips_opts.noreorder == 0)
10441 as_warn (_(".cpload not in noreorder section"));
10443 ex.X_op = O_symbol;
10444 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
10445 ex.X_op_symbol = NULL;
10446 ex.X_add_number = 0;
10448 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
10449 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
10451 macro_build_lui ((char *) NULL, &icnt, &ex, GP);
10452 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP,
10453 (int) BFD_RELOC_LO16);
10455 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
10456 GP, GP, tc_get_register (0));
10458 demand_empty_rest_of_line ();
10461 /* Handle the .cprestore pseudo-op. This stores $gp into a given
10462 offset from $sp. The offset is remembered, and after making a PIC
10463 call $gp is restored from that location. */
10466 s_cprestore (ignore)
10467 int ignore ATTRIBUTE_UNUSED;
10472 /* If we are not generating SVR4 PIC code, .cprestore is ignored. */
10473 if (mips_pic != SVR4_PIC)
10479 mips_cprestore_offset = get_absolute_expression ();
10481 ex.X_op = O_constant;
10482 ex.X_add_symbol = NULL;
10483 ex.X_op_symbol = NULL;
10484 ex.X_add_number = mips_cprestore_offset;
10486 macro_build ((char *) NULL, &icnt, &ex,
10487 ((bfd_arch_bits_per_address (stdoutput) == 32
10488 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
10490 "t,o(b)", GP, (int) BFD_RELOC_LO16, SP);
10492 demand_empty_rest_of_line ();
10495 /* Handle the .gpword pseudo-op. This is used when generating PIC
10496 code. It generates a 32 bit GP relative reloc. */
10500 int ignore ATTRIBUTE_UNUSED;
10506 /* When not generating PIC code, this is treated as .word. */
10507 if (mips_pic != SVR4_PIC)
10513 label = insn_labels != NULL ? insn_labels->label : NULL;
10514 mips_emit_delays (true);
10516 mips_align (2, 0, label);
10517 mips_clear_insn_labels ();
10521 if (ex.X_op != O_symbol || ex.X_add_number != 0)
10523 as_bad (_("Unsupported use of .gpword"));
10524 ignore_rest_of_line ();
10528 md_number_to_chars (p, (valueT) 0, 4);
10529 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0,
10530 BFD_RELOC_MIPS_GPREL32);
10532 demand_empty_rest_of_line ();
10535 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
10536 tables in SVR4 PIC code. */
10540 int ignore ATTRIBUTE_UNUSED;
10545 /* This is ignored when not generating SVR4 PIC code. */
10546 if (mips_pic != SVR4_PIC)
10552 /* Add $gp to the register named as an argument. */
10553 reg = tc_get_register (0);
10554 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
10555 ((bfd_arch_bits_per_address (stdoutput) == 32
10556 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
10557 ? "addu" : "daddu"),
10558 "d,v,t", reg, reg, GP);
10560 demand_empty_rest_of_line ();
10563 /* Handle the .insn pseudo-op. This marks instruction labels in
10564 mips16 mode. This permits the linker to handle them specially,
10565 such as generating jalx instructions when needed. We also make
10566 them odd for the duration of the assembly, in order to generate the
10567 right sort of code. We will make them even in the adjust_symtab
10568 routine, while leaving them marked. This is convenient for the
10569 debugger and the disassembler. The linker knows to make them odd
10574 int ignore ATTRIBUTE_UNUSED;
10576 if (mips_opts.mips16)
10577 mips16_mark_labels ();
10579 demand_empty_rest_of_line ();
10582 /* Handle a .stabn directive. We need these in order to mark a label
10583 as being a mips16 text label correctly. Sometimes the compiler
10584 will emit a label, followed by a .stabn, and then switch sections.
10585 If the label and .stabn are in mips16 mode, then the label is
10586 really a mips16 text label. */
10592 if (type == 'n' && mips_opts.mips16)
10593 mips16_mark_labels ();
10598 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
10602 s_mips_weakext (ignore)
10603 int ignore ATTRIBUTE_UNUSED;
10610 name = input_line_pointer;
10611 c = get_symbol_end ();
10612 symbolP = symbol_find_or_make (name);
10613 S_SET_WEAK (symbolP);
10614 *input_line_pointer = c;
10616 SKIP_WHITESPACE ();
10618 if (! is_end_of_line[(unsigned char) *input_line_pointer])
10620 if (S_IS_DEFINED (symbolP))
10622 as_bad ("Ignoring attempt to redefine symbol `%s'.",
10623 S_GET_NAME (symbolP));
10624 ignore_rest_of_line ();
10628 if (*input_line_pointer == ',')
10630 ++input_line_pointer;
10631 SKIP_WHITESPACE ();
10635 if (exp.X_op != O_symbol)
10637 as_bad ("bad .weakext directive");
10638 ignore_rest_of_line();
10641 symbol_set_value_expression (symbolP, &exp);
10644 demand_empty_rest_of_line ();
10647 /* Parse a register string into a number. Called from the ECOFF code
10648 to parse .frame. The argument is non-zero if this is the frame
10649 register, so that we can record it in mips_frame_reg. */
10652 tc_get_register (frame)
10657 SKIP_WHITESPACE ();
10658 if (*input_line_pointer++ != '$')
10660 as_warn (_("expected `$'"));
10663 else if (isdigit ((unsigned char) *input_line_pointer))
10665 reg = get_absolute_expression ();
10666 if (reg < 0 || reg >= 32)
10668 as_warn (_("Bad register number"));
10674 if (strncmp (input_line_pointer, "fp", 2) == 0)
10676 else if (strncmp (input_line_pointer, "sp", 2) == 0)
10678 else if (strncmp (input_line_pointer, "gp", 2) == 0)
10680 else if (strncmp (input_line_pointer, "at", 2) == 0)
10684 as_warn (_("Unrecognized register name"));
10687 input_line_pointer += 2;
10690 mips_frame_reg = reg != 0 ? reg : SP;
10695 md_section_align (seg, addr)
10699 int align = bfd_get_section_alignment (stdoutput, seg);
10702 /* We don't need to align ELF sections to the full alignment.
10703 However, Irix 5 may prefer that we align them at least to a 16
10704 byte boundary. We don't bother to align the sections if we are
10705 targeted for an embedded system. */
10706 if (strcmp (TARGET_OS, "elf") == 0)
10712 return ((addr + (1 << align) - 1) & (-1 << align));
10715 /* Utility routine, called from above as well. If called while the
10716 input file is still being read, it's only an approximation. (For
10717 example, a symbol may later become defined which appeared to be
10718 undefined earlier.) */
10721 nopic_need_relax (sym, before_relaxing)
10723 int before_relaxing;
10728 if (USE_GLOBAL_POINTER_OPT)
10730 const char *symname;
10733 /* Find out whether this symbol can be referenced off the GP
10734 register. It can be if it is smaller than the -G size or if
10735 it is in the .sdata or .sbss section. Certain symbols can
10736 not be referenced off the GP, although it appears as though
10738 symname = S_GET_NAME (sym);
10739 if (symname != (const char *) NULL
10740 && (strcmp (symname, "eprol") == 0
10741 || strcmp (symname, "etext") == 0
10742 || strcmp (symname, "_gp") == 0
10743 || strcmp (symname, "edata") == 0
10744 || strcmp (symname, "_fbss") == 0
10745 || strcmp (symname, "_fdata") == 0
10746 || strcmp (symname, "_ftext") == 0
10747 || strcmp (symname, "end") == 0
10748 || strcmp (symname, "_gp_disp") == 0))
10750 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
10752 #ifndef NO_ECOFF_DEBUGGING
10753 || (symbol_get_obj (sym)->ecoff_extern_size != 0
10754 && (symbol_get_obj (sym)->ecoff_extern_size
10755 <= g_switch_value))
10757 /* We must defer this decision until after the whole
10758 file has been read, since there might be a .extern
10759 after the first use of this symbol. */
10760 || (before_relaxing
10761 #ifndef NO_ECOFF_DEBUGGING
10762 && symbol_get_obj (sym)->ecoff_extern_size == 0
10764 && S_GET_VALUE (sym) == 0)
10765 || (S_GET_VALUE (sym) != 0
10766 && S_GET_VALUE (sym) <= g_switch_value)))
10770 const char *segname;
10772 segname = segment_name (S_GET_SEGMENT (sym));
10773 assert (strcmp (segname, ".lit8") != 0
10774 && strcmp (segname, ".lit4") != 0);
10775 change = (strcmp (segname, ".sdata") != 0
10776 && strcmp (segname, ".sbss") != 0
10777 && strncmp (segname, ".sdata.", 7) != 0
10778 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
10783 /* We are not optimizing for the GP register. */
10787 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
10788 extended opcode. SEC is the section the frag is in. */
10791 mips16_extended_frag (fragp, sec, stretch)
10797 register const struct mips16_immed_operand *op;
10799 int mintiny, maxtiny;
10802 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
10804 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
10807 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
10808 op = mips16_immed_operands;
10809 while (op->type != type)
10812 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
10817 if (type == '<' || type == '>' || type == '[' || type == ']')
10820 maxtiny = 1 << op->nbits;
10825 maxtiny = (1 << op->nbits) - 1;
10830 mintiny = - (1 << (op->nbits - 1));
10831 maxtiny = (1 << (op->nbits - 1)) - 1;
10834 /* We can't always call S_GET_VALUE here, because we don't want to
10835 lock in a particular frag address. */
10836 if (symbol_constant_p (fragp->fr_symbol))
10838 val = (S_GET_VALUE (fragp->fr_symbol)
10839 + symbol_get_frag (fragp->fr_symbol)->fr_address);
10840 symsec = S_GET_SEGMENT (fragp->fr_symbol);
10842 else if (symbol_equated_p (fragp->fr_symbol)
10843 && (symbol_constant_p
10844 (symbol_get_value_expression (fragp->fr_symbol)->X_add_symbol)))
10848 eqsym = symbol_get_value_expression (fragp->fr_symbol)->X_add_symbol;
10849 val = (S_GET_VALUE (eqsym)
10850 + symbol_get_frag (eqsym)->fr_address
10851 + symbol_get_value_expression (fragp->fr_symbol)->X_add_number
10852 + symbol_get_frag (fragp->fr_symbol)->fr_address);
10853 symsec = S_GET_SEGMENT (eqsym);
10862 /* We won't have the section when we are called from
10863 mips_relax_frag. However, we will always have been called
10864 from md_estimate_size_before_relax first. If this is a
10865 branch to a different section, we mark it as such. If SEC is
10866 NULL, and the frag is not marked, then it must be a branch to
10867 the same section. */
10870 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
10877 fragp->fr_subtype =
10878 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
10880 /* FIXME: We should support this, and let the linker
10881 catch branches and loads that are out of range. */
10882 as_bad_where (fragp->fr_file, fragp->fr_line,
10883 _("unsupported PC relative reference to different section"));
10889 /* In this case, we know for sure that the symbol fragment is in
10890 the same section. If the fr_address of the symbol fragment
10891 is greater then the address of this fragment we want to add
10892 in STRETCH in order to get a better estimate of the address.
10893 This particularly matters because of the shift bits. */
10895 && (symbol_get_frag (fragp->fr_symbol)->fr_address
10896 >= fragp->fr_address))
10900 /* Adjust stretch for any alignment frag. Note that if have
10901 been expanding the earlier code, the symbol may be
10902 defined in what appears to be an earlier frag. FIXME:
10903 This doesn't handle the fr_subtype field, which specifies
10904 a maximum number of bytes to skip when doing an
10907 f != NULL && f != symbol_get_frag (fragp->fr_symbol);
10910 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
10913 stretch = - ((- stretch)
10914 & ~ ((1 << (int) f->fr_offset) - 1));
10916 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
10925 addr = fragp->fr_address + fragp->fr_fix;
10927 /* The base address rules are complicated. The base address of
10928 a branch is the following instruction. The base address of a
10929 PC relative load or add is the instruction itself, but if it
10930 is in a delay slot (in which case it can not be extended) use
10931 the address of the instruction whose delay slot it is in. */
10932 if (type == 'p' || type == 'q')
10936 /* If we are currently assuming that this frag should be
10937 extended, then, the current address is two bytes
10939 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
10942 /* Ignore the low bit in the target, since it will be set
10943 for a text label. */
10944 if ((val & 1) != 0)
10947 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
10949 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
10952 val -= addr & ~ ((1 << op->shift) - 1);
10954 /* Branch offsets have an implicit 0 in the lowest bit. */
10955 if (type == 'p' || type == 'q')
10958 /* If any of the shifted bits are set, we must use an extended
10959 opcode. If the address depends on the size of this
10960 instruction, this can lead to a loop, so we arrange to always
10961 use an extended opcode. We only check this when we are in
10962 the main relaxation loop, when SEC is NULL. */
10963 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
10965 fragp->fr_subtype =
10966 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
10970 /* If we are about to mark a frag as extended because the value
10971 is precisely maxtiny + 1, then there is a chance of an
10972 infinite loop as in the following code:
10977 In this case when the la is extended, foo is 0x3fc bytes
10978 away, so the la can be shrunk, but then foo is 0x400 away, so
10979 the la must be extended. To avoid this loop, we mark the
10980 frag as extended if it was small, and is about to become
10981 extended with a value of maxtiny + 1. */
10982 if (val == ((maxtiny + 1) << op->shift)
10983 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
10986 fragp->fr_subtype =
10987 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
10991 else if (symsec != absolute_section && sec != NULL)
10992 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
10994 if ((val & ((1 << op->shift) - 1)) != 0
10995 || val < (mintiny << op->shift)
10996 || val > (maxtiny << op->shift))
11002 /* Estimate the size of a frag before relaxing. Unless this is the
11003 mips16, we are not really relaxing here, and the final size is
11004 encoded in the subtype information. For the mips16, we have to
11005 decide whether we are using an extended opcode or not. */
11009 md_estimate_size_before_relax (fragp, segtype)
11014 boolean linkonce = false;
11016 if (RELAX_MIPS16_P (fragp->fr_subtype))
11018 if (mips16_extended_frag (fragp, segtype, 0))
11020 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
11025 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
11030 if (mips_pic == NO_PIC)
11032 change = nopic_need_relax (fragp->fr_symbol, 0);
11034 else if (mips_pic == SVR4_PIC)
11039 sym = fragp->fr_symbol;
11041 /* Handle the case of a symbol equated to another symbol. */
11042 while (symbol_equated_p (sym)
11043 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
11047 /* It's possible to get a loop here in a badly written
11049 n = symbol_get_value_expression (sym)->X_add_symbol;
11055 symsec = S_GET_SEGMENT (sym);
11057 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
11058 if (symsec != segtype && ! S_IS_LOCAL (sym))
11060 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
11064 /* The GNU toolchain uses an extension for ELF: a section
11065 beginning with the magic string .gnu.linkonce is a linkonce
11067 if (strncmp (segment_name (symsec), ".gnu.linkonce",
11068 sizeof ".gnu.linkonce" - 1) == 0)
11072 /* This must duplicate the test in adjust_reloc_syms. */
11073 change = (symsec != &bfd_und_section
11074 && symsec != &bfd_abs_section
11075 && ! bfd_is_com_section (symsec)
11078 /* A weak symbol is treated as external. */
11079 && ! S_IS_WEAK (sym)
11088 /* Record the offset to the first reloc in the fr_opcode field.
11089 This lets md_convert_frag and tc_gen_reloc know that the code
11090 must be expanded. */
11091 fragp->fr_opcode = (fragp->fr_literal
11093 - RELAX_OLD (fragp->fr_subtype)
11094 + RELAX_RELOC1 (fragp->fr_subtype));
11095 /* FIXME: This really needs as_warn_where. */
11096 if (RELAX_WARN (fragp->fr_subtype))
11097 as_warn (_("AT used after \".set noat\" or macro used after \".set nomacro\""));
11103 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
11106 /* This is called to see whether a reloc against a defined symbol
11107 should be converted into a reloc against a section. Don't adjust
11108 MIPS16 jump relocations, so we don't have to worry about the format
11109 of the offset in the .o file. Don't adjust relocations against
11110 mips16 symbols, so that the linker can find them if it needs to set
11114 mips_fix_adjustable (fixp)
11117 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
11119 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11120 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11122 if (fixp->fx_addsy == NULL)
11125 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
11126 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
11127 && fixp->fx_subsy == NULL)
11133 /* Translate internal representation of relocation info to BFD target
11137 tc_gen_reloc (section, fixp)
11138 asection *section ATTRIBUTE_UNUSED;
11141 static arelent *retval[4];
11143 bfd_reloc_code_real_type code;
11145 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
11148 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11149 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11150 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11152 if (mips_pic == EMBEDDED_PIC
11153 && SWITCH_TABLE (fixp))
11155 /* For a switch table entry we use a special reloc. The addend
11156 is actually the difference between the reloc address and the
11158 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
11159 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
11160 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
11161 fixp->fx_r_type = BFD_RELOC_GPREL32;
11163 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11164 reloc->addend = fixp->fx_addnumber;
11165 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
11167 /* We use a special addend for an internal RELLO reloc. */
11168 if (symbol_section_p (fixp->fx_addsy))
11169 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
11171 reloc->addend = fixp->fx_addnumber + reloc->address;
11173 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
11175 assert (fixp->fx_next != NULL
11176 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
11177 /* We use a special addend for an internal RELHI reloc. The
11178 reloc is relative to the RELLO; adjust the addend
11180 if (symbol_section_p (fixp->fx_addsy))
11181 reloc->addend = (fixp->fx_next->fx_frag->fr_address
11182 + fixp->fx_next->fx_where
11183 - S_GET_VALUE (fixp->fx_subsy));
11185 reloc->addend = (fixp->fx_addnumber
11186 + fixp->fx_next->fx_frag->fr_address
11187 + fixp->fx_next->fx_where);
11191 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
11192 /* A gruesome hack which is a result of the gruesome gas reloc
11194 reloc->addend = reloc->address;
11196 reloc->addend = -reloc->address;
11199 /* If this is a variant frag, we may need to adjust the existing
11200 reloc and generate a new one. */
11201 if (fixp->fx_frag->fr_opcode != NULL
11202 && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
11203 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
11204 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
11205 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
11206 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
11207 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
11208 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16))
11212 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
11214 /* If this is not the last reloc in this frag, then we have two
11215 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
11216 CALL_HI16/CALL_LO16, both of which are being replaced. Let
11217 the second one handle all of them. */
11218 if (fixp->fx_next != NULL
11219 && fixp->fx_frag == fixp->fx_next->fx_frag)
11221 assert ((fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
11222 && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL)
11223 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
11224 && (fixp->fx_next->fx_r_type
11225 == BFD_RELOC_MIPS_GOT_LO16))
11226 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
11227 && (fixp->fx_next->fx_r_type
11228 == BFD_RELOC_MIPS_CALL_LO16)));
11233 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
11234 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11235 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
11237 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11238 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11239 reloc2->address = (reloc->address
11240 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
11241 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
11242 reloc2->addend = fixp->fx_addnumber;
11243 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
11244 assert (reloc2->howto != NULL);
11246 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
11250 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
11253 reloc3->address += 4;
11256 if (mips_pic == NO_PIC)
11258 assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL);
11259 fixp->fx_r_type = BFD_RELOC_HI16_S;
11261 else if (mips_pic == SVR4_PIC)
11263 switch (fixp->fx_r_type)
11267 case BFD_RELOC_MIPS_GOT16:
11269 case BFD_RELOC_MIPS_CALL16:
11270 case BFD_RELOC_MIPS_GOT_LO16:
11271 case BFD_RELOC_MIPS_CALL_LO16:
11272 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
11280 /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry
11281 to be used in the relocation's section offset. */
11282 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11284 reloc->address = reloc->addend;
11288 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
11289 fixup_segment converted a non-PC relative reloc into a PC
11290 relative reloc. In such a case, we need to convert the reloc
11292 code = fixp->fx_r_type;
11293 if (fixp->fx_pcrel)
11298 code = BFD_RELOC_8_PCREL;
11301 code = BFD_RELOC_16_PCREL;
11304 code = BFD_RELOC_32_PCREL;
11307 code = BFD_RELOC_64_PCREL;
11309 case BFD_RELOC_8_PCREL:
11310 case BFD_RELOC_16_PCREL:
11311 case BFD_RELOC_32_PCREL:
11312 case BFD_RELOC_64_PCREL:
11313 case BFD_RELOC_16_PCREL_S2:
11314 case BFD_RELOC_PCREL_HI16_S:
11315 case BFD_RELOC_PCREL_LO16:
11318 as_bad_where (fixp->fx_file, fixp->fx_line,
11319 _("Cannot make %s relocation PC relative"),
11320 bfd_get_reloc_code_name (code));
11324 /* To support a PC relative reloc when generating embedded PIC code
11325 for ECOFF, we use a Cygnus extension. We check for that here to
11326 make sure that we don't let such a reloc escape normally. */
11327 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
11328 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11329 && code == BFD_RELOC_16_PCREL_S2
11330 && mips_pic != EMBEDDED_PIC)
11331 reloc->howto = NULL;
11333 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
11335 if (reloc->howto == NULL)
11337 as_bad_where (fixp->fx_file, fixp->fx_line,
11338 _("Can not represent %s relocation in this object file format"),
11339 bfd_get_reloc_code_name (code));
11346 /* Relax a machine dependent frag. This returns the amount by which
11347 the current size of the frag should change. */
11350 mips_relax_frag (fragp, stretch)
11354 if (! RELAX_MIPS16_P (fragp->fr_subtype))
11357 if (mips16_extended_frag (fragp, (asection *) NULL, stretch))
11359 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
11361 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
11366 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
11368 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
11375 /* Convert a machine dependent frag. */
11378 md_convert_frag (abfd, asec, fragp)
11379 bfd *abfd ATTRIBUTE_UNUSED;
11386 if (RELAX_MIPS16_P (fragp->fr_subtype))
11389 register const struct mips16_immed_operand *op;
11390 boolean small, ext;
11393 unsigned long insn;
11394 boolean use_extend;
11395 unsigned short extend;
11397 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
11398 op = mips16_immed_operands;
11399 while (op->type != type)
11402 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
11413 resolve_symbol_value (fragp->fr_symbol, 1);
11414 val = S_GET_VALUE (fragp->fr_symbol);
11419 addr = fragp->fr_address + fragp->fr_fix;
11421 /* The rules for the base address of a PC relative reloc are
11422 complicated; see mips16_extended_frag. */
11423 if (type == 'p' || type == 'q')
11428 /* Ignore the low bit in the target, since it will be
11429 set for a text label. */
11430 if ((val & 1) != 0)
11433 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
11435 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
11438 addr &= ~ (addressT) ((1 << op->shift) - 1);
11441 /* Make sure the section winds up with the alignment we have
11444 record_alignment (asec, op->shift);
11448 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
11449 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
11450 as_warn_where (fragp->fr_file, fragp->fr_line,
11451 _("extended instruction in delay slot"));
11453 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
11455 if (target_big_endian)
11456 insn = bfd_getb16 (buf);
11458 insn = bfd_getl16 (buf);
11460 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
11461 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
11462 small, ext, &insn, &use_extend, &extend);
11466 md_number_to_chars (buf, 0xf000 | extend, 2);
11467 fragp->fr_fix += 2;
11471 md_number_to_chars (buf, insn, 2);
11472 fragp->fr_fix += 2;
11477 if (fragp->fr_opcode == NULL)
11480 old = RELAX_OLD (fragp->fr_subtype);
11481 new = RELAX_NEW (fragp->fr_subtype);
11482 fixptr = fragp->fr_literal + fragp->fr_fix;
11485 memcpy (fixptr - old, fixptr, new);
11487 fragp->fr_fix += new - old;
11493 /* This function is called after the relocs have been generated.
11494 We've been storing mips16 text labels as odd. Here we convert them
11495 back to even for the convenience of the debugger. */
11498 mips_frob_file_after_relocs ()
11501 unsigned int count, i;
11503 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11506 syms = bfd_get_outsymbols (stdoutput);
11507 count = bfd_get_symcount (stdoutput);
11508 for (i = 0; i < count; i++, syms++)
11510 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
11511 && ((*syms)->value & 1) != 0)
11513 (*syms)->value &= ~1;
11514 /* If the symbol has an odd size, it was probably computed
11515 incorrectly, so adjust that as well. */
11516 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
11517 ++elf_symbol (*syms)->internal_elf_sym.st_size;
11524 /* This function is called whenever a label is defined. It is used
11525 when handling branch delays; if a branch has a label, we assume we
11526 can not move it. */
11529 mips_define_label (sym)
11532 struct insn_label_list *l;
11534 if (free_insn_labels == NULL)
11535 l = (struct insn_label_list *) xmalloc (sizeof *l);
11538 l = free_insn_labels;
11539 free_insn_labels = l->next;
11543 l->next = insn_labels;
11547 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
11549 /* Some special processing for a MIPS ELF file. */
11552 mips_elf_final_processing ()
11554 /* Write out the register information. */
11559 s.ri_gprmask = mips_gprmask;
11560 s.ri_cprmask[0] = mips_cprmask[0];
11561 s.ri_cprmask[1] = mips_cprmask[1];
11562 s.ri_cprmask[2] = mips_cprmask[2];
11563 s.ri_cprmask[3] = mips_cprmask[3];
11564 /* The gp_value field is set by the MIPS ELF backend. */
11566 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
11567 ((Elf32_External_RegInfo *)
11568 mips_regmask_frag));
11572 Elf64_Internal_RegInfo s;
11574 s.ri_gprmask = mips_gprmask;
11576 s.ri_cprmask[0] = mips_cprmask[0];
11577 s.ri_cprmask[1] = mips_cprmask[1];
11578 s.ri_cprmask[2] = mips_cprmask[2];
11579 s.ri_cprmask[3] = mips_cprmask[3];
11580 /* The gp_value field is set by the MIPS ELF backend. */
11582 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
11583 ((Elf64_External_RegInfo *)
11584 mips_regmask_frag));
11587 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
11588 sort of BFD interface for this. */
11589 if (mips_any_noreorder)
11590 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
11591 if (mips_pic != NO_PIC)
11592 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
11594 /* Set the MIPS ELF ABI flags. */
11595 if (mips_abi_string == 0)
11597 else if (strcmp (mips_abi_string,"32") == 0)
11598 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
11599 else if (strcmp (mips_abi_string,"o64") == 0)
11600 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
11601 else if (strcmp (mips_abi_string,"eabi") == 0)
11604 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
11606 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
11609 if (mips_32bitmode)
11610 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
11613 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
11615 typedef struct proc
11618 unsigned long reg_mask;
11619 unsigned long reg_offset;
11620 unsigned long fpreg_mask;
11621 unsigned long fpreg_offset;
11622 unsigned long frame_offset;
11623 unsigned long frame_reg;
11624 unsigned long pc_reg;
11628 static procS cur_proc;
11629 static procS *cur_proc_ptr;
11630 static int numprocs;
11632 /* When we align code in the .text section of mips16, use the correct two
11633 byte nop pattern of 0x6500 (move $0,$0) */
11636 mips_do_align (n, fill, len, max)
11639 int len ATTRIBUTE_UNUSED;
11643 && subseg_text_p (now_seg)
11645 && mips_opts.mips16)
11647 static const unsigned char be_nop[] = { 0x65, 0x00 };
11648 static const unsigned char le_nop[] = { 0x00, 0x65 };
11650 frag_align (1, 0, 0);
11652 if (target_big_endian)
11653 frag_align_pattern (n, be_nop, 2, max);
11655 frag_align_pattern (n, le_nop, 2, max);
11670 /* check for premature end, nesting errors, etc */
11672 as_warn (_("missing `.end' at end of assembly"));
11681 if (*input_line_pointer == '-')
11683 ++input_line_pointer;
11686 if (!isdigit ((unsigned char) *input_line_pointer))
11687 as_bad (_("Expected simple number."));
11688 if (input_line_pointer[0] == '0')
11690 if (input_line_pointer[1] == 'x')
11692 input_line_pointer += 2;
11693 while (isxdigit ((unsigned char) *input_line_pointer))
11696 val |= hex_value (*input_line_pointer++);
11698 return negative ? -val : val;
11702 ++input_line_pointer;
11703 while (isdigit ((unsigned char) *input_line_pointer))
11706 val |= *input_line_pointer++ - '0';
11708 return negative ? -val : val;
11711 if (!isdigit ((unsigned char) *input_line_pointer))
11713 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
11714 *input_line_pointer, *input_line_pointer);
11715 as_warn (_("Invalid number"));
11718 while (isdigit ((unsigned char) *input_line_pointer))
11721 val += *input_line_pointer++ - '0';
11723 return negative ? -val : val;
11726 /* The .file directive; just like the usual .file directive, but there
11727 is an initial number which is the ECOFF file index. */
11731 int x ATTRIBUTE_UNUSED;
11735 line = get_number ();
11739 /* The .end directive. */
11743 int x ATTRIBUTE_UNUSED;
11748 if (!is_end_of_line[(unsigned char) *input_line_pointer])
11751 demand_empty_rest_of_line ();
11756 #ifdef BFD_ASSEMBLER
11757 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
11762 if (now_seg != data_section && now_seg != bss_section)
11769 as_warn (_(".end not in text section"));
11773 as_warn (_(".end directive without a preceding .ent directive."));
11774 demand_empty_rest_of_line ();
11780 assert (S_GET_NAME (p));
11781 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
11782 as_warn (_(".end symbol does not match .ent symbol."));
11785 as_warn (_(".end directive missing or unknown symbol"));
11787 #ifdef MIPS_STABS_ELF
11789 segT saved_seg = now_seg;
11790 subsegT saved_subseg = now_subseg;
11791 fragS *saved_frag = frag_now;
11797 dot = frag_now_fix ();
11799 #ifdef md_flush_pending_output
11800 md_flush_pending_output ();
11804 subseg_set (pdr_seg, 0);
11806 /* Write the symbol */
11807 exp.X_op = O_symbol;
11808 exp.X_add_symbol = p;
11809 exp.X_add_number = 0;
11810 emit_expr (&exp, 4);
11812 fragp = frag_more (7*4);
11814 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
11815 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
11816 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
11817 md_number_to_chars (fragp +12, (valueT) cur_proc_ptr->fpreg_offset, 4);
11818 md_number_to_chars (fragp +16, (valueT) cur_proc_ptr->frame_offset, 4);
11819 md_number_to_chars (fragp +20, (valueT) cur_proc_ptr->frame_reg, 4);
11820 md_number_to_chars (fragp +24, (valueT) cur_proc_ptr->pc_reg, 4);
11822 subseg_set (saved_seg, saved_subseg);
11826 cur_proc_ptr = NULL;
11829 /* The .aent and .ent directives. */
11839 symbolP = get_symbol ();
11840 if (*input_line_pointer == ',')
11841 input_line_pointer++;
11842 SKIP_WHITESPACE ();
11843 if (isdigit ((unsigned char) *input_line_pointer)
11844 || *input_line_pointer == '-')
11845 number = get_number ();
11847 #ifdef BFD_ASSEMBLER
11848 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
11853 if (now_seg != data_section && now_seg != bss_section)
11860 as_warn (_(".ent or .aent not in text section."));
11862 if (!aent && cur_proc_ptr)
11863 as_warn (_("missing `.end'"));
11867 cur_proc_ptr = &cur_proc;
11868 memset (cur_proc_ptr, '\0', sizeof (procS));
11870 cur_proc_ptr->isym = symbolP;
11872 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
11877 demand_empty_rest_of_line ();
11880 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
11881 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
11882 s_mips_frame is used so that we can set the PDR information correctly.
11883 We can't use the ecoff routines because they make reference to the ecoff
11884 symbol table (in the mdebug section). */
11887 s_mips_frame (ignore)
11890 #ifdef MIPS_STABS_ELF
11894 if (cur_proc_ptr == (procS *) NULL)
11896 as_warn (_(".frame outside of .ent"));
11897 demand_empty_rest_of_line ();
11901 cur_proc_ptr->frame_reg = tc_get_register (1);
11903 SKIP_WHITESPACE ();
11904 if (*input_line_pointer++ != ','
11905 || get_absolute_expression_and_terminator (&val) != ',')
11907 as_warn (_("Bad .frame directive"));
11908 --input_line_pointer;
11909 demand_empty_rest_of_line ();
11913 cur_proc_ptr->frame_offset = val;
11914 cur_proc_ptr->pc_reg = tc_get_register (0);
11916 demand_empty_rest_of_line ();
11919 #endif /* MIPS_STABS_ELF */
11922 /* The .fmask and .mask directives. If the mdebug section is present
11923 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
11924 embedded targets, s_mips_mask is used so that we can set the PDR
11925 information correctly. We can't use the ecoff routines because they
11926 make reference to the ecoff symbol table (in the mdebug section). */
11929 s_mips_mask (reg_type)
11932 #ifdef MIPS_STABS_ELF
11935 if (cur_proc_ptr == (procS *) NULL)
11937 as_warn (_(".mask/.fmask outside of .ent"));
11938 demand_empty_rest_of_line ();
11942 if (get_absolute_expression_and_terminator (&mask) != ',')
11944 as_warn (_("Bad .mask/.fmask directive"));
11945 --input_line_pointer;
11946 demand_empty_rest_of_line ();
11950 off = get_absolute_expression ();
11952 if (reg_type == 'F')
11954 cur_proc_ptr->fpreg_mask = mask;
11955 cur_proc_ptr->fpreg_offset = off;
11959 cur_proc_ptr->reg_mask = mask;
11960 cur_proc_ptr->reg_offset = off;
11963 demand_empty_rest_of_line ();
11965 s_ignore (reg_type);
11966 #endif /* MIPS_STABS_ELF */
11969 /* The .loc directive. */
11980 assert (now_seg == text_section);
11982 lineno = get_number ();
11983 addroff = frag_now_fix ();
11985 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
11986 S_SET_TYPE (symbolP, N_SLINE);
11987 S_SET_OTHER (symbolP, 0);
11988 S_SET_DESC (symbolP, lineno);
11989 symbolP->sy_segment = now_seg;