Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-mips.c -- assemble code for a MIPS chip. |
49309057 | 2 | Copyright (C) 1993, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc. |
252b5132 RH |
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 | |
6 | Support. | |
7 | ||
8 | This file is part of GAS. | |
9 | ||
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) | |
13 | any later version. | |
14 | ||
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. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GAS; see the file COPYING. If not, write to the Free | |
22 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
23 | 02111-1307, USA. */ | |
24 | ||
25 | #include "as.h" | |
26 | #include "config.h" | |
27 | #include "subsegs.h" | |
28 | ||
29 | #include <ctype.h> | |
30 | ||
31 | #ifdef USE_STDARG | |
32 | #include <stdarg.h> | |
33 | #endif | |
34 | #ifdef USE_VARARGS | |
35 | #include <varargs.h> | |
36 | #endif | |
37 | ||
38 | #include "opcode/mips.h" | |
39 | #include "itbl-ops.h" | |
40 | ||
41 | #ifdef DEBUG | |
42 | #define DBG(x) printf x | |
43 | #else | |
44 | #define DBG(x) | |
45 | #endif | |
46 | ||
47 | #ifdef OBJ_MAYBE_ELF | |
48 | /* Clean up namespace so we can include obj-elf.h too. */ | |
49 | static int mips_output_flavor PARAMS ((void)); | |
50 | static int mips_output_flavor () { return OUTPUT_FLAVOR; } | |
51 | #undef OBJ_PROCESS_STAB | |
52 | #undef OUTPUT_FLAVOR | |
53 | #undef S_GET_ALIGN | |
54 | #undef S_GET_SIZE | |
55 | #undef S_SET_ALIGN | |
56 | #undef S_SET_SIZE | |
252b5132 RH |
57 | #undef obj_frob_file |
58 | #undef obj_frob_file_after_relocs | |
59 | #undef obj_frob_symbol | |
60 | #undef obj_pop_insert | |
61 | #undef obj_sec_sym_ok_for_reloc | |
62 | #undef OBJ_COPY_SYMBOL_ATTRIBUTES | |
63 | ||
64 | #include "obj-elf.h" | |
65 | /* Fix any of them that we actually care about. */ | |
66 | #undef OUTPUT_FLAVOR | |
67 | #define OUTPUT_FLAVOR mips_output_flavor() | |
68 | #endif | |
69 | ||
70 | #if defined (OBJ_ELF) | |
71 | #include "elf/mips.h" | |
72 | #endif | |
73 | ||
74 | #ifndef ECOFF_DEBUGGING | |
75 | #define NO_ECOFF_DEBUGGING | |
76 | #define ECOFF_DEBUGGING 0 | |
77 | #endif | |
78 | ||
79 | #include "ecoff.h" | |
80 | ||
81 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
82 | static char *mips_regmask_frag; | |
83 | #endif | |
84 | ||
85 | #define AT 1 | |
86 | #define TREG 24 | |
87 | #define PIC_CALL_REG 25 | |
88 | #define KT0 26 | |
89 | #define KT1 27 | |
90 | #define GP 28 | |
91 | #define SP 29 | |
92 | #define FP 30 | |
93 | #define RA 31 | |
94 | ||
95 | #define ILLEGAL_REG (32) | |
96 | ||
97 | /* Allow override of standard little-endian ECOFF format. */ | |
98 | ||
99 | #ifndef ECOFF_LITTLE_FORMAT | |
100 | #define ECOFF_LITTLE_FORMAT "ecoff-littlemips" | |
101 | #endif | |
102 | ||
103 | extern int target_big_endian; | |
104 | ||
105 | /* 1 is we should use the 64 bit MIPS ELF ABI, 0 if we should use the | |
106 | 32 bit ABI. This has no meaning for ECOFF. | |
107 | Note that the default is always 32 bit, even if "configured" for | |
108 | 64 bit [e.g. --target=mips64-elf]. */ | |
109 | static int mips_64; | |
110 | ||
111 | /* The default target format to use. */ | |
112 | const char * | |
113 | mips_target_format () | |
114 | { | |
115 | switch (OUTPUT_FLAVOR) | |
116 | { | |
117 | case bfd_target_aout_flavour: | |
118 | return target_big_endian ? "a.out-mips-big" : "a.out-mips-little"; | |
119 | case bfd_target_ecoff_flavour: | |
120 | return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT; | |
121 | case bfd_target_elf_flavour: | |
122 | return (target_big_endian | |
123 | ? (mips_64 ? "elf64-bigmips" : "elf32-bigmips") | |
124 | : (mips_64 ? "elf64-littlemips" : "elf32-littlemips")); | |
125 | default: | |
126 | abort (); | |
127 | return NULL; | |
128 | } | |
129 | } | |
130 | ||
131 | /* The name of the readonly data section. */ | |
132 | #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \ | |
133 | ? ".data" \ | |
134 | : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \ | |
135 | ? ".rdata" \ | |
136 | : OUTPUT_FLAVOR == bfd_target_elf_flavour \ | |
137 | ? ".rodata" \ | |
138 | : (abort (), "")) | |
139 | ||
140 | /* This is the set of options which may be modified by the .set | |
141 | pseudo-op. We use a struct so that .set push and .set pop are more | |
142 | reliable. */ | |
143 | ||
144 | struct mips_set_options | |
145 | { | |
146 | /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 | |
147 | if it has not been initialized. Changed by `.set mipsN', and the | |
148 | -mipsN command line option, and the default CPU. */ | |
149 | int isa; | |
150 | /* Whether we are assembling for the mips16 processor. 0 if we are | |
151 | not, 1 if we are, and -1 if the value has not been initialized. | |
152 | Changed by `.set mips16' and `.set nomips16', and the -mips16 and | |
153 | -nomips16 command line options, and the default CPU. */ | |
154 | int mips16; | |
155 | /* Non-zero if we should not reorder instructions. Changed by `.set | |
156 | reorder' and `.set noreorder'. */ | |
157 | int noreorder; | |
158 | /* Non-zero if we should not permit the $at ($1) register to be used | |
159 | in instructions. Changed by `.set at' and `.set noat'. */ | |
160 | int noat; | |
161 | /* Non-zero if we should warn when a macro instruction expands into | |
162 | more than one machine instruction. Changed by `.set nomacro' and | |
163 | `.set macro'. */ | |
164 | int warn_about_macros; | |
165 | /* Non-zero if we should not move instructions. Changed by `.set | |
166 | move', `.set volatile', `.set nomove', and `.set novolatile'. */ | |
167 | int nomove; | |
168 | /* Non-zero if we should not optimize branches by moving the target | |
169 | of the branch into the delay slot. Actually, we don't perform | |
170 | this optimization anyhow. Changed by `.set bopt' and `.set | |
171 | nobopt'. */ | |
172 | int nobopt; | |
173 | /* Non-zero if we should not autoextend mips16 instructions. | |
174 | Changed by `.set autoextend' and `.set noautoextend'. */ | |
175 | int noautoextend; | |
176 | }; | |
177 | ||
178 | /* This is the struct we use to hold the current set of options. Note | |
179 | that we must set the isa and mips16 fields to -1 to indicate that | |
180 | they have not been initialized. */ | |
181 | ||
182 | static struct mips_set_options mips_opts = { -1, -1 }; | |
183 | ||
184 | /* These variables are filled in with the masks of registers used. | |
185 | The object format code reads them and puts them in the appropriate | |
186 | place. */ | |
187 | unsigned long mips_gprmask; | |
188 | unsigned long mips_cprmask[4]; | |
189 | ||
190 | /* MIPS ISA we are using for this output file. */ | |
191 | static int file_mips_isa; | |
192 | ||
193 | /* The CPU type as a number: 2000, 3000, 4000, 4400, etc. */ | |
194 | static int mips_cpu = -1; | |
195 | ||
196 | /* The argument of the -mabi= flag. */ | |
197 | static char* mips_abi_string = 0; | |
198 | ||
199 | /* Wether we should mark the file EABI64 or EABI32. */ | |
200 | static int mips_eabi64 = 0; | |
201 | ||
202 | /* If they asked for mips1 or mips2 and a cpu that is | |
203 | mips3 or greater, then mark the object file 32BITMODE. */ | |
204 | static int mips_32bitmode = 0; | |
205 | ||
206 | /* Whether the processor uses hardware interlocks to protect | |
207 | reads from the HI and LO registers, and thus does not | |
208 | require nops to be inserted. | |
209 | ||
210 | FIXME: GCC makes a distinction between -mcpu=FOO and -mFOO: | |
211 | -mcpu=FOO schedules for FOO, but still produces code that meets the | |
212 | requirements of MIPS ISA I. For example, it won't generate any | |
213 | FOO-specific instructions, and it will still assume that any | |
214 | scheduling hazards described in MIPS ISA I are there, even if FOO | |
215 | has interlocks. -mFOO gives GCC permission to generate code that | |
216 | will only run on a FOO; it will generate FOO-specific instructions, | |
217 | and assume interlocks provided by a FOO. | |
218 | ||
219 | However, GAS currently doesn't make this distinction; before Jan 28 | |
220 | 1999, GAS's -mcpu=FOO implied -mFOO, which violates GCC's | |
221 | assumptions. The GCC driver passes these flags through to GAS, so | |
222 | if GAS actually does anything that doesn't meet MIPS ISA I with | |
223 | -mFOO, then GCC's -mcpu=FOO flag isn't going to work. | |
224 | ||
225 | And furthermore, it did not assume that -mFOO implied -mcpu=FOO, | |
226 | which seems senseless --- why generate code which will only run on | |
227 | a FOO, but schedule for something else? | |
228 | ||
229 | So now, at least, -mcpu=FOO and -mFOO are exactly equivalent. | |
230 | ||
231 | -- Jim Blandy <jimb@cygnus.com> */ | |
232 | ||
233 | #define hilo_interlocks (mips_cpu == 4010 \ | |
234 | ) | |
235 | ||
236 | /* Whether the processor uses hardware interlocks to protect reads | |
237 | from the GPRs, and thus does not require nops to be inserted. */ | |
238 | #define gpr_interlocks \ | |
239 | (mips_opts.isa >= 2 \ | |
240 | || mips_cpu == 3900) | |
241 | ||
242 | /* As with other "interlocks" this is used by hardware that has FP | |
243 | (co-processor) interlocks. */ | |
244 | /* Itbl support may require additional care here. */ | |
245 | #define cop_interlocks (mips_cpu == 4300 \ | |
246 | ) | |
247 | ||
248 | /* MIPS PIC level. */ | |
249 | ||
250 | enum mips_pic_level | |
251 | { | |
252 | /* Do not generate PIC code. */ | |
253 | NO_PIC, | |
254 | ||
255 | /* Generate PIC code as in Irix 4. This is not implemented, and I'm | |
256 | not sure what it is supposed to do. */ | |
257 | IRIX4_PIC, | |
258 | ||
259 | /* Generate PIC code as in the SVR4 MIPS ABI. */ | |
260 | SVR4_PIC, | |
261 | ||
262 | /* Generate PIC code without using a global offset table: the data | |
263 | segment has a maximum size of 64K, all data references are off | |
264 | the $gp register, and all text references are PC relative. This | |
265 | is used on some embedded systems. */ | |
266 | EMBEDDED_PIC | |
267 | }; | |
268 | ||
269 | static enum mips_pic_level mips_pic; | |
270 | ||
271 | /* 1 if we should generate 32 bit offsets from the GP register in | |
272 | SVR4_PIC mode. Currently has no meaning in other modes. */ | |
273 | static int mips_big_got; | |
274 | ||
275 | /* 1 if trap instructions should used for overflow rather than break | |
276 | instructions. */ | |
277 | static int mips_trap; | |
278 | ||
279 | /* Non-zero if any .set noreorder directives were used. */ | |
280 | ||
281 | static int mips_any_noreorder; | |
282 | ||
283 | /* The size of the small data section. */ | |
284 | static int g_switch_value = 8; | |
285 | /* Whether the -G option was used. */ | |
286 | static int g_switch_seen = 0; | |
287 | ||
288 | #define N_RMASK 0xc4 | |
289 | #define N_VFP 0xd4 | |
290 | ||
291 | /* If we can determine in advance that GP optimization won't be | |
292 | possible, we can skip the relaxation stuff that tries to produce | |
293 | GP-relative references. This makes delay slot optimization work | |
294 | better. | |
295 | ||
296 | This function can only provide a guess, but it seems to work for | |
297 | gcc output. If it guesses wrong, the only loss should be in | |
298 | efficiency; it shouldn't introduce any bugs. | |
299 | ||
300 | I don't know if a fix is needed for the SVR4_PIC mode. I've only | |
301 | fixed it for the non-PIC mode. KR 95/04/07 */ | |
302 | static int nopic_need_relax PARAMS ((symbolS *, int)); | |
303 | ||
304 | /* handle of the OPCODE hash table */ | |
305 | static struct hash_control *op_hash = NULL; | |
306 | ||
307 | /* The opcode hash table we use for the mips16. */ | |
308 | static struct hash_control *mips16_op_hash = NULL; | |
309 | ||
310 | /* This array holds the chars that always start a comment. If the | |
311 | pre-processor is disabled, these aren't very useful */ | |
312 | const char comment_chars[] = "#"; | |
313 | ||
314 | /* This array holds the chars that only start a comment at the beginning of | |
315 | a line. If the line seems to have the form '# 123 filename' | |
316 | .line and .file directives will appear in the pre-processed output */ | |
317 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
318 | first line of the input file. This is because the compiler outputs | |
319 | #NO_APP at the beginning of its output. */ | |
320 | /* Also note that C style comments are always supported. */ | |
321 | const char line_comment_chars[] = "#"; | |
322 | ||
323 | /* This array holds machine specific line separator characters. */ | |
324 | const char line_separator_chars[] = ""; | |
325 | ||
326 | /* Chars that can be used to separate mant from exp in floating point nums */ | |
327 | const char EXP_CHARS[] = "eE"; | |
328 | ||
329 | /* Chars that mean this number is a floating point constant */ | |
330 | /* As in 0f12.456 */ | |
331 | /* or 0d1.2345e12 */ | |
332 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
333 | ||
334 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
335 | changed in read.c . Ideally it shouldn't have to know about it at all, | |
336 | but nothing is ideal around here. | |
337 | */ | |
338 | ||
339 | static char *insn_error; | |
340 | ||
341 | static int auto_align = 1; | |
342 | ||
343 | /* When outputting SVR4 PIC code, the assembler needs to know the | |
344 | offset in the stack frame from which to restore the $gp register. | |
345 | This is set by the .cprestore pseudo-op, and saved in this | |
346 | variable. */ | |
347 | static offsetT mips_cprestore_offset = -1; | |
348 | ||
349 | /* This is the register which holds the stack frame, as set by the | |
350 | .frame pseudo-op. This is needed to implement .cprestore. */ | |
351 | static int mips_frame_reg = SP; | |
352 | ||
353 | /* To output NOP instructions correctly, we need to keep information | |
354 | about the previous two instructions. */ | |
355 | ||
356 | /* Whether we are optimizing. The default value of 2 means to remove | |
357 | unneeded NOPs and swap branch instructions when possible. A value | |
358 | of 1 means to not swap branches. A value of 0 means to always | |
359 | insert NOPs. */ | |
360 | static int mips_optimize = 2; | |
361 | ||
362 | /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is | |
363 | equivalent to seeing no -g option at all. */ | |
364 | static int mips_debug = 0; | |
365 | ||
366 | /* The previous instruction. */ | |
367 | static struct mips_cl_insn prev_insn; | |
368 | ||
369 | /* The instruction before prev_insn. */ | |
370 | static struct mips_cl_insn prev_prev_insn; | |
371 | ||
372 | /* If we don't want information for prev_insn or prev_prev_insn, we | |
373 | point the insn_mo field at this dummy integer. */ | |
374 | static const struct mips_opcode dummy_opcode = { 0 }; | |
375 | ||
376 | /* Non-zero if prev_insn is valid. */ | |
377 | static int prev_insn_valid; | |
378 | ||
379 | /* The frag for the previous instruction. */ | |
380 | static struct frag *prev_insn_frag; | |
381 | ||
382 | /* The offset into prev_insn_frag for the previous instruction. */ | |
383 | static long prev_insn_where; | |
384 | ||
385 | /* The reloc type for the previous instruction, if any. */ | |
386 | static bfd_reloc_code_real_type prev_insn_reloc_type; | |
387 | ||
388 | /* The reloc for the previous instruction, if any. */ | |
389 | static fixS *prev_insn_fixp; | |
390 | ||
391 | /* Non-zero if the previous instruction was in a delay slot. */ | |
392 | static int prev_insn_is_delay_slot; | |
393 | ||
394 | /* Non-zero if the previous instruction was in a .set noreorder. */ | |
395 | static int prev_insn_unreordered; | |
396 | ||
397 | /* Non-zero if the previous instruction uses an extend opcode (if | |
398 | mips16). */ | |
399 | static int prev_insn_extended; | |
400 | ||
401 | /* Non-zero if the previous previous instruction was in a .set | |
402 | noreorder. */ | |
403 | static int prev_prev_insn_unreordered; | |
404 | ||
405 | /* If this is set, it points to a frag holding nop instructions which | |
406 | were inserted before the start of a noreorder section. If those | |
407 | nops turn out to be unnecessary, the size of the frag can be | |
408 | decreased. */ | |
409 | static fragS *prev_nop_frag; | |
410 | ||
411 | /* The number of nop instructions we created in prev_nop_frag. */ | |
412 | static int prev_nop_frag_holds; | |
413 | ||
414 | /* The number of nop instructions that we know we need in | |
415 | prev_nop_frag. */ | |
416 | static int prev_nop_frag_required; | |
417 | ||
418 | /* The number of instructions we've seen since prev_nop_frag. */ | |
419 | static int prev_nop_frag_since; | |
420 | ||
421 | /* For ECOFF and ELF, relocations against symbols are done in two | |
422 | parts, with a HI relocation and a LO relocation. Each relocation | |
423 | has only 16 bits of space to store an addend. This means that in | |
424 | order for the linker to handle carries correctly, it must be able | |
425 | to locate both the HI and the LO relocation. This means that the | |
426 | relocations must appear in order in the relocation table. | |
427 | ||
428 | In order to implement this, we keep track of each unmatched HI | |
429 | relocation. We then sort them so that they immediately precede the | |
430 | corresponding LO relocation. */ | |
431 | ||
432 | struct mips_hi_fixup | |
433 | { | |
434 | /* Next HI fixup. */ | |
435 | struct mips_hi_fixup *next; | |
436 | /* This fixup. */ | |
437 | fixS *fixp; | |
438 | /* The section this fixup is in. */ | |
439 | segT seg; | |
440 | }; | |
441 | ||
442 | /* The list of unmatched HI relocs. */ | |
443 | ||
444 | static struct mips_hi_fixup *mips_hi_fixup_list; | |
445 | ||
446 | /* Map normal MIPS register numbers to mips16 register numbers. */ | |
447 | ||
448 | #define X ILLEGAL_REG | |
449 | static const int mips32_to_16_reg_map[] = | |
450 | { | |
451 | X, X, 2, 3, 4, 5, 6, 7, | |
452 | X, X, X, X, X, X, X, X, | |
453 | 0, 1, X, X, X, X, X, X, | |
454 | X, X, X, X, X, X, X, X | |
455 | }; | |
456 | #undef X | |
457 | ||
458 | /* Map mips16 register numbers to normal MIPS register numbers. */ | |
459 | ||
460 | static const int mips16_to_32_reg_map[] = | |
461 | { | |
462 | 16, 17, 2, 3, 4, 5, 6, 7 | |
463 | }; | |
464 | \f | |
465 | /* Since the MIPS does not have multiple forms of PC relative | |
466 | instructions, we do not have to do relaxing as is done on other | |
467 | platforms. However, we do have to handle GP relative addressing | |
468 | correctly, which turns out to be a similar problem. | |
469 | ||
470 | Every macro that refers to a symbol can occur in (at least) two | |
471 | forms, one with GP relative addressing and one without. For | |
472 | example, loading a global variable into a register generally uses | |
473 | a macro instruction like this: | |
474 | lw $4,i | |
475 | If i can be addressed off the GP register (this is true if it is in | |
476 | the .sbss or .sdata section, or if it is known to be smaller than | |
477 | the -G argument) this will generate the following instruction: | |
478 | lw $4,i($gp) | |
479 | This instruction will use a GPREL reloc. If i can not be addressed | |
480 | off the GP register, the following instruction sequence will be used: | |
481 | lui $at,i | |
482 | lw $4,i($at) | |
483 | In this case the first instruction will have a HI16 reloc, and the | |
484 | second reloc will have a LO16 reloc. Both relocs will be against | |
485 | the symbol i. | |
486 | ||
487 | The issue here is that we may not know whether i is GP addressable | |
488 | until after we see the instruction that uses it. Therefore, we | |
489 | want to be able to choose the final instruction sequence only at | |
490 | the end of the assembly. This is similar to the way other | |
491 | platforms choose the size of a PC relative instruction only at the | |
492 | end of assembly. | |
493 | ||
494 | When generating position independent code we do not use GP | |
495 | addressing in quite the same way, but the issue still arises as | |
496 | external symbols and local symbols must be handled differently. | |
497 | ||
498 | We handle these issues by actually generating both possible | |
499 | instruction sequences. The longer one is put in a frag_var with | |
500 | type rs_machine_dependent. We encode what to do with the frag in | |
501 | the subtype field. We encode (1) the number of existing bytes to | |
502 | replace, (2) the number of new bytes to use, (3) the offset from | |
503 | the start of the existing bytes to the first reloc we must generate | |
504 | (that is, the offset is applied from the start of the existing | |
505 | bytes after they are replaced by the new bytes, if any), (4) the | |
506 | offset from the start of the existing bytes to the second reloc, | |
507 | (5) whether a third reloc is needed (the third reloc is always four | |
508 | bytes after the second reloc), and (6) whether to warn if this | |
509 | variant is used (this is sometimes needed if .set nomacro or .set | |
510 | noat is in effect). All these numbers are reasonably small. | |
511 | ||
512 | Generating two instruction sequences must be handled carefully to | |
513 | ensure that delay slots are handled correctly. Fortunately, there | |
514 | are a limited number of cases. When the second instruction | |
515 | sequence is generated, append_insn is directed to maintain the | |
516 | existing delay slot information, so it continues to apply to any | |
517 | code after the second instruction sequence. This means that the | |
518 | second instruction sequence must not impose any requirements not | |
519 | required by the first instruction sequence. | |
520 | ||
521 | These variant frags are then handled in functions called by the | |
522 | machine independent code. md_estimate_size_before_relax returns | |
523 | the final size of the frag. md_convert_frag sets up the final form | |
524 | of the frag. tc_gen_reloc adjust the first reloc and adds a second | |
525 | one if needed. */ | |
526 | #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \ | |
527 | ((relax_substateT) \ | |
528 | (((old) << 23) \ | |
529 | | ((new) << 16) \ | |
530 | | (((reloc1) + 64) << 9) \ | |
531 | | (((reloc2) + 64) << 2) \ | |
532 | | ((reloc3) ? (1 << 1) : 0) \ | |
533 | | ((warn) ? 1 : 0))) | |
534 | #define RELAX_OLD(i) (((i) >> 23) & 0x7f) | |
535 | #define RELAX_NEW(i) (((i) >> 16) & 0x7f) | |
536 | #define RELAX_RELOC1(i) ((bfd_vma)(((i) >> 9) & 0x7f) - 64) | |
537 | #define RELAX_RELOC2(i) ((bfd_vma)(((i) >> 2) & 0x7f) - 64) | |
538 | #define RELAX_RELOC3(i) (((i) >> 1) & 1) | |
539 | #define RELAX_WARN(i) ((i) & 1) | |
540 | ||
541 | /* For mips16 code, we use an entirely different form of relaxation. | |
542 | mips16 supports two versions of most instructions which take | |
543 | immediate values: a small one which takes some small value, and a | |
544 | larger one which takes a 16 bit value. Since branches also follow | |
545 | this pattern, relaxing these values is required. | |
546 | ||
547 | We can assemble both mips16 and normal MIPS code in a single | |
548 | object. Therefore, we need to support this type of relaxation at | |
549 | the same time that we support the relaxation described above. We | |
550 | use the high bit of the subtype field to distinguish these cases. | |
551 | ||
552 | The information we store for this type of relaxation is the | |
553 | argument code found in the opcode file for this relocation, whether | |
554 | the user explicitly requested a small or extended form, and whether | |
555 | the relocation is in a jump or jal delay slot. That tells us the | |
556 | size of the value, and how it should be stored. We also store | |
557 | whether the fragment is considered to be extended or not. We also | |
558 | store whether this is known to be a branch to a different section, | |
559 | whether we have tried to relax this frag yet, and whether we have | |
560 | ever extended a PC relative fragment because of a shift count. */ | |
561 | #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \ | |
562 | (0x80000000 \ | |
563 | | ((type) & 0xff) \ | |
564 | | ((small) ? 0x100 : 0) \ | |
565 | | ((ext) ? 0x200 : 0) \ | |
566 | | ((dslot) ? 0x400 : 0) \ | |
567 | | ((jal_dslot) ? 0x800 : 0)) | |
568 | #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0) | |
569 | #define RELAX_MIPS16_TYPE(i) ((i) & 0xff) | |
570 | #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0) | |
571 | #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0) | |
572 | #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0) | |
573 | #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0) | |
574 | #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0) | |
575 | #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000) | |
576 | #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000) | |
577 | #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0) | |
578 | #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000) | |
579 | #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000) | |
580 | \f | |
581 | /* Prototypes for static functions. */ | |
582 | ||
583 | #ifdef __STDC__ | |
584 | #define internalError() \ | |
585 | as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__) | |
586 | #else | |
587 | #define internalError() as_fatal (_("MIPS internal Error")); | |
588 | #endif | |
589 | ||
590 | enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG }; | |
591 | ||
592 | static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip, | |
593 | unsigned int reg, enum mips_regclass class)); | |
594 | static int reg_needs_delay PARAMS ((int)); | |
595 | static void mips16_mark_labels PARAMS ((void)); | |
596 | static void append_insn PARAMS ((char *place, | |
597 | struct mips_cl_insn * ip, | |
598 | expressionS * p, | |
599 | bfd_reloc_code_real_type r, | |
600 | boolean)); | |
601 | static void mips_no_prev_insn PARAMS ((int)); | |
602 | static void mips_emit_delays PARAMS ((boolean)); | |
603 | #ifdef USE_STDARG | |
604 | static void macro_build PARAMS ((char *place, int *counter, expressionS * ep, | |
605 | const char *name, const char *fmt, | |
606 | ...)); | |
607 | #else | |
608 | static void macro_build (); | |
609 | #endif | |
610 | static void mips16_macro_build PARAMS ((char *, int *, expressionS *, | |
611 | const char *, const char *, | |
612 | va_list)); | |
613 | static void macro_build_lui PARAMS ((char *place, int *counter, | |
614 | expressionS * ep, int regnum)); | |
615 | static void set_at PARAMS ((int *counter, int reg, int unsignedp)); | |
616 | static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip, | |
617 | expressionS *)); | |
618 | static void load_register PARAMS ((int *, int, expressionS *, int)); | |
619 | static void load_address PARAMS ((int *counter, int reg, expressionS *ep)); | |
620 | static void macro PARAMS ((struct mips_cl_insn * ip)); | |
621 | static void mips16_macro PARAMS ((struct mips_cl_insn * ip)); | |
622 | #ifdef LOSING_COMPILER | |
623 | static void macro2 PARAMS ((struct mips_cl_insn * ip)); | |
624 | #endif | |
625 | static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
626 | static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
627 | static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean, | |
628 | boolean, boolean, unsigned long *, | |
629 | boolean *, unsigned short *)); | |
630 | static int my_getSmallExpression PARAMS ((expressionS * ep, char *str)); | |
631 | static void my_getExpression PARAMS ((expressionS * ep, char *str)); | |
632 | static symbolS *get_symbol PARAMS ((void)); | |
633 | static void mips_align PARAMS ((int to, int fill, symbolS *label)); | |
634 | static void s_align PARAMS ((int)); | |
635 | static void s_change_sec PARAMS ((int)); | |
636 | static void s_cons PARAMS ((int)); | |
637 | static void s_float_cons PARAMS ((int)); | |
638 | static void s_mips_globl PARAMS ((int)); | |
639 | static void s_option PARAMS ((int)); | |
640 | static void s_mipsset PARAMS ((int)); | |
641 | static void s_abicalls PARAMS ((int)); | |
642 | static void s_cpload PARAMS ((int)); | |
643 | static void s_cprestore PARAMS ((int)); | |
644 | static void s_gpword PARAMS ((int)); | |
645 | static void s_cpadd PARAMS ((int)); | |
646 | static void s_insn PARAMS ((int)); | |
647 | static void md_obj_begin PARAMS ((void)); | |
648 | static void md_obj_end PARAMS ((void)); | |
649 | static long get_number PARAMS ((void)); | |
650 | static void s_mips_ent PARAMS ((int)); | |
651 | static void s_mips_end PARAMS ((int)); | |
652 | static void s_mips_frame PARAMS ((int)); | |
653 | static void s_mips_mask PARAMS ((int)); | |
654 | static void s_mips_stab PARAMS ((int)); | |
655 | static void s_mips_weakext PARAMS ((int)); | |
656 | static void s_file PARAMS ((int)); | |
657 | static int mips16_extended_frag PARAMS ((fragS *, asection *, long)); | |
658 | ||
659 | ||
660 | static int validate_mips_insn PARAMS ((const struct mips_opcode *)); | |
661 | \f | |
662 | /* Pseudo-op table. | |
663 | ||
664 | The following pseudo-ops from the Kane and Heinrich MIPS book | |
665 | should be defined here, but are currently unsupported: .alias, | |
666 | .galive, .gjaldef, .gjrlive, .livereg, .noalias. | |
667 | ||
668 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
669 | specific to the type of debugging information being generated, and | |
670 | should be defined by the object format: .aent, .begin, .bend, | |
671 | .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp, | |
672 | .vreg. | |
673 | ||
674 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
675 | not MIPS CPU specific, but are also not specific to the object file | |
676 | format. This file is probably the best place to define them, but | |
677 | they are not currently supported: .asm0, .endr, .lab, .repeat, | |
678 | .struct. */ | |
679 | ||
680 | static const pseudo_typeS mips_pseudo_table[] = | |
681 | { | |
682 | /* MIPS specific pseudo-ops. */ | |
683 | {"option", s_option, 0}, | |
684 | {"set", s_mipsset, 0}, | |
685 | {"rdata", s_change_sec, 'r'}, | |
686 | {"sdata", s_change_sec, 's'}, | |
687 | {"livereg", s_ignore, 0}, | |
688 | {"abicalls", s_abicalls, 0}, | |
689 | {"cpload", s_cpload, 0}, | |
690 | {"cprestore", s_cprestore, 0}, | |
691 | {"gpword", s_gpword, 0}, | |
692 | {"cpadd", s_cpadd, 0}, | |
693 | {"insn", s_insn, 0}, | |
694 | ||
695 | /* Relatively generic pseudo-ops that happen to be used on MIPS | |
696 | chips. */ | |
697 | {"asciiz", stringer, 1}, | |
698 | {"bss", s_change_sec, 'b'}, | |
699 | {"err", s_err, 0}, | |
700 | {"half", s_cons, 1}, | |
701 | {"dword", s_cons, 3}, | |
702 | {"weakext", s_mips_weakext, 0}, | |
703 | ||
704 | /* These pseudo-ops are defined in read.c, but must be overridden | |
705 | here for one reason or another. */ | |
706 | {"align", s_align, 0}, | |
707 | {"byte", s_cons, 0}, | |
708 | {"data", s_change_sec, 'd'}, | |
709 | {"double", s_float_cons, 'd'}, | |
710 | {"float", s_float_cons, 'f'}, | |
711 | {"globl", s_mips_globl, 0}, | |
712 | {"global", s_mips_globl, 0}, | |
713 | {"hword", s_cons, 1}, | |
714 | {"int", s_cons, 2}, | |
715 | {"long", s_cons, 2}, | |
716 | {"octa", s_cons, 4}, | |
717 | {"quad", s_cons, 3}, | |
718 | {"short", s_cons, 1}, | |
719 | {"single", s_float_cons, 'f'}, | |
720 | {"stabn", s_mips_stab, 'n'}, | |
721 | {"text", s_change_sec, 't'}, | |
722 | {"word", s_cons, 2}, | |
723 | { 0 }, | |
724 | }; | |
725 | ||
726 | static const pseudo_typeS mips_nonecoff_pseudo_table[] = { | |
727 | /* These pseudo-ops should be defined by the object file format. | |
728 | However, a.out doesn't support them, so we have versions here. */ | |
729 | {"aent", s_mips_ent, 1}, | |
730 | {"bgnb", s_ignore, 0}, | |
731 | {"end", s_mips_end, 0}, | |
732 | {"endb", s_ignore, 0}, | |
733 | {"ent", s_mips_ent, 0}, | |
734 | {"file", s_file, 0}, | |
735 | {"fmask", s_mips_mask, 'F'}, | |
736 | {"frame", s_mips_frame, 0}, | |
737 | {"loc", s_ignore, 0}, | |
738 | {"mask", s_mips_mask, 'R'}, | |
739 | {"verstamp", s_ignore, 0}, | |
740 | { 0 }, | |
741 | }; | |
742 | ||
743 | extern void pop_insert PARAMS ((const pseudo_typeS *)); | |
744 | ||
745 | void | |
746 | mips_pop_insert () | |
747 | { | |
748 | pop_insert (mips_pseudo_table); | |
749 | if (! ECOFF_DEBUGGING) | |
750 | pop_insert (mips_nonecoff_pseudo_table); | |
751 | } | |
752 | \f | |
753 | /* Symbols labelling the current insn. */ | |
754 | ||
755 | struct insn_label_list | |
756 | { | |
757 | struct insn_label_list *next; | |
758 | symbolS *label; | |
759 | }; | |
760 | ||
761 | static struct insn_label_list *insn_labels; | |
762 | static struct insn_label_list *free_insn_labels; | |
763 | ||
764 | static void mips_clear_insn_labels PARAMS ((void)); | |
765 | ||
766 | static inline void | |
767 | mips_clear_insn_labels () | |
768 | { | |
769 | register struct insn_label_list **pl; | |
770 | ||
771 | for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next) | |
772 | ; | |
773 | *pl = insn_labels; | |
774 | insn_labels = NULL; | |
775 | } | |
776 | \f | |
777 | static char *expr_end; | |
778 | ||
779 | /* Expressions which appear in instructions. These are set by | |
780 | mips_ip. */ | |
781 | ||
782 | static expressionS imm_expr; | |
783 | static expressionS offset_expr; | |
784 | ||
785 | /* Relocs associated with imm_expr and offset_expr. */ | |
786 | ||
787 | static bfd_reloc_code_real_type imm_reloc; | |
788 | static bfd_reloc_code_real_type offset_reloc; | |
789 | ||
790 | /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */ | |
791 | ||
792 | static boolean imm_unmatched_hi; | |
793 | ||
794 | /* These are set by mips16_ip if an explicit extension is used. */ | |
795 | ||
796 | static boolean mips16_small, mips16_ext; | |
797 | ||
798 | #ifdef MIPS_STABS_ELF | |
799 | /* The pdr segment for per procedure frame/regmask info */ | |
800 | ||
801 | static segT pdr_seg; | |
802 | #endif | |
803 | ||
804 | /* | |
805 | * This function is called once, at assembler startup time. It should | |
806 | * set up all the tables, etc. that the MD part of the assembler will need. | |
807 | */ | |
808 | void | |
809 | md_begin () | |
810 | { | |
811 | boolean ok = false; | |
812 | register const char *retval = NULL; | |
813 | register unsigned int i = 0; | |
814 | const char *cpu; | |
815 | char *a = NULL; | |
816 | int broken = 0; | |
817 | int mips_isa_from_cpu; | |
818 | ||
819 | cpu = TARGET_CPU; | |
820 | if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0) | |
821 | { | |
822 | a = xmalloc (sizeof TARGET_CPU); | |
823 | strcpy (a, TARGET_CPU); | |
824 | a[(sizeof TARGET_CPU) - 3] = '\0'; | |
825 | cpu = a; | |
826 | } | |
827 | ||
828 | if (mips_cpu < 0) | |
829 | { | |
830 | /* Set mips_cpu based on TARGET_CPU, unless TARGET_CPU is | |
831 | just the generic 'mips', in which case set mips_cpu based | |
832 | on the given ISA, if any. */ | |
833 | ||
834 | if (strcmp (cpu, "mips") == 0) | |
835 | { | |
836 | if (mips_opts.isa < 0) | |
837 | mips_cpu = 3000; | |
838 | ||
839 | else if (mips_opts.isa == 2) | |
840 | mips_cpu = 6000; | |
841 | ||
842 | else if (mips_opts.isa == 3) | |
843 | mips_cpu = 4000; | |
844 | ||
845 | else if (mips_opts.isa == 4) | |
846 | mips_cpu = 8000; | |
847 | ||
848 | else | |
849 | mips_cpu = 3000; | |
850 | } | |
851 | ||
852 | else if (strcmp (cpu, "r3900") == 0 | |
853 | || strcmp (cpu, "mipstx39") == 0 | |
854 | ) | |
855 | mips_cpu = 3900; | |
856 | ||
857 | else if (strcmp (cpu, "r6000") == 0 | |
858 | || strcmp (cpu, "mips2") == 0) | |
859 | mips_cpu = 6000; | |
860 | ||
861 | else if (strcmp (cpu, "mips64") == 0 | |
862 | || strcmp (cpu, "r4000") == 0 | |
863 | || strcmp (cpu, "mips3") == 0) | |
864 | mips_cpu = 4000; | |
865 | ||
866 | else if (strcmp (cpu, "r4400") == 0) | |
867 | mips_cpu = 4400; | |
868 | ||
869 | else if (strcmp (cpu, "mips64orion") == 0 | |
870 | || strcmp (cpu, "r4600") == 0) | |
871 | mips_cpu = 4600; | |
872 | ||
873 | else if (strcmp (cpu, "r4650") == 0) | |
874 | mips_cpu = 4650; | |
875 | ||
876 | else if (strcmp (cpu, "mips64vr4300") == 0) | |
877 | mips_cpu = 4300; | |
878 | ||
879 | else if (strcmp (cpu, "mips64vr4111") == 0) | |
880 | mips_cpu = 4111; | |
881 | ||
882 | else if (strcmp (cpu, "mips64vr4100") == 0) | |
883 | mips_cpu = 4100; | |
884 | ||
885 | else if (strcmp (cpu, "r4010") == 0) | |
886 | mips_cpu = 4010; | |
887 | ||
888 | ||
889 | else if (strcmp (cpu, "r5000") == 0 | |
890 | || strcmp (cpu, "mips64vr5000") == 0) | |
891 | mips_cpu = 5000; | |
892 | ||
893 | ||
894 | ||
895 | else if (strcmp (cpu, "r8000") == 0 | |
896 | || strcmp (cpu, "mips4") == 0) | |
897 | mips_cpu = 8000; | |
898 | ||
899 | else if (strcmp (cpu, "r10000") == 0) | |
900 | mips_cpu = 10000; | |
901 | ||
902 | else if (strcmp (cpu, "mips16") == 0) | |
903 | mips_cpu = 0; /* FIXME */ | |
904 | ||
905 | else | |
906 | mips_cpu = 3000; | |
907 | } | |
908 | ||
909 | if (mips_cpu == 3000 | |
910 | || mips_cpu == 3900) | |
911 | mips_isa_from_cpu = 1; | |
912 | ||
913 | else if (mips_cpu == 6000 | |
914 | || mips_cpu == 4010) | |
915 | mips_isa_from_cpu = 2; | |
916 | ||
917 | else if (mips_cpu == 4000 | |
918 | || mips_cpu == 4100 | |
919 | || mips_cpu == 4111 | |
920 | || mips_cpu == 4400 | |
921 | || mips_cpu == 4300 | |
922 | || mips_cpu == 4600 | |
923 | || mips_cpu == 4650) | |
924 | mips_isa_from_cpu = 3; | |
925 | ||
926 | else if (mips_cpu == 5000 | |
927 | || mips_cpu == 8000 | |
928 | || mips_cpu == 10000) | |
929 | mips_isa_from_cpu = 4; | |
930 | ||
931 | else | |
932 | mips_isa_from_cpu = -1; | |
933 | ||
934 | if (mips_opts.isa == -1) | |
935 | { | |
936 | if (mips_isa_from_cpu != -1) | |
937 | mips_opts.isa = mips_isa_from_cpu; | |
938 | else | |
939 | mips_opts.isa = 1; | |
940 | } | |
941 | ||
942 | if (mips_opts.mips16 < 0) | |
943 | { | |
944 | if (strncmp (TARGET_CPU, "mips16", sizeof "mips16" - 1) == 0) | |
945 | mips_opts.mips16 = 1; | |
946 | else | |
947 | mips_opts.mips16 = 0; | |
948 | } | |
949 | ||
950 | /* End of TARGET_CPU processing, get rid of malloced memory | |
951 | if necessary. */ | |
952 | cpu = NULL; | |
953 | if (a != NULL) | |
954 | { | |
955 | free (a); | |
956 | a = NULL; | |
957 | } | |
958 | ||
959 | if (mips_opts.isa < 2 && mips_trap) | |
960 | as_bad (_("trap exception not supported at ISA 1")); | |
961 | ||
962 | /* Set the EABI kind based on the ISA before the user gets | |
963 | to change the ISA with directives. This isn't really | |
964 | the best, but then neither is basing the abi on the isa. */ | |
965 | if (mips_opts.isa > 2 | |
966 | && mips_abi_string | |
967 | && 0 == strcmp (mips_abi_string,"eabi")) | |
968 | mips_eabi64 = 1; | |
969 | ||
970 | if (mips_cpu != 0 && mips_cpu != -1) | |
971 | { | |
972 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_cpu); | |
973 | ||
974 | /* If they asked for mips1 or mips2 and a cpu that is | |
975 | mips3 or greater, then mark the object file 32BITMODE. */ | |
976 | if (mips_isa_from_cpu != -1 | |
977 | && mips_opts.isa <= 2 && mips_isa_from_cpu > 2) | |
978 | mips_32bitmode = 1; | |
979 | } | |
980 | else | |
981 | { | |
982 | switch (mips_opts.isa) | |
983 | { | |
984 | case 1: | |
985 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 3000); | |
986 | break; | |
987 | case 2: | |
988 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 6000); | |
989 | break; | |
990 | case 3: | |
991 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 4000); | |
992 | break; | |
993 | case 4: | |
994 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 8000); | |
995 | break; | |
996 | } | |
997 | } | |
998 | ||
999 | if (! ok) | |
1000 | as_warn (_("Could not set architecture and machine")); | |
1001 | ||
1002 | file_mips_isa = mips_opts.isa; | |
1003 | ||
1004 | op_hash = hash_new (); | |
1005 | ||
1006 | for (i = 0; i < NUMOPCODES;) | |
1007 | { | |
1008 | const char *name = mips_opcodes[i].name; | |
1009 | ||
1010 | retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]); | |
1011 | if (retval != NULL) | |
1012 | { | |
1013 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), | |
1014 | mips_opcodes[i].name, retval); | |
1015 | /* Probably a memory allocation problem? Give up now. */ | |
1016 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1017 | } | |
1018 | do | |
1019 | { | |
1020 | if (mips_opcodes[i].pinfo != INSN_MACRO) | |
1021 | { | |
1022 | if (!validate_mips_insn (&mips_opcodes[i])) | |
1023 | broken = 1; | |
1024 | } | |
1025 | ++i; | |
1026 | } | |
1027 | while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name)); | |
1028 | } | |
1029 | ||
1030 | mips16_op_hash = hash_new (); | |
1031 | ||
1032 | i = 0; | |
1033 | while (i < bfd_mips16_num_opcodes) | |
1034 | { | |
1035 | const char *name = mips16_opcodes[i].name; | |
1036 | ||
1037 | retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]); | |
1038 | if (retval != NULL) | |
1039 | as_fatal (_("internal: can't hash `%s': %s"), | |
1040 | mips16_opcodes[i].name, retval); | |
1041 | do | |
1042 | { | |
1043 | if (mips16_opcodes[i].pinfo != INSN_MACRO | |
1044 | && ((mips16_opcodes[i].match & mips16_opcodes[i].mask) | |
1045 | != mips16_opcodes[i].match)) | |
1046 | { | |
1047 | fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"), | |
1048 | mips16_opcodes[i].name, mips16_opcodes[i].args); | |
1049 | broken = 1; | |
1050 | } | |
1051 | ++i; | |
1052 | } | |
1053 | while (i < bfd_mips16_num_opcodes | |
1054 | && strcmp (mips16_opcodes[i].name, name) == 0); | |
1055 | } | |
1056 | ||
1057 | if (broken) | |
1058 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1059 | ||
1060 | /* We add all the general register names to the symbol table. This | |
1061 | helps us detect invalid uses of them. */ | |
1062 | for (i = 0; i < 32; i++) | |
1063 | { | |
1064 | char buf[5]; | |
1065 | ||
1066 | sprintf (buf, "$%d", i); | |
1067 | symbol_table_insert (symbol_new (buf, reg_section, i, | |
1068 | &zero_address_frag)); | |
1069 | } | |
1070 | symbol_table_insert (symbol_new ("$fp", reg_section, FP, | |
1071 | &zero_address_frag)); | |
1072 | symbol_table_insert (symbol_new ("$sp", reg_section, SP, | |
1073 | &zero_address_frag)); | |
1074 | symbol_table_insert (symbol_new ("$gp", reg_section, GP, | |
1075 | &zero_address_frag)); | |
1076 | symbol_table_insert (symbol_new ("$at", reg_section, AT, | |
1077 | &zero_address_frag)); | |
1078 | symbol_table_insert (symbol_new ("$kt0", reg_section, KT0, | |
1079 | &zero_address_frag)); | |
1080 | symbol_table_insert (symbol_new ("$kt1", reg_section, KT1, | |
1081 | &zero_address_frag)); | |
1082 | symbol_table_insert (symbol_new ("$pc", reg_section, -1, | |
1083 | &zero_address_frag)); | |
1084 | ||
1085 | mips_no_prev_insn (false); | |
1086 | ||
1087 | mips_gprmask = 0; | |
1088 | mips_cprmask[0] = 0; | |
1089 | mips_cprmask[1] = 0; | |
1090 | mips_cprmask[2] = 0; | |
1091 | mips_cprmask[3] = 0; | |
1092 | ||
1093 | /* set the default alignment for the text section (2**2) */ | |
1094 | record_alignment (text_section, 2); | |
1095 | ||
1096 | if (USE_GLOBAL_POINTER_OPT) | |
1097 | bfd_set_gp_size (stdoutput, g_switch_value); | |
1098 | ||
1099 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1100 | { | |
1101 | /* On a native system, sections must be aligned to 16 byte | |
1102 | boundaries. When configured for an embedded ELF target, we | |
1103 | don't bother. */ | |
1104 | if (strcmp (TARGET_OS, "elf") != 0) | |
1105 | { | |
1106 | (void) bfd_set_section_alignment (stdoutput, text_section, 4); | |
1107 | (void) bfd_set_section_alignment (stdoutput, data_section, 4); | |
1108 | (void) bfd_set_section_alignment (stdoutput, bss_section, 4); | |
1109 | } | |
1110 | ||
1111 | /* Create a .reginfo section for register masks and a .mdebug | |
1112 | section for debugging information. */ | |
1113 | { | |
1114 | segT seg; | |
1115 | subsegT subseg; | |
1116 | flagword flags; | |
1117 | segT sec; | |
1118 | ||
1119 | seg = now_seg; | |
1120 | subseg = now_subseg; | |
1121 | ||
1122 | /* The ABI says this section should be loaded so that the | |
1123 | running program can access it. However, we don't load it | |
1124 | if we are configured for an embedded target */ | |
1125 | flags = SEC_READONLY | SEC_DATA; | |
1126 | if (strcmp (TARGET_OS, "elf") != 0) | |
1127 | flags |= SEC_ALLOC | SEC_LOAD; | |
1128 | ||
1129 | if (! mips_64) | |
1130 | { | |
1131 | sec = subseg_new (".reginfo", (subsegT) 0); | |
1132 | ||
1133 | ||
1134 | (void) bfd_set_section_flags (stdoutput, sec, flags); | |
1135 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
1136 | ||
1137 | #ifdef OBJ_ELF | |
1138 | mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo)); | |
1139 | #endif | |
1140 | } | |
1141 | else | |
1142 | { | |
1143 | /* The 64-bit ABI uses a .MIPS.options section rather than | |
1144 | .reginfo section. */ | |
1145 | sec = subseg_new (".MIPS.options", (subsegT) 0); | |
1146 | (void) bfd_set_section_flags (stdoutput, sec, flags); | |
1147 | (void) bfd_set_section_alignment (stdoutput, sec, 3); | |
1148 | ||
1149 | #ifdef OBJ_ELF | |
1150 | /* Set up the option header. */ | |
1151 | { | |
1152 | Elf_Internal_Options opthdr; | |
1153 | char *f; | |
1154 | ||
1155 | opthdr.kind = ODK_REGINFO; | |
1156 | opthdr.size = (sizeof (Elf_External_Options) | |
1157 | + sizeof (Elf64_External_RegInfo)); | |
1158 | opthdr.section = 0; | |
1159 | opthdr.info = 0; | |
1160 | f = frag_more (sizeof (Elf_External_Options)); | |
1161 | bfd_mips_elf_swap_options_out (stdoutput, &opthdr, | |
1162 | (Elf_External_Options *) f); | |
1163 | ||
1164 | mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo)); | |
1165 | } | |
1166 | #endif | |
1167 | } | |
1168 | ||
1169 | if (ECOFF_DEBUGGING) | |
1170 | { | |
1171 | sec = subseg_new (".mdebug", (subsegT) 0); | |
1172 | (void) bfd_set_section_flags (stdoutput, sec, | |
1173 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1174 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
1175 | } | |
1176 | ||
1177 | #ifdef MIPS_STABS_ELF | |
1178 | pdr_seg = subseg_new (".pdr", (subsegT) 0); | |
1179 | (void) bfd_set_section_flags (stdoutput, pdr_seg, | |
1180 | SEC_READONLY | SEC_RELOC | SEC_DEBUGGING); | |
1181 | (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2); | |
1182 | #endif | |
1183 | ||
1184 | subseg_set (seg, subseg); | |
1185 | } | |
1186 | } | |
1187 | ||
1188 | if (! ECOFF_DEBUGGING) | |
1189 | md_obj_begin (); | |
1190 | } | |
1191 | ||
1192 | void | |
1193 | md_mips_end () | |
1194 | { | |
1195 | if (! ECOFF_DEBUGGING) | |
1196 | md_obj_end (); | |
1197 | } | |
1198 | ||
1199 | void | |
1200 | md_assemble (str) | |
1201 | char *str; | |
1202 | { | |
1203 | struct mips_cl_insn insn; | |
1204 | ||
1205 | imm_expr.X_op = O_absent; | |
1206 | imm_reloc = BFD_RELOC_UNUSED; | |
1207 | imm_unmatched_hi = false; | |
1208 | offset_expr.X_op = O_absent; | |
1209 | offset_reloc = BFD_RELOC_UNUSED; | |
1210 | ||
1211 | if (mips_opts.mips16) | |
1212 | mips16_ip (str, &insn); | |
1213 | else | |
1214 | { | |
1215 | mips_ip (str, &insn); | |
1216 | DBG((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), | |
1217 | str, insn.insn_opcode)); | |
1218 | } | |
1219 | ||
1220 | if (insn_error) | |
1221 | { | |
1222 | as_bad ("%s `%s'", insn_error, str); | |
1223 | return; | |
1224 | } | |
1225 | ||
1226 | if (insn.insn_mo->pinfo == INSN_MACRO) | |
1227 | { | |
1228 | if (mips_opts.mips16) | |
1229 | mips16_macro (&insn); | |
1230 | else | |
1231 | macro (&insn); | |
1232 | } | |
1233 | else | |
1234 | { | |
1235 | if (imm_expr.X_op != O_absent) | |
1236 | append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc, | |
1237 | imm_unmatched_hi); | |
1238 | else if (offset_expr.X_op != O_absent) | |
1239 | append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc, false); | |
1240 | else | |
1241 | append_insn ((char *) NULL, &insn, NULL, BFD_RELOC_UNUSED, false); | |
1242 | } | |
1243 | } | |
1244 | ||
1245 | /* See whether instruction IP reads register REG. CLASS is the type | |
1246 | of register. */ | |
1247 | ||
1248 | static int | |
1249 | insn_uses_reg (ip, reg, class) | |
1250 | struct mips_cl_insn *ip; | |
1251 | unsigned int reg; | |
1252 | enum mips_regclass class; | |
1253 | { | |
1254 | if (class == MIPS16_REG) | |
1255 | { | |
1256 | assert (mips_opts.mips16); | |
1257 | reg = mips16_to_32_reg_map[reg]; | |
1258 | class = MIPS_GR_REG; | |
1259 | } | |
1260 | ||
1261 | /* Don't report on general register 0, since it never changes. */ | |
1262 | if (class == MIPS_GR_REG && reg == 0) | |
1263 | return 0; | |
1264 | ||
1265 | if (class == MIPS_FP_REG) | |
1266 | { | |
1267 | assert (! mips_opts.mips16); | |
1268 | /* If we are called with either $f0 or $f1, we must check $f0. | |
1269 | This is not optimal, because it will introduce an unnecessary | |
1270 | NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would | |
1271 | need to distinguish reading both $f0 and $f1 or just one of | |
1272 | them. Note that we don't have to check the other way, | |
1273 | because there is no instruction that sets both $f0 and $f1 | |
1274 | and requires a delay. */ | |
1275 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_S) | |
1276 | && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1) | |
1277 | == (reg &~ (unsigned) 1))) | |
1278 | return 1; | |
1279 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_T) | |
1280 | && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1) | |
1281 | == (reg &~ (unsigned) 1))) | |
1282 | return 1; | |
1283 | } | |
1284 | else if (! mips_opts.mips16) | |
1285 | { | |
1286 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_S) | |
1287 | && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg) | |
1288 | return 1; | |
1289 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_T) | |
1290 | && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg) | |
1291 | return 1; | |
1292 | } | |
1293 | else | |
1294 | { | |
1295 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X) | |
1296 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX) | |
1297 | & MIPS16OP_MASK_RX)] | |
1298 | == reg)) | |
1299 | return 1; | |
1300 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y) | |
1301 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY) | |
1302 | & MIPS16OP_MASK_RY)] | |
1303 | == reg)) | |
1304 | return 1; | |
1305 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z) | |
1306 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
1307 | & MIPS16OP_MASK_MOVE32Z)] | |
1308 | == reg)) | |
1309 | return 1; | |
1310 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG) | |
1311 | return 1; | |
1312 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP) | |
1313 | return 1; | |
1314 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA) | |
1315 | return 1; | |
1316 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X) | |
1317 | && ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
1318 | & MIPS16OP_MASK_REGR32) == reg) | |
1319 | return 1; | |
1320 | } | |
1321 | ||
1322 | return 0; | |
1323 | } | |
1324 | ||
1325 | /* This function returns true if modifying a register requires a | |
1326 | delay. */ | |
1327 | ||
1328 | static int | |
1329 | reg_needs_delay (reg) | |
1330 | int reg; | |
1331 | { | |
1332 | unsigned long prev_pinfo; | |
1333 | ||
1334 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1335 | if (! mips_opts.noreorder | |
1336 | && mips_opts.isa < 4 | |
1337 | && ((prev_pinfo & INSN_LOAD_COPROC_DELAY) | |
1338 | || (! gpr_interlocks | |
1339 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1340 | { | |
1341 | /* A load from a coprocessor or from memory. All load | |
1342 | delays delay the use of general register rt for one | |
1343 | instruction on the r3000. The r6000 and r4000 use | |
1344 | interlocks. */ | |
1345 | /* Itbl support may require additional care here. */ | |
1346 | know (prev_pinfo & INSN_WRITE_GPR_T); | |
1347 | if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)) | |
1348 | return 1; | |
1349 | } | |
1350 | ||
1351 | return 0; | |
1352 | } | |
1353 | ||
1354 | /* Mark instruction labels in mips16 mode. This permits the linker to | |
1355 | handle them specially, such as generating jalx instructions when | |
1356 | needed. We also make them odd for the duration of the assembly, in | |
1357 | order to generate the right sort of code. We will make them even | |
1358 | in the adjust_symtab routine, while leaving them marked. This is | |
1359 | convenient for the debugger and the disassembler. The linker knows | |
1360 | to make them odd again. */ | |
1361 | ||
1362 | static void | |
1363 | mips16_mark_labels () | |
1364 | { | |
1365 | if (mips_opts.mips16) | |
1366 | { | |
1367 | struct insn_label_list *l; | |
1368 | ||
1369 | for (l = insn_labels; l != NULL; l = l->next) | |
1370 | { | |
1371 | #ifdef OBJ_ELF | |
1372 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1373 | S_SET_OTHER (l->label, STO_MIPS16); | |
1374 | #endif | |
49309057 ILT |
1375 | if ((S_GET_VALUE (l->label) & 1) == 0) |
1376 | S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1); | |
252b5132 RH |
1377 | } |
1378 | } | |
1379 | } | |
1380 | ||
1381 | /* Output an instruction. PLACE is where to put the instruction; if | |
1382 | it is NULL, this uses frag_more to get room. IP is the instruction | |
1383 | information. ADDRESS_EXPR is an operand of the instruction to be | |
1384 | used with RELOC_TYPE. */ | |
1385 | ||
1386 | static void | |
1387 | append_insn (place, ip, address_expr, reloc_type, unmatched_hi) | |
1388 | char *place; | |
1389 | struct mips_cl_insn *ip; | |
1390 | expressionS *address_expr; | |
1391 | bfd_reloc_code_real_type reloc_type; | |
1392 | boolean unmatched_hi; | |
1393 | { | |
1394 | register unsigned long prev_pinfo, pinfo; | |
1395 | char *f; | |
1396 | fixS *fixp; | |
1397 | int nops = 0; | |
1398 | ||
1399 | /* Mark instruction labels in mips16 mode. */ | |
1400 | if (mips_opts.mips16) | |
1401 | mips16_mark_labels (); | |
1402 | ||
1403 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1404 | pinfo = ip->insn_mo->pinfo; | |
1405 | ||
1406 | if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL)) | |
1407 | { | |
1408 | int prev_prev_nop; | |
1409 | ||
1410 | /* If the previous insn required any delay slots, see if we need | |
1411 | to insert a NOP or two. There are eight kinds of possible | |
1412 | hazards, of which an instruction can have at most one type. | |
1413 | (1) a load from memory delay | |
1414 | (2) a load from a coprocessor delay | |
1415 | (3) an unconditional branch delay | |
1416 | (4) a conditional branch delay | |
1417 | (5) a move to coprocessor register delay | |
1418 | (6) a load coprocessor register from memory delay | |
1419 | (7) a coprocessor condition code delay | |
1420 | (8) a HI/LO special register delay | |
1421 | ||
1422 | There are a lot of optimizations we could do that we don't. | |
1423 | In particular, we do not, in general, reorder instructions. | |
1424 | If you use gcc with optimization, it will reorder | |
1425 | instructions and generally do much more optimization then we | |
1426 | do here; repeating all that work in the assembler would only | |
1427 | benefit hand written assembly code, and does not seem worth | |
1428 | it. */ | |
1429 | ||
1430 | /* This is how a NOP is emitted. */ | |
1431 | #define emit_nop() \ | |
1432 | (mips_opts.mips16 \ | |
1433 | ? md_number_to_chars (frag_more (2), 0x6500, 2) \ | |
1434 | : md_number_to_chars (frag_more (4), 0, 4)) | |
1435 | ||
1436 | /* The previous insn might require a delay slot, depending upon | |
1437 | the contents of the current insn. */ | |
1438 | if (! mips_opts.mips16 | |
1439 | && mips_opts.isa < 4 | |
1440 | && (((prev_pinfo & INSN_LOAD_COPROC_DELAY) | |
1441 | && ! cop_interlocks) | |
1442 | || (! gpr_interlocks | |
1443 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1444 | { | |
1445 | /* A load from a coprocessor or from memory. All load | |
1446 | delays delay the use of general register rt for one | |
1447 | instruction on the r3000. The r6000 and r4000 use | |
1448 | interlocks. */ | |
1449 | /* Itbl support may require additional care here. */ | |
1450 | know (prev_pinfo & INSN_WRITE_GPR_T); | |
1451 | if (mips_optimize == 0 | |
1452 | || insn_uses_reg (ip, | |
1453 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
1454 | & OP_MASK_RT), | |
1455 | MIPS_GR_REG)) | |
1456 | ++nops; | |
1457 | } | |
1458 | else if (! mips_opts.mips16 | |
1459 | && mips_opts.isa < 4 | |
1460 | && (((prev_pinfo & INSN_COPROC_MOVE_DELAY) | |
1461 | && ! cop_interlocks) | |
1462 | || (mips_opts.isa < 2 | |
1463 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)))) | |
1464 | { | |
1465 | /* A generic coprocessor delay. The previous instruction | |
1466 | modified a coprocessor general or control register. If | |
1467 | it modified a control register, we need to avoid any | |
1468 | coprocessor instruction (this is probably not always | |
1469 | required, but it sometimes is). If it modified a general | |
1470 | register, we avoid using that register. | |
1471 | ||
1472 | On the r6000 and r4000 loading a coprocessor register | |
1473 | from memory is interlocked, and does not require a delay. | |
1474 | ||
1475 | This case is not handled very well. There is no special | |
1476 | knowledge of CP0 handling, and the coprocessors other | |
1477 | than the floating point unit are not distinguished at | |
1478 | all. */ | |
1479 | /* Itbl support may require additional care here. FIXME! | |
1480 | Need to modify this to include knowledge about | |
1481 | user specified delays! */ | |
1482 | if (prev_pinfo & INSN_WRITE_FPR_T) | |
1483 | { | |
1484 | if (mips_optimize == 0 | |
1485 | || insn_uses_reg (ip, | |
1486 | ((prev_insn.insn_opcode >> OP_SH_FT) | |
1487 | & OP_MASK_FT), | |
1488 | MIPS_FP_REG)) | |
1489 | ++nops; | |
1490 | } | |
1491 | else if (prev_pinfo & INSN_WRITE_FPR_S) | |
1492 | { | |
1493 | if (mips_optimize == 0 | |
1494 | || insn_uses_reg (ip, | |
1495 | ((prev_insn.insn_opcode >> OP_SH_FS) | |
1496 | & OP_MASK_FS), | |
1497 | MIPS_FP_REG)) | |
1498 | ++nops; | |
1499 | } | |
1500 | else | |
1501 | { | |
1502 | /* We don't know exactly what the previous instruction | |
1503 | does. If the current instruction uses a coprocessor | |
1504 | register, we must insert a NOP. If previous | |
1505 | instruction may set the condition codes, and the | |
1506 | current instruction uses them, we must insert two | |
1507 | NOPS. */ | |
1508 | /* Itbl support may require additional care here. */ | |
1509 | if (mips_optimize == 0 | |
1510 | || ((prev_pinfo & INSN_WRITE_COND_CODE) | |
1511 | && (pinfo & INSN_READ_COND_CODE))) | |
1512 | nops += 2; | |
1513 | else if (pinfo & INSN_COP) | |
1514 | ++nops; | |
1515 | } | |
1516 | } | |
1517 | else if (! mips_opts.mips16 | |
1518 | && mips_opts.isa < 4 | |
1519 | && (prev_pinfo & INSN_WRITE_COND_CODE) | |
1520 | && ! cop_interlocks) | |
1521 | { | |
1522 | /* The previous instruction sets the coprocessor condition | |
1523 | codes, but does not require a general coprocessor delay | |
1524 | (this means it is a floating point comparison | |
1525 | instruction). If this instruction uses the condition | |
1526 | codes, we need to insert a single NOP. */ | |
1527 | /* Itbl support may require additional care here. */ | |
1528 | if (mips_optimize == 0 | |
1529 | || (pinfo & INSN_READ_COND_CODE)) | |
1530 | ++nops; | |
1531 | } | |
1532 | else if (prev_pinfo & INSN_READ_LO) | |
1533 | { | |
1534 | /* The previous instruction reads the LO register; if the | |
1535 | current instruction writes to the LO register, we must | |
1536 | insert two NOPS. Some newer processors have interlocks. | |
1537 | Also the tx39's multiply instructions can be exectuted | |
1538 | immediatly after a read from HI/LO (without the delay), | |
1539 | though the tx39's divide insns still do require the | |
1540 | delay. */ | |
1541 | if (! (hilo_interlocks | |
1542 | || (mips_cpu == 3900 && (pinfo & INSN_MULT))) | |
1543 | && (mips_optimize == 0 | |
1544 | || (pinfo & INSN_WRITE_LO))) | |
1545 | nops += 2; | |
1546 | /* Most mips16 branch insns don't have a delay slot. | |
1547 | If a read from LO is immediately followed by a branch | |
1548 | to a write to LO we have a read followed by a write | |
1549 | less than 2 insns away. We assume the target of | |
1550 | a branch might be a write to LO, and insert a nop | |
1551 | between a read and an immediately following branch. */ | |
1552 | else if (mips_opts.mips16 | |
1553 | && (mips_optimize == 0 | |
1554 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1555 | nops += 1; | |
1556 | } | |
1557 | else if (prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
1558 | { | |
1559 | /* The previous instruction reads the HI register; if the | |
1560 | current instruction writes to the HI register, we must | |
1561 | insert a NOP. Some newer processors have interlocks. | |
1562 | Also the note tx39's multiply above. */ | |
1563 | if (! (hilo_interlocks | |
1564 | || (mips_cpu == 3900 && (pinfo & INSN_MULT))) | |
1565 | && (mips_optimize == 0 | |
1566 | || (pinfo & INSN_WRITE_HI))) | |
1567 | nops += 2; | |
1568 | /* Most mips16 branch insns don't have a delay slot. | |
1569 | If a read from HI is immediately followed by a branch | |
1570 | to a write to HI we have a read followed by a write | |
1571 | less than 2 insns away. We assume the target of | |
1572 | a branch might be a write to HI, and insert a nop | |
1573 | between a read and an immediately following branch. */ | |
1574 | else if (mips_opts.mips16 | |
1575 | && (mips_optimize == 0 | |
1576 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1577 | nops += 1; | |
1578 | } | |
1579 | ||
1580 | /* If the previous instruction was in a noreorder section, then | |
1581 | we don't want to insert the nop after all. */ | |
1582 | /* Itbl support may require additional care here. */ | |
1583 | if (prev_insn_unreordered) | |
1584 | nops = 0; | |
1585 | ||
1586 | /* There are two cases which require two intervening | |
1587 | instructions: 1) setting the condition codes using a move to | |
1588 | coprocessor instruction which requires a general coprocessor | |
1589 | delay and then reading the condition codes 2) reading the HI | |
1590 | or LO register and then writing to it (except on processors | |
1591 | which have interlocks). If we are not already emitting a NOP | |
1592 | instruction, we must check for these cases compared to the | |
1593 | instruction previous to the previous instruction. */ | |
1594 | if ((! mips_opts.mips16 | |
1595 | && mips_opts.isa < 4 | |
1596 | && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY) | |
1597 | && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE) | |
1598 | && (pinfo & INSN_READ_COND_CODE) | |
1599 | && ! cop_interlocks) | |
1600 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO) | |
1601 | && (pinfo & INSN_WRITE_LO) | |
1602 | && ! (hilo_interlocks | |
1603 | || (mips_cpu == 3900 && (pinfo & INSN_MULT)))) | |
1604 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
1605 | && (pinfo & INSN_WRITE_HI) | |
1606 | && ! (hilo_interlocks | |
1607 | || (mips_cpu == 3900 && (pinfo & INSN_MULT))))) | |
1608 | prev_prev_nop = 1; | |
1609 | else | |
1610 | prev_prev_nop = 0; | |
1611 | ||
1612 | if (prev_prev_insn_unreordered) | |
1613 | prev_prev_nop = 0; | |
1614 | ||
1615 | if (prev_prev_nop && nops == 0) | |
1616 | ++nops; | |
1617 | ||
1618 | /* If we are being given a nop instruction, don't bother with | |
1619 | one of the nops we would otherwise output. This will only | |
1620 | happen when a nop instruction is used with mips_optimize set | |
1621 | to 0. */ | |
1622 | if (nops > 0 | |
1623 | && ! mips_opts.noreorder | |
1624 | && ip->insn_opcode == (mips_opts.mips16 ? 0x6500 : 0)) | |
1625 | --nops; | |
1626 | ||
1627 | /* Now emit the right number of NOP instructions. */ | |
1628 | if (nops > 0 && ! mips_opts.noreorder) | |
1629 | { | |
1630 | fragS *old_frag; | |
1631 | unsigned long old_frag_offset; | |
1632 | int i; | |
1633 | struct insn_label_list *l; | |
1634 | ||
1635 | old_frag = frag_now; | |
1636 | old_frag_offset = frag_now_fix (); | |
1637 | ||
1638 | for (i = 0; i < nops; i++) | |
1639 | emit_nop (); | |
1640 | ||
1641 | if (listing) | |
1642 | { | |
1643 | listing_prev_line (); | |
1644 | /* We may be at the start of a variant frag. In case we | |
1645 | are, make sure there is enough space for the frag | |
1646 | after the frags created by listing_prev_line. The | |
1647 | argument to frag_grow here must be at least as large | |
1648 | as the argument to all other calls to frag_grow in | |
1649 | this file. We don't have to worry about being in the | |
1650 | middle of a variant frag, because the variants insert | |
1651 | all needed nop instructions themselves. */ | |
1652 | frag_grow (40); | |
1653 | } | |
1654 | ||
1655 | for (l = insn_labels; l != NULL; l = l->next) | |
1656 | { | |
1657 | assert (S_GET_SEGMENT (l->label) == now_seg); | |
49309057 | 1658 | symbol_set_frag (l->label, frag_now); |
252b5132 RH |
1659 | S_SET_VALUE (l->label, (valueT) frag_now_fix ()); |
1660 | /* mips16 text labels are stored as odd. */ | |
1661 | if (mips_opts.mips16) | |
49309057 | 1662 | S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1); |
252b5132 RH |
1663 | } |
1664 | ||
1665 | #ifndef NO_ECOFF_DEBUGGING | |
1666 | if (ECOFF_DEBUGGING) | |
1667 | ecoff_fix_loc (old_frag, old_frag_offset); | |
1668 | #endif | |
1669 | } | |
1670 | else if (prev_nop_frag != NULL) | |
1671 | { | |
1672 | /* We have a frag holding nops we may be able to remove. If | |
1673 | we don't need any nops, we can decrease the size of | |
1674 | prev_nop_frag by the size of one instruction. If we do | |
1675 | need some nops, we count them in prev_nops_required. */ | |
1676 | if (prev_nop_frag_since == 0) | |
1677 | { | |
1678 | if (nops == 0) | |
1679 | { | |
1680 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1681 | --prev_nop_frag_holds; | |
1682 | } | |
1683 | else | |
1684 | prev_nop_frag_required += nops; | |
1685 | } | |
1686 | else | |
1687 | { | |
1688 | if (prev_prev_nop == 0) | |
1689 | { | |
1690 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1691 | --prev_nop_frag_holds; | |
1692 | } | |
1693 | else | |
1694 | ++prev_nop_frag_required; | |
1695 | } | |
1696 | ||
1697 | if (prev_nop_frag_holds <= prev_nop_frag_required) | |
1698 | prev_nop_frag = NULL; | |
1699 | ||
1700 | ++prev_nop_frag_since; | |
1701 | ||
1702 | /* Sanity check: by the time we reach the second instruction | |
1703 | after prev_nop_frag, we should have used up all the nops | |
1704 | one way or another. */ | |
1705 | assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL); | |
1706 | } | |
1707 | } | |
1708 | ||
1709 | if (reloc_type > BFD_RELOC_UNUSED) | |
1710 | { | |
1711 | /* We need to set up a variant frag. */ | |
1712 | assert (mips_opts.mips16 && address_expr != NULL); | |
1713 | f = frag_var (rs_machine_dependent, 4, 0, | |
1714 | RELAX_MIPS16_ENCODE (reloc_type - BFD_RELOC_UNUSED, | |
1715 | mips16_small, mips16_ext, | |
1716 | (prev_pinfo | |
1717 | & INSN_UNCOND_BRANCH_DELAY), | |
1718 | (prev_insn_reloc_type | |
1719 | == BFD_RELOC_MIPS16_JMP)), | |
1720 | make_expr_symbol (address_expr), (offsetT) 0, | |
1721 | (char *) NULL); | |
1722 | } | |
1723 | else if (place != NULL) | |
1724 | f = place; | |
1725 | else if (mips_opts.mips16 | |
1726 | && ! ip->use_extend | |
1727 | && reloc_type != BFD_RELOC_MIPS16_JMP) | |
1728 | { | |
1729 | /* Make sure there is enough room to swap this instruction with | |
1730 | a following jump instruction. */ | |
1731 | frag_grow (6); | |
1732 | f = frag_more (2); | |
1733 | } | |
1734 | else | |
1735 | { | |
1736 | if (mips_opts.mips16 | |
1737 | && mips_opts.noreorder | |
1738 | && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0) | |
1739 | as_warn (_("extended instruction in delay slot")); | |
1740 | ||
1741 | f = frag_more (4); | |
1742 | } | |
1743 | ||
1744 | fixp = NULL; | |
1745 | if (address_expr != NULL && reloc_type < BFD_RELOC_UNUSED) | |
1746 | { | |
1747 | if (address_expr->X_op == O_constant) | |
1748 | { | |
1749 | switch (reloc_type) | |
1750 | { | |
1751 | case BFD_RELOC_32: | |
1752 | ip->insn_opcode |= address_expr->X_add_number; | |
1753 | break; | |
1754 | ||
1755 | case BFD_RELOC_LO16: | |
1756 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; | |
1757 | break; | |
1758 | ||
1759 | case BFD_RELOC_MIPS_JMP: | |
1760 | if ((address_expr->X_add_number & 3) != 0) | |
1761 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1762 | (unsigned long) address_expr->X_add_number); | |
1763 | ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff; | |
1764 | break; | |
1765 | ||
1766 | case BFD_RELOC_MIPS16_JMP: | |
1767 | if ((address_expr->X_add_number & 3) != 0) | |
1768 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1769 | (unsigned long) address_expr->X_add_number); | |
1770 | ip->insn_opcode |= | |
1771 | (((address_expr->X_add_number & 0x7c0000) << 3) | |
1772 | | ((address_expr->X_add_number & 0xf800000) >> 7) | |
1773 | | ((address_expr->X_add_number & 0x3fffc) >> 2)); | |
1774 | break; | |
1775 | ||
1776 | ||
1777 | case BFD_RELOC_16_PCREL_S2: | |
1778 | goto need_reloc; | |
1779 | ||
1780 | default: | |
1781 | internalError (); | |
1782 | } | |
1783 | } | |
1784 | else | |
1785 | { | |
1786 | need_reloc: | |
1787 | /* Don't generate a reloc if we are writing into a variant | |
1788 | frag. */ | |
1789 | if (place == NULL) | |
1790 | { | |
1791 | fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4, | |
1792 | address_expr, | |
1793 | reloc_type == BFD_RELOC_16_PCREL_S2, | |
1794 | reloc_type); | |
1795 | if (unmatched_hi) | |
1796 | { | |
1797 | struct mips_hi_fixup *hi_fixup; | |
1798 | ||
1799 | assert (reloc_type == BFD_RELOC_HI16_S); | |
1800 | hi_fixup = ((struct mips_hi_fixup *) | |
1801 | xmalloc (sizeof (struct mips_hi_fixup))); | |
1802 | hi_fixup->fixp = fixp; | |
1803 | hi_fixup->seg = now_seg; | |
1804 | hi_fixup->next = mips_hi_fixup_list; | |
1805 | mips_hi_fixup_list = hi_fixup; | |
1806 | } | |
1807 | } | |
1808 | } | |
1809 | } | |
1810 | ||
1811 | if (! mips_opts.mips16) | |
1812 | md_number_to_chars (f, ip->insn_opcode, 4); | |
1813 | else if (reloc_type == BFD_RELOC_MIPS16_JMP) | |
1814 | { | |
1815 | md_number_to_chars (f, ip->insn_opcode >> 16, 2); | |
1816 | md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2); | |
1817 | } | |
1818 | else | |
1819 | { | |
1820 | if (ip->use_extend) | |
1821 | { | |
1822 | md_number_to_chars (f, 0xf000 | ip->extend, 2); | |
1823 | f += 2; | |
1824 | } | |
1825 | md_number_to_chars (f, ip->insn_opcode, 2); | |
1826 | } | |
1827 | ||
1828 | /* Update the register mask information. */ | |
1829 | if (! mips_opts.mips16) | |
1830 | { | |
1831 | if (pinfo & INSN_WRITE_GPR_D) | |
1832 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD); | |
1833 | if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0) | |
1834 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT); | |
1835 | if (pinfo & INSN_READ_GPR_S) | |
1836 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS); | |
1837 | if (pinfo & INSN_WRITE_GPR_31) | |
1838 | mips_gprmask |= 1 << 31; | |
1839 | if (pinfo & INSN_WRITE_FPR_D) | |
1840 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD); | |
1841 | if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0) | |
1842 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS); | |
1843 | if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0) | |
1844 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT); | |
1845 | if ((pinfo & INSN_READ_FPR_R) != 0) | |
1846 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR); | |
1847 | if (pinfo & INSN_COP) | |
1848 | { | |
1849 | /* We don't keep enough information to sort these cases out. | |
1850 | The itbl support does keep this information however, although | |
1851 | we currently don't support itbl fprmats as part of the cop | |
1852 | instruction. May want to add this support in the future. */ | |
1853 | } | |
1854 | /* Never set the bit for $0, which is always zero. */ | |
1855 | mips_gprmask &=~ 1 << 0; | |
1856 | } | |
1857 | else | |
1858 | { | |
1859 | if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X)) | |
1860 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX) | |
1861 | & MIPS16OP_MASK_RX); | |
1862 | if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y)) | |
1863 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY) | |
1864 | & MIPS16OP_MASK_RY); | |
1865 | if (pinfo & MIPS16_INSN_WRITE_Z) | |
1866 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ) | |
1867 | & MIPS16OP_MASK_RZ); | |
1868 | if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T)) | |
1869 | mips_gprmask |= 1 << TREG; | |
1870 | if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP)) | |
1871 | mips_gprmask |= 1 << SP; | |
1872 | if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31)) | |
1873 | mips_gprmask |= 1 << RA; | |
1874 | if (pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
1875 | mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode); | |
1876 | if (pinfo & MIPS16_INSN_READ_Z) | |
1877 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
1878 | & MIPS16OP_MASK_MOVE32Z); | |
1879 | if (pinfo & MIPS16_INSN_READ_GPR_X) | |
1880 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
1881 | & MIPS16OP_MASK_REGR32); | |
1882 | } | |
1883 | ||
1884 | if (place == NULL && ! mips_opts.noreorder) | |
1885 | { | |
1886 | /* Filling the branch delay slot is more complex. We try to | |
1887 | switch the branch with the previous instruction, which we can | |
1888 | do if the previous instruction does not set up a condition | |
1889 | that the branch tests and if the branch is not itself the | |
1890 | target of any branch. */ | |
1891 | if ((pinfo & INSN_UNCOND_BRANCH_DELAY) | |
1892 | || (pinfo & INSN_COND_BRANCH_DELAY)) | |
1893 | { | |
1894 | if (mips_optimize < 2 | |
1895 | /* If we have seen .set volatile or .set nomove, don't | |
1896 | optimize. */ | |
1897 | || mips_opts.nomove != 0 | |
1898 | /* If we had to emit any NOP instructions, then we | |
1899 | already know we can not swap. */ | |
1900 | || nops != 0 | |
1901 | /* If we don't even know the previous insn, we can not | |
1902 | swap. */ | |
1903 | || ! prev_insn_valid | |
1904 | /* If the previous insn is already in a branch delay | |
1905 | slot, then we can not swap. */ | |
1906 | || prev_insn_is_delay_slot | |
1907 | /* If the previous previous insn was in a .set | |
1908 | noreorder, we can't swap. Actually, the MIPS | |
1909 | assembler will swap in this situation. However, gcc | |
1910 | configured -with-gnu-as will generate code like | |
1911 | .set noreorder | |
1912 | lw $4,XXX | |
1913 | .set reorder | |
1914 | INSN | |
1915 | bne $4,$0,foo | |
1916 | in which we can not swap the bne and INSN. If gcc is | |
1917 | not configured -with-gnu-as, it does not output the | |
1918 | .set pseudo-ops. We don't have to check | |
1919 | prev_insn_unreordered, because prev_insn_valid will | |
1920 | be 0 in that case. We don't want to use | |
1921 | prev_prev_insn_valid, because we do want to be able | |
1922 | to swap at the start of a function. */ | |
1923 | || prev_prev_insn_unreordered | |
1924 | /* If the branch is itself the target of a branch, we | |
1925 | can not swap. We cheat on this; all we check for is | |
1926 | whether there is a label on this instruction. If | |
1927 | there are any branches to anything other than a | |
1928 | label, users must use .set noreorder. */ | |
1929 | || insn_labels != NULL | |
1930 | /* If the previous instruction is in a variant frag, we | |
1931 | can not do the swap. This does not apply to the | |
1932 | mips16, which uses variant frags for different | |
1933 | purposes. */ | |
1934 | || (! mips_opts.mips16 | |
1935 | && prev_insn_frag->fr_type == rs_machine_dependent) | |
1936 | /* If the branch reads the condition codes, we don't | |
1937 | even try to swap, because in the sequence | |
1938 | ctc1 $X,$31 | |
1939 | INSN | |
1940 | INSN | |
1941 | bc1t LABEL | |
1942 | we can not swap, and I don't feel like handling that | |
1943 | case. */ | |
1944 | || (! mips_opts.mips16 | |
1945 | && mips_opts.isa < 4 | |
1946 | && (pinfo & INSN_READ_COND_CODE)) | |
1947 | /* We can not swap with an instruction that requires a | |
1948 | delay slot, becase the target of the branch might | |
1949 | interfere with that instruction. */ | |
1950 | || (! mips_opts.mips16 | |
1951 | && mips_opts.isa < 4 | |
1952 | && (prev_pinfo | |
1953 | /* Itbl support may require additional care here. */ | |
1954 | & (INSN_LOAD_COPROC_DELAY | |
1955 | | INSN_COPROC_MOVE_DELAY | |
1956 | | INSN_WRITE_COND_CODE))) | |
1957 | || (! (hilo_interlocks | |
1958 | || (mips_cpu == 3900 && (pinfo & INSN_MULT))) | |
1959 | && (prev_pinfo | |
1960 | & (INSN_READ_LO | |
1961 | | INSN_READ_HI))) | |
1962 | || (! mips_opts.mips16 | |
1963 | && ! gpr_interlocks | |
1964 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)) | |
1965 | || (! mips_opts.mips16 | |
1966 | && mips_opts.isa < 2 | |
1967 | /* Itbl support may require additional care here. */ | |
1968 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)) | |
1969 | /* We can not swap with a branch instruction. */ | |
1970 | || (prev_pinfo | |
1971 | & (INSN_UNCOND_BRANCH_DELAY | |
1972 | | INSN_COND_BRANCH_DELAY | |
1973 | | INSN_COND_BRANCH_LIKELY)) | |
1974 | /* We do not swap with a trap instruction, since it | |
1975 | complicates trap handlers to have the trap | |
1976 | instruction be in a delay slot. */ | |
1977 | || (prev_pinfo & INSN_TRAP) | |
1978 | /* If the branch reads a register that the previous | |
1979 | instruction sets, we can not swap. */ | |
1980 | || (! mips_opts.mips16 | |
1981 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
1982 | && insn_uses_reg (ip, | |
1983 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
1984 | & OP_MASK_RT), | |
1985 | MIPS_GR_REG)) | |
1986 | || (! mips_opts.mips16 | |
1987 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
1988 | && insn_uses_reg (ip, | |
1989 | ((prev_insn.insn_opcode >> OP_SH_RD) | |
1990 | & OP_MASK_RD), | |
1991 | MIPS_GR_REG)) | |
1992 | || (mips_opts.mips16 | |
1993 | && (((prev_pinfo & MIPS16_INSN_WRITE_X) | |
1994 | && insn_uses_reg (ip, | |
1995 | ((prev_insn.insn_opcode | |
1996 | >> MIPS16OP_SH_RX) | |
1997 | & MIPS16OP_MASK_RX), | |
1998 | MIPS16_REG)) | |
1999 | || ((prev_pinfo & MIPS16_INSN_WRITE_Y) | |
2000 | && insn_uses_reg (ip, | |
2001 | ((prev_insn.insn_opcode | |
2002 | >> MIPS16OP_SH_RY) | |
2003 | & MIPS16OP_MASK_RY), | |
2004 | MIPS16_REG)) | |
2005 | || ((prev_pinfo & MIPS16_INSN_WRITE_Z) | |
2006 | && insn_uses_reg (ip, | |
2007 | ((prev_insn.insn_opcode | |
2008 | >> MIPS16OP_SH_RZ) | |
2009 | & MIPS16OP_MASK_RZ), | |
2010 | MIPS16_REG)) | |
2011 | || ((prev_pinfo & MIPS16_INSN_WRITE_T) | |
2012 | && insn_uses_reg (ip, TREG, MIPS_GR_REG)) | |
2013 | || ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2014 | && insn_uses_reg (ip, RA, MIPS_GR_REG)) | |
2015 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2016 | && insn_uses_reg (ip, | |
2017 | MIPS16OP_EXTRACT_REG32R (prev_insn. | |
2018 | insn_opcode), | |
2019 | MIPS_GR_REG)))) | |
2020 | /* If the branch writes a register that the previous | |
2021 | instruction sets, we can not swap (we know that | |
2022 | branches write only to RD or to $31). */ | |
2023 | || (! mips_opts.mips16 | |
2024 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2025 | && (((pinfo & INSN_WRITE_GPR_D) | |
2026 | && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT) | |
2027 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2028 | || ((pinfo & INSN_WRITE_GPR_31) | |
2029 | && (((prev_insn.insn_opcode >> OP_SH_RT) | |
2030 | & OP_MASK_RT) | |
2031 | == 31)))) | |
2032 | || (! mips_opts.mips16 | |
2033 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2034 | && (((pinfo & INSN_WRITE_GPR_D) | |
2035 | && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD) | |
2036 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2037 | || ((pinfo & INSN_WRITE_GPR_31) | |
2038 | && (((prev_insn.insn_opcode >> OP_SH_RD) | |
2039 | & OP_MASK_RD) | |
2040 | == 31)))) | |
2041 | || (mips_opts.mips16 | |
2042 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2043 | && ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2044 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2045 | && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode) | |
2046 | == RA)))) | |
2047 | /* If the branch writes a register that the previous | |
2048 | instruction reads, we can not swap (we know that | |
2049 | branches only write to RD or to $31). */ | |
2050 | || (! mips_opts.mips16 | |
2051 | && (pinfo & INSN_WRITE_GPR_D) | |
2052 | && insn_uses_reg (&prev_insn, | |
2053 | ((ip->insn_opcode >> OP_SH_RD) | |
2054 | & OP_MASK_RD), | |
2055 | MIPS_GR_REG)) | |
2056 | || (! mips_opts.mips16 | |
2057 | && (pinfo & INSN_WRITE_GPR_31) | |
2058 | && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG)) | |
2059 | || (mips_opts.mips16 | |
2060 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2061 | && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG)) | |
2062 | /* If we are generating embedded PIC code, the branch | |
2063 | might be expanded into a sequence which uses $at, so | |
2064 | we can't swap with an instruction which reads it. */ | |
2065 | || (mips_pic == EMBEDDED_PIC | |
2066 | && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG)) | |
2067 | /* If the previous previous instruction has a load | |
2068 | delay, and sets a register that the branch reads, we | |
2069 | can not swap. */ | |
2070 | || (! mips_opts.mips16 | |
2071 | && mips_opts.isa < 4 | |
2072 | /* Itbl support may require additional care here. */ | |
2073 | && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY) | |
2074 | || (! gpr_interlocks | |
2075 | && (prev_prev_insn.insn_mo->pinfo | |
2076 | & INSN_LOAD_MEMORY_DELAY))) | |
2077 | && insn_uses_reg (ip, | |
2078 | ((prev_prev_insn.insn_opcode >> OP_SH_RT) | |
2079 | & OP_MASK_RT), | |
2080 | MIPS_GR_REG)) | |
2081 | /* If one instruction sets a condition code and the | |
2082 | other one uses a condition code, we can not swap. */ | |
2083 | || ((pinfo & INSN_READ_COND_CODE) | |
2084 | && (prev_pinfo & INSN_WRITE_COND_CODE)) | |
2085 | || ((pinfo & INSN_WRITE_COND_CODE) | |
2086 | && (prev_pinfo & INSN_READ_COND_CODE)) | |
2087 | /* If the previous instruction uses the PC, we can not | |
2088 | swap. */ | |
2089 | || (mips_opts.mips16 | |
2090 | && (prev_pinfo & MIPS16_INSN_READ_PC)) | |
2091 | /* If the previous instruction was extended, we can not | |
2092 | swap. */ | |
2093 | || (mips_opts.mips16 && prev_insn_extended) | |
2094 | /* If the previous instruction had a fixup in mips16 | |
2095 | mode, we can not swap. This normally means that the | |
2096 | previous instruction was a 4 byte branch anyhow. */ | |
2097 | || (mips_opts.mips16 && prev_insn_fixp) | |
2098 | /* If the previous instruction is a sync, sync.l, or | |
2099 | sync.p, we can not swap. */ | |
2100 | || (prev_pinfo && INSN_SYNC)) | |
2101 | { | |
2102 | /* We could do even better for unconditional branches to | |
2103 | portions of this object file; we could pick up the | |
2104 | instruction at the destination, put it in the delay | |
2105 | slot, and bump the destination address. */ | |
2106 | emit_nop (); | |
2107 | /* Update the previous insn information. */ | |
2108 | prev_prev_insn = *ip; | |
2109 | prev_insn.insn_mo = &dummy_opcode; | |
2110 | } | |
2111 | else | |
2112 | { | |
2113 | /* It looks like we can actually do the swap. */ | |
2114 | if (! mips_opts.mips16) | |
2115 | { | |
2116 | char *prev_f; | |
2117 | char temp[4]; | |
2118 | ||
2119 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2120 | memcpy (temp, prev_f, 4); | |
2121 | memcpy (prev_f, f, 4); | |
2122 | memcpy (f, temp, 4); | |
2123 | if (prev_insn_fixp) | |
2124 | { | |
2125 | prev_insn_fixp->fx_frag = frag_now; | |
2126 | prev_insn_fixp->fx_where = f - frag_now->fr_literal; | |
2127 | } | |
2128 | if (fixp) | |
2129 | { | |
2130 | fixp->fx_frag = prev_insn_frag; | |
2131 | fixp->fx_where = prev_insn_where; | |
2132 | } | |
2133 | } | |
2134 | else | |
2135 | { | |
2136 | char *prev_f; | |
2137 | char temp[2]; | |
2138 | ||
2139 | assert (prev_insn_fixp == NULL); | |
2140 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2141 | memcpy (temp, prev_f, 2); | |
2142 | memcpy (prev_f, f, 2); | |
2143 | if (reloc_type != BFD_RELOC_MIPS16_JMP) | |
2144 | { | |
2145 | assert (reloc_type == BFD_RELOC_UNUSED); | |
2146 | memcpy (f, temp, 2); | |
2147 | } | |
2148 | else | |
2149 | { | |
2150 | memcpy (f, f + 2, 2); | |
2151 | memcpy (f + 2, temp, 2); | |
2152 | } | |
2153 | if (fixp) | |
2154 | { | |
2155 | fixp->fx_frag = prev_insn_frag; | |
2156 | fixp->fx_where = prev_insn_where; | |
2157 | } | |
2158 | } | |
2159 | ||
2160 | /* Update the previous insn information; leave prev_insn | |
2161 | unchanged. */ | |
2162 | prev_prev_insn = *ip; | |
2163 | } | |
2164 | prev_insn_is_delay_slot = 1; | |
2165 | ||
2166 | /* If that was an unconditional branch, forget the previous | |
2167 | insn information. */ | |
2168 | if (pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2169 | { | |
2170 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2171 | prev_insn.insn_mo = &dummy_opcode; | |
2172 | } | |
2173 | ||
2174 | prev_insn_fixp = NULL; | |
2175 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2176 | prev_insn_extended = 0; | |
2177 | } | |
2178 | else if (pinfo & INSN_COND_BRANCH_LIKELY) | |
2179 | { | |
2180 | /* We don't yet optimize a branch likely. What we should do | |
2181 | is look at the target, copy the instruction found there | |
2182 | into the delay slot, and increment the branch to jump to | |
2183 | the next instruction. */ | |
2184 | emit_nop (); | |
2185 | /* Update the previous insn information. */ | |
2186 | prev_prev_insn = *ip; | |
2187 | prev_insn.insn_mo = &dummy_opcode; | |
2188 | prev_insn_fixp = NULL; | |
2189 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2190 | prev_insn_extended = 0; | |
2191 | } | |
2192 | else | |
2193 | { | |
2194 | /* Update the previous insn information. */ | |
2195 | if (nops > 0) | |
2196 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2197 | else | |
2198 | prev_prev_insn = prev_insn; | |
2199 | prev_insn = *ip; | |
2200 | ||
2201 | /* Any time we see a branch, we always fill the delay slot | |
2202 | immediately; since this insn is not a branch, we know it | |
2203 | is not in a delay slot. */ | |
2204 | prev_insn_is_delay_slot = 0; | |
2205 | ||
2206 | prev_insn_fixp = fixp; | |
2207 | prev_insn_reloc_type = reloc_type; | |
2208 | if (mips_opts.mips16) | |
2209 | prev_insn_extended = (ip->use_extend | |
2210 | || reloc_type > BFD_RELOC_UNUSED); | |
2211 | } | |
2212 | ||
2213 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2214 | prev_insn_unreordered = 0; | |
2215 | prev_insn_frag = frag_now; | |
2216 | prev_insn_where = f - frag_now->fr_literal; | |
2217 | prev_insn_valid = 1; | |
2218 | } | |
2219 | else if (place == NULL) | |
2220 | { | |
2221 | /* We need to record a bit of information even when we are not | |
2222 | reordering, in order to determine the base address for mips16 | |
2223 | PC relative relocs. */ | |
2224 | prev_prev_insn = prev_insn; | |
2225 | prev_insn = *ip; | |
2226 | prev_insn_reloc_type = reloc_type; | |
2227 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2228 | prev_insn_unreordered = 1; | |
2229 | } | |
2230 | ||
2231 | /* We just output an insn, so the next one doesn't have a label. */ | |
2232 | mips_clear_insn_labels (); | |
2233 | ||
2234 | /* We must ensure that a fixup associated with an unmatched %hi | |
2235 | reloc does not become a variant frag. Otherwise, the | |
2236 | rearrangement of %hi relocs in frob_file may confuse | |
2237 | tc_gen_reloc. */ | |
2238 | if (unmatched_hi) | |
2239 | { | |
2240 | frag_wane (frag_now); | |
2241 | frag_new (0); | |
2242 | } | |
2243 | } | |
2244 | ||
2245 | /* This function forgets that there was any previous instruction or | |
2246 | label. If PRESERVE is non-zero, it remembers enough information to | |
2247 | know whether nops are needed before a noreorder section. */ | |
2248 | ||
2249 | static void | |
2250 | mips_no_prev_insn (preserve) | |
2251 | int preserve; | |
2252 | { | |
2253 | if (! preserve) | |
2254 | { | |
2255 | prev_insn.insn_mo = &dummy_opcode; | |
2256 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2257 | prev_nop_frag = NULL; | |
2258 | prev_nop_frag_holds = 0; | |
2259 | prev_nop_frag_required = 0; | |
2260 | prev_nop_frag_since = 0; | |
2261 | } | |
2262 | prev_insn_valid = 0; | |
2263 | prev_insn_is_delay_slot = 0; | |
2264 | prev_insn_unreordered = 0; | |
2265 | prev_insn_extended = 0; | |
2266 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2267 | prev_prev_insn_unreordered = 0; | |
2268 | mips_clear_insn_labels (); | |
2269 | } | |
2270 | ||
2271 | /* This function must be called whenever we turn on noreorder or emit | |
2272 | something other than instructions. It inserts any NOPS which might | |
2273 | be needed by the previous instruction, and clears the information | |
2274 | kept for the previous instructions. The INSNS parameter is true if | |
2275 | instructions are to follow. */ | |
2276 | ||
2277 | static void | |
2278 | mips_emit_delays (insns) | |
2279 | boolean insns; | |
2280 | { | |
2281 | if (! mips_opts.noreorder) | |
2282 | { | |
2283 | int nops; | |
2284 | ||
2285 | nops = 0; | |
2286 | if ((! mips_opts.mips16 | |
2287 | && mips_opts.isa < 4 | |
2288 | && (! cop_interlocks | |
2289 | && (prev_insn.insn_mo->pinfo | |
2290 | & (INSN_LOAD_COPROC_DELAY | |
2291 | | INSN_COPROC_MOVE_DELAY | |
2292 | | INSN_WRITE_COND_CODE)))) | |
2293 | || (! hilo_interlocks | |
2294 | && (prev_insn.insn_mo->pinfo | |
2295 | & (INSN_READ_LO | |
2296 | | INSN_READ_HI))) | |
2297 | || (! mips_opts.mips16 | |
2298 | && ! gpr_interlocks | |
2299 | && (prev_insn.insn_mo->pinfo | |
2300 | & INSN_LOAD_MEMORY_DELAY)) | |
2301 | || (! mips_opts.mips16 | |
2302 | && mips_opts.isa < 2 | |
2303 | && (prev_insn.insn_mo->pinfo | |
2304 | & INSN_COPROC_MEMORY_DELAY))) | |
2305 | { | |
2306 | /* Itbl support may require additional care here. */ | |
2307 | ++nops; | |
2308 | if ((! mips_opts.mips16 | |
2309 | && mips_opts.isa < 4 | |
2310 | && (! cop_interlocks | |
2311 | && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2312 | || (! hilo_interlocks | |
2313 | && ((prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2314 | || (prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2315 | ++nops; | |
2316 | ||
2317 | if (prev_insn_unreordered) | |
2318 | nops = 0; | |
2319 | } | |
2320 | else if ((! mips_opts.mips16 | |
2321 | && mips_opts.isa < 4 | |
2322 | && (! cop_interlocks | |
2323 | && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2324 | || (! hilo_interlocks | |
2325 | && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2326 | || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2327 | { | |
2328 | /* Itbl support may require additional care here. */ | |
2329 | if (! prev_prev_insn_unreordered) | |
2330 | ++nops; | |
2331 | } | |
2332 | ||
2333 | if (nops > 0) | |
2334 | { | |
2335 | struct insn_label_list *l; | |
2336 | ||
2337 | if (insns) | |
2338 | { | |
2339 | /* Record the frag which holds the nop instructions, so | |
2340 | that we can remove them if we don't need them. */ | |
2341 | frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4); | |
2342 | prev_nop_frag = frag_now; | |
2343 | prev_nop_frag_holds = nops; | |
2344 | prev_nop_frag_required = 0; | |
2345 | prev_nop_frag_since = 0; | |
2346 | } | |
2347 | ||
2348 | for (; nops > 0; --nops) | |
2349 | emit_nop (); | |
2350 | ||
2351 | if (insns) | |
2352 | { | |
2353 | /* Move on to a new frag, so that it is safe to simply | |
2354 | decrease the size of prev_nop_frag. */ | |
2355 | frag_wane (frag_now); | |
2356 | frag_new (0); | |
2357 | } | |
2358 | ||
2359 | for (l = insn_labels; l != NULL; l = l->next) | |
2360 | { | |
2361 | assert (S_GET_SEGMENT (l->label) == now_seg); | |
49309057 | 2362 | symbol_set_frag (l->label, frag_now); |
252b5132 RH |
2363 | S_SET_VALUE (l->label, (valueT) frag_now_fix ()); |
2364 | /* mips16 text labels are stored as odd. */ | |
2365 | if (mips_opts.mips16) | |
49309057 | 2366 | S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1); |
252b5132 RH |
2367 | } |
2368 | } | |
2369 | } | |
2370 | ||
2371 | /* Mark instruction labels in mips16 mode. */ | |
2372 | if (mips_opts.mips16 && insns) | |
2373 | mips16_mark_labels (); | |
2374 | ||
2375 | mips_no_prev_insn (insns); | |
2376 | } | |
2377 | ||
2378 | /* Build an instruction created by a macro expansion. This is passed | |
2379 | a pointer to the count of instructions created so far, an | |
2380 | expression, the name of the instruction to build, an operand format | |
2381 | string, and corresponding arguments. */ | |
2382 | ||
2383 | #ifdef USE_STDARG | |
2384 | static void | |
2385 | macro_build (char *place, | |
2386 | int *counter, | |
2387 | expressionS * ep, | |
2388 | const char *name, | |
2389 | const char *fmt, | |
2390 | ...) | |
2391 | #else | |
2392 | static void | |
2393 | macro_build (place, counter, ep, name, fmt, va_alist) | |
2394 | char *place; | |
2395 | int *counter; | |
2396 | expressionS *ep; | |
2397 | const char *name; | |
2398 | const char *fmt; | |
2399 | va_dcl | |
2400 | #endif | |
2401 | { | |
2402 | struct mips_cl_insn insn; | |
2403 | bfd_reloc_code_real_type r; | |
2404 | va_list args; | |
2405 | int insn_isa; | |
2406 | ||
2407 | #ifdef USE_STDARG | |
2408 | va_start (args, fmt); | |
2409 | #else | |
2410 | va_start (args); | |
2411 | #endif | |
2412 | ||
2413 | /* | |
2414 | * If the macro is about to expand into a second instruction, | |
2415 | * print a warning if needed. We need to pass ip as a parameter | |
2416 | * to generate a better warning message here... | |
2417 | */ | |
2418 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2419 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2420 | ||
2421 | if (place == NULL) | |
2422 | *counter += 1; /* bump instruction counter */ | |
2423 | ||
2424 | if (mips_opts.mips16) | |
2425 | { | |
2426 | mips16_macro_build (place, counter, ep, name, fmt, args); | |
2427 | va_end (args); | |
2428 | return; | |
2429 | } | |
2430 | ||
2431 | r = BFD_RELOC_UNUSED; | |
2432 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
2433 | assert (insn.insn_mo); | |
2434 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2435 | ||
2436 | /* Search until we get a match for NAME. */ | |
2437 | while (1) | |
2438 | { | |
2439 | if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA1) | |
2440 | insn_isa = 1; | |
2441 | else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA2) | |
2442 | insn_isa = 2; | |
2443 | else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA3) | |
2444 | insn_isa = 3; | |
2445 | else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA4) | |
2446 | insn_isa = 4; | |
2447 | else | |
2448 | insn_isa = 15; | |
2449 | ||
2450 | if (strcmp (fmt, insn.insn_mo->args) == 0 | |
2451 | && insn.insn_mo->pinfo != INSN_MACRO | |
2452 | && (insn_isa <= mips_opts.isa | |
2453 | || (mips_cpu == 4650 | |
2454 | && (insn.insn_mo->membership & INSN_4650) != 0) | |
2455 | || (mips_cpu == 4010 | |
2456 | && (insn.insn_mo->membership & INSN_4010) != 0) | |
2457 | || ((mips_cpu == 4100 | |
2458 | || mips_cpu == 4111 | |
2459 | ) | |
2460 | && (insn.insn_mo->membership & INSN_4100) != 0) | |
2461 | || (mips_cpu == 3900 | |
2462 | && (insn.insn_mo->membership & INSN_3900) != 0)) | |
2463 | && (mips_cpu != 4650 || (insn.insn_mo->pinfo & FP_D) == 0)) | |
2464 | break; | |
2465 | ||
2466 | ++insn.insn_mo; | |
2467 | assert (insn.insn_mo->name); | |
2468 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2469 | } | |
2470 | ||
2471 | insn.insn_opcode = insn.insn_mo->match; | |
2472 | for (;;) | |
2473 | { | |
2474 | switch (*fmt++) | |
2475 | { | |
2476 | case '\0': | |
2477 | break; | |
2478 | ||
2479 | case ',': | |
2480 | case '(': | |
2481 | case ')': | |
2482 | continue; | |
2483 | ||
2484 | case 't': | |
2485 | case 'w': | |
2486 | case 'E': | |
2487 | insn.insn_opcode |= va_arg (args, int) << 16; | |
2488 | continue; | |
2489 | ||
2490 | case 'c': | |
2491 | case 'T': | |
2492 | case 'W': | |
2493 | insn.insn_opcode |= va_arg (args, int) << 16; | |
2494 | continue; | |
2495 | ||
2496 | case 'd': | |
2497 | case 'G': | |
2498 | insn.insn_opcode |= va_arg (args, int) << 11; | |
2499 | continue; | |
2500 | ||
2501 | case 'V': | |
2502 | case 'S': | |
2503 | insn.insn_opcode |= va_arg (args, int) << 11; | |
2504 | continue; | |
2505 | ||
2506 | case 'z': | |
2507 | continue; | |
2508 | ||
2509 | case '<': | |
2510 | insn.insn_opcode |= va_arg (args, int) << 6; | |
2511 | continue; | |
2512 | ||
2513 | case 'D': | |
2514 | insn.insn_opcode |= va_arg (args, int) << 6; | |
2515 | continue; | |
2516 | ||
2517 | case 'B': | |
2518 | insn.insn_opcode |= va_arg (args, int) << 6; | |
2519 | continue; | |
2520 | ||
2521 | case 'q': | |
2522 | insn.insn_opcode |= va_arg (args, int) << 6; | |
2523 | continue; | |
2524 | ||
2525 | case 'b': | |
2526 | case 's': | |
2527 | case 'r': | |
2528 | case 'v': | |
2529 | insn.insn_opcode |= va_arg (args, int) << 21; | |
2530 | continue; | |
2531 | ||
2532 | case 'i': | |
2533 | case 'j': | |
2534 | case 'o': | |
2535 | r = (bfd_reloc_code_real_type) va_arg (args, int); | |
2536 | assert (r == BFD_RELOC_MIPS_GPREL | |
2537 | || r == BFD_RELOC_MIPS_LITERAL | |
2538 | || r == BFD_RELOC_LO16 | |
2539 | || r == BFD_RELOC_MIPS_GOT16 | |
2540 | || r == BFD_RELOC_MIPS_CALL16 | |
2541 | || r == BFD_RELOC_MIPS_GOT_LO16 | |
2542 | || r == BFD_RELOC_MIPS_CALL_LO16 | |
2543 | || (ep->X_op == O_subtract | |
2544 | && now_seg == text_section | |
2545 | && r == BFD_RELOC_PCREL_LO16)); | |
2546 | continue; | |
2547 | ||
2548 | case 'u': | |
2549 | r = (bfd_reloc_code_real_type) va_arg (args, int); | |
2550 | assert (ep != NULL | |
2551 | && (ep->X_op == O_constant | |
2552 | || (ep->X_op == O_symbol | |
2553 | && (r == BFD_RELOC_HI16_S | |
2554 | || r == BFD_RELOC_HI16 | |
2555 | || r == BFD_RELOC_MIPS_GOT_HI16 | |
2556 | || r == BFD_RELOC_MIPS_CALL_HI16)) | |
2557 | || (ep->X_op == O_subtract | |
2558 | && now_seg == text_section | |
2559 | && r == BFD_RELOC_PCREL_HI16_S))); | |
2560 | if (ep->X_op == O_constant) | |
2561 | { | |
2562 | insn.insn_opcode |= (ep->X_add_number >> 16) & 0xffff; | |
2563 | ep = NULL; | |
2564 | r = BFD_RELOC_UNUSED; | |
2565 | } | |
2566 | continue; | |
2567 | ||
2568 | case 'p': | |
2569 | assert (ep != NULL); | |
2570 | /* | |
2571 | * This allows macro() to pass an immediate expression for | |
2572 | * creating short branches without creating a symbol. | |
2573 | * Note that the expression still might come from the assembly | |
2574 | * input, in which case the value is not checked for range nor | |
2575 | * is a relocation entry generated (yuck). | |
2576 | */ | |
2577 | if (ep->X_op == O_constant) | |
2578 | { | |
2579 | insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff; | |
2580 | ep = NULL; | |
2581 | } | |
2582 | else | |
2583 | r = BFD_RELOC_16_PCREL_S2; | |
2584 | continue; | |
2585 | ||
2586 | case 'a': | |
2587 | assert (ep != NULL); | |
2588 | r = BFD_RELOC_MIPS_JMP; | |
2589 | continue; | |
2590 | ||
2591 | case 'C': | |
2592 | insn.insn_opcode |= va_arg (args, unsigned long); | |
2593 | continue; | |
2594 | ||
2595 | default: | |
2596 | internalError (); | |
2597 | } | |
2598 | break; | |
2599 | } | |
2600 | va_end (args); | |
2601 | assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); | |
2602 | ||
2603 | append_insn (place, &insn, ep, r, false); | |
2604 | } | |
2605 | ||
2606 | static void | |
2607 | mips16_macro_build (place, counter, ep, name, fmt, args) | |
2608 | char *place; | |
2609 | int *counter; | |
2610 | expressionS *ep; | |
2611 | const char *name; | |
2612 | const char *fmt; | |
2613 | va_list args; | |
2614 | { | |
2615 | struct mips_cl_insn insn; | |
2616 | bfd_reloc_code_real_type r; | |
2617 | ||
2618 | r = BFD_RELOC_UNUSED; | |
2619 | insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name); | |
2620 | assert (insn.insn_mo); | |
2621 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2622 | ||
2623 | while (strcmp (fmt, insn.insn_mo->args) != 0 | |
2624 | || insn.insn_mo->pinfo == INSN_MACRO) | |
2625 | { | |
2626 | ++insn.insn_mo; | |
2627 | assert (insn.insn_mo->name); | |
2628 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2629 | } | |
2630 | ||
2631 | insn.insn_opcode = insn.insn_mo->match; | |
2632 | insn.use_extend = false; | |
2633 | ||
2634 | for (;;) | |
2635 | { | |
2636 | int c; | |
2637 | ||
2638 | c = *fmt++; | |
2639 | switch (c) | |
2640 | { | |
2641 | case '\0': | |
2642 | break; | |
2643 | ||
2644 | case ',': | |
2645 | case '(': | |
2646 | case ')': | |
2647 | continue; | |
2648 | ||
2649 | case 'y': | |
2650 | case 'w': | |
2651 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY; | |
2652 | continue; | |
2653 | ||
2654 | case 'x': | |
2655 | case 'v': | |
2656 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX; | |
2657 | continue; | |
2658 | ||
2659 | case 'z': | |
2660 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ; | |
2661 | continue; | |
2662 | ||
2663 | case 'Z': | |
2664 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z; | |
2665 | continue; | |
2666 | ||
2667 | case '0': | |
2668 | case 'S': | |
2669 | case 'P': | |
2670 | case 'R': | |
2671 | continue; | |
2672 | ||
2673 | case 'X': | |
2674 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32; | |
2675 | continue; | |
2676 | ||
2677 | case 'Y': | |
2678 | { | |
2679 | int regno; | |
2680 | ||
2681 | regno = va_arg (args, int); | |
2682 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
2683 | insn.insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
2684 | } | |
2685 | continue; | |
2686 | ||
2687 | case '<': | |
2688 | case '>': | |
2689 | case '4': | |
2690 | case '5': | |
2691 | case 'H': | |
2692 | case 'W': | |
2693 | case 'D': | |
2694 | case 'j': | |
2695 | case '8': | |
2696 | case 'V': | |
2697 | case 'C': | |
2698 | case 'U': | |
2699 | case 'k': | |
2700 | case 'K': | |
2701 | case 'p': | |
2702 | case 'q': | |
2703 | { | |
2704 | assert (ep != NULL); | |
2705 | ||
2706 | if (ep->X_op != O_constant) | |
2707 | r = BFD_RELOC_UNUSED + c; | |
2708 | else | |
2709 | { | |
2710 | mips16_immed ((char *) NULL, 0, c, ep->X_add_number, false, | |
2711 | false, false, &insn.insn_opcode, | |
2712 | &insn.use_extend, &insn.extend); | |
2713 | ep = NULL; | |
2714 | r = BFD_RELOC_UNUSED; | |
2715 | } | |
2716 | } | |
2717 | continue; | |
2718 | ||
2719 | case '6': | |
2720 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6; | |
2721 | continue; | |
2722 | } | |
2723 | ||
2724 | break; | |
2725 | } | |
2726 | ||
2727 | assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); | |
2728 | ||
2729 | append_insn (place, &insn, ep, r, false); | |
2730 | } | |
2731 | ||
2732 | /* | |
2733 | * Generate a "lui" instruction. | |
2734 | */ | |
2735 | static void | |
2736 | macro_build_lui (place, counter, ep, regnum) | |
2737 | char *place; | |
2738 | int *counter; | |
2739 | expressionS *ep; | |
2740 | int regnum; | |
2741 | { | |
2742 | expressionS high_expr; | |
2743 | struct mips_cl_insn insn; | |
2744 | bfd_reloc_code_real_type r; | |
2745 | CONST char *name = "lui"; | |
2746 | CONST char *fmt = "t,u"; | |
2747 | ||
2748 | assert (! mips_opts.mips16); | |
2749 | ||
2750 | if (place == NULL) | |
2751 | high_expr = *ep; | |
2752 | else | |
2753 | { | |
2754 | high_expr.X_op = O_constant; | |
2755 | high_expr.X_add_number = ep->X_add_number; | |
2756 | } | |
2757 | ||
2758 | if (high_expr.X_op == O_constant) | |
2759 | { | |
2760 | /* we can compute the instruction now without a relocation entry */ | |
2761 | if (high_expr.X_add_number & 0x8000) | |
2762 | high_expr.X_add_number += 0x10000; | |
2763 | high_expr.X_add_number = | |
2764 | ((unsigned long) high_expr.X_add_number >> 16) & 0xffff; | |
2765 | r = BFD_RELOC_UNUSED; | |
2766 | } | |
2767 | else | |
2768 | { | |
2769 | assert (ep->X_op == O_symbol); | |
2770 | /* _gp_disp is a special case, used from s_cpload. */ | |
2771 | assert (mips_pic == NO_PIC | |
2772 | || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0); | |
2773 | r = BFD_RELOC_HI16_S; | |
2774 | } | |
2775 | ||
2776 | /* | |
2777 | * If the macro is about to expand into a second instruction, | |
2778 | * print a warning if needed. We need to pass ip as a parameter | |
2779 | * to generate a better warning message here... | |
2780 | */ | |
2781 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2782 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2783 | ||
2784 | if (place == NULL) | |
2785 | *counter += 1; /* bump instruction counter */ | |
2786 | ||
2787 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
2788 | assert (insn.insn_mo); | |
2789 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2790 | assert (strcmp (fmt, insn.insn_mo->args) == 0); | |
2791 | ||
2792 | insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT); | |
2793 | if (r == BFD_RELOC_UNUSED) | |
2794 | { | |
2795 | insn.insn_opcode |= high_expr.X_add_number; | |
2796 | append_insn (place, &insn, NULL, r, false); | |
2797 | } | |
2798 | else | |
2799 | append_insn (place, &insn, &high_expr, r, false); | |
2800 | } | |
2801 | ||
2802 | /* set_at() | |
2803 | * Generates code to set the $at register to true (one) | |
2804 | * if reg is less than the immediate expression. | |
2805 | */ | |
2806 | static void | |
2807 | set_at (counter, reg, unsignedp) | |
2808 | int *counter; | |
2809 | int reg; | |
2810 | int unsignedp; | |
2811 | { | |
2812 | if (imm_expr.X_op == O_constant | |
2813 | && imm_expr.X_add_number >= -0x8000 | |
2814 | && imm_expr.X_add_number < 0x8000) | |
2815 | macro_build ((char *) NULL, counter, &imm_expr, | |
2816 | unsignedp ? "sltiu" : "slti", | |
2817 | "t,r,j", AT, reg, (int) BFD_RELOC_LO16); | |
2818 | else | |
2819 | { | |
2820 | load_register (counter, AT, &imm_expr, 0); | |
2821 | macro_build ((char *) NULL, counter, NULL, | |
2822 | unsignedp ? "sltu" : "slt", | |
2823 | "d,v,t", AT, reg, AT); | |
2824 | } | |
2825 | } | |
2826 | ||
2827 | /* Warn if an expression is not a constant. */ | |
2828 | ||
2829 | static void | |
2830 | check_absolute_expr (ip, ex) | |
2831 | struct mips_cl_insn *ip; | |
2832 | expressionS *ex; | |
2833 | { | |
2834 | if (ex->X_op == O_big) | |
2835 | as_bad (_("unsupported large constant")); | |
2836 | else if (ex->X_op != O_constant) | |
2837 | as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name); | |
2838 | } | |
2839 | ||
2840 | /* Count the leading zeroes by performing a binary chop. This is a | |
2841 | bulky bit of source, but performance is a LOT better for the | |
2842 | majority of values than a simple loop to count the bits: | |
2843 | for (lcnt = 0; (lcnt < 32); lcnt++) | |
2844 | if ((v) & (1 << (31 - lcnt))) | |
2845 | break; | |
2846 | However it is not code size friendly, and the gain will drop a bit | |
2847 | on certain cached systems. | |
2848 | */ | |
2849 | #define COUNT_TOP_ZEROES(v) \ | |
2850 | (((v) & ~0xffff) == 0 \ | |
2851 | ? ((v) & ~0xff) == 0 \ | |
2852 | ? ((v) & ~0xf) == 0 \ | |
2853 | ? ((v) & ~0x3) == 0 \ | |
2854 | ? ((v) & ~0x1) == 0 \ | |
2855 | ? !(v) \ | |
2856 | ? 32 \ | |
2857 | : 31 \ | |
2858 | : 30 \ | |
2859 | : ((v) & ~0x7) == 0 \ | |
2860 | ? 29 \ | |
2861 | : 28 \ | |
2862 | : ((v) & ~0x3f) == 0 \ | |
2863 | ? ((v) & ~0x1f) == 0 \ | |
2864 | ? 27 \ | |
2865 | : 26 \ | |
2866 | : ((v) & ~0x7f) == 0 \ | |
2867 | ? 25 \ | |
2868 | : 24 \ | |
2869 | : ((v) & ~0xfff) == 0 \ | |
2870 | ? ((v) & ~0x3ff) == 0 \ | |
2871 | ? ((v) & ~0x1ff) == 0 \ | |
2872 | ? 23 \ | |
2873 | : 22 \ | |
2874 | : ((v) & ~0x7ff) == 0 \ | |
2875 | ? 21 \ | |
2876 | : 20 \ | |
2877 | : ((v) & ~0x3fff) == 0 \ | |
2878 | ? ((v) & ~0x1fff) == 0 \ | |
2879 | ? 19 \ | |
2880 | : 18 \ | |
2881 | : ((v) & ~0x7fff) == 0 \ | |
2882 | ? 17 \ | |
2883 | : 16 \ | |
2884 | : ((v) & ~0xffffff) == 0 \ | |
2885 | ? ((v) & ~0xfffff) == 0 \ | |
2886 | ? ((v) & ~0x3ffff) == 0 \ | |
2887 | ? ((v) & ~0x1ffff) == 0 \ | |
2888 | ? 15 \ | |
2889 | : 14 \ | |
2890 | : ((v) & ~0x7ffff) == 0 \ | |
2891 | ? 13 \ | |
2892 | : 12 \ | |
2893 | : ((v) & ~0x3fffff) == 0 \ | |
2894 | ? ((v) & ~0x1fffff) == 0 \ | |
2895 | ? 11 \ | |
2896 | : 10 \ | |
2897 | : ((v) & ~0x7fffff) == 0 \ | |
2898 | ? 9 \ | |
2899 | : 8 \ | |
2900 | : ((v) & ~0xfffffff) == 0 \ | |
2901 | ? ((v) & ~0x3ffffff) == 0 \ | |
2902 | ? ((v) & ~0x1ffffff) == 0 \ | |
2903 | ? 7 \ | |
2904 | : 6 \ | |
2905 | : ((v) & ~0x7ffffff) == 0 \ | |
2906 | ? 5 \ | |
2907 | : 4 \ | |
2908 | : ((v) & ~0x3fffffff) == 0 \ | |
2909 | ? ((v) & ~0x1fffffff) == 0 \ | |
2910 | ? 3 \ | |
2911 | : 2 \ | |
2912 | : ((v) & ~0x7fffffff) == 0 \ | |
2913 | ? 1 \ | |
2914 | : 0) | |
2915 | ||
2916 | /* load_register() | |
2917 | * This routine generates the least number of instructions neccessary to load | |
2918 | * an absolute expression value into a register. | |
2919 | */ | |
2920 | static void | |
2921 | load_register (counter, reg, ep, dbl) | |
2922 | int *counter; | |
2923 | int reg; | |
2924 | expressionS *ep; | |
2925 | int dbl; | |
2926 | { | |
2927 | int freg; | |
2928 | expressionS hi32, lo32; | |
2929 | ||
2930 | if (ep->X_op != O_big) | |
2931 | { | |
2932 | assert (ep->X_op == O_constant); | |
2933 | if (ep->X_add_number < 0x8000 | |
2934 | && (ep->X_add_number >= 0 | |
2935 | || (ep->X_add_number >= -0x8000 | |
2936 | && (! dbl | |
2937 | || ! ep->X_unsigned | |
2938 | || sizeof (ep->X_add_number) > 4)))) | |
2939 | { | |
2940 | /* We can handle 16 bit signed values with an addiu to | |
2941 | $zero. No need to ever use daddiu here, since $zero and | |
2942 | the result are always correct in 32 bit mode. */ | |
2943 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
2944 | (int) BFD_RELOC_LO16); | |
2945 | return; | |
2946 | } | |
2947 | else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000) | |
2948 | { | |
2949 | /* We can handle 16 bit unsigned values with an ori to | |
2950 | $zero. */ | |
2951 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0, | |
2952 | (int) BFD_RELOC_LO16); | |
2953 | return; | |
2954 | } | |
2955 | else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0 | |
2956 | || ((ep->X_add_number &~ (offsetT) 0x7fffffff) | |
2957 | == ~ (offsetT) 0x7fffffff)) | |
2958 | && (! dbl | |
2959 | || ! ep->X_unsigned | |
2960 | || sizeof (ep->X_add_number) > 4 | |
2961 | || (ep->X_add_number & 0x80000000) == 0)) | |
2962 | || ((mips_opts.isa < 3 || ! dbl) | |
2963 | && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0) | |
2964 | || (mips_opts.isa < 3 | |
2965 | && ! dbl | |
2966 | && ((ep->X_add_number &~ (offsetT) 0xffffffff) | |
2967 | == ~ (offsetT) 0xffffffff))) | |
2968 | { | |
2969 | /* 32 bit values require an lui. */ | |
2970 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
2971 | (int) BFD_RELOC_HI16); | |
2972 | if ((ep->X_add_number & 0xffff) != 0) | |
2973 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg, | |
2974 | (int) BFD_RELOC_LO16); | |
2975 | return; | |
2976 | } | |
2977 | } | |
2978 | ||
2979 | /* The value is larger than 32 bits. */ | |
2980 | ||
2981 | if (mips_opts.isa < 3) | |
2982 | { | |
2983 | as_bad (_("Number larger than 32 bits")); | |
2984 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
2985 | (int) BFD_RELOC_LO16); | |
2986 | return; | |
2987 | } | |
2988 | ||
2989 | if (ep->X_op != O_big) | |
2990 | { | |
2991 | hi32 = *ep; | |
2992 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
2993 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
2994 | hi32.X_add_number &= 0xffffffff; | |
2995 | lo32 = *ep; | |
2996 | lo32.X_add_number &= 0xffffffff; | |
2997 | } | |
2998 | else | |
2999 | { | |
3000 | assert (ep->X_add_number > 2); | |
3001 | if (ep->X_add_number == 3) | |
3002 | generic_bignum[3] = 0; | |
3003 | else if (ep->X_add_number > 4) | |
3004 | as_bad (_("Number larger than 64 bits")); | |
3005 | lo32.X_op = O_constant; | |
3006 | lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16); | |
3007 | hi32.X_op = O_constant; | |
3008 | hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16); | |
3009 | } | |
3010 | ||
3011 | if (hi32.X_add_number == 0) | |
3012 | freg = 0; | |
3013 | else | |
3014 | { | |
3015 | int shift, bit; | |
3016 | unsigned long hi, lo; | |
3017 | ||
3018 | if (hi32.X_add_number == 0xffffffff) | |
3019 | { | |
3020 | if ((lo32.X_add_number & 0xffff8000) == 0xffff8000) | |
3021 | { | |
3022 | macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j", | |
3023 | reg, 0, (int) BFD_RELOC_LO16); | |
3024 | return; | |
3025 | } | |
3026 | if (lo32.X_add_number & 0x80000000) | |
3027 | { | |
3028 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, | |
3029 | (int) BFD_RELOC_HI16); | |
3030 | if (lo32.X_add_number & 0xffff) | |
3031 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", | |
3032 | reg, reg, (int) BFD_RELOC_LO16); | |
3033 | return; | |
3034 | } | |
3035 | } | |
3036 | ||
3037 | /* Check for 16bit shifted constant. We know that hi32 is | |
3038 | non-zero, so start the mask on the first bit of the hi32 | |
3039 | value. */ | |
3040 | shift = 17; | |
3041 | do | |
3042 | { | |
3043 | unsigned long himask, lomask; | |
3044 | ||
3045 | if (shift < 32) | |
3046 | { | |
3047 | himask = 0xffff >> (32 - shift); | |
3048 | lomask = (0xffff << shift) & 0xffffffff; | |
3049 | } | |
3050 | else | |
3051 | { | |
3052 | himask = 0xffff << (shift - 32); | |
3053 | lomask = 0; | |
3054 | } | |
3055 | if ((hi32.X_add_number & ~ (offsetT) himask) == 0 | |
3056 | && (lo32.X_add_number & ~ (offsetT) lomask) == 0) | |
3057 | { | |
3058 | expressionS tmp; | |
3059 | ||
3060 | tmp.X_op = O_constant; | |
3061 | if (shift < 32) | |
3062 | tmp.X_add_number = ((hi32.X_add_number << (32 - shift)) | |
3063 | | (lo32.X_add_number >> shift)); | |
3064 | else | |
3065 | tmp.X_add_number = hi32.X_add_number >> (shift - 32); | |
3066 | macro_build ((char *) NULL, counter, &tmp, "ori", "t,r,i", reg, 0, | |
3067 | (int) BFD_RELOC_LO16); | |
3068 | macro_build ((char *) NULL, counter, NULL, | |
3069 | (shift >= 32) ? "dsll32" : "dsll", | |
3070 | "d,w,<", reg, reg, | |
3071 | (shift >= 32) ? shift - 32 : shift); | |
3072 | return; | |
3073 | } | |
3074 | shift++; | |
3075 | } while (shift <= (64 - 16)); | |
3076 | ||
3077 | /* Find the bit number of the lowest one bit, and store the | |
3078 | shifted value in hi/lo. */ | |
3079 | hi = (unsigned long) (hi32.X_add_number & 0xffffffff); | |
3080 | lo = (unsigned long) (lo32.X_add_number & 0xffffffff); | |
3081 | if (lo != 0) | |
3082 | { | |
3083 | bit = 0; | |
3084 | while ((lo & 1) == 0) | |
3085 | { | |
3086 | lo >>= 1; | |
3087 | ++bit; | |
3088 | } | |
3089 | lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit); | |
3090 | hi >>= bit; | |
3091 | } | |
3092 | else | |
3093 | { | |
3094 | bit = 32; | |
3095 | while ((hi & 1) == 0) | |
3096 | { | |
3097 | hi >>= 1; | |
3098 | ++bit; | |
3099 | } | |
3100 | lo = hi; | |
3101 | hi = 0; | |
3102 | } | |
3103 | ||
3104 | /* Optimize if the shifted value is a (power of 2) - 1. */ | |
3105 | if ((hi == 0 && ((lo + 1) & lo) == 0) | |
3106 | || (lo == 0xffffffff && ((hi + 1) & hi) == 0)) | |
3107 | { | |
3108 | shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number); | |
3109 | if (shift != 0) | |
3110 | { | |
3111 | expressionS tmp; | |
3112 | ||
3113 | /* This instruction will set the register to be all | |
3114 | ones. */ | |
3115 | tmp.X_op = O_constant; | |
3116 | tmp.X_add_number = (offsetT) -1; | |
3117 | macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j", | |
3118 | reg, 0, (int) BFD_RELOC_LO16); | |
3119 | if (bit != 0) | |
3120 | { | |
3121 | bit += shift; | |
3122 | macro_build ((char *) NULL, counter, NULL, | |
3123 | (bit >= 32) ? "dsll32" : "dsll", | |
3124 | "d,w,<", reg, reg, | |
3125 | (bit >= 32) ? bit - 32 : bit); | |
3126 | } | |
3127 | macro_build ((char *) NULL, counter, NULL, | |
3128 | (shift >= 32) ? "dsrl32" : "dsrl", | |
3129 | "d,w,<", reg, reg, | |
3130 | (shift >= 32) ? shift - 32 : shift); | |
3131 | return; | |
3132 | } | |
3133 | } | |
3134 | ||
3135 | /* Sign extend hi32 before calling load_register, because we can | |
3136 | generally get better code when we load a sign extended value. */ | |
3137 | if ((hi32.X_add_number & 0x80000000) != 0) | |
3138 | hi32.X_add_number |= ~ (offsetT) 0xffffffff; | |
3139 | load_register (counter, reg, &hi32, 0); | |
3140 | freg = reg; | |
3141 | } | |
3142 | if ((lo32.X_add_number & 0xffff0000) == 0) | |
3143 | { | |
3144 | if (freg != 0) | |
3145 | { | |
3146 | macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg, | |
3147 | freg, 0); | |
3148 | freg = reg; | |
3149 | } | |
3150 | } | |
3151 | else | |
3152 | { | |
3153 | expressionS mid16; | |
3154 | ||
3155 | if ((freg == 0) && (lo32.X_add_number == 0xffffffff)) | |
3156 | { | |
3157 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, | |
3158 | (int) BFD_RELOC_HI16); | |
3159 | macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg, | |
3160 | reg, 0); | |
3161 | return; | |
3162 | } | |
3163 | ||
3164 | if (freg != 0) | |
3165 | { | |
3166 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3167 | freg, 16); | |
3168 | freg = reg; | |
3169 | } | |
3170 | mid16 = lo32; | |
3171 | mid16.X_add_number >>= 16; | |
3172 | macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg, | |
3173 | freg, (int) BFD_RELOC_LO16); | |
3174 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3175 | reg, 16); | |
3176 | freg = reg; | |
3177 | } | |
3178 | if ((lo32.X_add_number & 0xffff) != 0) | |
3179 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg, | |
3180 | (int) BFD_RELOC_LO16); | |
3181 | } | |
3182 | ||
3183 | /* Load an address into a register. */ | |
3184 | ||
3185 | static void | |
3186 | load_address (counter, reg, ep) | |
3187 | int *counter; | |
3188 | int reg; | |
3189 | expressionS *ep; | |
3190 | { | |
3191 | char *p; | |
3192 | ||
3193 | if (ep->X_op != O_constant | |
3194 | && ep->X_op != O_symbol) | |
3195 | { | |
3196 | as_bad (_("expression too complex")); | |
3197 | ep->X_op = O_constant; | |
3198 | } | |
3199 | ||
3200 | if (ep->X_op == O_constant) | |
3201 | { | |
3202 | load_register (counter, reg, ep, 0); | |
3203 | return; | |
3204 | } | |
3205 | ||
3206 | if (mips_pic == NO_PIC) | |
3207 | { | |
3208 | /* If this is a reference to a GP relative symbol, we want | |
3209 | addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
3210 | Otherwise we want | |
3211 | lui $reg,<sym> (BFD_RELOC_HI16_S) | |
3212 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3213 | If we have an addend, we always use the latter form. */ | |
3214 | if ((valueT) ep->X_add_number >= MAX_GPREL_OFFSET | |
3215 | || nopic_need_relax (ep->X_add_symbol, 1)) | |
3216 | p = NULL; | |
3217 | else | |
3218 | { | |
3219 | frag_grow (20); | |
3220 | macro_build ((char *) NULL, counter, ep, | |
3221 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3222 | || mips_opts.isa < 3) | |
3223 | ? "addiu" : "daddiu"), | |
3224 | "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
3225 | p = frag_var (rs_machine_dependent, 8, 0, | |
3226 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
3227 | mips_opts.warn_about_macros), | |
3228 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3229 | } | |
3230 | macro_build_lui (p, counter, ep, reg); | |
3231 | if (p != NULL) | |
3232 | p += 4; | |
3233 | macro_build (p, counter, ep, | |
3234 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3235 | || mips_opts.isa < 3) | |
3236 | ? "addiu" : "daddiu"), | |
3237 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3238 | } | |
3239 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
3240 | { | |
3241 | expressionS ex; | |
3242 | ||
3243 | /* If this is a reference to an external symbol, we want | |
3244 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3245 | Otherwise we want | |
3246 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3247 | nop | |
3248 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3249 | If there is a constant, it must be added in after. */ | |
3250 | ex.X_add_number = ep->X_add_number; | |
3251 | ep->X_add_number = 0; | |
3252 | frag_grow (20); | |
3253 | macro_build ((char *) NULL, counter, ep, | |
3254 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3255 | || mips_opts.isa < 3) | |
3256 | ? "lw" : "ld"), | |
3257 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
3258 | macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", ""); | |
3259 | p = frag_var (rs_machine_dependent, 4, 0, | |
3260 | RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros), | |
3261 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3262 | macro_build (p, counter, ep, | |
3263 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3264 | || mips_opts.isa < 3) | |
3265 | ? "addiu" : "daddiu"), | |
3266 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3267 | if (ex.X_add_number != 0) | |
3268 | { | |
3269 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3270 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3271 | ex.X_op = O_constant; | |
3272 | macro_build ((char *) NULL, counter, &ex, | |
3273 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3274 | || mips_opts.isa < 3) | |
3275 | ? "addiu" : "daddiu"), | |
3276 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3277 | } | |
3278 | } | |
3279 | else if (mips_pic == SVR4_PIC) | |
3280 | { | |
3281 | expressionS ex; | |
3282 | int off; | |
3283 | ||
3284 | /* This is the large GOT case. If this is a reference to an | |
3285 | external symbol, we want | |
3286 | lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
3287 | addu $reg,$reg,$gp | |
3288 | lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16) | |
3289 | Otherwise, for a reference to a local symbol, we want | |
3290 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3291 | nop | |
3292 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3293 | If there is a constant, it must be added in after. */ | |
3294 | ex.X_add_number = ep->X_add_number; | |
3295 | ep->X_add_number = 0; | |
3296 | if (reg_needs_delay (GP)) | |
3297 | off = 4; | |
3298 | else | |
3299 | off = 0; | |
3300 | frag_grow (32); | |
3301 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3302 | (int) BFD_RELOC_MIPS_GOT_HI16); | |
3303 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
3304 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3305 | || mips_opts.isa < 3) | |
3306 | ? "addu" : "daddu"), | |
3307 | "d,v,t", reg, reg, GP); | |
3308 | macro_build ((char *) NULL, counter, ep, | |
3309 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3310 | || mips_opts.isa < 3) | |
3311 | ? "lw" : "ld"), | |
3312 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg); | |
3313 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
3314 | RELAX_ENCODE (12, 12 + off, off, 8 + off, 0, | |
3315 | mips_opts.warn_about_macros), | |
3316 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3317 | if (off > 0) | |
3318 | { | |
3319 | /* We need a nop before loading from $gp. This special | |
3320 | check is required because the lui which starts the main | |
3321 | instruction stream does not refer to $gp, and so will not | |
3322 | insert the nop which may be required. */ | |
3323 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3324 | p += 4; | |
3325 | } | |
3326 | macro_build (p, counter, ep, | |
3327 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3328 | || mips_opts.isa < 3) | |
3329 | ? "lw" : "ld"), | |
3330 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
3331 | p += 4; | |
3332 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3333 | p += 4; | |
3334 | macro_build (p, counter, ep, | |
3335 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3336 | || mips_opts.isa < 3) | |
3337 | ? "addiu" : "daddiu"), | |
3338 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3339 | if (ex.X_add_number != 0) | |
3340 | { | |
3341 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3342 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3343 | ex.X_op = O_constant; | |
3344 | macro_build ((char *) NULL, counter, &ex, | |
3345 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3346 | || mips_opts.isa < 3) | |
3347 | ? "addiu" : "daddiu"), | |
3348 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3349 | } | |
3350 | } | |
3351 | else if (mips_pic == EMBEDDED_PIC) | |
3352 | { | |
3353 | /* We always do | |
3354 | addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
3355 | */ | |
3356 | macro_build ((char *) NULL, counter, ep, | |
3357 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
3358 | || mips_opts.isa < 3) | |
3359 | ? "addiu" : "daddiu"), | |
3360 | "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
3361 | } | |
3362 | else | |
3363 | abort (); | |
3364 | } | |
3365 | ||
3366 | /* | |
3367 | * Build macros | |
3368 | * This routine implements the seemingly endless macro or synthesized | |
3369 | * instructions and addressing modes in the mips assembly language. Many | |
3370 | * of these macros are simple and are similar to each other. These could | |
3371 | * probably be handled by some kind of table or grammer aproach instead of | |
3372 | * this verbose method. Others are not simple macros but are more like | |
3373 | * optimizing code generation. | |
3374 | * One interesting optimization is when several store macros appear | |
3375 | * consecutivly that would load AT with the upper half of the same address. | |
3376 | * The ensuing load upper instructions are ommited. This implies some kind | |
3377 | * of global optimization. We currently only optimize within a single macro. | |
3378 | * For many of the load and store macros if the address is specified as a | |
3379 | * constant expression in the first 64k of memory (ie ld $2,0x4000c) we | |
3380 | * first load register 'at' with zero and use it as the base register. The | |
3381 | * mips assembler simply uses register $zero. Just one tiny optimization | |
3382 | * we're missing. | |
3383 | */ | |
3384 | static void | |
3385 | macro (ip) | |
3386 | struct mips_cl_insn *ip; | |
3387 | { | |
3388 | register int treg, sreg, dreg, breg; | |
3389 | int tempreg; | |
3390 | int mask; | |
3391 | int icnt = 0; | |
3392 | int used_at; | |
3393 | expressionS expr1; | |
3394 | const char *s; | |
3395 | const char *s2; | |
3396 | const char *fmt; | |
3397 | int likely = 0; | |
3398 | int dbl = 0; | |
3399 | int coproc = 0; | |
3400 | int lr = 0; | |
3401 | int imm = 0; | |
3402 | offsetT maxnum; | |
3403 | int off; | |
3404 | bfd_reloc_code_real_type r; | |
3405 | char *p; | |
3406 | int hold_mips_optimize; | |
3407 | ||
3408 | assert (! mips_opts.mips16); | |
3409 | ||
3410 | treg = (ip->insn_opcode >> 16) & 0x1f; | |
3411 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
3412 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
3413 | mask = ip->insn_mo->mask; | |
3414 | ||
3415 | expr1.X_op = O_constant; | |
3416 | expr1.X_op_symbol = NULL; | |
3417 | expr1.X_add_symbol = NULL; | |
3418 | expr1.X_add_number = 1; | |
3419 | ||
3420 | switch (mask) | |
3421 | { | |
3422 | case M_DABS: | |
3423 | dbl = 1; | |
3424 | case M_ABS: | |
3425 | /* bgez $a0,.+12 | |
3426 | move v0,$a0 | |
3427 | sub v0,$zero,$a0 | |
3428 | */ | |
3429 | ||
3430 | mips_emit_delays (true); | |
3431 | ++mips_opts.noreorder; | |
3432 | mips_any_noreorder = 1; | |
3433 | ||
3434 | expr1.X_add_number = 8; | |
3435 | macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg); | |
3436 | if (dreg == sreg) | |
3437 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
3438 | else | |
3439 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, sreg, 0); | |
3440 | macro_build ((char *) NULL, &icnt, NULL, | |
3441 | dbl ? "dsub" : "sub", | |
3442 | "d,v,t", dreg, 0, sreg); | |
3443 | ||
3444 | --mips_opts.noreorder; | |
3445 | return; | |
3446 | ||
3447 | case M_ADD_I: | |
3448 | s = "addi"; | |
3449 | s2 = "add"; | |
3450 | goto do_addi; | |
3451 | case M_ADDU_I: | |
3452 | s = "addiu"; | |
3453 | s2 = "addu"; | |
3454 | goto do_addi; | |
3455 | case M_DADD_I: | |
3456 | dbl = 1; | |
3457 | s = "daddi"; | |
3458 | s2 = "dadd"; | |
3459 | goto do_addi; | |
3460 | case M_DADDU_I: | |
3461 | dbl = 1; | |
3462 | s = "daddiu"; | |
3463 | s2 = "daddu"; | |
3464 | do_addi: | |
3465 | if (imm_expr.X_op == O_constant | |
3466 | && imm_expr.X_add_number >= -0x8000 | |
3467 | && imm_expr.X_add_number < 0x8000) | |
3468 | { | |
3469 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg, | |
3470 | (int) BFD_RELOC_LO16); | |
3471 | return; | |
3472 | } | |
3473 | load_register (&icnt, AT, &imm_expr, dbl); | |
3474 | macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT); | |
3475 | break; | |
3476 | ||
3477 | case M_AND_I: | |
3478 | s = "andi"; | |
3479 | s2 = "and"; | |
3480 | goto do_bit; | |
3481 | case M_OR_I: | |
3482 | s = "ori"; | |
3483 | s2 = "or"; | |
3484 | goto do_bit; | |
3485 | case M_NOR_I: | |
3486 | s = ""; | |
3487 | s2 = "nor"; | |
3488 | goto do_bit; | |
3489 | case M_XOR_I: | |
3490 | s = "xori"; | |
3491 | s2 = "xor"; | |
3492 | do_bit: | |
3493 | if (imm_expr.X_op == O_constant | |
3494 | && imm_expr.X_add_number >= 0 | |
3495 | && imm_expr.X_add_number < 0x10000) | |
3496 | { | |
3497 | if (mask != M_NOR_I) | |
3498 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg, | |
3499 | sreg, (int) BFD_RELOC_LO16); | |
3500 | else | |
3501 | { | |
3502 | macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i", | |
3503 | treg, sreg, (int) BFD_RELOC_LO16); | |
3504 | macro_build ((char *) NULL, &icnt, NULL, "nor", "d,v,t", | |
3505 | treg, treg, 0); | |
3506 | } | |
3507 | return; | |
3508 | } | |
3509 | ||
3510 | load_register (&icnt, AT, &imm_expr, 0); | |
3511 | macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT); | |
3512 | break; | |
3513 | ||
3514 | case M_BEQ_I: | |
3515 | s = "beq"; | |
3516 | goto beq_i; | |
3517 | case M_BEQL_I: | |
3518 | s = "beql"; | |
3519 | likely = 1; | |
3520 | goto beq_i; | |
3521 | case M_BNE_I: | |
3522 | s = "bne"; | |
3523 | goto beq_i; | |
3524 | case M_BNEL_I: | |
3525 | s = "bnel"; | |
3526 | likely = 1; | |
3527 | beq_i: | |
3528 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3529 | { | |
3530 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, | |
3531 | 0); | |
3532 | return; | |
3533 | } | |
3534 | load_register (&icnt, AT, &imm_expr, 0); | |
3535 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT); | |
3536 | break; | |
3537 | ||
3538 | case M_BGEL: | |
3539 | likely = 1; | |
3540 | case M_BGE: | |
3541 | if (treg == 0) | |
3542 | { | |
3543 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3544 | likely ? "bgezl" : "bgez", | |
3545 | "s,p", sreg); | |
3546 | return; | |
3547 | } | |
3548 | if (sreg == 0) | |
3549 | { | |
3550 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3551 | likely ? "blezl" : "blez", | |
3552 | "s,p", treg); | |
3553 | return; | |
3554 | } | |
3555 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg); | |
3556 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3557 | likely ? "beql" : "beq", | |
3558 | "s,t,p", AT, 0); | |
3559 | break; | |
3560 | ||
3561 | case M_BGTL_I: | |
3562 | likely = 1; | |
3563 | case M_BGT_I: | |
3564 | /* check for > max integer */ | |
3565 | maxnum = 0x7fffffff; | |
3566 | if (mips_opts.isa >= 3 && sizeof (maxnum) > 4) | |
3567 | { | |
3568 | maxnum <<= 16; | |
3569 | maxnum |= 0xffff; | |
3570 | maxnum <<= 16; | |
3571 | maxnum |= 0xffff; | |
3572 | } | |
3573 | if (imm_expr.X_op == O_constant | |
3574 | && imm_expr.X_add_number >= maxnum | |
3575 | && (mips_opts.isa < 3 || sizeof (maxnum) > 4)) | |
3576 | { | |
3577 | do_false: | |
3578 | /* result is always false */ | |
3579 | if (! likely) | |
3580 | { | |
3581 | as_warn (_("Branch %s is always false (nop)"), ip->insn_mo->name); | |
3582 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
3583 | } | |
3584 | else | |
3585 | { | |
3586 | as_warn (_("Branch likely %s is always false"), ip->insn_mo->name); | |
3587 | macro_build ((char *) NULL, &icnt, &offset_expr, "bnel", | |
3588 | "s,t,p", 0, 0); | |
3589 | } | |
3590 | return; | |
3591 | } | |
3592 | if (imm_expr.X_op != O_constant) | |
3593 | as_bad (_("Unsupported large constant")); | |
3594 | imm_expr.X_add_number++; | |
3595 | /* FALLTHROUGH */ | |
3596 | case M_BGE_I: | |
3597 | case M_BGEL_I: | |
3598 | if (mask == M_BGEL_I) | |
3599 | likely = 1; | |
3600 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3601 | { | |
3602 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3603 | likely ? "bgezl" : "bgez", | |
3604 | "s,p", sreg); | |
3605 | return; | |
3606 | } | |
3607 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3608 | { | |
3609 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3610 | likely ? "bgtzl" : "bgtz", | |
3611 | "s,p", sreg); | |
3612 | return; | |
3613 | } | |
3614 | maxnum = 0x7fffffff; | |
3615 | if (mips_opts.isa >= 3 && sizeof (maxnum) > 4) | |
3616 | { | |
3617 | maxnum <<= 16; | |
3618 | maxnum |= 0xffff; | |
3619 | maxnum <<= 16; | |
3620 | maxnum |= 0xffff; | |
3621 | } | |
3622 | maxnum = - maxnum - 1; | |
3623 | if (imm_expr.X_op == O_constant | |
3624 | && imm_expr.X_add_number <= maxnum | |
3625 | && (mips_opts.isa < 3 || sizeof (maxnum) > 4)) | |
3626 | { | |
3627 | do_true: | |
3628 | /* result is always true */ | |
3629 | as_warn (_("Branch %s is always true"), ip->insn_mo->name); | |
3630 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
3631 | return; | |
3632 | } | |
3633 | set_at (&icnt, sreg, 0); | |
3634 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3635 | likely ? "beql" : "beq", | |
3636 | "s,t,p", AT, 0); | |
3637 | break; | |
3638 | ||
3639 | case M_BGEUL: | |
3640 | likely = 1; | |
3641 | case M_BGEU: | |
3642 | if (treg == 0) | |
3643 | goto do_true; | |
3644 | if (sreg == 0) | |
3645 | { | |
3646 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3647 | likely ? "beql" : "beq", | |
3648 | "s,t,p", 0, treg); | |
3649 | return; | |
3650 | } | |
3651 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, | |
3652 | treg); | |
3653 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3654 | likely ? "beql" : "beq", | |
3655 | "s,t,p", AT, 0); | |
3656 | break; | |
3657 | ||
3658 | case M_BGTUL_I: | |
3659 | likely = 1; | |
3660 | case M_BGTU_I: | |
3661 | if (sreg == 0 | |
3662 | || (mips_opts.isa < 3 | |
3663 | && imm_expr.X_op == O_constant | |
3664 | && imm_expr.X_add_number == 0xffffffff)) | |
3665 | goto do_false; | |
3666 | if (imm_expr.X_op != O_constant) | |
3667 | as_bad (_("Unsupported large constant")); | |
3668 | imm_expr.X_add_number++; | |
3669 | /* FALLTHROUGH */ | |
3670 | case M_BGEU_I: | |
3671 | case M_BGEUL_I: | |
3672 | if (mask == M_BGEUL_I) | |
3673 | likely = 1; | |
3674 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3675 | goto do_true; | |
3676 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3677 | { | |
3678 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3679 | likely ? "bnel" : "bne", | |
3680 | "s,t,p", sreg, 0); | |
3681 | return; | |
3682 | } | |
3683 | set_at (&icnt, sreg, 1); | |
3684 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3685 | likely ? "beql" : "beq", | |
3686 | "s,t,p", AT, 0); | |
3687 | break; | |
3688 | ||
3689 | case M_BGTL: | |
3690 | likely = 1; | |
3691 | case M_BGT: | |
3692 | if (treg == 0) | |
3693 | { | |
3694 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3695 | likely ? "bgtzl" : "bgtz", | |
3696 | "s,p", sreg); | |
3697 | return; | |
3698 | } | |
3699 | if (sreg == 0) | |
3700 | { | |
3701 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3702 | likely ? "bltzl" : "bltz", | |
3703 | "s,p", treg); | |
3704 | return; | |
3705 | } | |
3706 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg); | |
3707 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3708 | likely ? "bnel" : "bne", | |
3709 | "s,t,p", AT, 0); | |
3710 | break; | |
3711 | ||
3712 | case M_BGTUL: | |
3713 | likely = 1; | |
3714 | case M_BGTU: | |
3715 | if (treg == 0) | |
3716 | { | |
3717 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3718 | likely ? "bnel" : "bne", | |
3719 | "s,t,p", sreg, 0); | |
3720 | return; | |
3721 | } | |
3722 | if (sreg == 0) | |
3723 | goto do_false; | |
3724 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, | |
3725 | sreg); | |
3726 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3727 | likely ? "bnel" : "bne", | |
3728 | "s,t,p", AT, 0); | |
3729 | break; | |
3730 | ||
3731 | case M_BLEL: | |
3732 | likely = 1; | |
3733 | case M_BLE: | |
3734 | if (treg == 0) | |
3735 | { | |
3736 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3737 | likely ? "blezl" : "blez", | |
3738 | "s,p", sreg); | |
3739 | return; | |
3740 | } | |
3741 | if (sreg == 0) | |
3742 | { | |
3743 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3744 | likely ? "bgezl" : "bgez", | |
3745 | "s,p", treg); | |
3746 | return; | |
3747 | } | |
3748 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg); | |
3749 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3750 | likely ? "beql" : "beq", | |
3751 | "s,t,p", AT, 0); | |
3752 | break; | |
3753 | ||
3754 | case M_BLEL_I: | |
3755 | likely = 1; | |
3756 | case M_BLE_I: | |
3757 | maxnum = 0x7fffffff; | |
3758 | if (mips_opts.isa >= 3 && sizeof (maxnum) > 4) | |
3759 | { | |
3760 | maxnum <<= 16; | |
3761 | maxnum |= 0xffff; | |
3762 | maxnum <<= 16; | |
3763 | maxnum |= 0xffff; | |
3764 | } | |
3765 | if (imm_expr.X_op == O_constant | |
3766 | && imm_expr.X_add_number >= maxnum | |
3767 | && (mips_opts.isa < 3 || sizeof (maxnum) > 4)) | |
3768 | goto do_true; | |
3769 | if (imm_expr.X_op != O_constant) | |
3770 | as_bad (_("Unsupported large constant")); | |
3771 | imm_expr.X_add_number++; | |
3772 | /* FALLTHROUGH */ | |
3773 | case M_BLT_I: | |
3774 | case M_BLTL_I: | |
3775 | if (mask == M_BLTL_I) | |
3776 | likely = 1; | |
3777 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3778 | { | |
3779 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3780 | likely ? "bltzl" : "bltz", | |
3781 | "s,p", sreg); | |
3782 | return; | |
3783 | } | |
3784 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3785 | { | |
3786 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3787 | likely ? "blezl" : "blez", | |
3788 | "s,p", sreg); | |
3789 | return; | |
3790 | } | |
3791 | set_at (&icnt, sreg, 0); | |
3792 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3793 | likely ? "bnel" : "bne", | |
3794 | "s,t,p", AT, 0); | |
3795 | break; | |
3796 | ||
3797 | case M_BLEUL: | |
3798 | likely = 1; | |
3799 | case M_BLEU: | |
3800 | if (treg == 0) | |
3801 | { | |
3802 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3803 | likely ? "beql" : "beq", | |
3804 | "s,t,p", sreg, 0); | |
3805 | return; | |
3806 | } | |
3807 | if (sreg == 0) | |
3808 | goto do_true; | |
3809 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, | |
3810 | sreg); | |
3811 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3812 | likely ? "beql" : "beq", | |
3813 | "s,t,p", AT, 0); | |
3814 | break; | |
3815 | ||
3816 | case M_BLEUL_I: | |
3817 | likely = 1; | |
3818 | case M_BLEU_I: | |
3819 | if (sreg == 0 | |
3820 | || (mips_opts.isa < 3 | |
3821 | && imm_expr.X_op == O_constant | |
3822 | && imm_expr.X_add_number == 0xffffffff)) | |
3823 | goto do_true; | |
3824 | if (imm_expr.X_op != O_constant) | |
3825 | as_bad (_("Unsupported large constant")); | |
3826 | imm_expr.X_add_number++; | |
3827 | /* FALLTHROUGH */ | |
3828 | case M_BLTU_I: | |
3829 | case M_BLTUL_I: | |
3830 | if (mask == M_BLTUL_I) | |
3831 | likely = 1; | |
3832 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3833 | goto do_false; | |
3834 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3835 | { | |
3836 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3837 | likely ? "beql" : "beq", | |
3838 | "s,t,p", sreg, 0); | |
3839 | return; | |
3840 | } | |
3841 | set_at (&icnt, sreg, 1); | |
3842 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3843 | likely ? "bnel" : "bne", | |
3844 | "s,t,p", AT, 0); | |
3845 | break; | |
3846 | ||
3847 | case M_BLTL: | |
3848 | likely = 1; | |
3849 | case M_BLT: | |
3850 | if (treg == 0) | |
3851 | { | |
3852 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3853 | likely ? "bltzl" : "bltz", | |
3854 | "s,p", sreg); | |
3855 | return; | |
3856 | } | |
3857 | if (sreg == 0) | |
3858 | { | |
3859 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3860 | likely ? "bgtzl" : "bgtz", | |
3861 | "s,p", treg); | |
3862 | return; | |
3863 | } | |
3864 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg); | |
3865 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3866 | likely ? "bnel" : "bne", | |
3867 | "s,t,p", AT, 0); | |
3868 | break; | |
3869 | ||
3870 | case M_BLTUL: | |
3871 | likely = 1; | |
3872 | case M_BLTU: | |
3873 | if (treg == 0) | |
3874 | goto do_false; | |
3875 | if (sreg == 0) | |
3876 | { | |
3877 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3878 | likely ? "bnel" : "bne", | |
3879 | "s,t,p", 0, treg); | |
3880 | return; | |
3881 | } | |
3882 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, | |
3883 | treg); | |
3884 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3885 | likely ? "bnel" : "bne", | |
3886 | "s,t,p", AT, 0); | |
3887 | break; | |
3888 | ||
3889 | case M_DDIV_3: | |
3890 | dbl = 1; | |
3891 | case M_DIV_3: | |
3892 | s = "mflo"; | |
3893 | goto do_div3; | |
3894 | case M_DREM_3: | |
3895 | dbl = 1; | |
3896 | case M_REM_3: | |
3897 | s = "mfhi"; | |
3898 | do_div3: | |
3899 | if (treg == 0) | |
3900 | { | |
3901 | as_warn (_("Divide by zero.")); | |
3902 | if (mips_trap) | |
3903 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0); | |
3904 | else | |
3905 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); | |
3906 | return; | |
3907 | } | |
3908 | ||
3909 | mips_emit_delays (true); | |
3910 | ++mips_opts.noreorder; | |
3911 | mips_any_noreorder = 1; | |
3912 | if (mips_trap) | |
3913 | { | |
3914 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0); | |
3915 | macro_build ((char *) NULL, &icnt, NULL, | |
3916 | dbl ? "ddiv" : "div", | |
3917 | "z,s,t", sreg, treg); | |
3918 | } | |
3919 | else | |
3920 | { | |
3921 | expr1.X_add_number = 8; | |
3922 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
3923 | macro_build ((char *) NULL, &icnt, NULL, | |
3924 | dbl ? "ddiv" : "div", | |
3925 | "z,s,t", sreg, treg); | |
3926 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); | |
3927 | } | |
3928 | expr1.X_add_number = -1; | |
3929 | macro_build ((char *) NULL, &icnt, &expr1, | |
3930 | dbl ? "daddiu" : "addiu", | |
3931 | "t,r,j", AT, 0, (int) BFD_RELOC_LO16); | |
3932 | expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16); | |
3933 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT); | |
3934 | if (dbl) | |
3935 | { | |
3936 | expr1.X_add_number = 1; | |
3937 | macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0, | |
3938 | (int) BFD_RELOC_LO16); | |
3939 | macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT, | |
3940 | 31); | |
3941 | } | |
3942 | else | |
3943 | { | |
3944 | expr1.X_add_number = 0x80000000; | |
3945 | macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT, | |
3946 | (int) BFD_RELOC_HI16); | |
3947 | } | |
3948 | if (mips_trap) | |
3949 | { | |
3950 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", sreg, AT); | |
3951 | /* We want to close the noreorder block as soon as possible, so | |
3952 | that later insns are available for delay slot filling. */ | |
3953 | --mips_opts.noreorder; | |
3954 | } | |
3955 | else | |
3956 | { | |
3957 | expr1.X_add_number = 8; | |
3958 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT); | |
3959 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
3960 | ||
3961 | /* We want to close the noreorder block as soon as possible, so | |
3962 | that later insns are available for delay slot filling. */ | |
3963 | --mips_opts.noreorder; | |
3964 | ||
3965 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); | |
3966 | } | |
3967 | macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg); | |
3968 | break; | |
3969 | ||
3970 | case M_DIV_3I: | |
3971 | s = "div"; | |
3972 | s2 = "mflo"; | |
3973 | goto do_divi; | |
3974 | case M_DIVU_3I: | |
3975 | s = "divu"; | |
3976 | s2 = "mflo"; | |
3977 | goto do_divi; | |
3978 | case M_REM_3I: | |
3979 | s = "div"; | |
3980 | s2 = "mfhi"; | |
3981 | goto do_divi; | |
3982 | case M_REMU_3I: | |
3983 | s = "divu"; | |
3984 | s2 = "mfhi"; | |
3985 | goto do_divi; | |
3986 | case M_DDIV_3I: | |
3987 | dbl = 1; | |
3988 | s = "ddiv"; | |
3989 | s2 = "mflo"; | |
3990 | goto do_divi; | |
3991 | case M_DDIVU_3I: | |
3992 | dbl = 1; | |
3993 | s = "ddivu"; | |
3994 | s2 = "mflo"; | |
3995 | goto do_divi; | |
3996 | case M_DREM_3I: | |
3997 | dbl = 1; | |
3998 | s = "ddiv"; | |
3999 | s2 = "mfhi"; | |
4000 | goto do_divi; | |
4001 | case M_DREMU_3I: | |
4002 | dbl = 1; | |
4003 | s = "ddivu"; | |
4004 | s2 = "mfhi"; | |
4005 | do_divi: | |
4006 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4007 | { | |
4008 | as_warn (_("Divide by zero.")); | |
4009 | if (mips_trap) | |
4010 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0); | |
4011 | else | |
4012 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); | |
4013 | return; | |
4014 | } | |
4015 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4016 | { | |
4017 | if (strcmp (s2, "mflo") == 0) | |
4018 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, | |
4019 | sreg); | |
4020 | else | |
4021 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0); | |
4022 | return; | |
4023 | } | |
4024 | if (imm_expr.X_op == O_constant | |
4025 | && imm_expr.X_add_number == -1 | |
4026 | && s[strlen (s) - 1] != 'u') | |
4027 | { | |
4028 | if (strcmp (s2, "mflo") == 0) | |
4029 | { | |
4030 | if (dbl) | |
4031 | macro_build ((char *) NULL, &icnt, NULL, "dneg", "d,w", dreg, | |
4032 | sreg); | |
4033 | else | |
4034 | macro_build ((char *) NULL, &icnt, NULL, "neg", "d,w", dreg, | |
4035 | sreg); | |
4036 | } | |
4037 | else | |
4038 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0); | |
4039 | return; | |
4040 | } | |
4041 | ||
4042 | load_register (&icnt, AT, &imm_expr, dbl); | |
4043 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT); | |
4044 | macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg); | |
4045 | break; | |
4046 | ||
4047 | case M_DIVU_3: | |
4048 | s = "divu"; | |
4049 | s2 = "mflo"; | |
4050 | goto do_divu3; | |
4051 | case M_REMU_3: | |
4052 | s = "divu"; | |
4053 | s2 = "mfhi"; | |
4054 | goto do_divu3; | |
4055 | case M_DDIVU_3: | |
4056 | s = "ddivu"; | |
4057 | s2 = "mflo"; | |
4058 | goto do_divu3; | |
4059 | case M_DREMU_3: | |
4060 | s = "ddivu"; | |
4061 | s2 = "mfhi"; | |
4062 | do_divu3: | |
4063 | mips_emit_delays (true); | |
4064 | ++mips_opts.noreorder; | |
4065 | mips_any_noreorder = 1; | |
4066 | if (mips_trap) | |
4067 | { | |
4068 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0); | |
4069 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg); | |
4070 | /* We want to close the noreorder block as soon as possible, so | |
4071 | that later insns are available for delay slot filling. */ | |
4072 | --mips_opts.noreorder; | |
4073 | } | |
4074 | else | |
4075 | { | |
4076 | expr1.X_add_number = 8; | |
4077 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
4078 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg); | |
4079 | ||
4080 | /* We want to close the noreorder block as soon as possible, so | |
4081 | that later insns are available for delay slot filling. */ | |
4082 | --mips_opts.noreorder; | |
4083 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); | |
4084 | } | |
4085 | macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg); | |
4086 | return; | |
4087 | ||
4088 | case M_DLA_AB: | |
4089 | dbl = 1; | |
4090 | case M_LA_AB: | |
4091 | /* Load the address of a symbol into a register. If breg is not | |
4092 | zero, we then add a base register to it. */ | |
4093 | ||
4094 | /* When generating embedded PIC code, we permit expressions of | |
4095 | the form | |
4096 | la $4,foo-bar | |
4097 | where bar is an address in the .text section. These are used | |
4098 | when getting the addresses of functions. We don't permit | |
4099 | X_add_number to be non-zero, because if the symbol is | |
4100 | external the relaxing code needs to know that any addend is | |
4101 | purely the offset to X_op_symbol. */ | |
4102 | if (mips_pic == EMBEDDED_PIC | |
4103 | && offset_expr.X_op == O_subtract | |
4104 | && now_seg == text_section | |
49309057 | 4105 | && (symbol_constant_p (offset_expr.X_op_symbol) |
252b5132 | 4106 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == text_section |
49309057 ILT |
4107 | : (symbol_equated_p (offset_expr.X_op_symbol) |
4108 | && (S_GET_SEGMENT | |
4109 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
4110 | ->X_add_symbol) | |
252b5132 RH |
4111 | == text_section))) |
4112 | && breg == 0 | |
4113 | && offset_expr.X_add_number == 0) | |
4114 | { | |
4115 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4116 | treg, (int) BFD_RELOC_PCREL_HI16_S); | |
4117 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4118 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4119 | || mips_opts.isa < 3) | |
4120 | ? "addiu" : "daddiu"), | |
4121 | "t,r,j", treg, treg, (int) BFD_RELOC_PCREL_LO16); | |
4122 | return; | |
4123 | } | |
4124 | ||
4125 | if (offset_expr.X_op != O_symbol | |
4126 | && offset_expr.X_op != O_constant) | |
4127 | { | |
4128 | as_bad (_("expression too complex")); | |
4129 | offset_expr.X_op = O_constant; | |
4130 | } | |
4131 | ||
4132 | if (treg == breg) | |
4133 | { | |
4134 | tempreg = AT; | |
4135 | used_at = 1; | |
4136 | } | |
4137 | else | |
4138 | { | |
4139 | tempreg = treg; | |
4140 | used_at = 0; | |
4141 | } | |
4142 | ||
4143 | if (offset_expr.X_op == O_constant) | |
4144 | load_register (&icnt, tempreg, &offset_expr, dbl); | |
4145 | else if (mips_pic == NO_PIC) | |
4146 | { | |
4147 | /* If this is a reference to an GP relative symbol, we want | |
4148 | addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
4149 | Otherwise we want | |
4150 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4151 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4152 | If we have a constant, we need two instructions anyhow, | |
4153 | so we may as well always use the latter form. */ | |
4154 | if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET | |
4155 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
4156 | p = NULL; | |
4157 | else | |
4158 | { | |
4159 | frag_grow (20); | |
4160 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4161 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4162 | || mips_opts.isa < 3) | |
4163 | ? "addiu" : "daddiu"), | |
4164 | "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
4165 | p = frag_var (rs_machine_dependent, 8, 0, | |
4166 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
4167 | mips_opts.warn_about_macros), | |
4168 | offset_expr.X_add_symbol, (offsetT) 0, | |
4169 | (char *) NULL); | |
4170 | } | |
4171 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
4172 | if (p != NULL) | |
4173 | p += 4; | |
4174 | macro_build (p, &icnt, &offset_expr, | |
4175 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4176 | || mips_opts.isa < 3) | |
4177 | ? "addiu" : "daddiu"), | |
4178 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4179 | } | |
4180 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
4181 | { | |
4182 | /* If this is a reference to an external symbol, and there | |
4183 | is no constant, we want | |
4184 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4185 | For a local symbol, we want | |
4186 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4187 | nop | |
4188 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4189 | ||
4190 | If we have a small constant, and this is a reference to | |
4191 | an external symbol, we want | |
4192 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4193 | nop | |
4194 | addiu $tempreg,$tempreg,<constant> | |
4195 | For a local symbol, we want the same instruction | |
4196 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4197 | addiu instruction. | |
4198 | ||
4199 | If we have a large constant, and this is a reference to | |
4200 | an external symbol, we want | |
4201 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4202 | lui $at,<hiconstant> | |
4203 | addiu $at,$at,<loconstant> | |
4204 | addu $tempreg,$tempreg,$at | |
4205 | For a local symbol, we want the same instruction | |
4206 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4207 | addiu instruction. */ | |
4208 | expr1.X_add_number = offset_expr.X_add_number; | |
4209 | offset_expr.X_add_number = 0; | |
4210 | frag_grow (32); | |
4211 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4212 | dbl ? "ld" : "lw", | |
4213 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
4214 | if (expr1.X_add_number == 0) | |
4215 | { | |
4216 | int off; | |
4217 | ||
4218 | if (breg == 0) | |
4219 | off = 0; | |
4220 | else | |
4221 | { | |
4222 | /* We're going to put in an addu instruction using | |
4223 | tempreg, so we may as well insert the nop right | |
4224 | now. */ | |
4225 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4226 | "nop", ""); | |
4227 | off = 4; | |
4228 | } | |
4229 | p = frag_var (rs_machine_dependent, 8 - off, 0, | |
4230 | RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0, | |
4231 | (breg == 0 | |
4232 | ? mips_opts.warn_about_macros | |
4233 | : 0)), | |
4234 | offset_expr.X_add_symbol, (offsetT) 0, | |
4235 | (char *) NULL); | |
4236 | if (breg == 0) | |
4237 | { | |
4238 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4239 | p += 4; | |
4240 | } | |
4241 | macro_build (p, &icnt, &expr1, | |
4242 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4243 | || mips_opts.isa < 3) | |
4244 | ? "addiu" : "daddiu"), | |
4245 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4246 | /* FIXME: If breg == 0, and the next instruction uses | |
4247 | $tempreg, then if this variant case is used an extra | |
4248 | nop will be generated. */ | |
4249 | } | |
4250 | else if (expr1.X_add_number >= -0x8000 | |
4251 | && expr1.X_add_number < 0x8000) | |
4252 | { | |
4253 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4254 | "nop", ""); | |
4255 | macro_build ((char *) NULL, &icnt, &expr1, | |
4256 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4257 | || mips_opts.isa < 3) | |
4258 | ? "addiu" : "daddiu"), | |
4259 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4260 | (void) frag_var (rs_machine_dependent, 0, 0, | |
4261 | RELAX_ENCODE (0, 0, -12, -4, 0, 0), | |
4262 | offset_expr.X_add_symbol, (offsetT) 0, | |
4263 | (char *) NULL); | |
4264 | } | |
4265 | else | |
4266 | { | |
4267 | int off1; | |
4268 | ||
4269 | /* If we are going to add in a base register, and the | |
4270 | target register and the base register are the same, | |
4271 | then we are using AT as a temporary register. Since | |
4272 | we want to load the constant into AT, we add our | |
4273 | current AT (from the global offset table) and the | |
4274 | register into the register now, and pretend we were | |
4275 | not using a base register. */ | |
4276 | if (breg != treg) | |
4277 | off1 = 0; | |
4278 | else | |
4279 | { | |
4280 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4281 | "nop", ""); | |
4282 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4283 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4284 | || mips_opts.isa < 3) | |
4285 | ? "addu" : "daddu"), | |
4286 | "d,v,t", treg, AT, breg); | |
4287 | breg = 0; | |
4288 | tempreg = treg; | |
4289 | off1 = -8; | |
4290 | } | |
4291 | ||
4292 | /* Set mips_optimize around the lui instruction to avoid | |
4293 | inserting an unnecessary nop after the lw. */ | |
4294 | hold_mips_optimize = mips_optimize; | |
4295 | mips_optimize = 2; | |
4296 | macro_build_lui ((char *) NULL, &icnt, &expr1, AT); | |
4297 | mips_optimize = hold_mips_optimize; | |
4298 | ||
4299 | macro_build ((char *) NULL, &icnt, &expr1, | |
4300 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4301 | || mips_opts.isa < 3) | |
4302 | ? "addiu" : "daddiu"), | |
4303 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); | |
4304 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4305 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4306 | || mips_opts.isa < 3) | |
4307 | ? "addu" : "daddu"), | |
4308 | "d,v,t", tempreg, tempreg, AT); | |
4309 | (void) frag_var (rs_machine_dependent, 0, 0, | |
4310 | RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0), | |
4311 | offset_expr.X_add_symbol, (offsetT) 0, | |
4312 | (char *) NULL); | |
4313 | used_at = 1; | |
4314 | } | |
4315 | } | |
4316 | else if (mips_pic == SVR4_PIC) | |
4317 | { | |
4318 | int gpdel; | |
4319 | ||
4320 | /* This is the large GOT case. If this is a reference to an | |
4321 | external symbol, and there is no constant, we want | |
4322 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4323 | addu $tempreg,$tempreg,$gp | |
4324 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4325 | For a local symbol, we want | |
4326 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4327 | nop | |
4328 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4329 | ||
4330 | If we have a small constant, and this is a reference to | |
4331 | an external symbol, we want | |
4332 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4333 | addu $tempreg,$tempreg,$gp | |
4334 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4335 | nop | |
4336 | addiu $tempreg,$tempreg,<constant> | |
4337 | For a local symbol, we want | |
4338 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4339 | nop | |
4340 | addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16) | |
4341 | ||
4342 | If we have a large constant, and this is a reference to | |
4343 | an external symbol, we want | |
4344 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4345 | addu $tempreg,$tempreg,$gp | |
4346 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4347 | lui $at,<hiconstant> | |
4348 | addiu $at,$at,<loconstant> | |
4349 | addu $tempreg,$tempreg,$at | |
4350 | For a local symbol, we want | |
4351 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4352 | lui $at,<hiconstant> | |
4353 | addiu $at,$at,<loconstant> (BFD_RELOC_LO16) | |
4354 | addu $tempreg,$tempreg,$at | |
4355 | */ | |
4356 | expr1.X_add_number = offset_expr.X_add_number; | |
4357 | offset_expr.X_add_number = 0; | |
4358 | frag_grow (52); | |
4359 | if (reg_needs_delay (GP)) | |
4360 | gpdel = 4; | |
4361 | else | |
4362 | gpdel = 0; | |
4363 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4364 | tempreg, (int) BFD_RELOC_MIPS_GOT_HI16); | |
4365 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4366 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4367 | || mips_opts.isa < 3) | |
4368 | ? "addu" : "daddu"), | |
4369 | "d,v,t", tempreg, tempreg, GP); | |
4370 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4371 | dbl ? "ld" : "lw", | |
4372 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16, | |
4373 | tempreg); | |
4374 | if (expr1.X_add_number == 0) | |
4375 | { | |
4376 | int off; | |
4377 | ||
4378 | if (breg == 0) | |
4379 | off = 0; | |
4380 | else | |
4381 | { | |
4382 | /* We're going to put in an addu instruction using | |
4383 | tempreg, so we may as well insert the nop right | |
4384 | now. */ | |
4385 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4386 | "nop", ""); | |
4387 | off = 4; | |
4388 | } | |
4389 | ||
4390 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4391 | RELAX_ENCODE (12 + off, 12 + gpdel, gpdel, | |
4392 | 8 + gpdel, 0, | |
4393 | (breg == 0 | |
4394 | ? mips_opts.warn_about_macros | |
4395 | : 0)), | |
4396 | offset_expr.X_add_symbol, (offsetT) 0, | |
4397 | (char *) NULL); | |
4398 | } | |
4399 | else if (expr1.X_add_number >= -0x8000 | |
4400 | && expr1.X_add_number < 0x8000) | |
4401 | { | |
4402 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4403 | "nop", ""); | |
4404 | macro_build ((char *) NULL, &icnt, &expr1, | |
4405 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4406 | || mips_opts.isa < 3) | |
4407 | ? "addiu" : "daddiu"), | |
4408 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4409 | ||
4410 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4411 | RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0, | |
4412 | (breg == 0 | |
4413 | ? mips_opts.warn_about_macros | |
4414 | : 0)), | |
4415 | offset_expr.X_add_symbol, (offsetT) 0, | |
4416 | (char *) NULL); | |
4417 | } | |
4418 | else | |
4419 | { | |
4420 | int adj, dreg; | |
4421 | ||
4422 | /* If we are going to add in a base register, and the | |
4423 | target register and the base register are the same, | |
4424 | then we are using AT as a temporary register. Since | |
4425 | we want to load the constant into AT, we add our | |
4426 | current AT (from the global offset table) and the | |
4427 | register into the register now, and pretend we were | |
4428 | not using a base register. */ | |
4429 | if (breg != treg) | |
4430 | { | |
4431 | adj = 0; | |
4432 | dreg = tempreg; | |
4433 | } | |
4434 | else | |
4435 | { | |
4436 | assert (tempreg == AT); | |
4437 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4438 | "nop", ""); | |
4439 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4440 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4441 | || mips_opts.isa < 3) | |
4442 | ? "addu" : "daddu"), | |
4443 | "d,v,t", treg, AT, breg); | |
4444 | dreg = treg; | |
4445 | adj = 8; | |
4446 | } | |
4447 | ||
4448 | /* Set mips_optimize around the lui instruction to avoid | |
4449 | inserting an unnecessary nop after the lw. */ | |
4450 | hold_mips_optimize = mips_optimize; | |
4451 | mips_optimize = 2; | |
4452 | macro_build_lui ((char *) NULL, &icnt, &expr1, AT); | |
4453 | mips_optimize = hold_mips_optimize; | |
4454 | ||
4455 | macro_build ((char *) NULL, &icnt, &expr1, | |
4456 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4457 | || mips_opts.isa < 3) | |
4458 | ? "addiu" : "daddiu"), | |
4459 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); | |
4460 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4461 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4462 | || mips_opts.isa < 3) | |
4463 | ? "addu" : "daddu"), | |
4464 | "d,v,t", dreg, dreg, AT); | |
4465 | ||
4466 | p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0, | |
4467 | RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel, | |
4468 | 8 + gpdel, 0, | |
4469 | (breg == 0 | |
4470 | ? mips_opts.warn_about_macros | |
4471 | : 0)), | |
4472 | offset_expr.X_add_symbol, (offsetT) 0, | |
4473 | (char *) NULL); | |
4474 | ||
4475 | used_at = 1; | |
4476 | } | |
4477 | ||
4478 | if (gpdel > 0) | |
4479 | { | |
4480 | /* This is needed because this instruction uses $gp, but | |
4481 | the first instruction on the main stream does not. */ | |
4482 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4483 | p += 4; | |
4484 | } | |
4485 | macro_build (p, &icnt, &offset_expr, | |
4486 | dbl ? "ld" : "lw", | |
4487 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
4488 | p += 4; | |
4489 | if (expr1.X_add_number >= -0x8000 | |
4490 | && expr1.X_add_number < 0x8000) | |
4491 | { | |
4492 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4493 | p += 4; | |
4494 | macro_build (p, &icnt, &expr1, | |
4495 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4496 | || mips_opts.isa < 3) | |
4497 | ? "addiu" : "daddiu"), | |
4498 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4499 | /* FIXME: If add_number is 0, and there was no base | |
4500 | register, the external symbol case ended with a load, | |
4501 | so if the symbol turns out to not be external, and | |
4502 | the next instruction uses tempreg, an unnecessary nop | |
4503 | will be inserted. */ | |
4504 | } | |
4505 | else | |
4506 | { | |
4507 | if (breg == treg) | |
4508 | { | |
4509 | /* We must add in the base register now, as in the | |
4510 | external symbol case. */ | |
4511 | assert (tempreg == AT); | |
4512 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4513 | p += 4; | |
4514 | macro_build (p, &icnt, (expressionS *) NULL, | |
4515 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4516 | || mips_opts.isa < 3) | |
4517 | ? "addu" : "daddu"), | |
4518 | "d,v,t", treg, AT, breg); | |
4519 | p += 4; | |
4520 | tempreg = treg; | |
4521 | /* We set breg to 0 because we have arranged to add | |
4522 | it in in both cases. */ | |
4523 | breg = 0; | |
4524 | } | |
4525 | ||
4526 | macro_build_lui (p, &icnt, &expr1, AT); | |
4527 | p += 4; | |
4528 | macro_build (p, &icnt, &expr1, | |
4529 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4530 | || mips_opts.isa < 3) | |
4531 | ? "addiu" : "daddiu"), | |
4532 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); | |
4533 | p += 4; | |
4534 | macro_build (p, &icnt, (expressionS *) NULL, | |
4535 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4536 | || mips_opts.isa < 3) | |
4537 | ? "addu" : "daddu"), | |
4538 | "d,v,t", tempreg, tempreg, AT); | |
4539 | p += 4; | |
4540 | } | |
4541 | } | |
4542 | else if (mips_pic == EMBEDDED_PIC) | |
4543 | { | |
4544 | /* We use | |
4545 | addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
4546 | */ | |
4547 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4548 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4549 | || mips_opts.isa < 3) | |
4550 | ? "addiu" : "daddiu"), | |
4551 | "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
4552 | } | |
4553 | else | |
4554 | abort (); | |
4555 | ||
4556 | if (breg != 0) | |
4557 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4558 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4559 | || mips_opts.isa < 3) | |
4560 | ? "addu" : "daddu"), | |
4561 | "d,v,t", treg, tempreg, breg); | |
4562 | ||
4563 | if (! used_at) | |
4564 | return; | |
4565 | ||
4566 | break; | |
4567 | ||
4568 | case M_J_A: | |
4569 | /* The j instruction may not be used in PIC code, since it | |
4570 | requires an absolute address. We convert it to a b | |
4571 | instruction. */ | |
4572 | if (mips_pic == NO_PIC) | |
4573 | macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a"); | |
4574 | else | |
4575 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
4576 | return; | |
4577 | ||
4578 | /* The jal instructions must be handled as macros because when | |
4579 | generating PIC code they expand to multi-instruction | |
4580 | sequences. Normally they are simple instructions. */ | |
4581 | case M_JAL_1: | |
4582 | dreg = RA; | |
4583 | /* Fall through. */ | |
4584 | case M_JAL_2: | |
4585 | if (mips_pic == NO_PIC | |
4586 | || mips_pic == EMBEDDED_PIC) | |
4587 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", | |
4588 | "d,s", dreg, sreg); | |
4589 | else if (mips_pic == SVR4_PIC) | |
4590 | { | |
4591 | if (sreg != PIC_CALL_REG) | |
4592 | as_warn (_("MIPS PIC call to register other than $25")); | |
4593 | ||
4594 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", | |
4595 | "d,s", dreg, sreg); | |
4596 | if (mips_cprestore_offset < 0) | |
4597 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
4598 | else | |
4599 | { | |
4600 | expr1.X_add_number = mips_cprestore_offset; | |
4601 | macro_build ((char *) NULL, &icnt, &expr1, | |
4602 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4603 | || mips_opts.isa < 3) | |
4604 | ? "lw" : "ld"), | |
4605 | "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg); | |
4606 | } | |
4607 | } | |
4608 | else | |
4609 | abort (); | |
4610 | ||
4611 | return; | |
4612 | ||
4613 | case M_JAL_A: | |
4614 | if (mips_pic == NO_PIC) | |
4615 | macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a"); | |
4616 | else if (mips_pic == SVR4_PIC) | |
4617 | { | |
4618 | /* If this is a reference to an external symbol, and we are | |
4619 | using a small GOT, we want | |
4620 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
4621 | nop | |
4622 | jalr $25 | |
4623 | nop | |
4624 | lw $gp,cprestore($sp) | |
4625 | The cprestore value is set using the .cprestore | |
4626 | pseudo-op. If we are using a big GOT, we want | |
4627 | lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
4628 | addu $25,$25,$gp | |
4629 | lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16) | |
4630 | nop | |
4631 | jalr $25 | |
4632 | nop | |
4633 | lw $gp,cprestore($sp) | |
4634 | If the symbol is not external, we want | |
4635 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4636 | nop | |
4637 | addiu $25,$25,<sym> (BFD_RELOC_LO16) | |
4638 | jalr $25 | |
4639 | nop | |
4640 | lw $gp,cprestore($sp) */ | |
4641 | frag_grow (40); | |
4642 | if (! mips_big_got) | |
4643 | { | |
4644 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4645 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4646 | || mips_opts.isa < 3) | |
4647 | ? "lw" : "ld"), | |
4648 | "t,o(b)", PIC_CALL_REG, | |
4649 | (int) BFD_RELOC_MIPS_CALL16, GP); | |
4650 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4651 | "nop", ""); | |
4652 | p = frag_var (rs_machine_dependent, 4, 0, | |
4653 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), | |
4654 | offset_expr.X_add_symbol, (offsetT) 0, | |
4655 | (char *) NULL); | |
4656 | } | |
4657 | else | |
4658 | { | |
4659 | int gpdel; | |
4660 | ||
4661 | if (reg_needs_delay (GP)) | |
4662 | gpdel = 4; | |
4663 | else | |
4664 | gpdel = 0; | |
4665 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4666 | PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16); | |
4667 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4668 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4669 | || mips_opts.isa < 3) | |
4670 | ? "addu" : "daddu"), | |
4671 | "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP); | |
4672 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4673 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4674 | || mips_opts.isa < 3) | |
4675 | ? "lw" : "ld"), | |
4676 | "t,o(b)", PIC_CALL_REG, | |
4677 | (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG); | |
4678 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4679 | "nop", ""); | |
4680 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4681 | RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel, | |
4682 | 0, 0), | |
4683 | offset_expr.X_add_symbol, (offsetT) 0, | |
4684 | (char *) NULL); | |
4685 | if (gpdel > 0) | |
4686 | { | |
4687 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4688 | p += 4; | |
4689 | } | |
4690 | macro_build (p, &icnt, &offset_expr, | |
4691 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4692 | || mips_opts.isa < 3) | |
4693 | ? "lw" : "ld"), | |
4694 | "t,o(b)", PIC_CALL_REG, | |
4695 | (int) BFD_RELOC_MIPS_GOT16, GP); | |
4696 | p += 4; | |
4697 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4698 | p += 4; | |
4699 | } | |
4700 | macro_build (p, &icnt, &offset_expr, | |
4701 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4702 | || mips_opts.isa < 3) | |
4703 | ? "addiu" : "daddiu"), | |
4704 | "t,r,j", PIC_CALL_REG, PIC_CALL_REG, | |
4705 | (int) BFD_RELOC_LO16); | |
4706 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4707 | "jalr", "s", PIC_CALL_REG); | |
4708 | if (mips_cprestore_offset < 0) | |
4709 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
4710 | else | |
4711 | { | |
4712 | if (mips_opts.noreorder) | |
4713 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4714 | "nop", ""); | |
4715 | expr1.X_add_number = mips_cprestore_offset; | |
4716 | macro_build ((char *) NULL, &icnt, &expr1, | |
4717 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4718 | || mips_opts.isa < 3) | |
4719 | ? "lw" : "ld"), | |
4720 | "t,o(b)", GP, (int) BFD_RELOC_LO16, | |
4721 | mips_frame_reg); | |
4722 | } | |
4723 | } | |
4724 | else if (mips_pic == EMBEDDED_PIC) | |
4725 | { | |
4726 | macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p"); | |
4727 | /* The linker may expand the call to a longer sequence which | |
4728 | uses $at, so we must break rather than return. */ | |
4729 | break; | |
4730 | } | |
4731 | else | |
4732 | abort (); | |
4733 | ||
4734 | return; | |
4735 | ||
4736 | case M_LB_AB: | |
4737 | s = "lb"; | |
4738 | goto ld; | |
4739 | case M_LBU_AB: | |
4740 | s = "lbu"; | |
4741 | goto ld; | |
4742 | case M_LH_AB: | |
4743 | s = "lh"; | |
4744 | goto ld; | |
4745 | case M_LHU_AB: | |
4746 | s = "lhu"; | |
4747 | goto ld; | |
4748 | case M_LW_AB: | |
4749 | s = "lw"; | |
4750 | goto ld; | |
4751 | case M_LWC0_AB: | |
4752 | s = "lwc0"; | |
4753 | /* Itbl support may require additional care here. */ | |
4754 | coproc = 1; | |
4755 | goto ld; | |
4756 | case M_LWC1_AB: | |
4757 | s = "lwc1"; | |
4758 | /* Itbl support may require additional care here. */ | |
4759 | coproc = 1; | |
4760 | goto ld; | |
4761 | case M_LWC2_AB: | |
4762 | s = "lwc2"; | |
4763 | /* Itbl support may require additional care here. */ | |
4764 | coproc = 1; | |
4765 | goto ld; | |
4766 | case M_LWC3_AB: | |
4767 | s = "lwc3"; | |
4768 | /* Itbl support may require additional care here. */ | |
4769 | coproc = 1; | |
4770 | goto ld; | |
4771 | case M_LWL_AB: | |
4772 | s = "lwl"; | |
4773 | lr = 1; | |
4774 | goto ld; | |
4775 | case M_LWR_AB: | |
4776 | s = "lwr"; | |
4777 | lr = 1; | |
4778 | goto ld; | |
4779 | case M_LDC1_AB: | |
4780 | if (mips_cpu == 4650) | |
4781 | { | |
4782 | as_bad (_("opcode not supported on this processor")); | |
4783 | return; | |
4784 | } | |
4785 | s = "ldc1"; | |
4786 | /* Itbl support may require additional care here. */ | |
4787 | coproc = 1; | |
4788 | goto ld; | |
4789 | case M_LDC2_AB: | |
4790 | s = "ldc2"; | |
4791 | /* Itbl support may require additional care here. */ | |
4792 | coproc = 1; | |
4793 | goto ld; | |
4794 | case M_LDC3_AB: | |
4795 | s = "ldc3"; | |
4796 | /* Itbl support may require additional care here. */ | |
4797 | coproc = 1; | |
4798 | goto ld; | |
4799 | case M_LDL_AB: | |
4800 | s = "ldl"; | |
4801 | lr = 1; | |
4802 | goto ld; | |
4803 | case M_LDR_AB: | |
4804 | s = "ldr"; | |
4805 | lr = 1; | |
4806 | goto ld; | |
4807 | case M_LL_AB: | |
4808 | s = "ll"; | |
4809 | goto ld; | |
4810 | case M_LLD_AB: | |
4811 | s = "lld"; | |
4812 | goto ld; | |
4813 | case M_LWU_AB: | |
4814 | s = "lwu"; | |
4815 | ld: | |
4816 | if (breg == treg || coproc || lr) | |
4817 | { | |
4818 | tempreg = AT; | |
4819 | used_at = 1; | |
4820 | } | |
4821 | else | |
4822 | { | |
4823 | tempreg = treg; | |
4824 | used_at = 0; | |
4825 | } | |
4826 | goto ld_st; | |
4827 | case M_SB_AB: | |
4828 | s = "sb"; | |
4829 | goto st; | |
4830 | case M_SH_AB: | |
4831 | s = "sh"; | |
4832 | goto st; | |
4833 | case M_SW_AB: | |
4834 | s = "sw"; | |
4835 | goto st; | |
4836 | case M_SWC0_AB: | |
4837 | s = "swc0"; | |
4838 | /* Itbl support may require additional care here. */ | |
4839 | coproc = 1; | |
4840 | goto st; | |
4841 | case M_SWC1_AB: | |
4842 | s = "swc1"; | |
4843 | /* Itbl support may require additional care here. */ | |
4844 | coproc = 1; | |
4845 | goto st; | |
4846 | case M_SWC2_AB: | |
4847 | s = "swc2"; | |
4848 | /* Itbl support may require additional care here. */ | |
4849 | coproc = 1; | |
4850 | goto st; | |
4851 | case M_SWC3_AB: | |
4852 | s = "swc3"; | |
4853 | /* Itbl support may require additional care here. */ | |
4854 | coproc = 1; | |
4855 | goto st; | |
4856 | case M_SWL_AB: | |
4857 | s = "swl"; | |
4858 | goto st; | |
4859 | case M_SWR_AB: | |
4860 | s = "swr"; | |
4861 | goto st; | |
4862 | case M_SC_AB: | |
4863 | s = "sc"; | |
4864 | goto st; | |
4865 | case M_SCD_AB: | |
4866 | s = "scd"; | |
4867 | goto st; | |
4868 | case M_SDC1_AB: | |
4869 | if (mips_cpu == 4650) | |
4870 | { | |
4871 | as_bad (_("opcode not supported on this processor")); | |
4872 | return; | |
4873 | } | |
4874 | s = "sdc1"; | |
4875 | coproc = 1; | |
4876 | /* Itbl support may require additional care here. */ | |
4877 | goto st; | |
4878 | case M_SDC2_AB: | |
4879 | s = "sdc2"; | |
4880 | /* Itbl support may require additional care here. */ | |
4881 | coproc = 1; | |
4882 | goto st; | |
4883 | case M_SDC3_AB: | |
4884 | s = "sdc3"; | |
4885 | /* Itbl support may require additional care here. */ | |
4886 | coproc = 1; | |
4887 | goto st; | |
4888 | case M_SDL_AB: | |
4889 | s = "sdl"; | |
4890 | goto st; | |
4891 | case M_SDR_AB: | |
4892 | s = "sdr"; | |
4893 | st: | |
4894 | tempreg = AT; | |
4895 | used_at = 1; | |
4896 | ld_st: | |
4897 | /* Itbl support may require additional care here. */ | |
4898 | if (mask == M_LWC1_AB | |
4899 | || mask == M_SWC1_AB | |
4900 | || mask == M_LDC1_AB | |
4901 | || mask == M_SDC1_AB | |
4902 | || mask == M_L_DAB | |
4903 | || mask == M_S_DAB) | |
4904 | fmt = "T,o(b)"; | |
4905 | else if (coproc) | |
4906 | fmt = "E,o(b)"; | |
4907 | else | |
4908 | fmt = "t,o(b)"; | |
4909 | ||
4910 | if (offset_expr.X_op != O_constant | |
4911 | && offset_expr.X_op != O_symbol) | |
4912 | { | |
4913 | as_bad (_("expression too complex")); | |
4914 | offset_expr.X_op = O_constant; | |
4915 | } | |
4916 | ||
4917 | /* A constant expression in PIC code can be handled just as it | |
4918 | is in non PIC code. */ | |
4919 | if (mips_pic == NO_PIC | |
4920 | || offset_expr.X_op == O_constant) | |
4921 | { | |
4922 | /* If this is a reference to a GP relative symbol, and there | |
4923 | is no base register, we want | |
4924 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
4925 | Otherwise, if there is no base register, we want | |
4926 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4927 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
4928 | If we have a constant, we need two instructions anyhow, | |
4929 | so we always use the latter form. | |
4930 | ||
4931 | If we have a base register, and this is a reference to a | |
4932 | GP relative symbol, we want | |
4933 | addu $tempreg,$breg,$gp | |
4934 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL) | |
4935 | Otherwise we want | |
4936 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4937 | addu $tempreg,$tempreg,$breg | |
4938 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
4939 | With a constant we always use the latter case. */ | |
4940 | if (breg == 0) | |
4941 | { | |
4942 | if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET | |
4943 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
4944 | p = NULL; | |
4945 | else | |
4946 | { | |
4947 | frag_grow (20); | |
4948 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
4949 | treg, (int) BFD_RELOC_MIPS_GPREL, GP); | |
4950 | p = frag_var (rs_machine_dependent, 8, 0, | |
4951 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
4952 | (mips_opts.warn_about_macros | |
4953 | || (used_at | |
4954 | && mips_opts.noat))), | |
4955 | offset_expr.X_add_symbol, (offsetT) 0, | |
4956 | (char *) NULL); | |
4957 | used_at = 0; | |
4958 | } | |
4959 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
4960 | if (p != NULL) | |
4961 | p += 4; | |
4962 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
4963 | (int) BFD_RELOC_LO16, tempreg); | |
4964 | } | |
4965 | else | |
4966 | { | |
4967 | if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET | |
4968 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
4969 | p = NULL; | |
4970 | else | |
4971 | { | |
4972 | frag_grow (28); | |
4973 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4974 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4975 | || mips_opts.isa < 3) | |
4976 | ? "addu" : "daddu"), | |
4977 | "d,v,t", tempreg, breg, GP); | |
4978 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
4979 | treg, (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
4980 | p = frag_var (rs_machine_dependent, 12, 0, | |
4981 | RELAX_ENCODE (8, 12, 0, 8, 0, 0), | |
4982 | offset_expr.X_add_symbol, (offsetT) 0, | |
4983 | (char *) NULL); | |
4984 | } | |
4985 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
4986 | if (p != NULL) | |
4987 | p += 4; | |
4988 | macro_build (p, &icnt, (expressionS *) NULL, | |
4989 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
4990 | || mips_opts.isa < 3) | |
4991 | ? "addu" : "daddu"), | |
4992 | "d,v,t", tempreg, tempreg, breg); | |
4993 | if (p != NULL) | |
4994 | p += 4; | |
4995 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
4996 | (int) BFD_RELOC_LO16, tempreg); | |
4997 | } | |
4998 | } | |
4999 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
5000 | { | |
5001 | /* If this is a reference to an external symbol, we want | |
5002 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5003 | nop | |
5004 | <op> $treg,0($tempreg) | |
5005 | Otherwise we want | |
5006 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5007 | nop | |
5008 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5009 | <op> $treg,0($tempreg) | |
5010 | If there is a base register, we add it to $tempreg before | |
5011 | the <op>. If there is a constant, we stick it in the | |
5012 | <op> instruction. We don't handle constants larger than | |
5013 | 16 bits, because we have no way to load the upper 16 bits | |
5014 | (actually, we could handle them for the subset of cases | |
5015 | in which we are not using $at). */ | |
5016 | assert (offset_expr.X_op == O_symbol); | |
5017 | expr1.X_add_number = offset_expr.X_add_number; | |
5018 | offset_expr.X_add_number = 0; | |
5019 | if (expr1.X_add_number < -0x8000 | |
5020 | || expr1.X_add_number >= 0x8000) | |
5021 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5022 | frag_grow (20); | |
5023 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5024 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5025 | || mips_opts.isa < 3) | |
5026 | ? "lw" : "ld"), | |
5027 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5028 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
5029 | p = frag_var (rs_machine_dependent, 4, 0, | |
5030 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), | |
5031 | offset_expr.X_add_symbol, (offsetT) 0, | |
5032 | (char *) NULL); | |
5033 | macro_build (p, &icnt, &offset_expr, | |
5034 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5035 | || mips_opts.isa < 3) | |
5036 | ? "addiu" : "daddiu"), | |
5037 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
5038 | if (breg != 0) | |
5039 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5040 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5041 | || mips_opts.isa < 3) | |
5042 | ? "addu" : "daddu"), | |
5043 | "d,v,t", tempreg, tempreg, breg); | |
5044 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5045 | (int) BFD_RELOC_LO16, tempreg); | |
5046 | } | |
5047 | else if (mips_pic == SVR4_PIC) | |
5048 | { | |
5049 | int gpdel; | |
5050 | ||
5051 | /* If this is a reference to an external symbol, we want | |
5052 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5053 | addu $tempreg,$tempreg,$gp | |
5054 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
5055 | <op> $treg,0($tempreg) | |
5056 | Otherwise we want | |
5057 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5058 | nop | |
5059 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5060 | <op> $treg,0($tempreg) | |
5061 | If there is a base register, we add it to $tempreg before | |
5062 | the <op>. If there is a constant, we stick it in the | |
5063 | <op> instruction. We don't handle constants larger than | |
5064 | 16 bits, because we have no way to load the upper 16 bits | |
5065 | (actually, we could handle them for the subset of cases | |
5066 | in which we are not using $at). */ | |
5067 | assert (offset_expr.X_op == O_symbol); | |
5068 | expr1.X_add_number = offset_expr.X_add_number; | |
5069 | offset_expr.X_add_number = 0; | |
5070 | if (expr1.X_add_number < -0x8000 | |
5071 | || expr1.X_add_number >= 0x8000) | |
5072 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5073 | if (reg_needs_delay (GP)) | |
5074 | gpdel = 4; | |
5075 | else | |
5076 | gpdel = 0; | |
5077 | frag_grow (36); | |
5078 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5079 | tempreg, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5080 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5081 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5082 | || mips_opts.isa < 3) | |
5083 | ? "addu" : "daddu"), | |
5084 | "d,v,t", tempreg, tempreg, GP); | |
5085 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5086 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5087 | || mips_opts.isa < 3) | |
5088 | ? "lw" : "ld"), | |
5089 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16, | |
5090 | tempreg); | |
5091 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5092 | RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0), | |
5093 | offset_expr.X_add_symbol, (offsetT) 0, (char *) NULL); | |
5094 | if (gpdel > 0) | |
5095 | { | |
5096 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5097 | p += 4; | |
5098 | } | |
5099 | macro_build (p, &icnt, &offset_expr, | |
5100 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5101 | || mips_opts.isa < 3) | |
5102 | ? "lw" : "ld"), | |
5103 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5104 | p += 4; | |
5105 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5106 | p += 4; | |
5107 | macro_build (p, &icnt, &offset_expr, | |
5108 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5109 | || mips_opts.isa < 3) | |
5110 | ? "addiu" : "daddiu"), | |
5111 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
5112 | if (breg != 0) | |
5113 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5114 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5115 | || mips_opts.isa < 3) | |
5116 | ? "addu" : "daddu"), | |
5117 | "d,v,t", tempreg, tempreg, breg); | |
5118 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5119 | (int) BFD_RELOC_LO16, tempreg); | |
5120 | } | |
5121 | else if (mips_pic == EMBEDDED_PIC) | |
5122 | { | |
5123 | /* If there is no base register, we want | |
5124 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5125 | If there is a base register, we want | |
5126 | addu $tempreg,$breg,$gp | |
5127 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL) | |
5128 | */ | |
5129 | assert (offset_expr.X_op == O_symbol); | |
5130 | if (breg == 0) | |
5131 | { | |
5132 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5133 | treg, (int) BFD_RELOC_MIPS_GPREL, GP); | |
5134 | used_at = 0; | |
5135 | } | |
5136 | else | |
5137 | { | |
5138 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5139 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5140 | || mips_opts.isa < 3) | |
5141 | ? "addu" : "daddu"), | |
5142 | "d,v,t", tempreg, breg, GP); | |
5143 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5144 | treg, (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5145 | } | |
5146 | } | |
5147 | else | |
5148 | abort (); | |
5149 | ||
5150 | if (! used_at) | |
5151 | return; | |
5152 | ||
5153 | break; | |
5154 | ||
5155 | case M_LI: | |
5156 | case M_LI_S: | |
5157 | load_register (&icnt, treg, &imm_expr, 0); | |
5158 | return; | |
5159 | ||
5160 | case M_DLI: | |
5161 | load_register (&icnt, treg, &imm_expr, 1); | |
5162 | return; | |
5163 | ||
5164 | case M_LI_SS: | |
5165 | if (imm_expr.X_op == O_constant) | |
5166 | { | |
5167 | load_register (&icnt, AT, &imm_expr, 0); | |
5168 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5169 | "mtc1", "t,G", AT, treg); | |
5170 | break; | |
5171 | } | |
5172 | else | |
5173 | { | |
5174 | assert (offset_expr.X_op == O_symbol | |
5175 | && strcmp (segment_name (S_GET_SEGMENT | |
5176 | (offset_expr.X_add_symbol)), | |
5177 | ".lit4") == 0 | |
5178 | && offset_expr.X_add_number == 0); | |
5179 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5180 | treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5181 | return; | |
5182 | } | |
5183 | ||
5184 | case M_LI_D: | |
5185 | /* If we have a constant in IMM_EXPR, then in mips3 mode it is | |
5186 | the entire value, and in mips1 mode it is the high order 32 | |
5187 | bits of the value and the low order 32 bits are either zero | |
5188 | or in offset_expr. */ | |
5189 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) | |
5190 | { | |
5191 | if (mips_opts.isa >= 3) | |
5192 | load_register (&icnt, treg, &imm_expr, 1); | |
5193 | else | |
5194 | { | |
5195 | int hreg, lreg; | |
5196 | ||
5197 | if (target_big_endian) | |
5198 | { | |
5199 | hreg = treg; | |
5200 | lreg = treg + 1; | |
5201 | } | |
5202 | else | |
5203 | { | |
5204 | hreg = treg + 1; | |
5205 | lreg = treg; | |
5206 | } | |
5207 | ||
5208 | if (hreg <= 31) | |
5209 | load_register (&icnt, hreg, &imm_expr, 0); | |
5210 | if (lreg <= 31) | |
5211 | { | |
5212 | if (offset_expr.X_op == O_absent) | |
5213 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", | |
5214 | lreg, 0); | |
5215 | else | |
5216 | { | |
5217 | assert (offset_expr.X_op == O_constant); | |
5218 | load_register (&icnt, lreg, &offset_expr, 0); | |
5219 | } | |
5220 | } | |
5221 | } | |
5222 | return; | |
5223 | } | |
5224 | ||
5225 | /* We know that sym is in the .rdata section. First we get the | |
5226 | upper 16 bits of the address. */ | |
5227 | if (mips_pic == NO_PIC) | |
5228 | { | |
5229 | /* FIXME: This won't work for a 64 bit address. */ | |
5230 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5231 | } | |
5232 | else if (mips_pic == SVR4_PIC) | |
5233 | { | |
5234 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5235 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5236 | || mips_opts.isa < 3) | |
5237 | ? "lw" : "ld"), | |
5238 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5239 | } | |
5240 | else if (mips_pic == EMBEDDED_PIC) | |
5241 | { | |
5242 | /* For embedded PIC we pick up the entire address off $gp in | |
5243 | a single instruction. */ | |
5244 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5245 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5246 | || mips_opts.isa < 3) | |
5247 | ? "addiu" : "daddiu"), | |
5248 | "t,r,j", AT, GP, (int) BFD_RELOC_MIPS_GPREL); | |
5249 | offset_expr.X_op = O_constant; | |
5250 | offset_expr.X_add_number = 0; | |
5251 | } | |
5252 | else | |
5253 | abort (); | |
5254 | ||
5255 | /* Now we load the register(s). */ | |
5256 | if (mips_opts.isa >= 3) | |
5257 | macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)", | |
5258 | treg, (int) BFD_RELOC_LO16, AT); | |
5259 | else | |
5260 | { | |
5261 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5262 | treg, (int) BFD_RELOC_LO16, AT); | |
5263 | if (treg != 31) | |
5264 | { | |
5265 | /* FIXME: How in the world do we deal with the possible | |
5266 | overflow here? */ | |
5267 | offset_expr.X_add_number += 4; | |
5268 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5269 | treg + 1, (int) BFD_RELOC_LO16, AT); | |
5270 | } | |
5271 | } | |
5272 | ||
5273 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5274 | does not become a variant frag. */ | |
5275 | frag_wane (frag_now); | |
5276 | frag_new (0); | |
5277 | ||
5278 | break; | |
5279 | ||
5280 | case M_LI_DD: | |
5281 | /* If we have a constant in IMM_EXPR, then in mips3 mode it is | |
5282 | the entire value, and in mips1 mode it is the high order 32 | |
5283 | bits of the value and the low order 32 bits are either zero | |
5284 | or in offset_expr. */ | |
5285 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) | |
5286 | { | |
5287 | load_register (&icnt, AT, &imm_expr, mips_opts.isa >= 3); | |
5288 | if (mips_opts.isa >= 3) | |
5289 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5290 | "dmtc1", "t,S", AT, treg); | |
5291 | else | |
5292 | { | |
5293 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5294 | "mtc1", "t,G", AT, treg + 1); | |
5295 | if (offset_expr.X_op == O_absent) | |
5296 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5297 | "mtc1", "t,G", 0, treg); | |
5298 | else | |
5299 | { | |
5300 | assert (offset_expr.X_op == O_constant); | |
5301 | load_register (&icnt, AT, &offset_expr, 0); | |
5302 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5303 | "mtc1", "t,G", AT, treg); | |
5304 | } | |
5305 | } | |
5306 | break; | |
5307 | } | |
5308 | ||
5309 | assert (offset_expr.X_op == O_symbol | |
5310 | && offset_expr.X_add_number == 0); | |
5311 | s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol)); | |
5312 | if (strcmp (s, ".lit8") == 0) | |
5313 | { | |
5314 | if (mips_opts.isa >= 2) | |
5315 | { | |
5316 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5317 | "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5318 | return; | |
5319 | } | |
5320 | breg = GP; | |
5321 | r = BFD_RELOC_MIPS_LITERAL; | |
5322 | goto dob; | |
5323 | } | |
5324 | else | |
5325 | { | |
5326 | assert (strcmp (s, RDATA_SECTION_NAME) == 0); | |
5327 | if (mips_pic == SVR4_PIC) | |
5328 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5329 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5330 | || mips_opts.isa < 3) | |
5331 | ? "lw" : "ld"), | |
5332 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5333 | else | |
5334 | { | |
5335 | /* FIXME: This won't work for a 64 bit address. */ | |
5336 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5337 | } | |
5338 | ||
5339 | if (mips_opts.isa >= 2) | |
5340 | { | |
5341 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5342 | "T,o(b)", treg, (int) BFD_RELOC_LO16, AT); | |
5343 | ||
5344 | /* To avoid confusion in tc_gen_reloc, we must ensure | |
5345 | that this does not become a variant frag. */ | |
5346 | frag_wane (frag_now); | |
5347 | frag_new (0); | |
5348 | ||
5349 | break; | |
5350 | } | |
5351 | breg = AT; | |
5352 | r = BFD_RELOC_LO16; | |
5353 | goto dob; | |
5354 | } | |
5355 | ||
5356 | case M_L_DOB: | |
5357 | if (mips_cpu == 4650) | |
5358 | { | |
5359 | as_bad (_("opcode not supported on this processor")); | |
5360 | return; | |
5361 | } | |
5362 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5363 | to adjust when loading from memory. */ | |
5364 | r = BFD_RELOC_LO16; | |
5365 | dob: | |
5366 | assert (mips_opts.isa < 2); | |
5367 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5368 | target_big_endian ? treg + 1 : treg, | |
5369 | (int) r, breg); | |
5370 | /* FIXME: A possible overflow which I don't know how to deal | |
5371 | with. */ | |
5372 | offset_expr.X_add_number += 4; | |
5373 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5374 | target_big_endian ? treg : treg + 1, | |
5375 | (int) r, breg); | |
5376 | ||
5377 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5378 | does not become a variant frag. */ | |
5379 | frag_wane (frag_now); | |
5380 | frag_new (0); | |
5381 | ||
5382 | if (breg != AT) | |
5383 | return; | |
5384 | break; | |
5385 | ||
5386 | case M_L_DAB: | |
5387 | /* | |
5388 | * The MIPS assembler seems to check for X_add_number not | |
5389 | * being double aligned and generating: | |
5390 | * lui at,%hi(foo+1) | |
5391 | * addu at,at,v1 | |
5392 | * addiu at,at,%lo(foo+1) | |
5393 | * lwc1 f2,0(at) | |
5394 | * lwc1 f3,4(at) | |
5395 | * But, the resulting address is the same after relocation so why | |
5396 | * generate the extra instruction? | |
5397 | */ | |
5398 | if (mips_cpu == 4650) | |
5399 | { | |
5400 | as_bad (_("opcode not supported on this processor")); | |
5401 | return; | |
5402 | } | |
5403 | /* Itbl support may require additional care here. */ | |
5404 | coproc = 1; | |
5405 | if (mips_opts.isa >= 2) | |
5406 | { | |
5407 | s = "ldc1"; | |
5408 | goto ld; | |
5409 | } | |
5410 | ||
5411 | s = "lwc1"; | |
5412 | fmt = "T,o(b)"; | |
5413 | goto ldd_std; | |
5414 | ||
5415 | case M_S_DAB: | |
5416 | if (mips_cpu == 4650) | |
5417 | { | |
5418 | as_bad (_("opcode not supported on this processor")); | |
5419 | return; | |
5420 | } | |
5421 | ||
5422 | if (mips_opts.isa >= 2) | |
5423 | { | |
5424 | s = "sdc1"; | |
5425 | goto st; | |
5426 | } | |
5427 | ||
5428 | s = "swc1"; | |
5429 | fmt = "T,o(b)"; | |
5430 | /* Itbl support may require additional care here. */ | |
5431 | coproc = 1; | |
5432 | goto ldd_std; | |
5433 | ||
5434 | case M_LD_AB: | |
5435 | if (mips_opts.isa >= 3) | |
5436 | { | |
5437 | s = "ld"; | |
5438 | goto ld; | |
5439 | } | |
5440 | ||
5441 | s = "lw"; | |
5442 | fmt = "t,o(b)"; | |
5443 | goto ldd_std; | |
5444 | ||
5445 | case M_SD_AB: | |
5446 | if (mips_opts.isa >= 3) | |
5447 | { | |
5448 | s = "sd"; | |
5449 | goto st; | |
5450 | } | |
5451 | ||
5452 | s = "sw"; | |
5453 | fmt = "t,o(b)"; | |
5454 | ||
5455 | ldd_std: | |
5456 | if (offset_expr.X_op != O_symbol | |
5457 | && offset_expr.X_op != O_constant) | |
5458 | { | |
5459 | as_bad (_("expression too complex")); | |
5460 | offset_expr.X_op = O_constant; | |
5461 | } | |
5462 | ||
5463 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5464 | to adjust when loading from memory. We set coproc if we must | |
5465 | load $fn+1 first. */ | |
5466 | /* Itbl support may require additional care here. */ | |
5467 | if (! target_big_endian) | |
5468 | coproc = 0; | |
5469 | ||
5470 | if (mips_pic == NO_PIC | |
5471 | || offset_expr.X_op == O_constant) | |
5472 | { | |
5473 | /* If this is a reference to a GP relative symbol, we want | |
5474 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5475 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL) | |
5476 | If we have a base register, we use this | |
5477 | addu $at,$breg,$gp | |
5478 | <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL) | |
5479 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL) | |
5480 | If this is not a GP relative symbol, we want | |
5481 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5482 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5483 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5484 | If there is a base register, we add it to $at after the | |
5485 | lui instruction. If there is a constant, we always use | |
5486 | the last case. */ | |
5487 | if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET | |
5488 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
5489 | { | |
5490 | p = NULL; | |
5491 | used_at = 1; | |
5492 | } | |
5493 | else | |
5494 | { | |
5495 | int off; | |
5496 | ||
5497 | if (breg == 0) | |
5498 | { | |
5499 | frag_grow (28); | |
5500 | tempreg = GP; | |
5501 | off = 0; | |
5502 | used_at = 0; | |
5503 | } | |
5504 | else | |
5505 | { | |
5506 | frag_grow (36); | |
5507 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5508 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5509 | || mips_opts.isa < 3) | |
5510 | ? "addu" : "daddu"), | |
5511 | "d,v,t", AT, breg, GP); | |
5512 | tempreg = AT; | |
5513 | off = 4; | |
5514 | used_at = 1; | |
5515 | } | |
5516 | ||
5517 | /* Itbl support may require additional care here. */ | |
5518 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5519 | coproc ? treg + 1 : treg, | |
5520 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5521 | offset_expr.X_add_number += 4; | |
5522 | ||
5523 | /* Set mips_optimize to 2 to avoid inserting an | |
5524 | undesired nop. */ | |
5525 | hold_mips_optimize = mips_optimize; | |
5526 | mips_optimize = 2; | |
5527 | /* Itbl support may require additional care here. */ | |
5528 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5529 | coproc ? treg : treg + 1, | |
5530 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5531 | mips_optimize = hold_mips_optimize; | |
5532 | ||
5533 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
5534 | RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1, | |
5535 | used_at && mips_opts.noat), | |
5536 | offset_expr.X_add_symbol, (offsetT) 0, | |
5537 | (char *) NULL); | |
5538 | ||
5539 | /* We just generated two relocs. When tc_gen_reloc | |
5540 | handles this case, it will skip the first reloc and | |
5541 | handle the second. The second reloc already has an | |
5542 | extra addend of 4, which we added above. We must | |
5543 | subtract it out, and then subtract another 4 to make | |
5544 | the first reloc come out right. The second reloc | |
5545 | will come out right because we are going to add 4 to | |
5546 | offset_expr when we build its instruction below. | |
5547 | ||
5548 | If we have a symbol, then we don't want to include | |
5549 | the offset, because it will wind up being included | |
5550 | when we generate the reloc. */ | |
5551 | ||
5552 | if (offset_expr.X_op == O_constant) | |
5553 | offset_expr.X_add_number -= 8; | |
5554 | else | |
5555 | { | |
5556 | offset_expr.X_add_number = -4; | |
5557 | offset_expr.X_op = O_constant; | |
5558 | } | |
5559 | } | |
5560 | macro_build_lui (p, &icnt, &offset_expr, AT); | |
5561 | if (p != NULL) | |
5562 | p += 4; | |
5563 | if (breg != 0) | |
5564 | { | |
5565 | macro_build (p, &icnt, (expressionS *) NULL, | |
5566 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5567 | || mips_opts.isa < 3) | |
5568 | ? "addu" : "daddu"), | |
5569 | "d,v,t", AT, breg, AT); | |
5570 | if (p != NULL) | |
5571 | p += 4; | |
5572 | } | |
5573 | /* Itbl support may require additional care here. */ | |
5574 | macro_build (p, &icnt, &offset_expr, s, fmt, | |
5575 | coproc ? treg + 1 : treg, | |
5576 | (int) BFD_RELOC_LO16, AT); | |
5577 | if (p != NULL) | |
5578 | p += 4; | |
5579 | /* FIXME: How do we handle overflow here? */ | |
5580 | offset_expr.X_add_number += 4; | |
5581 | /* Itbl support may require additional care here. */ | |
5582 | macro_build (p, &icnt, &offset_expr, s, fmt, | |
5583 | coproc ? treg : treg + 1, | |
5584 | (int) BFD_RELOC_LO16, AT); | |
5585 | } | |
5586 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
5587 | { | |
5588 | int off; | |
5589 | ||
5590 | /* If this is a reference to an external symbol, we want | |
5591 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5592 | nop | |
5593 | <op> $treg,0($at) | |
5594 | <op> $treg+1,4($at) | |
5595 | Otherwise we want | |
5596 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5597 | nop | |
5598 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5599 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5600 | If there is a base register we add it to $at before the | |
5601 | lwc1 instructions. If there is a constant we include it | |
5602 | in the lwc1 instructions. */ | |
5603 | used_at = 1; | |
5604 | expr1.X_add_number = offset_expr.X_add_number; | |
5605 | offset_expr.X_add_number = 0; | |
5606 | if (expr1.X_add_number < -0x8000 | |
5607 | || expr1.X_add_number >= 0x8000 - 4) | |
5608 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5609 | if (breg == 0) | |
5610 | off = 0; | |
5611 | else | |
5612 | off = 4; | |
5613 | frag_grow (24 + off); | |
5614 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5615 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5616 | || mips_opts.isa < 3) | |
5617 | ? "lw" : "ld"), | |
5618 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5619 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
5620 | if (breg != 0) | |
5621 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5622 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5623 | || mips_opts.isa < 3) | |
5624 | ? "addu" : "daddu"), | |
5625 | "d,v,t", AT, breg, AT); | |
5626 | /* Itbl support may require additional care here. */ | |
5627 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, | |
5628 | coproc ? treg + 1 : treg, | |
5629 | (int) BFD_RELOC_LO16, AT); | |
5630 | expr1.X_add_number += 4; | |
5631 | ||
5632 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5633 | nop. */ | |
5634 | hold_mips_optimize = mips_optimize; | |
5635 | mips_optimize = 2; | |
5636 | /* Itbl support may require additional care here. */ | |
5637 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, | |
5638 | coproc ? treg : treg + 1, | |
5639 | (int) BFD_RELOC_LO16, AT); | |
5640 | mips_optimize = hold_mips_optimize; | |
5641 | ||
5642 | (void) frag_var (rs_machine_dependent, 0, 0, | |
5643 | RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0), | |
5644 | offset_expr.X_add_symbol, (offsetT) 0, | |
5645 | (char *) NULL); | |
5646 | } | |
5647 | else if (mips_pic == SVR4_PIC) | |
5648 | { | |
5649 | int gpdel, off; | |
5650 | ||
5651 | /* If this is a reference to an external symbol, we want | |
5652 | lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5653 | addu $at,$at,$gp | |
5654 | lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16) | |
5655 | nop | |
5656 | <op> $treg,0($at) | |
5657 | <op> $treg+1,4($at) | |
5658 | Otherwise we want | |
5659 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5660 | nop | |
5661 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5662 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5663 | If there is a base register we add it to $at before the | |
5664 | lwc1 instructions. If there is a constant we include it | |
5665 | in the lwc1 instructions. */ | |
5666 | used_at = 1; | |
5667 | expr1.X_add_number = offset_expr.X_add_number; | |
5668 | offset_expr.X_add_number = 0; | |
5669 | if (expr1.X_add_number < -0x8000 | |
5670 | || expr1.X_add_number >= 0x8000 - 4) | |
5671 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5672 | if (reg_needs_delay (GP)) | |
5673 | gpdel = 4; | |
5674 | else | |
5675 | gpdel = 0; | |
5676 | if (breg == 0) | |
5677 | off = 0; | |
5678 | else | |
5679 | off = 4; | |
5680 | frag_grow (56); | |
5681 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5682 | AT, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5683 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5684 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5685 | || mips_opts.isa < 3) | |
5686 | ? "addu" : "daddu"), | |
5687 | "d,v,t", AT, AT, GP); | |
5688 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5689 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5690 | || mips_opts.isa < 3) | |
5691 | ? "lw" : "ld"), | |
5692 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT); | |
5693 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
5694 | if (breg != 0) | |
5695 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5696 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5697 | || mips_opts.isa < 3) | |
5698 | ? "addu" : "daddu"), | |
5699 | "d,v,t", AT, breg, AT); | |
5700 | /* Itbl support may require additional care here. */ | |
5701 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, | |
5702 | coproc ? treg + 1 : treg, | |
5703 | (int) BFD_RELOC_LO16, AT); | |
5704 | expr1.X_add_number += 4; | |
5705 | ||
5706 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5707 | nop. */ | |
5708 | hold_mips_optimize = mips_optimize; | |
5709 | mips_optimize = 2; | |
5710 | /* Itbl support may require additional care here. */ | |
5711 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, | |
5712 | coproc ? treg : treg + 1, | |
5713 | (int) BFD_RELOC_LO16, AT); | |
5714 | mips_optimize = hold_mips_optimize; | |
5715 | expr1.X_add_number -= 4; | |
5716 | ||
5717 | p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0, | |
5718 | RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel, | |
5719 | 8 + gpdel + off, 1, 0), | |
5720 | offset_expr.X_add_symbol, (offsetT) 0, | |
5721 | (char *) NULL); | |
5722 | if (gpdel > 0) | |
5723 | { | |
5724 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5725 | p += 4; | |
5726 | } | |
5727 | macro_build (p, &icnt, &offset_expr, | |
5728 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5729 | || mips_opts.isa < 3) | |
5730 | ? "lw" : "ld"), | |
5731 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5732 | p += 4; | |
5733 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5734 | p += 4; | |
5735 | if (breg != 0) | |
5736 | { | |
5737 | macro_build (p, &icnt, (expressionS *) NULL, | |
5738 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5739 | || mips_opts.isa < 3) | |
5740 | ? "addu" : "daddu"), | |
5741 | "d,v,t", AT, breg, AT); | |
5742 | p += 4; | |
5743 | } | |
5744 | /* Itbl support may require additional care here. */ | |
5745 | macro_build (p, &icnt, &expr1, s, fmt, | |
5746 | coproc ? treg + 1 : treg, | |
5747 | (int) BFD_RELOC_LO16, AT); | |
5748 | p += 4; | |
5749 | expr1.X_add_number += 4; | |
5750 | ||
5751 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5752 | nop. */ | |
5753 | hold_mips_optimize = mips_optimize; | |
5754 | mips_optimize = 2; | |
5755 | /* Itbl support may require additional care here. */ | |
5756 | macro_build (p, &icnt, &expr1, s, fmt, | |
5757 | coproc ? treg : treg + 1, | |
5758 | (int) BFD_RELOC_LO16, AT); | |
5759 | mips_optimize = hold_mips_optimize; | |
5760 | } | |
5761 | else if (mips_pic == EMBEDDED_PIC) | |
5762 | { | |
5763 | /* If there is no base register, we use | |
5764 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5765 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL) | |
5766 | If we have a base register, we use | |
5767 | addu $at,$breg,$gp | |
5768 | <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL) | |
5769 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL) | |
5770 | */ | |
5771 | if (breg == 0) | |
5772 | { | |
5773 | tempreg = GP; | |
5774 | used_at = 0; | |
5775 | } | |
5776 | else | |
5777 | { | |
5778 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5779 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5780 | || mips_opts.isa < 3) | |
5781 | ? "addu" : "daddu"), | |
5782 | "d,v,t", AT, breg, GP); | |
5783 | tempreg = AT; | |
5784 | used_at = 1; | |
5785 | } | |
5786 | ||
5787 | /* Itbl support may require additional care here. */ | |
5788 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5789 | coproc ? treg + 1 : treg, | |
5790 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5791 | offset_expr.X_add_number += 4; | |
5792 | /* Itbl support may require additional care here. */ | |
5793 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5794 | coproc ? treg : treg + 1, | |
5795 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5796 | } | |
5797 | else | |
5798 | abort (); | |
5799 | ||
5800 | if (! used_at) | |
5801 | return; | |
5802 | ||
5803 | break; | |
5804 | ||
5805 | case M_LD_OB: | |
5806 | s = "lw"; | |
5807 | goto sd_ob; | |
5808 | case M_SD_OB: | |
5809 | s = "sw"; | |
5810 | sd_ob: | |
5811 | assert (bfd_arch_bits_per_address (stdoutput) == 32 || mips_opts.isa < 3); | |
5812 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
5813 | (int) BFD_RELOC_LO16, breg); | |
5814 | offset_expr.X_add_number += 4; | |
5815 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1, | |
5816 | (int) BFD_RELOC_LO16, breg); | |
5817 | return; | |
5818 | ||
5819 | /* New code added to support COPZ instructions. | |
5820 | This code builds table entries out of the macros in mip_opcodes. | |
5821 | R4000 uses interlocks to handle coproc delays. | |
5822 | Other chips (like the R3000) require nops to be inserted for delays. | |
5823 | ||
5824 | FIXME: Currently, we require that the user handle delays. | |
5825 | In order to fill delay slots for non-interlocked chips, | |
5826 | we must have a way to specify delays based on the coprocessor. | |
5827 | Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc. | |
5828 | What are the side-effects of the cop instruction? | |
5829 | What cache support might we have and what are its effects? | |
5830 | Both coprocessor & memory require delays. how long??? | |
5831 | What registers are read/set/modified? | |
5832 | ||
5833 | If an itbl is provided to interpret cop instructions, | |
5834 | this knowledge can be encoded in the itbl spec. */ | |
5835 | ||
5836 | case M_COP0: | |
5837 | s = "c0"; | |
5838 | goto copz; | |
5839 | case M_COP1: | |
5840 | s = "c1"; | |
5841 | goto copz; | |
5842 | case M_COP2: | |
5843 | s = "c2"; | |
5844 | goto copz; | |
5845 | case M_COP3: | |
5846 | s = "c3"; | |
5847 | copz: | |
5848 | /* For now we just do C (same as Cz). The parameter will be | |
5849 | stored in insn_opcode by mips_ip. */ | |
5850 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C", | |
5851 | ip->insn_opcode); | |
5852 | return; | |
5853 | ||
5854 | #ifdef LOSING_COMPILER | |
5855 | default: | |
5856 | /* Try and see if this is a new itbl instruction. | |
5857 | This code builds table entries out of the macros in mip_opcodes. | |
5858 | FIXME: For now we just assemble the expression and pass it's | |
5859 | value along as a 32-bit immediate. | |
5860 | We may want to have the assembler assemble this value, | |
5861 | so that we gain the assembler's knowledge of delay slots, | |
5862 | symbols, etc. | |
5863 | Would it be more efficient to use mask (id) here? */ | |
5864 | if (itbl_have_entries | |
5865 | && (immed_expr = itbl_assemble (ip->insn_mo->name, ""))) | |
5866 | { | |
5867 | s = ip->insn_mo->name; | |
5868 | s2 = "cop3"; | |
5869 | coproc = ITBL_DECODE_PNUM (immed_expr);; | |
5870 | macro_build ((char *) NULL, &icnt, &immed_expr, s, "C"); | |
5871 | return; | |
5872 | } | |
5873 | macro2 (ip); | |
5874 | return; | |
5875 | } | |
5876 | if (mips_opts.noat) | |
5877 | as_warn (_("Macro used $at after \".set noat\"")); | |
5878 | } | |
5879 | ||
5880 | static void | |
5881 | macro2 (ip) | |
5882 | struct mips_cl_insn *ip; | |
5883 | { | |
5884 | register int treg, sreg, dreg, breg; | |
5885 | int tempreg; | |
5886 | int mask; | |
5887 | int icnt = 0; | |
5888 | int used_at; | |
5889 | expressionS expr1; | |
5890 | const char *s; | |
5891 | const char *s2; | |
5892 | const char *fmt; | |
5893 | int likely = 0; | |
5894 | int dbl = 0; | |
5895 | int coproc = 0; | |
5896 | int lr = 0; | |
5897 | int imm = 0; | |
5898 | int off; | |
5899 | offsetT maxnum; | |
5900 | bfd_reloc_code_real_type r; | |
5901 | char *p; | |
5902 | ||
5903 | treg = (ip->insn_opcode >> 16) & 0x1f; | |
5904 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
5905 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
5906 | mask = ip->insn_mo->mask; | |
5907 | ||
5908 | expr1.X_op = O_constant; | |
5909 | expr1.X_op_symbol = NULL; | |
5910 | expr1.X_add_symbol = NULL; | |
5911 | expr1.X_add_number = 1; | |
5912 | ||
5913 | switch (mask) | |
5914 | { | |
5915 | #endif /* LOSING_COMPILER */ | |
5916 | ||
5917 | case M_DMUL: | |
5918 | dbl = 1; | |
5919 | case M_MUL: | |
5920 | macro_build ((char *) NULL, &icnt, NULL, | |
5921 | dbl ? "dmultu" : "multu", | |
5922 | "s,t", sreg, treg); | |
5923 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
5924 | return; | |
5925 | ||
5926 | case M_DMUL_I: | |
5927 | dbl = 1; | |
5928 | case M_MUL_I: | |
5929 | /* The MIPS assembler some times generates shifts and adds. I'm | |
5930 | not trying to be that fancy. GCC should do this for us | |
5931 | anyway. */ | |
5932 | load_register (&icnt, AT, &imm_expr, dbl); | |
5933 | macro_build ((char *) NULL, &icnt, NULL, | |
5934 | dbl ? "dmult" : "mult", | |
5935 | "s,t", sreg, AT); | |
5936 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
5937 | break; | |
5938 | ||
5939 | case M_DMULO_I: | |
5940 | dbl = 1; | |
5941 | case M_MULO_I: | |
5942 | imm = 1; | |
5943 | goto do_mulo; | |
5944 | ||
5945 | case M_DMULO: | |
5946 | dbl = 1; | |
5947 | case M_MULO: | |
5948 | do_mulo: | |
5949 | mips_emit_delays (true); | |
5950 | ++mips_opts.noreorder; | |
5951 | mips_any_noreorder = 1; | |
5952 | if (imm) | |
5953 | load_register (&icnt, AT, &imm_expr, dbl); | |
5954 | macro_build ((char *) NULL, &icnt, NULL, | |
5955 | dbl ? "dmult" : "mult", | |
5956 | "s,t", sreg, imm ? AT : treg); | |
5957 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
5958 | macro_build ((char *) NULL, &icnt, NULL, | |
5959 | dbl ? "dsra32" : "sra", | |
5960 | "d,w,<", dreg, dreg, 31); | |
5961 | macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT); | |
5962 | if (mips_trap) | |
5963 | macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", dreg, AT); | |
5964 | else | |
5965 | { | |
5966 | expr1.X_add_number = 8; | |
5967 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT); | |
5968 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
5969 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); | |
5970 | } | |
5971 | --mips_opts.noreorder; | |
5972 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
5973 | break; | |
5974 | ||
5975 | case M_DMULOU_I: | |
5976 | dbl = 1; | |
5977 | case M_MULOU_I: | |
5978 | imm = 1; | |
5979 | goto do_mulou; | |
5980 | ||
5981 | case M_DMULOU: | |
5982 | dbl = 1; | |
5983 | case M_MULOU: | |
5984 | do_mulou: | |
5985 | mips_emit_delays (true); | |
5986 | ++mips_opts.noreorder; | |
5987 | mips_any_noreorder = 1; | |
5988 | if (imm) | |
5989 | load_register (&icnt, AT, &imm_expr, dbl); | |
5990 | macro_build ((char *) NULL, &icnt, NULL, | |
5991 | dbl ? "dmultu" : "multu", | |
5992 | "s,t", sreg, imm ? AT : treg); | |
5993 | macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT); | |
5994 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
5995 | if (mips_trap) | |
5996 | macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", AT, 0); | |
5997 | else | |
5998 | { | |
5999 | expr1.X_add_number = 8; | |
6000 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0); | |
6001 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
6002 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); | |
6003 | } | |
6004 | --mips_opts.noreorder; | |
6005 | break; | |
6006 | ||
6007 | case M_ROL: | |
6008 | macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg); | |
6009 | macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT); | |
6010 | macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg, | |
6011 | treg); | |
6012 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6013 | break; | |
6014 | ||
6015 | case M_ROL_I: | |
6016 | if (imm_expr.X_op != O_constant) | |
6017 | as_bad (_("rotate count too large")); | |
6018 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg, | |
6019 | (int) (imm_expr.X_add_number & 0x1f)); | |
6020 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, | |
6021 | (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6022 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6023 | break; | |
6024 | ||
6025 | case M_ROR: | |
6026 | macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg); | |
6027 | macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT); | |
6028 | macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg, | |
6029 | treg); | |
6030 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6031 | break; | |
6032 | ||
6033 | case M_ROR_I: | |
6034 | if (imm_expr.X_op != O_constant) | |
6035 | as_bad (_("rotate count too large")); | |
6036 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg, | |
6037 | (int) (imm_expr.X_add_number & 0x1f)); | |
6038 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg, | |
6039 | (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6040 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6041 | break; | |
6042 | ||
6043 | case M_S_DOB: | |
6044 | if (mips_cpu == 4650) | |
6045 | { | |
6046 | as_bad (_("opcode not supported on this processor")); | |
6047 | return; | |
6048 | } | |
6049 | assert (mips_opts.isa < 2); | |
6050 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
6051 | to adjust when storing to memory. */ | |
6052 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6053 | target_big_endian ? treg + 1 : treg, | |
6054 | (int) BFD_RELOC_LO16, breg); | |
6055 | offset_expr.X_add_number += 4; | |
6056 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6057 | target_big_endian ? treg : treg + 1, | |
6058 | (int) BFD_RELOC_LO16, breg); | |
6059 | return; | |
6060 | ||
6061 | case M_SEQ: | |
6062 | if (sreg == 0) | |
6063 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6064 | treg, (int) BFD_RELOC_LO16); | |
6065 | else if (treg == 0) | |
6066 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6067 | sreg, (int) BFD_RELOC_LO16); | |
6068 | else | |
6069 | { | |
6070 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6071 | sreg, treg); | |
6072 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6073 | dreg, (int) BFD_RELOC_LO16); | |
6074 | } | |
6075 | return; | |
6076 | ||
6077 | case M_SEQ_I: | |
6078 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6079 | { | |
6080 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6081 | sreg, (int) BFD_RELOC_LO16); | |
6082 | return; | |
6083 | } | |
6084 | if (sreg == 0) | |
6085 | { | |
6086 | as_warn (_("Instruction %s: result is always false"), | |
6087 | ip->insn_mo->name); | |
6088 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0); | |
6089 | return; | |
6090 | } | |
6091 | if (imm_expr.X_op == O_constant | |
6092 | && imm_expr.X_add_number >= 0 | |
6093 | && imm_expr.X_add_number < 0x10000) | |
6094 | { | |
6095 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, | |
6096 | sreg, (int) BFD_RELOC_LO16); | |
6097 | used_at = 0; | |
6098 | } | |
6099 | else if (imm_expr.X_op == O_constant | |
6100 | && imm_expr.X_add_number > -0x8000 | |
6101 | && imm_expr.X_add_number < 0) | |
6102 | { | |
6103 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6104 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6105 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
6106 | || mips_opts.isa < 3) | |
6107 | ? "addiu" : "daddiu"), | |
6108 | "t,r,j", dreg, sreg, | |
6109 | (int) BFD_RELOC_LO16); | |
6110 | used_at = 0; | |
6111 | } | |
6112 | else | |
6113 | { | |
6114 | load_register (&icnt, AT, &imm_expr, 0); | |
6115 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6116 | sreg, AT); | |
6117 | used_at = 1; | |
6118 | } | |
6119 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg, | |
6120 | (int) BFD_RELOC_LO16); | |
6121 | if (used_at) | |
6122 | break; | |
6123 | return; | |
6124 | ||
6125 | case M_SGE: /* sreg >= treg <==> not (sreg < treg) */ | |
6126 | s = "slt"; | |
6127 | goto sge; | |
6128 | case M_SGEU: | |
6129 | s = "sltu"; | |
6130 | sge: | |
6131 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg); | |
6132 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6133 | (int) BFD_RELOC_LO16); | |
6134 | return; | |
6135 | ||
6136 | case M_SGE_I: /* sreg >= I <==> not (sreg < I) */ | |
6137 | case M_SGEU_I: | |
6138 | if (imm_expr.X_op == O_constant | |
6139 | && imm_expr.X_add_number >= -0x8000 | |
6140 | && imm_expr.X_add_number < 0x8000) | |
6141 | { | |
6142 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6143 | mask == M_SGE_I ? "slti" : "sltiu", | |
6144 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6145 | used_at = 0; | |
6146 | } | |
6147 | else | |
6148 | { | |
6149 | load_register (&icnt, AT, &imm_expr, 0); | |
6150 | macro_build ((char *) NULL, &icnt, NULL, | |
6151 | mask == M_SGE_I ? "slt" : "sltu", | |
6152 | "d,v,t", dreg, sreg, AT); | |
6153 | used_at = 1; | |
6154 | } | |
6155 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6156 | (int) BFD_RELOC_LO16); | |
6157 | if (used_at) | |
6158 | break; | |
6159 | return; | |
6160 | ||
6161 | case M_SGT: /* sreg > treg <==> treg < sreg */ | |
6162 | s = "slt"; | |
6163 | goto sgt; | |
6164 | case M_SGTU: | |
6165 | s = "sltu"; | |
6166 | sgt: | |
6167 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg); | |
6168 | return; | |
6169 | ||
6170 | case M_SGT_I: /* sreg > I <==> I < sreg */ | |
6171 | s = "slt"; | |
6172 | goto sgti; | |
6173 | case M_SGTU_I: | |
6174 | s = "sltu"; | |
6175 | sgti: | |
6176 | load_register (&icnt, AT, &imm_expr, 0); | |
6177 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg); | |
6178 | break; | |
6179 | ||
6180 | case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */ | |
6181 | s = "slt"; | |
6182 | goto sle; | |
6183 | case M_SLEU: | |
6184 | s = "sltu"; | |
6185 | sle: | |
6186 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg); | |
6187 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6188 | (int) BFD_RELOC_LO16); | |
6189 | return; | |
6190 | ||
6191 | case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */ | |
6192 | s = "slt"; | |
6193 | goto slei; | |
6194 | case M_SLEU_I: | |
6195 | s = "sltu"; | |
6196 | slei: | |
6197 | load_register (&icnt, AT, &imm_expr, 0); | |
6198 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg); | |
6199 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6200 | (int) BFD_RELOC_LO16); | |
6201 | break; | |
6202 | ||
6203 | case M_SLT_I: | |
6204 | if (imm_expr.X_op == O_constant | |
6205 | && imm_expr.X_add_number >= -0x8000 | |
6206 | && imm_expr.X_add_number < 0x8000) | |
6207 | { | |
6208 | macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j", | |
6209 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6210 | return; | |
6211 | } | |
6212 | load_register (&icnt, AT, &imm_expr, 0); | |
6213 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT); | |
6214 | break; | |
6215 | ||
6216 | case M_SLTU_I: | |
6217 | if (imm_expr.X_op == O_constant | |
6218 | && imm_expr.X_add_number >= -0x8000 | |
6219 | && imm_expr.X_add_number < 0x8000) | |
6220 | { | |
6221 | macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j", | |
6222 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6223 | return; | |
6224 | } | |
6225 | load_register (&icnt, AT, &imm_expr, 0); | |
6226 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg, | |
6227 | AT); | |
6228 | break; | |
6229 | ||
6230 | case M_SNE: | |
6231 | if (sreg == 0) | |
6232 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6233 | treg); | |
6234 | else if (treg == 0) | |
6235 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6236 | sreg); | |
6237 | else | |
6238 | { | |
6239 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6240 | sreg, treg); | |
6241 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6242 | dreg); | |
6243 | } | |
6244 | return; | |
6245 | ||
6246 | case M_SNE_I: | |
6247 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6248 | { | |
6249 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6250 | sreg); | |
6251 | return; | |
6252 | } | |
6253 | if (sreg == 0) | |
6254 | { | |
6255 | as_warn (_("Instruction %s: result is always true"), | |
6256 | ip->insn_mo->name); | |
6257 | macro_build ((char *) NULL, &icnt, &expr1, | |
6258 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
6259 | || mips_opts.isa < 3) | |
6260 | ? "addiu" : "daddiu"), | |
6261 | "t,r,j", dreg, 0, (int) BFD_RELOC_LO16); | |
6262 | return; | |
6263 | } | |
6264 | if (imm_expr.X_op == O_constant | |
6265 | && imm_expr.X_add_number >= 0 | |
6266 | && imm_expr.X_add_number < 0x10000) | |
6267 | { | |
6268 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", | |
6269 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6270 | used_at = 0; | |
6271 | } | |
6272 | else if (imm_expr.X_op == O_constant | |
6273 | && imm_expr.X_add_number > -0x8000 | |
6274 | && imm_expr.X_add_number < 0) | |
6275 | { | |
6276 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6277 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6278 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
6279 | || mips_opts.isa < 3) | |
6280 | ? "addiu" : "daddiu"), | |
6281 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6282 | used_at = 0; | |
6283 | } | |
6284 | else | |
6285 | { | |
6286 | load_register (&icnt, AT, &imm_expr, 0); | |
6287 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6288 | sreg, AT); | |
6289 | used_at = 1; | |
6290 | } | |
6291 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg); | |
6292 | if (used_at) | |
6293 | break; | |
6294 | return; | |
6295 | ||
6296 | case M_DSUB_I: | |
6297 | dbl = 1; | |
6298 | case M_SUB_I: | |
6299 | if (imm_expr.X_op == O_constant | |
6300 | && imm_expr.X_add_number > -0x8000 | |
6301 | && imm_expr.X_add_number <= 0x8000) | |
6302 | { | |
6303 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6304 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6305 | dbl ? "daddi" : "addi", | |
6306 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6307 | return; | |
6308 | } | |
6309 | load_register (&icnt, AT, &imm_expr, dbl); | |
6310 | macro_build ((char *) NULL, &icnt, NULL, | |
6311 | dbl ? "dsub" : "sub", | |
6312 | "d,v,t", dreg, sreg, AT); | |
6313 | break; | |
6314 | ||
6315 | case M_DSUBU_I: | |
6316 | dbl = 1; | |
6317 | case M_SUBU_I: | |
6318 | if (imm_expr.X_op == O_constant | |
6319 | && imm_expr.X_add_number > -0x8000 | |
6320 | && imm_expr.X_add_number <= 0x8000) | |
6321 | { | |
6322 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6323 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6324 | dbl ? "daddiu" : "addiu", | |
6325 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6326 | return; | |
6327 | } | |
6328 | load_register (&icnt, AT, &imm_expr, dbl); | |
6329 | macro_build ((char *) NULL, &icnt, NULL, | |
6330 | dbl ? "dsubu" : "subu", | |
6331 | "d,v,t", dreg, sreg, AT); | |
6332 | break; | |
6333 | ||
6334 | case M_TEQ_I: | |
6335 | s = "teq"; | |
6336 | goto trap; | |
6337 | case M_TGE_I: | |
6338 | s = "tge"; | |
6339 | goto trap; | |
6340 | case M_TGEU_I: | |
6341 | s = "tgeu"; | |
6342 | goto trap; | |
6343 | case M_TLT_I: | |
6344 | s = "tlt"; | |
6345 | goto trap; | |
6346 | case M_TLTU_I: | |
6347 | s = "tltu"; | |
6348 | goto trap; | |
6349 | case M_TNE_I: | |
6350 | s = "tne"; | |
6351 | trap: | |
6352 | load_register (&icnt, AT, &imm_expr, 0); | |
6353 | macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT); | |
6354 | break; | |
6355 | ||
6356 | case M_TRUNCWD: | |
6357 | case M_TRUNCWS: | |
6358 | assert (mips_opts.isa < 2); | |
6359 | sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */ | |
6360 | dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */ | |
6361 | ||
6362 | /* | |
6363 | * Is the double cfc1 instruction a bug in the mips assembler; | |
6364 | * or is there a reason for it? | |
6365 | */ | |
6366 | mips_emit_delays (true); | |
6367 | ++mips_opts.noreorder; | |
6368 | mips_any_noreorder = 1; | |
6369 | macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31); | |
6370 | macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31); | |
6371 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6372 | expr1.X_add_number = 3; | |
6373 | macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg, | |
6374 | (int) BFD_RELOC_LO16); | |
6375 | expr1.X_add_number = 2; | |
6376 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT, | |
6377 | (int) BFD_RELOC_LO16); | |
6378 | macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31); | |
6379 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6380 | macro_build ((char *) NULL, &icnt, NULL, | |
6381 | mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg); | |
6382 | macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31); | |
6383 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6384 | --mips_opts.noreorder; | |
6385 | break; | |
6386 | ||
6387 | case M_ULH: | |
6388 | s = "lb"; | |
6389 | goto ulh; | |
6390 | case M_ULHU: | |
6391 | s = "lbu"; | |
6392 | ulh: | |
6393 | if (offset_expr.X_add_number >= 0x7fff) | |
6394 | as_bad (_("operand overflow")); | |
6395 | /* avoid load delay */ | |
6396 | if (! target_big_endian) | |
6397 | offset_expr.X_add_number += 1; | |
6398 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6399 | (int) BFD_RELOC_LO16, breg); | |
6400 | if (! target_big_endian) | |
6401 | offset_expr.X_add_number -= 1; | |
6402 | else | |
6403 | offset_expr.X_add_number += 1; | |
6404 | macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT, | |
6405 | (int) BFD_RELOC_LO16, breg); | |
6406 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8); | |
6407 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT); | |
6408 | break; | |
6409 | ||
6410 | case M_ULD: | |
6411 | s = "ldl"; | |
6412 | s2 = "ldr"; | |
6413 | off = 7; | |
6414 | goto ulw; | |
6415 | case M_ULW: | |
6416 | s = "lwl"; | |
6417 | s2 = "lwr"; | |
6418 | off = 3; | |
6419 | ulw: | |
6420 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6421 | as_bad (_("operand overflow")); | |
6422 | if (! target_big_endian) | |
6423 | offset_expr.X_add_number += off; | |
6424 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6425 | (int) BFD_RELOC_LO16, breg); | |
6426 | if (! target_big_endian) | |
6427 | offset_expr.X_add_number -= off; | |
6428 | else | |
6429 | offset_expr.X_add_number += off; | |
6430 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
6431 | (int) BFD_RELOC_LO16, breg); | |
6432 | return; | |
6433 | ||
6434 | case M_ULD_A: | |
6435 | s = "ldl"; | |
6436 | s2 = "ldr"; | |
6437 | off = 7; | |
6438 | goto ulwa; | |
6439 | case M_ULW_A: | |
6440 | s = "lwl"; | |
6441 | s2 = "lwr"; | |
6442 | off = 3; | |
6443 | ulwa: | |
6444 | load_address (&icnt, AT, &offset_expr); | |
6445 | if (breg != 0) | |
6446 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6447 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
6448 | || mips_opts.isa < 3) | |
6449 | ? "addu" : "daddu"), | |
6450 | "d,v,t", AT, AT, breg); | |
6451 | if (! target_big_endian) | |
6452 | expr1.X_add_number = off; | |
6453 | else | |
6454 | expr1.X_add_number = 0; | |
6455 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
6456 | (int) BFD_RELOC_LO16, AT); | |
6457 | if (! target_big_endian) | |
6458 | expr1.X_add_number = 0; | |
6459 | else | |
6460 | expr1.X_add_number = off; | |
6461 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
6462 | (int) BFD_RELOC_LO16, AT); | |
6463 | break; | |
6464 | ||
6465 | case M_ULH_A: | |
6466 | case M_ULHU_A: | |
6467 | load_address (&icnt, AT, &offset_expr); | |
6468 | if (breg != 0) | |
6469 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6470 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
6471 | || mips_opts.isa < 3) | |
6472 | ? "addu" : "daddu"), | |
6473 | "d,v,t", AT, AT, breg); | |
6474 | if (target_big_endian) | |
6475 | expr1.X_add_number = 0; | |
6476 | macro_build ((char *) NULL, &icnt, &expr1, | |
6477 | mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg, | |
6478 | (int) BFD_RELOC_LO16, AT); | |
6479 | if (target_big_endian) | |
6480 | expr1.X_add_number = 1; | |
6481 | else | |
6482 | expr1.X_add_number = 0; | |
6483 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
6484 | (int) BFD_RELOC_LO16, AT); | |
6485 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, | |
6486 | treg, 8); | |
6487 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, | |
6488 | treg, AT); | |
6489 | break; | |
6490 | ||
6491 | case M_USH: | |
6492 | if (offset_expr.X_add_number >= 0x7fff) | |
6493 | as_bad (_("operand overflow")); | |
6494 | if (target_big_endian) | |
6495 | offset_expr.X_add_number += 1; | |
6496 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg, | |
6497 | (int) BFD_RELOC_LO16, breg); | |
6498 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8); | |
6499 | if (target_big_endian) | |
6500 | offset_expr.X_add_number -= 1; | |
6501 | else | |
6502 | offset_expr.X_add_number += 1; | |
6503 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT, | |
6504 | (int) BFD_RELOC_LO16, breg); | |
6505 | break; | |
6506 | ||
6507 | case M_USD: | |
6508 | s = "sdl"; | |
6509 | s2 = "sdr"; | |
6510 | off = 7; | |
6511 | goto usw; | |
6512 | case M_USW: | |
6513 | s = "swl"; | |
6514 | s2 = "swr"; | |
6515 | off = 3; | |
6516 | usw: | |
6517 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6518 | as_bad (_("operand overflow")); | |
6519 | if (! target_big_endian) | |
6520 | offset_expr.X_add_number += off; | |
6521 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6522 | (int) BFD_RELOC_LO16, breg); | |
6523 | if (! target_big_endian) | |
6524 | offset_expr.X_add_number -= off; | |
6525 | else | |
6526 | offset_expr.X_add_number += off; | |
6527 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
6528 | (int) BFD_RELOC_LO16, breg); | |
6529 | return; | |
6530 | ||
6531 | case M_USD_A: | |
6532 | s = "sdl"; | |
6533 | s2 = "sdr"; | |
6534 | off = 7; | |
6535 | goto uswa; | |
6536 | case M_USW_A: | |
6537 | s = "swl"; | |
6538 | s2 = "swr"; | |
6539 | off = 3; | |
6540 | uswa: | |
6541 | load_address (&icnt, AT, &offset_expr); | |
6542 | if (breg != 0) | |
6543 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6544 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
6545 | || mips_opts.isa < 3) | |
6546 | ? "addu" : "daddu"), | |
6547 | "d,v,t", AT, AT, breg); | |
6548 | if (! target_big_endian) | |
6549 | expr1.X_add_number = off; | |
6550 | else | |
6551 | expr1.X_add_number = 0; | |
6552 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
6553 | (int) BFD_RELOC_LO16, AT); | |
6554 | if (! target_big_endian) | |
6555 | expr1.X_add_number = 0; | |
6556 | else | |
6557 | expr1.X_add_number = off; | |
6558 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
6559 | (int) BFD_RELOC_LO16, AT); | |
6560 | break; | |
6561 | ||
6562 | case M_USH_A: | |
6563 | load_address (&icnt, AT, &offset_expr); | |
6564 | if (breg != 0) | |
6565 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6566 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
6567 | || mips_opts.isa < 3) | |
6568 | ? "addu" : "daddu"), | |
6569 | "d,v,t", AT, AT, breg); | |
6570 | if (! target_big_endian) | |
6571 | expr1.X_add_number = 0; | |
6572 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
6573 | (int) BFD_RELOC_LO16, AT); | |
6574 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg, | |
6575 | treg, 8); | |
6576 | if (! target_big_endian) | |
6577 | expr1.X_add_number = 1; | |
6578 | else | |
6579 | expr1.X_add_number = 0; | |
6580 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
6581 | (int) BFD_RELOC_LO16, AT); | |
6582 | if (! target_big_endian) | |
6583 | expr1.X_add_number = 0; | |
6584 | else | |
6585 | expr1.X_add_number = 1; | |
6586 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
6587 | (int) BFD_RELOC_LO16, AT); | |
6588 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, | |
6589 | treg, 8); | |
6590 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, | |
6591 | treg, AT); | |
6592 | break; | |
6593 | ||
6594 | default: | |
6595 | /* FIXME: Check if this is one of the itbl macros, since they | |
6596 | are added dynamically. */ | |
6597 | as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name); | |
6598 | break; | |
6599 | } | |
6600 | if (mips_opts.noat) | |
6601 | as_warn (_("Macro used $at after \".set noat\"")); | |
6602 | } | |
6603 | ||
6604 | /* Implement macros in mips16 mode. */ | |
6605 | ||
6606 | static void | |
6607 | mips16_macro (ip) | |
6608 | struct mips_cl_insn *ip; | |
6609 | { | |
6610 | int mask; | |
6611 | int xreg, yreg, zreg, tmp; | |
6612 | int icnt; | |
6613 | expressionS expr1; | |
6614 | int dbl; | |
6615 | const char *s, *s2, *s3; | |
6616 | ||
6617 | mask = ip->insn_mo->mask; | |
6618 | ||
6619 | xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX; | |
6620 | yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY; | |
6621 | zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ; | |
6622 | ||
6623 | icnt = 0; | |
6624 | ||
6625 | expr1.X_op = O_constant; | |
6626 | expr1.X_op_symbol = NULL; | |
6627 | expr1.X_add_symbol = NULL; | |
6628 | expr1.X_add_number = 1; | |
6629 | ||
6630 | dbl = 0; | |
6631 | ||
6632 | switch (mask) | |
6633 | { | |
6634 | default: | |
6635 | internalError (); | |
6636 | ||
6637 | case M_DDIV_3: | |
6638 | dbl = 1; | |
6639 | case M_DIV_3: | |
6640 | s = "mflo"; | |
6641 | goto do_div3; | |
6642 | case M_DREM_3: | |
6643 | dbl = 1; | |
6644 | case M_REM_3: | |
6645 | s = "mfhi"; | |
6646 | do_div3: | |
6647 | mips_emit_delays (true); | |
6648 | ++mips_opts.noreorder; | |
6649 | mips_any_noreorder = 1; | |
6650 | macro_build ((char *) NULL, &icnt, NULL, | |
6651 | dbl ? "ddiv" : "div", | |
6652 | "0,x,y", xreg, yreg); | |
6653 | expr1.X_add_number = 2; | |
6654 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
6655 | macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7); | |
6656 | ||
6657 | /* FIXME: The normal code checks for of -1 / -0x80000000 here, | |
6658 | since that causes an overflow. We should do that as well, | |
6659 | but I don't see how to do the comparisons without a temporary | |
6660 | register. */ | |
6661 | --mips_opts.noreorder; | |
6662 | macro_build ((char *) NULL, &icnt, NULL, s, "x", zreg); | |
6663 | break; | |
6664 | ||
6665 | case M_DIVU_3: | |
6666 | s = "divu"; | |
6667 | s2 = "mflo"; | |
6668 | goto do_divu3; | |
6669 | case M_REMU_3: | |
6670 | s = "divu"; | |
6671 | s2 = "mfhi"; | |
6672 | goto do_divu3; | |
6673 | case M_DDIVU_3: | |
6674 | s = "ddivu"; | |
6675 | s2 = "mflo"; | |
6676 | goto do_divu3; | |
6677 | case M_DREMU_3: | |
6678 | s = "ddivu"; | |
6679 | s2 = "mfhi"; | |
6680 | do_divu3: | |
6681 | mips_emit_delays (true); | |
6682 | ++mips_opts.noreorder; | |
6683 | mips_any_noreorder = 1; | |
6684 | macro_build ((char *) NULL, &icnt, NULL, s, "0,x,y", xreg, yreg); | |
6685 | expr1.X_add_number = 2; | |
6686 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
6687 | macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7); | |
6688 | --mips_opts.noreorder; | |
6689 | macro_build ((char *) NULL, &icnt, NULL, s2, "x", zreg); | |
6690 | break; | |
6691 | ||
6692 | case M_DMUL: | |
6693 | dbl = 1; | |
6694 | case M_MUL: | |
6695 | macro_build ((char *) NULL, &icnt, NULL, | |
6696 | dbl ? "dmultu" : "multu", | |
6697 | "x,y", xreg, yreg); | |
6698 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "x", zreg); | |
6699 | return; | |
6700 | ||
6701 | case M_DSUBU_I: | |
6702 | dbl = 1; | |
6703 | goto do_subu; | |
6704 | case M_SUBU_I: | |
6705 | do_subu: | |
6706 | if (imm_expr.X_op != O_constant) | |
6707 | as_bad (_("Unsupported large constant")); | |
6708 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6709 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6710 | dbl ? "daddiu" : "addiu", | |
6711 | "y,x,4", yreg, xreg); | |
6712 | break; | |
6713 | ||
6714 | case M_SUBU_I_2: | |
6715 | if (imm_expr.X_op != O_constant) | |
6716 | as_bad (_("Unsupported large constant")); | |
6717 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6718 | macro_build ((char *) NULL, &icnt, &imm_expr, "addiu", | |
6719 | "x,k", xreg); | |
6720 | break; | |
6721 | ||
6722 | case M_DSUBU_I_2: | |
6723 | if (imm_expr.X_op != O_constant) | |
6724 | as_bad (_("Unsupported large constant")); | |
6725 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6726 | macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu", | |
6727 | "y,j", yreg); | |
6728 | break; | |
6729 | ||
6730 | case M_BEQ: | |
6731 | s = "cmp"; | |
6732 | s2 = "bteqz"; | |
6733 | goto do_branch; | |
6734 | case M_BNE: | |
6735 | s = "cmp"; | |
6736 | s2 = "btnez"; | |
6737 | goto do_branch; | |
6738 | case M_BLT: | |
6739 | s = "slt"; | |
6740 | s2 = "btnez"; | |
6741 | goto do_branch; | |
6742 | case M_BLTU: | |
6743 | s = "sltu"; | |
6744 | s2 = "btnez"; | |
6745 | goto do_branch; | |
6746 | case M_BLE: | |
6747 | s = "slt"; | |
6748 | s2 = "bteqz"; | |
6749 | goto do_reverse_branch; | |
6750 | case M_BLEU: | |
6751 | s = "sltu"; | |
6752 | s2 = "bteqz"; | |
6753 | goto do_reverse_branch; | |
6754 | case M_BGE: | |
6755 | s = "slt"; | |
6756 | s2 = "bteqz"; | |
6757 | goto do_branch; | |
6758 | case M_BGEU: | |
6759 | s = "sltu"; | |
6760 | s2 = "bteqz"; | |
6761 | goto do_branch; | |
6762 | case M_BGT: | |
6763 | s = "slt"; | |
6764 | s2 = "btnez"; | |
6765 | goto do_reverse_branch; | |
6766 | case M_BGTU: | |
6767 | s = "sltu"; | |
6768 | s2 = "btnez"; | |
6769 | ||
6770 | do_reverse_branch: | |
6771 | tmp = xreg; | |
6772 | xreg = yreg; | |
6773 | yreg = tmp; | |
6774 | ||
6775 | do_branch: | |
6776 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y", | |
6777 | xreg, yreg); | |
6778 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
6779 | break; | |
6780 | ||
6781 | case M_BEQ_I: | |
6782 | s = "cmpi"; | |
6783 | s2 = "bteqz"; | |
6784 | s3 = "x,U"; | |
6785 | goto do_branch_i; | |
6786 | case M_BNE_I: | |
6787 | s = "cmpi"; | |
6788 | s2 = "btnez"; | |
6789 | s3 = "x,U"; | |
6790 | goto do_branch_i; | |
6791 | case M_BLT_I: | |
6792 | s = "slti"; | |
6793 | s2 = "btnez"; | |
6794 | s3 = "x,8"; | |
6795 | goto do_branch_i; | |
6796 | case M_BLTU_I: | |
6797 | s = "sltiu"; | |
6798 | s2 = "btnez"; | |
6799 | s3 = "x,8"; | |
6800 | goto do_branch_i; | |
6801 | case M_BLE_I: | |
6802 | s = "slti"; | |
6803 | s2 = "btnez"; | |
6804 | s3 = "x,8"; | |
6805 | goto do_addone_branch_i; | |
6806 | case M_BLEU_I: | |
6807 | s = "sltiu"; | |
6808 | s2 = "btnez"; | |
6809 | s3 = "x,8"; | |
6810 | goto do_addone_branch_i; | |
6811 | case M_BGE_I: | |
6812 | s = "slti"; | |
6813 | s2 = "bteqz"; | |
6814 | s3 = "x,8"; | |
6815 | goto do_branch_i; | |
6816 | case M_BGEU_I: | |
6817 | s = "sltiu"; | |
6818 | s2 = "bteqz"; | |
6819 | s3 = "x,8"; | |
6820 | goto do_branch_i; | |
6821 | case M_BGT_I: | |
6822 | s = "slti"; | |
6823 | s2 = "bteqz"; | |
6824 | s3 = "x,8"; | |
6825 | goto do_addone_branch_i; | |
6826 | case M_BGTU_I: | |
6827 | s = "sltiu"; | |
6828 | s2 = "bteqz"; | |
6829 | s3 = "x,8"; | |
6830 | ||
6831 | do_addone_branch_i: | |
6832 | if (imm_expr.X_op != O_constant) | |
6833 | as_bad (_("Unsupported large constant")); | |
6834 | ++imm_expr.X_add_number; | |
6835 | ||
6836 | do_branch_i: | |
6837 | macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg); | |
6838 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
6839 | break; | |
6840 | ||
6841 | case M_ABS: | |
6842 | expr1.X_add_number = 0; | |
6843 | macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg); | |
6844 | if (xreg != yreg) | |
6845 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6846 | "move", "y,X", xreg, yreg); | |
6847 | expr1.X_add_number = 2; | |
6848 | macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p"); | |
6849 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6850 | "neg", "x,w", xreg, xreg); | |
6851 | } | |
6852 | } | |
6853 | ||
6854 | /* For consistency checking, verify that all bits are specified either | |
6855 | by the match/mask part of the instruction definition, or by the | |
6856 | operand list. */ | |
6857 | static int | |
6858 | validate_mips_insn (opc) | |
6859 | const struct mips_opcode *opc; | |
6860 | { | |
6861 | const char *p = opc->args; | |
6862 | char c; | |
6863 | unsigned long used_bits = opc->mask; | |
6864 | ||
6865 | if ((used_bits & opc->match) != opc->match) | |
6866 | { | |
6867 | as_bad (_("internal: bad mips opcode (mask error): %s %s"), | |
6868 | opc->name, opc->args); | |
6869 | return 0; | |
6870 | } | |
6871 | #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift))) | |
6872 | while (*p) | |
6873 | switch (c = *p++) | |
6874 | { | |
6875 | case ',': break; | |
6876 | case '(': break; | |
6877 | case ')': break; | |
6878 | case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
6879 | case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
6880 | case 'A': break; | |
6881 | case 'B': USE_BITS (OP_MASK_SYSCALL, OP_SH_SYSCALL); break; | |
6882 | case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break; | |
6883 | case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break; | |
6884 | case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
6885 | case 'F': break; | |
6886 | case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
6887 | case 'I': break; | |
6888 | case 'L': break; | |
6889 | case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break; | |
6890 | case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break; | |
6891 | case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break; | |
6892 | case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
6893 | case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
6894 | case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
6895 | case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
6896 | case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break; | |
6897 | case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
6898 | case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break; | |
6899 | case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
6900 | case 'f': break; | |
6901 | case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break; | |
6902 | case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
6903 | case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
6904 | case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break; | |
6905 | case 'l': break; | |
6906 | case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
6907 | case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
6908 | case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break; | |
6909 | case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
6910 | case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
6911 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
6912 | case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
6913 | case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
6914 | case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
6915 | case 'x': break; | |
6916 | case 'z': break; | |
6917 | case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break; | |
6918 | default: | |
6919 | as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"), | |
6920 | c, opc->name, opc->args); | |
6921 | return 0; | |
6922 | } | |
6923 | #undef USE_BITS | |
6924 | if (used_bits != 0xffffffff) | |
6925 | { | |
6926 | as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"), | |
6927 | ~used_bits & 0xffffffff, opc->name, opc->args); | |
6928 | return 0; | |
6929 | } | |
6930 | return 1; | |
6931 | } | |
6932 | ||
6933 | /* This routine assembles an instruction into its binary format. As a | |
6934 | side effect, it sets one of the global variables imm_reloc or | |
6935 | offset_reloc to the type of relocation to do if one of the operands | |
6936 | is an address expression. */ | |
6937 | ||
6938 | static void | |
6939 | mips_ip (str, ip) | |
6940 | char *str; | |
6941 | struct mips_cl_insn *ip; | |
6942 | { | |
6943 | char *s; | |
6944 | const char *args; | |
6945 | char c; | |
6946 | struct mips_opcode *insn; | |
6947 | char *argsStart; | |
6948 | unsigned int regno; | |
6949 | unsigned int lastregno = 0; | |
6950 | char *s_reset; | |
6951 | char save_c = 0; | |
6952 | int full_opcode_match = 1; | |
6953 | ||
6954 | insn_error = NULL; | |
6955 | ||
6956 | /* If the instruction contains a '.', we first try to match an instruction | |
6957 | including the '.'. Then we try again without the '.'. */ | |
6958 | insn = NULL; | |
d9a62219 | 6959 | for (s = str; *s != '\0' && !isspace ((unsigned char) *s); ++s) |
252b5132 RH |
6960 | continue; |
6961 | ||
6962 | /* If we stopped on whitespace, then replace the whitespace with null for | |
6963 | the call to hash_find. Save the character we replaced just in case we | |
6964 | have to re-parse the instruction. */ | |
d9a62219 | 6965 | if (isspace ((unsigned char) *s)) |
252b5132 RH |
6966 | { |
6967 | save_c = *s; | |
6968 | *s++ = '\0'; | |
6969 | } | |
6970 | ||
6971 | insn = (struct mips_opcode *) hash_find (op_hash, str); | |
6972 | ||
6973 | /* If we didn't find the instruction in the opcode table, try again, but | |
6974 | this time with just the instruction up to, but not including the | |
6975 | first '.'. */ | |
6976 | if (insn == NULL) | |
6977 | { | |
6978 | /* Restore the character we overwrite above (if any). */ | |
6979 | if (save_c) | |
6980 | *(--s) = save_c; | |
6981 | ||
6982 | /* Scan up to the first '.' or whitespace. */ | |
d9a62219 | 6983 | for (s = str; *s != '\0' && *s != '.' && !isspace ((unsigned char) *s); ++s) |
252b5132 RH |
6984 | continue; |
6985 | ||
6986 | /* If we did not find a '.', then we can quit now. */ | |
6987 | if (*s != '.') | |
6988 | { | |
6989 | insn_error = "unrecognized opcode"; | |
6990 | return; | |
6991 | } | |
6992 | ||
6993 | /* Lookup the instruction in the hash table. */ | |
6994 | *s++ = '\0'; | |
6995 | if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL) | |
6996 | { | |
6997 | insn_error = "unrecognized opcode"; | |
6998 | return; | |
6999 | } | |
7000 | ||
7001 | full_opcode_match = 0; | |
7002 | } | |
7003 | ||
7004 | argsStart = s; | |
7005 | for (;;) | |
7006 | { | |
7007 | int insn_isa; | |
7008 | boolean ok; | |
7009 | ||
7010 | assert (strcmp (insn->name, str) == 0); | |
7011 | ||
7012 | if ((insn->membership & INSN_ISA) == INSN_ISA1) | |
7013 | insn_isa = 1; | |
7014 | else if ((insn->membership & INSN_ISA) == INSN_ISA2) | |
7015 | insn_isa = 2; | |
7016 | else if ((insn->membership & INSN_ISA) == INSN_ISA3) | |
7017 | insn_isa = 3; | |
7018 | else if ((insn->membership & INSN_ISA) == INSN_ISA4) | |
7019 | insn_isa = 4; | |
7020 | else | |
7021 | insn_isa = 15; | |
7022 | ||
7023 | if (insn_isa <= mips_opts.isa) | |
7024 | ok = true; | |
7025 | else if (insn->pinfo == INSN_MACRO) | |
7026 | ok = false; | |
7027 | else if ((mips_cpu == 4650 && (insn->membership & INSN_4650) != 0) | |
7028 | || (mips_cpu == 4010 && (insn->membership & INSN_4010) != 0) | |
7029 | || ((mips_cpu == 4100 | |
7030 | || mips_cpu == 4111 | |
7031 | ) | |
7032 | && (insn->membership & INSN_4100) != 0) | |
7033 | || (mips_cpu == 3900 && (insn->membership & INSN_3900) != 0)) | |
7034 | ok = true; | |
7035 | else | |
7036 | ok = false; | |
7037 | ||
7038 | if (insn->pinfo != INSN_MACRO) | |
7039 | { | |
7040 | if (mips_cpu == 4650 && (insn->pinfo & FP_D) != 0) | |
7041 | ok = false; | |
7042 | } | |
7043 | ||
7044 | if (! ok) | |
7045 | { | |
7046 | if (insn + 1 < &mips_opcodes[NUMOPCODES] | |
7047 | && strcmp (insn->name, insn[1].name) == 0) | |
7048 | { | |
7049 | ++insn; | |
7050 | continue; | |
7051 | } | |
7052 | if (insn_isa == 15 | |
7053 | || insn_isa <= mips_opts.isa) | |
7054 | insn_error = _("opcode not supported on this processor"); | |
7055 | else | |
7056 | { | |
7057 | static char buf[100]; | |
7058 | ||
7059 | sprintf (buf, _("opcode requires -mips%d or greater"), insn_isa); | |
7060 | insn_error = buf; | |
7061 | } | |
7062 | return; | |
7063 | } | |
7064 | ||
7065 | ip->insn_mo = insn; | |
7066 | ip->insn_opcode = insn->match; | |
7067 | for (args = insn->args;; ++args) | |
7068 | { | |
7069 | if (*s == ' ') | |
7070 | ++s; | |
7071 | switch (*args) | |
7072 | { | |
7073 | case '\0': /* end of args */ | |
7074 | if (*s == '\0') | |
7075 | return; | |
7076 | break; | |
7077 | ||
7078 | case ',': | |
7079 | if (*s++ == *args) | |
7080 | continue; | |
7081 | s--; | |
7082 | switch (*++args) | |
7083 | { | |
7084 | case 'r': | |
7085 | case 'v': | |
7086 | ip->insn_opcode |= lastregno << 21; | |
7087 | continue; | |
7088 | ||
7089 | case 'w': | |
7090 | case 'W': | |
7091 | ip->insn_opcode |= lastregno << 16; | |
7092 | continue; | |
7093 | ||
7094 | case 'V': | |
7095 | ip->insn_opcode |= lastregno << 11; | |
7096 | continue; | |
7097 | } | |
7098 | break; | |
7099 | ||
7100 | case '(': | |
7101 | /* Handle optional base register. | |
7102 | Either the base register is omitted or | |
7103 | we must have a left paren. */ | |
7104 | /* This is dependent on the next operand specifier | |
7105 | is a base register specification. */ | |
7106 | assert (args[1] == 'b' || args[1] == '5' | |
7107 | || args[1] == '-' || args[1] == '4'); | |
7108 | if (*s == '\0') | |
7109 | return; | |
7110 | ||
7111 | case ')': /* these must match exactly */ | |
7112 | if (*s++ == *args) | |
7113 | continue; | |
7114 | break; | |
7115 | ||
7116 | case '<': /* must be at least one digit */ | |
7117 | /* | |
7118 | * According to the manual, if the shift amount is greater | |
7119 | * than 31 or less than 0 the the shift amount should be | |
7120 | * mod 32. In reality the mips assembler issues an error. | |
7121 | * We issue a warning and mask out all but the low 5 bits. | |
7122 | */ | |
7123 | my_getExpression (&imm_expr, s); | |
7124 | check_absolute_expr (ip, &imm_expr); | |
7125 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7126 | { | |
7127 | as_warn (_("Improper shift amount (%ld)"), | |
7128 | (long) imm_expr.X_add_number); | |
7129 | imm_expr.X_add_number = imm_expr.X_add_number & 0x1f; | |
7130 | } | |
7131 | ip->insn_opcode |= imm_expr.X_add_number << 6; | |
7132 | imm_expr.X_op = O_absent; | |
7133 | s = expr_end; | |
7134 | continue; | |
7135 | ||
7136 | case '>': /* shift amount minus 32 */ | |
7137 | my_getExpression (&imm_expr, s); | |
7138 | check_absolute_expr (ip, &imm_expr); | |
7139 | if ((unsigned long) imm_expr.X_add_number < 32 | |
7140 | || (unsigned long) imm_expr.X_add_number > 63) | |
7141 | break; | |
7142 | ip->insn_opcode |= (imm_expr.X_add_number - 32) << 6; | |
7143 | imm_expr.X_op = O_absent; | |
7144 | s = expr_end; | |
7145 | continue; | |
7146 | ||
7147 | ||
7148 | case 'k': /* cache code */ | |
7149 | case 'h': /* prefx code */ | |
7150 | my_getExpression (&imm_expr, s); | |
7151 | check_absolute_expr (ip, &imm_expr); | |
7152 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7153 | { | |
7154 | as_warn (_("Invalid value for `%s' (%lu)"), | |
7155 | ip->insn_mo->name, | |
7156 | (unsigned long) imm_expr.X_add_number); | |
7157 | imm_expr.X_add_number &= 0x1f; | |
7158 | } | |
7159 | if (*args == 'k') | |
7160 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE; | |
7161 | else | |
7162 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX; | |
7163 | imm_expr.X_op = O_absent; | |
7164 | s = expr_end; | |
7165 | continue; | |
7166 | ||
7167 | case 'c': /* break code */ | |
7168 | my_getExpression (&imm_expr, s); | |
7169 | check_absolute_expr (ip, &imm_expr); | |
7170 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7171 | { | |
7172 | as_warn (_("Illegal break code (%ld)"), | |
7173 | (long) imm_expr.X_add_number); | |
7174 | imm_expr.X_add_number &= 0x3ff; | |
7175 | } | |
7176 | ip->insn_opcode |= imm_expr.X_add_number << 16; | |
7177 | imm_expr.X_op = O_absent; | |
7178 | s = expr_end; | |
7179 | continue; | |
7180 | ||
7181 | case 'q': /* lower break code */ | |
7182 | my_getExpression (&imm_expr, s); | |
7183 | check_absolute_expr (ip, &imm_expr); | |
7184 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7185 | { | |
7186 | as_warn (_("Illegal lower break code (%ld)"), | |
7187 | (long) imm_expr.X_add_number); | |
7188 | imm_expr.X_add_number &= 0x3ff; | |
7189 | } | |
7190 | ip->insn_opcode |= imm_expr.X_add_number << 6; | |
7191 | imm_expr.X_op = O_absent; | |
7192 | s = expr_end; | |
7193 | continue; | |
7194 | ||
7195 | case 'B': /* syscall code */ | |
7196 | my_getExpression (&imm_expr, s); | |
7197 | check_absolute_expr (ip, &imm_expr); | |
7198 | if ((unsigned) imm_expr.X_add_number > 0xfffff) | |
7199 | as_warn (_("Illegal syscall code (%ld)"), | |
7200 | (long) imm_expr.X_add_number); | |
7201 | ip->insn_opcode |= imm_expr.X_add_number << 6; | |
7202 | imm_expr.X_op = O_absent; | |
7203 | s = expr_end; | |
7204 | continue; | |
7205 | ||
7206 | case 'C': /* Coprocessor code */ | |
7207 | my_getExpression (&imm_expr, s); | |
7208 | check_absolute_expr (ip, &imm_expr); | |
7209 | if ((unsigned long) imm_expr.X_add_number >= (1<<25)) | |
7210 | { | |
7211 | as_warn (_("Coproccesor code > 25 bits (%ld)"), | |
7212 | (long) imm_expr.X_add_number); | |
7213 | imm_expr.X_add_number &= ((1<<25) - 1); | |
7214 | } | |
7215 | ip->insn_opcode |= imm_expr.X_add_number; | |
7216 | imm_expr.X_op = O_absent; | |
7217 | s = expr_end; | |
7218 | continue; | |
7219 | ||
7220 | case 'P': /* Performance register */ | |
7221 | my_getExpression (&imm_expr, s); | |
7222 | check_absolute_expr (ip, &imm_expr); | |
7223 | if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1) | |
7224 | { | |
7225 | as_warn (_("Invalidate performance regster (%ld)"), | |
7226 | (long) imm_expr.X_add_number); | |
7227 | imm_expr.X_add_number &= 1; | |
7228 | } | |
7229 | ip->insn_opcode |= (imm_expr.X_add_number << 1); | |
7230 | imm_expr.X_op = O_absent; | |
7231 | s = expr_end; | |
7232 | continue; | |
7233 | ||
7234 | case 'b': /* base register */ | |
7235 | case 'd': /* destination register */ | |
7236 | case 's': /* source register */ | |
7237 | case 't': /* target register */ | |
7238 | case 'r': /* both target and source */ | |
7239 | case 'v': /* both dest and source */ | |
7240 | case 'w': /* both dest and target */ | |
7241 | case 'E': /* coprocessor target register */ | |
7242 | case 'G': /* coprocessor destination register */ | |
7243 | case 'x': /* ignore register name */ | |
7244 | case 'z': /* must be zero register */ | |
7245 | s_reset = s; | |
7246 | if (s[0] == '$') | |
7247 | { | |
7248 | ||
d9a62219 | 7249 | if (isdigit ((unsigned char) s[1])) |
252b5132 RH |
7250 | { |
7251 | ++s; | |
7252 | regno = 0; | |
7253 | do | |
7254 | { | |
7255 | regno *= 10; | |
7256 | regno += *s - '0'; | |
7257 | ++s; | |
7258 | } | |
d9a62219 | 7259 | while (isdigit ((unsigned char) *s)); |
252b5132 RH |
7260 | if (regno > 31) |
7261 | as_bad (_("Invalid register number (%d)"), regno); | |
7262 | } | |
7263 | else if (*args == 'E' || *args == 'G') | |
7264 | goto notreg; | |
7265 | else | |
7266 | { | |
7267 | if (s[1] == 'f' && s[2] == 'p') | |
7268 | { | |
7269 | s += 3; | |
7270 | regno = FP; | |
7271 | } | |
7272 | else if (s[1] == 's' && s[2] == 'p') | |
7273 | { | |
7274 | s += 3; | |
7275 | regno = SP; | |
7276 | } | |
7277 | else if (s[1] == 'g' && s[2] == 'p') | |
7278 | { | |
7279 | s += 3; | |
7280 | regno = GP; | |
7281 | } | |
7282 | else if (s[1] == 'a' && s[2] == 't') | |
7283 | { | |
7284 | s += 3; | |
7285 | regno = AT; | |
7286 | } | |
7287 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
7288 | { | |
7289 | s += 4; | |
7290 | regno = KT0; | |
7291 | } | |
7292 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
7293 | { | |
7294 | s += 4; | |
7295 | regno = KT1; | |
7296 | } | |
7297 | else if (itbl_have_entries) | |
7298 | { | |
7299 | char *p, *n; | |
d7ba4a77 | 7300 | unsigned long r; |
252b5132 | 7301 | |
d7ba4a77 | 7302 | p = s + 1; /* advance past '$' */ |
252b5132 RH |
7303 | n = itbl_get_field (&p); /* n is name */ |
7304 | ||
d7ba4a77 ILT |
7305 | /* See if this is a register defined in an |
7306 | itbl entry. */ | |
7307 | if (itbl_get_reg_val (n, &r)) | |
252b5132 RH |
7308 | { |
7309 | /* Get_field advances to the start of | |
7310 | the next field, so we need to back | |
d7ba4a77 | 7311 | rack to the end of the last field. */ |
252b5132 RH |
7312 | if (p) |
7313 | s = p - 1; | |
7314 | else | |
d7ba4a77 | 7315 | s = strchr (s, '\0'); |
252b5132 RH |
7316 | regno = r; |
7317 | } | |
7318 | else | |
7319 | goto notreg; | |
7320 | } | |
7321 | else | |
7322 | goto notreg; | |
7323 | } | |
7324 | if (regno == AT | |
7325 | && ! mips_opts.noat | |
7326 | && *args != 'E' | |
7327 | && *args != 'G') | |
7328 | as_warn (_("Used $at without \".set noat\"")); | |
7329 | c = *args; | |
7330 | if (*s == ' ') | |
7331 | s++; | |
7332 | if (args[1] != *s) | |
7333 | { | |
7334 | if (c == 'r' || c == 'v' || c == 'w') | |
7335 | { | |
7336 | regno = lastregno; | |
7337 | s = s_reset; | |
7338 | args++; | |
7339 | } | |
7340 | } | |
7341 | /* 'z' only matches $0. */ | |
7342 | if (c == 'z' && regno != 0) | |
7343 | break; | |
7344 | ||
7345 | /* Now that we have assembled one operand, we use the args string | |
7346 | * to figure out where it goes in the instruction. */ | |
7347 | switch (c) | |
7348 | { | |
7349 | case 'r': | |
7350 | case 's': | |
7351 | case 'v': | |
7352 | case 'b': | |
7353 | ip->insn_opcode |= regno << 21; | |
7354 | break; | |
7355 | case 'd': | |
7356 | case 'G': | |
7357 | ip->insn_opcode |= regno << 11; | |
7358 | break; | |
7359 | case 'w': | |
7360 | case 't': | |
7361 | case 'E': | |
7362 | ip->insn_opcode |= regno << 16; | |
7363 | break; | |
7364 | case 'x': | |
7365 | /* This case exists because on the r3000 trunc | |
7366 | expands into a macro which requires a gp | |
7367 | register. On the r6000 or r4000 it is | |
7368 | assembled into a single instruction which | |
7369 | ignores the register. Thus the insn version | |
7370 | is MIPS_ISA2 and uses 'x', and the macro | |
7371 | version is MIPS_ISA1 and uses 't'. */ | |
7372 | break; | |
7373 | case 'z': | |
7374 | /* This case is for the div instruction, which | |
7375 | acts differently if the destination argument | |
7376 | is $0. This only matches $0, and is checked | |
7377 | outside the switch. */ | |
7378 | break; | |
7379 | case 'D': | |
7380 | /* Itbl operand; not yet implemented. FIXME ?? */ | |
7381 | break; | |
7382 | /* What about all other operands like 'i', which | |
7383 | can be specified in the opcode table? */ | |
7384 | } | |
7385 | lastregno = regno; | |
7386 | continue; | |
7387 | } | |
7388 | notreg: | |
7389 | switch (*args++) | |
7390 | { | |
7391 | case 'r': | |
7392 | case 'v': | |
7393 | ip->insn_opcode |= lastregno << 21; | |
7394 | continue; | |
7395 | case 'w': | |
7396 | ip->insn_opcode |= lastregno << 16; | |
7397 | continue; | |
7398 | } | |
7399 | break; | |
7400 | ||
7401 | case 'D': /* floating point destination register */ | |
7402 | case 'S': /* floating point source register */ | |
7403 | case 'T': /* floating point target register */ | |
7404 | case 'R': /* floating point source register */ | |
7405 | case 'V': | |
7406 | case 'W': | |
7407 | s_reset = s; | |
d9a62219 | 7408 | if (s[0] == '$' && s[1] == 'f' && isdigit ((unsigned char) s[2])) |
252b5132 RH |
7409 | { |
7410 | s += 2; | |
7411 | regno = 0; | |
7412 | do | |
7413 | { | |
7414 | regno *= 10; | |
7415 | regno += *s - '0'; | |
7416 | ++s; | |
7417 | } | |
d9a62219 | 7418 | while (isdigit ((unsigned char) *s)); |
252b5132 RH |
7419 | |
7420 | if (regno > 31) | |
7421 | as_bad (_("Invalid float register number (%d)"), regno); | |
7422 | ||
7423 | if ((regno & 1) != 0 | |
7424 | && mips_opts.isa < 3 | |
7425 | && ! (strcmp (str, "mtc1") == 0 | |
7426 | || strcmp (str, "mfc1") == 0 | |
7427 | || strcmp (str, "lwc1") == 0 | |
7428 | || strcmp (str, "swc1") == 0 | |
7429 | || strcmp (str, "l.s") == 0 | |
7430 | || strcmp (str, "s.s") == 0)) | |
7431 | as_warn (_("Float register should be even, was %d"), | |
7432 | regno); | |
7433 | ||
7434 | c = *args; | |
7435 | if (*s == ' ') | |
7436 | s++; | |
7437 | if (args[1] != *s) | |
7438 | { | |
7439 | if (c == 'V' || c == 'W') | |
7440 | { | |
7441 | regno = lastregno; | |
7442 | s = s_reset; | |
7443 | args++; | |
7444 | } | |
7445 | } | |
7446 | switch (c) | |
7447 | { | |
7448 | case 'D': | |
7449 | ip->insn_opcode |= regno << 6; | |
7450 | break; | |
7451 | case 'V': | |
7452 | case 'S': | |
7453 | ip->insn_opcode |= regno << 11; | |
7454 | break; | |
7455 | case 'W': | |
7456 | case 'T': | |
7457 | ip->insn_opcode |= regno << 16; | |
7458 | break; | |
7459 | case 'R': | |
7460 | ip->insn_opcode |= regno << 21; | |
7461 | break; | |
7462 | } | |
7463 | lastregno = regno; | |
7464 | continue; | |
7465 | } | |
7466 | ||
7467 | ||
7468 | switch (*args++) | |
7469 | { | |
7470 | case 'V': | |
7471 | ip->insn_opcode |= lastregno << 11; | |
7472 | continue; | |
7473 | case 'W': | |
7474 | ip->insn_opcode |= lastregno << 16; | |
7475 | continue; | |
7476 | } | |
7477 | break; | |
7478 | ||
7479 | case 'I': | |
7480 | my_getExpression (&imm_expr, s); | |
7481 | if (imm_expr.X_op != O_big | |
7482 | && imm_expr.X_op != O_constant) | |
7483 | insn_error = _("absolute expression required"); | |
7484 | s = expr_end; | |
7485 | continue; | |
7486 | ||
7487 | case 'A': | |
7488 | my_getExpression (&offset_expr, s); | |
7489 | imm_reloc = BFD_RELOC_32; | |
7490 | s = expr_end; | |
7491 | continue; | |
7492 | ||
7493 | case 'F': | |
7494 | case 'L': | |
7495 | case 'f': | |
7496 | case 'l': | |
7497 | { | |
7498 | int f64; | |
7499 | char *save_in; | |
7500 | char *err; | |
7501 | unsigned char temp[8]; | |
7502 | int len; | |
7503 | unsigned int length; | |
7504 | segT seg; | |
7505 | subsegT subseg; | |
7506 | char *p; | |
7507 | ||
7508 | /* These only appear as the last operand in an | |
7509 | instruction, and every instruction that accepts | |
7510 | them in any variant accepts them in all variants. | |
7511 | This means we don't have to worry about backing out | |
7512 | any changes if the instruction does not match. | |
7513 | ||
7514 | The difference between them is the size of the | |
7515 | floating point constant and where it goes. For 'F' | |
7516 | and 'L' the constant is 64 bits; for 'f' and 'l' it | |
7517 | is 32 bits. Where the constant is placed is based | |
7518 | on how the MIPS assembler does things: | |
7519 | F -- .rdata | |
7520 | L -- .lit8 | |
7521 | f -- immediate value | |
7522 | l -- .lit4 | |
7523 | ||
7524 | The .lit4 and .lit8 sections are only used if | |
7525 | permitted by the -G argument. | |
7526 | ||
7527 | When generating embedded PIC code, we use the | |
7528 | .lit8 section but not the .lit4 section (we can do | |
7529 | .lit4 inline easily; we need to put .lit8 | |
7530 | somewhere in the data segment, and using .lit8 | |
7531 | permits the linker to eventually combine identical | |
7532 | .lit8 entries). */ | |
7533 | ||
7534 | f64 = *args == 'F' || *args == 'L'; | |
7535 | ||
7536 | save_in = input_line_pointer; | |
7537 | input_line_pointer = s; | |
7538 | err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len); | |
7539 | length = len; | |
7540 | s = input_line_pointer; | |
7541 | input_line_pointer = save_in; | |
7542 | if (err != NULL && *err != '\0') | |
7543 | { | |
7544 | as_bad (_("Bad floating point constant: %s"), err); | |
7545 | memset (temp, '\0', sizeof temp); | |
7546 | length = f64 ? 8 : 4; | |
7547 | } | |
7548 | ||
7549 | assert (length == (f64 ? 8 : 4)); | |
7550 | ||
7551 | if (*args == 'f' | |
7552 | || (*args == 'l' | |
7553 | && (! USE_GLOBAL_POINTER_OPT | |
7554 | || mips_pic == EMBEDDED_PIC | |
7555 | || g_switch_value < 4 | |
7556 | || (temp[0] == 0 && temp[1] == 0) | |
7557 | || (temp[2] == 0 && temp[3] == 0)))) | |
7558 | { | |
7559 | imm_expr.X_op = O_constant; | |
7560 | if (! target_big_endian) | |
7561 | imm_expr.X_add_number = bfd_getl32 (temp); | |
7562 | else | |
7563 | imm_expr.X_add_number = bfd_getb32 (temp); | |
7564 | } | |
7565 | else if (length > 4 | |
7566 | && ((temp[0] == 0 && temp[1] == 0) | |
7567 | || (temp[2] == 0 && temp[3] == 0)) | |
7568 | && ((temp[4] == 0 && temp[5] == 0) | |
7569 | || (temp[6] == 0 && temp[7] == 0))) | |
7570 | { | |
7571 | /* The value is simple enough to load with a | |
7572 | couple of instructions. In mips1 mode, set | |
7573 | imm_expr to the high order 32 bits and | |
7574 | offset_expr to the low order 32 bits. | |
7575 | Otherwise, set imm_expr to the entire 64 bit | |
7576 | constant. */ | |
7577 | if (mips_opts.isa < 3) | |
7578 | { | |
7579 | imm_expr.X_op = O_constant; | |
7580 | offset_expr.X_op = O_constant; | |
7581 | if (! target_big_endian) | |
7582 | { | |
7583 | imm_expr.X_add_number = bfd_getl32 (temp + 4); | |
7584 | offset_expr.X_add_number = bfd_getl32 (temp); | |
7585 | } | |
7586 | else | |
7587 | { | |
7588 | imm_expr.X_add_number = bfd_getb32 (temp); | |
7589 | offset_expr.X_add_number = bfd_getb32 (temp + 4); | |
7590 | } | |
7591 | if (offset_expr.X_add_number == 0) | |
7592 | offset_expr.X_op = O_absent; | |
7593 | } | |
7594 | else if (sizeof (imm_expr.X_add_number) > 4) | |
7595 | { | |
7596 | imm_expr.X_op = O_constant; | |
7597 | if (! target_big_endian) | |
7598 | imm_expr.X_add_number = bfd_getl64 (temp); | |
7599 | else | |
7600 | imm_expr.X_add_number = bfd_getb64 (temp); | |
7601 | } | |
7602 | else | |
7603 | { | |
7604 | imm_expr.X_op = O_big; | |
7605 | imm_expr.X_add_number = 4; | |
7606 | if (! target_big_endian) | |
7607 | { | |
7608 | generic_bignum[0] = bfd_getl16 (temp); | |
7609 | generic_bignum[1] = bfd_getl16 (temp + 2); | |
7610 | generic_bignum[2] = bfd_getl16 (temp + 4); | |
7611 | generic_bignum[3] = bfd_getl16 (temp + 6); | |
7612 | } | |
7613 | else | |
7614 | { | |
7615 | generic_bignum[0] = bfd_getb16 (temp + 6); | |
7616 | generic_bignum[1] = bfd_getb16 (temp + 4); | |
7617 | generic_bignum[2] = bfd_getb16 (temp + 2); | |
7618 | generic_bignum[3] = bfd_getb16 (temp); | |
7619 | } | |
7620 | } | |
7621 | } | |
7622 | else | |
7623 | { | |
7624 | const char *newname; | |
7625 | segT new_seg; | |
7626 | ||
7627 | /* Switch to the right section. */ | |
7628 | seg = now_seg; | |
7629 | subseg = now_subseg; | |
7630 | switch (*args) | |
7631 | { | |
7632 | default: /* unused default case avoids warnings. */ | |
7633 | case 'L': | |
7634 | newname = RDATA_SECTION_NAME; | |
7635 | if (USE_GLOBAL_POINTER_OPT && g_switch_value >= 8) | |
7636 | newname = ".lit8"; | |
7637 | break; | |
7638 | case 'F': | |
7639 | newname = RDATA_SECTION_NAME; | |
7640 | break; | |
7641 | case 'l': | |
7642 | assert (!USE_GLOBAL_POINTER_OPT | |
7643 | || g_switch_value >= 4); | |
7644 | newname = ".lit4"; | |
7645 | break; | |
7646 | } | |
7647 | new_seg = subseg_new (newname, (subsegT) 0); | |
7648 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
7649 | bfd_set_section_flags (stdoutput, new_seg, | |
7650 | (SEC_ALLOC | |
7651 | | SEC_LOAD | |
7652 | | SEC_READONLY | |
7653 | | SEC_DATA)); | |
7654 | frag_align (*args == 'l' ? 2 : 3, 0, 0); | |
7655 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
7656 | && strcmp (TARGET_OS, "elf") != 0) | |
7657 | record_alignment (new_seg, 4); | |
7658 | else | |
7659 | record_alignment (new_seg, *args == 'l' ? 2 : 3); | |
7660 | if (seg == now_seg) | |
7661 | as_bad (_("Can't use floating point insn in this section")); | |
7662 | ||
7663 | /* Set the argument to the current address in the | |
7664 | section. */ | |
7665 | offset_expr.X_op = O_symbol; | |
7666 | offset_expr.X_add_symbol = | |
7667 | symbol_new ("L0\001", now_seg, | |
7668 | (valueT) frag_now_fix (), frag_now); | |
7669 | offset_expr.X_add_number = 0; | |
7670 | ||
7671 | /* Put the floating point number into the section. */ | |
7672 | p = frag_more ((int) length); | |
7673 | memcpy (p, temp, length); | |
7674 | ||
7675 | /* Switch back to the original section. */ | |
7676 | subseg_set (seg, subseg); | |
7677 | } | |
7678 | } | |
7679 | continue; | |
7680 | ||
7681 | case 'i': /* 16 bit unsigned immediate */ | |
7682 | case 'j': /* 16 bit signed immediate */ | |
7683 | imm_reloc = BFD_RELOC_LO16; | |
7684 | c = my_getSmallExpression (&imm_expr, s); | |
7685 | if (c != '\0') | |
7686 | { | |
7687 | if (c != 'l') | |
7688 | { | |
7689 | if (imm_expr.X_op == O_constant) | |
7690 | imm_expr.X_add_number = | |
7691 | (imm_expr.X_add_number >> 16) & 0xffff; | |
7692 | else if (c == 'h') | |
7693 | { | |
7694 | imm_reloc = BFD_RELOC_HI16_S; | |
7695 | imm_unmatched_hi = true; | |
7696 | } | |
7697 | else | |
7698 | imm_reloc = BFD_RELOC_HI16; | |
7699 | } | |
7700 | else if (imm_expr.X_op == O_constant) | |
7701 | imm_expr.X_add_number &= 0xffff; | |
7702 | } | |
7703 | if (*args == 'i') | |
7704 | { | |
7705 | if ((c == '\0' && imm_expr.X_op != O_constant) | |
7706 | || ((imm_expr.X_add_number < 0 | |
7707 | || imm_expr.X_add_number >= 0x10000) | |
7708 | && imm_expr.X_op == O_constant)) | |
7709 | { | |
7710 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7711 | !strcmp (insn->name, insn[1].name)) | |
7712 | break; | |
7713 | if (imm_expr.X_op != O_constant | |
7714 | && imm_expr.X_op != O_big) | |
7715 | insn_error = _("absolute expression required"); | |
7716 | else | |
7717 | as_bad (_("16 bit expression not in range 0..65535")); | |
7718 | } | |
7719 | } | |
7720 | else | |
7721 | { | |
7722 | int more; | |
7723 | offsetT max; | |
7724 | ||
7725 | /* The upper bound should be 0x8000, but | |
7726 | unfortunately the MIPS assembler accepts numbers | |
7727 | from 0x8000 to 0xffff and sign extends them, and | |
7728 | we want to be compatible. We only permit this | |
7729 | extended range for an instruction which does not | |
7730 | provide any further alternates, since those | |
7731 | alternates may handle other cases. People should | |
7732 | use the numbers they mean, rather than relying on | |
7733 | a mysterious sign extension. */ | |
7734 | more = (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7735 | strcmp (insn->name, insn[1].name) == 0); | |
7736 | if (more) | |
7737 | max = 0x8000; | |
7738 | else | |
7739 | max = 0x10000; | |
7740 | if ((c == '\0' && imm_expr.X_op != O_constant) | |
7741 | || ((imm_expr.X_add_number < -0x8000 | |
7742 | || imm_expr.X_add_number >= max) | |
7743 | && imm_expr.X_op == O_constant) | |
7744 | || (more | |
7745 | && imm_expr.X_add_number < 0 | |
7746 | && mips_opts.isa >= 3 | |
7747 | && imm_expr.X_unsigned | |
7748 | && sizeof (imm_expr.X_add_number) <= 4)) | |
7749 | { | |
7750 | if (more) | |
7751 | break; | |
7752 | if (imm_expr.X_op != O_constant | |
7753 | && imm_expr.X_op != O_big) | |
7754 | insn_error = _("absolute expression required"); | |
7755 | else | |
7756 | as_bad (_("16 bit expression not in range -32768..32767")); | |
7757 | } | |
7758 | } | |
7759 | s = expr_end; | |
7760 | continue; | |
7761 | ||
7762 | case 'o': /* 16 bit offset */ | |
7763 | c = my_getSmallExpression (&offset_expr, s); | |
7764 | ||
7765 | /* If this value won't fit into a 16 bit offset, then go | |
7766 | find a macro that will generate the 32 bit offset | |
7767 | code pattern. As a special hack, we accept the | |
7768 | difference of two local symbols as a constant. This | |
7769 | is required to suppose embedded PIC switches, which | |
7770 | use an instruction which looks like | |
7771 | lw $4,$L12-$LS12($4) | |
7772 | The problem with handling this in a more general | |
7773 | fashion is that the macro function doesn't expect to | |
7774 | see anything which can be handled in a single | |
7775 | constant instruction. */ | |
7776 | if (c == 0 | |
7777 | && (offset_expr.X_op != O_constant | |
7778 | || offset_expr.X_add_number >= 0x8000 | |
7779 | || offset_expr.X_add_number < -0x8000) | |
7780 | && (mips_pic != EMBEDDED_PIC | |
7781 | || offset_expr.X_op != O_subtract | |
7782 | || now_seg != text_section | |
7783 | || (S_GET_SEGMENT (offset_expr.X_op_symbol) | |
7784 | != text_section))) | |
7785 | break; | |
7786 | ||
7787 | if (c == 'h' || c == 'H') | |
7788 | { | |
7789 | if (offset_expr.X_op != O_constant) | |
7790 | break; | |
7791 | offset_expr.X_add_number = | |
7792 | (offset_expr.X_add_number >> 16) & 0xffff; | |
7793 | } | |
7794 | offset_reloc = BFD_RELOC_LO16; | |
7795 | s = expr_end; | |
7796 | continue; | |
7797 | ||
7798 | case 'p': /* pc relative offset */ | |
7799 | offset_reloc = BFD_RELOC_16_PCREL_S2; | |
7800 | my_getExpression (&offset_expr, s); | |
7801 | s = expr_end; | |
7802 | continue; | |
7803 | ||
7804 | case 'u': /* upper 16 bits */ | |
7805 | c = my_getSmallExpression (&imm_expr, s); | |
7806 | imm_reloc = BFD_RELOC_LO16; | |
7807 | if (c) | |
7808 | { | |
7809 | if (c != 'l') | |
7810 | { | |
7811 | if (imm_expr.X_op == O_constant) | |
7812 | imm_expr.X_add_number = | |
7813 | (imm_expr.X_add_number >> 16) & 0xffff; | |
7814 | else if (c == 'h') | |
7815 | { | |
7816 | imm_reloc = BFD_RELOC_HI16_S; | |
7817 | imm_unmatched_hi = true; | |
7818 | } | |
7819 | else | |
7820 | imm_reloc = BFD_RELOC_HI16; | |
7821 | } | |
7822 | else if (imm_expr.X_op == O_constant) | |
7823 | imm_expr.X_add_number &= 0xffff; | |
7824 | } | |
7825 | if (imm_expr.X_op == O_constant | |
7826 | && (imm_expr.X_add_number < 0 | |
7827 | || imm_expr.X_add_number >= 0x10000)) | |
7828 | as_bad (_("lui expression not in range 0..65535")); | |
7829 | s = expr_end; | |
7830 | continue; | |
7831 | ||
7832 | case 'a': /* 26 bit address */ | |
7833 | my_getExpression (&offset_expr, s); | |
7834 | s = expr_end; | |
7835 | offset_reloc = BFD_RELOC_MIPS_JMP; | |
7836 | continue; | |
7837 | ||
7838 | case 'N': /* 3 bit branch condition code */ | |
7839 | case 'M': /* 3 bit compare condition code */ | |
7840 | if (strncmp (s, "$fcc", 4) != 0) | |
7841 | break; | |
7842 | s += 4; | |
7843 | regno = 0; | |
7844 | do | |
7845 | { | |
7846 | regno *= 10; | |
7847 | regno += *s - '0'; | |
7848 | ++s; | |
7849 | } | |
d9a62219 | 7850 | while (isdigit ((unsigned char) *s)); |
252b5132 RH |
7851 | if (regno > 7) |
7852 | as_bad (_("invalid condition code register $fcc%d"), regno); | |
7853 | if (*args == 'N') | |
7854 | ip->insn_opcode |= regno << OP_SH_BCC; | |
7855 | else | |
7856 | ip->insn_opcode |= regno << OP_SH_CCC; | |
7857 | continue; | |
7858 | ||
7859 | default: | |
7860 | as_bad (_("bad char = '%c'\n"), *args); | |
7861 | internalError (); | |
7862 | } | |
7863 | break; | |
7864 | } | |
7865 | /* Args don't match. */ | |
7866 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7867 | !strcmp (insn->name, insn[1].name)) | |
7868 | { | |
7869 | ++insn; | |
7870 | s = argsStart; | |
7871 | continue; | |
7872 | } | |
7873 | insn_error = _("illegal operands"); | |
7874 | return; | |
7875 | } | |
7876 | } | |
7877 | ||
7878 | /* This routine assembles an instruction into its binary format when | |
7879 | assembling for the mips16. As a side effect, it sets one of the | |
7880 | global variables imm_reloc or offset_reloc to the type of | |
7881 | relocation to do if one of the operands is an address expression. | |
7882 | It also sets mips16_small and mips16_ext if the user explicitly | |
7883 | requested a small or extended instruction. */ | |
7884 | ||
7885 | static void | |
7886 | mips16_ip (str, ip) | |
7887 | char *str; | |
7888 | struct mips_cl_insn *ip; | |
7889 | { | |
7890 | char *s; | |
7891 | const char *args; | |
7892 | struct mips_opcode *insn; | |
7893 | char *argsstart; | |
7894 | unsigned int regno; | |
7895 | unsigned int lastregno = 0; | |
7896 | char *s_reset; | |
7897 | ||
7898 | insn_error = NULL; | |
7899 | ||
7900 | mips16_small = false; | |
7901 | mips16_ext = false; | |
7902 | ||
d9a62219 | 7903 | for (s = str; islower ((unsigned char) *s); ++s) |
252b5132 RH |
7904 | ; |
7905 | switch (*s) | |
7906 | { | |
7907 | case '\0': | |
7908 | break; | |
7909 | ||
7910 | case ' ': | |
7911 | *s++ = '\0'; | |
7912 | break; | |
7913 | ||
7914 | case '.': | |
7915 | if (s[1] == 't' && s[2] == ' ') | |
7916 | { | |
7917 | *s = '\0'; | |
7918 | mips16_small = true; | |
7919 | s += 3; | |
7920 | break; | |
7921 | } | |
7922 | else if (s[1] == 'e' && s[2] == ' ') | |
7923 | { | |
7924 | *s = '\0'; | |
7925 | mips16_ext = true; | |
7926 | s += 3; | |
7927 | break; | |
7928 | } | |
7929 | /* Fall through. */ | |
7930 | default: | |
7931 | insn_error = _("unknown opcode"); | |
7932 | return; | |
7933 | } | |
7934 | ||
7935 | if (mips_opts.noautoextend && ! mips16_ext) | |
7936 | mips16_small = true; | |
7937 | ||
7938 | if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL) | |
7939 | { | |
7940 | insn_error = _("unrecognized opcode"); | |
7941 | return; | |
7942 | } | |
7943 | ||
7944 | argsstart = s; | |
7945 | for (;;) | |
7946 | { | |
7947 | assert (strcmp (insn->name, str) == 0); | |
7948 | ||
7949 | ip->insn_mo = insn; | |
7950 | ip->insn_opcode = insn->match; | |
7951 | ip->use_extend = false; | |
7952 | imm_expr.X_op = O_absent; | |
7953 | imm_reloc = BFD_RELOC_UNUSED; | |
7954 | offset_expr.X_op = O_absent; | |
7955 | offset_reloc = BFD_RELOC_UNUSED; | |
7956 | for (args = insn->args; 1; ++args) | |
7957 | { | |
7958 | int c; | |
7959 | ||
7960 | if (*s == ' ') | |
7961 | ++s; | |
7962 | ||
7963 | /* In this switch statement we call break if we did not find | |
7964 | a match, continue if we did find a match, or return if we | |
7965 | are done. */ | |
7966 | ||
7967 | c = *args; | |
7968 | switch (c) | |
7969 | { | |
7970 | case '\0': | |
7971 | if (*s == '\0') | |
7972 | { | |
7973 | /* Stuff the immediate value in now, if we can. */ | |
7974 | if (imm_expr.X_op == O_constant | |
7975 | && imm_reloc > BFD_RELOC_UNUSED | |
7976 | && insn->pinfo != INSN_MACRO) | |
7977 | { | |
7978 | mips16_immed ((char *) NULL, 0, | |
7979 | imm_reloc - BFD_RELOC_UNUSED, | |
7980 | imm_expr.X_add_number, true, mips16_small, | |
7981 | mips16_ext, &ip->insn_opcode, | |
7982 | &ip->use_extend, &ip->extend); | |
7983 | imm_expr.X_op = O_absent; | |
7984 | imm_reloc = BFD_RELOC_UNUSED; | |
7985 | } | |
7986 | ||
7987 | return; | |
7988 | } | |
7989 | break; | |
7990 | ||
7991 | case ',': | |
7992 | if (*s++ == c) | |
7993 | continue; | |
7994 | s--; | |
7995 | switch (*++args) | |
7996 | { | |
7997 | case 'v': | |
7998 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
7999 | continue; | |
8000 | case 'w': | |
8001 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8002 | continue; | |
8003 | } | |
8004 | break; | |
8005 | ||
8006 | case '(': | |
8007 | case ')': | |
8008 | if (*s++ == c) | |
8009 | continue; | |
8010 | break; | |
8011 | ||
8012 | case 'v': | |
8013 | case 'w': | |
8014 | if (s[0] != '$') | |
8015 | { | |
8016 | if (c == 'v') | |
8017 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8018 | else | |
8019 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8020 | ++args; | |
8021 | continue; | |
8022 | } | |
8023 | /* Fall through. */ | |
8024 | case 'x': | |
8025 | case 'y': | |
8026 | case 'z': | |
8027 | case 'Z': | |
8028 | case '0': | |
8029 | case 'S': | |
8030 | case 'R': | |
8031 | case 'X': | |
8032 | case 'Y': | |
8033 | if (s[0] != '$') | |
8034 | break; | |
8035 | s_reset = s; | |
d9a62219 | 8036 | if (isdigit ((unsigned char) s[1])) |
252b5132 RH |
8037 | { |
8038 | ++s; | |
8039 | regno = 0; | |
8040 | do | |
8041 | { | |
8042 | regno *= 10; | |
8043 | regno += *s - '0'; | |
8044 | ++s; | |
8045 | } | |
d9a62219 | 8046 | while (isdigit ((unsigned char) *s)); |
252b5132 RH |
8047 | if (regno > 31) |
8048 | { | |
8049 | as_bad (_("invalid register number (%d)"), regno); | |
8050 | regno = 2; | |
8051 | } | |
8052 | } | |
8053 | else | |
8054 | { | |
8055 | if (s[1] == 'f' && s[2] == 'p') | |
8056 | { | |
8057 | s += 3; | |
8058 | regno = FP; | |
8059 | } | |
8060 | else if (s[1] == 's' && s[2] == 'p') | |
8061 | { | |
8062 | s += 3; | |
8063 | regno = SP; | |
8064 | } | |
8065 | else if (s[1] == 'g' && s[2] == 'p') | |
8066 | { | |
8067 | s += 3; | |
8068 | regno = GP; | |
8069 | } | |
8070 | else if (s[1] == 'a' && s[2] == 't') | |
8071 | { | |
8072 | s += 3; | |
8073 | regno = AT; | |
8074 | } | |
8075 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
8076 | { | |
8077 | s += 4; | |
8078 | regno = KT0; | |
8079 | } | |
8080 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
8081 | { | |
8082 | s += 4; | |
8083 | regno = KT1; | |
8084 | } | |
8085 | else | |
8086 | break; | |
8087 | } | |
8088 | ||
8089 | if (*s == ' ') | |
8090 | ++s; | |
8091 | if (args[1] != *s) | |
8092 | { | |
8093 | if (c == 'v' || c == 'w') | |
8094 | { | |
8095 | regno = mips16_to_32_reg_map[lastregno]; | |
8096 | s = s_reset; | |
8097 | args++; | |
8098 | } | |
8099 | } | |
8100 | ||
8101 | switch (c) | |
8102 | { | |
8103 | case 'x': | |
8104 | case 'y': | |
8105 | case 'z': | |
8106 | case 'v': | |
8107 | case 'w': | |
8108 | case 'Z': | |
8109 | regno = mips32_to_16_reg_map[regno]; | |
8110 | break; | |
8111 | ||
8112 | case '0': | |
8113 | if (regno != 0) | |
8114 | regno = ILLEGAL_REG; | |
8115 | break; | |
8116 | ||
8117 | case 'S': | |
8118 | if (regno != SP) | |
8119 | regno = ILLEGAL_REG; | |
8120 | break; | |
8121 | ||
8122 | case 'R': | |
8123 | if (regno != RA) | |
8124 | regno = ILLEGAL_REG; | |
8125 | break; | |
8126 | ||
8127 | case 'X': | |
8128 | case 'Y': | |
8129 | if (regno == AT && ! mips_opts.noat) | |
8130 | as_warn (_("used $at without \".set noat\"")); | |
8131 | break; | |
8132 | ||
8133 | default: | |
8134 | internalError (); | |
8135 | } | |
8136 | ||
8137 | if (regno == ILLEGAL_REG) | |
8138 | break; | |
8139 | ||
8140 | switch (c) | |
8141 | { | |
8142 | case 'x': | |
8143 | case 'v': | |
8144 | ip->insn_opcode |= regno << MIPS16OP_SH_RX; | |
8145 | break; | |
8146 | case 'y': | |
8147 | case 'w': | |
8148 | ip->insn_opcode |= regno << MIPS16OP_SH_RY; | |
8149 | break; | |
8150 | case 'z': | |
8151 | ip->insn_opcode |= regno << MIPS16OP_SH_RZ; | |
8152 | break; | |
8153 | case 'Z': | |
8154 | ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z; | |
8155 | case '0': | |
8156 | case 'S': | |
8157 | case 'R': | |
8158 | break; | |
8159 | case 'X': | |
8160 | ip->insn_opcode |= regno << MIPS16OP_SH_REGR32; | |
8161 | break; | |
8162 | case 'Y': | |
8163 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
8164 | ip->insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
8165 | break; | |
8166 | default: | |
8167 | internalError (); | |
8168 | } | |
8169 | ||
8170 | lastregno = regno; | |
8171 | continue; | |
8172 | ||
8173 | case 'P': | |
8174 | if (strncmp (s, "$pc", 3) == 0) | |
8175 | { | |
8176 | s += 3; | |
8177 | continue; | |
8178 | } | |
8179 | break; | |
8180 | ||
8181 | case '<': | |
8182 | case '>': | |
8183 | case '[': | |
8184 | case ']': | |
8185 | case '4': | |
8186 | case '5': | |
8187 | case 'H': | |
8188 | case 'W': | |
8189 | case 'D': | |
8190 | case 'j': | |
8191 | case '8': | |
8192 | case 'V': | |
8193 | case 'C': | |
8194 | case 'U': | |
8195 | case 'k': | |
8196 | case 'K': | |
8197 | if (s[0] == '%' | |
8198 | && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0) | |
8199 | { | |
8200 | /* This is %gprel(SYMBOL). We need to read SYMBOL, | |
8201 | and generate the appropriate reloc. If the text | |
8202 | inside %gprel is not a symbol name with an | |
8203 | optional offset, then we generate a normal reloc | |
8204 | and will probably fail later. */ | |
8205 | my_getExpression (&imm_expr, s + sizeof "%gprel" - 1); | |
8206 | if (imm_expr.X_op == O_symbol) | |
8207 | { | |
8208 | mips16_ext = true; | |
8209 | imm_reloc = BFD_RELOC_MIPS16_GPREL; | |
8210 | s = expr_end; | |
8211 | ip->use_extend = true; | |
8212 | ip->extend = 0; | |
8213 | continue; | |
8214 | } | |
8215 | } | |
8216 | else | |
8217 | { | |
8218 | /* Just pick up a normal expression. */ | |
8219 | my_getExpression (&imm_expr, s); | |
8220 | } | |
8221 | ||
8222 | if (imm_expr.X_op == O_register) | |
8223 | { | |
8224 | /* What we thought was an expression turned out to | |
8225 | be a register. */ | |
8226 | ||
8227 | if (s[0] == '(' && args[1] == '(') | |
8228 | { | |
8229 | /* It looks like the expression was omitted | |
8230 | before a register indirection, which means | |
8231 | that the expression is implicitly zero. We | |
8232 | still set up imm_expr, so that we handle | |
8233 | explicit extensions correctly. */ | |
8234 | imm_expr.X_op = O_constant; | |
8235 | imm_expr.X_add_number = 0; | |
8236 | imm_reloc = (int) BFD_RELOC_UNUSED + c; | |
8237 | continue; | |
8238 | } | |
8239 | ||
8240 | break; | |
8241 | } | |
8242 | ||
8243 | /* We need to relax this instruction. */ | |
8244 | imm_reloc = (int) BFD_RELOC_UNUSED + c; | |
8245 | s = expr_end; | |
8246 | continue; | |
8247 | ||
8248 | case 'p': | |
8249 | case 'q': | |
8250 | case 'A': | |
8251 | case 'B': | |
8252 | case 'E': | |
8253 | /* We use offset_reloc rather than imm_reloc for the PC | |
8254 | relative operands. This lets macros with both | |
8255 | immediate and address operands work correctly. */ | |
8256 | my_getExpression (&offset_expr, s); | |
8257 | ||
8258 | if (offset_expr.X_op == O_register) | |
8259 | break; | |
8260 | ||
8261 | /* We need to relax this instruction. */ | |
8262 | offset_reloc = (int) BFD_RELOC_UNUSED + c; | |
8263 | s = expr_end; | |
8264 | continue; | |
8265 | ||
8266 | case '6': /* break code */ | |
8267 | my_getExpression (&imm_expr, s); | |
8268 | check_absolute_expr (ip, &imm_expr); | |
8269 | if ((unsigned long) imm_expr.X_add_number > 63) | |
8270 | { | |
8271 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8272 | ip->insn_mo->name, | |
8273 | (unsigned long) imm_expr.X_add_number); | |
8274 | imm_expr.X_add_number &= 0x3f; | |
8275 | } | |
8276 | ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6; | |
8277 | imm_expr.X_op = O_absent; | |
8278 | s = expr_end; | |
8279 | continue; | |
8280 | ||
8281 | case 'a': /* 26 bit address */ | |
8282 | my_getExpression (&offset_expr, s); | |
8283 | s = expr_end; | |
8284 | offset_reloc = BFD_RELOC_MIPS16_JMP; | |
8285 | ip->insn_opcode <<= 16; | |
8286 | continue; | |
8287 | ||
8288 | case 'l': /* register list for entry macro */ | |
8289 | case 'L': /* register list for exit macro */ | |
8290 | { | |
8291 | int mask; | |
8292 | ||
8293 | if (c == 'l') | |
8294 | mask = 0; | |
8295 | else | |
8296 | mask = 7 << 3; | |
8297 | while (*s != '\0') | |
8298 | { | |
8299 | int freg, reg1, reg2; | |
8300 | ||
8301 | while (*s == ' ' || *s == ',') | |
8302 | ++s; | |
8303 | if (*s != '$') | |
8304 | { | |
8305 | as_bad (_("can't parse register list")); | |
8306 | break; | |
8307 | } | |
8308 | ++s; | |
8309 | if (*s != 'f') | |
8310 | freg = 0; | |
8311 | else | |
8312 | { | |
8313 | freg = 1; | |
8314 | ++s; | |
8315 | } | |
8316 | reg1 = 0; | |
d9a62219 | 8317 | while (isdigit ((unsigned char) *s)) |
252b5132 RH |
8318 | { |
8319 | reg1 *= 10; | |
8320 | reg1 += *s - '0'; | |
8321 | ++s; | |
8322 | } | |
8323 | if (*s == ' ') | |
8324 | ++s; | |
8325 | if (*s != '-') | |
8326 | reg2 = reg1; | |
8327 | else | |
8328 | { | |
8329 | ++s; | |
8330 | if (*s != '$') | |
8331 | break; | |
8332 | ++s; | |
8333 | if (freg) | |
8334 | { | |
8335 | if (*s == 'f') | |
8336 | ++s; | |
8337 | else | |
8338 | { | |
8339 | as_bad (_("invalid register list")); | |
8340 | break; | |
8341 | } | |
8342 | } | |
8343 | reg2 = 0; | |
d9a62219 | 8344 | while (isdigit ((unsigned char) *s)) |
252b5132 RH |
8345 | { |
8346 | reg2 *= 10; | |
8347 | reg2 += *s - '0'; | |
8348 | ++s; | |
8349 | } | |
8350 | } | |
8351 | if (freg && reg1 == 0 && reg2 == 0 && c == 'L') | |
8352 | { | |
8353 | mask &= ~ (7 << 3); | |
8354 | mask |= 5 << 3; | |
8355 | } | |
8356 | else if (freg && reg1 == 0 && reg2 == 1 && c == 'L') | |
8357 | { | |
8358 | mask &= ~ (7 << 3); | |
8359 | mask |= 6 << 3; | |
8360 | } | |
8361 | else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L') | |
8362 | mask |= (reg2 - 3) << 3; | |
8363 | else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17) | |
8364 | mask |= (reg2 - 15) << 1; | |
8365 | else if (reg1 == 31 && reg2 == 31) | |
8366 | mask |= 1; | |
8367 | else | |
8368 | { | |
8369 | as_bad (_("invalid register list")); | |
8370 | break; | |
8371 | } | |
8372 | } | |
8373 | /* The mask is filled in in the opcode table for the | |
8374 | benefit of the disassembler. We remove it before | |
8375 | applying the actual mask. */ | |
8376 | ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6); | |
8377 | ip->insn_opcode |= mask << MIPS16OP_SH_IMM6; | |
8378 | } | |
8379 | continue; | |
8380 | ||
8381 | case 'e': /* extend code */ | |
8382 | my_getExpression (&imm_expr, s); | |
8383 | check_absolute_expr (ip, &imm_expr); | |
8384 | if ((unsigned long) imm_expr.X_add_number > 0x7ff) | |
8385 | { | |
8386 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8387 | ip->insn_mo->name, | |
8388 | (unsigned long) imm_expr.X_add_number); | |
8389 | imm_expr.X_add_number &= 0x7ff; | |
8390 | } | |
8391 | ip->insn_opcode |= imm_expr.X_add_number; | |
8392 | imm_expr.X_op = O_absent; | |
8393 | s = expr_end; | |
8394 | continue; | |
8395 | ||
8396 | default: | |
8397 | internalError (); | |
8398 | } | |
8399 | break; | |
8400 | } | |
8401 | ||
8402 | /* Args don't match. */ | |
8403 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] && | |
8404 | strcmp (insn->name, insn[1].name) == 0) | |
8405 | { | |
8406 | ++insn; | |
8407 | s = argsstart; | |
8408 | continue; | |
8409 | } | |
8410 | ||
8411 | insn_error = _("illegal operands"); | |
8412 | ||
8413 | return; | |
8414 | } | |
8415 | } | |
8416 | ||
8417 | /* This structure holds information we know about a mips16 immediate | |
8418 | argument type. */ | |
8419 | ||
8420 | struct mips16_immed_operand | |
8421 | { | |
8422 | /* The type code used in the argument string in the opcode table. */ | |
8423 | int type; | |
8424 | /* The number of bits in the short form of the opcode. */ | |
8425 | int nbits; | |
8426 | /* The number of bits in the extended form of the opcode. */ | |
8427 | int extbits; | |
8428 | /* The amount by which the short form is shifted when it is used; | |
8429 | for example, the sw instruction has a shift count of 2. */ | |
8430 | int shift; | |
8431 | /* The amount by which the short form is shifted when it is stored | |
8432 | into the instruction code. */ | |
8433 | int op_shift; | |
8434 | /* Non-zero if the short form is unsigned. */ | |
8435 | int unsp; | |
8436 | /* Non-zero if the extended form is unsigned. */ | |
8437 | int extu; | |
8438 | /* Non-zero if the value is PC relative. */ | |
8439 | int pcrel; | |
8440 | }; | |
8441 | ||
8442 | /* The mips16 immediate operand types. */ | |
8443 | ||
8444 | static const struct mips16_immed_operand mips16_immed_operands[] = | |
8445 | { | |
8446 | { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
8447 | { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
8448 | { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
8449 | { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
8450 | { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 }, | |
8451 | { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8452 | { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8453 | { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8454 | { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8455 | { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 }, | |
8456 | { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8457 | { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8458 | { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8459 | { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 }, | |
8460 | { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
8461 | { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
8462 | { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
8463 | { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
8464 | { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 }, | |
8465 | { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 }, | |
8466 | { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 } | |
8467 | }; | |
8468 | ||
8469 | #define MIPS16_NUM_IMMED \ | |
8470 | (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0]) | |
8471 | ||
8472 | /* Handle a mips16 instruction with an immediate value. This or's the | |
8473 | small immediate value into *INSN. It sets *USE_EXTEND to indicate | |
8474 | whether an extended value is needed; if one is needed, it sets | |
8475 | *EXTEND to the value. The argument type is TYPE. The value is VAL. | |
8476 | If SMALL is true, an unextended opcode was explicitly requested. | |
8477 | If EXT is true, an extended opcode was explicitly requested. If | |
8478 | WARN is true, warn if EXT does not match reality. */ | |
8479 | ||
8480 | static void | |
8481 | mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend, | |
8482 | extend) | |
8483 | char *file; | |
8484 | unsigned int line; | |
8485 | int type; | |
8486 | offsetT val; | |
8487 | boolean warn; | |
8488 | boolean small; | |
8489 | boolean ext; | |
8490 | unsigned long *insn; | |
8491 | boolean *use_extend; | |
8492 | unsigned short *extend; | |
8493 | { | |
8494 | register const struct mips16_immed_operand *op; | |
8495 | int mintiny, maxtiny; | |
8496 | boolean needext; | |
8497 | ||
8498 | op = mips16_immed_operands; | |
8499 | while (op->type != type) | |
8500 | { | |
8501 | ++op; | |
8502 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
8503 | } | |
8504 | ||
8505 | if (op->unsp) | |
8506 | { | |
8507 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
8508 | { | |
8509 | mintiny = 1; | |
8510 | maxtiny = 1 << op->nbits; | |
8511 | } | |
8512 | else | |
8513 | { | |
8514 | mintiny = 0; | |
8515 | maxtiny = (1 << op->nbits) - 1; | |
8516 | } | |
8517 | } | |
8518 | else | |
8519 | { | |
8520 | mintiny = - (1 << (op->nbits - 1)); | |
8521 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
8522 | } | |
8523 | ||
8524 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
8525 | if (type == 'p' || type == 'q') | |
8526 | val /= 2; | |
8527 | ||
8528 | if ((val & ((1 << op->shift) - 1)) != 0 | |
8529 | || val < (mintiny << op->shift) | |
8530 | || val > (maxtiny << op->shift)) | |
8531 | needext = true; | |
8532 | else | |
8533 | needext = false; | |
8534 | ||
8535 | if (warn && ext && ! needext) | |
8536 | as_warn_where (file, line, _("extended operand requested but not required")); | |
8537 | if (small && needext) | |
8538 | as_bad_where (file, line, _("invalid unextended operand value")); | |
8539 | ||
8540 | if (small || (! ext && ! needext)) | |
8541 | { | |
8542 | int insnval; | |
8543 | ||
8544 | *use_extend = false; | |
8545 | insnval = ((val >> op->shift) & ((1 << op->nbits) - 1)); | |
8546 | insnval <<= op->op_shift; | |
8547 | *insn |= insnval; | |
8548 | } | |
8549 | else | |
8550 | { | |
8551 | long minext, maxext; | |
8552 | int extval; | |
8553 | ||
8554 | if (op->extu) | |
8555 | { | |
8556 | minext = 0; | |
8557 | maxext = (1 << op->extbits) - 1; | |
8558 | } | |
8559 | else | |
8560 | { | |
8561 | minext = - (1 << (op->extbits - 1)); | |
8562 | maxext = (1 << (op->extbits - 1)) - 1; | |
8563 | } | |
8564 | if (val < minext || val > maxext) | |
8565 | as_bad_where (file, line, | |
8566 | _("operand value out of range for instruction")); | |
8567 | ||
8568 | *use_extend = true; | |
8569 | if (op->extbits == 16) | |
8570 | { | |
8571 | extval = ((val >> 11) & 0x1f) | (val & 0x7e0); | |
8572 | val &= 0x1f; | |
8573 | } | |
8574 | else if (op->extbits == 15) | |
8575 | { | |
8576 | extval = ((val >> 11) & 0xf) | (val & 0x7f0); | |
8577 | val &= 0xf; | |
8578 | } | |
8579 | else | |
8580 | { | |
8581 | extval = ((val & 0x1f) << 6) | (val & 0x20); | |
8582 | val = 0; | |
8583 | } | |
8584 | ||
8585 | *extend = (unsigned short) extval; | |
8586 | *insn |= val; | |
8587 | } | |
8588 | } | |
8589 | \f | |
8590 | #define LP '(' | |
8591 | #define RP ')' | |
8592 | ||
8593 | static int | |
8594 | my_getSmallExpression (ep, str) | |
8595 | expressionS *ep; | |
8596 | char *str; | |
8597 | { | |
8598 | char *sp; | |
8599 | int c = 0; | |
8600 | ||
8601 | if (*str == ' ') | |
8602 | str++; | |
8603 | if (*str == LP | |
8604 | || (*str == '%' && | |
8605 | ((str[1] == 'h' && str[2] == 'i') | |
8606 | || (str[1] == 'H' && str[2] == 'I') | |
8607 | || (str[1] == 'l' && str[2] == 'o')) | |
8608 | && str[3] == LP)) | |
8609 | { | |
8610 | if (*str == LP) | |
8611 | c = 0; | |
8612 | else | |
8613 | { | |
8614 | c = str[1]; | |
8615 | str += 3; | |
8616 | } | |
8617 | ||
8618 | /* | |
8619 | * A small expression may be followed by a base register. | |
8620 | * Scan to the end of this operand, and then back over a possible | |
8621 | * base register. Then scan the small expression up to that | |
8622 | * point. (Based on code in sparc.c...) | |
8623 | */ | |
8624 | for (sp = str; *sp && *sp != ','; sp++) | |
8625 | ; | |
8626 | if (sp - 4 >= str && sp[-1] == RP) | |
8627 | { | |
d9a62219 | 8628 | if (isdigit ((unsigned char) sp[-2])) |
252b5132 | 8629 | { |
d9a62219 | 8630 | for (sp -= 3; sp >= str && isdigit ((unsigned char) *sp); sp--) |
252b5132 RH |
8631 | ; |
8632 | if (*sp == '$' && sp > str && sp[-1] == LP) | |
8633 | { | |
8634 | sp--; | |
8635 | goto do_it; | |
8636 | } | |
8637 | } | |
8638 | else if (sp - 5 >= str | |
8639 | && sp[-5] == LP | |
8640 | && sp[-4] == '$' | |
8641 | && ((sp[-3] == 'f' && sp[-2] == 'p') | |
8642 | || (sp[-3] == 's' && sp[-2] == 'p') | |
8643 | || (sp[-3] == 'g' && sp[-2] == 'p') | |
8644 | || (sp[-3] == 'a' && sp[-2] == 't'))) | |
8645 | { | |
8646 | sp -= 5; | |
8647 | do_it: | |
8648 | if (sp == str) | |
8649 | { | |
8650 | /* no expression means zero offset */ | |
8651 | if (c) | |
8652 | { | |
8653 | /* %xx(reg) is an error */ | |
8654 | ep->X_op = O_absent; | |
8655 | expr_end = str - 3; | |
8656 | } | |
8657 | else | |
8658 | { | |
8659 | ep->X_op = O_constant; | |
8660 | expr_end = sp; | |
8661 | } | |
8662 | ep->X_add_symbol = NULL; | |
8663 | ep->X_op_symbol = NULL; | |
8664 | ep->X_add_number = 0; | |
8665 | } | |
8666 | else | |
8667 | { | |
8668 | *sp = '\0'; | |
8669 | my_getExpression (ep, str); | |
8670 | *sp = LP; | |
8671 | } | |
8672 | return c; | |
8673 | } | |
8674 | } | |
8675 | } | |
8676 | my_getExpression (ep, str); | |
8677 | return c; /* => %hi or %lo encountered */ | |
8678 | } | |
8679 | ||
8680 | static void | |
8681 | my_getExpression (ep, str) | |
8682 | expressionS *ep; | |
8683 | char *str; | |
8684 | { | |
8685 | char *save_in; | |
8686 | ||
8687 | save_in = input_line_pointer; | |
8688 | input_line_pointer = str; | |
8689 | expression (ep); | |
8690 | expr_end = input_line_pointer; | |
8691 | input_line_pointer = save_in; | |
8692 | ||
8693 | /* If we are in mips16 mode, and this is an expression based on `.', | |
8694 | then we bump the value of the symbol by 1 since that is how other | |
8695 | text symbols are handled. We don't bother to handle complex | |
8696 | expressions, just `.' plus or minus a constant. */ | |
8697 | if (mips_opts.mips16 | |
8698 | && ep->X_op == O_symbol | |
8699 | && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0 | |
8700 | && S_GET_SEGMENT (ep->X_add_symbol) == now_seg | |
49309057 ILT |
8701 | && symbol_get_frag (ep->X_add_symbol) == frag_now |
8702 | && symbol_constant_p (ep->X_add_symbol) | |
8703 | && S_GET_VALUE (ep->X_add_symbol) == frag_now_fix ()) | |
8704 | S_SET_VALUE (ep->X_add_symbol, S_GET_VALUE (ep->X_add_symbol) + 1); | |
252b5132 RH |
8705 | } |
8706 | ||
8707 | /* Turn a string in input_line_pointer into a floating point constant | |
8708 | of type type, and store the appropriate bytes in *litP. The number | |
8709 | of LITTLENUMS emitted is stored in *sizeP . An error message is | |
8710 | returned, or NULL on OK. */ | |
8711 | ||
8712 | char * | |
8713 | md_atof (type, litP, sizeP) | |
8714 | int type; | |
8715 | char *litP; | |
8716 | int *sizeP; | |
8717 | { | |
8718 | int prec; | |
8719 | LITTLENUM_TYPE words[4]; | |
8720 | char *t; | |
8721 | int i; | |
8722 | ||
8723 | switch (type) | |
8724 | { | |
8725 | case 'f': | |
8726 | prec = 2; | |
8727 | break; | |
8728 | ||
8729 | case 'd': | |
8730 | prec = 4; | |
8731 | break; | |
8732 | ||
8733 | default: | |
8734 | *sizeP = 0; | |
8735 | return _("bad call to md_atof"); | |
8736 | } | |
8737 | ||
8738 | t = atof_ieee (input_line_pointer, type, words); | |
8739 | if (t) | |
8740 | input_line_pointer = t; | |
8741 | ||
8742 | *sizeP = prec * 2; | |
8743 | ||
8744 | if (! target_big_endian) | |
8745 | { | |
8746 | for (i = prec - 1; i >= 0; i--) | |
8747 | { | |
8748 | md_number_to_chars (litP, (valueT) words[i], 2); | |
8749 | litP += 2; | |
8750 | } | |
8751 | } | |
8752 | else | |
8753 | { | |
8754 | for (i = 0; i < prec; i++) | |
8755 | { | |
8756 | md_number_to_chars (litP, (valueT) words[i], 2); | |
8757 | litP += 2; | |
8758 | } | |
8759 | } | |
8760 | ||
8761 | return NULL; | |
8762 | } | |
8763 | ||
8764 | void | |
8765 | md_number_to_chars (buf, val, n) | |
8766 | char *buf; | |
8767 | valueT val; | |
8768 | int n; | |
8769 | { | |
8770 | if (target_big_endian) | |
8771 | number_to_chars_bigendian (buf, val, n); | |
8772 | else | |
8773 | number_to_chars_littleendian (buf, val, n); | |
8774 | } | |
8775 | \f | |
8776 | CONST char *md_shortopts = "O::g::G:"; | |
8777 | ||
8778 | struct option md_longopts[] = { | |
8779 | #define OPTION_MIPS1 (OPTION_MD_BASE + 1) | |
8780 | {"mips0", no_argument, NULL, OPTION_MIPS1}, | |
8781 | {"mips1", no_argument, NULL, OPTION_MIPS1}, | |
8782 | #define OPTION_MIPS2 (OPTION_MD_BASE + 2) | |
8783 | {"mips2", no_argument, NULL, OPTION_MIPS2}, | |
8784 | #define OPTION_MIPS3 (OPTION_MD_BASE + 3) | |
8785 | {"mips3", no_argument, NULL, OPTION_MIPS3}, | |
8786 | #define OPTION_MIPS4 (OPTION_MD_BASE + 4) | |
8787 | {"mips4", no_argument, NULL, OPTION_MIPS4}, | |
8788 | #define OPTION_MCPU (OPTION_MD_BASE + 5) | |
8789 | {"mcpu", required_argument, NULL, OPTION_MCPU}, | |
8790 | #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 6) | |
8791 | {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC}, | |
8792 | #define OPTION_TRAP (OPTION_MD_BASE + 9) | |
8793 | {"trap", no_argument, NULL, OPTION_TRAP}, | |
8794 | {"no-break", no_argument, NULL, OPTION_TRAP}, | |
8795 | #define OPTION_BREAK (OPTION_MD_BASE + 10) | |
8796 | {"break", no_argument, NULL, OPTION_BREAK}, | |
8797 | {"no-trap", no_argument, NULL, OPTION_BREAK}, | |
8798 | #define OPTION_EB (OPTION_MD_BASE + 11) | |
8799 | {"EB", no_argument, NULL, OPTION_EB}, | |
8800 | #define OPTION_EL (OPTION_MD_BASE + 12) | |
8801 | {"EL", no_argument, NULL, OPTION_EL}, | |
8802 | #define OPTION_M4650 (OPTION_MD_BASE + 13) | |
8803 | {"m4650", no_argument, NULL, OPTION_M4650}, | |
8804 | #define OPTION_NO_M4650 (OPTION_MD_BASE + 14) | |
8805 | {"no-m4650", no_argument, NULL, OPTION_NO_M4650}, | |
8806 | #define OPTION_M4010 (OPTION_MD_BASE + 15) | |
8807 | {"m4010", no_argument, NULL, OPTION_M4010}, | |
8808 | #define OPTION_NO_M4010 (OPTION_MD_BASE + 16) | |
8809 | {"no-m4010", no_argument, NULL, OPTION_NO_M4010}, | |
8810 | #define OPTION_M4100 (OPTION_MD_BASE + 17) | |
8811 | {"m4100", no_argument, NULL, OPTION_M4100}, | |
8812 | #define OPTION_NO_M4100 (OPTION_MD_BASE + 18) | |
8813 | {"no-m4100", no_argument, NULL, OPTION_NO_M4100}, | |
8814 | #define OPTION_MIPS16 (OPTION_MD_BASE + 22) | |
8815 | {"mips16", no_argument, NULL, OPTION_MIPS16}, | |
8816 | #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 23) | |
8817 | {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16}, | |
8818 | #define OPTION_M3900 (OPTION_MD_BASE + 26) | |
8819 | {"m3900", no_argument, NULL, OPTION_M3900}, | |
8820 | #define OPTION_NO_M3900 (OPTION_MD_BASE + 27) | |
8821 | {"no-m3900", no_argument, NULL, OPTION_NO_M3900}, | |
8822 | ||
8823 | ||
8824 | #define OPTION_MABI (OPTION_MD_BASE + 38) | |
8825 | {"mabi", required_argument, NULL, OPTION_MABI}, | |
8826 | ||
8827 | #define OPTION_CALL_SHARED (OPTION_MD_BASE + 7) | |
8828 | #define OPTION_NON_SHARED (OPTION_MD_BASE + 8) | |
8829 | #define OPTION_XGOT (OPTION_MD_BASE + 19) | |
8830 | #define OPTION_32 (OPTION_MD_BASE + 20) | |
8831 | #define OPTION_64 (OPTION_MD_BASE + 21) | |
8832 | #ifdef OBJ_ELF | |
8833 | {"KPIC", no_argument, NULL, OPTION_CALL_SHARED}, | |
8834 | {"xgot", no_argument, NULL, OPTION_XGOT}, | |
8835 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, | |
8836 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, | |
8837 | {"32", no_argument, NULL, OPTION_32}, | |
8838 | {"64", no_argument, NULL, OPTION_64}, | |
8839 | #endif | |
8840 | ||
8841 | {NULL, no_argument, NULL, 0} | |
8842 | }; | |
8843 | size_t md_longopts_size = sizeof(md_longopts); | |
8844 | ||
8845 | int | |
8846 | md_parse_option (c, arg) | |
8847 | int c; | |
8848 | char *arg; | |
8849 | { | |
8850 | switch (c) | |
8851 | { | |
8852 | case OPTION_TRAP: | |
8853 | mips_trap = 1; | |
8854 | break; | |
8855 | ||
8856 | case OPTION_BREAK: | |
8857 | mips_trap = 0; | |
8858 | break; | |
8859 | ||
8860 | case OPTION_EB: | |
8861 | target_big_endian = 1; | |
8862 | break; | |
8863 | ||
8864 | case OPTION_EL: | |
8865 | target_big_endian = 0; | |
8866 | break; | |
8867 | ||
8868 | case 'O': | |
8869 | if (arg && arg[1] == '0') | |
8870 | mips_optimize = 1; | |
8871 | else | |
8872 | mips_optimize = 2; | |
8873 | break; | |
8874 | ||
8875 | case 'g': | |
8876 | if (arg == NULL) | |
8877 | mips_debug = 2; | |
8878 | else | |
8879 | mips_debug = atoi (arg); | |
8880 | /* When the MIPS assembler sees -g or -g2, it does not do | |
8881 | optimizations which limit full symbolic debugging. We take | |
8882 | that to be equivalent to -O0. */ | |
8883 | if (mips_debug == 2) | |
8884 | mips_optimize = 1; | |
8885 | break; | |
8886 | ||
8887 | case OPTION_MIPS1: | |
8888 | mips_opts.isa = 1; | |
8889 | break; | |
8890 | ||
8891 | case OPTION_MIPS2: | |
8892 | mips_opts.isa = 2; | |
8893 | break; | |
8894 | ||
8895 | case OPTION_MIPS3: | |
8896 | mips_opts.isa = 3; | |
8897 | break; | |
8898 | ||
8899 | case OPTION_MIPS4: | |
8900 | mips_opts.isa = 4; | |
8901 | break; | |
8902 | ||
8903 | case OPTION_MCPU: | |
8904 | { | |
8905 | char *p; | |
8906 | ||
8907 | /* Identify the processor type */ | |
8908 | p = arg; | |
8909 | if (strcmp (p, "default") == 0 | |
8910 | || strcmp (p, "DEFAULT") == 0) | |
8911 | mips_cpu = -1; | |
8912 | else | |
8913 | { | |
8914 | int sv = 0; | |
8915 | ||
8916 | /* We need to cope with the various "vr" prefixes for the 4300 | |
8917 | processor. */ | |
8918 | if (*p == 'v' || *p == 'V') | |
8919 | { | |
8920 | sv = 1; | |
8921 | p++; | |
8922 | } | |
8923 | ||
8924 | if (*p == 'r' || *p == 'R') | |
8925 | p++; | |
8926 | ||
8927 | mips_cpu = -1; | |
8928 | switch (*p) | |
8929 | { | |
8930 | case '1': | |
8931 | if (strcmp (p, "10000") == 0 | |
8932 | || strcmp (p, "10k") == 0 | |
8933 | || strcmp (p, "10K") == 0) | |
8934 | mips_cpu = 10000; | |
8935 | break; | |
8936 | ||
8937 | case '2': | |
8938 | if (strcmp (p, "2000") == 0 | |
8939 | || strcmp (p, "2k") == 0 | |
8940 | || strcmp (p, "2K") == 0) | |
8941 | mips_cpu = 2000; | |
8942 | break; | |
8943 | ||
8944 | case '3': | |
8945 | if (strcmp (p, "3000") == 0 | |
8946 | || strcmp (p, "3k") == 0 | |
8947 | || strcmp (p, "3K") == 0) | |
8948 | mips_cpu = 3000; | |
8949 | else if (strcmp (p, "3900") == 0) | |
8950 | mips_cpu = 3900; | |
8951 | break; | |
8952 | ||
8953 | case '4': | |
8954 | if (strcmp (p, "4000") == 0 | |
8955 | || strcmp (p, "4k") == 0 | |
8956 | || strcmp (p, "4K") == 0) | |
8957 | mips_cpu = 4000; | |
8958 | else if (strcmp (p, "4100") == 0) | |
8959 | mips_cpu = 4100; | |
8960 | else if (strcmp (p, "4111") == 0) | |
8961 | mips_cpu = 4111; | |
8962 | else if (strcmp (p, "4300") == 0) | |
8963 | mips_cpu = 4300; | |
8964 | else if (strcmp (p, "4400") == 0) | |
8965 | mips_cpu = 4400; | |
8966 | else if (strcmp (p, "4600") == 0) | |
8967 | mips_cpu = 4600; | |
8968 | else if (strcmp (p, "4650") == 0) | |
8969 | mips_cpu = 4650; | |
8970 | else if (strcmp (p, "4010") == 0) | |
8971 | mips_cpu = 4010; | |
8972 | break; | |
8973 | ||
8974 | case '5': | |
8975 | if (strcmp (p, "5000") == 0 | |
8976 | || strcmp (p, "5k") == 0 | |
8977 | || strcmp (p, "5K") == 0) | |
8978 | mips_cpu = 5000; | |
8979 | break; | |
8980 | ||
8981 | case '6': | |
8982 | if (strcmp (p, "6000") == 0 | |
8983 | || strcmp (p, "6k") == 0 | |
8984 | || strcmp (p, "6K") == 0) | |
8985 | mips_cpu = 6000; | |
8986 | break; | |
8987 | ||
8988 | case '8': | |
8989 | if (strcmp (p, "8000") == 0 | |
8990 | || strcmp (p, "8k") == 0 | |
8991 | || strcmp (p, "8K") == 0) | |
8992 | mips_cpu = 8000; | |
8993 | break; | |
8994 | ||
8995 | case 'o': | |
8996 | if (strcmp (p, "orion") == 0) | |
8997 | mips_cpu = 4600; | |
8998 | break; | |
8999 | } | |
9000 | ||
9001 | if (sv | |
9002 | && (mips_cpu != 4300 | |
9003 | && mips_cpu != 4100 | |
9004 | && mips_cpu != 4111 | |
9005 | && mips_cpu != 5000)) | |
9006 | { | |
9007 | as_bad (_("ignoring invalid leading 'v' in -mcpu=%s switch"), arg); | |
9008 | return 0; | |
9009 | } | |
9010 | ||
9011 | if (mips_cpu == -1) | |
9012 | { | |
9013 | as_bad (_("invalid architecture -mcpu=%s"), arg); | |
9014 | return 0; | |
9015 | } | |
9016 | } | |
9017 | } | |
9018 | break; | |
9019 | ||
9020 | case OPTION_M4650: | |
9021 | mips_cpu = 4650; | |
9022 | break; | |
9023 | ||
9024 | case OPTION_NO_M4650: | |
9025 | break; | |
9026 | ||
9027 | case OPTION_M4010: | |
9028 | mips_cpu = 4010; | |
9029 | break; | |
9030 | ||
9031 | case OPTION_NO_M4010: | |
9032 | break; | |
9033 | ||
9034 | case OPTION_M4100: | |
9035 | mips_cpu = 4100; | |
9036 | break; | |
9037 | ||
9038 | case OPTION_NO_M4100: | |
9039 | break; | |
9040 | ||
9041 | ||
9042 | case OPTION_M3900: | |
9043 | mips_cpu = 3900; | |
9044 | break; | |
9045 | ||
9046 | case OPTION_NO_M3900: | |
9047 | break; | |
9048 | ||
9049 | case OPTION_MIPS16: | |
9050 | mips_opts.mips16 = 1; | |
9051 | mips_no_prev_insn (false); | |
9052 | break; | |
9053 | ||
9054 | case OPTION_NO_MIPS16: | |
9055 | mips_opts.mips16 = 0; | |
9056 | mips_no_prev_insn (false); | |
9057 | break; | |
9058 | ||
9059 | case OPTION_MEMBEDDED_PIC: | |
9060 | mips_pic = EMBEDDED_PIC; | |
9061 | if (USE_GLOBAL_POINTER_OPT && g_switch_seen) | |
9062 | { | |
9063 | as_bad (_("-G may not be used with embedded PIC code")); | |
9064 | return 0; | |
9065 | } | |
9066 | g_switch_value = 0x7fffffff; | |
9067 | break; | |
9068 | ||
9069 | /* When generating ELF code, we permit -KPIC and -call_shared to | |
9070 | select SVR4_PIC, and -non_shared to select no PIC. This is | |
9071 | intended to be compatible with Irix 5. */ | |
9072 | case OPTION_CALL_SHARED: | |
9073 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9074 | { | |
9075 | as_bad (_("-call_shared is supported only for ELF format")); | |
9076 | return 0; | |
9077 | } | |
9078 | mips_pic = SVR4_PIC; | |
9079 | if (g_switch_seen && g_switch_value != 0) | |
9080 | { | |
9081 | as_bad (_("-G may not be used with SVR4 PIC code")); | |
9082 | return 0; | |
9083 | } | |
9084 | g_switch_value = 0; | |
9085 | break; | |
9086 | ||
9087 | case OPTION_NON_SHARED: | |
9088 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9089 | { | |
9090 | as_bad (_("-non_shared is supported only for ELF format")); | |
9091 | return 0; | |
9092 | } | |
9093 | mips_pic = NO_PIC; | |
9094 | break; | |
9095 | ||
9096 | /* The -xgot option tells the assembler to use 32 offsets when | |
9097 | accessing the got in SVR4_PIC mode. It is for Irix | |
9098 | compatibility. */ | |
9099 | case OPTION_XGOT: | |
9100 | mips_big_got = 1; | |
9101 | break; | |
9102 | ||
9103 | case 'G': | |
9104 | if (! USE_GLOBAL_POINTER_OPT) | |
9105 | { | |
9106 | as_bad (_("-G is not supported for this configuration")); | |
9107 | return 0; | |
9108 | } | |
9109 | else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC) | |
9110 | { | |
9111 | as_bad (_("-G may not be used with SVR4 or embedded PIC code")); | |
9112 | return 0; | |
9113 | } | |
9114 | else | |
9115 | g_switch_value = atoi (arg); | |
9116 | g_switch_seen = 1; | |
9117 | break; | |
9118 | ||
9119 | /* The -32 and -64 options tell the assembler to output the 32 | |
9120 | bit or the 64 bit MIPS ELF format. */ | |
9121 | case OPTION_32: | |
9122 | mips_64 = 0; | |
9123 | break; | |
9124 | ||
9125 | case OPTION_64: | |
9126 | { | |
9127 | const char **list, **l; | |
9128 | ||
9129 | list = bfd_target_list (); | |
9130 | for (l = list; *l != NULL; l++) | |
9131 | if (strcmp (*l, "elf64-bigmips") == 0 | |
9132 | || strcmp (*l, "elf64-littlemips") == 0) | |
9133 | break; | |
9134 | if (*l == NULL) | |
9135 | as_fatal (_("No compiled in support for 64 bit object file format")); | |
9136 | free (list); | |
9137 | mips_64 = 1; | |
9138 | } | |
9139 | break; | |
9140 | ||
9141 | ||
9142 | case OPTION_MABI: | |
9143 | if (strcmp (arg,"32") == 0 | |
9144 | || strcmp (arg,"n32") == 0 | |
9145 | || strcmp (arg,"64") == 0 | |
9146 | || strcmp (arg,"o64") == 0 | |
9147 | || strcmp (arg,"eabi") == 0) | |
9148 | mips_abi_string = arg; | |
9149 | break; | |
9150 | ||
9151 | default: | |
9152 | return 0; | |
9153 | } | |
9154 | ||
9155 | return 1; | |
9156 | } | |
9157 | ||
9158 | ||
9159 | static void | |
9160 | show (stream, string, col_p, first_p) | |
9161 | FILE *stream; | |
9162 | char *string; | |
9163 | int *col_p; | |
9164 | int *first_p; | |
9165 | { | |
9166 | if (*first_p) | |
9167 | { | |
9168 | fprintf (stream, "%24s", ""); | |
9169 | *col_p = 24; | |
9170 | } | |
9171 | else | |
9172 | { | |
9173 | fprintf (stream, ", "); | |
9174 | *col_p += 2; | |
9175 | } | |
9176 | ||
9177 | if (*col_p + strlen (string) > 72) | |
9178 | { | |
9179 | fprintf (stream, "\n%24s", ""); | |
9180 | *col_p = 24; | |
9181 | } | |
9182 | ||
9183 | fprintf (stream, "%s", string); | |
9184 | *col_p += strlen (string); | |
9185 | ||
9186 | *first_p = 0; | |
9187 | } | |
9188 | ||
9189 | ||
9190 | void | |
9191 | md_show_usage (stream) | |
9192 | FILE *stream; | |
9193 | { | |
9194 | int column, first; | |
9195 | ||
9196 | fprintf(stream, _("\ | |
9197 | MIPS options:\n\ | |
9198 | -membedded-pic generate embedded position independent code\n\ | |
9199 | -EB generate big endian output\n\ | |
9200 | -EL generate little endian output\n\ | |
9201 | -g, -g2 do not remove uneeded NOPs or swap branches\n\ | |
9202 | -G NUM allow referencing objects up to NUM bytes\n\ | |
9203 | implicitly with the gp register [default 8]\n")); | |
9204 | fprintf(stream, _("\ | |
9205 | -mips1 generate MIPS ISA I instructions\n\ | |
9206 | -mips2 generate MIPS ISA II instructions\n\ | |
9207 | -mips3 generate MIPS ISA III instructions\n\ | |
9208 | -mips4 generate MIPS ISA IV instructions\n\ | |
9209 | -mcpu=CPU generate code for CPU, where CPU is one of:\n")); | |
9210 | ||
9211 | first = 1; | |
9212 | ||
9213 | show (stream, "2000", &column, &first); | |
9214 | show (stream, "3000", &column, &first); | |
9215 | show (stream, "3900", &column, &first); | |
9216 | show (stream, "4000", &column, &first); | |
9217 | show (stream, "4010", &column, &first); | |
9218 | show (stream, "4100", &column, &first); | |
9219 | show (stream, "4111", &column, &first); | |
9220 | show (stream, "4300", &column, &first); | |
9221 | show (stream, "4400", &column, &first); | |
9222 | show (stream, "4600", &column, &first); | |
9223 | show (stream, "4650", &column, &first); | |
9224 | show (stream, "5000", &column, &first); | |
9225 | show (stream, "6000", &column, &first); | |
9226 | show (stream, "8000", &column, &first); | |
9227 | show (stream, "10000", &column, &first); | |
9228 | fputc ('\n', stream); | |
9229 | ||
9230 | fprintf (stream, _("\ | |
9231 | -mCPU equivalent to -mcpu=CPU.\n\ | |
9232 | -no-mCPU don't generate code specific to CPU.\n\ | |
9233 | For -mCPU and -no-mCPU, CPU must be one of:\n")); | |
9234 | ||
9235 | first = 1; | |
9236 | ||
9237 | show (stream, "3900", &column, &first); | |
9238 | show (stream, "4010", &column, &first); | |
9239 | show (stream, "4100", &column, &first); | |
9240 | show (stream, "4650", &column, &first); | |
9241 | fputc ('\n', stream); | |
9242 | ||
9243 | fprintf(stream, _("\ | |
9244 | -mips16 generate mips16 instructions\n\ | |
9245 | -no-mips16 do not generate mips16 instructions\n")); | |
9246 | fprintf(stream, _("\ | |
9247 | -O0 remove unneeded NOPs, do not swap branches\n\ | |
9248 | -O remove unneeded NOPs and swap branches\n\ | |
9249 | --trap, --no-break trap exception on div by 0 and mult overflow\n\ | |
9250 | --break, --no-trap break exception on div by 0 and mult overflow\n")); | |
9251 | #ifdef OBJ_ELF | |
9252 | fprintf(stream, _("\ | |
9253 | -KPIC, -call_shared generate SVR4 position independent code\n\ | |
9254 | -non_shared do not generate position independent code\n\ | |
9255 | -xgot assume a 32 bit GOT\n\ | |
9256 | -32 create 32 bit object file (default)\n\ | |
9257 | -64 create 64 bit object file\n")); | |
9258 | #endif | |
9259 | } | |
9260 | \f | |
9261 | void | |
9262 | mips_init_after_args () | |
9263 | { | |
9264 | /* initialize opcodes */ | |
9265 | bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes; | |
9266 | mips_opcodes = (struct mips_opcode*) mips_builtin_opcodes; | |
9267 | } | |
9268 | ||
9269 | long | |
9270 | md_pcrel_from (fixP) | |
9271 | fixS *fixP; | |
9272 | { | |
9273 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour | |
9274 | && fixP->fx_addsy != (symbolS *) NULL | |
9275 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
9276 | { | |
9277 | /* This makes a branch to an undefined symbol be a branch to the | |
9278 | current location. */ | |
9279 | return 4; | |
9280 | } | |
9281 | ||
9282 | /* return the address of the delay slot */ | |
9283 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; | |
9284 | } | |
9285 | ||
9286 | /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a | |
9287 | reloc for a cons. We could use the definition there, except that | |
9288 | we want to handle 64 bit relocs specially. */ | |
9289 | ||
9290 | void | |
9291 | cons_fix_new_mips (frag, where, nbytes, exp) | |
9292 | fragS *frag; | |
9293 | int where; | |
9294 | unsigned int nbytes; | |
9295 | expressionS *exp; | |
9296 | { | |
9297 | #ifndef OBJ_ELF | |
9298 | /* If we are assembling in 32 bit mode, turn an 8 byte reloc into a | |
9299 | 4 byte reloc. */ | |
9300 | if (nbytes == 8 && ! mips_64) | |
9301 | { | |
9302 | if (target_big_endian) | |
9303 | where += 4; | |
9304 | nbytes = 4; | |
9305 | } | |
9306 | #endif | |
9307 | ||
9308 | if (nbytes != 2 && nbytes != 4 && nbytes != 8) | |
9309 | as_bad (_("Unsupported reloc size %d"), nbytes); | |
9310 | ||
9311 | fix_new_exp (frag_now, where, (int) nbytes, exp, 0, | |
9312 | (nbytes == 2 | |
9313 | ? BFD_RELOC_16 | |
9314 | : (nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64))); | |
9315 | } | |
9316 | ||
9317 | /* This is called before the symbol table is processed. In order to | |
9318 | work with gcc when using mips-tfile, we must keep all local labels. | |
9319 | However, in other cases, we want to discard them. If we were | |
9320 | called with -g, but we didn't see any debugging information, it may | |
9321 | mean that gcc is smuggling debugging information through to | |
9322 | mips-tfile, in which case we must generate all local labels. */ | |
9323 | ||
9324 | void | |
9325 | mips_frob_file_before_adjust () | |
9326 | { | |
9327 | #ifndef NO_ECOFF_DEBUGGING | |
9328 | if (ECOFF_DEBUGGING | |
9329 | && mips_debug != 0 | |
9330 | && ! ecoff_debugging_seen) | |
9331 | flag_keep_locals = 1; | |
9332 | #endif | |
9333 | } | |
9334 | ||
9335 | /* Sort any unmatched HI16_S relocs so that they immediately precede | |
9336 | the corresponding LO reloc. This is called before md_apply_fix and | |
9337 | tc_gen_reloc. Unmatched HI16_S relocs can only be generated by | |
9338 | explicit use of the %hi modifier. */ | |
9339 | ||
9340 | void | |
9341 | mips_frob_file () | |
9342 | { | |
9343 | struct mips_hi_fixup *l; | |
9344 | ||
9345 | for (l = mips_hi_fixup_list; l != NULL; l = l->next) | |
9346 | { | |
9347 | segment_info_type *seginfo; | |
9348 | int pass; | |
9349 | ||
9350 | assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S); | |
9351 | ||
9352 | /* Check quickly whether the next fixup happens to be a matching | |
9353 | %lo. */ | |
9354 | if (l->fixp->fx_next != NULL | |
9355 | && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16 | |
9356 | && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy | |
9357 | && l->fixp->fx_offset == l->fixp->fx_next->fx_offset) | |
9358 | continue; | |
9359 | ||
9360 | /* Look through the fixups for this segment for a matching %lo. | |
9361 | When we find one, move the %hi just in front of it. We do | |
9362 | this in two passes. In the first pass, we try to find a | |
9363 | unique %lo. In the second pass, we permit multiple %hi | |
9364 | relocs for a single %lo (this is a GNU extension). */ | |
9365 | seginfo = seg_info (l->seg); | |
9366 | for (pass = 0; pass < 2; pass++) | |
9367 | { | |
9368 | fixS *f, *prev; | |
9369 | ||
9370 | prev = NULL; | |
9371 | for (f = seginfo->fix_root; f != NULL; f = f->fx_next) | |
9372 | { | |
9373 | /* Check whether this is a %lo fixup which matches l->fixp. */ | |
9374 | if (f->fx_r_type == BFD_RELOC_LO16 | |
9375 | && f->fx_addsy == l->fixp->fx_addsy | |
9376 | && f->fx_offset == l->fixp->fx_offset | |
9377 | && (pass == 1 | |
9378 | || prev == NULL | |
9379 | || prev->fx_r_type != BFD_RELOC_HI16_S | |
9380 | || prev->fx_addsy != f->fx_addsy | |
9381 | || prev->fx_offset != f->fx_offset)) | |
9382 | { | |
9383 | fixS **pf; | |
9384 | ||
9385 | /* Move l->fixp before f. */ | |
9386 | for (pf = &seginfo->fix_root; | |
9387 | *pf != l->fixp; | |
9388 | pf = &(*pf)->fx_next) | |
9389 | assert (*pf != NULL); | |
9390 | ||
9391 | *pf = l->fixp->fx_next; | |
9392 | ||
9393 | l->fixp->fx_next = f; | |
9394 | if (prev == NULL) | |
9395 | seginfo->fix_root = l->fixp; | |
9396 | else | |
9397 | prev->fx_next = l->fixp; | |
9398 | ||
9399 | break; | |
9400 | } | |
9401 | ||
9402 | prev = f; | |
9403 | } | |
9404 | ||
9405 | if (f != NULL) | |
9406 | break; | |
9407 | ||
9408 | #if 0 /* GCC code motion plus incomplete dead code elimination | |
9409 | can leave a %hi without a %lo. */ | |
9410 | if (pass == 1) | |
9411 | as_warn_where (l->fixp->fx_file, l->fixp->fx_line, | |
9412 | _("Unmatched %%hi reloc")); | |
9413 | #endif | |
9414 | } | |
9415 | } | |
9416 | } | |
9417 | ||
9418 | /* When generating embedded PIC code we need to use a special | |
9419 | relocation to represent the difference of two symbols in the .text | |
9420 | section (switch tables use a difference of this sort). See | |
9421 | include/coff/mips.h for details. This macro checks whether this | |
9422 | fixup requires the special reloc. */ | |
9423 | #define SWITCH_TABLE(fixp) \ | |
9424 | ((fixp)->fx_r_type == BFD_RELOC_32 \ | |
9425 | && (fixp)->fx_addsy != NULL \ | |
9426 | && (fixp)->fx_subsy != NULL \ | |
9427 | && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \ | |
9428 | && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section) | |
9429 | ||
9430 | /* When generating embedded PIC code we must keep all PC relative | |
9431 | relocations, in case the linker has to relax a call. We also need | |
9432 | to keep relocations for switch table entries. */ | |
9433 | ||
9434 | /*ARGSUSED*/ | |
9435 | int | |
9436 | mips_force_relocation (fixp) | |
9437 | fixS *fixp; | |
9438 | { | |
9439 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
9440 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
9441 | return 1; | |
9442 | ||
9443 | return (mips_pic == EMBEDDED_PIC | |
9444 | && (fixp->fx_pcrel | |
9445 | || SWITCH_TABLE (fixp) | |
9446 | || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S | |
9447 | || fixp->fx_r_type == BFD_RELOC_PCREL_LO16)); | |
9448 | } | |
9449 | ||
9450 | /* Apply a fixup to the object file. */ | |
9451 | ||
9452 | int | |
9453 | md_apply_fix (fixP, valueP) | |
9454 | fixS *fixP; | |
9455 | valueT *valueP; | |
9456 | { | |
9457 | unsigned char *buf; | |
9458 | long insn, value; | |
9459 | ||
9460 | assert (fixP->fx_size == 4 | |
9461 | || fixP->fx_r_type == BFD_RELOC_16 | |
9462 | || fixP->fx_r_type == BFD_RELOC_64 | |
9463 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
9464 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY); | |
9465 | ||
9466 | value = *valueP; | |
9467 | ||
9468 | /* If we aren't adjusting this fixup to be against the section | |
9469 | symbol, we need to adjust the value. */ | |
9470 | #ifdef OBJ_ELF | |
9471 | if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
9472 | if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16 | |
9473 | || S_IS_WEAK (fixP->fx_addsy) | |
49309057 ILT |
9474 | || (symbol_used_in_reloc_p (fixP->fx_addsy) |
9475 | && (((bfd_get_section_flags (stdoutput, | |
9476 | S_GET_SEGMENT (fixP->fx_addsy)) | |
9477 | & SEC_LINK_ONCE) != 0) | |
9478 | || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)), | |
9479 | ".gnu.linkonce", | |
9480 | sizeof (".gnu.linkonce") - 1)))) | |
252b5132 RH |
9481 | |
9482 | { | |
9483 | value -= S_GET_VALUE (fixP->fx_addsy); | |
9484 | if (value != 0 && ! fixP->fx_pcrel) | |
9485 | { | |
9486 | /* In this case, the bfd_install_relocation routine will | |
9487 | incorrectly add the symbol value back in. We just want | |
9488 | the addend to appear in the object file. */ | |
9489 | value -= S_GET_VALUE (fixP->fx_addsy); | |
9490 | } | |
9491 | } | |
9492 | #endif | |
9493 | ||
9494 | ||
9495 | fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */ | |
9496 | ||
9497 | if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel) | |
9498 | fixP->fx_done = 1; | |
9499 | ||
9500 | switch (fixP->fx_r_type) | |
9501 | { | |
9502 | case BFD_RELOC_MIPS_JMP: | |
9503 | case BFD_RELOC_HI16: | |
9504 | case BFD_RELOC_HI16_S: | |
9505 | case BFD_RELOC_MIPS_GPREL: | |
9506 | case BFD_RELOC_MIPS_LITERAL: | |
9507 | case BFD_RELOC_MIPS_CALL16: | |
9508 | case BFD_RELOC_MIPS_GOT16: | |
9509 | case BFD_RELOC_MIPS_GPREL32: | |
9510 | case BFD_RELOC_MIPS_GOT_HI16: | |
9511 | case BFD_RELOC_MIPS_GOT_LO16: | |
9512 | case BFD_RELOC_MIPS_CALL_HI16: | |
9513 | case BFD_RELOC_MIPS_CALL_LO16: | |
9514 | case BFD_RELOC_MIPS16_GPREL: | |
9515 | if (fixP->fx_pcrel) | |
9516 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9517 | _("Invalid PC relative reloc")); | |
9518 | /* Nothing needed to do. The value comes from the reloc entry */ | |
9519 | break; | |
9520 | ||
9521 | case BFD_RELOC_MIPS16_JMP: | |
9522 | /* We currently always generate a reloc against a symbol, which | |
9523 | means that we don't want an addend even if the symbol is | |
9524 | defined. */ | |
9525 | fixP->fx_addnumber = 0; | |
9526 | break; | |
9527 | ||
9528 | case BFD_RELOC_PCREL_HI16_S: | |
9529 | /* The addend for this is tricky if it is internal, so we just | |
9530 | do everything here rather than in bfd_install_relocation. */ | |
49309057 | 9531 | if ((symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) |
252b5132 RH |
9532 | { |
9533 | /* For an external symbol adjust by the address to make it | |
9534 | pcrel_offset. We use the address of the RELLO reloc | |
9535 | which follows this one. */ | |
9536 | value += (fixP->fx_next->fx_frag->fr_address | |
9537 | + fixP->fx_next->fx_where); | |
9538 | } | |
9539 | if (value & 0x8000) | |
9540 | value += 0x10000; | |
9541 | value >>= 16; | |
9542 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
9543 | if (target_big_endian) | |
9544 | buf += 2; | |
9545 | md_number_to_chars (buf, value, 2); | |
9546 | break; | |
9547 | ||
9548 | case BFD_RELOC_PCREL_LO16: | |
9549 | /* The addend for this is tricky if it is internal, so we just | |
9550 | do everything here rather than in bfd_install_relocation. */ | |
49309057 | 9551 | if ((symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) |
252b5132 RH |
9552 | value += fixP->fx_frag->fr_address + fixP->fx_where; |
9553 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
9554 | if (target_big_endian) | |
9555 | buf += 2; | |
9556 | md_number_to_chars (buf, value, 2); | |
9557 | break; | |
9558 | ||
9559 | case BFD_RELOC_64: | |
9560 | /* This is handled like BFD_RELOC_32, but we output a sign | |
9561 | extended value if we are only 32 bits. */ | |
9562 | if (fixP->fx_done | |
9563 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
9564 | { | |
9565 | if (8 <= sizeof (valueT)) | |
9566 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9567 | value, 8); | |
9568 | else | |
9569 | { | |
9570 | long w1, w2; | |
9571 | long hiv; | |
9572 | ||
9573 | w1 = w2 = fixP->fx_where; | |
9574 | if (target_big_endian) | |
9575 | w1 += 4; | |
9576 | else | |
9577 | w2 += 4; | |
9578 | md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4); | |
9579 | if ((value & 0x80000000) != 0) | |
9580 | hiv = 0xffffffff; | |
9581 | else | |
9582 | hiv = 0; | |
9583 | md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4); | |
9584 | } | |
9585 | } | |
9586 | break; | |
9587 | ||
9588 | case BFD_RELOC_32: | |
9589 | /* If we are deleting this reloc entry, we must fill in the | |
9590 | value now. This can happen if we have a .word which is not | |
9591 | resolved when it appears but is later defined. We also need | |
9592 | to fill in the value if this is an embedded PIC switch table | |
9593 | entry. */ | |
9594 | if (fixP->fx_done | |
9595 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
9596 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9597 | value, 4); | |
9598 | break; | |
9599 | ||
9600 | case BFD_RELOC_16: | |
9601 | /* If we are deleting this reloc entry, we must fill in the | |
9602 | value now. */ | |
9603 | assert (fixP->fx_size == 2); | |
9604 | if (fixP->fx_done) | |
9605 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9606 | value, 2); | |
9607 | break; | |
9608 | ||
9609 | case BFD_RELOC_LO16: | |
9610 | /* When handling an embedded PIC switch statement, we can wind | |
9611 | up deleting a LO16 reloc. See the 'o' case in mips_ip. */ | |
9612 | if (fixP->fx_done) | |
9613 | { | |
9614 | if (value < -0x8000 || value > 0x7fff) | |
9615 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9616 | _("relocation overflow")); | |
9617 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
9618 | if (target_big_endian) | |
9619 | buf += 2; | |
9620 | md_number_to_chars (buf, value, 2); | |
9621 | } | |
9622 | break; | |
9623 | ||
9624 | case BFD_RELOC_16_PCREL_S2: | |
9625 | /* | |
9626 | * We need to save the bits in the instruction since fixup_segment() | |
9627 | * might be deleting the relocation entry (i.e., a branch within | |
9628 | * the current segment). | |
9629 | */ | |
9630 | if ((value & 0x3) != 0) | |
9631 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9632 | _("Branch to odd address (%lx)"), value); | |
9633 | value >>= 2; | |
9634 | ||
9635 | /* update old instruction data */ | |
9636 | buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal); | |
9637 | if (target_big_endian) | |
9638 | insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
9639 | else | |
9640 | insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | |
9641 | ||
9642 | if (value >= -0x8000 && value < 0x8000) | |
9643 | insn |= value & 0xffff; | |
9644 | else | |
9645 | { | |
9646 | /* The branch offset is too large. If this is an | |
9647 | unconditional branch, and we are not generating PIC code, | |
9648 | we can convert it to an absolute jump instruction. */ | |
9649 | if (mips_pic == NO_PIC | |
9650 | && fixP->fx_done | |
9651 | && fixP->fx_frag->fr_address >= text_section->vma | |
9652 | && (fixP->fx_frag->fr_address | |
9653 | < text_section->vma + text_section->_raw_size) | |
9654 | && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */ | |
9655 | || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */ | |
9656 | || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */ | |
9657 | { | |
9658 | if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */ | |
9659 | insn = 0x0c000000; /* jal */ | |
9660 | else | |
9661 | insn = 0x08000000; /* j */ | |
9662 | fixP->fx_r_type = BFD_RELOC_MIPS_JMP; | |
9663 | fixP->fx_done = 0; | |
9664 | fixP->fx_addsy = section_symbol (text_section); | |
9665 | fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP); | |
9666 | } | |
9667 | else | |
9668 | { | |
9669 | /* FIXME. It would be possible in principle to handle | |
9670 | conditional branches which overflow. They could be | |
9671 | transformed into a branch around a jump. This would | |
9672 | require setting up variant frags for each different | |
9673 | branch type. The native MIPS assembler attempts to | |
9674 | handle these cases, but it appears to do it | |
9675 | incorrectly. */ | |
9676 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9677 | _("Branch out of range")); | |
9678 | } | |
9679 | } | |
9680 | ||
9681 | md_number_to_chars ((char *) buf, (valueT) insn, 4); | |
9682 | break; | |
9683 | ||
9684 | case BFD_RELOC_VTABLE_INHERIT: | |
9685 | fixP->fx_done = 0; | |
9686 | if (fixP->fx_addsy | |
9687 | && !S_IS_DEFINED (fixP->fx_addsy) | |
9688 | && !S_IS_WEAK (fixP->fx_addsy)) | |
9689 | S_SET_WEAK (fixP->fx_addsy); | |
9690 | break; | |
9691 | ||
9692 | case BFD_RELOC_VTABLE_ENTRY: | |
9693 | fixP->fx_done = 0; | |
9694 | break; | |
9695 | ||
9696 | default: | |
9697 | internalError (); | |
9698 | } | |
9699 | ||
9700 | return 1; | |
9701 | } | |
9702 | ||
9703 | #if 0 | |
9704 | void | |
9705 | printInsn (oc) | |
9706 | unsigned long oc; | |
9707 | { | |
9708 | const struct mips_opcode *p; | |
9709 | int treg, sreg, dreg, shamt; | |
9710 | short imm; | |
9711 | const char *args; | |
9712 | int i; | |
9713 | ||
9714 | for (i = 0; i < NUMOPCODES; ++i) | |
9715 | { | |
9716 | p = &mips_opcodes[i]; | |
9717 | if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO)) | |
9718 | { | |
9719 | printf ("%08lx %s\t", oc, p->name); | |
9720 | treg = (oc >> 16) & 0x1f; | |
9721 | sreg = (oc >> 21) & 0x1f; | |
9722 | dreg = (oc >> 11) & 0x1f; | |
9723 | shamt = (oc >> 6) & 0x1f; | |
9724 | imm = oc; | |
9725 | for (args = p->args;; ++args) | |
9726 | { | |
9727 | switch (*args) | |
9728 | { | |
9729 | case '\0': | |
9730 | printf ("\n"); | |
9731 | break; | |
9732 | ||
9733 | case ',': | |
9734 | case '(': | |
9735 | case ')': | |
9736 | printf ("%c", *args); | |
9737 | continue; | |
9738 | ||
9739 | case 'r': | |
9740 | assert (treg == sreg); | |
9741 | printf ("$%d,$%d", treg, sreg); | |
9742 | continue; | |
9743 | ||
9744 | case 'd': | |
9745 | case 'G': | |
9746 | printf ("$%d", dreg); | |
9747 | continue; | |
9748 | ||
9749 | case 't': | |
9750 | case 'E': | |
9751 | printf ("$%d", treg); | |
9752 | continue; | |
9753 | ||
9754 | case 'k': | |
9755 | printf ("0x%x", treg); | |
9756 | continue; | |
9757 | ||
9758 | case 'b': | |
9759 | case 's': | |
9760 | printf ("$%d", sreg); | |
9761 | continue; | |
9762 | ||
9763 | case 'a': | |
9764 | printf ("0x%08lx", oc & 0x1ffffff); | |
9765 | continue; | |
9766 | ||
9767 | case 'i': | |
9768 | case 'j': | |
9769 | case 'o': | |
9770 | case 'u': | |
9771 | printf ("%d", imm); | |
9772 | continue; | |
9773 | ||
9774 | case '<': | |
9775 | case '>': | |
9776 | printf ("$%d", shamt); | |
9777 | continue; | |
9778 | ||
9779 | default: | |
9780 | internalError (); | |
9781 | } | |
9782 | break; | |
9783 | } | |
9784 | return; | |
9785 | } | |
9786 | } | |
9787 | printf (_("%08lx UNDEFINED\n"), oc); | |
9788 | } | |
9789 | #endif | |
9790 | ||
9791 | static symbolS * | |
9792 | get_symbol () | |
9793 | { | |
9794 | int c; | |
9795 | char *name; | |
9796 | symbolS *p; | |
9797 | ||
9798 | name = input_line_pointer; | |
9799 | c = get_symbol_end (); | |
9800 | p = (symbolS *) symbol_find_or_make (name); | |
9801 | *input_line_pointer = c; | |
9802 | return p; | |
9803 | } | |
9804 | ||
9805 | /* Align the current frag to a given power of two. The MIPS assembler | |
9806 | also automatically adjusts any preceding label. */ | |
9807 | ||
9808 | static void | |
9809 | mips_align (to, fill, label) | |
9810 | int to; | |
9811 | int fill; | |
9812 | symbolS *label; | |
9813 | { | |
9814 | mips_emit_delays (false); | |
9815 | frag_align (to, fill, 0); | |
9816 | record_alignment (now_seg, to); | |
9817 | if (label != NULL) | |
9818 | { | |
9819 | assert (S_GET_SEGMENT (label) == now_seg); | |
49309057 | 9820 | symbol_set_frag (label, frag_now); |
252b5132 RH |
9821 | S_SET_VALUE (label, (valueT) frag_now_fix ()); |
9822 | } | |
9823 | } | |
9824 | ||
9825 | /* Align to a given power of two. .align 0 turns off the automatic | |
9826 | alignment used by the data creating pseudo-ops. */ | |
9827 | ||
9828 | static void | |
9829 | s_align (x) | |
9830 | int x; | |
9831 | { | |
9832 | register int temp; | |
9833 | register long temp_fill; | |
9834 | long max_alignment = 15; | |
9835 | ||
9836 | /* | |
9837 | ||
9838 | o Note that the assembler pulls down any immediately preceeding label | |
9839 | to the aligned address. | |
9840 | o It's not documented but auto alignment is reinstated by | |
9841 | a .align pseudo instruction. | |
9842 | o Note also that after auto alignment is turned off the mips assembler | |
9843 | issues an error on attempt to assemble an improperly aligned data item. | |
9844 | We don't. | |
9845 | ||
9846 | */ | |
9847 | ||
9848 | temp = get_absolute_expression (); | |
9849 | if (temp > max_alignment) | |
9850 | as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment); | |
9851 | else if (temp < 0) | |
9852 | { | |
9853 | as_warn (_("Alignment negative: 0 assumed.")); | |
9854 | temp = 0; | |
9855 | } | |
9856 | if (*input_line_pointer == ',') | |
9857 | { | |
9858 | input_line_pointer++; | |
9859 | temp_fill = get_absolute_expression (); | |
9860 | } | |
9861 | else | |
9862 | temp_fill = 0; | |
9863 | if (temp) | |
9864 | { | |
9865 | auto_align = 1; | |
9866 | mips_align (temp, (int) temp_fill, | |
9867 | insn_labels != NULL ? insn_labels->label : NULL); | |
9868 | } | |
9869 | else | |
9870 | { | |
9871 | auto_align = 0; | |
9872 | } | |
9873 | ||
9874 | demand_empty_rest_of_line (); | |
9875 | } | |
9876 | ||
9877 | void | |
9878 | mips_flush_pending_output () | |
9879 | { | |
9880 | mips_emit_delays (false); | |
9881 | mips_clear_insn_labels (); | |
9882 | } | |
9883 | ||
9884 | static void | |
9885 | s_change_sec (sec) | |
9886 | int sec; | |
9887 | { | |
9888 | segT seg; | |
9889 | ||
9890 | /* When generating embedded PIC code, we only use the .text, .lit8, | |
9891 | .sdata and .sbss sections. We change the .data and .rdata | |
9892 | pseudo-ops to use .sdata. */ | |
9893 | if (mips_pic == EMBEDDED_PIC | |
9894 | && (sec == 'd' || sec == 'r')) | |
9895 | sec = 's'; | |
9896 | ||
9897 | #ifdef OBJ_ELF | |
9898 | /* The ELF backend needs to know that we are changing sections, so | |
9899 | that .previous works correctly. We could do something like check | |
9900 | for a obj_section_change_hook macro, but that might be confusing | |
9901 | as it would not be appropriate to use it in the section changing | |
9902 | functions in read.c, since obj-elf.c intercepts those. FIXME: | |
9903 | This should be cleaner, somehow. */ | |
9904 | obj_elf_section_change_hook (); | |
9905 | #endif | |
9906 | ||
9907 | mips_emit_delays (false); | |
9908 | switch (sec) | |
9909 | { | |
9910 | case 't': | |
9911 | s_text (0); | |
9912 | break; | |
9913 | case 'd': | |
9914 | s_data (0); | |
9915 | break; | |
9916 | case 'b': | |
9917 | subseg_set (bss_section, (subsegT) get_absolute_expression ()); | |
9918 | demand_empty_rest_of_line (); | |
9919 | break; | |
9920 | ||
9921 | case 'r': | |
9922 | if (USE_GLOBAL_POINTER_OPT) | |
9923 | { | |
9924 | seg = subseg_new (RDATA_SECTION_NAME, | |
9925 | (subsegT) get_absolute_expression ()); | |
9926 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
9927 | { | |
9928 | bfd_set_section_flags (stdoutput, seg, | |
9929 | (SEC_ALLOC | |
9930 | | SEC_LOAD | |
9931 | | SEC_READONLY | |
9932 | | SEC_RELOC | |
9933 | | SEC_DATA)); | |
9934 | if (strcmp (TARGET_OS, "elf") != 0) | |
9935 | bfd_set_section_alignment (stdoutput, seg, 4); | |
9936 | } | |
9937 | demand_empty_rest_of_line (); | |
9938 | } | |
9939 | else | |
9940 | { | |
9941 | as_bad (_("No read only data section in this object file format")); | |
9942 | demand_empty_rest_of_line (); | |
9943 | return; | |
9944 | } | |
9945 | break; | |
9946 | ||
9947 | case 's': | |
9948 | if (USE_GLOBAL_POINTER_OPT) | |
9949 | { | |
9950 | seg = subseg_new (".sdata", (subsegT) get_absolute_expression ()); | |
9951 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
9952 | { | |
9953 | bfd_set_section_flags (stdoutput, seg, | |
9954 | SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
9955 | | SEC_DATA); | |
9956 | if (strcmp (TARGET_OS, "elf") != 0) | |
9957 | bfd_set_section_alignment (stdoutput, seg, 4); | |
9958 | } | |
9959 | demand_empty_rest_of_line (); | |
9960 | break; | |
9961 | } | |
9962 | else | |
9963 | { | |
9964 | as_bad (_("Global pointers not supported; recompile -G 0")); | |
9965 | demand_empty_rest_of_line (); | |
9966 | return; | |
9967 | } | |
9968 | } | |
9969 | ||
9970 | auto_align = 1; | |
9971 | } | |
9972 | ||
9973 | void | |
9974 | mips_enable_auto_align () | |
9975 | { | |
9976 | auto_align = 1; | |
9977 | } | |
9978 | ||
9979 | static void | |
9980 | s_cons (log_size) | |
9981 | int log_size; | |
9982 | { | |
9983 | symbolS *label; | |
9984 | ||
9985 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
9986 | mips_emit_delays (false); | |
9987 | if (log_size > 0 && auto_align) | |
9988 | mips_align (log_size, 0, label); | |
9989 | mips_clear_insn_labels (); | |
9990 | cons (1 << log_size); | |
9991 | } | |
9992 | ||
9993 | static void | |
9994 | s_float_cons (type) | |
9995 | int type; | |
9996 | { | |
9997 | symbolS *label; | |
9998 | ||
9999 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10000 | ||
10001 | mips_emit_delays (false); | |
10002 | ||
10003 | if (auto_align) | |
49309057 ILT |
10004 | { |
10005 | if (type == 'd') | |
10006 | mips_align (3, 0, label); | |
10007 | else | |
10008 | mips_align (2, 0, label); | |
10009 | } | |
252b5132 RH |
10010 | |
10011 | mips_clear_insn_labels (); | |
10012 | ||
10013 | float_cons (type); | |
10014 | } | |
10015 | ||
10016 | /* Handle .globl. We need to override it because on Irix 5 you are | |
10017 | permitted to say | |
10018 | .globl foo .text | |
10019 | where foo is an undefined symbol, to mean that foo should be | |
10020 | considered to be the address of a function. */ | |
10021 | ||
10022 | static void | |
10023 | s_mips_globl (x) | |
10024 | int x; | |
10025 | { | |
10026 | char *name; | |
10027 | int c; | |
10028 | symbolS *symbolP; | |
10029 | flagword flag; | |
10030 | ||
10031 | name = input_line_pointer; | |
10032 | c = get_symbol_end (); | |
10033 | symbolP = symbol_find_or_make (name); | |
10034 | *input_line_pointer = c; | |
10035 | SKIP_WHITESPACE (); | |
10036 | ||
10037 | /* On Irix 5, every global symbol that is not explicitly labelled as | |
10038 | being a function is apparently labelled as being an object. */ | |
10039 | flag = BSF_OBJECT; | |
10040 | ||
10041 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
10042 | { | |
10043 | char *secname; | |
10044 | asection *sec; | |
10045 | ||
10046 | secname = input_line_pointer; | |
10047 | c = get_symbol_end (); | |
10048 | sec = bfd_get_section_by_name (stdoutput, secname); | |
10049 | if (sec == NULL) | |
10050 | as_bad (_("%s: no such section"), secname); | |
10051 | *input_line_pointer = c; | |
10052 | ||
10053 | if (sec != NULL && (sec->flags & SEC_CODE) != 0) | |
10054 | flag = BSF_FUNCTION; | |
10055 | } | |
10056 | ||
49309057 | 10057 | symbol_get_bfdsym (symbolP)->flags |= flag; |
252b5132 RH |
10058 | |
10059 | S_SET_EXTERNAL (symbolP); | |
10060 | demand_empty_rest_of_line (); | |
10061 | } | |
10062 | ||
10063 | static void | |
10064 | s_option (x) | |
10065 | int x; | |
10066 | { | |
10067 | char *opt; | |
10068 | char c; | |
10069 | ||
10070 | opt = input_line_pointer; | |
10071 | c = get_symbol_end (); | |
10072 | ||
10073 | if (*opt == 'O') | |
10074 | { | |
10075 | /* FIXME: What does this mean? */ | |
10076 | } | |
10077 | else if (strncmp (opt, "pic", 3) == 0) | |
10078 | { | |
10079 | int i; | |
10080 | ||
10081 | i = atoi (opt + 3); | |
10082 | if (i == 0) | |
10083 | mips_pic = NO_PIC; | |
10084 | else if (i == 2) | |
10085 | mips_pic = SVR4_PIC; | |
10086 | else | |
10087 | as_bad (_(".option pic%d not supported"), i); | |
10088 | ||
10089 | if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC) | |
10090 | { | |
10091 | if (g_switch_seen && g_switch_value != 0) | |
10092 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
10093 | g_switch_value = 0; | |
10094 | bfd_set_gp_size (stdoutput, 0); | |
10095 | } | |
10096 | } | |
10097 | else | |
10098 | as_warn (_("Unrecognized option \"%s\""), opt); | |
10099 | ||
10100 | *input_line_pointer = c; | |
10101 | demand_empty_rest_of_line (); | |
10102 | } | |
10103 | ||
10104 | /* This structure is used to hold a stack of .set values. */ | |
10105 | ||
10106 | struct mips_option_stack | |
10107 | { | |
10108 | struct mips_option_stack *next; | |
10109 | struct mips_set_options options; | |
10110 | }; | |
10111 | ||
10112 | static struct mips_option_stack *mips_opts_stack; | |
10113 | ||
10114 | /* Handle the .set pseudo-op. */ | |
10115 | ||
10116 | static void | |
10117 | s_mipsset (x) | |
10118 | int x; | |
10119 | { | |
10120 | char *name = input_line_pointer, ch; | |
10121 | ||
10122 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
10123 | input_line_pointer++; | |
10124 | ch = *input_line_pointer; | |
10125 | *input_line_pointer = '\0'; | |
10126 | ||
10127 | if (strcmp (name, "reorder") == 0) | |
10128 | { | |
10129 | if (mips_opts.noreorder && prev_nop_frag != NULL) | |
10130 | { | |
10131 | /* If we still have pending nops, we can discard them. The | |
10132 | usual nop handling will insert any that are still | |
10133 | needed. */ | |
10134 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds | |
10135 | * (mips_opts.mips16 ? 2 : 4)); | |
10136 | prev_nop_frag = NULL; | |
10137 | } | |
10138 | mips_opts.noreorder = 0; | |
10139 | } | |
10140 | else if (strcmp (name, "noreorder") == 0) | |
10141 | { | |
10142 | mips_emit_delays (true); | |
10143 | mips_opts.noreorder = 1; | |
10144 | mips_any_noreorder = 1; | |
10145 | } | |
10146 | else if (strcmp (name, "at") == 0) | |
10147 | { | |
10148 | mips_opts.noat = 0; | |
10149 | } | |
10150 | else if (strcmp (name, "noat") == 0) | |
10151 | { | |
10152 | mips_opts.noat = 1; | |
10153 | } | |
10154 | else if (strcmp (name, "macro") == 0) | |
10155 | { | |
10156 | mips_opts.warn_about_macros = 0; | |
10157 | } | |
10158 | else if (strcmp (name, "nomacro") == 0) | |
10159 | { | |
10160 | if (mips_opts.noreorder == 0) | |
10161 | as_bad (_("`noreorder' must be set before `nomacro'")); | |
10162 | mips_opts.warn_about_macros = 1; | |
10163 | } | |
10164 | else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0) | |
10165 | { | |
10166 | mips_opts.nomove = 0; | |
10167 | } | |
10168 | else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0) | |
10169 | { | |
10170 | mips_opts.nomove = 1; | |
10171 | } | |
10172 | else if (strcmp (name, "bopt") == 0) | |
10173 | { | |
10174 | mips_opts.nobopt = 0; | |
10175 | } | |
10176 | else if (strcmp (name, "nobopt") == 0) | |
10177 | { | |
10178 | mips_opts.nobopt = 1; | |
10179 | } | |
10180 | else if (strcmp (name, "mips16") == 0 | |
10181 | || strcmp (name, "MIPS-16") == 0) | |
10182 | mips_opts.mips16 = 1; | |
10183 | else if (strcmp (name, "nomips16") == 0 | |
10184 | || strcmp (name, "noMIPS-16") == 0) | |
10185 | mips_opts.mips16 = 0; | |
10186 | else if (strncmp (name, "mips", 4) == 0) | |
10187 | { | |
10188 | int isa; | |
10189 | ||
10190 | /* Permit the user to change the ISA on the fly. Needless to | |
10191 | say, misuse can cause serious problems. */ | |
10192 | isa = atoi (name + 4); | |
10193 | if (isa == 0) | |
10194 | mips_opts.isa = file_mips_isa; | |
10195 | else if (isa < 1 || isa > 4) | |
10196 | as_bad (_("unknown ISA level")); | |
10197 | else | |
10198 | mips_opts.isa = isa; | |
10199 | } | |
10200 | else if (strcmp (name, "autoextend") == 0) | |
10201 | mips_opts.noautoextend = 0; | |
10202 | else if (strcmp (name, "noautoextend") == 0) | |
10203 | mips_opts.noautoextend = 1; | |
10204 | else if (strcmp (name, "push") == 0) | |
10205 | { | |
10206 | struct mips_option_stack *s; | |
10207 | ||
10208 | s = (struct mips_option_stack *) xmalloc (sizeof *s); | |
10209 | s->next = mips_opts_stack; | |
10210 | s->options = mips_opts; | |
10211 | mips_opts_stack = s; | |
10212 | } | |
10213 | else if (strcmp (name, "pop") == 0) | |
10214 | { | |
10215 | struct mips_option_stack *s; | |
10216 | ||
10217 | s = mips_opts_stack; | |
10218 | if (s == NULL) | |
10219 | as_bad (_(".set pop with no .set push")); | |
10220 | else | |
10221 | { | |
10222 | /* If we're changing the reorder mode we need to handle | |
10223 | delay slots correctly. */ | |
10224 | if (s->options.noreorder && ! mips_opts.noreorder) | |
10225 | mips_emit_delays (true); | |
10226 | else if (! s->options.noreorder && mips_opts.noreorder) | |
10227 | { | |
10228 | if (prev_nop_frag != NULL) | |
10229 | { | |
10230 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds | |
10231 | * (mips_opts.mips16 ? 2 : 4)); | |
10232 | prev_nop_frag = NULL; | |
10233 | } | |
10234 | } | |
10235 | ||
10236 | mips_opts = s->options; | |
10237 | mips_opts_stack = s->next; | |
10238 | free (s); | |
10239 | } | |
10240 | } | |
10241 | else | |
10242 | { | |
10243 | as_warn (_("Tried to set unrecognized symbol: %s\n"), name); | |
10244 | } | |
10245 | *input_line_pointer = ch; | |
10246 | demand_empty_rest_of_line (); | |
10247 | } | |
10248 | ||
10249 | /* Handle the .abicalls pseudo-op. I believe this is equivalent to | |
10250 | .option pic2. It means to generate SVR4 PIC calls. */ | |
10251 | ||
10252 | static void | |
10253 | s_abicalls (ignore) | |
10254 | int ignore; | |
10255 | { | |
10256 | mips_pic = SVR4_PIC; | |
10257 | if (USE_GLOBAL_POINTER_OPT) | |
10258 | { | |
10259 | if (g_switch_seen && g_switch_value != 0) | |
10260 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
10261 | g_switch_value = 0; | |
10262 | } | |
10263 | bfd_set_gp_size (stdoutput, 0); | |
10264 | demand_empty_rest_of_line (); | |
10265 | } | |
10266 | ||
10267 | /* Handle the .cpload pseudo-op. This is used when generating SVR4 | |
10268 | PIC code. It sets the $gp register for the function based on the | |
10269 | function address, which is in the register named in the argument. | |
10270 | This uses a relocation against _gp_disp, which is handled specially | |
10271 | by the linker. The result is: | |
10272 | lui $gp,%hi(_gp_disp) | |
10273 | addiu $gp,$gp,%lo(_gp_disp) | |
10274 | addu $gp,$gp,.cpload argument | |
10275 | The .cpload argument is normally $25 == $t9. */ | |
10276 | ||
10277 | static void | |
10278 | s_cpload (ignore) | |
10279 | int ignore; | |
10280 | { | |
10281 | expressionS ex; | |
10282 | int icnt = 0; | |
10283 | ||
10284 | /* If we are not generating SVR4 PIC code, .cpload is ignored. */ | |
10285 | if (mips_pic != SVR4_PIC) | |
10286 | { | |
10287 | s_ignore (0); | |
10288 | return; | |
10289 | } | |
10290 | ||
10291 | /* .cpload should be a in .set noreorder section. */ | |
10292 | if (mips_opts.noreorder == 0) | |
10293 | as_warn (_(".cpload not in noreorder section")); | |
10294 | ||
10295 | ex.X_op = O_symbol; | |
10296 | ex.X_add_symbol = symbol_find_or_make ("_gp_disp"); | |
10297 | ex.X_op_symbol = NULL; | |
10298 | ex.X_add_number = 0; | |
10299 | ||
10300 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ | |
49309057 | 10301 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
252b5132 RH |
10302 | |
10303 | macro_build_lui ((char *) NULL, &icnt, &ex, GP); | |
10304 | macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP, | |
10305 | (int) BFD_RELOC_LO16); | |
10306 | ||
10307 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t", | |
10308 | GP, GP, tc_get_register (0)); | |
10309 | ||
10310 | demand_empty_rest_of_line (); | |
10311 | } | |
10312 | ||
10313 | /* Handle the .cprestore pseudo-op. This stores $gp into a given | |
10314 | offset from $sp. The offset is remembered, and after making a PIC | |
10315 | call $gp is restored from that location. */ | |
10316 | ||
10317 | static void | |
10318 | s_cprestore (ignore) | |
10319 | int ignore; | |
10320 | { | |
10321 | expressionS ex; | |
10322 | int icnt = 0; | |
10323 | ||
10324 | /* If we are not generating SVR4 PIC code, .cprestore is ignored. */ | |
10325 | if (mips_pic != SVR4_PIC) | |
10326 | { | |
10327 | s_ignore (0); | |
10328 | return; | |
10329 | } | |
10330 | ||
10331 | mips_cprestore_offset = get_absolute_expression (); | |
10332 | ||
10333 | ex.X_op = O_constant; | |
10334 | ex.X_add_symbol = NULL; | |
10335 | ex.X_op_symbol = NULL; | |
10336 | ex.X_add_number = mips_cprestore_offset; | |
10337 | ||
10338 | macro_build ((char *) NULL, &icnt, &ex, | |
10339 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
10340 | || mips_opts.isa < 3) | |
10341 | ? "sw" : "sd"), | |
10342 | "t,o(b)", GP, (int) BFD_RELOC_LO16, SP); | |
10343 | ||
10344 | demand_empty_rest_of_line (); | |
10345 | } | |
10346 | ||
10347 | /* Handle the .gpword pseudo-op. This is used when generating PIC | |
10348 | code. It generates a 32 bit GP relative reloc. */ | |
10349 | ||
10350 | static void | |
10351 | s_gpword (ignore) | |
10352 | int ignore; | |
10353 | { | |
10354 | symbolS *label; | |
10355 | expressionS ex; | |
10356 | char *p; | |
10357 | ||
10358 | /* When not generating PIC code, this is treated as .word. */ | |
10359 | if (mips_pic != SVR4_PIC) | |
10360 | { | |
10361 | s_cons (2); | |
10362 | return; | |
10363 | } | |
10364 | ||
10365 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10366 | mips_emit_delays (true); | |
10367 | if (auto_align) | |
10368 | mips_align (2, 0, label); | |
10369 | mips_clear_insn_labels (); | |
10370 | ||
10371 | expression (&ex); | |
10372 | ||
10373 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
10374 | { | |
10375 | as_bad (_("Unsupported use of .gpword")); | |
10376 | ignore_rest_of_line (); | |
10377 | } | |
10378 | ||
10379 | p = frag_more (4); | |
10380 | md_number_to_chars (p, (valueT) 0, 4); | |
10381 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0, | |
10382 | BFD_RELOC_MIPS_GPREL32); | |
10383 | ||
10384 | demand_empty_rest_of_line (); | |
10385 | } | |
10386 | ||
10387 | /* Handle the .cpadd pseudo-op. This is used when dealing with switch | |
10388 | tables in SVR4 PIC code. */ | |
10389 | ||
10390 | static void | |
10391 | s_cpadd (ignore) | |
10392 | int ignore; | |
10393 | { | |
10394 | int icnt = 0; | |
10395 | int reg; | |
10396 | ||
10397 | /* This is ignored when not generating SVR4 PIC code. */ | |
10398 | if (mips_pic != SVR4_PIC) | |
10399 | { | |
10400 | s_ignore (0); | |
10401 | return; | |
10402 | } | |
10403 | ||
10404 | /* Add $gp to the register named as an argument. */ | |
10405 | reg = tc_get_register (0); | |
10406 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
10407 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
10408 | || mips_opts.isa < 3) | |
10409 | ? "addu" : "daddu"), | |
10410 | "d,v,t", reg, reg, GP); | |
10411 | ||
10412 | demand_empty_rest_of_line (); | |
10413 | } | |
10414 | ||
10415 | /* Handle the .insn pseudo-op. This marks instruction labels in | |
10416 | mips16 mode. This permits the linker to handle them specially, | |
10417 | such as generating jalx instructions when needed. We also make | |
10418 | them odd for the duration of the assembly, in order to generate the | |
10419 | right sort of code. We will make them even in the adjust_symtab | |
10420 | routine, while leaving them marked. This is convenient for the | |
10421 | debugger and the disassembler. The linker knows to make them odd | |
10422 | again. */ | |
10423 | ||
10424 | static void | |
10425 | s_insn (ignore) | |
10426 | int ignore; | |
10427 | { | |
10428 | if (mips_opts.mips16) | |
10429 | mips16_mark_labels (); | |
10430 | ||
10431 | demand_empty_rest_of_line (); | |
10432 | } | |
10433 | ||
10434 | /* Handle a .stabn directive. We need these in order to mark a label | |
10435 | as being a mips16 text label correctly. Sometimes the compiler | |
10436 | will emit a label, followed by a .stabn, and then switch sections. | |
10437 | If the label and .stabn are in mips16 mode, then the label is | |
10438 | really a mips16 text label. */ | |
10439 | ||
10440 | static void | |
10441 | s_mips_stab (type) | |
10442 | int type; | |
10443 | { | |
10444 | if (type == 'n' && mips_opts.mips16) | |
10445 | mips16_mark_labels (); | |
10446 | ||
10447 | s_stab (type); | |
10448 | } | |
10449 | ||
10450 | /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. | |
10451 | */ | |
10452 | ||
10453 | static void | |
10454 | s_mips_weakext (ignore) | |
10455 | int ignore; | |
10456 | { | |
10457 | char *name; | |
10458 | int c; | |
10459 | symbolS *symbolP; | |
10460 | expressionS exp; | |
10461 | ||
10462 | name = input_line_pointer; | |
10463 | c = get_symbol_end (); | |
10464 | symbolP = symbol_find_or_make (name); | |
10465 | S_SET_WEAK (symbolP); | |
10466 | *input_line_pointer = c; | |
10467 | ||
10468 | SKIP_WHITESPACE (); | |
10469 | ||
10470 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
10471 | { | |
10472 | if (S_IS_DEFINED (symbolP)) | |
10473 | { | |
10474 | as_bad ("Ignoring attempt to redefine symbol `%s'.", | |
10475 | S_GET_NAME (symbolP)); | |
10476 | ignore_rest_of_line (); | |
10477 | return; | |
10478 | } | |
10479 | ||
10480 | if (*input_line_pointer == ',') | |
10481 | { | |
10482 | ++input_line_pointer; | |
10483 | SKIP_WHITESPACE (); | |
10484 | } | |
10485 | ||
10486 | expression (&exp); | |
10487 | if (exp.X_op != O_symbol) | |
10488 | { | |
10489 | as_bad ("bad .weakext directive"); | |
10490 | ignore_rest_of_line(); | |
10491 | return; | |
10492 | } | |
49309057 | 10493 | symbol_set_value_expression (symbolP, &exp); |
252b5132 RH |
10494 | } |
10495 | ||
10496 | demand_empty_rest_of_line (); | |
10497 | } | |
10498 | ||
10499 | /* Parse a register string into a number. Called from the ECOFF code | |
10500 | to parse .frame. The argument is non-zero if this is the frame | |
10501 | register, so that we can record it in mips_frame_reg. */ | |
10502 | ||
10503 | int | |
10504 | tc_get_register (frame) | |
10505 | int frame; | |
10506 | { | |
10507 | int reg; | |
10508 | ||
10509 | SKIP_WHITESPACE (); | |
10510 | if (*input_line_pointer++ != '$') | |
10511 | { | |
10512 | as_warn (_("expected `$'")); | |
10513 | reg = 0; | |
10514 | } | |
10515 | else if (isdigit ((unsigned char) *input_line_pointer)) | |
10516 | { | |
10517 | reg = get_absolute_expression (); | |
10518 | if (reg < 0 || reg >= 32) | |
10519 | { | |
10520 | as_warn (_("Bad register number")); | |
10521 | reg = 0; | |
10522 | } | |
10523 | } | |
10524 | else | |
10525 | { | |
10526 | if (strncmp (input_line_pointer, "fp", 2) == 0) | |
10527 | reg = FP; | |
10528 | else if (strncmp (input_line_pointer, "sp", 2) == 0) | |
10529 | reg = SP; | |
10530 | else if (strncmp (input_line_pointer, "gp", 2) == 0) | |
10531 | reg = GP; | |
10532 | else if (strncmp (input_line_pointer, "at", 2) == 0) | |
10533 | reg = AT; | |
10534 | else | |
10535 | { | |
10536 | as_warn (_("Unrecognized register name")); | |
10537 | reg = 0; | |
10538 | } | |
10539 | input_line_pointer += 2; | |
10540 | } | |
10541 | if (frame) | |
10542 | mips_frame_reg = reg != 0 ? reg : SP; | |
10543 | return reg; | |
10544 | } | |
10545 | ||
10546 | valueT | |
10547 | md_section_align (seg, addr) | |
10548 | asection *seg; | |
10549 | valueT addr; | |
10550 | { | |
10551 | int align = bfd_get_section_alignment (stdoutput, seg); | |
10552 | ||
10553 | #ifdef OBJ_ELF | |
10554 | /* We don't need to align ELF sections to the full alignment. | |
10555 | However, Irix 5 may prefer that we align them at least to a 16 | |
10556 | byte boundary. We don't bother to align the sections if we are | |
10557 | targeted for an embedded system. */ | |
10558 | if (strcmp (TARGET_OS, "elf") == 0) | |
10559 | return addr; | |
10560 | if (align > 4) | |
10561 | align = 4; | |
10562 | #endif | |
10563 | ||
10564 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
10565 | } | |
10566 | ||
10567 | /* Utility routine, called from above as well. If called while the | |
10568 | input file is still being read, it's only an approximation. (For | |
10569 | example, a symbol may later become defined which appeared to be | |
10570 | undefined earlier.) */ | |
10571 | ||
10572 | static int | |
10573 | nopic_need_relax (sym, before_relaxing) | |
10574 | symbolS *sym; | |
10575 | int before_relaxing; | |
10576 | { | |
10577 | if (sym == 0) | |
10578 | return 0; | |
10579 | ||
10580 | if (USE_GLOBAL_POINTER_OPT) | |
10581 | { | |
10582 | const char *symname; | |
10583 | int change; | |
10584 | ||
10585 | /* Find out whether this symbol can be referenced off the GP | |
10586 | register. It can be if it is smaller than the -G size or if | |
10587 | it is in the .sdata or .sbss section. Certain symbols can | |
10588 | not be referenced off the GP, although it appears as though | |
10589 | they can. */ | |
10590 | symname = S_GET_NAME (sym); | |
10591 | if (symname != (const char *) NULL | |
10592 | && (strcmp (symname, "eprol") == 0 | |
10593 | || strcmp (symname, "etext") == 0 | |
10594 | || strcmp (symname, "_gp") == 0 | |
10595 | || strcmp (symname, "edata") == 0 | |
10596 | || strcmp (symname, "_fbss") == 0 | |
10597 | || strcmp (symname, "_fdata") == 0 | |
10598 | || strcmp (symname, "_ftext") == 0 | |
10599 | || strcmp (symname, "end") == 0 | |
10600 | || strcmp (symname, "_gp_disp") == 0)) | |
10601 | change = 1; | |
10602 | else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym)) | |
10603 | && (0 | |
10604 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 ILT |
10605 | || (symbol_get_obj (sym)->ecoff_extern_size != 0 |
10606 | && (symbol_get_obj (sym)->ecoff_extern_size | |
10607 | <= g_switch_value)) | |
252b5132 RH |
10608 | #endif |
10609 | /* We must defer this decision until after the whole | |
10610 | file has been read, since there might be a .extern | |
10611 | after the first use of this symbol. */ | |
10612 | || (before_relaxing | |
10613 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 | 10614 | && symbol_get_obj (sym)->ecoff_extern_size == 0 |
252b5132 RH |
10615 | #endif |
10616 | && S_GET_VALUE (sym) == 0) | |
10617 | || (S_GET_VALUE (sym) != 0 | |
10618 | && S_GET_VALUE (sym) <= g_switch_value))) | |
10619 | change = 0; | |
10620 | else | |
10621 | { | |
10622 | const char *segname; | |
10623 | ||
10624 | segname = segment_name (S_GET_SEGMENT (sym)); | |
10625 | assert (strcmp (segname, ".lit8") != 0 | |
10626 | && strcmp (segname, ".lit4") != 0); | |
10627 | change = (strcmp (segname, ".sdata") != 0 | |
10628 | && strcmp (segname, ".sbss") != 0); | |
10629 | } | |
10630 | return change; | |
10631 | } | |
10632 | else | |
10633 | /* We are not optimizing for the GP register. */ | |
10634 | return 1; | |
10635 | } | |
10636 | ||
10637 | /* Given a mips16 variant frag FRAGP, return non-zero if it needs an | |
10638 | extended opcode. SEC is the section the frag is in. */ | |
10639 | ||
10640 | static int | |
10641 | mips16_extended_frag (fragp, sec, stretch) | |
10642 | fragS *fragp; | |
10643 | asection *sec; | |
10644 | long stretch; | |
10645 | { | |
10646 | int type; | |
10647 | register const struct mips16_immed_operand *op; | |
10648 | offsetT val; | |
10649 | int mintiny, maxtiny; | |
10650 | segT symsec; | |
10651 | ||
10652 | if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) | |
10653 | return 0; | |
10654 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) | |
10655 | return 1; | |
10656 | ||
10657 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
10658 | op = mips16_immed_operands; | |
10659 | while (op->type != type) | |
10660 | { | |
10661 | ++op; | |
10662 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
10663 | } | |
10664 | ||
10665 | if (op->unsp) | |
10666 | { | |
10667 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
10668 | { | |
10669 | mintiny = 1; | |
10670 | maxtiny = 1 << op->nbits; | |
10671 | } | |
10672 | else | |
10673 | { | |
10674 | mintiny = 0; | |
10675 | maxtiny = (1 << op->nbits) - 1; | |
10676 | } | |
10677 | } | |
10678 | else | |
10679 | { | |
10680 | mintiny = - (1 << (op->nbits - 1)); | |
10681 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
10682 | } | |
10683 | ||
49309057 ILT |
10684 | /* We can't always call S_GET_VALUE here, because we don't want to |
10685 | lock in a particular frag address. */ | |
10686 | if (symbol_constant_p (fragp->fr_symbol)) | |
252b5132 | 10687 | { |
49309057 ILT |
10688 | val = (S_GET_VALUE (fragp->fr_symbol) |
10689 | + symbol_get_frag (fragp->fr_symbol)->fr_address); | |
252b5132 RH |
10690 | symsec = S_GET_SEGMENT (fragp->fr_symbol); |
10691 | } | |
49309057 ILT |
10692 | else if (symbol_equated_p (fragp->fr_symbol) |
10693 | && (symbol_constant_p | |
10694 | (symbol_get_value_expression (fragp->fr_symbol)->X_add_symbol))) | |
252b5132 | 10695 | { |
49309057 ILT |
10696 | symbolS *eqsym; |
10697 | ||
10698 | eqsym = symbol_get_value_expression (fragp->fr_symbol)->X_add_symbol; | |
10699 | val = (S_GET_VALUE (eqsym) | |
10700 | + symbol_get_frag (eqsym)->fr_address | |
10701 | + symbol_get_value_expression (fragp->fr_symbol)->X_add_number | |
10702 | + symbol_get_frag (fragp->fr_symbol)->fr_address); | |
10703 | symsec = S_GET_SEGMENT (eqsym); | |
252b5132 RH |
10704 | } |
10705 | else | |
10706 | return 1; | |
10707 | ||
10708 | if (op->pcrel) | |
10709 | { | |
10710 | addressT addr; | |
10711 | ||
10712 | /* We won't have the section when we are called from | |
10713 | mips_relax_frag. However, we will always have been called | |
10714 | from md_estimate_size_before_relax first. If this is a | |
10715 | branch to a different section, we mark it as such. If SEC is | |
10716 | NULL, and the frag is not marked, then it must be a branch to | |
10717 | the same section. */ | |
10718 | if (sec == NULL) | |
10719 | { | |
10720 | if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype)) | |
10721 | return 1; | |
10722 | } | |
10723 | else | |
10724 | { | |
10725 | if (symsec != sec) | |
10726 | { | |
10727 | fragp->fr_subtype = | |
10728 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
10729 | ||
10730 | /* FIXME: We should support this, and let the linker | |
10731 | catch branches and loads that are out of range. */ | |
10732 | as_bad_where (fragp->fr_file, fragp->fr_line, | |
10733 | _("unsupported PC relative reference to different section")); | |
10734 | ||
10735 | return 1; | |
10736 | } | |
10737 | } | |
10738 | ||
10739 | /* In this case, we know for sure that the symbol fragment is in | |
10740 | the same section. If the fr_address of the symbol fragment | |
10741 | is greater then the address of this fragment we want to add | |
10742 | in STRETCH in order to get a better estimate of the address. | |
10743 | This particularly matters because of the shift bits. */ | |
10744 | if (stretch != 0 | |
49309057 ILT |
10745 | && (symbol_get_frag (fragp->fr_symbol)->fr_address |
10746 | >= fragp->fr_address)) | |
252b5132 RH |
10747 | { |
10748 | fragS *f; | |
10749 | ||
10750 | /* Adjust stretch for any alignment frag. Note that if have | |
10751 | been expanding the earlier code, the symbol may be | |
10752 | defined in what appears to be an earlier frag. FIXME: | |
10753 | This doesn't handle the fr_subtype field, which specifies | |
10754 | a maximum number of bytes to skip when doing an | |
10755 | alignment. */ | |
10756 | for (f = fragp; | |
49309057 | 10757 | f != NULL && f != symbol_get_frag (fragp->fr_symbol); |
252b5132 RH |
10758 | f = f->fr_next) |
10759 | { | |
10760 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
10761 | { | |
10762 | if (stretch < 0) | |
10763 | stretch = - ((- stretch) | |
10764 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
10765 | else | |
10766 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
10767 | if (stretch == 0) | |
10768 | break; | |
10769 | } | |
10770 | } | |
10771 | if (f != NULL) | |
10772 | val += stretch; | |
10773 | } | |
10774 | ||
10775 | addr = fragp->fr_address + fragp->fr_fix; | |
10776 | ||
10777 | /* The base address rules are complicated. The base address of | |
10778 | a branch is the following instruction. The base address of a | |
10779 | PC relative load or add is the instruction itself, but if it | |
10780 | is in a delay slot (in which case it can not be extended) use | |
10781 | the address of the instruction whose delay slot it is in. */ | |
10782 | if (type == 'p' || type == 'q') | |
10783 | { | |
10784 | addr += 2; | |
10785 | ||
10786 | /* If we are currently assuming that this frag should be | |
10787 | extended, then, the current address is two bytes | |
10788 | higher. */ | |
10789 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
10790 | addr += 2; | |
10791 | ||
10792 | /* Ignore the low bit in the target, since it will be set | |
10793 | for a text label. */ | |
10794 | if ((val & 1) != 0) | |
10795 | --val; | |
10796 | } | |
10797 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
10798 | addr -= 4; | |
10799 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
10800 | addr -= 2; | |
10801 | ||
10802 | val -= addr & ~ ((1 << op->shift) - 1); | |
10803 | ||
10804 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
10805 | if (type == 'p' || type == 'q') | |
10806 | val /= 2; | |
10807 | ||
10808 | /* If any of the shifted bits are set, we must use an extended | |
10809 | opcode. If the address depends on the size of this | |
10810 | instruction, this can lead to a loop, so we arrange to always | |
10811 | use an extended opcode. We only check this when we are in | |
10812 | the main relaxation loop, when SEC is NULL. */ | |
10813 | if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL) | |
10814 | { | |
10815 | fragp->fr_subtype = | |
10816 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
10817 | return 1; | |
10818 | } | |
10819 | ||
10820 | /* If we are about to mark a frag as extended because the value | |
10821 | is precisely maxtiny + 1, then there is a chance of an | |
10822 | infinite loop as in the following code: | |
10823 | la $4,foo | |
10824 | .skip 1020 | |
10825 | .align 2 | |
10826 | foo: | |
10827 | In this case when the la is extended, foo is 0x3fc bytes | |
10828 | away, so the la can be shrunk, but then foo is 0x400 away, so | |
10829 | the la must be extended. To avoid this loop, we mark the | |
10830 | frag as extended if it was small, and is about to become | |
10831 | extended with a value of maxtiny + 1. */ | |
10832 | if (val == ((maxtiny + 1) << op->shift) | |
10833 | && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype) | |
10834 | && sec == NULL) | |
10835 | { | |
10836 | fragp->fr_subtype = | |
10837 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
10838 | return 1; | |
10839 | } | |
10840 | } | |
10841 | else if (symsec != absolute_section && sec != NULL) | |
10842 | as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation")); | |
10843 | ||
10844 | if ((val & ((1 << op->shift) - 1)) != 0 | |
10845 | || val < (mintiny << op->shift) | |
10846 | || val > (maxtiny << op->shift)) | |
10847 | return 1; | |
10848 | else | |
10849 | return 0; | |
10850 | } | |
10851 | ||
10852 | /* Estimate the size of a frag before relaxing. Unless this is the | |
10853 | mips16, we are not really relaxing here, and the final size is | |
10854 | encoded in the subtype information. For the mips16, we have to | |
10855 | decide whether we are using an extended opcode or not. */ | |
10856 | ||
10857 | /*ARGSUSED*/ | |
10858 | int | |
10859 | md_estimate_size_before_relax (fragp, segtype) | |
10860 | fragS *fragp; | |
10861 | asection *segtype; | |
10862 | { | |
10863 | int change; | |
10864 | ||
10865 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
10866 | { | |
10867 | if (mips16_extended_frag (fragp, segtype, 0)) | |
10868 | { | |
10869 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
10870 | return 4; | |
10871 | } | |
10872 | else | |
10873 | { | |
10874 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
10875 | return 2; | |
10876 | } | |
10877 | } | |
10878 | ||
10879 | if (mips_pic == NO_PIC) | |
10880 | { | |
10881 | change = nopic_need_relax (fragp->fr_symbol, 0); | |
10882 | } | |
10883 | else if (mips_pic == SVR4_PIC) | |
10884 | { | |
10885 | symbolS *sym; | |
10886 | asection *symsec; | |
10887 | ||
10888 | sym = fragp->fr_symbol; | |
10889 | ||
10890 | /* Handle the case of a symbol equated to another symbol. */ | |
49309057 | 10891 | while (symbol_equated_p (sym) |
252b5132 RH |
10892 | && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) |
10893 | { | |
10894 | symbolS *n; | |
10895 | ||
10896 | /* It's possible to get a loop here in a badly written | |
10897 | program. */ | |
49309057 | 10898 | n = symbol_get_value_expression (sym)->X_add_symbol; |
252b5132 RH |
10899 | if (n == sym) |
10900 | break; | |
10901 | sym = n; | |
10902 | } | |
10903 | ||
10904 | symsec = S_GET_SEGMENT (sym); | |
10905 | ||
10906 | /* This must duplicate the test in adjust_reloc_syms. */ | |
10907 | change = (symsec != &bfd_und_section | |
10908 | && symsec != &bfd_abs_section | |
10909 | && ! bfd_is_com_section (symsec)); | |
10910 | } | |
10911 | else | |
10912 | abort (); | |
10913 | ||
10914 | if (change) | |
10915 | { | |
10916 | /* Record the offset to the first reloc in the fr_opcode field. | |
10917 | This lets md_convert_frag and tc_gen_reloc know that the code | |
10918 | must be expanded. */ | |
10919 | fragp->fr_opcode = (fragp->fr_literal | |
10920 | + fragp->fr_fix | |
10921 | - RELAX_OLD (fragp->fr_subtype) | |
10922 | + RELAX_RELOC1 (fragp->fr_subtype)); | |
10923 | /* FIXME: This really needs as_warn_where. */ | |
10924 | if (RELAX_WARN (fragp->fr_subtype)) | |
10925 | as_warn (_("AT used after \".set noat\" or macro used after \".set nomacro\"")); | |
10926 | } | |
10927 | ||
10928 | if (! change) | |
10929 | return 0; | |
10930 | else | |
10931 | return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype); | |
10932 | } | |
10933 | ||
10934 | /* This is called to see whether a reloc against a defined symbol | |
10935 | should be converted into a reloc against a section. Don't adjust | |
10936 | MIPS16 jump relocations, so we don't have to worry about the format | |
10937 | of the offset in the .o file. Don't adjust relocations against | |
10938 | mips16 symbols, so that the linker can find them if it needs to set | |
10939 | up a stub. */ | |
10940 | ||
10941 | int | |
10942 | mips_fix_adjustable (fixp) | |
10943 | fixS *fixp; | |
10944 | { | |
10945 | if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP) | |
10946 | return 0; | |
10947 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
10948 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
10949 | return 0; | |
10950 | if (fixp->fx_addsy == NULL) | |
10951 | return 1; | |
10952 | #ifdef OBJ_ELF | |
10953 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
10954 | && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16 | |
10955 | && fixp->fx_subsy == NULL) | |
10956 | return 0; | |
10957 | #endif | |
10958 | return 1; | |
10959 | } | |
10960 | ||
10961 | /* Translate internal representation of relocation info to BFD target | |
10962 | format. */ | |
10963 | ||
10964 | arelent ** | |
10965 | tc_gen_reloc (section, fixp) | |
10966 | asection *section; | |
10967 | fixS *fixp; | |
10968 | { | |
10969 | static arelent *retval[4]; | |
10970 | arelent *reloc; | |
10971 | bfd_reloc_code_real_type code; | |
10972 | ||
10973 | reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent)); | |
10974 | retval[1] = NULL; | |
10975 | ||
49309057 ILT |
10976 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
10977 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
10978 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
10979 | ||
10980 | if (mips_pic == EMBEDDED_PIC | |
10981 | && SWITCH_TABLE (fixp)) | |
10982 | { | |
10983 | /* For a switch table entry we use a special reloc. The addend | |
10984 | is actually the difference between the reloc address and the | |
10985 | subtrahend. */ | |
10986 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); | |
10987 | if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour) | |
10988 | as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc")); | |
10989 | fixp->fx_r_type = BFD_RELOC_GPREL32; | |
10990 | } | |
10991 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16) | |
10992 | { | |
10993 | /* We use a special addend for an internal RELLO reloc. */ | |
49309057 | 10994 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
10995 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); |
10996 | else | |
10997 | reloc->addend = fixp->fx_addnumber + reloc->address; | |
10998 | } | |
10999 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S) | |
11000 | { | |
11001 | assert (fixp->fx_next != NULL | |
11002 | && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16); | |
11003 | /* We use a special addend for an internal RELHI reloc. The | |
11004 | reloc is relative to the RELLO; adjust the addend | |
11005 | accordingly. */ | |
49309057 | 11006 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
11007 | reloc->addend = (fixp->fx_next->fx_frag->fr_address |
11008 | + fixp->fx_next->fx_where | |
11009 | - S_GET_VALUE (fixp->fx_subsy)); | |
11010 | else | |
11011 | reloc->addend = (fixp->fx_addnumber | |
11012 | + fixp->fx_next->fx_frag->fr_address | |
11013 | + fixp->fx_next->fx_where); | |
11014 | } | |
11015 | else if (fixp->fx_pcrel == 0) | |
11016 | reloc->addend = fixp->fx_addnumber; | |
11017 | else | |
11018 | { | |
11019 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour) | |
11020 | /* A gruesome hack which is a result of the gruesome gas reloc | |
11021 | handling. */ | |
11022 | reloc->addend = reloc->address; | |
11023 | else | |
11024 | reloc->addend = -reloc->address; | |
11025 | } | |
11026 | ||
11027 | /* If this is a variant frag, we may need to adjust the existing | |
11028 | reloc and generate a new one. */ | |
11029 | if (fixp->fx_frag->fr_opcode != NULL | |
11030 | && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL | |
11031 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16 | |
11032 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16 | |
11033 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
11034 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16 | |
11035 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
11036 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)) | |
11037 | { | |
11038 | arelent *reloc2; | |
11039 | ||
11040 | assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype)); | |
11041 | ||
11042 | /* If this is not the last reloc in this frag, then we have two | |
11043 | GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a | |
11044 | CALL_HI16/CALL_LO16, both of which are being replaced. Let | |
11045 | the second one handle all of them. */ | |
11046 | if (fixp->fx_next != NULL | |
11047 | && fixp->fx_frag == fixp->fx_next->fx_frag) | |
11048 | { | |
11049 | assert ((fixp->fx_r_type == BFD_RELOC_MIPS_GPREL | |
11050 | && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL) | |
11051 | || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
11052 | && (fixp->fx_next->fx_r_type | |
11053 | == BFD_RELOC_MIPS_GOT_LO16)) | |
11054 | || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
11055 | && (fixp->fx_next->fx_r_type | |
11056 | == BFD_RELOC_MIPS_CALL_LO16))); | |
11057 | retval[0] = NULL; | |
11058 | return retval; | |
11059 | } | |
11060 | ||
11061 | fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal; | |
11062 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
11063 | reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent)); | |
11064 | retval[2] = NULL; | |
49309057 ILT |
11065 | reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
11066 | *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
11067 | reloc2->address = (reloc->address |
11068 | + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype) | |
11069 | - RELAX_RELOC1 (fixp->fx_frag->fr_subtype))); | |
11070 | reloc2->addend = fixp->fx_addnumber; | |
11071 | reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16); | |
11072 | assert (reloc2->howto != NULL); | |
11073 | ||
11074 | if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype)) | |
11075 | { | |
11076 | arelent *reloc3; | |
11077 | ||
11078 | reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent)); | |
11079 | retval[3] = NULL; | |
11080 | *reloc3 = *reloc2; | |
11081 | reloc3->address += 4; | |
11082 | } | |
11083 | ||
11084 | if (mips_pic == NO_PIC) | |
11085 | { | |
11086 | assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL); | |
11087 | fixp->fx_r_type = BFD_RELOC_HI16_S; | |
11088 | } | |
11089 | else if (mips_pic == SVR4_PIC) | |
11090 | { | |
11091 | switch (fixp->fx_r_type) | |
11092 | { | |
11093 | default: | |
11094 | abort (); | |
11095 | case BFD_RELOC_MIPS_GOT16: | |
11096 | break; | |
11097 | case BFD_RELOC_MIPS_CALL16: | |
11098 | case BFD_RELOC_MIPS_GOT_LO16: | |
11099 | case BFD_RELOC_MIPS_CALL_LO16: | |
11100 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT16; | |
11101 | break; | |
11102 | } | |
11103 | } | |
11104 | else | |
11105 | abort (); | |
11106 | } | |
11107 | ||
11108 | /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry | |
11109 | to be used in the relocation's section offset. */ | |
11110 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
11111 | { | |
11112 | reloc->address = reloc->addend; | |
11113 | reloc->addend = 0; | |
11114 | } | |
11115 | ||
11116 | /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that | |
11117 | fixup_segment converted a non-PC relative reloc into a PC | |
11118 | relative reloc. In such a case, we need to convert the reloc | |
11119 | code. */ | |
11120 | code = fixp->fx_r_type; | |
11121 | if (fixp->fx_pcrel) | |
11122 | { | |
11123 | switch (code) | |
11124 | { | |
11125 | case BFD_RELOC_8: | |
11126 | code = BFD_RELOC_8_PCREL; | |
11127 | break; | |
11128 | case BFD_RELOC_16: | |
11129 | code = BFD_RELOC_16_PCREL; | |
11130 | break; | |
11131 | case BFD_RELOC_32: | |
11132 | code = BFD_RELOC_32_PCREL; | |
11133 | break; | |
11134 | case BFD_RELOC_64: | |
11135 | code = BFD_RELOC_64_PCREL; | |
11136 | break; | |
11137 | case BFD_RELOC_8_PCREL: | |
11138 | case BFD_RELOC_16_PCREL: | |
11139 | case BFD_RELOC_32_PCREL: | |
11140 | case BFD_RELOC_64_PCREL: | |
11141 | case BFD_RELOC_16_PCREL_S2: | |
11142 | case BFD_RELOC_PCREL_HI16_S: | |
11143 | case BFD_RELOC_PCREL_LO16: | |
11144 | break; | |
11145 | default: | |
11146 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
11147 | _("Cannot make %s relocation PC relative"), | |
11148 | bfd_get_reloc_code_name (code)); | |
11149 | } | |
11150 | } | |
11151 | ||
11152 | /* To support a PC relative reloc when generating embedded PIC code | |
11153 | for ECOFF, we use a Cygnus extension. We check for that here to | |
11154 | make sure that we don't let such a reloc escape normally. */ | |
11155 | if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour | |
11156 | && code == BFD_RELOC_16_PCREL_S2 | |
11157 | && mips_pic != EMBEDDED_PIC) | |
11158 | reloc->howto = NULL; | |
11159 | else | |
11160 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
11161 | ||
11162 | if (reloc->howto == NULL) | |
11163 | { | |
11164 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
11165 | _("Can not represent %s relocation in this object file format"), | |
11166 | bfd_get_reloc_code_name (code)); | |
11167 | retval[0] = NULL; | |
11168 | } | |
11169 | ||
11170 | return retval; | |
11171 | } | |
11172 | ||
11173 | /* Relax a machine dependent frag. This returns the amount by which | |
11174 | the current size of the frag should change. */ | |
11175 | ||
11176 | int | |
11177 | mips_relax_frag (fragp, stretch) | |
11178 | fragS *fragp; | |
11179 | long stretch; | |
11180 | { | |
11181 | if (! RELAX_MIPS16_P (fragp->fr_subtype)) | |
11182 | return 0; | |
11183 | ||
11184 | if (mips16_extended_frag (fragp, (asection *) NULL, stretch)) | |
11185 | { | |
11186 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11187 | return 0; | |
11188 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
11189 | return 2; | |
11190 | } | |
11191 | else | |
11192 | { | |
11193 | if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11194 | return 0; | |
11195 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
11196 | return -2; | |
11197 | } | |
11198 | ||
11199 | return 0; | |
11200 | } | |
11201 | ||
11202 | /* Convert a machine dependent frag. */ | |
11203 | ||
11204 | void | |
11205 | md_convert_frag (abfd, asec, fragp) | |
11206 | bfd *abfd; | |
11207 | segT asec; | |
11208 | fragS *fragp; | |
11209 | { | |
11210 | int old, new; | |
11211 | char *fixptr; | |
11212 | ||
11213 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
11214 | { | |
11215 | int type; | |
11216 | register const struct mips16_immed_operand *op; | |
11217 | boolean small, ext; | |
11218 | offsetT val; | |
11219 | bfd_byte *buf; | |
11220 | unsigned long insn; | |
11221 | boolean use_extend; | |
11222 | unsigned short extend; | |
11223 | ||
11224 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
11225 | op = mips16_immed_operands; | |
11226 | while (op->type != type) | |
11227 | ++op; | |
11228 | ||
11229 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11230 | { | |
11231 | small = false; | |
11232 | ext = true; | |
11233 | } | |
11234 | else | |
11235 | { | |
11236 | small = true; | |
11237 | ext = false; | |
11238 | } | |
11239 | ||
11240 | resolve_symbol_value (fragp->fr_symbol, 1); | |
11241 | val = S_GET_VALUE (fragp->fr_symbol); | |
11242 | if (op->pcrel) | |
11243 | { | |
11244 | addressT addr; | |
11245 | ||
11246 | addr = fragp->fr_address + fragp->fr_fix; | |
11247 | ||
11248 | /* The rules for the base address of a PC relative reloc are | |
11249 | complicated; see mips16_extended_frag. */ | |
11250 | if (type == 'p' || type == 'q') | |
11251 | { | |
11252 | addr += 2; | |
11253 | if (ext) | |
11254 | addr += 2; | |
11255 | /* Ignore the low bit in the target, since it will be | |
11256 | set for a text label. */ | |
11257 | if ((val & 1) != 0) | |
11258 | --val; | |
11259 | } | |
11260 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
11261 | addr -= 4; | |
11262 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
11263 | addr -= 2; | |
11264 | ||
11265 | addr &= ~ (addressT) ((1 << op->shift) - 1); | |
11266 | val -= addr; | |
11267 | ||
11268 | /* Make sure the section winds up with the alignment we have | |
11269 | assumed. */ | |
11270 | if (op->shift > 0) | |
11271 | record_alignment (asec, op->shift); | |
11272 | } | |
11273 | ||
11274 | if (ext | |
11275 | && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype) | |
11276 | || RELAX_MIPS16_DSLOT (fragp->fr_subtype))) | |
11277 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
11278 | _("extended instruction in delay slot")); | |
11279 | ||
11280 | buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix); | |
11281 | ||
11282 | if (target_big_endian) | |
11283 | insn = bfd_getb16 (buf); | |
11284 | else | |
11285 | insn = bfd_getl16 (buf); | |
11286 | ||
11287 | mips16_immed (fragp->fr_file, fragp->fr_line, type, val, | |
11288 | RELAX_MIPS16_USER_EXT (fragp->fr_subtype), | |
11289 | small, ext, &insn, &use_extend, &extend); | |
11290 | ||
11291 | if (use_extend) | |
11292 | { | |
11293 | md_number_to_chars (buf, 0xf000 | extend, 2); | |
11294 | fragp->fr_fix += 2; | |
11295 | buf += 2; | |
11296 | } | |
11297 | ||
11298 | md_number_to_chars (buf, insn, 2); | |
11299 | fragp->fr_fix += 2; | |
11300 | buf += 2; | |
11301 | } | |
11302 | else | |
11303 | { | |
11304 | if (fragp->fr_opcode == NULL) | |
11305 | return; | |
11306 | ||
11307 | old = RELAX_OLD (fragp->fr_subtype); | |
11308 | new = RELAX_NEW (fragp->fr_subtype); | |
11309 | fixptr = fragp->fr_literal + fragp->fr_fix; | |
11310 | ||
11311 | if (new > 0) | |
11312 | memcpy (fixptr - old, fixptr, new); | |
11313 | ||
11314 | fragp->fr_fix += new - old; | |
11315 | } | |
11316 | } | |
11317 | ||
11318 | #ifdef OBJ_ELF | |
11319 | ||
11320 | /* This function is called after the relocs have been generated. | |
11321 | We've been storing mips16 text labels as odd. Here we convert them | |
11322 | back to even for the convenience of the debugger. */ | |
11323 | ||
11324 | void | |
11325 | mips_frob_file_after_relocs () | |
11326 | { | |
11327 | asymbol **syms; | |
11328 | unsigned int count, i; | |
11329 | ||
11330 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
11331 | return; | |
11332 | ||
11333 | syms = bfd_get_outsymbols (stdoutput); | |
11334 | count = bfd_get_symcount (stdoutput); | |
11335 | for (i = 0; i < count; i++, syms++) | |
11336 | { | |
11337 | if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16 | |
11338 | && ((*syms)->value & 1) != 0) | |
11339 | { | |
11340 | (*syms)->value &= ~1; | |
11341 | /* If the symbol has an odd size, it was probably computed | |
11342 | incorrectly, so adjust that as well. */ | |
11343 | if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0) | |
11344 | ++elf_symbol (*syms)->internal_elf_sym.st_size; | |
11345 | } | |
11346 | } | |
11347 | } | |
11348 | ||
11349 | #endif | |
11350 | ||
11351 | /* This function is called whenever a label is defined. It is used | |
11352 | when handling branch delays; if a branch has a label, we assume we | |
11353 | can not move it. */ | |
11354 | ||
11355 | void | |
11356 | mips_define_label (sym) | |
11357 | symbolS *sym; | |
11358 | { | |
11359 | struct insn_label_list *l; | |
11360 | ||
11361 | if (free_insn_labels == NULL) | |
11362 | l = (struct insn_label_list *) xmalloc (sizeof *l); | |
11363 | else | |
11364 | { | |
11365 | l = free_insn_labels; | |
11366 | free_insn_labels = l->next; | |
11367 | } | |
11368 | ||
11369 | l->label = sym; | |
11370 | l->next = insn_labels; | |
11371 | insn_labels = l; | |
11372 | } | |
11373 | \f | |
11374 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
11375 | ||
11376 | /* Some special processing for a MIPS ELF file. */ | |
11377 | ||
11378 | void | |
11379 | mips_elf_final_processing () | |
11380 | { | |
11381 | /* Write out the register information. */ | |
11382 | if (! mips_64) | |
11383 | { | |
11384 | Elf32_RegInfo s; | |
11385 | ||
11386 | s.ri_gprmask = mips_gprmask; | |
11387 | s.ri_cprmask[0] = mips_cprmask[0]; | |
11388 | s.ri_cprmask[1] = mips_cprmask[1]; | |
11389 | s.ri_cprmask[2] = mips_cprmask[2]; | |
11390 | s.ri_cprmask[3] = mips_cprmask[3]; | |
11391 | /* The gp_value field is set by the MIPS ELF backend. */ | |
11392 | ||
11393 | bfd_mips_elf32_swap_reginfo_out (stdoutput, &s, | |
11394 | ((Elf32_External_RegInfo *) | |
11395 | mips_regmask_frag)); | |
11396 | } | |
11397 | else | |
11398 | { | |
11399 | Elf64_Internal_RegInfo s; | |
11400 | ||
11401 | s.ri_gprmask = mips_gprmask; | |
11402 | s.ri_pad = 0; | |
11403 | s.ri_cprmask[0] = mips_cprmask[0]; | |
11404 | s.ri_cprmask[1] = mips_cprmask[1]; | |
11405 | s.ri_cprmask[2] = mips_cprmask[2]; | |
11406 | s.ri_cprmask[3] = mips_cprmask[3]; | |
11407 | /* The gp_value field is set by the MIPS ELF backend. */ | |
11408 | ||
11409 | bfd_mips_elf64_swap_reginfo_out (stdoutput, &s, | |
11410 | ((Elf64_External_RegInfo *) | |
11411 | mips_regmask_frag)); | |
11412 | } | |
11413 | ||
11414 | /* Set the MIPS ELF flag bits. FIXME: There should probably be some | |
11415 | sort of BFD interface for this. */ | |
11416 | if (mips_any_noreorder) | |
11417 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER; | |
11418 | if (mips_pic != NO_PIC) | |
11419 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC; | |
11420 | ||
11421 | /* Set the MIPS ELF ABI flags. */ | |
11422 | if (mips_abi_string == 0) | |
11423 | ; | |
11424 | else if (strcmp (mips_abi_string,"32") == 0) | |
11425 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32; | |
11426 | else if (strcmp (mips_abi_string,"o64") == 0) | |
11427 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64; | |
11428 | else if (strcmp (mips_abi_string,"eabi") == 0) | |
11429 | { | |
11430 | if (mips_eabi64) | |
11431 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64; | |
11432 | else | |
11433 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32; | |
11434 | } | |
11435 | ||
11436 | if (mips_32bitmode) | |
11437 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE; | |
11438 | } | |
11439 | ||
11440 | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ | |
11441 | \f | |
11442 | typedef struct proc | |
11443 | { | |
49309057 | 11444 | symbolS *isym; |
252b5132 RH |
11445 | unsigned long reg_mask; |
11446 | unsigned long reg_offset; | |
11447 | unsigned long fpreg_mask; | |
11448 | unsigned long fpreg_offset; | |
11449 | unsigned long frame_offset; | |
11450 | unsigned long frame_reg; | |
11451 | unsigned long pc_reg; | |
11452 | } | |
11453 | procS; | |
11454 | ||
11455 | static procS cur_proc; | |
11456 | static procS *cur_proc_ptr; | |
11457 | static int numprocs; | |
11458 | ||
11459 | static void | |
11460 | md_obj_begin () | |
11461 | { | |
11462 | } | |
11463 | ||
11464 | static void | |
11465 | md_obj_end () | |
11466 | { | |
11467 | /* check for premature end, nesting errors, etc */ | |
11468 | if (cur_proc_ptr) | |
11469 | as_warn (_("missing `.end' at end of assembly")); | |
11470 | } | |
11471 | ||
11472 | static long | |
11473 | get_number () | |
11474 | { | |
11475 | int negative = 0; | |
11476 | long val = 0; | |
11477 | ||
11478 | if (*input_line_pointer == '-') | |
11479 | { | |
11480 | ++input_line_pointer; | |
11481 | negative = 1; | |
11482 | } | |
d9a62219 | 11483 | if (!isdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11484 | as_bad (_("Expected simple number.")); |
11485 | if (input_line_pointer[0] == '0') | |
11486 | { | |
11487 | if (input_line_pointer[1] == 'x') | |
11488 | { | |
11489 | input_line_pointer += 2; | |
d9a62219 | 11490 | while (isxdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11491 | { |
11492 | val <<= 4; | |
11493 | val |= hex_value (*input_line_pointer++); | |
11494 | } | |
11495 | return negative ? -val : val; | |
11496 | } | |
11497 | else | |
11498 | { | |
11499 | ++input_line_pointer; | |
d9a62219 | 11500 | while (isdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11501 | { |
11502 | val <<= 3; | |
11503 | val |= *input_line_pointer++ - '0'; | |
11504 | } | |
11505 | return negative ? -val : val; | |
11506 | } | |
11507 | } | |
d9a62219 | 11508 | if (!isdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11509 | { |
11510 | printf (_(" *input_line_pointer == '%c' 0x%02x\n"), | |
11511 | *input_line_pointer, *input_line_pointer); | |
11512 | as_warn (_("Invalid number")); | |
11513 | return -1; | |
11514 | } | |
d9a62219 | 11515 | while (isdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11516 | { |
11517 | val *= 10; | |
11518 | val += *input_line_pointer++ - '0'; | |
11519 | } | |
11520 | return negative ? -val : val; | |
11521 | } | |
11522 | ||
11523 | /* The .file directive; just like the usual .file directive, but there | |
11524 | is an initial number which is the ECOFF file index. */ | |
11525 | ||
11526 | static void | |
11527 | s_file (x) | |
11528 | int x; | |
11529 | { | |
11530 | int line; | |
11531 | ||
11532 | line = get_number (); | |
11533 | s_app_file (0); | |
11534 | } | |
11535 | ||
11536 | ||
11537 | /* The .end directive. */ | |
11538 | ||
11539 | static void | |
11540 | s_mips_end (x) | |
11541 | int x; | |
11542 | { | |
11543 | symbolS *p; | |
11544 | int maybe_text; | |
11545 | ||
11546 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
11547 | { | |
11548 | p = get_symbol (); | |
11549 | demand_empty_rest_of_line (); | |
11550 | } | |
11551 | else | |
11552 | p = NULL; | |
11553 | ||
11554 | #ifdef BFD_ASSEMBLER | |
11555 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
11556 | maybe_text = 1; | |
11557 | else | |
11558 | maybe_text = 0; | |
11559 | #else | |
11560 | if (now_seg != data_section && now_seg != bss_section) | |
11561 | maybe_text = 1; | |
11562 | else | |
11563 | maybe_text = 0; | |
11564 | #endif | |
11565 | ||
11566 | if (!maybe_text) | |
11567 | as_warn (_(".end not in text section")); | |
11568 | ||
11569 | if (!cur_proc_ptr) | |
11570 | { | |
11571 | as_warn (_(".end directive without a preceding .ent directive.")); | |
11572 | demand_empty_rest_of_line (); | |
11573 | return; | |
11574 | } | |
11575 | ||
11576 | if (p != NULL) | |
11577 | { | |
11578 | assert (S_GET_NAME (p)); | |
11579 | if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym))) | |
11580 | as_warn (_(".end symbol does not match .ent symbol.")); | |
11581 | } | |
11582 | else | |
11583 | as_warn (_(".end directive missing or unknown symbol")); | |
11584 | ||
11585 | #ifdef MIPS_STABS_ELF | |
11586 | { | |
11587 | segT saved_seg = now_seg; | |
11588 | subsegT saved_subseg = now_subseg; | |
11589 | fragS *saved_frag = frag_now; | |
11590 | valueT dot; | |
11591 | segT seg; | |
11592 | expressionS exp; | |
11593 | char *fragp; | |
11594 | ||
11595 | dot = frag_now_fix (); | |
11596 | ||
11597 | #ifdef md_flush_pending_output | |
11598 | md_flush_pending_output (); | |
11599 | #endif | |
11600 | ||
11601 | assert (pdr_seg); | |
11602 | subseg_set (pdr_seg, 0); | |
11603 | ||
11604 | /* Write the symbol */ | |
11605 | exp.X_op = O_symbol; | |
11606 | exp.X_add_symbol = p; | |
11607 | exp.X_add_number = 0; | |
11608 | emit_expr (&exp, 4); | |
11609 | ||
11610 | fragp = frag_more (7*4); | |
11611 | ||
11612 | md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4); | |
11613 | md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4); | |
11614 | md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4); | |
11615 | md_number_to_chars (fragp +12, (valueT) cur_proc_ptr->fpreg_offset, 4); | |
11616 | md_number_to_chars (fragp +16, (valueT) cur_proc_ptr->frame_offset, 4); | |
11617 | md_number_to_chars (fragp +20, (valueT) cur_proc_ptr->frame_reg, 4); | |
11618 | md_number_to_chars (fragp +24, (valueT) cur_proc_ptr->pc_reg, 4); | |
11619 | ||
11620 | subseg_set (saved_seg, saved_subseg); | |
11621 | } | |
11622 | #endif | |
11623 | ||
11624 | cur_proc_ptr = NULL; | |
11625 | } | |
11626 | ||
11627 | /* The .aent and .ent directives. */ | |
11628 | ||
11629 | static void | |
11630 | s_mips_ent (aent) | |
11631 | int aent; | |
11632 | { | |
11633 | int number = 0; | |
11634 | symbolS *symbolP; | |
11635 | int maybe_text; | |
11636 | ||
11637 | symbolP = get_symbol (); | |
11638 | if (*input_line_pointer == ',') | |
11639 | input_line_pointer++; | |
11640 | SKIP_WHITESPACE (); | |
d9a62219 DE |
11641 | if (isdigit ((unsigned char) *input_line_pointer) |
11642 | || *input_line_pointer == '-') | |
252b5132 RH |
11643 | number = get_number (); |
11644 | ||
11645 | #ifdef BFD_ASSEMBLER | |
11646 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
11647 | maybe_text = 1; | |
11648 | else | |
11649 | maybe_text = 0; | |
11650 | #else | |
11651 | if (now_seg != data_section && now_seg != bss_section) | |
11652 | maybe_text = 1; | |
11653 | else | |
11654 | maybe_text = 0; | |
11655 | #endif | |
11656 | ||
11657 | if (!maybe_text) | |
11658 | as_warn (_(".ent or .aent not in text section.")); | |
11659 | ||
11660 | if (!aent && cur_proc_ptr) | |
11661 | as_warn (_("missing `.end'")); | |
11662 | ||
11663 | if (!aent) | |
11664 | { | |
11665 | cur_proc_ptr = &cur_proc; | |
11666 | memset (cur_proc_ptr, '\0', sizeof (procS)); | |
11667 | ||
11668 | cur_proc_ptr->isym = symbolP; | |
11669 | ||
49309057 | 11670 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
11671 | |
11672 | numprocs++; | |
11673 | } | |
11674 | ||
11675 | demand_empty_rest_of_line (); | |
11676 | } | |
11677 | ||
11678 | /* The .frame directive. If the mdebug section is present (IRIX 5 native) | |
11679 | then ecoff.c (ecoff_directive_frame) is used. For embedded targets, | |
11680 | s_mips_frame is used so that we can set the PDR information correctly. | |
11681 | We can't use the ecoff routines because they make reference to the ecoff | |
11682 | symbol table (in the mdebug section). */ | |
11683 | ||
11684 | static void | |
11685 | s_mips_frame (ignore) | |
11686 | int ignore; | |
11687 | { | |
11688 | #ifdef MIPS_STABS_ELF | |
11689 | ||
11690 | long val; | |
11691 | ||
11692 | if (cur_proc_ptr == (procS *) NULL) | |
11693 | { | |
11694 | as_warn (_(".frame outside of .ent")); | |
11695 | demand_empty_rest_of_line (); | |
11696 | return; | |
11697 | } | |
11698 | ||
11699 | cur_proc_ptr->frame_reg = tc_get_register (1); | |
11700 | ||
11701 | SKIP_WHITESPACE (); | |
11702 | if (*input_line_pointer++ != ',' | |
11703 | || get_absolute_expression_and_terminator (&val) != ',') | |
11704 | { | |
11705 | as_warn (_("Bad .frame directive")); | |
11706 | --input_line_pointer; | |
11707 | demand_empty_rest_of_line (); | |
11708 | return; | |
11709 | } | |
11710 | ||
11711 | cur_proc_ptr->frame_offset = val; | |
11712 | cur_proc_ptr->pc_reg = tc_get_register (0); | |
11713 | ||
11714 | demand_empty_rest_of_line (); | |
11715 | #else | |
11716 | s_ignore (ignore); | |
11717 | #endif /* MIPS_STABS_ELF */ | |
11718 | } | |
11719 | ||
11720 | /* The .fmask and .mask directives. If the mdebug section is present | |
11721 | (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For | |
11722 | embedded targets, s_mips_mask is used so that we can set the PDR | |
11723 | information correctly. We can't use the ecoff routines because they | |
11724 | make reference to the ecoff symbol table (in the mdebug section). */ | |
11725 | ||
11726 | static void | |
11727 | s_mips_mask (reg_type) | |
11728 | char reg_type; | |
11729 | { | |
11730 | #ifdef MIPS_STABS_ELF | |
11731 | long mask, off; | |
11732 | ||
11733 | if (cur_proc_ptr == (procS *) NULL) | |
11734 | { | |
11735 | as_warn (_(".mask/.fmask outside of .ent")); | |
11736 | demand_empty_rest_of_line (); | |
11737 | return; | |
11738 | } | |
11739 | ||
11740 | if (get_absolute_expression_and_terminator (&mask) != ',') | |
11741 | { | |
11742 | as_warn (_("Bad .mask/.fmask directive")); | |
11743 | --input_line_pointer; | |
11744 | demand_empty_rest_of_line (); | |
11745 | return; | |
11746 | } | |
11747 | ||
11748 | off = get_absolute_expression (); | |
11749 | ||
11750 | if (reg_type == 'F') | |
11751 | { | |
11752 | cur_proc_ptr->fpreg_mask = mask; | |
11753 | cur_proc_ptr->fpreg_offset = off; | |
11754 | } | |
11755 | else | |
11756 | { | |
11757 | cur_proc_ptr->reg_mask = mask; | |
11758 | cur_proc_ptr->reg_offset = off; | |
11759 | } | |
11760 | ||
11761 | demand_empty_rest_of_line (); | |
11762 | #else | |
11763 | s_ignore (reg_type); | |
11764 | #endif /* MIPS_STABS_ELF */ | |
11765 | } | |
11766 | ||
11767 | /* The .loc directive. */ | |
11768 | ||
11769 | #if 0 | |
11770 | static void | |
11771 | s_loc (x) | |
11772 | int x; | |
11773 | { | |
11774 | symbolS *symbolP; | |
11775 | int lineno; | |
11776 | int addroff; | |
11777 | ||
11778 | assert (now_seg == text_section); | |
11779 | ||
11780 | lineno = get_number (); | |
11781 | addroff = frag_now_fix (); | |
11782 | ||
11783 | symbolP = symbol_new ("", N_SLINE, addroff, frag_now); | |
11784 | S_SET_TYPE (symbolP, N_SLINE); | |
11785 | S_SET_OTHER (symbolP, 0); | |
11786 | S_SET_DESC (symbolP, lineno); | |
11787 | symbolP->sy_segment = now_seg; | |
11788 | } | |
11789 | #endif | |
11790 | ||
11791 | ||
11792 |