Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-mips.c -- assemble code for a MIPS chip. |
f7e42eb4 | 2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 |
82efde3a | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Contributed by the OSF and Ralph Campbell. |
5 | Written by Keith Knowles and Ralph Campbell, working independently. | |
6 | Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus | |
7 | Support. | |
8 | ||
9 | This file is part of GAS. | |
10 | ||
11 | GAS is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2, or (at your option) | |
14 | any later version. | |
15 | ||
16 | GAS is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with GAS; see the file COPYING. If not, write to the Free | |
23 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
24 | 02111-1307, USA. */ | |
25 | ||
26 | #include "as.h" | |
27 | #include "config.h" | |
28 | #include "subsegs.h" | |
3882b010 | 29 | #include "safe-ctype.h" |
252b5132 RH |
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 | ||
252b5132 RH |
105 | /* The name of the readonly data section. */ |
106 | #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \ | |
107 | ? ".data" \ | |
108 | : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \ | |
109 | ? ".rdata" \ | |
056350c6 NC |
110 | : OUTPUT_FLAVOR == bfd_target_coff_flavour \ |
111 | ? ".rdata" \ | |
252b5132 RH |
112 | : OUTPUT_FLAVOR == bfd_target_elf_flavour \ |
113 | ? ".rodata" \ | |
114 | : (abort (), "")) | |
115 | ||
116 | /* This is the set of options which may be modified by the .set | |
117 | pseudo-op. We use a struct so that .set push and .set pop are more | |
118 | reliable. */ | |
119 | ||
e972090a NC |
120 | struct mips_set_options |
121 | { | |
252b5132 RH |
122 | /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 |
123 | if it has not been initialized. Changed by `.set mipsN', and the | |
124 | -mipsN command line option, and the default CPU. */ | |
125 | int isa; | |
126 | /* Whether we are assembling for the mips16 processor. 0 if we are | |
127 | not, 1 if we are, and -1 if the value has not been initialized. | |
128 | Changed by `.set mips16' and `.set nomips16', and the -mips16 and | |
129 | -nomips16 command line options, and the default CPU. */ | |
130 | int mips16; | |
131 | /* Non-zero if we should not reorder instructions. Changed by `.set | |
132 | reorder' and `.set noreorder'. */ | |
133 | int noreorder; | |
134 | /* Non-zero if we should not permit the $at ($1) register to be used | |
135 | in instructions. Changed by `.set at' and `.set noat'. */ | |
136 | int noat; | |
137 | /* Non-zero if we should warn when a macro instruction expands into | |
138 | more than one machine instruction. Changed by `.set nomacro' and | |
139 | `.set macro'. */ | |
140 | int warn_about_macros; | |
141 | /* Non-zero if we should not move instructions. Changed by `.set | |
142 | move', `.set volatile', `.set nomove', and `.set novolatile'. */ | |
143 | int nomove; | |
144 | /* Non-zero if we should not optimize branches by moving the target | |
145 | of the branch into the delay slot. Actually, we don't perform | |
146 | this optimization anyhow. Changed by `.set bopt' and `.set | |
147 | nobopt'. */ | |
148 | int nobopt; | |
149 | /* Non-zero if we should not autoextend mips16 instructions. | |
150 | Changed by `.set autoextend' and `.set noautoextend'. */ | |
151 | int noautoextend; | |
152 | }; | |
153 | ||
154 | /* This is the struct we use to hold the current set of options. Note | |
e7af610e NC |
155 | that we must set the isa field to ISA_UNKNOWN and the mips16 field to |
156 | -1 to indicate that they have not been initialized. */ | |
252b5132 | 157 | |
e972090a NC |
158 | static struct mips_set_options mips_opts = |
159 | { | |
e7af610e NC |
160 | ISA_UNKNOWN, -1, 0, 0, 0, 0, 0, 0 |
161 | }; | |
252b5132 RH |
162 | |
163 | /* These variables are filled in with the masks of registers used. | |
164 | The object format code reads them and puts them in the appropriate | |
165 | place. */ | |
166 | unsigned long mips_gprmask; | |
167 | unsigned long mips_cprmask[4]; | |
168 | ||
169 | /* MIPS ISA we are using for this output file. */ | |
e7af610e | 170 | static int file_mips_isa = ISA_UNKNOWN; |
252b5132 | 171 | |
ec68c924 | 172 | /* The argument of the -mcpu= flag. Historical for code generation. */ |
e7af610e | 173 | static int mips_cpu = CPU_UNKNOWN; |
252b5132 | 174 | |
ec68c924 EC |
175 | /* The argument of the -march= flag. The architecture we are assembling. */ |
176 | static int mips_arch = CPU_UNKNOWN; | |
177 | ||
178 | /* The argument of the -mtune= flag. The architecture for which we | |
179 | are optimizing. */ | |
180 | static int mips_tune = CPU_UNKNOWN; | |
181 | ||
e013f690 TS |
182 | /* The ABI to use. */ |
183 | enum mips_abi_level | |
184 | { | |
185 | NO_ABI = 0, | |
186 | O32_ABI, | |
187 | O64_ABI, | |
188 | N32_ABI, | |
189 | N64_ABI, | |
190 | EABI_ABI | |
191 | }; | |
192 | ||
193 | static enum mips_abi_level mips_abi = NO_ABI; | |
252b5132 | 194 | |
2f4dcb11 | 195 | /* Whether we should mark the file EABI64 or EABI32. */ |
252b5132 RH |
196 | static int mips_eabi64 = 0; |
197 | ||
198 | /* If they asked for mips1 or mips2 and a cpu that is | |
bdaaa2e1 | 199 | mips3 or greater, then mark the object file 32BITMODE. */ |
252b5132 RH |
200 | static int mips_32bitmode = 0; |
201 | ||
bdaaa2e1 | 202 | /* True if -mgp32 was passed. */ |
c97ef257 AH |
203 | static int mips_gp32 = 0; |
204 | ||
ca4e0257 RS |
205 | /* True if -mfp32 was passed. */ |
206 | static int mips_fp32 = 0; | |
207 | ||
9ce8a5dd GRK |
208 | /* Some ISA's have delay slots for instructions which read or write |
209 | from a coprocessor (eg. mips1-mips3); some don't (eg mips4). | |
bdaaa2e1 | 210 | Return true if instructions marked INSN_LOAD_COPROC_DELAY, |
9ce8a5dd GRK |
211 | INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a |
212 | delay slot in this ISA. The uses of this macro assume that any | |
213 | ISA that has delay slots for one of these, has them for all. They | |
214 | also assume that ISAs which don't have delays for these insns, don't | |
bdaaa2e1 | 215 | have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */ |
9ce8a5dd | 216 | #define ISA_HAS_COPROC_DELAYS(ISA) ( \ |
e7af610e NC |
217 | (ISA) == ISA_MIPS1 \ |
218 | || (ISA) == ISA_MIPS2 \ | |
219 | || (ISA) == ISA_MIPS3 \ | |
9ce8a5dd GRK |
220 | ) |
221 | ||
bdaaa2e1 | 222 | /* Return true if ISA supports 64 bit gp register instructions. */ |
9ce8a5dd | 223 | #define ISA_HAS_64BIT_REGS(ISA) ( \ |
e7af610e NC |
224 | (ISA) == ISA_MIPS3 \ |
225 | || (ISA) == ISA_MIPS4 \ | |
84ea6cf2 | 226 | || (ISA) == ISA_MIPS5 \ |
d1cf510e | 227 | || (ISA) == ISA_MIPS64 \ |
9ce8a5dd GRK |
228 | ) |
229 | ||
e013f690 TS |
230 | #define HAVE_32BIT_GPRS \ |
231 | (mips_gp32 \ | |
232 | || mips_abi == O32_ABI \ | |
233 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
ca4e0257 | 234 | |
e013f690 TS |
235 | #define HAVE_32BIT_FPRS \ |
236 | (mips_fp32 \ | |
237 | || mips_abi == O32_ABI \ | |
238 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
ca4e0257 RS |
239 | |
240 | #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS) | |
241 | #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS) | |
242 | ||
e013f690 TS |
243 | #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI) |
244 | ||
245 | #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI) | |
246 | ||
247 | /* We can only have 64bit addresses if the object file format | |
248 | supports it. */ | |
249 | #define HAVE_32BIT_ADDRESSES \ | |
250 | (HAVE_32BIT_GPRS \ | |
251 | || bfd_arch_bits_per_address (stdoutput) == 32 \ | |
252 | || ! HAVE_64BIT_OBJECTS) | |
253 | ||
254 | #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES) | |
ca4e0257 | 255 | |
bdaaa2e1 | 256 | /* Whether the processor uses hardware interlocks to protect |
252b5132 | 257 | reads from the HI and LO registers, and thus does not |
ec68c924 | 258 | require nops to be inserted. */ |
252b5132 | 259 | |
ec68c924 | 260 | #define hilo_interlocks (mips_arch == CPU_R4010 \ |
252b5132 RH |
261 | ) |
262 | ||
263 | /* Whether the processor uses hardware interlocks to protect reads | |
264 | from the GPRs, and thus does not require nops to be inserted. */ | |
265 | #define gpr_interlocks \ | |
e7af610e | 266 | (mips_opts.isa != ISA_MIPS1 \ |
ec68c924 | 267 | || mips_arch == CPU_R3900) |
252b5132 RH |
268 | |
269 | /* As with other "interlocks" this is used by hardware that has FP | |
270 | (co-processor) interlocks. */ | |
bdaaa2e1 | 271 | /* Itbl support may require additional care here. */ |
ec68c924 | 272 | #define cop_interlocks (mips_arch == CPU_R4300 \ |
252b5132 RH |
273 | ) |
274 | ||
6b76fefe CM |
275 | /* Is this a mfhi or mflo instruction? */ |
276 | #define MF_HILO_INSN(PINFO) \ | |
277 | ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO)) | |
278 | ||
252b5132 RH |
279 | /* MIPS PIC level. */ |
280 | ||
e972090a NC |
281 | enum mips_pic_level |
282 | { | |
252b5132 RH |
283 | /* Do not generate PIC code. */ |
284 | NO_PIC, | |
285 | ||
286 | /* Generate PIC code as in Irix 4. This is not implemented, and I'm | |
287 | not sure what it is supposed to do. */ | |
288 | IRIX4_PIC, | |
289 | ||
290 | /* Generate PIC code as in the SVR4 MIPS ABI. */ | |
291 | SVR4_PIC, | |
292 | ||
293 | /* Generate PIC code without using a global offset table: the data | |
294 | segment has a maximum size of 64K, all data references are off | |
295 | the $gp register, and all text references are PC relative. This | |
296 | is used on some embedded systems. */ | |
297 | EMBEDDED_PIC | |
298 | }; | |
299 | ||
300 | static enum mips_pic_level mips_pic; | |
301 | ||
39c0a331 L |
302 | /* Warn about all NOPS that the assembler generates. */ |
303 | static int warn_nops = 0; | |
304 | ||
252b5132 RH |
305 | /* 1 if we should generate 32 bit offsets from the GP register in |
306 | SVR4_PIC mode. Currently has no meaning in other modes. */ | |
307 | static int mips_big_got; | |
308 | ||
309 | /* 1 if trap instructions should used for overflow rather than break | |
310 | instructions. */ | |
311 | static int mips_trap; | |
312 | ||
119d663a NC |
313 | /* 1 if double width floating point constants should not be constructed |
314 | by a assembling two single width halves into two single width floating | |
315 | point registers which just happen to alias the double width destination | |
316 | register. On some architectures this aliasing can be disabled by a bit | |
d547a75e | 317 | in the status register, and the setting of this bit cannot be determined |
119d663a NC |
318 | automatically at assemble time. */ |
319 | static int mips_disable_float_construction; | |
320 | ||
252b5132 RH |
321 | /* Non-zero if any .set noreorder directives were used. */ |
322 | ||
323 | static int mips_any_noreorder; | |
324 | ||
6b76fefe CM |
325 | /* Non-zero if nops should be inserted when the register referenced in |
326 | an mfhi/mflo instruction is read in the next two instructions. */ | |
327 | static int mips_7000_hilo_fix; | |
328 | ||
252b5132 | 329 | /* The size of the small data section. */ |
156c2f8b | 330 | static unsigned int g_switch_value = 8; |
252b5132 RH |
331 | /* Whether the -G option was used. */ |
332 | static int g_switch_seen = 0; | |
333 | ||
334 | #define N_RMASK 0xc4 | |
335 | #define N_VFP 0xd4 | |
336 | ||
337 | /* If we can determine in advance that GP optimization won't be | |
338 | possible, we can skip the relaxation stuff that tries to produce | |
339 | GP-relative references. This makes delay slot optimization work | |
340 | better. | |
341 | ||
342 | This function can only provide a guess, but it seems to work for | |
fba2b7f9 GK |
343 | gcc output. It needs to guess right for gcc, otherwise gcc |
344 | will put what it thinks is a GP-relative instruction in a branch | |
345 | delay slot. | |
252b5132 RH |
346 | |
347 | I don't know if a fix is needed for the SVR4_PIC mode. I've only | |
348 | fixed it for the non-PIC mode. KR 95/04/07 */ | |
349 | static int nopic_need_relax PARAMS ((symbolS *, int)); | |
350 | ||
351 | /* handle of the OPCODE hash table */ | |
352 | static struct hash_control *op_hash = NULL; | |
353 | ||
354 | /* The opcode hash table we use for the mips16. */ | |
355 | static struct hash_control *mips16_op_hash = NULL; | |
356 | ||
357 | /* This array holds the chars that always start a comment. If the | |
358 | pre-processor is disabled, these aren't very useful */ | |
359 | const char comment_chars[] = "#"; | |
360 | ||
361 | /* This array holds the chars that only start a comment at the beginning of | |
362 | a line. If the line seems to have the form '# 123 filename' | |
363 | .line and .file directives will appear in the pre-processed output */ | |
364 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
365 | first line of the input file. This is because the compiler outputs | |
bdaaa2e1 | 366 | #NO_APP at the beginning of its output. */ |
252b5132 RH |
367 | /* Also note that C style comments are always supported. */ |
368 | const char line_comment_chars[] = "#"; | |
369 | ||
bdaaa2e1 | 370 | /* This array holds machine specific line separator characters. */ |
63a0b638 | 371 | const char line_separator_chars[] = ";"; |
252b5132 RH |
372 | |
373 | /* Chars that can be used to separate mant from exp in floating point nums */ | |
374 | const char EXP_CHARS[] = "eE"; | |
375 | ||
376 | /* Chars that mean this number is a floating point constant */ | |
377 | /* As in 0f12.456 */ | |
378 | /* or 0d1.2345e12 */ | |
379 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
380 | ||
381 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
382 | changed in read.c . Ideally it shouldn't have to know about it at all, | |
383 | but nothing is ideal around here. | |
384 | */ | |
385 | ||
386 | static char *insn_error; | |
387 | ||
388 | static int auto_align = 1; | |
389 | ||
390 | /* When outputting SVR4 PIC code, the assembler needs to know the | |
391 | offset in the stack frame from which to restore the $gp register. | |
392 | This is set by the .cprestore pseudo-op, and saved in this | |
393 | variable. */ | |
394 | static offsetT mips_cprestore_offset = -1; | |
395 | ||
396 | /* This is the register which holds the stack frame, as set by the | |
397 | .frame pseudo-op. This is needed to implement .cprestore. */ | |
398 | static int mips_frame_reg = SP; | |
399 | ||
400 | /* To output NOP instructions correctly, we need to keep information | |
401 | about the previous two instructions. */ | |
402 | ||
403 | /* Whether we are optimizing. The default value of 2 means to remove | |
404 | unneeded NOPs and swap branch instructions when possible. A value | |
405 | of 1 means to not swap branches. A value of 0 means to always | |
406 | insert NOPs. */ | |
407 | static int mips_optimize = 2; | |
408 | ||
409 | /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is | |
410 | equivalent to seeing no -g option at all. */ | |
411 | static int mips_debug = 0; | |
412 | ||
413 | /* The previous instruction. */ | |
414 | static struct mips_cl_insn prev_insn; | |
415 | ||
416 | /* The instruction before prev_insn. */ | |
417 | static struct mips_cl_insn prev_prev_insn; | |
418 | ||
419 | /* If we don't want information for prev_insn or prev_prev_insn, we | |
420 | point the insn_mo field at this dummy integer. */ | |
43841e91 | 421 | static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 }; |
252b5132 RH |
422 | |
423 | /* Non-zero if prev_insn is valid. */ | |
424 | static int prev_insn_valid; | |
425 | ||
426 | /* The frag for the previous instruction. */ | |
427 | static struct frag *prev_insn_frag; | |
428 | ||
429 | /* The offset into prev_insn_frag for the previous instruction. */ | |
430 | static long prev_insn_where; | |
431 | ||
432 | /* The reloc type for the previous instruction, if any. */ | |
433 | static bfd_reloc_code_real_type prev_insn_reloc_type; | |
434 | ||
435 | /* The reloc for the previous instruction, if any. */ | |
436 | static fixS *prev_insn_fixp; | |
437 | ||
438 | /* Non-zero if the previous instruction was in a delay slot. */ | |
439 | static int prev_insn_is_delay_slot; | |
440 | ||
441 | /* Non-zero if the previous instruction was in a .set noreorder. */ | |
442 | static int prev_insn_unreordered; | |
443 | ||
444 | /* Non-zero if the previous instruction uses an extend opcode (if | |
445 | mips16). */ | |
446 | static int prev_insn_extended; | |
447 | ||
448 | /* Non-zero if the previous previous instruction was in a .set | |
449 | noreorder. */ | |
450 | static int prev_prev_insn_unreordered; | |
451 | ||
452 | /* If this is set, it points to a frag holding nop instructions which | |
453 | were inserted before the start of a noreorder section. If those | |
454 | nops turn out to be unnecessary, the size of the frag can be | |
455 | decreased. */ | |
456 | static fragS *prev_nop_frag; | |
457 | ||
458 | /* The number of nop instructions we created in prev_nop_frag. */ | |
459 | static int prev_nop_frag_holds; | |
460 | ||
461 | /* The number of nop instructions that we know we need in | |
bdaaa2e1 | 462 | prev_nop_frag. */ |
252b5132 RH |
463 | static int prev_nop_frag_required; |
464 | ||
465 | /* The number of instructions we've seen since prev_nop_frag. */ | |
466 | static int prev_nop_frag_since; | |
467 | ||
468 | /* For ECOFF and ELF, relocations against symbols are done in two | |
469 | parts, with a HI relocation and a LO relocation. Each relocation | |
470 | has only 16 bits of space to store an addend. This means that in | |
471 | order for the linker to handle carries correctly, it must be able | |
472 | to locate both the HI and the LO relocation. This means that the | |
473 | relocations must appear in order in the relocation table. | |
474 | ||
475 | In order to implement this, we keep track of each unmatched HI | |
476 | relocation. We then sort them so that they immediately precede the | |
bdaaa2e1 | 477 | corresponding LO relocation. */ |
252b5132 | 478 | |
e972090a NC |
479 | struct mips_hi_fixup |
480 | { | |
252b5132 RH |
481 | /* Next HI fixup. */ |
482 | struct mips_hi_fixup *next; | |
483 | /* This fixup. */ | |
484 | fixS *fixp; | |
485 | /* The section this fixup is in. */ | |
486 | segT seg; | |
487 | }; | |
488 | ||
489 | /* The list of unmatched HI relocs. */ | |
490 | ||
491 | static struct mips_hi_fixup *mips_hi_fixup_list; | |
492 | ||
493 | /* Map normal MIPS register numbers to mips16 register numbers. */ | |
494 | ||
495 | #define X ILLEGAL_REG | |
e972090a NC |
496 | static const int mips32_to_16_reg_map[] = |
497 | { | |
252b5132 RH |
498 | X, X, 2, 3, 4, 5, 6, 7, |
499 | X, X, X, X, X, X, X, X, | |
500 | 0, 1, X, X, X, X, X, X, | |
501 | X, X, X, X, X, X, X, X | |
502 | }; | |
503 | #undef X | |
504 | ||
505 | /* Map mips16 register numbers to normal MIPS register numbers. */ | |
506 | ||
e972090a NC |
507 | static const unsigned int mips16_to_32_reg_map[] = |
508 | { | |
252b5132 RH |
509 | 16, 17, 2, 3, 4, 5, 6, 7 |
510 | }; | |
511 | \f | |
512 | /* Since the MIPS does not have multiple forms of PC relative | |
513 | instructions, we do not have to do relaxing as is done on other | |
514 | platforms. However, we do have to handle GP relative addressing | |
515 | correctly, which turns out to be a similar problem. | |
516 | ||
517 | Every macro that refers to a symbol can occur in (at least) two | |
518 | forms, one with GP relative addressing and one without. For | |
519 | example, loading a global variable into a register generally uses | |
520 | a macro instruction like this: | |
521 | lw $4,i | |
522 | If i can be addressed off the GP register (this is true if it is in | |
523 | the .sbss or .sdata section, or if it is known to be smaller than | |
524 | the -G argument) this will generate the following instruction: | |
525 | lw $4,i($gp) | |
526 | This instruction will use a GPREL reloc. If i can not be addressed | |
527 | off the GP register, the following instruction sequence will be used: | |
528 | lui $at,i | |
529 | lw $4,i($at) | |
530 | In this case the first instruction will have a HI16 reloc, and the | |
531 | second reloc will have a LO16 reloc. Both relocs will be against | |
532 | the symbol i. | |
533 | ||
534 | The issue here is that we may not know whether i is GP addressable | |
535 | until after we see the instruction that uses it. Therefore, we | |
536 | want to be able to choose the final instruction sequence only at | |
537 | the end of the assembly. This is similar to the way other | |
538 | platforms choose the size of a PC relative instruction only at the | |
539 | end of assembly. | |
540 | ||
541 | When generating position independent code we do not use GP | |
542 | addressing in quite the same way, but the issue still arises as | |
543 | external symbols and local symbols must be handled differently. | |
544 | ||
545 | We handle these issues by actually generating both possible | |
546 | instruction sequences. The longer one is put in a frag_var with | |
547 | type rs_machine_dependent. We encode what to do with the frag in | |
548 | the subtype field. We encode (1) the number of existing bytes to | |
549 | replace, (2) the number of new bytes to use, (3) the offset from | |
550 | the start of the existing bytes to the first reloc we must generate | |
551 | (that is, the offset is applied from the start of the existing | |
552 | bytes after they are replaced by the new bytes, if any), (4) the | |
553 | offset from the start of the existing bytes to the second reloc, | |
554 | (5) whether a third reloc is needed (the third reloc is always four | |
555 | bytes after the second reloc), and (6) whether to warn if this | |
556 | variant is used (this is sometimes needed if .set nomacro or .set | |
557 | noat is in effect). All these numbers are reasonably small. | |
558 | ||
559 | Generating two instruction sequences must be handled carefully to | |
560 | ensure that delay slots are handled correctly. Fortunately, there | |
561 | are a limited number of cases. When the second instruction | |
562 | sequence is generated, append_insn is directed to maintain the | |
563 | existing delay slot information, so it continues to apply to any | |
564 | code after the second instruction sequence. This means that the | |
565 | second instruction sequence must not impose any requirements not | |
566 | required by the first instruction sequence. | |
567 | ||
568 | These variant frags are then handled in functions called by the | |
569 | machine independent code. md_estimate_size_before_relax returns | |
570 | the final size of the frag. md_convert_frag sets up the final form | |
571 | of the frag. tc_gen_reloc adjust the first reloc and adds a second | |
572 | one if needed. */ | |
573 | #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \ | |
574 | ((relax_substateT) \ | |
575 | (((old) << 23) \ | |
576 | | ((new) << 16) \ | |
577 | | (((reloc1) + 64) << 9) \ | |
578 | | (((reloc2) + 64) << 2) \ | |
579 | | ((reloc3) ? (1 << 1) : 0) \ | |
580 | | ((warn) ? 1 : 0))) | |
581 | #define RELAX_OLD(i) (((i) >> 23) & 0x7f) | |
582 | #define RELAX_NEW(i) (((i) >> 16) & 0x7f) | |
9a41af64 TS |
583 | #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64) |
584 | #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64) | |
252b5132 RH |
585 | #define RELAX_RELOC3(i) (((i) >> 1) & 1) |
586 | #define RELAX_WARN(i) ((i) & 1) | |
587 | ||
588 | /* For mips16 code, we use an entirely different form of relaxation. | |
589 | mips16 supports two versions of most instructions which take | |
590 | immediate values: a small one which takes some small value, and a | |
591 | larger one which takes a 16 bit value. Since branches also follow | |
592 | this pattern, relaxing these values is required. | |
593 | ||
594 | We can assemble both mips16 and normal MIPS code in a single | |
595 | object. Therefore, we need to support this type of relaxation at | |
596 | the same time that we support the relaxation described above. We | |
597 | use the high bit of the subtype field to distinguish these cases. | |
598 | ||
599 | The information we store for this type of relaxation is the | |
600 | argument code found in the opcode file for this relocation, whether | |
601 | the user explicitly requested a small or extended form, and whether | |
602 | the relocation is in a jump or jal delay slot. That tells us the | |
603 | size of the value, and how it should be stored. We also store | |
604 | whether the fragment is considered to be extended or not. We also | |
605 | store whether this is known to be a branch to a different section, | |
606 | whether we have tried to relax this frag yet, and whether we have | |
607 | ever extended a PC relative fragment because of a shift count. */ | |
608 | #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \ | |
609 | (0x80000000 \ | |
610 | | ((type) & 0xff) \ | |
611 | | ((small) ? 0x100 : 0) \ | |
612 | | ((ext) ? 0x200 : 0) \ | |
613 | | ((dslot) ? 0x400 : 0) \ | |
614 | | ((jal_dslot) ? 0x800 : 0)) | |
615 | #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0) | |
616 | #define RELAX_MIPS16_TYPE(i) ((i) & 0xff) | |
617 | #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0) | |
618 | #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0) | |
619 | #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0) | |
620 | #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0) | |
621 | #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0) | |
622 | #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000) | |
623 | #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000) | |
624 | #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0) | |
625 | #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000) | |
626 | #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000) | |
627 | \f | |
628 | /* Prototypes for static functions. */ | |
629 | ||
630 | #ifdef __STDC__ | |
631 | #define internalError() \ | |
632 | as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__) | |
633 | #else | |
634 | #define internalError() as_fatal (_("MIPS internal Error")); | |
635 | #endif | |
636 | ||
637 | enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG }; | |
638 | ||
639 | static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip, | |
640 | unsigned int reg, enum mips_regclass class)); | |
156c2f8b | 641 | static int reg_needs_delay PARAMS ((unsigned int)); |
252b5132 RH |
642 | static void mips16_mark_labels PARAMS ((void)); |
643 | static void append_insn PARAMS ((char *place, | |
644 | struct mips_cl_insn * ip, | |
645 | expressionS * p, | |
646 | bfd_reloc_code_real_type r, | |
647 | boolean)); | |
648 | static void mips_no_prev_insn PARAMS ((int)); | |
649 | static void mips_emit_delays PARAMS ((boolean)); | |
650 | #ifdef USE_STDARG | |
651 | static void macro_build PARAMS ((char *place, int *counter, expressionS * ep, | |
652 | const char *name, const char *fmt, | |
653 | ...)); | |
654 | #else | |
655 | static void macro_build (); | |
656 | #endif | |
657 | static void mips16_macro_build PARAMS ((char *, int *, expressionS *, | |
658 | const char *, const char *, | |
659 | va_list)); | |
660 | static void macro_build_lui PARAMS ((char *place, int *counter, | |
661 | expressionS * ep, int regnum)); | |
662 | static void set_at PARAMS ((int *counter, int reg, int unsignedp)); | |
663 | static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip, | |
664 | expressionS *)); | |
665 | static void load_register PARAMS ((int *, int, expressionS *, int)); | |
666 | static void load_address PARAMS ((int *counter, int reg, expressionS *ep)); | |
ea1fb5dc | 667 | static void move_register PARAMS ((int *, int, int)); |
252b5132 RH |
668 | static void macro PARAMS ((struct mips_cl_insn * ip)); |
669 | static void mips16_macro PARAMS ((struct mips_cl_insn * ip)); | |
670 | #ifdef LOSING_COMPILER | |
671 | static void macro2 PARAMS ((struct mips_cl_insn * ip)); | |
672 | #endif | |
673 | static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
674 | static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
675 | static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean, | |
676 | boolean, boolean, unsigned long *, | |
677 | boolean *, unsigned short *)); | |
678 | static int my_getSmallExpression PARAMS ((expressionS * ep, char *str)); | |
679 | static void my_getExpression PARAMS ((expressionS * ep, char *str)); | |
e013f690 | 680 | static int support_64bit_objects PARAMS((void)); |
252b5132 RH |
681 | static symbolS *get_symbol PARAMS ((void)); |
682 | static void mips_align PARAMS ((int to, int fill, symbolS *label)); | |
683 | static void s_align PARAMS ((int)); | |
684 | static void s_change_sec PARAMS ((int)); | |
685 | static void s_cons PARAMS ((int)); | |
686 | static void s_float_cons PARAMS ((int)); | |
687 | static void s_mips_globl PARAMS ((int)); | |
688 | static void s_option PARAMS ((int)); | |
689 | static void s_mipsset PARAMS ((int)); | |
690 | static void s_abicalls PARAMS ((int)); | |
691 | static void s_cpload PARAMS ((int)); | |
692 | static void s_cprestore PARAMS ((int)); | |
693 | static void s_gpword PARAMS ((int)); | |
694 | static void s_cpadd PARAMS ((int)); | |
695 | static void s_insn PARAMS ((int)); | |
696 | static void md_obj_begin PARAMS ((void)); | |
697 | static void md_obj_end PARAMS ((void)); | |
698 | static long get_number PARAMS ((void)); | |
699 | static void s_mips_ent PARAMS ((int)); | |
700 | static void s_mips_end PARAMS ((int)); | |
701 | static void s_mips_frame PARAMS ((int)); | |
702 | static void s_mips_mask PARAMS ((int)); | |
703 | static void s_mips_stab PARAMS ((int)); | |
704 | static void s_mips_weakext PARAMS ((int)); | |
705 | static void s_file PARAMS ((int)); | |
706 | static int mips16_extended_frag PARAMS ((fragS *, asection *, long)); | |
e7af610e NC |
707 | static const char *mips_isa_to_str PARAMS ((int)); |
708 | static const char *mips_cpu_to_str PARAMS ((int)); | |
252b5132 | 709 | static int validate_mips_insn PARAMS ((const struct mips_opcode *)); |
e87a0284 | 710 | static void show PARAMS ((FILE *, char *, int *, int *)); |
e7af610e | 711 | |
fb1b3232 TS |
712 | /* Return values of my_getSmallExpression() */ |
713 | ||
714 | enum | |
715 | { | |
716 | S_EX_NONE = 0, | |
717 | S_EX_LO, | |
718 | S_EX_HI, | |
719 | S_EX_HIGHER, | |
720 | S_EX_HIGHEST, | |
721 | S_EX_GPREL, | |
722 | S_EX_NEG | |
723 | }; | |
724 | ||
e7af610e NC |
725 | /* Table and functions used to map between CPU/ISA names, and |
726 | ISA levels, and CPU numbers. */ | |
727 | ||
e972090a NC |
728 | struct mips_cpu_info |
729 | { | |
e7af610e NC |
730 | const char *name; /* CPU or ISA name. */ |
731 | int is_isa; /* Is this an ISA? (If 0, a CPU.) */ | |
732 | int isa; /* ISA level. */ | |
733 | int cpu; /* CPU number (default CPU if ISA). */ | |
734 | }; | |
735 | ||
736 | static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *)); | |
737 | static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int)); | |
738 | static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int)); | |
252b5132 RH |
739 | \f |
740 | /* Pseudo-op table. | |
741 | ||
742 | The following pseudo-ops from the Kane and Heinrich MIPS book | |
743 | should be defined here, but are currently unsupported: .alias, | |
744 | .galive, .gjaldef, .gjrlive, .livereg, .noalias. | |
745 | ||
746 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
747 | specific to the type of debugging information being generated, and | |
748 | should be defined by the object format: .aent, .begin, .bend, | |
749 | .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp, | |
750 | .vreg. | |
751 | ||
752 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
753 | not MIPS CPU specific, but are also not specific to the object file | |
754 | format. This file is probably the best place to define them, but | |
755 | they are not currently supported: .asm0, .endr, .lab, .repeat, | |
756 | .struct. */ | |
757 | ||
e972090a NC |
758 | static const pseudo_typeS mips_pseudo_table[] = |
759 | { | |
beae10d5 | 760 | /* MIPS specific pseudo-ops. */ |
252b5132 RH |
761 | {"option", s_option, 0}, |
762 | {"set", s_mipsset, 0}, | |
763 | {"rdata", s_change_sec, 'r'}, | |
764 | {"sdata", s_change_sec, 's'}, | |
765 | {"livereg", s_ignore, 0}, | |
766 | {"abicalls", s_abicalls, 0}, | |
767 | {"cpload", s_cpload, 0}, | |
768 | {"cprestore", s_cprestore, 0}, | |
769 | {"gpword", s_gpword, 0}, | |
770 | {"cpadd", s_cpadd, 0}, | |
771 | {"insn", s_insn, 0}, | |
772 | ||
beae10d5 | 773 | /* Relatively generic pseudo-ops that happen to be used on MIPS |
252b5132 RH |
774 | chips. */ |
775 | {"asciiz", stringer, 1}, | |
776 | {"bss", s_change_sec, 'b'}, | |
777 | {"err", s_err, 0}, | |
778 | {"half", s_cons, 1}, | |
779 | {"dword", s_cons, 3}, | |
780 | {"weakext", s_mips_weakext, 0}, | |
781 | ||
beae10d5 | 782 | /* These pseudo-ops are defined in read.c, but must be overridden |
252b5132 RH |
783 | here for one reason or another. */ |
784 | {"align", s_align, 0}, | |
785 | {"byte", s_cons, 0}, | |
786 | {"data", s_change_sec, 'd'}, | |
787 | {"double", s_float_cons, 'd'}, | |
788 | {"float", s_float_cons, 'f'}, | |
789 | {"globl", s_mips_globl, 0}, | |
790 | {"global", s_mips_globl, 0}, | |
791 | {"hword", s_cons, 1}, | |
792 | {"int", s_cons, 2}, | |
793 | {"long", s_cons, 2}, | |
794 | {"octa", s_cons, 4}, | |
795 | {"quad", s_cons, 3}, | |
796 | {"short", s_cons, 1}, | |
797 | {"single", s_float_cons, 'f'}, | |
798 | {"stabn", s_mips_stab, 'n'}, | |
799 | {"text", s_change_sec, 't'}, | |
800 | {"word", s_cons, 2}, | |
add56521 L |
801 | |
802 | #ifdef MIPS_STABS_ELF | |
803 | { "extern", ecoff_directive_extern, 0}, | |
804 | #endif | |
805 | ||
43841e91 | 806 | { NULL, NULL, 0 }, |
252b5132 RH |
807 | }; |
808 | ||
e972090a NC |
809 | static const pseudo_typeS mips_nonecoff_pseudo_table[] = |
810 | { | |
beae10d5 KH |
811 | /* These pseudo-ops should be defined by the object file format. |
812 | However, a.out doesn't support them, so we have versions here. */ | |
252b5132 RH |
813 | {"aent", s_mips_ent, 1}, |
814 | {"bgnb", s_ignore, 0}, | |
815 | {"end", s_mips_end, 0}, | |
816 | {"endb", s_ignore, 0}, | |
817 | {"ent", s_mips_ent, 0}, | |
818 | {"file", s_file, 0}, | |
819 | {"fmask", s_mips_mask, 'F'}, | |
820 | {"frame", s_mips_frame, 0}, | |
821 | {"loc", s_ignore, 0}, | |
822 | {"mask", s_mips_mask, 'R'}, | |
823 | {"verstamp", s_ignore, 0}, | |
43841e91 | 824 | { NULL, NULL, 0 }, |
252b5132 RH |
825 | }; |
826 | ||
827 | extern void pop_insert PARAMS ((const pseudo_typeS *)); | |
828 | ||
829 | void | |
830 | mips_pop_insert () | |
831 | { | |
832 | pop_insert (mips_pseudo_table); | |
833 | if (! ECOFF_DEBUGGING) | |
834 | pop_insert (mips_nonecoff_pseudo_table); | |
835 | } | |
836 | \f | |
837 | /* Symbols labelling the current insn. */ | |
838 | ||
e972090a NC |
839 | struct insn_label_list |
840 | { | |
252b5132 RH |
841 | struct insn_label_list *next; |
842 | symbolS *label; | |
843 | }; | |
844 | ||
845 | static struct insn_label_list *insn_labels; | |
846 | static struct insn_label_list *free_insn_labels; | |
847 | ||
848 | static void mips_clear_insn_labels PARAMS ((void)); | |
849 | ||
850 | static inline void | |
851 | mips_clear_insn_labels () | |
852 | { | |
853 | register struct insn_label_list **pl; | |
854 | ||
855 | for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next) | |
856 | ; | |
857 | *pl = insn_labels; | |
858 | insn_labels = NULL; | |
859 | } | |
860 | \f | |
861 | static char *expr_end; | |
862 | ||
863 | /* Expressions which appear in instructions. These are set by | |
864 | mips_ip. */ | |
865 | ||
866 | static expressionS imm_expr; | |
867 | static expressionS offset_expr; | |
868 | ||
869 | /* Relocs associated with imm_expr and offset_expr. */ | |
870 | ||
871 | static bfd_reloc_code_real_type imm_reloc; | |
872 | static bfd_reloc_code_real_type offset_reloc; | |
873 | ||
874 | /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */ | |
875 | ||
876 | static boolean imm_unmatched_hi; | |
877 | ||
878 | /* These are set by mips16_ip if an explicit extension is used. */ | |
879 | ||
880 | static boolean mips16_small, mips16_ext; | |
881 | ||
882 | #ifdef MIPS_STABS_ELF | |
883 | /* The pdr segment for per procedure frame/regmask info */ | |
884 | ||
885 | static segT pdr_seg; | |
886 | #endif | |
887 | ||
e7af610e NC |
888 | static const char * |
889 | mips_isa_to_str (isa) | |
890 | int isa; | |
891 | { | |
892 | const struct mips_cpu_info *ci; | |
893 | static char s[20]; | |
894 | ||
895 | ci = mips_cpu_info_from_isa (isa); | |
896 | if (ci != NULL) | |
897 | return (ci->name); | |
898 | ||
899 | sprintf (s, "ISA#%d", isa); | |
900 | return s; | |
901 | } | |
902 | ||
903 | static const char * | |
156c2f8b NC |
904 | mips_cpu_to_str (cpu) |
905 | int cpu; | |
906 | { | |
e7af610e | 907 | const struct mips_cpu_info *ci; |
156c2f8b | 908 | static char s[16]; |
e7af610e NC |
909 | |
910 | ci = mips_cpu_info_from_cpu (cpu); | |
911 | if (ci != NULL) | |
912 | return (ci->name); | |
913 | ||
914 | sprintf (s, "CPU#%d", cpu); | |
915 | return s; | |
156c2f8b NC |
916 | } |
917 | ||
e013f690 TS |
918 | /* The default target format to use. */ |
919 | ||
920 | const char * | |
921 | mips_target_format () | |
922 | { | |
923 | switch (OUTPUT_FLAVOR) | |
924 | { | |
925 | case bfd_target_aout_flavour: | |
926 | return target_big_endian ? "a.out-mips-big" : "a.out-mips-little"; | |
927 | case bfd_target_ecoff_flavour: | |
928 | return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT; | |
929 | case bfd_target_coff_flavour: | |
930 | return "pe-mips"; | |
931 | case bfd_target_elf_flavour: | |
932 | #ifdef TE_TMIPS | |
933 | /* This is traditional mips */ | |
934 | return (target_big_endian | |
935 | ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips" | |
936 | : "elf32-tradbigmips") | |
937 | : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips" | |
938 | : "elf32-tradlittlemips")); | |
939 | #else | |
940 | return (target_big_endian | |
941 | ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips") | |
942 | : (HAVE_64BIT_OBJECTS ? "elf64-littlemips" | |
943 | : "elf32-littlemips")); | |
944 | #endif | |
945 | default: | |
946 | abort (); | |
947 | return NULL; | |
948 | } | |
949 | } | |
950 | ||
156c2f8b NC |
951 | /* This function is called once, at assembler startup time. It should |
952 | set up all the tables, etc. that the MD part of the assembler will need. */ | |
953 | ||
252b5132 RH |
954 | void |
955 | md_begin () | |
956 | { | |
252b5132 | 957 | register const char *retval = NULL; |
156c2f8b | 958 | int i = 0; |
252b5132 RH |
959 | const char *cpu; |
960 | char *a = NULL; | |
961 | int broken = 0; | |
962 | int mips_isa_from_cpu; | |
e7af610e NC |
963 | int target_cpu_had_mips16 = 0; |
964 | const struct mips_cpu_info *ci; | |
252b5132 | 965 | |
056350c6 NC |
966 | /* GP relative stuff not working for PE */ |
967 | if (strncmp (TARGET_OS, "pe", 2) == 0 | |
968 | && g_switch_value != 0) | |
969 | { | |
970 | if (g_switch_seen) | |
971 | as_bad (_("-G not supported in this configuration.")); | |
972 | g_switch_value = 0; | |
973 | } | |
974 | ||
252b5132 RH |
975 | cpu = TARGET_CPU; |
976 | if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0) | |
977 | { | |
978 | a = xmalloc (sizeof TARGET_CPU); | |
979 | strcpy (a, TARGET_CPU); | |
980 | a[(sizeof TARGET_CPU) - 3] = '\0'; | |
981 | cpu = a; | |
982 | } | |
983 | ||
e7af610e | 984 | if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0) |
252b5132 | 985 | { |
e7af610e NC |
986 | target_cpu_had_mips16 = 1; |
987 | cpu += sizeof "mips16" - 1; | |
252b5132 RH |
988 | } |
989 | ||
e7af610e NC |
990 | if (mips_opts.mips16 < 0) |
991 | mips_opts.mips16 = target_cpu_had_mips16; | |
252b5132 | 992 | |
6dce9e24 TS |
993 | /* Backward compatibility for historic -mcpu= option. Check for |
994 | incompatible options, warn if -mcpu is used. */ | |
995 | if (mips_cpu != CPU_UNKNOWN | |
996 | && mips_arch != CPU_UNKNOWN | |
997 | && mips_cpu != mips_arch) | |
998 | { | |
999 | as_fatal (_("The -mcpu option can't be used together with -march. " | |
1000 | "Use -mtune instead of -mcpu.")); | |
1001 | } | |
1002 | ||
1003 | if (mips_cpu != CPU_UNKNOWN | |
1004 | && mips_tune != CPU_UNKNOWN | |
1005 | && mips_cpu != mips_tune) | |
1006 | { | |
1007 | as_fatal (_("The -mcpu option can't be used together with -mtune. " | |
1008 | "Use -march instead of -mcpu.")); | |
1009 | } | |
1010 | ||
1011 | if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN) | |
1012 | { | |
1013 | ci = mips_cpu_info_from_cpu (mips_cpu); | |
1014 | assert (ci != NULL); | |
1015 | mips_arch = ci->cpu; | |
1016 | as_warn (_("The -mcpu option is deprecated. Please use -march and " | |
1017 | "-mtune instead.")); | |
1018 | } | |
1019 | ||
ec68c924 | 1020 | /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was |
e7af610e NC |
1021 | specified on the command line, or some other value if one was. |
1022 | Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on | |
1023 | the command line, or will be set otherwise if one was. */ | |
ec68c924 | 1024 | if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN) |
252b5132 | 1025 | { |
1ff54a84 TS |
1026 | /* We have to check if the isa is the default isa of arch. Otherwise |
1027 | we'll get invalid object file headers. */ | |
1028 | ci = mips_cpu_info_from_cpu (mips_arch); | |
1029 | assert (ci != NULL); | |
1030 | if (mips_opts.isa != ci->isa) | |
1031 | { | |
1032 | /* This really should be an error instead of a warning, but old | |
1033 | compilers only have -mcpu which sets both arch and tune. For | |
1034 | now, we discard arch and preserve tune. */ | |
1035 | as_warn (_("The -march option is incompatible to -mipsN and " | |
1036 | "therefore ignored.")); | |
1037 | if (mips_tune == CPU_UNKNOWN) | |
1038 | mips_tune = mips_arch; | |
1039 | ci = mips_cpu_info_from_isa (mips_opts.isa); | |
1040 | assert (ci != NULL); | |
1041 | mips_arch = ci->cpu; | |
1042 | } | |
252b5132 | 1043 | } |
ec68c924 | 1044 | else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN) |
252b5132 | 1045 | { |
ec68c924 EC |
1046 | /* We have ARCH, we need ISA. */ |
1047 | ci = mips_cpu_info_from_cpu (mips_arch); | |
e7af610e NC |
1048 | assert (ci != NULL); |
1049 | mips_opts.isa = ci->isa; | |
1050 | } | |
ec68c924 | 1051 | else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN) |
e7af610e | 1052 | { |
ec68c924 | 1053 | /* We have ISA, we need default ARCH. */ |
e7af610e NC |
1054 | ci = mips_cpu_info_from_isa (mips_opts.isa); |
1055 | assert (ci != NULL); | |
ec68c924 EC |
1056 | mips_arch = ci->cpu; |
1057 | } | |
e7af610e NC |
1058 | else |
1059 | { | |
ec68c924 | 1060 | /* We need to set both ISA and ARCH from target cpu. */ |
e7af610e NC |
1061 | ci = mips_cpu_info_from_name (cpu); |
1062 | if (ci == NULL) | |
beae10d5 | 1063 | ci = mips_cpu_info_from_cpu (CPU_R3000); |
e7af610e NC |
1064 | assert (ci != NULL); |
1065 | mips_opts.isa = ci->isa; | |
ec68c924 | 1066 | mips_arch = ci->cpu; |
252b5132 RH |
1067 | } |
1068 | ||
ec68c924 EC |
1069 | if (mips_tune == CPU_UNKNOWN) |
1070 | mips_tune = mips_arch; | |
1071 | ||
1072 | ci = mips_cpu_info_from_cpu (mips_arch); | |
e7af610e NC |
1073 | assert (ci != NULL); |
1074 | mips_isa_from_cpu = ci->isa; | |
1075 | ||
252b5132 | 1076 | /* End of TARGET_CPU processing, get rid of malloced memory |
bdaaa2e1 | 1077 | if necessary. */ |
252b5132 RH |
1078 | cpu = NULL; |
1079 | if (a != NULL) | |
1080 | { | |
156c2f8b NC |
1081 | free (a); |
1082 | a = NULL; | |
252b5132 RH |
1083 | } |
1084 | ||
e7af610e | 1085 | if (mips_opts.isa == ISA_MIPS1 && mips_trap) |
252b5132 RH |
1086 | as_bad (_("trap exception not supported at ISA 1")); |
1087 | ||
1088 | /* Set the EABI kind based on the ISA before the user gets | |
1089 | to change the ISA with directives. This isn't really | |
bdaaa2e1 | 1090 | the best, but then neither is basing the abi on the isa. */ |
9ce8a5dd | 1091 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) |
e013f690 | 1092 | && mips_abi == EABI_ABI) |
252b5132 RH |
1093 | mips_eabi64 = 1; |
1094 | ||
e7af610e NC |
1095 | /* If they asked for mips1 or mips2 and a cpu that is |
1096 | mips3 or greater, then mark the object file 32BITMODE. */ | |
1097 | if (mips_isa_from_cpu != ISA_UNKNOWN | |
1098 | && ! ISA_HAS_64BIT_REGS (mips_opts.isa) | |
1099 | && ISA_HAS_64BIT_REGS (mips_isa_from_cpu)) | |
1100 | mips_32bitmode = 1; | |
252b5132 | 1101 | |
ec68c924 | 1102 | if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch)) |
252b5132 RH |
1103 | as_warn (_("Could not set architecture and machine")); |
1104 | ||
1105 | file_mips_isa = mips_opts.isa; | |
1106 | ||
1107 | op_hash = hash_new (); | |
1108 | ||
1109 | for (i = 0; i < NUMOPCODES;) | |
1110 | { | |
1111 | const char *name = mips_opcodes[i].name; | |
1112 | ||
1113 | retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]); | |
1114 | if (retval != NULL) | |
1115 | { | |
1116 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), | |
1117 | mips_opcodes[i].name, retval); | |
1118 | /* Probably a memory allocation problem? Give up now. */ | |
1119 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1120 | } | |
1121 | do | |
1122 | { | |
1123 | if (mips_opcodes[i].pinfo != INSN_MACRO) | |
1124 | { | |
1125 | if (!validate_mips_insn (&mips_opcodes[i])) | |
1126 | broken = 1; | |
1127 | } | |
1128 | ++i; | |
1129 | } | |
1130 | while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name)); | |
1131 | } | |
1132 | ||
1133 | mips16_op_hash = hash_new (); | |
1134 | ||
1135 | i = 0; | |
1136 | while (i < bfd_mips16_num_opcodes) | |
1137 | { | |
1138 | const char *name = mips16_opcodes[i].name; | |
1139 | ||
1140 | retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]); | |
1141 | if (retval != NULL) | |
1142 | as_fatal (_("internal: can't hash `%s': %s"), | |
1143 | mips16_opcodes[i].name, retval); | |
1144 | do | |
1145 | { | |
1146 | if (mips16_opcodes[i].pinfo != INSN_MACRO | |
1147 | && ((mips16_opcodes[i].match & mips16_opcodes[i].mask) | |
1148 | != mips16_opcodes[i].match)) | |
1149 | { | |
1150 | fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"), | |
1151 | mips16_opcodes[i].name, mips16_opcodes[i].args); | |
1152 | broken = 1; | |
1153 | } | |
1154 | ++i; | |
1155 | } | |
1156 | while (i < bfd_mips16_num_opcodes | |
1157 | && strcmp (mips16_opcodes[i].name, name) == 0); | |
1158 | } | |
1159 | ||
1160 | if (broken) | |
1161 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1162 | ||
1163 | /* We add all the general register names to the symbol table. This | |
1164 | helps us detect invalid uses of them. */ | |
1165 | for (i = 0; i < 32; i++) | |
1166 | { | |
1167 | char buf[5]; | |
1168 | ||
1169 | sprintf (buf, "$%d", i); | |
1170 | symbol_table_insert (symbol_new (buf, reg_section, i, | |
1171 | &zero_address_frag)); | |
1172 | } | |
1173 | symbol_table_insert (symbol_new ("$fp", reg_section, FP, | |
1174 | &zero_address_frag)); | |
1175 | symbol_table_insert (symbol_new ("$sp", reg_section, SP, | |
1176 | &zero_address_frag)); | |
1177 | symbol_table_insert (symbol_new ("$gp", reg_section, GP, | |
1178 | &zero_address_frag)); | |
1179 | symbol_table_insert (symbol_new ("$at", reg_section, AT, | |
1180 | &zero_address_frag)); | |
1181 | symbol_table_insert (symbol_new ("$kt0", reg_section, KT0, | |
1182 | &zero_address_frag)); | |
1183 | symbol_table_insert (symbol_new ("$kt1", reg_section, KT1, | |
1184 | &zero_address_frag)); | |
1185 | symbol_table_insert (symbol_new ("$pc", reg_section, -1, | |
1186 | &zero_address_frag)); | |
1187 | ||
1188 | mips_no_prev_insn (false); | |
1189 | ||
1190 | mips_gprmask = 0; | |
1191 | mips_cprmask[0] = 0; | |
1192 | mips_cprmask[1] = 0; | |
1193 | mips_cprmask[2] = 0; | |
1194 | mips_cprmask[3] = 0; | |
1195 | ||
1196 | /* set the default alignment for the text section (2**2) */ | |
1197 | record_alignment (text_section, 2); | |
1198 | ||
1199 | if (USE_GLOBAL_POINTER_OPT) | |
1200 | bfd_set_gp_size (stdoutput, g_switch_value); | |
1201 | ||
1202 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1203 | { | |
1204 | /* On a native system, sections must be aligned to 16 byte | |
1205 | boundaries. When configured for an embedded ELF target, we | |
1206 | don't bother. */ | |
1207 | if (strcmp (TARGET_OS, "elf") != 0) | |
1208 | { | |
1209 | (void) bfd_set_section_alignment (stdoutput, text_section, 4); | |
1210 | (void) bfd_set_section_alignment (stdoutput, data_section, 4); | |
1211 | (void) bfd_set_section_alignment (stdoutput, bss_section, 4); | |
1212 | } | |
1213 | ||
1214 | /* Create a .reginfo section for register masks and a .mdebug | |
1215 | section for debugging information. */ | |
1216 | { | |
1217 | segT seg; | |
1218 | subsegT subseg; | |
1219 | flagword flags; | |
1220 | segT sec; | |
1221 | ||
1222 | seg = now_seg; | |
1223 | subseg = now_subseg; | |
1224 | ||
1225 | /* The ABI says this section should be loaded so that the | |
1226 | running program can access it. However, we don't load it | |
1227 | if we are configured for an embedded target */ | |
1228 | flags = SEC_READONLY | SEC_DATA; | |
1229 | if (strcmp (TARGET_OS, "elf") != 0) | |
1230 | flags |= SEC_ALLOC | SEC_LOAD; | |
1231 | ||
e013f690 | 1232 | if (! HAVE_NEWABI) |
252b5132 RH |
1233 | { |
1234 | sec = subseg_new (".reginfo", (subsegT) 0); | |
1235 | ||
252b5132 RH |
1236 | (void) bfd_set_section_flags (stdoutput, sec, flags); |
1237 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
bdaaa2e1 | 1238 | |
252b5132 RH |
1239 | #ifdef OBJ_ELF |
1240 | mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo)); | |
1241 | #endif | |
1242 | } | |
1243 | else | |
1244 | { | |
1245 | /* The 64-bit ABI uses a .MIPS.options section rather than | |
1246 | .reginfo section. */ | |
1247 | sec = subseg_new (".MIPS.options", (subsegT) 0); | |
1248 | (void) bfd_set_section_flags (stdoutput, sec, flags); | |
1249 | (void) bfd_set_section_alignment (stdoutput, sec, 3); | |
1250 | ||
1251 | #ifdef OBJ_ELF | |
1252 | /* Set up the option header. */ | |
1253 | { | |
1254 | Elf_Internal_Options opthdr; | |
1255 | char *f; | |
1256 | ||
1257 | opthdr.kind = ODK_REGINFO; | |
1258 | opthdr.size = (sizeof (Elf_External_Options) | |
1259 | + sizeof (Elf64_External_RegInfo)); | |
1260 | opthdr.section = 0; | |
1261 | opthdr.info = 0; | |
1262 | f = frag_more (sizeof (Elf_External_Options)); | |
1263 | bfd_mips_elf_swap_options_out (stdoutput, &opthdr, | |
1264 | (Elf_External_Options *) f); | |
1265 | ||
1266 | mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo)); | |
1267 | } | |
1268 | #endif | |
1269 | } | |
1270 | ||
1271 | if (ECOFF_DEBUGGING) | |
1272 | { | |
1273 | sec = subseg_new (".mdebug", (subsegT) 0); | |
1274 | (void) bfd_set_section_flags (stdoutput, sec, | |
1275 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1276 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
1277 | } | |
1278 | ||
1279 | #ifdef MIPS_STABS_ELF | |
1280 | pdr_seg = subseg_new (".pdr", (subsegT) 0); | |
1281 | (void) bfd_set_section_flags (stdoutput, pdr_seg, | |
1282 | SEC_READONLY | SEC_RELOC | SEC_DEBUGGING); | |
1283 | (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2); | |
1284 | #endif | |
1285 | ||
1286 | subseg_set (seg, subseg); | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | if (! ECOFF_DEBUGGING) | |
1291 | md_obj_begin (); | |
1292 | } | |
1293 | ||
1294 | void | |
1295 | md_mips_end () | |
1296 | { | |
1297 | if (! ECOFF_DEBUGGING) | |
1298 | md_obj_end (); | |
1299 | } | |
1300 | ||
1301 | void | |
1302 | md_assemble (str) | |
1303 | char *str; | |
1304 | { | |
1305 | struct mips_cl_insn insn; | |
1306 | ||
1307 | imm_expr.X_op = O_absent; | |
1308 | imm_reloc = BFD_RELOC_UNUSED; | |
1309 | imm_unmatched_hi = false; | |
1310 | offset_expr.X_op = O_absent; | |
1311 | offset_reloc = BFD_RELOC_UNUSED; | |
1312 | ||
1313 | if (mips_opts.mips16) | |
1314 | mips16_ip (str, &insn); | |
1315 | else | |
1316 | { | |
1317 | mips_ip (str, &insn); | |
beae10d5 KH |
1318 | DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), |
1319 | str, insn.insn_opcode)); | |
252b5132 RH |
1320 | } |
1321 | ||
1322 | if (insn_error) | |
1323 | { | |
1324 | as_bad ("%s `%s'", insn_error, str); | |
1325 | return; | |
1326 | } | |
1327 | ||
1328 | if (insn.insn_mo->pinfo == INSN_MACRO) | |
1329 | { | |
1330 | if (mips_opts.mips16) | |
1331 | mips16_macro (&insn); | |
1332 | else | |
1333 | macro (&insn); | |
1334 | } | |
1335 | else | |
1336 | { | |
1337 | if (imm_expr.X_op != O_absent) | |
1338 | append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc, | |
1339 | imm_unmatched_hi); | |
1340 | else if (offset_expr.X_op != O_absent) | |
1341 | append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc, false); | |
1342 | else | |
1343 | append_insn ((char *) NULL, &insn, NULL, BFD_RELOC_UNUSED, false); | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | /* See whether instruction IP reads register REG. CLASS is the type | |
1348 | of register. */ | |
1349 | ||
1350 | static int | |
1351 | insn_uses_reg (ip, reg, class) | |
1352 | struct mips_cl_insn *ip; | |
1353 | unsigned int reg; | |
1354 | enum mips_regclass class; | |
1355 | { | |
1356 | if (class == MIPS16_REG) | |
1357 | { | |
1358 | assert (mips_opts.mips16); | |
1359 | reg = mips16_to_32_reg_map[reg]; | |
1360 | class = MIPS_GR_REG; | |
1361 | } | |
1362 | ||
1363 | /* Don't report on general register 0, since it never changes. */ | |
1364 | if (class == MIPS_GR_REG && reg == 0) | |
1365 | return 0; | |
1366 | ||
1367 | if (class == MIPS_FP_REG) | |
1368 | { | |
1369 | assert (! mips_opts.mips16); | |
1370 | /* If we are called with either $f0 or $f1, we must check $f0. | |
1371 | This is not optimal, because it will introduce an unnecessary | |
1372 | NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would | |
1373 | need to distinguish reading both $f0 and $f1 or just one of | |
1374 | them. Note that we don't have to check the other way, | |
1375 | because there is no instruction that sets both $f0 and $f1 | |
1376 | and requires a delay. */ | |
1377 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_S) | |
1378 | && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1) | |
1379 | == (reg &~ (unsigned) 1))) | |
1380 | return 1; | |
1381 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_T) | |
1382 | && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1) | |
1383 | == (reg &~ (unsigned) 1))) | |
1384 | return 1; | |
1385 | } | |
1386 | else if (! mips_opts.mips16) | |
1387 | { | |
1388 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_S) | |
1389 | && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg) | |
1390 | return 1; | |
1391 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_T) | |
1392 | && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg) | |
1393 | return 1; | |
1394 | } | |
1395 | else | |
1396 | { | |
1397 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X) | |
1398 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX) | |
1399 | & MIPS16OP_MASK_RX)] | |
1400 | == reg)) | |
1401 | return 1; | |
1402 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y) | |
1403 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY) | |
1404 | & MIPS16OP_MASK_RY)] | |
1405 | == reg)) | |
1406 | return 1; | |
1407 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z) | |
1408 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
1409 | & MIPS16OP_MASK_MOVE32Z)] | |
1410 | == reg)) | |
1411 | return 1; | |
1412 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG) | |
1413 | return 1; | |
1414 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP) | |
1415 | return 1; | |
1416 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA) | |
1417 | return 1; | |
1418 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X) | |
1419 | && ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
1420 | & MIPS16OP_MASK_REGR32) == reg) | |
1421 | return 1; | |
1422 | } | |
1423 | ||
1424 | return 0; | |
1425 | } | |
1426 | ||
1427 | /* This function returns true if modifying a register requires a | |
1428 | delay. */ | |
1429 | ||
1430 | static int | |
1431 | reg_needs_delay (reg) | |
156c2f8b | 1432 | unsigned int reg; |
252b5132 RH |
1433 | { |
1434 | unsigned long prev_pinfo; | |
1435 | ||
1436 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1437 | if (! mips_opts.noreorder | |
9ce8a5dd | 1438 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1439 | && ((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1440 | || (! gpr_interlocks | |
1441 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1442 | { | |
1443 | /* A load from a coprocessor or from memory. All load | |
1444 | delays delay the use of general register rt for one | |
1445 | instruction on the r3000. The r6000 and r4000 use | |
1446 | interlocks. */ | |
bdaaa2e1 | 1447 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1448 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1449 | if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)) | |
1450 | return 1; | |
1451 | } | |
1452 | ||
1453 | return 0; | |
1454 | } | |
1455 | ||
1456 | /* Mark instruction labels in mips16 mode. This permits the linker to | |
1457 | handle them specially, such as generating jalx instructions when | |
1458 | needed. We also make them odd for the duration of the assembly, in | |
1459 | order to generate the right sort of code. We will make them even | |
1460 | in the adjust_symtab routine, while leaving them marked. This is | |
1461 | convenient for the debugger and the disassembler. The linker knows | |
1462 | to make them odd again. */ | |
1463 | ||
1464 | static void | |
1465 | mips16_mark_labels () | |
1466 | { | |
1467 | if (mips_opts.mips16) | |
1468 | { | |
1469 | struct insn_label_list *l; | |
98aa84af | 1470 | valueT val; |
252b5132 RH |
1471 | |
1472 | for (l = insn_labels; l != NULL; l = l->next) | |
1473 | { | |
1474 | #ifdef OBJ_ELF | |
1475 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1476 | S_SET_OTHER (l->label, STO_MIPS16); | |
1477 | #endif | |
98aa84af AM |
1478 | val = S_GET_VALUE (l->label); |
1479 | if ((val & 1) == 0) | |
1480 | S_SET_VALUE (l->label, val + 1); | |
252b5132 RH |
1481 | } |
1482 | } | |
1483 | } | |
1484 | ||
1485 | /* Output an instruction. PLACE is where to put the instruction; if | |
1486 | it is NULL, this uses frag_more to get room. IP is the instruction | |
1487 | information. ADDRESS_EXPR is an operand of the instruction to be | |
1488 | used with RELOC_TYPE. */ | |
1489 | ||
1490 | static void | |
1491 | append_insn (place, ip, address_expr, reloc_type, unmatched_hi) | |
1492 | char *place; | |
1493 | struct mips_cl_insn *ip; | |
1494 | expressionS *address_expr; | |
1495 | bfd_reloc_code_real_type reloc_type; | |
1496 | boolean unmatched_hi; | |
1497 | { | |
1498 | register unsigned long prev_pinfo, pinfo; | |
1499 | char *f; | |
1500 | fixS *fixp; | |
1501 | int nops = 0; | |
1502 | ||
1503 | /* Mark instruction labels in mips16 mode. */ | |
1504 | if (mips_opts.mips16) | |
1505 | mips16_mark_labels (); | |
1506 | ||
1507 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1508 | pinfo = ip->insn_mo->pinfo; | |
1509 | ||
1510 | if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL)) | |
1511 | { | |
1512 | int prev_prev_nop; | |
1513 | ||
1514 | /* If the previous insn required any delay slots, see if we need | |
1515 | to insert a NOP or two. There are eight kinds of possible | |
1516 | hazards, of which an instruction can have at most one type. | |
1517 | (1) a load from memory delay | |
1518 | (2) a load from a coprocessor delay | |
1519 | (3) an unconditional branch delay | |
1520 | (4) a conditional branch delay | |
1521 | (5) a move to coprocessor register delay | |
1522 | (6) a load coprocessor register from memory delay | |
1523 | (7) a coprocessor condition code delay | |
1524 | (8) a HI/LO special register delay | |
1525 | ||
1526 | There are a lot of optimizations we could do that we don't. | |
1527 | In particular, we do not, in general, reorder instructions. | |
1528 | If you use gcc with optimization, it will reorder | |
1529 | instructions and generally do much more optimization then we | |
1530 | do here; repeating all that work in the assembler would only | |
1531 | benefit hand written assembly code, and does not seem worth | |
1532 | it. */ | |
1533 | ||
1534 | /* This is how a NOP is emitted. */ | |
1535 | #define emit_nop() \ | |
1536 | (mips_opts.mips16 \ | |
1537 | ? md_number_to_chars (frag_more (2), 0x6500, 2) \ | |
1538 | : md_number_to_chars (frag_more (4), 0, 4)) | |
1539 | ||
1540 | /* The previous insn might require a delay slot, depending upon | |
1541 | the contents of the current insn. */ | |
1542 | if (! mips_opts.mips16 | |
9ce8a5dd | 1543 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1544 | && (((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1545 | && ! cop_interlocks) | |
1546 | || (! gpr_interlocks | |
1547 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1548 | { | |
1549 | /* A load from a coprocessor or from memory. All load | |
1550 | delays delay the use of general register rt for one | |
1551 | instruction on the r3000. The r6000 and r4000 use | |
1552 | interlocks. */ | |
beae10d5 | 1553 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1554 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1555 | if (mips_optimize == 0 | |
1556 | || insn_uses_reg (ip, | |
1557 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
1558 | & OP_MASK_RT), | |
1559 | MIPS_GR_REG)) | |
1560 | ++nops; | |
1561 | } | |
1562 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1563 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 1564 | && (((prev_pinfo & INSN_COPROC_MOVE_DELAY) |
beae10d5 | 1565 | && ! cop_interlocks) |
e7af610e | 1566 | || (mips_opts.isa == ISA_MIPS1 |
252b5132 RH |
1567 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)))) |
1568 | { | |
1569 | /* A generic coprocessor delay. The previous instruction | |
1570 | modified a coprocessor general or control register. If | |
1571 | it modified a control register, we need to avoid any | |
1572 | coprocessor instruction (this is probably not always | |
1573 | required, but it sometimes is). If it modified a general | |
1574 | register, we avoid using that register. | |
1575 | ||
1576 | On the r6000 and r4000 loading a coprocessor register | |
1577 | from memory is interlocked, and does not require a delay. | |
1578 | ||
1579 | This case is not handled very well. There is no special | |
1580 | knowledge of CP0 handling, and the coprocessors other | |
1581 | than the floating point unit are not distinguished at | |
1582 | all. */ | |
1583 | /* Itbl support may require additional care here. FIXME! | |
bdaaa2e1 | 1584 | Need to modify this to include knowledge about |
252b5132 RH |
1585 | user specified delays! */ |
1586 | if (prev_pinfo & INSN_WRITE_FPR_T) | |
1587 | { | |
1588 | if (mips_optimize == 0 | |
1589 | || insn_uses_reg (ip, | |
1590 | ((prev_insn.insn_opcode >> OP_SH_FT) | |
1591 | & OP_MASK_FT), | |
1592 | MIPS_FP_REG)) | |
1593 | ++nops; | |
1594 | } | |
1595 | else if (prev_pinfo & INSN_WRITE_FPR_S) | |
1596 | { | |
1597 | if (mips_optimize == 0 | |
1598 | || insn_uses_reg (ip, | |
1599 | ((prev_insn.insn_opcode >> OP_SH_FS) | |
1600 | & OP_MASK_FS), | |
1601 | MIPS_FP_REG)) | |
1602 | ++nops; | |
1603 | } | |
1604 | else | |
1605 | { | |
1606 | /* We don't know exactly what the previous instruction | |
1607 | does. If the current instruction uses a coprocessor | |
1608 | register, we must insert a NOP. If previous | |
1609 | instruction may set the condition codes, and the | |
1610 | current instruction uses them, we must insert two | |
1611 | NOPS. */ | |
bdaaa2e1 | 1612 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1613 | if (mips_optimize == 0 |
1614 | || ((prev_pinfo & INSN_WRITE_COND_CODE) | |
1615 | && (pinfo & INSN_READ_COND_CODE))) | |
1616 | nops += 2; | |
1617 | else if (pinfo & INSN_COP) | |
1618 | ++nops; | |
1619 | } | |
1620 | } | |
1621 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1622 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1623 | && (prev_pinfo & INSN_WRITE_COND_CODE) |
1624 | && ! cop_interlocks) | |
1625 | { | |
1626 | /* The previous instruction sets the coprocessor condition | |
1627 | codes, but does not require a general coprocessor delay | |
1628 | (this means it is a floating point comparison | |
1629 | instruction). If this instruction uses the condition | |
1630 | codes, we need to insert a single NOP. */ | |
beae10d5 | 1631 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1632 | if (mips_optimize == 0 |
1633 | || (pinfo & INSN_READ_COND_CODE)) | |
1634 | ++nops; | |
1635 | } | |
6b76fefe CM |
1636 | |
1637 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1638 | previous insn was an mfhi/mflo and the current insn | |
1639 | reads the register that the mfhi/mflo wrote to, then | |
1640 | insert two nops. */ | |
1641 | ||
1642 | else if (mips_7000_hilo_fix | |
1643 | && MF_HILO_INSN (prev_pinfo) | |
1644 | && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD) | |
beae10d5 KH |
1645 | & OP_MASK_RD), |
1646 | MIPS_GR_REG)) | |
6b76fefe CM |
1647 | { |
1648 | nops += 2; | |
1649 | } | |
1650 | ||
1651 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1652 | 2nd previous insn was an mfhi/mflo and the current insn | |
1653 | reads the register that the mfhi/mflo wrote to, then | |
1654 | insert one nop. */ | |
1655 | ||
1656 | else if (mips_7000_hilo_fix | |
1657 | && MF_HILO_INSN (prev_prev_insn.insn_opcode) | |
1658 | && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD) | |
1659 | & OP_MASK_RD), | |
1660 | MIPS_GR_REG)) | |
bdaaa2e1 | 1661 | |
6b76fefe CM |
1662 | { |
1663 | nops += 1; | |
1664 | } | |
bdaaa2e1 | 1665 | |
252b5132 RH |
1666 | else if (prev_pinfo & INSN_READ_LO) |
1667 | { | |
1668 | /* The previous instruction reads the LO register; if the | |
1669 | current instruction writes to the LO register, we must | |
bdaaa2e1 KH |
1670 | insert two NOPS. Some newer processors have interlocks. |
1671 | Also the tx39's multiply instructions can be exectuted | |
252b5132 | 1672 | immediatly after a read from HI/LO (without the delay), |
bdaaa2e1 KH |
1673 | though the tx39's divide insns still do require the |
1674 | delay. */ | |
252b5132 | 1675 | if (! (hilo_interlocks |
ec68c924 | 1676 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1677 | && (mips_optimize == 0 |
1678 | || (pinfo & INSN_WRITE_LO))) | |
1679 | nops += 2; | |
1680 | /* Most mips16 branch insns don't have a delay slot. | |
1681 | If a read from LO is immediately followed by a branch | |
1682 | to a write to LO we have a read followed by a write | |
1683 | less than 2 insns away. We assume the target of | |
1684 | a branch might be a write to LO, and insert a nop | |
bdaaa2e1 | 1685 | between a read and an immediately following branch. */ |
252b5132 RH |
1686 | else if (mips_opts.mips16 |
1687 | && (mips_optimize == 0 | |
1688 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1689 | nops += 1; | |
1690 | } | |
1691 | else if (prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
1692 | { | |
1693 | /* The previous instruction reads the HI register; if the | |
1694 | current instruction writes to the HI register, we must | |
1695 | insert a NOP. Some newer processors have interlocks. | |
bdaaa2e1 | 1696 | Also the note tx39's multiply above. */ |
252b5132 | 1697 | if (! (hilo_interlocks |
ec68c924 | 1698 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1699 | && (mips_optimize == 0 |
1700 | || (pinfo & INSN_WRITE_HI))) | |
1701 | nops += 2; | |
1702 | /* Most mips16 branch insns don't have a delay slot. | |
1703 | If a read from HI is immediately followed by a branch | |
1704 | to a write to HI we have a read followed by a write | |
1705 | less than 2 insns away. We assume the target of | |
1706 | a branch might be a write to HI, and insert a nop | |
bdaaa2e1 | 1707 | between a read and an immediately following branch. */ |
252b5132 RH |
1708 | else if (mips_opts.mips16 |
1709 | && (mips_optimize == 0 | |
1710 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1711 | nops += 1; | |
1712 | } | |
1713 | ||
1714 | /* If the previous instruction was in a noreorder section, then | |
1715 | we don't want to insert the nop after all. */ | |
bdaaa2e1 | 1716 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1717 | if (prev_insn_unreordered) |
1718 | nops = 0; | |
1719 | ||
1720 | /* There are two cases which require two intervening | |
1721 | instructions: 1) setting the condition codes using a move to | |
1722 | coprocessor instruction which requires a general coprocessor | |
1723 | delay and then reading the condition codes 2) reading the HI | |
1724 | or LO register and then writing to it (except on processors | |
1725 | which have interlocks). If we are not already emitting a NOP | |
1726 | instruction, we must check for these cases compared to the | |
1727 | instruction previous to the previous instruction. */ | |
1728 | if ((! mips_opts.mips16 | |
9ce8a5dd | 1729 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1730 | && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY) |
1731 | && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE) | |
1732 | && (pinfo & INSN_READ_COND_CODE) | |
1733 | && ! cop_interlocks) | |
1734 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO) | |
1735 | && (pinfo & INSN_WRITE_LO) | |
1736 | && ! (hilo_interlocks | |
ec68c924 | 1737 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))) |
252b5132 RH |
1738 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) |
1739 | && (pinfo & INSN_WRITE_HI) | |
1740 | && ! (hilo_interlocks | |
ec68c924 | 1741 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))) |
252b5132 RH |
1742 | prev_prev_nop = 1; |
1743 | else | |
1744 | prev_prev_nop = 0; | |
1745 | ||
1746 | if (prev_prev_insn_unreordered) | |
1747 | prev_prev_nop = 0; | |
1748 | ||
1749 | if (prev_prev_nop && nops == 0) | |
1750 | ++nops; | |
1751 | ||
1752 | /* If we are being given a nop instruction, don't bother with | |
1753 | one of the nops we would otherwise output. This will only | |
1754 | happen when a nop instruction is used with mips_optimize set | |
1755 | to 0. */ | |
1756 | if (nops > 0 | |
1757 | && ! mips_opts.noreorder | |
156c2f8b | 1758 | && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0)) |
252b5132 RH |
1759 | --nops; |
1760 | ||
1761 | /* Now emit the right number of NOP instructions. */ | |
1762 | if (nops > 0 && ! mips_opts.noreorder) | |
1763 | { | |
1764 | fragS *old_frag; | |
1765 | unsigned long old_frag_offset; | |
1766 | int i; | |
1767 | struct insn_label_list *l; | |
1768 | ||
1769 | old_frag = frag_now; | |
1770 | old_frag_offset = frag_now_fix (); | |
1771 | ||
1772 | for (i = 0; i < nops; i++) | |
1773 | emit_nop (); | |
1774 | ||
1775 | if (listing) | |
1776 | { | |
1777 | listing_prev_line (); | |
1778 | /* We may be at the start of a variant frag. In case we | |
1779 | are, make sure there is enough space for the frag | |
1780 | after the frags created by listing_prev_line. The | |
1781 | argument to frag_grow here must be at least as large | |
1782 | as the argument to all other calls to frag_grow in | |
1783 | this file. We don't have to worry about being in the | |
1784 | middle of a variant frag, because the variants insert | |
1785 | all needed nop instructions themselves. */ | |
1786 | frag_grow (40); | |
1787 | } | |
1788 | ||
1789 | for (l = insn_labels; l != NULL; l = l->next) | |
1790 | { | |
98aa84af AM |
1791 | valueT val; |
1792 | ||
252b5132 | 1793 | assert (S_GET_SEGMENT (l->label) == now_seg); |
49309057 | 1794 | symbol_set_frag (l->label, frag_now); |
98aa84af | 1795 | val = (valueT) frag_now_fix (); |
252b5132 RH |
1796 | /* mips16 text labels are stored as odd. */ |
1797 | if (mips_opts.mips16) | |
98aa84af AM |
1798 | val += 1; |
1799 | S_SET_VALUE (l->label, val); | |
252b5132 RH |
1800 | } |
1801 | ||
1802 | #ifndef NO_ECOFF_DEBUGGING | |
1803 | if (ECOFF_DEBUGGING) | |
1804 | ecoff_fix_loc (old_frag, old_frag_offset); | |
1805 | #endif | |
1806 | } | |
1807 | else if (prev_nop_frag != NULL) | |
1808 | { | |
1809 | /* We have a frag holding nops we may be able to remove. If | |
1810 | we don't need any nops, we can decrease the size of | |
1811 | prev_nop_frag by the size of one instruction. If we do | |
bdaaa2e1 | 1812 | need some nops, we count them in prev_nops_required. */ |
252b5132 RH |
1813 | if (prev_nop_frag_since == 0) |
1814 | { | |
1815 | if (nops == 0) | |
1816 | { | |
1817 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1818 | --prev_nop_frag_holds; | |
1819 | } | |
1820 | else | |
1821 | prev_nop_frag_required += nops; | |
1822 | } | |
1823 | else | |
1824 | { | |
1825 | if (prev_prev_nop == 0) | |
1826 | { | |
1827 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1828 | --prev_nop_frag_holds; | |
1829 | } | |
1830 | else | |
1831 | ++prev_nop_frag_required; | |
1832 | } | |
1833 | ||
1834 | if (prev_nop_frag_holds <= prev_nop_frag_required) | |
1835 | prev_nop_frag = NULL; | |
1836 | ||
1837 | ++prev_nop_frag_since; | |
1838 | ||
1839 | /* Sanity check: by the time we reach the second instruction | |
1840 | after prev_nop_frag, we should have used up all the nops | |
1841 | one way or another. */ | |
1842 | assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL); | |
1843 | } | |
1844 | } | |
1845 | ||
1846 | if (reloc_type > BFD_RELOC_UNUSED) | |
1847 | { | |
1848 | /* We need to set up a variant frag. */ | |
1849 | assert (mips_opts.mips16 && address_expr != NULL); | |
1850 | f = frag_var (rs_machine_dependent, 4, 0, | |
1851 | RELAX_MIPS16_ENCODE (reloc_type - BFD_RELOC_UNUSED, | |
1852 | mips16_small, mips16_ext, | |
1853 | (prev_pinfo | |
1854 | & INSN_UNCOND_BRANCH_DELAY), | |
1855 | (prev_insn_reloc_type | |
1856 | == BFD_RELOC_MIPS16_JMP)), | |
1857 | make_expr_symbol (address_expr), (offsetT) 0, | |
1858 | (char *) NULL); | |
1859 | } | |
1860 | else if (place != NULL) | |
1861 | f = place; | |
1862 | else if (mips_opts.mips16 | |
1863 | && ! ip->use_extend | |
1864 | && reloc_type != BFD_RELOC_MIPS16_JMP) | |
1865 | { | |
1866 | /* Make sure there is enough room to swap this instruction with | |
1867 | a following jump instruction. */ | |
1868 | frag_grow (6); | |
1869 | f = frag_more (2); | |
1870 | } | |
1871 | else | |
1872 | { | |
1873 | if (mips_opts.mips16 | |
1874 | && mips_opts.noreorder | |
1875 | && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0) | |
1876 | as_warn (_("extended instruction in delay slot")); | |
1877 | ||
1878 | f = frag_more (4); | |
1879 | } | |
1880 | ||
1881 | fixp = NULL; | |
1882 | if (address_expr != NULL && reloc_type < BFD_RELOC_UNUSED) | |
1883 | { | |
1884 | if (address_expr->X_op == O_constant) | |
1885 | { | |
1886 | switch (reloc_type) | |
1887 | { | |
1888 | case BFD_RELOC_32: | |
1889 | ip->insn_opcode |= address_expr->X_add_number; | |
1890 | break; | |
1891 | ||
1892 | case BFD_RELOC_LO16: | |
1893 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; | |
1894 | break; | |
1895 | ||
1896 | case BFD_RELOC_MIPS_JMP: | |
1897 | if ((address_expr->X_add_number & 3) != 0) | |
1898 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1899 | (unsigned long) address_expr->X_add_number); | |
1900 | ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff; | |
1901 | break; | |
1902 | ||
1903 | case BFD_RELOC_MIPS16_JMP: | |
1904 | if ((address_expr->X_add_number & 3) != 0) | |
1905 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1906 | (unsigned long) address_expr->X_add_number); | |
1907 | ip->insn_opcode |= | |
1908 | (((address_expr->X_add_number & 0x7c0000) << 3) | |
1909 | | ((address_expr->X_add_number & 0xf800000) >> 7) | |
1910 | | ((address_expr->X_add_number & 0x3fffc) >> 2)); | |
1911 | break; | |
1912 | ||
cb56d3d3 | 1913 | case BFD_RELOC_16_PCREL: |
233b8738 | 1914 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; |
cb56d3d3 TS |
1915 | break; |
1916 | ||
252b5132 RH |
1917 | case BFD_RELOC_16_PCREL_S2: |
1918 | goto need_reloc; | |
1919 | ||
1920 | default: | |
1921 | internalError (); | |
1922 | } | |
1923 | } | |
1924 | else | |
1925 | { | |
1926 | need_reloc: | |
1927 | /* Don't generate a reloc if we are writing into a variant | |
1928 | frag. */ | |
1929 | if (place == NULL) | |
1930 | { | |
1931 | fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4, | |
1932 | address_expr, | |
cb56d3d3 TS |
1933 | (reloc_type == BFD_RELOC_16_PCREL |
1934 | || reloc_type == BFD_RELOC_16_PCREL_S2), | |
252b5132 RH |
1935 | reloc_type); |
1936 | if (unmatched_hi) | |
1937 | { | |
1938 | struct mips_hi_fixup *hi_fixup; | |
1939 | ||
1940 | assert (reloc_type == BFD_RELOC_HI16_S); | |
1941 | hi_fixup = ((struct mips_hi_fixup *) | |
1942 | xmalloc (sizeof (struct mips_hi_fixup))); | |
1943 | hi_fixup->fixp = fixp; | |
1944 | hi_fixup->seg = now_seg; | |
1945 | hi_fixup->next = mips_hi_fixup_list; | |
1946 | mips_hi_fixup_list = hi_fixup; | |
1947 | } | |
1948 | } | |
1949 | } | |
1950 | } | |
1951 | ||
1952 | if (! mips_opts.mips16) | |
1953 | md_number_to_chars (f, ip->insn_opcode, 4); | |
1954 | else if (reloc_type == BFD_RELOC_MIPS16_JMP) | |
1955 | { | |
1956 | md_number_to_chars (f, ip->insn_opcode >> 16, 2); | |
1957 | md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2); | |
1958 | } | |
1959 | else | |
1960 | { | |
1961 | if (ip->use_extend) | |
1962 | { | |
1963 | md_number_to_chars (f, 0xf000 | ip->extend, 2); | |
1964 | f += 2; | |
1965 | } | |
1966 | md_number_to_chars (f, ip->insn_opcode, 2); | |
1967 | } | |
1968 | ||
1969 | /* Update the register mask information. */ | |
1970 | if (! mips_opts.mips16) | |
1971 | { | |
1972 | if (pinfo & INSN_WRITE_GPR_D) | |
1973 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD); | |
1974 | if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0) | |
1975 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT); | |
1976 | if (pinfo & INSN_READ_GPR_S) | |
1977 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS); | |
1978 | if (pinfo & INSN_WRITE_GPR_31) | |
1979 | mips_gprmask |= 1 << 31; | |
1980 | if (pinfo & INSN_WRITE_FPR_D) | |
1981 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD); | |
1982 | if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0) | |
1983 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS); | |
1984 | if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0) | |
1985 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT); | |
1986 | if ((pinfo & INSN_READ_FPR_R) != 0) | |
1987 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR); | |
1988 | if (pinfo & INSN_COP) | |
1989 | { | |
bdaaa2e1 KH |
1990 | /* We don't keep enough information to sort these cases out. |
1991 | The itbl support does keep this information however, although | |
1992 | we currently don't support itbl fprmats as part of the cop | |
1993 | instruction. May want to add this support in the future. */ | |
252b5132 RH |
1994 | } |
1995 | /* Never set the bit for $0, which is always zero. */ | |
beae10d5 | 1996 | mips_gprmask &= ~1 << 0; |
252b5132 RH |
1997 | } |
1998 | else | |
1999 | { | |
2000 | if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X)) | |
2001 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX) | |
2002 | & MIPS16OP_MASK_RX); | |
2003 | if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y)) | |
2004 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY) | |
2005 | & MIPS16OP_MASK_RY); | |
2006 | if (pinfo & MIPS16_INSN_WRITE_Z) | |
2007 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ) | |
2008 | & MIPS16OP_MASK_RZ); | |
2009 | if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T)) | |
2010 | mips_gprmask |= 1 << TREG; | |
2011 | if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP)) | |
2012 | mips_gprmask |= 1 << SP; | |
2013 | if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31)) | |
2014 | mips_gprmask |= 1 << RA; | |
2015 | if (pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2016 | mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode); | |
2017 | if (pinfo & MIPS16_INSN_READ_Z) | |
2018 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
2019 | & MIPS16OP_MASK_MOVE32Z); | |
2020 | if (pinfo & MIPS16_INSN_READ_GPR_X) | |
2021 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
2022 | & MIPS16OP_MASK_REGR32); | |
2023 | } | |
2024 | ||
2025 | if (place == NULL && ! mips_opts.noreorder) | |
2026 | { | |
2027 | /* Filling the branch delay slot is more complex. We try to | |
2028 | switch the branch with the previous instruction, which we can | |
2029 | do if the previous instruction does not set up a condition | |
2030 | that the branch tests and if the branch is not itself the | |
2031 | target of any branch. */ | |
2032 | if ((pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2033 | || (pinfo & INSN_COND_BRANCH_DELAY)) | |
2034 | { | |
2035 | if (mips_optimize < 2 | |
2036 | /* If we have seen .set volatile or .set nomove, don't | |
2037 | optimize. */ | |
2038 | || mips_opts.nomove != 0 | |
2039 | /* If we had to emit any NOP instructions, then we | |
2040 | already know we can not swap. */ | |
2041 | || nops != 0 | |
2042 | /* If we don't even know the previous insn, we can not | |
bdaaa2e1 | 2043 | swap. */ |
252b5132 RH |
2044 | || ! prev_insn_valid |
2045 | /* If the previous insn is already in a branch delay | |
2046 | slot, then we can not swap. */ | |
2047 | || prev_insn_is_delay_slot | |
2048 | /* If the previous previous insn was in a .set | |
2049 | noreorder, we can't swap. Actually, the MIPS | |
2050 | assembler will swap in this situation. However, gcc | |
2051 | configured -with-gnu-as will generate code like | |
2052 | .set noreorder | |
2053 | lw $4,XXX | |
2054 | .set reorder | |
2055 | INSN | |
2056 | bne $4,$0,foo | |
2057 | in which we can not swap the bne and INSN. If gcc is | |
2058 | not configured -with-gnu-as, it does not output the | |
2059 | .set pseudo-ops. We don't have to check | |
2060 | prev_insn_unreordered, because prev_insn_valid will | |
2061 | be 0 in that case. We don't want to use | |
2062 | prev_prev_insn_valid, because we do want to be able | |
2063 | to swap at the start of a function. */ | |
2064 | || prev_prev_insn_unreordered | |
2065 | /* If the branch is itself the target of a branch, we | |
2066 | can not swap. We cheat on this; all we check for is | |
2067 | whether there is a label on this instruction. If | |
2068 | there are any branches to anything other than a | |
2069 | label, users must use .set noreorder. */ | |
2070 | || insn_labels != NULL | |
2071 | /* If the previous instruction is in a variant frag, we | |
2072 | can not do the swap. This does not apply to the | |
2073 | mips16, which uses variant frags for different | |
2074 | purposes. */ | |
2075 | || (! mips_opts.mips16 | |
2076 | && prev_insn_frag->fr_type == rs_machine_dependent) | |
2077 | /* If the branch reads the condition codes, we don't | |
2078 | even try to swap, because in the sequence | |
2079 | ctc1 $X,$31 | |
2080 | INSN | |
2081 | INSN | |
2082 | bc1t LABEL | |
2083 | we can not swap, and I don't feel like handling that | |
2084 | case. */ | |
2085 | || (! mips_opts.mips16 | |
9ce8a5dd | 2086 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2087 | && (pinfo & INSN_READ_COND_CODE)) |
2088 | /* We can not swap with an instruction that requires a | |
2089 | delay slot, becase the target of the branch might | |
2090 | interfere with that instruction. */ | |
2091 | || (! mips_opts.mips16 | |
9ce8a5dd | 2092 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 2093 | && (prev_pinfo |
bdaaa2e1 | 2094 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2095 | & (INSN_LOAD_COPROC_DELAY |
2096 | | INSN_COPROC_MOVE_DELAY | |
2097 | | INSN_WRITE_COND_CODE))) | |
2098 | || (! (hilo_interlocks | |
ec68c924 | 2099 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
2100 | && (prev_pinfo |
2101 | & (INSN_READ_LO | |
2102 | | INSN_READ_HI))) | |
2103 | || (! mips_opts.mips16 | |
2104 | && ! gpr_interlocks | |
2105 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)) | |
2106 | || (! mips_opts.mips16 | |
e7af610e | 2107 | && mips_opts.isa == ISA_MIPS1 |
bdaaa2e1 | 2108 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2109 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)) |
2110 | /* We can not swap with a branch instruction. */ | |
2111 | || (prev_pinfo | |
2112 | & (INSN_UNCOND_BRANCH_DELAY | |
2113 | | INSN_COND_BRANCH_DELAY | |
2114 | | INSN_COND_BRANCH_LIKELY)) | |
2115 | /* We do not swap with a trap instruction, since it | |
2116 | complicates trap handlers to have the trap | |
2117 | instruction be in a delay slot. */ | |
2118 | || (prev_pinfo & INSN_TRAP) | |
2119 | /* If the branch reads a register that the previous | |
2120 | instruction sets, we can not swap. */ | |
2121 | || (! mips_opts.mips16 | |
2122 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2123 | && insn_uses_reg (ip, | |
2124 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
2125 | & OP_MASK_RT), | |
2126 | MIPS_GR_REG)) | |
2127 | || (! mips_opts.mips16 | |
2128 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2129 | && insn_uses_reg (ip, | |
2130 | ((prev_insn.insn_opcode >> OP_SH_RD) | |
2131 | & OP_MASK_RD), | |
2132 | MIPS_GR_REG)) | |
2133 | || (mips_opts.mips16 | |
2134 | && (((prev_pinfo & MIPS16_INSN_WRITE_X) | |
2135 | && insn_uses_reg (ip, | |
2136 | ((prev_insn.insn_opcode | |
2137 | >> MIPS16OP_SH_RX) | |
2138 | & MIPS16OP_MASK_RX), | |
2139 | MIPS16_REG)) | |
2140 | || ((prev_pinfo & MIPS16_INSN_WRITE_Y) | |
2141 | && insn_uses_reg (ip, | |
2142 | ((prev_insn.insn_opcode | |
2143 | >> MIPS16OP_SH_RY) | |
2144 | & MIPS16OP_MASK_RY), | |
2145 | MIPS16_REG)) | |
2146 | || ((prev_pinfo & MIPS16_INSN_WRITE_Z) | |
2147 | && insn_uses_reg (ip, | |
2148 | ((prev_insn.insn_opcode | |
2149 | >> MIPS16OP_SH_RZ) | |
2150 | & MIPS16OP_MASK_RZ), | |
2151 | MIPS16_REG)) | |
2152 | || ((prev_pinfo & MIPS16_INSN_WRITE_T) | |
2153 | && insn_uses_reg (ip, TREG, MIPS_GR_REG)) | |
2154 | || ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2155 | && insn_uses_reg (ip, RA, MIPS_GR_REG)) | |
2156 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2157 | && insn_uses_reg (ip, | |
2158 | MIPS16OP_EXTRACT_REG32R (prev_insn. | |
2159 | insn_opcode), | |
2160 | MIPS_GR_REG)))) | |
2161 | /* If the branch writes a register that the previous | |
2162 | instruction sets, we can not swap (we know that | |
2163 | branches write only to RD or to $31). */ | |
2164 | || (! mips_opts.mips16 | |
2165 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2166 | && (((pinfo & INSN_WRITE_GPR_D) | |
2167 | && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT) | |
2168 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2169 | || ((pinfo & INSN_WRITE_GPR_31) | |
2170 | && (((prev_insn.insn_opcode >> OP_SH_RT) | |
2171 | & OP_MASK_RT) | |
2172 | == 31)))) | |
2173 | || (! mips_opts.mips16 | |
2174 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2175 | && (((pinfo & INSN_WRITE_GPR_D) | |
2176 | && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD) | |
2177 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2178 | || ((pinfo & INSN_WRITE_GPR_31) | |
2179 | && (((prev_insn.insn_opcode >> OP_SH_RD) | |
2180 | & OP_MASK_RD) | |
2181 | == 31)))) | |
2182 | || (mips_opts.mips16 | |
2183 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2184 | && ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2185 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2186 | && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode) | |
2187 | == RA)))) | |
2188 | /* If the branch writes a register that the previous | |
2189 | instruction reads, we can not swap (we know that | |
2190 | branches only write to RD or to $31). */ | |
2191 | || (! mips_opts.mips16 | |
2192 | && (pinfo & INSN_WRITE_GPR_D) | |
2193 | && insn_uses_reg (&prev_insn, | |
2194 | ((ip->insn_opcode >> OP_SH_RD) | |
2195 | & OP_MASK_RD), | |
2196 | MIPS_GR_REG)) | |
2197 | || (! mips_opts.mips16 | |
2198 | && (pinfo & INSN_WRITE_GPR_31) | |
2199 | && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG)) | |
2200 | || (mips_opts.mips16 | |
2201 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2202 | && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG)) | |
2203 | /* If we are generating embedded PIC code, the branch | |
2204 | might be expanded into a sequence which uses $at, so | |
2205 | we can't swap with an instruction which reads it. */ | |
2206 | || (mips_pic == EMBEDDED_PIC | |
2207 | && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG)) | |
2208 | /* If the previous previous instruction has a load | |
2209 | delay, and sets a register that the branch reads, we | |
2210 | can not swap. */ | |
2211 | || (! mips_opts.mips16 | |
9ce8a5dd | 2212 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
bdaaa2e1 | 2213 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2214 | && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY) |
2215 | || (! gpr_interlocks | |
2216 | && (prev_prev_insn.insn_mo->pinfo | |
2217 | & INSN_LOAD_MEMORY_DELAY))) | |
2218 | && insn_uses_reg (ip, | |
2219 | ((prev_prev_insn.insn_opcode >> OP_SH_RT) | |
2220 | & OP_MASK_RT), | |
2221 | MIPS_GR_REG)) | |
2222 | /* If one instruction sets a condition code and the | |
2223 | other one uses a condition code, we can not swap. */ | |
2224 | || ((pinfo & INSN_READ_COND_CODE) | |
2225 | && (prev_pinfo & INSN_WRITE_COND_CODE)) | |
2226 | || ((pinfo & INSN_WRITE_COND_CODE) | |
2227 | && (prev_pinfo & INSN_READ_COND_CODE)) | |
2228 | /* If the previous instruction uses the PC, we can not | |
2229 | swap. */ | |
2230 | || (mips_opts.mips16 | |
2231 | && (prev_pinfo & MIPS16_INSN_READ_PC)) | |
2232 | /* If the previous instruction was extended, we can not | |
2233 | swap. */ | |
2234 | || (mips_opts.mips16 && prev_insn_extended) | |
2235 | /* If the previous instruction had a fixup in mips16 | |
2236 | mode, we can not swap. This normally means that the | |
2237 | previous instruction was a 4 byte branch anyhow. */ | |
2238 | || (mips_opts.mips16 && prev_insn_fixp) | |
bdaaa2e1 KH |
2239 | /* If the previous instruction is a sync, sync.l, or |
2240 | sync.p, we can not swap. */ | |
f173e82e | 2241 | || (prev_pinfo & INSN_SYNC)) |
252b5132 RH |
2242 | { |
2243 | /* We could do even better for unconditional branches to | |
2244 | portions of this object file; we could pick up the | |
2245 | instruction at the destination, put it in the delay | |
2246 | slot, and bump the destination address. */ | |
2247 | emit_nop (); | |
2248 | /* Update the previous insn information. */ | |
2249 | prev_prev_insn = *ip; | |
2250 | prev_insn.insn_mo = &dummy_opcode; | |
2251 | } | |
2252 | else | |
2253 | { | |
2254 | /* It looks like we can actually do the swap. */ | |
2255 | if (! mips_opts.mips16) | |
2256 | { | |
2257 | char *prev_f; | |
2258 | char temp[4]; | |
2259 | ||
2260 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2261 | memcpy (temp, prev_f, 4); | |
2262 | memcpy (prev_f, f, 4); | |
2263 | memcpy (f, temp, 4); | |
2264 | if (prev_insn_fixp) | |
2265 | { | |
2266 | prev_insn_fixp->fx_frag = frag_now; | |
2267 | prev_insn_fixp->fx_where = f - frag_now->fr_literal; | |
2268 | } | |
2269 | if (fixp) | |
2270 | { | |
2271 | fixp->fx_frag = prev_insn_frag; | |
2272 | fixp->fx_where = prev_insn_where; | |
2273 | } | |
2274 | } | |
2275 | else | |
2276 | { | |
2277 | char *prev_f; | |
2278 | char temp[2]; | |
2279 | ||
2280 | assert (prev_insn_fixp == NULL); | |
2281 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2282 | memcpy (temp, prev_f, 2); | |
2283 | memcpy (prev_f, f, 2); | |
2284 | if (reloc_type != BFD_RELOC_MIPS16_JMP) | |
2285 | { | |
2286 | assert (reloc_type == BFD_RELOC_UNUSED); | |
2287 | memcpy (f, temp, 2); | |
2288 | } | |
2289 | else | |
2290 | { | |
2291 | memcpy (f, f + 2, 2); | |
2292 | memcpy (f + 2, temp, 2); | |
2293 | } | |
2294 | if (fixp) | |
2295 | { | |
2296 | fixp->fx_frag = prev_insn_frag; | |
2297 | fixp->fx_where = prev_insn_where; | |
2298 | } | |
2299 | } | |
2300 | ||
2301 | /* Update the previous insn information; leave prev_insn | |
2302 | unchanged. */ | |
2303 | prev_prev_insn = *ip; | |
2304 | } | |
2305 | prev_insn_is_delay_slot = 1; | |
2306 | ||
2307 | /* If that was an unconditional branch, forget the previous | |
2308 | insn information. */ | |
2309 | if (pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2310 | { | |
2311 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2312 | prev_insn.insn_mo = &dummy_opcode; | |
2313 | } | |
2314 | ||
2315 | prev_insn_fixp = NULL; | |
2316 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2317 | prev_insn_extended = 0; | |
2318 | } | |
2319 | else if (pinfo & INSN_COND_BRANCH_LIKELY) | |
2320 | { | |
2321 | /* We don't yet optimize a branch likely. What we should do | |
2322 | is look at the target, copy the instruction found there | |
2323 | into the delay slot, and increment the branch to jump to | |
2324 | the next instruction. */ | |
2325 | emit_nop (); | |
2326 | /* Update the previous insn information. */ | |
2327 | prev_prev_insn = *ip; | |
2328 | prev_insn.insn_mo = &dummy_opcode; | |
2329 | prev_insn_fixp = NULL; | |
2330 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2331 | prev_insn_extended = 0; | |
2332 | } | |
2333 | else | |
2334 | { | |
2335 | /* Update the previous insn information. */ | |
2336 | if (nops > 0) | |
2337 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2338 | else | |
2339 | prev_prev_insn = prev_insn; | |
2340 | prev_insn = *ip; | |
2341 | ||
2342 | /* Any time we see a branch, we always fill the delay slot | |
2343 | immediately; since this insn is not a branch, we know it | |
2344 | is not in a delay slot. */ | |
2345 | prev_insn_is_delay_slot = 0; | |
2346 | ||
2347 | prev_insn_fixp = fixp; | |
2348 | prev_insn_reloc_type = reloc_type; | |
2349 | if (mips_opts.mips16) | |
2350 | prev_insn_extended = (ip->use_extend | |
2351 | || reloc_type > BFD_RELOC_UNUSED); | |
2352 | } | |
2353 | ||
2354 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2355 | prev_insn_unreordered = 0; | |
2356 | prev_insn_frag = frag_now; | |
2357 | prev_insn_where = f - frag_now->fr_literal; | |
2358 | prev_insn_valid = 1; | |
2359 | } | |
2360 | else if (place == NULL) | |
2361 | { | |
2362 | /* We need to record a bit of information even when we are not | |
2363 | reordering, in order to determine the base address for mips16 | |
2364 | PC relative relocs. */ | |
2365 | prev_prev_insn = prev_insn; | |
2366 | prev_insn = *ip; | |
2367 | prev_insn_reloc_type = reloc_type; | |
2368 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2369 | prev_insn_unreordered = 1; | |
2370 | } | |
2371 | ||
2372 | /* We just output an insn, so the next one doesn't have a label. */ | |
2373 | mips_clear_insn_labels (); | |
2374 | ||
2375 | /* We must ensure that a fixup associated with an unmatched %hi | |
2376 | reloc does not become a variant frag. Otherwise, the | |
2377 | rearrangement of %hi relocs in frob_file may confuse | |
2378 | tc_gen_reloc. */ | |
2379 | if (unmatched_hi) | |
2380 | { | |
2381 | frag_wane (frag_now); | |
2382 | frag_new (0); | |
2383 | } | |
2384 | } | |
2385 | ||
2386 | /* This function forgets that there was any previous instruction or | |
2387 | label. If PRESERVE is non-zero, it remembers enough information to | |
bdaaa2e1 | 2388 | know whether nops are needed before a noreorder section. */ |
252b5132 RH |
2389 | |
2390 | static void | |
2391 | mips_no_prev_insn (preserve) | |
2392 | int preserve; | |
2393 | { | |
2394 | if (! preserve) | |
2395 | { | |
2396 | prev_insn.insn_mo = &dummy_opcode; | |
2397 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2398 | prev_nop_frag = NULL; | |
2399 | prev_nop_frag_holds = 0; | |
2400 | prev_nop_frag_required = 0; | |
2401 | prev_nop_frag_since = 0; | |
2402 | } | |
2403 | prev_insn_valid = 0; | |
2404 | prev_insn_is_delay_slot = 0; | |
2405 | prev_insn_unreordered = 0; | |
2406 | prev_insn_extended = 0; | |
2407 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2408 | prev_prev_insn_unreordered = 0; | |
2409 | mips_clear_insn_labels (); | |
2410 | } | |
2411 | ||
2412 | /* This function must be called whenever we turn on noreorder or emit | |
2413 | something other than instructions. It inserts any NOPS which might | |
2414 | be needed by the previous instruction, and clears the information | |
2415 | kept for the previous instructions. The INSNS parameter is true if | |
bdaaa2e1 | 2416 | instructions are to follow. */ |
252b5132 RH |
2417 | |
2418 | static void | |
2419 | mips_emit_delays (insns) | |
2420 | boolean insns; | |
2421 | { | |
2422 | if (! mips_opts.noreorder) | |
2423 | { | |
2424 | int nops; | |
2425 | ||
2426 | nops = 0; | |
2427 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2428 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2429 | && (! cop_interlocks |
2430 | && (prev_insn.insn_mo->pinfo | |
2431 | & (INSN_LOAD_COPROC_DELAY | |
2432 | | INSN_COPROC_MOVE_DELAY | |
2433 | | INSN_WRITE_COND_CODE)))) | |
2434 | || (! hilo_interlocks | |
2435 | && (prev_insn.insn_mo->pinfo | |
2436 | & (INSN_READ_LO | |
2437 | | INSN_READ_HI))) | |
2438 | || (! mips_opts.mips16 | |
2439 | && ! gpr_interlocks | |
bdaaa2e1 | 2440 | && (prev_insn.insn_mo->pinfo |
252b5132 RH |
2441 | & INSN_LOAD_MEMORY_DELAY)) |
2442 | || (! mips_opts.mips16 | |
e7af610e | 2443 | && mips_opts.isa == ISA_MIPS1 |
252b5132 RH |
2444 | && (prev_insn.insn_mo->pinfo |
2445 | & INSN_COPROC_MEMORY_DELAY))) | |
2446 | { | |
beae10d5 | 2447 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2448 | ++nops; |
2449 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2450 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2451 | && (! cop_interlocks |
2452 | && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2453 | || (! hilo_interlocks | |
2454 | && ((prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2455 | || (prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2456 | ++nops; | |
2457 | ||
2458 | if (prev_insn_unreordered) | |
2459 | nops = 0; | |
2460 | } | |
2461 | else if ((! mips_opts.mips16 | |
9ce8a5dd | 2462 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2463 | && (! cop_interlocks |
2464 | && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2465 | || (! hilo_interlocks | |
2466 | && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2467 | || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2468 | { | |
beae10d5 | 2469 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2470 | if (! prev_prev_insn_unreordered) |
2471 | ++nops; | |
2472 | } | |
2473 | ||
2474 | if (nops > 0) | |
2475 | { | |
2476 | struct insn_label_list *l; | |
2477 | ||
2478 | if (insns) | |
2479 | { | |
2480 | /* Record the frag which holds the nop instructions, so | |
2481 | that we can remove them if we don't need them. */ | |
2482 | frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4); | |
2483 | prev_nop_frag = frag_now; | |
2484 | prev_nop_frag_holds = nops; | |
2485 | prev_nop_frag_required = 0; | |
2486 | prev_nop_frag_since = 0; | |
2487 | } | |
2488 | ||
2489 | for (; nops > 0; --nops) | |
2490 | emit_nop (); | |
2491 | ||
2492 | if (insns) | |
2493 | { | |
2494 | /* Move on to a new frag, so that it is safe to simply | |
bdaaa2e1 | 2495 | decrease the size of prev_nop_frag. */ |
252b5132 RH |
2496 | frag_wane (frag_now); |
2497 | frag_new (0); | |
2498 | } | |
2499 | ||
2500 | for (l = insn_labels; l != NULL; l = l->next) | |
2501 | { | |
98aa84af AM |
2502 | valueT val; |
2503 | ||
252b5132 | 2504 | assert (S_GET_SEGMENT (l->label) == now_seg); |
49309057 | 2505 | symbol_set_frag (l->label, frag_now); |
98aa84af | 2506 | val = (valueT) frag_now_fix (); |
252b5132 RH |
2507 | /* mips16 text labels are stored as odd. */ |
2508 | if (mips_opts.mips16) | |
98aa84af AM |
2509 | val += 1; |
2510 | S_SET_VALUE (l->label, val); | |
252b5132 RH |
2511 | } |
2512 | } | |
2513 | } | |
2514 | ||
2515 | /* Mark instruction labels in mips16 mode. */ | |
2516 | if (mips_opts.mips16 && insns) | |
2517 | mips16_mark_labels (); | |
2518 | ||
2519 | mips_no_prev_insn (insns); | |
2520 | } | |
2521 | ||
2522 | /* Build an instruction created by a macro expansion. This is passed | |
2523 | a pointer to the count of instructions created so far, an | |
2524 | expression, the name of the instruction to build, an operand format | |
2525 | string, and corresponding arguments. */ | |
2526 | ||
2527 | #ifdef USE_STDARG | |
2528 | static void | |
2529 | macro_build (char *place, | |
2530 | int *counter, | |
2531 | expressionS * ep, | |
2532 | const char *name, | |
2533 | const char *fmt, | |
2534 | ...) | |
2535 | #else | |
2536 | static void | |
2537 | macro_build (place, counter, ep, name, fmt, va_alist) | |
2538 | char *place; | |
2539 | int *counter; | |
2540 | expressionS *ep; | |
2541 | const char *name; | |
2542 | const char *fmt; | |
2543 | va_dcl | |
2544 | #endif | |
2545 | { | |
2546 | struct mips_cl_insn insn; | |
2547 | bfd_reloc_code_real_type r; | |
2548 | va_list args; | |
252b5132 RH |
2549 | |
2550 | #ifdef USE_STDARG | |
2551 | va_start (args, fmt); | |
2552 | #else | |
2553 | va_start (args); | |
2554 | #endif | |
2555 | ||
2556 | /* | |
2557 | * If the macro is about to expand into a second instruction, | |
2558 | * print a warning if needed. We need to pass ip as a parameter | |
2559 | * to generate a better warning message here... | |
2560 | */ | |
2561 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2562 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2563 | ||
2564 | if (place == NULL) | |
2565 | *counter += 1; /* bump instruction counter */ | |
2566 | ||
2567 | if (mips_opts.mips16) | |
2568 | { | |
2569 | mips16_macro_build (place, counter, ep, name, fmt, args); | |
2570 | va_end (args); | |
2571 | return; | |
2572 | } | |
2573 | ||
2574 | r = BFD_RELOC_UNUSED; | |
2575 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
2576 | assert (insn.insn_mo); | |
2577 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2578 | ||
2579 | /* Search until we get a match for NAME. */ | |
2580 | while (1) | |
2581 | { | |
252b5132 RH |
2582 | if (strcmp (fmt, insn.insn_mo->args) == 0 |
2583 | && insn.insn_mo->pinfo != INSN_MACRO | |
ea1fb5dc | 2584 | && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch) |
ec68c924 | 2585 | && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0)) |
252b5132 RH |
2586 | break; |
2587 | ||
2588 | ++insn.insn_mo; | |
2589 | assert (insn.insn_mo->name); | |
2590 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2591 | } | |
2592 | ||
2593 | insn.insn_opcode = insn.insn_mo->match; | |
2594 | for (;;) | |
2595 | { | |
2596 | switch (*fmt++) | |
2597 | { | |
2598 | case '\0': | |
2599 | break; | |
2600 | ||
2601 | case ',': | |
2602 | case '(': | |
2603 | case ')': | |
2604 | continue; | |
2605 | ||
2606 | case 't': | |
2607 | case 'w': | |
2608 | case 'E': | |
38487616 | 2609 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RT; |
252b5132 RH |
2610 | continue; |
2611 | ||
2612 | case 'c': | |
38487616 TS |
2613 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE; |
2614 | continue; | |
2615 | ||
252b5132 RH |
2616 | case 'T': |
2617 | case 'W': | |
38487616 | 2618 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FT; |
252b5132 RH |
2619 | continue; |
2620 | ||
2621 | case 'd': | |
2622 | case 'G': | |
38487616 | 2623 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RD; |
252b5132 RH |
2624 | continue; |
2625 | ||
4372b673 NC |
2626 | case 'U': |
2627 | { | |
2628 | int tmp = va_arg (args, int); | |
2629 | ||
38487616 TS |
2630 | insn.insn_opcode |= tmp << OP_SH_RT; |
2631 | insn.insn_opcode |= tmp << OP_SH_RD; | |
beae10d5 | 2632 | continue; |
4372b673 NC |
2633 | } |
2634 | ||
252b5132 RH |
2635 | case 'V': |
2636 | case 'S': | |
38487616 | 2637 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FS; |
252b5132 RH |
2638 | continue; |
2639 | ||
2640 | case 'z': | |
2641 | continue; | |
2642 | ||
2643 | case '<': | |
38487616 | 2644 | insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT; |
252b5132 RH |
2645 | continue; |
2646 | ||
2647 | case 'D': | |
38487616 | 2648 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FD; |
252b5132 RH |
2649 | continue; |
2650 | ||
2651 | case 'B': | |
38487616 | 2652 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20; |
252b5132 RH |
2653 | continue; |
2654 | ||
4372b673 | 2655 | case 'J': |
38487616 | 2656 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19; |
4372b673 NC |
2657 | continue; |
2658 | ||
252b5132 | 2659 | case 'q': |
38487616 | 2660 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2; |
252b5132 RH |
2661 | continue; |
2662 | ||
2663 | case 'b': | |
2664 | case 's': | |
2665 | case 'r': | |
2666 | case 'v': | |
38487616 | 2667 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RS; |
252b5132 RH |
2668 | continue; |
2669 | ||
2670 | case 'i': | |
2671 | case 'j': | |
2672 | case 'o': | |
2673 | r = (bfd_reloc_code_real_type) va_arg (args, int); | |
2674 | assert (r == BFD_RELOC_MIPS_GPREL | |
2675 | || r == BFD_RELOC_MIPS_LITERAL | |
2676 | || r == BFD_RELOC_LO16 | |
2677 | || r == BFD_RELOC_MIPS_GOT16 | |
2678 | || r == BFD_RELOC_MIPS_CALL16 | |
2679 | || r == BFD_RELOC_MIPS_GOT_LO16 | |
2680 | || r == BFD_RELOC_MIPS_CALL_LO16 | |
2681 | || (ep->X_op == O_subtract | |
252b5132 RH |
2682 | && r == BFD_RELOC_PCREL_LO16)); |
2683 | continue; | |
2684 | ||
2685 | case 'u': | |
2686 | r = (bfd_reloc_code_real_type) va_arg (args, int); | |
2687 | assert (ep != NULL | |
2688 | && (ep->X_op == O_constant | |
2689 | || (ep->X_op == O_symbol | |
2690 | && (r == BFD_RELOC_HI16_S | |
2691 | || r == BFD_RELOC_HI16 | |
2692 | || r == BFD_RELOC_MIPS_GOT_HI16 | |
2693 | || r == BFD_RELOC_MIPS_CALL_HI16)) | |
2694 | || (ep->X_op == O_subtract | |
252b5132 RH |
2695 | && r == BFD_RELOC_PCREL_HI16_S))); |
2696 | if (ep->X_op == O_constant) | |
2697 | { | |
2698 | insn.insn_opcode |= (ep->X_add_number >> 16) & 0xffff; | |
2699 | ep = NULL; | |
2700 | r = BFD_RELOC_UNUSED; | |
2701 | } | |
2702 | continue; | |
2703 | ||
2704 | case 'p': | |
2705 | assert (ep != NULL); | |
2706 | /* | |
2707 | * This allows macro() to pass an immediate expression for | |
2708 | * creating short branches without creating a symbol. | |
2709 | * Note that the expression still might come from the assembly | |
2710 | * input, in which case the value is not checked for range nor | |
2711 | * is a relocation entry generated (yuck). | |
2712 | */ | |
2713 | if (ep->X_op == O_constant) | |
2714 | { | |
2715 | insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff; | |
2716 | ep = NULL; | |
2717 | } | |
2718 | else | |
cb56d3d3 TS |
2719 | if (mips_pic == EMBEDDED_PIC) |
2720 | r = BFD_RELOC_16_PCREL_S2; | |
2721 | else | |
2722 | r = BFD_RELOC_16_PCREL; | |
252b5132 RH |
2723 | continue; |
2724 | ||
2725 | case 'a': | |
2726 | assert (ep != NULL); | |
2727 | r = BFD_RELOC_MIPS_JMP; | |
2728 | continue; | |
2729 | ||
2730 | case 'C': | |
2731 | insn.insn_opcode |= va_arg (args, unsigned long); | |
2732 | continue; | |
2733 | ||
2734 | default: | |
2735 | internalError (); | |
2736 | } | |
2737 | break; | |
2738 | } | |
2739 | va_end (args); | |
2740 | assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); | |
2741 | ||
2742 | append_insn (place, &insn, ep, r, false); | |
2743 | } | |
2744 | ||
2745 | static void | |
2746 | mips16_macro_build (place, counter, ep, name, fmt, args) | |
2747 | char *place; | |
43841e91 | 2748 | int *counter ATTRIBUTE_UNUSED; |
252b5132 RH |
2749 | expressionS *ep; |
2750 | const char *name; | |
2751 | const char *fmt; | |
2752 | va_list args; | |
2753 | { | |
2754 | struct mips_cl_insn insn; | |
2755 | bfd_reloc_code_real_type r; | |
2756 | ||
2757 | r = BFD_RELOC_UNUSED; | |
2758 | insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name); | |
2759 | assert (insn.insn_mo); | |
2760 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2761 | ||
2762 | while (strcmp (fmt, insn.insn_mo->args) != 0 | |
2763 | || insn.insn_mo->pinfo == INSN_MACRO) | |
2764 | { | |
2765 | ++insn.insn_mo; | |
2766 | assert (insn.insn_mo->name); | |
2767 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2768 | } | |
2769 | ||
2770 | insn.insn_opcode = insn.insn_mo->match; | |
2771 | insn.use_extend = false; | |
2772 | ||
2773 | for (;;) | |
2774 | { | |
2775 | int c; | |
2776 | ||
2777 | c = *fmt++; | |
2778 | switch (c) | |
2779 | { | |
2780 | case '\0': | |
2781 | break; | |
2782 | ||
2783 | case ',': | |
2784 | case '(': | |
2785 | case ')': | |
2786 | continue; | |
2787 | ||
2788 | case 'y': | |
2789 | case 'w': | |
2790 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY; | |
2791 | continue; | |
2792 | ||
2793 | case 'x': | |
2794 | case 'v': | |
2795 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX; | |
2796 | continue; | |
2797 | ||
2798 | case 'z': | |
2799 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ; | |
2800 | continue; | |
2801 | ||
2802 | case 'Z': | |
2803 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z; | |
2804 | continue; | |
2805 | ||
2806 | case '0': | |
2807 | case 'S': | |
2808 | case 'P': | |
2809 | case 'R': | |
2810 | continue; | |
2811 | ||
2812 | case 'X': | |
2813 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32; | |
2814 | continue; | |
2815 | ||
2816 | case 'Y': | |
2817 | { | |
2818 | int regno; | |
2819 | ||
2820 | regno = va_arg (args, int); | |
2821 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
2822 | insn.insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
2823 | } | |
2824 | continue; | |
2825 | ||
2826 | case '<': | |
2827 | case '>': | |
2828 | case '4': | |
2829 | case '5': | |
2830 | case 'H': | |
2831 | case 'W': | |
2832 | case 'D': | |
2833 | case 'j': | |
2834 | case '8': | |
2835 | case 'V': | |
2836 | case 'C': | |
2837 | case 'U': | |
2838 | case 'k': | |
2839 | case 'K': | |
2840 | case 'p': | |
2841 | case 'q': | |
2842 | { | |
2843 | assert (ep != NULL); | |
2844 | ||
2845 | if (ep->X_op != O_constant) | |
2846 | r = BFD_RELOC_UNUSED + c; | |
2847 | else | |
2848 | { | |
2849 | mips16_immed ((char *) NULL, 0, c, ep->X_add_number, false, | |
2850 | false, false, &insn.insn_opcode, | |
2851 | &insn.use_extend, &insn.extend); | |
2852 | ep = NULL; | |
2853 | r = BFD_RELOC_UNUSED; | |
2854 | } | |
2855 | } | |
2856 | continue; | |
2857 | ||
2858 | case '6': | |
2859 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6; | |
2860 | continue; | |
2861 | } | |
2862 | ||
2863 | break; | |
2864 | } | |
2865 | ||
2866 | assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); | |
2867 | ||
2868 | append_insn (place, &insn, ep, r, false); | |
2869 | } | |
2870 | ||
2871 | /* | |
2872 | * Generate a "lui" instruction. | |
2873 | */ | |
2874 | static void | |
2875 | macro_build_lui (place, counter, ep, regnum) | |
2876 | char *place; | |
2877 | int *counter; | |
2878 | expressionS *ep; | |
2879 | int regnum; | |
2880 | { | |
2881 | expressionS high_expr; | |
2882 | struct mips_cl_insn insn; | |
2883 | bfd_reloc_code_real_type r; | |
2884 | CONST char *name = "lui"; | |
2885 | CONST char *fmt = "t,u"; | |
2886 | ||
2887 | assert (! mips_opts.mips16); | |
2888 | ||
2889 | if (place == NULL) | |
2890 | high_expr = *ep; | |
2891 | else | |
2892 | { | |
2893 | high_expr.X_op = O_constant; | |
2894 | high_expr.X_add_number = ep->X_add_number; | |
2895 | } | |
2896 | ||
2897 | if (high_expr.X_op == O_constant) | |
2898 | { | |
2899 | /* we can compute the instruction now without a relocation entry */ | |
e7d556df TS |
2900 | high_expr.X_add_number = ((high_expr.X_add_number + 0x8000) |
2901 | >> 16) & 0xffff; | |
252b5132 RH |
2902 | r = BFD_RELOC_UNUSED; |
2903 | } | |
2904 | else | |
2905 | { | |
2906 | assert (ep->X_op == O_symbol); | |
2907 | /* _gp_disp is a special case, used from s_cpload. */ | |
2908 | assert (mips_pic == NO_PIC | |
2909 | || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0); | |
2910 | r = BFD_RELOC_HI16_S; | |
2911 | } | |
2912 | ||
2913 | /* | |
2914 | * If the macro is about to expand into a second instruction, | |
2915 | * print a warning if needed. We need to pass ip as a parameter | |
2916 | * to generate a better warning message here... | |
2917 | */ | |
2918 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2919 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2920 | ||
2921 | if (place == NULL) | |
2922 | *counter += 1; /* bump instruction counter */ | |
2923 | ||
2924 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
2925 | assert (insn.insn_mo); | |
2926 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2927 | assert (strcmp (fmt, insn.insn_mo->args) == 0); | |
2928 | ||
2929 | insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT); | |
2930 | if (r == BFD_RELOC_UNUSED) | |
2931 | { | |
2932 | insn.insn_opcode |= high_expr.X_add_number; | |
2933 | append_insn (place, &insn, NULL, r, false); | |
2934 | } | |
2935 | else | |
2936 | append_insn (place, &insn, &high_expr, r, false); | |
2937 | } | |
2938 | ||
2939 | /* set_at() | |
2940 | * Generates code to set the $at register to true (one) | |
2941 | * if reg is less than the immediate expression. | |
2942 | */ | |
2943 | static void | |
2944 | set_at (counter, reg, unsignedp) | |
2945 | int *counter; | |
2946 | int reg; | |
2947 | int unsignedp; | |
2948 | { | |
2949 | if (imm_expr.X_op == O_constant | |
2950 | && imm_expr.X_add_number >= -0x8000 | |
2951 | && imm_expr.X_add_number < 0x8000) | |
2952 | macro_build ((char *) NULL, counter, &imm_expr, | |
2953 | unsignedp ? "sltiu" : "slti", | |
2954 | "t,r,j", AT, reg, (int) BFD_RELOC_LO16); | |
2955 | else | |
2956 | { | |
2957 | load_register (counter, AT, &imm_expr, 0); | |
2958 | macro_build ((char *) NULL, counter, NULL, | |
2959 | unsignedp ? "sltu" : "slt", | |
2960 | "d,v,t", AT, reg, AT); | |
2961 | } | |
2962 | } | |
2963 | ||
2964 | /* Warn if an expression is not a constant. */ | |
2965 | ||
2966 | static void | |
2967 | check_absolute_expr (ip, ex) | |
2968 | struct mips_cl_insn *ip; | |
2969 | expressionS *ex; | |
2970 | { | |
2971 | if (ex->X_op == O_big) | |
2972 | as_bad (_("unsupported large constant")); | |
2973 | else if (ex->X_op != O_constant) | |
2974 | as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name); | |
2975 | } | |
2976 | ||
2977 | /* Count the leading zeroes by performing a binary chop. This is a | |
2978 | bulky bit of source, but performance is a LOT better for the | |
2979 | majority of values than a simple loop to count the bits: | |
2980 | for (lcnt = 0; (lcnt < 32); lcnt++) | |
2981 | if ((v) & (1 << (31 - lcnt))) | |
2982 | break; | |
2983 | However it is not code size friendly, and the gain will drop a bit | |
2984 | on certain cached systems. | |
2985 | */ | |
2986 | #define COUNT_TOP_ZEROES(v) \ | |
2987 | (((v) & ~0xffff) == 0 \ | |
2988 | ? ((v) & ~0xff) == 0 \ | |
2989 | ? ((v) & ~0xf) == 0 \ | |
2990 | ? ((v) & ~0x3) == 0 \ | |
2991 | ? ((v) & ~0x1) == 0 \ | |
2992 | ? !(v) \ | |
2993 | ? 32 \ | |
2994 | : 31 \ | |
2995 | : 30 \ | |
2996 | : ((v) & ~0x7) == 0 \ | |
2997 | ? 29 \ | |
2998 | : 28 \ | |
2999 | : ((v) & ~0x3f) == 0 \ | |
3000 | ? ((v) & ~0x1f) == 0 \ | |
3001 | ? 27 \ | |
3002 | : 26 \ | |
3003 | : ((v) & ~0x7f) == 0 \ | |
3004 | ? 25 \ | |
3005 | : 24 \ | |
3006 | : ((v) & ~0xfff) == 0 \ | |
3007 | ? ((v) & ~0x3ff) == 0 \ | |
3008 | ? ((v) & ~0x1ff) == 0 \ | |
3009 | ? 23 \ | |
3010 | : 22 \ | |
3011 | : ((v) & ~0x7ff) == 0 \ | |
3012 | ? 21 \ | |
3013 | : 20 \ | |
3014 | : ((v) & ~0x3fff) == 0 \ | |
3015 | ? ((v) & ~0x1fff) == 0 \ | |
3016 | ? 19 \ | |
3017 | : 18 \ | |
3018 | : ((v) & ~0x7fff) == 0 \ | |
3019 | ? 17 \ | |
3020 | : 16 \ | |
3021 | : ((v) & ~0xffffff) == 0 \ | |
3022 | ? ((v) & ~0xfffff) == 0 \ | |
3023 | ? ((v) & ~0x3ffff) == 0 \ | |
3024 | ? ((v) & ~0x1ffff) == 0 \ | |
3025 | ? 15 \ | |
3026 | : 14 \ | |
3027 | : ((v) & ~0x7ffff) == 0 \ | |
3028 | ? 13 \ | |
3029 | : 12 \ | |
3030 | : ((v) & ~0x3fffff) == 0 \ | |
3031 | ? ((v) & ~0x1fffff) == 0 \ | |
3032 | ? 11 \ | |
3033 | : 10 \ | |
3034 | : ((v) & ~0x7fffff) == 0 \ | |
3035 | ? 9 \ | |
3036 | : 8 \ | |
3037 | : ((v) & ~0xfffffff) == 0 \ | |
3038 | ? ((v) & ~0x3ffffff) == 0 \ | |
3039 | ? ((v) & ~0x1ffffff) == 0 \ | |
3040 | ? 7 \ | |
3041 | : 6 \ | |
3042 | : ((v) & ~0x7ffffff) == 0 \ | |
3043 | ? 5 \ | |
3044 | : 4 \ | |
3045 | : ((v) & ~0x3fffffff) == 0 \ | |
3046 | ? ((v) & ~0x1fffffff) == 0 \ | |
3047 | ? 3 \ | |
3048 | : 2 \ | |
3049 | : ((v) & ~0x7fffffff) == 0 \ | |
3050 | ? 1 \ | |
3051 | : 0) | |
3052 | ||
3053 | /* load_register() | |
3054 | * This routine generates the least number of instructions neccessary to load | |
3055 | * an absolute expression value into a register. | |
3056 | */ | |
3057 | static void | |
3058 | load_register (counter, reg, ep, dbl) | |
3059 | int *counter; | |
3060 | int reg; | |
3061 | expressionS *ep; | |
3062 | int dbl; | |
3063 | { | |
3064 | int freg; | |
3065 | expressionS hi32, lo32; | |
3066 | ||
3067 | if (ep->X_op != O_big) | |
3068 | { | |
3069 | assert (ep->X_op == O_constant); | |
3070 | if (ep->X_add_number < 0x8000 | |
3071 | && (ep->X_add_number >= 0 | |
3072 | || (ep->X_add_number >= -0x8000 | |
3073 | && (! dbl | |
3074 | || ! ep->X_unsigned | |
3075 | || sizeof (ep->X_add_number) > 4)))) | |
3076 | { | |
3077 | /* We can handle 16 bit signed values with an addiu to | |
3078 | $zero. No need to ever use daddiu here, since $zero and | |
3079 | the result are always correct in 32 bit mode. */ | |
3080 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3081 | (int) BFD_RELOC_LO16); | |
3082 | return; | |
3083 | } | |
3084 | else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000) | |
3085 | { | |
3086 | /* We can handle 16 bit unsigned values with an ori to | |
3087 | $zero. */ | |
3088 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0, | |
3089 | (int) BFD_RELOC_LO16); | |
3090 | return; | |
3091 | } | |
3092 | else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0 | |
3093 | || ((ep->X_add_number &~ (offsetT) 0x7fffffff) | |
3094 | == ~ (offsetT) 0x7fffffff)) | |
3095 | && (! dbl | |
3096 | || ! ep->X_unsigned | |
3097 | || sizeof (ep->X_add_number) > 4 | |
3098 | || (ep->X_add_number & 0x80000000) == 0)) | |
ca4e0257 | 3099 | || ((HAVE_32BIT_GPRS || ! dbl) |
252b5132 | 3100 | && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0) |
ca4e0257 | 3101 | || (HAVE_32BIT_GPRS |
252b5132 RH |
3102 | && ! dbl |
3103 | && ((ep->X_add_number &~ (offsetT) 0xffffffff) | |
3104 | == ~ (offsetT) 0xffffffff))) | |
3105 | { | |
3106 | /* 32 bit values require an lui. */ | |
3107 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3108 | (int) BFD_RELOC_HI16); | |
3109 | if ((ep->X_add_number & 0xffff) != 0) | |
3110 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg, | |
3111 | (int) BFD_RELOC_LO16); | |
3112 | return; | |
3113 | } | |
3114 | } | |
3115 | ||
3116 | /* The value is larger than 32 bits. */ | |
3117 | ||
ca4e0257 | 3118 | if (HAVE_32BIT_GPRS) |
252b5132 RH |
3119 | { |
3120 | as_bad (_("Number larger than 32 bits")); | |
3121 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3122 | (int) BFD_RELOC_LO16); | |
3123 | return; | |
3124 | } | |
3125 | ||
3126 | if (ep->X_op != O_big) | |
3127 | { | |
3128 | hi32 = *ep; | |
3129 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3130 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3131 | hi32.X_add_number &= 0xffffffff; | |
3132 | lo32 = *ep; | |
3133 | lo32.X_add_number &= 0xffffffff; | |
3134 | } | |
3135 | else | |
3136 | { | |
3137 | assert (ep->X_add_number > 2); | |
3138 | if (ep->X_add_number == 3) | |
3139 | generic_bignum[3] = 0; | |
3140 | else if (ep->X_add_number > 4) | |
3141 | as_bad (_("Number larger than 64 bits")); | |
3142 | lo32.X_op = O_constant; | |
3143 | lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16); | |
3144 | hi32.X_op = O_constant; | |
3145 | hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16); | |
3146 | } | |
3147 | ||
3148 | if (hi32.X_add_number == 0) | |
3149 | freg = 0; | |
3150 | else | |
3151 | { | |
3152 | int shift, bit; | |
3153 | unsigned long hi, lo; | |
3154 | ||
3155 | if (hi32.X_add_number == 0xffffffff) | |
beae10d5 KH |
3156 | { |
3157 | if ((lo32.X_add_number & 0xffff8000) == 0xffff8000) | |
3158 | { | |
3159 | macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j", | |
252b5132 | 3160 | reg, 0, (int) BFD_RELOC_LO16); |
beae10d5 KH |
3161 | return; |
3162 | } | |
3163 | if (lo32.X_add_number & 0x80000000) | |
3164 | { | |
3165 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, | |
3166 | (int) BFD_RELOC_HI16); | |
252b5132 RH |
3167 | if (lo32.X_add_number & 0xffff) |
3168 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", | |
3169 | reg, reg, (int) BFD_RELOC_LO16); | |
beae10d5 KH |
3170 | return; |
3171 | } | |
3172 | } | |
252b5132 RH |
3173 | |
3174 | /* Check for 16bit shifted constant. We know that hi32 is | |
3175 | non-zero, so start the mask on the first bit of the hi32 | |
3176 | value. */ | |
3177 | shift = 17; | |
3178 | do | |
beae10d5 KH |
3179 | { |
3180 | unsigned long himask, lomask; | |
3181 | ||
3182 | if (shift < 32) | |
3183 | { | |
3184 | himask = 0xffff >> (32 - shift); | |
3185 | lomask = (0xffff << shift) & 0xffffffff; | |
3186 | } | |
3187 | else | |
3188 | { | |
3189 | himask = 0xffff << (shift - 32); | |
3190 | lomask = 0; | |
3191 | } | |
3192 | if ((hi32.X_add_number & ~(offsetT) himask) == 0 | |
3193 | && (lo32.X_add_number & ~(offsetT) lomask) == 0) | |
3194 | { | |
3195 | expressionS tmp; | |
3196 | ||
3197 | tmp.X_op = O_constant; | |
3198 | if (shift < 32) | |
3199 | tmp.X_add_number = ((hi32.X_add_number << (32 - shift)) | |
3200 | | (lo32.X_add_number >> shift)); | |
3201 | else | |
3202 | tmp.X_add_number = hi32.X_add_number >> (shift - 32); | |
3203 | macro_build ((char *) NULL, counter, &tmp, | |
3204 | "ori", "t,r,i", reg, 0, | |
3205 | (int) BFD_RELOC_LO16); | |
3206 | macro_build ((char *) NULL, counter, NULL, | |
3207 | (shift >= 32) ? "dsll32" : "dsll", | |
3208 | "d,w,<", reg, reg, | |
3209 | (shift >= 32) ? shift - 32 : shift); | |
3210 | return; | |
3211 | } | |
3212 | shift++; | |
3213 | } | |
3214 | while (shift <= (64 - 16)); | |
252b5132 RH |
3215 | |
3216 | /* Find the bit number of the lowest one bit, and store the | |
3217 | shifted value in hi/lo. */ | |
3218 | hi = (unsigned long) (hi32.X_add_number & 0xffffffff); | |
3219 | lo = (unsigned long) (lo32.X_add_number & 0xffffffff); | |
3220 | if (lo != 0) | |
3221 | { | |
3222 | bit = 0; | |
3223 | while ((lo & 1) == 0) | |
3224 | { | |
3225 | lo >>= 1; | |
3226 | ++bit; | |
3227 | } | |
3228 | lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit); | |
3229 | hi >>= bit; | |
3230 | } | |
3231 | else | |
3232 | { | |
3233 | bit = 32; | |
3234 | while ((hi & 1) == 0) | |
3235 | { | |
3236 | hi >>= 1; | |
3237 | ++bit; | |
3238 | } | |
3239 | lo = hi; | |
3240 | hi = 0; | |
3241 | } | |
3242 | ||
3243 | /* Optimize if the shifted value is a (power of 2) - 1. */ | |
3244 | if ((hi == 0 && ((lo + 1) & lo) == 0) | |
3245 | || (lo == 0xffffffff && ((hi + 1) & hi) == 0)) | |
beae10d5 KH |
3246 | { |
3247 | shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number); | |
252b5132 | 3248 | if (shift != 0) |
beae10d5 | 3249 | { |
252b5132 RH |
3250 | expressionS tmp; |
3251 | ||
3252 | /* This instruction will set the register to be all | |
3253 | ones. */ | |
beae10d5 KH |
3254 | tmp.X_op = O_constant; |
3255 | tmp.X_add_number = (offsetT) -1; | |
3256 | macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j", | |
252b5132 | 3257 | reg, 0, (int) BFD_RELOC_LO16); |
beae10d5 KH |
3258 | if (bit != 0) |
3259 | { | |
3260 | bit += shift; | |
3261 | macro_build ((char *) NULL, counter, NULL, | |
3262 | (bit >= 32) ? "dsll32" : "dsll", | |
3263 | "d,w,<", reg, reg, | |
3264 | (bit >= 32) ? bit - 32 : bit); | |
3265 | } | |
3266 | macro_build ((char *) NULL, counter, NULL, | |
252b5132 | 3267 | (shift >= 32) ? "dsrl32" : "dsrl", |
beae10d5 | 3268 | "d,w,<", reg, reg, |
252b5132 | 3269 | (shift >= 32) ? shift - 32 : shift); |
beae10d5 KH |
3270 | return; |
3271 | } | |
3272 | } | |
252b5132 RH |
3273 | |
3274 | /* Sign extend hi32 before calling load_register, because we can | |
3275 | generally get better code when we load a sign extended value. */ | |
3276 | if ((hi32.X_add_number & 0x80000000) != 0) | |
beae10d5 | 3277 | hi32.X_add_number |= ~(offsetT) 0xffffffff; |
252b5132 RH |
3278 | load_register (counter, reg, &hi32, 0); |
3279 | freg = reg; | |
3280 | } | |
3281 | if ((lo32.X_add_number & 0xffff0000) == 0) | |
3282 | { | |
3283 | if (freg != 0) | |
3284 | { | |
3285 | macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg, | |
3286 | freg, 0); | |
3287 | freg = reg; | |
3288 | } | |
3289 | } | |
3290 | else | |
3291 | { | |
3292 | expressionS mid16; | |
3293 | ||
3294 | if ((freg == 0) && (lo32.X_add_number == 0xffffffff)) | |
beae10d5 | 3295 | { |
252b5132 RH |
3296 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, |
3297 | (int) BFD_RELOC_HI16); | |
beae10d5 KH |
3298 | macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg, |
3299 | reg, 0); | |
3300 | return; | |
3301 | } | |
252b5132 RH |
3302 | |
3303 | if (freg != 0) | |
3304 | { | |
3305 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3306 | freg, 16); | |
3307 | freg = reg; | |
3308 | } | |
3309 | mid16 = lo32; | |
3310 | mid16.X_add_number >>= 16; | |
3311 | macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg, | |
3312 | freg, (int) BFD_RELOC_LO16); | |
3313 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3314 | reg, 16); | |
3315 | freg = reg; | |
3316 | } | |
3317 | if ((lo32.X_add_number & 0xffff) != 0) | |
3318 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg, | |
3319 | (int) BFD_RELOC_LO16); | |
3320 | } | |
3321 | ||
3322 | /* Load an address into a register. */ | |
3323 | ||
3324 | static void | |
3325 | load_address (counter, reg, ep) | |
3326 | int *counter; | |
3327 | int reg; | |
3328 | expressionS *ep; | |
3329 | { | |
3330 | char *p; | |
3331 | ||
3332 | if (ep->X_op != O_constant | |
3333 | && ep->X_op != O_symbol) | |
3334 | { | |
3335 | as_bad (_("expression too complex")); | |
3336 | ep->X_op = O_constant; | |
3337 | } | |
3338 | ||
3339 | if (ep->X_op == O_constant) | |
3340 | { | |
3341 | load_register (counter, reg, ep, 0); | |
3342 | return; | |
3343 | } | |
3344 | ||
3345 | if (mips_pic == NO_PIC) | |
3346 | { | |
3347 | /* If this is a reference to a GP relative symbol, we want | |
3348 | addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
3349 | Otherwise we want | |
3350 | lui $reg,<sym> (BFD_RELOC_HI16_S) | |
3351 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3352 | If we have an addend, we always use the latter form. */ | |
7283eb86 | 3353 | if ((valueT) ep->X_add_number > MAX_GPREL_OFFSET |
beae10d5 | 3354 | || nopic_need_relax (ep->X_add_symbol, 1)) |
252b5132 RH |
3355 | p = NULL; |
3356 | else | |
3357 | { | |
3358 | frag_grow (20); | |
3359 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3360 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3361 | "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL); |
3362 | p = frag_var (rs_machine_dependent, 8, 0, | |
3363 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
3364 | mips_opts.warn_about_macros), | |
3365 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3366 | } | |
3367 | macro_build_lui (p, counter, ep, reg); | |
3368 | if (p != NULL) | |
3369 | p += 4; | |
3370 | macro_build (p, counter, ep, | |
ca4e0257 | 3371 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3372 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3373 | } | |
3374 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
3375 | { | |
3376 | expressionS ex; | |
3377 | ||
3378 | /* If this is a reference to an external symbol, we want | |
3379 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3380 | Otherwise we want | |
3381 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3382 | nop | |
3383 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3384 | If there is a constant, it must be added in after. */ | |
3385 | ex.X_add_number = ep->X_add_number; | |
3386 | ep->X_add_number = 0; | |
3387 | frag_grow (20); | |
3388 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3389 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3390 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); |
3391 | macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", ""); | |
3392 | p = frag_var (rs_machine_dependent, 4, 0, | |
3393 | RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros), | |
3394 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3395 | macro_build (p, counter, ep, | |
ca4e0257 | 3396 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3397 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3398 | if (ex.X_add_number != 0) | |
3399 | { | |
3400 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3401 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3402 | ex.X_op = O_constant; | |
3403 | macro_build ((char *) NULL, counter, &ex, | |
ca4e0257 | 3404 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3405 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3406 | } | |
3407 | } | |
3408 | else if (mips_pic == SVR4_PIC) | |
3409 | { | |
3410 | expressionS ex; | |
3411 | int off; | |
3412 | ||
3413 | /* This is the large GOT case. If this is a reference to an | |
3414 | external symbol, we want | |
3415 | lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
3416 | addu $reg,$reg,$gp | |
3417 | lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16) | |
3418 | Otherwise, for a reference to a local symbol, we want | |
3419 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3420 | nop | |
3421 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3422 | If there is a constant, it must be added in after. */ | |
3423 | ex.X_add_number = ep->X_add_number; | |
3424 | ep->X_add_number = 0; | |
3425 | if (reg_needs_delay (GP)) | |
3426 | off = 4; | |
3427 | else | |
3428 | off = 0; | |
3429 | frag_grow (32); | |
3430 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3431 | (int) BFD_RELOC_MIPS_GOT_HI16); | |
3432 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
ca4e0257 | 3433 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
3434 | "d,v,t", reg, reg, GP); |
3435 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3436 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3437 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg); |
3438 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
3439 | RELAX_ENCODE (12, 12 + off, off, 8 + off, 0, | |
3440 | mips_opts.warn_about_macros), | |
3441 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3442 | if (off > 0) | |
3443 | { | |
3444 | /* We need a nop before loading from $gp. This special | |
3445 | check is required because the lui which starts the main | |
3446 | instruction stream does not refer to $gp, and so will not | |
3447 | insert the nop which may be required. */ | |
3448 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3449 | p += 4; | |
3450 | } | |
9a41af64 | 3451 | macro_build (p, counter, ep, HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3452 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); |
3453 | p += 4; | |
3454 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3455 | p += 4; | |
9a41af64 | 3456 | macro_build (p, counter, ep, HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3457 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3458 | if (ex.X_add_number != 0) | |
3459 | { | |
3460 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3461 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3462 | ex.X_op = O_constant; | |
3463 | macro_build ((char *) NULL, counter, &ex, | |
ca4e0257 | 3464 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3465 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3466 | } | |
3467 | } | |
3468 | else if (mips_pic == EMBEDDED_PIC) | |
3469 | { | |
3470 | /* We always do | |
3471 | addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
3472 | */ | |
3473 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3474 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3475 | "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL); |
3476 | } | |
3477 | else | |
3478 | abort (); | |
3479 | } | |
3480 | ||
ea1fb5dc RS |
3481 | /* Move the contents of register SOURCE into register DEST. */ |
3482 | ||
3483 | static void | |
3484 | move_register (counter, dest, source) | |
3485 | int *counter; | |
3486 | int dest; | |
3487 | int source; | |
3488 | { | |
3489 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
3490 | HAVE_32BIT_GPRS ? "addu" : "daddu", | |
3491 | "d,v,t", dest, source, 0); | |
3492 | } | |
3493 | ||
252b5132 RH |
3494 | /* |
3495 | * Build macros | |
3496 | * This routine implements the seemingly endless macro or synthesized | |
3497 | * instructions and addressing modes in the mips assembly language. Many | |
3498 | * of these macros are simple and are similar to each other. These could | |
3499 | * probably be handled by some kind of table or grammer aproach instead of | |
3500 | * this verbose method. Others are not simple macros but are more like | |
3501 | * optimizing code generation. | |
3502 | * One interesting optimization is when several store macros appear | |
3503 | * consecutivly that would load AT with the upper half of the same address. | |
3504 | * The ensuing load upper instructions are ommited. This implies some kind | |
3505 | * of global optimization. We currently only optimize within a single macro. | |
3506 | * For many of the load and store macros if the address is specified as a | |
3507 | * constant expression in the first 64k of memory (ie ld $2,0x4000c) we | |
3508 | * first load register 'at' with zero and use it as the base register. The | |
3509 | * mips assembler simply uses register $zero. Just one tiny optimization | |
3510 | * we're missing. | |
3511 | */ | |
3512 | static void | |
3513 | macro (ip) | |
3514 | struct mips_cl_insn *ip; | |
3515 | { | |
3516 | register int treg, sreg, dreg, breg; | |
3517 | int tempreg; | |
3518 | int mask; | |
3519 | int icnt = 0; | |
43841e91 | 3520 | int used_at = 0; |
252b5132 RH |
3521 | expressionS expr1; |
3522 | const char *s; | |
3523 | const char *s2; | |
3524 | const char *fmt; | |
3525 | int likely = 0; | |
3526 | int dbl = 0; | |
3527 | int coproc = 0; | |
3528 | int lr = 0; | |
3529 | int imm = 0; | |
3530 | offsetT maxnum; | |
3531 | int off; | |
3532 | bfd_reloc_code_real_type r; | |
3533 | char *p; | |
3534 | int hold_mips_optimize; | |
3535 | ||
3536 | assert (! mips_opts.mips16); | |
3537 | ||
3538 | treg = (ip->insn_opcode >> 16) & 0x1f; | |
3539 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
3540 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
3541 | mask = ip->insn_mo->mask; | |
3542 | ||
3543 | expr1.X_op = O_constant; | |
3544 | expr1.X_op_symbol = NULL; | |
3545 | expr1.X_add_symbol = NULL; | |
3546 | expr1.X_add_number = 1; | |
3547 | ||
3548 | switch (mask) | |
3549 | { | |
3550 | case M_DABS: | |
3551 | dbl = 1; | |
3552 | case M_ABS: | |
3553 | /* bgez $a0,.+12 | |
3554 | move v0,$a0 | |
3555 | sub v0,$zero,$a0 | |
3556 | */ | |
3557 | ||
3558 | mips_emit_delays (true); | |
3559 | ++mips_opts.noreorder; | |
3560 | mips_any_noreorder = 1; | |
3561 | ||
3562 | expr1.X_add_number = 8; | |
3563 | macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg); | |
3564 | if (dreg == sreg) | |
3565 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
3566 | else | |
ea1fb5dc | 3567 | move_register (&icnt, dreg, sreg); |
252b5132 | 3568 | macro_build ((char *) NULL, &icnt, NULL, |
9a41af64 | 3569 | dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg); |
252b5132 RH |
3570 | |
3571 | --mips_opts.noreorder; | |
3572 | return; | |
3573 | ||
3574 | case M_ADD_I: | |
3575 | s = "addi"; | |
3576 | s2 = "add"; | |
3577 | goto do_addi; | |
3578 | case M_ADDU_I: | |
3579 | s = "addiu"; | |
3580 | s2 = "addu"; | |
3581 | goto do_addi; | |
3582 | case M_DADD_I: | |
3583 | dbl = 1; | |
3584 | s = "daddi"; | |
3585 | s2 = "dadd"; | |
3586 | goto do_addi; | |
3587 | case M_DADDU_I: | |
3588 | dbl = 1; | |
3589 | s = "daddiu"; | |
3590 | s2 = "daddu"; | |
3591 | do_addi: | |
3592 | if (imm_expr.X_op == O_constant | |
3593 | && imm_expr.X_add_number >= -0x8000 | |
3594 | && imm_expr.X_add_number < 0x8000) | |
3595 | { | |
3596 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg, | |
3597 | (int) BFD_RELOC_LO16); | |
3598 | return; | |
3599 | } | |
3600 | load_register (&icnt, AT, &imm_expr, dbl); | |
3601 | macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT); | |
3602 | break; | |
3603 | ||
3604 | case M_AND_I: | |
3605 | s = "andi"; | |
3606 | s2 = "and"; | |
3607 | goto do_bit; | |
3608 | case M_OR_I: | |
3609 | s = "ori"; | |
3610 | s2 = "or"; | |
3611 | goto do_bit; | |
3612 | case M_NOR_I: | |
3613 | s = ""; | |
3614 | s2 = "nor"; | |
3615 | goto do_bit; | |
3616 | case M_XOR_I: | |
3617 | s = "xori"; | |
3618 | s2 = "xor"; | |
3619 | do_bit: | |
3620 | if (imm_expr.X_op == O_constant | |
3621 | && imm_expr.X_add_number >= 0 | |
3622 | && imm_expr.X_add_number < 0x10000) | |
3623 | { | |
3624 | if (mask != M_NOR_I) | |
3625 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg, | |
3626 | sreg, (int) BFD_RELOC_LO16); | |
3627 | else | |
3628 | { | |
3629 | macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i", | |
3630 | treg, sreg, (int) BFD_RELOC_LO16); | |
3631 | macro_build ((char *) NULL, &icnt, NULL, "nor", "d,v,t", | |
3632 | treg, treg, 0); | |
3633 | } | |
3634 | return; | |
3635 | } | |
3636 | ||
3637 | load_register (&icnt, AT, &imm_expr, 0); | |
3638 | macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT); | |
3639 | break; | |
3640 | ||
3641 | case M_BEQ_I: | |
3642 | s = "beq"; | |
3643 | goto beq_i; | |
3644 | case M_BEQL_I: | |
3645 | s = "beql"; | |
3646 | likely = 1; | |
3647 | goto beq_i; | |
3648 | case M_BNE_I: | |
3649 | s = "bne"; | |
3650 | goto beq_i; | |
3651 | case M_BNEL_I: | |
3652 | s = "bnel"; | |
3653 | likely = 1; | |
3654 | beq_i: | |
3655 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3656 | { | |
3657 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, | |
3658 | 0); | |
3659 | return; | |
3660 | } | |
3661 | load_register (&icnt, AT, &imm_expr, 0); | |
3662 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT); | |
3663 | break; | |
3664 | ||
3665 | case M_BGEL: | |
3666 | likely = 1; | |
3667 | case M_BGE: | |
3668 | if (treg == 0) | |
3669 | { | |
3670 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3671 | likely ? "bgezl" : "bgez", | |
3672 | "s,p", sreg); | |
3673 | return; | |
3674 | } | |
3675 | if (sreg == 0) | |
3676 | { | |
3677 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3678 | likely ? "blezl" : "blez", | |
3679 | "s,p", treg); | |
3680 | return; | |
3681 | } | |
3682 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg); | |
3683 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3684 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
3685 | break; |
3686 | ||
3687 | case M_BGTL_I: | |
3688 | likely = 1; | |
3689 | case M_BGT_I: | |
3690 | /* check for > max integer */ | |
3691 | maxnum = 0x7fffffff; | |
ca4e0257 | 3692 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
3693 | { |
3694 | maxnum <<= 16; | |
3695 | maxnum |= 0xffff; | |
3696 | maxnum <<= 16; | |
3697 | maxnum |= 0xffff; | |
3698 | } | |
3699 | if (imm_expr.X_op == O_constant | |
3700 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 3701 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
3702 | { |
3703 | do_false: | |
3704 | /* result is always false */ | |
3705 | if (! likely) | |
3706 | { | |
39c0a331 L |
3707 | if (warn_nops) |
3708 | as_warn (_("Branch %s is always false (nop)"), | |
3709 | ip->insn_mo->name); | |
252b5132 RH |
3710 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); |
3711 | } | |
3712 | else | |
3713 | { | |
39c0a331 L |
3714 | if (warn_nops) |
3715 | as_warn (_("Branch likely %s is always false"), | |
3716 | ip->insn_mo->name); | |
252b5132 RH |
3717 | macro_build ((char *) NULL, &icnt, &offset_expr, "bnel", |
3718 | "s,t,p", 0, 0); | |
3719 | } | |
3720 | return; | |
3721 | } | |
3722 | if (imm_expr.X_op != O_constant) | |
3723 | as_bad (_("Unsupported large constant")); | |
3724 | imm_expr.X_add_number++; | |
3725 | /* FALLTHROUGH */ | |
3726 | case M_BGE_I: | |
3727 | case M_BGEL_I: | |
3728 | if (mask == M_BGEL_I) | |
3729 | likely = 1; | |
3730 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3731 | { | |
3732 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3733 | likely ? "bgezl" : "bgez", "s,p", sreg); |
252b5132 RH |
3734 | return; |
3735 | } | |
3736 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3737 | { | |
3738 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3739 | likely ? "bgtzl" : "bgtz", "s,p", sreg); |
252b5132 RH |
3740 | return; |
3741 | } | |
3742 | maxnum = 0x7fffffff; | |
ca4e0257 | 3743 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
3744 | { |
3745 | maxnum <<= 16; | |
3746 | maxnum |= 0xffff; | |
3747 | maxnum <<= 16; | |
3748 | maxnum |= 0xffff; | |
3749 | } | |
3750 | maxnum = - maxnum - 1; | |
3751 | if (imm_expr.X_op == O_constant | |
3752 | && imm_expr.X_add_number <= maxnum | |
ca4e0257 | 3753 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
3754 | { |
3755 | do_true: | |
3756 | /* result is always true */ | |
3757 | as_warn (_("Branch %s is always true"), ip->insn_mo->name); | |
3758 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
3759 | return; | |
3760 | } | |
3761 | set_at (&icnt, sreg, 0); | |
3762 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3763 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
3764 | break; |
3765 | ||
3766 | case M_BGEUL: | |
3767 | likely = 1; | |
3768 | case M_BGEU: | |
3769 | if (treg == 0) | |
3770 | goto do_true; | |
3771 | if (sreg == 0) | |
3772 | { | |
3773 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3774 | likely ? "beql" : "beq", "s,t,p", 0, treg); |
252b5132 RH |
3775 | return; |
3776 | } | |
3777 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, | |
3778 | treg); | |
3779 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3780 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
3781 | break; |
3782 | ||
3783 | case M_BGTUL_I: | |
3784 | likely = 1; | |
3785 | case M_BGTU_I: | |
3786 | if (sreg == 0 | |
ca4e0257 | 3787 | || (HAVE_32BIT_GPRS |
252b5132 RH |
3788 | && imm_expr.X_op == O_constant |
3789 | && imm_expr.X_add_number == 0xffffffff)) | |
3790 | goto do_false; | |
3791 | if (imm_expr.X_op != O_constant) | |
3792 | as_bad (_("Unsupported large constant")); | |
3793 | imm_expr.X_add_number++; | |
3794 | /* FALLTHROUGH */ | |
3795 | case M_BGEU_I: | |
3796 | case M_BGEUL_I: | |
3797 | if (mask == M_BGEUL_I) | |
3798 | likely = 1; | |
3799 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3800 | goto do_true; | |
3801 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3802 | { | |
3803 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3804 | likely ? "bnel" : "bne", "s,t,p", sreg, 0); |
252b5132 RH |
3805 | return; |
3806 | } | |
3807 | set_at (&icnt, sreg, 1); | |
3808 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3809 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
3810 | break; |
3811 | ||
3812 | case M_BGTL: | |
3813 | likely = 1; | |
3814 | case M_BGT: | |
3815 | if (treg == 0) | |
3816 | { | |
3817 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3818 | likely ? "bgtzl" : "bgtz", "s,p", sreg); |
252b5132 RH |
3819 | return; |
3820 | } | |
3821 | if (sreg == 0) | |
3822 | { | |
3823 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3824 | likely ? "bltzl" : "bltz", "s,p", treg); |
252b5132 RH |
3825 | return; |
3826 | } | |
3827 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg); | |
3828 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3829 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
3830 | break; |
3831 | ||
3832 | case M_BGTUL: | |
3833 | likely = 1; | |
3834 | case M_BGTU: | |
3835 | if (treg == 0) | |
3836 | { | |
3837 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3838 | likely ? "bnel" : "bne", "s,t,p", sreg, 0); |
252b5132 RH |
3839 | return; |
3840 | } | |
3841 | if (sreg == 0) | |
3842 | goto do_false; | |
3843 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, | |
3844 | sreg); | |
3845 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3846 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
3847 | break; |
3848 | ||
3849 | case M_BLEL: | |
3850 | likely = 1; | |
3851 | case M_BLE: | |
3852 | if (treg == 0) | |
3853 | { | |
3854 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3855 | likely ? "blezl" : "blez", "s,p", sreg); |
252b5132 RH |
3856 | return; |
3857 | } | |
3858 | if (sreg == 0) | |
3859 | { | |
3860 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3861 | likely ? "bgezl" : "bgez", "s,p", treg); |
252b5132 RH |
3862 | return; |
3863 | } | |
3864 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg); | |
3865 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3866 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
3867 | break; |
3868 | ||
3869 | case M_BLEL_I: | |
3870 | likely = 1; | |
3871 | case M_BLE_I: | |
3872 | maxnum = 0x7fffffff; | |
ca4e0257 | 3873 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
3874 | { |
3875 | maxnum <<= 16; | |
3876 | maxnum |= 0xffff; | |
3877 | maxnum <<= 16; | |
3878 | maxnum |= 0xffff; | |
3879 | } | |
3880 | if (imm_expr.X_op == O_constant | |
3881 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 3882 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
3883 | goto do_true; |
3884 | if (imm_expr.X_op != O_constant) | |
3885 | as_bad (_("Unsupported large constant")); | |
3886 | imm_expr.X_add_number++; | |
3887 | /* FALLTHROUGH */ | |
3888 | case M_BLT_I: | |
3889 | case M_BLTL_I: | |
3890 | if (mask == M_BLTL_I) | |
3891 | likely = 1; | |
3892 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3893 | { | |
3894 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3895 | likely ? "bltzl" : "bltz", "s,p", sreg); |
252b5132 RH |
3896 | return; |
3897 | } | |
3898 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3899 | { | |
3900 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3901 | likely ? "blezl" : "blez", "s,p", sreg); |
252b5132 RH |
3902 | return; |
3903 | } | |
3904 | set_at (&icnt, sreg, 0); | |
3905 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3906 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
3907 | break; |
3908 | ||
3909 | case M_BLEUL: | |
3910 | likely = 1; | |
3911 | case M_BLEU: | |
3912 | if (treg == 0) | |
3913 | { | |
3914 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3915 | likely ? "beql" : "beq", "s,t,p", sreg, 0); |
252b5132 RH |
3916 | return; |
3917 | } | |
3918 | if (sreg == 0) | |
3919 | goto do_true; | |
3920 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, | |
3921 | sreg); | |
3922 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3923 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
3924 | break; |
3925 | ||
3926 | case M_BLEUL_I: | |
3927 | likely = 1; | |
3928 | case M_BLEU_I: | |
3929 | if (sreg == 0 | |
ca4e0257 | 3930 | || (HAVE_32BIT_GPRS |
252b5132 RH |
3931 | && imm_expr.X_op == O_constant |
3932 | && imm_expr.X_add_number == 0xffffffff)) | |
3933 | goto do_true; | |
3934 | if (imm_expr.X_op != O_constant) | |
3935 | as_bad (_("Unsupported large constant")); | |
3936 | imm_expr.X_add_number++; | |
3937 | /* FALLTHROUGH */ | |
3938 | case M_BLTU_I: | |
3939 | case M_BLTUL_I: | |
3940 | if (mask == M_BLTUL_I) | |
3941 | likely = 1; | |
3942 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3943 | goto do_false; | |
3944 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3945 | { | |
3946 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3947 | likely ? "beql" : "beq", | |
3948 | "s,t,p", sreg, 0); | |
3949 | return; | |
3950 | } | |
3951 | set_at (&icnt, sreg, 1); | |
3952 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3953 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
3954 | break; |
3955 | ||
3956 | case M_BLTL: | |
3957 | likely = 1; | |
3958 | case M_BLT: | |
3959 | if (treg == 0) | |
3960 | { | |
3961 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3962 | likely ? "bltzl" : "bltz", "s,p", sreg); |
252b5132 RH |
3963 | return; |
3964 | } | |
3965 | if (sreg == 0) | |
3966 | { | |
3967 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3968 | likely ? "bgtzl" : "bgtz", "s,p", treg); |
252b5132 RH |
3969 | return; |
3970 | } | |
3971 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg); | |
3972 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3973 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
3974 | break; |
3975 | ||
3976 | case M_BLTUL: | |
3977 | likely = 1; | |
3978 | case M_BLTU: | |
3979 | if (treg == 0) | |
3980 | goto do_false; | |
3981 | if (sreg == 0) | |
3982 | { | |
3983 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3984 | likely ? "bnel" : "bne", "s,t,p", 0, treg); |
252b5132 RH |
3985 | return; |
3986 | } | |
3987 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, | |
3988 | treg); | |
3989 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3990 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
3991 | break; |
3992 | ||
3993 | case M_DDIV_3: | |
3994 | dbl = 1; | |
3995 | case M_DIV_3: | |
3996 | s = "mflo"; | |
3997 | goto do_div3; | |
3998 | case M_DREM_3: | |
3999 | dbl = 1; | |
4000 | case M_REM_3: | |
4001 | s = "mfhi"; | |
4002 | do_div3: | |
4003 | if (treg == 0) | |
4004 | { | |
4005 | as_warn (_("Divide by zero.")); | |
4006 | if (mips_trap) | |
4007 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0); | |
4008 | else | |
9117d219 | 4009 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); |
252b5132 RH |
4010 | return; |
4011 | } | |
4012 | ||
4013 | mips_emit_delays (true); | |
4014 | ++mips_opts.noreorder; | |
4015 | mips_any_noreorder = 1; | |
4016 | if (mips_trap) | |
4017 | { | |
4018 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0); | |
4019 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 4020 | dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
252b5132 RH |
4021 | } |
4022 | else | |
4023 | { | |
4024 | expr1.X_add_number = 8; | |
4025 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
4026 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 4027 | dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
9117d219 | 4028 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); |
252b5132 RH |
4029 | } |
4030 | expr1.X_add_number = -1; | |
4031 | macro_build ((char *) NULL, &icnt, &expr1, | |
4032 | dbl ? "daddiu" : "addiu", | |
4033 | "t,r,j", AT, 0, (int) BFD_RELOC_LO16); | |
4034 | expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16); | |
4035 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT); | |
4036 | if (dbl) | |
4037 | { | |
4038 | expr1.X_add_number = 1; | |
4039 | macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0, | |
4040 | (int) BFD_RELOC_LO16); | |
4041 | macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT, | |
4042 | 31); | |
4043 | } | |
4044 | else | |
4045 | { | |
4046 | expr1.X_add_number = 0x80000000; | |
4047 | macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT, | |
4048 | (int) BFD_RELOC_HI16); | |
4049 | } | |
4050 | if (mips_trap) | |
4051 | { | |
4052 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", sreg, AT); | |
4053 | /* We want to close the noreorder block as soon as possible, so | |
4054 | that later insns are available for delay slot filling. */ | |
4055 | --mips_opts.noreorder; | |
4056 | } | |
4057 | else | |
4058 | { | |
4059 | expr1.X_add_number = 8; | |
4060 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT); | |
4061 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
4062 | ||
4063 | /* We want to close the noreorder block as soon as possible, so | |
4064 | that later insns are available for delay slot filling. */ | |
4065 | --mips_opts.noreorder; | |
4066 | ||
9117d219 | 4067 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); |
252b5132 RH |
4068 | } |
4069 | macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg); | |
4070 | break; | |
4071 | ||
4072 | case M_DIV_3I: | |
4073 | s = "div"; | |
4074 | s2 = "mflo"; | |
4075 | goto do_divi; | |
4076 | case M_DIVU_3I: | |
4077 | s = "divu"; | |
4078 | s2 = "mflo"; | |
4079 | goto do_divi; | |
4080 | case M_REM_3I: | |
4081 | s = "div"; | |
4082 | s2 = "mfhi"; | |
4083 | goto do_divi; | |
4084 | case M_REMU_3I: | |
4085 | s = "divu"; | |
4086 | s2 = "mfhi"; | |
4087 | goto do_divi; | |
4088 | case M_DDIV_3I: | |
4089 | dbl = 1; | |
4090 | s = "ddiv"; | |
4091 | s2 = "mflo"; | |
4092 | goto do_divi; | |
4093 | case M_DDIVU_3I: | |
4094 | dbl = 1; | |
4095 | s = "ddivu"; | |
4096 | s2 = "mflo"; | |
4097 | goto do_divi; | |
4098 | case M_DREM_3I: | |
4099 | dbl = 1; | |
4100 | s = "ddiv"; | |
4101 | s2 = "mfhi"; | |
4102 | goto do_divi; | |
4103 | case M_DREMU_3I: | |
4104 | dbl = 1; | |
4105 | s = "ddivu"; | |
4106 | s2 = "mfhi"; | |
4107 | do_divi: | |
4108 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4109 | { | |
4110 | as_warn (_("Divide by zero.")); | |
4111 | if (mips_trap) | |
4112 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0); | |
4113 | else | |
beae10d5 | 4114 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); |
252b5132 RH |
4115 | return; |
4116 | } | |
4117 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4118 | { | |
4119 | if (strcmp (s2, "mflo") == 0) | |
ea1fb5dc | 4120 | move_register (&icnt, dreg, sreg); |
252b5132 | 4121 | else |
ea1fb5dc | 4122 | move_register (&icnt, dreg, 0); |
252b5132 RH |
4123 | return; |
4124 | } | |
4125 | if (imm_expr.X_op == O_constant | |
4126 | && imm_expr.X_add_number == -1 | |
4127 | && s[strlen (s) - 1] != 'u') | |
4128 | { | |
4129 | if (strcmp (s2, "mflo") == 0) | |
4130 | { | |
9a41af64 TS |
4131 | macro_build ((char *) NULL, &icnt, NULL, dbl ? "dneg" : "neg", |
4132 | "d,w", dreg, sreg); | |
252b5132 RH |
4133 | } |
4134 | else | |
ea1fb5dc | 4135 | move_register (&icnt, dreg, 0); |
252b5132 RH |
4136 | return; |
4137 | } | |
4138 | ||
4139 | load_register (&icnt, AT, &imm_expr, dbl); | |
4140 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT); | |
4141 | macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg); | |
4142 | break; | |
4143 | ||
4144 | case M_DIVU_3: | |
4145 | s = "divu"; | |
4146 | s2 = "mflo"; | |
4147 | goto do_divu3; | |
4148 | case M_REMU_3: | |
4149 | s = "divu"; | |
4150 | s2 = "mfhi"; | |
4151 | goto do_divu3; | |
4152 | case M_DDIVU_3: | |
4153 | s = "ddivu"; | |
4154 | s2 = "mflo"; | |
4155 | goto do_divu3; | |
4156 | case M_DREMU_3: | |
4157 | s = "ddivu"; | |
4158 | s2 = "mfhi"; | |
4159 | do_divu3: | |
4160 | mips_emit_delays (true); | |
4161 | ++mips_opts.noreorder; | |
4162 | mips_any_noreorder = 1; | |
4163 | if (mips_trap) | |
4164 | { | |
4165 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0); | |
4166 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg); | |
4167 | /* We want to close the noreorder block as soon as possible, so | |
4168 | that later insns are available for delay slot filling. */ | |
4169 | --mips_opts.noreorder; | |
4170 | } | |
4171 | else | |
4172 | { | |
4173 | expr1.X_add_number = 8; | |
4174 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
4175 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg); | |
4176 | ||
4177 | /* We want to close the noreorder block as soon as possible, so | |
4178 | that later insns are available for delay slot filling. */ | |
4179 | --mips_opts.noreorder; | |
beae10d5 | 4180 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); |
252b5132 RH |
4181 | } |
4182 | macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg); | |
4183 | return; | |
4184 | ||
4185 | case M_DLA_AB: | |
4186 | dbl = 1; | |
4187 | case M_LA_AB: | |
4188 | /* Load the address of a symbol into a register. If breg is not | |
4189 | zero, we then add a base register to it. */ | |
4190 | ||
4191 | /* When generating embedded PIC code, we permit expressions of | |
4192 | the form | |
4193 | la $4,foo-bar | |
bb2d6cd7 | 4194 | where bar is an address in the current section. These are used |
252b5132 RH |
4195 | when getting the addresses of functions. We don't permit |
4196 | X_add_number to be non-zero, because if the symbol is | |
4197 | external the relaxing code needs to know that any addend is | |
4198 | purely the offset to X_op_symbol. */ | |
4199 | if (mips_pic == EMBEDDED_PIC | |
4200 | && offset_expr.X_op == O_subtract | |
49309057 | 4201 | && (symbol_constant_p (offset_expr.X_op_symbol) |
bb2d6cd7 | 4202 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg |
49309057 ILT |
4203 | : (symbol_equated_p (offset_expr.X_op_symbol) |
4204 | && (S_GET_SEGMENT | |
4205 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
4206 | ->X_add_symbol) | |
bb2d6cd7 | 4207 | == now_seg))) |
252b5132 | 4208 | && breg == 0 |
bb2d6cd7 GK |
4209 | && (offset_expr.X_add_number == 0 |
4210 | || OUTPUT_FLAVOR == bfd_target_elf_flavour)) | |
252b5132 RH |
4211 | { |
4212 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4213 | treg, (int) BFD_RELOC_PCREL_HI16_S); | |
4214 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 4215 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4216 | "t,r,j", treg, treg, (int) BFD_RELOC_PCREL_LO16); |
4217 | return; | |
4218 | } | |
4219 | ||
4220 | if (offset_expr.X_op != O_symbol | |
4221 | && offset_expr.X_op != O_constant) | |
4222 | { | |
4223 | as_bad (_("expression too complex")); | |
4224 | offset_expr.X_op = O_constant; | |
4225 | } | |
4226 | ||
4227 | if (treg == breg) | |
4228 | { | |
4229 | tempreg = AT; | |
4230 | used_at = 1; | |
4231 | } | |
4232 | else | |
4233 | { | |
4234 | tempreg = treg; | |
4235 | used_at = 0; | |
4236 | } | |
4237 | ||
4238 | if (offset_expr.X_op == O_constant) | |
4239 | load_register (&icnt, tempreg, &offset_expr, dbl); | |
4240 | else if (mips_pic == NO_PIC) | |
4241 | { | |
4242 | /* If this is a reference to an GP relative symbol, we want | |
4243 | addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
4244 | Otherwise we want | |
4245 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4246 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4247 | If we have a constant, we need two instructions anyhow, | |
4248 | so we may as well always use the latter form. */ | |
7283eb86 | 4249 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
4250 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
4251 | p = NULL; | |
4252 | else | |
4253 | { | |
4254 | frag_grow (20); | |
4255 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 4256 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4257 | "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL); |
4258 | p = frag_var (rs_machine_dependent, 8, 0, | |
4259 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
4260 | mips_opts.warn_about_macros), | |
4261 | offset_expr.X_add_symbol, (offsetT) 0, | |
4262 | (char *) NULL); | |
4263 | } | |
4264 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
4265 | if (p != NULL) | |
4266 | p += 4; | |
4267 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 4268 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4269 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4270 | } | |
4271 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
4272 | { | |
9117d219 NC |
4273 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
4274 | ||
252b5132 RH |
4275 | /* If this is a reference to an external symbol, and there |
4276 | is no constant, we want | |
4277 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
9117d219 NC |
4278 | or if tempreg is PIC_CALL_REG |
4279 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
252b5132 RH |
4280 | For a local symbol, we want |
4281 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4282 | nop | |
4283 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4284 | ||
4285 | If we have a small constant, and this is a reference to | |
4286 | an external symbol, we want | |
4287 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4288 | nop | |
4289 | addiu $tempreg,$tempreg,<constant> | |
4290 | For a local symbol, we want the same instruction | |
4291 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4292 | addiu instruction. | |
4293 | ||
4294 | If we have a large constant, and this is a reference to | |
4295 | an external symbol, we want | |
4296 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4297 | lui $at,<hiconstant> | |
4298 | addiu $at,$at,<loconstant> | |
4299 | addu $tempreg,$tempreg,$at | |
4300 | For a local symbol, we want the same instruction | |
4301 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4302 | addiu instruction. */ | |
4303 | expr1.X_add_number = offset_expr.X_add_number; | |
4304 | offset_expr.X_add_number = 0; | |
4305 | frag_grow (32); | |
9117d219 NC |
4306 | if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG) |
4307 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16; | |
252b5132 RH |
4308 | macro_build ((char *) NULL, &icnt, &offset_expr, |
4309 | dbl ? "ld" : "lw", | |
9117d219 | 4310 | "t,o(b)", tempreg, lw_reloc_type, GP); |
252b5132 RH |
4311 | if (expr1.X_add_number == 0) |
4312 | { | |
4313 | int off; | |
4314 | ||
4315 | if (breg == 0) | |
4316 | off = 0; | |
4317 | else | |
4318 | { | |
4319 | /* We're going to put in an addu instruction using | |
4320 | tempreg, so we may as well insert the nop right | |
4321 | now. */ | |
4322 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4323 | "nop", ""); | |
4324 | off = 4; | |
4325 | } | |
4326 | p = frag_var (rs_machine_dependent, 8 - off, 0, | |
4327 | RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0, | |
4328 | (breg == 0 | |
4329 | ? mips_opts.warn_about_macros | |
4330 | : 0)), | |
4331 | offset_expr.X_add_symbol, (offsetT) 0, | |
4332 | (char *) NULL); | |
4333 | if (breg == 0) | |
4334 | { | |
4335 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4336 | p += 4; | |
4337 | } | |
4338 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4339 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4340 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4341 | /* FIXME: If breg == 0, and the next instruction uses | |
4342 | $tempreg, then if this variant case is used an extra | |
4343 | nop will be generated. */ | |
4344 | } | |
4345 | else if (expr1.X_add_number >= -0x8000 | |
4346 | && expr1.X_add_number < 0x8000) | |
4347 | { | |
4348 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4349 | "nop", ""); | |
4350 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4351 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4352 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4353 | (void) frag_var (rs_machine_dependent, 0, 0, | |
4354 | RELAX_ENCODE (0, 0, -12, -4, 0, 0), | |
4355 | offset_expr.X_add_symbol, (offsetT) 0, | |
4356 | (char *) NULL); | |
4357 | } | |
4358 | else | |
4359 | { | |
4360 | int off1; | |
4361 | ||
4362 | /* If we are going to add in a base register, and the | |
4363 | target register and the base register are the same, | |
4364 | then we are using AT as a temporary register. Since | |
4365 | we want to load the constant into AT, we add our | |
4366 | current AT (from the global offset table) and the | |
4367 | register into the register now, and pretend we were | |
4368 | not using a base register. */ | |
4369 | if (breg != treg) | |
4370 | off1 = 0; | |
4371 | else | |
4372 | { | |
4373 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4374 | "nop", ""); | |
4375 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4376 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4377 | "d,v,t", treg, AT, breg); |
4378 | breg = 0; | |
4379 | tempreg = treg; | |
4380 | off1 = -8; | |
4381 | } | |
4382 | ||
4383 | /* Set mips_optimize around the lui instruction to avoid | |
4384 | inserting an unnecessary nop after the lw. */ | |
4385 | hold_mips_optimize = mips_optimize; | |
4386 | mips_optimize = 2; | |
4387 | macro_build_lui ((char *) NULL, &icnt, &expr1, AT); | |
4388 | mips_optimize = hold_mips_optimize; | |
4389 | ||
4390 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4391 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4392 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4393 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4394 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4395 | "d,v,t", tempreg, tempreg, AT); |
4396 | (void) frag_var (rs_machine_dependent, 0, 0, | |
4397 | RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0), | |
4398 | offset_expr.X_add_symbol, (offsetT) 0, | |
4399 | (char *) NULL); | |
4400 | used_at = 1; | |
4401 | } | |
4402 | } | |
4403 | else if (mips_pic == SVR4_PIC) | |
4404 | { | |
4405 | int gpdel; | |
9117d219 NC |
4406 | int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16; |
4407 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16; | |
252b5132 RH |
4408 | |
4409 | /* This is the large GOT case. If this is a reference to an | |
4410 | external symbol, and there is no constant, we want | |
4411 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4412 | addu $tempreg,$tempreg,$gp | |
4413 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
9117d219 NC |
4414 | or if tempreg is PIC_CALL_REG |
4415 | lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
4416 | addu $tempreg,$tempreg,$gp | |
4417 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16) | |
252b5132 RH |
4418 | For a local symbol, we want |
4419 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4420 | nop | |
4421 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4422 | ||
4423 | If we have a small constant, and this is a reference to | |
4424 | an external symbol, we want | |
4425 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4426 | addu $tempreg,$tempreg,$gp | |
4427 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4428 | nop | |
4429 | addiu $tempreg,$tempreg,<constant> | |
4430 | For a local symbol, we want | |
4431 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4432 | nop | |
4433 | addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16) | |
4434 | ||
4435 | If we have a large constant, and this is a reference to | |
4436 | an external symbol, we want | |
4437 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4438 | addu $tempreg,$tempreg,$gp | |
4439 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4440 | lui $at,<hiconstant> | |
4441 | addiu $at,$at,<loconstant> | |
4442 | addu $tempreg,$tempreg,$at | |
4443 | For a local symbol, we want | |
4444 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4445 | lui $at,<hiconstant> | |
4446 | addiu $at,$at,<loconstant> (BFD_RELOC_LO16) | |
4447 | addu $tempreg,$tempreg,$at | |
4448 | */ | |
4449 | expr1.X_add_number = offset_expr.X_add_number; | |
4450 | offset_expr.X_add_number = 0; | |
4451 | frag_grow (52); | |
4452 | if (reg_needs_delay (GP)) | |
4453 | gpdel = 4; | |
4454 | else | |
4455 | gpdel = 0; | |
9117d219 NC |
4456 | if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG) |
4457 | { | |
4458 | lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16; | |
4459 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16; | |
4460 | } | |
252b5132 | 4461 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", |
9117d219 | 4462 | tempreg, lui_reloc_type); |
252b5132 | 4463 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
ca4e0257 | 4464 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4465 | "d,v,t", tempreg, tempreg, GP); |
4466 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4467 | dbl ? "ld" : "lw", | |
9117d219 | 4468 | "t,o(b)", tempreg, lw_reloc_type, tempreg); |
252b5132 RH |
4469 | if (expr1.X_add_number == 0) |
4470 | { | |
4471 | int off; | |
4472 | ||
4473 | if (breg == 0) | |
4474 | off = 0; | |
4475 | else | |
4476 | { | |
4477 | /* We're going to put in an addu instruction using | |
4478 | tempreg, so we may as well insert the nop right | |
4479 | now. */ | |
4480 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4481 | "nop", ""); | |
4482 | off = 4; | |
4483 | } | |
4484 | ||
4485 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4486 | RELAX_ENCODE (12 + off, 12 + gpdel, gpdel, | |
4487 | 8 + gpdel, 0, | |
4488 | (breg == 0 | |
4489 | ? mips_opts.warn_about_macros | |
4490 | : 0)), | |
4491 | offset_expr.X_add_symbol, (offsetT) 0, | |
4492 | (char *) NULL); | |
4493 | } | |
4494 | else if (expr1.X_add_number >= -0x8000 | |
4495 | && expr1.X_add_number < 0x8000) | |
4496 | { | |
4497 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4498 | "nop", ""); | |
4499 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4500 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4501 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4502 | ||
4503 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4504 | RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0, | |
4505 | (breg == 0 | |
4506 | ? mips_opts.warn_about_macros | |
4507 | : 0)), | |
4508 | offset_expr.X_add_symbol, (offsetT) 0, | |
4509 | (char *) NULL); | |
4510 | } | |
4511 | else | |
4512 | { | |
4513 | int adj, dreg; | |
4514 | ||
4515 | /* If we are going to add in a base register, and the | |
4516 | target register and the base register are the same, | |
4517 | then we are using AT as a temporary register. Since | |
4518 | we want to load the constant into AT, we add our | |
4519 | current AT (from the global offset table) and the | |
4520 | register into the register now, and pretend we were | |
4521 | not using a base register. */ | |
4522 | if (breg != treg) | |
4523 | { | |
4524 | adj = 0; | |
4525 | dreg = tempreg; | |
4526 | } | |
4527 | else | |
4528 | { | |
4529 | assert (tempreg == AT); | |
4530 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4531 | "nop", ""); | |
4532 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4533 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4534 | "d,v,t", treg, AT, breg); |
4535 | dreg = treg; | |
4536 | adj = 8; | |
4537 | } | |
4538 | ||
4539 | /* Set mips_optimize around the lui instruction to avoid | |
4540 | inserting an unnecessary nop after the lw. */ | |
4541 | hold_mips_optimize = mips_optimize; | |
4542 | mips_optimize = 2; | |
4543 | macro_build_lui ((char *) NULL, &icnt, &expr1, AT); | |
4544 | mips_optimize = hold_mips_optimize; | |
4545 | ||
4546 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4547 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4548 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4549 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4550 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4551 | "d,v,t", dreg, dreg, AT); |
4552 | ||
4553 | p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0, | |
4554 | RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel, | |
4555 | 8 + gpdel, 0, | |
4556 | (breg == 0 | |
4557 | ? mips_opts.warn_about_macros | |
4558 | : 0)), | |
4559 | offset_expr.X_add_symbol, (offsetT) 0, | |
4560 | (char *) NULL); | |
4561 | ||
4562 | used_at = 1; | |
4563 | } | |
4564 | ||
4565 | if (gpdel > 0) | |
4566 | { | |
4567 | /* This is needed because this instruction uses $gp, but | |
4568 | the first instruction on the main stream does not. */ | |
4569 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4570 | p += 4; | |
4571 | } | |
4572 | macro_build (p, &icnt, &offset_expr, | |
4573 | dbl ? "ld" : "lw", | |
4574 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
4575 | p += 4; | |
4576 | if (expr1.X_add_number >= -0x8000 | |
4577 | && expr1.X_add_number < 0x8000) | |
4578 | { | |
4579 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4580 | p += 4; | |
4581 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4582 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4583 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4584 | /* FIXME: If add_number is 0, and there was no base | |
4585 | register, the external symbol case ended with a load, | |
4586 | so if the symbol turns out to not be external, and | |
4587 | the next instruction uses tempreg, an unnecessary nop | |
4588 | will be inserted. */ | |
4589 | } | |
4590 | else | |
4591 | { | |
4592 | if (breg == treg) | |
4593 | { | |
4594 | /* We must add in the base register now, as in the | |
4595 | external symbol case. */ | |
4596 | assert (tempreg == AT); | |
4597 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4598 | p += 4; | |
4599 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4600 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4601 | "d,v,t", treg, AT, breg); |
4602 | p += 4; | |
4603 | tempreg = treg; | |
4604 | /* We set breg to 0 because we have arranged to add | |
4605 | it in in both cases. */ | |
4606 | breg = 0; | |
4607 | } | |
4608 | ||
4609 | macro_build_lui (p, &icnt, &expr1, AT); | |
4610 | p += 4; | |
4611 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4612 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4613 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4614 | p += 4; | |
4615 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4616 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4617 | "d,v,t", tempreg, tempreg, AT); |
4618 | p += 4; | |
4619 | } | |
4620 | } | |
4621 | else if (mips_pic == EMBEDDED_PIC) | |
4622 | { | |
4623 | /* We use | |
4624 | addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
4625 | */ | |
4626 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 4627 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4628 | "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL); |
4629 | } | |
4630 | else | |
4631 | abort (); | |
4632 | ||
4633 | if (breg != 0) | |
4634 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4635 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4636 | "d,v,t", treg, tempreg, breg); |
4637 | ||
4638 | if (! used_at) | |
4639 | return; | |
4640 | ||
4641 | break; | |
4642 | ||
4643 | case M_J_A: | |
4644 | /* The j instruction may not be used in PIC code, since it | |
4645 | requires an absolute address. We convert it to a b | |
4646 | instruction. */ | |
4647 | if (mips_pic == NO_PIC) | |
4648 | macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a"); | |
4649 | else | |
4650 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
4651 | return; | |
4652 | ||
4653 | /* The jal instructions must be handled as macros because when | |
4654 | generating PIC code they expand to multi-instruction | |
4655 | sequences. Normally they are simple instructions. */ | |
4656 | case M_JAL_1: | |
4657 | dreg = RA; | |
4658 | /* Fall through. */ | |
4659 | case M_JAL_2: | |
4660 | if (mips_pic == NO_PIC | |
4661 | || mips_pic == EMBEDDED_PIC) | |
4662 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", | |
4663 | "d,s", dreg, sreg); | |
4664 | else if (mips_pic == SVR4_PIC) | |
4665 | { | |
4666 | if (sreg != PIC_CALL_REG) | |
4667 | as_warn (_("MIPS PIC call to register other than $25")); | |
bdaaa2e1 | 4668 | |
252b5132 RH |
4669 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", |
4670 | "d,s", dreg, sreg); | |
4671 | if (mips_cprestore_offset < 0) | |
4672 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
4673 | else | |
4674 | { | |
4675 | expr1.X_add_number = mips_cprestore_offset; | |
4676 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4677 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
4678 | "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg); |
4679 | } | |
4680 | } | |
4681 | else | |
4682 | abort (); | |
4683 | ||
4684 | return; | |
4685 | ||
4686 | case M_JAL_A: | |
4687 | if (mips_pic == NO_PIC) | |
4688 | macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a"); | |
4689 | else if (mips_pic == SVR4_PIC) | |
4690 | { | |
4691 | /* If this is a reference to an external symbol, and we are | |
4692 | using a small GOT, we want | |
4693 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
4694 | nop | |
4695 | jalr $25 | |
4696 | nop | |
4697 | lw $gp,cprestore($sp) | |
4698 | The cprestore value is set using the .cprestore | |
4699 | pseudo-op. If we are using a big GOT, we want | |
4700 | lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
4701 | addu $25,$25,$gp | |
4702 | lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16) | |
4703 | nop | |
4704 | jalr $25 | |
4705 | nop | |
4706 | lw $gp,cprestore($sp) | |
4707 | If the symbol is not external, we want | |
4708 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4709 | nop | |
4710 | addiu $25,$25,<sym> (BFD_RELOC_LO16) | |
4711 | jalr $25 | |
4712 | nop | |
4713 | lw $gp,cprestore($sp) */ | |
4714 | frag_grow (40); | |
4715 | if (! mips_big_got) | |
4716 | { | |
4717 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 4718 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
4719 | "t,o(b)", PIC_CALL_REG, |
4720 | (int) BFD_RELOC_MIPS_CALL16, GP); | |
4721 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4722 | "nop", ""); | |
4723 | p = frag_var (rs_machine_dependent, 4, 0, | |
4724 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), | |
4725 | offset_expr.X_add_symbol, (offsetT) 0, | |
4726 | (char *) NULL); | |
4727 | } | |
4728 | else | |
4729 | { | |
4730 | int gpdel; | |
4731 | ||
4732 | if (reg_needs_delay (GP)) | |
4733 | gpdel = 4; | |
4734 | else | |
4735 | gpdel = 0; | |
4736 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4737 | PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16); | |
4738 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4739 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4740 | "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP); |
4741 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 4742 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
4743 | "t,o(b)", PIC_CALL_REG, |
4744 | (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG); | |
4745 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4746 | "nop", ""); | |
4747 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4748 | RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel, | |
4749 | 0, 0), | |
4750 | offset_expr.X_add_symbol, (offsetT) 0, | |
4751 | (char *) NULL); | |
4752 | if (gpdel > 0) | |
4753 | { | |
4754 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4755 | p += 4; | |
4756 | } | |
4757 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 4758 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
4759 | "t,o(b)", PIC_CALL_REG, |
4760 | (int) BFD_RELOC_MIPS_GOT16, GP); | |
4761 | p += 4; | |
4762 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4763 | p += 4; | |
bdaaa2e1 | 4764 | } |
252b5132 | 4765 | macro_build (p, &icnt, &offset_expr, |
ca4e0257 | 4766 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4767 | "t,r,j", PIC_CALL_REG, PIC_CALL_REG, |
4768 | (int) BFD_RELOC_LO16); | |
4769 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4770 | "jalr", "s", PIC_CALL_REG); | |
4771 | if (mips_cprestore_offset < 0) | |
4772 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
4773 | else | |
4774 | { | |
4775 | if (mips_opts.noreorder) | |
4776 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4777 | "nop", ""); | |
4778 | expr1.X_add_number = mips_cprestore_offset; | |
4779 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4780 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
4781 | "t,o(b)", GP, (int) BFD_RELOC_LO16, |
4782 | mips_frame_reg); | |
4783 | } | |
4784 | } | |
4785 | else if (mips_pic == EMBEDDED_PIC) | |
4786 | { | |
4787 | macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p"); | |
4788 | /* The linker may expand the call to a longer sequence which | |
4789 | uses $at, so we must break rather than return. */ | |
4790 | break; | |
4791 | } | |
4792 | else | |
4793 | abort (); | |
4794 | ||
4795 | return; | |
4796 | ||
4797 | case M_LB_AB: | |
4798 | s = "lb"; | |
4799 | goto ld; | |
4800 | case M_LBU_AB: | |
4801 | s = "lbu"; | |
4802 | goto ld; | |
4803 | case M_LH_AB: | |
4804 | s = "lh"; | |
4805 | goto ld; | |
4806 | case M_LHU_AB: | |
4807 | s = "lhu"; | |
4808 | goto ld; | |
4809 | case M_LW_AB: | |
4810 | s = "lw"; | |
4811 | goto ld; | |
4812 | case M_LWC0_AB: | |
4813 | s = "lwc0"; | |
bdaaa2e1 | 4814 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4815 | coproc = 1; |
4816 | goto ld; | |
4817 | case M_LWC1_AB: | |
4818 | s = "lwc1"; | |
bdaaa2e1 | 4819 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4820 | coproc = 1; |
4821 | goto ld; | |
4822 | case M_LWC2_AB: | |
4823 | s = "lwc2"; | |
bdaaa2e1 | 4824 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4825 | coproc = 1; |
4826 | goto ld; | |
4827 | case M_LWC3_AB: | |
4828 | s = "lwc3"; | |
bdaaa2e1 | 4829 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4830 | coproc = 1; |
4831 | goto ld; | |
4832 | case M_LWL_AB: | |
4833 | s = "lwl"; | |
4834 | lr = 1; | |
4835 | goto ld; | |
4836 | case M_LWR_AB: | |
4837 | s = "lwr"; | |
4838 | lr = 1; | |
4839 | goto ld; | |
4840 | case M_LDC1_AB: | |
ec68c924 | 4841 | if (mips_arch == CPU_R4650) |
252b5132 RH |
4842 | { |
4843 | as_bad (_("opcode not supported on this processor")); | |
4844 | return; | |
4845 | } | |
4846 | s = "ldc1"; | |
bdaaa2e1 | 4847 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4848 | coproc = 1; |
4849 | goto ld; | |
4850 | case M_LDC2_AB: | |
4851 | s = "ldc2"; | |
bdaaa2e1 | 4852 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4853 | coproc = 1; |
4854 | goto ld; | |
4855 | case M_LDC3_AB: | |
4856 | s = "ldc3"; | |
bdaaa2e1 | 4857 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4858 | coproc = 1; |
4859 | goto ld; | |
4860 | case M_LDL_AB: | |
4861 | s = "ldl"; | |
4862 | lr = 1; | |
4863 | goto ld; | |
4864 | case M_LDR_AB: | |
4865 | s = "ldr"; | |
4866 | lr = 1; | |
4867 | goto ld; | |
4868 | case M_LL_AB: | |
4869 | s = "ll"; | |
4870 | goto ld; | |
4871 | case M_LLD_AB: | |
4872 | s = "lld"; | |
4873 | goto ld; | |
4874 | case M_LWU_AB: | |
4875 | s = "lwu"; | |
4876 | ld: | |
4877 | if (breg == treg || coproc || lr) | |
4878 | { | |
4879 | tempreg = AT; | |
4880 | used_at = 1; | |
4881 | } | |
4882 | else | |
4883 | { | |
4884 | tempreg = treg; | |
4885 | used_at = 0; | |
4886 | } | |
4887 | goto ld_st; | |
4888 | case M_SB_AB: | |
4889 | s = "sb"; | |
4890 | goto st; | |
4891 | case M_SH_AB: | |
4892 | s = "sh"; | |
4893 | goto st; | |
4894 | case M_SW_AB: | |
4895 | s = "sw"; | |
4896 | goto st; | |
4897 | case M_SWC0_AB: | |
4898 | s = "swc0"; | |
bdaaa2e1 | 4899 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4900 | coproc = 1; |
4901 | goto st; | |
4902 | case M_SWC1_AB: | |
4903 | s = "swc1"; | |
bdaaa2e1 | 4904 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4905 | coproc = 1; |
4906 | goto st; | |
4907 | case M_SWC2_AB: | |
4908 | s = "swc2"; | |
bdaaa2e1 | 4909 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4910 | coproc = 1; |
4911 | goto st; | |
4912 | case M_SWC3_AB: | |
4913 | s = "swc3"; | |
bdaaa2e1 | 4914 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4915 | coproc = 1; |
4916 | goto st; | |
4917 | case M_SWL_AB: | |
4918 | s = "swl"; | |
4919 | goto st; | |
4920 | case M_SWR_AB: | |
4921 | s = "swr"; | |
4922 | goto st; | |
4923 | case M_SC_AB: | |
4924 | s = "sc"; | |
4925 | goto st; | |
4926 | case M_SCD_AB: | |
4927 | s = "scd"; | |
4928 | goto st; | |
4929 | case M_SDC1_AB: | |
ec68c924 | 4930 | if (mips_arch == CPU_R4650) |
252b5132 RH |
4931 | { |
4932 | as_bad (_("opcode not supported on this processor")); | |
4933 | return; | |
4934 | } | |
4935 | s = "sdc1"; | |
4936 | coproc = 1; | |
bdaaa2e1 | 4937 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4938 | goto st; |
4939 | case M_SDC2_AB: | |
4940 | s = "sdc2"; | |
bdaaa2e1 | 4941 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4942 | coproc = 1; |
4943 | goto st; | |
4944 | case M_SDC3_AB: | |
4945 | s = "sdc3"; | |
bdaaa2e1 | 4946 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4947 | coproc = 1; |
4948 | goto st; | |
4949 | case M_SDL_AB: | |
4950 | s = "sdl"; | |
4951 | goto st; | |
4952 | case M_SDR_AB: | |
4953 | s = "sdr"; | |
4954 | st: | |
4955 | tempreg = AT; | |
4956 | used_at = 1; | |
4957 | ld_st: | |
bdaaa2e1 | 4958 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4959 | if (mask == M_LWC1_AB |
4960 | || mask == M_SWC1_AB | |
4961 | || mask == M_LDC1_AB | |
4962 | || mask == M_SDC1_AB | |
4963 | || mask == M_L_DAB | |
4964 | || mask == M_S_DAB) | |
4965 | fmt = "T,o(b)"; | |
4966 | else if (coproc) | |
4967 | fmt = "E,o(b)"; | |
4968 | else | |
4969 | fmt = "t,o(b)"; | |
4970 | ||
4971 | if (offset_expr.X_op != O_constant | |
4972 | && offset_expr.X_op != O_symbol) | |
4973 | { | |
4974 | as_bad (_("expression too complex")); | |
4975 | offset_expr.X_op = O_constant; | |
4976 | } | |
4977 | ||
4978 | /* A constant expression in PIC code can be handled just as it | |
4979 | is in non PIC code. */ | |
4980 | if (mips_pic == NO_PIC | |
4981 | || offset_expr.X_op == O_constant) | |
4982 | { | |
4983 | /* If this is a reference to a GP relative symbol, and there | |
4984 | is no base register, we want | |
4985 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
4986 | Otherwise, if there is no base register, we want | |
4987 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4988 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
4989 | If we have a constant, we need two instructions anyhow, | |
4990 | so we always use the latter form. | |
4991 | ||
4992 | If we have a base register, and this is a reference to a | |
4993 | GP relative symbol, we want | |
4994 | addu $tempreg,$breg,$gp | |
4995 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL) | |
4996 | Otherwise we want | |
4997 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4998 | addu $tempreg,$tempreg,$breg | |
4999 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5000 | With a constant we always use the latter case. */ | |
5001 | if (breg == 0) | |
5002 | { | |
e7d556df | 5003 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5004 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5005 | p = NULL; | |
5006 | else | |
5007 | { | |
5008 | frag_grow (20); | |
5009 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5010 | treg, (int) BFD_RELOC_MIPS_GPREL, GP); | |
5011 | p = frag_var (rs_machine_dependent, 8, 0, | |
5012 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
5013 | (mips_opts.warn_about_macros | |
5014 | || (used_at | |
5015 | && mips_opts.noat))), | |
5016 | offset_expr.X_add_symbol, (offsetT) 0, | |
5017 | (char *) NULL); | |
5018 | used_at = 0; | |
5019 | } | |
5020 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5021 | if (p != NULL) | |
5022 | p += 4; | |
5023 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5024 | (int) BFD_RELOC_LO16, tempreg); | |
5025 | } | |
5026 | else | |
5027 | { | |
e7d556df | 5028 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5029 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5030 | p = NULL; | |
5031 | else | |
5032 | { | |
5033 | frag_grow (28); | |
5034 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5035 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5036 | "d,v,t", tempreg, breg, GP); |
5037 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5038 | treg, (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5039 | p = frag_var (rs_machine_dependent, 12, 0, | |
5040 | RELAX_ENCODE (8, 12, 0, 8, 0, 0), | |
5041 | offset_expr.X_add_symbol, (offsetT) 0, | |
5042 | (char *) NULL); | |
5043 | } | |
5044 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5045 | if (p != NULL) | |
5046 | p += 4; | |
5047 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5048 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5049 | "d,v,t", tempreg, tempreg, breg); |
5050 | if (p != NULL) | |
5051 | p += 4; | |
5052 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5053 | (int) BFD_RELOC_LO16, tempreg); | |
5054 | } | |
5055 | } | |
5056 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
5057 | { | |
5058 | /* If this is a reference to an external symbol, we want | |
5059 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5060 | nop | |
5061 | <op> $treg,0($tempreg) | |
5062 | Otherwise we want | |
5063 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5064 | nop | |
5065 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5066 | <op> $treg,0($tempreg) | |
5067 | If there is a base register, we add it to $tempreg before | |
5068 | the <op>. If there is a constant, we stick it in the | |
5069 | <op> instruction. We don't handle constants larger than | |
5070 | 16 bits, because we have no way to load the upper 16 bits | |
5071 | (actually, we could handle them for the subset of cases | |
5072 | in which we are not using $at). */ | |
5073 | assert (offset_expr.X_op == O_symbol); | |
5074 | expr1.X_add_number = offset_expr.X_add_number; | |
5075 | offset_expr.X_add_number = 0; | |
5076 | if (expr1.X_add_number < -0x8000 | |
5077 | || expr1.X_add_number >= 0x8000) | |
5078 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5079 | frag_grow (20); | |
5080 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5081 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5082 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); |
5083 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
bdaaa2e1 | 5084 | p = frag_var (rs_machine_dependent, 4, 0, |
252b5132 RH |
5085 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), |
5086 | offset_expr.X_add_symbol, (offsetT) 0, | |
5087 | (char *) NULL); | |
5088 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5089 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5090 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5091 | if (breg != 0) | |
5092 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5093 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5094 | "d,v,t", tempreg, tempreg, breg); |
5095 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5096 | (int) BFD_RELOC_LO16, tempreg); | |
5097 | } | |
5098 | else if (mips_pic == SVR4_PIC) | |
5099 | { | |
5100 | int gpdel; | |
5101 | ||
5102 | /* If this is a reference to an external symbol, we want | |
5103 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5104 | addu $tempreg,$tempreg,$gp | |
5105 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
5106 | <op> $treg,0($tempreg) | |
5107 | Otherwise we want | |
5108 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5109 | nop | |
5110 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5111 | <op> $treg,0($tempreg) | |
5112 | If there is a base register, we add it to $tempreg before | |
5113 | the <op>. If there is a constant, we stick it in the | |
5114 | <op> instruction. We don't handle constants larger than | |
5115 | 16 bits, because we have no way to load the upper 16 bits | |
5116 | (actually, we could handle them for the subset of cases | |
5117 | in which we are not using $at). */ | |
5118 | assert (offset_expr.X_op == O_symbol); | |
5119 | expr1.X_add_number = offset_expr.X_add_number; | |
5120 | offset_expr.X_add_number = 0; | |
5121 | if (expr1.X_add_number < -0x8000 | |
5122 | || expr1.X_add_number >= 0x8000) | |
5123 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5124 | if (reg_needs_delay (GP)) | |
5125 | gpdel = 4; | |
5126 | else | |
5127 | gpdel = 0; | |
5128 | frag_grow (36); | |
5129 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5130 | tempreg, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5131 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5132 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5133 | "d,v,t", tempreg, tempreg, GP); |
5134 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5135 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5136 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16, |
5137 | tempreg); | |
5138 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5139 | RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0), | |
5140 | offset_expr.X_add_symbol, (offsetT) 0, (char *) NULL); | |
5141 | if (gpdel > 0) | |
5142 | { | |
5143 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5144 | p += 4; | |
5145 | } | |
5146 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5147 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5148 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); |
5149 | p += 4; | |
5150 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5151 | p += 4; | |
5152 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5153 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5154 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5155 | if (breg != 0) | |
5156 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5157 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5158 | "d,v,t", tempreg, tempreg, breg); |
5159 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5160 | (int) BFD_RELOC_LO16, tempreg); | |
5161 | } | |
5162 | else if (mips_pic == EMBEDDED_PIC) | |
5163 | { | |
5164 | /* If there is no base register, we want | |
5165 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5166 | If there is a base register, we want | |
5167 | addu $tempreg,$breg,$gp | |
5168 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL) | |
5169 | */ | |
5170 | assert (offset_expr.X_op == O_symbol); | |
5171 | if (breg == 0) | |
5172 | { | |
5173 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5174 | treg, (int) BFD_RELOC_MIPS_GPREL, GP); | |
5175 | used_at = 0; | |
5176 | } | |
5177 | else | |
5178 | { | |
5179 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5180 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5181 | "d,v,t", tempreg, breg, GP); |
5182 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5183 | treg, (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5184 | } | |
5185 | } | |
5186 | else | |
5187 | abort (); | |
5188 | ||
5189 | if (! used_at) | |
5190 | return; | |
5191 | ||
5192 | break; | |
5193 | ||
5194 | case M_LI: | |
5195 | case M_LI_S: | |
5196 | load_register (&icnt, treg, &imm_expr, 0); | |
5197 | return; | |
5198 | ||
5199 | case M_DLI: | |
5200 | load_register (&icnt, treg, &imm_expr, 1); | |
5201 | return; | |
5202 | ||
5203 | case M_LI_SS: | |
5204 | if (imm_expr.X_op == O_constant) | |
5205 | { | |
5206 | load_register (&icnt, AT, &imm_expr, 0); | |
5207 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5208 | "mtc1", "t,G", AT, treg); | |
5209 | break; | |
5210 | } | |
5211 | else | |
5212 | { | |
5213 | assert (offset_expr.X_op == O_symbol | |
5214 | && strcmp (segment_name (S_GET_SEGMENT | |
5215 | (offset_expr.X_add_symbol)), | |
5216 | ".lit4") == 0 | |
5217 | && offset_expr.X_add_number == 0); | |
5218 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5219 | treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5220 | return; | |
5221 | } | |
5222 | ||
5223 | case M_LI_D: | |
ca4e0257 RS |
5224 | /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits |
5225 | wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high | |
5226 | order 32 bits of the value and the low order 32 bits are either | |
5227 | zero or in OFFSET_EXPR. */ | |
252b5132 RH |
5228 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
5229 | { | |
ca4e0257 | 5230 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5231 | load_register (&icnt, treg, &imm_expr, 1); |
5232 | else | |
5233 | { | |
5234 | int hreg, lreg; | |
5235 | ||
5236 | if (target_big_endian) | |
5237 | { | |
5238 | hreg = treg; | |
5239 | lreg = treg + 1; | |
5240 | } | |
5241 | else | |
5242 | { | |
5243 | hreg = treg + 1; | |
5244 | lreg = treg; | |
5245 | } | |
5246 | ||
5247 | if (hreg <= 31) | |
5248 | load_register (&icnt, hreg, &imm_expr, 0); | |
5249 | if (lreg <= 31) | |
5250 | { | |
5251 | if (offset_expr.X_op == O_absent) | |
ea1fb5dc | 5252 | move_register (&icnt, lreg, 0); |
252b5132 RH |
5253 | else |
5254 | { | |
5255 | assert (offset_expr.X_op == O_constant); | |
5256 | load_register (&icnt, lreg, &offset_expr, 0); | |
5257 | } | |
5258 | } | |
5259 | } | |
5260 | return; | |
5261 | } | |
5262 | ||
5263 | /* We know that sym is in the .rdata section. First we get the | |
5264 | upper 16 bits of the address. */ | |
5265 | if (mips_pic == NO_PIC) | |
5266 | { | |
5267 | /* FIXME: This won't work for a 64 bit address. */ | |
5268 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5269 | } | |
5270 | else if (mips_pic == SVR4_PIC) | |
5271 | { | |
5272 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5273 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5274 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
5275 | } | |
5276 | else if (mips_pic == EMBEDDED_PIC) | |
5277 | { | |
5278 | /* For embedded PIC we pick up the entire address off $gp in | |
5279 | a single instruction. */ | |
5280 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5281 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5282 | "t,r,j", AT, GP, (int) BFD_RELOC_MIPS_GPREL); |
5283 | offset_expr.X_op = O_constant; | |
5284 | offset_expr.X_add_number = 0; | |
5285 | } | |
5286 | else | |
5287 | abort (); | |
bdaaa2e1 | 5288 | |
252b5132 | 5289 | /* Now we load the register(s). */ |
ca4e0257 | 5290 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5291 | macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)", |
5292 | treg, (int) BFD_RELOC_LO16, AT); | |
5293 | else | |
5294 | { | |
5295 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5296 | treg, (int) BFD_RELOC_LO16, AT); | |
5297 | if (treg != 31) | |
5298 | { | |
5299 | /* FIXME: How in the world do we deal with the possible | |
5300 | overflow here? */ | |
5301 | offset_expr.X_add_number += 4; | |
5302 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5303 | treg + 1, (int) BFD_RELOC_LO16, AT); | |
5304 | } | |
5305 | } | |
5306 | ||
5307 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5308 | does not become a variant frag. */ | |
5309 | frag_wane (frag_now); | |
5310 | frag_new (0); | |
5311 | ||
5312 | break; | |
5313 | ||
5314 | case M_LI_DD: | |
ca4e0257 RS |
5315 | /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits |
5316 | wide, IMM_EXPR is the entire value and the GPRs are known to be 64 | |
5317 | bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of | |
5318 | the value and the low order 32 bits are either zero or in | |
5319 | OFFSET_EXPR. */ | |
252b5132 RH |
5320 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
5321 | { | |
ca4e0257 RS |
5322 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS); |
5323 | if (HAVE_64BIT_FPRS) | |
5324 | { | |
5325 | assert (HAVE_64BIT_GPRS); | |
5326 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5327 | "dmtc1", "t,S", AT, treg); | |
5328 | } | |
252b5132 RH |
5329 | else |
5330 | { | |
5331 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5332 | "mtc1", "t,G", AT, treg + 1); | |
5333 | if (offset_expr.X_op == O_absent) | |
5334 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5335 | "mtc1", "t,G", 0, treg); | |
5336 | else | |
5337 | { | |
5338 | assert (offset_expr.X_op == O_constant); | |
5339 | load_register (&icnt, AT, &offset_expr, 0); | |
5340 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5341 | "mtc1", "t,G", AT, treg); | |
5342 | } | |
5343 | } | |
5344 | break; | |
5345 | } | |
5346 | ||
5347 | assert (offset_expr.X_op == O_symbol | |
5348 | && offset_expr.X_add_number == 0); | |
5349 | s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol)); | |
5350 | if (strcmp (s, ".lit8") == 0) | |
5351 | { | |
e7af610e | 5352 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5353 | { |
5354 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5355 | "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5356 | return; | |
5357 | } | |
5358 | breg = GP; | |
5359 | r = BFD_RELOC_MIPS_LITERAL; | |
5360 | goto dob; | |
5361 | } | |
5362 | else | |
5363 | { | |
5364 | assert (strcmp (s, RDATA_SECTION_NAME) == 0); | |
5365 | if (mips_pic == SVR4_PIC) | |
5366 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5367 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5368 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
5369 | else | |
5370 | { | |
5371 | /* FIXME: This won't work for a 64 bit address. */ | |
5372 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5373 | } | |
bdaaa2e1 | 5374 | |
e7af610e | 5375 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5376 | { |
5377 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5378 | "T,o(b)", treg, (int) BFD_RELOC_LO16, AT); | |
5379 | ||
5380 | /* To avoid confusion in tc_gen_reloc, we must ensure | |
5381 | that this does not become a variant frag. */ | |
5382 | frag_wane (frag_now); | |
5383 | frag_new (0); | |
5384 | ||
5385 | break; | |
5386 | } | |
5387 | breg = AT; | |
5388 | r = BFD_RELOC_LO16; | |
5389 | goto dob; | |
5390 | } | |
5391 | ||
5392 | case M_L_DOB: | |
ec68c924 | 5393 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5394 | { |
5395 | as_bad (_("opcode not supported on this processor")); | |
5396 | return; | |
5397 | } | |
5398 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5399 | to adjust when loading from memory. */ | |
5400 | r = BFD_RELOC_LO16; | |
5401 | dob: | |
e7af610e | 5402 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
5403 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", |
5404 | target_big_endian ? treg + 1 : treg, | |
5405 | (int) r, breg); | |
5406 | /* FIXME: A possible overflow which I don't know how to deal | |
5407 | with. */ | |
5408 | offset_expr.X_add_number += 4; | |
5409 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5410 | target_big_endian ? treg : treg + 1, | |
5411 | (int) r, breg); | |
5412 | ||
5413 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5414 | does not become a variant frag. */ | |
5415 | frag_wane (frag_now); | |
5416 | frag_new (0); | |
5417 | ||
5418 | if (breg != AT) | |
5419 | return; | |
5420 | break; | |
5421 | ||
5422 | case M_L_DAB: | |
5423 | /* | |
5424 | * The MIPS assembler seems to check for X_add_number not | |
5425 | * being double aligned and generating: | |
5426 | * lui at,%hi(foo+1) | |
5427 | * addu at,at,v1 | |
5428 | * addiu at,at,%lo(foo+1) | |
5429 | * lwc1 f2,0(at) | |
5430 | * lwc1 f3,4(at) | |
5431 | * But, the resulting address is the same after relocation so why | |
5432 | * generate the extra instruction? | |
5433 | */ | |
ec68c924 | 5434 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5435 | { |
5436 | as_bad (_("opcode not supported on this processor")); | |
5437 | return; | |
5438 | } | |
bdaaa2e1 | 5439 | /* Itbl support may require additional care here. */ |
252b5132 | 5440 | coproc = 1; |
e7af610e | 5441 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5442 | { |
5443 | s = "ldc1"; | |
5444 | goto ld; | |
5445 | } | |
5446 | ||
5447 | s = "lwc1"; | |
5448 | fmt = "T,o(b)"; | |
5449 | goto ldd_std; | |
5450 | ||
5451 | case M_S_DAB: | |
ec68c924 | 5452 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5453 | { |
5454 | as_bad (_("opcode not supported on this processor")); | |
5455 | return; | |
5456 | } | |
5457 | ||
e7af610e | 5458 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5459 | { |
5460 | s = "sdc1"; | |
5461 | goto st; | |
5462 | } | |
5463 | ||
5464 | s = "swc1"; | |
5465 | fmt = "T,o(b)"; | |
bdaaa2e1 | 5466 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5467 | coproc = 1; |
5468 | goto ldd_std; | |
5469 | ||
5470 | case M_LD_AB: | |
ca4e0257 | 5471 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5472 | { |
5473 | s = "ld"; | |
5474 | goto ld; | |
5475 | } | |
5476 | ||
5477 | s = "lw"; | |
5478 | fmt = "t,o(b)"; | |
5479 | goto ldd_std; | |
5480 | ||
5481 | case M_SD_AB: | |
ca4e0257 | 5482 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5483 | { |
5484 | s = "sd"; | |
5485 | goto st; | |
5486 | } | |
5487 | ||
5488 | s = "sw"; | |
5489 | fmt = "t,o(b)"; | |
5490 | ||
5491 | ldd_std: | |
5492 | if (offset_expr.X_op != O_symbol | |
5493 | && offset_expr.X_op != O_constant) | |
5494 | { | |
5495 | as_bad (_("expression too complex")); | |
5496 | offset_expr.X_op = O_constant; | |
5497 | } | |
5498 | ||
5499 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5500 | to adjust when loading from memory. We set coproc if we must | |
5501 | load $fn+1 first. */ | |
bdaaa2e1 | 5502 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5503 | if (! target_big_endian) |
5504 | coproc = 0; | |
5505 | ||
5506 | if (mips_pic == NO_PIC | |
5507 | || offset_expr.X_op == O_constant) | |
5508 | { | |
5509 | /* If this is a reference to a GP relative symbol, we want | |
5510 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5511 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL) | |
5512 | If we have a base register, we use this | |
5513 | addu $at,$breg,$gp | |
5514 | <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL) | |
5515 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL) | |
5516 | If this is not a GP relative symbol, we want | |
5517 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5518 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5519 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5520 | If there is a base register, we add it to $at after the | |
5521 | lui instruction. If there is a constant, we always use | |
5522 | the last case. */ | |
e7d556df | 5523 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5524 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5525 | { | |
5526 | p = NULL; | |
5527 | used_at = 1; | |
5528 | } | |
5529 | else | |
5530 | { | |
5531 | int off; | |
5532 | ||
5533 | if (breg == 0) | |
5534 | { | |
5535 | frag_grow (28); | |
5536 | tempreg = GP; | |
5537 | off = 0; | |
5538 | used_at = 0; | |
5539 | } | |
5540 | else | |
5541 | { | |
5542 | frag_grow (36); | |
5543 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5544 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5545 | "d,v,t", AT, breg, GP); |
5546 | tempreg = AT; | |
5547 | off = 4; | |
5548 | used_at = 1; | |
5549 | } | |
5550 | ||
beae10d5 | 5551 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5552 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
5553 | coproc ? treg + 1 : treg, | |
5554 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5555 | offset_expr.X_add_number += 4; | |
5556 | ||
5557 | /* Set mips_optimize to 2 to avoid inserting an | |
5558 | undesired nop. */ | |
5559 | hold_mips_optimize = mips_optimize; | |
5560 | mips_optimize = 2; | |
beae10d5 | 5561 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5562 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
5563 | coproc ? treg : treg + 1, | |
5564 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5565 | mips_optimize = hold_mips_optimize; | |
5566 | ||
5567 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
5568 | RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1, | |
5569 | used_at && mips_opts.noat), | |
5570 | offset_expr.X_add_symbol, (offsetT) 0, | |
5571 | (char *) NULL); | |
5572 | ||
5573 | /* We just generated two relocs. When tc_gen_reloc | |
5574 | handles this case, it will skip the first reloc and | |
5575 | handle the second. The second reloc already has an | |
5576 | extra addend of 4, which we added above. We must | |
5577 | subtract it out, and then subtract another 4 to make | |
5578 | the first reloc come out right. The second reloc | |
5579 | will come out right because we are going to add 4 to | |
5580 | offset_expr when we build its instruction below. | |
5581 | ||
5582 | If we have a symbol, then we don't want to include | |
5583 | the offset, because it will wind up being included | |
5584 | when we generate the reloc. */ | |
5585 | ||
5586 | if (offset_expr.X_op == O_constant) | |
5587 | offset_expr.X_add_number -= 8; | |
5588 | else | |
5589 | { | |
5590 | offset_expr.X_add_number = -4; | |
5591 | offset_expr.X_op = O_constant; | |
5592 | } | |
5593 | } | |
5594 | macro_build_lui (p, &icnt, &offset_expr, AT); | |
5595 | if (p != NULL) | |
5596 | p += 4; | |
5597 | if (breg != 0) | |
5598 | { | |
5599 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5600 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5601 | "d,v,t", AT, breg, AT); |
5602 | if (p != NULL) | |
5603 | p += 4; | |
5604 | } | |
beae10d5 | 5605 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5606 | macro_build (p, &icnt, &offset_expr, s, fmt, |
5607 | coproc ? treg + 1 : treg, | |
5608 | (int) BFD_RELOC_LO16, AT); | |
5609 | if (p != NULL) | |
5610 | p += 4; | |
5611 | /* FIXME: How do we handle overflow here? */ | |
5612 | offset_expr.X_add_number += 4; | |
beae10d5 | 5613 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5614 | macro_build (p, &icnt, &offset_expr, s, fmt, |
5615 | coproc ? treg : treg + 1, | |
5616 | (int) BFD_RELOC_LO16, AT); | |
bdaaa2e1 | 5617 | } |
252b5132 RH |
5618 | else if (mips_pic == SVR4_PIC && ! mips_big_got) |
5619 | { | |
5620 | int off; | |
5621 | ||
5622 | /* If this is a reference to an external symbol, we want | |
5623 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5624 | nop | |
5625 | <op> $treg,0($at) | |
5626 | <op> $treg+1,4($at) | |
5627 | Otherwise we want | |
5628 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5629 | nop | |
5630 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5631 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5632 | If there is a base register we add it to $at before the | |
5633 | lwc1 instructions. If there is a constant we include it | |
5634 | in the lwc1 instructions. */ | |
5635 | used_at = 1; | |
5636 | expr1.X_add_number = offset_expr.X_add_number; | |
5637 | offset_expr.X_add_number = 0; | |
5638 | if (expr1.X_add_number < -0x8000 | |
5639 | || expr1.X_add_number >= 0x8000 - 4) | |
5640 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5641 | if (breg == 0) | |
5642 | off = 0; | |
5643 | else | |
5644 | off = 4; | |
5645 | frag_grow (24 + off); | |
5646 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5647 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5648 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
5649 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
5650 | if (breg != 0) | |
5651 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5652 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 5653 | "d,v,t", AT, breg, AT); |
beae10d5 | 5654 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5655 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
5656 | coproc ? treg + 1 : treg, | |
5657 | (int) BFD_RELOC_LO16, AT); | |
5658 | expr1.X_add_number += 4; | |
5659 | ||
5660 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5661 | nop. */ | |
5662 | hold_mips_optimize = mips_optimize; | |
5663 | mips_optimize = 2; | |
beae10d5 | 5664 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5665 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
5666 | coproc ? treg : treg + 1, | |
5667 | (int) BFD_RELOC_LO16, AT); | |
5668 | mips_optimize = hold_mips_optimize; | |
5669 | ||
5670 | (void) frag_var (rs_machine_dependent, 0, 0, | |
5671 | RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0), | |
5672 | offset_expr.X_add_symbol, (offsetT) 0, | |
5673 | (char *) NULL); | |
5674 | } | |
5675 | else if (mips_pic == SVR4_PIC) | |
5676 | { | |
5677 | int gpdel, off; | |
5678 | ||
5679 | /* If this is a reference to an external symbol, we want | |
5680 | lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5681 | addu $at,$at,$gp | |
5682 | lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16) | |
5683 | nop | |
5684 | <op> $treg,0($at) | |
5685 | <op> $treg+1,4($at) | |
5686 | Otherwise we want | |
5687 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5688 | nop | |
5689 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5690 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5691 | If there is a base register we add it to $at before the | |
5692 | lwc1 instructions. If there is a constant we include it | |
5693 | in the lwc1 instructions. */ | |
5694 | used_at = 1; | |
5695 | expr1.X_add_number = offset_expr.X_add_number; | |
5696 | offset_expr.X_add_number = 0; | |
5697 | if (expr1.X_add_number < -0x8000 | |
5698 | || expr1.X_add_number >= 0x8000 - 4) | |
5699 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5700 | if (reg_needs_delay (GP)) | |
5701 | gpdel = 4; | |
5702 | else | |
5703 | gpdel = 0; | |
5704 | if (breg == 0) | |
5705 | off = 0; | |
5706 | else | |
5707 | off = 4; | |
5708 | frag_grow (56); | |
5709 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5710 | AT, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5711 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5712 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5713 | "d,v,t", AT, AT, GP); |
5714 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5715 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5716 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT); |
5717 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
5718 | if (breg != 0) | |
5719 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5720 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 5721 | "d,v,t", AT, breg, AT); |
beae10d5 | 5722 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5723 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
5724 | coproc ? treg + 1 : treg, | |
5725 | (int) BFD_RELOC_LO16, AT); | |
5726 | expr1.X_add_number += 4; | |
5727 | ||
5728 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5729 | nop. */ | |
5730 | hold_mips_optimize = mips_optimize; | |
5731 | mips_optimize = 2; | |
beae10d5 | 5732 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5733 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
5734 | coproc ? treg : treg + 1, | |
5735 | (int) BFD_RELOC_LO16, AT); | |
5736 | mips_optimize = hold_mips_optimize; | |
5737 | expr1.X_add_number -= 4; | |
5738 | ||
5739 | p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0, | |
5740 | RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel, | |
5741 | 8 + gpdel + off, 1, 0), | |
5742 | offset_expr.X_add_symbol, (offsetT) 0, | |
5743 | (char *) NULL); | |
5744 | if (gpdel > 0) | |
5745 | { | |
5746 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5747 | p += 4; | |
5748 | } | |
5749 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5750 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5751 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
5752 | p += 4; | |
5753 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5754 | p += 4; | |
5755 | if (breg != 0) | |
5756 | { | |
5757 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5758 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5759 | "d,v,t", AT, breg, AT); |
5760 | p += 4; | |
5761 | } | |
beae10d5 | 5762 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5763 | macro_build (p, &icnt, &expr1, s, fmt, |
5764 | coproc ? treg + 1 : treg, | |
5765 | (int) BFD_RELOC_LO16, AT); | |
5766 | p += 4; | |
5767 | expr1.X_add_number += 4; | |
5768 | ||
5769 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5770 | nop. */ | |
5771 | hold_mips_optimize = mips_optimize; | |
5772 | mips_optimize = 2; | |
beae10d5 | 5773 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5774 | macro_build (p, &icnt, &expr1, s, fmt, |
5775 | coproc ? treg : treg + 1, | |
5776 | (int) BFD_RELOC_LO16, AT); | |
5777 | mips_optimize = hold_mips_optimize; | |
5778 | } | |
5779 | else if (mips_pic == EMBEDDED_PIC) | |
5780 | { | |
5781 | /* If there is no base register, we use | |
5782 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5783 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL) | |
5784 | If we have a base register, we use | |
5785 | addu $at,$breg,$gp | |
5786 | <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL) | |
5787 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL) | |
5788 | */ | |
5789 | if (breg == 0) | |
5790 | { | |
5791 | tempreg = GP; | |
5792 | used_at = 0; | |
5793 | } | |
5794 | else | |
5795 | { | |
5796 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5797 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5798 | "d,v,t", AT, breg, GP); |
5799 | tempreg = AT; | |
5800 | used_at = 1; | |
5801 | } | |
5802 | ||
beae10d5 | 5803 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5804 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
5805 | coproc ? treg + 1 : treg, | |
5806 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5807 | offset_expr.X_add_number += 4; | |
beae10d5 | 5808 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5809 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
5810 | coproc ? treg : treg + 1, | |
5811 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5812 | } | |
5813 | else | |
5814 | abort (); | |
5815 | ||
5816 | if (! used_at) | |
5817 | return; | |
5818 | ||
5819 | break; | |
5820 | ||
5821 | case M_LD_OB: | |
5822 | s = "lw"; | |
5823 | goto sd_ob; | |
5824 | case M_SD_OB: | |
5825 | s = "sw"; | |
5826 | sd_ob: | |
ca4e0257 | 5827 | assert (HAVE_32BIT_ADDRESSES); |
252b5132 RH |
5828 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, |
5829 | (int) BFD_RELOC_LO16, breg); | |
5830 | offset_expr.X_add_number += 4; | |
5831 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1, | |
5832 | (int) BFD_RELOC_LO16, breg); | |
5833 | return; | |
5834 | ||
5835 | /* New code added to support COPZ instructions. | |
5836 | This code builds table entries out of the macros in mip_opcodes. | |
5837 | R4000 uses interlocks to handle coproc delays. | |
5838 | Other chips (like the R3000) require nops to be inserted for delays. | |
5839 | ||
f72c8c98 | 5840 | FIXME: Currently, we require that the user handle delays. |
252b5132 RH |
5841 | In order to fill delay slots for non-interlocked chips, |
5842 | we must have a way to specify delays based on the coprocessor. | |
5843 | Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc. | |
5844 | What are the side-effects of the cop instruction? | |
5845 | What cache support might we have and what are its effects? | |
5846 | Both coprocessor & memory require delays. how long??? | |
bdaaa2e1 | 5847 | What registers are read/set/modified? |
252b5132 RH |
5848 | |
5849 | If an itbl is provided to interpret cop instructions, | |
bdaaa2e1 | 5850 | this knowledge can be encoded in the itbl spec. */ |
252b5132 RH |
5851 | |
5852 | case M_COP0: | |
5853 | s = "c0"; | |
5854 | goto copz; | |
5855 | case M_COP1: | |
5856 | s = "c1"; | |
5857 | goto copz; | |
5858 | case M_COP2: | |
5859 | s = "c2"; | |
5860 | goto copz; | |
5861 | case M_COP3: | |
5862 | s = "c3"; | |
5863 | copz: | |
5864 | /* For now we just do C (same as Cz). The parameter will be | |
5865 | stored in insn_opcode by mips_ip. */ | |
5866 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C", | |
5867 | ip->insn_opcode); | |
5868 | return; | |
5869 | ||
ea1fb5dc RS |
5870 | case M_MOVE: |
5871 | move_register (&icnt, dreg, sreg); | |
5872 | return; | |
5873 | ||
252b5132 RH |
5874 | #ifdef LOSING_COMPILER |
5875 | default: | |
5876 | /* Try and see if this is a new itbl instruction. | |
5877 | This code builds table entries out of the macros in mip_opcodes. | |
5878 | FIXME: For now we just assemble the expression and pass it's | |
5879 | value along as a 32-bit immediate. | |
bdaaa2e1 | 5880 | We may want to have the assembler assemble this value, |
252b5132 RH |
5881 | so that we gain the assembler's knowledge of delay slots, |
5882 | symbols, etc. | |
5883 | Would it be more efficient to use mask (id) here? */ | |
bdaaa2e1 | 5884 | if (itbl_have_entries |
252b5132 | 5885 | && (immed_expr = itbl_assemble (ip->insn_mo->name, ""))) |
beae10d5 | 5886 | { |
252b5132 RH |
5887 | s = ip->insn_mo->name; |
5888 | s2 = "cop3"; | |
5889 | coproc = ITBL_DECODE_PNUM (immed_expr);; | |
5890 | macro_build ((char *) NULL, &icnt, &immed_expr, s, "C"); | |
5891 | return; | |
beae10d5 | 5892 | } |
252b5132 RH |
5893 | macro2 (ip); |
5894 | return; | |
5895 | } | |
5896 | if (mips_opts.noat) | |
5897 | as_warn (_("Macro used $at after \".set noat\"")); | |
5898 | } | |
bdaaa2e1 | 5899 | |
252b5132 RH |
5900 | static void |
5901 | macro2 (ip) | |
5902 | struct mips_cl_insn *ip; | |
5903 | { | |
5904 | register int treg, sreg, dreg, breg; | |
5905 | int tempreg; | |
5906 | int mask; | |
5907 | int icnt = 0; | |
5908 | int used_at; | |
5909 | expressionS expr1; | |
5910 | const char *s; | |
5911 | const char *s2; | |
5912 | const char *fmt; | |
5913 | int likely = 0; | |
5914 | int dbl = 0; | |
5915 | int coproc = 0; | |
5916 | int lr = 0; | |
5917 | int imm = 0; | |
5918 | int off; | |
5919 | offsetT maxnum; | |
5920 | bfd_reloc_code_real_type r; | |
5921 | char *p; | |
bdaaa2e1 | 5922 | |
252b5132 RH |
5923 | treg = (ip->insn_opcode >> 16) & 0x1f; |
5924 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
5925 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
5926 | mask = ip->insn_mo->mask; | |
bdaaa2e1 | 5927 | |
252b5132 RH |
5928 | expr1.X_op = O_constant; |
5929 | expr1.X_op_symbol = NULL; | |
5930 | expr1.X_add_symbol = NULL; | |
5931 | expr1.X_add_number = 1; | |
bdaaa2e1 | 5932 | |
252b5132 RH |
5933 | switch (mask) |
5934 | { | |
5935 | #endif /* LOSING_COMPILER */ | |
5936 | ||
5937 | case M_DMUL: | |
5938 | dbl = 1; | |
5939 | case M_MUL: | |
5940 | macro_build ((char *) NULL, &icnt, NULL, | |
5941 | dbl ? "dmultu" : "multu", | |
5942 | "s,t", sreg, treg); | |
5943 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
5944 | return; | |
5945 | ||
5946 | case M_DMUL_I: | |
5947 | dbl = 1; | |
5948 | case M_MUL_I: | |
5949 | /* The MIPS assembler some times generates shifts and adds. I'm | |
5950 | not trying to be that fancy. GCC should do this for us | |
5951 | anyway. */ | |
5952 | load_register (&icnt, AT, &imm_expr, dbl); | |
5953 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 5954 | dbl ? "dmult" : "mult", "s,t", sreg, AT); |
252b5132 RH |
5955 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); |
5956 | break; | |
5957 | ||
5958 | case M_DMULO_I: | |
5959 | dbl = 1; | |
5960 | case M_MULO_I: | |
5961 | imm = 1; | |
5962 | goto do_mulo; | |
5963 | ||
5964 | case M_DMULO: | |
5965 | dbl = 1; | |
5966 | case M_MULO: | |
5967 | do_mulo: | |
5968 | mips_emit_delays (true); | |
5969 | ++mips_opts.noreorder; | |
5970 | mips_any_noreorder = 1; | |
5971 | if (imm) | |
5972 | load_register (&icnt, AT, &imm_expr, dbl); | |
5973 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 5974 | dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg); |
252b5132 RH |
5975 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); |
5976 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 5977 | dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, 31); |
252b5132 RH |
5978 | macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT); |
5979 | if (mips_trap) | |
5980 | macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", dreg, AT); | |
5981 | else | |
5982 | { | |
5983 | expr1.X_add_number = 8; | |
5984 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT); | |
5985 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
beae10d5 | 5986 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); |
252b5132 RH |
5987 | } |
5988 | --mips_opts.noreorder; | |
5989 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
5990 | break; | |
5991 | ||
5992 | case M_DMULOU_I: | |
5993 | dbl = 1; | |
5994 | case M_MULOU_I: | |
5995 | imm = 1; | |
5996 | goto do_mulou; | |
5997 | ||
5998 | case M_DMULOU: | |
5999 | dbl = 1; | |
6000 | case M_MULOU: | |
6001 | do_mulou: | |
6002 | mips_emit_delays (true); | |
6003 | ++mips_opts.noreorder; | |
6004 | mips_any_noreorder = 1; | |
6005 | if (imm) | |
6006 | load_register (&icnt, AT, &imm_expr, dbl); | |
6007 | macro_build ((char *) NULL, &icnt, NULL, | |
6008 | dbl ? "dmultu" : "multu", | |
6009 | "s,t", sreg, imm ? AT : treg); | |
6010 | macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT); | |
6011 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6012 | if (mips_trap) | |
6013 | macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", AT, 0); | |
6014 | else | |
6015 | { | |
6016 | expr1.X_add_number = 8; | |
6017 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0); | |
6018 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
beae10d5 | 6019 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); |
252b5132 RH |
6020 | } |
6021 | --mips_opts.noreorder; | |
6022 | break; | |
6023 | ||
6024 | case M_ROL: | |
6025 | macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg); | |
6026 | macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT); | |
6027 | macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg, | |
6028 | treg); | |
6029 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6030 | break; | |
6031 | ||
6032 | case M_ROL_I: | |
6033 | if (imm_expr.X_op != O_constant) | |
6034 | as_bad (_("rotate count too large")); | |
6035 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg, | |
6036 | (int) (imm_expr.X_add_number & 0x1f)); | |
6037 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, | |
6038 | (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6039 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6040 | break; | |
6041 | ||
6042 | case M_ROR: | |
6043 | macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg); | |
6044 | macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT); | |
6045 | macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg, | |
6046 | treg); | |
6047 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6048 | break; | |
6049 | ||
6050 | case M_ROR_I: | |
6051 | if (imm_expr.X_op != O_constant) | |
6052 | as_bad (_("rotate count too large")); | |
6053 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg, | |
6054 | (int) (imm_expr.X_add_number & 0x1f)); | |
6055 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg, | |
6056 | (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6057 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6058 | break; | |
6059 | ||
6060 | case M_S_DOB: | |
ec68c924 | 6061 | if (mips_arch == CPU_R4650) |
252b5132 RH |
6062 | { |
6063 | as_bad (_("opcode not supported on this processor")); | |
6064 | return; | |
6065 | } | |
e7af610e | 6066 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
6067 | /* Even on a big endian machine $fn comes before $fn+1. We have |
6068 | to adjust when storing to memory. */ | |
6069 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6070 | target_big_endian ? treg + 1 : treg, | |
6071 | (int) BFD_RELOC_LO16, breg); | |
6072 | offset_expr.X_add_number += 4; | |
6073 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6074 | target_big_endian ? treg : treg + 1, | |
6075 | (int) BFD_RELOC_LO16, breg); | |
6076 | return; | |
6077 | ||
6078 | case M_SEQ: | |
6079 | if (sreg == 0) | |
6080 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6081 | treg, (int) BFD_RELOC_LO16); | |
6082 | else if (treg == 0) | |
6083 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6084 | sreg, (int) BFD_RELOC_LO16); | |
6085 | else | |
6086 | { | |
6087 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6088 | sreg, treg); | |
6089 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6090 | dreg, (int) BFD_RELOC_LO16); | |
6091 | } | |
6092 | return; | |
6093 | ||
6094 | case M_SEQ_I: | |
6095 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6096 | { | |
6097 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6098 | sreg, (int) BFD_RELOC_LO16); | |
6099 | return; | |
6100 | } | |
6101 | if (sreg == 0) | |
6102 | { | |
6103 | as_warn (_("Instruction %s: result is always false"), | |
6104 | ip->insn_mo->name); | |
ea1fb5dc | 6105 | move_register (&icnt, dreg, 0); |
252b5132 RH |
6106 | return; |
6107 | } | |
6108 | if (imm_expr.X_op == O_constant | |
6109 | && imm_expr.X_add_number >= 0 | |
6110 | && imm_expr.X_add_number < 0x10000) | |
6111 | { | |
6112 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, | |
6113 | sreg, (int) BFD_RELOC_LO16); | |
6114 | used_at = 0; | |
6115 | } | |
6116 | else if (imm_expr.X_op == O_constant | |
6117 | && imm_expr.X_add_number > -0x8000 | |
6118 | && imm_expr.X_add_number < 0) | |
6119 | { | |
6120 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6121 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
ca4e0257 | 6122 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6123 | "t,r,j", dreg, sreg, |
6124 | (int) BFD_RELOC_LO16); | |
6125 | used_at = 0; | |
6126 | } | |
6127 | else | |
6128 | { | |
6129 | load_register (&icnt, AT, &imm_expr, 0); | |
6130 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6131 | sreg, AT); | |
6132 | used_at = 1; | |
6133 | } | |
6134 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg, | |
6135 | (int) BFD_RELOC_LO16); | |
6136 | if (used_at) | |
6137 | break; | |
6138 | return; | |
6139 | ||
6140 | case M_SGE: /* sreg >= treg <==> not (sreg < treg) */ | |
6141 | s = "slt"; | |
6142 | goto sge; | |
6143 | case M_SGEU: | |
6144 | s = "sltu"; | |
6145 | sge: | |
6146 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg); | |
6147 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6148 | (int) BFD_RELOC_LO16); | |
6149 | return; | |
6150 | ||
6151 | case M_SGE_I: /* sreg >= I <==> not (sreg < I) */ | |
6152 | case M_SGEU_I: | |
6153 | if (imm_expr.X_op == O_constant | |
6154 | && imm_expr.X_add_number >= -0x8000 | |
6155 | && imm_expr.X_add_number < 0x8000) | |
6156 | { | |
6157 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6158 | mask == M_SGE_I ? "slti" : "sltiu", | |
6159 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6160 | used_at = 0; | |
6161 | } | |
6162 | else | |
6163 | { | |
6164 | load_register (&icnt, AT, &imm_expr, 0); | |
6165 | macro_build ((char *) NULL, &icnt, NULL, | |
6166 | mask == M_SGE_I ? "slt" : "sltu", | |
6167 | "d,v,t", dreg, sreg, AT); | |
6168 | used_at = 1; | |
6169 | } | |
6170 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6171 | (int) BFD_RELOC_LO16); | |
6172 | if (used_at) | |
6173 | break; | |
6174 | return; | |
6175 | ||
6176 | case M_SGT: /* sreg > treg <==> treg < sreg */ | |
6177 | s = "slt"; | |
6178 | goto sgt; | |
6179 | case M_SGTU: | |
6180 | s = "sltu"; | |
6181 | sgt: | |
6182 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg); | |
6183 | return; | |
6184 | ||
6185 | case M_SGT_I: /* sreg > I <==> I < sreg */ | |
6186 | s = "slt"; | |
6187 | goto sgti; | |
6188 | case M_SGTU_I: | |
6189 | s = "sltu"; | |
6190 | sgti: | |
6191 | load_register (&icnt, AT, &imm_expr, 0); | |
6192 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg); | |
6193 | break; | |
6194 | ||
6195 | case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */ | |
6196 | s = "slt"; | |
6197 | goto sle; | |
6198 | case M_SLEU: | |
6199 | s = "sltu"; | |
6200 | sle: | |
6201 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg); | |
6202 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6203 | (int) BFD_RELOC_LO16); | |
6204 | return; | |
6205 | ||
6206 | case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */ | |
6207 | s = "slt"; | |
6208 | goto slei; | |
6209 | case M_SLEU_I: | |
6210 | s = "sltu"; | |
6211 | slei: | |
6212 | load_register (&icnt, AT, &imm_expr, 0); | |
6213 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg); | |
6214 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6215 | (int) BFD_RELOC_LO16); | |
6216 | break; | |
6217 | ||
6218 | case M_SLT_I: | |
6219 | if (imm_expr.X_op == O_constant | |
6220 | && imm_expr.X_add_number >= -0x8000 | |
6221 | && imm_expr.X_add_number < 0x8000) | |
6222 | { | |
6223 | macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j", | |
6224 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6225 | return; | |
6226 | } | |
6227 | load_register (&icnt, AT, &imm_expr, 0); | |
6228 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT); | |
6229 | break; | |
6230 | ||
6231 | case M_SLTU_I: | |
6232 | if (imm_expr.X_op == O_constant | |
6233 | && imm_expr.X_add_number >= -0x8000 | |
6234 | && imm_expr.X_add_number < 0x8000) | |
6235 | { | |
6236 | macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j", | |
6237 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6238 | return; | |
6239 | } | |
6240 | load_register (&icnt, AT, &imm_expr, 0); | |
6241 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg, | |
6242 | AT); | |
6243 | break; | |
6244 | ||
6245 | case M_SNE: | |
6246 | if (sreg == 0) | |
6247 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6248 | treg); | |
6249 | else if (treg == 0) | |
6250 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6251 | sreg); | |
6252 | else | |
6253 | { | |
6254 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6255 | sreg, treg); | |
6256 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6257 | dreg); | |
6258 | } | |
6259 | return; | |
6260 | ||
6261 | case M_SNE_I: | |
6262 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6263 | { | |
6264 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6265 | sreg); | |
6266 | return; | |
6267 | } | |
6268 | if (sreg == 0) | |
6269 | { | |
6270 | as_warn (_("Instruction %s: result is always true"), | |
6271 | ip->insn_mo->name); | |
6272 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 6273 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6274 | "t,r,j", dreg, 0, (int) BFD_RELOC_LO16); |
6275 | return; | |
6276 | } | |
6277 | if (imm_expr.X_op == O_constant | |
6278 | && imm_expr.X_add_number >= 0 | |
6279 | && imm_expr.X_add_number < 0x10000) | |
6280 | { | |
6281 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", | |
6282 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6283 | used_at = 0; | |
6284 | } | |
6285 | else if (imm_expr.X_op == O_constant | |
6286 | && imm_expr.X_add_number > -0x8000 | |
6287 | && imm_expr.X_add_number < 0) | |
6288 | { | |
6289 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6290 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
ca4e0257 | 6291 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6292 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); |
6293 | used_at = 0; | |
6294 | } | |
6295 | else | |
6296 | { | |
6297 | load_register (&icnt, AT, &imm_expr, 0); | |
6298 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6299 | sreg, AT); | |
6300 | used_at = 1; | |
6301 | } | |
6302 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg); | |
6303 | if (used_at) | |
6304 | break; | |
6305 | return; | |
6306 | ||
6307 | case M_DSUB_I: | |
6308 | dbl = 1; | |
6309 | case M_SUB_I: | |
6310 | if (imm_expr.X_op == O_constant | |
6311 | && imm_expr.X_add_number > -0x8000 | |
6312 | && imm_expr.X_add_number <= 0x8000) | |
6313 | { | |
6314 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6315 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6316 | dbl ? "daddi" : "addi", | |
6317 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6318 | return; | |
6319 | } | |
6320 | load_register (&icnt, AT, &imm_expr, dbl); | |
6321 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 6322 | dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT); |
252b5132 RH |
6323 | break; |
6324 | ||
6325 | case M_DSUBU_I: | |
6326 | dbl = 1; | |
6327 | case M_SUBU_I: | |
6328 | if (imm_expr.X_op == O_constant | |
6329 | && imm_expr.X_add_number > -0x8000 | |
6330 | && imm_expr.X_add_number <= 0x8000) | |
6331 | { | |
6332 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6333 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6334 | dbl ? "daddiu" : "addiu", | |
6335 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6336 | return; | |
6337 | } | |
6338 | load_register (&icnt, AT, &imm_expr, dbl); | |
6339 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 6340 | dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT); |
252b5132 RH |
6341 | break; |
6342 | ||
6343 | case M_TEQ_I: | |
6344 | s = "teq"; | |
6345 | goto trap; | |
6346 | case M_TGE_I: | |
6347 | s = "tge"; | |
6348 | goto trap; | |
6349 | case M_TGEU_I: | |
6350 | s = "tgeu"; | |
6351 | goto trap; | |
6352 | case M_TLT_I: | |
6353 | s = "tlt"; | |
6354 | goto trap; | |
6355 | case M_TLTU_I: | |
6356 | s = "tltu"; | |
6357 | goto trap; | |
6358 | case M_TNE_I: | |
6359 | s = "tne"; | |
6360 | trap: | |
6361 | load_register (&icnt, AT, &imm_expr, 0); | |
6362 | macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT); | |
6363 | break; | |
6364 | ||
252b5132 | 6365 | case M_TRUNCWS: |
43841e91 | 6366 | case M_TRUNCWD: |
e7af610e | 6367 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
6368 | sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */ |
6369 | dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */ | |
6370 | ||
6371 | /* | |
6372 | * Is the double cfc1 instruction a bug in the mips assembler; | |
6373 | * or is there a reason for it? | |
6374 | */ | |
6375 | mips_emit_delays (true); | |
6376 | ++mips_opts.noreorder; | |
6377 | mips_any_noreorder = 1; | |
6378 | macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31); | |
6379 | macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31); | |
6380 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6381 | expr1.X_add_number = 3; | |
6382 | macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg, | |
6383 | (int) BFD_RELOC_LO16); | |
6384 | expr1.X_add_number = 2; | |
6385 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT, | |
6386 | (int) BFD_RELOC_LO16); | |
6387 | macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31); | |
6388 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6389 | macro_build ((char *) NULL, &icnt, NULL, | |
6390 | mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg); | |
6391 | macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31); | |
6392 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6393 | --mips_opts.noreorder; | |
6394 | break; | |
6395 | ||
6396 | case M_ULH: | |
6397 | s = "lb"; | |
6398 | goto ulh; | |
6399 | case M_ULHU: | |
6400 | s = "lbu"; | |
6401 | ulh: | |
6402 | if (offset_expr.X_add_number >= 0x7fff) | |
6403 | as_bad (_("operand overflow")); | |
6404 | /* avoid load delay */ | |
6405 | if (! target_big_endian) | |
6406 | offset_expr.X_add_number += 1; | |
6407 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6408 | (int) BFD_RELOC_LO16, breg); | |
6409 | if (! target_big_endian) | |
6410 | offset_expr.X_add_number -= 1; | |
6411 | else | |
6412 | offset_expr.X_add_number += 1; | |
6413 | macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT, | |
6414 | (int) BFD_RELOC_LO16, breg); | |
6415 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8); | |
6416 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT); | |
6417 | break; | |
6418 | ||
6419 | case M_ULD: | |
6420 | s = "ldl"; | |
6421 | s2 = "ldr"; | |
6422 | off = 7; | |
6423 | goto ulw; | |
6424 | case M_ULW: | |
6425 | s = "lwl"; | |
6426 | s2 = "lwr"; | |
6427 | off = 3; | |
6428 | ulw: | |
6429 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6430 | as_bad (_("operand overflow")); | |
6431 | if (! target_big_endian) | |
6432 | offset_expr.X_add_number += off; | |
6433 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6434 | (int) BFD_RELOC_LO16, breg); | |
6435 | if (! target_big_endian) | |
6436 | offset_expr.X_add_number -= off; | |
6437 | else | |
6438 | offset_expr.X_add_number += off; | |
6439 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
6440 | (int) BFD_RELOC_LO16, breg); | |
6441 | return; | |
6442 | ||
6443 | case M_ULD_A: | |
6444 | s = "ldl"; | |
6445 | s2 = "ldr"; | |
6446 | off = 7; | |
6447 | goto ulwa; | |
6448 | case M_ULW_A: | |
6449 | s = "lwl"; | |
6450 | s2 = "lwr"; | |
6451 | off = 3; | |
6452 | ulwa: | |
6453 | load_address (&icnt, AT, &offset_expr); | |
6454 | if (breg != 0) | |
6455 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6456 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6457 | "d,v,t", AT, AT, breg); |
6458 | if (! target_big_endian) | |
6459 | expr1.X_add_number = off; | |
6460 | else | |
6461 | expr1.X_add_number = 0; | |
6462 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
6463 | (int) BFD_RELOC_LO16, AT); | |
6464 | if (! target_big_endian) | |
6465 | expr1.X_add_number = 0; | |
6466 | else | |
6467 | expr1.X_add_number = off; | |
6468 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
6469 | (int) BFD_RELOC_LO16, AT); | |
6470 | break; | |
6471 | ||
6472 | case M_ULH_A: | |
6473 | case M_ULHU_A: | |
6474 | load_address (&icnt, AT, &offset_expr); | |
6475 | if (breg != 0) | |
6476 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6477 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6478 | "d,v,t", AT, AT, breg); |
6479 | if (target_big_endian) | |
6480 | expr1.X_add_number = 0; | |
6481 | macro_build ((char *) NULL, &icnt, &expr1, | |
6482 | mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg, | |
6483 | (int) BFD_RELOC_LO16, AT); | |
6484 | if (target_big_endian) | |
6485 | expr1.X_add_number = 1; | |
6486 | else | |
6487 | expr1.X_add_number = 0; | |
6488 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
6489 | (int) BFD_RELOC_LO16, AT); | |
6490 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, | |
6491 | treg, 8); | |
6492 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, | |
6493 | treg, AT); | |
6494 | break; | |
6495 | ||
6496 | case M_USH: | |
6497 | if (offset_expr.X_add_number >= 0x7fff) | |
6498 | as_bad (_("operand overflow")); | |
6499 | if (target_big_endian) | |
6500 | offset_expr.X_add_number += 1; | |
6501 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg, | |
6502 | (int) BFD_RELOC_LO16, breg); | |
6503 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8); | |
6504 | if (target_big_endian) | |
6505 | offset_expr.X_add_number -= 1; | |
6506 | else | |
6507 | offset_expr.X_add_number += 1; | |
6508 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT, | |
6509 | (int) BFD_RELOC_LO16, breg); | |
6510 | break; | |
6511 | ||
6512 | case M_USD: | |
6513 | s = "sdl"; | |
6514 | s2 = "sdr"; | |
6515 | off = 7; | |
6516 | goto usw; | |
6517 | case M_USW: | |
6518 | s = "swl"; | |
6519 | s2 = "swr"; | |
6520 | off = 3; | |
6521 | usw: | |
6522 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6523 | as_bad (_("operand overflow")); | |
6524 | if (! target_big_endian) | |
6525 | offset_expr.X_add_number += off; | |
6526 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6527 | (int) BFD_RELOC_LO16, breg); | |
6528 | if (! target_big_endian) | |
6529 | offset_expr.X_add_number -= off; | |
6530 | else | |
6531 | offset_expr.X_add_number += off; | |
6532 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
6533 | (int) BFD_RELOC_LO16, breg); | |
6534 | return; | |
6535 | ||
6536 | case M_USD_A: | |
6537 | s = "sdl"; | |
6538 | s2 = "sdr"; | |
6539 | off = 7; | |
6540 | goto uswa; | |
6541 | case M_USW_A: | |
6542 | s = "swl"; | |
6543 | s2 = "swr"; | |
6544 | off = 3; | |
6545 | uswa: | |
6546 | load_address (&icnt, AT, &offset_expr); | |
6547 | if (breg != 0) | |
6548 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6549 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6550 | "d,v,t", AT, AT, breg); |
6551 | if (! target_big_endian) | |
6552 | expr1.X_add_number = off; | |
6553 | else | |
6554 | expr1.X_add_number = 0; | |
6555 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
6556 | (int) BFD_RELOC_LO16, AT); | |
6557 | if (! target_big_endian) | |
6558 | expr1.X_add_number = 0; | |
6559 | else | |
6560 | expr1.X_add_number = off; | |
6561 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
6562 | (int) BFD_RELOC_LO16, AT); | |
6563 | break; | |
6564 | ||
6565 | case M_USH_A: | |
6566 | load_address (&icnt, AT, &offset_expr); | |
6567 | if (breg != 0) | |
6568 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6569 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6570 | "d,v,t", AT, AT, breg); |
6571 | if (! target_big_endian) | |
6572 | expr1.X_add_number = 0; | |
6573 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
6574 | (int) BFD_RELOC_LO16, AT); | |
6575 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg, | |
6576 | treg, 8); | |
6577 | if (! target_big_endian) | |
6578 | expr1.X_add_number = 1; | |
6579 | else | |
6580 | expr1.X_add_number = 0; | |
6581 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
6582 | (int) BFD_RELOC_LO16, AT); | |
6583 | if (! target_big_endian) | |
6584 | expr1.X_add_number = 0; | |
6585 | else | |
6586 | expr1.X_add_number = 1; | |
6587 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
6588 | (int) BFD_RELOC_LO16, AT); | |
6589 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, | |
6590 | treg, 8); | |
6591 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, | |
6592 | treg, AT); | |
6593 | break; | |
6594 | ||
6595 | default: | |
6596 | /* FIXME: Check if this is one of the itbl macros, since they | |
bdaaa2e1 | 6597 | are added dynamically. */ |
252b5132 RH |
6598 | as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name); |
6599 | break; | |
6600 | } | |
6601 | if (mips_opts.noat) | |
6602 | as_warn (_("Macro used $at after \".set noat\"")); | |
6603 | } | |
6604 | ||
6605 | /* Implement macros in mips16 mode. */ | |
6606 | ||
6607 | static void | |
6608 | mips16_macro (ip) | |
6609 | struct mips_cl_insn *ip; | |
6610 | { | |
6611 | int mask; | |
6612 | int xreg, yreg, zreg, tmp; | |
6613 | int icnt; | |
6614 | expressionS expr1; | |
6615 | int dbl; | |
6616 | const char *s, *s2, *s3; | |
6617 | ||
6618 | mask = ip->insn_mo->mask; | |
6619 | ||
6620 | xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX; | |
6621 | yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY; | |
6622 | zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ; | |
6623 | ||
6624 | icnt = 0; | |
6625 | ||
6626 | expr1.X_op = O_constant; | |
6627 | expr1.X_op_symbol = NULL; | |
6628 | expr1.X_add_symbol = NULL; | |
6629 | expr1.X_add_number = 1; | |
6630 | ||
6631 | dbl = 0; | |
6632 | ||
6633 | switch (mask) | |
6634 | { | |
6635 | default: | |
6636 | internalError (); | |
6637 | ||
6638 | case M_DDIV_3: | |
6639 | dbl = 1; | |
6640 | case M_DIV_3: | |
6641 | s = "mflo"; | |
6642 | goto do_div3; | |
6643 | case M_DREM_3: | |
6644 | dbl = 1; | |
6645 | case M_REM_3: | |
6646 | s = "mfhi"; | |
6647 | do_div3: | |
6648 | mips_emit_delays (true); | |
6649 | ++mips_opts.noreorder; | |
6650 | mips_any_noreorder = 1; | |
6651 | macro_build ((char *) NULL, &icnt, NULL, | |
6652 | dbl ? "ddiv" : "div", | |
6653 | "0,x,y", xreg, yreg); | |
6654 | expr1.X_add_number = 2; | |
6655 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
beae10d5 | 6656 | macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7); |
bdaaa2e1 | 6657 | |
252b5132 RH |
6658 | /* FIXME: The normal code checks for of -1 / -0x80000000 here, |
6659 | since that causes an overflow. We should do that as well, | |
6660 | but I don't see how to do the comparisons without a temporary | |
6661 | register. */ | |
6662 | --mips_opts.noreorder; | |
6663 | macro_build ((char *) NULL, &icnt, NULL, s, "x", zreg); | |
6664 | break; | |
6665 | ||
6666 | case M_DIVU_3: | |
6667 | s = "divu"; | |
6668 | s2 = "mflo"; | |
6669 | goto do_divu3; | |
6670 | case M_REMU_3: | |
6671 | s = "divu"; | |
6672 | s2 = "mfhi"; | |
6673 | goto do_divu3; | |
6674 | case M_DDIVU_3: | |
6675 | s = "ddivu"; | |
6676 | s2 = "mflo"; | |
6677 | goto do_divu3; | |
6678 | case M_DREMU_3: | |
6679 | s = "ddivu"; | |
6680 | s2 = "mfhi"; | |
6681 | do_divu3: | |
6682 | mips_emit_delays (true); | |
6683 | ++mips_opts.noreorder; | |
6684 | mips_any_noreorder = 1; | |
6685 | macro_build ((char *) NULL, &icnt, NULL, s, "0,x,y", xreg, yreg); | |
6686 | expr1.X_add_number = 2; | |
6687 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
6688 | macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7); | |
6689 | --mips_opts.noreorder; | |
6690 | macro_build ((char *) NULL, &icnt, NULL, s2, "x", zreg); | |
6691 | break; | |
6692 | ||
6693 | case M_DMUL: | |
6694 | dbl = 1; | |
6695 | case M_MUL: | |
6696 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 6697 | dbl ? "dmultu" : "multu", "x,y", xreg, yreg); |
252b5132 RH |
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, | |
9a41af64 | 6710 | dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg); |
252b5132 RH |
6711 | break; |
6712 | ||
6713 | case M_SUBU_I_2: | |
6714 | if (imm_expr.X_op != O_constant) | |
6715 | as_bad (_("Unsupported large constant")); | |
6716 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6717 | macro_build ((char *) NULL, &icnt, &imm_expr, "addiu", | |
6718 | "x,k", xreg); | |
6719 | break; | |
6720 | ||
6721 | case M_DSUBU_I_2: | |
6722 | if (imm_expr.X_op != O_constant) | |
6723 | as_bad (_("Unsupported large constant")); | |
6724 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6725 | macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu", | |
6726 | "y,j", yreg); | |
6727 | break; | |
6728 | ||
6729 | case M_BEQ: | |
6730 | s = "cmp"; | |
6731 | s2 = "bteqz"; | |
6732 | goto do_branch; | |
6733 | case M_BNE: | |
6734 | s = "cmp"; | |
6735 | s2 = "btnez"; | |
6736 | goto do_branch; | |
6737 | case M_BLT: | |
6738 | s = "slt"; | |
6739 | s2 = "btnez"; | |
6740 | goto do_branch; | |
6741 | case M_BLTU: | |
6742 | s = "sltu"; | |
6743 | s2 = "btnez"; | |
6744 | goto do_branch; | |
6745 | case M_BLE: | |
6746 | s = "slt"; | |
6747 | s2 = "bteqz"; | |
6748 | goto do_reverse_branch; | |
6749 | case M_BLEU: | |
6750 | s = "sltu"; | |
6751 | s2 = "bteqz"; | |
6752 | goto do_reverse_branch; | |
6753 | case M_BGE: | |
6754 | s = "slt"; | |
6755 | s2 = "bteqz"; | |
6756 | goto do_branch; | |
6757 | case M_BGEU: | |
6758 | s = "sltu"; | |
6759 | s2 = "bteqz"; | |
6760 | goto do_branch; | |
6761 | case M_BGT: | |
6762 | s = "slt"; | |
6763 | s2 = "btnez"; | |
6764 | goto do_reverse_branch; | |
6765 | case M_BGTU: | |
6766 | s = "sltu"; | |
6767 | s2 = "btnez"; | |
6768 | ||
6769 | do_reverse_branch: | |
6770 | tmp = xreg; | |
6771 | xreg = yreg; | |
6772 | yreg = tmp; | |
6773 | ||
6774 | do_branch: | |
6775 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y", | |
6776 | xreg, yreg); | |
6777 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
6778 | break; | |
6779 | ||
6780 | case M_BEQ_I: | |
6781 | s = "cmpi"; | |
6782 | s2 = "bteqz"; | |
6783 | s3 = "x,U"; | |
6784 | goto do_branch_i; | |
6785 | case M_BNE_I: | |
6786 | s = "cmpi"; | |
6787 | s2 = "btnez"; | |
6788 | s3 = "x,U"; | |
6789 | goto do_branch_i; | |
6790 | case M_BLT_I: | |
6791 | s = "slti"; | |
6792 | s2 = "btnez"; | |
6793 | s3 = "x,8"; | |
6794 | goto do_branch_i; | |
6795 | case M_BLTU_I: | |
6796 | s = "sltiu"; | |
6797 | s2 = "btnez"; | |
6798 | s3 = "x,8"; | |
6799 | goto do_branch_i; | |
6800 | case M_BLE_I: | |
6801 | s = "slti"; | |
6802 | s2 = "btnez"; | |
6803 | s3 = "x,8"; | |
6804 | goto do_addone_branch_i; | |
6805 | case M_BLEU_I: | |
6806 | s = "sltiu"; | |
6807 | s2 = "btnez"; | |
6808 | s3 = "x,8"; | |
6809 | goto do_addone_branch_i; | |
6810 | case M_BGE_I: | |
6811 | s = "slti"; | |
6812 | s2 = "bteqz"; | |
6813 | s3 = "x,8"; | |
6814 | goto do_branch_i; | |
6815 | case M_BGEU_I: | |
6816 | s = "sltiu"; | |
6817 | s2 = "bteqz"; | |
6818 | s3 = "x,8"; | |
6819 | goto do_branch_i; | |
6820 | case M_BGT_I: | |
6821 | s = "slti"; | |
6822 | s2 = "bteqz"; | |
6823 | s3 = "x,8"; | |
6824 | goto do_addone_branch_i; | |
6825 | case M_BGTU_I: | |
6826 | s = "sltiu"; | |
6827 | s2 = "bteqz"; | |
6828 | s3 = "x,8"; | |
6829 | ||
6830 | do_addone_branch_i: | |
6831 | if (imm_expr.X_op != O_constant) | |
6832 | as_bad (_("Unsupported large constant")); | |
6833 | ++imm_expr.X_add_number; | |
6834 | ||
6835 | do_branch_i: | |
6836 | macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg); | |
6837 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
6838 | break; | |
6839 | ||
6840 | case M_ABS: | |
6841 | expr1.X_add_number = 0; | |
6842 | macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg); | |
6843 | if (xreg != yreg) | |
ea1fb5dc | 6844 | move_register (&icnt, xreg, yreg); |
252b5132 RH |
6845 | expr1.X_add_number = 2; |
6846 | macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p"); | |
6847 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6848 | "neg", "x,w", xreg, xreg); | |
6849 | } | |
6850 | } | |
6851 | ||
6852 | /* For consistency checking, verify that all bits are specified either | |
6853 | by the match/mask part of the instruction definition, or by the | |
6854 | operand list. */ | |
6855 | static int | |
6856 | validate_mips_insn (opc) | |
6857 | const struct mips_opcode *opc; | |
6858 | { | |
6859 | const char *p = opc->args; | |
6860 | char c; | |
6861 | unsigned long used_bits = opc->mask; | |
6862 | ||
6863 | if ((used_bits & opc->match) != opc->match) | |
6864 | { | |
6865 | as_bad (_("internal: bad mips opcode (mask error): %s %s"), | |
6866 | opc->name, opc->args); | |
6867 | return 0; | |
6868 | } | |
6869 | #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift))) | |
6870 | while (*p) | |
6871 | switch (c = *p++) | |
6872 | { | |
6873 | case ',': break; | |
6874 | case '(': break; | |
6875 | case ')': break; | |
6876 | case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
6877 | case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
6878 | case 'A': break; | |
4372b673 | 6879 | case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break; |
252b5132 RH |
6880 | case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break; |
6881 | case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break; | |
6882 | case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
6883 | case 'F': break; | |
6884 | case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
156c2f8b | 6885 | case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
252b5132 | 6886 | case 'I': break; |
e972090a | 6887 | case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break; |
252b5132 RH |
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; | |
4372b673 NC |
6918 | case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD); |
6919 | USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
252b5132 RH |
6920 | default: |
6921 | as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"), | |
6922 | c, opc->name, opc->args); | |
6923 | return 0; | |
6924 | } | |
6925 | #undef USE_BITS | |
6926 | if (used_bits != 0xffffffff) | |
6927 | { | |
6928 | as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"), | |
6929 | ~used_bits & 0xffffffff, opc->name, opc->args); | |
6930 | return 0; | |
6931 | } | |
6932 | return 1; | |
6933 | } | |
6934 | ||
6935 | /* This routine assembles an instruction into its binary format. As a | |
6936 | side effect, it sets one of the global variables imm_reloc or | |
6937 | offset_reloc to the type of relocation to do if one of the operands | |
6938 | is an address expression. */ | |
6939 | ||
6940 | static void | |
6941 | mips_ip (str, ip) | |
6942 | char *str; | |
6943 | struct mips_cl_insn *ip; | |
6944 | { | |
6945 | char *s; | |
6946 | const char *args; | |
43841e91 | 6947 | char c = 0; |
252b5132 RH |
6948 | struct mips_opcode *insn; |
6949 | char *argsStart; | |
6950 | unsigned int regno; | |
6951 | unsigned int lastregno = 0; | |
6952 | char *s_reset; | |
6953 | char save_c = 0; | |
6954 | int full_opcode_match = 1; | |
6955 | ||
6956 | insn_error = NULL; | |
6957 | ||
6958 | /* If the instruction contains a '.', we first try to match an instruction | |
6959 | including the '.'. Then we try again without the '.'. */ | |
6960 | insn = NULL; | |
3882b010 | 6961 | for (s = str; *s != '\0' && !ISSPACE (*s); ++s) |
252b5132 RH |
6962 | continue; |
6963 | ||
6964 | /* If we stopped on whitespace, then replace the whitespace with null for | |
6965 | the call to hash_find. Save the character we replaced just in case we | |
6966 | have to re-parse the instruction. */ | |
3882b010 | 6967 | if (ISSPACE (*s)) |
252b5132 RH |
6968 | { |
6969 | save_c = *s; | |
6970 | *s++ = '\0'; | |
6971 | } | |
bdaaa2e1 | 6972 | |
252b5132 RH |
6973 | insn = (struct mips_opcode *) hash_find (op_hash, str); |
6974 | ||
6975 | /* If we didn't find the instruction in the opcode table, try again, but | |
6976 | this time with just the instruction up to, but not including the | |
6977 | first '.'. */ | |
6978 | if (insn == NULL) | |
6979 | { | |
bdaaa2e1 | 6980 | /* Restore the character we overwrite above (if any). */ |
252b5132 RH |
6981 | if (save_c) |
6982 | *(--s) = save_c; | |
6983 | ||
6984 | /* Scan up to the first '.' or whitespace. */ | |
3882b010 L |
6985 | for (s = str; |
6986 | *s != '\0' && *s != '.' && !ISSPACE (*s); | |
6987 | ++s) | |
252b5132 RH |
6988 | continue; |
6989 | ||
6990 | /* If we did not find a '.', then we can quit now. */ | |
6991 | if (*s != '.') | |
6992 | { | |
6993 | insn_error = "unrecognized opcode"; | |
6994 | return; | |
6995 | } | |
6996 | ||
6997 | /* Lookup the instruction in the hash table. */ | |
6998 | *s++ = '\0'; | |
6999 | if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL) | |
7000 | { | |
7001 | insn_error = "unrecognized opcode"; | |
7002 | return; | |
7003 | } | |
7004 | ||
7005 | full_opcode_match = 0; | |
7006 | } | |
7007 | ||
7008 | argsStart = s; | |
7009 | for (;;) | |
7010 | { | |
252b5132 RH |
7011 | boolean ok; |
7012 | ||
7013 | assert (strcmp (insn->name, str) == 0); | |
7014 | ||
ea1fb5dc | 7015 | if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_arch)) |
252b5132 | 7016 | ok = true; |
bdaaa2e1 | 7017 | else |
252b5132 | 7018 | ok = false; |
bdaaa2e1 | 7019 | |
252b5132 RH |
7020 | if (insn->pinfo != INSN_MACRO) |
7021 | { | |
ec68c924 | 7022 | if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0) |
252b5132 RH |
7023 | ok = false; |
7024 | } | |
7025 | ||
7026 | if (! ok) | |
7027 | { | |
7028 | if (insn + 1 < &mips_opcodes[NUMOPCODES] | |
7029 | && strcmp (insn->name, insn[1].name) == 0) | |
7030 | { | |
7031 | ++insn; | |
7032 | continue; | |
7033 | } | |
252b5132 | 7034 | else |
beae10d5 | 7035 | { |
268f6bed L |
7036 | if (!insn_error) |
7037 | { | |
7038 | static char buf[100]; | |
7039 | sprintf (buf, | |
7040 | _("opcode not supported on this processor: %s (%s)"), | |
ec68c924 | 7041 | mips_cpu_to_str (mips_arch), |
268f6bed | 7042 | mips_isa_to_str (mips_opts.isa)); |
bdaaa2e1 | 7043 | |
268f6bed L |
7044 | insn_error = buf; |
7045 | } | |
7046 | if (save_c) | |
7047 | *(--s) = save_c; | |
2bd7f1f3 | 7048 | return; |
252b5132 | 7049 | } |
252b5132 RH |
7050 | } |
7051 | ||
7052 | ip->insn_mo = insn; | |
7053 | ip->insn_opcode = insn->match; | |
268f6bed | 7054 | insn_error = NULL; |
252b5132 RH |
7055 | for (args = insn->args;; ++args) |
7056 | { | |
7057 | if (*s == ' ') | |
7058 | ++s; | |
7059 | switch (*args) | |
7060 | { | |
7061 | case '\0': /* end of args */ | |
7062 | if (*s == '\0') | |
7063 | return; | |
7064 | break; | |
7065 | ||
7066 | case ',': | |
7067 | if (*s++ == *args) | |
7068 | continue; | |
7069 | s--; | |
7070 | switch (*++args) | |
7071 | { | |
7072 | case 'r': | |
7073 | case 'v': | |
38487616 | 7074 | ip->insn_opcode |= lastregno << OP_SH_RS; |
252b5132 RH |
7075 | continue; |
7076 | ||
7077 | case 'w': | |
38487616 TS |
7078 | ip->insn_opcode |= lastregno << OP_SH_RT; |
7079 | continue; | |
7080 | ||
252b5132 | 7081 | case 'W': |
38487616 | 7082 | ip->insn_opcode |= lastregno << OP_SH_FT; |
252b5132 RH |
7083 | continue; |
7084 | ||
7085 | case 'V': | |
38487616 | 7086 | ip->insn_opcode |= lastregno << OP_SH_FS; |
252b5132 RH |
7087 | continue; |
7088 | } | |
7089 | break; | |
7090 | ||
7091 | case '(': | |
7092 | /* Handle optional base register. | |
7093 | Either the base register is omitted or | |
bdaaa2e1 | 7094 | we must have a left paren. */ |
252b5132 RH |
7095 | /* This is dependent on the next operand specifier |
7096 | is a base register specification. */ | |
7097 | assert (args[1] == 'b' || args[1] == '5' | |
7098 | || args[1] == '-' || args[1] == '4'); | |
7099 | if (*s == '\0') | |
7100 | return; | |
7101 | ||
7102 | case ')': /* these must match exactly */ | |
7103 | if (*s++ == *args) | |
7104 | continue; | |
7105 | break; | |
7106 | ||
7107 | case '<': /* must be at least one digit */ | |
7108 | /* | |
7109 | * According to the manual, if the shift amount is greater | |
7110 | * than 31 or less than 0 the the shift amount should be | |
7111 | * mod 32. In reality the mips assembler issues an error. | |
7112 | * We issue a warning and mask out all but the low 5 bits. | |
7113 | */ | |
7114 | my_getExpression (&imm_expr, s); | |
7115 | check_absolute_expr (ip, &imm_expr); | |
7116 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7117 | { | |
7118 | as_warn (_("Improper shift amount (%ld)"), | |
7119 | (long) imm_expr.X_add_number); | |
38487616 | 7120 | imm_expr.X_add_number &= OP_MASK_SHAMT; |
252b5132 | 7121 | } |
38487616 | 7122 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT; |
252b5132 RH |
7123 | imm_expr.X_op = O_absent; |
7124 | s = expr_end; | |
7125 | continue; | |
7126 | ||
7127 | case '>': /* shift amount minus 32 */ | |
7128 | my_getExpression (&imm_expr, s); | |
7129 | check_absolute_expr (ip, &imm_expr); | |
7130 | if ((unsigned long) imm_expr.X_add_number < 32 | |
7131 | || (unsigned long) imm_expr.X_add_number > 63) | |
7132 | break; | |
38487616 | 7133 | ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT; |
252b5132 RH |
7134 | imm_expr.X_op = O_absent; |
7135 | s = expr_end; | |
7136 | continue; | |
7137 | ||
252b5132 RH |
7138 | case 'k': /* cache code */ |
7139 | case 'h': /* prefx code */ | |
7140 | my_getExpression (&imm_expr, s); | |
7141 | check_absolute_expr (ip, &imm_expr); | |
7142 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7143 | { | |
7144 | as_warn (_("Invalid value for `%s' (%lu)"), | |
7145 | ip->insn_mo->name, | |
7146 | (unsigned long) imm_expr.X_add_number); | |
7147 | imm_expr.X_add_number &= 0x1f; | |
7148 | } | |
7149 | if (*args == 'k') | |
7150 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE; | |
7151 | else | |
7152 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX; | |
7153 | imm_expr.X_op = O_absent; | |
7154 | s = expr_end; | |
7155 | continue; | |
7156 | ||
7157 | case 'c': /* break code */ | |
7158 | my_getExpression (&imm_expr, s); | |
7159 | check_absolute_expr (ip, &imm_expr); | |
7160 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7161 | { | |
7162 | as_warn (_("Illegal break code (%ld)"), | |
7163 | (long) imm_expr.X_add_number); | |
38487616 | 7164 | imm_expr.X_add_number &= OP_MASK_CODE; |
252b5132 | 7165 | } |
38487616 | 7166 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE; |
252b5132 RH |
7167 | imm_expr.X_op = O_absent; |
7168 | s = expr_end; | |
7169 | continue; | |
7170 | ||
7171 | case 'q': /* lower break code */ | |
7172 | my_getExpression (&imm_expr, s); | |
7173 | check_absolute_expr (ip, &imm_expr); | |
7174 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7175 | { | |
7176 | as_warn (_("Illegal lower break code (%ld)"), | |
7177 | (long) imm_expr.X_add_number); | |
38487616 | 7178 | imm_expr.X_add_number &= OP_MASK_CODE2; |
252b5132 | 7179 | } |
38487616 | 7180 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2; |
252b5132 RH |
7181 | imm_expr.X_op = O_absent; |
7182 | s = expr_end; | |
7183 | continue; | |
7184 | ||
4372b673 | 7185 | case 'B': /* 20-bit syscall/break code. */ |
156c2f8b | 7186 | my_getExpression (&imm_expr, s); |
156c2f8b | 7187 | check_absolute_expr (ip, &imm_expr); |
38487616 | 7188 | if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE20) |
4372b673 | 7189 | as_warn (_("Illegal 20-bit code (%ld)"), |
252b5132 | 7190 | (long) imm_expr.X_add_number); |
38487616 | 7191 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20; |
252b5132 RH |
7192 | imm_expr.X_op = O_absent; |
7193 | s = expr_end; | |
7194 | continue; | |
7195 | ||
7196 | case 'C': /* Coprocessor code */ | |
beae10d5 | 7197 | my_getExpression (&imm_expr, s); |
252b5132 | 7198 | check_absolute_expr (ip, &imm_expr); |
beae10d5 | 7199 | if ((unsigned long) imm_expr.X_add_number >= (1<<25)) |
252b5132 | 7200 | { |
beae10d5 | 7201 | as_warn (_("Coproccesor code > 25 bits (%ld)"), |
252b5132 | 7202 | (long) imm_expr.X_add_number); |
beae10d5 | 7203 | imm_expr.X_add_number &= ((1<<25) - 1); |
252b5132 | 7204 | } |
beae10d5 KH |
7205 | ip->insn_opcode |= imm_expr.X_add_number; |
7206 | imm_expr.X_op = O_absent; | |
7207 | s = expr_end; | |
7208 | continue; | |
252b5132 | 7209 | |
4372b673 NC |
7210 | case 'J': /* 19-bit wait code. */ |
7211 | my_getExpression (&imm_expr, s); | |
7212 | check_absolute_expr (ip, &imm_expr); | |
38487616 | 7213 | if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE19) |
4372b673 NC |
7214 | as_warn (_("Illegal 19-bit code (%ld)"), |
7215 | (long) imm_expr.X_add_number); | |
38487616 | 7216 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19; |
4372b673 NC |
7217 | imm_expr.X_op = O_absent; |
7218 | s = expr_end; | |
7219 | continue; | |
7220 | ||
252b5132 | 7221 | case 'P': /* Performance register */ |
beae10d5 | 7222 | my_getExpression (&imm_expr, s); |
252b5132 | 7223 | check_absolute_expr (ip, &imm_expr); |
beae10d5 | 7224 | if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1) |
252b5132 | 7225 | { |
38487616 | 7226 | as_warn (_("Invalid performance register (%ld)"), |
252b5132 | 7227 | (long) imm_expr.X_add_number); |
38487616 | 7228 | imm_expr.X_add_number &= OP_MASK_PERFREG; |
252b5132 | 7229 | } |
38487616 | 7230 | ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG); |
beae10d5 KH |
7231 | imm_expr.X_op = O_absent; |
7232 | s = expr_end; | |
7233 | continue; | |
252b5132 RH |
7234 | |
7235 | case 'b': /* base register */ | |
7236 | case 'd': /* destination register */ | |
7237 | case 's': /* source register */ | |
7238 | case 't': /* target register */ | |
7239 | case 'r': /* both target and source */ | |
7240 | case 'v': /* both dest and source */ | |
7241 | case 'w': /* both dest and target */ | |
7242 | case 'E': /* coprocessor target register */ | |
7243 | case 'G': /* coprocessor destination register */ | |
7244 | case 'x': /* ignore register name */ | |
7245 | case 'z': /* must be zero register */ | |
4372b673 | 7246 | case 'U': /* destination register (clo/clz). */ |
252b5132 RH |
7247 | s_reset = s; |
7248 | if (s[0] == '$') | |
7249 | { | |
7250 | ||
3882b010 | 7251 | if (ISDIGIT (s[1])) |
252b5132 RH |
7252 | { |
7253 | ++s; | |
7254 | regno = 0; | |
7255 | do | |
7256 | { | |
7257 | regno *= 10; | |
7258 | regno += *s - '0'; | |
7259 | ++s; | |
7260 | } | |
3882b010 | 7261 | while (ISDIGIT (*s)); |
252b5132 RH |
7262 | if (regno > 31) |
7263 | as_bad (_("Invalid register number (%d)"), regno); | |
7264 | } | |
7265 | else if (*args == 'E' || *args == 'G') | |
7266 | goto notreg; | |
7267 | else | |
7268 | { | |
7269 | if (s[1] == 'f' && s[2] == 'p') | |
7270 | { | |
7271 | s += 3; | |
7272 | regno = FP; | |
7273 | } | |
7274 | else if (s[1] == 's' && s[2] == 'p') | |
7275 | { | |
7276 | s += 3; | |
7277 | regno = SP; | |
7278 | } | |
7279 | else if (s[1] == 'g' && s[2] == 'p') | |
7280 | { | |
7281 | s += 3; | |
7282 | regno = GP; | |
7283 | } | |
7284 | else if (s[1] == 'a' && s[2] == 't') | |
7285 | { | |
7286 | s += 3; | |
7287 | regno = AT; | |
7288 | } | |
7289 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
7290 | { | |
7291 | s += 4; | |
7292 | regno = KT0; | |
7293 | } | |
7294 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
7295 | { | |
7296 | s += 4; | |
7297 | regno = KT1; | |
7298 | } | |
7299 | else if (itbl_have_entries) | |
7300 | { | |
7301 | char *p, *n; | |
d7ba4a77 | 7302 | unsigned long r; |
252b5132 | 7303 | |
d7ba4a77 | 7304 | p = s + 1; /* advance past '$' */ |
252b5132 RH |
7305 | n = itbl_get_field (&p); /* n is name */ |
7306 | ||
d7ba4a77 ILT |
7307 | /* See if this is a register defined in an |
7308 | itbl entry. */ | |
7309 | if (itbl_get_reg_val (n, &r)) | |
252b5132 RH |
7310 | { |
7311 | /* Get_field advances to the start of | |
7312 | the next field, so we need to back | |
d7ba4a77 | 7313 | rack to the end of the last field. */ |
bdaaa2e1 | 7314 | if (p) |
252b5132 | 7315 | s = p - 1; |
bdaaa2e1 | 7316 | else |
d7ba4a77 | 7317 | s = strchr (s, '\0'); |
252b5132 RH |
7318 | regno = r; |
7319 | } | |
7320 | else | |
7321 | goto notreg; | |
beae10d5 | 7322 | } |
252b5132 RH |
7323 | else |
7324 | goto notreg; | |
7325 | } | |
7326 | if (regno == AT | |
7327 | && ! mips_opts.noat | |
7328 | && *args != 'E' | |
7329 | && *args != 'G') | |
7330 | as_warn (_("Used $at without \".set noat\"")); | |
7331 | c = *args; | |
7332 | if (*s == ' ') | |
7333 | s++; | |
7334 | if (args[1] != *s) | |
7335 | { | |
7336 | if (c == 'r' || c == 'v' || c == 'w') | |
7337 | { | |
7338 | regno = lastregno; | |
7339 | s = s_reset; | |
7340 | args++; | |
7341 | } | |
7342 | } | |
7343 | /* 'z' only matches $0. */ | |
7344 | if (c == 'z' && regno != 0) | |
7345 | break; | |
7346 | ||
bdaaa2e1 KH |
7347 | /* Now that we have assembled one operand, we use the args string |
7348 | * to figure out where it goes in the instruction. */ | |
252b5132 RH |
7349 | switch (c) |
7350 | { | |
7351 | case 'r': | |
7352 | case 's': | |
7353 | case 'v': | |
7354 | case 'b': | |
38487616 | 7355 | ip->insn_opcode |= regno << OP_SH_RS; |
252b5132 RH |
7356 | break; |
7357 | case 'd': | |
7358 | case 'G': | |
38487616 | 7359 | ip->insn_opcode |= regno << OP_SH_RD; |
252b5132 | 7360 | break; |
4372b673 | 7361 | case 'U': |
38487616 TS |
7362 | ip->insn_opcode |= regno << OP_SH_RD; |
7363 | ip->insn_opcode |= regno << OP_SH_RT; | |
4372b673 | 7364 | break; |
252b5132 RH |
7365 | case 'w': |
7366 | case 't': | |
7367 | case 'E': | |
38487616 | 7368 | ip->insn_opcode |= regno << OP_SH_RT; |
252b5132 RH |
7369 | break; |
7370 | case 'x': | |
7371 | /* This case exists because on the r3000 trunc | |
7372 | expands into a macro which requires a gp | |
7373 | register. On the r6000 or r4000 it is | |
7374 | assembled into a single instruction which | |
7375 | ignores the register. Thus the insn version | |
7376 | is MIPS_ISA2 and uses 'x', and the macro | |
7377 | version is MIPS_ISA1 and uses 't'. */ | |
7378 | break; | |
7379 | case 'z': | |
7380 | /* This case is for the div instruction, which | |
7381 | acts differently if the destination argument | |
7382 | is $0. This only matches $0, and is checked | |
7383 | outside the switch. */ | |
7384 | break; | |
7385 | case 'D': | |
7386 | /* Itbl operand; not yet implemented. FIXME ?? */ | |
7387 | break; | |
7388 | /* What about all other operands like 'i', which | |
7389 | can be specified in the opcode table? */ | |
7390 | } | |
7391 | lastregno = regno; | |
7392 | continue; | |
7393 | } | |
7394 | notreg: | |
7395 | switch (*args++) | |
7396 | { | |
7397 | case 'r': | |
7398 | case 'v': | |
38487616 | 7399 | ip->insn_opcode |= lastregno << OP_SH_RS; |
252b5132 RH |
7400 | continue; |
7401 | case 'w': | |
38487616 | 7402 | ip->insn_opcode |= lastregno << OP_SH_RT; |
252b5132 RH |
7403 | continue; |
7404 | } | |
7405 | break; | |
7406 | ||
7407 | case 'D': /* floating point destination register */ | |
7408 | case 'S': /* floating point source register */ | |
7409 | case 'T': /* floating point target register */ | |
7410 | case 'R': /* floating point source register */ | |
7411 | case 'V': | |
7412 | case 'W': | |
7413 | s_reset = s; | |
3882b010 L |
7414 | if (s[0] == '$' && s[1] == 'f' |
7415 | && ISDIGIT (s[2])) | |
252b5132 RH |
7416 | { |
7417 | s += 2; | |
7418 | regno = 0; | |
7419 | do | |
7420 | { | |
7421 | regno *= 10; | |
7422 | regno += *s - '0'; | |
7423 | ++s; | |
7424 | } | |
3882b010 | 7425 | while (ISDIGIT (*s)); |
252b5132 RH |
7426 | |
7427 | if (regno > 31) | |
7428 | as_bad (_("Invalid float register number (%d)"), regno); | |
7429 | ||
7430 | if ((regno & 1) != 0 | |
ca4e0257 | 7431 | && HAVE_32BIT_FPRS |
252b5132 RH |
7432 | && ! (strcmp (str, "mtc1") == 0 |
7433 | || strcmp (str, "mfc1") == 0 | |
7434 | || strcmp (str, "lwc1") == 0 | |
7435 | || strcmp (str, "swc1") == 0 | |
7436 | || strcmp (str, "l.s") == 0 | |
7437 | || strcmp (str, "s.s") == 0)) | |
7438 | as_warn (_("Float register should be even, was %d"), | |
7439 | regno); | |
7440 | ||
7441 | c = *args; | |
7442 | if (*s == ' ') | |
7443 | s++; | |
7444 | if (args[1] != *s) | |
7445 | { | |
7446 | if (c == 'V' || c == 'W') | |
7447 | { | |
7448 | regno = lastregno; | |
7449 | s = s_reset; | |
7450 | args++; | |
7451 | } | |
7452 | } | |
7453 | switch (c) | |
7454 | { | |
7455 | case 'D': | |
38487616 | 7456 | ip->insn_opcode |= regno << OP_SH_FD; |
252b5132 RH |
7457 | break; |
7458 | case 'V': | |
7459 | case 'S': | |
38487616 | 7460 | ip->insn_opcode |= regno << OP_SH_FS; |
252b5132 RH |
7461 | break; |
7462 | case 'W': | |
7463 | case 'T': | |
38487616 | 7464 | ip->insn_opcode |= regno << OP_SH_FT; |
252b5132 RH |
7465 | break; |
7466 | case 'R': | |
38487616 | 7467 | ip->insn_opcode |= regno << OP_SH_FR; |
252b5132 RH |
7468 | break; |
7469 | } | |
7470 | lastregno = regno; | |
7471 | continue; | |
7472 | } | |
7473 | ||
252b5132 RH |
7474 | switch (*args++) |
7475 | { | |
7476 | case 'V': | |
38487616 | 7477 | ip->insn_opcode |= lastregno << OP_SH_FS; |
252b5132 RH |
7478 | continue; |
7479 | case 'W': | |
38487616 | 7480 | ip->insn_opcode |= lastregno << OP_SH_FT; |
252b5132 RH |
7481 | continue; |
7482 | } | |
7483 | break; | |
7484 | ||
7485 | case 'I': | |
7486 | my_getExpression (&imm_expr, s); | |
7487 | if (imm_expr.X_op != O_big | |
7488 | && imm_expr.X_op != O_constant) | |
7489 | insn_error = _("absolute expression required"); | |
7490 | s = expr_end; | |
7491 | continue; | |
7492 | ||
7493 | case 'A': | |
7494 | my_getExpression (&offset_expr, s); | |
7495 | imm_reloc = BFD_RELOC_32; | |
7496 | s = expr_end; | |
7497 | continue; | |
7498 | ||
7499 | case 'F': | |
7500 | case 'L': | |
7501 | case 'f': | |
7502 | case 'l': | |
7503 | { | |
7504 | int f64; | |
ca4e0257 | 7505 | int using_gprs; |
252b5132 RH |
7506 | char *save_in; |
7507 | char *err; | |
7508 | unsigned char temp[8]; | |
7509 | int len; | |
7510 | unsigned int length; | |
7511 | segT seg; | |
7512 | subsegT subseg; | |
7513 | char *p; | |
7514 | ||
7515 | /* These only appear as the last operand in an | |
7516 | instruction, and every instruction that accepts | |
7517 | them in any variant accepts them in all variants. | |
7518 | This means we don't have to worry about backing out | |
7519 | any changes if the instruction does not match. | |
7520 | ||
7521 | The difference between them is the size of the | |
7522 | floating point constant and where it goes. For 'F' | |
7523 | and 'L' the constant is 64 bits; for 'f' and 'l' it | |
7524 | is 32 bits. Where the constant is placed is based | |
7525 | on how the MIPS assembler does things: | |
7526 | F -- .rdata | |
7527 | L -- .lit8 | |
7528 | f -- immediate value | |
7529 | l -- .lit4 | |
7530 | ||
7531 | The .lit4 and .lit8 sections are only used if | |
7532 | permitted by the -G argument. | |
7533 | ||
7534 | When generating embedded PIC code, we use the | |
7535 | .lit8 section but not the .lit4 section (we can do | |
7536 | .lit4 inline easily; we need to put .lit8 | |
7537 | somewhere in the data segment, and using .lit8 | |
7538 | permits the linker to eventually combine identical | |
ca4e0257 RS |
7539 | .lit8 entries). |
7540 | ||
7541 | The code below needs to know whether the target register | |
7542 | is 32 or 64 bits wide. It relies on the fact 'f' and | |
7543 | 'F' are used with GPR-based instructions and 'l' and | |
7544 | 'L' are used with FPR-based instructions. */ | |
252b5132 RH |
7545 | |
7546 | f64 = *args == 'F' || *args == 'L'; | |
ca4e0257 | 7547 | using_gprs = *args == 'F' || *args == 'f'; |
252b5132 RH |
7548 | |
7549 | save_in = input_line_pointer; | |
7550 | input_line_pointer = s; | |
7551 | err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len); | |
7552 | length = len; | |
7553 | s = input_line_pointer; | |
7554 | input_line_pointer = save_in; | |
7555 | if (err != NULL && *err != '\0') | |
7556 | { | |
7557 | as_bad (_("Bad floating point constant: %s"), err); | |
7558 | memset (temp, '\0', sizeof temp); | |
7559 | length = f64 ? 8 : 4; | |
7560 | } | |
7561 | ||
156c2f8b | 7562 | assert (length == (unsigned) (f64 ? 8 : 4)); |
252b5132 RH |
7563 | |
7564 | if (*args == 'f' | |
7565 | || (*args == 'l' | |
7566 | && (! USE_GLOBAL_POINTER_OPT | |
7567 | || mips_pic == EMBEDDED_PIC | |
7568 | || g_switch_value < 4 | |
7569 | || (temp[0] == 0 && temp[1] == 0) | |
7570 | || (temp[2] == 0 && temp[3] == 0)))) | |
7571 | { | |
7572 | imm_expr.X_op = O_constant; | |
7573 | if (! target_big_endian) | |
7574 | imm_expr.X_add_number = bfd_getl32 (temp); | |
7575 | else | |
7576 | imm_expr.X_add_number = bfd_getb32 (temp); | |
7577 | } | |
7578 | else if (length > 4 | |
119d663a | 7579 | && ! mips_disable_float_construction |
ca4e0257 RS |
7580 | /* Constants can only be constructed in GPRs and |
7581 | copied to FPRs if the GPRs are at least as wide | |
7582 | as the FPRs. Force the constant into memory if | |
7583 | we are using 64-bit FPRs but the GPRs are only | |
7584 | 32 bits wide. */ | |
7585 | && (using_gprs | |
7586 | || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS)) | |
252b5132 RH |
7587 | && ((temp[0] == 0 && temp[1] == 0) |
7588 | || (temp[2] == 0 && temp[3] == 0)) | |
7589 | && ((temp[4] == 0 && temp[5] == 0) | |
7590 | || (temp[6] == 0 && temp[7] == 0))) | |
7591 | { | |
ca4e0257 RS |
7592 | /* The value is simple enough to load with a couple of |
7593 | instructions. If using 32-bit registers, set | |
7594 | imm_expr to the high order 32 bits and offset_expr to | |
7595 | the low order 32 bits. Otherwise, set imm_expr to | |
7596 | the entire 64 bit constant. */ | |
7597 | if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS) | |
252b5132 RH |
7598 | { |
7599 | imm_expr.X_op = O_constant; | |
7600 | offset_expr.X_op = O_constant; | |
7601 | if (! target_big_endian) | |
7602 | { | |
7603 | imm_expr.X_add_number = bfd_getl32 (temp + 4); | |
7604 | offset_expr.X_add_number = bfd_getl32 (temp); | |
7605 | } | |
7606 | else | |
7607 | { | |
7608 | imm_expr.X_add_number = bfd_getb32 (temp); | |
7609 | offset_expr.X_add_number = bfd_getb32 (temp + 4); | |
7610 | } | |
7611 | if (offset_expr.X_add_number == 0) | |
7612 | offset_expr.X_op = O_absent; | |
7613 | } | |
7614 | else if (sizeof (imm_expr.X_add_number) > 4) | |
7615 | { | |
7616 | imm_expr.X_op = O_constant; | |
7617 | if (! target_big_endian) | |
7618 | imm_expr.X_add_number = bfd_getl64 (temp); | |
7619 | else | |
7620 | imm_expr.X_add_number = bfd_getb64 (temp); | |
7621 | } | |
7622 | else | |
7623 | { | |
7624 | imm_expr.X_op = O_big; | |
7625 | imm_expr.X_add_number = 4; | |
7626 | if (! target_big_endian) | |
7627 | { | |
7628 | generic_bignum[0] = bfd_getl16 (temp); | |
7629 | generic_bignum[1] = bfd_getl16 (temp + 2); | |
7630 | generic_bignum[2] = bfd_getl16 (temp + 4); | |
7631 | generic_bignum[3] = bfd_getl16 (temp + 6); | |
7632 | } | |
7633 | else | |
7634 | { | |
7635 | generic_bignum[0] = bfd_getb16 (temp + 6); | |
7636 | generic_bignum[1] = bfd_getb16 (temp + 4); | |
7637 | generic_bignum[2] = bfd_getb16 (temp + 2); | |
7638 | generic_bignum[3] = bfd_getb16 (temp); | |
7639 | } | |
7640 | } | |
7641 | } | |
7642 | else | |
7643 | { | |
7644 | const char *newname; | |
7645 | segT new_seg; | |
7646 | ||
7647 | /* Switch to the right section. */ | |
7648 | seg = now_seg; | |
7649 | subseg = now_subseg; | |
7650 | switch (*args) | |
7651 | { | |
7652 | default: /* unused default case avoids warnings. */ | |
7653 | case 'L': | |
7654 | newname = RDATA_SECTION_NAME; | |
bb2d6cd7 GK |
7655 | if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8) |
7656 | || mips_pic == EMBEDDED_PIC) | |
252b5132 RH |
7657 | newname = ".lit8"; |
7658 | break; | |
7659 | case 'F': | |
bb2d6cd7 GK |
7660 | if (mips_pic == EMBEDDED_PIC) |
7661 | newname = ".lit8"; | |
7662 | else | |
7663 | newname = RDATA_SECTION_NAME; | |
252b5132 RH |
7664 | break; |
7665 | case 'l': | |
7666 | assert (!USE_GLOBAL_POINTER_OPT | |
7667 | || g_switch_value >= 4); | |
7668 | newname = ".lit4"; | |
7669 | break; | |
7670 | } | |
7671 | new_seg = subseg_new (newname, (subsegT) 0); | |
7672 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
7673 | bfd_set_section_flags (stdoutput, new_seg, | |
7674 | (SEC_ALLOC | |
7675 | | SEC_LOAD | |
7676 | | SEC_READONLY | |
7677 | | SEC_DATA)); | |
7678 | frag_align (*args == 'l' ? 2 : 3, 0, 0); | |
7679 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
7680 | && strcmp (TARGET_OS, "elf") != 0) | |
7681 | record_alignment (new_seg, 4); | |
7682 | else | |
7683 | record_alignment (new_seg, *args == 'l' ? 2 : 3); | |
7684 | if (seg == now_seg) | |
7685 | as_bad (_("Can't use floating point insn in this section")); | |
7686 | ||
7687 | /* Set the argument to the current address in the | |
7688 | section. */ | |
7689 | offset_expr.X_op = O_symbol; | |
7690 | offset_expr.X_add_symbol = | |
7691 | symbol_new ("L0\001", now_seg, | |
7692 | (valueT) frag_now_fix (), frag_now); | |
7693 | offset_expr.X_add_number = 0; | |
7694 | ||
7695 | /* Put the floating point number into the section. */ | |
7696 | p = frag_more ((int) length); | |
7697 | memcpy (p, temp, length); | |
7698 | ||
7699 | /* Switch back to the original section. */ | |
7700 | subseg_set (seg, subseg); | |
7701 | } | |
7702 | } | |
7703 | continue; | |
7704 | ||
7705 | case 'i': /* 16 bit unsigned immediate */ | |
7706 | case 'j': /* 16 bit signed immediate */ | |
7707 | imm_reloc = BFD_RELOC_LO16; | |
7708 | c = my_getSmallExpression (&imm_expr, s); | |
fb1b3232 | 7709 | if (c != S_EX_NONE) |
252b5132 | 7710 | { |
fb1b3232 | 7711 | if (c != S_EX_LO) |
252b5132 RH |
7712 | { |
7713 | if (imm_expr.X_op == O_constant) | |
7714 | imm_expr.X_add_number = | |
7715 | (imm_expr.X_add_number >> 16) & 0xffff; | |
fb1b3232 TS |
7716 | else if (c == S_EX_HIGHEST) |
7717 | imm_reloc = BFD_RELOC_MIPS_HIGHEST; | |
7718 | else if (c == S_EX_HIGHER) | |
7719 | imm_reloc = BFD_RELOC_MIPS_HIGHER; | |
7720 | else if (c == S_EX_HI) | |
252b5132 RH |
7721 | { |
7722 | imm_reloc = BFD_RELOC_HI16_S; | |
7723 | imm_unmatched_hi = true; | |
7724 | } | |
7725 | else | |
7726 | imm_reloc = BFD_RELOC_HI16; | |
7727 | } | |
7728 | else if (imm_expr.X_op == O_constant) | |
7729 | imm_expr.X_add_number &= 0xffff; | |
7730 | } | |
7731 | if (*args == 'i') | |
7732 | { | |
fb1b3232 | 7733 | if ((c == S_EX_NONE && imm_expr.X_op != O_constant) |
252b5132 | 7734 | || ((imm_expr.X_add_number < 0 |
beae10d5 KH |
7735 | || imm_expr.X_add_number >= 0x10000) |
7736 | && imm_expr.X_op == O_constant)) | |
252b5132 RH |
7737 | { |
7738 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7739 | !strcmp (insn->name, insn[1].name)) | |
7740 | break; | |
2ae7e77b AH |
7741 | if (imm_expr.X_op == O_constant |
7742 | || imm_expr.X_op == O_big) | |
252b5132 RH |
7743 | as_bad (_("16 bit expression not in range 0..65535")); |
7744 | } | |
7745 | } | |
7746 | else | |
7747 | { | |
7748 | int more; | |
7749 | offsetT max; | |
7750 | ||
7751 | /* The upper bound should be 0x8000, but | |
7752 | unfortunately the MIPS assembler accepts numbers | |
7753 | from 0x8000 to 0xffff and sign extends them, and | |
7754 | we want to be compatible. We only permit this | |
7755 | extended range for an instruction which does not | |
7756 | provide any further alternates, since those | |
7757 | alternates may handle other cases. People should | |
7758 | use the numbers they mean, rather than relying on | |
7759 | a mysterious sign extension. */ | |
7760 | more = (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7761 | strcmp (insn->name, insn[1].name) == 0); | |
7762 | if (more) | |
7763 | max = 0x8000; | |
7764 | else | |
7765 | max = 0x10000; | |
fb1b3232 | 7766 | if ((c == S_EX_NONE && imm_expr.X_op != O_constant) |
252b5132 | 7767 | || ((imm_expr.X_add_number < -0x8000 |
beae10d5 KH |
7768 | || imm_expr.X_add_number >= max) |
7769 | && imm_expr.X_op == O_constant) | |
252b5132 RH |
7770 | || (more |
7771 | && imm_expr.X_add_number < 0 | |
ca4e0257 | 7772 | && HAVE_64BIT_GPRS |
252b5132 RH |
7773 | && imm_expr.X_unsigned |
7774 | && sizeof (imm_expr.X_add_number) <= 4)) | |
7775 | { | |
7776 | if (more) | |
7777 | break; | |
2ae7e77b AH |
7778 | if (imm_expr.X_op == O_constant |
7779 | || imm_expr.X_op == O_big) | |
252b5132 RH |
7780 | as_bad (_("16 bit expression not in range -32768..32767")); |
7781 | } | |
7782 | } | |
7783 | s = expr_end; | |
7784 | continue; | |
7785 | ||
7786 | case 'o': /* 16 bit offset */ | |
7787 | c = my_getSmallExpression (&offset_expr, s); | |
7788 | ||
7789 | /* If this value won't fit into a 16 bit offset, then go | |
7790 | find a macro that will generate the 32 bit offset | |
7791 | code pattern. As a special hack, we accept the | |
7792 | difference of two local symbols as a constant. This | |
7793 | is required to suppose embedded PIC switches, which | |
7794 | use an instruction which looks like | |
7795 | lw $4,$L12-$LS12($4) | |
7796 | The problem with handling this in a more general | |
7797 | fashion is that the macro function doesn't expect to | |
7798 | see anything which can be handled in a single | |
7799 | constant instruction. */ | |
fb1b3232 | 7800 | if (c == S_EX_NONE |
252b5132 RH |
7801 | && (offset_expr.X_op != O_constant |
7802 | || offset_expr.X_add_number >= 0x8000 | |
7803 | || offset_expr.X_add_number < -0x8000) | |
7804 | && (mips_pic != EMBEDDED_PIC | |
7805 | || offset_expr.X_op != O_subtract | |
3dacdf2e NC |
7806 | || (S_GET_SEGMENT (offset_expr.X_add_symbol) |
7807 | != S_GET_SEGMENT (offset_expr.X_op_symbol)))) | |
252b5132 RH |
7808 | break; |
7809 | ||
fb1b3232 | 7810 | if (c == S_EX_HI) |
252b5132 RH |
7811 | { |
7812 | if (offset_expr.X_op != O_constant) | |
7813 | break; | |
7814 | offset_expr.X_add_number = | |
7815 | (offset_expr.X_add_number >> 16) & 0xffff; | |
7816 | } | |
7817 | offset_reloc = BFD_RELOC_LO16; | |
7818 | s = expr_end; | |
7819 | continue; | |
7820 | ||
7821 | case 'p': /* pc relative offset */ | |
cb56d3d3 TS |
7822 | if (mips_pic == EMBEDDED_PIC) |
7823 | offset_reloc = BFD_RELOC_16_PCREL_S2; | |
7824 | else | |
7825 | offset_reloc = BFD_RELOC_16_PCREL; | |
252b5132 RH |
7826 | my_getExpression (&offset_expr, s); |
7827 | s = expr_end; | |
7828 | continue; | |
7829 | ||
7830 | case 'u': /* upper 16 bits */ | |
7831 | c = my_getSmallExpression (&imm_expr, s); | |
7832 | imm_reloc = BFD_RELOC_LO16; | |
e7d556df | 7833 | if (c != S_EX_NONE) |
252b5132 | 7834 | { |
fb1b3232 | 7835 | if (c != S_EX_LO) |
252b5132 RH |
7836 | { |
7837 | if (imm_expr.X_op == O_constant) | |
7838 | imm_expr.X_add_number = | |
7839 | (imm_expr.X_add_number >> 16) & 0xffff; | |
fb1b3232 TS |
7840 | else if (c == S_EX_HIGHEST) |
7841 | imm_reloc = BFD_RELOC_MIPS_HIGHEST; | |
7842 | else if (c == S_EX_HI) | |
252b5132 RH |
7843 | { |
7844 | imm_reloc = BFD_RELOC_HI16_S; | |
7845 | imm_unmatched_hi = true; | |
7846 | } | |
7847 | else | |
7848 | imm_reloc = BFD_RELOC_HI16; | |
7849 | } | |
7850 | else if (imm_expr.X_op == O_constant) | |
7851 | imm_expr.X_add_number &= 0xffff; | |
7852 | } | |
7853 | if (imm_expr.X_op == O_constant | |
7854 | && (imm_expr.X_add_number < 0 | |
7855 | || imm_expr.X_add_number >= 0x10000)) | |
7856 | as_bad (_("lui expression not in range 0..65535")); | |
7857 | s = expr_end; | |
7858 | continue; | |
7859 | ||
7860 | case 'a': /* 26 bit address */ | |
7861 | my_getExpression (&offset_expr, s); | |
7862 | s = expr_end; | |
7863 | offset_reloc = BFD_RELOC_MIPS_JMP; | |
7864 | continue; | |
7865 | ||
7866 | case 'N': /* 3 bit branch condition code */ | |
7867 | case 'M': /* 3 bit compare condition code */ | |
7868 | if (strncmp (s, "$fcc", 4) != 0) | |
7869 | break; | |
7870 | s += 4; | |
7871 | regno = 0; | |
7872 | do | |
7873 | { | |
7874 | regno *= 10; | |
7875 | regno += *s - '0'; | |
7876 | ++s; | |
7877 | } | |
3882b010 | 7878 | while (ISDIGIT (*s)); |
252b5132 RH |
7879 | if (regno > 7) |
7880 | as_bad (_("invalid condition code register $fcc%d"), regno); | |
7881 | if (*args == 'N') | |
7882 | ip->insn_opcode |= regno << OP_SH_BCC; | |
7883 | else | |
7884 | ip->insn_opcode |= regno << OP_SH_CCC; | |
beae10d5 | 7885 | continue; |
252b5132 | 7886 | |
156c2f8b NC |
7887 | case 'H': |
7888 | if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) | |
7889 | s += 2; | |
3882b010 | 7890 | if (ISDIGIT (*s)) |
156c2f8b NC |
7891 | { |
7892 | c = 0; | |
7893 | do | |
7894 | { | |
7895 | c *= 10; | |
7896 | c += *s - '0'; | |
7897 | ++s; | |
7898 | } | |
3882b010 | 7899 | while (ISDIGIT (*s)); |
156c2f8b NC |
7900 | } |
7901 | else | |
7902 | c = 8; /* Invalid sel value. */ | |
7903 | ||
7904 | if (c > 7) | |
7905 | as_bad (_("invalid coprocessor sub-selection value (0-7)")); | |
7906 | ip->insn_opcode |= c; | |
7907 | continue; | |
7908 | ||
252b5132 RH |
7909 | default: |
7910 | as_bad (_("bad char = '%c'\n"), *args); | |
7911 | internalError (); | |
7912 | } | |
7913 | break; | |
7914 | } | |
7915 | /* Args don't match. */ | |
7916 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7917 | !strcmp (insn->name, insn[1].name)) | |
7918 | { | |
7919 | ++insn; | |
7920 | s = argsStart; | |
268f6bed | 7921 | insn_error = _("illegal operands"); |
252b5132 RH |
7922 | continue; |
7923 | } | |
268f6bed L |
7924 | if (save_c) |
7925 | *(--s) = save_c; | |
252b5132 RH |
7926 | insn_error = _("illegal operands"); |
7927 | return; | |
7928 | } | |
7929 | } | |
7930 | ||
7931 | /* This routine assembles an instruction into its binary format when | |
7932 | assembling for the mips16. As a side effect, it sets one of the | |
7933 | global variables imm_reloc or offset_reloc to the type of | |
7934 | relocation to do if one of the operands is an address expression. | |
7935 | It also sets mips16_small and mips16_ext if the user explicitly | |
7936 | requested a small or extended instruction. */ | |
7937 | ||
7938 | static void | |
7939 | mips16_ip (str, ip) | |
7940 | char *str; | |
7941 | struct mips_cl_insn *ip; | |
7942 | { | |
7943 | char *s; | |
7944 | const char *args; | |
7945 | struct mips_opcode *insn; | |
7946 | char *argsstart; | |
7947 | unsigned int regno; | |
7948 | unsigned int lastregno = 0; | |
7949 | char *s_reset; | |
7950 | ||
7951 | insn_error = NULL; | |
7952 | ||
7953 | mips16_small = false; | |
7954 | mips16_ext = false; | |
7955 | ||
3882b010 | 7956 | for (s = str; ISLOWER (*s); ++s) |
252b5132 RH |
7957 | ; |
7958 | switch (*s) | |
7959 | { | |
7960 | case '\0': | |
7961 | break; | |
7962 | ||
7963 | case ' ': | |
7964 | *s++ = '\0'; | |
7965 | break; | |
7966 | ||
7967 | case '.': | |
7968 | if (s[1] == 't' && s[2] == ' ') | |
7969 | { | |
7970 | *s = '\0'; | |
7971 | mips16_small = true; | |
7972 | s += 3; | |
7973 | break; | |
7974 | } | |
7975 | else if (s[1] == 'e' && s[2] == ' ') | |
7976 | { | |
7977 | *s = '\0'; | |
7978 | mips16_ext = true; | |
7979 | s += 3; | |
7980 | break; | |
7981 | } | |
7982 | /* Fall through. */ | |
7983 | default: | |
7984 | insn_error = _("unknown opcode"); | |
7985 | return; | |
7986 | } | |
7987 | ||
7988 | if (mips_opts.noautoextend && ! mips16_ext) | |
7989 | mips16_small = true; | |
7990 | ||
7991 | if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL) | |
7992 | { | |
7993 | insn_error = _("unrecognized opcode"); | |
7994 | return; | |
7995 | } | |
7996 | ||
7997 | argsstart = s; | |
7998 | for (;;) | |
7999 | { | |
8000 | assert (strcmp (insn->name, str) == 0); | |
8001 | ||
8002 | ip->insn_mo = insn; | |
8003 | ip->insn_opcode = insn->match; | |
8004 | ip->use_extend = false; | |
8005 | imm_expr.X_op = O_absent; | |
8006 | imm_reloc = BFD_RELOC_UNUSED; | |
8007 | offset_expr.X_op = O_absent; | |
8008 | offset_reloc = BFD_RELOC_UNUSED; | |
8009 | for (args = insn->args; 1; ++args) | |
8010 | { | |
8011 | int c; | |
8012 | ||
8013 | if (*s == ' ') | |
8014 | ++s; | |
8015 | ||
8016 | /* In this switch statement we call break if we did not find | |
8017 | a match, continue if we did find a match, or return if we | |
8018 | are done. */ | |
8019 | ||
8020 | c = *args; | |
8021 | switch (c) | |
8022 | { | |
8023 | case '\0': | |
8024 | if (*s == '\0') | |
8025 | { | |
8026 | /* Stuff the immediate value in now, if we can. */ | |
8027 | if (imm_expr.X_op == O_constant | |
8028 | && imm_reloc > BFD_RELOC_UNUSED | |
8029 | && insn->pinfo != INSN_MACRO) | |
8030 | { | |
8031 | mips16_immed ((char *) NULL, 0, | |
8032 | imm_reloc - BFD_RELOC_UNUSED, | |
8033 | imm_expr.X_add_number, true, mips16_small, | |
8034 | mips16_ext, &ip->insn_opcode, | |
8035 | &ip->use_extend, &ip->extend); | |
8036 | imm_expr.X_op = O_absent; | |
8037 | imm_reloc = BFD_RELOC_UNUSED; | |
8038 | } | |
8039 | ||
8040 | return; | |
8041 | } | |
8042 | break; | |
8043 | ||
8044 | case ',': | |
8045 | if (*s++ == c) | |
8046 | continue; | |
8047 | s--; | |
8048 | switch (*++args) | |
8049 | { | |
8050 | case 'v': | |
8051 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8052 | continue; | |
8053 | case 'w': | |
8054 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8055 | continue; | |
8056 | } | |
8057 | break; | |
8058 | ||
8059 | case '(': | |
8060 | case ')': | |
8061 | if (*s++ == c) | |
8062 | continue; | |
8063 | break; | |
8064 | ||
8065 | case 'v': | |
8066 | case 'w': | |
8067 | if (s[0] != '$') | |
8068 | { | |
8069 | if (c == 'v') | |
8070 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8071 | else | |
8072 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8073 | ++args; | |
8074 | continue; | |
8075 | } | |
8076 | /* Fall through. */ | |
8077 | case 'x': | |
8078 | case 'y': | |
8079 | case 'z': | |
8080 | case 'Z': | |
8081 | case '0': | |
8082 | case 'S': | |
8083 | case 'R': | |
8084 | case 'X': | |
8085 | case 'Y': | |
8086 | if (s[0] != '$') | |
8087 | break; | |
8088 | s_reset = s; | |
3882b010 | 8089 | if (ISDIGIT (s[1])) |
252b5132 RH |
8090 | { |
8091 | ++s; | |
8092 | regno = 0; | |
8093 | do | |
8094 | { | |
8095 | regno *= 10; | |
8096 | regno += *s - '0'; | |
8097 | ++s; | |
8098 | } | |
3882b010 | 8099 | while (ISDIGIT (*s)); |
252b5132 RH |
8100 | if (regno > 31) |
8101 | { | |
8102 | as_bad (_("invalid register number (%d)"), regno); | |
8103 | regno = 2; | |
8104 | } | |
8105 | } | |
8106 | else | |
8107 | { | |
8108 | if (s[1] == 'f' && s[2] == 'p') | |
8109 | { | |
8110 | s += 3; | |
8111 | regno = FP; | |
8112 | } | |
8113 | else if (s[1] == 's' && s[2] == 'p') | |
8114 | { | |
8115 | s += 3; | |
8116 | regno = SP; | |
8117 | } | |
8118 | else if (s[1] == 'g' && s[2] == 'p') | |
8119 | { | |
8120 | s += 3; | |
8121 | regno = GP; | |
8122 | } | |
8123 | else if (s[1] == 'a' && s[2] == 't') | |
8124 | { | |
8125 | s += 3; | |
8126 | regno = AT; | |
8127 | } | |
8128 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
8129 | { | |
8130 | s += 4; | |
8131 | regno = KT0; | |
8132 | } | |
8133 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
8134 | { | |
8135 | s += 4; | |
8136 | regno = KT1; | |
8137 | } | |
8138 | else | |
8139 | break; | |
8140 | } | |
8141 | ||
8142 | if (*s == ' ') | |
8143 | ++s; | |
8144 | if (args[1] != *s) | |
8145 | { | |
8146 | if (c == 'v' || c == 'w') | |
8147 | { | |
8148 | regno = mips16_to_32_reg_map[lastregno]; | |
8149 | s = s_reset; | |
8150 | args++; | |
8151 | } | |
8152 | } | |
8153 | ||
8154 | switch (c) | |
8155 | { | |
8156 | case 'x': | |
8157 | case 'y': | |
8158 | case 'z': | |
8159 | case 'v': | |
8160 | case 'w': | |
8161 | case 'Z': | |
8162 | regno = mips32_to_16_reg_map[regno]; | |
8163 | break; | |
8164 | ||
8165 | case '0': | |
8166 | if (regno != 0) | |
8167 | regno = ILLEGAL_REG; | |
8168 | break; | |
8169 | ||
8170 | case 'S': | |
8171 | if (regno != SP) | |
8172 | regno = ILLEGAL_REG; | |
8173 | break; | |
8174 | ||
8175 | case 'R': | |
8176 | if (regno != RA) | |
8177 | regno = ILLEGAL_REG; | |
8178 | break; | |
8179 | ||
8180 | case 'X': | |
8181 | case 'Y': | |
8182 | if (regno == AT && ! mips_opts.noat) | |
8183 | as_warn (_("used $at without \".set noat\"")); | |
8184 | break; | |
8185 | ||
8186 | default: | |
8187 | internalError (); | |
8188 | } | |
8189 | ||
8190 | if (regno == ILLEGAL_REG) | |
8191 | break; | |
8192 | ||
8193 | switch (c) | |
8194 | { | |
8195 | case 'x': | |
8196 | case 'v': | |
8197 | ip->insn_opcode |= regno << MIPS16OP_SH_RX; | |
8198 | break; | |
8199 | case 'y': | |
8200 | case 'w': | |
8201 | ip->insn_opcode |= regno << MIPS16OP_SH_RY; | |
8202 | break; | |
8203 | case 'z': | |
8204 | ip->insn_opcode |= regno << MIPS16OP_SH_RZ; | |
8205 | break; | |
8206 | case 'Z': | |
8207 | ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z; | |
8208 | case '0': | |
8209 | case 'S': | |
8210 | case 'R': | |
8211 | break; | |
8212 | case 'X': | |
8213 | ip->insn_opcode |= regno << MIPS16OP_SH_REGR32; | |
8214 | break; | |
8215 | case 'Y': | |
8216 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
8217 | ip->insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
8218 | break; | |
8219 | default: | |
8220 | internalError (); | |
8221 | } | |
8222 | ||
8223 | lastregno = regno; | |
8224 | continue; | |
8225 | ||
8226 | case 'P': | |
8227 | if (strncmp (s, "$pc", 3) == 0) | |
8228 | { | |
8229 | s += 3; | |
8230 | continue; | |
8231 | } | |
8232 | break; | |
8233 | ||
8234 | case '<': | |
8235 | case '>': | |
8236 | case '[': | |
8237 | case ']': | |
8238 | case '4': | |
8239 | case '5': | |
8240 | case 'H': | |
8241 | case 'W': | |
8242 | case 'D': | |
8243 | case 'j': | |
8244 | case '8': | |
8245 | case 'V': | |
8246 | case 'C': | |
8247 | case 'U': | |
8248 | case 'k': | |
8249 | case 'K': | |
8250 | if (s[0] == '%' | |
8251 | && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0) | |
8252 | { | |
8253 | /* This is %gprel(SYMBOL). We need to read SYMBOL, | |
8254 | and generate the appropriate reloc. If the text | |
8255 | inside %gprel is not a symbol name with an | |
8256 | optional offset, then we generate a normal reloc | |
8257 | and will probably fail later. */ | |
8258 | my_getExpression (&imm_expr, s + sizeof "%gprel" - 1); | |
8259 | if (imm_expr.X_op == O_symbol) | |
8260 | { | |
8261 | mips16_ext = true; | |
8262 | imm_reloc = BFD_RELOC_MIPS16_GPREL; | |
8263 | s = expr_end; | |
8264 | ip->use_extend = true; | |
8265 | ip->extend = 0; | |
8266 | continue; | |
8267 | } | |
8268 | } | |
8269 | else | |
8270 | { | |
8271 | /* Just pick up a normal expression. */ | |
8272 | my_getExpression (&imm_expr, s); | |
8273 | } | |
8274 | ||
8275 | if (imm_expr.X_op == O_register) | |
8276 | { | |
8277 | /* What we thought was an expression turned out to | |
8278 | be a register. */ | |
8279 | ||
8280 | if (s[0] == '(' && args[1] == '(') | |
8281 | { | |
8282 | /* It looks like the expression was omitted | |
8283 | before a register indirection, which means | |
8284 | that the expression is implicitly zero. We | |
8285 | still set up imm_expr, so that we handle | |
8286 | explicit extensions correctly. */ | |
8287 | imm_expr.X_op = O_constant; | |
8288 | imm_expr.X_add_number = 0; | |
8289 | imm_reloc = (int) BFD_RELOC_UNUSED + c; | |
8290 | continue; | |
8291 | } | |
8292 | ||
8293 | break; | |
8294 | } | |
8295 | ||
8296 | /* We need to relax this instruction. */ | |
8297 | imm_reloc = (int) BFD_RELOC_UNUSED + c; | |
8298 | s = expr_end; | |
8299 | continue; | |
8300 | ||
8301 | case 'p': | |
8302 | case 'q': | |
8303 | case 'A': | |
8304 | case 'B': | |
8305 | case 'E': | |
8306 | /* We use offset_reloc rather than imm_reloc for the PC | |
8307 | relative operands. This lets macros with both | |
8308 | immediate and address operands work correctly. */ | |
8309 | my_getExpression (&offset_expr, s); | |
8310 | ||
8311 | if (offset_expr.X_op == O_register) | |
8312 | break; | |
8313 | ||
8314 | /* We need to relax this instruction. */ | |
8315 | offset_reloc = (int) BFD_RELOC_UNUSED + c; | |
8316 | s = expr_end; | |
8317 | continue; | |
8318 | ||
8319 | case '6': /* break code */ | |
8320 | my_getExpression (&imm_expr, s); | |
8321 | check_absolute_expr (ip, &imm_expr); | |
8322 | if ((unsigned long) imm_expr.X_add_number > 63) | |
8323 | { | |
8324 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8325 | ip->insn_mo->name, | |
8326 | (unsigned long) imm_expr.X_add_number); | |
8327 | imm_expr.X_add_number &= 0x3f; | |
8328 | } | |
8329 | ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6; | |
8330 | imm_expr.X_op = O_absent; | |
8331 | s = expr_end; | |
8332 | continue; | |
8333 | ||
8334 | case 'a': /* 26 bit address */ | |
8335 | my_getExpression (&offset_expr, s); | |
8336 | s = expr_end; | |
8337 | offset_reloc = BFD_RELOC_MIPS16_JMP; | |
8338 | ip->insn_opcode <<= 16; | |
8339 | continue; | |
8340 | ||
8341 | case 'l': /* register list for entry macro */ | |
8342 | case 'L': /* register list for exit macro */ | |
8343 | { | |
8344 | int mask; | |
8345 | ||
8346 | if (c == 'l') | |
8347 | mask = 0; | |
8348 | else | |
8349 | mask = 7 << 3; | |
8350 | while (*s != '\0') | |
8351 | { | |
8352 | int freg, reg1, reg2; | |
8353 | ||
8354 | while (*s == ' ' || *s == ',') | |
8355 | ++s; | |
8356 | if (*s != '$') | |
8357 | { | |
8358 | as_bad (_("can't parse register list")); | |
8359 | break; | |
8360 | } | |
8361 | ++s; | |
8362 | if (*s != 'f') | |
8363 | freg = 0; | |
8364 | else | |
8365 | { | |
8366 | freg = 1; | |
8367 | ++s; | |
8368 | } | |
8369 | reg1 = 0; | |
3882b010 | 8370 | while (ISDIGIT (*s)) |
252b5132 RH |
8371 | { |
8372 | reg1 *= 10; | |
8373 | reg1 += *s - '0'; | |
8374 | ++s; | |
8375 | } | |
8376 | if (*s == ' ') | |
8377 | ++s; | |
8378 | if (*s != '-') | |
8379 | reg2 = reg1; | |
8380 | else | |
8381 | { | |
8382 | ++s; | |
8383 | if (*s != '$') | |
8384 | break; | |
8385 | ++s; | |
8386 | if (freg) | |
8387 | { | |
8388 | if (*s == 'f') | |
8389 | ++s; | |
8390 | else | |
8391 | { | |
8392 | as_bad (_("invalid register list")); | |
8393 | break; | |
8394 | } | |
8395 | } | |
8396 | reg2 = 0; | |
3882b010 | 8397 | while (ISDIGIT (*s)) |
252b5132 RH |
8398 | { |
8399 | reg2 *= 10; | |
8400 | reg2 += *s - '0'; | |
8401 | ++s; | |
8402 | } | |
8403 | } | |
8404 | if (freg && reg1 == 0 && reg2 == 0 && c == 'L') | |
8405 | { | |
8406 | mask &= ~ (7 << 3); | |
8407 | mask |= 5 << 3; | |
8408 | } | |
8409 | else if (freg && reg1 == 0 && reg2 == 1 && c == 'L') | |
8410 | { | |
8411 | mask &= ~ (7 << 3); | |
8412 | mask |= 6 << 3; | |
8413 | } | |
8414 | else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L') | |
8415 | mask |= (reg2 - 3) << 3; | |
8416 | else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17) | |
8417 | mask |= (reg2 - 15) << 1; | |
8418 | else if (reg1 == 31 && reg2 == 31) | |
8419 | mask |= 1; | |
8420 | else | |
8421 | { | |
8422 | as_bad (_("invalid register list")); | |
8423 | break; | |
8424 | } | |
8425 | } | |
8426 | /* The mask is filled in in the opcode table for the | |
8427 | benefit of the disassembler. We remove it before | |
8428 | applying the actual mask. */ | |
8429 | ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6); | |
8430 | ip->insn_opcode |= mask << MIPS16OP_SH_IMM6; | |
8431 | } | |
8432 | continue; | |
8433 | ||
8434 | case 'e': /* extend code */ | |
8435 | my_getExpression (&imm_expr, s); | |
8436 | check_absolute_expr (ip, &imm_expr); | |
8437 | if ((unsigned long) imm_expr.X_add_number > 0x7ff) | |
8438 | { | |
8439 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8440 | ip->insn_mo->name, | |
8441 | (unsigned long) imm_expr.X_add_number); | |
8442 | imm_expr.X_add_number &= 0x7ff; | |
8443 | } | |
8444 | ip->insn_opcode |= imm_expr.X_add_number; | |
8445 | imm_expr.X_op = O_absent; | |
8446 | s = expr_end; | |
8447 | continue; | |
8448 | ||
8449 | default: | |
8450 | internalError (); | |
8451 | } | |
8452 | break; | |
8453 | } | |
8454 | ||
8455 | /* Args don't match. */ | |
8456 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] && | |
8457 | strcmp (insn->name, insn[1].name) == 0) | |
8458 | { | |
8459 | ++insn; | |
8460 | s = argsstart; | |
8461 | continue; | |
8462 | } | |
8463 | ||
8464 | insn_error = _("illegal operands"); | |
8465 | ||
8466 | return; | |
8467 | } | |
8468 | } | |
8469 | ||
8470 | /* This structure holds information we know about a mips16 immediate | |
8471 | argument type. */ | |
8472 | ||
e972090a NC |
8473 | struct mips16_immed_operand |
8474 | { | |
252b5132 RH |
8475 | /* The type code used in the argument string in the opcode table. */ |
8476 | int type; | |
8477 | /* The number of bits in the short form of the opcode. */ | |
8478 | int nbits; | |
8479 | /* The number of bits in the extended form of the opcode. */ | |
8480 | int extbits; | |
8481 | /* The amount by which the short form is shifted when it is used; | |
8482 | for example, the sw instruction has a shift count of 2. */ | |
8483 | int shift; | |
8484 | /* The amount by which the short form is shifted when it is stored | |
8485 | into the instruction code. */ | |
8486 | int op_shift; | |
8487 | /* Non-zero if the short form is unsigned. */ | |
8488 | int unsp; | |
8489 | /* Non-zero if the extended form is unsigned. */ | |
8490 | int extu; | |
8491 | /* Non-zero if the value is PC relative. */ | |
8492 | int pcrel; | |
8493 | }; | |
8494 | ||
8495 | /* The mips16 immediate operand types. */ | |
8496 | ||
8497 | static const struct mips16_immed_operand mips16_immed_operands[] = | |
8498 | { | |
8499 | { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
8500 | { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
8501 | { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
8502 | { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
8503 | { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 }, | |
8504 | { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8505 | { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8506 | { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8507 | { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8508 | { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 }, | |
8509 | { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8510 | { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8511 | { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8512 | { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 }, | |
8513 | { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
8514 | { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
8515 | { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
8516 | { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
8517 | { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 }, | |
8518 | { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 }, | |
8519 | { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 } | |
8520 | }; | |
8521 | ||
8522 | #define MIPS16_NUM_IMMED \ | |
8523 | (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0]) | |
8524 | ||
8525 | /* Handle a mips16 instruction with an immediate value. This or's the | |
8526 | small immediate value into *INSN. It sets *USE_EXTEND to indicate | |
8527 | whether an extended value is needed; if one is needed, it sets | |
8528 | *EXTEND to the value. The argument type is TYPE. The value is VAL. | |
8529 | If SMALL is true, an unextended opcode was explicitly requested. | |
8530 | If EXT is true, an extended opcode was explicitly requested. If | |
8531 | WARN is true, warn if EXT does not match reality. */ | |
8532 | ||
8533 | static void | |
8534 | mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend, | |
8535 | extend) | |
8536 | char *file; | |
8537 | unsigned int line; | |
8538 | int type; | |
8539 | offsetT val; | |
8540 | boolean warn; | |
8541 | boolean small; | |
8542 | boolean ext; | |
8543 | unsigned long *insn; | |
8544 | boolean *use_extend; | |
8545 | unsigned short *extend; | |
8546 | { | |
8547 | register const struct mips16_immed_operand *op; | |
8548 | int mintiny, maxtiny; | |
8549 | boolean needext; | |
8550 | ||
8551 | op = mips16_immed_operands; | |
8552 | while (op->type != type) | |
8553 | { | |
8554 | ++op; | |
8555 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
8556 | } | |
8557 | ||
8558 | if (op->unsp) | |
8559 | { | |
8560 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
8561 | { | |
8562 | mintiny = 1; | |
8563 | maxtiny = 1 << op->nbits; | |
8564 | } | |
8565 | else | |
8566 | { | |
8567 | mintiny = 0; | |
8568 | maxtiny = (1 << op->nbits) - 1; | |
8569 | } | |
8570 | } | |
8571 | else | |
8572 | { | |
8573 | mintiny = - (1 << (op->nbits - 1)); | |
8574 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
8575 | } | |
8576 | ||
8577 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
8578 | if (type == 'p' || type == 'q') | |
8579 | val /= 2; | |
8580 | ||
8581 | if ((val & ((1 << op->shift) - 1)) != 0 | |
8582 | || val < (mintiny << op->shift) | |
8583 | || val > (maxtiny << op->shift)) | |
8584 | needext = true; | |
8585 | else | |
8586 | needext = false; | |
8587 | ||
8588 | if (warn && ext && ! needext) | |
beae10d5 KH |
8589 | as_warn_where (file, line, |
8590 | _("extended operand requested but not required")); | |
252b5132 RH |
8591 | if (small && needext) |
8592 | as_bad_where (file, line, _("invalid unextended operand value")); | |
8593 | ||
8594 | if (small || (! ext && ! needext)) | |
8595 | { | |
8596 | int insnval; | |
8597 | ||
8598 | *use_extend = false; | |
8599 | insnval = ((val >> op->shift) & ((1 << op->nbits) - 1)); | |
8600 | insnval <<= op->op_shift; | |
8601 | *insn |= insnval; | |
8602 | } | |
8603 | else | |
8604 | { | |
8605 | long minext, maxext; | |
8606 | int extval; | |
8607 | ||
8608 | if (op->extu) | |
8609 | { | |
8610 | minext = 0; | |
8611 | maxext = (1 << op->extbits) - 1; | |
8612 | } | |
8613 | else | |
8614 | { | |
8615 | minext = - (1 << (op->extbits - 1)); | |
8616 | maxext = (1 << (op->extbits - 1)) - 1; | |
8617 | } | |
8618 | if (val < minext || val > maxext) | |
8619 | as_bad_where (file, line, | |
8620 | _("operand value out of range for instruction")); | |
8621 | ||
8622 | *use_extend = true; | |
8623 | if (op->extbits == 16) | |
8624 | { | |
8625 | extval = ((val >> 11) & 0x1f) | (val & 0x7e0); | |
8626 | val &= 0x1f; | |
8627 | } | |
8628 | else if (op->extbits == 15) | |
8629 | { | |
8630 | extval = ((val >> 11) & 0xf) | (val & 0x7f0); | |
8631 | val &= 0xf; | |
8632 | } | |
8633 | else | |
8634 | { | |
8635 | extval = ((val & 0x1f) << 6) | (val & 0x20); | |
8636 | val = 0; | |
8637 | } | |
8638 | ||
8639 | *extend = (unsigned short) extval; | |
8640 | *insn |= val; | |
8641 | } | |
8642 | } | |
8643 | \f | |
252b5132 RH |
8644 | |
8645 | static int | |
8646 | my_getSmallExpression (ep, str) | |
8647 | expressionS *ep; | |
8648 | char *str; | |
8649 | { | |
8650 | char *sp; | |
fb1b3232 TS |
8651 | char *oldstr = str; |
8652 | int c = S_EX_NONE; | |
252b5132 RH |
8653 | |
8654 | if (*str == ' ') | |
8655 | str++; | |
fb1b3232 TS |
8656 | if (*str == '(') |
8657 | c = S_EX_NONE; | |
8658 | else if (str[0] == '%' | |
3882b010 L |
8659 | && TOLOWER (str[1]) == 'l' |
8660 | && TOLOWER (str[2]) == 'o' | |
fb1b3232 | 8661 | && str[3] == '(') |
252b5132 | 8662 | { |
fb1b3232 TS |
8663 | c = S_EX_LO; |
8664 | str += sizeof ("%lo(") - 2; | |
8665 | } | |
8666 | else if (str[0] == '%' | |
3882b010 L |
8667 | && TOLOWER (str[1]) == 'h' |
8668 | && TOLOWER (str[2]) == 'i' | |
fb1b3232 TS |
8669 | && str[3] == '(') |
8670 | { | |
8671 | c = S_EX_HI; | |
8672 | str += sizeof ("%hi(") - 2; | |
8673 | } | |
8674 | else if (str[0] == '%' | |
3882b010 L |
8675 | && TOLOWER (str[1]) == 'h' |
8676 | && TOLOWER (str[2]) == 'i' | |
8677 | && TOLOWER (str[3]) == 'g' | |
8678 | && TOLOWER (str[4]) == 'h' | |
8679 | && TOLOWER (str[5]) == 'e' | |
8680 | && TOLOWER (str[6]) == 'r' | |
fb1b3232 TS |
8681 | && str[7] == '(') |
8682 | { | |
8683 | c = S_EX_HIGHER; | |
8684 | str += sizeof ("%higher(") - 2; | |
8685 | } | |
8686 | else if (str[0] == '%' | |
3882b010 L |
8687 | && TOLOWER (str[1]) == 'h' |
8688 | && TOLOWER (str[2]) == 'i' | |
8689 | && TOLOWER (str[3]) == 'g' | |
8690 | && TOLOWER (str[4]) == 'h' | |
8691 | && TOLOWER (str[5]) == 'e' | |
8692 | && TOLOWER (str[6]) == 's' | |
8693 | && TOLOWER (str[7]) == 't' | |
fb1b3232 TS |
8694 | && str[8] == '(') |
8695 | { | |
8696 | c = S_EX_HIGHEST; | |
8697 | str += sizeof ("%highest(") - 2; | |
8698 | } | |
8699 | /* currently unsupported */ | |
8700 | #if 0 | |
8701 | else if (str[0] == '%' | |
3882b010 L |
8702 | && TOLOWER (str[1]) == 'g' |
8703 | && TOLOWER (str[2]) == 'p' | |
8704 | && TOLOWER (str[3]) == '_' | |
8705 | && TOLOWER (str[4]) == 'r' | |
8706 | && TOLOWER (str[5]) == 'e' | |
8707 | && TOLOWER (str[6]) == 'l' | |
e7d556df | 8708 | && str[7] == '(') |
fb1b3232 TS |
8709 | { |
8710 | c = S_EX_GPREL; | |
e7d556df | 8711 | str += sizeof ("%gp_rel(") - 2; |
fb1b3232 TS |
8712 | } |
8713 | else if (str[0] == '%' | |
3882b010 L |
8714 | && TOLOWER (str[1]) == 'n' |
8715 | && TOLOWER (str[2]) == 'e' | |
8716 | && TOLOWER (str[3]) == 'g' | |
fb1b3232 TS |
8717 | && str[4] == '(') |
8718 | { | |
8719 | c = S_EX_NEG; | |
8720 | str += sizeof ("%neg(") - 2; | |
8721 | } | |
8722 | #endif | |
8723 | else | |
8724 | { | |
8725 | my_getExpression (ep, str); | |
8726 | return c; | |
8727 | } | |
252b5132 | 8728 | |
fb1b3232 TS |
8729 | /* |
8730 | * A small expression may be followed by a base register. | |
8731 | * Scan to the end of this operand, and then back over a possible | |
8732 | * base register. Then scan the small expression up to that | |
8733 | * point. (Based on code in sparc.c...) | |
8734 | */ | |
8735 | for (sp = str; *sp && *sp != ','; sp++) | |
8736 | ; | |
8737 | if (sp - 4 >= str && sp[-1] == ')') | |
8738 | { | |
3882b010 | 8739 | if (ISDIGIT (sp[-2])) |
252b5132 | 8740 | { |
3882b010 | 8741 | for (sp -= 3; sp >= str && ISDIGIT (*sp); sp--) |
fb1b3232 TS |
8742 | ; |
8743 | if (*sp == '$' && sp > str && sp[-1] == '(') | |
252b5132 | 8744 | { |
fb1b3232 TS |
8745 | sp--; |
8746 | goto do_it; | |
252b5132 | 8747 | } |
fb1b3232 TS |
8748 | } |
8749 | else if (sp - 5 >= str | |
8750 | && sp[-5] == '(' | |
8751 | && sp[-4] == '$' | |
8752 | && ((sp[-3] == 'f' && sp[-2] == 'p') | |
8753 | || (sp[-3] == 's' && sp[-2] == 'p') | |
8754 | || (sp[-3] == 'g' && sp[-2] == 'p') | |
8755 | || (sp[-3] == 'a' && sp[-2] == 't'))) | |
8756 | { | |
8757 | sp -= 5; | |
8758 | do_it: | |
8759 | if (sp == str) | |
252b5132 | 8760 | { |
fb1b3232 TS |
8761 | /* no expression means zero offset */ |
8762 | if (c != S_EX_NONE) | |
252b5132 | 8763 | { |
fb1b3232 TS |
8764 | /* %xx(reg) is an error */ |
8765 | ep->X_op = O_absent; | |
8766 | expr_end = oldstr; | |
252b5132 RH |
8767 | } |
8768 | else | |
8769 | { | |
fb1b3232 TS |
8770 | ep->X_op = O_constant; |
8771 | expr_end = sp; | |
252b5132 | 8772 | } |
fb1b3232 TS |
8773 | ep->X_add_symbol = NULL; |
8774 | ep->X_op_symbol = NULL; | |
8775 | ep->X_add_number = 0; | |
252b5132 | 8776 | } |
fb1b3232 TS |
8777 | else |
8778 | { | |
8779 | *sp = '\0'; | |
8780 | my_getExpression (ep, str); | |
8781 | *sp = '('; | |
8782 | } | |
8783 | return c; | |
252b5132 RH |
8784 | } |
8785 | } | |
8786 | my_getExpression (ep, str); | |
fb1b3232 TS |
8787 | |
8788 | /* => %highest, %higher, %hi, %lo, %gprel, %neg encountered */ | |
8789 | return c; | |
252b5132 RH |
8790 | } |
8791 | ||
8792 | static void | |
8793 | my_getExpression (ep, str) | |
8794 | expressionS *ep; | |
8795 | char *str; | |
8796 | { | |
8797 | char *save_in; | |
98aa84af | 8798 | valueT val; |
252b5132 RH |
8799 | |
8800 | save_in = input_line_pointer; | |
8801 | input_line_pointer = str; | |
8802 | expression (ep); | |
8803 | expr_end = input_line_pointer; | |
8804 | input_line_pointer = save_in; | |
8805 | ||
8806 | /* If we are in mips16 mode, and this is an expression based on `.', | |
8807 | then we bump the value of the symbol by 1 since that is how other | |
8808 | text symbols are handled. We don't bother to handle complex | |
8809 | expressions, just `.' plus or minus a constant. */ | |
8810 | if (mips_opts.mips16 | |
8811 | && ep->X_op == O_symbol | |
8812 | && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0 | |
8813 | && S_GET_SEGMENT (ep->X_add_symbol) == now_seg | |
49309057 ILT |
8814 | && symbol_get_frag (ep->X_add_symbol) == frag_now |
8815 | && symbol_constant_p (ep->X_add_symbol) | |
98aa84af AM |
8816 | && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ()) |
8817 | S_SET_VALUE (ep->X_add_symbol, val + 1); | |
252b5132 RH |
8818 | } |
8819 | ||
8820 | /* Turn a string in input_line_pointer into a floating point constant | |
bc0d738a NC |
8821 | of type TYPE, and store the appropriate bytes in *LITP. The number |
8822 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
252b5132 RH |
8823 | returned, or NULL on OK. */ |
8824 | ||
8825 | char * | |
8826 | md_atof (type, litP, sizeP) | |
8827 | int type; | |
8828 | char *litP; | |
8829 | int *sizeP; | |
8830 | { | |
8831 | int prec; | |
8832 | LITTLENUM_TYPE words[4]; | |
8833 | char *t; | |
8834 | int i; | |
8835 | ||
8836 | switch (type) | |
8837 | { | |
8838 | case 'f': | |
8839 | prec = 2; | |
8840 | break; | |
8841 | ||
8842 | case 'd': | |
8843 | prec = 4; | |
8844 | break; | |
8845 | ||
8846 | default: | |
8847 | *sizeP = 0; | |
8848 | return _("bad call to md_atof"); | |
8849 | } | |
8850 | ||
8851 | t = atof_ieee (input_line_pointer, type, words); | |
8852 | if (t) | |
8853 | input_line_pointer = t; | |
8854 | ||
8855 | *sizeP = prec * 2; | |
8856 | ||
8857 | if (! target_big_endian) | |
8858 | { | |
8859 | for (i = prec - 1; i >= 0; i--) | |
8860 | { | |
8861 | md_number_to_chars (litP, (valueT) words[i], 2); | |
8862 | litP += 2; | |
8863 | } | |
8864 | } | |
8865 | else | |
8866 | { | |
8867 | for (i = 0; i < prec; i++) | |
8868 | { | |
8869 | md_number_to_chars (litP, (valueT) words[i], 2); | |
8870 | litP += 2; | |
8871 | } | |
8872 | } | |
bdaaa2e1 | 8873 | |
252b5132 RH |
8874 | return NULL; |
8875 | } | |
8876 | ||
8877 | void | |
8878 | md_number_to_chars (buf, val, n) | |
8879 | char *buf; | |
8880 | valueT val; | |
8881 | int n; | |
8882 | { | |
8883 | if (target_big_endian) | |
8884 | number_to_chars_bigendian (buf, val, n); | |
8885 | else | |
8886 | number_to_chars_littleendian (buf, val, n); | |
8887 | } | |
8888 | \f | |
e013f690 TS |
8889 | static int support_64bit_objects(void) |
8890 | { | |
8891 | const char **list, **l; | |
8892 | ||
8893 | list = bfd_target_list (); | |
8894 | for (l = list; *l != NULL; l++) | |
8895 | #ifdef TE_TMIPS | |
8896 | /* This is traditional mips */ | |
8897 | if (strcmp (*l, "elf64-tradbigmips") == 0 | |
8898 | || strcmp (*l, "elf64-tradlittlemips") == 0) | |
8899 | #else | |
8900 | if (strcmp (*l, "elf64-bigmips") == 0 | |
8901 | || strcmp (*l, "elf64-littlemips") == 0) | |
8902 | #endif | |
8903 | break; | |
8904 | free (list); | |
8905 | return (*l != NULL); | |
8906 | } | |
8907 | ||
39c0a331 | 8908 | CONST char *md_shortopts = "nO::g::G:"; |
252b5132 | 8909 | |
e972090a NC |
8910 | struct option md_longopts[] = |
8911 | { | |
252b5132 RH |
8912 | #define OPTION_MIPS1 (OPTION_MD_BASE + 1) |
8913 | {"mips0", no_argument, NULL, OPTION_MIPS1}, | |
8914 | {"mips1", no_argument, NULL, OPTION_MIPS1}, | |
8915 | #define OPTION_MIPS2 (OPTION_MD_BASE + 2) | |
8916 | {"mips2", no_argument, NULL, OPTION_MIPS2}, | |
8917 | #define OPTION_MIPS3 (OPTION_MD_BASE + 3) | |
8918 | {"mips3", no_argument, NULL, OPTION_MIPS3}, | |
8919 | #define OPTION_MIPS4 (OPTION_MD_BASE + 4) | |
8920 | {"mips4", no_argument, NULL, OPTION_MIPS4}, | |
8921 | #define OPTION_MCPU (OPTION_MD_BASE + 5) | |
8922 | {"mcpu", required_argument, NULL, OPTION_MCPU}, | |
8923 | #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 6) | |
8924 | {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC}, | |
156c2f8b | 8925 | #define OPTION_TRAP (OPTION_MD_BASE + 7) |
252b5132 RH |
8926 | {"trap", no_argument, NULL, OPTION_TRAP}, |
8927 | {"no-break", no_argument, NULL, OPTION_TRAP}, | |
156c2f8b | 8928 | #define OPTION_BREAK (OPTION_MD_BASE + 8) |
252b5132 RH |
8929 | {"break", no_argument, NULL, OPTION_BREAK}, |
8930 | {"no-trap", no_argument, NULL, OPTION_BREAK}, | |
156c2f8b | 8931 | #define OPTION_EB (OPTION_MD_BASE + 9) |
252b5132 | 8932 | {"EB", no_argument, NULL, OPTION_EB}, |
156c2f8b | 8933 | #define OPTION_EL (OPTION_MD_BASE + 10) |
252b5132 | 8934 | {"EL", no_argument, NULL, OPTION_EL}, |
156c2f8b | 8935 | #define OPTION_M4650 (OPTION_MD_BASE + 11) |
252b5132 | 8936 | {"m4650", no_argument, NULL, OPTION_M4650}, |
156c2f8b | 8937 | #define OPTION_NO_M4650 (OPTION_MD_BASE + 12) |
252b5132 | 8938 | {"no-m4650", no_argument, NULL, OPTION_NO_M4650}, |
156c2f8b | 8939 | #define OPTION_M4010 (OPTION_MD_BASE + 13) |
252b5132 | 8940 | {"m4010", no_argument, NULL, OPTION_M4010}, |
156c2f8b | 8941 | #define OPTION_NO_M4010 (OPTION_MD_BASE + 14) |
252b5132 | 8942 | {"no-m4010", no_argument, NULL, OPTION_NO_M4010}, |
156c2f8b | 8943 | #define OPTION_M4100 (OPTION_MD_BASE + 15) |
252b5132 | 8944 | {"m4100", no_argument, NULL, OPTION_M4100}, |
156c2f8b | 8945 | #define OPTION_NO_M4100 (OPTION_MD_BASE + 16) |
252b5132 | 8946 | {"no-m4100", no_argument, NULL, OPTION_NO_M4100}, |
156c2f8b | 8947 | #define OPTION_MIPS16 (OPTION_MD_BASE + 17) |
252b5132 | 8948 | {"mips16", no_argument, NULL, OPTION_MIPS16}, |
156c2f8b | 8949 | #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 18) |
252b5132 | 8950 | {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16}, |
156c2f8b | 8951 | #define OPTION_M3900 (OPTION_MD_BASE + 19) |
252b5132 | 8952 | {"m3900", no_argument, NULL, OPTION_M3900}, |
156c2f8b | 8953 | #define OPTION_NO_M3900 (OPTION_MD_BASE + 20) |
252b5132 | 8954 | {"no-m3900", no_argument, NULL, OPTION_NO_M3900}, |
156c2f8b | 8955 | #define OPTION_MABI (OPTION_MD_BASE + 21) |
252b5132 | 8956 | {"mabi", required_argument, NULL, OPTION_MABI}, |
156c2f8b | 8957 | #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 22) |
6b76fefe | 8958 | {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX}, |
156c2f8b | 8959 | #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 23) |
6b76fefe | 8960 | {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX}, |
156c2f8b | 8961 | #define OPTION_GP32 (OPTION_MD_BASE + 24) |
c97ef257 | 8962 | {"mgp32", no_argument, NULL, OPTION_GP32}, |
156c2f8b | 8963 | #define OPTION_GP64 (OPTION_MD_BASE + 25) |
c97ef257 | 8964 | {"mgp64", no_argument, NULL, OPTION_GP64}, |
156c2f8b | 8965 | #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 26) |
119d663a | 8966 | {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS}, |
156c2f8b | 8967 | #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 27) |
119d663a | 8968 | {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS}, |
156c2f8b NC |
8969 | #define OPTION_MIPS32 (OPTION_MD_BASE + 28) |
8970 | {"mips32", no_argument, NULL, OPTION_MIPS32}, | |
84ea6cf2 NC |
8971 | #define OPTION_MIPS5 (OPTION_MD_BASE + 29) |
8972 | {"mips5", no_argument, NULL, OPTION_MIPS5}, | |
8973 | #define OPTION_MIPS64 (OPTION_MD_BASE + 30) | |
8974 | {"mips64", no_argument, NULL, OPTION_MIPS64}, | |
ec68c924 EC |
8975 | #define OPTION_MARCH (OPTION_MD_BASE + 31) |
8976 | {"march", required_argument, NULL, OPTION_MARCH}, | |
8977 | #define OPTION_MTUNE (OPTION_MD_BASE + 32) | |
8978 | {"mtune", required_argument, NULL, OPTION_MTUNE}, | |
ca4e0257 RS |
8979 | #define OPTION_FP32 (OPTION_MD_BASE + 33) |
8980 | {"mfp32", no_argument, NULL, OPTION_FP32}, | |
156c2f8b NC |
8981 | #ifdef OBJ_ELF |
8982 | #define OPTION_ELF_BASE (OPTION_MD_BASE + 35) | |
8983 | #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0) | |
8984 | #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1) | |
8985 | #define OPTION_XGOT (OPTION_ELF_BASE + 2) | |
8986 | #define OPTION_32 (OPTION_ELF_BASE + 3) | |
e013f690 TS |
8987 | #define OPTION_N32 (OPTION_ELF_BASE + 4) |
8988 | #define OPTION_64 (OPTION_ELF_BASE + 5) | |
156c2f8b NC |
8989 | {"KPIC", no_argument, NULL, OPTION_CALL_SHARED}, |
8990 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, | |
8991 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, | |
8992 | {"xgot", no_argument, NULL, OPTION_XGOT}, | |
8993 | {"32", no_argument, NULL, OPTION_32}, | |
e013f690 | 8994 | {"n32", no_argument, NULL, OPTION_N32}, |
156c2f8b NC |
8995 | {"64", no_argument, NULL, OPTION_64}, |
8996 | #endif | |
119d663a | 8997 | |
252b5132 RH |
8998 | {NULL, no_argument, NULL, 0} |
8999 | }; | |
156c2f8b | 9000 | size_t md_longopts_size = sizeof (md_longopts); |
252b5132 RH |
9001 | |
9002 | int | |
9003 | md_parse_option (c, arg) | |
9004 | int c; | |
9005 | char *arg; | |
9006 | { | |
9007 | switch (c) | |
9008 | { | |
119d663a NC |
9009 | case OPTION_CONSTRUCT_FLOATS: |
9010 | mips_disable_float_construction = 0; | |
9011 | break; | |
bdaaa2e1 | 9012 | |
119d663a NC |
9013 | case OPTION_NO_CONSTRUCT_FLOATS: |
9014 | mips_disable_float_construction = 1; | |
9015 | break; | |
bdaaa2e1 | 9016 | |
252b5132 RH |
9017 | case OPTION_TRAP: |
9018 | mips_trap = 1; | |
9019 | break; | |
9020 | ||
9021 | case OPTION_BREAK: | |
9022 | mips_trap = 0; | |
9023 | break; | |
9024 | ||
9025 | case OPTION_EB: | |
9026 | target_big_endian = 1; | |
9027 | break; | |
9028 | ||
9029 | case OPTION_EL: | |
9030 | target_big_endian = 0; | |
9031 | break; | |
9032 | ||
39c0a331 L |
9033 | case 'n': |
9034 | warn_nops = 1; | |
9035 | break; | |
9036 | ||
252b5132 RH |
9037 | case 'O': |
9038 | if (arg && arg[1] == '0') | |
9039 | mips_optimize = 1; | |
9040 | else | |
9041 | mips_optimize = 2; | |
9042 | break; | |
9043 | ||
9044 | case 'g': | |
9045 | if (arg == NULL) | |
9046 | mips_debug = 2; | |
9047 | else | |
9048 | mips_debug = atoi (arg); | |
9049 | /* When the MIPS assembler sees -g or -g2, it does not do | |
9050 | optimizations which limit full symbolic debugging. We take | |
9051 | that to be equivalent to -O0. */ | |
9052 | if (mips_debug == 2) | |
9053 | mips_optimize = 1; | |
9054 | break; | |
9055 | ||
9056 | case OPTION_MIPS1: | |
e7af610e | 9057 | mips_opts.isa = ISA_MIPS1; |
252b5132 RH |
9058 | break; |
9059 | ||
9060 | case OPTION_MIPS2: | |
e7af610e | 9061 | mips_opts.isa = ISA_MIPS2; |
252b5132 RH |
9062 | break; |
9063 | ||
9064 | case OPTION_MIPS3: | |
e7af610e | 9065 | mips_opts.isa = ISA_MIPS3; |
252b5132 RH |
9066 | break; |
9067 | ||
9068 | case OPTION_MIPS4: | |
e7af610e NC |
9069 | mips_opts.isa = ISA_MIPS4; |
9070 | break; | |
9071 | ||
84ea6cf2 NC |
9072 | case OPTION_MIPS5: |
9073 | mips_opts.isa = ISA_MIPS5; | |
9074 | break; | |
9075 | ||
e7af610e NC |
9076 | case OPTION_MIPS32: |
9077 | mips_opts.isa = ISA_MIPS32; | |
252b5132 RH |
9078 | break; |
9079 | ||
84ea6cf2 NC |
9080 | case OPTION_MIPS64: |
9081 | mips_opts.isa = ISA_MIPS64; | |
9082 | break; | |
9083 | ||
ec68c924 EC |
9084 | case OPTION_MTUNE: |
9085 | case OPTION_MARCH: | |
252b5132 RH |
9086 | case OPTION_MCPU: |
9087 | { | |
ec68c924 EC |
9088 | int cpu = CPU_UNKNOWN; |
9089 | ||
e7af610e | 9090 | /* Identify the processor type. */ |
ec68c924 | 9091 | if (strcasecmp (arg, "default") != 0) |
252b5132 | 9092 | { |
e7af610e | 9093 | const struct mips_cpu_info *ci; |
252b5132 | 9094 | |
e7af610e NC |
9095 | ci = mips_cpu_info_from_name (arg); |
9096 | if (ci == NULL || ci->is_isa) | |
ec68c924 EC |
9097 | { |
9098 | switch (c) | |
9099 | { | |
9100 | case OPTION_MTUNE: | |
9101 | as_fatal (_("invalid architecture -mtune=%s"), arg); | |
9102 | break; | |
9103 | case OPTION_MARCH: | |
9104 | as_fatal (_("invalid architecture -march=%s"), arg); | |
9105 | break; | |
9106 | case OPTION_MCPU: | |
9107 | as_fatal (_("invalid architecture -mcpu=%s"), arg); | |
9108 | break; | |
9109 | } | |
9110 | } | |
e7af610e | 9111 | else |
ec68c924 EC |
9112 | cpu = ci->cpu; |
9113 | } | |
9114 | ||
9115 | switch (c) | |
9116 | { | |
9117 | case OPTION_MTUNE: | |
6dce9e24 TS |
9118 | if (mips_tune != CPU_UNKNOWN && mips_tune != cpu) |
9119 | as_warn(_("A different -mtune= was already specified, is now " | |
9120 | "-mtune=%s"), arg); | |
ec68c924 EC |
9121 | mips_tune = cpu; |
9122 | break; | |
9123 | case OPTION_MARCH: | |
6dce9e24 TS |
9124 | if (mips_arch != CPU_UNKNOWN && mips_arch != cpu) |
9125 | as_warn(_("A different -march= was already specified, is now " | |
9126 | "-march=%s"), arg); | |
ec68c924 EC |
9127 | mips_arch = cpu; |
9128 | break; | |
9129 | case OPTION_MCPU: | |
6dce9e24 TS |
9130 | if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu) |
9131 | as_warn(_("A different -mcpu= was already specified, is now " | |
9132 | "-mcpu=%s"), arg); | |
ec68c924 | 9133 | mips_cpu = cpu; |
252b5132 RH |
9134 | } |
9135 | } | |
9136 | break; | |
9137 | ||
9138 | case OPTION_M4650: | |
6dce9e24 TS |
9139 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650) |
9140 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650)) | |
9141 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9142 | "is now -m4650")); | |
ec68c924 EC |
9143 | mips_arch = CPU_R4650; |
9144 | mips_tune = CPU_R4650; | |
252b5132 RH |
9145 | break; |
9146 | ||
9147 | case OPTION_NO_M4650: | |
9148 | break; | |
9149 | ||
9150 | case OPTION_M4010: | |
6dce9e24 TS |
9151 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010) |
9152 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010)) | |
9153 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9154 | "is now -m4010")); | |
ec68c924 EC |
9155 | mips_arch = CPU_R4010; |
9156 | mips_tune = CPU_R4010; | |
252b5132 RH |
9157 | break; |
9158 | ||
9159 | case OPTION_NO_M4010: | |
9160 | break; | |
9161 | ||
9162 | case OPTION_M4100: | |
6dce9e24 TS |
9163 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100) |
9164 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100)) | |
9165 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9166 | "is now -m4100")); | |
ec68c924 EC |
9167 | mips_arch = CPU_VR4100; |
9168 | mips_tune = CPU_VR4100; | |
252b5132 RH |
9169 | break; |
9170 | ||
9171 | case OPTION_NO_M4100: | |
9172 | break; | |
9173 | ||
252b5132 | 9174 | case OPTION_M3900: |
6dce9e24 TS |
9175 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900) |
9176 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900)) | |
9177 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9178 | "is now -m3900")); | |
ec68c924 EC |
9179 | mips_arch = CPU_R3900; |
9180 | mips_tune = CPU_R3900; | |
252b5132 | 9181 | break; |
bdaaa2e1 | 9182 | |
252b5132 RH |
9183 | case OPTION_NO_M3900: |
9184 | break; | |
9185 | ||
9186 | case OPTION_MIPS16: | |
9187 | mips_opts.mips16 = 1; | |
9188 | mips_no_prev_insn (false); | |
9189 | break; | |
9190 | ||
9191 | case OPTION_NO_MIPS16: | |
9192 | mips_opts.mips16 = 0; | |
9193 | mips_no_prev_insn (false); | |
9194 | break; | |
9195 | ||
9196 | case OPTION_MEMBEDDED_PIC: | |
9197 | mips_pic = EMBEDDED_PIC; | |
9198 | if (USE_GLOBAL_POINTER_OPT && g_switch_seen) | |
9199 | { | |
9200 | as_bad (_("-G may not be used with embedded PIC code")); | |
9201 | return 0; | |
9202 | } | |
9203 | g_switch_value = 0x7fffffff; | |
9204 | break; | |
9205 | ||
0f074f60 | 9206 | #ifdef OBJ_ELF |
252b5132 RH |
9207 | /* When generating ELF code, we permit -KPIC and -call_shared to |
9208 | select SVR4_PIC, and -non_shared to select no PIC. This is | |
9209 | intended to be compatible with Irix 5. */ | |
9210 | case OPTION_CALL_SHARED: | |
9211 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9212 | { | |
9213 | as_bad (_("-call_shared is supported only for ELF format")); | |
9214 | return 0; | |
9215 | } | |
9216 | mips_pic = SVR4_PIC; | |
9217 | if (g_switch_seen && g_switch_value != 0) | |
9218 | { | |
9219 | as_bad (_("-G may not be used with SVR4 PIC code")); | |
9220 | return 0; | |
9221 | } | |
9222 | g_switch_value = 0; | |
9223 | break; | |
9224 | ||
9225 | case OPTION_NON_SHARED: | |
9226 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9227 | { | |
9228 | as_bad (_("-non_shared is supported only for ELF format")); | |
9229 | return 0; | |
9230 | } | |
9231 | mips_pic = NO_PIC; | |
9232 | break; | |
9233 | ||
9234 | /* The -xgot option tells the assembler to use 32 offsets when | |
9235 | accessing the got in SVR4_PIC mode. It is for Irix | |
9236 | compatibility. */ | |
9237 | case OPTION_XGOT: | |
9238 | mips_big_got = 1; | |
9239 | break; | |
0f074f60 | 9240 | #endif /* OBJ_ELF */ |
252b5132 RH |
9241 | |
9242 | case 'G': | |
9243 | if (! USE_GLOBAL_POINTER_OPT) | |
9244 | { | |
9245 | as_bad (_("-G is not supported for this configuration")); | |
9246 | return 0; | |
9247 | } | |
9248 | else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC) | |
9249 | { | |
9250 | as_bad (_("-G may not be used with SVR4 or embedded PIC code")); | |
9251 | return 0; | |
9252 | } | |
9253 | else | |
9254 | g_switch_value = atoi (arg); | |
9255 | g_switch_seen = 1; | |
9256 | break; | |
9257 | ||
0f074f60 | 9258 | #ifdef OBJ_ELF |
252b5132 RH |
9259 | /* The -32 and -64 options tell the assembler to output the 32 |
9260 | bit or the 64 bit MIPS ELF format. */ | |
9261 | case OPTION_32: | |
e013f690 | 9262 | mips_abi = O32_ABI; |
252b5132 RH |
9263 | break; |
9264 | ||
e013f690 TS |
9265 | case OPTION_N32: |
9266 | mips_abi = N32_ABI; | |
9267 | break; | |
252b5132 | 9268 | |
e013f690 TS |
9269 | case OPTION_64: |
9270 | mips_abi = N64_ABI; | |
9271 | if (! support_64bit_objects()) | |
9272 | as_fatal (_("No compiled in support for 64 bit object file format")); | |
252b5132 RH |
9273 | break; |
9274 | ||
c97ef257 AH |
9275 | case OPTION_GP32: |
9276 | mips_gp32 = 1; | |
e013f690 TS |
9277 | if (mips_abi != O32_ABI) |
9278 | mips_abi = NO_ABI; | |
c97ef257 AH |
9279 | break; |
9280 | ||
9281 | case OPTION_GP64: | |
9282 | mips_gp32 = 0; | |
e013f690 TS |
9283 | if (mips_abi == O32_ABI) |
9284 | mips_abi = NO_ABI; | |
c97ef257 | 9285 | break; |
252b5132 | 9286 | |
ca4e0257 RS |
9287 | case OPTION_FP32: |
9288 | mips_fp32 = 1; | |
e013f690 TS |
9289 | if (mips_abi != O32_ABI) |
9290 | mips_abi = NO_ABI; | |
ca4e0257 RS |
9291 | break; |
9292 | ||
252b5132 | 9293 | case OPTION_MABI: |
e013f690 TS |
9294 | if (strcmp (arg, "32") == 0) |
9295 | mips_abi = O32_ABI; | |
9296 | else if (strcmp (arg, "o64") == 0) | |
9297 | mips_abi = O64_ABI; | |
9298 | else if (strcmp (arg, "n32") == 0) | |
9299 | mips_abi = N32_ABI; | |
9300 | else if (strcmp (arg, "64") == 0) | |
9301 | { | |
9302 | mips_abi = N64_ABI; | |
9303 | if (! support_64bit_objects()) | |
9304 | as_fatal (_("No compiled in support for 64 bit object file " | |
9305 | "format")); | |
9306 | } | |
9307 | else if (strcmp (arg, "eabi") == 0) | |
9308 | mips_abi = EABI_ABI; | |
9309 | else | |
9310 | mips_abi = NO_ABI; | |
252b5132 | 9311 | break; |
e013f690 | 9312 | #endif /* OBJ_ELF */ |
252b5132 | 9313 | |
6b76fefe CM |
9314 | case OPTION_M7000_HILO_FIX: |
9315 | mips_7000_hilo_fix = true; | |
9316 | break; | |
9317 | ||
9318 | case OPTION_NO_M7000_HILO_FIX: | |
9319 | mips_7000_hilo_fix = false; | |
9320 | break; | |
9321 | ||
252b5132 RH |
9322 | default: |
9323 | return 0; | |
9324 | } | |
9325 | ||
9326 | return 1; | |
9327 | } | |
9328 | ||
252b5132 RH |
9329 | static void |
9330 | show (stream, string, col_p, first_p) | |
9331 | FILE *stream; | |
9332 | char *string; | |
9333 | int *col_p; | |
9334 | int *first_p; | |
9335 | { | |
9336 | if (*first_p) | |
9337 | { | |
9338 | fprintf (stream, "%24s", ""); | |
9339 | *col_p = 24; | |
9340 | } | |
9341 | else | |
9342 | { | |
9343 | fprintf (stream, ", "); | |
9344 | *col_p += 2; | |
9345 | } | |
9346 | ||
9347 | if (*col_p + strlen (string) > 72) | |
9348 | { | |
9349 | fprintf (stream, "\n%24s", ""); | |
9350 | *col_p = 24; | |
9351 | } | |
9352 | ||
9353 | fprintf (stream, "%s", string); | |
9354 | *col_p += strlen (string); | |
9355 | ||
9356 | *first_p = 0; | |
9357 | } | |
9358 | ||
252b5132 RH |
9359 | void |
9360 | md_show_usage (stream) | |
9361 | FILE *stream; | |
9362 | { | |
9363 | int column, first; | |
9364 | ||
beae10d5 | 9365 | fprintf (stream, _("\ |
252b5132 RH |
9366 | MIPS options:\n\ |
9367 | -membedded-pic generate embedded position independent code\n\ | |
9368 | -EB generate big endian output\n\ | |
9369 | -EL generate little endian output\n\ | |
9a41af64 | 9370 | -g, -g2 do not remove unneeded NOPs or swap branches\n\ |
252b5132 RH |
9371 | -G NUM allow referencing objects up to NUM bytes\n\ |
9372 | implicitly with the gp register [default 8]\n")); | |
beae10d5 | 9373 | fprintf (stream, _("\ |
252b5132 RH |
9374 | -mips1 generate MIPS ISA I instructions\n\ |
9375 | -mips2 generate MIPS ISA II instructions\n\ | |
9376 | -mips3 generate MIPS ISA III instructions\n\ | |
9377 | -mips4 generate MIPS ISA IV instructions\n\ | |
84ea6cf2 | 9378 | -mips5 generate MIPS ISA V instructions\n\ |
e7af610e | 9379 | -mips32 generate MIPS32 ISA instructions\n\ |
84ea6cf2 | 9380 | -mips64 generate MIPS64 ISA instructions\n\ |
ec68c924 | 9381 | -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n")); |
252b5132 RH |
9382 | |
9383 | first = 1; | |
9384 | ||
9385 | show (stream, "2000", &column, &first); | |
9386 | show (stream, "3000", &column, &first); | |
9387 | show (stream, "3900", &column, &first); | |
9388 | show (stream, "4000", &column, &first); | |
9389 | show (stream, "4010", &column, &first); | |
9390 | show (stream, "4100", &column, &first); | |
9391 | show (stream, "4111", &column, &first); | |
9392 | show (stream, "4300", &column, &first); | |
9393 | show (stream, "4400", &column, &first); | |
9394 | show (stream, "4600", &column, &first); | |
9395 | show (stream, "4650", &column, &first); | |
9396 | show (stream, "5000", &column, &first); | |
18ae5d72 EC |
9397 | show (stream, "5200", &column, &first); |
9398 | show (stream, "5230", &column, &first); | |
9399 | show (stream, "5231", &column, &first); | |
9400 | show (stream, "5261", &column, &first); | |
9401 | show (stream, "5721", &column, &first); | |
252b5132 RH |
9402 | show (stream, "6000", &column, &first); |
9403 | show (stream, "8000", &column, &first); | |
9404 | show (stream, "10000", &column, &first); | |
d1cf510e | 9405 | show (stream, "12000", &column, &first); |
c6c98b38 | 9406 | show (stream, "sb-1", &column, &first); |
252b5132 RH |
9407 | fputc ('\n', stream); |
9408 | ||
9409 | fprintf (stream, _("\ | |
ec68c924 | 9410 | -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\ |
252b5132 RH |
9411 | -no-mCPU don't generate code specific to CPU.\n\ |
9412 | For -mCPU and -no-mCPU, CPU must be one of:\n")); | |
9413 | ||
9414 | first = 1; | |
9415 | ||
9416 | show (stream, "3900", &column, &first); | |
9417 | show (stream, "4010", &column, &first); | |
9418 | show (stream, "4100", &column, &first); | |
9419 | show (stream, "4650", &column, &first); | |
9420 | fputc ('\n', stream); | |
9421 | ||
beae10d5 | 9422 | fprintf (stream, _("\ |
252b5132 RH |
9423 | -mips16 generate mips16 instructions\n\ |
9424 | -no-mips16 do not generate mips16 instructions\n")); | |
beae10d5 | 9425 | fprintf (stream, _("\ |
ca4e0257 RS |
9426 | -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\ |
9427 | -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\ | |
252b5132 RH |
9428 | -O0 remove unneeded NOPs, do not swap branches\n\ |
9429 | -O remove unneeded NOPs and swap branches\n\ | |
63486801 | 9430 | -n warn about NOPs generated from macros\n\ |
119d663a | 9431 | --[no-]construct-floats [dis]allow floating point values to be constructed\n\ |
252b5132 RH |
9432 | --trap, --no-break trap exception on div by 0 and mult overflow\n\ |
9433 | --break, --no-trap break exception on div by 0 and mult overflow\n")); | |
9434 | #ifdef OBJ_ELF | |
beae10d5 | 9435 | fprintf (stream, _("\ |
252b5132 RH |
9436 | -KPIC, -call_shared generate SVR4 position independent code\n\ |
9437 | -non_shared do not generate position independent code\n\ | |
9438 | -xgot assume a 32 bit GOT\n\ | |
e013f690 TS |
9439 | -32 create o32 ABI object file (default)\n\ |
9440 | -n32 create n32 ABI object file\n\ | |
9441 | -64 create 64 ABI object file\n")); | |
252b5132 RH |
9442 | #endif |
9443 | } | |
9444 | \f | |
9445 | void | |
9446 | mips_init_after_args () | |
9447 | { | |
9448 | /* initialize opcodes */ | |
9449 | bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes; | |
beae10d5 | 9450 | mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes; |
252b5132 RH |
9451 | } |
9452 | ||
9453 | long | |
9454 | md_pcrel_from (fixP) | |
9455 | fixS *fixP; | |
9456 | { | |
9457 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour | |
9458 | && fixP->fx_addsy != (symbolS *) NULL | |
9459 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
9460 | { | |
cb56d3d3 TS |
9461 | if (mips_pic == EMBEDDED_PIC) |
9462 | { | |
9463 | /* This makes a branch to an undefined symbol be a branch to the | |
9464 | current location. */ | |
9465 | return 4; | |
9466 | } | |
9467 | else | |
9468 | { | |
9469 | return 1; | |
9470 | } | |
252b5132 RH |
9471 | } |
9472 | ||
9473 | /* return the address of the delay slot */ | |
9474 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; | |
9475 | } | |
9476 | ||
252b5132 RH |
9477 | /* This is called before the symbol table is processed. In order to |
9478 | work with gcc when using mips-tfile, we must keep all local labels. | |
9479 | However, in other cases, we want to discard them. If we were | |
9480 | called with -g, but we didn't see any debugging information, it may | |
9481 | mean that gcc is smuggling debugging information through to | |
9482 | mips-tfile, in which case we must generate all local labels. */ | |
9483 | ||
9484 | void | |
9485 | mips_frob_file_before_adjust () | |
9486 | { | |
9487 | #ifndef NO_ECOFF_DEBUGGING | |
9488 | if (ECOFF_DEBUGGING | |
9489 | && mips_debug != 0 | |
9490 | && ! ecoff_debugging_seen) | |
9491 | flag_keep_locals = 1; | |
9492 | #endif | |
9493 | } | |
9494 | ||
9495 | /* Sort any unmatched HI16_S relocs so that they immediately precede | |
9496 | the corresponding LO reloc. This is called before md_apply_fix and | |
9497 | tc_gen_reloc. Unmatched HI16_S relocs can only be generated by | |
9498 | explicit use of the %hi modifier. */ | |
9499 | ||
9500 | void | |
9501 | mips_frob_file () | |
9502 | { | |
9503 | struct mips_hi_fixup *l; | |
9504 | ||
9505 | for (l = mips_hi_fixup_list; l != NULL; l = l->next) | |
9506 | { | |
9507 | segment_info_type *seginfo; | |
9508 | int pass; | |
9509 | ||
9510 | assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S); | |
9511 | ||
9512 | /* Check quickly whether the next fixup happens to be a matching | |
9513 | %lo. */ | |
9514 | if (l->fixp->fx_next != NULL | |
9515 | && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16 | |
9516 | && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy | |
9517 | && l->fixp->fx_offset == l->fixp->fx_next->fx_offset) | |
9518 | continue; | |
9519 | ||
9520 | /* Look through the fixups for this segment for a matching %lo. | |
9521 | When we find one, move the %hi just in front of it. We do | |
9522 | this in two passes. In the first pass, we try to find a | |
9523 | unique %lo. In the second pass, we permit multiple %hi | |
9524 | relocs for a single %lo (this is a GNU extension). */ | |
9525 | seginfo = seg_info (l->seg); | |
9526 | for (pass = 0; pass < 2; pass++) | |
9527 | { | |
9528 | fixS *f, *prev; | |
9529 | ||
9530 | prev = NULL; | |
9531 | for (f = seginfo->fix_root; f != NULL; f = f->fx_next) | |
9532 | { | |
9533 | /* Check whether this is a %lo fixup which matches l->fixp. */ | |
9534 | if (f->fx_r_type == BFD_RELOC_LO16 | |
9535 | && f->fx_addsy == l->fixp->fx_addsy | |
9536 | && f->fx_offset == l->fixp->fx_offset | |
9537 | && (pass == 1 | |
9538 | || prev == NULL | |
9539 | || prev->fx_r_type != BFD_RELOC_HI16_S | |
9540 | || prev->fx_addsy != f->fx_addsy | |
9541 | || prev->fx_offset != f->fx_offset)) | |
9542 | { | |
9543 | fixS **pf; | |
9544 | ||
9545 | /* Move l->fixp before f. */ | |
9546 | for (pf = &seginfo->fix_root; | |
9547 | *pf != l->fixp; | |
9548 | pf = &(*pf)->fx_next) | |
9549 | assert (*pf != NULL); | |
9550 | ||
9551 | *pf = l->fixp->fx_next; | |
9552 | ||
9553 | l->fixp->fx_next = f; | |
9554 | if (prev == NULL) | |
9555 | seginfo->fix_root = l->fixp; | |
9556 | else | |
9557 | prev->fx_next = l->fixp; | |
9558 | ||
9559 | break; | |
9560 | } | |
9561 | ||
9562 | prev = f; | |
9563 | } | |
9564 | ||
9565 | if (f != NULL) | |
9566 | break; | |
9567 | ||
9568 | #if 0 /* GCC code motion plus incomplete dead code elimination | |
9569 | can leave a %hi without a %lo. */ | |
9570 | if (pass == 1) | |
9571 | as_warn_where (l->fixp->fx_file, l->fixp->fx_line, | |
9572 | _("Unmatched %%hi reloc")); | |
9573 | #endif | |
9574 | } | |
9575 | } | |
9576 | } | |
9577 | ||
9578 | /* When generating embedded PIC code we need to use a special | |
9579 | relocation to represent the difference of two symbols in the .text | |
9580 | section (switch tables use a difference of this sort). See | |
9581 | include/coff/mips.h for details. This macro checks whether this | |
9582 | fixup requires the special reloc. */ | |
9583 | #define SWITCH_TABLE(fixp) \ | |
9584 | ((fixp)->fx_r_type == BFD_RELOC_32 \ | |
bb2d6cd7 | 9585 | && OUTPUT_FLAVOR != bfd_target_elf_flavour \ |
252b5132 RH |
9586 | && (fixp)->fx_addsy != NULL \ |
9587 | && (fixp)->fx_subsy != NULL \ | |
9588 | && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \ | |
9589 | && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section) | |
9590 | ||
9591 | /* When generating embedded PIC code we must keep all PC relative | |
9592 | relocations, in case the linker has to relax a call. We also need | |
9593 | to keep relocations for switch table entries. */ | |
9594 | ||
252b5132 RH |
9595 | int |
9596 | mips_force_relocation (fixp) | |
9597 | fixS *fixp; | |
9598 | { | |
9599 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
9600 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
9601 | return 1; | |
9602 | ||
9603 | return (mips_pic == EMBEDDED_PIC | |
9604 | && (fixp->fx_pcrel | |
9605 | || SWITCH_TABLE (fixp) | |
9606 | || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S | |
9607 | || fixp->fx_r_type == BFD_RELOC_PCREL_LO16)); | |
9608 | } | |
9609 | ||
9610 | /* Apply a fixup to the object file. */ | |
9611 | ||
9612 | int | |
9613 | md_apply_fix (fixP, valueP) | |
9614 | fixS *fixP; | |
9615 | valueT *valueP; | |
9616 | { | |
9617 | unsigned char *buf; | |
98aa84af AM |
9618 | long insn; |
9619 | valueT value; | |
252b5132 RH |
9620 | |
9621 | assert (fixP->fx_size == 4 | |
9622 | || fixP->fx_r_type == BFD_RELOC_16 | |
9623 | || fixP->fx_r_type == BFD_RELOC_64 | |
9624 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
9625 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY); | |
9626 | ||
9627 | value = *valueP; | |
9628 | ||
9629 | /* If we aren't adjusting this fixup to be against the section | |
9630 | symbol, we need to adjust the value. */ | |
9631 | #ifdef OBJ_ELF | |
9632 | if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
bb2d6cd7 | 9633 | { |
98aa84af | 9634 | if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16 |
ea4ff978 L |
9635 | || ((S_IS_WEAK (fixP->fx_addsy) |
9636 | || S_IS_EXTERN (fixP->fx_addsy)) | |
9637 | && !S_IS_COMMON (fixP->fx_addsy)) | |
98aa84af AM |
9638 | || (symbol_used_in_reloc_p (fixP->fx_addsy) |
9639 | && (((bfd_get_section_flags (stdoutput, | |
9640 | S_GET_SEGMENT (fixP->fx_addsy)) | |
9641 | & SEC_LINK_ONCE) != 0) | |
9642 | || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)), | |
9643 | ".gnu.linkonce", | |
9644 | sizeof (".gnu.linkonce") - 1)))) | |
252b5132 | 9645 | |
98aa84af AM |
9646 | { |
9647 | valueT symval = S_GET_VALUE (fixP->fx_addsy); | |
9648 | value -= symval; | |
236bd878 RS |
9649 | if (value != 0 |
9650 | && ! fixP->fx_pcrel | |
9651 | && fixP->fx_r_type != BFD_RELOC_MIPS_GPREL) | |
98aa84af AM |
9652 | { |
9653 | /* In this case, the bfd_install_relocation routine will | |
9654 | incorrectly add the symbol value back in. We just want | |
7461da6e | 9655 | the addend to appear in the object file. */ |
98aa84af | 9656 | value -= symval; |
7461da6e RS |
9657 | |
9658 | /* Make sure the addend is still non-zero. If it became zero | |
9659 | after the last operation, set it to a spurious value and | |
9660 | subtract the same value from the object file's contents. */ | |
9661 | if (value == 0) | |
9662 | { | |
9663 | value = 8; | |
9664 | ||
9665 | /* The in-place addends for LO16 relocations are signed; | |
9666 | leave the matching HI16 in-place addends as zero. */ | |
9667 | if (fixP->fx_r_type != BFD_RELOC_HI16_S) | |
9668 | { | |
9669 | reloc_howto_type *howto; | |
9670 | bfd_vma contents, mask, field; | |
9671 | ||
9672 | howto = bfd_reloc_type_lookup (stdoutput, | |
9673 | fixP->fx_r_type); | |
9674 | ||
9675 | contents = bfd_get_bits (fixP->fx_frag->fr_literal | |
9676 | + fixP->fx_where, | |
9677 | fixP->fx_size * 8, | |
9678 | target_big_endian); | |
9679 | ||
9680 | /* MASK has bits set where the relocation should go. | |
9681 | FIELD is -value, shifted into the appropriate place | |
9682 | for this relocation. */ | |
9683 | mask = 1 << (howto->bitsize - 1); | |
9684 | mask = (((mask - 1) << 1) | 1) << howto->bitpos; | |
9685 | field = (-value >> howto->rightshift) << howto->bitpos; | |
9686 | ||
9687 | bfd_put_bits ((field & mask) | (contents & ~mask), | |
9688 | fixP->fx_frag->fr_literal + fixP->fx_where, | |
9689 | fixP->fx_size * 8, | |
9690 | target_big_endian); | |
9691 | } | |
9692 | } | |
98aa84af AM |
9693 | } |
9694 | } | |
252b5132 | 9695 | |
bb2d6cd7 GK |
9696 | /* This code was generated using trial and error and so is |
9697 | fragile and not trustworthy. If you change it, you should | |
9698 | rerun the elf-rel, elf-rel2, and empic testcases and ensure | |
9699 | they still pass. */ | |
9700 | if (fixP->fx_pcrel || fixP->fx_subsy != NULL) | |
9701 | { | |
9702 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
9703 | ||
9704 | /* BFD's REL handling, for MIPS, is _very_ weird. | |
9705 | This gives the right results, but it can't possibly | |
9706 | be the way things are supposed to work. */ | |
cb56d3d3 TS |
9707 | if ((fixP->fx_r_type != BFD_RELOC_16_PCREL |
9708 | && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2) | |
bb2d6cd7 GK |
9709 | || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section) |
9710 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
9711 | } | |
9712 | } | |
9713 | #endif | |
252b5132 RH |
9714 | |
9715 | fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */ | |
9716 | ||
9717 | if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel) | |
9718 | fixP->fx_done = 1; | |
9719 | ||
9720 | switch (fixP->fx_r_type) | |
9721 | { | |
9722 | case BFD_RELOC_MIPS_JMP: | |
9723 | case BFD_RELOC_HI16: | |
9724 | case BFD_RELOC_HI16_S: | |
9725 | case BFD_RELOC_MIPS_GPREL: | |
9726 | case BFD_RELOC_MIPS_LITERAL: | |
9727 | case BFD_RELOC_MIPS_CALL16: | |
9728 | case BFD_RELOC_MIPS_GOT16: | |
9729 | case BFD_RELOC_MIPS_GPREL32: | |
9730 | case BFD_RELOC_MIPS_GOT_HI16: | |
9731 | case BFD_RELOC_MIPS_GOT_LO16: | |
9732 | case BFD_RELOC_MIPS_CALL_HI16: | |
9733 | case BFD_RELOC_MIPS_CALL_LO16: | |
9734 | case BFD_RELOC_MIPS16_GPREL: | |
9735 | if (fixP->fx_pcrel) | |
9736 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9737 | _("Invalid PC relative reloc")); | |
9738 | /* Nothing needed to do. The value comes from the reloc entry */ | |
9739 | break; | |
9740 | ||
9741 | case BFD_RELOC_MIPS16_JMP: | |
9742 | /* We currently always generate a reloc against a symbol, which | |
9743 | means that we don't want an addend even if the symbol is | |
9744 | defined. */ | |
9745 | fixP->fx_addnumber = 0; | |
9746 | break; | |
9747 | ||
9748 | case BFD_RELOC_PCREL_HI16_S: | |
9749 | /* The addend for this is tricky if it is internal, so we just | |
9750 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 9751 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
9752 | && !fixP->fx_done |
9753 | && value != 0) | |
9754 | break; | |
9755 | if (fixP->fx_addsy | |
9756 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
9757 | { |
9758 | /* For an external symbol adjust by the address to make it | |
9759 | pcrel_offset. We use the address of the RELLO reloc | |
9760 | which follows this one. */ | |
9761 | value += (fixP->fx_next->fx_frag->fr_address | |
9762 | + fixP->fx_next->fx_where); | |
9763 | } | |
e7d556df | 9764 | value = ((value + 0x8000) >> 16) & 0xffff; |
252b5132 RH |
9765 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; |
9766 | if (target_big_endian) | |
9767 | buf += 2; | |
9768 | md_number_to_chars (buf, value, 2); | |
9769 | break; | |
9770 | ||
9771 | case BFD_RELOC_PCREL_LO16: | |
9772 | /* The addend for this is tricky if it is internal, so we just | |
9773 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 9774 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
9775 | && !fixP->fx_done |
9776 | && value != 0) | |
9777 | break; | |
9778 | if (fixP->fx_addsy | |
9779 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
9780 | value += fixP->fx_frag->fr_address + fixP->fx_where; |
9781 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
9782 | if (target_big_endian) | |
9783 | buf += 2; | |
9784 | md_number_to_chars (buf, value, 2); | |
9785 | break; | |
9786 | ||
9787 | case BFD_RELOC_64: | |
9788 | /* This is handled like BFD_RELOC_32, but we output a sign | |
9789 | extended value if we are only 32 bits. */ | |
9790 | if (fixP->fx_done | |
9791 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
9792 | { | |
9793 | if (8 <= sizeof (valueT)) | |
9794 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9795 | value, 8); | |
9796 | else | |
9797 | { | |
9798 | long w1, w2; | |
9799 | long hiv; | |
9800 | ||
9801 | w1 = w2 = fixP->fx_where; | |
9802 | if (target_big_endian) | |
9803 | w1 += 4; | |
9804 | else | |
9805 | w2 += 4; | |
9806 | md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4); | |
9807 | if ((value & 0x80000000) != 0) | |
9808 | hiv = 0xffffffff; | |
9809 | else | |
9810 | hiv = 0; | |
9811 | md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4); | |
9812 | } | |
9813 | } | |
9814 | break; | |
9815 | ||
056350c6 | 9816 | case BFD_RELOC_RVA: |
252b5132 RH |
9817 | case BFD_RELOC_32: |
9818 | /* If we are deleting this reloc entry, we must fill in the | |
9819 | value now. This can happen if we have a .word which is not | |
9820 | resolved when it appears but is later defined. We also need | |
9821 | to fill in the value if this is an embedded PIC switch table | |
9822 | entry. */ | |
9823 | if (fixP->fx_done | |
9824 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
9825 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9826 | value, 4); | |
9827 | break; | |
9828 | ||
9829 | case BFD_RELOC_16: | |
9830 | /* If we are deleting this reloc entry, we must fill in the | |
9831 | value now. */ | |
9832 | assert (fixP->fx_size == 2); | |
9833 | if (fixP->fx_done) | |
9834 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9835 | value, 2); | |
9836 | break; | |
9837 | ||
9838 | case BFD_RELOC_LO16: | |
9839 | /* When handling an embedded PIC switch statement, we can wind | |
9840 | up deleting a LO16 reloc. See the 'o' case in mips_ip. */ | |
9841 | if (fixP->fx_done) | |
9842 | { | |
98aa84af | 9843 | if (value + 0x8000 > 0xffff) |
252b5132 RH |
9844 | as_bad_where (fixP->fx_file, fixP->fx_line, |
9845 | _("relocation overflow")); | |
9846 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
9847 | if (target_big_endian) | |
9848 | buf += 2; | |
9849 | md_number_to_chars (buf, value, 2); | |
9850 | } | |
9851 | break; | |
9852 | ||
9853 | case BFD_RELOC_16_PCREL_S2: | |
cb56d3d3 TS |
9854 | if ((value & 0x3) != 0) |
9855 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9856 | _("Branch to odd address (%lx)"), (long) value); | |
9857 | ||
9858 | /* Fall through. */ | |
9859 | ||
9860 | case BFD_RELOC_16_PCREL: | |
252b5132 RH |
9861 | /* |
9862 | * We need to save the bits in the instruction since fixup_segment() | |
9863 | * might be deleting the relocation entry (i.e., a branch within | |
9864 | * the current segment). | |
9865 | */ | |
bb2d6cd7 GK |
9866 | if (!fixP->fx_done && value != 0) |
9867 | break; | |
9868 | /* If 'value' is zero, the remaining reloc code won't actually | |
9869 | do the store, so it must be done here. This is probably | |
9870 | a bug somewhere. */ | |
9871 | if (!fixP->fx_done) | |
9872 | value -= fixP->fx_frag->fr_address + fixP->fx_where; | |
bdaaa2e1 | 9873 | |
98aa84af | 9874 | value = (offsetT) value >> 2; |
252b5132 RH |
9875 | |
9876 | /* update old instruction data */ | |
9877 | buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal); | |
9878 | if (target_big_endian) | |
9879 | insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
9880 | else | |
9881 | insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | |
9882 | ||
98aa84af | 9883 | if (value + 0x8000 <= 0xffff) |
252b5132 RH |
9884 | insn |= value & 0xffff; |
9885 | else | |
9886 | { | |
9887 | /* The branch offset is too large. If this is an | |
9888 | unconditional branch, and we are not generating PIC code, | |
9889 | we can convert it to an absolute jump instruction. */ | |
9890 | if (mips_pic == NO_PIC | |
9891 | && fixP->fx_done | |
9892 | && fixP->fx_frag->fr_address >= text_section->vma | |
9893 | && (fixP->fx_frag->fr_address | |
9894 | < text_section->vma + text_section->_raw_size) | |
9895 | && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */ | |
9896 | || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */ | |
9897 | || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */ | |
9898 | { | |
9899 | if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */ | |
9900 | insn = 0x0c000000; /* jal */ | |
9901 | else | |
9902 | insn = 0x08000000; /* j */ | |
9903 | fixP->fx_r_type = BFD_RELOC_MIPS_JMP; | |
9904 | fixP->fx_done = 0; | |
9905 | fixP->fx_addsy = section_symbol (text_section); | |
9906 | fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP); | |
9907 | } | |
9908 | else | |
9909 | { | |
9910 | /* FIXME. It would be possible in principle to handle | |
9911 | conditional branches which overflow. They could be | |
9912 | transformed into a branch around a jump. This would | |
9913 | require setting up variant frags for each different | |
9914 | branch type. The native MIPS assembler attempts to | |
9915 | handle these cases, but it appears to do it | |
9916 | incorrectly. */ | |
9917 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9918 | _("Branch out of range")); | |
9919 | } | |
9920 | } | |
9921 | ||
9922 | md_number_to_chars ((char *) buf, (valueT) insn, 4); | |
9923 | break; | |
9924 | ||
9925 | case BFD_RELOC_VTABLE_INHERIT: | |
9926 | fixP->fx_done = 0; | |
9927 | if (fixP->fx_addsy | |
9928 | && !S_IS_DEFINED (fixP->fx_addsy) | |
9929 | && !S_IS_WEAK (fixP->fx_addsy)) | |
9930 | S_SET_WEAK (fixP->fx_addsy); | |
9931 | break; | |
9932 | ||
9933 | case BFD_RELOC_VTABLE_ENTRY: | |
9934 | fixP->fx_done = 0; | |
9935 | break; | |
9936 | ||
9937 | default: | |
9938 | internalError (); | |
9939 | } | |
9940 | ||
9941 | return 1; | |
9942 | } | |
9943 | ||
9944 | #if 0 | |
9945 | void | |
9946 | printInsn (oc) | |
9947 | unsigned long oc; | |
9948 | { | |
9949 | const struct mips_opcode *p; | |
9950 | int treg, sreg, dreg, shamt; | |
9951 | short imm; | |
9952 | const char *args; | |
9953 | int i; | |
9954 | ||
9955 | for (i = 0; i < NUMOPCODES; ++i) | |
9956 | { | |
9957 | p = &mips_opcodes[i]; | |
9958 | if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO)) | |
9959 | { | |
9960 | printf ("%08lx %s\t", oc, p->name); | |
9961 | treg = (oc >> 16) & 0x1f; | |
9962 | sreg = (oc >> 21) & 0x1f; | |
9963 | dreg = (oc >> 11) & 0x1f; | |
9964 | shamt = (oc >> 6) & 0x1f; | |
9965 | imm = oc; | |
9966 | for (args = p->args;; ++args) | |
9967 | { | |
9968 | switch (*args) | |
9969 | { | |
9970 | case '\0': | |
9971 | printf ("\n"); | |
9972 | break; | |
9973 | ||
9974 | case ',': | |
9975 | case '(': | |
9976 | case ')': | |
9977 | printf ("%c", *args); | |
9978 | continue; | |
9979 | ||
9980 | case 'r': | |
9981 | assert (treg == sreg); | |
9982 | printf ("$%d,$%d", treg, sreg); | |
9983 | continue; | |
9984 | ||
9985 | case 'd': | |
9986 | case 'G': | |
9987 | printf ("$%d", dreg); | |
9988 | continue; | |
9989 | ||
9990 | case 't': | |
9991 | case 'E': | |
9992 | printf ("$%d", treg); | |
9993 | continue; | |
9994 | ||
9995 | case 'k': | |
9996 | printf ("0x%x", treg); | |
9997 | continue; | |
9998 | ||
9999 | case 'b': | |
10000 | case 's': | |
10001 | printf ("$%d", sreg); | |
10002 | continue; | |
10003 | ||
10004 | case 'a': | |
10005 | printf ("0x%08lx", oc & 0x1ffffff); | |
10006 | continue; | |
10007 | ||
10008 | case 'i': | |
10009 | case 'j': | |
10010 | case 'o': | |
10011 | case 'u': | |
10012 | printf ("%d", imm); | |
10013 | continue; | |
10014 | ||
10015 | case '<': | |
10016 | case '>': | |
10017 | printf ("$%d", shamt); | |
10018 | continue; | |
10019 | ||
10020 | default: | |
10021 | internalError (); | |
10022 | } | |
10023 | break; | |
10024 | } | |
10025 | return; | |
10026 | } | |
10027 | } | |
10028 | printf (_("%08lx UNDEFINED\n"), oc); | |
10029 | } | |
10030 | #endif | |
10031 | ||
10032 | static symbolS * | |
10033 | get_symbol () | |
10034 | { | |
10035 | int c; | |
10036 | char *name; | |
10037 | symbolS *p; | |
10038 | ||
10039 | name = input_line_pointer; | |
10040 | c = get_symbol_end (); | |
10041 | p = (symbolS *) symbol_find_or_make (name); | |
10042 | *input_line_pointer = c; | |
10043 | return p; | |
10044 | } | |
10045 | ||
10046 | /* Align the current frag to a given power of two. The MIPS assembler | |
10047 | also automatically adjusts any preceding label. */ | |
10048 | ||
10049 | static void | |
10050 | mips_align (to, fill, label) | |
10051 | int to; | |
10052 | int fill; | |
10053 | symbolS *label; | |
10054 | { | |
10055 | mips_emit_delays (false); | |
10056 | frag_align (to, fill, 0); | |
10057 | record_alignment (now_seg, to); | |
10058 | if (label != NULL) | |
10059 | { | |
10060 | assert (S_GET_SEGMENT (label) == now_seg); | |
49309057 | 10061 | symbol_set_frag (label, frag_now); |
252b5132 RH |
10062 | S_SET_VALUE (label, (valueT) frag_now_fix ()); |
10063 | } | |
10064 | } | |
10065 | ||
10066 | /* Align to a given power of two. .align 0 turns off the automatic | |
10067 | alignment used by the data creating pseudo-ops. */ | |
10068 | ||
10069 | static void | |
10070 | s_align (x) | |
43841e91 | 10071 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10072 | { |
10073 | register int temp; | |
10074 | register long temp_fill; | |
10075 | long max_alignment = 15; | |
10076 | ||
10077 | /* | |
10078 | ||
10079 | o Note that the assembler pulls down any immediately preceeding label | |
10080 | to the aligned address. | |
10081 | o It's not documented but auto alignment is reinstated by | |
10082 | a .align pseudo instruction. | |
10083 | o Note also that after auto alignment is turned off the mips assembler | |
10084 | issues an error on attempt to assemble an improperly aligned data item. | |
10085 | We don't. | |
10086 | ||
10087 | */ | |
10088 | ||
10089 | temp = get_absolute_expression (); | |
10090 | if (temp > max_alignment) | |
10091 | as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment); | |
10092 | else if (temp < 0) | |
10093 | { | |
10094 | as_warn (_("Alignment negative: 0 assumed.")); | |
10095 | temp = 0; | |
10096 | } | |
10097 | if (*input_line_pointer == ',') | |
10098 | { | |
10099 | input_line_pointer++; | |
10100 | temp_fill = get_absolute_expression (); | |
10101 | } | |
10102 | else | |
10103 | temp_fill = 0; | |
10104 | if (temp) | |
10105 | { | |
10106 | auto_align = 1; | |
10107 | mips_align (temp, (int) temp_fill, | |
10108 | insn_labels != NULL ? insn_labels->label : NULL); | |
10109 | } | |
10110 | else | |
10111 | { | |
10112 | auto_align = 0; | |
10113 | } | |
10114 | ||
10115 | demand_empty_rest_of_line (); | |
10116 | } | |
10117 | ||
10118 | void | |
10119 | mips_flush_pending_output () | |
10120 | { | |
10121 | mips_emit_delays (false); | |
10122 | mips_clear_insn_labels (); | |
10123 | } | |
10124 | ||
10125 | static void | |
10126 | s_change_sec (sec) | |
10127 | int sec; | |
10128 | { | |
10129 | segT seg; | |
10130 | ||
10131 | /* When generating embedded PIC code, we only use the .text, .lit8, | |
10132 | .sdata and .sbss sections. We change the .data and .rdata | |
10133 | pseudo-ops to use .sdata. */ | |
10134 | if (mips_pic == EMBEDDED_PIC | |
10135 | && (sec == 'd' || sec == 'r')) | |
10136 | sec = 's'; | |
10137 | ||
10138 | #ifdef OBJ_ELF | |
10139 | /* The ELF backend needs to know that we are changing sections, so | |
10140 | that .previous works correctly. We could do something like check | |
10141 | for a obj_section_change_hook macro, but that might be confusing | |
10142 | as it would not be appropriate to use it in the section changing | |
10143 | functions in read.c, since obj-elf.c intercepts those. FIXME: | |
10144 | This should be cleaner, somehow. */ | |
10145 | obj_elf_section_change_hook (); | |
10146 | #endif | |
10147 | ||
10148 | mips_emit_delays (false); | |
10149 | switch (sec) | |
10150 | { | |
10151 | case 't': | |
10152 | s_text (0); | |
10153 | break; | |
10154 | case 'd': | |
10155 | s_data (0); | |
10156 | break; | |
10157 | case 'b': | |
10158 | subseg_set (bss_section, (subsegT) get_absolute_expression ()); | |
10159 | demand_empty_rest_of_line (); | |
10160 | break; | |
10161 | ||
10162 | case 'r': | |
10163 | if (USE_GLOBAL_POINTER_OPT) | |
10164 | { | |
10165 | seg = subseg_new (RDATA_SECTION_NAME, | |
10166 | (subsegT) get_absolute_expression ()); | |
10167 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
10168 | { | |
10169 | bfd_set_section_flags (stdoutput, seg, | |
10170 | (SEC_ALLOC | |
10171 | | SEC_LOAD | |
10172 | | SEC_READONLY | |
10173 | | SEC_RELOC | |
10174 | | SEC_DATA)); | |
10175 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 10176 | record_alignment (seg, 4); |
252b5132 RH |
10177 | } |
10178 | demand_empty_rest_of_line (); | |
10179 | } | |
10180 | else | |
10181 | { | |
10182 | as_bad (_("No read only data section in this object file format")); | |
10183 | demand_empty_rest_of_line (); | |
10184 | return; | |
10185 | } | |
10186 | break; | |
10187 | ||
10188 | case 's': | |
10189 | if (USE_GLOBAL_POINTER_OPT) | |
10190 | { | |
10191 | seg = subseg_new (".sdata", (subsegT) get_absolute_expression ()); | |
10192 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
10193 | { | |
10194 | bfd_set_section_flags (stdoutput, seg, | |
10195 | SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
10196 | | SEC_DATA); | |
10197 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 10198 | record_alignment (seg, 4); |
252b5132 RH |
10199 | } |
10200 | demand_empty_rest_of_line (); | |
10201 | break; | |
10202 | } | |
10203 | else | |
10204 | { | |
10205 | as_bad (_("Global pointers not supported; recompile -G 0")); | |
10206 | demand_empty_rest_of_line (); | |
10207 | return; | |
10208 | } | |
10209 | } | |
10210 | ||
10211 | auto_align = 1; | |
10212 | } | |
10213 | ||
10214 | void | |
10215 | mips_enable_auto_align () | |
10216 | { | |
10217 | auto_align = 1; | |
10218 | } | |
10219 | ||
10220 | static void | |
10221 | s_cons (log_size) | |
10222 | int log_size; | |
10223 | { | |
10224 | symbolS *label; | |
10225 | ||
10226 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10227 | mips_emit_delays (false); | |
10228 | if (log_size > 0 && auto_align) | |
10229 | mips_align (log_size, 0, label); | |
10230 | mips_clear_insn_labels (); | |
10231 | cons (1 << log_size); | |
10232 | } | |
10233 | ||
10234 | static void | |
10235 | s_float_cons (type) | |
10236 | int type; | |
10237 | { | |
10238 | symbolS *label; | |
10239 | ||
10240 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10241 | ||
10242 | mips_emit_delays (false); | |
10243 | ||
10244 | if (auto_align) | |
49309057 ILT |
10245 | { |
10246 | if (type == 'd') | |
10247 | mips_align (3, 0, label); | |
10248 | else | |
10249 | mips_align (2, 0, label); | |
10250 | } | |
252b5132 RH |
10251 | |
10252 | mips_clear_insn_labels (); | |
10253 | ||
10254 | float_cons (type); | |
10255 | } | |
10256 | ||
10257 | /* Handle .globl. We need to override it because on Irix 5 you are | |
10258 | permitted to say | |
10259 | .globl foo .text | |
10260 | where foo is an undefined symbol, to mean that foo should be | |
10261 | considered to be the address of a function. */ | |
10262 | ||
10263 | static void | |
10264 | s_mips_globl (x) | |
43841e91 | 10265 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10266 | { |
10267 | char *name; | |
10268 | int c; | |
10269 | symbolS *symbolP; | |
10270 | flagword flag; | |
10271 | ||
10272 | name = input_line_pointer; | |
10273 | c = get_symbol_end (); | |
10274 | symbolP = symbol_find_or_make (name); | |
10275 | *input_line_pointer = c; | |
10276 | SKIP_WHITESPACE (); | |
10277 | ||
10278 | /* On Irix 5, every global symbol that is not explicitly labelled as | |
10279 | being a function is apparently labelled as being an object. */ | |
10280 | flag = BSF_OBJECT; | |
10281 | ||
10282 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
10283 | { | |
10284 | char *secname; | |
10285 | asection *sec; | |
10286 | ||
10287 | secname = input_line_pointer; | |
10288 | c = get_symbol_end (); | |
10289 | sec = bfd_get_section_by_name (stdoutput, secname); | |
10290 | if (sec == NULL) | |
10291 | as_bad (_("%s: no such section"), secname); | |
10292 | *input_line_pointer = c; | |
10293 | ||
10294 | if (sec != NULL && (sec->flags & SEC_CODE) != 0) | |
10295 | flag = BSF_FUNCTION; | |
10296 | } | |
10297 | ||
49309057 | 10298 | symbol_get_bfdsym (symbolP)->flags |= flag; |
252b5132 RH |
10299 | |
10300 | S_SET_EXTERNAL (symbolP); | |
10301 | demand_empty_rest_of_line (); | |
10302 | } | |
10303 | ||
10304 | static void | |
10305 | s_option (x) | |
43841e91 | 10306 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10307 | { |
10308 | char *opt; | |
10309 | char c; | |
10310 | ||
10311 | opt = input_line_pointer; | |
10312 | c = get_symbol_end (); | |
10313 | ||
10314 | if (*opt == 'O') | |
10315 | { | |
10316 | /* FIXME: What does this mean? */ | |
10317 | } | |
10318 | else if (strncmp (opt, "pic", 3) == 0) | |
10319 | { | |
10320 | int i; | |
10321 | ||
10322 | i = atoi (opt + 3); | |
10323 | if (i == 0) | |
10324 | mips_pic = NO_PIC; | |
10325 | else if (i == 2) | |
10326 | mips_pic = SVR4_PIC; | |
10327 | else | |
10328 | as_bad (_(".option pic%d not supported"), i); | |
10329 | ||
10330 | if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC) | |
10331 | { | |
10332 | if (g_switch_seen && g_switch_value != 0) | |
10333 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
10334 | g_switch_value = 0; | |
10335 | bfd_set_gp_size (stdoutput, 0); | |
10336 | } | |
10337 | } | |
10338 | else | |
10339 | as_warn (_("Unrecognized option \"%s\""), opt); | |
10340 | ||
10341 | *input_line_pointer = c; | |
10342 | demand_empty_rest_of_line (); | |
10343 | } | |
10344 | ||
10345 | /* This structure is used to hold a stack of .set values. */ | |
10346 | ||
e972090a NC |
10347 | struct mips_option_stack |
10348 | { | |
252b5132 RH |
10349 | struct mips_option_stack *next; |
10350 | struct mips_set_options options; | |
10351 | }; | |
10352 | ||
10353 | static struct mips_option_stack *mips_opts_stack; | |
10354 | ||
10355 | /* Handle the .set pseudo-op. */ | |
10356 | ||
10357 | static void | |
10358 | s_mipsset (x) | |
43841e91 | 10359 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10360 | { |
10361 | char *name = input_line_pointer, ch; | |
10362 | ||
10363 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
10364 | input_line_pointer++; | |
10365 | ch = *input_line_pointer; | |
10366 | *input_line_pointer = '\0'; | |
10367 | ||
10368 | if (strcmp (name, "reorder") == 0) | |
10369 | { | |
10370 | if (mips_opts.noreorder && prev_nop_frag != NULL) | |
10371 | { | |
10372 | /* If we still have pending nops, we can discard them. The | |
10373 | usual nop handling will insert any that are still | |
bdaaa2e1 | 10374 | needed. */ |
252b5132 RH |
10375 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds |
10376 | * (mips_opts.mips16 ? 2 : 4)); | |
10377 | prev_nop_frag = NULL; | |
10378 | } | |
10379 | mips_opts.noreorder = 0; | |
10380 | } | |
10381 | else if (strcmp (name, "noreorder") == 0) | |
10382 | { | |
10383 | mips_emit_delays (true); | |
10384 | mips_opts.noreorder = 1; | |
10385 | mips_any_noreorder = 1; | |
10386 | } | |
10387 | else if (strcmp (name, "at") == 0) | |
10388 | { | |
10389 | mips_opts.noat = 0; | |
10390 | } | |
10391 | else if (strcmp (name, "noat") == 0) | |
10392 | { | |
10393 | mips_opts.noat = 1; | |
10394 | } | |
10395 | else if (strcmp (name, "macro") == 0) | |
10396 | { | |
10397 | mips_opts.warn_about_macros = 0; | |
10398 | } | |
10399 | else if (strcmp (name, "nomacro") == 0) | |
10400 | { | |
10401 | if (mips_opts.noreorder == 0) | |
10402 | as_bad (_("`noreorder' must be set before `nomacro'")); | |
10403 | mips_opts.warn_about_macros = 1; | |
10404 | } | |
10405 | else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0) | |
10406 | { | |
10407 | mips_opts.nomove = 0; | |
10408 | } | |
10409 | else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0) | |
10410 | { | |
10411 | mips_opts.nomove = 1; | |
10412 | } | |
10413 | else if (strcmp (name, "bopt") == 0) | |
10414 | { | |
10415 | mips_opts.nobopt = 0; | |
10416 | } | |
10417 | else if (strcmp (name, "nobopt") == 0) | |
10418 | { | |
10419 | mips_opts.nobopt = 1; | |
10420 | } | |
10421 | else if (strcmp (name, "mips16") == 0 | |
10422 | || strcmp (name, "MIPS-16") == 0) | |
10423 | mips_opts.mips16 = 1; | |
10424 | else if (strcmp (name, "nomips16") == 0 | |
10425 | || strcmp (name, "noMIPS-16") == 0) | |
10426 | mips_opts.mips16 = 0; | |
10427 | else if (strncmp (name, "mips", 4) == 0) | |
10428 | { | |
10429 | int isa; | |
553178e4 TS |
10430 | static int saved_mips_gp32; |
10431 | static int saved_mips_fp32; | |
e013f690 | 10432 | static enum mips_abi_level saved_mips_abi; |
553178e4 | 10433 | static int is_saved; |
252b5132 RH |
10434 | |
10435 | /* Permit the user to change the ISA on the fly. Needless to | |
10436 | say, misuse can cause serious problems. */ | |
10437 | isa = atoi (name + 4); | |
553178e4 TS |
10438 | switch (isa) |
10439 | { | |
10440 | case 0: | |
10441 | mips_gp32 = saved_mips_gp32; | |
10442 | mips_fp32 = saved_mips_fp32; | |
e013f690 | 10443 | mips_abi = saved_mips_abi; |
553178e4 TS |
10444 | is_saved = 0; |
10445 | break; | |
10446 | case 1: | |
10447 | case 2: | |
10448 | case 32: | |
10449 | if (! is_saved) | |
10450 | { | |
10451 | saved_mips_gp32 = mips_gp32; | |
10452 | saved_mips_fp32 = mips_fp32; | |
e013f690 | 10453 | saved_mips_abi = mips_abi; |
553178e4 TS |
10454 | } |
10455 | mips_gp32 = 1; | |
10456 | mips_fp32 = 1; | |
10457 | is_saved = 1; | |
10458 | break; | |
10459 | case 3: | |
10460 | case 4: | |
10461 | case 5: | |
10462 | case 64: | |
10463 | if (! is_saved) | |
10464 | { | |
10465 | saved_mips_gp32 = mips_gp32; | |
10466 | saved_mips_fp32 = mips_fp32; | |
e013f690 | 10467 | saved_mips_abi = mips_abi; |
553178e4 TS |
10468 | } |
10469 | mips_gp32 = 0; | |
10470 | mips_fp32 = 0; | |
e013f690 | 10471 | mips_abi = NO_ABI; |
553178e4 TS |
10472 | is_saved = 1; |
10473 | break; | |
10474 | default: | |
10475 | as_bad (_("unknown ISA level")); | |
10476 | break; | |
10477 | } | |
10478 | ||
e7af610e NC |
10479 | switch (isa) |
10480 | { | |
84ea6cf2 NC |
10481 | case 0: mips_opts.isa = file_mips_isa; break; |
10482 | case 1: mips_opts.isa = ISA_MIPS1; break; | |
10483 | case 2: mips_opts.isa = ISA_MIPS2; break; | |
10484 | case 3: mips_opts.isa = ISA_MIPS3; break; | |
84ea6cf2 | 10485 | case 4: mips_opts.isa = ISA_MIPS4; break; |
9a41af64 | 10486 | case 5: mips_opts.isa = ISA_MIPS5; break; |
84ea6cf2 NC |
10487 | case 32: mips_opts.isa = ISA_MIPS32; break; |
10488 | case 64: mips_opts.isa = ISA_MIPS64; break; | |
10489 | default: as_bad (_("unknown ISA level")); break; | |
e7af610e | 10490 | } |
252b5132 RH |
10491 | } |
10492 | else if (strcmp (name, "autoextend") == 0) | |
10493 | mips_opts.noautoextend = 0; | |
10494 | else if (strcmp (name, "noautoextend") == 0) | |
10495 | mips_opts.noautoextend = 1; | |
10496 | else if (strcmp (name, "push") == 0) | |
10497 | { | |
10498 | struct mips_option_stack *s; | |
10499 | ||
10500 | s = (struct mips_option_stack *) xmalloc (sizeof *s); | |
10501 | s->next = mips_opts_stack; | |
10502 | s->options = mips_opts; | |
10503 | mips_opts_stack = s; | |
10504 | } | |
10505 | else if (strcmp (name, "pop") == 0) | |
10506 | { | |
10507 | struct mips_option_stack *s; | |
10508 | ||
10509 | s = mips_opts_stack; | |
10510 | if (s == NULL) | |
10511 | as_bad (_(".set pop with no .set push")); | |
10512 | else | |
10513 | { | |
10514 | /* If we're changing the reorder mode we need to handle | |
10515 | delay slots correctly. */ | |
10516 | if (s->options.noreorder && ! mips_opts.noreorder) | |
10517 | mips_emit_delays (true); | |
10518 | else if (! s->options.noreorder && mips_opts.noreorder) | |
10519 | { | |
10520 | if (prev_nop_frag != NULL) | |
10521 | { | |
10522 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds | |
10523 | * (mips_opts.mips16 ? 2 : 4)); | |
10524 | prev_nop_frag = NULL; | |
10525 | } | |
10526 | } | |
10527 | ||
10528 | mips_opts = s->options; | |
10529 | mips_opts_stack = s->next; | |
10530 | free (s); | |
10531 | } | |
10532 | } | |
10533 | else | |
10534 | { | |
10535 | as_warn (_("Tried to set unrecognized symbol: %s\n"), name); | |
10536 | } | |
10537 | *input_line_pointer = ch; | |
10538 | demand_empty_rest_of_line (); | |
10539 | } | |
10540 | ||
10541 | /* Handle the .abicalls pseudo-op. I believe this is equivalent to | |
10542 | .option pic2. It means to generate SVR4 PIC calls. */ | |
10543 | ||
10544 | static void | |
10545 | s_abicalls (ignore) | |
43841e91 | 10546 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10547 | { |
10548 | mips_pic = SVR4_PIC; | |
10549 | if (USE_GLOBAL_POINTER_OPT) | |
10550 | { | |
10551 | if (g_switch_seen && g_switch_value != 0) | |
10552 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
10553 | g_switch_value = 0; | |
10554 | } | |
10555 | bfd_set_gp_size (stdoutput, 0); | |
10556 | demand_empty_rest_of_line (); | |
10557 | } | |
10558 | ||
10559 | /* Handle the .cpload pseudo-op. This is used when generating SVR4 | |
10560 | PIC code. It sets the $gp register for the function based on the | |
10561 | function address, which is in the register named in the argument. | |
10562 | This uses a relocation against _gp_disp, which is handled specially | |
10563 | by the linker. The result is: | |
10564 | lui $gp,%hi(_gp_disp) | |
10565 | addiu $gp,$gp,%lo(_gp_disp) | |
10566 | addu $gp,$gp,.cpload argument | |
10567 | The .cpload argument is normally $25 == $t9. */ | |
10568 | ||
10569 | static void | |
10570 | s_cpload (ignore) | |
43841e91 | 10571 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10572 | { |
10573 | expressionS ex; | |
10574 | int icnt = 0; | |
10575 | ||
10576 | /* If we are not generating SVR4 PIC code, .cpload is ignored. */ | |
10577 | if (mips_pic != SVR4_PIC) | |
10578 | { | |
10579 | s_ignore (0); | |
10580 | return; | |
10581 | } | |
10582 | ||
10583 | /* .cpload should be a in .set noreorder section. */ | |
10584 | if (mips_opts.noreorder == 0) | |
10585 | as_warn (_(".cpload not in noreorder section")); | |
10586 | ||
10587 | ex.X_op = O_symbol; | |
10588 | ex.X_add_symbol = symbol_find_or_make ("_gp_disp"); | |
10589 | ex.X_op_symbol = NULL; | |
10590 | ex.X_add_number = 0; | |
10591 | ||
10592 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ | |
49309057 | 10593 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
252b5132 RH |
10594 | |
10595 | macro_build_lui ((char *) NULL, &icnt, &ex, GP); | |
10596 | macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP, | |
10597 | (int) BFD_RELOC_LO16); | |
10598 | ||
10599 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t", | |
10600 | GP, GP, tc_get_register (0)); | |
10601 | ||
10602 | demand_empty_rest_of_line (); | |
10603 | } | |
10604 | ||
10605 | /* Handle the .cprestore pseudo-op. This stores $gp into a given | |
10606 | offset from $sp. The offset is remembered, and after making a PIC | |
10607 | call $gp is restored from that location. */ | |
10608 | ||
10609 | static void | |
10610 | s_cprestore (ignore) | |
43841e91 | 10611 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10612 | { |
10613 | expressionS ex; | |
10614 | int icnt = 0; | |
10615 | ||
10616 | /* If we are not generating SVR4 PIC code, .cprestore is ignored. */ | |
10617 | if (mips_pic != SVR4_PIC) | |
10618 | { | |
10619 | s_ignore (0); | |
10620 | return; | |
10621 | } | |
10622 | ||
10623 | mips_cprestore_offset = get_absolute_expression (); | |
10624 | ||
10625 | ex.X_op = O_constant; | |
10626 | ex.X_add_symbol = NULL; | |
10627 | ex.X_op_symbol = NULL; | |
10628 | ex.X_add_number = mips_cprestore_offset; | |
10629 | ||
10630 | macro_build ((char *) NULL, &icnt, &ex, | |
ca4e0257 | 10631 | HAVE_32BIT_ADDRESSES ? "sw" : "sd", |
252b5132 RH |
10632 | "t,o(b)", GP, (int) BFD_RELOC_LO16, SP); |
10633 | ||
10634 | demand_empty_rest_of_line (); | |
10635 | } | |
10636 | ||
10637 | /* Handle the .gpword pseudo-op. This is used when generating PIC | |
10638 | code. It generates a 32 bit GP relative reloc. */ | |
10639 | ||
10640 | static void | |
10641 | s_gpword (ignore) | |
43841e91 | 10642 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10643 | { |
10644 | symbolS *label; | |
10645 | expressionS ex; | |
10646 | char *p; | |
10647 | ||
10648 | /* When not generating PIC code, this is treated as .word. */ | |
10649 | if (mips_pic != SVR4_PIC) | |
10650 | { | |
10651 | s_cons (2); | |
10652 | return; | |
10653 | } | |
10654 | ||
10655 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10656 | mips_emit_delays (true); | |
10657 | if (auto_align) | |
10658 | mips_align (2, 0, label); | |
10659 | mips_clear_insn_labels (); | |
10660 | ||
10661 | expression (&ex); | |
10662 | ||
10663 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
10664 | { | |
10665 | as_bad (_("Unsupported use of .gpword")); | |
10666 | ignore_rest_of_line (); | |
10667 | } | |
10668 | ||
10669 | p = frag_more (4); | |
10670 | md_number_to_chars (p, (valueT) 0, 4); | |
10671 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0, | |
10672 | BFD_RELOC_MIPS_GPREL32); | |
10673 | ||
10674 | demand_empty_rest_of_line (); | |
10675 | } | |
10676 | ||
10677 | /* Handle the .cpadd pseudo-op. This is used when dealing with switch | |
10678 | tables in SVR4 PIC code. */ | |
10679 | ||
10680 | static void | |
10681 | s_cpadd (ignore) | |
43841e91 | 10682 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10683 | { |
10684 | int icnt = 0; | |
10685 | int reg; | |
10686 | ||
10687 | /* This is ignored when not generating SVR4 PIC code. */ | |
10688 | if (mips_pic != SVR4_PIC) | |
10689 | { | |
10690 | s_ignore (0); | |
10691 | return; | |
10692 | } | |
10693 | ||
10694 | /* Add $gp to the register named as an argument. */ | |
10695 | reg = tc_get_register (0); | |
10696 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 10697 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
10698 | "d,v,t", reg, reg, GP); |
10699 | ||
bdaaa2e1 | 10700 | demand_empty_rest_of_line (); |
252b5132 RH |
10701 | } |
10702 | ||
10703 | /* Handle the .insn pseudo-op. This marks instruction labels in | |
10704 | mips16 mode. This permits the linker to handle them specially, | |
10705 | such as generating jalx instructions when needed. We also make | |
10706 | them odd for the duration of the assembly, in order to generate the | |
10707 | right sort of code. We will make them even in the adjust_symtab | |
10708 | routine, while leaving them marked. This is convenient for the | |
10709 | debugger and the disassembler. The linker knows to make them odd | |
10710 | again. */ | |
10711 | ||
10712 | static void | |
10713 | s_insn (ignore) | |
43841e91 | 10714 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10715 | { |
10716 | if (mips_opts.mips16) | |
10717 | mips16_mark_labels (); | |
10718 | ||
10719 | demand_empty_rest_of_line (); | |
10720 | } | |
10721 | ||
10722 | /* Handle a .stabn directive. We need these in order to mark a label | |
10723 | as being a mips16 text label correctly. Sometimes the compiler | |
10724 | will emit a label, followed by a .stabn, and then switch sections. | |
10725 | If the label and .stabn are in mips16 mode, then the label is | |
10726 | really a mips16 text label. */ | |
10727 | ||
10728 | static void | |
10729 | s_mips_stab (type) | |
10730 | int type; | |
10731 | { | |
10732 | if (type == 'n' && mips_opts.mips16) | |
10733 | mips16_mark_labels (); | |
10734 | ||
10735 | s_stab (type); | |
10736 | } | |
10737 | ||
10738 | /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. | |
10739 | */ | |
10740 | ||
10741 | static void | |
10742 | s_mips_weakext (ignore) | |
43841e91 | 10743 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10744 | { |
10745 | char *name; | |
10746 | int c; | |
10747 | symbolS *symbolP; | |
10748 | expressionS exp; | |
10749 | ||
10750 | name = input_line_pointer; | |
10751 | c = get_symbol_end (); | |
10752 | symbolP = symbol_find_or_make (name); | |
10753 | S_SET_WEAK (symbolP); | |
10754 | *input_line_pointer = c; | |
10755 | ||
10756 | SKIP_WHITESPACE (); | |
10757 | ||
10758 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
10759 | { | |
10760 | if (S_IS_DEFINED (symbolP)) | |
10761 | { | |
10762 | as_bad ("Ignoring attempt to redefine symbol `%s'.", | |
10763 | S_GET_NAME (symbolP)); | |
10764 | ignore_rest_of_line (); | |
10765 | return; | |
10766 | } | |
bdaaa2e1 | 10767 | |
252b5132 RH |
10768 | if (*input_line_pointer == ',') |
10769 | { | |
10770 | ++input_line_pointer; | |
10771 | SKIP_WHITESPACE (); | |
10772 | } | |
bdaaa2e1 | 10773 | |
252b5132 RH |
10774 | expression (&exp); |
10775 | if (exp.X_op != O_symbol) | |
10776 | { | |
10777 | as_bad ("bad .weakext directive"); | |
10778 | ignore_rest_of_line(); | |
10779 | return; | |
10780 | } | |
49309057 | 10781 | symbol_set_value_expression (symbolP, &exp); |
252b5132 RH |
10782 | } |
10783 | ||
10784 | demand_empty_rest_of_line (); | |
10785 | } | |
10786 | ||
10787 | /* Parse a register string into a number. Called from the ECOFF code | |
10788 | to parse .frame. The argument is non-zero if this is the frame | |
10789 | register, so that we can record it in mips_frame_reg. */ | |
10790 | ||
10791 | int | |
10792 | tc_get_register (frame) | |
10793 | int frame; | |
10794 | { | |
10795 | int reg; | |
10796 | ||
10797 | SKIP_WHITESPACE (); | |
10798 | if (*input_line_pointer++ != '$') | |
10799 | { | |
10800 | as_warn (_("expected `$'")); | |
10801 | reg = 0; | |
10802 | } | |
3882b010 | 10803 | else if (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
10804 | { |
10805 | reg = get_absolute_expression (); | |
10806 | if (reg < 0 || reg >= 32) | |
10807 | { | |
10808 | as_warn (_("Bad register number")); | |
10809 | reg = 0; | |
10810 | } | |
10811 | } | |
10812 | else | |
10813 | { | |
10814 | if (strncmp (input_line_pointer, "fp", 2) == 0) | |
10815 | reg = FP; | |
10816 | else if (strncmp (input_line_pointer, "sp", 2) == 0) | |
10817 | reg = SP; | |
10818 | else if (strncmp (input_line_pointer, "gp", 2) == 0) | |
10819 | reg = GP; | |
10820 | else if (strncmp (input_line_pointer, "at", 2) == 0) | |
10821 | reg = AT; | |
10822 | else | |
10823 | { | |
10824 | as_warn (_("Unrecognized register name")); | |
10825 | reg = 0; | |
10826 | } | |
10827 | input_line_pointer += 2; | |
10828 | } | |
10829 | if (frame) | |
10830 | mips_frame_reg = reg != 0 ? reg : SP; | |
10831 | return reg; | |
10832 | } | |
10833 | ||
10834 | valueT | |
10835 | md_section_align (seg, addr) | |
10836 | asection *seg; | |
10837 | valueT addr; | |
10838 | { | |
10839 | int align = bfd_get_section_alignment (stdoutput, seg); | |
10840 | ||
10841 | #ifdef OBJ_ELF | |
10842 | /* We don't need to align ELF sections to the full alignment. | |
10843 | However, Irix 5 may prefer that we align them at least to a 16 | |
10844 | byte boundary. We don't bother to align the sections if we are | |
10845 | targeted for an embedded system. */ | |
10846 | if (strcmp (TARGET_OS, "elf") == 0) | |
10847 | return addr; | |
10848 | if (align > 4) | |
10849 | align = 4; | |
10850 | #endif | |
10851 | ||
10852 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
10853 | } | |
10854 | ||
10855 | /* Utility routine, called from above as well. If called while the | |
10856 | input file is still being read, it's only an approximation. (For | |
10857 | example, a symbol may later become defined which appeared to be | |
10858 | undefined earlier.) */ | |
10859 | ||
10860 | static int | |
10861 | nopic_need_relax (sym, before_relaxing) | |
10862 | symbolS *sym; | |
10863 | int before_relaxing; | |
10864 | { | |
10865 | if (sym == 0) | |
10866 | return 0; | |
10867 | ||
10868 | if (USE_GLOBAL_POINTER_OPT) | |
10869 | { | |
10870 | const char *symname; | |
10871 | int change; | |
10872 | ||
10873 | /* Find out whether this symbol can be referenced off the GP | |
10874 | register. It can be if it is smaller than the -G size or if | |
10875 | it is in the .sdata or .sbss section. Certain symbols can | |
10876 | not be referenced off the GP, although it appears as though | |
10877 | they can. */ | |
10878 | symname = S_GET_NAME (sym); | |
10879 | if (symname != (const char *) NULL | |
10880 | && (strcmp (symname, "eprol") == 0 | |
10881 | || strcmp (symname, "etext") == 0 | |
10882 | || strcmp (symname, "_gp") == 0 | |
10883 | || strcmp (symname, "edata") == 0 | |
10884 | || strcmp (symname, "_fbss") == 0 | |
10885 | || strcmp (symname, "_fdata") == 0 | |
10886 | || strcmp (symname, "_ftext") == 0 | |
10887 | || strcmp (symname, "end") == 0 | |
10888 | || strcmp (symname, "_gp_disp") == 0)) | |
10889 | change = 1; | |
10890 | else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym)) | |
10891 | && (0 | |
10892 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 ILT |
10893 | || (symbol_get_obj (sym)->ecoff_extern_size != 0 |
10894 | && (symbol_get_obj (sym)->ecoff_extern_size | |
10895 | <= g_switch_value)) | |
252b5132 RH |
10896 | #endif |
10897 | /* We must defer this decision until after the whole | |
10898 | file has been read, since there might be a .extern | |
10899 | after the first use of this symbol. */ | |
10900 | || (before_relaxing | |
10901 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 | 10902 | && symbol_get_obj (sym)->ecoff_extern_size == 0 |
252b5132 RH |
10903 | #endif |
10904 | && S_GET_VALUE (sym) == 0) | |
10905 | || (S_GET_VALUE (sym) != 0 | |
10906 | && S_GET_VALUE (sym) <= g_switch_value))) | |
10907 | change = 0; | |
10908 | else | |
10909 | { | |
10910 | const char *segname; | |
10911 | ||
10912 | segname = segment_name (S_GET_SEGMENT (sym)); | |
10913 | assert (strcmp (segname, ".lit8") != 0 | |
10914 | && strcmp (segname, ".lit4") != 0); | |
10915 | change = (strcmp (segname, ".sdata") != 0 | |
fba2b7f9 GK |
10916 | && strcmp (segname, ".sbss") != 0 |
10917 | && strncmp (segname, ".sdata.", 7) != 0 | |
10918 | && strncmp (segname, ".gnu.linkonce.s.", 16) != 0); | |
252b5132 RH |
10919 | } |
10920 | return change; | |
10921 | } | |
10922 | else | |
10923 | /* We are not optimizing for the GP register. */ | |
10924 | return 1; | |
10925 | } | |
10926 | ||
10927 | /* Given a mips16 variant frag FRAGP, return non-zero if it needs an | |
10928 | extended opcode. SEC is the section the frag is in. */ | |
10929 | ||
10930 | static int | |
10931 | mips16_extended_frag (fragp, sec, stretch) | |
10932 | fragS *fragp; | |
10933 | asection *sec; | |
10934 | long stretch; | |
10935 | { | |
10936 | int type; | |
10937 | register const struct mips16_immed_operand *op; | |
10938 | offsetT val; | |
10939 | int mintiny, maxtiny; | |
10940 | segT symsec; | |
98aa84af | 10941 | fragS *sym_frag; |
252b5132 RH |
10942 | |
10943 | if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) | |
10944 | return 0; | |
10945 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) | |
10946 | return 1; | |
10947 | ||
10948 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
10949 | op = mips16_immed_operands; | |
10950 | while (op->type != type) | |
10951 | { | |
10952 | ++op; | |
10953 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
10954 | } | |
10955 | ||
10956 | if (op->unsp) | |
10957 | { | |
10958 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
10959 | { | |
10960 | mintiny = 1; | |
10961 | maxtiny = 1 << op->nbits; | |
10962 | } | |
10963 | else | |
10964 | { | |
10965 | mintiny = 0; | |
10966 | maxtiny = (1 << op->nbits) - 1; | |
10967 | } | |
10968 | } | |
10969 | else | |
10970 | { | |
10971 | mintiny = - (1 << (op->nbits - 1)); | |
10972 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
10973 | } | |
10974 | ||
98aa84af | 10975 | sym_frag = symbol_get_frag (fragp->fr_symbol); |
ac62c346 | 10976 | val = S_GET_VALUE (fragp->fr_symbol); |
98aa84af | 10977 | symsec = S_GET_SEGMENT (fragp->fr_symbol); |
252b5132 RH |
10978 | |
10979 | if (op->pcrel) | |
10980 | { | |
10981 | addressT addr; | |
10982 | ||
10983 | /* We won't have the section when we are called from | |
10984 | mips_relax_frag. However, we will always have been called | |
10985 | from md_estimate_size_before_relax first. If this is a | |
10986 | branch to a different section, we mark it as such. If SEC is | |
10987 | NULL, and the frag is not marked, then it must be a branch to | |
10988 | the same section. */ | |
10989 | if (sec == NULL) | |
10990 | { | |
10991 | if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype)) | |
10992 | return 1; | |
10993 | } | |
10994 | else | |
10995 | { | |
98aa84af | 10996 | /* Must have been called from md_estimate_size_before_relax. */ |
252b5132 RH |
10997 | if (symsec != sec) |
10998 | { | |
10999 | fragp->fr_subtype = | |
11000 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11001 | ||
11002 | /* FIXME: We should support this, and let the linker | |
11003 | catch branches and loads that are out of range. */ | |
11004 | as_bad_where (fragp->fr_file, fragp->fr_line, | |
11005 | _("unsupported PC relative reference to different section")); | |
11006 | ||
11007 | return 1; | |
11008 | } | |
98aa84af AM |
11009 | if (fragp != sym_frag && sym_frag->fr_address == 0) |
11010 | /* Assume non-extended on the first relaxation pass. | |
11011 | The address we have calculated will be bogus if this is | |
11012 | a forward branch to another frag, as the forward frag | |
11013 | will have fr_address == 0. */ | |
11014 | return 0; | |
252b5132 RH |
11015 | } |
11016 | ||
11017 | /* In this case, we know for sure that the symbol fragment is in | |
98aa84af AM |
11018 | the same section. If the relax_marker of the symbol fragment |
11019 | differs from the relax_marker of this fragment, we have not | |
11020 | yet adjusted the symbol fragment fr_address. We want to add | |
252b5132 RH |
11021 | in STRETCH in order to get a better estimate of the address. |
11022 | This particularly matters because of the shift bits. */ | |
11023 | if (stretch != 0 | |
98aa84af | 11024 | && sym_frag->relax_marker != fragp->relax_marker) |
252b5132 RH |
11025 | { |
11026 | fragS *f; | |
11027 | ||
11028 | /* Adjust stretch for any alignment frag. Note that if have | |
11029 | been expanding the earlier code, the symbol may be | |
11030 | defined in what appears to be an earlier frag. FIXME: | |
11031 | This doesn't handle the fr_subtype field, which specifies | |
11032 | a maximum number of bytes to skip when doing an | |
11033 | alignment. */ | |
98aa84af | 11034 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) |
252b5132 RH |
11035 | { |
11036 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
11037 | { | |
11038 | if (stretch < 0) | |
11039 | stretch = - ((- stretch) | |
11040 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
11041 | else | |
11042 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
11043 | if (stretch == 0) | |
11044 | break; | |
11045 | } | |
11046 | } | |
11047 | if (f != NULL) | |
11048 | val += stretch; | |
11049 | } | |
11050 | ||
11051 | addr = fragp->fr_address + fragp->fr_fix; | |
11052 | ||
11053 | /* The base address rules are complicated. The base address of | |
11054 | a branch is the following instruction. The base address of a | |
11055 | PC relative load or add is the instruction itself, but if it | |
11056 | is in a delay slot (in which case it can not be extended) use | |
11057 | the address of the instruction whose delay slot it is in. */ | |
11058 | if (type == 'p' || type == 'q') | |
11059 | { | |
11060 | addr += 2; | |
11061 | ||
11062 | /* If we are currently assuming that this frag should be | |
11063 | extended, then, the current address is two bytes | |
bdaaa2e1 | 11064 | higher. */ |
252b5132 RH |
11065 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
11066 | addr += 2; | |
11067 | ||
11068 | /* Ignore the low bit in the target, since it will be set | |
11069 | for a text label. */ | |
11070 | if ((val & 1) != 0) | |
11071 | --val; | |
11072 | } | |
11073 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
11074 | addr -= 4; | |
11075 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
11076 | addr -= 2; | |
11077 | ||
11078 | val -= addr & ~ ((1 << op->shift) - 1); | |
11079 | ||
11080 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
11081 | if (type == 'p' || type == 'q') | |
11082 | val /= 2; | |
11083 | ||
11084 | /* If any of the shifted bits are set, we must use an extended | |
11085 | opcode. If the address depends on the size of this | |
11086 | instruction, this can lead to a loop, so we arrange to always | |
11087 | use an extended opcode. We only check this when we are in | |
11088 | the main relaxation loop, when SEC is NULL. */ | |
11089 | if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL) | |
11090 | { | |
11091 | fragp->fr_subtype = | |
11092 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11093 | return 1; | |
11094 | } | |
11095 | ||
11096 | /* If we are about to mark a frag as extended because the value | |
11097 | is precisely maxtiny + 1, then there is a chance of an | |
11098 | infinite loop as in the following code: | |
11099 | la $4,foo | |
11100 | .skip 1020 | |
11101 | .align 2 | |
11102 | foo: | |
11103 | In this case when the la is extended, foo is 0x3fc bytes | |
11104 | away, so the la can be shrunk, but then foo is 0x400 away, so | |
11105 | the la must be extended. To avoid this loop, we mark the | |
11106 | frag as extended if it was small, and is about to become | |
11107 | extended with a value of maxtiny + 1. */ | |
11108 | if (val == ((maxtiny + 1) << op->shift) | |
11109 | && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype) | |
11110 | && sec == NULL) | |
11111 | { | |
11112 | fragp->fr_subtype = | |
11113 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11114 | return 1; | |
11115 | } | |
11116 | } | |
11117 | else if (symsec != absolute_section && sec != NULL) | |
11118 | as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation")); | |
11119 | ||
11120 | if ((val & ((1 << op->shift) - 1)) != 0 | |
11121 | || val < (mintiny << op->shift) | |
11122 | || val > (maxtiny << op->shift)) | |
11123 | return 1; | |
11124 | else | |
11125 | return 0; | |
11126 | } | |
11127 | ||
11128 | /* Estimate the size of a frag before relaxing. Unless this is the | |
11129 | mips16, we are not really relaxing here, and the final size is | |
11130 | encoded in the subtype information. For the mips16, we have to | |
11131 | decide whether we are using an extended opcode or not. */ | |
11132 | ||
252b5132 RH |
11133 | int |
11134 | md_estimate_size_before_relax (fragp, segtype) | |
11135 | fragS *fragp; | |
11136 | asection *segtype; | |
11137 | { | |
43841e91 | 11138 | int change = 0; |
8614eeee | 11139 | boolean linkonce = false; |
252b5132 RH |
11140 | |
11141 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
11142 | { | |
11143 | if (mips16_extended_frag (fragp, segtype, 0)) | |
11144 | { | |
11145 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
11146 | return 4; | |
11147 | } | |
11148 | else | |
11149 | { | |
11150 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
11151 | return 2; | |
11152 | } | |
11153 | } | |
11154 | ||
11155 | if (mips_pic == NO_PIC) | |
11156 | { | |
11157 | change = nopic_need_relax (fragp->fr_symbol, 0); | |
11158 | } | |
11159 | else if (mips_pic == SVR4_PIC) | |
11160 | { | |
11161 | symbolS *sym; | |
11162 | asection *symsec; | |
11163 | ||
11164 | sym = fragp->fr_symbol; | |
11165 | ||
11166 | /* Handle the case of a symbol equated to another symbol. */ | |
e0890092 | 11167 | while (symbol_equated_reloc_p (sym)) |
252b5132 RH |
11168 | { |
11169 | symbolS *n; | |
11170 | ||
11171 | /* It's possible to get a loop here in a badly written | |
11172 | program. */ | |
49309057 | 11173 | n = symbol_get_value_expression (sym)->X_add_symbol; |
252b5132 RH |
11174 | if (n == sym) |
11175 | break; | |
11176 | sym = n; | |
11177 | } | |
11178 | ||
11179 | symsec = S_GET_SEGMENT (sym); | |
11180 | ||
8614eeee UC |
11181 | /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */ |
11182 | if (symsec != segtype && ! S_IS_LOCAL (sym)) | |
beae10d5 KH |
11183 | { |
11184 | if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) | |
11185 | != 0) | |
11186 | linkonce = true; | |
11187 | ||
11188 | /* The GNU toolchain uses an extension for ELF: a section | |
11189 | beginning with the magic string .gnu.linkonce is a linkonce | |
11190 | section. */ | |
11191 | if (strncmp (segment_name (symsec), ".gnu.linkonce", | |
11192 | sizeof ".gnu.linkonce" - 1) == 0) | |
11193 | linkonce = true; | |
11194 | } | |
8614eeee | 11195 | |
252b5132 RH |
11196 | /* This must duplicate the test in adjust_reloc_syms. */ |
11197 | change = (symsec != &bfd_und_section | |
11198 | && symsec != &bfd_abs_section | |
426b0403 | 11199 | && ! bfd_is_com_section (symsec) |
8614eeee | 11200 | && !linkonce |
426b0403 | 11201 | #ifdef OBJ_ELF |
ea4ff978 | 11202 | /* A global or weak symbol is treated as external. */ |
46bac6de L |
11203 | && (OUTPUT_FLAVOR == bfd_target_elf_flavour |
11204 | && ! (S_IS_EXTERN (sym) || S_IS_WEAK (sym))) | |
426b0403 AM |
11205 | #endif |
11206 | ); | |
252b5132 RH |
11207 | } |
11208 | else | |
11209 | abort (); | |
11210 | ||
11211 | if (change) | |
11212 | { | |
11213 | /* Record the offset to the first reloc in the fr_opcode field. | |
11214 | This lets md_convert_frag and tc_gen_reloc know that the code | |
11215 | must be expanded. */ | |
11216 | fragp->fr_opcode = (fragp->fr_literal | |
11217 | + fragp->fr_fix | |
11218 | - RELAX_OLD (fragp->fr_subtype) | |
11219 | + RELAX_RELOC1 (fragp->fr_subtype)); | |
11220 | /* FIXME: This really needs as_warn_where. */ | |
11221 | if (RELAX_WARN (fragp->fr_subtype)) | |
9a41af64 TS |
11222 | as_warn (_("AT used after \".set noat\" or macro used after " |
11223 | "\".set nomacro\"")); | |
11224 | ||
11225 | return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype); | |
252b5132 RH |
11226 | } |
11227 | ||
9a41af64 | 11228 | return 0; |
252b5132 RH |
11229 | } |
11230 | ||
11231 | /* This is called to see whether a reloc against a defined symbol | |
11232 | should be converted into a reloc against a section. Don't adjust | |
11233 | MIPS16 jump relocations, so we don't have to worry about the format | |
11234 | of the offset in the .o file. Don't adjust relocations against | |
11235 | mips16 symbols, so that the linker can find them if it needs to set | |
11236 | up a stub. */ | |
11237 | ||
11238 | int | |
11239 | mips_fix_adjustable (fixp) | |
11240 | fixS *fixp; | |
11241 | { | |
ea4ff978 L |
11242 | #ifdef OBJ_ELF |
11243 | /* Prevent all adjustments to global symbols. */ | |
46bac6de L |
11244 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
11245 | && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy))) | |
ea4ff978 L |
11246 | return 0; |
11247 | #endif | |
252b5132 RH |
11248 | if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP) |
11249 | return 0; | |
11250 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
11251 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
11252 | return 0; | |
11253 | if (fixp->fx_addsy == NULL) | |
11254 | return 1; | |
11255 | #ifdef OBJ_ELF | |
11256 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
11257 | && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16 | |
11258 | && fixp->fx_subsy == NULL) | |
11259 | return 0; | |
11260 | #endif | |
11261 | return 1; | |
11262 | } | |
11263 | ||
11264 | /* Translate internal representation of relocation info to BFD target | |
11265 | format. */ | |
11266 | ||
11267 | arelent ** | |
11268 | tc_gen_reloc (section, fixp) | |
43841e91 | 11269 | asection *section ATTRIBUTE_UNUSED; |
252b5132 RH |
11270 | fixS *fixp; |
11271 | { | |
11272 | static arelent *retval[4]; | |
11273 | arelent *reloc; | |
11274 | bfd_reloc_code_real_type code; | |
11275 | ||
11276 | reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent)); | |
11277 | retval[1] = NULL; | |
11278 | ||
49309057 ILT |
11279 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
11280 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
11281 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
11282 | ||
11283 | if (mips_pic == EMBEDDED_PIC | |
11284 | && SWITCH_TABLE (fixp)) | |
11285 | { | |
11286 | /* For a switch table entry we use a special reloc. The addend | |
11287 | is actually the difference between the reloc address and the | |
11288 | subtrahend. */ | |
11289 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); | |
11290 | if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour) | |
11291 | as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc")); | |
11292 | fixp->fx_r_type = BFD_RELOC_GPREL32; | |
11293 | } | |
bb2d6cd7 GK |
11294 | else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour) |
11295 | reloc->addend = fixp->fx_addnumber; | |
252b5132 RH |
11296 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16) |
11297 | { | |
11298 | /* We use a special addend for an internal RELLO reloc. */ | |
49309057 | 11299 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
11300 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); |
11301 | else | |
11302 | reloc->addend = fixp->fx_addnumber + reloc->address; | |
11303 | } | |
11304 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S) | |
11305 | { | |
11306 | assert (fixp->fx_next != NULL | |
11307 | && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16); | |
11308 | /* We use a special addend for an internal RELHI reloc. The | |
11309 | reloc is relative to the RELLO; adjust the addend | |
11310 | accordingly. */ | |
49309057 | 11311 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
11312 | reloc->addend = (fixp->fx_next->fx_frag->fr_address |
11313 | + fixp->fx_next->fx_where | |
11314 | - S_GET_VALUE (fixp->fx_subsy)); | |
11315 | else | |
11316 | reloc->addend = (fixp->fx_addnumber | |
11317 | + fixp->fx_next->fx_frag->fr_address | |
11318 | + fixp->fx_next->fx_where); | |
11319 | } | |
252b5132 RH |
11320 | else |
11321 | { | |
11322 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour) | |
11323 | /* A gruesome hack which is a result of the gruesome gas reloc | |
11324 | handling. */ | |
11325 | reloc->addend = reloc->address; | |
11326 | else | |
11327 | reloc->addend = -reloc->address; | |
11328 | } | |
11329 | ||
11330 | /* If this is a variant frag, we may need to adjust the existing | |
11331 | reloc and generate a new one. */ | |
11332 | if (fixp->fx_frag->fr_opcode != NULL | |
11333 | && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL | |
11334 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16 | |
11335 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16 | |
11336 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
11337 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16 | |
11338 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
11339 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)) | |
11340 | { | |
11341 | arelent *reloc2; | |
11342 | ||
11343 | assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype)); | |
11344 | ||
11345 | /* If this is not the last reloc in this frag, then we have two | |
11346 | GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a | |
11347 | CALL_HI16/CALL_LO16, both of which are being replaced. Let | |
11348 | the second one handle all of them. */ | |
11349 | if (fixp->fx_next != NULL | |
11350 | && fixp->fx_frag == fixp->fx_next->fx_frag) | |
11351 | { | |
11352 | assert ((fixp->fx_r_type == BFD_RELOC_MIPS_GPREL | |
11353 | && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL) | |
11354 | || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
11355 | && (fixp->fx_next->fx_r_type | |
11356 | == BFD_RELOC_MIPS_GOT_LO16)) | |
11357 | || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
11358 | && (fixp->fx_next->fx_r_type | |
11359 | == BFD_RELOC_MIPS_CALL_LO16))); | |
11360 | retval[0] = NULL; | |
11361 | return retval; | |
11362 | } | |
11363 | ||
11364 | fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal; | |
11365 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
11366 | reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent)); | |
11367 | retval[2] = NULL; | |
49309057 ILT |
11368 | reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
11369 | *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
11370 | reloc2->address = (reloc->address |
11371 | + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype) | |
11372 | - RELAX_RELOC1 (fixp->fx_frag->fr_subtype))); | |
11373 | reloc2->addend = fixp->fx_addnumber; | |
11374 | reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16); | |
11375 | assert (reloc2->howto != NULL); | |
11376 | ||
11377 | if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype)) | |
11378 | { | |
11379 | arelent *reloc3; | |
11380 | ||
11381 | reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent)); | |
11382 | retval[3] = NULL; | |
11383 | *reloc3 = *reloc2; | |
11384 | reloc3->address += 4; | |
11385 | } | |
11386 | ||
11387 | if (mips_pic == NO_PIC) | |
11388 | { | |
11389 | assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL); | |
11390 | fixp->fx_r_type = BFD_RELOC_HI16_S; | |
11391 | } | |
11392 | else if (mips_pic == SVR4_PIC) | |
11393 | { | |
11394 | switch (fixp->fx_r_type) | |
11395 | { | |
11396 | default: | |
11397 | abort (); | |
11398 | case BFD_RELOC_MIPS_GOT16: | |
11399 | break; | |
11400 | case BFD_RELOC_MIPS_CALL16: | |
11401 | case BFD_RELOC_MIPS_GOT_LO16: | |
11402 | case BFD_RELOC_MIPS_CALL_LO16: | |
11403 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT16; | |
11404 | break; | |
11405 | } | |
11406 | } | |
11407 | else | |
11408 | abort (); | |
11409 | } | |
11410 | ||
11411 | /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry | |
11412 | to be used in the relocation's section offset. */ | |
11413 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
11414 | { | |
11415 | reloc->address = reloc->addend; | |
11416 | reloc->addend = 0; | |
11417 | } | |
11418 | ||
11419 | /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that | |
11420 | fixup_segment converted a non-PC relative reloc into a PC | |
11421 | relative reloc. In such a case, we need to convert the reloc | |
11422 | code. */ | |
11423 | code = fixp->fx_r_type; | |
11424 | if (fixp->fx_pcrel) | |
11425 | { | |
11426 | switch (code) | |
11427 | { | |
11428 | case BFD_RELOC_8: | |
11429 | code = BFD_RELOC_8_PCREL; | |
11430 | break; | |
11431 | case BFD_RELOC_16: | |
11432 | code = BFD_RELOC_16_PCREL; | |
11433 | break; | |
11434 | case BFD_RELOC_32: | |
11435 | code = BFD_RELOC_32_PCREL; | |
11436 | break; | |
11437 | case BFD_RELOC_64: | |
11438 | code = BFD_RELOC_64_PCREL; | |
11439 | break; | |
11440 | case BFD_RELOC_8_PCREL: | |
11441 | case BFD_RELOC_16_PCREL: | |
11442 | case BFD_RELOC_32_PCREL: | |
11443 | case BFD_RELOC_64_PCREL: | |
11444 | case BFD_RELOC_16_PCREL_S2: | |
11445 | case BFD_RELOC_PCREL_HI16_S: | |
11446 | case BFD_RELOC_PCREL_LO16: | |
11447 | break; | |
11448 | default: | |
11449 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
11450 | _("Cannot make %s relocation PC relative"), | |
11451 | bfd_get_reloc_code_name (code)); | |
11452 | } | |
11453 | } | |
11454 | ||
11455 | /* To support a PC relative reloc when generating embedded PIC code | |
11456 | for ECOFF, we use a Cygnus extension. We check for that here to | |
11457 | make sure that we don't let such a reloc escape normally. */ | |
bb2d6cd7 GK |
11458 | if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
11459 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
252b5132 RH |
11460 | && code == BFD_RELOC_16_PCREL_S2 |
11461 | && mips_pic != EMBEDDED_PIC) | |
11462 | reloc->howto = NULL; | |
11463 | else | |
11464 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
11465 | ||
11466 | if (reloc->howto == NULL) | |
11467 | { | |
11468 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
11469 | _("Can not represent %s relocation in this object file format"), | |
11470 | bfd_get_reloc_code_name (code)); | |
11471 | retval[0] = NULL; | |
11472 | } | |
11473 | ||
11474 | return retval; | |
11475 | } | |
11476 | ||
11477 | /* Relax a machine dependent frag. This returns the amount by which | |
11478 | the current size of the frag should change. */ | |
11479 | ||
11480 | int | |
11481 | mips_relax_frag (fragp, stretch) | |
11482 | fragS *fragp; | |
11483 | long stretch; | |
11484 | { | |
11485 | if (! RELAX_MIPS16_P (fragp->fr_subtype)) | |
11486 | return 0; | |
11487 | ||
11488 | if (mips16_extended_frag (fragp, (asection *) NULL, stretch)) | |
11489 | { | |
11490 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11491 | return 0; | |
11492 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
11493 | return 2; | |
11494 | } | |
11495 | else | |
11496 | { | |
11497 | if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11498 | return 0; | |
11499 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
11500 | return -2; | |
11501 | } | |
11502 | ||
11503 | return 0; | |
11504 | } | |
11505 | ||
11506 | /* Convert a machine dependent frag. */ | |
11507 | ||
11508 | void | |
11509 | md_convert_frag (abfd, asec, fragp) | |
43841e91 | 11510 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
11511 | segT asec; |
11512 | fragS *fragp; | |
11513 | { | |
11514 | int old, new; | |
11515 | char *fixptr; | |
11516 | ||
11517 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
11518 | { | |
11519 | int type; | |
11520 | register const struct mips16_immed_operand *op; | |
11521 | boolean small, ext; | |
11522 | offsetT val; | |
11523 | bfd_byte *buf; | |
11524 | unsigned long insn; | |
11525 | boolean use_extend; | |
11526 | unsigned short extend; | |
11527 | ||
11528 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
11529 | op = mips16_immed_operands; | |
11530 | while (op->type != type) | |
11531 | ++op; | |
11532 | ||
11533 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11534 | { | |
11535 | small = false; | |
11536 | ext = true; | |
11537 | } | |
11538 | else | |
11539 | { | |
11540 | small = true; | |
11541 | ext = false; | |
11542 | } | |
11543 | ||
6386f3a7 | 11544 | resolve_symbol_value (fragp->fr_symbol); |
252b5132 RH |
11545 | val = S_GET_VALUE (fragp->fr_symbol); |
11546 | if (op->pcrel) | |
11547 | { | |
11548 | addressT addr; | |
11549 | ||
11550 | addr = fragp->fr_address + fragp->fr_fix; | |
11551 | ||
11552 | /* The rules for the base address of a PC relative reloc are | |
11553 | complicated; see mips16_extended_frag. */ | |
11554 | if (type == 'p' || type == 'q') | |
11555 | { | |
11556 | addr += 2; | |
11557 | if (ext) | |
11558 | addr += 2; | |
11559 | /* Ignore the low bit in the target, since it will be | |
11560 | set for a text label. */ | |
11561 | if ((val & 1) != 0) | |
11562 | --val; | |
11563 | } | |
11564 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
11565 | addr -= 4; | |
11566 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
11567 | addr -= 2; | |
11568 | ||
11569 | addr &= ~ (addressT) ((1 << op->shift) - 1); | |
11570 | val -= addr; | |
11571 | ||
11572 | /* Make sure the section winds up with the alignment we have | |
11573 | assumed. */ | |
11574 | if (op->shift > 0) | |
11575 | record_alignment (asec, op->shift); | |
11576 | } | |
11577 | ||
11578 | if (ext | |
11579 | && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype) | |
11580 | || RELAX_MIPS16_DSLOT (fragp->fr_subtype))) | |
11581 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
11582 | _("extended instruction in delay slot")); | |
11583 | ||
11584 | buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix); | |
11585 | ||
11586 | if (target_big_endian) | |
11587 | insn = bfd_getb16 (buf); | |
11588 | else | |
11589 | insn = bfd_getl16 (buf); | |
11590 | ||
11591 | mips16_immed (fragp->fr_file, fragp->fr_line, type, val, | |
11592 | RELAX_MIPS16_USER_EXT (fragp->fr_subtype), | |
11593 | small, ext, &insn, &use_extend, &extend); | |
11594 | ||
11595 | if (use_extend) | |
11596 | { | |
11597 | md_number_to_chars (buf, 0xf000 | extend, 2); | |
11598 | fragp->fr_fix += 2; | |
11599 | buf += 2; | |
11600 | } | |
11601 | ||
11602 | md_number_to_chars (buf, insn, 2); | |
11603 | fragp->fr_fix += 2; | |
11604 | buf += 2; | |
11605 | } | |
11606 | else | |
11607 | { | |
11608 | if (fragp->fr_opcode == NULL) | |
11609 | return; | |
11610 | ||
11611 | old = RELAX_OLD (fragp->fr_subtype); | |
11612 | new = RELAX_NEW (fragp->fr_subtype); | |
11613 | fixptr = fragp->fr_literal + fragp->fr_fix; | |
11614 | ||
11615 | if (new > 0) | |
11616 | memcpy (fixptr - old, fixptr, new); | |
11617 | ||
11618 | fragp->fr_fix += new - old; | |
11619 | } | |
11620 | } | |
11621 | ||
11622 | #ifdef OBJ_ELF | |
11623 | ||
11624 | /* This function is called after the relocs have been generated. | |
11625 | We've been storing mips16 text labels as odd. Here we convert them | |
11626 | back to even for the convenience of the debugger. */ | |
11627 | ||
11628 | void | |
11629 | mips_frob_file_after_relocs () | |
11630 | { | |
11631 | asymbol **syms; | |
11632 | unsigned int count, i; | |
11633 | ||
11634 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
11635 | return; | |
11636 | ||
11637 | syms = bfd_get_outsymbols (stdoutput); | |
11638 | count = bfd_get_symcount (stdoutput); | |
11639 | for (i = 0; i < count; i++, syms++) | |
11640 | { | |
11641 | if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16 | |
11642 | && ((*syms)->value & 1) != 0) | |
11643 | { | |
11644 | (*syms)->value &= ~1; | |
11645 | /* If the symbol has an odd size, it was probably computed | |
11646 | incorrectly, so adjust that as well. */ | |
11647 | if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0) | |
11648 | ++elf_symbol (*syms)->internal_elf_sym.st_size; | |
11649 | } | |
11650 | } | |
11651 | } | |
11652 | ||
11653 | #endif | |
11654 | ||
11655 | /* This function is called whenever a label is defined. It is used | |
11656 | when handling branch delays; if a branch has a label, we assume we | |
11657 | can not move it. */ | |
11658 | ||
11659 | void | |
11660 | mips_define_label (sym) | |
11661 | symbolS *sym; | |
11662 | { | |
11663 | struct insn_label_list *l; | |
11664 | ||
11665 | if (free_insn_labels == NULL) | |
11666 | l = (struct insn_label_list *) xmalloc (sizeof *l); | |
11667 | else | |
11668 | { | |
11669 | l = free_insn_labels; | |
11670 | free_insn_labels = l->next; | |
11671 | } | |
11672 | ||
11673 | l->label = sym; | |
11674 | l->next = insn_labels; | |
11675 | insn_labels = l; | |
11676 | } | |
11677 | \f | |
11678 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
11679 | ||
11680 | /* Some special processing for a MIPS ELF file. */ | |
11681 | ||
11682 | void | |
11683 | mips_elf_final_processing () | |
11684 | { | |
11685 | /* Write out the register information. */ | |
e013f690 | 11686 | if (! HAVE_NEWABI) |
252b5132 RH |
11687 | { |
11688 | Elf32_RegInfo s; | |
11689 | ||
11690 | s.ri_gprmask = mips_gprmask; | |
11691 | s.ri_cprmask[0] = mips_cprmask[0]; | |
11692 | s.ri_cprmask[1] = mips_cprmask[1]; | |
11693 | s.ri_cprmask[2] = mips_cprmask[2]; | |
11694 | s.ri_cprmask[3] = mips_cprmask[3]; | |
11695 | /* The gp_value field is set by the MIPS ELF backend. */ | |
11696 | ||
11697 | bfd_mips_elf32_swap_reginfo_out (stdoutput, &s, | |
11698 | ((Elf32_External_RegInfo *) | |
11699 | mips_regmask_frag)); | |
11700 | } | |
11701 | else | |
11702 | { | |
11703 | Elf64_Internal_RegInfo s; | |
11704 | ||
11705 | s.ri_gprmask = mips_gprmask; | |
11706 | s.ri_pad = 0; | |
11707 | s.ri_cprmask[0] = mips_cprmask[0]; | |
11708 | s.ri_cprmask[1] = mips_cprmask[1]; | |
11709 | s.ri_cprmask[2] = mips_cprmask[2]; | |
11710 | s.ri_cprmask[3] = mips_cprmask[3]; | |
11711 | /* The gp_value field is set by the MIPS ELF backend. */ | |
11712 | ||
11713 | bfd_mips_elf64_swap_reginfo_out (stdoutput, &s, | |
11714 | ((Elf64_External_RegInfo *) | |
11715 | mips_regmask_frag)); | |
11716 | } | |
11717 | ||
11718 | /* Set the MIPS ELF flag bits. FIXME: There should probably be some | |
11719 | sort of BFD interface for this. */ | |
11720 | if (mips_any_noreorder) | |
11721 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER; | |
11722 | if (mips_pic != NO_PIC) | |
11723 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC; | |
11724 | ||
bdaaa2e1 | 11725 | /* Set the MIPS ELF ABI flags. */ |
e013f690 | 11726 | if (mips_abi == NO_ABI) |
252b5132 | 11727 | ; |
e013f690 | 11728 | else if (mips_abi == O32_ABI) |
252b5132 | 11729 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32; |
e013f690 | 11730 | else if (mips_abi == O64_ABI) |
252b5132 | 11731 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64; |
e013f690 | 11732 | else if (mips_abi == EABI_ABI) |
252b5132 RH |
11733 | { |
11734 | if (mips_eabi64) | |
11735 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64; | |
11736 | else | |
11737 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32; | |
11738 | } | |
e013f690 | 11739 | else if (mips_abi == N32_ABI) |
be00bddd TS |
11740 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2; |
11741 | ||
11742 | /* Nothing to do for "64". */ | |
252b5132 RH |
11743 | |
11744 | if (mips_32bitmode) | |
11745 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE; | |
11746 | } | |
11747 | ||
11748 | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ | |
11749 | \f | |
beae10d5 KH |
11750 | typedef struct proc { |
11751 | symbolS *isym; | |
11752 | unsigned long reg_mask; | |
11753 | unsigned long reg_offset; | |
11754 | unsigned long fpreg_mask; | |
11755 | unsigned long fpreg_offset; | |
11756 | unsigned long frame_offset; | |
11757 | unsigned long frame_reg; | |
11758 | unsigned long pc_reg; | |
11759 | } procS; | |
252b5132 RH |
11760 | |
11761 | static procS cur_proc; | |
11762 | static procS *cur_proc_ptr; | |
11763 | static int numprocs; | |
11764 | ||
0a9ef439 | 11765 | /* Fill in an rs_align_code fragment. */ |
a19d8eb0 | 11766 | |
0a9ef439 RH |
11767 | void |
11768 | mips_handle_align (fragp) | |
11769 | fragS *fragp; | |
a19d8eb0 | 11770 | { |
0a9ef439 RH |
11771 | if (fragp->fr_type != rs_align_code) |
11772 | return; | |
11773 | ||
11774 | if (mips_opts.mips16) | |
a19d8eb0 CP |
11775 | { |
11776 | static const unsigned char be_nop[] = { 0x65, 0x00 }; | |
11777 | static const unsigned char le_nop[] = { 0x00, 0x65 }; | |
11778 | ||
0a9ef439 RH |
11779 | int bytes; |
11780 | char *p; | |
a19d8eb0 | 11781 | |
0a9ef439 RH |
11782 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
11783 | p = fragp->fr_literal + fragp->fr_fix; | |
11784 | ||
11785 | if (bytes & 1) | |
11786 | { | |
11787 | *p++ = 0; | |
11788 | fragp->fr_fix += 1; | |
11789 | } | |
11790 | ||
11791 | memcpy (p, (target_big_endian ? be_nop : le_nop), 2); | |
11792 | fragp->fr_var = 2; | |
a19d8eb0 CP |
11793 | } |
11794 | ||
0a9ef439 | 11795 | /* For mips32, a nop is a zero, which we trivially get by doing nothing. */ |
a19d8eb0 CP |
11796 | } |
11797 | ||
252b5132 RH |
11798 | static void |
11799 | md_obj_begin () | |
11800 | { | |
11801 | } | |
11802 | ||
11803 | static void | |
11804 | md_obj_end () | |
11805 | { | |
11806 | /* check for premature end, nesting errors, etc */ | |
11807 | if (cur_proc_ptr) | |
9a41af64 | 11808 | as_warn (_("missing .end at end of assembly")); |
252b5132 RH |
11809 | } |
11810 | ||
11811 | static long | |
11812 | get_number () | |
11813 | { | |
11814 | int negative = 0; | |
11815 | long val = 0; | |
11816 | ||
11817 | if (*input_line_pointer == '-') | |
11818 | { | |
11819 | ++input_line_pointer; | |
11820 | negative = 1; | |
11821 | } | |
3882b010 | 11822 | if (!ISDIGIT (*input_line_pointer)) |
252b5132 RH |
11823 | as_bad (_("Expected simple number.")); |
11824 | if (input_line_pointer[0] == '0') | |
11825 | { | |
11826 | if (input_line_pointer[1] == 'x') | |
11827 | { | |
11828 | input_line_pointer += 2; | |
3882b010 | 11829 | while (ISXDIGIT (*input_line_pointer)) |
252b5132 RH |
11830 | { |
11831 | val <<= 4; | |
11832 | val |= hex_value (*input_line_pointer++); | |
11833 | } | |
11834 | return negative ? -val : val; | |
11835 | } | |
11836 | else | |
11837 | { | |
11838 | ++input_line_pointer; | |
3882b010 | 11839 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
11840 | { |
11841 | val <<= 3; | |
11842 | val |= *input_line_pointer++ - '0'; | |
11843 | } | |
11844 | return negative ? -val : val; | |
11845 | } | |
11846 | } | |
3882b010 | 11847 | if (!ISDIGIT (*input_line_pointer)) |
252b5132 RH |
11848 | { |
11849 | printf (_(" *input_line_pointer == '%c' 0x%02x\n"), | |
11850 | *input_line_pointer, *input_line_pointer); | |
11851 | as_warn (_("Invalid number")); | |
11852 | return -1; | |
11853 | } | |
3882b010 | 11854 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
11855 | { |
11856 | val *= 10; | |
11857 | val += *input_line_pointer++ - '0'; | |
11858 | } | |
11859 | return negative ? -val : val; | |
11860 | } | |
11861 | ||
11862 | /* The .file directive; just like the usual .file directive, but there | |
11863 | is an initial number which is the ECOFF file index. */ | |
11864 | ||
11865 | static void | |
11866 | s_file (x) | |
43841e91 | 11867 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11868 | { |
11869 | int line; | |
11870 | ||
11871 | line = get_number (); | |
11872 | s_app_file (0); | |
11873 | } | |
11874 | ||
252b5132 RH |
11875 | /* The .end directive. */ |
11876 | ||
11877 | static void | |
11878 | s_mips_end (x) | |
43841e91 | 11879 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11880 | { |
11881 | symbolS *p; | |
11882 | int maybe_text; | |
11883 | ||
11884 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
11885 | { | |
11886 | p = get_symbol (); | |
11887 | demand_empty_rest_of_line (); | |
11888 | } | |
11889 | else | |
11890 | p = NULL; | |
11891 | ||
11892 | #ifdef BFD_ASSEMBLER | |
11893 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
11894 | maybe_text = 1; | |
11895 | else | |
11896 | maybe_text = 0; | |
11897 | #else | |
11898 | if (now_seg != data_section && now_seg != bss_section) | |
11899 | maybe_text = 1; | |
11900 | else | |
11901 | maybe_text = 0; | |
11902 | #endif | |
11903 | ||
11904 | if (!maybe_text) | |
11905 | as_warn (_(".end not in text section")); | |
11906 | ||
11907 | if (!cur_proc_ptr) | |
11908 | { | |
11909 | as_warn (_(".end directive without a preceding .ent directive.")); | |
11910 | demand_empty_rest_of_line (); | |
11911 | return; | |
11912 | } | |
11913 | ||
11914 | if (p != NULL) | |
11915 | { | |
11916 | assert (S_GET_NAME (p)); | |
11917 | if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym))) | |
11918 | as_warn (_(".end symbol does not match .ent symbol.")); | |
11919 | } | |
11920 | else | |
11921 | as_warn (_(".end directive missing or unknown symbol")); | |
11922 | ||
11923 | #ifdef MIPS_STABS_ELF | |
11924 | { | |
11925 | segT saved_seg = now_seg; | |
11926 | subsegT saved_subseg = now_subseg; | |
252b5132 | 11927 | valueT dot; |
252b5132 RH |
11928 | expressionS exp; |
11929 | char *fragp; | |
11930 | ||
11931 | dot = frag_now_fix (); | |
11932 | ||
11933 | #ifdef md_flush_pending_output | |
11934 | md_flush_pending_output (); | |
11935 | #endif | |
11936 | ||
11937 | assert (pdr_seg); | |
11938 | subseg_set (pdr_seg, 0); | |
11939 | ||
beae10d5 | 11940 | /* Write the symbol. */ |
252b5132 RH |
11941 | exp.X_op = O_symbol; |
11942 | exp.X_add_symbol = p; | |
11943 | exp.X_add_number = 0; | |
11944 | emit_expr (&exp, 4); | |
11945 | ||
beae10d5 | 11946 | fragp = frag_more (7 * 4); |
252b5132 | 11947 | |
beae10d5 KH |
11948 | md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4); |
11949 | md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4); | |
11950 | md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4); | |
11951 | md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4); | |
11952 | md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4); | |
11953 | md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4); | |
11954 | md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4); | |
252b5132 RH |
11955 | |
11956 | subseg_set (saved_seg, saved_subseg); | |
11957 | } | |
11958 | #endif | |
11959 | ||
11960 | cur_proc_ptr = NULL; | |
11961 | } | |
11962 | ||
11963 | /* The .aent and .ent directives. */ | |
11964 | ||
11965 | static void | |
11966 | s_mips_ent (aent) | |
11967 | int aent; | |
11968 | { | |
11969 | int number = 0; | |
11970 | symbolS *symbolP; | |
11971 | int maybe_text; | |
11972 | ||
11973 | symbolP = get_symbol (); | |
11974 | if (*input_line_pointer == ',') | |
11975 | input_line_pointer++; | |
11976 | SKIP_WHITESPACE (); | |
3882b010 | 11977 | if (ISDIGIT (*input_line_pointer) |
d9a62219 | 11978 | || *input_line_pointer == '-') |
252b5132 RH |
11979 | number = get_number (); |
11980 | ||
11981 | #ifdef BFD_ASSEMBLER | |
11982 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
11983 | maybe_text = 1; | |
11984 | else | |
11985 | maybe_text = 0; | |
11986 | #else | |
11987 | if (now_seg != data_section && now_seg != bss_section) | |
11988 | maybe_text = 1; | |
11989 | else | |
11990 | maybe_text = 0; | |
11991 | #endif | |
11992 | ||
11993 | if (!maybe_text) | |
11994 | as_warn (_(".ent or .aent not in text section.")); | |
11995 | ||
11996 | if (!aent && cur_proc_ptr) | |
9a41af64 | 11997 | as_warn (_("missing .end")); |
252b5132 RH |
11998 | |
11999 | if (!aent) | |
12000 | { | |
12001 | cur_proc_ptr = &cur_proc; | |
12002 | memset (cur_proc_ptr, '\0', sizeof (procS)); | |
12003 | ||
12004 | cur_proc_ptr->isym = symbolP; | |
12005 | ||
49309057 | 12006 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
12007 | |
12008 | numprocs++; | |
12009 | } | |
12010 | ||
12011 | demand_empty_rest_of_line (); | |
12012 | } | |
12013 | ||
12014 | /* The .frame directive. If the mdebug section is present (IRIX 5 native) | |
bdaaa2e1 | 12015 | then ecoff.c (ecoff_directive_frame) is used. For embedded targets, |
252b5132 | 12016 | s_mips_frame is used so that we can set the PDR information correctly. |
bdaaa2e1 | 12017 | We can't use the ecoff routines because they make reference to the ecoff |
252b5132 RH |
12018 | symbol table (in the mdebug section). */ |
12019 | ||
12020 | static void | |
12021 | s_mips_frame (ignore) | |
2b3c5a5d | 12022 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
12023 | { |
12024 | #ifdef MIPS_STABS_ELF | |
12025 | ||
12026 | long val; | |
12027 | ||
beae10d5 | 12028 | if (cur_proc_ptr == (procS *) NULL) |
252b5132 RH |
12029 | { |
12030 | as_warn (_(".frame outside of .ent")); | |
12031 | demand_empty_rest_of_line (); | |
12032 | return; | |
12033 | } | |
12034 | ||
12035 | cur_proc_ptr->frame_reg = tc_get_register (1); | |
12036 | ||
12037 | SKIP_WHITESPACE (); | |
12038 | if (*input_line_pointer++ != ',' | |
12039 | || get_absolute_expression_and_terminator (&val) != ',') | |
12040 | { | |
12041 | as_warn (_("Bad .frame directive")); | |
12042 | --input_line_pointer; | |
12043 | demand_empty_rest_of_line (); | |
12044 | return; | |
12045 | } | |
12046 | ||
12047 | cur_proc_ptr->frame_offset = val; | |
12048 | cur_proc_ptr->pc_reg = tc_get_register (0); | |
12049 | ||
12050 | demand_empty_rest_of_line (); | |
12051 | #else | |
12052 | s_ignore (ignore); | |
12053 | #endif /* MIPS_STABS_ELF */ | |
12054 | } | |
12055 | ||
bdaaa2e1 KH |
12056 | /* The .fmask and .mask directives. If the mdebug section is present |
12057 | (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For | |
252b5132 | 12058 | embedded targets, s_mips_mask is used so that we can set the PDR |
bdaaa2e1 | 12059 | information correctly. We can't use the ecoff routines because they |
252b5132 RH |
12060 | make reference to the ecoff symbol table (in the mdebug section). */ |
12061 | ||
12062 | static void | |
12063 | s_mips_mask (reg_type) | |
12064 | char reg_type; | |
12065 | { | |
12066 | #ifdef MIPS_STABS_ELF | |
12067 | long mask, off; | |
bdaaa2e1 | 12068 | |
252b5132 RH |
12069 | if (cur_proc_ptr == (procS *) NULL) |
12070 | { | |
12071 | as_warn (_(".mask/.fmask outside of .ent")); | |
12072 | demand_empty_rest_of_line (); | |
12073 | return; | |
12074 | } | |
12075 | ||
12076 | if (get_absolute_expression_and_terminator (&mask) != ',') | |
12077 | { | |
12078 | as_warn (_("Bad .mask/.fmask directive")); | |
12079 | --input_line_pointer; | |
12080 | demand_empty_rest_of_line (); | |
12081 | return; | |
12082 | } | |
12083 | ||
12084 | off = get_absolute_expression (); | |
12085 | ||
12086 | if (reg_type == 'F') | |
12087 | { | |
12088 | cur_proc_ptr->fpreg_mask = mask; | |
12089 | cur_proc_ptr->fpreg_offset = off; | |
12090 | } | |
12091 | else | |
12092 | { | |
12093 | cur_proc_ptr->reg_mask = mask; | |
12094 | cur_proc_ptr->reg_offset = off; | |
12095 | } | |
12096 | ||
12097 | demand_empty_rest_of_line (); | |
12098 | #else | |
12099 | s_ignore (reg_type); | |
12100 | #endif /* MIPS_STABS_ELF */ | |
12101 | } | |
12102 | ||
12103 | /* The .loc directive. */ | |
12104 | ||
12105 | #if 0 | |
12106 | static void | |
12107 | s_loc (x) | |
12108 | int x; | |
12109 | { | |
12110 | symbolS *symbolP; | |
12111 | int lineno; | |
12112 | int addroff; | |
12113 | ||
12114 | assert (now_seg == text_section); | |
12115 | ||
12116 | lineno = get_number (); | |
12117 | addroff = frag_now_fix (); | |
12118 | ||
12119 | symbolP = symbol_new ("", N_SLINE, addroff, frag_now); | |
12120 | S_SET_TYPE (symbolP, N_SLINE); | |
12121 | S_SET_OTHER (symbolP, 0); | |
12122 | S_SET_DESC (symbolP, lineno); | |
12123 | symbolP->sy_segment = now_seg; | |
12124 | } | |
12125 | #endif | |
e7af610e NC |
12126 | |
12127 | /* CPU name/ISA/number mapping table. | |
12128 | ||
12129 | Entries are grouped by type. The first matching CPU or ISA entry | |
12130 | gets chosen by CPU or ISA, so it should be the 'canonical' name | |
12131 | for that type. Entries after that within the type are sorted | |
12132 | alphabetically. | |
12133 | ||
12134 | Case is ignored in comparison, so put the canonical entry in the | |
12135 | appropriate case but everything else in lower case to ease eye pain. */ | |
e972090a NC |
12136 | static const struct mips_cpu_info mips_cpu_info_table[] = |
12137 | { | |
e7af610e NC |
12138 | /* MIPS1 ISA */ |
12139 | { "MIPS1", 1, ISA_MIPS1, CPU_R3000, }, | |
12140 | { "mips", 1, ISA_MIPS1, CPU_R3000, }, | |
12141 | ||
12142 | /* MIPS2 ISA */ | |
12143 | { "MIPS2", 1, ISA_MIPS2, CPU_R6000, }, | |
12144 | ||
12145 | /* MIPS3 ISA */ | |
12146 | { "MIPS3", 1, ISA_MIPS3, CPU_R4000, }, | |
12147 | ||
12148 | /* MIPS4 ISA */ | |
12149 | { "MIPS4", 1, ISA_MIPS4, CPU_R8000, }, | |
12150 | ||
84ea6cf2 NC |
12151 | /* MIPS5 ISA */ |
12152 | { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, }, | |
12153 | { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, }, | |
12154 | ||
e7af610e NC |
12155 | /* MIPS32 ISA */ |
12156 | { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, }, | |
3c02b2ab | 12157 | { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, }, |
e7af610e | 12158 | { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, }, |
3c02b2ab EC |
12159 | { "4kc", 0, ISA_MIPS32, CPU_MIPS32, }, |
12160 | { "4km", 0, ISA_MIPS32, CPU_MIPS32, }, | |
12161 | { "4kp", 0, ISA_MIPS32, CPU_MIPS32, }, | |
12162 | ||
12163 | /* For historical reasons. */ | |
12164 | { "MIPS64", 1, ISA_MIPS3, CPU_R4000, }, | |
e7af610e | 12165 | |
84ea6cf2 | 12166 | /* MIPS64 ISA */ |
3c02b2ab | 12167 | { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, }, |
84ea6cf2 | 12168 | { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, }, |
3c02b2ab EC |
12169 | { "5kc", 0, ISA_MIPS64, CPU_MIPS64, }, |
12170 | { "20kc", 0, ISA_MIPS64, CPU_MIPS64, }, | |
e7af610e NC |
12171 | |
12172 | /* R2000 CPU */ | |
12173 | { "R2000", 0, ISA_MIPS1, CPU_R2000, }, | |
12174 | { "2000", 0, ISA_MIPS1, CPU_R2000, }, | |
12175 | { "2k", 0, ISA_MIPS1, CPU_R2000, }, | |
12176 | { "r2k", 0, ISA_MIPS1, CPU_R2000, }, | |
12177 | ||
12178 | /* R3000 CPU */ | |
12179 | { "R3000", 0, ISA_MIPS1, CPU_R3000, }, | |
12180 | { "3000", 0, ISA_MIPS1, CPU_R3000, }, | |
12181 | { "3k", 0, ISA_MIPS1, CPU_R3000, }, | |
12182 | { "r3k", 0, ISA_MIPS1, CPU_R3000, }, | |
12183 | ||
12184 | /* TX3900 CPU */ | |
12185 | { "R3900", 0, ISA_MIPS1, CPU_R3900, }, | |
12186 | { "3900", 0, ISA_MIPS1, CPU_R3900, }, | |
e972090a | 12187 | { "mipstx39", 0, ISA_MIPS1, CPU_R3900, }, |
e7af610e NC |
12188 | |
12189 | /* R4000 CPU */ | |
12190 | { "R4000", 0, ISA_MIPS3, CPU_R4000, }, | |
12191 | { "4000", 0, ISA_MIPS3, CPU_R4000, }, | |
12192 | { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */ | |
12193 | { "r4k", 0, ISA_MIPS3, CPU_R4000, }, | |
12194 | ||
12195 | /* R4010 CPU */ | |
12196 | { "R4010", 0, ISA_MIPS2, CPU_R4010, }, | |
12197 | { "4010", 0, ISA_MIPS2, CPU_R4010, }, | |
12198 | ||
12199 | /* R4400 CPU */ | |
12200 | { "R4400", 0, ISA_MIPS3, CPU_R4400, }, | |
12201 | { "4400", 0, ISA_MIPS3, CPU_R4400, }, | |
12202 | ||
12203 | /* R4600 CPU */ | |
12204 | { "R4600", 0, ISA_MIPS3, CPU_R4600, }, | |
12205 | { "4600", 0, ISA_MIPS3, CPU_R4600, }, | |
12206 | { "mips64orion", 0, ISA_MIPS3, CPU_R4600, }, | |
12207 | { "orion", 0, ISA_MIPS3, CPU_R4600, }, | |
12208 | ||
12209 | /* R4650 CPU */ | |
12210 | { "R4650", 0, ISA_MIPS3, CPU_R4650, }, | |
12211 | { "4650", 0, ISA_MIPS3, CPU_R4650, }, | |
12212 | ||
12213 | /* R6000 CPU */ | |
12214 | { "R6000", 0, ISA_MIPS2, CPU_R6000, }, | |
12215 | { "6000", 0, ISA_MIPS2, CPU_R6000, }, | |
12216 | { "6k", 0, ISA_MIPS2, CPU_R6000, }, | |
12217 | { "r6k", 0, ISA_MIPS2, CPU_R6000, }, | |
12218 | ||
12219 | /* R8000 CPU */ | |
12220 | { "R8000", 0, ISA_MIPS4, CPU_R8000, }, | |
12221 | { "8000", 0, ISA_MIPS4, CPU_R8000, }, | |
12222 | { "8k", 0, ISA_MIPS4, CPU_R8000, }, | |
12223 | { "r8k", 0, ISA_MIPS4, CPU_R8000, }, | |
12224 | ||
12225 | /* R10000 CPU */ | |
12226 | { "R10000", 0, ISA_MIPS4, CPU_R10000, }, | |
12227 | { "10000", 0, ISA_MIPS4, CPU_R10000, }, | |
12228 | { "10k", 0, ISA_MIPS4, CPU_R10000, }, | |
12229 | { "r10k", 0, ISA_MIPS4, CPU_R10000, }, | |
12230 | ||
d1cf510e NC |
12231 | /* R12000 CPU */ |
12232 | { "R12000", 0, ISA_MIPS4, CPU_R12000, }, | |
12233 | { "12000", 0, ISA_MIPS4, CPU_R12000, }, | |
12234 | { "12k", 0, ISA_MIPS4, CPU_R12000, }, | |
12235 | { "r12k", 0, ISA_MIPS4, CPU_R12000, }, | |
12236 | ||
e7af610e NC |
12237 | /* VR4100 CPU */ |
12238 | { "VR4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
12239 | { "4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
12240 | { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
12241 | { "r4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
12242 | ||
12243 | /* VR4111 CPU */ | |
12244 | { "VR4111", 0, ISA_MIPS3, CPU_R4111, }, | |
12245 | { "4111", 0, ISA_MIPS3, CPU_R4111, }, | |
12246 | { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, }, | |
12247 | { "r4111", 0, ISA_MIPS3, CPU_R4111, }, | |
12248 | ||
12249 | /* VR4300 CPU */ | |
12250 | { "VR4300", 0, ISA_MIPS3, CPU_R4300, }, | |
12251 | { "4300", 0, ISA_MIPS3, CPU_R4300, }, | |
12252 | { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, }, | |
12253 | { "r4300", 0, ISA_MIPS3, CPU_R4300, }, | |
12254 | ||
12255 | /* VR5000 CPU */ | |
12256 | { "VR5000", 0, ISA_MIPS4, CPU_R5000, }, | |
12257 | { "5000", 0, ISA_MIPS4, CPU_R5000, }, | |
12258 | { "5k", 0, ISA_MIPS4, CPU_R5000, }, | |
12259 | { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, }, | |
12260 | { "r5000", 0, ISA_MIPS4, CPU_R5000, }, | |
12261 | { "r5200", 0, ISA_MIPS4, CPU_R5000, }, | |
18ae5d72 | 12262 | { "rm5200", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 12263 | { "r5230", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 12264 | { "rm5230", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 12265 | { "r5231", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 12266 | { "rm5231", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 12267 | { "r5261", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 12268 | { "rm5261", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 12269 | { "r5721", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 12270 | { "rm5721", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e NC |
12271 | { "r5k", 0, ISA_MIPS4, CPU_R5000, }, |
12272 | { "r7000", 0, ISA_MIPS4, CPU_R5000, }, | |
12273 | ||
c6c98b38 NC |
12274 | /* SiByte SB-1 CPU */ |
12275 | { "SB-1", 0, ISA_MIPS64, CPU_SB1, }, | |
e972090a | 12276 | { "sb-1250", 0, ISA_MIPS64, CPU_SB1, }, |
c6c98b38 NC |
12277 | { "sb1", 0, ISA_MIPS64, CPU_SB1, }, |
12278 | { "sb1250", 0, ISA_MIPS64, CPU_SB1, }, | |
12279 | ||
beae10d5 | 12280 | /* End marker. */ |
e7af610e NC |
12281 | { NULL, 0, 0, 0, }, |
12282 | }; | |
12283 | ||
12284 | static const struct mips_cpu_info * | |
12285 | mips_cpu_info_from_name (name) | |
12286 | const char *name; | |
12287 | { | |
12288 | int i; | |
12289 | ||
12290 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
beae10d5 | 12291 | if (strcasecmp (name, mips_cpu_info_table[i].name) == 0) |
e7af610e NC |
12292 | return (&mips_cpu_info_table[i]); |
12293 | ||
e972090a | 12294 | return NULL; |
e7af610e NC |
12295 | } |
12296 | ||
12297 | static const struct mips_cpu_info * | |
12298 | mips_cpu_info_from_isa (isa) | |
12299 | int isa; | |
12300 | { | |
12301 | int i; | |
12302 | ||
12303 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
12304 | if (mips_cpu_info_table[i].is_isa | |
12305 | && isa == mips_cpu_info_table[i].isa) | |
12306 | return (&mips_cpu_info_table[i]); | |
12307 | ||
e972090a | 12308 | return NULL; |
e7af610e NC |
12309 | } |
12310 | ||
12311 | static const struct mips_cpu_info * | |
12312 | mips_cpu_info_from_cpu (cpu) | |
12313 | int cpu; | |
12314 | { | |
12315 | int i; | |
12316 | ||
12317 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
12318 | if (!mips_cpu_info_table[i].is_isa | |
12319 | && cpu == mips_cpu_info_table[i].cpu) | |
12320 | return (&mips_cpu_info_table[i]); | |
12321 | ||
e972090a | 12322 | return NULL; |
e7af610e | 12323 | } |