1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright (C) 1993 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
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
40 #endif /* NO_VARARGS */
41 #endif /* NO_STDARG */
43 #include "opcode/mips.h"
48 static char *mips_regmask_frag;
52 #define PIC_CALL_REG 25
58 /* Decide whether to do GP reference optimizations based on the object
68 /* The default target format to use. */
70 #ifdef TARGET_BYTES_BIG_ENDIAN
71 #define DEFAULT_TARGET_FORMAT "a.out-mips-big"
73 #define DEFAULT_TARGET_FORMAT "a.out-mips-little"
77 #ifdef TARGET_BYTES_BIG_ENDIAN
78 #define DEFAULT_TARGET_FORMAT "ecoff-bigmips"
80 #define DEFAULT_TARGET_FORMAT "ecoff-littlemips"
82 #endif /* OBJ_ECOFF */
84 #ifdef TARGET_BYTES_BIG_ENDIAN
85 #define DEFAULT_TARGET_FORMAT "elf32-bigmips"
87 #define DEFAULT_TARGET_FORMAT "elf32-littlemips"
91 const char *mips_target_format = DEFAULT_TARGET_FORMAT;
93 /* These variables are filled in with the masks of registers used.
94 The object format code reads them and puts them in the appropriate
96 unsigned long mips_gprmask;
97 unsigned long mips_cprmask[4];
99 /* MIPS ISA (Instruction Set Architecture) level (may be changed
100 temporarily using .set mipsN). */
101 static int mips_isa = -1;
103 /* MIPS ISA we are using for this output file. */
104 static int file_mips_isa;
106 /* MIPS PIC level. 0 is normal, non-PIC code. 2 means to generate
107 SVR4 ABI PIC calls. 1 doesn't mean anything. */
110 static int mips_warn_about_macros;
111 static int mips_noreorder;
112 static int mips_any_noreorder;
113 static int mips_nomove;
114 static int mips_noat;
115 static int mips_nobopt;
118 /* The size of the small data section. */
119 static int g_switch_value = 8;
120 /* Whether the -G option was used. */
121 static int g_switch_seen = 0;
127 /* handle of the OPCODE hash table */
128 static struct hash_control *op_hash = NULL;
130 /* This array holds the chars that always start a comment. If the
131 pre-processor is disabled, these aren't very useful */
132 const char comment_chars[] = "#";
134 /* This array holds the chars that only start a comment at the beginning of
135 a line. If the line seems to have the form '# 123 filename'
136 .line and .file directives will appear in the pre-processed output */
137 /* Note that input_file.c hand checks for '#' at the beginning of the
138 first line of the input file. This is because the compiler outputs
139 #NO_APP at the beginning of its output. */
140 /* Also note that C style comments are always supported. */
141 const char line_comment_chars[] = "#";
143 /* This array holds machine specific line separator characters. */
144 const char line_separator_chars[] = "";
146 /* Chars that can be used to separate mant from exp in floating point nums */
147 const char EXP_CHARS[] = "eE";
149 /* Chars that mean this number is a floating point constant */
152 const char FLT_CHARS[] = "rRsSfFdDxXpP";
154 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
155 changed in read.c . Ideally it shouldn't have to know about it at all,
156 but nothing is ideal around here.
159 static char *insn_error;
161 static int byte_order = BYTE_ORDER;
163 static int auto_align = 1;
165 /* Symbol labelling the current insn. */
166 static symbolS *insn_label;
168 /* When outputting SVR4 PIC code, the assembler needs to know the
169 offset in the stack frame from which to restore the $gp register.
170 This is set by the .cprestore pseudo-op, and saved in this
172 static offsetT mips_cprestore_offset = -1;
174 /* This is the register which holds the stack frame, as set by the
175 .frame pseudo-op. This is needed to implement .cprestore. */
176 static int mips_frame_reg = SP;
178 /* To output NOP instructions correctly, we need to keep information
179 about the previous two instructions. */
181 /* Whether we are optimizing. The default value of 2 means to remove
182 unneeded NOPs and swap branch instructions when possible. A value
183 of 1 means to not swap branches. A value of 0 means to always
185 static int mips_optimize = 2;
187 /* The previous instruction. */
188 static struct mips_cl_insn prev_insn;
190 /* The instruction before prev_insn. */
191 static struct mips_cl_insn prev_prev_insn;
193 /* If we don't want information for prev_insn or prev_prev_insn, we
194 point the insn_mo field at this dummy integer. */
195 static const struct mips_opcode dummy_opcode = { 0 };
197 /* Non-zero if prev_insn is valid. */
198 static int prev_insn_valid;
200 /* The frag for the previous instruction. */
201 static struct frag *prev_insn_frag;
203 /* The offset into prev_insn_frag for the previous instruction. */
204 static long prev_insn_where;
206 /* The reloc for the previous instruction, if any. */
207 static fixS *prev_insn_fixp;
209 /* Non-zero if the previous instruction was in a delay slot. */
210 static int prev_insn_is_delay_slot;
212 /* Non-zero if the previous instruction was in a .set noreorder. */
213 static int prev_insn_unreordered;
215 /* Non-zero if the previous previous instruction was in a .set
217 static int prev_prev_insn_unreordered;
219 /* Since the MIPS does not have multiple forms of PC relative
220 instructions, we do not have to do relaxing as is done on other
221 platforms. However, we do have to handle GP relative addressing
222 correctly, which turns out to be a similar problem.
224 Every macro that refers to a symbol can occur in (at least) two
225 forms, one with GP relative addressing and one without. For
226 example, loading a global variable into a register generally uses
227 an macroinstruction like this:
229 If i can be addressed off the GP register (this is true if it is in
230 the .sbss or .sdata section, or if it is known to be smaller than
231 the -G argument) this will generate the following instruction:
233 This instruction will use a GPREL reloc. If i can not be addressed
234 off the GP register, the following instruction sequence will be used:
237 In this case the first instruction will have a HI16 reloc, and the
238 second reloc will have a LO16 reloc. Both relocs will be against
241 The issue here is that we may not know whether i is GP addressable
242 until after we see the instruction that uses it. Therefore, we
243 want to be able to choose the final instruction sequence only at
244 the end of the assembly. This is similar to the way other
245 platforms choose the form of a PC relative instruction only at the
248 When generating position independent code we do not use GP
249 addressing in the same way, but the issue still arises as external
250 symbols and local symbols must be handled differently.
252 We handle these issues by actually generating both possible
253 instruction sequences. The longer one is put in a frag_var with
254 type rs_machine_dependent. We encode what to do with the frag in
255 the subtype field. We encode (1) the number of existing bytes to
256 replace, (2) the number of new bytes to use, (3) the offset from
257 the start of the existing bytes to the first reloc we must generate
258 (that is, the offset is applied from the start of the existing
259 bytes after they are replaced by the new bytes, if any), (4) the
260 offset from the start of the existing bytes to the second reloc,
261 (5) whether a third reloc is needed (the third reloc is always four
262 bytes after the second reloc), and (6) whether to warn if this
263 variant is used (this is sometimes needed if .set nomacro or .set
264 noat is in effect). All these numbers are reasonably small.
266 Generating two instruction sequences must be handled carefully to
267 ensure that delay slots are handled correctly. Fortunately, the
268 issue only arises in a restricted number of cases. When the second
269 instruction sequence is generated, append_insn is directed to
270 maintain the existing delay slot information, so it continues to
271 apply to any code after the second instruction sequence. This
272 means that the second instruction sequence must not impose any
273 requirements not required by the first instruction sequence.
275 These variant frags are then handled in functions called by the
276 machine independent code. md_estimate_size_before_relax returns
277 the final size of the frag. md_convert_frag sets up the final form
278 of the frag. tc_gen_reloc adjust the first reloc and adds a second
280 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
284 | (((reloc1) + 64) << 9) \
285 | (((reloc2) + 64) << 2) \
286 | ((reloc3) ? (1 << 1) : 0) \
288 #define RELAX_OLD(i) (((i) >> 24) & 0xff)
289 #define RELAX_NEW(i) (((i) >> 16) & 0xff)
290 #define RELAX_RELOC1(i) ((((i) >> 9) & 0x7f) - 64)
291 #define RELAX_RELOC2(i) ((((i) >> 2) & 0x7f) - 64)
292 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
293 #define RELAX_WARN(i) ((i) & 1)
295 /* Prototypes for static functions. */
298 #define internalError() \
299 as_fatal ("internal Error, line %d, %s", __LINE__, __FILE__)
301 #define internalError() as_fatal ("MIPS internal Error");
304 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
305 unsigned int reg, int fpr));
306 static void append_insn PARAMS ((char *place,
307 struct mips_cl_insn * ip,
309 bfd_reloc_code_real_type r));
310 static void mips_no_prev_insn PARAMS ((void));
311 static void mips_emit_delays PARAMS ((void));
312 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
313 const char *name, const char *fmt,
315 static void macro_build_lui PARAMS ((char *place, int *counter,
316 expressionS * ep, int regnum));
317 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
318 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
320 static void load_register PARAMS ((int *counter, int reg, expressionS * ep));
321 static void load_address PARAMS ((int *counter, int reg, expressionS *ep));
322 static void macro PARAMS ((struct mips_cl_insn * ip));
323 #ifdef LOSING_COMPILER
324 static void macro2 PARAMS ((struct mips_cl_insn * ip));
326 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
327 static int my_getSmallExpression PARAMS ((expressionS * ep, char *str));
328 static void my_getExpression PARAMS ((expressionS * ep, char *str));
329 static symbolS *get_symbol PARAMS ((void));
330 static void mips_align PARAMS ((int to, int fill));
331 static void s_align PARAMS ((int));
332 static void s_stringer PARAMS ((int));
333 static void s_change_sec PARAMS ((int));
334 static void s_cons PARAMS ((int));
335 static void s_err PARAMS ((int));
336 static void s_extern PARAMS ((int));
337 static void s_float_cons PARAMS ((int));
338 static void s_option PARAMS ((int));
339 static void s_mipsset PARAMS ((int));
340 static void s_mips_space PARAMS ((int));
341 static void s_abicalls PARAMS ((int));
342 static void s_cpload PARAMS ((int));
343 static void s_cprestore PARAMS ((int));
344 static void s_gpword PARAMS ((int));
345 static void s_cpadd PARAMS ((int));
346 #ifndef ECOFF_DEBUGGING
347 static void md_obj_begin PARAMS ((void));
348 static void md_obj_end PARAMS ((void));
349 static long get_number PARAMS ((void));
350 static void s_ent PARAMS ((int));
351 static void s_mipsend PARAMS ((int));
352 static void s_file PARAMS ((int));
354 static void s_frame PARAMS ((int));
355 static void s_loc PARAMS ((int));
356 static void s_mask PARAMS ((char));
362 The following pseudo-ops from the Kane and Heinrich MIPS book
363 should be defined here, but are currently unsupported: .alias,
364 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
366 The following pseudo-ops from the Kane and Heinrich MIPS book are
367 specific to the type of debugging information being generated, and
368 should be defined by the object format: .aent, .begin, .bend,
369 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
372 The following pseudo-ops from the Kane and Heinrich MIPS book are
373 not MIPS CPU specific, but are also not specific to the object file
374 format. This file is probably the best place to define them, but
375 they are not currently supported: .asm0, .endr, .lab, .repeat,
376 .struct, .weakext. */
378 const pseudo_typeS md_pseudo_table[] =
380 /* MIPS specific pseudo-ops. */
381 {"option", s_option, 0},
382 {"set", s_mipsset, 0},
383 {"rdata", s_change_sec, 'r'},
384 {"sdata", s_change_sec, 's'},
385 {"livereg", s_ignore, 0},
386 { "abicalls", s_abicalls, 0},
387 { "cpload", s_cpload, 0},
388 { "cprestore", s_cprestore, 0},
389 { "gpword", s_gpword, 0},
390 { "cpadd", s_cpadd, 0},
392 /* Relatively generic pseudo-ops that happen to be used on MIPS
394 {"asciiz", s_stringer, 1},
395 {"bss", s_change_sec, 'b'},
398 {"dword", s_cons, 3},
400 /* These pseudo-ops are defined in read.c, but must be overridden
401 here for one reason or another. */
402 {"align", s_align, 0},
403 {"ascii", s_stringer, 0},
404 {"asciz", s_stringer, 1},
406 {"data", s_change_sec, 'd'},
407 {"double", s_float_cons, 'd'},
408 {"extern", s_extern, 0},
409 {"float", s_float_cons, 'f'},
410 {"hword", s_cons, 1},
415 {"short", s_cons, 1},
416 {"single", s_float_cons, 'f'},
417 {"space", s_mips_space, 0},
418 {"text", s_change_sec, 't'},
421 #ifndef ECOFF_DEBUGGING
422 /* These pseudo-ops should be defined by the object file format.
423 However, a.out doesn't support them, so we have versions here. */
425 {"bgnb", s_ignore, 0},
426 {"end", s_mipsend, 0},
427 {"endb", s_ignore, 0},
430 {"fmask", s_ignore, 'F'},
431 {"frame", s_ignore, 0},
432 {"loc", s_ignore, 0},
433 {"mask", s_ignore, 'R'},
434 {"verstamp", s_ignore, 0},
441 const relax_typeS md_relax_table[] =
446 static char *expr_end;
448 static expressionS imm_expr;
449 static expressionS offset_expr;
450 static bfd_reloc_code_real_type imm_reloc;
451 static bfd_reloc_code_real_type offset_reloc;
453 /* FIXME: This should be handled in a different way. */
454 extern int target_big_endian;
457 * This function is called once, at assembler startup time. It should
458 * set up all the tables, etc. that the MD part of the assembler will need.
464 register const char *retval = NULL;
465 register unsigned int i = 0;
469 if (strcmp (TARGET_CPU, "mips") == 0)
471 else if (strcmp (TARGET_CPU, "r6000") == 0
472 || strcmp (TARGET_CPU, "mips2") == 0)
474 else if (strcmp (TARGET_CPU, "mips64") == 0
475 || strcmp (TARGET_CPU, "r4000") == 0
476 || strcmp (TARGET_CPU, "mips3") == 0)
485 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 3000);
488 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 6000);
491 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 4000);
495 as_warn ("Could not set architecture and machine");
497 file_mips_isa = mips_isa;
499 op_hash = hash_new ();
501 for (i = 0; i < NUMOPCODES;)
503 const char *name = mips_opcodes[i].name;
505 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
508 fprintf (stderr, "internal error: can't hash `%s': %s\n",
509 mips_opcodes[i].name, retval);
510 as_fatal ("Broken assembler. No assembly attempted.");
514 if (mips_opcodes[i].pinfo != INSN_MACRO
515 && ((mips_opcodes[i].match & mips_opcodes[i].mask)
516 != mips_opcodes[i].match))
518 fprintf (stderr, "internal error: bad opcode: `%s' \"%s\"\n",
519 mips_opcodes[i].name, mips_opcodes[i].args);
520 as_fatal ("Broken assembler. No assembly attempted.");
524 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
527 mips_no_prev_insn ();
535 /* set the default alignment for the text section (2**2) */
536 record_alignment (text_section, 2);
538 /* FIXME: This should be handled in a different way. */
539 target_big_endian = byte_order == BIG_ENDIAN;
542 bfd_set_gp_size (stdoutput, g_switch_value);
546 /* Sections must be aligned to 16 byte boundaries. */
547 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
548 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
549 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
551 /* Create a .reginfo section for register masks and a .mdebug
552 section for debugging information. */
560 sec = subseg_new (".reginfo", (subsegT) 0);
562 /* The ABI says this section should be loaded so that the running
563 program can access it. */
564 (void) bfd_set_section_flags (stdoutput, sec,
565 (SEC_ALLOC | SEC_LOAD
566 | SEC_READONLY | SEC_DATA));
567 (void) bfd_set_section_alignment (stdoutput, sec, 2);
569 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
571 #ifdef ECOFF_DEBUGGING
572 sec = subseg_new (".mdebug", (subsegT) 0);
573 (void) bfd_set_section_flags (stdoutput, sec,
574 SEC_HAS_CONTENTS | SEC_READONLY);
575 (void) bfd_set_section_alignment (stdoutput, sec, 2);
578 subseg_set (seg, subseg);
582 #ifndef ECOFF_DEBUGGING
590 #ifndef ECOFF_DEBUGGING
599 struct mips_cl_insn insn;
601 imm_expr.X_op = O_absent;
602 offset_expr.X_op = O_absent;
604 mips_ip (str, &insn);
607 as_bad ("%s `%s'", insn_error, str);
610 if (insn.insn_mo->pinfo == INSN_MACRO)
616 if (imm_expr.X_op != O_absent)
617 append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc);
618 else if (offset_expr.X_op != O_absent)
619 append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc);
621 append_insn ((char *) NULL, &insn, NULL, BFD_RELOC_UNUSED);
625 /* See whether instruction IP reads register REG. If FPR is non-zero,
626 REG is a floating point register. */
629 insn_uses_reg (ip, reg, fpr)
630 struct mips_cl_insn *ip;
634 /* Don't report on general register 0, since it never changes. */
635 if (! fpr && reg == 0)
640 /* If we are called with either $f0 or $f1, we must check $f0.
641 This is not optimal, because it will introduce an unnecessary
642 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
643 need to distinguish reading both $f0 and $f1 or just one of
644 them. Note that we don't have to check the other way,
645 because there is no instruction that sets both $f0 and $f1
646 and requires a delay. */
647 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
648 && (((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS)
649 == (reg &~ (unsigned) 1)))
651 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
652 && (((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT)
653 == (reg &~ (unsigned) 1)))
658 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
659 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
661 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
662 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
669 /* Output an instruction. PLACE is where to put the instruction; if
670 it is NULL, this uses frag_more to get room. IP is the instruction
671 information. ADDRESS_EXPR is an operand of the instruction to be
672 used with RELOC_TYPE. */
675 append_insn (place, ip, address_expr, reloc_type)
677 struct mips_cl_insn *ip;
678 expressionS *address_expr;
679 bfd_reloc_code_real_type reloc_type;
681 register unsigned long prev_pinfo, pinfo;
686 prev_pinfo = prev_insn.insn_mo->pinfo;
687 pinfo = ip->insn_mo->pinfo;
689 if (place == NULL && ! mips_noreorder)
691 /* If the previous insn required any delay slots, see if we need
692 to insert a NOP or two. There are eight kinds of possible
693 hazards, of which an instruction can have at most one type.
694 (1) a load from memory delay
695 (2) a load from a coprocessor delay
696 (3) an unconditional branch delay
697 (4) a conditional branch delay
698 (5) a move to coprocessor register delay
699 (6) a load coprocessor register from memory delay
700 (7) a coprocessor condition code delay
701 (8) a HI/LO special register delay
703 There are a lot of optimizations we could do that we don't.
704 In particular, we do not, in general, reorder instructions.
705 If you use gcc with optimization, it will reorder
706 instructions and generally do much more optimization then we
707 do here; repeating all that work in the assembler would only
708 benefit hand written assembly code, and does not seem worth
711 /* This is how a NOP is emitted. */
712 #define emit_nop() md_number_to_chars (frag_more (4), 0, 4)
714 /* The previous insn might require a delay slot, depending upon
715 the contents of the current insn. */
716 if ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
718 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))
720 /* A load from a coprocessor or from memory. All load
721 delays delay the use of general register rt for one
722 instruction on the r3000. The r6000 and r4000 use
724 know (prev_pinfo & INSN_WRITE_GPR_T);
725 if (mips_optimize == 0
726 || insn_uses_reg (ip,
727 ((prev_insn.insn_opcode >> OP_SH_RT)
732 else if ((prev_pinfo & INSN_COPROC_MOVE_DELAY)
734 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)))
736 /* A generic coprocessor delay. The previous instruction
737 modified a coprocessor general or control register. If
738 it modified a control register, we need to avoid any
739 coprocessor instruction (this is probably not always
740 required, but it sometimes is). If it modified a general
741 register, we avoid using that register.
743 On the r6000 and r4000 loading a coprocessor register
744 from memory is interlocked, and does not require a delay.
746 This case is not handled very well. There is no special
747 knowledge of CP0 handling, and the coprocessors other
748 than the floating point unit are not distinguished at
750 if (prev_pinfo & INSN_WRITE_FPR_T)
752 if (mips_optimize == 0
753 || insn_uses_reg (ip,
754 ((prev_insn.insn_opcode >> OP_SH_FT)
759 else if (prev_pinfo & INSN_WRITE_FPR_S)
761 if (mips_optimize == 0
762 || insn_uses_reg (ip,
763 ((prev_insn.insn_opcode >> OP_SH_FS)
770 /* We don't know exactly what the previous instruction
771 does. If the current instruction uses a coprocessor
772 register, we must insert a NOP. If previous
773 instruction may set the condition codes, and the
774 current instruction uses them, we must insert two
776 if (mips_optimize == 0
777 || ((prev_pinfo & INSN_WRITE_COND_CODE)
778 && (pinfo & INSN_READ_COND_CODE)))
780 else if (pinfo & INSN_COP)
784 else if (prev_pinfo & INSN_WRITE_COND_CODE)
786 /* The previous instruction sets the coprocessor condition
787 codes, but does not require a general coprocessor delay
788 (this means it is a floating point comparison
789 instruction). If this instruction uses the condition
790 codes, we need to insert a single NOP. */
791 if (mips_optimize == 0
792 || (pinfo & INSN_READ_COND_CODE))
795 else if (prev_pinfo & INSN_READ_LO)
797 /* The previous instruction reads the LO register; if the
798 current instruction writes to the LO register, we must
800 if (mips_optimize == 0
801 || (pinfo & INSN_WRITE_LO))
804 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
806 /* The previous instruction reads the HI register; if the
807 current instruction writes to the HI register, we must
809 if (mips_optimize == 0
810 || (pinfo & INSN_WRITE_HI))
814 /* There are two cases which require two intervening
815 instructions: 1) setting the condition codes using a move to
816 coprocessor instruction which requires a general coprocessor
817 delay and then reading the condition codes 2) reading the HI
818 or LO register and then writing to it. If we are not already
819 emitting a NOP instruction, we must check for these cases
820 compared to the instruction previous to the previous
823 && (((prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
824 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
825 && (pinfo & INSN_READ_COND_CODE))
826 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
827 && (pinfo & INSN_WRITE_LO))
828 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
829 && (pinfo & INSN_WRITE_HI))))
832 /* If we are being given a nop instruction, don't bother with
833 one of the nops we would otherwise output. This will only
834 happen when a nop instruction is used with mips_optimize set
836 if (nops > 0 && ip->insn_opcode == 0)
839 /* Now emit the right number of NOP instructions. */
846 listing_prev_line ();
847 if (insn_label != NULL)
849 assert (S_GET_SEGMENT (insn_label) == now_seg);
850 insn_label->sy_frag = frag_now;
851 S_SET_VALUE (insn_label, (valueT) frag_now_fix ());
861 if (address_expr != NULL)
863 if (address_expr->X_op == O_constant)
868 ip->insn_opcode |= address_expr->X_add_number;
872 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
875 case BFD_RELOC_MIPS_JMP:
876 case BFD_RELOC_16_PCREL_S2:
885 assert (reloc_type != BFD_RELOC_UNUSED);
887 /* Don't generate a reloc if we are writing into a variant
890 fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
892 reloc_type == BFD_RELOC_16_PCREL_S2,
897 md_number_to_chars (f, ip->insn_opcode, 4);
899 /* Update the register mask information. */
900 if (pinfo & INSN_WRITE_GPR_D)
901 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
902 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
903 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
904 if (pinfo & INSN_READ_GPR_S)
905 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
906 if (pinfo & INSN_WRITE_GPR_31)
907 mips_gprmask |= 1 << 31;
908 if (pinfo & INSN_WRITE_FPR_D)
909 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
910 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
911 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
912 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
913 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
914 if (pinfo & INSN_COP)
916 /* We don't keep enough information to sort these cases out. */
918 /* Never set the bit for $0, which is always zero. */
919 mips_gprmask &=~ 1 << 0;
921 if (place == NULL && ! mips_noreorder)
923 /* Filling the branch delay slot is more complex. We try to
924 switch the branch with the previous instruction, which we can
925 do if the previous instruction does not set up a condition
926 that the branch tests and if the branch is not itself the
927 target of any branch. */
928 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
929 || (pinfo & INSN_COND_BRANCH_DELAY))
931 if (mips_optimize < 2
932 /* If we have seen .set nobopt, don't optimize. */
934 /* If we have seen .set volatile or .set nomove, don't
937 /* If we had to emit any NOP instructions, then we
938 already know we can not swap. */
940 /* If we don't even know the previous insn, we can not
943 /* If the previous insn is already in a branch delay
944 slot, then we can not swap. */
945 || prev_insn_is_delay_slot
946 /* If the previous previous insn was in a .set
947 noreorder, we can't swap. Actually, the MIPS
948 assembler will swap in this situation. However, gcc
949 configured -with-gnu-as will generate code like
955 in which we can not swap the bne and INSN. If gcc is
956 not configured -with-gnu-as, it does not output the
957 .set pseudo-ops. We don't have to check
958 prev_insn_unreordered, because prev_insn_valid will
959 be 0 in that case. We don't want to use
960 prev_prev_insn_valid, because we do want to be able
961 to swap at the start of a function. */
962 || prev_prev_insn_unreordered
963 /* If the branch is itself the target of a branch, we
964 can not swap. We cheat on this; all we check for is
965 whether there is a label on this instruction. If
966 there are any branches to anything other than a
967 label, users must use .set noreorder. */
968 || insn_label != NULL
969 /* If the previous instruction is in a variant frag, we
970 can not do the swap. */
971 || prev_insn_frag->fr_type == rs_machine_dependent
972 /* If the branch reads the condition codes, we don't
973 even try to swap, because in the sequence
978 we can not swap, and I don't feel like handling that
980 || (pinfo & INSN_READ_COND_CODE)
981 /* We can not swap with an instruction that requires a
982 delay slot, becase the target of the branch might
983 interfere with that instruction. */
985 & (INSN_LOAD_COPROC_DELAY
986 | INSN_COPROC_MOVE_DELAY
987 | INSN_WRITE_COND_CODE
992 & (INSN_LOAD_MEMORY_DELAY
993 | INSN_COPROC_MEMORY_DELAY)))
994 /* We can not swap with a branch instruction. */
996 & (INSN_UNCOND_BRANCH_DELAY
997 | INSN_COND_BRANCH_DELAY
998 | INSN_COND_BRANCH_LIKELY))
999 /* We do not swap with a trap instruction, since it
1000 complicates trap handlers to have the trap
1001 instruction be in a delay slot. */
1002 || (prev_pinfo & INSN_TRAP)
1003 /* If the branch reads a register that the previous
1004 instruction sets, we can not swap. */
1005 || ((prev_pinfo & INSN_WRITE_GPR_T)
1006 && insn_uses_reg (ip,
1007 ((prev_insn.insn_opcode >> OP_SH_RT)
1010 || ((prev_pinfo & INSN_WRITE_GPR_D)
1011 && insn_uses_reg (ip,
1012 ((prev_insn.insn_opcode >> OP_SH_RD)
1015 /* If the branch writes a register that the previous
1016 instruction sets, we can not swap (we know that
1017 branches write only to RD or to $31). */
1018 || ((prev_pinfo & INSN_WRITE_GPR_T)
1019 && (((pinfo & INSN_WRITE_GPR_D)
1020 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
1021 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
1022 || ((pinfo & INSN_WRITE_GPR_31)
1023 && (((prev_insn.insn_opcode >> OP_SH_RT)
1026 || ((prev_pinfo & INSN_WRITE_GPR_D)
1027 && (((pinfo & INSN_WRITE_GPR_D)
1028 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
1029 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
1030 || ((pinfo & INSN_WRITE_GPR_31)
1031 && (((prev_insn.insn_opcode >> OP_SH_RD)
1034 /* If the branch writes a register that the previous
1035 instruction reads, we can not swap (we know that
1036 branches only write to RD or to $31). */
1037 || ((pinfo & INSN_WRITE_GPR_D)
1038 && insn_uses_reg (&prev_insn,
1039 ((ip->insn_opcode >> OP_SH_RD)
1042 || ((pinfo & INSN_WRITE_GPR_31)
1043 && insn_uses_reg (&prev_insn, 31, 0))
1044 /* If the previous previous instruction has a load
1045 delay, and sets a register that the branch reads, we
1047 || (((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
1049 && (prev_prev_insn.insn_mo->pinfo
1050 & INSN_LOAD_MEMORY_DELAY)))
1051 && insn_uses_reg (ip,
1052 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
1056 /* We could do even better for unconditional branches to
1057 portions of this object file; we could pick up the
1058 instruction at the destination, put it in the delay
1059 slot, and bump the destination address. */
1061 /* Update the previous insn information. */
1062 prev_prev_insn = *ip;
1063 prev_insn.insn_mo = &dummy_opcode;
1070 /* It looks like we can actually do the swap. */
1071 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
1072 memcpy (temp, prev_f, 4);
1073 memcpy (prev_f, f, 4);
1074 memcpy (f, temp, 4);
1077 prev_insn_fixp->fx_frag = frag_now;
1078 prev_insn_fixp->fx_where = f - frag_now->fr_literal;
1082 fixp->fx_frag = prev_insn_frag;
1083 fixp->fx_where = prev_insn_where;
1085 /* Update the previous insn information; leave prev_insn
1087 prev_prev_insn = *ip;
1089 prev_insn_is_delay_slot = 1;
1091 /* If that was an unconditional branch, forget the previous
1092 insn information. */
1093 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
1095 prev_prev_insn.insn_mo = &dummy_opcode;
1096 prev_insn.insn_mo = &dummy_opcode;
1099 else if (pinfo & INSN_COND_BRANCH_LIKELY)
1101 /* We don't yet optimize a branch likely. What we should do
1102 is look at the target, copy the instruction found there
1103 into the delay slot, and increment the branch to jump to
1104 the next instruction. */
1106 /* Update the previous insn information. */
1107 prev_prev_insn = *ip;
1108 prev_insn.insn_mo = &dummy_opcode;
1112 /* Update the previous insn information. */
1114 prev_prev_insn.insn_mo = &dummy_opcode;
1116 prev_prev_insn = prev_insn;
1119 /* Any time we see a branch, we always fill the delay slot
1120 immediately; since this insn is not a branch, we know it
1121 is not in a delay slot. */
1122 prev_insn_is_delay_slot = 0;
1125 prev_prev_insn_unreordered = prev_insn_unreordered;
1126 prev_insn_unreordered = 0;
1127 prev_insn_frag = frag_now;
1128 prev_insn_where = f - frag_now->fr_literal;
1129 prev_insn_fixp = fixp;
1130 prev_insn_valid = 1;
1133 /* We just output an insn, so the next one doesn't have a label. */
1137 /* This function forgets that there was any previous instruction or
1141 mips_no_prev_insn ()
1143 prev_insn.insn_mo = &dummy_opcode;
1144 prev_prev_insn.insn_mo = &dummy_opcode;
1145 prev_insn_valid = 0;
1146 prev_insn_is_delay_slot = 0;
1147 prev_insn_unreordered = 0;
1148 prev_prev_insn_unreordered = 0;
1152 /* This function must be called whenever we turn on noreorder or emit
1153 something other than instructions. It inserts any NOPS which might
1154 be needed by the previous instruction, and clears the information
1155 kept for the previous instructions. */
1160 if (! mips_noreorder)
1165 if ((prev_insn.insn_mo->pinfo
1166 & (INSN_LOAD_COPROC_DELAY
1167 | INSN_COPROC_MOVE_DELAY
1168 | INSN_WRITE_COND_CODE
1172 && (prev_insn.insn_mo->pinfo
1173 & (INSN_LOAD_MEMORY_DELAY
1174 | INSN_COPROC_MEMORY_DELAY))))
1177 if ((prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1178 || (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1179 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))
1182 else if ((prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1183 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1184 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))
1189 if (insn_label != NULL)
1191 assert (S_GET_SEGMENT (insn_label) == now_seg);
1192 insn_label->sy_frag = frag_now;
1193 S_SET_VALUE (insn_label, (valueT) frag_now_fix ());
1196 mips_no_prev_insn ();
1200 /* Build an instruction created by a macro expansion. This is passed
1201 a pointer to the count of instructions created so far, an
1202 expression, the name of the instruction to build, an operand format
1203 string, and corresponding arguments. */
1207 macro_build (char *place,
1213 #else /* ! defined (NO_STDARG) */
1215 macro_build (place, counter, ep, name, fmt, va_alist)
1222 #endif /* ! defined (NO_STDARG) */
1224 struct mips_cl_insn insn;
1225 bfd_reloc_code_real_type r;
1229 va_start (args, fmt);
1235 * If the macro is about to expand into a second instruction,
1236 * print a warning if needed. We need to pass ip as a parameter
1237 * to generate a better warning message here...
1239 if (mips_warn_about_macros && place == NULL && *counter == 1)
1240 as_warn ("Macro instruction expanded into multiple instructions");
1243 *counter += 1; /* bump instruction counter */
1245 r = BFD_RELOC_UNUSED;
1246 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
1247 assert (insn.insn_mo);
1248 assert (strcmp (name, insn.insn_mo->name) == 0);
1250 while (strcmp (fmt, insn.insn_mo->args) != 0
1251 || insn.insn_mo->pinfo == INSN_MACRO)
1254 assert (insn.insn_mo->name);
1255 assert (strcmp (name, insn.insn_mo->name) == 0);
1257 insn.insn_opcode = insn.insn_mo->match;
1273 insn.insn_opcode |= va_arg (args, int) << 16;
1279 insn.insn_opcode |= va_arg (args, int) << 16;
1284 insn.insn_opcode |= va_arg (args, int) << 11;
1289 insn.insn_opcode |= va_arg (args, int) << 11;
1296 insn.insn_opcode |= va_arg (args, int) << 6;
1300 insn.insn_opcode |= va_arg (args, int) << 6;
1304 insn.insn_opcode |= va_arg (args, int) << 6;
1311 insn.insn_opcode |= va_arg (args, int) << 21;
1317 r = (bfd_reloc_code_real_type) va_arg (args, int);
1318 assert (r == BFD_RELOC_MIPS_GPREL
1319 || r == BFD_RELOC_MIPS_LITERAL
1320 || r == BFD_RELOC_LO16
1321 || r == BFD_RELOC_MIPS_GOT16
1322 || r == BFD_RELOC_MIPS_CALL16);
1326 assert (ep != NULL && ep->X_op == O_constant);
1327 insn.insn_opcode |= (ep->X_add_number >> 16) & 0xffff;
1332 assert (ep != NULL);
1334 * This allows macro() to pass an immediate expression for
1335 * creating short branches without creating a symbol.
1336 * Note that the expression still might come from the assembly
1337 * input, in which case the value is not checked for range nor
1338 * is a relocation entry generated (yuck).
1340 if (ep->X_op == O_constant)
1342 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
1346 r = BFD_RELOC_16_PCREL_S2;
1350 assert (ep != NULL);
1351 r = BFD_RELOC_MIPS_JMP;
1360 assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
1362 append_insn (place, &insn, ep, r);
1366 * Generate a "lui" instruction.
1369 macro_build_lui (place, counter, ep, regnum)
1375 expressionS high_expr;
1376 struct mips_cl_insn insn;
1377 bfd_reloc_code_real_type r;
1378 CONST char *name = "lui";
1379 CONST char *fmt = "t,u";
1385 high_expr.X_op = O_constant;
1386 high_expr.X_add_number = 0;
1389 if (high_expr.X_op == O_constant)
1391 /* we can compute the instruction now without a relocation entry */
1392 if (high_expr.X_add_number & 0x8000)
1393 high_expr.X_add_number += 0x10000;
1394 high_expr.X_add_number =
1395 ((unsigned long) high_expr.X_add_number >> 16) & 0xffff;
1396 r = BFD_RELOC_UNUSED;
1400 assert (ep->X_op == O_symbol);
1401 /* _gp_disp is a special case, used from s_cpload. */
1402 assert (mips_pic == 0
1403 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
1404 r = BFD_RELOC_HI16_S;
1408 * If the macro is about to expand into a second instruction,
1409 * print a warning if needed. We need to pass ip as a parameter
1410 * to generate a better warning message here...
1412 if (mips_warn_about_macros && place == NULL && *counter == 1)
1413 as_warn ("Macro instruction expanded into multiple instructions");
1416 *counter += 1; /* bump instruction counter */
1418 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
1419 assert (insn.insn_mo);
1420 assert (strcmp (name, insn.insn_mo->name) == 0);
1421 assert (strcmp (fmt, insn.insn_mo->args) == 0);
1423 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
1424 if (r == BFD_RELOC_UNUSED)
1426 insn.insn_opcode |= high_expr.X_add_number;
1427 append_insn (place, &insn, NULL, r);
1430 append_insn (place, &insn, &high_expr, r);
1434 * Generates code to set the $at register to true (one)
1435 * if reg is less than the immediate expression.
1438 set_at (counter, reg, unsignedp)
1443 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
1444 macro_build ((char *) NULL, counter, &imm_expr,
1445 unsignedp ? "sltiu" : "slti",
1446 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
1449 load_register (counter, AT, &imm_expr);
1450 macro_build ((char *) NULL, counter, NULL,
1451 unsignedp ? "sltu" : "slt",
1452 "d,v,t", AT, reg, AT);
1456 /* Warn if an expression is not a constant. */
1459 check_absolute_expr (ip, ex)
1460 struct mips_cl_insn *ip;
1463 if (ex->X_op != O_constant)
1464 as_warn ("Instruction %s requires absolute expression", ip->insn_mo->name);
1468 * This routine generates the least number of instructions neccessary to load
1469 * an absolute expression value into a register.
1472 load_register (counter, reg, ep)
1477 assert (ep->X_op == O_constant);
1478 if (ep->X_add_number >= -0x8000 && ep->X_add_number < 0x8000)
1479 macro_build ((char *) NULL, counter, ep,
1480 mips_isa < 3 ? "addiu" : "daddiu",
1481 "t,r,j", reg, 0, (int) BFD_RELOC_LO16);
1482 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
1483 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
1484 (int) BFD_RELOC_LO16);
1485 else if ((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0
1486 || ((ep->X_add_number &~ (offsetT) 0x7fffffff)
1487 == ~ (offsetT) 0x7fffffff))
1489 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg);
1490 if ((ep->X_add_number & 0xffff) != 0)
1491 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
1492 (int) BFD_RELOC_LO16);
1494 else if (mips_isa < 3)
1496 as_bad ("Number larger than 32 bits");
1497 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
1498 (int) BFD_RELOC_LO16);
1503 expressionS hi32, lo32;
1507 hi32.X_add_number >>= shift;
1508 hi32.X_add_number &= 0xffffffff;
1509 if ((hi32.X_add_number & 0x80000000) != 0)
1510 hi32.X_add_number |= ~ (offsetT) 0xffffffff;
1511 load_register (counter, reg, &hi32);
1513 lo32.X_add_number &= 0xffffffff;
1514 if ((lo32.X_add_number & 0xffff0000) == 0)
1515 macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg,
1521 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
1524 mid16.X_add_number >>= 16;
1525 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
1526 reg, (int) BFD_RELOC_LO16);
1527 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
1530 if ((lo32.X_add_number & 0xffff) != 0)
1531 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, reg,
1532 (int) BFD_RELOC_LO16);
1536 /* Load an address into a register. */
1539 load_address (counter, reg, ep)
1546 if (ep->X_op != O_constant
1547 && ep->X_op != O_symbol)
1549 as_bad ("expression too complex");
1550 ep->X_op = O_constant;
1553 if (ep->X_op == O_constant)
1554 load_register (counter, reg, ep);
1555 else if (mips_pic == 0)
1557 /* If this is a reference to a GP relative symbol, we want
1558 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
1560 lui $reg,<sym> (BFD_RELOC_HI16_S)
1561 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
1562 If we have an addend, we always use the latter form. */
1563 if (ep->X_add_number != 0)
1568 macro_build ((char *) NULL, counter, ep,
1569 mips_isa < 3 ? "addiu" : "daddiu",
1570 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
1571 p = frag_var (rs_machine_dependent, 8, 0,
1572 RELAX_ENCODE (4, 8, -4, 0, 0, mips_warn_about_macros),
1573 ep->X_add_symbol, (long) 0, (char *) NULL);
1575 macro_build_lui (p, counter, ep, reg);
1578 macro_build (p, counter, ep,
1579 mips_isa < 3 ? "addiu" : "daddiu",
1580 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
1586 /* If this is a reference to an external symbol, we want
1587 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
1589 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
1591 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
1592 If there is a constant, it must be added in afterward. */
1593 ex.X_add_number = ep->X_add_number;
1594 ep->X_add_number = 0;
1596 macro_build ((char *) NULL, counter, ep,
1597 mips_isa < 3 ? "lw" : "ld",
1598 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
1599 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
1600 p = frag_var (rs_machine_dependent, 4, 0,
1601 RELAX_ENCODE (0, 4, -8, 0, 0, mips_warn_about_macros),
1602 ep->X_add_symbol, (long) 0, (char *) NULL);
1603 macro_build (p, counter, ep,
1604 mips_isa < 3 ? "addiu" : "daddiu",
1605 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
1606 if (ex.X_add_number != 0)
1608 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
1609 as_bad ("PIC code offset overflow (max 16 signed bits)");
1610 ex.X_op = O_constant;
1611 macro_build (p, counter, &ex,
1612 mips_isa < 3 ? "addiu" : "daddiu",
1613 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
1620 * This routine implements the seemingly endless macro or synthesized
1621 * instructions and addressing modes in the mips assembly language. Many
1622 * of these macros are simple and are similar to each other. These could
1623 * probably be handled by some kind of table or grammer aproach instead of
1624 * this verbose method. Others are not simple macros but are more like
1625 * optimizing code generation.
1626 * One interesting optimization is when several store macros appear
1627 * consecutivly that would load AT with the upper half of the same address.
1628 * The ensuing load upper instructions are ommited. This implies some kind
1629 * of global optimization. We currently only optimize within a single macro.
1630 * For many of the load and store macros if the address is specified as a
1631 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
1632 * first load register 'at' with zero and use it as the base register. The
1633 * mips assembler simply uses register $zero. Just one tiny optimization
1638 struct mips_cl_insn *ip;
1640 register int treg, sreg, dreg, breg;
1653 bfd_reloc_code_real_type r;
1656 treg = (ip->insn_opcode >> 16) & 0x1f;
1657 dreg = (ip->insn_opcode >> 11) & 0x1f;
1658 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
1659 mask = ip->insn_mo->mask;
1661 expr1.X_op = O_constant;
1662 expr1.X_op_symbol = NULL;
1663 expr1.X_add_symbol = NULL;
1664 expr1.X_add_number = 1;
1676 mips_emit_delays ();
1678 mips_any_noreorder = 1;
1680 expr1.X_add_number = 8;
1681 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
1683 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
1685 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, sreg, 0);
1686 macro_build ((char *) NULL, &icnt, NULL,
1687 dbl ? "dsub" : "sub",
1688 "d,v,t", dreg, 0, sreg);
1711 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
1713 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
1714 (int) BFD_RELOC_LO16);
1717 load_register (&icnt, AT, &imm_expr);
1718 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
1737 if (imm_expr.X_add_number >= 0 && imm_expr.X_add_number < 0x10000)
1739 if (mask != M_NOR_I)
1740 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
1741 sreg, (int) BFD_RELOC_LO16);
1744 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
1745 treg, sreg, (int) BFD_RELOC_LO16);
1746 macro_build ((char *) NULL, &icnt, &imm_expr, "nor", "d,v,t",
1752 load_register (&icnt, AT, &imm_expr);
1753 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
1770 if (imm_expr.X_add_number == 0)
1772 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
1776 load_register (&icnt, AT, &imm_expr);
1777 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
1785 macro_build ((char *) NULL, &icnt, &offset_expr,
1786 likely ? "bgezl" : "bgez",
1792 macro_build ((char *) NULL, &icnt, &offset_expr,
1793 likely ? "blezl" : "blez",
1797 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
1798 macro_build ((char *) NULL, &icnt, &offset_expr,
1799 likely ? "beql" : "beq",
1806 /* check for > max integer */
1807 maxnum = 0x7fffffff;
1815 if (imm_expr.X_add_number >= maxnum)
1818 /* result is always false */
1821 as_warn ("Branch %s is always false (nop)", ip->insn_mo->name);
1822 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
1826 as_warn ("Branch likely %s is always false", ip->insn_mo->name);
1827 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
1832 imm_expr.X_add_number++;
1836 if (mask == M_BGEL_I)
1838 if (imm_expr.X_add_number == 0)
1840 macro_build ((char *) NULL, &icnt, &offset_expr,
1841 likely ? "bgezl" : "bgez",
1845 if (imm_expr.X_add_number == 1)
1847 macro_build ((char *) NULL, &icnt, &offset_expr,
1848 likely ? "bgtzl" : "bgtz",
1852 maxnum = 0x7fffffff;
1860 maxnum = - maxnum - 1;
1861 if (imm_expr.X_add_number <= maxnum)
1864 /* result is always true */
1865 as_warn ("Branch %s is always true", ip->insn_mo->name);
1866 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
1869 set_at (&icnt, sreg, 0);
1870 macro_build ((char *) NULL, &icnt, &offset_expr,
1871 likely ? "beql" : "beq",
1882 macro_build ((char *) NULL, &icnt, &offset_expr,
1883 likely ? "beql" : "beq",
1887 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
1889 macro_build ((char *) NULL, &icnt, &offset_expr,
1890 likely ? "beql" : "beq",
1897 if (sreg == 0 || imm_expr.X_add_number == -1)
1899 imm_expr.X_add_number++;
1903 if (mask == M_BGEUL_I)
1905 if (imm_expr.X_add_number == 0)
1907 if (imm_expr.X_add_number == 1)
1909 macro_build ((char *) NULL, &icnt, &offset_expr,
1910 likely ? "bnel" : "bne",
1914 set_at (&icnt, sreg, 1);
1915 macro_build ((char *) NULL, &icnt, &offset_expr,
1916 likely ? "beql" : "beq",
1925 macro_build ((char *) NULL, &icnt, &offset_expr,
1926 likely ? "bgtzl" : "bgtz",
1932 macro_build ((char *) NULL, &icnt, &offset_expr,
1933 likely ? "bltzl" : "bltz",
1937 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
1938 macro_build ((char *) NULL, &icnt, &offset_expr,
1939 likely ? "bnel" : "bne",
1948 macro_build ((char *) NULL, &icnt, &offset_expr,
1949 likely ? "bnel" : "bne",
1955 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
1957 macro_build ((char *) NULL, &icnt, &offset_expr,
1958 likely ? "bnel" : "bne",
1967 macro_build ((char *) NULL, &icnt, &offset_expr,
1968 likely ? "blezl" : "blez",
1974 macro_build ((char *) NULL, &icnt, &offset_expr,
1975 likely ? "bgezl" : "bgez",
1979 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
1980 macro_build ((char *) NULL, &icnt, &offset_expr,
1981 likely ? "beql" : "beq",
1988 maxnum = 0x7fffffff;
1996 if (imm_expr.X_add_number >= maxnum)
1998 imm_expr.X_add_number++;
2002 if (mask == M_BLTL_I)
2004 if (imm_expr.X_add_number == 0)
2006 macro_build ((char *) NULL, &icnt, &offset_expr,
2007 likely ? "bltzl" : "bltz",
2011 if (imm_expr.X_add_number == 1)
2013 macro_build ((char *) NULL, &icnt, &offset_expr,
2014 likely ? "blezl" : "blez",
2018 set_at (&icnt, sreg, 0);
2019 macro_build ((char *) NULL, &icnt, &offset_expr,
2020 likely ? "bnel" : "bne",
2029 macro_build ((char *) NULL, &icnt, &offset_expr,
2030 likely ? "beql" : "beq",
2036 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
2038 macro_build ((char *) NULL, &icnt, &offset_expr,
2039 likely ? "beql" : "beq",
2046 if (sreg == 0 || imm_expr.X_add_number == -1)
2048 imm_expr.X_add_number++;
2052 if (mask == M_BLTUL_I)
2054 if (imm_expr.X_add_number == 0)
2056 if (imm_expr.X_add_number == 1)
2058 macro_build ((char *) NULL, &icnt, &offset_expr,
2059 likely ? "beql" : "beq",
2063 set_at (&icnt, sreg, 1);
2064 macro_build ((char *) NULL, &icnt, &offset_expr,
2065 likely ? "bnel" : "bne",
2074 macro_build ((char *) NULL, &icnt, &offset_expr,
2075 likely ? "bltzl" : "bltz",
2081 macro_build ((char *) NULL, &icnt, &offset_expr,
2082 likely ? "bgtzl" : "bgtz",
2086 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
2087 macro_build ((char *) NULL, &icnt, &offset_expr,
2088 likely ? "bnel" : "bne",
2099 macro_build ((char *) NULL, &icnt, &offset_expr,
2100 likely ? "bnel" : "bne",
2104 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
2106 macro_build ((char *) NULL, &icnt, &offset_expr,
2107 likely ? "bnel" : "bne",
2123 as_warn ("Divide by zero.");
2124 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
2128 mips_emit_delays ();
2130 mips_any_noreorder = 1;
2131 macro_build ((char *) NULL, &icnt, NULL,
2132 dbl ? "ddiv" : "div",
2133 "z,s,t", sreg, treg);
2134 expr1.X_add_number = 8;
2135 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
2136 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
2137 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
2138 expr1.X_add_number = -1;
2139 macro_build ((char *) NULL, &icnt, &expr1,
2140 dbl ? "daddiu" : "addiu",
2141 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
2142 expr1.X_add_number = dbl ? 20 : 16;
2143 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
2146 expr1.X_add_number = 1;
2147 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
2148 (int) BFD_RELOC_LO16);
2149 macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT,
2154 expr1.X_add_number = 0x80000000;
2155 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT);
2157 expr1.X_add_number = 8;
2158 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
2159 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
2160 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
2162 macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg);
2201 if (imm_expr.X_add_number == 0)
2203 as_warn ("Divide by zero.");
2204 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
2207 if (imm_expr.X_add_number == 1)
2209 if (strcmp (s2, "mflo") == 0)
2210 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg,
2213 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
2216 if (imm_expr.X_add_number == -1
2217 && s[strlen (s) - 1] != 'u')
2219 if (strcmp (s2, "mflo") == 0)
2222 macro_build ((char *) NULL, &icnt, NULL, "dneg", "d,w", dreg,
2225 macro_build ((char *) NULL, &icnt, NULL, "neg", "d,w", dreg,
2229 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
2233 load_register (&icnt, AT, &imm_expr);
2234 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT);
2235 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
2254 mips_emit_delays ();
2256 mips_any_noreorder = 1;
2257 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
2258 expr1.X_add_number = 8;
2259 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
2260 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
2261 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
2263 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
2267 /* Load the address of a symbol into a register. If M_LA_AB, we
2268 then add a base register to it. */
2269 if (offset_expr.X_op != O_symbol
2270 && offset_expr.X_op != O_constant)
2272 as_bad ("expression too complex");
2273 offset_expr.X_op = O_constant;
2287 if (offset_expr.X_op == O_constant)
2288 load_register (&icnt, tempreg, &offset_expr);
2289 else if (mips_pic == 0)
2291 /* If this is a reference to an GP relative symbol, we want
2292 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
2294 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
2295 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
2296 If we have a constant, we need two instructions anyhow,
2297 so we may as well always use the latter form. */
2298 if (offset_expr.X_add_number != 0)
2303 macro_build ((char *) NULL, &icnt, &offset_expr,
2304 mips_isa < 3 ? "addiu" : "daddiu",
2305 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
2306 p = frag_var (rs_machine_dependent, 8, 0,
2307 RELAX_ENCODE (4, 8, 0, 4, 0,
2308 mips_warn_about_macros),
2309 offset_expr.X_add_symbol, (long) 0,
2312 macro_build_lui (p, &icnt, &offset_expr, tempreg);
2315 macro_build (p, &icnt, &offset_expr,
2316 mips_isa < 3 ? "addiu" : "daddiu",
2317 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
2321 /* If this is a reference to an external symbol, and there
2322 is no constant, we want
2323 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2324 For a local symbol, we want
2325 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2327 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
2329 If we have a small constant, and this is a reference to
2330 an external symbol, we want
2331 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2333 addiu $tempreg,$tempreg,<constant>
2334 For a local symbol, we want the same instruction
2335 sequence, but we output a BFD_RELOC_LO16 reloc on the
2338 If we have a large constant, and this is a reference to
2339 an external symbol, we want
2340 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2341 lui $at,<hiconstant>
2342 addiu $at,$at,<loconstant>
2343 addu $tempreg,$tempreg,$at
2344 For a local symbol, we want the same instruction
2345 sequence, but we output a BFD_RELOC_LO16 reloc on the
2346 addiu instruction. */
2347 expr1.X_add_number = offset_expr.X_add_number;
2348 offset_expr.X_add_number = 0;
2350 macro_build ((char *) NULL, &icnt, &offset_expr,
2351 mips_isa < 3 ? "lw" : "ld",
2352 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
2353 if (expr1.X_add_number == 0)
2361 /* We're going to put in an addu instruction using
2362 tempreg, so we may as well insert the nop right
2364 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2368 p = frag_var (rs_machine_dependent, 8 - off, 0,
2369 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
2371 ? mips_warn_about_macros
2373 offset_expr.X_add_symbol, (long) 0,
2377 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
2380 macro_build (p, &icnt, &expr1,
2381 mips_isa < 3 ? "addiu" : "daddiu",
2382 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
2383 /* FIXME: If breg == 0, and the next instruction uses
2384 $tempreg, then if this variant case is used an extra
2385 nop will be generated. */
2387 else if (expr1.X_add_number >= -0x8000
2388 && expr1.X_add_number < 0x8000)
2390 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2392 macro_build ((char *) NULL, &icnt, &expr1,
2393 mips_isa < 3 ? "addiu" : "daddiu",
2394 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
2395 (void) frag_var (rs_machine_dependent, 0, 0,
2396 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
2397 offset_expr.X_add_symbol, (long) 0,
2404 /* If we are going to add in a base register, and the
2405 target register and the base register are the same,
2406 then we are using AT as a temporary register. Since
2407 we want to load the constant into AT, we add our
2408 current AT (from the global offset table) and the
2409 register into the register now, and pretend we were
2410 not using a base register. */
2415 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2417 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2418 mips_isa < 3 ? "addu" : "daddu",
2419 "d,v,t", treg, AT, breg);
2425 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
2426 macro_build ((char *) NULL, &icnt, &expr1,
2427 mips_isa < 3 ? "addiu" : "daddiu",
2428 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
2429 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2430 mips_isa < 3 ? "addu" : "daddu",
2431 "d,v,t", tempreg, tempreg, AT);
2432 (void) frag_var (rs_machine_dependent, 0, 0,
2433 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
2434 offset_expr.X_add_symbol, (long) 0,
2441 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2442 mips_isa < 3 ? "addu" : "daddu",
2443 "d,v,t", treg, tempreg, breg);
2451 /* The j instruction may not be used in PIC code, since it
2452 requires an absolute address. We convert it to a b
2455 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
2457 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
2460 /* The jal instructions must be handled as macros because when
2461 generating PIC code they expand to multi-instruction
2462 sequences. Normally they are simple instructions. */
2469 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
2474 /* I only know how to handle pic2. */
2475 assert (mips_pic == 2);
2477 if (sreg != PIC_CALL_REG)
2478 as_warn ("MIPS PIC call to register other than $25");
2480 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", "d,s",
2482 if (mips_cprestore_offset < 0)
2483 as_warn ("No .cprestore pseudo-op used in PIC code");
2486 expr1.X_add_number = mips_cprestore_offset;
2487 macro_build ((char *) NULL, &icnt, &expr1,
2488 mips_isa < 3 ? "lw" : "ld",
2489 "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg);
2496 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
2500 /* I only know how to handle pic2. */
2501 assert (mips_pic == 2);
2503 /* If this is a reference to an external symbol, we want
2504 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
2508 lw $gp,cprestore($sp)
2509 The cprestore value is set using the .cprestore pseudo-op.
2510 If the symbol is not external, we want
2511 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2513 addiu $25,$25,<sym> (BFD_RELOC_LO16)
2516 lw $gp,cprestore($sp)
2519 macro_build ((char *) NULL, &icnt, &offset_expr,
2520 mips_isa < 3 ? "lw" : "ld",
2521 "t,o(b)", PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL16, GP);
2522 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
2523 p = frag_var (rs_machine_dependent, 4, 0,
2524 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
2525 offset_expr.X_add_symbol, (long) 0, (char *) NULL);
2526 macro_build (p, &icnt, &offset_expr,
2527 mips_isa < 3 ? "addiu" : "daddiu",
2528 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
2529 (int) BFD_RELOC_LO16);
2530 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", "s",
2532 if (mips_cprestore_offset < 0)
2533 as_warn ("No .cprestore pseudo-op used in PIC code");
2537 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2539 expr1.X_add_number = mips_cprestore_offset;
2540 macro_build ((char *) NULL, &icnt, &expr1,
2541 mips_isa < 3 ? "lw" : "ld",
2542 "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg);
2610 if (breg == treg || coproc)
2679 if (mask == M_LWC1_AB
2680 || mask == M_SWC1_AB
2681 || mask == M_LDC1_AB
2682 || mask == M_SDC1_AB
2691 if (offset_expr.X_op != O_constant
2692 && offset_expr.X_op != O_symbol)
2694 as_bad ("expression too complex");
2695 offset_expr.X_op = O_constant;
2698 /* A constant expression in PIC code can be handled just as it
2699 is in non PIC code. */
2701 || offset_expr.X_op == O_constant)
2703 /* If this is a reference to a GP relative symbol, and there
2704 is no base register, we want
2705 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
2707 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
2708 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
2709 If we have a constant, we need two instructions anyhow,
2710 so we always use the latter form.
2712 If we have a base register, and this is a reference to a
2713 GP relative symbol, we want
2714 addu $tempreg,$breg,$gp
2715 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
2717 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
2718 addu $tempreg,$tempreg,$breg
2719 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
2720 With a constant we always use the latter case. */
2723 if (offset_expr.X_add_number != 0)
2728 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
2729 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
2730 p = frag_var (rs_machine_dependent, 8, 0,
2731 RELAX_ENCODE (4, 8, 0, 4, 0,
2732 (mips_warn_about_macros
2733 || (used_at && mips_noat))),
2734 offset_expr.X_add_symbol, (long) 0,
2738 macro_build_lui (p, &icnt, &offset_expr, tempreg);
2741 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
2742 (int) BFD_RELOC_LO16, tempreg);
2746 if (offset_expr.X_add_number != 0)
2751 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2752 mips_isa < 3 ? "addu" : "daddu",
2753 "d,v,t", tempreg, breg, GP);
2754 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
2755 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
2756 p = frag_var (rs_machine_dependent, 12, 0,
2757 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
2758 offset_expr.X_add_symbol, (long) 0,
2761 macro_build_lui (p, &icnt, &offset_expr, tempreg);
2764 macro_build (p, &icnt, (expressionS *) NULL,
2765 mips_isa < 3 ? "addu" : "daddu",
2766 "d,v,t", tempreg, tempreg, breg);
2769 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
2770 (int) BFD_RELOC_LO16, tempreg);
2775 /* If this is a reference to an external symbol, we want
2776 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2778 <op> $treg,0($tempreg)
2780 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2782 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
2783 <op> $treg,0($tempreg)
2784 If there is a base register, we add it to $tempreg before
2785 the <op>. If there is a constant, we stick it in the
2786 <op> instruction. We don't handle constants larger than
2787 16 bits, because we have no way to load the upper 16 bits
2788 (actually, we could handle them for the subset of cases
2789 in which we are not using $at). */
2790 assert (offset_expr.X_op == O_symbol);
2791 expr1.X_add_number = offset_expr.X_add_number;
2792 offset_expr.X_add_number = 0;
2793 if (expr1.X_add_number < -0x8000
2794 || expr1.X_add_number >= 0x8000)
2795 as_bad ("PIC code offset overflow (max 16 signed bits)");
2797 macro_build ((char *) NULL, &icnt, &offset_expr,
2798 mips_isa < 3 ? "lw" : "ld",
2799 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
2800 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
2801 p = frag_var (rs_machine_dependent, 4, 0,
2802 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
2803 offset_expr.X_add_symbol, (long) 0,
2805 macro_build (p, &icnt, &offset_expr,
2806 mips_isa < 3 ? "addiu" : "daddiu",
2807 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
2809 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2810 mips_isa < 3 ? "addu" : "daddu",
2811 "d,v,t", tempreg, tempreg, breg);
2812 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
2813 (int) BFD_RELOC_LO16, tempreg);
2823 load_register (&icnt, treg, &imm_expr);
2829 assert (offset_expr.X_op == O_symbol
2830 && strcmp (segment_name (S_GET_SEGMENT
2831 (offset_expr.X_add_symbol)),
2833 && offset_expr.X_add_number == 0);
2834 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
2835 treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
2839 assert (imm_expr.X_op == O_constant);
2840 load_register (&icnt, treg, &imm_expr);
2845 /* We know that sym is in the .rdata instruction. First we get
2846 the upper 16 bits of the address. */
2849 /* FIXME: This won't work for a 64 bit address. */
2850 macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
2854 macro_build ((char *) NULL, &icnt, &offset_expr,
2855 mips_isa < 3 ? "lw" : "ld",
2856 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
2858 /* Now we load the register(s). */
2860 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
2861 treg, (int) BFD_RELOC_LO16, AT);
2864 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
2865 treg, (int) BFD_RELOC_LO16, AT);
2868 /* FIXME: How in the world do we deal with the possible
2870 offset_expr.X_add_number += 4;
2871 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
2872 treg + 1, (int) BFD_RELOC_LO16, AT);
2881 /* Load a floating point number from the .lit8 section. */
2882 assert (offset_expr.X_op == O_symbol
2883 && strcmp (segment_name (S_GET_SEGMENT
2884 (offset_expr.X_add_symbol)),
2886 && offset_expr.X_add_number == 0);
2889 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
2890 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
2894 r = BFD_RELOC_MIPS_LITERAL;
2899 /* Load the double from the .rdata section. */
2900 macro_build ((char *) NULL, &icnt, &offset_expr,
2901 mips_isa < 3 ? "lw" : "ld",
2902 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
2905 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
2906 "T,o(b)", treg, (int) BFD_RELOC_LO16, GP);
2915 /* Even on a big endian machine $fn comes before $fn+1. We have
2916 to adjust when loading from memory. */
2919 assert (mips_isa < 2);
2920 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
2921 byte_order == LITTLE_ENDIAN ? treg : treg + 1,
2923 /* FIXME: A possible overflow which I don't know how to deal
2925 offset_expr.X_add_number += 4;
2926 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
2927 byte_order == LITTLE_ENDIAN ? treg + 1 : treg,
2935 * The MIPS assembler seems to check for X_add_number not
2936 * being double aligned and generating:
2939 * addiu at,at,%lo(foo+1)
2942 * But, the resulting address is the same after relocation so why
2943 * generate the extra instruction?
2990 if (offset_expr.X_op != O_symbol
2991 && offset_expr.X_op != O_constant)
2993 as_bad ("expression too complex");
2994 offset_expr.X_op = O_constant;
2997 /* Even on a big endian machine $fn comes before $fn+1. We have
2998 to adjust when loading from memory. We set coproc if we must
2999 load $fn+1 first. */
3000 if (byte_order == LITTLE_ENDIAN)
3004 || offset_expr.X_op == O_constant)
3006 /* If this is a reference to a GP relative symbol, we want
3007 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
3008 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
3009 If we have a base register, we use this
3011 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
3012 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
3013 If this is not a GP relative symbol, we want
3014 lui $at,<sym> (BFD_RELOC_HI16_S)
3015 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
3016 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
3017 If there is a base register, we add it to $at after the
3018 lui instruction. If there is a constant, we always use
3020 if (offset_expr.X_add_number != 0)
3039 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3040 mips_isa < 3 ? "addu" : "daddu",
3041 "d,v,t", AT, breg, GP);
3047 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
3048 coproc ? treg + 1 : treg,
3049 (int) BFD_RELOC_MIPS_GPREL, tempreg);
3050 offset_expr.X_add_number += 4;
3051 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
3052 coproc ? treg : treg + 1,
3053 (int) BFD_RELOC_MIPS_GPREL, tempreg);
3054 p = frag_var (rs_machine_dependent, 12 + off, 0,
3055 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
3056 used_at && mips_noat),
3057 offset_expr.X_add_symbol, (long) 0,
3060 /* We just generated two relocs. When tc_gen_reloc
3061 handles this case, it will skip the first reloc and
3062 handle the second. The second reloc already has an
3063 extra addend of 4, which we added above. We must
3064 subtract it out, and then subtract another 4 to make
3065 the first reloc come out right. The second reloc
3066 will come out right because we are going to add 4 to
3067 offset_expr when we build its instruction below. */
3068 offset_expr.X_add_number -= 8;
3069 offset_expr.X_op = O_constant;
3071 macro_build_lui (p, &icnt, &offset_expr, AT);
3076 macro_build (p, &icnt, (expressionS *) NULL,
3077 mips_isa < 3 ? "addu" : "daddu",
3078 "d,v,t", AT, breg, AT);
3082 macro_build (p, &icnt, &offset_expr, s, fmt,
3083 coproc ? treg + 1 : treg,
3084 (int) BFD_RELOC_LO16, AT);
3087 /* FIXME: How do we handle overflow here? */
3088 offset_expr.X_add_number += 4;
3089 macro_build (p, &icnt, &offset_expr, s, fmt,
3090 coproc ? treg : treg + 1,
3091 (int) BFD_RELOC_LO16, AT);
3097 /* If this is a reference to an external symbol, we want
3098 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3103 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3105 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
3106 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
3107 If there is a base register we add it to $at before the
3108 lwc1 instructions. If there is a constant we include it
3109 in the lwc1 instructions. */
3111 expr1.X_add_number = offset_expr.X_add_number;
3112 offset_expr.X_add_number = 0;
3113 if (expr1.X_add_number < -0x8000
3114 || expr1.X_add_number >= 0x8000 - 4)
3115 as_bad ("PIC code offset overflow (max 16 signed bits)");
3120 frag_grow (16 + off);
3121 macro_build ((char *) NULL, &icnt, &offset_expr,
3122 mips_isa < 3 ? "lw" : "ld",
3123 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
3124 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
3126 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3127 mips_isa < 3 ? "addu" : "daddu",
3128 "d,v,t", AT, breg, AT);
3129 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
3130 coproc ? treg + 1 : treg,
3131 (int) BFD_RELOC_LO16, AT);
3132 expr1.X_add_number += 4;
3133 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
3134 coproc ? treg : treg + 1,
3135 (int) BFD_RELOC_LO16, AT);
3136 (void) frag_var (rs_machine_dependent, 0, 0,
3137 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
3138 offset_expr.X_add_symbol, (long) 0,
3153 assert (mips_isa < 3);
3154 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
3155 (int) BFD_RELOC_LO16, breg);
3156 offset_expr.X_add_number += 4;
3157 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
3158 (int) BFD_RELOC_LO16, breg);
3160 #ifdef LOSING_COMPILER
3166 as_warn ("Macro used $at after \".set noat\"");
3171 struct mips_cl_insn *ip;
3173 register int treg, sreg, dreg, breg;
3186 bfd_reloc_code_real_type r;
3189 treg = (ip->insn_opcode >> 16) & 0x1f;
3190 dreg = (ip->insn_opcode >> 11) & 0x1f;
3191 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3192 mask = ip->insn_mo->mask;
3194 expr1.X_op = O_constant;
3195 expr1.X_op_symbol = NULL;
3196 expr1.X_add_symbol = NULL;
3197 expr1.X_add_number = 1;
3201 #endif /* LOSING_COMPILER */
3206 macro_build ((char *) NULL, &icnt, NULL,
3207 dbl ? "dmultu" : "multu",
3209 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3215 /* The MIPS assembler some times generates shifts and adds. I'm
3216 not trying to be that fancy. GCC should do this for us
3218 load_register (&icnt, AT, &imm_expr);
3219 macro_build ((char *) NULL, &icnt, NULL,
3220 dbl ? "dmult" : "mult",
3222 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3228 mips_emit_delays ();
3230 mips_any_noreorder = 1;
3231 macro_build ((char *) NULL, &icnt, NULL,
3232 dbl ? "dmult" : "mult",
3234 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3235 macro_build ((char *) NULL, &icnt, NULL,
3236 dbl ? "dsra32" : "sra",
3237 "d,w,<", dreg, dreg, 31);
3238 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
3239 expr1.X_add_number = 8;
3240 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
3241 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3242 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
3244 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3250 mips_emit_delays ();
3252 mips_any_noreorder = 1;
3253 macro_build ((char *) NULL, &icnt, NULL,
3254 dbl ? "dmultu" : "multu",
3256 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
3257 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3258 expr1.X_add_number = 8;
3259 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
3260 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3261 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
3266 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
3267 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT);
3268 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg,
3270 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
3274 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg,
3275 imm_expr.X_add_number & 0x1f);
3276 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg,
3277 (0 - imm_expr.X_add_number) & 0x1f);
3278 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
3282 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
3283 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT);
3284 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg,
3286 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
3290 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg,
3291 imm_expr.X_add_number & 0x1f);
3292 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg,
3293 (0 - imm_expr.X_add_number) & 0x1f);
3294 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
3298 assert (mips_isa < 2);
3299 /* Even on a big endian machine $fn comes before $fn+1. We have
3300 to adjust when storing to memory. */
3301 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
3302 byte_order == LITTLE_ENDIAN ? treg : treg + 1,
3303 (int) BFD_RELOC_LO16, breg);
3304 offset_expr.X_add_number += 4;
3305 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
3306 byte_order == LITTLE_ENDIAN ? treg + 1 : treg,
3307 (int) BFD_RELOC_LO16, breg);
3312 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
3313 treg, (int) BFD_RELOC_LO16);
3315 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
3316 sreg, (int) BFD_RELOC_LO16);
3319 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
3321 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
3322 dreg, (int) BFD_RELOC_LO16);
3327 if (imm_expr.X_add_number == 0)
3329 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
3330 sreg, (int) BFD_RELOC_LO16);
3335 as_warn ("Instruction %s: result is always false",
3337 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
3340 if (imm_expr.X_add_number >= 0 && imm_expr.X_add_number < 0x10000)
3342 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
3343 sreg, (int) BFD_RELOC_LO16);
3346 else if (imm_expr.X_add_number > -0x8000 && imm_expr.X_add_number < 0)
3348 imm_expr.X_add_number = -imm_expr.X_add_number;
3349 macro_build ((char *) NULL, &icnt, &imm_expr,
3350 mips_isa < 3 ? "addiu" : "daddiu",
3351 "t,r,j", dreg, sreg,
3352 (int) BFD_RELOC_LO16);
3357 load_register (&icnt, AT, &imm_expr);
3358 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
3362 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
3363 (int) BFD_RELOC_LO16);
3368 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
3374 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg);
3375 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
3376 (int) BFD_RELOC_LO16);
3379 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
3381 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
3383 macro_build ((char *) NULL, &icnt, &expr1,
3384 mask == M_SGE_I ? "slti" : "sltiu",
3385 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
3390 load_register (&icnt, AT, &imm_expr);
3391 macro_build ((char *) NULL, &icnt, NULL,
3392 mask == M_SGE_I ? "slt" : "sltu",
3393 "d,v,t", dreg, sreg, AT);
3396 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
3397 (int) BFD_RELOC_LO16);
3402 case M_SGT: /* sreg > treg <==> treg < sreg */
3408 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
3411 case M_SGT_I: /* sreg > I <==> I < sreg */
3417 load_register (&icnt, AT, &imm_expr);
3418 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
3421 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
3427 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
3428 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
3429 (int) BFD_RELOC_LO16);
3432 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
3438 load_register (&icnt, AT, &imm_expr);
3439 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
3440 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
3441 (int) BFD_RELOC_LO16);
3445 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
3447 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
3448 dreg, sreg, (int) BFD_RELOC_LO16);
3451 load_register (&icnt, AT, &imm_expr);
3452 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT);
3456 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
3458 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
3459 dreg, sreg, (int) BFD_RELOC_LO16);
3462 load_register (&icnt, AT, &imm_expr);
3463 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg,
3469 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
3472 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
3476 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
3478 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
3484 if (imm_expr.X_add_number == 0)
3486 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
3492 as_warn ("Instruction %s: result is always true",
3494 macro_build ((char *) NULL, &icnt, &expr1,
3495 mips_isa < 3 ? "addiu" : "daddiu",
3496 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
3499 if (imm_expr.X_add_number >= 0 && imm_expr.X_add_number < 0x10000)
3501 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
3502 dreg, sreg, (int) BFD_RELOC_LO16);
3505 else if (imm_expr.X_add_number > -0x8000 && imm_expr.X_add_number < 0)
3507 imm_expr.X_add_number = -imm_expr.X_add_number;
3508 macro_build ((char *) NULL, &icnt, &imm_expr,
3509 mips_isa < 3 ? "addiu" : "daddiu",
3510 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
3515 load_register (&icnt, AT, &imm_expr);
3516 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
3520 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
3528 if (imm_expr.X_add_number > -0x8000 && imm_expr.X_add_number <= 0x8000)
3530 imm_expr.X_add_number = -imm_expr.X_add_number;
3531 macro_build ((char *) NULL, &icnt, &imm_expr,
3532 dbl ? "daddi" : "addi",
3533 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
3536 load_register (&icnt, AT, &imm_expr);
3537 macro_build ((char *) NULL, &icnt, NULL,
3538 dbl ? "dsub" : "sub",
3539 "d,v,t", dreg, sreg, AT);
3545 if (imm_expr.X_add_number > -0x8000 && imm_expr.X_add_number <= 0x8000)
3547 imm_expr.X_add_number = -imm_expr.X_add_number;
3548 macro_build ((char *) NULL, &icnt, &imm_expr,
3549 dbl ? "daddiu" : "addiu",
3550 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
3553 load_register (&icnt, AT, &imm_expr);
3554 macro_build ((char *) NULL, &icnt, NULL,
3555 dbl ? "dsubu" : "subu",
3556 "d,v,t", dreg, sreg, AT);
3577 load_register (&icnt, AT, &imm_expr);
3578 macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT);
3583 assert (mips_isa < 2);
3584 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
3585 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
3588 * Is the double cfc1 instruction a bug in the mips assembler;
3589 * or is there a reason for it?
3591 mips_emit_delays ();
3593 mips_any_noreorder = 1;
3594 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
3595 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
3596 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
3597 expr1.X_add_number = 3;
3598 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
3599 (int) BFD_RELOC_LO16);
3600 expr1.X_add_number = 2;
3601 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
3602 (int) BFD_RELOC_LO16);
3603 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31);
3604 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
3605 macro_build ((char *) NULL, &icnt, NULL,
3606 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
3607 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31);
3608 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
3618 /* avoid load delay */
3619 offset_expr.X_add_number += 1;
3620 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
3621 (int) BFD_RELOC_LO16, breg);
3622 offset_expr.X_add_number -= 1;
3623 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
3624 (int) BFD_RELOC_LO16, breg);
3625 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
3626 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
3630 /* does this work on a big endian machine? */
3631 offset_expr.X_add_number += 3;
3632 macro_build ((char *) NULL, &icnt, &offset_expr, "lwl", "t,o(b)", treg,
3633 (int) BFD_RELOC_LO16, breg);
3634 offset_expr.X_add_number -= 3;
3635 macro_build ((char *) NULL, &icnt, &offset_expr, "lwr", "t,o(b)", treg,
3636 (int) BFD_RELOC_LO16, breg);
3642 load_address (&icnt, AT, &offset_expr);
3643 if (mask == M_ULW_A)
3645 expr1.X_add_number = 3;
3646 macro_build ((char *) NULL, &icnt, &expr1, "lwl", "t,o(b)", treg,
3647 (int) BFD_RELOC_LO16, AT);
3648 expr1.X_add_number = 0;
3649 macro_build ((char *) NULL, &icnt, &expr1, "lwr", "t,o(b)", treg,
3650 (int) BFD_RELOC_LO16, AT);
3654 macro_build ((char *) NULL, &icnt, &expr1,
3655 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
3656 (int) BFD_RELOC_LO16, AT);
3657 expr1.X_add_number = 0;
3658 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
3659 (int) BFD_RELOC_LO16, AT);
3660 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
3662 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
3668 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
3669 (int) BFD_RELOC_LO16, breg);
3670 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8);
3671 offset_expr.X_add_number += 1;
3672 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
3673 (int) BFD_RELOC_LO16, breg);
3677 offset_expr.X_add_number += 3;
3678 macro_build ((char *) NULL, &icnt, &offset_expr, "swl", "t,o(b)", treg,
3679 (int) BFD_RELOC_LO16, breg);
3680 offset_expr.X_add_number -= 3;
3681 macro_build ((char *) NULL, &icnt, &offset_expr, "swr", "t,o(b)", treg,
3682 (int) BFD_RELOC_LO16, breg);
3687 load_address (&icnt, AT, &offset_expr);
3688 if (mask == M_USW_A)
3690 expr1.X_add_number = 3;
3691 macro_build ((char *) NULL, &icnt, &expr1, "swl", "t,o(b)", treg,
3692 (int) BFD_RELOC_LO16, AT);
3693 expr1.X_add_number = 0;
3694 macro_build ((char *) NULL, &icnt, &expr1, "swr", "t,o(b)", treg,
3695 (int) BFD_RELOC_LO16, AT);
3699 expr1.X_add_number = 0;
3700 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
3701 (int) BFD_RELOC_LO16, AT);
3702 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg,
3704 expr1.X_add_number = 1;
3705 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
3706 (int) BFD_RELOC_LO16, AT);
3707 expr1.X_add_number = 0;
3708 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
3709 (int) BFD_RELOC_LO16, AT);
3710 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
3712 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
3718 as_bad ("Macro %s not implemented yet", ip->insn_mo->name);
3722 as_warn ("Macro used $at after \".set noat\"");
3727 This routine assembles an instruction into its binary format. As a side
3728 effect it sets one of the global variables imm_reloc or offset_reloc to the
3729 type of relocation to do if one of the operands is an address expression.
3734 struct mips_cl_insn *ip;
3739 struct mips_opcode *insn;
3742 unsigned int lastregno = 0;
3747 for (s = str; islower (*s) || (*s >= '0' && *s <= '3') || *s == '.'; ++s)
3759 as_warn ("Unknown opcode: `%s'", str);
3762 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
3764 as_warn ("`%s' not in hash table.", str);
3765 insn_error = "ERROR: Unrecognized opcode";
3773 assert (strcmp (insn->name, str) == 0);
3775 if (insn->pinfo == INSN_MACRO)
3776 insn_isa = insn->match;
3777 else if (insn->pinfo & INSN_ISA2)
3779 else if (insn->pinfo & INSN_ISA3)
3784 if (insn_isa > mips_isa)
3786 if (insn + 1 < &mips_opcodes[NUMOPCODES]
3787 && strcmp (insn->name, insn[1].name) == 0)
3792 as_warn ("Instruction not supported on this processor");
3796 ip->insn_opcode = insn->match;
3797 for (args = insn->args;; ++args)
3803 case '\0': /* end of args */
3816 ip->insn_opcode |= lastregno << 21;
3821 ip->insn_opcode |= lastregno << 16;
3825 ip->insn_opcode |= lastregno << 11;
3831 /* handle optional base register.
3832 Either the base register is omitted or
3833 we must have a left paren. */
3834 /* this is dependent on the next operand specifier
3835 is a 'b' for base register */
3836 assert (args[1] == 'b');
3840 case ')': /* these must match exactly */
3845 case '<': /* must be at least one digit */
3847 * According to the manual, if the shift amount is greater
3848 * than 31 or less than 0 the the shift amount should be
3849 * mod 32. In reality the mips assembler issues an error.
3850 * We issue a warning and mask out all but the low 5 bits.
3852 my_getExpression (&imm_expr, s);
3853 check_absolute_expr (ip, &imm_expr);
3854 if ((unsigned long) imm_expr.X_add_number > 31)
3856 as_warn ("Improper shift amount (%ld)",
3857 (long) imm_expr.X_add_number);
3858 imm_expr.X_add_number = imm_expr.X_add_number & 0x1f;
3860 ip->insn_opcode |= imm_expr.X_add_number << 6;
3861 imm_expr.X_op = O_absent;
3865 case '>': /* shift amount minus 32 */
3866 my_getExpression (&imm_expr, s);
3867 check_absolute_expr (ip, &imm_expr);
3868 if ((unsigned long) imm_expr.X_add_number < 32
3869 || (unsigned long) imm_expr.X_add_number > 63)
3871 ip->insn_opcode |= (imm_expr.X_add_number - 32) << 6;
3872 imm_expr.X_op = O_absent;
3876 case 'k': /* cache code */
3877 my_getExpression (&imm_expr, s);
3878 check_absolute_expr (ip, &imm_expr);
3879 if ((unsigned long) imm_expr.X_add_number > 31)
3881 as_warn ("Invalid cahce opcode (%lu)",
3882 (unsigned long) imm_expr.X_add_number);
3883 imm_expr.X_add_number &= 0x1f;
3885 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
3886 imm_expr.X_op = O_absent;
3890 case 'c': /* break code */
3891 my_getExpression (&imm_expr, s);
3892 check_absolute_expr (ip, &imm_expr);
3893 if ((unsigned) imm_expr.X_add_number > 1023)
3894 as_warn ("Illegal break code (%ld)",
3895 (long) imm_expr.X_add_number);
3896 ip->insn_opcode |= imm_expr.X_add_number << 16;
3897 imm_expr.X_op = O_absent;
3901 case 'B': /* syscall code */
3902 my_getExpression (&imm_expr, s);
3903 check_absolute_expr (ip, &imm_expr);
3904 if ((unsigned) imm_expr.X_add_number > 0xfffff)
3905 as_warn ("Illegal syscall code (%ld)",
3906 (long) imm_expr.X_add_number);
3907 ip->insn_opcode |= imm_expr.X_add_number << 6;
3908 imm_expr.X_op = O_absent;
3912 case 'C': /* Coprocessor code */
3913 my_getExpression (&imm_expr, s);
3914 check_absolute_expr (ip, &imm_expr);
3915 if ((unsigned long) imm_expr.X_add_number >= (1<<25))
3917 as_warn ("Coproccesor code > 25 bits (%ld)",
3918 (long) imm_expr.X_add_number);
3919 imm_expr.X_add_number &= ((1<<25) - 1);
3921 ip->insn_opcode |= imm_expr.X_add_number;
3922 imm_expr.X_op = O_absent;
3926 case 'b': /* base register */
3927 case 'd': /* destination register */
3928 case 's': /* source register */
3929 case 't': /* target register */
3930 case 'r': /* both target and source */
3931 case 'v': /* both dest and source */
3932 case 'w': /* both dest and target */
3933 case 'E': /* coprocessor target register */
3934 case 'G': /* coprocessor destination register */
3935 case 'x': /* ignore register name */
3936 case 'z': /* must be zero register */
3950 while (isdigit (*s));
3952 as_bad ("Invalid register number (%d)", regno);
3954 else if (*args == 'E' || *args == 'G')
3958 if (s[1] == 'f' && s[2] == 'p')
3963 else if (s[1] == 's' && s[2] == 'p')
3968 else if (s[1] == 'g' && s[2] == 'p')
3973 else if (s[1] == 'a' && s[2] == 't')
3981 if (regno == AT && ! mips_noat)
3982 as_warn ("Used $at without \".set noat\"");
3988 if (c == 'r' || c == 'v' || c == 'w')
3995 /* 'z' only matches $0. */
3996 if (c == 'z' && regno != 0)
4004 ip->insn_opcode |= regno << 21;
4008 ip->insn_opcode |= regno << 11;
4013 ip->insn_opcode |= regno << 16;
4016 /* This case exists because on the r3000 trunc
4017 expands into a macro which requires a gp
4018 register. On the r6000 or r4000 it is
4019 assembled into a single instruction which
4020 ignores the register. Thus the insn version
4021 is MIPS_ISA2 and uses 'x', and the macro
4022 version is MIPS_ISA1 and uses 't'. */
4025 /* This case is for the div instruction, which
4026 acts differently if the destination argument
4027 is $0. This only matches $0, and is checked
4028 outside the switch. */
4039 ip->insn_opcode |= lastregno << 21;
4042 ip->insn_opcode |= lastregno << 16;
4047 case 'D': /* floating point destination register */
4048 case 'S': /* floating point source register */
4049 case 'T': /* floating point target register */
4053 if (s[0] == '$' && s[1] == 'f' && isdigit (s[2]))
4063 while (isdigit (*s));
4066 as_bad ("Invalid float register number (%d)", regno);
4068 if ((regno & 1) != 0
4070 && ! (strcmp (str, "mtc1") == 0 ||
4071 strcmp (str, "mfc1") == 0 ||
4072 strcmp (str, "lwc1") == 0 ||
4073 strcmp (str, "swc1") == 0))
4074 as_warn ("Float register should be even, was %d",
4082 if (c == 'V' || c == 'W')
4092 ip->insn_opcode |= regno << 6;
4096 ip->insn_opcode |= regno << 11;
4100 ip->insn_opcode |= regno << 16;
4108 ip->insn_opcode |= lastregno << 11;
4111 ip->insn_opcode |= lastregno << 16;
4117 my_getExpression (&imm_expr, s);
4118 check_absolute_expr (ip, &imm_expr);
4123 my_getExpression (&offset_expr, s);
4124 imm_reloc = BFD_RELOC_32;
4136 unsigned char temp[8];
4138 unsigned int length;
4143 /* These only appear as the last operand in an
4144 instruction, and every instruction that accepts
4145 them in any variant accepts them in all variants.
4146 This means we don't have to worry about backing out
4147 any changes if the instruction does not match.
4149 The difference between them is the size of the
4150 floating point constant and where it goes. For 'F'
4151 and 'L' the constant is 64 bits; for 'f' and 'l' it
4152 is 32 bits. Where the constant is placed is based
4153 on how the MIPS assembler does things:
4156 f -- immediate value
4159 When generating PIC code, we do not use the .lit8
4160 or .lit4 sections at all, in order to reserve the
4161 entire global offset table. */
4163 f64 = *args == 'F' || *args == 'L';
4165 save_in = input_line_pointer;
4166 input_line_pointer = s;
4167 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
4169 s = input_line_pointer;
4170 input_line_pointer = save_in;
4171 if (err != NULL && *err != '\0')
4173 as_bad ("Bad floating point constant: %s", err);
4174 memset (temp, '\0', sizeof temp);
4175 length = f64 ? 8 : 4;
4178 assert (length == (f64 ? 8 : 4));
4181 || (mips_pic != 0 && *args == 'l'))
4183 imm_expr.X_op = O_constant;
4184 if (byte_order == LITTLE_ENDIAN)
4185 imm_expr.X_add_number =
4186 (((((((int) temp[3] << 8)
4191 imm_expr.X_add_number =
4192 (((((((int) temp[0] << 8)
4199 const char *newname;
4202 /* Switch to the right section. */
4204 subseg = now_subseg;
4207 default: /* unused default case avoids warnings. */
4209 newname = (mips_pic == 0 ? ".lit8" : ".rdata");
4215 assert (mips_pic == 0);
4219 new_seg = subseg_new (newname, (subsegT) 0);
4221 bfd_set_section_alignment (stdoutput, new_seg, 4);
4224 as_bad ("Can't use floating point insn in this section");
4226 /* Set the argument to the current address in the
4228 offset_expr.X_op = O_symbol;
4229 offset_expr.X_add_symbol =
4230 symbol_new ("L0\001", now_seg,
4231 (valueT) frag_now_fix (), frag_now);
4232 offset_expr.X_add_number = 0;
4234 /* Put the floating point number into the section. */
4235 p = frag_more ((int) length);
4236 memcpy (p, temp, length);
4238 /* Switch back to the original section. */
4239 subseg_set (seg, subseg);
4244 case 'i': /* 16 bit unsigned immediate */
4245 case 'j': /* 16 bit signed immediate */
4246 imm_reloc = BFD_RELOC_LO16;
4247 c = my_getSmallExpression (&imm_expr, s);
4252 if (imm_expr.X_op == O_constant)
4253 imm_expr.X_add_number =
4254 (imm_expr.X_add_number >> 16) & 0xffff;
4256 imm_reloc = BFD_RELOC_HI16_S;
4258 imm_reloc = BFD_RELOC_HI16;
4262 check_absolute_expr (ip, &imm_expr);
4265 if (imm_expr.X_add_number < 0
4266 || imm_expr.X_add_number >= 0x10000)
4268 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
4269 !strcmp (insn->name, insn[1].name))
4271 as_bad ("16 bit expression not in range 0..65535");
4276 if (imm_expr.X_add_number < -0x8000 ||
4277 imm_expr.X_add_number >= 0x8000)
4279 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
4280 !strcmp (insn->name, insn[1].name))
4282 as_bad ("16 bit expression not in range -32768..32767");
4288 case 'o': /* 16 bit offset */
4289 c = my_getSmallExpression (&offset_expr, s);
4291 * If this value won't fit into a 16 bit offset, then
4292 * go find a macro that will generate the 32 bit offset
4295 if (offset_expr.X_op != O_constant
4296 || offset_expr.X_add_number >= 0x8000
4297 || offset_expr.X_add_number < -0x8000)
4300 offset_reloc = BFD_RELOC_LO16;
4301 if (c == 'h' || c == 'H')
4303 assert (offset_expr.X_op == O_constant);
4304 offset_expr.X_add_number =
4305 (offset_expr.X_add_number >> 16) & 0xffff;
4310 case 'p': /* pc relative offset */
4311 offset_reloc = BFD_RELOC_16_PCREL_S2;
4312 my_getExpression (&offset_expr, s);
4316 case 'u': /* upper 16 bits */
4317 c = my_getSmallExpression (&imm_expr, s);
4318 if (imm_expr.X_op != O_constant
4319 || imm_expr.X_add_number < 0
4320 || imm_expr.X_add_number >= 0x10000)
4321 as_bad ("lui expression not in range 0..65535");
4322 imm_reloc = BFD_RELOC_LO16;
4327 if (imm_expr.X_op == O_constant)
4328 imm_expr.X_add_number =
4329 (imm_expr.X_add_number >> 16) & 0xffff;
4331 imm_reloc = BFD_RELOC_HI16_S;
4333 imm_reloc = BFD_RELOC_HI16;
4339 case 'a': /* 26 bit address */
4340 my_getExpression (&offset_expr, s);
4342 offset_reloc = BFD_RELOC_MIPS_JMP;
4346 fprintf (stderr, "bad char = '%c'\n", *args);
4351 /* Args don't match. */
4352 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
4353 !strcmp (insn->name, insn[1].name))
4359 insn_error = "ERROR: Illegal operands";
4368 my_getSmallExpression (ep, str)
4379 ((str[1] == 'h' && str[2] == 'i')
4380 || (str[1] == 'H' && str[2] == 'I')
4381 || (str[1] == 'l' && str[2] == 'o'))
4393 * A small expression may be followed by a base register.
4394 * Scan to the end of this operand, and then back over a possible
4395 * base register. Then scan the small expression up to that
4396 * point. (Based on code in sparc.c...)
4398 for (sp = str; *sp && *sp != ','; sp++)
4400 if (sp - 4 >= str && sp[-1] == RP)
4402 if (isdigit (sp[-2]))
4404 for (sp -= 3; sp >= str && isdigit (*sp); sp--)
4406 if (*sp == '$' && sp > str && sp[-1] == LP)
4412 else if (sp - 5 >= str
4415 && ((sp[-3] == 'f' && sp[-2] == 'p')
4416 || (sp[-3] == 's' && sp[-2] == 'p')
4417 || (sp[-3] == 'g' && sp[-2] == 'p')
4418 || (sp[-3] == 'a' && sp[-2] == 't')))
4424 /* no expression means zero offset */
4427 /* %xx(reg) is an error */
4428 ep->X_op = O_absent;
4433 ep->X_op = O_constant;
4436 ep->X_add_symbol = NULL;
4437 ep->X_op_symbol = NULL;
4438 ep->X_add_number = 0;
4443 my_getExpression (ep, str);
4450 my_getExpression (ep, str);
4451 return c; /* => %hi or %lo encountered */
4455 my_getExpression (ep, str)
4461 save_in = input_line_pointer;
4462 input_line_pointer = str;
4464 expr_end = input_line_pointer;
4465 input_line_pointer = save_in;
4468 /* Turn a string in input_line_pointer into a floating point constant
4469 of type type, and store the appropriate bytes in *litP. The number
4470 of LITTLENUMS emitted is stored in *sizeP . An error message is
4471 returned, or NULL on OK. */
4474 md_atof (type, litP, sizeP)
4480 LITTLENUM_TYPE words[4];
4496 return "bad call to md_atof";
4499 t = atof_ieee (input_line_pointer, type, words);
4501 input_line_pointer = t;
4505 if (byte_order == LITTLE_ENDIAN)
4507 for (i = prec - 1; i >= 0; i--)
4509 md_number_to_chars (litP, (valueT) words[i], 2);
4515 for (i = 0; i < prec; i++)
4517 md_number_to_chars (litP, (valueT) words[i], 2);
4526 md_number_to_chars (buf, val, n)
4534 number_to_chars_littleendian (buf, val, n);
4538 number_to_chars_bigendian (buf, val, n);
4547 md_parse_option (argP, cntP, vecP)
4552 /* Accept -nocpp but ignore it. */
4553 if (strcmp (*argP, "nocpp") == 0)
4559 if (strcmp (*argP, "EL") == 0
4560 || strcmp (*argP, "EB") == 0)
4562 if ((*argP)[1] == 'B')
4563 byte_order = BIG_ENDIAN;
4565 byte_order = LITTLE_ENDIAN;
4568 if ((*argP)[1] == 'B')
4569 mips_target_format = "a.out-mips-big";
4571 mips_target_format = "a.out-mips-little";
4574 if ((*argP)[1] == 'B')
4575 mips_target_format = "ecoff-bigmips";
4577 mips_target_format = "ecoff-littlemips";
4580 if ((*argP)[1] == 'B')
4581 mips_target_format = "elf32-bigmips";
4583 mips_target_format = "elf32-littlemips";
4586 /* FIXME: This breaks -L -EL. */
4594 if ((*argP)[1] == '0')
4603 if ((*argP)[1] == '\0' || (*argP)[1] == '2')
4608 if (strncmp (*argP, "mips", 4) == 0)
4610 mips_isa = atol (*argP + 4);
4613 else if (mips_isa < 1 || mips_isa > 3)
4615 as_bad ("-mips%d not supported", mips_isa);
4622 if (strncmp (*argP, "mcpu=", 5) == 0)
4626 /* Identify the processor type */
4628 if (strcmp (p, "default") == 0
4629 || strcmp (p, "DEFAULT") == 0)
4633 if (*p == 'r' || *p == 'R')
4640 if (strcmp (p, "2000") == 0
4641 || strcmp (p, "2k") == 0
4642 || strcmp (p, "2K") == 0)
4647 if (strcmp (p, "3000") == 0
4648 || strcmp (p, "3k") == 0
4649 || strcmp (p, "3K") == 0)
4654 if (strcmp (p, "4000") == 0
4655 || strcmp (p, "4k") == 0
4656 || strcmp (p, "4K") == 0)
4661 if (strcmp (p, "6000") == 0
4662 || strcmp (p, "6k") == 0
4663 || strcmp (p, "6K") == 0)
4670 as_bad ("bad value (%s) for -mcpu= switch", *argP + 5);
4683 if ((*argP)[1] != '\0')
4684 g_switch_value = atoi (*argP + 1);
4687 **vecP = (char *) NULL;
4690 g_switch_value = atoi (**vecP);
4693 as_warn ("Number expected after -G");
4700 return 1; /* pretend you parsed the character */
4704 md_pcrel_from (fixP)
4707 /* return the address of the delay slot */
4708 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
4711 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
4712 reloc for a cons. We could use the definition there, except that
4713 we want to handle 64 bit relocs specially. */
4716 cons_fix_new_mips (frag, where, nbytes, exp)
4719 unsigned int nbytes;
4722 /* If we are assembling in 32 bit mode, turn an 8 byte reloc into a
4724 FIXME: There is no way to select anything but 32 bit mode right
4728 if (byte_order == BIG_ENDIAN)
4733 if (nbytes != 2 && nbytes != 4)
4734 as_bad ("Unsupported reloc size %d", nbytes);
4736 fix_new_exp (frag_now, where, (int) nbytes, exp, 0,
4737 nbytes == 2 ? BFD_RELOC_16 : BFD_RELOC_32);
4741 md_apply_fix (fixP, valueP)
4748 assert (fixP->fx_size == 4);
4751 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */
4753 switch (fixP->fx_r_type)
4756 case BFD_RELOC_MIPS_JMP:
4757 case BFD_RELOC_HI16:
4758 case BFD_RELOC_HI16_S:
4759 case BFD_RELOC_LO16:
4760 case BFD_RELOC_MIPS_GPREL:
4761 case BFD_RELOC_MIPS_LITERAL:
4762 case BFD_RELOC_MIPS_CALL16:
4763 case BFD_RELOC_MIPS_GOT16:
4764 case BFD_RELOC_MIPS_GPREL32:
4765 /* Nothing needed to do. The value comes from the reloc entry */
4768 case BFD_RELOC_16_PCREL_S2:
4770 * We need to save the bits in the instruction since fixup_segment()
4771 * might be deleting the relocation entry (i.e., a branch within
4772 * the current segment).
4775 as_warn ("Branch to odd address (%lx)", value);
4777 if ((value & ~0xFFFF) && (value & ~0xFFFF) != (-1 & ~0xFFFF))
4778 as_bad ("Relocation overflow");
4780 /* update old instruction data */
4781 buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal);
4785 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
4789 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
4796 insn |= value & 0xFFFF;
4797 md_number_to_chars ((char *) buf, (valueT) insn, 4);
4811 const struct mips_opcode *p;
4812 int treg, sreg, dreg, shamt;
4817 for (i = 0; i < NUMOPCODES; ++i)
4819 p = &mips_opcodes[i];
4820 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
4822 printf ("%08lx %s\t", oc, p->name);
4823 treg = (oc >> 16) & 0x1f;
4824 sreg = (oc >> 21) & 0x1f;
4825 dreg = (oc >> 11) & 0x1f;
4826 shamt = (oc >> 6) & 0x1f;
4828 for (args = p->args;; ++args)
4839 printf ("%c", *args);
4843 assert (treg == sreg);
4844 printf ("$%d,$%d", treg, sreg);
4849 printf ("$%d", dreg);
4854 printf ("$%d", treg);
4858 printf ("0x%x", treg);
4863 printf ("$%d", sreg);
4867 printf ("0x%08lx", oc & 0x1ffffff);
4879 printf ("$%d", shamt);
4890 printf ("%08lx UNDEFINED\n", oc);
4901 name = input_line_pointer;
4902 c = get_symbol_end ();
4903 p = (symbolS *) symbol_find_or_make (name);
4904 *input_line_pointer = c;
4908 /* Align the current frag to a given power of two. The MIPS assembler
4909 also automatically adjusts any preceding label. */
4912 mips_align (to, fill)
4916 mips_emit_delays ();
4917 frag_align (to, fill);
4918 record_alignment (now_seg, to);
4919 if (insn_label != NULL)
4921 assert (S_GET_SEGMENT (insn_label) == now_seg);
4922 insn_label->sy_frag = frag_now;
4923 S_SET_VALUE (insn_label, (valueT) frag_now_fix ());
4928 /* Align to a given power of two. .align 0 turns off the automatic
4929 alignment used by the data creating pseudo-ops. */
4936 register long temp_fill;
4937 long max_alignment = 15;
4941 o Note that the assembler pulls down any immediately preceeding label
4942 to the aligned address.
4943 o It's not documented but auto alignment is reinstated by
4944 a .align pseudo instruction.
4945 o Note also that after auto alignment is turned off the mips assembler
4946 issues an error on attempt to assemble an improperly aligned data item.
4951 temp = get_absolute_expression ();
4952 if (temp > max_alignment)
4953 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
4956 as_warn ("Alignment negative: 0 assumed.");
4959 if (*input_line_pointer == ',')
4961 input_line_pointer++;
4962 temp_fill = get_absolute_expression ();
4969 mips_align (temp, (int) temp_fill);
4976 demand_empty_rest_of_line ();
4979 /* Handle .ascii and .asciiz. This just calls stringer and forgets
4980 that there was a previous instruction. */
4983 s_stringer (append_zero)
4986 mips_emit_delays ();
4988 stringer (append_zero);
4999 mips_emit_delays ();
5009 subseg_set (bss_section, (subsegT) get_absolute_expression ());
5010 demand_empty_rest_of_line ();
5015 subseg_new (".rdata", (subsegT) get_absolute_expression ());
5016 demand_empty_rest_of_line ();
5018 #else /* ! defined (OBJ_ECOFF) */
5020 seg = subseg_new (".rodata", (subsegT) get_absolute_expression ());
5021 bfd_set_section_flags (stdoutput, seg,
5027 bfd_set_section_alignment (stdoutput, seg, 4);
5028 demand_empty_rest_of_line ();
5030 #else /* ! defined (OBJ_ELF) */
5033 #endif /* ! defined (OBJ_ELF) */
5034 #endif /* ! defined (OBJ_ECOFF) */
5038 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
5040 bfd_set_section_flags (stdoutput, seg,
5041 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
5042 bfd_set_section_alignment (stdoutput, seg, 4);
5044 demand_empty_rest_of_line ();
5046 #else /* ! defined (GPOPT) */
5047 as_bad ("Global pointers not supported; recompile -G 0");
5048 demand_empty_rest_of_line ();
5050 #endif /* ! defined (GPOPT) */
5060 mips_emit_delays ();
5061 if (log_size > 0 && auto_align)
5062 mips_align (log_size, 0);
5064 cons (1 << log_size);
5071 as_fatal ("Encountered `.err', aborting assembly");
5081 symbolP = get_symbol ();
5082 if (*input_line_pointer == ',')
5083 input_line_pointer++;
5084 size = get_absolute_expression ();
5085 S_SET_VALUE (symbolP, size);
5086 S_SET_EXTERNAL (symbolP);
5088 #ifdef ECOFF_DEBUGGING
5089 /* ECOFF needs to distinguish a .comm symbol from a .extern symbol,
5090 so we use an additional ECOFF specific field. */
5091 symbolP->ecoff_undefined = 1;
5099 mips_emit_delays ();
5119 opt = input_line_pointer;
5120 c = get_symbol_end ();
5124 /* FIXME: What does this mean? */
5126 else if (strncmp (opt, "pic", 3) == 0)
5128 mips_pic = atoi (opt + 3);
5129 /* Supposedly no other values are used. */
5130 assert (mips_pic == 0 || mips_pic == 2);
5134 if (g_switch_seen && g_switch_value != 0)
5135 as_warn ("-G may not be used with PIC code");
5137 bfd_set_gp_size (stdoutput, 0);
5141 as_warn ("Unrecognized option \"%s\"", opt);
5143 *input_line_pointer = c;
5144 demand_empty_rest_of_line ();
5151 char *name = input_line_pointer, ch;
5153 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5154 input_line_pointer++;
5155 ch = *input_line_pointer;
5156 *input_line_pointer = '\0';
5158 if (strcmp (name, "reorder") == 0)
5162 prev_insn_unreordered = 1;
5163 prev_prev_insn_unreordered = 1;
5167 else if (strcmp (name, "noreorder") == 0)
5169 mips_emit_delays ();
5171 mips_any_noreorder = 1;
5173 else if (strcmp (name, "at") == 0)
5177 else if (strcmp (name, "noat") == 0)
5181 else if (strcmp (name, "macro") == 0)
5183 mips_warn_about_macros = 0;
5185 else if (strcmp (name, "nomacro") == 0)
5187 if (mips_noreorder == 0)
5188 as_bad ("`noreorder' must be set before `nomacro'");
5189 mips_warn_about_macros = 1;
5191 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
5195 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
5199 else if (strcmp (name, "bopt") == 0)
5203 else if (strcmp (name, "nobopt") == 0)
5207 else if (strncmp (name, "mips", 4) == 0)
5211 /* Permit the user to change the ISA on the fly. Needless to
5212 say, misuse can cause serious problems. */
5213 isa = atoi (name + 4);
5215 mips_isa = file_mips_isa;
5216 else if (isa < 1 || isa > 3)
5217 as_bad ("unknown ISA level");
5223 as_warn ("Tried to set unrecognized symbol: %s\n", name);
5225 *input_line_pointer = ch;
5226 demand_empty_rest_of_line ();
5229 /* The same as the usual .space directive, except that we have to
5230 forget about any previous instruction. */
5233 s_mips_space (param)
5236 mips_emit_delays ();
5241 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
5242 .option pic2. It means to generate SVR4 PIC calls. */
5249 demand_empty_rest_of_line ();
5252 /* Handle the .cpload pseudo-op. This is used when generating SVR4
5253 PIC code. It sets the $gp register for the function based on the
5254 function address, which is in the register named in the argument.
5255 This uses a relocation against _gp_disp, which is handled specially
5256 by the linker. The result is:
5257 lui $gp,%hi(_gp_disp)
5258 addiu $gp,$gp,%lo(_gp_disp)
5259 addu $gp,$gp,.cpload argument
5260 The .cpload argument is normally $25 == $t9. */
5269 /* If we are not generating PIC code, .cpload is ignored. */
5276 /* .cpload should be a in .set noreorder section. */
5277 if (mips_noreorder == 0)
5278 as_warn (".cpload not in noreorder section");
5281 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
5282 ex.X_op_symbol = NULL;
5283 ex.X_add_number = 0;
5285 macro_build_lui ((char *) NULL, &icnt, &ex, GP);
5286 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP,
5287 (int) BFD_RELOC_LO16);
5289 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
5290 GP, GP, tc_get_register (0));
5292 demand_empty_rest_of_line ();
5295 /* Handle the .cprestore pseudo-op. This stores $gp into a given
5296 offset from $sp. The offset is remembered, and after making a PIC
5297 call $gp is restored from that location. */
5300 s_cprestore (ignore)
5306 /* If we are not generating PIC code, .cprestore is ignored. */
5313 mips_cprestore_offset = get_absolute_expression ();
5315 ex.X_op = O_constant;
5316 ex.X_add_symbol = NULL;
5317 ex.X_op_symbol = NULL;
5318 ex.X_add_number = mips_cprestore_offset;
5320 macro_build ((char *) NULL, &icnt, &ex,
5321 mips_isa < 3 ? "sw" : "sd",
5322 "t,o(b)", GP, (int) BFD_RELOC_LO16, SP);
5324 demand_empty_rest_of_line ();
5327 /* Handle the .gpword pseudo-op. This is used when generating PIC
5328 code. It generates a 32 bit GP relative reloc. */
5337 /* When not generating PIC code, this is treated as .word. */
5344 mips_emit_delays ();
5351 if (ex.X_op != O_symbol || ex.X_add_number != 0)
5353 as_bad ("Unsupported use of .gpword");
5354 ignore_rest_of_line ();
5358 md_number_to_chars (p, (valueT) 0, 4);
5359 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0,
5360 BFD_RELOC_MIPS_GPREL32);
5362 demand_empty_rest_of_line ();
5365 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
5366 tables in SVR4 PIC code. */
5375 /* This is ignored when not generating SVR4 PIC code. */
5382 /* Add $gp to the register named as an argument. */
5383 reg = tc_get_register (0);
5384 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5385 mips_isa < 3 ? "addu" : "daddu",
5386 "d,v,t", reg, reg, GP);
5388 demand_empty_rest_of_line ();
5391 /* Parse a register string into a number. Called from the ECOFF code
5392 to parse .frame. The argument is non-zero if this is the frame
5393 register, so that we can record it in mips_frame_reg. */
5396 tc_get_register (frame)
5402 if (*input_line_pointer++ != '$')
5404 as_warn ("expected `$'");
5407 else if (isdigit ((unsigned char) *input_line_pointer))
5409 reg = get_absolute_expression ();
5410 if (reg < 0 || reg >= 32)
5412 as_warn ("Bad register number");
5418 if (strncmp (input_line_pointer, "fp", 2) == 0)
5420 else if (strncmp (input_line_pointer, "sp", 2) == 0)
5422 else if (strncmp (input_line_pointer, "gp", 2) == 0)
5424 else if (strncmp (input_line_pointer, "at", 2) == 0)
5428 as_warn ("Unrecognized register name");
5431 input_line_pointer += 2;
5434 mips_frame_reg = reg != 0 ? reg : SP;
5439 md_section_align (seg, addr)
5443 int align = bfd_get_section_alignment (stdoutput, seg);
5445 return ((addr + (1 << align) - 1) & (-1 << align));
5448 /* Estimate the size of a frag before relaxing. We are not really
5449 relaxing here, and the final size is encoded in the subtype
5454 md_estimate_size_before_relax (fragp, segtype)
5463 const char *symname;
5465 /* Find out whether this symbol can be referenced off the GP
5466 register. It can be if it is smaller than the -G size or if
5467 it is in the .sdata or .sbss section. Certain symbols can
5468 not be referenced off the GP, although it appears as though
5470 symname = S_GET_NAME (fragp->fr_symbol);
5471 if (symname != (const char *) NULL
5472 && (strcmp (symname, "eprol") == 0
5473 || strcmp (symname, "etext") == 0
5474 || strcmp (symname, "_gp") == 0
5475 || strcmp (symname, "edata") == 0
5476 || strcmp (symname, "_fbss") == 0
5477 || strcmp (symname, "_fdata") == 0
5478 || strcmp (symname, "_ftext") == 0
5479 || strcmp (symname, "end") == 0
5480 || strcmp (symname, "_gp_disp") == 0))
5482 else if (! S_IS_DEFINED (fragp->fr_symbol)
5483 && S_GET_VALUE (fragp->fr_symbol) != 0
5484 && S_GET_VALUE (fragp->fr_symbol) <= g_switch_value)
5488 const char *segname;
5490 segname = segment_name (S_GET_SEGMENT (fragp->fr_symbol));
5491 assert (strcmp (segname, ".lit8") != 0
5492 && strcmp (segname, ".lit4") != 0);
5493 change = (strcmp (segname, ".sdata") != 0
5494 && strcmp (segname, ".sbss") != 0);
5496 #else /* ! defined (GPOPT) */
5497 /* We are not optimizing for the GP register. */
5499 #endif /* ! defined (GPOPT) */
5503 asection *symsec = fragp->fr_symbol->bsym->section;
5505 /* This must duplicate the test in adjust_reloc_syms. */
5506 change = (symsec != &bfd_und_section
5507 && symsec != &bfd_abs_section
5508 && ! bfd_is_com_section (symsec));
5513 /* Record the offset to the first reloc in the fr_opcode field.
5514 This lets md_convert_frag and tc_gen_reloc know that the code
5515 must be expanded. */
5516 fragp->fr_opcode = (fragp->fr_literal
5518 - RELAX_OLD (fragp->fr_subtype)
5519 + RELAX_RELOC1 (fragp->fr_subtype));
5520 /* FIXME: This really needs as_warn_where. */
5521 if (RELAX_WARN (fragp->fr_subtype))
5522 as_warn ("AT used after \".set noat\" or macro used after \".set nomacro\"");
5528 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
5531 /* Translate internal representation of relocation info to BFD target
5535 tc_gen_reloc (section, fixp)
5539 static arelent *retval[4];
5542 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
5545 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
5546 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
5547 if (fixp->fx_pcrel == 0)
5548 reloc->addend = fixp->fx_addnumber;
5553 reloc->addend = -reloc->address;
5556 /* If this is a variant frag, we may need to adjust the existing
5557 reloc and generate a new one. */
5558 if (fixp->fx_frag->fr_opcode != NULL
5559 && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
5560 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
5561 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16))
5565 /* If this is not the last reloc in this frag, then we have two
5566 GPREL relocs, both of which are being replaced. Let the
5567 second one handle all of them. */
5568 if (fixp->fx_next != NULL
5569 && fixp->fx_frag == fixp->fx_next->fx_frag)
5571 assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
5572 && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL);
5577 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
5578 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
5579 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
5581 reloc2->sym_ptr_ptr = &fixp->fx_addsy->bsym;
5582 reloc2->address = (reloc->address
5583 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
5584 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
5585 reloc2->addend = fixp->fx_addnumber;
5586 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
5587 assert (reloc2->howto != NULL);
5589 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
5593 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
5596 reloc3->address += 4;
5601 assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL);
5602 fixp->fx_r_type = BFD_RELOC_HI16_S;
5606 if (fixp->fx_r_type != BFD_RELOC_MIPS_GOT16)
5608 assert (fixp->fx_r_type == BFD_RELOC_MIPS_CALL16);
5609 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
5614 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
5616 if (reloc->howto == NULL)
5618 as_bad_where (fixp->fx_file, fixp->fx_line,
5619 "Can not represent relocation in this object file format");
5626 /* Convert a machine dependent frag. */
5629 md_convert_frag (abfd, asec, fragp)
5637 if (fragp->fr_opcode == NULL)
5640 old = RELAX_OLD (fragp->fr_subtype);
5641 new = RELAX_NEW (fragp->fr_subtype);
5642 fixptr = fragp->fr_literal + fragp->fr_fix;
5645 memcpy (fixptr - old, fixptr, new);
5647 fragp->fr_fix += new - old;
5650 /* This function is called whenever a label is defined. It is used
5651 when handling branch delays; if a branch has a label, we assume we
5655 mips_define_label (sym)
5663 /* Some special processing for a MIPS ELF file. */
5666 mips_elf_final_processing ()
5670 /* Write out the .reginfo section. */
5671 s.ri_gprmask = mips_gprmask;
5672 s.ri_cprmask[0] = mips_cprmask[0];
5673 s.ri_cprmask[1] = mips_cprmask[1];
5674 s.ri_cprmask[2] = mips_cprmask[2];
5675 s.ri_cprmask[3] = mips_cprmask[3];
5676 /* The gp_value field is set by the MIPS ELF backend. */
5678 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
5679 ((Elf32_External_RegInfo *)
5680 mips_regmask_frag));
5682 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
5683 sort of BFD interface for this. */
5684 if (mips_any_noreorder)
5685 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
5687 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
5690 #endif /* OBJ_ELF */
5692 #ifndef ECOFF_DEBUGGING
5694 /* These functions should really be defined by the object file format,
5695 since they are related to debugging information. However, this
5696 code has to work for the a.out format, which does not define them,
5697 so we provide simple versions here. These don't actually generate
5698 any debugging information, but they do simple checking and someday
5699 somebody may make them useful. */
5703 struct loc *loc_next;
5704 unsigned long loc_fileno;
5705 unsigned long loc_lineno;
5706 unsigned long loc_offset;
5707 unsigned short loc_delta;
5708 unsigned short loc_count;
5717 struct proc *proc_next;
5718 struct symbol *proc_isym;
5719 struct symbol *proc_end;
5720 unsigned long proc_reg_mask;
5721 unsigned long proc_reg_offset;
5722 unsigned long proc_fpreg_mask;
5723 unsigned long proc_fpreg_offset;
5724 unsigned long proc_frameoffset;
5725 unsigned long proc_framereg;
5726 unsigned long proc_pcreg;
5728 struct file *proc_file;
5735 struct file *file_next;
5736 unsigned long file_fileno;
5737 struct symbol *file_symbol;
5738 struct symbol *file_end;
5739 struct proc *file_proc;
5744 static struct obstack proc_frags;
5745 static procS *proc_lastP;
5746 static procS *proc_rootP;
5747 static int numprocs;
5752 obstack_begin (&proc_frags, 0x2000);
5758 /* check for premature end, nesting errors, etc */
5759 if (proc_lastP && proc_lastP->proc_end == NULL)
5760 as_warn ("missing `.end' at end of assembly");
5763 extern char hex_value[];
5771 if (*input_line_pointer == '-')
5773 ++input_line_pointer;
5776 if (!isdigit (*input_line_pointer))
5777 as_bad ("Expected simple number.");
5778 if (input_line_pointer[0] == '0')
5780 if (input_line_pointer[1] == 'x')
5782 input_line_pointer += 2;
5783 while (isxdigit (*input_line_pointer))
5786 val |= hex_value[(int) *input_line_pointer++];
5788 return negative ? -val : val;
5792 ++input_line_pointer;
5793 while (isdigit (*input_line_pointer))
5796 val |= *input_line_pointer++ - '0';
5798 return negative ? -val : val;
5801 if (!isdigit (*input_line_pointer))
5803 printf (" *input_line_pointer == '%c' 0x%02x\n",
5804 *input_line_pointer, *input_line_pointer);
5805 as_warn ("Invalid number");
5808 while (isdigit (*input_line_pointer))
5811 val += *input_line_pointer++ - '0';
5813 return negative ? -val : val;
5816 /* The .file directive; just like the usual .file directive, but there
5817 is an initial number which is the ECOFF file index. */
5825 line = get_number ();
5830 /* The .end directive. */
5838 if (!is_end_of_line[(unsigned char) *input_line_pointer])
5841 demand_empty_rest_of_line ();
5845 if (now_seg != text_section)
5846 as_warn (".end not in text section");
5849 as_warn (".end and no .ent seen yet.");
5855 assert (S_GET_NAME (p));
5856 if (strcmp (S_GET_NAME (p), S_GET_NAME (proc_lastP->proc_isym)))
5857 as_warn (".end symbol does not match .ent symbol.");
5860 proc_lastP->proc_end = (symbolS *) 1;
5863 /* The .aent and .ent directives. */
5873 symbolP = get_symbol ();
5874 if (*input_line_pointer == ',')
5875 input_line_pointer++;
5877 if (isdigit (*input_line_pointer) || *input_line_pointer == '-')
5878 number = get_number ();
5879 if (now_seg != text_section)
5880 as_warn (".ent or .aent not in text section.");
5882 if (!aent && proc_lastP && proc_lastP->proc_end == NULL)
5883 as_warn ("missing `.end'");
5887 procP = (procS *) obstack_alloc (&proc_frags, sizeof (*procP));
5888 procP->proc_isym = symbolP;
5889 procP->proc_reg_mask = 0;
5890 procP->proc_reg_offset = 0;
5891 procP->proc_fpreg_mask = 0;
5892 procP->proc_fpreg_offset = 0;
5893 procP->proc_frameoffset = 0;
5894 procP->proc_framereg = 0;
5895 procP->proc_pcreg = 0;
5896 procP->proc_end = NULL;
5897 procP->proc_next = NULL;
5899 proc_lastP->proc_next = procP;
5905 demand_empty_rest_of_line ();
5908 /* The .frame directive. */
5921 frame_reg = tc_get_register (1);
5922 if (*input_line_pointer == ',')
5923 input_line_pointer++;
5924 frame_off = get_absolute_expression ();
5925 if (*input_line_pointer == ',')
5926 input_line_pointer++;
5927 pcreg = tc_get_register (0);
5930 assert (proc_rootP);
5931 proc_rootP->proc_framereg = frame_reg;
5932 proc_rootP->proc_frameoffset = frame_off;
5933 proc_rootP->proc_pcreg = pcreg;
5934 /* bob macho .frame */
5936 /* We don't have to write out a frame stab for unoptimized code. */
5937 if (!(frame_reg == FP && frame_off == 0))
5940 as_warn ("No .ent for .frame to use.");
5941 (void) sprintf (str, "R%d;%d", frame_reg, frame_off);
5942 symP = symbol_new (str, N_VFP, 0, frag_now);
5943 S_SET_TYPE (symP, N_RMASK);
5944 S_SET_OTHER (symP, 0);
5945 S_SET_DESC (symP, 0);
5946 symP->sy_forward = proc_lastP->proc_isym;
5947 /* bob perhaps I should have used pseudo set */
5949 demand_empty_rest_of_line ();
5953 /* The .fmask and .mask directives. */
5960 char str[100], *strP;
5966 mask = get_number ();
5967 if (*input_line_pointer == ',')
5968 input_line_pointer++;
5969 off = get_absolute_expression ();
5971 /* bob only for coff */
5972 assert (proc_rootP);
5973 if (reg_type == 'F')
5975 proc_rootP->proc_fpreg_mask = mask;
5976 proc_rootP->proc_fpreg_offset = off;
5980 proc_rootP->proc_reg_mask = mask;
5981 proc_rootP->proc_reg_offset = off;
5984 /* bob macho .mask + .fmask */
5986 /* We don't have to write out a mask stab if no saved regs. */
5990 as_warn ("No .ent for .mask to use.");
5992 for (i = 0; i < 32; i++)
5996 sprintf (strP, "%c%d,", reg_type, i);
5997 strP += strlen (strP);
6001 sprintf (strP, ";%d,", off);
6002 symP = symbol_new (str, N_RMASK, 0, frag_now);
6003 S_SET_TYPE (symP, N_RMASK);
6004 S_SET_OTHER (symP, 0);
6005 S_SET_DESC (symP, 0);
6006 symP->sy_forward = proc_lastP->proc_isym;
6007 /* bob perhaps I should have used pseudo set */
6012 /* The .loc directive. */
6023 assert (now_seg == text_section);
6025 lineno = get_number ();
6026 addroff = obstack_next_free (&frags) - frag_now->fr_literal;
6028 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
6029 S_SET_TYPE (symbolP, N_SLINE);
6030 S_SET_OTHER (symbolP, 0);
6031 S_SET_DESC (symbolP, lineno);
6032 symbolP->sy_segment = now_seg;
6036 #endif /* ! defined (ECOFF_DEBUGGING) */