Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-mips.c -- assemble code for a MIPS chip. |
81912461 | 2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
e407c74b | 3 | 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 |
c67a084a | 4 | Free Software Foundation, Inc. |
252b5132 RH |
5 | Contributed by the OSF and Ralph Campbell. |
6 | Written by Keith Knowles and Ralph Campbell, working independently. | |
7 | Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus | |
8 | Support. | |
9 | ||
10 | This file is part of GAS. | |
11 | ||
12 | GAS is free software; you can redistribute it and/or modify | |
13 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 14 | the Free Software Foundation; either version 3, or (at your option) |
252b5132 RH |
15 | any later version. |
16 | ||
17 | GAS is distributed in the hope that it will be useful, | |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | GNU General Public License for more details. | |
21 | ||
22 | You should have received a copy of the GNU General Public License | |
23 | along with GAS; see the file COPYING. If not, write to the Free | |
4b4da160 NC |
24 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
25 | 02110-1301, USA. */ | |
252b5132 RH |
26 | |
27 | #include "as.h" | |
28 | #include "config.h" | |
29 | #include "subsegs.h" | |
3882b010 | 30 | #include "safe-ctype.h" |
252b5132 | 31 | |
252b5132 RH |
32 | #include "opcode/mips.h" |
33 | #include "itbl-ops.h" | |
c5dd6aab | 34 | #include "dwarf2dbg.h" |
5862107c | 35 | #include "dw2gencfi.h" |
252b5132 RH |
36 | |
37 | #ifdef DEBUG | |
38 | #define DBG(x) printf x | |
39 | #else | |
40 | #define DBG(x) | |
41 | #endif | |
42 | ||
43 | #ifdef OBJ_MAYBE_ELF | |
44 | /* Clean up namespace so we can include obj-elf.h too. */ | |
17a2f251 TS |
45 | static int mips_output_flavor (void); |
46 | static int mips_output_flavor (void) { return OUTPUT_FLAVOR; } | |
252b5132 RH |
47 | #undef OBJ_PROCESS_STAB |
48 | #undef OUTPUT_FLAVOR | |
49 | #undef S_GET_ALIGN | |
50 | #undef S_GET_SIZE | |
51 | #undef S_SET_ALIGN | |
52 | #undef S_SET_SIZE | |
252b5132 RH |
53 | #undef obj_frob_file |
54 | #undef obj_frob_file_after_relocs | |
55 | #undef obj_frob_symbol | |
56 | #undef obj_pop_insert | |
57 | #undef obj_sec_sym_ok_for_reloc | |
58 | #undef OBJ_COPY_SYMBOL_ATTRIBUTES | |
59 | ||
60 | #include "obj-elf.h" | |
61 | /* Fix any of them that we actually care about. */ | |
62 | #undef OUTPUT_FLAVOR | |
63 | #define OUTPUT_FLAVOR mips_output_flavor() | |
64 | #endif | |
65 | ||
66 | #if defined (OBJ_ELF) | |
67 | #include "elf/mips.h" | |
68 | #endif | |
69 | ||
70 | #ifndef ECOFF_DEBUGGING | |
71 | #define NO_ECOFF_DEBUGGING | |
72 | #define ECOFF_DEBUGGING 0 | |
73 | #endif | |
74 | ||
ecb4347a DJ |
75 | int mips_flag_mdebug = -1; |
76 | ||
dcd410fe RO |
77 | /* Control generation of .pdr sections. Off by default on IRIX: the native |
78 | linker doesn't know about and discards them, but relocations against them | |
79 | remain, leading to rld crashes. */ | |
80 | #ifdef TE_IRIX | |
81 | int mips_flag_pdr = FALSE; | |
82 | #else | |
83 | int mips_flag_pdr = TRUE; | |
84 | #endif | |
85 | ||
252b5132 RH |
86 | #include "ecoff.h" |
87 | ||
88 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
89 | static char *mips_regmask_frag; | |
90 | #endif | |
91 | ||
85b51719 | 92 | #define ZERO 0 |
741fe287 | 93 | #define ATREG 1 |
df58fc94 RS |
94 | #define S0 16 |
95 | #define S7 23 | |
252b5132 RH |
96 | #define TREG 24 |
97 | #define PIC_CALL_REG 25 | |
98 | #define KT0 26 | |
99 | #define KT1 27 | |
100 | #define GP 28 | |
101 | #define SP 29 | |
102 | #define FP 30 | |
103 | #define RA 31 | |
104 | ||
105 | #define ILLEGAL_REG (32) | |
106 | ||
741fe287 MR |
107 | #define AT mips_opts.at |
108 | ||
252b5132 RH |
109 | /* Allow override of standard little-endian ECOFF format. */ |
110 | ||
111 | #ifndef ECOFF_LITTLE_FORMAT | |
112 | #define ECOFF_LITTLE_FORMAT "ecoff-littlemips" | |
113 | #endif | |
114 | ||
115 | extern int target_big_endian; | |
116 | ||
252b5132 | 117 | /* The name of the readonly data section. */ |
4d0d148d | 118 | #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \ |
252b5132 | 119 | ? ".rdata" \ |
056350c6 NC |
120 | : OUTPUT_FLAVOR == bfd_target_coff_flavour \ |
121 | ? ".rdata" \ | |
252b5132 RH |
122 | : OUTPUT_FLAVOR == bfd_target_elf_flavour \ |
123 | ? ".rodata" \ | |
124 | : (abort (), "")) | |
125 | ||
a4e06468 RS |
126 | /* Ways in which an instruction can be "appended" to the output. */ |
127 | enum append_method { | |
128 | /* Just add it normally. */ | |
129 | APPEND_ADD, | |
130 | ||
131 | /* Add it normally and then add a nop. */ | |
132 | APPEND_ADD_WITH_NOP, | |
133 | ||
134 | /* Turn an instruction with a delay slot into a "compact" version. */ | |
135 | APPEND_ADD_COMPACT, | |
136 | ||
137 | /* Insert the instruction before the last one. */ | |
138 | APPEND_SWAP | |
139 | }; | |
140 | ||
47e39b9d RS |
141 | /* Information about an instruction, including its format, operands |
142 | and fixups. */ | |
143 | struct mips_cl_insn | |
144 | { | |
145 | /* The opcode's entry in mips_opcodes or mips16_opcodes. */ | |
146 | const struct mips_opcode *insn_mo; | |
147 | ||
47e39b9d | 148 | /* The 16-bit or 32-bit bitstring of the instruction itself. This is |
5c04167a RS |
149 | a copy of INSN_MO->match with the operands filled in. If we have |
150 | decided to use an extended MIPS16 instruction, this includes the | |
151 | extension. */ | |
47e39b9d RS |
152 | unsigned long insn_opcode; |
153 | ||
154 | /* The frag that contains the instruction. */ | |
155 | struct frag *frag; | |
156 | ||
157 | /* The offset into FRAG of the first instruction byte. */ | |
158 | long where; | |
159 | ||
160 | /* The relocs associated with the instruction, if any. */ | |
161 | fixS *fixp[3]; | |
162 | ||
a38419a5 RS |
163 | /* True if this entry cannot be moved from its current position. */ |
164 | unsigned int fixed_p : 1; | |
47e39b9d | 165 | |
708587a4 | 166 | /* True if this instruction occurred in a .set noreorder block. */ |
47e39b9d RS |
167 | unsigned int noreorder_p : 1; |
168 | ||
2fa15973 RS |
169 | /* True for mips16 instructions that jump to an absolute address. */ |
170 | unsigned int mips16_absolute_jump_p : 1; | |
15be625d CM |
171 | |
172 | /* True if this instruction is complete. */ | |
173 | unsigned int complete_p : 1; | |
e407c74b NC |
174 | |
175 | /* True if this instruction is cleared from history by unconditional | |
176 | branch. */ | |
177 | unsigned int cleared_p : 1; | |
47e39b9d RS |
178 | }; |
179 | ||
a325df1d TS |
180 | /* The ABI to use. */ |
181 | enum mips_abi_level | |
182 | { | |
183 | NO_ABI = 0, | |
184 | O32_ABI, | |
185 | O64_ABI, | |
186 | N32_ABI, | |
187 | N64_ABI, | |
188 | EABI_ABI | |
189 | }; | |
190 | ||
191 | /* MIPS ABI we are using for this output file. */ | |
316f5878 | 192 | static enum mips_abi_level mips_abi = NO_ABI; |
a325df1d | 193 | |
143d77c5 EC |
194 | /* Whether or not we have code that can call pic code. */ |
195 | int mips_abicalls = FALSE; | |
196 | ||
aa6975fb ILT |
197 | /* Whether or not we have code which can be put into a shared |
198 | library. */ | |
199 | static bfd_boolean mips_in_shared = TRUE; | |
200 | ||
252b5132 RH |
201 | /* This is the set of options which may be modified by the .set |
202 | pseudo-op. We use a struct so that .set push and .set pop are more | |
203 | reliable. */ | |
204 | ||
e972090a NC |
205 | struct mips_set_options |
206 | { | |
252b5132 RH |
207 | /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 |
208 | if it has not been initialized. Changed by `.set mipsN', and the | |
209 | -mipsN command line option, and the default CPU. */ | |
210 | int isa; | |
1f25f5d3 CD |
211 | /* Enabled Application Specific Extensions (ASEs). These are set to -1 |
212 | if they have not been initialized. Changed by `.set <asename>', by | |
213 | command line options, and based on the default architecture. */ | |
214 | int ase_mips3d; | |
deec1734 | 215 | int ase_mdmx; |
e16bfa71 | 216 | int ase_smartmips; |
74cd071d | 217 | int ase_dsp; |
8b082fb1 | 218 | int ase_dspr2; |
ef2e4d86 | 219 | int ase_mt; |
dec0624d | 220 | int ase_mcu; |
252b5132 RH |
221 | /* Whether we are assembling for the mips16 processor. 0 if we are |
222 | not, 1 if we are, and -1 if the value has not been initialized. | |
223 | Changed by `.set mips16' and `.set nomips16', and the -mips16 and | |
224 | -nomips16 command line options, and the default CPU. */ | |
225 | int mips16; | |
df58fc94 RS |
226 | /* Whether we are assembling for the mipsMIPS ASE. 0 if we are not, |
227 | 1 if we are, and -1 if the value has not been initialized. Changed | |
228 | by `.set micromips' and `.set nomicromips', and the -mmicromips | |
229 | and -mno-micromips command line options, and the default CPU. */ | |
230 | int micromips; | |
252b5132 RH |
231 | /* Non-zero if we should not reorder instructions. Changed by `.set |
232 | reorder' and `.set noreorder'. */ | |
233 | int noreorder; | |
741fe287 MR |
234 | /* Non-zero if we should not permit the register designated "assembler |
235 | temporary" to be used in instructions. The value is the register | |
236 | number, normally $at ($1). Changed by `.set at=REG', `.set noat' | |
237 | (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */ | |
238 | unsigned int at; | |
252b5132 RH |
239 | /* Non-zero if we should warn when a macro instruction expands into |
240 | more than one machine instruction. Changed by `.set nomacro' and | |
241 | `.set macro'. */ | |
242 | int warn_about_macros; | |
243 | /* Non-zero if we should not move instructions. Changed by `.set | |
244 | move', `.set volatile', `.set nomove', and `.set novolatile'. */ | |
245 | int nomove; | |
246 | /* Non-zero if we should not optimize branches by moving the target | |
247 | of the branch into the delay slot. Actually, we don't perform | |
248 | this optimization anyhow. Changed by `.set bopt' and `.set | |
249 | nobopt'. */ | |
250 | int nobopt; | |
251 | /* Non-zero if we should not autoextend mips16 instructions. | |
252 | Changed by `.set autoextend' and `.set noautoextend'. */ | |
253 | int noautoextend; | |
a325df1d TS |
254 | /* Restrict general purpose registers and floating point registers |
255 | to 32 bit. This is initially determined when -mgp32 or -mfp32 | |
256 | is passed but can changed if the assembler code uses .set mipsN. */ | |
257 | int gp32; | |
258 | int fp32; | |
fef14a42 TS |
259 | /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march |
260 | command line option, and the default CPU. */ | |
261 | int arch; | |
aed1a261 RS |
262 | /* True if ".set sym32" is in effect. */ |
263 | bfd_boolean sym32; | |
037b32b9 AN |
264 | /* True if floating-point operations are not allowed. Changed by .set |
265 | softfloat or .set hardfloat, by command line options -msoft-float or | |
266 | -mhard-float. The default is false. */ | |
267 | bfd_boolean soft_float; | |
268 | ||
269 | /* True if only single-precision floating-point operations are allowed. | |
270 | Changed by .set singlefloat or .set doublefloat, command-line options | |
271 | -msingle-float or -mdouble-float. The default is false. */ | |
272 | bfd_boolean single_float; | |
252b5132 RH |
273 | }; |
274 | ||
037b32b9 AN |
275 | /* This is the struct we use to hold the current set of options. Note |
276 | that we must set the isa field to ISA_UNKNOWN and the ASE fields to | |
277 | -1 to indicate that they have not been initialized. */ | |
278 | ||
a325df1d | 279 | /* True if -mgp32 was passed. */ |
a8e8e863 | 280 | static int file_mips_gp32 = -1; |
a325df1d TS |
281 | |
282 | /* True if -mfp32 was passed. */ | |
a8e8e863 | 283 | static int file_mips_fp32 = -1; |
a325df1d | 284 | |
037b32b9 AN |
285 | /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */ |
286 | static int file_mips_soft_float = 0; | |
287 | ||
288 | /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */ | |
289 | static int file_mips_single_float = 0; | |
252b5132 | 290 | |
e972090a NC |
291 | static struct mips_set_options mips_opts = |
292 | { | |
037b32b9 AN |
293 | /* isa */ ISA_UNKNOWN, /* ase_mips3d */ -1, /* ase_mdmx */ -1, |
294 | /* ase_smartmips */ 0, /* ase_dsp */ -1, /* ase_dspr2 */ -1, /* ase_mt */ -1, | |
dec0624d MR |
295 | /* ase_mcu */ -1, /* mips16 */ -1, /* micromips */ -1, /* noreorder */ 0, |
296 | /* at */ ATREG, /* warn_about_macros */ 0, /* nomove */ 0, /* nobopt */ 0, | |
037b32b9 AN |
297 | /* noautoextend */ 0, /* gp32 */ 0, /* fp32 */ 0, /* arch */ CPU_UNKNOWN, |
298 | /* sym32 */ FALSE, /* soft_float */ FALSE, /* single_float */ FALSE | |
e7af610e | 299 | }; |
252b5132 RH |
300 | |
301 | /* These variables are filled in with the masks of registers used. | |
302 | The object format code reads them and puts them in the appropriate | |
303 | place. */ | |
304 | unsigned long mips_gprmask; | |
305 | unsigned long mips_cprmask[4]; | |
306 | ||
307 | /* MIPS ISA we are using for this output file. */ | |
e7af610e | 308 | static int file_mips_isa = ISA_UNKNOWN; |
252b5132 | 309 | |
738f4d98 | 310 | /* True if any MIPS16 code was produced. */ |
a4672219 TS |
311 | static int file_ase_mips16; |
312 | ||
3994f87e TS |
313 | #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \ |
314 | || mips_opts.isa == ISA_MIPS32R2 \ | |
315 | || mips_opts.isa == ISA_MIPS64 \ | |
316 | || mips_opts.isa == ISA_MIPS64R2) | |
317 | ||
df58fc94 RS |
318 | /* True if any microMIPS code was produced. */ |
319 | static int file_ase_micromips; | |
320 | ||
b12dd2e4 CF |
321 | /* True if we want to create R_MIPS_JALR for jalr $25. */ |
322 | #ifdef TE_IRIX | |
1180b5a4 | 323 | #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI |
b12dd2e4 | 324 | #else |
1180b5a4 RS |
325 | /* As a GNU extension, we use R_MIPS_JALR for o32 too. However, |
326 | because there's no place for any addend, the only acceptable | |
327 | expression is a bare symbol. */ | |
328 | #define MIPS_JALR_HINT_P(EXPR) \ | |
329 | (!HAVE_IN_PLACE_ADDENDS \ | |
330 | || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0)) | |
b12dd2e4 CF |
331 | #endif |
332 | ||
1f25f5d3 CD |
333 | /* True if -mips3d was passed or implied by arguments passed on the |
334 | command line (e.g., by -march). */ | |
335 | static int file_ase_mips3d; | |
336 | ||
deec1734 CD |
337 | /* True if -mdmx was passed or implied by arguments passed on the |
338 | command line (e.g., by -march). */ | |
339 | static int file_ase_mdmx; | |
340 | ||
e16bfa71 TS |
341 | /* True if -msmartmips was passed or implied by arguments passed on the |
342 | command line (e.g., by -march). */ | |
343 | static int file_ase_smartmips; | |
344 | ||
ad3fea08 TS |
345 | #define ISA_SUPPORTS_SMARTMIPS (mips_opts.isa == ISA_MIPS32 \ |
346 | || mips_opts.isa == ISA_MIPS32R2) | |
e16bfa71 | 347 | |
74cd071d CF |
348 | /* True if -mdsp was passed or implied by arguments passed on the |
349 | command line (e.g., by -march). */ | |
350 | static int file_ase_dsp; | |
351 | ||
ad3fea08 | 352 | #define ISA_SUPPORTS_DSP_ASE (mips_opts.isa == ISA_MIPS32R2 \ |
03f66e8a MR |
353 | || mips_opts.isa == ISA_MIPS64R2 \ |
354 | || mips_opts.micromips) | |
ad3fea08 | 355 | |
65263ce3 TS |
356 | #define ISA_SUPPORTS_DSP64_ASE (mips_opts.isa == ISA_MIPS64R2) |
357 | ||
8b082fb1 TS |
358 | /* True if -mdspr2 was passed or implied by arguments passed on the |
359 | command line (e.g., by -march). */ | |
360 | static int file_ase_dspr2; | |
361 | ||
362 | #define ISA_SUPPORTS_DSPR2_ASE (mips_opts.isa == ISA_MIPS32R2 \ | |
03f66e8a MR |
363 | || mips_opts.isa == ISA_MIPS64R2 \ |
364 | || mips_opts.micromips) | |
8b082fb1 | 365 | |
ef2e4d86 CF |
366 | /* True if -mmt was passed or implied by arguments passed on the |
367 | command line (e.g., by -march). */ | |
368 | static int file_ase_mt; | |
369 | ||
ad3fea08 TS |
370 | #define ISA_SUPPORTS_MT_ASE (mips_opts.isa == ISA_MIPS32R2 \ |
371 | || mips_opts.isa == ISA_MIPS64R2) | |
372 | ||
dec0624d | 373 | #define ISA_SUPPORTS_MCU_ASE (mips_opts.isa == ISA_MIPS32R2 \ |
9ddc84cc MR |
374 | || mips_opts.isa == ISA_MIPS64R2 \ |
375 | || mips_opts.micromips) | |
dec0624d | 376 | |
ec68c924 | 377 | /* The argument of the -march= flag. The architecture we are assembling. */ |
fef14a42 | 378 | static int file_mips_arch = CPU_UNKNOWN; |
316f5878 | 379 | static const char *mips_arch_string; |
ec68c924 EC |
380 | |
381 | /* The argument of the -mtune= flag. The architecture for which we | |
382 | are optimizing. */ | |
383 | static int mips_tune = CPU_UNKNOWN; | |
316f5878 | 384 | static const char *mips_tune_string; |
ec68c924 | 385 | |
316f5878 | 386 | /* True when generating 32-bit code for a 64-bit processor. */ |
252b5132 RH |
387 | static int mips_32bitmode = 0; |
388 | ||
316f5878 RS |
389 | /* True if the given ABI requires 32-bit registers. */ |
390 | #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI) | |
391 | ||
392 | /* Likewise 64-bit registers. */ | |
707bfff6 TS |
393 | #define ABI_NEEDS_64BIT_REGS(ABI) \ |
394 | ((ABI) == N32_ABI \ | |
395 | || (ABI) == N64_ABI \ | |
316f5878 RS |
396 | || (ABI) == O64_ABI) |
397 | ||
ad3fea08 | 398 | /* Return true if ISA supports 64 bit wide gp registers. */ |
707bfff6 TS |
399 | #define ISA_HAS_64BIT_REGS(ISA) \ |
400 | ((ISA) == ISA_MIPS3 \ | |
401 | || (ISA) == ISA_MIPS4 \ | |
402 | || (ISA) == ISA_MIPS5 \ | |
403 | || (ISA) == ISA_MIPS64 \ | |
404 | || (ISA) == ISA_MIPS64R2) | |
9ce8a5dd | 405 | |
ad3fea08 TS |
406 | /* Return true if ISA supports 64 bit wide float registers. */ |
407 | #define ISA_HAS_64BIT_FPRS(ISA) \ | |
408 | ((ISA) == ISA_MIPS3 \ | |
409 | || (ISA) == ISA_MIPS4 \ | |
410 | || (ISA) == ISA_MIPS5 \ | |
411 | || (ISA) == ISA_MIPS32R2 \ | |
412 | || (ISA) == ISA_MIPS64 \ | |
413 | || (ISA) == ISA_MIPS64R2) | |
414 | ||
af7ee8bf CD |
415 | /* Return true if ISA supports 64-bit right rotate (dror et al.) |
416 | instructions. */ | |
707bfff6 | 417 | #define ISA_HAS_DROR(ISA) \ |
df58fc94 RS |
418 | ((ISA) == ISA_MIPS64R2 \ |
419 | || (mips_opts.micromips \ | |
420 | && ISA_HAS_64BIT_REGS (ISA)) \ | |
421 | ) | |
af7ee8bf CD |
422 | |
423 | /* Return true if ISA supports 32-bit right rotate (ror et al.) | |
424 | instructions. */ | |
707bfff6 TS |
425 | #define ISA_HAS_ROR(ISA) \ |
426 | ((ISA) == ISA_MIPS32R2 \ | |
427 | || (ISA) == ISA_MIPS64R2 \ | |
df58fc94 RS |
428 | || mips_opts.ase_smartmips \ |
429 | || mips_opts.micromips \ | |
430 | ) | |
707bfff6 | 431 | |
7455baf8 TS |
432 | /* Return true if ISA supports single-precision floats in odd registers. */ |
433 | #define ISA_HAS_ODD_SINGLE_FPR(ISA) \ | |
434 | ((ISA) == ISA_MIPS32 \ | |
435 | || (ISA) == ISA_MIPS32R2 \ | |
436 | || (ISA) == ISA_MIPS64 \ | |
437 | || (ISA) == ISA_MIPS64R2) | |
af7ee8bf | 438 | |
ad3fea08 TS |
439 | /* Return true if ISA supports move to/from high part of a 64-bit |
440 | floating-point register. */ | |
441 | #define ISA_HAS_MXHC1(ISA) \ | |
442 | ((ISA) == ISA_MIPS32R2 \ | |
443 | || (ISA) == ISA_MIPS64R2) | |
444 | ||
e013f690 | 445 | #define HAVE_32BIT_GPRS \ |
ad3fea08 | 446 | (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa)) |
ca4e0257 | 447 | |
e013f690 | 448 | #define HAVE_32BIT_FPRS \ |
ad3fea08 | 449 | (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa)) |
ca4e0257 | 450 | |
ad3fea08 TS |
451 | #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS) |
452 | #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS) | |
ca4e0257 | 453 | |
316f5878 | 454 | #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI) |
e013f690 | 455 | |
316f5878 | 456 | #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI) |
e013f690 | 457 | |
3b91255e RS |
458 | /* True if relocations are stored in-place. */ |
459 | #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI) | |
460 | ||
aed1a261 RS |
461 | /* The ABI-derived address size. */ |
462 | #define HAVE_64BIT_ADDRESSES \ | |
463 | (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI)) | |
464 | #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES) | |
e013f690 | 465 | |
aed1a261 RS |
466 | /* The size of symbolic constants (i.e., expressions of the form |
467 | "SYMBOL" or "SYMBOL + OFFSET"). */ | |
468 | #define HAVE_32BIT_SYMBOLS \ | |
469 | (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32) | |
470 | #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS) | |
ca4e0257 | 471 | |
b7c7d6c1 TS |
472 | /* Addresses are loaded in different ways, depending on the address size |
473 | in use. The n32 ABI Documentation also mandates the use of additions | |
474 | with overflow checking, but existing implementations don't follow it. */ | |
f899b4b8 | 475 | #define ADDRESS_ADD_INSN \ |
b7c7d6c1 | 476 | (HAVE_32BIT_ADDRESSES ? "addu" : "daddu") |
f899b4b8 TS |
477 | |
478 | #define ADDRESS_ADDI_INSN \ | |
b7c7d6c1 | 479 | (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu") |
f899b4b8 TS |
480 | |
481 | #define ADDRESS_LOAD_INSN \ | |
482 | (HAVE_32BIT_ADDRESSES ? "lw" : "ld") | |
483 | ||
484 | #define ADDRESS_STORE_INSN \ | |
485 | (HAVE_32BIT_ADDRESSES ? "sw" : "sd") | |
486 | ||
a4672219 | 487 | /* Return true if the given CPU supports the MIPS16 ASE. */ |
3396de36 TS |
488 | #define CPU_HAS_MIPS16(cpu) \ |
489 | (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \ | |
490 | || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0) | |
a4672219 | 491 | |
2309ddf2 | 492 | /* Return true if the given CPU supports the microMIPS ASE. */ |
df58fc94 RS |
493 | #define CPU_HAS_MICROMIPS(cpu) 0 |
494 | ||
60b63b72 RS |
495 | /* True if CPU has a dror instruction. */ |
496 | #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500) | |
497 | ||
498 | /* True if CPU has a ror instruction. */ | |
499 | #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU) | |
500 | ||
dd6a37e7 | 501 | /* True if CPU is in the Octeon family */ |
432233b3 | 502 | #define CPU_IS_OCTEON(CPU) ((CPU) == CPU_OCTEON || (CPU) == CPU_OCTEONP || (CPU) == CPU_OCTEON2) |
dd6a37e7 | 503 | |
dd3cbb7e | 504 | /* True if CPU has seq/sne and seqi/snei instructions. */ |
dd6a37e7 | 505 | #define CPU_HAS_SEQ(CPU) (CPU_IS_OCTEON (CPU)) |
dd3cbb7e | 506 | |
0aa27725 RS |
507 | /* True, if CPU has support for ldc1 and sdc1. */ |
508 | #define CPU_HAS_LDC1_SDC1(CPU) \ | |
509 | ((mips_opts.isa != ISA_MIPS1) && ((CPU) != CPU_R5900)) | |
510 | ||
c8978940 CD |
511 | /* True if mflo and mfhi can be immediately followed by instructions |
512 | which write to the HI and LO registers. | |
513 | ||
514 | According to MIPS specifications, MIPS ISAs I, II, and III need | |
515 | (at least) two instructions between the reads of HI/LO and | |
516 | instructions which write them, and later ISAs do not. Contradicting | |
517 | the MIPS specifications, some MIPS IV processor user manuals (e.g. | |
518 | the UM for the NEC Vr5000) document needing the instructions between | |
519 | HI/LO reads and writes, as well. Therefore, we declare only MIPS32, | |
520 | MIPS64 and later ISAs to have the interlocks, plus any specific | |
521 | earlier-ISA CPUs for which CPU documentation declares that the | |
522 | instructions are really interlocked. */ | |
523 | #define hilo_interlocks \ | |
524 | (mips_opts.isa == ISA_MIPS32 \ | |
525 | || mips_opts.isa == ISA_MIPS32R2 \ | |
526 | || mips_opts.isa == ISA_MIPS64 \ | |
527 | || mips_opts.isa == ISA_MIPS64R2 \ | |
528 | || mips_opts.arch == CPU_R4010 \ | |
e407c74b | 529 | || mips_opts.arch == CPU_R5900 \ |
c8978940 CD |
530 | || mips_opts.arch == CPU_R10000 \ |
531 | || mips_opts.arch == CPU_R12000 \ | |
3aa3176b TS |
532 | || mips_opts.arch == CPU_R14000 \ |
533 | || mips_opts.arch == CPU_R16000 \ | |
c8978940 | 534 | || mips_opts.arch == CPU_RM7000 \ |
c8978940 | 535 | || mips_opts.arch == CPU_VR5500 \ |
df58fc94 | 536 | || mips_opts.micromips \ |
c8978940 | 537 | ) |
252b5132 RH |
538 | |
539 | /* Whether the processor uses hardware interlocks to protect reads | |
81912461 ILT |
540 | from the GPRs after they are loaded from memory, and thus does not |
541 | require nops to be inserted. This applies to instructions marked | |
542 | INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA | |
df58fc94 RS |
543 | level I and microMIPS mode instructions are always interlocked. */ |
544 | #define gpr_interlocks \ | |
545 | (mips_opts.isa != ISA_MIPS1 \ | |
546 | || mips_opts.arch == CPU_R3900 \ | |
e407c74b | 547 | || mips_opts.arch == CPU_R5900 \ |
df58fc94 RS |
548 | || mips_opts.micromips \ |
549 | ) | |
252b5132 | 550 | |
81912461 ILT |
551 | /* Whether the processor uses hardware interlocks to avoid delays |
552 | required by coprocessor instructions, and thus does not require | |
553 | nops to be inserted. This applies to instructions marked | |
554 | INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays | |
555 | between instructions marked INSN_WRITE_COND_CODE and ones marked | |
556 | INSN_READ_COND_CODE. These nops are only required at MIPS ISA | |
df58fc94 RS |
557 | levels I, II, and III and microMIPS mode instructions are always |
558 | interlocked. */ | |
bdaaa2e1 | 559 | /* Itbl support may require additional care here. */ |
81912461 ILT |
560 | #define cop_interlocks \ |
561 | ((mips_opts.isa != ISA_MIPS1 \ | |
562 | && mips_opts.isa != ISA_MIPS2 \ | |
563 | && mips_opts.isa != ISA_MIPS3) \ | |
564 | || mips_opts.arch == CPU_R4300 \ | |
df58fc94 | 565 | || mips_opts.micromips \ |
81912461 ILT |
566 | ) |
567 | ||
568 | /* Whether the processor uses hardware interlocks to protect reads | |
569 | from coprocessor registers after they are loaded from memory, and | |
570 | thus does not require nops to be inserted. This applies to | |
571 | instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only | |
df58fc94 RS |
572 | requires at MIPS ISA level I and microMIPS mode instructions are |
573 | always interlocked. */ | |
574 | #define cop_mem_interlocks \ | |
575 | (mips_opts.isa != ISA_MIPS1 \ | |
576 | || mips_opts.micromips \ | |
577 | ) | |
252b5132 | 578 | |
6b76fefe CM |
579 | /* Is this a mfhi or mflo instruction? */ |
580 | #define MF_HILO_INSN(PINFO) \ | |
b19e8a9b AN |
581 | ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO)) |
582 | ||
df58fc94 RS |
583 | /* Whether code compression (either of the MIPS16 or the microMIPS ASEs) |
584 | has been selected. This implies, in particular, that addresses of text | |
585 | labels have their LSB set. */ | |
586 | #define HAVE_CODE_COMPRESSION \ | |
587 | ((mips_opts.mips16 | mips_opts.micromips) != 0) | |
588 | ||
252b5132 RH |
589 | /* MIPS PIC level. */ |
590 | ||
a161fe53 | 591 | enum mips_pic_level mips_pic; |
252b5132 | 592 | |
c9914766 | 593 | /* 1 if we should generate 32 bit offsets from the $gp register in |
252b5132 | 594 | SVR4_PIC mode. Currently has no meaning in other modes. */ |
c9914766 | 595 | static int mips_big_got = 0; |
252b5132 RH |
596 | |
597 | /* 1 if trap instructions should used for overflow rather than break | |
598 | instructions. */ | |
c9914766 | 599 | static int mips_trap = 0; |
252b5132 | 600 | |
119d663a | 601 | /* 1 if double width floating point constants should not be constructed |
b6ff326e | 602 | by assembling two single width halves into two single width floating |
119d663a NC |
603 | point registers which just happen to alias the double width destination |
604 | register. On some architectures this aliasing can be disabled by a bit | |
d547a75e | 605 | in the status register, and the setting of this bit cannot be determined |
119d663a NC |
606 | automatically at assemble time. */ |
607 | static int mips_disable_float_construction; | |
608 | ||
252b5132 RH |
609 | /* Non-zero if any .set noreorder directives were used. */ |
610 | ||
611 | static int mips_any_noreorder; | |
612 | ||
6b76fefe CM |
613 | /* Non-zero if nops should be inserted when the register referenced in |
614 | an mfhi/mflo instruction is read in the next two instructions. */ | |
615 | static int mips_7000_hilo_fix; | |
616 | ||
02ffd3e4 | 617 | /* The size of objects in the small data section. */ |
156c2f8b | 618 | static unsigned int g_switch_value = 8; |
252b5132 RH |
619 | /* Whether the -G option was used. */ |
620 | static int g_switch_seen = 0; | |
621 | ||
622 | #define N_RMASK 0xc4 | |
623 | #define N_VFP 0xd4 | |
624 | ||
625 | /* If we can determine in advance that GP optimization won't be | |
626 | possible, we can skip the relaxation stuff that tries to produce | |
627 | GP-relative references. This makes delay slot optimization work | |
628 | better. | |
629 | ||
630 | This function can only provide a guess, but it seems to work for | |
fba2b7f9 GK |
631 | gcc output. It needs to guess right for gcc, otherwise gcc |
632 | will put what it thinks is a GP-relative instruction in a branch | |
633 | delay slot. | |
252b5132 RH |
634 | |
635 | I don't know if a fix is needed for the SVR4_PIC mode. I've only | |
636 | fixed it for the non-PIC mode. KR 95/04/07 */ | |
17a2f251 | 637 | static int nopic_need_relax (symbolS *, int); |
252b5132 RH |
638 | |
639 | /* handle of the OPCODE hash table */ | |
640 | static struct hash_control *op_hash = NULL; | |
641 | ||
642 | /* The opcode hash table we use for the mips16. */ | |
643 | static struct hash_control *mips16_op_hash = NULL; | |
644 | ||
df58fc94 RS |
645 | /* The opcode hash table we use for the microMIPS ASE. */ |
646 | static struct hash_control *micromips_op_hash = NULL; | |
647 | ||
252b5132 RH |
648 | /* This array holds the chars that always start a comment. If the |
649 | pre-processor is disabled, these aren't very useful */ | |
650 | const char comment_chars[] = "#"; | |
651 | ||
652 | /* This array holds the chars that only start a comment at the beginning of | |
653 | a line. If the line seems to have the form '# 123 filename' | |
654 | .line and .file directives will appear in the pre-processed output */ | |
655 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
656 | first line of the input file. This is because the compiler outputs | |
bdaaa2e1 | 657 | #NO_APP at the beginning of its output. */ |
252b5132 RH |
658 | /* Also note that C style comments are always supported. */ |
659 | const char line_comment_chars[] = "#"; | |
660 | ||
bdaaa2e1 | 661 | /* This array holds machine specific line separator characters. */ |
63a0b638 | 662 | const char line_separator_chars[] = ";"; |
252b5132 RH |
663 | |
664 | /* Chars that can be used to separate mant from exp in floating point nums */ | |
665 | const char EXP_CHARS[] = "eE"; | |
666 | ||
667 | /* Chars that mean this number is a floating point constant */ | |
668 | /* As in 0f12.456 */ | |
669 | /* or 0d1.2345e12 */ | |
670 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
671 | ||
672 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
673 | changed in read.c . Ideally it shouldn't have to know about it at all, | |
674 | but nothing is ideal around here. | |
675 | */ | |
676 | ||
677 | static char *insn_error; | |
678 | ||
679 | static int auto_align = 1; | |
680 | ||
681 | /* When outputting SVR4 PIC code, the assembler needs to know the | |
682 | offset in the stack frame from which to restore the $gp register. | |
683 | This is set by the .cprestore pseudo-op, and saved in this | |
684 | variable. */ | |
685 | static offsetT mips_cprestore_offset = -1; | |
686 | ||
67c1ffbe | 687 | /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some |
6478892d | 688 | more optimizations, it can use a register value instead of a memory-saved |
956cd1d6 | 689 | offset and even an other register than $gp as global pointer. */ |
6478892d TS |
690 | static offsetT mips_cpreturn_offset = -1; |
691 | static int mips_cpreturn_register = -1; | |
692 | static int mips_gp_register = GP; | |
def2e0dd | 693 | static int mips_gprel_offset = 0; |
6478892d | 694 | |
7a621144 DJ |
695 | /* Whether mips_cprestore_offset has been set in the current function |
696 | (or whether it has already been warned about, if not). */ | |
697 | static int mips_cprestore_valid = 0; | |
698 | ||
252b5132 RH |
699 | /* This is the register which holds the stack frame, as set by the |
700 | .frame pseudo-op. This is needed to implement .cprestore. */ | |
701 | static int mips_frame_reg = SP; | |
702 | ||
7a621144 DJ |
703 | /* Whether mips_frame_reg has been set in the current function |
704 | (or whether it has already been warned about, if not). */ | |
705 | static int mips_frame_reg_valid = 0; | |
706 | ||
252b5132 RH |
707 | /* To output NOP instructions correctly, we need to keep information |
708 | about the previous two instructions. */ | |
709 | ||
710 | /* Whether we are optimizing. The default value of 2 means to remove | |
711 | unneeded NOPs and swap branch instructions when possible. A value | |
712 | of 1 means to not swap branches. A value of 0 means to always | |
713 | insert NOPs. */ | |
714 | static int mips_optimize = 2; | |
715 | ||
716 | /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is | |
717 | equivalent to seeing no -g option at all. */ | |
718 | static int mips_debug = 0; | |
719 | ||
7d8e00cf RS |
720 | /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */ |
721 | #define MAX_VR4130_NOPS 4 | |
722 | ||
723 | /* The maximum number of NOPs needed to fill delay slots. */ | |
724 | #define MAX_DELAY_NOPS 2 | |
725 | ||
726 | /* The maximum number of NOPs needed for any purpose. */ | |
727 | #define MAX_NOPS 4 | |
71400594 RS |
728 | |
729 | /* A list of previous instructions, with index 0 being the most recent. | |
730 | We need to look back MAX_NOPS instructions when filling delay slots | |
731 | or working around processor errata. We need to look back one | |
732 | instruction further if we're thinking about using history[0] to | |
733 | fill a branch delay slot. */ | |
734 | static struct mips_cl_insn history[1 + MAX_NOPS]; | |
252b5132 | 735 | |
1e915849 | 736 | /* Nop instructions used by emit_nop. */ |
df58fc94 RS |
737 | static struct mips_cl_insn nop_insn; |
738 | static struct mips_cl_insn mips16_nop_insn; | |
739 | static struct mips_cl_insn micromips_nop16_insn; | |
740 | static struct mips_cl_insn micromips_nop32_insn; | |
1e915849 RS |
741 | |
742 | /* The appropriate nop for the current mode. */ | |
df58fc94 RS |
743 | #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn \ |
744 | : (mips_opts.micromips ? µmips_nop16_insn : &nop_insn)) | |
745 | ||
746 | /* The size of NOP_INSN in bytes. */ | |
747 | #define NOP_INSN_SIZE (HAVE_CODE_COMPRESSION ? 2 : 4) | |
252b5132 | 748 | |
252b5132 RH |
749 | /* If this is set, it points to a frag holding nop instructions which |
750 | were inserted before the start of a noreorder section. If those | |
751 | nops turn out to be unnecessary, the size of the frag can be | |
752 | decreased. */ | |
753 | static fragS *prev_nop_frag; | |
754 | ||
755 | /* The number of nop instructions we created in prev_nop_frag. */ | |
756 | static int prev_nop_frag_holds; | |
757 | ||
758 | /* The number of nop instructions that we know we need in | |
bdaaa2e1 | 759 | prev_nop_frag. */ |
252b5132 RH |
760 | static int prev_nop_frag_required; |
761 | ||
762 | /* The number of instructions we've seen since prev_nop_frag. */ | |
763 | static int prev_nop_frag_since; | |
764 | ||
765 | /* For ECOFF and ELF, relocations against symbols are done in two | |
766 | parts, with a HI relocation and a LO relocation. Each relocation | |
767 | has only 16 bits of space to store an addend. This means that in | |
768 | order for the linker to handle carries correctly, it must be able | |
769 | to locate both the HI and the LO relocation. This means that the | |
770 | relocations must appear in order in the relocation table. | |
771 | ||
772 | In order to implement this, we keep track of each unmatched HI | |
773 | relocation. We then sort them so that they immediately precede the | |
bdaaa2e1 | 774 | corresponding LO relocation. */ |
252b5132 | 775 | |
e972090a NC |
776 | struct mips_hi_fixup |
777 | { | |
252b5132 RH |
778 | /* Next HI fixup. */ |
779 | struct mips_hi_fixup *next; | |
780 | /* This fixup. */ | |
781 | fixS *fixp; | |
782 | /* The section this fixup is in. */ | |
783 | segT seg; | |
784 | }; | |
785 | ||
786 | /* The list of unmatched HI relocs. */ | |
787 | ||
788 | static struct mips_hi_fixup *mips_hi_fixup_list; | |
789 | ||
64bdfcaf RS |
790 | /* The frag containing the last explicit relocation operator. |
791 | Null if explicit relocations have not been used. */ | |
792 | ||
793 | static fragS *prev_reloc_op_frag; | |
794 | ||
252b5132 RH |
795 | /* Map normal MIPS register numbers to mips16 register numbers. */ |
796 | ||
797 | #define X ILLEGAL_REG | |
e972090a NC |
798 | static const int mips32_to_16_reg_map[] = |
799 | { | |
252b5132 RH |
800 | X, X, 2, 3, 4, 5, 6, 7, |
801 | X, X, X, X, X, X, X, X, | |
802 | 0, 1, X, X, X, X, X, X, | |
803 | X, X, X, X, X, X, X, X | |
804 | }; | |
805 | #undef X | |
806 | ||
807 | /* Map mips16 register numbers to normal MIPS register numbers. */ | |
808 | ||
e972090a NC |
809 | static const unsigned int mips16_to_32_reg_map[] = |
810 | { | |
252b5132 RH |
811 | 16, 17, 2, 3, 4, 5, 6, 7 |
812 | }; | |
60b63b72 | 813 | |
df58fc94 RS |
814 | /* Map normal MIPS register numbers to microMIPS register numbers. */ |
815 | ||
816 | #define mips32_to_micromips_reg_b_map mips32_to_16_reg_map | |
817 | #define mips32_to_micromips_reg_c_map mips32_to_16_reg_map | |
818 | #define mips32_to_micromips_reg_d_map mips32_to_16_reg_map | |
819 | #define mips32_to_micromips_reg_e_map mips32_to_16_reg_map | |
820 | #define mips32_to_micromips_reg_f_map mips32_to_16_reg_map | |
821 | #define mips32_to_micromips_reg_g_map mips32_to_16_reg_map | |
822 | #define mips32_to_micromips_reg_l_map mips32_to_16_reg_map | |
823 | ||
824 | #define X ILLEGAL_REG | |
825 | /* reg type h: 4, 5, 6. */ | |
826 | static const int mips32_to_micromips_reg_h_map[] = | |
827 | { | |
828 | X, X, X, X, 4, 5, 6, X, | |
829 | X, X, X, X, X, X, X, X, | |
830 | X, X, X, X, X, X, X, X, | |
831 | X, X, X, X, X, X, X, X | |
832 | }; | |
833 | ||
834 | /* reg type m: 0, 17, 2, 3, 16, 18, 19, 20. */ | |
835 | static const int mips32_to_micromips_reg_m_map[] = | |
836 | { | |
837 | 0, X, 2, 3, X, X, X, X, | |
838 | X, X, X, X, X, X, X, X, | |
839 | 4, 1, 5, 6, 7, X, X, X, | |
840 | X, X, X, X, X, X, X, X | |
841 | }; | |
842 | ||
843 | /* reg type q: 0, 2-7. 17. */ | |
844 | static const int mips32_to_micromips_reg_q_map[] = | |
845 | { | |
846 | 0, X, 2, 3, 4, 5, 6, 7, | |
847 | X, X, X, X, X, X, X, X, | |
848 | X, 1, X, X, X, X, X, X, | |
849 | X, X, X, X, X, X, X, X | |
850 | }; | |
851 | ||
852 | #define mips32_to_micromips_reg_n_map mips32_to_micromips_reg_m_map | |
853 | #undef X | |
854 | ||
855 | /* Map microMIPS register numbers to normal MIPS register numbers. */ | |
856 | ||
857 | #define micromips_to_32_reg_b_map mips16_to_32_reg_map | |
858 | #define micromips_to_32_reg_c_map mips16_to_32_reg_map | |
859 | #define micromips_to_32_reg_d_map mips16_to_32_reg_map | |
860 | #define micromips_to_32_reg_e_map mips16_to_32_reg_map | |
861 | #define micromips_to_32_reg_f_map mips16_to_32_reg_map | |
862 | #define micromips_to_32_reg_g_map mips16_to_32_reg_map | |
863 | ||
864 | /* The microMIPS registers with type h. */ | |
865 | static const unsigned int micromips_to_32_reg_h_map[] = | |
866 | { | |
867 | 5, 5, 6, 4, 4, 4, 4, 4 | |
868 | }; | |
869 | ||
870 | /* The microMIPS registers with type i. */ | |
871 | static const unsigned int micromips_to_32_reg_i_map[] = | |
872 | { | |
873 | 6, 7, 7, 21, 22, 5, 6, 7 | |
874 | }; | |
875 | ||
876 | #define micromips_to_32_reg_l_map mips16_to_32_reg_map | |
877 | ||
878 | /* The microMIPS registers with type m. */ | |
879 | static const unsigned int micromips_to_32_reg_m_map[] = | |
880 | { | |
881 | 0, 17, 2, 3, 16, 18, 19, 20 | |
882 | }; | |
883 | ||
884 | #define micromips_to_32_reg_n_map micromips_to_32_reg_m_map | |
885 | ||
886 | /* The microMIPS registers with type q. */ | |
887 | static const unsigned int micromips_to_32_reg_q_map[] = | |
888 | { | |
889 | 0, 17, 2, 3, 4, 5, 6, 7 | |
890 | }; | |
891 | ||
892 | /* microMIPS imm type B. */ | |
893 | static const int micromips_imm_b_map[] = | |
894 | { | |
895 | 1, 4, 8, 12, 16, 20, 24, -1 | |
896 | }; | |
897 | ||
898 | /* microMIPS imm type C. */ | |
899 | static const int micromips_imm_c_map[] = | |
900 | { | |
901 | 128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 255, 32768, 65535 | |
902 | }; | |
903 | ||
71400594 RS |
904 | /* Classifies the kind of instructions we're interested in when |
905 | implementing -mfix-vr4120. */ | |
c67a084a NC |
906 | enum fix_vr4120_class |
907 | { | |
71400594 RS |
908 | FIX_VR4120_MACC, |
909 | FIX_VR4120_DMACC, | |
910 | FIX_VR4120_MULT, | |
911 | FIX_VR4120_DMULT, | |
912 | FIX_VR4120_DIV, | |
913 | FIX_VR4120_MTHILO, | |
914 | NUM_FIX_VR4120_CLASSES | |
915 | }; | |
916 | ||
c67a084a NC |
917 | /* ...likewise -mfix-loongson2f-jump. */ |
918 | static bfd_boolean mips_fix_loongson2f_jump; | |
919 | ||
920 | /* ...likewise -mfix-loongson2f-nop. */ | |
921 | static bfd_boolean mips_fix_loongson2f_nop; | |
922 | ||
923 | /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed. */ | |
924 | static bfd_boolean mips_fix_loongson2f; | |
925 | ||
71400594 RS |
926 | /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if |
927 | there must be at least one other instruction between an instruction | |
928 | of type X and an instruction of type Y. */ | |
929 | static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES]; | |
930 | ||
931 | /* True if -mfix-vr4120 is in force. */ | |
d766e8ec | 932 | static int mips_fix_vr4120; |
4a6a3df4 | 933 | |
7d8e00cf RS |
934 | /* ...likewise -mfix-vr4130. */ |
935 | static int mips_fix_vr4130; | |
936 | ||
6a32d874 CM |
937 | /* ...likewise -mfix-24k. */ |
938 | static int mips_fix_24k; | |
939 | ||
d954098f DD |
940 | /* ...likewise -mfix-cn63xxp1 */ |
941 | static bfd_boolean mips_fix_cn63xxp1; | |
942 | ||
4a6a3df4 AO |
943 | /* We don't relax branches by default, since this causes us to expand |
944 | `la .l2 - .l1' if there's a branch between .l1 and .l2, because we | |
945 | fail to compute the offset before expanding the macro to the most | |
946 | efficient expansion. */ | |
947 | ||
948 | static int mips_relax_branch; | |
252b5132 | 949 | \f |
4d7206a2 RS |
950 | /* The expansion of many macros depends on the type of symbol that |
951 | they refer to. For example, when generating position-dependent code, | |
952 | a macro that refers to a symbol may have two different expansions, | |
953 | one which uses GP-relative addresses and one which uses absolute | |
954 | addresses. When generating SVR4-style PIC, a macro may have | |
955 | different expansions for local and global symbols. | |
956 | ||
957 | We handle these situations by generating both sequences and putting | |
958 | them in variant frags. In position-dependent code, the first sequence | |
959 | will be the GP-relative one and the second sequence will be the | |
960 | absolute one. In SVR4 PIC, the first sequence will be for global | |
961 | symbols and the second will be for local symbols. | |
962 | ||
584892a6 RS |
963 | The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and |
964 | SECOND are the lengths of the two sequences in bytes. These fields | |
965 | can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition, | |
966 | the subtype has the following flags: | |
4d7206a2 | 967 | |
584892a6 RS |
968 | RELAX_USE_SECOND |
969 | Set if it has been decided that we should use the second | |
970 | sequence instead of the first. | |
971 | ||
972 | RELAX_SECOND_LONGER | |
973 | Set in the first variant frag if the macro's second implementation | |
974 | is longer than its first. This refers to the macro as a whole, | |
975 | not an individual relaxation. | |
976 | ||
977 | RELAX_NOMACRO | |
978 | Set in the first variant frag if the macro appeared in a .set nomacro | |
979 | block and if one alternative requires a warning but the other does not. | |
980 | ||
981 | RELAX_DELAY_SLOT | |
982 | Like RELAX_NOMACRO, but indicates that the macro appears in a branch | |
983 | delay slot. | |
4d7206a2 | 984 | |
df58fc94 RS |
985 | RELAX_DELAY_SLOT_16BIT |
986 | Like RELAX_DELAY_SLOT, but indicates that the delay slot requires a | |
987 | 16-bit instruction. | |
988 | ||
989 | RELAX_DELAY_SLOT_SIZE_FIRST | |
990 | Like RELAX_DELAY_SLOT, but indicates that the first implementation of | |
991 | the macro is of the wrong size for the branch delay slot. | |
992 | ||
993 | RELAX_DELAY_SLOT_SIZE_SECOND | |
994 | Like RELAX_DELAY_SLOT, but indicates that the second implementation of | |
995 | the macro is of the wrong size for the branch delay slot. | |
996 | ||
4d7206a2 RS |
997 | The frag's "opcode" points to the first fixup for relaxable code. |
998 | ||
999 | Relaxable macros are generated using a sequence such as: | |
1000 | ||
1001 | relax_start (SYMBOL); | |
1002 | ... generate first expansion ... | |
1003 | relax_switch (); | |
1004 | ... generate second expansion ... | |
1005 | relax_end (); | |
1006 | ||
1007 | The code and fixups for the unwanted alternative are discarded | |
1008 | by md_convert_frag. */ | |
584892a6 | 1009 | #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND)) |
4d7206a2 | 1010 | |
584892a6 RS |
1011 | #define RELAX_FIRST(X) (((X) >> 8) & 0xff) |
1012 | #define RELAX_SECOND(X) ((X) & 0xff) | |
1013 | #define RELAX_USE_SECOND 0x10000 | |
1014 | #define RELAX_SECOND_LONGER 0x20000 | |
1015 | #define RELAX_NOMACRO 0x40000 | |
1016 | #define RELAX_DELAY_SLOT 0x80000 | |
df58fc94 RS |
1017 | #define RELAX_DELAY_SLOT_16BIT 0x100000 |
1018 | #define RELAX_DELAY_SLOT_SIZE_FIRST 0x200000 | |
1019 | #define RELAX_DELAY_SLOT_SIZE_SECOND 0x400000 | |
252b5132 | 1020 | |
4a6a3df4 AO |
1021 | /* Branch without likely bit. If label is out of range, we turn: |
1022 | ||
1023 | beq reg1, reg2, label | |
1024 | delay slot | |
1025 | ||
1026 | into | |
1027 | ||
1028 | bne reg1, reg2, 0f | |
1029 | nop | |
1030 | j label | |
1031 | 0: delay slot | |
1032 | ||
1033 | with the following opcode replacements: | |
1034 | ||
1035 | beq <-> bne | |
1036 | blez <-> bgtz | |
1037 | bltz <-> bgez | |
1038 | bc1f <-> bc1t | |
1039 | ||
1040 | bltzal <-> bgezal (with jal label instead of j label) | |
1041 | ||
1042 | Even though keeping the delay slot instruction in the delay slot of | |
1043 | the branch would be more efficient, it would be very tricky to do | |
1044 | correctly, because we'd have to introduce a variable frag *after* | |
1045 | the delay slot instruction, and expand that instead. Let's do it | |
1046 | the easy way for now, even if the branch-not-taken case now costs | |
1047 | one additional instruction. Out-of-range branches are not supposed | |
1048 | to be common, anyway. | |
1049 | ||
1050 | Branch likely. If label is out of range, we turn: | |
1051 | ||
1052 | beql reg1, reg2, label | |
1053 | delay slot (annulled if branch not taken) | |
1054 | ||
1055 | into | |
1056 | ||
1057 | beql reg1, reg2, 1f | |
1058 | nop | |
1059 | beql $0, $0, 2f | |
1060 | nop | |
1061 | 1: j[al] label | |
1062 | delay slot (executed only if branch taken) | |
1063 | 2: | |
1064 | ||
1065 | It would be possible to generate a shorter sequence by losing the | |
1066 | likely bit, generating something like: | |
b34976b6 | 1067 | |
4a6a3df4 AO |
1068 | bne reg1, reg2, 0f |
1069 | nop | |
1070 | j[al] label | |
1071 | delay slot (executed only if branch taken) | |
1072 | 0: | |
1073 | ||
1074 | beql -> bne | |
1075 | bnel -> beq | |
1076 | blezl -> bgtz | |
1077 | bgtzl -> blez | |
1078 | bltzl -> bgez | |
1079 | bgezl -> bltz | |
1080 | bc1fl -> bc1t | |
1081 | bc1tl -> bc1f | |
1082 | ||
1083 | bltzall -> bgezal (with jal label instead of j label) | |
1084 | bgezall -> bltzal (ditto) | |
1085 | ||
1086 | ||
1087 | but it's not clear that it would actually improve performance. */ | |
66b3e8da MR |
1088 | #define RELAX_BRANCH_ENCODE(at, uncond, likely, link, toofar) \ |
1089 | ((relax_substateT) \ | |
1090 | (0xc0000000 \ | |
1091 | | ((at) & 0x1f) \ | |
1092 | | ((toofar) ? 0x20 : 0) \ | |
1093 | | ((link) ? 0x40 : 0) \ | |
1094 | | ((likely) ? 0x80 : 0) \ | |
1095 | | ((uncond) ? 0x100 : 0))) | |
4a6a3df4 | 1096 | #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000) |
66b3e8da MR |
1097 | #define RELAX_BRANCH_UNCOND(i) (((i) & 0x100) != 0) |
1098 | #define RELAX_BRANCH_LIKELY(i) (((i) & 0x80) != 0) | |
1099 | #define RELAX_BRANCH_LINK(i) (((i) & 0x40) != 0) | |
1100 | #define RELAX_BRANCH_TOOFAR(i) (((i) & 0x20) != 0) | |
1101 | #define RELAX_BRANCH_AT(i) ((i) & 0x1f) | |
4a6a3df4 | 1102 | |
252b5132 RH |
1103 | /* For mips16 code, we use an entirely different form of relaxation. |
1104 | mips16 supports two versions of most instructions which take | |
1105 | immediate values: a small one which takes some small value, and a | |
1106 | larger one which takes a 16 bit value. Since branches also follow | |
1107 | this pattern, relaxing these values is required. | |
1108 | ||
1109 | We can assemble both mips16 and normal MIPS code in a single | |
1110 | object. Therefore, we need to support this type of relaxation at | |
1111 | the same time that we support the relaxation described above. We | |
1112 | use the high bit of the subtype field to distinguish these cases. | |
1113 | ||
1114 | The information we store for this type of relaxation is the | |
1115 | argument code found in the opcode file for this relocation, whether | |
1116 | the user explicitly requested a small or extended form, and whether | |
1117 | the relocation is in a jump or jal delay slot. That tells us the | |
1118 | size of the value, and how it should be stored. We also store | |
1119 | whether the fragment is considered to be extended or not. We also | |
1120 | store whether this is known to be a branch to a different section, | |
1121 | whether we have tried to relax this frag yet, and whether we have | |
1122 | ever extended a PC relative fragment because of a shift count. */ | |
1123 | #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \ | |
1124 | (0x80000000 \ | |
1125 | | ((type) & 0xff) \ | |
1126 | | ((small) ? 0x100 : 0) \ | |
1127 | | ((ext) ? 0x200 : 0) \ | |
1128 | | ((dslot) ? 0x400 : 0) \ | |
1129 | | ((jal_dslot) ? 0x800 : 0)) | |
4a6a3df4 | 1130 | #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000) |
252b5132 RH |
1131 | #define RELAX_MIPS16_TYPE(i) ((i) & 0xff) |
1132 | #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0) | |
1133 | #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0) | |
1134 | #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0) | |
1135 | #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0) | |
1136 | #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0) | |
1137 | #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000) | |
1138 | #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000) | |
1139 | #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0) | |
1140 | #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000) | |
1141 | #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000) | |
885add95 | 1142 | |
df58fc94 RS |
1143 | /* For microMIPS code, we use relaxation similar to one we use for |
1144 | MIPS16 code. Some instructions that take immediate values support | |
1145 | two encodings: a small one which takes some small value, and a | |
1146 | larger one which takes a 16 bit value. As some branches also follow | |
1147 | this pattern, relaxing these values is required. | |
1148 | ||
1149 | We can assemble both microMIPS and normal MIPS code in a single | |
1150 | object. Therefore, we need to support this type of relaxation at | |
1151 | the same time that we support the relaxation described above. We | |
1152 | use one of the high bits of the subtype field to distinguish these | |
1153 | cases. | |
1154 | ||
1155 | The information we store for this type of relaxation is the argument | |
1156 | code found in the opcode file for this relocation, the register | |
40209cad MR |
1157 | selected as the assembler temporary, whether the branch is |
1158 | unconditional, whether it is compact, whether it stores the link | |
1159 | address implicitly in $ra, whether relaxation of out-of-range 32-bit | |
1160 | branches to a sequence of instructions is enabled, and whether the | |
1161 | displacement of a branch is too large to fit as an immediate argument | |
1162 | of a 16-bit and a 32-bit branch, respectively. */ | |
1163 | #define RELAX_MICROMIPS_ENCODE(type, at, uncond, compact, link, \ | |
1164 | relax32, toofar16, toofar32) \ | |
1165 | (0x40000000 \ | |
1166 | | ((type) & 0xff) \ | |
1167 | | (((at) & 0x1f) << 8) \ | |
1168 | | ((uncond) ? 0x2000 : 0) \ | |
1169 | | ((compact) ? 0x4000 : 0) \ | |
1170 | | ((link) ? 0x8000 : 0) \ | |
1171 | | ((relax32) ? 0x10000 : 0) \ | |
1172 | | ((toofar16) ? 0x20000 : 0) \ | |
1173 | | ((toofar32) ? 0x40000 : 0)) | |
df58fc94 RS |
1174 | #define RELAX_MICROMIPS_P(i) (((i) & 0xc0000000) == 0x40000000) |
1175 | #define RELAX_MICROMIPS_TYPE(i) ((i) & 0xff) | |
1176 | #define RELAX_MICROMIPS_AT(i) (((i) >> 8) & 0x1f) | |
40209cad MR |
1177 | #define RELAX_MICROMIPS_UNCOND(i) (((i) & 0x2000) != 0) |
1178 | #define RELAX_MICROMIPS_COMPACT(i) (((i) & 0x4000) != 0) | |
1179 | #define RELAX_MICROMIPS_LINK(i) (((i) & 0x8000) != 0) | |
1180 | #define RELAX_MICROMIPS_RELAX32(i) (((i) & 0x10000) != 0) | |
1181 | ||
1182 | #define RELAX_MICROMIPS_TOOFAR16(i) (((i) & 0x20000) != 0) | |
1183 | #define RELAX_MICROMIPS_MARK_TOOFAR16(i) ((i) | 0x20000) | |
1184 | #define RELAX_MICROMIPS_CLEAR_TOOFAR16(i) ((i) & ~0x20000) | |
1185 | #define RELAX_MICROMIPS_TOOFAR32(i) (((i) & 0x40000) != 0) | |
1186 | #define RELAX_MICROMIPS_MARK_TOOFAR32(i) ((i) | 0x40000) | |
1187 | #define RELAX_MICROMIPS_CLEAR_TOOFAR32(i) ((i) & ~0x40000) | |
df58fc94 | 1188 | |
43c0598f RS |
1189 | /* Sign-extend 16-bit value X. */ |
1190 | #define SEXT_16BIT(X) ((((X) + 0x8000) & 0xffff) - 0x8000) | |
1191 | ||
885add95 CD |
1192 | /* Is the given value a sign-extended 32-bit value? */ |
1193 | #define IS_SEXT_32BIT_NUM(x) \ | |
1194 | (((x) &~ (offsetT) 0x7fffffff) == 0 \ | |
1195 | || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff)) | |
1196 | ||
1197 | /* Is the given value a sign-extended 16-bit value? */ | |
1198 | #define IS_SEXT_16BIT_NUM(x) \ | |
1199 | (((x) &~ (offsetT) 0x7fff) == 0 \ | |
1200 | || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff)) | |
1201 | ||
df58fc94 RS |
1202 | /* Is the given value a sign-extended 12-bit value? */ |
1203 | #define IS_SEXT_12BIT_NUM(x) \ | |
1204 | (((((x) & 0xfff) ^ 0x800LL) - 0x800LL) == (x)) | |
1205 | ||
2051e8c4 MR |
1206 | /* Is the given value a zero-extended 32-bit value? Or a negated one? */ |
1207 | #define IS_ZEXT_32BIT_NUM(x) \ | |
1208 | (((x) &~ (offsetT) 0xffffffff) == 0 \ | |
1209 | || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff)) | |
1210 | ||
bf12938e RS |
1211 | /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in |
1212 | VALUE << SHIFT. VALUE is evaluated exactly once. */ | |
1213 | #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \ | |
1214 | (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \ | |
1215 | | (((VALUE) & (MASK)) << (SHIFT))) | |
1216 | ||
1217 | /* Extract bits MASK << SHIFT from STRUCT and shift them right | |
1218 | SHIFT places. */ | |
1219 | #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \ | |
1220 | (((STRUCT) >> (SHIFT)) & (MASK)) | |
1221 | ||
1222 | /* Change INSN's opcode so that the operand given by FIELD has value VALUE. | |
1223 | INSN is a mips_cl_insn structure and VALUE is evaluated exactly once. | |
1224 | ||
1225 | include/opcode/mips.h specifies operand fields using the macros | |
1226 | OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start | |
1227 | with "MIPS16OP" instead of "OP". */ | |
df58fc94 RS |
1228 | #define INSERT_OPERAND(MICROMIPS, FIELD, INSN, VALUE) \ |
1229 | do \ | |
1230 | if (!(MICROMIPS)) \ | |
1231 | INSERT_BITS ((INSN).insn_opcode, VALUE, \ | |
1232 | OP_MASK_##FIELD, OP_SH_##FIELD); \ | |
1233 | else \ | |
1234 | INSERT_BITS ((INSN).insn_opcode, VALUE, \ | |
1235 | MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD); \ | |
1236 | while (0) | |
bf12938e RS |
1237 | #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \ |
1238 | INSERT_BITS ((INSN).insn_opcode, VALUE, \ | |
1239 | MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD) | |
1240 | ||
1241 | /* Extract the operand given by FIELD from mips_cl_insn INSN. */ | |
df58fc94 RS |
1242 | #define EXTRACT_OPERAND(MICROMIPS, FIELD, INSN) \ |
1243 | (!(MICROMIPS) \ | |
1244 | ? EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD) \ | |
1245 | : EXTRACT_BITS ((INSN).insn_opcode, \ | |
1246 | MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD)) | |
bf12938e RS |
1247 | #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \ |
1248 | EXTRACT_BITS ((INSN).insn_opcode, \ | |
1249 | MIPS16OP_MASK_##FIELD, \ | |
1250 | MIPS16OP_SH_##FIELD) | |
5c04167a RS |
1251 | |
1252 | /* The MIPS16 EXTEND opcode, shifted left 16 places. */ | |
1253 | #define MIPS16_EXTEND (0xf000U << 16) | |
4d7206a2 | 1254 | \f |
df58fc94 RS |
1255 | /* Whether or not we are emitting a branch-likely macro. */ |
1256 | static bfd_boolean emit_branch_likely_macro = FALSE; | |
1257 | ||
4d7206a2 RS |
1258 | /* Global variables used when generating relaxable macros. See the |
1259 | comment above RELAX_ENCODE for more details about how relaxation | |
1260 | is used. */ | |
1261 | static struct { | |
1262 | /* 0 if we're not emitting a relaxable macro. | |
1263 | 1 if we're emitting the first of the two relaxation alternatives. | |
1264 | 2 if we're emitting the second alternative. */ | |
1265 | int sequence; | |
1266 | ||
1267 | /* The first relaxable fixup in the current frag. (In other words, | |
1268 | the first fixup that refers to relaxable code.) */ | |
1269 | fixS *first_fixup; | |
1270 | ||
1271 | /* sizes[0] says how many bytes of the first alternative are stored in | |
1272 | the current frag. Likewise sizes[1] for the second alternative. */ | |
1273 | unsigned int sizes[2]; | |
1274 | ||
1275 | /* The symbol on which the choice of sequence depends. */ | |
1276 | symbolS *symbol; | |
1277 | } mips_relax; | |
252b5132 | 1278 | \f |
584892a6 RS |
1279 | /* Global variables used to decide whether a macro needs a warning. */ |
1280 | static struct { | |
1281 | /* True if the macro is in a branch delay slot. */ | |
1282 | bfd_boolean delay_slot_p; | |
1283 | ||
df58fc94 RS |
1284 | /* Set to the length in bytes required if the macro is in a delay slot |
1285 | that requires a specific length of instruction, otherwise zero. */ | |
1286 | unsigned int delay_slot_length; | |
1287 | ||
584892a6 RS |
1288 | /* For relaxable macros, sizes[0] is the length of the first alternative |
1289 | in bytes and sizes[1] is the length of the second alternative. | |
1290 | For non-relaxable macros, both elements give the length of the | |
1291 | macro in bytes. */ | |
1292 | unsigned int sizes[2]; | |
1293 | ||
df58fc94 RS |
1294 | /* For relaxable macros, first_insn_sizes[0] is the length of the first |
1295 | instruction of the first alternative in bytes and first_insn_sizes[1] | |
1296 | is the length of the first instruction of the second alternative. | |
1297 | For non-relaxable macros, both elements give the length of the first | |
1298 | instruction in bytes. | |
1299 | ||
1300 | Set to zero if we haven't yet seen the first instruction. */ | |
1301 | unsigned int first_insn_sizes[2]; | |
1302 | ||
1303 | /* For relaxable macros, insns[0] is the number of instructions for the | |
1304 | first alternative and insns[1] is the number of instructions for the | |
1305 | second alternative. | |
1306 | ||
1307 | For non-relaxable macros, both elements give the number of | |
1308 | instructions for the macro. */ | |
1309 | unsigned int insns[2]; | |
1310 | ||
584892a6 RS |
1311 | /* The first variant frag for this macro. */ |
1312 | fragS *first_frag; | |
1313 | } mips_macro_warning; | |
1314 | \f | |
252b5132 RH |
1315 | /* Prototypes for static functions. */ |
1316 | ||
252b5132 RH |
1317 | enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG }; |
1318 | ||
b34976b6 | 1319 | static void append_insn |
df58fc94 RS |
1320 | (struct mips_cl_insn *, expressionS *, bfd_reloc_code_real_type *, |
1321 | bfd_boolean expansionp); | |
7d10b47d | 1322 | static void mips_no_prev_insn (void); |
c67a084a | 1323 | static void macro_build (expressionS *, const char *, const char *, ...); |
b34976b6 | 1324 | static void mips16_macro_build |
03ea81db | 1325 | (expressionS *, const char *, const char *, va_list *); |
67c0d1eb | 1326 | static void load_register (int, expressionS *, int); |
584892a6 RS |
1327 | static void macro_start (void); |
1328 | static void macro_end (void); | |
17a2f251 TS |
1329 | static void macro (struct mips_cl_insn * ip); |
1330 | static void mips16_macro (struct mips_cl_insn * ip); | |
17a2f251 TS |
1331 | static void mips_ip (char *str, struct mips_cl_insn * ip); |
1332 | static void mips16_ip (char *str, struct mips_cl_insn * ip); | |
b34976b6 | 1333 | static void mips16_immed |
43c0598f RS |
1334 | (char *, unsigned int, int, bfd_reloc_code_real_type, offsetT, |
1335 | unsigned int, unsigned long *); | |
5e0116d5 | 1336 | static size_t my_getSmallExpression |
17a2f251 TS |
1337 | (expressionS *, bfd_reloc_code_real_type *, char *); |
1338 | static void my_getExpression (expressionS *, char *); | |
1339 | static void s_align (int); | |
1340 | static void s_change_sec (int); | |
1341 | static void s_change_section (int); | |
1342 | static void s_cons (int); | |
1343 | static void s_float_cons (int); | |
1344 | static void s_mips_globl (int); | |
1345 | static void s_option (int); | |
1346 | static void s_mipsset (int); | |
1347 | static void s_abicalls (int); | |
1348 | static void s_cpload (int); | |
1349 | static void s_cpsetup (int); | |
1350 | static void s_cplocal (int); | |
1351 | static void s_cprestore (int); | |
1352 | static void s_cpreturn (int); | |
741d6ea8 JM |
1353 | static void s_dtprelword (int); |
1354 | static void s_dtpreldword (int); | |
d0f13682 CLT |
1355 | static void s_tprelword (int); |
1356 | static void s_tpreldword (int); | |
17a2f251 TS |
1357 | static void s_gpvalue (int); |
1358 | static void s_gpword (int); | |
1359 | static void s_gpdword (int); | |
1360 | static void s_cpadd (int); | |
1361 | static void s_insn (int); | |
1362 | static void md_obj_begin (void); | |
1363 | static void md_obj_end (void); | |
1364 | static void s_mips_ent (int); | |
1365 | static void s_mips_end (int); | |
1366 | static void s_mips_frame (int); | |
1367 | static void s_mips_mask (int reg_type); | |
1368 | static void s_mips_stab (int); | |
1369 | static void s_mips_weakext (int); | |
1370 | static void s_mips_file (int); | |
1371 | static void s_mips_loc (int); | |
1372 | static bfd_boolean pic_need_relax (symbolS *, asection *); | |
4a6a3df4 | 1373 | static int relaxed_branch_length (fragS *, asection *, int); |
17a2f251 | 1374 | static int validate_mips_insn (const struct mips_opcode *); |
df58fc94 RS |
1375 | static int validate_micromips_insn (const struct mips_opcode *); |
1376 | static int relaxed_micromips_16bit_branch_length (fragS *, asection *, int); | |
1377 | static int relaxed_micromips_32bit_branch_length (fragS *, asection *, int); | |
e7af610e NC |
1378 | |
1379 | /* Table and functions used to map between CPU/ISA names, and | |
1380 | ISA levels, and CPU numbers. */ | |
1381 | ||
e972090a NC |
1382 | struct mips_cpu_info |
1383 | { | |
e7af610e | 1384 | const char *name; /* CPU or ISA name. */ |
ad3fea08 | 1385 | int flags; /* ASEs available, or ISA flag. */ |
e7af610e NC |
1386 | int isa; /* ISA level. */ |
1387 | int cpu; /* CPU number (default CPU if ISA). */ | |
1388 | }; | |
1389 | ||
ad3fea08 TS |
1390 | #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */ |
1391 | #define MIPS_CPU_ASE_SMARTMIPS 0x0002 /* CPU implements SmartMIPS ASE */ | |
1392 | #define MIPS_CPU_ASE_DSP 0x0004 /* CPU implements DSP ASE */ | |
1393 | #define MIPS_CPU_ASE_MT 0x0008 /* CPU implements MT ASE */ | |
1394 | #define MIPS_CPU_ASE_MIPS3D 0x0010 /* CPU implements MIPS-3D ASE */ | |
1395 | #define MIPS_CPU_ASE_MDMX 0x0020 /* CPU implements MDMX ASE */ | |
8b082fb1 | 1396 | #define MIPS_CPU_ASE_DSPR2 0x0040 /* CPU implements DSP R2 ASE */ |
dec0624d | 1397 | #define MIPS_CPU_ASE_MCU 0x0080 /* CPU implements MCU ASE */ |
ad3fea08 | 1398 | |
17a2f251 TS |
1399 | static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *); |
1400 | static const struct mips_cpu_info *mips_cpu_info_from_isa (int); | |
1401 | static const struct mips_cpu_info *mips_cpu_info_from_arch (int); | |
252b5132 RH |
1402 | \f |
1403 | /* Pseudo-op table. | |
1404 | ||
1405 | The following pseudo-ops from the Kane and Heinrich MIPS book | |
1406 | should be defined here, but are currently unsupported: .alias, | |
1407 | .galive, .gjaldef, .gjrlive, .livereg, .noalias. | |
1408 | ||
1409 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
1410 | specific to the type of debugging information being generated, and | |
1411 | should be defined by the object format: .aent, .begin, .bend, | |
1412 | .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp, | |
1413 | .vreg. | |
1414 | ||
1415 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
1416 | not MIPS CPU specific, but are also not specific to the object file | |
1417 | format. This file is probably the best place to define them, but | |
d84bcf09 | 1418 | they are not currently supported: .asm0, .endr, .lab, .struct. */ |
252b5132 | 1419 | |
e972090a NC |
1420 | static const pseudo_typeS mips_pseudo_table[] = |
1421 | { | |
beae10d5 | 1422 | /* MIPS specific pseudo-ops. */ |
252b5132 RH |
1423 | {"option", s_option, 0}, |
1424 | {"set", s_mipsset, 0}, | |
1425 | {"rdata", s_change_sec, 'r'}, | |
1426 | {"sdata", s_change_sec, 's'}, | |
1427 | {"livereg", s_ignore, 0}, | |
1428 | {"abicalls", s_abicalls, 0}, | |
1429 | {"cpload", s_cpload, 0}, | |
6478892d TS |
1430 | {"cpsetup", s_cpsetup, 0}, |
1431 | {"cplocal", s_cplocal, 0}, | |
252b5132 | 1432 | {"cprestore", s_cprestore, 0}, |
6478892d | 1433 | {"cpreturn", s_cpreturn, 0}, |
741d6ea8 JM |
1434 | {"dtprelword", s_dtprelword, 0}, |
1435 | {"dtpreldword", s_dtpreldword, 0}, | |
d0f13682 CLT |
1436 | {"tprelword", s_tprelword, 0}, |
1437 | {"tpreldword", s_tpreldword, 0}, | |
6478892d | 1438 | {"gpvalue", s_gpvalue, 0}, |
252b5132 | 1439 | {"gpword", s_gpword, 0}, |
10181a0d | 1440 | {"gpdword", s_gpdword, 0}, |
252b5132 RH |
1441 | {"cpadd", s_cpadd, 0}, |
1442 | {"insn", s_insn, 0}, | |
1443 | ||
beae10d5 | 1444 | /* Relatively generic pseudo-ops that happen to be used on MIPS |
252b5132 | 1445 | chips. */ |
38a57ae7 | 1446 | {"asciiz", stringer, 8 + 1}, |
252b5132 RH |
1447 | {"bss", s_change_sec, 'b'}, |
1448 | {"err", s_err, 0}, | |
1449 | {"half", s_cons, 1}, | |
1450 | {"dword", s_cons, 3}, | |
1451 | {"weakext", s_mips_weakext, 0}, | |
7c752c2a TS |
1452 | {"origin", s_org, 0}, |
1453 | {"repeat", s_rept, 0}, | |
252b5132 | 1454 | |
998b3c36 MR |
1455 | /* For MIPS this is non-standard, but we define it for consistency. */ |
1456 | {"sbss", s_change_sec, 'B'}, | |
1457 | ||
beae10d5 | 1458 | /* These pseudo-ops are defined in read.c, but must be overridden |
252b5132 RH |
1459 | here for one reason or another. */ |
1460 | {"align", s_align, 0}, | |
1461 | {"byte", s_cons, 0}, | |
1462 | {"data", s_change_sec, 'd'}, | |
1463 | {"double", s_float_cons, 'd'}, | |
1464 | {"float", s_float_cons, 'f'}, | |
1465 | {"globl", s_mips_globl, 0}, | |
1466 | {"global", s_mips_globl, 0}, | |
1467 | {"hword", s_cons, 1}, | |
1468 | {"int", s_cons, 2}, | |
1469 | {"long", s_cons, 2}, | |
1470 | {"octa", s_cons, 4}, | |
1471 | {"quad", s_cons, 3}, | |
cca86cc8 | 1472 | {"section", s_change_section, 0}, |
252b5132 RH |
1473 | {"short", s_cons, 1}, |
1474 | {"single", s_float_cons, 'f'}, | |
754e2bb9 | 1475 | {"stabd", s_mips_stab, 'd'}, |
252b5132 | 1476 | {"stabn", s_mips_stab, 'n'}, |
754e2bb9 | 1477 | {"stabs", s_mips_stab, 's'}, |
252b5132 RH |
1478 | {"text", s_change_sec, 't'}, |
1479 | {"word", s_cons, 2}, | |
add56521 | 1480 | |
add56521 | 1481 | { "extern", ecoff_directive_extern, 0}, |
add56521 | 1482 | |
43841e91 | 1483 | { NULL, NULL, 0 }, |
252b5132 RH |
1484 | }; |
1485 | ||
e972090a NC |
1486 | static const pseudo_typeS mips_nonecoff_pseudo_table[] = |
1487 | { | |
beae10d5 KH |
1488 | /* These pseudo-ops should be defined by the object file format. |
1489 | However, a.out doesn't support them, so we have versions here. */ | |
252b5132 RH |
1490 | {"aent", s_mips_ent, 1}, |
1491 | {"bgnb", s_ignore, 0}, | |
1492 | {"end", s_mips_end, 0}, | |
1493 | {"endb", s_ignore, 0}, | |
1494 | {"ent", s_mips_ent, 0}, | |
c5dd6aab | 1495 | {"file", s_mips_file, 0}, |
252b5132 RH |
1496 | {"fmask", s_mips_mask, 'F'}, |
1497 | {"frame", s_mips_frame, 0}, | |
c5dd6aab | 1498 | {"loc", s_mips_loc, 0}, |
252b5132 RH |
1499 | {"mask", s_mips_mask, 'R'}, |
1500 | {"verstamp", s_ignore, 0}, | |
43841e91 | 1501 | { NULL, NULL, 0 }, |
252b5132 RH |
1502 | }; |
1503 | ||
3ae8dd8d MR |
1504 | /* Export the ABI address size for use by TC_ADDRESS_BYTES for the |
1505 | purpose of the `.dc.a' internal pseudo-op. */ | |
1506 | ||
1507 | int | |
1508 | mips_address_bytes (void) | |
1509 | { | |
1510 | return HAVE_64BIT_ADDRESSES ? 8 : 4; | |
1511 | } | |
1512 | ||
17a2f251 | 1513 | extern void pop_insert (const pseudo_typeS *); |
252b5132 RH |
1514 | |
1515 | void | |
17a2f251 | 1516 | mips_pop_insert (void) |
252b5132 RH |
1517 | { |
1518 | pop_insert (mips_pseudo_table); | |
1519 | if (! ECOFF_DEBUGGING) | |
1520 | pop_insert (mips_nonecoff_pseudo_table); | |
1521 | } | |
1522 | \f | |
1523 | /* Symbols labelling the current insn. */ | |
1524 | ||
e972090a NC |
1525 | struct insn_label_list |
1526 | { | |
252b5132 RH |
1527 | struct insn_label_list *next; |
1528 | symbolS *label; | |
1529 | }; | |
1530 | ||
252b5132 | 1531 | static struct insn_label_list *free_insn_labels; |
742a56fe | 1532 | #define label_list tc_segment_info_data.labels |
252b5132 | 1533 | |
17a2f251 | 1534 | static void mips_clear_insn_labels (void); |
df58fc94 RS |
1535 | static void mips_mark_labels (void); |
1536 | static void mips_compressed_mark_labels (void); | |
252b5132 RH |
1537 | |
1538 | static inline void | |
17a2f251 | 1539 | mips_clear_insn_labels (void) |
252b5132 RH |
1540 | { |
1541 | register struct insn_label_list **pl; | |
a8dbcb85 | 1542 | segment_info_type *si; |
252b5132 | 1543 | |
a8dbcb85 TS |
1544 | if (now_seg) |
1545 | { | |
1546 | for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next) | |
1547 | ; | |
1548 | ||
1549 | si = seg_info (now_seg); | |
1550 | *pl = si->label_list; | |
1551 | si->label_list = NULL; | |
1552 | } | |
252b5132 | 1553 | } |
a8dbcb85 | 1554 | |
df58fc94 RS |
1555 | /* Mark instruction labels in MIPS16/microMIPS mode. */ |
1556 | ||
1557 | static inline void | |
1558 | mips_mark_labels (void) | |
1559 | { | |
1560 | if (HAVE_CODE_COMPRESSION) | |
1561 | mips_compressed_mark_labels (); | |
1562 | } | |
252b5132 RH |
1563 | \f |
1564 | static char *expr_end; | |
1565 | ||
1566 | /* Expressions which appear in instructions. These are set by | |
1567 | mips_ip. */ | |
1568 | ||
1569 | static expressionS imm_expr; | |
5f74bc13 | 1570 | static expressionS imm2_expr; |
252b5132 RH |
1571 | static expressionS offset_expr; |
1572 | ||
1573 | /* Relocs associated with imm_expr and offset_expr. */ | |
1574 | ||
f6688943 TS |
1575 | static bfd_reloc_code_real_type imm_reloc[3] |
1576 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
1577 | static bfd_reloc_code_real_type offset_reloc[3] | |
1578 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 | 1579 | |
df58fc94 RS |
1580 | /* This is set to the resulting size of the instruction to be produced |
1581 | by mips16_ip if an explicit extension is used or by mips_ip if an | |
1582 | explicit size is supplied. */ | |
252b5132 | 1583 | |
df58fc94 | 1584 | static unsigned int forced_insn_length; |
252b5132 | 1585 | |
e1b47bd5 RS |
1586 | /* True if we are assembling an instruction. All dot symbols defined during |
1587 | this time should be treated as code labels. */ | |
1588 | ||
1589 | static bfd_boolean mips_assembling_insn; | |
1590 | ||
7ed4a06a | 1591 | #ifdef OBJ_ELF |
ecb4347a DJ |
1592 | /* The pdr segment for per procedure frame/regmask info. Not used for |
1593 | ECOFF debugging. */ | |
252b5132 RH |
1594 | |
1595 | static segT pdr_seg; | |
7ed4a06a | 1596 | #endif |
252b5132 | 1597 | |
e013f690 TS |
1598 | /* The default target format to use. */ |
1599 | ||
aeffff67 RS |
1600 | #if defined (TE_FreeBSD) |
1601 | #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips-freebsd" | |
1602 | #elif defined (TE_TMIPS) | |
1603 | #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips" | |
1604 | #else | |
1605 | #define ELF_TARGET(PREFIX, ENDIAN) PREFIX ENDIAN "mips" | |
1606 | #endif | |
1607 | ||
e013f690 | 1608 | const char * |
17a2f251 | 1609 | mips_target_format (void) |
e013f690 TS |
1610 | { |
1611 | switch (OUTPUT_FLAVOR) | |
1612 | { | |
e013f690 TS |
1613 | case bfd_target_ecoff_flavour: |
1614 | return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT; | |
1615 | case bfd_target_coff_flavour: | |
1616 | return "pe-mips"; | |
1617 | case bfd_target_elf_flavour: | |
0a44bf69 RS |
1618 | #ifdef TE_VXWORKS |
1619 | if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI) | |
1620 | return (target_big_endian | |
1621 | ? "elf32-bigmips-vxworks" | |
1622 | : "elf32-littlemips-vxworks"); | |
1623 | #endif | |
e013f690 | 1624 | return (target_big_endian |
cfe86eaa | 1625 | ? (HAVE_64BIT_OBJECTS |
aeffff67 | 1626 | ? ELF_TARGET ("elf64-", "big") |
cfe86eaa | 1627 | : (HAVE_NEWABI |
aeffff67 RS |
1628 | ? ELF_TARGET ("elf32-n", "big") |
1629 | : ELF_TARGET ("elf32-", "big"))) | |
cfe86eaa | 1630 | : (HAVE_64BIT_OBJECTS |
aeffff67 | 1631 | ? ELF_TARGET ("elf64-", "little") |
cfe86eaa | 1632 | : (HAVE_NEWABI |
aeffff67 RS |
1633 | ? ELF_TARGET ("elf32-n", "little") |
1634 | : ELF_TARGET ("elf32-", "little")))); | |
e013f690 TS |
1635 | default: |
1636 | abort (); | |
1637 | return NULL; | |
1638 | } | |
1639 | } | |
1640 | ||
df58fc94 RS |
1641 | /* Return the length of a microMIPS instruction in bytes. If bits of |
1642 | the mask beyond the low 16 are 0, then it is a 16-bit instruction. | |
1643 | Otherwise assume a 32-bit instruction; 48-bit instructions (0x1f | |
1644 | major opcode) will require further modifications to the opcode | |
1645 | table. */ | |
1646 | ||
1647 | static inline unsigned int | |
1648 | micromips_insn_length (const struct mips_opcode *mo) | |
1649 | { | |
1650 | return (mo->mask >> 16) == 0 ? 2 : 4; | |
1651 | } | |
1652 | ||
5c04167a RS |
1653 | /* Return the length of MIPS16 instruction OPCODE. */ |
1654 | ||
1655 | static inline unsigned int | |
1656 | mips16_opcode_length (unsigned long opcode) | |
1657 | { | |
1658 | return (opcode >> 16) == 0 ? 2 : 4; | |
1659 | } | |
1660 | ||
1e915849 RS |
1661 | /* Return the length of instruction INSN. */ |
1662 | ||
1663 | static inline unsigned int | |
1664 | insn_length (const struct mips_cl_insn *insn) | |
1665 | { | |
df58fc94 RS |
1666 | if (mips_opts.micromips) |
1667 | return micromips_insn_length (insn->insn_mo); | |
1668 | else if (mips_opts.mips16) | |
5c04167a | 1669 | return mips16_opcode_length (insn->insn_opcode); |
df58fc94 | 1670 | else |
1e915849 | 1671 | return 4; |
1e915849 RS |
1672 | } |
1673 | ||
1674 | /* Initialise INSN from opcode entry MO. Leave its position unspecified. */ | |
1675 | ||
1676 | static void | |
1677 | create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo) | |
1678 | { | |
1679 | size_t i; | |
1680 | ||
1681 | insn->insn_mo = mo; | |
1e915849 RS |
1682 | insn->insn_opcode = mo->match; |
1683 | insn->frag = NULL; | |
1684 | insn->where = 0; | |
1685 | for (i = 0; i < ARRAY_SIZE (insn->fixp); i++) | |
1686 | insn->fixp[i] = NULL; | |
1687 | insn->fixed_p = (mips_opts.noreorder > 0); | |
1688 | insn->noreorder_p = (mips_opts.noreorder > 0); | |
1689 | insn->mips16_absolute_jump_p = 0; | |
15be625d | 1690 | insn->complete_p = 0; |
e407c74b | 1691 | insn->cleared_p = 0; |
1e915849 RS |
1692 | } |
1693 | ||
df58fc94 | 1694 | /* Record the current MIPS16/microMIPS mode in now_seg. */ |
742a56fe RS |
1695 | |
1696 | static void | |
df58fc94 | 1697 | mips_record_compressed_mode (void) |
742a56fe RS |
1698 | { |
1699 | segment_info_type *si; | |
1700 | ||
1701 | si = seg_info (now_seg); | |
1702 | if (si->tc_segment_info_data.mips16 != mips_opts.mips16) | |
1703 | si->tc_segment_info_data.mips16 = mips_opts.mips16; | |
df58fc94 RS |
1704 | if (si->tc_segment_info_data.micromips != mips_opts.micromips) |
1705 | si->tc_segment_info_data.micromips = mips_opts.micromips; | |
742a56fe RS |
1706 | } |
1707 | ||
4d68580a RS |
1708 | /* Read a standard MIPS instruction from BUF. */ |
1709 | ||
1710 | static unsigned long | |
1711 | read_insn (char *buf) | |
1712 | { | |
1713 | if (target_big_endian) | |
1714 | return bfd_getb32 ((bfd_byte *) buf); | |
1715 | else | |
1716 | return bfd_getl32 ((bfd_byte *) buf); | |
1717 | } | |
1718 | ||
1719 | /* Write standard MIPS instruction INSN to BUF. Return a pointer to | |
1720 | the next byte. */ | |
1721 | ||
1722 | static char * | |
1723 | write_insn (char *buf, unsigned int insn) | |
1724 | { | |
1725 | md_number_to_chars (buf, insn, 4); | |
1726 | return buf + 4; | |
1727 | } | |
1728 | ||
1729 | /* Read a microMIPS or MIPS16 opcode from BUF, given that it | |
1730 | has length LENGTH. */ | |
1731 | ||
1732 | static unsigned long | |
1733 | read_compressed_insn (char *buf, unsigned int length) | |
1734 | { | |
1735 | unsigned long insn; | |
1736 | unsigned int i; | |
1737 | ||
1738 | insn = 0; | |
1739 | for (i = 0; i < length; i += 2) | |
1740 | { | |
1741 | insn <<= 16; | |
1742 | if (target_big_endian) | |
1743 | insn |= bfd_getb16 ((char *) buf); | |
1744 | else | |
1745 | insn |= bfd_getl16 ((char *) buf); | |
1746 | buf += 2; | |
1747 | } | |
1748 | return insn; | |
1749 | } | |
1750 | ||
5c04167a RS |
1751 | /* Write microMIPS or MIPS16 instruction INSN to BUF, given that the |
1752 | instruction is LENGTH bytes long. Return a pointer to the next byte. */ | |
1753 | ||
1754 | static char * | |
1755 | write_compressed_insn (char *buf, unsigned int insn, unsigned int length) | |
1756 | { | |
1757 | unsigned int i; | |
1758 | ||
1759 | for (i = 0; i < length; i += 2) | |
1760 | md_number_to_chars (buf + i, insn >> ((length - i - 2) * 8), 2); | |
1761 | return buf + length; | |
1762 | } | |
1763 | ||
1e915849 RS |
1764 | /* Install INSN at the location specified by its "frag" and "where" fields. */ |
1765 | ||
1766 | static void | |
1767 | install_insn (const struct mips_cl_insn *insn) | |
1768 | { | |
1769 | char *f = insn->frag->fr_literal + insn->where; | |
5c04167a RS |
1770 | if (HAVE_CODE_COMPRESSION) |
1771 | write_compressed_insn (f, insn->insn_opcode, insn_length (insn)); | |
1e915849 | 1772 | else |
4d68580a | 1773 | write_insn (f, insn->insn_opcode); |
df58fc94 | 1774 | mips_record_compressed_mode (); |
1e915849 RS |
1775 | } |
1776 | ||
1777 | /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly | |
1778 | and install the opcode in the new location. */ | |
1779 | ||
1780 | static void | |
1781 | move_insn (struct mips_cl_insn *insn, fragS *frag, long where) | |
1782 | { | |
1783 | size_t i; | |
1784 | ||
1785 | insn->frag = frag; | |
1786 | insn->where = where; | |
1787 | for (i = 0; i < ARRAY_SIZE (insn->fixp); i++) | |
1788 | if (insn->fixp[i] != NULL) | |
1789 | { | |
1790 | insn->fixp[i]->fx_frag = frag; | |
1791 | insn->fixp[i]->fx_where = where; | |
1792 | } | |
1793 | install_insn (insn); | |
1794 | } | |
1795 | ||
1796 | /* Add INSN to the end of the output. */ | |
1797 | ||
1798 | static void | |
1799 | add_fixed_insn (struct mips_cl_insn *insn) | |
1800 | { | |
1801 | char *f = frag_more (insn_length (insn)); | |
1802 | move_insn (insn, frag_now, f - frag_now->fr_literal); | |
1803 | } | |
1804 | ||
1805 | /* Start a variant frag and move INSN to the start of the variant part, | |
1806 | marking it as fixed. The other arguments are as for frag_var. */ | |
1807 | ||
1808 | static void | |
1809 | add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var, | |
1810 | relax_substateT subtype, symbolS *symbol, offsetT offset) | |
1811 | { | |
1812 | frag_grow (max_chars); | |
1813 | move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal); | |
1814 | insn->fixed_p = 1; | |
1815 | frag_var (rs_machine_dependent, max_chars, var, | |
1816 | subtype, symbol, offset, NULL); | |
1817 | } | |
1818 | ||
1819 | /* Insert N copies of INSN into the history buffer, starting at | |
1820 | position FIRST. Neither FIRST nor N need to be clipped. */ | |
1821 | ||
1822 | static void | |
1823 | insert_into_history (unsigned int first, unsigned int n, | |
1824 | const struct mips_cl_insn *insn) | |
1825 | { | |
1826 | if (mips_relax.sequence != 2) | |
1827 | { | |
1828 | unsigned int i; | |
1829 | ||
1830 | for (i = ARRAY_SIZE (history); i-- > first;) | |
1831 | if (i >= first + n) | |
1832 | history[i] = history[i - n]; | |
1833 | else | |
1834 | history[i] = *insn; | |
1835 | } | |
1836 | } | |
1837 | ||
71400594 RS |
1838 | /* Initialize vr4120_conflicts. There is a bit of duplication here: |
1839 | the idea is to make it obvious at a glance that each errata is | |
1840 | included. */ | |
1841 | ||
1842 | static void | |
1843 | init_vr4120_conflicts (void) | |
1844 | { | |
1845 | #define CONFLICT(FIRST, SECOND) \ | |
1846 | vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND | |
1847 | ||
1848 | /* Errata 21 - [D]DIV[U] after [D]MACC */ | |
1849 | CONFLICT (MACC, DIV); | |
1850 | CONFLICT (DMACC, DIV); | |
1851 | ||
1852 | /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */ | |
1853 | CONFLICT (DMULT, DMULT); | |
1854 | CONFLICT (DMULT, DMACC); | |
1855 | CONFLICT (DMACC, DMULT); | |
1856 | CONFLICT (DMACC, DMACC); | |
1857 | ||
1858 | /* Errata 24 - MT{LO,HI} after [D]MACC */ | |
1859 | CONFLICT (MACC, MTHILO); | |
1860 | CONFLICT (DMACC, MTHILO); | |
1861 | ||
1862 | /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU | |
1863 | instruction is executed immediately after a MACC or DMACC | |
1864 | instruction, the result of [either instruction] is incorrect." */ | |
1865 | CONFLICT (MACC, MULT); | |
1866 | CONFLICT (MACC, DMULT); | |
1867 | CONFLICT (DMACC, MULT); | |
1868 | CONFLICT (DMACC, DMULT); | |
1869 | ||
1870 | /* VR4181A errata MD(4): "If a MACC or DMACC instruction is | |
1871 | executed immediately after a DMULT, DMULTU, DIV, DIVU, | |
1872 | DDIV or DDIVU instruction, the result of the MACC or | |
1873 | DMACC instruction is incorrect.". */ | |
1874 | CONFLICT (DMULT, MACC); | |
1875 | CONFLICT (DMULT, DMACC); | |
1876 | CONFLICT (DIV, MACC); | |
1877 | CONFLICT (DIV, DMACC); | |
1878 | ||
1879 | #undef CONFLICT | |
1880 | } | |
1881 | ||
707bfff6 TS |
1882 | struct regname { |
1883 | const char *name; | |
1884 | unsigned int num; | |
1885 | }; | |
1886 | ||
1887 | #define RTYPE_MASK 0x1ff00 | |
1888 | #define RTYPE_NUM 0x00100 | |
1889 | #define RTYPE_FPU 0x00200 | |
1890 | #define RTYPE_FCC 0x00400 | |
1891 | #define RTYPE_VEC 0x00800 | |
1892 | #define RTYPE_GP 0x01000 | |
1893 | #define RTYPE_CP0 0x02000 | |
1894 | #define RTYPE_PC 0x04000 | |
1895 | #define RTYPE_ACC 0x08000 | |
1896 | #define RTYPE_CCC 0x10000 | |
1897 | #define RNUM_MASK 0x000ff | |
1898 | #define RWARN 0x80000 | |
1899 | ||
1900 | #define GENERIC_REGISTER_NUMBERS \ | |
1901 | {"$0", RTYPE_NUM | 0}, \ | |
1902 | {"$1", RTYPE_NUM | 1}, \ | |
1903 | {"$2", RTYPE_NUM | 2}, \ | |
1904 | {"$3", RTYPE_NUM | 3}, \ | |
1905 | {"$4", RTYPE_NUM | 4}, \ | |
1906 | {"$5", RTYPE_NUM | 5}, \ | |
1907 | {"$6", RTYPE_NUM | 6}, \ | |
1908 | {"$7", RTYPE_NUM | 7}, \ | |
1909 | {"$8", RTYPE_NUM | 8}, \ | |
1910 | {"$9", RTYPE_NUM | 9}, \ | |
1911 | {"$10", RTYPE_NUM | 10}, \ | |
1912 | {"$11", RTYPE_NUM | 11}, \ | |
1913 | {"$12", RTYPE_NUM | 12}, \ | |
1914 | {"$13", RTYPE_NUM | 13}, \ | |
1915 | {"$14", RTYPE_NUM | 14}, \ | |
1916 | {"$15", RTYPE_NUM | 15}, \ | |
1917 | {"$16", RTYPE_NUM | 16}, \ | |
1918 | {"$17", RTYPE_NUM | 17}, \ | |
1919 | {"$18", RTYPE_NUM | 18}, \ | |
1920 | {"$19", RTYPE_NUM | 19}, \ | |
1921 | {"$20", RTYPE_NUM | 20}, \ | |
1922 | {"$21", RTYPE_NUM | 21}, \ | |
1923 | {"$22", RTYPE_NUM | 22}, \ | |
1924 | {"$23", RTYPE_NUM | 23}, \ | |
1925 | {"$24", RTYPE_NUM | 24}, \ | |
1926 | {"$25", RTYPE_NUM | 25}, \ | |
1927 | {"$26", RTYPE_NUM | 26}, \ | |
1928 | {"$27", RTYPE_NUM | 27}, \ | |
1929 | {"$28", RTYPE_NUM | 28}, \ | |
1930 | {"$29", RTYPE_NUM | 29}, \ | |
1931 | {"$30", RTYPE_NUM | 30}, \ | |
1932 | {"$31", RTYPE_NUM | 31} | |
1933 | ||
1934 | #define FPU_REGISTER_NAMES \ | |
1935 | {"$f0", RTYPE_FPU | 0}, \ | |
1936 | {"$f1", RTYPE_FPU | 1}, \ | |
1937 | {"$f2", RTYPE_FPU | 2}, \ | |
1938 | {"$f3", RTYPE_FPU | 3}, \ | |
1939 | {"$f4", RTYPE_FPU | 4}, \ | |
1940 | {"$f5", RTYPE_FPU | 5}, \ | |
1941 | {"$f6", RTYPE_FPU | 6}, \ | |
1942 | {"$f7", RTYPE_FPU | 7}, \ | |
1943 | {"$f8", RTYPE_FPU | 8}, \ | |
1944 | {"$f9", RTYPE_FPU | 9}, \ | |
1945 | {"$f10", RTYPE_FPU | 10}, \ | |
1946 | {"$f11", RTYPE_FPU | 11}, \ | |
1947 | {"$f12", RTYPE_FPU | 12}, \ | |
1948 | {"$f13", RTYPE_FPU | 13}, \ | |
1949 | {"$f14", RTYPE_FPU | 14}, \ | |
1950 | {"$f15", RTYPE_FPU | 15}, \ | |
1951 | {"$f16", RTYPE_FPU | 16}, \ | |
1952 | {"$f17", RTYPE_FPU | 17}, \ | |
1953 | {"$f18", RTYPE_FPU | 18}, \ | |
1954 | {"$f19", RTYPE_FPU | 19}, \ | |
1955 | {"$f20", RTYPE_FPU | 20}, \ | |
1956 | {"$f21", RTYPE_FPU | 21}, \ | |
1957 | {"$f22", RTYPE_FPU | 22}, \ | |
1958 | {"$f23", RTYPE_FPU | 23}, \ | |
1959 | {"$f24", RTYPE_FPU | 24}, \ | |
1960 | {"$f25", RTYPE_FPU | 25}, \ | |
1961 | {"$f26", RTYPE_FPU | 26}, \ | |
1962 | {"$f27", RTYPE_FPU | 27}, \ | |
1963 | {"$f28", RTYPE_FPU | 28}, \ | |
1964 | {"$f29", RTYPE_FPU | 29}, \ | |
1965 | {"$f30", RTYPE_FPU | 30}, \ | |
1966 | {"$f31", RTYPE_FPU | 31} | |
1967 | ||
1968 | #define FPU_CONDITION_CODE_NAMES \ | |
1969 | {"$fcc0", RTYPE_FCC | 0}, \ | |
1970 | {"$fcc1", RTYPE_FCC | 1}, \ | |
1971 | {"$fcc2", RTYPE_FCC | 2}, \ | |
1972 | {"$fcc3", RTYPE_FCC | 3}, \ | |
1973 | {"$fcc4", RTYPE_FCC | 4}, \ | |
1974 | {"$fcc5", RTYPE_FCC | 5}, \ | |
1975 | {"$fcc6", RTYPE_FCC | 6}, \ | |
1976 | {"$fcc7", RTYPE_FCC | 7} | |
1977 | ||
1978 | #define COPROC_CONDITION_CODE_NAMES \ | |
1979 | {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \ | |
1980 | {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \ | |
1981 | {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \ | |
1982 | {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \ | |
1983 | {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \ | |
1984 | {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \ | |
1985 | {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \ | |
1986 | {"$cc7", RTYPE_FCC | RTYPE_CCC | 7} | |
1987 | ||
1988 | #define N32N64_SYMBOLIC_REGISTER_NAMES \ | |
1989 | {"$a4", RTYPE_GP | 8}, \ | |
1990 | {"$a5", RTYPE_GP | 9}, \ | |
1991 | {"$a6", RTYPE_GP | 10}, \ | |
1992 | {"$a7", RTYPE_GP | 11}, \ | |
1993 | {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \ | |
1994 | {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \ | |
1995 | {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \ | |
1996 | {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \ | |
1997 | {"$t0", RTYPE_GP | 12}, \ | |
1998 | {"$t1", RTYPE_GP | 13}, \ | |
1999 | {"$t2", RTYPE_GP | 14}, \ | |
2000 | {"$t3", RTYPE_GP | 15} | |
2001 | ||
2002 | #define O32_SYMBOLIC_REGISTER_NAMES \ | |
2003 | {"$t0", RTYPE_GP | 8}, \ | |
2004 | {"$t1", RTYPE_GP | 9}, \ | |
2005 | {"$t2", RTYPE_GP | 10}, \ | |
2006 | {"$t3", RTYPE_GP | 11}, \ | |
2007 | {"$t4", RTYPE_GP | 12}, \ | |
2008 | {"$t5", RTYPE_GP | 13}, \ | |
2009 | {"$t6", RTYPE_GP | 14}, \ | |
2010 | {"$t7", RTYPE_GP | 15}, \ | |
2011 | {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \ | |
2012 | {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \ | |
2013 | {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \ | |
2014 | {"$ta3", RTYPE_GP | 15} /* alias for $t7 */ | |
2015 | ||
2016 | /* Remaining symbolic register names */ | |
2017 | #define SYMBOLIC_REGISTER_NAMES \ | |
2018 | {"$zero", RTYPE_GP | 0}, \ | |
2019 | {"$at", RTYPE_GP | 1}, \ | |
2020 | {"$AT", RTYPE_GP | 1}, \ | |
2021 | {"$v0", RTYPE_GP | 2}, \ | |
2022 | {"$v1", RTYPE_GP | 3}, \ | |
2023 | {"$a0", RTYPE_GP | 4}, \ | |
2024 | {"$a1", RTYPE_GP | 5}, \ | |
2025 | {"$a2", RTYPE_GP | 6}, \ | |
2026 | {"$a3", RTYPE_GP | 7}, \ | |
2027 | {"$s0", RTYPE_GP | 16}, \ | |
2028 | {"$s1", RTYPE_GP | 17}, \ | |
2029 | {"$s2", RTYPE_GP | 18}, \ | |
2030 | {"$s3", RTYPE_GP | 19}, \ | |
2031 | {"$s4", RTYPE_GP | 20}, \ | |
2032 | {"$s5", RTYPE_GP | 21}, \ | |
2033 | {"$s6", RTYPE_GP | 22}, \ | |
2034 | {"$s7", RTYPE_GP | 23}, \ | |
2035 | {"$t8", RTYPE_GP | 24}, \ | |
2036 | {"$t9", RTYPE_GP | 25}, \ | |
2037 | {"$k0", RTYPE_GP | 26}, \ | |
2038 | {"$kt0", RTYPE_GP | 26}, \ | |
2039 | {"$k1", RTYPE_GP | 27}, \ | |
2040 | {"$kt1", RTYPE_GP | 27}, \ | |
2041 | {"$gp", RTYPE_GP | 28}, \ | |
2042 | {"$sp", RTYPE_GP | 29}, \ | |
2043 | {"$s8", RTYPE_GP | 30}, \ | |
2044 | {"$fp", RTYPE_GP | 30}, \ | |
2045 | {"$ra", RTYPE_GP | 31} | |
2046 | ||
2047 | #define MIPS16_SPECIAL_REGISTER_NAMES \ | |
2048 | {"$pc", RTYPE_PC | 0} | |
2049 | ||
2050 | #define MDMX_VECTOR_REGISTER_NAMES \ | |
2051 | /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \ | |
2052 | /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \ | |
2053 | {"$v2", RTYPE_VEC | 2}, \ | |
2054 | {"$v3", RTYPE_VEC | 3}, \ | |
2055 | {"$v4", RTYPE_VEC | 4}, \ | |
2056 | {"$v5", RTYPE_VEC | 5}, \ | |
2057 | {"$v6", RTYPE_VEC | 6}, \ | |
2058 | {"$v7", RTYPE_VEC | 7}, \ | |
2059 | {"$v8", RTYPE_VEC | 8}, \ | |
2060 | {"$v9", RTYPE_VEC | 9}, \ | |
2061 | {"$v10", RTYPE_VEC | 10}, \ | |
2062 | {"$v11", RTYPE_VEC | 11}, \ | |
2063 | {"$v12", RTYPE_VEC | 12}, \ | |
2064 | {"$v13", RTYPE_VEC | 13}, \ | |
2065 | {"$v14", RTYPE_VEC | 14}, \ | |
2066 | {"$v15", RTYPE_VEC | 15}, \ | |
2067 | {"$v16", RTYPE_VEC | 16}, \ | |
2068 | {"$v17", RTYPE_VEC | 17}, \ | |
2069 | {"$v18", RTYPE_VEC | 18}, \ | |
2070 | {"$v19", RTYPE_VEC | 19}, \ | |
2071 | {"$v20", RTYPE_VEC | 20}, \ | |
2072 | {"$v21", RTYPE_VEC | 21}, \ | |
2073 | {"$v22", RTYPE_VEC | 22}, \ | |
2074 | {"$v23", RTYPE_VEC | 23}, \ | |
2075 | {"$v24", RTYPE_VEC | 24}, \ | |
2076 | {"$v25", RTYPE_VEC | 25}, \ | |
2077 | {"$v26", RTYPE_VEC | 26}, \ | |
2078 | {"$v27", RTYPE_VEC | 27}, \ | |
2079 | {"$v28", RTYPE_VEC | 28}, \ | |
2080 | {"$v29", RTYPE_VEC | 29}, \ | |
2081 | {"$v30", RTYPE_VEC | 30}, \ | |
2082 | {"$v31", RTYPE_VEC | 31} | |
2083 | ||
2084 | #define MIPS_DSP_ACCUMULATOR_NAMES \ | |
2085 | {"$ac0", RTYPE_ACC | 0}, \ | |
2086 | {"$ac1", RTYPE_ACC | 1}, \ | |
2087 | {"$ac2", RTYPE_ACC | 2}, \ | |
2088 | {"$ac3", RTYPE_ACC | 3} | |
2089 | ||
2090 | static const struct regname reg_names[] = { | |
2091 | GENERIC_REGISTER_NUMBERS, | |
2092 | FPU_REGISTER_NAMES, | |
2093 | FPU_CONDITION_CODE_NAMES, | |
2094 | COPROC_CONDITION_CODE_NAMES, | |
2095 | ||
2096 | /* The $txx registers depends on the abi, | |
2097 | these will be added later into the symbol table from | |
2098 | one of the tables below once mips_abi is set after | |
2099 | parsing of arguments from the command line. */ | |
2100 | SYMBOLIC_REGISTER_NAMES, | |
2101 | ||
2102 | MIPS16_SPECIAL_REGISTER_NAMES, | |
2103 | MDMX_VECTOR_REGISTER_NAMES, | |
2104 | MIPS_DSP_ACCUMULATOR_NAMES, | |
2105 | {0, 0} | |
2106 | }; | |
2107 | ||
2108 | static const struct regname reg_names_o32[] = { | |
2109 | O32_SYMBOLIC_REGISTER_NAMES, | |
2110 | {0, 0} | |
2111 | }; | |
2112 | ||
2113 | static const struct regname reg_names_n32n64[] = { | |
2114 | N32N64_SYMBOLIC_REGISTER_NAMES, | |
2115 | {0, 0} | |
2116 | }; | |
2117 | ||
df58fc94 RS |
2118 | /* Check if S points at a valid register specifier according to TYPES. |
2119 | If so, then return 1, advance S to consume the specifier and store | |
2120 | the register's number in REGNOP, otherwise return 0. */ | |
2121 | ||
707bfff6 TS |
2122 | static int |
2123 | reg_lookup (char **s, unsigned int types, unsigned int *regnop) | |
2124 | { | |
2125 | symbolS *symbolP; | |
2126 | char *e; | |
2127 | char save_c; | |
2128 | int reg = -1; | |
2129 | ||
2130 | /* Find end of name. */ | |
2131 | e = *s; | |
2132 | if (is_name_beginner (*e)) | |
2133 | ++e; | |
2134 | while (is_part_of_name (*e)) | |
2135 | ++e; | |
2136 | ||
2137 | /* Terminate name. */ | |
2138 | save_c = *e; | |
2139 | *e = '\0'; | |
2140 | ||
2141 | /* Look for a register symbol. */ | |
2142 | if ((symbolP = symbol_find (*s)) && S_GET_SEGMENT (symbolP) == reg_section) | |
2143 | { | |
2144 | int r = S_GET_VALUE (symbolP); | |
2145 | if (r & types) | |
2146 | reg = r & RNUM_MASK; | |
2147 | else if ((types & RTYPE_VEC) && (r & ~1) == (RTYPE_GP | 2)) | |
2148 | /* Convert GP reg $v0/1 to MDMX reg $v0/1! */ | |
2149 | reg = (r & RNUM_MASK) - 2; | |
2150 | } | |
2151 | /* Else see if this is a register defined in an itbl entry. */ | |
2152 | else if ((types & RTYPE_GP) && itbl_have_entries) | |
2153 | { | |
2154 | char *n = *s; | |
2155 | unsigned long r; | |
2156 | ||
2157 | if (*n == '$') | |
2158 | ++n; | |
2159 | if (itbl_get_reg_val (n, &r)) | |
2160 | reg = r & RNUM_MASK; | |
2161 | } | |
2162 | ||
2163 | /* Advance to next token if a register was recognised. */ | |
2164 | if (reg >= 0) | |
2165 | *s = e; | |
2166 | else if (types & RWARN) | |
20203fb9 | 2167 | as_warn (_("Unrecognized register name `%s'"), *s); |
707bfff6 TS |
2168 | |
2169 | *e = save_c; | |
2170 | if (regnop) | |
2171 | *regnop = reg; | |
2172 | return reg >= 0; | |
2173 | } | |
2174 | ||
df58fc94 RS |
2175 | /* Check if S points at a valid register list according to TYPES. |
2176 | If so, then return 1, advance S to consume the list and store | |
2177 | the registers present on the list as a bitmask of ones in REGLISTP, | |
2178 | otherwise return 0. A valid list comprises a comma-separated | |
2179 | enumeration of valid single registers and/or dash-separated | |
2180 | contiguous register ranges as determined by their numbers. | |
2181 | ||
2182 | As a special exception if one of s0-s7 registers is specified as | |
2183 | the range's lower delimiter and s8 (fp) is its upper one, then no | |
2184 | registers whose numbers place them between s7 and s8 (i.e. $24-$29) | |
2309ddf2 | 2185 | are selected; they have to be listed separately if needed. */ |
df58fc94 RS |
2186 | |
2187 | static int | |
2188 | reglist_lookup (char **s, unsigned int types, unsigned int *reglistp) | |
2189 | { | |
2190 | unsigned int reglist = 0; | |
2191 | unsigned int lastregno; | |
2192 | bfd_boolean ok = TRUE; | |
2193 | unsigned int regmask; | |
2309ddf2 | 2194 | char *s_endlist = *s; |
df58fc94 | 2195 | char *s_reset = *s; |
2309ddf2 | 2196 | unsigned int regno; |
df58fc94 RS |
2197 | |
2198 | while (reg_lookup (s, types, ®no)) | |
2199 | { | |
2200 | lastregno = regno; | |
2201 | if (**s == '-') | |
2202 | { | |
2203 | (*s)++; | |
2204 | ok = reg_lookup (s, types, &lastregno); | |
2205 | if (ok && lastregno < regno) | |
2206 | ok = FALSE; | |
2207 | if (!ok) | |
2208 | break; | |
2209 | } | |
2210 | ||
2211 | if (lastregno == FP && regno >= S0 && regno <= S7) | |
2212 | { | |
2213 | lastregno = S7; | |
2214 | reglist |= 1 << FP; | |
2215 | } | |
2216 | regmask = 1 << lastregno; | |
2217 | regmask = (regmask << 1) - 1; | |
2218 | regmask ^= (1 << regno) - 1; | |
2219 | reglist |= regmask; | |
2220 | ||
2309ddf2 | 2221 | s_endlist = *s; |
df58fc94 RS |
2222 | if (**s != ',') |
2223 | break; | |
2224 | (*s)++; | |
2225 | } | |
2226 | ||
2227 | if (ok) | |
2309ddf2 | 2228 | *s = s_endlist; |
df58fc94 RS |
2229 | else |
2230 | *s = s_reset; | |
2231 | if (reglistp) | |
2232 | *reglistp = reglist; | |
2233 | return ok && reglist != 0; | |
2234 | } | |
2235 | ||
037b32b9 | 2236 | /* Return TRUE if opcode MO is valid on the currently selected ISA and |
f79e2745 | 2237 | architecture. Use is_opcode_valid_16 for MIPS16 opcodes. */ |
037b32b9 AN |
2238 | |
2239 | static bfd_boolean | |
f79e2745 | 2240 | is_opcode_valid (const struct mips_opcode *mo) |
037b32b9 AN |
2241 | { |
2242 | int isa = mips_opts.isa; | |
2243 | int fp_s, fp_d; | |
2244 | ||
2245 | if (mips_opts.ase_mdmx) | |
2246 | isa |= INSN_MDMX; | |
2247 | if (mips_opts.ase_dsp) | |
2248 | isa |= INSN_DSP; | |
2249 | if (mips_opts.ase_dsp && ISA_SUPPORTS_DSP64_ASE) | |
2250 | isa |= INSN_DSP64; | |
2251 | if (mips_opts.ase_dspr2) | |
2252 | isa |= INSN_DSPR2; | |
2253 | if (mips_opts.ase_mt) | |
2254 | isa |= INSN_MT; | |
2255 | if (mips_opts.ase_mips3d) | |
2256 | isa |= INSN_MIPS3D; | |
2257 | if (mips_opts.ase_smartmips) | |
2258 | isa |= INSN_SMARTMIPS; | |
dec0624d MR |
2259 | if (mips_opts.ase_mcu) |
2260 | isa |= INSN_MCU; | |
037b32b9 | 2261 | |
35d0a169 | 2262 | if (!opcode_is_member (mo, isa, mips_opts.arch)) |
037b32b9 AN |
2263 | return FALSE; |
2264 | ||
2265 | /* Check whether the instruction or macro requires single-precision or | |
2266 | double-precision floating-point support. Note that this information is | |
2267 | stored differently in the opcode table for insns and macros. */ | |
2268 | if (mo->pinfo == INSN_MACRO) | |
2269 | { | |
2270 | fp_s = mo->pinfo2 & INSN2_M_FP_S; | |
2271 | fp_d = mo->pinfo2 & INSN2_M_FP_D; | |
2272 | } | |
2273 | else | |
2274 | { | |
2275 | fp_s = mo->pinfo & FP_S; | |
2276 | fp_d = mo->pinfo & FP_D; | |
2277 | } | |
2278 | ||
2279 | if (fp_d && (mips_opts.soft_float || mips_opts.single_float)) | |
2280 | return FALSE; | |
2281 | ||
2282 | if (fp_s && mips_opts.soft_float) | |
2283 | return FALSE; | |
2284 | ||
2285 | return TRUE; | |
2286 | } | |
2287 | ||
2288 | /* Return TRUE if the MIPS16 opcode MO is valid on the currently | |
2289 | selected ISA and architecture. */ | |
2290 | ||
2291 | static bfd_boolean | |
2292 | is_opcode_valid_16 (const struct mips_opcode *mo) | |
2293 | { | |
35d0a169 | 2294 | return opcode_is_member (mo, mips_opts.isa, mips_opts.arch); |
037b32b9 AN |
2295 | } |
2296 | ||
df58fc94 RS |
2297 | /* Return TRUE if the size of the microMIPS opcode MO matches one |
2298 | explicitly requested. Always TRUE in the standard MIPS mode. */ | |
2299 | ||
2300 | static bfd_boolean | |
2301 | is_size_valid (const struct mips_opcode *mo) | |
2302 | { | |
2303 | if (!mips_opts.micromips) | |
2304 | return TRUE; | |
2305 | ||
2306 | if (!forced_insn_length) | |
2307 | return TRUE; | |
2308 | if (mo->pinfo == INSN_MACRO) | |
2309 | return FALSE; | |
2310 | return forced_insn_length == micromips_insn_length (mo); | |
2311 | } | |
2312 | ||
2313 | /* Return TRUE if the microMIPS opcode MO is valid for the delay slot | |
e64af278 MR |
2314 | of the preceding instruction. Always TRUE in the standard MIPS mode. |
2315 | ||
2316 | We don't accept macros in 16-bit delay slots to avoid a case where | |
2317 | a macro expansion fails because it relies on a preceding 32-bit real | |
2318 | instruction to have matched and does not handle the operands correctly. | |
2319 | The only macros that may expand to 16-bit instructions are JAL that | |
2320 | cannot be placed in a delay slot anyway, and corner cases of BALIGN | |
2321 | and BGT (that likewise cannot be placed in a delay slot) that decay to | |
2322 | a NOP. In all these cases the macros precede any corresponding real | |
2323 | instruction definitions in the opcode table, so they will match in the | |
2324 | second pass where the size of the delay slot is ignored and therefore | |
2325 | produce correct code. */ | |
df58fc94 RS |
2326 | |
2327 | static bfd_boolean | |
2328 | is_delay_slot_valid (const struct mips_opcode *mo) | |
2329 | { | |
2330 | if (!mips_opts.micromips) | |
2331 | return TRUE; | |
2332 | ||
2333 | if (mo->pinfo == INSN_MACRO) | |
c06dec14 | 2334 | return (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) == 0; |
df58fc94 RS |
2335 | if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0 |
2336 | && micromips_insn_length (mo) != 4) | |
2337 | return FALSE; | |
2338 | if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 | |
2339 | && micromips_insn_length (mo) != 2) | |
2340 | return FALSE; | |
2341 | ||
2342 | return TRUE; | |
2343 | } | |
2344 | ||
707bfff6 TS |
2345 | /* This function is called once, at assembler startup time. It should set up |
2346 | all the tables, etc. that the MD part of the assembler will need. */ | |
156c2f8b | 2347 | |
252b5132 | 2348 | void |
17a2f251 | 2349 | md_begin (void) |
252b5132 | 2350 | { |
3994f87e | 2351 | const char *retval = NULL; |
156c2f8b | 2352 | int i = 0; |
252b5132 | 2353 | int broken = 0; |
1f25f5d3 | 2354 | |
0a44bf69 RS |
2355 | if (mips_pic != NO_PIC) |
2356 | { | |
2357 | if (g_switch_seen && g_switch_value != 0) | |
2358 | as_bad (_("-G may not be used in position-independent code")); | |
2359 | g_switch_value = 0; | |
2360 | } | |
2361 | ||
fef14a42 | 2362 | if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch)) |
252b5132 RH |
2363 | as_warn (_("Could not set architecture and machine")); |
2364 | ||
252b5132 RH |
2365 | op_hash = hash_new (); |
2366 | ||
2367 | for (i = 0; i < NUMOPCODES;) | |
2368 | { | |
2369 | const char *name = mips_opcodes[i].name; | |
2370 | ||
17a2f251 | 2371 | retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]); |
252b5132 RH |
2372 | if (retval != NULL) |
2373 | { | |
2374 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), | |
2375 | mips_opcodes[i].name, retval); | |
2376 | /* Probably a memory allocation problem? Give up now. */ | |
2377 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
2378 | } | |
2379 | do | |
2380 | { | |
2381 | if (mips_opcodes[i].pinfo != INSN_MACRO) | |
2382 | { | |
2383 | if (!validate_mips_insn (&mips_opcodes[i])) | |
2384 | broken = 1; | |
1e915849 RS |
2385 | if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0) |
2386 | { | |
2387 | create_insn (&nop_insn, mips_opcodes + i); | |
c67a084a NC |
2388 | if (mips_fix_loongson2f_nop) |
2389 | nop_insn.insn_opcode = LOONGSON2F_NOP_INSN; | |
1e915849 RS |
2390 | nop_insn.fixed_p = 1; |
2391 | } | |
252b5132 RH |
2392 | } |
2393 | ++i; | |
2394 | } | |
2395 | while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name)); | |
2396 | } | |
2397 | ||
2398 | mips16_op_hash = hash_new (); | |
2399 | ||
2400 | i = 0; | |
2401 | while (i < bfd_mips16_num_opcodes) | |
2402 | { | |
2403 | const char *name = mips16_opcodes[i].name; | |
2404 | ||
17a2f251 | 2405 | retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]); |
252b5132 RH |
2406 | if (retval != NULL) |
2407 | as_fatal (_("internal: can't hash `%s': %s"), | |
2408 | mips16_opcodes[i].name, retval); | |
2409 | do | |
2410 | { | |
2411 | if (mips16_opcodes[i].pinfo != INSN_MACRO | |
2412 | && ((mips16_opcodes[i].match & mips16_opcodes[i].mask) | |
2413 | != mips16_opcodes[i].match)) | |
2414 | { | |
2415 | fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"), | |
2416 | mips16_opcodes[i].name, mips16_opcodes[i].args); | |
2417 | broken = 1; | |
2418 | } | |
1e915849 RS |
2419 | if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0) |
2420 | { | |
2421 | create_insn (&mips16_nop_insn, mips16_opcodes + i); | |
2422 | mips16_nop_insn.fixed_p = 1; | |
2423 | } | |
252b5132 RH |
2424 | ++i; |
2425 | } | |
2426 | while (i < bfd_mips16_num_opcodes | |
2427 | && strcmp (mips16_opcodes[i].name, name) == 0); | |
2428 | } | |
2429 | ||
df58fc94 RS |
2430 | micromips_op_hash = hash_new (); |
2431 | ||
2432 | i = 0; | |
2433 | while (i < bfd_micromips_num_opcodes) | |
2434 | { | |
2435 | const char *name = micromips_opcodes[i].name; | |
2436 | ||
2437 | retval = hash_insert (micromips_op_hash, name, | |
2438 | (void *) µmips_opcodes[i]); | |
2439 | if (retval != NULL) | |
2440 | as_fatal (_("internal: can't hash `%s': %s"), | |
2441 | micromips_opcodes[i].name, retval); | |
2442 | do | |
2443 | if (micromips_opcodes[i].pinfo != INSN_MACRO) | |
2444 | { | |
2445 | struct mips_cl_insn *micromips_nop_insn; | |
2446 | ||
2447 | if (!validate_micromips_insn (µmips_opcodes[i])) | |
2448 | broken = 1; | |
2449 | ||
2450 | if (micromips_insn_length (micromips_opcodes + i) == 2) | |
2451 | micromips_nop_insn = µmips_nop16_insn; | |
2452 | else if (micromips_insn_length (micromips_opcodes + i) == 4) | |
2453 | micromips_nop_insn = µmips_nop32_insn; | |
2454 | else | |
2455 | continue; | |
2456 | ||
2457 | if (micromips_nop_insn->insn_mo == NULL | |
2458 | && strcmp (name, "nop") == 0) | |
2459 | { | |
2460 | create_insn (micromips_nop_insn, micromips_opcodes + i); | |
2461 | micromips_nop_insn->fixed_p = 1; | |
2462 | } | |
2463 | } | |
2464 | while (++i < bfd_micromips_num_opcodes | |
2465 | && strcmp (micromips_opcodes[i].name, name) == 0); | |
2466 | } | |
2467 | ||
252b5132 RH |
2468 | if (broken) |
2469 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
2470 | ||
2471 | /* We add all the general register names to the symbol table. This | |
2472 | helps us detect invalid uses of them. */ | |
707bfff6 TS |
2473 | for (i = 0; reg_names[i].name; i++) |
2474 | symbol_table_insert (symbol_new (reg_names[i].name, reg_section, | |
8fc4ee9b | 2475 | reg_names[i].num, /* & RNUM_MASK, */ |
707bfff6 TS |
2476 | &zero_address_frag)); |
2477 | if (HAVE_NEWABI) | |
2478 | for (i = 0; reg_names_n32n64[i].name; i++) | |
2479 | symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section, | |
8fc4ee9b | 2480 | reg_names_n32n64[i].num, /* & RNUM_MASK, */ |
252b5132 | 2481 | &zero_address_frag)); |
707bfff6 TS |
2482 | else |
2483 | for (i = 0; reg_names_o32[i].name; i++) | |
2484 | symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section, | |
8fc4ee9b | 2485 | reg_names_o32[i].num, /* & RNUM_MASK, */ |
6047c971 | 2486 | &zero_address_frag)); |
6047c971 | 2487 | |
7d10b47d | 2488 | mips_no_prev_insn (); |
252b5132 RH |
2489 | |
2490 | mips_gprmask = 0; | |
2491 | mips_cprmask[0] = 0; | |
2492 | mips_cprmask[1] = 0; | |
2493 | mips_cprmask[2] = 0; | |
2494 | mips_cprmask[3] = 0; | |
2495 | ||
2496 | /* set the default alignment for the text section (2**2) */ | |
2497 | record_alignment (text_section, 2); | |
2498 | ||
4d0d148d | 2499 | bfd_set_gp_size (stdoutput, g_switch_value); |
252b5132 | 2500 | |
707bfff6 | 2501 | #ifdef OBJ_ELF |
f43abd2b | 2502 | if (IS_ELF) |
252b5132 | 2503 | { |
0a44bf69 RS |
2504 | /* On a native system other than VxWorks, sections must be aligned |
2505 | to 16 byte boundaries. When configured for an embedded ELF | |
2506 | target, we don't bother. */ | |
c41e87e3 CF |
2507 | if (strncmp (TARGET_OS, "elf", 3) != 0 |
2508 | && strncmp (TARGET_OS, "vxworks", 7) != 0) | |
252b5132 RH |
2509 | { |
2510 | (void) bfd_set_section_alignment (stdoutput, text_section, 4); | |
2511 | (void) bfd_set_section_alignment (stdoutput, data_section, 4); | |
2512 | (void) bfd_set_section_alignment (stdoutput, bss_section, 4); | |
2513 | } | |
2514 | ||
2515 | /* Create a .reginfo section for register masks and a .mdebug | |
2516 | section for debugging information. */ | |
2517 | { | |
2518 | segT seg; | |
2519 | subsegT subseg; | |
2520 | flagword flags; | |
2521 | segT sec; | |
2522 | ||
2523 | seg = now_seg; | |
2524 | subseg = now_subseg; | |
2525 | ||
2526 | /* The ABI says this section should be loaded so that the | |
2527 | running program can access it. However, we don't load it | |
2528 | if we are configured for an embedded target */ | |
2529 | flags = SEC_READONLY | SEC_DATA; | |
c41e87e3 | 2530 | if (strncmp (TARGET_OS, "elf", 3) != 0) |
252b5132 RH |
2531 | flags |= SEC_ALLOC | SEC_LOAD; |
2532 | ||
316f5878 | 2533 | if (mips_abi != N64_ABI) |
252b5132 RH |
2534 | { |
2535 | sec = subseg_new (".reginfo", (subsegT) 0); | |
2536 | ||
195325d2 TS |
2537 | bfd_set_section_flags (stdoutput, sec, flags); |
2538 | bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2); | |
bdaaa2e1 | 2539 | |
252b5132 | 2540 | mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo)); |
252b5132 RH |
2541 | } |
2542 | else | |
2543 | { | |
2544 | /* The 64-bit ABI uses a .MIPS.options section rather than | |
2545 | .reginfo section. */ | |
2546 | sec = subseg_new (".MIPS.options", (subsegT) 0); | |
195325d2 TS |
2547 | bfd_set_section_flags (stdoutput, sec, flags); |
2548 | bfd_set_section_alignment (stdoutput, sec, 3); | |
252b5132 | 2549 | |
252b5132 RH |
2550 | /* Set up the option header. */ |
2551 | { | |
2552 | Elf_Internal_Options opthdr; | |
2553 | char *f; | |
2554 | ||
2555 | opthdr.kind = ODK_REGINFO; | |
2556 | opthdr.size = (sizeof (Elf_External_Options) | |
2557 | + sizeof (Elf64_External_RegInfo)); | |
2558 | opthdr.section = 0; | |
2559 | opthdr.info = 0; | |
2560 | f = frag_more (sizeof (Elf_External_Options)); | |
2561 | bfd_mips_elf_swap_options_out (stdoutput, &opthdr, | |
2562 | (Elf_External_Options *) f); | |
2563 | ||
2564 | mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo)); | |
2565 | } | |
252b5132 RH |
2566 | } |
2567 | ||
2568 | if (ECOFF_DEBUGGING) | |
2569 | { | |
2570 | sec = subseg_new (".mdebug", (subsegT) 0); | |
2571 | (void) bfd_set_section_flags (stdoutput, sec, | |
2572 | SEC_HAS_CONTENTS | SEC_READONLY); | |
2573 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
2574 | } | |
f43abd2b | 2575 | else if (mips_flag_pdr) |
ecb4347a DJ |
2576 | { |
2577 | pdr_seg = subseg_new (".pdr", (subsegT) 0); | |
2578 | (void) bfd_set_section_flags (stdoutput, pdr_seg, | |
2579 | SEC_READONLY | SEC_RELOC | |
2580 | | SEC_DEBUGGING); | |
2581 | (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2); | |
2582 | } | |
252b5132 RH |
2583 | |
2584 | subseg_set (seg, subseg); | |
2585 | } | |
2586 | } | |
707bfff6 | 2587 | #endif /* OBJ_ELF */ |
252b5132 RH |
2588 | |
2589 | if (! ECOFF_DEBUGGING) | |
2590 | md_obj_begin (); | |
71400594 RS |
2591 | |
2592 | if (mips_fix_vr4120) | |
2593 | init_vr4120_conflicts (); | |
252b5132 RH |
2594 | } |
2595 | ||
2596 | void | |
17a2f251 | 2597 | md_mips_end (void) |
252b5132 | 2598 | { |
02b1ab82 | 2599 | mips_emit_delays (); |
252b5132 RH |
2600 | if (! ECOFF_DEBUGGING) |
2601 | md_obj_end (); | |
2602 | } | |
2603 | ||
2604 | void | |
17a2f251 | 2605 | md_assemble (char *str) |
252b5132 RH |
2606 | { |
2607 | struct mips_cl_insn insn; | |
f6688943 TS |
2608 | bfd_reloc_code_real_type unused_reloc[3] |
2609 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
2610 | |
2611 | imm_expr.X_op = O_absent; | |
5f74bc13 | 2612 | imm2_expr.X_op = O_absent; |
252b5132 | 2613 | offset_expr.X_op = O_absent; |
f6688943 TS |
2614 | imm_reloc[0] = BFD_RELOC_UNUSED; |
2615 | imm_reloc[1] = BFD_RELOC_UNUSED; | |
2616 | imm_reloc[2] = BFD_RELOC_UNUSED; | |
2617 | offset_reloc[0] = BFD_RELOC_UNUSED; | |
2618 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
2619 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 | 2620 | |
e1b47bd5 RS |
2621 | mips_mark_labels (); |
2622 | mips_assembling_insn = TRUE; | |
2623 | ||
252b5132 RH |
2624 | if (mips_opts.mips16) |
2625 | mips16_ip (str, &insn); | |
2626 | else | |
2627 | { | |
2628 | mips_ip (str, &insn); | |
beae10d5 KH |
2629 | DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), |
2630 | str, insn.insn_opcode)); | |
252b5132 RH |
2631 | } |
2632 | ||
2633 | if (insn_error) | |
e1b47bd5 RS |
2634 | as_bad ("%s `%s'", insn_error, str); |
2635 | else if (insn.insn_mo->pinfo == INSN_MACRO) | |
252b5132 | 2636 | { |
584892a6 | 2637 | macro_start (); |
252b5132 RH |
2638 | if (mips_opts.mips16) |
2639 | mips16_macro (&insn); | |
2640 | else | |
2641 | macro (&insn); | |
584892a6 | 2642 | macro_end (); |
252b5132 RH |
2643 | } |
2644 | else | |
2645 | { | |
2646 | if (imm_expr.X_op != O_absent) | |
df58fc94 | 2647 | append_insn (&insn, &imm_expr, imm_reloc, FALSE); |
252b5132 | 2648 | else if (offset_expr.X_op != O_absent) |
df58fc94 | 2649 | append_insn (&insn, &offset_expr, offset_reloc, FALSE); |
252b5132 | 2650 | else |
df58fc94 | 2651 | append_insn (&insn, NULL, unused_reloc, FALSE); |
252b5132 | 2652 | } |
e1b47bd5 RS |
2653 | |
2654 | mips_assembling_insn = FALSE; | |
252b5132 RH |
2655 | } |
2656 | ||
738e5348 RS |
2657 | /* Convenience functions for abstracting away the differences between |
2658 | MIPS16 and non-MIPS16 relocations. */ | |
2659 | ||
2660 | static inline bfd_boolean | |
2661 | mips16_reloc_p (bfd_reloc_code_real_type reloc) | |
2662 | { | |
2663 | switch (reloc) | |
2664 | { | |
2665 | case BFD_RELOC_MIPS16_JMP: | |
2666 | case BFD_RELOC_MIPS16_GPREL: | |
2667 | case BFD_RELOC_MIPS16_GOT16: | |
2668 | case BFD_RELOC_MIPS16_CALL16: | |
2669 | case BFD_RELOC_MIPS16_HI16_S: | |
2670 | case BFD_RELOC_MIPS16_HI16: | |
2671 | case BFD_RELOC_MIPS16_LO16: | |
2672 | return TRUE; | |
2673 | ||
2674 | default: | |
2675 | return FALSE; | |
2676 | } | |
2677 | } | |
2678 | ||
df58fc94 RS |
2679 | static inline bfd_boolean |
2680 | micromips_reloc_p (bfd_reloc_code_real_type reloc) | |
2681 | { | |
2682 | switch (reloc) | |
2683 | { | |
2684 | case BFD_RELOC_MICROMIPS_7_PCREL_S1: | |
2685 | case BFD_RELOC_MICROMIPS_10_PCREL_S1: | |
2686 | case BFD_RELOC_MICROMIPS_16_PCREL_S1: | |
2687 | case BFD_RELOC_MICROMIPS_GPREL16: | |
2688 | case BFD_RELOC_MICROMIPS_JMP: | |
2689 | case BFD_RELOC_MICROMIPS_HI16: | |
2690 | case BFD_RELOC_MICROMIPS_HI16_S: | |
2691 | case BFD_RELOC_MICROMIPS_LO16: | |
2692 | case BFD_RELOC_MICROMIPS_LITERAL: | |
2693 | case BFD_RELOC_MICROMIPS_GOT16: | |
2694 | case BFD_RELOC_MICROMIPS_CALL16: | |
2695 | case BFD_RELOC_MICROMIPS_GOT_HI16: | |
2696 | case BFD_RELOC_MICROMIPS_GOT_LO16: | |
2697 | case BFD_RELOC_MICROMIPS_CALL_HI16: | |
2698 | case BFD_RELOC_MICROMIPS_CALL_LO16: | |
2699 | case BFD_RELOC_MICROMIPS_SUB: | |
2700 | case BFD_RELOC_MICROMIPS_GOT_PAGE: | |
2701 | case BFD_RELOC_MICROMIPS_GOT_OFST: | |
2702 | case BFD_RELOC_MICROMIPS_GOT_DISP: | |
2703 | case BFD_RELOC_MICROMIPS_HIGHEST: | |
2704 | case BFD_RELOC_MICROMIPS_HIGHER: | |
2705 | case BFD_RELOC_MICROMIPS_SCN_DISP: | |
2706 | case BFD_RELOC_MICROMIPS_JALR: | |
2707 | return TRUE; | |
2708 | ||
2709 | default: | |
2710 | return FALSE; | |
2711 | } | |
2712 | } | |
2713 | ||
2309ddf2 MR |
2714 | static inline bfd_boolean |
2715 | jmp_reloc_p (bfd_reloc_code_real_type reloc) | |
2716 | { | |
2717 | return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP; | |
2718 | } | |
2719 | ||
738e5348 RS |
2720 | static inline bfd_boolean |
2721 | got16_reloc_p (bfd_reloc_code_real_type reloc) | |
2722 | { | |
2309ddf2 | 2723 | return (reloc == BFD_RELOC_MIPS_GOT16 || reloc == BFD_RELOC_MIPS16_GOT16 |
df58fc94 | 2724 | || reloc == BFD_RELOC_MICROMIPS_GOT16); |
738e5348 RS |
2725 | } |
2726 | ||
2727 | static inline bfd_boolean | |
2728 | hi16_reloc_p (bfd_reloc_code_real_type reloc) | |
2729 | { | |
2309ddf2 | 2730 | return (reloc == BFD_RELOC_HI16_S || reloc == BFD_RELOC_MIPS16_HI16_S |
df58fc94 | 2731 | || reloc == BFD_RELOC_MICROMIPS_HI16_S); |
738e5348 RS |
2732 | } |
2733 | ||
2734 | static inline bfd_boolean | |
2735 | lo16_reloc_p (bfd_reloc_code_real_type reloc) | |
2736 | { | |
2309ddf2 | 2737 | return (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_MIPS16_LO16 |
df58fc94 RS |
2738 | || reloc == BFD_RELOC_MICROMIPS_LO16); |
2739 | } | |
2740 | ||
df58fc94 RS |
2741 | static inline bfd_boolean |
2742 | jalr_reloc_p (bfd_reloc_code_real_type reloc) | |
2743 | { | |
2309ddf2 | 2744 | return reloc == BFD_RELOC_MIPS_JALR || reloc == BFD_RELOC_MICROMIPS_JALR; |
738e5348 RS |
2745 | } |
2746 | ||
2de39019 CM |
2747 | /* Return true if RELOC is a PC-relative relocation that does not have |
2748 | full address range. */ | |
2749 | ||
2750 | static inline bfd_boolean | |
2751 | limited_pcrel_reloc_p (bfd_reloc_code_real_type reloc) | |
2752 | { | |
2753 | switch (reloc) | |
2754 | { | |
2755 | case BFD_RELOC_16_PCREL_S2: | |
2756 | case BFD_RELOC_MICROMIPS_7_PCREL_S1: | |
2757 | case BFD_RELOC_MICROMIPS_10_PCREL_S1: | |
2758 | case BFD_RELOC_MICROMIPS_16_PCREL_S1: | |
2759 | return TRUE; | |
2760 | ||
b47468a6 CM |
2761 | case BFD_RELOC_32_PCREL: |
2762 | return HAVE_64BIT_ADDRESSES; | |
2763 | ||
2de39019 CM |
2764 | default: |
2765 | return FALSE; | |
2766 | } | |
2767 | } | |
b47468a6 | 2768 | |
5919d012 | 2769 | /* Return true if the given relocation might need a matching %lo(). |
0a44bf69 RS |
2770 | This is only "might" because SVR4 R_MIPS_GOT16 relocations only |
2771 | need a matching %lo() when applied to local symbols. */ | |
5919d012 RS |
2772 | |
2773 | static inline bfd_boolean | |
17a2f251 | 2774 | reloc_needs_lo_p (bfd_reloc_code_real_type reloc) |
5919d012 | 2775 | { |
3b91255e | 2776 | return (HAVE_IN_PLACE_ADDENDS |
738e5348 | 2777 | && (hi16_reloc_p (reloc) |
0a44bf69 RS |
2778 | /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo(); |
2779 | all GOT16 relocations evaluate to "G". */ | |
738e5348 RS |
2780 | || (got16_reloc_p (reloc) && mips_pic != VXWORKS_PIC))); |
2781 | } | |
2782 | ||
2783 | /* Return the type of %lo() reloc needed by RELOC, given that | |
2784 | reloc_needs_lo_p. */ | |
2785 | ||
2786 | static inline bfd_reloc_code_real_type | |
2787 | matching_lo_reloc (bfd_reloc_code_real_type reloc) | |
2788 | { | |
df58fc94 RS |
2789 | return (mips16_reloc_p (reloc) ? BFD_RELOC_MIPS16_LO16 |
2790 | : (micromips_reloc_p (reloc) ? BFD_RELOC_MICROMIPS_LO16 | |
2791 | : BFD_RELOC_LO16)); | |
5919d012 RS |
2792 | } |
2793 | ||
2794 | /* Return true if the given fixup is followed by a matching R_MIPS_LO16 | |
2795 | relocation. */ | |
2796 | ||
2797 | static inline bfd_boolean | |
17a2f251 | 2798 | fixup_has_matching_lo_p (fixS *fixp) |
5919d012 RS |
2799 | { |
2800 | return (fixp->fx_next != NULL | |
738e5348 | 2801 | && fixp->fx_next->fx_r_type == matching_lo_reloc (fixp->fx_r_type) |
5919d012 RS |
2802 | && fixp->fx_addsy == fixp->fx_next->fx_addsy |
2803 | && fixp->fx_offset == fixp->fx_next->fx_offset); | |
2804 | } | |
2805 | ||
252b5132 RH |
2806 | /* This function returns true if modifying a register requires a |
2807 | delay. */ | |
2808 | ||
2809 | static int | |
17a2f251 | 2810 | reg_needs_delay (unsigned int reg) |
252b5132 RH |
2811 | { |
2812 | unsigned long prev_pinfo; | |
2813 | ||
47e39b9d | 2814 | prev_pinfo = history[0].insn_mo->pinfo; |
252b5132 | 2815 | if (! mips_opts.noreorder |
81912461 ILT |
2816 | && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY) |
2817 | && ! gpr_interlocks) | |
2818 | || ((prev_pinfo & INSN_LOAD_COPROC_DELAY) | |
2819 | && ! cop_interlocks))) | |
252b5132 | 2820 | { |
81912461 ILT |
2821 | /* A load from a coprocessor or from memory. All load delays |
2822 | delay the use of general register rt for one instruction. */ | |
bdaaa2e1 | 2823 | /* Itbl support may require additional care here. */ |
252b5132 | 2824 | know (prev_pinfo & INSN_WRITE_GPR_T); |
df58fc94 | 2825 | if (reg == EXTRACT_OPERAND (mips_opts.micromips, RT, history[0])) |
252b5132 RH |
2826 | return 1; |
2827 | } | |
2828 | ||
2829 | return 0; | |
2830 | } | |
2831 | ||
462427c4 RS |
2832 | /* Move all labels in LABELS to the current insertion point. TEXT_P |
2833 | says whether the labels refer to text or data. */ | |
404a8071 RS |
2834 | |
2835 | static void | |
462427c4 | 2836 | mips_move_labels (struct insn_label_list *labels, bfd_boolean text_p) |
404a8071 RS |
2837 | { |
2838 | struct insn_label_list *l; | |
2839 | valueT val; | |
2840 | ||
462427c4 | 2841 | for (l = labels; l != NULL; l = l->next) |
404a8071 | 2842 | { |
9c2799c2 | 2843 | gas_assert (S_GET_SEGMENT (l->label) == now_seg); |
404a8071 RS |
2844 | symbol_set_frag (l->label, frag_now); |
2845 | val = (valueT) frag_now_fix (); | |
df58fc94 | 2846 | /* MIPS16/microMIPS text labels are stored as odd. */ |
462427c4 | 2847 | if (text_p && HAVE_CODE_COMPRESSION) |
404a8071 RS |
2848 | ++val; |
2849 | S_SET_VALUE (l->label, val); | |
2850 | } | |
2851 | } | |
2852 | ||
462427c4 RS |
2853 | /* Move all labels in insn_labels to the current insertion point |
2854 | and treat them as text labels. */ | |
2855 | ||
2856 | static void | |
2857 | mips_move_text_labels (void) | |
2858 | { | |
2859 | mips_move_labels (seg_info (now_seg)->label_list, TRUE); | |
2860 | } | |
2861 | ||
5f0fe04b TS |
2862 | static bfd_boolean |
2863 | s_is_linkonce (symbolS *sym, segT from_seg) | |
2864 | { | |
2865 | bfd_boolean linkonce = FALSE; | |
2866 | segT symseg = S_GET_SEGMENT (sym); | |
2867 | ||
2868 | if (symseg != from_seg && !S_IS_LOCAL (sym)) | |
2869 | { | |
2870 | if ((bfd_get_section_flags (stdoutput, symseg) & SEC_LINK_ONCE)) | |
2871 | linkonce = TRUE; | |
2872 | #ifdef OBJ_ELF | |
2873 | /* The GNU toolchain uses an extension for ELF: a section | |
2874 | beginning with the magic string .gnu.linkonce is a | |
2875 | linkonce section. */ | |
2876 | if (strncmp (segment_name (symseg), ".gnu.linkonce", | |
2877 | sizeof ".gnu.linkonce" - 1) == 0) | |
2878 | linkonce = TRUE; | |
2879 | #endif | |
2880 | } | |
2881 | return linkonce; | |
2882 | } | |
2883 | ||
e1b47bd5 | 2884 | /* Mark MIPS16 or microMIPS instruction label LABEL. This permits the |
df58fc94 RS |
2885 | linker to handle them specially, such as generating jalx instructions |
2886 | when needed. We also make them odd for the duration of the assembly, | |
2887 | in order to generate the right sort of code. We will make them even | |
252b5132 RH |
2888 | in the adjust_symtab routine, while leaving them marked. This is |
2889 | convenient for the debugger and the disassembler. The linker knows | |
2890 | to make them odd again. */ | |
2891 | ||
2892 | static void | |
e1b47bd5 | 2893 | mips_compressed_mark_label (symbolS *label) |
252b5132 | 2894 | { |
df58fc94 | 2895 | gas_assert (HAVE_CODE_COMPRESSION); |
a8dbcb85 | 2896 | |
a8dbcb85 | 2897 | #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF) |
e1b47bd5 RS |
2898 | if (IS_ELF) |
2899 | { | |
2900 | if (mips_opts.mips16) | |
2901 | S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label))); | |
2902 | else | |
2903 | S_SET_OTHER (label, ELF_ST_SET_MICROMIPS (S_GET_OTHER (label))); | |
252b5132 | 2904 | } |
e1b47bd5 RS |
2905 | #endif |
2906 | if ((S_GET_VALUE (label) & 1) == 0 | |
2907 | /* Don't adjust the address if the label is global or weak, or | |
2908 | in a link-once section, since we'll be emitting symbol reloc | |
2909 | references to it which will be patched up by the linker, and | |
2910 | the final value of the symbol may or may not be MIPS16/microMIPS. */ | |
2911 | && !S_IS_WEAK (label) | |
2912 | && !S_IS_EXTERNAL (label) | |
2913 | && !s_is_linkonce (label, now_seg)) | |
2914 | S_SET_VALUE (label, S_GET_VALUE (label) | 1); | |
2915 | } | |
2916 | ||
2917 | /* Mark preceding MIPS16 or microMIPS instruction labels. */ | |
2918 | ||
2919 | static void | |
2920 | mips_compressed_mark_labels (void) | |
2921 | { | |
2922 | struct insn_label_list *l; | |
2923 | ||
2924 | for (l = seg_info (now_seg)->label_list; l != NULL; l = l->next) | |
2925 | mips_compressed_mark_label (l->label); | |
252b5132 RH |
2926 | } |
2927 | ||
4d7206a2 RS |
2928 | /* End the current frag. Make it a variant frag and record the |
2929 | relaxation info. */ | |
2930 | ||
2931 | static void | |
2932 | relax_close_frag (void) | |
2933 | { | |
584892a6 | 2934 | mips_macro_warning.first_frag = frag_now; |
4d7206a2 | 2935 | frag_var (rs_machine_dependent, 0, 0, |
584892a6 | 2936 | RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]), |
4d7206a2 RS |
2937 | mips_relax.symbol, 0, (char *) mips_relax.first_fixup); |
2938 | ||
2939 | memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes)); | |
2940 | mips_relax.first_fixup = 0; | |
2941 | } | |
2942 | ||
2943 | /* Start a new relaxation sequence whose expansion depends on SYMBOL. | |
2944 | See the comment above RELAX_ENCODE for more details. */ | |
2945 | ||
2946 | static void | |
2947 | relax_start (symbolS *symbol) | |
2948 | { | |
9c2799c2 | 2949 | gas_assert (mips_relax.sequence == 0); |
4d7206a2 RS |
2950 | mips_relax.sequence = 1; |
2951 | mips_relax.symbol = symbol; | |
2952 | } | |
2953 | ||
2954 | /* Start generating the second version of a relaxable sequence. | |
2955 | See the comment above RELAX_ENCODE for more details. */ | |
252b5132 RH |
2956 | |
2957 | static void | |
4d7206a2 RS |
2958 | relax_switch (void) |
2959 | { | |
9c2799c2 | 2960 | gas_assert (mips_relax.sequence == 1); |
4d7206a2 RS |
2961 | mips_relax.sequence = 2; |
2962 | } | |
2963 | ||
2964 | /* End the current relaxable sequence. */ | |
2965 | ||
2966 | static void | |
2967 | relax_end (void) | |
2968 | { | |
9c2799c2 | 2969 | gas_assert (mips_relax.sequence == 2); |
4d7206a2 RS |
2970 | relax_close_frag (); |
2971 | mips_relax.sequence = 0; | |
2972 | } | |
2973 | ||
11625dd8 RS |
2974 | /* Return true if IP is a delayed branch or jump. */ |
2975 | ||
2976 | static inline bfd_boolean | |
2977 | delayed_branch_p (const struct mips_cl_insn *ip) | |
2978 | { | |
2979 | return (ip->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY | |
2980 | | INSN_COND_BRANCH_DELAY | |
2981 | | INSN_COND_BRANCH_LIKELY)) != 0; | |
2982 | } | |
2983 | ||
2984 | /* Return true if IP is a compact branch or jump. */ | |
2985 | ||
2986 | static inline bfd_boolean | |
2987 | compact_branch_p (const struct mips_cl_insn *ip) | |
2988 | { | |
2989 | if (mips_opts.mips16) | |
2990 | return (ip->insn_mo->pinfo & (MIPS16_INSN_UNCOND_BRANCH | |
2991 | | MIPS16_INSN_COND_BRANCH)) != 0; | |
2992 | else | |
2993 | return (ip->insn_mo->pinfo2 & (INSN2_UNCOND_BRANCH | |
2994 | | INSN2_COND_BRANCH)) != 0; | |
2995 | } | |
2996 | ||
2997 | /* Return true if IP is an unconditional branch or jump. */ | |
2998 | ||
2999 | static inline bfd_boolean | |
3000 | uncond_branch_p (const struct mips_cl_insn *ip) | |
3001 | { | |
3002 | return ((ip->insn_mo->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0 | |
3003 | || (mips_opts.mips16 | |
3004 | ? (ip->insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH) != 0 | |
3005 | : (ip->insn_mo->pinfo2 & INSN2_UNCOND_BRANCH) != 0)); | |
3006 | } | |
3007 | ||
3008 | /* Return true if IP is a branch-likely instruction. */ | |
3009 | ||
3010 | static inline bfd_boolean | |
3011 | branch_likely_p (const struct mips_cl_insn *ip) | |
3012 | { | |
3013 | return (ip->insn_mo->pinfo & INSN_COND_BRANCH_LIKELY) != 0; | |
3014 | } | |
3015 | ||
14fe068b RS |
3016 | /* Return the type of nop that should be used to fill the delay slot |
3017 | of delayed branch IP. */ | |
3018 | ||
3019 | static struct mips_cl_insn * | |
3020 | get_delay_slot_nop (const struct mips_cl_insn *ip) | |
3021 | { | |
3022 | if (mips_opts.micromips | |
3023 | && (ip->insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) | |
3024 | return µmips_nop32_insn; | |
3025 | return NOP_INSN; | |
3026 | } | |
3027 | ||
2309ddf2 | 3028 | /* Return the mask of core registers that IP reads or writes. */ |
df58fc94 RS |
3029 | |
3030 | static unsigned int | |
3031 | gpr_mod_mask (const struct mips_cl_insn *ip) | |
3032 | { | |
2309ddf2 | 3033 | unsigned long pinfo2; |
df58fc94 RS |
3034 | unsigned int mask; |
3035 | ||
3036 | mask = 0; | |
df58fc94 RS |
3037 | pinfo2 = ip->insn_mo->pinfo2; |
3038 | if (mips_opts.micromips) | |
3039 | { | |
df58fc94 RS |
3040 | if (pinfo2 & INSN2_MOD_GPR_MD) |
3041 | mask |= 1 << micromips_to_32_reg_d_map[EXTRACT_OPERAND (1, MD, *ip)]; | |
df58fc94 RS |
3042 | if (pinfo2 & INSN2_MOD_GPR_MF) |
3043 | mask |= 1 << micromips_to_32_reg_f_map[EXTRACT_OPERAND (1, MF, *ip)]; | |
df58fc94 RS |
3044 | if (pinfo2 & INSN2_MOD_SP) |
3045 | mask |= 1 << SP; | |
3046 | } | |
3047 | return mask; | |
3048 | } | |
3049 | ||
4c260379 RS |
3050 | /* Return the mask of core registers that IP reads. */ |
3051 | ||
3052 | static unsigned int | |
3053 | gpr_read_mask (const struct mips_cl_insn *ip) | |
3054 | { | |
3055 | unsigned long pinfo, pinfo2; | |
3056 | unsigned int mask; | |
3057 | ||
df58fc94 | 3058 | mask = gpr_mod_mask (ip); |
4c260379 RS |
3059 | pinfo = ip->insn_mo->pinfo; |
3060 | pinfo2 = ip->insn_mo->pinfo2; | |
3061 | if (mips_opts.mips16) | |
3062 | { | |
3063 | if (pinfo & MIPS16_INSN_READ_X) | |
3064 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)]; | |
3065 | if (pinfo & MIPS16_INSN_READ_Y) | |
3066 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)]; | |
3067 | if (pinfo & MIPS16_INSN_READ_T) | |
3068 | mask |= 1 << TREG; | |
3069 | if (pinfo & MIPS16_INSN_READ_SP) | |
3070 | mask |= 1 << SP; | |
3071 | if (pinfo & MIPS16_INSN_READ_31) | |
3072 | mask |= 1 << RA; | |
3073 | if (pinfo & MIPS16_INSN_READ_Z) | |
3074 | mask |= 1 << (mips16_to_32_reg_map | |
3075 | [MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]); | |
3076 | if (pinfo & MIPS16_INSN_READ_GPR_X) | |
3077 | mask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip); | |
3078 | } | |
3079 | else | |
3080 | { | |
3081 | if (pinfo2 & INSN2_READ_GPR_D) | |
2309ddf2 | 3082 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip); |
4c260379 | 3083 | if (pinfo & INSN_READ_GPR_T) |
2309ddf2 | 3084 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip); |
4c260379 | 3085 | if (pinfo & INSN_READ_GPR_S) |
2309ddf2 MR |
3086 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip); |
3087 | if (pinfo2 & INSN2_READ_GP) | |
3088 | mask |= 1 << GP; | |
3089 | if (pinfo2 & INSN2_READ_GPR_31) | |
3090 | mask |= 1 << RA; | |
4c260379 | 3091 | if (pinfo2 & INSN2_READ_GPR_Z) |
2309ddf2 | 3092 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip); |
4c260379 | 3093 | } |
2b0c8b40 MR |
3094 | if (mips_opts.micromips) |
3095 | { | |
3096 | if (pinfo2 & INSN2_READ_GPR_MC) | |
3097 | mask |= 1 << micromips_to_32_reg_c_map[EXTRACT_OPERAND (1, MC, *ip)]; | |
3098 | if (pinfo2 & INSN2_READ_GPR_ME) | |
3099 | mask |= 1 << micromips_to_32_reg_e_map[EXTRACT_OPERAND (1, ME, *ip)]; | |
3100 | if (pinfo2 & INSN2_READ_GPR_MG) | |
3101 | mask |= 1 << micromips_to_32_reg_g_map[EXTRACT_OPERAND (1, MG, *ip)]; | |
3102 | if (pinfo2 & INSN2_READ_GPR_MJ) | |
3103 | mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip); | |
3104 | if (pinfo2 & INSN2_READ_GPR_MMN) | |
3105 | { | |
3106 | mask |= 1 << micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)]; | |
3107 | mask |= 1 << micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)]; | |
3108 | } | |
3109 | if (pinfo2 & INSN2_READ_GPR_MP) | |
3110 | mask |= 1 << EXTRACT_OPERAND (1, MP, *ip); | |
3111 | if (pinfo2 & INSN2_READ_GPR_MQ) | |
3112 | mask |= 1 << micromips_to_32_reg_q_map[EXTRACT_OPERAND (1, MQ, *ip)]; | |
3113 | } | |
fe35f09f RS |
3114 | /* Don't include register 0. */ |
3115 | return mask & ~1; | |
4c260379 RS |
3116 | } |
3117 | ||
3118 | /* Return the mask of core registers that IP writes. */ | |
3119 | ||
3120 | static unsigned int | |
3121 | gpr_write_mask (const struct mips_cl_insn *ip) | |
3122 | { | |
3123 | unsigned long pinfo, pinfo2; | |
3124 | unsigned int mask; | |
3125 | ||
df58fc94 | 3126 | mask = gpr_mod_mask (ip); |
4c260379 RS |
3127 | pinfo = ip->insn_mo->pinfo; |
3128 | pinfo2 = ip->insn_mo->pinfo2; | |
3129 | if (mips_opts.mips16) | |
3130 | { | |
3131 | if (pinfo & MIPS16_INSN_WRITE_X) | |
3132 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)]; | |
3133 | if (pinfo & MIPS16_INSN_WRITE_Y) | |
3134 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)]; | |
3135 | if (pinfo & MIPS16_INSN_WRITE_Z) | |
3136 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RZ, *ip)]; | |
3137 | if (pinfo & MIPS16_INSN_WRITE_T) | |
3138 | mask |= 1 << TREG; | |
3139 | if (pinfo & MIPS16_INSN_WRITE_SP) | |
3140 | mask |= 1 << SP; | |
3141 | if (pinfo & MIPS16_INSN_WRITE_31) | |
3142 | mask |= 1 << RA; | |
3143 | if (pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
3144 | mask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode); | |
3145 | } | |
3146 | else | |
3147 | { | |
3148 | if (pinfo & INSN_WRITE_GPR_D) | |
df58fc94 | 3149 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip); |
4c260379 | 3150 | if (pinfo & INSN_WRITE_GPR_T) |
df58fc94 | 3151 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip); |
2b0c8b40 | 3152 | if (pinfo & INSN_WRITE_GPR_S) |
2309ddf2 | 3153 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip); |
4c260379 RS |
3154 | if (pinfo & INSN_WRITE_GPR_31) |
3155 | mask |= 1 << RA; | |
3156 | if (pinfo2 & INSN2_WRITE_GPR_Z) | |
df58fc94 | 3157 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip); |
4c260379 | 3158 | } |
2b0c8b40 MR |
3159 | if (mips_opts.micromips) |
3160 | { | |
3161 | if (pinfo2 & INSN2_WRITE_GPR_MB) | |
3162 | mask |= 1 << micromips_to_32_reg_b_map[EXTRACT_OPERAND (1, MB, *ip)]; | |
3163 | if (pinfo2 & INSN2_WRITE_GPR_MHI) | |
3164 | { | |
3165 | mask |= 1 << micromips_to_32_reg_h_map[EXTRACT_OPERAND (1, MH, *ip)]; | |
3166 | mask |= 1 << micromips_to_32_reg_i_map[EXTRACT_OPERAND (1, MI, *ip)]; | |
3167 | } | |
3168 | if (pinfo2 & INSN2_WRITE_GPR_MJ) | |
3169 | mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip); | |
3170 | if (pinfo2 & INSN2_WRITE_GPR_MP) | |
3171 | mask |= 1 << EXTRACT_OPERAND (1, MP, *ip); | |
3172 | } | |
fe35f09f RS |
3173 | /* Don't include register 0. */ |
3174 | return mask & ~1; | |
4c260379 RS |
3175 | } |
3176 | ||
3177 | /* Return the mask of floating-point registers that IP reads. */ | |
3178 | ||
3179 | static unsigned int | |
3180 | fpr_read_mask (const struct mips_cl_insn *ip) | |
3181 | { | |
3182 | unsigned long pinfo, pinfo2; | |
3183 | unsigned int mask; | |
3184 | ||
3185 | mask = 0; | |
3186 | pinfo = ip->insn_mo->pinfo; | |
3187 | pinfo2 = ip->insn_mo->pinfo2; | |
2309ddf2 | 3188 | if (!mips_opts.mips16) |
df58fc94 RS |
3189 | { |
3190 | if (pinfo2 & INSN2_READ_FPR_D) | |
2309ddf2 | 3191 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip); |
4c260379 | 3192 | if (pinfo & INSN_READ_FPR_S) |
df58fc94 | 3193 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip); |
4c260379 | 3194 | if (pinfo & INSN_READ_FPR_T) |
df58fc94 | 3195 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip); |
4c260379 | 3196 | if (pinfo & INSN_READ_FPR_R) |
df58fc94 | 3197 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FR, *ip); |
4c260379 | 3198 | if (pinfo2 & INSN2_READ_FPR_Z) |
df58fc94 | 3199 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip); |
4c260379 RS |
3200 | } |
3201 | /* Conservatively treat all operands to an FP_D instruction are doubles. | |
3202 | (This is overly pessimistic for things like cvt.d.s.) */ | |
3203 | if (HAVE_32BIT_FPRS && (pinfo & FP_D)) | |
3204 | mask |= mask << 1; | |
3205 | return mask; | |
3206 | } | |
3207 | ||
3208 | /* Return the mask of floating-point registers that IP writes. */ | |
3209 | ||
3210 | static unsigned int | |
3211 | fpr_write_mask (const struct mips_cl_insn *ip) | |
3212 | { | |
3213 | unsigned long pinfo, pinfo2; | |
3214 | unsigned int mask; | |
3215 | ||
3216 | mask = 0; | |
3217 | pinfo = ip->insn_mo->pinfo; | |
3218 | pinfo2 = ip->insn_mo->pinfo2; | |
2309ddf2 | 3219 | if (!mips_opts.mips16) |
4c260379 RS |
3220 | { |
3221 | if (pinfo & INSN_WRITE_FPR_D) | |
df58fc94 | 3222 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip); |
4c260379 | 3223 | if (pinfo & INSN_WRITE_FPR_S) |
df58fc94 | 3224 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip); |
4c260379 | 3225 | if (pinfo & INSN_WRITE_FPR_T) |
df58fc94 | 3226 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip); |
4c260379 | 3227 | if (pinfo2 & INSN2_WRITE_FPR_Z) |
df58fc94 | 3228 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip); |
4c260379 RS |
3229 | } |
3230 | /* Conservatively treat all operands to an FP_D instruction are doubles. | |
3231 | (This is overly pessimistic for things like cvt.s.d.) */ | |
3232 | if (HAVE_32BIT_FPRS && (pinfo & FP_D)) | |
3233 | mask |= mask << 1; | |
3234 | return mask; | |
3235 | } | |
3236 | ||
71400594 RS |
3237 | /* Classify an instruction according to the FIX_VR4120_* enumeration. |
3238 | Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected | |
3239 | by VR4120 errata. */ | |
4d7206a2 | 3240 | |
71400594 RS |
3241 | static unsigned int |
3242 | classify_vr4120_insn (const char *name) | |
252b5132 | 3243 | { |
71400594 RS |
3244 | if (strncmp (name, "macc", 4) == 0) |
3245 | return FIX_VR4120_MACC; | |
3246 | if (strncmp (name, "dmacc", 5) == 0) | |
3247 | return FIX_VR4120_DMACC; | |
3248 | if (strncmp (name, "mult", 4) == 0) | |
3249 | return FIX_VR4120_MULT; | |
3250 | if (strncmp (name, "dmult", 5) == 0) | |
3251 | return FIX_VR4120_DMULT; | |
3252 | if (strstr (name, "div")) | |
3253 | return FIX_VR4120_DIV; | |
3254 | if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0) | |
3255 | return FIX_VR4120_MTHILO; | |
3256 | return NUM_FIX_VR4120_CLASSES; | |
3257 | } | |
252b5132 | 3258 | |
ff239038 CM |
3259 | #define INSN_ERET 0x42000018 |
3260 | #define INSN_DERET 0x4200001f | |
3261 | ||
71400594 RS |
3262 | /* Return the number of instructions that must separate INSN1 and INSN2, |
3263 | where INSN1 is the earlier instruction. Return the worst-case value | |
3264 | for any INSN2 if INSN2 is null. */ | |
252b5132 | 3265 | |
71400594 RS |
3266 | static unsigned int |
3267 | insns_between (const struct mips_cl_insn *insn1, | |
3268 | const struct mips_cl_insn *insn2) | |
3269 | { | |
3270 | unsigned long pinfo1, pinfo2; | |
4c260379 | 3271 | unsigned int mask; |
71400594 RS |
3272 | |
3273 | /* This function needs to know which pinfo flags are set for INSN2 | |
3274 | and which registers INSN2 uses. The former is stored in PINFO2 and | |
4c260379 RS |
3275 | the latter is tested via INSN2_USES_GPR. If INSN2 is null, PINFO2 |
3276 | will have every flag set and INSN2_USES_GPR will always return true. */ | |
71400594 RS |
3277 | pinfo1 = insn1->insn_mo->pinfo; |
3278 | pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U; | |
252b5132 | 3279 | |
4c260379 RS |
3280 | #define INSN2_USES_GPR(REG) \ |
3281 | (insn2 == NULL || (gpr_read_mask (insn2) & (1U << (REG))) != 0) | |
71400594 RS |
3282 | |
3283 | /* For most targets, write-after-read dependencies on the HI and LO | |
3284 | registers must be separated by at least two instructions. */ | |
3285 | if (!hilo_interlocks) | |
252b5132 | 3286 | { |
71400594 RS |
3287 | if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO)) |
3288 | return 2; | |
3289 | if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI)) | |
3290 | return 2; | |
3291 | } | |
3292 | ||
3293 | /* If we're working around r7000 errata, there must be two instructions | |
3294 | between an mfhi or mflo and any instruction that uses the result. */ | |
3295 | if (mips_7000_hilo_fix | |
df58fc94 | 3296 | && !mips_opts.micromips |
71400594 | 3297 | && MF_HILO_INSN (pinfo1) |
df58fc94 | 3298 | && INSN2_USES_GPR (EXTRACT_OPERAND (0, RD, *insn1))) |
71400594 RS |
3299 | return 2; |
3300 | ||
ff239038 CM |
3301 | /* If we're working around 24K errata, one instruction is required |
3302 | if an ERET or DERET is followed by a branch instruction. */ | |
df58fc94 | 3303 | if (mips_fix_24k && !mips_opts.micromips) |
ff239038 CM |
3304 | { |
3305 | if (insn1->insn_opcode == INSN_ERET | |
3306 | || insn1->insn_opcode == INSN_DERET) | |
3307 | { | |
3308 | if (insn2 == NULL | |
3309 | || insn2->insn_opcode == INSN_ERET | |
3310 | || insn2->insn_opcode == INSN_DERET | |
11625dd8 | 3311 | || delayed_branch_p (insn2)) |
ff239038 CM |
3312 | return 1; |
3313 | } | |
3314 | } | |
3315 | ||
71400594 RS |
3316 | /* If working around VR4120 errata, check for combinations that need |
3317 | a single intervening instruction. */ | |
df58fc94 | 3318 | if (mips_fix_vr4120 && !mips_opts.micromips) |
71400594 RS |
3319 | { |
3320 | unsigned int class1, class2; | |
252b5132 | 3321 | |
71400594 RS |
3322 | class1 = classify_vr4120_insn (insn1->insn_mo->name); |
3323 | if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0) | |
252b5132 | 3324 | { |
71400594 RS |
3325 | if (insn2 == NULL) |
3326 | return 1; | |
3327 | class2 = classify_vr4120_insn (insn2->insn_mo->name); | |
3328 | if (vr4120_conflicts[class1] & (1 << class2)) | |
3329 | return 1; | |
252b5132 | 3330 | } |
71400594 RS |
3331 | } |
3332 | ||
df58fc94 | 3333 | if (!HAVE_CODE_COMPRESSION) |
71400594 RS |
3334 | { |
3335 | /* Check for GPR or coprocessor load delays. All such delays | |
3336 | are on the RT register. */ | |
3337 | /* Itbl support may require additional care here. */ | |
3338 | if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY)) | |
3339 | || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY))) | |
252b5132 | 3340 | { |
71400594 | 3341 | know (pinfo1 & INSN_WRITE_GPR_T); |
df58fc94 | 3342 | if (INSN2_USES_GPR (EXTRACT_OPERAND (0, RT, *insn1))) |
71400594 RS |
3343 | return 1; |
3344 | } | |
3345 | ||
3346 | /* Check for generic coprocessor hazards. | |
3347 | ||
3348 | This case is not handled very well. There is no special | |
3349 | knowledge of CP0 handling, and the coprocessors other than | |
3350 | the floating point unit are not distinguished at all. */ | |
3351 | /* Itbl support may require additional care here. FIXME! | |
3352 | Need to modify this to include knowledge about | |
3353 | user specified delays! */ | |
3354 | else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY)) | |
3355 | || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY))) | |
3356 | { | |
3357 | /* Handle cases where INSN1 writes to a known general coprocessor | |
3358 | register. There must be a one instruction delay before INSN2 | |
3359 | if INSN2 reads that register, otherwise no delay is needed. */ | |
4c260379 RS |
3360 | mask = fpr_write_mask (insn1); |
3361 | if (mask != 0) | |
252b5132 | 3362 | { |
4c260379 | 3363 | if (!insn2 || (mask & fpr_read_mask (insn2)) != 0) |
71400594 | 3364 | return 1; |
252b5132 RH |
3365 | } |
3366 | else | |
3367 | { | |
71400594 RS |
3368 | /* Read-after-write dependencies on the control registers |
3369 | require a two-instruction gap. */ | |
3370 | if ((pinfo1 & INSN_WRITE_COND_CODE) | |
3371 | && (pinfo2 & INSN_READ_COND_CODE)) | |
3372 | return 2; | |
3373 | ||
3374 | /* We don't know exactly what INSN1 does. If INSN2 is | |
3375 | also a coprocessor instruction, assume there must be | |
3376 | a one instruction gap. */ | |
3377 | if (pinfo2 & INSN_COP) | |
3378 | return 1; | |
252b5132 RH |
3379 | } |
3380 | } | |
6b76fefe | 3381 | |
71400594 RS |
3382 | /* Check for read-after-write dependencies on the coprocessor |
3383 | control registers in cases where INSN1 does not need a general | |
3384 | coprocessor delay. This means that INSN1 is a floating point | |
3385 | comparison instruction. */ | |
3386 | /* Itbl support may require additional care here. */ | |
3387 | else if (!cop_interlocks | |
3388 | && (pinfo1 & INSN_WRITE_COND_CODE) | |
3389 | && (pinfo2 & INSN_READ_COND_CODE)) | |
3390 | return 1; | |
3391 | } | |
6b76fefe | 3392 | |
4c260379 | 3393 | #undef INSN2_USES_GPR |
6b76fefe | 3394 | |
71400594 RS |
3395 | return 0; |
3396 | } | |
6b76fefe | 3397 | |
7d8e00cf RS |
3398 | /* Return the number of nops that would be needed to work around the |
3399 | VR4130 mflo/mfhi errata if instruction INSN immediately followed | |
932d1a1b RS |
3400 | the MAX_VR4130_NOPS instructions described by HIST. Ignore hazards |
3401 | that are contained within the first IGNORE instructions of HIST. */ | |
7d8e00cf RS |
3402 | |
3403 | static int | |
932d1a1b | 3404 | nops_for_vr4130 (int ignore, const struct mips_cl_insn *hist, |
7d8e00cf RS |
3405 | const struct mips_cl_insn *insn) |
3406 | { | |
4c260379 RS |
3407 | int i, j; |
3408 | unsigned int mask; | |
7d8e00cf RS |
3409 | |
3410 | /* Check if the instruction writes to HI or LO. MTHI and MTLO | |
3411 | are not affected by the errata. */ | |
3412 | if (insn != 0 | |
3413 | && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0 | |
3414 | || strcmp (insn->insn_mo->name, "mtlo") == 0 | |
3415 | || strcmp (insn->insn_mo->name, "mthi") == 0)) | |
3416 | return 0; | |
3417 | ||
3418 | /* Search for the first MFLO or MFHI. */ | |
3419 | for (i = 0; i < MAX_VR4130_NOPS; i++) | |
91d6fa6a | 3420 | if (MF_HILO_INSN (hist[i].insn_mo->pinfo)) |
7d8e00cf RS |
3421 | { |
3422 | /* Extract the destination register. */ | |
4c260379 | 3423 | mask = gpr_write_mask (&hist[i]); |
7d8e00cf RS |
3424 | |
3425 | /* No nops are needed if INSN reads that register. */ | |
4c260379 | 3426 | if (insn != NULL && (gpr_read_mask (insn) & mask) != 0) |
7d8e00cf RS |
3427 | return 0; |
3428 | ||
3429 | /* ...or if any of the intervening instructions do. */ | |
3430 | for (j = 0; j < i; j++) | |
4c260379 | 3431 | if (gpr_read_mask (&hist[j]) & mask) |
7d8e00cf RS |
3432 | return 0; |
3433 | ||
932d1a1b RS |
3434 | if (i >= ignore) |
3435 | return MAX_VR4130_NOPS - i; | |
7d8e00cf RS |
3436 | } |
3437 | return 0; | |
3438 | } | |
3439 | ||
15be625d CM |
3440 | #define BASE_REG_EQ(INSN1, INSN2) \ |
3441 | ((((INSN1) >> OP_SH_RS) & OP_MASK_RS) \ | |
3442 | == (((INSN2) >> OP_SH_RS) & OP_MASK_RS)) | |
3443 | ||
3444 | /* Return the minimum alignment for this store instruction. */ | |
3445 | ||
3446 | static int | |
3447 | fix_24k_align_to (const struct mips_opcode *mo) | |
3448 | { | |
3449 | if (strcmp (mo->name, "sh") == 0) | |
3450 | return 2; | |
3451 | ||
3452 | if (strcmp (mo->name, "swc1") == 0 | |
3453 | || strcmp (mo->name, "swc2") == 0 | |
3454 | || strcmp (mo->name, "sw") == 0 | |
3455 | || strcmp (mo->name, "sc") == 0 | |
3456 | || strcmp (mo->name, "s.s") == 0) | |
3457 | return 4; | |
3458 | ||
3459 | if (strcmp (mo->name, "sdc1") == 0 | |
3460 | || strcmp (mo->name, "sdc2") == 0 | |
3461 | || strcmp (mo->name, "s.d") == 0) | |
3462 | return 8; | |
3463 | ||
3464 | /* sb, swl, swr */ | |
3465 | return 1; | |
3466 | } | |
3467 | ||
3468 | struct fix_24k_store_info | |
3469 | { | |
3470 | /* Immediate offset, if any, for this store instruction. */ | |
3471 | short off; | |
3472 | /* Alignment required by this store instruction. */ | |
3473 | int align_to; | |
3474 | /* True for register offsets. */ | |
3475 | int register_offset; | |
3476 | }; | |
3477 | ||
3478 | /* Comparison function used by qsort. */ | |
3479 | ||
3480 | static int | |
3481 | fix_24k_sort (const void *a, const void *b) | |
3482 | { | |
3483 | const struct fix_24k_store_info *pos1 = a; | |
3484 | const struct fix_24k_store_info *pos2 = b; | |
3485 | ||
3486 | return (pos1->off - pos2->off); | |
3487 | } | |
3488 | ||
3489 | /* INSN is a store instruction. Try to record the store information | |
3490 | in STINFO. Return false if the information isn't known. */ | |
3491 | ||
3492 | static bfd_boolean | |
3493 | fix_24k_record_store_info (struct fix_24k_store_info *stinfo, | |
ab9794cf | 3494 | const struct mips_cl_insn *insn) |
15be625d CM |
3495 | { |
3496 | /* The instruction must have a known offset. */ | |
3497 | if (!insn->complete_p || !strstr (insn->insn_mo->args, "o(")) | |
3498 | return FALSE; | |
3499 | ||
3500 | stinfo->off = (insn->insn_opcode >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE; | |
3501 | stinfo->align_to = fix_24k_align_to (insn->insn_mo); | |
3502 | return TRUE; | |
3503 | } | |
3504 | ||
932d1a1b RS |
3505 | /* Return the number of nops that would be needed to work around the 24k |
3506 | "lost data on stores during refill" errata if instruction INSN | |
3507 | immediately followed the 2 instructions described by HIST. | |
3508 | Ignore hazards that are contained within the first IGNORE | |
3509 | instructions of HIST. | |
3510 | ||
3511 | Problem: The FSB (fetch store buffer) acts as an intermediate buffer | |
3512 | for the data cache refills and store data. The following describes | |
3513 | the scenario where the store data could be lost. | |
3514 | ||
3515 | * A data cache miss, due to either a load or a store, causing fill | |
3516 | data to be supplied by the memory subsystem | |
3517 | * The first three doublewords of fill data are returned and written | |
3518 | into the cache | |
3519 | * A sequence of four stores occurs in consecutive cycles around the | |
3520 | final doubleword of the fill: | |
3521 | * Store A | |
3522 | * Store B | |
3523 | * Store C | |
3524 | * Zero, One or more instructions | |
3525 | * Store D | |
3526 | ||
3527 | The four stores A-D must be to different doublewords of the line that | |
3528 | is being filled. The fourth instruction in the sequence above permits | |
3529 | the fill of the final doubleword to be transferred from the FSB into | |
3530 | the cache. In the sequence above, the stores may be either integer | |
3531 | (sb, sh, sw, swr, swl, sc) or coprocessor (swc1/swc2, sdc1/sdc2, | |
3532 | swxc1, sdxc1, suxc1) stores, as long as the four stores are to | |
3533 | different doublewords on the line. If the floating point unit is | |
3534 | running in 1:2 mode, it is not possible to create the sequence above | |
3535 | using only floating point store instructions. | |
15be625d CM |
3536 | |
3537 | In this case, the cache line being filled is incorrectly marked | |
3538 | invalid, thereby losing the data from any store to the line that | |
3539 | occurs between the original miss and the completion of the five | |
3540 | cycle sequence shown above. | |
3541 | ||
932d1a1b | 3542 | The workarounds are: |
15be625d | 3543 | |
932d1a1b RS |
3544 | * Run the data cache in write-through mode. |
3545 | * Insert a non-store instruction between | |
3546 | Store A and Store B or Store B and Store C. */ | |
15be625d CM |
3547 | |
3548 | static int | |
932d1a1b | 3549 | nops_for_24k (int ignore, const struct mips_cl_insn *hist, |
15be625d CM |
3550 | const struct mips_cl_insn *insn) |
3551 | { | |
3552 | struct fix_24k_store_info pos[3]; | |
3553 | int align, i, base_offset; | |
3554 | ||
932d1a1b RS |
3555 | if (ignore >= 2) |
3556 | return 0; | |
3557 | ||
ab9794cf RS |
3558 | /* If the previous instruction wasn't a store, there's nothing to |
3559 | worry about. */ | |
15be625d CM |
3560 | if ((hist[0].insn_mo->pinfo & INSN_STORE_MEMORY) == 0) |
3561 | return 0; | |
3562 | ||
ab9794cf RS |
3563 | /* If the instructions after the previous one are unknown, we have |
3564 | to assume the worst. */ | |
3565 | if (!insn) | |
15be625d CM |
3566 | return 1; |
3567 | ||
ab9794cf RS |
3568 | /* Check whether we are dealing with three consecutive stores. */ |
3569 | if ((insn->insn_mo->pinfo & INSN_STORE_MEMORY) == 0 | |
3570 | || (hist[1].insn_mo->pinfo & INSN_STORE_MEMORY) == 0) | |
15be625d CM |
3571 | return 0; |
3572 | ||
3573 | /* If we don't know the relationship between the store addresses, | |
3574 | assume the worst. */ | |
ab9794cf | 3575 | if (!BASE_REG_EQ (insn->insn_opcode, hist[0].insn_opcode) |
15be625d CM |
3576 | || !BASE_REG_EQ (insn->insn_opcode, hist[1].insn_opcode)) |
3577 | return 1; | |
3578 | ||
3579 | if (!fix_24k_record_store_info (&pos[0], insn) | |
3580 | || !fix_24k_record_store_info (&pos[1], &hist[0]) | |
3581 | || !fix_24k_record_store_info (&pos[2], &hist[1])) | |
3582 | return 1; | |
3583 | ||
3584 | qsort (&pos, 3, sizeof (struct fix_24k_store_info), fix_24k_sort); | |
3585 | ||
3586 | /* Pick a value of ALIGN and X such that all offsets are adjusted by | |
3587 | X bytes and such that the base register + X is known to be aligned | |
3588 | to align bytes. */ | |
3589 | ||
3590 | if (((insn->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == SP) | |
3591 | align = 8; | |
3592 | else | |
3593 | { | |
3594 | align = pos[0].align_to; | |
3595 | base_offset = pos[0].off; | |
3596 | for (i = 1; i < 3; i++) | |
3597 | if (align < pos[i].align_to) | |
3598 | { | |
3599 | align = pos[i].align_to; | |
3600 | base_offset = pos[i].off; | |
3601 | } | |
3602 | for (i = 0; i < 3; i++) | |
3603 | pos[i].off -= base_offset; | |
3604 | } | |
3605 | ||
3606 | pos[0].off &= ~align + 1; | |
3607 | pos[1].off &= ~align + 1; | |
3608 | pos[2].off &= ~align + 1; | |
3609 | ||
3610 | /* If any two stores write to the same chunk, they also write to the | |
3611 | same doubleword. The offsets are still sorted at this point. */ | |
3612 | if (pos[0].off == pos[1].off || pos[1].off == pos[2].off) | |
3613 | return 0; | |
3614 | ||
3615 | /* A range of at least 9 bytes is needed for the stores to be in | |
3616 | non-overlapping doublewords. */ | |
3617 | if (pos[2].off - pos[0].off <= 8) | |
3618 | return 0; | |
3619 | ||
3620 | if (pos[2].off - pos[1].off >= 24 | |
3621 | || pos[1].off - pos[0].off >= 24 | |
3622 | || pos[2].off - pos[0].off >= 32) | |
3623 | return 0; | |
3624 | ||
3625 | return 1; | |
3626 | } | |
3627 | ||
71400594 | 3628 | /* Return the number of nops that would be needed if instruction INSN |
91d6fa6a | 3629 | immediately followed the MAX_NOPS instructions given by HIST, |
932d1a1b RS |
3630 | where HIST[0] is the most recent instruction. Ignore hazards |
3631 | between INSN and the first IGNORE instructions in HIST. | |
3632 | ||
3633 | If INSN is null, return the worse-case number of nops for any | |
3634 | instruction. */ | |
bdaaa2e1 | 3635 | |
71400594 | 3636 | static int |
932d1a1b | 3637 | nops_for_insn (int ignore, const struct mips_cl_insn *hist, |
71400594 RS |
3638 | const struct mips_cl_insn *insn) |
3639 | { | |
3640 | int i, nops, tmp_nops; | |
bdaaa2e1 | 3641 | |
71400594 | 3642 | nops = 0; |
932d1a1b | 3643 | for (i = ignore; i < MAX_DELAY_NOPS; i++) |
65b02341 | 3644 | { |
91d6fa6a | 3645 | tmp_nops = insns_between (hist + i, insn) - i; |
65b02341 RS |
3646 | if (tmp_nops > nops) |
3647 | nops = tmp_nops; | |
3648 | } | |
7d8e00cf | 3649 | |
df58fc94 | 3650 | if (mips_fix_vr4130 && !mips_opts.micromips) |
7d8e00cf | 3651 | { |
932d1a1b | 3652 | tmp_nops = nops_for_vr4130 (ignore, hist, insn); |
7d8e00cf RS |
3653 | if (tmp_nops > nops) |
3654 | nops = tmp_nops; | |
3655 | } | |
3656 | ||
df58fc94 | 3657 | if (mips_fix_24k && !mips_opts.micromips) |
15be625d | 3658 | { |
932d1a1b | 3659 | tmp_nops = nops_for_24k (ignore, hist, insn); |
15be625d CM |
3660 | if (tmp_nops > nops) |
3661 | nops = tmp_nops; | |
3662 | } | |
3663 | ||
71400594 RS |
3664 | return nops; |
3665 | } | |
252b5132 | 3666 | |
71400594 | 3667 | /* The variable arguments provide NUM_INSNS extra instructions that |
91d6fa6a | 3668 | might be added to HIST. Return the largest number of nops that |
932d1a1b RS |
3669 | would be needed after the extended sequence, ignoring hazards |
3670 | in the first IGNORE instructions. */ | |
252b5132 | 3671 | |
71400594 | 3672 | static int |
932d1a1b RS |
3673 | nops_for_sequence (int num_insns, int ignore, |
3674 | const struct mips_cl_insn *hist, ...) | |
71400594 RS |
3675 | { |
3676 | va_list args; | |
3677 | struct mips_cl_insn buffer[MAX_NOPS]; | |
3678 | struct mips_cl_insn *cursor; | |
3679 | int nops; | |
3680 | ||
91d6fa6a | 3681 | va_start (args, hist); |
71400594 | 3682 | cursor = buffer + num_insns; |
91d6fa6a | 3683 | memcpy (cursor, hist, (MAX_NOPS - num_insns) * sizeof (*cursor)); |
71400594 RS |
3684 | while (cursor > buffer) |
3685 | *--cursor = *va_arg (args, const struct mips_cl_insn *); | |
3686 | ||
932d1a1b | 3687 | nops = nops_for_insn (ignore, buffer, NULL); |
71400594 RS |
3688 | va_end (args); |
3689 | return nops; | |
3690 | } | |
252b5132 | 3691 | |
71400594 RS |
3692 | /* Like nops_for_insn, but if INSN is a branch, take into account the |
3693 | worst-case delay for the branch target. */ | |
252b5132 | 3694 | |
71400594 | 3695 | static int |
932d1a1b | 3696 | nops_for_insn_or_target (int ignore, const struct mips_cl_insn *hist, |
71400594 RS |
3697 | const struct mips_cl_insn *insn) |
3698 | { | |
3699 | int nops, tmp_nops; | |
60b63b72 | 3700 | |
932d1a1b | 3701 | nops = nops_for_insn (ignore, hist, insn); |
11625dd8 | 3702 | if (delayed_branch_p (insn)) |
71400594 | 3703 | { |
932d1a1b | 3704 | tmp_nops = nops_for_sequence (2, ignore ? ignore + 2 : 0, |
14fe068b | 3705 | hist, insn, get_delay_slot_nop (insn)); |
71400594 RS |
3706 | if (tmp_nops > nops) |
3707 | nops = tmp_nops; | |
3708 | } | |
11625dd8 | 3709 | else if (compact_branch_p (insn)) |
71400594 | 3710 | { |
932d1a1b | 3711 | tmp_nops = nops_for_sequence (1, ignore ? ignore + 1 : 0, hist, insn); |
71400594 RS |
3712 | if (tmp_nops > nops) |
3713 | nops = tmp_nops; | |
3714 | } | |
3715 | return nops; | |
3716 | } | |
3717 | ||
c67a084a NC |
3718 | /* Fix NOP issue: Replace nops by "or at,at,zero". */ |
3719 | ||
3720 | static void | |
3721 | fix_loongson2f_nop (struct mips_cl_insn * ip) | |
3722 | { | |
df58fc94 | 3723 | gas_assert (!HAVE_CODE_COMPRESSION); |
c67a084a NC |
3724 | if (strcmp (ip->insn_mo->name, "nop") == 0) |
3725 | ip->insn_opcode = LOONGSON2F_NOP_INSN; | |
3726 | } | |
3727 | ||
3728 | /* Fix Jump Issue: Eliminate instruction fetch from outside 256M region | |
3729 | jr target pc &= 'hffff_ffff_cfff_ffff. */ | |
3730 | ||
3731 | static void | |
3732 | fix_loongson2f_jump (struct mips_cl_insn * ip) | |
3733 | { | |
df58fc94 | 3734 | gas_assert (!HAVE_CODE_COMPRESSION); |
c67a084a NC |
3735 | if (strcmp (ip->insn_mo->name, "j") == 0 |
3736 | || strcmp (ip->insn_mo->name, "jr") == 0 | |
3737 | || strcmp (ip->insn_mo->name, "jalr") == 0) | |
3738 | { | |
3739 | int sreg; | |
3740 | expressionS ep; | |
3741 | ||
3742 | if (! mips_opts.at) | |
3743 | return; | |
3744 | ||
df58fc94 | 3745 | sreg = EXTRACT_OPERAND (0, RS, *ip); |
c67a084a NC |
3746 | if (sreg == ZERO || sreg == KT0 || sreg == KT1 || sreg == ATREG) |
3747 | return; | |
3748 | ||
3749 | ep.X_op = O_constant; | |
3750 | ep.X_add_number = 0xcfff0000; | |
3751 | macro_build (&ep, "lui", "t,u", ATREG, BFD_RELOC_HI16); | |
3752 | ep.X_add_number = 0xffff; | |
3753 | macro_build (&ep, "ori", "t,r,i", ATREG, ATREG, BFD_RELOC_LO16); | |
3754 | macro_build (NULL, "and", "d,v,t", sreg, sreg, ATREG); | |
3755 | } | |
3756 | } | |
3757 | ||
3758 | static void | |
3759 | fix_loongson2f (struct mips_cl_insn * ip) | |
3760 | { | |
3761 | if (mips_fix_loongson2f_nop) | |
3762 | fix_loongson2f_nop (ip); | |
3763 | ||
3764 | if (mips_fix_loongson2f_jump) | |
3765 | fix_loongson2f_jump (ip); | |
3766 | } | |
3767 | ||
a4e06468 RS |
3768 | /* IP is a branch that has a delay slot, and we need to fill it |
3769 | automatically. Return true if we can do that by swapping IP | |
e407c74b NC |
3770 | with the previous instruction. |
3771 | ADDRESS_EXPR is an operand of the instruction to be used with | |
3772 | RELOC_TYPE. */ | |
a4e06468 RS |
3773 | |
3774 | static bfd_boolean | |
e407c74b NC |
3775 | can_swap_branch_p (struct mips_cl_insn *ip, expressionS *address_expr, |
3776 | bfd_reloc_code_real_type *reloc_type) | |
a4e06468 | 3777 | { |
2b0c8b40 | 3778 | unsigned long pinfo, pinfo2, prev_pinfo, prev_pinfo2; |
a4e06468 RS |
3779 | unsigned int gpr_read, gpr_write, prev_gpr_read, prev_gpr_write; |
3780 | ||
3781 | /* -O2 and above is required for this optimization. */ | |
3782 | if (mips_optimize < 2) | |
3783 | return FALSE; | |
3784 | ||
3785 | /* If we have seen .set volatile or .set nomove, don't optimize. */ | |
3786 | if (mips_opts.nomove) | |
3787 | return FALSE; | |
3788 | ||
3789 | /* We can't swap if the previous instruction's position is fixed. */ | |
3790 | if (history[0].fixed_p) | |
3791 | return FALSE; | |
3792 | ||
3793 | /* If the previous previous insn was in a .set noreorder, we can't | |
3794 | swap. Actually, the MIPS assembler will swap in this situation. | |
3795 | However, gcc configured -with-gnu-as will generate code like | |
3796 | ||
3797 | .set noreorder | |
3798 | lw $4,XXX | |
3799 | .set reorder | |
3800 | INSN | |
3801 | bne $4,$0,foo | |
3802 | ||
3803 | in which we can not swap the bne and INSN. If gcc is not configured | |
3804 | -with-gnu-as, it does not output the .set pseudo-ops. */ | |
3805 | if (history[1].noreorder_p) | |
3806 | return FALSE; | |
3807 | ||
87333bb7 MR |
3808 | /* If the previous instruction had a fixup in mips16 mode, we can not swap. |
3809 | This means that the previous instruction was a 4-byte one anyhow. */ | |
a4e06468 RS |
3810 | if (mips_opts.mips16 && history[0].fixp[0]) |
3811 | return FALSE; | |
3812 | ||
3813 | /* If the branch is itself the target of a branch, we can not swap. | |
3814 | We cheat on this; all we check for is whether there is a label on | |
3815 | this instruction. If there are any branches to anything other than | |
3816 | a label, users must use .set noreorder. */ | |
3817 | if (seg_info (now_seg)->label_list) | |
3818 | return FALSE; | |
3819 | ||
3820 | /* If the previous instruction is in a variant frag other than this | |
2309ddf2 | 3821 | branch's one, we cannot do the swap. This does not apply to |
9301f9c3 MR |
3822 | MIPS16 code, which uses variant frags for different purposes. */ |
3823 | if (!mips_opts.mips16 | |
a4e06468 RS |
3824 | && history[0].frag |
3825 | && history[0].frag->fr_type == rs_machine_dependent) | |
3826 | return FALSE; | |
3827 | ||
bcd530a7 RS |
3828 | /* We do not swap with instructions that cannot architecturally |
3829 | be placed in a branch delay slot, such as SYNC or ERET. We | |
3830 | also refrain from swapping with a trap instruction, since it | |
3831 | complicates trap handlers to have the trap instruction be in | |
3832 | a delay slot. */ | |
a4e06468 | 3833 | prev_pinfo = history[0].insn_mo->pinfo; |
bcd530a7 | 3834 | if (prev_pinfo & INSN_NO_DELAY_SLOT) |
a4e06468 RS |
3835 | return FALSE; |
3836 | ||
3837 | /* Check for conflicts between the branch and the instructions | |
3838 | before the candidate delay slot. */ | |
3839 | if (nops_for_insn (0, history + 1, ip) > 0) | |
3840 | return FALSE; | |
3841 | ||
3842 | /* Check for conflicts between the swapped sequence and the | |
3843 | target of the branch. */ | |
3844 | if (nops_for_sequence (2, 0, history + 1, ip, history) > 0) | |
3845 | return FALSE; | |
3846 | ||
3847 | /* If the branch reads a register that the previous | |
3848 | instruction sets, we can not swap. */ | |
3849 | gpr_read = gpr_read_mask (ip); | |
3850 | prev_gpr_write = gpr_write_mask (&history[0]); | |
3851 | if (gpr_read & prev_gpr_write) | |
3852 | return FALSE; | |
3853 | ||
3854 | /* If the branch writes a register that the previous | |
3855 | instruction sets, we can not swap. */ | |
3856 | gpr_write = gpr_write_mask (ip); | |
3857 | if (gpr_write & prev_gpr_write) | |
3858 | return FALSE; | |
3859 | ||
3860 | /* If the branch writes a register that the previous | |
3861 | instruction reads, we can not swap. */ | |
3862 | prev_gpr_read = gpr_read_mask (&history[0]); | |
3863 | if (gpr_write & prev_gpr_read) | |
3864 | return FALSE; | |
3865 | ||
3866 | /* If one instruction sets a condition code and the | |
3867 | other one uses a condition code, we can not swap. */ | |
3868 | pinfo = ip->insn_mo->pinfo; | |
3869 | if ((pinfo & INSN_READ_COND_CODE) | |
3870 | && (prev_pinfo & INSN_WRITE_COND_CODE)) | |
3871 | return FALSE; | |
3872 | if ((pinfo & INSN_WRITE_COND_CODE) | |
3873 | && (prev_pinfo & INSN_READ_COND_CODE)) | |
3874 | return FALSE; | |
3875 | ||
3876 | /* If the previous instruction uses the PC, we can not swap. */ | |
2b0c8b40 | 3877 | prev_pinfo2 = history[0].insn_mo->pinfo2; |
a4e06468 RS |
3878 | if (mips_opts.mips16 && (prev_pinfo & MIPS16_INSN_READ_PC)) |
3879 | return FALSE; | |
2b0c8b40 MR |
3880 | if (mips_opts.micromips && (prev_pinfo2 & INSN2_READ_PC)) |
3881 | return FALSE; | |
a4e06468 | 3882 | |
df58fc94 RS |
3883 | /* If the previous instruction has an incorrect size for a fixed |
3884 | branch delay slot in microMIPS mode, we cannot swap. */ | |
2309ddf2 MR |
3885 | pinfo2 = ip->insn_mo->pinfo2; |
3886 | if (mips_opts.micromips | |
3887 | && (pinfo2 & INSN2_BRANCH_DELAY_16BIT) | |
3888 | && insn_length (history) != 2) | |
3889 | return FALSE; | |
3890 | if (mips_opts.micromips | |
3891 | && (pinfo2 & INSN2_BRANCH_DELAY_32BIT) | |
3892 | && insn_length (history) != 4) | |
3893 | return FALSE; | |
3894 | ||
e407c74b NC |
3895 | /* On R5900 short loops need to be fixed by inserting a nop in |
3896 | the branch delay slots. | |
3897 | A short loop can be terminated too early. */ | |
3898 | if (mips_opts.arch == CPU_R5900 | |
3899 | /* Check if instruction has a parameter, ignore "j $31". */ | |
3900 | && (address_expr != NULL) | |
3901 | /* Parameter must be 16 bit. */ | |
3902 | && (*reloc_type == BFD_RELOC_16_PCREL_S2) | |
3903 | /* Branch to same segment. */ | |
3904 | && (S_GET_SEGMENT(address_expr->X_add_symbol) == now_seg) | |
3905 | /* Branch to same code fragment. */ | |
3906 | && (symbol_get_frag(address_expr->X_add_symbol) == frag_now) | |
3907 | /* Can only calculate branch offset if value is known. */ | |
3908 | && symbol_constant_p(address_expr->X_add_symbol) | |
3909 | /* Check if branch is really conditional. */ | |
3910 | && !((ip->insn_opcode & 0xffff0000) == 0x10000000 /* beq $0,$0 */ | |
3911 | || (ip->insn_opcode & 0xffff0000) == 0x04010000 /* bgez $0 */ | |
3912 | || (ip->insn_opcode & 0xffff0000) == 0x04110000)) /* bgezal $0 */ | |
3913 | { | |
3914 | int distance; | |
3915 | /* Check if loop is shorter than 6 instructions including | |
3916 | branch and delay slot. */ | |
3917 | distance = frag_now_fix() - S_GET_VALUE(address_expr->X_add_symbol); | |
3918 | if (distance <= 20) | |
3919 | { | |
3920 | int i; | |
3921 | int rv; | |
3922 | ||
3923 | rv = FALSE; | |
3924 | /* When the loop includes branches or jumps, | |
3925 | it is not a short loop. */ | |
3926 | for (i = 0; i < (distance / 4); i++) | |
3927 | { | |
3928 | if ((history[i].cleared_p) | |
3929 | || delayed_branch_p(&history[i])) | |
3930 | { | |
3931 | rv = TRUE; | |
3932 | break; | |
3933 | } | |
3934 | } | |
3935 | if (rv == FALSE) | |
3936 | { | |
3937 | /* Insert nop after branch to fix short loop. */ | |
3938 | return FALSE; | |
3939 | } | |
3940 | } | |
3941 | } | |
3942 | ||
a4e06468 RS |
3943 | return TRUE; |
3944 | } | |
3945 | ||
e407c74b NC |
3946 | /* Decide how we should add IP to the instruction stream. |
3947 | ADDRESS_EXPR is an operand of the instruction to be used with | |
3948 | RELOC_TYPE. */ | |
a4e06468 RS |
3949 | |
3950 | static enum append_method | |
e407c74b NC |
3951 | get_append_method (struct mips_cl_insn *ip, expressionS *address_expr, |
3952 | bfd_reloc_code_real_type *reloc_type) | |
a4e06468 RS |
3953 | { |
3954 | unsigned long pinfo; | |
3955 | ||
3956 | /* The relaxed version of a macro sequence must be inherently | |
3957 | hazard-free. */ | |
3958 | if (mips_relax.sequence == 2) | |
3959 | return APPEND_ADD; | |
3960 | ||
3961 | /* We must not dabble with instructions in a ".set norerorder" block. */ | |
3962 | if (mips_opts.noreorder) | |
3963 | return APPEND_ADD; | |
3964 | ||
3965 | /* Otherwise, it's our responsibility to fill branch delay slots. */ | |
11625dd8 | 3966 | if (delayed_branch_p (ip)) |
a4e06468 | 3967 | { |
e407c74b NC |
3968 | if (!branch_likely_p (ip) |
3969 | && can_swap_branch_p (ip, address_expr, reloc_type)) | |
a4e06468 RS |
3970 | return APPEND_SWAP; |
3971 | ||
11625dd8 | 3972 | pinfo = ip->insn_mo->pinfo; |
a4e06468 RS |
3973 | if (mips_opts.mips16 |
3974 | && ISA_SUPPORTS_MIPS16E | |
a4e06468 RS |
3975 | && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31))) |
3976 | return APPEND_ADD_COMPACT; | |
3977 | ||
3978 | return APPEND_ADD_WITH_NOP; | |
3979 | } | |
3980 | ||
a4e06468 RS |
3981 | return APPEND_ADD; |
3982 | } | |
3983 | ||
ceb94aa5 RS |
3984 | /* IP is a MIPS16 instruction whose opcode we have just changed. |
3985 | Point IP->insn_mo to the new opcode's definition. */ | |
3986 | ||
3987 | static void | |
3988 | find_altered_mips16_opcode (struct mips_cl_insn *ip) | |
3989 | { | |
3990 | const struct mips_opcode *mo, *end; | |
3991 | ||
3992 | end = &mips16_opcodes[bfd_mips16_num_opcodes]; | |
3993 | for (mo = ip->insn_mo; mo < end; mo++) | |
3994 | if ((ip->insn_opcode & mo->mask) == mo->match) | |
3995 | { | |
3996 | ip->insn_mo = mo; | |
3997 | return; | |
3998 | } | |
3999 | abort (); | |
4000 | } | |
4001 | ||
df58fc94 RS |
4002 | /* For microMIPS macros, we need to generate a local number label |
4003 | as the target of branches. */ | |
4004 | #define MICROMIPS_LABEL_CHAR '\037' | |
4005 | static unsigned long micromips_target_label; | |
4006 | static char micromips_target_name[32]; | |
4007 | ||
4008 | static char * | |
4009 | micromips_label_name (void) | |
4010 | { | |
4011 | char *p = micromips_target_name; | |
4012 | char symbol_name_temporary[24]; | |
4013 | unsigned long l; | |
4014 | int i; | |
4015 | ||
4016 | if (*p) | |
4017 | return p; | |
4018 | ||
4019 | i = 0; | |
4020 | l = micromips_target_label; | |
4021 | #ifdef LOCAL_LABEL_PREFIX | |
4022 | *p++ = LOCAL_LABEL_PREFIX; | |
4023 | #endif | |
4024 | *p++ = 'L'; | |
4025 | *p++ = MICROMIPS_LABEL_CHAR; | |
4026 | do | |
4027 | { | |
4028 | symbol_name_temporary[i++] = l % 10 + '0'; | |
4029 | l /= 10; | |
4030 | } | |
4031 | while (l != 0); | |
4032 | while (i > 0) | |
4033 | *p++ = symbol_name_temporary[--i]; | |
4034 | *p = '\0'; | |
4035 | ||
4036 | return micromips_target_name; | |
4037 | } | |
4038 | ||
4039 | static void | |
4040 | micromips_label_expr (expressionS *label_expr) | |
4041 | { | |
4042 | label_expr->X_op = O_symbol; | |
4043 | label_expr->X_add_symbol = symbol_find_or_make (micromips_label_name ()); | |
4044 | label_expr->X_add_number = 0; | |
4045 | } | |
4046 | ||
4047 | static void | |
4048 | micromips_label_inc (void) | |
4049 | { | |
4050 | micromips_target_label++; | |
4051 | *micromips_target_name = '\0'; | |
4052 | } | |
4053 | ||
4054 | static void | |
4055 | micromips_add_label (void) | |
4056 | { | |
4057 | symbolS *s; | |
4058 | ||
4059 | s = colon (micromips_label_name ()); | |
4060 | micromips_label_inc (); | |
4061 | #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF) | |
4062 | if (IS_ELF) | |
4063 | S_SET_OTHER (s, ELF_ST_SET_MICROMIPS (S_GET_OTHER (s))); | |
db9b2be4 AM |
4064 | #else |
4065 | (void) s; | |
df58fc94 RS |
4066 | #endif |
4067 | } | |
4068 | ||
4069 | /* If assembling microMIPS code, then return the microMIPS reloc | |
4070 | corresponding to the requested one if any. Otherwise return | |
4071 | the reloc unchanged. */ | |
4072 | ||
4073 | static bfd_reloc_code_real_type | |
4074 | micromips_map_reloc (bfd_reloc_code_real_type reloc) | |
4075 | { | |
4076 | static const bfd_reloc_code_real_type relocs[][2] = | |
4077 | { | |
4078 | /* Keep sorted incrementally by the left-hand key. */ | |
4079 | { BFD_RELOC_16_PCREL_S2, BFD_RELOC_MICROMIPS_16_PCREL_S1 }, | |
4080 | { BFD_RELOC_GPREL16, BFD_RELOC_MICROMIPS_GPREL16 }, | |
4081 | { BFD_RELOC_MIPS_JMP, BFD_RELOC_MICROMIPS_JMP }, | |
4082 | { BFD_RELOC_HI16, BFD_RELOC_MICROMIPS_HI16 }, | |
4083 | { BFD_RELOC_HI16_S, BFD_RELOC_MICROMIPS_HI16_S }, | |
4084 | { BFD_RELOC_LO16, BFD_RELOC_MICROMIPS_LO16 }, | |
4085 | { BFD_RELOC_MIPS_LITERAL, BFD_RELOC_MICROMIPS_LITERAL }, | |
4086 | { BFD_RELOC_MIPS_GOT16, BFD_RELOC_MICROMIPS_GOT16 }, | |
4087 | { BFD_RELOC_MIPS_CALL16, BFD_RELOC_MICROMIPS_CALL16 }, | |
4088 | { BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MICROMIPS_GOT_HI16 }, | |
4089 | { BFD_RELOC_MIPS_GOT_LO16, BFD_RELOC_MICROMIPS_GOT_LO16 }, | |
4090 | { BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MICROMIPS_CALL_HI16 }, | |
4091 | { BFD_RELOC_MIPS_CALL_LO16, BFD_RELOC_MICROMIPS_CALL_LO16 }, | |
4092 | { BFD_RELOC_MIPS_SUB, BFD_RELOC_MICROMIPS_SUB }, | |
4093 | { BFD_RELOC_MIPS_GOT_PAGE, BFD_RELOC_MICROMIPS_GOT_PAGE }, | |
4094 | { BFD_RELOC_MIPS_GOT_OFST, BFD_RELOC_MICROMIPS_GOT_OFST }, | |
4095 | { BFD_RELOC_MIPS_GOT_DISP, BFD_RELOC_MICROMIPS_GOT_DISP }, | |
4096 | { BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MICROMIPS_HIGHEST }, | |
4097 | { BFD_RELOC_MIPS_HIGHER, BFD_RELOC_MICROMIPS_HIGHER }, | |
4098 | { BFD_RELOC_MIPS_SCN_DISP, BFD_RELOC_MICROMIPS_SCN_DISP }, | |
4099 | { BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MICROMIPS_TLS_GD }, | |
4100 | { BFD_RELOC_MIPS_TLS_LDM, BFD_RELOC_MICROMIPS_TLS_LDM }, | |
4101 | { BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16 }, | |
4102 | { BFD_RELOC_MIPS_TLS_DTPREL_LO16, BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16 }, | |
4103 | { BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MICROMIPS_TLS_GOTTPREL }, | |
4104 | { BFD_RELOC_MIPS_TLS_TPREL_HI16, BFD_RELOC_MICROMIPS_TLS_TPREL_HI16 }, | |
4105 | { BFD_RELOC_MIPS_TLS_TPREL_LO16, BFD_RELOC_MICROMIPS_TLS_TPREL_LO16 } | |
4106 | }; | |
4107 | bfd_reloc_code_real_type r; | |
4108 | size_t i; | |
4109 | ||
4110 | if (!mips_opts.micromips) | |
4111 | return reloc; | |
4112 | for (i = 0; i < ARRAY_SIZE (relocs); i++) | |
4113 | { | |
4114 | r = relocs[i][0]; | |
4115 | if (r > reloc) | |
4116 | return reloc; | |
4117 | if (r == reloc) | |
4118 | return relocs[i][1]; | |
4119 | } | |
4120 | return reloc; | |
4121 | } | |
4122 | ||
b886a2ab RS |
4123 | /* Try to resolve relocation RELOC against constant OPERAND at assembly time. |
4124 | Return true on success, storing the resolved value in RESULT. */ | |
4125 | ||
4126 | static bfd_boolean | |
4127 | calculate_reloc (bfd_reloc_code_real_type reloc, offsetT operand, | |
4128 | offsetT *result) | |
4129 | { | |
4130 | switch (reloc) | |
4131 | { | |
4132 | case BFD_RELOC_MIPS_HIGHEST: | |
4133 | case BFD_RELOC_MICROMIPS_HIGHEST: | |
4134 | *result = ((operand + 0x800080008000ull) >> 48) & 0xffff; | |
4135 | return TRUE; | |
4136 | ||
4137 | case BFD_RELOC_MIPS_HIGHER: | |
4138 | case BFD_RELOC_MICROMIPS_HIGHER: | |
4139 | *result = ((operand + 0x80008000ull) >> 32) & 0xffff; | |
4140 | return TRUE; | |
4141 | ||
4142 | case BFD_RELOC_HI16_S: | |
4143 | case BFD_RELOC_MICROMIPS_HI16_S: | |
4144 | case BFD_RELOC_MIPS16_HI16_S: | |
4145 | *result = ((operand + 0x8000) >> 16) & 0xffff; | |
4146 | return TRUE; | |
4147 | ||
4148 | case BFD_RELOC_HI16: | |
4149 | case BFD_RELOC_MICROMIPS_HI16: | |
4150 | case BFD_RELOC_MIPS16_HI16: | |
4151 | *result = (operand >> 16) & 0xffff; | |
4152 | return TRUE; | |
4153 | ||
4154 | case BFD_RELOC_LO16: | |
4155 | case BFD_RELOC_MICROMIPS_LO16: | |
4156 | case BFD_RELOC_MIPS16_LO16: | |
4157 | *result = operand & 0xffff; | |
4158 | return TRUE; | |
4159 | ||
4160 | case BFD_RELOC_UNUSED: | |
4161 | *result = operand; | |
4162 | return TRUE; | |
4163 | ||
4164 | default: | |
4165 | return FALSE; | |
4166 | } | |
4167 | } | |
4168 | ||
71400594 RS |
4169 | /* Output an instruction. IP is the instruction information. |
4170 | ADDRESS_EXPR is an operand of the instruction to be used with | |
df58fc94 RS |
4171 | RELOC_TYPE. EXPANSIONP is true if the instruction is part of |
4172 | a macro expansion. */ | |
71400594 RS |
4173 | |
4174 | static void | |
4175 | append_insn (struct mips_cl_insn *ip, expressionS *address_expr, | |
df58fc94 | 4176 | bfd_reloc_code_real_type *reloc_type, bfd_boolean expansionp) |
71400594 | 4177 | { |
14fe068b | 4178 | unsigned long prev_pinfo2, pinfo; |
71400594 | 4179 | bfd_boolean relaxed_branch = FALSE; |
a4e06468 | 4180 | enum append_method method; |
2309ddf2 | 4181 | bfd_boolean relax32; |
2b0c8b40 | 4182 | int branch_disp; |
71400594 | 4183 | |
2309ddf2 | 4184 | if (mips_fix_loongson2f && !HAVE_CODE_COMPRESSION) |
c67a084a NC |
4185 | fix_loongson2f (ip); |
4186 | ||
738f4d98 | 4187 | file_ase_mips16 |= mips_opts.mips16; |
df58fc94 | 4188 | file_ase_micromips |= mips_opts.micromips; |
738f4d98 | 4189 | |
df58fc94 | 4190 | prev_pinfo2 = history[0].insn_mo->pinfo2; |
71400594 | 4191 | pinfo = ip->insn_mo->pinfo; |
df58fc94 RS |
4192 | |
4193 | if (mips_opts.micromips | |
4194 | && !expansionp | |
4195 | && (((prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 | |
4196 | && micromips_insn_length (ip->insn_mo) != 2) | |
4197 | || ((prev_pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0 | |
4198 | && micromips_insn_length (ip->insn_mo) != 4))) | |
4199 | as_warn (_("Wrong size instruction in a %u-bit branch delay slot"), | |
4200 | (prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 ? 16 : 32); | |
71400594 | 4201 | |
15be625d CM |
4202 | if (address_expr == NULL) |
4203 | ip->complete_p = 1; | |
b886a2ab RS |
4204 | else if (reloc_type[0] <= BFD_RELOC_UNUSED |
4205 | && reloc_type[1] == BFD_RELOC_UNUSED | |
4206 | && reloc_type[2] == BFD_RELOC_UNUSED | |
15be625d CM |
4207 | && address_expr->X_op == O_constant) |
4208 | { | |
15be625d CM |
4209 | switch (*reloc_type) |
4210 | { | |
15be625d | 4211 | case BFD_RELOC_MIPS_JMP: |
df58fc94 RS |
4212 | { |
4213 | int shift; | |
4214 | ||
4215 | shift = mips_opts.micromips ? 1 : 2; | |
4216 | if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0) | |
4217 | as_bad (_("jump to misaligned address (0x%lx)"), | |
4218 | (unsigned long) address_expr->X_add_number); | |
4219 | ip->insn_opcode |= ((address_expr->X_add_number >> shift) | |
4220 | & 0x3ffffff); | |
335574df | 4221 | ip->complete_p = 1; |
df58fc94 | 4222 | } |
15be625d CM |
4223 | break; |
4224 | ||
4225 | case BFD_RELOC_MIPS16_JMP: | |
4226 | if ((address_expr->X_add_number & 3) != 0) | |
4227 | as_bad (_("jump to misaligned address (0x%lx)"), | |
4228 | (unsigned long) address_expr->X_add_number); | |
4229 | ip->insn_opcode |= | |
4230 | (((address_expr->X_add_number & 0x7c0000) << 3) | |
4231 | | ((address_expr->X_add_number & 0xf800000) >> 7) | |
4232 | | ((address_expr->X_add_number & 0x3fffc) >> 2)); | |
335574df | 4233 | ip->complete_p = 1; |
15be625d CM |
4234 | break; |
4235 | ||
4236 | case BFD_RELOC_16_PCREL_S2: | |
df58fc94 RS |
4237 | { |
4238 | int shift; | |
4239 | ||
4240 | shift = mips_opts.micromips ? 1 : 2; | |
4241 | if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0) | |
4242 | as_bad (_("branch to misaligned address (0x%lx)"), | |
4243 | (unsigned long) address_expr->X_add_number); | |
4244 | if (!mips_relax_branch) | |
4245 | { | |
4246 | if ((address_expr->X_add_number + (1 << (shift + 15))) | |
4247 | & ~((1 << (shift + 16)) - 1)) | |
4248 | as_bad (_("branch address range overflow (0x%lx)"), | |
4249 | (unsigned long) address_expr->X_add_number); | |
4250 | ip->insn_opcode |= ((address_expr->X_add_number >> shift) | |
4251 | & 0xffff); | |
4252 | } | |
df58fc94 | 4253 | } |
15be625d CM |
4254 | break; |
4255 | ||
4256 | default: | |
b886a2ab RS |
4257 | { |
4258 | offsetT value; | |
4259 | ||
4260 | if (calculate_reloc (*reloc_type, address_expr->X_add_number, | |
4261 | &value)) | |
4262 | { | |
4263 | ip->insn_opcode |= value & 0xffff; | |
4264 | ip->complete_p = 1; | |
4265 | } | |
4266 | } | |
4267 | break; | |
4268 | } | |
15be625d CM |
4269 | } |
4270 | ||
71400594 RS |
4271 | if (mips_relax.sequence != 2 && !mips_opts.noreorder) |
4272 | { | |
4273 | /* There are a lot of optimizations we could do that we don't. | |
4274 | In particular, we do not, in general, reorder instructions. | |
4275 | If you use gcc with optimization, it will reorder | |
4276 | instructions and generally do much more optimization then we | |
4277 | do here; repeating all that work in the assembler would only | |
4278 | benefit hand written assembly code, and does not seem worth | |
4279 | it. */ | |
4280 | int nops = (mips_optimize == 0 | |
932d1a1b RS |
4281 | ? nops_for_insn (0, history, NULL) |
4282 | : nops_for_insn_or_target (0, history, ip)); | |
71400594 | 4283 | if (nops > 0) |
252b5132 RH |
4284 | { |
4285 | fragS *old_frag; | |
4286 | unsigned long old_frag_offset; | |
4287 | int i; | |
252b5132 RH |
4288 | |
4289 | old_frag = frag_now; | |
4290 | old_frag_offset = frag_now_fix (); | |
4291 | ||
4292 | for (i = 0; i < nops; i++) | |
14fe068b RS |
4293 | add_fixed_insn (NOP_INSN); |
4294 | insert_into_history (0, nops, NOP_INSN); | |
252b5132 RH |
4295 | |
4296 | if (listing) | |
4297 | { | |
4298 | listing_prev_line (); | |
4299 | /* We may be at the start of a variant frag. In case we | |
4300 | are, make sure there is enough space for the frag | |
4301 | after the frags created by listing_prev_line. The | |
4302 | argument to frag_grow here must be at least as large | |
4303 | as the argument to all other calls to frag_grow in | |
4304 | this file. We don't have to worry about being in the | |
4305 | middle of a variant frag, because the variants insert | |
4306 | all needed nop instructions themselves. */ | |
4307 | frag_grow (40); | |
4308 | } | |
4309 | ||
462427c4 | 4310 | mips_move_text_labels (); |
252b5132 RH |
4311 | |
4312 | #ifndef NO_ECOFF_DEBUGGING | |
4313 | if (ECOFF_DEBUGGING) | |
4314 | ecoff_fix_loc (old_frag, old_frag_offset); | |
4315 | #endif | |
4316 | } | |
71400594 RS |
4317 | } |
4318 | else if (mips_relax.sequence != 2 && prev_nop_frag != NULL) | |
4319 | { | |
932d1a1b RS |
4320 | int nops; |
4321 | ||
4322 | /* Work out how many nops in prev_nop_frag are needed by IP, | |
4323 | ignoring hazards generated by the first prev_nop_frag_since | |
4324 | instructions. */ | |
4325 | nops = nops_for_insn_or_target (prev_nop_frag_since, history, ip); | |
9c2799c2 | 4326 | gas_assert (nops <= prev_nop_frag_holds); |
252b5132 | 4327 | |
71400594 RS |
4328 | /* Enforce NOPS as a minimum. */ |
4329 | if (nops > prev_nop_frag_required) | |
4330 | prev_nop_frag_required = nops; | |
252b5132 | 4331 | |
71400594 RS |
4332 | if (prev_nop_frag_holds == prev_nop_frag_required) |
4333 | { | |
4334 | /* Settle for the current number of nops. Update the history | |
4335 | accordingly (for the benefit of any future .set reorder code). */ | |
4336 | prev_nop_frag = NULL; | |
4337 | insert_into_history (prev_nop_frag_since, | |
4338 | prev_nop_frag_holds, NOP_INSN); | |
4339 | } | |
4340 | else | |
4341 | { | |
4342 | /* Allow this instruction to replace one of the nops that was | |
4343 | tentatively added to prev_nop_frag. */ | |
df58fc94 | 4344 | prev_nop_frag->fr_fix -= NOP_INSN_SIZE; |
71400594 RS |
4345 | prev_nop_frag_holds--; |
4346 | prev_nop_frag_since++; | |
252b5132 RH |
4347 | } |
4348 | } | |
4349 | ||
e407c74b | 4350 | method = get_append_method (ip, address_expr, reloc_type); |
2b0c8b40 | 4351 | branch_disp = method == APPEND_SWAP ? insn_length (history) : 0; |
a4e06468 | 4352 | |
58e2ea4d MR |
4353 | #ifdef OBJ_ELF |
4354 | /* The value passed to dwarf2_emit_insn is the distance between | |
4355 | the beginning of the current instruction and the address that | |
e3a82c8e MR |
4356 | should be recorded in the debug tables. This is normally the |
4357 | current address. | |
4358 | ||
df58fc94 RS |
4359 | For MIPS16/microMIPS debug info we want to use ISA-encoded |
4360 | addresses, so we use -1 for an address higher by one than the | |
4361 | current one. | |
e3a82c8e MR |
4362 | |
4363 | If the instruction produced is a branch that we will swap with | |
4364 | the preceding instruction, then we add the displacement by which | |
4365 | the branch will be moved backwards. This is more appropriate | |
2309ddf2 MR |
4366 | and for MIPS16/microMIPS code also prevents a debugger from |
4367 | placing a breakpoint in the middle of the branch (and corrupting | |
4368 | code if software breakpoints are used). */ | |
2b0c8b40 | 4369 | dwarf2_emit_insn ((HAVE_CODE_COMPRESSION ? -1 : 0) + branch_disp); |
58e2ea4d MR |
4370 | #endif |
4371 | ||
df58fc94 RS |
4372 | relax32 = (mips_relax_branch |
4373 | /* Don't try branch relaxation within .set nomacro, or within | |
4374 | .set noat if we use $at for PIC computations. If it turns | |
4375 | out that the branch was out-of-range, we'll get an error. */ | |
4376 | && !mips_opts.warn_about_macros | |
4377 | && (mips_opts.at || mips_pic == NO_PIC) | |
4378 | /* Don't relax BPOSGE32/64 as they have no complementing | |
4379 | branches. */ | |
40209cad | 4380 | && !(ip->insn_mo->membership & (INSN_DSP64 | INSN_DSP))); |
df58fc94 RS |
4381 | |
4382 | if (!HAVE_CODE_COMPRESSION | |
4383 | && address_expr | |
4384 | && relax32 | |
0b25d3e6 | 4385 | && *reloc_type == BFD_RELOC_16_PCREL_S2 |
11625dd8 | 4386 | && delayed_branch_p (ip)) |
4a6a3df4 | 4387 | { |
895921c9 | 4388 | relaxed_branch = TRUE; |
1e915849 RS |
4389 | add_relaxed_insn (ip, (relaxed_branch_length |
4390 | (NULL, NULL, | |
11625dd8 RS |
4391 | uncond_branch_p (ip) ? -1 |
4392 | : branch_likely_p (ip) ? 1 | |
1e915849 RS |
4393 | : 0)), 4, |
4394 | RELAX_BRANCH_ENCODE | |
66b3e8da | 4395 | (AT, |
11625dd8 RS |
4396 | uncond_branch_p (ip), |
4397 | branch_likely_p (ip), | |
1e915849 RS |
4398 | pinfo & INSN_WRITE_GPR_31, |
4399 | 0), | |
4400 | address_expr->X_add_symbol, | |
4401 | address_expr->X_add_number); | |
4a6a3df4 AO |
4402 | *reloc_type = BFD_RELOC_UNUSED; |
4403 | } | |
df58fc94 RS |
4404 | else if (mips_opts.micromips |
4405 | && address_expr | |
4406 | && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2) | |
4407 | || *reloc_type > BFD_RELOC_UNUSED) | |
40209cad MR |
4408 | && (delayed_branch_p (ip) || compact_branch_p (ip)) |
4409 | /* Don't try branch relaxation when users specify | |
4410 | 16-bit/32-bit instructions. */ | |
4411 | && !forced_insn_length) | |
df58fc94 RS |
4412 | { |
4413 | bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED; | |
4414 | int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0; | |
11625dd8 RS |
4415 | int uncond = uncond_branch_p (ip) ? -1 : 0; |
4416 | int compact = compact_branch_p (ip); | |
df58fc94 RS |
4417 | int al = pinfo & INSN_WRITE_GPR_31; |
4418 | int length32; | |
4419 | ||
4420 | gas_assert (address_expr != NULL); | |
4421 | gas_assert (!mips_relax.sequence); | |
4422 | ||
2b0c8b40 | 4423 | relaxed_branch = TRUE; |
df58fc94 RS |
4424 | length32 = relaxed_micromips_32bit_branch_length (NULL, NULL, uncond); |
4425 | add_relaxed_insn (ip, relax32 ? length32 : 4, relax16 ? 2 : 4, | |
40209cad MR |
4426 | RELAX_MICROMIPS_ENCODE (type, AT, uncond, compact, al, |
4427 | relax32, 0, 0), | |
df58fc94 RS |
4428 | address_expr->X_add_symbol, |
4429 | address_expr->X_add_number); | |
4430 | *reloc_type = BFD_RELOC_UNUSED; | |
4431 | } | |
4432 | else if (mips_opts.mips16 && *reloc_type > BFD_RELOC_UNUSED) | |
252b5132 RH |
4433 | { |
4434 | /* We need to set up a variant frag. */ | |
df58fc94 | 4435 | gas_assert (address_expr != NULL); |
1e915849 RS |
4436 | add_relaxed_insn (ip, 4, 0, |
4437 | RELAX_MIPS16_ENCODE | |
4438 | (*reloc_type - BFD_RELOC_UNUSED, | |
df58fc94 | 4439 | forced_insn_length == 2, forced_insn_length == 4, |
11625dd8 | 4440 | delayed_branch_p (&history[0]), |
1e915849 RS |
4441 | history[0].mips16_absolute_jump_p), |
4442 | make_expr_symbol (address_expr), 0); | |
252b5132 | 4443 | } |
5c04167a | 4444 | else if (mips_opts.mips16 && insn_length (ip) == 2) |
9497f5ac | 4445 | { |
11625dd8 | 4446 | if (!delayed_branch_p (ip)) |
b8ee1a6e DU |
4447 | /* Make sure there is enough room to swap this instruction with |
4448 | a following jump instruction. */ | |
4449 | frag_grow (6); | |
1e915849 | 4450 | add_fixed_insn (ip); |
252b5132 RH |
4451 | } |
4452 | else | |
4453 | { | |
4454 | if (mips_opts.mips16 | |
4455 | && mips_opts.noreorder | |
11625dd8 | 4456 | && delayed_branch_p (&history[0])) |
252b5132 RH |
4457 | as_warn (_("extended instruction in delay slot")); |
4458 | ||
4d7206a2 RS |
4459 | if (mips_relax.sequence) |
4460 | { | |
4461 | /* If we've reached the end of this frag, turn it into a variant | |
4462 | frag and record the information for the instructions we've | |
4463 | written so far. */ | |
4464 | if (frag_room () < 4) | |
4465 | relax_close_frag (); | |
df58fc94 | 4466 | mips_relax.sizes[mips_relax.sequence - 1] += insn_length (ip); |
4d7206a2 RS |
4467 | } |
4468 | ||
584892a6 | 4469 | if (mips_relax.sequence != 2) |
df58fc94 RS |
4470 | { |
4471 | if (mips_macro_warning.first_insn_sizes[0] == 0) | |
4472 | mips_macro_warning.first_insn_sizes[0] = insn_length (ip); | |
4473 | mips_macro_warning.sizes[0] += insn_length (ip); | |
4474 | mips_macro_warning.insns[0]++; | |
4475 | } | |
584892a6 | 4476 | if (mips_relax.sequence != 1) |
df58fc94 RS |
4477 | { |
4478 | if (mips_macro_warning.first_insn_sizes[1] == 0) | |
4479 | mips_macro_warning.first_insn_sizes[1] = insn_length (ip); | |
4480 | mips_macro_warning.sizes[1] += insn_length (ip); | |
4481 | mips_macro_warning.insns[1]++; | |
4482 | } | |
584892a6 | 4483 | |
1e915849 RS |
4484 | if (mips_opts.mips16) |
4485 | { | |
4486 | ip->fixed_p = 1; | |
4487 | ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP); | |
4488 | } | |
4489 | add_fixed_insn (ip); | |
252b5132 RH |
4490 | } |
4491 | ||
9fe77896 | 4492 | if (!ip->complete_p && *reloc_type < BFD_RELOC_UNUSED) |
252b5132 | 4493 | { |
df58fc94 | 4494 | bfd_reloc_code_real_type final_type[3]; |
2309ddf2 | 4495 | reloc_howto_type *howto0; |
9fe77896 RS |
4496 | reloc_howto_type *howto; |
4497 | int i; | |
34ce925e | 4498 | |
df58fc94 RS |
4499 | /* Perform any necessary conversion to microMIPS relocations |
4500 | and find out how many relocations there actually are. */ | |
4501 | for (i = 0; i < 3 && reloc_type[i] != BFD_RELOC_UNUSED; i++) | |
4502 | final_type[i] = micromips_map_reloc (reloc_type[i]); | |
4503 | ||
9fe77896 RS |
4504 | /* In a compound relocation, it is the final (outermost) |
4505 | operator that determines the relocated field. */ | |
2309ddf2 MR |
4506 | howto = howto0 = bfd_reloc_type_lookup (stdoutput, final_type[i - 1]); |
4507 | ||
9fe77896 RS |
4508 | if (howto == NULL) |
4509 | { | |
4510 | /* To reproduce this failure try assembling gas/testsuites/ | |
4511 | gas/mips/mips16-intermix.s with a mips-ecoff targeted | |
4512 | assembler. */ | |
df58fc94 RS |
4513 | as_bad (_("Unsupported MIPS relocation number %d"), |
4514 | final_type[i - 1]); | |
9fe77896 RS |
4515 | howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16); |
4516 | } | |
2309ddf2 MR |
4517 | |
4518 | if (i > 1) | |
4519 | howto0 = bfd_reloc_type_lookup (stdoutput, final_type[0]); | |
9fe77896 RS |
4520 | ip->fixp[0] = fix_new_exp (ip->frag, ip->where, |
4521 | bfd_get_reloc_size (howto), | |
4522 | address_expr, | |
2309ddf2 MR |
4523 | howto0 && howto0->pc_relative, |
4524 | final_type[0]); | |
9fe77896 RS |
4525 | |
4526 | /* Tag symbols that have a R_MIPS16_26 relocation against them. */ | |
2309ddf2 | 4527 | if (final_type[0] == BFD_RELOC_MIPS16_JMP && ip->fixp[0]->fx_addsy) |
9fe77896 RS |
4528 | *symbol_get_tc (ip->fixp[0]->fx_addsy) = 1; |
4529 | ||
4530 | /* These relocations can have an addend that won't fit in | |
4531 | 4 octets for 64bit assembly. */ | |
4532 | if (HAVE_64BIT_GPRS | |
4533 | && ! howto->partial_inplace | |
4534 | && (reloc_type[0] == BFD_RELOC_16 | |
4535 | || reloc_type[0] == BFD_RELOC_32 | |
4536 | || reloc_type[0] == BFD_RELOC_MIPS_JMP | |
4537 | || reloc_type[0] == BFD_RELOC_GPREL16 | |
4538 | || reloc_type[0] == BFD_RELOC_MIPS_LITERAL | |
4539 | || reloc_type[0] == BFD_RELOC_GPREL32 | |
4540 | || reloc_type[0] == BFD_RELOC_64 | |
4541 | || reloc_type[0] == BFD_RELOC_CTOR | |
4542 | || reloc_type[0] == BFD_RELOC_MIPS_SUB | |
4543 | || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST | |
4544 | || reloc_type[0] == BFD_RELOC_MIPS_HIGHER | |
4545 | || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP | |
4546 | || reloc_type[0] == BFD_RELOC_MIPS_REL16 | |
4547 | || reloc_type[0] == BFD_RELOC_MIPS_RELGOT | |
4548 | || reloc_type[0] == BFD_RELOC_MIPS16_GPREL | |
4549 | || hi16_reloc_p (reloc_type[0]) | |
4550 | || lo16_reloc_p (reloc_type[0]))) | |
4551 | ip->fixp[0]->fx_no_overflow = 1; | |
4552 | ||
ddaf2c41 MR |
4553 | /* These relocations can have an addend that won't fit in 2 octets. */ |
4554 | if (reloc_type[0] == BFD_RELOC_MICROMIPS_7_PCREL_S1 | |
4555 | || reloc_type[0] == BFD_RELOC_MICROMIPS_10_PCREL_S1) | |
4556 | ip->fixp[0]->fx_no_overflow = 1; | |
4557 | ||
9fe77896 RS |
4558 | if (mips_relax.sequence) |
4559 | { | |
4560 | if (mips_relax.first_fixup == 0) | |
4561 | mips_relax.first_fixup = ip->fixp[0]; | |
4562 | } | |
4563 | else if (reloc_needs_lo_p (*reloc_type)) | |
4564 | { | |
4565 | struct mips_hi_fixup *hi_fixup; | |
4566 | ||
4567 | /* Reuse the last entry if it already has a matching %lo. */ | |
4568 | hi_fixup = mips_hi_fixup_list; | |
4569 | if (hi_fixup == 0 | |
4570 | || !fixup_has_matching_lo_p (hi_fixup->fixp)) | |
4d7206a2 | 4571 | { |
9fe77896 RS |
4572 | hi_fixup = ((struct mips_hi_fixup *) |
4573 | xmalloc (sizeof (struct mips_hi_fixup))); | |
4574 | hi_fixup->next = mips_hi_fixup_list; | |
4575 | mips_hi_fixup_list = hi_fixup; | |
4d7206a2 | 4576 | } |
9fe77896 RS |
4577 | hi_fixup->fixp = ip->fixp[0]; |
4578 | hi_fixup->seg = now_seg; | |
4579 | } | |
252b5132 | 4580 | |
9fe77896 RS |
4581 | /* Add fixups for the second and third relocations, if given. |
4582 | Note that the ABI allows the second relocation to be | |
4583 | against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the | |
4584 | moment we only use RSS_UNDEF, but we could add support | |
4585 | for the others if it ever becomes necessary. */ | |
4586 | for (i = 1; i < 3; i++) | |
4587 | if (reloc_type[i] != BFD_RELOC_UNUSED) | |
4588 | { | |
4589 | ip->fixp[i] = fix_new (ip->frag, ip->where, | |
4590 | ip->fixp[0]->fx_size, NULL, 0, | |
df58fc94 | 4591 | FALSE, final_type[i]); |
f6688943 | 4592 | |
9fe77896 RS |
4593 | /* Use fx_tcbit to mark compound relocs. */ |
4594 | ip->fixp[0]->fx_tcbit = 1; | |
4595 | ip->fixp[i]->fx_tcbit = 1; | |
4596 | } | |
252b5132 | 4597 | } |
1e915849 | 4598 | install_insn (ip); |
252b5132 RH |
4599 | |
4600 | /* Update the register mask information. */ | |
4c260379 RS |
4601 | mips_gprmask |= gpr_read_mask (ip) | gpr_write_mask (ip); |
4602 | mips_cprmask[1] |= fpr_read_mask (ip) | fpr_write_mask (ip); | |
252b5132 | 4603 | |
a4e06468 | 4604 | switch (method) |
252b5132 | 4605 | { |
a4e06468 RS |
4606 | case APPEND_ADD: |
4607 | insert_into_history (0, 1, ip); | |
4608 | break; | |
4609 | ||
4610 | case APPEND_ADD_WITH_NOP: | |
14fe068b RS |
4611 | { |
4612 | struct mips_cl_insn *nop; | |
4613 | ||
4614 | insert_into_history (0, 1, ip); | |
4615 | nop = get_delay_slot_nop (ip); | |
4616 | add_fixed_insn (nop); | |
4617 | insert_into_history (0, 1, nop); | |
4618 | if (mips_relax.sequence) | |
4619 | mips_relax.sizes[mips_relax.sequence - 1] += insn_length (nop); | |
4620 | } | |
a4e06468 RS |
4621 | break; |
4622 | ||
4623 | case APPEND_ADD_COMPACT: | |
4624 | /* Convert MIPS16 jr/jalr into a "compact" jump. */ | |
4625 | gas_assert (mips_opts.mips16); | |
4626 | ip->insn_opcode |= 0x0080; | |
4627 | find_altered_mips16_opcode (ip); | |
4628 | install_insn (ip); | |
4629 | insert_into_history (0, 1, ip); | |
4630 | break; | |
4631 | ||
4632 | case APPEND_SWAP: | |
4633 | { | |
4634 | struct mips_cl_insn delay = history[0]; | |
4635 | if (mips_opts.mips16) | |
4636 | { | |
4637 | know (delay.frag == ip->frag); | |
4638 | move_insn (ip, delay.frag, delay.where); | |
4639 | move_insn (&delay, ip->frag, ip->where + insn_length (ip)); | |
4640 | } | |
464ab0e5 | 4641 | else if (relaxed_branch || delay.frag != ip->frag) |
a4e06468 RS |
4642 | { |
4643 | /* Add the delay slot instruction to the end of the | |
4644 | current frag and shrink the fixed part of the | |
4645 | original frag. If the branch occupies the tail of | |
4646 | the latter, move it backwards to cover the gap. */ | |
2b0c8b40 | 4647 | delay.frag->fr_fix -= branch_disp; |
a4e06468 | 4648 | if (delay.frag == ip->frag) |
2b0c8b40 | 4649 | move_insn (ip, ip->frag, ip->where - branch_disp); |
a4e06468 RS |
4650 | add_fixed_insn (&delay); |
4651 | } | |
4652 | else | |
4653 | { | |
2b0c8b40 MR |
4654 | move_insn (&delay, ip->frag, |
4655 | ip->where - branch_disp + insn_length (ip)); | |
a4e06468 RS |
4656 | move_insn (ip, history[0].frag, history[0].where); |
4657 | } | |
4658 | history[0] = *ip; | |
4659 | delay.fixed_p = 1; | |
4660 | insert_into_history (0, 1, &delay); | |
4661 | } | |
4662 | break; | |
252b5132 RH |
4663 | } |
4664 | ||
13408f1e | 4665 | /* If we have just completed an unconditional branch, clear the history. */ |
11625dd8 RS |
4666 | if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1])) |
4667 | || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0]))) | |
e407c74b NC |
4668 | { |
4669 | unsigned int i; | |
4670 | ||
79850f26 | 4671 | mips_no_prev_insn (); |
13408f1e | 4672 | |
e407c74b | 4673 | for (i = 0; i < ARRAY_SIZE (history); i++) |
79850f26 | 4674 | history[i].cleared_p = 1; |
e407c74b NC |
4675 | } |
4676 | ||
df58fc94 RS |
4677 | /* We need to emit a label at the end of branch-likely macros. */ |
4678 | if (emit_branch_likely_macro) | |
4679 | { | |
4680 | emit_branch_likely_macro = FALSE; | |
4681 | micromips_add_label (); | |
4682 | } | |
4683 | ||
252b5132 RH |
4684 | /* We just output an insn, so the next one doesn't have a label. */ |
4685 | mips_clear_insn_labels (); | |
252b5132 RH |
4686 | } |
4687 | ||
e407c74b NC |
4688 | /* Forget that there was any previous instruction or label. |
4689 | When BRANCH is true, the branch history is also flushed. */ | |
252b5132 RH |
4690 | |
4691 | static void | |
7d10b47d | 4692 | mips_no_prev_insn (void) |
252b5132 | 4693 | { |
7d10b47d RS |
4694 | prev_nop_frag = NULL; |
4695 | insert_into_history (0, ARRAY_SIZE (history), NOP_INSN); | |
252b5132 RH |
4696 | mips_clear_insn_labels (); |
4697 | } | |
4698 | ||
7d10b47d RS |
4699 | /* This function must be called before we emit something other than |
4700 | instructions. It is like mips_no_prev_insn except that it inserts | |
4701 | any NOPS that might be needed by previous instructions. */ | |
252b5132 | 4702 | |
7d10b47d RS |
4703 | void |
4704 | mips_emit_delays (void) | |
252b5132 RH |
4705 | { |
4706 | if (! mips_opts.noreorder) | |
4707 | { | |
932d1a1b | 4708 | int nops = nops_for_insn (0, history, NULL); |
252b5132 RH |
4709 | if (nops > 0) |
4710 | { | |
7d10b47d RS |
4711 | while (nops-- > 0) |
4712 | add_fixed_insn (NOP_INSN); | |
462427c4 | 4713 | mips_move_text_labels (); |
7d10b47d RS |
4714 | } |
4715 | } | |
4716 | mips_no_prev_insn (); | |
4717 | } | |
4718 | ||
4719 | /* Start a (possibly nested) noreorder block. */ | |
4720 | ||
4721 | static void | |
4722 | start_noreorder (void) | |
4723 | { | |
4724 | if (mips_opts.noreorder == 0) | |
4725 | { | |
4726 | unsigned int i; | |
4727 | int nops; | |
4728 | ||
4729 | /* None of the instructions before the .set noreorder can be moved. */ | |
4730 | for (i = 0; i < ARRAY_SIZE (history); i++) | |
4731 | history[i].fixed_p = 1; | |
4732 | ||
4733 | /* Insert any nops that might be needed between the .set noreorder | |
4734 | block and the previous instructions. We will later remove any | |
4735 | nops that turn out not to be needed. */ | |
932d1a1b | 4736 | nops = nops_for_insn (0, history, NULL); |
7d10b47d RS |
4737 | if (nops > 0) |
4738 | { | |
4739 | if (mips_optimize != 0) | |
252b5132 RH |
4740 | { |
4741 | /* Record the frag which holds the nop instructions, so | |
4742 | that we can remove them if we don't need them. */ | |
df58fc94 | 4743 | frag_grow (nops * NOP_INSN_SIZE); |
252b5132 RH |
4744 | prev_nop_frag = frag_now; |
4745 | prev_nop_frag_holds = nops; | |
4746 | prev_nop_frag_required = 0; | |
4747 | prev_nop_frag_since = 0; | |
4748 | } | |
4749 | ||
4750 | for (; nops > 0; --nops) | |
1e915849 | 4751 | add_fixed_insn (NOP_INSN); |
252b5132 | 4752 | |
7d10b47d RS |
4753 | /* Move on to a new frag, so that it is safe to simply |
4754 | decrease the size of prev_nop_frag. */ | |
4755 | frag_wane (frag_now); | |
4756 | frag_new (0); | |
462427c4 | 4757 | mips_move_text_labels (); |
252b5132 | 4758 | } |
df58fc94 | 4759 | mips_mark_labels (); |
7d10b47d | 4760 | mips_clear_insn_labels (); |
252b5132 | 4761 | } |
7d10b47d RS |
4762 | mips_opts.noreorder++; |
4763 | mips_any_noreorder = 1; | |
4764 | } | |
252b5132 | 4765 | |
7d10b47d | 4766 | /* End a nested noreorder block. */ |
252b5132 | 4767 | |
7d10b47d RS |
4768 | static void |
4769 | end_noreorder (void) | |
4770 | { | |
4771 | mips_opts.noreorder--; | |
4772 | if (mips_opts.noreorder == 0 && prev_nop_frag != NULL) | |
4773 | { | |
4774 | /* Commit to inserting prev_nop_frag_required nops and go back to | |
4775 | handling nop insertion the .set reorder way. */ | |
4776 | prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required) | |
df58fc94 | 4777 | * NOP_INSN_SIZE); |
7d10b47d RS |
4778 | insert_into_history (prev_nop_frag_since, |
4779 | prev_nop_frag_required, NOP_INSN); | |
4780 | prev_nop_frag = NULL; | |
4781 | } | |
252b5132 RH |
4782 | } |
4783 | ||
584892a6 RS |
4784 | /* Set up global variables for the start of a new macro. */ |
4785 | ||
4786 | static void | |
4787 | macro_start (void) | |
4788 | { | |
4789 | memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes)); | |
df58fc94 RS |
4790 | memset (&mips_macro_warning.first_insn_sizes, 0, |
4791 | sizeof (mips_macro_warning.first_insn_sizes)); | |
4792 | memset (&mips_macro_warning.insns, 0, sizeof (mips_macro_warning.insns)); | |
584892a6 | 4793 | mips_macro_warning.delay_slot_p = (mips_opts.noreorder |
11625dd8 | 4794 | && delayed_branch_p (&history[0])); |
df58fc94 RS |
4795 | switch (history[0].insn_mo->pinfo2 |
4796 | & (INSN2_BRANCH_DELAY_32BIT | INSN2_BRANCH_DELAY_16BIT)) | |
4797 | { | |
4798 | case INSN2_BRANCH_DELAY_32BIT: | |
4799 | mips_macro_warning.delay_slot_length = 4; | |
4800 | break; | |
4801 | case INSN2_BRANCH_DELAY_16BIT: | |
4802 | mips_macro_warning.delay_slot_length = 2; | |
4803 | break; | |
4804 | default: | |
4805 | mips_macro_warning.delay_slot_length = 0; | |
4806 | break; | |
4807 | } | |
4808 | mips_macro_warning.first_frag = NULL; | |
584892a6 RS |
4809 | } |
4810 | ||
df58fc94 RS |
4811 | /* Given that a macro is longer than one instruction or of the wrong size, |
4812 | return the appropriate warning for it. Return null if no warning is | |
4813 | needed. SUBTYPE is a bitmask of RELAX_DELAY_SLOT, RELAX_DELAY_SLOT_16BIT, | |
4814 | RELAX_DELAY_SLOT_SIZE_FIRST, RELAX_DELAY_SLOT_SIZE_SECOND, | |
4815 | and RELAX_NOMACRO. */ | |
584892a6 RS |
4816 | |
4817 | static const char * | |
4818 | macro_warning (relax_substateT subtype) | |
4819 | { | |
4820 | if (subtype & RELAX_DELAY_SLOT) | |
4821 | return _("Macro instruction expanded into multiple instructions" | |
4822 | " in a branch delay slot"); | |
4823 | else if (subtype & RELAX_NOMACRO) | |
4824 | return _("Macro instruction expanded into multiple instructions"); | |
df58fc94 RS |
4825 | else if (subtype & (RELAX_DELAY_SLOT_SIZE_FIRST |
4826 | | RELAX_DELAY_SLOT_SIZE_SECOND)) | |
4827 | return ((subtype & RELAX_DELAY_SLOT_16BIT) | |
4828 | ? _("Macro instruction expanded into a wrong size instruction" | |
4829 | " in a 16-bit branch delay slot") | |
4830 | : _("Macro instruction expanded into a wrong size instruction" | |
4831 | " in a 32-bit branch delay slot")); | |
584892a6 RS |
4832 | else |
4833 | return 0; | |
4834 | } | |
4835 | ||
4836 | /* Finish up a macro. Emit warnings as appropriate. */ | |
4837 | ||
4838 | static void | |
4839 | macro_end (void) | |
4840 | { | |
df58fc94 RS |
4841 | /* Relaxation warning flags. */ |
4842 | relax_substateT subtype = 0; | |
4843 | ||
4844 | /* Check delay slot size requirements. */ | |
4845 | if (mips_macro_warning.delay_slot_length == 2) | |
4846 | subtype |= RELAX_DELAY_SLOT_16BIT; | |
4847 | if (mips_macro_warning.delay_slot_length != 0) | |
584892a6 | 4848 | { |
df58fc94 RS |
4849 | if (mips_macro_warning.delay_slot_length |
4850 | != mips_macro_warning.first_insn_sizes[0]) | |
4851 | subtype |= RELAX_DELAY_SLOT_SIZE_FIRST; | |
4852 | if (mips_macro_warning.delay_slot_length | |
4853 | != mips_macro_warning.first_insn_sizes[1]) | |
4854 | subtype |= RELAX_DELAY_SLOT_SIZE_SECOND; | |
4855 | } | |
584892a6 | 4856 | |
df58fc94 RS |
4857 | /* Check instruction count requirements. */ |
4858 | if (mips_macro_warning.insns[0] > 1 || mips_macro_warning.insns[1] > 1) | |
4859 | { | |
4860 | if (mips_macro_warning.insns[1] > mips_macro_warning.insns[0]) | |
584892a6 RS |
4861 | subtype |= RELAX_SECOND_LONGER; |
4862 | if (mips_opts.warn_about_macros) | |
4863 | subtype |= RELAX_NOMACRO; | |
4864 | if (mips_macro_warning.delay_slot_p) | |
4865 | subtype |= RELAX_DELAY_SLOT; | |
df58fc94 | 4866 | } |
584892a6 | 4867 | |
df58fc94 RS |
4868 | /* If both alternatives fail to fill a delay slot correctly, |
4869 | emit the warning now. */ | |
4870 | if ((subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0 | |
4871 | && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0) | |
4872 | { | |
4873 | relax_substateT s; | |
4874 | const char *msg; | |
4875 | ||
4876 | s = subtype & (RELAX_DELAY_SLOT_16BIT | |
4877 | | RELAX_DELAY_SLOT_SIZE_FIRST | |
4878 | | RELAX_DELAY_SLOT_SIZE_SECOND); | |
4879 | msg = macro_warning (s); | |
4880 | if (msg != NULL) | |
4881 | as_warn ("%s", msg); | |
4882 | subtype &= ~s; | |
4883 | } | |
4884 | ||
4885 | /* If both implementations are longer than 1 instruction, then emit the | |
4886 | warning now. */ | |
4887 | if (mips_macro_warning.insns[0] > 1 && mips_macro_warning.insns[1] > 1) | |
4888 | { | |
4889 | relax_substateT s; | |
4890 | const char *msg; | |
4891 | ||
4892 | s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT); | |
4893 | msg = macro_warning (s); | |
4894 | if (msg != NULL) | |
4895 | as_warn ("%s", msg); | |
4896 | subtype &= ~s; | |
584892a6 | 4897 | } |
df58fc94 RS |
4898 | |
4899 | /* If any flags still set, then one implementation might need a warning | |
4900 | and the other either will need one of a different kind or none at all. | |
4901 | Pass any remaining flags over to relaxation. */ | |
4902 | if (mips_macro_warning.first_frag != NULL) | |
4903 | mips_macro_warning.first_frag->fr_subtype |= subtype; | |
584892a6 RS |
4904 | } |
4905 | ||
df58fc94 RS |
4906 | /* Instruction operand formats used in macros that vary between |
4907 | standard MIPS and microMIPS code. */ | |
4908 | ||
4909 | static const char * const brk_fmt[2] = { "c", "mF" }; | |
4910 | static const char * const cop12_fmt[2] = { "E,o(b)", "E,~(b)" }; | |
4911 | static const char * const jalr_fmt[2] = { "d,s", "t,s" }; | |
4912 | static const char * const lui_fmt[2] = { "t,u", "s,u" }; | |
4913 | static const char * const mem12_fmt[2] = { "t,o(b)", "t,~(b)" }; | |
4914 | static const char * const mfhl_fmt[2] = { "d", "mj" }; | |
4915 | static const char * const shft_fmt[2] = { "d,w,<", "t,r,<" }; | |
4916 | static const char * const trap_fmt[2] = { "s,t,q", "s,t,|" }; | |
4917 | ||
4918 | #define BRK_FMT (brk_fmt[mips_opts.micromips]) | |
4919 | #define COP12_FMT (cop12_fmt[mips_opts.micromips]) | |
4920 | #define JALR_FMT (jalr_fmt[mips_opts.micromips]) | |
4921 | #define LUI_FMT (lui_fmt[mips_opts.micromips]) | |
4922 | #define MEM12_FMT (mem12_fmt[mips_opts.micromips]) | |
4923 | #define MFHL_FMT (mfhl_fmt[mips_opts.micromips]) | |
4924 | #define SHFT_FMT (shft_fmt[mips_opts.micromips]) | |
4925 | #define TRAP_FMT (trap_fmt[mips_opts.micromips]) | |
4926 | ||
6e1304d8 RS |
4927 | /* Read a macro's relocation codes from *ARGS and store them in *R. |
4928 | The first argument in *ARGS will be either the code for a single | |
4929 | relocation or -1 followed by the three codes that make up a | |
4930 | composite relocation. */ | |
4931 | ||
4932 | static void | |
4933 | macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r) | |
4934 | { | |
4935 | int i, next; | |
4936 | ||
4937 | next = va_arg (*args, int); | |
4938 | if (next >= 0) | |
4939 | r[0] = (bfd_reloc_code_real_type) next; | |
4940 | else | |
4941 | for (i = 0; i < 3; i++) | |
4942 | r[i] = (bfd_reloc_code_real_type) va_arg (*args, int); | |
4943 | } | |
4944 | ||
252b5132 RH |
4945 | /* Build an instruction created by a macro expansion. This is passed |
4946 | a pointer to the count of instructions created so far, an | |
4947 | expression, the name of the instruction to build, an operand format | |
4948 | string, and corresponding arguments. */ | |
4949 | ||
252b5132 | 4950 | static void |
67c0d1eb | 4951 | macro_build (expressionS *ep, const char *name, const char *fmt, ...) |
252b5132 | 4952 | { |
df58fc94 | 4953 | const struct mips_opcode *mo = NULL; |
f6688943 | 4954 | bfd_reloc_code_real_type r[3]; |
df58fc94 RS |
4955 | const struct mips_opcode *amo; |
4956 | struct hash_control *hash; | |
4957 | struct mips_cl_insn insn; | |
252b5132 | 4958 | va_list args; |
252b5132 | 4959 | |
252b5132 | 4960 | va_start (args, fmt); |
252b5132 | 4961 | |
252b5132 RH |
4962 | if (mips_opts.mips16) |
4963 | { | |
03ea81db | 4964 | mips16_macro_build (ep, name, fmt, &args); |
252b5132 RH |
4965 | va_end (args); |
4966 | return; | |
4967 | } | |
4968 | ||
f6688943 TS |
4969 | r[0] = BFD_RELOC_UNUSED; |
4970 | r[1] = BFD_RELOC_UNUSED; | |
4971 | r[2] = BFD_RELOC_UNUSED; | |
df58fc94 RS |
4972 | hash = mips_opts.micromips ? micromips_op_hash : op_hash; |
4973 | amo = (struct mips_opcode *) hash_find (hash, name); | |
4974 | gas_assert (amo); | |
4975 | gas_assert (strcmp (name, amo->name) == 0); | |
1e915849 | 4976 | |
df58fc94 | 4977 | do |
8b082fb1 TS |
4978 | { |
4979 | /* Search until we get a match for NAME. It is assumed here that | |
df58fc94 RS |
4980 | macros will never generate MDMX, MIPS-3D, or MT instructions. |
4981 | We try to match an instruction that fulfils the branch delay | |
4982 | slot instruction length requirement (if any) of the previous | |
4983 | instruction. While doing this we record the first instruction | |
4984 | seen that matches all the other conditions and use it anyway | |
4985 | if the requirement cannot be met; we will issue an appropriate | |
4986 | warning later on. */ | |
4987 | if (strcmp (fmt, amo->args) == 0 | |
4988 | && amo->pinfo != INSN_MACRO | |
4989 | && is_opcode_valid (amo) | |
4990 | && is_size_valid (amo)) | |
4991 | { | |
4992 | if (is_delay_slot_valid (amo)) | |
4993 | { | |
4994 | mo = amo; | |
4995 | break; | |
4996 | } | |
4997 | else if (!mo) | |
4998 | mo = amo; | |
4999 | } | |
8b082fb1 | 5000 | |
df58fc94 RS |
5001 | ++amo; |
5002 | gas_assert (amo->name); | |
252b5132 | 5003 | } |
df58fc94 | 5004 | while (strcmp (name, amo->name) == 0); |
252b5132 | 5005 | |
df58fc94 | 5006 | gas_assert (mo); |
1e915849 | 5007 | create_insn (&insn, mo); |
252b5132 RH |
5008 | for (;;) |
5009 | { | |
5010 | switch (*fmt++) | |
5011 | { | |
5012 | case '\0': | |
5013 | break; | |
5014 | ||
5015 | case ',': | |
5016 | case '(': | |
5017 | case ')': | |
5018 | continue; | |
5019 | ||
5f74bc13 CD |
5020 | case '+': |
5021 | switch (*fmt++) | |
5022 | { | |
5023 | case 'A': | |
5024 | case 'E': | |
df58fc94 RS |
5025 | INSERT_OPERAND (mips_opts.micromips, |
5026 | EXTLSB, insn, va_arg (args, int)); | |
5f74bc13 CD |
5027 | continue; |
5028 | ||
5029 | case 'B': | |
5030 | case 'F': | |
5031 | /* Note that in the macro case, these arguments are already | |
5032 | in MSB form. (When handling the instruction in the | |
5033 | non-macro case, these arguments are sizes from which | |
5034 | MSB values must be calculated.) */ | |
df58fc94 RS |
5035 | INSERT_OPERAND (mips_opts.micromips, |
5036 | INSMSB, insn, va_arg (args, int)); | |
5f74bc13 CD |
5037 | continue; |
5038 | ||
5039 | case 'C': | |
5040 | case 'G': | |
5041 | case 'H': | |
5042 | /* Note that in the macro case, these arguments are already | |
5043 | in MSBD form. (When handling the instruction in the | |
5044 | non-macro case, these arguments are sizes from which | |
5045 | MSBD values must be calculated.) */ | |
df58fc94 RS |
5046 | INSERT_OPERAND (mips_opts.micromips, |
5047 | EXTMSBD, insn, va_arg (args, int)); | |
5f74bc13 CD |
5048 | continue; |
5049 | ||
dd3cbb7e | 5050 | case 'Q': |
df58fc94 RS |
5051 | gas_assert (!mips_opts.micromips); |
5052 | INSERT_OPERAND (0, SEQI, insn, va_arg (args, int)); | |
dd3cbb7e NC |
5053 | continue; |
5054 | ||
5f74bc13 | 5055 | default: |
b37df7c4 | 5056 | abort (); |
5f74bc13 CD |
5057 | } |
5058 | continue; | |
5059 | ||
8b082fb1 | 5060 | case '2': |
03f66e8a | 5061 | INSERT_OPERAND (mips_opts.micromips, BP, insn, va_arg (args, int)); |
8b082fb1 TS |
5062 | continue; |
5063 | ||
df58fc94 RS |
5064 | case 'n': |
5065 | gas_assert (mips_opts.micromips); | |
252b5132 RH |
5066 | case 't': |
5067 | case 'w': | |
5068 | case 'E': | |
df58fc94 | 5069 | INSERT_OPERAND (mips_opts.micromips, RT, insn, va_arg (args, int)); |
252b5132 RH |
5070 | continue; |
5071 | ||
5072 | case 'c': | |
df58fc94 RS |
5073 | gas_assert (!mips_opts.micromips); |
5074 | INSERT_OPERAND (0, CODE, insn, va_arg (args, int)); | |
38487616 TS |
5075 | continue; |
5076 | ||
252b5132 | 5077 | case 'W': |
df58fc94 RS |
5078 | gas_assert (!mips_opts.micromips); |
5079 | case 'T': | |
5080 | INSERT_OPERAND (mips_opts.micromips, FT, insn, va_arg (args, int)); | |
252b5132 RH |
5081 | continue; |
5082 | ||
252b5132 | 5083 | case 'G': |
df58fc94 RS |
5084 | if (mips_opts.micromips) |
5085 | INSERT_OPERAND (1, RS, insn, va_arg (args, int)); | |
5086 | else | |
5087 | INSERT_OPERAND (0, RD, insn, va_arg (args, int)); | |
5088 | continue; | |
5089 | ||
af7ee8bf | 5090 | case 'K': |
df58fc94 RS |
5091 | gas_assert (!mips_opts.micromips); |
5092 | case 'd': | |
5093 | INSERT_OPERAND (mips_opts.micromips, RD, insn, va_arg (args, int)); | |
252b5132 RH |
5094 | continue; |
5095 | ||
4372b673 | 5096 | case 'U': |
df58fc94 | 5097 | gas_assert (!mips_opts.micromips); |
4372b673 NC |
5098 | { |
5099 | int tmp = va_arg (args, int); | |
5100 | ||
df58fc94 RS |
5101 | INSERT_OPERAND (0, RT, insn, tmp); |
5102 | INSERT_OPERAND (0, RD, insn, tmp); | |
4372b673 | 5103 | } |
df58fc94 | 5104 | continue; |
4372b673 | 5105 | |
252b5132 RH |
5106 | case 'V': |
5107 | case 'S': | |
df58fc94 RS |
5108 | gas_assert (!mips_opts.micromips); |
5109 | INSERT_OPERAND (0, FS, insn, va_arg (args, int)); | |
252b5132 RH |
5110 | continue; |
5111 | ||
5112 | case 'z': | |
5113 | continue; | |
5114 | ||
5115 | case '<': | |
df58fc94 RS |
5116 | INSERT_OPERAND (mips_opts.micromips, |
5117 | SHAMT, insn, va_arg (args, int)); | |
252b5132 RH |
5118 | continue; |
5119 | ||
5120 | case 'D': | |
df58fc94 RS |
5121 | gas_assert (!mips_opts.micromips); |
5122 | INSERT_OPERAND (0, FD, insn, va_arg (args, int)); | |
252b5132 RH |
5123 | continue; |
5124 | ||
5125 | case 'B': | |
df58fc94 RS |
5126 | gas_assert (!mips_opts.micromips); |
5127 | INSERT_OPERAND (0, CODE20, insn, va_arg (args, int)); | |
252b5132 RH |
5128 | continue; |
5129 | ||
4372b673 | 5130 | case 'J': |
df58fc94 RS |
5131 | gas_assert (!mips_opts.micromips); |
5132 | INSERT_OPERAND (0, CODE19, insn, va_arg (args, int)); | |
4372b673 NC |
5133 | continue; |
5134 | ||
252b5132 | 5135 | case 'q': |
df58fc94 RS |
5136 | gas_assert (!mips_opts.micromips); |
5137 | INSERT_OPERAND (0, CODE2, insn, va_arg (args, int)); | |
252b5132 RH |
5138 | continue; |
5139 | ||
5140 | case 'b': | |
5141 | case 's': | |
5142 | case 'r': | |
5143 | case 'v': | |
df58fc94 | 5144 | INSERT_OPERAND (mips_opts.micromips, RS, insn, va_arg (args, int)); |
252b5132 RH |
5145 | continue; |
5146 | ||
5147 | case 'i': | |
5148 | case 'j': | |
6e1304d8 | 5149 | macro_read_relocs (&args, r); |
9c2799c2 | 5150 | gas_assert (*r == BFD_RELOC_GPREL16 |
e391c024 RS |
5151 | || *r == BFD_RELOC_MIPS_HIGHER |
5152 | || *r == BFD_RELOC_HI16_S | |
5153 | || *r == BFD_RELOC_LO16 | |
5154 | || *r == BFD_RELOC_MIPS_GOT_OFST); | |
5155 | continue; | |
5156 | ||
5157 | case 'o': | |
5158 | macro_read_relocs (&args, r); | |
252b5132 RH |
5159 | continue; |
5160 | ||
5161 | case 'u': | |
6e1304d8 | 5162 | macro_read_relocs (&args, r); |
9c2799c2 | 5163 | gas_assert (ep != NULL |
90ecf173 MR |
5164 | && (ep->X_op == O_constant |
5165 | || (ep->X_op == O_symbol | |
5166 | && (*r == BFD_RELOC_MIPS_HIGHEST | |
5167 | || *r == BFD_RELOC_HI16_S | |
5168 | || *r == BFD_RELOC_HI16 | |
5169 | || *r == BFD_RELOC_GPREL16 | |
5170 | || *r == BFD_RELOC_MIPS_GOT_HI16 | |
5171 | || *r == BFD_RELOC_MIPS_CALL_HI16)))); | |
252b5132 RH |
5172 | continue; |
5173 | ||
5174 | case 'p': | |
9c2799c2 | 5175 | gas_assert (ep != NULL); |
bad36eac | 5176 | |
252b5132 RH |
5177 | /* |
5178 | * This allows macro() to pass an immediate expression for | |
5179 | * creating short branches without creating a symbol. | |
bad36eac DJ |
5180 | * |
5181 | * We don't allow branch relaxation for these branches, as | |
5182 | * they should only appear in ".set nomacro" anyway. | |
252b5132 RH |
5183 | */ |
5184 | if (ep->X_op == O_constant) | |
5185 | { | |
df58fc94 RS |
5186 | /* For microMIPS we always use relocations for branches. |
5187 | So we should not resolve immediate values. */ | |
5188 | gas_assert (!mips_opts.micromips); | |
5189 | ||
bad36eac DJ |
5190 | if ((ep->X_add_number & 3) != 0) |
5191 | as_bad (_("branch to misaligned address (0x%lx)"), | |
5192 | (unsigned long) ep->X_add_number); | |
5193 | if ((ep->X_add_number + 0x20000) & ~0x3ffff) | |
5194 | as_bad (_("branch address range overflow (0x%lx)"), | |
5195 | (unsigned long) ep->X_add_number); | |
252b5132 RH |
5196 | insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff; |
5197 | ep = NULL; | |
5198 | } | |
5199 | else | |
0b25d3e6 | 5200 | *r = BFD_RELOC_16_PCREL_S2; |
252b5132 RH |
5201 | continue; |
5202 | ||
5203 | case 'a': | |
9c2799c2 | 5204 | gas_assert (ep != NULL); |
f6688943 | 5205 | *r = BFD_RELOC_MIPS_JMP; |
252b5132 RH |
5206 | continue; |
5207 | ||
5208 | case 'C': | |
df58fc94 RS |
5209 | gas_assert (!mips_opts.micromips); |
5210 | INSERT_OPERAND (0, COPZ, insn, va_arg (args, unsigned long)); | |
252b5132 RH |
5211 | continue; |
5212 | ||
d43b4baf | 5213 | case 'k': |
df58fc94 RS |
5214 | INSERT_OPERAND (mips_opts.micromips, |
5215 | CACHE, insn, va_arg (args, unsigned long)); | |
5216 | continue; | |
5217 | ||
5218 | case '|': | |
5219 | gas_assert (mips_opts.micromips); | |
5220 | INSERT_OPERAND (1, TRAP, insn, va_arg (args, int)); | |
5221 | continue; | |
5222 | ||
5223 | case '.': | |
5224 | gas_assert (mips_opts.micromips); | |
5225 | INSERT_OPERAND (1, OFFSET10, insn, va_arg (args, int)); | |
5226 | continue; | |
5227 | ||
dec0624d MR |
5228 | case '\\': |
5229 | INSERT_OPERAND (mips_opts.micromips, | |
5230 | 3BITPOS, insn, va_arg (args, unsigned int)); | |
5231 | continue; | |
5232 | ||
df58fc94 | 5233 | case '~': |
dec0624d MR |
5234 | INSERT_OPERAND (mips_opts.micromips, |
5235 | OFFSET12, insn, va_arg (args, unsigned long)); | |
df58fc94 RS |
5236 | continue; |
5237 | ||
5238 | case 'N': | |
5239 | gas_assert (mips_opts.micromips); | |
5240 | INSERT_OPERAND (1, BCC, insn, va_arg (args, int)); | |
5241 | continue; | |
5242 | ||
5243 | case 'm': /* Opcode extension character. */ | |
5244 | gas_assert (mips_opts.micromips); | |
5245 | switch (*fmt++) | |
5246 | { | |
5247 | case 'j': | |
5248 | INSERT_OPERAND (1, MJ, insn, va_arg (args, int)); | |
5249 | break; | |
5250 | ||
5251 | case 'p': | |
5252 | INSERT_OPERAND (1, MP, insn, va_arg (args, int)); | |
5253 | break; | |
5254 | ||
5255 | case 'F': | |
5256 | INSERT_OPERAND (1, IMMF, insn, va_arg (args, int)); | |
5257 | break; | |
5258 | ||
5259 | default: | |
b37df7c4 | 5260 | abort (); |
df58fc94 | 5261 | } |
d43b4baf TS |
5262 | continue; |
5263 | ||
252b5132 | 5264 | default: |
b37df7c4 | 5265 | abort (); |
252b5132 RH |
5266 | } |
5267 | break; | |
5268 | } | |
5269 | va_end (args); | |
9c2799c2 | 5270 | gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
252b5132 | 5271 | |
df58fc94 | 5272 | append_insn (&insn, ep, r, TRUE); |
252b5132 RH |
5273 | } |
5274 | ||
5275 | static void | |
67c0d1eb | 5276 | mips16_macro_build (expressionS *ep, const char *name, const char *fmt, |
03ea81db | 5277 | va_list *args) |
252b5132 | 5278 | { |
1e915849 | 5279 | struct mips_opcode *mo; |
252b5132 | 5280 | struct mips_cl_insn insn; |
f6688943 TS |
5281 | bfd_reloc_code_real_type r[3] |
5282 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 | 5283 | |
1e915849 | 5284 | mo = (struct mips_opcode *) hash_find (mips16_op_hash, name); |
9c2799c2 NC |
5285 | gas_assert (mo); |
5286 | gas_assert (strcmp (name, mo->name) == 0); | |
252b5132 | 5287 | |
1e915849 | 5288 | while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO) |
252b5132 | 5289 | { |
1e915849 | 5290 | ++mo; |
9c2799c2 NC |
5291 | gas_assert (mo->name); |
5292 | gas_assert (strcmp (name, mo->name) == 0); | |
252b5132 RH |
5293 | } |
5294 | ||
1e915849 | 5295 | create_insn (&insn, mo); |
252b5132 RH |
5296 | for (;;) |
5297 | { | |
5298 | int c; | |
5299 | ||
5300 | c = *fmt++; | |
5301 | switch (c) | |
5302 | { | |
5303 | case '\0': | |
5304 | break; | |
5305 | ||
5306 | case ',': | |
5307 | case '(': | |
5308 | case ')': | |
5309 | continue; | |
5310 | ||
5311 | case 'y': | |
5312 | case 'w': | |
03ea81db | 5313 | MIPS16_INSERT_OPERAND (RY, insn, va_arg (*args, int)); |
252b5132 RH |
5314 | continue; |
5315 | ||
5316 | case 'x': | |
5317 | case 'v': | |
03ea81db | 5318 | MIPS16_INSERT_OPERAND (RX, insn, va_arg (*args, int)); |
252b5132 RH |
5319 | continue; |
5320 | ||
5321 | case 'z': | |
03ea81db | 5322 | MIPS16_INSERT_OPERAND (RZ, insn, va_arg (*args, int)); |
252b5132 RH |
5323 | continue; |
5324 | ||
5325 | case 'Z': | |
03ea81db | 5326 | MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (*args, int)); |
252b5132 RH |
5327 | continue; |
5328 | ||
5329 | case '0': | |
5330 | case 'S': | |
5331 | case 'P': | |
5332 | case 'R': | |
5333 | continue; | |
5334 | ||
5335 | case 'X': | |
03ea81db | 5336 | MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (*args, int)); |
252b5132 RH |
5337 | continue; |
5338 | ||
5339 | case 'Y': | |
5340 | { | |
5341 | int regno; | |
5342 | ||
03ea81db | 5343 | regno = va_arg (*args, int); |
252b5132 | 5344 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); |
a9e24354 | 5345 | MIPS16_INSERT_OPERAND (REG32R, insn, regno); |
252b5132 RH |
5346 | } |
5347 | continue; | |
5348 | ||
5349 | case '<': | |
5350 | case '>': | |
5351 | case '4': | |
5352 | case '5': | |
5353 | case 'H': | |
5354 | case 'W': | |
5355 | case 'D': | |
5356 | case 'j': | |
5357 | case '8': | |
5358 | case 'V': | |
5359 | case 'C': | |
5360 | case 'U': | |
5361 | case 'k': | |
5362 | case 'K': | |
5363 | case 'p': | |
5364 | case 'q': | |
5365 | { | |
b886a2ab RS |
5366 | offsetT value; |
5367 | ||
9c2799c2 | 5368 | gas_assert (ep != NULL); |
252b5132 RH |
5369 | |
5370 | if (ep->X_op != O_constant) | |
874e8986 | 5371 | *r = (int) BFD_RELOC_UNUSED + c; |
b886a2ab | 5372 | else if (calculate_reloc (*r, ep->X_add_number, &value)) |
252b5132 | 5373 | { |
b886a2ab | 5374 | mips16_immed (NULL, 0, c, *r, value, 0, &insn.insn_opcode); |
252b5132 | 5375 | ep = NULL; |
f6688943 | 5376 | *r = BFD_RELOC_UNUSED; |
252b5132 RH |
5377 | } |
5378 | } | |
5379 | continue; | |
5380 | ||
5381 | case '6': | |
03ea81db | 5382 | MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (*args, int)); |
252b5132 RH |
5383 | continue; |
5384 | } | |
5385 | ||
5386 | break; | |
5387 | } | |
5388 | ||
9c2799c2 | 5389 | gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
252b5132 | 5390 | |
df58fc94 | 5391 | append_insn (&insn, ep, r, TRUE); |
252b5132 RH |
5392 | } |
5393 | ||
2051e8c4 MR |
5394 | /* |
5395 | * Sign-extend 32-bit mode constants that have bit 31 set and all | |
5396 | * higher bits unset. | |
5397 | */ | |
9f872bbe | 5398 | static void |
2051e8c4 MR |
5399 | normalize_constant_expr (expressionS *ex) |
5400 | { | |
9ee2a2d4 | 5401 | if (ex->X_op == O_constant |
2051e8c4 MR |
5402 | && IS_ZEXT_32BIT_NUM (ex->X_add_number)) |
5403 | ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000) | |
5404 | - 0x80000000); | |
5405 | } | |
5406 | ||
5407 | /* | |
5408 | * Sign-extend 32-bit mode address offsets that have bit 31 set and | |
5409 | * all higher bits unset. | |
5410 | */ | |
5411 | static void | |
5412 | normalize_address_expr (expressionS *ex) | |
5413 | { | |
5414 | if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES) | |
5415 | || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS)) | |
5416 | && IS_ZEXT_32BIT_NUM (ex->X_add_number)) | |
5417 | ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000) | |
5418 | - 0x80000000); | |
5419 | } | |
5420 | ||
438c16b8 TS |
5421 | /* |
5422 | * Generate a "jalr" instruction with a relocation hint to the called | |
5423 | * function. This occurs in NewABI PIC code. | |
5424 | */ | |
5425 | static void | |
df58fc94 | 5426 | macro_build_jalr (expressionS *ep, int cprestore) |
438c16b8 | 5427 | { |
df58fc94 RS |
5428 | static const bfd_reloc_code_real_type jalr_relocs[2] |
5429 | = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR }; | |
5430 | bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips]; | |
5431 | const char *jalr; | |
685736be | 5432 | char *f = NULL; |
b34976b6 | 5433 | |
1180b5a4 | 5434 | if (MIPS_JALR_HINT_P (ep)) |
f21f8242 | 5435 | { |
cc3d92a5 | 5436 | frag_grow (8); |
f21f8242 AO |
5437 | f = frag_more (0); |
5438 | } | |
2906b037 | 5439 | if (mips_opts.micromips) |
df58fc94 RS |
5440 | { |
5441 | jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs"; | |
e64af278 MR |
5442 | if (MIPS_JALR_HINT_P (ep) |
5443 | || (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) | |
df58fc94 RS |
5444 | macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG); |
5445 | else | |
5446 | macro_build (NULL, jalr, "mj", PIC_CALL_REG); | |
5447 | } | |
2906b037 MR |
5448 | else |
5449 | macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG); | |
1180b5a4 | 5450 | if (MIPS_JALR_HINT_P (ep)) |
df58fc94 | 5451 | fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc); |
438c16b8 TS |
5452 | } |
5453 | ||
252b5132 RH |
5454 | /* |
5455 | * Generate a "lui" instruction. | |
5456 | */ | |
5457 | static void | |
67c0d1eb | 5458 | macro_build_lui (expressionS *ep, int regnum) |
252b5132 | 5459 | { |
9c2799c2 | 5460 | gas_assert (! mips_opts.mips16); |
252b5132 | 5461 | |
df58fc94 | 5462 | if (ep->X_op != O_constant) |
252b5132 | 5463 | { |
9c2799c2 | 5464 | gas_assert (ep->X_op == O_symbol); |
bbe506e8 TS |
5465 | /* _gp_disp is a special case, used from s_cpload. |
5466 | __gnu_local_gp is used if mips_no_shared. */ | |
9c2799c2 | 5467 | gas_assert (mips_pic == NO_PIC |
78e1bb40 | 5468 | || (! HAVE_NEWABI |
aa6975fb ILT |
5469 | && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0) |
5470 | || (! mips_in_shared | |
bbe506e8 TS |
5471 | && strcmp (S_GET_NAME (ep->X_add_symbol), |
5472 | "__gnu_local_gp") == 0)); | |
252b5132 RH |
5473 | } |
5474 | ||
df58fc94 | 5475 | macro_build (ep, "lui", LUI_FMT, regnum, BFD_RELOC_HI16_S); |
252b5132 RH |
5476 | } |
5477 | ||
885add95 CD |
5478 | /* Generate a sequence of instructions to do a load or store from a constant |
5479 | offset off of a base register (breg) into/from a target register (treg), | |
5480 | using AT if necessary. */ | |
5481 | static void | |
67c0d1eb RS |
5482 | macro_build_ldst_constoffset (expressionS *ep, const char *op, |
5483 | int treg, int breg, int dbl) | |
885add95 | 5484 | { |
9c2799c2 | 5485 | gas_assert (ep->X_op == O_constant); |
885add95 | 5486 | |
256ab948 | 5487 | /* Sign-extending 32-bit constants makes their handling easier. */ |
2051e8c4 MR |
5488 | if (!dbl) |
5489 | normalize_constant_expr (ep); | |
256ab948 | 5490 | |
67c1ffbe | 5491 | /* Right now, this routine can only handle signed 32-bit constants. */ |
ecd13cd3 | 5492 | if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000)) |
885add95 CD |
5493 | as_warn (_("operand overflow")); |
5494 | ||
5495 | if (IS_SEXT_16BIT_NUM(ep->X_add_number)) | |
5496 | { | |
5497 | /* Signed 16-bit offset will fit in the op. Easy! */ | |
67c0d1eb | 5498 | macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg); |
885add95 CD |
5499 | } |
5500 | else | |
5501 | { | |
5502 | /* 32-bit offset, need multiple instructions and AT, like: | |
5503 | lui $tempreg,const_hi (BFD_RELOC_HI16_S) | |
5504 | addu $tempreg,$tempreg,$breg | |
5505 | <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16) | |
5506 | to handle the complete offset. */ | |
67c0d1eb RS |
5507 | macro_build_lui (ep, AT); |
5508 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg); | |
5509 | macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT); | |
885add95 | 5510 | |
741fe287 | 5511 | if (!mips_opts.at) |
8fc2e39e | 5512 | as_bad (_("Macro used $at after \".set noat\"")); |
885add95 CD |
5513 | } |
5514 | } | |
5515 | ||
252b5132 RH |
5516 | /* set_at() |
5517 | * Generates code to set the $at register to true (one) | |
5518 | * if reg is less than the immediate expression. | |
5519 | */ | |
5520 | static void | |
67c0d1eb | 5521 | set_at (int reg, int unsignedp) |
252b5132 RH |
5522 | { |
5523 | if (imm_expr.X_op == O_constant | |
5524 | && imm_expr.X_add_number >= -0x8000 | |
5525 | && imm_expr.X_add_number < 0x8000) | |
67c0d1eb RS |
5526 | macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j", |
5527 | AT, reg, BFD_RELOC_LO16); | |
252b5132 RH |
5528 | else |
5529 | { | |
67c0d1eb RS |
5530 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
5531 | macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT); | |
252b5132 RH |
5532 | } |
5533 | } | |
5534 | ||
5535 | /* Warn if an expression is not a constant. */ | |
5536 | ||
5537 | static void | |
17a2f251 | 5538 | check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex) |
252b5132 RH |
5539 | { |
5540 | if (ex->X_op == O_big) | |
5541 | as_bad (_("unsupported large constant")); | |
5542 | else if (ex->X_op != O_constant) | |
9ee2a2d4 MR |
5543 | as_bad (_("Instruction %s requires absolute expression"), |
5544 | ip->insn_mo->name); | |
13757d0c | 5545 | |
9ee2a2d4 MR |
5546 | if (HAVE_32BIT_GPRS) |
5547 | normalize_constant_expr (ex); | |
252b5132 RH |
5548 | } |
5549 | ||
5550 | /* Count the leading zeroes by performing a binary chop. This is a | |
5551 | bulky bit of source, but performance is a LOT better for the | |
5552 | majority of values than a simple loop to count the bits: | |
5553 | for (lcnt = 0; (lcnt < 32); lcnt++) | |
5554 | if ((v) & (1 << (31 - lcnt))) | |
5555 | break; | |
5556 | However it is not code size friendly, and the gain will drop a bit | |
5557 | on certain cached systems. | |
5558 | */ | |
5559 | #define COUNT_TOP_ZEROES(v) \ | |
5560 | (((v) & ~0xffff) == 0 \ | |
5561 | ? ((v) & ~0xff) == 0 \ | |
5562 | ? ((v) & ~0xf) == 0 \ | |
5563 | ? ((v) & ~0x3) == 0 \ | |
5564 | ? ((v) & ~0x1) == 0 \ | |
5565 | ? !(v) \ | |
5566 | ? 32 \ | |
5567 | : 31 \ | |
5568 | : 30 \ | |
5569 | : ((v) & ~0x7) == 0 \ | |
5570 | ? 29 \ | |
5571 | : 28 \ | |
5572 | : ((v) & ~0x3f) == 0 \ | |
5573 | ? ((v) & ~0x1f) == 0 \ | |
5574 | ? 27 \ | |
5575 | : 26 \ | |
5576 | : ((v) & ~0x7f) == 0 \ | |
5577 | ? 25 \ | |
5578 | : 24 \ | |
5579 | : ((v) & ~0xfff) == 0 \ | |
5580 | ? ((v) & ~0x3ff) == 0 \ | |
5581 | ? ((v) & ~0x1ff) == 0 \ | |
5582 | ? 23 \ | |
5583 | : 22 \ | |
5584 | : ((v) & ~0x7ff) == 0 \ | |
5585 | ? 21 \ | |
5586 | : 20 \ | |
5587 | : ((v) & ~0x3fff) == 0 \ | |
5588 | ? ((v) & ~0x1fff) == 0 \ | |
5589 | ? 19 \ | |
5590 | : 18 \ | |
5591 | : ((v) & ~0x7fff) == 0 \ | |
5592 | ? 17 \ | |
5593 | : 16 \ | |
5594 | : ((v) & ~0xffffff) == 0 \ | |
5595 | ? ((v) & ~0xfffff) == 0 \ | |
5596 | ? ((v) & ~0x3ffff) == 0 \ | |
5597 | ? ((v) & ~0x1ffff) == 0 \ | |
5598 | ? 15 \ | |
5599 | : 14 \ | |
5600 | : ((v) & ~0x7ffff) == 0 \ | |
5601 | ? 13 \ | |
5602 | : 12 \ | |
5603 | : ((v) & ~0x3fffff) == 0 \ | |
5604 | ? ((v) & ~0x1fffff) == 0 \ | |
5605 | ? 11 \ | |
5606 | : 10 \ | |
5607 | : ((v) & ~0x7fffff) == 0 \ | |
5608 | ? 9 \ | |
5609 | : 8 \ | |
5610 | : ((v) & ~0xfffffff) == 0 \ | |
5611 | ? ((v) & ~0x3ffffff) == 0 \ | |
5612 | ? ((v) & ~0x1ffffff) == 0 \ | |
5613 | ? 7 \ | |
5614 | : 6 \ | |
5615 | : ((v) & ~0x7ffffff) == 0 \ | |
5616 | ? 5 \ | |
5617 | : 4 \ | |
5618 | : ((v) & ~0x3fffffff) == 0 \ | |
5619 | ? ((v) & ~0x1fffffff) == 0 \ | |
5620 | ? 3 \ | |
5621 | : 2 \ | |
5622 | : ((v) & ~0x7fffffff) == 0 \ | |
5623 | ? 1 \ | |
5624 | : 0) | |
5625 | ||
5626 | /* load_register() | |
67c1ffbe | 5627 | * This routine generates the least number of instructions necessary to load |
252b5132 RH |
5628 | * an absolute expression value into a register. |
5629 | */ | |
5630 | static void | |
67c0d1eb | 5631 | load_register (int reg, expressionS *ep, int dbl) |
252b5132 RH |
5632 | { |
5633 | int freg; | |
5634 | expressionS hi32, lo32; | |
5635 | ||
5636 | if (ep->X_op != O_big) | |
5637 | { | |
9c2799c2 | 5638 | gas_assert (ep->X_op == O_constant); |
256ab948 TS |
5639 | |
5640 | /* Sign-extending 32-bit constants makes their handling easier. */ | |
2051e8c4 MR |
5641 | if (!dbl) |
5642 | normalize_constant_expr (ep); | |
256ab948 TS |
5643 | |
5644 | if (IS_SEXT_16BIT_NUM (ep->X_add_number)) | |
252b5132 RH |
5645 | { |
5646 | /* We can handle 16 bit signed values with an addiu to | |
5647 | $zero. No need to ever use daddiu here, since $zero and | |
5648 | the result are always correct in 32 bit mode. */ | |
67c0d1eb | 5649 | macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16); |
252b5132 RH |
5650 | return; |
5651 | } | |
5652 | else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000) | |
5653 | { | |
5654 | /* We can handle 16 bit unsigned values with an ori to | |
5655 | $zero. */ | |
67c0d1eb | 5656 | macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16); |
252b5132 RH |
5657 | return; |
5658 | } | |
256ab948 | 5659 | else if ((IS_SEXT_32BIT_NUM (ep->X_add_number))) |
252b5132 RH |
5660 | { |
5661 | /* 32 bit values require an lui. */ | |
df58fc94 | 5662 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_HI16); |
252b5132 | 5663 | if ((ep->X_add_number & 0xffff) != 0) |
67c0d1eb | 5664 | macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16); |
252b5132 RH |
5665 | return; |
5666 | } | |
5667 | } | |
5668 | ||
5669 | /* The value is larger than 32 bits. */ | |
5670 | ||
2051e8c4 | 5671 | if (!dbl || HAVE_32BIT_GPRS) |
252b5132 | 5672 | { |
55e08f71 NC |
5673 | char value[32]; |
5674 | ||
5675 | sprintf_vma (value, ep->X_add_number); | |
20e1fcfd | 5676 | as_bad (_("Number (0x%s) larger than 32 bits"), value); |
67c0d1eb | 5677 | macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16); |
252b5132 RH |
5678 | return; |
5679 | } | |
5680 | ||
5681 | if (ep->X_op != O_big) | |
5682 | { | |
5683 | hi32 = *ep; | |
5684 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
5685 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
5686 | hi32.X_add_number &= 0xffffffff; | |
5687 | lo32 = *ep; | |
5688 | lo32.X_add_number &= 0xffffffff; | |
5689 | } | |
5690 | else | |
5691 | { | |
9c2799c2 | 5692 | gas_assert (ep->X_add_number > 2); |
252b5132 RH |
5693 | if (ep->X_add_number == 3) |
5694 | generic_bignum[3] = 0; | |
5695 | else if (ep->X_add_number > 4) | |
5696 | as_bad (_("Number larger than 64 bits")); | |
5697 | lo32.X_op = O_constant; | |
5698 | lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16); | |
5699 | hi32.X_op = O_constant; | |
5700 | hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16); | |
5701 | } | |
5702 | ||
5703 | if (hi32.X_add_number == 0) | |
5704 | freg = 0; | |
5705 | else | |
5706 | { | |
5707 | int shift, bit; | |
5708 | unsigned long hi, lo; | |
5709 | ||
956cd1d6 | 5710 | if (hi32.X_add_number == (offsetT) 0xffffffff) |
beae10d5 KH |
5711 | { |
5712 | if ((lo32.X_add_number & 0xffff8000) == 0xffff8000) | |
5713 | { | |
67c0d1eb | 5714 | macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16); |
beae10d5 KH |
5715 | return; |
5716 | } | |
5717 | if (lo32.X_add_number & 0x80000000) | |
5718 | { | |
df58fc94 | 5719 | macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16); |
252b5132 | 5720 | if (lo32.X_add_number & 0xffff) |
67c0d1eb | 5721 | macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16); |
beae10d5 KH |
5722 | return; |
5723 | } | |
5724 | } | |
252b5132 RH |
5725 | |
5726 | /* Check for 16bit shifted constant. We know that hi32 is | |
5727 | non-zero, so start the mask on the first bit of the hi32 | |
5728 | value. */ | |
5729 | shift = 17; | |
5730 | do | |
beae10d5 KH |
5731 | { |
5732 | unsigned long himask, lomask; | |
5733 | ||
5734 | if (shift < 32) | |
5735 | { | |
5736 | himask = 0xffff >> (32 - shift); | |
5737 | lomask = (0xffff << shift) & 0xffffffff; | |
5738 | } | |
5739 | else | |
5740 | { | |
5741 | himask = 0xffff << (shift - 32); | |
5742 | lomask = 0; | |
5743 | } | |
5744 | if ((hi32.X_add_number & ~(offsetT) himask) == 0 | |
5745 | && (lo32.X_add_number & ~(offsetT) lomask) == 0) | |
5746 | { | |
5747 | expressionS tmp; | |
5748 | ||
5749 | tmp.X_op = O_constant; | |
5750 | if (shift < 32) | |
5751 | tmp.X_add_number = ((hi32.X_add_number << (32 - shift)) | |
5752 | | (lo32.X_add_number >> shift)); | |
5753 | else | |
5754 | tmp.X_add_number = hi32.X_add_number >> (shift - 32); | |
67c0d1eb | 5755 | macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16); |
df58fc94 | 5756 | macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", SHFT_FMT, |
67c0d1eb | 5757 | reg, reg, (shift >= 32) ? shift - 32 : shift); |
beae10d5 KH |
5758 | return; |
5759 | } | |
f9419b05 | 5760 | ++shift; |
beae10d5 KH |
5761 | } |
5762 | while (shift <= (64 - 16)); | |
252b5132 RH |
5763 | |
5764 | /* Find the bit number of the lowest one bit, and store the | |
5765 | shifted value in hi/lo. */ | |
5766 | hi = (unsigned long) (hi32.X_add_number & 0xffffffff); | |
5767 | lo = (unsigned long) (lo32.X_add_number & 0xffffffff); | |
5768 | if (lo != 0) | |
5769 | { | |
5770 | bit = 0; | |
5771 | while ((lo & 1) == 0) | |
5772 | { | |
5773 | lo >>= 1; | |
5774 | ++bit; | |
5775 | } | |
5776 | lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit); | |
5777 | hi >>= bit; | |
5778 | } | |
5779 | else | |
5780 | { | |
5781 | bit = 32; | |
5782 | while ((hi & 1) == 0) | |
5783 | { | |
5784 | hi >>= 1; | |
5785 | ++bit; | |
5786 | } | |
5787 | lo = hi; | |
5788 | hi = 0; | |
5789 | } | |
5790 | ||
5791 | /* Optimize if the shifted value is a (power of 2) - 1. */ | |
5792 | if ((hi == 0 && ((lo + 1) & lo) == 0) | |
5793 | || (lo == 0xffffffff && ((hi + 1) & hi) == 0)) | |
beae10d5 KH |
5794 | { |
5795 | shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number); | |
252b5132 | 5796 | if (shift != 0) |
beae10d5 | 5797 | { |
252b5132 RH |
5798 | expressionS tmp; |
5799 | ||
5800 | /* This instruction will set the register to be all | |
5801 | ones. */ | |
beae10d5 KH |
5802 | tmp.X_op = O_constant; |
5803 | tmp.X_add_number = (offsetT) -1; | |
67c0d1eb | 5804 | macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16); |
beae10d5 KH |
5805 | if (bit != 0) |
5806 | { | |
5807 | bit += shift; | |
df58fc94 | 5808 | macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", SHFT_FMT, |
67c0d1eb | 5809 | reg, reg, (bit >= 32) ? bit - 32 : bit); |
beae10d5 | 5810 | } |
df58fc94 | 5811 | macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", SHFT_FMT, |
67c0d1eb | 5812 | reg, reg, (shift >= 32) ? shift - 32 : shift); |
beae10d5 KH |
5813 | return; |
5814 | } | |
5815 | } | |
252b5132 RH |
5816 | |
5817 | /* Sign extend hi32 before calling load_register, because we can | |
5818 | generally get better code when we load a sign extended value. */ | |
5819 | if ((hi32.X_add_number & 0x80000000) != 0) | |
beae10d5 | 5820 | hi32.X_add_number |= ~(offsetT) 0xffffffff; |
67c0d1eb | 5821 | load_register (reg, &hi32, 0); |
252b5132 RH |
5822 | freg = reg; |
5823 | } | |
5824 | if ((lo32.X_add_number & 0xffff0000) == 0) | |
5825 | { | |
5826 | if (freg != 0) | |
5827 | { | |
df58fc94 | 5828 | macro_build (NULL, "dsll32", SHFT_FMT, reg, freg, 0); |
252b5132 RH |
5829 | freg = reg; |
5830 | } | |
5831 | } | |
5832 | else | |
5833 | { | |
5834 | expressionS mid16; | |
5835 | ||
956cd1d6 | 5836 | if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff)) |
beae10d5 | 5837 | { |
df58fc94 RS |
5838 | macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16); |
5839 | macro_build (NULL, "dsrl32", SHFT_FMT, reg, reg, 0); | |
beae10d5 KH |
5840 | return; |
5841 | } | |
252b5132 RH |
5842 | |
5843 | if (freg != 0) | |
5844 | { | |
df58fc94 | 5845 | macro_build (NULL, "dsll", SHFT_FMT, reg, freg, 16); |
252b5132 RH |
5846 | freg = reg; |
5847 | } | |
5848 | mid16 = lo32; | |
5849 | mid16.X_add_number >>= 16; | |
67c0d1eb | 5850 | macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16); |
df58fc94 | 5851 | macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16); |
252b5132 RH |
5852 | freg = reg; |
5853 | } | |
5854 | if ((lo32.X_add_number & 0xffff) != 0) | |
67c0d1eb | 5855 | macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16); |
252b5132 RH |
5856 | } |
5857 | ||
269137b2 TS |
5858 | static inline void |
5859 | load_delay_nop (void) | |
5860 | { | |
5861 | if (!gpr_interlocks) | |
5862 | macro_build (NULL, "nop", ""); | |
5863 | } | |
5864 | ||
252b5132 RH |
5865 | /* Load an address into a register. */ |
5866 | ||
5867 | static void | |
67c0d1eb | 5868 | load_address (int reg, expressionS *ep, int *used_at) |
252b5132 | 5869 | { |
252b5132 RH |
5870 | if (ep->X_op != O_constant |
5871 | && ep->X_op != O_symbol) | |
5872 | { | |
5873 | as_bad (_("expression too complex")); | |
5874 | ep->X_op = O_constant; | |
5875 | } | |
5876 | ||
5877 | if (ep->X_op == O_constant) | |
5878 | { | |
67c0d1eb | 5879 | load_register (reg, ep, HAVE_64BIT_ADDRESSES); |
252b5132 RH |
5880 | return; |
5881 | } | |
5882 | ||
5883 | if (mips_pic == NO_PIC) | |
5884 | { | |
5885 | /* If this is a reference to a GP relative symbol, we want | |
cdf6fd85 | 5886 | addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 RH |
5887 | Otherwise we want |
5888 | lui $reg,<sym> (BFD_RELOC_HI16_S) | |
5889 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
d6bc6245 | 5890 | If we have an addend, we always use the latter form. |
76b3015f | 5891 | |
d6bc6245 TS |
5892 | With 64bit address space and a usable $at we want |
5893 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5894 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5895 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5896 | daddiu $at,<sym> (BFD_RELOC_LO16) | |
5897 | dsll32 $reg,0 | |
3a482fd5 | 5898 | daddu $reg,$reg,$at |
76b3015f | 5899 | |
c03099e6 | 5900 | If $at is already in use, we use a path which is suboptimal |
d6bc6245 TS |
5901 | on superscalar processors. |
5902 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5903 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5904 | dsll $reg,16 | |
5905 | daddiu $reg,<sym> (BFD_RELOC_HI16_S) | |
5906 | dsll $reg,16 | |
5907 | daddiu $reg,<sym> (BFD_RELOC_LO16) | |
6caf9ef4 TS |
5908 | |
5909 | For GP relative symbols in 64bit address space we can use | |
5910 | the same sequence as in 32bit address space. */ | |
aed1a261 | 5911 | if (HAVE_64BIT_SYMBOLS) |
d6bc6245 | 5912 | { |
6caf9ef4 TS |
5913 | if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET |
5914 | && !nopic_need_relax (ep->X_add_symbol, 1)) | |
5915 | { | |
5916 | relax_start (ep->X_add_symbol); | |
5917 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, | |
5918 | mips_gp_register, BFD_RELOC_GPREL16); | |
5919 | relax_switch (); | |
5920 | } | |
d6bc6245 | 5921 | |
741fe287 | 5922 | if (*used_at == 0 && mips_opts.at) |
d6bc6245 | 5923 | { |
df58fc94 RS |
5924 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST); |
5925 | macro_build (ep, "lui", LUI_FMT, AT, BFD_RELOC_HI16_S); | |
67c0d1eb RS |
5926 | macro_build (ep, "daddiu", "t,r,j", reg, reg, |
5927 | BFD_RELOC_MIPS_HIGHER); | |
5928 | macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16); | |
df58fc94 | 5929 | macro_build (NULL, "dsll32", SHFT_FMT, reg, reg, 0); |
67c0d1eb | 5930 | macro_build (NULL, "daddu", "d,v,t", reg, reg, AT); |
d6bc6245 TS |
5931 | *used_at = 1; |
5932 | } | |
5933 | else | |
5934 | { | |
df58fc94 | 5935 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST); |
67c0d1eb RS |
5936 | macro_build (ep, "daddiu", "t,r,j", reg, reg, |
5937 | BFD_RELOC_MIPS_HIGHER); | |
df58fc94 | 5938 | macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16); |
67c0d1eb | 5939 | macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S); |
df58fc94 | 5940 | macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16); |
67c0d1eb | 5941 | macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16); |
d6bc6245 | 5942 | } |
6caf9ef4 TS |
5943 | |
5944 | if (mips_relax.sequence) | |
5945 | relax_end (); | |
d6bc6245 | 5946 | } |
252b5132 RH |
5947 | else |
5948 | { | |
d6bc6245 | 5949 | if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET |
6caf9ef4 | 5950 | && !nopic_need_relax (ep->X_add_symbol, 1)) |
d6bc6245 | 5951 | { |
4d7206a2 | 5952 | relax_start (ep->X_add_symbol); |
67c0d1eb | 5953 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, |
17a2f251 | 5954 | mips_gp_register, BFD_RELOC_GPREL16); |
4d7206a2 | 5955 | relax_switch (); |
d6bc6245 | 5956 | } |
67c0d1eb RS |
5957 | macro_build_lui (ep, reg); |
5958 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", | |
5959 | reg, reg, BFD_RELOC_LO16); | |
4d7206a2 RS |
5960 | if (mips_relax.sequence) |
5961 | relax_end (); | |
d6bc6245 | 5962 | } |
252b5132 | 5963 | } |
0a44bf69 | 5964 | else if (!mips_big_got) |
252b5132 RH |
5965 | { |
5966 | expressionS ex; | |
5967 | ||
5968 | /* If this is a reference to an external symbol, we want | |
5969 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5970 | Otherwise we want | |
5971 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5972 | nop | |
5973 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
f5040a92 AO |
5974 | If there is a constant, it must be added in after. |
5975 | ||
ed6fb7bd | 5976 | If we have NewABI, we want |
f5040a92 AO |
5977 | lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP) |
5978 | unless we're referencing a global symbol with a non-zero | |
5979 | offset, in which case cst must be added separately. */ | |
ed6fb7bd SC |
5980 | if (HAVE_NEWABI) |
5981 | { | |
f5040a92 AO |
5982 | if (ep->X_add_number) |
5983 | { | |
4d7206a2 | 5984 | ex.X_add_number = ep->X_add_number; |
f5040a92 | 5985 | ep->X_add_number = 0; |
4d7206a2 | 5986 | relax_start (ep->X_add_symbol); |
67c0d1eb RS |
5987 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
5988 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); | |
f5040a92 AO |
5989 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) |
5990 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5991 | ex.X_op = O_constant; | |
67c0d1eb | 5992 | macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", |
17a2f251 | 5993 | reg, reg, BFD_RELOC_LO16); |
f5040a92 | 5994 | ep->X_add_number = ex.X_add_number; |
4d7206a2 | 5995 | relax_switch (); |
f5040a92 | 5996 | } |
67c0d1eb | 5997 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
17a2f251 | 5998 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); |
4d7206a2 RS |
5999 | if (mips_relax.sequence) |
6000 | relax_end (); | |
ed6fb7bd SC |
6001 | } |
6002 | else | |
6003 | { | |
f5040a92 AO |
6004 | ex.X_add_number = ep->X_add_number; |
6005 | ep->X_add_number = 0; | |
67c0d1eb RS |
6006 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
6007 | BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
269137b2 | 6008 | load_delay_nop (); |
4d7206a2 RS |
6009 | relax_start (ep->X_add_symbol); |
6010 | relax_switch (); | |
67c0d1eb | 6011 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
17a2f251 | 6012 | BFD_RELOC_LO16); |
4d7206a2 | 6013 | relax_end (); |
ed6fb7bd | 6014 | |
f5040a92 AO |
6015 | if (ex.X_add_number != 0) |
6016 | { | |
6017 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
6018 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
6019 | ex.X_op = O_constant; | |
67c0d1eb | 6020 | macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", |
17a2f251 | 6021 | reg, reg, BFD_RELOC_LO16); |
f5040a92 | 6022 | } |
252b5132 RH |
6023 | } |
6024 | } | |
0a44bf69 | 6025 | else if (mips_big_got) |
252b5132 RH |
6026 | { |
6027 | expressionS ex; | |
252b5132 RH |
6028 | |
6029 | /* This is the large GOT case. If this is a reference to an | |
6030 | external symbol, we want | |
6031 | lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
6032 | addu $reg,$reg,$gp | |
6033 | lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16) | |
f5040a92 AO |
6034 | |
6035 | Otherwise, for a reference to a local symbol in old ABI, we want | |
252b5132 RH |
6036 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
6037 | nop | |
6038 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
684022ea | 6039 | If there is a constant, it must be added in after. |
f5040a92 AO |
6040 | |
6041 | In the NewABI, for local symbols, with or without offsets, we want: | |
438c16b8 TS |
6042 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) |
6043 | addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST) | |
f5040a92 | 6044 | */ |
438c16b8 TS |
6045 | if (HAVE_NEWABI) |
6046 | { | |
4d7206a2 | 6047 | ex.X_add_number = ep->X_add_number; |
f5040a92 | 6048 | ep->X_add_number = 0; |
4d7206a2 | 6049 | relax_start (ep->X_add_symbol); |
df58fc94 | 6050 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16); |
67c0d1eb RS |
6051 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
6052 | reg, reg, mips_gp_register); | |
6053 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", | |
6054 | reg, BFD_RELOC_MIPS_GOT_LO16, reg); | |
f5040a92 AO |
6055 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) |
6056 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
6057 | else if (ex.X_add_number) | |
6058 | { | |
6059 | ex.X_op = O_constant; | |
67c0d1eb RS |
6060 | macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
6061 | BFD_RELOC_LO16); | |
f5040a92 AO |
6062 | } |
6063 | ||
6064 | ep->X_add_number = ex.X_add_number; | |
4d7206a2 | 6065 | relax_switch (); |
67c0d1eb | 6066 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
17a2f251 | 6067 | BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); |
67c0d1eb RS |
6068 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
6069 | BFD_RELOC_MIPS_GOT_OFST); | |
4d7206a2 | 6070 | relax_end (); |
438c16b8 | 6071 | } |
252b5132 | 6072 | else |
438c16b8 | 6073 | { |
f5040a92 AO |
6074 | ex.X_add_number = ep->X_add_number; |
6075 | ep->X_add_number = 0; | |
4d7206a2 | 6076 | relax_start (ep->X_add_symbol); |
df58fc94 | 6077 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16); |
67c0d1eb RS |
6078 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
6079 | reg, reg, mips_gp_register); | |
6080 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", | |
6081 | reg, BFD_RELOC_MIPS_GOT_LO16, reg); | |
4d7206a2 RS |
6082 | relax_switch (); |
6083 | if (reg_needs_delay (mips_gp_register)) | |
438c16b8 TS |
6084 | { |
6085 | /* We need a nop before loading from $gp. This special | |
6086 | check is required because the lui which starts the main | |
6087 | instruction stream does not refer to $gp, and so will not | |
6088 | insert the nop which may be required. */ | |
67c0d1eb | 6089 | macro_build (NULL, "nop", ""); |
438c16b8 | 6090 | } |
67c0d1eb | 6091 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
17a2f251 | 6092 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
269137b2 | 6093 | load_delay_nop (); |
67c0d1eb | 6094 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
17a2f251 | 6095 | BFD_RELOC_LO16); |
4d7206a2 | 6096 | relax_end (); |
438c16b8 | 6097 | |
f5040a92 AO |
6098 | if (ex.X_add_number != 0) |
6099 | { | |
6100 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
6101 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
6102 | ex.X_op = O_constant; | |
67c0d1eb RS |
6103 | macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
6104 | BFD_RELOC_LO16); | |
f5040a92 | 6105 | } |
252b5132 RH |
6106 | } |
6107 | } | |
252b5132 RH |
6108 | else |
6109 | abort (); | |
8fc2e39e | 6110 | |
741fe287 | 6111 | if (!mips_opts.at && *used_at == 1) |
8fc2e39e | 6112 | as_bad (_("Macro used $at after \".set noat\"")); |
252b5132 RH |
6113 | } |
6114 | ||
ea1fb5dc RS |
6115 | /* Move the contents of register SOURCE into register DEST. */ |
6116 | ||
6117 | static void | |
67c0d1eb | 6118 | move_register (int dest, int source) |
ea1fb5dc | 6119 | { |
df58fc94 RS |
6120 | /* Prefer to use a 16-bit microMIPS instruction unless the previous |
6121 | instruction specifically requires a 32-bit one. */ | |
6122 | if (mips_opts.micromips | |
6123 | && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) | |
7951ca42 | 6124 | macro_build (NULL, "move", "mp,mj", dest, source); |
df58fc94 RS |
6125 | else |
6126 | macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t", | |
6127 | dest, source, 0); | |
ea1fb5dc RS |
6128 | } |
6129 | ||
4d7206a2 | 6130 | /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where |
f6a22291 MR |
6131 | LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement. |
6132 | The two alternatives are: | |
4d7206a2 RS |
6133 | |
6134 | Global symbol Local sybmol | |
6135 | ------------- ------------ | |
6136 | lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET) | |
6137 | ... ... | |
6138 | addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET) | |
6139 | ||
6140 | load_got_offset emits the first instruction and add_got_offset | |
f6a22291 MR |
6141 | emits the second for a 16-bit offset or add_got_offset_hilo emits |
6142 | a sequence to add a 32-bit offset using a scratch register. */ | |
4d7206a2 RS |
6143 | |
6144 | static void | |
67c0d1eb | 6145 | load_got_offset (int dest, expressionS *local) |
4d7206a2 RS |
6146 | { |
6147 | expressionS global; | |
6148 | ||
6149 | global = *local; | |
6150 | global.X_add_number = 0; | |
6151 | ||
6152 | relax_start (local->X_add_symbol); | |
67c0d1eb RS |
6153 | macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest, |
6154 | BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
4d7206a2 | 6155 | relax_switch (); |
67c0d1eb RS |
6156 | macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest, |
6157 | BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
4d7206a2 RS |
6158 | relax_end (); |
6159 | } | |
6160 | ||
6161 | static void | |
67c0d1eb | 6162 | add_got_offset (int dest, expressionS *local) |
4d7206a2 RS |
6163 | { |
6164 | expressionS global; | |
6165 | ||
6166 | global.X_op = O_constant; | |
6167 | global.X_op_symbol = NULL; | |
6168 | global.X_add_symbol = NULL; | |
6169 | global.X_add_number = local->X_add_number; | |
6170 | ||
6171 | relax_start (local->X_add_symbol); | |
67c0d1eb | 6172 | macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j", |
4d7206a2 RS |
6173 | dest, dest, BFD_RELOC_LO16); |
6174 | relax_switch (); | |
67c0d1eb | 6175 | macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16); |
4d7206a2 RS |
6176 | relax_end (); |
6177 | } | |
6178 | ||
f6a22291 MR |
6179 | static void |
6180 | add_got_offset_hilo (int dest, expressionS *local, int tmp) | |
6181 | { | |
6182 | expressionS global; | |
6183 | int hold_mips_optimize; | |
6184 | ||
6185 | global.X_op = O_constant; | |
6186 | global.X_op_symbol = NULL; | |
6187 | global.X_add_symbol = NULL; | |
6188 | global.X_add_number = local->X_add_number; | |
6189 | ||
6190 | relax_start (local->X_add_symbol); | |
6191 | load_register (tmp, &global, HAVE_64BIT_ADDRESSES); | |
6192 | relax_switch (); | |
6193 | /* Set mips_optimize around the lui instruction to avoid | |
6194 | inserting an unnecessary nop after the lw. */ | |
6195 | hold_mips_optimize = mips_optimize; | |
6196 | mips_optimize = 2; | |
6197 | macro_build_lui (&global, tmp); | |
6198 | mips_optimize = hold_mips_optimize; | |
6199 | macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16); | |
6200 | relax_end (); | |
6201 | ||
6202 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp); | |
6203 | } | |
6204 | ||
df58fc94 RS |
6205 | /* Emit a sequence of instructions to emulate a branch likely operation. |
6206 | BR is an ordinary branch corresponding to one to be emulated. BRNEG | |
6207 | is its complementing branch with the original condition negated. | |
6208 | CALL is set if the original branch specified the link operation. | |
6209 | EP, FMT, SREG and TREG specify the usual macro_build() parameters. | |
6210 | ||
6211 | Code like this is produced in the noreorder mode: | |
6212 | ||
6213 | BRNEG <args>, 1f | |
6214 | nop | |
6215 | b <sym> | |
6216 | delay slot (executed only if branch taken) | |
6217 | 1: | |
6218 | ||
6219 | or, if CALL is set: | |
6220 | ||
6221 | BRNEG <args>, 1f | |
6222 | nop | |
6223 | bal <sym> | |
6224 | delay slot (executed only if branch taken) | |
6225 | 1: | |
6226 | ||
6227 | In the reorder mode the delay slot would be filled with a nop anyway, | |
6228 | so code produced is simply: | |
6229 | ||
6230 | BR <args>, <sym> | |
6231 | nop | |
6232 | ||
6233 | This function is used when producing code for the microMIPS ASE that | |
6234 | does not implement branch likely instructions in hardware. */ | |
6235 | ||
6236 | static void | |
6237 | macro_build_branch_likely (const char *br, const char *brneg, | |
6238 | int call, expressionS *ep, const char *fmt, | |
6239 | unsigned int sreg, unsigned int treg) | |
6240 | { | |
6241 | int noreorder = mips_opts.noreorder; | |
6242 | expressionS expr1; | |
6243 | ||
6244 | gas_assert (mips_opts.micromips); | |
6245 | start_noreorder (); | |
6246 | if (noreorder) | |
6247 | { | |
6248 | micromips_label_expr (&expr1); | |
6249 | macro_build (&expr1, brneg, fmt, sreg, treg); | |
6250 | macro_build (NULL, "nop", ""); | |
6251 | macro_build (ep, call ? "bal" : "b", "p"); | |
6252 | ||
6253 | /* Set to true so that append_insn adds a label. */ | |
6254 | emit_branch_likely_macro = TRUE; | |
6255 | } | |
6256 | else | |
6257 | { | |
6258 | macro_build (ep, br, fmt, sreg, treg); | |
6259 | macro_build (NULL, "nop", ""); | |
6260 | } | |
6261 | end_noreorder (); | |
6262 | } | |
6263 | ||
6264 | /* Emit a coprocessor branch-likely macro specified by TYPE, using CC as | |
6265 | the condition code tested. EP specifies the branch target. */ | |
6266 | ||
6267 | static void | |
6268 | macro_build_branch_ccl (int type, expressionS *ep, unsigned int cc) | |
6269 | { | |
6270 | const int call = 0; | |
6271 | const char *brneg; | |
6272 | const char *br; | |
6273 | ||
6274 | switch (type) | |
6275 | { | |
6276 | case M_BC1FL: | |
6277 | br = "bc1f"; | |
6278 | brneg = "bc1t"; | |
6279 | break; | |
6280 | case M_BC1TL: | |
6281 | br = "bc1t"; | |
6282 | brneg = "bc1f"; | |
6283 | break; | |
6284 | case M_BC2FL: | |
6285 | br = "bc2f"; | |
6286 | brneg = "bc2t"; | |
6287 | break; | |
6288 | case M_BC2TL: | |
6289 | br = "bc2t"; | |
6290 | brneg = "bc2f"; | |
6291 | break; | |
6292 | default: | |
6293 | abort (); | |
6294 | } | |
6295 | macro_build_branch_likely (br, brneg, call, ep, "N,p", cc, ZERO); | |
6296 | } | |
6297 | ||
6298 | /* Emit a two-argument branch macro specified by TYPE, using SREG as | |
6299 | the register tested. EP specifies the branch target. */ | |
6300 | ||
6301 | static void | |
6302 | macro_build_branch_rs (int type, expressionS *ep, unsigned int sreg) | |
6303 | { | |
6304 | const char *brneg = NULL; | |
6305 | const char *br; | |
6306 | int call = 0; | |
6307 | ||
6308 | switch (type) | |
6309 | { | |
6310 | case M_BGEZ: | |
6311 | br = "bgez"; | |
6312 | break; | |
6313 | case M_BGEZL: | |
6314 | br = mips_opts.micromips ? "bgez" : "bgezl"; | |
6315 | brneg = "bltz"; | |
6316 | break; | |
6317 | case M_BGEZALL: | |
6318 | gas_assert (mips_opts.micromips); | |
6319 | br = "bgezals"; | |
6320 | brneg = "bltz"; | |
6321 | call = 1; | |
6322 | break; | |
6323 | case M_BGTZ: | |
6324 | br = "bgtz"; | |
6325 | break; | |
6326 | case M_BGTZL: | |
6327 | br = mips_opts.micromips ? "bgtz" : "bgtzl"; | |
6328 | brneg = "blez"; | |
6329 | break; | |
6330 | case M_BLEZ: | |
6331 | br = "blez"; | |
6332 | break; | |
6333 | case M_BLEZL: | |
6334 | br = mips_opts.micromips ? "blez" : "blezl"; | |
6335 | brneg = "bgtz"; | |
6336 | break; | |
6337 | case M_BLTZ: | |
6338 | br = "bltz"; | |
6339 | break; | |
6340 | case M_BLTZL: | |
6341 | br = mips_opts.micromips ? "bltz" : "bltzl"; | |
6342 | brneg = "bgez"; | |
6343 | break; | |
6344 | case M_BLTZALL: | |
6345 | gas_assert (mips_opts.micromips); | |
6346 | br = "bltzals"; | |
6347 | brneg = "bgez"; | |
6348 | call = 1; | |
6349 | break; | |
6350 | default: | |
6351 | abort (); | |
6352 | } | |
6353 | if (mips_opts.micromips && brneg) | |
6354 | macro_build_branch_likely (br, brneg, call, ep, "s,p", sreg, ZERO); | |
6355 | else | |
6356 | macro_build (ep, br, "s,p", sreg); | |
6357 | } | |
6358 | ||
6359 | /* Emit a three-argument branch macro specified by TYPE, using SREG and | |
6360 | TREG as the registers tested. EP specifies the branch target. */ | |
6361 | ||
6362 | static void | |
6363 | macro_build_branch_rsrt (int type, expressionS *ep, | |
6364 | unsigned int sreg, unsigned int treg) | |
6365 | { | |
6366 | const char *brneg = NULL; | |
6367 | const int call = 0; | |
6368 | const char *br; | |
6369 | ||
6370 | switch (type) | |
6371 | { | |
6372 | case M_BEQ: | |
6373 | case M_BEQ_I: | |
6374 | br = "beq"; | |
6375 | break; | |
6376 | case M_BEQL: | |
6377 | case M_BEQL_I: | |
6378 | br = mips_opts.micromips ? "beq" : "beql"; | |
6379 | brneg = "bne"; | |
6380 | break; | |
6381 | case M_BNE: | |
6382 | case M_BNE_I: | |
6383 | br = "bne"; | |
6384 | break; | |
6385 | case M_BNEL: | |
6386 | case M_BNEL_I: | |
6387 | br = mips_opts.micromips ? "bne" : "bnel"; | |
6388 | brneg = "beq"; | |
6389 | break; | |
6390 | default: | |
6391 | abort (); | |
6392 | } | |
6393 | if (mips_opts.micromips && brneg) | |
6394 | macro_build_branch_likely (br, brneg, call, ep, "s,t,p", sreg, treg); | |
6395 | else | |
6396 | macro_build (ep, br, "s,t,p", sreg, treg); | |
6397 | } | |
6398 | ||
252b5132 RH |
6399 | /* |
6400 | * Build macros | |
6401 | * This routine implements the seemingly endless macro or synthesized | |
6402 | * instructions and addressing modes in the mips assembly language. Many | |
6403 | * of these macros are simple and are similar to each other. These could | |
67c1ffbe | 6404 | * probably be handled by some kind of table or grammar approach instead of |
252b5132 RH |
6405 | * this verbose method. Others are not simple macros but are more like |
6406 | * optimizing code generation. | |
6407 | * One interesting optimization is when several store macros appear | |
67c1ffbe | 6408 | * consecutively that would load AT with the upper half of the same address. |
252b5132 RH |
6409 | * The ensuing load upper instructions are ommited. This implies some kind |
6410 | * of global optimization. We currently only optimize within a single macro. | |
6411 | * For many of the load and store macros if the address is specified as a | |
6412 | * constant expression in the first 64k of memory (ie ld $2,0x4000c) we | |
6413 | * first load register 'at' with zero and use it as the base register. The | |
6414 | * mips assembler simply uses register $zero. Just one tiny optimization | |
6415 | * we're missing. | |
6416 | */ | |
6417 | static void | |
17a2f251 | 6418 | macro (struct mips_cl_insn *ip) |
252b5132 | 6419 | { |
741fe287 MR |
6420 | unsigned int treg, sreg, dreg, breg; |
6421 | unsigned int tempreg; | |
252b5132 | 6422 | int mask; |
43841e91 | 6423 | int used_at = 0; |
df58fc94 | 6424 | expressionS label_expr; |
252b5132 | 6425 | expressionS expr1; |
df58fc94 | 6426 | expressionS *ep; |
252b5132 RH |
6427 | const char *s; |
6428 | const char *s2; | |
6429 | const char *fmt; | |
6430 | int likely = 0; | |
252b5132 | 6431 | int coproc = 0; |
df58fc94 | 6432 | int off12 = 0; |
1abe91b1 | 6433 | int call = 0; |
df58fc94 RS |
6434 | int jals = 0; |
6435 | int dbl = 0; | |
6436 | int imm = 0; | |
6437 | int ust = 0; | |
6438 | int lp = 0; | |
6439 | int ab = 0; | |
dd6a37e7 | 6440 | int off0 = 0; |
252b5132 | 6441 | int off; |
67c0d1eb | 6442 | offsetT maxnum; |
252b5132 | 6443 | bfd_reloc_code_real_type r; |
252b5132 RH |
6444 | int hold_mips_optimize; |
6445 | ||
9c2799c2 | 6446 | gas_assert (! mips_opts.mips16); |
252b5132 | 6447 | |
df58fc94 RS |
6448 | treg = EXTRACT_OPERAND (mips_opts.micromips, RT, *ip); |
6449 | dreg = EXTRACT_OPERAND (mips_opts.micromips, RD, *ip); | |
6450 | sreg = breg = EXTRACT_OPERAND (mips_opts.micromips, RS, *ip); | |
252b5132 RH |
6451 | mask = ip->insn_mo->mask; |
6452 | ||
df58fc94 RS |
6453 | label_expr.X_op = O_constant; |
6454 | label_expr.X_op_symbol = NULL; | |
6455 | label_expr.X_add_symbol = NULL; | |
6456 | label_expr.X_add_number = 0; | |
6457 | ||
252b5132 RH |
6458 | expr1.X_op = O_constant; |
6459 | expr1.X_op_symbol = NULL; | |
6460 | expr1.X_add_symbol = NULL; | |
6461 | expr1.X_add_number = 1; | |
6462 | ||
6463 | switch (mask) | |
6464 | { | |
6465 | case M_DABS: | |
6466 | dbl = 1; | |
6467 | case M_ABS: | |
df58fc94 RS |
6468 | /* bgez $a0,1f |
6469 | move v0,$a0 | |
6470 | sub v0,$zero,$a0 | |
6471 | 1: | |
6472 | */ | |
252b5132 | 6473 | |
7d10b47d | 6474 | start_noreorder (); |
252b5132 | 6475 | |
df58fc94 RS |
6476 | if (mips_opts.micromips) |
6477 | micromips_label_expr (&label_expr); | |
6478 | else | |
6479 | label_expr.X_add_number = 8; | |
6480 | macro_build (&label_expr, "bgez", "s,p", sreg); | |
252b5132 | 6481 | if (dreg == sreg) |
a605d2b3 | 6482 | macro_build (NULL, "nop", ""); |
252b5132 | 6483 | else |
67c0d1eb RS |
6484 | move_register (dreg, sreg); |
6485 | macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg); | |
df58fc94 RS |
6486 | if (mips_opts.micromips) |
6487 | micromips_add_label (); | |
252b5132 | 6488 | |
7d10b47d | 6489 | end_noreorder (); |
8fc2e39e | 6490 | break; |
252b5132 RH |
6491 | |
6492 | case M_ADD_I: | |
6493 | s = "addi"; | |
6494 | s2 = "add"; | |
6495 | goto do_addi; | |
6496 | case M_ADDU_I: | |
6497 | s = "addiu"; | |
6498 | s2 = "addu"; | |
6499 | goto do_addi; | |
6500 | case M_DADD_I: | |
6501 | dbl = 1; | |
6502 | s = "daddi"; | |
6503 | s2 = "dadd"; | |
df58fc94 RS |
6504 | if (!mips_opts.micromips) |
6505 | goto do_addi; | |
6506 | if (imm_expr.X_op == O_constant | |
6507 | && imm_expr.X_add_number >= -0x200 | |
6508 | && imm_expr.X_add_number < 0x200) | |
6509 | { | |
6510 | macro_build (NULL, s, "t,r,.", treg, sreg, imm_expr.X_add_number); | |
6511 | break; | |
6512 | } | |
6513 | goto do_addi_i; | |
252b5132 RH |
6514 | case M_DADDU_I: |
6515 | dbl = 1; | |
6516 | s = "daddiu"; | |
6517 | s2 = "daddu"; | |
6518 | do_addi: | |
6519 | if (imm_expr.X_op == O_constant | |
6520 | && imm_expr.X_add_number >= -0x8000 | |
6521 | && imm_expr.X_add_number < 0x8000) | |
6522 | { | |
67c0d1eb | 6523 | macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16); |
8fc2e39e | 6524 | break; |
252b5132 | 6525 | } |
df58fc94 | 6526 | do_addi_i: |
8fc2e39e | 6527 | used_at = 1; |
67c0d1eb RS |
6528 | load_register (AT, &imm_expr, dbl); |
6529 | macro_build (NULL, s2, "d,v,t", treg, sreg, AT); | |
252b5132 RH |
6530 | break; |
6531 | ||
6532 | case M_AND_I: | |
6533 | s = "andi"; | |
6534 | s2 = "and"; | |
6535 | goto do_bit; | |
6536 | case M_OR_I: | |
6537 | s = "ori"; | |
6538 | s2 = "or"; | |
6539 | goto do_bit; | |
6540 | case M_NOR_I: | |
6541 | s = ""; | |
6542 | s2 = "nor"; | |
6543 | goto do_bit; | |
6544 | case M_XOR_I: | |
6545 | s = "xori"; | |
6546 | s2 = "xor"; | |
6547 | do_bit: | |
6548 | if (imm_expr.X_op == O_constant | |
6549 | && imm_expr.X_add_number >= 0 | |
6550 | && imm_expr.X_add_number < 0x10000) | |
6551 | { | |
6552 | if (mask != M_NOR_I) | |
67c0d1eb | 6553 | macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16); |
252b5132 RH |
6554 | else |
6555 | { | |
67c0d1eb RS |
6556 | macro_build (&imm_expr, "ori", "t,r,i", |
6557 | treg, sreg, BFD_RELOC_LO16); | |
6558 | macro_build (NULL, "nor", "d,v,t", treg, treg, 0); | |
252b5132 | 6559 | } |
8fc2e39e | 6560 | break; |
252b5132 RH |
6561 | } |
6562 | ||
8fc2e39e | 6563 | used_at = 1; |
67c0d1eb RS |
6564 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
6565 | macro_build (NULL, s2, "d,v,t", treg, sreg, AT); | |
252b5132 RH |
6566 | break; |
6567 | ||
8b082fb1 TS |
6568 | case M_BALIGN: |
6569 | switch (imm_expr.X_add_number) | |
6570 | { | |
6571 | case 0: | |
6572 | macro_build (NULL, "nop", ""); | |
6573 | break; | |
6574 | case 2: | |
6575 | macro_build (NULL, "packrl.ph", "d,s,t", treg, treg, sreg); | |
6576 | break; | |
03f66e8a MR |
6577 | case 1: |
6578 | case 3: | |
8b082fb1 | 6579 | macro_build (NULL, "balign", "t,s,2", treg, sreg, |
90ecf173 | 6580 | (int) imm_expr.X_add_number); |
8b082fb1 | 6581 | break; |
03f66e8a MR |
6582 | default: |
6583 | as_bad (_("BALIGN immediate not 0, 1, 2 or 3 (%lu)"), | |
6584 | (unsigned long) imm_expr.X_add_number); | |
6585 | break; | |
8b082fb1 TS |
6586 | } |
6587 | break; | |
6588 | ||
df58fc94 RS |
6589 | case M_BC1FL: |
6590 | case M_BC1TL: | |
6591 | case M_BC2FL: | |
6592 | case M_BC2TL: | |
6593 | gas_assert (mips_opts.micromips); | |
6594 | macro_build_branch_ccl (mask, &offset_expr, | |
6595 | EXTRACT_OPERAND (1, BCC, *ip)); | |
6596 | break; | |
6597 | ||
252b5132 | 6598 | case M_BEQ_I: |
252b5132 | 6599 | case M_BEQL_I: |
252b5132 | 6600 | case M_BNE_I: |
252b5132 | 6601 | case M_BNEL_I: |
252b5132 | 6602 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
df58fc94 RS |
6603 | treg = 0; |
6604 | else | |
252b5132 | 6605 | { |
df58fc94 RS |
6606 | treg = AT; |
6607 | used_at = 1; | |
6608 | load_register (treg, &imm_expr, HAVE_64BIT_GPRS); | |
252b5132 | 6609 | } |
df58fc94 RS |
6610 | /* Fall through. */ |
6611 | case M_BEQL: | |
6612 | case M_BNEL: | |
6613 | macro_build_branch_rsrt (mask, &offset_expr, sreg, treg); | |
252b5132 RH |
6614 | break; |
6615 | ||
6616 | case M_BGEL: | |
6617 | likely = 1; | |
6618 | case M_BGE: | |
6619 | if (treg == 0) | |
df58fc94 RS |
6620 | macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, sreg); |
6621 | else if (sreg == 0) | |
6622 | macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, treg); | |
6623 | else | |
252b5132 | 6624 | { |
df58fc94 RS |
6625 | used_at = 1; |
6626 | macro_build (NULL, "slt", "d,v,t", AT, sreg, treg); | |
6627 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, | |
6628 | &offset_expr, AT, ZERO); | |
252b5132 | 6629 | } |
df58fc94 RS |
6630 | break; |
6631 | ||
6632 | case M_BGEZL: | |
6633 | case M_BGEZALL: | |
6634 | case M_BGTZL: | |
6635 | case M_BLEZL: | |
6636 | case M_BLTZL: | |
6637 | case M_BLTZALL: | |
6638 | macro_build_branch_rs (mask, &offset_expr, sreg); | |
252b5132 RH |
6639 | break; |
6640 | ||
6641 | case M_BGTL_I: | |
6642 | likely = 1; | |
6643 | case M_BGT_I: | |
90ecf173 | 6644 | /* Check for > max integer. */ |
252b5132 | 6645 | maxnum = 0x7fffffff; |
ca4e0257 | 6646 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
6647 | { |
6648 | maxnum <<= 16; | |
6649 | maxnum |= 0xffff; | |
6650 | maxnum <<= 16; | |
6651 | maxnum |= 0xffff; | |
6652 | } | |
6653 | if (imm_expr.X_op == O_constant | |
6654 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 6655 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
6656 | { |
6657 | do_false: | |
90ecf173 | 6658 | /* Result is always false. */ |
252b5132 | 6659 | if (! likely) |
a605d2b3 | 6660 | macro_build (NULL, "nop", ""); |
252b5132 | 6661 | else |
df58fc94 | 6662 | macro_build_branch_rsrt (M_BNEL, &offset_expr, ZERO, ZERO); |
8fc2e39e | 6663 | break; |
252b5132 RH |
6664 | } |
6665 | if (imm_expr.X_op != O_constant) | |
6666 | as_bad (_("Unsupported large constant")); | |
f9419b05 | 6667 | ++imm_expr.X_add_number; |
252b5132 RH |
6668 | /* FALLTHROUGH */ |
6669 | case M_BGE_I: | |
6670 | case M_BGEL_I: | |
6671 | if (mask == M_BGEL_I) | |
6672 | likely = 1; | |
6673 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6674 | { | |
df58fc94 RS |
6675 | macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, |
6676 | &offset_expr, sreg); | |
8fc2e39e | 6677 | break; |
252b5132 RH |
6678 | } |
6679 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
6680 | { | |
df58fc94 RS |
6681 | macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, |
6682 | &offset_expr, sreg); | |
8fc2e39e | 6683 | break; |
252b5132 RH |
6684 | } |
6685 | maxnum = 0x7fffffff; | |
ca4e0257 | 6686 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
6687 | { |
6688 | maxnum <<= 16; | |
6689 | maxnum |= 0xffff; | |
6690 | maxnum <<= 16; | |
6691 | maxnum |= 0xffff; | |
6692 | } | |
6693 | maxnum = - maxnum - 1; | |
6694 | if (imm_expr.X_op == O_constant | |
6695 | && imm_expr.X_add_number <= maxnum | |
ca4e0257 | 6696 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
6697 | { |
6698 | do_true: | |
6699 | /* result is always true */ | |
6700 | as_warn (_("Branch %s is always true"), ip->insn_mo->name); | |
67c0d1eb | 6701 | macro_build (&offset_expr, "b", "p"); |
8fc2e39e | 6702 | break; |
252b5132 | 6703 | } |
8fc2e39e | 6704 | used_at = 1; |
67c0d1eb | 6705 | set_at (sreg, 0); |
df58fc94 RS |
6706 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
6707 | &offset_expr, AT, ZERO); | |
252b5132 RH |
6708 | break; |
6709 | ||
6710 | case M_BGEUL: | |
6711 | likely = 1; | |
6712 | case M_BGEU: | |
6713 | if (treg == 0) | |
6714 | goto do_true; | |
df58fc94 RS |
6715 | else if (sreg == 0) |
6716 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, | |
6717 | &offset_expr, ZERO, treg); | |
6718 | else | |
252b5132 | 6719 | { |
df58fc94 RS |
6720 | used_at = 1; |
6721 | macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg); | |
6722 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, | |
6723 | &offset_expr, AT, ZERO); | |
252b5132 | 6724 | } |
252b5132 RH |
6725 | break; |
6726 | ||
6727 | case M_BGTUL_I: | |
6728 | likely = 1; | |
6729 | case M_BGTU_I: | |
6730 | if (sreg == 0 | |
ca4e0257 | 6731 | || (HAVE_32BIT_GPRS |
252b5132 | 6732 | && imm_expr.X_op == O_constant |
f01dc953 | 6733 | && imm_expr.X_add_number == -1)) |
252b5132 RH |
6734 | goto do_false; |
6735 | if (imm_expr.X_op != O_constant) | |
6736 | as_bad (_("Unsupported large constant")); | |
f9419b05 | 6737 | ++imm_expr.X_add_number; |
252b5132 RH |
6738 | /* FALLTHROUGH */ |
6739 | case M_BGEU_I: | |
6740 | case M_BGEUL_I: | |
6741 | if (mask == M_BGEUL_I) | |
6742 | likely = 1; | |
6743 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6744 | goto do_true; | |
df58fc94 RS |
6745 | else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) |
6746 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, | |
6747 | &offset_expr, sreg, ZERO); | |
6748 | else | |
252b5132 | 6749 | { |
df58fc94 RS |
6750 | used_at = 1; |
6751 | set_at (sreg, 1); | |
6752 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, | |
6753 | &offset_expr, AT, ZERO); | |
252b5132 | 6754 | } |
252b5132 RH |
6755 | break; |
6756 | ||
6757 | case M_BGTL: | |
6758 | likely = 1; | |
6759 | case M_BGT: | |
6760 | if (treg == 0) | |
df58fc94 RS |
6761 | macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, sreg); |
6762 | else if (sreg == 0) | |
6763 | macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, treg); | |
6764 | else | |
252b5132 | 6765 | { |
df58fc94 RS |
6766 | used_at = 1; |
6767 | macro_build (NULL, "slt", "d,v,t", AT, treg, sreg); | |
6768 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, | |
6769 | &offset_expr, AT, ZERO); | |
252b5132 | 6770 | } |
252b5132 RH |
6771 | break; |
6772 | ||
6773 | case M_BGTUL: | |
6774 | likely = 1; | |
6775 | case M_BGTU: | |
6776 | if (treg == 0) | |
df58fc94 RS |
6777 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
6778 | &offset_expr, sreg, ZERO); | |
6779 | else if (sreg == 0) | |
6780 | goto do_false; | |
6781 | else | |
252b5132 | 6782 | { |
df58fc94 RS |
6783 | used_at = 1; |
6784 | macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg); | |
6785 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, | |
6786 | &offset_expr, AT, ZERO); | |
252b5132 | 6787 | } |
252b5132 RH |
6788 | break; |
6789 | ||
6790 | case M_BLEL: | |
6791 | likely = 1; | |
6792 | case M_BLE: | |
6793 | if (treg == 0) | |
df58fc94 RS |
6794 | macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg); |
6795 | else if (sreg == 0) | |
6796 | macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, treg); | |
6797 | else | |
252b5132 | 6798 | { |
df58fc94 RS |
6799 | used_at = 1; |
6800 | macro_build (NULL, "slt", "d,v,t", AT, treg, sreg); | |
6801 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, | |
6802 | &offset_expr, AT, ZERO); | |
252b5132 | 6803 | } |
252b5132 RH |
6804 | break; |
6805 | ||
6806 | case M_BLEL_I: | |
6807 | likely = 1; | |
6808 | case M_BLE_I: | |
6809 | maxnum = 0x7fffffff; | |
ca4e0257 | 6810 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
6811 | { |
6812 | maxnum <<= 16; | |
6813 | maxnum |= 0xffff; | |
6814 | maxnum <<= 16; | |
6815 | maxnum |= 0xffff; | |
6816 | } | |
6817 | if (imm_expr.X_op == O_constant | |
6818 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 6819 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
6820 | goto do_true; |
6821 | if (imm_expr.X_op != O_constant) | |
6822 | as_bad (_("Unsupported large constant")); | |
f9419b05 | 6823 | ++imm_expr.X_add_number; |
252b5132 RH |
6824 | /* FALLTHROUGH */ |
6825 | case M_BLT_I: | |
6826 | case M_BLTL_I: | |
6827 | if (mask == M_BLTL_I) | |
6828 | likely = 1; | |
6829 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
df58fc94 RS |
6830 | macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg); |
6831 | else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
6832 | macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg); | |
6833 | else | |
252b5132 | 6834 | { |
df58fc94 RS |
6835 | used_at = 1; |
6836 | set_at (sreg, 0); | |
6837 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, | |
6838 | &offset_expr, AT, ZERO); | |
252b5132 | 6839 | } |
252b5132 RH |
6840 | break; |
6841 | ||
6842 | case M_BLEUL: | |
6843 | likely = 1; | |
6844 | case M_BLEU: | |
6845 | if (treg == 0) | |
df58fc94 RS |
6846 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
6847 | &offset_expr, sreg, ZERO); | |
6848 | else if (sreg == 0) | |
6849 | goto do_true; | |
6850 | else | |
252b5132 | 6851 | { |
df58fc94 RS |
6852 | used_at = 1; |
6853 | macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg); | |
6854 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, | |
6855 | &offset_expr, AT, ZERO); | |
252b5132 | 6856 | } |
252b5132 RH |
6857 | break; |
6858 | ||
6859 | case M_BLEUL_I: | |
6860 | likely = 1; | |
6861 | case M_BLEU_I: | |
6862 | if (sreg == 0 | |
ca4e0257 | 6863 | || (HAVE_32BIT_GPRS |
252b5132 | 6864 | && imm_expr.X_op == O_constant |
f01dc953 | 6865 | && imm_expr.X_add_number == -1)) |
252b5132 RH |
6866 | goto do_true; |
6867 | if (imm_expr.X_op != O_constant) | |
6868 | as_bad (_("Unsupported large constant")); | |
f9419b05 | 6869 | ++imm_expr.X_add_number; |
252b5132 RH |
6870 | /* FALLTHROUGH */ |
6871 | case M_BLTU_I: | |
6872 | case M_BLTUL_I: | |
6873 | if (mask == M_BLTUL_I) | |
6874 | likely = 1; | |
6875 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6876 | goto do_false; | |
df58fc94 RS |
6877 | else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) |
6878 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, | |
6879 | &offset_expr, sreg, ZERO); | |
6880 | else | |
252b5132 | 6881 | { |
df58fc94 RS |
6882 | used_at = 1; |
6883 | set_at (sreg, 1); | |
6884 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, | |
6885 | &offset_expr, AT, ZERO); | |
252b5132 | 6886 | } |
252b5132 RH |
6887 | break; |
6888 | ||
6889 | case M_BLTL: | |
6890 | likely = 1; | |
6891 | case M_BLT: | |
6892 | if (treg == 0) | |
df58fc94 RS |
6893 | macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg); |
6894 | else if (sreg == 0) | |
6895 | macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, treg); | |
6896 | else | |
252b5132 | 6897 | { |
df58fc94 RS |
6898 | used_at = 1; |
6899 | macro_build (NULL, "slt", "d,v,t", AT, sreg, treg); | |
6900 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, | |
6901 | &offset_expr, AT, ZERO); | |
252b5132 | 6902 | } |
252b5132 RH |
6903 | break; |
6904 | ||
6905 | case M_BLTUL: | |
6906 | likely = 1; | |
6907 | case M_BLTU: | |
6908 | if (treg == 0) | |
6909 | goto do_false; | |
df58fc94 RS |
6910 | else if (sreg == 0) |
6911 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, | |
6912 | &offset_expr, ZERO, treg); | |
6913 | else | |
252b5132 | 6914 | { |
df58fc94 RS |
6915 | used_at = 1; |
6916 | macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg); | |
6917 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, | |
6918 | &offset_expr, AT, ZERO); | |
252b5132 | 6919 | } |
252b5132 RH |
6920 | break; |
6921 | ||
5f74bc13 CD |
6922 | case M_DEXT: |
6923 | { | |
d5818fca MR |
6924 | /* Use unsigned arithmetic. */ |
6925 | addressT pos; | |
6926 | addressT size; | |
5f74bc13 | 6927 | |
90ecf173 | 6928 | if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant) |
5f74bc13 CD |
6929 | { |
6930 | as_bad (_("Unsupported large constant")); | |
6931 | pos = size = 1; | |
6932 | } | |
6933 | else | |
6934 | { | |
d5818fca MR |
6935 | pos = imm_expr.X_add_number; |
6936 | size = imm2_expr.X_add_number; | |
5f74bc13 CD |
6937 | } |
6938 | ||
6939 | if (pos > 63) | |
6940 | { | |
d5818fca | 6941 | as_bad (_("Improper position (%lu)"), (unsigned long) pos); |
5f74bc13 CD |
6942 | pos = 1; |
6943 | } | |
90ecf173 | 6944 | if (size == 0 || size > 64 || (pos + size - 1) > 63) |
5f74bc13 CD |
6945 | { |
6946 | as_bad (_("Improper extract size (%lu, position %lu)"), | |
d5818fca | 6947 | (unsigned long) size, (unsigned long) pos); |
5f74bc13 CD |
6948 | size = 1; |
6949 | } | |
6950 | ||
6951 | if (size <= 32 && pos < 32) | |
6952 | { | |
6953 | s = "dext"; | |
6954 | fmt = "t,r,+A,+C"; | |
6955 | } | |
6956 | else if (size <= 32) | |
6957 | { | |
6958 | s = "dextu"; | |
6959 | fmt = "t,r,+E,+H"; | |
6960 | } | |
6961 | else | |
6962 | { | |
6963 | s = "dextm"; | |
6964 | fmt = "t,r,+A,+G"; | |
6965 | } | |
d5818fca MR |
6966 | macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos, |
6967 | (int) (size - 1)); | |
5f74bc13 | 6968 | } |
8fc2e39e | 6969 | break; |
5f74bc13 CD |
6970 | |
6971 | case M_DINS: | |
6972 | { | |
d5818fca MR |
6973 | /* Use unsigned arithmetic. */ |
6974 | addressT pos; | |
6975 | addressT size; | |
5f74bc13 | 6976 | |
90ecf173 | 6977 | if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant) |
5f74bc13 CD |
6978 | { |
6979 | as_bad (_("Unsupported large constant")); | |
6980 | pos = size = 1; | |
6981 | } | |
6982 | else | |
6983 | { | |
d5818fca MR |
6984 | pos = imm_expr.X_add_number; |
6985 | size = imm2_expr.X_add_number; | |
5f74bc13 CD |
6986 | } |
6987 | ||
6988 | if (pos > 63) | |
6989 | { | |
d5818fca | 6990 | as_bad (_("Improper position (%lu)"), (unsigned long) pos); |
5f74bc13 CD |
6991 | pos = 1; |
6992 | } | |
90ecf173 | 6993 | if (size == 0 || size > 64 || (pos + size - 1) > 63) |
5f74bc13 CD |
6994 | { |
6995 | as_bad (_("Improper insert size (%lu, position %lu)"), | |
d5818fca | 6996 | (unsigned long) size, (unsigned long) pos); |
5f74bc13 CD |
6997 | size = 1; |
6998 | } | |
6999 | ||
7000 | if (pos < 32 && (pos + size - 1) < 32) | |
7001 | { | |
7002 | s = "dins"; | |
7003 | fmt = "t,r,+A,+B"; | |
7004 | } | |
7005 | else if (pos >= 32) | |
7006 | { | |
7007 | s = "dinsu"; | |
7008 | fmt = "t,r,+E,+F"; | |
7009 | } | |
7010 | else | |
7011 | { | |
7012 | s = "dinsm"; | |
7013 | fmt = "t,r,+A,+F"; | |
7014 | } | |
750bdd57 AS |
7015 | macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos, |
7016 | (int) (pos + size - 1)); | |
5f74bc13 | 7017 | } |
8fc2e39e | 7018 | break; |
5f74bc13 | 7019 | |
252b5132 RH |
7020 | case M_DDIV_3: |
7021 | dbl = 1; | |
7022 | case M_DIV_3: | |
7023 | s = "mflo"; | |
7024 | goto do_div3; | |
7025 | case M_DREM_3: | |
7026 | dbl = 1; | |
7027 | case M_REM_3: | |
7028 | s = "mfhi"; | |
7029 | do_div3: | |
7030 | if (treg == 0) | |
7031 | { | |
7032 | as_warn (_("Divide by zero.")); | |
7033 | if (mips_trap) | |
df58fc94 | 7034 | macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7); |
252b5132 | 7035 | else |
df58fc94 | 7036 | macro_build (NULL, "break", BRK_FMT, 7); |
8fc2e39e | 7037 | break; |
252b5132 RH |
7038 | } |
7039 | ||
7d10b47d | 7040 | start_noreorder (); |
252b5132 RH |
7041 | if (mips_trap) |
7042 | { | |
df58fc94 | 7043 | macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7); |
67c0d1eb | 7044 | macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
252b5132 RH |
7045 | } |
7046 | else | |
7047 | { | |
df58fc94 RS |
7048 | if (mips_opts.micromips) |
7049 | micromips_label_expr (&label_expr); | |
7050 | else | |
7051 | label_expr.X_add_number = 8; | |
7052 | macro_build (&label_expr, "bne", "s,t,p", treg, ZERO); | |
67c0d1eb | 7053 | macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
df58fc94 RS |
7054 | macro_build (NULL, "break", BRK_FMT, 7); |
7055 | if (mips_opts.micromips) | |
7056 | micromips_add_label (); | |
252b5132 RH |
7057 | } |
7058 | expr1.X_add_number = -1; | |
8fc2e39e | 7059 | used_at = 1; |
f6a22291 | 7060 | load_register (AT, &expr1, dbl); |
df58fc94 RS |
7061 | if (mips_opts.micromips) |
7062 | micromips_label_expr (&label_expr); | |
7063 | else | |
7064 | label_expr.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16); | |
7065 | macro_build (&label_expr, "bne", "s,t,p", treg, AT); | |
252b5132 RH |
7066 | if (dbl) |
7067 | { | |
7068 | expr1.X_add_number = 1; | |
f6a22291 | 7069 | load_register (AT, &expr1, dbl); |
df58fc94 | 7070 | macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31); |
252b5132 RH |
7071 | } |
7072 | else | |
7073 | { | |
7074 | expr1.X_add_number = 0x80000000; | |
df58fc94 | 7075 | macro_build (&expr1, "lui", LUI_FMT, AT, BFD_RELOC_HI16); |
252b5132 RH |
7076 | } |
7077 | if (mips_trap) | |
7078 | { | |
df58fc94 | 7079 | macro_build (NULL, "teq", TRAP_FMT, sreg, AT, 6); |
252b5132 RH |
7080 | /* We want to close the noreorder block as soon as possible, so |
7081 | that later insns are available for delay slot filling. */ | |
7d10b47d | 7082 | end_noreorder (); |
252b5132 RH |
7083 | } |
7084 | else | |
7085 | { | |
df58fc94 RS |
7086 | if (mips_opts.micromips) |
7087 | micromips_label_expr (&label_expr); | |
7088 | else | |
7089 | label_expr.X_add_number = 8; | |
7090 | macro_build (&label_expr, "bne", "s,t,p", sreg, AT); | |
a605d2b3 | 7091 | macro_build (NULL, "nop", ""); |
252b5132 RH |
7092 | |
7093 | /* We want to close the noreorder block as soon as possible, so | |
7094 | that later insns are available for delay slot filling. */ | |
7d10b47d | 7095 | end_noreorder (); |
252b5132 | 7096 | |
df58fc94 | 7097 | macro_build (NULL, "break", BRK_FMT, 6); |
252b5132 | 7098 | } |
df58fc94 RS |
7099 | if (mips_opts.micromips) |
7100 | micromips_add_label (); | |
7101 | macro_build (NULL, s, MFHL_FMT, dreg); | |
252b5132 RH |
7102 | break; |
7103 | ||
7104 | case M_DIV_3I: | |
7105 | s = "div"; | |
7106 | s2 = "mflo"; | |
7107 | goto do_divi; | |
7108 | case M_DIVU_3I: | |
7109 | s = "divu"; | |
7110 | s2 = "mflo"; | |
7111 | goto do_divi; | |
7112 | case M_REM_3I: | |
7113 | s = "div"; | |
7114 | s2 = "mfhi"; | |
7115 | goto do_divi; | |
7116 | case M_REMU_3I: | |
7117 | s = "divu"; | |
7118 | s2 = "mfhi"; | |
7119 | goto do_divi; | |
7120 | case M_DDIV_3I: | |
7121 | dbl = 1; | |
7122 | s = "ddiv"; | |
7123 | s2 = "mflo"; | |
7124 | goto do_divi; | |
7125 | case M_DDIVU_3I: | |
7126 | dbl = 1; | |
7127 | s = "ddivu"; | |
7128 | s2 = "mflo"; | |
7129 | goto do_divi; | |
7130 | case M_DREM_3I: | |
7131 | dbl = 1; | |
7132 | s = "ddiv"; | |
7133 | s2 = "mfhi"; | |
7134 | goto do_divi; | |
7135 | case M_DREMU_3I: | |
7136 | dbl = 1; | |
7137 | s = "ddivu"; | |
7138 | s2 = "mfhi"; | |
7139 | do_divi: | |
7140 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
7141 | { | |
7142 | as_warn (_("Divide by zero.")); | |
7143 | if (mips_trap) | |
df58fc94 | 7144 | macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7); |
252b5132 | 7145 | else |
df58fc94 | 7146 | macro_build (NULL, "break", BRK_FMT, 7); |
8fc2e39e | 7147 | break; |
252b5132 RH |
7148 | } |
7149 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
7150 | { | |
7151 | if (strcmp (s2, "mflo") == 0) | |
67c0d1eb | 7152 | move_register (dreg, sreg); |
252b5132 | 7153 | else |
c80c840e | 7154 | move_register (dreg, ZERO); |
8fc2e39e | 7155 | break; |
252b5132 RH |
7156 | } |
7157 | if (imm_expr.X_op == O_constant | |
7158 | && imm_expr.X_add_number == -1 | |
7159 | && s[strlen (s) - 1] != 'u') | |
7160 | { | |
7161 | if (strcmp (s2, "mflo") == 0) | |
7162 | { | |
67c0d1eb | 7163 | macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg); |
252b5132 RH |
7164 | } |
7165 | else | |
c80c840e | 7166 | move_register (dreg, ZERO); |
8fc2e39e | 7167 | break; |
252b5132 RH |
7168 | } |
7169 | ||
8fc2e39e | 7170 | used_at = 1; |
67c0d1eb RS |
7171 | load_register (AT, &imm_expr, dbl); |
7172 | macro_build (NULL, s, "z,s,t", sreg, AT); | |
df58fc94 | 7173 | macro_build (NULL, s2, MFHL_FMT, dreg); |
252b5132 RH |
7174 | break; |
7175 | ||
7176 | case M_DIVU_3: | |
7177 | s = "divu"; | |
7178 | s2 = "mflo"; | |
7179 | goto do_divu3; | |
7180 | case M_REMU_3: | |
7181 | s = "divu"; | |
7182 | s2 = "mfhi"; | |
7183 | goto do_divu3; | |
7184 | case M_DDIVU_3: | |
7185 | s = "ddivu"; | |
7186 | s2 = "mflo"; | |
7187 | goto do_divu3; | |
7188 | case M_DREMU_3: | |
7189 | s = "ddivu"; | |
7190 | s2 = "mfhi"; | |
7191 | do_divu3: | |
7d10b47d | 7192 | start_noreorder (); |
252b5132 RH |
7193 | if (mips_trap) |
7194 | { | |
df58fc94 | 7195 | macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7); |
67c0d1eb | 7196 | macro_build (NULL, s, "z,s,t", sreg, treg); |
252b5132 RH |
7197 | /* We want to close the noreorder block as soon as possible, so |
7198 | that later insns are available for delay slot filling. */ | |
7d10b47d | 7199 | end_noreorder (); |
252b5132 RH |
7200 | } |
7201 | else | |
7202 | { | |
df58fc94 RS |
7203 | if (mips_opts.micromips) |
7204 | micromips_label_expr (&label_expr); | |
7205 | else | |
7206 | label_expr.X_add_number = 8; | |
7207 | macro_build (&label_expr, "bne", "s,t,p", treg, ZERO); | |
67c0d1eb | 7208 | macro_build (NULL, s, "z,s,t", sreg, treg); |
252b5132 RH |
7209 | |
7210 | /* We want to close the noreorder block as soon as possible, so | |
7211 | that later insns are available for delay slot filling. */ | |
7d10b47d | 7212 | end_noreorder (); |
df58fc94 RS |
7213 | macro_build (NULL, "break", BRK_FMT, 7); |
7214 | if (mips_opts.micromips) | |
7215 | micromips_add_label (); | |
252b5132 | 7216 | } |
df58fc94 | 7217 | macro_build (NULL, s2, MFHL_FMT, dreg); |
8fc2e39e | 7218 | break; |
252b5132 | 7219 | |
1abe91b1 MR |
7220 | case M_DLCA_AB: |
7221 | dbl = 1; | |
7222 | case M_LCA_AB: | |
7223 | call = 1; | |
7224 | goto do_la; | |
252b5132 RH |
7225 | case M_DLA_AB: |
7226 | dbl = 1; | |
7227 | case M_LA_AB: | |
1abe91b1 | 7228 | do_la: |
252b5132 RH |
7229 | /* Load the address of a symbol into a register. If breg is not |
7230 | zero, we then add a base register to it. */ | |
7231 | ||
3bec30a8 TS |
7232 | if (dbl && HAVE_32BIT_GPRS) |
7233 | as_warn (_("dla used to load 32-bit register")); | |
7234 | ||
90ecf173 | 7235 | if (!dbl && HAVE_64BIT_OBJECTS) |
3bec30a8 TS |
7236 | as_warn (_("la used to load 64-bit address")); |
7237 | ||
0c11417f MR |
7238 | if (offset_expr.X_op == O_constant |
7239 | && offset_expr.X_add_number >= -0x8000 | |
7240 | && offset_expr.X_add_number < 0x8000) | |
7241 | { | |
aed1a261 | 7242 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, |
17a2f251 | 7243 | "t,r,j", treg, sreg, BFD_RELOC_LO16); |
8fc2e39e | 7244 | break; |
0c11417f MR |
7245 | } |
7246 | ||
741fe287 | 7247 | if (mips_opts.at && (treg == breg)) |
afdbd6d0 CD |
7248 | { |
7249 | tempreg = AT; | |
7250 | used_at = 1; | |
7251 | } | |
7252 | else | |
7253 | { | |
7254 | tempreg = treg; | |
afdbd6d0 CD |
7255 | } |
7256 | ||
252b5132 RH |
7257 | if (offset_expr.X_op != O_symbol |
7258 | && offset_expr.X_op != O_constant) | |
7259 | { | |
f71d0d44 | 7260 | as_bad (_("Expression too complex")); |
252b5132 RH |
7261 | offset_expr.X_op = O_constant; |
7262 | } | |
7263 | ||
252b5132 | 7264 | if (offset_expr.X_op == O_constant) |
aed1a261 | 7265 | load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES); |
252b5132 RH |
7266 | else if (mips_pic == NO_PIC) |
7267 | { | |
d6bc6245 | 7268 | /* If this is a reference to a GP relative symbol, we want |
cdf6fd85 | 7269 | addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 RH |
7270 | Otherwise we want |
7271 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
7272 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
7273 | If we have a constant, we need two instructions anyhow, | |
d6bc6245 | 7274 | so we may as well always use the latter form. |
76b3015f | 7275 | |
6caf9ef4 TS |
7276 | With 64bit address space and a usable $at we want |
7277 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
7278 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
7279 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
7280 | daddiu $at,<sym> (BFD_RELOC_LO16) | |
7281 | dsll32 $tempreg,0 | |
7282 | daddu $tempreg,$tempreg,$at | |
7283 | ||
7284 | If $at is already in use, we use a path which is suboptimal | |
7285 | on superscalar processors. | |
7286 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
7287 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
7288 | dsll $tempreg,16 | |
7289 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
7290 | dsll $tempreg,16 | |
7291 | daddiu $tempreg,<sym> (BFD_RELOC_LO16) | |
7292 | ||
7293 | For GP relative symbols in 64bit address space we can use | |
7294 | the same sequence as in 32bit address space. */ | |
aed1a261 | 7295 | if (HAVE_64BIT_SYMBOLS) |
252b5132 | 7296 | { |
6caf9ef4 TS |
7297 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
7298 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
7299 | { | |
7300 | relax_start (offset_expr.X_add_symbol); | |
7301 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", | |
7302 | tempreg, mips_gp_register, BFD_RELOC_GPREL16); | |
7303 | relax_switch (); | |
7304 | } | |
d6bc6245 | 7305 | |
741fe287 | 7306 | if (used_at == 0 && mips_opts.at) |
98d3f06f | 7307 | { |
df58fc94 | 7308 | macro_build (&offset_expr, "lui", LUI_FMT, |
17a2f251 | 7309 | tempreg, BFD_RELOC_MIPS_HIGHEST); |
df58fc94 | 7310 | macro_build (&offset_expr, "lui", LUI_FMT, |
17a2f251 | 7311 | AT, BFD_RELOC_HI16_S); |
67c0d1eb | 7312 | macro_build (&offset_expr, "daddiu", "t,r,j", |
17a2f251 | 7313 | tempreg, tempreg, BFD_RELOC_MIPS_HIGHER); |
67c0d1eb | 7314 | macro_build (&offset_expr, "daddiu", "t,r,j", |
17a2f251 | 7315 | AT, AT, BFD_RELOC_LO16); |
df58fc94 | 7316 | macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0); |
67c0d1eb | 7317 | macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT); |
98d3f06f KH |
7318 | used_at = 1; |
7319 | } | |
7320 | else | |
7321 | { | |
df58fc94 | 7322 | macro_build (&offset_expr, "lui", LUI_FMT, |
17a2f251 | 7323 | tempreg, BFD_RELOC_MIPS_HIGHEST); |
67c0d1eb | 7324 | macro_build (&offset_expr, "daddiu", "t,r,j", |
17a2f251 | 7325 | tempreg, tempreg, BFD_RELOC_MIPS_HIGHER); |
df58fc94 | 7326 | macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16); |
67c0d1eb | 7327 | macro_build (&offset_expr, "daddiu", "t,r,j", |
17a2f251 | 7328 | tempreg, tempreg, BFD_RELOC_HI16_S); |
df58fc94 | 7329 | macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16); |
67c0d1eb | 7330 | macro_build (&offset_expr, "daddiu", "t,r,j", |
17a2f251 | 7331 | tempreg, tempreg, BFD_RELOC_LO16); |
98d3f06f | 7332 | } |
6caf9ef4 TS |
7333 | |
7334 | if (mips_relax.sequence) | |
7335 | relax_end (); | |
98d3f06f KH |
7336 | } |
7337 | else | |
7338 | { | |
7339 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET | |
6caf9ef4 | 7340 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
98d3f06f | 7341 | { |
4d7206a2 | 7342 | relax_start (offset_expr.X_add_symbol); |
67c0d1eb RS |
7343 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
7344 | tempreg, mips_gp_register, BFD_RELOC_GPREL16); | |
4d7206a2 | 7345 | relax_switch (); |
98d3f06f | 7346 | } |
6943caf0 | 7347 | if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number)) |
f71d0d44 | 7348 | as_bad (_("Offset too large")); |
67c0d1eb RS |
7349 | macro_build_lui (&offset_expr, tempreg); |
7350 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", | |
7351 | tempreg, tempreg, BFD_RELOC_LO16); | |
4d7206a2 RS |
7352 | if (mips_relax.sequence) |
7353 | relax_end (); | |
98d3f06f | 7354 | } |
252b5132 | 7355 | } |
0a44bf69 | 7356 | else if (!mips_big_got && !HAVE_NEWABI) |
252b5132 | 7357 | { |
9117d219 NC |
7358 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
7359 | ||
252b5132 RH |
7360 | /* If this is a reference to an external symbol, and there |
7361 | is no constant, we want | |
7362 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
1abe91b1 | 7363 | or for lca or if tempreg is PIC_CALL_REG |
9117d219 | 7364 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16) |
252b5132 RH |
7365 | For a local symbol, we want |
7366 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
7367 | nop | |
7368 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
7369 | ||
7370 | If we have a small constant, and this is a reference to | |
7371 | an external symbol, we want | |
7372 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
7373 | nop | |
7374 | addiu $tempreg,$tempreg,<constant> | |
7375 | For a local symbol, we want the same instruction | |
7376 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
7377 | addiu instruction. | |
7378 | ||
7379 | If we have a large constant, and this is a reference to | |
7380 | an external symbol, we want | |
7381 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
7382 | lui $at,<hiconstant> | |
7383 | addiu $at,$at,<loconstant> | |
7384 | addu $tempreg,$tempreg,$at | |
7385 | For a local symbol, we want the same instruction | |
7386 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
ed6fb7bd | 7387 | addiu instruction. |
ed6fb7bd SC |
7388 | */ |
7389 | ||
4d7206a2 | 7390 | if (offset_expr.X_add_number == 0) |
252b5132 | 7391 | { |
0a44bf69 RS |
7392 | if (mips_pic == SVR4_PIC |
7393 | && breg == 0 | |
7394 | && (call || tempreg == PIC_CALL_REG)) | |
4d7206a2 RS |
7395 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16; |
7396 | ||
7397 | relax_start (offset_expr.X_add_symbol); | |
67c0d1eb RS |
7398 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
7399 | lw_reloc_type, mips_gp_register); | |
4d7206a2 | 7400 | if (breg != 0) |
252b5132 RH |
7401 | { |
7402 | /* We're going to put in an addu instruction using | |
7403 | tempreg, so we may as well insert the nop right | |
7404 | now. */ | |
269137b2 | 7405 | load_delay_nop (); |
252b5132 | 7406 | } |
4d7206a2 | 7407 | relax_switch (); |
67c0d1eb RS |
7408 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
7409 | tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
269137b2 | 7410 | load_delay_nop (); |
67c0d1eb RS |
7411 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
7412 | tempreg, tempreg, BFD_RELOC_LO16); | |
4d7206a2 | 7413 | relax_end (); |
252b5132 RH |
7414 | /* FIXME: If breg == 0, and the next instruction uses |
7415 | $tempreg, then if this variant case is used an extra | |
7416 | nop will be generated. */ | |
7417 | } | |
4d7206a2 RS |
7418 | else if (offset_expr.X_add_number >= -0x8000 |
7419 | && offset_expr.X_add_number < 0x8000) | |
252b5132 | 7420 | { |
67c0d1eb | 7421 | load_got_offset (tempreg, &offset_expr); |
269137b2 | 7422 | load_delay_nop (); |
67c0d1eb | 7423 | add_got_offset (tempreg, &offset_expr); |
252b5132 RH |
7424 | } |
7425 | else | |
7426 | { | |
4d7206a2 RS |
7427 | expr1.X_add_number = offset_expr.X_add_number; |
7428 | offset_expr.X_add_number = | |
43c0598f | 7429 | SEXT_16BIT (offset_expr.X_add_number); |
67c0d1eb | 7430 | load_got_offset (tempreg, &offset_expr); |
f6a22291 | 7431 | offset_expr.X_add_number = expr1.X_add_number; |
252b5132 RH |
7432 | /* If we are going to add in a base register, and the |
7433 | target register and the base register are the same, | |
7434 | then we are using AT as a temporary register. Since | |
7435 | we want to load the constant into AT, we add our | |
7436 | current AT (from the global offset table) and the | |
7437 | register into the register now, and pretend we were | |
7438 | not using a base register. */ | |
67c0d1eb | 7439 | if (breg == treg) |
252b5132 | 7440 | { |
269137b2 | 7441 | load_delay_nop (); |
67c0d1eb | 7442 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7443 | treg, AT, breg); |
252b5132 RH |
7444 | breg = 0; |
7445 | tempreg = treg; | |
252b5132 | 7446 | } |
f6a22291 | 7447 | add_got_offset_hilo (tempreg, &offset_expr, AT); |
252b5132 RH |
7448 | used_at = 1; |
7449 | } | |
7450 | } | |
0a44bf69 | 7451 | else if (!mips_big_got && HAVE_NEWABI) |
f5040a92 | 7452 | { |
67c0d1eb | 7453 | int add_breg_early = 0; |
f5040a92 AO |
7454 | |
7455 | /* If this is a reference to an external, and there is no | |
7456 | constant, or local symbol (*), with or without a | |
7457 | constant, we want | |
7458 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) | |
1abe91b1 | 7459 | or for lca or if tempreg is PIC_CALL_REG |
f5040a92 AO |
7460 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16) |
7461 | ||
7462 | If we have a small constant, and this is a reference to | |
7463 | an external symbol, we want | |
7464 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) | |
7465 | addiu $tempreg,$tempreg,<constant> | |
7466 | ||
7467 | If we have a large constant, and this is a reference to | |
7468 | an external symbol, we want | |
7469 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) | |
7470 | lui $at,<hiconstant> | |
7471 | addiu $at,$at,<loconstant> | |
7472 | addu $tempreg,$tempreg,$at | |
7473 | ||
7474 | (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for | |
7475 | local symbols, even though it introduces an additional | |
7476 | instruction. */ | |
7477 | ||
f5040a92 AO |
7478 | if (offset_expr.X_add_number) |
7479 | { | |
4d7206a2 | 7480 | expr1.X_add_number = offset_expr.X_add_number; |
f5040a92 AO |
7481 | offset_expr.X_add_number = 0; |
7482 | ||
4d7206a2 | 7483 | relax_start (offset_expr.X_add_symbol); |
67c0d1eb RS |
7484 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
7485 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); | |
f5040a92 AO |
7486 | |
7487 | if (expr1.X_add_number >= -0x8000 | |
7488 | && expr1.X_add_number < 0x8000) | |
7489 | { | |
67c0d1eb RS |
7490 | macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j", |
7491 | tempreg, tempreg, BFD_RELOC_LO16); | |
f5040a92 | 7492 | } |
ecd13cd3 | 7493 | else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000)) |
f5040a92 | 7494 | { |
f5040a92 AO |
7495 | /* If we are going to add in a base register, and the |
7496 | target register and the base register are the same, | |
7497 | then we are using AT as a temporary register. Since | |
7498 | we want to load the constant into AT, we add our | |
7499 | current AT (from the global offset table) and the | |
7500 | register into the register now, and pretend we were | |
7501 | not using a base register. */ | |
7502 | if (breg != treg) | |
7503 | dreg = tempreg; | |
7504 | else | |
7505 | { | |
9c2799c2 | 7506 | gas_assert (tempreg == AT); |
67c0d1eb RS |
7507 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
7508 | treg, AT, breg); | |
f5040a92 | 7509 | dreg = treg; |
67c0d1eb | 7510 | add_breg_early = 1; |
f5040a92 AO |
7511 | } |
7512 | ||
f6a22291 | 7513 | load_register (AT, &expr1, HAVE_64BIT_ADDRESSES); |
67c0d1eb | 7514 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7515 | dreg, dreg, AT); |
f5040a92 | 7516 | |
f5040a92 AO |
7517 | used_at = 1; |
7518 | } | |
7519 | else | |
7520 | as_bad (_("PIC code offset overflow (max 32 signed bits)")); | |
7521 | ||
4d7206a2 | 7522 | relax_switch (); |
f5040a92 AO |
7523 | offset_expr.X_add_number = expr1.X_add_number; |
7524 | ||
67c0d1eb RS |
7525 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
7526 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); | |
7527 | if (add_breg_early) | |
f5040a92 | 7528 | { |
67c0d1eb | 7529 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
f899b4b8 | 7530 | treg, tempreg, breg); |
f5040a92 AO |
7531 | breg = 0; |
7532 | tempreg = treg; | |
7533 | } | |
4d7206a2 | 7534 | relax_end (); |
f5040a92 | 7535 | } |
4d7206a2 | 7536 | else if (breg == 0 && (call || tempreg == PIC_CALL_REG)) |
f5040a92 | 7537 | { |
4d7206a2 | 7538 | relax_start (offset_expr.X_add_symbol); |
67c0d1eb RS |
7539 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
7540 | BFD_RELOC_MIPS_CALL16, mips_gp_register); | |
4d7206a2 | 7541 | relax_switch (); |
67c0d1eb RS |
7542 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
7543 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); | |
4d7206a2 | 7544 | relax_end (); |
f5040a92 | 7545 | } |
4d7206a2 | 7546 | else |
f5040a92 | 7547 | { |
67c0d1eb RS |
7548 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
7549 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); | |
f5040a92 AO |
7550 | } |
7551 | } | |
0a44bf69 | 7552 | else if (mips_big_got && !HAVE_NEWABI) |
252b5132 | 7553 | { |
67c0d1eb | 7554 | int gpdelay; |
9117d219 NC |
7555 | int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16; |
7556 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16; | |
ed6fb7bd | 7557 | int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
252b5132 RH |
7558 | |
7559 | /* This is the large GOT case. If this is a reference to an | |
7560 | external symbol, and there is no constant, we want | |
7561 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
7562 | addu $tempreg,$tempreg,$gp | |
7563 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
1abe91b1 | 7564 | or for lca or if tempreg is PIC_CALL_REG |
9117d219 NC |
7565 | lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16) |
7566 | addu $tempreg,$tempreg,$gp | |
7567 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16) | |
252b5132 RH |
7568 | For a local symbol, we want |
7569 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
7570 | nop | |
7571 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
7572 | ||
7573 | If we have a small constant, and this is a reference to | |
7574 | an external symbol, we want | |
7575 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
7576 | addu $tempreg,$tempreg,$gp | |
7577 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
7578 | nop | |
7579 | addiu $tempreg,$tempreg,<constant> | |
7580 | For a local symbol, we want | |
7581 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
7582 | nop | |
7583 | addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16) | |
7584 | ||
7585 | If we have a large constant, and this is a reference to | |
7586 | an external symbol, we want | |
7587 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
7588 | addu $tempreg,$tempreg,$gp | |
7589 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
7590 | lui $at,<hiconstant> | |
7591 | addiu $at,$at,<loconstant> | |
7592 | addu $tempreg,$tempreg,$at | |
7593 | For a local symbol, we want | |
7594 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
7595 | lui $at,<hiconstant> | |
7596 | addiu $at,$at,<loconstant> (BFD_RELOC_LO16) | |
7597 | addu $tempreg,$tempreg,$at | |
f5040a92 | 7598 | */ |
438c16b8 | 7599 | |
252b5132 RH |
7600 | expr1.X_add_number = offset_expr.X_add_number; |
7601 | offset_expr.X_add_number = 0; | |
4d7206a2 | 7602 | relax_start (offset_expr.X_add_symbol); |
67c0d1eb | 7603 | gpdelay = reg_needs_delay (mips_gp_register); |
1abe91b1 MR |
7604 | if (expr1.X_add_number == 0 && breg == 0 |
7605 | && (call || tempreg == PIC_CALL_REG)) | |
9117d219 NC |
7606 | { |
7607 | lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16; | |
7608 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16; | |
7609 | } | |
df58fc94 | 7610 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type); |
67c0d1eb | 7611 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7612 | tempreg, tempreg, mips_gp_register); |
67c0d1eb | 7613 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
17a2f251 | 7614 | tempreg, lw_reloc_type, tempreg); |
252b5132 RH |
7615 | if (expr1.X_add_number == 0) |
7616 | { | |
67c0d1eb | 7617 | if (breg != 0) |
252b5132 RH |
7618 | { |
7619 | /* We're going to put in an addu instruction using | |
7620 | tempreg, so we may as well insert the nop right | |
7621 | now. */ | |
269137b2 | 7622 | load_delay_nop (); |
252b5132 | 7623 | } |
252b5132 RH |
7624 | } |
7625 | else if (expr1.X_add_number >= -0x8000 | |
7626 | && expr1.X_add_number < 0x8000) | |
7627 | { | |
269137b2 | 7628 | load_delay_nop (); |
67c0d1eb | 7629 | macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j", |
17a2f251 | 7630 | tempreg, tempreg, BFD_RELOC_LO16); |
252b5132 RH |
7631 | } |
7632 | else | |
7633 | { | |
252b5132 RH |
7634 | /* If we are going to add in a base register, and the |
7635 | target register and the base register are the same, | |
7636 | then we are using AT as a temporary register. Since | |
7637 | we want to load the constant into AT, we add our | |
7638 | current AT (from the global offset table) and the | |
7639 | register into the register now, and pretend we were | |
7640 | not using a base register. */ | |
7641 | if (breg != treg) | |
67c0d1eb | 7642 | dreg = tempreg; |
252b5132 RH |
7643 | else |
7644 | { | |
9c2799c2 | 7645 | gas_assert (tempreg == AT); |
269137b2 | 7646 | load_delay_nop (); |
67c0d1eb | 7647 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7648 | treg, AT, breg); |
252b5132 | 7649 | dreg = treg; |
252b5132 RH |
7650 | } |
7651 | ||
f6a22291 | 7652 | load_register (AT, &expr1, HAVE_64BIT_ADDRESSES); |
67c0d1eb | 7653 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT); |
252b5132 | 7654 | |
252b5132 RH |
7655 | used_at = 1; |
7656 | } | |
43c0598f | 7657 | offset_expr.X_add_number = SEXT_16BIT (expr1.X_add_number); |
4d7206a2 | 7658 | relax_switch (); |
252b5132 | 7659 | |
67c0d1eb | 7660 | if (gpdelay) |
252b5132 RH |
7661 | { |
7662 | /* This is needed because this instruction uses $gp, but | |
f5040a92 | 7663 | the first instruction on the main stream does not. */ |
67c0d1eb | 7664 | macro_build (NULL, "nop", ""); |
252b5132 | 7665 | } |
ed6fb7bd | 7666 | |
67c0d1eb RS |
7667 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
7668 | local_reloc_type, mips_gp_register); | |
f5040a92 | 7669 | if (expr1.X_add_number >= -0x8000 |
252b5132 RH |
7670 | && expr1.X_add_number < 0x8000) |
7671 | { | |
269137b2 | 7672 | load_delay_nop (); |
67c0d1eb RS |
7673 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
7674 | tempreg, tempreg, BFD_RELOC_LO16); | |
252b5132 | 7675 | /* FIXME: If add_number is 0, and there was no base |
f5040a92 AO |
7676 | register, the external symbol case ended with a load, |
7677 | so if the symbol turns out to not be external, and | |
7678 | the next instruction uses tempreg, an unnecessary nop | |
7679 | will be inserted. */ | |
252b5132 RH |
7680 | } |
7681 | else | |
7682 | { | |
7683 | if (breg == treg) | |
7684 | { | |
7685 | /* We must add in the base register now, as in the | |
f5040a92 | 7686 | external symbol case. */ |
9c2799c2 | 7687 | gas_assert (tempreg == AT); |
269137b2 | 7688 | load_delay_nop (); |
67c0d1eb | 7689 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7690 | treg, AT, breg); |
252b5132 RH |
7691 | tempreg = treg; |
7692 | /* We set breg to 0 because we have arranged to add | |
f5040a92 | 7693 | it in in both cases. */ |
252b5132 RH |
7694 | breg = 0; |
7695 | } | |
7696 | ||
67c0d1eb RS |
7697 | macro_build_lui (&expr1, AT); |
7698 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", | |
17a2f251 | 7699 | AT, AT, BFD_RELOC_LO16); |
67c0d1eb | 7700 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7701 | tempreg, tempreg, AT); |
8fc2e39e | 7702 | used_at = 1; |
252b5132 | 7703 | } |
4d7206a2 | 7704 | relax_end (); |
252b5132 | 7705 | } |
0a44bf69 | 7706 | else if (mips_big_got && HAVE_NEWABI) |
f5040a92 | 7707 | { |
f5040a92 AO |
7708 | int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16; |
7709 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16; | |
67c0d1eb | 7710 | int add_breg_early = 0; |
f5040a92 AO |
7711 | |
7712 | /* This is the large GOT case. If this is a reference to an | |
7713 | external symbol, and there is no constant, we want | |
7714 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
7715 | add $tempreg,$tempreg,$gp | |
7716 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
1abe91b1 | 7717 | or for lca or if tempreg is PIC_CALL_REG |
f5040a92 AO |
7718 | lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16) |
7719 | add $tempreg,$tempreg,$gp | |
7720 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16) | |
7721 | ||
7722 | If we have a small constant, and this is a reference to | |
7723 | an external symbol, we want | |
7724 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
7725 | add $tempreg,$tempreg,$gp | |
7726 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
7727 | addi $tempreg,$tempreg,<constant> | |
7728 | ||
7729 | If we have a large constant, and this is a reference to | |
7730 | an external symbol, we want | |
7731 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
7732 | addu $tempreg,$tempreg,$gp | |
7733 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
7734 | lui $at,<hiconstant> | |
7735 | addi $at,$at,<loconstant> | |
7736 | add $tempreg,$tempreg,$at | |
7737 | ||
7738 | If we have NewABI, and we know it's a local symbol, we want | |
7739 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) | |
7740 | addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST) | |
7741 | otherwise we have to resort to GOT_HI16/GOT_LO16. */ | |
7742 | ||
4d7206a2 | 7743 | relax_start (offset_expr.X_add_symbol); |
f5040a92 | 7744 | |
4d7206a2 | 7745 | expr1.X_add_number = offset_expr.X_add_number; |
f5040a92 AO |
7746 | offset_expr.X_add_number = 0; |
7747 | ||
1abe91b1 MR |
7748 | if (expr1.X_add_number == 0 && breg == 0 |
7749 | && (call || tempreg == PIC_CALL_REG)) | |
f5040a92 AO |
7750 | { |
7751 | lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16; | |
7752 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16; | |
7753 | } | |
df58fc94 | 7754 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type); |
67c0d1eb | 7755 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7756 | tempreg, tempreg, mips_gp_register); |
67c0d1eb RS |
7757 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
7758 | tempreg, lw_reloc_type, tempreg); | |
f5040a92 AO |
7759 | |
7760 | if (expr1.X_add_number == 0) | |
4d7206a2 | 7761 | ; |
f5040a92 AO |
7762 | else if (expr1.X_add_number >= -0x8000 |
7763 | && expr1.X_add_number < 0x8000) | |
7764 | { | |
67c0d1eb | 7765 | macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j", |
17a2f251 | 7766 | tempreg, tempreg, BFD_RELOC_LO16); |
f5040a92 | 7767 | } |
ecd13cd3 | 7768 | else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000)) |
f5040a92 | 7769 | { |
f5040a92 AO |
7770 | /* If we are going to add in a base register, and the |
7771 | target register and the base register are the same, | |
7772 | then we are using AT as a temporary register. Since | |
7773 | we want to load the constant into AT, we add our | |
7774 | current AT (from the global offset table) and the | |
7775 | register into the register now, and pretend we were | |
7776 | not using a base register. */ | |
7777 | if (breg != treg) | |
7778 | dreg = tempreg; | |
7779 | else | |
7780 | { | |
9c2799c2 | 7781 | gas_assert (tempreg == AT); |
67c0d1eb | 7782 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7783 | treg, AT, breg); |
f5040a92 | 7784 | dreg = treg; |
67c0d1eb | 7785 | add_breg_early = 1; |
f5040a92 AO |
7786 | } |
7787 | ||
f6a22291 | 7788 | load_register (AT, &expr1, HAVE_64BIT_ADDRESSES); |
67c0d1eb | 7789 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT); |
f5040a92 | 7790 | |
f5040a92 AO |
7791 | used_at = 1; |
7792 | } | |
7793 | else | |
7794 | as_bad (_("PIC code offset overflow (max 32 signed bits)")); | |
7795 | ||
4d7206a2 | 7796 | relax_switch (); |
f5040a92 | 7797 | offset_expr.X_add_number = expr1.X_add_number; |
67c0d1eb RS |
7798 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
7799 | BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); | |
7800 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg, | |
7801 | tempreg, BFD_RELOC_MIPS_GOT_OFST); | |
7802 | if (add_breg_early) | |
f5040a92 | 7803 | { |
67c0d1eb | 7804 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 7805 | treg, tempreg, breg); |
f5040a92 AO |
7806 | breg = 0; |
7807 | tempreg = treg; | |
7808 | } | |
4d7206a2 | 7809 | relax_end (); |
f5040a92 | 7810 | } |
252b5132 RH |
7811 | else |
7812 | abort (); | |
7813 | ||
7814 | if (breg != 0) | |
aed1a261 | 7815 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg); |
252b5132 RH |
7816 | break; |
7817 | ||
52b6b6b9 | 7818 | case M_MSGSND: |
df58fc94 | 7819 | gas_assert (!mips_opts.micromips); |
52b6b6b9 JM |
7820 | { |
7821 | unsigned long temp = (treg << 16) | (0x01); | |
7822 | macro_build (NULL, "c2", "C", temp); | |
7823 | } | |
c7af4273 | 7824 | break; |
52b6b6b9 JM |
7825 | |
7826 | case M_MSGLD: | |
df58fc94 | 7827 | gas_assert (!mips_opts.micromips); |
52b6b6b9 JM |
7828 | { |
7829 | unsigned long temp = (0x02); | |
7830 | macro_build (NULL, "c2", "C", temp); | |
7831 | } | |
c7af4273 | 7832 | break; |
52b6b6b9 JM |
7833 | |
7834 | case M_MSGLD_T: | |
df58fc94 | 7835 | gas_assert (!mips_opts.micromips); |
52b6b6b9 JM |
7836 | { |
7837 | unsigned long temp = (treg << 16) | (0x02); | |
7838 | macro_build (NULL, "c2", "C", temp); | |
7839 | } | |
c7af4273 | 7840 | break; |
52b6b6b9 JM |
7841 | |
7842 | case M_MSGWAIT: | |
df58fc94 | 7843 | gas_assert (!mips_opts.micromips); |
52b6b6b9 | 7844 | macro_build (NULL, "c2", "C", 3); |
c7af4273 | 7845 | break; |
52b6b6b9 JM |
7846 | |
7847 | case M_MSGWAIT_T: | |
df58fc94 | 7848 | gas_assert (!mips_opts.micromips); |
52b6b6b9 JM |
7849 | { |
7850 | unsigned long temp = (treg << 16) | 0x03; | |
7851 | macro_build (NULL, "c2", "C", temp); | |
7852 | } | |
c7af4273 | 7853 | break; |
52b6b6b9 | 7854 | |
252b5132 RH |
7855 | case M_J_A: |
7856 | /* The j instruction may not be used in PIC code, since it | |
7857 | requires an absolute address. We convert it to a b | |
7858 | instruction. */ | |
7859 | if (mips_pic == NO_PIC) | |
67c0d1eb | 7860 | macro_build (&offset_expr, "j", "a"); |
252b5132 | 7861 | else |
67c0d1eb | 7862 | macro_build (&offset_expr, "b", "p"); |
8fc2e39e | 7863 | break; |
252b5132 RH |
7864 | |
7865 | /* The jal instructions must be handled as macros because when | |
7866 | generating PIC code they expand to multi-instruction | |
7867 | sequences. Normally they are simple instructions. */ | |
df58fc94 RS |
7868 | case M_JALS_1: |
7869 | dreg = RA; | |
7870 | /* Fall through. */ | |
7871 | case M_JALS_2: | |
7872 | gas_assert (mips_opts.micromips); | |
7873 | jals = 1; | |
7874 | goto jal; | |
252b5132 RH |
7875 | case M_JAL_1: |
7876 | dreg = RA; | |
7877 | /* Fall through. */ | |
7878 | case M_JAL_2: | |
df58fc94 | 7879 | jal: |
3e722fb5 | 7880 | if (mips_pic == NO_PIC) |
df58fc94 RS |
7881 | { |
7882 | s = jals ? "jalrs" : "jalr"; | |
e64af278 MR |
7883 | if (mips_opts.micromips |
7884 | && dreg == RA | |
7885 | && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) | |
df58fc94 RS |
7886 | macro_build (NULL, s, "mj", sreg); |
7887 | else | |
7888 | macro_build (NULL, s, JALR_FMT, dreg, sreg); | |
7889 | } | |
0a44bf69 | 7890 | else |
252b5132 | 7891 | { |
df58fc94 RS |
7892 | int cprestore = (mips_pic == SVR4_PIC && !HAVE_NEWABI |
7893 | && mips_cprestore_offset >= 0); | |
7894 | ||
252b5132 RH |
7895 | if (sreg != PIC_CALL_REG) |
7896 | as_warn (_("MIPS PIC call to register other than $25")); | |
bdaaa2e1 | 7897 | |
df58fc94 RS |
7898 | s = (mips_opts.micromips && (!mips_opts.noreorder || cprestore) |
7899 | ? "jalrs" : "jalr"); | |
e64af278 MR |
7900 | if (mips_opts.micromips |
7901 | && dreg == RA | |
7902 | && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) | |
df58fc94 RS |
7903 | macro_build (NULL, s, "mj", sreg); |
7904 | else | |
7905 | macro_build (NULL, s, JALR_FMT, dreg, sreg); | |
0a44bf69 | 7906 | if (mips_pic == SVR4_PIC && !HAVE_NEWABI) |
252b5132 | 7907 | { |
6478892d TS |
7908 | if (mips_cprestore_offset < 0) |
7909 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
7910 | else | |
7911 | { | |
90ecf173 | 7912 | if (!mips_frame_reg_valid) |
7a621144 DJ |
7913 | { |
7914 | as_warn (_("No .frame pseudo-op used in PIC code")); | |
7915 | /* Quiet this warning. */ | |
7916 | mips_frame_reg_valid = 1; | |
7917 | } | |
90ecf173 | 7918 | if (!mips_cprestore_valid) |
7a621144 DJ |
7919 | { |
7920 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
7921 | /* Quiet this warning. */ | |
7922 | mips_cprestore_valid = 1; | |
7923 | } | |
d3fca0b5 MR |
7924 | if (mips_opts.noreorder) |
7925 | macro_build (NULL, "nop", ""); | |
6478892d | 7926 | expr1.X_add_number = mips_cprestore_offset; |
67c0d1eb | 7927 | macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN, |
f899b4b8 | 7928 | mips_gp_register, |
256ab948 TS |
7929 | mips_frame_reg, |
7930 | HAVE_64BIT_ADDRESSES); | |
6478892d | 7931 | } |
252b5132 RH |
7932 | } |
7933 | } | |
252b5132 | 7934 | |
8fc2e39e | 7935 | break; |
252b5132 | 7936 | |
df58fc94 RS |
7937 | case M_JALS_A: |
7938 | gas_assert (mips_opts.micromips); | |
7939 | jals = 1; | |
7940 | /* Fall through. */ | |
252b5132 RH |
7941 | case M_JAL_A: |
7942 | if (mips_pic == NO_PIC) | |
df58fc94 | 7943 | macro_build (&offset_expr, jals ? "jals" : "jal", "a"); |
252b5132 RH |
7944 | else if (mips_pic == SVR4_PIC) |
7945 | { | |
7946 | /* If this is a reference to an external symbol, and we are | |
7947 | using a small GOT, we want | |
7948 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
7949 | nop | |
f9419b05 | 7950 | jalr $ra,$25 |
252b5132 RH |
7951 | nop |
7952 | lw $gp,cprestore($sp) | |
7953 | The cprestore value is set using the .cprestore | |
7954 | pseudo-op. If we are using a big GOT, we want | |
7955 | lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
7956 | addu $25,$25,$gp | |
7957 | lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16) | |
7958 | nop | |
f9419b05 | 7959 | jalr $ra,$25 |
252b5132 RH |
7960 | nop |
7961 | lw $gp,cprestore($sp) | |
7962 | If the symbol is not external, we want | |
7963 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
7964 | nop | |
7965 | addiu $25,$25,<sym> (BFD_RELOC_LO16) | |
f9419b05 | 7966 | jalr $ra,$25 |
252b5132 | 7967 | nop |
438c16b8 | 7968 | lw $gp,cprestore($sp) |
f5040a92 AO |
7969 | |
7970 | For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16 | |
7971 | sequences above, minus nops, unless the symbol is local, | |
7972 | which enables us to use GOT_PAGE/GOT_OFST (big got) or | |
7973 | GOT_DISP. */ | |
438c16b8 | 7974 | if (HAVE_NEWABI) |
252b5132 | 7975 | { |
90ecf173 | 7976 | if (!mips_big_got) |
f5040a92 | 7977 | { |
4d7206a2 | 7978 | relax_start (offset_expr.X_add_symbol); |
67c0d1eb RS |
7979 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
7980 | PIC_CALL_REG, BFD_RELOC_MIPS_CALL16, | |
f5040a92 | 7981 | mips_gp_register); |
4d7206a2 | 7982 | relax_switch (); |
67c0d1eb RS |
7983 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
7984 | PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP, | |
4d7206a2 RS |
7985 | mips_gp_register); |
7986 | relax_end (); | |
f5040a92 AO |
7987 | } |
7988 | else | |
7989 | { | |
4d7206a2 | 7990 | relax_start (offset_expr.X_add_symbol); |
df58fc94 | 7991 | macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG, |
67c0d1eb RS |
7992 | BFD_RELOC_MIPS_CALL_HI16); |
7993 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG, | |
7994 | PIC_CALL_REG, mips_gp_register); | |
7995 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", | |
7996 | PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16, | |
7997 | PIC_CALL_REG); | |
4d7206a2 | 7998 | relax_switch (); |
67c0d1eb RS |
7999 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
8000 | PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE, | |
8001 | mips_gp_register); | |
8002 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", | |
8003 | PIC_CALL_REG, PIC_CALL_REG, | |
17a2f251 | 8004 | BFD_RELOC_MIPS_GOT_OFST); |
4d7206a2 | 8005 | relax_end (); |
f5040a92 | 8006 | } |
684022ea | 8007 | |
df58fc94 | 8008 | macro_build_jalr (&offset_expr, 0); |
252b5132 RH |
8009 | } |
8010 | else | |
8011 | { | |
4d7206a2 | 8012 | relax_start (offset_expr.X_add_symbol); |
90ecf173 | 8013 | if (!mips_big_got) |
438c16b8 | 8014 | { |
67c0d1eb RS |
8015 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
8016 | PIC_CALL_REG, BFD_RELOC_MIPS_CALL16, | |
17a2f251 | 8017 | mips_gp_register); |
269137b2 | 8018 | load_delay_nop (); |
4d7206a2 | 8019 | relax_switch (); |
438c16b8 | 8020 | } |
252b5132 | 8021 | else |
252b5132 | 8022 | { |
67c0d1eb RS |
8023 | int gpdelay; |
8024 | ||
8025 | gpdelay = reg_needs_delay (mips_gp_register); | |
df58fc94 | 8026 | macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG, |
67c0d1eb RS |
8027 | BFD_RELOC_MIPS_CALL_HI16); |
8028 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG, | |
8029 | PIC_CALL_REG, mips_gp_register); | |
8030 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", | |
8031 | PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16, | |
8032 | PIC_CALL_REG); | |
269137b2 | 8033 | load_delay_nop (); |
4d7206a2 | 8034 | relax_switch (); |
67c0d1eb RS |
8035 | if (gpdelay) |
8036 | macro_build (NULL, "nop", ""); | |
252b5132 | 8037 | } |
67c0d1eb RS |
8038 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
8039 | PIC_CALL_REG, BFD_RELOC_MIPS_GOT16, | |
4d7206a2 | 8040 | mips_gp_register); |
269137b2 | 8041 | load_delay_nop (); |
67c0d1eb RS |
8042 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
8043 | PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16); | |
4d7206a2 | 8044 | relax_end (); |
df58fc94 | 8045 | macro_build_jalr (&offset_expr, mips_cprestore_offset >= 0); |
438c16b8 | 8046 | |
6478892d TS |
8047 | if (mips_cprestore_offset < 0) |
8048 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
8049 | else | |
8050 | { | |
90ecf173 | 8051 | if (!mips_frame_reg_valid) |
7a621144 DJ |
8052 | { |
8053 | as_warn (_("No .frame pseudo-op used in PIC code")); | |
8054 | /* Quiet this warning. */ | |
8055 | mips_frame_reg_valid = 1; | |
8056 | } | |
90ecf173 | 8057 | if (!mips_cprestore_valid) |
7a621144 DJ |
8058 | { |
8059 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
8060 | /* Quiet this warning. */ | |
8061 | mips_cprestore_valid = 1; | |
8062 | } | |
6478892d | 8063 | if (mips_opts.noreorder) |
67c0d1eb | 8064 | macro_build (NULL, "nop", ""); |
6478892d | 8065 | expr1.X_add_number = mips_cprestore_offset; |
67c0d1eb | 8066 | macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN, |
f899b4b8 | 8067 | mips_gp_register, |
256ab948 TS |
8068 | mips_frame_reg, |
8069 | HAVE_64BIT_ADDRESSES); | |
6478892d | 8070 | } |
252b5132 RH |
8071 | } |
8072 | } | |
0a44bf69 RS |
8073 | else if (mips_pic == VXWORKS_PIC) |
8074 | as_bad (_("Non-PIC jump used in PIC library")); | |
252b5132 RH |
8075 | else |
8076 | abort (); | |
8077 | ||
8fc2e39e | 8078 | break; |
252b5132 | 8079 | |
dec0624d MR |
8080 | case M_ACLR_AB: |
8081 | ab = 1; | |
8082 | case M_ACLR_OB: | |
8083 | s = "aclr"; | |
8084 | treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip); | |
8085 | fmt = "\\,~(b)"; | |
8086 | off12 = 1; | |
8087 | goto ld_st; | |
8088 | case M_ASET_AB: | |
8089 | ab = 1; | |
8090 | case M_ASET_OB: | |
8091 | s = "aset"; | |
8092 | treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip); | |
8093 | fmt = "\\,~(b)"; | |
8094 | off12 = 1; | |
8095 | goto ld_st; | |
252b5132 | 8096 | case M_LB_AB: |
df58fc94 | 8097 | ab = 1; |
252b5132 | 8098 | s = "lb"; |
df58fc94 | 8099 | fmt = "t,o(b)"; |
252b5132 RH |
8100 | goto ld; |
8101 | case M_LBU_AB: | |
df58fc94 | 8102 | ab = 1; |
252b5132 | 8103 | s = "lbu"; |
df58fc94 | 8104 | fmt = "t,o(b)"; |
252b5132 RH |
8105 | goto ld; |
8106 | case M_LH_AB: | |
df58fc94 | 8107 | ab = 1; |
252b5132 | 8108 | s = "lh"; |
df58fc94 | 8109 | fmt = "t,o(b)"; |
252b5132 RH |
8110 | goto ld; |
8111 | case M_LHU_AB: | |
df58fc94 | 8112 | ab = 1; |
252b5132 | 8113 | s = "lhu"; |
df58fc94 | 8114 | fmt = "t,o(b)"; |
252b5132 RH |
8115 | goto ld; |
8116 | case M_LW_AB: | |
df58fc94 | 8117 | ab = 1; |
252b5132 | 8118 | s = "lw"; |
df58fc94 | 8119 | fmt = "t,o(b)"; |
252b5132 RH |
8120 | goto ld; |
8121 | case M_LWC0_AB: | |
df58fc94 RS |
8122 | ab = 1; |
8123 | gas_assert (!mips_opts.micromips); | |
252b5132 | 8124 | s = "lwc0"; |
df58fc94 | 8125 | fmt = "E,o(b)"; |
bdaaa2e1 | 8126 | /* Itbl support may require additional care here. */ |
252b5132 | 8127 | coproc = 1; |
df58fc94 | 8128 | goto ld_st; |
252b5132 | 8129 | case M_LWC1_AB: |
df58fc94 | 8130 | ab = 1; |
252b5132 | 8131 | s = "lwc1"; |
df58fc94 | 8132 | fmt = "T,o(b)"; |
bdaaa2e1 | 8133 | /* Itbl support may require additional care here. */ |
252b5132 | 8134 | coproc = 1; |
df58fc94 | 8135 | goto ld_st; |
252b5132 | 8136 | case M_LWC2_AB: |
df58fc94 RS |
8137 | ab = 1; |
8138 | case M_LWC2_OB: | |
252b5132 | 8139 | s = "lwc2"; |
df58fc94 RS |
8140 | fmt = COP12_FMT; |
8141 | off12 = mips_opts.micromips; | |
bdaaa2e1 | 8142 | /* Itbl support may require additional care here. */ |
252b5132 | 8143 | coproc = 1; |
df58fc94 | 8144 | goto ld_st; |
252b5132 | 8145 | case M_LWC3_AB: |
df58fc94 RS |
8146 | ab = 1; |
8147 | gas_assert (!mips_opts.micromips); | |
252b5132 | 8148 | s = "lwc3"; |
df58fc94 | 8149 | fmt = "E,o(b)"; |
bdaaa2e1 | 8150 | /* Itbl support may require additional care here. */ |
252b5132 | 8151 | coproc = 1; |
df58fc94 | 8152 | goto ld_st; |
252b5132 | 8153 | case M_LWL_AB: |
df58fc94 RS |
8154 | ab = 1; |
8155 | case M_LWL_OB: | |
252b5132 | 8156 | s = "lwl"; |
df58fc94 RS |
8157 | fmt = MEM12_FMT; |
8158 | off12 = mips_opts.micromips; | |
8159 | goto ld_st; | |
252b5132 | 8160 | case M_LWR_AB: |
df58fc94 RS |
8161 | ab = 1; |
8162 | case M_LWR_OB: | |
252b5132 | 8163 | s = "lwr"; |
df58fc94 RS |
8164 | fmt = MEM12_FMT; |
8165 | off12 = mips_opts.micromips; | |
8166 | goto ld_st; | |
252b5132 | 8167 | case M_LDC1_AB: |
df58fc94 | 8168 | ab = 1; |
252b5132 | 8169 | s = "ldc1"; |
df58fc94 | 8170 | fmt = "T,o(b)"; |
bdaaa2e1 | 8171 | /* Itbl support may require additional care here. */ |
252b5132 | 8172 | coproc = 1; |
df58fc94 | 8173 | goto ld_st; |
252b5132 | 8174 | case M_LDC2_AB: |
df58fc94 RS |
8175 | ab = 1; |
8176 | case M_LDC2_OB: | |
252b5132 | 8177 | s = "ldc2"; |
df58fc94 RS |
8178 | fmt = COP12_FMT; |
8179 | off12 = mips_opts.micromips; | |
bdaaa2e1 | 8180 | /* Itbl support may require additional care here. */ |
252b5132 | 8181 | coproc = 1; |
df58fc94 | 8182 | goto ld_st; |
252b5132 | 8183 | case M_LDC3_AB: |
df58fc94 | 8184 | ab = 1; |
252b5132 | 8185 | s = "ldc3"; |
df58fc94 | 8186 | fmt = "E,o(b)"; |
bdaaa2e1 | 8187 | /* Itbl support may require additional care here. */ |
252b5132 | 8188 | coproc = 1; |
df58fc94 | 8189 | goto ld_st; |
252b5132 | 8190 | case M_LDL_AB: |
df58fc94 RS |
8191 | ab = 1; |
8192 | case M_LDL_OB: | |
252b5132 | 8193 | s = "ldl"; |
df58fc94 RS |
8194 | fmt = MEM12_FMT; |
8195 | off12 = mips_opts.micromips; | |
8196 | goto ld_st; | |
252b5132 | 8197 | case M_LDR_AB: |
df58fc94 RS |
8198 | ab = 1; |
8199 | case M_LDR_OB: | |
252b5132 | 8200 | s = "ldr"; |
df58fc94 RS |
8201 | fmt = MEM12_FMT; |
8202 | off12 = mips_opts.micromips; | |
8203 | goto ld_st; | |
252b5132 | 8204 | case M_LL_AB: |
df58fc94 RS |
8205 | ab = 1; |
8206 | case M_LL_OB: | |
252b5132 | 8207 | s = "ll"; |
df58fc94 RS |
8208 | fmt = MEM12_FMT; |
8209 | off12 = mips_opts.micromips; | |
252b5132 RH |
8210 | goto ld; |
8211 | case M_LLD_AB: | |
df58fc94 RS |
8212 | ab = 1; |
8213 | case M_LLD_OB: | |
252b5132 | 8214 | s = "lld"; |
df58fc94 RS |
8215 | fmt = MEM12_FMT; |
8216 | off12 = mips_opts.micromips; | |
252b5132 RH |
8217 | goto ld; |
8218 | case M_LWU_AB: | |
df58fc94 RS |
8219 | ab = 1; |
8220 | case M_LWU_OB: | |
252b5132 | 8221 | s = "lwu"; |
df58fc94 RS |
8222 | fmt = MEM12_FMT; |
8223 | off12 = mips_opts.micromips; | |
8224 | goto ld; | |
8225 | case M_LWP_AB: | |
8226 | ab = 1; | |
8227 | case M_LWP_OB: | |
8228 | gas_assert (mips_opts.micromips); | |
8229 | s = "lwp"; | |
8230 | fmt = "t,~(b)"; | |
8231 | off12 = 1; | |
8232 | lp = 1; | |
8233 | goto ld; | |
8234 | case M_LDP_AB: | |
8235 | ab = 1; | |
8236 | case M_LDP_OB: | |
8237 | gas_assert (mips_opts.micromips); | |
8238 | s = "ldp"; | |
8239 | fmt = "t,~(b)"; | |
8240 | off12 = 1; | |
8241 | lp = 1; | |
8242 | goto ld; | |
8243 | case M_LWM_AB: | |
8244 | ab = 1; | |
8245 | case M_LWM_OB: | |
8246 | gas_assert (mips_opts.micromips); | |
8247 | s = "lwm"; | |
8248 | fmt = "n,~(b)"; | |
8249 | off12 = 1; | |
8250 | goto ld_st; | |
8251 | case M_LDM_AB: | |
8252 | ab = 1; | |
8253 | case M_LDM_OB: | |
8254 | gas_assert (mips_opts.micromips); | |
8255 | s = "ldm"; | |
8256 | fmt = "n,~(b)"; | |
8257 | off12 = 1; | |
8258 | goto ld_st; | |
8259 | ||
252b5132 | 8260 | ld: |
df58fc94 RS |
8261 | if (breg == treg + lp) |
8262 | goto ld_st; | |
252b5132 | 8263 | else |
df58fc94 RS |
8264 | tempreg = treg + lp; |
8265 | goto ld_noat; | |
8266 | ||
252b5132 | 8267 | case M_SB_AB: |
df58fc94 | 8268 | ab = 1; |
252b5132 | 8269 | s = "sb"; |
df58fc94 RS |
8270 | fmt = "t,o(b)"; |
8271 | goto ld_st; | |
252b5132 | 8272 | case M_SH_AB: |
df58fc94 | 8273 | ab = 1; |
252b5132 | 8274 | s = "sh"; |
df58fc94 RS |
8275 | fmt = "t,o(b)"; |
8276 | goto ld_st; | |
252b5132 | 8277 | case M_SW_AB: |
df58fc94 | 8278 | ab = 1; |
252b5132 | 8279 | s = "sw"; |
df58fc94 RS |
8280 | fmt = "t,o(b)"; |
8281 | goto ld_st; | |
252b5132 | 8282 | case M_SWC0_AB: |
df58fc94 RS |
8283 | ab = 1; |
8284 | gas_assert (!mips_opts.micromips); | |
252b5132 | 8285 | s = "swc0"; |
df58fc94 | 8286 | fmt = "E,o(b)"; |
bdaaa2e1 | 8287 | /* Itbl support may require additional care here. */ |
252b5132 | 8288 | coproc = 1; |
df58fc94 | 8289 | goto ld_st; |
252b5132 | 8290 | case M_SWC1_AB: |
df58fc94 | 8291 | ab = 1; |
252b5132 | 8292 | s = "swc1"; |
df58fc94 | 8293 | fmt = "T,o(b)"; |
bdaaa2e1 | 8294 | /* Itbl support may require additional care here. */ |
252b5132 | 8295 | coproc = 1; |
df58fc94 | 8296 | goto ld_st; |
252b5132 | 8297 | case M_SWC2_AB: |
df58fc94 RS |
8298 | ab = 1; |
8299 | case M_SWC2_OB: | |
252b5132 | 8300 | s = "swc2"; |
df58fc94 RS |
8301 | fmt = COP12_FMT; |
8302 | off12 = mips_opts.micromips; | |
bdaaa2e1 | 8303 | /* Itbl support may require additional care here. */ |
252b5132 | 8304 | coproc = 1; |
df58fc94 | 8305 | goto ld_st; |
252b5132 | 8306 | case M_SWC3_AB: |
df58fc94 RS |
8307 | ab = 1; |
8308 | gas_assert (!mips_opts.micromips); | |
252b5132 | 8309 | s = "swc3"; |
df58fc94 | 8310 | fmt = "E,o(b)"; |
bdaaa2e1 | 8311 | /* Itbl support may require additional care here. */ |
252b5132 | 8312 | coproc = 1; |
df58fc94 | 8313 | goto ld_st; |
252b5132 | 8314 | case M_SWL_AB: |
df58fc94 RS |
8315 | ab = 1; |
8316 | case M_SWL_OB: | |
252b5132 | 8317 | s = "swl"; |
df58fc94 RS |
8318 | fmt = MEM12_FMT; |
8319 | off12 = mips_opts.micromips; | |
8320 | goto ld_st; | |
252b5132 | 8321 | case M_SWR_AB: |
df58fc94 RS |
8322 | ab = 1; |
8323 | case M_SWR_OB: | |
252b5132 | 8324 | s = "swr"; |
df58fc94 RS |
8325 | fmt = MEM12_FMT; |
8326 | off12 = mips_opts.micromips; | |
8327 | goto ld_st; | |
252b5132 | 8328 | case M_SC_AB: |
df58fc94 RS |
8329 | ab = 1; |
8330 | case M_SC_OB: | |
252b5132 | 8331 | s = "sc"; |
df58fc94 RS |
8332 | fmt = MEM12_FMT; |
8333 | off12 = mips_opts.micromips; | |
8334 | goto ld_st; | |
252b5132 | 8335 | case M_SCD_AB: |
df58fc94 RS |
8336 | ab = 1; |
8337 | case M_SCD_OB: | |
252b5132 | 8338 | s = "scd"; |
df58fc94 RS |
8339 | fmt = MEM12_FMT; |
8340 | off12 = mips_opts.micromips; | |
8341 | goto ld_st; | |
d43b4baf | 8342 | case M_CACHE_AB: |
df58fc94 RS |
8343 | ab = 1; |
8344 | case M_CACHE_OB: | |
d43b4baf | 8345 | s = "cache"; |
df58fc94 RS |
8346 | fmt = mips_opts.micromips ? "k,~(b)" : "k,o(b)"; |
8347 | off12 = mips_opts.micromips; | |
8348 | goto ld_st; | |
3eebd5eb | 8349 | case M_PREF_AB: |
df58fc94 RS |
8350 | ab = 1; |
8351 | case M_PREF_OB: | |
3eebd5eb | 8352 | s = "pref"; |
df58fc94 RS |
8353 | fmt = !mips_opts.micromips ? "k,o(b)" : "k,~(b)"; |
8354 | off12 = mips_opts.micromips; | |
8355 | goto ld_st; | |
252b5132 | 8356 | case M_SDC1_AB: |
df58fc94 | 8357 | ab = 1; |
252b5132 | 8358 | s = "sdc1"; |
df58fc94 | 8359 | fmt = "T,o(b)"; |
252b5132 | 8360 | coproc = 1; |
bdaaa2e1 | 8361 | /* Itbl support may require additional care here. */ |
df58fc94 | 8362 | goto ld_st; |
252b5132 | 8363 | case M_SDC2_AB: |
df58fc94 RS |
8364 | ab = 1; |
8365 | case M_SDC2_OB: | |
252b5132 | 8366 | s = "sdc2"; |
df58fc94 RS |
8367 | fmt = COP12_FMT; |
8368 | off12 = mips_opts.micromips; | |
bdaaa2e1 | 8369 | /* Itbl support may require additional care here. */ |
252b5132 | 8370 | coproc = 1; |
df58fc94 | 8371 | goto ld_st; |
252b5132 | 8372 | case M_SDC3_AB: |
df58fc94 RS |
8373 | ab = 1; |
8374 | gas_assert (!mips_opts.micromips); | |
252b5132 | 8375 | s = "sdc3"; |
df58fc94 | 8376 | fmt = "E,o(b)"; |
bdaaa2e1 | 8377 | /* Itbl support may require additional care here. */ |
252b5132 | 8378 | coproc = 1; |
df58fc94 | 8379 | goto ld_st; |
252b5132 | 8380 | case M_SDL_AB: |
df58fc94 RS |
8381 | ab = 1; |
8382 | case M_SDL_OB: | |
252b5132 | 8383 | s = "sdl"; |
df58fc94 RS |
8384 | fmt = MEM12_FMT; |
8385 | off12 = mips_opts.micromips; | |
8386 | goto ld_st; | |
252b5132 | 8387 | case M_SDR_AB: |
df58fc94 RS |
8388 | ab = 1; |
8389 | case M_SDR_OB: | |
252b5132 | 8390 | s = "sdr"; |
df58fc94 RS |
8391 | fmt = MEM12_FMT; |
8392 | off12 = mips_opts.micromips; | |
8393 | goto ld_st; | |
8394 | case M_SWP_AB: | |
8395 | ab = 1; | |
8396 | case M_SWP_OB: | |
8397 | gas_assert (mips_opts.micromips); | |
8398 | s = "swp"; | |
8399 | fmt = "t,~(b)"; | |
8400 | off12 = 1; | |
8401 | goto ld_st; | |
8402 | case M_SDP_AB: | |
8403 | ab = 1; | |
8404 | case M_SDP_OB: | |
8405 | gas_assert (mips_opts.micromips); | |
8406 | s = "sdp"; | |
8407 | fmt = "t,~(b)"; | |
8408 | off12 = 1; | |
8409 | goto ld_st; | |
8410 | case M_SWM_AB: | |
8411 | ab = 1; | |
8412 | case M_SWM_OB: | |
8413 | gas_assert (mips_opts.micromips); | |
8414 | s = "swm"; | |
8415 | fmt = "n,~(b)"; | |
8416 | off12 = 1; | |
8417 | goto ld_st; | |
8418 | case M_SDM_AB: | |
8419 | ab = 1; | |
8420 | case M_SDM_OB: | |
8421 | gas_assert (mips_opts.micromips); | |
8422 | s = "sdm"; | |
8423 | fmt = "n,~(b)"; | |
8424 | off12 = 1; | |
8425 | ||
8426 | ld_st: | |
8fc2e39e TS |
8427 | tempreg = AT; |
8428 | used_at = 1; | |
df58fc94 | 8429 | ld_noat: |
252b5132 RH |
8430 | if (offset_expr.X_op != O_constant |
8431 | && offset_expr.X_op != O_symbol) | |
8432 | { | |
f71d0d44 | 8433 | as_bad (_("Expression too complex")); |
252b5132 RH |
8434 | offset_expr.X_op = O_constant; |
8435 | } | |
8436 | ||
2051e8c4 MR |
8437 | if (HAVE_32BIT_ADDRESSES |
8438 | && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number)) | |
55e08f71 NC |
8439 | { |
8440 | char value [32]; | |
8441 | ||
8442 | sprintf_vma (value, offset_expr.X_add_number); | |
20e1fcfd | 8443 | as_bad (_("Number (0x%s) larger than 32 bits"), value); |
55e08f71 | 8444 | } |
2051e8c4 | 8445 | |
252b5132 RH |
8446 | /* A constant expression in PIC code can be handled just as it |
8447 | is in non PIC code. */ | |
aed1a261 RS |
8448 | if (offset_expr.X_op == O_constant) |
8449 | { | |
df58fc94 RS |
8450 | int hipart = 0; |
8451 | ||
842f8b2a | 8452 | expr1.X_add_number = offset_expr.X_add_number; |
2051e8c4 | 8453 | normalize_address_expr (&expr1); |
df58fc94 | 8454 | if (!off12 && !IS_SEXT_16BIT_NUM (expr1.X_add_number)) |
842f8b2a MR |
8455 | { |
8456 | expr1.X_add_number = ((expr1.X_add_number + 0x8000) | |
8457 | & ~(bfd_vma) 0xffff); | |
df58fc94 RS |
8458 | hipart = 1; |
8459 | } | |
8460 | else if (off12 && !IS_SEXT_12BIT_NUM (expr1.X_add_number)) | |
8461 | { | |
8462 | expr1.X_add_number = ((expr1.X_add_number + 0x800) | |
8463 | & ~(bfd_vma) 0xfff); | |
8464 | hipart = 1; | |
8465 | } | |
8466 | if (hipart) | |
8467 | { | |
842f8b2a MR |
8468 | load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES); |
8469 | if (breg != 0) | |
8470 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", | |
8471 | tempreg, tempreg, breg); | |
8472 | breg = tempreg; | |
8473 | } | |
dd6a37e7 AP |
8474 | if (off0) |
8475 | { | |
8476 | if (offset_expr.X_add_number == 0) | |
8477 | tempreg = breg; | |
8478 | else | |
8479 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, | |
8480 | "t,r,j", tempreg, breg, BFD_RELOC_LO16); | |
8481 | macro_build (NULL, s, fmt, treg, tempreg); | |
8482 | } | |
8483 | else if (!off12) | |
df58fc94 RS |
8484 | macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, breg); |
8485 | else | |
8486 | macro_build (NULL, s, fmt, | |
8487 | treg, (unsigned long) offset_expr.X_add_number, breg); | |
8488 | } | |
dd6a37e7 | 8489 | else if (off12 || off0) |
df58fc94 | 8490 | { |
dd6a37e7 AP |
8491 | /* A 12-bit or 0-bit offset field is too narrow to be used |
8492 | for a low-part relocation, so load the whole address into | |
8493 | the auxillary register. In the case of "A(b)" addresses, | |
8494 | we first load absolute address "A" into the register and | |
8495 | then add base register "b". In the case of "o(b)" addresses, | |
8496 | we simply need to add 16-bit offset "o" to base register "b", and | |
df58fc94 RS |
8497 | offset_reloc already contains the relocations associated |
8498 | with "o". */ | |
8499 | if (ab) | |
8500 | { | |
8501 | load_address (tempreg, &offset_expr, &used_at); | |
8502 | if (breg != 0) | |
8503 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", | |
8504 | tempreg, tempreg, breg); | |
8505 | } | |
8506 | else | |
8507 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", | |
8508 | tempreg, breg, -1, | |
8509 | offset_reloc[0], offset_reloc[1], offset_reloc[2]); | |
8510 | expr1.X_add_number = 0; | |
dd6a37e7 AP |
8511 | if (off0) |
8512 | macro_build (NULL, s, fmt, treg, tempreg); | |
8513 | else | |
8514 | macro_build (NULL, s, fmt, | |
8515 | treg, (unsigned long) expr1.X_add_number, tempreg); | |
aed1a261 RS |
8516 | } |
8517 | else if (mips_pic == NO_PIC) | |
252b5132 RH |
8518 | { |
8519 | /* If this is a reference to a GP relative symbol, and there | |
8520 | is no base register, we want | |
cdf6fd85 | 8521 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
252b5132 RH |
8522 | Otherwise, if there is no base register, we want |
8523 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
8524 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
8525 | If we have a constant, we need two instructions anyhow, | |
8526 | so we always use the latter form. | |
8527 | ||
8528 | If we have a base register, and this is a reference to a | |
8529 | GP relative symbol, we want | |
8530 | addu $tempreg,$breg,$gp | |
cdf6fd85 | 8531 | <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16) |
252b5132 RH |
8532 | Otherwise we want |
8533 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
8534 | addu $tempreg,$tempreg,$breg | |
8535 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
d6bc6245 | 8536 | With a constant we always use the latter case. |
76b3015f | 8537 | |
d6bc6245 TS |
8538 | With 64bit address space and no base register and $at usable, |
8539 | we want | |
8540 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
8541 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
8542 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
8543 | dsll32 $tempreg,0 | |
8544 | daddu $tempreg,$at | |
8545 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
8546 | If we have a base register, we want | |
8547 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
8548 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
8549 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
8550 | daddu $at,$breg | |
8551 | dsll32 $tempreg,0 | |
8552 | daddu $tempreg,$at | |
8553 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
8554 | ||
8555 | Without $at we can't generate the optimal path for superscalar | |
8556 | processors here since this would require two temporary registers. | |
8557 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
8558 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
8559 | dsll $tempreg,16 | |
8560 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
8561 | dsll $tempreg,16 | |
8562 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
8563 | If we have a base register, we want | |
8564 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
8565 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
8566 | dsll $tempreg,16 | |
8567 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
8568 | dsll $tempreg,16 | |
8569 | daddu $tempreg,$tempreg,$breg | |
8570 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
6373ee54 | 8571 | |
6caf9ef4 | 8572 | For GP relative symbols in 64bit address space we can use |
aed1a261 RS |
8573 | the same sequence as in 32bit address space. */ |
8574 | if (HAVE_64BIT_SYMBOLS) | |
d6bc6245 | 8575 | { |
aed1a261 | 8576 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
6caf9ef4 TS |
8577 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
8578 | { | |
8579 | relax_start (offset_expr.X_add_symbol); | |
8580 | if (breg == 0) | |
8581 | { | |
8582 | macro_build (&offset_expr, s, fmt, treg, | |
8583 | BFD_RELOC_GPREL16, mips_gp_register); | |
8584 | } | |
8585 | else | |
8586 | { | |
8587 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", | |
8588 | tempreg, breg, mips_gp_register); | |
8589 | macro_build (&offset_expr, s, fmt, treg, | |
8590 | BFD_RELOC_GPREL16, tempreg); | |
8591 | } | |
8592 | relax_switch (); | |
8593 | } | |
d6bc6245 | 8594 | |
741fe287 | 8595 | if (used_at == 0 && mips_opts.at) |
d6bc6245 | 8596 | { |
df58fc94 | 8597 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, |
67c0d1eb | 8598 | BFD_RELOC_MIPS_HIGHEST); |
df58fc94 | 8599 | macro_build (&offset_expr, "lui", LUI_FMT, AT, |
67c0d1eb RS |
8600 | BFD_RELOC_HI16_S); |
8601 | macro_build (&offset_expr, "daddiu", "t,r,j", tempreg, | |
8602 | tempreg, BFD_RELOC_MIPS_HIGHER); | |
d6bc6245 | 8603 | if (breg != 0) |
67c0d1eb | 8604 | macro_build (NULL, "daddu", "d,v,t", AT, AT, breg); |
df58fc94 | 8605 | macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0); |
67c0d1eb RS |
8606 | macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT); |
8607 | macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, | |
8608 | tempreg); | |
d6bc6245 TS |
8609 | used_at = 1; |
8610 | } | |
8611 | else | |
8612 | { | |
df58fc94 | 8613 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, |
67c0d1eb RS |
8614 | BFD_RELOC_MIPS_HIGHEST); |
8615 | macro_build (&offset_expr, "daddiu", "t,r,j", tempreg, | |
8616 | tempreg, BFD_RELOC_MIPS_HIGHER); | |
df58fc94 | 8617 | macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16); |
67c0d1eb RS |
8618 | macro_build (&offset_expr, "daddiu", "t,r,j", tempreg, |
8619 | tempreg, BFD_RELOC_HI16_S); | |
df58fc94 | 8620 | macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16); |
d6bc6245 | 8621 | if (breg != 0) |
67c0d1eb | 8622 | macro_build (NULL, "daddu", "d,v,t", |
17a2f251 | 8623 | tempreg, tempreg, breg); |
67c0d1eb | 8624 | macro_build (&offset_expr, s, fmt, treg, |
17a2f251 | 8625 | BFD_RELOC_LO16, tempreg); |
d6bc6245 | 8626 | } |
6caf9ef4 TS |
8627 | |
8628 | if (mips_relax.sequence) | |
8629 | relax_end (); | |
8fc2e39e | 8630 | break; |
d6bc6245 | 8631 | } |
256ab948 | 8632 | |
252b5132 RH |
8633 | if (breg == 0) |
8634 | { | |
67c0d1eb | 8635 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
6caf9ef4 | 8636 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
252b5132 | 8637 | { |
4d7206a2 | 8638 | relax_start (offset_expr.X_add_symbol); |
67c0d1eb RS |
8639 | macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16, |
8640 | mips_gp_register); | |
4d7206a2 | 8641 | relax_switch (); |
252b5132 | 8642 | } |
67c0d1eb RS |
8643 | macro_build_lui (&offset_expr, tempreg); |
8644 | macro_build (&offset_expr, s, fmt, treg, | |
17a2f251 | 8645 | BFD_RELOC_LO16, tempreg); |
4d7206a2 RS |
8646 | if (mips_relax.sequence) |
8647 | relax_end (); | |
252b5132 RH |
8648 | } |
8649 | else | |
8650 | { | |
67c0d1eb | 8651 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
6caf9ef4 | 8652 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
252b5132 | 8653 | { |
4d7206a2 | 8654 | relax_start (offset_expr.X_add_symbol); |
67c0d1eb | 8655 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 8656 | tempreg, breg, mips_gp_register); |
67c0d1eb | 8657 | macro_build (&offset_expr, s, fmt, treg, |
17a2f251 | 8658 | BFD_RELOC_GPREL16, tempreg); |
4d7206a2 | 8659 | relax_switch (); |
252b5132 | 8660 | } |
67c0d1eb RS |
8661 | macro_build_lui (&offset_expr, tempreg); |
8662 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", | |
17a2f251 | 8663 | tempreg, tempreg, breg); |
67c0d1eb | 8664 | macro_build (&offset_expr, s, fmt, treg, |
17a2f251 | 8665 | BFD_RELOC_LO16, tempreg); |
4d7206a2 RS |
8666 | if (mips_relax.sequence) |
8667 | relax_end (); | |
252b5132 RH |
8668 | } |
8669 | } | |
0a44bf69 | 8670 | else if (!mips_big_got) |
252b5132 | 8671 | { |
ed6fb7bd | 8672 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
f9419b05 | 8673 | |
252b5132 RH |
8674 | /* If this is a reference to an external symbol, we want |
8675 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
8676 | nop | |
8677 | <op> $treg,0($tempreg) | |
8678 | Otherwise we want | |
8679 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
8680 | nop | |
8681 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
8682 | <op> $treg,0($tempreg) | |
f5040a92 AO |
8683 | |
8684 | For NewABI, we want | |
8685 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) | |
8686 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) | |
8687 | ||
252b5132 RH |
8688 | If there is a base register, we add it to $tempreg before |
8689 | the <op>. If there is a constant, we stick it in the | |
8690 | <op> instruction. We don't handle constants larger than | |
8691 | 16 bits, because we have no way to load the upper 16 bits | |
8692 | (actually, we could handle them for the subset of cases | |
8693 | in which we are not using $at). */ | |
9c2799c2 | 8694 | gas_assert (offset_expr.X_op == O_symbol); |
f5040a92 AO |
8695 | if (HAVE_NEWABI) |
8696 | { | |
67c0d1eb RS |
8697 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
8698 | BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); | |
f5040a92 | 8699 | if (breg != 0) |
67c0d1eb | 8700 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 8701 | tempreg, tempreg, breg); |
67c0d1eb | 8702 | macro_build (&offset_expr, s, fmt, treg, |
17a2f251 | 8703 | BFD_RELOC_MIPS_GOT_OFST, tempreg); |
f5040a92 AO |
8704 | break; |
8705 | } | |
252b5132 RH |
8706 | expr1.X_add_number = offset_expr.X_add_number; |
8707 | offset_expr.X_add_number = 0; | |
8708 | if (expr1.X_add_number < -0x8000 | |
8709 | || expr1.X_add_number >= 0x8000) | |
8710 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
67c0d1eb RS |
8711 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
8712 | lw_reloc_type, mips_gp_register); | |
269137b2 | 8713 | load_delay_nop (); |
4d7206a2 RS |
8714 | relax_start (offset_expr.X_add_symbol); |
8715 | relax_switch (); | |
67c0d1eb RS |
8716 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg, |
8717 | tempreg, BFD_RELOC_LO16); | |
4d7206a2 | 8718 | relax_end (); |
252b5132 | 8719 | if (breg != 0) |
67c0d1eb | 8720 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 8721 | tempreg, tempreg, breg); |
67c0d1eb | 8722 | macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg); |
252b5132 | 8723 | } |
0a44bf69 | 8724 | else if (mips_big_got && !HAVE_NEWABI) |
252b5132 | 8725 | { |
67c0d1eb | 8726 | int gpdelay; |
252b5132 RH |
8727 | |
8728 | /* If this is a reference to an external symbol, we want | |
8729 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
8730 | addu $tempreg,$tempreg,$gp | |
8731 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
8732 | <op> $treg,0($tempreg) | |
8733 | Otherwise we want | |
8734 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
8735 | nop | |
8736 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
8737 | <op> $treg,0($tempreg) | |
8738 | If there is a base register, we add it to $tempreg before | |
8739 | the <op>. If there is a constant, we stick it in the | |
8740 | <op> instruction. We don't handle constants larger than | |
8741 | 16 bits, because we have no way to load the upper 16 bits | |
8742 | (actually, we could handle them for the subset of cases | |
f5040a92 | 8743 | in which we are not using $at). */ |
9c2799c2 | 8744 | gas_assert (offset_expr.X_op == O_symbol); |
252b5132 RH |
8745 | expr1.X_add_number = offset_expr.X_add_number; |
8746 | offset_expr.X_add_number = 0; | |
8747 | if (expr1.X_add_number < -0x8000 | |
8748 | || expr1.X_add_number >= 0x8000) | |
8749 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
67c0d1eb | 8750 | gpdelay = reg_needs_delay (mips_gp_register); |
4d7206a2 | 8751 | relax_start (offset_expr.X_add_symbol); |
df58fc94 | 8752 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, |
17a2f251 | 8753 | BFD_RELOC_MIPS_GOT_HI16); |
67c0d1eb RS |
8754 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, |
8755 | mips_gp_register); | |
8756 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, | |
8757 | BFD_RELOC_MIPS_GOT_LO16, tempreg); | |
4d7206a2 | 8758 | relax_switch (); |
67c0d1eb RS |
8759 | if (gpdelay) |
8760 | macro_build (NULL, "nop", ""); | |
8761 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, | |
8762 | BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
269137b2 | 8763 | load_delay_nop (); |
67c0d1eb RS |
8764 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg, |
8765 | tempreg, BFD_RELOC_LO16); | |
4d7206a2 RS |
8766 | relax_end (); |
8767 | ||
252b5132 | 8768 | if (breg != 0) |
67c0d1eb | 8769 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 8770 | tempreg, tempreg, breg); |
67c0d1eb | 8771 | macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg); |
252b5132 | 8772 | } |
0a44bf69 | 8773 | else if (mips_big_got && HAVE_NEWABI) |
f5040a92 | 8774 | { |
f5040a92 AO |
8775 | /* If this is a reference to an external symbol, we want |
8776 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
8777 | add $tempreg,$tempreg,$gp | |
8778 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
8779 | <op> $treg,<ofst>($tempreg) | |
8780 | Otherwise, for local symbols, we want: | |
8781 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) | |
8782 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */ | |
9c2799c2 | 8783 | gas_assert (offset_expr.X_op == O_symbol); |
4d7206a2 | 8784 | expr1.X_add_number = offset_expr.X_add_number; |
f5040a92 AO |
8785 | offset_expr.X_add_number = 0; |
8786 | if (expr1.X_add_number < -0x8000 | |
8787 | || expr1.X_add_number >= 0x8000) | |
8788 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
4d7206a2 | 8789 | relax_start (offset_expr.X_add_symbol); |
df58fc94 | 8790 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, |
17a2f251 | 8791 | BFD_RELOC_MIPS_GOT_HI16); |
67c0d1eb RS |
8792 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, |
8793 | mips_gp_register); | |
8794 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, | |
8795 | BFD_RELOC_MIPS_GOT_LO16, tempreg); | |
f5040a92 | 8796 | if (breg != 0) |
67c0d1eb | 8797 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 8798 | tempreg, tempreg, breg); |
67c0d1eb | 8799 | macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg); |
684022ea | 8800 | |
4d7206a2 | 8801 | relax_switch (); |
f5040a92 | 8802 | offset_expr.X_add_number = expr1.X_add_number; |
67c0d1eb RS |
8803 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
8804 | BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); | |
f5040a92 | 8805 | if (breg != 0) |
67c0d1eb | 8806 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 8807 | tempreg, tempreg, breg); |
67c0d1eb | 8808 | macro_build (&offset_expr, s, fmt, treg, |
17a2f251 | 8809 | BFD_RELOC_MIPS_GOT_OFST, tempreg); |
4d7206a2 | 8810 | relax_end (); |
f5040a92 | 8811 | } |
252b5132 RH |
8812 | else |
8813 | abort (); | |
8814 | ||
252b5132 RH |
8815 | break; |
8816 | ||
8817 | case M_LI: | |
8818 | case M_LI_S: | |
67c0d1eb | 8819 | load_register (treg, &imm_expr, 0); |
8fc2e39e | 8820 | break; |
252b5132 RH |
8821 | |
8822 | case M_DLI: | |
67c0d1eb | 8823 | load_register (treg, &imm_expr, 1); |
8fc2e39e | 8824 | break; |
252b5132 RH |
8825 | |
8826 | case M_LI_SS: | |
8827 | if (imm_expr.X_op == O_constant) | |
8828 | { | |
8fc2e39e | 8829 | used_at = 1; |
67c0d1eb RS |
8830 | load_register (AT, &imm_expr, 0); |
8831 | macro_build (NULL, "mtc1", "t,G", AT, treg); | |
252b5132 RH |
8832 | break; |
8833 | } | |
8834 | else | |
8835 | { | |
9c2799c2 | 8836 | gas_assert (offset_expr.X_op == O_symbol |
90ecf173 MR |
8837 | && strcmp (segment_name (S_GET_SEGMENT |
8838 | (offset_expr.X_add_symbol)), | |
8839 | ".lit4") == 0 | |
8840 | && offset_expr.X_add_number == 0); | |
67c0d1eb | 8841 | macro_build (&offset_expr, "lwc1", "T,o(b)", treg, |
17a2f251 | 8842 | BFD_RELOC_MIPS_LITERAL, mips_gp_register); |
8fc2e39e | 8843 | break; |
252b5132 RH |
8844 | } |
8845 | ||
8846 | case M_LI_D: | |
ca4e0257 RS |
8847 | /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits |
8848 | wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high | |
8849 | order 32 bits of the value and the low order 32 bits are either | |
8850 | zero or in OFFSET_EXPR. */ | |
252b5132 RH |
8851 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
8852 | { | |
ca4e0257 | 8853 | if (HAVE_64BIT_GPRS) |
67c0d1eb | 8854 | load_register (treg, &imm_expr, 1); |
252b5132 RH |
8855 | else |
8856 | { | |
8857 | int hreg, lreg; | |
8858 | ||
8859 | if (target_big_endian) | |
8860 | { | |
8861 | hreg = treg; | |
8862 | lreg = treg + 1; | |
8863 | } | |
8864 | else | |
8865 | { | |
8866 | hreg = treg + 1; | |
8867 | lreg = treg; | |
8868 | } | |
8869 | ||
8870 | if (hreg <= 31) | |
67c0d1eb | 8871 | load_register (hreg, &imm_expr, 0); |
252b5132 RH |
8872 | if (lreg <= 31) |
8873 | { | |
8874 | if (offset_expr.X_op == O_absent) | |
67c0d1eb | 8875 | move_register (lreg, 0); |
252b5132 RH |
8876 | else |
8877 | { | |
9c2799c2 | 8878 | gas_assert (offset_expr.X_op == O_constant); |
67c0d1eb | 8879 | load_register (lreg, &offset_expr, 0); |
252b5132 RH |
8880 | } |
8881 | } | |
8882 | } | |
8fc2e39e | 8883 | break; |
252b5132 RH |
8884 | } |
8885 | ||
8886 | /* We know that sym is in the .rdata section. First we get the | |
8887 | upper 16 bits of the address. */ | |
8888 | if (mips_pic == NO_PIC) | |
8889 | { | |
67c0d1eb | 8890 | macro_build_lui (&offset_expr, AT); |
8fc2e39e | 8891 | used_at = 1; |
252b5132 | 8892 | } |
0a44bf69 | 8893 | else |
252b5132 | 8894 | { |
67c0d1eb RS |
8895 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT, |
8896 | BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
8fc2e39e | 8897 | used_at = 1; |
252b5132 | 8898 | } |
bdaaa2e1 | 8899 | |
252b5132 | 8900 | /* Now we load the register(s). */ |
ca4e0257 | 8901 | if (HAVE_64BIT_GPRS) |
8fc2e39e TS |
8902 | { |
8903 | used_at = 1; | |
8904 | macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT); | |
8905 | } | |
252b5132 RH |
8906 | else |
8907 | { | |
8fc2e39e | 8908 | used_at = 1; |
67c0d1eb | 8909 | macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT); |
f9419b05 | 8910 | if (treg != RA) |
252b5132 RH |
8911 | { |
8912 | /* FIXME: How in the world do we deal with the possible | |
8913 | overflow here? */ | |
8914 | offset_expr.X_add_number += 4; | |
67c0d1eb | 8915 | macro_build (&offset_expr, "lw", "t,o(b)", |
17a2f251 | 8916 | treg + 1, BFD_RELOC_LO16, AT); |
252b5132 RH |
8917 | } |
8918 | } | |
252b5132 RH |
8919 | break; |
8920 | ||
8921 | case M_LI_DD: | |
ca4e0257 RS |
8922 | /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits |
8923 | wide, IMM_EXPR is the entire value and the GPRs are known to be 64 | |
8924 | bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of | |
8925 | the value and the low order 32 bits are either zero or in | |
8926 | OFFSET_EXPR. */ | |
252b5132 RH |
8927 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
8928 | { | |
8fc2e39e | 8929 | used_at = 1; |
67c0d1eb | 8930 | load_register (AT, &imm_expr, HAVE_64BIT_FPRS); |
ca4e0257 RS |
8931 | if (HAVE_64BIT_FPRS) |
8932 | { | |
9c2799c2 | 8933 | gas_assert (HAVE_64BIT_GPRS); |
67c0d1eb | 8934 | macro_build (NULL, "dmtc1", "t,S", AT, treg); |
ca4e0257 | 8935 | } |
252b5132 RH |
8936 | else |
8937 | { | |
67c0d1eb | 8938 | macro_build (NULL, "mtc1", "t,G", AT, treg + 1); |
252b5132 | 8939 | if (offset_expr.X_op == O_absent) |
67c0d1eb | 8940 | macro_build (NULL, "mtc1", "t,G", 0, treg); |
252b5132 RH |
8941 | else |
8942 | { | |
9c2799c2 | 8943 | gas_assert (offset_expr.X_op == O_constant); |
67c0d1eb RS |
8944 | load_register (AT, &offset_expr, 0); |
8945 | macro_build (NULL, "mtc1", "t,G", AT, treg); | |
252b5132 RH |
8946 | } |
8947 | } | |
8948 | break; | |
8949 | } | |
8950 | ||
9c2799c2 | 8951 | gas_assert (offset_expr.X_op == O_symbol |
90ecf173 | 8952 | && offset_expr.X_add_number == 0); |
252b5132 RH |
8953 | s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol)); |
8954 | if (strcmp (s, ".lit8") == 0) | |
8955 | { | |
0aa27725 | 8956 | if (CPU_HAS_LDC1_SDC1 (mips_opts.arch) || mips_opts.micromips) |
252b5132 | 8957 | { |
67c0d1eb | 8958 | macro_build (&offset_expr, "ldc1", "T,o(b)", treg, |
17a2f251 | 8959 | BFD_RELOC_MIPS_LITERAL, mips_gp_register); |
8fc2e39e | 8960 | break; |
252b5132 | 8961 | } |
c9914766 | 8962 | breg = mips_gp_register; |
252b5132 RH |
8963 | r = BFD_RELOC_MIPS_LITERAL; |
8964 | goto dob; | |
8965 | } | |
8966 | else | |
8967 | { | |
9c2799c2 | 8968 | gas_assert (strcmp (s, RDATA_SECTION_NAME) == 0); |
8fc2e39e | 8969 | used_at = 1; |
0a44bf69 | 8970 | if (mips_pic != NO_PIC) |
67c0d1eb RS |
8971 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT, |
8972 | BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
252b5132 RH |
8973 | else |
8974 | { | |
8975 | /* FIXME: This won't work for a 64 bit address. */ | |
67c0d1eb | 8976 | macro_build_lui (&offset_expr, AT); |
252b5132 | 8977 | } |
bdaaa2e1 | 8978 | |
0aa27725 | 8979 | if (CPU_HAS_LDC1_SDC1 (mips_opts.arch) || mips_opts.micromips) |
252b5132 | 8980 | { |
67c0d1eb RS |
8981 | macro_build (&offset_expr, "ldc1", "T,o(b)", |
8982 | treg, BFD_RELOC_LO16, AT); | |
252b5132 RH |
8983 | break; |
8984 | } | |
8985 | breg = AT; | |
8986 | r = BFD_RELOC_LO16; | |
8987 | goto dob; | |
8988 | } | |
8989 | ||
8990 | case M_L_DOB: | |
252b5132 RH |
8991 | /* Even on a big endian machine $fn comes before $fn+1. We have |
8992 | to adjust when loading from memory. */ | |
8993 | r = BFD_RELOC_LO16; | |
8994 | dob: | |
df58fc94 | 8995 | gas_assert (!mips_opts.micromips); |
0aa27725 | 8996 | gas_assert (!CPU_HAS_LDC1_SDC1 (mips_opts.arch)); |
67c0d1eb | 8997 | macro_build (&offset_expr, "lwc1", "T,o(b)", |
17a2f251 | 8998 | target_big_endian ? treg + 1 : treg, r, breg); |
252b5132 RH |
8999 | /* FIXME: A possible overflow which I don't know how to deal |
9000 | with. */ | |
9001 | offset_expr.X_add_number += 4; | |
67c0d1eb | 9002 | macro_build (&offset_expr, "lwc1", "T,o(b)", |
17a2f251 | 9003 | target_big_endian ? treg : treg + 1, r, breg); |
252b5132 RH |
9004 | break; |
9005 | ||
c4a68bea | 9006 | case M_S_DOB: |
df58fc94 | 9007 | gas_assert (!mips_opts.micromips); |
0aa27725 | 9008 | gas_assert (!CPU_HAS_LDC1_SDC1 (mips_opts.arch)); |
c4a68bea MR |
9009 | /* Even on a big endian machine $fn comes before $fn+1. We have |
9010 | to adjust when storing to memory. */ | |
9011 | macro_build (&offset_expr, "swc1", "T,o(b)", | |
9012 | target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg); | |
9013 | offset_expr.X_add_number += 4; | |
9014 | macro_build (&offset_expr, "swc1", "T,o(b)", | |
9015 | target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg); | |
9016 | break; | |
9017 | ||
252b5132 | 9018 | case M_L_DAB: |
df58fc94 | 9019 | gas_assert (!mips_opts.micromips); |
252b5132 RH |
9020 | /* |
9021 | * The MIPS assembler seems to check for X_add_number not | |
9022 | * being double aligned and generating: | |
9023 | * lui at,%hi(foo+1) | |
9024 | * addu at,at,v1 | |
9025 | * addiu at,at,%lo(foo+1) | |
9026 | * lwc1 f2,0(at) | |
9027 | * lwc1 f3,4(at) | |
9028 | * But, the resulting address is the same after relocation so why | |
9029 | * generate the extra instruction? | |
9030 | */ | |
bdaaa2e1 | 9031 | /* Itbl support may require additional care here. */ |
252b5132 | 9032 | coproc = 1; |
df58fc94 | 9033 | fmt = "T,o(b)"; |
0aa27725 | 9034 | if (CPU_HAS_LDC1_SDC1 (mips_opts.arch)) |
252b5132 RH |
9035 | { |
9036 | s = "ldc1"; | |
df58fc94 | 9037 | goto ld_st; |
252b5132 | 9038 | } |
252b5132 | 9039 | s = "lwc1"; |
252b5132 RH |
9040 | goto ldd_std; |
9041 | ||
9042 | case M_S_DAB: | |
df58fc94 RS |
9043 | gas_assert (!mips_opts.micromips); |
9044 | /* Itbl support may require additional care here. */ | |
9045 | coproc = 1; | |
9046 | fmt = "T,o(b)"; | |
0aa27725 | 9047 | if (CPU_HAS_LDC1_SDC1 (mips_opts.arch)) |
252b5132 RH |
9048 | { |
9049 | s = "sdc1"; | |
df58fc94 | 9050 | goto ld_st; |
252b5132 | 9051 | } |
252b5132 | 9052 | s = "swc1"; |
252b5132 RH |
9053 | goto ldd_std; |
9054 | ||
e407c74b NC |
9055 | case M_LQ_AB: |
9056 | fmt = "t,o(b)"; | |
9057 | s = "lq"; | |
9058 | goto ld; | |
9059 | ||
9060 | case M_SQ_AB: | |
9061 | fmt = "t,o(b)"; | |
9062 | s = "sq"; | |
9063 | goto ld_st; | |
9064 | ||
252b5132 | 9065 | case M_LD_AB: |
df58fc94 | 9066 | fmt = "t,o(b)"; |
ca4e0257 | 9067 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
9068 | { |
9069 | s = "ld"; | |
9070 | goto ld; | |
9071 | } | |
252b5132 | 9072 | s = "lw"; |
252b5132 RH |
9073 | goto ldd_std; |
9074 | ||
9075 | case M_SD_AB: | |
df58fc94 | 9076 | fmt = "t,o(b)"; |
ca4e0257 | 9077 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
9078 | { |
9079 | s = "sd"; | |
df58fc94 | 9080 | goto ld_st; |
252b5132 | 9081 | } |
252b5132 | 9082 | s = "sw"; |
252b5132 RH |
9083 | |
9084 | ldd_std: | |
9085 | if (offset_expr.X_op != O_symbol | |
9086 | && offset_expr.X_op != O_constant) | |
9087 | { | |
f71d0d44 | 9088 | as_bad (_("Expression too complex")); |
252b5132 RH |
9089 | offset_expr.X_op = O_constant; |
9090 | } | |
9091 | ||
2051e8c4 MR |
9092 | if (HAVE_32BIT_ADDRESSES |
9093 | && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number)) | |
55e08f71 NC |
9094 | { |
9095 | char value [32]; | |
9096 | ||
9097 | sprintf_vma (value, offset_expr.X_add_number); | |
20e1fcfd | 9098 | as_bad (_("Number (0x%s) larger than 32 bits"), value); |
55e08f71 | 9099 | } |
2051e8c4 | 9100 | |
252b5132 RH |
9101 | /* Even on a big endian machine $fn comes before $fn+1. We have |
9102 | to adjust when loading from memory. We set coproc if we must | |
9103 | load $fn+1 first. */ | |
bdaaa2e1 | 9104 | /* Itbl support may require additional care here. */ |
90ecf173 | 9105 | if (!target_big_endian) |
252b5132 RH |
9106 | coproc = 0; |
9107 | ||
90ecf173 | 9108 | if (mips_pic == NO_PIC || offset_expr.X_op == O_constant) |
252b5132 RH |
9109 | { |
9110 | /* If this is a reference to a GP relative symbol, we want | |
cdf6fd85 TS |
9111 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
9112 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16) | |
252b5132 RH |
9113 | If we have a base register, we use this |
9114 | addu $at,$breg,$gp | |
cdf6fd85 TS |
9115 | <op> $treg,<sym>($at) (BFD_RELOC_GPREL16) |
9116 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16) | |
252b5132 RH |
9117 | If this is not a GP relative symbol, we want |
9118 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
9119 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
9120 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
9121 | If there is a base register, we add it to $at after the | |
9122 | lui instruction. If there is a constant, we always use | |
9123 | the last case. */ | |
39a59cf8 MR |
9124 | if (offset_expr.X_op == O_symbol |
9125 | && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET | |
6caf9ef4 | 9126 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
252b5132 | 9127 | { |
4d7206a2 | 9128 | relax_start (offset_expr.X_add_symbol); |
252b5132 RH |
9129 | if (breg == 0) |
9130 | { | |
c9914766 | 9131 | tempreg = mips_gp_register; |
252b5132 RH |
9132 | } |
9133 | else | |
9134 | { | |
67c0d1eb | 9135 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
17a2f251 | 9136 | AT, breg, mips_gp_register); |
252b5132 | 9137 | tempreg = AT; |
252b5132 RH |
9138 | used_at = 1; |
9139 | } | |
9140 | ||
beae10d5 | 9141 | /* Itbl support may require additional care here. */ |
67c0d1eb | 9142 | macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg, |
17a2f251 | 9143 | BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
9144 | offset_expr.X_add_number += 4; |
9145 | ||
9146 | /* Set mips_optimize to 2 to avoid inserting an | |
9147 | undesired nop. */ | |
9148 | hold_mips_optimize = mips_optimize; | |
9149 | mips_optimize = 2; | |
beae10d5 | 9150 | /* Itbl support may require additional care here. */ |
67c0d1eb | 9151 | macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1, |
17a2f251 | 9152 | BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
9153 | mips_optimize = hold_mips_optimize; |
9154 | ||
4d7206a2 | 9155 | relax_switch (); |
252b5132 | 9156 | |
0970e49e | 9157 | offset_expr.X_add_number -= 4; |
252b5132 | 9158 | } |
8fc2e39e | 9159 | used_at = 1; |
67c0d1eb | 9160 | macro_build_lui (&offset_expr, AT); |
252b5132 | 9161 | if (breg != 0) |
67c0d1eb | 9162 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT); |
beae10d5 | 9163 | /* Itbl support may require additional care here. */ |
67c0d1eb | 9164 | macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg, |
17a2f251 | 9165 | BFD_RELOC_LO16, AT); |
252b5132 RH |
9166 | /* FIXME: How do we handle overflow here? */ |
9167 | offset_expr.X_add_number += 4; | |
beae10d5 | 9168 | /* Itbl support may require additional care here. */ |
67c0d1eb | 9169 | macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1, |
17a2f251 | 9170 | BFD_RELOC_LO16, AT); |
4d7206a2 RS |
9171 | if (mips_relax.sequence) |
9172 | relax_end (); | |
bdaaa2e1 | 9173 | } |
0a44bf69 | 9174 | else if (!mips_big_got) |
252b5132 | 9175 | { |
252b5132 RH |
9176 | /* If this is a reference to an external symbol, we want |
9177 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
9178 | nop | |
9179 | <op> $treg,0($at) | |
9180 | <op> $treg+1,4($at) | |
9181 | Otherwise we want | |
9182 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
9183 | nop | |
9184 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
9185 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
9186 | If there is a base register we add it to $at before the | |
9187 | lwc1 instructions. If there is a constant we include it | |
9188 | in the lwc1 instructions. */ | |
9189 | used_at = 1; | |
9190 | expr1.X_add_number = offset_expr.X_add_number; | |
252b5132 RH |
9191 | if (expr1.X_add_number < -0x8000 |
9192 | || expr1.X_add_number >= 0x8000 - 4) | |
9193 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
67c0d1eb | 9194 | load_got_offset (AT, &offset_expr); |
269137b2 | 9195 | load_delay_nop (); |
252b5132 | 9196 | if (breg != 0) |
67c0d1eb | 9197 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT); |
252b5132 RH |
9198 | |
9199 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
9200 | nop. */ | |
9201 | hold_mips_optimize = mips_optimize; | |
9202 | mips_optimize = 2; | |
4d7206a2 | 9203 | |
beae10d5 | 9204 | /* Itbl support may require additional care here. */ |
4d7206a2 | 9205 | relax_start (offset_expr.X_add_symbol); |
67c0d1eb RS |
9206 | macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg, |
9207 | BFD_RELOC_LO16, AT); | |
4d7206a2 | 9208 | expr1.X_add_number += 4; |
67c0d1eb RS |
9209 | macro_build (&expr1, s, fmt, coproc ? treg : treg + 1, |
9210 | BFD_RELOC_LO16, AT); | |
4d7206a2 | 9211 | relax_switch (); |
67c0d1eb RS |
9212 | macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg, |
9213 | BFD_RELOC_LO16, AT); | |
4d7206a2 | 9214 | offset_expr.X_add_number += 4; |
67c0d1eb RS |
9215 | macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1, |
9216 | BFD_RELOC_LO16, AT); | |
4d7206a2 | 9217 | relax_end (); |
252b5132 | 9218 | |
4d7206a2 | 9219 | mips_optimize = hold_mips_optimize; |
252b5132 | 9220 | } |
0a44bf69 | 9221 | else if (mips_big_got) |
252b5132 | 9222 | { |
67c0d1eb | 9223 | int gpdelay; |
252b5132 RH |
9224 | |
9225 | /* If this is a reference to an external symbol, we want | |
9226 | lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
9227 | addu $at,$at,$gp | |
9228 | lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16) | |
9229 | nop | |
9230 | <op> $treg,0($at) | |
9231 | <op> $treg+1,4($at) | |
9232 | Otherwise we want | |
9233 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
9234 | nop | |
9235 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
9236 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
9237 | If there is a base register we add it to $at before the | |
9238 | lwc1 instructions. If there is a constant we include it | |
9239 | in the lwc1 instructions. */ | |
9240 | used_at = 1; | |
9241 | expr1.X_add_number = offset_expr.X_add_number; | |
9242 | offset_expr.X_add_number = 0; | |
9243 | if (expr1.X_add_number < -0x8000 | |
9244 | || expr1.X_add_number >= 0x8000 - 4) | |
9245 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
67c0d1eb | 9246 | gpdelay = reg_needs_delay (mips_gp_register); |
4d7206a2 | 9247 | relax_start (offset_expr.X_add_symbol); |
df58fc94 | 9248 | macro_build (&offset_expr, "lui", LUI_FMT, |
67c0d1eb RS |
9249 | AT, BFD_RELOC_MIPS_GOT_HI16); |
9250 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", | |
17a2f251 | 9251 | AT, AT, mips_gp_register); |
67c0d1eb | 9252 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
17a2f251 | 9253 | AT, BFD_RELOC_MIPS_GOT_LO16, AT); |
269137b2 | 9254 | load_delay_nop (); |
252b5132 | 9255 | if (breg != 0) |
67c0d1eb | 9256 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT); |
beae10d5 | 9257 | /* Itbl support may require additional care here. */ |
67c0d1eb | 9258 | macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg, |
17a2f251 | 9259 | BFD_RELOC_LO16, AT); |
252b5132 RH |
9260 | expr1.X_add_number += 4; |
9261 | ||
9262 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
9263 | nop. */ | |
9264 | hold_mips_optimize = mips_optimize; | |
9265 | mips_optimize = 2; | |
beae10d5 | 9266 | /* Itbl support may require additional care here. */ |
67c0d1eb | 9267 | macro_build (&expr1, s, fmt, coproc ? treg : treg + 1, |
17a2f251 | 9268 | BFD_RELOC_LO16, AT); |
252b5132 RH |
9269 | mips_optimize = hold_mips_optimize; |
9270 | expr1.X_add_number -= 4; | |
9271 | ||
4d7206a2 RS |
9272 | relax_switch (); |
9273 | offset_expr.X_add_number = expr1.X_add_number; | |
67c0d1eb RS |
9274 | if (gpdelay) |
9275 | macro_build (NULL, "nop", ""); | |
9276 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT, | |
9277 | BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
269137b2 | 9278 | load_delay_nop (); |
252b5132 | 9279 | if (breg != 0) |
67c0d1eb | 9280 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT); |
beae10d5 | 9281 | /* Itbl support may require additional care here. */ |
67c0d1eb RS |
9282 | macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg, |
9283 | BFD_RELOC_LO16, AT); | |
4d7206a2 | 9284 | offset_expr.X_add_number += 4; |
252b5132 RH |
9285 | |
9286 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
9287 | nop. */ | |
9288 | hold_mips_optimize = mips_optimize; | |
9289 | mips_optimize = 2; | |
beae10d5 | 9290 | /* Itbl support may require additional care here. */ |
67c0d1eb RS |
9291 | macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1, |
9292 | BFD_RELOC_LO16, AT); | |
252b5132 | 9293 | mips_optimize = hold_mips_optimize; |
4d7206a2 | 9294 | relax_end (); |
252b5132 | 9295 | } |
252b5132 RH |
9296 | else |
9297 | abort (); | |
9298 | ||
252b5132 RH |
9299 | break; |
9300 | ||
9301 | case M_LD_OB: | |
704897fb | 9302 | s = HAVE_64BIT_GPRS ? "ld" : "lw"; |
252b5132 RH |
9303 | goto sd_ob; |
9304 | case M_SD_OB: | |
704897fb | 9305 | s = HAVE_64BIT_GPRS ? "sd" : "sw"; |
252b5132 | 9306 | sd_ob: |
4614d845 MR |
9307 | macro_build (&offset_expr, s, "t,o(b)", treg, |
9308 | -1, offset_reloc[0], offset_reloc[1], offset_reloc[2], | |
9309 | breg); | |
704897fb MR |
9310 | if (!HAVE_64BIT_GPRS) |
9311 | { | |
9312 | offset_expr.X_add_number += 4; | |
9313 | macro_build (&offset_expr, s, "t,o(b)", treg + 1, | |
4614d845 MR |
9314 | -1, offset_reloc[0], offset_reloc[1], offset_reloc[2], |
9315 | breg); | |
704897fb | 9316 | } |
8fc2e39e | 9317 | break; |
252b5132 | 9318 | |
dd6a37e7 AP |
9319 | |
9320 | case M_SAA_AB: | |
9321 | ab = 1; | |
9322 | case M_SAA_OB: | |
9323 | s = "saa"; | |
9324 | off0 = 1; | |
9325 | fmt = "t,(b)"; | |
9326 | goto ld_st; | |
9327 | case M_SAAD_AB: | |
9328 | ab = 1; | |
9329 | case M_SAAD_OB: | |
9330 | s = "saad"; | |
9331 | off0 = 1; | |
9332 | fmt = "t,(b)"; | |
9333 | goto ld_st; | |
9334 | ||
252b5132 RH |
9335 | /* New code added to support COPZ instructions. |
9336 | This code builds table entries out of the macros in mip_opcodes. | |
9337 | R4000 uses interlocks to handle coproc delays. | |
9338 | Other chips (like the R3000) require nops to be inserted for delays. | |
9339 | ||
f72c8c98 | 9340 | FIXME: Currently, we require that the user handle delays. |
252b5132 RH |
9341 | In order to fill delay slots for non-interlocked chips, |
9342 | we must have a way to specify delays based on the coprocessor. | |
9343 | Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc. | |
9344 | What are the side-effects of the cop instruction? | |
9345 | What cache support might we have and what are its effects? | |
9346 | Both coprocessor & memory require delays. how long??? | |
bdaaa2e1 | 9347 | What registers are read/set/modified? |
252b5132 RH |
9348 | |
9349 | If an itbl is provided to interpret cop instructions, | |
bdaaa2e1 | 9350 | this knowledge can be encoded in the itbl spec. */ |
252b5132 RH |
9351 | |
9352 | case M_COP0: | |
9353 | s = "c0"; | |
9354 | goto copz; | |
9355 | case M_COP1: | |
9356 | s = "c1"; | |
9357 | goto copz; | |
9358 | case M_COP2: | |
9359 | s = "c2"; | |
9360 | goto copz; | |
9361 | case M_COP3: | |
9362 | s = "c3"; | |
9363 | copz: | |
df58fc94 | 9364 | gas_assert (!mips_opts.micromips); |
252b5132 RH |
9365 | /* For now we just do C (same as Cz). The parameter will be |
9366 | stored in insn_opcode by mips_ip. */ | |
67c0d1eb | 9367 | macro_build (NULL, s, "C", ip->insn_opcode); |
8fc2e39e | 9368 | break; |
252b5132 | 9369 | |
ea1fb5dc | 9370 | case M_MOVE: |
67c0d1eb | 9371 | move_register (dreg, sreg); |
8fc2e39e | 9372 | break; |
ea1fb5dc | 9373 | |
252b5132 RH |
9374 | case M_DMUL: |
9375 | dbl = 1; | |
9376 | case M_MUL: | |
e407c74b NC |
9377 | if (mips_opts.arch == CPU_R5900) |
9378 | { | |
9379 | macro_build (NULL, dbl ? "dmultu" : "multu", "d,s,t", dreg, sreg, treg); | |
9380 | } | |
9381 | else | |
9382 | { | |
67c0d1eb | 9383 | macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg); |
df58fc94 | 9384 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
e407c74b | 9385 | } |
8fc2e39e | 9386 | break; |
252b5132 RH |
9387 | |
9388 | case M_DMUL_I: | |
9389 | dbl = 1; | |
9390 | case M_MUL_I: | |
9391 | /* The MIPS assembler some times generates shifts and adds. I'm | |
9392 | not trying to be that fancy. GCC should do this for us | |
9393 | anyway. */ | |
8fc2e39e | 9394 | used_at = 1; |
67c0d1eb RS |
9395 | load_register (AT, &imm_expr, dbl); |
9396 | macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT); | |
df58fc94 | 9397 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
252b5132 RH |
9398 | break; |
9399 | ||
9400 | case M_DMULO_I: | |
9401 | dbl = 1; | |
9402 | case M_MULO_I: | |
9403 | imm = 1; | |
9404 | goto do_mulo; | |
9405 | ||
9406 | case M_DMULO: | |
9407 | dbl = 1; | |
9408 | case M_MULO: | |
9409 | do_mulo: | |
7d10b47d | 9410 | start_noreorder (); |
8fc2e39e | 9411 | used_at = 1; |
252b5132 | 9412 | if (imm) |
67c0d1eb RS |
9413 | load_register (AT, &imm_expr, dbl); |
9414 | macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg); | |
df58fc94 RS |
9415 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
9416 | macro_build (NULL, dbl ? "dsra32" : "sra", SHFT_FMT, dreg, dreg, RA); | |
9417 | macro_build (NULL, "mfhi", MFHL_FMT, AT); | |
252b5132 | 9418 | if (mips_trap) |
df58fc94 | 9419 | macro_build (NULL, "tne", TRAP_FMT, dreg, AT, 6); |
252b5132 RH |
9420 | else |
9421 | { | |
df58fc94 RS |
9422 | if (mips_opts.micromips) |
9423 | micromips_label_expr (&label_expr); | |
9424 | else | |
9425 | label_expr.X_add_number = 8; | |
9426 | macro_build (&label_expr, "beq", "s,t,p", dreg, AT); | |
a605d2b3 | 9427 | macro_build (NULL, "nop", ""); |
df58fc94 RS |
9428 | macro_build (NULL, "break", BRK_FMT, 6); |
9429 | if (mips_opts.micromips) | |
9430 | micromips_add_label (); | |
252b5132 | 9431 | } |
7d10b47d | 9432 | end_noreorder (); |
df58fc94 | 9433 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
252b5132 RH |
9434 | break; |
9435 | ||
9436 | case M_DMULOU_I: | |
9437 | dbl = 1; | |
9438 | case M_MULOU_I: | |
9439 | imm = 1; | |
9440 | goto do_mulou; | |
9441 | ||
9442 | case M_DMULOU: | |
9443 | dbl = 1; | |
9444 | case M_MULOU: | |
9445 | do_mulou: | |
7d10b47d | 9446 | start_noreorder (); |
8fc2e39e | 9447 | used_at = 1; |
252b5132 | 9448 | if (imm) |
67c0d1eb RS |
9449 | load_register (AT, &imm_expr, dbl); |
9450 | macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", | |
17a2f251 | 9451 | sreg, imm ? AT : treg); |
df58fc94 RS |
9452 | macro_build (NULL, "mfhi", MFHL_FMT, AT); |
9453 | macro_build (NULL, "mflo", MFHL_FMT, dreg); | |
252b5132 | 9454 | if (mips_trap) |
df58fc94 | 9455 | macro_build (NULL, "tne", TRAP_FMT, AT, ZERO, 6); |
252b5132 RH |
9456 | else |
9457 | { | |
df58fc94 RS |
9458 | if (mips_opts.micromips) |
9459 | micromips_label_expr (&label_expr); | |
9460 | else | |
9461 | label_expr.X_add_number = 8; | |
9462 | macro_build (&label_expr, "beq", "s,t,p", AT, ZERO); | |
a605d2b3 | 9463 | macro_build (NULL, "nop", ""); |
df58fc94 RS |
9464 | macro_build (NULL, "break", BRK_FMT, 6); |
9465 | if (mips_opts.micromips) | |
9466 | micromips_add_label (); | |
252b5132 | 9467 | } |
7d10b47d | 9468 | end_noreorder (); |
252b5132 RH |
9469 | break; |
9470 | ||
771c7ce4 | 9471 | case M_DROL: |
fef14a42 | 9472 | if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch)) |
82dd0097 CD |
9473 | { |
9474 | if (dreg == sreg) | |
9475 | { | |
9476 | tempreg = AT; | |
9477 | used_at = 1; | |
9478 | } | |
9479 | else | |
9480 | { | |
9481 | tempreg = dreg; | |
82dd0097 | 9482 | } |
67c0d1eb RS |
9483 | macro_build (NULL, "dnegu", "d,w", tempreg, treg); |
9484 | macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg); | |
8fc2e39e | 9485 | break; |
82dd0097 | 9486 | } |
8fc2e39e | 9487 | used_at = 1; |
c80c840e | 9488 | macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg); |
67c0d1eb RS |
9489 | macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT); |
9490 | macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg); | |
9491 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); | |
771c7ce4 TS |
9492 | break; |
9493 | ||
252b5132 | 9494 | case M_ROL: |
fef14a42 | 9495 | if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch)) |
82dd0097 CD |
9496 | { |
9497 | if (dreg == sreg) | |
9498 | { | |
9499 | tempreg = AT; | |
9500 | used_at = 1; | |
9501 | } | |
9502 | else | |
9503 | { | |
9504 | tempreg = dreg; | |
82dd0097 | 9505 | } |
67c0d1eb RS |
9506 | macro_build (NULL, "negu", "d,w", tempreg, treg); |
9507 | macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg); | |
8fc2e39e | 9508 | break; |
82dd0097 | 9509 | } |
8fc2e39e | 9510 | used_at = 1; |
c80c840e | 9511 | macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg); |
67c0d1eb RS |
9512 | macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT); |
9513 | macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg); | |
9514 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); | |
252b5132 RH |
9515 | break; |
9516 | ||
771c7ce4 TS |
9517 | case M_DROL_I: |
9518 | { | |
9519 | unsigned int rot; | |
91d6fa6a NC |
9520 | char *l; |
9521 | char *rr; | |
771c7ce4 TS |
9522 | |
9523 | if (imm_expr.X_op != O_constant) | |
82dd0097 | 9524 | as_bad (_("Improper rotate count")); |
771c7ce4 | 9525 | rot = imm_expr.X_add_number & 0x3f; |
fef14a42 | 9526 | if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch)) |
60b63b72 RS |
9527 | { |
9528 | rot = (64 - rot) & 0x3f; | |
9529 | if (rot >= 32) | |
df58fc94 | 9530 | macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32); |
60b63b72 | 9531 | else |
df58fc94 | 9532 | macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot); |
8fc2e39e | 9533 | break; |
60b63b72 | 9534 | } |
483fc7cd | 9535 | if (rot == 0) |
483fc7cd | 9536 | { |
df58fc94 | 9537 | macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0); |
8fc2e39e | 9538 | break; |
483fc7cd | 9539 | } |
82dd0097 | 9540 | l = (rot < 0x20) ? "dsll" : "dsll32"; |
91d6fa6a | 9541 | rr = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32"; |
82dd0097 | 9542 | rot &= 0x1f; |
8fc2e39e | 9543 | used_at = 1; |
df58fc94 RS |
9544 | macro_build (NULL, l, SHFT_FMT, AT, sreg, rot); |
9545 | macro_build (NULL, rr, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f); | |
67c0d1eb | 9546 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
771c7ce4 TS |
9547 | } |
9548 | break; | |
9549 | ||
252b5132 | 9550 | case M_ROL_I: |
771c7ce4 TS |
9551 | { |
9552 | unsigned int rot; | |
9553 | ||
9554 | if (imm_expr.X_op != O_constant) | |
82dd0097 | 9555 | as_bad (_("Improper rotate count")); |
771c7ce4 | 9556 | rot = imm_expr.X_add_number & 0x1f; |
fef14a42 | 9557 | if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch)) |
60b63b72 | 9558 | { |
df58fc94 | 9559 | macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, (32 - rot) & 0x1f); |
8fc2e39e | 9560 | break; |
60b63b72 | 9561 | } |
483fc7cd | 9562 | if (rot == 0) |
483fc7cd | 9563 | { |
df58fc94 | 9564 | macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0); |
8fc2e39e | 9565 | break; |
483fc7cd | 9566 | } |
8fc2e39e | 9567 | used_at = 1; |
df58fc94 RS |
9568 | macro_build (NULL, "sll", SHFT_FMT, AT, sreg, rot); |
9569 | macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f); | |
67c0d1eb | 9570 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
771c7ce4 TS |
9571 | } |
9572 | break; | |
9573 | ||
9574 | case M_DROR: | |
fef14a42 | 9575 | if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch)) |
82dd0097 | 9576 | { |
67c0d1eb | 9577 | macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg); |
8fc2e39e | 9578 | break; |
82dd0097 | 9579 | } |
8fc2e39e | 9580 | used_at = 1; |
c80c840e | 9581 | macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg); |
67c0d1eb RS |
9582 | macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT); |
9583 | macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg); | |
9584 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); | |
252b5132 RH |
9585 | break; |
9586 | ||
9587 | case M_ROR: | |
fef14a42 | 9588 | if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch)) |
82dd0097 | 9589 | { |
67c0d1eb | 9590 | macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg); |
8fc2e39e | 9591 | break; |
82dd0097 | 9592 | } |
8fc2e39e | 9593 | used_at = 1; |
c80c840e | 9594 | macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg); |
67c0d1eb RS |
9595 | macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT); |
9596 | macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg); | |
9597 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); | |
252b5132 RH |
9598 | break; |
9599 | ||
771c7ce4 TS |
9600 | case M_DROR_I: |
9601 | { | |
9602 | unsigned int rot; | |
91d6fa6a NC |
9603 | char *l; |
9604 | char *rr; | |
771c7ce4 TS |
9605 | |
9606 | if (imm_expr.X_op != O_constant) | |
82dd0097 | 9607 | as_bad (_("Improper rotate count")); |
771c7ce4 | 9608 | rot = imm_expr.X_add_number & 0x3f; |
fef14a42 | 9609 | if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch)) |
82dd0097 CD |
9610 | { |
9611 | if (rot >= 32) | |
df58fc94 | 9612 | macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32); |
82dd0097 | 9613 | else |
df58fc94 | 9614 | macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot); |
8fc2e39e | 9615 | break; |
82dd0097 | 9616 | } |
483fc7cd | 9617 | if (rot == 0) |
483fc7cd | 9618 | { |
df58fc94 | 9619 | macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0); |
8fc2e39e | 9620 | break; |
483fc7cd | 9621 | } |
91d6fa6a | 9622 | rr = (rot < 0x20) ? "dsrl" : "dsrl32"; |
82dd0097 CD |
9623 | l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32"; |
9624 | rot &= 0x1f; | |
8fc2e39e | 9625 | used_at = 1; |
df58fc94 RS |
9626 | macro_build (NULL, rr, SHFT_FMT, AT, sreg, rot); |
9627 | macro_build (NULL, l, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f); | |
67c0d1eb | 9628 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
771c7ce4 TS |
9629 | } |
9630 | break; | |
9631 | ||
252b5132 | 9632 | case M_ROR_I: |
771c7ce4 TS |
9633 | { |
9634 | unsigned int rot; | |
9635 | ||
9636 | if (imm_expr.X_op != O_constant) | |
82dd0097 | 9637 | as_bad (_("Improper rotate count")); |
771c7ce4 | 9638 | rot = imm_expr.X_add_number & 0x1f; |
fef14a42 | 9639 | if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch)) |
82dd0097 | 9640 | { |
df58fc94 | 9641 | macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, rot); |
8fc2e39e | 9642 | break; |
82dd0097 | 9643 | } |
483fc7cd | 9644 | if (rot == 0) |
483fc7cd | 9645 | { |
df58fc94 | 9646 | macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0); |
8fc2e39e | 9647 | break; |
483fc7cd | 9648 | } |
8fc2e39e | 9649 | used_at = 1; |
df58fc94 RS |
9650 | macro_build (NULL, "srl", SHFT_FMT, AT, sreg, rot); |
9651 | macro_build (NULL, "sll", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f); | |
67c0d1eb | 9652 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
771c7ce4 | 9653 | } |
252b5132 RH |
9654 | break; |
9655 | ||
252b5132 RH |
9656 | case M_SEQ: |
9657 | if (sreg == 0) | |
67c0d1eb | 9658 | macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16); |
252b5132 | 9659 | else if (treg == 0) |
67c0d1eb | 9660 | macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
252b5132 RH |
9661 | else |
9662 | { | |
67c0d1eb RS |
9663 | macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg); |
9664 | macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16); | |
252b5132 | 9665 | } |
8fc2e39e | 9666 | break; |
252b5132 RH |
9667 | |
9668 | case M_SEQ_I: | |
9669 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
9670 | { | |
67c0d1eb | 9671 | macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
8fc2e39e | 9672 | break; |
252b5132 RH |
9673 | } |
9674 | if (sreg == 0) | |
9675 | { | |
9676 | as_warn (_("Instruction %s: result is always false"), | |
9677 | ip->insn_mo->name); | |
67c0d1eb | 9678 | move_register (dreg, 0); |
8fc2e39e | 9679 | break; |
252b5132 | 9680 | } |
dd3cbb7e NC |
9681 | if (CPU_HAS_SEQ (mips_opts.arch) |
9682 | && -512 <= imm_expr.X_add_number | |
9683 | && imm_expr.X_add_number < 512) | |
9684 | { | |
9685 | macro_build (NULL, "seqi", "t,r,+Q", dreg, sreg, | |
750bdd57 | 9686 | (int) imm_expr.X_add_number); |
dd3cbb7e NC |
9687 | break; |
9688 | } | |
252b5132 RH |
9689 | if (imm_expr.X_op == O_constant |
9690 | && imm_expr.X_add_number >= 0 | |
9691 | && imm_expr.X_add_number < 0x10000) | |
9692 | { | |
67c0d1eb | 9693 | macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16); |
252b5132 RH |
9694 | } |
9695 | else if (imm_expr.X_op == O_constant | |
9696 | && imm_expr.X_add_number > -0x8000 | |
9697 | && imm_expr.X_add_number < 0) | |
9698 | { | |
9699 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
67c0d1eb | 9700 | macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
17a2f251 | 9701 | "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
252b5132 | 9702 | } |
dd3cbb7e NC |
9703 | else if (CPU_HAS_SEQ (mips_opts.arch)) |
9704 | { | |
9705 | used_at = 1; | |
9706 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); | |
9707 | macro_build (NULL, "seq", "d,v,t", dreg, sreg, AT); | |
9708 | break; | |
9709 | } | |
252b5132 RH |
9710 | else |
9711 | { | |
67c0d1eb RS |
9712 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
9713 | macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
9714 | used_at = 1; |
9715 | } | |
67c0d1eb | 9716 | macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16); |
8fc2e39e | 9717 | break; |
252b5132 RH |
9718 | |
9719 | case M_SGE: /* sreg >= treg <==> not (sreg < treg) */ | |
9720 | s = "slt"; | |
9721 | goto sge; | |
9722 | case M_SGEU: | |
9723 | s = "sltu"; | |
9724 | sge: | |
67c0d1eb RS |
9725 | macro_build (NULL, s, "d,v,t", dreg, sreg, treg); |
9726 | macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16); | |
8fc2e39e | 9727 | break; |
252b5132 RH |
9728 | |
9729 | case M_SGE_I: /* sreg >= I <==> not (sreg < I) */ | |
9730 | case M_SGEU_I: | |
9731 | if (imm_expr.X_op == O_constant | |
9732 | && imm_expr.X_add_number >= -0x8000 | |
9733 | && imm_expr.X_add_number < 0x8000) | |
9734 | { | |
67c0d1eb RS |
9735 | macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j", |
9736 | dreg, sreg, BFD_RELOC_LO16); | |
252b5132 RH |
9737 | } |
9738 | else | |
9739 | { | |
67c0d1eb RS |
9740 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
9741 | macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t", | |
9742 | dreg, sreg, AT); | |
252b5132 RH |
9743 | used_at = 1; |
9744 | } | |
67c0d1eb | 9745 | macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16); |
8fc2e39e | 9746 | break; |
252b5132 RH |
9747 | |
9748 | case M_SGT: /* sreg > treg <==> treg < sreg */ | |
9749 | s = "slt"; | |
9750 | goto sgt; | |
9751 | case M_SGTU: | |
9752 | s = "sltu"; | |
9753 | sgt: | |
67c0d1eb | 9754 | macro_build (NULL, s, "d,v,t", dreg, treg, sreg); |
8fc2e39e | 9755 | break; |
252b5132 RH |
9756 | |
9757 | case M_SGT_I: /* sreg > I <==> I < sreg */ | |
9758 | s = "slt"; | |
9759 | goto sgti; | |
9760 | case M_SGTU_I: | |
9761 | s = "sltu"; | |
9762 | sgti: | |
8fc2e39e | 9763 | used_at = 1; |
67c0d1eb RS |
9764 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
9765 | macro_build (NULL, s, "d,v,t", dreg, AT, sreg); | |
252b5132 RH |
9766 | break; |
9767 | ||
2396cfb9 | 9768 | case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */ |
252b5132 RH |
9769 | s = "slt"; |
9770 | goto sle; | |
9771 | case M_SLEU: | |
9772 | s = "sltu"; | |
9773 | sle: | |
67c0d1eb RS |
9774 | macro_build (NULL, s, "d,v,t", dreg, treg, sreg); |
9775 | macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16); | |
8fc2e39e | 9776 | break; |
252b5132 | 9777 | |
2396cfb9 | 9778 | case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */ |
252b5132 RH |
9779 | s = "slt"; |
9780 | goto slei; | |
9781 | case M_SLEU_I: | |
9782 | s = "sltu"; | |
9783 | slei: | |
8fc2e39e | 9784 | used_at = 1; |
67c0d1eb RS |
9785 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
9786 | macro_build (NULL, s, "d,v,t", dreg, AT, sreg); | |
9787 | macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16); | |
252b5132 RH |
9788 | break; |
9789 | ||
9790 | case M_SLT_I: | |
9791 | if (imm_expr.X_op == O_constant | |
9792 | && imm_expr.X_add_number >= -0x8000 | |
9793 | && imm_expr.X_add_number < 0x8000) | |
9794 | { | |
67c0d1eb | 9795 | macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
8fc2e39e | 9796 | break; |
252b5132 | 9797 | } |
8fc2e39e | 9798 | used_at = 1; |
67c0d1eb RS |
9799 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
9800 | macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
9801 | break; |
9802 | ||
9803 | case M_SLTU_I: | |
9804 | if (imm_expr.X_op == O_constant | |
9805 | && imm_expr.X_add_number >= -0x8000 | |
9806 | && imm_expr.X_add_number < 0x8000) | |
9807 | { | |
67c0d1eb | 9808 | macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg, |
17a2f251 | 9809 | BFD_RELOC_LO16); |
8fc2e39e | 9810 | break; |
252b5132 | 9811 | } |
8fc2e39e | 9812 | used_at = 1; |
67c0d1eb RS |
9813 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
9814 | macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
9815 | break; |
9816 | ||
9817 | case M_SNE: | |
9818 | if (sreg == 0) | |
67c0d1eb | 9819 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg); |
252b5132 | 9820 | else if (treg == 0) |
67c0d1eb | 9821 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg); |
252b5132 RH |
9822 | else |
9823 | { | |
67c0d1eb RS |
9824 | macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg); |
9825 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg); | |
252b5132 | 9826 | } |
8fc2e39e | 9827 | break; |
252b5132 RH |
9828 | |
9829 | case M_SNE_I: | |
9830 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
9831 | { | |
67c0d1eb | 9832 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg); |
8fc2e39e | 9833 | break; |
252b5132 RH |
9834 | } |
9835 | if (sreg == 0) | |
9836 | { | |
9837 | as_warn (_("Instruction %s: result is always true"), | |
9838 | ip->insn_mo->name); | |
67c0d1eb RS |
9839 | macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j", |
9840 | dreg, 0, BFD_RELOC_LO16); | |
8fc2e39e | 9841 | break; |
252b5132 | 9842 | } |
dd3cbb7e NC |
9843 | if (CPU_HAS_SEQ (mips_opts.arch) |
9844 | && -512 <= imm_expr.X_add_number | |
9845 | && imm_expr.X_add_number < 512) | |
9846 | { | |
9847 | macro_build (NULL, "snei", "t,r,+Q", dreg, sreg, | |
750bdd57 | 9848 | (int) imm_expr.X_add_number); |
dd3cbb7e NC |
9849 | break; |
9850 | } | |
252b5132 RH |
9851 | if (imm_expr.X_op == O_constant |
9852 | && imm_expr.X_add_number >= 0 | |
9853 | && imm_expr.X_add_number < 0x10000) | |
9854 | { | |
67c0d1eb | 9855 | macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16); |
252b5132 RH |
9856 | } |
9857 | else if (imm_expr.X_op == O_constant | |
9858 | && imm_expr.X_add_number > -0x8000 | |
9859 | && imm_expr.X_add_number < 0) | |
9860 | { | |
9861 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
67c0d1eb | 9862 | macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
17a2f251 | 9863 | "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
252b5132 | 9864 | } |
dd3cbb7e NC |
9865 | else if (CPU_HAS_SEQ (mips_opts.arch)) |
9866 | { | |
9867 | used_at = 1; | |
9868 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); | |
9869 | macro_build (NULL, "sne", "d,v,t", dreg, sreg, AT); | |
9870 | break; | |
9871 | } | |
252b5132 RH |
9872 | else |
9873 | { | |
67c0d1eb RS |
9874 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
9875 | macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
9876 | used_at = 1; |
9877 | } | |
67c0d1eb | 9878 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg); |
8fc2e39e | 9879 | break; |
252b5132 | 9880 | |
df58fc94 RS |
9881 | case M_SUB_I: |
9882 | s = "addi"; | |
9883 | s2 = "sub"; | |
9884 | goto do_subi; | |
9885 | case M_SUBU_I: | |
9886 | s = "addiu"; | |
9887 | s2 = "subu"; | |
9888 | goto do_subi; | |
252b5132 RH |
9889 | case M_DSUB_I: |
9890 | dbl = 1; | |
df58fc94 RS |
9891 | s = "daddi"; |
9892 | s2 = "dsub"; | |
9893 | if (!mips_opts.micromips) | |
9894 | goto do_subi; | |
252b5132 | 9895 | if (imm_expr.X_op == O_constant |
df58fc94 RS |
9896 | && imm_expr.X_add_number > -0x200 |
9897 | && imm_expr.X_add_number <= 0x200) | |
252b5132 | 9898 | { |
df58fc94 | 9899 | macro_build (NULL, s, "t,r,.", dreg, sreg, -imm_expr.X_add_number); |
8fc2e39e | 9900 | break; |
252b5132 | 9901 | } |
df58fc94 | 9902 | goto do_subi_i; |
252b5132 RH |
9903 | case M_DSUBU_I: |
9904 | dbl = 1; | |
df58fc94 RS |
9905 | s = "daddiu"; |
9906 | s2 = "dsubu"; | |
9907 | do_subi: | |
252b5132 RH |
9908 | if (imm_expr.X_op == O_constant |
9909 | && imm_expr.X_add_number > -0x8000 | |
9910 | && imm_expr.X_add_number <= 0x8000) | |
9911 | { | |
9912 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
df58fc94 | 9913 | macro_build (&imm_expr, s, "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
8fc2e39e | 9914 | break; |
252b5132 | 9915 | } |
df58fc94 | 9916 | do_subi_i: |
8fc2e39e | 9917 | used_at = 1; |
67c0d1eb | 9918 | load_register (AT, &imm_expr, dbl); |
df58fc94 | 9919 | macro_build (NULL, s2, "d,v,t", dreg, sreg, AT); |
252b5132 RH |
9920 | break; |
9921 | ||
9922 | case M_TEQ_I: | |
9923 | s = "teq"; | |
9924 | goto trap; | |
9925 | case M_TGE_I: | |
9926 | s = "tge"; | |
9927 | goto trap; | |
9928 | case M_TGEU_I: | |
9929 | s = "tgeu"; | |
9930 | goto trap; | |
9931 | case M_TLT_I: | |
9932 | s = "tlt"; | |
9933 | goto trap; | |
9934 | case M_TLTU_I: | |
9935 | s = "tltu"; | |
9936 | goto trap; | |
9937 | case M_TNE_I: | |
9938 | s = "tne"; | |
9939 | trap: | |
8fc2e39e | 9940 | used_at = 1; |
67c0d1eb RS |
9941 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
9942 | macro_build (NULL, s, "s,t", sreg, AT); | |
252b5132 RH |
9943 | break; |
9944 | ||
252b5132 | 9945 | case M_TRUNCWS: |
43841e91 | 9946 | case M_TRUNCWD: |
df58fc94 | 9947 | gas_assert (!mips_opts.micromips); |
0aa27725 | 9948 | gas_assert (mips_opts.isa == ISA_MIPS1); |
8fc2e39e | 9949 | used_at = 1; |
252b5132 RH |
9950 | sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */ |
9951 | dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */ | |
9952 | ||
9953 | /* | |
9954 | * Is the double cfc1 instruction a bug in the mips assembler; | |
9955 | * or is there a reason for it? | |
9956 | */ | |
7d10b47d | 9957 | start_noreorder (); |
67c0d1eb RS |
9958 | macro_build (NULL, "cfc1", "t,G", treg, RA); |
9959 | macro_build (NULL, "cfc1", "t,G", treg, RA); | |
9960 | macro_build (NULL, "nop", ""); | |
252b5132 | 9961 | expr1.X_add_number = 3; |
67c0d1eb | 9962 | macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16); |
252b5132 | 9963 | expr1.X_add_number = 2; |
67c0d1eb RS |
9964 | macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16); |
9965 | macro_build (NULL, "ctc1", "t,G", AT, RA); | |
9966 | macro_build (NULL, "nop", ""); | |
9967 | macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", | |
9968 | dreg, sreg); | |
9969 | macro_build (NULL, "ctc1", "t,G", treg, RA); | |
9970 | macro_build (NULL, "nop", ""); | |
7d10b47d | 9971 | end_noreorder (); |
252b5132 RH |
9972 | break; |
9973 | ||
df58fc94 RS |
9974 | case M_ULH_A: |
9975 | ab = 1; | |
252b5132 RH |
9976 | case M_ULH: |
9977 | s = "lb"; | |
df58fc94 RS |
9978 | s2 = "lbu"; |
9979 | off = 1; | |
9980 | goto uld_st; | |
9981 | case M_ULHU_A: | |
9982 | ab = 1; | |
252b5132 RH |
9983 | case M_ULHU: |
9984 | s = "lbu"; | |
df58fc94 RS |
9985 | s2 = "lbu"; |
9986 | off = 1; | |
9987 | goto uld_st; | |
9988 | case M_ULW_A: | |
9989 | ab = 1; | |
9990 | case M_ULW: | |
9991 | s = "lwl"; | |
9992 | s2 = "lwr"; | |
9993 | off12 = mips_opts.micromips; | |
9994 | off = 3; | |
9995 | goto uld_st; | |
9996 | case M_ULD_A: | |
9997 | ab = 1; | |
252b5132 RH |
9998 | case M_ULD: |
9999 | s = "ldl"; | |
10000 | s2 = "ldr"; | |
df58fc94 | 10001 | off12 = mips_opts.micromips; |
252b5132 | 10002 | off = 7; |
df58fc94 RS |
10003 | goto uld_st; |
10004 | case M_USH_A: | |
10005 | ab = 1; | |
10006 | case M_USH: | |
10007 | s = "sb"; | |
10008 | s2 = "sb"; | |
10009 | off = 1; | |
10010 | ust = 1; | |
10011 | goto uld_st; | |
10012 | case M_USW_A: | |
10013 | ab = 1; | |
10014 | case M_USW: | |
10015 | s = "swl"; | |
10016 | s2 = "swr"; | |
10017 | off12 = mips_opts.micromips; | |
252b5132 | 10018 | off = 3; |
df58fc94 RS |
10019 | ust = 1; |
10020 | goto uld_st; | |
10021 | case M_USD_A: | |
10022 | ab = 1; | |
10023 | case M_USD: | |
10024 | s = "sdl"; | |
10025 | s2 = "sdr"; | |
10026 | off12 = mips_opts.micromips; | |
10027 | off = 7; | |
10028 | ust = 1; | |
10029 | ||
10030 | uld_st: | |
10031 | if (!ab && offset_expr.X_add_number >= 0x8000 - off) | |
f71d0d44 | 10032 | as_bad (_("Operand overflow")); |
df58fc94 RS |
10033 | |
10034 | ep = &offset_expr; | |
10035 | expr1.X_add_number = 0; | |
10036 | if (ab) | |
10037 | { | |
10038 | used_at = 1; | |
10039 | tempreg = AT; | |
10040 | load_address (tempreg, ep, &used_at); | |
10041 | if (breg != 0) | |
10042 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", | |
10043 | tempreg, tempreg, breg); | |
10044 | breg = tempreg; | |
10045 | tempreg = treg; | |
10046 | ep = &expr1; | |
10047 | } | |
10048 | else if (off12 | |
10049 | && (offset_expr.X_op != O_constant | |
10050 | || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number) | |
10051 | || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number + off))) | |
10052 | { | |
10053 | used_at = 1; | |
10054 | tempreg = AT; | |
10055 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", tempreg, breg, | |
10056 | -1, offset_reloc[0], offset_reloc[1], offset_reloc[2]); | |
10057 | breg = tempreg; | |
10058 | tempreg = treg; | |
10059 | ep = &expr1; | |
10060 | } | |
10061 | else if (!ust && treg == breg) | |
8fc2e39e TS |
10062 | { |
10063 | used_at = 1; | |
10064 | tempreg = AT; | |
10065 | } | |
252b5132 | 10066 | else |
df58fc94 | 10067 | tempreg = treg; |
af22f5b2 | 10068 | |
df58fc94 RS |
10069 | if (off == 1) |
10070 | goto ulh_sh; | |
252b5132 | 10071 | |
90ecf173 | 10072 | if (!target_big_endian) |
df58fc94 RS |
10073 | ep->X_add_number += off; |
10074 | if (!off12) | |
10075 | macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg); | |
252b5132 | 10076 | else |
df58fc94 RS |
10077 | macro_build (NULL, s, "t,~(b)", |
10078 | tempreg, (unsigned long) ep->X_add_number, breg); | |
10079 | ||
90ecf173 | 10080 | if (!target_big_endian) |
df58fc94 | 10081 | ep->X_add_number -= off; |
252b5132 | 10082 | else |
df58fc94 RS |
10083 | ep->X_add_number += off; |
10084 | if (!off12) | |
10085 | macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg); | |
10086 | else | |
10087 | macro_build (NULL, s2, "t,~(b)", | |
10088 | tempreg, (unsigned long) ep->X_add_number, breg); | |
252b5132 | 10089 | |
df58fc94 RS |
10090 | /* If necessary, move the result in tempreg to the final destination. */ |
10091 | if (!ust && treg != tempreg) | |
10092 | { | |
10093 | /* Protect second load's delay slot. */ | |
10094 | load_delay_nop (); | |
10095 | move_register (treg, tempreg); | |
10096 | } | |
8fc2e39e | 10097 | break; |
252b5132 | 10098 | |
df58fc94 | 10099 | ulh_sh: |
d6bc6245 | 10100 | used_at = 1; |
df58fc94 RS |
10101 | if (target_big_endian == ust) |
10102 | ep->X_add_number += off; | |
10103 | tempreg = ust || ab ? treg : AT; | |
10104 | macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg); | |
10105 | ||
10106 | /* For halfword transfers we need a temporary register to shuffle | |
10107 | bytes. Unfortunately for M_USH_A we have none available before | |
10108 | the next store as AT holds the base address. We deal with this | |
10109 | case by clobbering TREG and then restoring it as with ULH. */ | |
10110 | tempreg = ust == ab ? treg : AT; | |
10111 | if (ust) | |
10112 | macro_build (NULL, "srl", SHFT_FMT, tempreg, treg, 8); | |
10113 | ||
10114 | if (target_big_endian == ust) | |
10115 | ep->X_add_number -= off; | |
252b5132 | 10116 | else |
df58fc94 RS |
10117 | ep->X_add_number += off; |
10118 | macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg); | |
252b5132 | 10119 | |
df58fc94 RS |
10120 | /* For M_USH_A re-retrieve the LSB. */ |
10121 | if (ust && ab) | |
10122 | { | |
10123 | if (target_big_endian) | |
10124 | ep->X_add_number += off; | |
10125 | else | |
10126 | ep->X_add_number -= off; | |
10127 | macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT); | |
10128 | } | |
10129 | /* For ULH and M_USH_A OR the LSB in. */ | |
10130 | if (!ust || ab) | |
10131 | { | |
10132 | tempreg = !ab ? AT : treg; | |
10133 | macro_build (NULL, "sll", SHFT_FMT, tempreg, tempreg, 8); | |
10134 | macro_build (NULL, "or", "d,v,t", treg, treg, AT); | |
10135 | } | |
252b5132 RH |
10136 | break; |
10137 | ||
10138 | default: | |
10139 | /* FIXME: Check if this is one of the itbl macros, since they | |
bdaaa2e1 | 10140 | are added dynamically. */ |
252b5132 RH |
10141 | as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name); |
10142 | break; | |
10143 | } | |
741fe287 | 10144 | if (!mips_opts.at && used_at) |
8fc2e39e | 10145 | as_bad (_("Macro used $at after \".set noat\"")); |
252b5132 RH |
10146 | } |
10147 | ||
10148 | /* Implement macros in mips16 mode. */ | |
10149 | ||
10150 | static void | |
17a2f251 | 10151 | mips16_macro (struct mips_cl_insn *ip) |
252b5132 RH |
10152 | { |
10153 | int mask; | |
10154 | int xreg, yreg, zreg, tmp; | |
252b5132 RH |
10155 | expressionS expr1; |
10156 | int dbl; | |
10157 | const char *s, *s2, *s3; | |
10158 | ||
10159 | mask = ip->insn_mo->mask; | |
10160 | ||
bf12938e RS |
10161 | xreg = MIPS16_EXTRACT_OPERAND (RX, *ip); |
10162 | yreg = MIPS16_EXTRACT_OPERAND (RY, *ip); | |
10163 | zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip); | |
252b5132 | 10164 | |
252b5132 RH |
10165 | expr1.X_op = O_constant; |
10166 | expr1.X_op_symbol = NULL; | |
10167 | expr1.X_add_symbol = NULL; | |
10168 | expr1.X_add_number = 1; | |
10169 | ||
10170 | dbl = 0; | |
10171 | ||
10172 | switch (mask) | |
10173 | { | |
10174 | default: | |
b37df7c4 | 10175 | abort (); |
252b5132 RH |
10176 | |
10177 | case M_DDIV_3: | |
10178 | dbl = 1; | |
10179 | case M_DIV_3: | |
10180 | s = "mflo"; | |
10181 | goto do_div3; | |
10182 | case M_DREM_3: | |
10183 | dbl = 1; | |
10184 | case M_REM_3: | |
10185 | s = "mfhi"; | |
10186 | do_div3: | |
7d10b47d | 10187 | start_noreorder (); |
67c0d1eb | 10188 | macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg); |
252b5132 | 10189 | expr1.X_add_number = 2; |
67c0d1eb RS |
10190 | macro_build (&expr1, "bnez", "x,p", yreg); |
10191 | macro_build (NULL, "break", "6", 7); | |
bdaaa2e1 | 10192 | |
252b5132 RH |
10193 | /* FIXME: The normal code checks for of -1 / -0x80000000 here, |
10194 | since that causes an overflow. We should do that as well, | |
10195 | but I don't see how to do the comparisons without a temporary | |
10196 | register. */ | |
7d10b47d | 10197 | end_noreorder (); |
67c0d1eb | 10198 | macro_build (NULL, s, "x", zreg); |
252b5132 RH |
10199 | break; |
10200 | ||
10201 | case M_DIVU_3: | |
10202 | s = "divu"; | |
10203 | s2 = "mflo"; | |
10204 | goto do_divu3; | |
10205 | case M_REMU_3: | |
10206 | s = "divu"; | |
10207 | s2 = "mfhi"; | |
10208 | goto do_divu3; | |
10209 | case M_DDIVU_3: | |
10210 | s = "ddivu"; | |
10211 | s2 = "mflo"; | |
10212 | goto do_divu3; | |
10213 | case M_DREMU_3: | |
10214 | s = "ddivu"; | |
10215 | s2 = "mfhi"; | |
10216 | do_divu3: | |
7d10b47d | 10217 | start_noreorder (); |
67c0d1eb | 10218 | macro_build (NULL, s, "0,x,y", xreg, yreg); |
252b5132 | 10219 | expr1.X_add_number = 2; |
67c0d1eb RS |
10220 | macro_build (&expr1, "bnez", "x,p", yreg); |
10221 | macro_build (NULL, "break", "6", 7); | |
7d10b47d | 10222 | end_noreorder (); |
67c0d1eb | 10223 | macro_build (NULL, s2, "x", zreg); |
252b5132 RH |
10224 | break; |
10225 | ||
10226 | case M_DMUL: | |
10227 | dbl = 1; | |
10228 | case M_MUL: | |
67c0d1eb RS |
10229 | macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg); |
10230 | macro_build (NULL, "mflo", "x", zreg); | |
8fc2e39e | 10231 | break; |
252b5132 RH |
10232 | |
10233 | case M_DSUBU_I: | |
10234 | dbl = 1; | |
10235 | goto do_subu; | |
10236 | case M_SUBU_I: | |
10237 | do_subu: | |
10238 | if (imm_expr.X_op != O_constant) | |
10239 | as_bad (_("Unsupported large constant")); | |
10240 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
67c0d1eb | 10241 | macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg); |
252b5132 RH |
10242 | break; |
10243 | ||
10244 | case M_SUBU_I_2: | |
10245 | if (imm_expr.X_op != O_constant) | |
10246 | as_bad (_("Unsupported large constant")); | |
10247 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
67c0d1eb | 10248 | macro_build (&imm_expr, "addiu", "x,k", xreg); |
252b5132 RH |
10249 | break; |
10250 | ||
10251 | case M_DSUBU_I_2: | |
10252 | if (imm_expr.X_op != O_constant) | |
10253 | as_bad (_("Unsupported large constant")); | |
10254 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
67c0d1eb | 10255 | macro_build (&imm_expr, "daddiu", "y,j", yreg); |
252b5132 RH |
10256 | break; |
10257 | ||
10258 | case M_BEQ: | |
10259 | s = "cmp"; | |
10260 | s2 = "bteqz"; | |
10261 | goto do_branch; | |
10262 | case M_BNE: | |
10263 | s = "cmp"; | |
10264 | s2 = "btnez"; | |
10265 | goto do_branch; | |
10266 | case M_BLT: | |
10267 | s = "slt"; | |
10268 | s2 = "btnez"; | |
10269 | goto do_branch; | |
10270 | case M_BLTU: | |
10271 | s = "sltu"; | |
10272 | s2 = "btnez"; | |
10273 | goto do_branch; | |
10274 | case M_BLE: | |
10275 | s = "slt"; | |
10276 | s2 = "bteqz"; | |
10277 | goto do_reverse_branch; | |
10278 | case M_BLEU: | |
10279 | s = "sltu"; | |
10280 | s2 = "bteqz"; | |
10281 | goto do_reverse_branch; | |
10282 | case M_BGE: | |
10283 | s = "slt"; | |
10284 | s2 = "bteqz"; | |
10285 | goto do_branch; | |
10286 | case M_BGEU: | |
10287 | s = "sltu"; | |
10288 | s2 = "bteqz"; | |
10289 | goto do_branch; | |
10290 | case M_BGT: | |
10291 | s = "slt"; | |
10292 | s2 = "btnez"; | |
10293 | goto do_reverse_branch; | |
10294 | case M_BGTU: | |
10295 | s = "sltu"; | |
10296 | s2 = "btnez"; | |
10297 | ||
10298 | do_reverse_branch: | |
10299 | tmp = xreg; | |
10300 | xreg = yreg; | |
10301 | yreg = tmp; | |
10302 | ||
10303 | do_branch: | |
67c0d1eb RS |
10304 | macro_build (NULL, s, "x,y", xreg, yreg); |
10305 | macro_build (&offset_expr, s2, "p"); | |
252b5132 RH |
10306 | break; |
10307 | ||
10308 | case M_BEQ_I: | |
10309 | s = "cmpi"; | |
10310 | s2 = "bteqz"; | |
10311 | s3 = "x,U"; | |
10312 | goto do_branch_i; | |
10313 | case M_BNE_I: | |
10314 | s = "cmpi"; | |
10315 | s2 = "btnez"; | |
10316 | s3 = "x,U"; | |
10317 | goto do_branch_i; | |
10318 | case M_BLT_I: | |
10319 | s = "slti"; | |
10320 | s2 = "btnez"; | |
10321 | s3 = "x,8"; | |
10322 | goto do_branch_i; | |
10323 | case M_BLTU_I: | |
10324 | s = "sltiu"; | |
10325 | s2 = "btnez"; | |
10326 | s3 = "x,8"; | |
10327 | goto do_branch_i; | |
10328 | case M_BLE_I: | |
10329 | s = "slti"; | |
10330 | s2 = "btnez"; | |
10331 | s3 = "x,8"; | |
10332 | goto do_addone_branch_i; | |
10333 | case M_BLEU_I: | |
10334 | s = "sltiu"; | |
10335 | s2 = "btnez"; | |
10336 | s3 = "x,8"; | |
10337 | goto do_addone_branch_i; | |
10338 | case M_BGE_I: | |
10339 | s = "slti"; | |
10340 | s2 = "bteqz"; | |
10341 | s3 = "x,8"; | |
10342 | goto do_branch_i; | |
10343 | case M_BGEU_I: | |
10344 | s = "sltiu"; | |
10345 | s2 = "bteqz"; | |
10346 | s3 = "x,8"; | |
10347 | goto do_branch_i; | |
10348 | case M_BGT_I: | |
10349 | s = "slti"; | |
10350 | s2 = "bteqz"; | |
10351 | s3 = "x,8"; | |
10352 | goto do_addone_branch_i; | |
10353 | case M_BGTU_I: | |
10354 | s = "sltiu"; | |
10355 | s2 = "bteqz"; | |
10356 | s3 = "x,8"; | |
10357 | ||
10358 | do_addone_branch_i: | |
10359 | if (imm_expr.X_op != O_constant) | |
10360 | as_bad (_("Unsupported large constant")); | |
10361 | ++imm_expr.X_add_number; | |
10362 | ||
10363 | do_branch_i: | |
67c0d1eb RS |
10364 | macro_build (&imm_expr, s, s3, xreg); |
10365 | macro_build (&offset_expr, s2, "p"); | |
252b5132 RH |
10366 | break; |
10367 | ||
10368 | case M_ABS: | |
10369 | expr1.X_add_number = 0; | |
67c0d1eb | 10370 | macro_build (&expr1, "slti", "x,8", yreg); |
252b5132 | 10371 | if (xreg != yreg) |
67c0d1eb | 10372 | move_register (xreg, yreg); |
252b5132 | 10373 | expr1.X_add_number = 2; |
67c0d1eb RS |
10374 | macro_build (&expr1, "bteqz", "p"); |
10375 | macro_build (NULL, "neg", "x,w", xreg, xreg); | |
252b5132 RH |
10376 | } |
10377 | } | |
10378 | ||
10379 | /* For consistency checking, verify that all bits are specified either | |
10380 | by the match/mask part of the instruction definition, or by the | |
10381 | operand list. */ | |
10382 | static int | |
17a2f251 | 10383 | validate_mips_insn (const struct mips_opcode *opc) |
252b5132 RH |
10384 | { |
10385 | const char *p = opc->args; | |
10386 | char c; | |
10387 | unsigned long used_bits = opc->mask; | |
10388 | ||
10389 | if ((used_bits & opc->match) != opc->match) | |
10390 | { | |
10391 | as_bad (_("internal: bad mips opcode (mask error): %s %s"), | |
10392 | opc->name, opc->args); | |
10393 | return 0; | |
10394 | } | |
10395 | #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift))) | |
10396 | while (*p) | |
10397 | switch (c = *p++) | |
10398 | { | |
10399 | case ',': break; | |
10400 | case '(': break; | |
10401 | case ')': break; | |
af7ee8bf CD |
10402 | case '+': |
10403 | switch (c = *p++) | |
10404 | { | |
9bcd4f99 TS |
10405 | case '1': USE_BITS (OP_MASK_UDI1, OP_SH_UDI1); break; |
10406 | case '2': USE_BITS (OP_MASK_UDI2, OP_SH_UDI2); break; | |
10407 | case '3': USE_BITS (OP_MASK_UDI3, OP_SH_UDI3); break; | |
10408 | case '4': USE_BITS (OP_MASK_UDI4, OP_SH_UDI4); break; | |
af7ee8bf CD |
10409 | case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
10410 | case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break; | |
10411 | case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break; | |
bbcc0807 CD |
10412 | case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD); |
10413 | USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; | |
5f74bc13 CD |
10414 | case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
10415 | case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break; | |
10416 | case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break; | |
10417 | case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break; | |
10418 | case 'I': break; | |
ef2e4d86 CF |
10419 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; |
10420 | case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT); | |
10421 | USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; | |
bb35fb24 NC |
10422 | case 'x': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break; |
10423 | case 'X': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break; | |
10424 | case 'p': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break; | |
10425 | case 'P': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break; | |
dd3cbb7e | 10426 | case 'Q': USE_BITS (OP_MASK_SEQI, OP_SH_SEQI); break; |
bb35fb24 NC |
10427 | case 's': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break; |
10428 | case 'S': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break; | |
98675402 RS |
10429 | case 'z': USE_BITS (OP_MASK_RZ, OP_SH_RZ); break; |
10430 | case 'Z': USE_BITS (OP_MASK_FZ, OP_SH_FZ); break; | |
10431 | case 'a': USE_BITS (OP_MASK_OFFSET_A, OP_SH_OFFSET_A); break; | |
10432 | case 'b': USE_BITS (OP_MASK_OFFSET_B, OP_SH_OFFSET_B); break; | |
10433 | case 'c': USE_BITS (OP_MASK_OFFSET_C, OP_SH_OFFSET_C); break; | |
bb35fb24 | 10434 | |
af7ee8bf CD |
10435 | default: |
10436 | as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"), | |
10437 | c, opc->name, opc->args); | |
10438 | return 0; | |
10439 | } | |
10440 | break; | |
252b5132 RH |
10441 | case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
10442 | case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
10443 | case 'A': break; | |
4372b673 | 10444 | case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break; |
252b5132 RH |
10445 | case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break; |
10446 | case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break; | |
10447 | case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
10448 | case 'F': break; | |
10449 | case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
156c2f8b | 10450 | case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
252b5132 | 10451 | case 'I': break; |
e972090a | 10452 | case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break; |
af7ee8bf | 10453 | case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break; |
252b5132 RH |
10454 | case 'L': break; |
10455 | case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break; | |
10456 | case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break; | |
deec1734 CD |
10457 | case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break; |
10458 | case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL); | |
10459 | USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
252b5132 RH |
10460 | case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break; |
10461 | case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
10462 | case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
10463 | case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
10464 | case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
deec1734 CD |
10465 | case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break; |
10466 | case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
10467 | case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
252b5132 RH |
10468 | case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break; |
10469 | case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
10470 | case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break; | |
10471 | case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
10472 | case 'f': break; | |
10473 | case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break; | |
10474 | case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
10475 | case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
10476 | case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break; | |
10477 | case 'l': break; | |
10478 | case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
10479 | case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
10480 | case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break; | |
10481 | case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
10482 | case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
10483 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
10484 | case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
10485 | case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
10486 | case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
10487 | case 'x': break; | |
10488 | case 'z': break; | |
10489 | case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break; | |
4372b673 NC |
10490 | case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD); |
10491 | USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
60b63b72 RS |
10492 | case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break; |
10493 | case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break; | |
10494 | case '[': break; | |
10495 | case ']': break; | |
620edafd | 10496 | case '1': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
8b082fb1 | 10497 | case '2': USE_BITS (OP_MASK_BP, OP_SH_BP); break; |
74cd071d CF |
10498 | case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break; |
10499 | case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break; | |
10500 | case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break; | |
10501 | case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
10502 | case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break; | |
10503 | case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break; | |
10504 | case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break; | |
10505 | case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break; | |
10506 | case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break; | |
10507 | case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break; | |
10508 | case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break; | |
ef2e4d86 CF |
10509 | case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break; |
10510 | case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break; | |
10511 | case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break; | |
10512 | case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break; | |
dec0624d MR |
10513 | case '\\': USE_BITS (OP_MASK_3BITPOS, OP_SH_3BITPOS); break; |
10514 | case '~': USE_BITS (OP_MASK_OFFSET12, OP_SH_OFFSET12); break; | |
ef2e4d86 | 10515 | case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break; |
252b5132 RH |
10516 | default: |
10517 | as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"), | |
10518 | c, opc->name, opc->args); | |
10519 | return 0; | |
10520 | } | |
10521 | #undef USE_BITS | |
10522 | if (used_bits != 0xffffffff) | |
10523 | { | |
10524 | as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"), | |
10525 | ~used_bits & 0xffffffff, opc->name, opc->args); | |
10526 | return 0; | |
10527 | } | |
10528 | return 1; | |
10529 | } | |
10530 | ||
df58fc94 RS |
10531 | /* For consistency checking, verify that the length implied matches the |
10532 | major opcode and that all bits are specified either by the match/mask | |
10533 | part of the instruction definition, or by the operand list. */ | |
10534 | ||
10535 | static int | |
10536 | validate_micromips_insn (const struct mips_opcode *opc) | |
10537 | { | |
10538 | unsigned long match = opc->match; | |
10539 | unsigned long mask = opc->mask; | |
10540 | const char *p = opc->args; | |
10541 | unsigned long insn_bits; | |
10542 | unsigned long used_bits; | |
10543 | unsigned long major; | |
10544 | unsigned int length; | |
10545 | char e; | |
10546 | char c; | |
10547 | ||
10548 | if ((mask & match) != match) | |
10549 | { | |
10550 | as_bad (_("Internal error: bad microMIPS opcode (mask error): %s %s"), | |
10551 | opc->name, opc->args); | |
10552 | return 0; | |
10553 | } | |
10554 | length = micromips_insn_length (opc); | |
10555 | if (length != 2 && length != 4) | |
10556 | { | |
10557 | as_bad (_("Internal error: bad microMIPS opcode (incorrect length: %u): " | |
10558 | "%s %s"), length, opc->name, opc->args); | |
10559 | return 0; | |
10560 | } | |
10561 | major = match >> (10 + 8 * (length - 2)); | |
10562 | if ((length == 2 && (major & 7) != 1 && (major & 6) != 2) | |
10563 | || (length == 4 && (major & 7) != 0 && (major & 4) != 4)) | |
10564 | { | |
10565 | as_bad (_("Internal error: bad microMIPS opcode " | |
10566 | "(opcode/length mismatch): %s %s"), opc->name, opc->args); | |
10567 | return 0; | |
10568 | } | |
10569 | ||
10570 | /* Shift piecewise to avoid an overflow where unsigned long is 32-bit. */ | |
10571 | insn_bits = 1 << 4 * length; | |
10572 | insn_bits <<= 4 * length; | |
10573 | insn_bits -= 1; | |
10574 | used_bits = mask; | |
10575 | #define USE_BITS(field) \ | |
10576 | (used_bits |= MICROMIPSOP_MASK_##field << MICROMIPSOP_SH_##field) | |
10577 | while (*p) | |
10578 | switch (c = *p++) | |
10579 | { | |
10580 | case ',': break; | |
10581 | case '(': break; | |
10582 | case ')': break; | |
10583 | case '+': | |
10584 | e = c; | |
10585 | switch (c = *p++) | |
10586 | { | |
10587 | case 'A': USE_BITS (EXTLSB); break; | |
10588 | case 'B': USE_BITS (INSMSB); break; | |
10589 | case 'C': USE_BITS (EXTMSBD); break; | |
10590 | case 'D': USE_BITS (RS); USE_BITS (SEL); break; | |
10591 | case 'E': USE_BITS (EXTLSB); break; | |
10592 | case 'F': USE_BITS (INSMSB); break; | |
10593 | case 'G': USE_BITS (EXTMSBD); break; | |
10594 | case 'H': USE_BITS (EXTMSBD); break; | |
10595 | default: | |
10596 | as_bad (_("Internal error: bad mips opcode " | |
10597 | "(unknown extension operand type `%c%c'): %s %s"), | |
10598 | e, c, opc->name, opc->args); | |
10599 | return 0; | |
10600 | } | |
10601 | break; | |
10602 | case 'm': | |
10603 | e = c; | |
10604 | switch (c = *p++) | |
10605 | { | |
10606 | case 'A': USE_BITS (IMMA); break; | |
10607 | case 'B': USE_BITS (IMMB); break; | |
10608 | case 'C': USE_BITS (IMMC); break; | |
10609 | case 'D': USE_BITS (IMMD); break; | |
10610 | case 'E': USE_BITS (IMME); break; | |
10611 | case 'F': USE_BITS (IMMF); break; | |
10612 | case 'G': USE_BITS (IMMG); break; | |
10613 | case 'H': USE_BITS (IMMH); break; | |
10614 | case 'I': USE_BITS (IMMI); break; | |
10615 | case 'J': USE_BITS (IMMJ); break; | |
10616 | case 'L': USE_BITS (IMML); break; | |
10617 | case 'M': USE_BITS (IMMM); break; | |
10618 | case 'N': USE_BITS (IMMN); break; | |
10619 | case 'O': USE_BITS (IMMO); break; | |
10620 | case 'P': USE_BITS (IMMP); break; | |
10621 | case 'Q': USE_BITS (IMMQ); break; | |
10622 | case 'U': USE_BITS (IMMU); break; | |
10623 | case 'W': USE_BITS (IMMW); break; | |
10624 | case 'X': USE_BITS (IMMX); break; | |
10625 | case 'Y': USE_BITS (IMMY); break; | |
10626 | case 'Z': break; | |
10627 | case 'a': break; | |
10628 | case 'b': USE_BITS (MB); break; | |
10629 | case 'c': USE_BITS (MC); break; | |
10630 | case 'd': USE_BITS (MD); break; | |
10631 | case 'e': USE_BITS (ME); break; | |
10632 | case 'f': USE_BITS (MF); break; | |
10633 | case 'g': USE_BITS (MG); break; | |
10634 | case 'h': USE_BITS (MH); break; | |
10635 | case 'i': USE_BITS (MI); break; | |
10636 | case 'j': USE_BITS (MJ); break; | |
10637 | case 'l': USE_BITS (ML); break; | |
10638 | case 'm': USE_BITS (MM); break; | |
10639 | case 'n': USE_BITS (MN); break; | |
10640 | case 'p': USE_BITS (MP); break; | |
10641 | case 'q': USE_BITS (MQ); break; | |
10642 | case 'r': break; | |
10643 | case 's': break; | |
10644 | case 't': break; | |
10645 | case 'x': break; | |
10646 | case 'y': break; | |
10647 | case 'z': break; | |
10648 | default: | |
10649 | as_bad (_("Internal error: bad mips opcode " | |
10650 | "(unknown extension operand type `%c%c'): %s %s"), | |
10651 | e, c, opc->name, opc->args); | |
10652 | return 0; | |
10653 | } | |
10654 | break; | |
10655 | case '.': USE_BITS (OFFSET10); break; | |
10656 | case '1': USE_BITS (STYPE); break; | |
03f66e8a MR |
10657 | case '2': USE_BITS (BP); break; |
10658 | case '3': USE_BITS (SA3); break; | |
10659 | case '4': USE_BITS (SA4); break; | |
10660 | case '5': USE_BITS (IMM8); break; | |
10661 | case '6': USE_BITS (RS); break; | |
10662 | case '7': USE_BITS (DSPACC); break; | |
10663 | case '8': USE_BITS (WRDSP); break; | |
10664 | case '0': USE_BITS (DSPSFT); break; | |
df58fc94 RS |
10665 | case '<': USE_BITS (SHAMT); break; |
10666 | case '>': USE_BITS (SHAMT); break; | |
03f66e8a | 10667 | case '@': USE_BITS (IMM10); break; |
df58fc94 RS |
10668 | case 'B': USE_BITS (CODE10); break; |
10669 | case 'C': USE_BITS (COPZ); break; | |
10670 | case 'D': USE_BITS (FD); break; | |
10671 | case 'E': USE_BITS (RT); break; | |
10672 | case 'G': USE_BITS (RS); break; | |
444d75be | 10673 | case 'H': USE_BITS (SEL); break; |
df58fc94 RS |
10674 | case 'K': USE_BITS (RS); break; |
10675 | case 'M': USE_BITS (CCC); break; | |
10676 | case 'N': USE_BITS (BCC); break; | |
10677 | case 'R': USE_BITS (FR); break; | |
10678 | case 'S': USE_BITS (FS); break; | |
10679 | case 'T': USE_BITS (FT); break; | |
10680 | case 'V': USE_BITS (FS); break; | |
dec0624d | 10681 | case '\\': USE_BITS (3BITPOS); break; |
03f66e8a | 10682 | case '^': USE_BITS (RD); break; |
df58fc94 RS |
10683 | case 'a': USE_BITS (TARGET); break; |
10684 | case 'b': USE_BITS (RS); break; | |
10685 | case 'c': USE_BITS (CODE); break; | |
10686 | case 'd': USE_BITS (RD); break; | |
10687 | case 'h': USE_BITS (PREFX); break; | |
10688 | case 'i': USE_BITS (IMMEDIATE); break; | |
10689 | case 'j': USE_BITS (DELTA); break; | |
10690 | case 'k': USE_BITS (CACHE); break; | |
10691 | case 'n': USE_BITS (RT); break; | |
10692 | case 'o': USE_BITS (DELTA); break; | |
10693 | case 'p': USE_BITS (DELTA); break; | |
10694 | case 'q': USE_BITS (CODE2); break; | |
10695 | case 'r': USE_BITS (RS); break; | |
10696 | case 's': USE_BITS (RS); break; | |
10697 | case 't': USE_BITS (RT); break; | |
10698 | case 'u': USE_BITS (IMMEDIATE); break; | |
10699 | case 'v': USE_BITS (RS); break; | |
10700 | case 'w': USE_BITS (RT); break; | |
10701 | case 'y': USE_BITS (RS3); break; | |
10702 | case 'z': break; | |
10703 | case '|': USE_BITS (TRAP); break; | |
10704 | case '~': USE_BITS (OFFSET12); break; | |
10705 | default: | |
10706 | as_bad (_("Internal error: bad microMIPS opcode " | |
10707 | "(unknown operand type `%c'): %s %s"), | |
10708 | c, opc->name, opc->args); | |
10709 | return 0; | |
10710 | } | |
10711 | #undef USE_BITS | |
10712 | if (used_bits != insn_bits) | |
10713 | { | |
10714 | if (~used_bits & insn_bits) | |
10715 | as_bad (_("Internal error: bad microMIPS opcode " | |
10716 | "(bits 0x%lx undefined): %s %s"), | |
10717 | ~used_bits & insn_bits, opc->name, opc->args); | |
10718 | if (used_bits & ~insn_bits) | |
10719 | as_bad (_("Internal error: bad microMIPS opcode " | |
10720 | "(bits 0x%lx defined): %s %s"), | |
10721 | used_bits & ~insn_bits, opc->name, opc->args); | |
10722 | return 0; | |
10723 | } | |
10724 | return 1; | |
10725 | } | |
10726 | ||
9bcd4f99 TS |
10727 | /* UDI immediates. */ |
10728 | struct mips_immed { | |
10729 | char type; | |
10730 | unsigned int shift; | |
10731 | unsigned long mask; | |
10732 | const char * desc; | |
10733 | }; | |
10734 | ||
10735 | static const struct mips_immed mips_immed[] = { | |
10736 | { '1', OP_SH_UDI1, OP_MASK_UDI1, 0}, | |
10737 | { '2', OP_SH_UDI2, OP_MASK_UDI2, 0}, | |
10738 | { '3', OP_SH_UDI3, OP_MASK_UDI3, 0}, | |
10739 | { '4', OP_SH_UDI4, OP_MASK_UDI4, 0}, | |
10740 | { 0,0,0,0 } | |
10741 | }; | |
10742 | ||
7455baf8 TS |
10743 | /* Check whether an odd floating-point register is allowed. */ |
10744 | static int | |
10745 | mips_oddfpreg_ok (const struct mips_opcode *insn, int argnum) | |
10746 | { | |
10747 | const char *s = insn->name; | |
10748 | ||
10749 | if (insn->pinfo == INSN_MACRO) | |
10750 | /* Let a macro pass, we'll catch it later when it is expanded. */ | |
10751 | return 1; | |
10752 | ||
e407c74b | 10753 | if (ISA_HAS_ODD_SINGLE_FPR (mips_opts.isa) || (mips_opts.arch == CPU_R5900)) |
7455baf8 TS |
10754 | { |
10755 | /* Allow odd registers for single-precision ops. */ | |
10756 | switch (insn->pinfo & (FP_S | FP_D)) | |
10757 | { | |
10758 | case FP_S: | |
10759 | case 0: | |
10760 | return 1; /* both single precision - ok */ | |
10761 | case FP_D: | |
10762 | return 0; /* both double precision - fail */ | |
10763 | default: | |
10764 | break; | |
10765 | } | |
10766 | ||
10767 | /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */ | |
10768 | s = strchr (insn->name, '.'); | |
10769 | if (argnum == 2) | |
10770 | s = s != NULL ? strchr (s + 1, '.') : NULL; | |
10771 | return (s != NULL && (s[1] == 'w' || s[1] == 's')); | |
10772 | } | |
10773 | ||
10774 | /* Single-precision coprocessor loads and moves are OK too. */ | |
10775 | if ((insn->pinfo & FP_S) | |
10776 | && (insn->pinfo & (INSN_COPROC_MEMORY_DELAY | INSN_STORE_MEMORY | |
10777 | | INSN_LOAD_COPROC_DELAY | INSN_COPROC_MOVE_DELAY))) | |
10778 | return 1; | |
10779 | ||
10780 | return 0; | |
10781 | } | |
10782 | ||
df58fc94 RS |
10783 | /* Check if EXPR is a constant between MIN (inclusive) and MAX (exclusive) |
10784 | taking bits from BIT up. */ | |
10785 | static int | |
10786 | expr_const_in_range (expressionS *ep, offsetT min, offsetT max, int bit) | |
10787 | { | |
10788 | return (ep->X_op == O_constant | |
10789 | && (ep->X_add_number & ((1 << bit) - 1)) == 0 | |
10790 | && ep->X_add_number >= min << bit | |
10791 | && ep->X_add_number < max << bit); | |
10792 | } | |
10793 | ||
252b5132 RH |
10794 | /* This routine assembles an instruction into its binary format. As a |
10795 | side effect, it sets one of the global variables imm_reloc or | |
10796 | offset_reloc to the type of relocation to do if one of the operands | |
10797 | is an address expression. */ | |
10798 | ||
10799 | static void | |
17a2f251 | 10800 | mips_ip (char *str, struct mips_cl_insn *ip) |
252b5132 | 10801 | { |
df58fc94 RS |
10802 | bfd_boolean wrong_delay_slot_insns = FALSE; |
10803 | bfd_boolean need_delay_slot_ok = TRUE; | |
10804 | struct mips_opcode *firstinsn = NULL; | |
10805 | const struct mips_opcode *past; | |
10806 | struct hash_control *hash; | |
252b5132 RH |
10807 | char *s; |
10808 | const char *args; | |
43841e91 | 10809 | char c = 0; |
252b5132 RH |
10810 | struct mips_opcode *insn; |
10811 | char *argsStart; | |
10812 | unsigned int regno; | |
34224acf | 10813 | unsigned int lastregno; |
df58fc94 | 10814 | unsigned int destregno = 0; |
af7ee8bf | 10815 | unsigned int lastpos = 0; |
071742cf | 10816 | unsigned int limlo, limhi; |
f02d8318 | 10817 | int sizelo; |
252b5132 | 10818 | char *s_reset; |
74cd071d | 10819 | offsetT min_range, max_range; |
df58fc94 | 10820 | long opend; |
a40bc9dd | 10821 | char *name; |
707bfff6 TS |
10822 | int argnum; |
10823 | unsigned int rtype; | |
df58fc94 | 10824 | char *dot; |
a40bc9dd | 10825 | long end; |
252b5132 RH |
10826 | |
10827 | insn_error = NULL; | |
10828 | ||
df58fc94 RS |
10829 | if (mips_opts.micromips) |
10830 | { | |
10831 | hash = micromips_op_hash; | |
10832 | past = µmips_opcodes[bfd_micromips_num_opcodes]; | |
10833 | } | |
10834 | else | |
10835 | { | |
10836 | hash = op_hash; | |
10837 | past = &mips_opcodes[NUMOPCODES]; | |
10838 | } | |
10839 | forced_insn_length = 0; | |
252b5132 | 10840 | insn = NULL; |
252b5132 | 10841 | |
df58fc94 | 10842 | /* We first try to match an instruction up to a space or to the end. */ |
a40bc9dd RS |
10843 | for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++) |
10844 | continue; | |
bdaaa2e1 | 10845 | |
a40bc9dd RS |
10846 | /* Make a copy of the instruction so that we can fiddle with it. */ |
10847 | name = alloca (end + 1); | |
10848 | memcpy (name, str, end); | |
10849 | name[end] = '\0'; | |
252b5132 | 10850 | |
df58fc94 RS |
10851 | for (;;) |
10852 | { | |
10853 | insn = (struct mips_opcode *) hash_find (hash, name); | |
10854 | ||
10855 | if (insn != NULL || !mips_opts.micromips) | |
10856 | break; | |
10857 | if (forced_insn_length) | |
10858 | break; | |
10859 | ||
10860 | /* See if there's an instruction size override suffix, | |
10861 | either `16' or `32', at the end of the mnemonic proper, | |
10862 | that defines the operation, i.e. before the first `.' | |
10863 | character if any. Strip it and retry. */ | |
10864 | dot = strchr (name, '.'); | |
10865 | opend = dot != NULL ? dot - name : end; | |
10866 | if (opend < 3) | |
10867 | break; | |
10868 | if (name[opend - 2] == '1' && name[opend - 1] == '6') | |
10869 | forced_insn_length = 2; | |
10870 | else if (name[opend - 2] == '3' && name[opend - 1] == '2') | |
10871 | forced_insn_length = 4; | |
10872 | else | |
10873 | break; | |
10874 | memcpy (name + opend - 2, name + opend, end - opend + 1); | |
10875 | } | |
252b5132 RH |
10876 | if (insn == NULL) |
10877 | { | |
a40bc9dd RS |
10878 | insn_error = _("Unrecognized opcode"); |
10879 | return; | |
252b5132 RH |
10880 | } |
10881 | ||
df58fc94 RS |
10882 | /* For microMIPS instructions placed in a fixed-length branch delay slot |
10883 | we make up to two passes over the relevant fragment of the opcode | |
10884 | table. First we try instructions that meet the delay slot's length | |
10885 | requirement. If none matched, then we retry with the remaining ones | |
10886 | and if one matches, then we use it and then issue an appropriate | |
10887 | warning later on. */ | |
a40bc9dd | 10888 | argsStart = s = str + end; |
252b5132 RH |
10889 | for (;;) |
10890 | { | |
df58fc94 RS |
10891 | bfd_boolean delay_slot_ok; |
10892 | bfd_boolean size_ok; | |
b34976b6 | 10893 | bfd_boolean ok; |
252b5132 | 10894 | |
a40bc9dd | 10895 | gas_assert (strcmp (insn->name, name) == 0); |
252b5132 | 10896 | |
f79e2745 | 10897 | ok = is_opcode_valid (insn); |
df58fc94 RS |
10898 | size_ok = is_size_valid (insn); |
10899 | delay_slot_ok = is_delay_slot_valid (insn); | |
10900 | if (!delay_slot_ok && !wrong_delay_slot_insns) | |
252b5132 | 10901 | { |
df58fc94 RS |
10902 | firstinsn = insn; |
10903 | wrong_delay_slot_insns = TRUE; | |
10904 | } | |
10905 | if (!ok || !size_ok || delay_slot_ok != need_delay_slot_ok) | |
10906 | { | |
10907 | static char buf[256]; | |
10908 | ||
10909 | if (insn + 1 < past && strcmp (insn->name, insn[1].name) == 0) | |
252b5132 RH |
10910 | { |
10911 | ++insn; | |
10912 | continue; | |
10913 | } | |
df58fc94 | 10914 | if (wrong_delay_slot_insns && need_delay_slot_ok) |
beae10d5 | 10915 | { |
df58fc94 RS |
10916 | gas_assert (firstinsn); |
10917 | need_delay_slot_ok = FALSE; | |
10918 | past = insn + 1; | |
10919 | insn = firstinsn; | |
10920 | continue; | |
252b5132 | 10921 | } |
df58fc94 RS |
10922 | |
10923 | if (insn_error) | |
10924 | return; | |
10925 | ||
10926 | if (!ok) | |
7bd942df | 10927 | sprintf (buf, _("Opcode not supported on this processor: %s (%s)"), |
df58fc94 RS |
10928 | mips_cpu_info_from_arch (mips_opts.arch)->name, |
10929 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
10930 | else | |
10931 | sprintf (buf, _("Unrecognized %u-bit version of microMIPS opcode"), | |
10932 | 8 * forced_insn_length); | |
10933 | insn_error = buf; | |
10934 | ||
10935 | return; | |
252b5132 RH |
10936 | } |
10937 | ||
1e915849 | 10938 | create_insn (ip, insn); |
268f6bed | 10939 | insn_error = NULL; |
707bfff6 | 10940 | argnum = 1; |
24864476 | 10941 | lastregno = 0xffffffff; |
252b5132 RH |
10942 | for (args = insn->args;; ++args) |
10943 | { | |
deec1734 CD |
10944 | int is_mdmx; |
10945 | ||
ad8d3bb3 | 10946 | s += strspn (s, " \t"); |
deec1734 | 10947 | is_mdmx = 0; |
252b5132 RH |
10948 | switch (*args) |
10949 | { | |
10950 | case '\0': /* end of args */ | |
10951 | if (*s == '\0') | |
10952 | return; | |
10953 | break; | |
10954 | ||
03f66e8a MR |
10955 | case '2': |
10956 | /* DSP 2-bit unsigned immediate in bit 11 (for standard MIPS | |
10957 | code) or 14 (for microMIPS code). */ | |
8b082fb1 TS |
10958 | my_getExpression (&imm_expr, s); |
10959 | check_absolute_expr (ip, &imm_expr); | |
10960 | if ((unsigned long) imm_expr.X_add_number != 1 | |
10961 | && (unsigned long) imm_expr.X_add_number != 3) | |
10962 | { | |
10963 | as_bad (_("BALIGN immediate not 1 or 3 (%lu)"), | |
10964 | (unsigned long) imm_expr.X_add_number); | |
10965 | } | |
03f66e8a MR |
10966 | INSERT_OPERAND (mips_opts.micromips, |
10967 | BP, *ip, imm_expr.X_add_number); | |
8b082fb1 TS |
10968 | imm_expr.X_op = O_absent; |
10969 | s = expr_end; | |
10970 | continue; | |
10971 | ||
03f66e8a MR |
10972 | case '3': |
10973 | /* DSP 3-bit unsigned immediate in bit 13 (for standard MIPS | |
10974 | code) or 21 (for microMIPS code). */ | |
10975 | { | |
10976 | unsigned long mask = (mips_opts.micromips | |
10977 | ? MICROMIPSOP_MASK_SA3 : OP_MASK_SA3); | |
10978 | ||
10979 | my_getExpression (&imm_expr, s); | |
10980 | check_absolute_expr (ip, &imm_expr); | |
10981 | if ((unsigned long) imm_expr.X_add_number > mask) | |
10982 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), | |
10983 | mask, (unsigned long) imm_expr.X_add_number); | |
10984 | INSERT_OPERAND (mips_opts.micromips, | |
10985 | SA3, *ip, imm_expr.X_add_number); | |
10986 | imm_expr.X_op = O_absent; | |
10987 | s = expr_end; | |
10988 | } | |
74cd071d CF |
10989 | continue; |
10990 | ||
03f66e8a MR |
10991 | case '4': |
10992 | /* DSP 4-bit unsigned immediate in bit 12 (for standard MIPS | |
10993 | code) or 21 (for microMIPS code). */ | |
10994 | { | |
10995 | unsigned long mask = (mips_opts.micromips | |
10996 | ? MICROMIPSOP_MASK_SA4 : OP_MASK_SA4); | |
10997 | ||
10998 | my_getExpression (&imm_expr, s); | |
10999 | check_absolute_expr (ip, &imm_expr); | |
11000 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11001 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), | |
11002 | mask, (unsigned long) imm_expr.X_add_number); | |
11003 | INSERT_OPERAND (mips_opts.micromips, | |
11004 | SA4, *ip, imm_expr.X_add_number); | |
11005 | imm_expr.X_op = O_absent; | |
11006 | s = expr_end; | |
11007 | } | |
74cd071d CF |
11008 | continue; |
11009 | ||
03f66e8a MR |
11010 | case '5': |
11011 | /* DSP 8-bit unsigned immediate in bit 13 (for standard MIPS | |
11012 | code) or 16 (for microMIPS code). */ | |
11013 | { | |
11014 | unsigned long mask = (mips_opts.micromips | |
11015 | ? MICROMIPSOP_MASK_IMM8 : OP_MASK_IMM8); | |
11016 | ||
11017 | my_getExpression (&imm_expr, s); | |
11018 | check_absolute_expr (ip, &imm_expr); | |
11019 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11020 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), | |
11021 | mask, (unsigned long) imm_expr.X_add_number); | |
11022 | INSERT_OPERAND (mips_opts.micromips, | |
11023 | IMM8, *ip, imm_expr.X_add_number); | |
11024 | imm_expr.X_op = O_absent; | |
11025 | s = expr_end; | |
11026 | } | |
74cd071d CF |
11027 | continue; |
11028 | ||
03f66e8a MR |
11029 | case '6': |
11030 | /* DSP 5-bit unsigned immediate in bit 16 (for standard MIPS | |
11031 | code) or 21 (for microMIPS code). */ | |
11032 | { | |
11033 | unsigned long mask = (mips_opts.micromips | |
11034 | ? MICROMIPSOP_MASK_RS : OP_MASK_RS); | |
11035 | ||
11036 | my_getExpression (&imm_expr, s); | |
11037 | check_absolute_expr (ip, &imm_expr); | |
11038 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11039 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), | |
11040 | mask, (unsigned long) imm_expr.X_add_number); | |
11041 | INSERT_OPERAND (mips_opts.micromips, | |
11042 | RS, *ip, imm_expr.X_add_number); | |
11043 | imm_expr.X_op = O_absent; | |
11044 | s = expr_end; | |
11045 | } | |
74cd071d CF |
11046 | continue; |
11047 | ||
90ecf173 | 11048 | case '7': /* Four DSP accumulators in bits 11,12. */ |
03f66e8a MR |
11049 | if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' |
11050 | && s[3] >= '0' && s[3] <= '3') | |
74cd071d CF |
11051 | { |
11052 | regno = s[3] - '0'; | |
11053 | s += 4; | |
03f66e8a | 11054 | INSERT_OPERAND (mips_opts.micromips, DSPACC, *ip, regno); |
74cd071d CF |
11055 | continue; |
11056 | } | |
11057 | else | |
11058 | as_bad (_("Invalid dsp acc register")); | |
11059 | break; | |
11060 | ||
03f66e8a MR |
11061 | case '8': |
11062 | /* DSP 6-bit unsigned immediate in bit 11 (for standard MIPS | |
11063 | code) or 14 (for microMIPS code). */ | |
11064 | { | |
11065 | unsigned long mask = (mips_opts.micromips | |
11066 | ? MICROMIPSOP_MASK_WRDSP | |
11067 | : OP_MASK_WRDSP); | |
11068 | ||
11069 | my_getExpression (&imm_expr, s); | |
11070 | check_absolute_expr (ip, &imm_expr); | |
11071 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11072 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), | |
11073 | mask, (unsigned long) imm_expr.X_add_number); | |
11074 | INSERT_OPERAND (mips_opts.micromips, | |
11075 | WRDSP, *ip, imm_expr.X_add_number); | |
11076 | imm_expr.X_op = O_absent; | |
11077 | s = expr_end; | |
11078 | } | |
74cd071d CF |
11079 | continue; |
11080 | ||
90ecf173 | 11081 | case '9': /* Four DSP accumulators in bits 21,22. */ |
df58fc94 | 11082 | gas_assert (!mips_opts.micromips); |
03f66e8a MR |
11083 | if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' |
11084 | && s[3] >= '0' && s[3] <= '3') | |
74cd071d CF |
11085 | { |
11086 | regno = s[3] - '0'; | |
11087 | s += 4; | |
df58fc94 | 11088 | INSERT_OPERAND (0, DSPACC_S, *ip, regno); |
74cd071d CF |
11089 | continue; |
11090 | } | |
11091 | else | |
11092 | as_bad (_("Invalid dsp acc register")); | |
11093 | break; | |
11094 | ||
03f66e8a MR |
11095 | case '0': |
11096 | /* DSP 6-bit signed immediate in bit 16 (for standard MIPS | |
11097 | code) or 20 (for microMIPS code). */ | |
11098 | { | |
11099 | long mask = (mips_opts.micromips | |
11100 | ? MICROMIPSOP_MASK_DSPSFT : OP_MASK_DSPSFT); | |
11101 | ||
11102 | my_getExpression (&imm_expr, s); | |
11103 | check_absolute_expr (ip, &imm_expr); | |
11104 | min_range = -((mask + 1) >> 1); | |
11105 | max_range = ((mask + 1) >> 1) - 1; | |
11106 | if (imm_expr.X_add_number < min_range | |
11107 | || imm_expr.X_add_number > max_range) | |
a9e24354 TS |
11108 | as_bad (_("DSP immediate not in range %ld..%ld (%ld)"), |
11109 | (long) min_range, (long) max_range, | |
11110 | (long) imm_expr.X_add_number); | |
03f66e8a MR |
11111 | INSERT_OPERAND (mips_opts.micromips, |
11112 | DSPSFT, *ip, imm_expr.X_add_number); | |
11113 | imm_expr.X_op = O_absent; | |
11114 | s = expr_end; | |
11115 | } | |
74cd071d CF |
11116 | continue; |
11117 | ||
90ecf173 | 11118 | case '\'': /* DSP 6-bit unsigned immediate in bit 16. */ |
df58fc94 | 11119 | gas_assert (!mips_opts.micromips); |
74cd071d CF |
11120 | my_getExpression (&imm_expr, s); |
11121 | check_absolute_expr (ip, &imm_expr); | |
11122 | if (imm_expr.X_add_number & ~OP_MASK_RDDSP) | |
11123 | { | |
a9e24354 TS |
11124 | as_bad (_("DSP immediate not in range 0..%d (%lu)"), |
11125 | OP_MASK_RDDSP, | |
11126 | (unsigned long) imm_expr.X_add_number); | |
74cd071d | 11127 | } |
df58fc94 | 11128 | INSERT_OPERAND (0, RDDSP, *ip, imm_expr.X_add_number); |
74cd071d CF |
11129 | imm_expr.X_op = O_absent; |
11130 | s = expr_end; | |
11131 | continue; | |
11132 | ||
90ecf173 | 11133 | case ':': /* DSP 7-bit signed immediate in bit 19. */ |
df58fc94 | 11134 | gas_assert (!mips_opts.micromips); |
74cd071d CF |
11135 | my_getExpression (&imm_expr, s); |
11136 | check_absolute_expr (ip, &imm_expr); | |
11137 | min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1); | |
11138 | max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1; | |
11139 | if (imm_expr.X_add_number < min_range || | |
11140 | imm_expr.X_add_number > max_range) | |
11141 | { | |
a9e24354 TS |
11142 | as_bad (_("DSP immediate not in range %ld..%ld (%ld)"), |
11143 | (long) min_range, (long) max_range, | |
11144 | (long) imm_expr.X_add_number); | |
74cd071d | 11145 | } |
df58fc94 | 11146 | INSERT_OPERAND (0, DSPSFT_7, *ip, imm_expr.X_add_number); |
74cd071d CF |
11147 | imm_expr.X_op = O_absent; |
11148 | s = expr_end; | |
11149 | continue; | |
11150 | ||
90ecf173 | 11151 | case '@': /* DSP 10-bit signed immediate in bit 16. */ |
03f66e8a MR |
11152 | { |
11153 | long mask = (mips_opts.micromips | |
11154 | ? MICROMIPSOP_MASK_IMM10 : OP_MASK_IMM10); | |
11155 | ||
11156 | my_getExpression (&imm_expr, s); | |
11157 | check_absolute_expr (ip, &imm_expr); | |
11158 | min_range = -((mask + 1) >> 1); | |
11159 | max_range = ((mask + 1) >> 1) - 1; | |
11160 | if (imm_expr.X_add_number < min_range | |
11161 | || imm_expr.X_add_number > max_range) | |
a9e24354 TS |
11162 | as_bad (_("DSP immediate not in range %ld..%ld (%ld)"), |
11163 | (long) min_range, (long) max_range, | |
11164 | (long) imm_expr.X_add_number); | |
03f66e8a MR |
11165 | INSERT_OPERAND (mips_opts.micromips, |
11166 | IMM10, *ip, imm_expr.X_add_number); | |
11167 | imm_expr.X_op = O_absent; | |
11168 | s = expr_end; | |
11169 | } | |
11170 | continue; | |
11171 | ||
11172 | case '^': /* DSP 5-bit unsigned immediate in bit 11. */ | |
11173 | gas_assert (mips_opts.micromips); | |
11174 | my_getExpression (&imm_expr, s); | |
11175 | check_absolute_expr (ip, &imm_expr); | |
11176 | if (imm_expr.X_add_number & ~MICROMIPSOP_MASK_RD) | |
11177 | as_bad (_("DSP immediate not in range 0..%d (%lu)"), | |
11178 | MICROMIPSOP_MASK_RD, | |
11179 | (unsigned long) imm_expr.X_add_number); | |
11180 | INSERT_OPERAND (1, RD, *ip, imm_expr.X_add_number); | |
74cd071d CF |
11181 | imm_expr.X_op = O_absent; |
11182 | s = expr_end; | |
11183 | continue; | |
11184 | ||
a9e24354 | 11185 | case '!': /* MT usermode flag bit. */ |
df58fc94 | 11186 | gas_assert (!mips_opts.micromips); |
ef2e4d86 CF |
11187 | my_getExpression (&imm_expr, s); |
11188 | check_absolute_expr (ip, &imm_expr); | |
11189 | if (imm_expr.X_add_number & ~OP_MASK_MT_U) | |
a9e24354 TS |
11190 | as_bad (_("MT usermode bit not 0 or 1 (%lu)"), |
11191 | (unsigned long) imm_expr.X_add_number); | |
df58fc94 | 11192 | INSERT_OPERAND (0, MT_U, *ip, imm_expr.X_add_number); |
ef2e4d86 CF |
11193 | imm_expr.X_op = O_absent; |
11194 | s = expr_end; | |
11195 | continue; | |
11196 | ||
a9e24354 | 11197 | case '$': /* MT load high flag bit. */ |
df58fc94 | 11198 | gas_assert (!mips_opts.micromips); |
ef2e4d86 CF |
11199 | my_getExpression (&imm_expr, s); |
11200 | check_absolute_expr (ip, &imm_expr); | |
11201 | if (imm_expr.X_add_number & ~OP_MASK_MT_H) | |
a9e24354 TS |
11202 | as_bad (_("MT load high bit not 0 or 1 (%lu)"), |
11203 | (unsigned long) imm_expr.X_add_number); | |
df58fc94 | 11204 | INSERT_OPERAND (0, MT_H, *ip, imm_expr.X_add_number); |
ef2e4d86 CF |
11205 | imm_expr.X_op = O_absent; |
11206 | s = expr_end; | |
11207 | continue; | |
11208 | ||
90ecf173 | 11209 | case '*': /* Four DSP accumulators in bits 18,19. */ |
df58fc94 | 11210 | gas_assert (!mips_opts.micromips); |
ef2e4d86 CF |
11211 | if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' && |
11212 | s[3] >= '0' && s[3] <= '3') | |
11213 | { | |
11214 | regno = s[3] - '0'; | |
11215 | s += 4; | |
df58fc94 | 11216 | INSERT_OPERAND (0, MTACC_T, *ip, regno); |
ef2e4d86 CF |
11217 | continue; |
11218 | } | |
11219 | else | |
11220 | as_bad (_("Invalid dsp/smartmips acc register")); | |
11221 | break; | |
11222 | ||
90ecf173 | 11223 | case '&': /* Four DSP accumulators in bits 13,14. */ |
df58fc94 | 11224 | gas_assert (!mips_opts.micromips); |
ef2e4d86 CF |
11225 | if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' && |
11226 | s[3] >= '0' && s[3] <= '3') | |
11227 | { | |
11228 | regno = s[3] - '0'; | |
11229 | s += 4; | |
df58fc94 | 11230 | INSERT_OPERAND (0, MTACC_D, *ip, regno); |
ef2e4d86 CF |
11231 | continue; |
11232 | } | |
11233 | else | |
11234 | as_bad (_("Invalid dsp/smartmips acc register")); | |
11235 | break; | |
11236 | ||
dec0624d MR |
11237 | case '\\': /* 3-bit bit position. */ |
11238 | { | |
2906b037 MR |
11239 | unsigned long mask = (mips_opts.micromips |
11240 | ? MICROMIPSOP_MASK_3BITPOS | |
11241 | : OP_MASK_3BITPOS); | |
dec0624d MR |
11242 | |
11243 | my_getExpression (&imm_expr, s); | |
11244 | check_absolute_expr (ip, &imm_expr); | |
11245 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11246 | as_warn (_("Bit position for %s not in range 0..%lu (%lu)"), | |
11247 | ip->insn_mo->name, | |
11248 | mask, (unsigned long) imm_expr.X_add_number); | |
11249 | INSERT_OPERAND (mips_opts.micromips, | |
11250 | 3BITPOS, *ip, imm_expr.X_add_number); | |
11251 | imm_expr.X_op = O_absent; | |
11252 | s = expr_end; | |
11253 | } | |
11254 | continue; | |
11255 | ||
252b5132 | 11256 | case ',': |
a339155f | 11257 | ++argnum; |
252b5132 RH |
11258 | if (*s++ == *args) |
11259 | continue; | |
11260 | s--; | |
11261 | switch (*++args) | |
11262 | { | |
11263 | case 'r': | |
11264 | case 'v': | |
df58fc94 | 11265 | INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno); |
252b5132 RH |
11266 | continue; |
11267 | ||
11268 | case 'w': | |
df58fc94 | 11269 | INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno); |
38487616 TS |
11270 | continue; |
11271 | ||
252b5132 | 11272 | case 'W': |
df58fc94 RS |
11273 | gas_assert (!mips_opts.micromips); |
11274 | INSERT_OPERAND (0, FT, *ip, lastregno); | |
252b5132 RH |
11275 | continue; |
11276 | ||
11277 | case 'V': | |
df58fc94 | 11278 | INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno); |
252b5132 RH |
11279 | continue; |
11280 | } | |
11281 | break; | |
11282 | ||
11283 | case '(': | |
11284 | /* Handle optional base register. | |
11285 | Either the base register is omitted or | |
bdaaa2e1 | 11286 | we must have a left paren. */ |
252b5132 RH |
11287 | /* This is dependent on the next operand specifier |
11288 | is a base register specification. */ | |
df58fc94 RS |
11289 | gas_assert (args[1] == 'b' |
11290 | || (mips_opts.micromips | |
11291 | && args[1] == 'm' | |
11292 | && (args[2] == 'l' || args[2] == 'n' | |
11293 | || args[2] == 's' || args[2] == 'a'))); | |
11294 | if (*s == '\0' && args[1] == 'b') | |
252b5132 | 11295 | return; |
df58fc94 | 11296 | /* Fall through. */ |
252b5132 | 11297 | |
90ecf173 | 11298 | case ')': /* These must match exactly. */ |
df58fc94 RS |
11299 | if (*s++ == *args) |
11300 | continue; | |
11301 | break; | |
11302 | ||
11303 | case '[': /* These must match exactly. */ | |
60b63b72 | 11304 | case ']': |
df58fc94 | 11305 | gas_assert (!mips_opts.micromips); |
252b5132 RH |
11306 | if (*s++ == *args) |
11307 | continue; | |
11308 | break; | |
11309 | ||
af7ee8bf CD |
11310 | case '+': /* Opcode extension character. */ |
11311 | switch (*++args) | |
11312 | { | |
9bcd4f99 TS |
11313 | case '1': /* UDI immediates. */ |
11314 | case '2': | |
11315 | case '3': | |
11316 | case '4': | |
df58fc94 | 11317 | gas_assert (!mips_opts.micromips); |
9bcd4f99 TS |
11318 | { |
11319 | const struct mips_immed *imm = mips_immed; | |
11320 | ||
11321 | while (imm->type && imm->type != *args) | |
11322 | ++imm; | |
11323 | if (! imm->type) | |
b37df7c4 | 11324 | abort (); |
9bcd4f99 TS |
11325 | my_getExpression (&imm_expr, s); |
11326 | check_absolute_expr (ip, &imm_expr); | |
11327 | if ((unsigned long) imm_expr.X_add_number & ~imm->mask) | |
11328 | { | |
11329 | as_warn (_("Illegal %s number (%lu, 0x%lx)"), | |
11330 | imm->desc ? imm->desc : ip->insn_mo->name, | |
11331 | (unsigned long) imm_expr.X_add_number, | |
11332 | (unsigned long) imm_expr.X_add_number); | |
90ecf173 | 11333 | imm_expr.X_add_number &= imm->mask; |
9bcd4f99 TS |
11334 | } |
11335 | ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number | |
11336 | << imm->shift); | |
11337 | imm_expr.X_op = O_absent; | |
11338 | s = expr_end; | |
11339 | } | |
11340 | continue; | |
90ecf173 | 11341 | |
071742cf CD |
11342 | case 'A': /* ins/ext position, becomes LSB. */ |
11343 | limlo = 0; | |
11344 | limhi = 31; | |
5f74bc13 CD |
11345 | goto do_lsb; |
11346 | case 'E': | |
11347 | limlo = 32; | |
11348 | limhi = 63; | |
11349 | goto do_lsb; | |
90ecf173 | 11350 | do_lsb: |
071742cf CD |
11351 | my_getExpression (&imm_expr, s); |
11352 | check_absolute_expr (ip, &imm_expr); | |
11353 | if ((unsigned long) imm_expr.X_add_number < limlo | |
11354 | || (unsigned long) imm_expr.X_add_number > limhi) | |
11355 | { | |
11356 | as_bad (_("Improper position (%lu)"), | |
11357 | (unsigned long) imm_expr.X_add_number); | |
11358 | imm_expr.X_add_number = limlo; | |
11359 | } | |
11360 | lastpos = imm_expr.X_add_number; | |
df58fc94 RS |
11361 | INSERT_OPERAND (mips_opts.micromips, |
11362 | EXTLSB, *ip, imm_expr.X_add_number); | |
071742cf CD |
11363 | imm_expr.X_op = O_absent; |
11364 | s = expr_end; | |
11365 | continue; | |
11366 | ||
11367 | case 'B': /* ins size, becomes MSB. */ | |
11368 | limlo = 1; | |
11369 | limhi = 32; | |
5f74bc13 CD |
11370 | goto do_msb; |
11371 | case 'F': | |
11372 | limlo = 33; | |
11373 | limhi = 64; | |
11374 | goto do_msb; | |
90ecf173 | 11375 | do_msb: |
071742cf CD |
11376 | my_getExpression (&imm_expr, s); |
11377 | check_absolute_expr (ip, &imm_expr); | |
11378 | /* Check for negative input so that small negative numbers | |
11379 | will not succeed incorrectly. The checks against | |
11380 | (pos+size) transitively check "size" itself, | |
11381 | assuming that "pos" is reasonable. */ | |
11382 | if ((long) imm_expr.X_add_number < 0 | |
11383 | || ((unsigned long) imm_expr.X_add_number | |
11384 | + lastpos) < limlo | |
11385 | || ((unsigned long) imm_expr.X_add_number | |
11386 | + lastpos) > limhi) | |
11387 | { | |
11388 | as_bad (_("Improper insert size (%lu, position %lu)"), | |
11389 | (unsigned long) imm_expr.X_add_number, | |
11390 | (unsigned long) lastpos); | |
11391 | imm_expr.X_add_number = limlo - lastpos; | |
11392 | } | |
df58fc94 RS |
11393 | INSERT_OPERAND (mips_opts.micromips, INSMSB, *ip, |
11394 | lastpos + imm_expr.X_add_number - 1); | |
071742cf CD |
11395 | imm_expr.X_op = O_absent; |
11396 | s = expr_end; | |
11397 | continue; | |
11398 | ||
11399 | case 'C': /* ext size, becomes MSBD. */ | |
11400 | limlo = 1; | |
11401 | limhi = 32; | |
f02d8318 | 11402 | sizelo = 1; |
5f74bc13 CD |
11403 | goto do_msbd; |
11404 | case 'G': | |
11405 | limlo = 33; | |
11406 | limhi = 64; | |
f02d8318 | 11407 | sizelo = 33; |
5f74bc13 CD |
11408 | goto do_msbd; |
11409 | case 'H': | |
11410 | limlo = 33; | |
11411 | limhi = 64; | |
f02d8318 | 11412 | sizelo = 1; |
5f74bc13 | 11413 | goto do_msbd; |
90ecf173 | 11414 | do_msbd: |
071742cf CD |
11415 | my_getExpression (&imm_expr, s); |
11416 | check_absolute_expr (ip, &imm_expr); | |
f02d8318 CF |
11417 | /* The checks against (pos+size) don't transitively check |
11418 | "size" itself, assuming that "pos" is reasonable. | |
11419 | We also need to check the lower bound of "size". */ | |
11420 | if ((long) imm_expr.X_add_number < sizelo | |
071742cf CD |
11421 | || ((unsigned long) imm_expr.X_add_number |
11422 | + lastpos) < limlo | |
11423 | || ((unsigned long) imm_expr.X_add_number | |
11424 | + lastpos) > limhi) | |
11425 | { | |
11426 | as_bad (_("Improper extract size (%lu, position %lu)"), | |
11427 | (unsigned long) imm_expr.X_add_number, | |
11428 | (unsigned long) lastpos); | |
11429 | imm_expr.X_add_number = limlo - lastpos; | |
11430 | } | |
df58fc94 RS |
11431 | INSERT_OPERAND (mips_opts.micromips, |
11432 | EXTMSBD, *ip, imm_expr.X_add_number - 1); | |
071742cf CD |
11433 | imm_expr.X_op = O_absent; |
11434 | s = expr_end; | |
11435 | continue; | |
af7ee8bf | 11436 | |
bbcc0807 CD |
11437 | case 'D': |
11438 | /* +D is for disassembly only; never match. */ | |
11439 | break; | |
11440 | ||
5f74bc13 CD |
11441 | case 'I': |
11442 | /* "+I" is like "I", except that imm2_expr is used. */ | |
11443 | my_getExpression (&imm2_expr, s); | |
11444 | if (imm2_expr.X_op != O_big | |
11445 | && imm2_expr.X_op != O_constant) | |
11446 | insn_error = _("absolute expression required"); | |
9ee2a2d4 MR |
11447 | if (HAVE_32BIT_GPRS) |
11448 | normalize_constant_expr (&imm2_expr); | |
5f74bc13 CD |
11449 | s = expr_end; |
11450 | continue; | |
11451 | ||
707bfff6 | 11452 | case 'T': /* Coprocessor register. */ |
df58fc94 | 11453 | gas_assert (!mips_opts.micromips); |
ef2e4d86 CF |
11454 | /* +T is for disassembly only; never match. */ |
11455 | break; | |
11456 | ||
707bfff6 | 11457 | case 't': /* Coprocessor register number. */ |
df58fc94 | 11458 | gas_assert (!mips_opts.micromips); |
ef2e4d86 CF |
11459 | if (s[0] == '$' && ISDIGIT (s[1])) |
11460 | { | |
11461 | ++s; | |
11462 | regno = 0; | |
11463 | do | |
11464 | { | |
11465 | regno *= 10; | |
11466 | regno += *s - '0'; | |
11467 | ++s; | |
11468 | } | |
11469 | while (ISDIGIT (*s)); | |
11470 | if (regno > 31) | |
11471 | as_bad (_("Invalid register number (%d)"), regno); | |
11472 | else | |
11473 | { | |
df58fc94 | 11474 | INSERT_OPERAND (0, RT, *ip, regno); |
ef2e4d86 CF |
11475 | continue; |
11476 | } | |
11477 | } | |
11478 | else | |
11479 | as_bad (_("Invalid coprocessor 0 register number")); | |
11480 | break; | |
11481 | ||
bb35fb24 NC |
11482 | case 'x': |
11483 | /* bbit[01] and bbit[01]32 bit index. Give error if index | |
11484 | is not in the valid range. */ | |
df58fc94 | 11485 | gas_assert (!mips_opts.micromips); |
bb35fb24 NC |
11486 | my_getExpression (&imm_expr, s); |
11487 | check_absolute_expr (ip, &imm_expr); | |
11488 | if ((unsigned) imm_expr.X_add_number > 31) | |
11489 | { | |
11490 | as_bad (_("Improper bit index (%lu)"), | |
11491 | (unsigned long) imm_expr.X_add_number); | |
11492 | imm_expr.X_add_number = 0; | |
11493 | } | |
df58fc94 | 11494 | INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number); |
bb35fb24 NC |
11495 | imm_expr.X_op = O_absent; |
11496 | s = expr_end; | |
11497 | continue; | |
11498 | ||
11499 | case 'X': | |
11500 | /* bbit[01] bit index when bbit is used but we generate | |
11501 | bbit[01]32 because the index is over 32. Move to the | |
11502 | next candidate if index is not in the valid range. */ | |
df58fc94 | 11503 | gas_assert (!mips_opts.micromips); |
bb35fb24 NC |
11504 | my_getExpression (&imm_expr, s); |
11505 | check_absolute_expr (ip, &imm_expr); | |
11506 | if ((unsigned) imm_expr.X_add_number < 32 | |
11507 | || (unsigned) imm_expr.X_add_number > 63) | |
11508 | break; | |
df58fc94 | 11509 | INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number - 32); |
bb35fb24 NC |
11510 | imm_expr.X_op = O_absent; |
11511 | s = expr_end; | |
11512 | continue; | |
11513 | ||
11514 | case 'p': | |
11515 | /* cins, cins32, exts and exts32 position field. Give error | |
11516 | if it's not in the valid range. */ | |
df58fc94 | 11517 | gas_assert (!mips_opts.micromips); |
bb35fb24 NC |
11518 | my_getExpression (&imm_expr, s); |
11519 | check_absolute_expr (ip, &imm_expr); | |
11520 | if ((unsigned) imm_expr.X_add_number > 31) | |
11521 | { | |
11522 | as_bad (_("Improper position (%lu)"), | |
11523 | (unsigned long) imm_expr.X_add_number); | |
11524 | imm_expr.X_add_number = 0; | |
11525 | } | |
11526 | /* Make the pos explicit to simplify +S. */ | |
11527 | lastpos = imm_expr.X_add_number + 32; | |
df58fc94 | 11528 | INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number); |
bb35fb24 NC |
11529 | imm_expr.X_op = O_absent; |
11530 | s = expr_end; | |
11531 | continue; | |
11532 | ||
11533 | case 'P': | |
11534 | /* cins, cins32, exts and exts32 position field. Move to | |
11535 | the next candidate if it's not in the valid range. */ | |
df58fc94 | 11536 | gas_assert (!mips_opts.micromips); |
bb35fb24 NC |
11537 | my_getExpression (&imm_expr, s); |
11538 | check_absolute_expr (ip, &imm_expr); | |
11539 | if ((unsigned) imm_expr.X_add_number < 32 | |
11540 | || (unsigned) imm_expr.X_add_number > 63) | |
11541 | break; | |
11542 | lastpos = imm_expr.X_add_number; | |
df58fc94 | 11543 | INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number - 32); |
bb35fb24 NC |
11544 | imm_expr.X_op = O_absent; |
11545 | s = expr_end; | |
11546 | continue; | |
11547 | ||
11548 | case 's': | |
11549 | /* cins and exts length-minus-one field. */ | |
df58fc94 | 11550 | gas_assert (!mips_opts.micromips); |
bb35fb24 NC |
11551 | my_getExpression (&imm_expr, s); |
11552 | check_absolute_expr (ip, &imm_expr); | |
11553 | if ((unsigned long) imm_expr.X_add_number > 31) | |
11554 | { | |
11555 | as_bad (_("Improper size (%lu)"), | |
11556 | (unsigned long) imm_expr.X_add_number); | |
11557 | imm_expr.X_add_number = 0; | |
11558 | } | |
df58fc94 | 11559 | INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number); |
bb35fb24 NC |
11560 | imm_expr.X_op = O_absent; |
11561 | s = expr_end; | |
11562 | continue; | |
11563 | ||
11564 | case 'S': | |
11565 | /* cins32/exts32 and cins/exts aliasing cint32/exts32 | |
11566 | length-minus-one field. */ | |
df58fc94 | 11567 | gas_assert (!mips_opts.micromips); |
bb35fb24 NC |
11568 | my_getExpression (&imm_expr, s); |
11569 | check_absolute_expr (ip, &imm_expr); | |
11570 | if ((long) imm_expr.X_add_number < 0 | |
11571 | || (unsigned long) imm_expr.X_add_number + lastpos > 63) | |
11572 | { | |
11573 | as_bad (_("Improper size (%lu)"), | |
11574 | (unsigned long) imm_expr.X_add_number); | |
11575 | imm_expr.X_add_number = 0; | |
11576 | } | |
df58fc94 | 11577 | INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number); |
bb35fb24 NC |
11578 | imm_expr.X_op = O_absent; |
11579 | s = expr_end; | |
11580 | continue; | |
11581 | ||
dd3cbb7e NC |
11582 | case 'Q': |
11583 | /* seqi/snei immediate field. */ | |
df58fc94 | 11584 | gas_assert (!mips_opts.micromips); |
dd3cbb7e NC |
11585 | my_getExpression (&imm_expr, s); |
11586 | check_absolute_expr (ip, &imm_expr); | |
11587 | if ((long) imm_expr.X_add_number < -512 | |
11588 | || (long) imm_expr.X_add_number >= 512) | |
11589 | { | |
11590 | as_bad (_("Improper immediate (%ld)"), | |
11591 | (long) imm_expr.X_add_number); | |
11592 | imm_expr.X_add_number = 0; | |
11593 | } | |
df58fc94 | 11594 | INSERT_OPERAND (0, SEQI, *ip, imm_expr.X_add_number); |
dd3cbb7e NC |
11595 | imm_expr.X_op = O_absent; |
11596 | s = expr_end; | |
11597 | continue; | |
11598 | ||
98675402 | 11599 | case 'a': /* 8-bit signed offset in bit 6 */ |
df58fc94 | 11600 | gas_assert (!mips_opts.micromips); |
98675402 RS |
11601 | my_getExpression (&imm_expr, s); |
11602 | check_absolute_expr (ip, &imm_expr); | |
11603 | min_range = -((OP_MASK_OFFSET_A + 1) >> 1); | |
11604 | max_range = ((OP_MASK_OFFSET_A + 1) >> 1) - 1; | |
11605 | if (imm_expr.X_add_number < min_range | |
11606 | || imm_expr.X_add_number > max_range) | |
11607 | { | |
c95354ed | 11608 | as_bad (_("Offset not in range %ld..%ld (%ld)"), |
98675402 RS |
11609 | (long) min_range, (long) max_range, |
11610 | (long) imm_expr.X_add_number); | |
11611 | } | |
df58fc94 | 11612 | INSERT_OPERAND (0, OFFSET_A, *ip, imm_expr.X_add_number); |
98675402 RS |
11613 | imm_expr.X_op = O_absent; |
11614 | s = expr_end; | |
11615 | continue; | |
11616 | ||
11617 | case 'b': /* 8-bit signed offset in bit 3 */ | |
df58fc94 | 11618 | gas_assert (!mips_opts.micromips); |
98675402 RS |
11619 | my_getExpression (&imm_expr, s); |
11620 | check_absolute_expr (ip, &imm_expr); | |
11621 | min_range = -((OP_MASK_OFFSET_B + 1) >> 1); | |
11622 | max_range = ((OP_MASK_OFFSET_B + 1) >> 1) - 1; | |
11623 | if (imm_expr.X_add_number < min_range | |
11624 | || imm_expr.X_add_number > max_range) | |
11625 | { | |
c95354ed | 11626 | as_bad (_("Offset not in range %ld..%ld (%ld)"), |
98675402 RS |
11627 | (long) min_range, (long) max_range, |
11628 | (long) imm_expr.X_add_number); | |
11629 | } | |
df58fc94 | 11630 | INSERT_OPERAND (0, OFFSET_B, *ip, imm_expr.X_add_number); |
98675402 RS |
11631 | imm_expr.X_op = O_absent; |
11632 | s = expr_end; | |
11633 | continue; | |
11634 | ||
11635 | case 'c': /* 9-bit signed offset in bit 6 */ | |
df58fc94 | 11636 | gas_assert (!mips_opts.micromips); |
98675402 RS |
11637 | my_getExpression (&imm_expr, s); |
11638 | check_absolute_expr (ip, &imm_expr); | |
11639 | min_range = -((OP_MASK_OFFSET_C + 1) >> 1); | |
11640 | max_range = ((OP_MASK_OFFSET_C + 1) >> 1) - 1; | |
c95354ed MX |
11641 | /* We check the offset range before adjusted. */ |
11642 | min_range <<= 4; | |
11643 | max_range <<= 4; | |
98675402 RS |
11644 | if (imm_expr.X_add_number < min_range |
11645 | || imm_expr.X_add_number > max_range) | |
11646 | { | |
c95354ed | 11647 | as_bad (_("Offset not in range %ld..%ld (%ld)"), |
98675402 RS |
11648 | (long) min_range, (long) max_range, |
11649 | (long) imm_expr.X_add_number); | |
11650 | } | |
c95354ed MX |
11651 | if (imm_expr.X_add_number & 0xf) |
11652 | { | |
11653 | as_bad (_("Offset not 16 bytes alignment (%ld)"), | |
11654 | (long) imm_expr.X_add_number); | |
11655 | } | |
11656 | /* Right shift 4 bits to adjust the offset operand. */ | |
df58fc94 RS |
11657 | INSERT_OPERAND (0, OFFSET_C, *ip, |
11658 | imm_expr.X_add_number >> 4); | |
98675402 RS |
11659 | imm_expr.X_op = O_absent; |
11660 | s = expr_end; | |
11661 | continue; | |
11662 | ||
11663 | case 'z': | |
df58fc94 | 11664 | gas_assert (!mips_opts.micromips); |
98675402 RS |
11665 | if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no)) |
11666 | break; | |
11667 | if (regno == AT && mips_opts.at) | |
11668 | { | |
11669 | if (mips_opts.at == ATREG) | |
11670 | as_warn (_("used $at without \".set noat\"")); | |
11671 | else | |
11672 | as_warn (_("used $%u with \".set at=$%u\""), | |
11673 | regno, mips_opts.at); | |
11674 | } | |
df58fc94 | 11675 | INSERT_OPERAND (0, RZ, *ip, regno); |
98675402 RS |
11676 | continue; |
11677 | ||
11678 | case 'Z': | |
df58fc94 | 11679 | gas_assert (!mips_opts.micromips); |
98675402 RS |
11680 | if (!reg_lookup (&s, RTYPE_FPU, ®no)) |
11681 | break; | |
df58fc94 | 11682 | INSERT_OPERAND (0, FZ, *ip, regno); |
98675402 RS |
11683 | continue; |
11684 | ||
af7ee8bf | 11685 | default: |
df58fc94 | 11686 | as_bad (_("Internal error: bad %s opcode " |
90ecf173 | 11687 | "(unknown extension operand type `+%c'): %s %s"), |
df58fc94 | 11688 | mips_opts.micromips ? "microMIPS" : "MIPS", |
90ecf173 | 11689 | *args, insn->name, insn->args); |
af7ee8bf CD |
11690 | /* Further processing is fruitless. */ |
11691 | return; | |
11692 | } | |
11693 | break; | |
11694 | ||
df58fc94 | 11695 | case '.': /* 10-bit offset. */ |
df58fc94 | 11696 | gas_assert (mips_opts.micromips); |
dec0624d | 11697 | case '~': /* 12-bit offset. */ |
df58fc94 RS |
11698 | { |
11699 | int shift = *args == '.' ? 9 : 11; | |
11700 | size_t i; | |
11701 | ||
11702 | /* Check whether there is only a single bracketed expression | |
11703 | left. If so, it must be the base register and the | |
11704 | constant must be zero. */ | |
11705 | if (*s == '(' && strchr (s + 1, '(') == 0) | |
11706 | continue; | |
11707 | ||
11708 | /* If this value won't fit into the offset, then go find | |
11709 | a macro that will generate a 16- or 32-bit offset code | |
11710 | pattern. */ | |
11711 | i = my_getSmallExpression (&imm_expr, imm_reloc, s); | |
11712 | if ((i == 0 && (imm_expr.X_op != O_constant | |
11713 | || imm_expr.X_add_number >= 1 << shift | |
11714 | || imm_expr.X_add_number < -1 << shift)) | |
11715 | || i > 0) | |
11716 | { | |
11717 | imm_expr.X_op = O_absent; | |
11718 | break; | |
11719 | } | |
11720 | if (shift == 9) | |
11721 | INSERT_OPERAND (1, OFFSET10, *ip, imm_expr.X_add_number); | |
11722 | else | |
dec0624d MR |
11723 | INSERT_OPERAND (mips_opts.micromips, |
11724 | OFFSET12, *ip, imm_expr.X_add_number); | |
df58fc94 RS |
11725 | imm_expr.X_op = O_absent; |
11726 | s = expr_end; | |
11727 | } | |
11728 | continue; | |
11729 | ||
252b5132 RH |
11730 | case '<': /* must be at least one digit */ |
11731 | /* | |
11732 | * According to the manual, if the shift amount is greater | |
b6ff326e KH |
11733 | * than 31 or less than 0, then the shift amount should be |
11734 | * mod 32. In reality the mips assembler issues an error. | |
252b5132 RH |
11735 | * We issue a warning and mask out all but the low 5 bits. |
11736 | */ | |
11737 | my_getExpression (&imm_expr, s); | |
11738 | check_absolute_expr (ip, &imm_expr); | |
11739 | if ((unsigned long) imm_expr.X_add_number > 31) | |
bf12938e RS |
11740 | as_warn (_("Improper shift amount (%lu)"), |
11741 | (unsigned long) imm_expr.X_add_number); | |
df58fc94 RS |
11742 | INSERT_OPERAND (mips_opts.micromips, |
11743 | SHAMT, *ip, imm_expr.X_add_number); | |
252b5132 RH |
11744 | imm_expr.X_op = O_absent; |
11745 | s = expr_end; | |
11746 | continue; | |
11747 | ||
11748 | case '>': /* shift amount minus 32 */ | |
11749 | my_getExpression (&imm_expr, s); | |
11750 | check_absolute_expr (ip, &imm_expr); | |
11751 | if ((unsigned long) imm_expr.X_add_number < 32 | |
11752 | || (unsigned long) imm_expr.X_add_number > 63) | |
11753 | break; | |
df58fc94 RS |
11754 | INSERT_OPERAND (mips_opts.micromips, |
11755 | SHAMT, *ip, imm_expr.X_add_number - 32); | |
252b5132 RH |
11756 | imm_expr.X_op = O_absent; |
11757 | s = expr_end; | |
11758 | continue; | |
11759 | ||
90ecf173 MR |
11760 | case 'k': /* CACHE code. */ |
11761 | case 'h': /* PREFX code. */ | |
11762 | case '1': /* SYNC type. */ | |
252b5132 RH |
11763 | my_getExpression (&imm_expr, s); |
11764 | check_absolute_expr (ip, &imm_expr); | |
11765 | if ((unsigned long) imm_expr.X_add_number > 31) | |
bf12938e RS |
11766 | as_warn (_("Invalid value for `%s' (%lu)"), |
11767 | ip->insn_mo->name, | |
11768 | (unsigned long) imm_expr.X_add_number); | |
df58fc94 | 11769 | switch (*args) |
d954098f | 11770 | { |
df58fc94 RS |
11771 | case 'k': |
11772 | if (mips_fix_cn63xxp1 | |
11773 | && !mips_opts.micromips | |
11774 | && strcmp ("pref", insn->name) == 0) | |
d954098f DD |
11775 | switch (imm_expr.X_add_number) |
11776 | { | |
11777 | case 5: | |
11778 | case 25: | |
11779 | case 26: | |
11780 | case 27: | |
11781 | case 28: | |
11782 | case 29: | |
11783 | case 30: | |
11784 | case 31: /* These are ok. */ | |
11785 | break; | |
11786 | ||
11787 | default: /* The rest must be changed to 28. */ | |
11788 | imm_expr.X_add_number = 28; | |
11789 | break; | |
11790 | } | |
df58fc94 RS |
11791 | INSERT_OPERAND (mips_opts.micromips, |
11792 | CACHE, *ip, imm_expr.X_add_number); | |
11793 | break; | |
11794 | case 'h': | |
11795 | INSERT_OPERAND (mips_opts.micromips, | |
11796 | PREFX, *ip, imm_expr.X_add_number); | |
11797 | break; | |
11798 | case '1': | |
11799 | INSERT_OPERAND (mips_opts.micromips, | |
11800 | STYPE, *ip, imm_expr.X_add_number); | |
11801 | break; | |
d954098f | 11802 | } |
252b5132 RH |
11803 | imm_expr.X_op = O_absent; |
11804 | s = expr_end; | |
11805 | continue; | |
11806 | ||
90ecf173 | 11807 | case 'c': /* BREAK code. */ |
df58fc94 RS |
11808 | { |
11809 | unsigned long mask = (mips_opts.micromips | |
11810 | ? MICROMIPSOP_MASK_CODE | |
11811 | : OP_MASK_CODE); | |
11812 | ||
11813 | my_getExpression (&imm_expr, s); | |
11814 | check_absolute_expr (ip, &imm_expr); | |
11815 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11816 | as_warn (_("Code for %s not in range 0..%lu (%lu)"), | |
11817 | ip->insn_mo->name, | |
11818 | mask, (unsigned long) imm_expr.X_add_number); | |
11819 | INSERT_OPERAND (mips_opts.micromips, | |
11820 | CODE, *ip, imm_expr.X_add_number); | |
11821 | imm_expr.X_op = O_absent; | |
11822 | s = expr_end; | |
11823 | } | |
252b5132 RH |
11824 | continue; |
11825 | ||
90ecf173 | 11826 | case 'q': /* Lower BREAK code. */ |
df58fc94 RS |
11827 | { |
11828 | unsigned long mask = (mips_opts.micromips | |
11829 | ? MICROMIPSOP_MASK_CODE2 | |
11830 | : OP_MASK_CODE2); | |
11831 | ||
11832 | my_getExpression (&imm_expr, s); | |
11833 | check_absolute_expr (ip, &imm_expr); | |
11834 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11835 | as_warn (_("Lower code for %s not in range 0..%lu (%lu)"), | |
11836 | ip->insn_mo->name, | |
11837 | mask, (unsigned long) imm_expr.X_add_number); | |
11838 | INSERT_OPERAND (mips_opts.micromips, | |
11839 | CODE2, *ip, imm_expr.X_add_number); | |
11840 | imm_expr.X_op = O_absent; | |
11841 | s = expr_end; | |
11842 | } | |
252b5132 RH |
11843 | continue; |
11844 | ||
df58fc94 RS |
11845 | case 'B': /* 20- or 10-bit syscall/break/wait code. */ |
11846 | { | |
11847 | unsigned long mask = (mips_opts.micromips | |
11848 | ? MICROMIPSOP_MASK_CODE10 | |
11849 | : OP_MASK_CODE20); | |
11850 | ||
11851 | my_getExpression (&imm_expr, s); | |
11852 | check_absolute_expr (ip, &imm_expr); | |
11853 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11854 | as_warn (_("Code for %s not in range 0..%lu (%lu)"), | |
11855 | ip->insn_mo->name, | |
11856 | mask, (unsigned long) imm_expr.X_add_number); | |
11857 | if (mips_opts.micromips) | |
11858 | INSERT_OPERAND (1, CODE10, *ip, imm_expr.X_add_number); | |
11859 | else | |
11860 | INSERT_OPERAND (0, CODE20, *ip, imm_expr.X_add_number); | |
11861 | imm_expr.X_op = O_absent; | |
11862 | s = expr_end; | |
11863 | } | |
252b5132 RH |
11864 | continue; |
11865 | ||
df58fc94 RS |
11866 | case 'C': /* 25- or 23-bit coprocessor code. */ |
11867 | { | |
11868 | unsigned long mask = (mips_opts.micromips | |
11869 | ? MICROMIPSOP_MASK_COPZ | |
11870 | : OP_MASK_COPZ); | |
11871 | ||
11872 | my_getExpression (&imm_expr, s); | |
11873 | check_absolute_expr (ip, &imm_expr); | |
11874 | if ((unsigned long) imm_expr.X_add_number > mask) | |
11875 | as_warn (_("Coproccesor code > %u bits (%lu)"), | |
11876 | mips_opts.micromips ? 23U : 25U, | |
793b27f4 | 11877 | (unsigned long) imm_expr.X_add_number); |
df58fc94 RS |
11878 | INSERT_OPERAND (mips_opts.micromips, |
11879 | COPZ, *ip, imm_expr.X_add_number); | |
11880 | imm_expr.X_op = O_absent; | |
11881 | s = expr_end; | |
11882 | } | |
beae10d5 | 11883 | continue; |
252b5132 | 11884 | |
df58fc94 RS |
11885 | case 'J': /* 19-bit WAIT code. */ |
11886 | gas_assert (!mips_opts.micromips); | |
4372b673 NC |
11887 | my_getExpression (&imm_expr, s); |
11888 | check_absolute_expr (ip, &imm_expr); | |
793b27f4 | 11889 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19) |
df58fc94 RS |
11890 | { |
11891 | as_warn (_("Illegal 19-bit code (%lu)"), | |
a9e24354 | 11892 | (unsigned long) imm_expr.X_add_number); |
df58fc94 RS |
11893 | imm_expr.X_add_number &= OP_MASK_CODE19; |
11894 | } | |
11895 | INSERT_OPERAND (0, CODE19, *ip, imm_expr.X_add_number); | |
4372b673 NC |
11896 | imm_expr.X_op = O_absent; |
11897 | s = expr_end; | |
11898 | continue; | |
11899 | ||
707bfff6 | 11900 | case 'P': /* Performance register. */ |
df58fc94 | 11901 | gas_assert (!mips_opts.micromips); |
beae10d5 | 11902 | my_getExpression (&imm_expr, s); |
252b5132 | 11903 | check_absolute_expr (ip, &imm_expr); |
beae10d5 | 11904 | if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1) |
bf12938e RS |
11905 | as_warn (_("Invalid performance register (%lu)"), |
11906 | (unsigned long) imm_expr.X_add_number); | |
e407c74b NC |
11907 | if (imm_expr.X_add_number != 0 && mips_opts.arch == CPU_R5900 |
11908 | && (!strcmp(insn->name,"mfps") || !strcmp(insn->name,"mtps"))) | |
11909 | as_warn (_("Invalid performance register (%lu)"), | |
11910 | (unsigned long) imm_expr.X_add_number); | |
df58fc94 | 11911 | INSERT_OPERAND (0, PERFREG, *ip, imm_expr.X_add_number); |
beae10d5 KH |
11912 | imm_expr.X_op = O_absent; |
11913 | s = expr_end; | |
11914 | continue; | |
252b5132 | 11915 | |
707bfff6 | 11916 | case 'G': /* Coprocessor destination register. */ |
df58fc94 RS |
11917 | { |
11918 | unsigned long opcode = ip->insn_opcode; | |
11919 | unsigned long mask; | |
11920 | unsigned int types; | |
11921 | int cop0; | |
11922 | ||
11923 | if (mips_opts.micromips) | |
11924 | { | |
11925 | mask = ~((MICROMIPSOP_MASK_RT << MICROMIPSOP_SH_RT) | |
11926 | | (MICROMIPSOP_MASK_RS << MICROMIPSOP_SH_RS) | |
11927 | | (MICROMIPSOP_MASK_SEL << MICROMIPSOP_SH_SEL)); | |
11928 | opcode &= mask; | |
11929 | switch (opcode) | |
11930 | { | |
11931 | case 0x000000fc: /* mfc0 */ | |
11932 | case 0x000002fc: /* mtc0 */ | |
11933 | case 0x580000fc: /* dmfc0 */ | |
11934 | case 0x580002fc: /* dmtc0 */ | |
11935 | cop0 = 1; | |
11936 | break; | |
11937 | default: | |
11938 | cop0 = 0; | |
11939 | break; | |
11940 | } | |
11941 | } | |
11942 | else | |
11943 | { | |
11944 | opcode = (opcode >> OP_SH_OP) & OP_MASK_OP; | |
11945 | cop0 = opcode == OP_OP_COP0; | |
11946 | } | |
11947 | types = RTYPE_NUM | (cop0 ? RTYPE_CP0 : RTYPE_GP); | |
11948 | ok = reg_lookup (&s, types, ®no); | |
11949 | if (mips_opts.micromips) | |
11950 | INSERT_OPERAND (1, RS, *ip, regno); | |
11951 | else | |
11952 | INSERT_OPERAND (0, RD, *ip, regno); | |
11953 | if (ok) | |
11954 | { | |
11955 | lastregno = regno; | |
11956 | continue; | |
11957 | } | |
11958 | } | |
11959 | break; | |
707bfff6 | 11960 | |
df58fc94 RS |
11961 | case 'y': /* ALNV.PS source register. */ |
11962 | gas_assert (mips_opts.micromips); | |
11963 | goto do_reg; | |
11964 | case 'x': /* Ignore register name. */ | |
11965 | case 'U': /* Destination register (CLO/CLZ). */ | |
11966 | case 'g': /* Coprocessor destination register. */ | |
11967 | gas_assert (!mips_opts.micromips); | |
90ecf173 MR |
11968 | case 'b': /* Base register. */ |
11969 | case 'd': /* Destination register. */ | |
11970 | case 's': /* Source register. */ | |
11971 | case 't': /* Target register. */ | |
11972 | case 'r': /* Both target and source. */ | |
11973 | case 'v': /* Both dest and source. */ | |
11974 | case 'w': /* Both dest and target. */ | |
11975 | case 'E': /* Coprocessor target register. */ | |
11976 | case 'K': /* RDHWR destination register. */ | |
90ecf173 | 11977 | case 'z': /* Must be zero register. */ |
df58fc94 | 11978 | do_reg: |
90ecf173 | 11979 | s_reset = s; |
707bfff6 TS |
11980 | if (*args == 'E' || *args == 'K') |
11981 | ok = reg_lookup (&s, RTYPE_NUM, ®no); | |
11982 | else | |
11983 | { | |
11984 | ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no); | |
741fe287 MR |
11985 | if (regno == AT && mips_opts.at) |
11986 | { | |
11987 | if (mips_opts.at == ATREG) | |
f71d0d44 | 11988 | as_warn (_("Used $at without \".set noat\"")); |
741fe287 | 11989 | else |
f71d0d44 | 11990 | as_warn (_("Used $%u with \".set at=$%u\""), |
741fe287 MR |
11991 | regno, mips_opts.at); |
11992 | } | |
707bfff6 TS |
11993 | } |
11994 | if (ok) | |
252b5132 | 11995 | { |
252b5132 RH |
11996 | c = *args; |
11997 | if (*s == ' ') | |
f9419b05 | 11998 | ++s; |
252b5132 RH |
11999 | if (args[1] != *s) |
12000 | { | |
12001 | if (c == 'r' || c == 'v' || c == 'w') | |
12002 | { | |
12003 | regno = lastregno; | |
12004 | s = s_reset; | |
f9419b05 | 12005 | ++args; |
252b5132 RH |
12006 | } |
12007 | } | |
12008 | /* 'z' only matches $0. */ | |
12009 | if (c == 'z' && regno != 0) | |
12010 | break; | |
12011 | ||
24864476 | 12012 | if (c == 's' && !strncmp (ip->insn_mo->name, "jalr", 4)) |
e7c604dd CM |
12013 | { |
12014 | if (regno == lastregno) | |
90ecf173 MR |
12015 | { |
12016 | insn_error | |
f71d0d44 | 12017 | = _("Source and destination must be different"); |
e7c604dd | 12018 | continue; |
90ecf173 | 12019 | } |
24864476 | 12020 | if (regno == 31 && lastregno == 0xffffffff) |
90ecf173 MR |
12021 | { |
12022 | insn_error | |
f71d0d44 | 12023 | = _("A destination register must be supplied"); |
e7c604dd | 12024 | continue; |
90ecf173 | 12025 | } |
e7c604dd | 12026 | } |
90ecf173 MR |
12027 | /* Now that we have assembled one operand, we use the args |
12028 | string to figure out where it goes in the instruction. */ | |
252b5132 RH |
12029 | switch (c) |
12030 | { | |
12031 | case 'r': | |
12032 | case 's': | |
12033 | case 'v': | |
12034 | case 'b': | |
df58fc94 | 12035 | INSERT_OPERAND (mips_opts.micromips, RS, *ip, regno); |
252b5132 | 12036 | break; |
df58fc94 | 12037 | |
af7ee8bf | 12038 | case 'K': |
df58fc94 RS |
12039 | if (mips_opts.micromips) |
12040 | INSERT_OPERAND (1, RS, *ip, regno); | |
12041 | else | |
12042 | INSERT_OPERAND (0, RD, *ip, regno); | |
12043 | break; | |
12044 | ||
12045 | case 'd': | |
ef2e4d86 | 12046 | case 'g': |
df58fc94 | 12047 | INSERT_OPERAND (mips_opts.micromips, RD, *ip, regno); |
252b5132 | 12048 | break; |
df58fc94 | 12049 | |
4372b673 | 12050 | case 'U': |
df58fc94 RS |
12051 | gas_assert (!mips_opts.micromips); |
12052 | INSERT_OPERAND (0, RD, *ip, regno); | |
12053 | INSERT_OPERAND (0, RT, *ip, regno); | |
4372b673 | 12054 | break; |
df58fc94 | 12055 | |
252b5132 RH |
12056 | case 'w': |
12057 | case 't': | |
12058 | case 'E': | |
df58fc94 RS |
12059 | INSERT_OPERAND (mips_opts.micromips, RT, *ip, regno); |
12060 | break; | |
12061 | ||
12062 | case 'y': | |
12063 | gas_assert (mips_opts.micromips); | |
12064 | INSERT_OPERAND (1, RS3, *ip, regno); | |
252b5132 | 12065 | break; |
df58fc94 | 12066 | |
252b5132 RH |
12067 | case 'x': |
12068 | /* This case exists because on the r3000 trunc | |
12069 | expands into a macro which requires a gp | |
12070 | register. On the r6000 or r4000 it is | |
12071 | assembled into a single instruction which | |
12072 | ignores the register. Thus the insn version | |
12073 | is MIPS_ISA2 and uses 'x', and the macro | |
12074 | version is MIPS_ISA1 and uses 't'. */ | |
12075 | break; | |
df58fc94 | 12076 | |
252b5132 RH |
12077 | case 'z': |
12078 | /* This case is for the div instruction, which | |
12079 | acts differently if the destination argument | |
12080 | is $0. This only matches $0, and is checked | |
12081 | outside the switch. */ | |
12082 | break; | |
252b5132 RH |
12083 | } |
12084 | lastregno = regno; | |
12085 | continue; | |
12086 | } | |
252b5132 RH |
12087 | switch (*args++) |
12088 | { | |
12089 | case 'r': | |
12090 | case 'v': | |
df58fc94 | 12091 | INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno); |
252b5132 | 12092 | continue; |
df58fc94 | 12093 | |
252b5132 | 12094 | case 'w': |
df58fc94 | 12095 | INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno); |
252b5132 RH |
12096 | continue; |
12097 | } | |
12098 | break; | |
12099 | ||
deec1734 | 12100 | case 'O': /* MDMX alignment immediate constant. */ |
df58fc94 | 12101 | gas_assert (!mips_opts.micromips); |
deec1734 CD |
12102 | my_getExpression (&imm_expr, s); |
12103 | check_absolute_expr (ip, &imm_expr); | |
12104 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN) | |
20203fb9 | 12105 | as_warn (_("Improper align amount (%ld), using low bits"), |
bf12938e | 12106 | (long) imm_expr.X_add_number); |
df58fc94 | 12107 | INSERT_OPERAND (0, ALN, *ip, imm_expr.X_add_number); |
deec1734 CD |
12108 | imm_expr.X_op = O_absent; |
12109 | s = expr_end; | |
12110 | continue; | |
12111 | ||
12112 | case 'Q': /* MDMX vector, element sel, or const. */ | |
12113 | if (s[0] != '$') | |
12114 | { | |
12115 | /* MDMX Immediate. */ | |
df58fc94 | 12116 | gas_assert (!mips_opts.micromips); |
deec1734 CD |
12117 | my_getExpression (&imm_expr, s); |
12118 | check_absolute_expr (ip, &imm_expr); | |
12119 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT) | |
bf12938e RS |
12120 | as_warn (_("Invalid MDMX Immediate (%ld)"), |
12121 | (long) imm_expr.X_add_number); | |
df58fc94 | 12122 | INSERT_OPERAND (0, FT, *ip, imm_expr.X_add_number); |
deec1734 CD |
12123 | if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL)) |
12124 | ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL; | |
12125 | else | |
12126 | ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL; | |
deec1734 CD |
12127 | imm_expr.X_op = O_absent; |
12128 | s = expr_end; | |
12129 | continue; | |
12130 | } | |
12131 | /* Not MDMX Immediate. Fall through. */ | |
12132 | case 'X': /* MDMX destination register. */ | |
12133 | case 'Y': /* MDMX source register. */ | |
12134 | case 'Z': /* MDMX target register. */ | |
12135 | is_mdmx = 1; | |
df58fc94 RS |
12136 | case 'W': |
12137 | gas_assert (!mips_opts.micromips); | |
90ecf173 MR |
12138 | case 'D': /* Floating point destination register. */ |
12139 | case 'S': /* Floating point source register. */ | |
12140 | case 'T': /* Floating point target register. */ | |
12141 | case 'R': /* Floating point source register. */ | |
252b5132 | 12142 | case 'V': |
707bfff6 TS |
12143 | rtype = RTYPE_FPU; |
12144 | if (is_mdmx | |
12145 | || (mips_opts.ase_mdmx | |
12146 | && (ip->insn_mo->pinfo & FP_D) | |
12147 | && (ip->insn_mo->pinfo & (INSN_COPROC_MOVE_DELAY | |
12148 | | INSN_COPROC_MEMORY_DELAY | |
12149 | | INSN_LOAD_COPROC_DELAY | |
12150 | | INSN_LOAD_MEMORY_DELAY | |
12151 | | INSN_STORE_MEMORY)))) | |
12152 | rtype |= RTYPE_VEC; | |
252b5132 | 12153 | s_reset = s; |
707bfff6 | 12154 | if (reg_lookup (&s, rtype, ®no)) |
252b5132 | 12155 | { |
252b5132 | 12156 | if ((regno & 1) != 0 |
ca4e0257 | 12157 | && HAVE_32BIT_FPRS |
90ecf173 | 12158 | && !mips_oddfpreg_ok (ip->insn_mo, argnum)) |
252b5132 RH |
12159 | as_warn (_("Float register should be even, was %d"), |
12160 | regno); | |
12161 | ||
12162 | c = *args; | |
12163 | if (*s == ' ') | |
f9419b05 | 12164 | ++s; |
252b5132 RH |
12165 | if (args[1] != *s) |
12166 | { | |
12167 | if (c == 'V' || c == 'W') | |
12168 | { | |
12169 | regno = lastregno; | |
12170 | s = s_reset; | |
f9419b05 | 12171 | ++args; |
252b5132 RH |
12172 | } |
12173 | } | |
12174 | switch (c) | |
12175 | { | |
12176 | case 'D': | |
deec1734 | 12177 | case 'X': |
df58fc94 | 12178 | INSERT_OPERAND (mips_opts.micromips, FD, *ip, regno); |
252b5132 | 12179 | break; |
df58fc94 | 12180 | |
252b5132 RH |
12181 | case 'V': |
12182 | case 'S': | |
deec1734 | 12183 | case 'Y': |
df58fc94 | 12184 | INSERT_OPERAND (mips_opts.micromips, FS, *ip, regno); |
252b5132 | 12185 | break; |
df58fc94 | 12186 | |
deec1734 CD |
12187 | case 'Q': |
12188 | /* This is like 'Z', but also needs to fix the MDMX | |
12189 | vector/scalar select bits. Note that the | |
12190 | scalar immediate case is handled above. */ | |
12191 | if (*s == '[') | |
12192 | { | |
12193 | int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL)); | |
12194 | int max_el = (is_qh ? 3 : 7); | |
12195 | s++; | |
12196 | my_getExpression(&imm_expr, s); | |
12197 | check_absolute_expr (ip, &imm_expr); | |
12198 | s = expr_end; | |
12199 | if (imm_expr.X_add_number > max_el) | |
20203fb9 NC |
12200 | as_bad (_("Bad element selector %ld"), |
12201 | (long) imm_expr.X_add_number); | |
deec1734 CD |
12202 | imm_expr.X_add_number &= max_el; |
12203 | ip->insn_opcode |= (imm_expr.X_add_number | |
12204 | << (OP_SH_VSEL + | |
12205 | (is_qh ? 2 : 1))); | |
01a3f561 | 12206 | imm_expr.X_op = O_absent; |
deec1734 | 12207 | if (*s != ']') |
20203fb9 | 12208 | as_warn (_("Expecting ']' found '%s'"), s); |
deec1734 CD |
12209 | else |
12210 | s++; | |
12211 | } | |
12212 | else | |
12213 | { | |
12214 | if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL)) | |
12215 | ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH | |
12216 | << OP_SH_VSEL); | |
12217 | else | |
12218 | ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB << | |
12219 | OP_SH_VSEL); | |
12220 | } | |
90ecf173 | 12221 | /* Fall through. */ |
252b5132 RH |
12222 | case 'W': |
12223 | case 'T': | |
deec1734 | 12224 | case 'Z': |
df58fc94 | 12225 | INSERT_OPERAND (mips_opts.micromips, FT, *ip, regno); |
252b5132 | 12226 | break; |
df58fc94 | 12227 | |
252b5132 | 12228 | case 'R': |
df58fc94 | 12229 | INSERT_OPERAND (mips_opts.micromips, FR, *ip, regno); |
252b5132 RH |
12230 | break; |
12231 | } | |
12232 | lastregno = regno; | |
12233 | continue; | |
12234 | } | |
12235 | ||
252b5132 RH |
12236 | switch (*args++) |
12237 | { | |
12238 | case 'V': | |
df58fc94 | 12239 | INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno); |
252b5132 | 12240 | continue; |
df58fc94 | 12241 | |
252b5132 | 12242 | case 'W': |
df58fc94 | 12243 | INSERT_OPERAND (mips_opts.micromips, FT, *ip, lastregno); |
252b5132 RH |
12244 | continue; |
12245 | } | |
12246 | break; | |
12247 | ||
12248 | case 'I': | |
12249 | my_getExpression (&imm_expr, s); | |
12250 | if (imm_expr.X_op != O_big | |
12251 | && imm_expr.X_op != O_constant) | |
12252 | insn_error = _("absolute expression required"); | |
9ee2a2d4 MR |
12253 | if (HAVE_32BIT_GPRS) |
12254 | normalize_constant_expr (&imm_expr); | |
252b5132 RH |
12255 | s = expr_end; |
12256 | continue; | |
12257 | ||
12258 | case 'A': | |
12259 | my_getExpression (&offset_expr, s); | |
2051e8c4 | 12260 | normalize_address_expr (&offset_expr); |
f6688943 | 12261 | *imm_reloc = BFD_RELOC_32; |
252b5132 RH |
12262 | s = expr_end; |
12263 | continue; | |
12264 | ||
12265 | case 'F': | |
12266 | case 'L': | |
12267 | case 'f': | |
12268 | case 'l': | |
12269 | { | |
12270 | int f64; | |
ca4e0257 | 12271 | int using_gprs; |
252b5132 RH |
12272 | char *save_in; |
12273 | char *err; | |
12274 | unsigned char temp[8]; | |
12275 | int len; | |
12276 | unsigned int length; | |
12277 | segT seg; | |
12278 | subsegT subseg; | |
12279 | char *p; | |
12280 | ||
12281 | /* These only appear as the last operand in an | |
12282 | instruction, and every instruction that accepts | |
12283 | them in any variant accepts them in all variants. | |
12284 | This means we don't have to worry about backing out | |
12285 | any changes if the instruction does not match. | |
12286 | ||
12287 | The difference between them is the size of the | |
12288 | floating point constant and where it goes. For 'F' | |
12289 | and 'L' the constant is 64 bits; for 'f' and 'l' it | |
12290 | is 32 bits. Where the constant is placed is based | |
12291 | on how the MIPS assembler does things: | |
12292 | F -- .rdata | |
12293 | L -- .lit8 | |
12294 | f -- immediate value | |
12295 | l -- .lit4 | |
12296 | ||
12297 | The .lit4 and .lit8 sections are only used if | |
12298 | permitted by the -G argument. | |
12299 | ||
ca4e0257 RS |
12300 | The code below needs to know whether the target register |
12301 | is 32 or 64 bits wide. It relies on the fact 'f' and | |
12302 | 'F' are used with GPR-based instructions and 'l' and | |
12303 | 'L' are used with FPR-based instructions. */ | |
252b5132 RH |
12304 | |
12305 | f64 = *args == 'F' || *args == 'L'; | |
ca4e0257 | 12306 | using_gprs = *args == 'F' || *args == 'f'; |
252b5132 RH |
12307 | |
12308 | save_in = input_line_pointer; | |
12309 | input_line_pointer = s; | |
12310 | err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len); | |
12311 | length = len; | |
12312 | s = input_line_pointer; | |
12313 | input_line_pointer = save_in; | |
12314 | if (err != NULL && *err != '\0') | |
12315 | { | |
12316 | as_bad (_("Bad floating point constant: %s"), err); | |
12317 | memset (temp, '\0', sizeof temp); | |
12318 | length = f64 ? 8 : 4; | |
12319 | } | |
12320 | ||
9c2799c2 | 12321 | gas_assert (length == (unsigned) (f64 ? 8 : 4)); |
252b5132 RH |
12322 | |
12323 | if (*args == 'f' | |
12324 | || (*args == 'l' | |
3e722fb5 | 12325 | && (g_switch_value < 4 |
252b5132 RH |
12326 | || (temp[0] == 0 && temp[1] == 0) |
12327 | || (temp[2] == 0 && temp[3] == 0)))) | |
12328 | { | |
12329 | imm_expr.X_op = O_constant; | |
90ecf173 | 12330 | if (!target_big_endian) |
252b5132 RH |
12331 | imm_expr.X_add_number = bfd_getl32 (temp); |
12332 | else | |
12333 | imm_expr.X_add_number = bfd_getb32 (temp); | |
12334 | } | |
12335 | else if (length > 4 | |
90ecf173 | 12336 | && !mips_disable_float_construction |
ca4e0257 RS |
12337 | /* Constants can only be constructed in GPRs and |
12338 | copied to FPRs if the GPRs are at least as wide | |
12339 | as the FPRs. Force the constant into memory if | |
12340 | we are using 64-bit FPRs but the GPRs are only | |
12341 | 32 bits wide. */ | |
12342 | && (using_gprs | |
90ecf173 | 12343 | || !(HAVE_64BIT_FPRS && HAVE_32BIT_GPRS)) |
252b5132 RH |
12344 | && ((temp[0] == 0 && temp[1] == 0) |
12345 | || (temp[2] == 0 && temp[3] == 0)) | |
12346 | && ((temp[4] == 0 && temp[5] == 0) | |
12347 | || (temp[6] == 0 && temp[7] == 0))) | |
12348 | { | |
ca4e0257 | 12349 | /* The value is simple enough to load with a couple of |
90ecf173 MR |
12350 | instructions. If using 32-bit registers, set |
12351 | imm_expr to the high order 32 bits and offset_expr to | |
12352 | the low order 32 bits. Otherwise, set imm_expr to | |
12353 | the entire 64 bit constant. */ | |
ca4e0257 | 12354 | if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS) |
252b5132 RH |
12355 | { |
12356 | imm_expr.X_op = O_constant; | |
12357 | offset_expr.X_op = O_constant; | |
90ecf173 | 12358 | if (!target_big_endian) |
252b5132 RH |
12359 | { |
12360 | imm_expr.X_add_number = bfd_getl32 (temp + 4); | |
12361 | offset_expr.X_add_number = bfd_getl32 (temp); | |
12362 | } | |
12363 | else | |
12364 | { | |
12365 | imm_expr.X_add_number = bfd_getb32 (temp); | |
12366 | offset_expr.X_add_number = bfd_getb32 (temp + 4); | |
12367 | } | |
12368 | if (offset_expr.X_add_number == 0) | |
12369 | offset_expr.X_op = O_absent; | |
12370 | } | |
12371 | else if (sizeof (imm_expr.X_add_number) > 4) | |
12372 | { | |
12373 | imm_expr.X_op = O_constant; | |
90ecf173 | 12374 | if (!target_big_endian) |
252b5132 RH |
12375 | imm_expr.X_add_number = bfd_getl64 (temp); |
12376 | else | |
12377 | imm_expr.X_add_number = bfd_getb64 (temp); | |
12378 | } | |
12379 | else | |
12380 | { | |
12381 | imm_expr.X_op = O_big; | |
12382 | imm_expr.X_add_number = 4; | |
90ecf173 | 12383 | if (!target_big_endian) |
252b5132 RH |
12384 | { |
12385 | generic_bignum[0] = bfd_getl16 (temp); | |
12386 | generic_bignum[1] = bfd_getl16 (temp + 2); | |
12387 | generic_bignum[2] = bfd_getl16 (temp + 4); | |
12388 | generic_bignum[3] = bfd_getl16 (temp + 6); | |
12389 | } | |
12390 | else | |
12391 | { | |
12392 | generic_bignum[0] = bfd_getb16 (temp + 6); | |
12393 | generic_bignum[1] = bfd_getb16 (temp + 4); | |
12394 | generic_bignum[2] = bfd_getb16 (temp + 2); | |
12395 | generic_bignum[3] = bfd_getb16 (temp); | |
12396 | } | |
12397 | } | |
12398 | } | |
12399 | else | |
12400 | { | |
12401 | const char *newname; | |
12402 | segT new_seg; | |
12403 | ||
12404 | /* Switch to the right section. */ | |
12405 | seg = now_seg; | |
12406 | subseg = now_subseg; | |
12407 | switch (*args) | |
12408 | { | |
12409 | default: /* unused default case avoids warnings. */ | |
12410 | case 'L': | |
12411 | newname = RDATA_SECTION_NAME; | |
3e722fb5 | 12412 | if (g_switch_value >= 8) |
252b5132 RH |
12413 | newname = ".lit8"; |
12414 | break; | |
12415 | case 'F': | |
3e722fb5 | 12416 | newname = RDATA_SECTION_NAME; |
252b5132 RH |
12417 | break; |
12418 | case 'l': | |
9c2799c2 | 12419 | gas_assert (g_switch_value >= 4); |
252b5132 RH |
12420 | newname = ".lit4"; |
12421 | break; | |
12422 | } | |
12423 | new_seg = subseg_new (newname, (subsegT) 0); | |
f43abd2b | 12424 | if (IS_ELF) |
252b5132 RH |
12425 | bfd_set_section_flags (stdoutput, new_seg, |
12426 | (SEC_ALLOC | |
12427 | | SEC_LOAD | |
12428 | | SEC_READONLY | |
12429 | | SEC_DATA)); | |
12430 | frag_align (*args == 'l' ? 2 : 3, 0, 0); | |
c41e87e3 | 12431 | if (IS_ELF && strncmp (TARGET_OS, "elf", 3) != 0) |
252b5132 RH |
12432 | record_alignment (new_seg, 4); |
12433 | else | |
12434 | record_alignment (new_seg, *args == 'l' ? 2 : 3); | |
12435 | if (seg == now_seg) | |
12436 | as_bad (_("Can't use floating point insn in this section")); | |
12437 | ||
df58fc94 RS |
12438 | /* Set the argument to the current address in the |
12439 | section. */ | |
12440 | offset_expr.X_op = O_symbol; | |
12441 | offset_expr.X_add_symbol = symbol_temp_new_now (); | |
12442 | offset_expr.X_add_number = 0; | |
12443 | ||
12444 | /* Put the floating point number into the section. */ | |
12445 | p = frag_more ((int) length); | |
12446 | memcpy (p, temp, length); | |
12447 | ||
12448 | /* Switch back to the original section. */ | |
12449 | subseg_set (seg, subseg); | |
12450 | } | |
12451 | } | |
12452 | continue; | |
12453 | ||
12454 | case 'i': /* 16-bit unsigned immediate. */ | |
12455 | case 'j': /* 16-bit signed immediate. */ | |
12456 | *imm_reloc = BFD_RELOC_LO16; | |
12457 | if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0) | |
12458 | { | |
12459 | int more; | |
12460 | offsetT minval, maxval; | |
12461 | ||
12462 | more = (insn + 1 < past | |
12463 | && strcmp (insn->name, insn[1].name) == 0); | |
12464 | ||
12465 | /* If the expression was written as an unsigned number, | |
12466 | only treat it as signed if there are no more | |
12467 | alternatives. */ | |
12468 | if (more | |
12469 | && *args == 'j' | |
12470 | && sizeof (imm_expr.X_add_number) <= 4 | |
12471 | && imm_expr.X_op == O_constant | |
12472 | && imm_expr.X_add_number < 0 | |
12473 | && imm_expr.X_unsigned | |
12474 | && HAVE_64BIT_GPRS) | |
12475 | break; | |
12476 | ||
12477 | /* For compatibility with older assemblers, we accept | |
12478 | 0x8000-0xffff as signed 16-bit numbers when only | |
12479 | signed numbers are allowed. */ | |
12480 | if (*args == 'i') | |
12481 | minval = 0, maxval = 0xffff; | |
12482 | else if (more) | |
12483 | minval = -0x8000, maxval = 0x7fff; | |
12484 | else | |
12485 | minval = -0x8000, maxval = 0xffff; | |
12486 | ||
12487 | if (imm_expr.X_op != O_constant | |
12488 | || imm_expr.X_add_number < minval | |
12489 | || imm_expr.X_add_number > maxval) | |
12490 | { | |
12491 | if (more) | |
12492 | break; | |
12493 | if (imm_expr.X_op == O_constant | |
12494 | || imm_expr.X_op == O_big) | |
12495 | as_bad (_("Expression out of range")); | |
12496 | } | |
12497 | } | |
12498 | s = expr_end; | |
12499 | continue; | |
12500 | ||
12501 | case 'o': /* 16-bit offset. */ | |
12502 | offset_reloc[0] = BFD_RELOC_LO16; | |
12503 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
12504 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
12505 | ||
12506 | /* Check whether there is only a single bracketed expression | |
12507 | left. If so, it must be the base register and the | |
12508 | constant must be zero. */ | |
12509 | if (*s == '(' && strchr (s + 1, '(') == 0) | |
12510 | { | |
12511 | offset_expr.X_op = O_constant; | |
12512 | offset_expr.X_add_number = 0; | |
12513 | continue; | |
12514 | } | |
12515 | ||
12516 | /* If this value won't fit into a 16 bit offset, then go | |
12517 | find a macro that will generate the 32 bit offset | |
12518 | code pattern. */ | |
12519 | if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0 | |
12520 | && (offset_expr.X_op != O_constant | |
12521 | || offset_expr.X_add_number >= 0x8000 | |
12522 | || offset_expr.X_add_number < -0x8000)) | |
12523 | break; | |
12524 | ||
12525 | s = expr_end; | |
12526 | continue; | |
12527 | ||
12528 | case 'p': /* PC-relative offset. */ | |
12529 | *offset_reloc = BFD_RELOC_16_PCREL_S2; | |
12530 | my_getExpression (&offset_expr, s); | |
12531 | s = expr_end; | |
12532 | continue; | |
12533 | ||
12534 | case 'u': /* Upper 16 bits. */ | |
5821951c | 12535 | *imm_reloc = BFD_RELOC_LO16; |
df58fc94 RS |
12536 | if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0 |
12537 | && imm_expr.X_op == O_constant | |
12538 | && (imm_expr.X_add_number < 0 | |
12539 | || imm_expr.X_add_number >= 0x10000)) | |
12540 | as_bad (_("lui expression (%lu) not in range 0..65535"), | |
12541 | (unsigned long) imm_expr.X_add_number); | |
12542 | s = expr_end; | |
12543 | continue; | |
12544 | ||
12545 | case 'a': /* 26-bit address. */ | |
12546 | *offset_reloc = BFD_RELOC_MIPS_JMP; | |
12547 | my_getExpression (&offset_expr, s); | |
12548 | s = expr_end; | |
12549 | continue; | |
12550 | ||
12551 | case 'N': /* 3-bit branch condition code. */ | |
12552 | case 'M': /* 3-bit compare condition code. */ | |
12553 | rtype = RTYPE_CCC; | |
12554 | if (ip->insn_mo->pinfo & (FP_D | FP_S)) | |
12555 | rtype |= RTYPE_FCC; | |
12556 | if (!reg_lookup (&s, rtype, ®no)) | |
12557 | break; | |
12558 | if ((strcmp (str + strlen (str) - 3, ".ps") == 0 | |
12559 | || strcmp (str + strlen (str) - 5, "any2f") == 0 | |
12560 | || strcmp (str + strlen (str) - 5, "any2t") == 0) | |
12561 | && (regno & 1) != 0) | |
12562 | as_warn (_("Condition code register should be even for %s, " | |
12563 | "was %d"), | |
12564 | str, regno); | |
12565 | if ((strcmp (str + strlen (str) - 5, "any4f") == 0 | |
12566 | || strcmp (str + strlen (str) - 5, "any4t") == 0) | |
12567 | && (regno & 3) != 0) | |
12568 | as_warn (_("Condition code register should be 0 or 4 for %s, " | |
12569 | "was %d"), | |
12570 | str, regno); | |
12571 | if (*args == 'N') | |
12572 | INSERT_OPERAND (mips_opts.micromips, BCC, *ip, regno); | |
12573 | else | |
12574 | INSERT_OPERAND (mips_opts.micromips, CCC, *ip, regno); | |
12575 | continue; | |
12576 | ||
12577 | case 'H': | |
12578 | if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) | |
12579 | s += 2; | |
12580 | if (ISDIGIT (*s)) | |
12581 | { | |
12582 | c = 0; | |
12583 | do | |
12584 | { | |
12585 | c *= 10; | |
12586 | c += *s - '0'; | |
12587 | ++s; | |
12588 | } | |
12589 | while (ISDIGIT (*s)); | |
12590 | } | |
12591 | else | |
12592 | c = 8; /* Invalid sel value. */ | |
12593 | ||
12594 | if (c > 7) | |
12595 | as_bad (_("Invalid coprocessor sub-selection value (0-7)")); | |
12596 | INSERT_OPERAND (mips_opts.micromips, SEL, *ip, c); | |
12597 | continue; | |
12598 | ||
12599 | case 'e': | |
12600 | gas_assert (!mips_opts.micromips); | |
12601 | /* Must be at least one digit. */ | |
12602 | my_getExpression (&imm_expr, s); | |
12603 | check_absolute_expr (ip, &imm_expr); | |
12604 | ||
12605 | if ((unsigned long) imm_expr.X_add_number | |
12606 | > (unsigned long) OP_MASK_VECBYTE) | |
12607 | { | |
12608 | as_bad (_("bad byte vector index (%ld)"), | |
12609 | (long) imm_expr.X_add_number); | |
12610 | imm_expr.X_add_number = 0; | |
12611 | } | |
12612 | ||
12613 | INSERT_OPERAND (0, VECBYTE, *ip, imm_expr.X_add_number); | |
12614 | imm_expr.X_op = O_absent; | |
12615 | s = expr_end; | |
12616 | continue; | |
12617 | ||
12618 | case '%': | |
12619 | gas_assert (!mips_opts.micromips); | |
12620 | my_getExpression (&imm_expr, s); | |
12621 | check_absolute_expr (ip, &imm_expr); | |
12622 | ||
12623 | if ((unsigned long) imm_expr.X_add_number | |
12624 | > (unsigned long) OP_MASK_VECALIGN) | |
12625 | { | |
12626 | as_bad (_("bad byte vector index (%ld)"), | |
12627 | (long) imm_expr.X_add_number); | |
12628 | imm_expr.X_add_number = 0; | |
12629 | } | |
12630 | ||
12631 | INSERT_OPERAND (0, VECALIGN, *ip, imm_expr.X_add_number); | |
12632 | imm_expr.X_op = O_absent; | |
12633 | s = expr_end; | |
12634 | continue; | |
12635 | ||
12636 | case 'm': /* Opcode extension character. */ | |
12637 | gas_assert (mips_opts.micromips); | |
12638 | c = *++args; | |
12639 | switch (c) | |
12640 | { | |
12641 | case 'r': | |
12642 | if (strncmp (s, "$pc", 3) == 0) | |
12643 | { | |
12644 | s += 3; | |
12645 | continue; | |
12646 | } | |
12647 | break; | |
12648 | ||
12649 | case 'a': | |
12650 | case 'b': | |
12651 | case 'c': | |
12652 | case 'd': | |
12653 | case 'e': | |
12654 | case 'f': | |
12655 | case 'g': | |
12656 | case 'h': | |
12657 | case 'i': | |
12658 | case 'j': | |
12659 | case 'l': | |
12660 | case 'm': | |
12661 | case 'n': | |
12662 | case 'p': | |
12663 | case 'q': | |
12664 | case 's': | |
12665 | case 't': | |
12666 | case 'x': | |
12667 | case 'y': | |
12668 | case 'z': | |
12669 | s_reset = s; | |
12670 | ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no); | |
12671 | if (regno == AT && mips_opts.at) | |
12672 | { | |
12673 | if (mips_opts.at == ATREG) | |
12674 | as_warn (_("Used $at without \".set noat\"")); | |
12675 | else | |
12676 | as_warn (_("Used $%u with \".set at=$%u\""), | |
12677 | regno, mips_opts.at); | |
12678 | } | |
12679 | if (!ok) | |
12680 | { | |
12681 | if (c == 'c') | |
12682 | { | |
12683 | gas_assert (args[1] == ','); | |
12684 | regno = lastregno; | |
12685 | ++args; | |
12686 | } | |
12687 | else if (c == 't') | |
12688 | { | |
12689 | gas_assert (args[1] == ','); | |
12690 | ++args; | |
12691 | continue; /* Nothing to do. */ | |
12692 | } | |
12693 | else | |
12694 | break; | |
12695 | } | |
12696 | ||
12697 | if (c == 'j' && !strncmp (ip->insn_mo->name, "jalr", 4)) | |
12698 | { | |
12699 | if (regno == lastregno) | |
12700 | { | |
12701 | insn_error | |
12702 | = _("Source and destination must be different"); | |
12703 | continue; | |
12704 | } | |
12705 | if (regno == 31 && lastregno == 0xffffffff) | |
12706 | { | |
12707 | insn_error | |
12708 | = _("A destination register must be supplied"); | |
12709 | continue; | |
12710 | } | |
12711 | } | |
12712 | ||
12713 | if (*s == ' ') | |
12714 | ++s; | |
12715 | if (args[1] != *s) | |
12716 | { | |
12717 | if (c == 'e') | |
12718 | { | |
12719 | gas_assert (args[1] == ','); | |
12720 | regno = lastregno; | |
12721 | s = s_reset; | |
12722 | ++args; | |
12723 | } | |
12724 | else if (c == 't') | |
12725 | { | |
12726 | gas_assert (args[1] == ','); | |
12727 | s = s_reset; | |
12728 | ++args; | |
12729 | continue; /* Nothing to do. */ | |
12730 | } | |
12731 | } | |
12732 | ||
12733 | /* Make sure regno is the same as lastregno. */ | |
12734 | if (c == 't' && regno != lastregno) | |
12735 | break; | |
12736 | ||
12737 | /* Make sure regno is the same as destregno. */ | |
12738 | if (c == 'x' && regno != destregno) | |
12739 | break; | |
12740 | ||
12741 | /* We need to save regno, before regno maps to the | |
12742 | microMIPS register encoding. */ | |
12743 | lastregno = regno; | |
12744 | ||
12745 | if (c == 'f') | |
12746 | destregno = regno; | |
12747 | ||
12748 | switch (c) | |
12749 | { | |
12750 | case 'a': | |
12751 | if (regno != GP) | |
12752 | regno = ILLEGAL_REG; | |
12753 | break; | |
12754 | ||
12755 | case 'b': | |
12756 | regno = mips32_to_micromips_reg_b_map[regno]; | |
12757 | break; | |
12758 | ||
12759 | case 'c': | |
12760 | regno = mips32_to_micromips_reg_c_map[regno]; | |
12761 | break; | |
12762 | ||
12763 | case 'd': | |
12764 | regno = mips32_to_micromips_reg_d_map[regno]; | |
12765 | break; | |
12766 | ||
12767 | case 'e': | |
12768 | regno = mips32_to_micromips_reg_e_map[regno]; | |
12769 | break; | |
12770 | ||
12771 | case 'f': | |
12772 | regno = mips32_to_micromips_reg_f_map[regno]; | |
12773 | break; | |
12774 | ||
12775 | case 'g': | |
12776 | regno = mips32_to_micromips_reg_g_map[regno]; | |
12777 | break; | |
12778 | ||
12779 | case 'h': | |
12780 | regno = mips32_to_micromips_reg_h_map[regno]; | |
12781 | break; | |
12782 | ||
12783 | case 'i': | |
12784 | switch (EXTRACT_OPERAND (1, MI, *ip)) | |
12785 | { | |
12786 | case 4: | |
12787 | if (regno == 21) | |
12788 | regno = 3; | |
12789 | else if (regno == 22) | |
12790 | regno = 4; | |
12791 | else if (regno == 5) | |
12792 | regno = 5; | |
12793 | else if (regno == 6) | |
12794 | regno = 6; | |
12795 | else if (regno == 7) | |
12796 | regno = 7; | |
12797 | else | |
12798 | regno = ILLEGAL_REG; | |
12799 | break; | |
12800 | ||
12801 | case 5: | |
12802 | if (regno == 6) | |
12803 | regno = 0; | |
12804 | else if (regno == 7) | |
12805 | regno = 1; | |
12806 | else | |
12807 | regno = ILLEGAL_REG; | |
12808 | break; | |
12809 | ||
12810 | case 6: | |
12811 | if (regno == 7) | |
12812 | regno = 2; | |
12813 | else | |
12814 | regno = ILLEGAL_REG; | |
12815 | break; | |
12816 | ||
12817 | default: | |
12818 | regno = ILLEGAL_REG; | |
12819 | break; | |
12820 | } | |
12821 | break; | |
12822 | ||
12823 | case 'l': | |
12824 | regno = mips32_to_micromips_reg_l_map[regno]; | |
12825 | break; | |
12826 | ||
12827 | case 'm': | |
12828 | regno = mips32_to_micromips_reg_m_map[regno]; | |
12829 | break; | |
12830 | ||
12831 | case 'n': | |
12832 | regno = mips32_to_micromips_reg_n_map[regno]; | |
12833 | break; | |
12834 | ||
12835 | case 'q': | |
12836 | regno = mips32_to_micromips_reg_q_map[regno]; | |
12837 | break; | |
12838 | ||
12839 | case 's': | |
12840 | if (regno != SP) | |
12841 | regno = ILLEGAL_REG; | |
12842 | break; | |
12843 | ||
12844 | case 'y': | |
12845 | if (regno != 31) | |
12846 | regno = ILLEGAL_REG; | |
12847 | break; | |
12848 | ||
12849 | case 'z': | |
12850 | if (regno != ZERO) | |
12851 | regno = ILLEGAL_REG; | |
12852 | break; | |
12853 | ||
12854 | case 'j': /* Do nothing. */ | |
12855 | case 'p': | |
12856 | case 't': | |
12857 | case 'x': | |
12858 | break; | |
12859 | ||
12860 | default: | |
b37df7c4 | 12861 | abort (); |
df58fc94 RS |
12862 | } |
12863 | ||
12864 | if (regno == ILLEGAL_REG) | |
12865 | break; | |
12866 | ||
12867 | switch (c) | |
12868 | { | |
12869 | case 'b': | |
12870 | INSERT_OPERAND (1, MB, *ip, regno); | |
12871 | break; | |
12872 | ||
12873 | case 'c': | |
12874 | INSERT_OPERAND (1, MC, *ip, regno); | |
12875 | break; | |
12876 | ||
12877 | case 'd': | |
12878 | INSERT_OPERAND (1, MD, *ip, regno); | |
12879 | break; | |
12880 | ||
12881 | case 'e': | |
12882 | INSERT_OPERAND (1, ME, *ip, regno); | |
12883 | break; | |
12884 | ||
12885 | case 'f': | |
12886 | INSERT_OPERAND (1, MF, *ip, regno); | |
12887 | break; | |
12888 | ||
12889 | case 'g': | |
12890 | INSERT_OPERAND (1, MG, *ip, regno); | |
12891 | break; | |
12892 | ||
12893 | case 'h': | |
12894 | INSERT_OPERAND (1, MH, *ip, regno); | |
12895 | break; | |
12896 | ||
12897 | case 'i': | |
12898 | INSERT_OPERAND (1, MI, *ip, regno); | |
12899 | break; | |
12900 | ||
12901 | case 'j': | |
12902 | INSERT_OPERAND (1, MJ, *ip, regno); | |
12903 | break; | |
12904 | ||
12905 | case 'l': | |
12906 | INSERT_OPERAND (1, ML, *ip, regno); | |
12907 | break; | |
12908 | ||
12909 | case 'm': | |
12910 | INSERT_OPERAND (1, MM, *ip, regno); | |
12911 | break; | |
12912 | ||
12913 | case 'n': | |
12914 | INSERT_OPERAND (1, MN, *ip, regno); | |
12915 | break; | |
12916 | ||
12917 | case 'p': | |
12918 | INSERT_OPERAND (1, MP, *ip, regno); | |
12919 | break; | |
12920 | ||
12921 | case 'q': | |
12922 | INSERT_OPERAND (1, MQ, *ip, regno); | |
12923 | break; | |
12924 | ||
12925 | case 'a': /* Do nothing. */ | |
12926 | case 's': /* Do nothing. */ | |
12927 | case 't': /* Do nothing. */ | |
12928 | case 'x': /* Do nothing. */ | |
12929 | case 'y': /* Do nothing. */ | |
12930 | case 'z': /* Do nothing. */ | |
12931 | break; | |
12932 | ||
12933 | default: | |
b37df7c4 | 12934 | abort (); |
df58fc94 RS |
12935 | } |
12936 | continue; | |
12937 | ||
12938 | case 'A': | |
12939 | { | |
12940 | bfd_reloc_code_real_type r[3]; | |
12941 | expressionS ep; | |
12942 | int imm; | |
12943 | ||
12944 | /* Check whether there is only a single bracketed | |
12945 | expression left. If so, it must be the base register | |
12946 | and the constant must be zero. */ | |
12947 | if (*s == '(' && strchr (s + 1, '(') == 0) | |
12948 | { | |
12949 | INSERT_OPERAND (1, IMMA, *ip, 0); | |
12950 | continue; | |
12951 | } | |
12952 | ||
12953 | if (my_getSmallExpression (&ep, r, s) > 0 | |
12954 | || !expr_const_in_range (&ep, -64, 64, 2)) | |
12955 | break; | |
12956 | ||
12957 | imm = ep.X_add_number >> 2; | |
12958 | INSERT_OPERAND (1, IMMA, *ip, imm); | |
12959 | } | |
12960 | s = expr_end; | |
12961 | continue; | |
12962 | ||
12963 | case 'B': | |
12964 | { | |
12965 | bfd_reloc_code_real_type r[3]; | |
12966 | expressionS ep; | |
12967 | int imm; | |
12968 | ||
12969 | if (my_getSmallExpression (&ep, r, s) > 0 | |
12970 | || ep.X_op != O_constant) | |
12971 | break; | |
12972 | ||
12973 | for (imm = 0; imm < 8; imm++) | |
12974 | if (micromips_imm_b_map[imm] == ep.X_add_number) | |
12975 | break; | |
12976 | if (imm >= 8) | |
12977 | break; | |
12978 | ||
12979 | INSERT_OPERAND (1, IMMB, *ip, imm); | |
12980 | } | |
12981 | s = expr_end; | |
12982 | continue; | |
12983 | ||
12984 | case 'C': | |
12985 | { | |
12986 | bfd_reloc_code_real_type r[3]; | |
12987 | expressionS ep; | |
12988 | int imm; | |
12989 | ||
12990 | if (my_getSmallExpression (&ep, r, s) > 0 | |
12991 | || ep.X_op != O_constant) | |
12992 | break; | |
12993 | ||
12994 | for (imm = 0; imm < 16; imm++) | |
12995 | if (micromips_imm_c_map[imm] == ep.X_add_number) | |
12996 | break; | |
12997 | if (imm >= 16) | |
12998 | break; | |
12999 | ||
13000 | INSERT_OPERAND (1, IMMC, *ip, imm); | |
13001 | } | |
13002 | s = expr_end; | |
13003 | continue; | |
13004 | ||
13005 | case 'D': /* pc relative offset */ | |
13006 | case 'E': /* pc relative offset */ | |
13007 | my_getExpression (&offset_expr, s); | |
13008 | if (offset_expr.X_op == O_register) | |
13009 | break; | |
13010 | ||
40209cad MR |
13011 | if (!forced_insn_length) |
13012 | *offset_reloc = (int) BFD_RELOC_UNUSED + c; | |
13013 | else if (c == 'D') | |
13014 | *offset_reloc = BFD_RELOC_MICROMIPS_10_PCREL_S1; | |
13015 | else | |
13016 | *offset_reloc = BFD_RELOC_MICROMIPS_7_PCREL_S1; | |
df58fc94 RS |
13017 | s = expr_end; |
13018 | continue; | |
13019 | ||
13020 | case 'F': | |
13021 | { | |
13022 | bfd_reloc_code_real_type r[3]; | |
13023 | expressionS ep; | |
13024 | int imm; | |
13025 | ||
13026 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13027 | || !expr_const_in_range (&ep, 0, 16, 0)) | |
13028 | break; | |
13029 | ||
13030 | imm = ep.X_add_number; | |
13031 | INSERT_OPERAND (1, IMMF, *ip, imm); | |
13032 | } | |
13033 | s = expr_end; | |
13034 | continue; | |
13035 | ||
13036 | case 'G': | |
13037 | { | |
13038 | bfd_reloc_code_real_type r[3]; | |
13039 | expressionS ep; | |
13040 | int imm; | |
13041 | ||
13042 | /* Check whether there is only a single bracketed | |
13043 | expression left. If so, it must be the base register | |
13044 | and the constant must be zero. */ | |
13045 | if (*s == '(' && strchr (s + 1, '(') == 0) | |
13046 | { | |
13047 | INSERT_OPERAND (1, IMMG, *ip, 0); | |
13048 | continue; | |
13049 | } | |
13050 | ||
13051 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13052 | || !expr_const_in_range (&ep, -1, 15, 0)) | |
13053 | break; | |
13054 | ||
13055 | imm = ep.X_add_number & 15; | |
13056 | INSERT_OPERAND (1, IMMG, *ip, imm); | |
13057 | } | |
13058 | s = expr_end; | |
13059 | continue; | |
13060 | ||
13061 | case 'H': | |
13062 | { | |
13063 | bfd_reloc_code_real_type r[3]; | |
13064 | expressionS ep; | |
13065 | int imm; | |
13066 | ||
13067 | /* Check whether there is only a single bracketed | |
13068 | expression left. If so, it must be the base register | |
13069 | and the constant must be zero. */ | |
13070 | if (*s == '(' && strchr (s + 1, '(') == 0) | |
13071 | { | |
13072 | INSERT_OPERAND (1, IMMH, *ip, 0); | |
13073 | continue; | |
13074 | } | |
13075 | ||
13076 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13077 | || !expr_const_in_range (&ep, 0, 16, 1)) | |
13078 | break; | |
13079 | ||
13080 | imm = ep.X_add_number >> 1; | |
13081 | INSERT_OPERAND (1, IMMH, *ip, imm); | |
13082 | } | |
13083 | s = expr_end; | |
13084 | continue; | |
13085 | ||
13086 | case 'I': | |
13087 | { | |
13088 | bfd_reloc_code_real_type r[3]; | |
13089 | expressionS ep; | |
13090 | int imm; | |
13091 | ||
13092 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13093 | || !expr_const_in_range (&ep, -1, 127, 0)) | |
13094 | break; | |
13095 | ||
13096 | imm = ep.X_add_number & 127; | |
13097 | INSERT_OPERAND (1, IMMI, *ip, imm); | |
13098 | } | |
13099 | s = expr_end; | |
13100 | continue; | |
13101 | ||
13102 | case 'J': | |
13103 | { | |
13104 | bfd_reloc_code_real_type r[3]; | |
13105 | expressionS ep; | |
13106 | int imm; | |
13107 | ||
13108 | /* Check whether there is only a single bracketed | |
13109 | expression left. If so, it must be the base register | |
13110 | and the constant must be zero. */ | |
13111 | if (*s == '(' && strchr (s + 1, '(') == 0) | |
13112 | { | |
13113 | INSERT_OPERAND (1, IMMJ, *ip, 0); | |
13114 | continue; | |
13115 | } | |
13116 | ||
13117 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13118 | || !expr_const_in_range (&ep, 0, 16, 2)) | |
13119 | break; | |
13120 | ||
13121 | imm = ep.X_add_number >> 2; | |
13122 | INSERT_OPERAND (1, IMMJ, *ip, imm); | |
13123 | } | |
13124 | s = expr_end; | |
13125 | continue; | |
13126 | ||
13127 | case 'L': | |
13128 | { | |
13129 | bfd_reloc_code_real_type r[3]; | |
13130 | expressionS ep; | |
13131 | int imm; | |
13132 | ||
13133 | /* Check whether there is only a single bracketed | |
13134 | expression left. If so, it must be the base register | |
13135 | and the constant must be zero. */ | |
13136 | if (*s == '(' && strchr (s + 1, '(') == 0) | |
13137 | { | |
13138 | INSERT_OPERAND (1, IMML, *ip, 0); | |
13139 | continue; | |
13140 | } | |
13141 | ||
13142 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13143 | || !expr_const_in_range (&ep, 0, 16, 0)) | |
13144 | break; | |
13145 | ||
13146 | imm = ep.X_add_number; | |
13147 | INSERT_OPERAND (1, IMML, *ip, imm); | |
13148 | } | |
13149 | s = expr_end; | |
13150 | continue; | |
13151 | ||
13152 | case 'M': | |
13153 | { | |
13154 | bfd_reloc_code_real_type r[3]; | |
13155 | expressionS ep; | |
13156 | int imm; | |
13157 | ||
13158 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13159 | || !expr_const_in_range (&ep, 1, 9, 0)) | |
13160 | break; | |
13161 | ||
13162 | imm = ep.X_add_number & 7; | |
13163 | INSERT_OPERAND (1, IMMM, *ip, imm); | |
13164 | } | |
13165 | s = expr_end; | |
13166 | continue; | |
13167 | ||
13168 | case 'N': /* Register list for lwm and swm. */ | |
13169 | { | |
13170 | /* A comma-separated list of registers and/or | |
13171 | dash-separated contiguous ranges including | |
13172 | both ra and a set of one or more registers | |
13173 | starting at s0 up to s3 which have to be | |
13174 | consecutive, e.g.: | |
13175 | ||
13176 | s0, ra | |
13177 | s0, s1, ra, s2, s3 | |
13178 | s0-s2, ra | |
13179 | ||
13180 | and any permutations of these. */ | |
13181 | unsigned int reglist; | |
13182 | int imm; | |
13183 | ||
13184 | if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list)) | |
13185 | break; | |
13186 | ||
13187 | if ((reglist & 0xfff1ffff) != 0x80010000) | |
13188 | break; | |
13189 | ||
13190 | reglist = (reglist >> 17) & 7; | |
13191 | reglist += 1; | |
13192 | if ((reglist & -reglist) != reglist) | |
13193 | break; | |
252b5132 | 13194 | |
df58fc94 RS |
13195 | imm = ffs (reglist) - 1; |
13196 | INSERT_OPERAND (1, IMMN, *ip, imm); | |
13197 | } | |
13198 | continue; | |
252b5132 | 13199 | |
df58fc94 RS |
13200 | case 'O': /* sdbbp 4-bit code. */ |
13201 | { | |
13202 | bfd_reloc_code_real_type r[3]; | |
13203 | expressionS ep; | |
13204 | int imm; | |
13205 | ||
13206 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13207 | || !expr_const_in_range (&ep, 0, 16, 0)) | |
13208 | break; | |
13209 | ||
13210 | imm = ep.X_add_number; | |
13211 | INSERT_OPERAND (1, IMMO, *ip, imm); | |
252b5132 | 13212 | } |
df58fc94 RS |
13213 | s = expr_end; |
13214 | continue; | |
252b5132 | 13215 | |
df58fc94 RS |
13216 | case 'P': |
13217 | { | |
13218 | bfd_reloc_code_real_type r[3]; | |
13219 | expressionS ep; | |
13220 | int imm; | |
5e0116d5 | 13221 | |
df58fc94 RS |
13222 | if (my_getSmallExpression (&ep, r, s) > 0 |
13223 | || !expr_const_in_range (&ep, 0, 32, 2)) | |
13224 | break; | |
5e0116d5 | 13225 | |
df58fc94 RS |
13226 | imm = ep.X_add_number >> 2; |
13227 | INSERT_OPERAND (1, IMMP, *ip, imm); | |
13228 | } | |
13229 | s = expr_end; | |
13230 | continue; | |
5e0116d5 | 13231 | |
df58fc94 RS |
13232 | case 'Q': |
13233 | { | |
13234 | bfd_reloc_code_real_type r[3]; | |
13235 | expressionS ep; | |
13236 | int imm; | |
5e0116d5 | 13237 | |
df58fc94 RS |
13238 | if (my_getSmallExpression (&ep, r, s) > 0 |
13239 | || !expr_const_in_range (&ep, -0x400000, 0x400000, 2)) | |
13240 | break; | |
252b5132 | 13241 | |
df58fc94 RS |
13242 | imm = ep.X_add_number >> 2; |
13243 | INSERT_OPERAND (1, IMMQ, *ip, imm); | |
13244 | } | |
13245 | s = expr_end; | |
13246 | continue; | |
4614d845 | 13247 | |
df58fc94 RS |
13248 | case 'U': |
13249 | { | |
13250 | bfd_reloc_code_real_type r[3]; | |
13251 | expressionS ep; | |
13252 | int imm; | |
13253 | ||
13254 | /* Check whether there is only a single bracketed | |
13255 | expression left. If so, it must be the base register | |
13256 | and the constant must be zero. */ | |
13257 | if (*s == '(' && strchr (s + 1, '(') == 0) | |
13258 | { | |
13259 | INSERT_OPERAND (1, IMMU, *ip, 0); | |
13260 | continue; | |
13261 | } | |
13262 | ||
13263 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13264 | || !expr_const_in_range (&ep, 0, 32, 2)) | |
13265 | break; | |
13266 | ||
13267 | imm = ep.X_add_number >> 2; | |
13268 | INSERT_OPERAND (1, IMMU, *ip, imm); | |
13269 | } | |
13270 | s = expr_end; | |
5e0116d5 | 13271 | continue; |
252b5132 | 13272 | |
df58fc94 RS |
13273 | case 'W': |
13274 | { | |
13275 | bfd_reloc_code_real_type r[3]; | |
13276 | expressionS ep; | |
13277 | int imm; | |
252b5132 | 13278 | |
df58fc94 RS |
13279 | if (my_getSmallExpression (&ep, r, s) > 0 |
13280 | || !expr_const_in_range (&ep, 0, 64, 2)) | |
13281 | break; | |
252b5132 | 13282 | |
df58fc94 RS |
13283 | imm = ep.X_add_number >> 2; |
13284 | INSERT_OPERAND (1, IMMW, *ip, imm); | |
13285 | } | |
13286 | s = expr_end; | |
13287 | continue; | |
252b5132 | 13288 | |
df58fc94 RS |
13289 | case 'X': |
13290 | { | |
13291 | bfd_reloc_code_real_type r[3]; | |
13292 | expressionS ep; | |
13293 | int imm; | |
252b5132 | 13294 | |
df58fc94 RS |
13295 | if (my_getSmallExpression (&ep, r, s) > 0 |
13296 | || !expr_const_in_range (&ep, -8, 8, 0)) | |
13297 | break; | |
252b5132 | 13298 | |
df58fc94 RS |
13299 | imm = ep.X_add_number; |
13300 | INSERT_OPERAND (1, IMMX, *ip, imm); | |
13301 | } | |
13302 | s = expr_end; | |
13303 | continue; | |
252b5132 | 13304 | |
df58fc94 RS |
13305 | case 'Y': |
13306 | { | |
13307 | bfd_reloc_code_real_type r[3]; | |
13308 | expressionS ep; | |
13309 | int imm; | |
156c2f8b | 13310 | |
df58fc94 RS |
13311 | if (my_getSmallExpression (&ep, r, s) > 0 |
13312 | || expr_const_in_range (&ep, -2, 2, 2) | |
13313 | || !expr_const_in_range (&ep, -258, 258, 2)) | |
13314 | break; | |
156c2f8b | 13315 | |
df58fc94 RS |
13316 | imm = ep.X_add_number >> 2; |
13317 | imm = ((imm >> 1) & ~0xff) | (imm & 0xff); | |
13318 | INSERT_OPERAND (1, IMMY, *ip, imm); | |
13319 | } | |
13320 | s = expr_end; | |
13321 | continue; | |
60b63b72 | 13322 | |
df58fc94 RS |
13323 | case 'Z': |
13324 | { | |
13325 | bfd_reloc_code_real_type r[3]; | |
13326 | expressionS ep; | |
13327 | ||
13328 | if (my_getSmallExpression (&ep, r, s) > 0 | |
13329 | || !expr_const_in_range (&ep, 0, 1, 0)) | |
13330 | break; | |
13331 | } | |
13332 | s = expr_end; | |
13333 | continue; | |
13334 | ||
13335 | default: | |
13336 | as_bad (_("Internal error: bad microMIPS opcode " | |
13337 | "(unknown extension operand type `m%c'): %s %s"), | |
13338 | *args, insn->name, insn->args); | |
13339 | /* Further processing is fruitless. */ | |
13340 | return; | |
60b63b72 | 13341 | } |
df58fc94 | 13342 | break; |
60b63b72 | 13343 | |
df58fc94 RS |
13344 | case 'n': /* Register list for 32-bit lwm and swm. */ |
13345 | gas_assert (mips_opts.micromips); | |
13346 | { | |
13347 | /* A comma-separated list of registers and/or | |
13348 | dash-separated contiguous ranges including | |
13349 | at least one of ra and a set of one or more | |
13350 | registers starting at s0 up to s7 and then | |
13351 | s8 which have to be consecutive, e.g.: | |
13352 | ||
13353 | ra | |
13354 | s0 | |
13355 | ra, s0, s1, s2 | |
13356 | s0-s8 | |
13357 | s0-s5, ra | |
13358 | ||
13359 | and any permutations of these. */ | |
13360 | unsigned int reglist; | |
13361 | int imm; | |
13362 | int ra; | |
13363 | ||
13364 | if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list)) | |
13365 | break; | |
13366 | ||
13367 | if ((reglist & 0x3f00ffff) != 0) | |
13368 | break; | |
13369 | ||
13370 | ra = (reglist >> 27) & 0x10; | |
13371 | reglist = ((reglist >> 22) & 0x100) | ((reglist >> 16) & 0xff); | |
13372 | reglist += 1; | |
13373 | if ((reglist & -reglist) != reglist) | |
13374 | break; | |
13375 | ||
13376 | imm = (ffs (reglist) - 1) | ra; | |
13377 | INSERT_OPERAND (1, RT, *ip, imm); | |
13378 | imm_expr.X_op = O_absent; | |
13379 | } | |
60b63b72 RS |
13380 | continue; |
13381 | ||
df58fc94 RS |
13382 | case '|': /* 4-bit trap code. */ |
13383 | gas_assert (mips_opts.micromips); | |
60b63b72 RS |
13384 | my_getExpression (&imm_expr, s); |
13385 | check_absolute_expr (ip, &imm_expr); | |
60b63b72 | 13386 | if ((unsigned long) imm_expr.X_add_number |
df58fc94 RS |
13387 | > MICROMIPSOP_MASK_TRAP) |
13388 | as_bad (_("Trap code (%lu) for %s not in 0..15 range"), | |
13389 | (unsigned long) imm_expr.X_add_number, | |
13390 | ip->insn_mo->name); | |
13391 | INSERT_OPERAND (1, TRAP, *ip, imm_expr.X_add_number); | |
60b63b72 RS |
13392 | imm_expr.X_op = O_absent; |
13393 | s = expr_end; | |
13394 | continue; | |
13395 | ||
252b5132 | 13396 | default: |
f71d0d44 | 13397 | as_bad (_("Bad char = '%c'\n"), *args); |
b37df7c4 | 13398 | abort (); |
252b5132 RH |
13399 | } |
13400 | break; | |
13401 | } | |
13402 | /* Args don't match. */ | |
df58fc94 RS |
13403 | s = argsStart; |
13404 | insn_error = _("Illegal operands"); | |
13405 | if (insn + 1 < past && !strcmp (insn->name, insn[1].name)) | |
252b5132 RH |
13406 | { |
13407 | ++insn; | |
252b5132 RH |
13408 | continue; |
13409 | } | |
df58fc94 RS |
13410 | else if (wrong_delay_slot_insns && need_delay_slot_ok) |
13411 | { | |
13412 | gas_assert (firstinsn); | |
13413 | need_delay_slot_ok = FALSE; | |
13414 | past = insn + 1; | |
13415 | insn = firstinsn; | |
13416 | continue; | |
13417 | } | |
252b5132 RH |
13418 | return; |
13419 | } | |
13420 | } | |
13421 | ||
0499d65b TS |
13422 | #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); } |
13423 | ||
252b5132 RH |
13424 | /* This routine assembles an instruction into its binary format when |
13425 | assembling for the mips16. As a side effect, it sets one of the | |
df58fc94 RS |
13426 | global variables imm_reloc or offset_reloc to the type of relocation |
13427 | to do if one of the operands is an address expression. It also sets | |
13428 | forced_insn_length to the resulting instruction size in bytes if the | |
13429 | user explicitly requested a small or extended instruction. */ | |
252b5132 RH |
13430 | |
13431 | static void | |
17a2f251 | 13432 | mips16_ip (char *str, struct mips_cl_insn *ip) |
252b5132 RH |
13433 | { |
13434 | char *s; | |
13435 | const char *args; | |
13436 | struct mips_opcode *insn; | |
13437 | char *argsstart; | |
13438 | unsigned int regno; | |
13439 | unsigned int lastregno = 0; | |
13440 | char *s_reset; | |
d6f16593 | 13441 | size_t i; |
252b5132 RH |
13442 | |
13443 | insn_error = NULL; | |
13444 | ||
df58fc94 | 13445 | forced_insn_length = 0; |
252b5132 | 13446 | |
3882b010 | 13447 | for (s = str; ISLOWER (*s); ++s) |
252b5132 RH |
13448 | ; |
13449 | switch (*s) | |
13450 | { | |
13451 | case '\0': | |
13452 | break; | |
13453 | ||
13454 | case ' ': | |
13455 | *s++ = '\0'; | |
13456 | break; | |
13457 | ||
13458 | case '.': | |
13459 | if (s[1] == 't' && s[2] == ' ') | |
13460 | { | |
13461 | *s = '\0'; | |
df58fc94 | 13462 | forced_insn_length = 2; |
252b5132 RH |
13463 | s += 3; |
13464 | break; | |
13465 | } | |
13466 | else if (s[1] == 'e' && s[2] == ' ') | |
13467 | { | |
13468 | *s = '\0'; | |
df58fc94 | 13469 | forced_insn_length = 4; |
252b5132 RH |
13470 | s += 3; |
13471 | break; | |
13472 | } | |
13473 | /* Fall through. */ | |
13474 | default: | |
13475 | insn_error = _("unknown opcode"); | |
13476 | return; | |
13477 | } | |
13478 | ||
df58fc94 RS |
13479 | if (mips_opts.noautoextend && !forced_insn_length) |
13480 | forced_insn_length = 2; | |
252b5132 RH |
13481 | |
13482 | if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL) | |
13483 | { | |
13484 | insn_error = _("unrecognized opcode"); | |
13485 | return; | |
13486 | } | |
13487 | ||
13488 | argsstart = s; | |
13489 | for (;;) | |
13490 | { | |
9b3f89ee TS |
13491 | bfd_boolean ok; |
13492 | ||
9c2799c2 | 13493 | gas_assert (strcmp (insn->name, str) == 0); |
252b5132 | 13494 | |
037b32b9 | 13495 | ok = is_opcode_valid_16 (insn); |
9b3f89ee TS |
13496 | if (! ok) |
13497 | { | |
13498 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] | |
13499 | && strcmp (insn->name, insn[1].name) == 0) | |
13500 | { | |
13501 | ++insn; | |
13502 | continue; | |
13503 | } | |
13504 | else | |
13505 | { | |
13506 | if (!insn_error) | |
13507 | { | |
13508 | static char buf[100]; | |
13509 | sprintf (buf, | |
7bd942df | 13510 | _("Opcode not supported on this processor: %s (%s)"), |
9b3f89ee TS |
13511 | mips_cpu_info_from_arch (mips_opts.arch)->name, |
13512 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
13513 | insn_error = buf; | |
13514 | } | |
13515 | return; | |
13516 | } | |
13517 | } | |
13518 | ||
1e915849 | 13519 | create_insn (ip, insn); |
252b5132 | 13520 | imm_expr.X_op = O_absent; |
f6688943 TS |
13521 | imm_reloc[0] = BFD_RELOC_UNUSED; |
13522 | imm_reloc[1] = BFD_RELOC_UNUSED; | |
13523 | imm_reloc[2] = BFD_RELOC_UNUSED; | |
5f74bc13 | 13524 | imm2_expr.X_op = O_absent; |
252b5132 | 13525 | offset_expr.X_op = O_absent; |
f6688943 TS |
13526 | offset_reloc[0] = BFD_RELOC_UNUSED; |
13527 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
13528 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
13529 | for (args = insn->args; 1; ++args) |
13530 | { | |
13531 | int c; | |
13532 | ||
13533 | if (*s == ' ') | |
13534 | ++s; | |
13535 | ||
13536 | /* In this switch statement we call break if we did not find | |
13537 | a match, continue if we did find a match, or return if we | |
13538 | are done. */ | |
13539 | ||
13540 | c = *args; | |
13541 | switch (c) | |
13542 | { | |
13543 | case '\0': | |
13544 | if (*s == '\0') | |
13545 | { | |
b886a2ab RS |
13546 | offsetT value; |
13547 | ||
252b5132 RH |
13548 | /* Stuff the immediate value in now, if we can. */ |
13549 | if (imm_expr.X_op == O_constant | |
f6688943 | 13550 | && *imm_reloc > BFD_RELOC_UNUSED |
b886a2ab RS |
13551 | && insn->pinfo != INSN_MACRO |
13552 | && calculate_reloc (*offset_reloc, | |
13553 | imm_expr.X_add_number, &value)) | |
252b5132 | 13554 | { |
c4e7957c | 13555 | mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED, |
b886a2ab | 13556 | *offset_reloc, value, forced_insn_length, |
43c0598f | 13557 | &ip->insn_opcode); |
252b5132 | 13558 | imm_expr.X_op = O_absent; |
f6688943 | 13559 | *imm_reloc = BFD_RELOC_UNUSED; |
43c0598f | 13560 | *offset_reloc = BFD_RELOC_UNUSED; |
252b5132 RH |
13561 | } |
13562 | ||
13563 | return; | |
13564 | } | |
13565 | break; | |
13566 | ||
13567 | case ',': | |
13568 | if (*s++ == c) | |
13569 | continue; | |
13570 | s--; | |
13571 | switch (*++args) | |
13572 | { | |
13573 | case 'v': | |
bf12938e | 13574 | MIPS16_INSERT_OPERAND (RX, *ip, lastregno); |
252b5132 RH |
13575 | continue; |
13576 | case 'w': | |
bf12938e | 13577 | MIPS16_INSERT_OPERAND (RY, *ip, lastregno); |
252b5132 RH |
13578 | continue; |
13579 | } | |
13580 | break; | |
13581 | ||
13582 | case '(': | |
13583 | case ')': | |
13584 | if (*s++ == c) | |
13585 | continue; | |
13586 | break; | |
13587 | ||
13588 | case 'v': | |
13589 | case 'w': | |
13590 | if (s[0] != '$') | |
13591 | { | |
13592 | if (c == 'v') | |
bf12938e | 13593 | MIPS16_INSERT_OPERAND (RX, *ip, lastregno); |
252b5132 | 13594 | else |
bf12938e | 13595 | MIPS16_INSERT_OPERAND (RY, *ip, lastregno); |
252b5132 RH |
13596 | ++args; |
13597 | continue; | |
13598 | } | |
13599 | /* Fall through. */ | |
13600 | case 'x': | |
13601 | case 'y': | |
13602 | case 'z': | |
13603 | case 'Z': | |
13604 | case '0': | |
13605 | case 'S': | |
13606 | case 'R': | |
13607 | case 'X': | |
13608 | case 'Y': | |
707bfff6 TS |
13609 | s_reset = s; |
13610 | if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no)) | |
252b5132 | 13611 | { |
707bfff6 | 13612 | if (c == 'v' || c == 'w') |
85b51719 | 13613 | { |
707bfff6 | 13614 | if (c == 'v') |
a9e24354 | 13615 | MIPS16_INSERT_OPERAND (RX, *ip, lastregno); |
707bfff6 | 13616 | else |
a9e24354 | 13617 | MIPS16_INSERT_OPERAND (RY, *ip, lastregno); |
707bfff6 TS |
13618 | ++args; |
13619 | continue; | |
85b51719 | 13620 | } |
707bfff6 | 13621 | break; |
252b5132 RH |
13622 | } |
13623 | ||
13624 | if (*s == ' ') | |
13625 | ++s; | |
13626 | if (args[1] != *s) | |
13627 | { | |
13628 | if (c == 'v' || c == 'w') | |
13629 | { | |
13630 | regno = mips16_to_32_reg_map[lastregno]; | |
13631 | s = s_reset; | |
f9419b05 | 13632 | ++args; |
252b5132 RH |
13633 | } |
13634 | } | |
13635 | ||
13636 | switch (c) | |
13637 | { | |
13638 | case 'x': | |
13639 | case 'y': | |
13640 | case 'z': | |
13641 | case 'v': | |
13642 | case 'w': | |
13643 | case 'Z': | |
13644 | regno = mips32_to_16_reg_map[regno]; | |
13645 | break; | |
13646 | ||
13647 | case '0': | |
13648 | if (regno != 0) | |
13649 | regno = ILLEGAL_REG; | |
13650 | break; | |
13651 | ||
13652 | case 'S': | |
13653 | if (regno != SP) | |
13654 | regno = ILLEGAL_REG; | |
13655 | break; | |
13656 | ||
13657 | case 'R': | |
13658 | if (regno != RA) | |
13659 | regno = ILLEGAL_REG; | |
13660 | break; | |
13661 | ||
13662 | case 'X': | |
13663 | case 'Y': | |
741fe287 MR |
13664 | if (regno == AT && mips_opts.at) |
13665 | { | |
13666 | if (mips_opts.at == ATREG) | |
13667 | as_warn (_("used $at without \".set noat\"")); | |
13668 | else | |
13669 | as_warn (_("used $%u with \".set at=$%u\""), | |
13670 | regno, mips_opts.at); | |
13671 | } | |
252b5132 RH |
13672 | break; |
13673 | ||
13674 | default: | |
b37df7c4 | 13675 | abort (); |
252b5132 RH |
13676 | } |
13677 | ||
13678 | if (regno == ILLEGAL_REG) | |
13679 | break; | |
13680 | ||
13681 | switch (c) | |
13682 | { | |
13683 | case 'x': | |
13684 | case 'v': | |
bf12938e | 13685 | MIPS16_INSERT_OPERAND (RX, *ip, regno); |
252b5132 RH |
13686 | break; |
13687 | case 'y': | |
13688 | case 'w': | |
bf12938e | 13689 | MIPS16_INSERT_OPERAND (RY, *ip, regno); |
252b5132 RH |
13690 | break; |
13691 | case 'z': | |
bf12938e | 13692 | MIPS16_INSERT_OPERAND (RZ, *ip, regno); |
252b5132 RH |
13693 | break; |
13694 | case 'Z': | |
bf12938e | 13695 | MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno); |
252b5132 RH |
13696 | case '0': |
13697 | case 'S': | |
13698 | case 'R': | |
13699 | break; | |
13700 | case 'X': | |
bf12938e | 13701 | MIPS16_INSERT_OPERAND (REGR32, *ip, regno); |
252b5132 RH |
13702 | break; |
13703 | case 'Y': | |
13704 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
bf12938e | 13705 | MIPS16_INSERT_OPERAND (REG32R, *ip, regno); |
252b5132 RH |
13706 | break; |
13707 | default: | |
b37df7c4 | 13708 | abort (); |
252b5132 RH |
13709 | } |
13710 | ||
13711 | lastregno = regno; | |
13712 | continue; | |
13713 | ||
13714 | case 'P': | |
13715 | if (strncmp (s, "$pc", 3) == 0) | |
13716 | { | |
13717 | s += 3; | |
13718 | continue; | |
13719 | } | |
13720 | break; | |
13721 | ||
252b5132 RH |
13722 | case '5': |
13723 | case 'H': | |
13724 | case 'W': | |
13725 | case 'D': | |
13726 | case 'j': | |
252b5132 RH |
13727 | case 'V': |
13728 | case 'C': | |
13729 | case 'U': | |
13730 | case 'k': | |
13731 | case 'K': | |
d6f16593 MR |
13732 | i = my_getSmallExpression (&imm_expr, imm_reloc, s); |
13733 | if (i > 0) | |
252b5132 | 13734 | { |
d6f16593 | 13735 | if (imm_expr.X_op != O_constant) |
252b5132 | 13736 | { |
df58fc94 | 13737 | forced_insn_length = 4; |
5c04167a | 13738 | ip->insn_opcode |= MIPS16_EXTEND; |
252b5132 | 13739 | } |
d6f16593 MR |
13740 | else |
13741 | { | |
13742 | /* We need to relax this instruction. */ | |
13743 | *offset_reloc = *imm_reloc; | |
13744 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; | |
13745 | } | |
13746 | s = expr_end; | |
13747 | continue; | |
252b5132 | 13748 | } |
d6f16593 MR |
13749 | *imm_reloc = BFD_RELOC_UNUSED; |
13750 | /* Fall through. */ | |
13751 | case '<': | |
13752 | case '>': | |
13753 | case '[': | |
13754 | case ']': | |
13755 | case '4': | |
13756 | case '8': | |
13757 | my_getExpression (&imm_expr, s); | |
252b5132 RH |
13758 | if (imm_expr.X_op == O_register) |
13759 | { | |
13760 | /* What we thought was an expression turned out to | |
13761 | be a register. */ | |
13762 | ||
13763 | if (s[0] == '(' && args[1] == '(') | |
13764 | { | |
13765 | /* It looks like the expression was omitted | |
13766 | before a register indirection, which means | |
13767 | that the expression is implicitly zero. We | |
13768 | still set up imm_expr, so that we handle | |
13769 | explicit extensions correctly. */ | |
13770 | imm_expr.X_op = O_constant; | |
13771 | imm_expr.X_add_number = 0; | |
f6688943 | 13772 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
13773 | continue; |
13774 | } | |
13775 | ||
13776 | break; | |
13777 | } | |
13778 | ||
13779 | /* We need to relax this instruction. */ | |
f6688943 | 13780 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
13781 | s = expr_end; |
13782 | continue; | |
13783 | ||
13784 | case 'p': | |
13785 | case 'q': | |
13786 | case 'A': | |
13787 | case 'B': | |
13788 | case 'E': | |
13789 | /* We use offset_reloc rather than imm_reloc for the PC | |
13790 | relative operands. This lets macros with both | |
13791 | immediate and address operands work correctly. */ | |
13792 | my_getExpression (&offset_expr, s); | |
13793 | ||
13794 | if (offset_expr.X_op == O_register) | |
13795 | break; | |
13796 | ||
13797 | /* We need to relax this instruction. */ | |
f6688943 | 13798 | *offset_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
13799 | s = expr_end; |
13800 | continue; | |
13801 | ||
13802 | case '6': /* break code */ | |
13803 | my_getExpression (&imm_expr, s); | |
13804 | check_absolute_expr (ip, &imm_expr); | |
13805 | if ((unsigned long) imm_expr.X_add_number > 63) | |
bf12938e RS |
13806 | as_warn (_("Invalid value for `%s' (%lu)"), |
13807 | ip->insn_mo->name, | |
13808 | (unsigned long) imm_expr.X_add_number); | |
13809 | MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number); | |
252b5132 RH |
13810 | imm_expr.X_op = O_absent; |
13811 | s = expr_end; | |
13812 | continue; | |
13813 | ||
13814 | case 'a': /* 26 bit address */ | |
13815 | my_getExpression (&offset_expr, s); | |
13816 | s = expr_end; | |
f6688943 | 13817 | *offset_reloc = BFD_RELOC_MIPS16_JMP; |
252b5132 RH |
13818 | ip->insn_opcode <<= 16; |
13819 | continue; | |
13820 | ||
13821 | case 'l': /* register list for entry macro */ | |
13822 | case 'L': /* register list for exit macro */ | |
13823 | { | |
13824 | int mask; | |
13825 | ||
13826 | if (c == 'l') | |
13827 | mask = 0; | |
13828 | else | |
13829 | mask = 7 << 3; | |
13830 | while (*s != '\0') | |
13831 | { | |
707bfff6 | 13832 | unsigned int freg, reg1, reg2; |
252b5132 RH |
13833 | |
13834 | while (*s == ' ' || *s == ',') | |
13835 | ++s; | |
707bfff6 | 13836 | if (reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1)) |
252b5132 | 13837 | freg = 0; |
707bfff6 TS |
13838 | else if (reg_lookup (&s, RTYPE_FPU, ®1)) |
13839 | freg = 1; | |
252b5132 RH |
13840 | else |
13841 | { | |
707bfff6 TS |
13842 | as_bad (_("can't parse register list")); |
13843 | break; | |
252b5132 RH |
13844 | } |
13845 | if (*s == ' ') | |
13846 | ++s; | |
13847 | if (*s != '-') | |
13848 | reg2 = reg1; | |
13849 | else | |
13850 | { | |
13851 | ++s; | |
707bfff6 TS |
13852 | if (!reg_lookup (&s, freg ? RTYPE_FPU |
13853 | : (RTYPE_GP | RTYPE_NUM), ®2)) | |
252b5132 | 13854 | { |
707bfff6 TS |
13855 | as_bad (_("invalid register list")); |
13856 | break; | |
252b5132 RH |
13857 | } |
13858 | } | |
13859 | if (freg && reg1 == 0 && reg2 == 0 && c == 'L') | |
13860 | { | |
13861 | mask &= ~ (7 << 3); | |
13862 | mask |= 5 << 3; | |
13863 | } | |
13864 | else if (freg && reg1 == 0 && reg2 == 1 && c == 'L') | |
13865 | { | |
13866 | mask &= ~ (7 << 3); | |
13867 | mask |= 6 << 3; | |
13868 | } | |
13869 | else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L') | |
13870 | mask |= (reg2 - 3) << 3; | |
13871 | else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17) | |
13872 | mask |= (reg2 - 15) << 1; | |
f9419b05 | 13873 | else if (reg1 == RA && reg2 == RA) |
252b5132 RH |
13874 | mask |= 1; |
13875 | else | |
13876 | { | |
13877 | as_bad (_("invalid register list")); | |
13878 | break; | |
13879 | } | |
13880 | } | |
13881 | /* The mask is filled in in the opcode table for the | |
13882 | benefit of the disassembler. We remove it before | |
13883 | applying the actual mask. */ | |
13884 | ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6); | |
13885 | ip->insn_opcode |= mask << MIPS16OP_SH_IMM6; | |
13886 | } | |
13887 | continue; | |
13888 | ||
0499d65b TS |
13889 | case 'm': /* Register list for save insn. */ |
13890 | case 'M': /* Register list for restore insn. */ | |
13891 | { | |
5c04167a | 13892 | int opcode = ip->insn_opcode; |
0499d65b | 13893 | int framesz = 0, seen_framesz = 0; |
91d6fa6a | 13894 | int nargs = 0, statics = 0, sregs = 0; |
0499d65b TS |
13895 | |
13896 | while (*s != '\0') | |
13897 | { | |
13898 | unsigned int reg1, reg2; | |
13899 | ||
13900 | SKIP_SPACE_TABS (s); | |
13901 | while (*s == ',') | |
13902 | ++s; | |
13903 | SKIP_SPACE_TABS (s); | |
13904 | ||
13905 | my_getExpression (&imm_expr, s); | |
13906 | if (imm_expr.X_op == O_constant) | |
13907 | { | |
13908 | /* Handle the frame size. */ | |
13909 | if (seen_framesz) | |
13910 | { | |
13911 | as_bad (_("more than one frame size in list")); | |
13912 | break; | |
13913 | } | |
13914 | seen_framesz = 1; | |
13915 | framesz = imm_expr.X_add_number; | |
13916 | imm_expr.X_op = O_absent; | |
13917 | s = expr_end; | |
13918 | continue; | |
13919 | } | |
13920 | ||
707bfff6 | 13921 | if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1)) |
0499d65b TS |
13922 | { |
13923 | as_bad (_("can't parse register list")); | |
13924 | break; | |
13925 | } | |
0499d65b | 13926 | |
707bfff6 TS |
13927 | while (*s == ' ') |
13928 | ++s; | |
13929 | ||
0499d65b TS |
13930 | if (*s != '-') |
13931 | reg2 = reg1; | |
13932 | else | |
13933 | { | |
13934 | ++s; | |
707bfff6 TS |
13935 | if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®2) |
13936 | || reg2 < reg1) | |
0499d65b TS |
13937 | { |
13938 | as_bad (_("can't parse register list")); | |
13939 | break; | |
13940 | } | |
0499d65b TS |
13941 | } |
13942 | ||
13943 | while (reg1 <= reg2) | |
13944 | { | |
13945 | if (reg1 >= 4 && reg1 <= 7) | |
13946 | { | |
3a93f742 | 13947 | if (!seen_framesz) |
0499d65b | 13948 | /* args $a0-$a3 */ |
91d6fa6a | 13949 | nargs |= 1 << (reg1 - 4); |
0499d65b TS |
13950 | else |
13951 | /* statics $a0-$a3 */ | |
13952 | statics |= 1 << (reg1 - 4); | |
13953 | } | |
13954 | else if ((reg1 >= 16 && reg1 <= 23) || reg1 == 30) | |
13955 | { | |
13956 | /* $s0-$s8 */ | |
13957 | sregs |= 1 << ((reg1 == 30) ? 8 : (reg1 - 16)); | |
13958 | } | |
13959 | else if (reg1 == 31) | |
13960 | { | |
13961 | /* Add $ra to insn. */ | |
13962 | opcode |= 0x40; | |
13963 | } | |
13964 | else | |
13965 | { | |
13966 | as_bad (_("unexpected register in list")); | |
13967 | break; | |
13968 | } | |
13969 | if (++reg1 == 24) | |
13970 | reg1 = 30; | |
13971 | } | |
13972 | } | |
13973 | ||
13974 | /* Encode args/statics combination. */ | |
91d6fa6a | 13975 | if (nargs & statics) |
0499d65b | 13976 | as_bad (_("arg/static registers overlap")); |
91d6fa6a | 13977 | else if (nargs == 0xf) |
0499d65b TS |
13978 | /* All $a0-$a3 are args. */ |
13979 | opcode |= MIPS16_ALL_ARGS << 16; | |
13980 | else if (statics == 0xf) | |
13981 | /* All $a0-$a3 are statics. */ | |
13982 | opcode |= MIPS16_ALL_STATICS << 16; | |
13983 | else | |
13984 | { | |
13985 | int narg = 0, nstat = 0; | |
13986 | ||
13987 | /* Count arg registers. */ | |
91d6fa6a | 13988 | while (nargs & 0x1) |
0499d65b | 13989 | { |
91d6fa6a | 13990 | nargs >>= 1; |
0499d65b TS |
13991 | narg++; |
13992 | } | |
91d6fa6a | 13993 | if (nargs != 0) |
0499d65b TS |
13994 | as_bad (_("invalid arg register list")); |
13995 | ||
13996 | /* Count static registers. */ | |
13997 | while (statics & 0x8) | |
13998 | { | |
13999 | statics = (statics << 1) & 0xf; | |
14000 | nstat++; | |
14001 | } | |
14002 | if (statics != 0) | |
14003 | as_bad (_("invalid static register list")); | |
14004 | ||
14005 | /* Encode args/statics. */ | |
14006 | opcode |= ((narg << 2) | nstat) << 16; | |
14007 | } | |
14008 | ||
14009 | /* Encode $s0/$s1. */ | |
14010 | if (sregs & (1 << 0)) /* $s0 */ | |
14011 | opcode |= 0x20; | |
14012 | if (sregs & (1 << 1)) /* $s1 */ | |
14013 | opcode |= 0x10; | |
14014 | sregs >>= 2; | |
14015 | ||
14016 | if (sregs != 0) | |
14017 | { | |
14018 | /* Count regs $s2-$s8. */ | |
14019 | int nsreg = 0; | |
14020 | while (sregs & 1) | |
14021 | { | |
14022 | sregs >>= 1; | |
14023 | nsreg++; | |
14024 | } | |
14025 | if (sregs != 0) | |
14026 | as_bad (_("invalid static register list")); | |
14027 | /* Encode $s2-$s8. */ | |
14028 | opcode |= nsreg << 24; | |
14029 | } | |
14030 | ||
14031 | /* Encode frame size. */ | |
14032 | if (!seen_framesz) | |
14033 | as_bad (_("missing frame size")); | |
14034 | else if ((framesz & 7) != 0 || framesz < 0 | |
14035 | || framesz > 0xff * 8) | |
14036 | as_bad (_("invalid frame size")); | |
14037 | else if (framesz != 128 || (opcode >> 16) != 0) | |
14038 | { | |
14039 | framesz /= 8; | |
14040 | opcode |= (((framesz & 0xf0) << 16) | |
14041 | | (framesz & 0x0f)); | |
14042 | } | |
14043 | ||
14044 | /* Finally build the instruction. */ | |
14045 | if ((opcode >> 16) != 0 || framesz == 0) | |
5c04167a RS |
14046 | opcode |= MIPS16_EXTEND; |
14047 | ip->insn_opcode = opcode; | |
0499d65b TS |
14048 | } |
14049 | continue; | |
14050 | ||
252b5132 RH |
14051 | case 'e': /* extend code */ |
14052 | my_getExpression (&imm_expr, s); | |
14053 | check_absolute_expr (ip, &imm_expr); | |
14054 | if ((unsigned long) imm_expr.X_add_number > 0x7ff) | |
14055 | { | |
14056 | as_warn (_("Invalid value for `%s' (%lu)"), | |
14057 | ip->insn_mo->name, | |
14058 | (unsigned long) imm_expr.X_add_number); | |
14059 | imm_expr.X_add_number &= 0x7ff; | |
14060 | } | |
14061 | ip->insn_opcode |= imm_expr.X_add_number; | |
14062 | imm_expr.X_op = O_absent; | |
14063 | s = expr_end; | |
14064 | continue; | |
14065 | ||
14066 | default: | |
b37df7c4 | 14067 | abort (); |
252b5132 RH |
14068 | } |
14069 | break; | |
14070 | } | |
14071 | ||
14072 | /* Args don't match. */ | |
14073 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] && | |
14074 | strcmp (insn->name, insn[1].name) == 0) | |
14075 | { | |
14076 | ++insn; | |
14077 | s = argsstart; | |
14078 | continue; | |
14079 | } | |
14080 | ||
14081 | insn_error = _("illegal operands"); | |
14082 | ||
14083 | return; | |
14084 | } | |
14085 | } | |
14086 | ||
14087 | /* This structure holds information we know about a mips16 immediate | |
14088 | argument type. */ | |
14089 | ||
e972090a NC |
14090 | struct mips16_immed_operand |
14091 | { | |
252b5132 RH |
14092 | /* The type code used in the argument string in the opcode table. */ |
14093 | int type; | |
14094 | /* The number of bits in the short form of the opcode. */ | |
14095 | int nbits; | |
14096 | /* The number of bits in the extended form of the opcode. */ | |
14097 | int extbits; | |
14098 | /* The amount by which the short form is shifted when it is used; | |
14099 | for example, the sw instruction has a shift count of 2. */ | |
14100 | int shift; | |
14101 | /* The amount by which the short form is shifted when it is stored | |
14102 | into the instruction code. */ | |
14103 | int op_shift; | |
14104 | /* Non-zero if the short form is unsigned. */ | |
14105 | int unsp; | |
14106 | /* Non-zero if the extended form is unsigned. */ | |
14107 | int extu; | |
14108 | /* Non-zero if the value is PC relative. */ | |
14109 | int pcrel; | |
14110 | }; | |
14111 | ||
14112 | /* The mips16 immediate operand types. */ | |
14113 | ||
14114 | static const struct mips16_immed_operand mips16_immed_operands[] = | |
14115 | { | |
14116 | { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
14117 | { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
14118 | { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
14119 | { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
14120 | { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 }, | |
14121 | { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
14122 | { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
14123 | { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
14124 | { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
14125 | { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 }, | |
14126 | { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
14127 | { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
14128 | { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
14129 | { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 }, | |
14130 | { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
14131 | { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
14132 | { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
14133 | { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
14134 | { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 }, | |
14135 | { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 }, | |
14136 | { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 } | |
14137 | }; | |
14138 | ||
14139 | #define MIPS16_NUM_IMMED \ | |
14140 | (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0]) | |
14141 | ||
b886a2ab RS |
14142 | /* Marshal immediate value VAL for an extended MIPS16 instruction. |
14143 | NBITS is the number of significant bits in VAL. */ | |
14144 | ||
14145 | static unsigned long | |
14146 | mips16_immed_extend (offsetT val, unsigned int nbits) | |
14147 | { | |
14148 | int extval; | |
14149 | if (nbits == 16) | |
14150 | { | |
14151 | extval = ((val >> 11) & 0x1f) | (val & 0x7e0); | |
14152 | val &= 0x1f; | |
14153 | } | |
14154 | else if (nbits == 15) | |
14155 | { | |
14156 | extval = ((val >> 11) & 0xf) | (val & 0x7f0); | |
14157 | val &= 0xf; | |
14158 | } | |
14159 | else | |
14160 | { | |
14161 | extval = ((val & 0x1f) << 6) | (val & 0x20); | |
14162 | val = 0; | |
14163 | } | |
14164 | return (extval << 16) | val; | |
14165 | } | |
14166 | ||
5c04167a RS |
14167 | /* Install immediate value VAL into MIPS16 instruction *INSN, |
14168 | extending it if necessary. The instruction in *INSN may | |
14169 | already be extended. | |
14170 | ||
43c0598f RS |
14171 | RELOC is the relocation that produced VAL, or BFD_RELOC_UNUSED |
14172 | if none. In the former case, VAL is a 16-bit number with no | |
14173 | defined signedness. | |
14174 | ||
14175 | TYPE is the type of the immediate field. USER_INSN_LENGTH | |
14176 | is the length that the user requested, or 0 if none. */ | |
252b5132 RH |
14177 | |
14178 | static void | |
43c0598f RS |
14179 | mips16_immed (char *file, unsigned int line, int type, |
14180 | bfd_reloc_code_real_type reloc, offsetT val, | |
5c04167a | 14181 | unsigned int user_insn_length, unsigned long *insn) |
252b5132 | 14182 | { |
3994f87e | 14183 | const struct mips16_immed_operand *op; |
252b5132 | 14184 | int mintiny, maxtiny; |
252b5132 RH |
14185 | |
14186 | op = mips16_immed_operands; | |
14187 | while (op->type != type) | |
14188 | { | |
14189 | ++op; | |
9c2799c2 | 14190 | gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); |
252b5132 RH |
14191 | } |
14192 | ||
14193 | if (op->unsp) | |
14194 | { | |
14195 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
14196 | { | |
14197 | mintiny = 1; | |
14198 | maxtiny = 1 << op->nbits; | |
14199 | } | |
14200 | else | |
14201 | { | |
14202 | mintiny = 0; | |
14203 | maxtiny = (1 << op->nbits) - 1; | |
14204 | } | |
43c0598f RS |
14205 | if (reloc != BFD_RELOC_UNUSED) |
14206 | val &= 0xffff; | |
252b5132 RH |
14207 | } |
14208 | else | |
14209 | { | |
14210 | mintiny = - (1 << (op->nbits - 1)); | |
14211 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
43c0598f RS |
14212 | if (reloc != BFD_RELOC_UNUSED) |
14213 | val = SEXT_16BIT (val); | |
252b5132 RH |
14214 | } |
14215 | ||
14216 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
14217 | if (type == 'p' || type == 'q') | |
14218 | val /= 2; | |
14219 | ||
14220 | if ((val & ((1 << op->shift) - 1)) != 0 | |
14221 | || val < (mintiny << op->shift) | |
14222 | || val > (maxtiny << op->shift)) | |
5c04167a RS |
14223 | { |
14224 | /* We need an extended instruction. */ | |
14225 | if (user_insn_length == 2) | |
14226 | as_bad_where (file, line, _("invalid unextended operand value")); | |
14227 | else | |
14228 | *insn |= MIPS16_EXTEND; | |
14229 | } | |
14230 | else if (user_insn_length == 4) | |
14231 | { | |
14232 | /* The operand doesn't force an unextended instruction to be extended. | |
14233 | Warn if the user wanted an extended instruction anyway. */ | |
14234 | *insn |= MIPS16_EXTEND; | |
14235 | as_warn_where (file, line, | |
14236 | _("extended operand requested but not required")); | |
14237 | } | |
252b5132 | 14238 | |
5c04167a | 14239 | if (mips16_opcode_length (*insn) == 2) |
252b5132 RH |
14240 | { |
14241 | int insnval; | |
14242 | ||
252b5132 RH |
14243 | insnval = ((val >> op->shift) & ((1 << op->nbits) - 1)); |
14244 | insnval <<= op->op_shift; | |
14245 | *insn |= insnval; | |
14246 | } | |
14247 | else | |
14248 | { | |
14249 | long minext, maxext; | |
252b5132 | 14250 | |
43c0598f | 14251 | if (reloc == BFD_RELOC_UNUSED) |
252b5132 | 14252 | { |
43c0598f RS |
14253 | if (op->extu) |
14254 | { | |
14255 | minext = 0; | |
14256 | maxext = (1 << op->extbits) - 1; | |
14257 | } | |
14258 | else | |
14259 | { | |
14260 | minext = - (1 << (op->extbits - 1)); | |
14261 | maxext = (1 << (op->extbits - 1)) - 1; | |
14262 | } | |
14263 | if (val < minext || val > maxext) | |
14264 | as_bad_where (file, line, | |
14265 | _("operand value out of range for instruction")); | |
252b5132 | 14266 | } |
252b5132 | 14267 | |
b886a2ab | 14268 | *insn |= mips16_immed_extend (val, op->extbits); |
252b5132 RH |
14269 | } |
14270 | } | |
14271 | \f | |
d6f16593 | 14272 | struct percent_op_match |
ad8d3bb3 | 14273 | { |
5e0116d5 RS |
14274 | const char *str; |
14275 | bfd_reloc_code_real_type reloc; | |
d6f16593 MR |
14276 | }; |
14277 | ||
14278 | static const struct percent_op_match mips_percent_op[] = | |
ad8d3bb3 | 14279 | { |
5e0116d5 | 14280 | {"%lo", BFD_RELOC_LO16}, |
ad8d3bb3 | 14281 | #ifdef OBJ_ELF |
5e0116d5 RS |
14282 | {"%call_hi", BFD_RELOC_MIPS_CALL_HI16}, |
14283 | {"%call_lo", BFD_RELOC_MIPS_CALL_LO16}, | |
14284 | {"%call16", BFD_RELOC_MIPS_CALL16}, | |
14285 | {"%got_disp", BFD_RELOC_MIPS_GOT_DISP}, | |
14286 | {"%got_page", BFD_RELOC_MIPS_GOT_PAGE}, | |
14287 | {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST}, | |
14288 | {"%got_hi", BFD_RELOC_MIPS_GOT_HI16}, | |
14289 | {"%got_lo", BFD_RELOC_MIPS_GOT_LO16}, | |
14290 | {"%got", BFD_RELOC_MIPS_GOT16}, | |
14291 | {"%gp_rel", BFD_RELOC_GPREL16}, | |
14292 | {"%half", BFD_RELOC_16}, | |
14293 | {"%highest", BFD_RELOC_MIPS_HIGHEST}, | |
14294 | {"%higher", BFD_RELOC_MIPS_HIGHER}, | |
14295 | {"%neg", BFD_RELOC_MIPS_SUB}, | |
3f98094e DJ |
14296 | {"%tlsgd", BFD_RELOC_MIPS_TLS_GD}, |
14297 | {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM}, | |
14298 | {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16}, | |
14299 | {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16}, | |
14300 | {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16}, | |
14301 | {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16}, | |
14302 | {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL}, | |
ad8d3bb3 | 14303 | #endif |
5e0116d5 | 14304 | {"%hi", BFD_RELOC_HI16_S} |
ad8d3bb3 TS |
14305 | }; |
14306 | ||
d6f16593 MR |
14307 | static const struct percent_op_match mips16_percent_op[] = |
14308 | { | |
14309 | {"%lo", BFD_RELOC_MIPS16_LO16}, | |
14310 | {"%gprel", BFD_RELOC_MIPS16_GPREL}, | |
738e5348 RS |
14311 | {"%got", BFD_RELOC_MIPS16_GOT16}, |
14312 | {"%call16", BFD_RELOC_MIPS16_CALL16}, | |
d0f13682 CLT |
14313 | {"%hi", BFD_RELOC_MIPS16_HI16_S}, |
14314 | {"%tlsgd", BFD_RELOC_MIPS16_TLS_GD}, | |
14315 | {"%tlsldm", BFD_RELOC_MIPS16_TLS_LDM}, | |
14316 | {"%dtprel_hi", BFD_RELOC_MIPS16_TLS_DTPREL_HI16}, | |
14317 | {"%dtprel_lo", BFD_RELOC_MIPS16_TLS_DTPREL_LO16}, | |
14318 | {"%tprel_hi", BFD_RELOC_MIPS16_TLS_TPREL_HI16}, | |
14319 | {"%tprel_lo", BFD_RELOC_MIPS16_TLS_TPREL_LO16}, | |
14320 | {"%gottprel", BFD_RELOC_MIPS16_TLS_GOTTPREL} | |
d6f16593 MR |
14321 | }; |
14322 | ||
252b5132 | 14323 | |
5e0116d5 RS |
14324 | /* Return true if *STR points to a relocation operator. When returning true, |
14325 | move *STR over the operator and store its relocation code in *RELOC. | |
14326 | Leave both *STR and *RELOC alone when returning false. */ | |
14327 | ||
14328 | static bfd_boolean | |
17a2f251 | 14329 | parse_relocation (char **str, bfd_reloc_code_real_type *reloc) |
252b5132 | 14330 | { |
d6f16593 MR |
14331 | const struct percent_op_match *percent_op; |
14332 | size_t limit, i; | |
14333 | ||
14334 | if (mips_opts.mips16) | |
14335 | { | |
14336 | percent_op = mips16_percent_op; | |
14337 | limit = ARRAY_SIZE (mips16_percent_op); | |
14338 | } | |
14339 | else | |
14340 | { | |
14341 | percent_op = mips_percent_op; | |
14342 | limit = ARRAY_SIZE (mips_percent_op); | |
14343 | } | |
76b3015f | 14344 | |
d6f16593 | 14345 | for (i = 0; i < limit; i++) |
5e0116d5 | 14346 | if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0) |
394f9b3a | 14347 | { |
3f98094e DJ |
14348 | int len = strlen (percent_op[i].str); |
14349 | ||
14350 | if (!ISSPACE ((*str)[len]) && (*str)[len] != '(') | |
14351 | continue; | |
14352 | ||
5e0116d5 RS |
14353 | *str += strlen (percent_op[i].str); |
14354 | *reloc = percent_op[i].reloc; | |
394f9b3a | 14355 | |
5e0116d5 RS |
14356 | /* Check whether the output BFD supports this relocation. |
14357 | If not, issue an error and fall back on something safe. */ | |
14358 | if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc)) | |
394f9b3a | 14359 | { |
20203fb9 | 14360 | as_bad (_("relocation %s isn't supported by the current ABI"), |
5e0116d5 | 14361 | percent_op[i].str); |
01a3f561 | 14362 | *reloc = BFD_RELOC_UNUSED; |
394f9b3a | 14363 | } |
5e0116d5 | 14364 | return TRUE; |
394f9b3a | 14365 | } |
5e0116d5 | 14366 | return FALSE; |
394f9b3a | 14367 | } |
ad8d3bb3 | 14368 | |
ad8d3bb3 | 14369 | |
5e0116d5 RS |
14370 | /* Parse string STR as a 16-bit relocatable operand. Store the |
14371 | expression in *EP and the relocations in the array starting | |
14372 | at RELOC. Return the number of relocation operators used. | |
ad8d3bb3 | 14373 | |
01a3f561 | 14374 | On exit, EXPR_END points to the first character after the expression. */ |
ad8d3bb3 | 14375 | |
5e0116d5 | 14376 | static size_t |
17a2f251 TS |
14377 | my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc, |
14378 | char *str) | |
ad8d3bb3 | 14379 | { |
5e0116d5 RS |
14380 | bfd_reloc_code_real_type reversed_reloc[3]; |
14381 | size_t reloc_index, i; | |
09b8f35a RS |
14382 | int crux_depth, str_depth; |
14383 | char *crux; | |
5e0116d5 RS |
14384 | |
14385 | /* Search for the start of the main expression, recoding relocations | |
09b8f35a RS |
14386 | in REVERSED_RELOC. End the loop with CRUX pointing to the start |
14387 | of the main expression and with CRUX_DEPTH containing the number | |
14388 | of open brackets at that point. */ | |
14389 | reloc_index = -1; | |
14390 | str_depth = 0; | |
14391 | do | |
fb1b3232 | 14392 | { |
09b8f35a RS |
14393 | reloc_index++; |
14394 | crux = str; | |
14395 | crux_depth = str_depth; | |
14396 | ||
14397 | /* Skip over whitespace and brackets, keeping count of the number | |
14398 | of brackets. */ | |
14399 | while (*str == ' ' || *str == '\t' || *str == '(') | |
14400 | if (*str++ == '(') | |
14401 | str_depth++; | |
5e0116d5 | 14402 | } |
09b8f35a RS |
14403 | while (*str == '%' |
14404 | && reloc_index < (HAVE_NEWABI ? 3 : 1) | |
14405 | && parse_relocation (&str, &reversed_reloc[reloc_index])); | |
ad8d3bb3 | 14406 | |
09b8f35a | 14407 | my_getExpression (ep, crux); |
5e0116d5 | 14408 | str = expr_end; |
394f9b3a | 14409 | |
5e0116d5 | 14410 | /* Match every open bracket. */ |
09b8f35a | 14411 | while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t')) |
5e0116d5 | 14412 | if (*str++ == ')') |
09b8f35a | 14413 | crux_depth--; |
394f9b3a | 14414 | |
09b8f35a | 14415 | if (crux_depth > 0) |
20203fb9 | 14416 | as_bad (_("unclosed '('")); |
394f9b3a | 14417 | |
5e0116d5 | 14418 | expr_end = str; |
252b5132 | 14419 | |
01a3f561 | 14420 | if (reloc_index != 0) |
64bdfcaf RS |
14421 | { |
14422 | prev_reloc_op_frag = frag_now; | |
14423 | for (i = 0; i < reloc_index; i++) | |
14424 | reloc[i] = reversed_reloc[reloc_index - 1 - i]; | |
14425 | } | |
fb1b3232 | 14426 | |
5e0116d5 | 14427 | return reloc_index; |
252b5132 RH |
14428 | } |
14429 | ||
14430 | static void | |
17a2f251 | 14431 | my_getExpression (expressionS *ep, char *str) |
252b5132 RH |
14432 | { |
14433 | char *save_in; | |
14434 | ||
14435 | save_in = input_line_pointer; | |
14436 | input_line_pointer = str; | |
14437 | expression (ep); | |
14438 | expr_end = input_line_pointer; | |
14439 | input_line_pointer = save_in; | |
252b5132 RH |
14440 | } |
14441 | ||
252b5132 | 14442 | char * |
17a2f251 | 14443 | md_atof (int type, char *litP, int *sizeP) |
252b5132 | 14444 | { |
499ac353 | 14445 | return ieee_md_atof (type, litP, sizeP, target_big_endian); |
252b5132 RH |
14446 | } |
14447 | ||
14448 | void | |
17a2f251 | 14449 | md_number_to_chars (char *buf, valueT val, int n) |
252b5132 RH |
14450 | { |
14451 | if (target_big_endian) | |
14452 | number_to_chars_bigendian (buf, val, n); | |
14453 | else | |
14454 | number_to_chars_littleendian (buf, val, n); | |
14455 | } | |
14456 | \f | |
ae948b86 | 14457 | #ifdef OBJ_ELF |
e013f690 TS |
14458 | static int support_64bit_objects(void) |
14459 | { | |
14460 | const char **list, **l; | |
aa3d8fdf | 14461 | int yes; |
e013f690 TS |
14462 | |
14463 | list = bfd_target_list (); | |
14464 | for (l = list; *l != NULL; l++) | |
aeffff67 RS |
14465 | if (strcmp (*l, ELF_TARGET ("elf64-", "big")) == 0 |
14466 | || strcmp (*l, ELF_TARGET ("elf64-", "little")) == 0) | |
e013f690 | 14467 | break; |
aa3d8fdf | 14468 | yes = (*l != NULL); |
e013f690 | 14469 | free (list); |
aa3d8fdf | 14470 | return yes; |
e013f690 | 14471 | } |
ae948b86 | 14472 | #endif /* OBJ_ELF */ |
e013f690 | 14473 | |
78849248 | 14474 | const char *md_shortopts = "O::g::G:"; |
252b5132 | 14475 | |
23fce1e3 NC |
14476 | enum options |
14477 | { | |
14478 | OPTION_MARCH = OPTION_MD_BASE, | |
14479 | OPTION_MTUNE, | |
14480 | OPTION_MIPS1, | |
14481 | OPTION_MIPS2, | |
14482 | OPTION_MIPS3, | |
14483 | OPTION_MIPS4, | |
14484 | OPTION_MIPS5, | |
14485 | OPTION_MIPS32, | |
14486 | OPTION_MIPS64, | |
14487 | OPTION_MIPS32R2, | |
14488 | OPTION_MIPS64R2, | |
14489 | OPTION_MIPS16, | |
14490 | OPTION_NO_MIPS16, | |
14491 | OPTION_MIPS3D, | |
14492 | OPTION_NO_MIPS3D, | |
14493 | OPTION_MDMX, | |
14494 | OPTION_NO_MDMX, | |
14495 | OPTION_DSP, | |
14496 | OPTION_NO_DSP, | |
14497 | OPTION_MT, | |
14498 | OPTION_NO_MT, | |
14499 | OPTION_SMARTMIPS, | |
14500 | OPTION_NO_SMARTMIPS, | |
14501 | OPTION_DSPR2, | |
14502 | OPTION_NO_DSPR2, | |
df58fc94 RS |
14503 | OPTION_MICROMIPS, |
14504 | OPTION_NO_MICROMIPS, | |
dec0624d MR |
14505 | OPTION_MCU, |
14506 | OPTION_NO_MCU, | |
23fce1e3 NC |
14507 | OPTION_COMPAT_ARCH_BASE, |
14508 | OPTION_M4650, | |
14509 | OPTION_NO_M4650, | |
14510 | OPTION_M4010, | |
14511 | OPTION_NO_M4010, | |
14512 | OPTION_M4100, | |
14513 | OPTION_NO_M4100, | |
14514 | OPTION_M3900, | |
14515 | OPTION_NO_M3900, | |
14516 | OPTION_M7000_HILO_FIX, | |
6a32d874 CM |
14517 | OPTION_MNO_7000_HILO_FIX, |
14518 | OPTION_FIX_24K, | |
14519 | OPTION_NO_FIX_24K, | |
c67a084a NC |
14520 | OPTION_FIX_LOONGSON2F_JUMP, |
14521 | OPTION_NO_FIX_LOONGSON2F_JUMP, | |
14522 | OPTION_FIX_LOONGSON2F_NOP, | |
14523 | OPTION_NO_FIX_LOONGSON2F_NOP, | |
23fce1e3 NC |
14524 | OPTION_FIX_VR4120, |
14525 | OPTION_NO_FIX_VR4120, | |
14526 | OPTION_FIX_VR4130, | |
14527 | OPTION_NO_FIX_VR4130, | |
d954098f DD |
14528 | OPTION_FIX_CN63XXP1, |
14529 | OPTION_NO_FIX_CN63XXP1, | |
23fce1e3 NC |
14530 | OPTION_TRAP, |
14531 | OPTION_BREAK, | |
14532 | OPTION_EB, | |
14533 | OPTION_EL, | |
14534 | OPTION_FP32, | |
14535 | OPTION_GP32, | |
14536 | OPTION_CONSTRUCT_FLOATS, | |
14537 | OPTION_NO_CONSTRUCT_FLOATS, | |
14538 | OPTION_FP64, | |
14539 | OPTION_GP64, | |
14540 | OPTION_RELAX_BRANCH, | |
14541 | OPTION_NO_RELAX_BRANCH, | |
14542 | OPTION_MSHARED, | |
14543 | OPTION_MNO_SHARED, | |
14544 | OPTION_MSYM32, | |
14545 | OPTION_MNO_SYM32, | |
14546 | OPTION_SOFT_FLOAT, | |
14547 | OPTION_HARD_FLOAT, | |
14548 | OPTION_SINGLE_FLOAT, | |
14549 | OPTION_DOUBLE_FLOAT, | |
14550 | OPTION_32, | |
14551 | #ifdef OBJ_ELF | |
14552 | OPTION_CALL_SHARED, | |
14553 | OPTION_CALL_NONPIC, | |
14554 | OPTION_NON_SHARED, | |
14555 | OPTION_XGOT, | |
14556 | OPTION_MABI, | |
14557 | OPTION_N32, | |
14558 | OPTION_64, | |
14559 | OPTION_MDEBUG, | |
14560 | OPTION_NO_MDEBUG, | |
14561 | OPTION_PDR, | |
14562 | OPTION_NO_PDR, | |
14563 | OPTION_MVXWORKS_PIC, | |
14564 | #endif /* OBJ_ELF */ | |
14565 | OPTION_END_OF_ENUM | |
14566 | }; | |
14567 | ||
e972090a NC |
14568 | struct option md_longopts[] = |
14569 | { | |
f9b4148d | 14570 | /* Options which specify architecture. */ |
f9b4148d | 14571 | {"march", required_argument, NULL, OPTION_MARCH}, |
f9b4148d | 14572 | {"mtune", required_argument, NULL, OPTION_MTUNE}, |
252b5132 RH |
14573 | {"mips0", no_argument, NULL, OPTION_MIPS1}, |
14574 | {"mips1", no_argument, NULL, OPTION_MIPS1}, | |
252b5132 | 14575 | {"mips2", no_argument, NULL, OPTION_MIPS2}, |
252b5132 | 14576 | {"mips3", no_argument, NULL, OPTION_MIPS3}, |
252b5132 | 14577 | {"mips4", no_argument, NULL, OPTION_MIPS4}, |
ae948b86 | 14578 | {"mips5", no_argument, NULL, OPTION_MIPS5}, |
ae948b86 | 14579 | {"mips32", no_argument, NULL, OPTION_MIPS32}, |
ae948b86 | 14580 | {"mips64", no_argument, NULL, OPTION_MIPS64}, |
f9b4148d | 14581 | {"mips32r2", no_argument, NULL, OPTION_MIPS32R2}, |
5f74bc13 | 14582 | {"mips64r2", no_argument, NULL, OPTION_MIPS64R2}, |
f9b4148d CD |
14583 | |
14584 | /* Options which specify Application Specific Extensions (ASEs). */ | |
f9b4148d | 14585 | {"mips16", no_argument, NULL, OPTION_MIPS16}, |
f9b4148d | 14586 | {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16}, |
f9b4148d | 14587 | {"mips3d", no_argument, NULL, OPTION_MIPS3D}, |
f9b4148d | 14588 | {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D}, |
f9b4148d | 14589 | {"mdmx", no_argument, NULL, OPTION_MDMX}, |
f9b4148d | 14590 | {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX}, |
74cd071d | 14591 | {"mdsp", no_argument, NULL, OPTION_DSP}, |
74cd071d | 14592 | {"mno-dsp", no_argument, NULL, OPTION_NO_DSP}, |
ef2e4d86 | 14593 | {"mmt", no_argument, NULL, OPTION_MT}, |
ef2e4d86 | 14594 | {"mno-mt", no_argument, NULL, OPTION_NO_MT}, |
e16bfa71 | 14595 | {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS}, |
e16bfa71 | 14596 | {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS}, |
8b082fb1 | 14597 | {"mdspr2", no_argument, NULL, OPTION_DSPR2}, |
8b082fb1 | 14598 | {"mno-dspr2", no_argument, NULL, OPTION_NO_DSPR2}, |
df58fc94 RS |
14599 | {"mmicromips", no_argument, NULL, OPTION_MICROMIPS}, |
14600 | {"mno-micromips", no_argument, NULL, OPTION_NO_MICROMIPS}, | |
dec0624d MR |
14601 | {"mmcu", no_argument, NULL, OPTION_MCU}, |
14602 | {"mno-mcu", no_argument, NULL, OPTION_NO_MCU}, | |
f9b4148d CD |
14603 | |
14604 | /* Old-style architecture options. Don't add more of these. */ | |
f9b4148d | 14605 | {"m4650", no_argument, NULL, OPTION_M4650}, |
f9b4148d | 14606 | {"no-m4650", no_argument, NULL, OPTION_NO_M4650}, |
f9b4148d | 14607 | {"m4010", no_argument, NULL, OPTION_M4010}, |
f9b4148d | 14608 | {"no-m4010", no_argument, NULL, OPTION_NO_M4010}, |
f9b4148d | 14609 | {"m4100", no_argument, NULL, OPTION_M4100}, |
f9b4148d | 14610 | {"no-m4100", no_argument, NULL, OPTION_NO_M4100}, |
f9b4148d | 14611 | {"m3900", no_argument, NULL, OPTION_M3900}, |
f9b4148d CD |
14612 | {"no-m3900", no_argument, NULL, OPTION_NO_M3900}, |
14613 | ||
14614 | /* Options which enable bug fixes. */ | |
f9b4148d | 14615 | {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX}, |
f9b4148d CD |
14616 | {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX}, |
14617 | {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX}, | |
c67a084a NC |
14618 | {"mfix-loongson2f-jump", no_argument, NULL, OPTION_FIX_LOONGSON2F_JUMP}, |
14619 | {"mno-fix-loongson2f-jump", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_JUMP}, | |
14620 | {"mfix-loongson2f-nop", no_argument, NULL, OPTION_FIX_LOONGSON2F_NOP}, | |
14621 | {"mno-fix-loongson2f-nop", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_NOP}, | |
d766e8ec RS |
14622 | {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120}, |
14623 | {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120}, | |
7d8e00cf RS |
14624 | {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130}, |
14625 | {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130}, | |
6a32d874 CM |
14626 | {"mfix-24k", no_argument, NULL, OPTION_FIX_24K}, |
14627 | {"mno-fix-24k", no_argument, NULL, OPTION_NO_FIX_24K}, | |
d954098f DD |
14628 | {"mfix-cn63xxp1", no_argument, NULL, OPTION_FIX_CN63XXP1}, |
14629 | {"mno-fix-cn63xxp1", no_argument, NULL, OPTION_NO_FIX_CN63XXP1}, | |
f9b4148d CD |
14630 | |
14631 | /* Miscellaneous options. */ | |
252b5132 RH |
14632 | {"trap", no_argument, NULL, OPTION_TRAP}, |
14633 | {"no-break", no_argument, NULL, OPTION_TRAP}, | |
252b5132 RH |
14634 | {"break", no_argument, NULL, OPTION_BREAK}, |
14635 | {"no-trap", no_argument, NULL, OPTION_BREAK}, | |
252b5132 | 14636 | {"EB", no_argument, NULL, OPTION_EB}, |
252b5132 | 14637 | {"EL", no_argument, NULL, OPTION_EL}, |
ae948b86 | 14638 | {"mfp32", no_argument, NULL, OPTION_FP32}, |
c97ef257 | 14639 | {"mgp32", no_argument, NULL, OPTION_GP32}, |
119d663a | 14640 | {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS}, |
119d663a | 14641 | {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS}, |
316f5878 | 14642 | {"mfp64", no_argument, NULL, OPTION_FP64}, |
ae948b86 | 14643 | {"mgp64", no_argument, NULL, OPTION_GP64}, |
4a6a3df4 AO |
14644 | {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH}, |
14645 | {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH}, | |
aa6975fb ILT |
14646 | {"mshared", no_argument, NULL, OPTION_MSHARED}, |
14647 | {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED}, | |
aed1a261 RS |
14648 | {"msym32", no_argument, NULL, OPTION_MSYM32}, |
14649 | {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32}, | |
037b32b9 AN |
14650 | {"msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT}, |
14651 | {"mhard-float", no_argument, NULL, OPTION_HARD_FLOAT}, | |
037b32b9 AN |
14652 | {"msingle-float", no_argument, NULL, OPTION_SINGLE_FLOAT}, |
14653 | {"mdouble-float", no_argument, NULL, OPTION_DOUBLE_FLOAT}, | |
23fce1e3 NC |
14654 | |
14655 | /* Strictly speaking this next option is ELF specific, | |
14656 | but we allow it for other ports as well in order to | |
14657 | make testing easier. */ | |
14658 | {"32", no_argument, NULL, OPTION_32}, | |
037b32b9 | 14659 | |
f9b4148d | 14660 | /* ELF-specific options. */ |
156c2f8b | 14661 | #ifdef OBJ_ELF |
156c2f8b NC |
14662 | {"KPIC", no_argument, NULL, OPTION_CALL_SHARED}, |
14663 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, | |
861fb55a | 14664 | {"call_nonpic", no_argument, NULL, OPTION_CALL_NONPIC}, |
156c2f8b NC |
14665 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, |
14666 | {"xgot", no_argument, NULL, OPTION_XGOT}, | |
ae948b86 | 14667 | {"mabi", required_argument, NULL, OPTION_MABI}, |
e013f690 | 14668 | {"n32", no_argument, NULL, OPTION_N32}, |
156c2f8b | 14669 | {"64", no_argument, NULL, OPTION_64}, |
ecb4347a | 14670 | {"mdebug", no_argument, NULL, OPTION_MDEBUG}, |
ecb4347a | 14671 | {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG}, |
dcd410fe | 14672 | {"mpdr", no_argument, NULL, OPTION_PDR}, |
dcd410fe | 14673 | {"mno-pdr", no_argument, NULL, OPTION_NO_PDR}, |
0a44bf69 | 14674 | {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC}, |
ae948b86 | 14675 | #endif /* OBJ_ELF */ |
f9b4148d | 14676 | |
252b5132 RH |
14677 | {NULL, no_argument, NULL, 0} |
14678 | }; | |
156c2f8b | 14679 | size_t md_longopts_size = sizeof (md_longopts); |
252b5132 | 14680 | |
316f5878 RS |
14681 | /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to |
14682 | NEW_VALUE. Warn if another value was already specified. Note: | |
14683 | we have to defer parsing the -march and -mtune arguments in order | |
14684 | to handle 'from-abi' correctly, since the ABI might be specified | |
14685 | in a later argument. */ | |
14686 | ||
14687 | static void | |
17a2f251 | 14688 | mips_set_option_string (const char **string_ptr, const char *new_value) |
316f5878 RS |
14689 | { |
14690 | if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0) | |
14691 | as_warn (_("A different %s was already specified, is now %s"), | |
14692 | string_ptr == &mips_arch_string ? "-march" : "-mtune", | |
14693 | new_value); | |
14694 | ||
14695 | *string_ptr = new_value; | |
14696 | } | |
14697 | ||
252b5132 | 14698 | int |
17a2f251 | 14699 | md_parse_option (int c, char *arg) |
252b5132 RH |
14700 | { |
14701 | switch (c) | |
14702 | { | |
119d663a NC |
14703 | case OPTION_CONSTRUCT_FLOATS: |
14704 | mips_disable_float_construction = 0; | |
14705 | break; | |
bdaaa2e1 | 14706 | |
119d663a NC |
14707 | case OPTION_NO_CONSTRUCT_FLOATS: |
14708 | mips_disable_float_construction = 1; | |
14709 | break; | |
bdaaa2e1 | 14710 | |
252b5132 RH |
14711 | case OPTION_TRAP: |
14712 | mips_trap = 1; | |
14713 | break; | |
14714 | ||
14715 | case OPTION_BREAK: | |
14716 | mips_trap = 0; | |
14717 | break; | |
14718 | ||
14719 | case OPTION_EB: | |
14720 | target_big_endian = 1; | |
14721 | break; | |
14722 | ||
14723 | case OPTION_EL: | |
14724 | target_big_endian = 0; | |
14725 | break; | |
14726 | ||
14727 | case 'O': | |
4ffff32f TS |
14728 | if (arg == NULL) |
14729 | mips_optimize = 1; | |
14730 | else if (arg[0] == '0') | |
14731 | mips_optimize = 0; | |
14732 | else if (arg[0] == '1') | |
252b5132 RH |
14733 | mips_optimize = 1; |
14734 | else | |
14735 | mips_optimize = 2; | |
14736 | break; | |
14737 | ||
14738 | case 'g': | |
14739 | if (arg == NULL) | |
14740 | mips_debug = 2; | |
14741 | else | |
14742 | mips_debug = atoi (arg); | |
252b5132 RH |
14743 | break; |
14744 | ||
14745 | case OPTION_MIPS1: | |
316f5878 | 14746 | file_mips_isa = ISA_MIPS1; |
252b5132 RH |
14747 | break; |
14748 | ||
14749 | case OPTION_MIPS2: | |
316f5878 | 14750 | file_mips_isa = ISA_MIPS2; |
252b5132 RH |
14751 | break; |
14752 | ||
14753 | case OPTION_MIPS3: | |
316f5878 | 14754 | file_mips_isa = ISA_MIPS3; |
252b5132 RH |
14755 | break; |
14756 | ||
14757 | case OPTION_MIPS4: | |
316f5878 | 14758 | file_mips_isa = ISA_MIPS4; |
e7af610e NC |
14759 | break; |
14760 | ||
84ea6cf2 | 14761 | case OPTION_MIPS5: |
316f5878 | 14762 | file_mips_isa = ISA_MIPS5; |
84ea6cf2 NC |
14763 | break; |
14764 | ||
e7af610e | 14765 | case OPTION_MIPS32: |
316f5878 | 14766 | file_mips_isa = ISA_MIPS32; |
252b5132 RH |
14767 | break; |
14768 | ||
af7ee8bf CD |
14769 | case OPTION_MIPS32R2: |
14770 | file_mips_isa = ISA_MIPS32R2; | |
14771 | break; | |
14772 | ||
5f74bc13 CD |
14773 | case OPTION_MIPS64R2: |
14774 | file_mips_isa = ISA_MIPS64R2; | |
14775 | break; | |
14776 | ||
84ea6cf2 | 14777 | case OPTION_MIPS64: |
316f5878 | 14778 | file_mips_isa = ISA_MIPS64; |
84ea6cf2 NC |
14779 | break; |
14780 | ||
ec68c924 | 14781 | case OPTION_MTUNE: |
316f5878 RS |
14782 | mips_set_option_string (&mips_tune_string, arg); |
14783 | break; | |
ec68c924 | 14784 | |
316f5878 RS |
14785 | case OPTION_MARCH: |
14786 | mips_set_option_string (&mips_arch_string, arg); | |
252b5132 RH |
14787 | break; |
14788 | ||
14789 | case OPTION_M4650: | |
316f5878 RS |
14790 | mips_set_option_string (&mips_arch_string, "4650"); |
14791 | mips_set_option_string (&mips_tune_string, "4650"); | |
252b5132 RH |
14792 | break; |
14793 | ||
14794 | case OPTION_NO_M4650: | |
14795 | break; | |
14796 | ||
14797 | case OPTION_M4010: | |
316f5878 RS |
14798 | mips_set_option_string (&mips_arch_string, "4010"); |
14799 | mips_set_option_string (&mips_tune_string, "4010"); | |
252b5132 RH |
14800 | break; |
14801 | ||
14802 | case OPTION_NO_M4010: | |
14803 | break; | |
14804 | ||
14805 | case OPTION_M4100: | |
316f5878 RS |
14806 | mips_set_option_string (&mips_arch_string, "4100"); |
14807 | mips_set_option_string (&mips_tune_string, "4100"); | |
252b5132 RH |
14808 | break; |
14809 | ||
14810 | case OPTION_NO_M4100: | |
14811 | break; | |
14812 | ||
252b5132 | 14813 | case OPTION_M3900: |
316f5878 RS |
14814 | mips_set_option_string (&mips_arch_string, "3900"); |
14815 | mips_set_option_string (&mips_tune_string, "3900"); | |
252b5132 | 14816 | break; |
bdaaa2e1 | 14817 | |
252b5132 RH |
14818 | case OPTION_NO_M3900: |
14819 | break; | |
14820 | ||
deec1734 CD |
14821 | case OPTION_MDMX: |
14822 | mips_opts.ase_mdmx = 1; | |
14823 | break; | |
14824 | ||
14825 | case OPTION_NO_MDMX: | |
14826 | mips_opts.ase_mdmx = 0; | |
14827 | break; | |
14828 | ||
74cd071d CF |
14829 | case OPTION_DSP: |
14830 | mips_opts.ase_dsp = 1; | |
8b082fb1 | 14831 | mips_opts.ase_dspr2 = 0; |
74cd071d CF |
14832 | break; |
14833 | ||
14834 | case OPTION_NO_DSP: | |
8b082fb1 TS |
14835 | mips_opts.ase_dsp = 0; |
14836 | mips_opts.ase_dspr2 = 0; | |
14837 | break; | |
14838 | ||
14839 | case OPTION_DSPR2: | |
14840 | mips_opts.ase_dspr2 = 1; | |
14841 | mips_opts.ase_dsp = 1; | |
14842 | break; | |
14843 | ||
14844 | case OPTION_NO_DSPR2: | |
14845 | mips_opts.ase_dspr2 = 0; | |
74cd071d CF |
14846 | mips_opts.ase_dsp = 0; |
14847 | break; | |
14848 | ||
ef2e4d86 CF |
14849 | case OPTION_MT: |
14850 | mips_opts.ase_mt = 1; | |
14851 | break; | |
14852 | ||
14853 | case OPTION_NO_MT: | |
14854 | mips_opts.ase_mt = 0; | |
14855 | break; | |
14856 | ||
dec0624d MR |
14857 | case OPTION_MCU: |
14858 | mips_opts.ase_mcu = 1; | |
14859 | break; | |
14860 | ||
14861 | case OPTION_NO_MCU: | |
14862 | mips_opts.ase_mcu = 0; | |
14863 | break; | |
14864 | ||
df58fc94 RS |
14865 | case OPTION_MICROMIPS: |
14866 | if (mips_opts.mips16 == 1) | |
14867 | { | |
14868 | as_bad (_("-mmicromips cannot be used with -mips16")); | |
14869 | return 0; | |
14870 | } | |
14871 | mips_opts.micromips = 1; | |
14872 | mips_no_prev_insn (); | |
14873 | break; | |
14874 | ||
14875 | case OPTION_NO_MICROMIPS: | |
14876 | mips_opts.micromips = 0; | |
14877 | mips_no_prev_insn (); | |
14878 | break; | |
14879 | ||
252b5132 | 14880 | case OPTION_MIPS16: |
df58fc94 RS |
14881 | if (mips_opts.micromips == 1) |
14882 | { | |
14883 | as_bad (_("-mips16 cannot be used with -micromips")); | |
14884 | return 0; | |
14885 | } | |
252b5132 | 14886 | mips_opts.mips16 = 1; |
7d10b47d | 14887 | mips_no_prev_insn (); |
252b5132 RH |
14888 | break; |
14889 | ||
14890 | case OPTION_NO_MIPS16: | |
14891 | mips_opts.mips16 = 0; | |
7d10b47d | 14892 | mips_no_prev_insn (); |
252b5132 RH |
14893 | break; |
14894 | ||
1f25f5d3 CD |
14895 | case OPTION_MIPS3D: |
14896 | mips_opts.ase_mips3d = 1; | |
14897 | break; | |
14898 | ||
14899 | case OPTION_NO_MIPS3D: | |
14900 | mips_opts.ase_mips3d = 0; | |
14901 | break; | |
14902 | ||
e16bfa71 TS |
14903 | case OPTION_SMARTMIPS: |
14904 | mips_opts.ase_smartmips = 1; | |
14905 | break; | |
14906 | ||
14907 | case OPTION_NO_SMARTMIPS: | |
14908 | mips_opts.ase_smartmips = 0; | |
14909 | break; | |
14910 | ||
6a32d874 CM |
14911 | case OPTION_FIX_24K: |
14912 | mips_fix_24k = 1; | |
14913 | break; | |
14914 | ||
14915 | case OPTION_NO_FIX_24K: | |
14916 | mips_fix_24k = 0; | |
14917 | break; | |
14918 | ||
c67a084a NC |
14919 | case OPTION_FIX_LOONGSON2F_JUMP: |
14920 | mips_fix_loongson2f_jump = TRUE; | |
14921 | break; | |
14922 | ||
14923 | case OPTION_NO_FIX_LOONGSON2F_JUMP: | |
14924 | mips_fix_loongson2f_jump = FALSE; | |
14925 | break; | |
14926 | ||
14927 | case OPTION_FIX_LOONGSON2F_NOP: | |
14928 | mips_fix_loongson2f_nop = TRUE; | |
14929 | break; | |
14930 | ||
14931 | case OPTION_NO_FIX_LOONGSON2F_NOP: | |
14932 | mips_fix_loongson2f_nop = FALSE; | |
14933 | break; | |
14934 | ||
d766e8ec RS |
14935 | case OPTION_FIX_VR4120: |
14936 | mips_fix_vr4120 = 1; | |
60b63b72 RS |
14937 | break; |
14938 | ||
d766e8ec RS |
14939 | case OPTION_NO_FIX_VR4120: |
14940 | mips_fix_vr4120 = 0; | |
60b63b72 RS |
14941 | break; |
14942 | ||
7d8e00cf RS |
14943 | case OPTION_FIX_VR4130: |
14944 | mips_fix_vr4130 = 1; | |
14945 | break; | |
14946 | ||
14947 | case OPTION_NO_FIX_VR4130: | |
14948 | mips_fix_vr4130 = 0; | |
14949 | break; | |
14950 | ||
d954098f DD |
14951 | case OPTION_FIX_CN63XXP1: |
14952 | mips_fix_cn63xxp1 = TRUE; | |
14953 | break; | |
14954 | ||
14955 | case OPTION_NO_FIX_CN63XXP1: | |
14956 | mips_fix_cn63xxp1 = FALSE; | |
14957 | break; | |
14958 | ||
4a6a3df4 AO |
14959 | case OPTION_RELAX_BRANCH: |
14960 | mips_relax_branch = 1; | |
14961 | break; | |
14962 | ||
14963 | case OPTION_NO_RELAX_BRANCH: | |
14964 | mips_relax_branch = 0; | |
14965 | break; | |
14966 | ||
aa6975fb ILT |
14967 | case OPTION_MSHARED: |
14968 | mips_in_shared = TRUE; | |
14969 | break; | |
14970 | ||
14971 | case OPTION_MNO_SHARED: | |
14972 | mips_in_shared = FALSE; | |
14973 | break; | |
14974 | ||
aed1a261 RS |
14975 | case OPTION_MSYM32: |
14976 | mips_opts.sym32 = TRUE; | |
14977 | break; | |
14978 | ||
14979 | case OPTION_MNO_SYM32: | |
14980 | mips_opts.sym32 = FALSE; | |
14981 | break; | |
14982 | ||
0f074f60 | 14983 | #ifdef OBJ_ELF |
252b5132 RH |
14984 | /* When generating ELF code, we permit -KPIC and -call_shared to |
14985 | select SVR4_PIC, and -non_shared to select no PIC. This is | |
14986 | intended to be compatible with Irix 5. */ | |
14987 | case OPTION_CALL_SHARED: | |
f43abd2b | 14988 | if (!IS_ELF) |
252b5132 RH |
14989 | { |
14990 | as_bad (_("-call_shared is supported only for ELF format")); | |
14991 | return 0; | |
14992 | } | |
14993 | mips_pic = SVR4_PIC; | |
143d77c5 | 14994 | mips_abicalls = TRUE; |
252b5132 RH |
14995 | break; |
14996 | ||
861fb55a DJ |
14997 | case OPTION_CALL_NONPIC: |
14998 | if (!IS_ELF) | |
14999 | { | |
15000 | as_bad (_("-call_nonpic is supported only for ELF format")); | |
15001 | return 0; | |
15002 | } | |
15003 | mips_pic = NO_PIC; | |
15004 | mips_abicalls = TRUE; | |
15005 | break; | |
15006 | ||
252b5132 | 15007 | case OPTION_NON_SHARED: |
f43abd2b | 15008 | if (!IS_ELF) |
252b5132 RH |
15009 | { |
15010 | as_bad (_("-non_shared is supported only for ELF format")); | |
15011 | return 0; | |
15012 | } | |
15013 | mips_pic = NO_PIC; | |
143d77c5 | 15014 | mips_abicalls = FALSE; |
252b5132 RH |
15015 | break; |
15016 | ||
44075ae2 TS |
15017 | /* The -xgot option tells the assembler to use 32 bit offsets |
15018 | when accessing the got in SVR4_PIC mode. It is for Irix | |
252b5132 RH |
15019 | compatibility. */ |
15020 | case OPTION_XGOT: | |
15021 | mips_big_got = 1; | |
15022 | break; | |
0f074f60 | 15023 | #endif /* OBJ_ELF */ |
252b5132 RH |
15024 | |
15025 | case 'G': | |
6caf9ef4 TS |
15026 | g_switch_value = atoi (arg); |
15027 | g_switch_seen = 1; | |
252b5132 RH |
15028 | break; |
15029 | ||
34ba82a8 TS |
15030 | /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32 |
15031 | and -mabi=64. */ | |
252b5132 | 15032 | case OPTION_32: |
23fce1e3 NC |
15033 | if (IS_ELF) |
15034 | mips_abi = O32_ABI; | |
15035 | /* We silently ignore -32 for non-ELF targets. This greatly | |
15036 | simplifies the construction of the MIPS GAS test cases. */ | |
252b5132 RH |
15037 | break; |
15038 | ||
23fce1e3 | 15039 | #ifdef OBJ_ELF |
e013f690 | 15040 | case OPTION_N32: |
f43abd2b | 15041 | if (!IS_ELF) |
34ba82a8 TS |
15042 | { |
15043 | as_bad (_("-n32 is supported for ELF format only")); | |
15044 | return 0; | |
15045 | } | |
316f5878 | 15046 | mips_abi = N32_ABI; |
e013f690 | 15047 | break; |
252b5132 | 15048 | |
e013f690 | 15049 | case OPTION_64: |
f43abd2b | 15050 | if (!IS_ELF) |
34ba82a8 TS |
15051 | { |
15052 | as_bad (_("-64 is supported for ELF format only")); | |
15053 | return 0; | |
15054 | } | |
316f5878 | 15055 | mips_abi = N64_ABI; |
f43abd2b | 15056 | if (!support_64bit_objects()) |
e013f690 | 15057 | as_fatal (_("No compiled in support for 64 bit object file format")); |
252b5132 | 15058 | break; |
ae948b86 | 15059 | #endif /* OBJ_ELF */ |
252b5132 | 15060 | |
c97ef257 | 15061 | case OPTION_GP32: |
a325df1d | 15062 | file_mips_gp32 = 1; |
c97ef257 AH |
15063 | break; |
15064 | ||
15065 | case OPTION_GP64: | |
a325df1d | 15066 | file_mips_gp32 = 0; |
c97ef257 | 15067 | break; |
252b5132 | 15068 | |
ca4e0257 | 15069 | case OPTION_FP32: |
a325df1d | 15070 | file_mips_fp32 = 1; |
316f5878 RS |
15071 | break; |
15072 | ||
15073 | case OPTION_FP64: | |
15074 | file_mips_fp32 = 0; | |
ca4e0257 RS |
15075 | break; |
15076 | ||
037b32b9 AN |
15077 | case OPTION_SINGLE_FLOAT: |
15078 | file_mips_single_float = 1; | |
15079 | break; | |
15080 | ||
15081 | case OPTION_DOUBLE_FLOAT: | |
15082 | file_mips_single_float = 0; | |
15083 | break; | |
15084 | ||
15085 | case OPTION_SOFT_FLOAT: | |
15086 | file_mips_soft_float = 1; | |
15087 | break; | |
15088 | ||
15089 | case OPTION_HARD_FLOAT: | |
15090 | file_mips_soft_float = 0; | |
15091 | break; | |
15092 | ||
ae948b86 | 15093 | #ifdef OBJ_ELF |
252b5132 | 15094 | case OPTION_MABI: |
f43abd2b | 15095 | if (!IS_ELF) |
34ba82a8 TS |
15096 | { |
15097 | as_bad (_("-mabi is supported for ELF format only")); | |
15098 | return 0; | |
15099 | } | |
e013f690 | 15100 | if (strcmp (arg, "32") == 0) |
316f5878 | 15101 | mips_abi = O32_ABI; |
e013f690 | 15102 | else if (strcmp (arg, "o64") == 0) |
316f5878 | 15103 | mips_abi = O64_ABI; |
e013f690 | 15104 | else if (strcmp (arg, "n32") == 0) |
316f5878 | 15105 | mips_abi = N32_ABI; |
e013f690 TS |
15106 | else if (strcmp (arg, "64") == 0) |
15107 | { | |
316f5878 | 15108 | mips_abi = N64_ABI; |
e013f690 TS |
15109 | if (! support_64bit_objects()) |
15110 | as_fatal (_("No compiled in support for 64 bit object file " | |
15111 | "format")); | |
15112 | } | |
15113 | else if (strcmp (arg, "eabi") == 0) | |
316f5878 | 15114 | mips_abi = EABI_ABI; |
e013f690 | 15115 | else |
da0e507f TS |
15116 | { |
15117 | as_fatal (_("invalid abi -mabi=%s"), arg); | |
15118 | return 0; | |
15119 | } | |
252b5132 | 15120 | break; |
e013f690 | 15121 | #endif /* OBJ_ELF */ |
252b5132 | 15122 | |
6b76fefe | 15123 | case OPTION_M7000_HILO_FIX: |
b34976b6 | 15124 | mips_7000_hilo_fix = TRUE; |
6b76fefe CM |
15125 | break; |
15126 | ||
9ee72ff1 | 15127 | case OPTION_MNO_7000_HILO_FIX: |
b34976b6 | 15128 | mips_7000_hilo_fix = FALSE; |
6b76fefe CM |
15129 | break; |
15130 | ||
ecb4347a DJ |
15131 | #ifdef OBJ_ELF |
15132 | case OPTION_MDEBUG: | |
b34976b6 | 15133 | mips_flag_mdebug = TRUE; |
ecb4347a DJ |
15134 | break; |
15135 | ||
15136 | case OPTION_NO_MDEBUG: | |
b34976b6 | 15137 | mips_flag_mdebug = FALSE; |
ecb4347a | 15138 | break; |
dcd410fe RO |
15139 | |
15140 | case OPTION_PDR: | |
15141 | mips_flag_pdr = TRUE; | |
15142 | break; | |
15143 | ||
15144 | case OPTION_NO_PDR: | |
15145 | mips_flag_pdr = FALSE; | |
15146 | break; | |
0a44bf69 RS |
15147 | |
15148 | case OPTION_MVXWORKS_PIC: | |
15149 | mips_pic = VXWORKS_PIC; | |
15150 | break; | |
ecb4347a DJ |
15151 | #endif /* OBJ_ELF */ |
15152 | ||
252b5132 RH |
15153 | default: |
15154 | return 0; | |
15155 | } | |
15156 | ||
c67a084a NC |
15157 | mips_fix_loongson2f = mips_fix_loongson2f_nop || mips_fix_loongson2f_jump; |
15158 | ||
252b5132 RH |
15159 | return 1; |
15160 | } | |
316f5878 RS |
15161 | \f |
15162 | /* Set up globals to generate code for the ISA or processor | |
15163 | described by INFO. */ | |
252b5132 | 15164 | |
252b5132 | 15165 | static void |
17a2f251 | 15166 | mips_set_architecture (const struct mips_cpu_info *info) |
252b5132 | 15167 | { |
316f5878 | 15168 | if (info != 0) |
252b5132 | 15169 | { |
fef14a42 TS |
15170 | file_mips_arch = info->cpu; |
15171 | mips_opts.arch = info->cpu; | |
316f5878 | 15172 | mips_opts.isa = info->isa; |
252b5132 | 15173 | } |
252b5132 RH |
15174 | } |
15175 | ||
252b5132 | 15176 | |
316f5878 | 15177 | /* Likewise for tuning. */ |
252b5132 | 15178 | |
316f5878 | 15179 | static void |
17a2f251 | 15180 | mips_set_tune (const struct mips_cpu_info *info) |
316f5878 RS |
15181 | { |
15182 | if (info != 0) | |
fef14a42 | 15183 | mips_tune = info->cpu; |
316f5878 | 15184 | } |
80cc45a5 | 15185 | |
34ba82a8 | 15186 | |
252b5132 | 15187 | void |
17a2f251 | 15188 | mips_after_parse_args (void) |
e9670677 | 15189 | { |
fef14a42 TS |
15190 | const struct mips_cpu_info *arch_info = 0; |
15191 | const struct mips_cpu_info *tune_info = 0; | |
15192 | ||
e9670677 | 15193 | /* GP relative stuff not working for PE */ |
6caf9ef4 | 15194 | if (strncmp (TARGET_OS, "pe", 2) == 0) |
e9670677 | 15195 | { |
6caf9ef4 | 15196 | if (g_switch_seen && g_switch_value != 0) |
e9670677 MR |
15197 | as_bad (_("-G not supported in this configuration.")); |
15198 | g_switch_value = 0; | |
15199 | } | |
15200 | ||
cac012d6 AO |
15201 | if (mips_abi == NO_ABI) |
15202 | mips_abi = MIPS_DEFAULT_ABI; | |
15203 | ||
22923709 RS |
15204 | /* The following code determines the architecture and register size. |
15205 | Similar code was added to GCC 3.3 (see override_options() in | |
15206 | config/mips/mips.c). The GAS and GCC code should be kept in sync | |
15207 | as much as possible. */ | |
e9670677 | 15208 | |
316f5878 | 15209 | if (mips_arch_string != 0) |
fef14a42 | 15210 | arch_info = mips_parse_cpu ("-march", mips_arch_string); |
e9670677 | 15211 | |
316f5878 | 15212 | if (file_mips_isa != ISA_UNKNOWN) |
e9670677 | 15213 | { |
316f5878 | 15214 | /* Handle -mipsN. At this point, file_mips_isa contains the |
fef14a42 | 15215 | ISA level specified by -mipsN, while arch_info->isa contains |
316f5878 | 15216 | the -march selection (if any). */ |
fef14a42 | 15217 | if (arch_info != 0) |
e9670677 | 15218 | { |
316f5878 RS |
15219 | /* -march takes precedence over -mipsN, since it is more descriptive. |
15220 | There's no harm in specifying both as long as the ISA levels | |
15221 | are the same. */ | |
fef14a42 | 15222 | if (file_mips_isa != arch_info->isa) |
316f5878 RS |
15223 | as_bad (_("-%s conflicts with the other architecture options, which imply -%s"), |
15224 | mips_cpu_info_from_isa (file_mips_isa)->name, | |
fef14a42 | 15225 | mips_cpu_info_from_isa (arch_info->isa)->name); |
e9670677 | 15226 | } |
316f5878 | 15227 | else |
fef14a42 | 15228 | arch_info = mips_cpu_info_from_isa (file_mips_isa); |
e9670677 MR |
15229 | } |
15230 | ||
fef14a42 | 15231 | if (arch_info == 0) |
95bfe26e MF |
15232 | { |
15233 | arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT); | |
15234 | gas_assert (arch_info); | |
15235 | } | |
e9670677 | 15236 | |
fef14a42 | 15237 | if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa)) |
20203fb9 | 15238 | as_bad (_("-march=%s is not compatible with the selected ABI"), |
fef14a42 TS |
15239 | arch_info->name); |
15240 | ||
15241 | mips_set_architecture (arch_info); | |
15242 | ||
15243 | /* Optimize for file_mips_arch, unless -mtune selects a different processor. */ | |
15244 | if (mips_tune_string != 0) | |
15245 | tune_info = mips_parse_cpu ("-mtune", mips_tune_string); | |
e9670677 | 15246 | |
fef14a42 TS |
15247 | if (tune_info == 0) |
15248 | mips_set_tune (arch_info); | |
15249 | else | |
15250 | mips_set_tune (tune_info); | |
e9670677 | 15251 | |
316f5878 | 15252 | if (file_mips_gp32 >= 0) |
e9670677 | 15253 | { |
316f5878 RS |
15254 | /* The user specified the size of the integer registers. Make sure |
15255 | it agrees with the ABI and ISA. */ | |
15256 | if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
15257 | as_bad (_("-mgp64 used with a 32-bit processor")); | |
15258 | else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi)) | |
15259 | as_bad (_("-mgp32 used with a 64-bit ABI")); | |
15260 | else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi)) | |
15261 | as_bad (_("-mgp64 used with a 32-bit ABI")); | |
e9670677 MR |
15262 | } |
15263 | else | |
15264 | { | |
316f5878 RS |
15265 | /* Infer the integer register size from the ABI and processor. |
15266 | Restrict ourselves to 32-bit registers if that's all the | |
15267 | processor has, or if the ABI cannot handle 64-bit registers. */ | |
15268 | file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi) | |
15269 | || !ISA_HAS_64BIT_REGS (mips_opts.isa)); | |
e9670677 MR |
15270 | } |
15271 | ||
ad3fea08 TS |
15272 | switch (file_mips_fp32) |
15273 | { | |
15274 | default: | |
15275 | case -1: | |
15276 | /* No user specified float register size. | |
15277 | ??? GAS treats single-float processors as though they had 64-bit | |
15278 | float registers (although it complains when double-precision | |
15279 | instructions are used). As things stand, saying they have 32-bit | |
15280 | registers would lead to spurious "register must be even" messages. | |
15281 | So here we assume float registers are never smaller than the | |
15282 | integer ones. */ | |
15283 | if (file_mips_gp32 == 0) | |
15284 | /* 64-bit integer registers implies 64-bit float registers. */ | |
15285 | file_mips_fp32 = 0; | |
15286 | else if ((mips_opts.ase_mips3d > 0 || mips_opts.ase_mdmx > 0) | |
15287 | && ISA_HAS_64BIT_FPRS (mips_opts.isa)) | |
15288 | /* -mips3d and -mdmx imply 64-bit float registers, if possible. */ | |
15289 | file_mips_fp32 = 0; | |
15290 | else | |
15291 | /* 32-bit float registers. */ | |
15292 | file_mips_fp32 = 1; | |
15293 | break; | |
15294 | ||
15295 | /* The user specified the size of the float registers. Check if it | |
15296 | agrees with the ABI and ISA. */ | |
15297 | case 0: | |
15298 | if (!ISA_HAS_64BIT_FPRS (mips_opts.isa)) | |
15299 | as_bad (_("-mfp64 used with a 32-bit fpu")); | |
15300 | else if (ABI_NEEDS_32BIT_REGS (mips_abi) | |
15301 | && !ISA_HAS_MXHC1 (mips_opts.isa)) | |
15302 | as_warn (_("-mfp64 used with a 32-bit ABI")); | |
15303 | break; | |
15304 | case 1: | |
15305 | if (ABI_NEEDS_64BIT_REGS (mips_abi)) | |
15306 | as_warn (_("-mfp32 used with a 64-bit ABI")); | |
15307 | break; | |
15308 | } | |
e9670677 | 15309 | |
316f5878 | 15310 | /* End of GCC-shared inference code. */ |
e9670677 | 15311 | |
17a2f251 TS |
15312 | /* This flag is set when we have a 64-bit capable CPU but use only |
15313 | 32-bit wide registers. Note that EABI does not use it. */ | |
15314 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) | |
15315 | && ((mips_abi == NO_ABI && file_mips_gp32 == 1) | |
15316 | || mips_abi == O32_ABI)) | |
316f5878 | 15317 | mips_32bitmode = 1; |
e9670677 MR |
15318 | |
15319 | if (mips_opts.isa == ISA_MIPS1 && mips_trap) | |
15320 | as_bad (_("trap exception not supported at ISA 1")); | |
15321 | ||
e9670677 MR |
15322 | /* If the selected architecture includes support for ASEs, enable |
15323 | generation of code for them. */ | |
a4672219 | 15324 | if (mips_opts.mips16 == -1) |
fef14a42 | 15325 | mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0; |
df58fc94 RS |
15326 | if (mips_opts.micromips == -1) |
15327 | mips_opts.micromips = (CPU_HAS_MICROMIPS (file_mips_arch)) ? 1 : 0; | |
ffdefa66 | 15328 | if (mips_opts.ase_mips3d == -1) |
65263ce3 | 15329 | mips_opts.ase_mips3d = ((arch_info->flags & MIPS_CPU_ASE_MIPS3D) |
ad3fea08 TS |
15330 | && file_mips_fp32 == 0) ? 1 : 0; |
15331 | if (mips_opts.ase_mips3d && file_mips_fp32 == 1) | |
15332 | as_bad (_("-mfp32 used with -mips3d")); | |
15333 | ||
ffdefa66 | 15334 | if (mips_opts.ase_mdmx == -1) |
65263ce3 | 15335 | mips_opts.ase_mdmx = ((arch_info->flags & MIPS_CPU_ASE_MDMX) |
ad3fea08 TS |
15336 | && file_mips_fp32 == 0) ? 1 : 0; |
15337 | if (mips_opts.ase_mdmx && file_mips_fp32 == 1) | |
15338 | as_bad (_("-mfp32 used with -mdmx")); | |
15339 | ||
15340 | if (mips_opts.ase_smartmips == -1) | |
15341 | mips_opts.ase_smartmips = (arch_info->flags & MIPS_CPU_ASE_SMARTMIPS) ? 1 : 0; | |
15342 | if (mips_opts.ase_smartmips && !ISA_SUPPORTS_SMARTMIPS) | |
20203fb9 NC |
15343 | as_warn (_("%s ISA does not support SmartMIPS"), |
15344 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
ad3fea08 | 15345 | |
74cd071d | 15346 | if (mips_opts.ase_dsp == -1) |
ad3fea08 TS |
15347 | mips_opts.ase_dsp = (arch_info->flags & MIPS_CPU_ASE_DSP) ? 1 : 0; |
15348 | if (mips_opts.ase_dsp && !ISA_SUPPORTS_DSP_ASE) | |
20203fb9 NC |
15349 | as_warn (_("%s ISA does not support DSP ASE"), |
15350 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
ad3fea08 | 15351 | |
8b082fb1 TS |
15352 | if (mips_opts.ase_dspr2 == -1) |
15353 | { | |
15354 | mips_opts.ase_dspr2 = (arch_info->flags & MIPS_CPU_ASE_DSPR2) ? 1 : 0; | |
15355 | mips_opts.ase_dsp = (arch_info->flags & MIPS_CPU_ASE_DSP) ? 1 : 0; | |
15356 | } | |
15357 | if (mips_opts.ase_dspr2 && !ISA_SUPPORTS_DSPR2_ASE) | |
20203fb9 NC |
15358 | as_warn (_("%s ISA does not support DSP R2 ASE"), |
15359 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
8b082fb1 | 15360 | |
ef2e4d86 | 15361 | if (mips_opts.ase_mt == -1) |
ad3fea08 TS |
15362 | mips_opts.ase_mt = (arch_info->flags & MIPS_CPU_ASE_MT) ? 1 : 0; |
15363 | if (mips_opts.ase_mt && !ISA_SUPPORTS_MT_ASE) | |
20203fb9 NC |
15364 | as_warn (_("%s ISA does not support MT ASE"), |
15365 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
e9670677 | 15366 | |
dec0624d MR |
15367 | if (mips_opts.ase_mcu == -1) |
15368 | mips_opts.ase_mcu = (arch_info->flags & MIPS_CPU_ASE_MCU) ? 1 : 0; | |
15369 | if (mips_opts.ase_mcu && !ISA_SUPPORTS_MCU_ASE) | |
15370 | as_warn (_("%s ISA does not support MCU ASE"), | |
15371 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
15372 | ||
e9670677 | 15373 | file_mips_isa = mips_opts.isa; |
e9670677 MR |
15374 | file_ase_mips3d = mips_opts.ase_mips3d; |
15375 | file_ase_mdmx = mips_opts.ase_mdmx; | |
e16bfa71 | 15376 | file_ase_smartmips = mips_opts.ase_smartmips; |
74cd071d | 15377 | file_ase_dsp = mips_opts.ase_dsp; |
8b082fb1 | 15378 | file_ase_dspr2 = mips_opts.ase_dspr2; |
ef2e4d86 | 15379 | file_ase_mt = mips_opts.ase_mt; |
e9670677 MR |
15380 | mips_opts.gp32 = file_mips_gp32; |
15381 | mips_opts.fp32 = file_mips_fp32; | |
037b32b9 AN |
15382 | mips_opts.soft_float = file_mips_soft_float; |
15383 | mips_opts.single_float = file_mips_single_float; | |
e9670677 | 15384 | |
ecb4347a DJ |
15385 | if (mips_flag_mdebug < 0) |
15386 | { | |
15387 | #ifdef OBJ_MAYBE_ECOFF | |
15388 | if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour) | |
15389 | mips_flag_mdebug = 1; | |
15390 | else | |
15391 | #endif /* OBJ_MAYBE_ECOFF */ | |
15392 | mips_flag_mdebug = 0; | |
15393 | } | |
e9670677 MR |
15394 | } |
15395 | \f | |
15396 | void | |
17a2f251 | 15397 | mips_init_after_args (void) |
252b5132 RH |
15398 | { |
15399 | /* initialize opcodes */ | |
15400 | bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes; | |
beae10d5 | 15401 | mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes; |
252b5132 RH |
15402 | } |
15403 | ||
15404 | long | |
17a2f251 | 15405 | md_pcrel_from (fixS *fixP) |
252b5132 | 15406 | { |
a7ebbfdf TS |
15407 | valueT addr = fixP->fx_where + fixP->fx_frag->fr_address; |
15408 | switch (fixP->fx_r_type) | |
15409 | { | |
df58fc94 RS |
15410 | case BFD_RELOC_MICROMIPS_7_PCREL_S1: |
15411 | case BFD_RELOC_MICROMIPS_10_PCREL_S1: | |
15412 | /* Return the address of the delay slot. */ | |
15413 | return addr + 2; | |
15414 | ||
15415 | case BFD_RELOC_MICROMIPS_16_PCREL_S1: | |
15416 | case BFD_RELOC_MICROMIPS_JMP: | |
a7ebbfdf TS |
15417 | case BFD_RELOC_16_PCREL_S2: |
15418 | case BFD_RELOC_MIPS_JMP: | |
15419 | /* Return the address of the delay slot. */ | |
15420 | return addr + 4; | |
df58fc94 | 15421 | |
b47468a6 CM |
15422 | case BFD_RELOC_32_PCREL: |
15423 | return addr; | |
15424 | ||
a7ebbfdf | 15425 | default: |
58ea3d6a | 15426 | /* We have no relocation type for PC relative MIPS16 instructions. */ |
64817874 TS |
15427 | if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != now_seg) |
15428 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
15429 | _("PC relative MIPS16 instruction references a different section")); | |
a7ebbfdf TS |
15430 | return addr; |
15431 | } | |
252b5132 RH |
15432 | } |
15433 | ||
252b5132 RH |
15434 | /* This is called before the symbol table is processed. In order to |
15435 | work with gcc when using mips-tfile, we must keep all local labels. | |
15436 | However, in other cases, we want to discard them. If we were | |
15437 | called with -g, but we didn't see any debugging information, it may | |
15438 | mean that gcc is smuggling debugging information through to | |
15439 | mips-tfile, in which case we must generate all local labels. */ | |
15440 | ||
15441 | void | |
17a2f251 | 15442 | mips_frob_file_before_adjust (void) |
252b5132 RH |
15443 | { |
15444 | #ifndef NO_ECOFF_DEBUGGING | |
15445 | if (ECOFF_DEBUGGING | |
15446 | && mips_debug != 0 | |
15447 | && ! ecoff_debugging_seen) | |
15448 | flag_keep_locals = 1; | |
15449 | #endif | |
15450 | } | |
15451 | ||
3b91255e | 15452 | /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede |
55cf6793 | 15453 | the corresponding LO16 reloc. This is called before md_apply_fix and |
3b91255e RS |
15454 | tc_gen_reloc. Unmatched relocs can only be generated by use of explicit |
15455 | relocation operators. | |
15456 | ||
15457 | For our purposes, a %lo() expression matches a %got() or %hi() | |
15458 | expression if: | |
15459 | ||
15460 | (a) it refers to the same symbol; and | |
15461 | (b) the offset applied in the %lo() expression is no lower than | |
15462 | the offset applied in the %got() or %hi(). | |
15463 | ||
15464 | (b) allows us to cope with code like: | |
15465 | ||
15466 | lui $4,%hi(foo) | |
15467 | lh $4,%lo(foo+2)($4) | |
15468 | ||
15469 | ...which is legal on RELA targets, and has a well-defined behaviour | |
15470 | if the user knows that adding 2 to "foo" will not induce a carry to | |
15471 | the high 16 bits. | |
15472 | ||
15473 | When several %lo()s match a particular %got() or %hi(), we use the | |
15474 | following rules to distinguish them: | |
15475 | ||
15476 | (1) %lo()s with smaller offsets are a better match than %lo()s with | |
15477 | higher offsets. | |
15478 | ||
15479 | (2) %lo()s with no matching %got() or %hi() are better than those | |
15480 | that already have a matching %got() or %hi(). | |
15481 | ||
15482 | (3) later %lo()s are better than earlier %lo()s. | |
15483 | ||
15484 | These rules are applied in order. | |
15485 | ||
15486 | (1) means, among other things, that %lo()s with identical offsets are | |
15487 | chosen if they exist. | |
15488 | ||
15489 | (2) means that we won't associate several high-part relocations with | |
15490 | the same low-part relocation unless there's no alternative. Having | |
15491 | several high parts for the same low part is a GNU extension; this rule | |
15492 | allows careful users to avoid it. | |
15493 | ||
15494 | (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order, | |
15495 | with the last high-part relocation being at the front of the list. | |
15496 | It therefore makes sense to choose the last matching low-part | |
15497 | relocation, all other things being equal. It's also easier | |
15498 | to code that way. */ | |
252b5132 RH |
15499 | |
15500 | void | |
17a2f251 | 15501 | mips_frob_file (void) |
252b5132 RH |
15502 | { |
15503 | struct mips_hi_fixup *l; | |
35903be0 | 15504 | bfd_reloc_code_real_type looking_for_rtype = BFD_RELOC_UNUSED; |
252b5132 RH |
15505 | |
15506 | for (l = mips_hi_fixup_list; l != NULL; l = l->next) | |
15507 | { | |
15508 | segment_info_type *seginfo; | |
3b91255e RS |
15509 | bfd_boolean matched_lo_p; |
15510 | fixS **hi_pos, **lo_pos, **pos; | |
252b5132 | 15511 | |
9c2799c2 | 15512 | gas_assert (reloc_needs_lo_p (l->fixp->fx_r_type)); |
252b5132 | 15513 | |
5919d012 | 15514 | /* If a GOT16 relocation turns out to be against a global symbol, |
b886a2ab RS |
15515 | there isn't supposed to be a matching LO. Ignore %gots against |
15516 | constants; we'll report an error for those later. */ | |
738e5348 | 15517 | if (got16_reloc_p (l->fixp->fx_r_type) |
b886a2ab RS |
15518 | && !(l->fixp->fx_addsy |
15519 | && pic_need_relax (l->fixp->fx_addsy, l->seg))) | |
5919d012 RS |
15520 | continue; |
15521 | ||
15522 | /* Check quickly whether the next fixup happens to be a matching %lo. */ | |
15523 | if (fixup_has_matching_lo_p (l->fixp)) | |
252b5132 RH |
15524 | continue; |
15525 | ||
252b5132 | 15526 | seginfo = seg_info (l->seg); |
252b5132 | 15527 | |
3b91255e RS |
15528 | /* Set HI_POS to the position of this relocation in the chain. |
15529 | Set LO_POS to the position of the chosen low-part relocation. | |
15530 | MATCHED_LO_P is true on entry to the loop if *POS is a low-part | |
15531 | relocation that matches an immediately-preceding high-part | |
15532 | relocation. */ | |
15533 | hi_pos = NULL; | |
15534 | lo_pos = NULL; | |
15535 | matched_lo_p = FALSE; | |
738e5348 | 15536 | looking_for_rtype = matching_lo_reloc (l->fixp->fx_r_type); |
35903be0 | 15537 | |
3b91255e RS |
15538 | for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next) |
15539 | { | |
15540 | if (*pos == l->fixp) | |
15541 | hi_pos = pos; | |
15542 | ||
35903be0 | 15543 | if ((*pos)->fx_r_type == looking_for_rtype |
30cfc97a | 15544 | && symbol_same_p ((*pos)->fx_addsy, l->fixp->fx_addsy) |
3b91255e RS |
15545 | && (*pos)->fx_offset >= l->fixp->fx_offset |
15546 | && (lo_pos == NULL | |
15547 | || (*pos)->fx_offset < (*lo_pos)->fx_offset | |
15548 | || (!matched_lo_p | |
15549 | && (*pos)->fx_offset == (*lo_pos)->fx_offset))) | |
15550 | lo_pos = pos; | |
15551 | ||
15552 | matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type) | |
15553 | && fixup_has_matching_lo_p (*pos)); | |
15554 | } | |
15555 | ||
15556 | /* If we found a match, remove the high-part relocation from its | |
15557 | current position and insert it before the low-part relocation. | |
15558 | Make the offsets match so that fixup_has_matching_lo_p() | |
15559 | will return true. | |
15560 | ||
15561 | We don't warn about unmatched high-part relocations since some | |
15562 | versions of gcc have been known to emit dead "lui ...%hi(...)" | |
15563 | instructions. */ | |
15564 | if (lo_pos != NULL) | |
15565 | { | |
15566 | l->fixp->fx_offset = (*lo_pos)->fx_offset; | |
15567 | if (l->fixp->fx_next != *lo_pos) | |
252b5132 | 15568 | { |
3b91255e RS |
15569 | *hi_pos = l->fixp->fx_next; |
15570 | l->fixp->fx_next = *lo_pos; | |
15571 | *lo_pos = l->fixp; | |
252b5132 | 15572 | } |
252b5132 RH |
15573 | } |
15574 | } | |
15575 | } | |
15576 | ||
252b5132 | 15577 | int |
17a2f251 | 15578 | mips_force_relocation (fixS *fixp) |
252b5132 | 15579 | { |
ae6063d4 | 15580 | if (generic_force_reloc (fixp)) |
252b5132 RH |
15581 | return 1; |
15582 | ||
df58fc94 RS |
15583 | /* We want to keep BFD_RELOC_MICROMIPS_*_PCREL_S1 relocation, |
15584 | so that the linker relaxation can update targets. */ | |
15585 | if (fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1 | |
15586 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1 | |
15587 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1) | |
15588 | return 1; | |
15589 | ||
3e722fb5 | 15590 | return 0; |
252b5132 RH |
15591 | } |
15592 | ||
b886a2ab RS |
15593 | /* Read the instruction associated with RELOC from BUF. */ |
15594 | ||
15595 | static unsigned int | |
15596 | read_reloc_insn (char *buf, bfd_reloc_code_real_type reloc) | |
15597 | { | |
15598 | if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc)) | |
15599 | return read_compressed_insn (buf, 4); | |
15600 | else | |
15601 | return read_insn (buf); | |
15602 | } | |
15603 | ||
15604 | /* Write instruction INSN to BUF, given that it has been relocated | |
15605 | by RELOC. */ | |
15606 | ||
15607 | static void | |
15608 | write_reloc_insn (char *buf, bfd_reloc_code_real_type reloc, | |
15609 | unsigned long insn) | |
15610 | { | |
15611 | if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc)) | |
15612 | write_compressed_insn (buf, insn, 4); | |
15613 | else | |
15614 | write_insn (buf, insn); | |
15615 | } | |
15616 | ||
252b5132 RH |
15617 | /* Apply a fixup to the object file. */ |
15618 | ||
94f592af | 15619 | void |
55cf6793 | 15620 | md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) |
252b5132 | 15621 | { |
4d68580a | 15622 | char *buf; |
b886a2ab | 15623 | unsigned long insn; |
a7ebbfdf | 15624 | reloc_howto_type *howto; |
252b5132 | 15625 | |
a7ebbfdf TS |
15626 | /* We ignore generic BFD relocations we don't know about. */ |
15627 | howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type); | |
15628 | if (! howto) | |
15629 | return; | |
65551fa4 | 15630 | |
df58fc94 RS |
15631 | gas_assert (fixP->fx_size == 2 |
15632 | || fixP->fx_size == 4 | |
90ecf173 MR |
15633 | || fixP->fx_r_type == BFD_RELOC_16 |
15634 | || fixP->fx_r_type == BFD_RELOC_64 | |
15635 | || fixP->fx_r_type == BFD_RELOC_CTOR | |
15636 | || fixP->fx_r_type == BFD_RELOC_MIPS_SUB | |
df58fc94 | 15637 | || fixP->fx_r_type == BFD_RELOC_MICROMIPS_SUB |
90ecf173 MR |
15638 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
15639 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY | |
15640 | || fixP->fx_r_type == BFD_RELOC_MIPS_TLS_DTPREL64); | |
252b5132 | 15641 | |
4d68580a | 15642 | buf = fixP->fx_frag->fr_literal + fixP->fx_where; |
252b5132 | 15643 | |
df58fc94 RS |
15644 | gas_assert (!fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2 |
15645 | || fixP->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1 | |
15646 | || fixP->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1 | |
b47468a6 CM |
15647 | || fixP->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1 |
15648 | || fixP->fx_r_type == BFD_RELOC_32_PCREL); | |
b1dca8ee RS |
15649 | |
15650 | /* Don't treat parts of a composite relocation as done. There are two | |
15651 | reasons for this: | |
15652 | ||
15653 | (1) The second and third parts will be against 0 (RSS_UNDEF) but | |
15654 | should nevertheless be emitted if the first part is. | |
15655 | ||
15656 | (2) In normal usage, composite relocations are never assembly-time | |
15657 | constants. The easiest way of dealing with the pathological | |
15658 | exceptions is to generate a relocation against STN_UNDEF and | |
15659 | leave everything up to the linker. */ | |
3994f87e | 15660 | if (fixP->fx_addsy == NULL && !fixP->fx_pcrel && fixP->fx_tcbit == 0) |
252b5132 RH |
15661 | fixP->fx_done = 1; |
15662 | ||
15663 | switch (fixP->fx_r_type) | |
15664 | { | |
3f98094e DJ |
15665 | case BFD_RELOC_MIPS_TLS_GD: |
15666 | case BFD_RELOC_MIPS_TLS_LDM: | |
741d6ea8 JM |
15667 | case BFD_RELOC_MIPS_TLS_DTPREL32: |
15668 | case BFD_RELOC_MIPS_TLS_DTPREL64: | |
3f98094e DJ |
15669 | case BFD_RELOC_MIPS_TLS_DTPREL_HI16: |
15670 | case BFD_RELOC_MIPS_TLS_DTPREL_LO16: | |
15671 | case BFD_RELOC_MIPS_TLS_GOTTPREL: | |
d0f13682 CLT |
15672 | case BFD_RELOC_MIPS_TLS_TPREL32: |
15673 | case BFD_RELOC_MIPS_TLS_TPREL64: | |
3f98094e DJ |
15674 | case BFD_RELOC_MIPS_TLS_TPREL_HI16: |
15675 | case BFD_RELOC_MIPS_TLS_TPREL_LO16: | |
df58fc94 RS |
15676 | case BFD_RELOC_MICROMIPS_TLS_GD: |
15677 | case BFD_RELOC_MICROMIPS_TLS_LDM: | |
15678 | case BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16: | |
15679 | case BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16: | |
15680 | case BFD_RELOC_MICROMIPS_TLS_GOTTPREL: | |
15681 | case BFD_RELOC_MICROMIPS_TLS_TPREL_HI16: | |
15682 | case BFD_RELOC_MICROMIPS_TLS_TPREL_LO16: | |
d0f13682 CLT |
15683 | case BFD_RELOC_MIPS16_TLS_GD: |
15684 | case BFD_RELOC_MIPS16_TLS_LDM: | |
15685 | case BFD_RELOC_MIPS16_TLS_DTPREL_HI16: | |
15686 | case BFD_RELOC_MIPS16_TLS_DTPREL_LO16: | |
15687 | case BFD_RELOC_MIPS16_TLS_GOTTPREL: | |
15688 | case BFD_RELOC_MIPS16_TLS_TPREL_HI16: | |
15689 | case BFD_RELOC_MIPS16_TLS_TPREL_LO16: | |
b886a2ab RS |
15690 | if (!fixP->fx_addsy) |
15691 | { | |
15692 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
15693 | _("TLS relocation against a constant")); | |
15694 | break; | |
15695 | } | |
3f98094e DJ |
15696 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
15697 | /* fall through */ | |
15698 | ||
252b5132 | 15699 | case BFD_RELOC_MIPS_JMP: |
e369bcce TS |
15700 | case BFD_RELOC_MIPS_SHIFT5: |
15701 | case BFD_RELOC_MIPS_SHIFT6: | |
15702 | case BFD_RELOC_MIPS_GOT_DISP: | |
15703 | case BFD_RELOC_MIPS_GOT_PAGE: | |
15704 | case BFD_RELOC_MIPS_GOT_OFST: | |
15705 | case BFD_RELOC_MIPS_SUB: | |
15706 | case BFD_RELOC_MIPS_INSERT_A: | |
15707 | case BFD_RELOC_MIPS_INSERT_B: | |
15708 | case BFD_RELOC_MIPS_DELETE: | |
15709 | case BFD_RELOC_MIPS_HIGHEST: | |
15710 | case BFD_RELOC_MIPS_HIGHER: | |
15711 | case BFD_RELOC_MIPS_SCN_DISP: | |
15712 | case BFD_RELOC_MIPS_REL16: | |
15713 | case BFD_RELOC_MIPS_RELGOT: | |
15714 | case BFD_RELOC_MIPS_JALR: | |
252b5132 RH |
15715 | case BFD_RELOC_HI16: |
15716 | case BFD_RELOC_HI16_S: | |
b886a2ab | 15717 | case BFD_RELOC_LO16: |
cdf6fd85 | 15718 | case BFD_RELOC_GPREL16: |
252b5132 RH |
15719 | case BFD_RELOC_MIPS_LITERAL: |
15720 | case BFD_RELOC_MIPS_CALL16: | |
15721 | case BFD_RELOC_MIPS_GOT16: | |
cdf6fd85 | 15722 | case BFD_RELOC_GPREL32: |
252b5132 RH |
15723 | case BFD_RELOC_MIPS_GOT_HI16: |
15724 | case BFD_RELOC_MIPS_GOT_LO16: | |
15725 | case BFD_RELOC_MIPS_CALL_HI16: | |
15726 | case BFD_RELOC_MIPS_CALL_LO16: | |
15727 | case BFD_RELOC_MIPS16_GPREL: | |
738e5348 RS |
15728 | case BFD_RELOC_MIPS16_GOT16: |
15729 | case BFD_RELOC_MIPS16_CALL16: | |
d6f16593 MR |
15730 | case BFD_RELOC_MIPS16_HI16: |
15731 | case BFD_RELOC_MIPS16_HI16_S: | |
b886a2ab | 15732 | case BFD_RELOC_MIPS16_LO16: |
252b5132 | 15733 | case BFD_RELOC_MIPS16_JMP: |
df58fc94 RS |
15734 | case BFD_RELOC_MICROMIPS_JMP: |
15735 | case BFD_RELOC_MICROMIPS_GOT_DISP: | |
15736 | case BFD_RELOC_MICROMIPS_GOT_PAGE: | |
15737 | case BFD_RELOC_MICROMIPS_GOT_OFST: | |
15738 | case BFD_RELOC_MICROMIPS_SUB: | |
15739 | case BFD_RELOC_MICROMIPS_HIGHEST: | |
15740 | case BFD_RELOC_MICROMIPS_HIGHER: | |
15741 | case BFD_RELOC_MICROMIPS_SCN_DISP: | |
15742 | case BFD_RELOC_MICROMIPS_JALR: | |
15743 | case BFD_RELOC_MICROMIPS_HI16: | |
15744 | case BFD_RELOC_MICROMIPS_HI16_S: | |
b886a2ab | 15745 | case BFD_RELOC_MICROMIPS_LO16: |
df58fc94 RS |
15746 | case BFD_RELOC_MICROMIPS_GPREL16: |
15747 | case BFD_RELOC_MICROMIPS_LITERAL: | |
15748 | case BFD_RELOC_MICROMIPS_CALL16: | |
15749 | case BFD_RELOC_MICROMIPS_GOT16: | |
15750 | case BFD_RELOC_MICROMIPS_GOT_HI16: | |
15751 | case BFD_RELOC_MICROMIPS_GOT_LO16: | |
15752 | case BFD_RELOC_MICROMIPS_CALL_HI16: | |
15753 | case BFD_RELOC_MICROMIPS_CALL_LO16: | |
b886a2ab RS |
15754 | if (fixP->fx_done) |
15755 | { | |
15756 | offsetT value; | |
15757 | ||
15758 | if (calculate_reloc (fixP->fx_r_type, *valP, &value)) | |
15759 | { | |
15760 | insn = read_reloc_insn (buf, fixP->fx_r_type); | |
15761 | if (mips16_reloc_p (fixP->fx_r_type)) | |
15762 | insn |= mips16_immed_extend (value, 16); | |
15763 | else | |
15764 | insn |= (value & 0xffff); | |
15765 | write_reloc_insn (buf, fixP->fx_r_type, insn); | |
15766 | } | |
15767 | else | |
15768 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
15769 | _("Unsupported constant in relocation")); | |
15770 | } | |
252b5132 RH |
15771 | break; |
15772 | ||
252b5132 RH |
15773 | case BFD_RELOC_64: |
15774 | /* This is handled like BFD_RELOC_32, but we output a sign | |
15775 | extended value if we are only 32 bits. */ | |
3e722fb5 | 15776 | if (fixP->fx_done) |
252b5132 RH |
15777 | { |
15778 | if (8 <= sizeof (valueT)) | |
4d68580a | 15779 | md_number_to_chars (buf, *valP, 8); |
252b5132 RH |
15780 | else |
15781 | { | |
a7ebbfdf | 15782 | valueT hiv; |
252b5132 | 15783 | |
a7ebbfdf | 15784 | if ((*valP & 0x80000000) != 0) |
252b5132 RH |
15785 | hiv = 0xffffffff; |
15786 | else | |
15787 | hiv = 0; | |
4d68580a RS |
15788 | md_number_to_chars (buf + (target_big_endian ? 4 : 0), *valP, 4); |
15789 | md_number_to_chars (buf + (target_big_endian ? 0 : 4), hiv, 4); | |
252b5132 RH |
15790 | } |
15791 | } | |
15792 | break; | |
15793 | ||
056350c6 | 15794 | case BFD_RELOC_RVA: |
252b5132 | 15795 | case BFD_RELOC_32: |
b47468a6 | 15796 | case BFD_RELOC_32_PCREL: |
252b5132 RH |
15797 | case BFD_RELOC_16: |
15798 | /* If we are deleting this reloc entry, we must fill in the | |
54f4ddb3 TS |
15799 | value now. This can happen if we have a .word which is not |
15800 | resolved when it appears but is later defined. */ | |
252b5132 | 15801 | if (fixP->fx_done) |
4d68580a | 15802 | md_number_to_chars (buf, *valP, fixP->fx_size); |
252b5132 RH |
15803 | break; |
15804 | ||
252b5132 | 15805 | case BFD_RELOC_16_PCREL_S2: |
a7ebbfdf | 15806 | if ((*valP & 0x3) != 0) |
cb56d3d3 | 15807 | as_bad_where (fixP->fx_file, fixP->fx_line, |
bad36eac | 15808 | _("Branch to misaligned address (%lx)"), (long) *valP); |
cb56d3d3 | 15809 | |
54f4ddb3 TS |
15810 | /* We need to save the bits in the instruction since fixup_segment() |
15811 | might be deleting the relocation entry (i.e., a branch within | |
15812 | the current segment). */ | |
a7ebbfdf | 15813 | if (! fixP->fx_done) |
bb2d6cd7 | 15814 | break; |
252b5132 | 15815 | |
54f4ddb3 | 15816 | /* Update old instruction data. */ |
4d68580a | 15817 | insn = read_insn (buf); |
252b5132 | 15818 | |
a7ebbfdf TS |
15819 | if (*valP + 0x20000 <= 0x3ffff) |
15820 | { | |
15821 | insn |= (*valP >> 2) & 0xffff; | |
4d68580a | 15822 | write_insn (buf, insn); |
a7ebbfdf TS |
15823 | } |
15824 | else if (mips_pic == NO_PIC | |
15825 | && fixP->fx_done | |
15826 | && fixP->fx_frag->fr_address >= text_section->vma | |
15827 | && (fixP->fx_frag->fr_address | |
587aac4e | 15828 | < text_section->vma + bfd_get_section_size (text_section)) |
a7ebbfdf TS |
15829 | && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */ |
15830 | || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */ | |
15831 | || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */ | |
252b5132 RH |
15832 | { |
15833 | /* The branch offset is too large. If this is an | |
15834 | unconditional branch, and we are not generating PIC code, | |
15835 | we can convert it to an absolute jump instruction. */ | |
a7ebbfdf TS |
15836 | if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */ |
15837 | insn = 0x0c000000; /* jal */ | |
252b5132 | 15838 | else |
a7ebbfdf TS |
15839 | insn = 0x08000000; /* j */ |
15840 | fixP->fx_r_type = BFD_RELOC_MIPS_JMP; | |
15841 | fixP->fx_done = 0; | |
15842 | fixP->fx_addsy = section_symbol (text_section); | |
15843 | *valP += md_pcrel_from (fixP); | |
4d68580a | 15844 | write_insn (buf, insn); |
a7ebbfdf TS |
15845 | } |
15846 | else | |
15847 | { | |
15848 | /* If we got here, we have branch-relaxation disabled, | |
15849 | and there's nothing we can do to fix this instruction | |
15850 | without turning it into a longer sequence. */ | |
15851 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
15852 | _("Branch out of range")); | |
252b5132 | 15853 | } |
252b5132 RH |
15854 | break; |
15855 | ||
df58fc94 RS |
15856 | case BFD_RELOC_MICROMIPS_7_PCREL_S1: |
15857 | case BFD_RELOC_MICROMIPS_10_PCREL_S1: | |
15858 | case BFD_RELOC_MICROMIPS_16_PCREL_S1: | |
15859 | /* We adjust the offset back to even. */ | |
15860 | if ((*valP & 0x1) != 0) | |
15861 | --(*valP); | |
15862 | ||
15863 | if (! fixP->fx_done) | |
15864 | break; | |
15865 | ||
15866 | /* Should never visit here, because we keep the relocation. */ | |
15867 | abort (); | |
15868 | break; | |
15869 | ||
252b5132 RH |
15870 | case BFD_RELOC_VTABLE_INHERIT: |
15871 | fixP->fx_done = 0; | |
15872 | if (fixP->fx_addsy | |
15873 | && !S_IS_DEFINED (fixP->fx_addsy) | |
15874 | && !S_IS_WEAK (fixP->fx_addsy)) | |
15875 | S_SET_WEAK (fixP->fx_addsy); | |
15876 | break; | |
15877 | ||
15878 | case BFD_RELOC_VTABLE_ENTRY: | |
15879 | fixP->fx_done = 0; | |
15880 | break; | |
15881 | ||
15882 | default: | |
b37df7c4 | 15883 | abort (); |
252b5132 | 15884 | } |
a7ebbfdf TS |
15885 | |
15886 | /* Remember value for tc_gen_reloc. */ | |
15887 | fixP->fx_addnumber = *valP; | |
252b5132 RH |
15888 | } |
15889 | ||
252b5132 | 15890 | static symbolS * |
17a2f251 | 15891 | get_symbol (void) |
252b5132 RH |
15892 | { |
15893 | int c; | |
15894 | char *name; | |
15895 | symbolS *p; | |
15896 | ||
15897 | name = input_line_pointer; | |
15898 | c = get_symbol_end (); | |
15899 | p = (symbolS *) symbol_find_or_make (name); | |
15900 | *input_line_pointer = c; | |
15901 | return p; | |
15902 | } | |
15903 | ||
742a56fe RS |
15904 | /* Align the current frag to a given power of two. If a particular |
15905 | fill byte should be used, FILL points to an integer that contains | |
15906 | that byte, otherwise FILL is null. | |
15907 | ||
462427c4 RS |
15908 | This function used to have the comment: |
15909 | ||
15910 | The MIPS assembler also automatically adjusts any preceding label. | |
15911 | ||
15912 | The implementation therefore applied the adjustment to a maximum of | |
15913 | one label. However, other label adjustments are applied to batches | |
15914 | of labels, and adjusting just one caused problems when new labels | |
15915 | were added for the sake of debugging or unwind information. | |
15916 | We therefore adjust all preceding labels (given as LABELS) instead. */ | |
252b5132 RH |
15917 | |
15918 | static void | |
462427c4 | 15919 | mips_align (int to, int *fill, struct insn_label_list *labels) |
252b5132 | 15920 | { |
7d10b47d | 15921 | mips_emit_delays (); |
df58fc94 | 15922 | mips_record_compressed_mode (); |
742a56fe RS |
15923 | if (fill == NULL && subseg_text_p (now_seg)) |
15924 | frag_align_code (to, 0); | |
15925 | else | |
15926 | frag_align (to, fill ? *fill : 0, 0); | |
252b5132 | 15927 | record_alignment (now_seg, to); |
462427c4 | 15928 | mips_move_labels (labels, FALSE); |
252b5132 RH |
15929 | } |
15930 | ||
15931 | /* Align to a given power of two. .align 0 turns off the automatic | |
15932 | alignment used by the data creating pseudo-ops. */ | |
15933 | ||
15934 | static void | |
17a2f251 | 15935 | s_align (int x ATTRIBUTE_UNUSED) |
252b5132 | 15936 | { |
742a56fe | 15937 | int temp, fill_value, *fill_ptr; |
49954fb4 | 15938 | long max_alignment = 28; |
252b5132 | 15939 | |
54f4ddb3 | 15940 | /* o Note that the assembler pulls down any immediately preceding label |
252b5132 | 15941 | to the aligned address. |
54f4ddb3 | 15942 | o It's not documented but auto alignment is reinstated by |
252b5132 | 15943 | a .align pseudo instruction. |
54f4ddb3 | 15944 | o Note also that after auto alignment is turned off the mips assembler |
252b5132 | 15945 | issues an error on attempt to assemble an improperly aligned data item. |
54f4ddb3 | 15946 | We don't. */ |
252b5132 RH |
15947 | |
15948 | temp = get_absolute_expression (); | |
15949 | if (temp > max_alignment) | |
15950 | as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment); | |
15951 | else if (temp < 0) | |
15952 | { | |
15953 | as_warn (_("Alignment negative: 0 assumed.")); | |
15954 | temp = 0; | |
15955 | } | |
15956 | if (*input_line_pointer == ',') | |
15957 | { | |
f9419b05 | 15958 | ++input_line_pointer; |
742a56fe RS |
15959 | fill_value = get_absolute_expression (); |
15960 | fill_ptr = &fill_value; | |
252b5132 RH |
15961 | } |
15962 | else | |
742a56fe | 15963 | fill_ptr = 0; |
252b5132 RH |
15964 | if (temp) |
15965 | { | |
a8dbcb85 TS |
15966 | segment_info_type *si = seg_info (now_seg); |
15967 | struct insn_label_list *l = si->label_list; | |
54f4ddb3 | 15968 | /* Auto alignment should be switched on by next section change. */ |
252b5132 | 15969 | auto_align = 1; |
462427c4 | 15970 | mips_align (temp, fill_ptr, l); |
252b5132 RH |
15971 | } |
15972 | else | |
15973 | { | |
15974 | auto_align = 0; | |
15975 | } | |
15976 | ||
15977 | demand_empty_rest_of_line (); | |
15978 | } | |
15979 | ||
252b5132 | 15980 | static void |
17a2f251 | 15981 | s_change_sec (int sec) |
252b5132 RH |
15982 | { |
15983 | segT seg; | |
15984 | ||
252b5132 RH |
15985 | #ifdef OBJ_ELF |
15986 | /* The ELF backend needs to know that we are changing sections, so | |
15987 | that .previous works correctly. We could do something like check | |
b6ff326e | 15988 | for an obj_section_change_hook macro, but that might be confusing |
252b5132 RH |
15989 | as it would not be appropriate to use it in the section changing |
15990 | functions in read.c, since obj-elf.c intercepts those. FIXME: | |
15991 | This should be cleaner, somehow. */ | |
f43abd2b TS |
15992 | if (IS_ELF) |
15993 | obj_elf_section_change_hook (); | |
252b5132 RH |
15994 | #endif |
15995 | ||
7d10b47d | 15996 | mips_emit_delays (); |
6a32d874 | 15997 | |
252b5132 RH |
15998 | switch (sec) |
15999 | { | |
16000 | case 't': | |
16001 | s_text (0); | |
16002 | break; | |
16003 | case 'd': | |
16004 | s_data (0); | |
16005 | break; | |
16006 | case 'b': | |
16007 | subseg_set (bss_section, (subsegT) get_absolute_expression ()); | |
16008 | demand_empty_rest_of_line (); | |
16009 | break; | |
16010 | ||
16011 | case 'r': | |
4d0d148d TS |
16012 | seg = subseg_new (RDATA_SECTION_NAME, |
16013 | (subsegT) get_absolute_expression ()); | |
f43abd2b | 16014 | if (IS_ELF) |
252b5132 | 16015 | { |
4d0d148d TS |
16016 | bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD |
16017 | | SEC_READONLY | SEC_RELOC | |
16018 | | SEC_DATA)); | |
c41e87e3 | 16019 | if (strncmp (TARGET_OS, "elf", 3) != 0) |
4d0d148d | 16020 | record_alignment (seg, 4); |
252b5132 | 16021 | } |
4d0d148d | 16022 | demand_empty_rest_of_line (); |
252b5132 RH |
16023 | break; |
16024 | ||
16025 | case 's': | |
4d0d148d | 16026 | seg = subseg_new (".sdata", (subsegT) get_absolute_expression ()); |
f43abd2b | 16027 | if (IS_ELF) |
252b5132 | 16028 | { |
4d0d148d TS |
16029 | bfd_set_section_flags (stdoutput, seg, |
16030 | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA); | |
c41e87e3 | 16031 | if (strncmp (TARGET_OS, "elf", 3) != 0) |
4d0d148d | 16032 | record_alignment (seg, 4); |
252b5132 | 16033 | } |
4d0d148d TS |
16034 | demand_empty_rest_of_line (); |
16035 | break; | |
998b3c36 MR |
16036 | |
16037 | case 'B': | |
16038 | seg = subseg_new (".sbss", (subsegT) get_absolute_expression ()); | |
16039 | if (IS_ELF) | |
16040 | { | |
16041 | bfd_set_section_flags (stdoutput, seg, SEC_ALLOC); | |
16042 | if (strncmp (TARGET_OS, "elf", 3) != 0) | |
16043 | record_alignment (seg, 4); | |
16044 | } | |
16045 | demand_empty_rest_of_line (); | |
16046 | break; | |
252b5132 RH |
16047 | } |
16048 | ||
16049 | auto_align = 1; | |
16050 | } | |
b34976b6 | 16051 | |
cca86cc8 | 16052 | void |
17a2f251 | 16053 | s_change_section (int ignore ATTRIBUTE_UNUSED) |
cca86cc8 | 16054 | { |
7ed4a06a | 16055 | #ifdef OBJ_ELF |
cca86cc8 SC |
16056 | char *section_name; |
16057 | char c; | |
684022ea | 16058 | char next_c = 0; |
cca86cc8 SC |
16059 | int section_type; |
16060 | int section_flag; | |
16061 | int section_entry_size; | |
16062 | int section_alignment; | |
b34976b6 | 16063 | |
f43abd2b | 16064 | if (!IS_ELF) |
7ed4a06a TS |
16065 | return; |
16066 | ||
cca86cc8 SC |
16067 | section_name = input_line_pointer; |
16068 | c = get_symbol_end (); | |
a816d1ed AO |
16069 | if (c) |
16070 | next_c = *(input_line_pointer + 1); | |
cca86cc8 | 16071 | |
4cf0dd0d TS |
16072 | /* Do we have .section Name<,"flags">? */ |
16073 | if (c != ',' || (c == ',' && next_c == '"')) | |
cca86cc8 | 16074 | { |
4cf0dd0d TS |
16075 | /* just after name is now '\0'. */ |
16076 | *input_line_pointer = c; | |
cca86cc8 SC |
16077 | input_line_pointer = section_name; |
16078 | obj_elf_section (ignore); | |
16079 | return; | |
16080 | } | |
16081 | input_line_pointer++; | |
16082 | ||
16083 | /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */ | |
16084 | if (c == ',') | |
16085 | section_type = get_absolute_expression (); | |
16086 | else | |
16087 | section_type = 0; | |
16088 | if (*input_line_pointer++ == ',') | |
16089 | section_flag = get_absolute_expression (); | |
16090 | else | |
16091 | section_flag = 0; | |
16092 | if (*input_line_pointer++ == ',') | |
16093 | section_entry_size = get_absolute_expression (); | |
16094 | else | |
16095 | section_entry_size = 0; | |
16096 | if (*input_line_pointer++ == ',') | |
16097 | section_alignment = get_absolute_expression (); | |
16098 | else | |
16099 | section_alignment = 0; | |
87975d2a AM |
16100 | /* FIXME: really ignore? */ |
16101 | (void) section_alignment; | |
cca86cc8 | 16102 | |
a816d1ed AO |
16103 | section_name = xstrdup (section_name); |
16104 | ||
8ab8a5c8 RS |
16105 | /* When using the generic form of .section (as implemented by obj-elf.c), |
16106 | there's no way to set the section type to SHT_MIPS_DWARF. Users have | |
16107 | traditionally had to fall back on the more common @progbits instead. | |
16108 | ||
16109 | There's nothing really harmful in this, since bfd will correct | |
16110 | SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it | |
708587a4 | 16111 | means that, for backwards compatibility, the special_section entries |
8ab8a5c8 RS |
16112 | for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF. |
16113 | ||
16114 | Even so, we shouldn't force users of the MIPS .section syntax to | |
16115 | incorrectly label the sections as SHT_PROGBITS. The best compromise | |
16116 | seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the | |
16117 | generic type-checking code. */ | |
16118 | if (section_type == SHT_MIPS_DWARF) | |
16119 | section_type = SHT_PROGBITS; | |
16120 | ||
cca86cc8 SC |
16121 | obj_elf_change_section (section_name, section_type, section_flag, |
16122 | section_entry_size, 0, 0, 0); | |
a816d1ed AO |
16123 | |
16124 | if (now_seg->name != section_name) | |
16125 | free (section_name); | |
7ed4a06a | 16126 | #endif /* OBJ_ELF */ |
cca86cc8 | 16127 | } |
252b5132 RH |
16128 | |
16129 | void | |
17a2f251 | 16130 | mips_enable_auto_align (void) |
252b5132 RH |
16131 | { |
16132 | auto_align = 1; | |
16133 | } | |
16134 | ||
16135 | static void | |
17a2f251 | 16136 | s_cons (int log_size) |
252b5132 | 16137 | { |
a8dbcb85 TS |
16138 | segment_info_type *si = seg_info (now_seg); |
16139 | struct insn_label_list *l = si->label_list; | |
252b5132 | 16140 | |
7d10b47d | 16141 | mips_emit_delays (); |
252b5132 | 16142 | if (log_size > 0 && auto_align) |
462427c4 | 16143 | mips_align (log_size, 0, l); |
252b5132 | 16144 | cons (1 << log_size); |
a1facbec | 16145 | mips_clear_insn_labels (); |
252b5132 RH |
16146 | } |
16147 | ||
16148 | static void | |
17a2f251 | 16149 | s_float_cons (int type) |
252b5132 | 16150 | { |
a8dbcb85 TS |
16151 | segment_info_type *si = seg_info (now_seg); |
16152 | struct insn_label_list *l = si->label_list; | |
252b5132 | 16153 | |
7d10b47d | 16154 | mips_emit_delays (); |
252b5132 RH |
16155 | |
16156 | if (auto_align) | |
49309057 ILT |
16157 | { |
16158 | if (type == 'd') | |
462427c4 | 16159 | mips_align (3, 0, l); |
49309057 | 16160 | else |
462427c4 | 16161 | mips_align (2, 0, l); |
49309057 | 16162 | } |
252b5132 | 16163 | |
252b5132 | 16164 | float_cons (type); |
a1facbec | 16165 | mips_clear_insn_labels (); |
252b5132 RH |
16166 | } |
16167 | ||
16168 | /* Handle .globl. We need to override it because on Irix 5 you are | |
16169 | permitted to say | |
16170 | .globl foo .text | |
16171 | where foo is an undefined symbol, to mean that foo should be | |
16172 | considered to be the address of a function. */ | |
16173 | ||
16174 | static void | |
17a2f251 | 16175 | s_mips_globl (int x ATTRIBUTE_UNUSED) |
252b5132 RH |
16176 | { |
16177 | char *name; | |
16178 | int c; | |
16179 | symbolS *symbolP; | |
16180 | flagword flag; | |
16181 | ||
8a06b769 | 16182 | do |
252b5132 | 16183 | { |
8a06b769 | 16184 | name = input_line_pointer; |
252b5132 | 16185 | c = get_symbol_end (); |
8a06b769 TS |
16186 | symbolP = symbol_find_or_make (name); |
16187 | S_SET_EXTERNAL (symbolP); | |
16188 | ||
252b5132 | 16189 | *input_line_pointer = c; |
8a06b769 | 16190 | SKIP_WHITESPACE (); |
252b5132 | 16191 | |
8a06b769 TS |
16192 | /* On Irix 5, every global symbol that is not explicitly labelled as |
16193 | being a function is apparently labelled as being an object. */ | |
16194 | flag = BSF_OBJECT; | |
252b5132 | 16195 | |
8a06b769 TS |
16196 | if (!is_end_of_line[(unsigned char) *input_line_pointer] |
16197 | && (*input_line_pointer != ',')) | |
16198 | { | |
16199 | char *secname; | |
16200 | asection *sec; | |
16201 | ||
16202 | secname = input_line_pointer; | |
16203 | c = get_symbol_end (); | |
16204 | sec = bfd_get_section_by_name (stdoutput, secname); | |
16205 | if (sec == NULL) | |
16206 | as_bad (_("%s: no such section"), secname); | |
16207 | *input_line_pointer = c; | |
16208 | ||
16209 | if (sec != NULL && (sec->flags & SEC_CODE) != 0) | |
16210 | flag = BSF_FUNCTION; | |
16211 | } | |
16212 | ||
16213 | symbol_get_bfdsym (symbolP)->flags |= flag; | |
16214 | ||
16215 | c = *input_line_pointer; | |
16216 | if (c == ',') | |
16217 | { | |
16218 | input_line_pointer++; | |
16219 | SKIP_WHITESPACE (); | |
16220 | if (is_end_of_line[(unsigned char) *input_line_pointer]) | |
16221 | c = '\n'; | |
16222 | } | |
16223 | } | |
16224 | while (c == ','); | |
252b5132 | 16225 | |
252b5132 RH |
16226 | demand_empty_rest_of_line (); |
16227 | } | |
16228 | ||
16229 | static void | |
17a2f251 | 16230 | s_option (int x ATTRIBUTE_UNUSED) |
252b5132 RH |
16231 | { |
16232 | char *opt; | |
16233 | char c; | |
16234 | ||
16235 | opt = input_line_pointer; | |
16236 | c = get_symbol_end (); | |
16237 | ||
16238 | if (*opt == 'O') | |
16239 | { | |
16240 | /* FIXME: What does this mean? */ | |
16241 | } | |
16242 | else if (strncmp (opt, "pic", 3) == 0) | |
16243 | { | |
16244 | int i; | |
16245 | ||
16246 | i = atoi (opt + 3); | |
16247 | if (i == 0) | |
16248 | mips_pic = NO_PIC; | |
16249 | else if (i == 2) | |
143d77c5 | 16250 | { |
8b828383 | 16251 | mips_pic = SVR4_PIC; |
143d77c5 EC |
16252 | mips_abicalls = TRUE; |
16253 | } | |
252b5132 RH |
16254 | else |
16255 | as_bad (_(".option pic%d not supported"), i); | |
16256 | ||
4d0d148d | 16257 | if (mips_pic == SVR4_PIC) |
252b5132 RH |
16258 | { |
16259 | if (g_switch_seen && g_switch_value != 0) | |
16260 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
16261 | g_switch_value = 0; | |
16262 | bfd_set_gp_size (stdoutput, 0); | |
16263 | } | |
16264 | } | |
16265 | else | |
16266 | as_warn (_("Unrecognized option \"%s\""), opt); | |
16267 | ||
16268 | *input_line_pointer = c; | |
16269 | demand_empty_rest_of_line (); | |
16270 | } | |
16271 | ||
16272 | /* This structure is used to hold a stack of .set values. */ | |
16273 | ||
e972090a NC |
16274 | struct mips_option_stack |
16275 | { | |
252b5132 RH |
16276 | struct mips_option_stack *next; |
16277 | struct mips_set_options options; | |
16278 | }; | |
16279 | ||
16280 | static struct mips_option_stack *mips_opts_stack; | |
16281 | ||
16282 | /* Handle the .set pseudo-op. */ | |
16283 | ||
16284 | static void | |
17a2f251 | 16285 | s_mipsset (int x ATTRIBUTE_UNUSED) |
252b5132 RH |
16286 | { |
16287 | char *name = input_line_pointer, ch; | |
16288 | ||
16289 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
f9419b05 | 16290 | ++input_line_pointer; |
252b5132 RH |
16291 | ch = *input_line_pointer; |
16292 | *input_line_pointer = '\0'; | |
16293 | ||
16294 | if (strcmp (name, "reorder") == 0) | |
16295 | { | |
7d10b47d RS |
16296 | if (mips_opts.noreorder) |
16297 | end_noreorder (); | |
252b5132 RH |
16298 | } |
16299 | else if (strcmp (name, "noreorder") == 0) | |
16300 | { | |
7d10b47d RS |
16301 | if (!mips_opts.noreorder) |
16302 | start_noreorder (); | |
252b5132 | 16303 | } |
741fe287 MR |
16304 | else if (strncmp (name, "at=", 3) == 0) |
16305 | { | |
16306 | char *s = name + 3; | |
16307 | ||
16308 | if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, &mips_opts.at)) | |
16309 | as_bad (_("Unrecognized register name `%s'"), s); | |
16310 | } | |
252b5132 RH |
16311 | else if (strcmp (name, "at") == 0) |
16312 | { | |
741fe287 | 16313 | mips_opts.at = ATREG; |
252b5132 RH |
16314 | } |
16315 | else if (strcmp (name, "noat") == 0) | |
16316 | { | |
741fe287 | 16317 | mips_opts.at = ZERO; |
252b5132 RH |
16318 | } |
16319 | else if (strcmp (name, "macro") == 0) | |
16320 | { | |
16321 | mips_opts.warn_about_macros = 0; | |
16322 | } | |
16323 | else if (strcmp (name, "nomacro") == 0) | |
16324 | { | |
16325 | if (mips_opts.noreorder == 0) | |
16326 | as_bad (_("`noreorder' must be set before `nomacro'")); | |
16327 | mips_opts.warn_about_macros = 1; | |
16328 | } | |
16329 | else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0) | |
16330 | { | |
16331 | mips_opts.nomove = 0; | |
16332 | } | |
16333 | else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0) | |
16334 | { | |
16335 | mips_opts.nomove = 1; | |
16336 | } | |
16337 | else if (strcmp (name, "bopt") == 0) | |
16338 | { | |
16339 | mips_opts.nobopt = 0; | |
16340 | } | |
16341 | else if (strcmp (name, "nobopt") == 0) | |
16342 | { | |
16343 | mips_opts.nobopt = 1; | |
16344 | } | |
ad3fea08 TS |
16345 | else if (strcmp (name, "gp=default") == 0) |
16346 | mips_opts.gp32 = file_mips_gp32; | |
16347 | else if (strcmp (name, "gp=32") == 0) | |
16348 | mips_opts.gp32 = 1; | |
16349 | else if (strcmp (name, "gp=64") == 0) | |
16350 | { | |
16351 | if (!ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
20203fb9 | 16352 | as_warn (_("%s isa does not support 64-bit registers"), |
ad3fea08 TS |
16353 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
16354 | mips_opts.gp32 = 0; | |
16355 | } | |
16356 | else if (strcmp (name, "fp=default") == 0) | |
16357 | mips_opts.fp32 = file_mips_fp32; | |
16358 | else if (strcmp (name, "fp=32") == 0) | |
16359 | mips_opts.fp32 = 1; | |
16360 | else if (strcmp (name, "fp=64") == 0) | |
16361 | { | |
16362 | if (!ISA_HAS_64BIT_FPRS (mips_opts.isa)) | |
20203fb9 | 16363 | as_warn (_("%s isa does not support 64-bit floating point registers"), |
ad3fea08 TS |
16364 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
16365 | mips_opts.fp32 = 0; | |
16366 | } | |
037b32b9 AN |
16367 | else if (strcmp (name, "softfloat") == 0) |
16368 | mips_opts.soft_float = 1; | |
16369 | else if (strcmp (name, "hardfloat") == 0) | |
16370 | mips_opts.soft_float = 0; | |
16371 | else if (strcmp (name, "singlefloat") == 0) | |
16372 | mips_opts.single_float = 1; | |
16373 | else if (strcmp (name, "doublefloat") == 0) | |
16374 | mips_opts.single_float = 0; | |
252b5132 RH |
16375 | else if (strcmp (name, "mips16") == 0 |
16376 | || strcmp (name, "MIPS-16") == 0) | |
df58fc94 RS |
16377 | { |
16378 | if (mips_opts.micromips == 1) | |
16379 | as_fatal (_("`mips16' cannot be used with `micromips'")); | |
16380 | mips_opts.mips16 = 1; | |
16381 | } | |
252b5132 RH |
16382 | else if (strcmp (name, "nomips16") == 0 |
16383 | || strcmp (name, "noMIPS-16") == 0) | |
16384 | mips_opts.mips16 = 0; | |
df58fc94 RS |
16385 | else if (strcmp (name, "micromips") == 0) |
16386 | { | |
16387 | if (mips_opts.mips16 == 1) | |
16388 | as_fatal (_("`micromips' cannot be used with `mips16'")); | |
16389 | mips_opts.micromips = 1; | |
16390 | } | |
16391 | else if (strcmp (name, "nomicromips") == 0) | |
16392 | mips_opts.micromips = 0; | |
e16bfa71 TS |
16393 | else if (strcmp (name, "smartmips") == 0) |
16394 | { | |
ad3fea08 | 16395 | if (!ISA_SUPPORTS_SMARTMIPS) |
20203fb9 | 16396 | as_warn (_("%s ISA does not support SmartMIPS ASE"), |
e16bfa71 TS |
16397 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
16398 | mips_opts.ase_smartmips = 1; | |
16399 | } | |
16400 | else if (strcmp (name, "nosmartmips") == 0) | |
16401 | mips_opts.ase_smartmips = 0; | |
1f25f5d3 CD |
16402 | else if (strcmp (name, "mips3d") == 0) |
16403 | mips_opts.ase_mips3d = 1; | |
16404 | else if (strcmp (name, "nomips3d") == 0) | |
16405 | mips_opts.ase_mips3d = 0; | |
a4672219 TS |
16406 | else if (strcmp (name, "mdmx") == 0) |
16407 | mips_opts.ase_mdmx = 1; | |
16408 | else if (strcmp (name, "nomdmx") == 0) | |
16409 | mips_opts.ase_mdmx = 0; | |
74cd071d | 16410 | else if (strcmp (name, "dsp") == 0) |
ad3fea08 TS |
16411 | { |
16412 | if (!ISA_SUPPORTS_DSP_ASE) | |
20203fb9 | 16413 | as_warn (_("%s ISA does not support DSP ASE"), |
ad3fea08 TS |
16414 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
16415 | mips_opts.ase_dsp = 1; | |
8b082fb1 | 16416 | mips_opts.ase_dspr2 = 0; |
ad3fea08 | 16417 | } |
74cd071d | 16418 | else if (strcmp (name, "nodsp") == 0) |
8b082fb1 TS |
16419 | { |
16420 | mips_opts.ase_dsp = 0; | |
16421 | mips_opts.ase_dspr2 = 0; | |
16422 | } | |
16423 | else if (strcmp (name, "dspr2") == 0) | |
16424 | { | |
16425 | if (!ISA_SUPPORTS_DSPR2_ASE) | |
20203fb9 | 16426 | as_warn (_("%s ISA does not support DSP R2 ASE"), |
8b082fb1 TS |
16427 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
16428 | mips_opts.ase_dspr2 = 1; | |
16429 | mips_opts.ase_dsp = 1; | |
16430 | } | |
16431 | else if (strcmp (name, "nodspr2") == 0) | |
16432 | { | |
16433 | mips_opts.ase_dspr2 = 0; | |
16434 | mips_opts.ase_dsp = 0; | |
16435 | } | |
ef2e4d86 | 16436 | else if (strcmp (name, "mt") == 0) |
ad3fea08 TS |
16437 | { |
16438 | if (!ISA_SUPPORTS_MT_ASE) | |
20203fb9 | 16439 | as_warn (_("%s ISA does not support MT ASE"), |
ad3fea08 TS |
16440 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
16441 | mips_opts.ase_mt = 1; | |
16442 | } | |
ef2e4d86 CF |
16443 | else if (strcmp (name, "nomt") == 0) |
16444 | mips_opts.ase_mt = 0; | |
dec0624d MR |
16445 | else if (strcmp (name, "mcu") == 0) |
16446 | mips_opts.ase_mcu = 1; | |
16447 | else if (strcmp (name, "nomcu") == 0) | |
16448 | mips_opts.ase_mcu = 0; | |
1a2c1fad | 16449 | else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0) |
252b5132 | 16450 | { |
af7ee8bf | 16451 | int reset = 0; |
252b5132 | 16452 | |
1a2c1fad CD |
16453 | /* Permit the user to change the ISA and architecture on the fly. |
16454 | Needless to say, misuse can cause serious problems. */ | |
81a21e38 | 16455 | if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0) |
af7ee8bf CD |
16456 | { |
16457 | reset = 1; | |
16458 | mips_opts.isa = file_mips_isa; | |
1a2c1fad | 16459 | mips_opts.arch = file_mips_arch; |
1a2c1fad CD |
16460 | } |
16461 | else if (strncmp (name, "arch=", 5) == 0) | |
16462 | { | |
16463 | const struct mips_cpu_info *p; | |
16464 | ||
16465 | p = mips_parse_cpu("internal use", name + 5); | |
16466 | if (!p) | |
16467 | as_bad (_("unknown architecture %s"), name + 5); | |
16468 | else | |
16469 | { | |
16470 | mips_opts.arch = p->cpu; | |
16471 | mips_opts.isa = p->isa; | |
16472 | } | |
16473 | } | |
81a21e38 TS |
16474 | else if (strncmp (name, "mips", 4) == 0) |
16475 | { | |
16476 | const struct mips_cpu_info *p; | |
16477 | ||
16478 | p = mips_parse_cpu("internal use", name); | |
16479 | if (!p) | |
16480 | as_bad (_("unknown ISA level %s"), name + 4); | |
16481 | else | |
16482 | { | |
16483 | mips_opts.arch = p->cpu; | |
16484 | mips_opts.isa = p->isa; | |
16485 | } | |
16486 | } | |
af7ee8bf | 16487 | else |
81a21e38 | 16488 | as_bad (_("unknown ISA or architecture %s"), name); |
af7ee8bf CD |
16489 | |
16490 | switch (mips_opts.isa) | |
98d3f06f KH |
16491 | { |
16492 | case 0: | |
98d3f06f | 16493 | break; |
af7ee8bf CD |
16494 | case ISA_MIPS1: |
16495 | case ISA_MIPS2: | |
16496 | case ISA_MIPS32: | |
16497 | case ISA_MIPS32R2: | |
98d3f06f KH |
16498 | mips_opts.gp32 = 1; |
16499 | mips_opts.fp32 = 1; | |
16500 | break; | |
af7ee8bf CD |
16501 | case ISA_MIPS3: |
16502 | case ISA_MIPS4: | |
16503 | case ISA_MIPS5: | |
16504 | case ISA_MIPS64: | |
5f74bc13 | 16505 | case ISA_MIPS64R2: |
98d3f06f | 16506 | mips_opts.gp32 = 0; |
e407c74b NC |
16507 | if (mips_opts.arch == CPU_R5900) |
16508 | { | |
16509 | mips_opts.fp32 = 1; | |
16510 | } | |
16511 | else | |
16512 | { | |
98d3f06f | 16513 | mips_opts.fp32 = 0; |
e407c74b | 16514 | } |
98d3f06f KH |
16515 | break; |
16516 | default: | |
16517 | as_bad (_("unknown ISA level %s"), name + 4); | |
16518 | break; | |
16519 | } | |
af7ee8bf | 16520 | if (reset) |
98d3f06f | 16521 | { |
af7ee8bf CD |
16522 | mips_opts.gp32 = file_mips_gp32; |
16523 | mips_opts.fp32 = file_mips_fp32; | |
98d3f06f | 16524 | } |
252b5132 RH |
16525 | } |
16526 | else if (strcmp (name, "autoextend") == 0) | |
16527 | mips_opts.noautoextend = 0; | |
16528 | else if (strcmp (name, "noautoextend") == 0) | |
16529 | mips_opts.noautoextend = 1; | |
16530 | else if (strcmp (name, "push") == 0) | |
16531 | { | |
16532 | struct mips_option_stack *s; | |
16533 | ||
16534 | s = (struct mips_option_stack *) xmalloc (sizeof *s); | |
16535 | s->next = mips_opts_stack; | |
16536 | s->options = mips_opts; | |
16537 | mips_opts_stack = s; | |
16538 | } | |
16539 | else if (strcmp (name, "pop") == 0) | |
16540 | { | |
16541 | struct mips_option_stack *s; | |
16542 | ||
16543 | s = mips_opts_stack; | |
16544 | if (s == NULL) | |
16545 | as_bad (_(".set pop with no .set push")); | |
16546 | else | |
16547 | { | |
16548 | /* If we're changing the reorder mode we need to handle | |
16549 | delay slots correctly. */ | |
16550 | if (s->options.noreorder && ! mips_opts.noreorder) | |
7d10b47d | 16551 | start_noreorder (); |
252b5132 | 16552 | else if (! s->options.noreorder && mips_opts.noreorder) |
7d10b47d | 16553 | end_noreorder (); |
252b5132 RH |
16554 | |
16555 | mips_opts = s->options; | |
16556 | mips_opts_stack = s->next; | |
16557 | free (s); | |
16558 | } | |
16559 | } | |
aed1a261 RS |
16560 | else if (strcmp (name, "sym32") == 0) |
16561 | mips_opts.sym32 = TRUE; | |
16562 | else if (strcmp (name, "nosym32") == 0) | |
16563 | mips_opts.sym32 = FALSE; | |
e6559e01 JM |
16564 | else if (strchr (name, ',')) |
16565 | { | |
16566 | /* Generic ".set" directive; use the generic handler. */ | |
16567 | *input_line_pointer = ch; | |
16568 | input_line_pointer = name; | |
16569 | s_set (0); | |
16570 | return; | |
16571 | } | |
252b5132 RH |
16572 | else |
16573 | { | |
16574 | as_warn (_("Tried to set unrecognized symbol: %s\n"), name); | |
16575 | } | |
16576 | *input_line_pointer = ch; | |
16577 | demand_empty_rest_of_line (); | |
16578 | } | |
16579 | ||
16580 | /* Handle the .abicalls pseudo-op. I believe this is equivalent to | |
16581 | .option pic2. It means to generate SVR4 PIC calls. */ | |
16582 | ||
16583 | static void | |
17a2f251 | 16584 | s_abicalls (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
16585 | { |
16586 | mips_pic = SVR4_PIC; | |
143d77c5 | 16587 | mips_abicalls = TRUE; |
4d0d148d TS |
16588 | |
16589 | if (g_switch_seen && g_switch_value != 0) | |
16590 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
16591 | g_switch_value = 0; | |
16592 | ||
252b5132 RH |
16593 | bfd_set_gp_size (stdoutput, 0); |
16594 | demand_empty_rest_of_line (); | |
16595 | } | |
16596 | ||
16597 | /* Handle the .cpload pseudo-op. This is used when generating SVR4 | |
16598 | PIC code. It sets the $gp register for the function based on the | |
16599 | function address, which is in the register named in the argument. | |
16600 | This uses a relocation against _gp_disp, which is handled specially | |
16601 | by the linker. The result is: | |
16602 | lui $gp,%hi(_gp_disp) | |
16603 | addiu $gp,$gp,%lo(_gp_disp) | |
16604 | addu $gp,$gp,.cpload argument | |
aa6975fb ILT |
16605 | The .cpload argument is normally $25 == $t9. |
16606 | ||
16607 | The -mno-shared option changes this to: | |
bbe506e8 TS |
16608 | lui $gp,%hi(__gnu_local_gp) |
16609 | addiu $gp,$gp,%lo(__gnu_local_gp) | |
aa6975fb ILT |
16610 | and the argument is ignored. This saves an instruction, but the |
16611 | resulting code is not position independent; it uses an absolute | |
bbe506e8 TS |
16612 | address for __gnu_local_gp. Thus code assembled with -mno-shared |
16613 | can go into an ordinary executable, but not into a shared library. */ | |
252b5132 RH |
16614 | |
16615 | static void | |
17a2f251 | 16616 | s_cpload (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
16617 | { |
16618 | expressionS ex; | |
aa6975fb ILT |
16619 | int reg; |
16620 | int in_shared; | |
252b5132 | 16621 | |
6478892d TS |
16622 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
16623 | .cpload is ignored. */ | |
16624 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) | |
252b5132 RH |
16625 | { |
16626 | s_ignore (0); | |
16627 | return; | |
16628 | } | |
16629 | ||
a276b80c MR |
16630 | if (mips_opts.mips16) |
16631 | { | |
16632 | as_bad (_("%s not supported in MIPS16 mode"), ".cpload"); | |
16633 | ignore_rest_of_line (); | |
16634 | return; | |
16635 | } | |
16636 | ||
d3ecfc59 | 16637 | /* .cpload should be in a .set noreorder section. */ |
252b5132 RH |
16638 | if (mips_opts.noreorder == 0) |
16639 | as_warn (_(".cpload not in noreorder section")); | |
16640 | ||
aa6975fb ILT |
16641 | reg = tc_get_register (0); |
16642 | ||
16643 | /* If we need to produce a 64-bit address, we are better off using | |
16644 | the default instruction sequence. */ | |
aed1a261 | 16645 | in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS; |
aa6975fb | 16646 | |
252b5132 | 16647 | ex.X_op = O_symbol; |
bbe506e8 TS |
16648 | ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" : |
16649 | "__gnu_local_gp"); | |
252b5132 RH |
16650 | ex.X_op_symbol = NULL; |
16651 | ex.X_add_number = 0; | |
16652 | ||
16653 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ | |
49309057 | 16654 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
252b5132 | 16655 | |
8a75745d MR |
16656 | mips_mark_labels (); |
16657 | mips_assembling_insn = TRUE; | |
16658 | ||
584892a6 | 16659 | macro_start (); |
67c0d1eb RS |
16660 | macro_build_lui (&ex, mips_gp_register); |
16661 | macro_build (&ex, "addiu", "t,r,j", mips_gp_register, | |
17a2f251 | 16662 | mips_gp_register, BFD_RELOC_LO16); |
aa6975fb ILT |
16663 | if (in_shared) |
16664 | macro_build (NULL, "addu", "d,v,t", mips_gp_register, | |
16665 | mips_gp_register, reg); | |
584892a6 | 16666 | macro_end (); |
252b5132 | 16667 | |
8a75745d | 16668 | mips_assembling_insn = FALSE; |
252b5132 RH |
16669 | demand_empty_rest_of_line (); |
16670 | } | |
16671 | ||
6478892d TS |
16672 | /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is: |
16673 | .cpsetup $reg1, offset|$reg2, label | |
16674 | ||
16675 | If offset is given, this results in: | |
16676 | sd $gp, offset($sp) | |
956cd1d6 | 16677 | lui $gp, %hi(%neg(%gp_rel(label))) |
698b7d9d TS |
16678 | addiu $gp, $gp, %lo(%neg(%gp_rel(label))) |
16679 | daddu $gp, $gp, $reg1 | |
6478892d TS |
16680 | |
16681 | If $reg2 is given, this results in: | |
16682 | daddu $reg2, $gp, $0 | |
956cd1d6 | 16683 | lui $gp, %hi(%neg(%gp_rel(label))) |
698b7d9d TS |
16684 | addiu $gp, $gp, %lo(%neg(%gp_rel(label))) |
16685 | daddu $gp, $gp, $reg1 | |
aa6975fb ILT |
16686 | $reg1 is normally $25 == $t9. |
16687 | ||
16688 | The -mno-shared option replaces the last three instructions with | |
16689 | lui $gp,%hi(_gp) | |
54f4ddb3 | 16690 | addiu $gp,$gp,%lo(_gp) */ |
aa6975fb | 16691 | |
6478892d | 16692 | static void |
17a2f251 | 16693 | s_cpsetup (int ignore ATTRIBUTE_UNUSED) |
6478892d TS |
16694 | { |
16695 | expressionS ex_off; | |
16696 | expressionS ex_sym; | |
16697 | int reg1; | |
6478892d | 16698 | |
8586fc66 | 16699 | /* If we are not generating SVR4 PIC code, .cpsetup is ignored. |
6478892d TS |
16700 | We also need NewABI support. */ |
16701 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
16702 | { | |
16703 | s_ignore (0); | |
16704 | return; | |
16705 | } | |
16706 | ||
a276b80c MR |
16707 | if (mips_opts.mips16) |
16708 | { | |
16709 | as_bad (_("%s not supported in MIPS16 mode"), ".cpsetup"); | |
16710 | ignore_rest_of_line (); | |
16711 | return; | |
16712 | } | |
16713 | ||
6478892d TS |
16714 | reg1 = tc_get_register (0); |
16715 | SKIP_WHITESPACE (); | |
16716 | if (*input_line_pointer != ',') | |
16717 | { | |
16718 | as_bad (_("missing argument separator ',' for .cpsetup")); | |
16719 | return; | |
16720 | } | |
16721 | else | |
80245285 | 16722 | ++input_line_pointer; |
6478892d TS |
16723 | SKIP_WHITESPACE (); |
16724 | if (*input_line_pointer == '$') | |
80245285 TS |
16725 | { |
16726 | mips_cpreturn_register = tc_get_register (0); | |
16727 | mips_cpreturn_offset = -1; | |
16728 | } | |
6478892d | 16729 | else |
80245285 TS |
16730 | { |
16731 | mips_cpreturn_offset = get_absolute_expression (); | |
16732 | mips_cpreturn_register = -1; | |
16733 | } | |
6478892d TS |
16734 | SKIP_WHITESPACE (); |
16735 | if (*input_line_pointer != ',') | |
16736 | { | |
16737 | as_bad (_("missing argument separator ',' for .cpsetup")); | |
16738 | return; | |
16739 | } | |
16740 | else | |
f9419b05 | 16741 | ++input_line_pointer; |
6478892d | 16742 | SKIP_WHITESPACE (); |
f21f8242 | 16743 | expression (&ex_sym); |
6478892d | 16744 | |
8a75745d MR |
16745 | mips_mark_labels (); |
16746 | mips_assembling_insn = TRUE; | |
16747 | ||
584892a6 | 16748 | macro_start (); |
6478892d TS |
16749 | if (mips_cpreturn_register == -1) |
16750 | { | |
16751 | ex_off.X_op = O_constant; | |
16752 | ex_off.X_add_symbol = NULL; | |
16753 | ex_off.X_op_symbol = NULL; | |
16754 | ex_off.X_add_number = mips_cpreturn_offset; | |
16755 | ||
67c0d1eb | 16756 | macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register, |
17a2f251 | 16757 | BFD_RELOC_LO16, SP); |
6478892d TS |
16758 | } |
16759 | else | |
67c0d1eb | 16760 | macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register, |
17a2f251 | 16761 | mips_gp_register, 0); |
6478892d | 16762 | |
aed1a261 | 16763 | if (mips_in_shared || HAVE_64BIT_SYMBOLS) |
aa6975fb | 16764 | { |
df58fc94 | 16765 | macro_build (&ex_sym, "lui", LUI_FMT, mips_gp_register, |
aa6975fb ILT |
16766 | -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB, |
16767 | BFD_RELOC_HI16_S); | |
16768 | ||
16769 | macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register, | |
16770 | mips_gp_register, -1, BFD_RELOC_GPREL16, | |
16771 | BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16); | |
16772 | ||
16773 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register, | |
16774 | mips_gp_register, reg1); | |
16775 | } | |
16776 | else | |
16777 | { | |
16778 | expressionS ex; | |
16779 | ||
16780 | ex.X_op = O_symbol; | |
4184909a | 16781 | ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp"); |
aa6975fb ILT |
16782 | ex.X_op_symbol = NULL; |
16783 | ex.X_add_number = 0; | |
6e1304d8 | 16784 | |
aa6975fb ILT |
16785 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ |
16786 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; | |
16787 | ||
16788 | macro_build_lui (&ex, mips_gp_register); | |
16789 | macro_build (&ex, "addiu", "t,r,j", mips_gp_register, | |
16790 | mips_gp_register, BFD_RELOC_LO16); | |
16791 | } | |
f21f8242 | 16792 | |
584892a6 | 16793 | macro_end (); |
6478892d | 16794 | |
8a75745d | 16795 | mips_assembling_insn = FALSE; |
6478892d TS |
16796 | demand_empty_rest_of_line (); |
16797 | } | |
16798 | ||
16799 | static void | |
17a2f251 | 16800 | s_cplocal (int ignore ATTRIBUTE_UNUSED) |
6478892d TS |
16801 | { |
16802 | /* If we are not generating SVR4 PIC code, or if this is not NewABI code, | |
54f4ddb3 | 16803 | .cplocal is ignored. */ |
6478892d TS |
16804 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) |
16805 | { | |
16806 | s_ignore (0); | |
16807 | return; | |
16808 | } | |
16809 | ||
a276b80c MR |
16810 | if (mips_opts.mips16) |
16811 | { | |
16812 | as_bad (_("%s not supported in MIPS16 mode"), ".cplocal"); | |
16813 | ignore_rest_of_line (); | |
16814 | return; | |
16815 | } | |
16816 | ||
6478892d | 16817 | mips_gp_register = tc_get_register (0); |
85b51719 | 16818 | demand_empty_rest_of_line (); |
6478892d TS |
16819 | } |
16820 | ||
252b5132 RH |
16821 | /* Handle the .cprestore pseudo-op. This stores $gp into a given |
16822 | offset from $sp. The offset is remembered, and after making a PIC | |
16823 | call $gp is restored from that location. */ | |
16824 | ||
16825 | static void | |
17a2f251 | 16826 | s_cprestore (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
16827 | { |
16828 | expressionS ex; | |
252b5132 | 16829 | |
6478892d | 16830 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
c9914766 | 16831 | .cprestore is ignored. */ |
6478892d | 16832 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) |
252b5132 RH |
16833 | { |
16834 | s_ignore (0); | |
16835 | return; | |
16836 | } | |
16837 | ||
a276b80c MR |
16838 | if (mips_opts.mips16) |
16839 | { | |
16840 | as_bad (_("%s not supported in MIPS16 mode"), ".cprestore"); | |
16841 | ignore_rest_of_line (); | |
16842 | return; | |
16843 | } | |
16844 | ||
252b5132 | 16845 | mips_cprestore_offset = get_absolute_expression (); |
7a621144 | 16846 | mips_cprestore_valid = 1; |
252b5132 RH |
16847 | |
16848 | ex.X_op = O_constant; | |
16849 | ex.X_add_symbol = NULL; | |
16850 | ex.X_op_symbol = NULL; | |
16851 | ex.X_add_number = mips_cprestore_offset; | |
16852 | ||
8a75745d MR |
16853 | mips_mark_labels (); |
16854 | mips_assembling_insn = TRUE; | |
16855 | ||
584892a6 | 16856 | macro_start (); |
67c0d1eb RS |
16857 | macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register, |
16858 | SP, HAVE_64BIT_ADDRESSES); | |
584892a6 | 16859 | macro_end (); |
252b5132 | 16860 | |
8a75745d | 16861 | mips_assembling_insn = FALSE; |
252b5132 RH |
16862 | demand_empty_rest_of_line (); |
16863 | } | |
16864 | ||
6478892d | 16865 | /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset |
67c1ffbe | 16866 | was given in the preceding .cpsetup, it results in: |
6478892d | 16867 | ld $gp, offset($sp) |
76b3015f | 16868 | |
6478892d | 16869 | If a register $reg2 was given there, it results in: |
54f4ddb3 TS |
16870 | daddu $gp, $reg2, $0 */ |
16871 | ||
6478892d | 16872 | static void |
17a2f251 | 16873 | s_cpreturn (int ignore ATTRIBUTE_UNUSED) |
6478892d TS |
16874 | { |
16875 | expressionS ex; | |
6478892d TS |
16876 | |
16877 | /* If we are not generating SVR4 PIC code, .cpreturn is ignored. | |
16878 | We also need NewABI support. */ | |
16879 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
16880 | { | |
16881 | s_ignore (0); | |
16882 | return; | |
16883 | } | |
16884 | ||
a276b80c MR |
16885 | if (mips_opts.mips16) |
16886 | { | |
16887 | as_bad (_("%s not supported in MIPS16 mode"), ".cpreturn"); | |
16888 | ignore_rest_of_line (); | |
16889 | return; | |
16890 | } | |
16891 | ||
8a75745d MR |
16892 | mips_mark_labels (); |
16893 | mips_assembling_insn = TRUE; | |
16894 | ||
584892a6 | 16895 | macro_start (); |
6478892d TS |
16896 | if (mips_cpreturn_register == -1) |
16897 | { | |
16898 | ex.X_op = O_constant; | |
16899 | ex.X_add_symbol = NULL; | |
16900 | ex.X_op_symbol = NULL; | |
16901 | ex.X_add_number = mips_cpreturn_offset; | |
16902 | ||
67c0d1eb | 16903 | macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP); |
6478892d TS |
16904 | } |
16905 | else | |
67c0d1eb | 16906 | macro_build (NULL, "daddu", "d,v,t", mips_gp_register, |
17a2f251 | 16907 | mips_cpreturn_register, 0); |
584892a6 | 16908 | macro_end (); |
6478892d | 16909 | |
8a75745d | 16910 | mips_assembling_insn = FALSE; |
6478892d TS |
16911 | demand_empty_rest_of_line (); |
16912 | } | |
16913 | ||
d0f13682 CLT |
16914 | /* Handle a .dtprelword, .dtpreldword, .tprelword, or .tpreldword |
16915 | pseudo-op; DIRSTR says which. The pseudo-op generates a BYTES-size | |
16916 | DTP- or TP-relative relocation of type RTYPE, for use in either DWARF | |
16917 | debug information or MIPS16 TLS. */ | |
741d6ea8 JM |
16918 | |
16919 | static void | |
d0f13682 CLT |
16920 | s_tls_rel_directive (const size_t bytes, const char *dirstr, |
16921 | bfd_reloc_code_real_type rtype) | |
741d6ea8 JM |
16922 | { |
16923 | expressionS ex; | |
16924 | char *p; | |
16925 | ||
16926 | expression (&ex); | |
16927 | ||
16928 | if (ex.X_op != O_symbol) | |
16929 | { | |
d0f13682 | 16930 | as_bad (_("Unsupported use of %s"), dirstr); |
741d6ea8 JM |
16931 | ignore_rest_of_line (); |
16932 | } | |
16933 | ||
16934 | p = frag_more (bytes); | |
16935 | md_number_to_chars (p, 0, bytes); | |
d0f13682 | 16936 | fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE, rtype); |
741d6ea8 | 16937 | demand_empty_rest_of_line (); |
de64cffd | 16938 | mips_clear_insn_labels (); |
741d6ea8 JM |
16939 | } |
16940 | ||
16941 | /* Handle .dtprelword. */ | |
16942 | ||
16943 | static void | |
16944 | s_dtprelword (int ignore ATTRIBUTE_UNUSED) | |
16945 | { | |
d0f13682 | 16946 | s_tls_rel_directive (4, ".dtprelword", BFD_RELOC_MIPS_TLS_DTPREL32); |
741d6ea8 JM |
16947 | } |
16948 | ||
16949 | /* Handle .dtpreldword. */ | |
16950 | ||
16951 | static void | |
16952 | s_dtpreldword (int ignore ATTRIBUTE_UNUSED) | |
16953 | { | |
d0f13682 CLT |
16954 | s_tls_rel_directive (8, ".dtpreldword", BFD_RELOC_MIPS_TLS_DTPREL64); |
16955 | } | |
16956 | ||
16957 | /* Handle .tprelword. */ | |
16958 | ||
16959 | static void | |
16960 | s_tprelword (int ignore ATTRIBUTE_UNUSED) | |
16961 | { | |
16962 | s_tls_rel_directive (4, ".tprelword", BFD_RELOC_MIPS_TLS_TPREL32); | |
16963 | } | |
16964 | ||
16965 | /* Handle .tpreldword. */ | |
16966 | ||
16967 | static void | |
16968 | s_tpreldword (int ignore ATTRIBUTE_UNUSED) | |
16969 | { | |
16970 | s_tls_rel_directive (8, ".tpreldword", BFD_RELOC_MIPS_TLS_TPREL64); | |
741d6ea8 JM |
16971 | } |
16972 | ||
6478892d TS |
16973 | /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC |
16974 | code. It sets the offset to use in gp_rel relocations. */ | |
16975 | ||
16976 | static void | |
17a2f251 | 16977 | s_gpvalue (int ignore ATTRIBUTE_UNUSED) |
6478892d TS |
16978 | { |
16979 | /* If we are not generating SVR4 PIC code, .gpvalue is ignored. | |
16980 | We also need NewABI support. */ | |
16981 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
16982 | { | |
16983 | s_ignore (0); | |
16984 | return; | |
16985 | } | |
16986 | ||
def2e0dd | 16987 | mips_gprel_offset = get_absolute_expression (); |
6478892d TS |
16988 | |
16989 | demand_empty_rest_of_line (); | |
16990 | } | |
16991 | ||
252b5132 RH |
16992 | /* Handle the .gpword pseudo-op. This is used when generating PIC |
16993 | code. It generates a 32 bit GP relative reloc. */ | |
16994 | ||
16995 | static void | |
17a2f251 | 16996 | s_gpword (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 16997 | { |
a8dbcb85 TS |
16998 | segment_info_type *si; |
16999 | struct insn_label_list *l; | |
252b5132 RH |
17000 | expressionS ex; |
17001 | char *p; | |
17002 | ||
17003 | /* When not generating PIC code, this is treated as .word. */ | |
17004 | if (mips_pic != SVR4_PIC) | |
17005 | { | |
17006 | s_cons (2); | |
17007 | return; | |
17008 | } | |
17009 | ||
a8dbcb85 TS |
17010 | si = seg_info (now_seg); |
17011 | l = si->label_list; | |
7d10b47d | 17012 | mips_emit_delays (); |
252b5132 | 17013 | if (auto_align) |
462427c4 | 17014 | mips_align (2, 0, l); |
252b5132 RH |
17015 | |
17016 | expression (&ex); | |
a1facbec | 17017 | mips_clear_insn_labels (); |
252b5132 RH |
17018 | |
17019 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
17020 | { | |
17021 | as_bad (_("Unsupported use of .gpword")); | |
17022 | ignore_rest_of_line (); | |
17023 | } | |
17024 | ||
17025 | p = frag_more (4); | |
17a2f251 | 17026 | md_number_to_chars (p, 0, 4); |
b34976b6 | 17027 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE, |
cdf6fd85 | 17028 | BFD_RELOC_GPREL32); |
252b5132 RH |
17029 | |
17030 | demand_empty_rest_of_line (); | |
17031 | } | |
17032 | ||
10181a0d | 17033 | static void |
17a2f251 | 17034 | s_gpdword (int ignore ATTRIBUTE_UNUSED) |
10181a0d | 17035 | { |
a8dbcb85 TS |
17036 | segment_info_type *si; |
17037 | struct insn_label_list *l; | |
10181a0d AO |
17038 | expressionS ex; |
17039 | char *p; | |
17040 | ||
17041 | /* When not generating PIC code, this is treated as .dword. */ | |
17042 | if (mips_pic != SVR4_PIC) | |
17043 | { | |
17044 | s_cons (3); | |
17045 | return; | |
17046 | } | |
17047 | ||
a8dbcb85 TS |
17048 | si = seg_info (now_seg); |
17049 | l = si->label_list; | |
7d10b47d | 17050 | mips_emit_delays (); |
10181a0d | 17051 | if (auto_align) |
462427c4 | 17052 | mips_align (3, 0, l); |
10181a0d AO |
17053 | |
17054 | expression (&ex); | |
a1facbec | 17055 | mips_clear_insn_labels (); |
10181a0d AO |
17056 | |
17057 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
17058 | { | |
17059 | as_bad (_("Unsupported use of .gpdword")); | |
17060 | ignore_rest_of_line (); | |
17061 | } | |
17062 | ||
17063 | p = frag_more (8); | |
17a2f251 | 17064 | md_number_to_chars (p, 0, 8); |
a105a300 | 17065 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE, |
6e1304d8 | 17066 | BFD_RELOC_GPREL32)->fx_tcbit = 1; |
10181a0d AO |
17067 | |
17068 | /* GPREL32 composed with 64 gives a 64-bit GP offset. */ | |
6e1304d8 RS |
17069 | fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0, |
17070 | FALSE, BFD_RELOC_64)->fx_tcbit = 1; | |
10181a0d AO |
17071 | |
17072 | demand_empty_rest_of_line (); | |
17073 | } | |
17074 | ||
252b5132 RH |
17075 | /* Handle the .cpadd pseudo-op. This is used when dealing with switch |
17076 | tables in SVR4 PIC code. */ | |
17077 | ||
17078 | static void | |
17a2f251 | 17079 | s_cpadd (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 17080 | { |
252b5132 RH |
17081 | int reg; |
17082 | ||
10181a0d AO |
17083 | /* This is ignored when not generating SVR4 PIC code. */ |
17084 | if (mips_pic != SVR4_PIC) | |
252b5132 RH |
17085 | { |
17086 | s_ignore (0); | |
17087 | return; | |
17088 | } | |
17089 | ||
8a75745d MR |
17090 | mips_mark_labels (); |
17091 | mips_assembling_insn = TRUE; | |
17092 | ||
252b5132 | 17093 | /* Add $gp to the register named as an argument. */ |
584892a6 | 17094 | macro_start (); |
252b5132 | 17095 | reg = tc_get_register (0); |
67c0d1eb | 17096 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register); |
584892a6 | 17097 | macro_end (); |
252b5132 | 17098 | |
8a75745d | 17099 | mips_assembling_insn = FALSE; |
bdaaa2e1 | 17100 | demand_empty_rest_of_line (); |
252b5132 RH |
17101 | } |
17102 | ||
17103 | /* Handle the .insn pseudo-op. This marks instruction labels in | |
df58fc94 | 17104 | mips16/micromips mode. This permits the linker to handle them specially, |
252b5132 RH |
17105 | such as generating jalx instructions when needed. We also make |
17106 | them odd for the duration of the assembly, in order to generate the | |
17107 | right sort of code. We will make them even in the adjust_symtab | |
17108 | routine, while leaving them marked. This is convenient for the | |
17109 | debugger and the disassembler. The linker knows to make them odd | |
17110 | again. */ | |
17111 | ||
17112 | static void | |
17a2f251 | 17113 | s_insn (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 17114 | { |
df58fc94 | 17115 | mips_mark_labels (); |
252b5132 RH |
17116 | |
17117 | demand_empty_rest_of_line (); | |
17118 | } | |
17119 | ||
754e2bb9 RS |
17120 | /* Handle a .stab[snd] directive. Ideally these directives would be |
17121 | implemented in a transparent way, so that removing them would not | |
17122 | have any effect on the generated instructions. However, s_stab | |
17123 | internally changes the section, so in practice we need to decide | |
17124 | now whether the preceding label marks compressed code. We do not | |
17125 | support changing the compression mode of a label after a .stab* | |
17126 | directive, such as in: | |
17127 | ||
17128 | foo: | |
17129 | .stabs ... | |
17130 | .set mips16 | |
17131 | ||
17132 | so the current mode wins. */ | |
252b5132 RH |
17133 | |
17134 | static void | |
17a2f251 | 17135 | s_mips_stab (int type) |
252b5132 | 17136 | { |
754e2bb9 | 17137 | mips_mark_labels (); |
252b5132 RH |
17138 | s_stab (type); |
17139 | } | |
17140 | ||
54f4ddb3 | 17141 | /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */ |
252b5132 RH |
17142 | |
17143 | static void | |
17a2f251 | 17144 | s_mips_weakext (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
17145 | { |
17146 | char *name; | |
17147 | int c; | |
17148 | symbolS *symbolP; | |
17149 | expressionS exp; | |
17150 | ||
17151 | name = input_line_pointer; | |
17152 | c = get_symbol_end (); | |
17153 | symbolP = symbol_find_or_make (name); | |
17154 | S_SET_WEAK (symbolP); | |
17155 | *input_line_pointer = c; | |
17156 | ||
17157 | SKIP_WHITESPACE (); | |
17158 | ||
17159 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
17160 | { | |
17161 | if (S_IS_DEFINED (symbolP)) | |
17162 | { | |
20203fb9 | 17163 | as_bad (_("ignoring attempt to redefine symbol %s"), |
252b5132 RH |
17164 | S_GET_NAME (symbolP)); |
17165 | ignore_rest_of_line (); | |
17166 | return; | |
17167 | } | |
bdaaa2e1 | 17168 | |
252b5132 RH |
17169 | if (*input_line_pointer == ',') |
17170 | { | |
17171 | ++input_line_pointer; | |
17172 | SKIP_WHITESPACE (); | |
17173 | } | |
bdaaa2e1 | 17174 | |
252b5132 RH |
17175 | expression (&exp); |
17176 | if (exp.X_op != O_symbol) | |
17177 | { | |
20203fb9 | 17178 | as_bad (_("bad .weakext directive")); |
98d3f06f | 17179 | ignore_rest_of_line (); |
252b5132 RH |
17180 | return; |
17181 | } | |
49309057 | 17182 | symbol_set_value_expression (symbolP, &exp); |
252b5132 RH |
17183 | } |
17184 | ||
17185 | demand_empty_rest_of_line (); | |
17186 | } | |
17187 | ||
17188 | /* Parse a register string into a number. Called from the ECOFF code | |
17189 | to parse .frame. The argument is non-zero if this is the frame | |
17190 | register, so that we can record it in mips_frame_reg. */ | |
17191 | ||
17192 | int | |
17a2f251 | 17193 | tc_get_register (int frame) |
252b5132 | 17194 | { |
707bfff6 | 17195 | unsigned int reg; |
252b5132 RH |
17196 | |
17197 | SKIP_WHITESPACE (); | |
707bfff6 TS |
17198 | if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®)) |
17199 | reg = 0; | |
252b5132 | 17200 | if (frame) |
7a621144 DJ |
17201 | { |
17202 | mips_frame_reg = reg != 0 ? reg : SP; | |
17203 | mips_frame_reg_valid = 1; | |
17204 | mips_cprestore_valid = 0; | |
17205 | } | |
252b5132 RH |
17206 | return reg; |
17207 | } | |
17208 | ||
17209 | valueT | |
17a2f251 | 17210 | md_section_align (asection *seg, valueT addr) |
252b5132 RH |
17211 | { |
17212 | int align = bfd_get_section_alignment (stdoutput, seg); | |
17213 | ||
b4c71f56 TS |
17214 | if (IS_ELF) |
17215 | { | |
17216 | /* We don't need to align ELF sections to the full alignment. | |
17217 | However, Irix 5 may prefer that we align them at least to a 16 | |
17218 | byte boundary. We don't bother to align the sections if we | |
17219 | are targeted for an embedded system. */ | |
c41e87e3 | 17220 | if (strncmp (TARGET_OS, "elf", 3) == 0) |
b4c71f56 TS |
17221 | return addr; |
17222 | if (align > 4) | |
17223 | align = 4; | |
17224 | } | |
252b5132 RH |
17225 | |
17226 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
17227 | } | |
17228 | ||
17229 | /* Utility routine, called from above as well. If called while the | |
17230 | input file is still being read, it's only an approximation. (For | |
17231 | example, a symbol may later become defined which appeared to be | |
17232 | undefined earlier.) */ | |
17233 | ||
17234 | static int | |
17a2f251 | 17235 | nopic_need_relax (symbolS *sym, int before_relaxing) |
252b5132 RH |
17236 | { |
17237 | if (sym == 0) | |
17238 | return 0; | |
17239 | ||
4d0d148d | 17240 | if (g_switch_value > 0) |
252b5132 RH |
17241 | { |
17242 | const char *symname; | |
17243 | int change; | |
17244 | ||
c9914766 | 17245 | /* Find out whether this symbol can be referenced off the $gp |
252b5132 RH |
17246 | register. It can be if it is smaller than the -G size or if |
17247 | it is in the .sdata or .sbss section. Certain symbols can | |
c9914766 | 17248 | not be referenced off the $gp, although it appears as though |
252b5132 RH |
17249 | they can. */ |
17250 | symname = S_GET_NAME (sym); | |
17251 | if (symname != (const char *) NULL | |
17252 | && (strcmp (symname, "eprol") == 0 | |
17253 | || strcmp (symname, "etext") == 0 | |
17254 | || strcmp (symname, "_gp") == 0 | |
17255 | || strcmp (symname, "edata") == 0 | |
17256 | || strcmp (symname, "_fbss") == 0 | |
17257 | || strcmp (symname, "_fdata") == 0 | |
17258 | || strcmp (symname, "_ftext") == 0 | |
17259 | || strcmp (symname, "end") == 0 | |
17260 | || strcmp (symname, "_gp_disp") == 0)) | |
17261 | change = 1; | |
17262 | else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym)) | |
17263 | && (0 | |
17264 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 ILT |
17265 | || (symbol_get_obj (sym)->ecoff_extern_size != 0 |
17266 | && (symbol_get_obj (sym)->ecoff_extern_size | |
17267 | <= g_switch_value)) | |
252b5132 RH |
17268 | #endif |
17269 | /* We must defer this decision until after the whole | |
17270 | file has been read, since there might be a .extern | |
17271 | after the first use of this symbol. */ | |
17272 | || (before_relaxing | |
17273 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 | 17274 | && symbol_get_obj (sym)->ecoff_extern_size == 0 |
252b5132 RH |
17275 | #endif |
17276 | && S_GET_VALUE (sym) == 0) | |
17277 | || (S_GET_VALUE (sym) != 0 | |
17278 | && S_GET_VALUE (sym) <= g_switch_value))) | |
17279 | change = 0; | |
17280 | else | |
17281 | { | |
17282 | const char *segname; | |
17283 | ||
17284 | segname = segment_name (S_GET_SEGMENT (sym)); | |
9c2799c2 | 17285 | gas_assert (strcmp (segname, ".lit8") != 0 |
252b5132 RH |
17286 | && strcmp (segname, ".lit4") != 0); |
17287 | change = (strcmp (segname, ".sdata") != 0 | |
fba2b7f9 GK |
17288 | && strcmp (segname, ".sbss") != 0 |
17289 | && strncmp (segname, ".sdata.", 7) != 0 | |
d4dc2f22 TS |
17290 | && strncmp (segname, ".sbss.", 6) != 0 |
17291 | && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0 | |
fba2b7f9 | 17292 | && strncmp (segname, ".gnu.linkonce.s.", 16) != 0); |
252b5132 RH |
17293 | } |
17294 | return change; | |
17295 | } | |
17296 | else | |
c9914766 | 17297 | /* We are not optimizing for the $gp register. */ |
252b5132 RH |
17298 | return 1; |
17299 | } | |
17300 | ||
5919d012 RS |
17301 | |
17302 | /* Return true if the given symbol should be considered local for SVR4 PIC. */ | |
17303 | ||
17304 | static bfd_boolean | |
17a2f251 | 17305 | pic_need_relax (symbolS *sym, asection *segtype) |
5919d012 RS |
17306 | { |
17307 | asection *symsec; | |
5919d012 RS |
17308 | |
17309 | /* Handle the case of a symbol equated to another symbol. */ | |
17310 | while (symbol_equated_reloc_p (sym)) | |
17311 | { | |
17312 | symbolS *n; | |
17313 | ||
5f0fe04b | 17314 | /* It's possible to get a loop here in a badly written program. */ |
5919d012 RS |
17315 | n = symbol_get_value_expression (sym)->X_add_symbol; |
17316 | if (n == sym) | |
17317 | break; | |
17318 | sym = n; | |
17319 | } | |
17320 | ||
df1f3cda DD |
17321 | if (symbol_section_p (sym)) |
17322 | return TRUE; | |
17323 | ||
5919d012 RS |
17324 | symsec = S_GET_SEGMENT (sym); |
17325 | ||
5919d012 | 17326 | /* This must duplicate the test in adjust_reloc_syms. */ |
45dfa85a AM |
17327 | return (!bfd_is_und_section (symsec) |
17328 | && !bfd_is_abs_section (symsec) | |
5f0fe04b TS |
17329 | && !bfd_is_com_section (symsec) |
17330 | && !s_is_linkonce (sym, segtype) | |
5919d012 RS |
17331 | #ifdef OBJ_ELF |
17332 | /* A global or weak symbol is treated as external. */ | |
f43abd2b | 17333 | && (!IS_ELF || (! S_IS_WEAK (sym) && ! S_IS_EXTERNAL (sym))) |
5919d012 RS |
17334 | #endif |
17335 | ); | |
17336 | } | |
17337 | ||
17338 | ||
252b5132 RH |
17339 | /* Given a mips16 variant frag FRAGP, return non-zero if it needs an |
17340 | extended opcode. SEC is the section the frag is in. */ | |
17341 | ||
17342 | static int | |
17a2f251 | 17343 | mips16_extended_frag (fragS *fragp, asection *sec, long stretch) |
252b5132 RH |
17344 | { |
17345 | int type; | |
3994f87e | 17346 | const struct mips16_immed_operand *op; |
252b5132 RH |
17347 | offsetT val; |
17348 | int mintiny, maxtiny; | |
17349 | segT symsec; | |
98aa84af | 17350 | fragS *sym_frag; |
252b5132 RH |
17351 | |
17352 | if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) | |
17353 | return 0; | |
17354 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) | |
17355 | return 1; | |
17356 | ||
17357 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
17358 | op = mips16_immed_operands; | |
17359 | while (op->type != type) | |
17360 | { | |
17361 | ++op; | |
9c2799c2 | 17362 | gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); |
252b5132 RH |
17363 | } |
17364 | ||
17365 | if (op->unsp) | |
17366 | { | |
17367 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
17368 | { | |
17369 | mintiny = 1; | |
17370 | maxtiny = 1 << op->nbits; | |
17371 | } | |
17372 | else | |
17373 | { | |
17374 | mintiny = 0; | |
17375 | maxtiny = (1 << op->nbits) - 1; | |
17376 | } | |
17377 | } | |
17378 | else | |
17379 | { | |
17380 | mintiny = - (1 << (op->nbits - 1)); | |
17381 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
17382 | } | |
17383 | ||
98aa84af | 17384 | sym_frag = symbol_get_frag (fragp->fr_symbol); |
ac62c346 | 17385 | val = S_GET_VALUE (fragp->fr_symbol); |
98aa84af | 17386 | symsec = S_GET_SEGMENT (fragp->fr_symbol); |
252b5132 RH |
17387 | |
17388 | if (op->pcrel) | |
17389 | { | |
17390 | addressT addr; | |
17391 | ||
17392 | /* We won't have the section when we are called from | |
17393 | mips_relax_frag. However, we will always have been called | |
17394 | from md_estimate_size_before_relax first. If this is a | |
17395 | branch to a different section, we mark it as such. If SEC is | |
17396 | NULL, and the frag is not marked, then it must be a branch to | |
17397 | the same section. */ | |
17398 | if (sec == NULL) | |
17399 | { | |
17400 | if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype)) | |
17401 | return 1; | |
17402 | } | |
17403 | else | |
17404 | { | |
98aa84af | 17405 | /* Must have been called from md_estimate_size_before_relax. */ |
252b5132 RH |
17406 | if (symsec != sec) |
17407 | { | |
17408 | fragp->fr_subtype = | |
17409 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
17410 | ||
17411 | /* FIXME: We should support this, and let the linker | |
17412 | catch branches and loads that are out of range. */ | |
17413 | as_bad_where (fragp->fr_file, fragp->fr_line, | |
17414 | _("unsupported PC relative reference to different section")); | |
17415 | ||
17416 | return 1; | |
17417 | } | |
98aa84af AM |
17418 | if (fragp != sym_frag && sym_frag->fr_address == 0) |
17419 | /* Assume non-extended on the first relaxation pass. | |
17420 | The address we have calculated will be bogus if this is | |
17421 | a forward branch to another frag, as the forward frag | |
17422 | will have fr_address == 0. */ | |
17423 | return 0; | |
252b5132 RH |
17424 | } |
17425 | ||
17426 | /* In this case, we know for sure that the symbol fragment is in | |
98aa84af AM |
17427 | the same section. If the relax_marker of the symbol fragment |
17428 | differs from the relax_marker of this fragment, we have not | |
17429 | yet adjusted the symbol fragment fr_address. We want to add | |
252b5132 RH |
17430 | in STRETCH in order to get a better estimate of the address. |
17431 | This particularly matters because of the shift bits. */ | |
17432 | if (stretch != 0 | |
98aa84af | 17433 | && sym_frag->relax_marker != fragp->relax_marker) |
252b5132 RH |
17434 | { |
17435 | fragS *f; | |
17436 | ||
17437 | /* Adjust stretch for any alignment frag. Note that if have | |
17438 | been expanding the earlier code, the symbol may be | |
17439 | defined in what appears to be an earlier frag. FIXME: | |
17440 | This doesn't handle the fr_subtype field, which specifies | |
17441 | a maximum number of bytes to skip when doing an | |
17442 | alignment. */ | |
98aa84af | 17443 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) |
252b5132 RH |
17444 | { |
17445 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
17446 | { | |
17447 | if (stretch < 0) | |
17448 | stretch = - ((- stretch) | |
17449 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
17450 | else | |
17451 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
17452 | if (stretch == 0) | |
17453 | break; | |
17454 | } | |
17455 | } | |
17456 | if (f != NULL) | |
17457 | val += stretch; | |
17458 | } | |
17459 | ||
17460 | addr = fragp->fr_address + fragp->fr_fix; | |
17461 | ||
17462 | /* The base address rules are complicated. The base address of | |
17463 | a branch is the following instruction. The base address of a | |
17464 | PC relative load or add is the instruction itself, but if it | |
17465 | is in a delay slot (in which case it can not be extended) use | |
17466 | the address of the instruction whose delay slot it is in. */ | |
17467 | if (type == 'p' || type == 'q') | |
17468 | { | |
17469 | addr += 2; | |
17470 | ||
17471 | /* If we are currently assuming that this frag should be | |
17472 | extended, then, the current address is two bytes | |
bdaaa2e1 | 17473 | higher. */ |
252b5132 RH |
17474 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
17475 | addr += 2; | |
17476 | ||
17477 | /* Ignore the low bit in the target, since it will be set | |
17478 | for a text label. */ | |
17479 | if ((val & 1) != 0) | |
17480 | --val; | |
17481 | } | |
17482 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
17483 | addr -= 4; | |
17484 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
17485 | addr -= 2; | |
17486 | ||
17487 | val -= addr & ~ ((1 << op->shift) - 1); | |
17488 | ||
17489 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
17490 | if (type == 'p' || type == 'q') | |
17491 | val /= 2; | |
17492 | ||
17493 | /* If any of the shifted bits are set, we must use an extended | |
17494 | opcode. If the address depends on the size of this | |
17495 | instruction, this can lead to a loop, so we arrange to always | |
17496 | use an extended opcode. We only check this when we are in | |
17497 | the main relaxation loop, when SEC is NULL. */ | |
17498 | if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL) | |
17499 | { | |
17500 | fragp->fr_subtype = | |
17501 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
17502 | return 1; | |
17503 | } | |
17504 | ||
17505 | /* If we are about to mark a frag as extended because the value | |
17506 | is precisely maxtiny + 1, then there is a chance of an | |
17507 | infinite loop as in the following code: | |
17508 | la $4,foo | |
17509 | .skip 1020 | |
17510 | .align 2 | |
17511 | foo: | |
17512 | In this case when the la is extended, foo is 0x3fc bytes | |
17513 | away, so the la can be shrunk, but then foo is 0x400 away, so | |
17514 | the la must be extended. To avoid this loop, we mark the | |
17515 | frag as extended if it was small, and is about to become | |
17516 | extended with a value of maxtiny + 1. */ | |
17517 | if (val == ((maxtiny + 1) << op->shift) | |
17518 | && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype) | |
17519 | && sec == NULL) | |
17520 | { | |
17521 | fragp->fr_subtype = | |
17522 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
17523 | return 1; | |
17524 | } | |
17525 | } | |
17526 | else if (symsec != absolute_section && sec != NULL) | |
17527 | as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation")); | |
17528 | ||
17529 | if ((val & ((1 << op->shift) - 1)) != 0 | |
17530 | || val < (mintiny << op->shift) | |
17531 | || val > (maxtiny << op->shift)) | |
17532 | return 1; | |
17533 | else | |
17534 | return 0; | |
17535 | } | |
17536 | ||
4a6a3df4 AO |
17537 | /* Compute the length of a branch sequence, and adjust the |
17538 | RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the | |
17539 | worst-case length is computed, with UPDATE being used to indicate | |
17540 | whether an unconditional (-1), branch-likely (+1) or regular (0) | |
17541 | branch is to be computed. */ | |
17542 | static int | |
17a2f251 | 17543 | relaxed_branch_length (fragS *fragp, asection *sec, int update) |
4a6a3df4 | 17544 | { |
b34976b6 | 17545 | bfd_boolean toofar; |
4a6a3df4 AO |
17546 | int length; |
17547 | ||
17548 | if (fragp | |
17549 | && S_IS_DEFINED (fragp->fr_symbol) | |
17550 | && sec == S_GET_SEGMENT (fragp->fr_symbol)) | |
17551 | { | |
17552 | addressT addr; | |
17553 | offsetT val; | |
17554 | ||
17555 | val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; | |
17556 | ||
17557 | addr = fragp->fr_address + fragp->fr_fix + 4; | |
17558 | ||
17559 | val -= addr; | |
17560 | ||
17561 | toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2); | |
17562 | } | |
17563 | else if (fragp) | |
17564 | /* If the symbol is not defined or it's in a different segment, | |
17565 | assume the user knows what's going on and emit a short | |
17566 | branch. */ | |
b34976b6 | 17567 | toofar = FALSE; |
4a6a3df4 | 17568 | else |
b34976b6 | 17569 | toofar = TRUE; |
4a6a3df4 AO |
17570 | |
17571 | if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype)) | |
17572 | fragp->fr_subtype | |
66b3e8da MR |
17573 | = RELAX_BRANCH_ENCODE (RELAX_BRANCH_AT (fragp->fr_subtype), |
17574 | RELAX_BRANCH_UNCOND (fragp->fr_subtype), | |
4a6a3df4 AO |
17575 | RELAX_BRANCH_LIKELY (fragp->fr_subtype), |
17576 | RELAX_BRANCH_LINK (fragp->fr_subtype), | |
17577 | toofar); | |
17578 | ||
17579 | length = 4; | |
17580 | if (toofar) | |
17581 | { | |
17582 | if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0)) | |
17583 | length += 8; | |
17584 | ||
17585 | if (mips_pic != NO_PIC) | |
17586 | { | |
17587 | /* Additional space for PIC loading of target address. */ | |
17588 | length += 8; | |
17589 | if (mips_opts.isa == ISA_MIPS1) | |
17590 | /* Additional space for $at-stabilizing nop. */ | |
17591 | length += 4; | |
17592 | } | |
17593 | ||
17594 | /* If branch is conditional. */ | |
17595 | if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0)) | |
17596 | length += 8; | |
17597 | } | |
b34976b6 | 17598 | |
4a6a3df4 AO |
17599 | return length; |
17600 | } | |
17601 | ||
df58fc94 RS |
17602 | /* Compute the length of a branch sequence, and adjust the |
17603 | RELAX_MICROMIPS_TOOFAR32 bit accordingly. If FRAGP is NULL, the | |
17604 | worst-case length is computed, with UPDATE being used to indicate | |
17605 | whether an unconditional (-1), or regular (0) branch is to be | |
17606 | computed. */ | |
17607 | ||
17608 | static int | |
17609 | relaxed_micromips_32bit_branch_length (fragS *fragp, asection *sec, int update) | |
17610 | { | |
17611 | bfd_boolean toofar; | |
17612 | int length; | |
17613 | ||
17614 | if (fragp | |
17615 | && S_IS_DEFINED (fragp->fr_symbol) | |
17616 | && sec == S_GET_SEGMENT (fragp->fr_symbol)) | |
17617 | { | |
17618 | addressT addr; | |
17619 | offsetT val; | |
17620 | ||
17621 | val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; | |
17622 | /* Ignore the low bit in the target, since it will be set | |
17623 | for a text label. */ | |
17624 | if ((val & 1) != 0) | |
17625 | --val; | |
17626 | ||
17627 | addr = fragp->fr_address + fragp->fr_fix + 4; | |
17628 | ||
17629 | val -= addr; | |
17630 | ||
17631 | toofar = val < - (0x8000 << 1) || val >= (0x8000 << 1); | |
17632 | } | |
17633 | else if (fragp) | |
17634 | /* If the symbol is not defined or it's in a different segment, | |
17635 | assume the user knows what's going on and emit a short | |
17636 | branch. */ | |
17637 | toofar = FALSE; | |
17638 | else | |
17639 | toofar = TRUE; | |
17640 | ||
17641 | if (fragp && update | |
17642 | && toofar != RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype)) | |
17643 | fragp->fr_subtype = (toofar | |
17644 | ? RELAX_MICROMIPS_MARK_TOOFAR32 (fragp->fr_subtype) | |
17645 | : RELAX_MICROMIPS_CLEAR_TOOFAR32 (fragp->fr_subtype)); | |
17646 | ||
17647 | length = 4; | |
17648 | if (toofar) | |
17649 | { | |
17650 | bfd_boolean compact_known = fragp != NULL; | |
17651 | bfd_boolean compact = FALSE; | |
17652 | bfd_boolean uncond; | |
17653 | ||
17654 | if (compact_known) | |
17655 | compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype); | |
17656 | if (fragp) | |
17657 | uncond = RELAX_MICROMIPS_UNCOND (fragp->fr_subtype); | |
17658 | else | |
17659 | uncond = update < 0; | |
17660 | ||
17661 | /* If label is out of range, we turn branch <br>: | |
17662 | ||
17663 | <br> label # 4 bytes | |
17664 | 0: | |
17665 | ||
17666 | into: | |
17667 | ||
17668 | j label # 4 bytes | |
17669 | nop # 2 bytes if compact && !PIC | |
17670 | 0: | |
17671 | */ | |
17672 | if (mips_pic == NO_PIC && (!compact_known || compact)) | |
17673 | length += 2; | |
17674 | ||
17675 | /* If assembling PIC code, we further turn: | |
17676 | ||
17677 | j label # 4 bytes | |
17678 | ||
17679 | into: | |
17680 | ||
17681 | lw/ld at, %got(label)(gp) # 4 bytes | |
17682 | d/addiu at, %lo(label) # 4 bytes | |
17683 | jr/c at # 2 bytes | |
17684 | */ | |
17685 | if (mips_pic != NO_PIC) | |
17686 | length += 6; | |
17687 | ||
17688 | /* If branch <br> is conditional, we prepend negated branch <brneg>: | |
17689 | ||
17690 | <brneg> 0f # 4 bytes | |
17691 | nop # 2 bytes if !compact | |
17692 | */ | |
17693 | if (!uncond) | |
17694 | length += (compact_known && compact) ? 4 : 6; | |
17695 | } | |
17696 | ||
17697 | return length; | |
17698 | } | |
17699 | ||
17700 | /* Compute the length of a branch, and adjust the RELAX_MICROMIPS_TOOFAR16 | |
17701 | bit accordingly. */ | |
17702 | ||
17703 | static int | |
17704 | relaxed_micromips_16bit_branch_length (fragS *fragp, asection *sec, int update) | |
17705 | { | |
17706 | bfd_boolean toofar; | |
17707 | ||
df58fc94 RS |
17708 | if (fragp |
17709 | && S_IS_DEFINED (fragp->fr_symbol) | |
17710 | && sec == S_GET_SEGMENT (fragp->fr_symbol)) | |
17711 | { | |
17712 | addressT addr; | |
17713 | offsetT val; | |
17714 | int type; | |
17715 | ||
17716 | val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; | |
17717 | /* Ignore the low bit in the target, since it will be set | |
17718 | for a text label. */ | |
17719 | if ((val & 1) != 0) | |
17720 | --val; | |
17721 | ||
17722 | /* Assume this is a 2-byte branch. */ | |
17723 | addr = fragp->fr_address + fragp->fr_fix + 2; | |
17724 | ||
17725 | /* We try to avoid the infinite loop by not adding 2 more bytes for | |
17726 | long branches. */ | |
17727 | ||
17728 | val -= addr; | |
17729 | ||
17730 | type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype); | |
17731 | if (type == 'D') | |
17732 | toofar = val < - (0x200 << 1) || val >= (0x200 << 1); | |
17733 | else if (type == 'E') | |
17734 | toofar = val < - (0x40 << 1) || val >= (0x40 << 1); | |
17735 | else | |
17736 | abort (); | |
17737 | } | |
17738 | else | |
17739 | /* If the symbol is not defined or it's in a different segment, | |
17740 | we emit a normal 32-bit branch. */ | |
17741 | toofar = TRUE; | |
17742 | ||
17743 | if (fragp && update | |
17744 | && toofar != RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype)) | |
17745 | fragp->fr_subtype | |
17746 | = toofar ? RELAX_MICROMIPS_MARK_TOOFAR16 (fragp->fr_subtype) | |
17747 | : RELAX_MICROMIPS_CLEAR_TOOFAR16 (fragp->fr_subtype); | |
17748 | ||
17749 | if (toofar) | |
17750 | return 4; | |
17751 | ||
17752 | return 2; | |
17753 | } | |
17754 | ||
252b5132 RH |
17755 | /* Estimate the size of a frag before relaxing. Unless this is the |
17756 | mips16, we are not really relaxing here, and the final size is | |
17757 | encoded in the subtype information. For the mips16, we have to | |
17758 | decide whether we are using an extended opcode or not. */ | |
17759 | ||
252b5132 | 17760 | int |
17a2f251 | 17761 | md_estimate_size_before_relax (fragS *fragp, asection *segtype) |
252b5132 | 17762 | { |
5919d012 | 17763 | int change; |
252b5132 | 17764 | |
4a6a3df4 AO |
17765 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
17766 | { | |
17767 | ||
b34976b6 AM |
17768 | fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE); |
17769 | ||
4a6a3df4 AO |
17770 | return fragp->fr_var; |
17771 | } | |
17772 | ||
252b5132 | 17773 | if (RELAX_MIPS16_P (fragp->fr_subtype)) |
177b4a6a AO |
17774 | /* We don't want to modify the EXTENDED bit here; it might get us |
17775 | into infinite loops. We change it only in mips_relax_frag(). */ | |
17776 | return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2); | |
252b5132 | 17777 | |
df58fc94 RS |
17778 | if (RELAX_MICROMIPS_P (fragp->fr_subtype)) |
17779 | { | |
17780 | int length = 4; | |
17781 | ||
17782 | if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0) | |
17783 | length = relaxed_micromips_16bit_branch_length (fragp, segtype, FALSE); | |
17784 | if (length == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)) | |
17785 | length = relaxed_micromips_32bit_branch_length (fragp, segtype, FALSE); | |
17786 | fragp->fr_var = length; | |
17787 | ||
17788 | return length; | |
17789 | } | |
17790 | ||
252b5132 | 17791 | if (mips_pic == NO_PIC) |
5919d012 | 17792 | change = nopic_need_relax (fragp->fr_symbol, 0); |
252b5132 | 17793 | else if (mips_pic == SVR4_PIC) |
5919d012 | 17794 | change = pic_need_relax (fragp->fr_symbol, segtype); |
0a44bf69 RS |
17795 | else if (mips_pic == VXWORKS_PIC) |
17796 | /* For vxworks, GOT16 relocations never have a corresponding LO16. */ | |
17797 | change = 0; | |
252b5132 RH |
17798 | else |
17799 | abort (); | |
17800 | ||
17801 | if (change) | |
17802 | { | |
4d7206a2 | 17803 | fragp->fr_subtype |= RELAX_USE_SECOND; |
4d7206a2 | 17804 | return -RELAX_FIRST (fragp->fr_subtype); |
252b5132 | 17805 | } |
4d7206a2 RS |
17806 | else |
17807 | return -RELAX_SECOND (fragp->fr_subtype); | |
252b5132 RH |
17808 | } |
17809 | ||
17810 | /* This is called to see whether a reloc against a defined symbol | |
de7e6852 | 17811 | should be converted into a reloc against a section. */ |
252b5132 RH |
17812 | |
17813 | int | |
17a2f251 | 17814 | mips_fix_adjustable (fixS *fixp) |
252b5132 | 17815 | { |
252b5132 RH |
17816 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
17817 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
17818 | return 0; | |
a161fe53 | 17819 | |
252b5132 RH |
17820 | if (fixp->fx_addsy == NULL) |
17821 | return 1; | |
a161fe53 | 17822 | |
de7e6852 RS |
17823 | /* If symbol SYM is in a mergeable section, relocations of the form |
17824 | SYM + 0 can usually be made section-relative. The mergeable data | |
17825 | is then identified by the section offset rather than by the symbol. | |
17826 | ||
17827 | However, if we're generating REL LO16 relocations, the offset is split | |
17828 | between the LO16 and parterning high part relocation. The linker will | |
17829 | need to recalculate the complete offset in order to correctly identify | |
17830 | the merge data. | |
17831 | ||
17832 | The linker has traditionally not looked for the parterning high part | |
17833 | relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be | |
17834 | placed anywhere. Rather than break backwards compatibility by changing | |
17835 | this, it seems better not to force the issue, and instead keep the | |
17836 | original symbol. This will work with either linker behavior. */ | |
738e5348 | 17837 | if ((lo16_reloc_p (fixp->fx_r_type) |
704803a9 | 17838 | || reloc_needs_lo_p (fixp->fx_r_type)) |
de7e6852 RS |
17839 | && HAVE_IN_PLACE_ADDENDS |
17840 | && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0) | |
17841 | return 0; | |
17842 | ||
ce70d90a | 17843 | /* There is no place to store an in-place offset for JALR relocations. |
2de39019 CM |
17844 | Likewise an in-range offset of limited PC-relative relocations may |
17845 | overflow the in-place relocatable field if recalculated against the | |
17846 | start address of the symbol's containing section. */ | |
ce70d90a | 17847 | if (HAVE_IN_PLACE_ADDENDS |
2de39019 CM |
17848 | && (limited_pcrel_reloc_p (fixp->fx_r_type) |
17849 | || jalr_reloc_p (fixp->fx_r_type))) | |
1180b5a4 RS |
17850 | return 0; |
17851 | ||
252b5132 | 17852 | #ifdef OBJ_ELF |
b314ec0e RS |
17853 | /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve |
17854 | to a floating-point stub. The same is true for non-R_MIPS16_26 | |
17855 | relocations against MIPS16 functions; in this case, the stub becomes | |
17856 | the function's canonical address. | |
17857 | ||
17858 | Floating-point stubs are stored in unique .mips16.call.* or | |
17859 | .mips16.fn.* sections. If a stub T for function F is in section S, | |
17860 | the first relocation in section S must be against F; this is how the | |
17861 | linker determines the target function. All relocations that might | |
17862 | resolve to T must also be against F. We therefore have the following | |
17863 | restrictions, which are given in an intentionally-redundant way: | |
17864 | ||
17865 | 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16 | |
17866 | symbols. | |
17867 | ||
17868 | 2. We cannot reduce a stub's relocations against non-MIPS16 symbols | |
17869 | if that stub might be used. | |
17870 | ||
17871 | 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16 | |
17872 | symbols. | |
17873 | ||
17874 | 4. We cannot reduce a stub's relocations against MIPS16 symbols if | |
17875 | that stub might be used. | |
17876 | ||
17877 | There is a further restriction: | |
17878 | ||
df58fc94 RS |
17879 | 5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or |
17880 | R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols on | |
17881 | targets with in-place addends; the relocation field cannot | |
b314ec0e RS |
17882 | encode the low bit. |
17883 | ||
df58fc94 RS |
17884 | For simplicity, we deal with (3)-(4) by not reducing _any_ relocation |
17885 | against a MIPS16 symbol. We deal with (5) by by not reducing any | |
17886 | such relocations on REL targets. | |
b314ec0e RS |
17887 | |
17888 | We deal with (1)-(2) by saying that, if there's a R_MIPS16_26 | |
17889 | relocation against some symbol R, no relocation against R may be | |
17890 | reduced. (Note that this deals with (2) as well as (1) because | |
17891 | relocations against global symbols will never be reduced on ELF | |
17892 | targets.) This approach is a little simpler than trying to detect | |
17893 | stub sections, and gives the "all or nothing" per-symbol consistency | |
17894 | that we have for MIPS16 symbols. */ | |
f43abd2b | 17895 | if (IS_ELF |
b314ec0e | 17896 | && fixp->fx_subsy == NULL |
30c09090 | 17897 | && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy)) |
df58fc94 RS |
17898 | || *symbol_get_tc (fixp->fx_addsy) |
17899 | || (HAVE_IN_PLACE_ADDENDS | |
17900 | && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy)) | |
17901 | && jmp_reloc_p (fixp->fx_r_type)))) | |
252b5132 RH |
17902 | return 0; |
17903 | #endif | |
a161fe53 | 17904 | |
252b5132 RH |
17905 | return 1; |
17906 | } | |
17907 | ||
17908 | /* Translate internal representation of relocation info to BFD target | |
17909 | format. */ | |
17910 | ||
17911 | arelent ** | |
17a2f251 | 17912 | tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp) |
252b5132 RH |
17913 | { |
17914 | static arelent *retval[4]; | |
17915 | arelent *reloc; | |
17916 | bfd_reloc_code_real_type code; | |
17917 | ||
4b0cff4e TS |
17918 | memset (retval, 0, sizeof(retval)); |
17919 | reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent)); | |
49309057 ILT |
17920 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
17921 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
17922 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
17923 | ||
bad36eac DJ |
17924 | if (fixp->fx_pcrel) |
17925 | { | |
df58fc94 RS |
17926 | gas_assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2 |
17927 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1 | |
17928 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1 | |
b47468a6 CM |
17929 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1 |
17930 | || fixp->fx_r_type == BFD_RELOC_32_PCREL); | |
bad36eac DJ |
17931 | |
17932 | /* At this point, fx_addnumber is "symbol offset - pcrel address". | |
17933 | Relocations want only the symbol offset. */ | |
17934 | reloc->addend = fixp->fx_addnumber + reloc->address; | |
f43abd2b | 17935 | if (!IS_ELF) |
bad36eac DJ |
17936 | { |
17937 | /* A gruesome hack which is a result of the gruesome gas | |
17938 | reloc handling. What's worse, for COFF (as opposed to | |
17939 | ECOFF), we might need yet another copy of reloc->address. | |
17940 | See bfd_install_relocation. */ | |
17941 | reloc->addend += reloc->address; | |
17942 | } | |
17943 | } | |
17944 | else | |
17945 | reloc->addend = fixp->fx_addnumber; | |
252b5132 | 17946 | |
438c16b8 TS |
17947 | /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable |
17948 | entry to be used in the relocation's section offset. */ | |
17949 | if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
252b5132 RH |
17950 | { |
17951 | reloc->address = reloc->addend; | |
17952 | reloc->addend = 0; | |
17953 | } | |
17954 | ||
252b5132 | 17955 | code = fixp->fx_r_type; |
252b5132 | 17956 | |
bad36eac | 17957 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
252b5132 RH |
17958 | if (reloc->howto == NULL) |
17959 | { | |
17960 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
17961 | _("Can not represent %s relocation in this object file format"), | |
17962 | bfd_get_reloc_code_name (code)); | |
17963 | retval[0] = NULL; | |
17964 | } | |
17965 | ||
17966 | return retval; | |
17967 | } | |
17968 | ||
17969 | /* Relax a machine dependent frag. This returns the amount by which | |
17970 | the current size of the frag should change. */ | |
17971 | ||
17972 | int | |
17a2f251 | 17973 | mips_relax_frag (asection *sec, fragS *fragp, long stretch) |
252b5132 | 17974 | { |
4a6a3df4 AO |
17975 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
17976 | { | |
17977 | offsetT old_var = fragp->fr_var; | |
b34976b6 AM |
17978 | |
17979 | fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE); | |
4a6a3df4 AO |
17980 | |
17981 | return fragp->fr_var - old_var; | |
17982 | } | |
17983 | ||
df58fc94 RS |
17984 | if (RELAX_MICROMIPS_P (fragp->fr_subtype)) |
17985 | { | |
17986 | offsetT old_var = fragp->fr_var; | |
17987 | offsetT new_var = 4; | |
17988 | ||
17989 | if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0) | |
17990 | new_var = relaxed_micromips_16bit_branch_length (fragp, sec, TRUE); | |
17991 | if (new_var == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)) | |
17992 | new_var = relaxed_micromips_32bit_branch_length (fragp, sec, TRUE); | |
17993 | fragp->fr_var = new_var; | |
17994 | ||
17995 | return new_var - old_var; | |
17996 | } | |
17997 | ||
252b5132 RH |
17998 | if (! RELAX_MIPS16_P (fragp->fr_subtype)) |
17999 | return 0; | |
18000 | ||
c4e7957c | 18001 | if (mips16_extended_frag (fragp, NULL, stretch)) |
252b5132 RH |
18002 | { |
18003 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
18004 | return 0; | |
18005 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
18006 | return 2; | |
18007 | } | |
18008 | else | |
18009 | { | |
18010 | if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
18011 | return 0; | |
18012 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
18013 | return -2; | |
18014 | } | |
18015 | ||
18016 | return 0; | |
18017 | } | |
18018 | ||
18019 | /* Convert a machine dependent frag. */ | |
18020 | ||
18021 | void | |
17a2f251 | 18022 | md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp) |
252b5132 | 18023 | { |
4a6a3df4 AO |
18024 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
18025 | { | |
4d68580a | 18026 | char *buf; |
4a6a3df4 AO |
18027 | unsigned long insn; |
18028 | expressionS exp; | |
18029 | fixS *fixp; | |
b34976b6 | 18030 | |
4d68580a RS |
18031 | buf = fragp->fr_literal + fragp->fr_fix; |
18032 | insn = read_insn (buf); | |
b34976b6 | 18033 | |
4a6a3df4 AO |
18034 | if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype)) |
18035 | { | |
18036 | /* We generate a fixup instead of applying it right now | |
18037 | because, if there are linker relaxations, we're going to | |
18038 | need the relocations. */ | |
18039 | exp.X_op = O_symbol; | |
18040 | exp.X_add_symbol = fragp->fr_symbol; | |
18041 | exp.X_add_number = fragp->fr_offset; | |
18042 | ||
4d68580a RS |
18043 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE, |
18044 | BFD_RELOC_16_PCREL_S2); | |
4a6a3df4 AO |
18045 | fixp->fx_file = fragp->fr_file; |
18046 | fixp->fx_line = fragp->fr_line; | |
b34976b6 | 18047 | |
4d68580a | 18048 | buf = write_insn (buf, insn); |
4a6a3df4 AO |
18049 | } |
18050 | else | |
18051 | { | |
18052 | int i; | |
18053 | ||
18054 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
5c4f07ba | 18055 | _("Relaxed out-of-range branch into a jump")); |
4a6a3df4 AO |
18056 | |
18057 | if (RELAX_BRANCH_UNCOND (fragp->fr_subtype)) | |
18058 | goto uncond; | |
18059 | ||
18060 | if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype)) | |
18061 | { | |
18062 | /* Reverse the branch. */ | |
18063 | switch ((insn >> 28) & 0xf) | |
18064 | { | |
18065 | case 4: | |
18066 | /* bc[0-3][tf]l? and bc1any[24][ft] instructions can | |
18067 | have the condition reversed by tweaking a single | |
18068 | bit, and their opcodes all have 0x4???????. */ | |
9c2799c2 | 18069 | gas_assert ((insn & 0xf1000000) == 0x41000000); |
4a6a3df4 AO |
18070 | insn ^= 0x00010000; |
18071 | break; | |
18072 | ||
18073 | case 0: | |
18074 | /* bltz 0x04000000 bgez 0x04010000 | |
54f4ddb3 | 18075 | bltzal 0x04100000 bgezal 0x04110000 */ |
9c2799c2 | 18076 | gas_assert ((insn & 0xfc0e0000) == 0x04000000); |
4a6a3df4 AO |
18077 | insn ^= 0x00010000; |
18078 | break; | |
b34976b6 | 18079 | |
4a6a3df4 AO |
18080 | case 1: |
18081 | /* beq 0x10000000 bne 0x14000000 | |
54f4ddb3 | 18082 | blez 0x18000000 bgtz 0x1c000000 */ |
4a6a3df4 AO |
18083 | insn ^= 0x04000000; |
18084 | break; | |
18085 | ||
18086 | default: | |
18087 | abort (); | |
18088 | } | |
18089 | } | |
18090 | ||
18091 | if (RELAX_BRANCH_LINK (fragp->fr_subtype)) | |
18092 | { | |
18093 | /* Clear the and-link bit. */ | |
9c2799c2 | 18094 | gas_assert ((insn & 0xfc1c0000) == 0x04100000); |
4a6a3df4 | 18095 | |
54f4ddb3 TS |
18096 | /* bltzal 0x04100000 bgezal 0x04110000 |
18097 | bltzall 0x04120000 bgezall 0x04130000 */ | |
4a6a3df4 AO |
18098 | insn &= ~0x00100000; |
18099 | } | |
18100 | ||
18101 | /* Branch over the branch (if the branch was likely) or the | |
18102 | full jump (not likely case). Compute the offset from the | |
18103 | current instruction to branch to. */ | |
18104 | if (RELAX_BRANCH_LIKELY (fragp->fr_subtype)) | |
18105 | i = 16; | |
18106 | else | |
18107 | { | |
18108 | /* How many bytes in instructions we've already emitted? */ | |
4d68580a | 18109 | i = buf - fragp->fr_literal - fragp->fr_fix; |
4a6a3df4 AO |
18110 | /* How many bytes in instructions from here to the end? */ |
18111 | i = fragp->fr_var - i; | |
18112 | } | |
18113 | /* Convert to instruction count. */ | |
18114 | i >>= 2; | |
18115 | /* Branch counts from the next instruction. */ | |
b34976b6 | 18116 | i--; |
4a6a3df4 AO |
18117 | insn |= i; |
18118 | /* Branch over the jump. */ | |
4d68580a | 18119 | buf = write_insn (buf, insn); |
4a6a3df4 | 18120 | |
54f4ddb3 | 18121 | /* nop */ |
4d68580a | 18122 | buf = write_insn (buf, 0); |
4a6a3df4 AO |
18123 | |
18124 | if (RELAX_BRANCH_LIKELY (fragp->fr_subtype)) | |
18125 | { | |
18126 | /* beql $0, $0, 2f */ | |
18127 | insn = 0x50000000; | |
18128 | /* Compute the PC offset from the current instruction to | |
18129 | the end of the variable frag. */ | |
18130 | /* How many bytes in instructions we've already emitted? */ | |
4d68580a | 18131 | i = buf - fragp->fr_literal - fragp->fr_fix; |
4a6a3df4 AO |
18132 | /* How many bytes in instructions from here to the end? */ |
18133 | i = fragp->fr_var - i; | |
18134 | /* Convert to instruction count. */ | |
18135 | i >>= 2; | |
18136 | /* Don't decrement i, because we want to branch over the | |
18137 | delay slot. */ | |
4a6a3df4 | 18138 | insn |= i; |
4a6a3df4 | 18139 | |
4d68580a RS |
18140 | buf = write_insn (buf, insn); |
18141 | buf = write_insn (buf, 0); | |
4a6a3df4 AO |
18142 | } |
18143 | ||
18144 | uncond: | |
18145 | if (mips_pic == NO_PIC) | |
18146 | { | |
18147 | /* j or jal. */ | |
18148 | insn = (RELAX_BRANCH_LINK (fragp->fr_subtype) | |
18149 | ? 0x0c000000 : 0x08000000); | |
18150 | exp.X_op = O_symbol; | |
18151 | exp.X_add_symbol = fragp->fr_symbol; | |
18152 | exp.X_add_number = fragp->fr_offset; | |
18153 | ||
4d68580a RS |
18154 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, |
18155 | FALSE, BFD_RELOC_MIPS_JMP); | |
4a6a3df4 AO |
18156 | fixp->fx_file = fragp->fr_file; |
18157 | fixp->fx_line = fragp->fr_line; | |
18158 | ||
4d68580a | 18159 | buf = write_insn (buf, insn); |
4a6a3df4 AO |
18160 | } |
18161 | else | |
18162 | { | |
66b3e8da MR |
18163 | unsigned long at = RELAX_BRANCH_AT (fragp->fr_subtype); |
18164 | ||
4a6a3df4 | 18165 | /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */ |
66b3e8da MR |
18166 | insn = HAVE_64BIT_ADDRESSES ? 0xdf800000 : 0x8f800000; |
18167 | insn |= at << OP_SH_RT; | |
4a6a3df4 AO |
18168 | exp.X_op = O_symbol; |
18169 | exp.X_add_symbol = fragp->fr_symbol; | |
18170 | exp.X_add_number = fragp->fr_offset; | |
18171 | ||
18172 | if (fragp->fr_offset) | |
18173 | { | |
18174 | exp.X_add_symbol = make_expr_symbol (&exp); | |
18175 | exp.X_add_number = 0; | |
18176 | } | |
18177 | ||
4d68580a RS |
18178 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, |
18179 | FALSE, BFD_RELOC_MIPS_GOT16); | |
4a6a3df4 AO |
18180 | fixp->fx_file = fragp->fr_file; |
18181 | fixp->fx_line = fragp->fr_line; | |
18182 | ||
4d68580a | 18183 | buf = write_insn (buf, insn); |
b34976b6 | 18184 | |
4a6a3df4 | 18185 | if (mips_opts.isa == ISA_MIPS1) |
4d68580a RS |
18186 | /* nop */ |
18187 | buf = write_insn (buf, 0); | |
4a6a3df4 AO |
18188 | |
18189 | /* d/addiu $at, $at, <sym> R_MIPS_LO16 */ | |
66b3e8da MR |
18190 | insn = HAVE_64BIT_ADDRESSES ? 0x64000000 : 0x24000000; |
18191 | insn |= at << OP_SH_RS | at << OP_SH_RT; | |
4a6a3df4 | 18192 | |
4d68580a RS |
18193 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, |
18194 | FALSE, BFD_RELOC_LO16); | |
4a6a3df4 AO |
18195 | fixp->fx_file = fragp->fr_file; |
18196 | fixp->fx_line = fragp->fr_line; | |
b34976b6 | 18197 | |
4d68580a | 18198 | buf = write_insn (buf, insn); |
4a6a3df4 AO |
18199 | |
18200 | /* j(al)r $at. */ | |
18201 | if (RELAX_BRANCH_LINK (fragp->fr_subtype)) | |
66b3e8da | 18202 | insn = 0x0000f809; |
4a6a3df4 | 18203 | else |
66b3e8da MR |
18204 | insn = 0x00000008; |
18205 | insn |= at << OP_SH_RS; | |
4a6a3df4 | 18206 | |
4d68580a | 18207 | buf = write_insn (buf, insn); |
4a6a3df4 AO |
18208 | } |
18209 | } | |
18210 | ||
4a6a3df4 | 18211 | fragp->fr_fix += fragp->fr_var; |
4d68580a | 18212 | gas_assert (buf == fragp->fr_literal + fragp->fr_fix); |
4a6a3df4 AO |
18213 | return; |
18214 | } | |
18215 | ||
df58fc94 RS |
18216 | /* Relax microMIPS branches. */ |
18217 | if (RELAX_MICROMIPS_P (fragp->fr_subtype)) | |
18218 | { | |
4d68580a | 18219 | char *buf = fragp->fr_literal + fragp->fr_fix; |
df58fc94 RS |
18220 | bfd_boolean compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype); |
18221 | bfd_boolean al = RELAX_MICROMIPS_LINK (fragp->fr_subtype); | |
18222 | int type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype); | |
2309ddf2 | 18223 | bfd_boolean short_ds; |
df58fc94 RS |
18224 | unsigned long insn; |
18225 | expressionS exp; | |
18226 | fixS *fixp; | |
18227 | ||
18228 | exp.X_op = O_symbol; | |
18229 | exp.X_add_symbol = fragp->fr_symbol; | |
18230 | exp.X_add_number = fragp->fr_offset; | |
18231 | ||
18232 | fragp->fr_fix += fragp->fr_var; | |
18233 | ||
18234 | /* Handle 16-bit branches that fit or are forced to fit. */ | |
18235 | if (type != 0 && !RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype)) | |
18236 | { | |
18237 | /* We generate a fixup instead of applying it right now, | |
18238 | because if there is linker relaxation, we're going to | |
18239 | need the relocations. */ | |
18240 | if (type == 'D') | |
4d68580a | 18241 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE, |
df58fc94 RS |
18242 | BFD_RELOC_MICROMIPS_10_PCREL_S1); |
18243 | else if (type == 'E') | |
4d68580a | 18244 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE, |
df58fc94 RS |
18245 | BFD_RELOC_MICROMIPS_7_PCREL_S1); |
18246 | else | |
18247 | abort (); | |
18248 | ||
18249 | fixp->fx_file = fragp->fr_file; | |
18250 | fixp->fx_line = fragp->fr_line; | |
18251 | ||
18252 | /* These relocations can have an addend that won't fit in | |
18253 | 2 octets. */ | |
18254 | fixp->fx_no_overflow = 1; | |
18255 | ||
18256 | return; | |
18257 | } | |
18258 | ||
2309ddf2 | 18259 | /* Handle 32-bit branches that fit or are forced to fit. */ |
df58fc94 RS |
18260 | if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype) |
18261 | || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype)) | |
18262 | { | |
18263 | /* We generate a fixup instead of applying it right now, | |
18264 | because if there is linker relaxation, we're going to | |
18265 | need the relocations. */ | |
4d68580a RS |
18266 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE, |
18267 | BFD_RELOC_MICROMIPS_16_PCREL_S1); | |
df58fc94 RS |
18268 | fixp->fx_file = fragp->fr_file; |
18269 | fixp->fx_line = fragp->fr_line; | |
18270 | ||
18271 | if (type == 0) | |
18272 | return; | |
18273 | } | |
18274 | ||
18275 | /* Relax 16-bit branches to 32-bit branches. */ | |
18276 | if (type != 0) | |
18277 | { | |
4d68580a | 18278 | insn = read_compressed_insn (buf, 2); |
df58fc94 RS |
18279 | |
18280 | if ((insn & 0xfc00) == 0xcc00) /* b16 */ | |
18281 | insn = 0x94000000; /* beq */ | |
18282 | else if ((insn & 0xdc00) == 0x8c00) /* beqz16/bnez16 */ | |
18283 | { | |
18284 | unsigned long regno; | |
18285 | ||
18286 | regno = (insn >> MICROMIPSOP_SH_MD) & MICROMIPSOP_MASK_MD; | |
18287 | regno = micromips_to_32_reg_d_map [regno]; | |
18288 | insn = ((insn & 0x2000) << 16) | 0x94000000; /* beq/bne */ | |
18289 | insn |= regno << MICROMIPSOP_SH_RS; | |
18290 | } | |
18291 | else | |
18292 | abort (); | |
18293 | ||
18294 | /* Nothing else to do, just write it out. */ | |
18295 | if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype) | |
18296 | || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype)) | |
18297 | { | |
4d68580a RS |
18298 | buf = write_compressed_insn (buf, insn, 4); |
18299 | gas_assert (buf == fragp->fr_literal + fragp->fr_fix); | |
df58fc94 RS |
18300 | return; |
18301 | } | |
18302 | } | |
18303 | else | |
4d68580a | 18304 | insn = read_compressed_insn (buf, 4); |
df58fc94 RS |
18305 | |
18306 | /* Relax 32-bit branches to a sequence of instructions. */ | |
18307 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
18308 | _("Relaxed out-of-range branch into a jump")); | |
18309 | ||
2309ddf2 MR |
18310 | /* Set the short-delay-slot bit. */ |
18311 | short_ds = al && (insn & 0x02000000) != 0; | |
df58fc94 RS |
18312 | |
18313 | if (!RELAX_MICROMIPS_UNCOND (fragp->fr_subtype)) | |
18314 | { | |
18315 | symbolS *l; | |
18316 | ||
18317 | /* Reverse the branch. */ | |
18318 | if ((insn & 0xfc000000) == 0x94000000 /* beq */ | |
18319 | || (insn & 0xfc000000) == 0xb4000000) /* bne */ | |
18320 | insn ^= 0x20000000; | |
18321 | else if ((insn & 0xffe00000) == 0x40000000 /* bltz */ | |
18322 | || (insn & 0xffe00000) == 0x40400000 /* bgez */ | |
18323 | || (insn & 0xffe00000) == 0x40800000 /* blez */ | |
18324 | || (insn & 0xffe00000) == 0x40c00000 /* bgtz */ | |
18325 | || (insn & 0xffe00000) == 0x40a00000 /* bnezc */ | |
18326 | || (insn & 0xffe00000) == 0x40e00000 /* beqzc */ | |
18327 | || (insn & 0xffe00000) == 0x40200000 /* bltzal */ | |
18328 | || (insn & 0xffe00000) == 0x40600000 /* bgezal */ | |
18329 | || (insn & 0xffe00000) == 0x42200000 /* bltzals */ | |
18330 | || (insn & 0xffe00000) == 0x42600000) /* bgezals */ | |
18331 | insn ^= 0x00400000; | |
18332 | else if ((insn & 0xffe30000) == 0x43800000 /* bc1f */ | |
18333 | || (insn & 0xffe30000) == 0x43a00000 /* bc1t */ | |
18334 | || (insn & 0xffe30000) == 0x42800000 /* bc2f */ | |
18335 | || (insn & 0xffe30000) == 0x42a00000) /* bc2t */ | |
18336 | insn ^= 0x00200000; | |
18337 | else | |
18338 | abort (); | |
18339 | ||
18340 | if (al) | |
18341 | { | |
18342 | /* Clear the and-link and short-delay-slot bits. */ | |
18343 | gas_assert ((insn & 0xfda00000) == 0x40200000); | |
18344 | ||
18345 | /* bltzal 0x40200000 bgezal 0x40600000 */ | |
18346 | /* bltzals 0x42200000 bgezals 0x42600000 */ | |
18347 | insn &= ~0x02200000; | |
18348 | } | |
18349 | ||
18350 | /* Make a label at the end for use with the branch. */ | |
18351 | l = symbol_new (micromips_label_name (), asec, fragp->fr_fix, fragp); | |
18352 | micromips_label_inc (); | |
18353 | #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF) | |
18354 | if (IS_ELF) | |
18355 | S_SET_OTHER (l, ELF_ST_SET_MICROMIPS (S_GET_OTHER (l))); | |
18356 | #endif | |
18357 | ||
18358 | /* Refer to it. */ | |
4d68580a RS |
18359 | fixp = fix_new (fragp, buf - fragp->fr_literal, 4, l, 0, TRUE, |
18360 | BFD_RELOC_MICROMIPS_16_PCREL_S1); | |
df58fc94 RS |
18361 | fixp->fx_file = fragp->fr_file; |
18362 | fixp->fx_line = fragp->fr_line; | |
18363 | ||
18364 | /* Branch over the jump. */ | |
4d68580a | 18365 | buf = write_compressed_insn (buf, insn, 4); |
df58fc94 | 18366 | if (!compact) |
4d68580a RS |
18367 | /* nop */ |
18368 | buf = write_compressed_insn (buf, 0x0c00, 2); | |
df58fc94 RS |
18369 | } |
18370 | ||
18371 | if (mips_pic == NO_PIC) | |
18372 | { | |
2309ddf2 MR |
18373 | unsigned long jal = short_ds ? 0x74000000 : 0xf4000000; /* jal/s */ |
18374 | ||
df58fc94 RS |
18375 | /* j/jal/jals <sym> R_MICROMIPS_26_S1 */ |
18376 | insn = al ? jal : 0xd4000000; | |
18377 | ||
4d68580a RS |
18378 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE, |
18379 | BFD_RELOC_MICROMIPS_JMP); | |
df58fc94 RS |
18380 | fixp->fx_file = fragp->fr_file; |
18381 | fixp->fx_line = fragp->fr_line; | |
18382 | ||
4d68580a | 18383 | buf = write_compressed_insn (buf, insn, 4); |
df58fc94 | 18384 | if (compact) |
4d68580a RS |
18385 | /* nop */ |
18386 | buf = write_compressed_insn (buf, 0x0c00, 2); | |
df58fc94 RS |
18387 | } |
18388 | else | |
18389 | { | |
18390 | unsigned long at = RELAX_MICROMIPS_AT (fragp->fr_subtype); | |
2309ddf2 MR |
18391 | unsigned long jalr = short_ds ? 0x45e0 : 0x45c0; /* jalr/s */ |
18392 | unsigned long jr = compact ? 0x45a0 : 0x4580; /* jr/c */ | |
df58fc94 RS |
18393 | |
18394 | /* lw/ld $at, <sym>($gp) R_MICROMIPS_GOT16 */ | |
18395 | insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000; | |
18396 | insn |= at << MICROMIPSOP_SH_RT; | |
18397 | ||
18398 | if (exp.X_add_number) | |
18399 | { | |
18400 | exp.X_add_symbol = make_expr_symbol (&exp); | |
18401 | exp.X_add_number = 0; | |
18402 | } | |
18403 | ||
4d68580a RS |
18404 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE, |
18405 | BFD_RELOC_MICROMIPS_GOT16); | |
df58fc94 RS |
18406 | fixp->fx_file = fragp->fr_file; |
18407 | fixp->fx_line = fragp->fr_line; | |
18408 | ||
4d68580a | 18409 | buf = write_compressed_insn (buf, insn, 4); |
df58fc94 RS |
18410 | |
18411 | /* d/addiu $at, $at, <sym> R_MICROMIPS_LO16 */ | |
18412 | insn = HAVE_64BIT_ADDRESSES ? 0x5c000000 : 0x30000000; | |
18413 | insn |= at << MICROMIPSOP_SH_RT | at << MICROMIPSOP_SH_RS; | |
18414 | ||
4d68580a RS |
18415 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE, |
18416 | BFD_RELOC_MICROMIPS_LO16); | |
df58fc94 RS |
18417 | fixp->fx_file = fragp->fr_file; |
18418 | fixp->fx_line = fragp->fr_line; | |
18419 | ||
4d68580a | 18420 | buf = write_compressed_insn (buf, insn, 4); |
df58fc94 RS |
18421 | |
18422 | /* jr/jrc/jalr/jalrs $at */ | |
18423 | insn = al ? jalr : jr; | |
18424 | insn |= at << MICROMIPSOP_SH_MJ; | |
18425 | ||
4d68580a | 18426 | buf = write_compressed_insn (buf, insn, 2); |
df58fc94 RS |
18427 | } |
18428 | ||
4d68580a | 18429 | gas_assert (buf == fragp->fr_literal + fragp->fr_fix); |
df58fc94 RS |
18430 | return; |
18431 | } | |
18432 | ||
252b5132 RH |
18433 | if (RELAX_MIPS16_P (fragp->fr_subtype)) |
18434 | { | |
18435 | int type; | |
3994f87e | 18436 | const struct mips16_immed_operand *op; |
252b5132 | 18437 | offsetT val; |
5c04167a RS |
18438 | char *buf; |
18439 | unsigned int user_length, length; | |
252b5132 | 18440 | unsigned long insn; |
5c04167a | 18441 | bfd_boolean ext; |
252b5132 RH |
18442 | |
18443 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
18444 | op = mips16_immed_operands; | |
18445 | while (op->type != type) | |
18446 | ++op; | |
18447 | ||
5c04167a | 18448 | ext = RELAX_MIPS16_EXTENDED (fragp->fr_subtype); |
5f5f22c0 | 18449 | val = resolve_symbol_value (fragp->fr_symbol); |
252b5132 RH |
18450 | if (op->pcrel) |
18451 | { | |
18452 | addressT addr; | |
18453 | ||
18454 | addr = fragp->fr_address + fragp->fr_fix; | |
18455 | ||
18456 | /* The rules for the base address of a PC relative reloc are | |
18457 | complicated; see mips16_extended_frag. */ | |
18458 | if (type == 'p' || type == 'q') | |
18459 | { | |
18460 | addr += 2; | |
18461 | if (ext) | |
18462 | addr += 2; | |
18463 | /* Ignore the low bit in the target, since it will be | |
18464 | set for a text label. */ | |
18465 | if ((val & 1) != 0) | |
18466 | --val; | |
18467 | } | |
18468 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
18469 | addr -= 4; | |
18470 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
18471 | addr -= 2; | |
18472 | ||
18473 | addr &= ~ (addressT) ((1 << op->shift) - 1); | |
18474 | val -= addr; | |
18475 | ||
18476 | /* Make sure the section winds up with the alignment we have | |
18477 | assumed. */ | |
18478 | if (op->shift > 0) | |
18479 | record_alignment (asec, op->shift); | |
18480 | } | |
18481 | ||
18482 | if (ext | |
18483 | && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype) | |
18484 | || RELAX_MIPS16_DSLOT (fragp->fr_subtype))) | |
18485 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
18486 | _("extended instruction in delay slot")); | |
18487 | ||
5c04167a | 18488 | buf = fragp->fr_literal + fragp->fr_fix; |
252b5132 | 18489 | |
4d68580a | 18490 | insn = read_compressed_insn (buf, 2); |
5c04167a RS |
18491 | if (ext) |
18492 | insn |= MIPS16_EXTEND; | |
252b5132 | 18493 | |
5c04167a RS |
18494 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) |
18495 | user_length = 4; | |
18496 | else if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) | |
18497 | user_length = 2; | |
18498 | else | |
18499 | user_length = 0; | |
18500 | ||
43c0598f | 18501 | mips16_immed (fragp->fr_file, fragp->fr_line, type, |
c150d1d2 | 18502 | BFD_RELOC_UNUSED, val, user_length, &insn); |
252b5132 | 18503 | |
5c04167a RS |
18504 | length = (ext ? 4 : 2); |
18505 | gas_assert (mips16_opcode_length (insn) == length); | |
18506 | write_compressed_insn (buf, insn, length); | |
18507 | fragp->fr_fix += length; | |
252b5132 RH |
18508 | } |
18509 | else | |
18510 | { | |
df58fc94 RS |
18511 | relax_substateT subtype = fragp->fr_subtype; |
18512 | bfd_boolean second_longer = (subtype & RELAX_SECOND_LONGER) != 0; | |
18513 | bfd_boolean use_second = (subtype & RELAX_USE_SECOND) != 0; | |
4d7206a2 RS |
18514 | int first, second; |
18515 | fixS *fixp; | |
252b5132 | 18516 | |
df58fc94 RS |
18517 | first = RELAX_FIRST (subtype); |
18518 | second = RELAX_SECOND (subtype); | |
4d7206a2 | 18519 | fixp = (fixS *) fragp->fr_opcode; |
252b5132 | 18520 | |
df58fc94 RS |
18521 | /* If the delay slot chosen does not match the size of the instruction, |
18522 | then emit a warning. */ | |
18523 | if ((!use_second && (subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0) | |
18524 | || (use_second && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0)) | |
18525 | { | |
18526 | relax_substateT s; | |
18527 | const char *msg; | |
18528 | ||
18529 | s = subtype & (RELAX_DELAY_SLOT_16BIT | |
18530 | | RELAX_DELAY_SLOT_SIZE_FIRST | |
18531 | | RELAX_DELAY_SLOT_SIZE_SECOND); | |
18532 | msg = macro_warning (s); | |
18533 | if (msg != NULL) | |
db9b2be4 | 18534 | as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg); |
df58fc94 RS |
18535 | subtype &= ~s; |
18536 | } | |
18537 | ||
584892a6 | 18538 | /* Possibly emit a warning if we've chosen the longer option. */ |
df58fc94 | 18539 | if (use_second == second_longer) |
584892a6 | 18540 | { |
df58fc94 RS |
18541 | relax_substateT s; |
18542 | const char *msg; | |
18543 | ||
18544 | s = (subtype | |
18545 | & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT)); | |
18546 | msg = macro_warning (s); | |
18547 | if (msg != NULL) | |
db9b2be4 | 18548 | as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg); |
df58fc94 | 18549 | subtype &= ~s; |
584892a6 RS |
18550 | } |
18551 | ||
4d7206a2 RS |
18552 | /* Go through all the fixups for the first sequence. Disable them |
18553 | (by marking them as done) if we're going to use the second | |
18554 | sequence instead. */ | |
18555 | while (fixp | |
18556 | && fixp->fx_frag == fragp | |
18557 | && fixp->fx_where < fragp->fr_fix - second) | |
18558 | { | |
df58fc94 | 18559 | if (subtype & RELAX_USE_SECOND) |
4d7206a2 RS |
18560 | fixp->fx_done = 1; |
18561 | fixp = fixp->fx_next; | |
18562 | } | |
252b5132 | 18563 | |
4d7206a2 RS |
18564 | /* Go through the fixups for the second sequence. Disable them if |
18565 | we're going to use the first sequence, otherwise adjust their | |
18566 | addresses to account for the relaxation. */ | |
18567 | while (fixp && fixp->fx_frag == fragp) | |
18568 | { | |
df58fc94 | 18569 | if (subtype & RELAX_USE_SECOND) |
4d7206a2 RS |
18570 | fixp->fx_where -= first; |
18571 | else | |
18572 | fixp->fx_done = 1; | |
18573 | fixp = fixp->fx_next; | |
18574 | } | |
18575 | ||
18576 | /* Now modify the frag contents. */ | |
df58fc94 | 18577 | if (subtype & RELAX_USE_SECOND) |
4d7206a2 RS |
18578 | { |
18579 | char *start; | |
18580 | ||
18581 | start = fragp->fr_literal + fragp->fr_fix - first - second; | |
18582 | memmove (start, start + first, second); | |
18583 | fragp->fr_fix -= first; | |
18584 | } | |
18585 | else | |
18586 | fragp->fr_fix -= second; | |
252b5132 RH |
18587 | } |
18588 | } | |
18589 | ||
18590 | #ifdef OBJ_ELF | |
18591 | ||
18592 | /* This function is called after the relocs have been generated. | |
18593 | We've been storing mips16 text labels as odd. Here we convert them | |
18594 | back to even for the convenience of the debugger. */ | |
18595 | ||
18596 | void | |
17a2f251 | 18597 | mips_frob_file_after_relocs (void) |
252b5132 RH |
18598 | { |
18599 | asymbol **syms; | |
18600 | unsigned int count, i; | |
18601 | ||
f43abd2b | 18602 | if (!IS_ELF) |
252b5132 RH |
18603 | return; |
18604 | ||
18605 | syms = bfd_get_outsymbols (stdoutput); | |
18606 | count = bfd_get_symcount (stdoutput); | |
18607 | for (i = 0; i < count; i++, syms++) | |
df58fc94 RS |
18608 | if (ELF_ST_IS_COMPRESSED (elf_symbol (*syms)->internal_elf_sym.st_other) |
18609 | && ((*syms)->value & 1) != 0) | |
18610 | { | |
18611 | (*syms)->value &= ~1; | |
18612 | /* If the symbol has an odd size, it was probably computed | |
18613 | incorrectly, so adjust that as well. */ | |
18614 | if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0) | |
18615 | ++elf_symbol (*syms)->internal_elf_sym.st_size; | |
18616 | } | |
252b5132 RH |
18617 | } |
18618 | ||
18619 | #endif | |
18620 | ||
a1facbec MR |
18621 | /* This function is called whenever a label is defined, including fake |
18622 | labels instantiated off the dot special symbol. It is used when | |
18623 | handling branch delays; if a branch has a label, we assume we cannot | |
18624 | move it. This also bumps the value of the symbol by 1 in compressed | |
18625 | code. */ | |
252b5132 | 18626 | |
e1b47bd5 | 18627 | static void |
a1facbec | 18628 | mips_record_label (symbolS *sym) |
252b5132 | 18629 | { |
a8dbcb85 | 18630 | segment_info_type *si = seg_info (now_seg); |
252b5132 RH |
18631 | struct insn_label_list *l; |
18632 | ||
18633 | if (free_insn_labels == NULL) | |
18634 | l = (struct insn_label_list *) xmalloc (sizeof *l); | |
18635 | else | |
18636 | { | |
18637 | l = free_insn_labels; | |
18638 | free_insn_labels = l->next; | |
18639 | } | |
18640 | ||
18641 | l->label = sym; | |
a8dbcb85 TS |
18642 | l->next = si->label_list; |
18643 | si->label_list = l; | |
a1facbec | 18644 | } |
07a53e5c | 18645 | |
a1facbec MR |
18646 | /* This function is called as tc_frob_label() whenever a label is defined |
18647 | and adds a DWARF-2 record we only want for true labels. */ | |
18648 | ||
18649 | void | |
18650 | mips_define_label (symbolS *sym) | |
18651 | { | |
18652 | mips_record_label (sym); | |
07a53e5c RH |
18653 | #ifdef OBJ_ELF |
18654 | dwarf2_emit_label (sym); | |
18655 | #endif | |
252b5132 | 18656 | } |
e1b47bd5 RS |
18657 | |
18658 | /* This function is called by tc_new_dot_label whenever a new dot symbol | |
18659 | is defined. */ | |
18660 | ||
18661 | void | |
18662 | mips_add_dot_label (symbolS *sym) | |
18663 | { | |
18664 | mips_record_label (sym); | |
18665 | if (mips_assembling_insn && HAVE_CODE_COMPRESSION) | |
18666 | mips_compressed_mark_label (sym); | |
18667 | } | |
252b5132 RH |
18668 | \f |
18669 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
18670 | ||
18671 | /* Some special processing for a MIPS ELF file. */ | |
18672 | ||
18673 | void | |
17a2f251 | 18674 | mips_elf_final_processing (void) |
252b5132 RH |
18675 | { |
18676 | /* Write out the register information. */ | |
316f5878 | 18677 | if (mips_abi != N64_ABI) |
252b5132 RH |
18678 | { |
18679 | Elf32_RegInfo s; | |
18680 | ||
18681 | s.ri_gprmask = mips_gprmask; | |
18682 | s.ri_cprmask[0] = mips_cprmask[0]; | |
18683 | s.ri_cprmask[1] = mips_cprmask[1]; | |
18684 | s.ri_cprmask[2] = mips_cprmask[2]; | |
18685 | s.ri_cprmask[3] = mips_cprmask[3]; | |
18686 | /* The gp_value field is set by the MIPS ELF backend. */ | |
18687 | ||
18688 | bfd_mips_elf32_swap_reginfo_out (stdoutput, &s, | |
18689 | ((Elf32_External_RegInfo *) | |
18690 | mips_regmask_frag)); | |
18691 | } | |
18692 | else | |
18693 | { | |
18694 | Elf64_Internal_RegInfo s; | |
18695 | ||
18696 | s.ri_gprmask = mips_gprmask; | |
18697 | s.ri_pad = 0; | |
18698 | s.ri_cprmask[0] = mips_cprmask[0]; | |
18699 | s.ri_cprmask[1] = mips_cprmask[1]; | |
18700 | s.ri_cprmask[2] = mips_cprmask[2]; | |
18701 | s.ri_cprmask[3] = mips_cprmask[3]; | |
18702 | /* The gp_value field is set by the MIPS ELF backend. */ | |
18703 | ||
18704 | bfd_mips_elf64_swap_reginfo_out (stdoutput, &s, | |
18705 | ((Elf64_External_RegInfo *) | |
18706 | mips_regmask_frag)); | |
18707 | } | |
18708 | ||
18709 | /* Set the MIPS ELF flag bits. FIXME: There should probably be some | |
18710 | sort of BFD interface for this. */ | |
18711 | if (mips_any_noreorder) | |
18712 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER; | |
18713 | if (mips_pic != NO_PIC) | |
143d77c5 | 18714 | { |
8b828383 | 18715 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC; |
143d77c5 EC |
18716 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC; |
18717 | } | |
18718 | if (mips_abicalls) | |
18719 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC; | |
252b5132 | 18720 | |
98d3f06f | 18721 | /* Set MIPS ELF flags for ASEs. */ |
74cd071d CF |
18722 | /* We may need to define a new flag for DSP ASE, and set this flag when |
18723 | file_ase_dsp is true. */ | |
8b082fb1 | 18724 | /* Same for DSP R2. */ |
ef2e4d86 CF |
18725 | /* We may need to define a new flag for MT ASE, and set this flag when |
18726 | file_ase_mt is true. */ | |
a4672219 TS |
18727 | if (file_ase_mips16) |
18728 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16; | |
df58fc94 RS |
18729 | if (file_ase_micromips) |
18730 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MICROMIPS; | |
1f25f5d3 CD |
18731 | #if 0 /* XXX FIXME */ |
18732 | if (file_ase_mips3d) | |
18733 | elf_elfheader (stdoutput)->e_flags |= ???; | |
18734 | #endif | |
deec1734 CD |
18735 | if (file_ase_mdmx) |
18736 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX; | |
1f25f5d3 | 18737 | |
bdaaa2e1 | 18738 | /* Set the MIPS ELF ABI flags. */ |
316f5878 | 18739 | if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32) |
252b5132 | 18740 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32; |
316f5878 | 18741 | else if (mips_abi == O64_ABI) |
252b5132 | 18742 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64; |
316f5878 | 18743 | else if (mips_abi == EABI_ABI) |
252b5132 | 18744 | { |
316f5878 | 18745 | if (!file_mips_gp32) |
252b5132 RH |
18746 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64; |
18747 | else | |
18748 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32; | |
18749 | } | |
316f5878 | 18750 | else if (mips_abi == N32_ABI) |
be00bddd TS |
18751 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2; |
18752 | ||
c9914766 | 18753 | /* Nothing to do for N64_ABI. */ |
252b5132 RH |
18754 | |
18755 | if (mips_32bitmode) | |
18756 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE; | |
ad3fea08 TS |
18757 | |
18758 | #if 0 /* XXX FIXME */ | |
18759 | /* 32 bit code with 64 bit FP registers. */ | |
18760 | if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi)) | |
18761 | elf_elfheader (stdoutput)->e_flags |= ???; | |
18762 | #endif | |
252b5132 RH |
18763 | } |
18764 | ||
18765 | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ | |
18766 | \f | |
beae10d5 | 18767 | typedef struct proc { |
9b2f1d35 EC |
18768 | symbolS *func_sym; |
18769 | symbolS *func_end_sym; | |
beae10d5 KH |
18770 | unsigned long reg_mask; |
18771 | unsigned long reg_offset; | |
18772 | unsigned long fpreg_mask; | |
18773 | unsigned long fpreg_offset; | |
18774 | unsigned long frame_offset; | |
18775 | unsigned long frame_reg; | |
18776 | unsigned long pc_reg; | |
18777 | } procS; | |
252b5132 RH |
18778 | |
18779 | static procS cur_proc; | |
18780 | static procS *cur_proc_ptr; | |
18781 | static int numprocs; | |
18782 | ||
df58fc94 RS |
18783 | /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1", a microMIPS nop |
18784 | as "2", and a normal nop as "0". */ | |
18785 | ||
18786 | #define NOP_OPCODE_MIPS 0 | |
18787 | #define NOP_OPCODE_MIPS16 1 | |
18788 | #define NOP_OPCODE_MICROMIPS 2 | |
742a56fe RS |
18789 | |
18790 | char | |
18791 | mips_nop_opcode (void) | |
18792 | { | |
df58fc94 RS |
18793 | if (seg_info (now_seg)->tc_segment_info_data.micromips) |
18794 | return NOP_OPCODE_MICROMIPS; | |
18795 | else if (seg_info (now_seg)->tc_segment_info_data.mips16) | |
18796 | return NOP_OPCODE_MIPS16; | |
18797 | else | |
18798 | return NOP_OPCODE_MIPS; | |
742a56fe RS |
18799 | } |
18800 | ||
df58fc94 RS |
18801 | /* Fill in an rs_align_code fragment. Unlike elsewhere we want to use |
18802 | 32-bit microMIPS NOPs here (if applicable). */ | |
a19d8eb0 | 18803 | |
0a9ef439 | 18804 | void |
17a2f251 | 18805 | mips_handle_align (fragS *fragp) |
a19d8eb0 | 18806 | { |
df58fc94 | 18807 | char nop_opcode; |
742a56fe | 18808 | char *p; |
c67a084a NC |
18809 | int bytes, size, excess; |
18810 | valueT opcode; | |
742a56fe | 18811 | |
0a9ef439 RH |
18812 | if (fragp->fr_type != rs_align_code) |
18813 | return; | |
18814 | ||
742a56fe | 18815 | p = fragp->fr_literal + fragp->fr_fix; |
df58fc94 RS |
18816 | nop_opcode = *p; |
18817 | switch (nop_opcode) | |
a19d8eb0 | 18818 | { |
df58fc94 RS |
18819 | case NOP_OPCODE_MICROMIPS: |
18820 | opcode = micromips_nop32_insn.insn_opcode; | |
18821 | size = 4; | |
18822 | break; | |
18823 | case NOP_OPCODE_MIPS16: | |
c67a084a NC |
18824 | opcode = mips16_nop_insn.insn_opcode; |
18825 | size = 2; | |
df58fc94 RS |
18826 | break; |
18827 | case NOP_OPCODE_MIPS: | |
18828 | default: | |
c67a084a NC |
18829 | opcode = nop_insn.insn_opcode; |
18830 | size = 4; | |
df58fc94 | 18831 | break; |
c67a084a | 18832 | } |
a19d8eb0 | 18833 | |
c67a084a NC |
18834 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
18835 | excess = bytes % size; | |
df58fc94 RS |
18836 | |
18837 | /* Handle the leading part if we're not inserting a whole number of | |
18838 | instructions, and make it the end of the fixed part of the frag. | |
18839 | Try to fit in a short microMIPS NOP if applicable and possible, | |
18840 | and use zeroes otherwise. */ | |
18841 | gas_assert (excess < 4); | |
18842 | fragp->fr_fix += excess; | |
18843 | switch (excess) | |
c67a084a | 18844 | { |
df58fc94 RS |
18845 | case 3: |
18846 | *p++ = '\0'; | |
18847 | /* Fall through. */ | |
18848 | case 2: | |
18849 | if (nop_opcode == NOP_OPCODE_MICROMIPS) | |
18850 | { | |
4d68580a | 18851 | p = write_compressed_insn (p, micromips_nop16_insn.insn_opcode, 2); |
df58fc94 RS |
18852 | break; |
18853 | } | |
18854 | *p++ = '\0'; | |
18855 | /* Fall through. */ | |
18856 | case 1: | |
18857 | *p++ = '\0'; | |
18858 | /* Fall through. */ | |
18859 | case 0: | |
18860 | break; | |
a19d8eb0 | 18861 | } |
c67a084a NC |
18862 | |
18863 | md_number_to_chars (p, opcode, size); | |
18864 | fragp->fr_var = size; | |
a19d8eb0 CP |
18865 | } |
18866 | ||
252b5132 | 18867 | static void |
17a2f251 | 18868 | md_obj_begin (void) |
252b5132 RH |
18869 | { |
18870 | } | |
18871 | ||
18872 | static void | |
17a2f251 | 18873 | md_obj_end (void) |
252b5132 | 18874 | { |
54f4ddb3 | 18875 | /* Check for premature end, nesting errors, etc. */ |
252b5132 | 18876 | if (cur_proc_ptr) |
9a41af64 | 18877 | as_warn (_("missing .end at end of assembly")); |
252b5132 RH |
18878 | } |
18879 | ||
18880 | static long | |
17a2f251 | 18881 | get_number (void) |
252b5132 RH |
18882 | { |
18883 | int negative = 0; | |
18884 | long val = 0; | |
18885 | ||
18886 | if (*input_line_pointer == '-') | |
18887 | { | |
18888 | ++input_line_pointer; | |
18889 | negative = 1; | |
18890 | } | |
3882b010 | 18891 | if (!ISDIGIT (*input_line_pointer)) |
956cd1d6 | 18892 | as_bad (_("expected simple number")); |
252b5132 RH |
18893 | if (input_line_pointer[0] == '0') |
18894 | { | |
18895 | if (input_line_pointer[1] == 'x') | |
18896 | { | |
18897 | input_line_pointer += 2; | |
3882b010 | 18898 | while (ISXDIGIT (*input_line_pointer)) |
252b5132 RH |
18899 | { |
18900 | val <<= 4; | |
18901 | val |= hex_value (*input_line_pointer++); | |
18902 | } | |
18903 | return negative ? -val : val; | |
18904 | } | |
18905 | else | |
18906 | { | |
18907 | ++input_line_pointer; | |
3882b010 | 18908 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
18909 | { |
18910 | val <<= 3; | |
18911 | val |= *input_line_pointer++ - '0'; | |
18912 | } | |
18913 | return negative ? -val : val; | |
18914 | } | |
18915 | } | |
3882b010 | 18916 | if (!ISDIGIT (*input_line_pointer)) |
252b5132 RH |
18917 | { |
18918 | printf (_(" *input_line_pointer == '%c' 0x%02x\n"), | |
18919 | *input_line_pointer, *input_line_pointer); | |
956cd1d6 | 18920 | as_warn (_("invalid number")); |
252b5132 RH |
18921 | return -1; |
18922 | } | |
3882b010 | 18923 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
18924 | { |
18925 | val *= 10; | |
18926 | val += *input_line_pointer++ - '0'; | |
18927 | } | |
18928 | return negative ? -val : val; | |
18929 | } | |
18930 | ||
18931 | /* The .file directive; just like the usual .file directive, but there | |
c5dd6aab DJ |
18932 | is an initial number which is the ECOFF file index. In the non-ECOFF |
18933 | case .file implies DWARF-2. */ | |
18934 | ||
18935 | static void | |
17a2f251 | 18936 | s_mips_file (int x ATTRIBUTE_UNUSED) |
c5dd6aab | 18937 | { |
ecb4347a DJ |
18938 | static int first_file_directive = 0; |
18939 | ||
c5dd6aab DJ |
18940 | if (ECOFF_DEBUGGING) |
18941 | { | |
18942 | get_number (); | |
18943 | s_app_file (0); | |
18944 | } | |
18945 | else | |
ecb4347a DJ |
18946 | { |
18947 | char *filename; | |
18948 | ||
18949 | filename = dwarf2_directive_file (0); | |
18950 | ||
18951 | /* Versions of GCC up to 3.1 start files with a ".file" | |
18952 | directive even for stabs output. Make sure that this | |
18953 | ".file" is handled. Note that you need a version of GCC | |
18954 | after 3.1 in order to support DWARF-2 on MIPS. */ | |
18955 | if (filename != NULL && ! first_file_directive) | |
18956 | { | |
18957 | (void) new_logical_line (filename, -1); | |
c04f5787 | 18958 | s_app_file_string (filename, 0); |
ecb4347a DJ |
18959 | } |
18960 | first_file_directive = 1; | |
18961 | } | |
c5dd6aab DJ |
18962 | } |
18963 | ||
18964 | /* The .loc directive, implying DWARF-2. */ | |
252b5132 RH |
18965 | |
18966 | static void | |
17a2f251 | 18967 | s_mips_loc (int x ATTRIBUTE_UNUSED) |
252b5132 | 18968 | { |
c5dd6aab DJ |
18969 | if (!ECOFF_DEBUGGING) |
18970 | dwarf2_directive_loc (0); | |
252b5132 RH |
18971 | } |
18972 | ||
252b5132 RH |
18973 | /* The .end directive. */ |
18974 | ||
18975 | static void | |
17a2f251 | 18976 | s_mips_end (int x ATTRIBUTE_UNUSED) |
252b5132 RH |
18977 | { |
18978 | symbolS *p; | |
252b5132 | 18979 | |
7a621144 DJ |
18980 | /* Following functions need their own .frame and .cprestore directives. */ |
18981 | mips_frame_reg_valid = 0; | |
18982 | mips_cprestore_valid = 0; | |
18983 | ||
252b5132 RH |
18984 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
18985 | { | |
18986 | p = get_symbol (); | |
18987 | demand_empty_rest_of_line (); | |
18988 | } | |
18989 | else | |
18990 | p = NULL; | |
18991 | ||
14949570 | 18992 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0) |
252b5132 RH |
18993 | as_warn (_(".end not in text section")); |
18994 | ||
18995 | if (!cur_proc_ptr) | |
18996 | { | |
18997 | as_warn (_(".end directive without a preceding .ent directive.")); | |
18998 | demand_empty_rest_of_line (); | |
18999 | return; | |
19000 | } | |
19001 | ||
19002 | if (p != NULL) | |
19003 | { | |
9c2799c2 | 19004 | gas_assert (S_GET_NAME (p)); |
9b2f1d35 | 19005 | if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym))) |
252b5132 | 19006 | as_warn (_(".end symbol does not match .ent symbol.")); |
ecb4347a DJ |
19007 | |
19008 | if (debug_type == DEBUG_STABS) | |
19009 | stabs_generate_asm_endfunc (S_GET_NAME (p), | |
19010 | S_GET_NAME (p)); | |
252b5132 RH |
19011 | } |
19012 | else | |
19013 | as_warn (_(".end directive missing or unknown symbol")); | |
19014 | ||
2132e3a3 | 19015 | #ifdef OBJ_ELF |
9b2f1d35 EC |
19016 | /* Create an expression to calculate the size of the function. */ |
19017 | if (p && cur_proc_ptr) | |
19018 | { | |
19019 | OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p); | |
19020 | expressionS *exp = xmalloc (sizeof (expressionS)); | |
19021 | ||
19022 | obj->size = exp; | |
19023 | exp->X_op = O_subtract; | |
19024 | exp->X_add_symbol = symbol_temp_new_now (); | |
19025 | exp->X_op_symbol = p; | |
19026 | exp->X_add_number = 0; | |
19027 | ||
19028 | cur_proc_ptr->func_end_sym = exp->X_add_symbol; | |
19029 | } | |
19030 | ||
ecb4347a | 19031 | /* Generate a .pdr section. */ |
f43abd2b | 19032 | if (IS_ELF && !ECOFF_DEBUGGING && mips_flag_pdr) |
ecb4347a DJ |
19033 | { |
19034 | segT saved_seg = now_seg; | |
19035 | subsegT saved_subseg = now_subseg; | |
ecb4347a DJ |
19036 | expressionS exp; |
19037 | char *fragp; | |
252b5132 | 19038 | |
252b5132 | 19039 | #ifdef md_flush_pending_output |
ecb4347a | 19040 | md_flush_pending_output (); |
252b5132 RH |
19041 | #endif |
19042 | ||
9c2799c2 | 19043 | gas_assert (pdr_seg); |
ecb4347a | 19044 | subseg_set (pdr_seg, 0); |
252b5132 | 19045 | |
ecb4347a DJ |
19046 | /* Write the symbol. */ |
19047 | exp.X_op = O_symbol; | |
19048 | exp.X_add_symbol = p; | |
19049 | exp.X_add_number = 0; | |
19050 | emit_expr (&exp, 4); | |
252b5132 | 19051 | |
ecb4347a | 19052 | fragp = frag_more (7 * 4); |
252b5132 | 19053 | |
17a2f251 TS |
19054 | md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4); |
19055 | md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4); | |
19056 | md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4); | |
19057 | md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4); | |
19058 | md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4); | |
19059 | md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4); | |
19060 | md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4); | |
252b5132 | 19061 | |
ecb4347a DJ |
19062 | subseg_set (saved_seg, saved_subseg); |
19063 | } | |
19064 | #endif /* OBJ_ELF */ | |
252b5132 RH |
19065 | |
19066 | cur_proc_ptr = NULL; | |
19067 | } | |
19068 | ||
19069 | /* The .aent and .ent directives. */ | |
19070 | ||
19071 | static void | |
17a2f251 | 19072 | s_mips_ent (int aent) |
252b5132 | 19073 | { |
252b5132 | 19074 | symbolS *symbolP; |
252b5132 RH |
19075 | |
19076 | symbolP = get_symbol (); | |
19077 | if (*input_line_pointer == ',') | |
f9419b05 | 19078 | ++input_line_pointer; |
252b5132 | 19079 | SKIP_WHITESPACE (); |
3882b010 | 19080 | if (ISDIGIT (*input_line_pointer) |
d9a62219 | 19081 | || *input_line_pointer == '-') |
874e8986 | 19082 | get_number (); |
252b5132 | 19083 | |
14949570 | 19084 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0) |
252b5132 RH |
19085 | as_warn (_(".ent or .aent not in text section.")); |
19086 | ||
19087 | if (!aent && cur_proc_ptr) | |
9a41af64 | 19088 | as_warn (_("missing .end")); |
252b5132 RH |
19089 | |
19090 | if (!aent) | |
19091 | { | |
7a621144 DJ |
19092 | /* This function needs its own .frame and .cprestore directives. */ |
19093 | mips_frame_reg_valid = 0; | |
19094 | mips_cprestore_valid = 0; | |
19095 | ||
252b5132 RH |
19096 | cur_proc_ptr = &cur_proc; |
19097 | memset (cur_proc_ptr, '\0', sizeof (procS)); | |
19098 | ||
9b2f1d35 | 19099 | cur_proc_ptr->func_sym = symbolP; |
252b5132 | 19100 | |
f9419b05 | 19101 | ++numprocs; |
ecb4347a DJ |
19102 | |
19103 | if (debug_type == DEBUG_STABS) | |
19104 | stabs_generate_asm_func (S_GET_NAME (symbolP), | |
19105 | S_GET_NAME (symbolP)); | |
252b5132 RH |
19106 | } |
19107 | ||
7c0fc524 MR |
19108 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
19109 | ||
252b5132 RH |
19110 | demand_empty_rest_of_line (); |
19111 | } | |
19112 | ||
19113 | /* The .frame directive. If the mdebug section is present (IRIX 5 native) | |
bdaaa2e1 | 19114 | then ecoff.c (ecoff_directive_frame) is used. For embedded targets, |
252b5132 | 19115 | s_mips_frame is used so that we can set the PDR information correctly. |
bdaaa2e1 | 19116 | We can't use the ecoff routines because they make reference to the ecoff |
252b5132 RH |
19117 | symbol table (in the mdebug section). */ |
19118 | ||
19119 | static void | |
17a2f251 | 19120 | s_mips_frame (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 19121 | { |
ecb4347a | 19122 | #ifdef OBJ_ELF |
f43abd2b | 19123 | if (IS_ELF && !ECOFF_DEBUGGING) |
ecb4347a DJ |
19124 | { |
19125 | long val; | |
252b5132 | 19126 | |
ecb4347a DJ |
19127 | if (cur_proc_ptr == (procS *) NULL) |
19128 | { | |
19129 | as_warn (_(".frame outside of .ent")); | |
19130 | demand_empty_rest_of_line (); | |
19131 | return; | |
19132 | } | |
252b5132 | 19133 | |
ecb4347a DJ |
19134 | cur_proc_ptr->frame_reg = tc_get_register (1); |
19135 | ||
19136 | SKIP_WHITESPACE (); | |
19137 | if (*input_line_pointer++ != ',' | |
19138 | || get_absolute_expression_and_terminator (&val) != ',') | |
19139 | { | |
19140 | as_warn (_("Bad .frame directive")); | |
19141 | --input_line_pointer; | |
19142 | demand_empty_rest_of_line (); | |
19143 | return; | |
19144 | } | |
252b5132 | 19145 | |
ecb4347a DJ |
19146 | cur_proc_ptr->frame_offset = val; |
19147 | cur_proc_ptr->pc_reg = tc_get_register (0); | |
252b5132 | 19148 | |
252b5132 | 19149 | demand_empty_rest_of_line (); |
252b5132 | 19150 | } |
ecb4347a DJ |
19151 | else |
19152 | #endif /* OBJ_ELF */ | |
19153 | s_ignore (ignore); | |
252b5132 RH |
19154 | } |
19155 | ||
bdaaa2e1 KH |
19156 | /* The .fmask and .mask directives. If the mdebug section is present |
19157 | (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For | |
252b5132 | 19158 | embedded targets, s_mips_mask is used so that we can set the PDR |
bdaaa2e1 | 19159 | information correctly. We can't use the ecoff routines because they |
252b5132 RH |
19160 | make reference to the ecoff symbol table (in the mdebug section). */ |
19161 | ||
19162 | static void | |
17a2f251 | 19163 | s_mips_mask (int reg_type) |
252b5132 | 19164 | { |
ecb4347a | 19165 | #ifdef OBJ_ELF |
f43abd2b | 19166 | if (IS_ELF && !ECOFF_DEBUGGING) |
252b5132 | 19167 | { |
ecb4347a | 19168 | long mask, off; |
252b5132 | 19169 | |
ecb4347a DJ |
19170 | if (cur_proc_ptr == (procS *) NULL) |
19171 | { | |
19172 | as_warn (_(".mask/.fmask outside of .ent")); | |
19173 | demand_empty_rest_of_line (); | |
19174 | return; | |
19175 | } | |
252b5132 | 19176 | |
ecb4347a DJ |
19177 | if (get_absolute_expression_and_terminator (&mask) != ',') |
19178 | { | |
19179 | as_warn (_("Bad .mask/.fmask directive")); | |
19180 | --input_line_pointer; | |
19181 | demand_empty_rest_of_line (); | |
19182 | return; | |
19183 | } | |
252b5132 | 19184 | |
ecb4347a DJ |
19185 | off = get_absolute_expression (); |
19186 | ||
19187 | if (reg_type == 'F') | |
19188 | { | |
19189 | cur_proc_ptr->fpreg_mask = mask; | |
19190 | cur_proc_ptr->fpreg_offset = off; | |
19191 | } | |
19192 | else | |
19193 | { | |
19194 | cur_proc_ptr->reg_mask = mask; | |
19195 | cur_proc_ptr->reg_offset = off; | |
19196 | } | |
19197 | ||
19198 | demand_empty_rest_of_line (); | |
252b5132 RH |
19199 | } |
19200 | else | |
ecb4347a DJ |
19201 | #endif /* OBJ_ELF */ |
19202 | s_ignore (reg_type); | |
252b5132 RH |
19203 | } |
19204 | ||
316f5878 RS |
19205 | /* A table describing all the processors gas knows about. Names are |
19206 | matched in the order listed. | |
e7af610e | 19207 | |
316f5878 RS |
19208 | To ease comparison, please keep this table in the same order as |
19209 | gcc's mips_cpu_info_table[]. */ | |
e972090a NC |
19210 | static const struct mips_cpu_info mips_cpu_info_table[] = |
19211 | { | |
316f5878 | 19212 | /* Entries for generic ISAs */ |
ad3fea08 TS |
19213 | { "mips1", MIPS_CPU_IS_ISA, ISA_MIPS1, CPU_R3000 }, |
19214 | { "mips2", MIPS_CPU_IS_ISA, ISA_MIPS2, CPU_R6000 }, | |
19215 | { "mips3", MIPS_CPU_IS_ISA, ISA_MIPS3, CPU_R4000 }, | |
19216 | { "mips4", MIPS_CPU_IS_ISA, ISA_MIPS4, CPU_R8000 }, | |
19217 | { "mips5", MIPS_CPU_IS_ISA, ISA_MIPS5, CPU_MIPS5 }, | |
19218 | { "mips32", MIPS_CPU_IS_ISA, ISA_MIPS32, CPU_MIPS32 }, | |
19219 | { "mips32r2", MIPS_CPU_IS_ISA, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19220 | { "mips64", MIPS_CPU_IS_ISA, ISA_MIPS64, CPU_MIPS64 }, | |
19221 | { "mips64r2", MIPS_CPU_IS_ISA, ISA_MIPS64R2, CPU_MIPS64R2 }, | |
316f5878 RS |
19222 | |
19223 | /* MIPS I */ | |
ad3fea08 TS |
19224 | { "r3000", 0, ISA_MIPS1, CPU_R3000 }, |
19225 | { "r2000", 0, ISA_MIPS1, CPU_R3000 }, | |
19226 | { "r3900", 0, ISA_MIPS1, CPU_R3900 }, | |
316f5878 RS |
19227 | |
19228 | /* MIPS II */ | |
ad3fea08 | 19229 | { "r6000", 0, ISA_MIPS2, CPU_R6000 }, |
316f5878 RS |
19230 | |
19231 | /* MIPS III */ | |
ad3fea08 TS |
19232 | { "r4000", 0, ISA_MIPS3, CPU_R4000 }, |
19233 | { "r4010", 0, ISA_MIPS2, CPU_R4010 }, | |
19234 | { "vr4100", 0, ISA_MIPS3, CPU_VR4100 }, | |
19235 | { "vr4111", 0, ISA_MIPS3, CPU_R4111 }, | |
19236 | { "vr4120", 0, ISA_MIPS3, CPU_VR4120 }, | |
19237 | { "vr4130", 0, ISA_MIPS3, CPU_VR4120 }, | |
19238 | { "vr4181", 0, ISA_MIPS3, CPU_R4111 }, | |
19239 | { "vr4300", 0, ISA_MIPS3, CPU_R4300 }, | |
19240 | { "r4400", 0, ISA_MIPS3, CPU_R4400 }, | |
19241 | { "r4600", 0, ISA_MIPS3, CPU_R4600 }, | |
19242 | { "orion", 0, ISA_MIPS3, CPU_R4600 }, | |
19243 | { "r4650", 0, ISA_MIPS3, CPU_R4650 }, | |
e407c74b | 19244 | { "r5900", 0, ISA_MIPS3, CPU_R5900 }, |
b15591bb AN |
19245 | /* ST Microelectronics Loongson 2E and 2F cores */ |
19246 | { "loongson2e", 0, ISA_MIPS3, CPU_LOONGSON_2E }, | |
19247 | { "loongson2f", 0, ISA_MIPS3, CPU_LOONGSON_2F }, | |
316f5878 RS |
19248 | |
19249 | /* MIPS IV */ | |
ad3fea08 TS |
19250 | { "r8000", 0, ISA_MIPS4, CPU_R8000 }, |
19251 | { "r10000", 0, ISA_MIPS4, CPU_R10000 }, | |
19252 | { "r12000", 0, ISA_MIPS4, CPU_R12000 }, | |
3aa3176b TS |
19253 | { "r14000", 0, ISA_MIPS4, CPU_R14000 }, |
19254 | { "r16000", 0, ISA_MIPS4, CPU_R16000 }, | |
ad3fea08 TS |
19255 | { "vr5000", 0, ISA_MIPS4, CPU_R5000 }, |
19256 | { "vr5400", 0, ISA_MIPS4, CPU_VR5400 }, | |
19257 | { "vr5500", 0, ISA_MIPS4, CPU_VR5500 }, | |
19258 | { "rm5200", 0, ISA_MIPS4, CPU_R5000 }, | |
19259 | { "rm5230", 0, ISA_MIPS4, CPU_R5000 }, | |
19260 | { "rm5231", 0, ISA_MIPS4, CPU_R5000 }, | |
19261 | { "rm5261", 0, ISA_MIPS4, CPU_R5000 }, | |
19262 | { "rm5721", 0, ISA_MIPS4, CPU_R5000 }, | |
19263 | { "rm7000", 0, ISA_MIPS4, CPU_RM7000 }, | |
19264 | { "rm9000", 0, ISA_MIPS4, CPU_RM9000 }, | |
316f5878 RS |
19265 | |
19266 | /* MIPS 32 */ | |
ad3fea08 TS |
19267 | { "4kc", 0, ISA_MIPS32, CPU_MIPS32 }, |
19268 | { "4km", 0, ISA_MIPS32, CPU_MIPS32 }, | |
19269 | { "4kp", 0, ISA_MIPS32, CPU_MIPS32 }, | |
19270 | { "4ksc", MIPS_CPU_ASE_SMARTMIPS, ISA_MIPS32, CPU_MIPS32 }, | |
19271 | ||
19272 | /* MIPS 32 Release 2 */ | |
19273 | { "4kec", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19274 | { "4kem", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19275 | { "4kep", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19276 | { "4ksd", MIPS_CPU_ASE_SMARTMIPS, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19277 | { "m4k", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19278 | { "m4kp", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
b5503c7b MR |
19279 | { "m14k", MIPS_CPU_ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 }, |
19280 | { "m14kc", MIPS_CPU_ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
7a795ef4 MR |
19281 | { "m14ke", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2 | MIPS_CPU_ASE_MCU, |
19282 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19283 | { "m14kec", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2 | MIPS_CPU_ASE_MCU, | |
19284 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
ad3fea08 | 19285 | { "24kc", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
0fdf1951 | 19286 | { "24kf2_1", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
ad3fea08 | 19287 | { "24kf", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
0fdf1951 RS |
19288 | { "24kf1_1", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
19289 | /* Deprecated forms of the above. */ | |
19290 | { "24kfx", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
ad3fea08 | 19291 | { "24kx", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
01fd108f | 19292 | /* 24KE is a 24K with DSP ASE, other ASEs are optional. */ |
ad3fea08 | 19293 | { "24kec", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
0fdf1951 | 19294 | { "24kef2_1", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
ad3fea08 | 19295 | { "24kef", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
0fdf1951 RS |
19296 | { "24kef1_1", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
19297 | /* Deprecated forms of the above. */ | |
19298 | { "24kefx", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
65263ce3 | 19299 | { "24kex", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
01fd108f | 19300 | /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */ |
a360e743 TS |
19301 | { "34kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
19302 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
0fdf1951 RS |
19303 | { "34kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
19304 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
a360e743 TS |
19305 | { "34kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
19306 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
0fdf1951 RS |
19307 | { "34kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
19308 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19309 | /* Deprecated forms of the above. */ | |
19310 | { "34kfx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, | |
19311 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
a360e743 TS |
19312 | { "34kx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
19313 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
711eefe4 SL |
19314 | /* 34Kn is a 34kc without DSP. */ |
19315 | { "34kn", MIPS_CPU_ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 }, | |
01fd108f TS |
19316 | /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */ |
19317 | { "74kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, | |
19318 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
0fdf1951 RS |
19319 | { "74kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
19320 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
01fd108f TS |
19321 | { "74kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
19322 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
0fdf1951 RS |
19323 | { "74kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
19324 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19325 | { "74kf3_2", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, | |
19326 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19327 | /* Deprecated forms of the above. */ | |
19328 | { "74kfx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, | |
19329 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
01fd108f TS |
19330 | { "74kx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
19331 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
30f8113a SL |
19332 | /* 1004K cores are multiprocessor versions of the 34K. */ |
19333 | { "1004kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, | |
19334 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19335 | { "1004kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, | |
19336 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19337 | { "1004kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, | |
19338 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
19339 | { "1004kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, | |
19340 | ISA_MIPS32R2, CPU_MIPS32R2 }, | |
32b26a03 | 19341 | |
316f5878 | 19342 | /* MIPS 64 */ |
ad3fea08 TS |
19343 | { "5kc", 0, ISA_MIPS64, CPU_MIPS64 }, |
19344 | { "5kf", 0, ISA_MIPS64, CPU_MIPS64 }, | |
19345 | { "20kc", MIPS_CPU_ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 }, | |
7764b395 | 19346 | { "25kf", MIPS_CPU_ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 }, |
ad3fea08 | 19347 | |
c7a23324 | 19348 | /* Broadcom SB-1 CPU core */ |
65263ce3 TS |
19349 | { "sb1", MIPS_CPU_ASE_MIPS3D | MIPS_CPU_ASE_MDMX, |
19350 | ISA_MIPS64, CPU_SB1 }, | |
1e85aad8 JW |
19351 | /* Broadcom SB-1A CPU core */ |
19352 | { "sb1a", MIPS_CPU_ASE_MIPS3D | MIPS_CPU_ASE_MDMX, | |
19353 | ISA_MIPS64, CPU_SB1 }, | |
d051516a NC |
19354 | |
19355 | { "loongson3a", 0, ISA_MIPS64, CPU_LOONGSON_3A }, | |
e7af610e | 19356 | |
ed163775 MR |
19357 | /* MIPS 64 Release 2 */ |
19358 | ||
967344c6 AN |
19359 | /* Cavium Networks Octeon CPU core */ |
19360 | { "octeon", 0, ISA_MIPS64R2, CPU_OCTEON }, | |
dd6a37e7 | 19361 | { "octeon+", 0, ISA_MIPS64R2, CPU_OCTEONP }, |
432233b3 | 19362 | { "octeon2", 0, ISA_MIPS64R2, CPU_OCTEON2 }, |
967344c6 | 19363 | |
52b6b6b9 JM |
19364 | /* RMI Xlr */ |
19365 | { "xlr", 0, ISA_MIPS64, CPU_XLR }, | |
19366 | ||
55a36193 MK |
19367 | /* Broadcom XLP. |
19368 | XLP is mostly like XLR, with the prominent exception that it is | |
19369 | MIPS64R2 rather than MIPS64. */ | |
19370 | { "xlp", 0, ISA_MIPS64R2, CPU_XLR }, | |
19371 | ||
316f5878 RS |
19372 | /* End marker */ |
19373 | { NULL, 0, 0, 0 } | |
19374 | }; | |
e7af610e | 19375 | |
84ea6cf2 | 19376 | |
316f5878 RS |
19377 | /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL |
19378 | with a final "000" replaced by "k". Ignore case. | |
e7af610e | 19379 | |
316f5878 | 19380 | Note: this function is shared between GCC and GAS. */ |
c6c98b38 | 19381 | |
b34976b6 | 19382 | static bfd_boolean |
17a2f251 | 19383 | mips_strict_matching_cpu_name_p (const char *canonical, const char *given) |
316f5878 RS |
19384 | { |
19385 | while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical)) | |
19386 | given++, canonical++; | |
19387 | ||
19388 | return ((*given == 0 && *canonical == 0) | |
19389 | || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0)); | |
19390 | } | |
19391 | ||
19392 | ||
19393 | /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied | |
19394 | CPU name. We've traditionally allowed a lot of variation here. | |
19395 | ||
19396 | Note: this function is shared between GCC and GAS. */ | |
19397 | ||
b34976b6 | 19398 | static bfd_boolean |
17a2f251 | 19399 | mips_matching_cpu_name_p (const char *canonical, const char *given) |
316f5878 RS |
19400 | { |
19401 | /* First see if the name matches exactly, or with a final "000" | |
19402 | turned into "k". */ | |
19403 | if (mips_strict_matching_cpu_name_p (canonical, given)) | |
b34976b6 | 19404 | return TRUE; |
316f5878 RS |
19405 | |
19406 | /* If not, try comparing based on numerical designation alone. | |
19407 | See if GIVEN is an unadorned number, or 'r' followed by a number. */ | |
19408 | if (TOLOWER (*given) == 'r') | |
19409 | given++; | |
19410 | if (!ISDIGIT (*given)) | |
b34976b6 | 19411 | return FALSE; |
316f5878 RS |
19412 | |
19413 | /* Skip over some well-known prefixes in the canonical name, | |
19414 | hoping to find a number there too. */ | |
19415 | if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r') | |
19416 | canonical += 2; | |
19417 | else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm') | |
19418 | canonical += 2; | |
19419 | else if (TOLOWER (canonical[0]) == 'r') | |
19420 | canonical += 1; | |
19421 | ||
19422 | return mips_strict_matching_cpu_name_p (canonical, given); | |
19423 | } | |
19424 | ||
19425 | ||
19426 | /* Parse an option that takes the name of a processor as its argument. | |
19427 | OPTION is the name of the option and CPU_STRING is the argument. | |
19428 | Return the corresponding processor enumeration if the CPU_STRING is | |
19429 | recognized, otherwise report an error and return null. | |
19430 | ||
19431 | A similar function exists in GCC. */ | |
e7af610e NC |
19432 | |
19433 | static const struct mips_cpu_info * | |
17a2f251 | 19434 | mips_parse_cpu (const char *option, const char *cpu_string) |
e7af610e | 19435 | { |
316f5878 | 19436 | const struct mips_cpu_info *p; |
e7af610e | 19437 | |
316f5878 RS |
19438 | /* 'from-abi' selects the most compatible architecture for the given |
19439 | ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the | |
19440 | EABIs, we have to decide whether we're using the 32-bit or 64-bit | |
19441 | version. Look first at the -mgp options, if given, otherwise base | |
19442 | the choice on MIPS_DEFAULT_64BIT. | |
e7af610e | 19443 | |
316f5878 RS |
19444 | Treat NO_ABI like the EABIs. One reason to do this is that the |
19445 | plain 'mips' and 'mips64' configs have 'from-abi' as their default | |
19446 | architecture. This code picks MIPS I for 'mips' and MIPS III for | |
19447 | 'mips64', just as we did in the days before 'from-abi'. */ | |
19448 | if (strcasecmp (cpu_string, "from-abi") == 0) | |
19449 | { | |
19450 | if (ABI_NEEDS_32BIT_REGS (mips_abi)) | |
19451 | return mips_cpu_info_from_isa (ISA_MIPS1); | |
19452 | ||
19453 | if (ABI_NEEDS_64BIT_REGS (mips_abi)) | |
19454 | return mips_cpu_info_from_isa (ISA_MIPS3); | |
19455 | ||
19456 | if (file_mips_gp32 >= 0) | |
19457 | return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3); | |
19458 | ||
19459 | return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT | |
19460 | ? ISA_MIPS3 | |
19461 | : ISA_MIPS1); | |
19462 | } | |
19463 | ||
19464 | /* 'default' has traditionally been a no-op. Probably not very useful. */ | |
19465 | if (strcasecmp (cpu_string, "default") == 0) | |
19466 | return 0; | |
19467 | ||
19468 | for (p = mips_cpu_info_table; p->name != 0; p++) | |
19469 | if (mips_matching_cpu_name_p (p->name, cpu_string)) | |
19470 | return p; | |
19471 | ||
20203fb9 | 19472 | as_bad (_("Bad value (%s) for %s"), cpu_string, option); |
316f5878 | 19473 | return 0; |
e7af610e NC |
19474 | } |
19475 | ||
316f5878 RS |
19476 | /* Return the canonical processor information for ISA (a member of the |
19477 | ISA_MIPS* enumeration). */ | |
19478 | ||
e7af610e | 19479 | static const struct mips_cpu_info * |
17a2f251 | 19480 | mips_cpu_info_from_isa (int isa) |
e7af610e NC |
19481 | { |
19482 | int i; | |
19483 | ||
19484 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
ad3fea08 | 19485 | if ((mips_cpu_info_table[i].flags & MIPS_CPU_IS_ISA) |
316f5878 | 19486 | && isa == mips_cpu_info_table[i].isa) |
e7af610e NC |
19487 | return (&mips_cpu_info_table[i]); |
19488 | ||
e972090a | 19489 | return NULL; |
e7af610e | 19490 | } |
fef14a42 TS |
19491 | |
19492 | static const struct mips_cpu_info * | |
17a2f251 | 19493 | mips_cpu_info_from_arch (int arch) |
fef14a42 TS |
19494 | { |
19495 | int i; | |
19496 | ||
19497 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
19498 | if (arch == mips_cpu_info_table[i].cpu) | |
19499 | return (&mips_cpu_info_table[i]); | |
19500 | ||
19501 | return NULL; | |
19502 | } | |
316f5878 RS |
19503 | \f |
19504 | static void | |
17a2f251 | 19505 | show (FILE *stream, const char *string, int *col_p, int *first_p) |
316f5878 RS |
19506 | { |
19507 | if (*first_p) | |
19508 | { | |
19509 | fprintf (stream, "%24s", ""); | |
19510 | *col_p = 24; | |
19511 | } | |
19512 | else | |
19513 | { | |
19514 | fprintf (stream, ", "); | |
19515 | *col_p += 2; | |
19516 | } | |
e7af610e | 19517 | |
316f5878 RS |
19518 | if (*col_p + strlen (string) > 72) |
19519 | { | |
19520 | fprintf (stream, "\n%24s", ""); | |
19521 | *col_p = 24; | |
19522 | } | |
19523 | ||
19524 | fprintf (stream, "%s", string); | |
19525 | *col_p += strlen (string); | |
19526 | ||
19527 | *first_p = 0; | |
19528 | } | |
19529 | ||
19530 | void | |
17a2f251 | 19531 | md_show_usage (FILE *stream) |
e7af610e | 19532 | { |
316f5878 RS |
19533 | int column, first; |
19534 | size_t i; | |
19535 | ||
19536 | fprintf (stream, _("\ | |
19537 | MIPS options:\n\ | |
316f5878 RS |
19538 | -EB generate big endian output\n\ |
19539 | -EL generate little endian output\n\ | |
19540 | -g, -g2 do not remove unneeded NOPs or swap branches\n\ | |
19541 | -G NUM allow referencing objects up to NUM bytes\n\ | |
19542 | implicitly with the gp register [default 8]\n")); | |
19543 | fprintf (stream, _("\ | |
19544 | -mips1 generate MIPS ISA I instructions\n\ | |
19545 | -mips2 generate MIPS ISA II instructions\n\ | |
19546 | -mips3 generate MIPS ISA III instructions\n\ | |
19547 | -mips4 generate MIPS ISA IV instructions\n\ | |
19548 | -mips5 generate MIPS ISA V instructions\n\ | |
19549 | -mips32 generate MIPS32 ISA instructions\n\ | |
af7ee8bf | 19550 | -mips32r2 generate MIPS32 release 2 ISA instructions\n\ |
316f5878 | 19551 | -mips64 generate MIPS64 ISA instructions\n\ |
5f74bc13 | 19552 | -mips64r2 generate MIPS64 release 2 ISA instructions\n\ |
316f5878 RS |
19553 | -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n")); |
19554 | ||
19555 | first = 1; | |
e7af610e NC |
19556 | |
19557 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
316f5878 RS |
19558 | show (stream, mips_cpu_info_table[i].name, &column, &first); |
19559 | show (stream, "from-abi", &column, &first); | |
19560 | fputc ('\n', stream); | |
e7af610e | 19561 | |
316f5878 RS |
19562 | fprintf (stream, _("\ |
19563 | -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\ | |
19564 | -no-mCPU don't generate code specific to CPU.\n\ | |
19565 | For -mCPU and -no-mCPU, CPU must be one of:\n")); | |
19566 | ||
19567 | first = 1; | |
19568 | ||
19569 | show (stream, "3900", &column, &first); | |
19570 | show (stream, "4010", &column, &first); | |
19571 | show (stream, "4100", &column, &first); | |
19572 | show (stream, "4650", &column, &first); | |
19573 | fputc ('\n', stream); | |
19574 | ||
19575 | fprintf (stream, _("\ | |
19576 | -mips16 generate mips16 instructions\n\ | |
19577 | -no-mips16 do not generate mips16 instructions\n")); | |
19578 | fprintf (stream, _("\ | |
df58fc94 RS |
19579 | -mmicromips generate microMIPS instructions\n\ |
19580 | -mno-micromips do not generate microMIPS instructions\n")); | |
19581 | fprintf (stream, _("\ | |
e16bfa71 TS |
19582 | -msmartmips generate smartmips instructions\n\ |
19583 | -mno-smartmips do not generate smartmips instructions\n")); | |
19584 | fprintf (stream, _("\ | |
74cd071d CF |
19585 | -mdsp generate DSP instructions\n\ |
19586 | -mno-dsp do not generate DSP instructions\n")); | |
19587 | fprintf (stream, _("\ | |
8b082fb1 TS |
19588 | -mdspr2 generate DSP R2 instructions\n\ |
19589 | -mno-dspr2 do not generate DSP R2 instructions\n")); | |
19590 | fprintf (stream, _("\ | |
ef2e4d86 CF |
19591 | -mmt generate MT instructions\n\ |
19592 | -mno-mt do not generate MT instructions\n")); | |
19593 | fprintf (stream, _("\ | |
dec0624d MR |
19594 | -mmcu generate MCU instructions\n\ |
19595 | -mno-mcu do not generate MCU instructions\n")); | |
19596 | fprintf (stream, _("\ | |
c67a084a NC |
19597 | -mfix-loongson2f-jump work around Loongson2F JUMP instructions\n\ |
19598 | -mfix-loongson2f-nop work around Loongson2F NOP errata\n\ | |
d766e8ec | 19599 | -mfix-vr4120 work around certain VR4120 errata\n\ |
7d8e00cf | 19600 | -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\ |
6a32d874 | 19601 | -mfix-24k insert a nop after ERET and DERET instructions\n\ |
d954098f | 19602 | -mfix-cn63xxp1 work around CN63XXP1 PREF errata\n\ |
316f5878 RS |
19603 | -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\ |
19604 | -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\ | |
aed1a261 | 19605 | -msym32 assume all symbols have 32-bit values\n\ |
316f5878 RS |
19606 | -O0 remove unneeded NOPs, do not swap branches\n\ |
19607 | -O remove unneeded NOPs and swap branches\n\ | |
316f5878 RS |
19608 | --trap, --no-break trap exception on div by 0 and mult overflow\n\ |
19609 | --break, --no-trap break exception on div by 0 and mult overflow\n")); | |
037b32b9 AN |
19610 | fprintf (stream, _("\ |
19611 | -mhard-float allow floating-point instructions\n\ | |
19612 | -msoft-float do not allow floating-point instructions\n\ | |
19613 | -msingle-float only allow 32-bit floating-point operations\n\ | |
19614 | -mdouble-float allow 32-bit and 64-bit floating-point operations\n\ | |
19615 | --[no-]construct-floats [dis]allow floating point values to be constructed\n" | |
19616 | )); | |
316f5878 RS |
19617 | #ifdef OBJ_ELF |
19618 | fprintf (stream, _("\ | |
19619 | -KPIC, -call_shared generate SVR4 position independent code\n\ | |
861fb55a | 19620 | -call_nonpic generate non-PIC code that can operate with DSOs\n\ |
0c000745 | 19621 | -mvxworks-pic generate VxWorks position independent code\n\ |
861fb55a | 19622 | -non_shared do not generate code that can operate with DSOs\n\ |
316f5878 | 19623 | -xgot assume a 32 bit GOT\n\ |
dcd410fe | 19624 | -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\ |
bbe506e8 | 19625 | -mshared, -mno-shared disable/enable .cpload optimization for\n\ |
d821e36b | 19626 | position dependent (non shared) code\n\ |
316f5878 RS |
19627 | -mabi=ABI create ABI conformant object file for:\n")); |
19628 | ||
19629 | first = 1; | |
19630 | ||
19631 | show (stream, "32", &column, &first); | |
19632 | show (stream, "o64", &column, &first); | |
19633 | show (stream, "n32", &column, &first); | |
19634 | show (stream, "64", &column, &first); | |
19635 | show (stream, "eabi", &column, &first); | |
19636 | ||
19637 | fputc ('\n', stream); | |
19638 | ||
19639 | fprintf (stream, _("\ | |
19640 | -32 create o32 ABI object file (default)\n\ | |
19641 | -n32 create n32 ABI object file\n\ | |
19642 | -64 create 64 ABI object file\n")); | |
19643 | #endif | |
e7af610e | 19644 | } |
14e777e0 | 19645 | |
1575952e | 19646 | #ifdef TE_IRIX |
14e777e0 | 19647 | enum dwarf2_format |
413a266c | 19648 | mips_dwarf2_format (asection *sec ATTRIBUTE_UNUSED) |
14e777e0 | 19649 | { |
369943fe | 19650 | if (HAVE_64BIT_SYMBOLS) |
1575952e | 19651 | return dwarf2_format_64bit_irix; |
14e777e0 KB |
19652 | else |
19653 | return dwarf2_format_32bit; | |
19654 | } | |
1575952e | 19655 | #endif |
73369e65 EC |
19656 | |
19657 | int | |
19658 | mips_dwarf2_addr_size (void) | |
19659 | { | |
6b6b3450 | 19660 | if (HAVE_64BIT_OBJECTS) |
73369e65 | 19661 | return 8; |
73369e65 EC |
19662 | else |
19663 | return 4; | |
19664 | } | |
5862107c EC |
19665 | |
19666 | /* Standard calling conventions leave the CFA at SP on entry. */ | |
19667 | void | |
19668 | mips_cfi_frame_initial_instructions (void) | |
19669 | { | |
19670 | cfi_add_CFA_def_cfa_register (SP); | |
19671 | } | |
19672 | ||
707bfff6 TS |
19673 | int |
19674 | tc_mips_regname_to_dw2regnum (char *regname) | |
19675 | { | |
19676 | unsigned int regnum = -1; | |
19677 | unsigned int reg; | |
19678 | ||
19679 | if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®)) | |
19680 | regnum = reg; | |
19681 | ||
19682 | return regnum; | |
19683 | } |