Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-mips.c -- assemble code for a MIPS chip. |
f7e42eb4 | 2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 |
82efde3a | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Contributed by the OSF and Ralph Campbell. |
5 | Written by Keith Knowles and Ralph Campbell, working independently. | |
6 | Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus | |
7 | Support. | |
8 | ||
9 | This file is part of GAS. | |
10 | ||
11 | GAS is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2, or (at your option) | |
14 | any later version. | |
15 | ||
16 | GAS is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with GAS; see the file COPYING. If not, write to the Free | |
23 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
24 | 02111-1307, USA. */ | |
25 | ||
26 | #include "as.h" | |
27 | #include "config.h" | |
28 | #include "subsegs.h" | |
3882b010 | 29 | #include "safe-ctype.h" |
252b5132 RH |
30 | |
31 | #ifdef USE_STDARG | |
32 | #include <stdarg.h> | |
33 | #endif | |
34 | #ifdef USE_VARARGS | |
35 | #include <varargs.h> | |
36 | #endif | |
37 | ||
38 | #include "opcode/mips.h" | |
39 | #include "itbl-ops.h" | |
40 | ||
41 | #ifdef DEBUG | |
42 | #define DBG(x) printf x | |
43 | #else | |
44 | #define DBG(x) | |
45 | #endif | |
46 | ||
47 | #ifdef OBJ_MAYBE_ELF | |
48 | /* Clean up namespace so we can include obj-elf.h too. */ | |
49 | static int mips_output_flavor PARAMS ((void)); | |
50 | static int mips_output_flavor () { return OUTPUT_FLAVOR; } | |
51 | #undef OBJ_PROCESS_STAB | |
52 | #undef OUTPUT_FLAVOR | |
53 | #undef S_GET_ALIGN | |
54 | #undef S_GET_SIZE | |
55 | #undef S_SET_ALIGN | |
56 | #undef S_SET_SIZE | |
252b5132 RH |
57 | #undef obj_frob_file |
58 | #undef obj_frob_file_after_relocs | |
59 | #undef obj_frob_symbol | |
60 | #undef obj_pop_insert | |
61 | #undef obj_sec_sym_ok_for_reloc | |
62 | #undef OBJ_COPY_SYMBOL_ATTRIBUTES | |
63 | ||
64 | #include "obj-elf.h" | |
65 | /* Fix any of them that we actually care about. */ | |
66 | #undef OUTPUT_FLAVOR | |
67 | #define OUTPUT_FLAVOR mips_output_flavor() | |
68 | #endif | |
69 | ||
70 | #if defined (OBJ_ELF) | |
71 | #include "elf/mips.h" | |
72 | #endif | |
73 | ||
74 | #ifndef ECOFF_DEBUGGING | |
75 | #define NO_ECOFF_DEBUGGING | |
76 | #define ECOFF_DEBUGGING 0 | |
77 | #endif | |
78 | ||
79 | #include "ecoff.h" | |
80 | ||
81 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
82 | static char *mips_regmask_frag; | |
83 | #endif | |
84 | ||
85 | #define AT 1 | |
86 | #define TREG 24 | |
87 | #define PIC_CALL_REG 25 | |
88 | #define KT0 26 | |
89 | #define KT1 27 | |
90 | #define GP 28 | |
91 | #define SP 29 | |
92 | #define FP 30 | |
93 | #define RA 31 | |
94 | ||
95 | #define ILLEGAL_REG (32) | |
96 | ||
97 | /* Allow override of standard little-endian ECOFF format. */ | |
98 | ||
99 | #ifndef ECOFF_LITTLE_FORMAT | |
100 | #define ECOFF_LITTLE_FORMAT "ecoff-littlemips" | |
101 | #endif | |
102 | ||
103 | extern int target_big_endian; | |
104 | ||
252b5132 RH |
105 | /* The name of the readonly data section. */ |
106 | #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \ | |
107 | ? ".data" \ | |
108 | : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \ | |
109 | ? ".rdata" \ | |
056350c6 NC |
110 | : OUTPUT_FLAVOR == bfd_target_coff_flavour \ |
111 | ? ".rdata" \ | |
252b5132 RH |
112 | : OUTPUT_FLAVOR == bfd_target_elf_flavour \ |
113 | ? ".rodata" \ | |
114 | : (abort (), "")) | |
115 | ||
116 | /* This is the set of options which may be modified by the .set | |
117 | pseudo-op. We use a struct so that .set push and .set pop are more | |
118 | reliable. */ | |
119 | ||
e972090a NC |
120 | struct mips_set_options |
121 | { | |
252b5132 RH |
122 | /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 |
123 | if it has not been initialized. Changed by `.set mipsN', and the | |
124 | -mipsN command line option, and the default CPU. */ | |
125 | int isa; | |
126 | /* Whether we are assembling for the mips16 processor. 0 if we are | |
127 | not, 1 if we are, and -1 if the value has not been initialized. | |
128 | Changed by `.set mips16' and `.set nomips16', and the -mips16 and | |
129 | -nomips16 command line options, and the default CPU. */ | |
130 | int mips16; | |
131 | /* Non-zero if we should not reorder instructions. Changed by `.set | |
132 | reorder' and `.set noreorder'. */ | |
133 | int noreorder; | |
134 | /* Non-zero if we should not permit the $at ($1) register to be used | |
135 | in instructions. Changed by `.set at' and `.set noat'. */ | |
136 | int noat; | |
137 | /* Non-zero if we should warn when a macro instruction expands into | |
138 | more than one machine instruction. Changed by `.set nomacro' and | |
139 | `.set macro'. */ | |
140 | int warn_about_macros; | |
141 | /* Non-zero if we should not move instructions. Changed by `.set | |
142 | move', `.set volatile', `.set nomove', and `.set novolatile'. */ | |
143 | int nomove; | |
144 | /* Non-zero if we should not optimize branches by moving the target | |
145 | of the branch into the delay slot. Actually, we don't perform | |
146 | this optimization anyhow. Changed by `.set bopt' and `.set | |
147 | nobopt'. */ | |
148 | int nobopt; | |
149 | /* Non-zero if we should not autoextend mips16 instructions. | |
150 | Changed by `.set autoextend' and `.set noautoextend'. */ | |
151 | int noautoextend; | |
152 | }; | |
153 | ||
154 | /* This is the struct we use to hold the current set of options. Note | |
e7af610e NC |
155 | that we must set the isa field to ISA_UNKNOWN and the mips16 field to |
156 | -1 to indicate that they have not been initialized. */ | |
252b5132 | 157 | |
e972090a NC |
158 | static struct mips_set_options mips_opts = |
159 | { | |
e7af610e NC |
160 | ISA_UNKNOWN, -1, 0, 0, 0, 0, 0, 0 |
161 | }; | |
252b5132 RH |
162 | |
163 | /* These variables are filled in with the masks of registers used. | |
164 | The object format code reads them and puts them in the appropriate | |
165 | place. */ | |
166 | unsigned long mips_gprmask; | |
167 | unsigned long mips_cprmask[4]; | |
168 | ||
169 | /* MIPS ISA we are using for this output file. */ | |
e7af610e | 170 | static int file_mips_isa = ISA_UNKNOWN; |
252b5132 | 171 | |
ec68c924 | 172 | /* The argument of the -mcpu= flag. Historical for code generation. */ |
e7af610e | 173 | static int mips_cpu = CPU_UNKNOWN; |
252b5132 | 174 | |
ec68c924 EC |
175 | /* The argument of the -march= flag. The architecture we are assembling. */ |
176 | static int mips_arch = CPU_UNKNOWN; | |
177 | ||
178 | /* The argument of the -mtune= flag. The architecture for which we | |
179 | are optimizing. */ | |
180 | static int mips_tune = CPU_UNKNOWN; | |
181 | ||
e013f690 TS |
182 | /* The ABI to use. */ |
183 | enum mips_abi_level | |
184 | { | |
185 | NO_ABI = 0, | |
186 | O32_ABI, | |
187 | O64_ABI, | |
188 | N32_ABI, | |
189 | N64_ABI, | |
190 | EABI_ABI | |
191 | }; | |
192 | ||
193 | static enum mips_abi_level mips_abi = NO_ABI; | |
252b5132 | 194 | |
2f4dcb11 | 195 | /* Whether we should mark the file EABI64 or EABI32. */ |
252b5132 RH |
196 | static int mips_eabi64 = 0; |
197 | ||
198 | /* If they asked for mips1 or mips2 and a cpu that is | |
bdaaa2e1 | 199 | mips3 or greater, then mark the object file 32BITMODE. */ |
252b5132 RH |
200 | static int mips_32bitmode = 0; |
201 | ||
bdaaa2e1 | 202 | /* True if -mgp32 was passed. */ |
c97ef257 AH |
203 | static int mips_gp32 = 0; |
204 | ||
ca4e0257 RS |
205 | /* True if -mfp32 was passed. */ |
206 | static int mips_fp32 = 0; | |
207 | ||
9ce8a5dd GRK |
208 | /* Some ISA's have delay slots for instructions which read or write |
209 | from a coprocessor (eg. mips1-mips3); some don't (eg mips4). | |
bdaaa2e1 | 210 | Return true if instructions marked INSN_LOAD_COPROC_DELAY, |
9ce8a5dd GRK |
211 | INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a |
212 | delay slot in this ISA. The uses of this macro assume that any | |
213 | ISA that has delay slots for one of these, has them for all. They | |
214 | also assume that ISAs which don't have delays for these insns, don't | |
bdaaa2e1 | 215 | have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */ |
9ce8a5dd | 216 | #define ISA_HAS_COPROC_DELAYS(ISA) ( \ |
e7af610e NC |
217 | (ISA) == ISA_MIPS1 \ |
218 | || (ISA) == ISA_MIPS2 \ | |
219 | || (ISA) == ISA_MIPS3 \ | |
9ce8a5dd GRK |
220 | ) |
221 | ||
bdaaa2e1 | 222 | /* Return true if ISA supports 64 bit gp register instructions. */ |
9ce8a5dd | 223 | #define ISA_HAS_64BIT_REGS(ISA) ( \ |
e7af610e NC |
224 | (ISA) == ISA_MIPS3 \ |
225 | || (ISA) == ISA_MIPS4 \ | |
84ea6cf2 | 226 | || (ISA) == ISA_MIPS5 \ |
d1cf510e | 227 | || (ISA) == ISA_MIPS64 \ |
9ce8a5dd GRK |
228 | ) |
229 | ||
e013f690 TS |
230 | #define HAVE_32BIT_GPRS \ |
231 | (mips_gp32 \ | |
232 | || mips_abi == O32_ABI \ | |
233 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
ca4e0257 | 234 | |
e013f690 TS |
235 | #define HAVE_32BIT_FPRS \ |
236 | (mips_fp32 \ | |
237 | || mips_abi == O32_ABI \ | |
238 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
ca4e0257 RS |
239 | |
240 | #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS) | |
241 | #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS) | |
242 | ||
e013f690 TS |
243 | #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI) |
244 | ||
245 | #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI) | |
246 | ||
247 | /* We can only have 64bit addresses if the object file format | |
248 | supports it. */ | |
afdbd6d0 CD |
249 | #define HAVE_32BIT_ADDRESSES \ |
250 | (HAVE_32BIT_GPRS \ | |
251 | || ((bfd_arch_bits_per_address (stdoutput) == 32 \ | |
252 | || ! HAVE_64BIT_OBJECTS) \ | |
253 | && mips_pic != EMBEDDED_PIC)) | |
e013f690 TS |
254 | |
255 | #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES) | |
ca4e0257 | 256 | |
bdaaa2e1 | 257 | /* Whether the processor uses hardware interlocks to protect |
252b5132 | 258 | reads from the HI and LO registers, and thus does not |
ec68c924 | 259 | require nops to be inserted. */ |
252b5132 | 260 | |
ec68c924 | 261 | #define hilo_interlocks (mips_arch == CPU_R4010 \ |
0a758a12 | 262 | || mips_arch == CPU_SB1 \ |
252b5132 RH |
263 | ) |
264 | ||
265 | /* Whether the processor uses hardware interlocks to protect reads | |
266 | from the GPRs, and thus does not require nops to be inserted. */ | |
267 | #define gpr_interlocks \ | |
e7af610e | 268 | (mips_opts.isa != ISA_MIPS1 \ |
ec68c924 | 269 | || mips_arch == CPU_R3900) |
252b5132 RH |
270 | |
271 | /* As with other "interlocks" this is used by hardware that has FP | |
272 | (co-processor) interlocks. */ | |
bdaaa2e1 | 273 | /* Itbl support may require additional care here. */ |
ec68c924 | 274 | #define cop_interlocks (mips_arch == CPU_R4300 \ |
0a758a12 | 275 | || mips_arch == CPU_SB1 \ |
252b5132 RH |
276 | ) |
277 | ||
6b76fefe CM |
278 | /* Is this a mfhi or mflo instruction? */ |
279 | #define MF_HILO_INSN(PINFO) \ | |
280 | ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO)) | |
281 | ||
252b5132 RH |
282 | /* MIPS PIC level. */ |
283 | ||
e972090a NC |
284 | enum mips_pic_level |
285 | { | |
252b5132 RH |
286 | /* Do not generate PIC code. */ |
287 | NO_PIC, | |
288 | ||
289 | /* Generate PIC code as in Irix 4. This is not implemented, and I'm | |
290 | not sure what it is supposed to do. */ | |
291 | IRIX4_PIC, | |
292 | ||
293 | /* Generate PIC code as in the SVR4 MIPS ABI. */ | |
294 | SVR4_PIC, | |
295 | ||
296 | /* Generate PIC code without using a global offset table: the data | |
297 | segment has a maximum size of 64K, all data references are off | |
298 | the $gp register, and all text references are PC relative. This | |
299 | is used on some embedded systems. */ | |
300 | EMBEDDED_PIC | |
301 | }; | |
302 | ||
303 | static enum mips_pic_level mips_pic; | |
304 | ||
39c0a331 L |
305 | /* Warn about all NOPS that the assembler generates. */ |
306 | static int warn_nops = 0; | |
307 | ||
252b5132 RH |
308 | /* 1 if we should generate 32 bit offsets from the GP register in |
309 | SVR4_PIC mode. Currently has no meaning in other modes. */ | |
310 | static int mips_big_got; | |
311 | ||
312 | /* 1 if trap instructions should used for overflow rather than break | |
313 | instructions. */ | |
314 | static int mips_trap; | |
315 | ||
119d663a | 316 | /* 1 if double width floating point constants should not be constructed |
b6ff326e | 317 | by assembling two single width halves into two single width floating |
119d663a NC |
318 | point registers which just happen to alias the double width destination |
319 | register. On some architectures this aliasing can be disabled by a bit | |
d547a75e | 320 | in the status register, and the setting of this bit cannot be determined |
119d663a NC |
321 | automatically at assemble time. */ |
322 | static int mips_disable_float_construction; | |
323 | ||
252b5132 RH |
324 | /* Non-zero if any .set noreorder directives were used. */ |
325 | ||
326 | static int mips_any_noreorder; | |
327 | ||
6b76fefe CM |
328 | /* Non-zero if nops should be inserted when the register referenced in |
329 | an mfhi/mflo instruction is read in the next two instructions. */ | |
330 | static int mips_7000_hilo_fix; | |
331 | ||
252b5132 | 332 | /* The size of the small data section. */ |
156c2f8b | 333 | static unsigned int g_switch_value = 8; |
252b5132 RH |
334 | /* Whether the -G option was used. */ |
335 | static int g_switch_seen = 0; | |
336 | ||
337 | #define N_RMASK 0xc4 | |
338 | #define N_VFP 0xd4 | |
339 | ||
340 | /* If we can determine in advance that GP optimization won't be | |
341 | possible, we can skip the relaxation stuff that tries to produce | |
342 | GP-relative references. This makes delay slot optimization work | |
343 | better. | |
344 | ||
345 | This function can only provide a guess, but it seems to work for | |
fba2b7f9 GK |
346 | gcc output. It needs to guess right for gcc, otherwise gcc |
347 | will put what it thinks is a GP-relative instruction in a branch | |
348 | delay slot. | |
252b5132 RH |
349 | |
350 | I don't know if a fix is needed for the SVR4_PIC mode. I've only | |
351 | fixed it for the non-PIC mode. KR 95/04/07 */ | |
352 | static int nopic_need_relax PARAMS ((symbolS *, int)); | |
353 | ||
354 | /* handle of the OPCODE hash table */ | |
355 | static struct hash_control *op_hash = NULL; | |
356 | ||
357 | /* The opcode hash table we use for the mips16. */ | |
358 | static struct hash_control *mips16_op_hash = NULL; | |
359 | ||
360 | /* This array holds the chars that always start a comment. If the | |
361 | pre-processor is disabled, these aren't very useful */ | |
362 | const char comment_chars[] = "#"; | |
363 | ||
364 | /* This array holds the chars that only start a comment at the beginning of | |
365 | a line. If the line seems to have the form '# 123 filename' | |
366 | .line and .file directives will appear in the pre-processed output */ | |
367 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
368 | first line of the input file. This is because the compiler outputs | |
bdaaa2e1 | 369 | #NO_APP at the beginning of its output. */ |
252b5132 RH |
370 | /* Also note that C style comments are always supported. */ |
371 | const char line_comment_chars[] = "#"; | |
372 | ||
bdaaa2e1 | 373 | /* This array holds machine specific line separator characters. */ |
63a0b638 | 374 | const char line_separator_chars[] = ";"; |
252b5132 RH |
375 | |
376 | /* Chars that can be used to separate mant from exp in floating point nums */ | |
377 | const char EXP_CHARS[] = "eE"; | |
378 | ||
379 | /* Chars that mean this number is a floating point constant */ | |
380 | /* As in 0f12.456 */ | |
381 | /* or 0d1.2345e12 */ | |
382 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
383 | ||
384 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
385 | changed in read.c . Ideally it shouldn't have to know about it at all, | |
386 | but nothing is ideal around here. | |
387 | */ | |
388 | ||
389 | static char *insn_error; | |
390 | ||
391 | static int auto_align = 1; | |
392 | ||
393 | /* When outputting SVR4 PIC code, the assembler needs to know the | |
394 | offset in the stack frame from which to restore the $gp register. | |
395 | This is set by the .cprestore pseudo-op, and saved in this | |
396 | variable. */ | |
397 | static offsetT mips_cprestore_offset = -1; | |
398 | ||
6478892d TS |
399 | /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some |
400 | more optimizations, it can use a register value instead of a memory-saved | |
401 | offset and even an other than GP as global pointer. */ | |
402 | static offsetT mips_cpreturn_offset = -1; | |
403 | static int mips_cpreturn_register = -1; | |
404 | static int mips_gp_register = GP; | |
405 | ||
252b5132 RH |
406 | /* This is the register which holds the stack frame, as set by the |
407 | .frame pseudo-op. This is needed to implement .cprestore. */ | |
408 | static int mips_frame_reg = SP; | |
409 | ||
410 | /* To output NOP instructions correctly, we need to keep information | |
411 | about the previous two instructions. */ | |
412 | ||
413 | /* Whether we are optimizing. The default value of 2 means to remove | |
414 | unneeded NOPs and swap branch instructions when possible. A value | |
415 | of 1 means to not swap branches. A value of 0 means to always | |
416 | insert NOPs. */ | |
417 | static int mips_optimize = 2; | |
418 | ||
419 | /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is | |
420 | equivalent to seeing no -g option at all. */ | |
421 | static int mips_debug = 0; | |
422 | ||
423 | /* The previous instruction. */ | |
424 | static struct mips_cl_insn prev_insn; | |
425 | ||
426 | /* The instruction before prev_insn. */ | |
427 | static struct mips_cl_insn prev_prev_insn; | |
428 | ||
429 | /* If we don't want information for prev_insn or prev_prev_insn, we | |
430 | point the insn_mo field at this dummy integer. */ | |
43841e91 | 431 | static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 }; |
252b5132 RH |
432 | |
433 | /* Non-zero if prev_insn is valid. */ | |
434 | static int prev_insn_valid; | |
435 | ||
436 | /* The frag for the previous instruction. */ | |
437 | static struct frag *prev_insn_frag; | |
438 | ||
439 | /* The offset into prev_insn_frag for the previous instruction. */ | |
440 | static long prev_insn_where; | |
441 | ||
442 | /* The reloc type for the previous instruction, if any. */ | |
f6688943 | 443 | static bfd_reloc_code_real_type prev_insn_reloc_type[3]; |
252b5132 RH |
444 | |
445 | /* The reloc for the previous instruction, if any. */ | |
f6688943 | 446 | static fixS *prev_insn_fixp[3]; |
252b5132 RH |
447 | |
448 | /* Non-zero if the previous instruction was in a delay slot. */ | |
449 | static int prev_insn_is_delay_slot; | |
450 | ||
451 | /* Non-zero if the previous instruction was in a .set noreorder. */ | |
452 | static int prev_insn_unreordered; | |
453 | ||
454 | /* Non-zero if the previous instruction uses an extend opcode (if | |
455 | mips16). */ | |
456 | static int prev_insn_extended; | |
457 | ||
458 | /* Non-zero if the previous previous instruction was in a .set | |
459 | noreorder. */ | |
460 | static int prev_prev_insn_unreordered; | |
461 | ||
462 | /* If this is set, it points to a frag holding nop instructions which | |
463 | were inserted before the start of a noreorder section. If those | |
464 | nops turn out to be unnecessary, the size of the frag can be | |
465 | decreased. */ | |
466 | static fragS *prev_nop_frag; | |
467 | ||
468 | /* The number of nop instructions we created in prev_nop_frag. */ | |
469 | static int prev_nop_frag_holds; | |
470 | ||
471 | /* The number of nop instructions that we know we need in | |
bdaaa2e1 | 472 | prev_nop_frag. */ |
252b5132 RH |
473 | static int prev_nop_frag_required; |
474 | ||
475 | /* The number of instructions we've seen since prev_nop_frag. */ | |
476 | static int prev_nop_frag_since; | |
477 | ||
478 | /* For ECOFF and ELF, relocations against symbols are done in two | |
479 | parts, with a HI relocation and a LO relocation. Each relocation | |
480 | has only 16 bits of space to store an addend. This means that in | |
481 | order for the linker to handle carries correctly, it must be able | |
482 | to locate both the HI and the LO relocation. This means that the | |
483 | relocations must appear in order in the relocation table. | |
484 | ||
485 | In order to implement this, we keep track of each unmatched HI | |
486 | relocation. We then sort them so that they immediately precede the | |
bdaaa2e1 | 487 | corresponding LO relocation. */ |
252b5132 | 488 | |
e972090a NC |
489 | struct mips_hi_fixup |
490 | { | |
252b5132 RH |
491 | /* Next HI fixup. */ |
492 | struct mips_hi_fixup *next; | |
493 | /* This fixup. */ | |
494 | fixS *fixp; | |
495 | /* The section this fixup is in. */ | |
496 | segT seg; | |
497 | }; | |
498 | ||
499 | /* The list of unmatched HI relocs. */ | |
500 | ||
501 | static struct mips_hi_fixup *mips_hi_fixup_list; | |
502 | ||
503 | /* Map normal MIPS register numbers to mips16 register numbers. */ | |
504 | ||
505 | #define X ILLEGAL_REG | |
e972090a NC |
506 | static const int mips32_to_16_reg_map[] = |
507 | { | |
252b5132 RH |
508 | X, X, 2, 3, 4, 5, 6, 7, |
509 | X, X, X, X, X, X, X, X, | |
510 | 0, 1, X, X, X, X, X, X, | |
511 | X, X, X, X, X, X, X, X | |
512 | }; | |
513 | #undef X | |
514 | ||
515 | /* Map mips16 register numbers to normal MIPS register numbers. */ | |
516 | ||
e972090a NC |
517 | static const unsigned int mips16_to_32_reg_map[] = |
518 | { | |
252b5132 RH |
519 | 16, 17, 2, 3, 4, 5, 6, 7 |
520 | }; | |
521 | \f | |
522 | /* Since the MIPS does not have multiple forms of PC relative | |
523 | instructions, we do not have to do relaxing as is done on other | |
524 | platforms. However, we do have to handle GP relative addressing | |
525 | correctly, which turns out to be a similar problem. | |
526 | ||
527 | Every macro that refers to a symbol can occur in (at least) two | |
528 | forms, one with GP relative addressing and one without. For | |
529 | example, loading a global variable into a register generally uses | |
530 | a macro instruction like this: | |
531 | lw $4,i | |
532 | If i can be addressed off the GP register (this is true if it is in | |
533 | the .sbss or .sdata section, or if it is known to be smaller than | |
534 | the -G argument) this will generate the following instruction: | |
535 | lw $4,i($gp) | |
536 | This instruction will use a GPREL reloc. If i can not be addressed | |
537 | off the GP register, the following instruction sequence will be used: | |
538 | lui $at,i | |
539 | lw $4,i($at) | |
540 | In this case the first instruction will have a HI16 reloc, and the | |
541 | second reloc will have a LO16 reloc. Both relocs will be against | |
542 | the symbol i. | |
543 | ||
544 | The issue here is that we may not know whether i is GP addressable | |
545 | until after we see the instruction that uses it. Therefore, we | |
546 | want to be able to choose the final instruction sequence only at | |
547 | the end of the assembly. This is similar to the way other | |
548 | platforms choose the size of a PC relative instruction only at the | |
549 | end of assembly. | |
550 | ||
551 | When generating position independent code we do not use GP | |
552 | addressing in quite the same way, but the issue still arises as | |
553 | external symbols and local symbols must be handled differently. | |
554 | ||
555 | We handle these issues by actually generating both possible | |
556 | instruction sequences. The longer one is put in a frag_var with | |
557 | type rs_machine_dependent. We encode what to do with the frag in | |
558 | the subtype field. We encode (1) the number of existing bytes to | |
559 | replace, (2) the number of new bytes to use, (3) the offset from | |
560 | the start of the existing bytes to the first reloc we must generate | |
561 | (that is, the offset is applied from the start of the existing | |
562 | bytes after they are replaced by the new bytes, if any), (4) the | |
563 | offset from the start of the existing bytes to the second reloc, | |
564 | (5) whether a third reloc is needed (the third reloc is always four | |
565 | bytes after the second reloc), and (6) whether to warn if this | |
566 | variant is used (this is sometimes needed if .set nomacro or .set | |
567 | noat is in effect). All these numbers are reasonably small. | |
568 | ||
569 | Generating two instruction sequences must be handled carefully to | |
570 | ensure that delay slots are handled correctly. Fortunately, there | |
571 | are a limited number of cases. When the second instruction | |
572 | sequence is generated, append_insn is directed to maintain the | |
573 | existing delay slot information, so it continues to apply to any | |
574 | code after the second instruction sequence. This means that the | |
575 | second instruction sequence must not impose any requirements not | |
576 | required by the first instruction sequence. | |
577 | ||
578 | These variant frags are then handled in functions called by the | |
579 | machine independent code. md_estimate_size_before_relax returns | |
580 | the final size of the frag. md_convert_frag sets up the final form | |
581 | of the frag. tc_gen_reloc adjust the first reloc and adds a second | |
582 | one if needed. */ | |
583 | #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \ | |
584 | ((relax_substateT) \ | |
585 | (((old) << 23) \ | |
586 | | ((new) << 16) \ | |
587 | | (((reloc1) + 64) << 9) \ | |
588 | | (((reloc2) + 64) << 2) \ | |
589 | | ((reloc3) ? (1 << 1) : 0) \ | |
590 | | ((warn) ? 1 : 0))) | |
591 | #define RELAX_OLD(i) (((i) >> 23) & 0x7f) | |
592 | #define RELAX_NEW(i) (((i) >> 16) & 0x7f) | |
9a41af64 TS |
593 | #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64) |
594 | #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64) | |
252b5132 RH |
595 | #define RELAX_RELOC3(i) (((i) >> 1) & 1) |
596 | #define RELAX_WARN(i) ((i) & 1) | |
597 | ||
598 | /* For mips16 code, we use an entirely different form of relaxation. | |
599 | mips16 supports two versions of most instructions which take | |
600 | immediate values: a small one which takes some small value, and a | |
601 | larger one which takes a 16 bit value. Since branches also follow | |
602 | this pattern, relaxing these values is required. | |
603 | ||
604 | We can assemble both mips16 and normal MIPS code in a single | |
605 | object. Therefore, we need to support this type of relaxation at | |
606 | the same time that we support the relaxation described above. We | |
607 | use the high bit of the subtype field to distinguish these cases. | |
608 | ||
609 | The information we store for this type of relaxation is the | |
610 | argument code found in the opcode file for this relocation, whether | |
611 | the user explicitly requested a small or extended form, and whether | |
612 | the relocation is in a jump or jal delay slot. That tells us the | |
613 | size of the value, and how it should be stored. We also store | |
614 | whether the fragment is considered to be extended or not. We also | |
615 | store whether this is known to be a branch to a different section, | |
616 | whether we have tried to relax this frag yet, and whether we have | |
617 | ever extended a PC relative fragment because of a shift count. */ | |
618 | #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \ | |
619 | (0x80000000 \ | |
620 | | ((type) & 0xff) \ | |
621 | | ((small) ? 0x100 : 0) \ | |
622 | | ((ext) ? 0x200 : 0) \ | |
623 | | ((dslot) ? 0x400 : 0) \ | |
624 | | ((jal_dslot) ? 0x800 : 0)) | |
625 | #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0) | |
626 | #define RELAX_MIPS16_TYPE(i) ((i) & 0xff) | |
627 | #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0) | |
628 | #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0) | |
629 | #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0) | |
630 | #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0) | |
631 | #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0) | |
632 | #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000) | |
633 | #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000) | |
634 | #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0) | |
635 | #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000) | |
636 | #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000) | |
637 | \f | |
638 | /* Prototypes for static functions. */ | |
639 | ||
640 | #ifdef __STDC__ | |
641 | #define internalError() \ | |
642 | as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__) | |
643 | #else | |
644 | #define internalError() as_fatal (_("MIPS internal Error")); | |
645 | #endif | |
646 | ||
647 | enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG }; | |
648 | ||
649 | static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip, | |
650 | unsigned int reg, enum mips_regclass class)); | |
156c2f8b | 651 | static int reg_needs_delay PARAMS ((unsigned int)); |
252b5132 RH |
652 | static void mips16_mark_labels PARAMS ((void)); |
653 | static void append_insn PARAMS ((char *place, | |
654 | struct mips_cl_insn * ip, | |
655 | expressionS * p, | |
f6688943 | 656 | bfd_reloc_code_real_type *r, |
252b5132 RH |
657 | boolean)); |
658 | static void mips_no_prev_insn PARAMS ((int)); | |
659 | static void mips_emit_delays PARAMS ((boolean)); | |
660 | #ifdef USE_STDARG | |
661 | static void macro_build PARAMS ((char *place, int *counter, expressionS * ep, | |
662 | const char *name, const char *fmt, | |
663 | ...)); | |
664 | #else | |
665 | static void macro_build (); | |
666 | #endif | |
667 | static void mips16_macro_build PARAMS ((char *, int *, expressionS *, | |
668 | const char *, const char *, | |
669 | va_list)); | |
670 | static void macro_build_lui PARAMS ((char *place, int *counter, | |
671 | expressionS * ep, int regnum)); | |
672 | static void set_at PARAMS ((int *counter, int reg, int unsignedp)); | |
673 | static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip, | |
674 | expressionS *)); | |
675 | static void load_register PARAMS ((int *, int, expressionS *, int)); | |
d6bc6245 | 676 | static void load_address PARAMS ((int *, int, expressionS *, int, int *)); |
ea1fb5dc | 677 | static void move_register PARAMS ((int *, int, int)); |
252b5132 RH |
678 | static void macro PARAMS ((struct mips_cl_insn * ip)); |
679 | static void mips16_macro PARAMS ((struct mips_cl_insn * ip)); | |
680 | #ifdef LOSING_COMPILER | |
681 | static void macro2 PARAMS ((struct mips_cl_insn * ip)); | |
682 | #endif | |
683 | static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
684 | static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
685 | static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean, | |
686 | boolean, boolean, unsigned long *, | |
687 | boolean *, unsigned short *)); | |
ad8d3bb3 TS |
688 | static int my_getSmallParser PARAMS ((char **, unsigned int *, int *)); |
689 | static int my_getSmallExpression PARAMS ((expressionS *, char *)); | |
690 | static void my_getExpression PARAMS ((expressionS *, char *)); | |
e013f690 | 691 | static int support_64bit_objects PARAMS((void)); |
252b5132 RH |
692 | static symbolS *get_symbol PARAMS ((void)); |
693 | static void mips_align PARAMS ((int to, int fill, symbolS *label)); | |
694 | static void s_align PARAMS ((int)); | |
695 | static void s_change_sec PARAMS ((int)); | |
696 | static void s_cons PARAMS ((int)); | |
697 | static void s_float_cons PARAMS ((int)); | |
698 | static void s_mips_globl PARAMS ((int)); | |
699 | static void s_option PARAMS ((int)); | |
700 | static void s_mipsset PARAMS ((int)); | |
701 | static void s_abicalls PARAMS ((int)); | |
702 | static void s_cpload PARAMS ((int)); | |
6478892d TS |
703 | static void s_cpsetup PARAMS ((int)); |
704 | static void s_cplocal PARAMS ((int)); | |
252b5132 | 705 | static void s_cprestore PARAMS ((int)); |
6478892d TS |
706 | static void s_cpreturn PARAMS ((int)); |
707 | static void s_gpvalue PARAMS ((int)); | |
252b5132 RH |
708 | static void s_gpword PARAMS ((int)); |
709 | static void s_cpadd PARAMS ((int)); | |
710 | static void s_insn PARAMS ((int)); | |
711 | static void md_obj_begin PARAMS ((void)); | |
712 | static void md_obj_end PARAMS ((void)); | |
713 | static long get_number PARAMS ((void)); | |
714 | static void s_mips_ent PARAMS ((int)); | |
715 | static void s_mips_end PARAMS ((int)); | |
716 | static void s_mips_frame PARAMS ((int)); | |
717 | static void s_mips_mask PARAMS ((int)); | |
718 | static void s_mips_stab PARAMS ((int)); | |
719 | static void s_mips_weakext PARAMS ((int)); | |
720 | static void s_file PARAMS ((int)); | |
721 | static int mips16_extended_frag PARAMS ((fragS *, asection *, long)); | |
e7af610e NC |
722 | static const char *mips_isa_to_str PARAMS ((int)); |
723 | static const char *mips_cpu_to_str PARAMS ((int)); | |
252b5132 | 724 | static int validate_mips_insn PARAMS ((const struct mips_opcode *)); |
e87a0284 | 725 | static void show PARAMS ((FILE *, char *, int *, int *)); |
e7af610e | 726 | |
ad8d3bb3 | 727 | /* Return values of my_getSmallExpression(). */ |
fb1b3232 | 728 | |
ad8d3bb3 | 729 | enum small_ex_type |
fb1b3232 TS |
730 | { |
731 | S_EX_NONE = 0, | |
ad8d3bb3 TS |
732 | S_EX_REGISTER, |
733 | ||
734 | /* Direct relocation creation by %percent_op(). */ | |
735 | S_EX_HALF, | |
fb1b3232 | 736 | S_EX_HI, |
ad8d3bb3 TS |
737 | S_EX_LO, |
738 | S_EX_GP_REL, | |
739 | S_EX_GOT, | |
740 | S_EX_CALL16, | |
741 | S_EX_GOT_DISP, | |
742 | S_EX_GOT_PAGE, | |
743 | S_EX_GOT_OFST, | |
744 | S_EX_GOT_HI, | |
745 | S_EX_GOT_LO, | |
746 | S_EX_NEG, | |
fb1b3232 TS |
747 | S_EX_HIGHER, |
748 | S_EX_HIGHEST, | |
ad8d3bb3 TS |
749 | S_EX_CALL_HI, |
750 | S_EX_CALL_LO | |
fb1b3232 TS |
751 | }; |
752 | ||
e7af610e NC |
753 | /* Table and functions used to map between CPU/ISA names, and |
754 | ISA levels, and CPU numbers. */ | |
755 | ||
e972090a NC |
756 | struct mips_cpu_info |
757 | { | |
e7af610e NC |
758 | const char *name; /* CPU or ISA name. */ |
759 | int is_isa; /* Is this an ISA? (If 0, a CPU.) */ | |
760 | int isa; /* ISA level. */ | |
761 | int cpu; /* CPU number (default CPU if ISA). */ | |
762 | }; | |
763 | ||
764 | static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *)); | |
765 | static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int)); | |
766 | static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int)); | |
252b5132 RH |
767 | \f |
768 | /* Pseudo-op table. | |
769 | ||
770 | The following pseudo-ops from the Kane and Heinrich MIPS book | |
771 | should be defined here, but are currently unsupported: .alias, | |
772 | .galive, .gjaldef, .gjrlive, .livereg, .noalias. | |
773 | ||
774 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
775 | specific to the type of debugging information being generated, and | |
776 | should be defined by the object format: .aent, .begin, .bend, | |
777 | .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp, | |
778 | .vreg. | |
779 | ||
780 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
781 | not MIPS CPU specific, but are also not specific to the object file | |
782 | format. This file is probably the best place to define them, but | |
783 | they are not currently supported: .asm0, .endr, .lab, .repeat, | |
784 | .struct. */ | |
785 | ||
e972090a NC |
786 | static const pseudo_typeS mips_pseudo_table[] = |
787 | { | |
beae10d5 | 788 | /* MIPS specific pseudo-ops. */ |
252b5132 RH |
789 | {"option", s_option, 0}, |
790 | {"set", s_mipsset, 0}, | |
791 | {"rdata", s_change_sec, 'r'}, | |
792 | {"sdata", s_change_sec, 's'}, | |
793 | {"livereg", s_ignore, 0}, | |
794 | {"abicalls", s_abicalls, 0}, | |
795 | {"cpload", s_cpload, 0}, | |
6478892d TS |
796 | {"cpsetup", s_cpsetup, 0}, |
797 | {"cplocal", s_cplocal, 0}, | |
252b5132 | 798 | {"cprestore", s_cprestore, 0}, |
6478892d TS |
799 | {"cpreturn", s_cpreturn, 0}, |
800 | {"gpvalue", s_gpvalue, 0}, | |
252b5132 RH |
801 | {"gpword", s_gpword, 0}, |
802 | {"cpadd", s_cpadd, 0}, | |
803 | {"insn", s_insn, 0}, | |
804 | ||
beae10d5 | 805 | /* Relatively generic pseudo-ops that happen to be used on MIPS |
252b5132 RH |
806 | chips. */ |
807 | {"asciiz", stringer, 1}, | |
808 | {"bss", s_change_sec, 'b'}, | |
809 | {"err", s_err, 0}, | |
810 | {"half", s_cons, 1}, | |
811 | {"dword", s_cons, 3}, | |
812 | {"weakext", s_mips_weakext, 0}, | |
813 | ||
beae10d5 | 814 | /* These pseudo-ops are defined in read.c, but must be overridden |
252b5132 RH |
815 | here for one reason or another. */ |
816 | {"align", s_align, 0}, | |
817 | {"byte", s_cons, 0}, | |
818 | {"data", s_change_sec, 'd'}, | |
819 | {"double", s_float_cons, 'd'}, | |
820 | {"float", s_float_cons, 'f'}, | |
821 | {"globl", s_mips_globl, 0}, | |
822 | {"global", s_mips_globl, 0}, | |
823 | {"hword", s_cons, 1}, | |
824 | {"int", s_cons, 2}, | |
825 | {"long", s_cons, 2}, | |
826 | {"octa", s_cons, 4}, | |
827 | {"quad", s_cons, 3}, | |
828 | {"short", s_cons, 1}, | |
829 | {"single", s_float_cons, 'f'}, | |
830 | {"stabn", s_mips_stab, 'n'}, | |
831 | {"text", s_change_sec, 't'}, | |
832 | {"word", s_cons, 2}, | |
add56521 L |
833 | |
834 | #ifdef MIPS_STABS_ELF | |
835 | { "extern", ecoff_directive_extern, 0}, | |
836 | #endif | |
837 | ||
43841e91 | 838 | { NULL, NULL, 0 }, |
252b5132 RH |
839 | }; |
840 | ||
e972090a NC |
841 | static const pseudo_typeS mips_nonecoff_pseudo_table[] = |
842 | { | |
beae10d5 KH |
843 | /* These pseudo-ops should be defined by the object file format. |
844 | However, a.out doesn't support them, so we have versions here. */ | |
252b5132 RH |
845 | {"aent", s_mips_ent, 1}, |
846 | {"bgnb", s_ignore, 0}, | |
847 | {"end", s_mips_end, 0}, | |
848 | {"endb", s_ignore, 0}, | |
849 | {"ent", s_mips_ent, 0}, | |
850 | {"file", s_file, 0}, | |
851 | {"fmask", s_mips_mask, 'F'}, | |
852 | {"frame", s_mips_frame, 0}, | |
853 | {"loc", s_ignore, 0}, | |
854 | {"mask", s_mips_mask, 'R'}, | |
855 | {"verstamp", s_ignore, 0}, | |
43841e91 | 856 | { NULL, NULL, 0 }, |
252b5132 RH |
857 | }; |
858 | ||
859 | extern void pop_insert PARAMS ((const pseudo_typeS *)); | |
860 | ||
861 | void | |
862 | mips_pop_insert () | |
863 | { | |
864 | pop_insert (mips_pseudo_table); | |
865 | if (! ECOFF_DEBUGGING) | |
866 | pop_insert (mips_nonecoff_pseudo_table); | |
867 | } | |
868 | \f | |
869 | /* Symbols labelling the current insn. */ | |
870 | ||
e972090a NC |
871 | struct insn_label_list |
872 | { | |
252b5132 RH |
873 | struct insn_label_list *next; |
874 | symbolS *label; | |
875 | }; | |
876 | ||
877 | static struct insn_label_list *insn_labels; | |
878 | static struct insn_label_list *free_insn_labels; | |
879 | ||
880 | static void mips_clear_insn_labels PARAMS ((void)); | |
881 | ||
882 | static inline void | |
883 | mips_clear_insn_labels () | |
884 | { | |
885 | register struct insn_label_list **pl; | |
886 | ||
887 | for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next) | |
888 | ; | |
889 | *pl = insn_labels; | |
890 | insn_labels = NULL; | |
891 | } | |
892 | \f | |
893 | static char *expr_end; | |
894 | ||
895 | /* Expressions which appear in instructions. These are set by | |
896 | mips_ip. */ | |
897 | ||
898 | static expressionS imm_expr; | |
899 | static expressionS offset_expr; | |
900 | ||
901 | /* Relocs associated with imm_expr and offset_expr. */ | |
902 | ||
f6688943 TS |
903 | static bfd_reloc_code_real_type imm_reloc[3] |
904 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
905 | static bfd_reloc_code_real_type offset_reloc[3] | |
906 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
907 | |
908 | /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */ | |
909 | ||
910 | static boolean imm_unmatched_hi; | |
911 | ||
912 | /* These are set by mips16_ip if an explicit extension is used. */ | |
913 | ||
914 | static boolean mips16_small, mips16_ext; | |
915 | ||
916 | #ifdef MIPS_STABS_ELF | |
917 | /* The pdr segment for per procedure frame/regmask info */ | |
918 | ||
919 | static segT pdr_seg; | |
920 | #endif | |
921 | ||
e7af610e NC |
922 | static const char * |
923 | mips_isa_to_str (isa) | |
924 | int isa; | |
925 | { | |
926 | const struct mips_cpu_info *ci; | |
927 | static char s[20]; | |
928 | ||
929 | ci = mips_cpu_info_from_isa (isa); | |
930 | if (ci != NULL) | |
931 | return (ci->name); | |
932 | ||
933 | sprintf (s, "ISA#%d", isa); | |
934 | return s; | |
935 | } | |
936 | ||
937 | static const char * | |
156c2f8b NC |
938 | mips_cpu_to_str (cpu) |
939 | int cpu; | |
940 | { | |
e7af610e | 941 | const struct mips_cpu_info *ci; |
156c2f8b | 942 | static char s[16]; |
e7af610e NC |
943 | |
944 | ci = mips_cpu_info_from_cpu (cpu); | |
945 | if (ci != NULL) | |
946 | return (ci->name); | |
947 | ||
948 | sprintf (s, "CPU#%d", cpu); | |
949 | return s; | |
156c2f8b NC |
950 | } |
951 | ||
e013f690 TS |
952 | /* The default target format to use. */ |
953 | ||
954 | const char * | |
955 | mips_target_format () | |
956 | { | |
957 | switch (OUTPUT_FLAVOR) | |
958 | { | |
959 | case bfd_target_aout_flavour: | |
960 | return target_big_endian ? "a.out-mips-big" : "a.out-mips-little"; | |
961 | case bfd_target_ecoff_flavour: | |
962 | return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT; | |
963 | case bfd_target_coff_flavour: | |
964 | return "pe-mips"; | |
965 | case bfd_target_elf_flavour: | |
966 | #ifdef TE_TMIPS | |
967 | /* This is traditional mips */ | |
968 | return (target_big_endian | |
969 | ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips" | |
970 | : "elf32-tradbigmips") | |
971 | : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips" | |
972 | : "elf32-tradlittlemips")); | |
973 | #else | |
974 | return (target_big_endian | |
975 | ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips") | |
976 | : (HAVE_64BIT_OBJECTS ? "elf64-littlemips" | |
977 | : "elf32-littlemips")); | |
978 | #endif | |
979 | default: | |
980 | abort (); | |
981 | return NULL; | |
982 | } | |
983 | } | |
984 | ||
156c2f8b NC |
985 | /* This function is called once, at assembler startup time. It should |
986 | set up all the tables, etc. that the MD part of the assembler will need. */ | |
987 | ||
252b5132 RH |
988 | void |
989 | md_begin () | |
990 | { | |
252b5132 | 991 | register const char *retval = NULL; |
156c2f8b | 992 | int i = 0; |
252b5132 RH |
993 | const char *cpu; |
994 | char *a = NULL; | |
995 | int broken = 0; | |
996 | int mips_isa_from_cpu; | |
e7af610e NC |
997 | int target_cpu_had_mips16 = 0; |
998 | const struct mips_cpu_info *ci; | |
252b5132 | 999 | |
056350c6 NC |
1000 | /* GP relative stuff not working for PE */ |
1001 | if (strncmp (TARGET_OS, "pe", 2) == 0 | |
1002 | && g_switch_value != 0) | |
1003 | { | |
1004 | if (g_switch_seen) | |
1005 | as_bad (_("-G not supported in this configuration.")); | |
1006 | g_switch_value = 0; | |
1007 | } | |
1008 | ||
252b5132 RH |
1009 | cpu = TARGET_CPU; |
1010 | if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0) | |
1011 | { | |
1012 | a = xmalloc (sizeof TARGET_CPU); | |
1013 | strcpy (a, TARGET_CPU); | |
1014 | a[(sizeof TARGET_CPU) - 3] = '\0'; | |
1015 | cpu = a; | |
1016 | } | |
1017 | ||
e7af610e | 1018 | if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0) |
252b5132 | 1019 | { |
e7af610e NC |
1020 | target_cpu_had_mips16 = 1; |
1021 | cpu += sizeof "mips16" - 1; | |
252b5132 RH |
1022 | } |
1023 | ||
e7af610e NC |
1024 | if (mips_opts.mips16 < 0) |
1025 | mips_opts.mips16 = target_cpu_had_mips16; | |
252b5132 | 1026 | |
6dce9e24 TS |
1027 | /* Backward compatibility for historic -mcpu= option. Check for |
1028 | incompatible options, warn if -mcpu is used. */ | |
1029 | if (mips_cpu != CPU_UNKNOWN | |
1030 | && mips_arch != CPU_UNKNOWN | |
1031 | && mips_cpu != mips_arch) | |
1032 | { | |
1033 | as_fatal (_("The -mcpu option can't be used together with -march. " | |
1034 | "Use -mtune instead of -mcpu.")); | |
1035 | } | |
1036 | ||
1037 | if (mips_cpu != CPU_UNKNOWN | |
1038 | && mips_tune != CPU_UNKNOWN | |
1039 | && mips_cpu != mips_tune) | |
1040 | { | |
1041 | as_fatal (_("The -mcpu option can't be used together with -mtune. " | |
1042 | "Use -march instead of -mcpu.")); | |
1043 | } | |
1044 | ||
1045 | if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN) | |
1046 | { | |
1047 | ci = mips_cpu_info_from_cpu (mips_cpu); | |
1048 | assert (ci != NULL); | |
1049 | mips_arch = ci->cpu; | |
1050 | as_warn (_("The -mcpu option is deprecated. Please use -march and " | |
1051 | "-mtune instead.")); | |
1052 | } | |
1053 | ||
ec68c924 | 1054 | /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was |
e7af610e NC |
1055 | specified on the command line, or some other value if one was. |
1056 | Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on | |
1057 | the command line, or will be set otherwise if one was. */ | |
ec68c924 | 1058 | if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN) |
252b5132 | 1059 | { |
1ff54a84 TS |
1060 | /* We have to check if the isa is the default isa of arch. Otherwise |
1061 | we'll get invalid object file headers. */ | |
1062 | ci = mips_cpu_info_from_cpu (mips_arch); | |
1063 | assert (ci != NULL); | |
1064 | if (mips_opts.isa != ci->isa) | |
1065 | { | |
1066 | /* This really should be an error instead of a warning, but old | |
1067 | compilers only have -mcpu which sets both arch and tune. For | |
1068 | now, we discard arch and preserve tune. */ | |
1069 | as_warn (_("The -march option is incompatible to -mipsN and " | |
1070 | "therefore ignored.")); | |
1071 | if (mips_tune == CPU_UNKNOWN) | |
1072 | mips_tune = mips_arch; | |
1073 | ci = mips_cpu_info_from_isa (mips_opts.isa); | |
1074 | assert (ci != NULL); | |
1075 | mips_arch = ci->cpu; | |
1076 | } | |
252b5132 | 1077 | } |
ec68c924 | 1078 | else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN) |
252b5132 | 1079 | { |
ec68c924 EC |
1080 | /* We have ARCH, we need ISA. */ |
1081 | ci = mips_cpu_info_from_cpu (mips_arch); | |
e7af610e NC |
1082 | assert (ci != NULL); |
1083 | mips_opts.isa = ci->isa; | |
1084 | } | |
ec68c924 | 1085 | else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN) |
e7af610e | 1086 | { |
ec68c924 | 1087 | /* We have ISA, we need default ARCH. */ |
e7af610e NC |
1088 | ci = mips_cpu_info_from_isa (mips_opts.isa); |
1089 | assert (ci != NULL); | |
ec68c924 EC |
1090 | mips_arch = ci->cpu; |
1091 | } | |
e7af610e NC |
1092 | else |
1093 | { | |
ec68c924 | 1094 | /* We need to set both ISA and ARCH from target cpu. */ |
e7af610e NC |
1095 | ci = mips_cpu_info_from_name (cpu); |
1096 | if (ci == NULL) | |
beae10d5 | 1097 | ci = mips_cpu_info_from_cpu (CPU_R3000); |
e7af610e NC |
1098 | assert (ci != NULL); |
1099 | mips_opts.isa = ci->isa; | |
ec68c924 | 1100 | mips_arch = ci->cpu; |
252b5132 RH |
1101 | } |
1102 | ||
ec68c924 EC |
1103 | if (mips_tune == CPU_UNKNOWN) |
1104 | mips_tune = mips_arch; | |
1105 | ||
1106 | ci = mips_cpu_info_from_cpu (mips_arch); | |
e7af610e NC |
1107 | assert (ci != NULL); |
1108 | mips_isa_from_cpu = ci->isa; | |
1109 | ||
252b5132 | 1110 | /* End of TARGET_CPU processing, get rid of malloced memory |
bdaaa2e1 | 1111 | if necessary. */ |
252b5132 RH |
1112 | cpu = NULL; |
1113 | if (a != NULL) | |
1114 | { | |
156c2f8b NC |
1115 | free (a); |
1116 | a = NULL; | |
252b5132 RH |
1117 | } |
1118 | ||
e7af610e | 1119 | if (mips_opts.isa == ISA_MIPS1 && mips_trap) |
252b5132 RH |
1120 | as_bad (_("trap exception not supported at ISA 1")); |
1121 | ||
1122 | /* Set the EABI kind based on the ISA before the user gets | |
1123 | to change the ISA with directives. This isn't really | |
bdaaa2e1 | 1124 | the best, but then neither is basing the abi on the isa. */ |
9ce8a5dd | 1125 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) |
e013f690 | 1126 | && mips_abi == EABI_ABI) |
252b5132 RH |
1127 | mips_eabi64 = 1; |
1128 | ||
e7af610e NC |
1129 | /* If they asked for mips1 or mips2 and a cpu that is |
1130 | mips3 or greater, then mark the object file 32BITMODE. */ | |
1131 | if (mips_isa_from_cpu != ISA_UNKNOWN | |
1132 | && ! ISA_HAS_64BIT_REGS (mips_opts.isa) | |
1133 | && ISA_HAS_64BIT_REGS (mips_isa_from_cpu)) | |
1134 | mips_32bitmode = 1; | |
252b5132 | 1135 | |
ec68c924 | 1136 | if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch)) |
252b5132 RH |
1137 | as_warn (_("Could not set architecture and machine")); |
1138 | ||
1139 | file_mips_isa = mips_opts.isa; | |
1140 | ||
1141 | op_hash = hash_new (); | |
1142 | ||
1143 | for (i = 0; i < NUMOPCODES;) | |
1144 | { | |
1145 | const char *name = mips_opcodes[i].name; | |
1146 | ||
1147 | retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]); | |
1148 | if (retval != NULL) | |
1149 | { | |
1150 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), | |
1151 | mips_opcodes[i].name, retval); | |
1152 | /* Probably a memory allocation problem? Give up now. */ | |
1153 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1154 | } | |
1155 | do | |
1156 | { | |
1157 | if (mips_opcodes[i].pinfo != INSN_MACRO) | |
1158 | { | |
1159 | if (!validate_mips_insn (&mips_opcodes[i])) | |
1160 | broken = 1; | |
1161 | } | |
1162 | ++i; | |
1163 | } | |
1164 | while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name)); | |
1165 | } | |
1166 | ||
1167 | mips16_op_hash = hash_new (); | |
1168 | ||
1169 | i = 0; | |
1170 | while (i < bfd_mips16_num_opcodes) | |
1171 | { | |
1172 | const char *name = mips16_opcodes[i].name; | |
1173 | ||
1174 | retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]); | |
1175 | if (retval != NULL) | |
1176 | as_fatal (_("internal: can't hash `%s': %s"), | |
1177 | mips16_opcodes[i].name, retval); | |
1178 | do | |
1179 | { | |
1180 | if (mips16_opcodes[i].pinfo != INSN_MACRO | |
1181 | && ((mips16_opcodes[i].match & mips16_opcodes[i].mask) | |
1182 | != mips16_opcodes[i].match)) | |
1183 | { | |
1184 | fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"), | |
1185 | mips16_opcodes[i].name, mips16_opcodes[i].args); | |
1186 | broken = 1; | |
1187 | } | |
1188 | ++i; | |
1189 | } | |
1190 | while (i < bfd_mips16_num_opcodes | |
1191 | && strcmp (mips16_opcodes[i].name, name) == 0); | |
1192 | } | |
1193 | ||
1194 | if (broken) | |
1195 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1196 | ||
1197 | /* We add all the general register names to the symbol table. This | |
1198 | helps us detect invalid uses of them. */ | |
1199 | for (i = 0; i < 32; i++) | |
1200 | { | |
1201 | char buf[5]; | |
1202 | ||
1203 | sprintf (buf, "$%d", i); | |
1204 | symbol_table_insert (symbol_new (buf, reg_section, i, | |
1205 | &zero_address_frag)); | |
1206 | } | |
1207 | symbol_table_insert (symbol_new ("$fp", reg_section, FP, | |
1208 | &zero_address_frag)); | |
1209 | symbol_table_insert (symbol_new ("$sp", reg_section, SP, | |
1210 | &zero_address_frag)); | |
1211 | symbol_table_insert (symbol_new ("$gp", reg_section, GP, | |
1212 | &zero_address_frag)); | |
1213 | symbol_table_insert (symbol_new ("$at", reg_section, AT, | |
1214 | &zero_address_frag)); | |
1215 | symbol_table_insert (symbol_new ("$kt0", reg_section, KT0, | |
1216 | &zero_address_frag)); | |
1217 | symbol_table_insert (symbol_new ("$kt1", reg_section, KT1, | |
1218 | &zero_address_frag)); | |
1219 | symbol_table_insert (symbol_new ("$pc", reg_section, -1, | |
1220 | &zero_address_frag)); | |
1221 | ||
1222 | mips_no_prev_insn (false); | |
1223 | ||
1224 | mips_gprmask = 0; | |
1225 | mips_cprmask[0] = 0; | |
1226 | mips_cprmask[1] = 0; | |
1227 | mips_cprmask[2] = 0; | |
1228 | mips_cprmask[3] = 0; | |
1229 | ||
1230 | /* set the default alignment for the text section (2**2) */ | |
1231 | record_alignment (text_section, 2); | |
1232 | ||
1233 | if (USE_GLOBAL_POINTER_OPT) | |
1234 | bfd_set_gp_size (stdoutput, g_switch_value); | |
1235 | ||
1236 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1237 | { | |
1238 | /* On a native system, sections must be aligned to 16 byte | |
1239 | boundaries. When configured for an embedded ELF target, we | |
1240 | don't bother. */ | |
1241 | if (strcmp (TARGET_OS, "elf") != 0) | |
1242 | { | |
1243 | (void) bfd_set_section_alignment (stdoutput, text_section, 4); | |
1244 | (void) bfd_set_section_alignment (stdoutput, data_section, 4); | |
1245 | (void) bfd_set_section_alignment (stdoutput, bss_section, 4); | |
1246 | } | |
1247 | ||
1248 | /* Create a .reginfo section for register masks and a .mdebug | |
1249 | section for debugging information. */ | |
1250 | { | |
1251 | segT seg; | |
1252 | subsegT subseg; | |
1253 | flagword flags; | |
1254 | segT sec; | |
1255 | ||
1256 | seg = now_seg; | |
1257 | subseg = now_subseg; | |
1258 | ||
1259 | /* The ABI says this section should be loaded so that the | |
1260 | running program can access it. However, we don't load it | |
1261 | if we are configured for an embedded target */ | |
1262 | flags = SEC_READONLY | SEC_DATA; | |
1263 | if (strcmp (TARGET_OS, "elf") != 0) | |
1264 | flags |= SEC_ALLOC | SEC_LOAD; | |
1265 | ||
e013f690 | 1266 | if (! HAVE_NEWABI) |
252b5132 RH |
1267 | { |
1268 | sec = subseg_new (".reginfo", (subsegT) 0); | |
1269 | ||
252b5132 RH |
1270 | (void) bfd_set_section_flags (stdoutput, sec, flags); |
1271 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
bdaaa2e1 | 1272 | |
252b5132 RH |
1273 | #ifdef OBJ_ELF |
1274 | mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo)); | |
1275 | #endif | |
1276 | } | |
1277 | else | |
1278 | { | |
1279 | /* The 64-bit ABI uses a .MIPS.options section rather than | |
1280 | .reginfo section. */ | |
1281 | sec = subseg_new (".MIPS.options", (subsegT) 0); | |
1282 | (void) bfd_set_section_flags (stdoutput, sec, flags); | |
1283 | (void) bfd_set_section_alignment (stdoutput, sec, 3); | |
1284 | ||
1285 | #ifdef OBJ_ELF | |
1286 | /* Set up the option header. */ | |
1287 | { | |
1288 | Elf_Internal_Options opthdr; | |
1289 | char *f; | |
1290 | ||
1291 | opthdr.kind = ODK_REGINFO; | |
1292 | opthdr.size = (sizeof (Elf_External_Options) | |
1293 | + sizeof (Elf64_External_RegInfo)); | |
1294 | opthdr.section = 0; | |
1295 | opthdr.info = 0; | |
1296 | f = frag_more (sizeof (Elf_External_Options)); | |
1297 | bfd_mips_elf_swap_options_out (stdoutput, &opthdr, | |
1298 | (Elf_External_Options *) f); | |
1299 | ||
1300 | mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo)); | |
1301 | } | |
1302 | #endif | |
1303 | } | |
1304 | ||
1305 | if (ECOFF_DEBUGGING) | |
1306 | { | |
1307 | sec = subseg_new (".mdebug", (subsegT) 0); | |
1308 | (void) bfd_set_section_flags (stdoutput, sec, | |
1309 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1310 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
1311 | } | |
1312 | ||
1313 | #ifdef MIPS_STABS_ELF | |
1314 | pdr_seg = subseg_new (".pdr", (subsegT) 0); | |
1315 | (void) bfd_set_section_flags (stdoutput, pdr_seg, | |
1316 | SEC_READONLY | SEC_RELOC | SEC_DEBUGGING); | |
1317 | (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2); | |
1318 | #endif | |
1319 | ||
1320 | subseg_set (seg, subseg); | |
1321 | } | |
1322 | } | |
1323 | ||
1324 | if (! ECOFF_DEBUGGING) | |
1325 | md_obj_begin (); | |
1326 | } | |
1327 | ||
1328 | void | |
1329 | md_mips_end () | |
1330 | { | |
1331 | if (! ECOFF_DEBUGGING) | |
1332 | md_obj_end (); | |
1333 | } | |
1334 | ||
1335 | void | |
1336 | md_assemble (str) | |
1337 | char *str; | |
1338 | { | |
1339 | struct mips_cl_insn insn; | |
f6688943 TS |
1340 | bfd_reloc_code_real_type unused_reloc[3] |
1341 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
1342 | |
1343 | imm_expr.X_op = O_absent; | |
252b5132 RH |
1344 | imm_unmatched_hi = false; |
1345 | offset_expr.X_op = O_absent; | |
f6688943 TS |
1346 | imm_reloc[0] = BFD_RELOC_UNUSED; |
1347 | imm_reloc[1] = BFD_RELOC_UNUSED; | |
1348 | imm_reloc[2] = BFD_RELOC_UNUSED; | |
1349 | offset_reloc[0] = BFD_RELOC_UNUSED; | |
1350 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
1351 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
1352 | |
1353 | if (mips_opts.mips16) | |
1354 | mips16_ip (str, &insn); | |
1355 | else | |
1356 | { | |
1357 | mips_ip (str, &insn); | |
beae10d5 KH |
1358 | DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), |
1359 | str, insn.insn_opcode)); | |
252b5132 RH |
1360 | } |
1361 | ||
1362 | if (insn_error) | |
1363 | { | |
1364 | as_bad ("%s `%s'", insn_error, str); | |
1365 | return; | |
1366 | } | |
1367 | ||
1368 | if (insn.insn_mo->pinfo == INSN_MACRO) | |
1369 | { | |
1370 | if (mips_opts.mips16) | |
1371 | mips16_macro (&insn); | |
1372 | else | |
1373 | macro (&insn); | |
1374 | } | |
1375 | else | |
1376 | { | |
1377 | if (imm_expr.X_op != O_absent) | |
1378 | append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc, | |
1379 | imm_unmatched_hi); | |
1380 | else if (offset_expr.X_op != O_absent) | |
1381 | append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc, false); | |
1382 | else | |
f6688943 | 1383 | append_insn ((char *) NULL, &insn, NULL, unused_reloc, false); |
252b5132 RH |
1384 | } |
1385 | } | |
1386 | ||
1387 | /* See whether instruction IP reads register REG. CLASS is the type | |
1388 | of register. */ | |
1389 | ||
1390 | static int | |
1391 | insn_uses_reg (ip, reg, class) | |
1392 | struct mips_cl_insn *ip; | |
1393 | unsigned int reg; | |
1394 | enum mips_regclass class; | |
1395 | { | |
1396 | if (class == MIPS16_REG) | |
1397 | { | |
1398 | assert (mips_opts.mips16); | |
1399 | reg = mips16_to_32_reg_map[reg]; | |
1400 | class = MIPS_GR_REG; | |
1401 | } | |
1402 | ||
1403 | /* Don't report on general register 0, since it never changes. */ | |
1404 | if (class == MIPS_GR_REG && reg == 0) | |
1405 | return 0; | |
1406 | ||
1407 | if (class == MIPS_FP_REG) | |
1408 | { | |
1409 | assert (! mips_opts.mips16); | |
1410 | /* If we are called with either $f0 or $f1, we must check $f0. | |
1411 | This is not optimal, because it will introduce an unnecessary | |
1412 | NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would | |
1413 | need to distinguish reading both $f0 and $f1 or just one of | |
1414 | them. Note that we don't have to check the other way, | |
1415 | because there is no instruction that sets both $f0 and $f1 | |
1416 | and requires a delay. */ | |
1417 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_S) | |
1418 | && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1) | |
1419 | == (reg &~ (unsigned) 1))) | |
1420 | return 1; | |
1421 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_T) | |
1422 | && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1) | |
1423 | == (reg &~ (unsigned) 1))) | |
1424 | return 1; | |
1425 | } | |
1426 | else if (! mips_opts.mips16) | |
1427 | { | |
1428 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_S) | |
1429 | && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg) | |
1430 | return 1; | |
1431 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_T) | |
1432 | && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg) | |
1433 | return 1; | |
1434 | } | |
1435 | else | |
1436 | { | |
1437 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X) | |
1438 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX) | |
1439 | & MIPS16OP_MASK_RX)] | |
1440 | == reg)) | |
1441 | return 1; | |
1442 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y) | |
1443 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY) | |
1444 | & MIPS16OP_MASK_RY)] | |
1445 | == reg)) | |
1446 | return 1; | |
1447 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z) | |
1448 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
1449 | & MIPS16OP_MASK_MOVE32Z)] | |
1450 | == reg)) | |
1451 | return 1; | |
1452 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG) | |
1453 | return 1; | |
1454 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP) | |
1455 | return 1; | |
1456 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA) | |
1457 | return 1; | |
1458 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X) | |
1459 | && ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
1460 | & MIPS16OP_MASK_REGR32) == reg) | |
1461 | return 1; | |
1462 | } | |
1463 | ||
1464 | return 0; | |
1465 | } | |
1466 | ||
1467 | /* This function returns true if modifying a register requires a | |
1468 | delay. */ | |
1469 | ||
1470 | static int | |
1471 | reg_needs_delay (reg) | |
156c2f8b | 1472 | unsigned int reg; |
252b5132 RH |
1473 | { |
1474 | unsigned long prev_pinfo; | |
1475 | ||
1476 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1477 | if (! mips_opts.noreorder | |
9ce8a5dd | 1478 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1479 | && ((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1480 | || (! gpr_interlocks | |
1481 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1482 | { | |
1483 | /* A load from a coprocessor or from memory. All load | |
1484 | delays delay the use of general register rt for one | |
1485 | instruction on the r3000. The r6000 and r4000 use | |
1486 | interlocks. */ | |
bdaaa2e1 | 1487 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1488 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1489 | if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)) | |
1490 | return 1; | |
1491 | } | |
1492 | ||
1493 | return 0; | |
1494 | } | |
1495 | ||
1496 | /* Mark instruction labels in mips16 mode. This permits the linker to | |
1497 | handle them specially, such as generating jalx instructions when | |
1498 | needed. We also make them odd for the duration of the assembly, in | |
1499 | order to generate the right sort of code. We will make them even | |
1500 | in the adjust_symtab routine, while leaving them marked. This is | |
1501 | convenient for the debugger and the disassembler. The linker knows | |
1502 | to make them odd again. */ | |
1503 | ||
1504 | static void | |
1505 | mips16_mark_labels () | |
1506 | { | |
1507 | if (mips_opts.mips16) | |
1508 | { | |
1509 | struct insn_label_list *l; | |
98aa84af | 1510 | valueT val; |
252b5132 RH |
1511 | |
1512 | for (l = insn_labels; l != NULL; l = l->next) | |
1513 | { | |
1514 | #ifdef OBJ_ELF | |
1515 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1516 | S_SET_OTHER (l->label, STO_MIPS16); | |
1517 | #endif | |
98aa84af AM |
1518 | val = S_GET_VALUE (l->label); |
1519 | if ((val & 1) == 0) | |
1520 | S_SET_VALUE (l->label, val + 1); | |
252b5132 RH |
1521 | } |
1522 | } | |
1523 | } | |
1524 | ||
1525 | /* Output an instruction. PLACE is where to put the instruction; if | |
1526 | it is NULL, this uses frag_more to get room. IP is the instruction | |
1527 | information. ADDRESS_EXPR is an operand of the instruction to be | |
1528 | used with RELOC_TYPE. */ | |
1529 | ||
1530 | static void | |
1531 | append_insn (place, ip, address_expr, reloc_type, unmatched_hi) | |
1532 | char *place; | |
1533 | struct mips_cl_insn *ip; | |
1534 | expressionS *address_expr; | |
f6688943 | 1535 | bfd_reloc_code_real_type *reloc_type; |
252b5132 RH |
1536 | boolean unmatched_hi; |
1537 | { | |
1538 | register unsigned long prev_pinfo, pinfo; | |
1539 | char *f; | |
f6688943 | 1540 | fixS *fixp[3]; |
252b5132 RH |
1541 | int nops = 0; |
1542 | ||
1543 | /* Mark instruction labels in mips16 mode. */ | |
1544 | if (mips_opts.mips16) | |
1545 | mips16_mark_labels (); | |
1546 | ||
1547 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1548 | pinfo = ip->insn_mo->pinfo; | |
1549 | ||
1550 | if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL)) | |
1551 | { | |
1552 | int prev_prev_nop; | |
1553 | ||
1554 | /* If the previous insn required any delay slots, see if we need | |
1555 | to insert a NOP or two. There are eight kinds of possible | |
1556 | hazards, of which an instruction can have at most one type. | |
1557 | (1) a load from memory delay | |
1558 | (2) a load from a coprocessor delay | |
1559 | (3) an unconditional branch delay | |
1560 | (4) a conditional branch delay | |
1561 | (5) a move to coprocessor register delay | |
1562 | (6) a load coprocessor register from memory delay | |
1563 | (7) a coprocessor condition code delay | |
1564 | (8) a HI/LO special register delay | |
1565 | ||
1566 | There are a lot of optimizations we could do that we don't. | |
1567 | In particular, we do not, in general, reorder instructions. | |
1568 | If you use gcc with optimization, it will reorder | |
1569 | instructions and generally do much more optimization then we | |
1570 | do here; repeating all that work in the assembler would only | |
1571 | benefit hand written assembly code, and does not seem worth | |
1572 | it. */ | |
1573 | ||
1574 | /* This is how a NOP is emitted. */ | |
1575 | #define emit_nop() \ | |
1576 | (mips_opts.mips16 \ | |
1577 | ? md_number_to_chars (frag_more (2), 0x6500, 2) \ | |
1578 | : md_number_to_chars (frag_more (4), 0, 4)) | |
1579 | ||
1580 | /* The previous insn might require a delay slot, depending upon | |
1581 | the contents of the current insn. */ | |
1582 | if (! mips_opts.mips16 | |
9ce8a5dd | 1583 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1584 | && (((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1585 | && ! cop_interlocks) | |
1586 | || (! gpr_interlocks | |
1587 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1588 | { | |
1589 | /* A load from a coprocessor or from memory. All load | |
1590 | delays delay the use of general register rt for one | |
1591 | instruction on the r3000. The r6000 and r4000 use | |
1592 | interlocks. */ | |
beae10d5 | 1593 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1594 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1595 | if (mips_optimize == 0 | |
1596 | || insn_uses_reg (ip, | |
1597 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
1598 | & OP_MASK_RT), | |
1599 | MIPS_GR_REG)) | |
1600 | ++nops; | |
1601 | } | |
1602 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1603 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 1604 | && (((prev_pinfo & INSN_COPROC_MOVE_DELAY) |
beae10d5 | 1605 | && ! cop_interlocks) |
e7af610e | 1606 | || (mips_opts.isa == ISA_MIPS1 |
252b5132 RH |
1607 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)))) |
1608 | { | |
1609 | /* A generic coprocessor delay. The previous instruction | |
1610 | modified a coprocessor general or control register. If | |
1611 | it modified a control register, we need to avoid any | |
1612 | coprocessor instruction (this is probably not always | |
1613 | required, but it sometimes is). If it modified a general | |
1614 | register, we avoid using that register. | |
1615 | ||
1616 | On the r6000 and r4000 loading a coprocessor register | |
1617 | from memory is interlocked, and does not require a delay. | |
1618 | ||
1619 | This case is not handled very well. There is no special | |
1620 | knowledge of CP0 handling, and the coprocessors other | |
1621 | than the floating point unit are not distinguished at | |
1622 | all. */ | |
1623 | /* Itbl support may require additional care here. FIXME! | |
bdaaa2e1 | 1624 | Need to modify this to include knowledge about |
252b5132 RH |
1625 | user specified delays! */ |
1626 | if (prev_pinfo & INSN_WRITE_FPR_T) | |
1627 | { | |
1628 | if (mips_optimize == 0 | |
1629 | || insn_uses_reg (ip, | |
1630 | ((prev_insn.insn_opcode >> OP_SH_FT) | |
1631 | & OP_MASK_FT), | |
1632 | MIPS_FP_REG)) | |
1633 | ++nops; | |
1634 | } | |
1635 | else if (prev_pinfo & INSN_WRITE_FPR_S) | |
1636 | { | |
1637 | if (mips_optimize == 0 | |
1638 | || insn_uses_reg (ip, | |
1639 | ((prev_insn.insn_opcode >> OP_SH_FS) | |
1640 | & OP_MASK_FS), | |
1641 | MIPS_FP_REG)) | |
1642 | ++nops; | |
1643 | } | |
1644 | else | |
1645 | { | |
1646 | /* We don't know exactly what the previous instruction | |
1647 | does. If the current instruction uses a coprocessor | |
1648 | register, we must insert a NOP. If previous | |
1649 | instruction may set the condition codes, and the | |
1650 | current instruction uses them, we must insert two | |
1651 | NOPS. */ | |
bdaaa2e1 | 1652 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1653 | if (mips_optimize == 0 |
1654 | || ((prev_pinfo & INSN_WRITE_COND_CODE) | |
1655 | && (pinfo & INSN_READ_COND_CODE))) | |
1656 | nops += 2; | |
1657 | else if (pinfo & INSN_COP) | |
1658 | ++nops; | |
1659 | } | |
1660 | } | |
1661 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1662 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1663 | && (prev_pinfo & INSN_WRITE_COND_CODE) |
1664 | && ! cop_interlocks) | |
1665 | { | |
1666 | /* The previous instruction sets the coprocessor condition | |
1667 | codes, but does not require a general coprocessor delay | |
1668 | (this means it is a floating point comparison | |
1669 | instruction). If this instruction uses the condition | |
1670 | codes, we need to insert a single NOP. */ | |
beae10d5 | 1671 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1672 | if (mips_optimize == 0 |
1673 | || (pinfo & INSN_READ_COND_CODE)) | |
1674 | ++nops; | |
1675 | } | |
6b76fefe CM |
1676 | |
1677 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1678 | previous insn was an mfhi/mflo and the current insn | |
1679 | reads the register that the mfhi/mflo wrote to, then | |
1680 | insert two nops. */ | |
1681 | ||
1682 | else if (mips_7000_hilo_fix | |
1683 | && MF_HILO_INSN (prev_pinfo) | |
1684 | && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD) | |
beae10d5 KH |
1685 | & OP_MASK_RD), |
1686 | MIPS_GR_REG)) | |
6b76fefe CM |
1687 | { |
1688 | nops += 2; | |
1689 | } | |
1690 | ||
1691 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1692 | 2nd previous insn was an mfhi/mflo and the current insn | |
1693 | reads the register that the mfhi/mflo wrote to, then | |
1694 | insert one nop. */ | |
1695 | ||
1696 | else if (mips_7000_hilo_fix | |
1697 | && MF_HILO_INSN (prev_prev_insn.insn_opcode) | |
1698 | && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD) | |
1699 | & OP_MASK_RD), | |
1700 | MIPS_GR_REG)) | |
bdaaa2e1 | 1701 | |
6b76fefe CM |
1702 | { |
1703 | nops += 1; | |
1704 | } | |
bdaaa2e1 | 1705 | |
252b5132 RH |
1706 | else if (prev_pinfo & INSN_READ_LO) |
1707 | { | |
1708 | /* The previous instruction reads the LO register; if the | |
1709 | current instruction writes to the LO register, we must | |
bdaaa2e1 KH |
1710 | insert two NOPS. Some newer processors have interlocks. |
1711 | Also the tx39's multiply instructions can be exectuted | |
252b5132 | 1712 | immediatly after a read from HI/LO (without the delay), |
bdaaa2e1 KH |
1713 | though the tx39's divide insns still do require the |
1714 | delay. */ | |
252b5132 | 1715 | if (! (hilo_interlocks |
ec68c924 | 1716 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1717 | && (mips_optimize == 0 |
1718 | || (pinfo & INSN_WRITE_LO))) | |
1719 | nops += 2; | |
1720 | /* Most mips16 branch insns don't have a delay slot. | |
1721 | If a read from LO is immediately followed by a branch | |
1722 | to a write to LO we have a read followed by a write | |
1723 | less than 2 insns away. We assume the target of | |
1724 | a branch might be a write to LO, and insert a nop | |
bdaaa2e1 | 1725 | between a read and an immediately following branch. */ |
252b5132 RH |
1726 | else if (mips_opts.mips16 |
1727 | && (mips_optimize == 0 | |
1728 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1729 | nops += 1; | |
1730 | } | |
1731 | else if (prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
1732 | { | |
1733 | /* The previous instruction reads the HI register; if the | |
1734 | current instruction writes to the HI register, we must | |
1735 | insert a NOP. Some newer processors have interlocks. | |
bdaaa2e1 | 1736 | Also the note tx39's multiply above. */ |
252b5132 | 1737 | if (! (hilo_interlocks |
ec68c924 | 1738 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1739 | && (mips_optimize == 0 |
1740 | || (pinfo & INSN_WRITE_HI))) | |
1741 | nops += 2; | |
1742 | /* Most mips16 branch insns don't have a delay slot. | |
1743 | If a read from HI is immediately followed by a branch | |
1744 | to a write to HI we have a read followed by a write | |
1745 | less than 2 insns away. We assume the target of | |
1746 | a branch might be a write to HI, and insert a nop | |
bdaaa2e1 | 1747 | between a read and an immediately following branch. */ |
252b5132 RH |
1748 | else if (mips_opts.mips16 |
1749 | && (mips_optimize == 0 | |
1750 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1751 | nops += 1; | |
1752 | } | |
1753 | ||
1754 | /* If the previous instruction was in a noreorder section, then | |
1755 | we don't want to insert the nop after all. */ | |
bdaaa2e1 | 1756 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1757 | if (prev_insn_unreordered) |
1758 | nops = 0; | |
1759 | ||
1760 | /* There are two cases which require two intervening | |
1761 | instructions: 1) setting the condition codes using a move to | |
1762 | coprocessor instruction which requires a general coprocessor | |
1763 | delay and then reading the condition codes 2) reading the HI | |
1764 | or LO register and then writing to it (except on processors | |
1765 | which have interlocks). If we are not already emitting a NOP | |
1766 | instruction, we must check for these cases compared to the | |
1767 | instruction previous to the previous instruction. */ | |
1768 | if ((! mips_opts.mips16 | |
9ce8a5dd | 1769 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1770 | && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY) |
1771 | && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE) | |
1772 | && (pinfo & INSN_READ_COND_CODE) | |
1773 | && ! cop_interlocks) | |
1774 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO) | |
1775 | && (pinfo & INSN_WRITE_LO) | |
1776 | && ! (hilo_interlocks | |
ec68c924 | 1777 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))) |
252b5132 RH |
1778 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) |
1779 | && (pinfo & INSN_WRITE_HI) | |
1780 | && ! (hilo_interlocks | |
ec68c924 | 1781 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))) |
252b5132 RH |
1782 | prev_prev_nop = 1; |
1783 | else | |
1784 | prev_prev_nop = 0; | |
1785 | ||
1786 | if (prev_prev_insn_unreordered) | |
1787 | prev_prev_nop = 0; | |
1788 | ||
1789 | if (prev_prev_nop && nops == 0) | |
1790 | ++nops; | |
1791 | ||
1792 | /* If we are being given a nop instruction, don't bother with | |
1793 | one of the nops we would otherwise output. This will only | |
1794 | happen when a nop instruction is used with mips_optimize set | |
1795 | to 0. */ | |
1796 | if (nops > 0 | |
1797 | && ! mips_opts.noreorder | |
156c2f8b | 1798 | && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0)) |
252b5132 RH |
1799 | --nops; |
1800 | ||
1801 | /* Now emit the right number of NOP instructions. */ | |
1802 | if (nops > 0 && ! mips_opts.noreorder) | |
1803 | { | |
1804 | fragS *old_frag; | |
1805 | unsigned long old_frag_offset; | |
1806 | int i; | |
1807 | struct insn_label_list *l; | |
1808 | ||
1809 | old_frag = frag_now; | |
1810 | old_frag_offset = frag_now_fix (); | |
1811 | ||
1812 | for (i = 0; i < nops; i++) | |
1813 | emit_nop (); | |
1814 | ||
1815 | if (listing) | |
1816 | { | |
1817 | listing_prev_line (); | |
1818 | /* We may be at the start of a variant frag. In case we | |
1819 | are, make sure there is enough space for the frag | |
1820 | after the frags created by listing_prev_line. The | |
1821 | argument to frag_grow here must be at least as large | |
1822 | as the argument to all other calls to frag_grow in | |
1823 | this file. We don't have to worry about being in the | |
1824 | middle of a variant frag, because the variants insert | |
1825 | all needed nop instructions themselves. */ | |
1826 | frag_grow (40); | |
1827 | } | |
1828 | ||
1829 | for (l = insn_labels; l != NULL; l = l->next) | |
1830 | { | |
98aa84af AM |
1831 | valueT val; |
1832 | ||
252b5132 | 1833 | assert (S_GET_SEGMENT (l->label) == now_seg); |
49309057 | 1834 | symbol_set_frag (l->label, frag_now); |
98aa84af | 1835 | val = (valueT) frag_now_fix (); |
252b5132 RH |
1836 | /* mips16 text labels are stored as odd. */ |
1837 | if (mips_opts.mips16) | |
98aa84af AM |
1838 | val += 1; |
1839 | S_SET_VALUE (l->label, val); | |
252b5132 RH |
1840 | } |
1841 | ||
1842 | #ifndef NO_ECOFF_DEBUGGING | |
1843 | if (ECOFF_DEBUGGING) | |
1844 | ecoff_fix_loc (old_frag, old_frag_offset); | |
1845 | #endif | |
1846 | } | |
1847 | else if (prev_nop_frag != NULL) | |
1848 | { | |
1849 | /* We have a frag holding nops we may be able to remove. If | |
1850 | we don't need any nops, we can decrease the size of | |
1851 | prev_nop_frag by the size of one instruction. If we do | |
bdaaa2e1 | 1852 | need some nops, we count them in prev_nops_required. */ |
252b5132 RH |
1853 | if (prev_nop_frag_since == 0) |
1854 | { | |
1855 | if (nops == 0) | |
1856 | { | |
1857 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1858 | --prev_nop_frag_holds; | |
1859 | } | |
1860 | else | |
1861 | prev_nop_frag_required += nops; | |
1862 | } | |
1863 | else | |
1864 | { | |
1865 | if (prev_prev_nop == 0) | |
1866 | { | |
1867 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1868 | --prev_nop_frag_holds; | |
1869 | } | |
1870 | else | |
1871 | ++prev_nop_frag_required; | |
1872 | } | |
1873 | ||
1874 | if (prev_nop_frag_holds <= prev_nop_frag_required) | |
1875 | prev_nop_frag = NULL; | |
1876 | ||
1877 | ++prev_nop_frag_since; | |
1878 | ||
1879 | /* Sanity check: by the time we reach the second instruction | |
1880 | after prev_nop_frag, we should have used up all the nops | |
1881 | one way or another. */ | |
1882 | assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL); | |
1883 | } | |
1884 | } | |
1885 | ||
f6688943 | 1886 | if (*reloc_type > BFD_RELOC_UNUSED) |
252b5132 RH |
1887 | { |
1888 | /* We need to set up a variant frag. */ | |
1889 | assert (mips_opts.mips16 && address_expr != NULL); | |
1890 | f = frag_var (rs_machine_dependent, 4, 0, | |
f6688943 | 1891 | RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED, |
252b5132 RH |
1892 | mips16_small, mips16_ext, |
1893 | (prev_pinfo | |
1894 | & INSN_UNCOND_BRANCH_DELAY), | |
f6688943 | 1895 | (*prev_insn_reloc_type |
252b5132 RH |
1896 | == BFD_RELOC_MIPS16_JMP)), |
1897 | make_expr_symbol (address_expr), (offsetT) 0, | |
1898 | (char *) NULL); | |
1899 | } | |
1900 | else if (place != NULL) | |
1901 | f = place; | |
1902 | else if (mips_opts.mips16 | |
1903 | && ! ip->use_extend | |
f6688943 | 1904 | && *reloc_type != BFD_RELOC_MIPS16_JMP) |
252b5132 RH |
1905 | { |
1906 | /* Make sure there is enough room to swap this instruction with | |
1907 | a following jump instruction. */ | |
1908 | frag_grow (6); | |
1909 | f = frag_more (2); | |
1910 | } | |
1911 | else | |
1912 | { | |
1913 | if (mips_opts.mips16 | |
1914 | && mips_opts.noreorder | |
1915 | && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0) | |
1916 | as_warn (_("extended instruction in delay slot")); | |
1917 | ||
1918 | f = frag_more (4); | |
1919 | } | |
1920 | ||
f6688943 TS |
1921 | fixp[0] = fixp[1] = fixp[2] = NULL; |
1922 | if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED) | |
252b5132 RH |
1923 | { |
1924 | if (address_expr->X_op == O_constant) | |
1925 | { | |
f6688943 TS |
1926 | unsigned long tmp; |
1927 | ||
1928 | switch (*reloc_type) | |
252b5132 RH |
1929 | { |
1930 | case BFD_RELOC_32: | |
1931 | ip->insn_opcode |= address_expr->X_add_number; | |
1932 | break; | |
1933 | ||
f6688943 TS |
1934 | case BFD_RELOC_MIPS_HIGHEST: |
1935 | tmp = (address_expr->X_add_number + 0x800080008000) >> 16; | |
1936 | tmp >>= 16; | |
1937 | ip->insn_opcode |= (tmp >> 16) & 0xffff; | |
1938 | break; | |
1939 | ||
1940 | case BFD_RELOC_MIPS_HIGHER: | |
1941 | tmp = (address_expr->X_add_number + 0x80008000) >> 16; | |
1942 | ip->insn_opcode |= (tmp >> 16) & 0xffff; | |
1943 | break; | |
1944 | ||
1945 | case BFD_RELOC_HI16_S: | |
1946 | ip->insn_opcode |= ((address_expr->X_add_number + 0x8000) | |
1947 | >> 16) & 0xffff; | |
1948 | break; | |
1949 | ||
1950 | case BFD_RELOC_HI16: | |
1951 | ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff; | |
1952 | break; | |
1953 | ||
252b5132 RH |
1954 | case BFD_RELOC_LO16: |
1955 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; | |
1956 | break; | |
1957 | ||
1958 | case BFD_RELOC_MIPS_JMP: | |
1959 | if ((address_expr->X_add_number & 3) != 0) | |
1960 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1961 | (unsigned long) address_expr->X_add_number); | |
1962 | ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff; | |
1963 | break; | |
1964 | ||
1965 | case BFD_RELOC_MIPS16_JMP: | |
1966 | if ((address_expr->X_add_number & 3) != 0) | |
1967 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1968 | (unsigned long) address_expr->X_add_number); | |
1969 | ip->insn_opcode |= | |
1970 | (((address_expr->X_add_number & 0x7c0000) << 3) | |
1971 | | ((address_expr->X_add_number & 0xf800000) >> 7) | |
1972 | | ((address_expr->X_add_number & 0x3fffc) >> 2)); | |
1973 | break; | |
1974 | ||
cb56d3d3 | 1975 | case BFD_RELOC_16_PCREL: |
233b8738 | 1976 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; |
cb56d3d3 TS |
1977 | break; |
1978 | ||
252b5132 RH |
1979 | case BFD_RELOC_16_PCREL_S2: |
1980 | goto need_reloc; | |
1981 | ||
1982 | default: | |
1983 | internalError (); | |
1984 | } | |
1985 | } | |
1986 | else | |
1987 | { | |
1988 | need_reloc: | |
f6688943 | 1989 | /* Don't generate a reloc if we are writing into a variant frag. */ |
252b5132 RH |
1990 | if (place == NULL) |
1991 | { | |
f6688943 TS |
1992 | fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4, |
1993 | address_expr, | |
1994 | (*reloc_type == BFD_RELOC_16_PCREL | |
1995 | || *reloc_type == BFD_RELOC_16_PCREL_S2), | |
1996 | reloc_type[0]); | |
1997 | ||
b6ff326e | 1998 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
1999 | 4 octets for 64bit assembly. */ |
2000 | if (HAVE_64BIT_GPRS && | |
2001 | (*reloc_type == BFD_RELOC_16 | |
2002 | || *reloc_type == BFD_RELOC_32 | |
2003 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2004 | || *reloc_type == BFD_RELOC_HI16_S | |
2005 | || *reloc_type == BFD_RELOC_LO16 | |
2006 | || *reloc_type == BFD_RELOC_GPREL16 | |
2007 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2008 | || *reloc_type == BFD_RELOC_GPREL32 | |
2009 | || *reloc_type == BFD_RELOC_64 | |
2010 | || *reloc_type == BFD_RELOC_CTOR | |
2011 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2012 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2013 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2014 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2015 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2016 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
2017 | fixp[0]->fx_no_overflow = 1; | |
2018 | ||
252b5132 RH |
2019 | if (unmatched_hi) |
2020 | { | |
2021 | struct mips_hi_fixup *hi_fixup; | |
2022 | ||
f6688943 | 2023 | assert (*reloc_type == BFD_RELOC_HI16_S); |
252b5132 RH |
2024 | hi_fixup = ((struct mips_hi_fixup *) |
2025 | xmalloc (sizeof (struct mips_hi_fixup))); | |
f6688943 | 2026 | hi_fixup->fixp = fixp[0]; |
252b5132 RH |
2027 | hi_fixup->seg = now_seg; |
2028 | hi_fixup->next = mips_hi_fixup_list; | |
2029 | mips_hi_fixup_list = hi_fixup; | |
2030 | } | |
f6688943 TS |
2031 | |
2032 | if (reloc_type[1] != BFD_RELOC_UNUSED) | |
2033 | { | |
2034 | /* FIXME: This symbol can be one of | |
2035 | RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */ | |
2036 | address_expr->X_op = O_absent; | |
2037 | address_expr->X_add_symbol = 0; | |
2038 | address_expr->X_add_number = 0; | |
2039 | ||
2040 | fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal, | |
2041 | 4, address_expr, false, | |
2042 | reloc_type[1]); | |
2043 | ||
b6ff326e | 2044 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
2045 | 4 octets for 64bit assembly. */ |
2046 | if (HAVE_64BIT_GPRS && | |
2047 | (*reloc_type == BFD_RELOC_16 | |
2048 | || *reloc_type == BFD_RELOC_32 | |
2049 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2050 | || *reloc_type == BFD_RELOC_HI16_S | |
2051 | || *reloc_type == BFD_RELOC_LO16 | |
2052 | || *reloc_type == BFD_RELOC_GPREL16 | |
2053 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2054 | || *reloc_type == BFD_RELOC_GPREL32 | |
2055 | || *reloc_type == BFD_RELOC_64 | |
2056 | || *reloc_type == BFD_RELOC_CTOR | |
2057 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2058 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2059 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2060 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2061 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2062 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
2063 | fixp[1]->fx_no_overflow = 1; | |
2064 | ||
2065 | if (reloc_type[2] != BFD_RELOC_UNUSED) | |
2066 | { | |
2067 | address_expr->X_op = O_absent; | |
2068 | address_expr->X_add_symbol = 0; | |
2069 | address_expr->X_add_number = 0; | |
2070 | ||
2071 | fixp[2] = fix_new_exp (frag_now, | |
2072 | f - frag_now->fr_literal, 4, | |
2073 | address_expr, false, | |
2074 | reloc_type[2]); | |
2075 | ||
b6ff326e | 2076 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
2077 | 4 octets for 64bit assembly. */ |
2078 | if (HAVE_64BIT_GPRS && | |
2079 | (*reloc_type == BFD_RELOC_16 | |
2080 | || *reloc_type == BFD_RELOC_32 | |
2081 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2082 | || *reloc_type == BFD_RELOC_HI16_S | |
2083 | || *reloc_type == BFD_RELOC_LO16 | |
2084 | || *reloc_type == BFD_RELOC_GPREL16 | |
2085 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2086 | || *reloc_type == BFD_RELOC_GPREL32 | |
2087 | || *reloc_type == BFD_RELOC_64 | |
2088 | || *reloc_type == BFD_RELOC_CTOR | |
2089 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2090 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2091 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2092 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2093 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2094 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
2095 | fixp[2]->fx_no_overflow = 1; | |
2096 | } | |
2097 | } | |
252b5132 RH |
2098 | } |
2099 | } | |
2100 | } | |
2101 | ||
2102 | if (! mips_opts.mips16) | |
2103 | md_number_to_chars (f, ip->insn_opcode, 4); | |
f6688943 | 2104 | else if (*reloc_type == BFD_RELOC_MIPS16_JMP) |
252b5132 RH |
2105 | { |
2106 | md_number_to_chars (f, ip->insn_opcode >> 16, 2); | |
2107 | md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2); | |
2108 | } | |
2109 | else | |
2110 | { | |
2111 | if (ip->use_extend) | |
2112 | { | |
2113 | md_number_to_chars (f, 0xf000 | ip->extend, 2); | |
2114 | f += 2; | |
2115 | } | |
2116 | md_number_to_chars (f, ip->insn_opcode, 2); | |
2117 | } | |
2118 | ||
2119 | /* Update the register mask information. */ | |
2120 | if (! mips_opts.mips16) | |
2121 | { | |
2122 | if (pinfo & INSN_WRITE_GPR_D) | |
2123 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD); | |
2124 | if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0) | |
2125 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT); | |
2126 | if (pinfo & INSN_READ_GPR_S) | |
2127 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS); | |
2128 | if (pinfo & INSN_WRITE_GPR_31) | |
2129 | mips_gprmask |= 1 << 31; | |
2130 | if (pinfo & INSN_WRITE_FPR_D) | |
2131 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD); | |
2132 | if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0) | |
2133 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS); | |
2134 | if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0) | |
2135 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT); | |
2136 | if ((pinfo & INSN_READ_FPR_R) != 0) | |
2137 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR); | |
2138 | if (pinfo & INSN_COP) | |
2139 | { | |
bdaaa2e1 KH |
2140 | /* We don't keep enough information to sort these cases out. |
2141 | The itbl support does keep this information however, although | |
2142 | we currently don't support itbl fprmats as part of the cop | |
2143 | instruction. May want to add this support in the future. */ | |
252b5132 RH |
2144 | } |
2145 | /* Never set the bit for $0, which is always zero. */ | |
beae10d5 | 2146 | mips_gprmask &= ~1 << 0; |
252b5132 RH |
2147 | } |
2148 | else | |
2149 | { | |
2150 | if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X)) | |
2151 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX) | |
2152 | & MIPS16OP_MASK_RX); | |
2153 | if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y)) | |
2154 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY) | |
2155 | & MIPS16OP_MASK_RY); | |
2156 | if (pinfo & MIPS16_INSN_WRITE_Z) | |
2157 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ) | |
2158 | & MIPS16OP_MASK_RZ); | |
2159 | if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T)) | |
2160 | mips_gprmask |= 1 << TREG; | |
2161 | if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP)) | |
2162 | mips_gprmask |= 1 << SP; | |
2163 | if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31)) | |
2164 | mips_gprmask |= 1 << RA; | |
2165 | if (pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2166 | mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode); | |
2167 | if (pinfo & MIPS16_INSN_READ_Z) | |
2168 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
2169 | & MIPS16OP_MASK_MOVE32Z); | |
2170 | if (pinfo & MIPS16_INSN_READ_GPR_X) | |
2171 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
2172 | & MIPS16OP_MASK_REGR32); | |
2173 | } | |
2174 | ||
2175 | if (place == NULL && ! mips_opts.noreorder) | |
2176 | { | |
2177 | /* Filling the branch delay slot is more complex. We try to | |
2178 | switch the branch with the previous instruction, which we can | |
2179 | do if the previous instruction does not set up a condition | |
2180 | that the branch tests and if the branch is not itself the | |
2181 | target of any branch. */ | |
2182 | if ((pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2183 | || (pinfo & INSN_COND_BRANCH_DELAY)) | |
2184 | { | |
2185 | if (mips_optimize < 2 | |
2186 | /* If we have seen .set volatile or .set nomove, don't | |
2187 | optimize. */ | |
2188 | || mips_opts.nomove != 0 | |
2189 | /* If we had to emit any NOP instructions, then we | |
2190 | already know we can not swap. */ | |
2191 | || nops != 0 | |
2192 | /* If we don't even know the previous insn, we can not | |
bdaaa2e1 | 2193 | swap. */ |
252b5132 RH |
2194 | || ! prev_insn_valid |
2195 | /* If the previous insn is already in a branch delay | |
2196 | slot, then we can not swap. */ | |
2197 | || prev_insn_is_delay_slot | |
2198 | /* If the previous previous insn was in a .set | |
2199 | noreorder, we can't swap. Actually, the MIPS | |
2200 | assembler will swap in this situation. However, gcc | |
2201 | configured -with-gnu-as will generate code like | |
2202 | .set noreorder | |
2203 | lw $4,XXX | |
2204 | .set reorder | |
2205 | INSN | |
2206 | bne $4,$0,foo | |
2207 | in which we can not swap the bne and INSN. If gcc is | |
2208 | not configured -with-gnu-as, it does not output the | |
2209 | .set pseudo-ops. We don't have to check | |
2210 | prev_insn_unreordered, because prev_insn_valid will | |
2211 | be 0 in that case. We don't want to use | |
2212 | prev_prev_insn_valid, because we do want to be able | |
2213 | to swap at the start of a function. */ | |
2214 | || prev_prev_insn_unreordered | |
2215 | /* If the branch is itself the target of a branch, we | |
2216 | can not swap. We cheat on this; all we check for is | |
2217 | whether there is a label on this instruction. If | |
2218 | there are any branches to anything other than a | |
2219 | label, users must use .set noreorder. */ | |
2220 | || insn_labels != NULL | |
2221 | /* If the previous instruction is in a variant frag, we | |
2222 | can not do the swap. This does not apply to the | |
2223 | mips16, which uses variant frags for different | |
2224 | purposes. */ | |
2225 | || (! mips_opts.mips16 | |
2226 | && prev_insn_frag->fr_type == rs_machine_dependent) | |
2227 | /* If the branch reads the condition codes, we don't | |
2228 | even try to swap, because in the sequence | |
2229 | ctc1 $X,$31 | |
2230 | INSN | |
2231 | INSN | |
2232 | bc1t LABEL | |
2233 | we can not swap, and I don't feel like handling that | |
2234 | case. */ | |
2235 | || (! mips_opts.mips16 | |
9ce8a5dd | 2236 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2237 | && (pinfo & INSN_READ_COND_CODE)) |
2238 | /* We can not swap with an instruction that requires a | |
2239 | delay slot, becase the target of the branch might | |
2240 | interfere with that instruction. */ | |
2241 | || (! mips_opts.mips16 | |
9ce8a5dd | 2242 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 2243 | && (prev_pinfo |
bdaaa2e1 | 2244 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2245 | & (INSN_LOAD_COPROC_DELAY |
2246 | | INSN_COPROC_MOVE_DELAY | |
2247 | | INSN_WRITE_COND_CODE))) | |
2248 | || (! (hilo_interlocks | |
ec68c924 | 2249 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
2250 | && (prev_pinfo |
2251 | & (INSN_READ_LO | |
2252 | | INSN_READ_HI))) | |
2253 | || (! mips_opts.mips16 | |
2254 | && ! gpr_interlocks | |
2255 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)) | |
2256 | || (! mips_opts.mips16 | |
e7af610e | 2257 | && mips_opts.isa == ISA_MIPS1 |
bdaaa2e1 | 2258 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2259 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)) |
2260 | /* We can not swap with a branch instruction. */ | |
2261 | || (prev_pinfo | |
2262 | & (INSN_UNCOND_BRANCH_DELAY | |
2263 | | INSN_COND_BRANCH_DELAY | |
2264 | | INSN_COND_BRANCH_LIKELY)) | |
2265 | /* We do not swap with a trap instruction, since it | |
2266 | complicates trap handlers to have the trap | |
2267 | instruction be in a delay slot. */ | |
2268 | || (prev_pinfo & INSN_TRAP) | |
2269 | /* If the branch reads a register that the previous | |
2270 | instruction sets, we can not swap. */ | |
2271 | || (! mips_opts.mips16 | |
2272 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2273 | && insn_uses_reg (ip, | |
2274 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
2275 | & OP_MASK_RT), | |
2276 | MIPS_GR_REG)) | |
2277 | || (! mips_opts.mips16 | |
2278 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2279 | && insn_uses_reg (ip, | |
2280 | ((prev_insn.insn_opcode >> OP_SH_RD) | |
2281 | & OP_MASK_RD), | |
2282 | MIPS_GR_REG)) | |
2283 | || (mips_opts.mips16 | |
2284 | && (((prev_pinfo & MIPS16_INSN_WRITE_X) | |
2285 | && insn_uses_reg (ip, | |
2286 | ((prev_insn.insn_opcode | |
2287 | >> MIPS16OP_SH_RX) | |
2288 | & MIPS16OP_MASK_RX), | |
2289 | MIPS16_REG)) | |
2290 | || ((prev_pinfo & MIPS16_INSN_WRITE_Y) | |
2291 | && insn_uses_reg (ip, | |
2292 | ((prev_insn.insn_opcode | |
2293 | >> MIPS16OP_SH_RY) | |
2294 | & MIPS16OP_MASK_RY), | |
2295 | MIPS16_REG)) | |
2296 | || ((prev_pinfo & MIPS16_INSN_WRITE_Z) | |
2297 | && insn_uses_reg (ip, | |
2298 | ((prev_insn.insn_opcode | |
2299 | >> MIPS16OP_SH_RZ) | |
2300 | & MIPS16OP_MASK_RZ), | |
2301 | MIPS16_REG)) | |
2302 | || ((prev_pinfo & MIPS16_INSN_WRITE_T) | |
2303 | && insn_uses_reg (ip, TREG, MIPS_GR_REG)) | |
2304 | || ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2305 | && insn_uses_reg (ip, RA, MIPS_GR_REG)) | |
2306 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2307 | && insn_uses_reg (ip, | |
2308 | MIPS16OP_EXTRACT_REG32R (prev_insn. | |
2309 | insn_opcode), | |
2310 | MIPS_GR_REG)))) | |
2311 | /* If the branch writes a register that the previous | |
2312 | instruction sets, we can not swap (we know that | |
2313 | branches write only to RD or to $31). */ | |
2314 | || (! mips_opts.mips16 | |
2315 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2316 | && (((pinfo & INSN_WRITE_GPR_D) | |
2317 | && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT) | |
2318 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2319 | || ((pinfo & INSN_WRITE_GPR_31) | |
2320 | && (((prev_insn.insn_opcode >> OP_SH_RT) | |
2321 | & OP_MASK_RT) | |
2322 | == 31)))) | |
2323 | || (! mips_opts.mips16 | |
2324 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2325 | && (((pinfo & INSN_WRITE_GPR_D) | |
2326 | && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD) | |
2327 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2328 | || ((pinfo & INSN_WRITE_GPR_31) | |
2329 | && (((prev_insn.insn_opcode >> OP_SH_RD) | |
2330 | & OP_MASK_RD) | |
2331 | == 31)))) | |
2332 | || (mips_opts.mips16 | |
2333 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2334 | && ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2335 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2336 | && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode) | |
2337 | == RA)))) | |
2338 | /* If the branch writes a register that the previous | |
2339 | instruction reads, we can not swap (we know that | |
2340 | branches only write to RD or to $31). */ | |
2341 | || (! mips_opts.mips16 | |
2342 | && (pinfo & INSN_WRITE_GPR_D) | |
2343 | && insn_uses_reg (&prev_insn, | |
2344 | ((ip->insn_opcode >> OP_SH_RD) | |
2345 | & OP_MASK_RD), | |
2346 | MIPS_GR_REG)) | |
2347 | || (! mips_opts.mips16 | |
2348 | && (pinfo & INSN_WRITE_GPR_31) | |
2349 | && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG)) | |
2350 | || (mips_opts.mips16 | |
2351 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2352 | && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG)) | |
2353 | /* If we are generating embedded PIC code, the branch | |
2354 | might be expanded into a sequence which uses $at, so | |
2355 | we can't swap with an instruction which reads it. */ | |
2356 | || (mips_pic == EMBEDDED_PIC | |
2357 | && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG)) | |
2358 | /* If the previous previous instruction has a load | |
2359 | delay, and sets a register that the branch reads, we | |
2360 | can not swap. */ | |
2361 | || (! mips_opts.mips16 | |
9ce8a5dd | 2362 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
bdaaa2e1 | 2363 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2364 | && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY) |
2365 | || (! gpr_interlocks | |
2366 | && (prev_prev_insn.insn_mo->pinfo | |
2367 | & INSN_LOAD_MEMORY_DELAY))) | |
2368 | && insn_uses_reg (ip, | |
2369 | ((prev_prev_insn.insn_opcode >> OP_SH_RT) | |
2370 | & OP_MASK_RT), | |
2371 | MIPS_GR_REG)) | |
2372 | /* If one instruction sets a condition code and the | |
2373 | other one uses a condition code, we can not swap. */ | |
2374 | || ((pinfo & INSN_READ_COND_CODE) | |
2375 | && (prev_pinfo & INSN_WRITE_COND_CODE)) | |
2376 | || ((pinfo & INSN_WRITE_COND_CODE) | |
2377 | && (prev_pinfo & INSN_READ_COND_CODE)) | |
2378 | /* If the previous instruction uses the PC, we can not | |
2379 | swap. */ | |
2380 | || (mips_opts.mips16 | |
2381 | && (prev_pinfo & MIPS16_INSN_READ_PC)) | |
2382 | /* If the previous instruction was extended, we can not | |
2383 | swap. */ | |
2384 | || (mips_opts.mips16 && prev_insn_extended) | |
2385 | /* If the previous instruction had a fixup in mips16 | |
2386 | mode, we can not swap. This normally means that the | |
2387 | previous instruction was a 4 byte branch anyhow. */ | |
f6688943 | 2388 | || (mips_opts.mips16 && prev_insn_fixp[0]) |
bdaaa2e1 KH |
2389 | /* If the previous instruction is a sync, sync.l, or |
2390 | sync.p, we can not swap. */ | |
f173e82e | 2391 | || (prev_pinfo & INSN_SYNC)) |
252b5132 RH |
2392 | { |
2393 | /* We could do even better for unconditional branches to | |
2394 | portions of this object file; we could pick up the | |
2395 | instruction at the destination, put it in the delay | |
2396 | slot, and bump the destination address. */ | |
2397 | emit_nop (); | |
2398 | /* Update the previous insn information. */ | |
2399 | prev_prev_insn = *ip; | |
2400 | prev_insn.insn_mo = &dummy_opcode; | |
2401 | } | |
2402 | else | |
2403 | { | |
2404 | /* It looks like we can actually do the swap. */ | |
2405 | if (! mips_opts.mips16) | |
2406 | { | |
2407 | char *prev_f; | |
2408 | char temp[4]; | |
2409 | ||
2410 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2411 | memcpy (temp, prev_f, 4); | |
2412 | memcpy (prev_f, f, 4); | |
2413 | memcpy (f, temp, 4); | |
f6688943 TS |
2414 | if (prev_insn_fixp[0]) |
2415 | { | |
2416 | prev_insn_fixp[0]->fx_frag = frag_now; | |
2417 | prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal; | |
2418 | } | |
2419 | if (prev_insn_fixp[1]) | |
2420 | { | |
2421 | prev_insn_fixp[1]->fx_frag = frag_now; | |
2422 | prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal; | |
2423 | } | |
2424 | if (prev_insn_fixp[2]) | |
252b5132 | 2425 | { |
f6688943 TS |
2426 | prev_insn_fixp[2]->fx_frag = frag_now; |
2427 | prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal; | |
252b5132 | 2428 | } |
f6688943 | 2429 | if (fixp[0]) |
252b5132 | 2430 | { |
f6688943 TS |
2431 | fixp[0]->fx_frag = prev_insn_frag; |
2432 | fixp[0]->fx_where = prev_insn_where; | |
2433 | } | |
2434 | if (fixp[1]) | |
2435 | { | |
2436 | fixp[1]->fx_frag = prev_insn_frag; | |
2437 | fixp[1]->fx_where = prev_insn_where; | |
2438 | } | |
2439 | if (fixp[2]) | |
2440 | { | |
2441 | fixp[2]->fx_frag = prev_insn_frag; | |
2442 | fixp[2]->fx_where = prev_insn_where; | |
252b5132 RH |
2443 | } |
2444 | } | |
2445 | else | |
2446 | { | |
2447 | char *prev_f; | |
2448 | char temp[2]; | |
2449 | ||
f6688943 TS |
2450 | assert (prev_insn_fixp[0] == NULL); |
2451 | assert (prev_insn_fixp[1] == NULL); | |
2452 | assert (prev_insn_fixp[2] == NULL); | |
252b5132 RH |
2453 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; |
2454 | memcpy (temp, prev_f, 2); | |
2455 | memcpy (prev_f, f, 2); | |
f6688943 | 2456 | if (*reloc_type != BFD_RELOC_MIPS16_JMP) |
252b5132 | 2457 | { |
f6688943 | 2458 | assert (*reloc_type == BFD_RELOC_UNUSED); |
252b5132 RH |
2459 | memcpy (f, temp, 2); |
2460 | } | |
2461 | else | |
2462 | { | |
2463 | memcpy (f, f + 2, 2); | |
2464 | memcpy (f + 2, temp, 2); | |
2465 | } | |
f6688943 TS |
2466 | if (fixp[0]) |
2467 | { | |
2468 | fixp[0]->fx_frag = prev_insn_frag; | |
2469 | fixp[0]->fx_where = prev_insn_where; | |
2470 | } | |
2471 | if (fixp[1]) | |
2472 | { | |
2473 | fixp[1]->fx_frag = prev_insn_frag; | |
2474 | fixp[1]->fx_where = prev_insn_where; | |
2475 | } | |
2476 | if (fixp[2]) | |
252b5132 | 2477 | { |
f6688943 TS |
2478 | fixp[2]->fx_frag = prev_insn_frag; |
2479 | fixp[2]->fx_where = prev_insn_where; | |
252b5132 RH |
2480 | } |
2481 | } | |
2482 | ||
2483 | /* Update the previous insn information; leave prev_insn | |
2484 | unchanged. */ | |
2485 | prev_prev_insn = *ip; | |
2486 | } | |
2487 | prev_insn_is_delay_slot = 1; | |
2488 | ||
2489 | /* If that was an unconditional branch, forget the previous | |
2490 | insn information. */ | |
2491 | if (pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2492 | { | |
2493 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2494 | prev_insn.insn_mo = &dummy_opcode; | |
2495 | } | |
2496 | ||
f6688943 TS |
2497 | prev_insn_fixp[0] = NULL; |
2498 | prev_insn_fixp[1] = NULL; | |
2499 | prev_insn_fixp[2] = NULL; | |
2500 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; | |
2501 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2502 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2503 | prev_insn_extended = 0; |
2504 | } | |
2505 | else if (pinfo & INSN_COND_BRANCH_LIKELY) | |
2506 | { | |
2507 | /* We don't yet optimize a branch likely. What we should do | |
2508 | is look at the target, copy the instruction found there | |
2509 | into the delay slot, and increment the branch to jump to | |
2510 | the next instruction. */ | |
2511 | emit_nop (); | |
2512 | /* Update the previous insn information. */ | |
2513 | prev_prev_insn = *ip; | |
2514 | prev_insn.insn_mo = &dummy_opcode; | |
f6688943 TS |
2515 | prev_insn_fixp[0] = NULL; |
2516 | prev_insn_fixp[1] = NULL; | |
2517 | prev_insn_fixp[2] = NULL; | |
2518 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; | |
2519 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2520 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2521 | prev_insn_extended = 0; |
2522 | } | |
2523 | else | |
2524 | { | |
2525 | /* Update the previous insn information. */ | |
2526 | if (nops > 0) | |
2527 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2528 | else | |
2529 | prev_prev_insn = prev_insn; | |
2530 | prev_insn = *ip; | |
2531 | ||
2532 | /* Any time we see a branch, we always fill the delay slot | |
2533 | immediately; since this insn is not a branch, we know it | |
2534 | is not in a delay slot. */ | |
2535 | prev_insn_is_delay_slot = 0; | |
2536 | ||
f6688943 TS |
2537 | prev_insn_fixp[0] = fixp[0]; |
2538 | prev_insn_fixp[1] = fixp[1]; | |
2539 | prev_insn_fixp[2] = fixp[2]; | |
2540 | prev_insn_reloc_type[0] = reloc_type[0]; | |
2541 | prev_insn_reloc_type[1] = reloc_type[1]; | |
2542 | prev_insn_reloc_type[2] = reloc_type[2]; | |
252b5132 RH |
2543 | if (mips_opts.mips16) |
2544 | prev_insn_extended = (ip->use_extend | |
f6688943 | 2545 | || *reloc_type > BFD_RELOC_UNUSED); |
252b5132 RH |
2546 | } |
2547 | ||
2548 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2549 | prev_insn_unreordered = 0; | |
2550 | prev_insn_frag = frag_now; | |
2551 | prev_insn_where = f - frag_now->fr_literal; | |
2552 | prev_insn_valid = 1; | |
2553 | } | |
2554 | else if (place == NULL) | |
2555 | { | |
2556 | /* We need to record a bit of information even when we are not | |
2557 | reordering, in order to determine the base address for mips16 | |
2558 | PC relative relocs. */ | |
2559 | prev_prev_insn = prev_insn; | |
2560 | prev_insn = *ip; | |
f6688943 TS |
2561 | prev_insn_reloc_type[0] = reloc_type[0]; |
2562 | prev_insn_reloc_type[1] = reloc_type[1]; | |
2563 | prev_insn_reloc_type[2] = reloc_type[2]; | |
252b5132 RH |
2564 | prev_prev_insn_unreordered = prev_insn_unreordered; |
2565 | prev_insn_unreordered = 1; | |
2566 | } | |
2567 | ||
2568 | /* We just output an insn, so the next one doesn't have a label. */ | |
2569 | mips_clear_insn_labels (); | |
2570 | ||
2571 | /* We must ensure that a fixup associated with an unmatched %hi | |
2572 | reloc does not become a variant frag. Otherwise, the | |
2573 | rearrangement of %hi relocs in frob_file may confuse | |
2574 | tc_gen_reloc. */ | |
2575 | if (unmatched_hi) | |
2576 | { | |
2577 | frag_wane (frag_now); | |
2578 | frag_new (0); | |
2579 | } | |
2580 | } | |
2581 | ||
2582 | /* This function forgets that there was any previous instruction or | |
2583 | label. If PRESERVE is non-zero, it remembers enough information to | |
bdaaa2e1 | 2584 | know whether nops are needed before a noreorder section. */ |
252b5132 RH |
2585 | |
2586 | static void | |
2587 | mips_no_prev_insn (preserve) | |
2588 | int preserve; | |
2589 | { | |
2590 | if (! preserve) | |
2591 | { | |
2592 | prev_insn.insn_mo = &dummy_opcode; | |
2593 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2594 | prev_nop_frag = NULL; | |
2595 | prev_nop_frag_holds = 0; | |
2596 | prev_nop_frag_required = 0; | |
2597 | prev_nop_frag_since = 0; | |
2598 | } | |
2599 | prev_insn_valid = 0; | |
2600 | prev_insn_is_delay_slot = 0; | |
2601 | prev_insn_unreordered = 0; | |
2602 | prev_insn_extended = 0; | |
f6688943 TS |
2603 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; |
2604 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2605 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2606 | prev_prev_insn_unreordered = 0; |
2607 | mips_clear_insn_labels (); | |
2608 | } | |
2609 | ||
2610 | /* This function must be called whenever we turn on noreorder or emit | |
2611 | something other than instructions. It inserts any NOPS which might | |
2612 | be needed by the previous instruction, and clears the information | |
2613 | kept for the previous instructions. The INSNS parameter is true if | |
bdaaa2e1 | 2614 | instructions are to follow. */ |
252b5132 RH |
2615 | |
2616 | static void | |
2617 | mips_emit_delays (insns) | |
2618 | boolean insns; | |
2619 | { | |
2620 | if (! mips_opts.noreorder) | |
2621 | { | |
2622 | int nops; | |
2623 | ||
2624 | nops = 0; | |
2625 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2626 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2627 | && (! cop_interlocks |
2628 | && (prev_insn.insn_mo->pinfo | |
2629 | & (INSN_LOAD_COPROC_DELAY | |
2630 | | INSN_COPROC_MOVE_DELAY | |
2631 | | INSN_WRITE_COND_CODE)))) | |
2632 | || (! hilo_interlocks | |
2633 | && (prev_insn.insn_mo->pinfo | |
2634 | & (INSN_READ_LO | |
2635 | | INSN_READ_HI))) | |
2636 | || (! mips_opts.mips16 | |
2637 | && ! gpr_interlocks | |
bdaaa2e1 | 2638 | && (prev_insn.insn_mo->pinfo |
252b5132 RH |
2639 | & INSN_LOAD_MEMORY_DELAY)) |
2640 | || (! mips_opts.mips16 | |
e7af610e | 2641 | && mips_opts.isa == ISA_MIPS1 |
252b5132 RH |
2642 | && (prev_insn.insn_mo->pinfo |
2643 | & INSN_COPROC_MEMORY_DELAY))) | |
2644 | { | |
beae10d5 | 2645 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2646 | ++nops; |
2647 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2648 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2649 | && (! cop_interlocks |
2650 | && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2651 | || (! hilo_interlocks | |
2652 | && ((prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2653 | || (prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2654 | ++nops; | |
2655 | ||
2656 | if (prev_insn_unreordered) | |
2657 | nops = 0; | |
2658 | } | |
2659 | else if ((! mips_opts.mips16 | |
9ce8a5dd | 2660 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2661 | && (! cop_interlocks |
2662 | && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2663 | || (! hilo_interlocks | |
2664 | && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2665 | || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2666 | { | |
beae10d5 | 2667 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2668 | if (! prev_prev_insn_unreordered) |
2669 | ++nops; | |
2670 | } | |
2671 | ||
2672 | if (nops > 0) | |
2673 | { | |
2674 | struct insn_label_list *l; | |
2675 | ||
2676 | if (insns) | |
2677 | { | |
2678 | /* Record the frag which holds the nop instructions, so | |
2679 | that we can remove them if we don't need them. */ | |
2680 | frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4); | |
2681 | prev_nop_frag = frag_now; | |
2682 | prev_nop_frag_holds = nops; | |
2683 | prev_nop_frag_required = 0; | |
2684 | prev_nop_frag_since = 0; | |
2685 | } | |
2686 | ||
2687 | for (; nops > 0; --nops) | |
2688 | emit_nop (); | |
2689 | ||
2690 | if (insns) | |
2691 | { | |
2692 | /* Move on to a new frag, so that it is safe to simply | |
bdaaa2e1 | 2693 | decrease the size of prev_nop_frag. */ |
252b5132 RH |
2694 | frag_wane (frag_now); |
2695 | frag_new (0); | |
2696 | } | |
2697 | ||
2698 | for (l = insn_labels; l != NULL; l = l->next) | |
2699 | { | |
98aa84af AM |
2700 | valueT val; |
2701 | ||
252b5132 | 2702 | assert (S_GET_SEGMENT (l->label) == now_seg); |
49309057 | 2703 | symbol_set_frag (l->label, frag_now); |
98aa84af | 2704 | val = (valueT) frag_now_fix (); |
252b5132 RH |
2705 | /* mips16 text labels are stored as odd. */ |
2706 | if (mips_opts.mips16) | |
98aa84af AM |
2707 | val += 1; |
2708 | S_SET_VALUE (l->label, val); | |
252b5132 RH |
2709 | } |
2710 | } | |
2711 | } | |
2712 | ||
2713 | /* Mark instruction labels in mips16 mode. */ | |
2714 | if (mips_opts.mips16 && insns) | |
2715 | mips16_mark_labels (); | |
2716 | ||
2717 | mips_no_prev_insn (insns); | |
2718 | } | |
2719 | ||
2720 | /* Build an instruction created by a macro expansion. This is passed | |
2721 | a pointer to the count of instructions created so far, an | |
2722 | expression, the name of the instruction to build, an operand format | |
2723 | string, and corresponding arguments. */ | |
2724 | ||
2725 | #ifdef USE_STDARG | |
2726 | static void | |
2727 | macro_build (char *place, | |
2728 | int *counter, | |
2729 | expressionS * ep, | |
2730 | const char *name, | |
2731 | const char *fmt, | |
2732 | ...) | |
2733 | #else | |
2734 | static void | |
2735 | macro_build (place, counter, ep, name, fmt, va_alist) | |
2736 | char *place; | |
2737 | int *counter; | |
2738 | expressionS *ep; | |
2739 | const char *name; | |
2740 | const char *fmt; | |
2741 | va_dcl | |
2742 | #endif | |
2743 | { | |
2744 | struct mips_cl_insn insn; | |
f6688943 | 2745 | bfd_reloc_code_real_type r[3]; |
252b5132 | 2746 | va_list args; |
252b5132 RH |
2747 | |
2748 | #ifdef USE_STDARG | |
2749 | va_start (args, fmt); | |
2750 | #else | |
2751 | va_start (args); | |
2752 | #endif | |
2753 | ||
2754 | /* | |
2755 | * If the macro is about to expand into a second instruction, | |
2756 | * print a warning if needed. We need to pass ip as a parameter | |
2757 | * to generate a better warning message here... | |
2758 | */ | |
2759 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2760 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2761 | ||
2762 | if (place == NULL) | |
2763 | *counter += 1; /* bump instruction counter */ | |
2764 | ||
2765 | if (mips_opts.mips16) | |
2766 | { | |
2767 | mips16_macro_build (place, counter, ep, name, fmt, args); | |
2768 | va_end (args); | |
2769 | return; | |
2770 | } | |
2771 | ||
f6688943 TS |
2772 | r[0] = BFD_RELOC_UNUSED; |
2773 | r[1] = BFD_RELOC_UNUSED; | |
2774 | r[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2775 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); |
2776 | assert (insn.insn_mo); | |
2777 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2778 | ||
2779 | /* Search until we get a match for NAME. */ | |
2780 | while (1) | |
2781 | { | |
252b5132 RH |
2782 | if (strcmp (fmt, insn.insn_mo->args) == 0 |
2783 | && insn.insn_mo->pinfo != INSN_MACRO | |
ea1fb5dc | 2784 | && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch) |
ec68c924 | 2785 | && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0)) |
252b5132 RH |
2786 | break; |
2787 | ||
2788 | ++insn.insn_mo; | |
2789 | assert (insn.insn_mo->name); | |
2790 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2791 | } | |
2792 | ||
2793 | insn.insn_opcode = insn.insn_mo->match; | |
2794 | for (;;) | |
2795 | { | |
2796 | switch (*fmt++) | |
2797 | { | |
2798 | case '\0': | |
2799 | break; | |
2800 | ||
2801 | case ',': | |
2802 | case '(': | |
2803 | case ')': | |
2804 | continue; | |
2805 | ||
2806 | case 't': | |
2807 | case 'w': | |
2808 | case 'E': | |
38487616 | 2809 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RT; |
252b5132 RH |
2810 | continue; |
2811 | ||
2812 | case 'c': | |
38487616 TS |
2813 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE; |
2814 | continue; | |
2815 | ||
252b5132 RH |
2816 | case 'T': |
2817 | case 'W': | |
38487616 | 2818 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FT; |
252b5132 RH |
2819 | continue; |
2820 | ||
2821 | case 'd': | |
2822 | case 'G': | |
38487616 | 2823 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RD; |
252b5132 RH |
2824 | continue; |
2825 | ||
4372b673 NC |
2826 | case 'U': |
2827 | { | |
2828 | int tmp = va_arg (args, int); | |
2829 | ||
38487616 TS |
2830 | insn.insn_opcode |= tmp << OP_SH_RT; |
2831 | insn.insn_opcode |= tmp << OP_SH_RD; | |
beae10d5 | 2832 | continue; |
4372b673 NC |
2833 | } |
2834 | ||
252b5132 RH |
2835 | case 'V': |
2836 | case 'S': | |
38487616 | 2837 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FS; |
252b5132 RH |
2838 | continue; |
2839 | ||
2840 | case 'z': | |
2841 | continue; | |
2842 | ||
2843 | case '<': | |
38487616 | 2844 | insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT; |
252b5132 RH |
2845 | continue; |
2846 | ||
2847 | case 'D': | |
38487616 | 2848 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FD; |
252b5132 RH |
2849 | continue; |
2850 | ||
2851 | case 'B': | |
38487616 | 2852 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20; |
252b5132 RH |
2853 | continue; |
2854 | ||
4372b673 | 2855 | case 'J': |
38487616 | 2856 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19; |
4372b673 NC |
2857 | continue; |
2858 | ||
252b5132 | 2859 | case 'q': |
38487616 | 2860 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2; |
252b5132 RH |
2861 | continue; |
2862 | ||
2863 | case 'b': | |
2864 | case 's': | |
2865 | case 'r': | |
2866 | case 'v': | |
38487616 | 2867 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RS; |
252b5132 RH |
2868 | continue; |
2869 | ||
2870 | case 'i': | |
2871 | case 'j': | |
2872 | case 'o': | |
f6688943 TS |
2873 | *r = (bfd_reloc_code_real_type) va_arg (args, int); |
2874 | assert (*r == BFD_RELOC_MIPS_GPREL | |
2875 | || *r == BFD_RELOC_MIPS_LITERAL | |
2876 | || *r == BFD_RELOC_MIPS_HIGHER | |
2877 | || *r == BFD_RELOC_HI16_S | |
2878 | || *r == BFD_RELOC_LO16 | |
2879 | || *r == BFD_RELOC_MIPS_GOT16 | |
2880 | || *r == BFD_RELOC_MIPS_CALL16 | |
2881 | || *r == BFD_RELOC_MIPS_GOT_LO16 | |
2882 | || *r == BFD_RELOC_MIPS_CALL_LO16 | |
252b5132 | 2883 | || (ep->X_op == O_subtract |
f6688943 | 2884 | && *r == BFD_RELOC_PCREL_LO16)); |
252b5132 RH |
2885 | continue; |
2886 | ||
2887 | case 'u': | |
f6688943 | 2888 | *r = (bfd_reloc_code_real_type) va_arg (args, int); |
252b5132 RH |
2889 | assert (ep != NULL |
2890 | && (ep->X_op == O_constant | |
2891 | || (ep->X_op == O_symbol | |
f6688943 TS |
2892 | && (*r == BFD_RELOC_MIPS_HIGHEST |
2893 | || *r == BFD_RELOC_HI16_S | |
2894 | || *r == BFD_RELOC_HI16 | |
2895 | || *r == BFD_RELOC_GPREL16 | |
2896 | || *r == BFD_RELOC_MIPS_GOT_HI16 | |
2897 | || *r == BFD_RELOC_MIPS_CALL_HI16)) | |
252b5132 | 2898 | || (ep->X_op == O_subtract |
f6688943 | 2899 | && *r == BFD_RELOC_PCREL_HI16_S))); |
252b5132 RH |
2900 | continue; |
2901 | ||
2902 | case 'p': | |
2903 | assert (ep != NULL); | |
2904 | /* | |
2905 | * This allows macro() to pass an immediate expression for | |
2906 | * creating short branches without creating a symbol. | |
2907 | * Note that the expression still might come from the assembly | |
2908 | * input, in which case the value is not checked for range nor | |
2909 | * is a relocation entry generated (yuck). | |
2910 | */ | |
2911 | if (ep->X_op == O_constant) | |
2912 | { | |
2913 | insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff; | |
2914 | ep = NULL; | |
2915 | } | |
2916 | else | |
cb56d3d3 | 2917 | if (mips_pic == EMBEDDED_PIC) |
f6688943 | 2918 | *r = BFD_RELOC_16_PCREL_S2; |
cb56d3d3 | 2919 | else |
f6688943 | 2920 | *r = BFD_RELOC_16_PCREL; |
252b5132 RH |
2921 | continue; |
2922 | ||
2923 | case 'a': | |
2924 | assert (ep != NULL); | |
f6688943 | 2925 | *r = BFD_RELOC_MIPS_JMP; |
252b5132 RH |
2926 | continue; |
2927 | ||
2928 | case 'C': | |
2929 | insn.insn_opcode |= va_arg (args, unsigned long); | |
2930 | continue; | |
2931 | ||
2932 | default: | |
2933 | internalError (); | |
2934 | } | |
2935 | break; | |
2936 | } | |
2937 | va_end (args); | |
f6688943 | 2938 | assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
252b5132 RH |
2939 | |
2940 | append_insn (place, &insn, ep, r, false); | |
2941 | } | |
2942 | ||
2943 | static void | |
2944 | mips16_macro_build (place, counter, ep, name, fmt, args) | |
2945 | char *place; | |
43841e91 | 2946 | int *counter ATTRIBUTE_UNUSED; |
252b5132 RH |
2947 | expressionS *ep; |
2948 | const char *name; | |
2949 | const char *fmt; | |
2950 | va_list args; | |
2951 | { | |
2952 | struct mips_cl_insn insn; | |
f6688943 TS |
2953 | bfd_reloc_code_real_type r[3] |
2954 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 | 2955 | |
252b5132 RH |
2956 | insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name); |
2957 | assert (insn.insn_mo); | |
2958 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2959 | ||
2960 | while (strcmp (fmt, insn.insn_mo->args) != 0 | |
2961 | || insn.insn_mo->pinfo == INSN_MACRO) | |
2962 | { | |
2963 | ++insn.insn_mo; | |
2964 | assert (insn.insn_mo->name); | |
2965 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2966 | } | |
2967 | ||
2968 | insn.insn_opcode = insn.insn_mo->match; | |
2969 | insn.use_extend = false; | |
2970 | ||
2971 | for (;;) | |
2972 | { | |
2973 | int c; | |
2974 | ||
2975 | c = *fmt++; | |
2976 | switch (c) | |
2977 | { | |
2978 | case '\0': | |
2979 | break; | |
2980 | ||
2981 | case ',': | |
2982 | case '(': | |
2983 | case ')': | |
2984 | continue; | |
2985 | ||
2986 | case 'y': | |
2987 | case 'w': | |
2988 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY; | |
2989 | continue; | |
2990 | ||
2991 | case 'x': | |
2992 | case 'v': | |
2993 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX; | |
2994 | continue; | |
2995 | ||
2996 | case 'z': | |
2997 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ; | |
2998 | continue; | |
2999 | ||
3000 | case 'Z': | |
3001 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z; | |
3002 | continue; | |
3003 | ||
3004 | case '0': | |
3005 | case 'S': | |
3006 | case 'P': | |
3007 | case 'R': | |
3008 | continue; | |
3009 | ||
3010 | case 'X': | |
3011 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32; | |
3012 | continue; | |
3013 | ||
3014 | case 'Y': | |
3015 | { | |
3016 | int regno; | |
3017 | ||
3018 | regno = va_arg (args, int); | |
3019 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
3020 | insn.insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
3021 | } | |
3022 | continue; | |
3023 | ||
3024 | case '<': | |
3025 | case '>': | |
3026 | case '4': | |
3027 | case '5': | |
3028 | case 'H': | |
3029 | case 'W': | |
3030 | case 'D': | |
3031 | case 'j': | |
3032 | case '8': | |
3033 | case 'V': | |
3034 | case 'C': | |
3035 | case 'U': | |
3036 | case 'k': | |
3037 | case 'K': | |
3038 | case 'p': | |
3039 | case 'q': | |
3040 | { | |
3041 | assert (ep != NULL); | |
3042 | ||
3043 | if (ep->X_op != O_constant) | |
f6688943 | 3044 | *r = BFD_RELOC_UNUSED + c; |
252b5132 RH |
3045 | else |
3046 | { | |
3047 | mips16_immed ((char *) NULL, 0, c, ep->X_add_number, false, | |
3048 | false, false, &insn.insn_opcode, | |
3049 | &insn.use_extend, &insn.extend); | |
3050 | ep = NULL; | |
f6688943 | 3051 | *r = BFD_RELOC_UNUSED; |
252b5132 RH |
3052 | } |
3053 | } | |
3054 | continue; | |
3055 | ||
3056 | case '6': | |
3057 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6; | |
3058 | continue; | |
3059 | } | |
3060 | ||
3061 | break; | |
3062 | } | |
3063 | ||
f6688943 | 3064 | assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
252b5132 RH |
3065 | |
3066 | append_insn (place, &insn, ep, r, false); | |
3067 | } | |
3068 | ||
3069 | /* | |
3070 | * Generate a "lui" instruction. | |
3071 | */ | |
3072 | static void | |
3073 | macro_build_lui (place, counter, ep, regnum) | |
3074 | char *place; | |
3075 | int *counter; | |
3076 | expressionS *ep; | |
3077 | int regnum; | |
3078 | { | |
3079 | expressionS high_expr; | |
3080 | struct mips_cl_insn insn; | |
f6688943 TS |
3081 | bfd_reloc_code_real_type r[3] |
3082 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
3083 | CONST char *name = "lui"; |
3084 | CONST char *fmt = "t,u"; | |
3085 | ||
3086 | assert (! mips_opts.mips16); | |
3087 | ||
3088 | if (place == NULL) | |
3089 | high_expr = *ep; | |
3090 | else | |
3091 | { | |
3092 | high_expr.X_op = O_constant; | |
3093 | high_expr.X_add_number = ep->X_add_number; | |
3094 | } | |
3095 | ||
3096 | if (high_expr.X_op == O_constant) | |
3097 | { | |
3098 | /* we can compute the instruction now without a relocation entry */ | |
e7d556df TS |
3099 | high_expr.X_add_number = ((high_expr.X_add_number + 0x8000) |
3100 | >> 16) & 0xffff; | |
f6688943 | 3101 | *r = BFD_RELOC_UNUSED; |
252b5132 | 3102 | } |
f6688943 | 3103 | else if (! HAVE_NEWABI) |
252b5132 RH |
3104 | { |
3105 | assert (ep->X_op == O_symbol); | |
3106 | /* _gp_disp is a special case, used from s_cpload. */ | |
3107 | assert (mips_pic == NO_PIC | |
3108 | || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0); | |
f6688943 | 3109 | *r = BFD_RELOC_HI16_S; |
252b5132 RH |
3110 | } |
3111 | ||
3112 | /* | |
3113 | * If the macro is about to expand into a second instruction, | |
3114 | * print a warning if needed. We need to pass ip as a parameter | |
3115 | * to generate a better warning message here... | |
3116 | */ | |
3117 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
3118 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
3119 | ||
3120 | if (place == NULL) | |
3121 | *counter += 1; /* bump instruction counter */ | |
3122 | ||
3123 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
3124 | assert (insn.insn_mo); | |
3125 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
3126 | assert (strcmp (fmt, insn.insn_mo->args) == 0); | |
3127 | ||
3128 | insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT); | |
f6688943 | 3129 | if (*r == BFD_RELOC_UNUSED) |
252b5132 RH |
3130 | { |
3131 | insn.insn_opcode |= high_expr.X_add_number; | |
3132 | append_insn (place, &insn, NULL, r, false); | |
3133 | } | |
3134 | else | |
3135 | append_insn (place, &insn, &high_expr, r, false); | |
3136 | } | |
3137 | ||
3138 | /* set_at() | |
3139 | * Generates code to set the $at register to true (one) | |
3140 | * if reg is less than the immediate expression. | |
3141 | */ | |
3142 | static void | |
3143 | set_at (counter, reg, unsignedp) | |
3144 | int *counter; | |
3145 | int reg; | |
3146 | int unsignedp; | |
3147 | { | |
3148 | if (imm_expr.X_op == O_constant | |
3149 | && imm_expr.X_add_number >= -0x8000 | |
3150 | && imm_expr.X_add_number < 0x8000) | |
3151 | macro_build ((char *) NULL, counter, &imm_expr, | |
3152 | unsignedp ? "sltiu" : "slti", | |
3153 | "t,r,j", AT, reg, (int) BFD_RELOC_LO16); | |
3154 | else | |
3155 | { | |
3156 | load_register (counter, AT, &imm_expr, 0); | |
3157 | macro_build ((char *) NULL, counter, NULL, | |
3158 | unsignedp ? "sltu" : "slt", | |
3159 | "d,v,t", AT, reg, AT); | |
3160 | } | |
3161 | } | |
3162 | ||
3163 | /* Warn if an expression is not a constant. */ | |
3164 | ||
3165 | static void | |
3166 | check_absolute_expr (ip, ex) | |
3167 | struct mips_cl_insn *ip; | |
3168 | expressionS *ex; | |
3169 | { | |
3170 | if (ex->X_op == O_big) | |
3171 | as_bad (_("unsupported large constant")); | |
3172 | else if (ex->X_op != O_constant) | |
3173 | as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name); | |
3174 | } | |
3175 | ||
3176 | /* Count the leading zeroes by performing a binary chop. This is a | |
3177 | bulky bit of source, but performance is a LOT better for the | |
3178 | majority of values than a simple loop to count the bits: | |
3179 | for (lcnt = 0; (lcnt < 32); lcnt++) | |
3180 | if ((v) & (1 << (31 - lcnt))) | |
3181 | break; | |
3182 | However it is not code size friendly, and the gain will drop a bit | |
3183 | on certain cached systems. | |
3184 | */ | |
3185 | #define COUNT_TOP_ZEROES(v) \ | |
3186 | (((v) & ~0xffff) == 0 \ | |
3187 | ? ((v) & ~0xff) == 0 \ | |
3188 | ? ((v) & ~0xf) == 0 \ | |
3189 | ? ((v) & ~0x3) == 0 \ | |
3190 | ? ((v) & ~0x1) == 0 \ | |
3191 | ? !(v) \ | |
3192 | ? 32 \ | |
3193 | : 31 \ | |
3194 | : 30 \ | |
3195 | : ((v) & ~0x7) == 0 \ | |
3196 | ? 29 \ | |
3197 | : 28 \ | |
3198 | : ((v) & ~0x3f) == 0 \ | |
3199 | ? ((v) & ~0x1f) == 0 \ | |
3200 | ? 27 \ | |
3201 | : 26 \ | |
3202 | : ((v) & ~0x7f) == 0 \ | |
3203 | ? 25 \ | |
3204 | : 24 \ | |
3205 | : ((v) & ~0xfff) == 0 \ | |
3206 | ? ((v) & ~0x3ff) == 0 \ | |
3207 | ? ((v) & ~0x1ff) == 0 \ | |
3208 | ? 23 \ | |
3209 | : 22 \ | |
3210 | : ((v) & ~0x7ff) == 0 \ | |
3211 | ? 21 \ | |
3212 | : 20 \ | |
3213 | : ((v) & ~0x3fff) == 0 \ | |
3214 | ? ((v) & ~0x1fff) == 0 \ | |
3215 | ? 19 \ | |
3216 | : 18 \ | |
3217 | : ((v) & ~0x7fff) == 0 \ | |
3218 | ? 17 \ | |
3219 | : 16 \ | |
3220 | : ((v) & ~0xffffff) == 0 \ | |
3221 | ? ((v) & ~0xfffff) == 0 \ | |
3222 | ? ((v) & ~0x3ffff) == 0 \ | |
3223 | ? ((v) & ~0x1ffff) == 0 \ | |
3224 | ? 15 \ | |
3225 | : 14 \ | |
3226 | : ((v) & ~0x7ffff) == 0 \ | |
3227 | ? 13 \ | |
3228 | : 12 \ | |
3229 | : ((v) & ~0x3fffff) == 0 \ | |
3230 | ? ((v) & ~0x1fffff) == 0 \ | |
3231 | ? 11 \ | |
3232 | : 10 \ | |
3233 | : ((v) & ~0x7fffff) == 0 \ | |
3234 | ? 9 \ | |
3235 | : 8 \ | |
3236 | : ((v) & ~0xfffffff) == 0 \ | |
3237 | ? ((v) & ~0x3ffffff) == 0 \ | |
3238 | ? ((v) & ~0x1ffffff) == 0 \ | |
3239 | ? 7 \ | |
3240 | : 6 \ | |
3241 | : ((v) & ~0x7ffffff) == 0 \ | |
3242 | ? 5 \ | |
3243 | : 4 \ | |
3244 | : ((v) & ~0x3fffffff) == 0 \ | |
3245 | ? ((v) & ~0x1fffffff) == 0 \ | |
3246 | ? 3 \ | |
3247 | : 2 \ | |
3248 | : ((v) & ~0x7fffffff) == 0 \ | |
3249 | ? 1 \ | |
3250 | : 0) | |
3251 | ||
3252 | /* load_register() | |
3253 | * This routine generates the least number of instructions neccessary to load | |
3254 | * an absolute expression value into a register. | |
3255 | */ | |
3256 | static void | |
3257 | load_register (counter, reg, ep, dbl) | |
3258 | int *counter; | |
3259 | int reg; | |
3260 | expressionS *ep; | |
3261 | int dbl; | |
3262 | { | |
3263 | int freg; | |
3264 | expressionS hi32, lo32; | |
3265 | ||
3266 | if (ep->X_op != O_big) | |
3267 | { | |
3268 | assert (ep->X_op == O_constant); | |
3269 | if (ep->X_add_number < 0x8000 | |
3270 | && (ep->X_add_number >= 0 | |
3271 | || (ep->X_add_number >= -0x8000 | |
3272 | && (! dbl | |
3273 | || ! ep->X_unsigned | |
3274 | || sizeof (ep->X_add_number) > 4)))) | |
3275 | { | |
3276 | /* We can handle 16 bit signed values with an addiu to | |
3277 | $zero. No need to ever use daddiu here, since $zero and | |
3278 | the result are always correct in 32 bit mode. */ | |
3279 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3280 | (int) BFD_RELOC_LO16); | |
3281 | return; | |
3282 | } | |
3283 | else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000) | |
3284 | { | |
3285 | /* We can handle 16 bit unsigned values with an ori to | |
3286 | $zero. */ | |
3287 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0, | |
3288 | (int) BFD_RELOC_LO16); | |
3289 | return; | |
3290 | } | |
3291 | else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0 | |
3292 | || ((ep->X_add_number &~ (offsetT) 0x7fffffff) | |
3293 | == ~ (offsetT) 0x7fffffff)) | |
3294 | && (! dbl | |
3295 | || ! ep->X_unsigned | |
3296 | || sizeof (ep->X_add_number) > 4 | |
3297 | || (ep->X_add_number & 0x80000000) == 0)) | |
ca4e0257 | 3298 | || ((HAVE_32BIT_GPRS || ! dbl) |
252b5132 | 3299 | && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0) |
ca4e0257 | 3300 | || (HAVE_32BIT_GPRS |
252b5132 RH |
3301 | && ! dbl |
3302 | && ((ep->X_add_number &~ (offsetT) 0xffffffff) | |
3303 | == ~ (offsetT) 0xffffffff))) | |
3304 | { | |
3305 | /* 32 bit values require an lui. */ | |
3306 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3307 | (int) BFD_RELOC_HI16); | |
3308 | if ((ep->X_add_number & 0xffff) != 0) | |
3309 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg, | |
3310 | (int) BFD_RELOC_LO16); | |
3311 | return; | |
3312 | } | |
3313 | } | |
3314 | ||
3315 | /* The value is larger than 32 bits. */ | |
3316 | ||
ca4e0257 | 3317 | if (HAVE_32BIT_GPRS) |
252b5132 RH |
3318 | { |
3319 | as_bad (_("Number larger than 32 bits")); | |
3320 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3321 | (int) BFD_RELOC_LO16); | |
3322 | return; | |
3323 | } | |
3324 | ||
3325 | if (ep->X_op != O_big) | |
3326 | { | |
3327 | hi32 = *ep; | |
3328 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3329 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3330 | hi32.X_add_number &= 0xffffffff; | |
3331 | lo32 = *ep; | |
3332 | lo32.X_add_number &= 0xffffffff; | |
3333 | } | |
3334 | else | |
3335 | { | |
3336 | assert (ep->X_add_number > 2); | |
3337 | if (ep->X_add_number == 3) | |
3338 | generic_bignum[3] = 0; | |
3339 | else if (ep->X_add_number > 4) | |
3340 | as_bad (_("Number larger than 64 bits")); | |
3341 | lo32.X_op = O_constant; | |
3342 | lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16); | |
3343 | hi32.X_op = O_constant; | |
3344 | hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16); | |
3345 | } | |
3346 | ||
3347 | if (hi32.X_add_number == 0) | |
3348 | freg = 0; | |
3349 | else | |
3350 | { | |
3351 | int shift, bit; | |
3352 | unsigned long hi, lo; | |
3353 | ||
3354 | if (hi32.X_add_number == 0xffffffff) | |
beae10d5 KH |
3355 | { |
3356 | if ((lo32.X_add_number & 0xffff8000) == 0xffff8000) | |
3357 | { | |
3358 | macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j", | |
252b5132 | 3359 | reg, 0, (int) BFD_RELOC_LO16); |
beae10d5 KH |
3360 | return; |
3361 | } | |
3362 | if (lo32.X_add_number & 0x80000000) | |
3363 | { | |
3364 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, | |
3365 | (int) BFD_RELOC_HI16); | |
252b5132 RH |
3366 | if (lo32.X_add_number & 0xffff) |
3367 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", | |
3368 | reg, reg, (int) BFD_RELOC_LO16); | |
beae10d5 KH |
3369 | return; |
3370 | } | |
3371 | } | |
252b5132 RH |
3372 | |
3373 | /* Check for 16bit shifted constant. We know that hi32 is | |
3374 | non-zero, so start the mask on the first bit of the hi32 | |
3375 | value. */ | |
3376 | shift = 17; | |
3377 | do | |
beae10d5 KH |
3378 | { |
3379 | unsigned long himask, lomask; | |
3380 | ||
3381 | if (shift < 32) | |
3382 | { | |
3383 | himask = 0xffff >> (32 - shift); | |
3384 | lomask = (0xffff << shift) & 0xffffffff; | |
3385 | } | |
3386 | else | |
3387 | { | |
3388 | himask = 0xffff << (shift - 32); | |
3389 | lomask = 0; | |
3390 | } | |
3391 | if ((hi32.X_add_number & ~(offsetT) himask) == 0 | |
3392 | && (lo32.X_add_number & ~(offsetT) lomask) == 0) | |
3393 | { | |
3394 | expressionS tmp; | |
3395 | ||
3396 | tmp.X_op = O_constant; | |
3397 | if (shift < 32) | |
3398 | tmp.X_add_number = ((hi32.X_add_number << (32 - shift)) | |
3399 | | (lo32.X_add_number >> shift)); | |
3400 | else | |
3401 | tmp.X_add_number = hi32.X_add_number >> (shift - 32); | |
3402 | macro_build ((char *) NULL, counter, &tmp, | |
3403 | "ori", "t,r,i", reg, 0, | |
3404 | (int) BFD_RELOC_LO16); | |
3405 | macro_build ((char *) NULL, counter, NULL, | |
3406 | (shift >= 32) ? "dsll32" : "dsll", | |
3407 | "d,w,<", reg, reg, | |
3408 | (shift >= 32) ? shift - 32 : shift); | |
3409 | return; | |
3410 | } | |
3411 | shift++; | |
3412 | } | |
3413 | while (shift <= (64 - 16)); | |
252b5132 RH |
3414 | |
3415 | /* Find the bit number of the lowest one bit, and store the | |
3416 | shifted value in hi/lo. */ | |
3417 | hi = (unsigned long) (hi32.X_add_number & 0xffffffff); | |
3418 | lo = (unsigned long) (lo32.X_add_number & 0xffffffff); | |
3419 | if (lo != 0) | |
3420 | { | |
3421 | bit = 0; | |
3422 | while ((lo & 1) == 0) | |
3423 | { | |
3424 | lo >>= 1; | |
3425 | ++bit; | |
3426 | } | |
3427 | lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit); | |
3428 | hi >>= bit; | |
3429 | } | |
3430 | else | |
3431 | { | |
3432 | bit = 32; | |
3433 | while ((hi & 1) == 0) | |
3434 | { | |
3435 | hi >>= 1; | |
3436 | ++bit; | |
3437 | } | |
3438 | lo = hi; | |
3439 | hi = 0; | |
3440 | } | |
3441 | ||
3442 | /* Optimize if the shifted value is a (power of 2) - 1. */ | |
3443 | if ((hi == 0 && ((lo + 1) & lo) == 0) | |
3444 | || (lo == 0xffffffff && ((hi + 1) & hi) == 0)) | |
beae10d5 KH |
3445 | { |
3446 | shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number); | |
252b5132 | 3447 | if (shift != 0) |
beae10d5 | 3448 | { |
252b5132 RH |
3449 | expressionS tmp; |
3450 | ||
3451 | /* This instruction will set the register to be all | |
3452 | ones. */ | |
beae10d5 KH |
3453 | tmp.X_op = O_constant; |
3454 | tmp.X_add_number = (offsetT) -1; | |
3455 | macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j", | |
252b5132 | 3456 | reg, 0, (int) BFD_RELOC_LO16); |
beae10d5 KH |
3457 | if (bit != 0) |
3458 | { | |
3459 | bit += shift; | |
3460 | macro_build ((char *) NULL, counter, NULL, | |
3461 | (bit >= 32) ? "dsll32" : "dsll", | |
3462 | "d,w,<", reg, reg, | |
3463 | (bit >= 32) ? bit - 32 : bit); | |
3464 | } | |
3465 | macro_build ((char *) NULL, counter, NULL, | |
252b5132 | 3466 | (shift >= 32) ? "dsrl32" : "dsrl", |
beae10d5 | 3467 | "d,w,<", reg, reg, |
252b5132 | 3468 | (shift >= 32) ? shift - 32 : shift); |
beae10d5 KH |
3469 | return; |
3470 | } | |
3471 | } | |
252b5132 RH |
3472 | |
3473 | /* Sign extend hi32 before calling load_register, because we can | |
3474 | generally get better code when we load a sign extended value. */ | |
3475 | if ((hi32.X_add_number & 0x80000000) != 0) | |
beae10d5 | 3476 | hi32.X_add_number |= ~(offsetT) 0xffffffff; |
252b5132 RH |
3477 | load_register (counter, reg, &hi32, 0); |
3478 | freg = reg; | |
3479 | } | |
3480 | if ((lo32.X_add_number & 0xffff0000) == 0) | |
3481 | { | |
3482 | if (freg != 0) | |
3483 | { | |
3484 | macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg, | |
3485 | freg, 0); | |
3486 | freg = reg; | |
3487 | } | |
3488 | } | |
3489 | else | |
3490 | { | |
3491 | expressionS mid16; | |
3492 | ||
3493 | if ((freg == 0) && (lo32.X_add_number == 0xffffffff)) | |
beae10d5 | 3494 | { |
252b5132 RH |
3495 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, |
3496 | (int) BFD_RELOC_HI16); | |
beae10d5 KH |
3497 | macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg, |
3498 | reg, 0); | |
3499 | return; | |
3500 | } | |
252b5132 RH |
3501 | |
3502 | if (freg != 0) | |
3503 | { | |
3504 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3505 | freg, 16); | |
3506 | freg = reg; | |
3507 | } | |
3508 | mid16 = lo32; | |
3509 | mid16.X_add_number >>= 16; | |
3510 | macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg, | |
3511 | freg, (int) BFD_RELOC_LO16); | |
3512 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3513 | reg, 16); | |
3514 | freg = reg; | |
3515 | } | |
3516 | if ((lo32.X_add_number & 0xffff) != 0) | |
3517 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg, | |
3518 | (int) BFD_RELOC_LO16); | |
3519 | } | |
3520 | ||
3521 | /* Load an address into a register. */ | |
3522 | ||
3523 | static void | |
d6bc6245 | 3524 | load_address (counter, reg, ep, dbl, used_at) |
252b5132 RH |
3525 | int *counter; |
3526 | int reg; | |
3527 | expressionS *ep; | |
d6bc6245 TS |
3528 | int dbl; |
3529 | int *used_at; | |
252b5132 RH |
3530 | { |
3531 | char *p; | |
3532 | ||
3533 | if (ep->X_op != O_constant | |
3534 | && ep->X_op != O_symbol) | |
3535 | { | |
3536 | as_bad (_("expression too complex")); | |
3537 | ep->X_op = O_constant; | |
3538 | } | |
3539 | ||
3540 | if (ep->X_op == O_constant) | |
3541 | { | |
d6bc6245 | 3542 | load_register (counter, reg, ep, dbl); |
252b5132 RH |
3543 | return; |
3544 | } | |
3545 | ||
3546 | if (mips_pic == NO_PIC) | |
3547 | { | |
3548 | /* If this is a reference to a GP relative symbol, we want | |
3549 | addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
3550 | Otherwise we want | |
3551 | lui $reg,<sym> (BFD_RELOC_HI16_S) | |
3552 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
d6bc6245 | 3553 | If we have an addend, we always use the latter form. |
76b3015f | 3554 | |
d6bc6245 TS |
3555 | With 64bit address space and a usable $at we want |
3556 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
3557 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
3558 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
3559 | daddiu $at,<sym> (BFD_RELOC_LO16) | |
3560 | dsll32 $reg,0 | |
3561 | dadd $reg,$reg,$at | |
76b3015f | 3562 | |
d6bc6245 TS |
3563 | If $at is already in use, we use an path which is suboptimal |
3564 | on superscalar processors. | |
3565 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
3566 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
3567 | dsll $reg,16 | |
3568 | daddiu $reg,<sym> (BFD_RELOC_HI16_S) | |
3569 | dsll $reg,16 | |
3570 | daddiu $reg,<sym> (BFD_RELOC_LO16) | |
3571 | */ | |
3572 | if (HAVE_64BIT_ADDRESSES) | |
3573 | { | |
3574 | p = NULL; | |
3575 | ||
3576 | /* We don't do GP optimization for now because RELAX_ENCODE can't | |
3577 | hold the data for such large chunks. */ | |
3578 | ||
3579 | if (*used_at == 0) | |
3580 | { | |
3581 | macro_build (p, counter, ep, "lui", "t,u", | |
3582 | reg, (int) BFD_RELOC_MIPS_HIGHEST); | |
3583 | macro_build (p, counter, ep, "lui", "t,u", | |
3584 | AT, (int) BFD_RELOC_HI16_S); | |
3585 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3586 | reg, reg, (int) BFD_RELOC_MIPS_HIGHER); | |
3587 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3588 | AT, AT, (int) BFD_RELOC_LO16); | |
3589 | macro_build (p, counter, NULL, "dsll32", "d,w,<", | |
3590 | reg, reg, 0); | |
3591 | macro_build (p, counter, NULL, "dadd", "d,v,t", | |
3592 | reg, reg, AT); | |
3593 | *used_at = 1; | |
3594 | } | |
3595 | else | |
3596 | { | |
3597 | macro_build (p, counter, ep, "lui", "t,u", | |
3598 | reg, (int) BFD_RELOC_MIPS_HIGHEST); | |
3599 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3600 | reg, reg, (int) BFD_RELOC_MIPS_HIGHER); | |
3601 | macro_build (p, counter, NULL, "dsll", "d,w,<", | |
3602 | reg, reg, 16); | |
3603 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3604 | reg, reg, (int) BFD_RELOC_HI16_S); | |
3605 | macro_build (p, counter, NULL, "dsll", "d,w,<", | |
3606 | reg, reg, 16); | |
3607 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3608 | reg, reg, (int) BFD_RELOC_LO16); | |
3609 | } | |
3610 | } | |
252b5132 RH |
3611 | else |
3612 | { | |
d6bc6245 TS |
3613 | p = NULL; |
3614 | if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET | |
3615 | && ! nopic_need_relax (ep->X_add_symbol, 1)) | |
3616 | { | |
3617 | frag_grow (20); | |
3618 | macro_build ((char *) NULL, counter, ep, | |
3619 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
3620 | "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
3621 | p = frag_var (rs_machine_dependent, 8, 0, | |
3622 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
3623 | mips_opts.warn_about_macros), | |
3624 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3625 | } | |
3626 | macro_build_lui (p, counter, ep, reg); | |
3627 | if (p != NULL) | |
3628 | p += 4; | |
3629 | macro_build (p, counter, ep, | |
ca4e0257 | 3630 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
d6bc6245 TS |
3631 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3632 | } | |
252b5132 RH |
3633 | } |
3634 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
3635 | { | |
3636 | expressionS ex; | |
3637 | ||
3638 | /* If this is a reference to an external symbol, we want | |
3639 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3640 | Otherwise we want | |
3641 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3642 | nop | |
3643 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3644 | If there is a constant, it must be added in after. */ | |
3645 | ex.X_add_number = ep->X_add_number; | |
3646 | ep->X_add_number = 0; | |
3647 | frag_grow (20); | |
3648 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3649 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3650 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); |
3651 | macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", ""); | |
3652 | p = frag_var (rs_machine_dependent, 4, 0, | |
3653 | RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros), | |
3654 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3655 | macro_build (p, counter, ep, | |
ca4e0257 | 3656 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3657 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3658 | if (ex.X_add_number != 0) | |
3659 | { | |
3660 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3661 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3662 | ex.X_op = O_constant; | |
3663 | macro_build ((char *) NULL, counter, &ex, | |
ca4e0257 | 3664 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3665 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3666 | } | |
3667 | } | |
3668 | else if (mips_pic == SVR4_PIC) | |
3669 | { | |
3670 | expressionS ex; | |
3671 | int off; | |
3672 | ||
3673 | /* This is the large GOT case. If this is a reference to an | |
3674 | external symbol, we want | |
3675 | lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
3676 | addu $reg,$reg,$gp | |
3677 | lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16) | |
3678 | Otherwise, for a reference to a local symbol, we want | |
3679 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3680 | nop | |
3681 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3682 | If there is a constant, it must be added in after. */ | |
3683 | ex.X_add_number = ep->X_add_number; | |
3684 | ep->X_add_number = 0; | |
3685 | if (reg_needs_delay (GP)) | |
3686 | off = 4; | |
3687 | else | |
3688 | off = 0; | |
3689 | frag_grow (32); | |
3690 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3691 | (int) BFD_RELOC_MIPS_GOT_HI16); | |
3692 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
ca4e0257 | 3693 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
3694 | "d,v,t", reg, reg, GP); |
3695 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3696 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3697 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg); |
3698 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
3699 | RELAX_ENCODE (12, 12 + off, off, 8 + off, 0, | |
3700 | mips_opts.warn_about_macros), | |
3701 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3702 | if (off > 0) | |
3703 | { | |
3704 | /* We need a nop before loading from $gp. This special | |
3705 | check is required because the lui which starts the main | |
3706 | instruction stream does not refer to $gp, and so will not | |
3707 | insert the nop which may be required. */ | |
3708 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3709 | p += 4; | |
3710 | } | |
9a41af64 | 3711 | macro_build (p, counter, ep, HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
3712 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); |
3713 | p += 4; | |
3714 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3715 | p += 4; | |
9a41af64 | 3716 | macro_build (p, counter, ep, HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3717 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3718 | if (ex.X_add_number != 0) | |
3719 | { | |
3720 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3721 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3722 | ex.X_op = O_constant; | |
3723 | macro_build ((char *) NULL, counter, &ex, | |
ca4e0257 | 3724 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3725 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3726 | } | |
3727 | } | |
3728 | else if (mips_pic == EMBEDDED_PIC) | |
3729 | { | |
3730 | /* We always do | |
3731 | addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
3732 | */ | |
3733 | macro_build ((char *) NULL, counter, ep, | |
ca4e0257 | 3734 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3735 | "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL); |
3736 | } | |
3737 | else | |
3738 | abort (); | |
3739 | } | |
3740 | ||
ea1fb5dc RS |
3741 | /* Move the contents of register SOURCE into register DEST. */ |
3742 | ||
3743 | static void | |
3744 | move_register (counter, dest, source) | |
3745 | int *counter; | |
3746 | int dest; | |
3747 | int source; | |
3748 | { | |
3749 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
3750 | HAVE_32BIT_GPRS ? "addu" : "daddu", | |
3751 | "d,v,t", dest, source, 0); | |
3752 | } | |
3753 | ||
252b5132 RH |
3754 | /* |
3755 | * Build macros | |
3756 | * This routine implements the seemingly endless macro or synthesized | |
3757 | * instructions and addressing modes in the mips assembly language. Many | |
3758 | * of these macros are simple and are similar to each other. These could | |
3759 | * probably be handled by some kind of table or grammer aproach instead of | |
3760 | * this verbose method. Others are not simple macros but are more like | |
3761 | * optimizing code generation. | |
3762 | * One interesting optimization is when several store macros appear | |
3763 | * consecutivly that would load AT with the upper half of the same address. | |
3764 | * The ensuing load upper instructions are ommited. This implies some kind | |
3765 | * of global optimization. We currently only optimize within a single macro. | |
3766 | * For many of the load and store macros if the address is specified as a | |
3767 | * constant expression in the first 64k of memory (ie ld $2,0x4000c) we | |
3768 | * first load register 'at' with zero and use it as the base register. The | |
3769 | * mips assembler simply uses register $zero. Just one tiny optimization | |
3770 | * we're missing. | |
3771 | */ | |
3772 | static void | |
3773 | macro (ip) | |
3774 | struct mips_cl_insn *ip; | |
3775 | { | |
3776 | register int treg, sreg, dreg, breg; | |
3777 | int tempreg; | |
3778 | int mask; | |
3779 | int icnt = 0; | |
43841e91 | 3780 | int used_at = 0; |
252b5132 RH |
3781 | expressionS expr1; |
3782 | const char *s; | |
3783 | const char *s2; | |
3784 | const char *fmt; | |
3785 | int likely = 0; | |
3786 | int dbl = 0; | |
3787 | int coproc = 0; | |
3788 | int lr = 0; | |
3789 | int imm = 0; | |
3790 | offsetT maxnum; | |
3791 | int off; | |
3792 | bfd_reloc_code_real_type r; | |
3793 | char *p; | |
3794 | int hold_mips_optimize; | |
3795 | ||
3796 | assert (! mips_opts.mips16); | |
3797 | ||
3798 | treg = (ip->insn_opcode >> 16) & 0x1f; | |
3799 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
3800 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
3801 | mask = ip->insn_mo->mask; | |
3802 | ||
3803 | expr1.X_op = O_constant; | |
3804 | expr1.X_op_symbol = NULL; | |
3805 | expr1.X_add_symbol = NULL; | |
3806 | expr1.X_add_number = 1; | |
3807 | ||
3808 | switch (mask) | |
3809 | { | |
3810 | case M_DABS: | |
3811 | dbl = 1; | |
3812 | case M_ABS: | |
3813 | /* bgez $a0,.+12 | |
3814 | move v0,$a0 | |
3815 | sub v0,$zero,$a0 | |
3816 | */ | |
3817 | ||
3818 | mips_emit_delays (true); | |
3819 | ++mips_opts.noreorder; | |
3820 | mips_any_noreorder = 1; | |
3821 | ||
3822 | expr1.X_add_number = 8; | |
3823 | macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg); | |
3824 | if (dreg == sreg) | |
3825 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
3826 | else | |
ea1fb5dc | 3827 | move_register (&icnt, dreg, sreg); |
252b5132 | 3828 | macro_build ((char *) NULL, &icnt, NULL, |
9a41af64 | 3829 | dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg); |
252b5132 RH |
3830 | |
3831 | --mips_opts.noreorder; | |
3832 | return; | |
3833 | ||
3834 | case M_ADD_I: | |
3835 | s = "addi"; | |
3836 | s2 = "add"; | |
3837 | goto do_addi; | |
3838 | case M_ADDU_I: | |
3839 | s = "addiu"; | |
3840 | s2 = "addu"; | |
3841 | goto do_addi; | |
3842 | case M_DADD_I: | |
3843 | dbl = 1; | |
3844 | s = "daddi"; | |
3845 | s2 = "dadd"; | |
3846 | goto do_addi; | |
3847 | case M_DADDU_I: | |
3848 | dbl = 1; | |
3849 | s = "daddiu"; | |
3850 | s2 = "daddu"; | |
3851 | do_addi: | |
3852 | if (imm_expr.X_op == O_constant | |
3853 | && imm_expr.X_add_number >= -0x8000 | |
3854 | && imm_expr.X_add_number < 0x8000) | |
3855 | { | |
3856 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg, | |
3857 | (int) BFD_RELOC_LO16); | |
3858 | return; | |
3859 | } | |
3860 | load_register (&icnt, AT, &imm_expr, dbl); | |
3861 | macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT); | |
3862 | break; | |
3863 | ||
3864 | case M_AND_I: | |
3865 | s = "andi"; | |
3866 | s2 = "and"; | |
3867 | goto do_bit; | |
3868 | case M_OR_I: | |
3869 | s = "ori"; | |
3870 | s2 = "or"; | |
3871 | goto do_bit; | |
3872 | case M_NOR_I: | |
3873 | s = ""; | |
3874 | s2 = "nor"; | |
3875 | goto do_bit; | |
3876 | case M_XOR_I: | |
3877 | s = "xori"; | |
3878 | s2 = "xor"; | |
3879 | do_bit: | |
3880 | if (imm_expr.X_op == O_constant | |
3881 | && imm_expr.X_add_number >= 0 | |
3882 | && imm_expr.X_add_number < 0x10000) | |
3883 | { | |
3884 | if (mask != M_NOR_I) | |
3885 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg, | |
3886 | sreg, (int) BFD_RELOC_LO16); | |
3887 | else | |
3888 | { | |
3889 | macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i", | |
3890 | treg, sreg, (int) BFD_RELOC_LO16); | |
3891 | macro_build ((char *) NULL, &icnt, NULL, "nor", "d,v,t", | |
3892 | treg, treg, 0); | |
3893 | } | |
3894 | return; | |
3895 | } | |
3896 | ||
d6bc6245 | 3897 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
252b5132 RH |
3898 | macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT); |
3899 | break; | |
3900 | ||
3901 | case M_BEQ_I: | |
3902 | s = "beq"; | |
3903 | goto beq_i; | |
3904 | case M_BEQL_I: | |
3905 | s = "beql"; | |
3906 | likely = 1; | |
3907 | goto beq_i; | |
3908 | case M_BNE_I: | |
3909 | s = "bne"; | |
3910 | goto beq_i; | |
3911 | case M_BNEL_I: | |
3912 | s = "bnel"; | |
3913 | likely = 1; | |
3914 | beq_i: | |
3915 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3916 | { | |
3917 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, | |
3918 | 0); | |
3919 | return; | |
3920 | } | |
3921 | load_register (&icnt, AT, &imm_expr, 0); | |
3922 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT); | |
3923 | break; | |
3924 | ||
3925 | case M_BGEL: | |
3926 | likely = 1; | |
3927 | case M_BGE: | |
3928 | if (treg == 0) | |
3929 | { | |
3930 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3931 | likely ? "bgezl" : "bgez", | |
3932 | "s,p", sreg); | |
3933 | return; | |
3934 | } | |
3935 | if (sreg == 0) | |
3936 | { | |
3937 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3938 | likely ? "blezl" : "blez", | |
3939 | "s,p", treg); | |
3940 | return; | |
3941 | } | |
3942 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg); | |
3943 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3944 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
3945 | break; |
3946 | ||
3947 | case M_BGTL_I: | |
3948 | likely = 1; | |
3949 | case M_BGT_I: | |
3950 | /* check for > max integer */ | |
3951 | maxnum = 0x7fffffff; | |
ca4e0257 | 3952 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
3953 | { |
3954 | maxnum <<= 16; | |
3955 | maxnum |= 0xffff; | |
3956 | maxnum <<= 16; | |
3957 | maxnum |= 0xffff; | |
3958 | } | |
3959 | if (imm_expr.X_op == O_constant | |
3960 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 3961 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
3962 | { |
3963 | do_false: | |
3964 | /* result is always false */ | |
3965 | if (! likely) | |
3966 | { | |
39c0a331 L |
3967 | if (warn_nops) |
3968 | as_warn (_("Branch %s is always false (nop)"), | |
3969 | ip->insn_mo->name); | |
252b5132 RH |
3970 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); |
3971 | } | |
3972 | else | |
3973 | { | |
39c0a331 L |
3974 | if (warn_nops) |
3975 | as_warn (_("Branch likely %s is always false"), | |
3976 | ip->insn_mo->name); | |
252b5132 RH |
3977 | macro_build ((char *) NULL, &icnt, &offset_expr, "bnel", |
3978 | "s,t,p", 0, 0); | |
3979 | } | |
3980 | return; | |
3981 | } | |
3982 | if (imm_expr.X_op != O_constant) | |
3983 | as_bad (_("Unsupported large constant")); | |
3984 | imm_expr.X_add_number++; | |
3985 | /* FALLTHROUGH */ | |
3986 | case M_BGE_I: | |
3987 | case M_BGEL_I: | |
3988 | if (mask == M_BGEL_I) | |
3989 | likely = 1; | |
3990 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3991 | { | |
3992 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3993 | likely ? "bgezl" : "bgez", "s,p", sreg); |
252b5132 RH |
3994 | return; |
3995 | } | |
3996 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3997 | { | |
3998 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 3999 | likely ? "bgtzl" : "bgtz", "s,p", sreg); |
252b5132 RH |
4000 | return; |
4001 | } | |
4002 | maxnum = 0x7fffffff; | |
ca4e0257 | 4003 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
4004 | { |
4005 | maxnum <<= 16; | |
4006 | maxnum |= 0xffff; | |
4007 | maxnum <<= 16; | |
4008 | maxnum |= 0xffff; | |
4009 | } | |
4010 | maxnum = - maxnum - 1; | |
4011 | if (imm_expr.X_op == O_constant | |
4012 | && imm_expr.X_add_number <= maxnum | |
ca4e0257 | 4013 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
4014 | { |
4015 | do_true: | |
4016 | /* result is always true */ | |
4017 | as_warn (_("Branch %s is always true"), ip->insn_mo->name); | |
4018 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
4019 | return; | |
4020 | } | |
4021 | set_at (&icnt, sreg, 0); | |
4022 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4023 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4024 | break; |
4025 | ||
4026 | case M_BGEUL: | |
4027 | likely = 1; | |
4028 | case M_BGEU: | |
4029 | if (treg == 0) | |
4030 | goto do_true; | |
4031 | if (sreg == 0) | |
4032 | { | |
4033 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4034 | likely ? "beql" : "beq", "s,t,p", 0, treg); |
252b5132 RH |
4035 | return; |
4036 | } | |
4037 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, | |
4038 | treg); | |
4039 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4040 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4041 | break; |
4042 | ||
4043 | case M_BGTUL_I: | |
4044 | likely = 1; | |
4045 | case M_BGTU_I: | |
4046 | if (sreg == 0 | |
ca4e0257 | 4047 | || (HAVE_32BIT_GPRS |
252b5132 RH |
4048 | && imm_expr.X_op == O_constant |
4049 | && imm_expr.X_add_number == 0xffffffff)) | |
4050 | goto do_false; | |
4051 | if (imm_expr.X_op != O_constant) | |
4052 | as_bad (_("Unsupported large constant")); | |
4053 | imm_expr.X_add_number++; | |
4054 | /* FALLTHROUGH */ | |
4055 | case M_BGEU_I: | |
4056 | case M_BGEUL_I: | |
4057 | if (mask == M_BGEUL_I) | |
4058 | likely = 1; | |
4059 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4060 | goto do_true; | |
4061 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4062 | { | |
4063 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4064 | likely ? "bnel" : "bne", "s,t,p", sreg, 0); |
252b5132 RH |
4065 | return; |
4066 | } | |
4067 | set_at (&icnt, sreg, 1); | |
4068 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4069 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4070 | break; |
4071 | ||
4072 | case M_BGTL: | |
4073 | likely = 1; | |
4074 | case M_BGT: | |
4075 | if (treg == 0) | |
4076 | { | |
4077 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4078 | likely ? "bgtzl" : "bgtz", "s,p", sreg); |
252b5132 RH |
4079 | return; |
4080 | } | |
4081 | if (sreg == 0) | |
4082 | { | |
4083 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4084 | likely ? "bltzl" : "bltz", "s,p", treg); |
252b5132 RH |
4085 | return; |
4086 | } | |
4087 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg); | |
4088 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4089 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4090 | break; |
4091 | ||
4092 | case M_BGTUL: | |
4093 | likely = 1; | |
4094 | case M_BGTU: | |
4095 | if (treg == 0) | |
4096 | { | |
4097 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4098 | likely ? "bnel" : "bne", "s,t,p", sreg, 0); |
252b5132 RH |
4099 | return; |
4100 | } | |
4101 | if (sreg == 0) | |
4102 | goto do_false; | |
4103 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, | |
4104 | sreg); | |
4105 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4106 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4107 | break; |
4108 | ||
4109 | case M_BLEL: | |
4110 | likely = 1; | |
4111 | case M_BLE: | |
4112 | if (treg == 0) | |
4113 | { | |
4114 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4115 | likely ? "blezl" : "blez", "s,p", sreg); |
252b5132 RH |
4116 | return; |
4117 | } | |
4118 | if (sreg == 0) | |
4119 | { | |
4120 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4121 | likely ? "bgezl" : "bgez", "s,p", treg); |
252b5132 RH |
4122 | return; |
4123 | } | |
4124 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg); | |
4125 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4126 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4127 | break; |
4128 | ||
4129 | case M_BLEL_I: | |
4130 | likely = 1; | |
4131 | case M_BLE_I: | |
4132 | maxnum = 0x7fffffff; | |
ca4e0257 | 4133 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
4134 | { |
4135 | maxnum <<= 16; | |
4136 | maxnum |= 0xffff; | |
4137 | maxnum <<= 16; | |
4138 | maxnum |= 0xffff; | |
4139 | } | |
4140 | if (imm_expr.X_op == O_constant | |
4141 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 4142 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
4143 | goto do_true; |
4144 | if (imm_expr.X_op != O_constant) | |
4145 | as_bad (_("Unsupported large constant")); | |
4146 | imm_expr.X_add_number++; | |
4147 | /* FALLTHROUGH */ | |
4148 | case M_BLT_I: | |
4149 | case M_BLTL_I: | |
4150 | if (mask == M_BLTL_I) | |
4151 | likely = 1; | |
4152 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4153 | { | |
4154 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4155 | likely ? "bltzl" : "bltz", "s,p", sreg); |
252b5132 RH |
4156 | return; |
4157 | } | |
4158 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4159 | { | |
4160 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4161 | likely ? "blezl" : "blez", "s,p", sreg); |
252b5132 RH |
4162 | return; |
4163 | } | |
4164 | set_at (&icnt, sreg, 0); | |
4165 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4166 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4167 | break; |
4168 | ||
4169 | case M_BLEUL: | |
4170 | likely = 1; | |
4171 | case M_BLEU: | |
4172 | if (treg == 0) | |
4173 | { | |
4174 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4175 | likely ? "beql" : "beq", "s,t,p", sreg, 0); |
252b5132 RH |
4176 | return; |
4177 | } | |
4178 | if (sreg == 0) | |
4179 | goto do_true; | |
4180 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, | |
4181 | sreg); | |
4182 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4183 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4184 | break; |
4185 | ||
4186 | case M_BLEUL_I: | |
4187 | likely = 1; | |
4188 | case M_BLEU_I: | |
4189 | if (sreg == 0 | |
ca4e0257 | 4190 | || (HAVE_32BIT_GPRS |
252b5132 RH |
4191 | && imm_expr.X_op == O_constant |
4192 | && imm_expr.X_add_number == 0xffffffff)) | |
4193 | goto do_true; | |
4194 | if (imm_expr.X_op != O_constant) | |
4195 | as_bad (_("Unsupported large constant")); | |
4196 | imm_expr.X_add_number++; | |
4197 | /* FALLTHROUGH */ | |
4198 | case M_BLTU_I: | |
4199 | case M_BLTUL_I: | |
4200 | if (mask == M_BLTUL_I) | |
4201 | likely = 1; | |
4202 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4203 | goto do_false; | |
4204 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4205 | { | |
4206 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4207 | likely ? "beql" : "beq", | |
4208 | "s,t,p", sreg, 0); | |
4209 | return; | |
4210 | } | |
4211 | set_at (&icnt, sreg, 1); | |
4212 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4213 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4214 | break; |
4215 | ||
4216 | case M_BLTL: | |
4217 | likely = 1; | |
4218 | case M_BLT: | |
4219 | if (treg == 0) | |
4220 | { | |
4221 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4222 | likely ? "bltzl" : "bltz", "s,p", sreg); |
252b5132 RH |
4223 | return; |
4224 | } | |
4225 | if (sreg == 0) | |
4226 | { | |
4227 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4228 | likely ? "bgtzl" : "bgtz", "s,p", treg); |
252b5132 RH |
4229 | return; |
4230 | } | |
4231 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg); | |
4232 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4233 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4234 | break; |
4235 | ||
4236 | case M_BLTUL: | |
4237 | likely = 1; | |
4238 | case M_BLTU: | |
4239 | if (treg == 0) | |
4240 | goto do_false; | |
4241 | if (sreg == 0) | |
4242 | { | |
4243 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4244 | likely ? "bnel" : "bne", "s,t,p", 0, treg); |
252b5132 RH |
4245 | return; |
4246 | } | |
4247 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, | |
4248 | treg); | |
4249 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4250 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4251 | break; |
4252 | ||
4253 | case M_DDIV_3: | |
4254 | dbl = 1; | |
4255 | case M_DIV_3: | |
4256 | s = "mflo"; | |
4257 | goto do_div3; | |
4258 | case M_DREM_3: | |
4259 | dbl = 1; | |
4260 | case M_REM_3: | |
4261 | s = "mfhi"; | |
4262 | do_div3: | |
4263 | if (treg == 0) | |
4264 | { | |
4265 | as_warn (_("Divide by zero.")); | |
4266 | if (mips_trap) | |
4267 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0); | |
4268 | else | |
9117d219 | 4269 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); |
252b5132 RH |
4270 | return; |
4271 | } | |
4272 | ||
4273 | mips_emit_delays (true); | |
4274 | ++mips_opts.noreorder; | |
4275 | mips_any_noreorder = 1; | |
4276 | if (mips_trap) | |
4277 | { | |
4278 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0); | |
4279 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 4280 | dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
252b5132 RH |
4281 | } |
4282 | else | |
4283 | { | |
4284 | expr1.X_add_number = 8; | |
4285 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
4286 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 4287 | dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
9117d219 | 4288 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); |
252b5132 RH |
4289 | } |
4290 | expr1.X_add_number = -1; | |
4291 | macro_build ((char *) NULL, &icnt, &expr1, | |
4292 | dbl ? "daddiu" : "addiu", | |
4293 | "t,r,j", AT, 0, (int) BFD_RELOC_LO16); | |
4294 | expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16); | |
4295 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT); | |
4296 | if (dbl) | |
4297 | { | |
4298 | expr1.X_add_number = 1; | |
4299 | macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0, | |
4300 | (int) BFD_RELOC_LO16); | |
4301 | macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT, | |
4302 | 31); | |
4303 | } | |
4304 | else | |
4305 | { | |
4306 | expr1.X_add_number = 0x80000000; | |
4307 | macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT, | |
4308 | (int) BFD_RELOC_HI16); | |
4309 | } | |
4310 | if (mips_trap) | |
4311 | { | |
4312 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", sreg, AT); | |
4313 | /* We want to close the noreorder block as soon as possible, so | |
4314 | that later insns are available for delay slot filling. */ | |
4315 | --mips_opts.noreorder; | |
4316 | } | |
4317 | else | |
4318 | { | |
4319 | expr1.X_add_number = 8; | |
4320 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT); | |
4321 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
4322 | ||
4323 | /* We want to close the noreorder block as soon as possible, so | |
4324 | that later insns are available for delay slot filling. */ | |
4325 | --mips_opts.noreorder; | |
4326 | ||
9117d219 | 4327 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); |
252b5132 RH |
4328 | } |
4329 | macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg); | |
4330 | break; | |
4331 | ||
4332 | case M_DIV_3I: | |
4333 | s = "div"; | |
4334 | s2 = "mflo"; | |
4335 | goto do_divi; | |
4336 | case M_DIVU_3I: | |
4337 | s = "divu"; | |
4338 | s2 = "mflo"; | |
4339 | goto do_divi; | |
4340 | case M_REM_3I: | |
4341 | s = "div"; | |
4342 | s2 = "mfhi"; | |
4343 | goto do_divi; | |
4344 | case M_REMU_3I: | |
4345 | s = "divu"; | |
4346 | s2 = "mfhi"; | |
4347 | goto do_divi; | |
4348 | case M_DDIV_3I: | |
4349 | dbl = 1; | |
4350 | s = "ddiv"; | |
4351 | s2 = "mflo"; | |
4352 | goto do_divi; | |
4353 | case M_DDIVU_3I: | |
4354 | dbl = 1; | |
4355 | s = "ddivu"; | |
4356 | s2 = "mflo"; | |
4357 | goto do_divi; | |
4358 | case M_DREM_3I: | |
4359 | dbl = 1; | |
4360 | s = "ddiv"; | |
4361 | s2 = "mfhi"; | |
4362 | goto do_divi; | |
4363 | case M_DREMU_3I: | |
4364 | dbl = 1; | |
4365 | s = "ddivu"; | |
4366 | s2 = "mfhi"; | |
4367 | do_divi: | |
4368 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4369 | { | |
4370 | as_warn (_("Divide by zero.")); | |
4371 | if (mips_trap) | |
4372 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0); | |
4373 | else | |
beae10d5 | 4374 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); |
252b5132 RH |
4375 | return; |
4376 | } | |
4377 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4378 | { | |
4379 | if (strcmp (s2, "mflo") == 0) | |
ea1fb5dc | 4380 | move_register (&icnt, dreg, sreg); |
252b5132 | 4381 | else |
ea1fb5dc | 4382 | move_register (&icnt, dreg, 0); |
252b5132 RH |
4383 | return; |
4384 | } | |
4385 | if (imm_expr.X_op == O_constant | |
4386 | && imm_expr.X_add_number == -1 | |
4387 | && s[strlen (s) - 1] != 'u') | |
4388 | { | |
4389 | if (strcmp (s2, "mflo") == 0) | |
4390 | { | |
9a41af64 TS |
4391 | macro_build ((char *) NULL, &icnt, NULL, dbl ? "dneg" : "neg", |
4392 | "d,w", dreg, sreg); | |
252b5132 RH |
4393 | } |
4394 | else | |
ea1fb5dc | 4395 | move_register (&icnt, dreg, 0); |
252b5132 RH |
4396 | return; |
4397 | } | |
4398 | ||
4399 | load_register (&icnt, AT, &imm_expr, dbl); | |
4400 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT); | |
4401 | macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg); | |
4402 | break; | |
4403 | ||
4404 | case M_DIVU_3: | |
4405 | s = "divu"; | |
4406 | s2 = "mflo"; | |
4407 | goto do_divu3; | |
4408 | case M_REMU_3: | |
4409 | s = "divu"; | |
4410 | s2 = "mfhi"; | |
4411 | goto do_divu3; | |
4412 | case M_DDIVU_3: | |
4413 | s = "ddivu"; | |
4414 | s2 = "mflo"; | |
4415 | goto do_divu3; | |
4416 | case M_DREMU_3: | |
4417 | s = "ddivu"; | |
4418 | s2 = "mfhi"; | |
4419 | do_divu3: | |
4420 | mips_emit_delays (true); | |
4421 | ++mips_opts.noreorder; | |
4422 | mips_any_noreorder = 1; | |
4423 | if (mips_trap) | |
4424 | { | |
4425 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0); | |
4426 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg); | |
4427 | /* We want to close the noreorder block as soon as possible, so | |
4428 | that later insns are available for delay slot filling. */ | |
4429 | --mips_opts.noreorder; | |
4430 | } | |
4431 | else | |
4432 | { | |
4433 | expr1.X_add_number = 8; | |
4434 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
4435 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg); | |
4436 | ||
4437 | /* We want to close the noreorder block as soon as possible, so | |
4438 | that later insns are available for delay slot filling. */ | |
4439 | --mips_opts.noreorder; | |
beae10d5 | 4440 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); |
252b5132 RH |
4441 | } |
4442 | macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg); | |
4443 | return; | |
4444 | ||
4445 | case M_DLA_AB: | |
4446 | dbl = 1; | |
4447 | case M_LA_AB: | |
4448 | /* Load the address of a symbol into a register. If breg is not | |
4449 | zero, we then add a base register to it. */ | |
4450 | ||
afdbd6d0 CD |
4451 | if (treg == breg) |
4452 | { | |
4453 | tempreg = AT; | |
4454 | used_at = 1; | |
4455 | } | |
4456 | else | |
4457 | { | |
4458 | tempreg = treg; | |
4459 | used_at = 0; | |
4460 | } | |
4461 | ||
252b5132 RH |
4462 | /* When generating embedded PIC code, we permit expressions of |
4463 | the form | |
afdbd6d0 CD |
4464 | la $treg,foo-bar |
4465 | la $treg,foo-bar($breg) | |
bb2d6cd7 | 4466 | where bar is an address in the current section. These are used |
252b5132 RH |
4467 | when getting the addresses of functions. We don't permit |
4468 | X_add_number to be non-zero, because if the symbol is | |
4469 | external the relaxing code needs to know that any addend is | |
4470 | purely the offset to X_op_symbol. */ | |
4471 | if (mips_pic == EMBEDDED_PIC | |
4472 | && offset_expr.X_op == O_subtract | |
49309057 | 4473 | && (symbol_constant_p (offset_expr.X_op_symbol) |
bb2d6cd7 | 4474 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg |
49309057 ILT |
4475 | : (symbol_equated_p (offset_expr.X_op_symbol) |
4476 | && (S_GET_SEGMENT | |
4477 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
4478 | ->X_add_symbol) | |
bb2d6cd7 | 4479 | == now_seg))) |
bb2d6cd7 GK |
4480 | && (offset_expr.X_add_number == 0 |
4481 | || OUTPUT_FLAVOR == bfd_target_elf_flavour)) | |
252b5132 | 4482 | { |
afdbd6d0 CD |
4483 | if (breg == 0) |
4484 | { | |
4485 | tempreg = treg; | |
4486 | used_at = 0; | |
4487 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4488 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
4489 | } | |
4490 | else | |
4491 | { | |
4492 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4493 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
4494 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4495 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", | |
4496 | "d,v,t", tempreg, tempreg, breg); | |
4497 | } | |
252b5132 | 4498 | macro_build ((char *) NULL, &icnt, &offset_expr, |
ca4e0257 | 4499 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
afdbd6d0 CD |
4500 | "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16); |
4501 | if (! used_at) | |
4502 | return; | |
4503 | break; | |
252b5132 RH |
4504 | } |
4505 | ||
4506 | if (offset_expr.X_op != O_symbol | |
4507 | && offset_expr.X_op != O_constant) | |
4508 | { | |
4509 | as_bad (_("expression too complex")); | |
4510 | offset_expr.X_op = O_constant; | |
4511 | } | |
4512 | ||
252b5132 RH |
4513 | if (offset_expr.X_op == O_constant) |
4514 | load_register (&icnt, tempreg, &offset_expr, dbl); | |
4515 | else if (mips_pic == NO_PIC) | |
4516 | { | |
d6bc6245 | 4517 | /* If this is a reference to a GP relative symbol, we want |
252b5132 RH |
4518 | addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) |
4519 | Otherwise we want | |
4520 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4521 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4522 | If we have a constant, we need two instructions anyhow, | |
d6bc6245 | 4523 | so we may as well always use the latter form. |
76b3015f | 4524 | |
d6bc6245 TS |
4525 | With 64bit address space and a usable $at we want |
4526 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
4527 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
4528 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
4529 | daddiu $at,<sym> (BFD_RELOC_LO16) | |
4530 | dsll32 $tempreg,0 | |
4531 | dadd $tempreg,$tempreg,$at | |
76b3015f | 4532 | |
d6bc6245 TS |
4533 | If $at is already in use, we use an path which is suboptimal |
4534 | on superscalar processors. | |
4535 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
4536 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
4537 | dsll $tempreg,16 | |
4538 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4539 | dsll $tempreg,16 | |
4540 | daddiu $tempreg,<sym> (BFD_RELOC_LO16) | |
4541 | */ | |
4542 | p = NULL; | |
4543 | if (HAVE_64BIT_ADDRESSES) | |
252b5132 | 4544 | { |
d6bc6245 TS |
4545 | /* We don't do GP optimization for now because RELAX_ENCODE can't |
4546 | hold the data for such large chunks. */ | |
4547 | ||
4548 | if (used_at == 0) | |
4549 | { | |
4550 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4551 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
4552 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4553 | AT, (int) BFD_RELOC_HI16_S); | |
4554 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4555 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
4556 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4557 | AT, AT, (int) BFD_RELOC_LO16); | |
4558 | macro_build (p, &icnt, NULL, "dsll32", "d,w,<", | |
4559 | tempreg, tempreg, 0); | |
4560 | macro_build (p, &icnt, NULL, "dadd", "d,v,t", | |
4561 | tempreg, tempreg, AT); | |
4562 | used_at = 1; | |
4563 | } | |
4564 | else | |
4565 | { | |
4566 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4567 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
4568 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4569 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
4570 | macro_build (p, &icnt, NULL, "dsll", "d,w,<", | |
4571 | tempreg, tempreg, 16); | |
4572 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4573 | tempreg, tempreg, (int) BFD_RELOC_HI16_S); | |
4574 | macro_build (p, &icnt, NULL, "dsll", "d,w,<", | |
4575 | tempreg, tempreg, 16); | |
4576 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4577 | tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4578 | } | |
4579 | } | |
4580 | else | |
4581 | { | |
4582 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET | |
4583 | && ! nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
4584 | { | |
4585 | frag_grow (20); | |
4586 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4587 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
4588 | "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
4589 | p = frag_var (rs_machine_dependent, 8, 0, | |
4590 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
4591 | mips_opts.warn_about_macros), | |
4592 | offset_expr.X_add_symbol, (offsetT) 0, | |
4593 | (char *) NULL); | |
4594 | } | |
4595 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
4596 | if (p != NULL) | |
4597 | p += 4; | |
4598 | macro_build (p, &icnt, &offset_expr, | |
4599 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
4600 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4601 | } | |
252b5132 RH |
4602 | } |
4603 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
4604 | { | |
9117d219 NC |
4605 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
4606 | ||
252b5132 RH |
4607 | /* If this is a reference to an external symbol, and there |
4608 | is no constant, we want | |
4609 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
9117d219 NC |
4610 | or if tempreg is PIC_CALL_REG |
4611 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
252b5132 RH |
4612 | For a local symbol, we want |
4613 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4614 | nop | |
4615 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4616 | ||
4617 | If we have a small constant, and this is a reference to | |
4618 | an external symbol, we want | |
4619 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4620 | nop | |
4621 | addiu $tempreg,$tempreg,<constant> | |
4622 | For a local symbol, we want the same instruction | |
4623 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4624 | addiu instruction. | |
4625 | ||
4626 | If we have a large constant, and this is a reference to | |
4627 | an external symbol, we want | |
4628 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4629 | lui $at,<hiconstant> | |
4630 | addiu $at,$at,<loconstant> | |
4631 | addu $tempreg,$tempreg,$at | |
4632 | For a local symbol, we want the same instruction | |
4633 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4634 | addiu instruction. */ | |
4635 | expr1.X_add_number = offset_expr.X_add_number; | |
4636 | offset_expr.X_add_number = 0; | |
4637 | frag_grow (32); | |
9117d219 NC |
4638 | if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG) |
4639 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16; | |
252b5132 RH |
4640 | macro_build ((char *) NULL, &icnt, &offset_expr, |
4641 | dbl ? "ld" : "lw", | |
9117d219 | 4642 | "t,o(b)", tempreg, lw_reloc_type, GP); |
252b5132 RH |
4643 | if (expr1.X_add_number == 0) |
4644 | { | |
4645 | int off; | |
4646 | ||
4647 | if (breg == 0) | |
4648 | off = 0; | |
4649 | else | |
4650 | { | |
4651 | /* We're going to put in an addu instruction using | |
4652 | tempreg, so we may as well insert the nop right | |
4653 | now. */ | |
4654 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4655 | "nop", ""); | |
4656 | off = 4; | |
4657 | } | |
4658 | p = frag_var (rs_machine_dependent, 8 - off, 0, | |
4659 | RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0, | |
4660 | (breg == 0 | |
4661 | ? mips_opts.warn_about_macros | |
4662 | : 0)), | |
4663 | offset_expr.X_add_symbol, (offsetT) 0, | |
4664 | (char *) NULL); | |
4665 | if (breg == 0) | |
4666 | { | |
4667 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4668 | p += 4; | |
4669 | } | |
4670 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4671 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4672 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4673 | /* FIXME: If breg == 0, and the next instruction uses | |
4674 | $tempreg, then if this variant case is used an extra | |
4675 | nop will be generated. */ | |
4676 | } | |
4677 | else if (expr1.X_add_number >= -0x8000 | |
4678 | && expr1.X_add_number < 0x8000) | |
4679 | { | |
4680 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4681 | "nop", ""); | |
4682 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4683 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4684 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4685 | (void) frag_var (rs_machine_dependent, 0, 0, | |
4686 | RELAX_ENCODE (0, 0, -12, -4, 0, 0), | |
4687 | offset_expr.X_add_symbol, (offsetT) 0, | |
4688 | (char *) NULL); | |
4689 | } | |
4690 | else | |
4691 | { | |
4692 | int off1; | |
4693 | ||
4694 | /* If we are going to add in a base register, and the | |
4695 | target register and the base register are the same, | |
4696 | then we are using AT as a temporary register. Since | |
4697 | we want to load the constant into AT, we add our | |
4698 | current AT (from the global offset table) and the | |
4699 | register into the register now, and pretend we were | |
4700 | not using a base register. */ | |
4701 | if (breg != treg) | |
4702 | off1 = 0; | |
4703 | else | |
4704 | { | |
4705 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4706 | "nop", ""); | |
4707 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4708 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4709 | "d,v,t", treg, AT, breg); |
4710 | breg = 0; | |
4711 | tempreg = treg; | |
4712 | off1 = -8; | |
4713 | } | |
4714 | ||
4715 | /* Set mips_optimize around the lui instruction to avoid | |
4716 | inserting an unnecessary nop after the lw. */ | |
4717 | hold_mips_optimize = mips_optimize; | |
4718 | mips_optimize = 2; | |
4719 | macro_build_lui ((char *) NULL, &icnt, &expr1, AT); | |
4720 | mips_optimize = hold_mips_optimize; | |
4721 | ||
4722 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4723 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4724 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4725 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4726 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4727 | "d,v,t", tempreg, tempreg, AT); |
4728 | (void) frag_var (rs_machine_dependent, 0, 0, | |
4729 | RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0), | |
4730 | offset_expr.X_add_symbol, (offsetT) 0, | |
4731 | (char *) NULL); | |
4732 | used_at = 1; | |
4733 | } | |
4734 | } | |
4735 | else if (mips_pic == SVR4_PIC) | |
4736 | { | |
4737 | int gpdel; | |
9117d219 NC |
4738 | int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16; |
4739 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16; | |
252b5132 RH |
4740 | |
4741 | /* This is the large GOT case. If this is a reference to an | |
4742 | external symbol, and there is no constant, we want | |
4743 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4744 | addu $tempreg,$tempreg,$gp | |
4745 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
9117d219 NC |
4746 | or if tempreg is PIC_CALL_REG |
4747 | lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
4748 | addu $tempreg,$tempreg,$gp | |
4749 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16) | |
252b5132 RH |
4750 | For a local symbol, we want |
4751 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4752 | nop | |
4753 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4754 | ||
4755 | If we have a small constant, and this is a reference to | |
4756 | an external symbol, we want | |
4757 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4758 | addu $tempreg,$tempreg,$gp | |
4759 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4760 | nop | |
4761 | addiu $tempreg,$tempreg,<constant> | |
4762 | For a local symbol, we want | |
4763 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4764 | nop | |
4765 | addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16) | |
4766 | ||
4767 | If we have a large constant, and this is a reference to | |
4768 | an external symbol, we want | |
4769 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4770 | addu $tempreg,$tempreg,$gp | |
4771 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4772 | lui $at,<hiconstant> | |
4773 | addiu $at,$at,<loconstant> | |
4774 | addu $tempreg,$tempreg,$at | |
4775 | For a local symbol, we want | |
4776 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4777 | lui $at,<hiconstant> | |
4778 | addiu $at,$at,<loconstant> (BFD_RELOC_LO16) | |
4779 | addu $tempreg,$tempreg,$at | |
4780 | */ | |
4781 | expr1.X_add_number = offset_expr.X_add_number; | |
4782 | offset_expr.X_add_number = 0; | |
4783 | frag_grow (52); | |
4784 | if (reg_needs_delay (GP)) | |
4785 | gpdel = 4; | |
4786 | else | |
4787 | gpdel = 0; | |
9117d219 NC |
4788 | if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG) |
4789 | { | |
4790 | lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16; | |
4791 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16; | |
4792 | } | |
252b5132 | 4793 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", |
9117d219 | 4794 | tempreg, lui_reloc_type); |
252b5132 | 4795 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
ca4e0257 | 4796 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4797 | "d,v,t", tempreg, tempreg, GP); |
4798 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4799 | dbl ? "ld" : "lw", | |
9117d219 | 4800 | "t,o(b)", tempreg, lw_reloc_type, tempreg); |
252b5132 RH |
4801 | if (expr1.X_add_number == 0) |
4802 | { | |
4803 | int off; | |
4804 | ||
4805 | if (breg == 0) | |
4806 | off = 0; | |
4807 | else | |
4808 | { | |
4809 | /* We're going to put in an addu instruction using | |
4810 | tempreg, so we may as well insert the nop right | |
4811 | now. */ | |
4812 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4813 | "nop", ""); | |
4814 | off = 4; | |
4815 | } | |
4816 | ||
4817 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4818 | RELAX_ENCODE (12 + off, 12 + gpdel, gpdel, | |
4819 | 8 + gpdel, 0, | |
4820 | (breg == 0 | |
4821 | ? mips_opts.warn_about_macros | |
4822 | : 0)), | |
4823 | offset_expr.X_add_symbol, (offsetT) 0, | |
4824 | (char *) NULL); | |
4825 | } | |
4826 | else if (expr1.X_add_number >= -0x8000 | |
4827 | && expr1.X_add_number < 0x8000) | |
4828 | { | |
4829 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4830 | "nop", ""); | |
4831 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4832 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4833 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4834 | ||
4835 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4836 | RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0, | |
4837 | (breg == 0 | |
4838 | ? mips_opts.warn_about_macros | |
4839 | : 0)), | |
4840 | offset_expr.X_add_symbol, (offsetT) 0, | |
4841 | (char *) NULL); | |
4842 | } | |
4843 | else | |
4844 | { | |
4845 | int adj, dreg; | |
4846 | ||
4847 | /* If we are going to add in a base register, and the | |
4848 | target register and the base register are the same, | |
4849 | then we are using AT as a temporary register. Since | |
4850 | we want to load the constant into AT, we add our | |
4851 | current AT (from the global offset table) and the | |
4852 | register into the register now, and pretend we were | |
4853 | not using a base register. */ | |
4854 | if (breg != treg) | |
4855 | { | |
4856 | adj = 0; | |
4857 | dreg = tempreg; | |
4858 | } | |
4859 | else | |
4860 | { | |
4861 | assert (tempreg == AT); | |
4862 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4863 | "nop", ""); | |
4864 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4865 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4866 | "d,v,t", treg, AT, breg); |
4867 | dreg = treg; | |
4868 | adj = 8; | |
4869 | } | |
4870 | ||
4871 | /* Set mips_optimize around the lui instruction to avoid | |
4872 | inserting an unnecessary nop after the lw. */ | |
4873 | hold_mips_optimize = mips_optimize; | |
4874 | mips_optimize = 2; | |
4875 | macro_build_lui ((char *) NULL, &icnt, &expr1, AT); | |
4876 | mips_optimize = hold_mips_optimize; | |
4877 | ||
4878 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4879 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4880 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4881 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4882 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4883 | "d,v,t", dreg, dreg, AT); |
4884 | ||
4885 | p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0, | |
4886 | RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel, | |
4887 | 8 + gpdel, 0, | |
4888 | (breg == 0 | |
4889 | ? mips_opts.warn_about_macros | |
4890 | : 0)), | |
4891 | offset_expr.X_add_symbol, (offsetT) 0, | |
4892 | (char *) NULL); | |
4893 | ||
4894 | used_at = 1; | |
4895 | } | |
4896 | ||
4897 | if (gpdel > 0) | |
4898 | { | |
4899 | /* This is needed because this instruction uses $gp, but | |
4900 | the first instruction on the main stream does not. */ | |
4901 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4902 | p += 4; | |
4903 | } | |
4904 | macro_build (p, &icnt, &offset_expr, | |
4905 | dbl ? "ld" : "lw", | |
4906 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
4907 | p += 4; | |
4908 | if (expr1.X_add_number >= -0x8000 | |
4909 | && expr1.X_add_number < 0x8000) | |
4910 | { | |
4911 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4912 | p += 4; | |
4913 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4914 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4915 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4916 | /* FIXME: If add_number is 0, and there was no base | |
4917 | register, the external symbol case ended with a load, | |
4918 | so if the symbol turns out to not be external, and | |
4919 | the next instruction uses tempreg, an unnecessary nop | |
4920 | will be inserted. */ | |
4921 | } | |
4922 | else | |
4923 | { | |
4924 | if (breg == treg) | |
4925 | { | |
4926 | /* We must add in the base register now, as in the | |
4927 | external symbol case. */ | |
4928 | assert (tempreg == AT); | |
4929 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4930 | p += 4; | |
4931 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4932 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4933 | "d,v,t", treg, AT, breg); |
4934 | p += 4; | |
4935 | tempreg = treg; | |
4936 | /* We set breg to 0 because we have arranged to add | |
4937 | it in in both cases. */ | |
4938 | breg = 0; | |
4939 | } | |
4940 | ||
4941 | macro_build_lui (p, &icnt, &expr1, AT); | |
4942 | p += 4; | |
4943 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4944 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4945 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4946 | p += 4; | |
4947 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4948 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4949 | "d,v,t", tempreg, tempreg, AT); |
4950 | p += 4; | |
4951 | } | |
4952 | } | |
4953 | else if (mips_pic == EMBEDDED_PIC) | |
4954 | { | |
4955 | /* We use | |
4956 | addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
4957 | */ | |
4958 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 4959 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4960 | "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL); |
4961 | } | |
4962 | else | |
4963 | abort (); | |
4964 | ||
4965 | if (breg != 0) | |
4966 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4967 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4968 | "d,v,t", treg, tempreg, breg); |
4969 | ||
4970 | if (! used_at) | |
4971 | return; | |
4972 | ||
4973 | break; | |
4974 | ||
4975 | case M_J_A: | |
4976 | /* The j instruction may not be used in PIC code, since it | |
4977 | requires an absolute address. We convert it to a b | |
4978 | instruction. */ | |
4979 | if (mips_pic == NO_PIC) | |
4980 | macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a"); | |
4981 | else | |
4982 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
4983 | return; | |
4984 | ||
4985 | /* The jal instructions must be handled as macros because when | |
4986 | generating PIC code they expand to multi-instruction | |
4987 | sequences. Normally they are simple instructions. */ | |
4988 | case M_JAL_1: | |
4989 | dreg = RA; | |
4990 | /* Fall through. */ | |
4991 | case M_JAL_2: | |
4992 | if (mips_pic == NO_PIC | |
4993 | || mips_pic == EMBEDDED_PIC) | |
4994 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", | |
4995 | "d,s", dreg, sreg); | |
4996 | else if (mips_pic == SVR4_PIC) | |
4997 | { | |
4998 | if (sreg != PIC_CALL_REG) | |
4999 | as_warn (_("MIPS PIC call to register other than $25")); | |
bdaaa2e1 | 5000 | |
252b5132 RH |
5001 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", |
5002 | "d,s", dreg, sreg); | |
6478892d | 5003 | if (! HAVE_NEWABI) |
252b5132 | 5004 | { |
6478892d TS |
5005 | if (mips_cprestore_offset < 0) |
5006 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
5007 | else | |
5008 | { | |
5009 | expr1.X_add_number = mips_cprestore_offset; | |
5010 | macro_build ((char *) NULL, &icnt, &expr1, | |
5011 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", | |
5012 | GP, (int) BFD_RELOC_LO16, mips_frame_reg); | |
5013 | } | |
252b5132 RH |
5014 | } |
5015 | } | |
5016 | else | |
5017 | abort (); | |
5018 | ||
5019 | return; | |
5020 | ||
5021 | case M_JAL_A: | |
5022 | if (mips_pic == NO_PIC) | |
5023 | macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a"); | |
5024 | else if (mips_pic == SVR4_PIC) | |
5025 | { | |
5026 | /* If this is a reference to an external symbol, and we are | |
5027 | using a small GOT, we want | |
5028 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
5029 | nop | |
5030 | jalr $25 | |
5031 | nop | |
5032 | lw $gp,cprestore($sp) | |
5033 | The cprestore value is set using the .cprestore | |
5034 | pseudo-op. If we are using a big GOT, we want | |
5035 | lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
5036 | addu $25,$25,$gp | |
5037 | lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16) | |
5038 | nop | |
5039 | jalr $25 | |
5040 | nop | |
5041 | lw $gp,cprestore($sp) | |
5042 | If the symbol is not external, we want | |
5043 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5044 | nop | |
5045 | addiu $25,$25,<sym> (BFD_RELOC_LO16) | |
5046 | jalr $25 | |
5047 | nop | |
5048 | lw $gp,cprestore($sp) */ | |
5049 | frag_grow (40); | |
5050 | if (! mips_big_got) | |
5051 | { | |
5052 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5053 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5054 | "t,o(b)", PIC_CALL_REG, |
5055 | (int) BFD_RELOC_MIPS_CALL16, GP); | |
5056 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5057 | "nop", ""); | |
5058 | p = frag_var (rs_machine_dependent, 4, 0, | |
5059 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), | |
5060 | offset_expr.X_add_symbol, (offsetT) 0, | |
5061 | (char *) NULL); | |
5062 | } | |
5063 | else | |
5064 | { | |
5065 | int gpdel; | |
5066 | ||
5067 | if (reg_needs_delay (GP)) | |
5068 | gpdel = 4; | |
5069 | else | |
5070 | gpdel = 0; | |
5071 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5072 | PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16); | |
5073 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5074 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5075 | "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP); |
5076 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5077 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5078 | "t,o(b)", PIC_CALL_REG, |
5079 | (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG); | |
5080 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5081 | "nop", ""); | |
5082 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5083 | RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel, | |
5084 | 0, 0), | |
5085 | offset_expr.X_add_symbol, (offsetT) 0, | |
5086 | (char *) NULL); | |
5087 | if (gpdel > 0) | |
5088 | { | |
5089 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5090 | p += 4; | |
5091 | } | |
5092 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5093 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5094 | "t,o(b)", PIC_CALL_REG, |
5095 | (int) BFD_RELOC_MIPS_GOT16, GP); | |
5096 | p += 4; | |
5097 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5098 | p += 4; | |
bdaaa2e1 | 5099 | } |
252b5132 | 5100 | macro_build (p, &icnt, &offset_expr, |
ca4e0257 | 5101 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5102 | "t,r,j", PIC_CALL_REG, PIC_CALL_REG, |
5103 | (int) BFD_RELOC_LO16); | |
5104 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5105 | "jalr", "s", PIC_CALL_REG); | |
6478892d | 5106 | if (! HAVE_NEWABI) |
252b5132 | 5107 | { |
6478892d TS |
5108 | if (mips_cprestore_offset < 0) |
5109 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
5110 | else | |
5111 | { | |
5112 | if (mips_opts.noreorder) | |
5113 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
252b5132 | 5114 | "nop", ""); |
6478892d TS |
5115 | expr1.X_add_number = mips_cprestore_offset; |
5116 | macro_build ((char *) NULL, &icnt, &expr1, | |
5117 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", | |
5118 | GP, (int) BFD_RELOC_LO16, mips_frame_reg); | |
5119 | } | |
252b5132 RH |
5120 | } |
5121 | } | |
5122 | else if (mips_pic == EMBEDDED_PIC) | |
5123 | { | |
5124 | macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p"); | |
5125 | /* The linker may expand the call to a longer sequence which | |
5126 | uses $at, so we must break rather than return. */ | |
5127 | break; | |
5128 | } | |
5129 | else | |
5130 | abort (); | |
5131 | ||
5132 | return; | |
5133 | ||
5134 | case M_LB_AB: | |
5135 | s = "lb"; | |
5136 | goto ld; | |
5137 | case M_LBU_AB: | |
5138 | s = "lbu"; | |
5139 | goto ld; | |
5140 | case M_LH_AB: | |
5141 | s = "lh"; | |
5142 | goto ld; | |
5143 | case M_LHU_AB: | |
5144 | s = "lhu"; | |
5145 | goto ld; | |
5146 | case M_LW_AB: | |
5147 | s = "lw"; | |
5148 | goto ld; | |
5149 | case M_LWC0_AB: | |
5150 | s = "lwc0"; | |
bdaaa2e1 | 5151 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5152 | coproc = 1; |
5153 | goto ld; | |
5154 | case M_LWC1_AB: | |
5155 | s = "lwc1"; | |
bdaaa2e1 | 5156 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5157 | coproc = 1; |
5158 | goto ld; | |
5159 | case M_LWC2_AB: | |
5160 | s = "lwc2"; | |
bdaaa2e1 | 5161 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5162 | coproc = 1; |
5163 | goto ld; | |
5164 | case M_LWC3_AB: | |
5165 | s = "lwc3"; | |
bdaaa2e1 | 5166 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5167 | coproc = 1; |
5168 | goto ld; | |
5169 | case M_LWL_AB: | |
5170 | s = "lwl"; | |
5171 | lr = 1; | |
5172 | goto ld; | |
5173 | case M_LWR_AB: | |
5174 | s = "lwr"; | |
5175 | lr = 1; | |
5176 | goto ld; | |
5177 | case M_LDC1_AB: | |
ec68c924 | 5178 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5179 | { |
5180 | as_bad (_("opcode not supported on this processor")); | |
5181 | return; | |
5182 | } | |
5183 | s = "ldc1"; | |
bdaaa2e1 | 5184 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5185 | coproc = 1; |
5186 | goto ld; | |
5187 | case M_LDC2_AB: | |
5188 | s = "ldc2"; | |
bdaaa2e1 | 5189 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5190 | coproc = 1; |
5191 | goto ld; | |
5192 | case M_LDC3_AB: | |
5193 | s = "ldc3"; | |
bdaaa2e1 | 5194 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5195 | coproc = 1; |
5196 | goto ld; | |
5197 | case M_LDL_AB: | |
5198 | s = "ldl"; | |
5199 | lr = 1; | |
5200 | goto ld; | |
5201 | case M_LDR_AB: | |
5202 | s = "ldr"; | |
5203 | lr = 1; | |
5204 | goto ld; | |
5205 | case M_LL_AB: | |
5206 | s = "ll"; | |
5207 | goto ld; | |
5208 | case M_LLD_AB: | |
5209 | s = "lld"; | |
5210 | goto ld; | |
5211 | case M_LWU_AB: | |
5212 | s = "lwu"; | |
5213 | ld: | |
5214 | if (breg == treg || coproc || lr) | |
5215 | { | |
5216 | tempreg = AT; | |
5217 | used_at = 1; | |
5218 | } | |
5219 | else | |
5220 | { | |
5221 | tempreg = treg; | |
5222 | used_at = 0; | |
5223 | } | |
5224 | goto ld_st; | |
5225 | case M_SB_AB: | |
5226 | s = "sb"; | |
5227 | goto st; | |
5228 | case M_SH_AB: | |
5229 | s = "sh"; | |
5230 | goto st; | |
5231 | case M_SW_AB: | |
5232 | s = "sw"; | |
5233 | goto st; | |
5234 | case M_SWC0_AB: | |
5235 | s = "swc0"; | |
bdaaa2e1 | 5236 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5237 | coproc = 1; |
5238 | goto st; | |
5239 | case M_SWC1_AB: | |
5240 | s = "swc1"; | |
bdaaa2e1 | 5241 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5242 | coproc = 1; |
5243 | goto st; | |
5244 | case M_SWC2_AB: | |
5245 | s = "swc2"; | |
bdaaa2e1 | 5246 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5247 | coproc = 1; |
5248 | goto st; | |
5249 | case M_SWC3_AB: | |
5250 | s = "swc3"; | |
bdaaa2e1 | 5251 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5252 | coproc = 1; |
5253 | goto st; | |
5254 | case M_SWL_AB: | |
5255 | s = "swl"; | |
5256 | goto st; | |
5257 | case M_SWR_AB: | |
5258 | s = "swr"; | |
5259 | goto st; | |
5260 | case M_SC_AB: | |
5261 | s = "sc"; | |
5262 | goto st; | |
5263 | case M_SCD_AB: | |
5264 | s = "scd"; | |
5265 | goto st; | |
5266 | case M_SDC1_AB: | |
ec68c924 | 5267 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5268 | { |
5269 | as_bad (_("opcode not supported on this processor")); | |
5270 | return; | |
5271 | } | |
5272 | s = "sdc1"; | |
5273 | coproc = 1; | |
bdaaa2e1 | 5274 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5275 | goto st; |
5276 | case M_SDC2_AB: | |
5277 | s = "sdc2"; | |
bdaaa2e1 | 5278 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5279 | coproc = 1; |
5280 | goto st; | |
5281 | case M_SDC3_AB: | |
5282 | s = "sdc3"; | |
bdaaa2e1 | 5283 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5284 | coproc = 1; |
5285 | goto st; | |
5286 | case M_SDL_AB: | |
5287 | s = "sdl"; | |
5288 | goto st; | |
5289 | case M_SDR_AB: | |
5290 | s = "sdr"; | |
5291 | st: | |
5292 | tempreg = AT; | |
5293 | used_at = 1; | |
5294 | ld_st: | |
bdaaa2e1 | 5295 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5296 | if (mask == M_LWC1_AB |
5297 | || mask == M_SWC1_AB | |
5298 | || mask == M_LDC1_AB | |
5299 | || mask == M_SDC1_AB | |
5300 | || mask == M_L_DAB | |
5301 | || mask == M_S_DAB) | |
5302 | fmt = "T,o(b)"; | |
5303 | else if (coproc) | |
5304 | fmt = "E,o(b)"; | |
5305 | else | |
5306 | fmt = "t,o(b)"; | |
5307 | ||
afdbd6d0 CD |
5308 | /* For embedded PIC, we allow loads where the offset is calculated |
5309 | by subtracting a symbol in the current segment from an unknown | |
5310 | symbol, relative to a base register, e.g.: | |
5311 | <op> $treg, <sym>-<localsym>($breg) | |
5312 | This is used by the compiler for switch statements. */ | |
76b3015f | 5313 | if (mips_pic == EMBEDDED_PIC |
afdbd6d0 CD |
5314 | && offset_expr.X_op == O_subtract |
5315 | && (symbol_constant_p (offset_expr.X_op_symbol) | |
5316 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg | |
5317 | : (symbol_equated_p (offset_expr.X_op_symbol) | |
5318 | && (S_GET_SEGMENT | |
5319 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
5320 | ->X_add_symbol) | |
5321 | == now_seg))) | |
5322 | && breg != 0 | |
5323 | && (offset_expr.X_add_number == 0 | |
5324 | || OUTPUT_FLAVOR == bfd_target_elf_flavour)) | |
5325 | { | |
5326 | /* For this case, we output the instructions: | |
5327 | lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S) | |
5328 | addiu $tempreg,$tempreg,$breg | |
5329 | <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16) | |
5330 | If the relocation would fit entirely in 16 bits, it would be | |
5331 | nice to emit: | |
5332 | <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16) | |
5333 | instead, but that seems quite difficult. */ | |
5334 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5335 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
5336 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5337 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5338 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
5339 | ? "addu" : "daddu"), | |
5340 | "d,v,t", tempreg, tempreg, breg); | |
5341 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg, | |
5342 | (int) BFD_RELOC_PCREL_LO16, tempreg); | |
5343 | if (! used_at) | |
5344 | return; | |
5345 | break; | |
5346 | } | |
5347 | ||
252b5132 RH |
5348 | if (offset_expr.X_op != O_constant |
5349 | && offset_expr.X_op != O_symbol) | |
5350 | { | |
5351 | as_bad (_("expression too complex")); | |
5352 | offset_expr.X_op = O_constant; | |
5353 | } | |
5354 | ||
5355 | /* A constant expression in PIC code can be handled just as it | |
5356 | is in non PIC code. */ | |
5357 | if (mips_pic == NO_PIC | |
5358 | || offset_expr.X_op == O_constant) | |
5359 | { | |
5360 | /* If this is a reference to a GP relative symbol, and there | |
5361 | is no base register, we want | |
5362 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5363 | Otherwise, if there is no base register, we want | |
5364 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5365 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5366 | If we have a constant, we need two instructions anyhow, | |
5367 | so we always use the latter form. | |
5368 | ||
5369 | If we have a base register, and this is a reference to a | |
5370 | GP relative symbol, we want | |
5371 | addu $tempreg,$breg,$gp | |
5372 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL) | |
5373 | Otherwise we want | |
5374 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5375 | addu $tempreg,$tempreg,$breg | |
5376 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
d6bc6245 | 5377 | With a constant we always use the latter case. |
76b3015f | 5378 | |
d6bc6245 TS |
5379 | With 64bit address space and no base register and $at usable, |
5380 | we want | |
5381 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5382 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5383 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5384 | dsll32 $tempreg,0 | |
5385 | daddu $tempreg,$at | |
5386 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5387 | If we have a base register, we want | |
5388 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5389 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5390 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5391 | daddu $at,$breg | |
5392 | dsll32 $tempreg,0 | |
5393 | daddu $tempreg,$at | |
5394 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5395 | ||
5396 | Without $at we can't generate the optimal path for superscalar | |
5397 | processors here since this would require two temporary registers. | |
5398 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5399 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5400 | dsll $tempreg,16 | |
5401 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5402 | dsll $tempreg,16 | |
5403 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5404 | If we have a base register, we want | |
5405 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5406 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5407 | dsll $tempreg,16 | |
5408 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5409 | dsll $tempreg,16 | |
5410 | daddu $tempreg,$tempreg,$breg | |
5411 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5412 | */ | |
5413 | if (HAVE_64BIT_ADDRESSES) | |
5414 | { | |
5415 | p = NULL; | |
5416 | ||
5417 | /* We don't do GP optimization for now because RELAX_ENCODE can't | |
5418 | hold the data for such large chunks. */ | |
5419 | ||
5420 | if (used_at == 0) | |
5421 | { | |
5422 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5423 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
5424 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5425 | AT, (int) BFD_RELOC_HI16_S); | |
5426 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
5427 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
5428 | if (breg != 0) | |
5429 | macro_build (p, &icnt, NULL, "daddu", "d,v,t", | |
5430 | AT, AT, breg); | |
5431 | macro_build (p, &icnt, NULL, "dsll32", "d,w,<", | |
5432 | tempreg, tempreg, 0); | |
5433 | macro_build (p, &icnt, NULL, "daddu", "d,v,t", | |
5434 | tempreg, tempreg, AT); | |
5435 | macro_build (p, &icnt, &offset_expr, s, | |
5436 | fmt, treg, (int) BFD_RELOC_LO16, tempreg); | |
5437 | used_at = 1; | |
5438 | } | |
5439 | else | |
5440 | { | |
5441 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5442 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
5443 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
5444 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
5445 | macro_build (p, &icnt, NULL, "dsll", "d,w,<", | |
5446 | tempreg, tempreg, 16); | |
5447 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
5448 | tempreg, tempreg, (int) BFD_RELOC_HI16_S); | |
5449 | macro_build (p, &icnt, NULL, "dsll", "d,w,<", | |
5450 | tempreg, tempreg, 16); | |
5451 | if (breg != 0) | |
5452 | macro_build (p, &icnt, NULL, "daddu", "d,v,t", | |
5453 | tempreg, tempreg, breg); | |
5454 | macro_build (p, &icnt, &offset_expr, s, | |
5455 | fmt, treg, (int) BFD_RELOC_LO16, tempreg); | |
5456 | } | |
5457 | ||
5458 | return; | |
5459 | } | |
76b3015f | 5460 | |
252b5132 RH |
5461 | if (breg == 0) |
5462 | { | |
e7d556df | 5463 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5464 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5465 | p = NULL; | |
5466 | else | |
5467 | { | |
5468 | frag_grow (20); | |
5469 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5470 | treg, (int) BFD_RELOC_MIPS_GPREL, GP); | |
5471 | p = frag_var (rs_machine_dependent, 8, 0, | |
5472 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
5473 | (mips_opts.warn_about_macros | |
5474 | || (used_at | |
5475 | && mips_opts.noat))), | |
5476 | offset_expr.X_add_symbol, (offsetT) 0, | |
5477 | (char *) NULL); | |
5478 | used_at = 0; | |
5479 | } | |
5480 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5481 | if (p != NULL) | |
5482 | p += 4; | |
5483 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5484 | (int) BFD_RELOC_LO16, tempreg); | |
5485 | } | |
5486 | else | |
5487 | { | |
e7d556df | 5488 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5489 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5490 | p = NULL; | |
5491 | else | |
5492 | { | |
5493 | frag_grow (28); | |
5494 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5495 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5496 | "d,v,t", tempreg, breg, GP); |
5497 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5498 | treg, (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5499 | p = frag_var (rs_machine_dependent, 12, 0, | |
5500 | RELAX_ENCODE (8, 12, 0, 8, 0, 0), | |
5501 | offset_expr.X_add_symbol, (offsetT) 0, | |
5502 | (char *) NULL); | |
5503 | } | |
5504 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5505 | if (p != NULL) | |
5506 | p += 4; | |
5507 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5508 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5509 | "d,v,t", tempreg, tempreg, breg); |
5510 | if (p != NULL) | |
5511 | p += 4; | |
5512 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5513 | (int) BFD_RELOC_LO16, tempreg); | |
5514 | } | |
5515 | } | |
5516 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
5517 | { | |
5518 | /* If this is a reference to an external symbol, we want | |
5519 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5520 | nop | |
5521 | <op> $treg,0($tempreg) | |
5522 | Otherwise we want | |
5523 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5524 | nop | |
5525 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5526 | <op> $treg,0($tempreg) | |
5527 | If there is a base register, we add it to $tempreg before | |
5528 | the <op>. If there is a constant, we stick it in the | |
5529 | <op> instruction. We don't handle constants larger than | |
5530 | 16 bits, because we have no way to load the upper 16 bits | |
5531 | (actually, we could handle them for the subset of cases | |
5532 | in which we are not using $at). */ | |
5533 | assert (offset_expr.X_op == O_symbol); | |
5534 | expr1.X_add_number = offset_expr.X_add_number; | |
5535 | offset_expr.X_add_number = 0; | |
5536 | if (expr1.X_add_number < -0x8000 | |
5537 | || expr1.X_add_number >= 0x8000) | |
5538 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5539 | frag_grow (20); | |
5540 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5541 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5542 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); |
5543 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
bdaaa2e1 | 5544 | p = frag_var (rs_machine_dependent, 4, 0, |
252b5132 RH |
5545 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), |
5546 | offset_expr.X_add_symbol, (offsetT) 0, | |
5547 | (char *) NULL); | |
5548 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5549 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5550 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5551 | if (breg != 0) | |
5552 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5553 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5554 | "d,v,t", tempreg, tempreg, breg); |
5555 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5556 | (int) BFD_RELOC_LO16, tempreg); | |
5557 | } | |
5558 | else if (mips_pic == SVR4_PIC) | |
5559 | { | |
5560 | int gpdel; | |
5561 | ||
5562 | /* If this is a reference to an external symbol, we want | |
5563 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5564 | addu $tempreg,$tempreg,$gp | |
5565 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
5566 | <op> $treg,0($tempreg) | |
5567 | Otherwise we want | |
5568 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5569 | nop | |
5570 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5571 | <op> $treg,0($tempreg) | |
5572 | If there is a base register, we add it to $tempreg before | |
5573 | the <op>. If there is a constant, we stick it in the | |
5574 | <op> instruction. We don't handle constants larger than | |
5575 | 16 bits, because we have no way to load the upper 16 bits | |
5576 | (actually, we could handle them for the subset of cases | |
5577 | in which we are not using $at). */ | |
5578 | assert (offset_expr.X_op == O_symbol); | |
5579 | expr1.X_add_number = offset_expr.X_add_number; | |
5580 | offset_expr.X_add_number = 0; | |
5581 | if (expr1.X_add_number < -0x8000 | |
5582 | || expr1.X_add_number >= 0x8000) | |
5583 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5584 | if (reg_needs_delay (GP)) | |
5585 | gpdel = 4; | |
5586 | else | |
5587 | gpdel = 0; | |
5588 | frag_grow (36); | |
5589 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5590 | tempreg, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5591 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5592 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5593 | "d,v,t", tempreg, tempreg, GP); |
5594 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5595 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5596 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16, |
5597 | tempreg); | |
5598 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5599 | RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0), | |
5600 | offset_expr.X_add_symbol, (offsetT) 0, (char *) NULL); | |
5601 | if (gpdel > 0) | |
5602 | { | |
5603 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5604 | p += 4; | |
5605 | } | |
5606 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5607 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5608 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); |
5609 | p += 4; | |
5610 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5611 | p += 4; | |
5612 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5613 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5614 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5615 | if (breg != 0) | |
5616 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5617 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5618 | "d,v,t", tempreg, tempreg, breg); |
5619 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5620 | (int) BFD_RELOC_LO16, tempreg); | |
5621 | } | |
5622 | else if (mips_pic == EMBEDDED_PIC) | |
5623 | { | |
5624 | /* If there is no base register, we want | |
5625 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5626 | If there is a base register, we want | |
5627 | addu $tempreg,$breg,$gp | |
5628 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL) | |
5629 | */ | |
5630 | assert (offset_expr.X_op == O_symbol); | |
5631 | if (breg == 0) | |
5632 | { | |
5633 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5634 | treg, (int) BFD_RELOC_MIPS_GPREL, GP); | |
5635 | used_at = 0; | |
5636 | } | |
5637 | else | |
5638 | { | |
5639 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5640 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5641 | "d,v,t", tempreg, breg, GP); |
5642 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5643 | treg, (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5644 | } | |
5645 | } | |
5646 | else | |
5647 | abort (); | |
5648 | ||
5649 | if (! used_at) | |
5650 | return; | |
5651 | ||
5652 | break; | |
5653 | ||
5654 | case M_LI: | |
5655 | case M_LI_S: | |
5656 | load_register (&icnt, treg, &imm_expr, 0); | |
5657 | return; | |
5658 | ||
5659 | case M_DLI: | |
5660 | load_register (&icnt, treg, &imm_expr, 1); | |
5661 | return; | |
5662 | ||
5663 | case M_LI_SS: | |
5664 | if (imm_expr.X_op == O_constant) | |
5665 | { | |
5666 | load_register (&icnt, AT, &imm_expr, 0); | |
5667 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5668 | "mtc1", "t,G", AT, treg); | |
5669 | break; | |
5670 | } | |
5671 | else | |
5672 | { | |
5673 | assert (offset_expr.X_op == O_symbol | |
5674 | && strcmp (segment_name (S_GET_SEGMENT | |
5675 | (offset_expr.X_add_symbol)), | |
5676 | ".lit4") == 0 | |
5677 | && offset_expr.X_add_number == 0); | |
5678 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5679 | treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5680 | return; | |
5681 | } | |
5682 | ||
5683 | case M_LI_D: | |
ca4e0257 RS |
5684 | /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits |
5685 | wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high | |
5686 | order 32 bits of the value and the low order 32 bits are either | |
5687 | zero or in OFFSET_EXPR. */ | |
252b5132 RH |
5688 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
5689 | { | |
ca4e0257 | 5690 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5691 | load_register (&icnt, treg, &imm_expr, 1); |
5692 | else | |
5693 | { | |
5694 | int hreg, lreg; | |
5695 | ||
5696 | if (target_big_endian) | |
5697 | { | |
5698 | hreg = treg; | |
5699 | lreg = treg + 1; | |
5700 | } | |
5701 | else | |
5702 | { | |
5703 | hreg = treg + 1; | |
5704 | lreg = treg; | |
5705 | } | |
5706 | ||
5707 | if (hreg <= 31) | |
5708 | load_register (&icnt, hreg, &imm_expr, 0); | |
5709 | if (lreg <= 31) | |
5710 | { | |
5711 | if (offset_expr.X_op == O_absent) | |
ea1fb5dc | 5712 | move_register (&icnt, lreg, 0); |
252b5132 RH |
5713 | else |
5714 | { | |
5715 | assert (offset_expr.X_op == O_constant); | |
5716 | load_register (&icnt, lreg, &offset_expr, 0); | |
5717 | } | |
5718 | } | |
5719 | } | |
5720 | return; | |
5721 | } | |
5722 | ||
5723 | /* We know that sym is in the .rdata section. First we get the | |
5724 | upper 16 bits of the address. */ | |
5725 | if (mips_pic == NO_PIC) | |
5726 | { | |
5727 | /* FIXME: This won't work for a 64 bit address. */ | |
5728 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5729 | } | |
5730 | else if (mips_pic == SVR4_PIC) | |
5731 | { | |
5732 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5733 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5734 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
5735 | } | |
5736 | else if (mips_pic == EMBEDDED_PIC) | |
5737 | { | |
5738 | /* For embedded PIC we pick up the entire address off $gp in | |
5739 | a single instruction. */ | |
5740 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5741 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5742 | "t,r,j", AT, GP, (int) BFD_RELOC_MIPS_GPREL); |
5743 | offset_expr.X_op = O_constant; | |
5744 | offset_expr.X_add_number = 0; | |
5745 | } | |
5746 | else | |
5747 | abort (); | |
bdaaa2e1 | 5748 | |
252b5132 | 5749 | /* Now we load the register(s). */ |
ca4e0257 | 5750 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5751 | macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)", |
5752 | treg, (int) BFD_RELOC_LO16, AT); | |
5753 | else | |
5754 | { | |
5755 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5756 | treg, (int) BFD_RELOC_LO16, AT); | |
5757 | if (treg != 31) | |
5758 | { | |
5759 | /* FIXME: How in the world do we deal with the possible | |
5760 | overflow here? */ | |
5761 | offset_expr.X_add_number += 4; | |
5762 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5763 | treg + 1, (int) BFD_RELOC_LO16, AT); | |
5764 | } | |
5765 | } | |
5766 | ||
5767 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5768 | does not become a variant frag. */ | |
5769 | frag_wane (frag_now); | |
5770 | frag_new (0); | |
5771 | ||
5772 | break; | |
5773 | ||
5774 | case M_LI_DD: | |
ca4e0257 RS |
5775 | /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits |
5776 | wide, IMM_EXPR is the entire value and the GPRs are known to be 64 | |
5777 | bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of | |
5778 | the value and the low order 32 bits are either zero or in | |
5779 | OFFSET_EXPR. */ | |
252b5132 RH |
5780 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
5781 | { | |
ca4e0257 RS |
5782 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS); |
5783 | if (HAVE_64BIT_FPRS) | |
5784 | { | |
5785 | assert (HAVE_64BIT_GPRS); | |
5786 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5787 | "dmtc1", "t,S", AT, treg); | |
5788 | } | |
252b5132 RH |
5789 | else |
5790 | { | |
5791 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5792 | "mtc1", "t,G", AT, treg + 1); | |
5793 | if (offset_expr.X_op == O_absent) | |
5794 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5795 | "mtc1", "t,G", 0, treg); | |
5796 | else | |
5797 | { | |
5798 | assert (offset_expr.X_op == O_constant); | |
5799 | load_register (&icnt, AT, &offset_expr, 0); | |
5800 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5801 | "mtc1", "t,G", AT, treg); | |
5802 | } | |
5803 | } | |
5804 | break; | |
5805 | } | |
5806 | ||
5807 | assert (offset_expr.X_op == O_symbol | |
5808 | && offset_expr.X_add_number == 0); | |
5809 | s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol)); | |
5810 | if (strcmp (s, ".lit8") == 0) | |
5811 | { | |
e7af610e | 5812 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5813 | { |
5814 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5815 | "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5816 | return; | |
5817 | } | |
5818 | breg = GP; | |
5819 | r = BFD_RELOC_MIPS_LITERAL; | |
5820 | goto dob; | |
5821 | } | |
5822 | else | |
5823 | { | |
5824 | assert (strcmp (s, RDATA_SECTION_NAME) == 0); | |
5825 | if (mips_pic == SVR4_PIC) | |
5826 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5827 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5828 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
5829 | else | |
5830 | { | |
5831 | /* FIXME: This won't work for a 64 bit address. */ | |
5832 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5833 | } | |
bdaaa2e1 | 5834 | |
e7af610e | 5835 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5836 | { |
5837 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5838 | "T,o(b)", treg, (int) BFD_RELOC_LO16, AT); | |
5839 | ||
5840 | /* To avoid confusion in tc_gen_reloc, we must ensure | |
5841 | that this does not become a variant frag. */ | |
5842 | frag_wane (frag_now); | |
5843 | frag_new (0); | |
5844 | ||
5845 | break; | |
5846 | } | |
5847 | breg = AT; | |
5848 | r = BFD_RELOC_LO16; | |
5849 | goto dob; | |
5850 | } | |
5851 | ||
5852 | case M_L_DOB: | |
ec68c924 | 5853 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5854 | { |
5855 | as_bad (_("opcode not supported on this processor")); | |
5856 | return; | |
5857 | } | |
5858 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5859 | to adjust when loading from memory. */ | |
5860 | r = BFD_RELOC_LO16; | |
5861 | dob: | |
e7af610e | 5862 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
5863 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", |
5864 | target_big_endian ? treg + 1 : treg, | |
5865 | (int) r, breg); | |
5866 | /* FIXME: A possible overflow which I don't know how to deal | |
5867 | with. */ | |
5868 | offset_expr.X_add_number += 4; | |
5869 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5870 | target_big_endian ? treg : treg + 1, | |
5871 | (int) r, breg); | |
5872 | ||
5873 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5874 | does not become a variant frag. */ | |
5875 | frag_wane (frag_now); | |
5876 | frag_new (0); | |
5877 | ||
5878 | if (breg != AT) | |
5879 | return; | |
5880 | break; | |
5881 | ||
5882 | case M_L_DAB: | |
5883 | /* | |
5884 | * The MIPS assembler seems to check for X_add_number not | |
5885 | * being double aligned and generating: | |
5886 | * lui at,%hi(foo+1) | |
5887 | * addu at,at,v1 | |
5888 | * addiu at,at,%lo(foo+1) | |
5889 | * lwc1 f2,0(at) | |
5890 | * lwc1 f3,4(at) | |
5891 | * But, the resulting address is the same after relocation so why | |
5892 | * generate the extra instruction? | |
5893 | */ | |
ec68c924 | 5894 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5895 | { |
5896 | as_bad (_("opcode not supported on this processor")); | |
5897 | return; | |
5898 | } | |
bdaaa2e1 | 5899 | /* Itbl support may require additional care here. */ |
252b5132 | 5900 | coproc = 1; |
e7af610e | 5901 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5902 | { |
5903 | s = "ldc1"; | |
5904 | goto ld; | |
5905 | } | |
5906 | ||
5907 | s = "lwc1"; | |
5908 | fmt = "T,o(b)"; | |
5909 | goto ldd_std; | |
5910 | ||
5911 | case M_S_DAB: | |
ec68c924 | 5912 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5913 | { |
5914 | as_bad (_("opcode not supported on this processor")); | |
5915 | return; | |
5916 | } | |
5917 | ||
e7af610e | 5918 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
5919 | { |
5920 | s = "sdc1"; | |
5921 | goto st; | |
5922 | } | |
5923 | ||
5924 | s = "swc1"; | |
5925 | fmt = "T,o(b)"; | |
bdaaa2e1 | 5926 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5927 | coproc = 1; |
5928 | goto ldd_std; | |
5929 | ||
5930 | case M_LD_AB: | |
ca4e0257 | 5931 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5932 | { |
5933 | s = "ld"; | |
5934 | goto ld; | |
5935 | } | |
5936 | ||
5937 | s = "lw"; | |
5938 | fmt = "t,o(b)"; | |
5939 | goto ldd_std; | |
5940 | ||
5941 | case M_SD_AB: | |
ca4e0257 | 5942 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
5943 | { |
5944 | s = "sd"; | |
5945 | goto st; | |
5946 | } | |
5947 | ||
5948 | s = "sw"; | |
5949 | fmt = "t,o(b)"; | |
5950 | ||
5951 | ldd_std: | |
afdbd6d0 CD |
5952 | /* We do _not_ bother to allow embedded PIC (symbol-local_symbol) |
5953 | loads for the case of doing a pair of loads to simulate an 'ld'. | |
5954 | This is not currently done by the compiler, and assembly coders | |
5955 | writing embedded-pic code can cope. */ | |
5956 | ||
252b5132 RH |
5957 | if (offset_expr.X_op != O_symbol |
5958 | && offset_expr.X_op != O_constant) | |
5959 | { | |
5960 | as_bad (_("expression too complex")); | |
5961 | offset_expr.X_op = O_constant; | |
5962 | } | |
5963 | ||
5964 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5965 | to adjust when loading from memory. We set coproc if we must | |
5966 | load $fn+1 first. */ | |
bdaaa2e1 | 5967 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5968 | if (! target_big_endian) |
5969 | coproc = 0; | |
5970 | ||
5971 | if (mips_pic == NO_PIC | |
5972 | || offset_expr.X_op == O_constant) | |
5973 | { | |
5974 | /* If this is a reference to a GP relative symbol, we want | |
5975 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5976 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL) | |
5977 | If we have a base register, we use this | |
5978 | addu $at,$breg,$gp | |
5979 | <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL) | |
5980 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL) | |
5981 | If this is not a GP relative symbol, we want | |
5982 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5983 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5984 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5985 | If there is a base register, we add it to $at after the | |
5986 | lui instruction. If there is a constant, we always use | |
5987 | the last case. */ | |
e7d556df | 5988 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5989 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5990 | { | |
5991 | p = NULL; | |
5992 | used_at = 1; | |
5993 | } | |
5994 | else | |
5995 | { | |
5996 | int off; | |
5997 | ||
5998 | if (breg == 0) | |
5999 | { | |
6000 | frag_grow (28); | |
6001 | tempreg = GP; | |
6002 | off = 0; | |
6003 | used_at = 0; | |
6004 | } | |
6005 | else | |
6006 | { | |
6007 | frag_grow (36); | |
6008 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6009 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6010 | "d,v,t", AT, breg, GP); |
6011 | tempreg = AT; | |
6012 | off = 4; | |
6013 | used_at = 1; | |
6014 | } | |
6015 | ||
beae10d5 | 6016 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6017 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6018 | coproc ? treg + 1 : treg, | |
6019 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
6020 | offset_expr.X_add_number += 4; | |
6021 | ||
6022 | /* Set mips_optimize to 2 to avoid inserting an | |
6023 | undesired nop. */ | |
6024 | hold_mips_optimize = mips_optimize; | |
6025 | mips_optimize = 2; | |
beae10d5 | 6026 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6027 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6028 | coproc ? treg : treg + 1, | |
6029 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
6030 | mips_optimize = hold_mips_optimize; | |
6031 | ||
6032 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
6033 | RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1, | |
6034 | used_at && mips_opts.noat), | |
6035 | offset_expr.X_add_symbol, (offsetT) 0, | |
6036 | (char *) NULL); | |
6037 | ||
6038 | /* We just generated two relocs. When tc_gen_reloc | |
6039 | handles this case, it will skip the first reloc and | |
6040 | handle the second. The second reloc already has an | |
6041 | extra addend of 4, which we added above. We must | |
6042 | subtract it out, and then subtract another 4 to make | |
6043 | the first reloc come out right. The second reloc | |
6044 | will come out right because we are going to add 4 to | |
6045 | offset_expr when we build its instruction below. | |
6046 | ||
6047 | If we have a symbol, then we don't want to include | |
6048 | the offset, because it will wind up being included | |
6049 | when we generate the reloc. */ | |
6050 | ||
6051 | if (offset_expr.X_op == O_constant) | |
6052 | offset_expr.X_add_number -= 8; | |
6053 | else | |
6054 | { | |
6055 | offset_expr.X_add_number = -4; | |
6056 | offset_expr.X_op = O_constant; | |
6057 | } | |
6058 | } | |
6059 | macro_build_lui (p, &icnt, &offset_expr, AT); | |
6060 | if (p != NULL) | |
6061 | p += 4; | |
6062 | if (breg != 0) | |
6063 | { | |
6064 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6065 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6066 | "d,v,t", AT, breg, AT); |
6067 | if (p != NULL) | |
6068 | p += 4; | |
6069 | } | |
beae10d5 | 6070 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6071 | macro_build (p, &icnt, &offset_expr, s, fmt, |
6072 | coproc ? treg + 1 : treg, | |
6073 | (int) BFD_RELOC_LO16, AT); | |
6074 | if (p != NULL) | |
6075 | p += 4; | |
6076 | /* FIXME: How do we handle overflow here? */ | |
6077 | offset_expr.X_add_number += 4; | |
beae10d5 | 6078 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6079 | macro_build (p, &icnt, &offset_expr, s, fmt, |
6080 | coproc ? treg : treg + 1, | |
6081 | (int) BFD_RELOC_LO16, AT); | |
bdaaa2e1 | 6082 | } |
252b5132 RH |
6083 | else if (mips_pic == SVR4_PIC && ! mips_big_got) |
6084 | { | |
6085 | int off; | |
6086 | ||
6087 | /* If this is a reference to an external symbol, we want | |
6088 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6089 | nop | |
6090 | <op> $treg,0($at) | |
6091 | <op> $treg+1,4($at) | |
6092 | Otherwise we want | |
6093 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6094 | nop | |
6095 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
6096 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
6097 | If there is a base register we add it to $at before the | |
6098 | lwc1 instructions. If there is a constant we include it | |
6099 | in the lwc1 instructions. */ | |
6100 | used_at = 1; | |
6101 | expr1.X_add_number = offset_expr.X_add_number; | |
6102 | offset_expr.X_add_number = 0; | |
6103 | if (expr1.X_add_number < -0x8000 | |
6104 | || expr1.X_add_number >= 0x8000 - 4) | |
6105 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
6106 | if (breg == 0) | |
6107 | off = 0; | |
6108 | else | |
6109 | off = 4; | |
6110 | frag_grow (24 + off); | |
6111 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 6112 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
6113 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
6114 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
6115 | if (breg != 0) | |
6116 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6117 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 6118 | "d,v,t", AT, breg, AT); |
beae10d5 | 6119 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6120 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6121 | coproc ? treg + 1 : treg, | |
6122 | (int) BFD_RELOC_LO16, AT); | |
6123 | expr1.X_add_number += 4; | |
6124 | ||
6125 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6126 | nop. */ | |
6127 | hold_mips_optimize = mips_optimize; | |
6128 | mips_optimize = 2; | |
beae10d5 | 6129 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6130 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6131 | coproc ? treg : treg + 1, | |
6132 | (int) BFD_RELOC_LO16, AT); | |
6133 | mips_optimize = hold_mips_optimize; | |
6134 | ||
6135 | (void) frag_var (rs_machine_dependent, 0, 0, | |
6136 | RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0), | |
6137 | offset_expr.X_add_symbol, (offsetT) 0, | |
6138 | (char *) NULL); | |
6139 | } | |
6140 | else if (mips_pic == SVR4_PIC) | |
6141 | { | |
6142 | int gpdel, off; | |
6143 | ||
6144 | /* If this is a reference to an external symbol, we want | |
6145 | lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
6146 | addu $at,$at,$gp | |
6147 | lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16) | |
6148 | nop | |
6149 | <op> $treg,0($at) | |
6150 | <op> $treg+1,4($at) | |
6151 | Otherwise we want | |
6152 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6153 | nop | |
6154 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
6155 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
6156 | If there is a base register we add it to $at before the | |
6157 | lwc1 instructions. If there is a constant we include it | |
6158 | in the lwc1 instructions. */ | |
6159 | used_at = 1; | |
6160 | expr1.X_add_number = offset_expr.X_add_number; | |
6161 | offset_expr.X_add_number = 0; | |
6162 | if (expr1.X_add_number < -0x8000 | |
6163 | || expr1.X_add_number >= 0x8000 - 4) | |
6164 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
6165 | if (reg_needs_delay (GP)) | |
6166 | gpdel = 4; | |
6167 | else | |
6168 | gpdel = 0; | |
6169 | if (breg == 0) | |
6170 | off = 0; | |
6171 | else | |
6172 | off = 4; | |
6173 | frag_grow (56); | |
6174 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
6175 | AT, (int) BFD_RELOC_MIPS_GOT_HI16); | |
6176 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6177 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6178 | "d,v,t", AT, AT, GP); |
6179 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 6180 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
6181 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT); |
6182 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
6183 | if (breg != 0) | |
6184 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6185 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 6186 | "d,v,t", AT, breg, AT); |
beae10d5 | 6187 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6188 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6189 | coproc ? treg + 1 : treg, | |
6190 | (int) BFD_RELOC_LO16, AT); | |
6191 | expr1.X_add_number += 4; | |
6192 | ||
6193 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6194 | nop. */ | |
6195 | hold_mips_optimize = mips_optimize; | |
6196 | mips_optimize = 2; | |
beae10d5 | 6197 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6198 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6199 | coproc ? treg : treg + 1, | |
6200 | (int) BFD_RELOC_LO16, AT); | |
6201 | mips_optimize = hold_mips_optimize; | |
6202 | expr1.X_add_number -= 4; | |
6203 | ||
6204 | p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0, | |
6205 | RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel, | |
6206 | 8 + gpdel + off, 1, 0), | |
6207 | offset_expr.X_add_symbol, (offsetT) 0, | |
6208 | (char *) NULL); | |
6209 | if (gpdel > 0) | |
6210 | { | |
6211 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
6212 | p += 4; | |
6213 | } | |
6214 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 6215 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
6216 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); |
6217 | p += 4; | |
6218 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
6219 | p += 4; | |
6220 | if (breg != 0) | |
6221 | { | |
6222 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6223 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6224 | "d,v,t", AT, breg, AT); |
6225 | p += 4; | |
6226 | } | |
beae10d5 | 6227 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6228 | macro_build (p, &icnt, &expr1, s, fmt, |
6229 | coproc ? treg + 1 : treg, | |
6230 | (int) BFD_RELOC_LO16, AT); | |
6231 | p += 4; | |
6232 | expr1.X_add_number += 4; | |
6233 | ||
6234 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6235 | nop. */ | |
6236 | hold_mips_optimize = mips_optimize; | |
6237 | mips_optimize = 2; | |
beae10d5 | 6238 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6239 | macro_build (p, &icnt, &expr1, s, fmt, |
6240 | coproc ? treg : treg + 1, | |
6241 | (int) BFD_RELOC_LO16, AT); | |
6242 | mips_optimize = hold_mips_optimize; | |
6243 | } | |
6244 | else if (mips_pic == EMBEDDED_PIC) | |
6245 | { | |
6246 | /* If there is no base register, we use | |
6247 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
6248 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL) | |
6249 | If we have a base register, we use | |
6250 | addu $at,$breg,$gp | |
6251 | <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL) | |
6252 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL) | |
6253 | */ | |
6254 | if (breg == 0) | |
6255 | { | |
6256 | tempreg = GP; | |
6257 | used_at = 0; | |
6258 | } | |
6259 | else | |
6260 | { | |
6261 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6262 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6263 | "d,v,t", AT, breg, GP); |
6264 | tempreg = AT; | |
6265 | used_at = 1; | |
6266 | } | |
6267 | ||
beae10d5 | 6268 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6269 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6270 | coproc ? treg + 1 : treg, | |
6271 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
6272 | offset_expr.X_add_number += 4; | |
beae10d5 | 6273 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6274 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6275 | coproc ? treg : treg + 1, | |
6276 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
6277 | } | |
6278 | else | |
6279 | abort (); | |
6280 | ||
6281 | if (! used_at) | |
6282 | return; | |
6283 | ||
6284 | break; | |
6285 | ||
6286 | case M_LD_OB: | |
6287 | s = "lw"; | |
6288 | goto sd_ob; | |
6289 | case M_SD_OB: | |
6290 | s = "sw"; | |
6291 | sd_ob: | |
ca4e0257 | 6292 | assert (HAVE_32BIT_ADDRESSES); |
252b5132 RH |
6293 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, |
6294 | (int) BFD_RELOC_LO16, breg); | |
6295 | offset_expr.X_add_number += 4; | |
6296 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1, | |
6297 | (int) BFD_RELOC_LO16, breg); | |
6298 | return; | |
6299 | ||
6300 | /* New code added to support COPZ instructions. | |
6301 | This code builds table entries out of the macros in mip_opcodes. | |
6302 | R4000 uses interlocks to handle coproc delays. | |
6303 | Other chips (like the R3000) require nops to be inserted for delays. | |
6304 | ||
f72c8c98 | 6305 | FIXME: Currently, we require that the user handle delays. |
252b5132 RH |
6306 | In order to fill delay slots for non-interlocked chips, |
6307 | we must have a way to specify delays based on the coprocessor. | |
6308 | Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc. | |
6309 | What are the side-effects of the cop instruction? | |
6310 | What cache support might we have and what are its effects? | |
6311 | Both coprocessor & memory require delays. how long??? | |
bdaaa2e1 | 6312 | What registers are read/set/modified? |
252b5132 RH |
6313 | |
6314 | If an itbl is provided to interpret cop instructions, | |
bdaaa2e1 | 6315 | this knowledge can be encoded in the itbl spec. */ |
252b5132 RH |
6316 | |
6317 | case M_COP0: | |
6318 | s = "c0"; | |
6319 | goto copz; | |
6320 | case M_COP1: | |
6321 | s = "c1"; | |
6322 | goto copz; | |
6323 | case M_COP2: | |
6324 | s = "c2"; | |
6325 | goto copz; | |
6326 | case M_COP3: | |
6327 | s = "c3"; | |
6328 | copz: | |
6329 | /* For now we just do C (same as Cz). The parameter will be | |
6330 | stored in insn_opcode by mips_ip. */ | |
6331 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C", | |
6332 | ip->insn_opcode); | |
6333 | return; | |
6334 | ||
ea1fb5dc RS |
6335 | case M_MOVE: |
6336 | move_register (&icnt, dreg, sreg); | |
6337 | return; | |
6338 | ||
252b5132 RH |
6339 | #ifdef LOSING_COMPILER |
6340 | default: | |
6341 | /* Try and see if this is a new itbl instruction. | |
6342 | This code builds table entries out of the macros in mip_opcodes. | |
6343 | FIXME: For now we just assemble the expression and pass it's | |
6344 | value along as a 32-bit immediate. | |
bdaaa2e1 | 6345 | We may want to have the assembler assemble this value, |
252b5132 RH |
6346 | so that we gain the assembler's knowledge of delay slots, |
6347 | symbols, etc. | |
6348 | Would it be more efficient to use mask (id) here? */ | |
bdaaa2e1 | 6349 | if (itbl_have_entries |
252b5132 | 6350 | && (immed_expr = itbl_assemble (ip->insn_mo->name, ""))) |
beae10d5 | 6351 | { |
252b5132 RH |
6352 | s = ip->insn_mo->name; |
6353 | s2 = "cop3"; | |
6354 | coproc = ITBL_DECODE_PNUM (immed_expr);; | |
6355 | macro_build ((char *) NULL, &icnt, &immed_expr, s, "C"); | |
6356 | return; | |
beae10d5 | 6357 | } |
252b5132 RH |
6358 | macro2 (ip); |
6359 | return; | |
6360 | } | |
6361 | if (mips_opts.noat) | |
6362 | as_warn (_("Macro used $at after \".set noat\"")); | |
6363 | } | |
bdaaa2e1 | 6364 | |
252b5132 RH |
6365 | static void |
6366 | macro2 (ip) | |
6367 | struct mips_cl_insn *ip; | |
6368 | { | |
6369 | register int treg, sreg, dreg, breg; | |
6370 | int tempreg; | |
6371 | int mask; | |
6372 | int icnt = 0; | |
6373 | int used_at; | |
6374 | expressionS expr1; | |
6375 | const char *s; | |
6376 | const char *s2; | |
6377 | const char *fmt; | |
6378 | int likely = 0; | |
6379 | int dbl = 0; | |
6380 | int coproc = 0; | |
6381 | int lr = 0; | |
6382 | int imm = 0; | |
6383 | int off; | |
6384 | offsetT maxnum; | |
6385 | bfd_reloc_code_real_type r; | |
6386 | char *p; | |
bdaaa2e1 | 6387 | |
252b5132 RH |
6388 | treg = (ip->insn_opcode >> 16) & 0x1f; |
6389 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
6390 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
6391 | mask = ip->insn_mo->mask; | |
bdaaa2e1 | 6392 | |
252b5132 RH |
6393 | expr1.X_op = O_constant; |
6394 | expr1.X_op_symbol = NULL; | |
6395 | expr1.X_add_symbol = NULL; | |
6396 | expr1.X_add_number = 1; | |
bdaaa2e1 | 6397 | |
252b5132 RH |
6398 | switch (mask) |
6399 | { | |
6400 | #endif /* LOSING_COMPILER */ | |
6401 | ||
6402 | case M_DMUL: | |
6403 | dbl = 1; | |
6404 | case M_MUL: | |
6405 | macro_build ((char *) NULL, &icnt, NULL, | |
6406 | dbl ? "dmultu" : "multu", | |
6407 | "s,t", sreg, treg); | |
6408 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6409 | return; | |
6410 | ||
6411 | case M_DMUL_I: | |
6412 | dbl = 1; | |
6413 | case M_MUL_I: | |
6414 | /* The MIPS assembler some times generates shifts and adds. I'm | |
6415 | not trying to be that fancy. GCC should do this for us | |
6416 | anyway. */ | |
6417 | load_register (&icnt, AT, &imm_expr, dbl); | |
6418 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 6419 | dbl ? "dmult" : "mult", "s,t", sreg, AT); |
252b5132 RH |
6420 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); |
6421 | break; | |
6422 | ||
6423 | case M_DMULO_I: | |
6424 | dbl = 1; | |
6425 | case M_MULO_I: | |
6426 | imm = 1; | |
6427 | goto do_mulo; | |
6428 | ||
6429 | case M_DMULO: | |
6430 | dbl = 1; | |
6431 | case M_MULO: | |
6432 | do_mulo: | |
6433 | mips_emit_delays (true); | |
6434 | ++mips_opts.noreorder; | |
6435 | mips_any_noreorder = 1; | |
6436 | if (imm) | |
6437 | load_register (&icnt, AT, &imm_expr, dbl); | |
6438 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 6439 | dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg); |
252b5132 RH |
6440 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); |
6441 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 6442 | dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, 31); |
252b5132 RH |
6443 | macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT); |
6444 | if (mips_trap) | |
6445 | macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", dreg, AT); | |
6446 | else | |
6447 | { | |
6448 | expr1.X_add_number = 8; | |
6449 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT); | |
6450 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
beae10d5 | 6451 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); |
252b5132 RH |
6452 | } |
6453 | --mips_opts.noreorder; | |
6454 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6455 | break; | |
6456 | ||
6457 | case M_DMULOU_I: | |
6458 | dbl = 1; | |
6459 | case M_MULOU_I: | |
6460 | imm = 1; | |
6461 | goto do_mulou; | |
6462 | ||
6463 | case M_DMULOU: | |
6464 | dbl = 1; | |
6465 | case M_MULOU: | |
6466 | do_mulou: | |
6467 | mips_emit_delays (true); | |
6468 | ++mips_opts.noreorder; | |
6469 | mips_any_noreorder = 1; | |
6470 | if (imm) | |
6471 | load_register (&icnt, AT, &imm_expr, dbl); | |
6472 | macro_build ((char *) NULL, &icnt, NULL, | |
6473 | dbl ? "dmultu" : "multu", | |
6474 | "s,t", sreg, imm ? AT : treg); | |
6475 | macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT); | |
6476 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6477 | if (mips_trap) | |
6478 | macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", AT, 0); | |
6479 | else | |
6480 | { | |
6481 | expr1.X_add_number = 8; | |
6482 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0); | |
6483 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
beae10d5 | 6484 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); |
252b5132 RH |
6485 | } |
6486 | --mips_opts.noreorder; | |
6487 | break; | |
6488 | ||
6489 | case M_ROL: | |
6490 | macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg); | |
6491 | macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT); | |
6492 | macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg, | |
6493 | treg); | |
6494 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6495 | break; | |
6496 | ||
6497 | case M_ROL_I: | |
6498 | if (imm_expr.X_op != O_constant) | |
6499 | as_bad (_("rotate count too large")); | |
6500 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg, | |
6501 | (int) (imm_expr.X_add_number & 0x1f)); | |
6502 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, | |
6503 | (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6504 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6505 | break; | |
6506 | ||
6507 | case M_ROR: | |
6508 | macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg); | |
6509 | macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT); | |
6510 | macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg, | |
6511 | treg); | |
6512 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6513 | break; | |
6514 | ||
6515 | case M_ROR_I: | |
6516 | if (imm_expr.X_op != O_constant) | |
6517 | as_bad (_("rotate count too large")); | |
6518 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg, | |
6519 | (int) (imm_expr.X_add_number & 0x1f)); | |
6520 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg, | |
6521 | (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6522 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6523 | break; | |
6524 | ||
6525 | case M_S_DOB: | |
ec68c924 | 6526 | if (mips_arch == CPU_R4650) |
252b5132 RH |
6527 | { |
6528 | as_bad (_("opcode not supported on this processor")); | |
6529 | return; | |
6530 | } | |
e7af610e | 6531 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
6532 | /* Even on a big endian machine $fn comes before $fn+1. We have |
6533 | to adjust when storing to memory. */ | |
6534 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6535 | target_big_endian ? treg + 1 : treg, | |
6536 | (int) BFD_RELOC_LO16, breg); | |
6537 | offset_expr.X_add_number += 4; | |
6538 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6539 | target_big_endian ? treg : treg + 1, | |
6540 | (int) BFD_RELOC_LO16, breg); | |
6541 | return; | |
6542 | ||
6543 | case M_SEQ: | |
6544 | if (sreg == 0) | |
6545 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6546 | treg, (int) BFD_RELOC_LO16); | |
6547 | else if (treg == 0) | |
6548 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6549 | sreg, (int) BFD_RELOC_LO16); | |
6550 | else | |
6551 | { | |
6552 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6553 | sreg, treg); | |
6554 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6555 | dreg, (int) BFD_RELOC_LO16); | |
6556 | } | |
6557 | return; | |
6558 | ||
6559 | case M_SEQ_I: | |
6560 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6561 | { | |
6562 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6563 | sreg, (int) BFD_RELOC_LO16); | |
6564 | return; | |
6565 | } | |
6566 | if (sreg == 0) | |
6567 | { | |
6568 | as_warn (_("Instruction %s: result is always false"), | |
6569 | ip->insn_mo->name); | |
ea1fb5dc | 6570 | move_register (&icnt, dreg, 0); |
252b5132 RH |
6571 | return; |
6572 | } | |
6573 | if (imm_expr.X_op == O_constant | |
6574 | && imm_expr.X_add_number >= 0 | |
6575 | && imm_expr.X_add_number < 0x10000) | |
6576 | { | |
6577 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, | |
6578 | sreg, (int) BFD_RELOC_LO16); | |
6579 | used_at = 0; | |
6580 | } | |
6581 | else if (imm_expr.X_op == O_constant | |
6582 | && imm_expr.X_add_number > -0x8000 | |
6583 | && imm_expr.X_add_number < 0) | |
6584 | { | |
6585 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6586 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
ca4e0257 | 6587 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6588 | "t,r,j", dreg, sreg, |
6589 | (int) BFD_RELOC_LO16); | |
6590 | used_at = 0; | |
6591 | } | |
6592 | else | |
6593 | { | |
6594 | load_register (&icnt, AT, &imm_expr, 0); | |
6595 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6596 | sreg, AT); | |
6597 | used_at = 1; | |
6598 | } | |
6599 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg, | |
6600 | (int) BFD_RELOC_LO16); | |
6601 | if (used_at) | |
6602 | break; | |
6603 | return; | |
6604 | ||
6605 | case M_SGE: /* sreg >= treg <==> not (sreg < treg) */ | |
6606 | s = "slt"; | |
6607 | goto sge; | |
6608 | case M_SGEU: | |
6609 | s = "sltu"; | |
6610 | sge: | |
6611 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg); | |
6612 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6613 | (int) BFD_RELOC_LO16); | |
6614 | return; | |
6615 | ||
6616 | case M_SGE_I: /* sreg >= I <==> not (sreg < I) */ | |
6617 | case M_SGEU_I: | |
6618 | if (imm_expr.X_op == O_constant | |
6619 | && imm_expr.X_add_number >= -0x8000 | |
6620 | && imm_expr.X_add_number < 0x8000) | |
6621 | { | |
6622 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6623 | mask == M_SGE_I ? "slti" : "sltiu", | |
6624 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6625 | used_at = 0; | |
6626 | } | |
6627 | else | |
6628 | { | |
6629 | load_register (&icnt, AT, &imm_expr, 0); | |
6630 | macro_build ((char *) NULL, &icnt, NULL, | |
6631 | mask == M_SGE_I ? "slt" : "sltu", | |
6632 | "d,v,t", dreg, sreg, AT); | |
6633 | used_at = 1; | |
6634 | } | |
6635 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6636 | (int) BFD_RELOC_LO16); | |
6637 | if (used_at) | |
6638 | break; | |
6639 | return; | |
6640 | ||
6641 | case M_SGT: /* sreg > treg <==> treg < sreg */ | |
6642 | s = "slt"; | |
6643 | goto sgt; | |
6644 | case M_SGTU: | |
6645 | s = "sltu"; | |
6646 | sgt: | |
6647 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg); | |
6648 | return; | |
6649 | ||
6650 | case M_SGT_I: /* sreg > I <==> I < sreg */ | |
6651 | s = "slt"; | |
6652 | goto sgti; | |
6653 | case M_SGTU_I: | |
6654 | s = "sltu"; | |
6655 | sgti: | |
6656 | load_register (&icnt, AT, &imm_expr, 0); | |
6657 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg); | |
6658 | break; | |
6659 | ||
6660 | case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */ | |
6661 | s = "slt"; | |
6662 | goto sle; | |
6663 | case M_SLEU: | |
6664 | s = "sltu"; | |
6665 | sle: | |
6666 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg); | |
6667 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6668 | (int) BFD_RELOC_LO16); | |
6669 | return; | |
6670 | ||
6671 | case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */ | |
6672 | s = "slt"; | |
6673 | goto slei; | |
6674 | case M_SLEU_I: | |
6675 | s = "sltu"; | |
6676 | slei: | |
6677 | load_register (&icnt, AT, &imm_expr, 0); | |
6678 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg); | |
6679 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6680 | (int) BFD_RELOC_LO16); | |
6681 | break; | |
6682 | ||
6683 | case M_SLT_I: | |
6684 | if (imm_expr.X_op == O_constant | |
6685 | && imm_expr.X_add_number >= -0x8000 | |
6686 | && imm_expr.X_add_number < 0x8000) | |
6687 | { | |
6688 | macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j", | |
6689 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6690 | return; | |
6691 | } | |
6692 | load_register (&icnt, AT, &imm_expr, 0); | |
6693 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT); | |
6694 | break; | |
6695 | ||
6696 | case M_SLTU_I: | |
6697 | if (imm_expr.X_op == O_constant | |
6698 | && imm_expr.X_add_number >= -0x8000 | |
6699 | && imm_expr.X_add_number < 0x8000) | |
6700 | { | |
6701 | macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j", | |
6702 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6703 | return; | |
6704 | } | |
6705 | load_register (&icnt, AT, &imm_expr, 0); | |
6706 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg, | |
6707 | AT); | |
6708 | break; | |
6709 | ||
6710 | case M_SNE: | |
6711 | if (sreg == 0) | |
6712 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6713 | treg); | |
6714 | else if (treg == 0) | |
6715 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6716 | sreg); | |
6717 | else | |
6718 | { | |
6719 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6720 | sreg, treg); | |
6721 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6722 | dreg); | |
6723 | } | |
6724 | return; | |
6725 | ||
6726 | case M_SNE_I: | |
6727 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6728 | { | |
6729 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6730 | sreg); | |
6731 | return; | |
6732 | } | |
6733 | if (sreg == 0) | |
6734 | { | |
6735 | as_warn (_("Instruction %s: result is always true"), | |
6736 | ip->insn_mo->name); | |
6737 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 6738 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6739 | "t,r,j", dreg, 0, (int) BFD_RELOC_LO16); |
6740 | return; | |
6741 | } | |
6742 | if (imm_expr.X_op == O_constant | |
6743 | && imm_expr.X_add_number >= 0 | |
6744 | && imm_expr.X_add_number < 0x10000) | |
6745 | { | |
6746 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", | |
6747 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6748 | used_at = 0; | |
6749 | } | |
6750 | else if (imm_expr.X_op == O_constant | |
6751 | && imm_expr.X_add_number > -0x8000 | |
6752 | && imm_expr.X_add_number < 0) | |
6753 | { | |
6754 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6755 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
ca4e0257 | 6756 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
6757 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); |
6758 | used_at = 0; | |
6759 | } | |
6760 | else | |
6761 | { | |
6762 | load_register (&icnt, AT, &imm_expr, 0); | |
6763 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6764 | sreg, AT); | |
6765 | used_at = 1; | |
6766 | } | |
6767 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg); | |
6768 | if (used_at) | |
6769 | break; | |
6770 | return; | |
6771 | ||
6772 | case M_DSUB_I: | |
6773 | dbl = 1; | |
6774 | case M_SUB_I: | |
6775 | if (imm_expr.X_op == O_constant | |
6776 | && imm_expr.X_add_number > -0x8000 | |
6777 | && imm_expr.X_add_number <= 0x8000) | |
6778 | { | |
6779 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6780 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6781 | dbl ? "daddi" : "addi", | |
6782 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6783 | return; | |
6784 | } | |
6785 | load_register (&icnt, AT, &imm_expr, dbl); | |
6786 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 6787 | dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT); |
252b5132 RH |
6788 | break; |
6789 | ||
6790 | case M_DSUBU_I: | |
6791 | dbl = 1; | |
6792 | case M_SUBU_I: | |
6793 | if (imm_expr.X_op == O_constant | |
6794 | && imm_expr.X_add_number > -0x8000 | |
6795 | && imm_expr.X_add_number <= 0x8000) | |
6796 | { | |
6797 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6798 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6799 | dbl ? "daddiu" : "addiu", | |
6800 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6801 | return; | |
6802 | } | |
6803 | load_register (&icnt, AT, &imm_expr, dbl); | |
6804 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 6805 | dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT); |
252b5132 RH |
6806 | break; |
6807 | ||
6808 | case M_TEQ_I: | |
6809 | s = "teq"; | |
6810 | goto trap; | |
6811 | case M_TGE_I: | |
6812 | s = "tge"; | |
6813 | goto trap; | |
6814 | case M_TGEU_I: | |
6815 | s = "tgeu"; | |
6816 | goto trap; | |
6817 | case M_TLT_I: | |
6818 | s = "tlt"; | |
6819 | goto trap; | |
6820 | case M_TLTU_I: | |
6821 | s = "tltu"; | |
6822 | goto trap; | |
6823 | case M_TNE_I: | |
6824 | s = "tne"; | |
6825 | trap: | |
6826 | load_register (&icnt, AT, &imm_expr, 0); | |
6827 | macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT); | |
6828 | break; | |
6829 | ||
252b5132 | 6830 | case M_TRUNCWS: |
43841e91 | 6831 | case M_TRUNCWD: |
e7af610e | 6832 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
6833 | sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */ |
6834 | dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */ | |
6835 | ||
6836 | /* | |
6837 | * Is the double cfc1 instruction a bug in the mips assembler; | |
6838 | * or is there a reason for it? | |
6839 | */ | |
6840 | mips_emit_delays (true); | |
6841 | ++mips_opts.noreorder; | |
6842 | mips_any_noreorder = 1; | |
6843 | macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31); | |
6844 | macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31); | |
6845 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6846 | expr1.X_add_number = 3; | |
6847 | macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg, | |
6848 | (int) BFD_RELOC_LO16); | |
6849 | expr1.X_add_number = 2; | |
6850 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT, | |
6851 | (int) BFD_RELOC_LO16); | |
6852 | macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31); | |
6853 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6854 | macro_build ((char *) NULL, &icnt, NULL, | |
6855 | mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg); | |
6856 | macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31); | |
6857 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6858 | --mips_opts.noreorder; | |
6859 | break; | |
6860 | ||
6861 | case M_ULH: | |
6862 | s = "lb"; | |
6863 | goto ulh; | |
6864 | case M_ULHU: | |
6865 | s = "lbu"; | |
6866 | ulh: | |
6867 | if (offset_expr.X_add_number >= 0x7fff) | |
6868 | as_bad (_("operand overflow")); | |
6869 | /* avoid load delay */ | |
6870 | if (! target_big_endian) | |
6871 | offset_expr.X_add_number += 1; | |
6872 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6873 | (int) BFD_RELOC_LO16, breg); | |
6874 | if (! target_big_endian) | |
6875 | offset_expr.X_add_number -= 1; | |
6876 | else | |
6877 | offset_expr.X_add_number += 1; | |
6878 | macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT, | |
6879 | (int) BFD_RELOC_LO16, breg); | |
6880 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8); | |
6881 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT); | |
6882 | break; | |
6883 | ||
6884 | case M_ULD: | |
6885 | s = "ldl"; | |
6886 | s2 = "ldr"; | |
6887 | off = 7; | |
6888 | goto ulw; | |
6889 | case M_ULW: | |
6890 | s = "lwl"; | |
6891 | s2 = "lwr"; | |
6892 | off = 3; | |
6893 | ulw: | |
6894 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6895 | as_bad (_("operand overflow")); | |
6896 | if (! target_big_endian) | |
6897 | offset_expr.X_add_number += off; | |
6898 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6899 | (int) BFD_RELOC_LO16, breg); | |
6900 | if (! target_big_endian) | |
6901 | offset_expr.X_add_number -= off; | |
6902 | else | |
6903 | offset_expr.X_add_number += off; | |
6904 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
6905 | (int) BFD_RELOC_LO16, breg); | |
6906 | return; | |
6907 | ||
6908 | case M_ULD_A: | |
6909 | s = "ldl"; | |
6910 | s2 = "ldr"; | |
6911 | off = 7; | |
6912 | goto ulwa; | |
6913 | case M_ULW_A: | |
6914 | s = "lwl"; | |
6915 | s2 = "lwr"; | |
6916 | off = 3; | |
6917 | ulwa: | |
d6bc6245 TS |
6918 | used_at = 1; |
6919 | load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at); | |
252b5132 RH |
6920 | if (breg != 0) |
6921 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6922 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6923 | "d,v,t", AT, AT, breg); |
6924 | if (! target_big_endian) | |
6925 | expr1.X_add_number = off; | |
6926 | else | |
6927 | expr1.X_add_number = 0; | |
6928 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
6929 | (int) BFD_RELOC_LO16, AT); | |
6930 | if (! target_big_endian) | |
6931 | expr1.X_add_number = 0; | |
6932 | else | |
6933 | expr1.X_add_number = off; | |
6934 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
6935 | (int) BFD_RELOC_LO16, AT); | |
6936 | break; | |
6937 | ||
6938 | case M_ULH_A: | |
6939 | case M_ULHU_A: | |
d6bc6245 TS |
6940 | used_at = 1; |
6941 | load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at); | |
252b5132 RH |
6942 | if (breg != 0) |
6943 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6944 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6945 | "d,v,t", AT, AT, breg); |
6946 | if (target_big_endian) | |
6947 | expr1.X_add_number = 0; | |
6948 | macro_build ((char *) NULL, &icnt, &expr1, | |
6949 | mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg, | |
6950 | (int) BFD_RELOC_LO16, AT); | |
6951 | if (target_big_endian) | |
6952 | expr1.X_add_number = 1; | |
6953 | else | |
6954 | expr1.X_add_number = 0; | |
6955 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
6956 | (int) BFD_RELOC_LO16, AT); | |
6957 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, | |
6958 | treg, 8); | |
6959 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, | |
6960 | treg, AT); | |
6961 | break; | |
6962 | ||
6963 | case M_USH: | |
6964 | if (offset_expr.X_add_number >= 0x7fff) | |
6965 | as_bad (_("operand overflow")); | |
6966 | if (target_big_endian) | |
6967 | offset_expr.X_add_number += 1; | |
6968 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg, | |
6969 | (int) BFD_RELOC_LO16, breg); | |
6970 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8); | |
6971 | if (target_big_endian) | |
6972 | offset_expr.X_add_number -= 1; | |
6973 | else | |
6974 | offset_expr.X_add_number += 1; | |
6975 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT, | |
6976 | (int) BFD_RELOC_LO16, breg); | |
6977 | break; | |
6978 | ||
6979 | case M_USD: | |
6980 | s = "sdl"; | |
6981 | s2 = "sdr"; | |
6982 | off = 7; | |
6983 | goto usw; | |
6984 | case M_USW: | |
6985 | s = "swl"; | |
6986 | s2 = "swr"; | |
6987 | off = 3; | |
6988 | usw: | |
6989 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6990 | as_bad (_("operand overflow")); | |
6991 | if (! target_big_endian) | |
6992 | offset_expr.X_add_number += off; | |
6993 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6994 | (int) BFD_RELOC_LO16, breg); | |
6995 | if (! target_big_endian) | |
6996 | offset_expr.X_add_number -= off; | |
6997 | else | |
6998 | offset_expr.X_add_number += off; | |
6999 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
7000 | (int) BFD_RELOC_LO16, breg); | |
7001 | return; | |
7002 | ||
7003 | case M_USD_A: | |
7004 | s = "sdl"; | |
7005 | s2 = "sdr"; | |
7006 | off = 7; | |
7007 | goto uswa; | |
7008 | case M_USW_A: | |
7009 | s = "swl"; | |
7010 | s2 = "swr"; | |
7011 | off = 3; | |
7012 | uswa: | |
d6bc6245 TS |
7013 | used_at = 1; |
7014 | load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at); | |
252b5132 RH |
7015 | if (breg != 0) |
7016 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7017 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7018 | "d,v,t", AT, AT, breg); |
7019 | if (! target_big_endian) | |
7020 | expr1.X_add_number = off; | |
7021 | else | |
7022 | expr1.X_add_number = 0; | |
7023 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
7024 | (int) BFD_RELOC_LO16, AT); | |
7025 | if (! target_big_endian) | |
7026 | expr1.X_add_number = 0; | |
7027 | else | |
7028 | expr1.X_add_number = off; | |
7029 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
7030 | (int) BFD_RELOC_LO16, AT); | |
7031 | break; | |
7032 | ||
7033 | case M_USH_A: | |
d6bc6245 TS |
7034 | used_at = 1; |
7035 | load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at); | |
252b5132 RH |
7036 | if (breg != 0) |
7037 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7038 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7039 | "d,v,t", AT, AT, breg); |
7040 | if (! target_big_endian) | |
7041 | expr1.X_add_number = 0; | |
7042 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
7043 | (int) BFD_RELOC_LO16, AT); | |
7044 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg, | |
7045 | treg, 8); | |
7046 | if (! target_big_endian) | |
7047 | expr1.X_add_number = 1; | |
7048 | else | |
7049 | expr1.X_add_number = 0; | |
7050 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
7051 | (int) BFD_RELOC_LO16, AT); | |
7052 | if (! target_big_endian) | |
7053 | expr1.X_add_number = 0; | |
7054 | else | |
7055 | expr1.X_add_number = 1; | |
7056 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
7057 | (int) BFD_RELOC_LO16, AT); | |
7058 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, | |
7059 | treg, 8); | |
7060 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, | |
7061 | treg, AT); | |
7062 | break; | |
7063 | ||
7064 | default: | |
7065 | /* FIXME: Check if this is one of the itbl macros, since they | |
bdaaa2e1 | 7066 | are added dynamically. */ |
252b5132 RH |
7067 | as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name); |
7068 | break; | |
7069 | } | |
7070 | if (mips_opts.noat) | |
7071 | as_warn (_("Macro used $at after \".set noat\"")); | |
7072 | } | |
7073 | ||
7074 | /* Implement macros in mips16 mode. */ | |
7075 | ||
7076 | static void | |
7077 | mips16_macro (ip) | |
7078 | struct mips_cl_insn *ip; | |
7079 | { | |
7080 | int mask; | |
7081 | int xreg, yreg, zreg, tmp; | |
7082 | int icnt; | |
7083 | expressionS expr1; | |
7084 | int dbl; | |
7085 | const char *s, *s2, *s3; | |
7086 | ||
7087 | mask = ip->insn_mo->mask; | |
7088 | ||
7089 | xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX; | |
7090 | yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY; | |
7091 | zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ; | |
7092 | ||
7093 | icnt = 0; | |
7094 | ||
7095 | expr1.X_op = O_constant; | |
7096 | expr1.X_op_symbol = NULL; | |
7097 | expr1.X_add_symbol = NULL; | |
7098 | expr1.X_add_number = 1; | |
7099 | ||
7100 | dbl = 0; | |
7101 | ||
7102 | switch (mask) | |
7103 | { | |
7104 | default: | |
7105 | internalError (); | |
7106 | ||
7107 | case M_DDIV_3: | |
7108 | dbl = 1; | |
7109 | case M_DIV_3: | |
7110 | s = "mflo"; | |
7111 | goto do_div3; | |
7112 | case M_DREM_3: | |
7113 | dbl = 1; | |
7114 | case M_REM_3: | |
7115 | s = "mfhi"; | |
7116 | do_div3: | |
7117 | mips_emit_delays (true); | |
7118 | ++mips_opts.noreorder; | |
7119 | mips_any_noreorder = 1; | |
7120 | macro_build ((char *) NULL, &icnt, NULL, | |
7121 | dbl ? "ddiv" : "div", | |
7122 | "0,x,y", xreg, yreg); | |
7123 | expr1.X_add_number = 2; | |
7124 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
beae10d5 | 7125 | macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7); |
bdaaa2e1 | 7126 | |
252b5132 RH |
7127 | /* FIXME: The normal code checks for of -1 / -0x80000000 here, |
7128 | since that causes an overflow. We should do that as well, | |
7129 | but I don't see how to do the comparisons without a temporary | |
7130 | register. */ | |
7131 | --mips_opts.noreorder; | |
7132 | macro_build ((char *) NULL, &icnt, NULL, s, "x", zreg); | |
7133 | break; | |
7134 | ||
7135 | case M_DIVU_3: | |
7136 | s = "divu"; | |
7137 | s2 = "mflo"; | |
7138 | goto do_divu3; | |
7139 | case M_REMU_3: | |
7140 | s = "divu"; | |
7141 | s2 = "mfhi"; | |
7142 | goto do_divu3; | |
7143 | case M_DDIVU_3: | |
7144 | s = "ddivu"; | |
7145 | s2 = "mflo"; | |
7146 | goto do_divu3; | |
7147 | case M_DREMU_3: | |
7148 | s = "ddivu"; | |
7149 | s2 = "mfhi"; | |
7150 | do_divu3: | |
7151 | mips_emit_delays (true); | |
7152 | ++mips_opts.noreorder; | |
7153 | mips_any_noreorder = 1; | |
7154 | macro_build ((char *) NULL, &icnt, NULL, s, "0,x,y", xreg, yreg); | |
7155 | expr1.X_add_number = 2; | |
7156 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
7157 | macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7); | |
7158 | --mips_opts.noreorder; | |
7159 | macro_build ((char *) NULL, &icnt, NULL, s2, "x", zreg); | |
7160 | break; | |
7161 | ||
7162 | case M_DMUL: | |
7163 | dbl = 1; | |
7164 | case M_MUL: | |
7165 | macro_build ((char *) NULL, &icnt, NULL, | |
9a41af64 | 7166 | dbl ? "dmultu" : "multu", "x,y", xreg, yreg); |
252b5132 RH |
7167 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "x", zreg); |
7168 | return; | |
7169 | ||
7170 | case M_DSUBU_I: | |
7171 | dbl = 1; | |
7172 | goto do_subu; | |
7173 | case M_SUBU_I: | |
7174 | do_subu: | |
7175 | if (imm_expr.X_op != O_constant) | |
7176 | as_bad (_("Unsupported large constant")); | |
7177 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7178 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
9a41af64 | 7179 | dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg); |
252b5132 RH |
7180 | break; |
7181 | ||
7182 | case M_SUBU_I_2: | |
7183 | if (imm_expr.X_op != O_constant) | |
7184 | as_bad (_("Unsupported large constant")); | |
7185 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7186 | macro_build ((char *) NULL, &icnt, &imm_expr, "addiu", | |
7187 | "x,k", xreg); | |
7188 | break; | |
7189 | ||
7190 | case M_DSUBU_I_2: | |
7191 | if (imm_expr.X_op != O_constant) | |
7192 | as_bad (_("Unsupported large constant")); | |
7193 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7194 | macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu", | |
7195 | "y,j", yreg); | |
7196 | break; | |
7197 | ||
7198 | case M_BEQ: | |
7199 | s = "cmp"; | |
7200 | s2 = "bteqz"; | |
7201 | goto do_branch; | |
7202 | case M_BNE: | |
7203 | s = "cmp"; | |
7204 | s2 = "btnez"; | |
7205 | goto do_branch; | |
7206 | case M_BLT: | |
7207 | s = "slt"; | |
7208 | s2 = "btnez"; | |
7209 | goto do_branch; | |
7210 | case M_BLTU: | |
7211 | s = "sltu"; | |
7212 | s2 = "btnez"; | |
7213 | goto do_branch; | |
7214 | case M_BLE: | |
7215 | s = "slt"; | |
7216 | s2 = "bteqz"; | |
7217 | goto do_reverse_branch; | |
7218 | case M_BLEU: | |
7219 | s = "sltu"; | |
7220 | s2 = "bteqz"; | |
7221 | goto do_reverse_branch; | |
7222 | case M_BGE: | |
7223 | s = "slt"; | |
7224 | s2 = "bteqz"; | |
7225 | goto do_branch; | |
7226 | case M_BGEU: | |
7227 | s = "sltu"; | |
7228 | s2 = "bteqz"; | |
7229 | goto do_branch; | |
7230 | case M_BGT: | |
7231 | s = "slt"; | |
7232 | s2 = "btnez"; | |
7233 | goto do_reverse_branch; | |
7234 | case M_BGTU: | |
7235 | s = "sltu"; | |
7236 | s2 = "btnez"; | |
7237 | ||
7238 | do_reverse_branch: | |
7239 | tmp = xreg; | |
7240 | xreg = yreg; | |
7241 | yreg = tmp; | |
7242 | ||
7243 | do_branch: | |
7244 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y", | |
7245 | xreg, yreg); | |
7246 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
7247 | break; | |
7248 | ||
7249 | case M_BEQ_I: | |
7250 | s = "cmpi"; | |
7251 | s2 = "bteqz"; | |
7252 | s3 = "x,U"; | |
7253 | goto do_branch_i; | |
7254 | case M_BNE_I: | |
7255 | s = "cmpi"; | |
7256 | s2 = "btnez"; | |
7257 | s3 = "x,U"; | |
7258 | goto do_branch_i; | |
7259 | case M_BLT_I: | |
7260 | s = "slti"; | |
7261 | s2 = "btnez"; | |
7262 | s3 = "x,8"; | |
7263 | goto do_branch_i; | |
7264 | case M_BLTU_I: | |
7265 | s = "sltiu"; | |
7266 | s2 = "btnez"; | |
7267 | s3 = "x,8"; | |
7268 | goto do_branch_i; | |
7269 | case M_BLE_I: | |
7270 | s = "slti"; | |
7271 | s2 = "btnez"; | |
7272 | s3 = "x,8"; | |
7273 | goto do_addone_branch_i; | |
7274 | case M_BLEU_I: | |
7275 | s = "sltiu"; | |
7276 | s2 = "btnez"; | |
7277 | s3 = "x,8"; | |
7278 | goto do_addone_branch_i; | |
7279 | case M_BGE_I: | |
7280 | s = "slti"; | |
7281 | s2 = "bteqz"; | |
7282 | s3 = "x,8"; | |
7283 | goto do_branch_i; | |
7284 | case M_BGEU_I: | |
7285 | s = "sltiu"; | |
7286 | s2 = "bteqz"; | |
7287 | s3 = "x,8"; | |
7288 | goto do_branch_i; | |
7289 | case M_BGT_I: | |
7290 | s = "slti"; | |
7291 | s2 = "bteqz"; | |
7292 | s3 = "x,8"; | |
7293 | goto do_addone_branch_i; | |
7294 | case M_BGTU_I: | |
7295 | s = "sltiu"; | |
7296 | s2 = "bteqz"; | |
7297 | s3 = "x,8"; | |
7298 | ||
7299 | do_addone_branch_i: | |
7300 | if (imm_expr.X_op != O_constant) | |
7301 | as_bad (_("Unsupported large constant")); | |
7302 | ++imm_expr.X_add_number; | |
7303 | ||
7304 | do_branch_i: | |
7305 | macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg); | |
7306 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
7307 | break; | |
7308 | ||
7309 | case M_ABS: | |
7310 | expr1.X_add_number = 0; | |
7311 | macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg); | |
7312 | if (xreg != yreg) | |
ea1fb5dc | 7313 | move_register (&icnt, xreg, yreg); |
252b5132 RH |
7314 | expr1.X_add_number = 2; |
7315 | macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p"); | |
7316 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
7317 | "neg", "x,w", xreg, xreg); | |
7318 | } | |
7319 | } | |
7320 | ||
7321 | /* For consistency checking, verify that all bits are specified either | |
7322 | by the match/mask part of the instruction definition, or by the | |
7323 | operand list. */ | |
7324 | static int | |
7325 | validate_mips_insn (opc) | |
7326 | const struct mips_opcode *opc; | |
7327 | { | |
7328 | const char *p = opc->args; | |
7329 | char c; | |
7330 | unsigned long used_bits = opc->mask; | |
7331 | ||
7332 | if ((used_bits & opc->match) != opc->match) | |
7333 | { | |
7334 | as_bad (_("internal: bad mips opcode (mask error): %s %s"), | |
7335 | opc->name, opc->args); | |
7336 | return 0; | |
7337 | } | |
7338 | #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift))) | |
7339 | while (*p) | |
7340 | switch (c = *p++) | |
7341 | { | |
7342 | case ',': break; | |
7343 | case '(': break; | |
7344 | case ')': break; | |
7345 | case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
7346 | case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
7347 | case 'A': break; | |
4372b673 | 7348 | case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break; |
252b5132 RH |
7349 | case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break; |
7350 | case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break; | |
7351 | case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7352 | case 'F': break; | |
7353 | case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
156c2f8b | 7354 | case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
252b5132 | 7355 | case 'I': break; |
e972090a | 7356 | case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break; |
252b5132 RH |
7357 | case 'L': break; |
7358 | case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break; | |
7359 | case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break; | |
7360 | case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break; | |
7361 | case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
7362 | case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
7363 | case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
7364 | case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
7365 | case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break; | |
7366 | case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7367 | case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break; | |
7368 | case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
7369 | case 'f': break; | |
7370 | case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break; | |
7371 | case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
7372 | case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7373 | case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break; | |
7374 | case 'l': break; | |
7375 | case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7376 | case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7377 | case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break; | |
7378 | case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7379 | case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7380 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7381 | case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
7382 | case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7383 | case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7384 | case 'x': break; | |
7385 | case 'z': break; | |
7386 | case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break; | |
4372b673 NC |
7387 | case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD); |
7388 | USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
252b5132 RH |
7389 | default: |
7390 | as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"), | |
7391 | c, opc->name, opc->args); | |
7392 | return 0; | |
7393 | } | |
7394 | #undef USE_BITS | |
7395 | if (used_bits != 0xffffffff) | |
7396 | { | |
7397 | as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"), | |
7398 | ~used_bits & 0xffffffff, opc->name, opc->args); | |
7399 | return 0; | |
7400 | } | |
7401 | return 1; | |
7402 | } | |
7403 | ||
7404 | /* This routine assembles an instruction into its binary format. As a | |
7405 | side effect, it sets one of the global variables imm_reloc or | |
7406 | offset_reloc to the type of relocation to do if one of the operands | |
7407 | is an address expression. */ | |
7408 | ||
7409 | static void | |
7410 | mips_ip (str, ip) | |
7411 | char *str; | |
7412 | struct mips_cl_insn *ip; | |
7413 | { | |
7414 | char *s; | |
7415 | const char *args; | |
43841e91 | 7416 | char c = 0; |
252b5132 RH |
7417 | struct mips_opcode *insn; |
7418 | char *argsStart; | |
7419 | unsigned int regno; | |
7420 | unsigned int lastregno = 0; | |
7421 | char *s_reset; | |
7422 | char save_c = 0; | |
7423 | int full_opcode_match = 1; | |
7424 | ||
7425 | insn_error = NULL; | |
7426 | ||
7427 | /* If the instruction contains a '.', we first try to match an instruction | |
7428 | including the '.'. Then we try again without the '.'. */ | |
7429 | insn = NULL; | |
3882b010 | 7430 | for (s = str; *s != '\0' && !ISSPACE (*s); ++s) |
252b5132 RH |
7431 | continue; |
7432 | ||
7433 | /* If we stopped on whitespace, then replace the whitespace with null for | |
7434 | the call to hash_find. Save the character we replaced just in case we | |
7435 | have to re-parse the instruction. */ | |
3882b010 | 7436 | if (ISSPACE (*s)) |
252b5132 RH |
7437 | { |
7438 | save_c = *s; | |
7439 | *s++ = '\0'; | |
7440 | } | |
bdaaa2e1 | 7441 | |
252b5132 RH |
7442 | insn = (struct mips_opcode *) hash_find (op_hash, str); |
7443 | ||
7444 | /* If we didn't find the instruction in the opcode table, try again, but | |
7445 | this time with just the instruction up to, but not including the | |
7446 | first '.'. */ | |
7447 | if (insn == NULL) | |
7448 | { | |
bdaaa2e1 | 7449 | /* Restore the character we overwrite above (if any). */ |
252b5132 RH |
7450 | if (save_c) |
7451 | *(--s) = save_c; | |
7452 | ||
7453 | /* Scan up to the first '.' or whitespace. */ | |
3882b010 L |
7454 | for (s = str; |
7455 | *s != '\0' && *s != '.' && !ISSPACE (*s); | |
7456 | ++s) | |
252b5132 RH |
7457 | continue; |
7458 | ||
7459 | /* If we did not find a '.', then we can quit now. */ | |
7460 | if (*s != '.') | |
7461 | { | |
7462 | insn_error = "unrecognized opcode"; | |
7463 | return; | |
7464 | } | |
7465 | ||
7466 | /* Lookup the instruction in the hash table. */ | |
7467 | *s++ = '\0'; | |
7468 | if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL) | |
7469 | { | |
7470 | insn_error = "unrecognized opcode"; | |
7471 | return; | |
7472 | } | |
7473 | ||
7474 | full_opcode_match = 0; | |
7475 | } | |
7476 | ||
7477 | argsStart = s; | |
7478 | for (;;) | |
7479 | { | |
252b5132 RH |
7480 | boolean ok; |
7481 | ||
7482 | assert (strcmp (insn->name, str) == 0); | |
7483 | ||
ea1fb5dc | 7484 | if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_arch)) |
252b5132 | 7485 | ok = true; |
bdaaa2e1 | 7486 | else |
252b5132 | 7487 | ok = false; |
bdaaa2e1 | 7488 | |
252b5132 RH |
7489 | if (insn->pinfo != INSN_MACRO) |
7490 | { | |
ec68c924 | 7491 | if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0) |
252b5132 RH |
7492 | ok = false; |
7493 | } | |
7494 | ||
7495 | if (! ok) | |
7496 | { | |
7497 | if (insn + 1 < &mips_opcodes[NUMOPCODES] | |
7498 | && strcmp (insn->name, insn[1].name) == 0) | |
7499 | { | |
7500 | ++insn; | |
7501 | continue; | |
7502 | } | |
252b5132 | 7503 | else |
beae10d5 | 7504 | { |
268f6bed L |
7505 | if (!insn_error) |
7506 | { | |
7507 | static char buf[100]; | |
7508 | sprintf (buf, | |
7509 | _("opcode not supported on this processor: %s (%s)"), | |
ec68c924 | 7510 | mips_cpu_to_str (mips_arch), |
268f6bed | 7511 | mips_isa_to_str (mips_opts.isa)); |
bdaaa2e1 | 7512 | |
268f6bed L |
7513 | insn_error = buf; |
7514 | } | |
7515 | if (save_c) | |
7516 | *(--s) = save_c; | |
2bd7f1f3 | 7517 | return; |
252b5132 | 7518 | } |
252b5132 RH |
7519 | } |
7520 | ||
7521 | ip->insn_mo = insn; | |
7522 | ip->insn_opcode = insn->match; | |
268f6bed | 7523 | insn_error = NULL; |
252b5132 RH |
7524 | for (args = insn->args;; ++args) |
7525 | { | |
ad8d3bb3 | 7526 | s += strspn (s, " \t"); |
252b5132 RH |
7527 | switch (*args) |
7528 | { | |
7529 | case '\0': /* end of args */ | |
7530 | if (*s == '\0') | |
7531 | return; | |
7532 | break; | |
7533 | ||
7534 | case ',': | |
7535 | if (*s++ == *args) | |
7536 | continue; | |
7537 | s--; | |
7538 | switch (*++args) | |
7539 | { | |
7540 | case 'r': | |
7541 | case 'v': | |
38487616 | 7542 | ip->insn_opcode |= lastregno << OP_SH_RS; |
252b5132 RH |
7543 | continue; |
7544 | ||
7545 | case 'w': | |
38487616 TS |
7546 | ip->insn_opcode |= lastregno << OP_SH_RT; |
7547 | continue; | |
7548 | ||
252b5132 | 7549 | case 'W': |
38487616 | 7550 | ip->insn_opcode |= lastregno << OP_SH_FT; |
252b5132 RH |
7551 | continue; |
7552 | ||
7553 | case 'V': | |
38487616 | 7554 | ip->insn_opcode |= lastregno << OP_SH_FS; |
252b5132 RH |
7555 | continue; |
7556 | } | |
7557 | break; | |
7558 | ||
7559 | case '(': | |
7560 | /* Handle optional base register. | |
7561 | Either the base register is omitted or | |
bdaaa2e1 | 7562 | we must have a left paren. */ |
252b5132 RH |
7563 | /* This is dependent on the next operand specifier |
7564 | is a base register specification. */ | |
7565 | assert (args[1] == 'b' || args[1] == '5' | |
7566 | || args[1] == '-' || args[1] == '4'); | |
7567 | if (*s == '\0') | |
7568 | return; | |
7569 | ||
7570 | case ')': /* these must match exactly */ | |
7571 | if (*s++ == *args) | |
7572 | continue; | |
7573 | break; | |
7574 | ||
7575 | case '<': /* must be at least one digit */ | |
7576 | /* | |
7577 | * According to the manual, if the shift amount is greater | |
b6ff326e KH |
7578 | * than 31 or less than 0, then the shift amount should be |
7579 | * mod 32. In reality the mips assembler issues an error. | |
252b5132 RH |
7580 | * We issue a warning and mask out all but the low 5 bits. |
7581 | */ | |
7582 | my_getExpression (&imm_expr, s); | |
7583 | check_absolute_expr (ip, &imm_expr); | |
7584 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7585 | { | |
7586 | as_warn (_("Improper shift amount (%ld)"), | |
7587 | (long) imm_expr.X_add_number); | |
38487616 | 7588 | imm_expr.X_add_number &= OP_MASK_SHAMT; |
252b5132 | 7589 | } |
38487616 | 7590 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT; |
252b5132 RH |
7591 | imm_expr.X_op = O_absent; |
7592 | s = expr_end; | |
7593 | continue; | |
7594 | ||
7595 | case '>': /* shift amount minus 32 */ | |
7596 | my_getExpression (&imm_expr, s); | |
7597 | check_absolute_expr (ip, &imm_expr); | |
7598 | if ((unsigned long) imm_expr.X_add_number < 32 | |
7599 | || (unsigned long) imm_expr.X_add_number > 63) | |
7600 | break; | |
38487616 | 7601 | ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT; |
252b5132 RH |
7602 | imm_expr.X_op = O_absent; |
7603 | s = expr_end; | |
7604 | continue; | |
7605 | ||
252b5132 RH |
7606 | case 'k': /* cache code */ |
7607 | case 'h': /* prefx code */ | |
7608 | my_getExpression (&imm_expr, s); | |
7609 | check_absolute_expr (ip, &imm_expr); | |
7610 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7611 | { | |
7612 | as_warn (_("Invalid value for `%s' (%lu)"), | |
7613 | ip->insn_mo->name, | |
7614 | (unsigned long) imm_expr.X_add_number); | |
7615 | imm_expr.X_add_number &= 0x1f; | |
7616 | } | |
7617 | if (*args == 'k') | |
7618 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE; | |
7619 | else | |
7620 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX; | |
7621 | imm_expr.X_op = O_absent; | |
7622 | s = expr_end; | |
7623 | continue; | |
7624 | ||
7625 | case 'c': /* break code */ | |
7626 | my_getExpression (&imm_expr, s); | |
7627 | check_absolute_expr (ip, &imm_expr); | |
7628 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7629 | { | |
7630 | as_warn (_("Illegal break code (%ld)"), | |
7631 | (long) imm_expr.X_add_number); | |
38487616 | 7632 | imm_expr.X_add_number &= OP_MASK_CODE; |
252b5132 | 7633 | } |
38487616 | 7634 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE; |
252b5132 RH |
7635 | imm_expr.X_op = O_absent; |
7636 | s = expr_end; | |
7637 | continue; | |
7638 | ||
7639 | case 'q': /* lower break code */ | |
7640 | my_getExpression (&imm_expr, s); | |
7641 | check_absolute_expr (ip, &imm_expr); | |
7642 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7643 | { | |
7644 | as_warn (_("Illegal lower break code (%ld)"), | |
7645 | (long) imm_expr.X_add_number); | |
38487616 | 7646 | imm_expr.X_add_number &= OP_MASK_CODE2; |
252b5132 | 7647 | } |
38487616 | 7648 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2; |
252b5132 RH |
7649 | imm_expr.X_op = O_absent; |
7650 | s = expr_end; | |
7651 | continue; | |
7652 | ||
4372b673 | 7653 | case 'B': /* 20-bit syscall/break code. */ |
156c2f8b | 7654 | my_getExpression (&imm_expr, s); |
156c2f8b | 7655 | check_absolute_expr (ip, &imm_expr); |
38487616 | 7656 | if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE20) |
4372b673 | 7657 | as_warn (_("Illegal 20-bit code (%ld)"), |
252b5132 | 7658 | (long) imm_expr.X_add_number); |
38487616 | 7659 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20; |
252b5132 RH |
7660 | imm_expr.X_op = O_absent; |
7661 | s = expr_end; | |
7662 | continue; | |
7663 | ||
7664 | case 'C': /* Coprocessor code */ | |
beae10d5 | 7665 | my_getExpression (&imm_expr, s); |
252b5132 | 7666 | check_absolute_expr (ip, &imm_expr); |
beae10d5 | 7667 | if ((unsigned long) imm_expr.X_add_number >= (1<<25)) |
252b5132 | 7668 | { |
beae10d5 | 7669 | as_warn (_("Coproccesor code > 25 bits (%ld)"), |
252b5132 | 7670 | (long) imm_expr.X_add_number); |
beae10d5 | 7671 | imm_expr.X_add_number &= ((1<<25) - 1); |
252b5132 | 7672 | } |
beae10d5 KH |
7673 | ip->insn_opcode |= imm_expr.X_add_number; |
7674 | imm_expr.X_op = O_absent; | |
7675 | s = expr_end; | |
7676 | continue; | |
252b5132 | 7677 | |
4372b673 NC |
7678 | case 'J': /* 19-bit wait code. */ |
7679 | my_getExpression (&imm_expr, s); | |
7680 | check_absolute_expr (ip, &imm_expr); | |
38487616 | 7681 | if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE19) |
4372b673 NC |
7682 | as_warn (_("Illegal 19-bit code (%ld)"), |
7683 | (long) imm_expr.X_add_number); | |
38487616 | 7684 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19; |
4372b673 NC |
7685 | imm_expr.X_op = O_absent; |
7686 | s = expr_end; | |
7687 | continue; | |
7688 | ||
252b5132 | 7689 | case 'P': /* Performance register */ |
beae10d5 | 7690 | my_getExpression (&imm_expr, s); |
252b5132 | 7691 | check_absolute_expr (ip, &imm_expr); |
beae10d5 | 7692 | if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1) |
252b5132 | 7693 | { |
38487616 | 7694 | as_warn (_("Invalid performance register (%ld)"), |
252b5132 | 7695 | (long) imm_expr.X_add_number); |
38487616 | 7696 | imm_expr.X_add_number &= OP_MASK_PERFREG; |
252b5132 | 7697 | } |
38487616 | 7698 | ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG); |
beae10d5 KH |
7699 | imm_expr.X_op = O_absent; |
7700 | s = expr_end; | |
7701 | continue; | |
252b5132 RH |
7702 | |
7703 | case 'b': /* base register */ | |
7704 | case 'd': /* destination register */ | |
7705 | case 's': /* source register */ | |
7706 | case 't': /* target register */ | |
7707 | case 'r': /* both target and source */ | |
7708 | case 'v': /* both dest and source */ | |
7709 | case 'w': /* both dest and target */ | |
7710 | case 'E': /* coprocessor target register */ | |
7711 | case 'G': /* coprocessor destination register */ | |
7712 | case 'x': /* ignore register name */ | |
7713 | case 'z': /* must be zero register */ | |
4372b673 | 7714 | case 'U': /* destination register (clo/clz). */ |
252b5132 RH |
7715 | s_reset = s; |
7716 | if (s[0] == '$') | |
7717 | { | |
7718 | ||
3882b010 | 7719 | if (ISDIGIT (s[1])) |
252b5132 RH |
7720 | { |
7721 | ++s; | |
7722 | regno = 0; | |
7723 | do | |
7724 | { | |
7725 | regno *= 10; | |
7726 | regno += *s - '0'; | |
7727 | ++s; | |
7728 | } | |
3882b010 | 7729 | while (ISDIGIT (*s)); |
252b5132 RH |
7730 | if (regno > 31) |
7731 | as_bad (_("Invalid register number (%d)"), regno); | |
7732 | } | |
7733 | else if (*args == 'E' || *args == 'G') | |
7734 | goto notreg; | |
7735 | else | |
7736 | { | |
7737 | if (s[1] == 'f' && s[2] == 'p') | |
7738 | { | |
7739 | s += 3; | |
7740 | regno = FP; | |
7741 | } | |
7742 | else if (s[1] == 's' && s[2] == 'p') | |
7743 | { | |
7744 | s += 3; | |
7745 | regno = SP; | |
7746 | } | |
7747 | else if (s[1] == 'g' && s[2] == 'p') | |
7748 | { | |
7749 | s += 3; | |
7750 | regno = GP; | |
7751 | } | |
7752 | else if (s[1] == 'a' && s[2] == 't') | |
7753 | { | |
7754 | s += 3; | |
7755 | regno = AT; | |
7756 | } | |
7757 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
7758 | { | |
7759 | s += 4; | |
7760 | regno = KT0; | |
7761 | } | |
7762 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
7763 | { | |
7764 | s += 4; | |
7765 | regno = KT1; | |
7766 | } | |
7767 | else if (itbl_have_entries) | |
7768 | { | |
7769 | char *p, *n; | |
d7ba4a77 | 7770 | unsigned long r; |
252b5132 | 7771 | |
d7ba4a77 | 7772 | p = s + 1; /* advance past '$' */ |
252b5132 RH |
7773 | n = itbl_get_field (&p); /* n is name */ |
7774 | ||
d7ba4a77 ILT |
7775 | /* See if this is a register defined in an |
7776 | itbl entry. */ | |
7777 | if (itbl_get_reg_val (n, &r)) | |
252b5132 RH |
7778 | { |
7779 | /* Get_field advances to the start of | |
7780 | the next field, so we need to back | |
d7ba4a77 | 7781 | rack to the end of the last field. */ |
bdaaa2e1 | 7782 | if (p) |
252b5132 | 7783 | s = p - 1; |
bdaaa2e1 | 7784 | else |
d7ba4a77 | 7785 | s = strchr (s, '\0'); |
252b5132 RH |
7786 | regno = r; |
7787 | } | |
7788 | else | |
7789 | goto notreg; | |
beae10d5 | 7790 | } |
252b5132 RH |
7791 | else |
7792 | goto notreg; | |
7793 | } | |
7794 | if (regno == AT | |
7795 | && ! mips_opts.noat | |
7796 | && *args != 'E' | |
7797 | && *args != 'G') | |
7798 | as_warn (_("Used $at without \".set noat\"")); | |
7799 | c = *args; | |
7800 | if (*s == ' ') | |
7801 | s++; | |
7802 | if (args[1] != *s) | |
7803 | { | |
7804 | if (c == 'r' || c == 'v' || c == 'w') | |
7805 | { | |
7806 | regno = lastregno; | |
7807 | s = s_reset; | |
7808 | args++; | |
7809 | } | |
7810 | } | |
7811 | /* 'z' only matches $0. */ | |
7812 | if (c == 'z' && regno != 0) | |
7813 | break; | |
7814 | ||
bdaaa2e1 KH |
7815 | /* Now that we have assembled one operand, we use the args string |
7816 | * to figure out where it goes in the instruction. */ | |
252b5132 RH |
7817 | switch (c) |
7818 | { | |
7819 | case 'r': | |
7820 | case 's': | |
7821 | case 'v': | |
7822 | case 'b': | |
38487616 | 7823 | ip->insn_opcode |= regno << OP_SH_RS; |
252b5132 RH |
7824 | break; |
7825 | case 'd': | |
7826 | case 'G': | |
38487616 | 7827 | ip->insn_opcode |= regno << OP_SH_RD; |
252b5132 | 7828 | break; |
4372b673 | 7829 | case 'U': |
38487616 TS |
7830 | ip->insn_opcode |= regno << OP_SH_RD; |
7831 | ip->insn_opcode |= regno << OP_SH_RT; | |
4372b673 | 7832 | break; |
252b5132 RH |
7833 | case 'w': |
7834 | case 't': | |
7835 | case 'E': | |
38487616 | 7836 | ip->insn_opcode |= regno << OP_SH_RT; |
252b5132 RH |
7837 | break; |
7838 | case 'x': | |
7839 | /* This case exists because on the r3000 trunc | |
7840 | expands into a macro which requires a gp | |
7841 | register. On the r6000 or r4000 it is | |
7842 | assembled into a single instruction which | |
7843 | ignores the register. Thus the insn version | |
7844 | is MIPS_ISA2 and uses 'x', and the macro | |
7845 | version is MIPS_ISA1 and uses 't'. */ | |
7846 | break; | |
7847 | case 'z': | |
7848 | /* This case is for the div instruction, which | |
7849 | acts differently if the destination argument | |
7850 | is $0. This only matches $0, and is checked | |
7851 | outside the switch. */ | |
7852 | break; | |
7853 | case 'D': | |
7854 | /* Itbl operand; not yet implemented. FIXME ?? */ | |
7855 | break; | |
7856 | /* What about all other operands like 'i', which | |
7857 | can be specified in the opcode table? */ | |
7858 | } | |
7859 | lastregno = regno; | |
7860 | continue; | |
7861 | } | |
7862 | notreg: | |
7863 | switch (*args++) | |
7864 | { | |
7865 | case 'r': | |
7866 | case 'v': | |
38487616 | 7867 | ip->insn_opcode |= lastregno << OP_SH_RS; |
252b5132 RH |
7868 | continue; |
7869 | case 'w': | |
38487616 | 7870 | ip->insn_opcode |= lastregno << OP_SH_RT; |
252b5132 RH |
7871 | continue; |
7872 | } | |
7873 | break; | |
7874 | ||
7875 | case 'D': /* floating point destination register */ | |
7876 | case 'S': /* floating point source register */ | |
7877 | case 'T': /* floating point target register */ | |
7878 | case 'R': /* floating point source register */ | |
7879 | case 'V': | |
7880 | case 'W': | |
7881 | s_reset = s; | |
3882b010 L |
7882 | if (s[0] == '$' && s[1] == 'f' |
7883 | && ISDIGIT (s[2])) | |
252b5132 RH |
7884 | { |
7885 | s += 2; | |
7886 | regno = 0; | |
7887 | do | |
7888 | { | |
7889 | regno *= 10; | |
7890 | regno += *s - '0'; | |
7891 | ++s; | |
7892 | } | |
3882b010 | 7893 | while (ISDIGIT (*s)); |
252b5132 RH |
7894 | |
7895 | if (regno > 31) | |
7896 | as_bad (_("Invalid float register number (%d)"), regno); | |
7897 | ||
7898 | if ((regno & 1) != 0 | |
ca4e0257 | 7899 | && HAVE_32BIT_FPRS |
252b5132 RH |
7900 | && ! (strcmp (str, "mtc1") == 0 |
7901 | || strcmp (str, "mfc1") == 0 | |
7902 | || strcmp (str, "lwc1") == 0 | |
7903 | || strcmp (str, "swc1") == 0 | |
7904 | || strcmp (str, "l.s") == 0 | |
7905 | || strcmp (str, "s.s") == 0)) | |
7906 | as_warn (_("Float register should be even, was %d"), | |
7907 | regno); | |
7908 | ||
7909 | c = *args; | |
7910 | if (*s == ' ') | |
7911 | s++; | |
7912 | if (args[1] != *s) | |
7913 | { | |
7914 | if (c == 'V' || c == 'W') | |
7915 | { | |
7916 | regno = lastregno; | |
7917 | s = s_reset; | |
7918 | args++; | |
7919 | } | |
7920 | } | |
7921 | switch (c) | |
7922 | { | |
7923 | case 'D': | |
38487616 | 7924 | ip->insn_opcode |= regno << OP_SH_FD; |
252b5132 RH |
7925 | break; |
7926 | case 'V': | |
7927 | case 'S': | |
38487616 | 7928 | ip->insn_opcode |= regno << OP_SH_FS; |
252b5132 RH |
7929 | break; |
7930 | case 'W': | |
7931 | case 'T': | |
38487616 | 7932 | ip->insn_opcode |= regno << OP_SH_FT; |
252b5132 RH |
7933 | break; |
7934 | case 'R': | |
38487616 | 7935 | ip->insn_opcode |= regno << OP_SH_FR; |
252b5132 RH |
7936 | break; |
7937 | } | |
7938 | lastregno = regno; | |
7939 | continue; | |
7940 | } | |
7941 | ||
252b5132 RH |
7942 | switch (*args++) |
7943 | { | |
7944 | case 'V': | |
38487616 | 7945 | ip->insn_opcode |= lastregno << OP_SH_FS; |
252b5132 RH |
7946 | continue; |
7947 | case 'W': | |
38487616 | 7948 | ip->insn_opcode |= lastregno << OP_SH_FT; |
252b5132 RH |
7949 | continue; |
7950 | } | |
7951 | break; | |
7952 | ||
7953 | case 'I': | |
7954 | my_getExpression (&imm_expr, s); | |
7955 | if (imm_expr.X_op != O_big | |
7956 | && imm_expr.X_op != O_constant) | |
7957 | insn_error = _("absolute expression required"); | |
7958 | s = expr_end; | |
7959 | continue; | |
7960 | ||
7961 | case 'A': | |
7962 | my_getExpression (&offset_expr, s); | |
f6688943 | 7963 | *imm_reloc = BFD_RELOC_32; |
252b5132 RH |
7964 | s = expr_end; |
7965 | continue; | |
7966 | ||
7967 | case 'F': | |
7968 | case 'L': | |
7969 | case 'f': | |
7970 | case 'l': | |
7971 | { | |
7972 | int f64; | |
ca4e0257 | 7973 | int using_gprs; |
252b5132 RH |
7974 | char *save_in; |
7975 | char *err; | |
7976 | unsigned char temp[8]; | |
7977 | int len; | |
7978 | unsigned int length; | |
7979 | segT seg; | |
7980 | subsegT subseg; | |
7981 | char *p; | |
7982 | ||
7983 | /* These only appear as the last operand in an | |
7984 | instruction, and every instruction that accepts | |
7985 | them in any variant accepts them in all variants. | |
7986 | This means we don't have to worry about backing out | |
7987 | any changes if the instruction does not match. | |
7988 | ||
7989 | The difference between them is the size of the | |
7990 | floating point constant and where it goes. For 'F' | |
7991 | and 'L' the constant is 64 bits; for 'f' and 'l' it | |
7992 | is 32 bits. Where the constant is placed is based | |
7993 | on how the MIPS assembler does things: | |
7994 | F -- .rdata | |
7995 | L -- .lit8 | |
7996 | f -- immediate value | |
7997 | l -- .lit4 | |
7998 | ||
7999 | The .lit4 and .lit8 sections are only used if | |
8000 | permitted by the -G argument. | |
8001 | ||
8002 | When generating embedded PIC code, we use the | |
8003 | .lit8 section but not the .lit4 section (we can do | |
8004 | .lit4 inline easily; we need to put .lit8 | |
8005 | somewhere in the data segment, and using .lit8 | |
8006 | permits the linker to eventually combine identical | |
ca4e0257 RS |
8007 | .lit8 entries). |
8008 | ||
8009 | The code below needs to know whether the target register | |
8010 | is 32 or 64 bits wide. It relies on the fact 'f' and | |
8011 | 'F' are used with GPR-based instructions and 'l' and | |
8012 | 'L' are used with FPR-based instructions. */ | |
252b5132 RH |
8013 | |
8014 | f64 = *args == 'F' || *args == 'L'; | |
ca4e0257 | 8015 | using_gprs = *args == 'F' || *args == 'f'; |
252b5132 RH |
8016 | |
8017 | save_in = input_line_pointer; | |
8018 | input_line_pointer = s; | |
8019 | err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len); | |
8020 | length = len; | |
8021 | s = input_line_pointer; | |
8022 | input_line_pointer = save_in; | |
8023 | if (err != NULL && *err != '\0') | |
8024 | { | |
8025 | as_bad (_("Bad floating point constant: %s"), err); | |
8026 | memset (temp, '\0', sizeof temp); | |
8027 | length = f64 ? 8 : 4; | |
8028 | } | |
8029 | ||
156c2f8b | 8030 | assert (length == (unsigned) (f64 ? 8 : 4)); |
252b5132 RH |
8031 | |
8032 | if (*args == 'f' | |
8033 | || (*args == 'l' | |
8034 | && (! USE_GLOBAL_POINTER_OPT | |
8035 | || mips_pic == EMBEDDED_PIC | |
8036 | || g_switch_value < 4 | |
8037 | || (temp[0] == 0 && temp[1] == 0) | |
8038 | || (temp[2] == 0 && temp[3] == 0)))) | |
8039 | { | |
8040 | imm_expr.X_op = O_constant; | |
8041 | if (! target_big_endian) | |
8042 | imm_expr.X_add_number = bfd_getl32 (temp); | |
8043 | else | |
8044 | imm_expr.X_add_number = bfd_getb32 (temp); | |
8045 | } | |
8046 | else if (length > 4 | |
119d663a | 8047 | && ! mips_disable_float_construction |
ca4e0257 RS |
8048 | /* Constants can only be constructed in GPRs and |
8049 | copied to FPRs if the GPRs are at least as wide | |
8050 | as the FPRs. Force the constant into memory if | |
8051 | we are using 64-bit FPRs but the GPRs are only | |
8052 | 32 bits wide. */ | |
8053 | && (using_gprs | |
8054 | || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS)) | |
252b5132 RH |
8055 | && ((temp[0] == 0 && temp[1] == 0) |
8056 | || (temp[2] == 0 && temp[3] == 0)) | |
8057 | && ((temp[4] == 0 && temp[5] == 0) | |
8058 | || (temp[6] == 0 && temp[7] == 0))) | |
8059 | { | |
ca4e0257 RS |
8060 | /* The value is simple enough to load with a couple of |
8061 | instructions. If using 32-bit registers, set | |
8062 | imm_expr to the high order 32 bits and offset_expr to | |
8063 | the low order 32 bits. Otherwise, set imm_expr to | |
8064 | the entire 64 bit constant. */ | |
8065 | if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS) | |
252b5132 RH |
8066 | { |
8067 | imm_expr.X_op = O_constant; | |
8068 | offset_expr.X_op = O_constant; | |
8069 | if (! target_big_endian) | |
8070 | { | |
8071 | imm_expr.X_add_number = bfd_getl32 (temp + 4); | |
8072 | offset_expr.X_add_number = bfd_getl32 (temp); | |
8073 | } | |
8074 | else | |
8075 | { | |
8076 | imm_expr.X_add_number = bfd_getb32 (temp); | |
8077 | offset_expr.X_add_number = bfd_getb32 (temp + 4); | |
8078 | } | |
8079 | if (offset_expr.X_add_number == 0) | |
8080 | offset_expr.X_op = O_absent; | |
8081 | } | |
8082 | else if (sizeof (imm_expr.X_add_number) > 4) | |
8083 | { | |
8084 | imm_expr.X_op = O_constant; | |
8085 | if (! target_big_endian) | |
8086 | imm_expr.X_add_number = bfd_getl64 (temp); | |
8087 | else | |
8088 | imm_expr.X_add_number = bfd_getb64 (temp); | |
8089 | } | |
8090 | else | |
8091 | { | |
8092 | imm_expr.X_op = O_big; | |
8093 | imm_expr.X_add_number = 4; | |
8094 | if (! target_big_endian) | |
8095 | { | |
8096 | generic_bignum[0] = bfd_getl16 (temp); | |
8097 | generic_bignum[1] = bfd_getl16 (temp + 2); | |
8098 | generic_bignum[2] = bfd_getl16 (temp + 4); | |
8099 | generic_bignum[3] = bfd_getl16 (temp + 6); | |
8100 | } | |
8101 | else | |
8102 | { | |
8103 | generic_bignum[0] = bfd_getb16 (temp + 6); | |
8104 | generic_bignum[1] = bfd_getb16 (temp + 4); | |
8105 | generic_bignum[2] = bfd_getb16 (temp + 2); | |
8106 | generic_bignum[3] = bfd_getb16 (temp); | |
8107 | } | |
8108 | } | |
8109 | } | |
8110 | else | |
8111 | { | |
8112 | const char *newname; | |
8113 | segT new_seg; | |
8114 | ||
8115 | /* Switch to the right section. */ | |
8116 | seg = now_seg; | |
8117 | subseg = now_subseg; | |
8118 | switch (*args) | |
8119 | { | |
8120 | default: /* unused default case avoids warnings. */ | |
8121 | case 'L': | |
8122 | newname = RDATA_SECTION_NAME; | |
bb2d6cd7 GK |
8123 | if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8) |
8124 | || mips_pic == EMBEDDED_PIC) | |
252b5132 RH |
8125 | newname = ".lit8"; |
8126 | break; | |
8127 | case 'F': | |
bb2d6cd7 GK |
8128 | if (mips_pic == EMBEDDED_PIC) |
8129 | newname = ".lit8"; | |
8130 | else | |
8131 | newname = RDATA_SECTION_NAME; | |
252b5132 RH |
8132 | break; |
8133 | case 'l': | |
8134 | assert (!USE_GLOBAL_POINTER_OPT | |
8135 | || g_switch_value >= 4); | |
8136 | newname = ".lit4"; | |
8137 | break; | |
8138 | } | |
8139 | new_seg = subseg_new (newname, (subsegT) 0); | |
8140 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
8141 | bfd_set_section_flags (stdoutput, new_seg, | |
8142 | (SEC_ALLOC | |
8143 | | SEC_LOAD | |
8144 | | SEC_READONLY | |
8145 | | SEC_DATA)); | |
8146 | frag_align (*args == 'l' ? 2 : 3, 0, 0); | |
8147 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
8148 | && strcmp (TARGET_OS, "elf") != 0) | |
8149 | record_alignment (new_seg, 4); | |
8150 | else | |
8151 | record_alignment (new_seg, *args == 'l' ? 2 : 3); | |
8152 | if (seg == now_seg) | |
8153 | as_bad (_("Can't use floating point insn in this section")); | |
8154 | ||
8155 | /* Set the argument to the current address in the | |
8156 | section. */ | |
8157 | offset_expr.X_op = O_symbol; | |
8158 | offset_expr.X_add_symbol = | |
8159 | symbol_new ("L0\001", now_seg, | |
8160 | (valueT) frag_now_fix (), frag_now); | |
8161 | offset_expr.X_add_number = 0; | |
8162 | ||
8163 | /* Put the floating point number into the section. */ | |
8164 | p = frag_more ((int) length); | |
8165 | memcpy (p, temp, length); | |
8166 | ||
8167 | /* Switch back to the original section. */ | |
8168 | subseg_set (seg, subseg); | |
8169 | } | |
8170 | } | |
8171 | continue; | |
8172 | ||
8173 | case 'i': /* 16 bit unsigned immediate */ | |
8174 | case 'j': /* 16 bit signed immediate */ | |
f6688943 | 8175 | *imm_reloc = BFD_RELOC_LO16; |
252b5132 | 8176 | c = my_getSmallExpression (&imm_expr, s); |
fb1b3232 | 8177 | if (c != S_EX_NONE) |
252b5132 | 8178 | { |
fb1b3232 | 8179 | if (c != S_EX_LO) |
252b5132 RH |
8180 | { |
8181 | if (imm_expr.X_op == O_constant) | |
8182 | imm_expr.X_add_number = | |
8183 | (imm_expr.X_add_number >> 16) & 0xffff; | |
ad8d3bb3 | 8184 | #ifdef OBJ_ELF |
fb1b3232 | 8185 | else if (c == S_EX_HIGHEST) |
f6688943 | 8186 | *imm_reloc = BFD_RELOC_MIPS_HIGHEST; |
fb1b3232 | 8187 | else if (c == S_EX_HIGHER) |
f6688943 | 8188 | *imm_reloc = BFD_RELOC_MIPS_HIGHER; |
ad8d3bb3 TS |
8189 | else if (c == S_EX_GP_REL) |
8190 | { | |
8191 | /* This occurs in NewABI only. */ | |
8192 | c = my_getSmallExpression (&imm_expr, s); | |
8193 | if (c != S_EX_NEG) | |
8194 | as_bad (_("bad composition of relocations")); | |
8195 | else | |
8196 | { | |
8197 | c = my_getSmallExpression (&imm_expr, s); | |
8198 | if (c != S_EX_LO) | |
8199 | as_bad (_("bad composition of relocations")); | |
8200 | else | |
8201 | { | |
8202 | imm_reloc[0] = BFD_RELOC_GPREL16; | |
8203 | imm_reloc[1] = BFD_RELOC_MIPS_SUB; | |
8204 | imm_reloc[2] = BFD_RELOC_LO16; | |
8205 | } | |
8206 | } | |
8207 | } | |
8208 | #endif | |
fb1b3232 | 8209 | else if (c == S_EX_HI) |
252b5132 | 8210 | { |
f6688943 | 8211 | *imm_reloc = BFD_RELOC_HI16_S; |
252b5132 RH |
8212 | imm_unmatched_hi = true; |
8213 | } | |
8214 | else | |
f6688943 | 8215 | *imm_reloc = BFD_RELOC_HI16; |
252b5132 RH |
8216 | } |
8217 | else if (imm_expr.X_op == O_constant) | |
8218 | imm_expr.X_add_number &= 0xffff; | |
8219 | } | |
8220 | if (*args == 'i') | |
8221 | { | |
fb1b3232 | 8222 | if ((c == S_EX_NONE && imm_expr.X_op != O_constant) |
252b5132 | 8223 | || ((imm_expr.X_add_number < 0 |
beae10d5 KH |
8224 | || imm_expr.X_add_number >= 0x10000) |
8225 | && imm_expr.X_op == O_constant)) | |
252b5132 RH |
8226 | { |
8227 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
8228 | !strcmp (insn->name, insn[1].name)) | |
8229 | break; | |
2ae7e77b AH |
8230 | if (imm_expr.X_op == O_constant |
8231 | || imm_expr.X_op == O_big) | |
252b5132 RH |
8232 | as_bad (_("16 bit expression not in range 0..65535")); |
8233 | } | |
8234 | } | |
8235 | else | |
8236 | { | |
8237 | int more; | |
8238 | offsetT max; | |
8239 | ||
8240 | /* The upper bound should be 0x8000, but | |
8241 | unfortunately the MIPS assembler accepts numbers | |
8242 | from 0x8000 to 0xffff and sign extends them, and | |
8243 | we want to be compatible. We only permit this | |
8244 | extended range for an instruction which does not | |
8245 | provide any further alternates, since those | |
8246 | alternates may handle other cases. People should | |
8247 | use the numbers they mean, rather than relying on | |
8248 | a mysterious sign extension. */ | |
8249 | more = (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
8250 | strcmp (insn->name, insn[1].name) == 0); | |
8251 | if (more) | |
8252 | max = 0x8000; | |
8253 | else | |
8254 | max = 0x10000; | |
fb1b3232 | 8255 | if ((c == S_EX_NONE && imm_expr.X_op != O_constant) |
252b5132 | 8256 | || ((imm_expr.X_add_number < -0x8000 |
beae10d5 KH |
8257 | || imm_expr.X_add_number >= max) |
8258 | && imm_expr.X_op == O_constant) | |
252b5132 RH |
8259 | || (more |
8260 | && imm_expr.X_add_number < 0 | |
ca4e0257 | 8261 | && HAVE_64BIT_GPRS |
252b5132 RH |
8262 | && imm_expr.X_unsigned |
8263 | && sizeof (imm_expr.X_add_number) <= 4)) | |
8264 | { | |
8265 | if (more) | |
8266 | break; | |
2ae7e77b AH |
8267 | if (imm_expr.X_op == O_constant |
8268 | || imm_expr.X_op == O_big) | |
252b5132 RH |
8269 | as_bad (_("16 bit expression not in range -32768..32767")); |
8270 | } | |
8271 | } | |
8272 | s = expr_end; | |
8273 | continue; | |
8274 | ||
8275 | case 'o': /* 16 bit offset */ | |
8276 | c = my_getSmallExpression (&offset_expr, s); | |
8277 | ||
8278 | /* If this value won't fit into a 16 bit offset, then go | |
8279 | find a macro that will generate the 32 bit offset | |
afdbd6d0 | 8280 | code pattern. */ |
fb1b3232 | 8281 | if (c == S_EX_NONE |
252b5132 RH |
8282 | && (offset_expr.X_op != O_constant |
8283 | || offset_expr.X_add_number >= 0x8000 | |
afdbd6d0 | 8284 | || offset_expr.X_add_number < -0x8000)) |
252b5132 RH |
8285 | break; |
8286 | ||
fb1b3232 | 8287 | if (c == S_EX_HI) |
252b5132 RH |
8288 | { |
8289 | if (offset_expr.X_op != O_constant) | |
8290 | break; | |
8291 | offset_expr.X_add_number = | |
8292 | (offset_expr.X_add_number >> 16) & 0xffff; | |
8293 | } | |
f6688943 | 8294 | *offset_reloc = BFD_RELOC_LO16; |
252b5132 RH |
8295 | s = expr_end; |
8296 | continue; | |
8297 | ||
8298 | case 'p': /* pc relative offset */ | |
cb56d3d3 | 8299 | if (mips_pic == EMBEDDED_PIC) |
f6688943 | 8300 | *offset_reloc = BFD_RELOC_16_PCREL_S2; |
cb56d3d3 | 8301 | else |
f6688943 | 8302 | *offset_reloc = BFD_RELOC_16_PCREL; |
252b5132 RH |
8303 | my_getExpression (&offset_expr, s); |
8304 | s = expr_end; | |
8305 | continue; | |
8306 | ||
8307 | case 'u': /* upper 16 bits */ | |
8308 | c = my_getSmallExpression (&imm_expr, s); | |
f6688943 | 8309 | *imm_reloc = BFD_RELOC_LO16; |
e7d556df | 8310 | if (c != S_EX_NONE) |
252b5132 | 8311 | { |
fb1b3232 | 8312 | if (c != S_EX_LO) |
252b5132 RH |
8313 | { |
8314 | if (imm_expr.X_op == O_constant) | |
8315 | imm_expr.X_add_number = | |
8316 | (imm_expr.X_add_number >> 16) & 0xffff; | |
ad8d3bb3 | 8317 | #ifdef OBJ_ELF |
fb1b3232 | 8318 | else if (c == S_EX_HIGHEST) |
f6688943 | 8319 | *imm_reloc = BFD_RELOC_MIPS_HIGHEST; |
fb1b3232 | 8320 | else if (c == S_EX_HI) |
252b5132 | 8321 | { |
f6688943 | 8322 | *imm_reloc = BFD_RELOC_HI16_S; |
252b5132 RH |
8323 | imm_unmatched_hi = true; |
8324 | } | |
ad8d3bb3 TS |
8325 | else if (c == S_EX_GP_REL) |
8326 | { | |
8327 | /* This occurs in NewABI only. */ | |
8328 | c = my_getSmallExpression (&imm_expr, s); | |
8329 | if (c != S_EX_NEG) | |
8330 | as_bad (_("bad composition of relocations")); | |
8331 | else | |
8332 | { | |
8333 | c = my_getSmallExpression (&imm_expr, s); | |
8334 | if (c != S_EX_HI) | |
8335 | as_bad (_("bad composition of relocations")); | |
8336 | else | |
8337 | { | |
8338 | imm_reloc[0] = BFD_RELOC_GPREL16; | |
8339 | imm_reloc[1] = BFD_RELOC_MIPS_SUB; | |
8340 | imm_reloc[2] = BFD_RELOC_HI16_S; | |
8341 | } | |
8342 | } | |
8343 | } | |
8344 | #endif | |
252b5132 | 8345 | else |
f6688943 | 8346 | *imm_reloc = BFD_RELOC_HI16; |
252b5132 RH |
8347 | } |
8348 | else if (imm_expr.X_op == O_constant) | |
8349 | imm_expr.X_add_number &= 0xffff; | |
8350 | } | |
8351 | if (imm_expr.X_op == O_constant | |
8352 | && (imm_expr.X_add_number < 0 | |
8353 | || imm_expr.X_add_number >= 0x10000)) | |
8354 | as_bad (_("lui expression not in range 0..65535")); | |
8355 | s = expr_end; | |
8356 | continue; | |
8357 | ||
8358 | case 'a': /* 26 bit address */ | |
8359 | my_getExpression (&offset_expr, s); | |
8360 | s = expr_end; | |
f6688943 | 8361 | *offset_reloc = BFD_RELOC_MIPS_JMP; |
252b5132 RH |
8362 | continue; |
8363 | ||
8364 | case 'N': /* 3 bit branch condition code */ | |
8365 | case 'M': /* 3 bit compare condition code */ | |
8366 | if (strncmp (s, "$fcc", 4) != 0) | |
8367 | break; | |
8368 | s += 4; | |
8369 | regno = 0; | |
8370 | do | |
8371 | { | |
8372 | regno *= 10; | |
8373 | regno += *s - '0'; | |
8374 | ++s; | |
8375 | } | |
3882b010 | 8376 | while (ISDIGIT (*s)); |
252b5132 RH |
8377 | if (regno > 7) |
8378 | as_bad (_("invalid condition code register $fcc%d"), regno); | |
8379 | if (*args == 'N') | |
8380 | ip->insn_opcode |= regno << OP_SH_BCC; | |
8381 | else | |
8382 | ip->insn_opcode |= regno << OP_SH_CCC; | |
beae10d5 | 8383 | continue; |
252b5132 | 8384 | |
156c2f8b NC |
8385 | case 'H': |
8386 | if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) | |
8387 | s += 2; | |
3882b010 | 8388 | if (ISDIGIT (*s)) |
156c2f8b NC |
8389 | { |
8390 | c = 0; | |
8391 | do | |
8392 | { | |
8393 | c *= 10; | |
8394 | c += *s - '0'; | |
8395 | ++s; | |
8396 | } | |
3882b010 | 8397 | while (ISDIGIT (*s)); |
156c2f8b NC |
8398 | } |
8399 | else | |
8400 | c = 8; /* Invalid sel value. */ | |
8401 | ||
8402 | if (c > 7) | |
8403 | as_bad (_("invalid coprocessor sub-selection value (0-7)")); | |
8404 | ip->insn_opcode |= c; | |
8405 | continue; | |
8406 | ||
252b5132 RH |
8407 | default: |
8408 | as_bad (_("bad char = '%c'\n"), *args); | |
8409 | internalError (); | |
8410 | } | |
8411 | break; | |
8412 | } | |
8413 | /* Args don't match. */ | |
8414 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
8415 | !strcmp (insn->name, insn[1].name)) | |
8416 | { | |
8417 | ++insn; | |
8418 | s = argsStart; | |
268f6bed | 8419 | insn_error = _("illegal operands"); |
252b5132 RH |
8420 | continue; |
8421 | } | |
268f6bed L |
8422 | if (save_c) |
8423 | *(--s) = save_c; | |
252b5132 RH |
8424 | insn_error = _("illegal operands"); |
8425 | return; | |
8426 | } | |
8427 | } | |
8428 | ||
8429 | /* This routine assembles an instruction into its binary format when | |
8430 | assembling for the mips16. As a side effect, it sets one of the | |
8431 | global variables imm_reloc or offset_reloc to the type of | |
8432 | relocation to do if one of the operands is an address expression. | |
8433 | It also sets mips16_small and mips16_ext if the user explicitly | |
8434 | requested a small or extended instruction. */ | |
8435 | ||
8436 | static void | |
8437 | mips16_ip (str, ip) | |
8438 | char *str; | |
8439 | struct mips_cl_insn *ip; | |
8440 | { | |
8441 | char *s; | |
8442 | const char *args; | |
8443 | struct mips_opcode *insn; | |
8444 | char *argsstart; | |
8445 | unsigned int regno; | |
8446 | unsigned int lastregno = 0; | |
8447 | char *s_reset; | |
8448 | ||
8449 | insn_error = NULL; | |
8450 | ||
8451 | mips16_small = false; | |
8452 | mips16_ext = false; | |
8453 | ||
3882b010 | 8454 | for (s = str; ISLOWER (*s); ++s) |
252b5132 RH |
8455 | ; |
8456 | switch (*s) | |
8457 | { | |
8458 | case '\0': | |
8459 | break; | |
8460 | ||
8461 | case ' ': | |
8462 | *s++ = '\0'; | |
8463 | break; | |
8464 | ||
8465 | case '.': | |
8466 | if (s[1] == 't' && s[2] == ' ') | |
8467 | { | |
8468 | *s = '\0'; | |
8469 | mips16_small = true; | |
8470 | s += 3; | |
8471 | break; | |
8472 | } | |
8473 | else if (s[1] == 'e' && s[2] == ' ') | |
8474 | { | |
8475 | *s = '\0'; | |
8476 | mips16_ext = true; | |
8477 | s += 3; | |
8478 | break; | |
8479 | } | |
8480 | /* Fall through. */ | |
8481 | default: | |
8482 | insn_error = _("unknown opcode"); | |
8483 | return; | |
8484 | } | |
8485 | ||
8486 | if (mips_opts.noautoextend && ! mips16_ext) | |
8487 | mips16_small = true; | |
8488 | ||
8489 | if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL) | |
8490 | { | |
8491 | insn_error = _("unrecognized opcode"); | |
8492 | return; | |
8493 | } | |
8494 | ||
8495 | argsstart = s; | |
8496 | for (;;) | |
8497 | { | |
8498 | assert (strcmp (insn->name, str) == 0); | |
8499 | ||
8500 | ip->insn_mo = insn; | |
8501 | ip->insn_opcode = insn->match; | |
8502 | ip->use_extend = false; | |
8503 | imm_expr.X_op = O_absent; | |
f6688943 TS |
8504 | imm_reloc[0] = BFD_RELOC_UNUSED; |
8505 | imm_reloc[1] = BFD_RELOC_UNUSED; | |
8506 | imm_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 | 8507 | offset_expr.X_op = O_absent; |
f6688943 TS |
8508 | offset_reloc[0] = BFD_RELOC_UNUSED; |
8509 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
8510 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
8511 | for (args = insn->args; 1; ++args) |
8512 | { | |
8513 | int c; | |
8514 | ||
8515 | if (*s == ' ') | |
8516 | ++s; | |
8517 | ||
8518 | /* In this switch statement we call break if we did not find | |
8519 | a match, continue if we did find a match, or return if we | |
8520 | are done. */ | |
8521 | ||
8522 | c = *args; | |
8523 | switch (c) | |
8524 | { | |
8525 | case '\0': | |
8526 | if (*s == '\0') | |
8527 | { | |
8528 | /* Stuff the immediate value in now, if we can. */ | |
8529 | if (imm_expr.X_op == O_constant | |
f6688943 | 8530 | && *imm_reloc > BFD_RELOC_UNUSED |
252b5132 RH |
8531 | && insn->pinfo != INSN_MACRO) |
8532 | { | |
8533 | mips16_immed ((char *) NULL, 0, | |
f6688943 | 8534 | *imm_reloc - BFD_RELOC_UNUSED, |
252b5132 RH |
8535 | imm_expr.X_add_number, true, mips16_small, |
8536 | mips16_ext, &ip->insn_opcode, | |
8537 | &ip->use_extend, &ip->extend); | |
8538 | imm_expr.X_op = O_absent; | |
f6688943 | 8539 | *imm_reloc = BFD_RELOC_UNUSED; |
252b5132 RH |
8540 | } |
8541 | ||
8542 | return; | |
8543 | } | |
8544 | break; | |
8545 | ||
8546 | case ',': | |
8547 | if (*s++ == c) | |
8548 | continue; | |
8549 | s--; | |
8550 | switch (*++args) | |
8551 | { | |
8552 | case 'v': | |
8553 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8554 | continue; | |
8555 | case 'w': | |
8556 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8557 | continue; | |
8558 | } | |
8559 | break; | |
8560 | ||
8561 | case '(': | |
8562 | case ')': | |
8563 | if (*s++ == c) | |
8564 | continue; | |
8565 | break; | |
8566 | ||
8567 | case 'v': | |
8568 | case 'w': | |
8569 | if (s[0] != '$') | |
8570 | { | |
8571 | if (c == 'v') | |
8572 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8573 | else | |
8574 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8575 | ++args; | |
8576 | continue; | |
8577 | } | |
8578 | /* Fall through. */ | |
8579 | case 'x': | |
8580 | case 'y': | |
8581 | case 'z': | |
8582 | case 'Z': | |
8583 | case '0': | |
8584 | case 'S': | |
8585 | case 'R': | |
8586 | case 'X': | |
8587 | case 'Y': | |
8588 | if (s[0] != '$') | |
8589 | break; | |
8590 | s_reset = s; | |
3882b010 | 8591 | if (ISDIGIT (s[1])) |
252b5132 RH |
8592 | { |
8593 | ++s; | |
8594 | regno = 0; | |
8595 | do | |
8596 | { | |
8597 | regno *= 10; | |
8598 | regno += *s - '0'; | |
8599 | ++s; | |
8600 | } | |
3882b010 | 8601 | while (ISDIGIT (*s)); |
252b5132 RH |
8602 | if (regno > 31) |
8603 | { | |
8604 | as_bad (_("invalid register number (%d)"), regno); | |
8605 | regno = 2; | |
8606 | } | |
8607 | } | |
8608 | else | |
8609 | { | |
8610 | if (s[1] == 'f' && s[2] == 'p') | |
8611 | { | |
8612 | s += 3; | |
8613 | regno = FP; | |
8614 | } | |
8615 | else if (s[1] == 's' && s[2] == 'p') | |
8616 | { | |
8617 | s += 3; | |
8618 | regno = SP; | |
8619 | } | |
8620 | else if (s[1] == 'g' && s[2] == 'p') | |
8621 | { | |
8622 | s += 3; | |
8623 | regno = GP; | |
8624 | } | |
8625 | else if (s[1] == 'a' && s[2] == 't') | |
8626 | { | |
8627 | s += 3; | |
8628 | regno = AT; | |
8629 | } | |
8630 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
8631 | { | |
8632 | s += 4; | |
8633 | regno = KT0; | |
8634 | } | |
8635 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
8636 | { | |
8637 | s += 4; | |
8638 | regno = KT1; | |
8639 | } | |
8640 | else | |
8641 | break; | |
8642 | } | |
8643 | ||
8644 | if (*s == ' ') | |
8645 | ++s; | |
8646 | if (args[1] != *s) | |
8647 | { | |
8648 | if (c == 'v' || c == 'w') | |
8649 | { | |
8650 | regno = mips16_to_32_reg_map[lastregno]; | |
8651 | s = s_reset; | |
8652 | args++; | |
8653 | } | |
8654 | } | |
8655 | ||
8656 | switch (c) | |
8657 | { | |
8658 | case 'x': | |
8659 | case 'y': | |
8660 | case 'z': | |
8661 | case 'v': | |
8662 | case 'w': | |
8663 | case 'Z': | |
8664 | regno = mips32_to_16_reg_map[regno]; | |
8665 | break; | |
8666 | ||
8667 | case '0': | |
8668 | if (regno != 0) | |
8669 | regno = ILLEGAL_REG; | |
8670 | break; | |
8671 | ||
8672 | case 'S': | |
8673 | if (regno != SP) | |
8674 | regno = ILLEGAL_REG; | |
8675 | break; | |
8676 | ||
8677 | case 'R': | |
8678 | if (regno != RA) | |
8679 | regno = ILLEGAL_REG; | |
8680 | break; | |
8681 | ||
8682 | case 'X': | |
8683 | case 'Y': | |
8684 | if (regno == AT && ! mips_opts.noat) | |
8685 | as_warn (_("used $at without \".set noat\"")); | |
8686 | break; | |
8687 | ||
8688 | default: | |
8689 | internalError (); | |
8690 | } | |
8691 | ||
8692 | if (regno == ILLEGAL_REG) | |
8693 | break; | |
8694 | ||
8695 | switch (c) | |
8696 | { | |
8697 | case 'x': | |
8698 | case 'v': | |
8699 | ip->insn_opcode |= regno << MIPS16OP_SH_RX; | |
8700 | break; | |
8701 | case 'y': | |
8702 | case 'w': | |
8703 | ip->insn_opcode |= regno << MIPS16OP_SH_RY; | |
8704 | break; | |
8705 | case 'z': | |
8706 | ip->insn_opcode |= regno << MIPS16OP_SH_RZ; | |
8707 | break; | |
8708 | case 'Z': | |
8709 | ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z; | |
8710 | case '0': | |
8711 | case 'S': | |
8712 | case 'R': | |
8713 | break; | |
8714 | case 'X': | |
8715 | ip->insn_opcode |= regno << MIPS16OP_SH_REGR32; | |
8716 | break; | |
8717 | case 'Y': | |
8718 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
8719 | ip->insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
8720 | break; | |
8721 | default: | |
8722 | internalError (); | |
8723 | } | |
8724 | ||
8725 | lastregno = regno; | |
8726 | continue; | |
8727 | ||
8728 | case 'P': | |
8729 | if (strncmp (s, "$pc", 3) == 0) | |
8730 | { | |
8731 | s += 3; | |
8732 | continue; | |
8733 | } | |
8734 | break; | |
8735 | ||
8736 | case '<': | |
8737 | case '>': | |
8738 | case '[': | |
8739 | case ']': | |
8740 | case '4': | |
8741 | case '5': | |
8742 | case 'H': | |
8743 | case 'W': | |
8744 | case 'D': | |
8745 | case 'j': | |
8746 | case '8': | |
8747 | case 'V': | |
8748 | case 'C': | |
8749 | case 'U': | |
8750 | case 'k': | |
8751 | case 'K': | |
8752 | if (s[0] == '%' | |
8753 | && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0) | |
8754 | { | |
8755 | /* This is %gprel(SYMBOL). We need to read SYMBOL, | |
8756 | and generate the appropriate reloc. If the text | |
8757 | inside %gprel is not a symbol name with an | |
8758 | optional offset, then we generate a normal reloc | |
8759 | and will probably fail later. */ | |
8760 | my_getExpression (&imm_expr, s + sizeof "%gprel" - 1); | |
8761 | if (imm_expr.X_op == O_symbol) | |
8762 | { | |
8763 | mips16_ext = true; | |
f6688943 | 8764 | *imm_reloc = BFD_RELOC_MIPS16_GPREL; |
252b5132 RH |
8765 | s = expr_end; |
8766 | ip->use_extend = true; | |
8767 | ip->extend = 0; | |
8768 | continue; | |
8769 | } | |
8770 | } | |
8771 | else | |
8772 | { | |
8773 | /* Just pick up a normal expression. */ | |
8774 | my_getExpression (&imm_expr, s); | |
8775 | } | |
8776 | ||
8777 | if (imm_expr.X_op == O_register) | |
8778 | { | |
8779 | /* What we thought was an expression turned out to | |
8780 | be a register. */ | |
8781 | ||
8782 | if (s[0] == '(' && args[1] == '(') | |
8783 | { | |
8784 | /* It looks like the expression was omitted | |
8785 | before a register indirection, which means | |
8786 | that the expression is implicitly zero. We | |
8787 | still set up imm_expr, so that we handle | |
8788 | explicit extensions correctly. */ | |
8789 | imm_expr.X_op = O_constant; | |
8790 | imm_expr.X_add_number = 0; | |
f6688943 | 8791 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
8792 | continue; |
8793 | } | |
8794 | ||
8795 | break; | |
8796 | } | |
8797 | ||
8798 | /* We need to relax this instruction. */ | |
f6688943 | 8799 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
8800 | s = expr_end; |
8801 | continue; | |
8802 | ||
8803 | case 'p': | |
8804 | case 'q': | |
8805 | case 'A': | |
8806 | case 'B': | |
8807 | case 'E': | |
8808 | /* We use offset_reloc rather than imm_reloc for the PC | |
8809 | relative operands. This lets macros with both | |
8810 | immediate and address operands work correctly. */ | |
8811 | my_getExpression (&offset_expr, s); | |
8812 | ||
8813 | if (offset_expr.X_op == O_register) | |
8814 | break; | |
8815 | ||
8816 | /* We need to relax this instruction. */ | |
f6688943 | 8817 | *offset_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
8818 | s = expr_end; |
8819 | continue; | |
8820 | ||
8821 | case '6': /* break code */ | |
8822 | my_getExpression (&imm_expr, s); | |
8823 | check_absolute_expr (ip, &imm_expr); | |
8824 | if ((unsigned long) imm_expr.X_add_number > 63) | |
8825 | { | |
8826 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8827 | ip->insn_mo->name, | |
8828 | (unsigned long) imm_expr.X_add_number); | |
8829 | imm_expr.X_add_number &= 0x3f; | |
8830 | } | |
8831 | ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6; | |
8832 | imm_expr.X_op = O_absent; | |
8833 | s = expr_end; | |
8834 | continue; | |
8835 | ||
8836 | case 'a': /* 26 bit address */ | |
8837 | my_getExpression (&offset_expr, s); | |
8838 | s = expr_end; | |
f6688943 | 8839 | *offset_reloc = BFD_RELOC_MIPS16_JMP; |
252b5132 RH |
8840 | ip->insn_opcode <<= 16; |
8841 | continue; | |
8842 | ||
8843 | case 'l': /* register list for entry macro */ | |
8844 | case 'L': /* register list for exit macro */ | |
8845 | { | |
8846 | int mask; | |
8847 | ||
8848 | if (c == 'l') | |
8849 | mask = 0; | |
8850 | else | |
8851 | mask = 7 << 3; | |
8852 | while (*s != '\0') | |
8853 | { | |
8854 | int freg, reg1, reg2; | |
8855 | ||
8856 | while (*s == ' ' || *s == ',') | |
8857 | ++s; | |
8858 | if (*s != '$') | |
8859 | { | |
8860 | as_bad (_("can't parse register list")); | |
8861 | break; | |
8862 | } | |
8863 | ++s; | |
8864 | if (*s != 'f') | |
8865 | freg = 0; | |
8866 | else | |
8867 | { | |
8868 | freg = 1; | |
8869 | ++s; | |
8870 | } | |
8871 | reg1 = 0; | |
3882b010 | 8872 | while (ISDIGIT (*s)) |
252b5132 RH |
8873 | { |
8874 | reg1 *= 10; | |
8875 | reg1 += *s - '0'; | |
8876 | ++s; | |
8877 | } | |
8878 | if (*s == ' ') | |
8879 | ++s; | |
8880 | if (*s != '-') | |
8881 | reg2 = reg1; | |
8882 | else | |
8883 | { | |
8884 | ++s; | |
8885 | if (*s != '$') | |
8886 | break; | |
8887 | ++s; | |
8888 | if (freg) | |
8889 | { | |
8890 | if (*s == 'f') | |
8891 | ++s; | |
8892 | else | |
8893 | { | |
8894 | as_bad (_("invalid register list")); | |
8895 | break; | |
8896 | } | |
8897 | } | |
8898 | reg2 = 0; | |
3882b010 | 8899 | while (ISDIGIT (*s)) |
252b5132 RH |
8900 | { |
8901 | reg2 *= 10; | |
8902 | reg2 += *s - '0'; | |
8903 | ++s; | |
8904 | } | |
8905 | } | |
8906 | if (freg && reg1 == 0 && reg2 == 0 && c == 'L') | |
8907 | { | |
8908 | mask &= ~ (7 << 3); | |
8909 | mask |= 5 << 3; | |
8910 | } | |
8911 | else if (freg && reg1 == 0 && reg2 == 1 && c == 'L') | |
8912 | { | |
8913 | mask &= ~ (7 << 3); | |
8914 | mask |= 6 << 3; | |
8915 | } | |
8916 | else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L') | |
8917 | mask |= (reg2 - 3) << 3; | |
8918 | else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17) | |
8919 | mask |= (reg2 - 15) << 1; | |
8920 | else if (reg1 == 31 && reg2 == 31) | |
8921 | mask |= 1; | |
8922 | else | |
8923 | { | |
8924 | as_bad (_("invalid register list")); | |
8925 | break; | |
8926 | } | |
8927 | } | |
8928 | /* The mask is filled in in the opcode table for the | |
8929 | benefit of the disassembler. We remove it before | |
8930 | applying the actual mask. */ | |
8931 | ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6); | |
8932 | ip->insn_opcode |= mask << MIPS16OP_SH_IMM6; | |
8933 | } | |
8934 | continue; | |
8935 | ||
8936 | case 'e': /* extend code */ | |
8937 | my_getExpression (&imm_expr, s); | |
8938 | check_absolute_expr (ip, &imm_expr); | |
8939 | if ((unsigned long) imm_expr.X_add_number > 0x7ff) | |
8940 | { | |
8941 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8942 | ip->insn_mo->name, | |
8943 | (unsigned long) imm_expr.X_add_number); | |
8944 | imm_expr.X_add_number &= 0x7ff; | |
8945 | } | |
8946 | ip->insn_opcode |= imm_expr.X_add_number; | |
8947 | imm_expr.X_op = O_absent; | |
8948 | s = expr_end; | |
8949 | continue; | |
8950 | ||
8951 | default: | |
8952 | internalError (); | |
8953 | } | |
8954 | break; | |
8955 | } | |
8956 | ||
8957 | /* Args don't match. */ | |
8958 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] && | |
8959 | strcmp (insn->name, insn[1].name) == 0) | |
8960 | { | |
8961 | ++insn; | |
8962 | s = argsstart; | |
8963 | continue; | |
8964 | } | |
8965 | ||
8966 | insn_error = _("illegal operands"); | |
8967 | ||
8968 | return; | |
8969 | } | |
8970 | } | |
8971 | ||
8972 | /* This structure holds information we know about a mips16 immediate | |
8973 | argument type. */ | |
8974 | ||
e972090a NC |
8975 | struct mips16_immed_operand |
8976 | { | |
252b5132 RH |
8977 | /* The type code used in the argument string in the opcode table. */ |
8978 | int type; | |
8979 | /* The number of bits in the short form of the opcode. */ | |
8980 | int nbits; | |
8981 | /* The number of bits in the extended form of the opcode. */ | |
8982 | int extbits; | |
8983 | /* The amount by which the short form is shifted when it is used; | |
8984 | for example, the sw instruction has a shift count of 2. */ | |
8985 | int shift; | |
8986 | /* The amount by which the short form is shifted when it is stored | |
8987 | into the instruction code. */ | |
8988 | int op_shift; | |
8989 | /* Non-zero if the short form is unsigned. */ | |
8990 | int unsp; | |
8991 | /* Non-zero if the extended form is unsigned. */ | |
8992 | int extu; | |
8993 | /* Non-zero if the value is PC relative. */ | |
8994 | int pcrel; | |
8995 | }; | |
8996 | ||
8997 | /* The mips16 immediate operand types. */ | |
8998 | ||
8999 | static const struct mips16_immed_operand mips16_immed_operands[] = | |
9000 | { | |
9001 | { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
9002 | { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
9003 | { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
9004 | { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
9005 | { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 }, | |
9006 | { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9007 | { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9008 | { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9009 | { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9010 | { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 }, | |
9011 | { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9012 | { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9013 | { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9014 | { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 }, | |
9015 | { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
9016 | { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
9017 | { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
9018 | { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
9019 | { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 }, | |
9020 | { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 }, | |
9021 | { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 } | |
9022 | }; | |
9023 | ||
9024 | #define MIPS16_NUM_IMMED \ | |
9025 | (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0]) | |
9026 | ||
9027 | /* Handle a mips16 instruction with an immediate value. This or's the | |
9028 | small immediate value into *INSN. It sets *USE_EXTEND to indicate | |
9029 | whether an extended value is needed; if one is needed, it sets | |
9030 | *EXTEND to the value. The argument type is TYPE. The value is VAL. | |
9031 | If SMALL is true, an unextended opcode was explicitly requested. | |
9032 | If EXT is true, an extended opcode was explicitly requested. If | |
9033 | WARN is true, warn if EXT does not match reality. */ | |
9034 | ||
9035 | static void | |
9036 | mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend, | |
9037 | extend) | |
9038 | char *file; | |
9039 | unsigned int line; | |
9040 | int type; | |
9041 | offsetT val; | |
9042 | boolean warn; | |
9043 | boolean small; | |
9044 | boolean ext; | |
9045 | unsigned long *insn; | |
9046 | boolean *use_extend; | |
9047 | unsigned short *extend; | |
9048 | { | |
9049 | register const struct mips16_immed_operand *op; | |
9050 | int mintiny, maxtiny; | |
9051 | boolean needext; | |
9052 | ||
9053 | op = mips16_immed_operands; | |
9054 | while (op->type != type) | |
9055 | { | |
9056 | ++op; | |
9057 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
9058 | } | |
9059 | ||
9060 | if (op->unsp) | |
9061 | { | |
9062 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
9063 | { | |
9064 | mintiny = 1; | |
9065 | maxtiny = 1 << op->nbits; | |
9066 | } | |
9067 | else | |
9068 | { | |
9069 | mintiny = 0; | |
9070 | maxtiny = (1 << op->nbits) - 1; | |
9071 | } | |
9072 | } | |
9073 | else | |
9074 | { | |
9075 | mintiny = - (1 << (op->nbits - 1)); | |
9076 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
9077 | } | |
9078 | ||
9079 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
9080 | if (type == 'p' || type == 'q') | |
9081 | val /= 2; | |
9082 | ||
9083 | if ((val & ((1 << op->shift) - 1)) != 0 | |
9084 | || val < (mintiny << op->shift) | |
9085 | || val > (maxtiny << op->shift)) | |
9086 | needext = true; | |
9087 | else | |
9088 | needext = false; | |
9089 | ||
9090 | if (warn && ext && ! needext) | |
beae10d5 KH |
9091 | as_warn_where (file, line, |
9092 | _("extended operand requested but not required")); | |
252b5132 RH |
9093 | if (small && needext) |
9094 | as_bad_where (file, line, _("invalid unextended operand value")); | |
9095 | ||
9096 | if (small || (! ext && ! needext)) | |
9097 | { | |
9098 | int insnval; | |
9099 | ||
9100 | *use_extend = false; | |
9101 | insnval = ((val >> op->shift) & ((1 << op->nbits) - 1)); | |
9102 | insnval <<= op->op_shift; | |
9103 | *insn |= insnval; | |
9104 | } | |
9105 | else | |
9106 | { | |
9107 | long minext, maxext; | |
9108 | int extval; | |
9109 | ||
9110 | if (op->extu) | |
9111 | { | |
9112 | minext = 0; | |
9113 | maxext = (1 << op->extbits) - 1; | |
9114 | } | |
9115 | else | |
9116 | { | |
9117 | minext = - (1 << (op->extbits - 1)); | |
9118 | maxext = (1 << (op->extbits - 1)) - 1; | |
9119 | } | |
9120 | if (val < minext || val > maxext) | |
9121 | as_bad_where (file, line, | |
9122 | _("operand value out of range for instruction")); | |
9123 | ||
9124 | *use_extend = true; | |
9125 | if (op->extbits == 16) | |
9126 | { | |
9127 | extval = ((val >> 11) & 0x1f) | (val & 0x7e0); | |
9128 | val &= 0x1f; | |
9129 | } | |
9130 | else if (op->extbits == 15) | |
9131 | { | |
9132 | extval = ((val >> 11) & 0xf) | (val & 0x7f0); | |
9133 | val &= 0xf; | |
9134 | } | |
9135 | else | |
9136 | { | |
9137 | extval = ((val & 0x1f) << 6) | (val & 0x20); | |
9138 | val = 0; | |
9139 | } | |
9140 | ||
9141 | *extend = (unsigned short) extval; | |
9142 | *insn |= val; | |
9143 | } | |
9144 | } | |
9145 | \f | |
ad8d3bb3 TS |
9146 | static struct percent_op_match |
9147 | { | |
9148 | const char *str; | |
9149 | const enum small_ex_type type; | |
9150 | } percent_op[] = | |
9151 | { | |
9152 | #ifdef OBJ_ELF | |
9153 | {"%half", S_EX_HALF}, | |
9154 | #endif | |
9155 | {"%hi", S_EX_HI}, | |
9156 | {"%lo", S_EX_LO}, | |
9157 | #ifdef OBJ_ELF | |
9158 | {"%gp_rel", S_EX_GP_REL}, | |
9159 | {"%got", S_EX_GOT}, | |
9160 | {"%call16", S_EX_CALL16}, | |
9161 | {"%got_disp", S_EX_GOT_DISP}, | |
9162 | {"%got_page", S_EX_GOT_PAGE}, | |
9163 | {"%got_ofst", S_EX_GOT_OFST}, | |
9164 | {"%got_hi", S_EX_GOT_HI}, | |
9165 | {"%got_lo", S_EX_GOT_LO}, | |
9166 | {"%neg", S_EX_NEG}, | |
9167 | {"%higher", S_EX_HIGHER}, | |
9168 | {"%highest", S_EX_HIGHEST}, | |
9169 | {"%call_hi", S_EX_CALL_HI}, | |
9170 | {"%call_lo", S_EX_CALL_LO} | |
9171 | #endif | |
9172 | }; | |
9173 | ||
9174 | /* Parse small expression input. STR gets adjusted to eat up whitespace. | |
9175 | It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's | |
9176 | can be nested, this is handled by blanking the innermost, parsing the | |
9177 | rest by subsequent calls. */ | |
252b5132 RH |
9178 | |
9179 | static int | |
ad8d3bb3 TS |
9180 | my_getSmallParser (str, len, nestlevel) |
9181 | char **str; | |
9182 | unsigned int *len; | |
9183 | int *nestlevel; | |
252b5132 | 9184 | { |
ad8d3bb3 | 9185 | int type = S_EX_NONE; |
252b5132 | 9186 | |
ad8d3bb3 TS |
9187 | *len = 0; |
9188 | *str += strspn (*str, " \t"); | |
9189 | if (**str == '(') | |
252b5132 | 9190 | { |
ad8d3bb3 TS |
9191 | char *b = *str + 1 + strspn (*str + 1, " \t"); |
9192 | char *e; | |
9193 | ||
9194 | /* Check for base register. */ | |
9195 | if (b[0] == '$') | |
9196 | { | |
9197 | if (strchr (b, ')') | |
9198 | && (e = b + strcspn (b, ") \t")) | |
9199 | && e - b > 1 && e - b < 4) | |
9200 | { | |
9201 | if ((e - b == 3 | |
9202 | && ((b[1] == 'f' && b[2] == 'p') | |
9203 | || (b[1] == 's' && b[2] == 'p') | |
9204 | || (b[1] == 'g' && b[2] == 'p') | |
9205 | || (b[1] == 'a' && b[2] == 't') | |
9206 | || (ISDIGIT (b[1]) | |
9207 | && ISDIGIT (b[2])))) | |
9208 | || (ISDIGIT (b[1]))) | |
9209 | { | |
9210 | *len = strcspn (*str, ")") + 1; | |
9211 | return S_EX_REGISTER; | |
9212 | } | |
9213 | } | |
9214 | } | |
9215 | else if (b[0] == '%') | |
9216 | { | |
9217 | *str = b; | |
9218 | goto percent_op; | |
9219 | } | |
76b3015f EC |
9220 | |
9221 | /* Some other expression in the braces. */ | |
9222 | *len = strcspn (*str, ")") + 1; | |
fb1b3232 | 9223 | } |
ad8d3bb3 TS |
9224 | /* Check for percent_op. */ |
9225 | else if (*str[0] == '%') | |
fb1b3232 | 9226 | { |
ad8d3bb3 TS |
9227 | char *tmp; |
9228 | unsigned int i; | |
9229 | ||
9230 | percent_op: | |
9231 | tmp = *str + 1; | |
9232 | i = 0; | |
9233 | ||
9234 | while (ISALPHA (*tmp) || *tmp == '_') | |
9235 | { | |
9236 | *tmp = TOLOWER (*tmp); | |
9237 | tmp++; | |
9238 | } | |
9239 | while (i < (sizeof (percent_op) / sizeof (struct percent_op_match))) | |
9240 | { | |
9241 | if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str))) | |
9242 | i++; | |
9243 | else | |
9244 | { | |
9245 | type = percent_op[i].type; | |
9246 | ||
9247 | /* Only %hi and %lo are allowed for OldABI. */ | |
9248 | if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO) | |
9249 | return S_EX_NONE; | |
9250 | ||
9251 | *len = strlen (percent_op[i].str); | |
9252 | (*nestlevel)++; | |
9253 | return type; | |
9254 | } | |
9255 | } | |
fb1b3232 | 9256 | } |
ad8d3bb3 TS |
9257 | |
9258 | /* Any other expression. */ | |
9259 | return S_EX_NONE; | |
9260 | } | |
9261 | ||
9262 | static int | |
9263 | my_getSmallExpression (ep, str) | |
9264 | expressionS *ep; | |
9265 | char *str; | |
9266 | { | |
9267 | static char *oldstr = NULL; | |
9268 | int c = S_EX_NONE; | |
9269 | int oldc; | |
9270 | int nest_level = 0; | |
9271 | unsigned int len; | |
9272 | ||
9273 | /* Don't update oldstr if the last call had nested percent_op's. */ | |
9274 | if (! oldstr) | |
9275 | oldstr = str; | |
76b3015f | 9276 | |
ad8d3bb3 | 9277 | do |
fb1b3232 | 9278 | { |
ad8d3bb3 TS |
9279 | oldc = c; |
9280 | c = my_getSmallParser (&str, &len, &nest_level); | |
9281 | if (c != S_EX_NONE && c != S_EX_REGISTER) | |
9282 | str += len; | |
fb1b3232 | 9283 | } |
ad8d3bb3 TS |
9284 | while (c != S_EX_NONE && c != S_EX_REGISTER); |
9285 | ||
9286 | /* A percent_op was encountered. */ | |
9287 | if (nest_level) | |
fb1b3232 | 9288 | { |
b6ff326e | 9289 | /* Don't try to get an expression if it is already blanked out. */ |
ad8d3bb3 TS |
9290 | if (*(str + strspn (str + 1, " )")) != ')') |
9291 | { | |
9292 | char save; | |
9293 | ||
9294 | save = *(str + len); | |
9295 | *(str + len) = '\0'; | |
9296 | my_getExpression (ep, str); | |
9297 | *(str + len) = save; | |
9298 | } | |
9299 | if (nest_level > 1) | |
9300 | { | |
9301 | /* blank out including the % sign. */ | |
9302 | char *p = strrchr (oldstr, '%'); | |
9303 | memset (p, ' ', str - p + len); | |
9304 | str = oldstr; | |
9305 | } | |
9306 | else | |
9307 | { | |
9308 | expr_end = strchr (str, ')') + 1; | |
9309 | } | |
9310 | c = oldc; | |
fb1b3232 | 9311 | } |
ad8d3bb3 | 9312 | else if (c == S_EX_NONE) |
fb1b3232 | 9313 | { |
ad8d3bb3 | 9314 | my_getExpression (ep, str); |
fb1b3232 | 9315 | } |
ad8d3bb3 | 9316 | else if (c == S_EX_REGISTER) |
fb1b3232 | 9317 | { |
ad8d3bb3 TS |
9318 | ep->X_op = O_constant; |
9319 | expr_end = str; | |
9320 | ep->X_add_symbol = NULL; | |
9321 | ep->X_op_symbol = NULL; | |
9322 | ep->X_add_number = 0; | |
fb1b3232 | 9323 | } |
fb1b3232 TS |
9324 | else |
9325 | { | |
ad8d3bb3 | 9326 | as_fatal(_("internal error")); |
fb1b3232 | 9327 | } |
252b5132 | 9328 | |
ad8d3bb3 TS |
9329 | if (nest_level <= 1) |
9330 | oldstr = NULL; | |
fb1b3232 | 9331 | |
fb1b3232 | 9332 | return c; |
252b5132 RH |
9333 | } |
9334 | ||
9335 | static void | |
9336 | my_getExpression (ep, str) | |
9337 | expressionS *ep; | |
9338 | char *str; | |
9339 | { | |
9340 | char *save_in; | |
98aa84af | 9341 | valueT val; |
252b5132 RH |
9342 | |
9343 | save_in = input_line_pointer; | |
9344 | input_line_pointer = str; | |
9345 | expression (ep); | |
9346 | expr_end = input_line_pointer; | |
9347 | input_line_pointer = save_in; | |
9348 | ||
9349 | /* If we are in mips16 mode, and this is an expression based on `.', | |
9350 | then we bump the value of the symbol by 1 since that is how other | |
9351 | text symbols are handled. We don't bother to handle complex | |
9352 | expressions, just `.' plus or minus a constant. */ | |
9353 | if (mips_opts.mips16 | |
9354 | && ep->X_op == O_symbol | |
9355 | && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0 | |
9356 | && S_GET_SEGMENT (ep->X_add_symbol) == now_seg | |
49309057 ILT |
9357 | && symbol_get_frag (ep->X_add_symbol) == frag_now |
9358 | && symbol_constant_p (ep->X_add_symbol) | |
98aa84af AM |
9359 | && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ()) |
9360 | S_SET_VALUE (ep->X_add_symbol, val + 1); | |
252b5132 RH |
9361 | } |
9362 | ||
9363 | /* Turn a string in input_line_pointer into a floating point constant | |
bc0d738a NC |
9364 | of type TYPE, and store the appropriate bytes in *LITP. The number |
9365 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
252b5132 RH |
9366 | returned, or NULL on OK. */ |
9367 | ||
9368 | char * | |
9369 | md_atof (type, litP, sizeP) | |
9370 | int type; | |
9371 | char *litP; | |
9372 | int *sizeP; | |
9373 | { | |
9374 | int prec; | |
9375 | LITTLENUM_TYPE words[4]; | |
9376 | char *t; | |
9377 | int i; | |
9378 | ||
9379 | switch (type) | |
9380 | { | |
9381 | case 'f': | |
9382 | prec = 2; | |
9383 | break; | |
9384 | ||
9385 | case 'd': | |
9386 | prec = 4; | |
9387 | break; | |
9388 | ||
9389 | default: | |
9390 | *sizeP = 0; | |
9391 | return _("bad call to md_atof"); | |
9392 | } | |
9393 | ||
9394 | t = atof_ieee (input_line_pointer, type, words); | |
9395 | if (t) | |
9396 | input_line_pointer = t; | |
9397 | ||
9398 | *sizeP = prec * 2; | |
9399 | ||
9400 | if (! target_big_endian) | |
9401 | { | |
9402 | for (i = prec - 1; i >= 0; i--) | |
9403 | { | |
9404 | md_number_to_chars (litP, (valueT) words[i], 2); | |
9405 | litP += 2; | |
9406 | } | |
9407 | } | |
9408 | else | |
9409 | { | |
9410 | for (i = 0; i < prec; i++) | |
9411 | { | |
9412 | md_number_to_chars (litP, (valueT) words[i], 2); | |
9413 | litP += 2; | |
9414 | } | |
9415 | } | |
bdaaa2e1 | 9416 | |
252b5132 RH |
9417 | return NULL; |
9418 | } | |
9419 | ||
9420 | void | |
9421 | md_number_to_chars (buf, val, n) | |
9422 | char *buf; | |
9423 | valueT val; | |
9424 | int n; | |
9425 | { | |
9426 | if (target_big_endian) | |
9427 | number_to_chars_bigendian (buf, val, n); | |
9428 | else | |
9429 | number_to_chars_littleendian (buf, val, n); | |
9430 | } | |
9431 | \f | |
e013f690 TS |
9432 | static int support_64bit_objects(void) |
9433 | { | |
9434 | const char **list, **l; | |
9435 | ||
9436 | list = bfd_target_list (); | |
9437 | for (l = list; *l != NULL; l++) | |
9438 | #ifdef TE_TMIPS | |
9439 | /* This is traditional mips */ | |
9440 | if (strcmp (*l, "elf64-tradbigmips") == 0 | |
9441 | || strcmp (*l, "elf64-tradlittlemips") == 0) | |
9442 | #else | |
9443 | if (strcmp (*l, "elf64-bigmips") == 0 | |
9444 | || strcmp (*l, "elf64-littlemips") == 0) | |
9445 | #endif | |
9446 | break; | |
9447 | free (list); | |
9448 | return (*l != NULL); | |
9449 | } | |
9450 | ||
39c0a331 | 9451 | CONST char *md_shortopts = "nO::g::G:"; |
252b5132 | 9452 | |
e972090a NC |
9453 | struct option md_longopts[] = |
9454 | { | |
252b5132 RH |
9455 | #define OPTION_MIPS1 (OPTION_MD_BASE + 1) |
9456 | {"mips0", no_argument, NULL, OPTION_MIPS1}, | |
9457 | {"mips1", no_argument, NULL, OPTION_MIPS1}, | |
9458 | #define OPTION_MIPS2 (OPTION_MD_BASE + 2) | |
9459 | {"mips2", no_argument, NULL, OPTION_MIPS2}, | |
9460 | #define OPTION_MIPS3 (OPTION_MD_BASE + 3) | |
9461 | {"mips3", no_argument, NULL, OPTION_MIPS3}, | |
9462 | #define OPTION_MIPS4 (OPTION_MD_BASE + 4) | |
9463 | {"mips4", no_argument, NULL, OPTION_MIPS4}, | |
9464 | #define OPTION_MCPU (OPTION_MD_BASE + 5) | |
9465 | {"mcpu", required_argument, NULL, OPTION_MCPU}, | |
9466 | #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 6) | |
9467 | {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC}, | |
156c2f8b | 9468 | #define OPTION_TRAP (OPTION_MD_BASE + 7) |
252b5132 RH |
9469 | {"trap", no_argument, NULL, OPTION_TRAP}, |
9470 | {"no-break", no_argument, NULL, OPTION_TRAP}, | |
156c2f8b | 9471 | #define OPTION_BREAK (OPTION_MD_BASE + 8) |
252b5132 RH |
9472 | {"break", no_argument, NULL, OPTION_BREAK}, |
9473 | {"no-trap", no_argument, NULL, OPTION_BREAK}, | |
156c2f8b | 9474 | #define OPTION_EB (OPTION_MD_BASE + 9) |
252b5132 | 9475 | {"EB", no_argument, NULL, OPTION_EB}, |
156c2f8b | 9476 | #define OPTION_EL (OPTION_MD_BASE + 10) |
252b5132 | 9477 | {"EL", no_argument, NULL, OPTION_EL}, |
156c2f8b | 9478 | #define OPTION_M4650 (OPTION_MD_BASE + 11) |
252b5132 | 9479 | {"m4650", no_argument, NULL, OPTION_M4650}, |
156c2f8b | 9480 | #define OPTION_NO_M4650 (OPTION_MD_BASE + 12) |
252b5132 | 9481 | {"no-m4650", no_argument, NULL, OPTION_NO_M4650}, |
156c2f8b | 9482 | #define OPTION_M4010 (OPTION_MD_BASE + 13) |
252b5132 | 9483 | {"m4010", no_argument, NULL, OPTION_M4010}, |
156c2f8b | 9484 | #define OPTION_NO_M4010 (OPTION_MD_BASE + 14) |
252b5132 | 9485 | {"no-m4010", no_argument, NULL, OPTION_NO_M4010}, |
156c2f8b | 9486 | #define OPTION_M4100 (OPTION_MD_BASE + 15) |
252b5132 | 9487 | {"m4100", no_argument, NULL, OPTION_M4100}, |
156c2f8b | 9488 | #define OPTION_NO_M4100 (OPTION_MD_BASE + 16) |
252b5132 | 9489 | {"no-m4100", no_argument, NULL, OPTION_NO_M4100}, |
156c2f8b | 9490 | #define OPTION_MIPS16 (OPTION_MD_BASE + 17) |
252b5132 | 9491 | {"mips16", no_argument, NULL, OPTION_MIPS16}, |
156c2f8b | 9492 | #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 18) |
252b5132 | 9493 | {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16}, |
156c2f8b | 9494 | #define OPTION_M3900 (OPTION_MD_BASE + 19) |
252b5132 | 9495 | {"m3900", no_argument, NULL, OPTION_M3900}, |
156c2f8b | 9496 | #define OPTION_NO_M3900 (OPTION_MD_BASE + 20) |
252b5132 | 9497 | {"no-m3900", no_argument, NULL, OPTION_NO_M3900}, |
156c2f8b | 9498 | #define OPTION_MABI (OPTION_MD_BASE + 21) |
252b5132 | 9499 | {"mabi", required_argument, NULL, OPTION_MABI}, |
156c2f8b | 9500 | #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 22) |
6b76fefe | 9501 | {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX}, |
156c2f8b | 9502 | #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 23) |
6b76fefe | 9503 | {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX}, |
156c2f8b | 9504 | #define OPTION_GP32 (OPTION_MD_BASE + 24) |
c97ef257 | 9505 | {"mgp32", no_argument, NULL, OPTION_GP32}, |
156c2f8b | 9506 | #define OPTION_GP64 (OPTION_MD_BASE + 25) |
c97ef257 | 9507 | {"mgp64", no_argument, NULL, OPTION_GP64}, |
156c2f8b | 9508 | #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 26) |
119d663a | 9509 | {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS}, |
156c2f8b | 9510 | #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 27) |
119d663a | 9511 | {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS}, |
156c2f8b NC |
9512 | #define OPTION_MIPS32 (OPTION_MD_BASE + 28) |
9513 | {"mips32", no_argument, NULL, OPTION_MIPS32}, | |
84ea6cf2 NC |
9514 | #define OPTION_MIPS5 (OPTION_MD_BASE + 29) |
9515 | {"mips5", no_argument, NULL, OPTION_MIPS5}, | |
9516 | #define OPTION_MIPS64 (OPTION_MD_BASE + 30) | |
9517 | {"mips64", no_argument, NULL, OPTION_MIPS64}, | |
ec68c924 EC |
9518 | #define OPTION_MARCH (OPTION_MD_BASE + 31) |
9519 | {"march", required_argument, NULL, OPTION_MARCH}, | |
9520 | #define OPTION_MTUNE (OPTION_MD_BASE + 32) | |
9521 | {"mtune", required_argument, NULL, OPTION_MTUNE}, | |
ca4e0257 RS |
9522 | #define OPTION_FP32 (OPTION_MD_BASE + 33) |
9523 | {"mfp32", no_argument, NULL, OPTION_FP32}, | |
156c2f8b NC |
9524 | #ifdef OBJ_ELF |
9525 | #define OPTION_ELF_BASE (OPTION_MD_BASE + 35) | |
9526 | #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0) | |
9527 | #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1) | |
9528 | #define OPTION_XGOT (OPTION_ELF_BASE + 2) | |
9529 | #define OPTION_32 (OPTION_ELF_BASE + 3) | |
e013f690 TS |
9530 | #define OPTION_N32 (OPTION_ELF_BASE + 4) |
9531 | #define OPTION_64 (OPTION_ELF_BASE + 5) | |
156c2f8b NC |
9532 | {"KPIC", no_argument, NULL, OPTION_CALL_SHARED}, |
9533 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, | |
9534 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, | |
9535 | {"xgot", no_argument, NULL, OPTION_XGOT}, | |
9536 | {"32", no_argument, NULL, OPTION_32}, | |
e013f690 | 9537 | {"n32", no_argument, NULL, OPTION_N32}, |
156c2f8b NC |
9538 | {"64", no_argument, NULL, OPTION_64}, |
9539 | #endif | |
119d663a | 9540 | |
252b5132 RH |
9541 | {NULL, no_argument, NULL, 0} |
9542 | }; | |
156c2f8b | 9543 | size_t md_longopts_size = sizeof (md_longopts); |
252b5132 RH |
9544 | |
9545 | int | |
9546 | md_parse_option (c, arg) | |
9547 | int c; | |
9548 | char *arg; | |
9549 | { | |
9550 | switch (c) | |
9551 | { | |
119d663a NC |
9552 | case OPTION_CONSTRUCT_FLOATS: |
9553 | mips_disable_float_construction = 0; | |
9554 | break; | |
bdaaa2e1 | 9555 | |
119d663a NC |
9556 | case OPTION_NO_CONSTRUCT_FLOATS: |
9557 | mips_disable_float_construction = 1; | |
9558 | break; | |
bdaaa2e1 | 9559 | |
252b5132 RH |
9560 | case OPTION_TRAP: |
9561 | mips_trap = 1; | |
9562 | break; | |
9563 | ||
9564 | case OPTION_BREAK: | |
9565 | mips_trap = 0; | |
9566 | break; | |
9567 | ||
9568 | case OPTION_EB: | |
9569 | target_big_endian = 1; | |
9570 | break; | |
9571 | ||
9572 | case OPTION_EL: | |
9573 | target_big_endian = 0; | |
9574 | break; | |
9575 | ||
39c0a331 L |
9576 | case 'n': |
9577 | warn_nops = 1; | |
9578 | break; | |
9579 | ||
252b5132 RH |
9580 | case 'O': |
9581 | if (arg && arg[1] == '0') | |
9582 | mips_optimize = 1; | |
9583 | else | |
9584 | mips_optimize = 2; | |
9585 | break; | |
9586 | ||
9587 | case 'g': | |
9588 | if (arg == NULL) | |
9589 | mips_debug = 2; | |
9590 | else | |
9591 | mips_debug = atoi (arg); | |
9592 | /* When the MIPS assembler sees -g or -g2, it does not do | |
9593 | optimizations which limit full symbolic debugging. We take | |
9594 | that to be equivalent to -O0. */ | |
9595 | if (mips_debug == 2) | |
9596 | mips_optimize = 1; | |
9597 | break; | |
9598 | ||
9599 | case OPTION_MIPS1: | |
e7af610e | 9600 | mips_opts.isa = ISA_MIPS1; |
252b5132 RH |
9601 | break; |
9602 | ||
9603 | case OPTION_MIPS2: | |
e7af610e | 9604 | mips_opts.isa = ISA_MIPS2; |
252b5132 RH |
9605 | break; |
9606 | ||
9607 | case OPTION_MIPS3: | |
e7af610e | 9608 | mips_opts.isa = ISA_MIPS3; |
252b5132 RH |
9609 | break; |
9610 | ||
9611 | case OPTION_MIPS4: | |
e7af610e NC |
9612 | mips_opts.isa = ISA_MIPS4; |
9613 | break; | |
9614 | ||
84ea6cf2 NC |
9615 | case OPTION_MIPS5: |
9616 | mips_opts.isa = ISA_MIPS5; | |
9617 | break; | |
9618 | ||
e7af610e NC |
9619 | case OPTION_MIPS32: |
9620 | mips_opts.isa = ISA_MIPS32; | |
252b5132 RH |
9621 | break; |
9622 | ||
84ea6cf2 NC |
9623 | case OPTION_MIPS64: |
9624 | mips_opts.isa = ISA_MIPS64; | |
9625 | break; | |
9626 | ||
ec68c924 EC |
9627 | case OPTION_MTUNE: |
9628 | case OPTION_MARCH: | |
252b5132 RH |
9629 | case OPTION_MCPU: |
9630 | { | |
ec68c924 EC |
9631 | int cpu = CPU_UNKNOWN; |
9632 | ||
e7af610e | 9633 | /* Identify the processor type. */ |
ec68c924 | 9634 | if (strcasecmp (arg, "default") != 0) |
252b5132 | 9635 | { |
e7af610e | 9636 | const struct mips_cpu_info *ci; |
252b5132 | 9637 | |
e7af610e NC |
9638 | ci = mips_cpu_info_from_name (arg); |
9639 | if (ci == NULL || ci->is_isa) | |
ec68c924 EC |
9640 | { |
9641 | switch (c) | |
9642 | { | |
9643 | case OPTION_MTUNE: | |
9644 | as_fatal (_("invalid architecture -mtune=%s"), arg); | |
9645 | break; | |
9646 | case OPTION_MARCH: | |
9647 | as_fatal (_("invalid architecture -march=%s"), arg); | |
9648 | break; | |
9649 | case OPTION_MCPU: | |
9650 | as_fatal (_("invalid architecture -mcpu=%s"), arg); | |
9651 | break; | |
9652 | } | |
9653 | } | |
e7af610e | 9654 | else |
ec68c924 EC |
9655 | cpu = ci->cpu; |
9656 | } | |
9657 | ||
9658 | switch (c) | |
9659 | { | |
9660 | case OPTION_MTUNE: | |
6dce9e24 TS |
9661 | if (mips_tune != CPU_UNKNOWN && mips_tune != cpu) |
9662 | as_warn(_("A different -mtune= was already specified, is now " | |
9663 | "-mtune=%s"), arg); | |
ec68c924 EC |
9664 | mips_tune = cpu; |
9665 | break; | |
9666 | case OPTION_MARCH: | |
6dce9e24 TS |
9667 | if (mips_arch != CPU_UNKNOWN && mips_arch != cpu) |
9668 | as_warn(_("A different -march= was already specified, is now " | |
9669 | "-march=%s"), arg); | |
ec68c924 EC |
9670 | mips_arch = cpu; |
9671 | break; | |
9672 | case OPTION_MCPU: | |
6dce9e24 TS |
9673 | if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu) |
9674 | as_warn(_("A different -mcpu= was already specified, is now " | |
9675 | "-mcpu=%s"), arg); | |
ec68c924 | 9676 | mips_cpu = cpu; |
252b5132 RH |
9677 | } |
9678 | } | |
9679 | break; | |
9680 | ||
9681 | case OPTION_M4650: | |
6dce9e24 TS |
9682 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650) |
9683 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650)) | |
9684 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9685 | "is now -m4650")); | |
ec68c924 EC |
9686 | mips_arch = CPU_R4650; |
9687 | mips_tune = CPU_R4650; | |
252b5132 RH |
9688 | break; |
9689 | ||
9690 | case OPTION_NO_M4650: | |
9691 | break; | |
9692 | ||
9693 | case OPTION_M4010: | |
6dce9e24 TS |
9694 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010) |
9695 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010)) | |
9696 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9697 | "is now -m4010")); | |
ec68c924 EC |
9698 | mips_arch = CPU_R4010; |
9699 | mips_tune = CPU_R4010; | |
252b5132 RH |
9700 | break; |
9701 | ||
9702 | case OPTION_NO_M4010: | |
9703 | break; | |
9704 | ||
9705 | case OPTION_M4100: | |
6dce9e24 TS |
9706 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100) |
9707 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100)) | |
9708 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9709 | "is now -m4100")); | |
ec68c924 EC |
9710 | mips_arch = CPU_VR4100; |
9711 | mips_tune = CPU_VR4100; | |
252b5132 RH |
9712 | break; |
9713 | ||
9714 | case OPTION_NO_M4100: | |
9715 | break; | |
9716 | ||
252b5132 | 9717 | case OPTION_M3900: |
6dce9e24 TS |
9718 | if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900) |
9719 | || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900)) | |
9720 | as_warn(_("A different -march= or -mtune= was already specified, " | |
9721 | "is now -m3900")); | |
ec68c924 EC |
9722 | mips_arch = CPU_R3900; |
9723 | mips_tune = CPU_R3900; | |
252b5132 | 9724 | break; |
bdaaa2e1 | 9725 | |
252b5132 RH |
9726 | case OPTION_NO_M3900: |
9727 | break; | |
9728 | ||
9729 | case OPTION_MIPS16: | |
9730 | mips_opts.mips16 = 1; | |
9731 | mips_no_prev_insn (false); | |
9732 | break; | |
9733 | ||
9734 | case OPTION_NO_MIPS16: | |
9735 | mips_opts.mips16 = 0; | |
9736 | mips_no_prev_insn (false); | |
9737 | break; | |
9738 | ||
9739 | case OPTION_MEMBEDDED_PIC: | |
9740 | mips_pic = EMBEDDED_PIC; | |
9741 | if (USE_GLOBAL_POINTER_OPT && g_switch_seen) | |
9742 | { | |
9743 | as_bad (_("-G may not be used with embedded PIC code")); | |
9744 | return 0; | |
9745 | } | |
9746 | g_switch_value = 0x7fffffff; | |
9747 | break; | |
9748 | ||
0f074f60 | 9749 | #ifdef OBJ_ELF |
252b5132 RH |
9750 | /* When generating ELF code, we permit -KPIC and -call_shared to |
9751 | select SVR4_PIC, and -non_shared to select no PIC. This is | |
9752 | intended to be compatible with Irix 5. */ | |
9753 | case OPTION_CALL_SHARED: | |
9754 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9755 | { | |
9756 | as_bad (_("-call_shared is supported only for ELF format")); | |
9757 | return 0; | |
9758 | } | |
9759 | mips_pic = SVR4_PIC; | |
9760 | if (g_switch_seen && g_switch_value != 0) | |
9761 | { | |
9762 | as_bad (_("-G may not be used with SVR4 PIC code")); | |
9763 | return 0; | |
9764 | } | |
9765 | g_switch_value = 0; | |
9766 | break; | |
9767 | ||
9768 | case OPTION_NON_SHARED: | |
9769 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9770 | { | |
9771 | as_bad (_("-non_shared is supported only for ELF format")); | |
9772 | return 0; | |
9773 | } | |
9774 | mips_pic = NO_PIC; | |
9775 | break; | |
9776 | ||
9777 | /* The -xgot option tells the assembler to use 32 offsets when | |
9778 | accessing the got in SVR4_PIC mode. It is for Irix | |
9779 | compatibility. */ | |
9780 | case OPTION_XGOT: | |
9781 | mips_big_got = 1; | |
9782 | break; | |
0f074f60 | 9783 | #endif /* OBJ_ELF */ |
252b5132 RH |
9784 | |
9785 | case 'G': | |
9786 | if (! USE_GLOBAL_POINTER_OPT) | |
9787 | { | |
9788 | as_bad (_("-G is not supported for this configuration")); | |
9789 | return 0; | |
9790 | } | |
9791 | else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC) | |
9792 | { | |
9793 | as_bad (_("-G may not be used with SVR4 or embedded PIC code")); | |
9794 | return 0; | |
9795 | } | |
9796 | else | |
9797 | g_switch_value = atoi (arg); | |
9798 | g_switch_seen = 1; | |
9799 | break; | |
9800 | ||
0f074f60 | 9801 | #ifdef OBJ_ELF |
252b5132 RH |
9802 | /* The -32 and -64 options tell the assembler to output the 32 |
9803 | bit or the 64 bit MIPS ELF format. */ | |
9804 | case OPTION_32: | |
e013f690 | 9805 | mips_abi = O32_ABI; |
252b5132 RH |
9806 | break; |
9807 | ||
e013f690 TS |
9808 | case OPTION_N32: |
9809 | mips_abi = N32_ABI; | |
9810 | break; | |
252b5132 | 9811 | |
e013f690 TS |
9812 | case OPTION_64: |
9813 | mips_abi = N64_ABI; | |
9814 | if (! support_64bit_objects()) | |
9815 | as_fatal (_("No compiled in support for 64 bit object file format")); | |
252b5132 RH |
9816 | break; |
9817 | ||
c97ef257 AH |
9818 | case OPTION_GP32: |
9819 | mips_gp32 = 1; | |
e013f690 TS |
9820 | if (mips_abi != O32_ABI) |
9821 | mips_abi = NO_ABI; | |
c97ef257 AH |
9822 | break; |
9823 | ||
9824 | case OPTION_GP64: | |
9825 | mips_gp32 = 0; | |
e013f690 TS |
9826 | if (mips_abi == O32_ABI) |
9827 | mips_abi = NO_ABI; | |
c97ef257 | 9828 | break; |
252b5132 | 9829 | |
ca4e0257 RS |
9830 | case OPTION_FP32: |
9831 | mips_fp32 = 1; | |
e013f690 TS |
9832 | if (mips_abi != O32_ABI) |
9833 | mips_abi = NO_ABI; | |
ca4e0257 RS |
9834 | break; |
9835 | ||
252b5132 | 9836 | case OPTION_MABI: |
e013f690 TS |
9837 | if (strcmp (arg, "32") == 0) |
9838 | mips_abi = O32_ABI; | |
9839 | else if (strcmp (arg, "o64") == 0) | |
9840 | mips_abi = O64_ABI; | |
9841 | else if (strcmp (arg, "n32") == 0) | |
9842 | mips_abi = N32_ABI; | |
9843 | else if (strcmp (arg, "64") == 0) | |
9844 | { | |
9845 | mips_abi = N64_ABI; | |
9846 | if (! support_64bit_objects()) | |
9847 | as_fatal (_("No compiled in support for 64 bit object file " | |
9848 | "format")); | |
9849 | } | |
9850 | else if (strcmp (arg, "eabi") == 0) | |
9851 | mips_abi = EABI_ABI; | |
9852 | else | |
9853 | mips_abi = NO_ABI; | |
252b5132 | 9854 | break; |
e013f690 | 9855 | #endif /* OBJ_ELF */ |
252b5132 | 9856 | |
6b76fefe CM |
9857 | case OPTION_M7000_HILO_FIX: |
9858 | mips_7000_hilo_fix = true; | |
9859 | break; | |
9860 | ||
9861 | case OPTION_NO_M7000_HILO_FIX: | |
9862 | mips_7000_hilo_fix = false; | |
9863 | break; | |
9864 | ||
252b5132 RH |
9865 | default: |
9866 | return 0; | |
9867 | } | |
9868 | ||
9869 | return 1; | |
9870 | } | |
9871 | ||
252b5132 RH |
9872 | static void |
9873 | show (stream, string, col_p, first_p) | |
9874 | FILE *stream; | |
9875 | char *string; | |
9876 | int *col_p; | |
9877 | int *first_p; | |
9878 | { | |
9879 | if (*first_p) | |
9880 | { | |
9881 | fprintf (stream, "%24s", ""); | |
9882 | *col_p = 24; | |
9883 | } | |
9884 | else | |
9885 | { | |
9886 | fprintf (stream, ", "); | |
9887 | *col_p += 2; | |
9888 | } | |
9889 | ||
9890 | if (*col_p + strlen (string) > 72) | |
9891 | { | |
9892 | fprintf (stream, "\n%24s", ""); | |
9893 | *col_p = 24; | |
9894 | } | |
9895 | ||
9896 | fprintf (stream, "%s", string); | |
9897 | *col_p += strlen (string); | |
9898 | ||
9899 | *first_p = 0; | |
9900 | } | |
9901 | ||
252b5132 RH |
9902 | void |
9903 | md_show_usage (stream) | |
9904 | FILE *stream; | |
9905 | { | |
9906 | int column, first; | |
9907 | ||
beae10d5 | 9908 | fprintf (stream, _("\ |
252b5132 RH |
9909 | MIPS options:\n\ |
9910 | -membedded-pic generate embedded position independent code\n\ | |
9911 | -EB generate big endian output\n\ | |
9912 | -EL generate little endian output\n\ | |
9a41af64 | 9913 | -g, -g2 do not remove unneeded NOPs or swap branches\n\ |
252b5132 RH |
9914 | -G NUM allow referencing objects up to NUM bytes\n\ |
9915 | implicitly with the gp register [default 8]\n")); | |
beae10d5 | 9916 | fprintf (stream, _("\ |
252b5132 RH |
9917 | -mips1 generate MIPS ISA I instructions\n\ |
9918 | -mips2 generate MIPS ISA II instructions\n\ | |
9919 | -mips3 generate MIPS ISA III instructions\n\ | |
9920 | -mips4 generate MIPS ISA IV instructions\n\ | |
84ea6cf2 | 9921 | -mips5 generate MIPS ISA V instructions\n\ |
e7af610e | 9922 | -mips32 generate MIPS32 ISA instructions\n\ |
84ea6cf2 | 9923 | -mips64 generate MIPS64 ISA instructions\n\ |
ec68c924 | 9924 | -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n")); |
252b5132 RH |
9925 | |
9926 | first = 1; | |
9927 | ||
9928 | show (stream, "2000", &column, &first); | |
9929 | show (stream, "3000", &column, &first); | |
9930 | show (stream, "3900", &column, &first); | |
9931 | show (stream, "4000", &column, &first); | |
9932 | show (stream, "4010", &column, &first); | |
9933 | show (stream, "4100", &column, &first); | |
9934 | show (stream, "4111", &column, &first); | |
9935 | show (stream, "4300", &column, &first); | |
9936 | show (stream, "4400", &column, &first); | |
9937 | show (stream, "4600", &column, &first); | |
9938 | show (stream, "4650", &column, &first); | |
9939 | show (stream, "5000", &column, &first); | |
18ae5d72 EC |
9940 | show (stream, "5200", &column, &first); |
9941 | show (stream, "5230", &column, &first); | |
9942 | show (stream, "5231", &column, &first); | |
9943 | show (stream, "5261", &column, &first); | |
9944 | show (stream, "5721", &column, &first); | |
252b5132 RH |
9945 | show (stream, "6000", &column, &first); |
9946 | show (stream, "8000", &column, &first); | |
9947 | show (stream, "10000", &column, &first); | |
d1cf510e | 9948 | show (stream, "12000", &column, &first); |
2e4acd24 | 9949 | show (stream, "sb1", &column, &first); |
252b5132 RH |
9950 | fputc ('\n', stream); |
9951 | ||
9952 | fprintf (stream, _("\ | |
ec68c924 | 9953 | -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\ |
252b5132 RH |
9954 | -no-mCPU don't generate code specific to CPU.\n\ |
9955 | For -mCPU and -no-mCPU, CPU must be one of:\n")); | |
9956 | ||
9957 | first = 1; | |
9958 | ||
9959 | show (stream, "3900", &column, &first); | |
9960 | show (stream, "4010", &column, &first); | |
9961 | show (stream, "4100", &column, &first); | |
9962 | show (stream, "4650", &column, &first); | |
9963 | fputc ('\n', stream); | |
9964 | ||
beae10d5 | 9965 | fprintf (stream, _("\ |
252b5132 RH |
9966 | -mips16 generate mips16 instructions\n\ |
9967 | -no-mips16 do not generate mips16 instructions\n")); | |
beae10d5 | 9968 | fprintf (stream, _("\ |
ca4e0257 RS |
9969 | -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\ |
9970 | -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\ | |
252b5132 RH |
9971 | -O0 remove unneeded NOPs, do not swap branches\n\ |
9972 | -O remove unneeded NOPs and swap branches\n\ | |
63486801 | 9973 | -n warn about NOPs generated from macros\n\ |
119d663a | 9974 | --[no-]construct-floats [dis]allow floating point values to be constructed\n\ |
252b5132 RH |
9975 | --trap, --no-break trap exception on div by 0 and mult overflow\n\ |
9976 | --break, --no-trap break exception on div by 0 and mult overflow\n")); | |
9977 | #ifdef OBJ_ELF | |
beae10d5 | 9978 | fprintf (stream, _("\ |
252b5132 RH |
9979 | -KPIC, -call_shared generate SVR4 position independent code\n\ |
9980 | -non_shared do not generate position independent code\n\ | |
9981 | -xgot assume a 32 bit GOT\n\ | |
e013f690 TS |
9982 | -32 create o32 ABI object file (default)\n\ |
9983 | -n32 create n32 ABI object file\n\ | |
9984 | -64 create 64 ABI object file\n")); | |
252b5132 RH |
9985 | #endif |
9986 | } | |
9987 | \f | |
9988 | void | |
9989 | mips_init_after_args () | |
9990 | { | |
9991 | /* initialize opcodes */ | |
9992 | bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes; | |
beae10d5 | 9993 | mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes; |
252b5132 RH |
9994 | } |
9995 | ||
9996 | long | |
9997 | md_pcrel_from (fixP) | |
9998 | fixS *fixP; | |
9999 | { | |
10000 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour | |
10001 | && fixP->fx_addsy != (symbolS *) NULL | |
10002 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
10003 | { | |
6478892d TS |
10004 | /* This makes a branch to an undefined symbol be a branch to the |
10005 | current location. */ | |
cb56d3d3 | 10006 | if (mips_pic == EMBEDDED_PIC) |
6478892d | 10007 | return 4; |
cb56d3d3 | 10008 | else |
6478892d | 10009 | return 1; |
252b5132 RH |
10010 | } |
10011 | ||
10012 | /* return the address of the delay slot */ | |
10013 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; | |
10014 | } | |
10015 | ||
252b5132 RH |
10016 | /* This is called before the symbol table is processed. In order to |
10017 | work with gcc when using mips-tfile, we must keep all local labels. | |
10018 | However, in other cases, we want to discard them. If we were | |
10019 | called with -g, but we didn't see any debugging information, it may | |
10020 | mean that gcc is smuggling debugging information through to | |
10021 | mips-tfile, in which case we must generate all local labels. */ | |
10022 | ||
10023 | void | |
10024 | mips_frob_file_before_adjust () | |
10025 | { | |
10026 | #ifndef NO_ECOFF_DEBUGGING | |
10027 | if (ECOFF_DEBUGGING | |
10028 | && mips_debug != 0 | |
10029 | && ! ecoff_debugging_seen) | |
10030 | flag_keep_locals = 1; | |
10031 | #endif | |
10032 | } | |
10033 | ||
10034 | /* Sort any unmatched HI16_S relocs so that they immediately precede | |
10035 | the corresponding LO reloc. This is called before md_apply_fix and | |
10036 | tc_gen_reloc. Unmatched HI16_S relocs can only be generated by | |
10037 | explicit use of the %hi modifier. */ | |
10038 | ||
10039 | void | |
10040 | mips_frob_file () | |
10041 | { | |
10042 | struct mips_hi_fixup *l; | |
10043 | ||
10044 | for (l = mips_hi_fixup_list; l != NULL; l = l->next) | |
10045 | { | |
10046 | segment_info_type *seginfo; | |
10047 | int pass; | |
10048 | ||
10049 | assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S); | |
10050 | ||
10051 | /* Check quickly whether the next fixup happens to be a matching | |
10052 | %lo. */ | |
10053 | if (l->fixp->fx_next != NULL | |
10054 | && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16 | |
10055 | && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy | |
10056 | && l->fixp->fx_offset == l->fixp->fx_next->fx_offset) | |
10057 | continue; | |
10058 | ||
10059 | /* Look through the fixups for this segment for a matching %lo. | |
10060 | When we find one, move the %hi just in front of it. We do | |
10061 | this in two passes. In the first pass, we try to find a | |
10062 | unique %lo. In the second pass, we permit multiple %hi | |
10063 | relocs for a single %lo (this is a GNU extension). */ | |
10064 | seginfo = seg_info (l->seg); | |
10065 | for (pass = 0; pass < 2; pass++) | |
10066 | { | |
10067 | fixS *f, *prev; | |
10068 | ||
10069 | prev = NULL; | |
10070 | for (f = seginfo->fix_root; f != NULL; f = f->fx_next) | |
10071 | { | |
10072 | /* Check whether this is a %lo fixup which matches l->fixp. */ | |
10073 | if (f->fx_r_type == BFD_RELOC_LO16 | |
10074 | && f->fx_addsy == l->fixp->fx_addsy | |
10075 | && f->fx_offset == l->fixp->fx_offset | |
10076 | && (pass == 1 | |
10077 | || prev == NULL | |
10078 | || prev->fx_r_type != BFD_RELOC_HI16_S | |
10079 | || prev->fx_addsy != f->fx_addsy | |
10080 | || prev->fx_offset != f->fx_offset)) | |
10081 | { | |
10082 | fixS **pf; | |
10083 | ||
10084 | /* Move l->fixp before f. */ | |
10085 | for (pf = &seginfo->fix_root; | |
10086 | *pf != l->fixp; | |
10087 | pf = &(*pf)->fx_next) | |
10088 | assert (*pf != NULL); | |
10089 | ||
10090 | *pf = l->fixp->fx_next; | |
10091 | ||
10092 | l->fixp->fx_next = f; | |
10093 | if (prev == NULL) | |
10094 | seginfo->fix_root = l->fixp; | |
10095 | else | |
10096 | prev->fx_next = l->fixp; | |
10097 | ||
10098 | break; | |
10099 | } | |
10100 | ||
10101 | prev = f; | |
10102 | } | |
10103 | ||
10104 | if (f != NULL) | |
10105 | break; | |
10106 | ||
10107 | #if 0 /* GCC code motion plus incomplete dead code elimination | |
10108 | can leave a %hi without a %lo. */ | |
10109 | if (pass == 1) | |
10110 | as_warn_where (l->fixp->fx_file, l->fixp->fx_line, | |
10111 | _("Unmatched %%hi reloc")); | |
10112 | #endif | |
10113 | } | |
10114 | } | |
10115 | } | |
10116 | ||
10117 | /* When generating embedded PIC code we need to use a special | |
10118 | relocation to represent the difference of two symbols in the .text | |
10119 | section (switch tables use a difference of this sort). See | |
10120 | include/coff/mips.h for details. This macro checks whether this | |
10121 | fixup requires the special reloc. */ | |
10122 | #define SWITCH_TABLE(fixp) \ | |
10123 | ((fixp)->fx_r_type == BFD_RELOC_32 \ | |
bb2d6cd7 | 10124 | && OUTPUT_FLAVOR != bfd_target_elf_flavour \ |
252b5132 RH |
10125 | && (fixp)->fx_addsy != NULL \ |
10126 | && (fixp)->fx_subsy != NULL \ | |
10127 | && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \ | |
10128 | && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section) | |
10129 | ||
10130 | /* When generating embedded PIC code we must keep all PC relative | |
10131 | relocations, in case the linker has to relax a call. We also need | |
f6688943 TS |
10132 | to keep relocations for switch table entries. |
10133 | ||
10134 | We may have combined relocations without symbols in the N32/N64 ABI. | |
10135 | We have to prevent gas from dropping them. */ | |
252b5132 | 10136 | |
252b5132 RH |
10137 | int |
10138 | mips_force_relocation (fixp) | |
10139 | fixS *fixp; | |
10140 | { | |
10141 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
10142 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
10143 | return 1; | |
10144 | ||
f6688943 TS |
10145 | if (HAVE_NEWABI |
10146 | && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr | |
10147 | && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB | |
10148 | || fixp->fx_r_type == BFD_RELOC_HI16_S | |
10149 | || fixp->fx_r_type == BFD_RELOC_LO16)) | |
10150 | return 1; | |
10151 | ||
252b5132 RH |
10152 | return (mips_pic == EMBEDDED_PIC |
10153 | && (fixp->fx_pcrel | |
10154 | || SWITCH_TABLE (fixp) | |
10155 | || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S | |
10156 | || fixp->fx_r_type == BFD_RELOC_PCREL_LO16)); | |
10157 | } | |
10158 | ||
10159 | /* Apply a fixup to the object file. */ | |
10160 | ||
10161 | int | |
10162 | md_apply_fix (fixP, valueP) | |
10163 | fixS *fixP; | |
10164 | valueT *valueP; | |
10165 | { | |
10166 | unsigned char *buf; | |
98aa84af AM |
10167 | long insn; |
10168 | valueT value; | |
252b5132 RH |
10169 | |
10170 | assert (fixP->fx_size == 4 | |
10171 | || fixP->fx_r_type == BFD_RELOC_16 | |
f6688943 TS |
10172 | || fixP->fx_r_type == BFD_RELOC_32 |
10173 | || fixP->fx_r_type == BFD_RELOC_MIPS_JMP | |
10174 | || fixP->fx_r_type == BFD_RELOC_HI16_S | |
10175 | || fixP->fx_r_type == BFD_RELOC_LO16 | |
10176 | || fixP->fx_r_type == BFD_RELOC_GPREL16 | |
76b3015f | 10177 | || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL |
f6688943 | 10178 | || fixP->fx_r_type == BFD_RELOC_GPREL32 |
252b5132 | 10179 | || fixP->fx_r_type == BFD_RELOC_64 |
f6688943 TS |
10180 | || fixP->fx_r_type == BFD_RELOC_CTOR |
10181 | || fixP->fx_r_type == BFD_RELOC_MIPS_SUB | |
10182 | || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST | |
10183 | || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER | |
10184 | || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP | |
10185 | || fixP->fx_r_type == BFD_RELOC_MIPS_REL16 | |
10186 | || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT | |
252b5132 RH |
10187 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
10188 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY); | |
10189 | ||
10190 | value = *valueP; | |
10191 | ||
10192 | /* If we aren't adjusting this fixup to be against the section | |
10193 | symbol, we need to adjust the value. */ | |
10194 | #ifdef OBJ_ELF | |
10195 | if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
bb2d6cd7 | 10196 | { |
98aa84af | 10197 | if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16 |
ea4ff978 L |
10198 | || ((S_IS_WEAK (fixP->fx_addsy) |
10199 | || S_IS_EXTERN (fixP->fx_addsy)) | |
10200 | && !S_IS_COMMON (fixP->fx_addsy)) | |
98aa84af AM |
10201 | || (symbol_used_in_reloc_p (fixP->fx_addsy) |
10202 | && (((bfd_get_section_flags (stdoutput, | |
10203 | S_GET_SEGMENT (fixP->fx_addsy)) | |
10204 | & SEC_LINK_ONCE) != 0) | |
10205 | || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)), | |
10206 | ".gnu.linkonce", | |
10207 | sizeof (".gnu.linkonce") - 1)))) | |
252b5132 | 10208 | |
98aa84af AM |
10209 | { |
10210 | valueT symval = S_GET_VALUE (fixP->fx_addsy); | |
10211 | value -= symval; | |
236bd878 RS |
10212 | if (value != 0 |
10213 | && ! fixP->fx_pcrel | |
10214 | && fixP->fx_r_type != BFD_RELOC_MIPS_GPREL) | |
98aa84af AM |
10215 | { |
10216 | /* In this case, the bfd_install_relocation routine will | |
10217 | incorrectly add the symbol value back in. We just want | |
7461da6e | 10218 | the addend to appear in the object file. */ |
98aa84af | 10219 | value -= symval; |
7461da6e RS |
10220 | |
10221 | /* Make sure the addend is still non-zero. If it became zero | |
10222 | after the last operation, set it to a spurious value and | |
10223 | subtract the same value from the object file's contents. */ | |
10224 | if (value == 0) | |
10225 | { | |
10226 | value = 8; | |
10227 | ||
10228 | /* The in-place addends for LO16 relocations are signed; | |
10229 | leave the matching HI16 in-place addends as zero. */ | |
10230 | if (fixP->fx_r_type != BFD_RELOC_HI16_S) | |
10231 | { | |
10232 | reloc_howto_type *howto; | |
10233 | bfd_vma contents, mask, field; | |
10234 | ||
10235 | howto = bfd_reloc_type_lookup (stdoutput, | |
10236 | fixP->fx_r_type); | |
10237 | ||
10238 | contents = bfd_get_bits (fixP->fx_frag->fr_literal | |
10239 | + fixP->fx_where, | |
10240 | fixP->fx_size * 8, | |
10241 | target_big_endian); | |
10242 | ||
10243 | /* MASK has bits set where the relocation should go. | |
10244 | FIELD is -value, shifted into the appropriate place | |
10245 | for this relocation. */ | |
10246 | mask = 1 << (howto->bitsize - 1); | |
10247 | mask = (((mask - 1) << 1) | 1) << howto->bitpos; | |
10248 | field = (-value >> howto->rightshift) << howto->bitpos; | |
10249 | ||
10250 | bfd_put_bits ((field & mask) | (contents & ~mask), | |
10251 | fixP->fx_frag->fr_literal + fixP->fx_where, | |
10252 | fixP->fx_size * 8, | |
10253 | target_big_endian); | |
10254 | } | |
10255 | } | |
98aa84af AM |
10256 | } |
10257 | } | |
252b5132 | 10258 | |
bb2d6cd7 GK |
10259 | /* This code was generated using trial and error and so is |
10260 | fragile and not trustworthy. If you change it, you should | |
10261 | rerun the elf-rel, elf-rel2, and empic testcases and ensure | |
10262 | they still pass. */ | |
10263 | if (fixP->fx_pcrel || fixP->fx_subsy != NULL) | |
10264 | { | |
10265 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
10266 | ||
10267 | /* BFD's REL handling, for MIPS, is _very_ weird. | |
10268 | This gives the right results, but it can't possibly | |
10269 | be the way things are supposed to work. */ | |
cb56d3d3 TS |
10270 | if ((fixP->fx_r_type != BFD_RELOC_16_PCREL |
10271 | && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2) | |
bb2d6cd7 GK |
10272 | || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section) |
10273 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
10274 | } | |
10275 | } | |
10276 | #endif | |
252b5132 RH |
10277 | |
10278 | fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */ | |
10279 | ||
10280 | if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel) | |
10281 | fixP->fx_done = 1; | |
10282 | ||
10283 | switch (fixP->fx_r_type) | |
10284 | { | |
10285 | case BFD_RELOC_MIPS_JMP: | |
e369bcce TS |
10286 | case BFD_RELOC_MIPS_SHIFT5: |
10287 | case BFD_RELOC_MIPS_SHIFT6: | |
10288 | case BFD_RELOC_MIPS_GOT_DISP: | |
10289 | case BFD_RELOC_MIPS_GOT_PAGE: | |
10290 | case BFD_RELOC_MIPS_GOT_OFST: | |
10291 | case BFD_RELOC_MIPS_SUB: | |
10292 | case BFD_RELOC_MIPS_INSERT_A: | |
10293 | case BFD_RELOC_MIPS_INSERT_B: | |
10294 | case BFD_RELOC_MIPS_DELETE: | |
10295 | case BFD_RELOC_MIPS_HIGHEST: | |
10296 | case BFD_RELOC_MIPS_HIGHER: | |
10297 | case BFD_RELOC_MIPS_SCN_DISP: | |
10298 | case BFD_RELOC_MIPS_REL16: | |
10299 | case BFD_RELOC_MIPS_RELGOT: | |
10300 | case BFD_RELOC_MIPS_JALR: | |
252b5132 RH |
10301 | case BFD_RELOC_HI16: |
10302 | case BFD_RELOC_HI16_S: | |
10303 | case BFD_RELOC_MIPS_GPREL: | |
10304 | case BFD_RELOC_MIPS_LITERAL: | |
10305 | case BFD_RELOC_MIPS_CALL16: | |
10306 | case BFD_RELOC_MIPS_GOT16: | |
10307 | case BFD_RELOC_MIPS_GPREL32: | |
10308 | case BFD_RELOC_MIPS_GOT_HI16: | |
10309 | case BFD_RELOC_MIPS_GOT_LO16: | |
10310 | case BFD_RELOC_MIPS_CALL_HI16: | |
10311 | case BFD_RELOC_MIPS_CALL_LO16: | |
10312 | case BFD_RELOC_MIPS16_GPREL: | |
10313 | if (fixP->fx_pcrel) | |
10314 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
10315 | _("Invalid PC relative reloc")); | |
10316 | /* Nothing needed to do. The value comes from the reloc entry */ | |
10317 | break; | |
10318 | ||
10319 | case BFD_RELOC_MIPS16_JMP: | |
10320 | /* We currently always generate a reloc against a symbol, which | |
10321 | means that we don't want an addend even if the symbol is | |
10322 | defined. */ | |
10323 | fixP->fx_addnumber = 0; | |
10324 | break; | |
10325 | ||
10326 | case BFD_RELOC_PCREL_HI16_S: | |
10327 | /* The addend for this is tricky if it is internal, so we just | |
10328 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 10329 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
10330 | && !fixP->fx_done |
10331 | && value != 0) | |
10332 | break; | |
10333 | if (fixP->fx_addsy | |
10334 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
10335 | { |
10336 | /* For an external symbol adjust by the address to make it | |
10337 | pcrel_offset. We use the address of the RELLO reloc | |
10338 | which follows this one. */ | |
10339 | value += (fixP->fx_next->fx_frag->fr_address | |
10340 | + fixP->fx_next->fx_where); | |
10341 | } | |
e7d556df | 10342 | value = ((value + 0x8000) >> 16) & 0xffff; |
252b5132 RH |
10343 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; |
10344 | if (target_big_endian) | |
10345 | buf += 2; | |
10346 | md_number_to_chars (buf, value, 2); | |
10347 | break; | |
10348 | ||
10349 | case BFD_RELOC_PCREL_LO16: | |
10350 | /* The addend for this is tricky if it is internal, so we just | |
10351 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 10352 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
10353 | && !fixP->fx_done |
10354 | && value != 0) | |
10355 | break; | |
10356 | if (fixP->fx_addsy | |
10357 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
10358 | value += fixP->fx_frag->fr_address + fixP->fx_where; |
10359 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
10360 | if (target_big_endian) | |
10361 | buf += 2; | |
10362 | md_number_to_chars (buf, value, 2); | |
10363 | break; | |
10364 | ||
10365 | case BFD_RELOC_64: | |
10366 | /* This is handled like BFD_RELOC_32, but we output a sign | |
10367 | extended value if we are only 32 bits. */ | |
10368 | if (fixP->fx_done | |
10369 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
10370 | { | |
10371 | if (8 <= sizeof (valueT)) | |
10372 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
10373 | value, 8); | |
10374 | else | |
10375 | { | |
10376 | long w1, w2; | |
10377 | long hiv; | |
10378 | ||
10379 | w1 = w2 = fixP->fx_where; | |
10380 | if (target_big_endian) | |
10381 | w1 += 4; | |
10382 | else | |
10383 | w2 += 4; | |
10384 | md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4); | |
10385 | if ((value & 0x80000000) != 0) | |
10386 | hiv = 0xffffffff; | |
10387 | else | |
10388 | hiv = 0; | |
10389 | md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4); | |
10390 | } | |
10391 | } | |
10392 | break; | |
10393 | ||
056350c6 | 10394 | case BFD_RELOC_RVA: |
252b5132 RH |
10395 | case BFD_RELOC_32: |
10396 | /* If we are deleting this reloc entry, we must fill in the | |
10397 | value now. This can happen if we have a .word which is not | |
10398 | resolved when it appears but is later defined. We also need | |
10399 | to fill in the value if this is an embedded PIC switch table | |
10400 | entry. */ | |
10401 | if (fixP->fx_done | |
10402 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
10403 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
10404 | value, 4); | |
10405 | break; | |
10406 | ||
10407 | case BFD_RELOC_16: | |
10408 | /* If we are deleting this reloc entry, we must fill in the | |
10409 | value now. */ | |
10410 | assert (fixP->fx_size == 2); | |
10411 | if (fixP->fx_done) | |
10412 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
10413 | value, 2); | |
10414 | break; | |
10415 | ||
10416 | case BFD_RELOC_LO16: | |
10417 | /* When handling an embedded PIC switch statement, we can wind | |
10418 | up deleting a LO16 reloc. See the 'o' case in mips_ip. */ | |
10419 | if (fixP->fx_done) | |
10420 | { | |
98aa84af | 10421 | if (value + 0x8000 > 0xffff) |
252b5132 RH |
10422 | as_bad_where (fixP->fx_file, fixP->fx_line, |
10423 | _("relocation overflow")); | |
10424 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
10425 | if (target_big_endian) | |
10426 | buf += 2; | |
10427 | md_number_to_chars (buf, value, 2); | |
10428 | } | |
10429 | break; | |
10430 | ||
10431 | case BFD_RELOC_16_PCREL_S2: | |
cb56d3d3 TS |
10432 | if ((value & 0x3) != 0) |
10433 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
10434 | _("Branch to odd address (%lx)"), (long) value); | |
10435 | ||
10436 | /* Fall through. */ | |
10437 | ||
10438 | case BFD_RELOC_16_PCREL: | |
252b5132 RH |
10439 | /* |
10440 | * We need to save the bits in the instruction since fixup_segment() | |
10441 | * might be deleting the relocation entry (i.e., a branch within | |
10442 | * the current segment). | |
10443 | */ | |
bb2d6cd7 GK |
10444 | if (!fixP->fx_done && value != 0) |
10445 | break; | |
10446 | /* If 'value' is zero, the remaining reloc code won't actually | |
10447 | do the store, so it must be done here. This is probably | |
10448 | a bug somewhere. */ | |
10449 | if (!fixP->fx_done) | |
10450 | value -= fixP->fx_frag->fr_address + fixP->fx_where; | |
bdaaa2e1 | 10451 | |
98aa84af | 10452 | value = (offsetT) value >> 2; |
252b5132 RH |
10453 | |
10454 | /* update old instruction data */ | |
10455 | buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal); | |
10456 | if (target_big_endian) | |
10457 | insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
10458 | else | |
10459 | insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | |
10460 | ||
98aa84af | 10461 | if (value + 0x8000 <= 0xffff) |
252b5132 RH |
10462 | insn |= value & 0xffff; |
10463 | else | |
10464 | { | |
10465 | /* The branch offset is too large. If this is an | |
10466 | unconditional branch, and we are not generating PIC code, | |
10467 | we can convert it to an absolute jump instruction. */ | |
10468 | if (mips_pic == NO_PIC | |
10469 | && fixP->fx_done | |
10470 | && fixP->fx_frag->fr_address >= text_section->vma | |
10471 | && (fixP->fx_frag->fr_address | |
10472 | < text_section->vma + text_section->_raw_size) | |
10473 | && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */ | |
10474 | || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */ | |
10475 | || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */ | |
10476 | { | |
10477 | if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */ | |
10478 | insn = 0x0c000000; /* jal */ | |
10479 | else | |
10480 | insn = 0x08000000; /* j */ | |
10481 | fixP->fx_r_type = BFD_RELOC_MIPS_JMP; | |
10482 | fixP->fx_done = 0; | |
10483 | fixP->fx_addsy = section_symbol (text_section); | |
10484 | fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP); | |
10485 | } | |
10486 | else | |
10487 | { | |
10488 | /* FIXME. It would be possible in principle to handle | |
10489 | conditional branches which overflow. They could be | |
10490 | transformed into a branch around a jump. This would | |
10491 | require setting up variant frags for each different | |
10492 | branch type. The native MIPS assembler attempts to | |
10493 | handle these cases, but it appears to do it | |
10494 | incorrectly. */ | |
10495 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
10496 | _("Branch out of range")); | |
10497 | } | |
10498 | } | |
10499 | ||
10500 | md_number_to_chars ((char *) buf, (valueT) insn, 4); | |
10501 | break; | |
10502 | ||
10503 | case BFD_RELOC_VTABLE_INHERIT: | |
10504 | fixP->fx_done = 0; | |
10505 | if (fixP->fx_addsy | |
10506 | && !S_IS_DEFINED (fixP->fx_addsy) | |
10507 | && !S_IS_WEAK (fixP->fx_addsy)) | |
10508 | S_SET_WEAK (fixP->fx_addsy); | |
10509 | break; | |
10510 | ||
10511 | case BFD_RELOC_VTABLE_ENTRY: | |
10512 | fixP->fx_done = 0; | |
10513 | break; | |
10514 | ||
10515 | default: | |
10516 | internalError (); | |
10517 | } | |
10518 | ||
10519 | return 1; | |
10520 | } | |
10521 | ||
10522 | #if 0 | |
10523 | void | |
10524 | printInsn (oc) | |
10525 | unsigned long oc; | |
10526 | { | |
10527 | const struct mips_opcode *p; | |
10528 | int treg, sreg, dreg, shamt; | |
10529 | short imm; | |
10530 | const char *args; | |
10531 | int i; | |
10532 | ||
10533 | for (i = 0; i < NUMOPCODES; ++i) | |
10534 | { | |
10535 | p = &mips_opcodes[i]; | |
10536 | if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO)) | |
10537 | { | |
10538 | printf ("%08lx %s\t", oc, p->name); | |
10539 | treg = (oc >> 16) & 0x1f; | |
10540 | sreg = (oc >> 21) & 0x1f; | |
10541 | dreg = (oc >> 11) & 0x1f; | |
10542 | shamt = (oc >> 6) & 0x1f; | |
10543 | imm = oc; | |
10544 | for (args = p->args;; ++args) | |
10545 | { | |
10546 | switch (*args) | |
10547 | { | |
10548 | case '\0': | |
10549 | printf ("\n"); | |
10550 | break; | |
10551 | ||
10552 | case ',': | |
10553 | case '(': | |
10554 | case ')': | |
10555 | printf ("%c", *args); | |
10556 | continue; | |
10557 | ||
10558 | case 'r': | |
10559 | assert (treg == sreg); | |
10560 | printf ("$%d,$%d", treg, sreg); | |
10561 | continue; | |
10562 | ||
10563 | case 'd': | |
10564 | case 'G': | |
10565 | printf ("$%d", dreg); | |
10566 | continue; | |
10567 | ||
10568 | case 't': | |
10569 | case 'E': | |
10570 | printf ("$%d", treg); | |
10571 | continue; | |
10572 | ||
10573 | case 'k': | |
10574 | printf ("0x%x", treg); | |
10575 | continue; | |
10576 | ||
10577 | case 'b': | |
10578 | case 's': | |
10579 | printf ("$%d", sreg); | |
10580 | continue; | |
10581 | ||
10582 | case 'a': | |
10583 | printf ("0x%08lx", oc & 0x1ffffff); | |
10584 | continue; | |
10585 | ||
10586 | case 'i': | |
10587 | case 'j': | |
10588 | case 'o': | |
10589 | case 'u': | |
10590 | printf ("%d", imm); | |
10591 | continue; | |
10592 | ||
10593 | case '<': | |
10594 | case '>': | |
10595 | printf ("$%d", shamt); | |
10596 | continue; | |
10597 | ||
10598 | default: | |
10599 | internalError (); | |
10600 | } | |
10601 | break; | |
10602 | } | |
10603 | return; | |
10604 | } | |
10605 | } | |
10606 | printf (_("%08lx UNDEFINED\n"), oc); | |
10607 | } | |
10608 | #endif | |
10609 | ||
10610 | static symbolS * | |
10611 | get_symbol () | |
10612 | { | |
10613 | int c; | |
10614 | char *name; | |
10615 | symbolS *p; | |
10616 | ||
10617 | name = input_line_pointer; | |
10618 | c = get_symbol_end (); | |
10619 | p = (symbolS *) symbol_find_or_make (name); | |
10620 | *input_line_pointer = c; | |
10621 | return p; | |
10622 | } | |
10623 | ||
10624 | /* Align the current frag to a given power of two. The MIPS assembler | |
10625 | also automatically adjusts any preceding label. */ | |
10626 | ||
10627 | static void | |
10628 | mips_align (to, fill, label) | |
10629 | int to; | |
10630 | int fill; | |
10631 | symbolS *label; | |
10632 | { | |
10633 | mips_emit_delays (false); | |
10634 | frag_align (to, fill, 0); | |
10635 | record_alignment (now_seg, to); | |
10636 | if (label != NULL) | |
10637 | { | |
10638 | assert (S_GET_SEGMENT (label) == now_seg); | |
49309057 | 10639 | symbol_set_frag (label, frag_now); |
252b5132 RH |
10640 | S_SET_VALUE (label, (valueT) frag_now_fix ()); |
10641 | } | |
10642 | } | |
10643 | ||
10644 | /* Align to a given power of two. .align 0 turns off the automatic | |
10645 | alignment used by the data creating pseudo-ops. */ | |
10646 | ||
10647 | static void | |
10648 | s_align (x) | |
43841e91 | 10649 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10650 | { |
10651 | register int temp; | |
10652 | register long temp_fill; | |
10653 | long max_alignment = 15; | |
10654 | ||
10655 | /* | |
10656 | ||
10657 | o Note that the assembler pulls down any immediately preceeding label | |
10658 | to the aligned address. | |
10659 | o It's not documented but auto alignment is reinstated by | |
10660 | a .align pseudo instruction. | |
10661 | o Note also that after auto alignment is turned off the mips assembler | |
10662 | issues an error on attempt to assemble an improperly aligned data item. | |
10663 | We don't. | |
10664 | ||
10665 | */ | |
10666 | ||
10667 | temp = get_absolute_expression (); | |
10668 | if (temp > max_alignment) | |
10669 | as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment); | |
10670 | else if (temp < 0) | |
10671 | { | |
10672 | as_warn (_("Alignment negative: 0 assumed.")); | |
10673 | temp = 0; | |
10674 | } | |
10675 | if (*input_line_pointer == ',') | |
10676 | { | |
10677 | input_line_pointer++; | |
10678 | temp_fill = get_absolute_expression (); | |
10679 | } | |
10680 | else | |
10681 | temp_fill = 0; | |
10682 | if (temp) | |
10683 | { | |
10684 | auto_align = 1; | |
10685 | mips_align (temp, (int) temp_fill, | |
10686 | insn_labels != NULL ? insn_labels->label : NULL); | |
10687 | } | |
10688 | else | |
10689 | { | |
10690 | auto_align = 0; | |
10691 | } | |
10692 | ||
10693 | demand_empty_rest_of_line (); | |
10694 | } | |
10695 | ||
10696 | void | |
10697 | mips_flush_pending_output () | |
10698 | { | |
10699 | mips_emit_delays (false); | |
10700 | mips_clear_insn_labels (); | |
10701 | } | |
10702 | ||
10703 | static void | |
10704 | s_change_sec (sec) | |
10705 | int sec; | |
10706 | { | |
10707 | segT seg; | |
10708 | ||
10709 | /* When generating embedded PIC code, we only use the .text, .lit8, | |
10710 | .sdata and .sbss sections. We change the .data and .rdata | |
10711 | pseudo-ops to use .sdata. */ | |
10712 | if (mips_pic == EMBEDDED_PIC | |
10713 | && (sec == 'd' || sec == 'r')) | |
10714 | sec = 's'; | |
10715 | ||
10716 | #ifdef OBJ_ELF | |
10717 | /* The ELF backend needs to know that we are changing sections, so | |
10718 | that .previous works correctly. We could do something like check | |
b6ff326e | 10719 | for an obj_section_change_hook macro, but that might be confusing |
252b5132 RH |
10720 | as it would not be appropriate to use it in the section changing |
10721 | functions in read.c, since obj-elf.c intercepts those. FIXME: | |
10722 | This should be cleaner, somehow. */ | |
10723 | obj_elf_section_change_hook (); | |
10724 | #endif | |
10725 | ||
10726 | mips_emit_delays (false); | |
10727 | switch (sec) | |
10728 | { | |
10729 | case 't': | |
10730 | s_text (0); | |
10731 | break; | |
10732 | case 'd': | |
10733 | s_data (0); | |
10734 | break; | |
10735 | case 'b': | |
10736 | subseg_set (bss_section, (subsegT) get_absolute_expression ()); | |
10737 | demand_empty_rest_of_line (); | |
10738 | break; | |
10739 | ||
10740 | case 'r': | |
10741 | if (USE_GLOBAL_POINTER_OPT) | |
10742 | { | |
10743 | seg = subseg_new (RDATA_SECTION_NAME, | |
10744 | (subsegT) get_absolute_expression ()); | |
10745 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
10746 | { | |
10747 | bfd_set_section_flags (stdoutput, seg, | |
10748 | (SEC_ALLOC | |
10749 | | SEC_LOAD | |
10750 | | SEC_READONLY | |
10751 | | SEC_RELOC | |
10752 | | SEC_DATA)); | |
10753 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 10754 | record_alignment (seg, 4); |
252b5132 RH |
10755 | } |
10756 | demand_empty_rest_of_line (); | |
10757 | } | |
10758 | else | |
10759 | { | |
10760 | as_bad (_("No read only data section in this object file format")); | |
10761 | demand_empty_rest_of_line (); | |
10762 | return; | |
10763 | } | |
10764 | break; | |
10765 | ||
10766 | case 's': | |
10767 | if (USE_GLOBAL_POINTER_OPT) | |
10768 | { | |
10769 | seg = subseg_new (".sdata", (subsegT) get_absolute_expression ()); | |
10770 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
10771 | { | |
10772 | bfd_set_section_flags (stdoutput, seg, | |
10773 | SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
10774 | | SEC_DATA); | |
10775 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 10776 | record_alignment (seg, 4); |
252b5132 RH |
10777 | } |
10778 | demand_empty_rest_of_line (); | |
10779 | break; | |
10780 | } | |
10781 | else | |
10782 | { | |
10783 | as_bad (_("Global pointers not supported; recompile -G 0")); | |
10784 | demand_empty_rest_of_line (); | |
10785 | return; | |
10786 | } | |
10787 | } | |
10788 | ||
10789 | auto_align = 1; | |
10790 | } | |
10791 | ||
10792 | void | |
10793 | mips_enable_auto_align () | |
10794 | { | |
10795 | auto_align = 1; | |
10796 | } | |
10797 | ||
10798 | static void | |
10799 | s_cons (log_size) | |
10800 | int log_size; | |
10801 | { | |
10802 | symbolS *label; | |
10803 | ||
10804 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10805 | mips_emit_delays (false); | |
10806 | if (log_size > 0 && auto_align) | |
10807 | mips_align (log_size, 0, label); | |
10808 | mips_clear_insn_labels (); | |
10809 | cons (1 << log_size); | |
10810 | } | |
10811 | ||
10812 | static void | |
10813 | s_float_cons (type) | |
10814 | int type; | |
10815 | { | |
10816 | symbolS *label; | |
10817 | ||
10818 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10819 | ||
10820 | mips_emit_delays (false); | |
10821 | ||
10822 | if (auto_align) | |
49309057 ILT |
10823 | { |
10824 | if (type == 'd') | |
10825 | mips_align (3, 0, label); | |
10826 | else | |
10827 | mips_align (2, 0, label); | |
10828 | } | |
252b5132 RH |
10829 | |
10830 | mips_clear_insn_labels (); | |
10831 | ||
10832 | float_cons (type); | |
10833 | } | |
10834 | ||
10835 | /* Handle .globl. We need to override it because on Irix 5 you are | |
10836 | permitted to say | |
10837 | .globl foo .text | |
10838 | where foo is an undefined symbol, to mean that foo should be | |
10839 | considered to be the address of a function. */ | |
10840 | ||
10841 | static void | |
10842 | s_mips_globl (x) | |
43841e91 | 10843 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10844 | { |
10845 | char *name; | |
10846 | int c; | |
10847 | symbolS *symbolP; | |
10848 | flagword flag; | |
10849 | ||
10850 | name = input_line_pointer; | |
10851 | c = get_symbol_end (); | |
10852 | symbolP = symbol_find_or_make (name); | |
10853 | *input_line_pointer = c; | |
10854 | SKIP_WHITESPACE (); | |
10855 | ||
10856 | /* On Irix 5, every global symbol that is not explicitly labelled as | |
10857 | being a function is apparently labelled as being an object. */ | |
10858 | flag = BSF_OBJECT; | |
10859 | ||
10860 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
10861 | { | |
10862 | char *secname; | |
10863 | asection *sec; | |
10864 | ||
10865 | secname = input_line_pointer; | |
10866 | c = get_symbol_end (); | |
10867 | sec = bfd_get_section_by_name (stdoutput, secname); | |
10868 | if (sec == NULL) | |
10869 | as_bad (_("%s: no such section"), secname); | |
10870 | *input_line_pointer = c; | |
10871 | ||
10872 | if (sec != NULL && (sec->flags & SEC_CODE) != 0) | |
10873 | flag = BSF_FUNCTION; | |
10874 | } | |
10875 | ||
49309057 | 10876 | symbol_get_bfdsym (symbolP)->flags |= flag; |
252b5132 RH |
10877 | |
10878 | S_SET_EXTERNAL (symbolP); | |
10879 | demand_empty_rest_of_line (); | |
10880 | } | |
10881 | ||
10882 | static void | |
10883 | s_option (x) | |
43841e91 | 10884 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10885 | { |
10886 | char *opt; | |
10887 | char c; | |
10888 | ||
10889 | opt = input_line_pointer; | |
10890 | c = get_symbol_end (); | |
10891 | ||
10892 | if (*opt == 'O') | |
10893 | { | |
10894 | /* FIXME: What does this mean? */ | |
10895 | } | |
10896 | else if (strncmp (opt, "pic", 3) == 0) | |
10897 | { | |
10898 | int i; | |
10899 | ||
10900 | i = atoi (opt + 3); | |
10901 | if (i == 0) | |
10902 | mips_pic = NO_PIC; | |
10903 | else if (i == 2) | |
10904 | mips_pic = SVR4_PIC; | |
10905 | else | |
10906 | as_bad (_(".option pic%d not supported"), i); | |
10907 | ||
10908 | if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC) | |
10909 | { | |
10910 | if (g_switch_seen && g_switch_value != 0) | |
10911 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
10912 | g_switch_value = 0; | |
10913 | bfd_set_gp_size (stdoutput, 0); | |
10914 | } | |
10915 | } | |
10916 | else | |
10917 | as_warn (_("Unrecognized option \"%s\""), opt); | |
10918 | ||
10919 | *input_line_pointer = c; | |
10920 | demand_empty_rest_of_line (); | |
10921 | } | |
10922 | ||
10923 | /* This structure is used to hold a stack of .set values. */ | |
10924 | ||
e972090a NC |
10925 | struct mips_option_stack |
10926 | { | |
252b5132 RH |
10927 | struct mips_option_stack *next; |
10928 | struct mips_set_options options; | |
10929 | }; | |
10930 | ||
10931 | static struct mips_option_stack *mips_opts_stack; | |
10932 | ||
10933 | /* Handle the .set pseudo-op. */ | |
10934 | ||
10935 | static void | |
10936 | s_mipsset (x) | |
43841e91 | 10937 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10938 | { |
10939 | char *name = input_line_pointer, ch; | |
10940 | ||
10941 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
10942 | input_line_pointer++; | |
10943 | ch = *input_line_pointer; | |
10944 | *input_line_pointer = '\0'; | |
10945 | ||
10946 | if (strcmp (name, "reorder") == 0) | |
10947 | { | |
10948 | if (mips_opts.noreorder && prev_nop_frag != NULL) | |
10949 | { | |
10950 | /* If we still have pending nops, we can discard them. The | |
10951 | usual nop handling will insert any that are still | |
bdaaa2e1 | 10952 | needed. */ |
252b5132 RH |
10953 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds |
10954 | * (mips_opts.mips16 ? 2 : 4)); | |
10955 | prev_nop_frag = NULL; | |
10956 | } | |
10957 | mips_opts.noreorder = 0; | |
10958 | } | |
10959 | else if (strcmp (name, "noreorder") == 0) | |
10960 | { | |
10961 | mips_emit_delays (true); | |
10962 | mips_opts.noreorder = 1; | |
10963 | mips_any_noreorder = 1; | |
10964 | } | |
10965 | else if (strcmp (name, "at") == 0) | |
10966 | { | |
10967 | mips_opts.noat = 0; | |
10968 | } | |
10969 | else if (strcmp (name, "noat") == 0) | |
10970 | { | |
10971 | mips_opts.noat = 1; | |
10972 | } | |
10973 | else if (strcmp (name, "macro") == 0) | |
10974 | { | |
10975 | mips_opts.warn_about_macros = 0; | |
10976 | } | |
10977 | else if (strcmp (name, "nomacro") == 0) | |
10978 | { | |
10979 | if (mips_opts.noreorder == 0) | |
10980 | as_bad (_("`noreorder' must be set before `nomacro'")); | |
10981 | mips_opts.warn_about_macros = 1; | |
10982 | } | |
10983 | else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0) | |
10984 | { | |
10985 | mips_opts.nomove = 0; | |
10986 | } | |
10987 | else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0) | |
10988 | { | |
10989 | mips_opts.nomove = 1; | |
10990 | } | |
10991 | else if (strcmp (name, "bopt") == 0) | |
10992 | { | |
10993 | mips_opts.nobopt = 0; | |
10994 | } | |
10995 | else if (strcmp (name, "nobopt") == 0) | |
10996 | { | |
10997 | mips_opts.nobopt = 1; | |
10998 | } | |
10999 | else if (strcmp (name, "mips16") == 0 | |
11000 | || strcmp (name, "MIPS-16") == 0) | |
11001 | mips_opts.mips16 = 1; | |
11002 | else if (strcmp (name, "nomips16") == 0 | |
11003 | || strcmp (name, "noMIPS-16") == 0) | |
11004 | mips_opts.mips16 = 0; | |
11005 | else if (strncmp (name, "mips", 4) == 0) | |
11006 | { | |
11007 | int isa; | |
553178e4 TS |
11008 | static int saved_mips_gp32; |
11009 | static int saved_mips_fp32; | |
e013f690 | 11010 | static enum mips_abi_level saved_mips_abi; |
553178e4 | 11011 | static int is_saved; |
252b5132 RH |
11012 | |
11013 | /* Permit the user to change the ISA on the fly. Needless to | |
11014 | say, misuse can cause serious problems. */ | |
11015 | isa = atoi (name + 4); | |
553178e4 TS |
11016 | switch (isa) |
11017 | { | |
11018 | case 0: | |
11019 | mips_gp32 = saved_mips_gp32; | |
11020 | mips_fp32 = saved_mips_fp32; | |
e013f690 | 11021 | mips_abi = saved_mips_abi; |
553178e4 TS |
11022 | is_saved = 0; |
11023 | break; | |
11024 | case 1: | |
11025 | case 2: | |
11026 | case 32: | |
11027 | if (! is_saved) | |
11028 | { | |
11029 | saved_mips_gp32 = mips_gp32; | |
11030 | saved_mips_fp32 = mips_fp32; | |
e013f690 | 11031 | saved_mips_abi = mips_abi; |
553178e4 TS |
11032 | } |
11033 | mips_gp32 = 1; | |
11034 | mips_fp32 = 1; | |
11035 | is_saved = 1; | |
11036 | break; | |
11037 | case 3: | |
11038 | case 4: | |
11039 | case 5: | |
11040 | case 64: | |
11041 | if (! is_saved) | |
11042 | { | |
11043 | saved_mips_gp32 = mips_gp32; | |
11044 | saved_mips_fp32 = mips_fp32; | |
e013f690 | 11045 | saved_mips_abi = mips_abi; |
553178e4 TS |
11046 | } |
11047 | mips_gp32 = 0; | |
11048 | mips_fp32 = 0; | |
e013f690 | 11049 | mips_abi = NO_ABI; |
553178e4 TS |
11050 | is_saved = 1; |
11051 | break; | |
11052 | default: | |
11053 | as_bad (_("unknown ISA level")); | |
11054 | break; | |
11055 | } | |
11056 | ||
e7af610e NC |
11057 | switch (isa) |
11058 | { | |
84ea6cf2 NC |
11059 | case 0: mips_opts.isa = file_mips_isa; break; |
11060 | case 1: mips_opts.isa = ISA_MIPS1; break; | |
11061 | case 2: mips_opts.isa = ISA_MIPS2; break; | |
11062 | case 3: mips_opts.isa = ISA_MIPS3; break; | |
84ea6cf2 | 11063 | case 4: mips_opts.isa = ISA_MIPS4; break; |
9a41af64 | 11064 | case 5: mips_opts.isa = ISA_MIPS5; break; |
84ea6cf2 NC |
11065 | case 32: mips_opts.isa = ISA_MIPS32; break; |
11066 | case 64: mips_opts.isa = ISA_MIPS64; break; | |
11067 | default: as_bad (_("unknown ISA level")); break; | |
e7af610e | 11068 | } |
252b5132 RH |
11069 | } |
11070 | else if (strcmp (name, "autoextend") == 0) | |
11071 | mips_opts.noautoextend = 0; | |
11072 | else if (strcmp (name, "noautoextend") == 0) | |
11073 | mips_opts.noautoextend = 1; | |
11074 | else if (strcmp (name, "push") == 0) | |
11075 | { | |
11076 | struct mips_option_stack *s; | |
11077 | ||
11078 | s = (struct mips_option_stack *) xmalloc (sizeof *s); | |
11079 | s->next = mips_opts_stack; | |
11080 | s->options = mips_opts; | |
11081 | mips_opts_stack = s; | |
11082 | } | |
11083 | else if (strcmp (name, "pop") == 0) | |
11084 | { | |
11085 | struct mips_option_stack *s; | |
11086 | ||
11087 | s = mips_opts_stack; | |
11088 | if (s == NULL) | |
11089 | as_bad (_(".set pop with no .set push")); | |
11090 | else | |
11091 | { | |
11092 | /* If we're changing the reorder mode we need to handle | |
11093 | delay slots correctly. */ | |
11094 | if (s->options.noreorder && ! mips_opts.noreorder) | |
11095 | mips_emit_delays (true); | |
11096 | else if (! s->options.noreorder && mips_opts.noreorder) | |
11097 | { | |
11098 | if (prev_nop_frag != NULL) | |
11099 | { | |
11100 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds | |
11101 | * (mips_opts.mips16 ? 2 : 4)); | |
11102 | prev_nop_frag = NULL; | |
11103 | } | |
11104 | } | |
11105 | ||
11106 | mips_opts = s->options; | |
11107 | mips_opts_stack = s->next; | |
11108 | free (s); | |
11109 | } | |
11110 | } | |
11111 | else | |
11112 | { | |
11113 | as_warn (_("Tried to set unrecognized symbol: %s\n"), name); | |
11114 | } | |
11115 | *input_line_pointer = ch; | |
11116 | demand_empty_rest_of_line (); | |
11117 | } | |
11118 | ||
11119 | /* Handle the .abicalls pseudo-op. I believe this is equivalent to | |
11120 | .option pic2. It means to generate SVR4 PIC calls. */ | |
11121 | ||
11122 | static void | |
11123 | s_abicalls (ignore) | |
43841e91 | 11124 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11125 | { |
11126 | mips_pic = SVR4_PIC; | |
11127 | if (USE_GLOBAL_POINTER_OPT) | |
11128 | { | |
11129 | if (g_switch_seen && g_switch_value != 0) | |
11130 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
11131 | g_switch_value = 0; | |
11132 | } | |
11133 | bfd_set_gp_size (stdoutput, 0); | |
11134 | demand_empty_rest_of_line (); | |
11135 | } | |
11136 | ||
11137 | /* Handle the .cpload pseudo-op. This is used when generating SVR4 | |
11138 | PIC code. It sets the $gp register for the function based on the | |
11139 | function address, which is in the register named in the argument. | |
11140 | This uses a relocation against _gp_disp, which is handled specially | |
11141 | by the linker. The result is: | |
11142 | lui $gp,%hi(_gp_disp) | |
11143 | addiu $gp,$gp,%lo(_gp_disp) | |
11144 | addu $gp,$gp,.cpload argument | |
11145 | The .cpload argument is normally $25 == $t9. */ | |
11146 | ||
11147 | static void | |
11148 | s_cpload (ignore) | |
43841e91 | 11149 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11150 | { |
11151 | expressionS ex; | |
11152 | int icnt = 0; | |
11153 | ||
6478892d TS |
11154 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
11155 | .cpload is ignored. */ | |
11156 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) | |
252b5132 RH |
11157 | { |
11158 | s_ignore (0); | |
11159 | return; | |
11160 | } | |
11161 | ||
d3ecfc59 | 11162 | /* .cpload should be in a .set noreorder section. */ |
252b5132 RH |
11163 | if (mips_opts.noreorder == 0) |
11164 | as_warn (_(".cpload not in noreorder section")); | |
11165 | ||
11166 | ex.X_op = O_symbol; | |
11167 | ex.X_add_symbol = symbol_find_or_make ("_gp_disp"); | |
11168 | ex.X_op_symbol = NULL; | |
11169 | ex.X_add_number = 0; | |
11170 | ||
11171 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ | |
49309057 | 11172 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
252b5132 RH |
11173 | |
11174 | macro_build_lui ((char *) NULL, &icnt, &ex, GP); | |
11175 | macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP, | |
11176 | (int) BFD_RELOC_LO16); | |
11177 | ||
11178 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t", | |
11179 | GP, GP, tc_get_register (0)); | |
11180 | ||
11181 | demand_empty_rest_of_line (); | |
11182 | } | |
11183 | ||
6478892d TS |
11184 | /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is: |
11185 | .cpsetup $reg1, offset|$reg2, label | |
11186 | ||
11187 | If offset is given, this results in: | |
11188 | sd $gp, offset($sp) | |
11189 | lui $gp, %gp_rel(%neg(%hi(label))) | |
11190 | daddiu $gp, $gp, %gp_rel(%neg(%lo(label))) | |
11191 | addu $gp, $gp, $reg1 | |
11192 | ||
11193 | If $reg2 is given, this results in: | |
11194 | daddu $reg2, $gp, $0 | |
11195 | lui $gp, %gp_rel(%neg(%hi(label))) | |
11196 | daddiu $gp, $gp, %gp_rel(%neg(%lo(label))) | |
11197 | addu $gp, $gp, $reg1 | |
11198 | */ | |
11199 | static void | |
11200 | s_cpsetup (ignore) | |
11201 | int ignore ATTRIBUTE_UNUSED; | |
11202 | { | |
11203 | expressionS ex_off; | |
11204 | expressionS ex_sym; | |
11205 | int reg1; | |
11206 | int icnt = 0; | |
11207 | char *sym; | |
11208 | ||
11209 | /* If we are not generating SVR4 PIC code, .cpload is ignored. | |
11210 | We also need NewABI support. */ | |
11211 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
11212 | { | |
11213 | s_ignore (0); | |
11214 | return; | |
11215 | } | |
11216 | ||
11217 | reg1 = tc_get_register (0); | |
11218 | SKIP_WHITESPACE (); | |
11219 | if (*input_line_pointer != ',') | |
11220 | { | |
11221 | as_bad (_("missing argument separator ',' for .cpsetup")); | |
11222 | return; | |
11223 | } | |
11224 | else | |
11225 | input_line_pointer++; | |
11226 | SKIP_WHITESPACE (); | |
11227 | if (*input_line_pointer == '$') | |
11228 | mips_cpreturn_register = tc_get_register (0); | |
11229 | else | |
11230 | mips_cpreturn_offset = get_absolute_expression (); | |
11231 | SKIP_WHITESPACE (); | |
11232 | if (*input_line_pointer != ',') | |
11233 | { | |
11234 | as_bad (_("missing argument separator ',' for .cpsetup")); | |
11235 | return; | |
11236 | } | |
11237 | else | |
11238 | input_line_pointer++; | |
11239 | SKIP_WHITESPACE (); | |
11240 | sym = input_line_pointer; | |
11241 | while (ISALNUM (*input_line_pointer)) | |
11242 | input_line_pointer++; | |
11243 | *input_line_pointer = 0; | |
11244 | ||
11245 | ex_sym.X_op = O_symbol; | |
11246 | ex_sym.X_add_symbol = symbol_find_or_make (sym); | |
11247 | ex_sym.X_op_symbol = NULL; | |
11248 | ex_sym.X_add_number = 0; | |
11249 | ||
11250 | if (mips_cpreturn_register == -1) | |
11251 | { | |
11252 | ex_off.X_op = O_constant; | |
11253 | ex_off.X_add_symbol = NULL; | |
11254 | ex_off.X_op_symbol = NULL; | |
11255 | ex_off.X_add_number = mips_cpreturn_offset; | |
11256 | ||
11257 | macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)", | |
11258 | mips_gp_register, (int) BFD_RELOC_LO16, SP); | |
11259 | } | |
11260 | else | |
11261 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu", | |
11262 | "d,v,t", mips_cpreturn_register, mips_gp_register, 0); | |
11263 | ||
11264 | macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register, | |
11265 | (int) BFD_RELOC_GPREL16); | |
11266 | fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0, | |
11267 | NULL, 0, 0, BFD_RELOC_MIPS_SUB); | |
11268 | fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0, | |
11269 | NULL, 0, 0, BFD_RELOC_HI16_S); | |
11270 | macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j", | |
11271 | mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16); | |
11272 | fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0, | |
11273 | NULL, 0, 0, BFD_RELOC_MIPS_SUB); | |
11274 | fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0, | |
11275 | NULL, 0, 0, BFD_RELOC_LO16); | |
11276 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu", | |
11277 | "d,v,t", mips_gp_register, mips_gp_register, reg1); | |
11278 | ||
11279 | demand_empty_rest_of_line (); | |
11280 | } | |
11281 | ||
11282 | static void | |
11283 | s_cplocal (ignore) | |
11284 | int ignore ATTRIBUTE_UNUSED; | |
11285 | { | |
11286 | /* If we are not generating SVR4 PIC code, or if this is not NewABI code, | |
11287 | .cplocal is ignored. */ | |
11288 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
11289 | { | |
11290 | s_ignore (0); | |
11291 | return; | |
11292 | } | |
11293 | ||
11294 | mips_gp_register = tc_get_register (0); | |
11295 | } | |
11296 | ||
252b5132 RH |
11297 | /* Handle the .cprestore pseudo-op. This stores $gp into a given |
11298 | offset from $sp. The offset is remembered, and after making a PIC | |
11299 | call $gp is restored from that location. */ | |
11300 | ||
11301 | static void | |
11302 | s_cprestore (ignore) | |
43841e91 | 11303 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11304 | { |
11305 | expressionS ex; | |
11306 | int icnt = 0; | |
11307 | ||
6478892d TS |
11308 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
11309 | .cprestore is ignored. */ | |
11310 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) | |
252b5132 RH |
11311 | { |
11312 | s_ignore (0); | |
11313 | return; | |
11314 | } | |
11315 | ||
11316 | mips_cprestore_offset = get_absolute_expression (); | |
11317 | ||
11318 | ex.X_op = O_constant; | |
11319 | ex.X_add_symbol = NULL; | |
11320 | ex.X_op_symbol = NULL; | |
11321 | ex.X_add_number = mips_cprestore_offset; | |
11322 | ||
11323 | macro_build ((char *) NULL, &icnt, &ex, | |
ca4e0257 | 11324 | HAVE_32BIT_ADDRESSES ? "sw" : "sd", |
252b5132 RH |
11325 | "t,o(b)", GP, (int) BFD_RELOC_LO16, SP); |
11326 | ||
11327 | demand_empty_rest_of_line (); | |
11328 | } | |
11329 | ||
6478892d TS |
11330 | /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset |
11331 | was given in the preceeding .gpsetup, it results in: | |
11332 | ld $gp, offset($sp) | |
76b3015f | 11333 | |
6478892d TS |
11334 | If a register $reg2 was given there, it results in: |
11335 | daddiu $gp, $gp, $reg2 | |
11336 | */ | |
11337 | static void | |
11338 | s_cpreturn (ignore) | |
11339 | int ignore ATTRIBUTE_UNUSED; | |
11340 | { | |
11341 | expressionS ex; | |
11342 | int icnt = 0; | |
11343 | ||
11344 | /* If we are not generating SVR4 PIC code, .cpreturn is ignored. | |
11345 | We also need NewABI support. */ | |
11346 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
11347 | { | |
11348 | s_ignore (0); | |
11349 | return; | |
11350 | } | |
11351 | ||
11352 | if (mips_cpreturn_register == -1) | |
11353 | { | |
11354 | ex.X_op = O_constant; | |
11355 | ex.X_add_symbol = NULL; | |
11356 | ex.X_op_symbol = NULL; | |
11357 | ex.X_add_number = mips_cpreturn_offset; | |
11358 | ||
11359 | macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)", | |
11360 | mips_gp_register, (int) BFD_RELOC_LO16, SP); | |
11361 | } | |
11362 | else | |
11363 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu", | |
11364 | "d,v,t", mips_gp_register, mips_cpreturn_register, 0); | |
11365 | ||
11366 | demand_empty_rest_of_line (); | |
11367 | } | |
11368 | ||
11369 | /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC | |
11370 | code. It sets the offset to use in gp_rel relocations. */ | |
11371 | ||
11372 | static void | |
11373 | s_gpvalue (ignore) | |
11374 | int ignore ATTRIBUTE_UNUSED; | |
11375 | { | |
11376 | /* If we are not generating SVR4 PIC code, .gpvalue is ignored. | |
11377 | We also need NewABI support. */ | |
11378 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
11379 | { | |
11380 | s_ignore (0); | |
11381 | return; | |
11382 | } | |
11383 | ||
11384 | mips_cpreturn_offset = get_absolute_expression (); | |
11385 | ||
11386 | demand_empty_rest_of_line (); | |
11387 | } | |
11388 | ||
252b5132 RH |
11389 | /* Handle the .gpword pseudo-op. This is used when generating PIC |
11390 | code. It generates a 32 bit GP relative reloc. */ | |
11391 | ||
11392 | static void | |
11393 | s_gpword (ignore) | |
43841e91 | 11394 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11395 | { |
11396 | symbolS *label; | |
11397 | expressionS ex; | |
11398 | char *p; | |
11399 | ||
11400 | /* When not generating PIC code, this is treated as .word. */ | |
11401 | if (mips_pic != SVR4_PIC) | |
11402 | { | |
11403 | s_cons (2); | |
11404 | return; | |
11405 | } | |
11406 | ||
11407 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
11408 | mips_emit_delays (true); | |
11409 | if (auto_align) | |
11410 | mips_align (2, 0, label); | |
11411 | mips_clear_insn_labels (); | |
11412 | ||
11413 | expression (&ex); | |
11414 | ||
11415 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
11416 | { | |
11417 | as_bad (_("Unsupported use of .gpword")); | |
11418 | ignore_rest_of_line (); | |
11419 | } | |
11420 | ||
11421 | p = frag_more (4); | |
11422 | md_number_to_chars (p, (valueT) 0, 4); | |
11423 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0, | |
11424 | BFD_RELOC_MIPS_GPREL32); | |
11425 | ||
11426 | demand_empty_rest_of_line (); | |
11427 | } | |
11428 | ||
11429 | /* Handle the .cpadd pseudo-op. This is used when dealing with switch | |
11430 | tables in SVR4 PIC code. */ | |
11431 | ||
11432 | static void | |
11433 | s_cpadd (ignore) | |
43841e91 | 11434 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11435 | { |
11436 | int icnt = 0; | |
11437 | int reg; | |
11438 | ||
6478892d TS |
11439 | /* This is ignored when not generating SVR4 PIC code or if this is NewABI |
11440 | code. */ | |
11441 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) | |
252b5132 RH |
11442 | { |
11443 | s_ignore (0); | |
11444 | return; | |
11445 | } | |
11446 | ||
11447 | /* Add $gp to the register named as an argument. */ | |
11448 | reg = tc_get_register (0); | |
11449 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 11450 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
11451 | "d,v,t", reg, reg, GP); |
11452 | ||
bdaaa2e1 | 11453 | demand_empty_rest_of_line (); |
252b5132 RH |
11454 | } |
11455 | ||
11456 | /* Handle the .insn pseudo-op. This marks instruction labels in | |
11457 | mips16 mode. This permits the linker to handle them specially, | |
11458 | such as generating jalx instructions when needed. We also make | |
11459 | them odd for the duration of the assembly, in order to generate the | |
11460 | right sort of code. We will make them even in the adjust_symtab | |
11461 | routine, while leaving them marked. This is convenient for the | |
11462 | debugger and the disassembler. The linker knows to make them odd | |
11463 | again. */ | |
11464 | ||
11465 | static void | |
11466 | s_insn (ignore) | |
43841e91 | 11467 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11468 | { |
11469 | if (mips_opts.mips16) | |
11470 | mips16_mark_labels (); | |
11471 | ||
11472 | demand_empty_rest_of_line (); | |
11473 | } | |
11474 | ||
11475 | /* Handle a .stabn directive. We need these in order to mark a label | |
11476 | as being a mips16 text label correctly. Sometimes the compiler | |
11477 | will emit a label, followed by a .stabn, and then switch sections. | |
11478 | If the label and .stabn are in mips16 mode, then the label is | |
11479 | really a mips16 text label. */ | |
11480 | ||
11481 | static void | |
11482 | s_mips_stab (type) | |
11483 | int type; | |
11484 | { | |
11485 | if (type == 'n' && mips_opts.mips16) | |
11486 | mips16_mark_labels (); | |
11487 | ||
11488 | s_stab (type); | |
11489 | } | |
11490 | ||
11491 | /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. | |
11492 | */ | |
11493 | ||
11494 | static void | |
11495 | s_mips_weakext (ignore) | |
43841e91 | 11496 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11497 | { |
11498 | char *name; | |
11499 | int c; | |
11500 | symbolS *symbolP; | |
11501 | expressionS exp; | |
11502 | ||
11503 | name = input_line_pointer; | |
11504 | c = get_symbol_end (); | |
11505 | symbolP = symbol_find_or_make (name); | |
11506 | S_SET_WEAK (symbolP); | |
11507 | *input_line_pointer = c; | |
11508 | ||
11509 | SKIP_WHITESPACE (); | |
11510 | ||
11511 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
11512 | { | |
11513 | if (S_IS_DEFINED (symbolP)) | |
11514 | { | |
11515 | as_bad ("Ignoring attempt to redefine symbol `%s'.", | |
11516 | S_GET_NAME (symbolP)); | |
11517 | ignore_rest_of_line (); | |
11518 | return; | |
11519 | } | |
bdaaa2e1 | 11520 | |
252b5132 RH |
11521 | if (*input_line_pointer == ',') |
11522 | { | |
11523 | ++input_line_pointer; | |
11524 | SKIP_WHITESPACE (); | |
11525 | } | |
bdaaa2e1 | 11526 | |
252b5132 RH |
11527 | expression (&exp); |
11528 | if (exp.X_op != O_symbol) | |
11529 | { | |
11530 | as_bad ("bad .weakext directive"); | |
11531 | ignore_rest_of_line(); | |
11532 | return; | |
11533 | } | |
49309057 | 11534 | symbol_set_value_expression (symbolP, &exp); |
252b5132 RH |
11535 | } |
11536 | ||
11537 | demand_empty_rest_of_line (); | |
11538 | } | |
11539 | ||
11540 | /* Parse a register string into a number. Called from the ECOFF code | |
11541 | to parse .frame. The argument is non-zero if this is the frame | |
11542 | register, so that we can record it in mips_frame_reg. */ | |
11543 | ||
11544 | int | |
11545 | tc_get_register (frame) | |
11546 | int frame; | |
11547 | { | |
11548 | int reg; | |
11549 | ||
11550 | SKIP_WHITESPACE (); | |
11551 | if (*input_line_pointer++ != '$') | |
11552 | { | |
11553 | as_warn (_("expected `$'")); | |
11554 | reg = 0; | |
11555 | } | |
3882b010 | 11556 | else if (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
11557 | { |
11558 | reg = get_absolute_expression (); | |
11559 | if (reg < 0 || reg >= 32) | |
11560 | { | |
11561 | as_warn (_("Bad register number")); | |
11562 | reg = 0; | |
11563 | } | |
11564 | } | |
11565 | else | |
11566 | { | |
11567 | if (strncmp (input_line_pointer, "fp", 2) == 0) | |
11568 | reg = FP; | |
11569 | else if (strncmp (input_line_pointer, "sp", 2) == 0) | |
11570 | reg = SP; | |
11571 | else if (strncmp (input_line_pointer, "gp", 2) == 0) | |
11572 | reg = GP; | |
11573 | else if (strncmp (input_line_pointer, "at", 2) == 0) | |
11574 | reg = AT; | |
11575 | else | |
11576 | { | |
11577 | as_warn (_("Unrecognized register name")); | |
11578 | reg = 0; | |
11579 | } | |
11580 | input_line_pointer += 2; | |
11581 | } | |
11582 | if (frame) | |
11583 | mips_frame_reg = reg != 0 ? reg : SP; | |
11584 | return reg; | |
11585 | } | |
11586 | ||
11587 | valueT | |
11588 | md_section_align (seg, addr) | |
11589 | asection *seg; | |
11590 | valueT addr; | |
11591 | { | |
11592 | int align = bfd_get_section_alignment (stdoutput, seg); | |
11593 | ||
11594 | #ifdef OBJ_ELF | |
11595 | /* We don't need to align ELF sections to the full alignment. | |
11596 | However, Irix 5 may prefer that we align them at least to a 16 | |
11597 | byte boundary. We don't bother to align the sections if we are | |
11598 | targeted for an embedded system. */ | |
11599 | if (strcmp (TARGET_OS, "elf") == 0) | |
11600 | return addr; | |
11601 | if (align > 4) | |
11602 | align = 4; | |
11603 | #endif | |
11604 | ||
11605 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
11606 | } | |
11607 | ||
11608 | /* Utility routine, called from above as well. If called while the | |
11609 | input file is still being read, it's only an approximation. (For | |
11610 | example, a symbol may later become defined which appeared to be | |
11611 | undefined earlier.) */ | |
11612 | ||
11613 | static int | |
11614 | nopic_need_relax (sym, before_relaxing) | |
11615 | symbolS *sym; | |
11616 | int before_relaxing; | |
11617 | { | |
11618 | if (sym == 0) | |
11619 | return 0; | |
11620 | ||
6478892d | 11621 | if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0) |
252b5132 RH |
11622 | { |
11623 | const char *symname; | |
11624 | int change; | |
11625 | ||
11626 | /* Find out whether this symbol can be referenced off the GP | |
11627 | register. It can be if it is smaller than the -G size or if | |
11628 | it is in the .sdata or .sbss section. Certain symbols can | |
11629 | not be referenced off the GP, although it appears as though | |
11630 | they can. */ | |
11631 | symname = S_GET_NAME (sym); | |
11632 | if (symname != (const char *) NULL | |
11633 | && (strcmp (symname, "eprol") == 0 | |
11634 | || strcmp (symname, "etext") == 0 | |
11635 | || strcmp (symname, "_gp") == 0 | |
11636 | || strcmp (symname, "edata") == 0 | |
11637 | || strcmp (symname, "_fbss") == 0 | |
11638 | || strcmp (symname, "_fdata") == 0 | |
11639 | || strcmp (symname, "_ftext") == 0 | |
11640 | || strcmp (symname, "end") == 0 | |
11641 | || strcmp (symname, "_gp_disp") == 0)) | |
11642 | change = 1; | |
11643 | else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym)) | |
11644 | && (0 | |
11645 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 ILT |
11646 | || (symbol_get_obj (sym)->ecoff_extern_size != 0 |
11647 | && (symbol_get_obj (sym)->ecoff_extern_size | |
11648 | <= g_switch_value)) | |
252b5132 RH |
11649 | #endif |
11650 | /* We must defer this decision until after the whole | |
11651 | file has been read, since there might be a .extern | |
11652 | after the first use of this symbol. */ | |
11653 | || (before_relaxing | |
11654 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 | 11655 | && symbol_get_obj (sym)->ecoff_extern_size == 0 |
252b5132 RH |
11656 | #endif |
11657 | && S_GET_VALUE (sym) == 0) | |
11658 | || (S_GET_VALUE (sym) != 0 | |
11659 | && S_GET_VALUE (sym) <= g_switch_value))) | |
11660 | change = 0; | |
11661 | else | |
11662 | { | |
11663 | const char *segname; | |
11664 | ||
11665 | segname = segment_name (S_GET_SEGMENT (sym)); | |
11666 | assert (strcmp (segname, ".lit8") != 0 | |
11667 | && strcmp (segname, ".lit4") != 0); | |
11668 | change = (strcmp (segname, ".sdata") != 0 | |
fba2b7f9 GK |
11669 | && strcmp (segname, ".sbss") != 0 |
11670 | && strncmp (segname, ".sdata.", 7) != 0 | |
11671 | && strncmp (segname, ".gnu.linkonce.s.", 16) != 0); | |
252b5132 RH |
11672 | } |
11673 | return change; | |
11674 | } | |
11675 | else | |
11676 | /* We are not optimizing for the GP register. */ | |
11677 | return 1; | |
11678 | } | |
11679 | ||
11680 | /* Given a mips16 variant frag FRAGP, return non-zero if it needs an | |
11681 | extended opcode. SEC is the section the frag is in. */ | |
11682 | ||
11683 | static int | |
11684 | mips16_extended_frag (fragp, sec, stretch) | |
11685 | fragS *fragp; | |
11686 | asection *sec; | |
11687 | long stretch; | |
11688 | { | |
11689 | int type; | |
11690 | register const struct mips16_immed_operand *op; | |
11691 | offsetT val; | |
11692 | int mintiny, maxtiny; | |
11693 | segT symsec; | |
98aa84af | 11694 | fragS *sym_frag; |
252b5132 RH |
11695 | |
11696 | if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) | |
11697 | return 0; | |
11698 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) | |
11699 | return 1; | |
11700 | ||
11701 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
11702 | op = mips16_immed_operands; | |
11703 | while (op->type != type) | |
11704 | { | |
11705 | ++op; | |
11706 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
11707 | } | |
11708 | ||
11709 | if (op->unsp) | |
11710 | { | |
11711 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
11712 | { | |
11713 | mintiny = 1; | |
11714 | maxtiny = 1 << op->nbits; | |
11715 | } | |
11716 | else | |
11717 | { | |
11718 | mintiny = 0; | |
11719 | maxtiny = (1 << op->nbits) - 1; | |
11720 | } | |
11721 | } | |
11722 | else | |
11723 | { | |
11724 | mintiny = - (1 << (op->nbits - 1)); | |
11725 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
11726 | } | |
11727 | ||
98aa84af | 11728 | sym_frag = symbol_get_frag (fragp->fr_symbol); |
ac62c346 | 11729 | val = S_GET_VALUE (fragp->fr_symbol); |
98aa84af | 11730 | symsec = S_GET_SEGMENT (fragp->fr_symbol); |
252b5132 RH |
11731 | |
11732 | if (op->pcrel) | |
11733 | { | |
11734 | addressT addr; | |
11735 | ||
11736 | /* We won't have the section when we are called from | |
11737 | mips_relax_frag. However, we will always have been called | |
11738 | from md_estimate_size_before_relax first. If this is a | |
11739 | branch to a different section, we mark it as such. If SEC is | |
11740 | NULL, and the frag is not marked, then it must be a branch to | |
11741 | the same section. */ | |
11742 | if (sec == NULL) | |
11743 | { | |
11744 | if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype)) | |
11745 | return 1; | |
11746 | } | |
11747 | else | |
11748 | { | |
98aa84af | 11749 | /* Must have been called from md_estimate_size_before_relax. */ |
252b5132 RH |
11750 | if (symsec != sec) |
11751 | { | |
11752 | fragp->fr_subtype = | |
11753 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11754 | ||
11755 | /* FIXME: We should support this, and let the linker | |
11756 | catch branches and loads that are out of range. */ | |
11757 | as_bad_where (fragp->fr_file, fragp->fr_line, | |
11758 | _("unsupported PC relative reference to different section")); | |
11759 | ||
11760 | return 1; | |
11761 | } | |
98aa84af AM |
11762 | if (fragp != sym_frag && sym_frag->fr_address == 0) |
11763 | /* Assume non-extended on the first relaxation pass. | |
11764 | The address we have calculated will be bogus if this is | |
11765 | a forward branch to another frag, as the forward frag | |
11766 | will have fr_address == 0. */ | |
11767 | return 0; | |
252b5132 RH |
11768 | } |
11769 | ||
11770 | /* In this case, we know for sure that the symbol fragment is in | |
98aa84af AM |
11771 | the same section. If the relax_marker of the symbol fragment |
11772 | differs from the relax_marker of this fragment, we have not | |
11773 | yet adjusted the symbol fragment fr_address. We want to add | |
252b5132 RH |
11774 | in STRETCH in order to get a better estimate of the address. |
11775 | This particularly matters because of the shift bits. */ | |
11776 | if (stretch != 0 | |
98aa84af | 11777 | && sym_frag->relax_marker != fragp->relax_marker) |
252b5132 RH |
11778 | { |
11779 | fragS *f; | |
11780 | ||
11781 | /* Adjust stretch for any alignment frag. Note that if have | |
11782 | been expanding the earlier code, the symbol may be | |
11783 | defined in what appears to be an earlier frag. FIXME: | |
11784 | This doesn't handle the fr_subtype field, which specifies | |
11785 | a maximum number of bytes to skip when doing an | |
11786 | alignment. */ | |
98aa84af | 11787 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) |
252b5132 RH |
11788 | { |
11789 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
11790 | { | |
11791 | if (stretch < 0) | |
11792 | stretch = - ((- stretch) | |
11793 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
11794 | else | |
11795 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
11796 | if (stretch == 0) | |
11797 | break; | |
11798 | } | |
11799 | } | |
11800 | if (f != NULL) | |
11801 | val += stretch; | |
11802 | } | |
11803 | ||
11804 | addr = fragp->fr_address + fragp->fr_fix; | |
11805 | ||
11806 | /* The base address rules are complicated. The base address of | |
11807 | a branch is the following instruction. The base address of a | |
11808 | PC relative load or add is the instruction itself, but if it | |
11809 | is in a delay slot (in which case it can not be extended) use | |
11810 | the address of the instruction whose delay slot it is in. */ | |
11811 | if (type == 'p' || type == 'q') | |
11812 | { | |
11813 | addr += 2; | |
11814 | ||
11815 | /* If we are currently assuming that this frag should be | |
11816 | extended, then, the current address is two bytes | |
bdaaa2e1 | 11817 | higher. */ |
252b5132 RH |
11818 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
11819 | addr += 2; | |
11820 | ||
11821 | /* Ignore the low bit in the target, since it will be set | |
11822 | for a text label. */ | |
11823 | if ((val & 1) != 0) | |
11824 | --val; | |
11825 | } | |
11826 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
11827 | addr -= 4; | |
11828 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
11829 | addr -= 2; | |
11830 | ||
11831 | val -= addr & ~ ((1 << op->shift) - 1); | |
11832 | ||
11833 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
11834 | if (type == 'p' || type == 'q') | |
11835 | val /= 2; | |
11836 | ||
11837 | /* If any of the shifted bits are set, we must use an extended | |
11838 | opcode. If the address depends on the size of this | |
11839 | instruction, this can lead to a loop, so we arrange to always | |
11840 | use an extended opcode. We only check this when we are in | |
11841 | the main relaxation loop, when SEC is NULL. */ | |
11842 | if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL) | |
11843 | { | |
11844 | fragp->fr_subtype = | |
11845 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11846 | return 1; | |
11847 | } | |
11848 | ||
11849 | /* If we are about to mark a frag as extended because the value | |
11850 | is precisely maxtiny + 1, then there is a chance of an | |
11851 | infinite loop as in the following code: | |
11852 | la $4,foo | |
11853 | .skip 1020 | |
11854 | .align 2 | |
11855 | foo: | |
11856 | In this case when the la is extended, foo is 0x3fc bytes | |
11857 | away, so the la can be shrunk, but then foo is 0x400 away, so | |
11858 | the la must be extended. To avoid this loop, we mark the | |
11859 | frag as extended if it was small, and is about to become | |
11860 | extended with a value of maxtiny + 1. */ | |
11861 | if (val == ((maxtiny + 1) << op->shift) | |
11862 | && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype) | |
11863 | && sec == NULL) | |
11864 | { | |
11865 | fragp->fr_subtype = | |
11866 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11867 | return 1; | |
11868 | } | |
11869 | } | |
11870 | else if (symsec != absolute_section && sec != NULL) | |
11871 | as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation")); | |
11872 | ||
11873 | if ((val & ((1 << op->shift) - 1)) != 0 | |
11874 | || val < (mintiny << op->shift) | |
11875 | || val > (maxtiny << op->shift)) | |
11876 | return 1; | |
11877 | else | |
11878 | return 0; | |
11879 | } | |
11880 | ||
11881 | /* Estimate the size of a frag before relaxing. Unless this is the | |
11882 | mips16, we are not really relaxing here, and the final size is | |
11883 | encoded in the subtype information. For the mips16, we have to | |
11884 | decide whether we are using an extended opcode or not. */ | |
11885 | ||
252b5132 RH |
11886 | int |
11887 | md_estimate_size_before_relax (fragp, segtype) | |
11888 | fragS *fragp; | |
11889 | asection *segtype; | |
11890 | { | |
43841e91 | 11891 | int change = 0; |
8614eeee | 11892 | boolean linkonce = false; |
252b5132 RH |
11893 | |
11894 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
11895 | { | |
11896 | if (mips16_extended_frag (fragp, segtype, 0)) | |
11897 | { | |
11898 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
11899 | return 4; | |
11900 | } | |
11901 | else | |
11902 | { | |
11903 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
11904 | return 2; | |
11905 | } | |
11906 | } | |
11907 | ||
11908 | if (mips_pic == NO_PIC) | |
11909 | { | |
11910 | change = nopic_need_relax (fragp->fr_symbol, 0); | |
11911 | } | |
11912 | else if (mips_pic == SVR4_PIC) | |
11913 | { | |
11914 | symbolS *sym; | |
11915 | asection *symsec; | |
11916 | ||
11917 | sym = fragp->fr_symbol; | |
11918 | ||
11919 | /* Handle the case of a symbol equated to another symbol. */ | |
e0890092 | 11920 | while (symbol_equated_reloc_p (sym)) |
252b5132 RH |
11921 | { |
11922 | symbolS *n; | |
11923 | ||
11924 | /* It's possible to get a loop here in a badly written | |
11925 | program. */ | |
49309057 | 11926 | n = symbol_get_value_expression (sym)->X_add_symbol; |
252b5132 RH |
11927 | if (n == sym) |
11928 | break; | |
11929 | sym = n; | |
11930 | } | |
11931 | ||
11932 | symsec = S_GET_SEGMENT (sym); | |
11933 | ||
8614eeee UC |
11934 | /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */ |
11935 | if (symsec != segtype && ! S_IS_LOCAL (sym)) | |
beae10d5 KH |
11936 | { |
11937 | if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) | |
11938 | != 0) | |
11939 | linkonce = true; | |
11940 | ||
11941 | /* The GNU toolchain uses an extension for ELF: a section | |
11942 | beginning with the magic string .gnu.linkonce is a linkonce | |
11943 | section. */ | |
11944 | if (strncmp (segment_name (symsec), ".gnu.linkonce", | |
11945 | sizeof ".gnu.linkonce" - 1) == 0) | |
11946 | linkonce = true; | |
11947 | } | |
8614eeee | 11948 | |
252b5132 RH |
11949 | /* This must duplicate the test in adjust_reloc_syms. */ |
11950 | change = (symsec != &bfd_und_section | |
11951 | && symsec != &bfd_abs_section | |
426b0403 | 11952 | && ! bfd_is_com_section (symsec) |
8614eeee | 11953 | && !linkonce |
426b0403 | 11954 | #ifdef OBJ_ELF |
ea4ff978 | 11955 | /* A global or weak symbol is treated as external. */ |
46bac6de L |
11956 | && (OUTPUT_FLAVOR == bfd_target_elf_flavour |
11957 | && ! (S_IS_EXTERN (sym) || S_IS_WEAK (sym))) | |
426b0403 AM |
11958 | #endif |
11959 | ); | |
252b5132 RH |
11960 | } |
11961 | else | |
11962 | abort (); | |
11963 | ||
11964 | if (change) | |
11965 | { | |
11966 | /* Record the offset to the first reloc in the fr_opcode field. | |
11967 | This lets md_convert_frag and tc_gen_reloc know that the code | |
11968 | must be expanded. */ | |
11969 | fragp->fr_opcode = (fragp->fr_literal | |
11970 | + fragp->fr_fix | |
11971 | - RELAX_OLD (fragp->fr_subtype) | |
11972 | + RELAX_RELOC1 (fragp->fr_subtype)); | |
11973 | /* FIXME: This really needs as_warn_where. */ | |
11974 | if (RELAX_WARN (fragp->fr_subtype)) | |
9a41af64 TS |
11975 | as_warn (_("AT used after \".set noat\" or macro used after " |
11976 | "\".set nomacro\"")); | |
11977 | ||
11978 | return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype); | |
252b5132 RH |
11979 | } |
11980 | ||
9a41af64 | 11981 | return 0; |
252b5132 RH |
11982 | } |
11983 | ||
11984 | /* This is called to see whether a reloc against a defined symbol | |
11985 | should be converted into a reloc against a section. Don't adjust | |
11986 | MIPS16 jump relocations, so we don't have to worry about the format | |
11987 | of the offset in the .o file. Don't adjust relocations against | |
11988 | mips16 symbols, so that the linker can find them if it needs to set | |
11989 | up a stub. */ | |
11990 | ||
11991 | int | |
11992 | mips_fix_adjustable (fixp) | |
11993 | fixS *fixp; | |
11994 | { | |
ea4ff978 L |
11995 | #ifdef OBJ_ELF |
11996 | /* Prevent all adjustments to global symbols. */ | |
46bac6de L |
11997 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
11998 | && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy))) | |
ea4ff978 L |
11999 | return 0; |
12000 | #endif | |
252b5132 RH |
12001 | if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP) |
12002 | return 0; | |
12003 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
12004 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
12005 | return 0; | |
12006 | if (fixp->fx_addsy == NULL) | |
12007 | return 1; | |
12008 | #ifdef OBJ_ELF | |
12009 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
12010 | && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16 | |
12011 | && fixp->fx_subsy == NULL) | |
12012 | return 0; | |
12013 | #endif | |
12014 | return 1; | |
12015 | } | |
12016 | ||
12017 | /* Translate internal representation of relocation info to BFD target | |
12018 | format. */ | |
12019 | ||
12020 | arelent ** | |
12021 | tc_gen_reloc (section, fixp) | |
43841e91 | 12022 | asection *section ATTRIBUTE_UNUSED; |
252b5132 RH |
12023 | fixS *fixp; |
12024 | { | |
12025 | static arelent *retval[4]; | |
12026 | arelent *reloc; | |
12027 | bfd_reloc_code_real_type code; | |
12028 | ||
12029 | reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent)); | |
12030 | retval[1] = NULL; | |
12031 | ||
49309057 ILT |
12032 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
12033 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
12034 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
12035 | ||
12036 | if (mips_pic == EMBEDDED_PIC | |
12037 | && SWITCH_TABLE (fixp)) | |
12038 | { | |
12039 | /* For a switch table entry we use a special reloc. The addend | |
12040 | is actually the difference between the reloc address and the | |
12041 | subtrahend. */ | |
12042 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); | |
12043 | if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour) | |
12044 | as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc")); | |
12045 | fixp->fx_r_type = BFD_RELOC_GPREL32; | |
12046 | } | |
bb2d6cd7 GK |
12047 | else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour) |
12048 | reloc->addend = fixp->fx_addnumber; | |
252b5132 RH |
12049 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16) |
12050 | { | |
12051 | /* We use a special addend for an internal RELLO reloc. */ | |
49309057 | 12052 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
12053 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); |
12054 | else | |
12055 | reloc->addend = fixp->fx_addnumber + reloc->address; | |
12056 | } | |
12057 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S) | |
12058 | { | |
12059 | assert (fixp->fx_next != NULL | |
12060 | && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16); | |
12061 | /* We use a special addend for an internal RELHI reloc. The | |
12062 | reloc is relative to the RELLO; adjust the addend | |
12063 | accordingly. */ | |
49309057 | 12064 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
12065 | reloc->addend = (fixp->fx_next->fx_frag->fr_address |
12066 | + fixp->fx_next->fx_where | |
12067 | - S_GET_VALUE (fixp->fx_subsy)); | |
12068 | else | |
12069 | reloc->addend = (fixp->fx_addnumber | |
12070 | + fixp->fx_next->fx_frag->fr_address | |
12071 | + fixp->fx_next->fx_where); | |
12072 | } | |
252b5132 RH |
12073 | else |
12074 | { | |
12075 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour) | |
12076 | /* A gruesome hack which is a result of the gruesome gas reloc | |
12077 | handling. */ | |
12078 | reloc->addend = reloc->address; | |
12079 | else | |
12080 | reloc->addend = -reloc->address; | |
12081 | } | |
12082 | ||
12083 | /* If this is a variant frag, we may need to adjust the existing | |
12084 | reloc and generate a new one. */ | |
12085 | if (fixp->fx_frag->fr_opcode != NULL | |
12086 | && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL | |
12087 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16 | |
12088 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16 | |
12089 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
12090 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16 | |
12091 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
6478892d TS |
12092 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16) |
12093 | && ! HAVE_NEWABI) | |
252b5132 RH |
12094 | { |
12095 | arelent *reloc2; | |
12096 | ||
12097 | assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype)); | |
12098 | ||
12099 | /* If this is not the last reloc in this frag, then we have two | |
12100 | GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a | |
12101 | CALL_HI16/CALL_LO16, both of which are being replaced. Let | |
12102 | the second one handle all of them. */ | |
12103 | if (fixp->fx_next != NULL | |
12104 | && fixp->fx_frag == fixp->fx_next->fx_frag) | |
12105 | { | |
12106 | assert ((fixp->fx_r_type == BFD_RELOC_MIPS_GPREL | |
12107 | && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL) | |
12108 | || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
12109 | && (fixp->fx_next->fx_r_type | |
12110 | == BFD_RELOC_MIPS_GOT_LO16)) | |
12111 | || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
12112 | && (fixp->fx_next->fx_r_type | |
12113 | == BFD_RELOC_MIPS_CALL_LO16))); | |
12114 | retval[0] = NULL; | |
12115 | return retval; | |
12116 | } | |
12117 | ||
12118 | fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal; | |
12119 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
12120 | reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent)); | |
12121 | retval[2] = NULL; | |
49309057 ILT |
12122 | reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
12123 | *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
12124 | reloc2->address = (reloc->address |
12125 | + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype) | |
12126 | - RELAX_RELOC1 (fixp->fx_frag->fr_subtype))); | |
12127 | reloc2->addend = fixp->fx_addnumber; | |
12128 | reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16); | |
12129 | assert (reloc2->howto != NULL); | |
12130 | ||
12131 | if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype)) | |
12132 | { | |
12133 | arelent *reloc3; | |
12134 | ||
12135 | reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent)); | |
12136 | retval[3] = NULL; | |
12137 | *reloc3 = *reloc2; | |
12138 | reloc3->address += 4; | |
12139 | } | |
12140 | ||
12141 | if (mips_pic == NO_PIC) | |
12142 | { | |
12143 | assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL); | |
12144 | fixp->fx_r_type = BFD_RELOC_HI16_S; | |
12145 | } | |
12146 | else if (mips_pic == SVR4_PIC) | |
12147 | { | |
12148 | switch (fixp->fx_r_type) | |
12149 | { | |
12150 | default: | |
12151 | abort (); | |
12152 | case BFD_RELOC_MIPS_GOT16: | |
12153 | break; | |
12154 | case BFD_RELOC_MIPS_CALL16: | |
12155 | case BFD_RELOC_MIPS_GOT_LO16: | |
12156 | case BFD_RELOC_MIPS_CALL_LO16: | |
12157 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT16; | |
12158 | break; | |
12159 | } | |
12160 | } | |
12161 | else | |
12162 | abort (); | |
12163 | } | |
12164 | ||
12165 | /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry | |
12166 | to be used in the relocation's section offset. */ | |
12167 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
12168 | { | |
12169 | reloc->address = reloc->addend; | |
12170 | reloc->addend = 0; | |
12171 | } | |
12172 | ||
12173 | /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that | |
12174 | fixup_segment converted a non-PC relative reloc into a PC | |
12175 | relative reloc. In such a case, we need to convert the reloc | |
12176 | code. */ | |
12177 | code = fixp->fx_r_type; | |
12178 | if (fixp->fx_pcrel) | |
12179 | { | |
12180 | switch (code) | |
12181 | { | |
12182 | case BFD_RELOC_8: | |
12183 | code = BFD_RELOC_8_PCREL; | |
12184 | break; | |
12185 | case BFD_RELOC_16: | |
12186 | code = BFD_RELOC_16_PCREL; | |
12187 | break; | |
12188 | case BFD_RELOC_32: | |
12189 | code = BFD_RELOC_32_PCREL; | |
12190 | break; | |
12191 | case BFD_RELOC_64: | |
12192 | code = BFD_RELOC_64_PCREL; | |
12193 | break; | |
12194 | case BFD_RELOC_8_PCREL: | |
12195 | case BFD_RELOC_16_PCREL: | |
12196 | case BFD_RELOC_32_PCREL: | |
12197 | case BFD_RELOC_64_PCREL: | |
12198 | case BFD_RELOC_16_PCREL_S2: | |
12199 | case BFD_RELOC_PCREL_HI16_S: | |
12200 | case BFD_RELOC_PCREL_LO16: | |
12201 | break; | |
12202 | default: | |
12203 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12204 | _("Cannot make %s relocation PC relative"), | |
12205 | bfd_get_reloc_code_name (code)); | |
12206 | } | |
12207 | } | |
12208 | ||
12209 | /* To support a PC relative reloc when generating embedded PIC code | |
12210 | for ECOFF, we use a Cygnus extension. We check for that here to | |
12211 | make sure that we don't let such a reloc escape normally. */ | |
bb2d6cd7 GK |
12212 | if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
12213 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
252b5132 RH |
12214 | && code == BFD_RELOC_16_PCREL_S2 |
12215 | && mips_pic != EMBEDDED_PIC) | |
12216 | reloc->howto = NULL; | |
12217 | else | |
12218 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
12219 | ||
12220 | if (reloc->howto == NULL) | |
12221 | { | |
12222 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12223 | _("Can not represent %s relocation in this object file format"), | |
12224 | bfd_get_reloc_code_name (code)); | |
12225 | retval[0] = NULL; | |
12226 | } | |
12227 | ||
12228 | return retval; | |
12229 | } | |
12230 | ||
12231 | /* Relax a machine dependent frag. This returns the amount by which | |
12232 | the current size of the frag should change. */ | |
12233 | ||
12234 | int | |
12235 | mips_relax_frag (fragp, stretch) | |
12236 | fragS *fragp; | |
12237 | long stretch; | |
12238 | { | |
12239 | if (! RELAX_MIPS16_P (fragp->fr_subtype)) | |
12240 | return 0; | |
12241 | ||
12242 | if (mips16_extended_frag (fragp, (asection *) NULL, stretch)) | |
12243 | { | |
12244 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
12245 | return 0; | |
12246 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
12247 | return 2; | |
12248 | } | |
12249 | else | |
12250 | { | |
12251 | if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
12252 | return 0; | |
12253 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
12254 | return -2; | |
12255 | } | |
12256 | ||
12257 | return 0; | |
12258 | } | |
12259 | ||
12260 | /* Convert a machine dependent frag. */ | |
12261 | ||
12262 | void | |
12263 | md_convert_frag (abfd, asec, fragp) | |
43841e91 | 12264 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
12265 | segT asec; |
12266 | fragS *fragp; | |
12267 | { | |
12268 | int old, new; | |
12269 | char *fixptr; | |
12270 | ||
12271 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
12272 | { | |
12273 | int type; | |
12274 | register const struct mips16_immed_operand *op; | |
12275 | boolean small, ext; | |
12276 | offsetT val; | |
12277 | bfd_byte *buf; | |
12278 | unsigned long insn; | |
12279 | boolean use_extend; | |
12280 | unsigned short extend; | |
12281 | ||
12282 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
12283 | op = mips16_immed_operands; | |
12284 | while (op->type != type) | |
12285 | ++op; | |
12286 | ||
12287 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
12288 | { | |
12289 | small = false; | |
12290 | ext = true; | |
12291 | } | |
12292 | else | |
12293 | { | |
12294 | small = true; | |
12295 | ext = false; | |
12296 | } | |
12297 | ||
6386f3a7 | 12298 | resolve_symbol_value (fragp->fr_symbol); |
252b5132 RH |
12299 | val = S_GET_VALUE (fragp->fr_symbol); |
12300 | if (op->pcrel) | |
12301 | { | |
12302 | addressT addr; | |
12303 | ||
12304 | addr = fragp->fr_address + fragp->fr_fix; | |
12305 | ||
12306 | /* The rules for the base address of a PC relative reloc are | |
12307 | complicated; see mips16_extended_frag. */ | |
12308 | if (type == 'p' || type == 'q') | |
12309 | { | |
12310 | addr += 2; | |
12311 | if (ext) | |
12312 | addr += 2; | |
12313 | /* Ignore the low bit in the target, since it will be | |
12314 | set for a text label. */ | |
12315 | if ((val & 1) != 0) | |
12316 | --val; | |
12317 | } | |
12318 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
12319 | addr -= 4; | |
12320 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
12321 | addr -= 2; | |
12322 | ||
12323 | addr &= ~ (addressT) ((1 << op->shift) - 1); | |
12324 | val -= addr; | |
12325 | ||
12326 | /* Make sure the section winds up with the alignment we have | |
12327 | assumed. */ | |
12328 | if (op->shift > 0) | |
12329 | record_alignment (asec, op->shift); | |
12330 | } | |
12331 | ||
12332 | if (ext | |
12333 | && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype) | |
12334 | || RELAX_MIPS16_DSLOT (fragp->fr_subtype))) | |
12335 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
12336 | _("extended instruction in delay slot")); | |
12337 | ||
12338 | buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix); | |
12339 | ||
12340 | if (target_big_endian) | |
12341 | insn = bfd_getb16 (buf); | |
12342 | else | |
12343 | insn = bfd_getl16 (buf); | |
12344 | ||
12345 | mips16_immed (fragp->fr_file, fragp->fr_line, type, val, | |
12346 | RELAX_MIPS16_USER_EXT (fragp->fr_subtype), | |
12347 | small, ext, &insn, &use_extend, &extend); | |
12348 | ||
12349 | if (use_extend) | |
12350 | { | |
12351 | md_number_to_chars (buf, 0xf000 | extend, 2); | |
12352 | fragp->fr_fix += 2; | |
12353 | buf += 2; | |
12354 | } | |
12355 | ||
12356 | md_number_to_chars (buf, insn, 2); | |
12357 | fragp->fr_fix += 2; | |
12358 | buf += 2; | |
12359 | } | |
12360 | else | |
12361 | { | |
12362 | if (fragp->fr_opcode == NULL) | |
12363 | return; | |
12364 | ||
12365 | old = RELAX_OLD (fragp->fr_subtype); | |
12366 | new = RELAX_NEW (fragp->fr_subtype); | |
12367 | fixptr = fragp->fr_literal + fragp->fr_fix; | |
12368 | ||
12369 | if (new > 0) | |
12370 | memcpy (fixptr - old, fixptr, new); | |
12371 | ||
12372 | fragp->fr_fix += new - old; | |
12373 | } | |
12374 | } | |
12375 | ||
12376 | #ifdef OBJ_ELF | |
12377 | ||
12378 | /* This function is called after the relocs have been generated. | |
12379 | We've been storing mips16 text labels as odd. Here we convert them | |
12380 | back to even for the convenience of the debugger. */ | |
12381 | ||
12382 | void | |
12383 | mips_frob_file_after_relocs () | |
12384 | { | |
12385 | asymbol **syms; | |
12386 | unsigned int count, i; | |
12387 | ||
12388 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
12389 | return; | |
12390 | ||
12391 | syms = bfd_get_outsymbols (stdoutput); | |
12392 | count = bfd_get_symcount (stdoutput); | |
12393 | for (i = 0; i < count; i++, syms++) | |
12394 | { | |
12395 | if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16 | |
12396 | && ((*syms)->value & 1) != 0) | |
12397 | { | |
12398 | (*syms)->value &= ~1; | |
12399 | /* If the symbol has an odd size, it was probably computed | |
12400 | incorrectly, so adjust that as well. */ | |
12401 | if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0) | |
12402 | ++elf_symbol (*syms)->internal_elf_sym.st_size; | |
12403 | } | |
12404 | } | |
12405 | } | |
12406 | ||
12407 | #endif | |
12408 | ||
12409 | /* This function is called whenever a label is defined. It is used | |
12410 | when handling branch delays; if a branch has a label, we assume we | |
12411 | can not move it. */ | |
12412 | ||
12413 | void | |
12414 | mips_define_label (sym) | |
12415 | symbolS *sym; | |
12416 | { | |
12417 | struct insn_label_list *l; | |
12418 | ||
12419 | if (free_insn_labels == NULL) | |
12420 | l = (struct insn_label_list *) xmalloc (sizeof *l); | |
12421 | else | |
12422 | { | |
12423 | l = free_insn_labels; | |
12424 | free_insn_labels = l->next; | |
12425 | } | |
12426 | ||
12427 | l->label = sym; | |
12428 | l->next = insn_labels; | |
12429 | insn_labels = l; | |
12430 | } | |
12431 | \f | |
12432 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
12433 | ||
12434 | /* Some special processing for a MIPS ELF file. */ | |
12435 | ||
12436 | void | |
12437 | mips_elf_final_processing () | |
12438 | { | |
12439 | /* Write out the register information. */ | |
e013f690 | 12440 | if (! HAVE_NEWABI) |
252b5132 RH |
12441 | { |
12442 | Elf32_RegInfo s; | |
12443 | ||
12444 | s.ri_gprmask = mips_gprmask; | |
12445 | s.ri_cprmask[0] = mips_cprmask[0]; | |
12446 | s.ri_cprmask[1] = mips_cprmask[1]; | |
12447 | s.ri_cprmask[2] = mips_cprmask[2]; | |
12448 | s.ri_cprmask[3] = mips_cprmask[3]; | |
12449 | /* The gp_value field is set by the MIPS ELF backend. */ | |
12450 | ||
12451 | bfd_mips_elf32_swap_reginfo_out (stdoutput, &s, | |
12452 | ((Elf32_External_RegInfo *) | |
12453 | mips_regmask_frag)); | |
12454 | } | |
12455 | else | |
12456 | { | |
12457 | Elf64_Internal_RegInfo s; | |
12458 | ||
12459 | s.ri_gprmask = mips_gprmask; | |
12460 | s.ri_pad = 0; | |
12461 | s.ri_cprmask[0] = mips_cprmask[0]; | |
12462 | s.ri_cprmask[1] = mips_cprmask[1]; | |
12463 | s.ri_cprmask[2] = mips_cprmask[2]; | |
12464 | s.ri_cprmask[3] = mips_cprmask[3]; | |
12465 | /* The gp_value field is set by the MIPS ELF backend. */ | |
12466 | ||
12467 | bfd_mips_elf64_swap_reginfo_out (stdoutput, &s, | |
12468 | ((Elf64_External_RegInfo *) | |
12469 | mips_regmask_frag)); | |
12470 | } | |
12471 | ||
12472 | /* Set the MIPS ELF flag bits. FIXME: There should probably be some | |
12473 | sort of BFD interface for this. */ | |
12474 | if (mips_any_noreorder) | |
12475 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER; | |
12476 | if (mips_pic != NO_PIC) | |
12477 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC; | |
12478 | ||
bdaaa2e1 | 12479 | /* Set the MIPS ELF ABI flags. */ |
e013f690 | 12480 | if (mips_abi == NO_ABI) |
252b5132 | 12481 | ; |
e013f690 | 12482 | else if (mips_abi == O32_ABI) |
252b5132 | 12483 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32; |
e013f690 | 12484 | else if (mips_abi == O64_ABI) |
252b5132 | 12485 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64; |
e013f690 | 12486 | else if (mips_abi == EABI_ABI) |
252b5132 RH |
12487 | { |
12488 | if (mips_eabi64) | |
12489 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64; | |
12490 | else | |
12491 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32; | |
12492 | } | |
e013f690 | 12493 | else if (mips_abi == N32_ABI) |
be00bddd TS |
12494 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2; |
12495 | ||
12496 | /* Nothing to do for "64". */ | |
252b5132 RH |
12497 | |
12498 | if (mips_32bitmode) | |
12499 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE; | |
12500 | } | |
12501 | ||
12502 | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ | |
12503 | \f | |
beae10d5 KH |
12504 | typedef struct proc { |
12505 | symbolS *isym; | |
12506 | unsigned long reg_mask; | |
12507 | unsigned long reg_offset; | |
12508 | unsigned long fpreg_mask; | |
12509 | unsigned long fpreg_offset; | |
12510 | unsigned long frame_offset; | |
12511 | unsigned long frame_reg; | |
12512 | unsigned long pc_reg; | |
12513 | } procS; | |
252b5132 RH |
12514 | |
12515 | static procS cur_proc; | |
12516 | static procS *cur_proc_ptr; | |
12517 | static int numprocs; | |
12518 | ||
0a9ef439 | 12519 | /* Fill in an rs_align_code fragment. */ |
a19d8eb0 | 12520 | |
0a9ef439 RH |
12521 | void |
12522 | mips_handle_align (fragp) | |
12523 | fragS *fragp; | |
a19d8eb0 | 12524 | { |
0a9ef439 RH |
12525 | if (fragp->fr_type != rs_align_code) |
12526 | return; | |
12527 | ||
12528 | if (mips_opts.mips16) | |
a19d8eb0 CP |
12529 | { |
12530 | static const unsigned char be_nop[] = { 0x65, 0x00 }; | |
12531 | static const unsigned char le_nop[] = { 0x00, 0x65 }; | |
12532 | ||
0a9ef439 RH |
12533 | int bytes; |
12534 | char *p; | |
a19d8eb0 | 12535 | |
0a9ef439 RH |
12536 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
12537 | p = fragp->fr_literal + fragp->fr_fix; | |
12538 | ||
12539 | if (bytes & 1) | |
12540 | { | |
12541 | *p++ = 0; | |
12542 | fragp->fr_fix += 1; | |
12543 | } | |
12544 | ||
12545 | memcpy (p, (target_big_endian ? be_nop : le_nop), 2); | |
12546 | fragp->fr_var = 2; | |
a19d8eb0 CP |
12547 | } |
12548 | ||
0a9ef439 | 12549 | /* For mips32, a nop is a zero, which we trivially get by doing nothing. */ |
a19d8eb0 CP |
12550 | } |
12551 | ||
252b5132 RH |
12552 | static void |
12553 | md_obj_begin () | |
12554 | { | |
12555 | } | |
12556 | ||
12557 | static void | |
12558 | md_obj_end () | |
12559 | { | |
12560 | /* check for premature end, nesting errors, etc */ | |
12561 | if (cur_proc_ptr) | |
9a41af64 | 12562 | as_warn (_("missing .end at end of assembly")); |
252b5132 RH |
12563 | } |
12564 | ||
12565 | static long | |
12566 | get_number () | |
12567 | { | |
12568 | int negative = 0; | |
12569 | long val = 0; | |
12570 | ||
12571 | if (*input_line_pointer == '-') | |
12572 | { | |
12573 | ++input_line_pointer; | |
12574 | negative = 1; | |
12575 | } | |
3882b010 | 12576 | if (!ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12577 | as_bad (_("Expected simple number.")); |
12578 | if (input_line_pointer[0] == '0') | |
12579 | { | |
12580 | if (input_line_pointer[1] == 'x') | |
12581 | { | |
12582 | input_line_pointer += 2; | |
3882b010 | 12583 | while (ISXDIGIT (*input_line_pointer)) |
252b5132 RH |
12584 | { |
12585 | val <<= 4; | |
12586 | val |= hex_value (*input_line_pointer++); | |
12587 | } | |
12588 | return negative ? -val : val; | |
12589 | } | |
12590 | else | |
12591 | { | |
12592 | ++input_line_pointer; | |
3882b010 | 12593 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12594 | { |
12595 | val <<= 3; | |
12596 | val |= *input_line_pointer++ - '0'; | |
12597 | } | |
12598 | return negative ? -val : val; | |
12599 | } | |
12600 | } | |
3882b010 | 12601 | if (!ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12602 | { |
12603 | printf (_(" *input_line_pointer == '%c' 0x%02x\n"), | |
12604 | *input_line_pointer, *input_line_pointer); | |
12605 | as_warn (_("Invalid number")); | |
12606 | return -1; | |
12607 | } | |
3882b010 | 12608 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12609 | { |
12610 | val *= 10; | |
12611 | val += *input_line_pointer++ - '0'; | |
12612 | } | |
12613 | return negative ? -val : val; | |
12614 | } | |
12615 | ||
12616 | /* The .file directive; just like the usual .file directive, but there | |
12617 | is an initial number which is the ECOFF file index. */ | |
12618 | ||
12619 | static void | |
12620 | s_file (x) | |
43841e91 | 12621 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
12622 | { |
12623 | int line; | |
12624 | ||
12625 | line = get_number (); | |
12626 | s_app_file (0); | |
12627 | } | |
12628 | ||
252b5132 RH |
12629 | /* The .end directive. */ |
12630 | ||
12631 | static void | |
12632 | s_mips_end (x) | |
43841e91 | 12633 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
12634 | { |
12635 | symbolS *p; | |
12636 | int maybe_text; | |
12637 | ||
12638 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
12639 | { | |
12640 | p = get_symbol (); | |
12641 | demand_empty_rest_of_line (); | |
12642 | } | |
12643 | else | |
12644 | p = NULL; | |
12645 | ||
12646 | #ifdef BFD_ASSEMBLER | |
12647 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
12648 | maybe_text = 1; | |
12649 | else | |
12650 | maybe_text = 0; | |
12651 | #else | |
12652 | if (now_seg != data_section && now_seg != bss_section) | |
12653 | maybe_text = 1; | |
12654 | else | |
12655 | maybe_text = 0; | |
12656 | #endif | |
12657 | ||
12658 | if (!maybe_text) | |
12659 | as_warn (_(".end not in text section")); | |
12660 | ||
12661 | if (!cur_proc_ptr) | |
12662 | { | |
12663 | as_warn (_(".end directive without a preceding .ent directive.")); | |
12664 | demand_empty_rest_of_line (); | |
12665 | return; | |
12666 | } | |
12667 | ||
12668 | if (p != NULL) | |
12669 | { | |
12670 | assert (S_GET_NAME (p)); | |
12671 | if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym))) | |
12672 | as_warn (_(".end symbol does not match .ent symbol.")); | |
12673 | } | |
12674 | else | |
12675 | as_warn (_(".end directive missing or unknown symbol")); | |
12676 | ||
12677 | #ifdef MIPS_STABS_ELF | |
12678 | { | |
12679 | segT saved_seg = now_seg; | |
12680 | subsegT saved_subseg = now_subseg; | |
252b5132 | 12681 | valueT dot; |
252b5132 RH |
12682 | expressionS exp; |
12683 | char *fragp; | |
12684 | ||
12685 | dot = frag_now_fix (); | |
12686 | ||
12687 | #ifdef md_flush_pending_output | |
12688 | md_flush_pending_output (); | |
12689 | #endif | |
12690 | ||
12691 | assert (pdr_seg); | |
12692 | subseg_set (pdr_seg, 0); | |
12693 | ||
beae10d5 | 12694 | /* Write the symbol. */ |
252b5132 RH |
12695 | exp.X_op = O_symbol; |
12696 | exp.X_add_symbol = p; | |
12697 | exp.X_add_number = 0; | |
12698 | emit_expr (&exp, 4); | |
12699 | ||
beae10d5 | 12700 | fragp = frag_more (7 * 4); |
252b5132 | 12701 | |
beae10d5 KH |
12702 | md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4); |
12703 | md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4); | |
12704 | md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4); | |
12705 | md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4); | |
12706 | md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4); | |
12707 | md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4); | |
12708 | md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4); | |
252b5132 RH |
12709 | |
12710 | subseg_set (saved_seg, saved_subseg); | |
12711 | } | |
12712 | #endif | |
12713 | ||
12714 | cur_proc_ptr = NULL; | |
12715 | } | |
12716 | ||
12717 | /* The .aent and .ent directives. */ | |
12718 | ||
12719 | static void | |
12720 | s_mips_ent (aent) | |
12721 | int aent; | |
12722 | { | |
12723 | int number = 0; | |
12724 | symbolS *symbolP; | |
12725 | int maybe_text; | |
12726 | ||
12727 | symbolP = get_symbol (); | |
12728 | if (*input_line_pointer == ',') | |
12729 | input_line_pointer++; | |
12730 | SKIP_WHITESPACE (); | |
3882b010 | 12731 | if (ISDIGIT (*input_line_pointer) |
d9a62219 | 12732 | || *input_line_pointer == '-') |
252b5132 RH |
12733 | number = get_number (); |
12734 | ||
12735 | #ifdef BFD_ASSEMBLER | |
12736 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
12737 | maybe_text = 1; | |
12738 | else | |
12739 | maybe_text = 0; | |
12740 | #else | |
12741 | if (now_seg != data_section && now_seg != bss_section) | |
12742 | maybe_text = 1; | |
12743 | else | |
12744 | maybe_text = 0; | |
12745 | #endif | |
12746 | ||
12747 | if (!maybe_text) | |
12748 | as_warn (_(".ent or .aent not in text section.")); | |
12749 | ||
12750 | if (!aent && cur_proc_ptr) | |
9a41af64 | 12751 | as_warn (_("missing .end")); |
252b5132 RH |
12752 | |
12753 | if (!aent) | |
12754 | { | |
12755 | cur_proc_ptr = &cur_proc; | |
12756 | memset (cur_proc_ptr, '\0', sizeof (procS)); | |
12757 | ||
12758 | cur_proc_ptr->isym = symbolP; | |
12759 | ||
49309057 | 12760 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
12761 | |
12762 | numprocs++; | |
12763 | } | |
12764 | ||
12765 | demand_empty_rest_of_line (); | |
12766 | } | |
12767 | ||
12768 | /* The .frame directive. If the mdebug section is present (IRIX 5 native) | |
bdaaa2e1 | 12769 | then ecoff.c (ecoff_directive_frame) is used. For embedded targets, |
252b5132 | 12770 | s_mips_frame is used so that we can set the PDR information correctly. |
bdaaa2e1 | 12771 | We can't use the ecoff routines because they make reference to the ecoff |
252b5132 RH |
12772 | symbol table (in the mdebug section). */ |
12773 | ||
12774 | static void | |
12775 | s_mips_frame (ignore) | |
2b3c5a5d | 12776 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
12777 | { |
12778 | #ifdef MIPS_STABS_ELF | |
12779 | ||
12780 | long val; | |
12781 | ||
beae10d5 | 12782 | if (cur_proc_ptr == (procS *) NULL) |
252b5132 RH |
12783 | { |
12784 | as_warn (_(".frame outside of .ent")); | |
12785 | demand_empty_rest_of_line (); | |
12786 | return; | |
12787 | } | |
12788 | ||
12789 | cur_proc_ptr->frame_reg = tc_get_register (1); | |
12790 | ||
12791 | SKIP_WHITESPACE (); | |
12792 | if (*input_line_pointer++ != ',' | |
12793 | || get_absolute_expression_and_terminator (&val) != ',') | |
12794 | { | |
12795 | as_warn (_("Bad .frame directive")); | |
12796 | --input_line_pointer; | |
12797 | demand_empty_rest_of_line (); | |
12798 | return; | |
12799 | } | |
12800 | ||
12801 | cur_proc_ptr->frame_offset = val; | |
12802 | cur_proc_ptr->pc_reg = tc_get_register (0); | |
12803 | ||
12804 | demand_empty_rest_of_line (); | |
12805 | #else | |
12806 | s_ignore (ignore); | |
12807 | #endif /* MIPS_STABS_ELF */ | |
12808 | } | |
12809 | ||
bdaaa2e1 KH |
12810 | /* The .fmask and .mask directives. If the mdebug section is present |
12811 | (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For | |
252b5132 | 12812 | embedded targets, s_mips_mask is used so that we can set the PDR |
bdaaa2e1 | 12813 | information correctly. We can't use the ecoff routines because they |
252b5132 RH |
12814 | make reference to the ecoff symbol table (in the mdebug section). */ |
12815 | ||
12816 | static void | |
12817 | s_mips_mask (reg_type) | |
12818 | char reg_type; | |
12819 | { | |
12820 | #ifdef MIPS_STABS_ELF | |
12821 | long mask, off; | |
bdaaa2e1 | 12822 | |
252b5132 RH |
12823 | if (cur_proc_ptr == (procS *) NULL) |
12824 | { | |
12825 | as_warn (_(".mask/.fmask outside of .ent")); | |
12826 | demand_empty_rest_of_line (); | |
12827 | return; | |
12828 | } | |
12829 | ||
12830 | if (get_absolute_expression_and_terminator (&mask) != ',') | |
12831 | { | |
12832 | as_warn (_("Bad .mask/.fmask directive")); | |
12833 | --input_line_pointer; | |
12834 | demand_empty_rest_of_line (); | |
12835 | return; | |
12836 | } | |
12837 | ||
12838 | off = get_absolute_expression (); | |
12839 | ||
12840 | if (reg_type == 'F') | |
12841 | { | |
12842 | cur_proc_ptr->fpreg_mask = mask; | |
12843 | cur_proc_ptr->fpreg_offset = off; | |
12844 | } | |
12845 | else | |
12846 | { | |
12847 | cur_proc_ptr->reg_mask = mask; | |
12848 | cur_proc_ptr->reg_offset = off; | |
12849 | } | |
12850 | ||
12851 | demand_empty_rest_of_line (); | |
12852 | #else | |
12853 | s_ignore (reg_type); | |
12854 | #endif /* MIPS_STABS_ELF */ | |
12855 | } | |
12856 | ||
12857 | /* The .loc directive. */ | |
12858 | ||
12859 | #if 0 | |
12860 | static void | |
12861 | s_loc (x) | |
12862 | int x; | |
12863 | { | |
12864 | symbolS *symbolP; | |
12865 | int lineno; | |
12866 | int addroff; | |
12867 | ||
12868 | assert (now_seg == text_section); | |
12869 | ||
12870 | lineno = get_number (); | |
12871 | addroff = frag_now_fix (); | |
12872 | ||
12873 | symbolP = symbol_new ("", N_SLINE, addroff, frag_now); | |
12874 | S_SET_TYPE (symbolP, N_SLINE); | |
12875 | S_SET_OTHER (symbolP, 0); | |
12876 | S_SET_DESC (symbolP, lineno); | |
12877 | symbolP->sy_segment = now_seg; | |
12878 | } | |
12879 | #endif | |
e7af610e NC |
12880 | |
12881 | /* CPU name/ISA/number mapping table. | |
12882 | ||
12883 | Entries are grouped by type. The first matching CPU or ISA entry | |
12884 | gets chosen by CPU or ISA, so it should be the 'canonical' name | |
12885 | for that type. Entries after that within the type are sorted | |
12886 | alphabetically. | |
12887 | ||
12888 | Case is ignored in comparison, so put the canonical entry in the | |
12889 | appropriate case but everything else in lower case to ease eye pain. */ | |
e972090a NC |
12890 | static const struct mips_cpu_info mips_cpu_info_table[] = |
12891 | { | |
e7af610e NC |
12892 | /* MIPS1 ISA */ |
12893 | { "MIPS1", 1, ISA_MIPS1, CPU_R3000, }, | |
12894 | { "mips", 1, ISA_MIPS1, CPU_R3000, }, | |
12895 | ||
12896 | /* MIPS2 ISA */ | |
12897 | { "MIPS2", 1, ISA_MIPS2, CPU_R6000, }, | |
12898 | ||
12899 | /* MIPS3 ISA */ | |
12900 | { "MIPS3", 1, ISA_MIPS3, CPU_R4000, }, | |
12901 | ||
12902 | /* MIPS4 ISA */ | |
12903 | { "MIPS4", 1, ISA_MIPS4, CPU_R8000, }, | |
12904 | ||
84ea6cf2 NC |
12905 | /* MIPS5 ISA */ |
12906 | { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, }, | |
12907 | { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, }, | |
12908 | ||
e7af610e NC |
12909 | /* MIPS32 ISA */ |
12910 | { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, }, | |
3c02b2ab | 12911 | { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, }, |
e7af610e | 12912 | { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, }, |
3c02b2ab EC |
12913 | { "4kc", 0, ISA_MIPS32, CPU_MIPS32, }, |
12914 | { "4km", 0, ISA_MIPS32, CPU_MIPS32, }, | |
12915 | { "4kp", 0, ISA_MIPS32, CPU_MIPS32, }, | |
12916 | ||
12917 | /* For historical reasons. */ | |
12918 | { "MIPS64", 1, ISA_MIPS3, CPU_R4000, }, | |
e7af610e | 12919 | |
84ea6cf2 | 12920 | /* MIPS64 ISA */ |
3c02b2ab | 12921 | { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, }, |
84ea6cf2 | 12922 | { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, }, |
3c02b2ab EC |
12923 | { "5kc", 0, ISA_MIPS64, CPU_MIPS64, }, |
12924 | { "20kc", 0, ISA_MIPS64, CPU_MIPS64, }, | |
e7af610e NC |
12925 | |
12926 | /* R2000 CPU */ | |
12927 | { "R2000", 0, ISA_MIPS1, CPU_R2000, }, | |
12928 | { "2000", 0, ISA_MIPS1, CPU_R2000, }, | |
12929 | { "2k", 0, ISA_MIPS1, CPU_R2000, }, | |
12930 | { "r2k", 0, ISA_MIPS1, CPU_R2000, }, | |
12931 | ||
12932 | /* R3000 CPU */ | |
12933 | { "R3000", 0, ISA_MIPS1, CPU_R3000, }, | |
12934 | { "3000", 0, ISA_MIPS1, CPU_R3000, }, | |
12935 | { "3k", 0, ISA_MIPS1, CPU_R3000, }, | |
12936 | { "r3k", 0, ISA_MIPS1, CPU_R3000, }, | |
12937 | ||
12938 | /* TX3900 CPU */ | |
12939 | { "R3900", 0, ISA_MIPS1, CPU_R3900, }, | |
12940 | { "3900", 0, ISA_MIPS1, CPU_R3900, }, | |
e972090a | 12941 | { "mipstx39", 0, ISA_MIPS1, CPU_R3900, }, |
e7af610e NC |
12942 | |
12943 | /* R4000 CPU */ | |
12944 | { "R4000", 0, ISA_MIPS3, CPU_R4000, }, | |
12945 | { "4000", 0, ISA_MIPS3, CPU_R4000, }, | |
12946 | { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */ | |
12947 | { "r4k", 0, ISA_MIPS3, CPU_R4000, }, | |
12948 | ||
12949 | /* R4010 CPU */ | |
12950 | { "R4010", 0, ISA_MIPS2, CPU_R4010, }, | |
12951 | { "4010", 0, ISA_MIPS2, CPU_R4010, }, | |
12952 | ||
12953 | /* R4400 CPU */ | |
12954 | { "R4400", 0, ISA_MIPS3, CPU_R4400, }, | |
12955 | { "4400", 0, ISA_MIPS3, CPU_R4400, }, | |
12956 | ||
12957 | /* R4600 CPU */ | |
12958 | { "R4600", 0, ISA_MIPS3, CPU_R4600, }, | |
12959 | { "4600", 0, ISA_MIPS3, CPU_R4600, }, | |
12960 | { "mips64orion", 0, ISA_MIPS3, CPU_R4600, }, | |
12961 | { "orion", 0, ISA_MIPS3, CPU_R4600, }, | |
12962 | ||
12963 | /* R4650 CPU */ | |
12964 | { "R4650", 0, ISA_MIPS3, CPU_R4650, }, | |
12965 | { "4650", 0, ISA_MIPS3, CPU_R4650, }, | |
12966 | ||
12967 | /* R6000 CPU */ | |
12968 | { "R6000", 0, ISA_MIPS2, CPU_R6000, }, | |
12969 | { "6000", 0, ISA_MIPS2, CPU_R6000, }, | |
12970 | { "6k", 0, ISA_MIPS2, CPU_R6000, }, | |
12971 | { "r6k", 0, ISA_MIPS2, CPU_R6000, }, | |
12972 | ||
12973 | /* R8000 CPU */ | |
12974 | { "R8000", 0, ISA_MIPS4, CPU_R8000, }, | |
12975 | { "8000", 0, ISA_MIPS4, CPU_R8000, }, | |
12976 | { "8k", 0, ISA_MIPS4, CPU_R8000, }, | |
12977 | { "r8k", 0, ISA_MIPS4, CPU_R8000, }, | |
12978 | ||
12979 | /* R10000 CPU */ | |
12980 | { "R10000", 0, ISA_MIPS4, CPU_R10000, }, | |
12981 | { "10000", 0, ISA_MIPS4, CPU_R10000, }, | |
12982 | { "10k", 0, ISA_MIPS4, CPU_R10000, }, | |
12983 | { "r10k", 0, ISA_MIPS4, CPU_R10000, }, | |
12984 | ||
d1cf510e NC |
12985 | /* R12000 CPU */ |
12986 | { "R12000", 0, ISA_MIPS4, CPU_R12000, }, | |
12987 | { "12000", 0, ISA_MIPS4, CPU_R12000, }, | |
12988 | { "12k", 0, ISA_MIPS4, CPU_R12000, }, | |
12989 | { "r12k", 0, ISA_MIPS4, CPU_R12000, }, | |
12990 | ||
e7af610e NC |
12991 | /* VR4100 CPU */ |
12992 | { "VR4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
12993 | { "4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
12994 | { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
12995 | { "r4100", 0, ISA_MIPS3, CPU_VR4100, }, | |
12996 | ||
12997 | /* VR4111 CPU */ | |
12998 | { "VR4111", 0, ISA_MIPS3, CPU_R4111, }, | |
12999 | { "4111", 0, ISA_MIPS3, CPU_R4111, }, | |
13000 | { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, }, | |
13001 | { "r4111", 0, ISA_MIPS3, CPU_R4111, }, | |
13002 | ||
13003 | /* VR4300 CPU */ | |
13004 | { "VR4300", 0, ISA_MIPS3, CPU_R4300, }, | |
13005 | { "4300", 0, ISA_MIPS3, CPU_R4300, }, | |
13006 | { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, }, | |
13007 | { "r4300", 0, ISA_MIPS3, CPU_R4300, }, | |
13008 | ||
13009 | /* VR5000 CPU */ | |
13010 | { "VR5000", 0, ISA_MIPS4, CPU_R5000, }, | |
13011 | { "5000", 0, ISA_MIPS4, CPU_R5000, }, | |
13012 | { "5k", 0, ISA_MIPS4, CPU_R5000, }, | |
13013 | { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, }, | |
13014 | { "r5000", 0, ISA_MIPS4, CPU_R5000, }, | |
13015 | { "r5200", 0, ISA_MIPS4, CPU_R5000, }, | |
18ae5d72 | 13016 | { "rm5200", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 13017 | { "r5230", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 13018 | { "rm5230", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 13019 | { "r5231", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 13020 | { "rm5231", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 13021 | { "r5261", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 13022 | { "rm5261", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e | 13023 | { "r5721", 0, ISA_MIPS4, CPU_R5000, }, |
18ae5d72 | 13024 | { "rm5721", 0, ISA_MIPS4, CPU_R5000, }, |
e7af610e NC |
13025 | { "r5k", 0, ISA_MIPS4, CPU_R5000, }, |
13026 | { "r7000", 0, ISA_MIPS4, CPU_R5000, }, | |
13027 | ||
2e4acd24 | 13028 | /* Broadcom SB-1 CPU */ |
c6c98b38 | 13029 | { "SB-1", 0, ISA_MIPS64, CPU_SB1, }, |
e972090a | 13030 | { "sb-1250", 0, ISA_MIPS64, CPU_SB1, }, |
c6c98b38 NC |
13031 | { "sb1", 0, ISA_MIPS64, CPU_SB1, }, |
13032 | { "sb1250", 0, ISA_MIPS64, CPU_SB1, }, | |
13033 | ||
beae10d5 | 13034 | /* End marker. */ |
e7af610e NC |
13035 | { NULL, 0, 0, 0, }, |
13036 | }; | |
13037 | ||
13038 | static const struct mips_cpu_info * | |
13039 | mips_cpu_info_from_name (name) | |
13040 | const char *name; | |
13041 | { | |
13042 | int i; | |
13043 | ||
13044 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
beae10d5 | 13045 | if (strcasecmp (name, mips_cpu_info_table[i].name) == 0) |
e7af610e NC |
13046 | return (&mips_cpu_info_table[i]); |
13047 | ||
e972090a | 13048 | return NULL; |
e7af610e NC |
13049 | } |
13050 | ||
13051 | static const struct mips_cpu_info * | |
13052 | mips_cpu_info_from_isa (isa) | |
13053 | int isa; | |
13054 | { | |
13055 | int i; | |
13056 | ||
13057 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
13058 | if (mips_cpu_info_table[i].is_isa | |
13059 | && isa == mips_cpu_info_table[i].isa) | |
13060 | return (&mips_cpu_info_table[i]); | |
13061 | ||
e972090a | 13062 | return NULL; |
e7af610e NC |
13063 | } |
13064 | ||
13065 | static const struct mips_cpu_info * | |
13066 | mips_cpu_info_from_cpu (cpu) | |
13067 | int cpu; | |
13068 | { | |
13069 | int i; | |
13070 | ||
13071 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
13072 | if (!mips_cpu_info_table[i].is_isa | |
13073 | && cpu == mips_cpu_info_table[i].cpu) | |
13074 | return (&mips_cpu_info_table[i]); | |
13075 | ||
e972090a | 13076 | return NULL; |
e7af610e | 13077 | } |