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 | ||
a325df1d TS |
116 | /* The ABI to use. */ |
117 | enum mips_abi_level | |
118 | { | |
119 | NO_ABI = 0, | |
120 | O32_ABI, | |
121 | O64_ABI, | |
122 | N32_ABI, | |
123 | N64_ABI, | |
124 | EABI_ABI | |
125 | }; | |
126 | ||
127 | /* MIPS ABI we are using for this output file. */ | |
128 | static enum mips_abi_level file_mips_abi = NO_ABI; | |
129 | ||
252b5132 RH |
130 | /* This is the set of options which may be modified by the .set |
131 | pseudo-op. We use a struct so that .set push and .set pop are more | |
132 | reliable. */ | |
133 | ||
e972090a NC |
134 | struct mips_set_options |
135 | { | |
252b5132 RH |
136 | /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 |
137 | if it has not been initialized. Changed by `.set mipsN', and the | |
138 | -mipsN command line option, and the default CPU. */ | |
139 | int isa; | |
140 | /* Whether we are assembling for the mips16 processor. 0 if we are | |
141 | not, 1 if we are, and -1 if the value has not been initialized. | |
142 | Changed by `.set mips16' and `.set nomips16', and the -mips16 and | |
143 | -nomips16 command line options, and the default CPU. */ | |
144 | int mips16; | |
145 | /* Non-zero if we should not reorder instructions. Changed by `.set | |
146 | reorder' and `.set noreorder'. */ | |
147 | int noreorder; | |
148 | /* Non-zero if we should not permit the $at ($1) register to be used | |
149 | in instructions. Changed by `.set at' and `.set noat'. */ | |
150 | int noat; | |
151 | /* Non-zero if we should warn when a macro instruction expands into | |
152 | more than one machine instruction. Changed by `.set nomacro' and | |
153 | `.set macro'. */ | |
154 | int warn_about_macros; | |
155 | /* Non-zero if we should not move instructions. Changed by `.set | |
156 | move', `.set volatile', `.set nomove', and `.set novolatile'. */ | |
157 | int nomove; | |
158 | /* Non-zero if we should not optimize branches by moving the target | |
159 | of the branch into the delay slot. Actually, we don't perform | |
160 | this optimization anyhow. Changed by `.set bopt' and `.set | |
161 | nobopt'. */ | |
162 | int nobopt; | |
163 | /* Non-zero if we should not autoextend mips16 instructions. | |
164 | Changed by `.set autoextend' and `.set noautoextend'. */ | |
165 | int noautoextend; | |
a325df1d TS |
166 | /* Restrict general purpose registers and floating point registers |
167 | to 32 bit. This is initially determined when -mgp32 or -mfp32 | |
168 | is passed but can changed if the assembler code uses .set mipsN. */ | |
169 | int gp32; | |
170 | int fp32; | |
171 | /* The ABI currently in use. This is changed by .set mipsN to loosen | |
172 | restrictions and doesn't affect the whole file. */ | |
173 | enum mips_abi_level abi; | |
252b5132 RH |
174 | }; |
175 | ||
a325df1d TS |
176 | /* True if -mgp32 was passed. */ |
177 | static int file_mips_gp32 = 0; | |
178 | ||
179 | /* True if -mfp32 was passed. */ | |
180 | static int file_mips_fp32 = 0; | |
181 | ||
252b5132 | 182 | /* This is the struct we use to hold the current set of options. Note |
e7af610e NC |
183 | that we must set the isa field to ISA_UNKNOWN and the mips16 field to |
184 | -1 to indicate that they have not been initialized. */ | |
252b5132 | 185 | |
e972090a NC |
186 | static struct mips_set_options mips_opts = |
187 | { | |
a325df1d | 188 | ISA_UNKNOWN, -1, 0, 0, 0, 0, 0, 0, 0, 0, NO_ABI |
e7af610e | 189 | }; |
252b5132 RH |
190 | |
191 | /* These variables are filled in with the masks of registers used. | |
192 | The object format code reads them and puts them in the appropriate | |
193 | place. */ | |
194 | unsigned long mips_gprmask; | |
195 | unsigned long mips_cprmask[4]; | |
196 | ||
197 | /* MIPS ISA we are using for this output file. */ | |
e7af610e | 198 | static int file_mips_isa = ISA_UNKNOWN; |
252b5132 | 199 | |
ec68c924 | 200 | /* The argument of the -mcpu= flag. Historical for code generation. */ |
e7af610e | 201 | static int mips_cpu = CPU_UNKNOWN; |
252b5132 | 202 | |
ec68c924 EC |
203 | /* The argument of the -march= flag. The architecture we are assembling. */ |
204 | static int mips_arch = CPU_UNKNOWN; | |
205 | ||
206 | /* The argument of the -mtune= flag. The architecture for which we | |
207 | are optimizing. */ | |
208 | static int mips_tune = CPU_UNKNOWN; | |
209 | ||
2f4dcb11 | 210 | /* Whether we should mark the file EABI64 or EABI32. */ |
252b5132 RH |
211 | static int mips_eabi64 = 0; |
212 | ||
213 | /* If they asked for mips1 or mips2 and a cpu that is | |
bdaaa2e1 | 214 | mips3 or greater, then mark the object file 32BITMODE. */ |
252b5132 RH |
215 | static int mips_32bitmode = 0; |
216 | ||
9ce8a5dd GRK |
217 | /* Some ISA's have delay slots for instructions which read or write |
218 | from a coprocessor (eg. mips1-mips3); some don't (eg mips4). | |
bdaaa2e1 | 219 | Return true if instructions marked INSN_LOAD_COPROC_DELAY, |
9ce8a5dd GRK |
220 | INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a |
221 | delay slot in this ISA. The uses of this macro assume that any | |
222 | ISA that has delay slots for one of these, has them for all. They | |
223 | also assume that ISAs which don't have delays for these insns, don't | |
bdaaa2e1 | 224 | have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */ |
9ce8a5dd | 225 | #define ISA_HAS_COPROC_DELAYS(ISA) ( \ |
e7af610e NC |
226 | (ISA) == ISA_MIPS1 \ |
227 | || (ISA) == ISA_MIPS2 \ | |
228 | || (ISA) == ISA_MIPS3 \ | |
9ce8a5dd GRK |
229 | ) |
230 | ||
bdaaa2e1 | 231 | /* Return true if ISA supports 64 bit gp register instructions. */ |
9ce8a5dd | 232 | #define ISA_HAS_64BIT_REGS(ISA) ( \ |
e7af610e NC |
233 | (ISA) == ISA_MIPS3 \ |
234 | || (ISA) == ISA_MIPS4 \ | |
84ea6cf2 | 235 | || (ISA) == ISA_MIPS5 \ |
d1cf510e | 236 | || (ISA) == ISA_MIPS64 \ |
9ce8a5dd GRK |
237 | ) |
238 | ||
e013f690 | 239 | #define HAVE_32BIT_GPRS \ |
a325df1d TS |
240 | (mips_opts.gp32 \ |
241 | || mips_opts.abi == O32_ABI \ | |
e013f690 | 242 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
ca4e0257 | 243 | |
e013f690 | 244 | #define HAVE_32BIT_FPRS \ |
a325df1d TS |
245 | (mips_opts.fp32 \ |
246 | || mips_opts.abi == O32_ABI \ | |
e013f690 | 247 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
ca4e0257 RS |
248 | |
249 | #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS) | |
250 | #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS) | |
251 | ||
a325df1d | 252 | #define HAVE_NEWABI (mips_opts.abi == N32_ABI || mips_opts.abi == N64_ABI) |
e013f690 | 253 | |
a325df1d | 254 | #define HAVE_64BIT_OBJECTS (mips_opts.abi == N64_ABI) |
e013f690 TS |
255 | |
256 | /* We can only have 64bit addresses if the object file format | |
257 | supports it. */ | |
afdbd6d0 CD |
258 | #define HAVE_32BIT_ADDRESSES \ |
259 | (HAVE_32BIT_GPRS \ | |
260 | || ((bfd_arch_bits_per_address (stdoutput) == 32 \ | |
261 | || ! HAVE_64BIT_OBJECTS) \ | |
262 | && mips_pic != EMBEDDED_PIC)) | |
e013f690 TS |
263 | |
264 | #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES) | |
ca4e0257 | 265 | |
bdaaa2e1 | 266 | /* Whether the processor uses hardware interlocks to protect |
252b5132 | 267 | reads from the HI and LO registers, and thus does not |
ec68c924 | 268 | require nops to be inserted. */ |
252b5132 | 269 | |
ec68c924 | 270 | #define hilo_interlocks (mips_arch == CPU_R4010 \ |
0a758a12 | 271 | || mips_arch == CPU_SB1 \ |
252b5132 RH |
272 | ) |
273 | ||
274 | /* Whether the processor uses hardware interlocks to protect reads | |
275 | from the GPRs, and thus does not require nops to be inserted. */ | |
276 | #define gpr_interlocks \ | |
e7af610e | 277 | (mips_opts.isa != ISA_MIPS1 \ |
ec68c924 | 278 | || mips_arch == CPU_R3900) |
252b5132 RH |
279 | |
280 | /* As with other "interlocks" this is used by hardware that has FP | |
281 | (co-processor) interlocks. */ | |
bdaaa2e1 | 282 | /* Itbl support may require additional care here. */ |
ec68c924 | 283 | #define cop_interlocks (mips_arch == CPU_R4300 \ |
0a758a12 | 284 | || mips_arch == CPU_SB1 \ |
252b5132 RH |
285 | ) |
286 | ||
6b76fefe CM |
287 | /* Is this a mfhi or mflo instruction? */ |
288 | #define MF_HILO_INSN(PINFO) \ | |
289 | ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO)) | |
290 | ||
252b5132 RH |
291 | /* MIPS PIC level. */ |
292 | ||
e972090a NC |
293 | enum mips_pic_level |
294 | { | |
252b5132 RH |
295 | /* Do not generate PIC code. */ |
296 | NO_PIC, | |
297 | ||
298 | /* Generate PIC code as in Irix 4. This is not implemented, and I'm | |
299 | not sure what it is supposed to do. */ | |
300 | IRIX4_PIC, | |
301 | ||
302 | /* Generate PIC code as in the SVR4 MIPS ABI. */ | |
303 | SVR4_PIC, | |
304 | ||
305 | /* Generate PIC code without using a global offset table: the data | |
306 | segment has a maximum size of 64K, all data references are off | |
307 | the $gp register, and all text references are PC relative. This | |
308 | is used on some embedded systems. */ | |
309 | EMBEDDED_PIC | |
310 | }; | |
311 | ||
312 | static enum mips_pic_level mips_pic; | |
313 | ||
39c0a331 L |
314 | /* Warn about all NOPS that the assembler generates. */ |
315 | static int warn_nops = 0; | |
316 | ||
252b5132 RH |
317 | /* 1 if we should generate 32 bit offsets from the GP register in |
318 | SVR4_PIC mode. Currently has no meaning in other modes. */ | |
319 | static int mips_big_got; | |
320 | ||
321 | /* 1 if trap instructions should used for overflow rather than break | |
322 | instructions. */ | |
323 | static int mips_trap; | |
324 | ||
119d663a | 325 | /* 1 if double width floating point constants should not be constructed |
b6ff326e | 326 | by assembling two single width halves into two single width floating |
119d663a NC |
327 | point registers which just happen to alias the double width destination |
328 | register. On some architectures this aliasing can be disabled by a bit | |
d547a75e | 329 | in the status register, and the setting of this bit cannot be determined |
119d663a NC |
330 | automatically at assemble time. */ |
331 | static int mips_disable_float_construction; | |
332 | ||
252b5132 RH |
333 | /* Non-zero if any .set noreorder directives were used. */ |
334 | ||
335 | static int mips_any_noreorder; | |
336 | ||
6b76fefe CM |
337 | /* Non-zero if nops should be inserted when the register referenced in |
338 | an mfhi/mflo instruction is read in the next two instructions. */ | |
339 | static int mips_7000_hilo_fix; | |
340 | ||
252b5132 | 341 | /* The size of the small data section. */ |
156c2f8b | 342 | static unsigned int g_switch_value = 8; |
252b5132 RH |
343 | /* Whether the -G option was used. */ |
344 | static int g_switch_seen = 0; | |
345 | ||
346 | #define N_RMASK 0xc4 | |
347 | #define N_VFP 0xd4 | |
348 | ||
349 | /* If we can determine in advance that GP optimization won't be | |
350 | possible, we can skip the relaxation stuff that tries to produce | |
351 | GP-relative references. This makes delay slot optimization work | |
352 | better. | |
353 | ||
354 | This function can only provide a guess, but it seems to work for | |
fba2b7f9 GK |
355 | gcc output. It needs to guess right for gcc, otherwise gcc |
356 | will put what it thinks is a GP-relative instruction in a branch | |
357 | delay slot. | |
252b5132 RH |
358 | |
359 | I don't know if a fix is needed for the SVR4_PIC mode. I've only | |
360 | fixed it for the non-PIC mode. KR 95/04/07 */ | |
361 | static int nopic_need_relax PARAMS ((symbolS *, int)); | |
362 | ||
363 | /* handle of the OPCODE hash table */ | |
364 | static struct hash_control *op_hash = NULL; | |
365 | ||
366 | /* The opcode hash table we use for the mips16. */ | |
367 | static struct hash_control *mips16_op_hash = NULL; | |
368 | ||
369 | /* This array holds the chars that always start a comment. If the | |
370 | pre-processor is disabled, these aren't very useful */ | |
371 | const char comment_chars[] = "#"; | |
372 | ||
373 | /* This array holds the chars that only start a comment at the beginning of | |
374 | a line. If the line seems to have the form '# 123 filename' | |
375 | .line and .file directives will appear in the pre-processed output */ | |
376 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
377 | first line of the input file. This is because the compiler outputs | |
bdaaa2e1 | 378 | #NO_APP at the beginning of its output. */ |
252b5132 RH |
379 | /* Also note that C style comments are always supported. */ |
380 | const char line_comment_chars[] = "#"; | |
381 | ||
bdaaa2e1 | 382 | /* This array holds machine specific line separator characters. */ |
63a0b638 | 383 | const char line_separator_chars[] = ";"; |
252b5132 RH |
384 | |
385 | /* Chars that can be used to separate mant from exp in floating point nums */ | |
386 | const char EXP_CHARS[] = "eE"; | |
387 | ||
388 | /* Chars that mean this number is a floating point constant */ | |
389 | /* As in 0f12.456 */ | |
390 | /* or 0d1.2345e12 */ | |
391 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
392 | ||
393 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
394 | changed in read.c . Ideally it shouldn't have to know about it at all, | |
395 | but nothing is ideal around here. | |
396 | */ | |
397 | ||
398 | static char *insn_error; | |
399 | ||
400 | static int auto_align = 1; | |
401 | ||
402 | /* When outputting SVR4 PIC code, the assembler needs to know the | |
403 | offset in the stack frame from which to restore the $gp register. | |
404 | This is set by the .cprestore pseudo-op, and saved in this | |
405 | variable. */ | |
406 | static offsetT mips_cprestore_offset = -1; | |
407 | ||
6478892d TS |
408 | /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some |
409 | more optimizations, it can use a register value instead of a memory-saved | |
410 | offset and even an other than GP as global pointer. */ | |
411 | static offsetT mips_cpreturn_offset = -1; | |
412 | static int mips_cpreturn_register = -1; | |
413 | static int mips_gp_register = GP; | |
414 | ||
252b5132 RH |
415 | /* This is the register which holds the stack frame, as set by the |
416 | .frame pseudo-op. This is needed to implement .cprestore. */ | |
417 | static int mips_frame_reg = SP; | |
418 | ||
419 | /* To output NOP instructions correctly, we need to keep information | |
420 | about the previous two instructions. */ | |
421 | ||
422 | /* Whether we are optimizing. The default value of 2 means to remove | |
423 | unneeded NOPs and swap branch instructions when possible. A value | |
424 | of 1 means to not swap branches. A value of 0 means to always | |
425 | insert NOPs. */ | |
426 | static int mips_optimize = 2; | |
427 | ||
428 | /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is | |
429 | equivalent to seeing no -g option at all. */ | |
430 | static int mips_debug = 0; | |
431 | ||
432 | /* The previous instruction. */ | |
433 | static struct mips_cl_insn prev_insn; | |
434 | ||
435 | /* The instruction before prev_insn. */ | |
436 | static struct mips_cl_insn prev_prev_insn; | |
437 | ||
438 | /* If we don't want information for prev_insn or prev_prev_insn, we | |
439 | point the insn_mo field at this dummy integer. */ | |
43841e91 | 440 | static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 }; |
252b5132 RH |
441 | |
442 | /* Non-zero if prev_insn is valid. */ | |
443 | static int prev_insn_valid; | |
444 | ||
445 | /* The frag for the previous instruction. */ | |
446 | static struct frag *prev_insn_frag; | |
447 | ||
448 | /* The offset into prev_insn_frag for the previous instruction. */ | |
449 | static long prev_insn_where; | |
450 | ||
451 | /* The reloc type for the previous instruction, if any. */ | |
f6688943 | 452 | static bfd_reloc_code_real_type prev_insn_reloc_type[3]; |
252b5132 RH |
453 | |
454 | /* The reloc for the previous instruction, if any. */ | |
f6688943 | 455 | static fixS *prev_insn_fixp[3]; |
252b5132 RH |
456 | |
457 | /* Non-zero if the previous instruction was in a delay slot. */ | |
458 | static int prev_insn_is_delay_slot; | |
459 | ||
460 | /* Non-zero if the previous instruction was in a .set noreorder. */ | |
461 | static int prev_insn_unreordered; | |
462 | ||
463 | /* Non-zero if the previous instruction uses an extend opcode (if | |
464 | mips16). */ | |
465 | static int prev_insn_extended; | |
466 | ||
467 | /* Non-zero if the previous previous instruction was in a .set | |
468 | noreorder. */ | |
469 | static int prev_prev_insn_unreordered; | |
470 | ||
471 | /* If this is set, it points to a frag holding nop instructions which | |
472 | were inserted before the start of a noreorder section. If those | |
473 | nops turn out to be unnecessary, the size of the frag can be | |
474 | decreased. */ | |
475 | static fragS *prev_nop_frag; | |
476 | ||
477 | /* The number of nop instructions we created in prev_nop_frag. */ | |
478 | static int prev_nop_frag_holds; | |
479 | ||
480 | /* The number of nop instructions that we know we need in | |
bdaaa2e1 | 481 | prev_nop_frag. */ |
252b5132 RH |
482 | static int prev_nop_frag_required; |
483 | ||
484 | /* The number of instructions we've seen since prev_nop_frag. */ | |
485 | static int prev_nop_frag_since; | |
486 | ||
487 | /* For ECOFF and ELF, relocations against symbols are done in two | |
488 | parts, with a HI relocation and a LO relocation. Each relocation | |
489 | has only 16 bits of space to store an addend. This means that in | |
490 | order for the linker to handle carries correctly, it must be able | |
491 | to locate both the HI and the LO relocation. This means that the | |
492 | relocations must appear in order in the relocation table. | |
493 | ||
494 | In order to implement this, we keep track of each unmatched HI | |
495 | relocation. We then sort them so that they immediately precede the | |
bdaaa2e1 | 496 | corresponding LO relocation. */ |
252b5132 | 497 | |
e972090a NC |
498 | struct mips_hi_fixup |
499 | { | |
252b5132 RH |
500 | /* Next HI fixup. */ |
501 | struct mips_hi_fixup *next; | |
502 | /* This fixup. */ | |
503 | fixS *fixp; | |
504 | /* The section this fixup is in. */ | |
505 | segT seg; | |
506 | }; | |
507 | ||
508 | /* The list of unmatched HI relocs. */ | |
509 | ||
510 | static struct mips_hi_fixup *mips_hi_fixup_list; | |
511 | ||
512 | /* Map normal MIPS register numbers to mips16 register numbers. */ | |
513 | ||
514 | #define X ILLEGAL_REG | |
e972090a NC |
515 | static const int mips32_to_16_reg_map[] = |
516 | { | |
252b5132 RH |
517 | X, X, 2, 3, 4, 5, 6, 7, |
518 | X, X, X, X, X, X, X, X, | |
519 | 0, 1, X, X, X, X, X, X, | |
520 | X, X, X, X, X, X, X, X | |
521 | }; | |
522 | #undef X | |
523 | ||
524 | /* Map mips16 register numbers to normal MIPS register numbers. */ | |
525 | ||
e972090a NC |
526 | static const unsigned int mips16_to_32_reg_map[] = |
527 | { | |
252b5132 RH |
528 | 16, 17, 2, 3, 4, 5, 6, 7 |
529 | }; | |
530 | \f | |
531 | /* Since the MIPS does not have multiple forms of PC relative | |
532 | instructions, we do not have to do relaxing as is done on other | |
533 | platforms. However, we do have to handle GP relative addressing | |
534 | correctly, which turns out to be a similar problem. | |
535 | ||
536 | Every macro that refers to a symbol can occur in (at least) two | |
537 | forms, one with GP relative addressing and one without. For | |
538 | example, loading a global variable into a register generally uses | |
539 | a macro instruction like this: | |
540 | lw $4,i | |
541 | If i can be addressed off the GP register (this is true if it is in | |
542 | the .sbss or .sdata section, or if it is known to be smaller than | |
543 | the -G argument) this will generate the following instruction: | |
544 | lw $4,i($gp) | |
545 | This instruction will use a GPREL reloc. If i can not be addressed | |
546 | off the GP register, the following instruction sequence will be used: | |
547 | lui $at,i | |
548 | lw $4,i($at) | |
549 | In this case the first instruction will have a HI16 reloc, and the | |
550 | second reloc will have a LO16 reloc. Both relocs will be against | |
551 | the symbol i. | |
552 | ||
553 | The issue here is that we may not know whether i is GP addressable | |
554 | until after we see the instruction that uses it. Therefore, we | |
555 | want to be able to choose the final instruction sequence only at | |
556 | the end of the assembly. This is similar to the way other | |
557 | platforms choose the size of a PC relative instruction only at the | |
558 | end of assembly. | |
559 | ||
560 | When generating position independent code we do not use GP | |
561 | addressing in quite the same way, but the issue still arises as | |
562 | external symbols and local symbols must be handled differently. | |
563 | ||
564 | We handle these issues by actually generating both possible | |
565 | instruction sequences. The longer one is put in a frag_var with | |
566 | type rs_machine_dependent. We encode what to do with the frag in | |
567 | the subtype field. We encode (1) the number of existing bytes to | |
568 | replace, (2) the number of new bytes to use, (3) the offset from | |
569 | the start of the existing bytes to the first reloc we must generate | |
570 | (that is, the offset is applied from the start of the existing | |
571 | bytes after they are replaced by the new bytes, if any), (4) the | |
572 | offset from the start of the existing bytes to the second reloc, | |
573 | (5) whether a third reloc is needed (the third reloc is always four | |
574 | bytes after the second reloc), and (6) whether to warn if this | |
575 | variant is used (this is sometimes needed if .set nomacro or .set | |
576 | noat is in effect). All these numbers are reasonably small. | |
577 | ||
578 | Generating two instruction sequences must be handled carefully to | |
579 | ensure that delay slots are handled correctly. Fortunately, there | |
580 | are a limited number of cases. When the second instruction | |
581 | sequence is generated, append_insn is directed to maintain the | |
582 | existing delay slot information, so it continues to apply to any | |
583 | code after the second instruction sequence. This means that the | |
584 | second instruction sequence must not impose any requirements not | |
585 | required by the first instruction sequence. | |
586 | ||
587 | These variant frags are then handled in functions called by the | |
588 | machine independent code. md_estimate_size_before_relax returns | |
589 | the final size of the frag. md_convert_frag sets up the final form | |
590 | of the frag. tc_gen_reloc adjust the first reloc and adds a second | |
591 | one if needed. */ | |
592 | #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \ | |
593 | ((relax_substateT) \ | |
594 | (((old) << 23) \ | |
595 | | ((new) << 16) \ | |
596 | | (((reloc1) + 64) << 9) \ | |
597 | | (((reloc2) + 64) << 2) \ | |
598 | | ((reloc3) ? (1 << 1) : 0) \ | |
599 | | ((warn) ? 1 : 0))) | |
600 | #define RELAX_OLD(i) (((i) >> 23) & 0x7f) | |
601 | #define RELAX_NEW(i) (((i) >> 16) & 0x7f) | |
9a41af64 TS |
602 | #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64) |
603 | #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64) | |
252b5132 RH |
604 | #define RELAX_RELOC3(i) (((i) >> 1) & 1) |
605 | #define RELAX_WARN(i) ((i) & 1) | |
606 | ||
607 | /* For mips16 code, we use an entirely different form of relaxation. | |
608 | mips16 supports two versions of most instructions which take | |
609 | immediate values: a small one which takes some small value, and a | |
610 | larger one which takes a 16 bit value. Since branches also follow | |
611 | this pattern, relaxing these values is required. | |
612 | ||
613 | We can assemble both mips16 and normal MIPS code in a single | |
614 | object. Therefore, we need to support this type of relaxation at | |
615 | the same time that we support the relaxation described above. We | |
616 | use the high bit of the subtype field to distinguish these cases. | |
617 | ||
618 | The information we store for this type of relaxation is the | |
619 | argument code found in the opcode file for this relocation, whether | |
620 | the user explicitly requested a small or extended form, and whether | |
621 | the relocation is in a jump or jal delay slot. That tells us the | |
622 | size of the value, and how it should be stored. We also store | |
623 | whether the fragment is considered to be extended or not. We also | |
624 | store whether this is known to be a branch to a different section, | |
625 | whether we have tried to relax this frag yet, and whether we have | |
626 | ever extended a PC relative fragment because of a shift count. */ | |
627 | #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \ | |
628 | (0x80000000 \ | |
629 | | ((type) & 0xff) \ | |
630 | | ((small) ? 0x100 : 0) \ | |
631 | | ((ext) ? 0x200 : 0) \ | |
632 | | ((dslot) ? 0x400 : 0) \ | |
633 | | ((jal_dslot) ? 0x800 : 0)) | |
634 | #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0) | |
635 | #define RELAX_MIPS16_TYPE(i) ((i) & 0xff) | |
636 | #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0) | |
637 | #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0) | |
638 | #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0) | |
639 | #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0) | |
640 | #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0) | |
641 | #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000) | |
642 | #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000) | |
643 | #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0) | |
644 | #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000) | |
645 | #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000) | |
646 | \f | |
647 | /* Prototypes for static functions. */ | |
648 | ||
649 | #ifdef __STDC__ | |
650 | #define internalError() \ | |
651 | as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__) | |
652 | #else | |
653 | #define internalError() as_fatal (_("MIPS internal Error")); | |
654 | #endif | |
655 | ||
656 | enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG }; | |
657 | ||
658 | static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip, | |
659 | unsigned int reg, enum mips_regclass class)); | |
156c2f8b | 660 | static int reg_needs_delay PARAMS ((unsigned int)); |
252b5132 RH |
661 | static void mips16_mark_labels PARAMS ((void)); |
662 | static void append_insn PARAMS ((char *place, | |
663 | struct mips_cl_insn * ip, | |
664 | expressionS * p, | |
f6688943 | 665 | bfd_reloc_code_real_type *r, |
252b5132 RH |
666 | boolean)); |
667 | static void mips_no_prev_insn PARAMS ((int)); | |
668 | static void mips_emit_delays PARAMS ((boolean)); | |
669 | #ifdef USE_STDARG | |
670 | static void macro_build PARAMS ((char *place, int *counter, expressionS * ep, | |
671 | const char *name, const char *fmt, | |
672 | ...)); | |
673 | #else | |
674 | static void macro_build (); | |
675 | #endif | |
676 | static void mips16_macro_build PARAMS ((char *, int *, expressionS *, | |
677 | const char *, const char *, | |
678 | va_list)); | |
679 | static void macro_build_lui PARAMS ((char *place, int *counter, | |
680 | expressionS * ep, int regnum)); | |
681 | static void set_at PARAMS ((int *counter, int reg, int unsignedp)); | |
682 | static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip, | |
683 | expressionS *)); | |
684 | static void load_register PARAMS ((int *, int, expressionS *, int)); | |
d6bc6245 | 685 | static void load_address PARAMS ((int *, int, expressionS *, int, int *)); |
ea1fb5dc | 686 | static void move_register PARAMS ((int *, int, int)); |
252b5132 RH |
687 | static void macro PARAMS ((struct mips_cl_insn * ip)); |
688 | static void mips16_macro PARAMS ((struct mips_cl_insn * ip)); | |
689 | #ifdef LOSING_COMPILER | |
690 | static void macro2 PARAMS ((struct mips_cl_insn * ip)); | |
691 | #endif | |
692 | static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
693 | static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
694 | static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean, | |
695 | boolean, boolean, unsigned long *, | |
696 | boolean *, unsigned short *)); | |
ad8d3bb3 TS |
697 | static int my_getSmallParser PARAMS ((char **, unsigned int *, int *)); |
698 | static int my_getSmallExpression PARAMS ((expressionS *, char *)); | |
699 | static void my_getExpression PARAMS ((expressionS *, char *)); | |
ae948b86 | 700 | #ifdef OBJ_ELF |
e013f690 | 701 | static int support_64bit_objects PARAMS((void)); |
ae948b86 | 702 | #endif |
252b5132 RH |
703 | static symbolS *get_symbol PARAMS ((void)); |
704 | static void mips_align PARAMS ((int to, int fill, symbolS *label)); | |
705 | static void s_align PARAMS ((int)); | |
706 | static void s_change_sec PARAMS ((int)); | |
707 | static void s_cons PARAMS ((int)); | |
708 | static void s_float_cons PARAMS ((int)); | |
709 | static void s_mips_globl PARAMS ((int)); | |
710 | static void s_option PARAMS ((int)); | |
711 | static void s_mipsset PARAMS ((int)); | |
712 | static void s_abicalls PARAMS ((int)); | |
713 | static void s_cpload PARAMS ((int)); | |
6478892d TS |
714 | static void s_cpsetup PARAMS ((int)); |
715 | static void s_cplocal PARAMS ((int)); | |
252b5132 | 716 | static void s_cprestore PARAMS ((int)); |
6478892d TS |
717 | static void s_cpreturn PARAMS ((int)); |
718 | static void s_gpvalue PARAMS ((int)); | |
252b5132 RH |
719 | static void s_gpword PARAMS ((int)); |
720 | static void s_cpadd PARAMS ((int)); | |
721 | static void s_insn PARAMS ((int)); | |
722 | static void md_obj_begin PARAMS ((void)); | |
723 | static void md_obj_end PARAMS ((void)); | |
724 | static long get_number PARAMS ((void)); | |
725 | static void s_mips_ent PARAMS ((int)); | |
726 | static void s_mips_end PARAMS ((int)); | |
727 | static void s_mips_frame PARAMS ((int)); | |
728 | static void s_mips_mask PARAMS ((int)); | |
729 | static void s_mips_stab PARAMS ((int)); | |
730 | static void s_mips_weakext PARAMS ((int)); | |
731 | static void s_file PARAMS ((int)); | |
732 | static int mips16_extended_frag PARAMS ((fragS *, asection *, long)); | |
e7af610e NC |
733 | static const char *mips_isa_to_str PARAMS ((int)); |
734 | static const char *mips_cpu_to_str PARAMS ((int)); | |
252b5132 | 735 | static int validate_mips_insn PARAMS ((const struct mips_opcode *)); |
e87a0284 | 736 | static void show PARAMS ((FILE *, char *, int *, int *)); |
add55e1f RS |
737 | #ifdef OBJ_ELF |
738 | static int mips_need_elf_addend_fixup PARAMS ((fixS *)); | |
739 | #endif | |
e7af610e | 740 | |
ad8d3bb3 | 741 | /* Return values of my_getSmallExpression(). */ |
fb1b3232 | 742 | |
ad8d3bb3 | 743 | enum small_ex_type |
fb1b3232 TS |
744 | { |
745 | S_EX_NONE = 0, | |
ad8d3bb3 TS |
746 | S_EX_REGISTER, |
747 | ||
748 | /* Direct relocation creation by %percent_op(). */ | |
749 | S_EX_HALF, | |
fb1b3232 | 750 | S_EX_HI, |
ad8d3bb3 TS |
751 | S_EX_LO, |
752 | S_EX_GP_REL, | |
753 | S_EX_GOT, | |
754 | S_EX_CALL16, | |
755 | S_EX_GOT_DISP, | |
756 | S_EX_GOT_PAGE, | |
757 | S_EX_GOT_OFST, | |
758 | S_EX_GOT_HI, | |
759 | S_EX_GOT_LO, | |
760 | S_EX_NEG, | |
fb1b3232 TS |
761 | S_EX_HIGHER, |
762 | S_EX_HIGHEST, | |
ad8d3bb3 TS |
763 | S_EX_CALL_HI, |
764 | S_EX_CALL_LO | |
fb1b3232 TS |
765 | }; |
766 | ||
e7af610e NC |
767 | /* Table and functions used to map between CPU/ISA names, and |
768 | ISA levels, and CPU numbers. */ | |
769 | ||
e972090a NC |
770 | struct mips_cpu_info |
771 | { | |
e7af610e NC |
772 | const char *name; /* CPU or ISA name. */ |
773 | int is_isa; /* Is this an ISA? (If 0, a CPU.) */ | |
774 | int isa; /* ISA level. */ | |
775 | int cpu; /* CPU number (default CPU if ISA). */ | |
776 | }; | |
777 | ||
778 | static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *)); | |
779 | static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int)); | |
780 | static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int)); | |
252b5132 RH |
781 | \f |
782 | /* Pseudo-op table. | |
783 | ||
784 | The following pseudo-ops from the Kane and Heinrich MIPS book | |
785 | should be defined here, but are currently unsupported: .alias, | |
786 | .galive, .gjaldef, .gjrlive, .livereg, .noalias. | |
787 | ||
788 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
789 | specific to the type of debugging information being generated, and | |
790 | should be defined by the object format: .aent, .begin, .bend, | |
791 | .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp, | |
792 | .vreg. | |
793 | ||
794 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
795 | not MIPS CPU specific, but are also not specific to the object file | |
796 | format. This file is probably the best place to define them, but | |
797 | they are not currently supported: .asm0, .endr, .lab, .repeat, | |
798 | .struct. */ | |
799 | ||
e972090a NC |
800 | static const pseudo_typeS mips_pseudo_table[] = |
801 | { | |
beae10d5 | 802 | /* MIPS specific pseudo-ops. */ |
252b5132 RH |
803 | {"option", s_option, 0}, |
804 | {"set", s_mipsset, 0}, | |
805 | {"rdata", s_change_sec, 'r'}, | |
806 | {"sdata", s_change_sec, 's'}, | |
807 | {"livereg", s_ignore, 0}, | |
808 | {"abicalls", s_abicalls, 0}, | |
809 | {"cpload", s_cpload, 0}, | |
6478892d TS |
810 | {"cpsetup", s_cpsetup, 0}, |
811 | {"cplocal", s_cplocal, 0}, | |
252b5132 | 812 | {"cprestore", s_cprestore, 0}, |
6478892d TS |
813 | {"cpreturn", s_cpreturn, 0}, |
814 | {"gpvalue", s_gpvalue, 0}, | |
252b5132 RH |
815 | {"gpword", s_gpword, 0}, |
816 | {"cpadd", s_cpadd, 0}, | |
817 | {"insn", s_insn, 0}, | |
818 | ||
beae10d5 | 819 | /* Relatively generic pseudo-ops that happen to be used on MIPS |
252b5132 RH |
820 | chips. */ |
821 | {"asciiz", stringer, 1}, | |
822 | {"bss", s_change_sec, 'b'}, | |
823 | {"err", s_err, 0}, | |
824 | {"half", s_cons, 1}, | |
825 | {"dword", s_cons, 3}, | |
826 | {"weakext", s_mips_weakext, 0}, | |
827 | ||
beae10d5 | 828 | /* These pseudo-ops are defined in read.c, but must be overridden |
252b5132 RH |
829 | here for one reason or another. */ |
830 | {"align", s_align, 0}, | |
831 | {"byte", s_cons, 0}, | |
832 | {"data", s_change_sec, 'd'}, | |
833 | {"double", s_float_cons, 'd'}, | |
834 | {"float", s_float_cons, 'f'}, | |
835 | {"globl", s_mips_globl, 0}, | |
836 | {"global", s_mips_globl, 0}, | |
837 | {"hword", s_cons, 1}, | |
838 | {"int", s_cons, 2}, | |
839 | {"long", s_cons, 2}, | |
840 | {"octa", s_cons, 4}, | |
841 | {"quad", s_cons, 3}, | |
842 | {"short", s_cons, 1}, | |
843 | {"single", s_float_cons, 'f'}, | |
844 | {"stabn", s_mips_stab, 'n'}, | |
845 | {"text", s_change_sec, 't'}, | |
846 | {"word", s_cons, 2}, | |
add56521 L |
847 | |
848 | #ifdef MIPS_STABS_ELF | |
849 | { "extern", ecoff_directive_extern, 0}, | |
850 | #endif | |
851 | ||
43841e91 | 852 | { NULL, NULL, 0 }, |
252b5132 RH |
853 | }; |
854 | ||
e972090a NC |
855 | static const pseudo_typeS mips_nonecoff_pseudo_table[] = |
856 | { | |
beae10d5 KH |
857 | /* These pseudo-ops should be defined by the object file format. |
858 | However, a.out doesn't support them, so we have versions here. */ | |
252b5132 RH |
859 | {"aent", s_mips_ent, 1}, |
860 | {"bgnb", s_ignore, 0}, | |
861 | {"end", s_mips_end, 0}, | |
862 | {"endb", s_ignore, 0}, | |
863 | {"ent", s_mips_ent, 0}, | |
864 | {"file", s_file, 0}, | |
865 | {"fmask", s_mips_mask, 'F'}, | |
866 | {"frame", s_mips_frame, 0}, | |
867 | {"loc", s_ignore, 0}, | |
868 | {"mask", s_mips_mask, 'R'}, | |
869 | {"verstamp", s_ignore, 0}, | |
43841e91 | 870 | { NULL, NULL, 0 }, |
252b5132 RH |
871 | }; |
872 | ||
873 | extern void pop_insert PARAMS ((const pseudo_typeS *)); | |
874 | ||
875 | void | |
876 | mips_pop_insert () | |
877 | { | |
878 | pop_insert (mips_pseudo_table); | |
879 | if (! ECOFF_DEBUGGING) | |
880 | pop_insert (mips_nonecoff_pseudo_table); | |
881 | } | |
882 | \f | |
883 | /* Symbols labelling the current insn. */ | |
884 | ||
e972090a NC |
885 | struct insn_label_list |
886 | { | |
252b5132 RH |
887 | struct insn_label_list *next; |
888 | symbolS *label; | |
889 | }; | |
890 | ||
891 | static struct insn_label_list *insn_labels; | |
892 | static struct insn_label_list *free_insn_labels; | |
893 | ||
894 | static void mips_clear_insn_labels PARAMS ((void)); | |
895 | ||
896 | static inline void | |
897 | mips_clear_insn_labels () | |
898 | { | |
899 | register struct insn_label_list **pl; | |
900 | ||
901 | for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next) | |
902 | ; | |
903 | *pl = insn_labels; | |
904 | insn_labels = NULL; | |
905 | } | |
906 | \f | |
907 | static char *expr_end; | |
908 | ||
909 | /* Expressions which appear in instructions. These are set by | |
910 | mips_ip. */ | |
911 | ||
912 | static expressionS imm_expr; | |
913 | static expressionS offset_expr; | |
914 | ||
915 | /* Relocs associated with imm_expr and offset_expr. */ | |
916 | ||
f6688943 TS |
917 | static bfd_reloc_code_real_type imm_reloc[3] |
918 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
919 | static bfd_reloc_code_real_type offset_reloc[3] | |
920 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
921 | |
922 | /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */ | |
923 | ||
924 | static boolean imm_unmatched_hi; | |
925 | ||
926 | /* These are set by mips16_ip if an explicit extension is used. */ | |
927 | ||
928 | static boolean mips16_small, mips16_ext; | |
929 | ||
930 | #ifdef MIPS_STABS_ELF | |
931 | /* The pdr segment for per procedure frame/regmask info */ | |
932 | ||
933 | static segT pdr_seg; | |
934 | #endif | |
935 | ||
e7af610e NC |
936 | static const char * |
937 | mips_isa_to_str (isa) | |
938 | int isa; | |
939 | { | |
940 | const struct mips_cpu_info *ci; | |
941 | static char s[20]; | |
942 | ||
943 | ci = mips_cpu_info_from_isa (isa); | |
944 | if (ci != NULL) | |
945 | return (ci->name); | |
946 | ||
947 | sprintf (s, "ISA#%d", isa); | |
948 | return s; | |
949 | } | |
950 | ||
951 | static const char * | |
156c2f8b NC |
952 | mips_cpu_to_str (cpu) |
953 | int cpu; | |
954 | { | |
e7af610e | 955 | const struct mips_cpu_info *ci; |
156c2f8b | 956 | static char s[16]; |
e7af610e NC |
957 | |
958 | ci = mips_cpu_info_from_cpu (cpu); | |
959 | if (ci != NULL) | |
960 | return (ci->name); | |
961 | ||
962 | sprintf (s, "CPU#%d", cpu); | |
963 | return s; | |
156c2f8b NC |
964 | } |
965 | ||
e013f690 TS |
966 | /* The default target format to use. */ |
967 | ||
968 | const char * | |
969 | mips_target_format () | |
970 | { | |
971 | switch (OUTPUT_FLAVOR) | |
972 | { | |
973 | case bfd_target_aout_flavour: | |
974 | return target_big_endian ? "a.out-mips-big" : "a.out-mips-little"; | |
975 | case bfd_target_ecoff_flavour: | |
976 | return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT; | |
977 | case bfd_target_coff_flavour: | |
978 | return "pe-mips"; | |
979 | case bfd_target_elf_flavour: | |
980 | #ifdef TE_TMIPS | |
981 | /* This is traditional mips */ | |
982 | return (target_big_endian | |
983 | ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips" | |
984 | : "elf32-tradbigmips") | |
985 | : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips" | |
986 | : "elf32-tradlittlemips")); | |
987 | #else | |
988 | return (target_big_endian | |
989 | ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips") | |
990 | : (HAVE_64BIT_OBJECTS ? "elf64-littlemips" | |
991 | : "elf32-littlemips")); | |
992 | #endif | |
993 | default: | |
994 | abort (); | |
995 | return NULL; | |
996 | } | |
997 | } | |
998 | ||
156c2f8b NC |
999 | /* This function is called once, at assembler startup time. It should |
1000 | set up all the tables, etc. that the MD part of the assembler will need. */ | |
1001 | ||
252b5132 RH |
1002 | void |
1003 | md_begin () | |
1004 | { | |
252b5132 | 1005 | register const char *retval = NULL; |
156c2f8b | 1006 | int i = 0; |
252b5132 RH |
1007 | const char *cpu; |
1008 | char *a = NULL; | |
1009 | int broken = 0; | |
1010 | int mips_isa_from_cpu; | |
e7af610e NC |
1011 | int target_cpu_had_mips16 = 0; |
1012 | const struct mips_cpu_info *ci; | |
252b5132 | 1013 | |
056350c6 NC |
1014 | /* GP relative stuff not working for PE */ |
1015 | if (strncmp (TARGET_OS, "pe", 2) == 0 | |
1016 | && g_switch_value != 0) | |
1017 | { | |
1018 | if (g_switch_seen) | |
1019 | as_bad (_("-G not supported in this configuration.")); | |
1020 | g_switch_value = 0; | |
1021 | } | |
1022 | ||
252b5132 RH |
1023 | cpu = TARGET_CPU; |
1024 | if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0) | |
1025 | { | |
1026 | a = xmalloc (sizeof TARGET_CPU); | |
1027 | strcpy (a, TARGET_CPU); | |
1028 | a[(sizeof TARGET_CPU) - 3] = '\0'; | |
1029 | cpu = a; | |
1030 | } | |
1031 | ||
e7af610e | 1032 | if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0) |
252b5132 | 1033 | { |
e7af610e NC |
1034 | target_cpu_had_mips16 = 1; |
1035 | cpu += sizeof "mips16" - 1; | |
252b5132 RH |
1036 | } |
1037 | ||
e7af610e NC |
1038 | if (mips_opts.mips16 < 0) |
1039 | mips_opts.mips16 = target_cpu_had_mips16; | |
252b5132 | 1040 | |
6dce9e24 TS |
1041 | /* Backward compatibility for historic -mcpu= option. Check for |
1042 | incompatible options, warn if -mcpu is used. */ | |
1043 | if (mips_cpu != CPU_UNKNOWN | |
1044 | && mips_arch != CPU_UNKNOWN | |
1045 | && mips_cpu != mips_arch) | |
1046 | { | |
1047 | as_fatal (_("The -mcpu option can't be used together with -march. " | |
1048 | "Use -mtune instead of -mcpu.")); | |
1049 | } | |
1050 | ||
1051 | if (mips_cpu != CPU_UNKNOWN | |
1052 | && mips_tune != CPU_UNKNOWN | |
1053 | && mips_cpu != mips_tune) | |
1054 | { | |
1055 | as_fatal (_("The -mcpu option can't be used together with -mtune. " | |
1056 | "Use -march instead of -mcpu.")); | |
1057 | } | |
1058 | ||
1059 | if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN) | |
1060 | { | |
1061 | ci = mips_cpu_info_from_cpu (mips_cpu); | |
1062 | assert (ci != NULL); | |
1063 | mips_arch = ci->cpu; | |
1064 | as_warn (_("The -mcpu option is deprecated. Please use -march and " | |
1065 | "-mtune instead.")); | |
1066 | } | |
1067 | ||
ec68c924 | 1068 | /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was |
e7af610e NC |
1069 | specified on the command line, or some other value if one was. |
1070 | Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on | |
1071 | the command line, or will be set otherwise if one was. */ | |
ec68c924 | 1072 | if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN) |
252b5132 | 1073 | { |
1ff54a84 TS |
1074 | /* We have to check if the isa is the default isa of arch. Otherwise |
1075 | we'll get invalid object file headers. */ | |
1076 | ci = mips_cpu_info_from_cpu (mips_arch); | |
1077 | assert (ci != NULL); | |
1078 | if (mips_opts.isa != ci->isa) | |
1079 | { | |
1080 | /* This really should be an error instead of a warning, but old | |
1081 | compilers only have -mcpu which sets both arch and tune. For | |
1082 | now, we discard arch and preserve tune. */ | |
1083 | as_warn (_("The -march option is incompatible to -mipsN and " | |
1084 | "therefore ignored.")); | |
1085 | if (mips_tune == CPU_UNKNOWN) | |
1086 | mips_tune = mips_arch; | |
1087 | ci = mips_cpu_info_from_isa (mips_opts.isa); | |
1088 | assert (ci != NULL); | |
1089 | mips_arch = ci->cpu; | |
1090 | } | |
252b5132 | 1091 | } |
ec68c924 | 1092 | else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN) |
252b5132 | 1093 | { |
ec68c924 EC |
1094 | /* We have ARCH, we need ISA. */ |
1095 | ci = mips_cpu_info_from_cpu (mips_arch); | |
e7af610e NC |
1096 | assert (ci != NULL); |
1097 | mips_opts.isa = ci->isa; | |
1098 | } | |
ec68c924 | 1099 | else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN) |
e7af610e | 1100 | { |
ec68c924 | 1101 | /* We have ISA, we need default ARCH. */ |
e7af610e NC |
1102 | ci = mips_cpu_info_from_isa (mips_opts.isa); |
1103 | assert (ci != NULL); | |
ec68c924 EC |
1104 | mips_arch = ci->cpu; |
1105 | } | |
e7af610e NC |
1106 | else |
1107 | { | |
ec68c924 | 1108 | /* We need to set both ISA and ARCH from target cpu. */ |
e7af610e NC |
1109 | ci = mips_cpu_info_from_name (cpu); |
1110 | if (ci == NULL) | |
beae10d5 | 1111 | ci = mips_cpu_info_from_cpu (CPU_R3000); |
e7af610e NC |
1112 | assert (ci != NULL); |
1113 | mips_opts.isa = ci->isa; | |
ec68c924 | 1114 | mips_arch = ci->cpu; |
252b5132 RH |
1115 | } |
1116 | ||
ec68c924 EC |
1117 | if (mips_tune == CPU_UNKNOWN) |
1118 | mips_tune = mips_arch; | |
1119 | ||
1120 | ci = mips_cpu_info_from_cpu (mips_arch); | |
e7af610e NC |
1121 | assert (ci != NULL); |
1122 | mips_isa_from_cpu = ci->isa; | |
1123 | ||
252b5132 | 1124 | /* End of TARGET_CPU processing, get rid of malloced memory |
bdaaa2e1 | 1125 | if necessary. */ |
252b5132 RH |
1126 | cpu = NULL; |
1127 | if (a != NULL) | |
1128 | { | |
156c2f8b NC |
1129 | free (a); |
1130 | a = NULL; | |
252b5132 RH |
1131 | } |
1132 | ||
e7af610e | 1133 | if (mips_opts.isa == ISA_MIPS1 && mips_trap) |
252b5132 RH |
1134 | as_bad (_("trap exception not supported at ISA 1")); |
1135 | ||
1136 | /* Set the EABI kind based on the ISA before the user gets | |
1137 | to change the ISA with directives. This isn't really | |
bdaaa2e1 | 1138 | the best, but then neither is basing the abi on the isa. */ |
9ce8a5dd | 1139 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) |
a325df1d | 1140 | && mips_opts.abi == EABI_ABI) |
252b5132 RH |
1141 | mips_eabi64 = 1; |
1142 | ||
e7af610e NC |
1143 | /* If they asked for mips1 or mips2 and a cpu that is |
1144 | mips3 or greater, then mark the object file 32BITMODE. */ | |
1145 | if (mips_isa_from_cpu != ISA_UNKNOWN | |
1146 | && ! ISA_HAS_64BIT_REGS (mips_opts.isa) | |
1147 | && ISA_HAS_64BIT_REGS (mips_isa_from_cpu)) | |
1148 | mips_32bitmode = 1; | |
252b5132 | 1149 | |
ec68c924 | 1150 | if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch)) |
252b5132 RH |
1151 | as_warn (_("Could not set architecture and machine")); |
1152 | ||
1153 | file_mips_isa = mips_opts.isa; | |
a325df1d TS |
1154 | file_mips_abi = mips_opts.abi; |
1155 | mips_opts.gp32 = file_mips_gp32; | |
1156 | mips_opts.fp32 = file_mips_fp32; | |
252b5132 RH |
1157 | |
1158 | op_hash = hash_new (); | |
1159 | ||
1160 | for (i = 0; i < NUMOPCODES;) | |
1161 | { | |
1162 | const char *name = mips_opcodes[i].name; | |
1163 | ||
1164 | retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]); | |
1165 | if (retval != NULL) | |
1166 | { | |
1167 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), | |
1168 | mips_opcodes[i].name, retval); | |
1169 | /* Probably a memory allocation problem? Give up now. */ | |
1170 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1171 | } | |
1172 | do | |
1173 | { | |
1174 | if (mips_opcodes[i].pinfo != INSN_MACRO) | |
1175 | { | |
1176 | if (!validate_mips_insn (&mips_opcodes[i])) | |
1177 | broken = 1; | |
1178 | } | |
1179 | ++i; | |
1180 | } | |
1181 | while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name)); | |
1182 | } | |
1183 | ||
1184 | mips16_op_hash = hash_new (); | |
1185 | ||
1186 | i = 0; | |
1187 | while (i < bfd_mips16_num_opcodes) | |
1188 | { | |
1189 | const char *name = mips16_opcodes[i].name; | |
1190 | ||
1191 | retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]); | |
1192 | if (retval != NULL) | |
1193 | as_fatal (_("internal: can't hash `%s': %s"), | |
1194 | mips16_opcodes[i].name, retval); | |
1195 | do | |
1196 | { | |
1197 | if (mips16_opcodes[i].pinfo != INSN_MACRO | |
1198 | && ((mips16_opcodes[i].match & mips16_opcodes[i].mask) | |
1199 | != mips16_opcodes[i].match)) | |
1200 | { | |
1201 | fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"), | |
1202 | mips16_opcodes[i].name, mips16_opcodes[i].args); | |
1203 | broken = 1; | |
1204 | } | |
1205 | ++i; | |
1206 | } | |
1207 | while (i < bfd_mips16_num_opcodes | |
1208 | && strcmp (mips16_opcodes[i].name, name) == 0); | |
1209 | } | |
1210 | ||
1211 | if (broken) | |
1212 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1213 | ||
1214 | /* We add all the general register names to the symbol table. This | |
1215 | helps us detect invalid uses of them. */ | |
1216 | for (i = 0; i < 32; i++) | |
1217 | { | |
1218 | char buf[5]; | |
1219 | ||
1220 | sprintf (buf, "$%d", i); | |
1221 | symbol_table_insert (symbol_new (buf, reg_section, i, | |
1222 | &zero_address_frag)); | |
1223 | } | |
1224 | symbol_table_insert (symbol_new ("$fp", reg_section, FP, | |
1225 | &zero_address_frag)); | |
1226 | symbol_table_insert (symbol_new ("$sp", reg_section, SP, | |
1227 | &zero_address_frag)); | |
1228 | symbol_table_insert (symbol_new ("$gp", reg_section, GP, | |
1229 | &zero_address_frag)); | |
1230 | symbol_table_insert (symbol_new ("$at", reg_section, AT, | |
1231 | &zero_address_frag)); | |
1232 | symbol_table_insert (symbol_new ("$kt0", reg_section, KT0, | |
1233 | &zero_address_frag)); | |
1234 | symbol_table_insert (symbol_new ("$kt1", reg_section, KT1, | |
1235 | &zero_address_frag)); | |
1236 | symbol_table_insert (symbol_new ("$pc", reg_section, -1, | |
1237 | &zero_address_frag)); | |
1238 | ||
1239 | mips_no_prev_insn (false); | |
1240 | ||
1241 | mips_gprmask = 0; | |
1242 | mips_cprmask[0] = 0; | |
1243 | mips_cprmask[1] = 0; | |
1244 | mips_cprmask[2] = 0; | |
1245 | mips_cprmask[3] = 0; | |
1246 | ||
1247 | /* set the default alignment for the text section (2**2) */ | |
1248 | record_alignment (text_section, 2); | |
1249 | ||
1250 | if (USE_GLOBAL_POINTER_OPT) | |
1251 | bfd_set_gp_size (stdoutput, g_switch_value); | |
1252 | ||
1253 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1254 | { | |
1255 | /* On a native system, sections must be aligned to 16 byte | |
1256 | boundaries. When configured for an embedded ELF target, we | |
1257 | don't bother. */ | |
1258 | if (strcmp (TARGET_OS, "elf") != 0) | |
1259 | { | |
1260 | (void) bfd_set_section_alignment (stdoutput, text_section, 4); | |
1261 | (void) bfd_set_section_alignment (stdoutput, data_section, 4); | |
1262 | (void) bfd_set_section_alignment (stdoutput, bss_section, 4); | |
1263 | } | |
1264 | ||
1265 | /* Create a .reginfo section for register masks and a .mdebug | |
1266 | section for debugging information. */ | |
1267 | { | |
1268 | segT seg; | |
1269 | subsegT subseg; | |
1270 | flagword flags; | |
1271 | segT sec; | |
1272 | ||
1273 | seg = now_seg; | |
1274 | subseg = now_subseg; | |
1275 | ||
1276 | /* The ABI says this section should be loaded so that the | |
1277 | running program can access it. However, we don't load it | |
1278 | if we are configured for an embedded target */ | |
1279 | flags = SEC_READONLY | SEC_DATA; | |
1280 | if (strcmp (TARGET_OS, "elf") != 0) | |
1281 | flags |= SEC_ALLOC | SEC_LOAD; | |
1282 | ||
e013f690 | 1283 | if (! HAVE_NEWABI) |
252b5132 RH |
1284 | { |
1285 | sec = subseg_new (".reginfo", (subsegT) 0); | |
1286 | ||
252b5132 RH |
1287 | (void) bfd_set_section_flags (stdoutput, sec, flags); |
1288 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
bdaaa2e1 | 1289 | |
252b5132 RH |
1290 | #ifdef OBJ_ELF |
1291 | mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo)); | |
1292 | #endif | |
1293 | } | |
1294 | else | |
1295 | { | |
1296 | /* The 64-bit ABI uses a .MIPS.options section rather than | |
1297 | .reginfo section. */ | |
1298 | sec = subseg_new (".MIPS.options", (subsegT) 0); | |
1299 | (void) bfd_set_section_flags (stdoutput, sec, flags); | |
1300 | (void) bfd_set_section_alignment (stdoutput, sec, 3); | |
1301 | ||
1302 | #ifdef OBJ_ELF | |
1303 | /* Set up the option header. */ | |
1304 | { | |
1305 | Elf_Internal_Options opthdr; | |
1306 | char *f; | |
1307 | ||
1308 | opthdr.kind = ODK_REGINFO; | |
1309 | opthdr.size = (sizeof (Elf_External_Options) | |
1310 | + sizeof (Elf64_External_RegInfo)); | |
1311 | opthdr.section = 0; | |
1312 | opthdr.info = 0; | |
1313 | f = frag_more (sizeof (Elf_External_Options)); | |
1314 | bfd_mips_elf_swap_options_out (stdoutput, &opthdr, | |
1315 | (Elf_External_Options *) f); | |
1316 | ||
1317 | mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo)); | |
1318 | } | |
1319 | #endif | |
1320 | } | |
1321 | ||
1322 | if (ECOFF_DEBUGGING) | |
1323 | { | |
1324 | sec = subseg_new (".mdebug", (subsegT) 0); | |
1325 | (void) bfd_set_section_flags (stdoutput, sec, | |
1326 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1327 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
1328 | } | |
1329 | ||
1330 | #ifdef MIPS_STABS_ELF | |
1331 | pdr_seg = subseg_new (".pdr", (subsegT) 0); | |
1332 | (void) bfd_set_section_flags (stdoutput, pdr_seg, | |
1333 | SEC_READONLY | SEC_RELOC | SEC_DEBUGGING); | |
1334 | (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2); | |
1335 | #endif | |
1336 | ||
1337 | subseg_set (seg, subseg); | |
1338 | } | |
1339 | } | |
1340 | ||
1341 | if (! ECOFF_DEBUGGING) | |
1342 | md_obj_begin (); | |
1343 | } | |
1344 | ||
1345 | void | |
1346 | md_mips_end () | |
1347 | { | |
1348 | if (! ECOFF_DEBUGGING) | |
1349 | md_obj_end (); | |
1350 | } | |
1351 | ||
1352 | void | |
1353 | md_assemble (str) | |
1354 | char *str; | |
1355 | { | |
1356 | struct mips_cl_insn insn; | |
f6688943 TS |
1357 | bfd_reloc_code_real_type unused_reloc[3] |
1358 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
1359 | |
1360 | imm_expr.X_op = O_absent; | |
252b5132 RH |
1361 | imm_unmatched_hi = false; |
1362 | offset_expr.X_op = O_absent; | |
f6688943 TS |
1363 | imm_reloc[0] = BFD_RELOC_UNUSED; |
1364 | imm_reloc[1] = BFD_RELOC_UNUSED; | |
1365 | imm_reloc[2] = BFD_RELOC_UNUSED; | |
1366 | offset_reloc[0] = BFD_RELOC_UNUSED; | |
1367 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
1368 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
1369 | |
1370 | if (mips_opts.mips16) | |
1371 | mips16_ip (str, &insn); | |
1372 | else | |
1373 | { | |
1374 | mips_ip (str, &insn); | |
beae10d5 KH |
1375 | DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), |
1376 | str, insn.insn_opcode)); | |
252b5132 RH |
1377 | } |
1378 | ||
1379 | if (insn_error) | |
1380 | { | |
1381 | as_bad ("%s `%s'", insn_error, str); | |
1382 | return; | |
1383 | } | |
1384 | ||
1385 | if (insn.insn_mo->pinfo == INSN_MACRO) | |
1386 | { | |
1387 | if (mips_opts.mips16) | |
1388 | mips16_macro (&insn); | |
1389 | else | |
1390 | macro (&insn); | |
1391 | } | |
1392 | else | |
1393 | { | |
1394 | if (imm_expr.X_op != O_absent) | |
c4e7957c | 1395 | append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi); |
252b5132 | 1396 | else if (offset_expr.X_op != O_absent) |
c4e7957c | 1397 | append_insn (NULL, &insn, &offset_expr, offset_reloc, false); |
252b5132 | 1398 | else |
c4e7957c | 1399 | append_insn (NULL, &insn, NULL, unused_reloc, false); |
252b5132 RH |
1400 | } |
1401 | } | |
1402 | ||
1403 | /* See whether instruction IP reads register REG. CLASS is the type | |
1404 | of register. */ | |
1405 | ||
1406 | static int | |
1407 | insn_uses_reg (ip, reg, class) | |
1408 | struct mips_cl_insn *ip; | |
1409 | unsigned int reg; | |
1410 | enum mips_regclass class; | |
1411 | { | |
1412 | if (class == MIPS16_REG) | |
1413 | { | |
1414 | assert (mips_opts.mips16); | |
1415 | reg = mips16_to_32_reg_map[reg]; | |
1416 | class = MIPS_GR_REG; | |
1417 | } | |
1418 | ||
1419 | /* Don't report on general register 0, since it never changes. */ | |
1420 | if (class == MIPS_GR_REG && reg == 0) | |
1421 | return 0; | |
1422 | ||
1423 | if (class == MIPS_FP_REG) | |
1424 | { | |
1425 | assert (! mips_opts.mips16); | |
1426 | /* If we are called with either $f0 or $f1, we must check $f0. | |
1427 | This is not optimal, because it will introduce an unnecessary | |
1428 | NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would | |
1429 | need to distinguish reading both $f0 and $f1 or just one of | |
1430 | them. Note that we don't have to check the other way, | |
1431 | because there is no instruction that sets both $f0 and $f1 | |
1432 | and requires a delay. */ | |
1433 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_S) | |
1434 | && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1) | |
1435 | == (reg &~ (unsigned) 1))) | |
1436 | return 1; | |
1437 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_T) | |
1438 | && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1) | |
1439 | == (reg &~ (unsigned) 1))) | |
1440 | return 1; | |
1441 | } | |
1442 | else if (! mips_opts.mips16) | |
1443 | { | |
1444 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_S) | |
1445 | && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg) | |
1446 | return 1; | |
1447 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_T) | |
1448 | && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg) | |
1449 | return 1; | |
1450 | } | |
1451 | else | |
1452 | { | |
1453 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X) | |
1454 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX) | |
1455 | & MIPS16OP_MASK_RX)] | |
1456 | == reg)) | |
1457 | return 1; | |
1458 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y) | |
1459 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY) | |
1460 | & MIPS16OP_MASK_RY)] | |
1461 | == reg)) | |
1462 | return 1; | |
1463 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z) | |
1464 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
1465 | & MIPS16OP_MASK_MOVE32Z)] | |
1466 | == reg)) | |
1467 | return 1; | |
1468 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG) | |
1469 | return 1; | |
1470 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP) | |
1471 | return 1; | |
1472 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA) | |
1473 | return 1; | |
1474 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X) | |
1475 | && ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
1476 | & MIPS16OP_MASK_REGR32) == reg) | |
1477 | return 1; | |
1478 | } | |
1479 | ||
1480 | return 0; | |
1481 | } | |
1482 | ||
1483 | /* This function returns true if modifying a register requires a | |
1484 | delay. */ | |
1485 | ||
1486 | static int | |
1487 | reg_needs_delay (reg) | |
156c2f8b | 1488 | unsigned int reg; |
252b5132 RH |
1489 | { |
1490 | unsigned long prev_pinfo; | |
1491 | ||
1492 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1493 | if (! mips_opts.noreorder | |
9ce8a5dd | 1494 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1495 | && ((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1496 | || (! gpr_interlocks | |
1497 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1498 | { | |
1499 | /* A load from a coprocessor or from memory. All load | |
1500 | delays delay the use of general register rt for one | |
1501 | instruction on the r3000. The r6000 and r4000 use | |
1502 | interlocks. */ | |
bdaaa2e1 | 1503 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1504 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1505 | if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)) | |
1506 | return 1; | |
1507 | } | |
1508 | ||
1509 | return 0; | |
1510 | } | |
1511 | ||
1512 | /* Mark instruction labels in mips16 mode. This permits the linker to | |
1513 | handle them specially, such as generating jalx instructions when | |
1514 | needed. We also make them odd for the duration of the assembly, in | |
1515 | order to generate the right sort of code. We will make them even | |
1516 | in the adjust_symtab routine, while leaving them marked. This is | |
1517 | convenient for the debugger and the disassembler. The linker knows | |
1518 | to make them odd again. */ | |
1519 | ||
1520 | static void | |
1521 | mips16_mark_labels () | |
1522 | { | |
1523 | if (mips_opts.mips16) | |
1524 | { | |
1525 | struct insn_label_list *l; | |
98aa84af | 1526 | valueT val; |
252b5132 RH |
1527 | |
1528 | for (l = insn_labels; l != NULL; l = l->next) | |
1529 | { | |
1530 | #ifdef OBJ_ELF | |
1531 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1532 | S_SET_OTHER (l->label, STO_MIPS16); | |
1533 | #endif | |
98aa84af AM |
1534 | val = S_GET_VALUE (l->label); |
1535 | if ((val & 1) == 0) | |
1536 | S_SET_VALUE (l->label, val + 1); | |
252b5132 RH |
1537 | } |
1538 | } | |
1539 | } | |
1540 | ||
1541 | /* Output an instruction. PLACE is where to put the instruction; if | |
1542 | it is NULL, this uses frag_more to get room. IP is the instruction | |
1543 | information. ADDRESS_EXPR is an operand of the instruction to be | |
1544 | used with RELOC_TYPE. */ | |
1545 | ||
1546 | static void | |
1547 | append_insn (place, ip, address_expr, reloc_type, unmatched_hi) | |
1548 | char *place; | |
1549 | struct mips_cl_insn *ip; | |
1550 | expressionS *address_expr; | |
f6688943 | 1551 | bfd_reloc_code_real_type *reloc_type; |
252b5132 RH |
1552 | boolean unmatched_hi; |
1553 | { | |
1554 | register unsigned long prev_pinfo, pinfo; | |
1555 | char *f; | |
f6688943 | 1556 | fixS *fixp[3]; |
252b5132 RH |
1557 | int nops = 0; |
1558 | ||
1559 | /* Mark instruction labels in mips16 mode. */ | |
1560 | if (mips_opts.mips16) | |
1561 | mips16_mark_labels (); | |
1562 | ||
1563 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1564 | pinfo = ip->insn_mo->pinfo; | |
1565 | ||
1566 | if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL)) | |
1567 | { | |
1568 | int prev_prev_nop; | |
1569 | ||
1570 | /* If the previous insn required any delay slots, see if we need | |
1571 | to insert a NOP or two. There are eight kinds of possible | |
1572 | hazards, of which an instruction can have at most one type. | |
1573 | (1) a load from memory delay | |
1574 | (2) a load from a coprocessor delay | |
1575 | (3) an unconditional branch delay | |
1576 | (4) a conditional branch delay | |
1577 | (5) a move to coprocessor register delay | |
1578 | (6) a load coprocessor register from memory delay | |
1579 | (7) a coprocessor condition code delay | |
1580 | (8) a HI/LO special register delay | |
1581 | ||
1582 | There are a lot of optimizations we could do that we don't. | |
1583 | In particular, we do not, in general, reorder instructions. | |
1584 | If you use gcc with optimization, it will reorder | |
1585 | instructions and generally do much more optimization then we | |
1586 | do here; repeating all that work in the assembler would only | |
1587 | benefit hand written assembly code, and does not seem worth | |
1588 | it. */ | |
1589 | ||
1590 | /* This is how a NOP is emitted. */ | |
1591 | #define emit_nop() \ | |
1592 | (mips_opts.mips16 \ | |
1593 | ? md_number_to_chars (frag_more (2), 0x6500, 2) \ | |
1594 | : md_number_to_chars (frag_more (4), 0, 4)) | |
1595 | ||
1596 | /* The previous insn might require a delay slot, depending upon | |
1597 | the contents of the current insn. */ | |
1598 | if (! mips_opts.mips16 | |
9ce8a5dd | 1599 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1600 | && (((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1601 | && ! cop_interlocks) | |
1602 | || (! gpr_interlocks | |
1603 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1604 | { | |
1605 | /* A load from a coprocessor or from memory. All load | |
1606 | delays delay the use of general register rt for one | |
1607 | instruction on the r3000. The r6000 and r4000 use | |
1608 | interlocks. */ | |
beae10d5 | 1609 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1610 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1611 | if (mips_optimize == 0 | |
1612 | || insn_uses_reg (ip, | |
1613 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
1614 | & OP_MASK_RT), | |
1615 | MIPS_GR_REG)) | |
1616 | ++nops; | |
1617 | } | |
1618 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1619 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 1620 | && (((prev_pinfo & INSN_COPROC_MOVE_DELAY) |
beae10d5 | 1621 | && ! cop_interlocks) |
e7af610e | 1622 | || (mips_opts.isa == ISA_MIPS1 |
252b5132 RH |
1623 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)))) |
1624 | { | |
1625 | /* A generic coprocessor delay. The previous instruction | |
1626 | modified a coprocessor general or control register. If | |
1627 | it modified a control register, we need to avoid any | |
1628 | coprocessor instruction (this is probably not always | |
1629 | required, but it sometimes is). If it modified a general | |
1630 | register, we avoid using that register. | |
1631 | ||
1632 | On the r6000 and r4000 loading a coprocessor register | |
1633 | from memory is interlocked, and does not require a delay. | |
1634 | ||
1635 | This case is not handled very well. There is no special | |
1636 | knowledge of CP0 handling, and the coprocessors other | |
1637 | than the floating point unit are not distinguished at | |
1638 | all. */ | |
1639 | /* Itbl support may require additional care here. FIXME! | |
bdaaa2e1 | 1640 | Need to modify this to include knowledge about |
252b5132 RH |
1641 | user specified delays! */ |
1642 | if (prev_pinfo & INSN_WRITE_FPR_T) | |
1643 | { | |
1644 | if (mips_optimize == 0 | |
1645 | || insn_uses_reg (ip, | |
1646 | ((prev_insn.insn_opcode >> OP_SH_FT) | |
1647 | & OP_MASK_FT), | |
1648 | MIPS_FP_REG)) | |
1649 | ++nops; | |
1650 | } | |
1651 | else if (prev_pinfo & INSN_WRITE_FPR_S) | |
1652 | { | |
1653 | if (mips_optimize == 0 | |
1654 | || insn_uses_reg (ip, | |
1655 | ((prev_insn.insn_opcode >> OP_SH_FS) | |
1656 | & OP_MASK_FS), | |
1657 | MIPS_FP_REG)) | |
1658 | ++nops; | |
1659 | } | |
1660 | else | |
1661 | { | |
1662 | /* We don't know exactly what the previous instruction | |
1663 | does. If the current instruction uses a coprocessor | |
1664 | register, we must insert a NOP. If previous | |
1665 | instruction may set the condition codes, and the | |
1666 | current instruction uses them, we must insert two | |
1667 | NOPS. */ | |
bdaaa2e1 | 1668 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1669 | if (mips_optimize == 0 |
1670 | || ((prev_pinfo & INSN_WRITE_COND_CODE) | |
1671 | && (pinfo & INSN_READ_COND_CODE))) | |
1672 | nops += 2; | |
1673 | else if (pinfo & INSN_COP) | |
1674 | ++nops; | |
1675 | } | |
1676 | } | |
1677 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1678 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1679 | && (prev_pinfo & INSN_WRITE_COND_CODE) |
1680 | && ! cop_interlocks) | |
1681 | { | |
1682 | /* The previous instruction sets the coprocessor condition | |
1683 | codes, but does not require a general coprocessor delay | |
1684 | (this means it is a floating point comparison | |
1685 | instruction). If this instruction uses the condition | |
1686 | codes, we need to insert a single NOP. */ | |
beae10d5 | 1687 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1688 | if (mips_optimize == 0 |
1689 | || (pinfo & INSN_READ_COND_CODE)) | |
1690 | ++nops; | |
1691 | } | |
6b76fefe CM |
1692 | |
1693 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1694 | previous insn was an mfhi/mflo and the current insn | |
1695 | reads the register that the mfhi/mflo wrote to, then | |
1696 | insert two nops. */ | |
1697 | ||
1698 | else if (mips_7000_hilo_fix | |
1699 | && MF_HILO_INSN (prev_pinfo) | |
1700 | && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD) | |
beae10d5 KH |
1701 | & OP_MASK_RD), |
1702 | MIPS_GR_REG)) | |
6b76fefe CM |
1703 | { |
1704 | nops += 2; | |
1705 | } | |
1706 | ||
1707 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1708 | 2nd previous insn was an mfhi/mflo and the current insn | |
1709 | reads the register that the mfhi/mflo wrote to, then | |
1710 | insert one nop. */ | |
1711 | ||
1712 | else if (mips_7000_hilo_fix | |
1713 | && MF_HILO_INSN (prev_prev_insn.insn_opcode) | |
1714 | && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD) | |
1715 | & OP_MASK_RD), | |
1716 | MIPS_GR_REG)) | |
bdaaa2e1 | 1717 | |
6b76fefe CM |
1718 | { |
1719 | nops += 1; | |
1720 | } | |
bdaaa2e1 | 1721 | |
252b5132 RH |
1722 | else if (prev_pinfo & INSN_READ_LO) |
1723 | { | |
1724 | /* The previous instruction reads the LO register; if the | |
1725 | current instruction writes to the LO register, we must | |
bdaaa2e1 KH |
1726 | insert two NOPS. Some newer processors have interlocks. |
1727 | Also the tx39's multiply instructions can be exectuted | |
252b5132 | 1728 | immediatly after a read from HI/LO (without the delay), |
bdaaa2e1 KH |
1729 | though the tx39's divide insns still do require the |
1730 | delay. */ | |
252b5132 | 1731 | if (! (hilo_interlocks |
ec68c924 | 1732 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1733 | && (mips_optimize == 0 |
1734 | || (pinfo & INSN_WRITE_LO))) | |
1735 | nops += 2; | |
1736 | /* Most mips16 branch insns don't have a delay slot. | |
1737 | If a read from LO is immediately followed by a branch | |
1738 | to a write to LO we have a read followed by a write | |
1739 | less than 2 insns away. We assume the target of | |
1740 | a branch might be a write to LO, and insert a nop | |
bdaaa2e1 | 1741 | between a read and an immediately following branch. */ |
252b5132 RH |
1742 | else if (mips_opts.mips16 |
1743 | && (mips_optimize == 0 | |
1744 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1745 | nops += 1; | |
1746 | } | |
1747 | else if (prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
1748 | { | |
1749 | /* The previous instruction reads the HI register; if the | |
1750 | current instruction writes to the HI register, we must | |
1751 | insert a NOP. Some newer processors have interlocks. | |
bdaaa2e1 | 1752 | Also the note tx39's multiply above. */ |
252b5132 | 1753 | if (! (hilo_interlocks |
ec68c924 | 1754 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1755 | && (mips_optimize == 0 |
1756 | || (pinfo & INSN_WRITE_HI))) | |
1757 | nops += 2; | |
1758 | /* Most mips16 branch insns don't have a delay slot. | |
1759 | If a read from HI is immediately followed by a branch | |
1760 | to a write to HI we have a read followed by a write | |
1761 | less than 2 insns away. We assume the target of | |
1762 | a branch might be a write to HI, and insert a nop | |
bdaaa2e1 | 1763 | between a read and an immediately following branch. */ |
252b5132 RH |
1764 | else if (mips_opts.mips16 |
1765 | && (mips_optimize == 0 | |
1766 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1767 | nops += 1; | |
1768 | } | |
1769 | ||
1770 | /* If the previous instruction was in a noreorder section, then | |
1771 | we don't want to insert the nop after all. */ | |
bdaaa2e1 | 1772 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1773 | if (prev_insn_unreordered) |
1774 | nops = 0; | |
1775 | ||
1776 | /* There are two cases which require two intervening | |
1777 | instructions: 1) setting the condition codes using a move to | |
1778 | coprocessor instruction which requires a general coprocessor | |
1779 | delay and then reading the condition codes 2) reading the HI | |
1780 | or LO register and then writing to it (except on processors | |
1781 | which have interlocks). If we are not already emitting a NOP | |
1782 | instruction, we must check for these cases compared to the | |
1783 | instruction previous to the previous instruction. */ | |
1784 | if ((! mips_opts.mips16 | |
9ce8a5dd | 1785 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1786 | && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY) |
1787 | && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE) | |
1788 | && (pinfo & INSN_READ_COND_CODE) | |
1789 | && ! cop_interlocks) | |
1790 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO) | |
1791 | && (pinfo & INSN_WRITE_LO) | |
1792 | && ! (hilo_interlocks | |
ec68c924 | 1793 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))) |
252b5132 RH |
1794 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) |
1795 | && (pinfo & INSN_WRITE_HI) | |
1796 | && ! (hilo_interlocks | |
ec68c924 | 1797 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))) |
252b5132 RH |
1798 | prev_prev_nop = 1; |
1799 | else | |
1800 | prev_prev_nop = 0; | |
1801 | ||
1802 | if (prev_prev_insn_unreordered) | |
1803 | prev_prev_nop = 0; | |
1804 | ||
1805 | if (prev_prev_nop && nops == 0) | |
1806 | ++nops; | |
1807 | ||
1808 | /* If we are being given a nop instruction, don't bother with | |
1809 | one of the nops we would otherwise output. This will only | |
1810 | happen when a nop instruction is used with mips_optimize set | |
1811 | to 0. */ | |
1812 | if (nops > 0 | |
1813 | && ! mips_opts.noreorder | |
156c2f8b | 1814 | && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0)) |
252b5132 RH |
1815 | --nops; |
1816 | ||
1817 | /* Now emit the right number of NOP instructions. */ | |
1818 | if (nops > 0 && ! mips_opts.noreorder) | |
1819 | { | |
1820 | fragS *old_frag; | |
1821 | unsigned long old_frag_offset; | |
1822 | int i; | |
1823 | struct insn_label_list *l; | |
1824 | ||
1825 | old_frag = frag_now; | |
1826 | old_frag_offset = frag_now_fix (); | |
1827 | ||
1828 | for (i = 0; i < nops; i++) | |
1829 | emit_nop (); | |
1830 | ||
1831 | if (listing) | |
1832 | { | |
1833 | listing_prev_line (); | |
1834 | /* We may be at the start of a variant frag. In case we | |
1835 | are, make sure there is enough space for the frag | |
1836 | after the frags created by listing_prev_line. The | |
1837 | argument to frag_grow here must be at least as large | |
1838 | as the argument to all other calls to frag_grow in | |
1839 | this file. We don't have to worry about being in the | |
1840 | middle of a variant frag, because the variants insert | |
1841 | all needed nop instructions themselves. */ | |
1842 | frag_grow (40); | |
1843 | } | |
1844 | ||
1845 | for (l = insn_labels; l != NULL; l = l->next) | |
1846 | { | |
98aa84af AM |
1847 | valueT val; |
1848 | ||
252b5132 | 1849 | assert (S_GET_SEGMENT (l->label) == now_seg); |
49309057 | 1850 | symbol_set_frag (l->label, frag_now); |
98aa84af | 1851 | val = (valueT) frag_now_fix (); |
252b5132 RH |
1852 | /* mips16 text labels are stored as odd. */ |
1853 | if (mips_opts.mips16) | |
98aa84af AM |
1854 | val += 1; |
1855 | S_SET_VALUE (l->label, val); | |
252b5132 RH |
1856 | } |
1857 | ||
1858 | #ifndef NO_ECOFF_DEBUGGING | |
1859 | if (ECOFF_DEBUGGING) | |
1860 | ecoff_fix_loc (old_frag, old_frag_offset); | |
1861 | #endif | |
1862 | } | |
1863 | else if (prev_nop_frag != NULL) | |
1864 | { | |
1865 | /* We have a frag holding nops we may be able to remove. If | |
1866 | we don't need any nops, we can decrease the size of | |
1867 | prev_nop_frag by the size of one instruction. If we do | |
bdaaa2e1 | 1868 | need some nops, we count them in prev_nops_required. */ |
252b5132 RH |
1869 | if (prev_nop_frag_since == 0) |
1870 | { | |
1871 | if (nops == 0) | |
1872 | { | |
1873 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1874 | --prev_nop_frag_holds; | |
1875 | } | |
1876 | else | |
1877 | prev_nop_frag_required += nops; | |
1878 | } | |
1879 | else | |
1880 | { | |
1881 | if (prev_prev_nop == 0) | |
1882 | { | |
1883 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1884 | --prev_nop_frag_holds; | |
1885 | } | |
1886 | else | |
1887 | ++prev_nop_frag_required; | |
1888 | } | |
1889 | ||
1890 | if (prev_nop_frag_holds <= prev_nop_frag_required) | |
1891 | prev_nop_frag = NULL; | |
1892 | ||
1893 | ++prev_nop_frag_since; | |
1894 | ||
1895 | /* Sanity check: by the time we reach the second instruction | |
1896 | after prev_nop_frag, we should have used up all the nops | |
1897 | one way or another. */ | |
1898 | assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL); | |
1899 | } | |
1900 | } | |
1901 | ||
f6688943 | 1902 | if (*reloc_type > BFD_RELOC_UNUSED) |
252b5132 RH |
1903 | { |
1904 | /* We need to set up a variant frag. */ | |
1905 | assert (mips_opts.mips16 && address_expr != NULL); | |
1906 | f = frag_var (rs_machine_dependent, 4, 0, | |
f6688943 | 1907 | RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED, |
252b5132 RH |
1908 | mips16_small, mips16_ext, |
1909 | (prev_pinfo | |
1910 | & INSN_UNCOND_BRANCH_DELAY), | |
f6688943 | 1911 | (*prev_insn_reloc_type |
252b5132 | 1912 | == BFD_RELOC_MIPS16_JMP)), |
c4e7957c | 1913 | make_expr_symbol (address_expr), 0, NULL); |
252b5132 RH |
1914 | } |
1915 | else if (place != NULL) | |
1916 | f = place; | |
1917 | else if (mips_opts.mips16 | |
1918 | && ! ip->use_extend | |
f6688943 | 1919 | && *reloc_type != BFD_RELOC_MIPS16_JMP) |
252b5132 RH |
1920 | { |
1921 | /* Make sure there is enough room to swap this instruction with | |
1922 | a following jump instruction. */ | |
1923 | frag_grow (6); | |
1924 | f = frag_more (2); | |
1925 | } | |
1926 | else | |
1927 | { | |
1928 | if (mips_opts.mips16 | |
1929 | && mips_opts.noreorder | |
1930 | && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0) | |
1931 | as_warn (_("extended instruction in delay slot")); | |
1932 | ||
1933 | f = frag_more (4); | |
1934 | } | |
1935 | ||
f6688943 TS |
1936 | fixp[0] = fixp[1] = fixp[2] = NULL; |
1937 | if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED) | |
252b5132 RH |
1938 | { |
1939 | if (address_expr->X_op == O_constant) | |
1940 | { | |
f6688943 TS |
1941 | unsigned long tmp; |
1942 | ||
1943 | switch (*reloc_type) | |
252b5132 RH |
1944 | { |
1945 | case BFD_RELOC_32: | |
1946 | ip->insn_opcode |= address_expr->X_add_number; | |
1947 | break; | |
1948 | ||
f6688943 TS |
1949 | case BFD_RELOC_MIPS_HIGHEST: |
1950 | tmp = (address_expr->X_add_number + 0x800080008000) >> 16; | |
1951 | tmp >>= 16; | |
1952 | ip->insn_opcode |= (tmp >> 16) & 0xffff; | |
1953 | break; | |
1954 | ||
1955 | case BFD_RELOC_MIPS_HIGHER: | |
1956 | tmp = (address_expr->X_add_number + 0x80008000) >> 16; | |
1957 | ip->insn_opcode |= (tmp >> 16) & 0xffff; | |
1958 | break; | |
1959 | ||
1960 | case BFD_RELOC_HI16_S: | |
1961 | ip->insn_opcode |= ((address_expr->X_add_number + 0x8000) | |
1962 | >> 16) & 0xffff; | |
1963 | break; | |
1964 | ||
1965 | case BFD_RELOC_HI16: | |
1966 | ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff; | |
1967 | break; | |
1968 | ||
252b5132 RH |
1969 | case BFD_RELOC_LO16: |
1970 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; | |
1971 | break; | |
1972 | ||
1973 | case BFD_RELOC_MIPS_JMP: | |
1974 | if ((address_expr->X_add_number & 3) != 0) | |
1975 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1976 | (unsigned long) address_expr->X_add_number); | |
7496292d TS |
1977 | if (address_expr->X_add_number & ~0xfffffff |
1978 | || address_expr->X_add_number > 0x7fffffc) | |
1979 | as_bad (_("jump address range overflow (0x%lx)"), | |
1980 | (unsigned long) address_expr->X_add_number); | |
252b5132 RH |
1981 | ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff; |
1982 | break; | |
1983 | ||
1984 | case BFD_RELOC_MIPS16_JMP: | |
1985 | if ((address_expr->X_add_number & 3) != 0) | |
1986 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1987 | (unsigned long) address_expr->X_add_number); | |
7496292d TS |
1988 | if (address_expr->X_add_number & ~0xfffffff |
1989 | || address_expr->X_add_number > 0x7fffffc) | |
1990 | as_bad (_("jump address range overflow (0x%lx)"), | |
1991 | (unsigned long) address_expr->X_add_number); | |
252b5132 RH |
1992 | ip->insn_opcode |= |
1993 | (((address_expr->X_add_number & 0x7c0000) << 3) | |
1994 | | ((address_expr->X_add_number & 0xf800000) >> 7) | |
1995 | | ((address_expr->X_add_number & 0x3fffc) >> 2)); | |
1996 | break; | |
1997 | ||
cb56d3d3 | 1998 | case BFD_RELOC_16_PCREL: |
233b8738 | 1999 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; |
cb56d3d3 TS |
2000 | break; |
2001 | ||
252b5132 RH |
2002 | case BFD_RELOC_16_PCREL_S2: |
2003 | goto need_reloc; | |
2004 | ||
2005 | default: | |
2006 | internalError (); | |
2007 | } | |
2008 | } | |
2009 | else | |
2010 | { | |
2011 | need_reloc: | |
f6688943 | 2012 | /* Don't generate a reloc if we are writing into a variant frag. */ |
252b5132 RH |
2013 | if (place == NULL) |
2014 | { | |
f6688943 TS |
2015 | fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4, |
2016 | address_expr, | |
2017 | (*reloc_type == BFD_RELOC_16_PCREL | |
2018 | || *reloc_type == BFD_RELOC_16_PCREL_S2), | |
2019 | reloc_type[0]); | |
2020 | ||
b6ff326e | 2021 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
2022 | 4 octets for 64bit assembly. */ |
2023 | if (HAVE_64BIT_GPRS && | |
2024 | (*reloc_type == BFD_RELOC_16 | |
2025 | || *reloc_type == BFD_RELOC_32 | |
2026 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2027 | || *reloc_type == BFD_RELOC_HI16_S | |
2028 | || *reloc_type == BFD_RELOC_LO16 | |
2029 | || *reloc_type == BFD_RELOC_GPREL16 | |
2030 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2031 | || *reloc_type == BFD_RELOC_GPREL32 | |
2032 | || *reloc_type == BFD_RELOC_64 | |
2033 | || *reloc_type == BFD_RELOC_CTOR | |
2034 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2035 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2036 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2037 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2038 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2039 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
2040 | fixp[0]->fx_no_overflow = 1; | |
2041 | ||
252b5132 RH |
2042 | if (unmatched_hi) |
2043 | { | |
2044 | struct mips_hi_fixup *hi_fixup; | |
2045 | ||
f6688943 | 2046 | assert (*reloc_type == BFD_RELOC_HI16_S); |
252b5132 RH |
2047 | hi_fixup = ((struct mips_hi_fixup *) |
2048 | xmalloc (sizeof (struct mips_hi_fixup))); | |
f6688943 | 2049 | hi_fixup->fixp = fixp[0]; |
252b5132 RH |
2050 | hi_fixup->seg = now_seg; |
2051 | hi_fixup->next = mips_hi_fixup_list; | |
2052 | mips_hi_fixup_list = hi_fixup; | |
2053 | } | |
f6688943 TS |
2054 | |
2055 | if (reloc_type[1] != BFD_RELOC_UNUSED) | |
2056 | { | |
2057 | /* FIXME: This symbol can be one of | |
2058 | RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */ | |
2059 | address_expr->X_op = O_absent; | |
2060 | address_expr->X_add_symbol = 0; | |
2061 | address_expr->X_add_number = 0; | |
2062 | ||
2063 | fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal, | |
2064 | 4, address_expr, false, | |
2065 | reloc_type[1]); | |
2066 | ||
b6ff326e | 2067 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
2068 | 4 octets for 64bit assembly. */ |
2069 | if (HAVE_64BIT_GPRS && | |
2070 | (*reloc_type == BFD_RELOC_16 | |
2071 | || *reloc_type == BFD_RELOC_32 | |
2072 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2073 | || *reloc_type == BFD_RELOC_HI16_S | |
2074 | || *reloc_type == BFD_RELOC_LO16 | |
2075 | || *reloc_type == BFD_RELOC_GPREL16 | |
2076 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2077 | || *reloc_type == BFD_RELOC_GPREL32 | |
2078 | || *reloc_type == BFD_RELOC_64 | |
2079 | || *reloc_type == BFD_RELOC_CTOR | |
2080 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2081 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2082 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2083 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2084 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2085 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
2086 | fixp[1]->fx_no_overflow = 1; | |
2087 | ||
2088 | if (reloc_type[2] != BFD_RELOC_UNUSED) | |
2089 | { | |
2090 | address_expr->X_op = O_absent; | |
2091 | address_expr->X_add_symbol = 0; | |
2092 | address_expr->X_add_number = 0; | |
2093 | ||
2094 | fixp[2] = fix_new_exp (frag_now, | |
2095 | f - frag_now->fr_literal, 4, | |
2096 | address_expr, false, | |
2097 | reloc_type[2]); | |
2098 | ||
b6ff326e | 2099 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
2100 | 4 octets for 64bit assembly. */ |
2101 | if (HAVE_64BIT_GPRS && | |
2102 | (*reloc_type == BFD_RELOC_16 | |
2103 | || *reloc_type == BFD_RELOC_32 | |
2104 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2105 | || *reloc_type == BFD_RELOC_HI16_S | |
2106 | || *reloc_type == BFD_RELOC_LO16 | |
2107 | || *reloc_type == BFD_RELOC_GPREL16 | |
2108 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2109 | || *reloc_type == BFD_RELOC_GPREL32 | |
2110 | || *reloc_type == BFD_RELOC_64 | |
2111 | || *reloc_type == BFD_RELOC_CTOR | |
2112 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2113 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2114 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2115 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2116 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2117 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
2118 | fixp[2]->fx_no_overflow = 1; | |
2119 | } | |
2120 | } | |
252b5132 RH |
2121 | } |
2122 | } | |
2123 | } | |
2124 | ||
2125 | if (! mips_opts.mips16) | |
2126 | md_number_to_chars (f, ip->insn_opcode, 4); | |
f6688943 | 2127 | else if (*reloc_type == BFD_RELOC_MIPS16_JMP) |
252b5132 RH |
2128 | { |
2129 | md_number_to_chars (f, ip->insn_opcode >> 16, 2); | |
2130 | md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2); | |
2131 | } | |
2132 | else | |
2133 | { | |
2134 | if (ip->use_extend) | |
2135 | { | |
2136 | md_number_to_chars (f, 0xf000 | ip->extend, 2); | |
2137 | f += 2; | |
2138 | } | |
2139 | md_number_to_chars (f, ip->insn_opcode, 2); | |
2140 | } | |
2141 | ||
2142 | /* Update the register mask information. */ | |
2143 | if (! mips_opts.mips16) | |
2144 | { | |
2145 | if (pinfo & INSN_WRITE_GPR_D) | |
2146 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD); | |
2147 | if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0) | |
2148 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT); | |
2149 | if (pinfo & INSN_READ_GPR_S) | |
2150 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS); | |
2151 | if (pinfo & INSN_WRITE_GPR_31) | |
2152 | mips_gprmask |= 1 << 31; | |
2153 | if (pinfo & INSN_WRITE_FPR_D) | |
2154 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD); | |
2155 | if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0) | |
2156 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS); | |
2157 | if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0) | |
2158 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT); | |
2159 | if ((pinfo & INSN_READ_FPR_R) != 0) | |
2160 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR); | |
2161 | if (pinfo & INSN_COP) | |
2162 | { | |
bdaaa2e1 KH |
2163 | /* We don't keep enough information to sort these cases out. |
2164 | The itbl support does keep this information however, although | |
2165 | we currently don't support itbl fprmats as part of the cop | |
2166 | instruction. May want to add this support in the future. */ | |
252b5132 RH |
2167 | } |
2168 | /* Never set the bit for $0, which is always zero. */ | |
beae10d5 | 2169 | mips_gprmask &= ~1 << 0; |
252b5132 RH |
2170 | } |
2171 | else | |
2172 | { | |
2173 | if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X)) | |
2174 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX) | |
2175 | & MIPS16OP_MASK_RX); | |
2176 | if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y)) | |
2177 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY) | |
2178 | & MIPS16OP_MASK_RY); | |
2179 | if (pinfo & MIPS16_INSN_WRITE_Z) | |
2180 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ) | |
2181 | & MIPS16OP_MASK_RZ); | |
2182 | if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T)) | |
2183 | mips_gprmask |= 1 << TREG; | |
2184 | if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP)) | |
2185 | mips_gprmask |= 1 << SP; | |
2186 | if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31)) | |
2187 | mips_gprmask |= 1 << RA; | |
2188 | if (pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2189 | mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode); | |
2190 | if (pinfo & MIPS16_INSN_READ_Z) | |
2191 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
2192 | & MIPS16OP_MASK_MOVE32Z); | |
2193 | if (pinfo & MIPS16_INSN_READ_GPR_X) | |
2194 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
2195 | & MIPS16OP_MASK_REGR32); | |
2196 | } | |
2197 | ||
2198 | if (place == NULL && ! mips_opts.noreorder) | |
2199 | { | |
2200 | /* Filling the branch delay slot is more complex. We try to | |
2201 | switch the branch with the previous instruction, which we can | |
2202 | do if the previous instruction does not set up a condition | |
2203 | that the branch tests and if the branch is not itself the | |
2204 | target of any branch. */ | |
2205 | if ((pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2206 | || (pinfo & INSN_COND_BRANCH_DELAY)) | |
2207 | { | |
2208 | if (mips_optimize < 2 | |
2209 | /* If we have seen .set volatile or .set nomove, don't | |
2210 | optimize. */ | |
2211 | || mips_opts.nomove != 0 | |
2212 | /* If we had to emit any NOP instructions, then we | |
2213 | already know we can not swap. */ | |
2214 | || nops != 0 | |
2215 | /* If we don't even know the previous insn, we can not | |
bdaaa2e1 | 2216 | swap. */ |
252b5132 RH |
2217 | || ! prev_insn_valid |
2218 | /* If the previous insn is already in a branch delay | |
2219 | slot, then we can not swap. */ | |
2220 | || prev_insn_is_delay_slot | |
2221 | /* If the previous previous insn was in a .set | |
2222 | noreorder, we can't swap. Actually, the MIPS | |
2223 | assembler will swap in this situation. However, gcc | |
2224 | configured -with-gnu-as will generate code like | |
2225 | .set noreorder | |
2226 | lw $4,XXX | |
2227 | .set reorder | |
2228 | INSN | |
2229 | bne $4,$0,foo | |
2230 | in which we can not swap the bne and INSN. If gcc is | |
2231 | not configured -with-gnu-as, it does not output the | |
2232 | .set pseudo-ops. We don't have to check | |
2233 | prev_insn_unreordered, because prev_insn_valid will | |
2234 | be 0 in that case. We don't want to use | |
2235 | prev_prev_insn_valid, because we do want to be able | |
2236 | to swap at the start of a function. */ | |
2237 | || prev_prev_insn_unreordered | |
2238 | /* If the branch is itself the target of a branch, we | |
2239 | can not swap. We cheat on this; all we check for is | |
2240 | whether there is a label on this instruction. If | |
2241 | there are any branches to anything other than a | |
2242 | label, users must use .set noreorder. */ | |
2243 | || insn_labels != NULL | |
2244 | /* If the previous instruction is in a variant frag, we | |
2245 | can not do the swap. This does not apply to the | |
2246 | mips16, which uses variant frags for different | |
2247 | purposes. */ | |
2248 | || (! mips_opts.mips16 | |
2249 | && prev_insn_frag->fr_type == rs_machine_dependent) | |
2250 | /* If the branch reads the condition codes, we don't | |
2251 | even try to swap, because in the sequence | |
2252 | ctc1 $X,$31 | |
2253 | INSN | |
2254 | INSN | |
2255 | bc1t LABEL | |
2256 | we can not swap, and I don't feel like handling that | |
2257 | case. */ | |
2258 | || (! mips_opts.mips16 | |
9ce8a5dd | 2259 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2260 | && (pinfo & INSN_READ_COND_CODE)) |
2261 | /* We can not swap with an instruction that requires a | |
2262 | delay slot, becase the target of the branch might | |
2263 | interfere with that instruction. */ | |
2264 | || (! mips_opts.mips16 | |
9ce8a5dd | 2265 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 2266 | && (prev_pinfo |
bdaaa2e1 | 2267 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2268 | & (INSN_LOAD_COPROC_DELAY |
2269 | | INSN_COPROC_MOVE_DELAY | |
2270 | | INSN_WRITE_COND_CODE))) | |
2271 | || (! (hilo_interlocks | |
ec68c924 | 2272 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
2273 | && (prev_pinfo |
2274 | & (INSN_READ_LO | |
2275 | | INSN_READ_HI))) | |
2276 | || (! mips_opts.mips16 | |
2277 | && ! gpr_interlocks | |
2278 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)) | |
2279 | || (! mips_opts.mips16 | |
e7af610e | 2280 | && mips_opts.isa == ISA_MIPS1 |
bdaaa2e1 | 2281 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2282 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)) |
2283 | /* We can not swap with a branch instruction. */ | |
2284 | || (prev_pinfo | |
2285 | & (INSN_UNCOND_BRANCH_DELAY | |
2286 | | INSN_COND_BRANCH_DELAY | |
2287 | | INSN_COND_BRANCH_LIKELY)) | |
2288 | /* We do not swap with a trap instruction, since it | |
2289 | complicates trap handlers to have the trap | |
2290 | instruction be in a delay slot. */ | |
2291 | || (prev_pinfo & INSN_TRAP) | |
2292 | /* If the branch reads a register that the previous | |
2293 | instruction sets, we can not swap. */ | |
2294 | || (! mips_opts.mips16 | |
2295 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2296 | && insn_uses_reg (ip, | |
2297 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
2298 | & OP_MASK_RT), | |
2299 | MIPS_GR_REG)) | |
2300 | || (! mips_opts.mips16 | |
2301 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2302 | && insn_uses_reg (ip, | |
2303 | ((prev_insn.insn_opcode >> OP_SH_RD) | |
2304 | & OP_MASK_RD), | |
2305 | MIPS_GR_REG)) | |
2306 | || (mips_opts.mips16 | |
2307 | && (((prev_pinfo & MIPS16_INSN_WRITE_X) | |
2308 | && insn_uses_reg (ip, | |
2309 | ((prev_insn.insn_opcode | |
2310 | >> MIPS16OP_SH_RX) | |
2311 | & MIPS16OP_MASK_RX), | |
2312 | MIPS16_REG)) | |
2313 | || ((prev_pinfo & MIPS16_INSN_WRITE_Y) | |
2314 | && insn_uses_reg (ip, | |
2315 | ((prev_insn.insn_opcode | |
2316 | >> MIPS16OP_SH_RY) | |
2317 | & MIPS16OP_MASK_RY), | |
2318 | MIPS16_REG)) | |
2319 | || ((prev_pinfo & MIPS16_INSN_WRITE_Z) | |
2320 | && insn_uses_reg (ip, | |
2321 | ((prev_insn.insn_opcode | |
2322 | >> MIPS16OP_SH_RZ) | |
2323 | & MIPS16OP_MASK_RZ), | |
2324 | MIPS16_REG)) | |
2325 | || ((prev_pinfo & MIPS16_INSN_WRITE_T) | |
2326 | && insn_uses_reg (ip, TREG, MIPS_GR_REG)) | |
2327 | || ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2328 | && insn_uses_reg (ip, RA, MIPS_GR_REG)) | |
2329 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2330 | && insn_uses_reg (ip, | |
2331 | MIPS16OP_EXTRACT_REG32R (prev_insn. | |
2332 | insn_opcode), | |
2333 | MIPS_GR_REG)))) | |
2334 | /* If the branch writes a register that the previous | |
2335 | instruction sets, we can not swap (we know that | |
2336 | branches write only to RD or to $31). */ | |
2337 | || (! mips_opts.mips16 | |
2338 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2339 | && (((pinfo & INSN_WRITE_GPR_D) | |
2340 | && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT) | |
2341 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2342 | || ((pinfo & INSN_WRITE_GPR_31) | |
2343 | && (((prev_insn.insn_opcode >> OP_SH_RT) | |
2344 | & OP_MASK_RT) | |
2345 | == 31)))) | |
2346 | || (! mips_opts.mips16 | |
2347 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2348 | && (((pinfo & INSN_WRITE_GPR_D) | |
2349 | && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD) | |
2350 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2351 | || ((pinfo & INSN_WRITE_GPR_31) | |
2352 | && (((prev_insn.insn_opcode >> OP_SH_RD) | |
2353 | & OP_MASK_RD) | |
2354 | == 31)))) | |
2355 | || (mips_opts.mips16 | |
2356 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2357 | && ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2358 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2359 | && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode) | |
2360 | == RA)))) | |
2361 | /* If the branch writes a register that the previous | |
2362 | instruction reads, we can not swap (we know that | |
2363 | branches only write to RD or to $31). */ | |
2364 | || (! mips_opts.mips16 | |
2365 | && (pinfo & INSN_WRITE_GPR_D) | |
2366 | && insn_uses_reg (&prev_insn, | |
2367 | ((ip->insn_opcode >> OP_SH_RD) | |
2368 | & OP_MASK_RD), | |
2369 | MIPS_GR_REG)) | |
2370 | || (! mips_opts.mips16 | |
2371 | && (pinfo & INSN_WRITE_GPR_31) | |
2372 | && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG)) | |
2373 | || (mips_opts.mips16 | |
2374 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2375 | && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG)) | |
2376 | /* If we are generating embedded PIC code, the branch | |
2377 | might be expanded into a sequence which uses $at, so | |
2378 | we can't swap with an instruction which reads it. */ | |
2379 | || (mips_pic == EMBEDDED_PIC | |
2380 | && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG)) | |
2381 | /* If the previous previous instruction has a load | |
2382 | delay, and sets a register that the branch reads, we | |
2383 | can not swap. */ | |
2384 | || (! mips_opts.mips16 | |
9ce8a5dd | 2385 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
bdaaa2e1 | 2386 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2387 | && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY) |
2388 | || (! gpr_interlocks | |
2389 | && (prev_prev_insn.insn_mo->pinfo | |
2390 | & INSN_LOAD_MEMORY_DELAY))) | |
2391 | && insn_uses_reg (ip, | |
2392 | ((prev_prev_insn.insn_opcode >> OP_SH_RT) | |
2393 | & OP_MASK_RT), | |
2394 | MIPS_GR_REG)) | |
2395 | /* If one instruction sets a condition code and the | |
2396 | other one uses a condition code, we can not swap. */ | |
2397 | || ((pinfo & INSN_READ_COND_CODE) | |
2398 | && (prev_pinfo & INSN_WRITE_COND_CODE)) | |
2399 | || ((pinfo & INSN_WRITE_COND_CODE) | |
2400 | && (prev_pinfo & INSN_READ_COND_CODE)) | |
2401 | /* If the previous instruction uses the PC, we can not | |
2402 | swap. */ | |
2403 | || (mips_opts.mips16 | |
2404 | && (prev_pinfo & MIPS16_INSN_READ_PC)) | |
2405 | /* If the previous instruction was extended, we can not | |
2406 | swap. */ | |
2407 | || (mips_opts.mips16 && prev_insn_extended) | |
2408 | /* If the previous instruction had a fixup in mips16 | |
2409 | mode, we can not swap. This normally means that the | |
2410 | previous instruction was a 4 byte branch anyhow. */ | |
f6688943 | 2411 | || (mips_opts.mips16 && prev_insn_fixp[0]) |
bdaaa2e1 KH |
2412 | /* If the previous instruction is a sync, sync.l, or |
2413 | sync.p, we can not swap. */ | |
f173e82e | 2414 | || (prev_pinfo & INSN_SYNC)) |
252b5132 RH |
2415 | { |
2416 | /* We could do even better for unconditional branches to | |
2417 | portions of this object file; we could pick up the | |
2418 | instruction at the destination, put it in the delay | |
2419 | slot, and bump the destination address. */ | |
2420 | emit_nop (); | |
2421 | /* Update the previous insn information. */ | |
2422 | prev_prev_insn = *ip; | |
2423 | prev_insn.insn_mo = &dummy_opcode; | |
2424 | } | |
2425 | else | |
2426 | { | |
2427 | /* It looks like we can actually do the swap. */ | |
2428 | if (! mips_opts.mips16) | |
2429 | { | |
2430 | char *prev_f; | |
2431 | char temp[4]; | |
2432 | ||
2433 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2434 | memcpy (temp, prev_f, 4); | |
2435 | memcpy (prev_f, f, 4); | |
2436 | memcpy (f, temp, 4); | |
f6688943 TS |
2437 | if (prev_insn_fixp[0]) |
2438 | { | |
2439 | prev_insn_fixp[0]->fx_frag = frag_now; | |
2440 | prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal; | |
2441 | } | |
2442 | if (prev_insn_fixp[1]) | |
2443 | { | |
2444 | prev_insn_fixp[1]->fx_frag = frag_now; | |
2445 | prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal; | |
2446 | } | |
2447 | if (prev_insn_fixp[2]) | |
252b5132 | 2448 | { |
f6688943 TS |
2449 | prev_insn_fixp[2]->fx_frag = frag_now; |
2450 | prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal; | |
252b5132 | 2451 | } |
f6688943 | 2452 | if (fixp[0]) |
252b5132 | 2453 | { |
f6688943 TS |
2454 | fixp[0]->fx_frag = prev_insn_frag; |
2455 | fixp[0]->fx_where = prev_insn_where; | |
2456 | } | |
2457 | if (fixp[1]) | |
2458 | { | |
2459 | fixp[1]->fx_frag = prev_insn_frag; | |
2460 | fixp[1]->fx_where = prev_insn_where; | |
2461 | } | |
2462 | if (fixp[2]) | |
2463 | { | |
2464 | fixp[2]->fx_frag = prev_insn_frag; | |
2465 | fixp[2]->fx_where = prev_insn_where; | |
252b5132 RH |
2466 | } |
2467 | } | |
2468 | else | |
2469 | { | |
2470 | char *prev_f; | |
2471 | char temp[2]; | |
2472 | ||
f6688943 TS |
2473 | assert (prev_insn_fixp[0] == NULL); |
2474 | assert (prev_insn_fixp[1] == NULL); | |
2475 | assert (prev_insn_fixp[2] == NULL); | |
252b5132 RH |
2476 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; |
2477 | memcpy (temp, prev_f, 2); | |
2478 | memcpy (prev_f, f, 2); | |
f6688943 | 2479 | if (*reloc_type != BFD_RELOC_MIPS16_JMP) |
252b5132 | 2480 | { |
f6688943 | 2481 | assert (*reloc_type == BFD_RELOC_UNUSED); |
252b5132 RH |
2482 | memcpy (f, temp, 2); |
2483 | } | |
2484 | else | |
2485 | { | |
2486 | memcpy (f, f + 2, 2); | |
2487 | memcpy (f + 2, temp, 2); | |
2488 | } | |
f6688943 TS |
2489 | if (fixp[0]) |
2490 | { | |
2491 | fixp[0]->fx_frag = prev_insn_frag; | |
2492 | fixp[0]->fx_where = prev_insn_where; | |
2493 | } | |
2494 | if (fixp[1]) | |
2495 | { | |
2496 | fixp[1]->fx_frag = prev_insn_frag; | |
2497 | fixp[1]->fx_where = prev_insn_where; | |
2498 | } | |
2499 | if (fixp[2]) | |
252b5132 | 2500 | { |
f6688943 TS |
2501 | fixp[2]->fx_frag = prev_insn_frag; |
2502 | fixp[2]->fx_where = prev_insn_where; | |
252b5132 RH |
2503 | } |
2504 | } | |
2505 | ||
2506 | /* Update the previous insn information; leave prev_insn | |
2507 | unchanged. */ | |
2508 | prev_prev_insn = *ip; | |
2509 | } | |
2510 | prev_insn_is_delay_slot = 1; | |
2511 | ||
2512 | /* If that was an unconditional branch, forget the previous | |
2513 | insn information. */ | |
2514 | if (pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2515 | { | |
2516 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2517 | prev_insn.insn_mo = &dummy_opcode; | |
2518 | } | |
2519 | ||
f6688943 TS |
2520 | prev_insn_fixp[0] = NULL; |
2521 | prev_insn_fixp[1] = NULL; | |
2522 | prev_insn_fixp[2] = NULL; | |
2523 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; | |
2524 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2525 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2526 | prev_insn_extended = 0; |
2527 | } | |
2528 | else if (pinfo & INSN_COND_BRANCH_LIKELY) | |
2529 | { | |
2530 | /* We don't yet optimize a branch likely. What we should do | |
2531 | is look at the target, copy the instruction found there | |
2532 | into the delay slot, and increment the branch to jump to | |
2533 | the next instruction. */ | |
2534 | emit_nop (); | |
2535 | /* Update the previous insn information. */ | |
2536 | prev_prev_insn = *ip; | |
2537 | prev_insn.insn_mo = &dummy_opcode; | |
f6688943 TS |
2538 | prev_insn_fixp[0] = NULL; |
2539 | prev_insn_fixp[1] = NULL; | |
2540 | prev_insn_fixp[2] = NULL; | |
2541 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; | |
2542 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2543 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2544 | prev_insn_extended = 0; |
2545 | } | |
2546 | else | |
2547 | { | |
2548 | /* Update the previous insn information. */ | |
2549 | if (nops > 0) | |
2550 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2551 | else | |
2552 | prev_prev_insn = prev_insn; | |
2553 | prev_insn = *ip; | |
2554 | ||
2555 | /* Any time we see a branch, we always fill the delay slot | |
2556 | immediately; since this insn is not a branch, we know it | |
2557 | is not in a delay slot. */ | |
2558 | prev_insn_is_delay_slot = 0; | |
2559 | ||
f6688943 TS |
2560 | prev_insn_fixp[0] = fixp[0]; |
2561 | prev_insn_fixp[1] = fixp[1]; | |
2562 | prev_insn_fixp[2] = fixp[2]; | |
2563 | prev_insn_reloc_type[0] = reloc_type[0]; | |
2564 | prev_insn_reloc_type[1] = reloc_type[1]; | |
2565 | prev_insn_reloc_type[2] = reloc_type[2]; | |
252b5132 RH |
2566 | if (mips_opts.mips16) |
2567 | prev_insn_extended = (ip->use_extend | |
f6688943 | 2568 | || *reloc_type > BFD_RELOC_UNUSED); |
252b5132 RH |
2569 | } |
2570 | ||
2571 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2572 | prev_insn_unreordered = 0; | |
2573 | prev_insn_frag = frag_now; | |
2574 | prev_insn_where = f - frag_now->fr_literal; | |
2575 | prev_insn_valid = 1; | |
2576 | } | |
2577 | else if (place == NULL) | |
2578 | { | |
2579 | /* We need to record a bit of information even when we are not | |
2580 | reordering, in order to determine the base address for mips16 | |
2581 | PC relative relocs. */ | |
2582 | prev_prev_insn = prev_insn; | |
2583 | prev_insn = *ip; | |
f6688943 TS |
2584 | prev_insn_reloc_type[0] = reloc_type[0]; |
2585 | prev_insn_reloc_type[1] = reloc_type[1]; | |
2586 | prev_insn_reloc_type[2] = reloc_type[2]; | |
252b5132 RH |
2587 | prev_prev_insn_unreordered = prev_insn_unreordered; |
2588 | prev_insn_unreordered = 1; | |
2589 | } | |
2590 | ||
2591 | /* We just output an insn, so the next one doesn't have a label. */ | |
2592 | mips_clear_insn_labels (); | |
2593 | ||
2594 | /* We must ensure that a fixup associated with an unmatched %hi | |
2595 | reloc does not become a variant frag. Otherwise, the | |
2596 | rearrangement of %hi relocs in frob_file may confuse | |
2597 | tc_gen_reloc. */ | |
2598 | if (unmatched_hi) | |
2599 | { | |
2600 | frag_wane (frag_now); | |
2601 | frag_new (0); | |
2602 | } | |
2603 | } | |
2604 | ||
2605 | /* This function forgets that there was any previous instruction or | |
2606 | label. If PRESERVE is non-zero, it remembers enough information to | |
bdaaa2e1 | 2607 | know whether nops are needed before a noreorder section. */ |
252b5132 RH |
2608 | |
2609 | static void | |
2610 | mips_no_prev_insn (preserve) | |
2611 | int preserve; | |
2612 | { | |
2613 | if (! preserve) | |
2614 | { | |
2615 | prev_insn.insn_mo = &dummy_opcode; | |
2616 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2617 | prev_nop_frag = NULL; | |
2618 | prev_nop_frag_holds = 0; | |
2619 | prev_nop_frag_required = 0; | |
2620 | prev_nop_frag_since = 0; | |
2621 | } | |
2622 | prev_insn_valid = 0; | |
2623 | prev_insn_is_delay_slot = 0; | |
2624 | prev_insn_unreordered = 0; | |
2625 | prev_insn_extended = 0; | |
f6688943 TS |
2626 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; |
2627 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2628 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2629 | prev_prev_insn_unreordered = 0; |
2630 | mips_clear_insn_labels (); | |
2631 | } | |
2632 | ||
2633 | /* This function must be called whenever we turn on noreorder or emit | |
2634 | something other than instructions. It inserts any NOPS which might | |
2635 | be needed by the previous instruction, and clears the information | |
2636 | kept for the previous instructions. The INSNS parameter is true if | |
bdaaa2e1 | 2637 | instructions are to follow. */ |
252b5132 RH |
2638 | |
2639 | static void | |
2640 | mips_emit_delays (insns) | |
2641 | boolean insns; | |
2642 | { | |
2643 | if (! mips_opts.noreorder) | |
2644 | { | |
2645 | int nops; | |
2646 | ||
2647 | nops = 0; | |
2648 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2649 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2650 | && (! cop_interlocks |
2651 | && (prev_insn.insn_mo->pinfo | |
2652 | & (INSN_LOAD_COPROC_DELAY | |
2653 | | INSN_COPROC_MOVE_DELAY | |
2654 | | INSN_WRITE_COND_CODE)))) | |
2655 | || (! hilo_interlocks | |
2656 | && (prev_insn.insn_mo->pinfo | |
2657 | & (INSN_READ_LO | |
2658 | | INSN_READ_HI))) | |
2659 | || (! mips_opts.mips16 | |
2660 | && ! gpr_interlocks | |
bdaaa2e1 | 2661 | && (prev_insn.insn_mo->pinfo |
252b5132 RH |
2662 | & INSN_LOAD_MEMORY_DELAY)) |
2663 | || (! mips_opts.mips16 | |
e7af610e | 2664 | && mips_opts.isa == ISA_MIPS1 |
252b5132 RH |
2665 | && (prev_insn.insn_mo->pinfo |
2666 | & INSN_COPROC_MEMORY_DELAY))) | |
2667 | { | |
beae10d5 | 2668 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2669 | ++nops; |
2670 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2671 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2672 | && (! cop_interlocks |
2673 | && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2674 | || (! hilo_interlocks | |
2675 | && ((prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2676 | || (prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2677 | ++nops; | |
2678 | ||
2679 | if (prev_insn_unreordered) | |
2680 | nops = 0; | |
2681 | } | |
2682 | else if ((! mips_opts.mips16 | |
9ce8a5dd | 2683 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2684 | && (! cop_interlocks |
2685 | && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2686 | || (! hilo_interlocks | |
2687 | && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2688 | || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2689 | { | |
beae10d5 | 2690 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2691 | if (! prev_prev_insn_unreordered) |
2692 | ++nops; | |
2693 | } | |
2694 | ||
2695 | if (nops > 0) | |
2696 | { | |
2697 | struct insn_label_list *l; | |
2698 | ||
2699 | if (insns) | |
2700 | { | |
2701 | /* Record the frag which holds the nop instructions, so | |
2702 | that we can remove them if we don't need them. */ | |
2703 | frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4); | |
2704 | prev_nop_frag = frag_now; | |
2705 | prev_nop_frag_holds = nops; | |
2706 | prev_nop_frag_required = 0; | |
2707 | prev_nop_frag_since = 0; | |
2708 | } | |
2709 | ||
2710 | for (; nops > 0; --nops) | |
2711 | emit_nop (); | |
2712 | ||
2713 | if (insns) | |
2714 | { | |
2715 | /* Move on to a new frag, so that it is safe to simply | |
bdaaa2e1 | 2716 | decrease the size of prev_nop_frag. */ |
252b5132 RH |
2717 | frag_wane (frag_now); |
2718 | frag_new (0); | |
2719 | } | |
2720 | ||
2721 | for (l = insn_labels; l != NULL; l = l->next) | |
2722 | { | |
98aa84af AM |
2723 | valueT val; |
2724 | ||
252b5132 | 2725 | assert (S_GET_SEGMENT (l->label) == now_seg); |
49309057 | 2726 | symbol_set_frag (l->label, frag_now); |
98aa84af | 2727 | val = (valueT) frag_now_fix (); |
252b5132 RH |
2728 | /* mips16 text labels are stored as odd. */ |
2729 | if (mips_opts.mips16) | |
98aa84af AM |
2730 | val += 1; |
2731 | S_SET_VALUE (l->label, val); | |
252b5132 RH |
2732 | } |
2733 | } | |
2734 | } | |
2735 | ||
2736 | /* Mark instruction labels in mips16 mode. */ | |
2737 | if (mips_opts.mips16 && insns) | |
2738 | mips16_mark_labels (); | |
2739 | ||
2740 | mips_no_prev_insn (insns); | |
2741 | } | |
2742 | ||
2743 | /* Build an instruction created by a macro expansion. This is passed | |
2744 | a pointer to the count of instructions created so far, an | |
2745 | expression, the name of the instruction to build, an operand format | |
2746 | string, and corresponding arguments. */ | |
2747 | ||
2748 | #ifdef USE_STDARG | |
2749 | static void | |
2750 | macro_build (char *place, | |
2751 | int *counter, | |
2752 | expressionS * ep, | |
2753 | const char *name, | |
2754 | const char *fmt, | |
2755 | ...) | |
2756 | #else | |
2757 | static void | |
2758 | macro_build (place, counter, ep, name, fmt, va_alist) | |
2759 | char *place; | |
2760 | int *counter; | |
2761 | expressionS *ep; | |
2762 | const char *name; | |
2763 | const char *fmt; | |
2764 | va_dcl | |
2765 | #endif | |
2766 | { | |
2767 | struct mips_cl_insn insn; | |
f6688943 | 2768 | bfd_reloc_code_real_type r[3]; |
252b5132 | 2769 | va_list args; |
252b5132 RH |
2770 | |
2771 | #ifdef USE_STDARG | |
2772 | va_start (args, fmt); | |
2773 | #else | |
2774 | va_start (args); | |
2775 | #endif | |
2776 | ||
2777 | /* | |
2778 | * If the macro is about to expand into a second instruction, | |
2779 | * print a warning if needed. We need to pass ip as a parameter | |
2780 | * to generate a better warning message here... | |
2781 | */ | |
2782 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2783 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2784 | ||
2785 | if (place == NULL) | |
2786 | *counter += 1; /* bump instruction counter */ | |
2787 | ||
2788 | if (mips_opts.mips16) | |
2789 | { | |
2790 | mips16_macro_build (place, counter, ep, name, fmt, args); | |
2791 | va_end (args); | |
2792 | return; | |
2793 | } | |
2794 | ||
f6688943 TS |
2795 | r[0] = BFD_RELOC_UNUSED; |
2796 | r[1] = BFD_RELOC_UNUSED; | |
2797 | r[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2798 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); |
2799 | assert (insn.insn_mo); | |
2800 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2801 | ||
2802 | /* Search until we get a match for NAME. */ | |
2803 | while (1) | |
2804 | { | |
252b5132 RH |
2805 | if (strcmp (fmt, insn.insn_mo->args) == 0 |
2806 | && insn.insn_mo->pinfo != INSN_MACRO | |
ea1fb5dc | 2807 | && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch) |
ec68c924 | 2808 | && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0)) |
252b5132 RH |
2809 | break; |
2810 | ||
2811 | ++insn.insn_mo; | |
2812 | assert (insn.insn_mo->name); | |
2813 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2814 | } | |
2815 | ||
2816 | insn.insn_opcode = insn.insn_mo->match; | |
2817 | for (;;) | |
2818 | { | |
2819 | switch (*fmt++) | |
2820 | { | |
2821 | case '\0': | |
2822 | break; | |
2823 | ||
2824 | case ',': | |
2825 | case '(': | |
2826 | case ')': | |
2827 | continue; | |
2828 | ||
2829 | case 't': | |
2830 | case 'w': | |
2831 | case 'E': | |
38487616 | 2832 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RT; |
252b5132 RH |
2833 | continue; |
2834 | ||
2835 | case 'c': | |
38487616 TS |
2836 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE; |
2837 | continue; | |
2838 | ||
252b5132 RH |
2839 | case 'T': |
2840 | case 'W': | |
38487616 | 2841 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FT; |
252b5132 RH |
2842 | continue; |
2843 | ||
2844 | case 'd': | |
2845 | case 'G': | |
38487616 | 2846 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RD; |
252b5132 RH |
2847 | continue; |
2848 | ||
4372b673 NC |
2849 | case 'U': |
2850 | { | |
2851 | int tmp = va_arg (args, int); | |
2852 | ||
38487616 TS |
2853 | insn.insn_opcode |= tmp << OP_SH_RT; |
2854 | insn.insn_opcode |= tmp << OP_SH_RD; | |
beae10d5 | 2855 | continue; |
4372b673 NC |
2856 | } |
2857 | ||
252b5132 RH |
2858 | case 'V': |
2859 | case 'S': | |
38487616 | 2860 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FS; |
252b5132 RH |
2861 | continue; |
2862 | ||
2863 | case 'z': | |
2864 | continue; | |
2865 | ||
2866 | case '<': | |
38487616 | 2867 | insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT; |
252b5132 RH |
2868 | continue; |
2869 | ||
2870 | case 'D': | |
38487616 | 2871 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FD; |
252b5132 RH |
2872 | continue; |
2873 | ||
2874 | case 'B': | |
38487616 | 2875 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20; |
252b5132 RH |
2876 | continue; |
2877 | ||
4372b673 | 2878 | case 'J': |
38487616 | 2879 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19; |
4372b673 NC |
2880 | continue; |
2881 | ||
252b5132 | 2882 | case 'q': |
38487616 | 2883 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2; |
252b5132 RH |
2884 | continue; |
2885 | ||
2886 | case 'b': | |
2887 | case 's': | |
2888 | case 'r': | |
2889 | case 'v': | |
38487616 | 2890 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RS; |
252b5132 RH |
2891 | continue; |
2892 | ||
2893 | case 'i': | |
2894 | case 'j': | |
2895 | case 'o': | |
f6688943 | 2896 | *r = (bfd_reloc_code_real_type) va_arg (args, int); |
cdf6fd85 | 2897 | assert (*r == BFD_RELOC_GPREL16 |
f6688943 TS |
2898 | || *r == BFD_RELOC_MIPS_LITERAL |
2899 | || *r == BFD_RELOC_MIPS_HIGHER | |
2900 | || *r == BFD_RELOC_HI16_S | |
2901 | || *r == BFD_RELOC_LO16 | |
2902 | || *r == BFD_RELOC_MIPS_GOT16 | |
2903 | || *r == BFD_RELOC_MIPS_CALL16 | |
2904 | || *r == BFD_RELOC_MIPS_GOT_LO16 | |
2905 | || *r == BFD_RELOC_MIPS_CALL_LO16 | |
252b5132 | 2906 | || (ep->X_op == O_subtract |
f6688943 | 2907 | && *r == BFD_RELOC_PCREL_LO16)); |
252b5132 RH |
2908 | continue; |
2909 | ||
2910 | case 'u': | |
f6688943 | 2911 | *r = (bfd_reloc_code_real_type) va_arg (args, int); |
252b5132 RH |
2912 | assert (ep != NULL |
2913 | && (ep->X_op == O_constant | |
2914 | || (ep->X_op == O_symbol | |
f6688943 TS |
2915 | && (*r == BFD_RELOC_MIPS_HIGHEST |
2916 | || *r == BFD_RELOC_HI16_S | |
2917 | || *r == BFD_RELOC_HI16 | |
2918 | || *r == BFD_RELOC_GPREL16 | |
2919 | || *r == BFD_RELOC_MIPS_GOT_HI16 | |
2920 | || *r == BFD_RELOC_MIPS_CALL_HI16)) | |
252b5132 | 2921 | || (ep->X_op == O_subtract |
f6688943 | 2922 | && *r == BFD_RELOC_PCREL_HI16_S))); |
252b5132 RH |
2923 | continue; |
2924 | ||
2925 | case 'p': | |
2926 | assert (ep != NULL); | |
2927 | /* | |
2928 | * This allows macro() to pass an immediate expression for | |
2929 | * creating short branches without creating a symbol. | |
2930 | * Note that the expression still might come from the assembly | |
2931 | * input, in which case the value is not checked for range nor | |
2932 | * is a relocation entry generated (yuck). | |
2933 | */ | |
2934 | if (ep->X_op == O_constant) | |
2935 | { | |
2936 | insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff; | |
2937 | ep = NULL; | |
2938 | } | |
2939 | else | |
cb56d3d3 | 2940 | if (mips_pic == EMBEDDED_PIC) |
f6688943 | 2941 | *r = BFD_RELOC_16_PCREL_S2; |
cb56d3d3 | 2942 | else |
f6688943 | 2943 | *r = BFD_RELOC_16_PCREL; |
252b5132 RH |
2944 | continue; |
2945 | ||
2946 | case 'a': | |
2947 | assert (ep != NULL); | |
f6688943 | 2948 | *r = BFD_RELOC_MIPS_JMP; |
252b5132 RH |
2949 | continue; |
2950 | ||
2951 | case 'C': | |
2952 | insn.insn_opcode |= va_arg (args, unsigned long); | |
2953 | continue; | |
2954 | ||
2955 | default: | |
2956 | internalError (); | |
2957 | } | |
2958 | break; | |
2959 | } | |
2960 | va_end (args); | |
f6688943 | 2961 | assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
252b5132 RH |
2962 | |
2963 | append_insn (place, &insn, ep, r, false); | |
2964 | } | |
2965 | ||
2966 | static void | |
2967 | mips16_macro_build (place, counter, ep, name, fmt, args) | |
2968 | char *place; | |
43841e91 | 2969 | int *counter ATTRIBUTE_UNUSED; |
252b5132 RH |
2970 | expressionS *ep; |
2971 | const char *name; | |
2972 | const char *fmt; | |
2973 | va_list args; | |
2974 | { | |
2975 | struct mips_cl_insn insn; | |
f6688943 TS |
2976 | bfd_reloc_code_real_type r[3] |
2977 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 | 2978 | |
252b5132 RH |
2979 | insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name); |
2980 | assert (insn.insn_mo); | |
2981 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2982 | ||
2983 | while (strcmp (fmt, insn.insn_mo->args) != 0 | |
2984 | || insn.insn_mo->pinfo == INSN_MACRO) | |
2985 | { | |
2986 | ++insn.insn_mo; | |
2987 | assert (insn.insn_mo->name); | |
2988 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2989 | } | |
2990 | ||
2991 | insn.insn_opcode = insn.insn_mo->match; | |
2992 | insn.use_extend = false; | |
2993 | ||
2994 | for (;;) | |
2995 | { | |
2996 | int c; | |
2997 | ||
2998 | c = *fmt++; | |
2999 | switch (c) | |
3000 | { | |
3001 | case '\0': | |
3002 | break; | |
3003 | ||
3004 | case ',': | |
3005 | case '(': | |
3006 | case ')': | |
3007 | continue; | |
3008 | ||
3009 | case 'y': | |
3010 | case 'w': | |
3011 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY; | |
3012 | continue; | |
3013 | ||
3014 | case 'x': | |
3015 | case 'v': | |
3016 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX; | |
3017 | continue; | |
3018 | ||
3019 | case 'z': | |
3020 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ; | |
3021 | continue; | |
3022 | ||
3023 | case 'Z': | |
3024 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z; | |
3025 | continue; | |
3026 | ||
3027 | case '0': | |
3028 | case 'S': | |
3029 | case 'P': | |
3030 | case 'R': | |
3031 | continue; | |
3032 | ||
3033 | case 'X': | |
3034 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32; | |
3035 | continue; | |
3036 | ||
3037 | case 'Y': | |
3038 | { | |
3039 | int regno; | |
3040 | ||
3041 | regno = va_arg (args, int); | |
3042 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
3043 | insn.insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
3044 | } | |
3045 | continue; | |
3046 | ||
3047 | case '<': | |
3048 | case '>': | |
3049 | case '4': | |
3050 | case '5': | |
3051 | case 'H': | |
3052 | case 'W': | |
3053 | case 'D': | |
3054 | case 'j': | |
3055 | case '8': | |
3056 | case 'V': | |
3057 | case 'C': | |
3058 | case 'U': | |
3059 | case 'k': | |
3060 | case 'K': | |
3061 | case 'p': | |
3062 | case 'q': | |
3063 | { | |
3064 | assert (ep != NULL); | |
3065 | ||
3066 | if (ep->X_op != O_constant) | |
f6688943 | 3067 | *r = BFD_RELOC_UNUSED + c; |
252b5132 RH |
3068 | else |
3069 | { | |
c4e7957c TS |
3070 | mips16_immed (NULL, 0, c, ep->X_add_number, false, false, |
3071 | false, &insn.insn_opcode, &insn.use_extend, | |
3072 | &insn.extend); | |
252b5132 | 3073 | ep = NULL; |
f6688943 | 3074 | *r = BFD_RELOC_UNUSED; |
252b5132 RH |
3075 | } |
3076 | } | |
3077 | continue; | |
3078 | ||
3079 | case '6': | |
3080 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6; | |
3081 | continue; | |
3082 | } | |
3083 | ||
3084 | break; | |
3085 | } | |
3086 | ||
f6688943 | 3087 | assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
252b5132 RH |
3088 | |
3089 | append_insn (place, &insn, ep, r, false); | |
3090 | } | |
3091 | ||
3092 | /* | |
3093 | * Generate a "lui" instruction. | |
3094 | */ | |
3095 | static void | |
3096 | macro_build_lui (place, counter, ep, regnum) | |
3097 | char *place; | |
3098 | int *counter; | |
3099 | expressionS *ep; | |
3100 | int regnum; | |
3101 | { | |
3102 | expressionS high_expr; | |
3103 | struct mips_cl_insn insn; | |
f6688943 TS |
3104 | bfd_reloc_code_real_type r[3] |
3105 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
3106 | CONST char *name = "lui"; |
3107 | CONST char *fmt = "t,u"; | |
3108 | ||
3109 | assert (! mips_opts.mips16); | |
3110 | ||
3111 | if (place == NULL) | |
3112 | high_expr = *ep; | |
3113 | else | |
3114 | { | |
3115 | high_expr.X_op = O_constant; | |
3116 | high_expr.X_add_number = ep->X_add_number; | |
3117 | } | |
3118 | ||
3119 | if (high_expr.X_op == O_constant) | |
3120 | { | |
3121 | /* we can compute the instruction now without a relocation entry */ | |
e7d556df TS |
3122 | high_expr.X_add_number = ((high_expr.X_add_number + 0x8000) |
3123 | >> 16) & 0xffff; | |
f6688943 | 3124 | *r = BFD_RELOC_UNUSED; |
252b5132 | 3125 | } |
f6688943 | 3126 | else if (! HAVE_NEWABI) |
252b5132 RH |
3127 | { |
3128 | assert (ep->X_op == O_symbol); | |
3129 | /* _gp_disp is a special case, used from s_cpload. */ | |
3130 | assert (mips_pic == NO_PIC | |
3131 | || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0); | |
f6688943 | 3132 | *r = BFD_RELOC_HI16_S; |
252b5132 RH |
3133 | } |
3134 | ||
3135 | /* | |
3136 | * If the macro is about to expand into a second instruction, | |
3137 | * print a warning if needed. We need to pass ip as a parameter | |
3138 | * to generate a better warning message here... | |
3139 | */ | |
3140 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
3141 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
3142 | ||
3143 | if (place == NULL) | |
3144 | *counter += 1; /* bump instruction counter */ | |
3145 | ||
3146 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
3147 | assert (insn.insn_mo); | |
3148 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
3149 | assert (strcmp (fmt, insn.insn_mo->args) == 0); | |
3150 | ||
3151 | insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT); | |
f6688943 | 3152 | if (*r == BFD_RELOC_UNUSED) |
252b5132 RH |
3153 | { |
3154 | insn.insn_opcode |= high_expr.X_add_number; | |
3155 | append_insn (place, &insn, NULL, r, false); | |
3156 | } | |
3157 | else | |
3158 | append_insn (place, &insn, &high_expr, r, false); | |
3159 | } | |
3160 | ||
3161 | /* set_at() | |
3162 | * Generates code to set the $at register to true (one) | |
3163 | * if reg is less than the immediate expression. | |
3164 | */ | |
3165 | static void | |
3166 | set_at (counter, reg, unsignedp) | |
3167 | int *counter; | |
3168 | int reg; | |
3169 | int unsignedp; | |
3170 | { | |
3171 | if (imm_expr.X_op == O_constant | |
3172 | && imm_expr.X_add_number >= -0x8000 | |
3173 | && imm_expr.X_add_number < 0x8000) | |
3174 | macro_build ((char *) NULL, counter, &imm_expr, | |
3175 | unsignedp ? "sltiu" : "slti", | |
3176 | "t,r,j", AT, reg, (int) BFD_RELOC_LO16); | |
3177 | else | |
3178 | { | |
3179 | load_register (counter, AT, &imm_expr, 0); | |
2396cfb9 | 3180 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
252b5132 RH |
3181 | unsignedp ? "sltu" : "slt", |
3182 | "d,v,t", AT, reg, AT); | |
3183 | } | |
3184 | } | |
3185 | ||
3186 | /* Warn if an expression is not a constant. */ | |
3187 | ||
3188 | static void | |
3189 | check_absolute_expr (ip, ex) | |
3190 | struct mips_cl_insn *ip; | |
3191 | expressionS *ex; | |
3192 | { | |
3193 | if (ex->X_op == O_big) | |
3194 | as_bad (_("unsupported large constant")); | |
3195 | else if (ex->X_op != O_constant) | |
3196 | as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name); | |
3197 | } | |
3198 | ||
3199 | /* Count the leading zeroes by performing a binary chop. This is a | |
3200 | bulky bit of source, but performance is a LOT better for the | |
3201 | majority of values than a simple loop to count the bits: | |
3202 | for (lcnt = 0; (lcnt < 32); lcnt++) | |
3203 | if ((v) & (1 << (31 - lcnt))) | |
3204 | break; | |
3205 | However it is not code size friendly, and the gain will drop a bit | |
3206 | on certain cached systems. | |
3207 | */ | |
3208 | #define COUNT_TOP_ZEROES(v) \ | |
3209 | (((v) & ~0xffff) == 0 \ | |
3210 | ? ((v) & ~0xff) == 0 \ | |
3211 | ? ((v) & ~0xf) == 0 \ | |
3212 | ? ((v) & ~0x3) == 0 \ | |
3213 | ? ((v) & ~0x1) == 0 \ | |
3214 | ? !(v) \ | |
3215 | ? 32 \ | |
3216 | : 31 \ | |
3217 | : 30 \ | |
3218 | : ((v) & ~0x7) == 0 \ | |
3219 | ? 29 \ | |
3220 | : 28 \ | |
3221 | : ((v) & ~0x3f) == 0 \ | |
3222 | ? ((v) & ~0x1f) == 0 \ | |
3223 | ? 27 \ | |
3224 | : 26 \ | |
3225 | : ((v) & ~0x7f) == 0 \ | |
3226 | ? 25 \ | |
3227 | : 24 \ | |
3228 | : ((v) & ~0xfff) == 0 \ | |
3229 | ? ((v) & ~0x3ff) == 0 \ | |
3230 | ? ((v) & ~0x1ff) == 0 \ | |
3231 | ? 23 \ | |
3232 | : 22 \ | |
3233 | : ((v) & ~0x7ff) == 0 \ | |
3234 | ? 21 \ | |
3235 | : 20 \ | |
3236 | : ((v) & ~0x3fff) == 0 \ | |
3237 | ? ((v) & ~0x1fff) == 0 \ | |
3238 | ? 19 \ | |
3239 | : 18 \ | |
3240 | : ((v) & ~0x7fff) == 0 \ | |
3241 | ? 17 \ | |
3242 | : 16 \ | |
3243 | : ((v) & ~0xffffff) == 0 \ | |
3244 | ? ((v) & ~0xfffff) == 0 \ | |
3245 | ? ((v) & ~0x3ffff) == 0 \ | |
3246 | ? ((v) & ~0x1ffff) == 0 \ | |
3247 | ? 15 \ | |
3248 | : 14 \ | |
3249 | : ((v) & ~0x7ffff) == 0 \ | |
3250 | ? 13 \ | |
3251 | : 12 \ | |
3252 | : ((v) & ~0x3fffff) == 0 \ | |
3253 | ? ((v) & ~0x1fffff) == 0 \ | |
3254 | ? 11 \ | |
3255 | : 10 \ | |
3256 | : ((v) & ~0x7fffff) == 0 \ | |
3257 | ? 9 \ | |
3258 | : 8 \ | |
3259 | : ((v) & ~0xfffffff) == 0 \ | |
3260 | ? ((v) & ~0x3ffffff) == 0 \ | |
3261 | ? ((v) & ~0x1ffffff) == 0 \ | |
3262 | ? 7 \ | |
3263 | : 6 \ | |
3264 | : ((v) & ~0x7ffffff) == 0 \ | |
3265 | ? 5 \ | |
3266 | : 4 \ | |
3267 | : ((v) & ~0x3fffffff) == 0 \ | |
3268 | ? ((v) & ~0x1fffffff) == 0 \ | |
3269 | ? 3 \ | |
3270 | : 2 \ | |
3271 | : ((v) & ~0x7fffffff) == 0 \ | |
3272 | ? 1 \ | |
3273 | : 0) | |
3274 | ||
3275 | /* load_register() | |
3276 | * This routine generates the least number of instructions neccessary to load | |
3277 | * an absolute expression value into a register. | |
3278 | */ | |
3279 | static void | |
3280 | load_register (counter, reg, ep, dbl) | |
3281 | int *counter; | |
3282 | int reg; | |
3283 | expressionS *ep; | |
3284 | int dbl; | |
3285 | { | |
3286 | int freg; | |
3287 | expressionS hi32, lo32; | |
3288 | ||
3289 | if (ep->X_op != O_big) | |
3290 | { | |
3291 | assert (ep->X_op == O_constant); | |
3292 | if (ep->X_add_number < 0x8000 | |
3293 | && (ep->X_add_number >= 0 | |
3294 | || (ep->X_add_number >= -0x8000 | |
3295 | && (! dbl | |
3296 | || ! ep->X_unsigned | |
3297 | || sizeof (ep->X_add_number) > 4)))) | |
3298 | { | |
3299 | /* We can handle 16 bit signed values with an addiu to | |
3300 | $zero. No need to ever use daddiu here, since $zero and | |
3301 | the result are always correct in 32 bit mode. */ | |
3302 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3303 | (int) BFD_RELOC_LO16); | |
3304 | return; | |
3305 | } | |
3306 | else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000) | |
3307 | { | |
3308 | /* We can handle 16 bit unsigned values with an ori to | |
3309 | $zero. */ | |
3310 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0, | |
3311 | (int) BFD_RELOC_LO16); | |
3312 | return; | |
3313 | } | |
3314 | else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0 | |
3315 | || ((ep->X_add_number &~ (offsetT) 0x7fffffff) | |
3316 | == ~ (offsetT) 0x7fffffff)) | |
3317 | && (! dbl | |
3318 | || ! ep->X_unsigned | |
3319 | || sizeof (ep->X_add_number) > 4 | |
3320 | || (ep->X_add_number & 0x80000000) == 0)) | |
ca4e0257 | 3321 | || ((HAVE_32BIT_GPRS || ! dbl) |
252b5132 | 3322 | && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0) |
ca4e0257 | 3323 | || (HAVE_32BIT_GPRS |
252b5132 RH |
3324 | && ! dbl |
3325 | && ((ep->X_add_number &~ (offsetT) 0xffffffff) | |
3326 | == ~ (offsetT) 0xffffffff))) | |
3327 | { | |
3328 | /* 32 bit values require an lui. */ | |
3329 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3330 | (int) BFD_RELOC_HI16); | |
3331 | if ((ep->X_add_number & 0xffff) != 0) | |
3332 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg, | |
3333 | (int) BFD_RELOC_LO16); | |
3334 | return; | |
3335 | } | |
3336 | } | |
3337 | ||
3338 | /* The value is larger than 32 bits. */ | |
3339 | ||
ca4e0257 | 3340 | if (HAVE_32BIT_GPRS) |
252b5132 RH |
3341 | { |
3342 | as_bad (_("Number larger than 32 bits")); | |
3343 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3344 | (int) BFD_RELOC_LO16); | |
3345 | return; | |
3346 | } | |
3347 | ||
3348 | if (ep->X_op != O_big) | |
3349 | { | |
3350 | hi32 = *ep; | |
3351 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3352 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3353 | hi32.X_add_number &= 0xffffffff; | |
3354 | lo32 = *ep; | |
3355 | lo32.X_add_number &= 0xffffffff; | |
3356 | } | |
3357 | else | |
3358 | { | |
3359 | assert (ep->X_add_number > 2); | |
3360 | if (ep->X_add_number == 3) | |
3361 | generic_bignum[3] = 0; | |
3362 | else if (ep->X_add_number > 4) | |
3363 | as_bad (_("Number larger than 64 bits")); | |
3364 | lo32.X_op = O_constant; | |
3365 | lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16); | |
3366 | hi32.X_op = O_constant; | |
3367 | hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16); | |
3368 | } | |
3369 | ||
3370 | if (hi32.X_add_number == 0) | |
3371 | freg = 0; | |
3372 | else | |
3373 | { | |
3374 | int shift, bit; | |
3375 | unsigned long hi, lo; | |
3376 | ||
3377 | if (hi32.X_add_number == 0xffffffff) | |
beae10d5 KH |
3378 | { |
3379 | if ((lo32.X_add_number & 0xffff8000) == 0xffff8000) | |
3380 | { | |
3381 | macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j", | |
252b5132 | 3382 | reg, 0, (int) BFD_RELOC_LO16); |
beae10d5 KH |
3383 | return; |
3384 | } | |
3385 | if (lo32.X_add_number & 0x80000000) | |
3386 | { | |
3387 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, | |
3388 | (int) BFD_RELOC_HI16); | |
252b5132 RH |
3389 | if (lo32.X_add_number & 0xffff) |
3390 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", | |
3391 | reg, reg, (int) BFD_RELOC_LO16); | |
beae10d5 KH |
3392 | return; |
3393 | } | |
3394 | } | |
252b5132 RH |
3395 | |
3396 | /* Check for 16bit shifted constant. We know that hi32 is | |
3397 | non-zero, so start the mask on the first bit of the hi32 | |
3398 | value. */ | |
3399 | shift = 17; | |
3400 | do | |
beae10d5 KH |
3401 | { |
3402 | unsigned long himask, lomask; | |
3403 | ||
3404 | if (shift < 32) | |
3405 | { | |
3406 | himask = 0xffff >> (32 - shift); | |
3407 | lomask = (0xffff << shift) & 0xffffffff; | |
3408 | } | |
3409 | else | |
3410 | { | |
3411 | himask = 0xffff << (shift - 32); | |
3412 | lomask = 0; | |
3413 | } | |
3414 | if ((hi32.X_add_number & ~(offsetT) himask) == 0 | |
3415 | && (lo32.X_add_number & ~(offsetT) lomask) == 0) | |
3416 | { | |
3417 | expressionS tmp; | |
3418 | ||
3419 | tmp.X_op = O_constant; | |
3420 | if (shift < 32) | |
3421 | tmp.X_add_number = ((hi32.X_add_number << (32 - shift)) | |
3422 | | (lo32.X_add_number >> shift)); | |
3423 | else | |
3424 | tmp.X_add_number = hi32.X_add_number >> (shift - 32); | |
3425 | macro_build ((char *) NULL, counter, &tmp, | |
3426 | "ori", "t,r,i", reg, 0, | |
3427 | (int) BFD_RELOC_LO16); | |
2396cfb9 | 3428 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
beae10d5 KH |
3429 | (shift >= 32) ? "dsll32" : "dsll", |
3430 | "d,w,<", reg, reg, | |
3431 | (shift >= 32) ? shift - 32 : shift); | |
3432 | return; | |
3433 | } | |
3434 | shift++; | |
3435 | } | |
3436 | while (shift <= (64 - 16)); | |
252b5132 RH |
3437 | |
3438 | /* Find the bit number of the lowest one bit, and store the | |
3439 | shifted value in hi/lo. */ | |
3440 | hi = (unsigned long) (hi32.X_add_number & 0xffffffff); | |
3441 | lo = (unsigned long) (lo32.X_add_number & 0xffffffff); | |
3442 | if (lo != 0) | |
3443 | { | |
3444 | bit = 0; | |
3445 | while ((lo & 1) == 0) | |
3446 | { | |
3447 | lo >>= 1; | |
3448 | ++bit; | |
3449 | } | |
3450 | lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit); | |
3451 | hi >>= bit; | |
3452 | } | |
3453 | else | |
3454 | { | |
3455 | bit = 32; | |
3456 | while ((hi & 1) == 0) | |
3457 | { | |
3458 | hi >>= 1; | |
3459 | ++bit; | |
3460 | } | |
3461 | lo = hi; | |
3462 | hi = 0; | |
3463 | } | |
3464 | ||
3465 | /* Optimize if the shifted value is a (power of 2) - 1. */ | |
3466 | if ((hi == 0 && ((lo + 1) & lo) == 0) | |
3467 | || (lo == 0xffffffff && ((hi + 1) & hi) == 0)) | |
beae10d5 KH |
3468 | { |
3469 | shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number); | |
252b5132 | 3470 | if (shift != 0) |
beae10d5 | 3471 | { |
252b5132 RH |
3472 | expressionS tmp; |
3473 | ||
3474 | /* This instruction will set the register to be all | |
3475 | ones. */ | |
beae10d5 KH |
3476 | tmp.X_op = O_constant; |
3477 | tmp.X_add_number = (offsetT) -1; | |
3478 | macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j", | |
252b5132 | 3479 | reg, 0, (int) BFD_RELOC_LO16); |
beae10d5 KH |
3480 | if (bit != 0) |
3481 | { | |
3482 | bit += shift; | |
2396cfb9 | 3483 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
beae10d5 KH |
3484 | (bit >= 32) ? "dsll32" : "dsll", |
3485 | "d,w,<", reg, reg, | |
3486 | (bit >= 32) ? bit - 32 : bit); | |
3487 | } | |
2396cfb9 | 3488 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
252b5132 | 3489 | (shift >= 32) ? "dsrl32" : "dsrl", |
beae10d5 | 3490 | "d,w,<", reg, reg, |
252b5132 | 3491 | (shift >= 32) ? shift - 32 : shift); |
beae10d5 KH |
3492 | return; |
3493 | } | |
3494 | } | |
252b5132 RH |
3495 | |
3496 | /* Sign extend hi32 before calling load_register, because we can | |
3497 | generally get better code when we load a sign extended value. */ | |
3498 | if ((hi32.X_add_number & 0x80000000) != 0) | |
beae10d5 | 3499 | hi32.X_add_number |= ~(offsetT) 0xffffffff; |
252b5132 RH |
3500 | load_register (counter, reg, &hi32, 0); |
3501 | freg = reg; | |
3502 | } | |
3503 | if ((lo32.X_add_number & 0xffff0000) == 0) | |
3504 | { | |
3505 | if (freg != 0) | |
3506 | { | |
2396cfb9 TS |
3507 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
3508 | "dsll32", "d,w,<", reg, freg, 0); | |
252b5132 RH |
3509 | freg = reg; |
3510 | } | |
3511 | } | |
3512 | else | |
3513 | { | |
3514 | expressionS mid16; | |
3515 | ||
3516 | if ((freg == 0) && (lo32.X_add_number == 0xffffffff)) | |
beae10d5 | 3517 | { |
252b5132 RH |
3518 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, |
3519 | (int) BFD_RELOC_HI16); | |
beae10d5 KH |
3520 | macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg, |
3521 | reg, 0); | |
3522 | return; | |
3523 | } | |
252b5132 RH |
3524 | |
3525 | if (freg != 0) | |
3526 | { | |
3527 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3528 | freg, 16); | |
3529 | freg = reg; | |
3530 | } | |
3531 | mid16 = lo32; | |
3532 | mid16.X_add_number >>= 16; | |
3533 | macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg, | |
3534 | freg, (int) BFD_RELOC_LO16); | |
3535 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3536 | reg, 16); | |
3537 | freg = reg; | |
3538 | } | |
3539 | if ((lo32.X_add_number & 0xffff) != 0) | |
3540 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg, | |
3541 | (int) BFD_RELOC_LO16); | |
3542 | } | |
3543 | ||
3544 | /* Load an address into a register. */ | |
3545 | ||
3546 | static void | |
d6bc6245 | 3547 | load_address (counter, reg, ep, dbl, used_at) |
252b5132 RH |
3548 | int *counter; |
3549 | int reg; | |
3550 | expressionS *ep; | |
d6bc6245 TS |
3551 | int dbl; |
3552 | int *used_at; | |
252b5132 RH |
3553 | { |
3554 | char *p; | |
3555 | ||
3556 | if (ep->X_op != O_constant | |
3557 | && ep->X_op != O_symbol) | |
3558 | { | |
3559 | as_bad (_("expression too complex")); | |
3560 | ep->X_op = O_constant; | |
3561 | } | |
3562 | ||
3563 | if (ep->X_op == O_constant) | |
3564 | { | |
d6bc6245 | 3565 | load_register (counter, reg, ep, dbl); |
252b5132 RH |
3566 | return; |
3567 | } | |
3568 | ||
3569 | if (mips_pic == NO_PIC) | |
3570 | { | |
3571 | /* If this is a reference to a GP relative symbol, we want | |
cdf6fd85 | 3572 | addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 RH |
3573 | Otherwise we want |
3574 | lui $reg,<sym> (BFD_RELOC_HI16_S) | |
3575 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
d6bc6245 | 3576 | If we have an addend, we always use the latter form. |
76b3015f | 3577 | |
d6bc6245 TS |
3578 | With 64bit address space and a usable $at we want |
3579 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
3580 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
3581 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
3582 | daddiu $at,<sym> (BFD_RELOC_LO16) | |
3583 | dsll32 $reg,0 | |
3584 | dadd $reg,$reg,$at | |
76b3015f | 3585 | |
d6bc6245 TS |
3586 | If $at is already in use, we use an path which is suboptimal |
3587 | on superscalar processors. | |
3588 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
3589 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
3590 | dsll $reg,16 | |
3591 | daddiu $reg,<sym> (BFD_RELOC_HI16_S) | |
3592 | dsll $reg,16 | |
3593 | daddiu $reg,<sym> (BFD_RELOC_LO16) | |
3594 | */ | |
3595 | if (HAVE_64BIT_ADDRESSES) | |
3596 | { | |
3597 | p = NULL; | |
3598 | ||
3599 | /* We don't do GP optimization for now because RELAX_ENCODE can't | |
3600 | hold the data for such large chunks. */ | |
3601 | ||
3602 | if (*used_at == 0) | |
3603 | { | |
3604 | macro_build (p, counter, ep, "lui", "t,u", | |
3605 | reg, (int) BFD_RELOC_MIPS_HIGHEST); | |
3606 | macro_build (p, counter, ep, "lui", "t,u", | |
3607 | AT, (int) BFD_RELOC_HI16_S); | |
3608 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3609 | reg, reg, (int) BFD_RELOC_MIPS_HIGHER); | |
3610 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3611 | AT, AT, (int) BFD_RELOC_LO16); | |
2396cfb9 TS |
3612 | macro_build (p, counter, (expressionS *) NULL, "dsll32", |
3613 | "d,w,<", reg, reg, 0); | |
3614 | macro_build (p, counter, (expressionS *) NULL, "dadd", | |
3615 | "d,v,t", reg, reg, AT); | |
d6bc6245 TS |
3616 | *used_at = 1; |
3617 | } | |
3618 | else | |
3619 | { | |
3620 | macro_build (p, counter, ep, "lui", "t,u", | |
3621 | reg, (int) BFD_RELOC_MIPS_HIGHEST); | |
3622 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3623 | reg, reg, (int) BFD_RELOC_MIPS_HIGHER); | |
2396cfb9 TS |
3624 | macro_build (p, counter, (expressionS *) NULL, "dsll", |
3625 | "d,w,<", reg, reg, 16); | |
d6bc6245 TS |
3626 | macro_build (p, counter, ep, "daddiu", "t,r,j", |
3627 | reg, reg, (int) BFD_RELOC_HI16_S); | |
2396cfb9 TS |
3628 | macro_build (p, counter, (expressionS *) NULL, "dsll", |
3629 | "d,w,<", reg, reg, 16); | |
d6bc6245 TS |
3630 | macro_build (p, counter, ep, "daddiu", "t,r,j", |
3631 | reg, reg, (int) BFD_RELOC_LO16); | |
3632 | } | |
3633 | } | |
252b5132 RH |
3634 | else |
3635 | { | |
d6bc6245 TS |
3636 | p = NULL; |
3637 | if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET | |
3638 | && ! nopic_need_relax (ep->X_add_symbol, 1)) | |
3639 | { | |
3640 | frag_grow (20); | |
3641 | macro_build ((char *) NULL, counter, ep, | |
cdf6fd85 TS |
3642 | dbl ? "daddiu" : "addiu", "t,r,j", reg, GP, |
3643 | (int) BFD_RELOC_GPREL16); | |
d6bc6245 TS |
3644 | p = frag_var (rs_machine_dependent, 8, 0, |
3645 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
3646 | mips_opts.warn_about_macros), | |
3647 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3648 | } | |
3649 | macro_build_lui (p, counter, ep, reg); | |
3650 | if (p != NULL) | |
3651 | p += 4; | |
3652 | macro_build (p, counter, ep, | |
ca4e0257 | 3653 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
d6bc6245 TS |
3654 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3655 | } | |
252b5132 RH |
3656 | } |
3657 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
3658 | { | |
3659 | expressionS ex; | |
3660 | ||
3661 | /* If this is a reference to an external symbol, we want | |
3662 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3663 | Otherwise we want | |
3664 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3665 | nop | |
3666 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3667 | If there is a constant, it must be added in after. */ | |
3668 | ex.X_add_number = ep->X_add_number; | |
3669 | ep->X_add_number = 0; | |
3670 | frag_grow (20); | |
3671 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3672 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3673 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); |
3674 | macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", ""); | |
3675 | p = frag_var (rs_machine_dependent, 4, 0, | |
3676 | RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros), | |
3677 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3678 | macro_build (p, counter, ep, | |
ca4e0257 | 3679 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3680 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3681 | if (ex.X_add_number != 0) | |
3682 | { | |
3683 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3684 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3685 | ex.X_op = O_constant; | |
3686 | macro_build ((char *) NULL, counter, &ex, | |
ca4e0257 | 3687 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3688 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3689 | } | |
3690 | } | |
3691 | else if (mips_pic == SVR4_PIC) | |
3692 | { | |
3693 | expressionS ex; | |
3694 | int off; | |
3695 | ||
3696 | /* This is the large GOT case. If this is a reference to an | |
3697 | external symbol, we want | |
3698 | lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
3699 | addu $reg,$reg,$gp | |
3700 | lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16) | |
3701 | Otherwise, for a reference to a local symbol, we want | |
3702 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3703 | nop | |
3704 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3705 | If there is a constant, it must be added in after. */ | |
3706 | ex.X_add_number = ep->X_add_number; | |
3707 | ep->X_add_number = 0; | |
3708 | if (reg_needs_delay (GP)) | |
3709 | off = 4; | |
3710 | else | |
3711 | off = 0; | |
3712 | frag_grow (32); | |
3713 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3714 | (int) BFD_RELOC_MIPS_GOT_HI16); | |
3715 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
ca4e0257 | 3716 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
3717 | "d,v,t", reg, reg, GP); |
3718 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3719 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3720 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg); |
3721 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
3722 | RELAX_ENCODE (12, 12 + off, off, 8 + off, 0, | |
3723 | mips_opts.warn_about_macros), | |
3724 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3725 | if (off > 0) | |
3726 | { | |
3727 | /* We need a nop before loading from $gp. This special | |
3728 | check is required because the lui which starts the main | |
3729 | instruction stream does not refer to $gp, and so will not | |
3730 | insert the nop which may be required. */ | |
3731 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3732 | p += 4; | |
3733 | } | |
9a41af64 | 3734 | macro_build (p, counter, ep, HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3735 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); |
3736 | p += 4; | |
3737 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3738 | p += 4; | |
9a41af64 | 3739 | macro_build (p, counter, ep, HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3740 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3741 | if (ex.X_add_number != 0) | |
3742 | { | |
3743 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3744 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3745 | ex.X_op = O_constant; | |
3746 | macro_build ((char *) NULL, counter, &ex, | |
ca4e0257 | 3747 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3748 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3749 | } | |
3750 | } | |
3751 | else if (mips_pic == EMBEDDED_PIC) | |
3752 | { | |
3753 | /* We always do | |
cdf6fd85 | 3754 | addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 | 3755 | */ |
cdf6fd85 TS |
3756 | macro_build ((char *) NULL, counter, ep, dbl ? "daddiu" : "addiu", |
3757 | "t,r,j", reg, GP, (int) BFD_RELOC_GPREL16); | |
252b5132 RH |
3758 | } |
3759 | else | |
3760 | abort (); | |
3761 | } | |
3762 | ||
ea1fb5dc RS |
3763 | /* Move the contents of register SOURCE into register DEST. */ |
3764 | ||
3765 | static void | |
3766 | move_register (counter, dest, source) | |
3767 | int *counter; | |
3768 | int dest; | |
3769 | int source; | |
3770 | { | |
3771 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
3772 | HAVE_32BIT_GPRS ? "addu" : "daddu", | |
3773 | "d,v,t", dest, source, 0); | |
3774 | } | |
3775 | ||
252b5132 RH |
3776 | /* |
3777 | * Build macros | |
3778 | * This routine implements the seemingly endless macro or synthesized | |
3779 | * instructions and addressing modes in the mips assembly language. Many | |
3780 | * of these macros are simple and are similar to each other. These could | |
3781 | * probably be handled by some kind of table or grammer aproach instead of | |
3782 | * this verbose method. Others are not simple macros but are more like | |
3783 | * optimizing code generation. | |
3784 | * One interesting optimization is when several store macros appear | |
3785 | * consecutivly that would load AT with the upper half of the same address. | |
3786 | * The ensuing load upper instructions are ommited. This implies some kind | |
3787 | * of global optimization. We currently only optimize within a single macro. | |
3788 | * For many of the load and store macros if the address is specified as a | |
3789 | * constant expression in the first 64k of memory (ie ld $2,0x4000c) we | |
3790 | * first load register 'at' with zero and use it as the base register. The | |
3791 | * mips assembler simply uses register $zero. Just one tiny optimization | |
3792 | * we're missing. | |
3793 | */ | |
3794 | static void | |
3795 | macro (ip) | |
3796 | struct mips_cl_insn *ip; | |
3797 | { | |
3798 | register int treg, sreg, dreg, breg; | |
3799 | int tempreg; | |
3800 | int mask; | |
3801 | int icnt = 0; | |
43841e91 | 3802 | int used_at = 0; |
252b5132 RH |
3803 | expressionS expr1; |
3804 | const char *s; | |
3805 | const char *s2; | |
3806 | const char *fmt; | |
3807 | int likely = 0; | |
3808 | int dbl = 0; | |
3809 | int coproc = 0; | |
3810 | int lr = 0; | |
3811 | int imm = 0; | |
3812 | offsetT maxnum; | |
3813 | int off; | |
3814 | bfd_reloc_code_real_type r; | |
3815 | char *p; | |
3816 | int hold_mips_optimize; | |
3817 | ||
3818 | assert (! mips_opts.mips16); | |
3819 | ||
3820 | treg = (ip->insn_opcode >> 16) & 0x1f; | |
3821 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
3822 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
3823 | mask = ip->insn_mo->mask; | |
3824 | ||
3825 | expr1.X_op = O_constant; | |
3826 | expr1.X_op_symbol = NULL; | |
3827 | expr1.X_add_symbol = NULL; | |
3828 | expr1.X_add_number = 1; | |
3829 | ||
3830 | switch (mask) | |
3831 | { | |
3832 | case M_DABS: | |
3833 | dbl = 1; | |
3834 | case M_ABS: | |
3835 | /* bgez $a0,.+12 | |
3836 | move v0,$a0 | |
3837 | sub v0,$zero,$a0 | |
3838 | */ | |
3839 | ||
3840 | mips_emit_delays (true); | |
3841 | ++mips_opts.noreorder; | |
3842 | mips_any_noreorder = 1; | |
3843 | ||
3844 | expr1.X_add_number = 8; | |
3845 | macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg); | |
3846 | if (dreg == sreg) | |
2396cfb9 TS |
3847 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "", |
3848 | 0); | |
252b5132 | 3849 | else |
ea1fb5dc | 3850 | move_register (&icnt, dreg, sreg); |
2396cfb9 | 3851 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 3852 | dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg); |
252b5132 RH |
3853 | |
3854 | --mips_opts.noreorder; | |
3855 | return; | |
3856 | ||
3857 | case M_ADD_I: | |
3858 | s = "addi"; | |
3859 | s2 = "add"; | |
3860 | goto do_addi; | |
3861 | case M_ADDU_I: | |
3862 | s = "addiu"; | |
3863 | s2 = "addu"; | |
3864 | goto do_addi; | |
3865 | case M_DADD_I: | |
3866 | dbl = 1; | |
3867 | s = "daddi"; | |
3868 | s2 = "dadd"; | |
3869 | goto do_addi; | |
3870 | case M_DADDU_I: | |
3871 | dbl = 1; | |
3872 | s = "daddiu"; | |
3873 | s2 = "daddu"; | |
3874 | do_addi: | |
3875 | if (imm_expr.X_op == O_constant | |
3876 | && imm_expr.X_add_number >= -0x8000 | |
3877 | && imm_expr.X_add_number < 0x8000) | |
3878 | { | |
3879 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg, | |
3880 | (int) BFD_RELOC_LO16); | |
3881 | return; | |
3882 | } | |
3883 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 TS |
3884 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t", |
3885 | treg, sreg, AT); | |
252b5132 RH |
3886 | break; |
3887 | ||
3888 | case M_AND_I: | |
3889 | s = "andi"; | |
3890 | s2 = "and"; | |
3891 | goto do_bit; | |
3892 | case M_OR_I: | |
3893 | s = "ori"; | |
3894 | s2 = "or"; | |
3895 | goto do_bit; | |
3896 | case M_NOR_I: | |
3897 | s = ""; | |
3898 | s2 = "nor"; | |
3899 | goto do_bit; | |
3900 | case M_XOR_I: | |
3901 | s = "xori"; | |
3902 | s2 = "xor"; | |
3903 | do_bit: | |
3904 | if (imm_expr.X_op == O_constant | |
3905 | && imm_expr.X_add_number >= 0 | |
3906 | && imm_expr.X_add_number < 0x10000) | |
3907 | { | |
3908 | if (mask != M_NOR_I) | |
3909 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg, | |
3910 | sreg, (int) BFD_RELOC_LO16); | |
3911 | else | |
3912 | { | |
3913 | macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i", | |
3914 | treg, sreg, (int) BFD_RELOC_LO16); | |
2396cfb9 TS |
3915 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor", |
3916 | "d,v,t", treg, treg, 0); | |
252b5132 RH |
3917 | } |
3918 | return; | |
3919 | } | |
3920 | ||
d6bc6245 | 3921 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
3922 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t", |
3923 | treg, sreg, AT); | |
252b5132 RH |
3924 | break; |
3925 | ||
3926 | case M_BEQ_I: | |
3927 | s = "beq"; | |
3928 | goto beq_i; | |
3929 | case M_BEQL_I: | |
3930 | s = "beql"; | |
3931 | likely = 1; | |
3932 | goto beq_i; | |
3933 | case M_BNE_I: | |
3934 | s = "bne"; | |
3935 | goto beq_i; | |
3936 | case M_BNEL_I: | |
3937 | s = "bnel"; | |
3938 | likely = 1; | |
3939 | beq_i: | |
3940 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3941 | { | |
3942 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, | |
3943 | 0); | |
3944 | return; | |
3945 | } | |
3946 | load_register (&icnt, AT, &imm_expr, 0); | |
3947 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT); | |
3948 | break; | |
3949 | ||
3950 | case M_BGEL: | |
3951 | likely = 1; | |
3952 | case M_BGE: | |
3953 | if (treg == 0) | |
3954 | { | |
3955 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
2396cfb9 | 3956 | likely ? "bgezl" : "bgez", "s,p", sreg); |
252b5132 RH |
3957 | return; |
3958 | } | |
3959 | if (sreg == 0) | |
3960 | { | |
3961 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
2396cfb9 | 3962 | likely ? "blezl" : "blez", "s,p", treg); |
252b5132 RH |
3963 | return; |
3964 | } | |
2396cfb9 TS |
3965 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
3966 | AT, sreg, treg); | |
252b5132 | 3967 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 3968 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
3969 | break; |
3970 | ||
3971 | case M_BGTL_I: | |
3972 | likely = 1; | |
3973 | case M_BGT_I: | |
3974 | /* check for > max integer */ | |
3975 | maxnum = 0x7fffffff; | |
ca4e0257 | 3976 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
3977 | { |
3978 | maxnum <<= 16; | |
3979 | maxnum |= 0xffff; | |
3980 | maxnum <<= 16; | |
3981 | maxnum |= 0xffff; | |
3982 | } | |
3983 | if (imm_expr.X_op == O_constant | |
3984 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 3985 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
3986 | { |
3987 | do_false: | |
3988 | /* result is always false */ | |
3989 | if (! likely) | |
3990 | { | |
39c0a331 L |
3991 | if (warn_nops) |
3992 | as_warn (_("Branch %s is always false (nop)"), | |
3993 | ip->insn_mo->name); | |
2396cfb9 TS |
3994 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", |
3995 | "", 0); | |
252b5132 RH |
3996 | } |
3997 | else | |
3998 | { | |
39c0a331 L |
3999 | if (warn_nops) |
4000 | as_warn (_("Branch likely %s is always false"), | |
4001 | ip->insn_mo->name); | |
252b5132 RH |
4002 | macro_build ((char *) NULL, &icnt, &offset_expr, "bnel", |
4003 | "s,t,p", 0, 0); | |
4004 | } | |
4005 | return; | |
4006 | } | |
4007 | if (imm_expr.X_op != O_constant) | |
4008 | as_bad (_("Unsupported large constant")); | |
4009 | imm_expr.X_add_number++; | |
4010 | /* FALLTHROUGH */ | |
4011 | case M_BGE_I: | |
4012 | case M_BGEL_I: | |
4013 | if (mask == M_BGEL_I) | |
4014 | likely = 1; | |
4015 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4016 | { | |
4017 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4018 | likely ? "bgezl" : "bgez", "s,p", sreg); |
252b5132 RH |
4019 | return; |
4020 | } | |
4021 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4022 | { | |
4023 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4024 | likely ? "bgtzl" : "bgtz", "s,p", sreg); |
252b5132 RH |
4025 | return; |
4026 | } | |
4027 | maxnum = 0x7fffffff; | |
ca4e0257 | 4028 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
4029 | { |
4030 | maxnum <<= 16; | |
4031 | maxnum |= 0xffff; | |
4032 | maxnum <<= 16; | |
4033 | maxnum |= 0xffff; | |
4034 | } | |
4035 | maxnum = - maxnum - 1; | |
4036 | if (imm_expr.X_op == O_constant | |
4037 | && imm_expr.X_add_number <= maxnum | |
ca4e0257 | 4038 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
4039 | { |
4040 | do_true: | |
4041 | /* result is always true */ | |
4042 | as_warn (_("Branch %s is always true"), ip->insn_mo->name); | |
4043 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
4044 | return; | |
4045 | } | |
4046 | set_at (&icnt, sreg, 0); | |
4047 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4048 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4049 | break; |
4050 | ||
4051 | case M_BGEUL: | |
4052 | likely = 1; | |
4053 | case M_BGEU: | |
4054 | if (treg == 0) | |
4055 | goto do_true; | |
4056 | if (sreg == 0) | |
4057 | { | |
4058 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4059 | likely ? "beql" : "beq", "s,t,p", 0, treg); |
252b5132 RH |
4060 | return; |
4061 | } | |
2396cfb9 TS |
4062 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
4063 | "d,v,t", AT, sreg, treg); | |
252b5132 | 4064 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4065 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4066 | break; |
4067 | ||
4068 | case M_BGTUL_I: | |
4069 | likely = 1; | |
4070 | case M_BGTU_I: | |
4071 | if (sreg == 0 | |
ca4e0257 | 4072 | || (HAVE_32BIT_GPRS |
252b5132 RH |
4073 | && imm_expr.X_op == O_constant |
4074 | && imm_expr.X_add_number == 0xffffffff)) | |
4075 | goto do_false; | |
4076 | if (imm_expr.X_op != O_constant) | |
4077 | as_bad (_("Unsupported large constant")); | |
4078 | imm_expr.X_add_number++; | |
4079 | /* FALLTHROUGH */ | |
4080 | case M_BGEU_I: | |
4081 | case M_BGEUL_I: | |
4082 | if (mask == M_BGEUL_I) | |
4083 | likely = 1; | |
4084 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4085 | goto do_true; | |
4086 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4087 | { | |
4088 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4089 | likely ? "bnel" : "bne", "s,t,p", sreg, 0); |
252b5132 RH |
4090 | return; |
4091 | } | |
4092 | set_at (&icnt, sreg, 1); | |
4093 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4094 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4095 | break; |
4096 | ||
4097 | case M_BGTL: | |
4098 | likely = 1; | |
4099 | case M_BGT: | |
4100 | if (treg == 0) | |
4101 | { | |
4102 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4103 | likely ? "bgtzl" : "bgtz", "s,p", sreg); |
252b5132 RH |
4104 | return; |
4105 | } | |
4106 | if (sreg == 0) | |
4107 | { | |
4108 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4109 | likely ? "bltzl" : "bltz", "s,p", treg); |
252b5132 RH |
4110 | return; |
4111 | } | |
2396cfb9 TS |
4112 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
4113 | AT, treg, sreg); | |
252b5132 | 4114 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4115 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4116 | break; |
4117 | ||
4118 | case M_BGTUL: | |
4119 | likely = 1; | |
4120 | case M_BGTU: | |
4121 | if (treg == 0) | |
4122 | { | |
4123 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4124 | likely ? "bnel" : "bne", "s,t,p", sreg, 0); |
252b5132 RH |
4125 | return; |
4126 | } | |
4127 | if (sreg == 0) | |
4128 | goto do_false; | |
2396cfb9 TS |
4129 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
4130 | "d,v,t", AT, treg, sreg); | |
252b5132 | 4131 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4132 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4133 | break; |
4134 | ||
4135 | case M_BLEL: | |
4136 | likely = 1; | |
4137 | case M_BLE: | |
4138 | if (treg == 0) | |
4139 | { | |
4140 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4141 | likely ? "blezl" : "blez", "s,p", sreg); |
252b5132 RH |
4142 | return; |
4143 | } | |
4144 | if (sreg == 0) | |
4145 | { | |
4146 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4147 | likely ? "bgezl" : "bgez", "s,p", treg); |
252b5132 RH |
4148 | return; |
4149 | } | |
2396cfb9 TS |
4150 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
4151 | AT, treg, sreg); | |
252b5132 | 4152 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4153 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4154 | break; |
4155 | ||
4156 | case M_BLEL_I: | |
4157 | likely = 1; | |
4158 | case M_BLE_I: | |
4159 | maxnum = 0x7fffffff; | |
ca4e0257 | 4160 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
4161 | { |
4162 | maxnum <<= 16; | |
4163 | maxnum |= 0xffff; | |
4164 | maxnum <<= 16; | |
4165 | maxnum |= 0xffff; | |
4166 | } | |
4167 | if (imm_expr.X_op == O_constant | |
4168 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 4169 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
4170 | goto do_true; |
4171 | if (imm_expr.X_op != O_constant) | |
4172 | as_bad (_("Unsupported large constant")); | |
4173 | imm_expr.X_add_number++; | |
4174 | /* FALLTHROUGH */ | |
4175 | case M_BLT_I: | |
4176 | case M_BLTL_I: | |
4177 | if (mask == M_BLTL_I) | |
4178 | likely = 1; | |
4179 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4180 | { | |
4181 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4182 | likely ? "bltzl" : "bltz", "s,p", sreg); |
252b5132 RH |
4183 | return; |
4184 | } | |
4185 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4186 | { | |
4187 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4188 | likely ? "blezl" : "blez", "s,p", sreg); |
252b5132 RH |
4189 | return; |
4190 | } | |
4191 | set_at (&icnt, sreg, 0); | |
4192 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4193 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4194 | break; |
4195 | ||
4196 | case M_BLEUL: | |
4197 | likely = 1; | |
4198 | case M_BLEU: | |
4199 | if (treg == 0) | |
4200 | { | |
4201 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4202 | likely ? "beql" : "beq", "s,t,p", sreg, 0); |
252b5132 RH |
4203 | return; |
4204 | } | |
4205 | if (sreg == 0) | |
4206 | goto do_true; | |
2396cfb9 TS |
4207 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
4208 | "d,v,t", AT, treg, sreg); | |
252b5132 | 4209 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4210 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4211 | break; |
4212 | ||
4213 | case M_BLEUL_I: | |
4214 | likely = 1; | |
4215 | case M_BLEU_I: | |
4216 | if (sreg == 0 | |
ca4e0257 | 4217 | || (HAVE_32BIT_GPRS |
252b5132 RH |
4218 | && imm_expr.X_op == O_constant |
4219 | && imm_expr.X_add_number == 0xffffffff)) | |
4220 | goto do_true; | |
4221 | if (imm_expr.X_op != O_constant) | |
4222 | as_bad (_("Unsupported large constant")); | |
4223 | imm_expr.X_add_number++; | |
4224 | /* FALLTHROUGH */ | |
4225 | case M_BLTU_I: | |
4226 | case M_BLTUL_I: | |
4227 | if (mask == M_BLTUL_I) | |
4228 | likely = 1; | |
4229 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4230 | goto do_false; | |
4231 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4232 | { | |
4233 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4234 | likely ? "beql" : "beq", | |
4235 | "s,t,p", sreg, 0); | |
4236 | return; | |
4237 | } | |
4238 | set_at (&icnt, sreg, 1); | |
4239 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4240 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4241 | break; |
4242 | ||
4243 | case M_BLTL: | |
4244 | likely = 1; | |
4245 | case M_BLT: | |
4246 | if (treg == 0) | |
4247 | { | |
4248 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4249 | likely ? "bltzl" : "bltz", "s,p", sreg); |
252b5132 RH |
4250 | return; |
4251 | } | |
4252 | if (sreg == 0) | |
4253 | { | |
4254 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4255 | likely ? "bgtzl" : "bgtz", "s,p", treg); |
252b5132 RH |
4256 | return; |
4257 | } | |
2396cfb9 TS |
4258 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
4259 | AT, sreg, treg); | |
252b5132 | 4260 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4261 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4262 | break; |
4263 | ||
4264 | case M_BLTUL: | |
4265 | likely = 1; | |
4266 | case M_BLTU: | |
4267 | if (treg == 0) | |
4268 | goto do_false; | |
4269 | if (sreg == 0) | |
4270 | { | |
4271 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4272 | likely ? "bnel" : "bne", "s,t,p", 0, treg); |
252b5132 RH |
4273 | return; |
4274 | } | |
2396cfb9 TS |
4275 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
4276 | "d,v,t", AT, sreg, | |
252b5132 RH |
4277 | treg); |
4278 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4279 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4280 | break; |
4281 | ||
4282 | case M_DDIV_3: | |
4283 | dbl = 1; | |
4284 | case M_DIV_3: | |
4285 | s = "mflo"; | |
4286 | goto do_div3; | |
4287 | case M_DREM_3: | |
4288 | dbl = 1; | |
4289 | case M_REM_3: | |
4290 | s = "mfhi"; | |
4291 | do_div3: | |
4292 | if (treg == 0) | |
4293 | { | |
4294 | as_warn (_("Divide by zero.")); | |
4295 | if (mips_trap) | |
2396cfb9 TS |
4296 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
4297 | "s,t", 0, 0); | |
252b5132 | 4298 | else |
2396cfb9 TS |
4299 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4300 | "c", 7); | |
252b5132 RH |
4301 | return; |
4302 | } | |
4303 | ||
4304 | mips_emit_delays (true); | |
4305 | ++mips_opts.noreorder; | |
4306 | mips_any_noreorder = 1; | |
4307 | if (mips_trap) | |
4308 | { | |
2396cfb9 TS |
4309 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
4310 | "s,t", treg, 0); | |
4311 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
9a41af64 | 4312 | dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
252b5132 RH |
4313 | } |
4314 | else | |
4315 | { | |
4316 | expr1.X_add_number = 8; | |
4317 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
2396cfb9 | 4318 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 4319 | dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
2396cfb9 TS |
4320 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4321 | "c", 7); | |
252b5132 RH |
4322 | } |
4323 | expr1.X_add_number = -1; | |
4324 | macro_build ((char *) NULL, &icnt, &expr1, | |
4325 | dbl ? "daddiu" : "addiu", | |
4326 | "t,r,j", AT, 0, (int) BFD_RELOC_LO16); | |
4327 | expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16); | |
4328 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT); | |
4329 | if (dbl) | |
4330 | { | |
4331 | expr1.X_add_number = 1; | |
4332 | macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0, | |
4333 | (int) BFD_RELOC_LO16); | |
2396cfb9 TS |
4334 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32", |
4335 | "d,w,<", AT, AT, 31); | |
252b5132 RH |
4336 | } |
4337 | else | |
4338 | { | |
4339 | expr1.X_add_number = 0x80000000; | |
4340 | macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT, | |
4341 | (int) BFD_RELOC_HI16); | |
4342 | } | |
4343 | if (mips_trap) | |
4344 | { | |
2396cfb9 TS |
4345 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
4346 | "s,t", sreg, AT); | |
252b5132 RH |
4347 | /* We want to close the noreorder block as soon as possible, so |
4348 | that later insns are available for delay slot filling. */ | |
4349 | --mips_opts.noreorder; | |
4350 | } | |
4351 | else | |
4352 | { | |
4353 | expr1.X_add_number = 8; | |
4354 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT); | |
2396cfb9 TS |
4355 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "", |
4356 | 0); | |
252b5132 RH |
4357 | |
4358 | /* We want to close the noreorder block as soon as possible, so | |
4359 | that later insns are available for delay slot filling. */ | |
4360 | --mips_opts.noreorder; | |
4361 | ||
2396cfb9 TS |
4362 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4363 | "c", 6); | |
252b5132 | 4364 | } |
2396cfb9 | 4365 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg); |
252b5132 RH |
4366 | break; |
4367 | ||
4368 | case M_DIV_3I: | |
4369 | s = "div"; | |
4370 | s2 = "mflo"; | |
4371 | goto do_divi; | |
4372 | case M_DIVU_3I: | |
4373 | s = "divu"; | |
4374 | s2 = "mflo"; | |
4375 | goto do_divi; | |
4376 | case M_REM_3I: | |
4377 | s = "div"; | |
4378 | s2 = "mfhi"; | |
4379 | goto do_divi; | |
4380 | case M_REMU_3I: | |
4381 | s = "divu"; | |
4382 | s2 = "mfhi"; | |
4383 | goto do_divi; | |
4384 | case M_DDIV_3I: | |
4385 | dbl = 1; | |
4386 | s = "ddiv"; | |
4387 | s2 = "mflo"; | |
4388 | goto do_divi; | |
4389 | case M_DDIVU_3I: | |
4390 | dbl = 1; | |
4391 | s = "ddivu"; | |
4392 | s2 = "mflo"; | |
4393 | goto do_divi; | |
4394 | case M_DREM_3I: | |
4395 | dbl = 1; | |
4396 | s = "ddiv"; | |
4397 | s2 = "mfhi"; | |
4398 | goto do_divi; | |
4399 | case M_DREMU_3I: | |
4400 | dbl = 1; | |
4401 | s = "ddivu"; | |
4402 | s2 = "mfhi"; | |
4403 | do_divi: | |
4404 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4405 | { | |
4406 | as_warn (_("Divide by zero.")); | |
4407 | if (mips_trap) | |
2396cfb9 TS |
4408 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
4409 | "s,t", 0, 0); | |
252b5132 | 4410 | else |
2396cfb9 TS |
4411 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4412 | "c", 7); | |
252b5132 RH |
4413 | return; |
4414 | } | |
4415 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4416 | { | |
4417 | if (strcmp (s2, "mflo") == 0) | |
ea1fb5dc | 4418 | move_register (&icnt, dreg, sreg); |
252b5132 | 4419 | else |
ea1fb5dc | 4420 | move_register (&icnt, dreg, 0); |
252b5132 RH |
4421 | return; |
4422 | } | |
4423 | if (imm_expr.X_op == O_constant | |
4424 | && imm_expr.X_add_number == -1 | |
4425 | && s[strlen (s) - 1] != 'u') | |
4426 | { | |
4427 | if (strcmp (s2, "mflo") == 0) | |
4428 | { | |
2396cfb9 TS |
4429 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
4430 | dbl ? "dneg" : "neg", "d,w", dreg, sreg); | |
252b5132 RH |
4431 | } |
4432 | else | |
ea1fb5dc | 4433 | move_register (&icnt, dreg, 0); |
252b5132 RH |
4434 | return; |
4435 | } | |
4436 | ||
4437 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 TS |
4438 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t", |
4439 | sreg, AT); | |
4440 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg); | |
252b5132 RH |
4441 | break; |
4442 | ||
4443 | case M_DIVU_3: | |
4444 | s = "divu"; | |
4445 | s2 = "mflo"; | |
4446 | goto do_divu3; | |
4447 | case M_REMU_3: | |
4448 | s = "divu"; | |
4449 | s2 = "mfhi"; | |
4450 | goto do_divu3; | |
4451 | case M_DDIVU_3: | |
4452 | s = "ddivu"; | |
4453 | s2 = "mflo"; | |
4454 | goto do_divu3; | |
4455 | case M_DREMU_3: | |
4456 | s = "ddivu"; | |
4457 | s2 = "mfhi"; | |
4458 | do_divu3: | |
4459 | mips_emit_delays (true); | |
4460 | ++mips_opts.noreorder; | |
4461 | mips_any_noreorder = 1; | |
4462 | if (mips_trap) | |
4463 | { | |
2396cfb9 TS |
4464 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
4465 | "s,t", treg, 0); | |
4466 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t", | |
4467 | sreg, treg); | |
252b5132 RH |
4468 | /* We want to close the noreorder block as soon as possible, so |
4469 | that later insns are available for delay slot filling. */ | |
4470 | --mips_opts.noreorder; | |
4471 | } | |
4472 | else | |
4473 | { | |
4474 | expr1.X_add_number = 8; | |
4475 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
2396cfb9 TS |
4476 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t", |
4477 | sreg, treg); | |
252b5132 RH |
4478 | |
4479 | /* We want to close the noreorder block as soon as possible, so | |
4480 | that later insns are available for delay slot filling. */ | |
4481 | --mips_opts.noreorder; | |
2396cfb9 TS |
4482 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4483 | "c", 7); | |
252b5132 | 4484 | } |
2396cfb9 | 4485 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg); |
252b5132 RH |
4486 | return; |
4487 | ||
4488 | case M_DLA_AB: | |
4489 | dbl = 1; | |
4490 | case M_LA_AB: | |
4491 | /* Load the address of a symbol into a register. If breg is not | |
4492 | zero, we then add a base register to it. */ | |
4493 | ||
afdbd6d0 CD |
4494 | if (treg == breg) |
4495 | { | |
4496 | tempreg = AT; | |
4497 | used_at = 1; | |
4498 | } | |
4499 | else | |
4500 | { | |
4501 | tempreg = treg; | |
4502 | used_at = 0; | |
4503 | } | |
4504 | ||
252b5132 RH |
4505 | /* When generating embedded PIC code, we permit expressions of |
4506 | the form | |
afdbd6d0 CD |
4507 | la $treg,foo-bar |
4508 | la $treg,foo-bar($breg) | |
bb2d6cd7 | 4509 | where bar is an address in the current section. These are used |
252b5132 RH |
4510 | when getting the addresses of functions. We don't permit |
4511 | X_add_number to be non-zero, because if the symbol is | |
4512 | external the relaxing code needs to know that any addend is | |
4513 | purely the offset to X_op_symbol. */ | |
4514 | if (mips_pic == EMBEDDED_PIC | |
4515 | && offset_expr.X_op == O_subtract | |
49309057 | 4516 | && (symbol_constant_p (offset_expr.X_op_symbol) |
bb2d6cd7 | 4517 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg |
49309057 ILT |
4518 | : (symbol_equated_p (offset_expr.X_op_symbol) |
4519 | && (S_GET_SEGMENT | |
4520 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
4521 | ->X_add_symbol) | |
bb2d6cd7 | 4522 | == now_seg))) |
bb2d6cd7 GK |
4523 | && (offset_expr.X_add_number == 0 |
4524 | || OUTPUT_FLAVOR == bfd_target_elf_flavour)) | |
252b5132 | 4525 | { |
afdbd6d0 CD |
4526 | if (breg == 0) |
4527 | { | |
4528 | tempreg = treg; | |
4529 | used_at = 0; | |
4530 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4531 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
4532 | } | |
4533 | else | |
4534 | { | |
4535 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4536 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
4537 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4538 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", | |
4539 | "d,v,t", tempreg, tempreg, breg); | |
4540 | } | |
252b5132 | 4541 | macro_build ((char *) NULL, &icnt, &offset_expr, |
ca4e0257 | 4542 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
afdbd6d0 CD |
4543 | "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16); |
4544 | if (! used_at) | |
4545 | return; | |
4546 | break; | |
252b5132 RH |
4547 | } |
4548 | ||
4549 | if (offset_expr.X_op != O_symbol | |
4550 | && offset_expr.X_op != O_constant) | |
4551 | { | |
4552 | as_bad (_("expression too complex")); | |
4553 | offset_expr.X_op = O_constant; | |
4554 | } | |
4555 | ||
252b5132 RH |
4556 | if (offset_expr.X_op == O_constant) |
4557 | load_register (&icnt, tempreg, &offset_expr, dbl); | |
4558 | else if (mips_pic == NO_PIC) | |
4559 | { | |
d6bc6245 | 4560 | /* If this is a reference to a GP relative symbol, we want |
cdf6fd85 | 4561 | addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 RH |
4562 | Otherwise we want |
4563 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4564 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4565 | If we have a constant, we need two instructions anyhow, | |
d6bc6245 | 4566 | so we may as well always use the latter form. |
76b3015f | 4567 | |
d6bc6245 TS |
4568 | With 64bit address space and a usable $at we want |
4569 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
4570 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
4571 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
4572 | daddiu $at,<sym> (BFD_RELOC_LO16) | |
4573 | dsll32 $tempreg,0 | |
4574 | dadd $tempreg,$tempreg,$at | |
76b3015f | 4575 | |
d6bc6245 TS |
4576 | If $at is already in use, we use an path which is suboptimal |
4577 | on superscalar processors. | |
4578 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
4579 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
4580 | dsll $tempreg,16 | |
4581 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4582 | dsll $tempreg,16 | |
4583 | daddiu $tempreg,<sym> (BFD_RELOC_LO16) | |
4584 | */ | |
4585 | p = NULL; | |
4586 | if (HAVE_64BIT_ADDRESSES) | |
252b5132 | 4587 | { |
d6bc6245 TS |
4588 | /* We don't do GP optimization for now because RELAX_ENCODE can't |
4589 | hold the data for such large chunks. */ | |
4590 | ||
4591 | if (used_at == 0) | |
4592 | { | |
4593 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4594 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
4595 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4596 | AT, (int) BFD_RELOC_HI16_S); | |
4597 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4598 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
4599 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4600 | AT, AT, (int) BFD_RELOC_LO16); | |
2396cfb9 TS |
4601 | macro_build (p, &icnt, (expressionS *) NULL, "dsll32", |
4602 | "d,w,<", tempreg, tempreg, 0); | |
4603 | macro_build (p, &icnt, (expressionS *) NULL, "dadd", "d,v,t", | |
d6bc6245 TS |
4604 | tempreg, tempreg, AT); |
4605 | used_at = 1; | |
4606 | } | |
4607 | else | |
4608 | { | |
4609 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4610 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
4611 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4612 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
2396cfb9 | 4613 | macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<", |
d6bc6245 TS |
4614 | tempreg, tempreg, 16); |
4615 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4616 | tempreg, tempreg, (int) BFD_RELOC_HI16_S); | |
2396cfb9 | 4617 | macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<", |
d6bc6245 TS |
4618 | tempreg, tempreg, 16); |
4619 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4620 | tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4621 | } | |
4622 | } | |
4623 | else | |
4624 | { | |
4625 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET | |
4626 | && ! nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
4627 | { | |
4628 | frag_grow (20); | |
4629 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4630 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
cdf6fd85 | 4631 | "t,r,j", tempreg, GP, (int) BFD_RELOC_GPREL16); |
d6bc6245 TS |
4632 | p = frag_var (rs_machine_dependent, 8, 0, |
4633 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
4634 | mips_opts.warn_about_macros), | |
4635 | offset_expr.X_add_symbol, (offsetT) 0, | |
4636 | (char *) NULL); | |
4637 | } | |
4638 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
4639 | if (p != NULL) | |
4640 | p += 4; | |
4641 | macro_build (p, &icnt, &offset_expr, | |
4642 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
4643 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4644 | } | |
252b5132 RH |
4645 | } |
4646 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
4647 | { | |
9117d219 NC |
4648 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
4649 | ||
252b5132 RH |
4650 | /* If this is a reference to an external symbol, and there |
4651 | is no constant, we want | |
4652 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
9117d219 NC |
4653 | or if tempreg is PIC_CALL_REG |
4654 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
252b5132 RH |
4655 | For a local symbol, we want |
4656 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4657 | nop | |
4658 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4659 | ||
4660 | If we have a small constant, and this is a reference to | |
4661 | an external symbol, we want | |
4662 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4663 | nop | |
4664 | addiu $tempreg,$tempreg,<constant> | |
4665 | For a local symbol, we want the same instruction | |
4666 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4667 | addiu instruction. | |
4668 | ||
4669 | If we have a large constant, and this is a reference to | |
4670 | an external symbol, we want | |
4671 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4672 | lui $at,<hiconstant> | |
4673 | addiu $at,$at,<loconstant> | |
4674 | addu $tempreg,$tempreg,$at | |
4675 | For a local symbol, we want the same instruction | |
4676 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4677 | addiu instruction. */ | |
4678 | expr1.X_add_number = offset_expr.X_add_number; | |
4679 | offset_expr.X_add_number = 0; | |
4680 | frag_grow (32); | |
9117d219 NC |
4681 | if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG) |
4682 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16; | |
2396cfb9 | 4683 | macro_build ((char *) NULL, &icnt, &offset_expr, dbl ? "ld" : "lw", |
9117d219 | 4684 | "t,o(b)", tempreg, lw_reloc_type, GP); |
252b5132 RH |
4685 | if (expr1.X_add_number == 0) |
4686 | { | |
4687 | int off; | |
4688 | ||
4689 | if (breg == 0) | |
4690 | off = 0; | |
4691 | else | |
4692 | { | |
4693 | /* We're going to put in an addu instruction using | |
4694 | tempreg, so we may as well insert the nop right | |
4695 | now. */ | |
4696 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4697 | "nop", ""); | |
4698 | off = 4; | |
4699 | } | |
4700 | p = frag_var (rs_machine_dependent, 8 - off, 0, | |
4701 | RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0, | |
4702 | (breg == 0 | |
4703 | ? mips_opts.warn_about_macros | |
4704 | : 0)), | |
c4e7957c | 4705 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
4706 | if (breg == 0) |
4707 | { | |
4708 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4709 | p += 4; | |
4710 | } | |
4711 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4712 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4713 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4714 | /* FIXME: If breg == 0, and the next instruction uses | |
4715 | $tempreg, then if this variant case is used an extra | |
4716 | nop will be generated. */ | |
4717 | } | |
4718 | else if (expr1.X_add_number >= -0x8000 | |
4719 | && expr1.X_add_number < 0x8000) | |
4720 | { | |
4721 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4722 | "nop", ""); | |
4723 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4724 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 | 4725 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
c4e7957c TS |
4726 | frag_var (rs_machine_dependent, 0, 0, |
4727 | RELAX_ENCODE (0, 0, -12, -4, 0, 0), | |
4728 | offset_expr.X_add_symbol, 0, NULL); | |
252b5132 RH |
4729 | } |
4730 | else | |
4731 | { | |
4732 | int off1; | |
4733 | ||
4734 | /* If we are going to add in a base register, and the | |
4735 | target register and the base register are the same, | |
4736 | then we are using AT as a temporary register. Since | |
4737 | we want to load the constant into AT, we add our | |
4738 | current AT (from the global offset table) and the | |
4739 | register into the register now, and pretend we were | |
4740 | not using a base register. */ | |
4741 | if (breg != treg) | |
4742 | off1 = 0; | |
4743 | else | |
4744 | { | |
4745 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4746 | "nop", ""); | |
4747 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4748 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4749 | "d,v,t", treg, AT, breg); |
4750 | breg = 0; | |
4751 | tempreg = treg; | |
4752 | off1 = -8; | |
4753 | } | |
4754 | ||
4755 | /* Set mips_optimize around the lui instruction to avoid | |
4756 | inserting an unnecessary nop after the lw. */ | |
4757 | hold_mips_optimize = mips_optimize; | |
4758 | mips_optimize = 2; | |
c4e7957c | 4759 | macro_build_lui (NULL, &icnt, &expr1, AT); |
252b5132 RH |
4760 | mips_optimize = hold_mips_optimize; |
4761 | ||
4762 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4763 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4764 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4765 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4766 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 4767 | "d,v,t", tempreg, tempreg, AT); |
c4e7957c TS |
4768 | frag_var (rs_machine_dependent, 0, 0, |
4769 | RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0), | |
4770 | offset_expr.X_add_symbol, 0, NULL); | |
252b5132 RH |
4771 | used_at = 1; |
4772 | } | |
4773 | } | |
4774 | else if (mips_pic == SVR4_PIC) | |
4775 | { | |
4776 | int gpdel; | |
9117d219 NC |
4777 | int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16; |
4778 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16; | |
252b5132 RH |
4779 | |
4780 | /* This is the large GOT case. If this is a reference to an | |
4781 | external symbol, and there is no constant, we want | |
4782 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4783 | addu $tempreg,$tempreg,$gp | |
4784 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
9117d219 NC |
4785 | or if tempreg is PIC_CALL_REG |
4786 | lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
4787 | addu $tempreg,$tempreg,$gp | |
4788 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16) | |
252b5132 RH |
4789 | For a local symbol, we want |
4790 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4791 | nop | |
4792 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4793 | ||
4794 | If we have a small constant, and this is a reference to | |
4795 | an external symbol, we want | |
4796 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4797 | addu $tempreg,$tempreg,$gp | |
4798 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4799 | nop | |
4800 | addiu $tempreg,$tempreg,<constant> | |
4801 | For a local symbol, we want | |
4802 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4803 | nop | |
4804 | addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16) | |
4805 | ||
4806 | If we have a large constant, and this is a reference to | |
4807 | an external symbol, we want | |
4808 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4809 | addu $tempreg,$tempreg,$gp | |
4810 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4811 | lui $at,<hiconstant> | |
4812 | addiu $at,$at,<loconstant> | |
4813 | addu $tempreg,$tempreg,$at | |
4814 | For a local symbol, we want | |
4815 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4816 | lui $at,<hiconstant> | |
4817 | addiu $at,$at,<loconstant> (BFD_RELOC_LO16) | |
4818 | addu $tempreg,$tempreg,$at | |
4819 | */ | |
4820 | expr1.X_add_number = offset_expr.X_add_number; | |
4821 | offset_expr.X_add_number = 0; | |
4822 | frag_grow (52); | |
4823 | if (reg_needs_delay (GP)) | |
4824 | gpdel = 4; | |
4825 | else | |
4826 | gpdel = 0; | |
9117d219 NC |
4827 | if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG) |
4828 | { | |
4829 | lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16; | |
4830 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16; | |
4831 | } | |
252b5132 | 4832 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", |
9117d219 | 4833 | tempreg, lui_reloc_type); |
252b5132 | 4834 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
ca4e0257 | 4835 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4836 | "d,v,t", tempreg, tempreg, GP); |
4837 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4838 | dbl ? "ld" : "lw", | |
9117d219 | 4839 | "t,o(b)", tempreg, lw_reloc_type, tempreg); |
252b5132 RH |
4840 | if (expr1.X_add_number == 0) |
4841 | { | |
4842 | int off; | |
4843 | ||
4844 | if (breg == 0) | |
4845 | off = 0; | |
4846 | else | |
4847 | { | |
4848 | /* We're going to put in an addu instruction using | |
4849 | tempreg, so we may as well insert the nop right | |
4850 | now. */ | |
4851 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4852 | "nop", ""); | |
4853 | off = 4; | |
4854 | } | |
4855 | ||
4856 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4857 | RELAX_ENCODE (12 + off, 12 + gpdel, gpdel, | |
4858 | 8 + gpdel, 0, | |
4859 | (breg == 0 | |
4860 | ? mips_opts.warn_about_macros | |
4861 | : 0)), | |
c4e7957c | 4862 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
4863 | } |
4864 | else if (expr1.X_add_number >= -0x8000 | |
4865 | && expr1.X_add_number < 0x8000) | |
4866 | { | |
4867 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4868 | "nop", ""); | |
4869 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4870 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4871 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4872 | ||
4873 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4874 | RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0, | |
4875 | (breg == 0 | |
4876 | ? mips_opts.warn_about_macros | |
4877 | : 0)), | |
c4e7957c | 4878 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
4879 | } |
4880 | else | |
4881 | { | |
4882 | int adj, dreg; | |
4883 | ||
4884 | /* If we are going to add in a base register, and the | |
4885 | target register and the base register are the same, | |
4886 | then we are using AT as a temporary register. Since | |
4887 | we want to load the constant into AT, we add our | |
4888 | current AT (from the global offset table) and the | |
4889 | register into the register now, and pretend we were | |
4890 | not using a base register. */ | |
4891 | if (breg != treg) | |
4892 | { | |
4893 | adj = 0; | |
4894 | dreg = tempreg; | |
4895 | } | |
4896 | else | |
4897 | { | |
4898 | assert (tempreg == AT); | |
4899 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4900 | "nop", ""); | |
4901 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4902 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4903 | "d,v,t", treg, AT, breg); |
4904 | dreg = treg; | |
4905 | adj = 8; | |
4906 | } | |
4907 | ||
4908 | /* Set mips_optimize around the lui instruction to avoid | |
4909 | inserting an unnecessary nop after the lw. */ | |
4910 | hold_mips_optimize = mips_optimize; | |
4911 | mips_optimize = 2; | |
c4e7957c | 4912 | macro_build_lui (NULL, &icnt, &expr1, AT); |
252b5132 RH |
4913 | mips_optimize = hold_mips_optimize; |
4914 | ||
4915 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4916 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4917 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4918 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4919 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4920 | "d,v,t", dreg, dreg, AT); |
4921 | ||
4922 | p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0, | |
4923 | RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel, | |
4924 | 8 + gpdel, 0, | |
4925 | (breg == 0 | |
4926 | ? mips_opts.warn_about_macros | |
4927 | : 0)), | |
c4e7957c | 4928 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
4929 | |
4930 | used_at = 1; | |
4931 | } | |
4932 | ||
4933 | if (gpdel > 0) | |
4934 | { | |
4935 | /* This is needed because this instruction uses $gp, but | |
4936 | the first instruction on the main stream does not. */ | |
4937 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4938 | p += 4; | |
4939 | } | |
4940 | macro_build (p, &icnt, &offset_expr, | |
4941 | dbl ? "ld" : "lw", | |
4942 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
4943 | p += 4; | |
4944 | if (expr1.X_add_number >= -0x8000 | |
4945 | && expr1.X_add_number < 0x8000) | |
4946 | { | |
4947 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4948 | p += 4; | |
4949 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4950 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4951 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4952 | /* FIXME: If add_number is 0, and there was no base | |
4953 | register, the external symbol case ended with a load, | |
4954 | so if the symbol turns out to not be external, and | |
4955 | the next instruction uses tempreg, an unnecessary nop | |
4956 | will be inserted. */ | |
4957 | } | |
4958 | else | |
4959 | { | |
4960 | if (breg == treg) | |
4961 | { | |
4962 | /* We must add in the base register now, as in the | |
4963 | external symbol case. */ | |
4964 | assert (tempreg == AT); | |
4965 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4966 | p += 4; | |
4967 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4968 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4969 | "d,v,t", treg, AT, breg); |
4970 | p += 4; | |
4971 | tempreg = treg; | |
4972 | /* We set breg to 0 because we have arranged to add | |
4973 | it in in both cases. */ | |
4974 | breg = 0; | |
4975 | } | |
4976 | ||
4977 | macro_build_lui (p, &icnt, &expr1, AT); | |
4978 | p += 4; | |
4979 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4980 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4981 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4982 | p += 4; | |
4983 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4984 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4985 | "d,v,t", tempreg, tempreg, AT); |
4986 | p += 4; | |
4987 | } | |
4988 | } | |
4989 | else if (mips_pic == EMBEDDED_PIC) | |
4990 | { | |
4991 | /* We use | |
cdf6fd85 | 4992 | addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 RH |
4993 | */ |
4994 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 4995 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
cdf6fd85 | 4996 | "t,r,j", tempreg, GP, (int) BFD_RELOC_GPREL16); |
252b5132 RH |
4997 | } |
4998 | else | |
4999 | abort (); | |
5000 | ||
5001 | if (breg != 0) | |
5002 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5003 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5004 | "d,v,t", treg, tempreg, breg); |
5005 | ||
5006 | if (! used_at) | |
5007 | return; | |
5008 | ||
5009 | break; | |
5010 | ||
5011 | case M_J_A: | |
5012 | /* The j instruction may not be used in PIC code, since it | |
5013 | requires an absolute address. We convert it to a b | |
5014 | instruction. */ | |
5015 | if (mips_pic == NO_PIC) | |
5016 | macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a"); | |
5017 | else | |
5018 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
5019 | return; | |
5020 | ||
5021 | /* The jal instructions must be handled as macros because when | |
5022 | generating PIC code they expand to multi-instruction | |
5023 | sequences. Normally they are simple instructions. */ | |
5024 | case M_JAL_1: | |
5025 | dreg = RA; | |
5026 | /* Fall through. */ | |
5027 | case M_JAL_2: | |
5028 | if (mips_pic == NO_PIC | |
5029 | || mips_pic == EMBEDDED_PIC) | |
5030 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", | |
5031 | "d,s", dreg, sreg); | |
5032 | else if (mips_pic == SVR4_PIC) | |
5033 | { | |
5034 | if (sreg != PIC_CALL_REG) | |
5035 | as_warn (_("MIPS PIC call to register other than $25")); | |
bdaaa2e1 | 5036 | |
252b5132 RH |
5037 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", |
5038 | "d,s", dreg, sreg); | |
6478892d | 5039 | if (! HAVE_NEWABI) |
252b5132 | 5040 | { |
6478892d TS |
5041 | if (mips_cprestore_offset < 0) |
5042 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
5043 | else | |
5044 | { | |
5045 | expr1.X_add_number = mips_cprestore_offset; | |
5046 | macro_build ((char *) NULL, &icnt, &expr1, | |
5047 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", | |
5048 | GP, (int) BFD_RELOC_LO16, mips_frame_reg); | |
5049 | } | |
252b5132 RH |
5050 | } |
5051 | } | |
5052 | else | |
5053 | abort (); | |
5054 | ||
5055 | return; | |
5056 | ||
5057 | case M_JAL_A: | |
5058 | if (mips_pic == NO_PIC) | |
5059 | macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a"); | |
5060 | else if (mips_pic == SVR4_PIC) | |
5061 | { | |
5062 | /* If this is a reference to an external symbol, and we are | |
5063 | using a small GOT, we want | |
5064 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
5065 | nop | |
5066 | jalr $25 | |
5067 | nop | |
5068 | lw $gp,cprestore($sp) | |
5069 | The cprestore value is set using the .cprestore | |
5070 | pseudo-op. If we are using a big GOT, we want | |
5071 | lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
5072 | addu $25,$25,$gp | |
5073 | lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16) | |
5074 | nop | |
5075 | jalr $25 | |
5076 | nop | |
5077 | lw $gp,cprestore($sp) | |
5078 | If the symbol is not external, we want | |
5079 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5080 | nop | |
5081 | addiu $25,$25,<sym> (BFD_RELOC_LO16) | |
5082 | jalr $25 | |
5083 | nop | |
5084 | lw $gp,cprestore($sp) */ | |
5085 | frag_grow (40); | |
5086 | if (! mips_big_got) | |
5087 | { | |
5088 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5089 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5090 | "t,o(b)", PIC_CALL_REG, |
5091 | (int) BFD_RELOC_MIPS_CALL16, GP); | |
5092 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5093 | "nop", ""); | |
5094 | p = frag_var (rs_machine_dependent, 4, 0, | |
5095 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), | |
c4e7957c | 5096 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5097 | } |
5098 | else | |
5099 | { | |
5100 | int gpdel; | |
5101 | ||
5102 | if (reg_needs_delay (GP)) | |
5103 | gpdel = 4; | |
5104 | else | |
5105 | gpdel = 0; | |
5106 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5107 | PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16); | |
5108 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5109 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5110 | "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP); |
5111 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5112 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5113 | "t,o(b)", PIC_CALL_REG, |
5114 | (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG); | |
5115 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5116 | "nop", ""); | |
5117 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5118 | RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel, | |
5119 | 0, 0), | |
c4e7957c | 5120 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5121 | if (gpdel > 0) |
5122 | { | |
5123 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5124 | p += 4; | |
5125 | } | |
5126 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5127 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5128 | "t,o(b)", PIC_CALL_REG, |
5129 | (int) BFD_RELOC_MIPS_GOT16, GP); | |
5130 | p += 4; | |
5131 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5132 | p += 4; | |
bdaaa2e1 | 5133 | } |
252b5132 | 5134 | macro_build (p, &icnt, &offset_expr, |
ca4e0257 | 5135 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5136 | "t,r,j", PIC_CALL_REG, PIC_CALL_REG, |
5137 | (int) BFD_RELOC_LO16); | |
5138 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5139 | "jalr", "s", PIC_CALL_REG); | |
6478892d | 5140 | if (! HAVE_NEWABI) |
252b5132 | 5141 | { |
6478892d TS |
5142 | if (mips_cprestore_offset < 0) |
5143 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
5144 | else | |
5145 | { | |
5146 | if (mips_opts.noreorder) | |
5147 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
252b5132 | 5148 | "nop", ""); |
6478892d TS |
5149 | expr1.X_add_number = mips_cprestore_offset; |
5150 | macro_build ((char *) NULL, &icnt, &expr1, | |
5151 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", | |
5152 | GP, (int) BFD_RELOC_LO16, mips_frame_reg); | |
5153 | } | |
252b5132 RH |
5154 | } |
5155 | } | |
5156 | else if (mips_pic == EMBEDDED_PIC) | |
5157 | { | |
5158 | macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p"); | |
5159 | /* The linker may expand the call to a longer sequence which | |
5160 | uses $at, so we must break rather than return. */ | |
5161 | break; | |
5162 | } | |
5163 | else | |
5164 | abort (); | |
5165 | ||
5166 | return; | |
5167 | ||
5168 | case M_LB_AB: | |
5169 | s = "lb"; | |
5170 | goto ld; | |
5171 | case M_LBU_AB: | |
5172 | s = "lbu"; | |
5173 | goto ld; | |
5174 | case M_LH_AB: | |
5175 | s = "lh"; | |
5176 | goto ld; | |
5177 | case M_LHU_AB: | |
5178 | s = "lhu"; | |
5179 | goto ld; | |
5180 | case M_LW_AB: | |
5181 | s = "lw"; | |
5182 | goto ld; | |
5183 | case M_LWC0_AB: | |
5184 | s = "lwc0"; | |
bdaaa2e1 | 5185 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5186 | coproc = 1; |
5187 | goto ld; | |
5188 | case M_LWC1_AB: | |
5189 | s = "lwc1"; | |
bdaaa2e1 | 5190 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5191 | coproc = 1; |
5192 | goto ld; | |
5193 | case M_LWC2_AB: | |
5194 | s = "lwc2"; | |
bdaaa2e1 | 5195 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5196 | coproc = 1; |
5197 | goto ld; | |
5198 | case M_LWC3_AB: | |
5199 | s = "lwc3"; | |
bdaaa2e1 | 5200 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5201 | coproc = 1; |
5202 | goto ld; | |
5203 | case M_LWL_AB: | |
5204 | s = "lwl"; | |
5205 | lr = 1; | |
5206 | goto ld; | |
5207 | case M_LWR_AB: | |
5208 | s = "lwr"; | |
5209 | lr = 1; | |
5210 | goto ld; | |
5211 | case M_LDC1_AB: | |
ec68c924 | 5212 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5213 | { |
5214 | as_bad (_("opcode not supported on this processor")); | |
5215 | return; | |
5216 | } | |
5217 | s = "ldc1"; | |
bdaaa2e1 | 5218 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5219 | coproc = 1; |
5220 | goto ld; | |
5221 | case M_LDC2_AB: | |
5222 | s = "ldc2"; | |
bdaaa2e1 | 5223 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5224 | coproc = 1; |
5225 | goto ld; | |
5226 | case M_LDC3_AB: | |
5227 | s = "ldc3"; | |
bdaaa2e1 | 5228 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5229 | coproc = 1; |
5230 | goto ld; | |
5231 | case M_LDL_AB: | |
5232 | s = "ldl"; | |
5233 | lr = 1; | |
5234 | goto ld; | |
5235 | case M_LDR_AB: | |
5236 | s = "ldr"; | |
5237 | lr = 1; | |
5238 | goto ld; | |
5239 | case M_LL_AB: | |
5240 | s = "ll"; | |
5241 | goto ld; | |
5242 | case M_LLD_AB: | |
5243 | s = "lld"; | |
5244 | goto ld; | |
5245 | case M_LWU_AB: | |
5246 | s = "lwu"; | |
5247 | ld: | |
5248 | if (breg == treg || coproc || lr) | |
5249 | { | |
5250 | tempreg = AT; | |
5251 | used_at = 1; | |
5252 | } | |
5253 | else | |
5254 | { | |
5255 | tempreg = treg; | |
5256 | used_at = 0; | |
5257 | } | |
5258 | goto ld_st; | |
5259 | case M_SB_AB: | |
5260 | s = "sb"; | |
5261 | goto st; | |
5262 | case M_SH_AB: | |
5263 | s = "sh"; | |
5264 | goto st; | |
5265 | case M_SW_AB: | |
5266 | s = "sw"; | |
5267 | goto st; | |
5268 | case M_SWC0_AB: | |
5269 | s = "swc0"; | |
bdaaa2e1 | 5270 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5271 | coproc = 1; |
5272 | goto st; | |
5273 | case M_SWC1_AB: | |
5274 | s = "swc1"; | |
bdaaa2e1 | 5275 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5276 | coproc = 1; |
5277 | goto st; | |
5278 | case M_SWC2_AB: | |
5279 | s = "swc2"; | |
bdaaa2e1 | 5280 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5281 | coproc = 1; |
5282 | goto st; | |
5283 | case M_SWC3_AB: | |
5284 | s = "swc3"; | |
bdaaa2e1 | 5285 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5286 | coproc = 1; |
5287 | goto st; | |
5288 | case M_SWL_AB: | |
5289 | s = "swl"; | |
5290 | goto st; | |
5291 | case M_SWR_AB: | |
5292 | s = "swr"; | |
5293 | goto st; | |
5294 | case M_SC_AB: | |
5295 | s = "sc"; | |
5296 | goto st; | |
5297 | case M_SCD_AB: | |
5298 | s = "scd"; | |
5299 | goto st; | |
5300 | case M_SDC1_AB: | |
ec68c924 | 5301 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5302 | { |
5303 | as_bad (_("opcode not supported on this processor")); | |
5304 | return; | |
5305 | } | |
5306 | s = "sdc1"; | |
5307 | coproc = 1; | |
bdaaa2e1 | 5308 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5309 | goto st; |
5310 | case M_SDC2_AB: | |
5311 | s = "sdc2"; | |
bdaaa2e1 | 5312 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5313 | coproc = 1; |
5314 | goto st; | |
5315 | case M_SDC3_AB: | |
5316 | s = "sdc3"; | |
bdaaa2e1 | 5317 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5318 | coproc = 1; |
5319 | goto st; | |
5320 | case M_SDL_AB: | |
5321 | s = "sdl"; | |
5322 | goto st; | |
5323 | case M_SDR_AB: | |
5324 | s = "sdr"; | |
5325 | st: | |
5326 | tempreg = AT; | |
5327 | used_at = 1; | |
5328 | ld_st: | |
bdaaa2e1 | 5329 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5330 | if (mask == M_LWC1_AB |
5331 | || mask == M_SWC1_AB | |
5332 | || mask == M_LDC1_AB | |
5333 | || mask == M_SDC1_AB | |
5334 | || mask == M_L_DAB | |
5335 | || mask == M_S_DAB) | |
5336 | fmt = "T,o(b)"; | |
5337 | else if (coproc) | |
5338 | fmt = "E,o(b)"; | |
5339 | else | |
5340 | fmt = "t,o(b)"; | |
5341 | ||
afdbd6d0 CD |
5342 | /* For embedded PIC, we allow loads where the offset is calculated |
5343 | by subtracting a symbol in the current segment from an unknown | |
5344 | symbol, relative to a base register, e.g.: | |
5345 | <op> $treg, <sym>-<localsym>($breg) | |
5346 | This is used by the compiler for switch statements. */ | |
76b3015f | 5347 | if (mips_pic == EMBEDDED_PIC |
afdbd6d0 CD |
5348 | && offset_expr.X_op == O_subtract |
5349 | && (symbol_constant_p (offset_expr.X_op_symbol) | |
5350 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg | |
5351 | : (symbol_equated_p (offset_expr.X_op_symbol) | |
5352 | && (S_GET_SEGMENT | |
5353 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
5354 | ->X_add_symbol) | |
5355 | == now_seg))) | |
5356 | && breg != 0 | |
5357 | && (offset_expr.X_add_number == 0 | |
5358 | || OUTPUT_FLAVOR == bfd_target_elf_flavour)) | |
5359 | { | |
5360 | /* For this case, we output the instructions: | |
5361 | lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S) | |
5362 | addiu $tempreg,$tempreg,$breg | |
5363 | <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16) | |
5364 | If the relocation would fit entirely in 16 bits, it would be | |
5365 | nice to emit: | |
5366 | <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16) | |
5367 | instead, but that seems quite difficult. */ | |
5368 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5369 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
5370 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5371 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5372 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
5373 | ? "addu" : "daddu"), | |
5374 | "d,v,t", tempreg, tempreg, breg); | |
5375 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg, | |
5376 | (int) BFD_RELOC_PCREL_LO16, tempreg); | |
5377 | if (! used_at) | |
5378 | return; | |
5379 | break; | |
5380 | } | |
5381 | ||
252b5132 RH |
5382 | if (offset_expr.X_op != O_constant |
5383 | && offset_expr.X_op != O_symbol) | |
5384 | { | |
5385 | as_bad (_("expression too complex")); | |
5386 | offset_expr.X_op = O_constant; | |
5387 | } | |
5388 | ||
5389 | /* A constant expression in PIC code can be handled just as it | |
5390 | is in non PIC code. */ | |
5391 | if (mips_pic == NO_PIC | |
5392 | || offset_expr.X_op == O_constant) | |
5393 | { | |
5394 | /* If this is a reference to a GP relative symbol, and there | |
5395 | is no base register, we want | |
cdf6fd85 | 5396 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
252b5132 RH |
5397 | Otherwise, if there is no base register, we want |
5398 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5399 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5400 | If we have a constant, we need two instructions anyhow, | |
5401 | so we always use the latter form. | |
5402 | ||
5403 | If we have a base register, and this is a reference to a | |
5404 | GP relative symbol, we want | |
5405 | addu $tempreg,$breg,$gp | |
cdf6fd85 | 5406 | <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16) |
252b5132 RH |
5407 | Otherwise we want |
5408 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5409 | addu $tempreg,$tempreg,$breg | |
5410 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
d6bc6245 | 5411 | With a constant we always use the latter case. |
76b3015f | 5412 | |
d6bc6245 TS |
5413 | With 64bit address space and no base register and $at usable, |
5414 | we want | |
5415 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5416 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5417 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5418 | dsll32 $tempreg,0 | |
5419 | daddu $tempreg,$at | |
5420 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5421 | If we have a base register, we want | |
5422 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5423 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5424 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5425 | daddu $at,$breg | |
5426 | dsll32 $tempreg,0 | |
5427 | daddu $tempreg,$at | |
5428 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5429 | ||
5430 | Without $at we can't generate the optimal path for superscalar | |
5431 | processors here since this would require two temporary registers. | |
5432 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5433 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5434 | dsll $tempreg,16 | |
5435 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5436 | dsll $tempreg,16 | |
5437 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5438 | If we have a base register, we want | |
5439 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5440 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5441 | dsll $tempreg,16 | |
5442 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5443 | dsll $tempreg,16 | |
5444 | daddu $tempreg,$tempreg,$breg | |
5445 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5446 | */ | |
5447 | if (HAVE_64BIT_ADDRESSES) | |
5448 | { | |
5449 | p = NULL; | |
5450 | ||
5451 | /* We don't do GP optimization for now because RELAX_ENCODE can't | |
5452 | hold the data for such large chunks. */ | |
5453 | ||
5454 | if (used_at == 0) | |
5455 | { | |
5456 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5457 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
5458 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5459 | AT, (int) BFD_RELOC_HI16_S); | |
5460 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
5461 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
5462 | if (breg != 0) | |
2396cfb9 TS |
5463 | macro_build (p, &icnt, (expressionS *) NULL, "daddu", |
5464 | "d,v,t", AT, AT, breg); | |
5465 | macro_build (p, &icnt, (expressionS *) NULL, "dsll32", | |
5466 | "d,w,<", tempreg, tempreg, 0); | |
5467 | macro_build (p, &icnt, (expressionS *) NULL, "daddu", | |
5468 | "d,v,t", tempreg, tempreg, AT); | |
d6bc6245 TS |
5469 | macro_build (p, &icnt, &offset_expr, s, |
5470 | fmt, treg, (int) BFD_RELOC_LO16, tempreg); | |
5471 | used_at = 1; | |
5472 | } | |
5473 | else | |
5474 | { | |
5475 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5476 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
5477 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
5478 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
2396cfb9 TS |
5479 | macro_build (p, &icnt, (expressionS *) NULL, "dsll", |
5480 | "d,w,<", tempreg, tempreg, 16); | |
d6bc6245 TS |
5481 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", |
5482 | tempreg, tempreg, (int) BFD_RELOC_HI16_S); | |
2396cfb9 TS |
5483 | macro_build (p, &icnt, (expressionS *) NULL, "dsll", |
5484 | "d,w,<", tempreg, tempreg, 16); | |
d6bc6245 | 5485 | if (breg != 0) |
2396cfb9 TS |
5486 | macro_build (p, &icnt, (expressionS *) NULL, "daddu", |
5487 | "d,v,t", tempreg, tempreg, breg); | |
d6bc6245 TS |
5488 | macro_build (p, &icnt, &offset_expr, s, |
5489 | fmt, treg, (int) BFD_RELOC_LO16, tempreg); | |
5490 | } | |
5491 | ||
5492 | return; | |
5493 | } | |
76b3015f | 5494 | |
252b5132 RH |
5495 | if (breg == 0) |
5496 | { | |
e7d556df | 5497 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5498 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5499 | p = NULL; | |
5500 | else | |
5501 | { | |
5502 | frag_grow (20); | |
5503 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
cdf6fd85 | 5504 | treg, (int) BFD_RELOC_GPREL16, GP); |
252b5132 RH |
5505 | p = frag_var (rs_machine_dependent, 8, 0, |
5506 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
5507 | (mips_opts.warn_about_macros | |
5508 | || (used_at | |
5509 | && mips_opts.noat))), | |
5510 | offset_expr.X_add_symbol, (offsetT) 0, | |
5511 | (char *) NULL); | |
5512 | used_at = 0; | |
5513 | } | |
5514 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5515 | if (p != NULL) | |
5516 | p += 4; | |
5517 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5518 | (int) BFD_RELOC_LO16, tempreg); | |
5519 | } | |
5520 | else | |
5521 | { | |
e7d556df | 5522 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5523 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5524 | p = NULL; | |
5525 | else | |
5526 | { | |
5527 | frag_grow (28); | |
5528 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5529 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5530 | "d,v,t", tempreg, breg, GP); |
5531 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
cdf6fd85 | 5532 | treg, (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
5533 | p = frag_var (rs_machine_dependent, 12, 0, |
5534 | RELAX_ENCODE (8, 12, 0, 8, 0, 0), | |
5535 | offset_expr.X_add_symbol, (offsetT) 0, | |
5536 | (char *) NULL); | |
5537 | } | |
5538 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5539 | if (p != NULL) | |
5540 | p += 4; | |
5541 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5542 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5543 | "d,v,t", tempreg, tempreg, breg); |
5544 | if (p != NULL) | |
5545 | p += 4; | |
5546 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5547 | (int) BFD_RELOC_LO16, tempreg); | |
5548 | } | |
5549 | } | |
5550 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
5551 | { | |
5552 | /* If this is a reference to an external symbol, we want | |
5553 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5554 | nop | |
5555 | <op> $treg,0($tempreg) | |
5556 | Otherwise we want | |
5557 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5558 | nop | |
5559 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5560 | <op> $treg,0($tempreg) | |
5561 | If there is a base register, we add it to $tempreg before | |
5562 | the <op>. If there is a constant, we stick it in the | |
5563 | <op> instruction. We don't handle constants larger than | |
5564 | 16 bits, because we have no way to load the upper 16 bits | |
5565 | (actually, we could handle them for the subset of cases | |
5566 | in which we are not using $at). */ | |
5567 | assert (offset_expr.X_op == O_symbol); | |
5568 | expr1.X_add_number = offset_expr.X_add_number; | |
5569 | offset_expr.X_add_number = 0; | |
5570 | if (expr1.X_add_number < -0x8000 | |
5571 | || expr1.X_add_number >= 0x8000) | |
5572 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5573 | frag_grow (20); | |
5574 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5575 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5576 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); |
5577 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
bdaaa2e1 | 5578 | p = frag_var (rs_machine_dependent, 4, 0, |
252b5132 | 5579 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), |
c4e7957c | 5580 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 | 5581 | macro_build (p, &icnt, &offset_expr, |
ca4e0257 | 5582 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5583 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5584 | if (breg != 0) | |
5585 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5586 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5587 | "d,v,t", tempreg, tempreg, breg); |
5588 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5589 | (int) BFD_RELOC_LO16, tempreg); | |
5590 | } | |
5591 | else if (mips_pic == SVR4_PIC) | |
5592 | { | |
5593 | int gpdel; | |
5594 | ||
5595 | /* If this is a reference to an external symbol, we want | |
5596 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5597 | addu $tempreg,$tempreg,$gp | |
5598 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
5599 | <op> $treg,0($tempreg) | |
5600 | Otherwise we want | |
5601 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5602 | nop | |
5603 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5604 | <op> $treg,0($tempreg) | |
5605 | If there is a base register, we add it to $tempreg before | |
5606 | the <op>. If there is a constant, we stick it in the | |
5607 | <op> instruction. We don't handle constants larger than | |
5608 | 16 bits, because we have no way to load the upper 16 bits | |
5609 | (actually, we could handle them for the subset of cases | |
5610 | in which we are not using $at). */ | |
5611 | assert (offset_expr.X_op == O_symbol); | |
5612 | expr1.X_add_number = offset_expr.X_add_number; | |
5613 | offset_expr.X_add_number = 0; | |
5614 | if (expr1.X_add_number < -0x8000 | |
5615 | || expr1.X_add_number >= 0x8000) | |
5616 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5617 | if (reg_needs_delay (GP)) | |
5618 | gpdel = 4; | |
5619 | else | |
5620 | gpdel = 0; | |
5621 | frag_grow (36); | |
5622 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5623 | tempreg, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5624 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5625 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5626 | "d,v,t", tempreg, tempreg, GP); |
5627 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5628 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5629 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16, |
5630 | tempreg); | |
5631 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5632 | RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0), | |
c4e7957c | 5633 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5634 | if (gpdel > 0) |
5635 | { | |
5636 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5637 | p += 4; | |
5638 | } | |
5639 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5640 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5641 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); |
5642 | p += 4; | |
5643 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5644 | p += 4; | |
5645 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5646 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5647 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5648 | if (breg != 0) | |
5649 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5650 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5651 | "d,v,t", tempreg, tempreg, breg); |
5652 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5653 | (int) BFD_RELOC_LO16, tempreg); | |
5654 | } | |
5655 | else if (mips_pic == EMBEDDED_PIC) | |
5656 | { | |
5657 | /* If there is no base register, we want | |
cdf6fd85 | 5658 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
252b5132 RH |
5659 | If there is a base register, we want |
5660 | addu $tempreg,$breg,$gp | |
cdf6fd85 | 5661 | <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16) |
252b5132 RH |
5662 | */ |
5663 | assert (offset_expr.X_op == O_symbol); | |
5664 | if (breg == 0) | |
5665 | { | |
5666 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
cdf6fd85 | 5667 | treg, (int) BFD_RELOC_GPREL16, GP); |
252b5132 RH |
5668 | used_at = 0; |
5669 | } | |
5670 | else | |
5671 | { | |
5672 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5673 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5674 | "d,v,t", tempreg, breg, GP); |
5675 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
cdf6fd85 | 5676 | treg, (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
5677 | } |
5678 | } | |
5679 | else | |
5680 | abort (); | |
5681 | ||
5682 | if (! used_at) | |
5683 | return; | |
5684 | ||
5685 | break; | |
5686 | ||
5687 | case M_LI: | |
5688 | case M_LI_S: | |
5689 | load_register (&icnt, treg, &imm_expr, 0); | |
5690 | return; | |
5691 | ||
5692 | case M_DLI: | |
5693 | load_register (&icnt, treg, &imm_expr, 1); | |
5694 | return; | |
5695 | ||
5696 | case M_LI_SS: | |
5697 | if (imm_expr.X_op == O_constant) | |
5698 | { | |
5699 | load_register (&icnt, AT, &imm_expr, 0); | |
5700 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5701 | "mtc1", "t,G", AT, treg); | |
5702 | break; | |
5703 | } | |
5704 | else | |
5705 | { | |
5706 | assert (offset_expr.X_op == O_symbol | |
5707 | && strcmp (segment_name (S_GET_SEGMENT | |
5708 | (offset_expr.X_add_symbol)), | |
5709 | ".lit4") == 0 | |
5710 | && offset_expr.X_add_number == 0); | |
5711 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5712 | treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5713 | return; | |
5714 | } | |
5715 | ||
5716 | case M_LI_D: | |
ca4e0257 RS |
5717 | /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits |
5718 | wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high | |
5719 | order 32 bits of the value and the low order 32 bits are either | |
5720 | zero or in OFFSET_EXPR. */ | |
252b5132 RH |
5721 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
5722 | { | |
ca4e0257 | 5723 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5724 | load_register (&icnt, treg, &imm_expr, 1); |
5725 | else | |
5726 | { | |
5727 | int hreg, lreg; | |
5728 | ||
5729 | if (target_big_endian) | |
5730 | { | |
5731 | hreg = treg; | |
5732 | lreg = treg + 1; | |
5733 | } | |
5734 | else | |
5735 | { | |
5736 | hreg = treg + 1; | |
5737 | lreg = treg; | |
5738 | } | |
5739 | ||
5740 | if (hreg <= 31) | |
5741 | load_register (&icnt, hreg, &imm_expr, 0); | |
5742 | if (lreg <= 31) | |
5743 | { | |
5744 | if (offset_expr.X_op == O_absent) | |
ea1fb5dc | 5745 | move_register (&icnt, lreg, 0); |
252b5132 RH |
5746 | else |
5747 | { | |
5748 | assert (offset_expr.X_op == O_constant); | |
5749 | load_register (&icnt, lreg, &offset_expr, 0); | |
5750 | } | |
5751 | } | |
5752 | } | |
5753 | return; | |
5754 | } | |
5755 | ||
5756 | /* We know that sym is in the .rdata section. First we get the | |
5757 | upper 16 bits of the address. */ | |
5758 | if (mips_pic == NO_PIC) | |
5759 | { | |
5760 | /* FIXME: This won't work for a 64 bit address. */ | |
5761 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5762 | } | |
5763 | else if (mips_pic == SVR4_PIC) | |
5764 | { | |
5765 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5766 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5767 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
5768 | } | |
5769 | else if (mips_pic == EMBEDDED_PIC) | |
5770 | { | |
5771 | /* For embedded PIC we pick up the entire address off $gp in | |
5772 | a single instruction. */ | |
5773 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5774 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
cdf6fd85 | 5775 | "t,r,j", AT, GP, (int) BFD_RELOC_GPREL16); |
252b5132 RH |
5776 | offset_expr.X_op = O_constant; |
5777 | offset_expr.X_add_number = 0; | |
5778 | } | |
5779 | else | |
5780 | abort (); | |
bdaaa2e1 | 5781 | |
252b5132 | 5782 | /* Now we load the register(s). */ |
ca4e0257 | 5783 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5784 | macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)", |
5785 | treg, (int) BFD_RELOC_LO16, AT); | |
5786 | else | |
5787 | { | |
5788 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5789 | treg, (int) BFD_RELOC_LO16, AT); | |
5790 | if (treg != 31) | |
5791 | { | |
5792 | /* FIXME: How in the world do we deal with the possible | |
5793 | overflow here? */ | |
5794 | offset_expr.X_add_number += 4; | |
5795 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5796 | treg + 1, (int) BFD_RELOC_LO16, AT); | |
5797 | } | |
5798 | } | |
5799 | ||
5800 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5801 | does not become a variant frag. */ | |
5802 | frag_wane (frag_now); | |
5803 | frag_new (0); | |
5804 | ||
5805 | break; | |
5806 | ||
5807 | case M_LI_DD: | |
ca4e0257 RS |
5808 | /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits |
5809 | wide, IMM_EXPR is the entire value and the GPRs are known to be 64 | |
5810 | bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of | |
5811 | the value and the low order 32 bits are either zero or in | |
5812 | OFFSET_EXPR. */ | |
252b5132 RH |
5813 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
5814 | { | |
ca4e0257 RS |
5815 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS); |
5816 | if (HAVE_64BIT_FPRS) | |
5817 | { | |
5818 | assert (HAVE_64BIT_GPRS); | |
5819 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5820 | "dmtc1", "t,S", AT, treg); | |
5821 | } | |
252b5132 RH |
5822 | else |
5823 | { | |
5824 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5825 | "mtc1", "t,G", AT, treg + 1); | |
5826 | if (offset_expr.X_op == O_absent) | |
5827 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5828 | "mtc1", "t,G", 0, treg); | |
5829 | else | |
5830 | { | |
5831 | assert (offset_expr.X_op == O_constant); | |
5832 | load_register (&icnt, AT, &offset_expr, 0); | |
5833 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5834 | "mtc1", "t,G", AT, treg); | |
5835 | } | |
5836 | } | |
5837 | break; | |
5838 | } | |
5839 | ||
5840 | assert (offset_expr.X_op == O_symbol | |
5841 | && offset_expr.X_add_number == 0); | |
5842 | s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol)); | |
5843 | if (strcmp (s, ".lit8") == 0) | |
5844 | { | |
e7af610e | 5845 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5846 | { |
5847 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5848 | "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5849 | return; | |
5850 | } | |
5851 | breg = GP; | |
5852 | r = BFD_RELOC_MIPS_LITERAL; | |
5853 | goto dob; | |
5854 | } | |
5855 | else | |
5856 | { | |
5857 | assert (strcmp (s, RDATA_SECTION_NAME) == 0); | |
5858 | if (mips_pic == SVR4_PIC) | |
5859 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5860 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5861 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
5862 | else | |
5863 | { | |
5864 | /* FIXME: This won't work for a 64 bit address. */ | |
5865 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5866 | } | |
bdaaa2e1 | 5867 | |
e7af610e | 5868 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5869 | { |
5870 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5871 | "T,o(b)", treg, (int) BFD_RELOC_LO16, AT); | |
5872 | ||
5873 | /* To avoid confusion in tc_gen_reloc, we must ensure | |
5874 | that this does not become a variant frag. */ | |
5875 | frag_wane (frag_now); | |
5876 | frag_new (0); | |
5877 | ||
5878 | break; | |
5879 | } | |
5880 | breg = AT; | |
5881 | r = BFD_RELOC_LO16; | |
5882 | goto dob; | |
5883 | } | |
5884 | ||
5885 | case M_L_DOB: | |
ec68c924 | 5886 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5887 | { |
5888 | as_bad (_("opcode not supported on this processor")); | |
5889 | return; | |
5890 | } | |
5891 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5892 | to adjust when loading from memory. */ | |
5893 | r = BFD_RELOC_LO16; | |
5894 | dob: | |
e7af610e | 5895 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
5896 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", |
5897 | target_big_endian ? treg + 1 : treg, | |
5898 | (int) r, breg); | |
5899 | /* FIXME: A possible overflow which I don't know how to deal | |
5900 | with. */ | |
5901 | offset_expr.X_add_number += 4; | |
5902 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5903 | target_big_endian ? treg : treg + 1, | |
5904 | (int) r, breg); | |
5905 | ||
5906 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5907 | does not become a variant frag. */ | |
5908 | frag_wane (frag_now); | |
5909 | frag_new (0); | |
5910 | ||
5911 | if (breg != AT) | |
5912 | return; | |
5913 | break; | |
5914 | ||
5915 | case M_L_DAB: | |
5916 | /* | |
5917 | * The MIPS assembler seems to check for X_add_number not | |
5918 | * being double aligned and generating: | |
5919 | * lui at,%hi(foo+1) | |
5920 | * addu at,at,v1 | |
5921 | * addiu at,at,%lo(foo+1) | |
5922 | * lwc1 f2,0(at) | |
5923 | * lwc1 f3,4(at) | |
5924 | * But, the resulting address is the same after relocation so why | |
5925 | * generate the extra instruction? | |
5926 | */ | |
ec68c924 | 5927 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5928 | { |
5929 | as_bad (_("opcode not supported on this processor")); | |
5930 | return; | |
5931 | } | |
bdaaa2e1 | 5932 | /* Itbl support may require additional care here. */ |
252b5132 | 5933 | coproc = 1; |
e7af610e | 5934 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5935 | { |
5936 | s = "ldc1"; | |
5937 | goto ld; | |
5938 | } | |
5939 | ||
5940 | s = "lwc1"; | |
5941 | fmt = "T,o(b)"; | |
5942 | goto ldd_std; | |
5943 | ||
5944 | case M_S_DAB: | |
ec68c924 | 5945 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5946 | { |
5947 | as_bad (_("opcode not supported on this processor")); | |
5948 | return; | |
5949 | } | |
5950 | ||
e7af610e | 5951 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5952 | { |
5953 | s = "sdc1"; | |
5954 | goto st; | |
5955 | } | |
5956 | ||
5957 | s = "swc1"; | |
5958 | fmt = "T,o(b)"; | |
bdaaa2e1 | 5959 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5960 | coproc = 1; |
5961 | goto ldd_std; | |
5962 | ||
5963 | case M_LD_AB: | |
ca4e0257 | 5964 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5965 | { |
5966 | s = "ld"; | |
5967 | goto ld; | |
5968 | } | |
5969 | ||
5970 | s = "lw"; | |
5971 | fmt = "t,o(b)"; | |
5972 | goto ldd_std; | |
5973 | ||
5974 | case M_SD_AB: | |
ca4e0257 | 5975 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5976 | { |
5977 | s = "sd"; | |
5978 | goto st; | |
5979 | } | |
5980 | ||
5981 | s = "sw"; | |
5982 | fmt = "t,o(b)"; | |
5983 | ||
5984 | ldd_std: | |
afdbd6d0 CD |
5985 | /* We do _not_ bother to allow embedded PIC (symbol-local_symbol) |
5986 | loads for the case of doing a pair of loads to simulate an 'ld'. | |
5987 | This is not currently done by the compiler, and assembly coders | |
5988 | writing embedded-pic code can cope. */ | |
5989 | ||
252b5132 RH |
5990 | if (offset_expr.X_op != O_symbol |
5991 | && offset_expr.X_op != O_constant) | |
5992 | { | |
5993 | as_bad (_("expression too complex")); | |
5994 | offset_expr.X_op = O_constant; | |
5995 | } | |
5996 | ||
5997 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5998 | to adjust when loading from memory. We set coproc if we must | |
5999 | load $fn+1 first. */ | |
bdaaa2e1 | 6000 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6001 | if (! target_big_endian) |
6002 | coproc = 0; | |
6003 | ||
6004 | if (mips_pic == NO_PIC | |
6005 | || offset_expr.X_op == O_constant) | |
6006 | { | |
6007 | /* If this is a reference to a GP relative symbol, we want | |
cdf6fd85 TS |
6008 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
6009 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16) | |
252b5132 RH |
6010 | If we have a base register, we use this |
6011 | addu $at,$breg,$gp | |
cdf6fd85 TS |
6012 | <op> $treg,<sym>($at) (BFD_RELOC_GPREL16) |
6013 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16) | |
252b5132 RH |
6014 | If this is not a GP relative symbol, we want |
6015 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
6016 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
6017 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
6018 | If there is a base register, we add it to $at after the | |
6019 | lui instruction. If there is a constant, we always use | |
6020 | the last case. */ | |
e7d556df | 6021 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
6022 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
6023 | { | |
6024 | p = NULL; | |
6025 | used_at = 1; | |
6026 | } | |
6027 | else | |
6028 | { | |
6029 | int off; | |
6030 | ||
6031 | if (breg == 0) | |
6032 | { | |
6033 | frag_grow (28); | |
6034 | tempreg = GP; | |
6035 | off = 0; | |
6036 | used_at = 0; | |
6037 | } | |
6038 | else | |
6039 | { | |
6040 | frag_grow (36); | |
6041 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6042 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6043 | "d,v,t", AT, breg, GP); |
6044 | tempreg = AT; | |
6045 | off = 4; | |
6046 | used_at = 1; | |
6047 | } | |
6048 | ||
beae10d5 | 6049 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6050 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6051 | coproc ? treg + 1 : treg, | |
cdf6fd85 | 6052 | (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
6053 | offset_expr.X_add_number += 4; |
6054 | ||
6055 | /* Set mips_optimize to 2 to avoid inserting an | |
6056 | undesired nop. */ | |
6057 | hold_mips_optimize = mips_optimize; | |
6058 | mips_optimize = 2; | |
beae10d5 | 6059 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6060 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6061 | coproc ? treg : treg + 1, | |
cdf6fd85 | 6062 | (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
6063 | mips_optimize = hold_mips_optimize; |
6064 | ||
6065 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
6066 | RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1, | |
6067 | used_at && mips_opts.noat), | |
6068 | offset_expr.X_add_symbol, (offsetT) 0, | |
6069 | (char *) NULL); | |
6070 | ||
6071 | /* We just generated two relocs. When tc_gen_reloc | |
6072 | handles this case, it will skip the first reloc and | |
6073 | handle the second. The second reloc already has an | |
6074 | extra addend of 4, which we added above. We must | |
6075 | subtract it out, and then subtract another 4 to make | |
6076 | the first reloc come out right. The second reloc | |
6077 | will come out right because we are going to add 4 to | |
6078 | offset_expr when we build its instruction below. | |
6079 | ||
6080 | If we have a symbol, then we don't want to include | |
6081 | the offset, because it will wind up being included | |
6082 | when we generate the reloc. */ | |
6083 | ||
6084 | if (offset_expr.X_op == O_constant) | |
6085 | offset_expr.X_add_number -= 8; | |
6086 | else | |
6087 | { | |
6088 | offset_expr.X_add_number = -4; | |
6089 | offset_expr.X_op = O_constant; | |
6090 | } | |
6091 | } | |
6092 | macro_build_lui (p, &icnt, &offset_expr, AT); | |
6093 | if (p != NULL) | |
6094 | p += 4; | |
6095 | if (breg != 0) | |
6096 | { | |
6097 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6098 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6099 | "d,v,t", AT, breg, AT); |
6100 | if (p != NULL) | |
6101 | p += 4; | |
6102 | } | |
beae10d5 | 6103 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6104 | macro_build (p, &icnt, &offset_expr, s, fmt, |
6105 | coproc ? treg + 1 : treg, | |
6106 | (int) BFD_RELOC_LO16, AT); | |
6107 | if (p != NULL) | |
6108 | p += 4; | |
6109 | /* FIXME: How do we handle overflow here? */ | |
6110 | offset_expr.X_add_number += 4; | |
beae10d5 | 6111 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6112 | macro_build (p, &icnt, &offset_expr, s, fmt, |
6113 | coproc ? treg : treg + 1, | |
6114 | (int) BFD_RELOC_LO16, AT); | |
bdaaa2e1 | 6115 | } |
252b5132 RH |
6116 | else if (mips_pic == SVR4_PIC && ! mips_big_got) |
6117 | { | |
6118 | int off; | |
6119 | ||
6120 | /* If this is a reference to an external symbol, we want | |
6121 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6122 | nop | |
6123 | <op> $treg,0($at) | |
6124 | <op> $treg+1,4($at) | |
6125 | Otherwise we want | |
6126 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6127 | nop | |
6128 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
6129 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
6130 | If there is a base register we add it to $at before the | |
6131 | lwc1 instructions. If there is a constant we include it | |
6132 | in the lwc1 instructions. */ | |
6133 | used_at = 1; | |
6134 | expr1.X_add_number = offset_expr.X_add_number; | |
6135 | offset_expr.X_add_number = 0; | |
6136 | if (expr1.X_add_number < -0x8000 | |
6137 | || expr1.X_add_number >= 0x8000 - 4) | |
6138 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
6139 | if (breg == 0) | |
6140 | off = 0; | |
6141 | else | |
6142 | off = 4; | |
6143 | frag_grow (24 + off); | |
6144 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 6145 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
6146 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
6147 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
6148 | if (breg != 0) | |
6149 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6150 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 6151 | "d,v,t", AT, breg, AT); |
beae10d5 | 6152 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6153 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6154 | coproc ? treg + 1 : treg, | |
6155 | (int) BFD_RELOC_LO16, AT); | |
6156 | expr1.X_add_number += 4; | |
6157 | ||
6158 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6159 | nop. */ | |
6160 | hold_mips_optimize = mips_optimize; | |
6161 | mips_optimize = 2; | |
beae10d5 | 6162 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6163 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6164 | coproc ? treg : treg + 1, | |
6165 | (int) BFD_RELOC_LO16, AT); | |
6166 | mips_optimize = hold_mips_optimize; | |
6167 | ||
6168 | (void) frag_var (rs_machine_dependent, 0, 0, | |
6169 | RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0), | |
c4e7957c | 6170 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
6171 | } |
6172 | else if (mips_pic == SVR4_PIC) | |
6173 | { | |
6174 | int gpdel, off; | |
6175 | ||
6176 | /* If this is a reference to an external symbol, we want | |
6177 | lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
6178 | addu $at,$at,$gp | |
6179 | lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16) | |
6180 | nop | |
6181 | <op> $treg,0($at) | |
6182 | <op> $treg+1,4($at) | |
6183 | Otherwise we want | |
6184 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6185 | nop | |
6186 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
6187 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
6188 | If there is a base register we add it to $at before the | |
6189 | lwc1 instructions. If there is a constant we include it | |
6190 | in the lwc1 instructions. */ | |
6191 | used_at = 1; | |
6192 | expr1.X_add_number = offset_expr.X_add_number; | |
6193 | offset_expr.X_add_number = 0; | |
6194 | if (expr1.X_add_number < -0x8000 | |
6195 | || expr1.X_add_number >= 0x8000 - 4) | |
6196 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
6197 | if (reg_needs_delay (GP)) | |
6198 | gpdel = 4; | |
6199 | else | |
6200 | gpdel = 0; | |
6201 | if (breg == 0) | |
6202 | off = 0; | |
6203 | else | |
6204 | off = 4; | |
6205 | frag_grow (56); | |
6206 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
6207 | AT, (int) BFD_RELOC_MIPS_GOT_HI16); | |
6208 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6209 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6210 | "d,v,t", AT, AT, GP); |
6211 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 6212 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
6213 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT); |
6214 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
6215 | if (breg != 0) | |
6216 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6217 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 6218 | "d,v,t", AT, breg, AT); |
beae10d5 | 6219 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6220 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6221 | coproc ? treg + 1 : treg, | |
6222 | (int) BFD_RELOC_LO16, AT); | |
6223 | expr1.X_add_number += 4; | |
6224 | ||
6225 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6226 | nop. */ | |
6227 | hold_mips_optimize = mips_optimize; | |
6228 | mips_optimize = 2; | |
beae10d5 | 6229 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6230 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6231 | coproc ? treg : treg + 1, | |
6232 | (int) BFD_RELOC_LO16, AT); | |
6233 | mips_optimize = hold_mips_optimize; | |
6234 | expr1.X_add_number -= 4; | |
6235 | ||
6236 | p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0, | |
6237 | RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel, | |
6238 | 8 + gpdel + off, 1, 0), | |
c4e7957c | 6239 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
6240 | if (gpdel > 0) |
6241 | { | |
6242 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
6243 | p += 4; | |
6244 | } | |
6245 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 6246 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
6247 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
6248 | p += 4; | |
6249 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
6250 | p += 4; | |
6251 | if (breg != 0) | |
6252 | { | |
6253 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6254 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6255 | "d,v,t", AT, breg, AT); |
6256 | p += 4; | |
6257 | } | |
beae10d5 | 6258 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6259 | macro_build (p, &icnt, &expr1, s, fmt, |
6260 | coproc ? treg + 1 : treg, | |
6261 | (int) BFD_RELOC_LO16, AT); | |
6262 | p += 4; | |
6263 | expr1.X_add_number += 4; | |
6264 | ||
6265 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6266 | nop. */ | |
6267 | hold_mips_optimize = mips_optimize; | |
6268 | mips_optimize = 2; | |
beae10d5 | 6269 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6270 | macro_build (p, &icnt, &expr1, s, fmt, |
6271 | coproc ? treg : treg + 1, | |
6272 | (int) BFD_RELOC_LO16, AT); | |
6273 | mips_optimize = hold_mips_optimize; | |
6274 | } | |
6275 | else if (mips_pic == EMBEDDED_PIC) | |
6276 | { | |
6277 | /* If there is no base register, we use | |
cdf6fd85 TS |
6278 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
6279 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16) | |
252b5132 RH |
6280 | If we have a base register, we use |
6281 | addu $at,$breg,$gp | |
cdf6fd85 TS |
6282 | <op> $treg,<sym>($at) (BFD_RELOC_GPREL16) |
6283 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16) | |
252b5132 RH |
6284 | */ |
6285 | if (breg == 0) | |
6286 | { | |
6287 | tempreg = GP; | |
6288 | used_at = 0; | |
6289 | } | |
6290 | else | |
6291 | { | |
6292 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6293 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6294 | "d,v,t", AT, breg, GP); |
6295 | tempreg = AT; | |
6296 | used_at = 1; | |
6297 | } | |
6298 | ||
beae10d5 | 6299 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6300 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6301 | coproc ? treg + 1 : treg, | |
cdf6fd85 | 6302 | (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 | 6303 | offset_expr.X_add_number += 4; |
beae10d5 | 6304 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6305 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6306 | coproc ? treg : treg + 1, | |
cdf6fd85 | 6307 | (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
6308 | } |
6309 | else | |
6310 | abort (); | |
6311 | ||
6312 | if (! used_at) | |
6313 | return; | |
6314 | ||
6315 | break; | |
6316 | ||
6317 | case M_LD_OB: | |
6318 | s = "lw"; | |
6319 | goto sd_ob; | |
6320 | case M_SD_OB: | |
6321 | s = "sw"; | |
6322 | sd_ob: | |
ca4e0257 | 6323 | assert (HAVE_32BIT_ADDRESSES); |
252b5132 RH |
6324 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, |
6325 | (int) BFD_RELOC_LO16, breg); | |
6326 | offset_expr.X_add_number += 4; | |
6327 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1, | |
6328 | (int) BFD_RELOC_LO16, breg); | |
6329 | return; | |
6330 | ||
6331 | /* New code added to support COPZ instructions. | |
6332 | This code builds table entries out of the macros in mip_opcodes. | |
6333 | R4000 uses interlocks to handle coproc delays. | |
6334 | Other chips (like the R3000) require nops to be inserted for delays. | |
6335 | ||
f72c8c98 | 6336 | FIXME: Currently, we require that the user handle delays. |
252b5132 RH |
6337 | In order to fill delay slots for non-interlocked chips, |
6338 | we must have a way to specify delays based on the coprocessor. | |
6339 | Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc. | |
6340 | What are the side-effects of the cop instruction? | |
6341 | What cache support might we have and what are its effects? | |
6342 | Both coprocessor & memory require delays. how long??? | |
bdaaa2e1 | 6343 | What registers are read/set/modified? |
252b5132 RH |
6344 | |
6345 | If an itbl is provided to interpret cop instructions, | |
bdaaa2e1 | 6346 | this knowledge can be encoded in the itbl spec. */ |
252b5132 RH |
6347 | |
6348 | case M_COP0: | |
6349 | s = "c0"; | |
6350 | goto copz; | |
6351 | case M_COP1: | |
6352 | s = "c1"; | |
6353 | goto copz; | |
6354 | case M_COP2: | |
6355 | s = "c2"; | |
6356 | goto copz; | |
6357 | case M_COP3: | |
6358 | s = "c3"; | |
6359 | copz: | |
6360 | /* For now we just do C (same as Cz). The parameter will be | |
6361 | stored in insn_opcode by mips_ip. */ | |
6362 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C", | |
6363 | ip->insn_opcode); | |
6364 | return; | |
6365 | ||
ea1fb5dc RS |
6366 | case M_MOVE: |
6367 | move_register (&icnt, dreg, sreg); | |
6368 | return; | |
6369 | ||
252b5132 RH |
6370 | #ifdef LOSING_COMPILER |
6371 | default: | |
6372 | /* Try and see if this is a new itbl instruction. | |
6373 | This code builds table entries out of the macros in mip_opcodes. | |
6374 | FIXME: For now we just assemble the expression and pass it's | |
6375 | value along as a 32-bit immediate. | |
bdaaa2e1 | 6376 | We may want to have the assembler assemble this value, |
252b5132 RH |
6377 | so that we gain the assembler's knowledge of delay slots, |
6378 | symbols, etc. | |
6379 | Would it be more efficient to use mask (id) here? */ | |
bdaaa2e1 | 6380 | if (itbl_have_entries |
252b5132 | 6381 | && (immed_expr = itbl_assemble (ip->insn_mo->name, ""))) |
beae10d5 | 6382 | { |
252b5132 RH |
6383 | s = ip->insn_mo->name; |
6384 | s2 = "cop3"; | |
6385 | coproc = ITBL_DECODE_PNUM (immed_expr);; | |
6386 | macro_build ((char *) NULL, &icnt, &immed_expr, s, "C"); | |
6387 | return; | |
beae10d5 | 6388 | } |
252b5132 RH |
6389 | macro2 (ip); |
6390 | return; | |
6391 | } | |
6392 | if (mips_opts.noat) | |
6393 | as_warn (_("Macro used $at after \".set noat\"")); | |
6394 | } | |
bdaaa2e1 | 6395 | |
252b5132 RH |
6396 | static void |
6397 | macro2 (ip) | |
6398 | struct mips_cl_insn *ip; | |
6399 | { | |
6400 | register int treg, sreg, dreg, breg; | |
6401 | int tempreg; | |
6402 | int mask; | |
6403 | int icnt = 0; | |
6404 | int used_at; | |
6405 | expressionS expr1; | |
6406 | const char *s; | |
6407 | const char *s2; | |
6408 | const char *fmt; | |
6409 | int likely = 0; | |
6410 | int dbl = 0; | |
6411 | int coproc = 0; | |
6412 | int lr = 0; | |
6413 | int imm = 0; | |
6414 | int off; | |
6415 | offsetT maxnum; | |
6416 | bfd_reloc_code_real_type r; | |
6417 | char *p; | |
bdaaa2e1 | 6418 | |
252b5132 RH |
6419 | treg = (ip->insn_opcode >> 16) & 0x1f; |
6420 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
6421 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
6422 | mask = ip->insn_mo->mask; | |
bdaaa2e1 | 6423 | |
252b5132 RH |
6424 | expr1.X_op = O_constant; |
6425 | expr1.X_op_symbol = NULL; | |
6426 | expr1.X_add_symbol = NULL; | |
6427 | expr1.X_add_number = 1; | |
bdaaa2e1 | 6428 | |
252b5132 RH |
6429 | switch (mask) |
6430 | { | |
6431 | #endif /* LOSING_COMPILER */ | |
6432 | ||
6433 | case M_DMUL: | |
6434 | dbl = 1; | |
6435 | case M_MUL: | |
2396cfb9 TS |
6436 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
6437 | dbl ? "dmultu" : "multu", "s,t", sreg, treg); | |
6438 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", | |
6439 | dreg); | |
252b5132 RH |
6440 | return; |
6441 | ||
6442 | case M_DMUL_I: | |
6443 | dbl = 1; | |
6444 | case M_MUL_I: | |
6445 | /* The MIPS assembler some times generates shifts and adds. I'm | |
6446 | not trying to be that fancy. GCC should do this for us | |
6447 | anyway. */ | |
6448 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 6449 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 6450 | dbl ? "dmult" : "mult", "s,t", sreg, AT); |
2396cfb9 TS |
6451 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", |
6452 | dreg); | |
252b5132 RH |
6453 | break; |
6454 | ||
6455 | case M_DMULO_I: | |
6456 | dbl = 1; | |
6457 | case M_MULO_I: | |
6458 | imm = 1; | |
6459 | goto do_mulo; | |
6460 | ||
6461 | case M_DMULO: | |
6462 | dbl = 1; | |
6463 | case M_MULO: | |
6464 | do_mulo: | |
6465 | mips_emit_delays (true); | |
6466 | ++mips_opts.noreorder; | |
6467 | mips_any_noreorder = 1; | |
6468 | if (imm) | |
6469 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 6470 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 6471 | dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg); |
2396cfb9 TS |
6472 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", |
6473 | dreg); | |
6474 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
9a41af64 | 6475 | dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, 31); |
2396cfb9 TS |
6476 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d", |
6477 | AT); | |
252b5132 | 6478 | if (mips_trap) |
2396cfb9 TS |
6479 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t", |
6480 | dreg, AT); | |
252b5132 RH |
6481 | else |
6482 | { | |
6483 | expr1.X_add_number = 8; | |
2396cfb9 TS |
6484 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, |
6485 | AT); | |
6486 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "", | |
6487 | 0); | |
6488 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", | |
6489 | "c", 6); | |
252b5132 RH |
6490 | } |
6491 | --mips_opts.noreorder; | |
2396cfb9 | 6492 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg); |
252b5132 RH |
6493 | break; |
6494 | ||
6495 | case M_DMULOU_I: | |
6496 | dbl = 1; | |
6497 | case M_MULOU_I: | |
6498 | imm = 1; | |
6499 | goto do_mulou; | |
6500 | ||
6501 | case M_DMULOU: | |
6502 | dbl = 1; | |
6503 | case M_MULOU: | |
6504 | do_mulou: | |
6505 | mips_emit_delays (true); | |
6506 | ++mips_opts.noreorder; | |
6507 | mips_any_noreorder = 1; | |
6508 | if (imm) | |
6509 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 6510 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
252b5132 RH |
6511 | dbl ? "dmultu" : "multu", |
6512 | "s,t", sreg, imm ? AT : treg); | |
2396cfb9 TS |
6513 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d", |
6514 | AT); | |
6515 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", | |
6516 | dreg); | |
252b5132 | 6517 | if (mips_trap) |
2396cfb9 TS |
6518 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t", |
6519 | AT, 0); | |
252b5132 RH |
6520 | else |
6521 | { | |
6522 | expr1.X_add_number = 8; | |
6523 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0); | |
2396cfb9 TS |
6524 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "", |
6525 | 0); | |
6526 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", | |
6527 | "c", 6); | |
252b5132 RH |
6528 | } |
6529 | --mips_opts.noreorder; | |
6530 | break; | |
6531 | ||
6532 | case M_ROL: | |
2396cfb9 TS |
6533 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu", |
6534 | "d,v,t", AT, 0, treg); | |
6535 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv", | |
6536 | "d,t,s", AT, sreg, AT); | |
6537 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv", | |
6538 | "d,t,s", dreg, sreg, treg); | |
6539 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
6540 | "d,v,t", dreg, dreg, AT); | |
252b5132 RH |
6541 | break; |
6542 | ||
6543 | case M_ROL_I: | |
6544 | if (imm_expr.X_op != O_constant) | |
6545 | as_bad (_("rotate count too large")); | |
2396cfb9 TS |
6546 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<", |
6547 | AT, sreg, (int) (imm_expr.X_add_number & 0x1f)); | |
6548 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<", | |
6549 | dreg, sreg, (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6550 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t", | |
6551 | dreg, dreg, AT); | |
252b5132 RH |
6552 | break; |
6553 | ||
6554 | case M_ROR: | |
2396cfb9 TS |
6555 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu", |
6556 | "d,v,t", AT, 0, treg); | |
6557 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv", | |
6558 | "d,t,s", AT, sreg, AT); | |
6559 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv", | |
6560 | "d,t,s", dreg, sreg, treg); | |
6561 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
6562 | "d,v,t", dreg, dreg, AT); | |
252b5132 RH |
6563 | break; |
6564 | ||
6565 | case M_ROR_I: | |
6566 | if (imm_expr.X_op != O_constant) | |
6567 | as_bad (_("rotate count too large")); | |
2396cfb9 TS |
6568 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<", |
6569 | AT, sreg, (int) (imm_expr.X_add_number & 0x1f)); | |
6570 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<", | |
6571 | dreg, sreg, (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6572 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t", | |
6573 | dreg, dreg, AT); | |
252b5132 RH |
6574 | break; |
6575 | ||
6576 | case M_S_DOB: | |
ec68c924 | 6577 | if (mips_arch == CPU_R4650) |
252b5132 RH |
6578 | { |
6579 | as_bad (_("opcode not supported on this processor")); | |
6580 | return; | |
6581 | } | |
e7af610e | 6582 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
6583 | /* Even on a big endian machine $fn comes before $fn+1. We have |
6584 | to adjust when storing to memory. */ | |
6585 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6586 | target_big_endian ? treg + 1 : treg, | |
6587 | (int) BFD_RELOC_LO16, breg); | |
6588 | offset_expr.X_add_number += 4; | |
6589 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6590 | target_big_endian ? treg : treg + 1, | |
6591 | (int) BFD_RELOC_LO16, breg); | |
6592 | return; | |
6593 | ||
6594 | case M_SEQ: | |
6595 | if (sreg == 0) | |
6596 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6597 | treg, (int) BFD_RELOC_LO16); | |
6598 | else if (treg == 0) | |
6599 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6600 | sreg, (int) BFD_RELOC_LO16); | |
6601 | else | |
6602 | { | |
2396cfb9 TS |
6603 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor", |
6604 | "d,v,t", dreg, sreg, treg); | |
252b5132 RH |
6605 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, |
6606 | dreg, (int) BFD_RELOC_LO16); | |
6607 | } | |
6608 | return; | |
6609 | ||
6610 | case M_SEQ_I: | |
6611 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6612 | { | |
6613 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6614 | sreg, (int) BFD_RELOC_LO16); | |
6615 | return; | |
6616 | } | |
6617 | if (sreg == 0) | |
6618 | { | |
6619 | as_warn (_("Instruction %s: result is always false"), | |
6620 | ip->insn_mo->name); | |
ea1fb5dc | 6621 | move_register (&icnt, dreg, 0); |
252b5132 RH |
6622 | return; |
6623 | } | |
6624 | if (imm_expr.X_op == O_constant | |
6625 | && imm_expr.X_add_number >= 0 | |
6626 | && imm_expr.X_add_number < 0x10000) | |
6627 | { | |
6628 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, | |
6629 | sreg, (int) BFD_RELOC_LO16); | |
6630 | used_at = 0; | |
6631 | } | |
6632 | else if (imm_expr.X_op == O_constant | |
6633 | && imm_expr.X_add_number > -0x8000 | |
6634 | && imm_expr.X_add_number < 0) | |
6635 | { | |
6636 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6637 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
ca4e0257 | 6638 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6639 | "t,r,j", dreg, sreg, |
6640 | (int) BFD_RELOC_LO16); | |
6641 | used_at = 0; | |
6642 | } | |
6643 | else | |
6644 | { | |
6645 | load_register (&icnt, AT, &imm_expr, 0); | |
2396cfb9 TS |
6646 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor", |
6647 | "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
6648 | used_at = 1; |
6649 | } | |
6650 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg, | |
6651 | (int) BFD_RELOC_LO16); | |
6652 | if (used_at) | |
6653 | break; | |
6654 | return; | |
6655 | ||
6656 | case M_SGE: /* sreg >= treg <==> not (sreg < treg) */ | |
6657 | s = "slt"; | |
6658 | goto sge; | |
6659 | case M_SGEU: | |
6660 | s = "sltu"; | |
6661 | sge: | |
2396cfb9 TS |
6662 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
6663 | dreg, sreg, treg); | |
252b5132 RH |
6664 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, |
6665 | (int) BFD_RELOC_LO16); | |
6666 | return; | |
6667 | ||
6668 | case M_SGE_I: /* sreg >= I <==> not (sreg < I) */ | |
6669 | case M_SGEU_I: | |
6670 | if (imm_expr.X_op == O_constant | |
6671 | && imm_expr.X_add_number >= -0x8000 | |
6672 | && imm_expr.X_add_number < 0x8000) | |
6673 | { | |
6674 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6675 | mask == M_SGE_I ? "slti" : "sltiu", | |
6676 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6677 | used_at = 0; | |
6678 | } | |
6679 | else | |
6680 | { | |
6681 | load_register (&icnt, AT, &imm_expr, 0); | |
2396cfb9 TS |
6682 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
6683 | mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg, | |
6684 | AT); | |
252b5132 RH |
6685 | used_at = 1; |
6686 | } | |
6687 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6688 | (int) BFD_RELOC_LO16); | |
6689 | if (used_at) | |
6690 | break; | |
6691 | return; | |
6692 | ||
6693 | case M_SGT: /* sreg > treg <==> treg < sreg */ | |
6694 | s = "slt"; | |
6695 | goto sgt; | |
6696 | case M_SGTU: | |
6697 | s = "sltu"; | |
6698 | sgt: | |
2396cfb9 TS |
6699 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
6700 | dreg, treg, sreg); | |
252b5132 RH |
6701 | return; |
6702 | ||
6703 | case M_SGT_I: /* sreg > I <==> I < sreg */ | |
6704 | s = "slt"; | |
6705 | goto sgti; | |
6706 | case M_SGTU_I: | |
6707 | s = "sltu"; | |
6708 | sgti: | |
6709 | load_register (&icnt, AT, &imm_expr, 0); | |
2396cfb9 TS |
6710 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
6711 | dreg, AT, sreg); | |
252b5132 RH |
6712 | break; |
6713 | ||
2396cfb9 | 6714 | case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */ |
252b5132 RH |
6715 | s = "slt"; |
6716 | goto sle; | |
6717 | case M_SLEU: | |
6718 | s = "sltu"; | |
6719 | sle: | |
2396cfb9 TS |
6720 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
6721 | dreg, treg, sreg); | |
252b5132 RH |
6722 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, |
6723 | (int) BFD_RELOC_LO16); | |
6724 | return; | |
6725 | ||
2396cfb9 | 6726 | case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */ |
252b5132 RH |
6727 | s = "slt"; |
6728 | goto slei; | |
6729 | case M_SLEU_I: | |
6730 | s = "sltu"; | |
6731 | slei: | |
6732 | load_register (&icnt, AT, &imm_expr, 0); | |
2396cfb9 TS |
6733 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
6734 | dreg, AT, sreg); | |
252b5132 RH |
6735 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, |
6736 | (int) BFD_RELOC_LO16); | |
6737 | break; | |
6738 | ||
6739 | case M_SLT_I: | |
6740 | if (imm_expr.X_op == O_constant | |
6741 | && imm_expr.X_add_number >= -0x8000 | |
6742 | && imm_expr.X_add_number < 0x8000) | |
6743 | { | |
6744 | macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j", | |
6745 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6746 | return; | |
6747 | } | |
6748 | load_register (&icnt, AT, &imm_expr, 0); | |
2396cfb9 TS |
6749 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
6750 | dreg, sreg, AT); | |
252b5132 RH |
6751 | break; |
6752 | ||
6753 | case M_SLTU_I: | |
6754 | if (imm_expr.X_op == O_constant | |
6755 | && imm_expr.X_add_number >= -0x8000 | |
6756 | && imm_expr.X_add_number < 0x8000) | |
6757 | { | |
6758 | macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j", | |
6759 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6760 | return; | |
6761 | } | |
6762 | load_register (&icnt, AT, &imm_expr, 0); | |
2396cfb9 TS |
6763 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
6764 | "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
6765 | break; |
6766 | ||
6767 | case M_SNE: | |
6768 | if (sreg == 0) | |
2396cfb9 TS |
6769 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
6770 | "d,v,t", dreg, 0, treg); | |
252b5132 | 6771 | else if (treg == 0) |
2396cfb9 TS |
6772 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
6773 | "d,v,t", dreg, 0, sreg); | |
252b5132 RH |
6774 | else |
6775 | { | |
2396cfb9 TS |
6776 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor", |
6777 | "d,v,t", dreg, sreg, treg); | |
6778 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", | |
6779 | "d,v,t", dreg, 0, dreg); | |
252b5132 RH |
6780 | } |
6781 | return; | |
6782 | ||
6783 | case M_SNE_I: | |
6784 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6785 | { | |
2396cfb9 TS |
6786 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
6787 | "d,v,t", dreg, 0, sreg); | |
252b5132 RH |
6788 | return; |
6789 | } | |
6790 | if (sreg == 0) | |
6791 | { | |
6792 | as_warn (_("Instruction %s: result is always true"), | |
6793 | ip->insn_mo->name); | |
6794 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 6795 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6796 | "t,r,j", dreg, 0, (int) BFD_RELOC_LO16); |
6797 | return; | |
6798 | } | |
6799 | if (imm_expr.X_op == O_constant | |
6800 | && imm_expr.X_add_number >= 0 | |
6801 | && imm_expr.X_add_number < 0x10000) | |
6802 | { | |
6803 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", | |
6804 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6805 | used_at = 0; | |
6806 | } | |
6807 | else if (imm_expr.X_op == O_constant | |
6808 | && imm_expr.X_add_number > -0x8000 | |
6809 | && imm_expr.X_add_number < 0) | |
6810 | { | |
6811 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6812 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
ca4e0257 | 6813 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6814 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); |
6815 | used_at = 0; | |
6816 | } | |
6817 | else | |
6818 | { | |
6819 | load_register (&icnt, AT, &imm_expr, 0); | |
2396cfb9 TS |
6820 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor", |
6821 | "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
6822 | used_at = 1; |
6823 | } | |
2396cfb9 TS |
6824 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
6825 | "d,v,t", dreg, 0, dreg); | |
252b5132 RH |
6826 | if (used_at) |
6827 | break; | |
6828 | return; | |
6829 | ||
6830 | case M_DSUB_I: | |
6831 | dbl = 1; | |
6832 | case M_SUB_I: | |
6833 | if (imm_expr.X_op == O_constant | |
6834 | && imm_expr.X_add_number > -0x8000 | |
6835 | && imm_expr.X_add_number <= 0x8000) | |
6836 | { | |
6837 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6838 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6839 | dbl ? "daddi" : "addi", | |
6840 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6841 | return; | |
6842 | } | |
6843 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 6844 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 6845 | dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT); |
252b5132 RH |
6846 | break; |
6847 | ||
6848 | case M_DSUBU_I: | |
6849 | dbl = 1; | |
6850 | case M_SUBU_I: | |
6851 | if (imm_expr.X_op == O_constant | |
6852 | && imm_expr.X_add_number > -0x8000 | |
6853 | && imm_expr.X_add_number <= 0x8000) | |
6854 | { | |
6855 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6856 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6857 | dbl ? "daddiu" : "addiu", | |
6858 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6859 | return; | |
6860 | } | |
6861 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 6862 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 6863 | dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT); |
252b5132 RH |
6864 | break; |
6865 | ||
6866 | case M_TEQ_I: | |
6867 | s = "teq"; | |
6868 | goto trap; | |
6869 | case M_TGE_I: | |
6870 | s = "tge"; | |
6871 | goto trap; | |
6872 | case M_TGEU_I: | |
6873 | s = "tgeu"; | |
6874 | goto trap; | |
6875 | case M_TLT_I: | |
6876 | s = "tlt"; | |
6877 | goto trap; | |
6878 | case M_TLTU_I: | |
6879 | s = "tltu"; | |
6880 | goto trap; | |
6881 | case M_TNE_I: | |
6882 | s = "tne"; | |
6883 | trap: | |
6884 | load_register (&icnt, AT, &imm_expr, 0); | |
2396cfb9 TS |
6885 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg, |
6886 | AT); | |
252b5132 RH |
6887 | break; |
6888 | ||
252b5132 | 6889 | case M_TRUNCWS: |
43841e91 | 6890 | case M_TRUNCWD: |
e7af610e | 6891 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
6892 | sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */ |
6893 | dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */ | |
6894 | ||
6895 | /* | |
6896 | * Is the double cfc1 instruction a bug in the mips assembler; | |
6897 | * or is there a reason for it? | |
6898 | */ | |
6899 | mips_emit_delays (true); | |
6900 | ++mips_opts.noreorder; | |
6901 | mips_any_noreorder = 1; | |
2396cfb9 TS |
6902 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G", |
6903 | treg, 31); | |
6904 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G", | |
6905 | treg, 31); | |
6906 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
252b5132 RH |
6907 | expr1.X_add_number = 3; |
6908 | macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg, | |
6909 | (int) BFD_RELOC_LO16); | |
6910 | expr1.X_add_number = 2; | |
6911 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT, | |
6912 | (int) BFD_RELOC_LO16); | |
2396cfb9 TS |
6913 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G", |
6914 | AT, 31); | |
6915 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
6916 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
252b5132 | 6917 | mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg); |
2396cfb9 TS |
6918 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G", |
6919 | treg, 31); | |
6920 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
252b5132 RH |
6921 | --mips_opts.noreorder; |
6922 | break; | |
6923 | ||
6924 | case M_ULH: | |
6925 | s = "lb"; | |
6926 | goto ulh; | |
6927 | case M_ULHU: | |
6928 | s = "lbu"; | |
6929 | ulh: | |
6930 | if (offset_expr.X_add_number >= 0x7fff) | |
6931 | as_bad (_("operand overflow")); | |
6932 | /* avoid load delay */ | |
6933 | if (! target_big_endian) | |
6934 | offset_expr.X_add_number += 1; | |
6935 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6936 | (int) BFD_RELOC_LO16, breg); | |
6937 | if (! target_big_endian) | |
6938 | offset_expr.X_add_number -= 1; | |
6939 | else | |
6940 | offset_expr.X_add_number += 1; | |
6941 | macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT, | |
6942 | (int) BFD_RELOC_LO16, breg); | |
2396cfb9 TS |
6943 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<", |
6944 | treg, treg, 8); | |
6945 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t", | |
6946 | treg, treg, AT); | |
252b5132 RH |
6947 | break; |
6948 | ||
6949 | case M_ULD: | |
6950 | s = "ldl"; | |
6951 | s2 = "ldr"; | |
6952 | off = 7; | |
6953 | goto ulw; | |
6954 | case M_ULW: | |
6955 | s = "lwl"; | |
6956 | s2 = "lwr"; | |
6957 | off = 3; | |
6958 | ulw: | |
6959 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6960 | as_bad (_("operand overflow")); | |
6961 | if (! target_big_endian) | |
6962 | offset_expr.X_add_number += off; | |
6963 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6964 | (int) BFD_RELOC_LO16, breg); | |
6965 | if (! target_big_endian) | |
6966 | offset_expr.X_add_number -= off; | |
6967 | else | |
6968 | offset_expr.X_add_number += off; | |
6969 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
6970 | (int) BFD_RELOC_LO16, breg); | |
6971 | return; | |
6972 | ||
6973 | case M_ULD_A: | |
6974 | s = "ldl"; | |
6975 | s2 = "ldr"; | |
6976 | off = 7; | |
6977 | goto ulwa; | |
6978 | case M_ULW_A: | |
6979 | s = "lwl"; | |
6980 | s2 = "lwr"; | |
6981 | off = 3; | |
6982 | ulwa: | |
d6bc6245 TS |
6983 | used_at = 1; |
6984 | load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at); | |
252b5132 RH |
6985 | if (breg != 0) |
6986 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6987 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6988 | "d,v,t", AT, AT, breg); |
6989 | if (! target_big_endian) | |
6990 | expr1.X_add_number = off; | |
6991 | else | |
6992 | expr1.X_add_number = 0; | |
6993 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
6994 | (int) BFD_RELOC_LO16, AT); | |
6995 | if (! target_big_endian) | |
6996 | expr1.X_add_number = 0; | |
6997 | else | |
6998 | expr1.X_add_number = off; | |
6999 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
7000 | (int) BFD_RELOC_LO16, AT); | |
7001 | break; | |
7002 | ||
7003 | case M_ULH_A: | |
7004 | case M_ULHU_A: | |
d6bc6245 TS |
7005 | used_at = 1; |
7006 | load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at); | |
252b5132 RH |
7007 | if (breg != 0) |
7008 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7009 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7010 | "d,v,t", AT, AT, breg); |
7011 | if (target_big_endian) | |
7012 | expr1.X_add_number = 0; | |
7013 | macro_build ((char *) NULL, &icnt, &expr1, | |
7014 | mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg, | |
7015 | (int) BFD_RELOC_LO16, AT); | |
7016 | if (target_big_endian) | |
7017 | expr1.X_add_number = 1; | |
7018 | else | |
7019 | expr1.X_add_number = 0; | |
7020 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
7021 | (int) BFD_RELOC_LO16, AT); | |
2396cfb9 TS |
7022 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<", |
7023 | treg, treg, 8); | |
7024 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t", | |
7025 | treg, treg, AT); | |
252b5132 RH |
7026 | break; |
7027 | ||
7028 | case M_USH: | |
7029 | if (offset_expr.X_add_number >= 0x7fff) | |
7030 | as_bad (_("operand overflow")); | |
7031 | if (target_big_endian) | |
7032 | offset_expr.X_add_number += 1; | |
7033 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg, | |
7034 | (int) BFD_RELOC_LO16, breg); | |
2396cfb9 TS |
7035 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<", |
7036 | AT, treg, 8); | |
252b5132 RH |
7037 | if (target_big_endian) |
7038 | offset_expr.X_add_number -= 1; | |
7039 | else | |
7040 | offset_expr.X_add_number += 1; | |
7041 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT, | |
7042 | (int) BFD_RELOC_LO16, breg); | |
7043 | break; | |
7044 | ||
7045 | case M_USD: | |
7046 | s = "sdl"; | |
7047 | s2 = "sdr"; | |
7048 | off = 7; | |
7049 | goto usw; | |
7050 | case M_USW: | |
7051 | s = "swl"; | |
7052 | s2 = "swr"; | |
7053 | off = 3; | |
7054 | usw: | |
7055 | if (offset_expr.X_add_number >= 0x8000 - off) | |
7056 | as_bad (_("operand overflow")); | |
7057 | if (! target_big_endian) | |
7058 | offset_expr.X_add_number += off; | |
7059 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
7060 | (int) BFD_RELOC_LO16, breg); | |
7061 | if (! target_big_endian) | |
7062 | offset_expr.X_add_number -= off; | |
7063 | else | |
7064 | offset_expr.X_add_number += off; | |
7065 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
7066 | (int) BFD_RELOC_LO16, breg); | |
7067 | return; | |
7068 | ||
7069 | case M_USD_A: | |
7070 | s = "sdl"; | |
7071 | s2 = "sdr"; | |
7072 | off = 7; | |
7073 | goto uswa; | |
7074 | case M_USW_A: | |
7075 | s = "swl"; | |
7076 | s2 = "swr"; | |
7077 | off = 3; | |
7078 | uswa: | |
d6bc6245 TS |
7079 | used_at = 1; |
7080 | load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at); | |
252b5132 RH |
7081 | if (breg != 0) |
7082 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7083 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7084 | "d,v,t", AT, AT, breg); |
7085 | if (! target_big_endian) | |
7086 | expr1.X_add_number = off; | |
7087 | else | |
7088 | expr1.X_add_number = 0; | |
7089 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
7090 | (int) BFD_RELOC_LO16, AT); | |
7091 | if (! target_big_endian) | |
7092 | expr1.X_add_number = 0; | |
7093 | else | |
7094 | expr1.X_add_number = off; | |
7095 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
7096 | (int) BFD_RELOC_LO16, AT); | |
7097 | break; | |
7098 | ||
7099 | case M_USH_A: | |
d6bc6245 TS |
7100 | used_at = 1; |
7101 | load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at); | |
252b5132 RH |
7102 | if (breg != 0) |
7103 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7104 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7105 | "d,v,t", AT, AT, breg); |
7106 | if (! target_big_endian) | |
7107 | expr1.X_add_number = 0; | |
7108 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
7109 | (int) BFD_RELOC_LO16, AT); | |
2396cfb9 TS |
7110 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<", |
7111 | treg, treg, 8); | |
252b5132 RH |
7112 | if (! target_big_endian) |
7113 | expr1.X_add_number = 1; | |
7114 | else | |
7115 | expr1.X_add_number = 0; | |
7116 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
7117 | (int) BFD_RELOC_LO16, AT); | |
7118 | if (! target_big_endian) | |
7119 | expr1.X_add_number = 0; | |
7120 | else | |
7121 | expr1.X_add_number = 1; | |
7122 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
7123 | (int) BFD_RELOC_LO16, AT); | |
2396cfb9 TS |
7124 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<", |
7125 | treg, treg, 8); | |
7126 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t", | |
7127 | treg, treg, AT); | |
252b5132 RH |
7128 | break; |
7129 | ||
7130 | default: | |
7131 | /* FIXME: Check if this is one of the itbl macros, since they | |
bdaaa2e1 | 7132 | are added dynamically. */ |
252b5132 RH |
7133 | as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name); |
7134 | break; | |
7135 | } | |
7136 | if (mips_opts.noat) | |
7137 | as_warn (_("Macro used $at after \".set noat\"")); | |
7138 | } | |
7139 | ||
7140 | /* Implement macros in mips16 mode. */ | |
7141 | ||
7142 | static void | |
7143 | mips16_macro (ip) | |
7144 | struct mips_cl_insn *ip; | |
7145 | { | |
7146 | int mask; | |
7147 | int xreg, yreg, zreg, tmp; | |
7148 | int icnt; | |
7149 | expressionS expr1; | |
7150 | int dbl; | |
7151 | const char *s, *s2, *s3; | |
7152 | ||
7153 | mask = ip->insn_mo->mask; | |
7154 | ||
7155 | xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX; | |
7156 | yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY; | |
7157 | zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ; | |
7158 | ||
7159 | icnt = 0; | |
7160 | ||
7161 | expr1.X_op = O_constant; | |
7162 | expr1.X_op_symbol = NULL; | |
7163 | expr1.X_add_symbol = NULL; | |
7164 | expr1.X_add_number = 1; | |
7165 | ||
7166 | dbl = 0; | |
7167 | ||
7168 | switch (mask) | |
7169 | { | |
7170 | default: | |
7171 | internalError (); | |
7172 | ||
7173 | case M_DDIV_3: | |
7174 | dbl = 1; | |
7175 | case M_DIV_3: | |
7176 | s = "mflo"; | |
7177 | goto do_div3; | |
7178 | case M_DREM_3: | |
7179 | dbl = 1; | |
7180 | case M_REM_3: | |
7181 | s = "mfhi"; | |
7182 | do_div3: | |
7183 | mips_emit_delays (true); | |
7184 | ++mips_opts.noreorder; | |
7185 | mips_any_noreorder = 1; | |
2396cfb9 | 7186 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
252b5132 RH |
7187 | dbl ? "ddiv" : "div", |
7188 | "0,x,y", xreg, yreg); | |
7189 | expr1.X_add_number = 2; | |
7190 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
2396cfb9 TS |
7191 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6", |
7192 | 7); | |
bdaaa2e1 | 7193 | |
252b5132 RH |
7194 | /* FIXME: The normal code checks for of -1 / -0x80000000 here, |
7195 | since that causes an overflow. We should do that as well, | |
7196 | but I don't see how to do the comparisons without a temporary | |
7197 | register. */ | |
7198 | --mips_opts.noreorder; | |
2396cfb9 | 7199 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg); |
252b5132 RH |
7200 | break; |
7201 | ||
7202 | case M_DIVU_3: | |
7203 | s = "divu"; | |
7204 | s2 = "mflo"; | |
7205 | goto do_divu3; | |
7206 | case M_REMU_3: | |
7207 | s = "divu"; | |
7208 | s2 = "mfhi"; | |
7209 | goto do_divu3; | |
7210 | case M_DDIVU_3: | |
7211 | s = "ddivu"; | |
7212 | s2 = "mflo"; | |
7213 | goto do_divu3; | |
7214 | case M_DREMU_3: | |
7215 | s = "ddivu"; | |
7216 | s2 = "mfhi"; | |
7217 | do_divu3: | |
7218 | mips_emit_delays (true); | |
7219 | ++mips_opts.noreorder; | |
7220 | mips_any_noreorder = 1; | |
2396cfb9 TS |
7221 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y", |
7222 | xreg, yreg); | |
252b5132 RH |
7223 | expr1.X_add_number = 2; |
7224 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
2396cfb9 TS |
7225 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
7226 | "6", 7); | |
252b5132 | 7227 | --mips_opts.noreorder; |
2396cfb9 | 7228 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg); |
252b5132 RH |
7229 | break; |
7230 | ||
7231 | case M_DMUL: | |
7232 | dbl = 1; | |
7233 | case M_MUL: | |
2396cfb9 | 7234 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 7235 | dbl ? "dmultu" : "multu", "x,y", xreg, yreg); |
2396cfb9 TS |
7236 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x", |
7237 | zreg); | |
252b5132 RH |
7238 | return; |
7239 | ||
7240 | case M_DSUBU_I: | |
7241 | dbl = 1; | |
7242 | goto do_subu; | |
7243 | case M_SUBU_I: | |
7244 | do_subu: | |
7245 | if (imm_expr.X_op != O_constant) | |
7246 | as_bad (_("Unsupported large constant")); | |
7247 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7248 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
9a41af64 | 7249 | dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg); |
252b5132 RH |
7250 | break; |
7251 | ||
7252 | case M_SUBU_I_2: | |
7253 | if (imm_expr.X_op != O_constant) | |
7254 | as_bad (_("Unsupported large constant")); | |
7255 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7256 | macro_build ((char *) NULL, &icnt, &imm_expr, "addiu", | |
7257 | "x,k", xreg); | |
7258 | break; | |
7259 | ||
7260 | case M_DSUBU_I_2: | |
7261 | if (imm_expr.X_op != O_constant) | |
7262 | as_bad (_("Unsupported large constant")); | |
7263 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7264 | macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu", | |
7265 | "y,j", yreg); | |
7266 | break; | |
7267 | ||
7268 | case M_BEQ: | |
7269 | s = "cmp"; | |
7270 | s2 = "bteqz"; | |
7271 | goto do_branch; | |
7272 | case M_BNE: | |
7273 | s = "cmp"; | |
7274 | s2 = "btnez"; | |
7275 | goto do_branch; | |
7276 | case M_BLT: | |
7277 | s = "slt"; | |
7278 | s2 = "btnez"; | |
7279 | goto do_branch; | |
7280 | case M_BLTU: | |
7281 | s = "sltu"; | |
7282 | s2 = "btnez"; | |
7283 | goto do_branch; | |
7284 | case M_BLE: | |
7285 | s = "slt"; | |
7286 | s2 = "bteqz"; | |
7287 | goto do_reverse_branch; | |
7288 | case M_BLEU: | |
7289 | s = "sltu"; | |
7290 | s2 = "bteqz"; | |
7291 | goto do_reverse_branch; | |
7292 | case M_BGE: | |
7293 | s = "slt"; | |
7294 | s2 = "bteqz"; | |
7295 | goto do_branch; | |
7296 | case M_BGEU: | |
7297 | s = "sltu"; | |
7298 | s2 = "bteqz"; | |
7299 | goto do_branch; | |
7300 | case M_BGT: | |
7301 | s = "slt"; | |
7302 | s2 = "btnez"; | |
7303 | goto do_reverse_branch; | |
7304 | case M_BGTU: | |
7305 | s = "sltu"; | |
7306 | s2 = "btnez"; | |
7307 | ||
7308 | do_reverse_branch: | |
7309 | tmp = xreg; | |
7310 | xreg = yreg; | |
7311 | yreg = tmp; | |
7312 | ||
7313 | do_branch: | |
7314 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y", | |
7315 | xreg, yreg); | |
7316 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
7317 | break; | |
7318 | ||
7319 | case M_BEQ_I: | |
7320 | s = "cmpi"; | |
7321 | s2 = "bteqz"; | |
7322 | s3 = "x,U"; | |
7323 | goto do_branch_i; | |
7324 | case M_BNE_I: | |
7325 | s = "cmpi"; | |
7326 | s2 = "btnez"; | |
7327 | s3 = "x,U"; | |
7328 | goto do_branch_i; | |
7329 | case M_BLT_I: | |
7330 | s = "slti"; | |
7331 | s2 = "btnez"; | |
7332 | s3 = "x,8"; | |
7333 | goto do_branch_i; | |
7334 | case M_BLTU_I: | |
7335 | s = "sltiu"; | |
7336 | s2 = "btnez"; | |
7337 | s3 = "x,8"; | |
7338 | goto do_branch_i; | |
7339 | case M_BLE_I: | |
7340 | s = "slti"; | |
7341 | s2 = "btnez"; | |
7342 | s3 = "x,8"; | |
7343 | goto do_addone_branch_i; | |
7344 | case M_BLEU_I: | |
7345 | s = "sltiu"; | |
7346 | s2 = "btnez"; | |
7347 | s3 = "x,8"; | |
7348 | goto do_addone_branch_i; | |
7349 | case M_BGE_I: | |
7350 | s = "slti"; | |
7351 | s2 = "bteqz"; | |
7352 | s3 = "x,8"; | |
7353 | goto do_branch_i; | |
7354 | case M_BGEU_I: | |
7355 | s = "sltiu"; | |
7356 | s2 = "bteqz"; | |
7357 | s3 = "x,8"; | |
7358 | goto do_branch_i; | |
7359 | case M_BGT_I: | |
7360 | s = "slti"; | |
7361 | s2 = "bteqz"; | |
7362 | s3 = "x,8"; | |
7363 | goto do_addone_branch_i; | |
7364 | case M_BGTU_I: | |
7365 | s = "sltiu"; | |
7366 | s2 = "bteqz"; | |
7367 | s3 = "x,8"; | |
7368 | ||
7369 | do_addone_branch_i: | |
7370 | if (imm_expr.X_op != O_constant) | |
7371 | as_bad (_("Unsupported large constant")); | |
7372 | ++imm_expr.X_add_number; | |
7373 | ||
7374 | do_branch_i: | |
7375 | macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg); | |
7376 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
7377 | break; | |
7378 | ||
7379 | case M_ABS: | |
7380 | expr1.X_add_number = 0; | |
7381 | macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg); | |
7382 | if (xreg != yreg) | |
ea1fb5dc | 7383 | move_register (&icnt, xreg, yreg); |
252b5132 RH |
7384 | expr1.X_add_number = 2; |
7385 | macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p"); | |
7386 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
7387 | "neg", "x,w", xreg, xreg); | |
7388 | } | |
7389 | } | |
7390 | ||
7391 | /* For consistency checking, verify that all bits are specified either | |
7392 | by the match/mask part of the instruction definition, or by the | |
7393 | operand list. */ | |
7394 | static int | |
7395 | validate_mips_insn (opc) | |
7396 | const struct mips_opcode *opc; | |
7397 | { | |
7398 | const char *p = opc->args; | |
7399 | char c; | |
7400 | unsigned long used_bits = opc->mask; | |
7401 | ||
7402 | if ((used_bits & opc->match) != opc->match) | |
7403 | { | |
7404 | as_bad (_("internal: bad mips opcode (mask error): %s %s"), | |
7405 | opc->name, opc->args); | |
7406 | return 0; | |
7407 | } | |
7408 | #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift))) | |
7409 | while (*p) | |
7410 | switch (c = *p++) | |
7411 | { | |
7412 | case ',': break; | |
7413 | case '(': break; | |
7414 | case ')': break; | |
7415 | case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
7416 | case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
7417 | case 'A': break; | |
4372b673 | 7418 | case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break; |
252b5132 RH |
7419 | case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break; |
7420 | case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break; | |
7421 | case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7422 | case 'F': break; | |
7423 | case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
156c2f8b | 7424 | case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
252b5132 | 7425 | case 'I': break; |
e972090a | 7426 | case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break; |
252b5132 RH |
7427 | case 'L': break; |
7428 | case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break; | |
7429 | case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break; | |
7430 | case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break; | |
7431 | case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
7432 | case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
7433 | case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
7434 | case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
7435 | case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break; | |
7436 | case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7437 | case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break; | |
7438 | case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
7439 | case 'f': break; | |
7440 | case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break; | |
7441 | case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
7442 | case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7443 | case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break; | |
7444 | case 'l': break; | |
7445 | case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7446 | case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7447 | case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break; | |
7448 | case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7449 | case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7450 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7451 | case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
7452 | case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7453 | case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7454 | case 'x': break; | |
7455 | case 'z': break; | |
7456 | case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break; | |
4372b673 NC |
7457 | case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD); |
7458 | USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
252b5132 RH |
7459 | default: |
7460 | as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"), | |
7461 | c, opc->name, opc->args); | |
7462 | return 0; | |
7463 | } | |
7464 | #undef USE_BITS | |
7465 | if (used_bits != 0xffffffff) | |
7466 | { | |
7467 | as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"), | |
7468 | ~used_bits & 0xffffffff, opc->name, opc->args); | |
7469 | return 0; | |
7470 | } | |
7471 | return 1; | |
7472 | } | |
7473 | ||
7474 | /* This routine assembles an instruction into its binary format. As a | |
7475 | side effect, it sets one of the global variables imm_reloc or | |
7476 | offset_reloc to the type of relocation to do if one of the operands | |
7477 | is an address expression. */ | |
7478 | ||
7479 | static void | |
7480 | mips_ip (str, ip) | |
7481 | char *str; | |
7482 | struct mips_cl_insn *ip; | |
7483 | { | |
7484 | char *s; | |
7485 | const char *args; | |
43841e91 | 7486 | char c = 0; |
252b5132 RH |
7487 | struct mips_opcode *insn; |
7488 | char *argsStart; | |
7489 | unsigned int regno; | |
7490 | unsigned int lastregno = 0; | |
7491 | char *s_reset; | |
7492 | char save_c = 0; | |
7493 | int full_opcode_match = 1; | |
7494 | ||
7495 | insn_error = NULL; | |
7496 | ||
7497 | /* If the instruction contains a '.', we first try to match an instruction | |
7498 | including the '.'. Then we try again without the '.'. */ | |
7499 | insn = NULL; | |
3882b010 | 7500 | for (s = str; *s != '\0' && !ISSPACE (*s); ++s) |
252b5132 RH |
7501 | continue; |
7502 | ||
7503 | /* If we stopped on whitespace, then replace the whitespace with null for | |
7504 | the call to hash_find. Save the character we replaced just in case we | |
7505 | have to re-parse the instruction. */ | |
3882b010 | 7506 | if (ISSPACE (*s)) |
252b5132 RH |
7507 | { |
7508 | save_c = *s; | |
7509 | *s++ = '\0'; | |
7510 | } | |
bdaaa2e1 | 7511 | |
252b5132 RH |
7512 | insn = (struct mips_opcode *) hash_find (op_hash, str); |
7513 | ||
7514 | /* If we didn't find the instruction in the opcode table, try again, but | |
7515 | this time with just the instruction up to, but not including the | |
7516 | first '.'. */ | |
7517 | if (insn == NULL) | |
7518 | { | |
bdaaa2e1 | 7519 | /* Restore the character we overwrite above (if any). */ |
252b5132 RH |
7520 | if (save_c) |
7521 | *(--s) = save_c; | |
7522 | ||
7523 | /* Scan up to the first '.' or whitespace. */ | |
3882b010 L |
7524 | for (s = str; |
7525 | *s != '\0' && *s != '.' && !ISSPACE (*s); | |
7526 | ++s) | |
252b5132 RH |
7527 | continue; |
7528 | ||
7529 | /* If we did not find a '.', then we can quit now. */ | |
7530 | if (*s != '.') | |
7531 | { | |
7532 | insn_error = "unrecognized opcode"; | |
7533 | return; | |
7534 | } | |
7535 | ||
7536 | /* Lookup the instruction in the hash table. */ | |
7537 | *s++ = '\0'; | |
7538 | if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL) | |
7539 | { | |
7540 | insn_error = "unrecognized opcode"; | |
7541 | return; | |
7542 | } | |
7543 | ||
7544 | full_opcode_match = 0; | |
7545 | } | |
7546 | ||
7547 | argsStart = s; | |
7548 | for (;;) | |
7549 | { | |
252b5132 RH |
7550 | boolean ok; |
7551 | ||
7552 | assert (strcmp (insn->name, str) == 0); | |
7553 | ||
ea1fb5dc | 7554 | if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_arch)) |
252b5132 | 7555 | ok = true; |
bdaaa2e1 | 7556 | else |
252b5132 | 7557 | ok = false; |
bdaaa2e1 | 7558 | |
252b5132 RH |
7559 | if (insn->pinfo != INSN_MACRO) |
7560 | { | |
ec68c924 | 7561 | if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0) |
252b5132 RH |
7562 | ok = false; |
7563 | } | |
7564 | ||
7565 | if (! ok) | |
7566 | { | |
7567 | if (insn + 1 < &mips_opcodes[NUMOPCODES] | |
7568 | && strcmp (insn->name, insn[1].name) == 0) | |
7569 | { | |
7570 | ++insn; | |
7571 | continue; | |
7572 | } | |
252b5132 | 7573 | else |
beae10d5 | 7574 | { |
268f6bed L |
7575 | if (!insn_error) |
7576 | { | |
7577 | static char buf[100]; | |
7578 | sprintf (buf, | |
7579 | _("opcode not supported on this processor: %s (%s)"), | |
ec68c924 | 7580 | mips_cpu_to_str (mips_arch), |
268f6bed | 7581 | mips_isa_to_str (mips_opts.isa)); |
bdaaa2e1 | 7582 | |
268f6bed L |
7583 | insn_error = buf; |
7584 | } | |
7585 | if (save_c) | |
7586 | *(--s) = save_c; | |
2bd7f1f3 | 7587 | return; |
252b5132 | 7588 | } |
252b5132 RH |
7589 | } |
7590 | ||
7591 | ip->insn_mo = insn; | |
7592 | ip->insn_opcode = insn->match; | |
268f6bed | 7593 | insn_error = NULL; |
252b5132 RH |
7594 | for (args = insn->args;; ++args) |
7595 | { | |
ad8d3bb3 | 7596 | s += strspn (s, " \t"); |
252b5132 RH |
7597 | switch (*args) |
7598 | { | |
7599 | case '\0': /* end of args */ | |
7600 | if (*s == '\0') | |
7601 | return; | |
7602 | break; | |
7603 | ||
7604 | case ',': | |
7605 | if (*s++ == *args) | |
7606 | continue; | |
7607 | s--; | |
7608 | switch (*++args) | |
7609 | { | |
7610 | case 'r': | |
7611 | case 'v': | |
38487616 | 7612 | ip->insn_opcode |= lastregno << OP_SH_RS; |
252b5132 RH |
7613 | continue; |
7614 | ||
7615 | case 'w': | |
38487616 TS |
7616 | ip->insn_opcode |= lastregno << OP_SH_RT; |
7617 | continue; | |
7618 | ||
252b5132 | 7619 | case 'W': |
38487616 | 7620 | ip->insn_opcode |= lastregno << OP_SH_FT; |
252b5132 RH |
7621 | continue; |
7622 | ||
7623 | case 'V': | |
38487616 | 7624 | ip->insn_opcode |= lastregno << OP_SH_FS; |
252b5132 RH |
7625 | continue; |
7626 | } | |
7627 | break; | |
7628 | ||
7629 | case '(': | |
7630 | /* Handle optional base register. | |
7631 | Either the base register is omitted or | |
bdaaa2e1 | 7632 | we must have a left paren. */ |
252b5132 RH |
7633 | /* This is dependent on the next operand specifier |
7634 | is a base register specification. */ | |
7635 | assert (args[1] == 'b' || args[1] == '5' | |
7636 | || args[1] == '-' || args[1] == '4'); | |
7637 | if (*s == '\0') | |
7638 | return; | |
7639 | ||
7640 | case ')': /* these must match exactly */ | |
7641 | if (*s++ == *args) | |
7642 | continue; | |
7643 | break; | |
7644 | ||
7645 | case '<': /* must be at least one digit */ | |
7646 | /* | |
7647 | * According to the manual, if the shift amount is greater | |
b6ff326e KH |
7648 | * than 31 or less than 0, then the shift amount should be |
7649 | * mod 32. In reality the mips assembler issues an error. | |
252b5132 RH |
7650 | * We issue a warning and mask out all but the low 5 bits. |
7651 | */ | |
7652 | my_getExpression (&imm_expr, s); | |
7653 | check_absolute_expr (ip, &imm_expr); | |
7654 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7655 | { | |
7656 | as_warn (_("Improper shift amount (%ld)"), | |
7657 | (long) imm_expr.X_add_number); | |
38487616 | 7658 | imm_expr.X_add_number &= OP_MASK_SHAMT; |
252b5132 | 7659 | } |
38487616 | 7660 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT; |
252b5132 RH |
7661 | imm_expr.X_op = O_absent; |
7662 | s = expr_end; | |
7663 | continue; | |
7664 | ||
7665 | case '>': /* shift amount minus 32 */ | |
7666 | my_getExpression (&imm_expr, s); | |
7667 | check_absolute_expr (ip, &imm_expr); | |
7668 | if ((unsigned long) imm_expr.X_add_number < 32 | |
7669 | || (unsigned long) imm_expr.X_add_number > 63) | |
7670 | break; | |
38487616 | 7671 | ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT; |
252b5132 RH |
7672 | imm_expr.X_op = O_absent; |
7673 | s = expr_end; | |
7674 | continue; | |
7675 | ||
252b5132 RH |
7676 | case 'k': /* cache code */ |
7677 | case 'h': /* prefx code */ | |
7678 | my_getExpression (&imm_expr, s); | |
7679 | check_absolute_expr (ip, &imm_expr); | |
7680 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7681 | { | |
7682 | as_warn (_("Invalid value for `%s' (%lu)"), | |
7683 | ip->insn_mo->name, | |
7684 | (unsigned long) imm_expr.X_add_number); | |
7685 | imm_expr.X_add_number &= 0x1f; | |
7686 | } | |
7687 | if (*args == 'k') | |
7688 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE; | |
7689 | else | |
7690 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX; | |
7691 | imm_expr.X_op = O_absent; | |
7692 | s = expr_end; | |
7693 | continue; | |
7694 | ||
7695 | case 'c': /* break code */ | |
7696 | my_getExpression (&imm_expr, s); | |
7697 | check_absolute_expr (ip, &imm_expr); | |
7698 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7699 | { | |
7700 | as_warn (_("Illegal break code (%ld)"), | |
7701 | (long) imm_expr.X_add_number); | |
38487616 | 7702 | imm_expr.X_add_number &= OP_MASK_CODE; |
252b5132 | 7703 | } |
38487616 | 7704 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE; |
252b5132 RH |
7705 | imm_expr.X_op = O_absent; |
7706 | s = expr_end; | |
7707 | continue; | |
7708 | ||
7709 | case 'q': /* lower break code */ | |
7710 | my_getExpression (&imm_expr, s); | |
7711 | check_absolute_expr (ip, &imm_expr); | |
7712 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7713 | { | |
7714 | as_warn (_("Illegal lower break code (%ld)"), | |
7715 | (long) imm_expr.X_add_number); | |
38487616 | 7716 | imm_expr.X_add_number &= OP_MASK_CODE2; |
252b5132 | 7717 | } |
38487616 | 7718 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2; |
252b5132 RH |
7719 | imm_expr.X_op = O_absent; |
7720 | s = expr_end; | |
7721 | continue; | |
7722 | ||
4372b673 | 7723 | case 'B': /* 20-bit syscall/break code. */ |
156c2f8b | 7724 | my_getExpression (&imm_expr, s); |
156c2f8b | 7725 | check_absolute_expr (ip, &imm_expr); |
38487616 | 7726 | if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE20) |
4372b673 | 7727 | as_warn (_("Illegal 20-bit code (%ld)"), |
252b5132 | 7728 | (long) imm_expr.X_add_number); |
38487616 | 7729 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20; |
252b5132 RH |
7730 | imm_expr.X_op = O_absent; |
7731 | s = expr_end; | |
7732 | continue; | |
7733 | ||
7734 | case 'C': /* Coprocessor code */ | |
beae10d5 | 7735 | my_getExpression (&imm_expr, s); |
252b5132 | 7736 | check_absolute_expr (ip, &imm_expr); |
beae10d5 | 7737 | if ((unsigned long) imm_expr.X_add_number >= (1<<25)) |
252b5132 | 7738 | { |
beae10d5 | 7739 | as_warn (_("Coproccesor code > 25 bits (%ld)"), |
252b5132 | 7740 | (long) imm_expr.X_add_number); |
beae10d5 | 7741 | imm_expr.X_add_number &= ((1<<25) - 1); |
252b5132 | 7742 | } |
beae10d5 KH |
7743 | ip->insn_opcode |= imm_expr.X_add_number; |
7744 | imm_expr.X_op = O_absent; | |
7745 | s = expr_end; | |
7746 | continue; | |
252b5132 | 7747 | |
4372b673 NC |
7748 | case 'J': /* 19-bit wait code. */ |
7749 | my_getExpression (&imm_expr, s); | |
7750 | check_absolute_expr (ip, &imm_expr); | |
38487616 | 7751 | if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE19) |
4372b673 NC |
7752 | as_warn (_("Illegal 19-bit code (%ld)"), |
7753 | (long) imm_expr.X_add_number); | |
38487616 | 7754 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19; |
4372b673 NC |
7755 | imm_expr.X_op = O_absent; |
7756 | s = expr_end; | |
7757 | continue; | |
7758 | ||
252b5132 | 7759 | case 'P': /* Performance register */ |
beae10d5 | 7760 | my_getExpression (&imm_expr, s); |
252b5132 | 7761 | check_absolute_expr (ip, &imm_expr); |
beae10d5 | 7762 | if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1) |
252b5132 | 7763 | { |
38487616 | 7764 | as_warn (_("Invalid performance register (%ld)"), |
252b5132 | 7765 | (long) imm_expr.X_add_number); |
38487616 | 7766 | imm_expr.X_add_number &= OP_MASK_PERFREG; |
252b5132 | 7767 | } |
38487616 | 7768 | ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG); |
beae10d5 KH |
7769 | imm_expr.X_op = O_absent; |
7770 | s = expr_end; | |
7771 | continue; | |
252b5132 RH |
7772 | |
7773 | case 'b': /* base register */ | |
7774 | case 'd': /* destination register */ | |
7775 | case 's': /* source register */ | |
7776 | case 't': /* target register */ | |
7777 | case 'r': /* both target and source */ | |
7778 | case 'v': /* both dest and source */ | |
7779 | case 'w': /* both dest and target */ | |
7780 | case 'E': /* coprocessor target register */ | |
7781 | case 'G': /* coprocessor destination register */ | |
7782 | case 'x': /* ignore register name */ | |
7783 | case 'z': /* must be zero register */ | |
4372b673 | 7784 | case 'U': /* destination register (clo/clz). */ |
252b5132 RH |
7785 | s_reset = s; |
7786 | if (s[0] == '$') | |
7787 | { | |
7788 | ||
3882b010 | 7789 | if (ISDIGIT (s[1])) |
252b5132 RH |
7790 | { |
7791 | ++s; | |
7792 | regno = 0; | |
7793 | do | |
7794 | { | |
7795 | regno *= 10; | |
7796 | regno += *s - '0'; | |
7797 | ++s; | |
7798 | } | |
3882b010 | 7799 | while (ISDIGIT (*s)); |
252b5132 RH |
7800 | if (regno > 31) |
7801 | as_bad (_("Invalid register number (%d)"), regno); | |
7802 | } | |
7803 | else if (*args == 'E' || *args == 'G') | |
7804 | goto notreg; | |
7805 | else | |
7806 | { | |
7807 | if (s[1] == 'f' && s[2] == 'p') | |
7808 | { | |
7809 | s += 3; | |
7810 | regno = FP; | |
7811 | } | |
7812 | else if (s[1] == 's' && s[2] == 'p') | |
7813 | { | |
7814 | s += 3; | |
7815 | regno = SP; | |
7816 | } | |
7817 | else if (s[1] == 'g' && s[2] == 'p') | |
7818 | { | |
7819 | s += 3; | |
7820 | regno = GP; | |
7821 | } | |
7822 | else if (s[1] == 'a' && s[2] == 't') | |
7823 | { | |
7824 | s += 3; | |
7825 | regno = AT; | |
7826 | } | |
7827 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
7828 | { | |
7829 | s += 4; | |
7830 | regno = KT0; | |
7831 | } | |
7832 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
7833 | { | |
7834 | s += 4; | |
7835 | regno = KT1; | |
7836 | } | |
7837 | else if (itbl_have_entries) | |
7838 | { | |
7839 | char *p, *n; | |
d7ba4a77 | 7840 | unsigned long r; |
252b5132 | 7841 | |
d7ba4a77 | 7842 | p = s + 1; /* advance past '$' */ |
252b5132 RH |
7843 | n = itbl_get_field (&p); /* n is name */ |
7844 | ||
d7ba4a77 ILT |
7845 | /* See if this is a register defined in an |
7846 | itbl entry. */ | |
7847 | if (itbl_get_reg_val (n, &r)) | |
252b5132 RH |
7848 | { |
7849 | /* Get_field advances to the start of | |
7850 | the next field, so we need to back | |
d7ba4a77 | 7851 | rack to the end of the last field. */ |
bdaaa2e1 | 7852 | if (p) |
252b5132 | 7853 | s = p - 1; |
bdaaa2e1 | 7854 | else |
d7ba4a77 | 7855 | s = strchr (s, '\0'); |
252b5132 RH |
7856 | regno = r; |
7857 | } | |
7858 | else | |
7859 | goto notreg; | |
beae10d5 | 7860 | } |
252b5132 RH |
7861 | else |
7862 | goto notreg; | |
7863 | } | |
7864 | if (regno == AT | |
7865 | && ! mips_opts.noat | |
7866 | && *args != 'E' | |
7867 | && *args != 'G') | |
7868 | as_warn (_("Used $at without \".set noat\"")); | |
7869 | c = *args; | |
7870 | if (*s == ' ') | |
7871 | s++; | |
7872 | if (args[1] != *s) | |
7873 | { | |
7874 | if (c == 'r' || c == 'v' || c == 'w') | |
7875 | { | |
7876 | regno = lastregno; | |
7877 | s = s_reset; | |
7878 | args++; | |
7879 | } | |
7880 | } | |
7881 | /* 'z' only matches $0. */ | |
7882 | if (c == 'z' && regno != 0) | |
7883 | break; | |
7884 | ||
bdaaa2e1 KH |
7885 | /* Now that we have assembled one operand, we use the args string |
7886 | * to figure out where it goes in the instruction. */ | |
252b5132 RH |
7887 | switch (c) |
7888 | { | |
7889 | case 'r': | |
7890 | case 's': | |
7891 | case 'v': | |
7892 | case 'b': | |
38487616 | 7893 | ip->insn_opcode |= regno << OP_SH_RS; |
252b5132 RH |
7894 | break; |
7895 | case 'd': | |
7896 | case 'G': | |
38487616 | 7897 | ip->insn_opcode |= regno << OP_SH_RD; |
252b5132 | 7898 | break; |
4372b673 | 7899 | case 'U': |
38487616 TS |
7900 | ip->insn_opcode |= regno << OP_SH_RD; |
7901 | ip->insn_opcode |= regno << OP_SH_RT; | |
4372b673 | 7902 | break; |
252b5132 RH |
7903 | case 'w': |
7904 | case 't': | |
7905 | case 'E': | |
38487616 | 7906 | ip->insn_opcode |= regno << OP_SH_RT; |
252b5132 RH |
7907 | break; |
7908 | case 'x': | |
7909 | /* This case exists because on the r3000 trunc | |
7910 | expands into a macro which requires a gp | |
7911 | register. On the r6000 or r4000 it is | |
7912 | assembled into a single instruction which | |
7913 | ignores the register. Thus the insn version | |
7914 | is MIPS_ISA2 and uses 'x', and the macro | |
7915 | version is MIPS_ISA1 and uses 't'. */ | |
7916 | break; | |
7917 | case 'z': | |
7918 | /* This case is for the div instruction, which | |
7919 | acts differently if the destination argument | |
7920 | is $0. This only matches $0, and is checked | |
7921 | outside the switch. */ | |
7922 | break; | |
7923 | case 'D': | |
7924 | /* Itbl operand; not yet implemented. FIXME ?? */ | |
7925 | break; | |
7926 | /* What about all other operands like 'i', which | |
7927 | can be specified in the opcode table? */ | |
7928 | } | |
7929 | lastregno = regno; | |
7930 | continue; | |
7931 | } | |
7932 | notreg: | |
7933 | switch (*args++) | |
7934 | { | |
7935 | case 'r': | |
7936 | case 'v': | |
38487616 | 7937 | ip->insn_opcode |= lastregno << OP_SH_RS; |
252b5132 RH |
7938 | continue; |
7939 | case 'w': | |
38487616 | 7940 | ip->insn_opcode |= lastregno << OP_SH_RT; |
252b5132 RH |
7941 | continue; |
7942 | } | |
7943 | break; | |
7944 | ||
7945 | case 'D': /* floating point destination register */ | |
7946 | case 'S': /* floating point source register */ | |
7947 | case 'T': /* floating point target register */ | |
7948 | case 'R': /* floating point source register */ | |
7949 | case 'V': | |
7950 | case 'W': | |
7951 | s_reset = s; | |
3882b010 L |
7952 | if (s[0] == '$' && s[1] == 'f' |
7953 | && ISDIGIT (s[2])) | |
252b5132 RH |
7954 | { |
7955 | s += 2; | |
7956 | regno = 0; | |
7957 | do | |
7958 | { | |
7959 | regno *= 10; | |
7960 | regno += *s - '0'; | |
7961 | ++s; | |
7962 | } | |
3882b010 | 7963 | while (ISDIGIT (*s)); |
252b5132 RH |
7964 | |
7965 | if (regno > 31) | |
7966 | as_bad (_("Invalid float register number (%d)"), regno); | |
7967 | ||
7968 | if ((regno & 1) != 0 | |
ca4e0257 | 7969 | && HAVE_32BIT_FPRS |
252b5132 RH |
7970 | && ! (strcmp (str, "mtc1") == 0 |
7971 | || strcmp (str, "mfc1") == 0 | |
7972 | || strcmp (str, "lwc1") == 0 | |
7973 | || strcmp (str, "swc1") == 0 | |
7974 | || strcmp (str, "l.s") == 0 | |
7975 | || strcmp (str, "s.s") == 0)) | |
7976 | as_warn (_("Float register should be even, was %d"), | |
7977 | regno); | |
7978 | ||
7979 | c = *args; | |
7980 | if (*s == ' ') | |
7981 | s++; | |
7982 | if (args[1] != *s) | |
7983 | { | |
7984 | if (c == 'V' || c == 'W') | |
7985 | { | |
7986 | regno = lastregno; | |
7987 | s = s_reset; | |
7988 | args++; | |
7989 | } | |
7990 | } | |
7991 | switch (c) | |
7992 | { | |
7993 | case 'D': | |
38487616 | 7994 | ip->insn_opcode |= regno << OP_SH_FD; |
252b5132 RH |
7995 | break; |
7996 | case 'V': | |
7997 | case 'S': | |
38487616 | 7998 | ip->insn_opcode |= regno << OP_SH_FS; |
252b5132 RH |
7999 | break; |
8000 | case 'W': | |
8001 | case 'T': | |
38487616 | 8002 | ip->insn_opcode |= regno << OP_SH_FT; |
252b5132 RH |
8003 | break; |
8004 | case 'R': | |
38487616 | 8005 | ip->insn_opcode |= regno << OP_SH_FR; |
252b5132 RH |
8006 | break; |
8007 | } | |
8008 | lastregno = regno; | |
8009 | continue; | |
8010 | } | |
8011 | ||
252b5132 RH |
8012 | switch (*args++) |
8013 | { | |
8014 | case 'V': | |
38487616 | 8015 | ip->insn_opcode |= lastregno << OP_SH_FS; |
252b5132 RH |
8016 | continue; |
8017 | case 'W': | |
38487616 | 8018 | ip->insn_opcode |= lastregno << OP_SH_FT; |
252b5132 RH |
8019 | continue; |
8020 | } | |
8021 | break; | |
8022 | ||
8023 | case 'I': | |
8024 | my_getExpression (&imm_expr, s); | |
8025 | if (imm_expr.X_op != O_big | |
8026 | && imm_expr.X_op != O_constant) | |
8027 | insn_error = _("absolute expression required"); | |
8028 | s = expr_end; | |
8029 | continue; | |
8030 | ||
8031 | case 'A': | |
8032 | my_getExpression (&offset_expr, s); | |
f6688943 | 8033 | *imm_reloc = BFD_RELOC_32; |
252b5132 RH |
8034 | s = expr_end; |
8035 | continue; | |
8036 | ||
8037 | case 'F': | |
8038 | case 'L': | |
8039 | case 'f': | |
8040 | case 'l': | |
8041 | { | |
8042 | int f64; | |
ca4e0257 | 8043 | int using_gprs; |
252b5132 RH |
8044 | char *save_in; |
8045 | char *err; | |
8046 | unsigned char temp[8]; | |
8047 | int len; | |
8048 | unsigned int length; | |
8049 | segT seg; | |
8050 | subsegT subseg; | |
8051 | char *p; | |
8052 | ||
8053 | /* These only appear as the last operand in an | |
8054 | instruction, and every instruction that accepts | |
8055 | them in any variant accepts them in all variants. | |
8056 | This means we don't have to worry about backing out | |
8057 | any changes if the instruction does not match. | |
8058 | ||
8059 | The difference between them is the size of the | |
8060 | floating point constant and where it goes. For 'F' | |
8061 | and 'L' the constant is 64 bits; for 'f' and 'l' it | |
8062 | is 32 bits. Where the constant is placed is based | |
8063 | on how the MIPS assembler does things: | |
8064 | F -- .rdata | |
8065 | L -- .lit8 | |
8066 | f -- immediate value | |
8067 | l -- .lit4 | |
8068 | ||
8069 | The .lit4 and .lit8 sections are only used if | |
8070 | permitted by the -G argument. | |
8071 | ||
8072 | When generating embedded PIC code, we use the | |
8073 | .lit8 section but not the .lit4 section (we can do | |
8074 | .lit4 inline easily; we need to put .lit8 | |
8075 | somewhere in the data segment, and using .lit8 | |
8076 | permits the linker to eventually combine identical | |
ca4e0257 RS |
8077 | .lit8 entries). |
8078 | ||
8079 | The code below needs to know whether the target register | |
8080 | is 32 or 64 bits wide. It relies on the fact 'f' and | |
8081 | 'F' are used with GPR-based instructions and 'l' and | |
8082 | 'L' are used with FPR-based instructions. */ | |
252b5132 RH |
8083 | |
8084 | f64 = *args == 'F' || *args == 'L'; | |
ca4e0257 | 8085 | using_gprs = *args == 'F' || *args == 'f'; |
252b5132 RH |
8086 | |
8087 | save_in = input_line_pointer; | |
8088 | input_line_pointer = s; | |
8089 | err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len); | |
8090 | length = len; | |
8091 | s = input_line_pointer; | |
8092 | input_line_pointer = save_in; | |
8093 | if (err != NULL && *err != '\0') | |
8094 | { | |
8095 | as_bad (_("Bad floating point constant: %s"), err); | |
8096 | memset (temp, '\0', sizeof temp); | |
8097 | length = f64 ? 8 : 4; | |
8098 | } | |
8099 | ||
156c2f8b | 8100 | assert (length == (unsigned) (f64 ? 8 : 4)); |
252b5132 RH |
8101 | |
8102 | if (*args == 'f' | |
8103 | || (*args == 'l' | |
8104 | && (! USE_GLOBAL_POINTER_OPT | |
8105 | || mips_pic == EMBEDDED_PIC | |
8106 | || g_switch_value < 4 | |
8107 | || (temp[0] == 0 && temp[1] == 0) | |
8108 | || (temp[2] == 0 && temp[3] == 0)))) | |
8109 | { | |
8110 | imm_expr.X_op = O_constant; | |
8111 | if (! target_big_endian) | |
8112 | imm_expr.X_add_number = bfd_getl32 (temp); | |
8113 | else | |
8114 | imm_expr.X_add_number = bfd_getb32 (temp); | |
8115 | } | |
8116 | else if (length > 4 | |
119d663a | 8117 | && ! mips_disable_float_construction |
ca4e0257 RS |
8118 | /* Constants can only be constructed in GPRs and |
8119 | copied to FPRs if the GPRs are at least as wide | |
8120 | as the FPRs. Force the constant into memory if | |
8121 | we are using 64-bit FPRs but the GPRs are only | |
8122 | 32 bits wide. */ | |
8123 | && (using_gprs | |
8124 | || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS)) | |
252b5132 RH |
8125 | && ((temp[0] == 0 && temp[1] == 0) |
8126 | || (temp[2] == 0 && temp[3] == 0)) | |
8127 | && ((temp[4] == 0 && temp[5] == 0) | |
8128 | || (temp[6] == 0 && temp[7] == 0))) | |
8129 | { | |
ca4e0257 RS |
8130 | /* The value is simple enough to load with a couple of |
8131 | instructions. If using 32-bit registers, set | |
8132 | imm_expr to the high order 32 bits and offset_expr to | |
8133 | the low order 32 bits. Otherwise, set imm_expr to | |
8134 | the entire 64 bit constant. */ | |
8135 | if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS) | |
252b5132 RH |
8136 | { |
8137 | imm_expr.X_op = O_constant; | |
8138 | offset_expr.X_op = O_constant; | |
8139 | if (! target_big_endian) | |
8140 | { | |
8141 | imm_expr.X_add_number = bfd_getl32 (temp + 4); | |
8142 | offset_expr.X_add_number = bfd_getl32 (temp); | |
8143 | } | |
8144 | else | |
8145 | { | |
8146 | imm_expr.X_add_number = bfd_getb32 (temp); | |
8147 | offset_expr.X_add_number = bfd_getb32 (temp + 4); | |
8148 | } | |
8149 | if (offset_expr.X_add_number == 0) | |
8150 | offset_expr.X_op = O_absent; | |
8151 | } | |
8152 | else if (sizeof (imm_expr.X_add_number) > 4) | |
8153 | { | |
8154 | imm_expr.X_op = O_constant; | |
8155 | if (! target_big_endian) | |
8156 | imm_expr.X_add_number = bfd_getl64 (temp); | |
8157 | else | |
8158 | imm_expr.X_add_number = bfd_getb64 (temp); | |
8159 | } | |
8160 | else | |
8161 | { | |
8162 | imm_expr.X_op = O_big; | |
8163 | imm_expr.X_add_number = 4; | |
8164 | if (! target_big_endian) | |
8165 | { | |
8166 | generic_bignum[0] = bfd_getl16 (temp); | |
8167 | generic_bignum[1] = bfd_getl16 (temp + 2); | |
8168 | generic_bignum[2] = bfd_getl16 (temp + 4); | |
8169 | generic_bignum[3] = bfd_getl16 (temp + 6); | |
8170 | } | |
8171 | else | |
8172 | { | |
8173 | generic_bignum[0] = bfd_getb16 (temp + 6); | |
8174 | generic_bignum[1] = bfd_getb16 (temp + 4); | |
8175 | generic_bignum[2] = bfd_getb16 (temp + 2); | |
8176 | generic_bignum[3] = bfd_getb16 (temp); | |
8177 | } | |
8178 | } | |
8179 | } | |
8180 | else | |
8181 | { | |
8182 | const char *newname; | |
8183 | segT new_seg; | |
8184 | ||
8185 | /* Switch to the right section. */ | |
8186 | seg = now_seg; | |
8187 | subseg = now_subseg; | |
8188 | switch (*args) | |
8189 | { | |
8190 | default: /* unused default case avoids warnings. */ | |
8191 | case 'L': | |
8192 | newname = RDATA_SECTION_NAME; | |
bb2d6cd7 GK |
8193 | if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8) |
8194 | || mips_pic == EMBEDDED_PIC) | |
252b5132 RH |
8195 | newname = ".lit8"; |
8196 | break; | |
8197 | case 'F': | |
bb2d6cd7 GK |
8198 | if (mips_pic == EMBEDDED_PIC) |
8199 | newname = ".lit8"; | |
8200 | else | |
8201 | newname = RDATA_SECTION_NAME; | |
252b5132 RH |
8202 | break; |
8203 | case 'l': | |
8204 | assert (!USE_GLOBAL_POINTER_OPT | |
8205 | || g_switch_value >= 4); | |
8206 | newname = ".lit4"; | |
8207 | break; | |
8208 | } | |
8209 | new_seg = subseg_new (newname, (subsegT) 0); | |
8210 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
8211 | bfd_set_section_flags (stdoutput, new_seg, | |
8212 | (SEC_ALLOC | |
8213 | | SEC_LOAD | |
8214 | | SEC_READONLY | |
8215 | | SEC_DATA)); | |
8216 | frag_align (*args == 'l' ? 2 : 3, 0, 0); | |
8217 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
8218 | && strcmp (TARGET_OS, "elf") != 0) | |
8219 | record_alignment (new_seg, 4); | |
8220 | else | |
8221 | record_alignment (new_seg, *args == 'l' ? 2 : 3); | |
8222 | if (seg == now_seg) | |
8223 | as_bad (_("Can't use floating point insn in this section")); | |
8224 | ||
8225 | /* Set the argument to the current address in the | |
8226 | section. */ | |
8227 | offset_expr.X_op = O_symbol; | |
8228 | offset_expr.X_add_symbol = | |
8229 | symbol_new ("L0\001", now_seg, | |
8230 | (valueT) frag_now_fix (), frag_now); | |
8231 | offset_expr.X_add_number = 0; | |
8232 | ||
8233 | /* Put the floating point number into the section. */ | |
8234 | p = frag_more ((int) length); | |
8235 | memcpy (p, temp, length); | |
8236 | ||
8237 | /* Switch back to the original section. */ | |
8238 | subseg_set (seg, subseg); | |
8239 | } | |
8240 | } | |
8241 | continue; | |
8242 | ||
8243 | case 'i': /* 16 bit unsigned immediate */ | |
8244 | case 'j': /* 16 bit signed immediate */ | |
f6688943 | 8245 | *imm_reloc = BFD_RELOC_LO16; |
252b5132 | 8246 | c = my_getSmallExpression (&imm_expr, s); |
fb1b3232 | 8247 | if (c != S_EX_NONE) |
252b5132 | 8248 | { |
fb1b3232 | 8249 | if (c != S_EX_LO) |
252b5132 RH |
8250 | { |
8251 | if (imm_expr.X_op == O_constant) | |
8252 | imm_expr.X_add_number = | |
8253 | (imm_expr.X_add_number >> 16) & 0xffff; | |
ad8d3bb3 | 8254 | #ifdef OBJ_ELF |
fb1b3232 | 8255 | else if (c == S_EX_HIGHEST) |
f6688943 | 8256 | *imm_reloc = BFD_RELOC_MIPS_HIGHEST; |
fb1b3232 | 8257 | else if (c == S_EX_HIGHER) |
f6688943 | 8258 | *imm_reloc = BFD_RELOC_MIPS_HIGHER; |
ad8d3bb3 TS |
8259 | else if (c == S_EX_GP_REL) |
8260 | { | |
8261 | /* This occurs in NewABI only. */ | |
8262 | c = my_getSmallExpression (&imm_expr, s); | |
8263 | if (c != S_EX_NEG) | |
8264 | as_bad (_("bad composition of relocations")); | |
8265 | else | |
8266 | { | |
8267 | c = my_getSmallExpression (&imm_expr, s); | |
8268 | if (c != S_EX_LO) | |
8269 | as_bad (_("bad composition of relocations")); | |
8270 | else | |
8271 | { | |
8272 | imm_reloc[0] = BFD_RELOC_GPREL16; | |
8273 | imm_reloc[1] = BFD_RELOC_MIPS_SUB; | |
8274 | imm_reloc[2] = BFD_RELOC_LO16; | |
8275 | } | |
8276 | } | |
8277 | } | |
8278 | #endif | |
fb1b3232 | 8279 | else if (c == S_EX_HI) |
252b5132 | 8280 | { |
f6688943 | 8281 | *imm_reloc = BFD_RELOC_HI16_S; |
252b5132 RH |
8282 | imm_unmatched_hi = true; |
8283 | } | |
8284 | else | |
f6688943 | 8285 | *imm_reloc = BFD_RELOC_HI16; |
252b5132 RH |
8286 | } |
8287 | else if (imm_expr.X_op == O_constant) | |
8288 | imm_expr.X_add_number &= 0xffff; | |
8289 | } | |
8290 | if (*args == 'i') | |
8291 | { | |
fb1b3232 | 8292 | if ((c == S_EX_NONE && imm_expr.X_op != O_constant) |
252b5132 | 8293 | || ((imm_expr.X_add_number < 0 |
beae10d5 KH |
8294 | || imm_expr.X_add_number >= 0x10000) |
8295 | && imm_expr.X_op == O_constant)) | |
252b5132 RH |
8296 | { |
8297 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
8298 | !strcmp (insn->name, insn[1].name)) | |
8299 | break; | |
2ae7e77b AH |
8300 | if (imm_expr.X_op == O_constant |
8301 | || imm_expr.X_op == O_big) | |
252b5132 RH |
8302 | as_bad (_("16 bit expression not in range 0..65535")); |
8303 | } | |
8304 | } | |
8305 | else | |
8306 | { | |
8307 | int more; | |
8308 | offsetT max; | |
8309 | ||
8310 | /* The upper bound should be 0x8000, but | |
8311 | unfortunately the MIPS assembler accepts numbers | |
8312 | from 0x8000 to 0xffff and sign extends them, and | |
8313 | we want to be compatible. We only permit this | |
8314 | extended range for an instruction which does not | |
8315 | provide any further alternates, since those | |
8316 | alternates may handle other cases. People should | |
8317 | use the numbers they mean, rather than relying on | |
8318 | a mysterious sign extension. */ | |
8319 | more = (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
8320 | strcmp (insn->name, insn[1].name) == 0); | |
8321 | if (more) | |
8322 | max = 0x8000; | |
8323 | else | |
8324 | max = 0x10000; | |
fb1b3232 | 8325 | if ((c == S_EX_NONE && imm_expr.X_op != O_constant) |
252b5132 | 8326 | || ((imm_expr.X_add_number < -0x8000 |
beae10d5 KH |
8327 | || imm_expr.X_add_number >= max) |
8328 | && imm_expr.X_op == O_constant) | |
252b5132 RH |
8329 | || (more |
8330 | && imm_expr.X_add_number < 0 | |
ca4e0257 | 8331 | && HAVE_64BIT_GPRS |
252b5132 RH |
8332 | && imm_expr.X_unsigned |
8333 | && sizeof (imm_expr.X_add_number) <= 4)) | |
8334 | { | |
8335 | if (more) | |
8336 | break; | |
2ae7e77b AH |
8337 | if (imm_expr.X_op == O_constant |
8338 | || imm_expr.X_op == O_big) | |
252b5132 RH |
8339 | as_bad (_("16 bit expression not in range -32768..32767")); |
8340 | } | |
8341 | } | |
8342 | s = expr_end; | |
8343 | continue; | |
8344 | ||
8345 | case 'o': /* 16 bit offset */ | |
8346 | c = my_getSmallExpression (&offset_expr, s); | |
8347 | ||
8348 | /* If this value won't fit into a 16 bit offset, then go | |
8349 | find a macro that will generate the 32 bit offset | |
afdbd6d0 | 8350 | code pattern. */ |
fb1b3232 | 8351 | if (c == S_EX_NONE |
252b5132 RH |
8352 | && (offset_expr.X_op != O_constant |
8353 | || offset_expr.X_add_number >= 0x8000 | |
afdbd6d0 | 8354 | || offset_expr.X_add_number < -0x8000)) |
252b5132 RH |
8355 | break; |
8356 | ||
fb1b3232 | 8357 | if (c == S_EX_HI) |
252b5132 RH |
8358 | { |
8359 | if (offset_expr.X_op != O_constant) | |
8360 | break; | |
8361 | offset_expr.X_add_number = | |
8362 | (offset_expr.X_add_number >> 16) & 0xffff; | |
8363 | } | |
f6688943 | 8364 | *offset_reloc = BFD_RELOC_LO16; |
252b5132 RH |
8365 | s = expr_end; |
8366 | continue; | |
8367 | ||
8368 | case 'p': /* pc relative offset */ | |
cb56d3d3 | 8369 | if (mips_pic == EMBEDDED_PIC) |
f6688943 | 8370 | *offset_reloc = BFD_RELOC_16_PCREL_S2; |
cb56d3d3 | 8371 | else |
f6688943 | 8372 | *offset_reloc = BFD_RELOC_16_PCREL; |
252b5132 RH |
8373 | my_getExpression (&offset_expr, s); |
8374 | s = expr_end; | |
8375 | continue; | |
8376 | ||
8377 | case 'u': /* upper 16 bits */ | |
8378 | c = my_getSmallExpression (&imm_expr, s); | |
f6688943 | 8379 | *imm_reloc = BFD_RELOC_LO16; |
e7d556df | 8380 | if (c != S_EX_NONE) |
252b5132 | 8381 | { |
fb1b3232 | 8382 | if (c != S_EX_LO) |
252b5132 RH |
8383 | { |
8384 | if (imm_expr.X_op == O_constant) | |
8385 | imm_expr.X_add_number = | |
8386 | (imm_expr.X_add_number >> 16) & 0xffff; | |
fb1b3232 | 8387 | else if (c == S_EX_HI) |
252b5132 | 8388 | { |
f6688943 | 8389 | *imm_reloc = BFD_RELOC_HI16_S; |
252b5132 RH |
8390 | imm_unmatched_hi = true; |
8391 | } | |
645dc66c TS |
8392 | #ifdef OBJ_ELF |
8393 | else if (c == S_EX_HIGHEST) | |
8394 | *imm_reloc = BFD_RELOC_MIPS_HIGHEST; | |
ad8d3bb3 TS |
8395 | else if (c == S_EX_GP_REL) |
8396 | { | |
8397 | /* This occurs in NewABI only. */ | |
8398 | c = my_getSmallExpression (&imm_expr, s); | |
8399 | if (c != S_EX_NEG) | |
8400 | as_bad (_("bad composition of relocations")); | |
8401 | else | |
8402 | { | |
8403 | c = my_getSmallExpression (&imm_expr, s); | |
8404 | if (c != S_EX_HI) | |
8405 | as_bad (_("bad composition of relocations")); | |
8406 | else | |
8407 | { | |
8408 | imm_reloc[0] = BFD_RELOC_GPREL16; | |
8409 | imm_reloc[1] = BFD_RELOC_MIPS_SUB; | |
8410 | imm_reloc[2] = BFD_RELOC_HI16_S; | |
8411 | } | |
8412 | } | |
8413 | } | |
8414 | #endif | |
252b5132 | 8415 | else |
f6688943 | 8416 | *imm_reloc = BFD_RELOC_HI16; |
252b5132 RH |
8417 | } |
8418 | else if (imm_expr.X_op == O_constant) | |
8419 | imm_expr.X_add_number &= 0xffff; | |
8420 | } | |
8421 | if (imm_expr.X_op == O_constant | |
8422 | && (imm_expr.X_add_number < 0 | |
8423 | || imm_expr.X_add_number >= 0x10000)) | |
8424 | as_bad (_("lui expression not in range 0..65535")); | |
8425 | s = expr_end; | |
8426 | continue; | |
8427 | ||
8428 | case 'a': /* 26 bit address */ | |
8429 | my_getExpression (&offset_expr, s); | |
8430 | s = expr_end; | |
f6688943 | 8431 | *offset_reloc = BFD_RELOC_MIPS_JMP; |
252b5132 RH |
8432 | continue; |
8433 | ||
8434 | case 'N': /* 3 bit branch condition code */ | |
8435 | case 'M': /* 3 bit compare condition code */ | |
8436 | if (strncmp (s, "$fcc", 4) != 0) | |
8437 | break; | |
8438 | s += 4; | |
8439 | regno = 0; | |
8440 | do | |
8441 | { | |
8442 | regno *= 10; | |
8443 | regno += *s - '0'; | |
8444 | ++s; | |
8445 | } | |
3882b010 | 8446 | while (ISDIGIT (*s)); |
252b5132 RH |
8447 | if (regno > 7) |
8448 | as_bad (_("invalid condition code register $fcc%d"), regno); | |
8449 | if (*args == 'N') | |
8450 | ip->insn_opcode |= regno << OP_SH_BCC; | |
8451 | else | |
8452 | ip->insn_opcode |= regno << OP_SH_CCC; | |
beae10d5 | 8453 | continue; |
252b5132 | 8454 | |
156c2f8b NC |
8455 | case 'H': |
8456 | if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) | |
8457 | s += 2; | |
3882b010 | 8458 | if (ISDIGIT (*s)) |
156c2f8b NC |
8459 | { |
8460 | c = 0; | |
8461 | do | |
8462 | { | |
8463 | c *= 10; | |
8464 | c += *s - '0'; | |
8465 | ++s; | |
8466 | } | |
3882b010 | 8467 | while (ISDIGIT (*s)); |
156c2f8b NC |
8468 | } |
8469 | else | |
8470 | c = 8; /* Invalid sel value. */ | |
8471 | ||
8472 | if (c > 7) | |
8473 | as_bad (_("invalid coprocessor sub-selection value (0-7)")); | |
8474 | ip->insn_opcode |= c; | |
8475 | continue; | |
8476 | ||
252b5132 RH |
8477 | default: |
8478 | as_bad (_("bad char = '%c'\n"), *args); | |
8479 | internalError (); | |
8480 | } | |
8481 | break; | |
8482 | } | |
8483 | /* Args don't match. */ | |
8484 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
8485 | !strcmp (insn->name, insn[1].name)) | |
8486 | { | |
8487 | ++insn; | |
8488 | s = argsStart; | |
268f6bed | 8489 | insn_error = _("illegal operands"); |
252b5132 RH |
8490 | continue; |
8491 | } | |
268f6bed L |
8492 | if (save_c) |
8493 | *(--s) = save_c; | |
252b5132 RH |
8494 | insn_error = _("illegal operands"); |
8495 | return; | |
8496 | } | |
8497 | } | |
8498 | ||
8499 | /* This routine assembles an instruction into its binary format when | |
8500 | assembling for the mips16. As a side effect, it sets one of the | |
8501 | global variables imm_reloc or offset_reloc to the type of | |
8502 | relocation to do if one of the operands is an address expression. | |
8503 | It also sets mips16_small and mips16_ext if the user explicitly | |
8504 | requested a small or extended instruction. */ | |
8505 | ||
8506 | static void | |
8507 | mips16_ip (str, ip) | |
8508 | char *str; | |
8509 | struct mips_cl_insn *ip; | |
8510 | { | |
8511 | char *s; | |
8512 | const char *args; | |
8513 | struct mips_opcode *insn; | |
8514 | char *argsstart; | |
8515 | unsigned int regno; | |
8516 | unsigned int lastregno = 0; | |
8517 | char *s_reset; | |
8518 | ||
8519 | insn_error = NULL; | |
8520 | ||
8521 | mips16_small = false; | |
8522 | mips16_ext = false; | |
8523 | ||
3882b010 | 8524 | for (s = str; ISLOWER (*s); ++s) |
252b5132 RH |
8525 | ; |
8526 | switch (*s) | |
8527 | { | |
8528 | case '\0': | |
8529 | break; | |
8530 | ||
8531 | case ' ': | |
8532 | *s++ = '\0'; | |
8533 | break; | |
8534 | ||
8535 | case '.': | |
8536 | if (s[1] == 't' && s[2] == ' ') | |
8537 | { | |
8538 | *s = '\0'; | |
8539 | mips16_small = true; | |
8540 | s += 3; | |
8541 | break; | |
8542 | } | |
8543 | else if (s[1] == 'e' && s[2] == ' ') | |
8544 | { | |
8545 | *s = '\0'; | |
8546 | mips16_ext = true; | |
8547 | s += 3; | |
8548 | break; | |
8549 | } | |
8550 | /* Fall through. */ | |
8551 | default: | |
8552 | insn_error = _("unknown opcode"); | |
8553 | return; | |
8554 | } | |
8555 | ||
8556 | if (mips_opts.noautoextend && ! mips16_ext) | |
8557 | mips16_small = true; | |
8558 | ||
8559 | if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL) | |
8560 | { | |
8561 | insn_error = _("unrecognized opcode"); | |
8562 | return; | |
8563 | } | |
8564 | ||
8565 | argsstart = s; | |
8566 | for (;;) | |
8567 | { | |
8568 | assert (strcmp (insn->name, str) == 0); | |
8569 | ||
8570 | ip->insn_mo = insn; | |
8571 | ip->insn_opcode = insn->match; | |
8572 | ip->use_extend = false; | |
8573 | imm_expr.X_op = O_absent; | |
f6688943 TS |
8574 | imm_reloc[0] = BFD_RELOC_UNUSED; |
8575 | imm_reloc[1] = BFD_RELOC_UNUSED; | |
8576 | imm_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 | 8577 | offset_expr.X_op = O_absent; |
f6688943 TS |
8578 | offset_reloc[0] = BFD_RELOC_UNUSED; |
8579 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
8580 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
8581 | for (args = insn->args; 1; ++args) |
8582 | { | |
8583 | int c; | |
8584 | ||
8585 | if (*s == ' ') | |
8586 | ++s; | |
8587 | ||
8588 | /* In this switch statement we call break if we did not find | |
8589 | a match, continue if we did find a match, or return if we | |
8590 | are done. */ | |
8591 | ||
8592 | c = *args; | |
8593 | switch (c) | |
8594 | { | |
8595 | case '\0': | |
8596 | if (*s == '\0') | |
8597 | { | |
8598 | /* Stuff the immediate value in now, if we can. */ | |
8599 | if (imm_expr.X_op == O_constant | |
f6688943 | 8600 | && *imm_reloc > BFD_RELOC_UNUSED |
252b5132 RH |
8601 | && insn->pinfo != INSN_MACRO) |
8602 | { | |
c4e7957c | 8603 | mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED, |
252b5132 RH |
8604 | imm_expr.X_add_number, true, mips16_small, |
8605 | mips16_ext, &ip->insn_opcode, | |
8606 | &ip->use_extend, &ip->extend); | |
8607 | imm_expr.X_op = O_absent; | |
f6688943 | 8608 | *imm_reloc = BFD_RELOC_UNUSED; |
252b5132 RH |
8609 | } |
8610 | ||
8611 | return; | |
8612 | } | |
8613 | break; | |
8614 | ||
8615 | case ',': | |
8616 | if (*s++ == c) | |
8617 | continue; | |
8618 | s--; | |
8619 | switch (*++args) | |
8620 | { | |
8621 | case 'v': | |
8622 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8623 | continue; | |
8624 | case 'w': | |
8625 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8626 | continue; | |
8627 | } | |
8628 | break; | |
8629 | ||
8630 | case '(': | |
8631 | case ')': | |
8632 | if (*s++ == c) | |
8633 | continue; | |
8634 | break; | |
8635 | ||
8636 | case 'v': | |
8637 | case 'w': | |
8638 | if (s[0] != '$') | |
8639 | { | |
8640 | if (c == 'v') | |
8641 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8642 | else | |
8643 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8644 | ++args; | |
8645 | continue; | |
8646 | } | |
8647 | /* Fall through. */ | |
8648 | case 'x': | |
8649 | case 'y': | |
8650 | case 'z': | |
8651 | case 'Z': | |
8652 | case '0': | |
8653 | case 'S': | |
8654 | case 'R': | |
8655 | case 'X': | |
8656 | case 'Y': | |
8657 | if (s[0] != '$') | |
8658 | break; | |
8659 | s_reset = s; | |
3882b010 | 8660 | if (ISDIGIT (s[1])) |
252b5132 RH |
8661 | { |
8662 | ++s; | |
8663 | regno = 0; | |
8664 | do | |
8665 | { | |
8666 | regno *= 10; | |
8667 | regno += *s - '0'; | |
8668 | ++s; | |
8669 | } | |
3882b010 | 8670 | while (ISDIGIT (*s)); |
252b5132 RH |
8671 | if (regno > 31) |
8672 | { | |
8673 | as_bad (_("invalid register number (%d)"), regno); | |
8674 | regno = 2; | |
8675 | } | |
8676 | } | |
8677 | else | |
8678 | { | |
8679 | if (s[1] == 'f' && s[2] == 'p') | |
8680 | { | |
8681 | s += 3; | |
8682 | regno = FP; | |
8683 | } | |
8684 | else if (s[1] == 's' && s[2] == 'p') | |
8685 | { | |
8686 | s += 3; | |
8687 | regno = SP; | |
8688 | } | |
8689 | else if (s[1] == 'g' && s[2] == 'p') | |
8690 | { | |
8691 | s += 3; | |
8692 | regno = GP; | |
8693 | } | |
8694 | else if (s[1] == 'a' && s[2] == 't') | |
8695 | { | |
8696 | s += 3; | |
8697 | regno = AT; | |
8698 | } | |
8699 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
8700 | { | |
8701 | s += 4; | |
8702 | regno = KT0; | |
8703 | } | |
8704 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
8705 | { | |
8706 | s += 4; | |
8707 | regno = KT1; | |
8708 | } | |
8709 | else | |
8710 | break; | |
8711 | } | |
8712 | ||
8713 | if (*s == ' ') | |
8714 | ++s; | |
8715 | if (args[1] != *s) | |
8716 | { | |
8717 | if (c == 'v' || c == 'w') | |
8718 | { | |
8719 | regno = mips16_to_32_reg_map[lastregno]; | |
8720 | s = s_reset; | |
8721 | args++; | |
8722 | } | |
8723 | } | |
8724 | ||
8725 | switch (c) | |
8726 | { | |
8727 | case 'x': | |
8728 | case 'y': | |
8729 | case 'z': | |
8730 | case 'v': | |
8731 | case 'w': | |
8732 | case 'Z': | |
8733 | regno = mips32_to_16_reg_map[regno]; | |
8734 | break; | |
8735 | ||
8736 | case '0': | |
8737 | if (regno != 0) | |
8738 | regno = ILLEGAL_REG; | |
8739 | break; | |
8740 | ||
8741 | case 'S': | |
8742 | if (regno != SP) | |
8743 | regno = ILLEGAL_REG; | |
8744 | break; | |
8745 | ||
8746 | case 'R': | |
8747 | if (regno != RA) | |
8748 | regno = ILLEGAL_REG; | |
8749 | break; | |
8750 | ||
8751 | case 'X': | |
8752 | case 'Y': | |
8753 | if (regno == AT && ! mips_opts.noat) | |
8754 | as_warn (_("used $at without \".set noat\"")); | |
8755 | break; | |
8756 | ||
8757 | default: | |
8758 | internalError (); | |
8759 | } | |
8760 | ||
8761 | if (regno == ILLEGAL_REG) | |
8762 | break; | |
8763 | ||
8764 | switch (c) | |
8765 | { | |
8766 | case 'x': | |
8767 | case 'v': | |
8768 | ip->insn_opcode |= regno << MIPS16OP_SH_RX; | |
8769 | break; | |
8770 | case 'y': | |
8771 | case 'w': | |
8772 | ip->insn_opcode |= regno << MIPS16OP_SH_RY; | |
8773 | break; | |
8774 | case 'z': | |
8775 | ip->insn_opcode |= regno << MIPS16OP_SH_RZ; | |
8776 | break; | |
8777 | case 'Z': | |
8778 | ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z; | |
8779 | case '0': | |
8780 | case 'S': | |
8781 | case 'R': | |
8782 | break; | |
8783 | case 'X': | |
8784 | ip->insn_opcode |= regno << MIPS16OP_SH_REGR32; | |
8785 | break; | |
8786 | case 'Y': | |
8787 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
8788 | ip->insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
8789 | break; | |
8790 | default: | |
8791 | internalError (); | |
8792 | } | |
8793 | ||
8794 | lastregno = regno; | |
8795 | continue; | |
8796 | ||
8797 | case 'P': | |
8798 | if (strncmp (s, "$pc", 3) == 0) | |
8799 | { | |
8800 | s += 3; | |
8801 | continue; | |
8802 | } | |
8803 | break; | |
8804 | ||
8805 | case '<': | |
8806 | case '>': | |
8807 | case '[': | |
8808 | case ']': | |
8809 | case '4': | |
8810 | case '5': | |
8811 | case 'H': | |
8812 | case 'W': | |
8813 | case 'D': | |
8814 | case 'j': | |
8815 | case '8': | |
8816 | case 'V': | |
8817 | case 'C': | |
8818 | case 'U': | |
8819 | case 'k': | |
8820 | case 'K': | |
8821 | if (s[0] == '%' | |
8822 | && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0) | |
8823 | { | |
8824 | /* This is %gprel(SYMBOL). We need to read SYMBOL, | |
8825 | and generate the appropriate reloc. If the text | |
8826 | inside %gprel is not a symbol name with an | |
8827 | optional offset, then we generate a normal reloc | |
8828 | and will probably fail later. */ | |
8829 | my_getExpression (&imm_expr, s + sizeof "%gprel" - 1); | |
8830 | if (imm_expr.X_op == O_symbol) | |
8831 | { | |
8832 | mips16_ext = true; | |
f6688943 | 8833 | *imm_reloc = BFD_RELOC_MIPS16_GPREL; |
252b5132 RH |
8834 | s = expr_end; |
8835 | ip->use_extend = true; | |
8836 | ip->extend = 0; | |
8837 | continue; | |
8838 | } | |
8839 | } | |
8840 | else | |
8841 | { | |
8842 | /* Just pick up a normal expression. */ | |
8843 | my_getExpression (&imm_expr, s); | |
8844 | } | |
8845 | ||
8846 | if (imm_expr.X_op == O_register) | |
8847 | { | |
8848 | /* What we thought was an expression turned out to | |
8849 | be a register. */ | |
8850 | ||
8851 | if (s[0] == '(' && args[1] == '(') | |
8852 | { | |
8853 | /* It looks like the expression was omitted | |
8854 | before a register indirection, which means | |
8855 | that the expression is implicitly zero. We | |
8856 | still set up imm_expr, so that we handle | |
8857 | explicit extensions correctly. */ | |
8858 | imm_expr.X_op = O_constant; | |
8859 | imm_expr.X_add_number = 0; | |
f6688943 | 8860 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
8861 | continue; |
8862 | } | |
8863 | ||
8864 | break; | |
8865 | } | |
8866 | ||
8867 | /* We need to relax this instruction. */ | |
f6688943 | 8868 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
8869 | s = expr_end; |
8870 | continue; | |
8871 | ||
8872 | case 'p': | |
8873 | case 'q': | |
8874 | case 'A': | |
8875 | case 'B': | |
8876 | case 'E': | |
8877 | /* We use offset_reloc rather than imm_reloc for the PC | |
8878 | relative operands. This lets macros with both | |
8879 | immediate and address operands work correctly. */ | |
8880 | my_getExpression (&offset_expr, s); | |
8881 | ||
8882 | if (offset_expr.X_op == O_register) | |
8883 | break; | |
8884 | ||
8885 | /* We need to relax this instruction. */ | |
f6688943 | 8886 | *offset_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
8887 | s = expr_end; |
8888 | continue; | |
8889 | ||
8890 | case '6': /* break code */ | |
8891 | my_getExpression (&imm_expr, s); | |
8892 | check_absolute_expr (ip, &imm_expr); | |
8893 | if ((unsigned long) imm_expr.X_add_number > 63) | |
8894 | { | |
8895 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8896 | ip->insn_mo->name, | |
8897 | (unsigned long) imm_expr.X_add_number); | |
8898 | imm_expr.X_add_number &= 0x3f; | |
8899 | } | |
8900 | ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6; | |
8901 | imm_expr.X_op = O_absent; | |
8902 | s = expr_end; | |
8903 | continue; | |
8904 | ||
8905 | case 'a': /* 26 bit address */ | |
8906 | my_getExpression (&offset_expr, s); | |
8907 | s = expr_end; | |
f6688943 | 8908 | *offset_reloc = BFD_RELOC_MIPS16_JMP; |
252b5132 RH |
8909 | ip->insn_opcode <<= 16; |
8910 | continue; | |
8911 | ||
8912 | case 'l': /* register list for entry macro */ | |
8913 | case 'L': /* register list for exit macro */ | |
8914 | { | |
8915 | int mask; | |
8916 | ||
8917 | if (c == 'l') | |
8918 | mask = 0; | |
8919 | else | |
8920 | mask = 7 << 3; | |
8921 | while (*s != '\0') | |
8922 | { | |
8923 | int freg, reg1, reg2; | |
8924 | ||
8925 | while (*s == ' ' || *s == ',') | |
8926 | ++s; | |
8927 | if (*s != '$') | |
8928 | { | |
8929 | as_bad (_("can't parse register list")); | |
8930 | break; | |
8931 | } | |
8932 | ++s; | |
8933 | if (*s != 'f') | |
8934 | freg = 0; | |
8935 | else | |
8936 | { | |
8937 | freg = 1; | |
8938 | ++s; | |
8939 | } | |
8940 | reg1 = 0; | |
3882b010 | 8941 | while (ISDIGIT (*s)) |
252b5132 RH |
8942 | { |
8943 | reg1 *= 10; | |
8944 | reg1 += *s - '0'; | |
8945 | ++s; | |
8946 | } | |
8947 | if (*s == ' ') | |
8948 | ++s; | |
8949 | if (*s != '-') | |
8950 | reg2 = reg1; | |
8951 | else | |
8952 | { | |
8953 | ++s; | |
8954 | if (*s != '$') | |
8955 | break; | |
8956 | ++s; | |
8957 | if (freg) | |
8958 | { | |
8959 | if (*s == 'f') | |
8960 | ++s; | |
8961 | else | |
8962 | { | |
8963 | as_bad (_("invalid register list")); | |
8964 | break; | |
8965 | } | |
8966 | } | |
8967 | reg2 = 0; | |
3882b010 | 8968 | while (ISDIGIT (*s)) |
252b5132 RH |
8969 | { |
8970 | reg2 *= 10; | |
8971 | reg2 += *s - '0'; | |
8972 | ++s; | |
8973 | } | |
8974 | } | |
8975 | if (freg && reg1 == 0 && reg2 == 0 && c == 'L') | |
8976 | { | |
8977 | mask &= ~ (7 << 3); | |
8978 | mask |= 5 << 3; | |
8979 | } | |
8980 | else if (freg && reg1 == 0 && reg2 == 1 && c == 'L') | |
8981 | { | |
8982 | mask &= ~ (7 << 3); | |
8983 | mask |= 6 << 3; | |
8984 | } | |
8985 | else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L') | |
8986 | mask |= (reg2 - 3) << 3; | |
8987 | else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17) | |
8988 | mask |= (reg2 - 15) << 1; | |
8989 | else if (reg1 == 31 && reg2 == 31) | |
8990 | mask |= 1; | |
8991 | else | |
8992 | { | |
8993 | as_bad (_("invalid register list")); | |
8994 | break; | |
8995 | } | |
8996 | } | |
8997 | /* The mask is filled in in the opcode table for the | |
8998 | benefit of the disassembler. We remove it before | |
8999 | applying the actual mask. */ | |
9000 | ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6); | |
9001 | ip->insn_opcode |= mask << MIPS16OP_SH_IMM6; | |
9002 | } | |
9003 | continue; | |
9004 | ||
9005 | case 'e': /* extend code */ | |
9006 | my_getExpression (&imm_expr, s); | |
9007 | check_absolute_expr (ip, &imm_expr); | |
9008 | if ((unsigned long) imm_expr.X_add_number > 0x7ff) | |
9009 | { | |
9010 | as_warn (_("Invalid value for `%s' (%lu)"), | |
9011 | ip->insn_mo->name, | |
9012 | (unsigned long) imm_expr.X_add_number); | |
9013 | imm_expr.X_add_number &= 0x7ff; | |
9014 | } | |
9015 | ip->insn_opcode |= imm_expr.X_add_number; | |
9016 | imm_expr.X_op = O_absent; | |
9017 | s = expr_end; | |
9018 | continue; | |
9019 | ||
9020 | default: | |
9021 | internalError (); | |
9022 | } | |
9023 | break; | |
9024 | } | |
9025 | ||
9026 | /* Args don't match. */ | |
9027 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] && | |
9028 | strcmp (insn->name, insn[1].name) == 0) | |
9029 | { | |
9030 | ++insn; | |
9031 | s = argsstart; | |
9032 | continue; | |
9033 | } | |
9034 | ||
9035 | insn_error = _("illegal operands"); | |
9036 | ||
9037 | return; | |
9038 | } | |
9039 | } | |
9040 | ||
9041 | /* This structure holds information we know about a mips16 immediate | |
9042 | argument type. */ | |
9043 | ||
e972090a NC |
9044 | struct mips16_immed_operand |
9045 | { | |
252b5132 RH |
9046 | /* The type code used in the argument string in the opcode table. */ |
9047 | int type; | |
9048 | /* The number of bits in the short form of the opcode. */ | |
9049 | int nbits; | |
9050 | /* The number of bits in the extended form of the opcode. */ | |
9051 | int extbits; | |
9052 | /* The amount by which the short form is shifted when it is used; | |
9053 | for example, the sw instruction has a shift count of 2. */ | |
9054 | int shift; | |
9055 | /* The amount by which the short form is shifted when it is stored | |
9056 | into the instruction code. */ | |
9057 | int op_shift; | |
9058 | /* Non-zero if the short form is unsigned. */ | |
9059 | int unsp; | |
9060 | /* Non-zero if the extended form is unsigned. */ | |
9061 | int extu; | |
9062 | /* Non-zero if the value is PC relative. */ | |
9063 | int pcrel; | |
9064 | }; | |
9065 | ||
9066 | /* The mips16 immediate operand types. */ | |
9067 | ||
9068 | static const struct mips16_immed_operand mips16_immed_operands[] = | |
9069 | { | |
9070 | { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
9071 | { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
9072 | { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
9073 | { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
9074 | { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 }, | |
9075 | { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9076 | { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9077 | { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9078 | { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9079 | { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 }, | |
9080 | { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9081 | { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9082 | { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9083 | { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 }, | |
9084 | { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
9085 | { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
9086 | { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
9087 | { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
9088 | { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 }, | |
9089 | { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 }, | |
9090 | { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 } | |
9091 | }; | |
9092 | ||
9093 | #define MIPS16_NUM_IMMED \ | |
9094 | (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0]) | |
9095 | ||
9096 | /* Handle a mips16 instruction with an immediate value. This or's the | |
9097 | small immediate value into *INSN. It sets *USE_EXTEND to indicate | |
9098 | whether an extended value is needed; if one is needed, it sets | |
9099 | *EXTEND to the value. The argument type is TYPE. The value is VAL. | |
9100 | If SMALL is true, an unextended opcode was explicitly requested. | |
9101 | If EXT is true, an extended opcode was explicitly requested. If | |
9102 | WARN is true, warn if EXT does not match reality. */ | |
9103 | ||
9104 | static void | |
9105 | mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend, | |
9106 | extend) | |
9107 | char *file; | |
9108 | unsigned int line; | |
9109 | int type; | |
9110 | offsetT val; | |
9111 | boolean warn; | |
9112 | boolean small; | |
9113 | boolean ext; | |
9114 | unsigned long *insn; | |
9115 | boolean *use_extend; | |
9116 | unsigned short *extend; | |
9117 | { | |
9118 | register const struct mips16_immed_operand *op; | |
9119 | int mintiny, maxtiny; | |
9120 | boolean needext; | |
9121 | ||
9122 | op = mips16_immed_operands; | |
9123 | while (op->type != type) | |
9124 | { | |
9125 | ++op; | |
9126 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
9127 | } | |
9128 | ||
9129 | if (op->unsp) | |
9130 | { | |
9131 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
9132 | { | |
9133 | mintiny = 1; | |
9134 | maxtiny = 1 << op->nbits; | |
9135 | } | |
9136 | else | |
9137 | { | |
9138 | mintiny = 0; | |
9139 | maxtiny = (1 << op->nbits) - 1; | |
9140 | } | |
9141 | } | |
9142 | else | |
9143 | { | |
9144 | mintiny = - (1 << (op->nbits - 1)); | |
9145 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
9146 | } | |
9147 | ||
9148 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
9149 | if (type == 'p' || type == 'q') | |
9150 | val /= 2; | |
9151 | ||
9152 | if ((val & ((1 << op->shift) - 1)) != 0 | |
9153 | || val < (mintiny << op->shift) | |
9154 | || val > (maxtiny << op->shift)) | |
9155 | needext = true; | |
9156 | else | |
9157 | needext = false; | |
9158 | ||
9159 | if (warn && ext && ! needext) | |
beae10d5 KH |
9160 | as_warn_where (file, line, |
9161 | _("extended operand requested but not required")); | |
252b5132 RH |
9162 | if (small && needext) |
9163 | as_bad_where (file, line, _("invalid unextended operand value")); | |
9164 | ||
9165 | if (small || (! ext && ! needext)) | |
9166 | { | |
9167 | int insnval; | |
9168 | ||
9169 | *use_extend = false; | |
9170 | insnval = ((val >> op->shift) & ((1 << op->nbits) - 1)); | |
9171 | insnval <<= op->op_shift; | |
9172 | *insn |= insnval; | |
9173 | } | |
9174 | else | |
9175 | { | |
9176 | long minext, maxext; | |
9177 | int extval; | |
9178 | ||
9179 | if (op->extu) | |
9180 | { | |
9181 | minext = 0; | |
9182 | maxext = (1 << op->extbits) - 1; | |
9183 | } | |
9184 | else | |
9185 | { | |
9186 | minext = - (1 << (op->extbits - 1)); | |
9187 | maxext = (1 << (op->extbits - 1)) - 1; | |
9188 | } | |
9189 | if (val < minext || val > maxext) | |
9190 | as_bad_where (file, line, | |
9191 | _("operand value out of range for instruction")); | |
9192 | ||
9193 | *use_extend = true; | |
9194 | if (op->extbits == 16) | |
9195 | { | |
9196 | extval = ((val >> 11) & 0x1f) | (val & 0x7e0); | |
9197 | val &= 0x1f; | |
9198 | } | |
9199 | else if (op->extbits == 15) | |
9200 | { | |
9201 | extval = ((val >> 11) & 0xf) | (val & 0x7f0); | |
9202 | val &= 0xf; | |
9203 | } | |
9204 | else | |
9205 | { | |
9206 | extval = ((val & 0x1f) << 6) | (val & 0x20); | |
9207 | val = 0; | |
9208 | } | |
9209 | ||
9210 | *extend = (unsigned short) extval; | |
9211 | *insn |= val; | |
9212 | } | |
9213 | } | |
9214 | \f | |
ad8d3bb3 TS |
9215 | static struct percent_op_match |
9216 | { | |
9217 | const char *str; | |
9218 | const enum small_ex_type type; | |
9219 | } percent_op[] = | |
9220 | { | |
9221 | #ifdef OBJ_ELF | |
9222 | {"%half", S_EX_HALF}, | |
9223 | #endif | |
9224 | {"%hi", S_EX_HI}, | |
9225 | {"%lo", S_EX_LO}, | |
9226 | #ifdef OBJ_ELF | |
9227 | {"%gp_rel", S_EX_GP_REL}, | |
9228 | {"%got", S_EX_GOT}, | |
9229 | {"%call16", S_EX_CALL16}, | |
9230 | {"%got_disp", S_EX_GOT_DISP}, | |
9231 | {"%got_page", S_EX_GOT_PAGE}, | |
9232 | {"%got_ofst", S_EX_GOT_OFST}, | |
9233 | {"%got_hi", S_EX_GOT_HI}, | |
9234 | {"%got_lo", S_EX_GOT_LO}, | |
9235 | {"%neg", S_EX_NEG}, | |
9236 | {"%higher", S_EX_HIGHER}, | |
9237 | {"%highest", S_EX_HIGHEST}, | |
9238 | {"%call_hi", S_EX_CALL_HI}, | |
9239 | {"%call_lo", S_EX_CALL_LO} | |
9240 | #endif | |
9241 | }; | |
9242 | ||
9243 | /* Parse small expression input. STR gets adjusted to eat up whitespace. | |
9244 | It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's | |
9245 | can be nested, this is handled by blanking the innermost, parsing the | |
9246 | rest by subsequent calls. */ | |
252b5132 RH |
9247 | |
9248 | static int | |
ad8d3bb3 TS |
9249 | my_getSmallParser (str, len, nestlevel) |
9250 | char **str; | |
9251 | unsigned int *len; | |
9252 | int *nestlevel; | |
252b5132 | 9253 | { |
ad8d3bb3 | 9254 | int type = S_EX_NONE; |
252b5132 | 9255 | |
ad8d3bb3 TS |
9256 | *len = 0; |
9257 | *str += strspn (*str, " \t"); | |
9258 | if (**str == '(') | |
252b5132 | 9259 | { |
ad8d3bb3 TS |
9260 | char *b = *str + 1 + strspn (*str + 1, " \t"); |
9261 | char *e; | |
9262 | ||
9263 | /* Check for base register. */ | |
9264 | if (b[0] == '$') | |
9265 | { | |
9266 | if (strchr (b, ')') | |
9267 | && (e = b + strcspn (b, ") \t")) | |
9268 | && e - b > 1 && e - b < 4) | |
9269 | { | |
9270 | if ((e - b == 3 | |
9271 | && ((b[1] == 'f' && b[2] == 'p') | |
9272 | || (b[1] == 's' && b[2] == 'p') | |
9273 | || (b[1] == 'g' && b[2] == 'p') | |
9274 | || (b[1] == 'a' && b[2] == 't') | |
9275 | || (ISDIGIT (b[1]) | |
9276 | && ISDIGIT (b[2])))) | |
9277 | || (ISDIGIT (b[1]))) | |
9278 | { | |
9279 | *len = strcspn (*str, ")") + 1; | |
9280 | return S_EX_REGISTER; | |
9281 | } | |
9282 | } | |
9283 | } | |
9284 | else if (b[0] == '%') | |
9285 | { | |
9286 | *str = b; | |
9287 | goto percent_op; | |
9288 | } | |
76b3015f EC |
9289 | |
9290 | /* Some other expression in the braces. */ | |
9291 | *len = strcspn (*str, ")") + 1; | |
fb1b3232 | 9292 | } |
ad8d3bb3 TS |
9293 | /* Check for percent_op. */ |
9294 | else if (*str[0] == '%') | |
fb1b3232 | 9295 | { |
ad8d3bb3 TS |
9296 | char *tmp; |
9297 | unsigned int i; | |
9298 | ||
9299 | percent_op: | |
9300 | tmp = *str + 1; | |
9301 | i = 0; | |
9302 | ||
9303 | while (ISALPHA (*tmp) || *tmp == '_') | |
9304 | { | |
9305 | *tmp = TOLOWER (*tmp); | |
9306 | tmp++; | |
9307 | } | |
9308 | while (i < (sizeof (percent_op) / sizeof (struct percent_op_match))) | |
9309 | { | |
9310 | if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str))) | |
9311 | i++; | |
9312 | else | |
9313 | { | |
9314 | type = percent_op[i].type; | |
9315 | ||
9316 | /* Only %hi and %lo are allowed for OldABI. */ | |
9317 | if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO) | |
9318 | return S_EX_NONE; | |
9319 | ||
9320 | *len = strlen (percent_op[i].str); | |
9321 | (*nestlevel)++; | |
9322 | return type; | |
9323 | } | |
9324 | } | |
fb1b3232 | 9325 | } |
ad8d3bb3 TS |
9326 | |
9327 | /* Any other expression. */ | |
9328 | return S_EX_NONE; | |
9329 | } | |
9330 | ||
9331 | static int | |
9332 | my_getSmallExpression (ep, str) | |
9333 | expressionS *ep; | |
9334 | char *str; | |
9335 | { | |
9336 | static char *oldstr = NULL; | |
9337 | int c = S_EX_NONE; | |
9338 | int oldc; | |
9339 | int nest_level = 0; | |
9340 | unsigned int len; | |
9341 | ||
9342 | /* Don't update oldstr if the last call had nested percent_op's. */ | |
9343 | if (! oldstr) | |
9344 | oldstr = str; | |
76b3015f | 9345 | |
ad8d3bb3 | 9346 | do |
fb1b3232 | 9347 | { |
ad8d3bb3 TS |
9348 | oldc = c; |
9349 | c = my_getSmallParser (&str, &len, &nest_level); | |
9350 | if (c != S_EX_NONE && c != S_EX_REGISTER) | |
9351 | str += len; | |
fb1b3232 | 9352 | } |
ad8d3bb3 TS |
9353 | while (c != S_EX_NONE && c != S_EX_REGISTER); |
9354 | ||
9355 | /* A percent_op was encountered. */ | |
9356 | if (nest_level) | |
fb1b3232 | 9357 | { |
b6ff326e | 9358 | /* Don't try to get an expression if it is already blanked out. */ |
ad8d3bb3 TS |
9359 | if (*(str + strspn (str + 1, " )")) != ')') |
9360 | { | |
9361 | char save; | |
9362 | ||
9363 | save = *(str + len); | |
9364 | *(str + len) = '\0'; | |
9365 | my_getExpression (ep, str); | |
9366 | *(str + len) = save; | |
9367 | } | |
9368 | if (nest_level > 1) | |
9369 | { | |
9370 | /* blank out including the % sign. */ | |
9371 | char *p = strrchr (oldstr, '%'); | |
9372 | memset (p, ' ', str - p + len); | |
9373 | str = oldstr; | |
9374 | } | |
9375 | else | |
9376 | { | |
9377 | expr_end = strchr (str, ')') + 1; | |
9378 | } | |
9379 | c = oldc; | |
fb1b3232 | 9380 | } |
ad8d3bb3 | 9381 | else if (c == S_EX_NONE) |
fb1b3232 | 9382 | { |
ad8d3bb3 | 9383 | my_getExpression (ep, str); |
fb1b3232 | 9384 | } |
ad8d3bb3 | 9385 | else if (c == S_EX_REGISTER) |
fb1b3232 | 9386 | { |
ad8d3bb3 TS |
9387 | ep->X_op = O_constant; |
9388 | expr_end = str; | |
9389 | ep->X_add_symbol = NULL; | |
9390 | ep->X_op_symbol = NULL; | |
9391 | ep->X_add_number = 0; | |
fb1b3232 | 9392 | } |
fb1b3232 TS |
9393 | else |
9394 | { | |
ad8d3bb3 | 9395 | as_fatal(_("internal error")); |
fb1b3232 | 9396 | } |
252b5132 | 9397 | |
ad8d3bb3 TS |
9398 | if (nest_level <= 1) |
9399 | oldstr = NULL; | |
fb1b3232 | 9400 | |
fb1b3232 | 9401 | return c; |
252b5132 RH |
9402 | } |
9403 | ||
9404 | static void | |
9405 | my_getExpression (ep, str) | |
9406 | expressionS *ep; | |
9407 | char *str; | |
9408 | { | |
9409 | char *save_in; | |
98aa84af | 9410 | valueT val; |
252b5132 RH |
9411 | |
9412 | save_in = input_line_pointer; | |
9413 | input_line_pointer = str; | |
9414 | expression (ep); | |
9415 | expr_end = input_line_pointer; | |
9416 | input_line_pointer = save_in; | |
9417 | ||
9418 | /* If we are in mips16 mode, and this is an expression based on `.', | |
9419 | then we bump the value of the symbol by 1 since that is how other | |
9420 | text symbols are handled. We don't bother to handle complex | |
9421 | expressions, just `.' plus or minus a constant. */ | |
9422 | if (mips_opts.mips16 | |
9423 | && ep->X_op == O_symbol | |
9424 | && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0 | |
9425 | && S_GET_SEGMENT (ep->X_add_symbol) == now_seg | |
49309057 ILT |
9426 | && symbol_get_frag (ep->X_add_symbol) == frag_now |
9427 | && symbol_constant_p (ep->X_add_symbol) | |
98aa84af AM |
9428 | && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ()) |
9429 | S_SET_VALUE (ep->X_add_symbol, val + 1); | |
252b5132 RH |
9430 | } |
9431 | ||
9432 | /* Turn a string in input_line_pointer into a floating point constant | |
bc0d738a NC |
9433 | of type TYPE, and store the appropriate bytes in *LITP. The number |
9434 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
252b5132 RH |
9435 | returned, or NULL on OK. */ |
9436 | ||
9437 | char * | |
9438 | md_atof (type, litP, sizeP) | |
9439 | int type; | |
9440 | char *litP; | |
9441 | int *sizeP; | |
9442 | { | |
9443 | int prec; | |
9444 | LITTLENUM_TYPE words[4]; | |
9445 | char *t; | |
9446 | int i; | |
9447 | ||
9448 | switch (type) | |
9449 | { | |
9450 | case 'f': | |
9451 | prec = 2; | |
9452 | break; | |
9453 | ||
9454 | case 'd': | |
9455 | prec = 4; | |
9456 | break; | |
9457 | ||
9458 | default: | |
9459 | *sizeP = 0; | |
9460 | return _("bad call to md_atof"); | |
9461 | } | |
9462 | ||
9463 | t = atof_ieee (input_line_pointer, type, words); | |
9464 | if (t) | |
9465 | input_line_pointer = t; | |
9466 | ||
9467 | *sizeP = prec * 2; | |
9468 | ||
9469 | if (! target_big_endian) | |
9470 | { | |
9471 | for (i = prec - 1; i >= 0; i--) | |
9472 | { | |
9473 | md_number_to_chars (litP, (valueT) words[i], 2); | |
9474 | litP += 2; | |
9475 | } | |
9476 | } | |
9477 | else | |
9478 | { | |
9479 | for (i = 0; i < prec; i++) | |
9480 | { | |
9481 | md_number_to_chars (litP, (valueT) words[i], 2); | |
9482 | litP += 2; | |
9483 | } | |
9484 | } | |
bdaaa2e1 | 9485 | |
252b5132 RH |
9486 | return NULL; |
9487 | } | |
9488 | ||
9489 | void | |
9490 | md_number_to_chars (buf, val, n) | |
9491 | char *buf; | |
9492 | valueT val; | |
9493 | int n; | |
9494 | { | |
9495 | if (target_big_endian) | |
9496 | number_to_chars_bigendian (buf, val, n); | |
9497 | else | |
9498 | number_to_chars_littleendian (buf, val, n); | |
9499 | } | |
9500 | \f | |
ae948b86 | 9501 | #ifdef OBJ_ELF |
e013f690 TS |
9502 | static int support_64bit_objects(void) |
9503 | { | |
9504 | const char **list, **l; | |
9505 | ||
9506 | list = bfd_target_list (); | |
9507 | for (l = list; *l != NULL; l++) | |
9508 | #ifdef TE_TMIPS | |
9509 | /* This is traditional mips */ | |
9510 | if (strcmp (*l, "elf64-tradbigmips") == 0 | |
9511 | || strcmp (*l, "elf64-tradlittlemips") == 0) | |
9512 | #else | |
9513 | if (strcmp (*l, "elf64-bigmips") == 0 | |
9514 | || strcmp (*l, "elf64-littlemips") == 0) | |
9515 | #endif | |
9516 | break; | |
9517 | free (list); | |
9518 | return (*l != NULL); | |
9519 | } | |
ae948b86 | 9520 | #endif /* OBJ_ELF */ |
e013f690 | 9521 | |
39c0a331 | 9522 | CONST char *md_shortopts = "nO::g::G:"; |
252b5132 | 9523 | |
e972090a NC |
9524 | struct option md_longopts[] = |
9525 | { | |
252b5132 RH |
9526 | #define OPTION_MIPS1 (OPTION_MD_BASE + 1) |
9527 | {"mips0", no_argument, NULL, OPTION_MIPS1}, | |
9528 | {"mips1", no_argument, NULL, OPTION_MIPS1}, | |
9529 | #define OPTION_MIPS2 (OPTION_MD_BASE + 2) | |
9530 | {"mips2", no_argument, NULL, OPTION_MIPS2}, | |
9531 | #define OPTION_MIPS3 (OPTION_MD_BASE + 3) | |
9532 | {"mips3", no_argument, NULL, OPTION_MIPS3}, | |
9533 | #define OPTION_MIPS4 (OPTION_MD_BASE + 4) | |
9534 | {"mips4", no_argument, NULL, OPTION_MIPS4}, | |
ae948b86 TS |
9535 | #define OPTION_MIPS5 (OPTION_MD_BASE + 5) |
9536 | {"mips5", no_argument, NULL, OPTION_MIPS5}, | |
9537 | #define OPTION_MIPS32 (OPTION_MD_BASE + 6) | |
9538 | {"mips32", no_argument, NULL, OPTION_MIPS32}, | |
9539 | #define OPTION_MIPS64 (OPTION_MD_BASE + 7) | |
9540 | {"mips64", no_argument, NULL, OPTION_MIPS64}, | |
9541 | #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8) | |
252b5132 | 9542 | {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC}, |
ae948b86 | 9543 | #define OPTION_TRAP (OPTION_MD_BASE + 9) |
252b5132 RH |
9544 | {"trap", no_argument, NULL, OPTION_TRAP}, |
9545 | {"no-break", no_argument, NULL, OPTION_TRAP}, | |
ae948b86 | 9546 | #define OPTION_BREAK (OPTION_MD_BASE + 10) |
252b5132 RH |
9547 | {"break", no_argument, NULL, OPTION_BREAK}, |
9548 | {"no-trap", no_argument, NULL, OPTION_BREAK}, | |
ae948b86 | 9549 | #define OPTION_EB (OPTION_MD_BASE + 11) |
252b5132 | 9550 | {"EB", no_argument, NULL, OPTION_EB}, |
ae948b86 | 9551 | #define OPTION_EL (OPTION_MD_BASE + 12) |
252b5132 | 9552 | {"EL", no_argument, NULL, OPTION_EL}, |
ae948b86 | 9553 | #define OPTION_MIPS16 (OPTION_MD_BASE + 13) |
252b5132 | 9554 | {"mips16", no_argument, NULL, OPTION_MIPS16}, |
ae948b86 | 9555 | #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14) |
252b5132 | 9556 | {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16}, |
ae948b86 | 9557 | #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15) |
6b76fefe | 9558 | {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX}, |
ae948b86 | 9559 | #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 16) |
6b76fefe | 9560 | {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX}, |
ae948b86 TS |
9561 | #define OPTION_FP32 (OPTION_MD_BASE + 17) |
9562 | {"mfp32", no_argument, NULL, OPTION_FP32}, | |
9563 | #define OPTION_GP32 (OPTION_MD_BASE + 18) | |
c97ef257 | 9564 | {"mgp32", no_argument, NULL, OPTION_GP32}, |
ae948b86 | 9565 | #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19) |
119d663a | 9566 | {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS}, |
ae948b86 | 9567 | #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20) |
119d663a | 9568 | {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS}, |
ae948b86 | 9569 | #define OPTION_MARCH (OPTION_MD_BASE + 21) |
ec68c924 | 9570 | {"march", required_argument, NULL, OPTION_MARCH}, |
ae948b86 | 9571 | #define OPTION_MTUNE (OPTION_MD_BASE + 22) |
ec68c924 | 9572 | {"mtune", required_argument, NULL, OPTION_MTUNE}, |
ae948b86 TS |
9573 | #define OPTION_MCPU (OPTION_MD_BASE + 23) |
9574 | {"mcpu", required_argument, NULL, OPTION_MCPU}, | |
9575 | #define OPTION_M4650 (OPTION_MD_BASE + 24) | |
9576 | {"m4650", no_argument, NULL, OPTION_M4650}, | |
9577 | #define OPTION_NO_M4650 (OPTION_MD_BASE + 25) | |
9578 | {"no-m4650", no_argument, NULL, OPTION_NO_M4650}, | |
9579 | #define OPTION_M4010 (OPTION_MD_BASE + 26) | |
9580 | {"m4010", no_argument, NULL, OPTION_M4010}, | |
9581 | #define OPTION_NO_M4010 (OPTION_MD_BASE + 27) | |
9582 | {"no-m4010", no_argument, NULL, OPTION_NO_M4010}, | |
9583 | #define OPTION_M4100 (OPTION_MD_BASE + 28) | |
9584 | {"m4100", no_argument, NULL, OPTION_M4100}, | |
9585 | #define OPTION_NO_M4100 (OPTION_MD_BASE + 29) | |
9586 | {"no-m4100", no_argument, NULL, OPTION_NO_M4100}, | |
9587 | #define OPTION_M3900 (OPTION_MD_BASE + 30) | |
9588 | {"m3900", no_argument, NULL, OPTION_M3900}, | |
9589 | #define OPTION_NO_M3900 (OPTION_MD_BASE + 31) | |
9590 | {"no-m3900", no_argument, NULL, OPTION_NO_M3900}, | |
9591 | #define OPTION_GP64 (OPTION_MD_BASE + 32) | |
9592 | {"mgp64", no_argument, NULL, OPTION_GP64}, | |
156c2f8b | 9593 | #ifdef OBJ_ELF |
ae948b86 | 9594 | #define OPTION_ELF_BASE (OPTION_MD_BASE + 33) |
156c2f8b | 9595 | #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0) |
156c2f8b NC |
9596 | {"KPIC", no_argument, NULL, OPTION_CALL_SHARED}, |
9597 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, | |
ae948b86 | 9598 | #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1) |
156c2f8b | 9599 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, |
ae948b86 | 9600 | #define OPTION_XGOT (OPTION_ELF_BASE + 2) |
156c2f8b | 9601 | {"xgot", no_argument, NULL, OPTION_XGOT}, |
ae948b86 TS |
9602 | #define OPTION_MABI (OPTION_ELF_BASE + 3) |
9603 | {"mabi", required_argument, NULL, OPTION_MABI}, | |
9604 | #define OPTION_32 (OPTION_ELF_BASE + 4) | |
156c2f8b | 9605 | {"32", no_argument, NULL, OPTION_32}, |
ae948b86 | 9606 | #define OPTION_N32 (OPTION_ELF_BASE + 5) |
e013f690 | 9607 | {"n32", no_argument, NULL, OPTION_N32}, |
ae948b86 | 9608 | #define OPTION_64 (OPTION_ELF_BASE + 6) |
156c2f8b | 9609 | {"64", no_argument, NULL, OPTION_64}, |
ae948b86 | 9610 | #endif /* OBJ_ELF */ |
252b5132 RH |
9611 | {NULL, no_argument, NULL, 0} |
9612 | }; | |
156c2f8b | 9613 | size_t md_longopts_size = sizeof (md_longopts); |
252b5132 RH |
9614 | |
9615 | int | |
9616 | md_parse_option (c, arg) | |
9617 | int c; | |
9618 | char *arg; | |
9619 | { | |
9620 | switch (c) | |
9621 | { | |
119d663a NC |
9622 | case OPTION_CONSTRUCT_FLOATS: |
9623 | mips_disable_float_construction = 0; | |
9624 | break; | |
bdaaa2e1 | 9625 | |
119d663a NC |
9626 | case OPTION_NO_CONSTRUCT_FLOATS: |
9627 | mips_disable_float_construction = 1; | |
9628 | break; | |
bdaaa2e1 | 9629 | |
252b5132 RH |
9630 | case OPTION_TRAP: |
9631 | mips_trap = 1; | |
9632 | break; | |
9633 | ||
9634 | case OPTION_BREAK: | |
9635 | mips_trap = 0; | |
9636 | break; | |
9637 | ||
9638 | case OPTION_EB: | |
9639 | target_big_endian = 1; | |
9640 | break; | |
9641 | ||
9642 | case OPTION_EL: | |
9643 | target_big_endian = 0; | |
9644 | break; | |
9645 | ||
39c0a331 L |
9646 | case 'n': |
9647 | warn_nops = 1; | |
9648 | break; | |
9649 | ||
252b5132 RH |
9650 | case 'O': |
9651 | if (arg && arg[1] == '0') | |
9652 | mips_optimize = 1; | |
9653 | else | |
9654 | mips_optimize = 2; | |
9655 | break; | |
9656 | ||
9657 | case 'g': | |
9658 | if (arg == NULL) | |
9659 | mips_debug = 2; | |
9660 | else | |
9661 | mips_debug = atoi (arg); | |
9662 | /* When the MIPS assembler sees -g or -g2, it does not do | |
9663 | optimizations which limit full symbolic debugging. We take | |
9664 | that to be equivalent to -O0. */ | |
9665 | if (mips_debug == 2) | |
9666 | mips_optimize = 1; | |
9667 | break; | |
9668 | ||
9669 | case OPTION_MIPS1: | |
e7af610e | 9670 | mips_opts.isa = ISA_MIPS1; |
252b5132 RH |
9671 | break; |
9672 | ||
9673 | case OPTION_MIPS2: | |
e7af610e | 9674 | mips_opts.isa = ISA_MIPS2; |
252b5132 RH |
9675 | break; |
9676 | ||
9677 | case OPTION_MIPS3: | |
e7af610e | 9678 | mips_opts.isa = ISA_MIPS3; |
252b5132 RH |
9679 | break; |
9680 | ||
9681 | case OPTION_MIPS4: | |
e7af610e NC |
9682 | mips_opts.isa = ISA_MIPS4; |
9683 | break; | |
9684 | ||
84ea6cf2 NC |
9685 | case OPTION_MIPS5: |
9686 | mips_opts.isa = ISA_MIPS5; | |
9687 | break; | |
9688 | ||
e7af610e NC |
9689 | case OPTION_MIPS32: |
9690 | mips_opts.isa = ISA_MIPS32; | |
252b5132 RH |
9691 | break; |
9692 | ||
84ea6cf2 NC |
9693 | case OPTION_MIPS64: |
9694 | mips_opts.isa = ISA_MIPS64; | |
9695 | break; | |
9696 | ||
ec68c924 EC |
9697 | case OPTION_MTUNE: |
9698 | case OPTION_MARCH: | |
252b5132 RH |
9699 | case OPTION_MCPU: |
9700 | { | |
ec68c924 EC |
9701 | int cpu = CPU_UNKNOWN; |
9702 | ||
e7af610e | 9703 | /* Identify the processor type. */ |
ec68c924 | 9704 | if (strcasecmp (arg, "default") != 0) |
252b5132 | 9705 | { |
e7af610e | 9706 | const struct mips_cpu_info *ci; |
252b5132 | 9707 | |
e7af610e NC |
9708 | ci = mips_cpu_info_from_name (arg); |
9709 | if (ci == NULL || ci->is_isa) | |
ec68c924 EC |
9710 | { |
9711 | switch (c) | |
9712 | { | |
9713 | case OPTION_MTUNE: | |
9714 | as_fatal (_("invalid architecture -mtune=%s"), arg); | |
9715 | break; | |
9716 | case OPTION_MARCH: | |
9717 | as_fatal (_("invalid architecture -march=%s"), arg); | |
9718 | break; | |
9719 | case OPTION_MCPU: | |
9720 | as_fatal (_("invalid architecture -mcpu=%s"), arg); | |
9721 | break; | |
9722 | } | |
9723 | } | |
e7af610e | 9724 | else |
ec68c924 EC |
9725 | cpu = ci->cpu; |
9726 | } | |
9727 | ||
9728 | switch (c) | |
9729 | { | |
9730 | case OPTION_MTUNE: | |
6dce9e24 TS |
9731 | if (mips_tune != CPU_UNKNOWN && mips_tune != cpu) |
9732 | as_warn(_("A different -mtune= was already specified, is now " | |
9733 | "-mtune=%s"), arg); | |
ec68c924 EC |
9734 | mips_tune = cpu; |
9735 | break; | |
9736 | case OPTION_MARCH: | |
6dce9e24 TS |
9737 | if (mips_arch != CPU_UNKNOWN && mips_arch != cpu) |
9738 | as_warn(_("A different -march= was already specified, is now " | |
9739 | "-march=%s"), arg); | |
ec68c924 EC |
9740 | mips_arch = cpu; |
9741 | break; | |
9742 | case OPTION_MCPU: | |
6dce9e24 TS |
9743 | if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu) |
9744 | as_warn(_("A different -mcpu= was already specified, is now " | |
9745 | "-mcpu=%s"), arg); | |
ec68c924 | 9746 | mips_cpu = cpu; |
252b5132 RH |
9747 | } |
9748 | } | |
9749 | break; | |
9750 | ||
9751 | case OPTION_M4650: | |
6dce9e24 TS |
9752 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650) |
9753 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650)) | |
9754 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9755 | "is now -m4650")); | |
ec68c924 EC |
9756 | mips_arch = CPU_R4650; |
9757 | mips_tune = CPU_R4650; | |
252b5132 RH |
9758 | break; |
9759 | ||
9760 | case OPTION_NO_M4650: | |
9761 | break; | |
9762 | ||
9763 | case OPTION_M4010: | |
6dce9e24 TS |
9764 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010) |
9765 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010)) | |
9766 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9767 | "is now -m4010")); | |
ec68c924 EC |
9768 | mips_arch = CPU_R4010; |
9769 | mips_tune = CPU_R4010; | |
252b5132 RH |
9770 | break; |
9771 | ||
9772 | case OPTION_NO_M4010: | |
9773 | break; | |
9774 | ||
9775 | case OPTION_M4100: | |
6dce9e24 TS |
9776 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100) |
9777 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100)) | |
9778 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9779 | "is now -m4100")); | |
ec68c924 EC |
9780 | mips_arch = CPU_VR4100; |
9781 | mips_tune = CPU_VR4100; | |
252b5132 RH |
9782 | break; |
9783 | ||
9784 | case OPTION_NO_M4100: | |
9785 | break; | |
9786 | ||
252b5132 | 9787 | case OPTION_M3900: |
6dce9e24 TS |
9788 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900) |
9789 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900)) | |
9790 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9791 | "is now -m3900")); | |
ec68c924 EC |
9792 | mips_arch = CPU_R3900; |
9793 | mips_tune = CPU_R3900; | |
252b5132 | 9794 | break; |
bdaaa2e1 | 9795 | |
252b5132 RH |
9796 | case OPTION_NO_M3900: |
9797 | break; | |
9798 | ||
9799 | case OPTION_MIPS16: | |
9800 | mips_opts.mips16 = 1; | |
9801 | mips_no_prev_insn (false); | |
9802 | break; | |
9803 | ||
9804 | case OPTION_NO_MIPS16: | |
9805 | mips_opts.mips16 = 0; | |
9806 | mips_no_prev_insn (false); | |
9807 | break; | |
9808 | ||
9809 | case OPTION_MEMBEDDED_PIC: | |
9810 | mips_pic = EMBEDDED_PIC; | |
9811 | if (USE_GLOBAL_POINTER_OPT && g_switch_seen) | |
9812 | { | |
9813 | as_bad (_("-G may not be used with embedded PIC code")); | |
9814 | return 0; | |
9815 | } | |
9816 | g_switch_value = 0x7fffffff; | |
9817 | break; | |
9818 | ||
0f074f60 | 9819 | #ifdef OBJ_ELF |
252b5132 RH |
9820 | /* When generating ELF code, we permit -KPIC and -call_shared to |
9821 | select SVR4_PIC, and -non_shared to select no PIC. This is | |
9822 | intended to be compatible with Irix 5. */ | |
9823 | case OPTION_CALL_SHARED: | |
9824 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9825 | { | |
9826 | as_bad (_("-call_shared is supported only for ELF format")); | |
9827 | return 0; | |
9828 | } | |
9829 | mips_pic = SVR4_PIC; | |
9830 | if (g_switch_seen && g_switch_value != 0) | |
9831 | { | |
9832 | as_bad (_("-G may not be used with SVR4 PIC code")); | |
9833 | return 0; | |
9834 | } | |
9835 | g_switch_value = 0; | |
9836 | break; | |
9837 | ||
9838 | case OPTION_NON_SHARED: | |
9839 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9840 | { | |
9841 | as_bad (_("-non_shared is supported only for ELF format")); | |
9842 | return 0; | |
9843 | } | |
9844 | mips_pic = NO_PIC; | |
9845 | break; | |
9846 | ||
9847 | /* The -xgot option tells the assembler to use 32 offsets when | |
9848 | accessing the got in SVR4_PIC mode. It is for Irix | |
9849 | compatibility. */ | |
9850 | case OPTION_XGOT: | |
9851 | mips_big_got = 1; | |
9852 | break; | |
0f074f60 | 9853 | #endif /* OBJ_ELF */ |
252b5132 RH |
9854 | |
9855 | case 'G': | |
9856 | if (! USE_GLOBAL_POINTER_OPT) | |
9857 | { | |
9858 | as_bad (_("-G is not supported for this configuration")); | |
9859 | return 0; | |
9860 | } | |
9861 | else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC) | |
9862 | { | |
9863 | as_bad (_("-G may not be used with SVR4 or embedded PIC code")); | |
9864 | return 0; | |
9865 | } | |
9866 | else | |
9867 | g_switch_value = atoi (arg); | |
9868 | g_switch_seen = 1; | |
9869 | break; | |
9870 | ||
0f074f60 | 9871 | #ifdef OBJ_ELF |
34ba82a8 TS |
9872 | /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32 |
9873 | and -mabi=64. */ | |
252b5132 | 9874 | case OPTION_32: |
34ba82a8 TS |
9875 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
9876 | { | |
9877 | as_bad (_("-32 is supported for ELF format only")); | |
9878 | return 0; | |
9879 | } | |
a325df1d | 9880 | mips_opts.abi = O32_ABI; |
252b5132 RH |
9881 | break; |
9882 | ||
e013f690 | 9883 | case OPTION_N32: |
34ba82a8 TS |
9884 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
9885 | { | |
9886 | as_bad (_("-n32 is supported for ELF format only")); | |
9887 | return 0; | |
9888 | } | |
a325df1d | 9889 | mips_opts.abi = N32_ABI; |
e013f690 | 9890 | break; |
252b5132 | 9891 | |
e013f690 | 9892 | case OPTION_64: |
34ba82a8 TS |
9893 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
9894 | { | |
9895 | as_bad (_("-64 is supported for ELF format only")); | |
9896 | return 0; | |
9897 | } | |
a325df1d | 9898 | mips_opts.abi = N64_ABI; |
e013f690 TS |
9899 | if (! support_64bit_objects()) |
9900 | as_fatal (_("No compiled in support for 64 bit object file format")); | |
252b5132 | 9901 | break; |
ae948b86 | 9902 | #endif /* OBJ_ELF */ |
252b5132 | 9903 | |
c97ef257 | 9904 | case OPTION_GP32: |
a325df1d TS |
9905 | file_mips_gp32 = 1; |
9906 | if (mips_opts.abi != O32_ABI) | |
9907 | mips_opts.abi = NO_ABI; | |
c97ef257 AH |
9908 | break; |
9909 | ||
9910 | case OPTION_GP64: | |
a325df1d TS |
9911 | file_mips_gp32 = 0; |
9912 | if (mips_opts.abi == O32_ABI) | |
9913 | mips_opts.abi = NO_ABI; | |
c97ef257 | 9914 | break; |
252b5132 | 9915 | |
ca4e0257 | 9916 | case OPTION_FP32: |
a325df1d TS |
9917 | file_mips_fp32 = 1; |
9918 | if (mips_opts.abi != O32_ABI) | |
9919 | mips_opts.abi = NO_ABI; | |
ca4e0257 RS |
9920 | break; |
9921 | ||
ae948b86 | 9922 | #ifdef OBJ_ELF |
252b5132 | 9923 | case OPTION_MABI: |
34ba82a8 TS |
9924 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
9925 | { | |
9926 | as_bad (_("-mabi is supported for ELF format only")); | |
9927 | return 0; | |
9928 | } | |
e013f690 | 9929 | if (strcmp (arg, "32") == 0) |
a325df1d | 9930 | mips_opts.abi = O32_ABI; |
e013f690 | 9931 | else if (strcmp (arg, "o64") == 0) |
a325df1d | 9932 | mips_opts.abi = O64_ABI; |
e013f690 | 9933 | else if (strcmp (arg, "n32") == 0) |
a325df1d | 9934 | mips_opts.abi = N32_ABI; |
e013f690 TS |
9935 | else if (strcmp (arg, "64") == 0) |
9936 | { | |
a325df1d | 9937 | mips_opts.abi = N64_ABI; |
e013f690 TS |
9938 | if (! support_64bit_objects()) |
9939 | as_fatal (_("No compiled in support for 64 bit object file " | |
9940 | "format")); | |
9941 | } | |
9942 | else if (strcmp (arg, "eabi") == 0) | |
a325df1d | 9943 | mips_opts.abi = EABI_ABI; |
e013f690 | 9944 | else |
a325df1d | 9945 | mips_opts.abi = NO_ABI; |
252b5132 | 9946 | break; |
e013f690 | 9947 | #endif /* OBJ_ELF */ |
252b5132 | 9948 | |
6b76fefe CM |
9949 | case OPTION_M7000_HILO_FIX: |
9950 | mips_7000_hilo_fix = true; | |
9951 | break; | |
9952 | ||
9953 | case OPTION_NO_M7000_HILO_FIX: | |
9954 | mips_7000_hilo_fix = false; | |
9955 | break; | |
9956 | ||
252b5132 RH |
9957 | default: |
9958 | return 0; | |
9959 | } | |
9960 | ||
9961 | return 1; | |
9962 | } | |
9963 | ||
252b5132 RH |
9964 | static void |
9965 | show (stream, string, col_p, first_p) | |
9966 | FILE *stream; | |
9967 | char *string; | |
9968 | int *col_p; | |
9969 | int *first_p; | |
9970 | { | |
9971 | if (*first_p) | |
9972 | { | |
9973 | fprintf (stream, "%24s", ""); | |
9974 | *col_p = 24; | |
9975 | } | |
9976 | else | |
9977 | { | |
9978 | fprintf (stream, ", "); | |
9979 | *col_p += 2; | |
9980 | } | |
9981 | ||
9982 | if (*col_p + strlen (string) > 72) | |
9983 | { | |
9984 | fprintf (stream, "\n%24s", ""); | |
9985 | *col_p = 24; | |
9986 | } | |
9987 | ||
9988 | fprintf (stream, "%s", string); | |
9989 | *col_p += strlen (string); | |
9990 | ||
9991 | *first_p = 0; | |
9992 | } | |
9993 | ||
252b5132 RH |
9994 | void |
9995 | md_show_usage (stream) | |
9996 | FILE *stream; | |
9997 | { | |
9998 | int column, first; | |
9999 | ||
beae10d5 | 10000 | fprintf (stream, _("\ |
252b5132 RH |
10001 | MIPS options:\n\ |
10002 | -membedded-pic generate embedded position independent code\n\ | |
10003 | -EB generate big endian output\n\ | |
10004 | -EL generate little endian output\n\ | |
9a41af64 | 10005 | -g, -g2 do not remove unneeded NOPs or swap branches\n\ |
252b5132 RH |
10006 | -G NUM allow referencing objects up to NUM bytes\n\ |
10007 | implicitly with the gp register [default 8]\n")); | |
beae10d5 | 10008 | fprintf (stream, _("\ |
252b5132 RH |
10009 | -mips1 generate MIPS ISA I instructions\n\ |
10010 | -mips2 generate MIPS ISA II instructions\n\ | |
10011 | -mips3 generate MIPS ISA III instructions\n\ | |
10012 | -mips4 generate MIPS ISA IV instructions\n\ | |
84ea6cf2 | 10013 | -mips5 generate MIPS ISA V instructions\n\ |
e7af610e | 10014 | -mips32 generate MIPS32 ISA instructions\n\ |
84ea6cf2 | 10015 | -mips64 generate MIPS64 ISA instructions\n\ |
ec68c924 | 10016 | -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n")); |
252b5132 RH |
10017 | |
10018 | first = 1; | |
10019 | ||
10020 | show (stream, "2000", &column, &first); | |
10021 | show (stream, "3000", &column, &first); | |
10022 | show (stream, "3900", &column, &first); | |
10023 | show (stream, "4000", &column, &first); | |
10024 | show (stream, "4010", &column, &first); | |
10025 | show (stream, "4100", &column, &first); | |
10026 | show (stream, "4111", &column, &first); | |
10027 | show (stream, "4300", &column, &first); | |
10028 | show (stream, "4400", &column, &first); | |
10029 | show (stream, "4600", &column, &first); | |
10030 | show (stream, "4650", &column, &first); | |
10031 | show (stream, "5000", &column, &first); | |
18ae5d72 EC |
10032 | show (stream, "5200", &column, &first); |
10033 | show (stream, "5230", &column, &first); | |
10034 | show (stream, "5231", &column, &first); | |
10035 | show (stream, "5261", &column, &first); | |
10036 | show (stream, "5721", &column, &first); | |
252b5132 RH |
10037 | show (stream, "6000", &column, &first); |
10038 | show (stream, "8000", &column, &first); | |
10039 | show (stream, "10000", &column, &first); | |
d1cf510e | 10040 | show (stream, "12000", &column, &first); |
2e4acd24 | 10041 | show (stream, "sb1", &column, &first); |
252b5132 RH |
10042 | fputc ('\n', stream); |
10043 | ||
10044 | fprintf (stream, _("\ | |
ec68c924 | 10045 | -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\ |
252b5132 RH |
10046 | -no-mCPU don't generate code specific to CPU.\n\ |
10047 | For -mCPU and -no-mCPU, CPU must be one of:\n")); | |
10048 | ||
10049 | first = 1; | |
10050 | ||
10051 | show (stream, "3900", &column, &first); | |
10052 | show (stream, "4010", &column, &first); | |
10053 | show (stream, "4100", &column, &first); | |
10054 | show (stream, "4650", &column, &first); | |
10055 | fputc ('\n', stream); | |
10056 | ||
beae10d5 | 10057 | fprintf (stream, _("\ |
252b5132 RH |
10058 | -mips16 generate mips16 instructions\n\ |
10059 | -no-mips16 do not generate mips16 instructions\n")); | |
beae10d5 | 10060 | fprintf (stream, _("\ |
ca4e0257 RS |
10061 | -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\ |
10062 | -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\ | |
252b5132 RH |
10063 | -O0 remove unneeded NOPs, do not swap branches\n\ |
10064 | -O remove unneeded NOPs and swap branches\n\ | |
63486801 | 10065 | -n warn about NOPs generated from macros\n\ |
119d663a | 10066 | --[no-]construct-floats [dis]allow floating point values to be constructed\n\ |
252b5132 RH |
10067 | --trap, --no-break trap exception on div by 0 and mult overflow\n\ |
10068 | --break, --no-trap break exception on div by 0 and mult overflow\n")); | |
10069 | #ifdef OBJ_ELF | |
beae10d5 | 10070 | fprintf (stream, _("\ |
252b5132 RH |
10071 | -KPIC, -call_shared generate SVR4 position independent code\n\ |
10072 | -non_shared do not generate position independent code\n\ | |
10073 | -xgot assume a 32 bit GOT\n\ | |
34ba82a8 TS |
10074 | -mabi=ABI create ABI conformant object file for:\n")); |
10075 | ||
10076 | first = 1; | |
10077 | ||
10078 | show (stream, "32", &column, &first); | |
10079 | show (stream, "o64", &column, &first); | |
10080 | show (stream, "n32", &column, &first); | |
10081 | show (stream, "64", &column, &first); | |
10082 | show (stream, "eabi", &column, &first); | |
10083 | ||
10084 | fputc ('\n', stream); | |
10085 | ||
10086 | fprintf (stream, _("\ | |
e013f690 TS |
10087 | -32 create o32 ABI object file (default)\n\ |
10088 | -n32 create n32 ABI object file\n\ | |
10089 | -64 create 64 ABI object file\n")); | |
252b5132 RH |
10090 | #endif |
10091 | } | |
10092 | \f | |
10093 | void | |
10094 | mips_init_after_args () | |
10095 | { | |
10096 | /* initialize opcodes */ | |
10097 | bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes; | |
beae10d5 | 10098 | mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes; |
252b5132 RH |
10099 | } |
10100 | ||
10101 | long | |
10102 | md_pcrel_from (fixP) | |
10103 | fixS *fixP; | |
10104 | { | |
10105 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour | |
10106 | && fixP->fx_addsy != (symbolS *) NULL | |
10107 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
10108 | { | |
6478892d TS |
10109 | /* This makes a branch to an undefined symbol be a branch to the |
10110 | current location. */ | |
cb56d3d3 | 10111 | if (mips_pic == EMBEDDED_PIC) |
6478892d | 10112 | return 4; |
cb56d3d3 | 10113 | else |
6478892d | 10114 | return 1; |
252b5132 RH |
10115 | } |
10116 | ||
10117 | /* return the address of the delay slot */ | |
10118 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; | |
10119 | } | |
10120 | ||
252b5132 RH |
10121 | /* This is called before the symbol table is processed. In order to |
10122 | work with gcc when using mips-tfile, we must keep all local labels. | |
10123 | However, in other cases, we want to discard them. If we were | |
10124 | called with -g, but we didn't see any debugging information, it may | |
10125 | mean that gcc is smuggling debugging information through to | |
10126 | mips-tfile, in which case we must generate all local labels. */ | |
10127 | ||
10128 | void | |
10129 | mips_frob_file_before_adjust () | |
10130 | { | |
10131 | #ifndef NO_ECOFF_DEBUGGING | |
10132 | if (ECOFF_DEBUGGING | |
10133 | && mips_debug != 0 | |
10134 | && ! ecoff_debugging_seen) | |
10135 | flag_keep_locals = 1; | |
10136 | #endif | |
10137 | } | |
10138 | ||
10139 | /* Sort any unmatched HI16_S relocs so that they immediately precede | |
94f592af | 10140 | the corresponding LO reloc. This is called before md_apply_fix3 and |
252b5132 RH |
10141 | tc_gen_reloc. Unmatched HI16_S relocs can only be generated by |
10142 | explicit use of the %hi modifier. */ | |
10143 | ||
10144 | void | |
10145 | mips_frob_file () | |
10146 | { | |
10147 | struct mips_hi_fixup *l; | |
10148 | ||
10149 | for (l = mips_hi_fixup_list; l != NULL; l = l->next) | |
10150 | { | |
10151 | segment_info_type *seginfo; | |
10152 | int pass; | |
10153 | ||
10154 | assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S); | |
10155 | ||
10156 | /* Check quickly whether the next fixup happens to be a matching | |
10157 | %lo. */ | |
10158 | if (l->fixp->fx_next != NULL | |
10159 | && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16 | |
10160 | && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy | |
10161 | && l->fixp->fx_offset == l->fixp->fx_next->fx_offset) | |
10162 | continue; | |
10163 | ||
10164 | /* Look through the fixups for this segment for a matching %lo. | |
10165 | When we find one, move the %hi just in front of it. We do | |
10166 | this in two passes. In the first pass, we try to find a | |
10167 | unique %lo. In the second pass, we permit multiple %hi | |
10168 | relocs for a single %lo (this is a GNU extension). */ | |
10169 | seginfo = seg_info (l->seg); | |
10170 | for (pass = 0; pass < 2; pass++) | |
10171 | { | |
10172 | fixS *f, *prev; | |
10173 | ||
10174 | prev = NULL; | |
10175 | for (f = seginfo->fix_root; f != NULL; f = f->fx_next) | |
10176 | { | |
10177 | /* Check whether this is a %lo fixup which matches l->fixp. */ | |
10178 | if (f->fx_r_type == BFD_RELOC_LO16 | |
10179 | && f->fx_addsy == l->fixp->fx_addsy | |
10180 | && f->fx_offset == l->fixp->fx_offset | |
10181 | && (pass == 1 | |
10182 | || prev == NULL | |
10183 | || prev->fx_r_type != BFD_RELOC_HI16_S | |
10184 | || prev->fx_addsy != f->fx_addsy | |
10185 | || prev->fx_offset != f->fx_offset)) | |
10186 | { | |
10187 | fixS **pf; | |
10188 | ||
10189 | /* Move l->fixp before f. */ | |
10190 | for (pf = &seginfo->fix_root; | |
10191 | *pf != l->fixp; | |
10192 | pf = &(*pf)->fx_next) | |
10193 | assert (*pf != NULL); | |
10194 | ||
10195 | *pf = l->fixp->fx_next; | |
10196 | ||
10197 | l->fixp->fx_next = f; | |
10198 | if (prev == NULL) | |
10199 | seginfo->fix_root = l->fixp; | |
10200 | else | |
10201 | prev->fx_next = l->fixp; | |
10202 | ||
10203 | break; | |
10204 | } | |
10205 | ||
10206 | prev = f; | |
10207 | } | |
10208 | ||
10209 | if (f != NULL) | |
10210 | break; | |
10211 | ||
10212 | #if 0 /* GCC code motion plus incomplete dead code elimination | |
10213 | can leave a %hi without a %lo. */ | |
10214 | if (pass == 1) | |
10215 | as_warn_where (l->fixp->fx_file, l->fixp->fx_line, | |
10216 | _("Unmatched %%hi reloc")); | |
10217 | #endif | |
10218 | } | |
10219 | } | |
10220 | } | |
10221 | ||
10222 | /* When generating embedded PIC code we need to use a special | |
10223 | relocation to represent the difference of two symbols in the .text | |
10224 | section (switch tables use a difference of this sort). See | |
10225 | include/coff/mips.h for details. This macro checks whether this | |
10226 | fixup requires the special reloc. */ | |
10227 | #define SWITCH_TABLE(fixp) \ | |
10228 | ((fixp)->fx_r_type == BFD_RELOC_32 \ | |
bb2d6cd7 | 10229 | && OUTPUT_FLAVOR != bfd_target_elf_flavour \ |
252b5132 RH |
10230 | && (fixp)->fx_addsy != NULL \ |
10231 | && (fixp)->fx_subsy != NULL \ | |
10232 | && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \ | |
10233 | && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section) | |
10234 | ||
10235 | /* When generating embedded PIC code we must keep all PC relative | |
10236 | relocations, in case the linker has to relax a call. We also need | |
f6688943 TS |
10237 | to keep relocations for switch table entries. |
10238 | ||
10239 | We may have combined relocations without symbols in the N32/N64 ABI. | |
10240 | We have to prevent gas from dropping them. */ | |
252b5132 | 10241 | |
252b5132 RH |
10242 | int |
10243 | mips_force_relocation (fixp) | |
10244 | fixS *fixp; | |
10245 | { | |
10246 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
10247 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
10248 | return 1; | |
10249 | ||
f6688943 TS |
10250 | if (HAVE_NEWABI |
10251 | && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr | |
10252 | && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB | |
10253 | || fixp->fx_r_type == BFD_RELOC_HI16_S | |
10254 | || fixp->fx_r_type == BFD_RELOC_LO16)) | |
10255 | return 1; | |
10256 | ||
252b5132 RH |
10257 | return (mips_pic == EMBEDDED_PIC |
10258 | && (fixp->fx_pcrel | |
10259 | || SWITCH_TABLE (fixp) | |
10260 | || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S | |
10261 | || fixp->fx_r_type == BFD_RELOC_PCREL_LO16)); | |
10262 | } | |
10263 | ||
add55e1f RS |
10264 | #ifdef OBJ_ELF |
10265 | static int | |
10266 | mips_need_elf_addend_fixup (fixP) | |
10267 | fixS *fixP; | |
10268 | { | |
10269 | return (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16 | |
10270 | || ((S_IS_WEAK (fixP->fx_addsy) | |
10271 | || S_IS_EXTERN (fixP->fx_addsy)) | |
10272 | && !S_IS_COMMON (fixP->fx_addsy)) | |
10273 | || (symbol_used_in_reloc_p (fixP->fx_addsy) | |
10274 | && (((bfd_get_section_flags (stdoutput, | |
10275 | S_GET_SEGMENT (fixP->fx_addsy)) | |
10276 | & SEC_LINK_ONCE) != 0) | |
10277 | || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)), | |
10278 | ".gnu.linkonce", | |
10279 | sizeof (".gnu.linkonce") - 1)))); | |
10280 | } | |
10281 | #endif | |
10282 | ||
252b5132 RH |
10283 | /* Apply a fixup to the object file. */ |
10284 | ||
94f592af NC |
10285 | void |
10286 | md_apply_fix3 (fixP, valP, seg) | |
252b5132 | 10287 | fixS *fixP; |
94f592af NC |
10288 | valueT * valP; |
10289 | segT seg ATTRIBUTE_UNUSED; | |
252b5132 RH |
10290 | { |
10291 | unsigned char *buf; | |
98aa84af AM |
10292 | long insn; |
10293 | valueT value; | |
252b5132 RH |
10294 | |
10295 | assert (fixP->fx_size == 4 | |
10296 | || fixP->fx_r_type == BFD_RELOC_16 | |
f6688943 TS |
10297 | || fixP->fx_r_type == BFD_RELOC_32 |
10298 | || fixP->fx_r_type == BFD_RELOC_MIPS_JMP | |
10299 | || fixP->fx_r_type == BFD_RELOC_HI16_S | |
10300 | || fixP->fx_r_type == BFD_RELOC_LO16 | |
10301 | || fixP->fx_r_type == BFD_RELOC_GPREL16 | |
76b3015f | 10302 | || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL |
f6688943 | 10303 | || fixP->fx_r_type == BFD_RELOC_GPREL32 |
252b5132 | 10304 | || fixP->fx_r_type == BFD_RELOC_64 |
f6688943 TS |
10305 | || fixP->fx_r_type == BFD_RELOC_CTOR |
10306 | || fixP->fx_r_type == BFD_RELOC_MIPS_SUB | |
10307 | || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST | |
10308 | || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER | |
10309 | || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP | |
10310 | || fixP->fx_r_type == BFD_RELOC_MIPS_REL16 | |
10311 | || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT | |
252b5132 RH |
10312 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
10313 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY); | |
10314 | ||
94f592af | 10315 | value = * valP; |
252b5132 RH |
10316 | |
10317 | /* If we aren't adjusting this fixup to be against the section | |
10318 | symbol, we need to adjust the value. */ | |
10319 | #ifdef OBJ_ELF | |
10320 | if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
bb2d6cd7 | 10321 | { |
add55e1f | 10322 | if (mips_need_elf_addend_fixup (fixP)) |
98aa84af AM |
10323 | { |
10324 | valueT symval = S_GET_VALUE (fixP->fx_addsy); | |
94f592af | 10325 | |
98aa84af | 10326 | value -= symval; |
add55e1f | 10327 | if (value != 0 && ! fixP->fx_pcrel) |
98aa84af AM |
10328 | { |
10329 | /* In this case, the bfd_install_relocation routine will | |
10330 | incorrectly add the symbol value back in. We just want | |
7461da6e | 10331 | the addend to appear in the object file. */ |
98aa84af | 10332 | value -= symval; |
7461da6e RS |
10333 | |
10334 | /* Make sure the addend is still non-zero. If it became zero | |
10335 | after the last operation, set it to a spurious value and | |
10336 | subtract the same value from the object file's contents. */ | |
10337 | if (value == 0) | |
10338 | { | |
10339 | value = 8; | |
10340 | ||
10341 | /* The in-place addends for LO16 relocations are signed; | |
10342 | leave the matching HI16 in-place addends as zero. */ | |
10343 | if (fixP->fx_r_type != BFD_RELOC_HI16_S) | |
10344 | { | |
10345 | reloc_howto_type *howto; | |
10346 | bfd_vma contents, mask, field; | |
10347 | ||
10348 | howto = bfd_reloc_type_lookup (stdoutput, | |
10349 | fixP->fx_r_type); | |
10350 | ||
10351 | contents = bfd_get_bits (fixP->fx_frag->fr_literal | |
10352 | + fixP->fx_where, | |
10353 | fixP->fx_size * 8, | |
10354 | target_big_endian); | |
10355 | ||
10356 | /* MASK has bits set where the relocation should go. | |
10357 | FIELD is -value, shifted into the appropriate place | |
10358 | for this relocation. */ | |
10359 | mask = 1 << (howto->bitsize - 1); | |
10360 | mask = (((mask - 1) << 1) | 1) << howto->bitpos; | |
10361 | field = (-value >> howto->rightshift) << howto->bitpos; | |
10362 | ||
10363 | bfd_put_bits ((field & mask) | (contents & ~mask), | |
10364 | fixP->fx_frag->fr_literal + fixP->fx_where, | |
10365 | fixP->fx_size * 8, | |
10366 | target_big_endian); | |
10367 | } | |
10368 | } | |
98aa84af AM |
10369 | } |
10370 | } | |
252b5132 | 10371 | |
bb2d6cd7 GK |
10372 | /* This code was generated using trial and error and so is |
10373 | fragile and not trustworthy. If you change it, you should | |
10374 | rerun the elf-rel, elf-rel2, and empic testcases and ensure | |
10375 | they still pass. */ | |
10376 | if (fixP->fx_pcrel || fixP->fx_subsy != NULL) | |
10377 | { | |
10378 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
10379 | ||
10380 | /* BFD's REL handling, for MIPS, is _very_ weird. | |
10381 | This gives the right results, but it can't possibly | |
10382 | be the way things are supposed to work. */ | |
cb56d3d3 TS |
10383 | if ((fixP->fx_r_type != BFD_RELOC_16_PCREL |
10384 | && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2) | |
bb2d6cd7 GK |
10385 | || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section) |
10386 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
10387 | } | |
10388 | } | |
10389 | #endif | |
252b5132 | 10390 | |
94f592af | 10391 | fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */ |
252b5132 RH |
10392 | |
10393 | if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel) | |
10394 | fixP->fx_done = 1; | |
10395 | ||
10396 | switch (fixP->fx_r_type) | |
10397 | { | |
10398 | case BFD_RELOC_MIPS_JMP: | |
e369bcce TS |
10399 | case BFD_RELOC_MIPS_SHIFT5: |
10400 | case BFD_RELOC_MIPS_SHIFT6: | |
10401 | case BFD_RELOC_MIPS_GOT_DISP: | |
10402 | case BFD_RELOC_MIPS_GOT_PAGE: | |
10403 | case BFD_RELOC_MIPS_GOT_OFST: | |
10404 | case BFD_RELOC_MIPS_SUB: | |
10405 | case BFD_RELOC_MIPS_INSERT_A: | |
10406 | case BFD_RELOC_MIPS_INSERT_B: | |
10407 | case BFD_RELOC_MIPS_DELETE: | |
10408 | case BFD_RELOC_MIPS_HIGHEST: | |
10409 | case BFD_RELOC_MIPS_HIGHER: | |
10410 | case BFD_RELOC_MIPS_SCN_DISP: | |
10411 | case BFD_RELOC_MIPS_REL16: | |
10412 | case BFD_RELOC_MIPS_RELGOT: | |
10413 | case BFD_RELOC_MIPS_JALR: | |
252b5132 RH |
10414 | case BFD_RELOC_HI16: |
10415 | case BFD_RELOC_HI16_S: | |
cdf6fd85 | 10416 | case BFD_RELOC_GPREL16: |
252b5132 RH |
10417 | case BFD_RELOC_MIPS_LITERAL: |
10418 | case BFD_RELOC_MIPS_CALL16: | |
10419 | case BFD_RELOC_MIPS_GOT16: | |
cdf6fd85 | 10420 | case BFD_RELOC_GPREL32: |
252b5132 RH |
10421 | case BFD_RELOC_MIPS_GOT_HI16: |
10422 | case BFD_RELOC_MIPS_GOT_LO16: | |
10423 | case BFD_RELOC_MIPS_CALL_HI16: | |
10424 | case BFD_RELOC_MIPS_CALL_LO16: | |
10425 | case BFD_RELOC_MIPS16_GPREL: | |
10426 | if (fixP->fx_pcrel) | |
10427 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
10428 | _("Invalid PC relative reloc")); | |
10429 | /* Nothing needed to do. The value comes from the reloc entry */ | |
10430 | break; | |
10431 | ||
10432 | case BFD_RELOC_MIPS16_JMP: | |
10433 | /* We currently always generate a reloc against a symbol, which | |
10434 | means that we don't want an addend even if the symbol is | |
10435 | defined. */ | |
10436 | fixP->fx_addnumber = 0; | |
10437 | break; | |
10438 | ||
10439 | case BFD_RELOC_PCREL_HI16_S: | |
10440 | /* The addend for this is tricky if it is internal, so we just | |
10441 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 10442 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
10443 | && !fixP->fx_done |
10444 | && value != 0) | |
10445 | break; | |
10446 | if (fixP->fx_addsy | |
10447 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
10448 | { |
10449 | /* For an external symbol adjust by the address to make it | |
10450 | pcrel_offset. We use the address of the RELLO reloc | |
10451 | which follows this one. */ | |
10452 | value += (fixP->fx_next->fx_frag->fr_address | |
10453 | + fixP->fx_next->fx_where); | |
10454 | } | |
e7d556df | 10455 | value = ((value + 0x8000) >> 16) & 0xffff; |
252b5132 RH |
10456 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; |
10457 | if (target_big_endian) | |
10458 | buf += 2; | |
10459 | md_number_to_chars (buf, value, 2); | |
10460 | break; | |
10461 | ||
10462 | case BFD_RELOC_PCREL_LO16: | |
10463 | /* The addend for this is tricky if it is internal, so we just | |
10464 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 10465 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
10466 | && !fixP->fx_done |
10467 | && value != 0) | |
10468 | break; | |
10469 | if (fixP->fx_addsy | |
10470 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
10471 | value += fixP->fx_frag->fr_address + fixP->fx_where; |
10472 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
10473 | if (target_big_endian) | |
10474 | buf += 2; | |
10475 | md_number_to_chars (buf, value, 2); | |
10476 | break; | |
10477 | ||
10478 | case BFD_RELOC_64: | |
10479 | /* This is handled like BFD_RELOC_32, but we output a sign | |
10480 | extended value if we are only 32 bits. */ | |
10481 | if (fixP->fx_done | |
10482 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
10483 | { | |
10484 | if (8 <= sizeof (valueT)) | |
10485 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
10486 | value, 8); | |
10487 | else | |
10488 | { | |
10489 | long w1, w2; | |
10490 | long hiv; | |
10491 | ||
10492 | w1 = w2 = fixP->fx_where; | |
10493 | if (target_big_endian) | |
10494 | w1 += 4; | |
10495 | else | |
10496 | w2 += 4; | |
10497 | md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4); | |
10498 | if ((value & 0x80000000) != 0) | |
10499 | hiv = 0xffffffff; | |
10500 | else | |
10501 | hiv = 0; | |
10502 | md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4); | |
10503 | } | |
10504 | } | |
10505 | break; | |
10506 | ||
056350c6 | 10507 | case BFD_RELOC_RVA: |
252b5132 RH |
10508 | case BFD_RELOC_32: |
10509 | /* If we are deleting this reloc entry, we must fill in the | |
10510 | value now. This can happen if we have a .word which is not | |
10511 | resolved when it appears but is later defined. We also need | |
10512 | to fill in the value if this is an embedded PIC switch table | |
10513 | entry. */ | |
10514 | if (fixP->fx_done | |
10515 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
10516 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
10517 | value, 4); | |
10518 | break; | |
10519 | ||
10520 | case BFD_RELOC_16: | |
10521 | /* If we are deleting this reloc entry, we must fill in the | |
10522 | value now. */ | |
10523 | assert (fixP->fx_size == 2); | |
10524 | if (fixP->fx_done) | |
10525 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
10526 | value, 2); | |
10527 | break; | |
10528 | ||
10529 | case BFD_RELOC_LO16: | |
10530 | /* When handling an embedded PIC switch statement, we can wind | |
10531 | up deleting a LO16 reloc. See the 'o' case in mips_ip. */ | |
10532 | if (fixP->fx_done) | |
10533 | { | |
98aa84af | 10534 | if (value + 0x8000 > 0xffff) |
252b5132 RH |
10535 | as_bad_where (fixP->fx_file, fixP->fx_line, |
10536 | _("relocation overflow")); | |
10537 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
10538 | if (target_big_endian) | |
10539 | buf += 2; | |
10540 | md_number_to_chars (buf, value, 2); | |
10541 | } | |
10542 | break; | |
10543 | ||
10544 | case BFD_RELOC_16_PCREL_S2: | |
cb56d3d3 TS |
10545 | if ((value & 0x3) != 0) |
10546 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
10547 | _("Branch to odd address (%lx)"), (long) value); | |
10548 | ||
10549 | /* Fall through. */ | |
10550 | ||
10551 | case BFD_RELOC_16_PCREL: | |
252b5132 RH |
10552 | /* |
10553 | * We need to save the bits in the instruction since fixup_segment() | |
10554 | * might be deleting the relocation entry (i.e., a branch within | |
10555 | * the current segment). | |
10556 | */ | |
bb2d6cd7 GK |
10557 | if (!fixP->fx_done && value != 0) |
10558 | break; | |
10559 | /* If 'value' is zero, the remaining reloc code won't actually | |
10560 | do the store, so it must be done here. This is probably | |
10561 | a bug somewhere. */ | |
10562 | if (!fixP->fx_done) | |
10563 | value -= fixP->fx_frag->fr_address + fixP->fx_where; | |
bdaaa2e1 | 10564 | |
98aa84af | 10565 | value = (offsetT) value >> 2; |
252b5132 RH |
10566 | |
10567 | /* update old instruction data */ | |
10568 | buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal); | |
10569 | if (target_big_endian) | |
10570 | insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
10571 | else | |
10572 | insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | |
10573 | ||
98aa84af | 10574 | if (value + 0x8000 <= 0xffff) |
252b5132 RH |
10575 | insn |= value & 0xffff; |
10576 | else | |
10577 | { | |
10578 | /* The branch offset is too large. If this is an | |
10579 | unconditional branch, and we are not generating PIC code, | |
10580 | we can convert it to an absolute jump instruction. */ | |
10581 | if (mips_pic == NO_PIC | |
10582 | && fixP->fx_done | |
10583 | && fixP->fx_frag->fr_address >= text_section->vma | |
10584 | && (fixP->fx_frag->fr_address | |
10585 | < text_section->vma + text_section->_raw_size) | |
10586 | && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */ | |
10587 | || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */ | |
10588 | || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */ | |
10589 | { | |
10590 | if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */ | |
10591 | insn = 0x0c000000; /* jal */ | |
10592 | else | |
10593 | insn = 0x08000000; /* j */ | |
10594 | fixP->fx_r_type = BFD_RELOC_MIPS_JMP; | |
10595 | fixP->fx_done = 0; | |
10596 | fixP->fx_addsy = section_symbol (text_section); | |
10597 | fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP); | |
10598 | } | |
10599 | else | |
10600 | { | |
10601 | /* FIXME. It would be possible in principle to handle | |
10602 | conditional branches which overflow. They could be | |
10603 | transformed into a branch around a jump. This would | |
10604 | require setting up variant frags for each different | |
10605 | branch type. The native MIPS assembler attempts to | |
10606 | handle these cases, but it appears to do it | |
10607 | incorrectly. */ | |
10608 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
10609 | _("Branch out of range")); | |
10610 | } | |
10611 | } | |
10612 | ||
10613 | md_number_to_chars ((char *) buf, (valueT) insn, 4); | |
10614 | break; | |
10615 | ||
10616 | case BFD_RELOC_VTABLE_INHERIT: | |
10617 | fixP->fx_done = 0; | |
10618 | if (fixP->fx_addsy | |
10619 | && !S_IS_DEFINED (fixP->fx_addsy) | |
10620 | && !S_IS_WEAK (fixP->fx_addsy)) | |
10621 | S_SET_WEAK (fixP->fx_addsy); | |
10622 | break; | |
10623 | ||
10624 | case BFD_RELOC_VTABLE_ENTRY: | |
10625 | fixP->fx_done = 0; | |
10626 | break; | |
10627 | ||
10628 | default: | |
10629 | internalError (); | |
10630 | } | |
252b5132 RH |
10631 | } |
10632 | ||
10633 | #if 0 | |
10634 | void | |
10635 | printInsn (oc) | |
10636 | unsigned long oc; | |
10637 | { | |
10638 | const struct mips_opcode *p; | |
10639 | int treg, sreg, dreg, shamt; | |
10640 | short imm; | |
10641 | const char *args; | |
10642 | int i; | |
10643 | ||
10644 | for (i = 0; i < NUMOPCODES; ++i) | |
10645 | { | |
10646 | p = &mips_opcodes[i]; | |
10647 | if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO)) | |
10648 | { | |
10649 | printf ("%08lx %s\t", oc, p->name); | |
10650 | treg = (oc >> 16) & 0x1f; | |
10651 | sreg = (oc >> 21) & 0x1f; | |
10652 | dreg = (oc >> 11) & 0x1f; | |
10653 | shamt = (oc >> 6) & 0x1f; | |
10654 | imm = oc; | |
10655 | for (args = p->args;; ++args) | |
10656 | { | |
10657 | switch (*args) | |
10658 | { | |
10659 | case '\0': | |
10660 | printf ("\n"); | |
10661 | break; | |
10662 | ||
10663 | case ',': | |
10664 | case '(': | |
10665 | case ')': | |
10666 | printf ("%c", *args); | |
10667 | continue; | |
10668 | ||
10669 | case 'r': | |
10670 | assert (treg == sreg); | |
10671 | printf ("$%d,$%d", treg, sreg); | |
10672 | continue; | |
10673 | ||
10674 | case 'd': | |
10675 | case 'G': | |
10676 | printf ("$%d", dreg); | |
10677 | continue; | |
10678 | ||
10679 | case 't': | |
10680 | case 'E': | |
10681 | printf ("$%d", treg); | |
10682 | continue; | |
10683 | ||
10684 | case 'k': | |
10685 | printf ("0x%x", treg); | |
10686 | continue; | |
10687 | ||
10688 | case 'b': | |
10689 | case 's': | |
10690 | printf ("$%d", sreg); | |
10691 | continue; | |
10692 | ||
10693 | case 'a': | |
10694 | printf ("0x%08lx", oc & 0x1ffffff); | |
10695 | continue; | |
10696 | ||
10697 | case 'i': | |
10698 | case 'j': | |
10699 | case 'o': | |
10700 | case 'u': | |
10701 | printf ("%d", imm); | |
10702 | continue; | |
10703 | ||
10704 | case '<': | |
10705 | case '>': | |
10706 | printf ("$%d", shamt); | |
10707 | continue; | |
10708 | ||
10709 | default: | |
10710 | internalError (); | |
10711 | } | |
10712 | break; | |
10713 | } | |
10714 | return; | |
10715 | } | |
10716 | } | |
10717 | printf (_("%08lx UNDEFINED\n"), oc); | |
10718 | } | |
10719 | #endif | |
10720 | ||
10721 | static symbolS * | |
10722 | get_symbol () | |
10723 | { | |
10724 | int c; | |
10725 | char *name; | |
10726 | symbolS *p; | |
10727 | ||
10728 | name = input_line_pointer; | |
10729 | c = get_symbol_end (); | |
10730 | p = (symbolS *) symbol_find_or_make (name); | |
10731 | *input_line_pointer = c; | |
10732 | return p; | |
10733 | } | |
10734 | ||
10735 | /* Align the current frag to a given power of two. The MIPS assembler | |
10736 | also automatically adjusts any preceding label. */ | |
10737 | ||
10738 | static void | |
10739 | mips_align (to, fill, label) | |
10740 | int to; | |
10741 | int fill; | |
10742 | symbolS *label; | |
10743 | { | |
10744 | mips_emit_delays (false); | |
10745 | frag_align (to, fill, 0); | |
10746 | record_alignment (now_seg, to); | |
10747 | if (label != NULL) | |
10748 | { | |
10749 | assert (S_GET_SEGMENT (label) == now_seg); | |
49309057 | 10750 | symbol_set_frag (label, frag_now); |
252b5132 RH |
10751 | S_SET_VALUE (label, (valueT) frag_now_fix ()); |
10752 | } | |
10753 | } | |
10754 | ||
10755 | /* Align to a given power of two. .align 0 turns off the automatic | |
10756 | alignment used by the data creating pseudo-ops. */ | |
10757 | ||
10758 | static void | |
10759 | s_align (x) | |
43841e91 | 10760 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10761 | { |
10762 | register int temp; | |
10763 | register long temp_fill; | |
10764 | long max_alignment = 15; | |
10765 | ||
10766 | /* | |
10767 | ||
10768 | o Note that the assembler pulls down any immediately preceeding label | |
10769 | to the aligned address. | |
10770 | o It's not documented but auto alignment is reinstated by | |
10771 | a .align pseudo instruction. | |
10772 | o Note also that after auto alignment is turned off the mips assembler | |
10773 | issues an error on attempt to assemble an improperly aligned data item. | |
10774 | We don't. | |
10775 | ||
10776 | */ | |
10777 | ||
10778 | temp = get_absolute_expression (); | |
10779 | if (temp > max_alignment) | |
10780 | as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment); | |
10781 | else if (temp < 0) | |
10782 | { | |
10783 | as_warn (_("Alignment negative: 0 assumed.")); | |
10784 | temp = 0; | |
10785 | } | |
10786 | if (*input_line_pointer == ',') | |
10787 | { | |
10788 | input_line_pointer++; | |
10789 | temp_fill = get_absolute_expression (); | |
10790 | } | |
10791 | else | |
10792 | temp_fill = 0; | |
10793 | if (temp) | |
10794 | { | |
10795 | auto_align = 1; | |
10796 | mips_align (temp, (int) temp_fill, | |
10797 | insn_labels != NULL ? insn_labels->label : NULL); | |
10798 | } | |
10799 | else | |
10800 | { | |
10801 | auto_align = 0; | |
10802 | } | |
10803 | ||
10804 | demand_empty_rest_of_line (); | |
10805 | } | |
10806 | ||
10807 | void | |
10808 | mips_flush_pending_output () | |
10809 | { | |
10810 | mips_emit_delays (false); | |
10811 | mips_clear_insn_labels (); | |
10812 | } | |
10813 | ||
10814 | static void | |
10815 | s_change_sec (sec) | |
10816 | int sec; | |
10817 | { | |
10818 | segT seg; | |
10819 | ||
10820 | /* When generating embedded PIC code, we only use the .text, .lit8, | |
10821 | .sdata and .sbss sections. We change the .data and .rdata | |
10822 | pseudo-ops to use .sdata. */ | |
10823 | if (mips_pic == EMBEDDED_PIC | |
10824 | && (sec == 'd' || sec == 'r')) | |
10825 | sec = 's'; | |
10826 | ||
10827 | #ifdef OBJ_ELF | |
10828 | /* The ELF backend needs to know that we are changing sections, so | |
10829 | that .previous works correctly. We could do something like check | |
b6ff326e | 10830 | for an obj_section_change_hook macro, but that might be confusing |
252b5132 RH |
10831 | as it would not be appropriate to use it in the section changing |
10832 | functions in read.c, since obj-elf.c intercepts those. FIXME: | |
10833 | This should be cleaner, somehow. */ | |
10834 | obj_elf_section_change_hook (); | |
10835 | #endif | |
10836 | ||
10837 | mips_emit_delays (false); | |
10838 | switch (sec) | |
10839 | { | |
10840 | case 't': | |
10841 | s_text (0); | |
10842 | break; | |
10843 | case 'd': | |
10844 | s_data (0); | |
10845 | break; | |
10846 | case 'b': | |
10847 | subseg_set (bss_section, (subsegT) get_absolute_expression ()); | |
10848 | demand_empty_rest_of_line (); | |
10849 | break; | |
10850 | ||
10851 | case 'r': | |
10852 | if (USE_GLOBAL_POINTER_OPT) | |
10853 | { | |
10854 | seg = subseg_new (RDATA_SECTION_NAME, | |
10855 | (subsegT) get_absolute_expression ()); | |
10856 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
10857 | { | |
10858 | bfd_set_section_flags (stdoutput, seg, | |
10859 | (SEC_ALLOC | |
10860 | | SEC_LOAD | |
10861 | | SEC_READONLY | |
10862 | | SEC_RELOC | |
10863 | | SEC_DATA)); | |
10864 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 10865 | record_alignment (seg, 4); |
252b5132 RH |
10866 | } |
10867 | demand_empty_rest_of_line (); | |
10868 | } | |
10869 | else | |
10870 | { | |
10871 | as_bad (_("No read only data section in this object file format")); | |
10872 | demand_empty_rest_of_line (); | |
10873 | return; | |
10874 | } | |
10875 | break; | |
10876 | ||
10877 | case 's': | |
10878 | if (USE_GLOBAL_POINTER_OPT) | |
10879 | { | |
10880 | seg = subseg_new (".sdata", (subsegT) get_absolute_expression ()); | |
10881 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
10882 | { | |
10883 | bfd_set_section_flags (stdoutput, seg, | |
10884 | SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
10885 | | SEC_DATA); | |
10886 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 10887 | record_alignment (seg, 4); |
252b5132 RH |
10888 | } |
10889 | demand_empty_rest_of_line (); | |
10890 | break; | |
10891 | } | |
10892 | else | |
10893 | { | |
10894 | as_bad (_("Global pointers not supported; recompile -G 0")); | |
10895 | demand_empty_rest_of_line (); | |
10896 | return; | |
10897 | } | |
10898 | } | |
10899 | ||
10900 | auto_align = 1; | |
10901 | } | |
10902 | ||
10903 | void | |
10904 | mips_enable_auto_align () | |
10905 | { | |
10906 | auto_align = 1; | |
10907 | } | |
10908 | ||
10909 | static void | |
10910 | s_cons (log_size) | |
10911 | int log_size; | |
10912 | { | |
10913 | symbolS *label; | |
10914 | ||
10915 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10916 | mips_emit_delays (false); | |
10917 | if (log_size > 0 && auto_align) | |
10918 | mips_align (log_size, 0, label); | |
10919 | mips_clear_insn_labels (); | |
10920 | cons (1 << log_size); | |
10921 | } | |
10922 | ||
10923 | static void | |
10924 | s_float_cons (type) | |
10925 | int type; | |
10926 | { | |
10927 | symbolS *label; | |
10928 | ||
10929 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10930 | ||
10931 | mips_emit_delays (false); | |
10932 | ||
10933 | if (auto_align) | |
49309057 ILT |
10934 | { |
10935 | if (type == 'd') | |
10936 | mips_align (3, 0, label); | |
10937 | else | |
10938 | mips_align (2, 0, label); | |
10939 | } | |
252b5132 RH |
10940 | |
10941 | mips_clear_insn_labels (); | |
10942 | ||
10943 | float_cons (type); | |
10944 | } | |
10945 | ||
10946 | /* Handle .globl. We need to override it because on Irix 5 you are | |
10947 | permitted to say | |
10948 | .globl foo .text | |
10949 | where foo is an undefined symbol, to mean that foo should be | |
10950 | considered to be the address of a function. */ | |
10951 | ||
10952 | static void | |
10953 | s_mips_globl (x) | |
43841e91 | 10954 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10955 | { |
10956 | char *name; | |
10957 | int c; | |
10958 | symbolS *symbolP; | |
10959 | flagword flag; | |
10960 | ||
10961 | name = input_line_pointer; | |
10962 | c = get_symbol_end (); | |
10963 | symbolP = symbol_find_or_make (name); | |
10964 | *input_line_pointer = c; | |
10965 | SKIP_WHITESPACE (); | |
10966 | ||
10967 | /* On Irix 5, every global symbol that is not explicitly labelled as | |
10968 | being a function is apparently labelled as being an object. */ | |
10969 | flag = BSF_OBJECT; | |
10970 | ||
10971 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
10972 | { | |
10973 | char *secname; | |
10974 | asection *sec; | |
10975 | ||
10976 | secname = input_line_pointer; | |
10977 | c = get_symbol_end (); | |
10978 | sec = bfd_get_section_by_name (stdoutput, secname); | |
10979 | if (sec == NULL) | |
10980 | as_bad (_("%s: no such section"), secname); | |
10981 | *input_line_pointer = c; | |
10982 | ||
10983 | if (sec != NULL && (sec->flags & SEC_CODE) != 0) | |
10984 | flag = BSF_FUNCTION; | |
10985 | } | |
10986 | ||
49309057 | 10987 | symbol_get_bfdsym (symbolP)->flags |= flag; |
252b5132 RH |
10988 | |
10989 | S_SET_EXTERNAL (symbolP); | |
10990 | demand_empty_rest_of_line (); | |
10991 | } | |
10992 | ||
10993 | static void | |
10994 | s_option (x) | |
43841e91 | 10995 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10996 | { |
10997 | char *opt; | |
10998 | char c; | |
10999 | ||
11000 | opt = input_line_pointer; | |
11001 | c = get_symbol_end (); | |
11002 | ||
11003 | if (*opt == 'O') | |
11004 | { | |
11005 | /* FIXME: What does this mean? */ | |
11006 | } | |
11007 | else if (strncmp (opt, "pic", 3) == 0) | |
11008 | { | |
11009 | int i; | |
11010 | ||
11011 | i = atoi (opt + 3); | |
11012 | if (i == 0) | |
11013 | mips_pic = NO_PIC; | |
11014 | else if (i == 2) | |
11015 | mips_pic = SVR4_PIC; | |
11016 | else | |
11017 | as_bad (_(".option pic%d not supported"), i); | |
11018 | ||
11019 | if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC) | |
11020 | { | |
11021 | if (g_switch_seen && g_switch_value != 0) | |
11022 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
11023 | g_switch_value = 0; | |
11024 | bfd_set_gp_size (stdoutput, 0); | |
11025 | } | |
11026 | } | |
11027 | else | |
11028 | as_warn (_("Unrecognized option \"%s\""), opt); | |
11029 | ||
11030 | *input_line_pointer = c; | |
11031 | demand_empty_rest_of_line (); | |
11032 | } | |
11033 | ||
11034 | /* This structure is used to hold a stack of .set values. */ | |
11035 | ||
e972090a NC |
11036 | struct mips_option_stack |
11037 | { | |
252b5132 RH |
11038 | struct mips_option_stack *next; |
11039 | struct mips_set_options options; | |
11040 | }; | |
11041 | ||
11042 | static struct mips_option_stack *mips_opts_stack; | |
11043 | ||
11044 | /* Handle the .set pseudo-op. */ | |
11045 | ||
11046 | static void | |
11047 | s_mipsset (x) | |
43841e91 | 11048 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11049 | { |
11050 | char *name = input_line_pointer, ch; | |
11051 | ||
11052 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
11053 | input_line_pointer++; | |
11054 | ch = *input_line_pointer; | |
11055 | *input_line_pointer = '\0'; | |
11056 | ||
11057 | if (strcmp (name, "reorder") == 0) | |
11058 | { | |
11059 | if (mips_opts.noreorder && prev_nop_frag != NULL) | |
11060 | { | |
11061 | /* If we still have pending nops, we can discard them. The | |
11062 | usual nop handling will insert any that are still | |
bdaaa2e1 | 11063 | needed. */ |
252b5132 RH |
11064 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds |
11065 | * (mips_opts.mips16 ? 2 : 4)); | |
11066 | prev_nop_frag = NULL; | |
11067 | } | |
11068 | mips_opts.noreorder = 0; | |
11069 | } | |
11070 | else if (strcmp (name, "noreorder") == 0) | |
11071 | { | |
11072 | mips_emit_delays (true); | |
11073 | mips_opts.noreorder = 1; | |
11074 | mips_any_noreorder = 1; | |
11075 | } | |
11076 | else if (strcmp (name, "at") == 0) | |
11077 | { | |
11078 | mips_opts.noat = 0; | |
11079 | } | |
11080 | else if (strcmp (name, "noat") == 0) | |
11081 | { | |
11082 | mips_opts.noat = 1; | |
11083 | } | |
11084 | else if (strcmp (name, "macro") == 0) | |
11085 | { | |
11086 | mips_opts.warn_about_macros = 0; | |
11087 | } | |
11088 | else if (strcmp (name, "nomacro") == 0) | |
11089 | { | |
11090 | if (mips_opts.noreorder == 0) | |
11091 | as_bad (_("`noreorder' must be set before `nomacro'")); | |
11092 | mips_opts.warn_about_macros = 1; | |
11093 | } | |
11094 | else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0) | |
11095 | { | |
11096 | mips_opts.nomove = 0; | |
11097 | } | |
11098 | else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0) | |
11099 | { | |
11100 | mips_opts.nomove = 1; | |
11101 | } | |
11102 | else if (strcmp (name, "bopt") == 0) | |
11103 | { | |
11104 | mips_opts.nobopt = 0; | |
11105 | } | |
11106 | else if (strcmp (name, "nobopt") == 0) | |
11107 | { | |
11108 | mips_opts.nobopt = 1; | |
11109 | } | |
11110 | else if (strcmp (name, "mips16") == 0 | |
11111 | || strcmp (name, "MIPS-16") == 0) | |
11112 | mips_opts.mips16 = 1; | |
11113 | else if (strcmp (name, "nomips16") == 0 | |
11114 | || strcmp (name, "noMIPS-16") == 0) | |
11115 | mips_opts.mips16 = 0; | |
11116 | else if (strncmp (name, "mips", 4) == 0) | |
11117 | { | |
11118 | int isa; | |
11119 | ||
11120 | /* Permit the user to change the ISA on the fly. Needless to | |
11121 | say, misuse can cause serious problems. */ | |
11122 | isa = atoi (name + 4); | |
553178e4 TS |
11123 | switch (isa) |
11124 | { | |
11125 | case 0: | |
a325df1d TS |
11126 | mips_opts.gp32 = file_mips_gp32; |
11127 | mips_opts.fp32 = file_mips_fp32; | |
11128 | mips_opts.abi = file_mips_abi; | |
553178e4 TS |
11129 | break; |
11130 | case 1: | |
11131 | case 2: | |
11132 | case 32: | |
a325df1d TS |
11133 | mips_opts.gp32 = 1; |
11134 | mips_opts.fp32 = 1; | |
553178e4 TS |
11135 | break; |
11136 | case 3: | |
11137 | case 4: | |
11138 | case 5: | |
11139 | case 64: | |
a325df1d TS |
11140 | /* Loosen ABI register width restriction. */ |
11141 | if (mips_opts.abi == O32_ABI) | |
11142 | mips_opts.abi = NO_ABI; | |
11143 | mips_opts.gp32 = 0; | |
11144 | mips_opts.fp32 = 0; | |
553178e4 TS |
11145 | break; |
11146 | default: | |
a325df1d | 11147 | as_bad (_("unknown ISA level %s"), name + 4); |
553178e4 TS |
11148 | break; |
11149 | } | |
11150 | ||
e7af610e NC |
11151 | switch (isa) |
11152 | { | |
84ea6cf2 NC |
11153 | case 0: mips_opts.isa = file_mips_isa; break; |
11154 | case 1: mips_opts.isa = ISA_MIPS1; break; | |
11155 | case 2: mips_opts.isa = ISA_MIPS2; break; | |
11156 | case 3: mips_opts.isa = ISA_MIPS3; break; | |
84ea6cf2 | 11157 | case 4: mips_opts.isa = ISA_MIPS4; break; |
9a41af64 | 11158 | case 5: mips_opts.isa = ISA_MIPS5; break; |
84ea6cf2 NC |
11159 | case 32: mips_opts.isa = ISA_MIPS32; break; |
11160 | case 64: mips_opts.isa = ISA_MIPS64; break; | |
a325df1d | 11161 | default: as_bad (_("unknown ISA level %s"), name + 4); break; |
e7af610e | 11162 | } |
252b5132 RH |
11163 | } |
11164 | else if (strcmp (name, "autoextend") == 0) | |
11165 | mips_opts.noautoextend = 0; | |
11166 | else if (strcmp (name, "noautoextend") == 0) | |
11167 | mips_opts.noautoextend = 1; | |
11168 | else if (strcmp (name, "push") == 0) | |
11169 | { | |
11170 | struct mips_option_stack *s; | |
11171 | ||
11172 | s = (struct mips_option_stack *) xmalloc (sizeof *s); | |
11173 | s->next = mips_opts_stack; | |
11174 | s->options = mips_opts; | |
11175 | mips_opts_stack = s; | |
11176 | } | |
11177 | else if (strcmp (name, "pop") == 0) | |
11178 | { | |
11179 | struct mips_option_stack *s; | |
11180 | ||
11181 | s = mips_opts_stack; | |
11182 | if (s == NULL) | |
11183 | as_bad (_(".set pop with no .set push")); | |
11184 | else | |
11185 | { | |
11186 | /* If we're changing the reorder mode we need to handle | |
11187 | delay slots correctly. */ | |
11188 | if (s->options.noreorder && ! mips_opts.noreorder) | |
11189 | mips_emit_delays (true); | |
11190 | else if (! s->options.noreorder && mips_opts.noreorder) | |
11191 | { | |
11192 | if (prev_nop_frag != NULL) | |
11193 | { | |
11194 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds | |
11195 | * (mips_opts.mips16 ? 2 : 4)); | |
11196 | prev_nop_frag = NULL; | |
11197 | } | |
11198 | } | |
11199 | ||
11200 | mips_opts = s->options; | |
11201 | mips_opts_stack = s->next; | |
11202 | free (s); | |
11203 | } | |
11204 | } | |
11205 | else | |
11206 | { | |
11207 | as_warn (_("Tried to set unrecognized symbol: %s\n"), name); | |
11208 | } | |
11209 | *input_line_pointer = ch; | |
11210 | demand_empty_rest_of_line (); | |
11211 | } | |
11212 | ||
11213 | /* Handle the .abicalls pseudo-op. I believe this is equivalent to | |
11214 | .option pic2. It means to generate SVR4 PIC calls. */ | |
11215 | ||
11216 | static void | |
11217 | s_abicalls (ignore) | |
43841e91 | 11218 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11219 | { |
11220 | mips_pic = SVR4_PIC; | |
11221 | if (USE_GLOBAL_POINTER_OPT) | |
11222 | { | |
11223 | if (g_switch_seen && g_switch_value != 0) | |
11224 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
11225 | g_switch_value = 0; | |
11226 | } | |
11227 | bfd_set_gp_size (stdoutput, 0); | |
11228 | demand_empty_rest_of_line (); | |
11229 | } | |
11230 | ||
11231 | /* Handle the .cpload pseudo-op. This is used when generating SVR4 | |
11232 | PIC code. It sets the $gp register for the function based on the | |
11233 | function address, which is in the register named in the argument. | |
11234 | This uses a relocation against _gp_disp, which is handled specially | |
11235 | by the linker. The result is: | |
11236 | lui $gp,%hi(_gp_disp) | |
11237 | addiu $gp,$gp,%lo(_gp_disp) | |
11238 | addu $gp,$gp,.cpload argument | |
11239 | The .cpload argument is normally $25 == $t9. */ | |
11240 | ||
11241 | static void | |
11242 | s_cpload (ignore) | |
43841e91 | 11243 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11244 | { |
11245 | expressionS ex; | |
11246 | int icnt = 0; | |
11247 | ||
6478892d TS |
11248 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
11249 | .cpload is ignored. */ | |
11250 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) | |
252b5132 RH |
11251 | { |
11252 | s_ignore (0); | |
11253 | return; | |
11254 | } | |
11255 | ||
d3ecfc59 | 11256 | /* .cpload should be in a .set noreorder section. */ |
252b5132 RH |
11257 | if (mips_opts.noreorder == 0) |
11258 | as_warn (_(".cpload not in noreorder section")); | |
11259 | ||
11260 | ex.X_op = O_symbol; | |
11261 | ex.X_add_symbol = symbol_find_or_make ("_gp_disp"); | |
11262 | ex.X_op_symbol = NULL; | |
11263 | ex.X_add_number = 0; | |
11264 | ||
11265 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ | |
49309057 | 11266 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
252b5132 | 11267 | |
c4e7957c | 11268 | macro_build_lui (NULL, &icnt, &ex, GP); |
252b5132 RH |
11269 | macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP, |
11270 | (int) BFD_RELOC_LO16); | |
11271 | ||
11272 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t", | |
11273 | GP, GP, tc_get_register (0)); | |
11274 | ||
11275 | demand_empty_rest_of_line (); | |
11276 | } | |
11277 | ||
6478892d TS |
11278 | /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is: |
11279 | .cpsetup $reg1, offset|$reg2, label | |
11280 | ||
11281 | If offset is given, this results in: | |
11282 | sd $gp, offset($sp) | |
11283 | lui $gp, %gp_rel(%neg(%hi(label))) | |
11284 | daddiu $gp, $gp, %gp_rel(%neg(%lo(label))) | |
11285 | addu $gp, $gp, $reg1 | |
11286 | ||
11287 | If $reg2 is given, this results in: | |
11288 | daddu $reg2, $gp, $0 | |
11289 | lui $gp, %gp_rel(%neg(%hi(label))) | |
11290 | daddiu $gp, $gp, %gp_rel(%neg(%lo(label))) | |
11291 | addu $gp, $gp, $reg1 | |
11292 | */ | |
11293 | static void | |
11294 | s_cpsetup (ignore) | |
11295 | int ignore ATTRIBUTE_UNUSED; | |
11296 | { | |
11297 | expressionS ex_off; | |
11298 | expressionS ex_sym; | |
11299 | int reg1; | |
11300 | int icnt = 0; | |
11301 | char *sym; | |
11302 | ||
11303 | /* If we are not generating SVR4 PIC code, .cpload is ignored. | |
11304 | We also need NewABI support. */ | |
11305 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
11306 | { | |
11307 | s_ignore (0); | |
11308 | return; | |
11309 | } | |
11310 | ||
11311 | reg1 = tc_get_register (0); | |
11312 | SKIP_WHITESPACE (); | |
11313 | if (*input_line_pointer != ',') | |
11314 | { | |
11315 | as_bad (_("missing argument separator ',' for .cpsetup")); | |
11316 | return; | |
11317 | } | |
11318 | else | |
11319 | input_line_pointer++; | |
11320 | SKIP_WHITESPACE (); | |
11321 | if (*input_line_pointer == '$') | |
11322 | mips_cpreturn_register = tc_get_register (0); | |
11323 | else | |
11324 | mips_cpreturn_offset = get_absolute_expression (); | |
11325 | SKIP_WHITESPACE (); | |
11326 | if (*input_line_pointer != ',') | |
11327 | { | |
11328 | as_bad (_("missing argument separator ',' for .cpsetup")); | |
11329 | return; | |
11330 | } | |
11331 | else | |
11332 | input_line_pointer++; | |
11333 | SKIP_WHITESPACE (); | |
11334 | sym = input_line_pointer; | |
11335 | while (ISALNUM (*input_line_pointer)) | |
11336 | input_line_pointer++; | |
11337 | *input_line_pointer = 0; | |
11338 | ||
11339 | ex_sym.X_op = O_symbol; | |
11340 | ex_sym.X_add_symbol = symbol_find_or_make (sym); | |
11341 | ex_sym.X_op_symbol = NULL; | |
11342 | ex_sym.X_add_number = 0; | |
11343 | ||
11344 | if (mips_cpreturn_register == -1) | |
11345 | { | |
11346 | ex_off.X_op = O_constant; | |
11347 | ex_off.X_add_symbol = NULL; | |
11348 | ex_off.X_op_symbol = NULL; | |
11349 | ex_off.X_add_number = mips_cpreturn_offset; | |
11350 | ||
11351 | macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)", | |
11352 | mips_gp_register, (int) BFD_RELOC_LO16, SP); | |
11353 | } | |
11354 | else | |
11355 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu", | |
11356 | "d,v,t", mips_cpreturn_register, mips_gp_register, 0); | |
11357 | ||
11358 | macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register, | |
11359 | (int) BFD_RELOC_GPREL16); | |
11360 | fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0, | |
11361 | NULL, 0, 0, BFD_RELOC_MIPS_SUB); | |
11362 | fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0, | |
11363 | NULL, 0, 0, BFD_RELOC_HI16_S); | |
11364 | macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j", | |
11365 | mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16); | |
11366 | fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0, | |
11367 | NULL, 0, 0, BFD_RELOC_MIPS_SUB); | |
11368 | fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0, | |
11369 | NULL, 0, 0, BFD_RELOC_LO16); | |
11370 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu", | |
11371 | "d,v,t", mips_gp_register, mips_gp_register, reg1); | |
11372 | ||
11373 | demand_empty_rest_of_line (); | |
11374 | } | |
11375 | ||
11376 | static void | |
11377 | s_cplocal (ignore) | |
11378 | int ignore ATTRIBUTE_UNUSED; | |
11379 | { | |
11380 | /* If we are not generating SVR4 PIC code, or if this is not NewABI code, | |
11381 | .cplocal is ignored. */ | |
11382 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
11383 | { | |
11384 | s_ignore (0); | |
11385 | return; | |
11386 | } | |
11387 | ||
11388 | mips_gp_register = tc_get_register (0); | |
11389 | } | |
11390 | ||
252b5132 RH |
11391 | /* Handle the .cprestore pseudo-op. This stores $gp into a given |
11392 | offset from $sp. The offset is remembered, and after making a PIC | |
11393 | call $gp is restored from that location. */ | |
11394 | ||
11395 | static void | |
11396 | s_cprestore (ignore) | |
43841e91 | 11397 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11398 | { |
11399 | expressionS ex; | |
11400 | int icnt = 0; | |
11401 | ||
6478892d TS |
11402 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
11403 | .cprestore is ignored. */ | |
11404 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) | |
252b5132 RH |
11405 | { |
11406 | s_ignore (0); | |
11407 | return; | |
11408 | } | |
11409 | ||
11410 | mips_cprestore_offset = get_absolute_expression (); | |
11411 | ||
11412 | ex.X_op = O_constant; | |
11413 | ex.X_add_symbol = NULL; | |
11414 | ex.X_op_symbol = NULL; | |
11415 | ex.X_add_number = mips_cprestore_offset; | |
11416 | ||
11417 | macro_build ((char *) NULL, &icnt, &ex, | |
ca4e0257 | 11418 | HAVE_32BIT_ADDRESSES ? "sw" : "sd", |
252b5132 RH |
11419 | "t,o(b)", GP, (int) BFD_RELOC_LO16, SP); |
11420 | ||
11421 | demand_empty_rest_of_line (); | |
11422 | } | |
11423 | ||
6478892d TS |
11424 | /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset |
11425 | was given in the preceeding .gpsetup, it results in: | |
11426 | ld $gp, offset($sp) | |
76b3015f | 11427 | |
6478892d TS |
11428 | If a register $reg2 was given there, it results in: |
11429 | daddiu $gp, $gp, $reg2 | |
11430 | */ | |
11431 | static void | |
11432 | s_cpreturn (ignore) | |
11433 | int ignore ATTRIBUTE_UNUSED; | |
11434 | { | |
11435 | expressionS ex; | |
11436 | int icnt = 0; | |
11437 | ||
11438 | /* If we are not generating SVR4 PIC code, .cpreturn is ignored. | |
11439 | We also need NewABI support. */ | |
11440 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
11441 | { | |
11442 | s_ignore (0); | |
11443 | return; | |
11444 | } | |
11445 | ||
11446 | if (mips_cpreturn_register == -1) | |
11447 | { | |
11448 | ex.X_op = O_constant; | |
11449 | ex.X_add_symbol = NULL; | |
11450 | ex.X_op_symbol = NULL; | |
11451 | ex.X_add_number = mips_cpreturn_offset; | |
11452 | ||
11453 | macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)", | |
11454 | mips_gp_register, (int) BFD_RELOC_LO16, SP); | |
11455 | } | |
11456 | else | |
11457 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu", | |
11458 | "d,v,t", mips_gp_register, mips_cpreturn_register, 0); | |
11459 | ||
11460 | demand_empty_rest_of_line (); | |
11461 | } | |
11462 | ||
11463 | /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC | |
11464 | code. It sets the offset to use in gp_rel relocations. */ | |
11465 | ||
11466 | static void | |
11467 | s_gpvalue (ignore) | |
11468 | int ignore ATTRIBUTE_UNUSED; | |
11469 | { | |
11470 | /* If we are not generating SVR4 PIC code, .gpvalue is ignored. | |
11471 | We also need NewABI support. */ | |
11472 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
11473 | { | |
11474 | s_ignore (0); | |
11475 | return; | |
11476 | } | |
11477 | ||
11478 | mips_cpreturn_offset = get_absolute_expression (); | |
11479 | ||
11480 | demand_empty_rest_of_line (); | |
11481 | } | |
11482 | ||
252b5132 RH |
11483 | /* Handle the .gpword pseudo-op. This is used when generating PIC |
11484 | code. It generates a 32 bit GP relative reloc. */ | |
11485 | ||
11486 | static void | |
11487 | s_gpword (ignore) | |
43841e91 | 11488 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11489 | { |
11490 | symbolS *label; | |
11491 | expressionS ex; | |
11492 | char *p; | |
11493 | ||
11494 | /* When not generating PIC code, this is treated as .word. */ | |
11495 | if (mips_pic != SVR4_PIC) | |
11496 | { | |
11497 | s_cons (2); | |
11498 | return; | |
11499 | } | |
11500 | ||
11501 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
11502 | mips_emit_delays (true); | |
11503 | if (auto_align) | |
11504 | mips_align (2, 0, label); | |
11505 | mips_clear_insn_labels (); | |
11506 | ||
11507 | expression (&ex); | |
11508 | ||
11509 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
11510 | { | |
11511 | as_bad (_("Unsupported use of .gpword")); | |
11512 | ignore_rest_of_line (); | |
11513 | } | |
11514 | ||
11515 | p = frag_more (4); | |
11516 | md_number_to_chars (p, (valueT) 0, 4); | |
11517 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0, | |
cdf6fd85 | 11518 | BFD_RELOC_GPREL32); |
252b5132 RH |
11519 | |
11520 | demand_empty_rest_of_line (); | |
11521 | } | |
11522 | ||
11523 | /* Handle the .cpadd pseudo-op. This is used when dealing with switch | |
11524 | tables in SVR4 PIC code. */ | |
11525 | ||
11526 | static void | |
11527 | s_cpadd (ignore) | |
43841e91 | 11528 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11529 | { |
11530 | int icnt = 0; | |
11531 | int reg; | |
11532 | ||
6478892d TS |
11533 | /* This is ignored when not generating SVR4 PIC code or if this is NewABI |
11534 | code. */ | |
11535 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) | |
252b5132 RH |
11536 | { |
11537 | s_ignore (0); | |
11538 | return; | |
11539 | } | |
11540 | ||
11541 | /* Add $gp to the register named as an argument. */ | |
11542 | reg = tc_get_register (0); | |
11543 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 11544 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
11545 | "d,v,t", reg, reg, GP); |
11546 | ||
bdaaa2e1 | 11547 | demand_empty_rest_of_line (); |
252b5132 RH |
11548 | } |
11549 | ||
11550 | /* Handle the .insn pseudo-op. This marks instruction labels in | |
11551 | mips16 mode. This permits the linker to handle them specially, | |
11552 | such as generating jalx instructions when needed. We also make | |
11553 | them odd for the duration of the assembly, in order to generate the | |
11554 | right sort of code. We will make them even in the adjust_symtab | |
11555 | routine, while leaving them marked. This is convenient for the | |
11556 | debugger and the disassembler. The linker knows to make them odd | |
11557 | again. */ | |
11558 | ||
11559 | static void | |
11560 | s_insn (ignore) | |
43841e91 | 11561 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11562 | { |
11563 | if (mips_opts.mips16) | |
11564 | mips16_mark_labels (); | |
11565 | ||
11566 | demand_empty_rest_of_line (); | |
11567 | } | |
11568 | ||
11569 | /* Handle a .stabn directive. We need these in order to mark a label | |
11570 | as being a mips16 text label correctly. Sometimes the compiler | |
11571 | will emit a label, followed by a .stabn, and then switch sections. | |
11572 | If the label and .stabn are in mips16 mode, then the label is | |
11573 | really a mips16 text label. */ | |
11574 | ||
11575 | static void | |
11576 | s_mips_stab (type) | |
11577 | int type; | |
11578 | { | |
11579 | if (type == 'n' && mips_opts.mips16) | |
11580 | mips16_mark_labels (); | |
11581 | ||
11582 | s_stab (type); | |
11583 | } | |
11584 | ||
11585 | /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. | |
11586 | */ | |
11587 | ||
11588 | static void | |
11589 | s_mips_weakext (ignore) | |
43841e91 | 11590 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11591 | { |
11592 | char *name; | |
11593 | int c; | |
11594 | symbolS *symbolP; | |
11595 | expressionS exp; | |
11596 | ||
11597 | name = input_line_pointer; | |
11598 | c = get_symbol_end (); | |
11599 | symbolP = symbol_find_or_make (name); | |
11600 | S_SET_WEAK (symbolP); | |
11601 | *input_line_pointer = c; | |
11602 | ||
11603 | SKIP_WHITESPACE (); | |
11604 | ||
11605 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
11606 | { | |
11607 | if (S_IS_DEFINED (symbolP)) | |
11608 | { | |
11609 | as_bad ("Ignoring attempt to redefine symbol `%s'.", | |
11610 | S_GET_NAME (symbolP)); | |
11611 | ignore_rest_of_line (); | |
11612 | return; | |
11613 | } | |
bdaaa2e1 | 11614 | |
252b5132 RH |
11615 | if (*input_line_pointer == ',') |
11616 | { | |
11617 | ++input_line_pointer; | |
11618 | SKIP_WHITESPACE (); | |
11619 | } | |
bdaaa2e1 | 11620 | |
252b5132 RH |
11621 | expression (&exp); |
11622 | if (exp.X_op != O_symbol) | |
11623 | { | |
11624 | as_bad ("bad .weakext directive"); | |
11625 | ignore_rest_of_line(); | |
11626 | return; | |
11627 | } | |
49309057 | 11628 | symbol_set_value_expression (symbolP, &exp); |
252b5132 RH |
11629 | } |
11630 | ||
11631 | demand_empty_rest_of_line (); | |
11632 | } | |
11633 | ||
11634 | /* Parse a register string into a number. Called from the ECOFF code | |
11635 | to parse .frame. The argument is non-zero if this is the frame | |
11636 | register, so that we can record it in mips_frame_reg. */ | |
11637 | ||
11638 | int | |
11639 | tc_get_register (frame) | |
11640 | int frame; | |
11641 | { | |
11642 | int reg; | |
11643 | ||
11644 | SKIP_WHITESPACE (); | |
11645 | if (*input_line_pointer++ != '$') | |
11646 | { | |
11647 | as_warn (_("expected `$'")); | |
11648 | reg = 0; | |
11649 | } | |
3882b010 | 11650 | else if (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
11651 | { |
11652 | reg = get_absolute_expression (); | |
11653 | if (reg < 0 || reg >= 32) | |
11654 | { | |
11655 | as_warn (_("Bad register number")); | |
11656 | reg = 0; | |
11657 | } | |
11658 | } | |
11659 | else | |
11660 | { | |
11661 | if (strncmp (input_line_pointer, "fp", 2) == 0) | |
11662 | reg = FP; | |
11663 | else if (strncmp (input_line_pointer, "sp", 2) == 0) | |
11664 | reg = SP; | |
11665 | else if (strncmp (input_line_pointer, "gp", 2) == 0) | |
11666 | reg = GP; | |
11667 | else if (strncmp (input_line_pointer, "at", 2) == 0) | |
11668 | reg = AT; | |
11669 | else | |
11670 | { | |
11671 | as_warn (_("Unrecognized register name")); | |
11672 | reg = 0; | |
11673 | } | |
11674 | input_line_pointer += 2; | |
11675 | } | |
11676 | if (frame) | |
11677 | mips_frame_reg = reg != 0 ? reg : SP; | |
11678 | return reg; | |
11679 | } | |
11680 | ||
11681 | valueT | |
11682 | md_section_align (seg, addr) | |
11683 | asection *seg; | |
11684 | valueT addr; | |
11685 | { | |
11686 | int align = bfd_get_section_alignment (stdoutput, seg); | |
11687 | ||
11688 | #ifdef OBJ_ELF | |
11689 | /* We don't need to align ELF sections to the full alignment. | |
11690 | However, Irix 5 may prefer that we align them at least to a 16 | |
11691 | byte boundary. We don't bother to align the sections if we are | |
11692 | targeted for an embedded system. */ | |
11693 | if (strcmp (TARGET_OS, "elf") == 0) | |
11694 | return addr; | |
11695 | if (align > 4) | |
11696 | align = 4; | |
11697 | #endif | |
11698 | ||
11699 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
11700 | } | |
11701 | ||
11702 | /* Utility routine, called from above as well. If called while the | |
11703 | input file is still being read, it's only an approximation. (For | |
11704 | example, a symbol may later become defined which appeared to be | |
11705 | undefined earlier.) */ | |
11706 | ||
11707 | static int | |
11708 | nopic_need_relax (sym, before_relaxing) | |
11709 | symbolS *sym; | |
11710 | int before_relaxing; | |
11711 | { | |
11712 | if (sym == 0) | |
11713 | return 0; | |
11714 | ||
6478892d | 11715 | if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0) |
252b5132 RH |
11716 | { |
11717 | const char *symname; | |
11718 | int change; | |
11719 | ||
11720 | /* Find out whether this symbol can be referenced off the GP | |
11721 | register. It can be if it is smaller than the -G size or if | |
11722 | it is in the .sdata or .sbss section. Certain symbols can | |
11723 | not be referenced off the GP, although it appears as though | |
11724 | they can. */ | |
11725 | symname = S_GET_NAME (sym); | |
11726 | if (symname != (const char *) NULL | |
11727 | && (strcmp (symname, "eprol") == 0 | |
11728 | || strcmp (symname, "etext") == 0 | |
11729 | || strcmp (symname, "_gp") == 0 | |
11730 | || strcmp (symname, "edata") == 0 | |
11731 | || strcmp (symname, "_fbss") == 0 | |
11732 | || strcmp (symname, "_fdata") == 0 | |
11733 | || strcmp (symname, "_ftext") == 0 | |
11734 | || strcmp (symname, "end") == 0 | |
11735 | || strcmp (symname, "_gp_disp") == 0)) | |
11736 | change = 1; | |
11737 | else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym)) | |
11738 | && (0 | |
11739 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 ILT |
11740 | || (symbol_get_obj (sym)->ecoff_extern_size != 0 |
11741 | && (symbol_get_obj (sym)->ecoff_extern_size | |
11742 | <= g_switch_value)) | |
252b5132 RH |
11743 | #endif |
11744 | /* We must defer this decision until after the whole | |
11745 | file has been read, since there might be a .extern | |
11746 | after the first use of this symbol. */ | |
11747 | || (before_relaxing | |
11748 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 | 11749 | && symbol_get_obj (sym)->ecoff_extern_size == 0 |
252b5132 RH |
11750 | #endif |
11751 | && S_GET_VALUE (sym) == 0) | |
11752 | || (S_GET_VALUE (sym) != 0 | |
11753 | && S_GET_VALUE (sym) <= g_switch_value))) | |
11754 | change = 0; | |
11755 | else | |
11756 | { | |
11757 | const char *segname; | |
11758 | ||
11759 | segname = segment_name (S_GET_SEGMENT (sym)); | |
11760 | assert (strcmp (segname, ".lit8") != 0 | |
11761 | && strcmp (segname, ".lit4") != 0); | |
11762 | change = (strcmp (segname, ".sdata") != 0 | |
fba2b7f9 GK |
11763 | && strcmp (segname, ".sbss") != 0 |
11764 | && strncmp (segname, ".sdata.", 7) != 0 | |
11765 | && strncmp (segname, ".gnu.linkonce.s.", 16) != 0); | |
252b5132 RH |
11766 | } |
11767 | return change; | |
11768 | } | |
11769 | else | |
11770 | /* We are not optimizing for the GP register. */ | |
11771 | return 1; | |
11772 | } | |
11773 | ||
11774 | /* Given a mips16 variant frag FRAGP, return non-zero if it needs an | |
11775 | extended opcode. SEC is the section the frag is in. */ | |
11776 | ||
11777 | static int | |
11778 | mips16_extended_frag (fragp, sec, stretch) | |
11779 | fragS *fragp; | |
11780 | asection *sec; | |
11781 | long stretch; | |
11782 | { | |
11783 | int type; | |
11784 | register const struct mips16_immed_operand *op; | |
11785 | offsetT val; | |
11786 | int mintiny, maxtiny; | |
11787 | segT symsec; | |
98aa84af | 11788 | fragS *sym_frag; |
252b5132 RH |
11789 | |
11790 | if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) | |
11791 | return 0; | |
11792 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) | |
11793 | return 1; | |
11794 | ||
11795 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
11796 | op = mips16_immed_operands; | |
11797 | while (op->type != type) | |
11798 | { | |
11799 | ++op; | |
11800 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
11801 | } | |
11802 | ||
11803 | if (op->unsp) | |
11804 | { | |
11805 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
11806 | { | |
11807 | mintiny = 1; | |
11808 | maxtiny = 1 << op->nbits; | |
11809 | } | |
11810 | else | |
11811 | { | |
11812 | mintiny = 0; | |
11813 | maxtiny = (1 << op->nbits) - 1; | |
11814 | } | |
11815 | } | |
11816 | else | |
11817 | { | |
11818 | mintiny = - (1 << (op->nbits - 1)); | |
11819 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
11820 | } | |
11821 | ||
98aa84af | 11822 | sym_frag = symbol_get_frag (fragp->fr_symbol); |
ac62c346 | 11823 | val = S_GET_VALUE (fragp->fr_symbol); |
98aa84af | 11824 | symsec = S_GET_SEGMENT (fragp->fr_symbol); |
252b5132 RH |
11825 | |
11826 | if (op->pcrel) | |
11827 | { | |
11828 | addressT addr; | |
11829 | ||
11830 | /* We won't have the section when we are called from | |
11831 | mips_relax_frag. However, we will always have been called | |
11832 | from md_estimate_size_before_relax first. If this is a | |
11833 | branch to a different section, we mark it as such. If SEC is | |
11834 | NULL, and the frag is not marked, then it must be a branch to | |
11835 | the same section. */ | |
11836 | if (sec == NULL) | |
11837 | { | |
11838 | if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype)) | |
11839 | return 1; | |
11840 | } | |
11841 | else | |
11842 | { | |
98aa84af | 11843 | /* Must have been called from md_estimate_size_before_relax. */ |
252b5132 RH |
11844 | if (symsec != sec) |
11845 | { | |
11846 | fragp->fr_subtype = | |
11847 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11848 | ||
11849 | /* FIXME: We should support this, and let the linker | |
11850 | catch branches and loads that are out of range. */ | |
11851 | as_bad_where (fragp->fr_file, fragp->fr_line, | |
11852 | _("unsupported PC relative reference to different section")); | |
11853 | ||
11854 | return 1; | |
11855 | } | |
98aa84af AM |
11856 | if (fragp != sym_frag && sym_frag->fr_address == 0) |
11857 | /* Assume non-extended on the first relaxation pass. | |
11858 | The address we have calculated will be bogus if this is | |
11859 | a forward branch to another frag, as the forward frag | |
11860 | will have fr_address == 0. */ | |
11861 | return 0; | |
252b5132 RH |
11862 | } |
11863 | ||
11864 | /* In this case, we know for sure that the symbol fragment is in | |
98aa84af AM |
11865 | the same section. If the relax_marker of the symbol fragment |
11866 | differs from the relax_marker of this fragment, we have not | |
11867 | yet adjusted the symbol fragment fr_address. We want to add | |
252b5132 RH |
11868 | in STRETCH in order to get a better estimate of the address. |
11869 | This particularly matters because of the shift bits. */ | |
11870 | if (stretch != 0 | |
98aa84af | 11871 | && sym_frag->relax_marker != fragp->relax_marker) |
252b5132 RH |
11872 | { |
11873 | fragS *f; | |
11874 | ||
11875 | /* Adjust stretch for any alignment frag. Note that if have | |
11876 | been expanding the earlier code, the symbol may be | |
11877 | defined in what appears to be an earlier frag. FIXME: | |
11878 | This doesn't handle the fr_subtype field, which specifies | |
11879 | a maximum number of bytes to skip when doing an | |
11880 | alignment. */ | |
98aa84af | 11881 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) |
252b5132 RH |
11882 | { |
11883 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
11884 | { | |
11885 | if (stretch < 0) | |
11886 | stretch = - ((- stretch) | |
11887 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
11888 | else | |
11889 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
11890 | if (stretch == 0) | |
11891 | break; | |
11892 | } | |
11893 | } | |
11894 | if (f != NULL) | |
11895 | val += stretch; | |
11896 | } | |
11897 | ||
11898 | addr = fragp->fr_address + fragp->fr_fix; | |
11899 | ||
11900 | /* The base address rules are complicated. The base address of | |
11901 | a branch is the following instruction. The base address of a | |
11902 | PC relative load or add is the instruction itself, but if it | |
11903 | is in a delay slot (in which case it can not be extended) use | |
11904 | the address of the instruction whose delay slot it is in. */ | |
11905 | if (type == 'p' || type == 'q') | |
11906 | { | |
11907 | addr += 2; | |
11908 | ||
11909 | /* If we are currently assuming that this frag should be | |
11910 | extended, then, the current address is two bytes | |
bdaaa2e1 | 11911 | higher. */ |
252b5132 RH |
11912 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
11913 | addr += 2; | |
11914 | ||
11915 | /* Ignore the low bit in the target, since it will be set | |
11916 | for a text label. */ | |
11917 | if ((val & 1) != 0) | |
11918 | --val; | |
11919 | } | |
11920 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
11921 | addr -= 4; | |
11922 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
11923 | addr -= 2; | |
11924 | ||
11925 | val -= addr & ~ ((1 << op->shift) - 1); | |
11926 | ||
11927 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
11928 | if (type == 'p' || type == 'q') | |
11929 | val /= 2; | |
11930 | ||
11931 | /* If any of the shifted bits are set, we must use an extended | |
11932 | opcode. If the address depends on the size of this | |
11933 | instruction, this can lead to a loop, so we arrange to always | |
11934 | use an extended opcode. We only check this when we are in | |
11935 | the main relaxation loop, when SEC is NULL. */ | |
11936 | if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL) | |
11937 | { | |
11938 | fragp->fr_subtype = | |
11939 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11940 | return 1; | |
11941 | } | |
11942 | ||
11943 | /* If we are about to mark a frag as extended because the value | |
11944 | is precisely maxtiny + 1, then there is a chance of an | |
11945 | infinite loop as in the following code: | |
11946 | la $4,foo | |
11947 | .skip 1020 | |
11948 | .align 2 | |
11949 | foo: | |
11950 | In this case when the la is extended, foo is 0x3fc bytes | |
11951 | away, so the la can be shrunk, but then foo is 0x400 away, so | |
11952 | the la must be extended. To avoid this loop, we mark the | |
11953 | frag as extended if it was small, and is about to become | |
11954 | extended with a value of maxtiny + 1. */ | |
11955 | if (val == ((maxtiny + 1) << op->shift) | |
11956 | && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype) | |
11957 | && sec == NULL) | |
11958 | { | |
11959 | fragp->fr_subtype = | |
11960 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11961 | return 1; | |
11962 | } | |
11963 | } | |
11964 | else if (symsec != absolute_section && sec != NULL) | |
11965 | as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation")); | |
11966 | ||
11967 | if ((val & ((1 << op->shift) - 1)) != 0 | |
11968 | || val < (mintiny << op->shift) | |
11969 | || val > (maxtiny << op->shift)) | |
11970 | return 1; | |
11971 | else | |
11972 | return 0; | |
11973 | } | |
11974 | ||
11975 | /* Estimate the size of a frag before relaxing. Unless this is the | |
11976 | mips16, we are not really relaxing here, and the final size is | |
11977 | encoded in the subtype information. For the mips16, we have to | |
11978 | decide whether we are using an extended opcode or not. */ | |
11979 | ||
252b5132 RH |
11980 | int |
11981 | md_estimate_size_before_relax (fragp, segtype) | |
11982 | fragS *fragp; | |
11983 | asection *segtype; | |
11984 | { | |
43841e91 | 11985 | int change = 0; |
8614eeee | 11986 | boolean linkonce = false; |
252b5132 RH |
11987 | |
11988 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
11989 | { | |
11990 | if (mips16_extended_frag (fragp, segtype, 0)) | |
11991 | { | |
11992 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
11993 | return 4; | |
11994 | } | |
11995 | else | |
11996 | { | |
11997 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
11998 | return 2; | |
11999 | } | |
12000 | } | |
12001 | ||
12002 | if (mips_pic == NO_PIC) | |
12003 | { | |
12004 | change = nopic_need_relax (fragp->fr_symbol, 0); | |
12005 | } | |
12006 | else if (mips_pic == SVR4_PIC) | |
12007 | { | |
12008 | symbolS *sym; | |
12009 | asection *symsec; | |
12010 | ||
12011 | sym = fragp->fr_symbol; | |
12012 | ||
12013 | /* Handle the case of a symbol equated to another symbol. */ | |
e0890092 | 12014 | while (symbol_equated_reloc_p (sym)) |
252b5132 RH |
12015 | { |
12016 | symbolS *n; | |
12017 | ||
12018 | /* It's possible to get a loop here in a badly written | |
12019 | program. */ | |
49309057 | 12020 | n = symbol_get_value_expression (sym)->X_add_symbol; |
252b5132 RH |
12021 | if (n == sym) |
12022 | break; | |
12023 | sym = n; | |
12024 | } | |
12025 | ||
12026 | symsec = S_GET_SEGMENT (sym); | |
12027 | ||
8614eeee UC |
12028 | /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */ |
12029 | if (symsec != segtype && ! S_IS_LOCAL (sym)) | |
beae10d5 KH |
12030 | { |
12031 | if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) | |
12032 | != 0) | |
12033 | linkonce = true; | |
12034 | ||
12035 | /* The GNU toolchain uses an extension for ELF: a section | |
12036 | beginning with the magic string .gnu.linkonce is a linkonce | |
12037 | section. */ | |
12038 | if (strncmp (segment_name (symsec), ".gnu.linkonce", | |
12039 | sizeof ".gnu.linkonce" - 1) == 0) | |
12040 | linkonce = true; | |
12041 | } | |
8614eeee | 12042 | |
252b5132 RH |
12043 | /* This must duplicate the test in adjust_reloc_syms. */ |
12044 | change = (symsec != &bfd_und_section | |
12045 | && symsec != &bfd_abs_section | |
426b0403 | 12046 | && ! bfd_is_com_section (symsec) |
8614eeee | 12047 | && !linkonce |
426b0403 | 12048 | #ifdef OBJ_ELF |
ea4ff978 | 12049 | /* A global or weak symbol is treated as external. */ |
46bac6de L |
12050 | && (OUTPUT_FLAVOR == bfd_target_elf_flavour |
12051 | && ! (S_IS_EXTERN (sym) || S_IS_WEAK (sym))) | |
426b0403 AM |
12052 | #endif |
12053 | ); | |
252b5132 RH |
12054 | } |
12055 | else | |
12056 | abort (); | |
12057 | ||
12058 | if (change) | |
12059 | { | |
12060 | /* Record the offset to the first reloc in the fr_opcode field. | |
12061 | This lets md_convert_frag and tc_gen_reloc know that the code | |
12062 | must be expanded. */ | |
12063 | fragp->fr_opcode = (fragp->fr_literal | |
12064 | + fragp->fr_fix | |
12065 | - RELAX_OLD (fragp->fr_subtype) | |
12066 | + RELAX_RELOC1 (fragp->fr_subtype)); | |
12067 | /* FIXME: This really needs as_warn_where. */ | |
12068 | if (RELAX_WARN (fragp->fr_subtype)) | |
9a41af64 TS |
12069 | as_warn (_("AT used after \".set noat\" or macro used after " |
12070 | "\".set nomacro\"")); | |
12071 | ||
12072 | return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype); | |
252b5132 RH |
12073 | } |
12074 | ||
9a41af64 | 12075 | return 0; |
252b5132 RH |
12076 | } |
12077 | ||
12078 | /* This is called to see whether a reloc against a defined symbol | |
12079 | should be converted into a reloc against a section. Don't adjust | |
12080 | MIPS16 jump relocations, so we don't have to worry about the format | |
12081 | of the offset in the .o file. Don't adjust relocations against | |
12082 | mips16 symbols, so that the linker can find them if it needs to set | |
12083 | up a stub. */ | |
12084 | ||
12085 | int | |
12086 | mips_fix_adjustable (fixp) | |
12087 | fixS *fixp; | |
12088 | { | |
ea4ff978 L |
12089 | #ifdef OBJ_ELF |
12090 | /* Prevent all adjustments to global symbols. */ | |
46bac6de L |
12091 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
12092 | && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy))) | |
ea4ff978 L |
12093 | return 0; |
12094 | #endif | |
252b5132 RH |
12095 | if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP) |
12096 | return 0; | |
12097 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
12098 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
12099 | return 0; | |
12100 | if (fixp->fx_addsy == NULL) | |
12101 | return 1; | |
12102 | #ifdef OBJ_ELF | |
12103 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
12104 | && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16 | |
12105 | && fixp->fx_subsy == NULL) | |
12106 | return 0; | |
12107 | #endif | |
12108 | return 1; | |
12109 | } | |
12110 | ||
12111 | /* Translate internal representation of relocation info to BFD target | |
12112 | format. */ | |
12113 | ||
12114 | arelent ** | |
12115 | tc_gen_reloc (section, fixp) | |
43841e91 | 12116 | asection *section ATTRIBUTE_UNUSED; |
252b5132 RH |
12117 | fixS *fixp; |
12118 | { | |
12119 | static arelent *retval[4]; | |
12120 | arelent *reloc; | |
12121 | bfd_reloc_code_real_type code; | |
12122 | ||
12123 | reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent)); | |
12124 | retval[1] = NULL; | |
12125 | ||
49309057 ILT |
12126 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
12127 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
12128 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
12129 | ||
12130 | if (mips_pic == EMBEDDED_PIC | |
12131 | && SWITCH_TABLE (fixp)) | |
12132 | { | |
12133 | /* For a switch table entry we use a special reloc. The addend | |
12134 | is actually the difference between the reloc address and the | |
12135 | subtrahend. */ | |
12136 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); | |
12137 | if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour) | |
12138 | as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc")); | |
12139 | fixp->fx_r_type = BFD_RELOC_GPREL32; | |
12140 | } | |
bb2d6cd7 GK |
12141 | else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour) |
12142 | reloc->addend = fixp->fx_addnumber; | |
252b5132 RH |
12143 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16) |
12144 | { | |
12145 | /* We use a special addend for an internal RELLO reloc. */ | |
49309057 | 12146 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
12147 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); |
12148 | else | |
12149 | reloc->addend = fixp->fx_addnumber + reloc->address; | |
12150 | } | |
12151 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S) | |
12152 | { | |
12153 | assert (fixp->fx_next != NULL | |
12154 | && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16); | |
12155 | /* We use a special addend for an internal RELHI reloc. The | |
12156 | reloc is relative to the RELLO; adjust the addend | |
12157 | accordingly. */ | |
49309057 | 12158 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
12159 | reloc->addend = (fixp->fx_next->fx_frag->fr_address |
12160 | + fixp->fx_next->fx_where | |
12161 | - S_GET_VALUE (fixp->fx_subsy)); | |
12162 | else | |
12163 | reloc->addend = (fixp->fx_addnumber | |
12164 | + fixp->fx_next->fx_frag->fr_address | |
12165 | + fixp->fx_next->fx_where); | |
12166 | } | |
252b5132 RH |
12167 | else |
12168 | { | |
12169 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour) | |
12170 | /* A gruesome hack which is a result of the gruesome gas reloc | |
12171 | handling. */ | |
12172 | reloc->addend = reloc->address; | |
12173 | else | |
12174 | reloc->addend = -reloc->address; | |
12175 | } | |
12176 | ||
12177 | /* If this is a variant frag, we may need to adjust the existing | |
12178 | reloc and generate a new one. */ | |
12179 | if (fixp->fx_frag->fr_opcode != NULL | |
cdf6fd85 | 12180 | && (fixp->fx_r_type == BFD_RELOC_GPREL16 |
252b5132 RH |
12181 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16 |
12182 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16 | |
12183 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
12184 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16 | |
12185 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
6478892d TS |
12186 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16) |
12187 | && ! HAVE_NEWABI) | |
252b5132 RH |
12188 | { |
12189 | arelent *reloc2; | |
12190 | ||
12191 | assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype)); | |
12192 | ||
12193 | /* If this is not the last reloc in this frag, then we have two | |
12194 | GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a | |
12195 | CALL_HI16/CALL_LO16, both of which are being replaced. Let | |
12196 | the second one handle all of them. */ | |
12197 | if (fixp->fx_next != NULL | |
12198 | && fixp->fx_frag == fixp->fx_next->fx_frag) | |
12199 | { | |
cdf6fd85 TS |
12200 | assert ((fixp->fx_r_type == BFD_RELOC_GPREL16 |
12201 | && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16) | |
252b5132 RH |
12202 | || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 |
12203 | && (fixp->fx_next->fx_r_type | |
12204 | == BFD_RELOC_MIPS_GOT_LO16)) | |
12205 | || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
12206 | && (fixp->fx_next->fx_r_type | |
12207 | == BFD_RELOC_MIPS_CALL_LO16))); | |
12208 | retval[0] = NULL; | |
12209 | return retval; | |
12210 | } | |
12211 | ||
12212 | fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal; | |
12213 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
12214 | reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent)); | |
12215 | retval[2] = NULL; | |
49309057 ILT |
12216 | reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
12217 | *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
12218 | reloc2->address = (reloc->address |
12219 | + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype) | |
12220 | - RELAX_RELOC1 (fixp->fx_frag->fr_subtype))); | |
12221 | reloc2->addend = fixp->fx_addnumber; | |
12222 | reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16); | |
12223 | assert (reloc2->howto != NULL); | |
12224 | ||
12225 | if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype)) | |
12226 | { | |
12227 | arelent *reloc3; | |
12228 | ||
12229 | reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent)); | |
12230 | retval[3] = NULL; | |
12231 | *reloc3 = *reloc2; | |
12232 | reloc3->address += 4; | |
12233 | } | |
12234 | ||
12235 | if (mips_pic == NO_PIC) | |
12236 | { | |
cdf6fd85 | 12237 | assert (fixp->fx_r_type == BFD_RELOC_GPREL16); |
252b5132 RH |
12238 | fixp->fx_r_type = BFD_RELOC_HI16_S; |
12239 | } | |
12240 | else if (mips_pic == SVR4_PIC) | |
12241 | { | |
12242 | switch (fixp->fx_r_type) | |
12243 | { | |
12244 | default: | |
12245 | abort (); | |
12246 | case BFD_RELOC_MIPS_GOT16: | |
12247 | break; | |
12248 | case BFD_RELOC_MIPS_CALL16: | |
12249 | case BFD_RELOC_MIPS_GOT_LO16: | |
12250 | case BFD_RELOC_MIPS_CALL_LO16: | |
12251 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT16; | |
12252 | break; | |
12253 | } | |
12254 | } | |
12255 | else | |
12256 | abort (); | |
12257 | } | |
12258 | ||
12259 | /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry | |
12260 | to be used in the relocation's section offset. */ | |
12261 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
12262 | { | |
12263 | reloc->address = reloc->addend; | |
12264 | reloc->addend = 0; | |
12265 | } | |
12266 | ||
12267 | /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that | |
12268 | fixup_segment converted a non-PC relative reloc into a PC | |
12269 | relative reloc. In such a case, we need to convert the reloc | |
12270 | code. */ | |
12271 | code = fixp->fx_r_type; | |
12272 | if (fixp->fx_pcrel) | |
12273 | { | |
12274 | switch (code) | |
12275 | { | |
12276 | case BFD_RELOC_8: | |
12277 | code = BFD_RELOC_8_PCREL; | |
12278 | break; | |
12279 | case BFD_RELOC_16: | |
12280 | code = BFD_RELOC_16_PCREL; | |
12281 | break; | |
12282 | case BFD_RELOC_32: | |
12283 | code = BFD_RELOC_32_PCREL; | |
12284 | break; | |
12285 | case BFD_RELOC_64: | |
12286 | code = BFD_RELOC_64_PCREL; | |
12287 | break; | |
12288 | case BFD_RELOC_8_PCREL: | |
12289 | case BFD_RELOC_16_PCREL: | |
12290 | case BFD_RELOC_32_PCREL: | |
12291 | case BFD_RELOC_64_PCREL: | |
12292 | case BFD_RELOC_16_PCREL_S2: | |
12293 | case BFD_RELOC_PCREL_HI16_S: | |
12294 | case BFD_RELOC_PCREL_LO16: | |
12295 | break; | |
12296 | default: | |
12297 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12298 | _("Cannot make %s relocation PC relative"), | |
12299 | bfd_get_reloc_code_name (code)); | |
12300 | } | |
12301 | } | |
12302 | ||
add55e1f RS |
12303 | #ifdef OBJ_ELF |
12304 | /* md_apply_fix3 has a double-subtraction hack to get | |
12305 | bfd_install_relocation to behave nicely. GPREL relocations are | |
12306 | handled correctly without this hack, so undo it here. We can't | |
12307 | stop md_apply_fix3 from subtracting twice in the first place since | |
12308 | the fake addend is required for variant frags above. */ | |
12309 | if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour | |
d11008e1 | 12310 | && code == BFD_RELOC_GPREL16 |
add55e1f RS |
12311 | && reloc->addend != 0 |
12312 | && mips_need_elf_addend_fixup (fixp)) | |
12313 | reloc->addend += S_GET_VALUE (fixp->fx_addsy); | |
12314 | #endif | |
12315 | ||
252b5132 RH |
12316 | /* To support a PC relative reloc when generating embedded PIC code |
12317 | for ECOFF, we use a Cygnus extension. We check for that here to | |
12318 | make sure that we don't let such a reloc escape normally. */ | |
bb2d6cd7 GK |
12319 | if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
12320 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
252b5132 RH |
12321 | && code == BFD_RELOC_16_PCREL_S2 |
12322 | && mips_pic != EMBEDDED_PIC) | |
12323 | reloc->howto = NULL; | |
12324 | else | |
12325 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
12326 | ||
12327 | if (reloc->howto == NULL) | |
12328 | { | |
12329 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12330 | _("Can not represent %s relocation in this object file format"), | |
12331 | bfd_get_reloc_code_name (code)); | |
12332 | retval[0] = NULL; | |
12333 | } | |
12334 | ||
12335 | return retval; | |
12336 | } | |
12337 | ||
12338 | /* Relax a machine dependent frag. This returns the amount by which | |
12339 | the current size of the frag should change. */ | |
12340 | ||
12341 | int | |
12342 | mips_relax_frag (fragp, stretch) | |
12343 | fragS *fragp; | |
12344 | long stretch; | |
12345 | { | |
12346 | if (! RELAX_MIPS16_P (fragp->fr_subtype)) | |
12347 | return 0; | |
12348 | ||
c4e7957c | 12349 | if (mips16_extended_frag (fragp, NULL, stretch)) |
252b5132 RH |
12350 | { |
12351 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
12352 | return 0; | |
12353 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
12354 | return 2; | |
12355 | } | |
12356 | else | |
12357 | { | |
12358 | if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
12359 | return 0; | |
12360 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
12361 | return -2; | |
12362 | } | |
12363 | ||
12364 | return 0; | |
12365 | } | |
12366 | ||
12367 | /* Convert a machine dependent frag. */ | |
12368 | ||
12369 | void | |
12370 | md_convert_frag (abfd, asec, fragp) | |
43841e91 | 12371 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
12372 | segT asec; |
12373 | fragS *fragp; | |
12374 | { | |
12375 | int old, new; | |
12376 | char *fixptr; | |
12377 | ||
12378 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
12379 | { | |
12380 | int type; | |
12381 | register const struct mips16_immed_operand *op; | |
12382 | boolean small, ext; | |
12383 | offsetT val; | |
12384 | bfd_byte *buf; | |
12385 | unsigned long insn; | |
12386 | boolean use_extend; | |
12387 | unsigned short extend; | |
12388 | ||
12389 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
12390 | op = mips16_immed_operands; | |
12391 | while (op->type != type) | |
12392 | ++op; | |
12393 | ||
12394 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
12395 | { | |
12396 | small = false; | |
12397 | ext = true; | |
12398 | } | |
12399 | else | |
12400 | { | |
12401 | small = true; | |
12402 | ext = false; | |
12403 | } | |
12404 | ||
6386f3a7 | 12405 | resolve_symbol_value (fragp->fr_symbol); |
252b5132 RH |
12406 | val = S_GET_VALUE (fragp->fr_symbol); |
12407 | if (op->pcrel) | |
12408 | { | |
12409 | addressT addr; | |
12410 | ||
12411 | addr = fragp->fr_address + fragp->fr_fix; | |
12412 | ||
12413 | /* The rules for the base address of a PC relative reloc are | |
12414 | complicated; see mips16_extended_frag. */ | |
12415 | if (type == 'p' || type == 'q') | |
12416 | { | |
12417 | addr += 2; | |
12418 | if (ext) | |
12419 | addr += 2; | |
12420 | /* Ignore the low bit in the target, since it will be | |
12421 | set for a text label. */ | |
12422 | if ((val & 1) != 0) | |
12423 | --val; | |
12424 | } | |
12425 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
12426 | addr -= 4; | |
12427 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
12428 | addr -= 2; | |
12429 | ||
12430 | addr &= ~ (addressT) ((1 << op->shift) - 1); | |
12431 | val -= addr; | |
12432 | ||
12433 | /* Make sure the section winds up with the alignment we have | |
12434 | assumed. */ | |
12435 | if (op->shift > 0) | |
12436 | record_alignment (asec, op->shift); | |
12437 | } | |
12438 | ||
12439 | if (ext | |
12440 | && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype) | |
12441 | || RELAX_MIPS16_DSLOT (fragp->fr_subtype))) | |
12442 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
12443 | _("extended instruction in delay slot")); | |
12444 | ||
12445 | buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix); | |
12446 | ||
12447 | if (target_big_endian) | |
12448 | insn = bfd_getb16 (buf); | |
12449 | else | |
12450 | insn = bfd_getl16 (buf); | |
12451 | ||
12452 | mips16_immed (fragp->fr_file, fragp->fr_line, type, val, | |
12453 | RELAX_MIPS16_USER_EXT (fragp->fr_subtype), | |
12454 | small, ext, &insn, &use_extend, &extend); | |
12455 | ||
12456 | if (use_extend) | |
12457 | { | |
12458 | md_number_to_chars (buf, 0xf000 | extend, 2); | |
12459 | fragp->fr_fix += 2; | |
12460 | buf += 2; | |
12461 | } | |
12462 | ||
12463 | md_number_to_chars (buf, insn, 2); | |
12464 | fragp->fr_fix += 2; | |
12465 | buf += 2; | |
12466 | } | |
12467 | else | |
12468 | { | |
12469 | if (fragp->fr_opcode == NULL) | |
12470 | return; | |
12471 | ||
12472 | old = RELAX_OLD (fragp->fr_subtype); | |
12473 | new = RELAX_NEW (fragp->fr_subtype); | |
12474 | fixptr = fragp->fr_literal + fragp->fr_fix; | |
12475 | ||
12476 | if (new > 0) | |
12477 | memcpy (fixptr - old, fixptr, new); | |
12478 | ||
12479 | fragp->fr_fix += new - old; | |
12480 | } | |
12481 | } | |
12482 | ||
12483 | #ifdef OBJ_ELF | |
12484 | ||
12485 | /* This function is called after the relocs have been generated. | |
12486 | We've been storing mips16 text labels as odd. Here we convert them | |
12487 | back to even for the convenience of the debugger. */ | |
12488 | ||
12489 | void | |
12490 | mips_frob_file_after_relocs () | |
12491 | { | |
12492 | asymbol **syms; | |
12493 | unsigned int count, i; | |
12494 | ||
12495 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
12496 | return; | |
12497 | ||
12498 | syms = bfd_get_outsymbols (stdoutput); | |
12499 | count = bfd_get_symcount (stdoutput); | |
12500 | for (i = 0; i < count; i++, syms++) | |
12501 | { | |
12502 | if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16 | |
12503 | && ((*syms)->value & 1) != 0) | |
12504 | { | |
12505 | (*syms)->value &= ~1; | |
12506 | /* If the symbol has an odd size, it was probably computed | |
12507 | incorrectly, so adjust that as well. */ | |
12508 | if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0) | |
12509 | ++elf_symbol (*syms)->internal_elf_sym.st_size; | |
12510 | } | |
12511 | } | |
12512 | } | |
12513 | ||
12514 | #endif | |
12515 | ||
12516 | /* This function is called whenever a label is defined. It is used | |
12517 | when handling branch delays; if a branch has a label, we assume we | |
12518 | can not move it. */ | |
12519 | ||
12520 | void | |
12521 | mips_define_label (sym) | |
12522 | symbolS *sym; | |
12523 | { | |
12524 | struct insn_label_list *l; | |
12525 | ||
12526 | if (free_insn_labels == NULL) | |
12527 | l = (struct insn_label_list *) xmalloc (sizeof *l); | |
12528 | else | |
12529 | { | |
12530 | l = free_insn_labels; | |
12531 | free_insn_labels = l->next; | |
12532 | } | |
12533 | ||
12534 | l->label = sym; | |
12535 | l->next = insn_labels; | |
12536 | insn_labels = l; | |
12537 | } | |
12538 | \f | |
12539 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
12540 | ||
12541 | /* Some special processing for a MIPS ELF file. */ | |
12542 | ||
12543 | void | |
12544 | mips_elf_final_processing () | |
12545 | { | |
12546 | /* Write out the register information. */ | |
e013f690 | 12547 | if (! HAVE_NEWABI) |
252b5132 RH |
12548 | { |
12549 | Elf32_RegInfo s; | |
12550 | ||
12551 | s.ri_gprmask = mips_gprmask; | |
12552 | s.ri_cprmask[0] = mips_cprmask[0]; | |
12553 | s.ri_cprmask[1] = mips_cprmask[1]; | |
12554 | s.ri_cprmask[2] = mips_cprmask[2]; | |
12555 | s.ri_cprmask[3] = mips_cprmask[3]; | |
12556 | /* The gp_value field is set by the MIPS ELF backend. */ | |
12557 | ||
12558 | bfd_mips_elf32_swap_reginfo_out (stdoutput, &s, | |
12559 | ((Elf32_External_RegInfo *) | |
12560 | mips_regmask_frag)); | |
12561 | } | |
12562 | else | |
12563 | { | |
12564 | Elf64_Internal_RegInfo s; | |
12565 | ||
12566 | s.ri_gprmask = mips_gprmask; | |
12567 | s.ri_pad = 0; | |
12568 | s.ri_cprmask[0] = mips_cprmask[0]; | |
12569 | s.ri_cprmask[1] = mips_cprmask[1]; | |
12570 | s.ri_cprmask[2] = mips_cprmask[2]; | |
12571 | s.ri_cprmask[3] = mips_cprmask[3]; | |
12572 | /* The gp_value field is set by the MIPS ELF backend. */ | |
12573 | ||
12574 | bfd_mips_elf64_swap_reginfo_out (stdoutput, &s, | |
12575 | ((Elf64_External_RegInfo *) | |
12576 | mips_regmask_frag)); | |
12577 | } | |
12578 | ||
12579 | /* Set the MIPS ELF flag bits. FIXME: There should probably be some | |
12580 | sort of BFD interface for this. */ | |
12581 | if (mips_any_noreorder) | |
12582 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER; | |
12583 | if (mips_pic != NO_PIC) | |
12584 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC; | |
12585 | ||
bdaaa2e1 | 12586 | /* Set the MIPS ELF ABI flags. */ |
a325df1d | 12587 | if (file_mips_abi == NO_ABI) |
252b5132 | 12588 | ; |
a325df1d | 12589 | else if (file_mips_abi == O32_ABI) |
252b5132 | 12590 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32; |
a325df1d | 12591 | else if (file_mips_abi == O64_ABI) |
252b5132 | 12592 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64; |
a325df1d | 12593 | else if (file_mips_abi == EABI_ABI) |
252b5132 RH |
12594 | { |
12595 | if (mips_eabi64) | |
12596 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64; | |
12597 | else | |
12598 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32; | |
12599 | } | |
a325df1d | 12600 | else if (file_mips_abi == N32_ABI) |
be00bddd TS |
12601 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2; |
12602 | ||
12603 | /* Nothing to do for "64". */ | |
252b5132 RH |
12604 | |
12605 | if (mips_32bitmode) | |
12606 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE; | |
12607 | } | |
12608 | ||
12609 | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ | |
12610 | \f | |
beae10d5 KH |
12611 | typedef struct proc { |
12612 | symbolS *isym; | |
12613 | unsigned long reg_mask; | |
12614 | unsigned long reg_offset; | |
12615 | unsigned long fpreg_mask; | |
12616 | unsigned long fpreg_offset; | |
12617 | unsigned long frame_offset; | |
12618 | unsigned long frame_reg; | |
12619 | unsigned long pc_reg; | |
12620 | } procS; | |
252b5132 RH |
12621 | |
12622 | static procS cur_proc; | |
12623 | static procS *cur_proc_ptr; | |
12624 | static int numprocs; | |
12625 | ||
0a9ef439 | 12626 | /* Fill in an rs_align_code fragment. */ |
a19d8eb0 | 12627 | |
0a9ef439 RH |
12628 | void |
12629 | mips_handle_align (fragp) | |
12630 | fragS *fragp; | |
a19d8eb0 | 12631 | { |
0a9ef439 RH |
12632 | if (fragp->fr_type != rs_align_code) |
12633 | return; | |
12634 | ||
12635 | if (mips_opts.mips16) | |
a19d8eb0 CP |
12636 | { |
12637 | static const unsigned char be_nop[] = { 0x65, 0x00 }; | |
12638 | static const unsigned char le_nop[] = { 0x00, 0x65 }; | |
12639 | ||
0a9ef439 RH |
12640 | int bytes; |
12641 | char *p; | |
a19d8eb0 | 12642 | |
0a9ef439 RH |
12643 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
12644 | p = fragp->fr_literal + fragp->fr_fix; | |
12645 | ||
12646 | if (bytes & 1) | |
12647 | { | |
12648 | *p++ = 0; | |
12649 | fragp->fr_fix += 1; | |
12650 | } | |
12651 | ||
12652 | memcpy (p, (target_big_endian ? be_nop : le_nop), 2); | |
12653 | fragp->fr_var = 2; | |
a19d8eb0 CP |
12654 | } |
12655 | ||
0a9ef439 | 12656 | /* For mips32, a nop is a zero, which we trivially get by doing nothing. */ |
a19d8eb0 CP |
12657 | } |
12658 | ||
252b5132 RH |
12659 | static void |
12660 | md_obj_begin () | |
12661 | { | |
12662 | } | |
12663 | ||
12664 | static void | |
12665 | md_obj_end () | |
12666 | { | |
12667 | /* check for premature end, nesting errors, etc */ | |
12668 | if (cur_proc_ptr) | |
9a41af64 | 12669 | as_warn (_("missing .end at end of assembly")); |
252b5132 RH |
12670 | } |
12671 | ||
12672 | static long | |
12673 | get_number () | |
12674 | { | |
12675 | int negative = 0; | |
12676 | long val = 0; | |
12677 | ||
12678 | if (*input_line_pointer == '-') | |
12679 | { | |
12680 | ++input_line_pointer; | |
12681 | negative = 1; | |
12682 | } | |
3882b010 | 12683 | if (!ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12684 | as_bad (_("Expected simple number.")); |
12685 | if (input_line_pointer[0] == '0') | |
12686 | { | |
12687 | if (input_line_pointer[1] == 'x') | |
12688 | { | |
12689 | input_line_pointer += 2; | |
3882b010 | 12690 | while (ISXDIGIT (*input_line_pointer)) |
252b5132 RH |
12691 | { |
12692 | val <<= 4; | |
12693 | val |= hex_value (*input_line_pointer++); | |
12694 | } | |
12695 | return negative ? -val : val; | |
12696 | } | |
12697 | else | |
12698 | { | |
12699 | ++input_line_pointer; | |
3882b010 | 12700 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12701 | { |
12702 | val <<= 3; | |
12703 | val |= *input_line_pointer++ - '0'; | |
12704 | } | |
12705 | return negative ? -val : val; | |
12706 | } | |
12707 | } | |
3882b010 | 12708 | if (!ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12709 | { |
12710 | printf (_(" *input_line_pointer == '%c' 0x%02x\n"), | |
12711 | *input_line_pointer, *input_line_pointer); | |
12712 | as_warn (_("Invalid number")); | |
12713 | return -1; | |
12714 | } | |
3882b010 | 12715 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12716 | { |
12717 | val *= 10; | |
12718 | val += *input_line_pointer++ - '0'; | |
12719 | } | |
12720 | return negative ? -val : val; | |
12721 | } | |
12722 | ||
12723 | /* The .file directive; just like the usual .file directive, but there | |
12724 | is an initial number which is the ECOFF file index. */ | |
12725 | ||
12726 | static void | |
12727 | s_file (x) | |
43841e91 | 12728 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
12729 | { |
12730 | int line; | |
12731 | ||
12732 | line = get_number (); | |
12733 | s_app_file (0); | |
12734 | } | |
12735 | ||
252b5132 RH |
12736 | /* The .end directive. */ |
12737 | ||
12738 | static void | |
12739 | s_mips_end (x) | |
43841e91 | 12740 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
12741 | { |
12742 | symbolS *p; | |
12743 | int maybe_text; | |
12744 | ||
12745 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
12746 | { | |
12747 | p = get_symbol (); | |
12748 | demand_empty_rest_of_line (); | |
12749 | } | |
12750 | else | |
12751 | p = NULL; | |
12752 | ||
12753 | #ifdef BFD_ASSEMBLER | |
12754 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
12755 | maybe_text = 1; | |
12756 | else | |
12757 | maybe_text = 0; | |
12758 | #else | |
12759 | if (now_seg != data_section && now_seg != bss_section) | |
12760 | maybe_text = 1; | |
12761 | else | |
12762 | maybe_text = 0; | |
12763 | #endif | |
12764 | ||
12765 | if (!maybe_text) | |
12766 | as_warn (_(".end not in text section")); | |
12767 | ||
12768 | if (!cur_proc_ptr) | |
12769 | { | |
12770 | as_warn (_(".end directive without a preceding .ent directive.")); | |
12771 | demand_empty_rest_of_line (); | |
12772 | return; | |
12773 | } | |
12774 | ||
12775 | if (p != NULL) | |
12776 | { | |
12777 | assert (S_GET_NAME (p)); | |
12778 | if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym))) | |
12779 | as_warn (_(".end symbol does not match .ent symbol.")); | |
12780 | } | |
12781 | else | |
12782 | as_warn (_(".end directive missing or unknown symbol")); | |
12783 | ||
12784 | #ifdef MIPS_STABS_ELF | |
12785 | { | |
12786 | segT saved_seg = now_seg; | |
12787 | subsegT saved_subseg = now_subseg; | |
252b5132 | 12788 | valueT dot; |
252b5132 RH |
12789 | expressionS exp; |
12790 | char *fragp; | |
12791 | ||
12792 | dot = frag_now_fix (); | |
12793 | ||
12794 | #ifdef md_flush_pending_output | |
12795 | md_flush_pending_output (); | |
12796 | #endif | |
12797 | ||
12798 | assert (pdr_seg); | |
12799 | subseg_set (pdr_seg, 0); | |
12800 | ||
beae10d5 | 12801 | /* Write the symbol. */ |
252b5132 RH |
12802 | exp.X_op = O_symbol; |
12803 | exp.X_add_symbol = p; | |
12804 | exp.X_add_number = 0; | |
12805 | emit_expr (&exp, 4); | |
12806 | ||
beae10d5 | 12807 | fragp = frag_more (7 * 4); |
252b5132 | 12808 | |
beae10d5 KH |
12809 | md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4); |
12810 | md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4); | |
12811 | md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4); | |
12812 | md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4); | |
12813 | md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4); | |
12814 | md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4); | |
12815 | md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4); | |
252b5132 RH |
12816 | |
12817 | subseg_set (saved_seg, saved_subseg); | |
12818 | } | |
12819 | #endif | |
12820 | ||
12821 | cur_proc_ptr = NULL; | |
12822 | } | |
12823 | ||
12824 | /* The .aent and .ent directives. */ | |
12825 | ||
12826 | static void | |
12827 | s_mips_ent (aent) | |
12828 | int aent; | |
12829 | { | |
12830 | int number = 0; | |
12831 | symbolS *symbolP; | |
12832 | int maybe_text; | |
12833 | ||
12834 | symbolP = get_symbol (); | |
12835 | if (*input_line_pointer == ',') | |
12836 | input_line_pointer++; | |
12837 | SKIP_WHITESPACE (); | |
3882b010 | 12838 | if (ISDIGIT (*input_line_pointer) |
d9a62219 | 12839 | || *input_line_pointer == '-') |
252b5132 RH |
12840 | number = get_number (); |
12841 | ||
12842 | #ifdef BFD_ASSEMBLER | |
12843 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
12844 | maybe_text = 1; | |
12845 | else | |
12846 | maybe_text = 0; | |
12847 | #else | |
12848 | if (now_seg != data_section && now_seg != bss_section) | |
12849 | maybe_text = 1; | |
12850 | else | |
12851 | maybe_text = 0; | |
12852 | #endif | |
12853 | ||
12854 | if (!maybe_text) | |
12855 | as_warn (_(".ent or .aent not in text section.")); | |
12856 | ||
12857 | if (!aent && cur_proc_ptr) | |
9a41af64 | 12858 | as_warn (_("missing .end")); |
252b5132 RH |
12859 | |
12860 | if (!aent) | |
12861 | { | |
12862 | cur_proc_ptr = &cur_proc; | |
12863 | memset (cur_proc_ptr, '\0', sizeof (procS)); | |
12864 | ||
12865 | cur_proc_ptr->isym = symbolP; | |
12866 | ||
49309057 | 12867 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
12868 | |
12869 | numprocs++; | |
12870 | } | |
12871 | ||
12872 | demand_empty_rest_of_line (); | |
12873 | } | |
12874 | ||
12875 | /* The .frame directive. If the mdebug section is present (IRIX 5 native) | |
bdaaa2e1 | 12876 | then ecoff.c (ecoff_directive_frame) is used. For embedded targets, |
252b5132 | 12877 | s_mips_frame is used so that we can set the PDR information correctly. |
bdaaa2e1 | 12878 | We can't use the ecoff routines because they make reference to the ecoff |
252b5132 RH |
12879 | symbol table (in the mdebug section). */ |
12880 | ||
12881 | static void | |
12882 | s_mips_frame (ignore) | |
2b3c5a5d | 12883 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
12884 | { |
12885 | #ifdef MIPS_STABS_ELF | |
12886 | ||
12887 | long val; | |
12888 | ||
beae10d5 | 12889 | if (cur_proc_ptr == (procS *) NULL) |
252b5132 RH |
12890 | { |
12891 | as_warn (_(".frame outside of .ent")); | |
12892 | demand_empty_rest_of_line (); | |
12893 | return; | |
12894 | } | |
12895 | ||
12896 | cur_proc_ptr->frame_reg = tc_get_register (1); | |
12897 | ||
12898 | SKIP_WHITESPACE (); | |
12899 | if (*input_line_pointer++ != ',' | |
12900 | || get_absolute_expression_and_terminator (&val) != ',') | |
12901 | { | |
12902 | as_warn (_("Bad .frame directive")); | |
12903 | --input_line_pointer; | |
12904 | demand_empty_rest_of_line (); | |
12905 | return; | |
12906 | } | |
12907 | ||
12908 | cur_proc_ptr->frame_offset = val; | |
12909 | cur_proc_ptr->pc_reg = tc_get_register (0); | |
12910 | ||
12911 | demand_empty_rest_of_line (); | |
12912 | #else | |
12913 | s_ignore (ignore); | |
12914 | #endif /* MIPS_STABS_ELF */ | |
12915 | } | |
12916 | ||
bdaaa2e1 KH |
12917 | /* The .fmask and .mask directives. If the mdebug section is present |
12918 | (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For | |
252b5132 | 12919 | embedded targets, s_mips_mask is used so that we can set the PDR |
bdaaa2e1 | 12920 | information correctly. We can't use the ecoff routines because they |
252b5132 RH |
12921 | make reference to the ecoff symbol table (in the mdebug section). */ |
12922 | ||
12923 | static void | |
12924 | s_mips_mask (reg_type) | |
12925 | char reg_type; | |
12926 | { | |
12927 | #ifdef MIPS_STABS_ELF | |
12928 | long mask, off; | |
bdaaa2e1 | 12929 | |
252b5132 RH |
12930 | if (cur_proc_ptr == (procS *) NULL) |
12931 | { | |
12932 | as_warn (_(".mask/.fmask outside of .ent")); | |
12933 | demand_empty_rest_of_line (); | |
12934 | return; | |
12935 | } | |
12936 | ||
12937 | if (get_absolute_expression_and_terminator (&mask) != ',') | |
12938 | { | |
12939 | as_warn (_("Bad .mask/.fmask directive")); | |
12940 | --input_line_pointer; | |
12941 | demand_empty_rest_of_line (); | |
12942 | return; | |
12943 | } | |
12944 | ||
12945 | off = get_absolute_expression (); | |
12946 | ||
12947 | if (reg_type == 'F') | |
12948 | { | |
12949 | cur_proc_ptr->fpreg_mask = mask; | |
12950 | cur_proc_ptr->fpreg_offset = off; | |
12951 | } | |
12952 | else | |
12953 | { | |
12954 | cur_proc_ptr->reg_mask = mask; | |
12955 | cur_proc_ptr->reg_offset = off; | |
12956 | } | |
12957 | ||
12958 | demand_empty_rest_of_line (); | |
12959 | #else | |
12960 | s_ignore (reg_type); | |
12961 | #endif /* MIPS_STABS_ELF */ | |
12962 | } | |
12963 | ||
12964 | /* The .loc directive. */ | |
12965 | ||
12966 | #if 0 | |
12967 | static void | |
12968 | s_loc (x) | |
12969 | int x; | |
12970 | { | |
12971 | symbolS *symbolP; | |
12972 | int lineno; | |
12973 | int addroff; | |
12974 | ||
12975 | assert (now_seg == text_section); | |
12976 | ||
12977 | lineno = get_number (); | |
12978 | addroff = frag_now_fix (); | |
12979 | ||
12980 | symbolP = symbol_new ("", N_SLINE, addroff, frag_now); | |
12981 | S_SET_TYPE (symbolP, N_SLINE); | |
12982 | S_SET_OTHER (symbolP, 0); | |
12983 | S_SET_DESC (symbolP, lineno); | |
12984 | symbolP->sy_segment = now_seg; | |
12985 | } | |
12986 | #endif | |
e7af610e NC |
12987 | |
12988 | /* CPU name/ISA/number mapping table. | |
12989 | ||
12990 | Entries are grouped by type. The first matching CPU or ISA entry | |
12991 | gets chosen by CPU or ISA, so it should be the 'canonical' name | |
12992 | for that type. Entries after that within the type are sorted | |
12993 | alphabetically. | |
12994 | ||
12995 | Case is ignored in comparison, so put the canonical entry in the | |
12996 | appropriate case but everything else in lower case to ease eye pain. */ | |
e972090a NC |
12997 | static const struct mips_cpu_info mips_cpu_info_table[] = |
12998 | { | |
e7af610e NC |
12999 | /* MIPS1 ISA */ |
13000 | { "MIPS1", 1, ISA_MIPS1, CPU_R3000, }, | |
13001 | { "mips", 1, ISA_MIPS1, CPU_R3000, }, | |
13002 | ||
13003 | /* MIPS2 ISA */ | |
13004 | { "MIPS2", 1, ISA_MIPS2, CPU_R6000, }, | |
13005 | ||
13006 | /* MIPS3 ISA */ | |
13007 | { "MIPS3", 1, ISA_MIPS3, CPU_R4000, }, | |
13008 | ||
13009 | /* MIPS4 ISA */ | |
13010 | { "MIPS4", 1, ISA_MIPS4, CPU_R8000, }, | |
13011 | ||
84ea6cf2 NC |
13012 | /* MIPS5 ISA */ |
13013 | { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, }, | |
13014 | { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, }, | |
13015 | ||
e7af610e NC |
13016 | /* MIPS32 ISA */ |
13017 | { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, }, | |
3c02b2ab | 13018 | { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, }, |
e7af610e | 13019 | { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, }, |
3c02b2ab EC |
13020 | { "4kc", 0, ISA_MIPS32, CPU_MIPS32, }, |
13021 | { "4km", 0, ISA_MIPS32, CPU_MIPS32, }, | |
13022 | { "4kp", 0, ISA_MIPS32, CPU_MIPS32, }, | |
13023 | ||
13024 | /* For historical reasons. */ | |
13025 | { "MIPS64", 1, ISA_MIPS3, CPU_R4000, }, | |
e7af610e | 13026 | |
84ea6cf2 | 13027 | /* MIPS64 ISA */ |
3c02b2ab | 13028 | { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, }, |
84ea6cf2 | 13029 | { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, }, |
3c02b2ab EC |
13030 | { "5kc", 0, ISA_MIPS64, CPU_MIPS64, }, |
13031 | { "20kc", 0, ISA_MIPS64, CPU_MIPS64, }, | |
e7af610e NC |
13032 | |
13033 | /* R2000 CPU */ | |
13034 | { "R2000", 0, ISA_MIPS1, CPU_R2000, }, | |
13035 | { "2000", 0, ISA_MIPS1, CPU_R2000, }, | |
13036 | { "2k", 0, ISA_MIPS1, CPU_R2000, }, | |
13037 | { "r2k", 0, ISA_MIPS1, CPU_R2000, }, | |
13038 | ||
13039 | /* R3000 CPU */ | |
13040 | { "R3000", 0, ISA_MIPS1, CPU_R3000, }, | |
13041 | { "3000", 0, ISA_MIPS1, CPU_R3000, }, | |
13042 | { "3k", 0, ISA_MIPS1, CPU_R3000, }, | |
13043 | { "r3k", 0, ISA_MIPS1, CPU_R3000, }, | |
13044 | ||
13045 | /* TX3900 CPU */ | |
13046 | { "R3900", 0, ISA_MIPS1, CPU_R3900, }, | |
13047 | { "3900", 0, ISA_MIPS1, CPU_R3900, }, | |
e972090a | 13048 | { "mipstx39", 0, ISA_MIPS1, CPU_R3900, }, |
e7af610e NC |
13049 | |
13050 | /* R4000 CPU */ | |
13051 | { "R4000", 0, ISA_MIPS3, CPU_R4000, }, | |
13052 | { "4000", 0, ISA_MIPS3, CPU_R4000, }, | |
13053 | { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */ | |
13054 | { "r4k", 0, ISA_MIPS3, CPU_R4000, }, | |
13055 | ||
13056 | /* R4010 CPU */ | |
13057 | { "R4010", 0, ISA_MIPS2, CPU_R4010, }, | |
13058 | { "4010", 0, ISA_MIPS2, CPU_R4010, }, | |
13059 | ||
13060 | /* R4400 CPU */ | |
13061 | { "R4400", 0, ISA_MIPS3, CPU_R4400, }, | |
13062 | { "4400", 0, ISA_MIPS3, CPU_R4400, }, | |
13063 | ||
13064 | /* R4600 CPU */ | |
13065 | { "R4600", 0, ISA_MIPS3, CPU_R4600, }, | |
13066 | { "4600", 0, ISA_MIPS3, CPU_R4600, }, | |
13067 | { "mips64orion", 0, ISA_MIPS3, CPU_R4600, }, | |
13068 | { "orion", 0, ISA_MIPS3, CPU_R4600, }, | |
13069 | ||
13070 | /* R4650 CPU */ | |
13071 | { "R4650", 0, ISA_MIPS3, CPU_R4650, }, | |
13072 | { "4650", 0, ISA_MIPS3, CPU_R4650, }, | |
13073 | ||
13074 | /* R6000 CPU */ | |
13075 | { "R6000", 0, ISA_MIPS2, CPU_R6000, }, | |
13076 | { "6000", 0, ISA_MIPS2, CPU_R6000, }, | |
13077 | { "6k", 0, ISA_MIPS2, CPU_R6000, }, | |
13078 | { "r6k", 0, ISA_MIPS2, CPU_R6000, }, | |
13079 | ||
13080 | /* R8000 CPU */ | |
13081 | { "R8000", 0, ISA_MIPS4, CPU_R8000, }, | |
13082 | { "8000", 0, ISA_MIPS4, CPU_R8000, }, | |
13083 | { "8k", 0, ISA_MIPS4, CPU_R8000, }, | |
13084 | { "r8k", 0, ISA_MIPS4, CPU_R8000, }, | |
13085 | ||
13086 | /* R10000 CPU */ | |
13087 | { "R10000", 0, ISA_MIPS4, CPU_R10000, }, | |
13088 | { "10000", 0, ISA_MIPS4, CPU_R10000, }, | |
13089 | { "10k", 0, ISA_MIPS4, CPU_R10000, }, | |
13090 | { "r10k", 0, ISA_MIPS4, CPU_R10000, }, | |
13091 | ||
d1cf510e NC |
13092 | /* R12000 CPU */ |
13093 | { "R12000", 0, ISA_MIPS4, CPU_R12000, }, | |
13094 | { "12000", 0, ISA_MIPS4, CPU_R12000, }, | |
13095 | { "12k", 0, ISA_MIPS4, CPU_R12000, }, | |
13096 | { "r12k", 0, ISA_MIPS4, CPU_R12000, }, | |
13097 | ||
e7af610e NC |
13098 | /* VR4100 CPU */ |
13099 | { "VR4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
13100 | { "4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
13101 | { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
13102 | { "r4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
13103 | ||
13104 | /* VR4111 CPU */ | |
13105 | { "VR4111", 0, ISA_MIPS3, CPU_R4111, }, | |
13106 | { "4111", 0, ISA_MIPS3, CPU_R4111, }, | |
13107 | { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, }, | |
13108 | { "r4111", 0, ISA_MIPS3, CPU_R4111, }, | |
13109 | ||
13110 | /* VR4300 CPU */ | |
13111 | { "VR4300", 0, ISA_MIPS3, CPU_R4300, }, | |
13112 | { "4300", 0, ISA_MIPS3, CPU_R4300, }, | |
13113 | { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, }, | |
13114 | { "r4300", 0, ISA_MIPS3, CPU_R4300, }, | |
13115 | ||
13116 | /* VR5000 CPU */ | |
13117 | { "VR5000", 0, ISA_MIPS4, CPU_R5000, }, | |
13118 | { "5000", 0, ISA_MIPS4, CPU_R5000, }, | |
13119 | { "5k", 0, ISA_MIPS4, CPU_R5000, }, | |
13120 | { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, }, | |
13121 | { "r5000", 0, ISA_MIPS4, CPU_R5000, }, | |
13122 | { "r5200", 0, ISA_MIPS4, CPU_R5000, }, | |
18ae5d72 | 13123 | { "rm5200", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 13124 | { "r5230", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 13125 | { "rm5230", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 13126 | { "r5231", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 13127 | { "rm5231", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 13128 | { "r5261", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 13129 | { "rm5261", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 13130 | { "r5721", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 13131 | { "rm5721", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e NC |
13132 | { "r5k", 0, ISA_MIPS4, CPU_R5000, }, |
13133 | { "r7000", 0, ISA_MIPS4, CPU_R5000, }, | |
13134 | ||
2e4acd24 | 13135 | /* Broadcom SB-1 CPU */ |
c6c98b38 | 13136 | { "SB-1", 0, ISA_MIPS64, CPU_SB1, }, |
e972090a | 13137 | { "sb-1250", 0, ISA_MIPS64, CPU_SB1, }, |
c6c98b38 NC |
13138 | { "sb1", 0, ISA_MIPS64, CPU_SB1, }, |
13139 | { "sb1250", 0, ISA_MIPS64, CPU_SB1, }, | |
13140 | ||
beae10d5 | 13141 | /* End marker. */ |
e7af610e NC |
13142 | { NULL, 0, 0, 0, }, |
13143 | }; | |
13144 | ||
13145 | static const struct mips_cpu_info * | |
13146 | mips_cpu_info_from_name (name) | |
13147 | const char *name; | |
13148 | { | |
13149 | int i; | |
13150 | ||
13151 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
beae10d5 | 13152 | if (strcasecmp (name, mips_cpu_info_table[i].name) == 0) |
e7af610e NC |
13153 | return (&mips_cpu_info_table[i]); |
13154 | ||
e972090a | 13155 | return NULL; |
e7af610e NC |
13156 | } |
13157 | ||
13158 | static const struct mips_cpu_info * | |
13159 | mips_cpu_info_from_isa (isa) | |
13160 | int isa; | |
13161 | { | |
13162 | int i; | |
13163 | ||
13164 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
13165 | if (mips_cpu_info_table[i].is_isa | |
13166 | && isa == mips_cpu_info_table[i].isa) | |
13167 | return (&mips_cpu_info_table[i]); | |
13168 | ||
e972090a | 13169 | return NULL; |
e7af610e NC |
13170 | } |
13171 | ||
13172 | static const struct mips_cpu_info * | |
13173 | mips_cpu_info_from_cpu (cpu) | |
13174 | int cpu; | |
13175 | { | |
13176 | int i; | |
13177 | ||
13178 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
13179 | if (!mips_cpu_info_table[i].is_isa | |
13180 | && cpu == mips_cpu_info_table[i].cpu) | |
13181 | return (&mips_cpu_info_table[i]); | |
13182 | ||
e972090a | 13183 | return NULL; |
e7af610e | 13184 | } |