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. */
110 /* Do not generate PIC code. */
113 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
114 not sure what it is supposed to do. */
117 /* Generate PIC code as in the SVR4 MIPS ABI. */
120 /* Generate PIC code without using a global offset table: the data
121 segment has a maximum size of 64K, all data references are off
122 the $gp register, and all text references are PC relative. This
123 is used on some embedded systems. */
127 static enum mips_pic_level mips_pic;
129 /* 1 if trap instructions should used for overflow rather than break
131 static int mips_trap;
133 static int mips_warn_about_macros;
134 static int mips_noreorder;
135 static int mips_any_noreorder;
136 static int mips_nomove;
137 static int mips_noat;
138 static int mips_nobopt;
141 /* The size of the small data section. */
142 static int g_switch_value = 8;
143 /* Whether the -G option was used. */
144 static int g_switch_seen = 0;
150 /* handle of the OPCODE hash table */
151 static struct hash_control *op_hash = NULL;
153 /* This array holds the chars that always start a comment. If the
154 pre-processor is disabled, these aren't very useful */
155 const char comment_chars[] = "#";
157 /* This array holds the chars that only start a comment at the beginning of
158 a line. If the line seems to have the form '# 123 filename'
159 .line and .file directives will appear in the pre-processed output */
160 /* Note that input_file.c hand checks for '#' at the beginning of the
161 first line of the input file. This is because the compiler outputs
162 #NO_APP at the beginning of its output. */
163 /* Also note that C style comments are always supported. */
164 const char line_comment_chars[] = "#";
166 /* This array holds machine specific line separator characters. */
167 const char line_separator_chars[] = "";
169 /* Chars that can be used to separate mant from exp in floating point nums */
170 const char EXP_CHARS[] = "eE";
172 /* Chars that mean this number is a floating point constant */
175 const char FLT_CHARS[] = "rRsSfFdDxXpP";
177 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
178 changed in read.c . Ideally it shouldn't have to know about it at all,
179 but nothing is ideal around here.
182 static char *insn_error;
184 static int byte_order = BYTE_ORDER;
186 static int auto_align = 1;
188 /* Symbol labelling the current insn. */
189 static symbolS *insn_label;
191 /* When outputting SVR4 PIC code, the assembler needs to know the
192 offset in the stack frame from which to restore the $gp register.
193 This is set by the .cprestore pseudo-op, and saved in this
195 static offsetT mips_cprestore_offset = -1;
197 /* This is the register which holds the stack frame, as set by the
198 .frame pseudo-op. This is needed to implement .cprestore. */
199 static int mips_frame_reg = SP;
201 /* To output NOP instructions correctly, we need to keep information
202 about the previous two instructions. */
204 /* Whether we are optimizing. The default value of 2 means to remove
205 unneeded NOPs and swap branch instructions when possible. A value
206 of 1 means to not swap branches. A value of 0 means to always
208 static int mips_optimize = 2;
210 /* The previous instruction. */
211 static struct mips_cl_insn prev_insn;
213 /* The instruction before prev_insn. */
214 static struct mips_cl_insn prev_prev_insn;
216 /* If we don't want information for prev_insn or prev_prev_insn, we
217 point the insn_mo field at this dummy integer. */
218 static const struct mips_opcode dummy_opcode = { 0 };
220 /* Non-zero if prev_insn is valid. */
221 static int prev_insn_valid;
223 /* The frag for the previous instruction. */
224 static struct frag *prev_insn_frag;
226 /* The offset into prev_insn_frag for the previous instruction. */
227 static long prev_insn_where;
229 /* The reloc for the previous instruction, if any. */
230 static fixS *prev_insn_fixp;
232 /* Non-zero if the previous instruction was in a delay slot. */
233 static int prev_insn_is_delay_slot;
235 /* Non-zero if the previous instruction was in a .set noreorder. */
236 static int prev_insn_unreordered;
238 /* Non-zero if the previous previous instruction was in a .set
240 static int prev_prev_insn_unreordered;
242 /* Since the MIPS does not have multiple forms of PC relative
243 instructions, we do not have to do relaxing as is done on other
244 platforms. However, we do have to handle GP relative addressing
245 correctly, which turns out to be a similar problem.
247 Every macro that refers to a symbol can occur in (at least) two
248 forms, one with GP relative addressing and one without. For
249 example, loading a global variable into a register generally uses
250 a macro instruction like this:
252 If i can be addressed off the GP register (this is true if it is in
253 the .sbss or .sdata section, or if it is known to be smaller than
254 the -G argument) this will generate the following instruction:
256 This instruction will use a GPREL reloc. If i can not be addressed
257 off the GP register, the following instruction sequence will be used:
260 In this case the first instruction will have a HI16 reloc, and the
261 second reloc will have a LO16 reloc. Both relocs will be against
264 The issue here is that we may not know whether i is GP addressable
265 until after we see the instruction that uses it. Therefore, we
266 want to be able to choose the final instruction sequence only at
267 the end of the assembly. This is similar to the way other
268 platforms choose the size of a PC relative instruction only at the
271 When generating position independent code we do not use GP
272 addressing in quite the same way, but the issue still arises as
273 external symbols and local symbols must be handled differently.
275 We handle these issues by actually generating both possible
276 instruction sequences. The longer one is put in a frag_var with
277 type rs_machine_dependent. We encode what to do with the frag in
278 the subtype field. We encode (1) the number of existing bytes to
279 replace, (2) the number of new bytes to use, (3) the offset from
280 the start of the existing bytes to the first reloc we must generate
281 (that is, the offset is applied from the start of the existing
282 bytes after they are replaced by the new bytes, if any), (4) the
283 offset from the start of the existing bytes to the second reloc,
284 (5) whether a third reloc is needed (the third reloc is always four
285 bytes after the second reloc), and (6) whether to warn if this
286 variant is used (this is sometimes needed if .set nomacro or .set
287 noat is in effect). All these numbers are reasonably small.
289 Generating two instruction sequences must be handled carefully to
290 ensure that delay slots are handled correctly. Fortunately, there
291 are a limited number of cases. When the second instruction
292 sequence is generated, append_insn is directed to maintain the
293 existing delay slot information, so it continues to apply to any
294 code after the second instruction sequence. This means that the
295 second instruction sequence must not impose any requirements not
296 required by the first instruction sequence.
298 These variant frags are then handled in functions called by the
299 machine independent code. md_estimate_size_before_relax returns
300 the final size of the frag. md_convert_frag sets up the final form
301 of the frag. tc_gen_reloc adjust the first reloc and adds a second
303 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
307 | (((reloc1) + 64) << 9) \
308 | (((reloc2) + 64) << 2) \
309 | ((reloc3) ? (1 << 1) : 0) \
311 #define RELAX_OLD(i) (((i) >> 24) & 0xff)
312 #define RELAX_NEW(i) (((i) >> 16) & 0xff)
313 #define RELAX_RELOC1(i) ((((i) >> 9) & 0x7f) - 64)
314 #define RELAX_RELOC2(i) ((((i) >> 2) & 0x7f) - 64)
315 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
316 #define RELAX_WARN(i) ((i) & 1)
318 /* Prototypes for static functions. */
321 #define internalError() \
322 as_fatal ("internal Error, line %d, %s", __LINE__, __FILE__)
324 #define internalError() as_fatal ("MIPS internal Error");
327 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
328 unsigned int reg, int fpr));
329 static void append_insn PARAMS ((char *place,
330 struct mips_cl_insn * ip,
332 bfd_reloc_code_real_type r));
333 static void mips_no_prev_insn PARAMS ((void));
334 static void mips_emit_delays PARAMS ((void));
335 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
336 const char *name, const char *fmt,
338 static void macro_build_lui PARAMS ((char *place, int *counter,
339 expressionS * ep, int regnum));
340 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
341 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
343 static void load_register PARAMS ((int *counter, int reg, expressionS * ep));
344 static void load_address PARAMS ((int *counter, int reg, expressionS *ep));
345 static void macro PARAMS ((struct mips_cl_insn * ip));
346 #ifdef LOSING_COMPILER
347 static void macro2 PARAMS ((struct mips_cl_insn * ip));
349 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
350 static int my_getSmallExpression PARAMS ((expressionS * ep, char *str));
351 static void my_getExpression PARAMS ((expressionS * ep, char *str));
352 static symbolS *get_symbol PARAMS ((void));
353 static void mips_align PARAMS ((int to, int fill, symbolS *label));
354 static void s_align PARAMS ((int));
355 static void s_stringer PARAMS ((int));
356 static void s_change_sec PARAMS ((int));
357 static void s_cons PARAMS ((int));
358 static void s_err PARAMS ((int));
359 static void s_extern PARAMS ((int));
360 static void s_float_cons PARAMS ((int));
361 static void s_option PARAMS ((int));
362 static void s_mipsset PARAMS ((int));
363 static void s_mips_space PARAMS ((int));
364 static void s_abicalls PARAMS ((int));
365 static void s_cpload PARAMS ((int));
366 static void s_cprestore PARAMS ((int));
367 static void s_gpword PARAMS ((int));
368 static void s_cpadd PARAMS ((int));
369 #ifndef ECOFF_DEBUGGING
370 static void md_obj_begin PARAMS ((void));
371 static void md_obj_end PARAMS ((void));
372 static long get_number PARAMS ((void));
373 static void s_ent PARAMS ((int));
374 static void s_mipsend PARAMS ((int));
375 static void s_file PARAMS ((int));
377 static void s_frame PARAMS ((int));
378 static void s_loc PARAMS ((int));
379 static void s_mask PARAMS ((char));
385 The following pseudo-ops from the Kane and Heinrich MIPS book
386 should be defined here, but are currently unsupported: .alias,
387 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
389 The following pseudo-ops from the Kane and Heinrich MIPS book are
390 specific to the type of debugging information being generated, and
391 should be defined by the object format: .aent, .begin, .bend,
392 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
395 The following pseudo-ops from the Kane and Heinrich MIPS book are
396 not MIPS CPU specific, but are also not specific to the object file
397 format. This file is probably the best place to define them, but
398 they are not currently supported: .asm0, .endr, .lab, .repeat,
399 .struct, .weakext. */
401 const pseudo_typeS md_pseudo_table[] =
403 /* MIPS specific pseudo-ops. */
404 {"option", s_option, 0},
405 {"set", s_mipsset, 0},
406 {"rdata", s_change_sec, 'r'},
407 {"sdata", s_change_sec, 's'},
408 {"livereg", s_ignore, 0},
409 { "abicalls", s_abicalls, 0},
410 { "cpload", s_cpload, 0},
411 { "cprestore", s_cprestore, 0},
412 { "gpword", s_gpword, 0},
413 { "cpadd", s_cpadd, 0},
415 /* Relatively generic pseudo-ops that happen to be used on MIPS
417 {"asciiz", s_stringer, 1},
418 {"bss", s_change_sec, 'b'},
421 {"dword", s_cons, 3},
423 /* These pseudo-ops are defined in read.c, but must be overridden
424 here for one reason or another. */
425 {"align", s_align, 0},
426 {"ascii", s_stringer, 0},
427 {"asciz", s_stringer, 1},
429 {"data", s_change_sec, 'd'},
430 {"double", s_float_cons, 'd'},
431 {"extern", s_extern, 0},
432 {"float", s_float_cons, 'f'},
433 {"hword", s_cons, 1},
438 {"short", s_cons, 1},
439 {"single", s_float_cons, 'f'},
440 {"space", s_mips_space, 0},
441 {"text", s_change_sec, 't'},
444 #ifndef ECOFF_DEBUGGING
445 /* These pseudo-ops should be defined by the object file format.
446 However, a.out doesn't support them, so we have versions here. */
448 {"bgnb", s_ignore, 0},
449 {"end", s_mipsend, 0},
450 {"endb", s_ignore, 0},
453 {"fmask", s_ignore, 'F'},
454 {"frame", s_ignore, 0},
455 {"loc", s_ignore, 0},
456 {"mask", s_ignore, 'R'},
457 {"verstamp", s_ignore, 0},
464 const relax_typeS md_relax_table[] =
469 static char *expr_end;
471 static expressionS imm_expr;
472 static expressionS offset_expr;
473 static bfd_reloc_code_real_type imm_reloc;
474 static bfd_reloc_code_real_type offset_reloc;
476 /* FIXME: This should be handled in a different way. */
477 extern int target_big_endian;
480 * This function is called once, at assembler startup time. It should
481 * set up all the tables, etc. that the MD part of the assembler will need.
487 register const char *retval = NULL;
488 register unsigned int i = 0;
492 if (strcmp (TARGET_CPU, "mips") == 0)
494 else if (strcmp (TARGET_CPU, "r6000") == 0
495 || strcmp (TARGET_CPU, "mips2") == 0)
497 else if (strcmp (TARGET_CPU, "mips64") == 0
498 || strcmp (TARGET_CPU, "r4000") == 0
499 || strcmp (TARGET_CPU, "mips3") == 0)
505 if (mips_isa < 2 && mips_trap)
506 as_bad ("trap exception not supported at ISA 1");
511 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 3000);
514 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 6000);
517 ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 4000);
521 as_warn ("Could not set architecture and machine");
523 file_mips_isa = mips_isa;
525 op_hash = hash_new ();
527 for (i = 0; i < NUMOPCODES;)
529 const char *name = mips_opcodes[i].name;
531 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
534 fprintf (stderr, "internal error: can't hash `%s': %s\n",
535 mips_opcodes[i].name, retval);
536 as_fatal ("Broken assembler. No assembly attempted.");
540 if (mips_opcodes[i].pinfo != INSN_MACRO
541 && ((mips_opcodes[i].match & mips_opcodes[i].mask)
542 != mips_opcodes[i].match))
544 fprintf (stderr, "internal error: bad opcode: `%s' \"%s\"\n",
545 mips_opcodes[i].name, mips_opcodes[i].args);
546 as_fatal ("Broken assembler. No assembly attempted.");
550 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
553 mips_no_prev_insn ();
561 /* set the default alignment for the text section (2**2) */
562 record_alignment (text_section, 2);
564 /* FIXME: This should be handled in a different way. */
565 target_big_endian = byte_order == BIG_ENDIAN;
568 bfd_set_gp_size (stdoutput, g_switch_value);
572 /* Sections must be aligned to 16 byte boundaries. */
573 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
574 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
575 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
577 /* Create a .reginfo section for register masks and a .mdebug
578 section for debugging information. */
586 sec = subseg_new (".reginfo", (subsegT) 0);
588 /* The ABI says this section should be loaded so that the running
589 program can access it. */
590 (void) bfd_set_section_flags (stdoutput, sec,
591 (SEC_ALLOC | SEC_LOAD
592 | SEC_READONLY | SEC_DATA));
593 (void) bfd_set_section_alignment (stdoutput, sec, 2);
595 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
597 #ifdef ECOFF_DEBUGGING
598 sec = subseg_new (".mdebug", (subsegT) 0);
599 (void) bfd_set_section_flags (stdoutput, sec,
600 SEC_HAS_CONTENTS | SEC_READONLY);
601 (void) bfd_set_section_alignment (stdoutput, sec, 2);
604 subseg_set (seg, subseg);
608 #ifndef ECOFF_DEBUGGING
616 #ifndef ECOFF_DEBUGGING
625 struct mips_cl_insn insn;
627 imm_expr.X_op = O_absent;
628 offset_expr.X_op = O_absent;
630 mips_ip (str, &insn);
633 as_bad ("%s `%s'", insn_error, str);
636 if (insn.insn_mo->pinfo == INSN_MACRO)
642 if (imm_expr.X_op != O_absent)
643 append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc);
644 else if (offset_expr.X_op != O_absent)
645 append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc);
647 append_insn ((char *) NULL, &insn, NULL, BFD_RELOC_UNUSED);
651 /* See whether instruction IP reads register REG. If FPR is non-zero,
652 REG is a floating point register. */
655 insn_uses_reg (ip, reg, fpr)
656 struct mips_cl_insn *ip;
660 /* Don't report on general register 0, since it never changes. */
661 if (! fpr && reg == 0)
666 /* If we are called with either $f0 or $f1, we must check $f0.
667 This is not optimal, because it will introduce an unnecessary
668 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
669 need to distinguish reading both $f0 and $f1 or just one of
670 them. Note that we don't have to check the other way,
671 because there is no instruction that sets both $f0 and $f1
672 and requires a delay. */
673 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
674 && (((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS)
675 == (reg &~ (unsigned) 1)))
677 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
678 && (((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT)
679 == (reg &~ (unsigned) 1)))
684 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
685 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
687 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
688 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
695 /* Output an instruction. PLACE is where to put the instruction; if
696 it is NULL, this uses frag_more to get room. IP is the instruction
697 information. ADDRESS_EXPR is an operand of the instruction to be
698 used with RELOC_TYPE. */
701 append_insn (place, ip, address_expr, reloc_type)
703 struct mips_cl_insn *ip;
704 expressionS *address_expr;
705 bfd_reloc_code_real_type reloc_type;
707 register unsigned long prev_pinfo, pinfo;
712 prev_pinfo = prev_insn.insn_mo->pinfo;
713 pinfo = ip->insn_mo->pinfo;
715 if (place == NULL && ! mips_noreorder)
717 /* If the previous insn required any delay slots, see if we need
718 to insert a NOP or two. There are eight kinds of possible
719 hazards, of which an instruction can have at most one type.
720 (1) a load from memory delay
721 (2) a load from a coprocessor delay
722 (3) an unconditional branch delay
723 (4) a conditional branch delay
724 (5) a move to coprocessor register delay
725 (6) a load coprocessor register from memory delay
726 (7) a coprocessor condition code delay
727 (8) a HI/LO special register delay
729 There are a lot of optimizations we could do that we don't.
730 In particular, we do not, in general, reorder instructions.
731 If you use gcc with optimization, it will reorder
732 instructions and generally do much more optimization then we
733 do here; repeating all that work in the assembler would only
734 benefit hand written assembly code, and does not seem worth
737 /* This is how a NOP is emitted. */
738 #define emit_nop() md_number_to_chars (frag_more (4), 0, 4)
740 /* The previous insn might require a delay slot, depending upon
741 the contents of the current insn. */
742 if ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
744 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))
746 /* A load from a coprocessor or from memory. All load
747 delays delay the use of general register rt for one
748 instruction on the r3000. The r6000 and r4000 use
750 know (prev_pinfo & INSN_WRITE_GPR_T);
751 if (mips_optimize == 0
752 || insn_uses_reg (ip,
753 ((prev_insn.insn_opcode >> OP_SH_RT)
758 else if ((prev_pinfo & INSN_COPROC_MOVE_DELAY)
760 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)))
762 /* A generic coprocessor delay. The previous instruction
763 modified a coprocessor general or control register. If
764 it modified a control register, we need to avoid any
765 coprocessor instruction (this is probably not always
766 required, but it sometimes is). If it modified a general
767 register, we avoid using that register.
769 On the r6000 and r4000 loading a coprocessor register
770 from memory is interlocked, and does not require a delay.
772 This case is not handled very well. There is no special
773 knowledge of CP0 handling, and the coprocessors other
774 than the floating point unit are not distinguished at
776 if (prev_pinfo & INSN_WRITE_FPR_T)
778 if (mips_optimize == 0
779 || insn_uses_reg (ip,
780 ((prev_insn.insn_opcode >> OP_SH_FT)
785 else if (prev_pinfo & INSN_WRITE_FPR_S)
787 if (mips_optimize == 0
788 || insn_uses_reg (ip,
789 ((prev_insn.insn_opcode >> OP_SH_FS)
796 /* We don't know exactly what the previous instruction
797 does. If the current instruction uses a coprocessor
798 register, we must insert a NOP. If previous
799 instruction may set the condition codes, and the
800 current instruction uses them, we must insert two
802 if (mips_optimize == 0
803 || ((prev_pinfo & INSN_WRITE_COND_CODE)
804 && (pinfo & INSN_READ_COND_CODE)))
806 else if (pinfo & INSN_COP)
810 else if (prev_pinfo & INSN_WRITE_COND_CODE)
812 /* The previous instruction sets the coprocessor condition
813 codes, but does not require a general coprocessor delay
814 (this means it is a floating point comparison
815 instruction). If this instruction uses the condition
816 codes, we need to insert a single NOP. */
817 if (mips_optimize == 0
818 || (pinfo & INSN_READ_COND_CODE))
821 else if (prev_pinfo & INSN_READ_LO)
823 /* The previous instruction reads the LO register; if the
824 current instruction writes to the LO register, we must
826 if (mips_optimize == 0
827 || (pinfo & INSN_WRITE_LO))
830 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
832 /* The previous instruction reads the HI register; if the
833 current instruction writes to the HI register, we must
835 if (mips_optimize == 0
836 || (pinfo & INSN_WRITE_HI))
840 /* There are two cases which require two intervening
841 instructions: 1) setting the condition codes using a move to
842 coprocessor instruction which requires a general coprocessor
843 delay and then reading the condition codes 2) reading the HI
844 or LO register and then writing to it. If we are not already
845 emitting a NOP instruction, we must check for these cases
846 compared to the instruction previous to the previous
849 && (((prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
850 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
851 && (pinfo & INSN_READ_COND_CODE))
852 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
853 && (pinfo & INSN_WRITE_LO))
854 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
855 && (pinfo & INSN_WRITE_HI))))
858 /* If we are being given a nop instruction, don't bother with
859 one of the nops we would otherwise output. This will only
860 happen when a nop instruction is used with mips_optimize set
862 if (nops > 0 && ip->insn_opcode == 0)
865 /* Now emit the right number of NOP instructions. */
872 listing_prev_line ();
873 if (insn_label != NULL)
875 assert (S_GET_SEGMENT (insn_label) == now_seg);
876 insn_label->sy_frag = frag_now;
877 S_SET_VALUE (insn_label, (valueT) frag_now_fix ());
887 if (address_expr != NULL)
889 if (address_expr->X_op == O_constant)
894 ip->insn_opcode |= address_expr->X_add_number;
898 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
901 case BFD_RELOC_MIPS_JMP:
902 case BFD_RELOC_16_PCREL_S2:
911 assert (reloc_type != BFD_RELOC_UNUSED);
913 /* Don't generate a reloc if we are writing into a variant
916 fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
918 reloc_type == BFD_RELOC_16_PCREL_S2,
923 md_number_to_chars (f, ip->insn_opcode, 4);
925 /* Update the register mask information. */
926 if (pinfo & INSN_WRITE_GPR_D)
927 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
928 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
929 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
930 if (pinfo & INSN_READ_GPR_S)
931 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
932 if (pinfo & INSN_WRITE_GPR_31)
933 mips_gprmask |= 1 << 31;
934 if (pinfo & INSN_WRITE_FPR_D)
935 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
936 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
937 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
938 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
939 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
940 if (pinfo & INSN_COP)
942 /* We don't keep enough information to sort these cases out. */
944 /* Never set the bit for $0, which is always zero. */
945 mips_gprmask &=~ 1 << 0;
947 if (place == NULL && ! mips_noreorder)
949 /* Filling the branch delay slot is more complex. We try to
950 switch the branch with the previous instruction, which we can
951 do if the previous instruction does not set up a condition
952 that the branch tests and if the branch is not itself the
953 target of any branch. */
954 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
955 || (pinfo & INSN_COND_BRANCH_DELAY))
957 if (mips_optimize < 2
958 /* If we have seen .set nobopt, don't optimize. */
960 /* If we have seen .set volatile or .set nomove, don't
963 /* If we had to emit any NOP instructions, then we
964 already know we can not swap. */
966 /* If we don't even know the previous insn, we can not
969 /* If the previous insn is already in a branch delay
970 slot, then we can not swap. */
971 || prev_insn_is_delay_slot
972 /* If the previous previous insn was in a .set
973 noreorder, we can't swap. Actually, the MIPS
974 assembler will swap in this situation. However, gcc
975 configured -with-gnu-as will generate code like
981 in which we can not swap the bne and INSN. If gcc is
982 not configured -with-gnu-as, it does not output the
983 .set pseudo-ops. We don't have to check
984 prev_insn_unreordered, because prev_insn_valid will
985 be 0 in that case. We don't want to use
986 prev_prev_insn_valid, because we do want to be able
987 to swap at the start of a function. */
988 || prev_prev_insn_unreordered
989 /* If the branch is itself the target of a branch, we
990 can not swap. We cheat on this; all we check for is
991 whether there is a label on this instruction. If
992 there are any branches to anything other than a
993 label, users must use .set noreorder. */
994 || insn_label != NULL
995 /* If the previous instruction is in a variant frag, we
996 can not do the swap. */
997 || prev_insn_frag->fr_type == rs_machine_dependent
998 /* If the branch reads the condition codes, we don't
999 even try to swap, because in the sequence
1004 we can not swap, and I don't feel like handling that
1006 || (pinfo & INSN_READ_COND_CODE)
1007 /* We can not swap with an instruction that requires a
1008 delay slot, becase the target of the branch might
1009 interfere with that instruction. */
1011 & (INSN_LOAD_COPROC_DELAY
1012 | INSN_COPROC_MOVE_DELAY
1013 | INSN_WRITE_COND_CODE
1018 & (INSN_LOAD_MEMORY_DELAY
1019 | INSN_COPROC_MEMORY_DELAY)))
1020 /* We can not swap with a branch instruction. */
1022 & (INSN_UNCOND_BRANCH_DELAY
1023 | INSN_COND_BRANCH_DELAY
1024 | INSN_COND_BRANCH_LIKELY))
1025 /* We do not swap with a trap instruction, since it
1026 complicates trap handlers to have the trap
1027 instruction be in a delay slot. */
1028 || (prev_pinfo & INSN_TRAP)
1029 /* If the branch reads a register that the previous
1030 instruction sets, we can not swap. */
1031 || ((prev_pinfo & INSN_WRITE_GPR_T)
1032 && insn_uses_reg (ip,
1033 ((prev_insn.insn_opcode >> OP_SH_RT)
1036 || ((prev_pinfo & INSN_WRITE_GPR_D)
1037 && insn_uses_reg (ip,
1038 ((prev_insn.insn_opcode >> OP_SH_RD)
1041 /* If the branch writes a register that the previous
1042 instruction sets, we can not swap (we know that
1043 branches write only to RD or to $31). */
1044 || ((prev_pinfo & INSN_WRITE_GPR_T)
1045 && (((pinfo & INSN_WRITE_GPR_D)
1046 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
1047 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
1048 || ((pinfo & INSN_WRITE_GPR_31)
1049 && (((prev_insn.insn_opcode >> OP_SH_RT)
1052 || ((prev_pinfo & INSN_WRITE_GPR_D)
1053 && (((pinfo & INSN_WRITE_GPR_D)
1054 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
1055 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
1056 || ((pinfo & INSN_WRITE_GPR_31)
1057 && (((prev_insn.insn_opcode >> OP_SH_RD)
1060 /* If the branch writes a register that the previous
1061 instruction reads, we can not swap (we know that
1062 branches only write to RD or to $31). */
1063 || ((pinfo & INSN_WRITE_GPR_D)
1064 && insn_uses_reg (&prev_insn,
1065 ((ip->insn_opcode >> OP_SH_RD)
1068 || ((pinfo & INSN_WRITE_GPR_31)
1069 && insn_uses_reg (&prev_insn, 31, 0))
1070 /* If we are generating embedded PIC code, the branch
1071 might be expanded into a sequence which uses $at, so
1072 we can't swap with an instruction which reads it. */
1073 || (mips_pic == EMBEDDED_PIC
1074 && insn_uses_reg (&prev_insn, AT, 0))
1075 /* If the previous previous instruction has a load
1076 delay, and sets a register that the branch reads, we
1078 || (((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
1080 && (prev_prev_insn.insn_mo->pinfo
1081 & INSN_LOAD_MEMORY_DELAY)))
1082 && insn_uses_reg (ip,
1083 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
1087 /* We could do even better for unconditional branches to
1088 portions of this object file; we could pick up the
1089 instruction at the destination, put it in the delay
1090 slot, and bump the destination address. */
1092 /* Update the previous insn information. */
1093 prev_prev_insn = *ip;
1094 prev_insn.insn_mo = &dummy_opcode;
1101 /* It looks like we can actually do the swap. */
1102 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
1103 memcpy (temp, prev_f, 4);
1104 memcpy (prev_f, f, 4);
1105 memcpy (f, temp, 4);
1108 prev_insn_fixp->fx_frag = frag_now;
1109 prev_insn_fixp->fx_where = f - frag_now->fr_literal;
1113 fixp->fx_frag = prev_insn_frag;
1114 fixp->fx_where = prev_insn_where;
1116 /* Update the previous insn information; leave prev_insn
1118 prev_prev_insn = *ip;
1120 prev_insn_is_delay_slot = 1;
1122 /* If that was an unconditional branch, forget the previous
1123 insn information. */
1124 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
1126 prev_prev_insn.insn_mo = &dummy_opcode;
1127 prev_insn.insn_mo = &dummy_opcode;
1130 else if (pinfo & INSN_COND_BRANCH_LIKELY)
1132 /* We don't yet optimize a branch likely. What we should do
1133 is look at the target, copy the instruction found there
1134 into the delay slot, and increment the branch to jump to
1135 the next instruction. */
1137 /* Update the previous insn information. */
1138 prev_prev_insn = *ip;
1139 prev_insn.insn_mo = &dummy_opcode;
1143 /* Update the previous insn information. */
1145 prev_prev_insn.insn_mo = &dummy_opcode;
1147 prev_prev_insn = prev_insn;
1150 /* Any time we see a branch, we always fill the delay slot
1151 immediately; since this insn is not a branch, we know it
1152 is not in a delay slot. */
1153 prev_insn_is_delay_slot = 0;
1156 prev_prev_insn_unreordered = prev_insn_unreordered;
1157 prev_insn_unreordered = 0;
1158 prev_insn_frag = frag_now;
1159 prev_insn_where = f - frag_now->fr_literal;
1160 prev_insn_fixp = fixp;
1161 prev_insn_valid = 1;
1164 /* We just output an insn, so the next one doesn't have a label. */
1168 /* This function forgets that there was any previous instruction or
1172 mips_no_prev_insn ()
1174 prev_insn.insn_mo = &dummy_opcode;
1175 prev_prev_insn.insn_mo = &dummy_opcode;
1176 prev_insn_valid = 0;
1177 prev_insn_is_delay_slot = 0;
1178 prev_insn_unreordered = 0;
1179 prev_prev_insn_unreordered = 0;
1183 /* This function must be called whenever we turn on noreorder or emit
1184 something other than instructions. It inserts any NOPS which might
1185 be needed by the previous instruction, and clears the information
1186 kept for the previous instructions. */
1191 if (! mips_noreorder)
1196 if ((prev_insn.insn_mo->pinfo
1197 & (INSN_LOAD_COPROC_DELAY
1198 | INSN_COPROC_MOVE_DELAY
1199 | INSN_WRITE_COND_CODE
1203 && (prev_insn.insn_mo->pinfo
1204 & (INSN_LOAD_MEMORY_DELAY
1205 | INSN_COPROC_MEMORY_DELAY))))
1208 if ((prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1209 || (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1210 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))
1213 else if ((prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1214 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1215 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))
1220 if (insn_label != NULL)
1222 assert (S_GET_SEGMENT (insn_label) == now_seg);
1223 insn_label->sy_frag = frag_now;
1224 S_SET_VALUE (insn_label, (valueT) frag_now_fix ());
1227 mips_no_prev_insn ();
1231 /* Build an instruction created by a macro expansion. This is passed
1232 a pointer to the count of instructions created so far, an
1233 expression, the name of the instruction to build, an operand format
1234 string, and corresponding arguments. */
1238 macro_build (char *place,
1244 #else /* ! defined (NO_STDARG) */
1246 macro_build (place, counter, ep, name, fmt, va_alist)
1253 #endif /* ! defined (NO_STDARG) */
1255 struct mips_cl_insn insn;
1256 bfd_reloc_code_real_type r;
1260 va_start (args, fmt);
1266 * If the macro is about to expand into a second instruction,
1267 * print a warning if needed. We need to pass ip as a parameter
1268 * to generate a better warning message here...
1270 if (mips_warn_about_macros && place == NULL && *counter == 1)
1271 as_warn ("Macro instruction expanded into multiple instructions");
1274 *counter += 1; /* bump instruction counter */
1276 r = BFD_RELOC_UNUSED;
1277 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
1278 assert (insn.insn_mo);
1279 assert (strcmp (name, insn.insn_mo->name) == 0);
1281 while (strcmp (fmt, insn.insn_mo->args) != 0
1282 || insn.insn_mo->pinfo == INSN_MACRO)
1285 assert (insn.insn_mo->name);
1286 assert (strcmp (name, insn.insn_mo->name) == 0);
1288 insn.insn_opcode = insn.insn_mo->match;
1304 insn.insn_opcode |= va_arg (args, int) << 16;
1310 insn.insn_opcode |= va_arg (args, int) << 16;
1315 insn.insn_opcode |= va_arg (args, int) << 11;
1320 insn.insn_opcode |= va_arg (args, int) << 11;
1327 insn.insn_opcode |= va_arg (args, int) << 6;
1331 insn.insn_opcode |= va_arg (args, int) << 6;
1335 insn.insn_opcode |= va_arg (args, int) << 6;
1342 insn.insn_opcode |= va_arg (args, int) << 21;
1348 r = (bfd_reloc_code_real_type) va_arg (args, int);
1349 assert (r == BFD_RELOC_MIPS_GPREL
1350 || r == BFD_RELOC_MIPS_LITERAL
1351 || r == BFD_RELOC_LO16
1352 || r == BFD_RELOC_MIPS_GOT16
1353 || r == BFD_RELOC_MIPS_CALL16
1354 || (ep->X_op == O_subtract
1355 && now_seg == text_section
1356 && S_GET_SEGMENT (ep->X_op_symbol) == text_section
1357 && r == BFD_RELOC_PCREL_LO16));
1361 r = (bfd_reloc_code_real_type) va_arg (args, int);
1363 && (ep->X_op == O_constant
1364 || (ep->X_op == O_symbol
1365 && (r == BFD_RELOC_HI16_S
1366 || r == BFD_RELOC_HI16))
1367 || (ep->X_op == O_subtract
1368 && now_seg == text_section
1369 && S_GET_SEGMENT (ep->X_op_symbol) == text_section
1370 && r == BFD_RELOC_PCREL_HI16_S)));
1371 if (ep->X_op == O_constant)
1373 insn.insn_opcode |= (ep->X_add_number >> 16) & 0xffff;
1375 r = BFD_RELOC_UNUSED;
1380 assert (ep != NULL);
1382 * This allows macro() to pass an immediate expression for
1383 * creating short branches without creating a symbol.
1384 * Note that the expression still might come from the assembly
1385 * input, in which case the value is not checked for range nor
1386 * is a relocation entry generated (yuck).
1388 if (ep->X_op == O_constant)
1390 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
1394 r = BFD_RELOC_16_PCREL_S2;
1398 assert (ep != NULL);
1399 r = BFD_RELOC_MIPS_JMP;
1408 assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
1410 append_insn (place, &insn, ep, r);
1414 * Generate a "lui" instruction.
1417 macro_build_lui (place, counter, ep, regnum)
1423 expressionS high_expr;
1424 struct mips_cl_insn insn;
1425 bfd_reloc_code_real_type r;
1426 CONST char *name = "lui";
1427 CONST char *fmt = "t,u";
1433 high_expr.X_op = O_constant;
1434 high_expr.X_add_number = 0;
1437 if (high_expr.X_op == O_constant)
1439 /* we can compute the instruction now without a relocation entry */
1440 if (high_expr.X_add_number & 0x8000)
1441 high_expr.X_add_number += 0x10000;
1442 high_expr.X_add_number =
1443 ((unsigned long) high_expr.X_add_number >> 16) & 0xffff;
1444 r = BFD_RELOC_UNUSED;
1448 assert (ep->X_op == O_symbol);
1449 /* _gp_disp is a special case, used from s_cpload. */
1450 assert (mips_pic == NO_PIC
1451 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
1452 r = BFD_RELOC_HI16_S;
1456 * If the macro is about to expand into a second instruction,
1457 * print a warning if needed. We need to pass ip as a parameter
1458 * to generate a better warning message here...
1460 if (mips_warn_about_macros && place == NULL && *counter == 1)
1461 as_warn ("Macro instruction expanded into multiple instructions");
1464 *counter += 1; /* bump instruction counter */
1466 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
1467 assert (insn.insn_mo);
1468 assert (strcmp (name, insn.insn_mo->name) == 0);
1469 assert (strcmp (fmt, insn.insn_mo->args) == 0);
1471 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
1472 if (r == BFD_RELOC_UNUSED)
1474 insn.insn_opcode |= high_expr.X_add_number;
1475 append_insn (place, &insn, NULL, r);
1478 append_insn (place, &insn, &high_expr, r);
1482 * Generates code to set the $at register to true (one)
1483 * if reg is less than the immediate expression.
1486 set_at (counter, reg, unsignedp)
1491 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
1492 macro_build ((char *) NULL, counter, &imm_expr,
1493 unsignedp ? "sltiu" : "slti",
1494 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
1497 load_register (counter, AT, &imm_expr);
1498 macro_build ((char *) NULL, counter, NULL,
1499 unsignedp ? "sltu" : "slt",
1500 "d,v,t", AT, reg, AT);
1504 /* Warn if an expression is not a constant. */
1507 check_absolute_expr (ip, ex)
1508 struct mips_cl_insn *ip;
1511 if (ex->X_op != O_constant)
1512 as_warn ("Instruction %s requires absolute expression", ip->insn_mo->name);
1516 * This routine generates the least number of instructions neccessary to load
1517 * an absolute expression value into a register.
1520 load_register (counter, reg, ep)
1525 assert (ep->X_op == O_constant);
1526 if (ep->X_add_number >= -0x8000 && ep->X_add_number < 0x8000)
1527 macro_build ((char *) NULL, counter, ep,
1528 mips_isa < 3 ? "addiu" : "daddiu",
1529 "t,r,j", reg, 0, (int) BFD_RELOC_LO16);
1530 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
1531 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
1532 (int) BFD_RELOC_LO16);
1533 else if ((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0
1534 || ((ep->X_add_number &~ (offsetT) 0x7fffffff)
1535 == ~ (offsetT) 0x7fffffff))
1537 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
1538 (int) BFD_RELOC_HI16);
1539 if ((ep->X_add_number & 0xffff) != 0)
1540 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
1541 (int) BFD_RELOC_LO16);
1543 else if (mips_isa < 3)
1545 as_bad ("Number larger than 32 bits");
1546 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
1547 (int) BFD_RELOC_LO16);
1552 expressionS hi32, lo32;
1556 hi32.X_add_number >>= shift;
1557 hi32.X_add_number &= 0xffffffff;
1558 if ((hi32.X_add_number & 0x80000000) != 0)
1559 hi32.X_add_number |= ~ (offsetT) 0xffffffff;
1560 load_register (counter, reg, &hi32);
1562 lo32.X_add_number &= 0xffffffff;
1563 if ((lo32.X_add_number & 0xffff0000) == 0)
1564 macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg,
1570 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
1573 mid16.X_add_number >>= 16;
1574 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
1575 reg, (int) BFD_RELOC_LO16);
1576 macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg,
1579 if ((lo32.X_add_number & 0xffff) != 0)
1580 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, reg,
1581 (int) BFD_RELOC_LO16);
1585 /* Load an address into a register. */
1588 load_address (counter, reg, ep)
1595 if (ep->X_op != O_constant
1596 && ep->X_op != O_symbol)
1598 as_bad ("expression too complex");
1599 ep->X_op = O_constant;
1602 if (ep->X_op == O_constant)
1604 load_register (counter, reg, ep);
1608 if (mips_pic == NO_PIC)
1610 /* If this is a reference to a GP relative symbol, we want
1611 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
1613 lui $reg,<sym> (BFD_RELOC_HI16_S)
1614 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
1615 If we have an addend, we always use the latter form. */
1616 if (ep->X_add_number != 0)
1621 macro_build ((char *) NULL, counter, ep,
1622 mips_isa < 3 ? "addiu" : "daddiu",
1623 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
1624 p = frag_var (rs_machine_dependent, 8, 0,
1625 RELAX_ENCODE (4, 8, -4, 0, 0, mips_warn_about_macros),
1626 ep->X_add_symbol, (long) 0, (char *) NULL);
1628 macro_build_lui (p, counter, ep, reg);
1631 macro_build (p, counter, ep,
1632 mips_isa < 3 ? "addiu" : "daddiu",
1633 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
1635 else if (mips_pic == SVR4_PIC)
1639 /* If this is a reference to an external symbol, we want
1640 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
1642 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
1644 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
1645 If there is a constant, it must be added in after. */
1646 ex.X_add_number = ep->X_add_number;
1647 ep->X_add_number = 0;
1649 macro_build ((char *) NULL, counter, ep,
1650 mips_isa < 3 ? "lw" : "ld",
1651 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
1652 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
1653 p = frag_var (rs_machine_dependent, 4, 0,
1654 RELAX_ENCODE (0, 4, -8, 0, 0, mips_warn_about_macros),
1655 ep->X_add_symbol, (long) 0, (char *) NULL);
1656 macro_build (p, counter, ep,
1657 mips_isa < 3 ? "addiu" : "daddiu",
1658 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
1659 if (ex.X_add_number != 0)
1661 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
1662 as_bad ("PIC code offset overflow (max 16 signed bits)");
1663 ex.X_op = O_constant;
1664 macro_build (p, counter, &ex,
1665 mips_isa < 3 ? "addiu" : "daddiu",
1666 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
1669 else if (mips_pic == EMBEDDED_PIC)
1672 addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
1674 macro_build ((char *) NULL, counter, ep,
1675 mips_isa < 3 ? "addiu" : "daddiu",
1676 "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL);
1684 * This routine implements the seemingly endless macro or synthesized
1685 * instructions and addressing modes in the mips assembly language. Many
1686 * of these macros are simple and are similar to each other. These could
1687 * probably be handled by some kind of table or grammer aproach instead of
1688 * this verbose method. Others are not simple macros but are more like
1689 * optimizing code generation.
1690 * One interesting optimization is when several store macros appear
1691 * consecutivly that would load AT with the upper half of the same address.
1692 * The ensuing load upper instructions are ommited. This implies some kind
1693 * of global optimization. We currently only optimize within a single macro.
1694 * For many of the load and store macros if the address is specified as a
1695 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
1696 * first load register 'at' with zero and use it as the base register. The
1697 * mips assembler simply uses register $zero. Just one tiny optimization
1702 struct mips_cl_insn *ip;
1704 register int treg, sreg, dreg, breg;
1717 bfd_reloc_code_real_type r;
1720 treg = (ip->insn_opcode >> 16) & 0x1f;
1721 dreg = (ip->insn_opcode >> 11) & 0x1f;
1722 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
1723 mask = ip->insn_mo->mask;
1725 expr1.X_op = O_constant;
1726 expr1.X_op_symbol = NULL;
1727 expr1.X_add_symbol = NULL;
1728 expr1.X_add_number = 1;
1740 mips_emit_delays ();
1742 mips_any_noreorder = 1;
1744 expr1.X_add_number = 8;
1745 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
1747 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
1749 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, sreg, 0);
1750 macro_build ((char *) NULL, &icnt, NULL,
1751 dbl ? "dsub" : "sub",
1752 "d,v,t", dreg, 0, sreg);
1775 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
1777 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
1778 (int) BFD_RELOC_LO16);
1781 load_register (&icnt, AT, &imm_expr);
1782 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
1801 if (imm_expr.X_add_number >= 0 && imm_expr.X_add_number < 0x10000)
1803 if (mask != M_NOR_I)
1804 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
1805 sreg, (int) BFD_RELOC_LO16);
1808 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
1809 treg, sreg, (int) BFD_RELOC_LO16);
1810 macro_build ((char *) NULL, &icnt, NULL, "nor", "d,v,t",
1816 load_register (&icnt, AT, &imm_expr);
1817 macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT);
1834 if (imm_expr.X_add_number == 0)
1836 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
1840 load_register (&icnt, AT, &imm_expr);
1841 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
1849 macro_build ((char *) NULL, &icnt, &offset_expr,
1850 likely ? "bgezl" : "bgez",
1856 macro_build ((char *) NULL, &icnt, &offset_expr,
1857 likely ? "blezl" : "blez",
1861 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
1862 macro_build ((char *) NULL, &icnt, &offset_expr,
1863 likely ? "beql" : "beq",
1870 /* check for > max integer */
1871 maxnum = 0x7fffffff;
1879 if (imm_expr.X_add_number >= maxnum)
1882 /* result is always false */
1885 as_warn ("Branch %s is always false (nop)", ip->insn_mo->name);
1886 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
1890 as_warn ("Branch likely %s is always false", ip->insn_mo->name);
1891 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
1896 imm_expr.X_add_number++;
1900 if (mask == M_BGEL_I)
1902 if (imm_expr.X_add_number == 0)
1904 macro_build ((char *) NULL, &icnt, &offset_expr,
1905 likely ? "bgezl" : "bgez",
1909 if (imm_expr.X_add_number == 1)
1911 macro_build ((char *) NULL, &icnt, &offset_expr,
1912 likely ? "bgtzl" : "bgtz",
1916 maxnum = 0x7fffffff;
1924 maxnum = - maxnum - 1;
1925 if (imm_expr.X_add_number <= maxnum)
1928 /* result is always true */
1929 as_warn ("Branch %s is always true", ip->insn_mo->name);
1930 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
1933 set_at (&icnt, sreg, 0);
1934 macro_build ((char *) NULL, &icnt, &offset_expr,
1935 likely ? "beql" : "beq",
1946 macro_build ((char *) NULL, &icnt, &offset_expr,
1947 likely ? "beql" : "beq",
1951 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
1953 macro_build ((char *) NULL, &icnt, &offset_expr,
1954 likely ? "beql" : "beq",
1961 if (sreg == 0 || imm_expr.X_add_number == -1)
1963 imm_expr.X_add_number++;
1967 if (mask == M_BGEUL_I)
1969 if (imm_expr.X_add_number == 0)
1971 if (imm_expr.X_add_number == 1)
1973 macro_build ((char *) NULL, &icnt, &offset_expr,
1974 likely ? "bnel" : "bne",
1978 set_at (&icnt, sreg, 1);
1979 macro_build ((char *) NULL, &icnt, &offset_expr,
1980 likely ? "beql" : "beq",
1989 macro_build ((char *) NULL, &icnt, &offset_expr,
1990 likely ? "bgtzl" : "bgtz",
1996 macro_build ((char *) NULL, &icnt, &offset_expr,
1997 likely ? "bltzl" : "bltz",
2001 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
2002 macro_build ((char *) NULL, &icnt, &offset_expr,
2003 likely ? "bnel" : "bne",
2012 macro_build ((char *) NULL, &icnt, &offset_expr,
2013 likely ? "bnel" : "bne",
2019 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
2021 macro_build ((char *) NULL, &icnt, &offset_expr,
2022 likely ? "bnel" : "bne",
2031 macro_build ((char *) NULL, &icnt, &offset_expr,
2032 likely ? "blezl" : "blez",
2038 macro_build ((char *) NULL, &icnt, &offset_expr,
2039 likely ? "bgezl" : "bgez",
2043 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg);
2044 macro_build ((char *) NULL, &icnt, &offset_expr,
2045 likely ? "beql" : "beq",
2052 maxnum = 0x7fffffff;
2060 if (imm_expr.X_add_number >= maxnum)
2062 imm_expr.X_add_number++;
2066 if (mask == M_BLTL_I)
2068 if (imm_expr.X_add_number == 0)
2070 macro_build ((char *) NULL, &icnt, &offset_expr,
2071 likely ? "bltzl" : "bltz",
2075 if (imm_expr.X_add_number == 1)
2077 macro_build ((char *) NULL, &icnt, &offset_expr,
2078 likely ? "blezl" : "blez",
2082 set_at (&icnt, sreg, 0);
2083 macro_build ((char *) NULL, &icnt, &offset_expr,
2084 likely ? "bnel" : "bne",
2093 macro_build ((char *) NULL, &icnt, &offset_expr,
2094 likely ? "beql" : "beq",
2100 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg,
2102 macro_build ((char *) NULL, &icnt, &offset_expr,
2103 likely ? "beql" : "beq",
2110 if (sreg == 0 || imm_expr.X_add_number == -1)
2112 imm_expr.X_add_number++;
2116 if (mask == M_BLTUL_I)
2118 if (imm_expr.X_add_number == 0)
2120 if (imm_expr.X_add_number == 1)
2122 macro_build ((char *) NULL, &icnt, &offset_expr,
2123 likely ? "beql" : "beq",
2127 set_at (&icnt, sreg, 1);
2128 macro_build ((char *) NULL, &icnt, &offset_expr,
2129 likely ? "bnel" : "bne",
2138 macro_build ((char *) NULL, &icnt, &offset_expr,
2139 likely ? "bltzl" : "bltz",
2145 macro_build ((char *) NULL, &icnt, &offset_expr,
2146 likely ? "bgtzl" : "bgtz",
2150 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg);
2151 macro_build ((char *) NULL, &icnt, &offset_expr,
2152 likely ? "bnel" : "bne",
2163 macro_build ((char *) NULL, &icnt, &offset_expr,
2164 likely ? "bnel" : "bne",
2168 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg,
2170 macro_build ((char *) NULL, &icnt, &offset_expr,
2171 likely ? "bnel" : "bne",
2187 as_warn ("Divide by zero.");
2189 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
2191 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
2195 mips_emit_delays ();
2197 mips_any_noreorder = 1;
2198 macro_build ((char *) NULL, &icnt, NULL,
2199 dbl ? "ddiv" : "div",
2200 "z,s,t", sreg, treg);
2202 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0);
2205 expr1.X_add_number = 8;
2206 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
2207 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
2208 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
2210 expr1.X_add_number = -1;
2211 macro_build ((char *) NULL, &icnt, &expr1,
2212 dbl ? "daddiu" : "addiu",
2213 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
2214 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
2215 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
2218 expr1.X_add_number = 1;
2219 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
2220 (int) BFD_RELOC_LO16);
2221 macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT,
2226 expr1.X_add_number = 0x80000000;
2227 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
2228 (int) BFD_RELOC_HI16);
2231 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", sreg, AT);
2234 expr1.X_add_number = 8;
2235 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
2236 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
2237 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
2240 macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg);
2279 if (imm_expr.X_add_number == 0)
2281 as_warn ("Divide by zero.");
2283 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
2285 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
2288 if (imm_expr.X_add_number == 1)
2290 if (strcmp (s2, "mflo") == 0)
2291 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg,
2294 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
2297 if (imm_expr.X_add_number == -1
2298 && s[strlen (s) - 1] != 'u')
2300 if (strcmp (s2, "mflo") == 0)
2303 macro_build ((char *) NULL, &icnt, NULL, "dneg", "d,w", dreg,
2306 macro_build ((char *) NULL, &icnt, NULL, "neg", "d,w", dreg,
2310 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
2314 load_register (&icnt, AT, &imm_expr);
2315 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT);
2316 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
2335 mips_emit_delays ();
2337 mips_any_noreorder = 1;
2338 macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg);
2340 macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0);
2343 expr1.X_add_number = 8;
2344 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
2345 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
2346 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
2349 macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
2353 /* Load the address of a symbol into a register. If breg is not
2354 zero, we then add a base register to it. */
2356 /* When generating embedded PIC code, we permit expressions of
2359 where bar is an address in the .text section. These are used
2360 when getting the addresses of functions. We don't permit
2361 X_add_number to be non-zero, because if the symbol is
2362 external the relaxing code needs to know that any addend is
2363 purely the offset to X_op_symbol. */
2364 if (mips_pic == EMBEDDED_PIC
2365 && offset_expr.X_op == O_subtract
2366 && now_seg == text_section
2367 && S_GET_SEGMENT (offset_expr.X_op_symbol) == text_section
2369 && offset_expr.X_add_number == 0)
2371 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
2372 treg, (int) BFD_RELOC_PCREL_HI16_S);
2373 macro_build ((char *) NULL, &icnt, &offset_expr,
2374 mips_isa < 3 ? "addiu" : "daddiu",
2375 "t,r,j", treg, treg, (int) BFD_RELOC_PCREL_LO16);
2379 if (offset_expr.X_op != O_symbol
2380 && offset_expr.X_op != O_constant)
2382 as_bad ("expression too complex");
2383 offset_expr.X_op = O_constant;
2397 if (offset_expr.X_op == O_constant)
2398 load_register (&icnt, tempreg, &offset_expr);
2399 else if (mips_pic == NO_PIC)
2401 /* If this is a reference to an GP relative symbol, we want
2402 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
2404 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
2405 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
2406 If we have a constant, we need two instructions anyhow,
2407 so we may as well always use the latter form. */
2408 if (offset_expr.X_add_number != 0)
2413 macro_build ((char *) NULL, &icnt, &offset_expr,
2414 mips_isa < 3 ? "addiu" : "daddiu",
2415 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
2416 p = frag_var (rs_machine_dependent, 8, 0,
2417 RELAX_ENCODE (4, 8, 0, 4, 0,
2418 mips_warn_about_macros),
2419 offset_expr.X_add_symbol, (long) 0,
2422 macro_build_lui (p, &icnt, &offset_expr, tempreg);
2425 macro_build (p, &icnt, &offset_expr,
2426 mips_isa < 3 ? "addiu" : "daddiu",
2427 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
2429 else if (mips_pic == SVR4_PIC)
2431 /* If this is a reference to an external symbol, and there
2432 is no constant, we want
2433 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2434 For a local symbol, we want
2435 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2437 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
2439 If we have a small constant, and this is a reference to
2440 an external symbol, we want
2441 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2443 addiu $tempreg,$tempreg,<constant>
2444 For a local symbol, we want the same instruction
2445 sequence, but we output a BFD_RELOC_LO16 reloc on the
2448 If we have a large constant, and this is a reference to
2449 an external symbol, we want
2450 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2451 lui $at,<hiconstant>
2452 addiu $at,$at,<loconstant>
2453 addu $tempreg,$tempreg,$at
2454 For a local symbol, we want the same instruction
2455 sequence, but we output a BFD_RELOC_LO16 reloc on the
2456 addiu instruction. */
2457 expr1.X_add_number = offset_expr.X_add_number;
2458 offset_expr.X_add_number = 0;
2460 macro_build ((char *) NULL, &icnt, &offset_expr,
2461 mips_isa < 3 ? "lw" : "ld",
2462 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
2463 if (expr1.X_add_number == 0)
2471 /* We're going to put in an addu instruction using
2472 tempreg, so we may as well insert the nop right
2474 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2478 p = frag_var (rs_machine_dependent, 8 - off, 0,
2479 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
2481 ? mips_warn_about_macros
2483 offset_expr.X_add_symbol, (long) 0,
2487 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
2490 macro_build (p, &icnt, &expr1,
2491 mips_isa < 3 ? "addiu" : "daddiu",
2492 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
2493 /* FIXME: If breg == 0, and the next instruction uses
2494 $tempreg, then if this variant case is used an extra
2495 nop will be generated. */
2497 else if (expr1.X_add_number >= -0x8000
2498 && expr1.X_add_number < 0x8000)
2500 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2502 macro_build ((char *) NULL, &icnt, &expr1,
2503 mips_isa < 3 ? "addiu" : "daddiu",
2504 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
2505 (void) frag_var (rs_machine_dependent, 0, 0,
2506 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
2507 offset_expr.X_add_symbol, (long) 0,
2514 /* If we are going to add in a base register, and the
2515 target register and the base register are the same,
2516 then we are using AT as a temporary register. Since
2517 we want to load the constant into AT, we add our
2518 current AT (from the global offset table) and the
2519 register into the register now, and pretend we were
2520 not using a base register. */
2525 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2527 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2528 mips_isa < 3 ? "addu" : "daddu",
2529 "d,v,t", treg, AT, breg);
2535 macro_build_lui ((char *) NULL, &icnt, &expr1, AT);
2536 macro_build ((char *) NULL, &icnt, &expr1,
2537 mips_isa < 3 ? "addiu" : "daddiu",
2538 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
2539 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2540 mips_isa < 3 ? "addu" : "daddu",
2541 "d,v,t", tempreg, tempreg, AT);
2542 (void) frag_var (rs_machine_dependent, 0, 0,
2543 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
2544 offset_expr.X_add_symbol, (long) 0,
2549 else if (mips_pic == EMBEDDED_PIC)
2552 addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL)
2554 macro_build ((char *) NULL, &icnt, &offset_expr,
2555 mips_isa < 3 ? "addiu" : "daddiu",
2556 "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL);
2562 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2563 mips_isa < 3 ? "addu" : "daddu",
2564 "d,v,t", treg, tempreg, breg);
2572 /* The j instruction may not be used in PIC code, since it
2573 requires an absolute address. We convert it to a b
2575 if (mips_pic == NO_PIC)
2576 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
2578 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
2581 /* The jal instructions must be handled as macros because when
2582 generating PIC code they expand to multi-instruction
2583 sequences. Normally they are simple instructions. */
2588 if (mips_pic == NO_PIC
2589 || mips_pic == EMBEDDED_PIC)
2590 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
2592 else if (mips_pic == SVR4_PIC)
2594 if (sreg != PIC_CALL_REG)
2595 as_warn ("MIPS PIC call to register other than $25");
2597 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
2599 if (mips_cprestore_offset < 0)
2600 as_warn ("No .cprestore pseudo-op used in PIC code");
2603 expr1.X_add_number = mips_cprestore_offset;
2604 macro_build ((char *) NULL, &icnt, &expr1,
2605 mips_isa < 3 ? "lw" : "ld",
2606 "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg);
2615 if (mips_pic == NO_PIC)
2616 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
2617 else if (mips_pic == SVR4_PIC)
2619 /* If this is a reference to an external symbol, we want
2620 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
2624 lw $gp,cprestore($sp)
2625 The cprestore value is set using the .cprestore
2626 pseudo-op. If the symbol is not external, we want
2627 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2629 addiu $25,$25,<sym> (BFD_RELOC_LO16)
2632 lw $gp,cprestore($sp)
2635 macro_build ((char *) NULL, &icnt, &offset_expr,
2636 mips_isa < 3 ? "lw" : "ld",
2637 "t,o(b)", PIC_CALL_REG,
2638 (int) BFD_RELOC_MIPS_CALL16, GP);
2639 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
2640 p = frag_var (rs_machine_dependent, 4, 0,
2641 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
2642 offset_expr.X_add_symbol, (long) 0, (char *) NULL);
2643 macro_build (p, &icnt, &offset_expr,
2644 mips_isa < 3 ? "addiu" : "daddiu",
2645 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
2646 (int) BFD_RELOC_LO16);
2647 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2648 "jalr", "s", PIC_CALL_REG);
2649 if (mips_cprestore_offset < 0)
2650 as_warn ("No .cprestore pseudo-op used in PIC code");
2654 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2656 expr1.X_add_number = mips_cprestore_offset;
2657 macro_build ((char *) NULL, &icnt, &expr1,
2658 mips_isa < 3 ? "lw" : "ld",
2659 "t,o(b)", GP, (int) BFD_RELOC_LO16,
2663 else if (mips_pic == EMBEDDED_PIC)
2665 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
2666 /* The linker may expand the call to a longer sequence which
2667 uses $at, so we must break rather than return. */
2739 if (breg == treg || coproc)
2808 if (mask == M_LWC1_AB
2809 || mask == M_SWC1_AB
2810 || mask == M_LDC1_AB
2811 || mask == M_SDC1_AB
2820 if (offset_expr.X_op != O_constant
2821 && offset_expr.X_op != O_symbol)
2823 as_bad ("expression too complex");
2824 offset_expr.X_op = O_constant;
2827 /* A constant expression in PIC code can be handled just as it
2828 is in non PIC code. */
2829 if (mips_pic == NO_PIC
2830 || offset_expr.X_op == O_constant)
2832 /* If this is a reference to a GP relative symbol, and there
2833 is no base register, we want
2834 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
2835 Otherwise, if there is no base register, we want
2836 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
2837 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
2838 If we have a constant, we need two instructions anyhow,
2839 so we always use the latter form.
2841 If we have a base register, and this is a reference to a
2842 GP relative symbol, we want
2843 addu $tempreg,$breg,$gp
2844 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
2846 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
2847 addu $tempreg,$tempreg,$breg
2848 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
2849 With a constant we always use the latter case. */
2852 if (offset_expr.X_add_number != 0)
2857 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
2858 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
2859 p = frag_var (rs_machine_dependent, 8, 0,
2860 RELAX_ENCODE (4, 8, 0, 4, 0,
2861 (mips_warn_about_macros
2862 || (used_at && mips_noat))),
2863 offset_expr.X_add_symbol, (long) 0,
2867 macro_build_lui (p, &icnt, &offset_expr, tempreg);
2870 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
2871 (int) BFD_RELOC_LO16, tempreg);
2875 if (offset_expr.X_add_number != 0)
2880 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2881 mips_isa < 3 ? "addu" : "daddu",
2882 "d,v,t", tempreg, breg, GP);
2883 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
2884 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
2885 p = frag_var (rs_machine_dependent, 12, 0,
2886 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
2887 offset_expr.X_add_symbol, (long) 0,
2890 macro_build_lui (p, &icnt, &offset_expr, tempreg);
2893 macro_build (p, &icnt, (expressionS *) NULL,
2894 mips_isa < 3 ? "addu" : "daddu",
2895 "d,v,t", tempreg, tempreg, breg);
2898 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
2899 (int) BFD_RELOC_LO16, tempreg);
2902 else if (mips_pic == SVR4_PIC)
2904 /* If this is a reference to an external symbol, we want
2905 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2907 <op> $treg,0($tempreg)
2909 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
2911 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
2912 <op> $treg,0($tempreg)
2913 If there is a base register, we add it to $tempreg before
2914 the <op>. If there is a constant, we stick it in the
2915 <op> instruction. We don't handle constants larger than
2916 16 bits, because we have no way to load the upper 16 bits
2917 (actually, we could handle them for the subset of cases
2918 in which we are not using $at). */
2919 assert (offset_expr.X_op == O_symbol);
2920 expr1.X_add_number = offset_expr.X_add_number;
2921 offset_expr.X_add_number = 0;
2922 if (expr1.X_add_number < -0x8000
2923 || expr1.X_add_number >= 0x8000)
2924 as_bad ("PIC code offset overflow (max 16 signed bits)");
2926 macro_build ((char *) NULL, &icnt, &offset_expr,
2927 mips_isa < 3 ? "lw" : "ld",
2928 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
2929 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
2930 p = frag_var (rs_machine_dependent, 4, 0,
2931 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
2932 offset_expr.X_add_symbol, (long) 0,
2934 macro_build (p, &icnt, &offset_expr,
2935 mips_isa < 3 ? "addiu" : "daddiu",
2936 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
2938 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2939 mips_isa < 3 ? "addu" : "daddu",
2940 "d,v,t", tempreg, tempreg, breg);
2941 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
2942 (int) BFD_RELOC_LO16, tempreg);
2944 else if (mips_pic == EMBEDDED_PIC)
2946 /* If there is no base register, we want
2947 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
2948 If there is a base register, we want
2949 addu $tempreg,$breg,$gp
2950 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL)
2952 assert (offset_expr.X_op == O_symbol);
2955 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
2956 treg, (int) BFD_RELOC_MIPS_GPREL, GP);
2961 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
2962 mips_isa < 3 ? "addu" : "daddu",
2963 "d,v,t", tempreg, breg, GP);
2964 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
2965 treg, (int) BFD_RELOC_MIPS_GPREL, tempreg);
2978 load_register (&icnt, treg, &imm_expr);
2982 if (mips_pic == NO_PIC)
2984 assert (offset_expr.X_op == O_symbol
2985 && strcmp (segment_name (S_GET_SEGMENT
2986 (offset_expr.X_add_symbol)),
2988 && offset_expr.X_add_number == 0);
2989 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
2990 treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
2992 else if (mips_pic == SVR4_PIC
2993 || mips_pic == EMBEDDED_PIC)
2995 assert (imm_expr.X_op == O_constant);
2996 load_register (&icnt, treg, &imm_expr);
3004 /* We know that sym is in the .rdata section. First we get the
3005 upper 16 bits of the address. */
3006 if (mips_pic == NO_PIC)
3008 /* FIXME: This won't work for a 64 bit address. */
3009 macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
3011 else if (mips_pic == SVR4_PIC)
3013 macro_build ((char *) NULL, &icnt, &offset_expr,
3014 mips_isa < 3 ? "lw" : "ld",
3015 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
3017 else if (mips_pic == EMBEDDED_PIC)
3019 /* For embedded PIC we pick up the entire address off $gp in
3020 a single instruction. */
3021 macro_build ((char *) NULL, &icnt, &offset_expr,
3022 mips_isa < 3 ? "addiu" : "daddiu",
3023 "t,r,j", AT, GP, (int) BFD_RELOC_MIPS_GPREL);
3024 offset_expr.X_op = O_constant;
3025 offset_expr.X_add_number = 0;
3030 /* Now we load the register(s). */
3032 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
3033 treg, (int) BFD_RELOC_LO16, AT);
3036 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
3037 treg, (int) BFD_RELOC_LO16, AT);
3040 /* FIXME: How in the world do we deal with the possible
3042 offset_expr.X_add_number += 4;
3043 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
3044 treg + 1, (int) BFD_RELOC_LO16, AT);
3051 if (mips_pic == NO_PIC
3052 || mips_pic == EMBEDDED_PIC)
3054 /* Load a floating point number from the .lit8 section. */
3055 assert (offset_expr.X_op == O_symbol
3056 && strcmp (segment_name (S_GET_SEGMENT
3057 (offset_expr.X_add_symbol)),
3059 && offset_expr.X_add_number == 0);
3062 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
3063 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
3067 r = BFD_RELOC_MIPS_LITERAL;
3070 else if (mips_pic == SVR4_PIC)
3072 /* Load the double from the .rdata section. */
3073 macro_build ((char *) NULL, &icnt, &offset_expr,
3074 mips_isa < 3 ? "lw" : "ld",
3075 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
3078 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
3079 "T,o(b)", treg, (int) BFD_RELOC_LO16, GP);
3090 /* Even on a big endian machine $fn comes before $fn+1. We have
3091 to adjust when loading from memory. */
3094 assert (mips_isa < 2);
3095 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
3096 byte_order == LITTLE_ENDIAN ? treg : treg + 1,
3098 /* FIXME: A possible overflow which I don't know how to deal
3100 offset_expr.X_add_number += 4;
3101 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
3102 byte_order == LITTLE_ENDIAN ? treg + 1 : treg,
3110 * The MIPS assembler seems to check for X_add_number not
3111 * being double aligned and generating:
3114 * addiu at,at,%lo(foo+1)
3117 * But, the resulting address is the same after relocation so why
3118 * generate the extra instruction?
3165 if (offset_expr.X_op != O_symbol
3166 && offset_expr.X_op != O_constant)
3168 as_bad ("expression too complex");
3169 offset_expr.X_op = O_constant;
3172 /* Even on a big endian machine $fn comes before $fn+1. We have
3173 to adjust when loading from memory. We set coproc if we must
3174 load $fn+1 first. */
3175 if (byte_order == LITTLE_ENDIAN)
3178 if (mips_pic == NO_PIC
3179 || offset_expr.X_op == O_constant)
3181 /* If this is a reference to a GP relative symbol, we want
3182 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
3183 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
3184 If we have a base register, we use this
3186 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
3187 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
3188 If this is not a GP relative symbol, we want
3189 lui $at,<sym> (BFD_RELOC_HI16_S)
3190 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
3191 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
3192 If there is a base register, we add it to $at after the
3193 lui instruction. If there is a constant, we always use
3195 if (offset_expr.X_add_number != 0)
3214 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3215 mips_isa < 3 ? "addu" : "daddu",
3216 "d,v,t", AT, breg, GP);
3222 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
3223 coproc ? treg + 1 : treg,
3224 (int) BFD_RELOC_MIPS_GPREL, tempreg);
3225 offset_expr.X_add_number += 4;
3226 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
3227 coproc ? treg : treg + 1,
3228 (int) BFD_RELOC_MIPS_GPREL, tempreg);
3229 p = frag_var (rs_machine_dependent, 12 + off, 0,
3230 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
3231 used_at && mips_noat),
3232 offset_expr.X_add_symbol, (long) 0,
3235 /* We just generated two relocs. When tc_gen_reloc
3236 handles this case, it will skip the first reloc and
3237 handle the second. The second reloc already has an
3238 extra addend of 4, which we added above. We must
3239 subtract it out, and then subtract another 4 to make
3240 the first reloc come out right. The second reloc
3241 will come out right because we are going to add 4 to
3242 offset_expr when we build its instruction below. */
3243 offset_expr.X_add_number -= 8;
3244 offset_expr.X_op = O_constant;
3246 macro_build_lui (p, &icnt, &offset_expr, AT);
3251 macro_build (p, &icnt, (expressionS *) NULL,
3252 mips_isa < 3 ? "addu" : "daddu",
3253 "d,v,t", AT, breg, AT);
3257 macro_build (p, &icnt, &offset_expr, s, fmt,
3258 coproc ? treg + 1 : treg,
3259 (int) BFD_RELOC_LO16, AT);
3262 /* FIXME: How do we handle overflow here? */
3263 offset_expr.X_add_number += 4;
3264 macro_build (p, &icnt, &offset_expr, s, fmt,
3265 coproc ? treg : treg + 1,
3266 (int) BFD_RELOC_LO16, AT);
3268 else if (mips_pic == SVR4_PIC)
3272 /* If this is a reference to an external symbol, we want
3273 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3278 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3280 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
3281 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
3282 If there is a base register we add it to $at before the
3283 lwc1 instructions. If there is a constant we include it
3284 in the lwc1 instructions. */
3286 expr1.X_add_number = offset_expr.X_add_number;
3287 offset_expr.X_add_number = 0;
3288 if (expr1.X_add_number < -0x8000
3289 || expr1.X_add_number >= 0x8000 - 4)
3290 as_bad ("PIC code offset overflow (max 16 signed bits)");
3295 frag_grow (24 + off);
3296 macro_build ((char *) NULL, &icnt, &offset_expr,
3297 mips_isa < 3 ? "lw" : "ld",
3298 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
3299 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
3301 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3302 mips_isa < 3 ? "addu" : "daddu",
3303 "d,v,t", AT, breg, AT);
3304 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
3305 coproc ? treg + 1 : treg,
3306 (int) BFD_RELOC_LO16, AT);
3307 expr1.X_add_number += 4;
3308 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
3309 coproc ? treg : treg + 1,
3310 (int) BFD_RELOC_LO16, AT);
3311 (void) frag_var (rs_machine_dependent, 0, 0,
3312 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
3313 offset_expr.X_add_symbol, (long) 0,
3316 else if (mips_pic == EMBEDDED_PIC)
3318 /* If there is no base register, we use
3319 <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL)
3320 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL)
3321 If we have a base register, we use
3323 <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL)
3324 <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL)
3333 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3334 mips_isa < 3 ? "addu" : "daddu",
3335 "d,v,t", AT, breg, GP);
3340 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
3341 coproc ? treg + 1 : treg,
3342 (int) BFD_RELOC_MIPS_GPREL, tempreg);
3343 offset_expr.X_add_number += 4;
3344 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
3345 coproc ? treg : treg + 1,
3346 (int) BFD_RELOC_MIPS_GPREL, tempreg);
3362 assert (mips_isa < 3);
3363 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
3364 (int) BFD_RELOC_LO16, breg);
3365 offset_expr.X_add_number += 4;
3366 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
3367 (int) BFD_RELOC_LO16, breg);
3369 #ifdef LOSING_COMPILER
3375 as_warn ("Macro used $at after \".set noat\"");
3380 struct mips_cl_insn *ip;
3382 register int treg, sreg, dreg, breg;
3395 bfd_reloc_code_real_type r;
3398 treg = (ip->insn_opcode >> 16) & 0x1f;
3399 dreg = (ip->insn_opcode >> 11) & 0x1f;
3400 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3401 mask = ip->insn_mo->mask;
3403 expr1.X_op = O_constant;
3404 expr1.X_op_symbol = NULL;
3405 expr1.X_add_symbol = NULL;
3406 expr1.X_add_number = 1;
3410 #endif /* LOSING_COMPILER */
3415 macro_build ((char *) NULL, &icnt, NULL,
3416 dbl ? "dmultu" : "multu",
3418 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3424 /* The MIPS assembler some times generates shifts and adds. I'm
3425 not trying to be that fancy. GCC should do this for us
3427 load_register (&icnt, AT, &imm_expr);
3428 macro_build ((char *) NULL, &icnt, NULL,
3429 dbl ? "dmult" : "mult",
3431 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3437 mips_emit_delays ();
3439 mips_any_noreorder = 1;
3440 macro_build ((char *) NULL, &icnt, NULL,
3441 dbl ? "dmult" : "mult",
3443 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3444 macro_build ((char *) NULL, &icnt, NULL,
3445 dbl ? "dsra32" : "sra",
3446 "d,w,<", dreg, dreg, 31);
3447 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
3449 macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", dreg, AT);
3452 expr1.X_add_number = 8;
3453 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
3454 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3455 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
3458 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3464 mips_emit_delays ();
3466 mips_any_noreorder = 1;
3467 macro_build ((char *) NULL, &icnt, NULL,
3468 dbl ? "dmultu" : "multu",
3470 macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT);
3471 macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
3473 macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", AT, 0);
3476 expr1.X_add_number = 8;
3477 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
3478 macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
3479 macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
3485 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
3486 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT);
3487 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg,
3489 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
3493 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg,
3494 imm_expr.X_add_number & 0x1f);
3495 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg,
3496 (0 - imm_expr.X_add_number) & 0x1f);
3497 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
3501 macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg);
3502 macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT);
3503 macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg,
3505 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
3509 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg,
3510 imm_expr.X_add_number & 0x1f);
3511 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg,
3512 (0 - imm_expr.X_add_number) & 0x1f);
3513 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT);
3517 assert (mips_isa < 2);
3518 /* Even on a big endian machine $fn comes before $fn+1. We have
3519 to adjust when storing to memory. */
3520 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
3521 byte_order == LITTLE_ENDIAN ? treg : treg + 1,
3522 (int) BFD_RELOC_LO16, breg);
3523 offset_expr.X_add_number += 4;
3524 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
3525 byte_order == LITTLE_ENDIAN ? treg + 1 : treg,
3526 (int) BFD_RELOC_LO16, breg);
3531 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
3532 treg, (int) BFD_RELOC_LO16);
3534 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
3535 sreg, (int) BFD_RELOC_LO16);
3538 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
3540 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
3541 dreg, (int) BFD_RELOC_LO16);
3546 if (imm_expr.X_add_number == 0)
3548 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
3549 sreg, (int) BFD_RELOC_LO16);
3554 as_warn ("Instruction %s: result is always false",
3556 macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0);
3559 if (imm_expr.X_add_number >= 0 && imm_expr.X_add_number < 0x10000)
3561 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
3562 sreg, (int) BFD_RELOC_LO16);
3565 else if (imm_expr.X_add_number > -0x8000 && imm_expr.X_add_number < 0)
3567 imm_expr.X_add_number = -imm_expr.X_add_number;
3568 macro_build ((char *) NULL, &icnt, &imm_expr,
3569 mips_isa < 3 ? "addiu" : "daddiu",
3570 "t,r,j", dreg, sreg,
3571 (int) BFD_RELOC_LO16);
3576 load_register (&icnt, AT, &imm_expr);
3577 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
3581 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
3582 (int) BFD_RELOC_LO16);
3587 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
3593 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg);
3594 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
3595 (int) BFD_RELOC_LO16);
3598 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
3600 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
3602 macro_build ((char *) NULL, &icnt, &expr1,
3603 mask == M_SGE_I ? "slti" : "sltiu",
3604 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
3609 load_register (&icnt, AT, &imm_expr);
3610 macro_build ((char *) NULL, &icnt, NULL,
3611 mask == M_SGE_I ? "slt" : "sltu",
3612 "d,v,t", dreg, sreg, AT);
3615 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
3616 (int) BFD_RELOC_LO16);
3621 case M_SGT: /* sreg > treg <==> treg < sreg */
3627 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
3630 case M_SGT_I: /* sreg > I <==> I < sreg */
3636 load_register (&icnt, AT, &imm_expr);
3637 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
3640 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
3646 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg);
3647 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
3648 (int) BFD_RELOC_LO16);
3651 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
3657 load_register (&icnt, AT, &imm_expr);
3658 macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg);
3659 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
3660 (int) BFD_RELOC_LO16);
3664 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
3666 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
3667 dreg, sreg, (int) BFD_RELOC_LO16);
3670 load_register (&icnt, AT, &imm_expr);
3671 macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT);
3675 if (imm_expr.X_add_number >= -0x8000 && imm_expr.X_add_number < 0x8000)
3677 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
3678 dreg, sreg, (int) BFD_RELOC_LO16);
3681 load_register (&icnt, AT, &imm_expr);
3682 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg,
3688 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
3691 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
3695 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
3697 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
3703 if (imm_expr.X_add_number == 0)
3705 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0,
3711 as_warn ("Instruction %s: result is always true",
3713 macro_build ((char *) NULL, &icnt, &expr1,
3714 mips_isa < 3 ? "addiu" : "daddiu",
3715 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
3718 if (imm_expr.X_add_number >= 0 && imm_expr.X_add_number < 0x10000)
3720 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
3721 dreg, sreg, (int) BFD_RELOC_LO16);
3724 else if (imm_expr.X_add_number > -0x8000 && imm_expr.X_add_number < 0)
3726 imm_expr.X_add_number = -imm_expr.X_add_number;
3727 macro_build ((char *) NULL, &icnt, &imm_expr,
3728 mips_isa < 3 ? "addiu" : "daddiu",
3729 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
3734 load_register (&icnt, AT, &imm_expr);
3735 macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg,
3739 macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg);
3747 if (imm_expr.X_add_number > -0x8000 && imm_expr.X_add_number <= 0x8000)
3749 imm_expr.X_add_number = -imm_expr.X_add_number;
3750 macro_build ((char *) NULL, &icnt, &imm_expr,
3751 dbl ? "daddi" : "addi",
3752 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
3755 load_register (&icnt, AT, &imm_expr);
3756 macro_build ((char *) NULL, &icnt, NULL,
3757 dbl ? "dsub" : "sub",
3758 "d,v,t", dreg, sreg, AT);
3764 if (imm_expr.X_add_number > -0x8000 && imm_expr.X_add_number <= 0x8000)
3766 imm_expr.X_add_number = -imm_expr.X_add_number;
3767 macro_build ((char *) NULL, &icnt, &imm_expr,
3768 dbl ? "daddiu" : "addiu",
3769 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
3772 load_register (&icnt, AT, &imm_expr);
3773 macro_build ((char *) NULL, &icnt, NULL,
3774 dbl ? "dsubu" : "subu",
3775 "d,v,t", dreg, sreg, AT);
3796 load_register (&icnt, AT, &imm_expr);
3797 macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT);
3802 assert (mips_isa < 2);
3803 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
3804 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
3807 * Is the double cfc1 instruction a bug in the mips assembler;
3808 * or is there a reason for it?
3810 mips_emit_delays ();
3812 mips_any_noreorder = 1;
3813 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
3814 macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31);
3815 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
3816 expr1.X_add_number = 3;
3817 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
3818 (int) BFD_RELOC_LO16);
3819 expr1.X_add_number = 2;
3820 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
3821 (int) BFD_RELOC_LO16);
3822 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31);
3823 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
3824 macro_build ((char *) NULL, &icnt, NULL,
3825 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
3826 macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31);
3827 macro_build ((char *) NULL, &icnt, NULL, "nop", "");
3837 if (offset_expr.X_add_number >= 0x7fff)
3838 as_bad ("operand overflow");
3839 /* avoid load delay */
3840 if (byte_order == LITTLE_ENDIAN)
3841 offset_expr.X_add_number += 1;
3842 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
3843 (int) BFD_RELOC_LO16, breg);
3844 if (byte_order == LITTLE_ENDIAN)
3845 offset_expr.X_add_number -= 1;
3847 offset_expr.X_add_number += 1;
3848 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
3849 (int) BFD_RELOC_LO16, breg);
3850 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8);
3851 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT);
3855 if (offset_expr.X_add_number >= 0x7ffd)
3856 as_bad ("operand overflow");
3857 if (byte_order == LITTLE_ENDIAN)
3858 offset_expr.X_add_number += 3;
3859 macro_build ((char *) NULL, &icnt, &offset_expr, "lwl", "t,o(b)", treg,
3860 (int) BFD_RELOC_LO16, breg);
3861 if (byte_order == LITTLE_ENDIAN)
3862 offset_expr.X_add_number -= 3;
3864 offset_expr.X_add_number += 3;
3865 macro_build ((char *) NULL, &icnt, &offset_expr, "lwr", "t,o(b)", treg,
3866 (int) BFD_RELOC_LO16, breg);
3872 load_address (&icnt, AT, &offset_expr);
3873 if (mask == M_ULW_A)
3875 if (byte_order == LITTLE_ENDIAN)
3876 expr1.X_add_number = 3;
3878 expr1.X_add_number = 0;
3879 macro_build ((char *) NULL, &icnt, &expr1, "lwl", "t,o(b)", treg,
3880 (int) BFD_RELOC_LO16, AT);
3881 if (byte_order == LITTLE_ENDIAN)
3882 expr1.X_add_number = 0;
3884 expr1.X_add_number = 3;
3885 macro_build ((char *) NULL, &icnt, &expr1, "lwr", "t,o(b)", treg,
3886 (int) BFD_RELOC_LO16, AT);
3890 if (byte_order == BIG_ENDIAN)
3891 expr1.X_add_number = 0;
3892 macro_build ((char *) NULL, &icnt, &expr1,
3893 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
3894 (int) BFD_RELOC_LO16, AT);
3895 if (byte_order == BIG_ENDIAN)
3896 expr1.X_add_number = 1;
3898 expr1.X_add_number = 0;
3899 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
3900 (int) BFD_RELOC_LO16, AT);
3901 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
3903 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
3909 if (offset_expr.X_add_number >= 0x7fff)
3910 as_bad ("operand overflow");
3911 if (byte_order == BIG_ENDIAN)
3912 offset_expr.X_add_number += 1;
3913 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
3914 (int) BFD_RELOC_LO16, breg);
3915 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8);
3916 if (byte_order == BIG_ENDIAN)
3917 offset_expr.X_add_number -= 1;
3919 offset_expr.X_add_number += 1;
3920 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
3921 (int) BFD_RELOC_LO16, breg);
3925 if (offset_expr.X_add_number >= 0x7ffd)
3926 as_bad ("operand overflow");
3927 if (byte_order == LITTLE_ENDIAN)
3928 offset_expr.X_add_number += 3;
3929 macro_build ((char *) NULL, &icnt, &offset_expr, "swl", "t,o(b)", treg,
3930 (int) BFD_RELOC_LO16, breg);
3931 if (byte_order == LITTLE_ENDIAN)
3932 offset_expr.X_add_number -= 3;
3934 offset_expr.X_add_number += 3;
3935 macro_build ((char *) NULL, &icnt, &offset_expr, "swr", "t,o(b)", treg,
3936 (int) BFD_RELOC_LO16, breg);
3941 load_address (&icnt, AT, &offset_expr);
3942 if (mask == M_USW_A)
3944 if (byte_order == LITTLE_ENDIAN)
3945 expr1.X_add_number = 3;
3947 expr1.X_add_number = 0;
3948 macro_build ((char *) NULL, &icnt, &expr1, "swl", "t,o(b)", treg,
3949 (int) BFD_RELOC_LO16, AT);
3950 if (byte_order == LITTLE_ENDIAN)
3951 expr1.X_add_number = 0;
3953 expr1.X_add_number = 3;
3954 macro_build ((char *) NULL, &icnt, &expr1, "swr", "t,o(b)", treg,
3955 (int) BFD_RELOC_LO16, AT);
3959 if (byte_order == LITTLE_ENDIAN)
3960 expr1.X_add_number = 0;
3961 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
3962 (int) BFD_RELOC_LO16, AT);
3963 macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg,
3965 if (byte_order == LITTLE_ENDIAN)
3966 expr1.X_add_number = 1;
3968 expr1.X_add_number = 0;
3969 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
3970 (int) BFD_RELOC_LO16, AT);
3971 if (byte_order == LITTLE_ENDIAN)
3972 expr1.X_add_number = 0;
3974 expr1.X_add_number = 1;
3975 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
3976 (int) BFD_RELOC_LO16, AT);
3977 macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg,
3979 macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg,
3985 as_bad ("Macro %s not implemented yet", ip->insn_mo->name);
3989 as_warn ("Macro used $at after \".set noat\"");
3994 This routine assembles an instruction into its binary format. As a side
3995 effect it sets one of the global variables imm_reloc or offset_reloc to the
3996 type of relocation to do if one of the operands is an address expression.
4001 struct mips_cl_insn *ip;
4006 struct mips_opcode *insn;
4009 unsigned int lastregno = 0;
4014 for (s = str; islower (*s) || (*s >= '0' && *s <= '3') || *s == '.'; ++s)
4026 as_warn ("Unknown opcode: `%s'", str);
4029 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
4031 as_warn ("`%s' not in hash table.", str);
4032 insn_error = "ERROR: Unrecognized opcode";
4040 assert (strcmp (insn->name, str) == 0);
4042 if (insn->pinfo == INSN_MACRO)
4043 insn_isa = insn->match;
4044 else if (insn->pinfo & INSN_ISA2)
4046 else if (insn->pinfo & INSN_ISA3)
4051 if (insn_isa > mips_isa)
4053 if (insn + 1 < &mips_opcodes[NUMOPCODES]
4054 && strcmp (insn->name, insn[1].name) == 0)
4059 as_warn ("Instruction not supported on this processor");
4063 ip->insn_opcode = insn->match;
4064 for (args = insn->args;; ++args)
4070 case '\0': /* end of args */
4083 ip->insn_opcode |= lastregno << 21;
4088 ip->insn_opcode |= lastregno << 16;
4092 ip->insn_opcode |= lastregno << 11;
4098 /* handle optional base register.
4099 Either the base register is omitted or
4100 we must have a left paren. */
4101 /* this is dependent on the next operand specifier
4102 is a 'b' for base register */
4103 assert (args[1] == 'b');
4107 case ')': /* these must match exactly */
4112 case '<': /* must be at least one digit */
4114 * According to the manual, if the shift amount is greater
4115 * than 31 or less than 0 the the shift amount should be
4116 * mod 32. In reality the mips assembler issues an error.
4117 * We issue a warning and mask out all but the low 5 bits.
4119 my_getExpression (&imm_expr, s);
4120 check_absolute_expr (ip, &imm_expr);
4121 if ((unsigned long) imm_expr.X_add_number > 31)
4123 as_warn ("Improper shift amount (%ld)",
4124 (long) imm_expr.X_add_number);
4125 imm_expr.X_add_number = imm_expr.X_add_number & 0x1f;
4127 ip->insn_opcode |= imm_expr.X_add_number << 6;
4128 imm_expr.X_op = O_absent;
4132 case '>': /* shift amount minus 32 */
4133 my_getExpression (&imm_expr, s);
4134 check_absolute_expr (ip, &imm_expr);
4135 if ((unsigned long) imm_expr.X_add_number < 32
4136 || (unsigned long) imm_expr.X_add_number > 63)
4138 ip->insn_opcode |= (imm_expr.X_add_number - 32) << 6;
4139 imm_expr.X_op = O_absent;
4143 case 'k': /* cache code */
4144 my_getExpression (&imm_expr, s);
4145 check_absolute_expr (ip, &imm_expr);
4146 if ((unsigned long) imm_expr.X_add_number > 31)
4148 as_warn ("Invalid cahce opcode (%lu)",
4149 (unsigned long) imm_expr.X_add_number);
4150 imm_expr.X_add_number &= 0x1f;
4152 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
4153 imm_expr.X_op = O_absent;
4157 case 'c': /* break code */
4158 my_getExpression (&imm_expr, s);
4159 check_absolute_expr (ip, &imm_expr);
4160 if ((unsigned) imm_expr.X_add_number > 1023)
4161 as_warn ("Illegal break code (%ld)",
4162 (long) imm_expr.X_add_number);
4163 ip->insn_opcode |= imm_expr.X_add_number << 16;
4164 imm_expr.X_op = O_absent;
4168 case 'B': /* syscall code */
4169 my_getExpression (&imm_expr, s);
4170 check_absolute_expr (ip, &imm_expr);
4171 if ((unsigned) imm_expr.X_add_number > 0xfffff)
4172 as_warn ("Illegal syscall code (%ld)",
4173 (long) imm_expr.X_add_number);
4174 ip->insn_opcode |= imm_expr.X_add_number << 6;
4175 imm_expr.X_op = O_absent;
4179 case 'C': /* Coprocessor code */
4180 my_getExpression (&imm_expr, s);
4181 check_absolute_expr (ip, &imm_expr);
4182 if ((unsigned long) imm_expr.X_add_number >= (1<<25))
4184 as_warn ("Coproccesor code > 25 bits (%ld)",
4185 (long) imm_expr.X_add_number);
4186 imm_expr.X_add_number &= ((1<<25) - 1);
4188 ip->insn_opcode |= imm_expr.X_add_number;
4189 imm_expr.X_op = O_absent;
4193 case 'b': /* base register */
4194 case 'd': /* destination register */
4195 case 's': /* source register */
4196 case 't': /* target register */
4197 case 'r': /* both target and source */
4198 case 'v': /* both dest and source */
4199 case 'w': /* both dest and target */
4200 case 'E': /* coprocessor target register */
4201 case 'G': /* coprocessor destination register */
4202 case 'x': /* ignore register name */
4203 case 'z': /* must be zero register */
4217 while (isdigit (*s));
4219 as_bad ("Invalid register number (%d)", regno);
4221 else if (*args == 'E' || *args == 'G')
4225 if (s[1] == 'f' && s[2] == 'p')
4230 else if (s[1] == 's' && s[2] == 'p')
4235 else if (s[1] == 'g' && s[2] == 'p')
4240 else if (s[1] == 'a' && s[2] == 't')
4248 if (regno == AT && ! mips_noat)
4249 as_warn ("Used $at without \".set noat\"");
4255 if (c == 'r' || c == 'v' || c == 'w')
4262 /* 'z' only matches $0. */
4263 if (c == 'z' && regno != 0)
4271 ip->insn_opcode |= regno << 21;
4275 ip->insn_opcode |= regno << 11;
4280 ip->insn_opcode |= regno << 16;
4283 /* This case exists because on the r3000 trunc
4284 expands into a macro which requires a gp
4285 register. On the r6000 or r4000 it is
4286 assembled into a single instruction which
4287 ignores the register. Thus the insn version
4288 is MIPS_ISA2 and uses 'x', and the macro
4289 version is MIPS_ISA1 and uses 't'. */
4292 /* This case is for the div instruction, which
4293 acts differently if the destination argument
4294 is $0. This only matches $0, and is checked
4295 outside the switch. */
4306 ip->insn_opcode |= lastregno << 21;
4309 ip->insn_opcode |= lastregno << 16;
4314 case 'D': /* floating point destination register */
4315 case 'S': /* floating point source register */
4316 case 'T': /* floating point target register */
4320 if (s[0] == '$' && s[1] == 'f' && isdigit (s[2]))
4330 while (isdigit (*s));
4333 as_bad ("Invalid float register number (%d)", regno);
4335 if ((regno & 1) != 0
4337 && ! (strcmp (str, "mtc1") == 0 ||
4338 strcmp (str, "mfc1") == 0 ||
4339 strcmp (str, "lwc1") == 0 ||
4340 strcmp (str, "swc1") == 0))
4341 as_warn ("Float register should be even, was %d",
4349 if (c == 'V' || c == 'W')
4359 ip->insn_opcode |= regno << 6;
4363 ip->insn_opcode |= regno << 11;
4367 ip->insn_opcode |= regno << 16;
4375 ip->insn_opcode |= lastregno << 11;
4378 ip->insn_opcode |= lastregno << 16;
4384 my_getExpression (&imm_expr, s);
4385 check_absolute_expr (ip, &imm_expr);
4390 my_getExpression (&offset_expr, s);
4391 imm_reloc = BFD_RELOC_32;
4403 unsigned char temp[8];
4405 unsigned int length;
4410 /* These only appear as the last operand in an
4411 instruction, and every instruction that accepts
4412 them in any variant accepts them in all variants.
4413 This means we don't have to worry about backing out
4414 any changes if the instruction does not match.
4416 The difference between them is the size of the
4417 floating point constant and where it goes. For 'F'
4418 and 'L' the constant is 64 bits; for 'f' and 'l' it
4419 is 32 bits. Where the constant is placed is based
4420 on how the MIPS assembler does things:
4423 f -- immediate value
4426 When generating SVR4 PIC code, we do not use the
4427 .lit8 or .lit4 sections at all, in order to
4428 reserve the entire global offset table. When
4429 generating embedded PIC code, we use the .lit8
4430 section but not the .lit4 section (we can do .lit4
4431 inline easily; we need to put .lit8 somewhere in
4432 the data segment, and using .lit8 permits the
4433 linker to eventually combine identical .lit8
4436 f64 = *args == 'F' || *args == 'L';
4438 save_in = input_line_pointer;
4439 input_line_pointer = s;
4440 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
4442 s = input_line_pointer;
4443 input_line_pointer = save_in;
4444 if (err != NULL && *err != '\0')
4446 as_bad ("Bad floating point constant: %s", err);
4447 memset (temp, '\0', sizeof temp);
4448 length = f64 ? 8 : 4;
4451 assert (length == (f64 ? 8 : 4));
4454 || (mips_pic != NO_PIC && *args == 'l'))
4456 imm_expr.X_op = O_constant;
4457 if (byte_order == LITTLE_ENDIAN)
4458 imm_expr.X_add_number =
4459 (((((((int) temp[3] << 8)
4464 imm_expr.X_add_number =
4465 (((((((int) temp[0] << 8)
4472 const char *newname;
4475 /* Switch to the right section. */
4477 subseg = now_subseg;
4480 default: /* unused default case avoids warnings. */
4482 newname = (mips_pic != SVR4_PIC ? ".lit8" : ".rdata");
4488 assert (mips_pic == NO_PIC);
4492 new_seg = subseg_new (newname, (subsegT) 0);
4494 bfd_set_section_alignment (stdoutput, new_seg, 4);
4497 as_bad ("Can't use floating point insn in this section");
4499 /* Set the argument to the current address in the
4501 offset_expr.X_op = O_symbol;
4502 offset_expr.X_add_symbol =
4503 symbol_new ("L0\001", now_seg,
4504 (valueT) frag_now_fix (), frag_now);
4505 offset_expr.X_add_number = 0;
4507 /* Put the floating point number into the section. */
4508 p = frag_more ((int) length);
4509 memcpy (p, temp, length);
4511 /* Switch back to the original section. */
4512 subseg_set (seg, subseg);
4517 case 'i': /* 16 bit unsigned immediate */
4518 case 'j': /* 16 bit signed immediate */
4519 imm_reloc = BFD_RELOC_LO16;
4520 c = my_getSmallExpression (&imm_expr, s);
4525 if (imm_expr.X_op == O_constant)
4526 imm_expr.X_add_number =
4527 (imm_expr.X_add_number >> 16) & 0xffff;
4529 imm_reloc = BFD_RELOC_HI16_S;
4531 imm_reloc = BFD_RELOC_HI16;
4535 check_absolute_expr (ip, &imm_expr);
4538 if (imm_expr.X_add_number < 0
4539 || imm_expr.X_add_number >= 0x10000)
4541 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
4542 !strcmp (insn->name, insn[1].name))
4544 as_bad ("16 bit expression not in range 0..65535");
4552 /* The upper bound should be 0x8000, but
4553 unfortunately the MIPS assembler accepts numbers
4554 from 0x8000 to 0xffff and sign extends them, and
4555 we want to be compatible. We only permit this
4556 extended range for an instruction which does not
4557 provide any further alternates, since those
4558 alternates may handle other cases. People should
4559 use the numbers they mean, rather than relying on
4560 a mysterious sign extension. */
4561 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
4562 strcmp (insn->name, insn[1].name) == 0);
4567 if (imm_expr.X_add_number < -0x8000 ||
4568 imm_expr.X_add_number >= max)
4572 as_bad ("16 bit expression not in range -32768..32767");
4578 case 'o': /* 16 bit offset */
4579 c = my_getSmallExpression (&offset_expr, s);
4581 /* If this value won't fit into a 16 bit offset, then go
4582 find a macro that will generate the 32 bit offset
4583 code pattern. As a special hack, we accept the
4584 difference of two local symbols as a constant. This
4585 is required to suppose embedded PIC switches, which
4586 use an instruction which looks like
4587 lw $4,$L12-$LS12($4)
4588 The problem with handling this in a more general
4589 fashion is that the macro function doesn't expect to
4590 see anything which can be handled in a single
4591 constant instruction. */
4592 if ((offset_expr.X_op != O_constant
4593 || offset_expr.X_add_number >= 0x8000
4594 || offset_expr.X_add_number < -0x8000)
4595 && (mips_pic != EMBEDDED_PIC
4596 || offset_expr.X_op != O_subtract
4597 || ! S_IS_LOCAL (offset_expr.X_add_symbol)
4598 || ! S_IS_LOCAL (offset_expr.X_op_symbol)))
4601 offset_reloc = BFD_RELOC_LO16;
4602 if (c == 'h' || c == 'H')
4604 assert (offset_expr.X_op == O_constant);
4605 offset_expr.X_add_number =
4606 (offset_expr.X_add_number >> 16) & 0xffff;
4611 case 'p': /* pc relative offset */
4612 offset_reloc = BFD_RELOC_16_PCREL_S2;
4613 my_getExpression (&offset_expr, s);
4617 case 'u': /* upper 16 bits */
4618 c = my_getSmallExpression (&imm_expr, s);
4619 if (imm_expr.X_op != O_constant
4620 || imm_expr.X_add_number < 0
4621 || imm_expr.X_add_number >= 0x10000)
4622 as_bad ("lui expression not in range 0..65535");
4623 imm_reloc = BFD_RELOC_LO16;
4628 if (imm_expr.X_op == O_constant)
4629 imm_expr.X_add_number =
4630 (imm_expr.X_add_number >> 16) & 0xffff;
4632 imm_reloc = BFD_RELOC_HI16_S;
4634 imm_reloc = BFD_RELOC_HI16;
4640 case 'a': /* 26 bit address */
4641 my_getExpression (&offset_expr, s);
4643 offset_reloc = BFD_RELOC_MIPS_JMP;
4647 fprintf (stderr, "bad char = '%c'\n", *args);
4652 /* Args don't match. */
4653 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
4654 !strcmp (insn->name, insn[1].name))
4660 insn_error = "ERROR: Illegal operands";
4669 my_getSmallExpression (ep, str)
4680 ((str[1] == 'h' && str[2] == 'i')
4681 || (str[1] == 'H' && str[2] == 'I')
4682 || (str[1] == 'l' && str[2] == 'o'))
4694 * A small expression may be followed by a base register.
4695 * Scan to the end of this operand, and then back over a possible
4696 * base register. Then scan the small expression up to that
4697 * point. (Based on code in sparc.c...)
4699 for (sp = str; *sp && *sp != ','; sp++)
4701 if (sp - 4 >= str && sp[-1] == RP)
4703 if (isdigit (sp[-2]))
4705 for (sp -= 3; sp >= str && isdigit (*sp); sp--)
4707 if (*sp == '$' && sp > str && sp[-1] == LP)
4713 else if (sp - 5 >= str
4716 && ((sp[-3] == 'f' && sp[-2] == 'p')
4717 || (sp[-3] == 's' && sp[-2] == 'p')
4718 || (sp[-3] == 'g' && sp[-2] == 'p')
4719 || (sp[-3] == 'a' && sp[-2] == 't')))
4725 /* no expression means zero offset */
4728 /* %xx(reg) is an error */
4729 ep->X_op = O_absent;
4734 ep->X_op = O_constant;
4737 ep->X_add_symbol = NULL;
4738 ep->X_op_symbol = NULL;
4739 ep->X_add_number = 0;
4744 my_getExpression (ep, str);
4751 my_getExpression (ep, str);
4752 return c; /* => %hi or %lo encountered */
4756 my_getExpression (ep, str)
4762 save_in = input_line_pointer;
4763 input_line_pointer = str;
4765 expr_end = input_line_pointer;
4766 input_line_pointer = save_in;
4769 /* Turn a string in input_line_pointer into a floating point constant
4770 of type type, and store the appropriate bytes in *litP. The number
4771 of LITTLENUMS emitted is stored in *sizeP . An error message is
4772 returned, or NULL on OK. */
4775 md_atof (type, litP, sizeP)
4781 LITTLENUM_TYPE words[4];
4797 return "bad call to md_atof";
4800 t = atof_ieee (input_line_pointer, type, words);
4802 input_line_pointer = t;
4806 if (byte_order == LITTLE_ENDIAN)
4808 for (i = prec - 1; i >= 0; i--)
4810 md_number_to_chars (litP, (valueT) words[i], 2);
4816 for (i = 0; i < prec; i++)
4818 md_number_to_chars (litP, (valueT) words[i], 2);
4827 md_number_to_chars (buf, val, n)
4835 number_to_chars_littleendian (buf, val, n);
4839 number_to_chars_bigendian (buf, val, n);
4848 md_parse_option (argP, cntP, vecP)
4853 /* Accept -nocpp but ignore it. */
4854 if (strcmp (*argP, "nocpp") == 0)
4860 if (strcmp (*argP, "EL") == 0
4861 || strcmp (*argP, "EB") == 0)
4863 if ((*argP)[1] == 'B')
4864 byte_order = BIG_ENDIAN;
4866 byte_order = LITTLE_ENDIAN;
4869 if ((*argP)[1] == 'B')
4870 mips_target_format = "a.out-mips-big";
4872 mips_target_format = "a.out-mips-little";
4875 if ((*argP)[1] == 'B')
4876 mips_target_format = "ecoff-bigmips";
4878 mips_target_format = "ecoff-littlemips";
4881 if ((*argP)[1] == 'B')
4882 mips_target_format = "elf32-bigmips";
4884 mips_target_format = "elf32-littlemips";
4887 /* FIXME: This breaks -L -EL. */
4895 if ((*argP)[1] == '0')
4904 if ((*argP)[1] == '\0' || (*argP)[1] == '2')
4909 if (strncmp (*argP, "mips", 4) == 0)
4911 mips_isa = atol (*argP + 4);
4914 else if (mips_isa < 1 || mips_isa > 3)
4916 as_bad ("-mips%d not supported", mips_isa);
4923 if (strncmp (*argP, "mcpu=", 5) == 0)
4927 /* Identify the processor type */
4929 if (strcmp (p, "default") == 0
4930 || strcmp (p, "DEFAULT") == 0)
4934 if (*p == 'r' || *p == 'R')
4941 if (strcmp (p, "2000") == 0
4942 || strcmp (p, "2k") == 0
4943 || strcmp (p, "2K") == 0)
4948 if (strcmp (p, "3000") == 0
4949 || strcmp (p, "3k") == 0
4950 || strcmp (p, "3K") == 0)
4955 if (strcmp (p, "4000") == 0
4956 || strcmp (p, "4k") == 0
4957 || strcmp (p, "4K") == 0)
4962 if (strcmp (p, "6000") == 0
4963 || strcmp (p, "6k") == 0
4964 || strcmp (p, "6K") == 0)
4971 as_bad ("bad value (%s) for -mcpu= switch", *argP + 5);
4980 /* Argument -membedded-pic means to use EMBEDDED_PIC. */
4981 if (strcmp (*argP, "membedded-pic") == 0)
4983 mips_pic = EMBEDDED_PIC;
4986 as_warn ("-G may not be used with embedded PIC code");
4987 g_switch_value = 0x7fffffff;
4994 /* When generating ELF code, we permit -KPIC and -call_shared to
4995 select SVR4_PIC, and -non_shared to select no PIC. This is
4996 intended to be compatible with Irix 5. */
4997 if (strcmp (*argP, "KPIC") == 0
4998 || strcmp (*argP, "call_shared") == 0)
5000 mips_pic = SVR4_PIC;
5001 if (g_switch_seen && g_switch_value != 0)
5002 as_warn ("-G may not be used with SVR4 PIC code");
5007 else if (strcmp (*argP, "non_shared") == 0)
5013 #endif /* OBJ_ELF */
5018 if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
5019 as_warn ("-G may not be used with SVR4 or embedded PIC code");
5020 else if ((*argP)[1] != '\0')
5021 g_switch_value = atoi (*argP + 1);
5024 **vecP = (char *) NULL;
5027 g_switch_value = atoi (**vecP);
5030 as_warn ("Number expected after -G");
5037 return 1; /* pretend you parsed the character */
5040 /* Handle a long option name. */
5043 mips_parse_long_option (arg)
5046 if (strcmp (arg, "--trap") == 0
5047 || strcmp (arg, "--no-break") == 0)
5052 else if (strcmp (arg, "--no-trap") == 0
5053 || strcmp (arg, "--break") == 0)
5063 md_pcrel_from (fixP)
5067 if (fixP->fx_addsy != (symbolS *) NULL
5068 && ! S_IS_DEFINED (fixP->fx_addsy))
5070 /* This makes a branch to an undefined symbol be a branch to the
5071 current location. */
5076 /* return the address of the delay slot */
5077 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
5080 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
5081 reloc for a cons. We could use the definition there, except that
5082 we want to handle 64 bit relocs specially. */
5085 cons_fix_new_mips (frag, where, nbytes, exp)
5088 unsigned int nbytes;
5091 /* If we are assembling in 32 bit mode, turn an 8 byte reloc into a
5093 FIXME: There is no way to select anything but 32 bit mode right
5097 if (byte_order == BIG_ENDIAN)
5102 if (nbytes != 2 && nbytes != 4)
5103 as_bad ("Unsupported reloc size %d", nbytes);
5105 fix_new_exp (frag_now, where, (int) nbytes, exp, 0,
5106 nbytes == 2 ? BFD_RELOC_16 : BFD_RELOC_32);
5109 /* When generating embedded PIC code we need to use a special
5110 relocation to represent the difference of two symbols in the .text
5111 section (switch tables use a difference of this sort). See
5112 include/coff/mips.h for details. This macro checks whether this
5113 fixup requires the special reloc. */
5114 #define SWITCH_TABLE(fixp) \
5115 ((fixp)->fx_r_type == BFD_RELOC_32 \
5116 && (fixp)->fx_addsy != NULL \
5117 && (fixp)->fx_subsy != NULL \
5118 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
5119 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
5121 /* When generating embedded PIC code we must keep all PC relative
5122 relocations, in case the linker has to relax a call. We also need
5123 to keep relocations for switch table entries. */
5127 mips_force_relocation (fixp)
5130 return (mips_pic == EMBEDDED_PIC
5132 || SWITCH_TABLE (fixp)
5133 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
5134 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
5137 /* Apply a fixup to the object file. */
5140 md_apply_fix (fixP, valueP)
5147 assert (fixP->fx_size == 4);
5150 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */
5152 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
5155 switch (fixP->fx_r_type)
5157 case BFD_RELOC_MIPS_JMP:
5158 case BFD_RELOC_HI16:
5159 case BFD_RELOC_HI16_S:
5160 case BFD_RELOC_MIPS_GPREL:
5161 case BFD_RELOC_MIPS_LITERAL:
5162 case BFD_RELOC_MIPS_CALL16:
5163 case BFD_RELOC_MIPS_GOT16:
5164 case BFD_RELOC_MIPS_GPREL32:
5166 as_bad ("Invalid PC relative reloc");
5167 /* Nothing needed to do. The value comes from the reloc entry */
5170 case BFD_RELOC_PCREL_HI16_S:
5171 /* The addend for this is tricky if it is internal, so we just
5172 do everything here rather than in bfd_perform_relocation. */
5173 if ((fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) == 0)
5175 /* For an external symbol adjust by the address to make it
5176 pcrel_offset. We use the address of the RELLO reloc
5177 which follows this one. */
5178 value += (fixP->fx_next->fx_frag->fr_address
5179 + fixP->fx_next->fx_where);
5184 buf = fixP->fx_frag->fr_literal + fixP->fx_where;
5185 if (byte_order == BIG_ENDIAN)
5187 md_number_to_chars (buf, value, 2);
5190 case BFD_RELOC_PCREL_LO16:
5191 /* The addend for this is tricky if it is internal, so we just
5192 do everything here rather than in bfd_perform_relocation. */
5193 if ((fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) == 0)
5194 value += fixP->fx_frag->fr_address + fixP->fx_where;
5195 buf = fixP->fx_frag->fr_literal + fixP->fx_where;
5196 if (byte_order == BIG_ENDIAN)
5198 md_number_to_chars (buf, value, 2);
5202 /* If we are deleting this reloc entry, we must fill in the
5203 value now. This can happen if we have a .word which is not
5204 resolved when it appears but is later defined. We also need
5205 to fill in the value if this is an embedded PIC switch table
5208 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
5209 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5213 case BFD_RELOC_LO16:
5214 /* When handling an embedded PIC switch statement, we can wind
5215 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
5218 if (value < -0x8000 || value > 0x7fff)
5219 as_bad_where (fixP->fx_file, fixP->fx_line,
5220 "relocation overflow");
5221 buf = fixP->fx_frag->fr_literal + fixP->fx_where;
5222 if (byte_order == BIG_ENDIAN)
5224 md_number_to_chars (buf, value, 2);
5228 case BFD_RELOC_16_PCREL_S2:
5230 * We need to save the bits in the instruction since fixup_segment()
5231 * might be deleting the relocation entry (i.e., a branch within
5232 * the current segment).
5234 assert (fixP->fx_pcrel);
5236 as_warn ("Branch to odd address (%lx)", value);
5238 if ((value & ~0xFFFF) && (value & ~0xFFFF) != (-1 & ~0xFFFF))
5239 as_bad ("Relocation overflow");
5241 /* update old instruction data */
5242 buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal);
5246 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
5250 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
5257 insn |= value & 0xFFFF;
5258 md_number_to_chars ((char *) buf, (valueT) insn, 4);
5273 const struct mips_opcode *p;
5274 int treg, sreg, dreg, shamt;
5279 for (i = 0; i < NUMOPCODES; ++i)
5281 p = &mips_opcodes[i];
5282 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
5284 printf ("%08lx %s\t", oc, p->name);
5285 treg = (oc >> 16) & 0x1f;
5286 sreg = (oc >> 21) & 0x1f;
5287 dreg = (oc >> 11) & 0x1f;
5288 shamt = (oc >> 6) & 0x1f;
5290 for (args = p->args;; ++args)
5301 printf ("%c", *args);
5305 assert (treg == sreg);
5306 printf ("$%d,$%d", treg, sreg);
5311 printf ("$%d", dreg);
5316 printf ("$%d", treg);
5320 printf ("0x%x", treg);
5325 printf ("$%d", sreg);
5329 printf ("0x%08lx", oc & 0x1ffffff);
5341 printf ("$%d", shamt);
5352 printf ("%08lx UNDEFINED\n", oc);
5363 name = input_line_pointer;
5364 c = get_symbol_end ();
5365 p = (symbolS *) symbol_find_or_make (name);
5366 *input_line_pointer = c;
5370 /* Align the current frag to a given power of two. The MIPS assembler
5371 also automatically adjusts any preceding label. */
5374 mips_align (to, fill, label)
5379 mips_emit_delays ();
5380 frag_align (to, fill);
5381 record_alignment (now_seg, to);
5384 assert (S_GET_SEGMENT (label) == now_seg);
5385 label->sy_frag = frag_now;
5386 S_SET_VALUE (label, (valueT) frag_now_fix ());
5390 /* Align to a given power of two. .align 0 turns off the automatic
5391 alignment used by the data creating pseudo-ops. */
5398 register long temp_fill;
5399 long max_alignment = 15;
5403 o Note that the assembler pulls down any immediately preceeding label
5404 to the aligned address.
5405 o It's not documented but auto alignment is reinstated by
5406 a .align pseudo instruction.
5407 o Note also that after auto alignment is turned off the mips assembler
5408 issues an error on attempt to assemble an improperly aligned data item.
5413 temp = get_absolute_expression ();
5414 if (temp > max_alignment)
5415 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
5418 as_warn ("Alignment negative: 0 assumed.");
5421 if (*input_line_pointer == ',')
5423 input_line_pointer++;
5424 temp_fill = get_absolute_expression ();
5431 mips_align (temp, (int) temp_fill, insn_label);
5438 demand_empty_rest_of_line ();
5441 /* Handle .ascii and .asciiz. This just calls stringer and forgets
5442 that there was a previous instruction. */
5445 s_stringer (append_zero)
5448 mips_emit_delays ();
5450 stringer (append_zero);
5461 /* When generating embedded PIC code, we only use the .text, .lit8,
5462 .sdata and .sbss sections. We change the .data and .rdata
5463 pseudo-ops to use .sdata. */
5464 if (mips_pic == EMBEDDED_PIC
5465 && (sec == 'd' || sec == 'r'))
5468 mips_emit_delays ();
5478 subseg_set (bss_section, (subsegT) get_absolute_expression ());
5479 demand_empty_rest_of_line ();
5484 subseg_new (".rdata", (subsegT) get_absolute_expression ());
5485 demand_empty_rest_of_line ();
5487 #else /* ! defined (OBJ_ECOFF) */
5489 seg = subseg_new (".rodata", (subsegT) get_absolute_expression ());
5490 bfd_set_section_flags (stdoutput, seg,
5496 bfd_set_section_alignment (stdoutput, seg, 4);
5497 demand_empty_rest_of_line ();
5499 #else /* ! defined (OBJ_ELF) */
5502 #endif /* ! defined (OBJ_ELF) */
5503 #endif /* ! defined (OBJ_ECOFF) */
5507 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
5509 bfd_set_section_flags (stdoutput, seg,
5510 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
5511 bfd_set_section_alignment (stdoutput, seg, 4);
5513 demand_empty_rest_of_line ();
5515 #else /* ! defined (GPOPT) */
5516 as_bad ("Global pointers not supported; recompile -G 0");
5517 demand_empty_rest_of_line ();
5519 #endif /* ! defined (GPOPT) */
5532 mips_emit_delays ();
5533 if (log_size > 0 && auto_align)
5534 mips_align (log_size, 0, label);
5536 cons (1 << log_size);
5543 as_fatal ("Encountered `.err', aborting assembly");
5553 symbolP = get_symbol ();
5554 if (*input_line_pointer == ',')
5555 input_line_pointer++;
5556 size = get_absolute_expression ();
5557 S_SET_EXTERNAL (symbolP);
5559 #ifdef ECOFF_DEBUGGING
5560 symbolP->ecoff_extern_size = size;
5572 mips_emit_delays ();
5576 mips_align (3, 0, label);
5578 mips_align (2, 0, label);
5592 opt = input_line_pointer;
5593 c = get_symbol_end ();
5597 /* FIXME: What does this mean? */
5599 else if (strncmp (opt, "pic", 3) == 0)
5607 mips_pic = SVR4_PIC;
5609 as_bad (".option pic%d not supported", i);
5611 if (mips_pic == SVR4_PIC)
5613 if (g_switch_seen && g_switch_value != 0)
5614 as_warn ("-G may not be used with SVR4 PIC code");
5616 bfd_set_gp_size (stdoutput, 0);
5620 as_warn ("Unrecognized option \"%s\"", opt);
5622 *input_line_pointer = c;
5623 demand_empty_rest_of_line ();
5630 char *name = input_line_pointer, ch;
5632 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5633 input_line_pointer++;
5634 ch = *input_line_pointer;
5635 *input_line_pointer = '\0';
5637 if (strcmp (name, "reorder") == 0)
5641 prev_insn_unreordered = 1;
5642 prev_prev_insn_unreordered = 1;
5646 else if (strcmp (name, "noreorder") == 0)
5648 mips_emit_delays ();
5650 mips_any_noreorder = 1;
5652 else if (strcmp (name, "at") == 0)
5656 else if (strcmp (name, "noat") == 0)
5660 else if (strcmp (name, "macro") == 0)
5662 mips_warn_about_macros = 0;
5664 else if (strcmp (name, "nomacro") == 0)
5666 if (mips_noreorder == 0)
5667 as_bad ("`noreorder' must be set before `nomacro'");
5668 mips_warn_about_macros = 1;
5670 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
5674 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
5678 else if (strcmp (name, "bopt") == 0)
5682 else if (strcmp (name, "nobopt") == 0)
5686 else if (strncmp (name, "mips", 4) == 0)
5690 /* Permit the user to change the ISA on the fly. Needless to
5691 say, misuse can cause serious problems. */
5692 isa = atoi (name + 4);
5694 mips_isa = file_mips_isa;
5695 else if (isa < 1 || isa > 3)
5696 as_bad ("unknown ISA level");
5702 as_warn ("Tried to set unrecognized symbol: %s\n", name);
5704 *input_line_pointer = ch;
5705 demand_empty_rest_of_line ();
5708 /* The same as the usual .space directive, except that we have to
5709 forget about any previous instruction. */
5712 s_mips_space (param)
5715 mips_emit_delays ();
5720 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
5721 .option pic2. It means to generate SVR4 PIC calls. */
5727 mips_pic = SVR4_PIC;
5728 if (g_switch_seen && g_switch_value != 0)
5729 as_warn ("-G may not be used with SVR4 PIC code");
5731 bfd_set_gp_size (stdoutput, 0);
5732 demand_empty_rest_of_line ();
5735 /* Handle the .cpload pseudo-op. This is used when generating SVR4
5736 PIC code. It sets the $gp register for the function based on the
5737 function address, which is in the register named in the argument.
5738 This uses a relocation against _gp_disp, which is handled specially
5739 by the linker. The result is:
5740 lui $gp,%hi(_gp_disp)
5741 addiu $gp,$gp,%lo(_gp_disp)
5742 addu $gp,$gp,.cpload argument
5743 The .cpload argument is normally $25 == $t9. */
5752 /* If we are not generating SVR4 PIC code, .cpload is ignored. */
5753 if (mips_pic != SVR4_PIC)
5759 /* .cpload should be a in .set noreorder section. */
5760 if (mips_noreorder == 0)
5761 as_warn (".cpload not in noreorder section");
5764 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
5765 ex.X_op_symbol = NULL;
5766 ex.X_add_number = 0;
5768 macro_build_lui ((char *) NULL, &icnt, &ex, GP);
5769 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP,
5770 (int) BFD_RELOC_LO16);
5772 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
5773 GP, GP, tc_get_register (0));
5775 demand_empty_rest_of_line ();
5778 /* Handle the .cprestore pseudo-op. This stores $gp into a given
5779 offset from $sp. The offset is remembered, and after making a PIC
5780 call $gp is restored from that location. */
5783 s_cprestore (ignore)
5789 /* If we are not generating SVR4 PIC code, .cprestore is ignored. */
5790 if (mips_pic != SVR4_PIC)
5796 mips_cprestore_offset = get_absolute_expression ();
5798 ex.X_op = O_constant;
5799 ex.X_add_symbol = NULL;
5800 ex.X_op_symbol = NULL;
5801 ex.X_add_number = mips_cprestore_offset;
5803 macro_build ((char *) NULL, &icnt, &ex,
5804 mips_isa < 3 ? "sw" : "sd",
5805 "t,o(b)", GP, (int) BFD_RELOC_LO16, SP);
5807 demand_empty_rest_of_line ();
5810 /* Handle the .gpword pseudo-op. This is used when generating PIC
5811 code. It generates a 32 bit GP relative reloc. */
5821 /* When not generating PIC code, this is treated as .word. */
5822 if (mips_pic != SVR4_PIC)
5829 mips_emit_delays ();
5831 mips_align (2, 0, label);
5836 if (ex.X_op != O_symbol || ex.X_add_number != 0)
5838 as_bad ("Unsupported use of .gpword");
5839 ignore_rest_of_line ();
5843 md_number_to_chars (p, (valueT) 0, 4);
5844 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0,
5845 BFD_RELOC_MIPS_GPREL32);
5847 demand_empty_rest_of_line ();
5850 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
5851 tables in SVR4 PIC code. */
5860 /* This is ignored when not generating SVR4 PIC code. */
5861 if (mips_pic != SVR4_PIC)
5867 /* Add $gp to the register named as an argument. */
5868 reg = tc_get_register (0);
5869 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5870 mips_isa < 3 ? "addu" : "daddu",
5871 "d,v,t", reg, reg, GP);
5873 demand_empty_rest_of_line ();
5876 /* Parse a register string into a number. Called from the ECOFF code
5877 to parse .frame. The argument is non-zero if this is the frame
5878 register, so that we can record it in mips_frame_reg. */
5881 tc_get_register (frame)
5887 if (*input_line_pointer++ != '$')
5889 as_warn ("expected `$'");
5892 else if (isdigit ((unsigned char) *input_line_pointer))
5894 reg = get_absolute_expression ();
5895 if (reg < 0 || reg >= 32)
5897 as_warn ("Bad register number");
5903 if (strncmp (input_line_pointer, "fp", 2) == 0)
5905 else if (strncmp (input_line_pointer, "sp", 2) == 0)
5907 else if (strncmp (input_line_pointer, "gp", 2) == 0)
5909 else if (strncmp (input_line_pointer, "at", 2) == 0)
5913 as_warn ("Unrecognized register name");
5916 input_line_pointer += 2;
5919 mips_frame_reg = reg != 0 ? reg : SP;
5924 md_section_align (seg, addr)
5928 int align = bfd_get_section_alignment (stdoutput, seg);
5930 return ((addr + (1 << align) - 1) & (-1 << align));
5933 /* Estimate the size of a frag before relaxing. We are not really
5934 relaxing here, and the final size is encoded in the subtype
5939 md_estimate_size_before_relax (fragp, segtype)
5945 if (mips_pic == NO_PIC)
5948 const char *symname;
5950 /* Find out whether this symbol can be referenced off the GP
5951 register. It can be if it is smaller than the -G size or if
5952 it is in the .sdata or .sbss section. Certain symbols can
5953 not be referenced off the GP, although it appears as though
5955 symname = S_GET_NAME (fragp->fr_symbol);
5956 if (symname != (const char *) NULL
5957 && (strcmp (symname, "eprol") == 0
5958 || strcmp (symname, "etext") == 0
5959 || strcmp (symname, "_gp") == 0
5960 || strcmp (symname, "edata") == 0
5961 || strcmp (symname, "_fbss") == 0
5962 || strcmp (symname, "_fdata") == 0
5963 || strcmp (symname, "_ftext") == 0
5964 || strcmp (symname, "end") == 0
5965 || strcmp (symname, "_gp_disp") == 0))
5967 else if (! S_IS_DEFINED (fragp->fr_symbol)
5968 && ((fragp->fr_symbol->ecoff_extern_size != 0
5969 && fragp->fr_symbol->ecoff_extern_size <= g_switch_value)
5970 || (S_GET_VALUE (fragp->fr_symbol) != 0
5971 && S_GET_VALUE (fragp->fr_symbol) <= g_switch_value)))
5975 const char *segname;
5977 segname = segment_name (S_GET_SEGMENT (fragp->fr_symbol));
5978 assert (strcmp (segname, ".lit8") != 0
5979 && strcmp (segname, ".lit4") != 0);
5980 change = (strcmp (segname, ".sdata") != 0
5981 && strcmp (segname, ".sbss") != 0);
5983 #else /* ! defined (GPOPT) */
5984 /* We are not optimizing for the GP register. */
5986 #endif /* ! defined (GPOPT) */
5988 else if (mips_pic == SVR4_PIC)
5990 asection *symsec = fragp->fr_symbol->bsym->section;
5992 /* This must duplicate the test in adjust_reloc_syms. */
5993 change = (symsec != &bfd_und_section
5994 && symsec != &bfd_abs_section
5995 && ! bfd_is_com_section (symsec));
6002 /* Record the offset to the first reloc in the fr_opcode field.
6003 This lets md_convert_frag and tc_gen_reloc know that the code
6004 must be expanded. */
6005 fragp->fr_opcode = (fragp->fr_literal
6007 - RELAX_OLD (fragp->fr_subtype)
6008 + RELAX_RELOC1 (fragp->fr_subtype));
6009 /* FIXME: This really needs as_warn_where. */
6010 if (RELAX_WARN (fragp->fr_subtype))
6011 as_warn ("AT used after \".set noat\" or macro used after \".set nomacro\"");
6017 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
6020 /* Translate internal representation of relocation info to BFD target
6024 tc_gen_reloc (section, fixp)
6028 static arelent *retval[4];
6031 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
6034 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
6035 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
6037 if (mips_pic == EMBEDDED_PIC
6038 && SWITCH_TABLE (fixp))
6040 /* For a switch table entry we use a special reloc. The addend
6041 is actually the difference between the reloc address and the
6043 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
6045 as_fatal ("Double check fx_r_type in tc-mips.c:tc_gen_reloc");
6047 fixp->fx_r_type = BFD_RELOC_GPREL32;
6049 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
6051 /* We use a special addend for an internal RELLO reloc. */
6052 if (fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM)
6053 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
6055 reloc->addend = fixp->fx_addnumber + reloc->address;
6057 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
6059 assert (fixp->fx_next != NULL
6060 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
6061 /* We use a special addend for an internal RELHI reloc. The
6062 reloc is relative to the RELLO; adjust the addend
6064 if (fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM)
6065 reloc->addend = (fixp->fx_next->fx_frag->fr_address
6066 + fixp->fx_next->fx_where
6067 - S_GET_VALUE (fixp->fx_subsy));
6069 reloc->addend = (fixp->fx_addnumber
6070 + fixp->fx_next->fx_frag->fr_address
6071 + fixp->fx_next->fx_where);
6073 else if (fixp->fx_pcrel == 0)
6074 reloc->addend = fixp->fx_addnumber;
6078 /* A gruesome hack which is a result of the gruesome gas reloc
6080 reloc->addend = reloc->address;
6082 reloc->addend = -reloc->address;
6086 /* If this is a variant frag, we may need to adjust the existing
6087 reloc and generate a new one. */
6088 if (fixp->fx_frag->fr_opcode != NULL
6089 && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
6090 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
6091 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16))
6095 /* If this is not the last reloc in this frag, then we have two
6096 GPREL relocs, both of which are being replaced. Let the
6097 second one handle all of them. */
6098 if (fixp->fx_next != NULL
6099 && fixp->fx_frag == fixp->fx_next->fx_frag)
6101 assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL
6102 && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL);
6107 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
6108 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
6109 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
6111 reloc2->sym_ptr_ptr = &fixp->fx_addsy->bsym;
6112 reloc2->address = (reloc->address
6113 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
6114 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
6115 reloc2->addend = fixp->fx_addnumber;
6116 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
6117 assert (reloc2->howto != NULL);
6119 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
6123 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
6126 reloc3->address += 4;
6129 if (mips_pic == NO_PIC)
6131 assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL);
6132 fixp->fx_r_type = BFD_RELOC_HI16_S;
6134 else if (mips_pic == SVR4_PIC)
6136 if (fixp->fx_r_type != BFD_RELOC_MIPS_GOT16)
6138 assert (fixp->fx_r_type == BFD_RELOC_MIPS_CALL16);
6139 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
6146 /* To support a PC relative reloc when generating embedded PIC code
6147 for ECOFF, we use a Cygnus extension. We check for that here to
6148 make sure that we don't let such a reloc escape normally. */
6150 if (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2
6151 && mips_pic != EMBEDDED_PIC)
6152 reloc->howto = NULL;
6155 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
6157 if (reloc->howto == NULL)
6159 as_bad_where (fixp->fx_file, fixp->fx_line,
6160 "Can not represent relocation in this object file format");
6167 /* Convert a machine dependent frag. */
6170 md_convert_frag (abfd, asec, fragp)
6178 if (fragp->fr_opcode == NULL)
6181 old = RELAX_OLD (fragp->fr_subtype);
6182 new = RELAX_NEW (fragp->fr_subtype);
6183 fixptr = fragp->fr_literal + fragp->fr_fix;
6186 memcpy (fixptr - old, fixptr, new);
6188 fragp->fr_fix += new - old;
6191 /* This function is called whenever a label is defined. It is used
6192 when handling branch delays; if a branch has a label, we assume we
6196 mips_define_label (sym)
6204 /* Some special processing for a MIPS ELF file. */
6207 mips_elf_final_processing ()
6211 /* Write out the .reginfo section. */
6212 s.ri_gprmask = mips_gprmask;
6213 s.ri_cprmask[0] = mips_cprmask[0];
6214 s.ri_cprmask[1] = mips_cprmask[1];
6215 s.ri_cprmask[2] = mips_cprmask[2];
6216 s.ri_cprmask[3] = mips_cprmask[3];
6217 /* The gp_value field is set by the MIPS ELF backend. */
6219 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
6220 ((Elf32_External_RegInfo *)
6221 mips_regmask_frag));
6223 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
6224 sort of BFD interface for this. */
6225 if (mips_any_noreorder)
6226 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
6227 if (mips_pic != NO_PIC)
6228 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
6231 #endif /* OBJ_ELF */
6233 #ifndef ECOFF_DEBUGGING
6235 /* These functions should really be defined by the object file format,
6236 since they are related to debugging information. However, this
6237 code has to work for the a.out format, which does not define them,
6238 so we provide simple versions here. These don't actually generate
6239 any debugging information, but they do simple checking and someday
6240 somebody may make them useful. */
6244 struct loc *loc_next;
6245 unsigned long loc_fileno;
6246 unsigned long loc_lineno;
6247 unsigned long loc_offset;
6248 unsigned short loc_delta;
6249 unsigned short loc_count;
6258 struct proc *proc_next;
6259 struct symbol *proc_isym;
6260 struct symbol *proc_end;
6261 unsigned long proc_reg_mask;
6262 unsigned long proc_reg_offset;
6263 unsigned long proc_fpreg_mask;
6264 unsigned long proc_fpreg_offset;
6265 unsigned long proc_frameoffset;
6266 unsigned long proc_framereg;
6267 unsigned long proc_pcreg;
6269 struct file *proc_file;
6276 struct file *file_next;
6277 unsigned long file_fileno;
6278 struct symbol *file_symbol;
6279 struct symbol *file_end;
6280 struct proc *file_proc;
6285 static struct obstack proc_frags;
6286 static procS *proc_lastP;
6287 static procS *proc_rootP;
6288 static int numprocs;
6293 obstack_begin (&proc_frags, 0x2000);
6299 /* check for premature end, nesting errors, etc */
6300 if (proc_lastP && proc_lastP->proc_end == NULL)
6301 as_warn ("missing `.end' at end of assembly");
6304 extern char hex_value[];
6312 if (*input_line_pointer == '-')
6314 ++input_line_pointer;
6317 if (!isdigit (*input_line_pointer))
6318 as_bad ("Expected simple number.");
6319 if (input_line_pointer[0] == '0')
6321 if (input_line_pointer[1] == 'x')
6323 input_line_pointer += 2;
6324 while (isxdigit (*input_line_pointer))
6327 val |= hex_value[(int) *input_line_pointer++];
6329 return negative ? -val : val;
6333 ++input_line_pointer;
6334 while (isdigit (*input_line_pointer))
6337 val |= *input_line_pointer++ - '0';
6339 return negative ? -val : val;
6342 if (!isdigit (*input_line_pointer))
6344 printf (" *input_line_pointer == '%c' 0x%02x\n",
6345 *input_line_pointer, *input_line_pointer);
6346 as_warn ("Invalid number");
6349 while (isdigit (*input_line_pointer))
6352 val += *input_line_pointer++ - '0';
6354 return negative ? -val : val;
6357 /* The .file directive; just like the usual .file directive, but there
6358 is an initial number which is the ECOFF file index. */
6366 line = get_number ();
6371 /* The .end directive. */
6379 if (!is_end_of_line[(unsigned char) *input_line_pointer])
6382 demand_empty_rest_of_line ();
6386 if (now_seg != text_section)
6387 as_warn (".end not in text section");
6390 as_warn (".end and no .ent seen yet.");
6396 assert (S_GET_NAME (p));
6397 if (strcmp (S_GET_NAME (p), S_GET_NAME (proc_lastP->proc_isym)))
6398 as_warn (".end symbol does not match .ent symbol.");
6401 proc_lastP->proc_end = (symbolS *) 1;
6404 /* The .aent and .ent directives. */
6414 symbolP = get_symbol ();
6415 if (*input_line_pointer == ',')
6416 input_line_pointer++;
6418 if (isdigit (*input_line_pointer) || *input_line_pointer == '-')
6419 number = get_number ();
6420 if (now_seg != text_section)
6421 as_warn (".ent or .aent not in text section.");
6423 if (!aent && proc_lastP && proc_lastP->proc_end == NULL)
6424 as_warn ("missing `.end'");
6428 procP = (procS *) obstack_alloc (&proc_frags, sizeof (*procP));
6429 procP->proc_isym = symbolP;
6430 procP->proc_reg_mask = 0;
6431 procP->proc_reg_offset = 0;
6432 procP->proc_fpreg_mask = 0;
6433 procP->proc_fpreg_offset = 0;
6434 procP->proc_frameoffset = 0;
6435 procP->proc_framereg = 0;
6436 procP->proc_pcreg = 0;
6437 procP->proc_end = NULL;
6438 procP->proc_next = NULL;
6440 proc_lastP->proc_next = procP;
6446 demand_empty_rest_of_line ();
6449 /* The .frame directive. */
6462 frame_reg = tc_get_register (1);
6463 if (*input_line_pointer == ',')
6464 input_line_pointer++;
6465 frame_off = get_absolute_expression ();
6466 if (*input_line_pointer == ',')
6467 input_line_pointer++;
6468 pcreg = tc_get_register (0);
6471 assert (proc_rootP);
6472 proc_rootP->proc_framereg = frame_reg;
6473 proc_rootP->proc_frameoffset = frame_off;
6474 proc_rootP->proc_pcreg = pcreg;
6475 /* bob macho .frame */
6477 /* We don't have to write out a frame stab for unoptimized code. */
6478 if (!(frame_reg == FP && frame_off == 0))
6481 as_warn ("No .ent for .frame to use.");
6482 (void) sprintf (str, "R%d;%d", frame_reg, frame_off);
6483 symP = symbol_new (str, N_VFP, 0, frag_now);
6484 S_SET_TYPE (symP, N_RMASK);
6485 S_SET_OTHER (symP, 0);
6486 S_SET_DESC (symP, 0);
6487 symP->sy_forward = proc_lastP->proc_isym;
6488 /* bob perhaps I should have used pseudo set */
6490 demand_empty_rest_of_line ();
6494 /* The .fmask and .mask directives. */
6501 char str[100], *strP;
6507 mask = get_number ();
6508 if (*input_line_pointer == ',')
6509 input_line_pointer++;
6510 off = get_absolute_expression ();
6512 /* bob only for coff */
6513 assert (proc_rootP);
6514 if (reg_type == 'F')
6516 proc_rootP->proc_fpreg_mask = mask;
6517 proc_rootP->proc_fpreg_offset = off;
6521 proc_rootP->proc_reg_mask = mask;
6522 proc_rootP->proc_reg_offset = off;
6525 /* bob macho .mask + .fmask */
6527 /* We don't have to write out a mask stab if no saved regs. */
6531 as_warn ("No .ent for .mask to use.");
6533 for (i = 0; i < 32; i++)
6537 sprintf (strP, "%c%d,", reg_type, i);
6538 strP += strlen (strP);
6542 sprintf (strP, ";%d,", off);
6543 symP = symbol_new (str, N_RMASK, 0, frag_now);
6544 S_SET_TYPE (symP, N_RMASK);
6545 S_SET_OTHER (symP, 0);
6546 S_SET_DESC (symP, 0);
6547 symP->sy_forward = proc_lastP->proc_isym;
6548 /* bob perhaps I should have used pseudo set */
6553 /* The .loc directive. */
6564 assert (now_seg == text_section);
6566 lineno = get_number ();
6567 addroff = obstack_next_free (&frags) - frag_now->fr_literal;
6569 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
6570 S_SET_TYPE (symbolP, N_SLINE);
6571 S_SET_OTHER (symbolP, 0);
6572 S_SET_DESC (symbolP, lineno);
6573 symbolP->sy_segment = now_seg;
6577 #endif /* ! defined (ECOFF_DEBUGGING) */