Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-mips.c -- assemble code for a MIPS chip. |
98d3f06f | 2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
82efde3a | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Contributed by the OSF and Ralph Campbell. |
5 | Written by Keith Knowles and Ralph Campbell, working independently. | |
6 | Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus | |
7 | Support. | |
8 | ||
9 | This file is part of GAS. | |
10 | ||
11 | GAS is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2, or (at your option) | |
14 | any later version. | |
15 | ||
16 | GAS is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with GAS; see the file COPYING. If not, write to the Free | |
23 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
24 | 02111-1307, USA. */ | |
25 | ||
26 | #include "as.h" | |
27 | #include "config.h" | |
28 | #include "subsegs.h" | |
3882b010 | 29 | #include "safe-ctype.h" |
252b5132 RH |
30 | |
31 | #ifdef USE_STDARG | |
32 | #include <stdarg.h> | |
33 | #endif | |
34 | #ifdef USE_VARARGS | |
35 | #include <varargs.h> | |
36 | #endif | |
37 | ||
38 | #include "opcode/mips.h" | |
39 | #include "itbl-ops.h" | |
c5dd6aab | 40 | #include "dwarf2dbg.h" |
252b5132 RH |
41 | |
42 | #ifdef DEBUG | |
43 | #define DBG(x) printf x | |
44 | #else | |
45 | #define DBG(x) | |
46 | #endif | |
47 | ||
48 | #ifdef OBJ_MAYBE_ELF | |
49 | /* Clean up namespace so we can include obj-elf.h too. */ | |
50 | static int mips_output_flavor PARAMS ((void)); | |
51 | static int mips_output_flavor () { return OUTPUT_FLAVOR; } | |
52 | #undef OBJ_PROCESS_STAB | |
53 | #undef OUTPUT_FLAVOR | |
54 | #undef S_GET_ALIGN | |
55 | #undef S_GET_SIZE | |
56 | #undef S_SET_ALIGN | |
57 | #undef S_SET_SIZE | |
252b5132 RH |
58 | #undef obj_frob_file |
59 | #undef obj_frob_file_after_relocs | |
60 | #undef obj_frob_symbol | |
61 | #undef obj_pop_insert | |
62 | #undef obj_sec_sym_ok_for_reloc | |
63 | #undef OBJ_COPY_SYMBOL_ATTRIBUTES | |
64 | ||
65 | #include "obj-elf.h" | |
66 | /* Fix any of them that we actually care about. */ | |
67 | #undef OUTPUT_FLAVOR | |
68 | #define OUTPUT_FLAVOR mips_output_flavor() | |
69 | #endif | |
70 | ||
71 | #if defined (OBJ_ELF) | |
72 | #include "elf/mips.h" | |
73 | #endif | |
74 | ||
75 | #ifndef ECOFF_DEBUGGING | |
76 | #define NO_ECOFF_DEBUGGING | |
77 | #define ECOFF_DEBUGGING 0 | |
78 | #endif | |
79 | ||
ecb4347a DJ |
80 | int mips_flag_mdebug = -1; |
81 | ||
252b5132 RH |
82 | #include "ecoff.h" |
83 | ||
84 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
85 | static char *mips_regmask_frag; | |
86 | #endif | |
87 | ||
85b51719 | 88 | #define ZERO 0 |
252b5132 RH |
89 | #define AT 1 |
90 | #define TREG 24 | |
91 | #define PIC_CALL_REG 25 | |
92 | #define KT0 26 | |
93 | #define KT1 27 | |
94 | #define GP 28 | |
95 | #define SP 29 | |
96 | #define FP 30 | |
97 | #define RA 31 | |
98 | ||
99 | #define ILLEGAL_REG (32) | |
100 | ||
101 | /* Allow override of standard little-endian ECOFF format. */ | |
102 | ||
103 | #ifndef ECOFF_LITTLE_FORMAT | |
104 | #define ECOFF_LITTLE_FORMAT "ecoff-littlemips" | |
105 | #endif | |
106 | ||
107 | extern int target_big_endian; | |
108 | ||
252b5132 RH |
109 | /* The name of the readonly data section. */ |
110 | #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \ | |
111 | ? ".data" \ | |
112 | : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \ | |
113 | ? ".rdata" \ | |
056350c6 NC |
114 | : OUTPUT_FLAVOR == bfd_target_coff_flavour \ |
115 | ? ".rdata" \ | |
252b5132 RH |
116 | : OUTPUT_FLAVOR == bfd_target_elf_flavour \ |
117 | ? ".rodata" \ | |
118 | : (abort (), "")) | |
119 | ||
a325df1d TS |
120 | /* The ABI to use. */ |
121 | enum mips_abi_level | |
122 | { | |
123 | NO_ABI = 0, | |
124 | O32_ABI, | |
125 | O64_ABI, | |
126 | N32_ABI, | |
127 | N64_ABI, | |
128 | EABI_ABI | |
129 | }; | |
130 | ||
131 | /* MIPS ABI we are using for this output file. */ | |
316f5878 | 132 | static enum mips_abi_level mips_abi = NO_ABI; |
a325df1d | 133 | |
252b5132 RH |
134 | /* This is the set of options which may be modified by the .set |
135 | pseudo-op. We use a struct so that .set push and .set pop are more | |
136 | reliable. */ | |
137 | ||
e972090a NC |
138 | struct mips_set_options |
139 | { | |
252b5132 RH |
140 | /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 |
141 | if it has not been initialized. Changed by `.set mipsN', and the | |
142 | -mipsN command line option, and the default CPU. */ | |
143 | int isa; | |
1f25f5d3 CD |
144 | /* Enabled Application Specific Extensions (ASEs). These are set to -1 |
145 | if they have not been initialized. Changed by `.set <asename>', by | |
146 | command line options, and based on the default architecture. */ | |
147 | int ase_mips3d; | |
deec1734 | 148 | int ase_mdmx; |
252b5132 RH |
149 | /* Whether we are assembling for the mips16 processor. 0 if we are |
150 | not, 1 if we are, and -1 if the value has not been initialized. | |
151 | Changed by `.set mips16' and `.set nomips16', and the -mips16 and | |
152 | -nomips16 command line options, and the default CPU. */ | |
153 | int mips16; | |
154 | /* Non-zero if we should not reorder instructions. Changed by `.set | |
155 | reorder' and `.set noreorder'. */ | |
156 | int noreorder; | |
157 | /* Non-zero if we should not permit the $at ($1) register to be used | |
158 | in instructions. Changed by `.set at' and `.set noat'. */ | |
159 | int noat; | |
160 | /* Non-zero if we should warn when a macro instruction expands into | |
161 | more than one machine instruction. Changed by `.set nomacro' and | |
162 | `.set macro'. */ | |
163 | int warn_about_macros; | |
164 | /* Non-zero if we should not move instructions. Changed by `.set | |
165 | move', `.set volatile', `.set nomove', and `.set novolatile'. */ | |
166 | int nomove; | |
167 | /* Non-zero if we should not optimize branches by moving the target | |
168 | of the branch into the delay slot. Actually, we don't perform | |
169 | this optimization anyhow. Changed by `.set bopt' and `.set | |
170 | nobopt'. */ | |
171 | int nobopt; | |
172 | /* Non-zero if we should not autoextend mips16 instructions. | |
173 | Changed by `.set autoextend' and `.set noautoextend'. */ | |
174 | int noautoextend; | |
a325df1d TS |
175 | /* Restrict general purpose registers and floating point registers |
176 | to 32 bit. This is initially determined when -mgp32 or -mfp32 | |
177 | is passed but can changed if the assembler code uses .set mipsN. */ | |
178 | int gp32; | |
179 | int fp32; | |
252b5132 RH |
180 | }; |
181 | ||
a325df1d | 182 | /* True if -mgp32 was passed. */ |
a8e8e863 | 183 | static int file_mips_gp32 = -1; |
a325df1d TS |
184 | |
185 | /* True if -mfp32 was passed. */ | |
a8e8e863 | 186 | static int file_mips_fp32 = -1; |
a325df1d | 187 | |
252b5132 | 188 | /* This is the struct we use to hold the current set of options. Note |
a4672219 | 189 | that we must set the isa field to ISA_UNKNOWN and the ASE fields to |
e7af610e | 190 | -1 to indicate that they have not been initialized. */ |
252b5132 | 191 | |
e972090a NC |
192 | static struct mips_set_options mips_opts = |
193 | { | |
316f5878 | 194 | ISA_UNKNOWN, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 |
e7af610e | 195 | }; |
252b5132 RH |
196 | |
197 | /* These variables are filled in with the masks of registers used. | |
198 | The object format code reads them and puts them in the appropriate | |
199 | place. */ | |
200 | unsigned long mips_gprmask; | |
201 | unsigned long mips_cprmask[4]; | |
202 | ||
203 | /* MIPS ISA we are using for this output file. */ | |
e7af610e | 204 | static int file_mips_isa = ISA_UNKNOWN; |
252b5132 | 205 | |
a4672219 TS |
206 | /* True if -mips16 was passed or implied by arguments passed on the |
207 | command line (e.g., by -march). */ | |
208 | static int file_ase_mips16; | |
209 | ||
1f25f5d3 CD |
210 | /* True if -mips3d was passed or implied by arguments passed on the |
211 | command line (e.g., by -march). */ | |
212 | static int file_ase_mips3d; | |
213 | ||
deec1734 CD |
214 | /* True if -mdmx was passed or implied by arguments passed on the |
215 | command line (e.g., by -march). */ | |
216 | static int file_ase_mdmx; | |
217 | ||
ec68c924 EC |
218 | /* The argument of the -march= flag. The architecture we are assembling. */ |
219 | static int mips_arch = CPU_UNKNOWN; | |
316f5878 RS |
220 | static const char *mips_arch_string; |
221 | static const struct mips_cpu_info *mips_arch_info; | |
ec68c924 EC |
222 | |
223 | /* The argument of the -mtune= flag. The architecture for which we | |
224 | are optimizing. */ | |
225 | static int mips_tune = CPU_UNKNOWN; | |
316f5878 RS |
226 | static const char *mips_tune_string; |
227 | static const struct mips_cpu_info *mips_tune_info; | |
ec68c924 | 228 | |
316f5878 | 229 | /* True when generating 32-bit code for a 64-bit processor. */ |
252b5132 RH |
230 | static int mips_32bitmode = 0; |
231 | ||
9ce8a5dd GRK |
232 | /* Some ISA's have delay slots for instructions which read or write |
233 | from a coprocessor (eg. mips1-mips3); some don't (eg mips4). | |
bdaaa2e1 | 234 | Return true if instructions marked INSN_LOAD_COPROC_DELAY, |
9ce8a5dd GRK |
235 | INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a |
236 | delay slot in this ISA. The uses of this macro assume that any | |
237 | ISA that has delay slots for one of these, has them for all. They | |
238 | also assume that ISAs which don't have delays for these insns, don't | |
bdaaa2e1 | 239 | have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */ |
9ce8a5dd | 240 | #define ISA_HAS_COPROC_DELAYS(ISA) ( \ |
e7af610e NC |
241 | (ISA) == ISA_MIPS1 \ |
242 | || (ISA) == ISA_MIPS2 \ | |
243 | || (ISA) == ISA_MIPS3 \ | |
9ce8a5dd GRK |
244 | ) |
245 | ||
316f5878 RS |
246 | /* True if the given ABI requires 32-bit registers. */ |
247 | #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI) | |
248 | ||
249 | /* Likewise 64-bit registers. */ | |
250 | #define ABI_NEEDS_64BIT_REGS(ABI) \ | |
251 | ((ABI) == N32_ABI \ | |
252 | || (ABI) == N64_ABI \ | |
253 | || (ABI) == O64_ABI) | |
254 | ||
bdaaa2e1 | 255 | /* Return true if ISA supports 64 bit gp register instructions. */ |
9ce8a5dd | 256 | #define ISA_HAS_64BIT_REGS(ISA) ( \ |
e7af610e NC |
257 | (ISA) == ISA_MIPS3 \ |
258 | || (ISA) == ISA_MIPS4 \ | |
84ea6cf2 | 259 | || (ISA) == ISA_MIPS5 \ |
d1cf510e | 260 | || (ISA) == ISA_MIPS64 \ |
9ce8a5dd GRK |
261 | ) |
262 | ||
e013f690 | 263 | #define HAVE_32BIT_GPRS \ |
316f5878 | 264 | (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
ca4e0257 | 265 | |
e013f690 | 266 | #define HAVE_32BIT_FPRS \ |
316f5878 | 267 | (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
ca4e0257 RS |
268 | |
269 | #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS) | |
270 | #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS) | |
271 | ||
316f5878 | 272 | #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI) |
e013f690 | 273 | |
316f5878 | 274 | #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI) |
e013f690 TS |
275 | |
276 | /* We can only have 64bit addresses if the object file format | |
277 | supports it. */ | |
afdbd6d0 CD |
278 | #define HAVE_32BIT_ADDRESSES \ |
279 | (HAVE_32BIT_GPRS \ | |
280 | || ((bfd_arch_bits_per_address (stdoutput) == 32 \ | |
281 | || ! HAVE_64BIT_OBJECTS) \ | |
282 | && mips_pic != EMBEDDED_PIC)) | |
e013f690 TS |
283 | |
284 | #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES) | |
ca4e0257 | 285 | |
a4672219 | 286 | /* Return true if the given CPU supports the MIPS16 ASE. */ |
3396de36 TS |
287 | #define CPU_HAS_MIPS16(cpu) \ |
288 | (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \ | |
289 | || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0) | |
a4672219 | 290 | |
1f25f5d3 CD |
291 | /* Return true if the given CPU supports the MIPS3D ASE. */ |
292 | #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \ | |
293 | ) | |
294 | ||
deec1734 | 295 | /* Return true if the given CPU supports the MDMX ASE. */ |
a4672219 | 296 | #define CPU_HAS_MDMX(cpu) (false \ |
deec1734 CD |
297 | ) |
298 | ||
60b63b72 RS |
299 | /* True if CPU has a dror instruction. */ |
300 | #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500) | |
301 | ||
302 | /* True if CPU has a ror instruction. */ | |
303 | #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU) | |
304 | ||
bdaaa2e1 | 305 | /* Whether the processor uses hardware interlocks to protect |
252b5132 | 306 | reads from the HI and LO registers, and thus does not |
ec68c924 | 307 | require nops to be inserted. */ |
252b5132 | 308 | |
ec68c924 | 309 | #define hilo_interlocks (mips_arch == CPU_R4010 \ |
60b63b72 | 310 | || mips_arch == CPU_VR5500 \ |
0a758a12 | 311 | || mips_arch == CPU_SB1 \ |
252b5132 RH |
312 | ) |
313 | ||
314 | /* Whether the processor uses hardware interlocks to protect reads | |
315 | from the GPRs, and thus does not require nops to be inserted. */ | |
316 | #define gpr_interlocks \ | |
e7af610e | 317 | (mips_opts.isa != ISA_MIPS1 \ |
60b63b72 RS |
318 | || mips_arch == CPU_VR5400 \ |
319 | || mips_arch == CPU_VR5500 \ | |
ec68c924 | 320 | || mips_arch == CPU_R3900) |
252b5132 RH |
321 | |
322 | /* As with other "interlocks" this is used by hardware that has FP | |
323 | (co-processor) interlocks. */ | |
bdaaa2e1 | 324 | /* Itbl support may require additional care here. */ |
ec68c924 | 325 | #define cop_interlocks (mips_arch == CPU_R4300 \ |
60b63b72 RS |
326 | || mips_arch == CPU_VR5400 \ |
327 | || mips_arch == CPU_VR5500 \ | |
0a758a12 | 328 | || mips_arch == CPU_SB1 \ |
252b5132 RH |
329 | ) |
330 | ||
6b76fefe CM |
331 | /* Is this a mfhi or mflo instruction? */ |
332 | #define MF_HILO_INSN(PINFO) \ | |
333 | ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO)) | |
334 | ||
252b5132 RH |
335 | /* MIPS PIC level. */ |
336 | ||
a161fe53 | 337 | enum mips_pic_level mips_pic; |
252b5132 | 338 | |
39c0a331 L |
339 | /* Warn about all NOPS that the assembler generates. */ |
340 | static int warn_nops = 0; | |
341 | ||
c9914766 | 342 | /* 1 if we should generate 32 bit offsets from the $gp register in |
252b5132 | 343 | SVR4_PIC mode. Currently has no meaning in other modes. */ |
c9914766 | 344 | static int mips_big_got = 0; |
252b5132 RH |
345 | |
346 | /* 1 if trap instructions should used for overflow rather than break | |
347 | instructions. */ | |
c9914766 | 348 | static int mips_trap = 0; |
252b5132 | 349 | |
119d663a | 350 | /* 1 if double width floating point constants should not be constructed |
b6ff326e | 351 | by assembling two single width halves into two single width floating |
119d663a NC |
352 | point registers which just happen to alias the double width destination |
353 | register. On some architectures this aliasing can be disabled by a bit | |
d547a75e | 354 | in the status register, and the setting of this bit cannot be determined |
119d663a NC |
355 | automatically at assemble time. */ |
356 | static int mips_disable_float_construction; | |
357 | ||
252b5132 RH |
358 | /* Non-zero if any .set noreorder directives were used. */ |
359 | ||
360 | static int mips_any_noreorder; | |
361 | ||
6b76fefe CM |
362 | /* Non-zero if nops should be inserted when the register referenced in |
363 | an mfhi/mflo instruction is read in the next two instructions. */ | |
364 | static int mips_7000_hilo_fix; | |
365 | ||
252b5132 | 366 | /* The size of the small data section. */ |
156c2f8b | 367 | static unsigned int g_switch_value = 8; |
252b5132 RH |
368 | /* Whether the -G option was used. */ |
369 | static int g_switch_seen = 0; | |
370 | ||
371 | #define N_RMASK 0xc4 | |
372 | #define N_VFP 0xd4 | |
373 | ||
374 | /* If we can determine in advance that GP optimization won't be | |
375 | possible, we can skip the relaxation stuff that tries to produce | |
376 | GP-relative references. This makes delay slot optimization work | |
377 | better. | |
378 | ||
379 | This function can only provide a guess, but it seems to work for | |
fba2b7f9 GK |
380 | gcc output. It needs to guess right for gcc, otherwise gcc |
381 | will put what it thinks is a GP-relative instruction in a branch | |
382 | delay slot. | |
252b5132 RH |
383 | |
384 | I don't know if a fix is needed for the SVR4_PIC mode. I've only | |
385 | fixed it for the non-PIC mode. KR 95/04/07 */ | |
386 | static int nopic_need_relax PARAMS ((symbolS *, int)); | |
387 | ||
388 | /* handle of the OPCODE hash table */ | |
389 | static struct hash_control *op_hash = NULL; | |
390 | ||
391 | /* The opcode hash table we use for the mips16. */ | |
392 | static struct hash_control *mips16_op_hash = NULL; | |
393 | ||
394 | /* This array holds the chars that always start a comment. If the | |
395 | pre-processor is disabled, these aren't very useful */ | |
396 | const char comment_chars[] = "#"; | |
397 | ||
398 | /* This array holds the chars that only start a comment at the beginning of | |
399 | a line. If the line seems to have the form '# 123 filename' | |
400 | .line and .file directives will appear in the pre-processed output */ | |
401 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
402 | first line of the input file. This is because the compiler outputs | |
bdaaa2e1 | 403 | #NO_APP at the beginning of its output. */ |
252b5132 RH |
404 | /* Also note that C style comments are always supported. */ |
405 | const char line_comment_chars[] = "#"; | |
406 | ||
bdaaa2e1 | 407 | /* This array holds machine specific line separator characters. */ |
63a0b638 | 408 | const char line_separator_chars[] = ";"; |
252b5132 RH |
409 | |
410 | /* Chars that can be used to separate mant from exp in floating point nums */ | |
411 | const char EXP_CHARS[] = "eE"; | |
412 | ||
413 | /* Chars that mean this number is a floating point constant */ | |
414 | /* As in 0f12.456 */ | |
415 | /* or 0d1.2345e12 */ | |
416 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
417 | ||
418 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
419 | changed in read.c . Ideally it shouldn't have to know about it at all, | |
420 | but nothing is ideal around here. | |
421 | */ | |
422 | ||
423 | static char *insn_error; | |
424 | ||
425 | static int auto_align = 1; | |
426 | ||
427 | /* When outputting SVR4 PIC code, the assembler needs to know the | |
428 | offset in the stack frame from which to restore the $gp register. | |
429 | This is set by the .cprestore pseudo-op, and saved in this | |
430 | variable. */ | |
431 | static offsetT mips_cprestore_offset = -1; | |
432 | ||
6478892d TS |
433 | /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some |
434 | more optimizations, it can use a register value instead of a memory-saved | |
956cd1d6 | 435 | offset and even an other register than $gp as global pointer. */ |
6478892d TS |
436 | static offsetT mips_cpreturn_offset = -1; |
437 | static int mips_cpreturn_register = -1; | |
438 | static int mips_gp_register = GP; | |
def2e0dd | 439 | static int mips_gprel_offset = 0; |
6478892d | 440 | |
7a621144 DJ |
441 | /* Whether mips_cprestore_offset has been set in the current function |
442 | (or whether it has already been warned about, if not). */ | |
443 | static int mips_cprestore_valid = 0; | |
444 | ||
252b5132 RH |
445 | /* This is the register which holds the stack frame, as set by the |
446 | .frame pseudo-op. This is needed to implement .cprestore. */ | |
447 | static int mips_frame_reg = SP; | |
448 | ||
7a621144 DJ |
449 | /* Whether mips_frame_reg has been set in the current function |
450 | (or whether it has already been warned about, if not). */ | |
451 | static int mips_frame_reg_valid = 0; | |
452 | ||
252b5132 RH |
453 | /* To output NOP instructions correctly, we need to keep information |
454 | about the previous two instructions. */ | |
455 | ||
456 | /* Whether we are optimizing. The default value of 2 means to remove | |
457 | unneeded NOPs and swap branch instructions when possible. A value | |
458 | of 1 means to not swap branches. A value of 0 means to always | |
459 | insert NOPs. */ | |
460 | static int mips_optimize = 2; | |
461 | ||
462 | /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is | |
463 | equivalent to seeing no -g option at all. */ | |
464 | static int mips_debug = 0; | |
465 | ||
466 | /* The previous instruction. */ | |
467 | static struct mips_cl_insn prev_insn; | |
468 | ||
469 | /* The instruction before prev_insn. */ | |
470 | static struct mips_cl_insn prev_prev_insn; | |
471 | ||
472 | /* If we don't want information for prev_insn or prev_prev_insn, we | |
473 | point the insn_mo field at this dummy integer. */ | |
43841e91 | 474 | static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 }; |
252b5132 RH |
475 | |
476 | /* Non-zero if prev_insn is valid. */ | |
477 | static int prev_insn_valid; | |
478 | ||
479 | /* The frag for the previous instruction. */ | |
480 | static struct frag *prev_insn_frag; | |
481 | ||
482 | /* The offset into prev_insn_frag for the previous instruction. */ | |
483 | static long prev_insn_where; | |
484 | ||
485 | /* The reloc type for the previous instruction, if any. */ | |
f6688943 | 486 | static bfd_reloc_code_real_type prev_insn_reloc_type[3]; |
252b5132 RH |
487 | |
488 | /* The reloc for the previous instruction, if any. */ | |
f6688943 | 489 | static fixS *prev_insn_fixp[3]; |
252b5132 RH |
490 | |
491 | /* Non-zero if the previous instruction was in a delay slot. */ | |
492 | static int prev_insn_is_delay_slot; | |
493 | ||
494 | /* Non-zero if the previous instruction was in a .set noreorder. */ | |
495 | static int prev_insn_unreordered; | |
496 | ||
497 | /* Non-zero if the previous instruction uses an extend opcode (if | |
498 | mips16). */ | |
499 | static int prev_insn_extended; | |
500 | ||
501 | /* Non-zero if the previous previous instruction was in a .set | |
502 | noreorder. */ | |
503 | static int prev_prev_insn_unreordered; | |
504 | ||
505 | /* If this is set, it points to a frag holding nop instructions which | |
506 | were inserted before the start of a noreorder section. If those | |
507 | nops turn out to be unnecessary, the size of the frag can be | |
508 | decreased. */ | |
509 | static fragS *prev_nop_frag; | |
510 | ||
511 | /* The number of nop instructions we created in prev_nop_frag. */ | |
512 | static int prev_nop_frag_holds; | |
513 | ||
514 | /* The number of nop instructions that we know we need in | |
bdaaa2e1 | 515 | prev_nop_frag. */ |
252b5132 RH |
516 | static int prev_nop_frag_required; |
517 | ||
518 | /* The number of instructions we've seen since prev_nop_frag. */ | |
519 | static int prev_nop_frag_since; | |
520 | ||
521 | /* For ECOFF and ELF, relocations against symbols are done in two | |
522 | parts, with a HI relocation and a LO relocation. Each relocation | |
523 | has only 16 bits of space to store an addend. This means that in | |
524 | order for the linker to handle carries correctly, it must be able | |
525 | to locate both the HI and the LO relocation. This means that the | |
526 | relocations must appear in order in the relocation table. | |
527 | ||
528 | In order to implement this, we keep track of each unmatched HI | |
529 | relocation. We then sort them so that they immediately precede the | |
bdaaa2e1 | 530 | corresponding LO relocation. */ |
252b5132 | 531 | |
e972090a NC |
532 | struct mips_hi_fixup |
533 | { | |
252b5132 RH |
534 | /* Next HI fixup. */ |
535 | struct mips_hi_fixup *next; | |
536 | /* This fixup. */ | |
537 | fixS *fixp; | |
538 | /* The section this fixup is in. */ | |
539 | segT seg; | |
540 | }; | |
541 | ||
542 | /* The list of unmatched HI relocs. */ | |
543 | ||
544 | static struct mips_hi_fixup *mips_hi_fixup_list; | |
545 | ||
546 | /* Map normal MIPS register numbers to mips16 register numbers. */ | |
547 | ||
548 | #define X ILLEGAL_REG | |
e972090a NC |
549 | static const int mips32_to_16_reg_map[] = |
550 | { | |
252b5132 RH |
551 | X, X, 2, 3, 4, 5, 6, 7, |
552 | X, X, X, X, X, X, X, X, | |
553 | 0, 1, X, X, X, X, X, X, | |
554 | X, X, X, X, X, X, X, X | |
555 | }; | |
556 | #undef X | |
557 | ||
558 | /* Map mips16 register numbers to normal MIPS register numbers. */ | |
559 | ||
e972090a NC |
560 | static const unsigned int mips16_to_32_reg_map[] = |
561 | { | |
252b5132 RH |
562 | 16, 17, 2, 3, 4, 5, 6, 7 |
563 | }; | |
60b63b72 RS |
564 | |
565 | static int mips_fix_4122_bugs; | |
4a6a3df4 AO |
566 | |
567 | /* We don't relax branches by default, since this causes us to expand | |
568 | `la .l2 - .l1' if there's a branch between .l1 and .l2, because we | |
569 | fail to compute the offset before expanding the macro to the most | |
570 | efficient expansion. */ | |
571 | ||
572 | static int mips_relax_branch; | |
252b5132 RH |
573 | \f |
574 | /* Since the MIPS does not have multiple forms of PC relative | |
575 | instructions, we do not have to do relaxing as is done on other | |
576 | platforms. However, we do have to handle GP relative addressing | |
577 | correctly, which turns out to be a similar problem. | |
578 | ||
579 | Every macro that refers to a symbol can occur in (at least) two | |
580 | forms, one with GP relative addressing and one without. For | |
581 | example, loading a global variable into a register generally uses | |
582 | a macro instruction like this: | |
583 | lw $4,i | |
584 | If i can be addressed off the GP register (this is true if it is in | |
585 | the .sbss or .sdata section, or if it is known to be smaller than | |
586 | the -G argument) this will generate the following instruction: | |
587 | lw $4,i($gp) | |
588 | This instruction will use a GPREL reloc. If i can not be addressed | |
589 | off the GP register, the following instruction sequence will be used: | |
590 | lui $at,i | |
591 | lw $4,i($at) | |
592 | In this case the first instruction will have a HI16 reloc, and the | |
593 | second reloc will have a LO16 reloc. Both relocs will be against | |
594 | the symbol i. | |
595 | ||
596 | The issue here is that we may not know whether i is GP addressable | |
597 | until after we see the instruction that uses it. Therefore, we | |
598 | want to be able to choose the final instruction sequence only at | |
599 | the end of the assembly. This is similar to the way other | |
600 | platforms choose the size of a PC relative instruction only at the | |
601 | end of assembly. | |
602 | ||
603 | When generating position independent code we do not use GP | |
604 | addressing in quite the same way, but the issue still arises as | |
605 | external symbols and local symbols must be handled differently. | |
606 | ||
607 | We handle these issues by actually generating both possible | |
608 | instruction sequences. The longer one is put in a frag_var with | |
609 | type rs_machine_dependent. We encode what to do with the frag in | |
610 | the subtype field. We encode (1) the number of existing bytes to | |
611 | replace, (2) the number of new bytes to use, (3) the offset from | |
612 | the start of the existing bytes to the first reloc we must generate | |
613 | (that is, the offset is applied from the start of the existing | |
614 | bytes after they are replaced by the new bytes, if any), (4) the | |
615 | offset from the start of the existing bytes to the second reloc, | |
616 | (5) whether a third reloc is needed (the third reloc is always four | |
617 | bytes after the second reloc), and (6) whether to warn if this | |
618 | variant is used (this is sometimes needed if .set nomacro or .set | |
619 | noat is in effect). All these numbers are reasonably small. | |
620 | ||
621 | Generating two instruction sequences must be handled carefully to | |
622 | ensure that delay slots are handled correctly. Fortunately, there | |
623 | are a limited number of cases. When the second instruction | |
624 | sequence is generated, append_insn is directed to maintain the | |
625 | existing delay slot information, so it continues to apply to any | |
626 | code after the second instruction sequence. This means that the | |
627 | second instruction sequence must not impose any requirements not | |
628 | required by the first instruction sequence. | |
629 | ||
630 | These variant frags are then handled in functions called by the | |
631 | machine independent code. md_estimate_size_before_relax returns | |
632 | the final size of the frag. md_convert_frag sets up the final form | |
633 | of the frag. tc_gen_reloc adjust the first reloc and adds a second | |
634 | one if needed. */ | |
635 | #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \ | |
636 | ((relax_substateT) \ | |
637 | (((old) << 23) \ | |
638 | | ((new) << 16) \ | |
639 | | (((reloc1) + 64) << 9) \ | |
640 | | (((reloc2) + 64) << 2) \ | |
641 | | ((reloc3) ? (1 << 1) : 0) \ | |
642 | | ((warn) ? 1 : 0))) | |
643 | #define RELAX_OLD(i) (((i) >> 23) & 0x7f) | |
644 | #define RELAX_NEW(i) (((i) >> 16) & 0x7f) | |
9a41af64 TS |
645 | #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64) |
646 | #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64) | |
252b5132 RH |
647 | #define RELAX_RELOC3(i) (((i) >> 1) & 1) |
648 | #define RELAX_WARN(i) ((i) & 1) | |
649 | ||
4a6a3df4 AO |
650 | /* Branch without likely bit. If label is out of range, we turn: |
651 | ||
652 | beq reg1, reg2, label | |
653 | delay slot | |
654 | ||
655 | into | |
656 | ||
657 | bne reg1, reg2, 0f | |
658 | nop | |
659 | j label | |
660 | 0: delay slot | |
661 | ||
662 | with the following opcode replacements: | |
663 | ||
664 | beq <-> bne | |
665 | blez <-> bgtz | |
666 | bltz <-> bgez | |
667 | bc1f <-> bc1t | |
668 | ||
669 | bltzal <-> bgezal (with jal label instead of j label) | |
670 | ||
671 | Even though keeping the delay slot instruction in the delay slot of | |
672 | the branch would be more efficient, it would be very tricky to do | |
673 | correctly, because we'd have to introduce a variable frag *after* | |
674 | the delay slot instruction, and expand that instead. Let's do it | |
675 | the easy way for now, even if the branch-not-taken case now costs | |
676 | one additional instruction. Out-of-range branches are not supposed | |
677 | to be common, anyway. | |
678 | ||
679 | Branch likely. If label is out of range, we turn: | |
680 | ||
681 | beql reg1, reg2, label | |
682 | delay slot (annulled if branch not taken) | |
683 | ||
684 | into | |
685 | ||
686 | beql reg1, reg2, 1f | |
687 | nop | |
688 | beql $0, $0, 2f | |
689 | nop | |
690 | 1: j[al] label | |
691 | delay slot (executed only if branch taken) | |
692 | 2: | |
693 | ||
694 | It would be possible to generate a shorter sequence by losing the | |
695 | likely bit, generating something like: | |
696 | ||
697 | bne reg1, reg2, 0f | |
698 | nop | |
699 | j[al] label | |
700 | delay slot (executed only if branch taken) | |
701 | 0: | |
702 | ||
703 | beql -> bne | |
704 | bnel -> beq | |
705 | blezl -> bgtz | |
706 | bgtzl -> blez | |
707 | bltzl -> bgez | |
708 | bgezl -> bltz | |
709 | bc1fl -> bc1t | |
710 | bc1tl -> bc1f | |
711 | ||
712 | bltzall -> bgezal (with jal label instead of j label) | |
713 | bgezall -> bltzal (ditto) | |
714 | ||
715 | ||
716 | but it's not clear that it would actually improve performance. */ | |
717 | #define RELAX_BRANCH_ENCODE(reloc_s2, uncond, likely, link, toofar) \ | |
718 | ((relax_substateT) \ | |
719 | (0xc0000000 \ | |
720 | | ((toofar) ? 1 : 0) \ | |
721 | | ((link) ? 2 : 0) \ | |
722 | | ((likely) ? 4 : 0) \ | |
723 | | ((uncond) ? 8 : 0) \ | |
724 | | ((reloc_s2) ? 16 : 0))) | |
725 | #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000) | |
726 | #define RELAX_BRANCH_RELOC_S2(i) (((i) & 16) != 0) | |
727 | #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0) | |
728 | #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0) | |
729 | #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0) | |
730 | #define RELAX_BRANCH_TOOFAR(i) (((i) & 1)) | |
731 | ||
252b5132 RH |
732 | /* For mips16 code, we use an entirely different form of relaxation. |
733 | mips16 supports two versions of most instructions which take | |
734 | immediate values: a small one which takes some small value, and a | |
735 | larger one which takes a 16 bit value. Since branches also follow | |
736 | this pattern, relaxing these values is required. | |
737 | ||
738 | We can assemble both mips16 and normal MIPS code in a single | |
739 | object. Therefore, we need to support this type of relaxation at | |
740 | the same time that we support the relaxation described above. We | |
741 | use the high bit of the subtype field to distinguish these cases. | |
742 | ||
743 | The information we store for this type of relaxation is the | |
744 | argument code found in the opcode file for this relocation, whether | |
745 | the user explicitly requested a small or extended form, and whether | |
746 | the relocation is in a jump or jal delay slot. That tells us the | |
747 | size of the value, and how it should be stored. We also store | |
748 | whether the fragment is considered to be extended or not. We also | |
749 | store whether this is known to be a branch to a different section, | |
750 | whether we have tried to relax this frag yet, and whether we have | |
751 | ever extended a PC relative fragment because of a shift count. */ | |
752 | #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \ | |
753 | (0x80000000 \ | |
754 | | ((type) & 0xff) \ | |
755 | | ((small) ? 0x100 : 0) \ | |
756 | | ((ext) ? 0x200 : 0) \ | |
757 | | ((dslot) ? 0x400 : 0) \ | |
758 | | ((jal_dslot) ? 0x800 : 0)) | |
4a6a3df4 | 759 | #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000) |
252b5132 RH |
760 | #define RELAX_MIPS16_TYPE(i) ((i) & 0xff) |
761 | #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0) | |
762 | #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0) | |
763 | #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0) | |
764 | #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0) | |
765 | #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0) | |
766 | #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000) | |
767 | #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000) | |
768 | #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0) | |
769 | #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000) | |
770 | #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000) | |
885add95 CD |
771 | |
772 | /* Is the given value a sign-extended 32-bit value? */ | |
773 | #define IS_SEXT_32BIT_NUM(x) \ | |
774 | (((x) &~ (offsetT) 0x7fffffff) == 0 \ | |
775 | || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff)) | |
776 | ||
777 | /* Is the given value a sign-extended 16-bit value? */ | |
778 | #define IS_SEXT_16BIT_NUM(x) \ | |
779 | (((x) &~ (offsetT) 0x7fff) == 0 \ | |
780 | || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff)) | |
781 | ||
252b5132 RH |
782 | \f |
783 | /* Prototypes for static functions. */ | |
784 | ||
785 | #ifdef __STDC__ | |
786 | #define internalError() \ | |
787 | as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__) | |
788 | #else | |
789 | #define internalError() as_fatal (_("MIPS internal Error")); | |
790 | #endif | |
791 | ||
792 | enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG }; | |
793 | ||
794 | static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip, | |
795 | unsigned int reg, enum mips_regclass class)); | |
156c2f8b | 796 | static int reg_needs_delay PARAMS ((unsigned int)); |
252b5132 RH |
797 | static void mips16_mark_labels PARAMS ((void)); |
798 | static void append_insn PARAMS ((char *place, | |
799 | struct mips_cl_insn * ip, | |
800 | expressionS * p, | |
f6688943 | 801 | bfd_reloc_code_real_type *r, |
252b5132 RH |
802 | boolean)); |
803 | static void mips_no_prev_insn PARAMS ((int)); | |
804 | static void mips_emit_delays PARAMS ((boolean)); | |
805 | #ifdef USE_STDARG | |
806 | static void macro_build PARAMS ((char *place, int *counter, expressionS * ep, | |
807 | const char *name, const char *fmt, | |
808 | ...)); | |
809 | #else | |
810 | static void macro_build (); | |
811 | #endif | |
812 | static void mips16_macro_build PARAMS ((char *, int *, expressionS *, | |
813 | const char *, const char *, | |
814 | va_list)); | |
438c16b8 | 815 | static void macro_build_jalr PARAMS ((int, expressionS *)); |
252b5132 RH |
816 | static void macro_build_lui PARAMS ((char *place, int *counter, |
817 | expressionS * ep, int regnum)); | |
885add95 CD |
818 | static void macro_build_ldst_constoffset PARAMS ((char *place, int *counter, |
819 | expressionS * ep, const char *op, | |
820 | int valreg, int breg)); | |
252b5132 RH |
821 | static void set_at PARAMS ((int *counter, int reg, int unsignedp)); |
822 | static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip, | |
823 | expressionS *)); | |
824 | static void load_register PARAMS ((int *, int, expressionS *, int)); | |
c9914766 | 825 | static void load_address PARAMS ((int *, int, expressionS *, int *)); |
ea1fb5dc | 826 | static void move_register PARAMS ((int *, int, int)); |
252b5132 RH |
827 | static void macro PARAMS ((struct mips_cl_insn * ip)); |
828 | static void mips16_macro PARAMS ((struct mips_cl_insn * ip)); | |
829 | #ifdef LOSING_COMPILER | |
830 | static void macro2 PARAMS ((struct mips_cl_insn * ip)); | |
831 | #endif | |
832 | static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
833 | static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
834 | static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean, | |
835 | boolean, boolean, unsigned long *, | |
836 | boolean *, unsigned short *)); | |
394f9b3a | 837 | static int my_getPercentOp PARAMS ((char **, unsigned int *, int *)); |
ad8d3bb3 TS |
838 | static int my_getSmallParser PARAMS ((char **, unsigned int *, int *)); |
839 | static int my_getSmallExpression PARAMS ((expressionS *, char *)); | |
840 | static void my_getExpression PARAMS ((expressionS *, char *)); | |
ae948b86 | 841 | #ifdef OBJ_ELF |
e013f690 | 842 | static int support_64bit_objects PARAMS((void)); |
ae948b86 | 843 | #endif |
316f5878 | 844 | static void mips_set_option_string PARAMS ((const char **, const char *)); |
252b5132 RH |
845 | static symbolS *get_symbol PARAMS ((void)); |
846 | static void mips_align PARAMS ((int to, int fill, symbolS *label)); | |
847 | static void s_align PARAMS ((int)); | |
848 | static void s_change_sec PARAMS ((int)); | |
cca86cc8 | 849 | static void s_change_section PARAMS ((int)); |
252b5132 RH |
850 | static void s_cons PARAMS ((int)); |
851 | static void s_float_cons PARAMS ((int)); | |
852 | static void s_mips_globl PARAMS ((int)); | |
853 | static void s_option PARAMS ((int)); | |
854 | static void s_mipsset PARAMS ((int)); | |
855 | static void s_abicalls PARAMS ((int)); | |
856 | static void s_cpload PARAMS ((int)); | |
6478892d TS |
857 | static void s_cpsetup PARAMS ((int)); |
858 | static void s_cplocal PARAMS ((int)); | |
252b5132 | 859 | static void s_cprestore PARAMS ((int)); |
6478892d TS |
860 | static void s_cpreturn PARAMS ((int)); |
861 | static void s_gpvalue PARAMS ((int)); | |
252b5132 | 862 | static void s_gpword PARAMS ((int)); |
10181a0d | 863 | static void s_gpdword PARAMS ((int)); |
252b5132 RH |
864 | static void s_cpadd PARAMS ((int)); |
865 | static void s_insn PARAMS ((int)); | |
866 | static void md_obj_begin PARAMS ((void)); | |
867 | static void md_obj_end PARAMS ((void)); | |
868 | static long get_number PARAMS ((void)); | |
869 | static void s_mips_ent PARAMS ((int)); | |
870 | static void s_mips_end PARAMS ((int)); | |
871 | static void s_mips_frame PARAMS ((int)); | |
872 | static void s_mips_mask PARAMS ((int)); | |
873 | static void s_mips_stab PARAMS ((int)); | |
874 | static void s_mips_weakext PARAMS ((int)); | |
c5dd6aab DJ |
875 | static void s_mips_file PARAMS ((int)); |
876 | static void s_mips_loc PARAMS ((int)); | |
252b5132 | 877 | static int mips16_extended_frag PARAMS ((fragS *, asection *, long)); |
4a6a3df4 | 878 | static int relaxed_branch_length (fragS *, asection *, int); |
252b5132 | 879 | static int validate_mips_insn PARAMS ((const struct mips_opcode *)); |
316f5878 | 880 | static void show PARAMS ((FILE *, const char *, int *, int *)); |
add55e1f RS |
881 | #ifdef OBJ_ELF |
882 | static int mips_need_elf_addend_fixup PARAMS ((fixS *)); | |
883 | #endif | |
e7af610e | 884 | |
ad8d3bb3 | 885 | /* Return values of my_getSmallExpression(). */ |
fb1b3232 | 886 | |
ad8d3bb3 | 887 | enum small_ex_type |
fb1b3232 TS |
888 | { |
889 | S_EX_NONE = 0, | |
ad8d3bb3 TS |
890 | S_EX_REGISTER, |
891 | ||
892 | /* Direct relocation creation by %percent_op(). */ | |
893 | S_EX_HALF, | |
fb1b3232 | 894 | S_EX_HI, |
ad8d3bb3 TS |
895 | S_EX_LO, |
896 | S_EX_GP_REL, | |
897 | S_EX_GOT, | |
898 | S_EX_CALL16, | |
899 | S_EX_GOT_DISP, | |
900 | S_EX_GOT_PAGE, | |
901 | S_EX_GOT_OFST, | |
902 | S_EX_GOT_HI, | |
903 | S_EX_GOT_LO, | |
904 | S_EX_NEG, | |
fb1b3232 TS |
905 | S_EX_HIGHER, |
906 | S_EX_HIGHEST, | |
ad8d3bb3 TS |
907 | S_EX_CALL_HI, |
908 | S_EX_CALL_LO | |
fb1b3232 TS |
909 | }; |
910 | ||
e7af610e NC |
911 | /* Table and functions used to map between CPU/ISA names, and |
912 | ISA levels, and CPU numbers. */ | |
913 | ||
e972090a NC |
914 | struct mips_cpu_info |
915 | { | |
e7af610e NC |
916 | const char *name; /* CPU or ISA name. */ |
917 | int is_isa; /* Is this an ISA? (If 0, a CPU.) */ | |
918 | int isa; /* ISA level. */ | |
919 | int cpu; /* CPU number (default CPU if ISA). */ | |
920 | }; | |
921 | ||
316f5878 RS |
922 | static void mips_set_architecture PARAMS ((const struct mips_cpu_info *)); |
923 | static void mips_set_tune PARAMS ((const struct mips_cpu_info *)); | |
924 | static boolean mips_strict_matching_cpu_name_p PARAMS ((const char *, | |
925 | const char *)); | |
926 | static boolean mips_matching_cpu_name_p PARAMS ((const char *, const char *)); | |
927 | static const struct mips_cpu_info *mips_parse_cpu PARAMS ((const char *, | |
928 | const char *)); | |
e7af610e | 929 | static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int)); |
252b5132 RH |
930 | \f |
931 | /* Pseudo-op table. | |
932 | ||
933 | The following pseudo-ops from the Kane and Heinrich MIPS book | |
934 | should be defined here, but are currently unsupported: .alias, | |
935 | .galive, .gjaldef, .gjrlive, .livereg, .noalias. | |
936 | ||
937 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
938 | specific to the type of debugging information being generated, and | |
939 | should be defined by the object format: .aent, .begin, .bend, | |
940 | .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp, | |
941 | .vreg. | |
942 | ||
943 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
944 | not MIPS CPU specific, but are also not specific to the object file | |
945 | format. This file is probably the best place to define them, but | |
946 | they are not currently supported: .asm0, .endr, .lab, .repeat, | |
947 | .struct. */ | |
948 | ||
e972090a NC |
949 | static const pseudo_typeS mips_pseudo_table[] = |
950 | { | |
beae10d5 | 951 | /* MIPS specific pseudo-ops. */ |
252b5132 RH |
952 | {"option", s_option, 0}, |
953 | {"set", s_mipsset, 0}, | |
954 | {"rdata", s_change_sec, 'r'}, | |
955 | {"sdata", s_change_sec, 's'}, | |
956 | {"livereg", s_ignore, 0}, | |
957 | {"abicalls", s_abicalls, 0}, | |
958 | {"cpload", s_cpload, 0}, | |
6478892d TS |
959 | {"cpsetup", s_cpsetup, 0}, |
960 | {"cplocal", s_cplocal, 0}, | |
252b5132 | 961 | {"cprestore", s_cprestore, 0}, |
6478892d TS |
962 | {"cpreturn", s_cpreturn, 0}, |
963 | {"gpvalue", s_gpvalue, 0}, | |
252b5132 | 964 | {"gpword", s_gpword, 0}, |
10181a0d | 965 | {"gpdword", s_gpdword, 0}, |
252b5132 RH |
966 | {"cpadd", s_cpadd, 0}, |
967 | {"insn", s_insn, 0}, | |
968 | ||
beae10d5 | 969 | /* Relatively generic pseudo-ops that happen to be used on MIPS |
252b5132 RH |
970 | chips. */ |
971 | {"asciiz", stringer, 1}, | |
972 | {"bss", s_change_sec, 'b'}, | |
973 | {"err", s_err, 0}, | |
974 | {"half", s_cons, 1}, | |
975 | {"dword", s_cons, 3}, | |
976 | {"weakext", s_mips_weakext, 0}, | |
977 | ||
beae10d5 | 978 | /* These pseudo-ops are defined in read.c, but must be overridden |
252b5132 RH |
979 | here for one reason or another. */ |
980 | {"align", s_align, 0}, | |
981 | {"byte", s_cons, 0}, | |
982 | {"data", s_change_sec, 'd'}, | |
983 | {"double", s_float_cons, 'd'}, | |
984 | {"float", s_float_cons, 'f'}, | |
985 | {"globl", s_mips_globl, 0}, | |
986 | {"global", s_mips_globl, 0}, | |
987 | {"hword", s_cons, 1}, | |
988 | {"int", s_cons, 2}, | |
989 | {"long", s_cons, 2}, | |
990 | {"octa", s_cons, 4}, | |
991 | {"quad", s_cons, 3}, | |
cca86cc8 | 992 | {"section", s_change_section, 0}, |
252b5132 RH |
993 | {"short", s_cons, 1}, |
994 | {"single", s_float_cons, 'f'}, | |
995 | {"stabn", s_mips_stab, 'n'}, | |
996 | {"text", s_change_sec, 't'}, | |
997 | {"word", s_cons, 2}, | |
add56521 | 998 | |
add56521 | 999 | { "extern", ecoff_directive_extern, 0}, |
add56521 | 1000 | |
43841e91 | 1001 | { NULL, NULL, 0 }, |
252b5132 RH |
1002 | }; |
1003 | ||
e972090a NC |
1004 | static const pseudo_typeS mips_nonecoff_pseudo_table[] = |
1005 | { | |
beae10d5 KH |
1006 | /* These pseudo-ops should be defined by the object file format. |
1007 | However, a.out doesn't support them, so we have versions here. */ | |
252b5132 RH |
1008 | {"aent", s_mips_ent, 1}, |
1009 | {"bgnb", s_ignore, 0}, | |
1010 | {"end", s_mips_end, 0}, | |
1011 | {"endb", s_ignore, 0}, | |
1012 | {"ent", s_mips_ent, 0}, | |
c5dd6aab | 1013 | {"file", s_mips_file, 0}, |
252b5132 RH |
1014 | {"fmask", s_mips_mask, 'F'}, |
1015 | {"frame", s_mips_frame, 0}, | |
c5dd6aab | 1016 | {"loc", s_mips_loc, 0}, |
252b5132 RH |
1017 | {"mask", s_mips_mask, 'R'}, |
1018 | {"verstamp", s_ignore, 0}, | |
43841e91 | 1019 | { NULL, NULL, 0 }, |
252b5132 RH |
1020 | }; |
1021 | ||
1022 | extern void pop_insert PARAMS ((const pseudo_typeS *)); | |
1023 | ||
1024 | void | |
1025 | mips_pop_insert () | |
1026 | { | |
1027 | pop_insert (mips_pseudo_table); | |
1028 | if (! ECOFF_DEBUGGING) | |
1029 | pop_insert (mips_nonecoff_pseudo_table); | |
1030 | } | |
1031 | \f | |
1032 | /* Symbols labelling the current insn. */ | |
1033 | ||
e972090a NC |
1034 | struct insn_label_list |
1035 | { | |
252b5132 RH |
1036 | struct insn_label_list *next; |
1037 | symbolS *label; | |
1038 | }; | |
1039 | ||
1040 | static struct insn_label_list *insn_labels; | |
1041 | static struct insn_label_list *free_insn_labels; | |
1042 | ||
1043 | static void mips_clear_insn_labels PARAMS ((void)); | |
1044 | ||
1045 | static inline void | |
1046 | mips_clear_insn_labels () | |
1047 | { | |
1048 | register struct insn_label_list **pl; | |
1049 | ||
1050 | for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next) | |
1051 | ; | |
1052 | *pl = insn_labels; | |
1053 | insn_labels = NULL; | |
1054 | } | |
1055 | \f | |
1056 | static char *expr_end; | |
1057 | ||
1058 | /* Expressions which appear in instructions. These are set by | |
1059 | mips_ip. */ | |
1060 | ||
1061 | static expressionS imm_expr; | |
1062 | static expressionS offset_expr; | |
1063 | ||
1064 | /* Relocs associated with imm_expr and offset_expr. */ | |
1065 | ||
f6688943 TS |
1066 | static bfd_reloc_code_real_type imm_reloc[3] |
1067 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
1068 | static bfd_reloc_code_real_type offset_reloc[3] | |
1069 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
1070 | |
1071 | /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */ | |
1072 | ||
1073 | static boolean imm_unmatched_hi; | |
1074 | ||
1075 | /* These are set by mips16_ip if an explicit extension is used. */ | |
1076 | ||
1077 | static boolean mips16_small, mips16_ext; | |
1078 | ||
7ed4a06a | 1079 | #ifdef OBJ_ELF |
ecb4347a DJ |
1080 | /* The pdr segment for per procedure frame/regmask info. Not used for |
1081 | ECOFF debugging. */ | |
252b5132 RH |
1082 | |
1083 | static segT pdr_seg; | |
7ed4a06a | 1084 | #endif |
252b5132 | 1085 | |
e013f690 TS |
1086 | /* The default target format to use. */ |
1087 | ||
1088 | const char * | |
1089 | mips_target_format () | |
1090 | { | |
1091 | switch (OUTPUT_FLAVOR) | |
1092 | { | |
1093 | case bfd_target_aout_flavour: | |
1094 | return target_big_endian ? "a.out-mips-big" : "a.out-mips-little"; | |
1095 | case bfd_target_ecoff_flavour: | |
1096 | return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT; | |
1097 | case bfd_target_coff_flavour: | |
1098 | return "pe-mips"; | |
1099 | case bfd_target_elf_flavour: | |
1100 | #ifdef TE_TMIPS | |
cfe86eaa | 1101 | /* This is traditional mips. */ |
e013f690 | 1102 | return (target_big_endian |
cfe86eaa TS |
1103 | ? (HAVE_64BIT_OBJECTS |
1104 | ? "elf64-tradbigmips" | |
1105 | : (HAVE_NEWABI | |
1106 | ? "elf32-ntradbigmips" : "elf32-tradbigmips")) | |
1107 | : (HAVE_64BIT_OBJECTS | |
1108 | ? "elf64-tradlittlemips" | |
1109 | : (HAVE_NEWABI | |
1110 | ? "elf32-ntradlittlemips" : "elf32-tradlittlemips"))); | |
e013f690 TS |
1111 | #else |
1112 | return (target_big_endian | |
cfe86eaa TS |
1113 | ? (HAVE_64BIT_OBJECTS |
1114 | ? "elf64-bigmips" | |
1115 | : (HAVE_NEWABI | |
1116 | ? "elf32-nbigmips" : "elf32-bigmips")) | |
1117 | : (HAVE_64BIT_OBJECTS | |
1118 | ? "elf64-littlemips" | |
1119 | : (HAVE_NEWABI | |
1120 | ? "elf32-nlittlemips" : "elf32-littlemips"))); | |
e013f690 TS |
1121 | #endif |
1122 | default: | |
1123 | abort (); | |
1124 | return NULL; | |
1125 | } | |
1126 | } | |
1127 | ||
156c2f8b NC |
1128 | /* This function is called once, at assembler startup time. It should |
1129 | set up all the tables, etc. that the MD part of the assembler will need. */ | |
1130 | ||
252b5132 RH |
1131 | void |
1132 | md_begin () | |
1133 | { | |
252b5132 | 1134 | register const char *retval = NULL; |
156c2f8b | 1135 | int i = 0; |
252b5132 | 1136 | int broken = 0; |
1f25f5d3 | 1137 | |
ec68c924 | 1138 | if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch)) |
252b5132 RH |
1139 | as_warn (_("Could not set architecture and machine")); |
1140 | ||
252b5132 RH |
1141 | op_hash = hash_new (); |
1142 | ||
1143 | for (i = 0; i < NUMOPCODES;) | |
1144 | { | |
1145 | const char *name = mips_opcodes[i].name; | |
1146 | ||
1147 | retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]); | |
1148 | if (retval != NULL) | |
1149 | { | |
1150 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), | |
1151 | mips_opcodes[i].name, retval); | |
1152 | /* Probably a memory allocation problem? Give up now. */ | |
1153 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1154 | } | |
1155 | do | |
1156 | { | |
1157 | if (mips_opcodes[i].pinfo != INSN_MACRO) | |
1158 | { | |
1159 | if (!validate_mips_insn (&mips_opcodes[i])) | |
1160 | broken = 1; | |
1161 | } | |
1162 | ++i; | |
1163 | } | |
1164 | while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name)); | |
1165 | } | |
1166 | ||
1167 | mips16_op_hash = hash_new (); | |
1168 | ||
1169 | i = 0; | |
1170 | while (i < bfd_mips16_num_opcodes) | |
1171 | { | |
1172 | const char *name = mips16_opcodes[i].name; | |
1173 | ||
1174 | retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]); | |
1175 | if (retval != NULL) | |
1176 | as_fatal (_("internal: can't hash `%s': %s"), | |
1177 | mips16_opcodes[i].name, retval); | |
1178 | do | |
1179 | { | |
1180 | if (mips16_opcodes[i].pinfo != INSN_MACRO | |
1181 | && ((mips16_opcodes[i].match & mips16_opcodes[i].mask) | |
1182 | != mips16_opcodes[i].match)) | |
1183 | { | |
1184 | fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"), | |
1185 | mips16_opcodes[i].name, mips16_opcodes[i].args); | |
1186 | broken = 1; | |
1187 | } | |
1188 | ++i; | |
1189 | } | |
1190 | while (i < bfd_mips16_num_opcodes | |
1191 | && strcmp (mips16_opcodes[i].name, name) == 0); | |
1192 | } | |
1193 | ||
1194 | if (broken) | |
1195 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1196 | ||
1197 | /* We add all the general register names to the symbol table. This | |
1198 | helps us detect invalid uses of them. */ | |
1199 | for (i = 0; i < 32; i++) | |
1200 | { | |
1201 | char buf[5]; | |
1202 | ||
1203 | sprintf (buf, "$%d", i); | |
1204 | symbol_table_insert (symbol_new (buf, reg_section, i, | |
1205 | &zero_address_frag)); | |
1206 | } | |
76db943d TS |
1207 | symbol_table_insert (symbol_new ("$ra", reg_section, RA, |
1208 | &zero_address_frag)); | |
252b5132 RH |
1209 | symbol_table_insert (symbol_new ("$fp", reg_section, FP, |
1210 | &zero_address_frag)); | |
1211 | symbol_table_insert (symbol_new ("$sp", reg_section, SP, | |
1212 | &zero_address_frag)); | |
1213 | symbol_table_insert (symbol_new ("$gp", reg_section, GP, | |
1214 | &zero_address_frag)); | |
1215 | symbol_table_insert (symbol_new ("$at", reg_section, AT, | |
1216 | &zero_address_frag)); | |
1217 | symbol_table_insert (symbol_new ("$kt0", reg_section, KT0, | |
1218 | &zero_address_frag)); | |
1219 | symbol_table_insert (symbol_new ("$kt1", reg_section, KT1, | |
1220 | &zero_address_frag)); | |
85b51719 TS |
1221 | symbol_table_insert (symbol_new ("$zero", reg_section, ZERO, |
1222 | &zero_address_frag)); | |
252b5132 RH |
1223 | symbol_table_insert (symbol_new ("$pc", reg_section, -1, |
1224 | &zero_address_frag)); | |
1225 | ||
1226 | mips_no_prev_insn (false); | |
1227 | ||
1228 | mips_gprmask = 0; | |
1229 | mips_cprmask[0] = 0; | |
1230 | mips_cprmask[1] = 0; | |
1231 | mips_cprmask[2] = 0; | |
1232 | mips_cprmask[3] = 0; | |
1233 | ||
1234 | /* set the default alignment for the text section (2**2) */ | |
1235 | record_alignment (text_section, 2); | |
1236 | ||
1237 | if (USE_GLOBAL_POINTER_OPT) | |
1238 | bfd_set_gp_size (stdoutput, g_switch_value); | |
1239 | ||
1240 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1241 | { | |
1242 | /* On a native system, sections must be aligned to 16 byte | |
1243 | boundaries. When configured for an embedded ELF target, we | |
1244 | don't bother. */ | |
1245 | if (strcmp (TARGET_OS, "elf") != 0) | |
1246 | { | |
1247 | (void) bfd_set_section_alignment (stdoutput, text_section, 4); | |
1248 | (void) bfd_set_section_alignment (stdoutput, data_section, 4); | |
1249 | (void) bfd_set_section_alignment (stdoutput, bss_section, 4); | |
1250 | } | |
1251 | ||
1252 | /* Create a .reginfo section for register masks and a .mdebug | |
1253 | section for debugging information. */ | |
1254 | { | |
1255 | segT seg; | |
1256 | subsegT subseg; | |
1257 | flagword flags; | |
1258 | segT sec; | |
1259 | ||
1260 | seg = now_seg; | |
1261 | subseg = now_subseg; | |
1262 | ||
1263 | /* The ABI says this section should be loaded so that the | |
1264 | running program can access it. However, we don't load it | |
1265 | if we are configured for an embedded target */ | |
1266 | flags = SEC_READONLY | SEC_DATA; | |
1267 | if (strcmp (TARGET_OS, "elf") != 0) | |
1268 | flags |= SEC_ALLOC | SEC_LOAD; | |
1269 | ||
316f5878 | 1270 | if (mips_abi != N64_ABI) |
252b5132 RH |
1271 | { |
1272 | sec = subseg_new (".reginfo", (subsegT) 0); | |
1273 | ||
195325d2 TS |
1274 | bfd_set_section_flags (stdoutput, sec, flags); |
1275 | bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2); | |
bdaaa2e1 | 1276 | |
252b5132 RH |
1277 | #ifdef OBJ_ELF |
1278 | mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo)); | |
1279 | #endif | |
1280 | } | |
1281 | else | |
1282 | { | |
1283 | /* The 64-bit ABI uses a .MIPS.options section rather than | |
1284 | .reginfo section. */ | |
1285 | sec = subseg_new (".MIPS.options", (subsegT) 0); | |
195325d2 TS |
1286 | bfd_set_section_flags (stdoutput, sec, flags); |
1287 | bfd_set_section_alignment (stdoutput, sec, 3); | |
252b5132 RH |
1288 | |
1289 | #ifdef OBJ_ELF | |
1290 | /* Set up the option header. */ | |
1291 | { | |
1292 | Elf_Internal_Options opthdr; | |
1293 | char *f; | |
1294 | ||
1295 | opthdr.kind = ODK_REGINFO; | |
1296 | opthdr.size = (sizeof (Elf_External_Options) | |
1297 | + sizeof (Elf64_External_RegInfo)); | |
1298 | opthdr.section = 0; | |
1299 | opthdr.info = 0; | |
1300 | f = frag_more (sizeof (Elf_External_Options)); | |
1301 | bfd_mips_elf_swap_options_out (stdoutput, &opthdr, | |
1302 | (Elf_External_Options *) f); | |
1303 | ||
1304 | mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo)); | |
1305 | } | |
1306 | #endif | |
1307 | } | |
1308 | ||
1309 | if (ECOFF_DEBUGGING) | |
1310 | { | |
1311 | sec = subseg_new (".mdebug", (subsegT) 0); | |
1312 | (void) bfd_set_section_flags (stdoutput, sec, | |
1313 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1314 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
1315 | } | |
ecb4347a DJ |
1316 | #ifdef OBJ_ELF |
1317 | else if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1318 | { | |
1319 | pdr_seg = subseg_new (".pdr", (subsegT) 0); | |
1320 | (void) bfd_set_section_flags (stdoutput, pdr_seg, | |
1321 | SEC_READONLY | SEC_RELOC | |
1322 | | SEC_DEBUGGING); | |
1323 | (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2); | |
1324 | } | |
252b5132 RH |
1325 | #endif |
1326 | ||
1327 | subseg_set (seg, subseg); | |
1328 | } | |
1329 | } | |
1330 | ||
1331 | if (! ECOFF_DEBUGGING) | |
1332 | md_obj_begin (); | |
1333 | } | |
1334 | ||
1335 | void | |
1336 | md_mips_end () | |
1337 | { | |
1338 | if (! ECOFF_DEBUGGING) | |
1339 | md_obj_end (); | |
1340 | } | |
1341 | ||
1342 | void | |
1343 | md_assemble (str) | |
1344 | char *str; | |
1345 | { | |
1346 | struct mips_cl_insn insn; | |
f6688943 TS |
1347 | bfd_reloc_code_real_type unused_reloc[3] |
1348 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 RH |
1349 | |
1350 | imm_expr.X_op = O_absent; | |
252b5132 RH |
1351 | imm_unmatched_hi = false; |
1352 | offset_expr.X_op = O_absent; | |
f6688943 TS |
1353 | imm_reloc[0] = BFD_RELOC_UNUSED; |
1354 | imm_reloc[1] = BFD_RELOC_UNUSED; | |
1355 | imm_reloc[2] = BFD_RELOC_UNUSED; | |
1356 | offset_reloc[0] = BFD_RELOC_UNUSED; | |
1357 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
1358 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
1359 | |
1360 | if (mips_opts.mips16) | |
1361 | mips16_ip (str, &insn); | |
1362 | else | |
1363 | { | |
1364 | mips_ip (str, &insn); | |
beae10d5 KH |
1365 | DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), |
1366 | str, insn.insn_opcode)); | |
252b5132 RH |
1367 | } |
1368 | ||
1369 | if (insn_error) | |
1370 | { | |
1371 | as_bad ("%s `%s'", insn_error, str); | |
1372 | return; | |
1373 | } | |
1374 | ||
1375 | if (insn.insn_mo->pinfo == INSN_MACRO) | |
1376 | { | |
1377 | if (mips_opts.mips16) | |
1378 | mips16_macro (&insn); | |
1379 | else | |
1380 | macro (&insn); | |
1381 | } | |
1382 | else | |
1383 | { | |
1384 | if (imm_expr.X_op != O_absent) | |
c4e7957c | 1385 | append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi); |
252b5132 | 1386 | else if (offset_expr.X_op != O_absent) |
c4e7957c | 1387 | append_insn (NULL, &insn, &offset_expr, offset_reloc, false); |
252b5132 | 1388 | else |
c4e7957c | 1389 | append_insn (NULL, &insn, NULL, unused_reloc, false); |
252b5132 RH |
1390 | } |
1391 | } | |
1392 | ||
1393 | /* See whether instruction IP reads register REG. CLASS is the type | |
1394 | of register. */ | |
1395 | ||
1396 | static int | |
1397 | insn_uses_reg (ip, reg, class) | |
1398 | struct mips_cl_insn *ip; | |
1399 | unsigned int reg; | |
1400 | enum mips_regclass class; | |
1401 | { | |
1402 | if (class == MIPS16_REG) | |
1403 | { | |
1404 | assert (mips_opts.mips16); | |
1405 | reg = mips16_to_32_reg_map[reg]; | |
1406 | class = MIPS_GR_REG; | |
1407 | } | |
1408 | ||
85b51719 TS |
1409 | /* Don't report on general register ZERO, since it never changes. */ |
1410 | if (class == MIPS_GR_REG && reg == ZERO) | |
252b5132 RH |
1411 | return 0; |
1412 | ||
1413 | if (class == MIPS_FP_REG) | |
1414 | { | |
1415 | assert (! mips_opts.mips16); | |
1416 | /* If we are called with either $f0 or $f1, we must check $f0. | |
1417 | This is not optimal, because it will introduce an unnecessary | |
1418 | NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would | |
1419 | need to distinguish reading both $f0 and $f1 or just one of | |
1420 | them. Note that we don't have to check the other way, | |
1421 | because there is no instruction that sets both $f0 and $f1 | |
1422 | and requires a delay. */ | |
1423 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_S) | |
1424 | && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1) | |
1425 | == (reg &~ (unsigned) 1))) | |
1426 | return 1; | |
1427 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_T) | |
1428 | && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1) | |
1429 | == (reg &~ (unsigned) 1))) | |
1430 | return 1; | |
1431 | } | |
1432 | else if (! mips_opts.mips16) | |
1433 | { | |
1434 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_S) | |
1435 | && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg) | |
1436 | return 1; | |
1437 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_T) | |
1438 | && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg) | |
1439 | return 1; | |
1440 | } | |
1441 | else | |
1442 | { | |
1443 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X) | |
1444 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX) | |
1445 | & MIPS16OP_MASK_RX)] | |
1446 | == reg)) | |
1447 | return 1; | |
1448 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y) | |
1449 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY) | |
1450 | & MIPS16OP_MASK_RY)] | |
1451 | == reg)) | |
1452 | return 1; | |
1453 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z) | |
1454 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
1455 | & MIPS16OP_MASK_MOVE32Z)] | |
1456 | == reg)) | |
1457 | return 1; | |
1458 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG) | |
1459 | return 1; | |
1460 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP) | |
1461 | return 1; | |
1462 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA) | |
1463 | return 1; | |
1464 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X) | |
1465 | && ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
1466 | & MIPS16OP_MASK_REGR32) == reg) | |
1467 | return 1; | |
1468 | } | |
1469 | ||
1470 | return 0; | |
1471 | } | |
1472 | ||
1473 | /* This function returns true if modifying a register requires a | |
1474 | delay. */ | |
1475 | ||
1476 | static int | |
1477 | reg_needs_delay (reg) | |
156c2f8b | 1478 | unsigned int reg; |
252b5132 RH |
1479 | { |
1480 | unsigned long prev_pinfo; | |
1481 | ||
1482 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1483 | if (! mips_opts.noreorder | |
9ce8a5dd | 1484 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1485 | && ((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1486 | || (! gpr_interlocks | |
1487 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1488 | { | |
1489 | /* A load from a coprocessor or from memory. All load | |
1490 | delays delay the use of general register rt for one | |
1491 | instruction on the r3000. The r6000 and r4000 use | |
1492 | interlocks. */ | |
bdaaa2e1 | 1493 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1494 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1495 | if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)) | |
1496 | return 1; | |
1497 | } | |
1498 | ||
1499 | return 0; | |
1500 | } | |
1501 | ||
1502 | /* Mark instruction labels in mips16 mode. This permits the linker to | |
1503 | handle them specially, such as generating jalx instructions when | |
1504 | needed. We also make them odd for the duration of the assembly, in | |
1505 | order to generate the right sort of code. We will make them even | |
1506 | in the adjust_symtab routine, while leaving them marked. This is | |
1507 | convenient for the debugger and the disassembler. The linker knows | |
1508 | to make them odd again. */ | |
1509 | ||
1510 | static void | |
1511 | mips16_mark_labels () | |
1512 | { | |
1513 | if (mips_opts.mips16) | |
1514 | { | |
1515 | struct insn_label_list *l; | |
98aa84af | 1516 | valueT val; |
252b5132 RH |
1517 | |
1518 | for (l = insn_labels; l != NULL; l = l->next) | |
1519 | { | |
1520 | #ifdef OBJ_ELF | |
1521 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1522 | S_SET_OTHER (l->label, STO_MIPS16); | |
1523 | #endif | |
98aa84af AM |
1524 | val = S_GET_VALUE (l->label); |
1525 | if ((val & 1) == 0) | |
1526 | S_SET_VALUE (l->label, val + 1); | |
252b5132 RH |
1527 | } |
1528 | } | |
1529 | } | |
1530 | ||
1531 | /* Output an instruction. PLACE is where to put the instruction; if | |
1532 | it is NULL, this uses frag_more to get room. IP is the instruction | |
1533 | information. ADDRESS_EXPR is an operand of the instruction to be | |
1534 | used with RELOC_TYPE. */ | |
1535 | ||
1536 | static void | |
1537 | append_insn (place, ip, address_expr, reloc_type, unmatched_hi) | |
1538 | char *place; | |
1539 | struct mips_cl_insn *ip; | |
1540 | expressionS *address_expr; | |
f6688943 | 1541 | bfd_reloc_code_real_type *reloc_type; |
252b5132 RH |
1542 | boolean unmatched_hi; |
1543 | { | |
1544 | register unsigned long prev_pinfo, pinfo; | |
1545 | char *f; | |
f6688943 | 1546 | fixS *fixp[3]; |
252b5132 RH |
1547 | int nops = 0; |
1548 | ||
1549 | /* Mark instruction labels in mips16 mode. */ | |
f9419b05 | 1550 | mips16_mark_labels (); |
252b5132 RH |
1551 | |
1552 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1553 | pinfo = ip->insn_mo->pinfo; | |
1554 | ||
1555 | if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL)) | |
1556 | { | |
1557 | int prev_prev_nop; | |
1558 | ||
1559 | /* If the previous insn required any delay slots, see if we need | |
1560 | to insert a NOP or two. There are eight kinds of possible | |
1561 | hazards, of which an instruction can have at most one type. | |
1562 | (1) a load from memory delay | |
1563 | (2) a load from a coprocessor delay | |
1564 | (3) an unconditional branch delay | |
1565 | (4) a conditional branch delay | |
1566 | (5) a move to coprocessor register delay | |
1567 | (6) a load coprocessor register from memory delay | |
1568 | (7) a coprocessor condition code delay | |
1569 | (8) a HI/LO special register delay | |
1570 | ||
1571 | There are a lot of optimizations we could do that we don't. | |
1572 | In particular, we do not, in general, reorder instructions. | |
1573 | If you use gcc with optimization, it will reorder | |
1574 | instructions and generally do much more optimization then we | |
1575 | do here; repeating all that work in the assembler would only | |
1576 | benefit hand written assembly code, and does not seem worth | |
1577 | it. */ | |
1578 | ||
1579 | /* This is how a NOP is emitted. */ | |
1580 | #define emit_nop() \ | |
1581 | (mips_opts.mips16 \ | |
1582 | ? md_number_to_chars (frag_more (2), 0x6500, 2) \ | |
1583 | : md_number_to_chars (frag_more (4), 0, 4)) | |
1584 | ||
1585 | /* The previous insn might require a delay slot, depending upon | |
1586 | the contents of the current insn. */ | |
1587 | if (! mips_opts.mips16 | |
9ce8a5dd | 1588 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1589 | && (((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1590 | && ! cop_interlocks) | |
1591 | || (! gpr_interlocks | |
1592 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1593 | { | |
1594 | /* A load from a coprocessor or from memory. All load | |
1595 | delays delay the use of general register rt for one | |
1596 | instruction on the r3000. The r6000 and r4000 use | |
1597 | interlocks. */ | |
beae10d5 | 1598 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1599 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1600 | if (mips_optimize == 0 | |
1601 | || insn_uses_reg (ip, | |
1602 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
1603 | & OP_MASK_RT), | |
1604 | MIPS_GR_REG)) | |
1605 | ++nops; | |
1606 | } | |
1607 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1608 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 1609 | && (((prev_pinfo & INSN_COPROC_MOVE_DELAY) |
beae10d5 | 1610 | && ! cop_interlocks) |
e7af610e | 1611 | || (mips_opts.isa == ISA_MIPS1 |
252b5132 RH |
1612 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)))) |
1613 | { | |
1614 | /* A generic coprocessor delay. The previous instruction | |
1615 | modified a coprocessor general or control register. If | |
1616 | it modified a control register, we need to avoid any | |
1617 | coprocessor instruction (this is probably not always | |
1618 | required, but it sometimes is). If it modified a general | |
1619 | register, we avoid using that register. | |
1620 | ||
1621 | On the r6000 and r4000 loading a coprocessor register | |
1622 | from memory is interlocked, and does not require a delay. | |
1623 | ||
1624 | This case is not handled very well. There is no special | |
1625 | knowledge of CP0 handling, and the coprocessors other | |
1626 | than the floating point unit are not distinguished at | |
1627 | all. */ | |
1628 | /* Itbl support may require additional care here. FIXME! | |
bdaaa2e1 | 1629 | Need to modify this to include knowledge about |
252b5132 RH |
1630 | user specified delays! */ |
1631 | if (prev_pinfo & INSN_WRITE_FPR_T) | |
1632 | { | |
1633 | if (mips_optimize == 0 | |
1634 | || insn_uses_reg (ip, | |
1635 | ((prev_insn.insn_opcode >> OP_SH_FT) | |
1636 | & OP_MASK_FT), | |
1637 | MIPS_FP_REG)) | |
1638 | ++nops; | |
1639 | } | |
1640 | else if (prev_pinfo & INSN_WRITE_FPR_S) | |
1641 | { | |
1642 | if (mips_optimize == 0 | |
1643 | || insn_uses_reg (ip, | |
1644 | ((prev_insn.insn_opcode >> OP_SH_FS) | |
1645 | & OP_MASK_FS), | |
1646 | MIPS_FP_REG)) | |
1647 | ++nops; | |
1648 | } | |
1649 | else | |
1650 | { | |
1651 | /* We don't know exactly what the previous instruction | |
1652 | does. If the current instruction uses a coprocessor | |
1653 | register, we must insert a NOP. If previous | |
1654 | instruction may set the condition codes, and the | |
1655 | current instruction uses them, we must insert two | |
1656 | NOPS. */ | |
bdaaa2e1 | 1657 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1658 | if (mips_optimize == 0 |
1659 | || ((prev_pinfo & INSN_WRITE_COND_CODE) | |
1660 | && (pinfo & INSN_READ_COND_CODE))) | |
1661 | nops += 2; | |
1662 | else if (pinfo & INSN_COP) | |
1663 | ++nops; | |
1664 | } | |
1665 | } | |
1666 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1667 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1668 | && (prev_pinfo & INSN_WRITE_COND_CODE) |
1669 | && ! cop_interlocks) | |
1670 | { | |
1671 | /* The previous instruction sets the coprocessor condition | |
1672 | codes, but does not require a general coprocessor delay | |
1673 | (this means it is a floating point comparison | |
1674 | instruction). If this instruction uses the condition | |
1675 | codes, we need to insert a single NOP. */ | |
beae10d5 | 1676 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1677 | if (mips_optimize == 0 |
1678 | || (pinfo & INSN_READ_COND_CODE)) | |
1679 | ++nops; | |
1680 | } | |
6b76fefe CM |
1681 | |
1682 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1683 | previous insn was an mfhi/mflo and the current insn | |
1684 | reads the register that the mfhi/mflo wrote to, then | |
1685 | insert two nops. */ | |
1686 | ||
1687 | else if (mips_7000_hilo_fix | |
1688 | && MF_HILO_INSN (prev_pinfo) | |
1689 | && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD) | |
beae10d5 KH |
1690 | & OP_MASK_RD), |
1691 | MIPS_GR_REG)) | |
6b76fefe CM |
1692 | { |
1693 | nops += 2; | |
1694 | } | |
1695 | ||
1696 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1697 | 2nd previous insn was an mfhi/mflo and the current insn | |
1698 | reads the register that the mfhi/mflo wrote to, then | |
1699 | insert one nop. */ | |
1700 | ||
1701 | else if (mips_7000_hilo_fix | |
1702 | && MF_HILO_INSN (prev_prev_insn.insn_opcode) | |
1703 | && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD) | |
1704 | & OP_MASK_RD), | |
1705 | MIPS_GR_REG)) | |
bdaaa2e1 | 1706 | |
6b76fefe | 1707 | { |
f9419b05 | 1708 | ++nops; |
6b76fefe | 1709 | } |
bdaaa2e1 | 1710 | |
252b5132 RH |
1711 | else if (prev_pinfo & INSN_READ_LO) |
1712 | { | |
1713 | /* The previous instruction reads the LO register; if the | |
1714 | current instruction writes to the LO register, we must | |
bdaaa2e1 KH |
1715 | insert two NOPS. Some newer processors have interlocks. |
1716 | Also the tx39's multiply instructions can be exectuted | |
252b5132 | 1717 | immediatly after a read from HI/LO (without the delay), |
bdaaa2e1 KH |
1718 | though the tx39's divide insns still do require the |
1719 | delay. */ | |
252b5132 | 1720 | if (! (hilo_interlocks |
ec68c924 | 1721 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1722 | && (mips_optimize == 0 |
1723 | || (pinfo & INSN_WRITE_LO))) | |
1724 | nops += 2; | |
1725 | /* Most mips16 branch insns don't have a delay slot. | |
1726 | If a read from LO is immediately followed by a branch | |
1727 | to a write to LO we have a read followed by a write | |
1728 | less than 2 insns away. We assume the target of | |
1729 | a branch might be a write to LO, and insert a nop | |
bdaaa2e1 | 1730 | between a read and an immediately following branch. */ |
252b5132 RH |
1731 | else if (mips_opts.mips16 |
1732 | && (mips_optimize == 0 | |
1733 | || (pinfo & MIPS16_INSN_BRANCH))) | |
f9419b05 | 1734 | ++nops; |
252b5132 RH |
1735 | } |
1736 | else if (prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
1737 | { | |
1738 | /* The previous instruction reads the HI register; if the | |
1739 | current instruction writes to the HI register, we must | |
1740 | insert a NOP. Some newer processors have interlocks. | |
bdaaa2e1 | 1741 | Also the note tx39's multiply above. */ |
252b5132 | 1742 | if (! (hilo_interlocks |
ec68c924 | 1743 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1744 | && (mips_optimize == 0 |
1745 | || (pinfo & INSN_WRITE_HI))) | |
1746 | nops += 2; | |
1747 | /* Most mips16 branch insns don't have a delay slot. | |
1748 | If a read from HI is immediately followed by a branch | |
1749 | to a write to HI we have a read followed by a write | |
1750 | less than 2 insns away. We assume the target of | |
1751 | a branch might be a write to HI, and insert a nop | |
bdaaa2e1 | 1752 | between a read and an immediately following branch. */ |
252b5132 RH |
1753 | else if (mips_opts.mips16 |
1754 | && (mips_optimize == 0 | |
1755 | || (pinfo & MIPS16_INSN_BRANCH))) | |
f9419b05 | 1756 | ++nops; |
252b5132 RH |
1757 | } |
1758 | ||
1759 | /* If the previous instruction was in a noreorder section, then | |
1760 | we don't want to insert the nop after all. */ | |
bdaaa2e1 | 1761 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1762 | if (prev_insn_unreordered) |
1763 | nops = 0; | |
1764 | ||
1765 | /* There are two cases which require two intervening | |
1766 | instructions: 1) setting the condition codes using a move to | |
1767 | coprocessor instruction which requires a general coprocessor | |
1768 | delay and then reading the condition codes 2) reading the HI | |
1769 | or LO register and then writing to it (except on processors | |
1770 | which have interlocks). If we are not already emitting a NOP | |
1771 | instruction, we must check for these cases compared to the | |
1772 | instruction previous to the previous instruction. */ | |
1773 | if ((! mips_opts.mips16 | |
9ce8a5dd | 1774 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1775 | && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY) |
1776 | && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE) | |
1777 | && (pinfo & INSN_READ_COND_CODE) | |
1778 | && ! cop_interlocks) | |
1779 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO) | |
1780 | && (pinfo & INSN_WRITE_LO) | |
1781 | && ! (hilo_interlocks | |
ec68c924 | 1782 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))) |
252b5132 RH |
1783 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) |
1784 | && (pinfo & INSN_WRITE_HI) | |
1785 | && ! (hilo_interlocks | |
ec68c924 | 1786 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))) |
252b5132 RH |
1787 | prev_prev_nop = 1; |
1788 | else | |
1789 | prev_prev_nop = 0; | |
1790 | ||
1791 | if (prev_prev_insn_unreordered) | |
1792 | prev_prev_nop = 0; | |
1793 | ||
1794 | if (prev_prev_nop && nops == 0) | |
1795 | ++nops; | |
1796 | ||
60b63b72 RS |
1797 | if (mips_fix_4122_bugs && prev_insn.insn_mo->name) |
1798 | { | |
1799 | /* We're out of bits in pinfo, so we must resort to string | |
1800 | ops here. Shortcuts are selected based on opcodes being | |
1801 | limited to the VR4122 instruction set. */ | |
1802 | int min_nops = 0; | |
1803 | const char *pn = prev_insn.insn_mo->name; | |
1804 | const char *tn = ip->insn_mo->name; | |
1805 | if (strncmp(pn, "macc", 4) == 0 | |
1806 | || strncmp(pn, "dmacc", 5) == 0) | |
1807 | { | |
1808 | /* Errata 21 - [D]DIV[U] after [D]MACC */ | |
1809 | if (strstr (tn, "div")) | |
1810 | { | |
1811 | min_nops = 1; | |
1812 | } | |
1813 | ||
1814 | /* Errata 23 - Continuous DMULT[U]/DMACC instructions */ | |
1815 | if (pn[0] == 'd' /* dmacc */ | |
1816 | && (strncmp(tn, "dmult", 5) == 0 | |
1817 | || strncmp(tn, "dmacc", 5) == 0)) | |
1818 | { | |
1819 | min_nops = 1; | |
1820 | } | |
1821 | ||
1822 | /* Errata 24 - MT{LO,HI} after [D]MACC */ | |
1823 | if (strcmp (tn, "mtlo") == 0 | |
1824 | || strcmp (tn, "mthi") == 0) | |
1825 | { | |
1826 | min_nops = 1; | |
1827 | } | |
1828 | ||
1829 | } | |
1830 | else if (strncmp(pn, "dmult", 5) == 0 | |
1831 | && (strncmp(tn, "dmult", 5) == 0 | |
1832 | || strncmp(tn, "dmacc", 5) == 0)) | |
1833 | { | |
1834 | /* Here is the rest of errata 23. */ | |
1835 | min_nops = 1; | |
1836 | } | |
1837 | if (nops < min_nops) | |
1838 | nops = min_nops; | |
1839 | } | |
1840 | ||
252b5132 RH |
1841 | /* If we are being given a nop instruction, don't bother with |
1842 | one of the nops we would otherwise output. This will only | |
1843 | happen when a nop instruction is used with mips_optimize set | |
1844 | to 0. */ | |
1845 | if (nops > 0 | |
1846 | && ! mips_opts.noreorder | |
156c2f8b | 1847 | && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0)) |
252b5132 RH |
1848 | --nops; |
1849 | ||
1850 | /* Now emit the right number of NOP instructions. */ | |
1851 | if (nops > 0 && ! mips_opts.noreorder) | |
1852 | { | |
1853 | fragS *old_frag; | |
1854 | unsigned long old_frag_offset; | |
1855 | int i; | |
1856 | struct insn_label_list *l; | |
1857 | ||
1858 | old_frag = frag_now; | |
1859 | old_frag_offset = frag_now_fix (); | |
1860 | ||
1861 | for (i = 0; i < nops; i++) | |
1862 | emit_nop (); | |
1863 | ||
1864 | if (listing) | |
1865 | { | |
1866 | listing_prev_line (); | |
1867 | /* We may be at the start of a variant frag. In case we | |
1868 | are, make sure there is enough space for the frag | |
1869 | after the frags created by listing_prev_line. The | |
1870 | argument to frag_grow here must be at least as large | |
1871 | as the argument to all other calls to frag_grow in | |
1872 | this file. We don't have to worry about being in the | |
1873 | middle of a variant frag, because the variants insert | |
1874 | all needed nop instructions themselves. */ | |
1875 | frag_grow (40); | |
1876 | } | |
1877 | ||
1878 | for (l = insn_labels; l != NULL; l = l->next) | |
1879 | { | |
98aa84af AM |
1880 | valueT val; |
1881 | ||
252b5132 | 1882 | assert (S_GET_SEGMENT (l->label) == now_seg); |
49309057 | 1883 | symbol_set_frag (l->label, frag_now); |
98aa84af | 1884 | val = (valueT) frag_now_fix (); |
252b5132 RH |
1885 | /* mips16 text labels are stored as odd. */ |
1886 | if (mips_opts.mips16) | |
f9419b05 | 1887 | ++val; |
98aa84af | 1888 | S_SET_VALUE (l->label, val); |
252b5132 RH |
1889 | } |
1890 | ||
1891 | #ifndef NO_ECOFF_DEBUGGING | |
1892 | if (ECOFF_DEBUGGING) | |
1893 | ecoff_fix_loc (old_frag, old_frag_offset); | |
1894 | #endif | |
1895 | } | |
1896 | else if (prev_nop_frag != NULL) | |
1897 | { | |
1898 | /* We have a frag holding nops we may be able to remove. If | |
1899 | we don't need any nops, we can decrease the size of | |
1900 | prev_nop_frag by the size of one instruction. If we do | |
bdaaa2e1 | 1901 | need some nops, we count them in prev_nops_required. */ |
252b5132 RH |
1902 | if (prev_nop_frag_since == 0) |
1903 | { | |
1904 | if (nops == 0) | |
1905 | { | |
1906 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1907 | --prev_nop_frag_holds; | |
1908 | } | |
1909 | else | |
1910 | prev_nop_frag_required += nops; | |
1911 | } | |
1912 | else | |
1913 | { | |
1914 | if (prev_prev_nop == 0) | |
1915 | { | |
1916 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1917 | --prev_nop_frag_holds; | |
1918 | } | |
1919 | else | |
1920 | ++prev_nop_frag_required; | |
1921 | } | |
1922 | ||
1923 | if (prev_nop_frag_holds <= prev_nop_frag_required) | |
1924 | prev_nop_frag = NULL; | |
1925 | ||
1926 | ++prev_nop_frag_since; | |
1927 | ||
1928 | /* Sanity check: by the time we reach the second instruction | |
1929 | after prev_nop_frag, we should have used up all the nops | |
1930 | one way or another. */ | |
1931 | assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL); | |
1932 | } | |
1933 | } | |
1934 | ||
4a6a3df4 AO |
1935 | if (place == NULL |
1936 | && address_expr | |
1937 | && ((*reloc_type == BFD_RELOC_16_PCREL | |
1938 | && address_expr->X_op != O_constant) | |
1939 | || *reloc_type == BFD_RELOC_16_PCREL_S2) | |
1940 | && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY | |
1941 | || pinfo & INSN_COND_BRANCH_LIKELY) | |
1942 | && mips_relax_branch | |
1943 | /* Don't try branch relaxation within .set nomacro, or within | |
1944 | .set noat if we use $at for PIC computations. If it turns | |
1945 | out that the branch was out-of-range, we'll get an error. */ | |
1946 | && !mips_opts.warn_about_macros | |
1947 | && !(mips_opts.noat && mips_pic != NO_PIC) | |
1948 | && !mips_opts.mips16) | |
1949 | { | |
1950 | f = frag_var (rs_machine_dependent, | |
1951 | relaxed_branch_length | |
1952 | (NULL, NULL, | |
1953 | (pinfo & INSN_UNCOND_BRANCH_DELAY) ? -1 | |
1954 | : (pinfo & INSN_COND_BRANCH_LIKELY) ? 1 : 0), 4, | |
1955 | RELAX_BRANCH_ENCODE | |
1956 | (*reloc_type == BFD_RELOC_16_PCREL_S2, | |
1957 | pinfo & INSN_UNCOND_BRANCH_DELAY, | |
1958 | pinfo & INSN_COND_BRANCH_LIKELY, | |
1959 | pinfo & INSN_WRITE_GPR_31, | |
1960 | 0), | |
1961 | address_expr->X_add_symbol, | |
1962 | address_expr->X_add_number, | |
1963 | 0); | |
1964 | *reloc_type = BFD_RELOC_UNUSED; | |
1965 | } | |
1966 | else if (*reloc_type > BFD_RELOC_UNUSED) | |
252b5132 RH |
1967 | { |
1968 | /* We need to set up a variant frag. */ | |
1969 | assert (mips_opts.mips16 && address_expr != NULL); | |
1970 | f = frag_var (rs_machine_dependent, 4, 0, | |
f6688943 | 1971 | RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED, |
252b5132 RH |
1972 | mips16_small, mips16_ext, |
1973 | (prev_pinfo | |
1974 | & INSN_UNCOND_BRANCH_DELAY), | |
f6688943 | 1975 | (*prev_insn_reloc_type |
252b5132 | 1976 | == BFD_RELOC_MIPS16_JMP)), |
c4e7957c | 1977 | make_expr_symbol (address_expr), 0, NULL); |
252b5132 RH |
1978 | } |
1979 | else if (place != NULL) | |
1980 | f = place; | |
1981 | else if (mips_opts.mips16 | |
1982 | && ! ip->use_extend | |
f6688943 | 1983 | && *reloc_type != BFD_RELOC_MIPS16_JMP) |
252b5132 RH |
1984 | { |
1985 | /* Make sure there is enough room to swap this instruction with | |
1986 | a following jump instruction. */ | |
1987 | frag_grow (6); | |
1988 | f = frag_more (2); | |
1989 | } | |
1990 | else | |
1991 | { | |
1992 | if (mips_opts.mips16 | |
1993 | && mips_opts.noreorder | |
1994 | && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0) | |
1995 | as_warn (_("extended instruction in delay slot")); | |
1996 | ||
1997 | f = frag_more (4); | |
1998 | } | |
1999 | ||
f6688943 TS |
2000 | fixp[0] = fixp[1] = fixp[2] = NULL; |
2001 | if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED) | |
252b5132 RH |
2002 | { |
2003 | if (address_expr->X_op == O_constant) | |
2004 | { | |
4db1a35d | 2005 | valueT tmp; |
f6688943 TS |
2006 | |
2007 | switch (*reloc_type) | |
252b5132 RH |
2008 | { |
2009 | case BFD_RELOC_32: | |
2010 | ip->insn_opcode |= address_expr->X_add_number; | |
2011 | break; | |
2012 | ||
f6688943 TS |
2013 | case BFD_RELOC_MIPS_HIGHEST: |
2014 | tmp = (address_expr->X_add_number + 0x800080008000) >> 16; | |
2015 | tmp >>= 16; | |
2016 | ip->insn_opcode |= (tmp >> 16) & 0xffff; | |
2017 | break; | |
2018 | ||
2019 | case BFD_RELOC_MIPS_HIGHER: | |
2020 | tmp = (address_expr->X_add_number + 0x80008000) >> 16; | |
2021 | ip->insn_opcode |= (tmp >> 16) & 0xffff; | |
2022 | break; | |
2023 | ||
2024 | case BFD_RELOC_HI16_S: | |
2025 | ip->insn_opcode |= ((address_expr->X_add_number + 0x8000) | |
2026 | >> 16) & 0xffff; | |
2027 | break; | |
2028 | ||
2029 | case BFD_RELOC_HI16: | |
2030 | ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff; | |
2031 | break; | |
2032 | ||
252b5132 | 2033 | case BFD_RELOC_LO16: |
ed6fb7bd | 2034 | case BFD_RELOC_MIPS_GOT_DISP: |
252b5132 RH |
2035 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; |
2036 | break; | |
2037 | ||
2038 | case BFD_RELOC_MIPS_JMP: | |
2039 | if ((address_expr->X_add_number & 3) != 0) | |
2040 | as_bad (_("jump to misaligned address (0x%lx)"), | |
2041 | (unsigned long) address_expr->X_add_number); | |
f3c0ec86 | 2042 | if (address_expr->X_add_number & ~0xfffffff) |
7496292d TS |
2043 | as_bad (_("jump address range overflow (0x%lx)"), |
2044 | (unsigned long) address_expr->X_add_number); | |
252b5132 RH |
2045 | ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff; |
2046 | break; | |
2047 | ||
2048 | case BFD_RELOC_MIPS16_JMP: | |
2049 | if ((address_expr->X_add_number & 3) != 0) | |
2050 | as_bad (_("jump to misaligned address (0x%lx)"), | |
2051 | (unsigned long) address_expr->X_add_number); | |
f3c0ec86 | 2052 | if (address_expr->X_add_number & ~0xfffffff) |
7496292d TS |
2053 | as_bad (_("jump address range overflow (0x%lx)"), |
2054 | (unsigned long) address_expr->X_add_number); | |
252b5132 RH |
2055 | ip->insn_opcode |= |
2056 | (((address_expr->X_add_number & 0x7c0000) << 3) | |
2057 | | ((address_expr->X_add_number & 0xf800000) >> 7) | |
2058 | | ((address_expr->X_add_number & 0x3fffc) >> 2)); | |
2059 | break; | |
2060 | ||
cb56d3d3 | 2061 | case BFD_RELOC_16_PCREL: |
233b8738 | 2062 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; |
cb56d3d3 TS |
2063 | break; |
2064 | ||
252b5132 RH |
2065 | case BFD_RELOC_16_PCREL_S2: |
2066 | goto need_reloc; | |
2067 | ||
2068 | default: | |
2069 | internalError (); | |
2070 | } | |
2071 | } | |
2072 | else | |
2073 | { | |
2074 | need_reloc: | |
f6688943 | 2075 | /* Don't generate a reloc if we are writing into a variant frag. */ |
252b5132 RH |
2076 | if (place == NULL) |
2077 | { | |
f6688943 TS |
2078 | fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4, |
2079 | address_expr, | |
2080 | (*reloc_type == BFD_RELOC_16_PCREL | |
2081 | || *reloc_type == BFD_RELOC_16_PCREL_S2), | |
2082 | reloc_type[0]); | |
2083 | ||
b6ff326e | 2084 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
2085 | 4 octets for 64bit assembly. */ |
2086 | if (HAVE_64BIT_GPRS && | |
2087 | (*reloc_type == BFD_RELOC_16 | |
98d3f06f KH |
2088 | || *reloc_type == BFD_RELOC_32 |
2089 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2090 | || *reloc_type == BFD_RELOC_HI16_S | |
2091 | || *reloc_type == BFD_RELOC_LO16 | |
2092 | || *reloc_type == BFD_RELOC_GPREL16 | |
2093 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2094 | || *reloc_type == BFD_RELOC_GPREL32 | |
2095 | || *reloc_type == BFD_RELOC_64 | |
2096 | || *reloc_type == BFD_RELOC_CTOR | |
2097 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2098 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2099 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2100 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2101 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2102 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
f6688943 TS |
2103 | fixp[0]->fx_no_overflow = 1; |
2104 | ||
252b5132 RH |
2105 | if (unmatched_hi) |
2106 | { | |
2107 | struct mips_hi_fixup *hi_fixup; | |
2108 | ||
f6688943 | 2109 | assert (*reloc_type == BFD_RELOC_HI16_S); |
252b5132 RH |
2110 | hi_fixup = ((struct mips_hi_fixup *) |
2111 | xmalloc (sizeof (struct mips_hi_fixup))); | |
f6688943 | 2112 | hi_fixup->fixp = fixp[0]; |
252b5132 RH |
2113 | hi_fixup->seg = now_seg; |
2114 | hi_fixup->next = mips_hi_fixup_list; | |
2115 | mips_hi_fixup_list = hi_fixup; | |
2116 | } | |
f6688943 TS |
2117 | |
2118 | if (reloc_type[1] != BFD_RELOC_UNUSED) | |
2119 | { | |
2120 | /* FIXME: This symbol can be one of | |
2121 | RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */ | |
2122 | address_expr->X_op = O_absent; | |
2123 | address_expr->X_add_symbol = 0; | |
2124 | address_expr->X_add_number = 0; | |
2125 | ||
2126 | fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal, | |
2127 | 4, address_expr, false, | |
2128 | reloc_type[1]); | |
2129 | ||
b6ff326e | 2130 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
2131 | 4 octets for 64bit assembly. */ |
2132 | if (HAVE_64BIT_GPRS && | |
2133 | (*reloc_type == BFD_RELOC_16 | |
2134 | || *reloc_type == BFD_RELOC_32 | |
2135 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2136 | || *reloc_type == BFD_RELOC_HI16_S | |
2137 | || *reloc_type == BFD_RELOC_LO16 | |
2138 | || *reloc_type == BFD_RELOC_GPREL16 | |
2139 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2140 | || *reloc_type == BFD_RELOC_GPREL32 | |
2141 | || *reloc_type == BFD_RELOC_64 | |
2142 | || *reloc_type == BFD_RELOC_CTOR | |
2143 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2144 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2145 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2146 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2147 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2148 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
98d3f06f | 2149 | fixp[1]->fx_no_overflow = 1; |
f6688943 TS |
2150 | |
2151 | if (reloc_type[2] != BFD_RELOC_UNUSED) | |
2152 | { | |
2153 | address_expr->X_op = O_absent; | |
2154 | address_expr->X_add_symbol = 0; | |
2155 | address_expr->X_add_number = 0; | |
2156 | ||
2157 | fixp[2] = fix_new_exp (frag_now, | |
2158 | f - frag_now->fr_literal, 4, | |
2159 | address_expr, false, | |
2160 | reloc_type[2]); | |
2161 | ||
b6ff326e | 2162 | /* These relocations can have an addend that won't fit in |
f6688943 TS |
2163 | 4 octets for 64bit assembly. */ |
2164 | if (HAVE_64BIT_GPRS && | |
2165 | (*reloc_type == BFD_RELOC_16 | |
2166 | || *reloc_type == BFD_RELOC_32 | |
2167 | || *reloc_type == BFD_RELOC_MIPS_JMP | |
2168 | || *reloc_type == BFD_RELOC_HI16_S | |
2169 | || *reloc_type == BFD_RELOC_LO16 | |
2170 | || *reloc_type == BFD_RELOC_GPREL16 | |
2171 | || *reloc_type == BFD_RELOC_MIPS_LITERAL | |
2172 | || *reloc_type == BFD_RELOC_GPREL32 | |
2173 | || *reloc_type == BFD_RELOC_64 | |
2174 | || *reloc_type == BFD_RELOC_CTOR | |
2175 | || *reloc_type == BFD_RELOC_MIPS_SUB | |
2176 | || *reloc_type == BFD_RELOC_MIPS_HIGHEST | |
2177 | || *reloc_type == BFD_RELOC_MIPS_HIGHER | |
2178 | || *reloc_type == BFD_RELOC_MIPS_SCN_DISP | |
2179 | || *reloc_type == BFD_RELOC_MIPS_REL16 | |
2180 | || *reloc_type == BFD_RELOC_MIPS_RELGOT)) | |
98d3f06f | 2181 | fixp[2]->fx_no_overflow = 1; |
f6688943 TS |
2182 | } |
2183 | } | |
252b5132 RH |
2184 | } |
2185 | } | |
2186 | } | |
2187 | ||
2188 | if (! mips_opts.mips16) | |
c5dd6aab DJ |
2189 | { |
2190 | md_number_to_chars (f, ip->insn_opcode, 4); | |
2191 | #ifdef OBJ_ELF | |
2192 | dwarf2_emit_insn (4); | |
2193 | #endif | |
2194 | } | |
f6688943 | 2195 | else if (*reloc_type == BFD_RELOC_MIPS16_JMP) |
252b5132 RH |
2196 | { |
2197 | md_number_to_chars (f, ip->insn_opcode >> 16, 2); | |
2198 | md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2); | |
c5dd6aab DJ |
2199 | #ifdef OBJ_ELF |
2200 | dwarf2_emit_insn (4); | |
2201 | #endif | |
252b5132 RH |
2202 | } |
2203 | else | |
2204 | { | |
2205 | if (ip->use_extend) | |
2206 | { | |
2207 | md_number_to_chars (f, 0xf000 | ip->extend, 2); | |
2208 | f += 2; | |
2209 | } | |
2210 | md_number_to_chars (f, ip->insn_opcode, 2); | |
c5dd6aab DJ |
2211 | #ifdef OBJ_ELF |
2212 | dwarf2_emit_insn (ip->use_extend ? 4 : 2); | |
2213 | #endif | |
252b5132 RH |
2214 | } |
2215 | ||
2216 | /* Update the register mask information. */ | |
2217 | if (! mips_opts.mips16) | |
2218 | { | |
2219 | if (pinfo & INSN_WRITE_GPR_D) | |
2220 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD); | |
2221 | if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0) | |
2222 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT); | |
2223 | if (pinfo & INSN_READ_GPR_S) | |
2224 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS); | |
2225 | if (pinfo & INSN_WRITE_GPR_31) | |
f9419b05 | 2226 | mips_gprmask |= 1 << RA; |
252b5132 RH |
2227 | if (pinfo & INSN_WRITE_FPR_D) |
2228 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD); | |
2229 | if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0) | |
2230 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS); | |
2231 | if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0) | |
2232 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT); | |
2233 | if ((pinfo & INSN_READ_FPR_R) != 0) | |
2234 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR); | |
2235 | if (pinfo & INSN_COP) | |
2236 | { | |
bdaaa2e1 KH |
2237 | /* We don't keep enough information to sort these cases out. |
2238 | The itbl support does keep this information however, although | |
2239 | we currently don't support itbl fprmats as part of the cop | |
2240 | instruction. May want to add this support in the future. */ | |
252b5132 RH |
2241 | } |
2242 | /* Never set the bit for $0, which is always zero. */ | |
beae10d5 | 2243 | mips_gprmask &= ~1 << 0; |
252b5132 RH |
2244 | } |
2245 | else | |
2246 | { | |
2247 | if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X)) | |
2248 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX) | |
2249 | & MIPS16OP_MASK_RX); | |
2250 | if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y)) | |
2251 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY) | |
2252 | & MIPS16OP_MASK_RY); | |
2253 | if (pinfo & MIPS16_INSN_WRITE_Z) | |
2254 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ) | |
2255 | & MIPS16OP_MASK_RZ); | |
2256 | if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T)) | |
2257 | mips_gprmask |= 1 << TREG; | |
2258 | if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP)) | |
2259 | mips_gprmask |= 1 << SP; | |
2260 | if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31)) | |
2261 | mips_gprmask |= 1 << RA; | |
2262 | if (pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2263 | mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode); | |
2264 | if (pinfo & MIPS16_INSN_READ_Z) | |
2265 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
2266 | & MIPS16OP_MASK_MOVE32Z); | |
2267 | if (pinfo & MIPS16_INSN_READ_GPR_X) | |
2268 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
2269 | & MIPS16OP_MASK_REGR32); | |
2270 | } | |
2271 | ||
2272 | if (place == NULL && ! mips_opts.noreorder) | |
2273 | { | |
2274 | /* Filling the branch delay slot is more complex. We try to | |
2275 | switch the branch with the previous instruction, which we can | |
2276 | do if the previous instruction does not set up a condition | |
2277 | that the branch tests and if the branch is not itself the | |
2278 | target of any branch. */ | |
2279 | if ((pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2280 | || (pinfo & INSN_COND_BRANCH_DELAY)) | |
2281 | { | |
2282 | if (mips_optimize < 2 | |
2283 | /* If we have seen .set volatile or .set nomove, don't | |
2284 | optimize. */ | |
2285 | || mips_opts.nomove != 0 | |
2286 | /* If we had to emit any NOP instructions, then we | |
2287 | already know we can not swap. */ | |
2288 | || nops != 0 | |
2289 | /* If we don't even know the previous insn, we can not | |
bdaaa2e1 | 2290 | swap. */ |
252b5132 RH |
2291 | || ! prev_insn_valid |
2292 | /* If the previous insn is already in a branch delay | |
2293 | slot, then we can not swap. */ | |
2294 | || prev_insn_is_delay_slot | |
2295 | /* If the previous previous insn was in a .set | |
2296 | noreorder, we can't swap. Actually, the MIPS | |
2297 | assembler will swap in this situation. However, gcc | |
2298 | configured -with-gnu-as will generate code like | |
2299 | .set noreorder | |
2300 | lw $4,XXX | |
2301 | .set reorder | |
2302 | INSN | |
2303 | bne $4,$0,foo | |
2304 | in which we can not swap the bne and INSN. If gcc is | |
2305 | not configured -with-gnu-as, it does not output the | |
2306 | .set pseudo-ops. We don't have to check | |
2307 | prev_insn_unreordered, because prev_insn_valid will | |
2308 | be 0 in that case. We don't want to use | |
2309 | prev_prev_insn_valid, because we do want to be able | |
2310 | to swap at the start of a function. */ | |
2311 | || prev_prev_insn_unreordered | |
2312 | /* If the branch is itself the target of a branch, we | |
2313 | can not swap. We cheat on this; all we check for is | |
2314 | whether there is a label on this instruction. If | |
2315 | there are any branches to anything other than a | |
2316 | label, users must use .set noreorder. */ | |
2317 | || insn_labels != NULL | |
2318 | /* If the previous instruction is in a variant frag, we | |
2319 | can not do the swap. This does not apply to the | |
2320 | mips16, which uses variant frags for different | |
2321 | purposes. */ | |
2322 | || (! mips_opts.mips16 | |
2323 | && prev_insn_frag->fr_type == rs_machine_dependent) | |
2324 | /* If the branch reads the condition codes, we don't | |
2325 | even try to swap, because in the sequence | |
2326 | ctc1 $X,$31 | |
2327 | INSN | |
2328 | INSN | |
2329 | bc1t LABEL | |
2330 | we can not swap, and I don't feel like handling that | |
2331 | case. */ | |
2332 | || (! mips_opts.mips16 | |
9ce8a5dd | 2333 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2334 | && (pinfo & INSN_READ_COND_CODE)) |
2335 | /* We can not swap with an instruction that requires a | |
2336 | delay slot, becase the target of the branch might | |
2337 | interfere with that instruction. */ | |
2338 | || (! mips_opts.mips16 | |
9ce8a5dd | 2339 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 2340 | && (prev_pinfo |
bdaaa2e1 | 2341 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2342 | & (INSN_LOAD_COPROC_DELAY |
2343 | | INSN_COPROC_MOVE_DELAY | |
2344 | | INSN_WRITE_COND_CODE))) | |
2345 | || (! (hilo_interlocks | |
ec68c924 | 2346 | || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
2347 | && (prev_pinfo |
2348 | & (INSN_READ_LO | |
2349 | | INSN_READ_HI))) | |
2350 | || (! mips_opts.mips16 | |
2351 | && ! gpr_interlocks | |
2352 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)) | |
2353 | || (! mips_opts.mips16 | |
e7af610e | 2354 | && mips_opts.isa == ISA_MIPS1 |
bdaaa2e1 | 2355 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2356 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)) |
2357 | /* We can not swap with a branch instruction. */ | |
2358 | || (prev_pinfo | |
2359 | & (INSN_UNCOND_BRANCH_DELAY | |
2360 | | INSN_COND_BRANCH_DELAY | |
2361 | | INSN_COND_BRANCH_LIKELY)) | |
2362 | /* We do not swap with a trap instruction, since it | |
2363 | complicates trap handlers to have the trap | |
2364 | instruction be in a delay slot. */ | |
2365 | || (prev_pinfo & INSN_TRAP) | |
2366 | /* If the branch reads a register that the previous | |
2367 | instruction sets, we can not swap. */ | |
2368 | || (! mips_opts.mips16 | |
2369 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2370 | && insn_uses_reg (ip, | |
2371 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
2372 | & OP_MASK_RT), | |
2373 | MIPS_GR_REG)) | |
2374 | || (! mips_opts.mips16 | |
2375 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2376 | && insn_uses_reg (ip, | |
2377 | ((prev_insn.insn_opcode >> OP_SH_RD) | |
2378 | & OP_MASK_RD), | |
2379 | MIPS_GR_REG)) | |
2380 | || (mips_opts.mips16 | |
2381 | && (((prev_pinfo & MIPS16_INSN_WRITE_X) | |
2382 | && insn_uses_reg (ip, | |
2383 | ((prev_insn.insn_opcode | |
2384 | >> MIPS16OP_SH_RX) | |
2385 | & MIPS16OP_MASK_RX), | |
2386 | MIPS16_REG)) | |
2387 | || ((prev_pinfo & MIPS16_INSN_WRITE_Y) | |
2388 | && insn_uses_reg (ip, | |
2389 | ((prev_insn.insn_opcode | |
2390 | >> MIPS16OP_SH_RY) | |
2391 | & MIPS16OP_MASK_RY), | |
2392 | MIPS16_REG)) | |
2393 | || ((prev_pinfo & MIPS16_INSN_WRITE_Z) | |
2394 | && insn_uses_reg (ip, | |
2395 | ((prev_insn.insn_opcode | |
2396 | >> MIPS16OP_SH_RZ) | |
2397 | & MIPS16OP_MASK_RZ), | |
2398 | MIPS16_REG)) | |
2399 | || ((prev_pinfo & MIPS16_INSN_WRITE_T) | |
2400 | && insn_uses_reg (ip, TREG, MIPS_GR_REG)) | |
2401 | || ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2402 | && insn_uses_reg (ip, RA, MIPS_GR_REG)) | |
2403 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2404 | && insn_uses_reg (ip, | |
2405 | MIPS16OP_EXTRACT_REG32R (prev_insn. | |
2406 | insn_opcode), | |
2407 | MIPS_GR_REG)))) | |
2408 | /* If the branch writes a register that the previous | |
2409 | instruction sets, we can not swap (we know that | |
2410 | branches write only to RD or to $31). */ | |
2411 | || (! mips_opts.mips16 | |
2412 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2413 | && (((pinfo & INSN_WRITE_GPR_D) | |
2414 | && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT) | |
2415 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2416 | || ((pinfo & INSN_WRITE_GPR_31) | |
2417 | && (((prev_insn.insn_opcode >> OP_SH_RT) | |
2418 | & OP_MASK_RT) | |
f9419b05 | 2419 | == RA)))) |
252b5132 RH |
2420 | || (! mips_opts.mips16 |
2421 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2422 | && (((pinfo & INSN_WRITE_GPR_D) | |
2423 | && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD) | |
2424 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2425 | || ((pinfo & INSN_WRITE_GPR_31) | |
2426 | && (((prev_insn.insn_opcode >> OP_SH_RD) | |
2427 | & OP_MASK_RD) | |
f9419b05 | 2428 | == RA)))) |
252b5132 RH |
2429 | || (mips_opts.mips16 |
2430 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2431 | && ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2432 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2433 | && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode) | |
2434 | == RA)))) | |
2435 | /* If the branch writes a register that the previous | |
2436 | instruction reads, we can not swap (we know that | |
2437 | branches only write to RD or to $31). */ | |
2438 | || (! mips_opts.mips16 | |
2439 | && (pinfo & INSN_WRITE_GPR_D) | |
2440 | && insn_uses_reg (&prev_insn, | |
2441 | ((ip->insn_opcode >> OP_SH_RD) | |
2442 | & OP_MASK_RD), | |
2443 | MIPS_GR_REG)) | |
2444 | || (! mips_opts.mips16 | |
2445 | && (pinfo & INSN_WRITE_GPR_31) | |
f9419b05 | 2446 | && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG)) |
252b5132 RH |
2447 | || (mips_opts.mips16 |
2448 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2449 | && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG)) | |
2450 | /* If we are generating embedded PIC code, the branch | |
2451 | might be expanded into a sequence which uses $at, so | |
2452 | we can't swap with an instruction which reads it. */ | |
2453 | || (mips_pic == EMBEDDED_PIC | |
2454 | && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG)) | |
2455 | /* If the previous previous instruction has a load | |
2456 | delay, and sets a register that the branch reads, we | |
2457 | can not swap. */ | |
2458 | || (! mips_opts.mips16 | |
9ce8a5dd | 2459 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
bdaaa2e1 | 2460 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2461 | && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY) |
2462 | || (! gpr_interlocks | |
2463 | && (prev_prev_insn.insn_mo->pinfo | |
2464 | & INSN_LOAD_MEMORY_DELAY))) | |
2465 | && insn_uses_reg (ip, | |
2466 | ((prev_prev_insn.insn_opcode >> OP_SH_RT) | |
2467 | & OP_MASK_RT), | |
2468 | MIPS_GR_REG)) | |
2469 | /* If one instruction sets a condition code and the | |
2470 | other one uses a condition code, we can not swap. */ | |
2471 | || ((pinfo & INSN_READ_COND_CODE) | |
2472 | && (prev_pinfo & INSN_WRITE_COND_CODE)) | |
2473 | || ((pinfo & INSN_WRITE_COND_CODE) | |
2474 | && (prev_pinfo & INSN_READ_COND_CODE)) | |
2475 | /* If the previous instruction uses the PC, we can not | |
2476 | swap. */ | |
2477 | || (mips_opts.mips16 | |
2478 | && (prev_pinfo & MIPS16_INSN_READ_PC)) | |
2479 | /* If the previous instruction was extended, we can not | |
2480 | swap. */ | |
2481 | || (mips_opts.mips16 && prev_insn_extended) | |
2482 | /* If the previous instruction had a fixup in mips16 | |
2483 | mode, we can not swap. This normally means that the | |
2484 | previous instruction was a 4 byte branch anyhow. */ | |
f6688943 | 2485 | || (mips_opts.mips16 && prev_insn_fixp[0]) |
bdaaa2e1 KH |
2486 | /* If the previous instruction is a sync, sync.l, or |
2487 | sync.p, we can not swap. */ | |
f173e82e | 2488 | || (prev_pinfo & INSN_SYNC)) |
252b5132 RH |
2489 | { |
2490 | /* We could do even better for unconditional branches to | |
2491 | portions of this object file; we could pick up the | |
2492 | instruction at the destination, put it in the delay | |
2493 | slot, and bump the destination address. */ | |
2494 | emit_nop (); | |
2495 | /* Update the previous insn information. */ | |
2496 | prev_prev_insn = *ip; | |
2497 | prev_insn.insn_mo = &dummy_opcode; | |
2498 | } | |
2499 | else | |
2500 | { | |
2501 | /* It looks like we can actually do the swap. */ | |
2502 | if (! mips_opts.mips16) | |
2503 | { | |
2504 | char *prev_f; | |
2505 | char temp[4]; | |
2506 | ||
2507 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2508 | memcpy (temp, prev_f, 4); | |
2509 | memcpy (prev_f, f, 4); | |
2510 | memcpy (f, temp, 4); | |
f6688943 TS |
2511 | if (prev_insn_fixp[0]) |
2512 | { | |
2513 | prev_insn_fixp[0]->fx_frag = frag_now; | |
2514 | prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal; | |
2515 | } | |
2516 | if (prev_insn_fixp[1]) | |
2517 | { | |
2518 | prev_insn_fixp[1]->fx_frag = frag_now; | |
2519 | prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal; | |
2520 | } | |
2521 | if (prev_insn_fixp[2]) | |
252b5132 | 2522 | { |
f6688943 TS |
2523 | prev_insn_fixp[2]->fx_frag = frag_now; |
2524 | prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal; | |
252b5132 | 2525 | } |
f6688943 | 2526 | if (fixp[0]) |
252b5132 | 2527 | { |
f6688943 TS |
2528 | fixp[0]->fx_frag = prev_insn_frag; |
2529 | fixp[0]->fx_where = prev_insn_where; | |
2530 | } | |
2531 | if (fixp[1]) | |
2532 | { | |
2533 | fixp[1]->fx_frag = prev_insn_frag; | |
2534 | fixp[1]->fx_where = prev_insn_where; | |
2535 | } | |
2536 | if (fixp[2]) | |
2537 | { | |
2538 | fixp[2]->fx_frag = prev_insn_frag; | |
2539 | fixp[2]->fx_where = prev_insn_where; | |
252b5132 RH |
2540 | } |
2541 | } | |
2542 | else | |
2543 | { | |
2544 | char *prev_f; | |
2545 | char temp[2]; | |
2546 | ||
f6688943 TS |
2547 | assert (prev_insn_fixp[0] == NULL); |
2548 | assert (prev_insn_fixp[1] == NULL); | |
2549 | assert (prev_insn_fixp[2] == NULL); | |
252b5132 RH |
2550 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; |
2551 | memcpy (temp, prev_f, 2); | |
2552 | memcpy (prev_f, f, 2); | |
f6688943 | 2553 | if (*reloc_type != BFD_RELOC_MIPS16_JMP) |
252b5132 | 2554 | { |
f6688943 | 2555 | assert (*reloc_type == BFD_RELOC_UNUSED); |
252b5132 RH |
2556 | memcpy (f, temp, 2); |
2557 | } | |
2558 | else | |
2559 | { | |
2560 | memcpy (f, f + 2, 2); | |
2561 | memcpy (f + 2, temp, 2); | |
2562 | } | |
f6688943 TS |
2563 | if (fixp[0]) |
2564 | { | |
2565 | fixp[0]->fx_frag = prev_insn_frag; | |
2566 | fixp[0]->fx_where = prev_insn_where; | |
2567 | } | |
2568 | if (fixp[1]) | |
2569 | { | |
2570 | fixp[1]->fx_frag = prev_insn_frag; | |
2571 | fixp[1]->fx_where = prev_insn_where; | |
2572 | } | |
2573 | if (fixp[2]) | |
252b5132 | 2574 | { |
f6688943 TS |
2575 | fixp[2]->fx_frag = prev_insn_frag; |
2576 | fixp[2]->fx_where = prev_insn_where; | |
252b5132 RH |
2577 | } |
2578 | } | |
2579 | ||
2580 | /* Update the previous insn information; leave prev_insn | |
2581 | unchanged. */ | |
2582 | prev_prev_insn = *ip; | |
2583 | } | |
2584 | prev_insn_is_delay_slot = 1; | |
2585 | ||
2586 | /* If that was an unconditional branch, forget the previous | |
2587 | insn information. */ | |
2588 | if (pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2589 | { | |
2590 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2591 | prev_insn.insn_mo = &dummy_opcode; | |
2592 | } | |
2593 | ||
f6688943 TS |
2594 | prev_insn_fixp[0] = NULL; |
2595 | prev_insn_fixp[1] = NULL; | |
2596 | prev_insn_fixp[2] = NULL; | |
2597 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; | |
2598 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2599 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2600 | prev_insn_extended = 0; |
2601 | } | |
2602 | else if (pinfo & INSN_COND_BRANCH_LIKELY) | |
2603 | { | |
2604 | /* We don't yet optimize a branch likely. What we should do | |
2605 | is look at the target, copy the instruction found there | |
2606 | into the delay slot, and increment the branch to jump to | |
2607 | the next instruction. */ | |
2608 | emit_nop (); | |
2609 | /* Update the previous insn information. */ | |
2610 | prev_prev_insn = *ip; | |
2611 | prev_insn.insn_mo = &dummy_opcode; | |
f6688943 TS |
2612 | prev_insn_fixp[0] = NULL; |
2613 | prev_insn_fixp[1] = NULL; | |
2614 | prev_insn_fixp[2] = NULL; | |
2615 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; | |
2616 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2617 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2618 | prev_insn_extended = 0; |
2619 | } | |
2620 | else | |
2621 | { | |
2622 | /* Update the previous insn information. */ | |
2623 | if (nops > 0) | |
2624 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2625 | else | |
2626 | prev_prev_insn = prev_insn; | |
2627 | prev_insn = *ip; | |
2628 | ||
2629 | /* Any time we see a branch, we always fill the delay slot | |
2630 | immediately; since this insn is not a branch, we know it | |
2631 | is not in a delay slot. */ | |
2632 | prev_insn_is_delay_slot = 0; | |
2633 | ||
f6688943 TS |
2634 | prev_insn_fixp[0] = fixp[0]; |
2635 | prev_insn_fixp[1] = fixp[1]; | |
2636 | prev_insn_fixp[2] = fixp[2]; | |
2637 | prev_insn_reloc_type[0] = reloc_type[0]; | |
2638 | prev_insn_reloc_type[1] = reloc_type[1]; | |
2639 | prev_insn_reloc_type[2] = reloc_type[2]; | |
252b5132 RH |
2640 | if (mips_opts.mips16) |
2641 | prev_insn_extended = (ip->use_extend | |
f6688943 | 2642 | || *reloc_type > BFD_RELOC_UNUSED); |
252b5132 RH |
2643 | } |
2644 | ||
2645 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2646 | prev_insn_unreordered = 0; | |
2647 | prev_insn_frag = frag_now; | |
2648 | prev_insn_where = f - frag_now->fr_literal; | |
2649 | prev_insn_valid = 1; | |
2650 | } | |
2651 | else if (place == NULL) | |
2652 | { | |
2653 | /* We need to record a bit of information even when we are not | |
2654 | reordering, in order to determine the base address for mips16 | |
2655 | PC relative relocs. */ | |
2656 | prev_prev_insn = prev_insn; | |
2657 | prev_insn = *ip; | |
f6688943 TS |
2658 | prev_insn_reloc_type[0] = reloc_type[0]; |
2659 | prev_insn_reloc_type[1] = reloc_type[1]; | |
2660 | prev_insn_reloc_type[2] = reloc_type[2]; | |
252b5132 RH |
2661 | prev_prev_insn_unreordered = prev_insn_unreordered; |
2662 | prev_insn_unreordered = 1; | |
2663 | } | |
2664 | ||
2665 | /* We just output an insn, so the next one doesn't have a label. */ | |
2666 | mips_clear_insn_labels (); | |
2667 | ||
2668 | /* We must ensure that a fixup associated with an unmatched %hi | |
2669 | reloc does not become a variant frag. Otherwise, the | |
2670 | rearrangement of %hi relocs in frob_file may confuse | |
2671 | tc_gen_reloc. */ | |
2672 | if (unmatched_hi) | |
2673 | { | |
2674 | frag_wane (frag_now); | |
2675 | frag_new (0); | |
2676 | } | |
2677 | } | |
2678 | ||
2679 | /* This function forgets that there was any previous instruction or | |
2680 | label. If PRESERVE is non-zero, it remembers enough information to | |
bdaaa2e1 | 2681 | know whether nops are needed before a noreorder section. */ |
252b5132 RH |
2682 | |
2683 | static void | |
2684 | mips_no_prev_insn (preserve) | |
2685 | int preserve; | |
2686 | { | |
2687 | if (! preserve) | |
2688 | { | |
2689 | prev_insn.insn_mo = &dummy_opcode; | |
2690 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2691 | prev_nop_frag = NULL; | |
2692 | prev_nop_frag_holds = 0; | |
2693 | prev_nop_frag_required = 0; | |
2694 | prev_nop_frag_since = 0; | |
2695 | } | |
2696 | prev_insn_valid = 0; | |
2697 | prev_insn_is_delay_slot = 0; | |
2698 | prev_insn_unreordered = 0; | |
2699 | prev_insn_extended = 0; | |
f6688943 TS |
2700 | prev_insn_reloc_type[0] = BFD_RELOC_UNUSED; |
2701 | prev_insn_reloc_type[1] = BFD_RELOC_UNUSED; | |
2702 | prev_insn_reloc_type[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2703 | prev_prev_insn_unreordered = 0; |
2704 | mips_clear_insn_labels (); | |
2705 | } | |
2706 | ||
2707 | /* This function must be called whenever we turn on noreorder or emit | |
2708 | something other than instructions. It inserts any NOPS which might | |
2709 | be needed by the previous instruction, and clears the information | |
2710 | kept for the previous instructions. The INSNS parameter is true if | |
bdaaa2e1 | 2711 | instructions are to follow. */ |
252b5132 RH |
2712 | |
2713 | static void | |
2714 | mips_emit_delays (insns) | |
2715 | boolean insns; | |
2716 | { | |
2717 | if (! mips_opts.noreorder) | |
2718 | { | |
2719 | int nops; | |
2720 | ||
2721 | nops = 0; | |
2722 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2723 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2724 | && (! cop_interlocks |
2725 | && (prev_insn.insn_mo->pinfo | |
2726 | & (INSN_LOAD_COPROC_DELAY | |
2727 | | INSN_COPROC_MOVE_DELAY | |
2728 | | INSN_WRITE_COND_CODE)))) | |
2729 | || (! hilo_interlocks | |
2730 | && (prev_insn.insn_mo->pinfo | |
2731 | & (INSN_READ_LO | |
2732 | | INSN_READ_HI))) | |
2733 | || (! mips_opts.mips16 | |
2734 | && ! gpr_interlocks | |
bdaaa2e1 | 2735 | && (prev_insn.insn_mo->pinfo |
252b5132 RH |
2736 | & INSN_LOAD_MEMORY_DELAY)) |
2737 | || (! mips_opts.mips16 | |
e7af610e | 2738 | && mips_opts.isa == ISA_MIPS1 |
252b5132 RH |
2739 | && (prev_insn.insn_mo->pinfo |
2740 | & INSN_COPROC_MEMORY_DELAY))) | |
2741 | { | |
beae10d5 | 2742 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2743 | ++nops; |
2744 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2745 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2746 | && (! cop_interlocks |
2747 | && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2748 | || (! hilo_interlocks | |
2749 | && ((prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2750 | || (prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2751 | ++nops; | |
2752 | ||
2753 | if (prev_insn_unreordered) | |
2754 | nops = 0; | |
2755 | } | |
2756 | else if ((! mips_opts.mips16 | |
9ce8a5dd | 2757 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2758 | && (! cop_interlocks |
2759 | && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2760 | || (! hilo_interlocks | |
2761 | && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2762 | || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2763 | { | |
beae10d5 | 2764 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2765 | if (! prev_prev_insn_unreordered) |
2766 | ++nops; | |
2767 | } | |
2768 | ||
60b63b72 RS |
2769 | if (mips_fix_4122_bugs && prev_insn.insn_mo->name) |
2770 | { | |
2771 | int min_nops = 0; | |
2772 | const char *pn = prev_insn.insn_mo->name; | |
2773 | if (strncmp(pn, "macc", 4) == 0 | |
2774 | || strncmp(pn, "dmacc", 5) == 0 | |
2775 | || strncmp(pn, "dmult", 5) == 0) | |
2776 | { | |
2777 | min_nops = 1; | |
2778 | } | |
2779 | if (nops < min_nops) | |
2780 | nops = min_nops; | |
2781 | } | |
2782 | ||
252b5132 RH |
2783 | if (nops > 0) |
2784 | { | |
2785 | struct insn_label_list *l; | |
2786 | ||
2787 | if (insns) | |
2788 | { | |
2789 | /* Record the frag which holds the nop instructions, so | |
2790 | that we can remove them if we don't need them. */ | |
2791 | frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4); | |
2792 | prev_nop_frag = frag_now; | |
2793 | prev_nop_frag_holds = nops; | |
2794 | prev_nop_frag_required = 0; | |
2795 | prev_nop_frag_since = 0; | |
2796 | } | |
2797 | ||
2798 | for (; nops > 0; --nops) | |
2799 | emit_nop (); | |
2800 | ||
2801 | if (insns) | |
2802 | { | |
2803 | /* Move on to a new frag, so that it is safe to simply | |
bdaaa2e1 | 2804 | decrease the size of prev_nop_frag. */ |
252b5132 RH |
2805 | frag_wane (frag_now); |
2806 | frag_new (0); | |
2807 | } | |
2808 | ||
2809 | for (l = insn_labels; l != NULL; l = l->next) | |
2810 | { | |
98aa84af AM |
2811 | valueT val; |
2812 | ||
252b5132 | 2813 | assert (S_GET_SEGMENT (l->label) == now_seg); |
49309057 | 2814 | symbol_set_frag (l->label, frag_now); |
98aa84af | 2815 | val = (valueT) frag_now_fix (); |
252b5132 RH |
2816 | /* mips16 text labels are stored as odd. */ |
2817 | if (mips_opts.mips16) | |
f9419b05 | 2818 | ++val; |
98aa84af | 2819 | S_SET_VALUE (l->label, val); |
252b5132 RH |
2820 | } |
2821 | } | |
2822 | } | |
2823 | ||
2824 | /* Mark instruction labels in mips16 mode. */ | |
f9419b05 | 2825 | if (insns) |
252b5132 RH |
2826 | mips16_mark_labels (); |
2827 | ||
2828 | mips_no_prev_insn (insns); | |
2829 | } | |
2830 | ||
2831 | /* Build an instruction created by a macro expansion. This is passed | |
2832 | a pointer to the count of instructions created so far, an | |
2833 | expression, the name of the instruction to build, an operand format | |
2834 | string, and corresponding arguments. */ | |
2835 | ||
2836 | #ifdef USE_STDARG | |
2837 | static void | |
2838 | macro_build (char *place, | |
2839 | int *counter, | |
2840 | expressionS * ep, | |
2841 | const char *name, | |
2842 | const char *fmt, | |
2843 | ...) | |
2844 | #else | |
2845 | static void | |
2846 | macro_build (place, counter, ep, name, fmt, va_alist) | |
2847 | char *place; | |
2848 | int *counter; | |
2849 | expressionS *ep; | |
2850 | const char *name; | |
2851 | const char *fmt; | |
2852 | va_dcl | |
2853 | #endif | |
2854 | { | |
2855 | struct mips_cl_insn insn; | |
f6688943 | 2856 | bfd_reloc_code_real_type r[3]; |
252b5132 | 2857 | va_list args; |
252b5132 RH |
2858 | |
2859 | #ifdef USE_STDARG | |
2860 | va_start (args, fmt); | |
2861 | #else | |
2862 | va_start (args); | |
2863 | #endif | |
2864 | ||
2865 | /* | |
2866 | * If the macro is about to expand into a second instruction, | |
2867 | * print a warning if needed. We need to pass ip as a parameter | |
2868 | * to generate a better warning message here... | |
2869 | */ | |
2870 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2871 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2872 | ||
80cc45a5 EC |
2873 | /* |
2874 | * If the macro is about to expand into a second instruction, | |
2875 | * and it is in a delay slot, print a warning. | |
2876 | */ | |
2877 | if (place == NULL | |
2878 | && *counter == 1 | |
2879 | && mips_opts.noreorder | |
2880 | && (prev_prev_insn.insn_mo->pinfo | |
2881 | & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY | |
2b2e39bf | 2882 | | INSN_COND_BRANCH_LIKELY)) != 0) |
80cc45a5 EC |
2883 | as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot")); |
2884 | ||
252b5132 | 2885 | if (place == NULL) |
f9419b05 | 2886 | ++*counter; /* bump instruction counter */ |
252b5132 RH |
2887 | |
2888 | if (mips_opts.mips16) | |
2889 | { | |
2890 | mips16_macro_build (place, counter, ep, name, fmt, args); | |
2891 | va_end (args); | |
2892 | return; | |
2893 | } | |
2894 | ||
f6688943 TS |
2895 | r[0] = BFD_RELOC_UNUSED; |
2896 | r[1] = BFD_RELOC_UNUSED; | |
2897 | r[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
2898 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); |
2899 | assert (insn.insn_mo); | |
2900 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2901 | ||
2902 | /* Search until we get a match for NAME. */ | |
2903 | while (1) | |
2904 | { | |
deec1734 CD |
2905 | /* It is assumed here that macros will never generate |
2906 | MDMX or MIPS-3D instructions. */ | |
252b5132 RH |
2907 | if (strcmp (fmt, insn.insn_mo->args) == 0 |
2908 | && insn.insn_mo->pinfo != INSN_MACRO | |
aec421e0 TS |
2909 | && OPCODE_IS_MEMBER (insn.insn_mo, |
2910 | (mips_opts.isa | |
3396de36 | 2911 | | (file_ase_mips16 ? INSN_MIPS16 : 0)), |
aec421e0 | 2912 | mips_arch) |
ec68c924 | 2913 | && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0)) |
252b5132 RH |
2914 | break; |
2915 | ||
2916 | ++insn.insn_mo; | |
2917 | assert (insn.insn_mo->name); | |
2918 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2919 | } | |
2920 | ||
2921 | insn.insn_opcode = insn.insn_mo->match; | |
2922 | for (;;) | |
2923 | { | |
2924 | switch (*fmt++) | |
2925 | { | |
2926 | case '\0': | |
2927 | break; | |
2928 | ||
2929 | case ',': | |
2930 | case '(': | |
2931 | case ')': | |
2932 | continue; | |
2933 | ||
2934 | case 't': | |
2935 | case 'w': | |
2936 | case 'E': | |
38487616 | 2937 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RT; |
252b5132 RH |
2938 | continue; |
2939 | ||
2940 | case 'c': | |
38487616 TS |
2941 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE; |
2942 | continue; | |
2943 | ||
252b5132 RH |
2944 | case 'T': |
2945 | case 'W': | |
38487616 | 2946 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FT; |
252b5132 RH |
2947 | continue; |
2948 | ||
2949 | case 'd': | |
2950 | case 'G': | |
38487616 | 2951 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RD; |
252b5132 RH |
2952 | continue; |
2953 | ||
4372b673 NC |
2954 | case 'U': |
2955 | { | |
2956 | int tmp = va_arg (args, int); | |
2957 | ||
38487616 TS |
2958 | insn.insn_opcode |= tmp << OP_SH_RT; |
2959 | insn.insn_opcode |= tmp << OP_SH_RD; | |
beae10d5 | 2960 | continue; |
4372b673 NC |
2961 | } |
2962 | ||
252b5132 RH |
2963 | case 'V': |
2964 | case 'S': | |
38487616 | 2965 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FS; |
252b5132 RH |
2966 | continue; |
2967 | ||
2968 | case 'z': | |
2969 | continue; | |
2970 | ||
2971 | case '<': | |
38487616 | 2972 | insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT; |
252b5132 RH |
2973 | continue; |
2974 | ||
2975 | case 'D': | |
38487616 | 2976 | insn.insn_opcode |= va_arg (args, int) << OP_SH_FD; |
252b5132 RH |
2977 | continue; |
2978 | ||
2979 | case 'B': | |
38487616 | 2980 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20; |
252b5132 RH |
2981 | continue; |
2982 | ||
4372b673 | 2983 | case 'J': |
38487616 | 2984 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19; |
4372b673 NC |
2985 | continue; |
2986 | ||
252b5132 | 2987 | case 'q': |
38487616 | 2988 | insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2; |
252b5132 RH |
2989 | continue; |
2990 | ||
2991 | case 'b': | |
2992 | case 's': | |
2993 | case 'r': | |
2994 | case 'v': | |
38487616 | 2995 | insn.insn_opcode |= va_arg (args, int) << OP_SH_RS; |
252b5132 RH |
2996 | continue; |
2997 | ||
2998 | case 'i': | |
2999 | case 'j': | |
3000 | case 'o': | |
f6688943 | 3001 | *r = (bfd_reloc_code_real_type) va_arg (args, int); |
cdf6fd85 | 3002 | assert (*r == BFD_RELOC_GPREL16 |
f6688943 TS |
3003 | || *r == BFD_RELOC_MIPS_LITERAL |
3004 | || *r == BFD_RELOC_MIPS_HIGHER | |
3005 | || *r == BFD_RELOC_HI16_S | |
3006 | || *r == BFD_RELOC_LO16 | |
3007 | || *r == BFD_RELOC_MIPS_GOT16 | |
3008 | || *r == BFD_RELOC_MIPS_CALL16 | |
438c16b8 TS |
3009 | || *r == BFD_RELOC_MIPS_GOT_DISP |
3010 | || *r == BFD_RELOC_MIPS_GOT_PAGE | |
3011 | || *r == BFD_RELOC_MIPS_GOT_OFST | |
f6688943 TS |
3012 | || *r == BFD_RELOC_MIPS_GOT_LO16 |
3013 | || *r == BFD_RELOC_MIPS_CALL_LO16 | |
252b5132 | 3014 | || (ep->X_op == O_subtract |
f6688943 | 3015 | && *r == BFD_RELOC_PCREL_LO16)); |
252b5132 RH |
3016 | continue; |
3017 | ||
3018 | case 'u': | |
f6688943 | 3019 | *r = (bfd_reloc_code_real_type) va_arg (args, int); |
252b5132 RH |
3020 | assert (ep != NULL |
3021 | && (ep->X_op == O_constant | |
3022 | || (ep->X_op == O_symbol | |
f6688943 TS |
3023 | && (*r == BFD_RELOC_MIPS_HIGHEST |
3024 | || *r == BFD_RELOC_HI16_S | |
3025 | || *r == BFD_RELOC_HI16 | |
3026 | || *r == BFD_RELOC_GPREL16 | |
3027 | || *r == BFD_RELOC_MIPS_GOT_HI16 | |
3028 | || *r == BFD_RELOC_MIPS_CALL_HI16)) | |
252b5132 | 3029 | || (ep->X_op == O_subtract |
f6688943 | 3030 | && *r == BFD_RELOC_PCREL_HI16_S))); |
252b5132 RH |
3031 | continue; |
3032 | ||
3033 | case 'p': | |
3034 | assert (ep != NULL); | |
3035 | /* | |
3036 | * This allows macro() to pass an immediate expression for | |
3037 | * creating short branches without creating a symbol. | |
3038 | * Note that the expression still might come from the assembly | |
3039 | * input, in which case the value is not checked for range nor | |
3040 | * is a relocation entry generated (yuck). | |
3041 | */ | |
3042 | if (ep->X_op == O_constant) | |
3043 | { | |
3044 | insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff; | |
3045 | ep = NULL; | |
3046 | } | |
3047 | else | |
cb56d3d3 | 3048 | if (mips_pic == EMBEDDED_PIC) |
f6688943 | 3049 | *r = BFD_RELOC_16_PCREL_S2; |
cb56d3d3 | 3050 | else |
f6688943 | 3051 | *r = BFD_RELOC_16_PCREL; |
252b5132 RH |
3052 | continue; |
3053 | ||
3054 | case 'a': | |
3055 | assert (ep != NULL); | |
f6688943 | 3056 | *r = BFD_RELOC_MIPS_JMP; |
252b5132 RH |
3057 | continue; |
3058 | ||
3059 | case 'C': | |
3060 | insn.insn_opcode |= va_arg (args, unsigned long); | |
3061 | continue; | |
3062 | ||
3063 | default: | |
3064 | internalError (); | |
3065 | } | |
3066 | break; | |
3067 | } | |
3068 | va_end (args); | |
f6688943 | 3069 | assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
252b5132 RH |
3070 | |
3071 | append_insn (place, &insn, ep, r, false); | |
3072 | } | |
3073 | ||
3074 | static void | |
3075 | mips16_macro_build (place, counter, ep, name, fmt, args) | |
3076 | char *place; | |
43841e91 | 3077 | int *counter ATTRIBUTE_UNUSED; |
252b5132 RH |
3078 | expressionS *ep; |
3079 | const char *name; | |
3080 | const char *fmt; | |
3081 | va_list args; | |
3082 | { | |
3083 | struct mips_cl_insn insn; | |
f6688943 TS |
3084 | bfd_reloc_code_real_type r[3] |
3085 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
252b5132 | 3086 | |
252b5132 RH |
3087 | insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name); |
3088 | assert (insn.insn_mo); | |
3089 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
3090 | ||
3091 | while (strcmp (fmt, insn.insn_mo->args) != 0 | |
3092 | || insn.insn_mo->pinfo == INSN_MACRO) | |
3093 | { | |
3094 | ++insn.insn_mo; | |
3095 | assert (insn.insn_mo->name); | |
3096 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
3097 | } | |
3098 | ||
3099 | insn.insn_opcode = insn.insn_mo->match; | |
3100 | insn.use_extend = false; | |
3101 | ||
3102 | for (;;) | |
3103 | { | |
3104 | int c; | |
3105 | ||
3106 | c = *fmt++; | |
3107 | switch (c) | |
3108 | { | |
3109 | case '\0': | |
3110 | break; | |
3111 | ||
3112 | case ',': | |
3113 | case '(': | |
3114 | case ')': | |
3115 | continue; | |
3116 | ||
3117 | case 'y': | |
3118 | case 'w': | |
3119 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY; | |
3120 | continue; | |
3121 | ||
3122 | case 'x': | |
3123 | case 'v': | |
3124 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX; | |
3125 | continue; | |
3126 | ||
3127 | case 'z': | |
3128 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ; | |
3129 | continue; | |
3130 | ||
3131 | case 'Z': | |
3132 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z; | |
3133 | continue; | |
3134 | ||
3135 | case '0': | |
3136 | case 'S': | |
3137 | case 'P': | |
3138 | case 'R': | |
3139 | continue; | |
3140 | ||
3141 | case 'X': | |
3142 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32; | |
3143 | continue; | |
3144 | ||
3145 | case 'Y': | |
3146 | { | |
3147 | int regno; | |
3148 | ||
3149 | regno = va_arg (args, int); | |
3150 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
3151 | insn.insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
3152 | } | |
3153 | continue; | |
3154 | ||
3155 | case '<': | |
3156 | case '>': | |
3157 | case '4': | |
3158 | case '5': | |
3159 | case 'H': | |
3160 | case 'W': | |
3161 | case 'D': | |
3162 | case 'j': | |
3163 | case '8': | |
3164 | case 'V': | |
3165 | case 'C': | |
3166 | case 'U': | |
3167 | case 'k': | |
3168 | case 'K': | |
3169 | case 'p': | |
3170 | case 'q': | |
3171 | { | |
3172 | assert (ep != NULL); | |
3173 | ||
3174 | if (ep->X_op != O_constant) | |
874e8986 | 3175 | *r = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
3176 | else |
3177 | { | |
c4e7957c TS |
3178 | mips16_immed (NULL, 0, c, ep->X_add_number, false, false, |
3179 | false, &insn.insn_opcode, &insn.use_extend, | |
3180 | &insn.extend); | |
252b5132 | 3181 | ep = NULL; |
f6688943 | 3182 | *r = BFD_RELOC_UNUSED; |
252b5132 RH |
3183 | } |
3184 | } | |
3185 | continue; | |
3186 | ||
3187 | case '6': | |
3188 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6; | |
3189 | continue; | |
3190 | } | |
3191 | ||
3192 | break; | |
3193 | } | |
3194 | ||
f6688943 | 3195 | assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
252b5132 RH |
3196 | |
3197 | append_insn (place, &insn, ep, r, false); | |
3198 | } | |
3199 | ||
438c16b8 TS |
3200 | /* |
3201 | * Generate a "jalr" instruction with a relocation hint to the called | |
3202 | * function. This occurs in NewABI PIC code. | |
3203 | */ | |
3204 | static void | |
3205 | macro_build_jalr (icnt, ep) | |
3206 | int icnt; | |
3207 | expressionS *ep; | |
3208 | { | |
f21f8242 AO |
3209 | char *f; |
3210 | ||
438c16b8 | 3211 | if (HAVE_NEWABI) |
f21f8242 AO |
3212 | { |
3213 | frag_grow (4); | |
3214 | f = frag_more (0); | |
3215 | } | |
438c16b8 TS |
3216 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", "d,s", |
3217 | RA, PIC_CALL_REG); | |
3218 | if (HAVE_NEWABI) | |
f21f8242 AO |
3219 | fix_new_exp (frag_now, f - frag_now->fr_literal, |
3220 | 0, ep, false, BFD_RELOC_MIPS_JALR); | |
438c16b8 TS |
3221 | } |
3222 | ||
252b5132 RH |
3223 | /* |
3224 | * Generate a "lui" instruction. | |
3225 | */ | |
3226 | static void | |
3227 | macro_build_lui (place, counter, ep, regnum) | |
3228 | char *place; | |
3229 | int *counter; | |
3230 | expressionS *ep; | |
3231 | int regnum; | |
3232 | { | |
3233 | expressionS high_expr; | |
3234 | struct mips_cl_insn insn; | |
f6688943 TS |
3235 | bfd_reloc_code_real_type r[3] |
3236 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; | |
5a38dc70 AM |
3237 | const char *name = "lui"; |
3238 | const char *fmt = "t,u"; | |
252b5132 RH |
3239 | |
3240 | assert (! mips_opts.mips16); | |
3241 | ||
3242 | if (place == NULL) | |
3243 | high_expr = *ep; | |
3244 | else | |
3245 | { | |
3246 | high_expr.X_op = O_constant; | |
3247 | high_expr.X_add_number = ep->X_add_number; | |
3248 | } | |
3249 | ||
3250 | if (high_expr.X_op == O_constant) | |
3251 | { | |
3252 | /* we can compute the instruction now without a relocation entry */ | |
e7d556df TS |
3253 | high_expr.X_add_number = ((high_expr.X_add_number + 0x8000) |
3254 | >> 16) & 0xffff; | |
f6688943 | 3255 | *r = BFD_RELOC_UNUSED; |
252b5132 | 3256 | } |
f6688943 | 3257 | else if (! HAVE_NEWABI) |
252b5132 RH |
3258 | { |
3259 | assert (ep->X_op == O_symbol); | |
3260 | /* _gp_disp is a special case, used from s_cpload. */ | |
3261 | assert (mips_pic == NO_PIC | |
3262 | || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0); | |
f6688943 | 3263 | *r = BFD_RELOC_HI16_S; |
252b5132 RH |
3264 | } |
3265 | ||
3266 | /* | |
3267 | * If the macro is about to expand into a second instruction, | |
3268 | * print a warning if needed. We need to pass ip as a parameter | |
3269 | * to generate a better warning message here... | |
3270 | */ | |
3271 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
3272 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
3273 | ||
3274 | if (place == NULL) | |
f9419b05 | 3275 | ++*counter; /* bump instruction counter */ |
252b5132 RH |
3276 | |
3277 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
3278 | assert (insn.insn_mo); | |
3279 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
3280 | assert (strcmp (fmt, insn.insn_mo->args) == 0); | |
3281 | ||
3282 | insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT); | |
f6688943 | 3283 | if (*r == BFD_RELOC_UNUSED) |
252b5132 RH |
3284 | { |
3285 | insn.insn_opcode |= high_expr.X_add_number; | |
3286 | append_insn (place, &insn, NULL, r, false); | |
3287 | } | |
3288 | else | |
3289 | append_insn (place, &insn, &high_expr, r, false); | |
3290 | } | |
3291 | ||
885add95 CD |
3292 | /* Generate a sequence of instructions to do a load or store from a constant |
3293 | offset off of a base register (breg) into/from a target register (treg), | |
3294 | using AT if necessary. */ | |
3295 | static void | |
3296 | macro_build_ldst_constoffset (place, counter, ep, op, treg, breg) | |
3297 | char *place; | |
3298 | int *counter; | |
3299 | expressionS *ep; | |
3300 | const char *op; | |
3301 | int treg, breg; | |
3302 | { | |
3303 | assert (ep->X_op == O_constant); | |
3304 | ||
3305 | /* Right now, this routine can only handle signed 32-bit contants. */ | |
3306 | if (! IS_SEXT_32BIT_NUM(ep->X_add_number)) | |
3307 | as_warn (_("operand overflow")); | |
3308 | ||
3309 | if (IS_SEXT_16BIT_NUM(ep->X_add_number)) | |
3310 | { | |
3311 | /* Signed 16-bit offset will fit in the op. Easy! */ | |
3312 | macro_build (place, counter, ep, op, "t,o(b)", treg, | |
3313 | (int) BFD_RELOC_LO16, breg); | |
3314 | } | |
3315 | else | |
3316 | { | |
3317 | /* 32-bit offset, need multiple instructions and AT, like: | |
3318 | lui $tempreg,const_hi (BFD_RELOC_HI16_S) | |
3319 | addu $tempreg,$tempreg,$breg | |
3320 | <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16) | |
3321 | to handle the complete offset. */ | |
3322 | macro_build_lui (place, counter, ep, AT); | |
3323 | if (place != NULL) | |
3324 | place += 4; | |
3325 | macro_build (place, counter, (expressionS *) NULL, | |
3326 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", | |
3327 | "d,v,t", AT, AT, breg); | |
3328 | if (place != NULL) | |
3329 | place += 4; | |
3330 | macro_build (place, counter, ep, op, "t,o(b)", treg, | |
3331 | (int) BFD_RELOC_LO16, AT); | |
3332 | ||
3333 | if (mips_opts.noat) | |
3334 | as_warn (_("Macro used $at after \".set noat\"")); | |
3335 | } | |
3336 | } | |
3337 | ||
252b5132 RH |
3338 | /* set_at() |
3339 | * Generates code to set the $at register to true (one) | |
3340 | * if reg is less than the immediate expression. | |
3341 | */ | |
3342 | static void | |
3343 | set_at (counter, reg, unsignedp) | |
3344 | int *counter; | |
3345 | int reg; | |
3346 | int unsignedp; | |
3347 | { | |
3348 | if (imm_expr.X_op == O_constant | |
3349 | && imm_expr.X_add_number >= -0x8000 | |
3350 | && imm_expr.X_add_number < 0x8000) | |
3351 | macro_build ((char *) NULL, counter, &imm_expr, | |
3352 | unsignedp ? "sltiu" : "slti", | |
3353 | "t,r,j", AT, reg, (int) BFD_RELOC_LO16); | |
3354 | else | |
3355 | { | |
4d34fb5f | 3356 | load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 | 3357 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
252b5132 RH |
3358 | unsignedp ? "sltu" : "slt", |
3359 | "d,v,t", AT, reg, AT); | |
3360 | } | |
3361 | } | |
3362 | ||
3363 | /* Warn if an expression is not a constant. */ | |
3364 | ||
3365 | static void | |
3366 | check_absolute_expr (ip, ex) | |
3367 | struct mips_cl_insn *ip; | |
3368 | expressionS *ex; | |
3369 | { | |
3370 | if (ex->X_op == O_big) | |
3371 | as_bad (_("unsupported large constant")); | |
3372 | else if (ex->X_op != O_constant) | |
3373 | as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name); | |
3374 | } | |
3375 | ||
3376 | /* Count the leading zeroes by performing a binary chop. This is a | |
3377 | bulky bit of source, but performance is a LOT better for the | |
3378 | majority of values than a simple loop to count the bits: | |
3379 | for (lcnt = 0; (lcnt < 32); lcnt++) | |
3380 | if ((v) & (1 << (31 - lcnt))) | |
3381 | break; | |
3382 | However it is not code size friendly, and the gain will drop a bit | |
3383 | on certain cached systems. | |
3384 | */ | |
3385 | #define COUNT_TOP_ZEROES(v) \ | |
3386 | (((v) & ~0xffff) == 0 \ | |
3387 | ? ((v) & ~0xff) == 0 \ | |
3388 | ? ((v) & ~0xf) == 0 \ | |
3389 | ? ((v) & ~0x3) == 0 \ | |
3390 | ? ((v) & ~0x1) == 0 \ | |
3391 | ? !(v) \ | |
3392 | ? 32 \ | |
3393 | : 31 \ | |
3394 | : 30 \ | |
3395 | : ((v) & ~0x7) == 0 \ | |
3396 | ? 29 \ | |
3397 | : 28 \ | |
3398 | : ((v) & ~0x3f) == 0 \ | |
3399 | ? ((v) & ~0x1f) == 0 \ | |
3400 | ? 27 \ | |
3401 | : 26 \ | |
3402 | : ((v) & ~0x7f) == 0 \ | |
3403 | ? 25 \ | |
3404 | : 24 \ | |
3405 | : ((v) & ~0xfff) == 0 \ | |
3406 | ? ((v) & ~0x3ff) == 0 \ | |
3407 | ? ((v) & ~0x1ff) == 0 \ | |
3408 | ? 23 \ | |
3409 | : 22 \ | |
3410 | : ((v) & ~0x7ff) == 0 \ | |
3411 | ? 21 \ | |
3412 | : 20 \ | |
3413 | : ((v) & ~0x3fff) == 0 \ | |
3414 | ? ((v) & ~0x1fff) == 0 \ | |
3415 | ? 19 \ | |
3416 | : 18 \ | |
3417 | : ((v) & ~0x7fff) == 0 \ | |
3418 | ? 17 \ | |
3419 | : 16 \ | |
3420 | : ((v) & ~0xffffff) == 0 \ | |
3421 | ? ((v) & ~0xfffff) == 0 \ | |
3422 | ? ((v) & ~0x3ffff) == 0 \ | |
3423 | ? ((v) & ~0x1ffff) == 0 \ | |
3424 | ? 15 \ | |
3425 | : 14 \ | |
3426 | : ((v) & ~0x7ffff) == 0 \ | |
3427 | ? 13 \ | |
3428 | : 12 \ | |
3429 | : ((v) & ~0x3fffff) == 0 \ | |
3430 | ? ((v) & ~0x1fffff) == 0 \ | |
3431 | ? 11 \ | |
3432 | : 10 \ | |
3433 | : ((v) & ~0x7fffff) == 0 \ | |
3434 | ? 9 \ | |
3435 | : 8 \ | |
3436 | : ((v) & ~0xfffffff) == 0 \ | |
3437 | ? ((v) & ~0x3ffffff) == 0 \ | |
3438 | ? ((v) & ~0x1ffffff) == 0 \ | |
3439 | ? 7 \ | |
3440 | : 6 \ | |
3441 | : ((v) & ~0x7ffffff) == 0 \ | |
3442 | ? 5 \ | |
3443 | : 4 \ | |
3444 | : ((v) & ~0x3fffffff) == 0 \ | |
3445 | ? ((v) & ~0x1fffffff) == 0 \ | |
3446 | ? 3 \ | |
3447 | : 2 \ | |
3448 | : ((v) & ~0x7fffffff) == 0 \ | |
3449 | ? 1 \ | |
3450 | : 0) | |
3451 | ||
3452 | /* load_register() | |
3453 | * This routine generates the least number of instructions neccessary to load | |
3454 | * an absolute expression value into a register. | |
3455 | */ | |
3456 | static void | |
3457 | load_register (counter, reg, ep, dbl) | |
3458 | int *counter; | |
3459 | int reg; | |
3460 | expressionS *ep; | |
3461 | int dbl; | |
3462 | { | |
3463 | int freg; | |
3464 | expressionS hi32, lo32; | |
3465 | ||
3466 | if (ep->X_op != O_big) | |
3467 | { | |
3468 | assert (ep->X_op == O_constant); | |
3469 | if (ep->X_add_number < 0x8000 | |
3470 | && (ep->X_add_number >= 0 | |
3471 | || (ep->X_add_number >= -0x8000 | |
3472 | && (! dbl | |
3473 | || ! ep->X_unsigned | |
3474 | || sizeof (ep->X_add_number) > 4)))) | |
3475 | { | |
3476 | /* We can handle 16 bit signed values with an addiu to | |
3477 | $zero. No need to ever use daddiu here, since $zero and | |
3478 | the result are always correct in 32 bit mode. */ | |
3479 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3480 | (int) BFD_RELOC_LO16); | |
3481 | return; | |
3482 | } | |
3483 | else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000) | |
3484 | { | |
3485 | /* We can handle 16 bit unsigned values with an ori to | |
3486 | $zero. */ | |
3487 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0, | |
3488 | (int) BFD_RELOC_LO16); | |
3489 | return; | |
3490 | } | |
6373ee54 | 3491 | else if ((IS_SEXT_32BIT_NUM (ep->X_add_number) |
252b5132 RH |
3492 | && (! dbl |
3493 | || ! ep->X_unsigned | |
3494 | || sizeof (ep->X_add_number) > 4 | |
3495 | || (ep->X_add_number & 0x80000000) == 0)) | |
ca4e0257 | 3496 | || ((HAVE_32BIT_GPRS || ! dbl) |
252b5132 | 3497 | && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0) |
ca4e0257 | 3498 | || (HAVE_32BIT_GPRS |
252b5132 RH |
3499 | && ! dbl |
3500 | && ((ep->X_add_number &~ (offsetT) 0xffffffff) | |
3501 | == ~ (offsetT) 0xffffffff))) | |
3502 | { | |
3503 | /* 32 bit values require an lui. */ | |
3504 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3505 | (int) BFD_RELOC_HI16); | |
3506 | if ((ep->X_add_number & 0xffff) != 0) | |
3507 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg, | |
3508 | (int) BFD_RELOC_LO16); | |
3509 | return; | |
3510 | } | |
3511 | } | |
3512 | ||
3513 | /* The value is larger than 32 bits. */ | |
3514 | ||
ca4e0257 | 3515 | if (HAVE_32BIT_GPRS) |
252b5132 | 3516 | { |
956cd1d6 TS |
3517 | as_bad (_("Number (0x%lx) larger than 32 bits"), |
3518 | (unsigned long) ep->X_add_number); | |
252b5132 RH |
3519 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, |
3520 | (int) BFD_RELOC_LO16); | |
3521 | return; | |
3522 | } | |
3523 | ||
3524 | if (ep->X_op != O_big) | |
3525 | { | |
3526 | hi32 = *ep; | |
3527 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3528 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3529 | hi32.X_add_number &= 0xffffffff; | |
3530 | lo32 = *ep; | |
3531 | lo32.X_add_number &= 0xffffffff; | |
3532 | } | |
3533 | else | |
3534 | { | |
3535 | assert (ep->X_add_number > 2); | |
3536 | if (ep->X_add_number == 3) | |
3537 | generic_bignum[3] = 0; | |
3538 | else if (ep->X_add_number > 4) | |
3539 | as_bad (_("Number larger than 64 bits")); | |
3540 | lo32.X_op = O_constant; | |
3541 | lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16); | |
3542 | hi32.X_op = O_constant; | |
3543 | hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16); | |
3544 | } | |
3545 | ||
3546 | if (hi32.X_add_number == 0) | |
3547 | freg = 0; | |
3548 | else | |
3549 | { | |
3550 | int shift, bit; | |
3551 | unsigned long hi, lo; | |
3552 | ||
956cd1d6 | 3553 | if (hi32.X_add_number == (offsetT) 0xffffffff) |
beae10d5 KH |
3554 | { |
3555 | if ((lo32.X_add_number & 0xffff8000) == 0xffff8000) | |
3556 | { | |
3557 | macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j", | |
252b5132 | 3558 | reg, 0, (int) BFD_RELOC_LO16); |
beae10d5 KH |
3559 | return; |
3560 | } | |
3561 | if (lo32.X_add_number & 0x80000000) | |
3562 | { | |
3563 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, | |
3564 | (int) BFD_RELOC_HI16); | |
252b5132 RH |
3565 | if (lo32.X_add_number & 0xffff) |
3566 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", | |
3567 | reg, reg, (int) BFD_RELOC_LO16); | |
beae10d5 KH |
3568 | return; |
3569 | } | |
3570 | } | |
252b5132 RH |
3571 | |
3572 | /* Check for 16bit shifted constant. We know that hi32 is | |
3573 | non-zero, so start the mask on the first bit of the hi32 | |
3574 | value. */ | |
3575 | shift = 17; | |
3576 | do | |
beae10d5 KH |
3577 | { |
3578 | unsigned long himask, lomask; | |
3579 | ||
3580 | if (shift < 32) | |
3581 | { | |
3582 | himask = 0xffff >> (32 - shift); | |
3583 | lomask = (0xffff << shift) & 0xffffffff; | |
3584 | } | |
3585 | else | |
3586 | { | |
3587 | himask = 0xffff << (shift - 32); | |
3588 | lomask = 0; | |
3589 | } | |
3590 | if ((hi32.X_add_number & ~(offsetT) himask) == 0 | |
3591 | && (lo32.X_add_number & ~(offsetT) lomask) == 0) | |
3592 | { | |
3593 | expressionS tmp; | |
3594 | ||
3595 | tmp.X_op = O_constant; | |
3596 | if (shift < 32) | |
3597 | tmp.X_add_number = ((hi32.X_add_number << (32 - shift)) | |
3598 | | (lo32.X_add_number >> shift)); | |
3599 | else | |
3600 | tmp.X_add_number = hi32.X_add_number >> (shift - 32); | |
3601 | macro_build ((char *) NULL, counter, &tmp, | |
3602 | "ori", "t,r,i", reg, 0, | |
3603 | (int) BFD_RELOC_LO16); | |
2396cfb9 | 3604 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
beae10d5 KH |
3605 | (shift >= 32) ? "dsll32" : "dsll", |
3606 | "d,w,<", reg, reg, | |
3607 | (shift >= 32) ? shift - 32 : shift); | |
3608 | return; | |
3609 | } | |
f9419b05 | 3610 | ++shift; |
beae10d5 KH |
3611 | } |
3612 | while (shift <= (64 - 16)); | |
252b5132 RH |
3613 | |
3614 | /* Find the bit number of the lowest one bit, and store the | |
3615 | shifted value in hi/lo. */ | |
3616 | hi = (unsigned long) (hi32.X_add_number & 0xffffffff); | |
3617 | lo = (unsigned long) (lo32.X_add_number & 0xffffffff); | |
3618 | if (lo != 0) | |
3619 | { | |
3620 | bit = 0; | |
3621 | while ((lo & 1) == 0) | |
3622 | { | |
3623 | lo >>= 1; | |
3624 | ++bit; | |
3625 | } | |
3626 | lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit); | |
3627 | hi >>= bit; | |
3628 | } | |
3629 | else | |
3630 | { | |
3631 | bit = 32; | |
3632 | while ((hi & 1) == 0) | |
3633 | { | |
3634 | hi >>= 1; | |
3635 | ++bit; | |
3636 | } | |
3637 | lo = hi; | |
3638 | hi = 0; | |
3639 | } | |
3640 | ||
3641 | /* Optimize if the shifted value is a (power of 2) - 1. */ | |
3642 | if ((hi == 0 && ((lo + 1) & lo) == 0) | |
3643 | || (lo == 0xffffffff && ((hi + 1) & hi) == 0)) | |
beae10d5 KH |
3644 | { |
3645 | shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number); | |
252b5132 | 3646 | if (shift != 0) |
beae10d5 | 3647 | { |
252b5132 RH |
3648 | expressionS tmp; |
3649 | ||
3650 | /* This instruction will set the register to be all | |
3651 | ones. */ | |
beae10d5 KH |
3652 | tmp.X_op = O_constant; |
3653 | tmp.X_add_number = (offsetT) -1; | |
3654 | macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j", | |
252b5132 | 3655 | reg, 0, (int) BFD_RELOC_LO16); |
beae10d5 KH |
3656 | if (bit != 0) |
3657 | { | |
3658 | bit += shift; | |
2396cfb9 | 3659 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
beae10d5 KH |
3660 | (bit >= 32) ? "dsll32" : "dsll", |
3661 | "d,w,<", reg, reg, | |
3662 | (bit >= 32) ? bit - 32 : bit); | |
3663 | } | |
2396cfb9 | 3664 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
252b5132 | 3665 | (shift >= 32) ? "dsrl32" : "dsrl", |
beae10d5 | 3666 | "d,w,<", reg, reg, |
252b5132 | 3667 | (shift >= 32) ? shift - 32 : shift); |
beae10d5 KH |
3668 | return; |
3669 | } | |
3670 | } | |
252b5132 RH |
3671 | |
3672 | /* Sign extend hi32 before calling load_register, because we can | |
3673 | generally get better code when we load a sign extended value. */ | |
3674 | if ((hi32.X_add_number & 0x80000000) != 0) | |
beae10d5 | 3675 | hi32.X_add_number |= ~(offsetT) 0xffffffff; |
252b5132 RH |
3676 | load_register (counter, reg, &hi32, 0); |
3677 | freg = reg; | |
3678 | } | |
3679 | if ((lo32.X_add_number & 0xffff0000) == 0) | |
3680 | { | |
3681 | if (freg != 0) | |
3682 | { | |
2396cfb9 TS |
3683 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
3684 | "dsll32", "d,w,<", reg, freg, 0); | |
252b5132 RH |
3685 | freg = reg; |
3686 | } | |
3687 | } | |
3688 | else | |
3689 | { | |
3690 | expressionS mid16; | |
3691 | ||
956cd1d6 | 3692 | if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff)) |
beae10d5 | 3693 | { |
252b5132 RH |
3694 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, |
3695 | (int) BFD_RELOC_HI16); | |
956cd1d6 TS |
3696 | macro_build ((char *) NULL, counter, (expressionS *) NULL, |
3697 | "dsrl32", "d,w,<", reg, reg, 0); | |
beae10d5 KH |
3698 | return; |
3699 | } | |
252b5132 RH |
3700 | |
3701 | if (freg != 0) | |
3702 | { | |
956cd1d6 TS |
3703 | macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll", |
3704 | "d,w,<", reg, freg, 16); | |
252b5132 RH |
3705 | freg = reg; |
3706 | } | |
3707 | mid16 = lo32; | |
3708 | mid16.X_add_number >>= 16; | |
3709 | macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg, | |
3710 | freg, (int) BFD_RELOC_LO16); | |
956cd1d6 TS |
3711 | macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll", |
3712 | "d,w,<", reg, reg, 16); | |
252b5132 RH |
3713 | freg = reg; |
3714 | } | |
3715 | if ((lo32.X_add_number & 0xffff) != 0) | |
3716 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg, | |
3717 | (int) BFD_RELOC_LO16); | |
3718 | } | |
3719 | ||
3720 | /* Load an address into a register. */ | |
3721 | ||
3722 | static void | |
c9914766 | 3723 | load_address (counter, reg, ep, used_at) |
252b5132 RH |
3724 | int *counter; |
3725 | int reg; | |
3726 | expressionS *ep; | |
d6bc6245 | 3727 | int *used_at; |
252b5132 | 3728 | { |
f9419b05 | 3729 | char *p = NULL; |
252b5132 RH |
3730 | |
3731 | if (ep->X_op != O_constant | |
3732 | && ep->X_op != O_symbol) | |
3733 | { | |
3734 | as_bad (_("expression too complex")); | |
3735 | ep->X_op = O_constant; | |
3736 | } | |
3737 | ||
3738 | if (ep->X_op == O_constant) | |
3739 | { | |
c9914766 | 3740 | load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES); |
252b5132 RH |
3741 | return; |
3742 | } | |
3743 | ||
3744 | if (mips_pic == NO_PIC) | |
3745 | { | |
3746 | /* If this is a reference to a GP relative symbol, we want | |
cdf6fd85 | 3747 | addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 RH |
3748 | Otherwise we want |
3749 | lui $reg,<sym> (BFD_RELOC_HI16_S) | |
3750 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
d6bc6245 | 3751 | If we have an addend, we always use the latter form. |
76b3015f | 3752 | |
d6bc6245 TS |
3753 | With 64bit address space and a usable $at we want |
3754 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
3755 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
3756 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
3757 | daddiu $at,<sym> (BFD_RELOC_LO16) | |
3758 | dsll32 $reg,0 | |
3a482fd5 | 3759 | daddu $reg,$reg,$at |
76b3015f | 3760 | |
d6bc6245 TS |
3761 | If $at is already in use, we use an path which is suboptimal |
3762 | on superscalar processors. | |
3763 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
3764 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
3765 | dsll $reg,16 | |
3766 | daddiu $reg,<sym> (BFD_RELOC_HI16_S) | |
3767 | dsll $reg,16 | |
3768 | daddiu $reg,<sym> (BFD_RELOC_LO16) | |
3769 | */ | |
c9914766 | 3770 | if (HAVE_64BIT_ADDRESSES) |
d6bc6245 | 3771 | { |
d6bc6245 TS |
3772 | /* We don't do GP optimization for now because RELAX_ENCODE can't |
3773 | hold the data for such large chunks. */ | |
3774 | ||
460597ba | 3775 | if (*used_at == 0 && ! mips_opts.noat) |
d6bc6245 TS |
3776 | { |
3777 | macro_build (p, counter, ep, "lui", "t,u", | |
3778 | reg, (int) BFD_RELOC_MIPS_HIGHEST); | |
3779 | macro_build (p, counter, ep, "lui", "t,u", | |
3780 | AT, (int) BFD_RELOC_HI16_S); | |
3781 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3782 | reg, reg, (int) BFD_RELOC_MIPS_HIGHER); | |
3783 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3784 | AT, AT, (int) BFD_RELOC_LO16); | |
2396cfb9 TS |
3785 | macro_build (p, counter, (expressionS *) NULL, "dsll32", |
3786 | "d,w,<", reg, reg, 0); | |
3a482fd5 | 3787 | macro_build (p, counter, (expressionS *) NULL, "daddu", |
2396cfb9 | 3788 | "d,v,t", reg, reg, AT); |
d6bc6245 TS |
3789 | *used_at = 1; |
3790 | } | |
3791 | else | |
3792 | { | |
3793 | macro_build (p, counter, ep, "lui", "t,u", | |
3794 | reg, (int) BFD_RELOC_MIPS_HIGHEST); | |
3795 | macro_build (p, counter, ep, "daddiu", "t,r,j", | |
3796 | reg, reg, (int) BFD_RELOC_MIPS_HIGHER); | |
2396cfb9 TS |
3797 | macro_build (p, counter, (expressionS *) NULL, "dsll", |
3798 | "d,w,<", reg, reg, 16); | |
d6bc6245 TS |
3799 | macro_build (p, counter, ep, "daddiu", "t,r,j", |
3800 | reg, reg, (int) BFD_RELOC_HI16_S); | |
2396cfb9 TS |
3801 | macro_build (p, counter, (expressionS *) NULL, "dsll", |
3802 | "d,w,<", reg, reg, 16); | |
d6bc6245 TS |
3803 | macro_build (p, counter, ep, "daddiu", "t,r,j", |
3804 | reg, reg, (int) BFD_RELOC_LO16); | |
3805 | } | |
3806 | } | |
252b5132 RH |
3807 | else |
3808 | { | |
d6bc6245 TS |
3809 | if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET |
3810 | && ! nopic_need_relax (ep->X_add_symbol, 1)) | |
3811 | { | |
3812 | frag_grow (20); | |
3813 | macro_build ((char *) NULL, counter, ep, | |
c9914766 TS |
3814 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j", |
3815 | reg, mips_gp_register, (int) BFD_RELOC_GPREL16); | |
d6bc6245 TS |
3816 | p = frag_var (rs_machine_dependent, 8, 0, |
3817 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
3818 | mips_opts.warn_about_macros), | |
956cd1d6 | 3819 | ep->X_add_symbol, 0, NULL); |
d6bc6245 TS |
3820 | } |
3821 | macro_build_lui (p, counter, ep, reg); | |
3822 | if (p != NULL) | |
3823 | p += 4; | |
c9914766 TS |
3824 | macro_build (p, counter, ep, |
3825 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
d6bc6245 TS |
3826 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3827 | } | |
252b5132 RH |
3828 | } |
3829 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
3830 | { | |
3831 | expressionS ex; | |
3832 | ||
3833 | /* If this is a reference to an external symbol, we want | |
3834 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3835 | Otherwise we want | |
3836 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3837 | nop | |
3838 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
ed6fb7bd SC |
3839 | If we have NewABI, we want |
3840 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) | |
252b5132 RH |
3841 | If there is a constant, it must be added in after. */ |
3842 | ex.X_add_number = ep->X_add_number; | |
3843 | ep->X_add_number = 0; | |
3844 | frag_grow (20); | |
ed6fb7bd SC |
3845 | if (HAVE_NEWABI) |
3846 | { | |
3847 | macro_build ((char *) NULL, counter, ep, | |
3848 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg, | |
3849 | (int) BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); | |
3850 | } | |
3851 | else | |
3852 | { | |
3853 | macro_build ((char *) NULL, counter, ep, | |
3854 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", | |
3855 | reg, (int) BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
3856 | macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", ""); | |
3857 | p = frag_var (rs_machine_dependent, 4, 0, | |
3858 | RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros), | |
3859 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3860 | macro_build (p, counter, ep, | |
3861 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
3862 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3863 | } | |
3864 | ||
252b5132 RH |
3865 | if (ex.X_add_number != 0) |
3866 | { | |
3867 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3868 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3869 | ex.X_op = O_constant; | |
3870 | macro_build ((char *) NULL, counter, &ex, | |
ca4e0257 | 3871 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
3872 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3873 | } | |
3874 | } | |
3875 | else if (mips_pic == SVR4_PIC) | |
3876 | { | |
3877 | expressionS ex; | |
3878 | int off; | |
3879 | ||
3880 | /* This is the large GOT case. If this is a reference to an | |
3881 | external symbol, we want | |
3882 | lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
3883 | addu $reg,$reg,$gp | |
3884 | lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16) | |
3885 | Otherwise, for a reference to a local symbol, we want | |
3886 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3887 | nop | |
3888 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
438c16b8 TS |
3889 | If we have NewABI, we want |
3890 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) | |
3891 | addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST) | |
252b5132 RH |
3892 | If there is a constant, it must be added in after. */ |
3893 | ex.X_add_number = ep->X_add_number; | |
3894 | ep->X_add_number = 0; | |
438c16b8 TS |
3895 | if (HAVE_NEWABI) |
3896 | { | |
3897 | macro_build ((char *) NULL, counter, ep, | |
3898 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg, | |
3899 | (int) BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); | |
3900 | macro_build (p, counter, ep, | |
3901 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j", | |
3902 | reg, reg, (int) BFD_RELOC_MIPS_GOT_OFST); | |
3903 | } | |
252b5132 | 3904 | else |
438c16b8 TS |
3905 | { |
3906 | if (reg_needs_delay (mips_gp_register)) | |
3907 | off = 4; | |
3908 | else | |
3909 | off = 0; | |
3910 | frag_grow (32); | |
3911 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3912 | (int) BFD_RELOC_MIPS_GOT_HI16); | |
3913 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
3914 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", "d,v,t", reg, | |
3915 | reg, mips_gp_register); | |
3916 | macro_build ((char *) NULL, counter, ep, | |
3917 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", | |
3918 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg); | |
3919 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
3920 | RELAX_ENCODE (12, 12 + off, off, 8 + off, 0, | |
3921 | mips_opts.warn_about_macros), | |
3922 | ep->X_add_symbol, 0, NULL); | |
3923 | if (off > 0) | |
3924 | { | |
3925 | /* We need a nop before loading from $gp. This special | |
3926 | check is required because the lui which starts the main | |
3927 | instruction stream does not refer to $gp, and so will not | |
3928 | insert the nop which may be required. */ | |
3929 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3930 | p += 4; | |
3931 | } | |
3932 | macro_build (p, counter, ep, | |
3933 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg, | |
3934 | (int) BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
3935 | p += 4; | |
252b5132 RH |
3936 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); |
3937 | p += 4; | |
438c16b8 TS |
3938 | macro_build (p, counter, ep, |
3939 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
3940 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
252b5132 | 3941 | } |
438c16b8 | 3942 | |
252b5132 RH |
3943 | if (ex.X_add_number != 0) |
3944 | { | |
3945 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3946 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3947 | ex.X_op = O_constant; | |
f7ea7ef2 TS |
3948 | macro_build ((char *) NULL, counter, &ex, |
3949 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
252b5132 RH |
3950 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); |
3951 | } | |
3952 | } | |
3953 | else if (mips_pic == EMBEDDED_PIC) | |
3954 | { | |
3955 | /* We always do | |
cdf6fd85 | 3956 | addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16) |
c9914766 TS |
3957 | */ |
3958 | macro_build ((char *) NULL, counter, ep, | |
3959 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
3960 | "t,r,j", reg, mips_gp_register, (int) BFD_RELOC_GPREL16); | |
252b5132 RH |
3961 | } |
3962 | else | |
3963 | abort (); | |
3964 | } | |
3965 | ||
ea1fb5dc RS |
3966 | /* Move the contents of register SOURCE into register DEST. */ |
3967 | ||
3968 | static void | |
3969 | move_register (counter, dest, source) | |
3970 | int *counter; | |
3971 | int dest; | |
3972 | int source; | |
3973 | { | |
3974 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
3975 | HAVE_32BIT_GPRS ? "addu" : "daddu", | |
3976 | "d,v,t", dest, source, 0); | |
3977 | } | |
3978 | ||
252b5132 RH |
3979 | /* |
3980 | * Build macros | |
3981 | * This routine implements the seemingly endless macro or synthesized | |
3982 | * instructions and addressing modes in the mips assembly language. Many | |
3983 | * of these macros are simple and are similar to each other. These could | |
3984 | * probably be handled by some kind of table or grammer aproach instead of | |
3985 | * this verbose method. Others are not simple macros but are more like | |
3986 | * optimizing code generation. | |
3987 | * One interesting optimization is when several store macros appear | |
3988 | * consecutivly that would load AT with the upper half of the same address. | |
3989 | * The ensuing load upper instructions are ommited. This implies some kind | |
3990 | * of global optimization. We currently only optimize within a single macro. | |
3991 | * For many of the load and store macros if the address is specified as a | |
3992 | * constant expression in the first 64k of memory (ie ld $2,0x4000c) we | |
3993 | * first load register 'at' with zero and use it as the base register. The | |
3994 | * mips assembler simply uses register $zero. Just one tiny optimization | |
3995 | * we're missing. | |
3996 | */ | |
3997 | static void | |
3998 | macro (ip) | |
3999 | struct mips_cl_insn *ip; | |
4000 | { | |
4001 | register int treg, sreg, dreg, breg; | |
4002 | int tempreg; | |
4003 | int mask; | |
4004 | int icnt = 0; | |
43841e91 | 4005 | int used_at = 0; |
252b5132 RH |
4006 | expressionS expr1; |
4007 | const char *s; | |
4008 | const char *s2; | |
4009 | const char *fmt; | |
4010 | int likely = 0; | |
4011 | int dbl = 0; | |
4012 | int coproc = 0; | |
4013 | int lr = 0; | |
4014 | int imm = 0; | |
4015 | offsetT maxnum; | |
4016 | int off; | |
4017 | bfd_reloc_code_real_type r; | |
252b5132 RH |
4018 | int hold_mips_optimize; |
4019 | ||
4020 | assert (! mips_opts.mips16); | |
4021 | ||
4022 | treg = (ip->insn_opcode >> 16) & 0x1f; | |
4023 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
4024 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
4025 | mask = ip->insn_mo->mask; | |
4026 | ||
4027 | expr1.X_op = O_constant; | |
4028 | expr1.X_op_symbol = NULL; | |
4029 | expr1.X_add_symbol = NULL; | |
4030 | expr1.X_add_number = 1; | |
4031 | ||
4032 | switch (mask) | |
4033 | { | |
4034 | case M_DABS: | |
4035 | dbl = 1; | |
4036 | case M_ABS: | |
4037 | /* bgez $a0,.+12 | |
4038 | move v0,$a0 | |
4039 | sub v0,$zero,$a0 | |
4040 | */ | |
4041 | ||
4042 | mips_emit_delays (true); | |
4043 | ++mips_opts.noreorder; | |
4044 | mips_any_noreorder = 1; | |
4045 | ||
4046 | expr1.X_add_number = 8; | |
4047 | macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg); | |
4048 | if (dreg == sreg) | |
2396cfb9 TS |
4049 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "", |
4050 | 0); | |
252b5132 | 4051 | else |
ea1fb5dc | 4052 | move_register (&icnt, dreg, sreg); |
2396cfb9 | 4053 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 4054 | dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg); |
252b5132 RH |
4055 | |
4056 | --mips_opts.noreorder; | |
4057 | return; | |
4058 | ||
4059 | case M_ADD_I: | |
4060 | s = "addi"; | |
4061 | s2 = "add"; | |
4062 | goto do_addi; | |
4063 | case M_ADDU_I: | |
4064 | s = "addiu"; | |
4065 | s2 = "addu"; | |
4066 | goto do_addi; | |
4067 | case M_DADD_I: | |
4068 | dbl = 1; | |
4069 | s = "daddi"; | |
4070 | s2 = "dadd"; | |
4071 | goto do_addi; | |
4072 | case M_DADDU_I: | |
4073 | dbl = 1; | |
4074 | s = "daddiu"; | |
4075 | s2 = "daddu"; | |
4076 | do_addi: | |
4077 | if (imm_expr.X_op == O_constant | |
4078 | && imm_expr.X_add_number >= -0x8000 | |
4079 | && imm_expr.X_add_number < 0x8000) | |
4080 | { | |
4081 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg, | |
4082 | (int) BFD_RELOC_LO16); | |
4083 | return; | |
4084 | } | |
4085 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 TS |
4086 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t", |
4087 | treg, sreg, AT); | |
252b5132 RH |
4088 | break; |
4089 | ||
4090 | case M_AND_I: | |
4091 | s = "andi"; | |
4092 | s2 = "and"; | |
4093 | goto do_bit; | |
4094 | case M_OR_I: | |
4095 | s = "ori"; | |
4096 | s2 = "or"; | |
4097 | goto do_bit; | |
4098 | case M_NOR_I: | |
4099 | s = ""; | |
4100 | s2 = "nor"; | |
4101 | goto do_bit; | |
4102 | case M_XOR_I: | |
4103 | s = "xori"; | |
4104 | s2 = "xor"; | |
4105 | do_bit: | |
4106 | if (imm_expr.X_op == O_constant | |
4107 | && imm_expr.X_add_number >= 0 | |
4108 | && imm_expr.X_add_number < 0x10000) | |
4109 | { | |
4110 | if (mask != M_NOR_I) | |
4111 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg, | |
4112 | sreg, (int) BFD_RELOC_LO16); | |
4113 | else | |
4114 | { | |
4115 | macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i", | |
4116 | treg, sreg, (int) BFD_RELOC_LO16); | |
2396cfb9 TS |
4117 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor", |
4118 | "d,v,t", treg, treg, 0); | |
252b5132 RH |
4119 | } |
4120 | return; | |
4121 | } | |
4122 | ||
d6bc6245 | 4123 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
4124 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t", |
4125 | treg, sreg, AT); | |
252b5132 RH |
4126 | break; |
4127 | ||
4128 | case M_BEQ_I: | |
4129 | s = "beq"; | |
4130 | goto beq_i; | |
4131 | case M_BEQL_I: | |
4132 | s = "beql"; | |
4133 | likely = 1; | |
4134 | goto beq_i; | |
4135 | case M_BNE_I: | |
4136 | s = "bne"; | |
4137 | goto beq_i; | |
4138 | case M_BNEL_I: | |
4139 | s = "bnel"; | |
4140 | likely = 1; | |
4141 | beq_i: | |
4142 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4143 | { | |
4144 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, | |
4145 | 0); | |
4146 | return; | |
4147 | } | |
4d34fb5f | 4148 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
252b5132 RH |
4149 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT); |
4150 | break; | |
4151 | ||
4152 | case M_BGEL: | |
4153 | likely = 1; | |
4154 | case M_BGE: | |
4155 | if (treg == 0) | |
4156 | { | |
4157 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
2396cfb9 | 4158 | likely ? "bgezl" : "bgez", "s,p", sreg); |
252b5132 RH |
4159 | return; |
4160 | } | |
4161 | if (sreg == 0) | |
4162 | { | |
4163 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
2396cfb9 | 4164 | likely ? "blezl" : "blez", "s,p", treg); |
252b5132 RH |
4165 | return; |
4166 | } | |
2396cfb9 TS |
4167 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
4168 | AT, sreg, treg); | |
252b5132 | 4169 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4170 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4171 | break; |
4172 | ||
4173 | case M_BGTL_I: | |
4174 | likely = 1; | |
4175 | case M_BGT_I: | |
4176 | /* check for > max integer */ | |
4177 | maxnum = 0x7fffffff; | |
ca4e0257 | 4178 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
4179 | { |
4180 | maxnum <<= 16; | |
4181 | maxnum |= 0xffff; | |
4182 | maxnum <<= 16; | |
4183 | maxnum |= 0xffff; | |
4184 | } | |
4185 | if (imm_expr.X_op == O_constant | |
4186 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 4187 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
4188 | { |
4189 | do_false: | |
4190 | /* result is always false */ | |
4191 | if (! likely) | |
4192 | { | |
39c0a331 L |
4193 | if (warn_nops) |
4194 | as_warn (_("Branch %s is always false (nop)"), | |
4195 | ip->insn_mo->name); | |
2396cfb9 TS |
4196 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", |
4197 | "", 0); | |
252b5132 RH |
4198 | } |
4199 | else | |
4200 | { | |
39c0a331 L |
4201 | if (warn_nops) |
4202 | as_warn (_("Branch likely %s is always false"), | |
4203 | ip->insn_mo->name); | |
252b5132 RH |
4204 | macro_build ((char *) NULL, &icnt, &offset_expr, "bnel", |
4205 | "s,t,p", 0, 0); | |
4206 | } | |
4207 | return; | |
4208 | } | |
4209 | if (imm_expr.X_op != O_constant) | |
4210 | as_bad (_("Unsupported large constant")); | |
f9419b05 | 4211 | ++imm_expr.X_add_number; |
252b5132 RH |
4212 | /* FALLTHROUGH */ |
4213 | case M_BGE_I: | |
4214 | case M_BGEL_I: | |
4215 | if (mask == M_BGEL_I) | |
4216 | likely = 1; | |
4217 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4218 | { | |
4219 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4220 | likely ? "bgezl" : "bgez", "s,p", sreg); |
252b5132 RH |
4221 | return; |
4222 | } | |
4223 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4224 | { | |
4225 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4226 | likely ? "bgtzl" : "bgtz", "s,p", sreg); |
252b5132 RH |
4227 | return; |
4228 | } | |
4229 | maxnum = 0x7fffffff; | |
ca4e0257 | 4230 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
4231 | { |
4232 | maxnum <<= 16; | |
4233 | maxnum |= 0xffff; | |
4234 | maxnum <<= 16; | |
4235 | maxnum |= 0xffff; | |
4236 | } | |
4237 | maxnum = - maxnum - 1; | |
4238 | if (imm_expr.X_op == O_constant | |
4239 | && imm_expr.X_add_number <= maxnum | |
ca4e0257 | 4240 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
4241 | { |
4242 | do_true: | |
4243 | /* result is always true */ | |
4244 | as_warn (_("Branch %s is always true"), ip->insn_mo->name); | |
4245 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
4246 | return; | |
4247 | } | |
4248 | set_at (&icnt, sreg, 0); | |
4249 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4250 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4251 | break; |
4252 | ||
4253 | case M_BGEUL: | |
4254 | likely = 1; | |
4255 | case M_BGEU: | |
4256 | if (treg == 0) | |
4257 | goto do_true; | |
4258 | if (sreg == 0) | |
4259 | { | |
4260 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4261 | likely ? "beql" : "beq", "s,t,p", 0, treg); |
252b5132 RH |
4262 | return; |
4263 | } | |
2396cfb9 TS |
4264 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
4265 | "d,v,t", AT, sreg, treg); | |
252b5132 | 4266 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4267 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4268 | break; |
4269 | ||
4270 | case M_BGTUL_I: | |
4271 | likely = 1; | |
4272 | case M_BGTU_I: | |
4273 | if (sreg == 0 | |
ca4e0257 | 4274 | || (HAVE_32BIT_GPRS |
252b5132 | 4275 | && imm_expr.X_op == O_constant |
956cd1d6 | 4276 | && imm_expr.X_add_number == (offsetT) 0xffffffff)) |
252b5132 RH |
4277 | goto do_false; |
4278 | if (imm_expr.X_op != O_constant) | |
4279 | as_bad (_("Unsupported large constant")); | |
f9419b05 | 4280 | ++imm_expr.X_add_number; |
252b5132 RH |
4281 | /* FALLTHROUGH */ |
4282 | case M_BGEU_I: | |
4283 | case M_BGEUL_I: | |
4284 | if (mask == M_BGEUL_I) | |
4285 | likely = 1; | |
4286 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4287 | goto do_true; | |
4288 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4289 | { | |
4290 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4291 | likely ? "bnel" : "bne", "s,t,p", sreg, 0); |
252b5132 RH |
4292 | return; |
4293 | } | |
4294 | set_at (&icnt, sreg, 1); | |
4295 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4296 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4297 | break; |
4298 | ||
4299 | case M_BGTL: | |
4300 | likely = 1; | |
4301 | case M_BGT: | |
4302 | if (treg == 0) | |
4303 | { | |
4304 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4305 | likely ? "bgtzl" : "bgtz", "s,p", sreg); |
252b5132 RH |
4306 | return; |
4307 | } | |
4308 | if (sreg == 0) | |
4309 | { | |
4310 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4311 | likely ? "bltzl" : "bltz", "s,p", treg); |
252b5132 RH |
4312 | return; |
4313 | } | |
2396cfb9 TS |
4314 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
4315 | AT, treg, sreg); | |
252b5132 | 4316 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4317 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4318 | break; |
4319 | ||
4320 | case M_BGTUL: | |
4321 | likely = 1; | |
4322 | case M_BGTU: | |
4323 | if (treg == 0) | |
4324 | { | |
4325 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4326 | likely ? "bnel" : "bne", "s,t,p", sreg, 0); |
252b5132 RH |
4327 | return; |
4328 | } | |
4329 | if (sreg == 0) | |
4330 | goto do_false; | |
2396cfb9 TS |
4331 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
4332 | "d,v,t", AT, treg, sreg); | |
252b5132 | 4333 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4334 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4335 | break; |
4336 | ||
4337 | case M_BLEL: | |
4338 | likely = 1; | |
4339 | case M_BLE: | |
4340 | if (treg == 0) | |
4341 | { | |
4342 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4343 | likely ? "blezl" : "blez", "s,p", sreg); |
252b5132 RH |
4344 | return; |
4345 | } | |
4346 | if (sreg == 0) | |
4347 | { | |
4348 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4349 | likely ? "bgezl" : "bgez", "s,p", treg); |
252b5132 RH |
4350 | return; |
4351 | } | |
2396cfb9 TS |
4352 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
4353 | AT, treg, sreg); | |
252b5132 | 4354 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4355 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4356 | break; |
4357 | ||
4358 | case M_BLEL_I: | |
4359 | likely = 1; | |
4360 | case M_BLE_I: | |
4361 | maxnum = 0x7fffffff; | |
ca4e0257 | 4362 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
252b5132 RH |
4363 | { |
4364 | maxnum <<= 16; | |
4365 | maxnum |= 0xffff; | |
4366 | maxnum <<= 16; | |
4367 | maxnum |= 0xffff; | |
4368 | } | |
4369 | if (imm_expr.X_op == O_constant | |
4370 | && imm_expr.X_add_number >= maxnum | |
ca4e0257 | 4371 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
252b5132 RH |
4372 | goto do_true; |
4373 | if (imm_expr.X_op != O_constant) | |
4374 | as_bad (_("Unsupported large constant")); | |
f9419b05 | 4375 | ++imm_expr.X_add_number; |
252b5132 RH |
4376 | /* FALLTHROUGH */ |
4377 | case M_BLT_I: | |
4378 | case M_BLTL_I: | |
4379 | if (mask == M_BLTL_I) | |
4380 | likely = 1; | |
4381 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4382 | { | |
4383 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4384 | likely ? "bltzl" : "bltz", "s,p", sreg); |
252b5132 RH |
4385 | return; |
4386 | } | |
4387 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4388 | { | |
4389 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4390 | likely ? "blezl" : "blez", "s,p", sreg); |
252b5132 RH |
4391 | return; |
4392 | } | |
4393 | set_at (&icnt, sreg, 0); | |
4394 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4395 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4396 | break; |
4397 | ||
4398 | case M_BLEUL: | |
4399 | likely = 1; | |
4400 | case M_BLEU: | |
4401 | if (treg == 0) | |
4402 | { | |
4403 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4404 | likely ? "beql" : "beq", "s,t,p", sreg, 0); |
252b5132 RH |
4405 | return; |
4406 | } | |
4407 | if (sreg == 0) | |
4408 | goto do_true; | |
2396cfb9 TS |
4409 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
4410 | "d,v,t", AT, treg, sreg); | |
252b5132 | 4411 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4412 | likely ? "beql" : "beq", "s,t,p", AT, 0); |
252b5132 RH |
4413 | break; |
4414 | ||
4415 | case M_BLEUL_I: | |
4416 | likely = 1; | |
4417 | case M_BLEU_I: | |
4418 | if (sreg == 0 | |
ca4e0257 | 4419 | || (HAVE_32BIT_GPRS |
252b5132 | 4420 | && imm_expr.X_op == O_constant |
956cd1d6 | 4421 | && imm_expr.X_add_number == (offsetT) 0xffffffff)) |
252b5132 RH |
4422 | goto do_true; |
4423 | if (imm_expr.X_op != O_constant) | |
4424 | as_bad (_("Unsupported large constant")); | |
f9419b05 | 4425 | ++imm_expr.X_add_number; |
252b5132 RH |
4426 | /* FALLTHROUGH */ |
4427 | case M_BLTU_I: | |
4428 | case M_BLTUL_I: | |
4429 | if (mask == M_BLTUL_I) | |
4430 | likely = 1; | |
4431 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4432 | goto do_false; | |
4433 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4434 | { | |
4435 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4436 | likely ? "beql" : "beq", | |
4437 | "s,t,p", sreg, 0); | |
4438 | return; | |
4439 | } | |
4440 | set_at (&icnt, sreg, 1); | |
4441 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4442 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4443 | break; |
4444 | ||
4445 | case M_BLTL: | |
4446 | likely = 1; | |
4447 | case M_BLT: | |
4448 | if (treg == 0) | |
4449 | { | |
4450 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4451 | likely ? "bltzl" : "bltz", "s,p", sreg); |
252b5132 RH |
4452 | return; |
4453 | } | |
4454 | if (sreg == 0) | |
4455 | { | |
4456 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4457 | likely ? "bgtzl" : "bgtz", "s,p", treg); |
252b5132 RH |
4458 | return; |
4459 | } | |
2396cfb9 TS |
4460 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
4461 | AT, sreg, treg); | |
252b5132 | 4462 | macro_build ((char *) NULL, &icnt, &offset_expr, |
9a41af64 | 4463 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4464 | break; |
4465 | ||
4466 | case M_BLTUL: | |
4467 | likely = 1; | |
4468 | case M_BLTU: | |
4469 | if (treg == 0) | |
4470 | goto do_false; | |
4471 | if (sreg == 0) | |
4472 | { | |
4473 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4474 | likely ? "bnel" : "bne", "s,t,p", 0, treg); |
252b5132 RH |
4475 | return; |
4476 | } | |
2396cfb9 TS |
4477 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
4478 | "d,v,t", AT, sreg, | |
252b5132 RH |
4479 | treg); |
4480 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
9a41af64 | 4481 | likely ? "bnel" : "bne", "s,t,p", AT, 0); |
252b5132 RH |
4482 | break; |
4483 | ||
4484 | case M_DDIV_3: | |
4485 | dbl = 1; | |
4486 | case M_DIV_3: | |
4487 | s = "mflo"; | |
4488 | goto do_div3; | |
4489 | case M_DREM_3: | |
4490 | dbl = 1; | |
4491 | case M_REM_3: | |
4492 | s = "mfhi"; | |
4493 | do_div3: | |
4494 | if (treg == 0) | |
4495 | { | |
4496 | as_warn (_("Divide by zero.")); | |
4497 | if (mips_trap) | |
2396cfb9 | 4498 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
9bd7d936 | 4499 | "s,t,q", 0, 0, 7); |
252b5132 | 4500 | else |
2396cfb9 TS |
4501 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4502 | "c", 7); | |
252b5132 RH |
4503 | return; |
4504 | } | |
4505 | ||
4506 | mips_emit_delays (true); | |
4507 | ++mips_opts.noreorder; | |
4508 | mips_any_noreorder = 1; | |
4509 | if (mips_trap) | |
4510 | { | |
2396cfb9 | 4511 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
9bd7d936 | 4512 | "s,t,q", treg, 0, 7); |
2396cfb9 | 4513 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 4514 | dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
252b5132 RH |
4515 | } |
4516 | else | |
4517 | { | |
4518 | expr1.X_add_number = 8; | |
4519 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
2396cfb9 | 4520 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 4521 | dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
2396cfb9 TS |
4522 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4523 | "c", 7); | |
252b5132 RH |
4524 | } |
4525 | expr1.X_add_number = -1; | |
4526 | macro_build ((char *) NULL, &icnt, &expr1, | |
4527 | dbl ? "daddiu" : "addiu", | |
4528 | "t,r,j", AT, 0, (int) BFD_RELOC_LO16); | |
4529 | expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16); | |
4530 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT); | |
4531 | if (dbl) | |
4532 | { | |
4533 | expr1.X_add_number = 1; | |
4534 | macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0, | |
4535 | (int) BFD_RELOC_LO16); | |
2396cfb9 TS |
4536 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32", |
4537 | "d,w,<", AT, AT, 31); | |
252b5132 RH |
4538 | } |
4539 | else | |
4540 | { | |
4541 | expr1.X_add_number = 0x80000000; | |
4542 | macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT, | |
4543 | (int) BFD_RELOC_HI16); | |
4544 | } | |
4545 | if (mips_trap) | |
4546 | { | |
2396cfb9 | 4547 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
9bd7d936 | 4548 | "s,t,q", sreg, AT, 6); |
252b5132 RH |
4549 | /* We want to close the noreorder block as soon as possible, so |
4550 | that later insns are available for delay slot filling. */ | |
4551 | --mips_opts.noreorder; | |
4552 | } | |
4553 | else | |
4554 | { | |
4555 | expr1.X_add_number = 8; | |
4556 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT); | |
2396cfb9 TS |
4557 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "", |
4558 | 0); | |
252b5132 RH |
4559 | |
4560 | /* We want to close the noreorder block as soon as possible, so | |
4561 | that later insns are available for delay slot filling. */ | |
4562 | --mips_opts.noreorder; | |
4563 | ||
2396cfb9 TS |
4564 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4565 | "c", 6); | |
252b5132 | 4566 | } |
2396cfb9 | 4567 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg); |
252b5132 RH |
4568 | break; |
4569 | ||
4570 | case M_DIV_3I: | |
4571 | s = "div"; | |
4572 | s2 = "mflo"; | |
4573 | goto do_divi; | |
4574 | case M_DIVU_3I: | |
4575 | s = "divu"; | |
4576 | s2 = "mflo"; | |
4577 | goto do_divi; | |
4578 | case M_REM_3I: | |
4579 | s = "div"; | |
4580 | s2 = "mfhi"; | |
4581 | goto do_divi; | |
4582 | case M_REMU_3I: | |
4583 | s = "divu"; | |
4584 | s2 = "mfhi"; | |
4585 | goto do_divi; | |
4586 | case M_DDIV_3I: | |
4587 | dbl = 1; | |
4588 | s = "ddiv"; | |
4589 | s2 = "mflo"; | |
4590 | goto do_divi; | |
4591 | case M_DDIVU_3I: | |
4592 | dbl = 1; | |
4593 | s = "ddivu"; | |
4594 | s2 = "mflo"; | |
4595 | goto do_divi; | |
4596 | case M_DREM_3I: | |
4597 | dbl = 1; | |
4598 | s = "ddiv"; | |
4599 | s2 = "mfhi"; | |
4600 | goto do_divi; | |
4601 | case M_DREMU_3I: | |
4602 | dbl = 1; | |
4603 | s = "ddivu"; | |
4604 | s2 = "mfhi"; | |
4605 | do_divi: | |
4606 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4607 | { | |
4608 | as_warn (_("Divide by zero.")); | |
4609 | if (mips_trap) | |
2396cfb9 | 4610 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
9bd7d936 | 4611 | "s,t,q", 0, 0, 7); |
252b5132 | 4612 | else |
2396cfb9 TS |
4613 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4614 | "c", 7); | |
252b5132 RH |
4615 | return; |
4616 | } | |
4617 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4618 | { | |
4619 | if (strcmp (s2, "mflo") == 0) | |
ea1fb5dc | 4620 | move_register (&icnt, dreg, sreg); |
252b5132 | 4621 | else |
ea1fb5dc | 4622 | move_register (&icnt, dreg, 0); |
252b5132 RH |
4623 | return; |
4624 | } | |
4625 | if (imm_expr.X_op == O_constant | |
4626 | && imm_expr.X_add_number == -1 | |
4627 | && s[strlen (s) - 1] != 'u') | |
4628 | { | |
4629 | if (strcmp (s2, "mflo") == 0) | |
4630 | { | |
2396cfb9 TS |
4631 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
4632 | dbl ? "dneg" : "neg", "d,w", dreg, sreg); | |
252b5132 RH |
4633 | } |
4634 | else | |
ea1fb5dc | 4635 | move_register (&icnt, dreg, 0); |
252b5132 RH |
4636 | return; |
4637 | } | |
4638 | ||
4639 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 TS |
4640 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t", |
4641 | sreg, AT); | |
4642 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg); | |
252b5132 RH |
4643 | break; |
4644 | ||
4645 | case M_DIVU_3: | |
4646 | s = "divu"; | |
4647 | s2 = "mflo"; | |
4648 | goto do_divu3; | |
4649 | case M_REMU_3: | |
4650 | s = "divu"; | |
4651 | s2 = "mfhi"; | |
4652 | goto do_divu3; | |
4653 | case M_DDIVU_3: | |
4654 | s = "ddivu"; | |
4655 | s2 = "mflo"; | |
4656 | goto do_divu3; | |
4657 | case M_DREMU_3: | |
4658 | s = "ddivu"; | |
4659 | s2 = "mfhi"; | |
4660 | do_divu3: | |
4661 | mips_emit_delays (true); | |
4662 | ++mips_opts.noreorder; | |
4663 | mips_any_noreorder = 1; | |
4664 | if (mips_trap) | |
4665 | { | |
2396cfb9 | 4666 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq", |
9bd7d936 | 4667 | "s,t,q", treg, 0, 7); |
2396cfb9 TS |
4668 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t", |
4669 | sreg, treg); | |
252b5132 RH |
4670 | /* We want to close the noreorder block as soon as possible, so |
4671 | that later insns are available for delay slot filling. */ | |
4672 | --mips_opts.noreorder; | |
4673 | } | |
4674 | else | |
4675 | { | |
4676 | expr1.X_add_number = 8; | |
4677 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
2396cfb9 TS |
4678 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t", |
4679 | sreg, treg); | |
252b5132 RH |
4680 | |
4681 | /* We want to close the noreorder block as soon as possible, so | |
4682 | that later insns are available for delay slot filling. */ | |
4683 | --mips_opts.noreorder; | |
2396cfb9 TS |
4684 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
4685 | "c", 7); | |
252b5132 | 4686 | } |
2396cfb9 | 4687 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg); |
252b5132 RH |
4688 | return; |
4689 | ||
4690 | case M_DLA_AB: | |
4691 | dbl = 1; | |
4692 | case M_LA_AB: | |
4693 | /* Load the address of a symbol into a register. If breg is not | |
4694 | zero, we then add a base register to it. */ | |
4695 | ||
3bec30a8 TS |
4696 | if (dbl && HAVE_32BIT_GPRS) |
4697 | as_warn (_("dla used to load 32-bit register")); | |
4698 | ||
c90bbe5b | 4699 | if (! dbl && HAVE_64BIT_OBJECTS) |
3bec30a8 TS |
4700 | as_warn (_("la used to load 64-bit address")); |
4701 | ||
0c11417f MR |
4702 | if (offset_expr.X_op == O_constant |
4703 | && offset_expr.X_add_number >= -0x8000 | |
4704 | && offset_expr.X_add_number < 0x8000) | |
4705 | { | |
4706 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4707 | (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu", | |
4708 | "t,r,j", treg, sreg, (int) BFD_RELOC_LO16); | |
4709 | return; | |
4710 | } | |
4711 | ||
afdbd6d0 CD |
4712 | if (treg == breg) |
4713 | { | |
4714 | tempreg = AT; | |
4715 | used_at = 1; | |
4716 | } | |
4717 | else | |
4718 | { | |
4719 | tempreg = treg; | |
4720 | used_at = 0; | |
4721 | } | |
4722 | ||
252b5132 RH |
4723 | /* When generating embedded PIC code, we permit expressions of |
4724 | the form | |
afdbd6d0 CD |
4725 | la $treg,foo-bar |
4726 | la $treg,foo-bar($breg) | |
bb2d6cd7 | 4727 | where bar is an address in the current section. These are used |
252b5132 RH |
4728 | when getting the addresses of functions. We don't permit |
4729 | X_add_number to be non-zero, because if the symbol is | |
4730 | external the relaxing code needs to know that any addend is | |
4731 | purely the offset to X_op_symbol. */ | |
4732 | if (mips_pic == EMBEDDED_PIC | |
4733 | && offset_expr.X_op == O_subtract | |
49309057 | 4734 | && (symbol_constant_p (offset_expr.X_op_symbol) |
bb2d6cd7 | 4735 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg |
49309057 ILT |
4736 | : (symbol_equated_p (offset_expr.X_op_symbol) |
4737 | && (S_GET_SEGMENT | |
4738 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
4739 | ->X_add_symbol) | |
bb2d6cd7 | 4740 | == now_seg))) |
bb2d6cd7 GK |
4741 | && (offset_expr.X_add_number == 0 |
4742 | || OUTPUT_FLAVOR == bfd_target_elf_flavour)) | |
252b5132 | 4743 | { |
afdbd6d0 CD |
4744 | if (breg == 0) |
4745 | { | |
4746 | tempreg = treg; | |
4747 | used_at = 0; | |
4748 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4749 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
4750 | } | |
4751 | else | |
4752 | { | |
4753 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4754 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
4755 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4d34fb5f | 4756 | (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu", |
afdbd6d0 CD |
4757 | "d,v,t", tempreg, tempreg, breg); |
4758 | } | |
252b5132 | 4759 | macro_build ((char *) NULL, &icnt, &offset_expr, |
4d34fb5f | 4760 | (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu", |
afdbd6d0 CD |
4761 | "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16); |
4762 | if (! used_at) | |
4763 | return; | |
4764 | break; | |
252b5132 RH |
4765 | } |
4766 | ||
4767 | if (offset_expr.X_op != O_symbol | |
4768 | && offset_expr.X_op != O_constant) | |
4769 | { | |
4770 | as_bad (_("expression too complex")); | |
4771 | offset_expr.X_op = O_constant; | |
4772 | } | |
4773 | ||
252b5132 | 4774 | if (offset_expr.X_op == O_constant) |
4d34fb5f TS |
4775 | load_register (&icnt, tempreg, &offset_expr, |
4776 | ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC) | |
4777 | ? (dbl || HAVE_64BIT_ADDRESSES) | |
4778 | : HAVE_64BIT_ADDRESSES)); | |
252b5132 RH |
4779 | else if (mips_pic == NO_PIC) |
4780 | { | |
d6bc6245 | 4781 | /* If this is a reference to a GP relative symbol, we want |
cdf6fd85 | 4782 | addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 RH |
4783 | Otherwise we want |
4784 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4785 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4786 | If we have a constant, we need two instructions anyhow, | |
d6bc6245 | 4787 | so we may as well always use the latter form. |
76b3015f | 4788 | |
d6bc6245 TS |
4789 | With 64bit address space and a usable $at we want |
4790 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
4791 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
4792 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
4793 | daddiu $at,<sym> (BFD_RELOC_LO16) | |
4794 | dsll32 $tempreg,0 | |
3a482fd5 | 4795 | daddu $tempreg,$tempreg,$at |
76b3015f | 4796 | |
d6bc6245 TS |
4797 | If $at is already in use, we use an path which is suboptimal |
4798 | on superscalar processors. | |
4799 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
4800 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
4801 | dsll $tempreg,16 | |
4802 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4803 | dsll $tempreg,16 | |
4804 | daddiu $tempreg,<sym> (BFD_RELOC_LO16) | |
4805 | */ | |
f9419b05 | 4806 | char *p = NULL; |
d6bc6245 | 4807 | if (HAVE_64BIT_ADDRESSES) |
252b5132 | 4808 | { |
d6bc6245 TS |
4809 | /* We don't do GP optimization for now because RELAX_ENCODE can't |
4810 | hold the data for such large chunks. */ | |
4811 | ||
460597ba | 4812 | if (used_at == 0 && ! mips_opts.noat) |
98d3f06f KH |
4813 | { |
4814 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4815 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
4816 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4817 | AT, (int) BFD_RELOC_HI16_S); | |
4818 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4819 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
4820 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4821 | AT, AT, (int) BFD_RELOC_LO16); | |
4822 | macro_build (p, &icnt, (expressionS *) NULL, "dsll32", | |
4823 | "d,w,<", tempreg, tempreg, 0); | |
3a482fd5 MR |
4824 | macro_build (p, &icnt, (expressionS *) NULL, "daddu", |
4825 | "d,v,t", tempreg, tempreg, AT); | |
98d3f06f KH |
4826 | used_at = 1; |
4827 | } | |
4828 | else | |
4829 | { | |
4830 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
4831 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
4832 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4833 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
4834 | macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<", | |
4835 | tempreg, tempreg, 16); | |
4836 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4837 | tempreg, tempreg, (int) BFD_RELOC_HI16_S); | |
4838 | macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<", | |
4839 | tempreg, tempreg, 16); | |
4840 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
4841 | tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4842 | } | |
4843 | } | |
4844 | else | |
4845 | { | |
4846 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET | |
4847 | && ! nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
4848 | { | |
4849 | frag_grow (20); | |
4850 | macro_build ((char *) NULL, &icnt, &offset_expr, "addiu", | |
c9914766 TS |
4851 | "t,r,j", tempreg, mips_gp_register, |
4852 | (int) BFD_RELOC_GPREL16); | |
98d3f06f KH |
4853 | p = frag_var (rs_machine_dependent, 8, 0, |
4854 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
4855 | mips_opts.warn_about_macros), | |
4856 | offset_expr.X_add_symbol, 0, NULL); | |
4857 | } | |
4858 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
4859 | if (p != NULL) | |
4860 | p += 4; | |
4861 | macro_build (p, &icnt, &offset_expr, "addiu", | |
4862 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4863 | } | |
252b5132 RH |
4864 | } |
4865 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
4866 | { | |
9117d219 NC |
4867 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
4868 | ||
252b5132 RH |
4869 | /* If this is a reference to an external symbol, and there |
4870 | is no constant, we want | |
4871 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
9117d219 NC |
4872 | or if tempreg is PIC_CALL_REG |
4873 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
252b5132 RH |
4874 | For a local symbol, we want |
4875 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4876 | nop | |
4877 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4878 | ||
4879 | If we have a small constant, and this is a reference to | |
4880 | an external symbol, we want | |
4881 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4882 | nop | |
4883 | addiu $tempreg,$tempreg,<constant> | |
4884 | For a local symbol, we want the same instruction | |
4885 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4886 | addiu instruction. | |
4887 | ||
4888 | If we have a large constant, and this is a reference to | |
4889 | an external symbol, we want | |
4890 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4891 | lui $at,<hiconstant> | |
4892 | addiu $at,$at,<loconstant> | |
4893 | addu $tempreg,$tempreg,$at | |
4894 | For a local symbol, we want the same instruction | |
4895 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
ed6fb7bd SC |
4896 | addiu instruction. |
4897 | ||
4898 | For NewABI, we want for local or external data addresses | |
4899 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) | |
4900 | For a local function symbol, we want | |
4901 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) | |
4902 | nop | |
4903 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_MIPS_GOT_OFST) | |
4904 | */ | |
4905 | ||
252b5132 RH |
4906 | expr1.X_add_number = offset_expr.X_add_number; |
4907 | offset_expr.X_add_number = 0; | |
4908 | frag_grow (32); | |
9117d219 NC |
4909 | if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG) |
4910 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16; | |
ed6fb7bd SC |
4911 | else if (HAVE_NEWABI) |
4912 | lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_DISP; | |
4d34fb5f TS |
4913 | macro_build ((char *) NULL, &icnt, &offset_expr, |
4914 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", | |
c9914766 | 4915 | "t,o(b)", tempreg, lw_reloc_type, mips_gp_register); |
252b5132 RH |
4916 | if (expr1.X_add_number == 0) |
4917 | { | |
4918 | int off; | |
f9419b05 | 4919 | char *p; |
252b5132 RH |
4920 | |
4921 | if (breg == 0) | |
4922 | off = 0; | |
4923 | else | |
4924 | { | |
4925 | /* We're going to put in an addu instruction using | |
4926 | tempreg, so we may as well insert the nop right | |
4927 | now. */ | |
4928 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4929 | "nop", ""); | |
4930 | off = 4; | |
4931 | } | |
4932 | p = frag_var (rs_machine_dependent, 8 - off, 0, | |
4933 | RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0, | |
4934 | (breg == 0 | |
4935 | ? mips_opts.warn_about_macros | |
4936 | : 0)), | |
c4e7957c | 4937 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
4938 | if (breg == 0) |
4939 | { | |
4940 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4941 | p += 4; | |
4942 | } | |
4943 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 4944 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4945 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
4946 | /* FIXME: If breg == 0, and the next instruction uses | |
4947 | $tempreg, then if this variant case is used an extra | |
4948 | nop will be generated. */ | |
4949 | } | |
4950 | else if (expr1.X_add_number >= -0x8000 | |
4951 | && expr1.X_add_number < 0x8000) | |
4952 | { | |
4953 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4954 | "nop", ""); | |
4955 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4956 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 | 4957 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
c4e7957c TS |
4958 | frag_var (rs_machine_dependent, 0, 0, |
4959 | RELAX_ENCODE (0, 0, -12, -4, 0, 0), | |
4960 | offset_expr.X_add_symbol, 0, NULL); | |
252b5132 RH |
4961 | } |
4962 | else | |
4963 | { | |
4964 | int off1; | |
4965 | ||
4966 | /* If we are going to add in a base register, and the | |
4967 | target register and the base register are the same, | |
4968 | then we are using AT as a temporary register. Since | |
4969 | we want to load the constant into AT, we add our | |
4970 | current AT (from the global offset table) and the | |
4971 | register into the register now, and pretend we were | |
4972 | not using a base register. */ | |
4973 | if (breg != treg) | |
4974 | off1 = 0; | |
4975 | else | |
4976 | { | |
4977 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4978 | "nop", ""); | |
4979 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4980 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
4981 | "d,v,t", treg, AT, breg); |
4982 | breg = 0; | |
4983 | tempreg = treg; | |
4984 | off1 = -8; | |
4985 | } | |
4986 | ||
4987 | /* Set mips_optimize around the lui instruction to avoid | |
4988 | inserting an unnecessary nop after the lw. */ | |
4989 | hold_mips_optimize = mips_optimize; | |
4990 | mips_optimize = 2; | |
c4e7957c | 4991 | macro_build_lui (NULL, &icnt, &expr1, AT); |
252b5132 RH |
4992 | mips_optimize = hold_mips_optimize; |
4993 | ||
4994 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 4995 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
4996 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
4997 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 4998 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 4999 | "d,v,t", tempreg, tempreg, AT); |
c4e7957c TS |
5000 | frag_var (rs_machine_dependent, 0, 0, |
5001 | RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0), | |
5002 | offset_expr.X_add_symbol, 0, NULL); | |
252b5132 RH |
5003 | used_at = 1; |
5004 | } | |
5005 | } | |
5006 | else if (mips_pic == SVR4_PIC) | |
5007 | { | |
5008 | int gpdel; | |
f9419b05 | 5009 | char *p; |
9117d219 NC |
5010 | int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16; |
5011 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16; | |
ed6fb7bd | 5012 | int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
252b5132 RH |
5013 | |
5014 | /* This is the large GOT case. If this is a reference to an | |
5015 | external symbol, and there is no constant, we want | |
5016 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5017 | addu $tempreg,$tempreg,$gp | |
5018 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
9117d219 NC |
5019 | or if tempreg is PIC_CALL_REG |
5020 | lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
5021 | addu $tempreg,$tempreg,$gp | |
5022 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16) | |
252b5132 RH |
5023 | For a local symbol, we want |
5024 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5025 | nop | |
5026 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5027 | ||
5028 | If we have a small constant, and this is a reference to | |
5029 | an external symbol, we want | |
5030 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5031 | addu $tempreg,$tempreg,$gp | |
5032 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
5033 | nop | |
5034 | addiu $tempreg,$tempreg,<constant> | |
5035 | For a local symbol, we want | |
5036 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5037 | nop | |
5038 | addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16) | |
5039 | ||
5040 | If we have a large constant, and this is a reference to | |
5041 | an external symbol, we want | |
5042 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5043 | addu $tempreg,$tempreg,$gp | |
5044 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
5045 | lui $at,<hiconstant> | |
5046 | addiu $at,$at,<loconstant> | |
5047 | addu $tempreg,$tempreg,$at | |
5048 | For a local symbol, we want | |
5049 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5050 | lui $at,<hiconstant> | |
5051 | addiu $at,$at,<loconstant> (BFD_RELOC_LO16) | |
5052 | addu $tempreg,$tempreg,$at | |
438c16b8 | 5053 | |
ed6fb7bd SC |
5054 | For NewABI, we want for local data addresses |
5055 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) | |
438c16b8 | 5056 | */ |
438c16b8 | 5057 | |
252b5132 RH |
5058 | expr1.X_add_number = offset_expr.X_add_number; |
5059 | offset_expr.X_add_number = 0; | |
5060 | frag_grow (52); | |
f7ea7ef2 | 5061 | if (reg_needs_delay (mips_gp_register)) |
252b5132 RH |
5062 | gpdel = 4; |
5063 | else | |
5064 | gpdel = 0; | |
9117d219 NC |
5065 | if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG) |
5066 | { | |
5067 | lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16; | |
5068 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16; | |
5069 | } | |
252b5132 | 5070 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", |
9117d219 | 5071 | tempreg, lui_reloc_type); |
252b5132 | 5072 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
ca4e0257 | 5073 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
c9914766 | 5074 | "d,v,t", tempreg, tempreg, mips_gp_register); |
252b5132 | 5075 | macro_build ((char *) NULL, &icnt, &offset_expr, |
4d34fb5f | 5076 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
9117d219 | 5077 | "t,o(b)", tempreg, lw_reloc_type, tempreg); |
252b5132 RH |
5078 | if (expr1.X_add_number == 0) |
5079 | { | |
5080 | int off; | |
5081 | ||
5082 | if (breg == 0) | |
5083 | off = 0; | |
5084 | else | |
5085 | { | |
5086 | /* We're going to put in an addu instruction using | |
5087 | tempreg, so we may as well insert the nop right | |
5088 | now. */ | |
5089 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5090 | "nop", ""); | |
5091 | off = 4; | |
5092 | } | |
5093 | ||
5094 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5095 | RELAX_ENCODE (12 + off, 12 + gpdel, gpdel, | |
5096 | 8 + gpdel, 0, | |
5097 | (breg == 0 | |
5098 | ? mips_opts.warn_about_macros | |
5099 | : 0)), | |
c4e7957c | 5100 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5101 | } |
5102 | else if (expr1.X_add_number >= -0x8000 | |
5103 | && expr1.X_add_number < 0x8000) | |
5104 | { | |
5105 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5106 | "nop", ""); | |
5107 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 5108 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5109 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5110 | ||
5111 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5112 | RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0, | |
5113 | (breg == 0 | |
5114 | ? mips_opts.warn_about_macros | |
5115 | : 0)), | |
c4e7957c | 5116 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5117 | } |
5118 | else | |
5119 | { | |
5120 | int adj, dreg; | |
5121 | ||
5122 | /* If we are going to add in a base register, and the | |
5123 | target register and the base register are the same, | |
5124 | then we are using AT as a temporary register. Since | |
5125 | we want to load the constant into AT, we add our | |
5126 | current AT (from the global offset table) and the | |
5127 | register into the register now, and pretend we were | |
5128 | not using a base register. */ | |
5129 | if (breg != treg) | |
5130 | { | |
5131 | adj = 0; | |
5132 | dreg = tempreg; | |
5133 | } | |
5134 | else | |
5135 | { | |
5136 | assert (tempreg == AT); | |
5137 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5138 | "nop", ""); | |
5139 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5140 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5141 | "d,v,t", treg, AT, breg); |
5142 | dreg = treg; | |
5143 | adj = 8; | |
5144 | } | |
5145 | ||
5146 | /* Set mips_optimize around the lui instruction to avoid | |
5147 | inserting an unnecessary nop after the lw. */ | |
5148 | hold_mips_optimize = mips_optimize; | |
5149 | mips_optimize = 2; | |
c4e7957c | 5150 | macro_build_lui (NULL, &icnt, &expr1, AT); |
252b5132 RH |
5151 | mips_optimize = hold_mips_optimize; |
5152 | ||
5153 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 5154 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5155 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
5156 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5157 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5158 | "d,v,t", dreg, dreg, AT); |
5159 | ||
5160 | p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0, | |
5161 | RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel, | |
5162 | 8 + gpdel, 0, | |
5163 | (breg == 0 | |
5164 | ? mips_opts.warn_about_macros | |
5165 | : 0)), | |
c4e7957c | 5166 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5167 | |
5168 | used_at = 1; | |
5169 | } | |
5170 | ||
5171 | if (gpdel > 0) | |
5172 | { | |
5173 | /* This is needed because this instruction uses $gp, but | |
5174 | the first instruction on the main stream does not. */ | |
5175 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5176 | p += 4; | |
5177 | } | |
ed6fb7bd SC |
5178 | |
5179 | if (HAVE_NEWABI) | |
5180 | local_reloc_type = (int) BFD_RELOC_MIPS_GOT_DISP; | |
252b5132 | 5181 | macro_build (p, &icnt, &offset_expr, |
4d34fb5f | 5182 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
ed6fb7bd SC |
5183 | "t,o(b)", tempreg, |
5184 | local_reloc_type, | |
c9914766 | 5185 | mips_gp_register); |
252b5132 | 5186 | p += 4; |
ed6fb7bd SC |
5187 | if (expr1.X_add_number == 0 && HAVE_NEWABI) |
5188 | { | |
5189 | /* BFD_RELOC_MIPS_GOT_DISP is sufficient for newabi */ | |
5190 | } | |
5191 | else | |
5192 | if (expr1.X_add_number >= -0x8000 | |
252b5132 RH |
5193 | && expr1.X_add_number < 0x8000) |
5194 | { | |
5195 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5196 | p += 4; | |
5197 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 5198 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5199 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5200 | /* FIXME: If add_number is 0, and there was no base | |
5201 | register, the external symbol case ended with a load, | |
5202 | so if the symbol turns out to not be external, and | |
5203 | the next instruction uses tempreg, an unnecessary nop | |
5204 | will be inserted. */ | |
5205 | } | |
5206 | else | |
5207 | { | |
5208 | if (breg == treg) | |
5209 | { | |
5210 | /* We must add in the base register now, as in the | |
5211 | external symbol case. */ | |
5212 | assert (tempreg == AT); | |
5213 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5214 | p += 4; | |
5215 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5216 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5217 | "d,v,t", treg, AT, breg); |
5218 | p += 4; | |
5219 | tempreg = treg; | |
5220 | /* We set breg to 0 because we have arranged to add | |
5221 | it in in both cases. */ | |
5222 | breg = 0; | |
5223 | } | |
5224 | ||
5225 | macro_build_lui (p, &icnt, &expr1, AT); | |
5226 | p += 4; | |
5227 | macro_build (p, &icnt, &expr1, | |
ca4e0257 | 5228 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5229 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); |
5230 | p += 4; | |
5231 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5232 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5233 | "d,v,t", tempreg, tempreg, AT); |
5234 | p += 4; | |
5235 | } | |
5236 | } | |
5237 | else if (mips_pic == EMBEDDED_PIC) | |
5238 | { | |
5239 | /* We use | |
cdf6fd85 | 5240 | addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16) |
252b5132 RH |
5241 | */ |
5242 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
c9914766 TS |
5243 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j", |
5244 | tempreg, mips_gp_register, (int) BFD_RELOC_GPREL16); | |
252b5132 RH |
5245 | } |
5246 | else | |
5247 | abort (); | |
5248 | ||
5249 | if (breg != 0) | |
4d34fb5f TS |
5250 | { |
5251 | char *s; | |
5252 | ||
5253 | if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC) | |
5254 | s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu"; | |
5255 | else | |
5256 | s = HAVE_64BIT_ADDRESSES ? "daddu" : "addu"; | |
5257 | ||
5258 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, | |
5259 | "d,v,t", treg, tempreg, breg); | |
5260 | } | |
252b5132 RH |
5261 | |
5262 | if (! used_at) | |
5263 | return; | |
5264 | ||
5265 | break; | |
5266 | ||
5267 | case M_J_A: | |
5268 | /* The j instruction may not be used in PIC code, since it | |
5269 | requires an absolute address. We convert it to a b | |
5270 | instruction. */ | |
5271 | if (mips_pic == NO_PIC) | |
5272 | macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a"); | |
5273 | else | |
5274 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
5275 | return; | |
5276 | ||
5277 | /* The jal instructions must be handled as macros because when | |
5278 | generating PIC code they expand to multi-instruction | |
5279 | sequences. Normally they are simple instructions. */ | |
5280 | case M_JAL_1: | |
5281 | dreg = RA; | |
5282 | /* Fall through. */ | |
5283 | case M_JAL_2: | |
5284 | if (mips_pic == NO_PIC | |
5285 | || mips_pic == EMBEDDED_PIC) | |
5286 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", | |
5287 | "d,s", dreg, sreg); | |
5288 | else if (mips_pic == SVR4_PIC) | |
5289 | { | |
5290 | if (sreg != PIC_CALL_REG) | |
5291 | as_warn (_("MIPS PIC call to register other than $25")); | |
bdaaa2e1 | 5292 | |
252b5132 RH |
5293 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", |
5294 | "d,s", dreg, sreg); | |
6478892d | 5295 | if (! HAVE_NEWABI) |
252b5132 | 5296 | { |
6478892d TS |
5297 | if (mips_cprestore_offset < 0) |
5298 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
5299 | else | |
5300 | { | |
7a621144 DJ |
5301 | if (! mips_frame_reg_valid) |
5302 | { | |
5303 | as_warn (_("No .frame pseudo-op used in PIC code")); | |
5304 | /* Quiet this warning. */ | |
5305 | mips_frame_reg_valid = 1; | |
5306 | } | |
5307 | if (! mips_cprestore_valid) | |
5308 | { | |
5309 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
5310 | /* Quiet this warning. */ | |
5311 | mips_cprestore_valid = 1; | |
5312 | } | |
6478892d | 5313 | expr1.X_add_number = mips_cprestore_offset; |
885add95 CD |
5314 | macro_build_ldst_constoffset ((char *) NULL, &icnt, &expr1, |
5315 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", | |
5316 | mips_gp_register, mips_frame_reg); | |
6478892d | 5317 | } |
252b5132 RH |
5318 | } |
5319 | } | |
5320 | else | |
5321 | abort (); | |
5322 | ||
5323 | return; | |
5324 | ||
5325 | case M_JAL_A: | |
5326 | if (mips_pic == NO_PIC) | |
5327 | macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a"); | |
5328 | else if (mips_pic == SVR4_PIC) | |
5329 | { | |
f9419b05 TS |
5330 | char *p; |
5331 | ||
252b5132 RH |
5332 | /* If this is a reference to an external symbol, and we are |
5333 | using a small GOT, we want | |
5334 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
5335 | nop | |
f9419b05 | 5336 | jalr $ra,$25 |
252b5132 RH |
5337 | nop |
5338 | lw $gp,cprestore($sp) | |
5339 | The cprestore value is set using the .cprestore | |
5340 | pseudo-op. If we are using a big GOT, we want | |
5341 | lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
5342 | addu $25,$25,$gp | |
5343 | lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16) | |
5344 | nop | |
f9419b05 | 5345 | jalr $ra,$25 |
252b5132 RH |
5346 | nop |
5347 | lw $gp,cprestore($sp) | |
5348 | If the symbol is not external, we want | |
5349 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5350 | nop | |
5351 | addiu $25,$25,<sym> (BFD_RELOC_LO16) | |
f9419b05 | 5352 | jalr $ra,$25 |
252b5132 | 5353 | nop |
438c16b8 TS |
5354 | lw $gp,cprestore($sp) |
5355 | For NewABI, we want | |
5356 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) | |
5357 | jalr $ra,$25 (BFD_RELOC_MIPS_JALR) | |
5358 | */ | |
5359 | if (HAVE_NEWABI) | |
252b5132 RH |
5360 | { |
5361 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 5362 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 | 5363 | "t,o(b)", PIC_CALL_REG, |
438c16b8 TS |
5364 | (int) BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); |
5365 | macro_build_jalr (icnt, &offset_expr); | |
252b5132 RH |
5366 | } |
5367 | else | |
5368 | { | |
438c16b8 TS |
5369 | frag_grow (40); |
5370 | if (! mips_big_got) | |
5371 | { | |
5372 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5373 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", | |
5374 | "t,o(b)", PIC_CALL_REG, | |
5375 | (int) BFD_RELOC_MIPS_CALL16, mips_gp_register); | |
5376 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5377 | "nop", ""); | |
5378 | p = frag_var (rs_machine_dependent, 4, 0, | |
5379 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), | |
5380 | offset_expr.X_add_symbol, 0, NULL); | |
5381 | } | |
252b5132 | 5382 | else |
252b5132 | 5383 | { |
438c16b8 TS |
5384 | int gpdel; |
5385 | ||
5386 | if (reg_needs_delay (mips_gp_register)) | |
5387 | gpdel = 4; | |
5388 | else | |
5389 | gpdel = 0; | |
5390 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", | |
5391 | "t,u", PIC_CALL_REG, | |
5392 | (int) BFD_RELOC_MIPS_CALL_HI16); | |
5393 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5394 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", | |
5395 | "d,v,t", PIC_CALL_REG, PIC_CALL_REG, | |
5396 | mips_gp_register); | |
5397 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5398 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", | |
5399 | "t,o(b)", PIC_CALL_REG, | |
5400 | (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG); | |
5401 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5402 | "nop", ""); | |
5403 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5404 | RELAX_ENCODE (16, 12 + gpdel, gpdel, | |
5405 | 8 + gpdel, 0, 0), | |
5406 | offset_expr.X_add_symbol, 0, NULL); | |
5407 | if (gpdel > 0) | |
5408 | { | |
5409 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5410 | p += 4; | |
5411 | } | |
5412 | macro_build (p, &icnt, &offset_expr, | |
5413 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", | |
5414 | "t,o(b)", PIC_CALL_REG, | |
5415 | (int) BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
5416 | p += 4; | |
252b5132 RH |
5417 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); |
5418 | p += 4; | |
5419 | } | |
5420 | macro_build (p, &icnt, &offset_expr, | |
438c16b8 TS |
5421 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
5422 | "t,r,j", PIC_CALL_REG, PIC_CALL_REG, | |
5423 | (int) BFD_RELOC_LO16); | |
5424 | macro_build_jalr (icnt, &offset_expr); | |
5425 | ||
6478892d TS |
5426 | if (mips_cprestore_offset < 0) |
5427 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
5428 | else | |
5429 | { | |
7a621144 DJ |
5430 | if (! mips_frame_reg_valid) |
5431 | { | |
5432 | as_warn (_("No .frame pseudo-op used in PIC code")); | |
5433 | /* Quiet this warning. */ | |
5434 | mips_frame_reg_valid = 1; | |
5435 | } | |
5436 | if (! mips_cprestore_valid) | |
5437 | { | |
5438 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
5439 | /* Quiet this warning. */ | |
5440 | mips_cprestore_valid = 1; | |
5441 | } | |
6478892d TS |
5442 | if (mips_opts.noreorder) |
5443 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
98d3f06f | 5444 | "nop", ""); |
6478892d | 5445 | expr1.X_add_number = mips_cprestore_offset; |
885add95 CD |
5446 | macro_build_ldst_constoffset ((char *) NULL, &icnt, &expr1, |
5447 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", | |
5448 | mips_gp_register, mips_frame_reg); | |
6478892d | 5449 | } |
252b5132 RH |
5450 | } |
5451 | } | |
5452 | else if (mips_pic == EMBEDDED_PIC) | |
5453 | { | |
5454 | macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p"); | |
5455 | /* The linker may expand the call to a longer sequence which | |
5456 | uses $at, so we must break rather than return. */ | |
5457 | break; | |
5458 | } | |
5459 | else | |
5460 | abort (); | |
5461 | ||
5462 | return; | |
5463 | ||
5464 | case M_LB_AB: | |
5465 | s = "lb"; | |
5466 | goto ld; | |
5467 | case M_LBU_AB: | |
5468 | s = "lbu"; | |
5469 | goto ld; | |
5470 | case M_LH_AB: | |
5471 | s = "lh"; | |
5472 | goto ld; | |
5473 | case M_LHU_AB: | |
5474 | s = "lhu"; | |
5475 | goto ld; | |
5476 | case M_LW_AB: | |
5477 | s = "lw"; | |
5478 | goto ld; | |
5479 | case M_LWC0_AB: | |
5480 | s = "lwc0"; | |
bdaaa2e1 | 5481 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5482 | coproc = 1; |
5483 | goto ld; | |
5484 | case M_LWC1_AB: | |
5485 | s = "lwc1"; | |
bdaaa2e1 | 5486 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5487 | coproc = 1; |
5488 | goto ld; | |
5489 | case M_LWC2_AB: | |
5490 | s = "lwc2"; | |
bdaaa2e1 | 5491 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5492 | coproc = 1; |
5493 | goto ld; | |
5494 | case M_LWC3_AB: | |
5495 | s = "lwc3"; | |
bdaaa2e1 | 5496 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5497 | coproc = 1; |
5498 | goto ld; | |
5499 | case M_LWL_AB: | |
5500 | s = "lwl"; | |
5501 | lr = 1; | |
5502 | goto ld; | |
5503 | case M_LWR_AB: | |
5504 | s = "lwr"; | |
5505 | lr = 1; | |
5506 | goto ld; | |
5507 | case M_LDC1_AB: | |
ec68c924 | 5508 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5509 | { |
5510 | as_bad (_("opcode not supported on this processor")); | |
5511 | return; | |
5512 | } | |
5513 | s = "ldc1"; | |
bdaaa2e1 | 5514 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5515 | coproc = 1; |
5516 | goto ld; | |
5517 | case M_LDC2_AB: | |
5518 | s = "ldc2"; | |
bdaaa2e1 | 5519 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5520 | coproc = 1; |
5521 | goto ld; | |
5522 | case M_LDC3_AB: | |
5523 | s = "ldc3"; | |
bdaaa2e1 | 5524 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5525 | coproc = 1; |
5526 | goto ld; | |
5527 | case M_LDL_AB: | |
5528 | s = "ldl"; | |
5529 | lr = 1; | |
5530 | goto ld; | |
5531 | case M_LDR_AB: | |
5532 | s = "ldr"; | |
5533 | lr = 1; | |
5534 | goto ld; | |
5535 | case M_LL_AB: | |
5536 | s = "ll"; | |
5537 | goto ld; | |
5538 | case M_LLD_AB: | |
5539 | s = "lld"; | |
5540 | goto ld; | |
5541 | case M_LWU_AB: | |
5542 | s = "lwu"; | |
5543 | ld: | |
5544 | if (breg == treg || coproc || lr) | |
5545 | { | |
5546 | tempreg = AT; | |
5547 | used_at = 1; | |
5548 | } | |
5549 | else | |
5550 | { | |
5551 | tempreg = treg; | |
5552 | used_at = 0; | |
5553 | } | |
5554 | goto ld_st; | |
5555 | case M_SB_AB: | |
5556 | s = "sb"; | |
5557 | goto st; | |
5558 | case M_SH_AB: | |
5559 | s = "sh"; | |
5560 | goto st; | |
5561 | case M_SW_AB: | |
5562 | s = "sw"; | |
5563 | goto st; | |
5564 | case M_SWC0_AB: | |
5565 | s = "swc0"; | |
bdaaa2e1 | 5566 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5567 | coproc = 1; |
5568 | goto st; | |
5569 | case M_SWC1_AB: | |
5570 | s = "swc1"; | |
bdaaa2e1 | 5571 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5572 | coproc = 1; |
5573 | goto st; | |
5574 | case M_SWC2_AB: | |
5575 | s = "swc2"; | |
bdaaa2e1 | 5576 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5577 | coproc = 1; |
5578 | goto st; | |
5579 | case M_SWC3_AB: | |
5580 | s = "swc3"; | |
bdaaa2e1 | 5581 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5582 | coproc = 1; |
5583 | goto st; | |
5584 | case M_SWL_AB: | |
5585 | s = "swl"; | |
5586 | goto st; | |
5587 | case M_SWR_AB: | |
5588 | s = "swr"; | |
5589 | goto st; | |
5590 | case M_SC_AB: | |
5591 | s = "sc"; | |
5592 | goto st; | |
5593 | case M_SCD_AB: | |
5594 | s = "scd"; | |
5595 | goto st; | |
5596 | case M_SDC1_AB: | |
ec68c924 | 5597 | if (mips_arch == CPU_R4650) |
252b5132 RH |
5598 | { |
5599 | as_bad (_("opcode not supported on this processor")); | |
5600 | return; | |
5601 | } | |
5602 | s = "sdc1"; | |
5603 | coproc = 1; | |
bdaaa2e1 | 5604 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5605 | goto st; |
5606 | case M_SDC2_AB: | |
5607 | s = "sdc2"; | |
bdaaa2e1 | 5608 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5609 | coproc = 1; |
5610 | goto st; | |
5611 | case M_SDC3_AB: | |
5612 | s = "sdc3"; | |
bdaaa2e1 | 5613 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5614 | coproc = 1; |
5615 | goto st; | |
5616 | case M_SDL_AB: | |
5617 | s = "sdl"; | |
5618 | goto st; | |
5619 | case M_SDR_AB: | |
5620 | s = "sdr"; | |
5621 | st: | |
5622 | tempreg = AT; | |
5623 | used_at = 1; | |
5624 | ld_st: | |
bdaaa2e1 | 5625 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5626 | if (mask == M_LWC1_AB |
5627 | || mask == M_SWC1_AB | |
5628 | || mask == M_LDC1_AB | |
5629 | || mask == M_SDC1_AB | |
5630 | || mask == M_L_DAB | |
5631 | || mask == M_S_DAB) | |
5632 | fmt = "T,o(b)"; | |
5633 | else if (coproc) | |
5634 | fmt = "E,o(b)"; | |
5635 | else | |
5636 | fmt = "t,o(b)"; | |
5637 | ||
afdbd6d0 CD |
5638 | /* For embedded PIC, we allow loads where the offset is calculated |
5639 | by subtracting a symbol in the current segment from an unknown | |
5640 | symbol, relative to a base register, e.g.: | |
5641 | <op> $treg, <sym>-<localsym>($breg) | |
5642 | This is used by the compiler for switch statements. */ | |
76b3015f | 5643 | if (mips_pic == EMBEDDED_PIC |
afdbd6d0 CD |
5644 | && offset_expr.X_op == O_subtract |
5645 | && (symbol_constant_p (offset_expr.X_op_symbol) | |
5646 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg | |
5647 | : (symbol_equated_p (offset_expr.X_op_symbol) | |
5648 | && (S_GET_SEGMENT | |
5649 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
5650 | ->X_add_symbol) | |
5651 | == now_seg))) | |
5652 | && breg != 0 | |
5653 | && (offset_expr.X_add_number == 0 | |
5654 | || OUTPUT_FLAVOR == bfd_target_elf_flavour)) | |
5655 | { | |
5656 | /* For this case, we output the instructions: | |
5657 | lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S) | |
5658 | addiu $tempreg,$tempreg,$breg | |
5659 | <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16) | |
5660 | If the relocation would fit entirely in 16 bits, it would be | |
5661 | nice to emit: | |
5662 | <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16) | |
5663 | instead, but that seems quite difficult. */ | |
5664 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5665 | tempreg, (int) BFD_RELOC_PCREL_HI16_S); | |
5666 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5667 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
5668 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
5669 | ? "addu" : "daddu"), | |
5670 | "d,v,t", tempreg, tempreg, breg); | |
5671 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg, | |
5672 | (int) BFD_RELOC_PCREL_LO16, tempreg); | |
5673 | if (! used_at) | |
5674 | return; | |
5675 | break; | |
5676 | } | |
5677 | ||
252b5132 RH |
5678 | if (offset_expr.X_op != O_constant |
5679 | && offset_expr.X_op != O_symbol) | |
5680 | { | |
5681 | as_bad (_("expression too complex")); | |
5682 | offset_expr.X_op = O_constant; | |
5683 | } | |
5684 | ||
5685 | /* A constant expression in PIC code can be handled just as it | |
5686 | is in non PIC code. */ | |
5687 | if (mips_pic == NO_PIC | |
5688 | || offset_expr.X_op == O_constant) | |
5689 | { | |
f9419b05 TS |
5690 | char *p; |
5691 | ||
252b5132 RH |
5692 | /* If this is a reference to a GP relative symbol, and there |
5693 | is no base register, we want | |
cdf6fd85 | 5694 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
252b5132 RH |
5695 | Otherwise, if there is no base register, we want |
5696 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5697 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5698 | If we have a constant, we need two instructions anyhow, | |
5699 | so we always use the latter form. | |
5700 | ||
5701 | If we have a base register, and this is a reference to a | |
5702 | GP relative symbol, we want | |
5703 | addu $tempreg,$breg,$gp | |
cdf6fd85 | 5704 | <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16) |
252b5132 RH |
5705 | Otherwise we want |
5706 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5707 | addu $tempreg,$tempreg,$breg | |
5708 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
d6bc6245 | 5709 | With a constant we always use the latter case. |
76b3015f | 5710 | |
d6bc6245 TS |
5711 | With 64bit address space and no base register and $at usable, |
5712 | we want | |
5713 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5714 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5715 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5716 | dsll32 $tempreg,0 | |
5717 | daddu $tempreg,$at | |
5718 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5719 | If we have a base register, we want | |
5720 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5721 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5722 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5723 | daddu $at,$breg | |
5724 | dsll32 $tempreg,0 | |
5725 | daddu $tempreg,$at | |
5726 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5727 | ||
5728 | Without $at we can't generate the optimal path for superscalar | |
5729 | processors here since this would require two temporary registers. | |
5730 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5731 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5732 | dsll $tempreg,16 | |
5733 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5734 | dsll $tempreg,16 | |
5735 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5736 | If we have a base register, we want | |
5737 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) | |
5738 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) | |
5739 | dsll $tempreg,16 | |
5740 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5741 | dsll $tempreg,16 | |
5742 | daddu $tempreg,$tempreg,$breg | |
5743 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
6373ee54 CD |
5744 | |
5745 | If we have 64-bit addresses, as an optimization, for | |
5746 | addresses which are 32-bit constants (e.g. kseg0/kseg1 | |
5747 | addresses) we fall back to the 32-bit address generation | |
78d32a17 MR |
5748 | mechanism since it is more efficient. Note that due to |
5749 | the signed offset used by memory operations, the 32-bit | |
5750 | range is shifted down by 32768 here. This code should | |
6373ee54 CD |
5751 | probably attempt to generate 64-bit constants more |
5752 | efficiently in general. | |
d6bc6245 | 5753 | */ |
6373ee54 CD |
5754 | if (HAVE_64BIT_ADDRESSES |
5755 | && !(offset_expr.X_op == O_constant | |
78d32a17 | 5756 | && IS_SEXT_32BIT_NUM (offset_expr.X_add_number + 0x8000))) |
d6bc6245 TS |
5757 | { |
5758 | p = NULL; | |
5759 | ||
5760 | /* We don't do GP optimization for now because RELAX_ENCODE can't | |
5761 | hold the data for such large chunks. */ | |
5762 | ||
460597ba | 5763 | if (used_at == 0 && ! mips_opts.noat) |
d6bc6245 TS |
5764 | { |
5765 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5766 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
5767 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5768 | AT, (int) BFD_RELOC_HI16_S); | |
5769 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
5770 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
5771 | if (breg != 0) | |
2396cfb9 TS |
5772 | macro_build (p, &icnt, (expressionS *) NULL, "daddu", |
5773 | "d,v,t", AT, AT, breg); | |
5774 | macro_build (p, &icnt, (expressionS *) NULL, "dsll32", | |
5775 | "d,w,<", tempreg, tempreg, 0); | |
5776 | macro_build (p, &icnt, (expressionS *) NULL, "daddu", | |
5777 | "d,v,t", tempreg, tempreg, AT); | |
d6bc6245 TS |
5778 | macro_build (p, &icnt, &offset_expr, s, |
5779 | fmt, treg, (int) BFD_RELOC_LO16, tempreg); | |
5780 | used_at = 1; | |
5781 | } | |
5782 | else | |
5783 | { | |
5784 | macro_build (p, &icnt, &offset_expr, "lui", "t,u", | |
5785 | tempreg, (int) BFD_RELOC_MIPS_HIGHEST); | |
5786 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", | |
5787 | tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER); | |
2396cfb9 TS |
5788 | macro_build (p, &icnt, (expressionS *) NULL, "dsll", |
5789 | "d,w,<", tempreg, tempreg, 16); | |
d6bc6245 TS |
5790 | macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j", |
5791 | tempreg, tempreg, (int) BFD_RELOC_HI16_S); | |
2396cfb9 TS |
5792 | macro_build (p, &icnt, (expressionS *) NULL, "dsll", |
5793 | "d,w,<", tempreg, tempreg, 16); | |
d6bc6245 | 5794 | if (breg != 0) |
2396cfb9 TS |
5795 | macro_build (p, &icnt, (expressionS *) NULL, "daddu", |
5796 | "d,v,t", tempreg, tempreg, breg); | |
d6bc6245 TS |
5797 | macro_build (p, &icnt, &offset_expr, s, |
5798 | fmt, treg, (int) BFD_RELOC_LO16, tempreg); | |
5799 | } | |
5800 | ||
5801 | return; | |
5802 | } | |
76b3015f | 5803 | |
252b5132 RH |
5804 | if (breg == 0) |
5805 | { | |
e7d556df | 5806 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5807 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5808 | p = NULL; | |
5809 | else | |
5810 | { | |
5811 | frag_grow (20); | |
5812 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
c9914766 TS |
5813 | treg, (int) BFD_RELOC_GPREL16, |
5814 | mips_gp_register); | |
252b5132 RH |
5815 | p = frag_var (rs_machine_dependent, 8, 0, |
5816 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
5817 | (mips_opts.warn_about_macros | |
5818 | || (used_at | |
5819 | && mips_opts.noat))), | |
956cd1d6 | 5820 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5821 | used_at = 0; |
5822 | } | |
5823 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5824 | if (p != NULL) | |
5825 | p += 4; | |
5826 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5827 | (int) BFD_RELOC_LO16, tempreg); | |
5828 | } | |
5829 | else | |
5830 | { | |
e7d556df | 5831 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
5832 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
5833 | p = NULL; | |
5834 | else | |
5835 | { | |
5836 | frag_grow (28); | |
5837 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5838 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
c9914766 | 5839 | "d,v,t", tempreg, breg, mips_gp_register); |
252b5132 | 5840 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
cdf6fd85 | 5841 | treg, (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
5842 | p = frag_var (rs_machine_dependent, 12, 0, |
5843 | RELAX_ENCODE (8, 12, 0, 8, 0, 0), | |
956cd1d6 | 5844 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5845 | } |
5846 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5847 | if (p != NULL) | |
5848 | p += 4; | |
5849 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5850 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5851 | "d,v,t", tempreg, tempreg, breg); |
5852 | if (p != NULL) | |
5853 | p += 4; | |
5854 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5855 | (int) BFD_RELOC_LO16, tempreg); | |
5856 | } | |
5857 | } | |
5858 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
5859 | { | |
f9419b05 | 5860 | char *p; |
ed6fb7bd | 5861 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
f9419b05 | 5862 | |
252b5132 RH |
5863 | /* If this is a reference to an external symbol, we want |
5864 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5865 | nop | |
5866 | <op> $treg,0($tempreg) | |
5867 | Otherwise we want | |
5868 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5869 | nop | |
5870 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5871 | <op> $treg,0($tempreg) | |
ed6fb7bd SC |
5872 | If we have NewABI, we want |
5873 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) | |
252b5132 RH |
5874 | If there is a base register, we add it to $tempreg before |
5875 | the <op>. If there is a constant, we stick it in the | |
5876 | <op> instruction. We don't handle constants larger than | |
5877 | 16 bits, because we have no way to load the upper 16 bits | |
5878 | (actually, we could handle them for the subset of cases | |
5879 | in which we are not using $at). */ | |
5880 | assert (offset_expr.X_op == O_symbol); | |
5881 | expr1.X_add_number = offset_expr.X_add_number; | |
5882 | offset_expr.X_add_number = 0; | |
ed6fb7bd SC |
5883 | if (HAVE_NEWABI) |
5884 | lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_DISP; | |
252b5132 RH |
5885 | if (expr1.X_add_number < -0x8000 |
5886 | || expr1.X_add_number >= 0x8000) | |
5887 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5888 | frag_grow (20); | |
5889 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
c9914766 | 5890 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", tempreg, |
ed6fb7bd | 5891 | (int) lw_reloc_type, mips_gp_register); |
252b5132 | 5892 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); |
bdaaa2e1 | 5893 | p = frag_var (rs_machine_dependent, 4, 0, |
252b5132 | 5894 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), |
c4e7957c | 5895 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 | 5896 | macro_build (p, &icnt, &offset_expr, |
ca4e0257 | 5897 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5898 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5899 | if (breg != 0) | |
5900 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5901 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5902 | "d,v,t", tempreg, tempreg, breg); |
5903 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5904 | (int) BFD_RELOC_LO16, tempreg); | |
5905 | } | |
5906 | else if (mips_pic == SVR4_PIC) | |
5907 | { | |
5908 | int gpdel; | |
f9419b05 | 5909 | char *p; |
252b5132 RH |
5910 | |
5911 | /* If this is a reference to an external symbol, we want | |
5912 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5913 | addu $tempreg,$tempreg,$gp | |
5914 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
5915 | <op> $treg,0($tempreg) | |
5916 | Otherwise we want | |
5917 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5918 | nop | |
5919 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5920 | <op> $treg,0($tempreg) | |
5921 | If there is a base register, we add it to $tempreg before | |
5922 | the <op>. If there is a constant, we stick it in the | |
5923 | <op> instruction. We don't handle constants larger than | |
5924 | 16 bits, because we have no way to load the upper 16 bits | |
5925 | (actually, we could handle them for the subset of cases | |
438c16b8 TS |
5926 | in which we are not using $at). |
5927 | ||
5928 | For NewABI, we want | |
5929 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) | |
5930 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_MIPS_GOT_OFST) | |
5931 | <op> $treg,0($tempreg) | |
5932 | */ | |
252b5132 RH |
5933 | assert (offset_expr.X_op == O_symbol); |
5934 | expr1.X_add_number = offset_expr.X_add_number; | |
5935 | offset_expr.X_add_number = 0; | |
5936 | if (expr1.X_add_number < -0x8000 | |
5937 | || expr1.X_add_number >= 0x8000) | |
5938 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
438c16b8 TS |
5939 | if (HAVE_NEWABI) |
5940 | { | |
5941 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5942 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", | |
5943 | "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_PAGE, | |
5944 | mips_gp_register); | |
5945 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5946 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", | |
5947 | "t,r,j", tempreg, tempreg, | |
5948 | BFD_RELOC_MIPS_GOT_OFST); | |
5949 | if (breg != 0) | |
5950 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5951 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", | |
5952 | "d,v,t", tempreg, tempreg, breg); | |
5953 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5954 | (int) BFD_RELOC_LO16, tempreg); | |
5955 | ||
5956 | if (! used_at) | |
5957 | return; | |
5958 | ||
5959 | break; | |
5960 | } | |
f7ea7ef2 | 5961 | if (reg_needs_delay (mips_gp_register)) |
252b5132 RH |
5962 | gpdel = 4; |
5963 | else | |
5964 | gpdel = 0; | |
5965 | frag_grow (36); | |
5966 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5967 | tempreg, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5968 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5969 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
c9914766 | 5970 | "d,v,t", tempreg, tempreg, mips_gp_register); |
252b5132 | 5971 | macro_build ((char *) NULL, &icnt, &offset_expr, |
ca4e0257 | 5972 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
5973 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16, |
5974 | tempreg); | |
5975 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5976 | RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0), | |
c4e7957c | 5977 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
5978 | if (gpdel > 0) |
5979 | { | |
5980 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5981 | p += 4; | |
5982 | } | |
5983 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5984 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
c9914766 TS |
5985 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, |
5986 | mips_gp_register); | |
252b5132 RH |
5987 | p += 4; |
5988 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5989 | p += 4; | |
5990 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 5991 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", |
252b5132 RH |
5992 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); |
5993 | if (breg != 0) | |
5994 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 5995 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
5996 | "d,v,t", tempreg, tempreg, breg); |
5997 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5998 | (int) BFD_RELOC_LO16, tempreg); | |
5999 | } | |
6000 | else if (mips_pic == EMBEDDED_PIC) | |
6001 | { | |
6002 | /* If there is no base register, we want | |
cdf6fd85 | 6003 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
252b5132 RH |
6004 | If there is a base register, we want |
6005 | addu $tempreg,$breg,$gp | |
cdf6fd85 | 6006 | <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16) |
252b5132 RH |
6007 | */ |
6008 | assert (offset_expr.X_op == O_symbol); | |
6009 | if (breg == 0) | |
6010 | { | |
6011 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
c9914766 | 6012 | treg, (int) BFD_RELOC_GPREL16, mips_gp_register); |
252b5132 RH |
6013 | used_at = 0; |
6014 | } | |
6015 | else | |
6016 | { | |
6017 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6018 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
c9914766 | 6019 | "d,v,t", tempreg, breg, mips_gp_register); |
252b5132 | 6020 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
cdf6fd85 | 6021 | treg, (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
6022 | } |
6023 | } | |
6024 | else | |
6025 | abort (); | |
6026 | ||
6027 | if (! used_at) | |
6028 | return; | |
6029 | ||
6030 | break; | |
6031 | ||
6032 | case M_LI: | |
6033 | case M_LI_S: | |
6034 | load_register (&icnt, treg, &imm_expr, 0); | |
6035 | return; | |
6036 | ||
6037 | case M_DLI: | |
6038 | load_register (&icnt, treg, &imm_expr, 1); | |
6039 | return; | |
6040 | ||
6041 | case M_LI_SS: | |
6042 | if (imm_expr.X_op == O_constant) | |
6043 | { | |
6044 | load_register (&icnt, AT, &imm_expr, 0); | |
6045 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6046 | "mtc1", "t,G", AT, treg); | |
6047 | break; | |
6048 | } | |
6049 | else | |
6050 | { | |
6051 | assert (offset_expr.X_op == O_symbol | |
6052 | && strcmp (segment_name (S_GET_SEGMENT | |
6053 | (offset_expr.X_add_symbol)), | |
6054 | ".lit4") == 0 | |
6055 | && offset_expr.X_add_number == 0); | |
6056 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
c9914766 | 6057 | treg, (int) BFD_RELOC_MIPS_LITERAL, mips_gp_register); |
252b5132 RH |
6058 | return; |
6059 | } | |
6060 | ||
6061 | case M_LI_D: | |
ca4e0257 RS |
6062 | /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits |
6063 | wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high | |
6064 | order 32 bits of the value and the low order 32 bits are either | |
6065 | zero or in OFFSET_EXPR. */ | |
252b5132 RH |
6066 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
6067 | { | |
ca4e0257 | 6068 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
6069 | load_register (&icnt, treg, &imm_expr, 1); |
6070 | else | |
6071 | { | |
6072 | int hreg, lreg; | |
6073 | ||
6074 | if (target_big_endian) | |
6075 | { | |
6076 | hreg = treg; | |
6077 | lreg = treg + 1; | |
6078 | } | |
6079 | else | |
6080 | { | |
6081 | hreg = treg + 1; | |
6082 | lreg = treg; | |
6083 | } | |
6084 | ||
6085 | if (hreg <= 31) | |
6086 | load_register (&icnt, hreg, &imm_expr, 0); | |
6087 | if (lreg <= 31) | |
6088 | { | |
6089 | if (offset_expr.X_op == O_absent) | |
ea1fb5dc | 6090 | move_register (&icnt, lreg, 0); |
252b5132 RH |
6091 | else |
6092 | { | |
6093 | assert (offset_expr.X_op == O_constant); | |
6094 | load_register (&icnt, lreg, &offset_expr, 0); | |
6095 | } | |
6096 | } | |
6097 | } | |
6098 | return; | |
6099 | } | |
6100 | ||
6101 | /* We know that sym is in the .rdata section. First we get the | |
6102 | upper 16 bits of the address. */ | |
6103 | if (mips_pic == NO_PIC) | |
6104 | { | |
956cd1d6 | 6105 | macro_build_lui (NULL, &icnt, &offset_expr, AT); |
252b5132 RH |
6106 | } |
6107 | else if (mips_pic == SVR4_PIC) | |
6108 | { | |
6109 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 6110 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
c9914766 TS |
6111 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, |
6112 | mips_gp_register); | |
252b5132 RH |
6113 | } |
6114 | else if (mips_pic == EMBEDDED_PIC) | |
6115 | { | |
6116 | /* For embedded PIC we pick up the entire address off $gp in | |
6117 | a single instruction. */ | |
6118 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
c9914766 TS |
6119 | HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j", AT, |
6120 | mips_gp_register, (int) BFD_RELOC_GPREL16); | |
252b5132 RH |
6121 | offset_expr.X_op = O_constant; |
6122 | offset_expr.X_add_number = 0; | |
6123 | } | |
6124 | else | |
6125 | abort (); | |
bdaaa2e1 | 6126 | |
252b5132 | 6127 | /* Now we load the register(s). */ |
ca4e0257 | 6128 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
6129 | macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)", |
6130 | treg, (int) BFD_RELOC_LO16, AT); | |
6131 | else | |
6132 | { | |
6133 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
6134 | treg, (int) BFD_RELOC_LO16, AT); | |
f9419b05 | 6135 | if (treg != RA) |
252b5132 RH |
6136 | { |
6137 | /* FIXME: How in the world do we deal with the possible | |
6138 | overflow here? */ | |
6139 | offset_expr.X_add_number += 4; | |
6140 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
6141 | treg + 1, (int) BFD_RELOC_LO16, AT); | |
6142 | } | |
6143 | } | |
6144 | ||
6145 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
6146 | does not become a variant frag. */ | |
6147 | frag_wane (frag_now); | |
6148 | frag_new (0); | |
6149 | ||
6150 | break; | |
6151 | ||
6152 | case M_LI_DD: | |
ca4e0257 RS |
6153 | /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits |
6154 | wide, IMM_EXPR is the entire value and the GPRs are known to be 64 | |
6155 | bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of | |
6156 | the value and the low order 32 bits are either zero or in | |
6157 | OFFSET_EXPR. */ | |
252b5132 RH |
6158 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
6159 | { | |
ca4e0257 RS |
6160 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS); |
6161 | if (HAVE_64BIT_FPRS) | |
6162 | { | |
6163 | assert (HAVE_64BIT_GPRS); | |
6164 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6165 | "dmtc1", "t,S", AT, treg); | |
6166 | } | |
252b5132 RH |
6167 | else |
6168 | { | |
6169 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6170 | "mtc1", "t,G", AT, treg + 1); | |
6171 | if (offset_expr.X_op == O_absent) | |
6172 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6173 | "mtc1", "t,G", 0, treg); | |
6174 | else | |
6175 | { | |
6176 | assert (offset_expr.X_op == O_constant); | |
6177 | load_register (&icnt, AT, &offset_expr, 0); | |
6178 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6179 | "mtc1", "t,G", AT, treg); | |
6180 | } | |
6181 | } | |
6182 | break; | |
6183 | } | |
6184 | ||
6185 | assert (offset_expr.X_op == O_symbol | |
6186 | && offset_expr.X_add_number == 0); | |
6187 | s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol)); | |
6188 | if (strcmp (s, ".lit8") == 0) | |
6189 | { | |
e7af610e | 6190 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
6191 | { |
6192 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
c9914766 TS |
6193 | "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, |
6194 | mips_gp_register); | |
252b5132 RH |
6195 | return; |
6196 | } | |
c9914766 | 6197 | breg = mips_gp_register; |
252b5132 RH |
6198 | r = BFD_RELOC_MIPS_LITERAL; |
6199 | goto dob; | |
6200 | } | |
6201 | else | |
6202 | { | |
6203 | assert (strcmp (s, RDATA_SECTION_NAME) == 0); | |
6204 | if (mips_pic == SVR4_PIC) | |
6205 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
ca4e0257 | 6206 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
c9914766 TS |
6207 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, |
6208 | mips_gp_register); | |
252b5132 RH |
6209 | else |
6210 | { | |
6211 | /* FIXME: This won't work for a 64 bit address. */ | |
956cd1d6 | 6212 | macro_build_lui (NULL, &icnt, &offset_expr, AT); |
252b5132 | 6213 | } |
bdaaa2e1 | 6214 | |
e7af610e | 6215 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
6216 | { |
6217 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
6218 | "T,o(b)", treg, (int) BFD_RELOC_LO16, AT); | |
6219 | ||
6220 | /* To avoid confusion in tc_gen_reloc, we must ensure | |
6221 | that this does not become a variant frag. */ | |
6222 | frag_wane (frag_now); | |
6223 | frag_new (0); | |
6224 | ||
6225 | break; | |
6226 | } | |
6227 | breg = AT; | |
6228 | r = BFD_RELOC_LO16; | |
6229 | goto dob; | |
6230 | } | |
6231 | ||
6232 | case M_L_DOB: | |
ec68c924 | 6233 | if (mips_arch == CPU_R4650) |
252b5132 RH |
6234 | { |
6235 | as_bad (_("opcode not supported on this processor")); | |
6236 | return; | |
6237 | } | |
6238 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
6239 | to adjust when loading from memory. */ | |
6240 | r = BFD_RELOC_LO16; | |
6241 | dob: | |
e7af610e | 6242 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
6243 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", |
6244 | target_big_endian ? treg + 1 : treg, | |
6245 | (int) r, breg); | |
6246 | /* FIXME: A possible overflow which I don't know how to deal | |
6247 | with. */ | |
6248 | offset_expr.X_add_number += 4; | |
6249 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
6250 | target_big_endian ? treg : treg + 1, | |
6251 | (int) r, breg); | |
6252 | ||
6253 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
6254 | does not become a variant frag. */ | |
6255 | frag_wane (frag_now); | |
6256 | frag_new (0); | |
6257 | ||
6258 | if (breg != AT) | |
6259 | return; | |
6260 | break; | |
6261 | ||
6262 | case M_L_DAB: | |
6263 | /* | |
6264 | * The MIPS assembler seems to check for X_add_number not | |
6265 | * being double aligned and generating: | |
6266 | * lui at,%hi(foo+1) | |
6267 | * addu at,at,v1 | |
6268 | * addiu at,at,%lo(foo+1) | |
6269 | * lwc1 f2,0(at) | |
6270 | * lwc1 f3,4(at) | |
6271 | * But, the resulting address is the same after relocation so why | |
6272 | * generate the extra instruction? | |
6273 | */ | |
ec68c924 | 6274 | if (mips_arch == CPU_R4650) |
252b5132 RH |
6275 | { |
6276 | as_bad (_("opcode not supported on this processor")); | |
6277 | return; | |
6278 | } | |
bdaaa2e1 | 6279 | /* Itbl support may require additional care here. */ |
252b5132 | 6280 | coproc = 1; |
e7af610e | 6281 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
6282 | { |
6283 | s = "ldc1"; | |
6284 | goto ld; | |
6285 | } | |
6286 | ||
6287 | s = "lwc1"; | |
6288 | fmt = "T,o(b)"; | |
6289 | goto ldd_std; | |
6290 | ||
6291 | case M_S_DAB: | |
ec68c924 | 6292 | if (mips_arch == CPU_R4650) |
252b5132 RH |
6293 | { |
6294 | as_bad (_("opcode not supported on this processor")); | |
6295 | return; | |
6296 | } | |
6297 | ||
e7af610e | 6298 | if (mips_opts.isa != ISA_MIPS1) |
252b5132 RH |
6299 | { |
6300 | s = "sdc1"; | |
6301 | goto st; | |
6302 | } | |
6303 | ||
6304 | s = "swc1"; | |
6305 | fmt = "T,o(b)"; | |
bdaaa2e1 | 6306 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6307 | coproc = 1; |
6308 | goto ldd_std; | |
6309 | ||
6310 | case M_LD_AB: | |
ca4e0257 | 6311 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
6312 | { |
6313 | s = "ld"; | |
6314 | goto ld; | |
6315 | } | |
6316 | ||
6317 | s = "lw"; | |
6318 | fmt = "t,o(b)"; | |
6319 | goto ldd_std; | |
6320 | ||
6321 | case M_SD_AB: | |
ca4e0257 | 6322 | if (HAVE_64BIT_GPRS) |
252b5132 RH |
6323 | { |
6324 | s = "sd"; | |
6325 | goto st; | |
6326 | } | |
6327 | ||
6328 | s = "sw"; | |
6329 | fmt = "t,o(b)"; | |
6330 | ||
6331 | ldd_std: | |
afdbd6d0 CD |
6332 | /* We do _not_ bother to allow embedded PIC (symbol-local_symbol) |
6333 | loads for the case of doing a pair of loads to simulate an 'ld'. | |
6334 | This is not currently done by the compiler, and assembly coders | |
6335 | writing embedded-pic code can cope. */ | |
6336 | ||
252b5132 RH |
6337 | if (offset_expr.X_op != O_symbol |
6338 | && offset_expr.X_op != O_constant) | |
6339 | { | |
6340 | as_bad (_("expression too complex")); | |
6341 | offset_expr.X_op = O_constant; | |
6342 | } | |
6343 | ||
6344 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
6345 | to adjust when loading from memory. We set coproc if we must | |
6346 | load $fn+1 first. */ | |
bdaaa2e1 | 6347 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6348 | if (! target_big_endian) |
6349 | coproc = 0; | |
6350 | ||
6351 | if (mips_pic == NO_PIC | |
6352 | || offset_expr.X_op == O_constant) | |
6353 | { | |
f9419b05 TS |
6354 | char *p; |
6355 | ||
252b5132 | 6356 | /* If this is a reference to a GP relative symbol, we want |
cdf6fd85 TS |
6357 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
6358 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16) | |
252b5132 RH |
6359 | If we have a base register, we use this |
6360 | addu $at,$breg,$gp | |
cdf6fd85 TS |
6361 | <op> $treg,<sym>($at) (BFD_RELOC_GPREL16) |
6362 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16) | |
252b5132 RH |
6363 | If this is not a GP relative symbol, we want |
6364 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
6365 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
6366 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
6367 | If there is a base register, we add it to $at after the | |
6368 | lui instruction. If there is a constant, we always use | |
6369 | the last case. */ | |
e7d556df | 6370 | if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET |
252b5132 RH |
6371 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) |
6372 | { | |
6373 | p = NULL; | |
6374 | used_at = 1; | |
6375 | } | |
6376 | else | |
6377 | { | |
6378 | int off; | |
6379 | ||
6380 | if (breg == 0) | |
6381 | { | |
6382 | frag_grow (28); | |
c9914766 | 6383 | tempreg = mips_gp_register; |
252b5132 RH |
6384 | off = 0; |
6385 | used_at = 0; | |
6386 | } | |
6387 | else | |
6388 | { | |
6389 | frag_grow (36); | |
6390 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6391 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
c9914766 | 6392 | "d,v,t", AT, breg, mips_gp_register); |
252b5132 RH |
6393 | tempreg = AT; |
6394 | off = 4; | |
6395 | used_at = 1; | |
6396 | } | |
6397 | ||
beae10d5 | 6398 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6399 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6400 | coproc ? treg + 1 : treg, | |
cdf6fd85 | 6401 | (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
6402 | offset_expr.X_add_number += 4; |
6403 | ||
6404 | /* Set mips_optimize to 2 to avoid inserting an | |
6405 | undesired nop. */ | |
6406 | hold_mips_optimize = mips_optimize; | |
6407 | mips_optimize = 2; | |
beae10d5 | 6408 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6409 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6410 | coproc ? treg : treg + 1, | |
cdf6fd85 | 6411 | (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
6412 | mips_optimize = hold_mips_optimize; |
6413 | ||
6414 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
6415 | RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1, | |
6416 | used_at && mips_opts.noat), | |
956cd1d6 | 6417 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
6418 | |
6419 | /* We just generated two relocs. When tc_gen_reloc | |
6420 | handles this case, it will skip the first reloc and | |
6421 | handle the second. The second reloc already has an | |
6422 | extra addend of 4, which we added above. We must | |
6423 | subtract it out, and then subtract another 4 to make | |
6424 | the first reloc come out right. The second reloc | |
6425 | will come out right because we are going to add 4 to | |
6426 | offset_expr when we build its instruction below. | |
6427 | ||
6428 | If we have a symbol, then we don't want to include | |
6429 | the offset, because it will wind up being included | |
6430 | when we generate the reloc. */ | |
6431 | ||
6432 | if (offset_expr.X_op == O_constant) | |
6433 | offset_expr.X_add_number -= 8; | |
6434 | else | |
6435 | { | |
6436 | offset_expr.X_add_number = -4; | |
6437 | offset_expr.X_op = O_constant; | |
6438 | } | |
6439 | } | |
6440 | macro_build_lui (p, &icnt, &offset_expr, AT); | |
6441 | if (p != NULL) | |
6442 | p += 4; | |
6443 | if (breg != 0) | |
6444 | { | |
6445 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6446 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6447 | "d,v,t", AT, breg, AT); |
6448 | if (p != NULL) | |
6449 | p += 4; | |
6450 | } | |
beae10d5 | 6451 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6452 | macro_build (p, &icnt, &offset_expr, s, fmt, |
6453 | coproc ? treg + 1 : treg, | |
6454 | (int) BFD_RELOC_LO16, AT); | |
6455 | if (p != NULL) | |
6456 | p += 4; | |
6457 | /* FIXME: How do we handle overflow here? */ | |
6458 | offset_expr.X_add_number += 4; | |
beae10d5 | 6459 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6460 | macro_build (p, &icnt, &offset_expr, s, fmt, |
6461 | coproc ? treg : treg + 1, | |
6462 | (int) BFD_RELOC_LO16, AT); | |
bdaaa2e1 | 6463 | } |
252b5132 RH |
6464 | else if (mips_pic == SVR4_PIC && ! mips_big_got) |
6465 | { | |
6466 | int off; | |
6467 | ||
6468 | /* If this is a reference to an external symbol, we want | |
6469 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6470 | nop | |
6471 | <op> $treg,0($at) | |
6472 | <op> $treg+1,4($at) | |
6473 | Otherwise we want | |
6474 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6475 | nop | |
6476 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
6477 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
6478 | If there is a base register we add it to $at before the | |
6479 | lwc1 instructions. If there is a constant we include it | |
6480 | in the lwc1 instructions. */ | |
6481 | used_at = 1; | |
6482 | expr1.X_add_number = offset_expr.X_add_number; | |
6483 | offset_expr.X_add_number = 0; | |
6484 | if (expr1.X_add_number < -0x8000 | |
6485 | || expr1.X_add_number >= 0x8000 - 4) | |
6486 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
6487 | if (breg == 0) | |
6488 | off = 0; | |
6489 | else | |
6490 | off = 4; | |
6491 | frag_grow (24 + off); | |
6492 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
c9914766 TS |
6493 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", AT, |
6494 | (int) BFD_RELOC_MIPS_GOT16, mips_gp_register); | |
252b5132 RH |
6495 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); |
6496 | if (breg != 0) | |
6497 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6498 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 6499 | "d,v,t", AT, breg, AT); |
beae10d5 | 6500 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6501 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6502 | coproc ? treg + 1 : treg, | |
6503 | (int) BFD_RELOC_LO16, AT); | |
6504 | expr1.X_add_number += 4; | |
6505 | ||
6506 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6507 | nop. */ | |
6508 | hold_mips_optimize = mips_optimize; | |
6509 | mips_optimize = 2; | |
beae10d5 | 6510 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6511 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6512 | coproc ? treg : treg + 1, | |
6513 | (int) BFD_RELOC_LO16, AT); | |
6514 | mips_optimize = hold_mips_optimize; | |
6515 | ||
6516 | (void) frag_var (rs_machine_dependent, 0, 0, | |
6517 | RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0), | |
c4e7957c | 6518 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
6519 | } |
6520 | else if (mips_pic == SVR4_PIC) | |
6521 | { | |
6522 | int gpdel, off; | |
f9419b05 | 6523 | char *p; |
252b5132 RH |
6524 | |
6525 | /* If this is a reference to an external symbol, we want | |
6526 | lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
6527 | addu $at,$at,$gp | |
6528 | lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16) | |
6529 | nop | |
6530 | <op> $treg,0($at) | |
6531 | <op> $treg+1,4($at) | |
6532 | Otherwise we want | |
6533 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
6534 | nop | |
6535 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
6536 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
6537 | If there is a base register we add it to $at before the | |
6538 | lwc1 instructions. If there is a constant we include it | |
6539 | in the lwc1 instructions. */ | |
6540 | used_at = 1; | |
6541 | expr1.X_add_number = offset_expr.X_add_number; | |
6542 | offset_expr.X_add_number = 0; | |
6543 | if (expr1.X_add_number < -0x8000 | |
6544 | || expr1.X_add_number >= 0x8000 - 4) | |
6545 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
c9914766 | 6546 | if (reg_needs_delay (mips_gp_register)) |
252b5132 RH |
6547 | gpdel = 4; |
6548 | else | |
6549 | gpdel = 0; | |
6550 | if (breg == 0) | |
6551 | off = 0; | |
6552 | else | |
6553 | off = 4; | |
6554 | frag_grow (56); | |
6555 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
6556 | AT, (int) BFD_RELOC_MIPS_GOT_HI16); | |
6557 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6558 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
c9914766 | 6559 | "d,v,t", AT, AT, mips_gp_register); |
252b5132 | 6560 | macro_build ((char *) NULL, &icnt, &offset_expr, |
ca4e0257 | 6561 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
252b5132 RH |
6562 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT); |
6563 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
6564 | if (breg != 0) | |
6565 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6566 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 | 6567 | "d,v,t", AT, breg, AT); |
beae10d5 | 6568 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6569 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6570 | coproc ? treg + 1 : treg, | |
6571 | (int) BFD_RELOC_LO16, AT); | |
6572 | expr1.X_add_number += 4; | |
6573 | ||
6574 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6575 | nop. */ | |
6576 | hold_mips_optimize = mips_optimize; | |
6577 | mips_optimize = 2; | |
beae10d5 | 6578 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6579 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
6580 | coproc ? treg : treg + 1, | |
6581 | (int) BFD_RELOC_LO16, AT); | |
6582 | mips_optimize = hold_mips_optimize; | |
6583 | expr1.X_add_number -= 4; | |
6584 | ||
6585 | p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0, | |
6586 | RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel, | |
6587 | 8 + gpdel + off, 1, 0), | |
c4e7957c | 6588 | offset_expr.X_add_symbol, 0, NULL); |
252b5132 RH |
6589 | if (gpdel > 0) |
6590 | { | |
6591 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
6592 | p += 4; | |
6593 | } | |
6594 | macro_build (p, &icnt, &offset_expr, | |
ca4e0257 | 6595 | HAVE_32BIT_ADDRESSES ? "lw" : "ld", |
c9914766 TS |
6596 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, |
6597 | mips_gp_register); | |
252b5132 RH |
6598 | p += 4; |
6599 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
6600 | p += 4; | |
6601 | if (breg != 0) | |
6602 | { | |
6603 | macro_build (p, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6604 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
6605 | "d,v,t", AT, breg, AT); |
6606 | p += 4; | |
6607 | } | |
beae10d5 | 6608 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6609 | macro_build (p, &icnt, &expr1, s, fmt, |
6610 | coproc ? treg + 1 : treg, | |
6611 | (int) BFD_RELOC_LO16, AT); | |
6612 | p += 4; | |
6613 | expr1.X_add_number += 4; | |
6614 | ||
6615 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
6616 | nop. */ | |
6617 | hold_mips_optimize = mips_optimize; | |
6618 | mips_optimize = 2; | |
beae10d5 | 6619 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6620 | macro_build (p, &icnt, &expr1, s, fmt, |
6621 | coproc ? treg : treg + 1, | |
6622 | (int) BFD_RELOC_LO16, AT); | |
6623 | mips_optimize = hold_mips_optimize; | |
6624 | } | |
6625 | else if (mips_pic == EMBEDDED_PIC) | |
6626 | { | |
6627 | /* If there is no base register, we use | |
cdf6fd85 TS |
6628 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
6629 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16) | |
252b5132 RH |
6630 | If we have a base register, we use |
6631 | addu $at,$breg,$gp | |
cdf6fd85 TS |
6632 | <op> $treg,<sym>($at) (BFD_RELOC_GPREL16) |
6633 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16) | |
252b5132 RH |
6634 | */ |
6635 | if (breg == 0) | |
6636 | { | |
c9914766 | 6637 | tempreg = mips_gp_register; |
252b5132 RH |
6638 | used_at = 0; |
6639 | } | |
6640 | else | |
6641 | { | |
6642 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 6643 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
c9914766 | 6644 | "d,v,t", AT, breg, mips_gp_register); |
252b5132 RH |
6645 | tempreg = AT; |
6646 | used_at = 1; | |
6647 | } | |
6648 | ||
beae10d5 | 6649 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6650 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6651 | coproc ? treg + 1 : treg, | |
cdf6fd85 | 6652 | (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 | 6653 | offset_expr.X_add_number += 4; |
beae10d5 | 6654 | /* Itbl support may require additional care here. */ |
252b5132 RH |
6655 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
6656 | coproc ? treg : treg + 1, | |
cdf6fd85 | 6657 | (int) BFD_RELOC_GPREL16, tempreg); |
252b5132 RH |
6658 | } |
6659 | else | |
6660 | abort (); | |
6661 | ||
6662 | if (! used_at) | |
6663 | return; | |
6664 | ||
6665 | break; | |
6666 | ||
6667 | case M_LD_OB: | |
6668 | s = "lw"; | |
6669 | goto sd_ob; | |
6670 | case M_SD_OB: | |
6671 | s = "sw"; | |
6672 | sd_ob: | |
ca4e0257 | 6673 | assert (HAVE_32BIT_ADDRESSES); |
252b5132 RH |
6674 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, |
6675 | (int) BFD_RELOC_LO16, breg); | |
6676 | offset_expr.X_add_number += 4; | |
6677 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1, | |
6678 | (int) BFD_RELOC_LO16, breg); | |
6679 | return; | |
6680 | ||
6681 | /* New code added to support COPZ instructions. | |
6682 | This code builds table entries out of the macros in mip_opcodes. | |
6683 | R4000 uses interlocks to handle coproc delays. | |
6684 | Other chips (like the R3000) require nops to be inserted for delays. | |
6685 | ||
f72c8c98 | 6686 | FIXME: Currently, we require that the user handle delays. |
252b5132 RH |
6687 | In order to fill delay slots for non-interlocked chips, |
6688 | we must have a way to specify delays based on the coprocessor. | |
6689 | Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc. | |
6690 | What are the side-effects of the cop instruction? | |
6691 | What cache support might we have and what are its effects? | |
6692 | Both coprocessor & memory require delays. how long??? | |
bdaaa2e1 | 6693 | What registers are read/set/modified? |
252b5132 RH |
6694 | |
6695 | If an itbl is provided to interpret cop instructions, | |
bdaaa2e1 | 6696 | this knowledge can be encoded in the itbl spec. */ |
252b5132 RH |
6697 | |
6698 | case M_COP0: | |
6699 | s = "c0"; | |
6700 | goto copz; | |
6701 | case M_COP1: | |
6702 | s = "c1"; | |
6703 | goto copz; | |
6704 | case M_COP2: | |
6705 | s = "c2"; | |
6706 | goto copz; | |
6707 | case M_COP3: | |
6708 | s = "c3"; | |
6709 | copz: | |
6710 | /* For now we just do C (same as Cz). The parameter will be | |
6711 | stored in insn_opcode by mips_ip. */ | |
6712 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C", | |
6713 | ip->insn_opcode); | |
6714 | return; | |
6715 | ||
ea1fb5dc RS |
6716 | case M_MOVE: |
6717 | move_register (&icnt, dreg, sreg); | |
6718 | return; | |
6719 | ||
252b5132 RH |
6720 | #ifdef LOSING_COMPILER |
6721 | default: | |
6722 | /* Try and see if this is a new itbl instruction. | |
6723 | This code builds table entries out of the macros in mip_opcodes. | |
6724 | FIXME: For now we just assemble the expression and pass it's | |
6725 | value along as a 32-bit immediate. | |
bdaaa2e1 | 6726 | We may want to have the assembler assemble this value, |
252b5132 RH |
6727 | so that we gain the assembler's knowledge of delay slots, |
6728 | symbols, etc. | |
6729 | Would it be more efficient to use mask (id) here? */ | |
bdaaa2e1 | 6730 | if (itbl_have_entries |
252b5132 | 6731 | && (immed_expr = itbl_assemble (ip->insn_mo->name, ""))) |
beae10d5 | 6732 | { |
252b5132 RH |
6733 | s = ip->insn_mo->name; |
6734 | s2 = "cop3"; | |
6735 | coproc = ITBL_DECODE_PNUM (immed_expr);; | |
6736 | macro_build ((char *) NULL, &icnt, &immed_expr, s, "C"); | |
6737 | return; | |
beae10d5 | 6738 | } |
252b5132 RH |
6739 | macro2 (ip); |
6740 | return; | |
6741 | } | |
6742 | if (mips_opts.noat) | |
6743 | as_warn (_("Macro used $at after \".set noat\"")); | |
6744 | } | |
bdaaa2e1 | 6745 | |
252b5132 RH |
6746 | static void |
6747 | macro2 (ip) | |
6748 | struct mips_cl_insn *ip; | |
6749 | { | |
6750 | register int treg, sreg, dreg, breg; | |
6751 | int tempreg; | |
6752 | int mask; | |
6753 | int icnt = 0; | |
6754 | int used_at; | |
6755 | expressionS expr1; | |
6756 | const char *s; | |
6757 | const char *s2; | |
6758 | const char *fmt; | |
6759 | int likely = 0; | |
6760 | int dbl = 0; | |
6761 | int coproc = 0; | |
6762 | int lr = 0; | |
6763 | int imm = 0; | |
6764 | int off; | |
6765 | offsetT maxnum; | |
6766 | bfd_reloc_code_real_type r; | |
6767 | char *p; | |
bdaaa2e1 | 6768 | |
252b5132 RH |
6769 | treg = (ip->insn_opcode >> 16) & 0x1f; |
6770 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
6771 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
6772 | mask = ip->insn_mo->mask; | |
bdaaa2e1 | 6773 | |
252b5132 RH |
6774 | expr1.X_op = O_constant; |
6775 | expr1.X_op_symbol = NULL; | |
6776 | expr1.X_add_symbol = NULL; | |
6777 | expr1.X_add_number = 1; | |
bdaaa2e1 | 6778 | |
252b5132 RH |
6779 | switch (mask) |
6780 | { | |
6781 | #endif /* LOSING_COMPILER */ | |
6782 | ||
6783 | case M_DMUL: | |
6784 | dbl = 1; | |
6785 | case M_MUL: | |
2396cfb9 TS |
6786 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
6787 | dbl ? "dmultu" : "multu", "s,t", sreg, treg); | |
6788 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", | |
6789 | dreg); | |
252b5132 RH |
6790 | return; |
6791 | ||
6792 | case M_DMUL_I: | |
6793 | dbl = 1; | |
6794 | case M_MUL_I: | |
6795 | /* The MIPS assembler some times generates shifts and adds. I'm | |
6796 | not trying to be that fancy. GCC should do this for us | |
6797 | anyway. */ | |
6798 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 6799 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 6800 | dbl ? "dmult" : "mult", "s,t", sreg, AT); |
2396cfb9 TS |
6801 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", |
6802 | dreg); | |
252b5132 RH |
6803 | break; |
6804 | ||
6805 | case M_DMULO_I: | |
6806 | dbl = 1; | |
6807 | case M_MULO_I: | |
6808 | imm = 1; | |
6809 | goto do_mulo; | |
6810 | ||
6811 | case M_DMULO: | |
6812 | dbl = 1; | |
6813 | case M_MULO: | |
6814 | do_mulo: | |
6815 | mips_emit_delays (true); | |
6816 | ++mips_opts.noreorder; | |
6817 | mips_any_noreorder = 1; | |
6818 | if (imm) | |
6819 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 6820 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 6821 | dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg); |
2396cfb9 TS |
6822 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", |
6823 | dreg); | |
6824 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
f9419b05 | 6825 | dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA); |
2396cfb9 TS |
6826 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d", |
6827 | AT); | |
252b5132 | 6828 | if (mips_trap) |
9bd7d936 MR |
6829 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", |
6830 | "s,t,q", dreg, AT, 6); | |
252b5132 RH |
6831 | else |
6832 | { | |
6833 | expr1.X_add_number = 8; | |
2396cfb9 TS |
6834 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, |
6835 | AT); | |
6836 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "", | |
6837 | 0); | |
6838 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", | |
6839 | "c", 6); | |
252b5132 RH |
6840 | } |
6841 | --mips_opts.noreorder; | |
2396cfb9 | 6842 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg); |
252b5132 RH |
6843 | break; |
6844 | ||
6845 | case M_DMULOU_I: | |
6846 | dbl = 1; | |
6847 | case M_MULOU_I: | |
6848 | imm = 1; | |
6849 | goto do_mulou; | |
6850 | ||
6851 | case M_DMULOU: | |
6852 | dbl = 1; | |
6853 | case M_MULOU: | |
6854 | do_mulou: | |
6855 | mips_emit_delays (true); | |
6856 | ++mips_opts.noreorder; | |
6857 | mips_any_noreorder = 1; | |
6858 | if (imm) | |
6859 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 6860 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
252b5132 RH |
6861 | dbl ? "dmultu" : "multu", |
6862 | "s,t", sreg, imm ? AT : treg); | |
2396cfb9 TS |
6863 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d", |
6864 | AT); | |
6865 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", | |
6866 | dreg); | |
252b5132 | 6867 | if (mips_trap) |
9bd7d936 MR |
6868 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", |
6869 | "s,t,q", AT, 0, 6); | |
252b5132 RH |
6870 | else |
6871 | { | |
6872 | expr1.X_add_number = 8; | |
6873 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0); | |
2396cfb9 TS |
6874 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "", |
6875 | 0); | |
6876 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", | |
6877 | "c", 6); | |
252b5132 RH |
6878 | } |
6879 | --mips_opts.noreorder; | |
6880 | break; | |
6881 | ||
771c7ce4 TS |
6882 | case M_DROL: |
6883 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu", | |
6884 | "d,v,t", AT, 0, treg); | |
6885 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv", | |
6886 | "d,t,s", AT, sreg, AT); | |
6887 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv", | |
6888 | "d,t,s", dreg, sreg, treg); | |
6889 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
6890 | "d,v,t", dreg, dreg, AT); | |
6891 | break; | |
6892 | ||
252b5132 | 6893 | case M_ROL: |
2396cfb9 TS |
6894 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu", |
6895 | "d,v,t", AT, 0, treg); | |
6896 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv", | |
6897 | "d,t,s", AT, sreg, AT); | |
6898 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv", | |
6899 | "d,t,s", dreg, sreg, treg); | |
6900 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
6901 | "d,v,t", dreg, dreg, AT); | |
252b5132 RH |
6902 | break; |
6903 | ||
771c7ce4 TS |
6904 | case M_DROL_I: |
6905 | { | |
6906 | unsigned int rot; | |
771c7ce4 TS |
6907 | |
6908 | if (imm_expr.X_op != O_constant) | |
6909 | as_bad (_("rotate count too large")); | |
6910 | rot = imm_expr.X_add_number & 0x3f; | |
60b63b72 RS |
6911 | if (CPU_HAS_DROR (mips_arch)) |
6912 | { | |
6913 | rot = (64 - rot) & 0x3f; | |
6914 | if (rot >= 32) | |
6915 | macro_build ((char *) NULL, &icnt, NULL, "dror32", | |
6916 | "d,w,<", dreg, sreg, rot - 32); | |
6917 | else | |
6918 | macro_build ((char *) NULL, &icnt, NULL, "dror", | |
6919 | "d,w,<", dreg, sreg, rot); | |
6920 | break; | |
6921 | } | |
483fc7cd RS |
6922 | if (rot == 0) |
6923 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrl", | |
6924 | "d,w,<", dreg, sreg, 0); | |
6925 | else | |
6926 | { | |
6927 | char *l, *r; | |
6928 | ||
6929 | l = (rot < 0x20) ? "dsll" : "dsll32"; | |
6930 | r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32"; | |
6931 | rot &= 0x1f; | |
6932 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l, | |
6933 | "d,w,<", AT, sreg, rot); | |
6934 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r, | |
6935 | "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f); | |
6936 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
6937 | "d,v,t", dreg, dreg, AT); | |
6938 | } | |
771c7ce4 TS |
6939 | } |
6940 | break; | |
6941 | ||
252b5132 | 6942 | case M_ROL_I: |
771c7ce4 TS |
6943 | { |
6944 | unsigned int rot; | |
6945 | ||
6946 | if (imm_expr.X_op != O_constant) | |
6947 | as_bad (_("rotate count too large")); | |
6948 | rot = imm_expr.X_add_number & 0x1f; | |
60b63b72 RS |
6949 | if (CPU_HAS_ROR (mips_arch)) |
6950 | { | |
6951 | macro_build ((char *) NULL, &icnt, NULL, "ror", | |
6952 | "d,w,<", dreg, sreg, (32 - rot) & 0x1f); | |
6953 | break; | |
6954 | } | |
483fc7cd RS |
6955 | if (rot == 0) |
6956 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", | |
6957 | "d,w,<", dreg, sreg, 0); | |
6958 | else | |
6959 | { | |
6960 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", | |
6961 | "d,w,<", AT, sreg, rot); | |
6962 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", | |
6963 | "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f); | |
6964 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
6965 | "d,v,t", dreg, dreg, AT); | |
6966 | } | |
771c7ce4 TS |
6967 | } |
6968 | break; | |
6969 | ||
6970 | case M_DROR: | |
6971 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu", | |
6972 | "d,v,t", AT, 0, treg); | |
6973 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv", | |
6974 | "d,t,s", AT, sreg, AT); | |
6975 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv", | |
6976 | "d,t,s", dreg, sreg, treg); | |
6977 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
6978 | "d,v,t", dreg, dreg, AT); | |
252b5132 RH |
6979 | break; |
6980 | ||
6981 | case M_ROR: | |
2396cfb9 TS |
6982 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu", |
6983 | "d,v,t", AT, 0, treg); | |
6984 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv", | |
6985 | "d,t,s", AT, sreg, AT); | |
6986 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv", | |
6987 | "d,t,s", dreg, sreg, treg); | |
6988 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
6989 | "d,v,t", dreg, dreg, AT); | |
252b5132 RH |
6990 | break; |
6991 | ||
771c7ce4 TS |
6992 | case M_DROR_I: |
6993 | { | |
6994 | unsigned int rot; | |
771c7ce4 TS |
6995 | |
6996 | if (imm_expr.X_op != O_constant) | |
6997 | as_bad (_("rotate count too large")); | |
6998 | rot = imm_expr.X_add_number & 0x3f; | |
483fc7cd RS |
6999 | if (rot == 0) |
7000 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrl", | |
7001 | "d,w,<", dreg, sreg, 0); | |
7002 | else | |
7003 | { | |
7004 | char *l, *r; | |
7005 | ||
7006 | r = (rot < 0x20) ? "dsrl" : "dsrl32"; | |
7007 | l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32"; | |
7008 | rot &= 0x1f; | |
7009 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r, | |
7010 | "d,w,<", AT, sreg, rot); | |
7011 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l, | |
7012 | "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f); | |
7013 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
7014 | "d,v,t", dreg, dreg, AT); | |
7015 | } | |
771c7ce4 TS |
7016 | } |
7017 | break; | |
7018 | ||
252b5132 | 7019 | case M_ROR_I: |
771c7ce4 TS |
7020 | { |
7021 | unsigned int rot; | |
7022 | ||
7023 | if (imm_expr.X_op != O_constant) | |
7024 | as_bad (_("rotate count too large")); | |
7025 | rot = imm_expr.X_add_number & 0x1f; | |
483fc7cd RS |
7026 | if (rot == 0) |
7027 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", | |
7028 | "d,w,<", dreg, sreg, 0); | |
7029 | else | |
7030 | { | |
7031 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", | |
7032 | "d,w,<", AT, sreg, rot); | |
7033 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", | |
7034 | "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f); | |
7035 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", | |
7036 | "d,v,t", dreg, dreg, AT); | |
7037 | } | |
771c7ce4 | 7038 | } |
252b5132 RH |
7039 | break; |
7040 | ||
7041 | case M_S_DOB: | |
ec68c924 | 7042 | if (mips_arch == CPU_R4650) |
252b5132 RH |
7043 | { |
7044 | as_bad (_("opcode not supported on this processor")); | |
7045 | return; | |
7046 | } | |
e7af610e | 7047 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
7048 | /* Even on a big endian machine $fn comes before $fn+1. We have |
7049 | to adjust when storing to memory. */ | |
7050 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
7051 | target_big_endian ? treg + 1 : treg, | |
7052 | (int) BFD_RELOC_LO16, breg); | |
7053 | offset_expr.X_add_number += 4; | |
7054 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
7055 | target_big_endian ? treg : treg + 1, | |
7056 | (int) BFD_RELOC_LO16, breg); | |
7057 | return; | |
7058 | ||
7059 | case M_SEQ: | |
7060 | if (sreg == 0) | |
7061 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
7062 | treg, (int) BFD_RELOC_LO16); | |
7063 | else if (treg == 0) | |
7064 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
7065 | sreg, (int) BFD_RELOC_LO16); | |
7066 | else | |
7067 | { | |
2396cfb9 TS |
7068 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor", |
7069 | "d,v,t", dreg, sreg, treg); | |
252b5132 RH |
7070 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, |
7071 | dreg, (int) BFD_RELOC_LO16); | |
7072 | } | |
7073 | return; | |
7074 | ||
7075 | case M_SEQ_I: | |
7076 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
7077 | { | |
7078 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
7079 | sreg, (int) BFD_RELOC_LO16); | |
7080 | return; | |
7081 | } | |
7082 | if (sreg == 0) | |
7083 | { | |
7084 | as_warn (_("Instruction %s: result is always false"), | |
7085 | ip->insn_mo->name); | |
ea1fb5dc | 7086 | move_register (&icnt, dreg, 0); |
252b5132 RH |
7087 | return; |
7088 | } | |
7089 | if (imm_expr.X_op == O_constant | |
7090 | && imm_expr.X_add_number >= 0 | |
7091 | && imm_expr.X_add_number < 0x10000) | |
7092 | { | |
7093 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, | |
7094 | sreg, (int) BFD_RELOC_LO16); | |
7095 | used_at = 0; | |
7096 | } | |
7097 | else if (imm_expr.X_op == O_constant | |
7098 | && imm_expr.X_add_number > -0x8000 | |
7099 | && imm_expr.X_add_number < 0) | |
7100 | { | |
7101 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7102 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
ca4e0257 | 7103 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
7104 | "t,r,j", dreg, sreg, |
7105 | (int) BFD_RELOC_LO16); | |
7106 | used_at = 0; | |
7107 | } | |
7108 | else | |
7109 | { | |
4d34fb5f | 7110 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
7111 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor", |
7112 | "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
7113 | used_at = 1; |
7114 | } | |
7115 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg, | |
7116 | (int) BFD_RELOC_LO16); | |
7117 | if (used_at) | |
7118 | break; | |
7119 | return; | |
7120 | ||
7121 | case M_SGE: /* sreg >= treg <==> not (sreg < treg) */ | |
7122 | s = "slt"; | |
7123 | goto sge; | |
7124 | case M_SGEU: | |
7125 | s = "sltu"; | |
7126 | sge: | |
2396cfb9 TS |
7127 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
7128 | dreg, sreg, treg); | |
252b5132 RH |
7129 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, |
7130 | (int) BFD_RELOC_LO16); | |
7131 | return; | |
7132 | ||
7133 | case M_SGE_I: /* sreg >= I <==> not (sreg < I) */ | |
7134 | case M_SGEU_I: | |
7135 | if (imm_expr.X_op == O_constant | |
7136 | && imm_expr.X_add_number >= -0x8000 | |
7137 | && imm_expr.X_add_number < 0x8000) | |
7138 | { | |
7139 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
7140 | mask == M_SGE_I ? "slti" : "sltiu", | |
7141 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
7142 | used_at = 0; | |
7143 | } | |
7144 | else | |
7145 | { | |
4d34fb5f | 7146 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
7147 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
7148 | mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg, | |
7149 | AT); | |
252b5132 RH |
7150 | used_at = 1; |
7151 | } | |
7152 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
7153 | (int) BFD_RELOC_LO16); | |
7154 | if (used_at) | |
7155 | break; | |
7156 | return; | |
7157 | ||
7158 | case M_SGT: /* sreg > treg <==> treg < sreg */ | |
7159 | s = "slt"; | |
7160 | goto sgt; | |
7161 | case M_SGTU: | |
7162 | s = "sltu"; | |
7163 | sgt: | |
2396cfb9 TS |
7164 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
7165 | dreg, treg, sreg); | |
252b5132 RH |
7166 | return; |
7167 | ||
7168 | case M_SGT_I: /* sreg > I <==> I < sreg */ | |
7169 | s = "slt"; | |
7170 | goto sgti; | |
7171 | case M_SGTU_I: | |
7172 | s = "sltu"; | |
7173 | sgti: | |
4d34fb5f | 7174 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
7175 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
7176 | dreg, AT, sreg); | |
252b5132 RH |
7177 | break; |
7178 | ||
2396cfb9 | 7179 | case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */ |
252b5132 RH |
7180 | s = "slt"; |
7181 | goto sle; | |
7182 | case M_SLEU: | |
7183 | s = "sltu"; | |
7184 | sle: | |
2396cfb9 TS |
7185 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
7186 | dreg, treg, sreg); | |
252b5132 RH |
7187 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, |
7188 | (int) BFD_RELOC_LO16); | |
7189 | return; | |
7190 | ||
2396cfb9 | 7191 | case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */ |
252b5132 RH |
7192 | s = "slt"; |
7193 | goto slei; | |
7194 | case M_SLEU_I: | |
7195 | s = "sltu"; | |
7196 | slei: | |
4d34fb5f | 7197 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
7198 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t", |
7199 | dreg, AT, sreg); | |
252b5132 RH |
7200 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, |
7201 | (int) BFD_RELOC_LO16); | |
7202 | break; | |
7203 | ||
7204 | case M_SLT_I: | |
7205 | if (imm_expr.X_op == O_constant | |
7206 | && imm_expr.X_add_number >= -0x8000 | |
7207 | && imm_expr.X_add_number < 0x8000) | |
7208 | { | |
7209 | macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j", | |
7210 | dreg, sreg, (int) BFD_RELOC_LO16); | |
7211 | return; | |
7212 | } | |
4d34fb5f | 7213 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
7214 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t", |
7215 | dreg, sreg, AT); | |
252b5132 RH |
7216 | break; |
7217 | ||
7218 | case M_SLTU_I: | |
7219 | if (imm_expr.X_op == O_constant | |
7220 | && imm_expr.X_add_number >= -0x8000 | |
7221 | && imm_expr.X_add_number < 0x8000) | |
7222 | { | |
7223 | macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j", | |
7224 | dreg, sreg, (int) BFD_RELOC_LO16); | |
7225 | return; | |
7226 | } | |
4d34fb5f | 7227 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
7228 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
7229 | "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
7230 | break; |
7231 | ||
7232 | case M_SNE: | |
7233 | if (sreg == 0) | |
2396cfb9 TS |
7234 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
7235 | "d,v,t", dreg, 0, treg); | |
252b5132 | 7236 | else if (treg == 0) |
2396cfb9 TS |
7237 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
7238 | "d,v,t", dreg, 0, sreg); | |
252b5132 RH |
7239 | else |
7240 | { | |
2396cfb9 TS |
7241 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor", |
7242 | "d,v,t", dreg, sreg, treg); | |
7243 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", | |
7244 | "d,v,t", dreg, 0, dreg); | |
252b5132 RH |
7245 | } |
7246 | return; | |
7247 | ||
7248 | case M_SNE_I: | |
7249 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
7250 | { | |
2396cfb9 TS |
7251 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
7252 | "d,v,t", dreg, 0, sreg); | |
252b5132 RH |
7253 | return; |
7254 | } | |
7255 | if (sreg == 0) | |
7256 | { | |
7257 | as_warn (_("Instruction %s: result is always true"), | |
7258 | ip->insn_mo->name); | |
7259 | macro_build ((char *) NULL, &icnt, &expr1, | |
ca4e0257 | 7260 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
7261 | "t,r,j", dreg, 0, (int) BFD_RELOC_LO16); |
7262 | return; | |
7263 | } | |
7264 | if (imm_expr.X_op == O_constant | |
7265 | && imm_expr.X_add_number >= 0 | |
7266 | && imm_expr.X_add_number < 0x10000) | |
7267 | { | |
7268 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", | |
7269 | dreg, sreg, (int) BFD_RELOC_LO16); | |
7270 | used_at = 0; | |
7271 | } | |
7272 | else if (imm_expr.X_op == O_constant | |
7273 | && imm_expr.X_add_number > -0x8000 | |
7274 | && imm_expr.X_add_number < 0) | |
7275 | { | |
7276 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7277 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
ca4e0257 | 7278 | HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
252b5132 RH |
7279 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); |
7280 | used_at = 0; | |
7281 | } | |
7282 | else | |
7283 | { | |
4d34fb5f | 7284 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
7285 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor", |
7286 | "d,v,t", dreg, sreg, AT); | |
252b5132 RH |
7287 | used_at = 1; |
7288 | } | |
2396cfb9 TS |
7289 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu", |
7290 | "d,v,t", dreg, 0, dreg); | |
252b5132 RH |
7291 | if (used_at) |
7292 | break; | |
7293 | return; | |
7294 | ||
7295 | case M_DSUB_I: | |
7296 | dbl = 1; | |
7297 | case M_SUB_I: | |
7298 | if (imm_expr.X_op == O_constant | |
7299 | && imm_expr.X_add_number > -0x8000 | |
7300 | && imm_expr.X_add_number <= 0x8000) | |
7301 | { | |
7302 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7303 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
7304 | dbl ? "daddi" : "addi", | |
7305 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
7306 | return; | |
7307 | } | |
7308 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 7309 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 7310 | dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT); |
252b5132 RH |
7311 | break; |
7312 | ||
7313 | case M_DSUBU_I: | |
7314 | dbl = 1; | |
7315 | case M_SUBU_I: | |
7316 | if (imm_expr.X_op == O_constant | |
7317 | && imm_expr.X_add_number > -0x8000 | |
7318 | && imm_expr.X_add_number <= 0x8000) | |
7319 | { | |
7320 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7321 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
7322 | dbl ? "daddiu" : "addiu", | |
7323 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
7324 | return; | |
7325 | } | |
7326 | load_register (&icnt, AT, &imm_expr, dbl); | |
2396cfb9 | 7327 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 7328 | dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT); |
252b5132 RH |
7329 | break; |
7330 | ||
7331 | case M_TEQ_I: | |
7332 | s = "teq"; | |
7333 | goto trap; | |
7334 | case M_TGE_I: | |
7335 | s = "tge"; | |
7336 | goto trap; | |
7337 | case M_TGEU_I: | |
7338 | s = "tgeu"; | |
7339 | goto trap; | |
7340 | case M_TLT_I: | |
7341 | s = "tlt"; | |
7342 | goto trap; | |
7343 | case M_TLTU_I: | |
7344 | s = "tltu"; | |
7345 | goto trap; | |
7346 | case M_TNE_I: | |
7347 | s = "tne"; | |
7348 | trap: | |
4d34fb5f | 7349 | load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS); |
2396cfb9 TS |
7350 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg, |
7351 | AT); | |
252b5132 RH |
7352 | break; |
7353 | ||
252b5132 | 7354 | case M_TRUNCWS: |
43841e91 | 7355 | case M_TRUNCWD: |
e7af610e | 7356 | assert (mips_opts.isa == ISA_MIPS1); |
252b5132 RH |
7357 | sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */ |
7358 | dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */ | |
7359 | ||
7360 | /* | |
7361 | * Is the double cfc1 instruction a bug in the mips assembler; | |
7362 | * or is there a reason for it? | |
7363 | */ | |
7364 | mips_emit_delays (true); | |
7365 | ++mips_opts.noreorder; | |
7366 | mips_any_noreorder = 1; | |
2396cfb9 | 7367 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G", |
f9419b05 | 7368 | treg, RA); |
2396cfb9 | 7369 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G", |
f9419b05 | 7370 | treg, RA); |
2396cfb9 | 7371 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); |
252b5132 RH |
7372 | expr1.X_add_number = 3; |
7373 | macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg, | |
7374 | (int) BFD_RELOC_LO16); | |
7375 | expr1.X_add_number = 2; | |
7376 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT, | |
7377 | (int) BFD_RELOC_LO16); | |
2396cfb9 | 7378 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G", |
f9419b05 | 7379 | AT, RA); |
2396cfb9 TS |
7380 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); |
7381 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
252b5132 | 7382 | mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg); |
2396cfb9 | 7383 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G", |
f9419b05 | 7384 | treg, RA); |
2396cfb9 | 7385 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); |
252b5132 RH |
7386 | --mips_opts.noreorder; |
7387 | break; | |
7388 | ||
7389 | case M_ULH: | |
7390 | s = "lb"; | |
7391 | goto ulh; | |
7392 | case M_ULHU: | |
7393 | s = "lbu"; | |
7394 | ulh: | |
7395 | if (offset_expr.X_add_number >= 0x7fff) | |
7396 | as_bad (_("operand overflow")); | |
7397 | /* avoid load delay */ | |
7398 | if (! target_big_endian) | |
f9419b05 | 7399 | ++offset_expr.X_add_number; |
252b5132 RH |
7400 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, |
7401 | (int) BFD_RELOC_LO16, breg); | |
7402 | if (! target_big_endian) | |
f9419b05 | 7403 | --offset_expr.X_add_number; |
252b5132 | 7404 | else |
f9419b05 | 7405 | ++offset_expr.X_add_number; |
252b5132 RH |
7406 | macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT, |
7407 | (int) BFD_RELOC_LO16, breg); | |
2396cfb9 TS |
7408 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<", |
7409 | treg, treg, 8); | |
7410 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t", | |
7411 | treg, treg, AT); | |
252b5132 RH |
7412 | break; |
7413 | ||
7414 | case M_ULD: | |
7415 | s = "ldl"; | |
7416 | s2 = "ldr"; | |
7417 | off = 7; | |
7418 | goto ulw; | |
7419 | case M_ULW: | |
7420 | s = "lwl"; | |
7421 | s2 = "lwr"; | |
7422 | off = 3; | |
7423 | ulw: | |
7424 | if (offset_expr.X_add_number >= 0x8000 - off) | |
7425 | as_bad (_("operand overflow")); | |
7426 | if (! target_big_endian) | |
7427 | offset_expr.X_add_number += off; | |
7428 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
7429 | (int) BFD_RELOC_LO16, breg); | |
7430 | if (! target_big_endian) | |
7431 | offset_expr.X_add_number -= off; | |
7432 | else | |
7433 | offset_expr.X_add_number += off; | |
7434 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
7435 | (int) BFD_RELOC_LO16, breg); | |
7436 | return; | |
7437 | ||
7438 | case M_ULD_A: | |
7439 | s = "ldl"; | |
7440 | s2 = "ldr"; | |
7441 | off = 7; | |
7442 | goto ulwa; | |
7443 | case M_ULW_A: | |
7444 | s = "lwl"; | |
7445 | s2 = "lwr"; | |
7446 | off = 3; | |
7447 | ulwa: | |
d6bc6245 | 7448 | used_at = 1; |
c9914766 | 7449 | load_address (&icnt, AT, &offset_expr, &used_at); |
252b5132 RH |
7450 | if (breg != 0) |
7451 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7452 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7453 | "d,v,t", AT, AT, breg); |
7454 | if (! target_big_endian) | |
7455 | expr1.X_add_number = off; | |
7456 | else | |
7457 | expr1.X_add_number = 0; | |
7458 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
7459 | (int) BFD_RELOC_LO16, AT); | |
7460 | if (! target_big_endian) | |
7461 | expr1.X_add_number = 0; | |
7462 | else | |
7463 | expr1.X_add_number = off; | |
7464 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
7465 | (int) BFD_RELOC_LO16, AT); | |
7466 | break; | |
7467 | ||
7468 | case M_ULH_A: | |
7469 | case M_ULHU_A: | |
d6bc6245 | 7470 | used_at = 1; |
c9914766 | 7471 | load_address (&icnt, AT, &offset_expr, &used_at); |
252b5132 RH |
7472 | if (breg != 0) |
7473 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7474 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7475 | "d,v,t", AT, AT, breg); |
7476 | if (target_big_endian) | |
7477 | expr1.X_add_number = 0; | |
7478 | macro_build ((char *) NULL, &icnt, &expr1, | |
7479 | mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg, | |
7480 | (int) BFD_RELOC_LO16, AT); | |
7481 | if (target_big_endian) | |
7482 | expr1.X_add_number = 1; | |
7483 | else | |
7484 | expr1.X_add_number = 0; | |
7485 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
7486 | (int) BFD_RELOC_LO16, AT); | |
2396cfb9 TS |
7487 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<", |
7488 | treg, treg, 8); | |
7489 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t", | |
7490 | treg, treg, AT); | |
252b5132 RH |
7491 | break; |
7492 | ||
7493 | case M_USH: | |
7494 | if (offset_expr.X_add_number >= 0x7fff) | |
7495 | as_bad (_("operand overflow")); | |
7496 | if (target_big_endian) | |
f9419b05 | 7497 | ++offset_expr.X_add_number; |
252b5132 RH |
7498 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg, |
7499 | (int) BFD_RELOC_LO16, breg); | |
2396cfb9 TS |
7500 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<", |
7501 | AT, treg, 8); | |
252b5132 | 7502 | if (target_big_endian) |
f9419b05 | 7503 | --offset_expr.X_add_number; |
252b5132 | 7504 | else |
f9419b05 | 7505 | ++offset_expr.X_add_number; |
252b5132 RH |
7506 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT, |
7507 | (int) BFD_RELOC_LO16, breg); | |
7508 | break; | |
7509 | ||
7510 | case M_USD: | |
7511 | s = "sdl"; | |
7512 | s2 = "sdr"; | |
7513 | off = 7; | |
7514 | goto usw; | |
7515 | case M_USW: | |
7516 | s = "swl"; | |
7517 | s2 = "swr"; | |
7518 | off = 3; | |
7519 | usw: | |
7520 | if (offset_expr.X_add_number >= 0x8000 - off) | |
7521 | as_bad (_("operand overflow")); | |
7522 | if (! target_big_endian) | |
7523 | offset_expr.X_add_number += off; | |
7524 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
7525 | (int) BFD_RELOC_LO16, breg); | |
7526 | if (! target_big_endian) | |
7527 | offset_expr.X_add_number -= off; | |
7528 | else | |
7529 | offset_expr.X_add_number += off; | |
7530 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
7531 | (int) BFD_RELOC_LO16, breg); | |
7532 | return; | |
7533 | ||
7534 | case M_USD_A: | |
7535 | s = "sdl"; | |
7536 | s2 = "sdr"; | |
7537 | off = 7; | |
7538 | goto uswa; | |
7539 | case M_USW_A: | |
7540 | s = "swl"; | |
7541 | s2 = "swr"; | |
7542 | off = 3; | |
7543 | uswa: | |
d6bc6245 | 7544 | used_at = 1; |
c9914766 | 7545 | load_address (&icnt, AT, &offset_expr, &used_at); |
252b5132 RH |
7546 | if (breg != 0) |
7547 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7548 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7549 | "d,v,t", AT, AT, breg); |
7550 | if (! target_big_endian) | |
7551 | expr1.X_add_number = off; | |
7552 | else | |
7553 | expr1.X_add_number = 0; | |
7554 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
7555 | (int) BFD_RELOC_LO16, AT); | |
7556 | if (! target_big_endian) | |
7557 | expr1.X_add_number = 0; | |
7558 | else | |
7559 | expr1.X_add_number = off; | |
7560 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
7561 | (int) BFD_RELOC_LO16, AT); | |
7562 | break; | |
7563 | ||
7564 | case M_USH_A: | |
d6bc6245 | 7565 | used_at = 1; |
c9914766 | 7566 | load_address (&icnt, AT, &offset_expr, &used_at); |
252b5132 RH |
7567 | if (breg != 0) |
7568 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 7569 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
252b5132 RH |
7570 | "d,v,t", AT, AT, breg); |
7571 | if (! target_big_endian) | |
7572 | expr1.X_add_number = 0; | |
7573 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
7574 | (int) BFD_RELOC_LO16, AT); | |
2396cfb9 TS |
7575 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<", |
7576 | treg, treg, 8); | |
252b5132 RH |
7577 | if (! target_big_endian) |
7578 | expr1.X_add_number = 1; | |
7579 | else | |
7580 | expr1.X_add_number = 0; | |
7581 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
7582 | (int) BFD_RELOC_LO16, AT); | |
7583 | if (! target_big_endian) | |
7584 | expr1.X_add_number = 0; | |
7585 | else | |
7586 | expr1.X_add_number = 1; | |
7587 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
7588 | (int) BFD_RELOC_LO16, AT); | |
2396cfb9 TS |
7589 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<", |
7590 | treg, treg, 8); | |
7591 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t", | |
7592 | treg, treg, AT); | |
252b5132 RH |
7593 | break; |
7594 | ||
7595 | default: | |
7596 | /* FIXME: Check if this is one of the itbl macros, since they | |
bdaaa2e1 | 7597 | are added dynamically. */ |
252b5132 RH |
7598 | as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name); |
7599 | break; | |
7600 | } | |
7601 | if (mips_opts.noat) | |
7602 | as_warn (_("Macro used $at after \".set noat\"")); | |
7603 | } | |
7604 | ||
7605 | /* Implement macros in mips16 mode. */ | |
7606 | ||
7607 | static void | |
7608 | mips16_macro (ip) | |
7609 | struct mips_cl_insn *ip; | |
7610 | { | |
7611 | int mask; | |
7612 | int xreg, yreg, zreg, tmp; | |
7613 | int icnt; | |
7614 | expressionS expr1; | |
7615 | int dbl; | |
7616 | const char *s, *s2, *s3; | |
7617 | ||
7618 | mask = ip->insn_mo->mask; | |
7619 | ||
7620 | xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX; | |
7621 | yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY; | |
7622 | zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ; | |
7623 | ||
7624 | icnt = 0; | |
7625 | ||
7626 | expr1.X_op = O_constant; | |
7627 | expr1.X_op_symbol = NULL; | |
7628 | expr1.X_add_symbol = NULL; | |
7629 | expr1.X_add_number = 1; | |
7630 | ||
7631 | dbl = 0; | |
7632 | ||
7633 | switch (mask) | |
7634 | { | |
7635 | default: | |
7636 | internalError (); | |
7637 | ||
7638 | case M_DDIV_3: | |
7639 | dbl = 1; | |
7640 | case M_DIV_3: | |
7641 | s = "mflo"; | |
7642 | goto do_div3; | |
7643 | case M_DREM_3: | |
7644 | dbl = 1; | |
7645 | case M_REM_3: | |
7646 | s = "mfhi"; | |
7647 | do_div3: | |
7648 | mips_emit_delays (true); | |
7649 | ++mips_opts.noreorder; | |
7650 | mips_any_noreorder = 1; | |
2396cfb9 | 7651 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
252b5132 RH |
7652 | dbl ? "ddiv" : "div", |
7653 | "0,x,y", xreg, yreg); | |
7654 | expr1.X_add_number = 2; | |
7655 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
2396cfb9 TS |
7656 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6", |
7657 | 7); | |
bdaaa2e1 | 7658 | |
252b5132 RH |
7659 | /* FIXME: The normal code checks for of -1 / -0x80000000 here, |
7660 | since that causes an overflow. We should do that as well, | |
7661 | but I don't see how to do the comparisons without a temporary | |
7662 | register. */ | |
7663 | --mips_opts.noreorder; | |
2396cfb9 | 7664 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg); |
252b5132 RH |
7665 | break; |
7666 | ||
7667 | case M_DIVU_3: | |
7668 | s = "divu"; | |
7669 | s2 = "mflo"; | |
7670 | goto do_divu3; | |
7671 | case M_REMU_3: | |
7672 | s = "divu"; | |
7673 | s2 = "mfhi"; | |
7674 | goto do_divu3; | |
7675 | case M_DDIVU_3: | |
7676 | s = "ddivu"; | |
7677 | s2 = "mflo"; | |
7678 | goto do_divu3; | |
7679 | case M_DREMU_3: | |
7680 | s = "ddivu"; | |
7681 | s2 = "mfhi"; | |
7682 | do_divu3: | |
7683 | mips_emit_delays (true); | |
7684 | ++mips_opts.noreorder; | |
7685 | mips_any_noreorder = 1; | |
2396cfb9 TS |
7686 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y", |
7687 | xreg, yreg); | |
252b5132 RH |
7688 | expr1.X_add_number = 2; |
7689 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
98d3f06f KH |
7690 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", |
7691 | "6", 7); | |
252b5132 | 7692 | --mips_opts.noreorder; |
2396cfb9 | 7693 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg); |
252b5132 RH |
7694 | break; |
7695 | ||
7696 | case M_DMUL: | |
7697 | dbl = 1; | |
7698 | case M_MUL: | |
2396cfb9 | 7699 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
9a41af64 | 7700 | dbl ? "dmultu" : "multu", "x,y", xreg, yreg); |
2396cfb9 TS |
7701 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x", |
7702 | zreg); | |
252b5132 RH |
7703 | return; |
7704 | ||
7705 | case M_DSUBU_I: | |
7706 | dbl = 1; | |
7707 | goto do_subu; | |
7708 | case M_SUBU_I: | |
7709 | do_subu: | |
7710 | if (imm_expr.X_op != O_constant) | |
7711 | as_bad (_("Unsupported large constant")); | |
7712 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7713 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
9a41af64 | 7714 | dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg); |
252b5132 RH |
7715 | break; |
7716 | ||
7717 | case M_SUBU_I_2: | |
7718 | if (imm_expr.X_op != O_constant) | |
7719 | as_bad (_("Unsupported large constant")); | |
7720 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7721 | macro_build ((char *) NULL, &icnt, &imm_expr, "addiu", | |
7722 | "x,k", xreg); | |
7723 | break; | |
7724 | ||
7725 | case M_DSUBU_I_2: | |
7726 | if (imm_expr.X_op != O_constant) | |
7727 | as_bad (_("Unsupported large constant")); | |
7728 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
7729 | macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu", | |
7730 | "y,j", yreg); | |
7731 | break; | |
7732 | ||
7733 | case M_BEQ: | |
7734 | s = "cmp"; | |
7735 | s2 = "bteqz"; | |
7736 | goto do_branch; | |
7737 | case M_BNE: | |
7738 | s = "cmp"; | |
7739 | s2 = "btnez"; | |
7740 | goto do_branch; | |
7741 | case M_BLT: | |
7742 | s = "slt"; | |
7743 | s2 = "btnez"; | |
7744 | goto do_branch; | |
7745 | case M_BLTU: | |
7746 | s = "sltu"; | |
7747 | s2 = "btnez"; | |
7748 | goto do_branch; | |
7749 | case M_BLE: | |
7750 | s = "slt"; | |
7751 | s2 = "bteqz"; | |
7752 | goto do_reverse_branch; | |
7753 | case M_BLEU: | |
7754 | s = "sltu"; | |
7755 | s2 = "bteqz"; | |
7756 | goto do_reverse_branch; | |
7757 | case M_BGE: | |
7758 | s = "slt"; | |
7759 | s2 = "bteqz"; | |
7760 | goto do_branch; | |
7761 | case M_BGEU: | |
7762 | s = "sltu"; | |
7763 | s2 = "bteqz"; | |
7764 | goto do_branch; | |
7765 | case M_BGT: | |
7766 | s = "slt"; | |
7767 | s2 = "btnez"; | |
7768 | goto do_reverse_branch; | |
7769 | case M_BGTU: | |
7770 | s = "sltu"; | |
7771 | s2 = "btnez"; | |
7772 | ||
7773 | do_reverse_branch: | |
7774 | tmp = xreg; | |
7775 | xreg = yreg; | |
7776 | yreg = tmp; | |
7777 | ||
7778 | do_branch: | |
7779 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y", | |
7780 | xreg, yreg); | |
7781 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
7782 | break; | |
7783 | ||
7784 | case M_BEQ_I: | |
7785 | s = "cmpi"; | |
7786 | s2 = "bteqz"; | |
7787 | s3 = "x,U"; | |
7788 | goto do_branch_i; | |
7789 | case M_BNE_I: | |
7790 | s = "cmpi"; | |
7791 | s2 = "btnez"; | |
7792 | s3 = "x,U"; | |
7793 | goto do_branch_i; | |
7794 | case M_BLT_I: | |
7795 | s = "slti"; | |
7796 | s2 = "btnez"; | |
7797 | s3 = "x,8"; | |
7798 | goto do_branch_i; | |
7799 | case M_BLTU_I: | |
7800 | s = "sltiu"; | |
7801 | s2 = "btnez"; | |
7802 | s3 = "x,8"; | |
7803 | goto do_branch_i; | |
7804 | case M_BLE_I: | |
7805 | s = "slti"; | |
7806 | s2 = "btnez"; | |
7807 | s3 = "x,8"; | |
7808 | goto do_addone_branch_i; | |
7809 | case M_BLEU_I: | |
7810 | s = "sltiu"; | |
7811 | s2 = "btnez"; | |
7812 | s3 = "x,8"; | |
7813 | goto do_addone_branch_i; | |
7814 | case M_BGE_I: | |
7815 | s = "slti"; | |
7816 | s2 = "bteqz"; | |
7817 | s3 = "x,8"; | |
7818 | goto do_branch_i; | |
7819 | case M_BGEU_I: | |
7820 | s = "sltiu"; | |
7821 | s2 = "bteqz"; | |
7822 | s3 = "x,8"; | |
7823 | goto do_branch_i; | |
7824 | case M_BGT_I: | |
7825 | s = "slti"; | |
7826 | s2 = "bteqz"; | |
7827 | s3 = "x,8"; | |
7828 | goto do_addone_branch_i; | |
7829 | case M_BGTU_I: | |
7830 | s = "sltiu"; | |
7831 | s2 = "bteqz"; | |
7832 | s3 = "x,8"; | |
7833 | ||
7834 | do_addone_branch_i: | |
7835 | if (imm_expr.X_op != O_constant) | |
7836 | as_bad (_("Unsupported large constant")); | |
7837 | ++imm_expr.X_add_number; | |
7838 | ||
7839 | do_branch_i: | |
7840 | macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg); | |
7841 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
7842 | break; | |
7843 | ||
7844 | case M_ABS: | |
7845 | expr1.X_add_number = 0; | |
98d3f06f | 7846 | macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg); |
252b5132 | 7847 | if (xreg != yreg) |
ea1fb5dc | 7848 | move_register (&icnt, xreg, yreg); |
252b5132 RH |
7849 | expr1.X_add_number = 2; |
7850 | macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p"); | |
7851 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
7852 | "neg", "x,w", xreg, xreg); | |
7853 | } | |
7854 | } | |
7855 | ||
7856 | /* For consistency checking, verify that all bits are specified either | |
7857 | by the match/mask part of the instruction definition, or by the | |
7858 | operand list. */ | |
7859 | static int | |
7860 | validate_mips_insn (opc) | |
7861 | const struct mips_opcode *opc; | |
7862 | { | |
7863 | const char *p = opc->args; | |
7864 | char c; | |
7865 | unsigned long used_bits = opc->mask; | |
7866 | ||
7867 | if ((used_bits & opc->match) != opc->match) | |
7868 | { | |
7869 | as_bad (_("internal: bad mips opcode (mask error): %s %s"), | |
7870 | opc->name, opc->args); | |
7871 | return 0; | |
7872 | } | |
7873 | #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift))) | |
7874 | while (*p) | |
7875 | switch (c = *p++) | |
7876 | { | |
7877 | case ',': break; | |
7878 | case '(': break; | |
7879 | case ')': break; | |
7880 | case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
7881 | case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
7882 | case 'A': break; | |
4372b673 | 7883 | case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break; |
252b5132 RH |
7884 | case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break; |
7885 | case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break; | |
7886 | case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7887 | case 'F': break; | |
7888 | case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
156c2f8b | 7889 | case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
252b5132 | 7890 | case 'I': break; |
e972090a | 7891 | case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break; |
252b5132 RH |
7892 | case 'L': break; |
7893 | case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break; | |
7894 | case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break; | |
deec1734 CD |
7895 | case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break; |
7896 | case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL); | |
7897 | USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
252b5132 RH |
7898 | case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break; |
7899 | case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
7900 | case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
7901 | case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
7902 | case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
deec1734 CD |
7903 | case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break; |
7904 | case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
7905 | case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
252b5132 RH |
7906 | case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break; |
7907 | case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7908 | case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break; | |
7909 | case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
7910 | case 'f': break; | |
7911 | case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break; | |
7912 | case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
7913 | case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7914 | case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break; | |
7915 | case 'l': break; | |
7916 | case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7917 | case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7918 | case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break; | |
7919 | case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7920 | case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7921 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7922 | case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
7923 | case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7924 | case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7925 | case 'x': break; | |
7926 | case 'z': break; | |
7927 | case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break; | |
4372b673 NC |
7928 | case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD); |
7929 | USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
60b63b72 RS |
7930 | case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break; |
7931 | case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break; | |
7932 | case '[': break; | |
7933 | case ']': break; | |
252b5132 RH |
7934 | default: |
7935 | as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"), | |
7936 | c, opc->name, opc->args); | |
7937 | return 0; | |
7938 | } | |
7939 | #undef USE_BITS | |
7940 | if (used_bits != 0xffffffff) | |
7941 | { | |
7942 | as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"), | |
7943 | ~used_bits & 0xffffffff, opc->name, opc->args); | |
7944 | return 0; | |
7945 | } | |
7946 | return 1; | |
7947 | } | |
7948 | ||
7949 | /* This routine assembles an instruction into its binary format. As a | |
7950 | side effect, it sets one of the global variables imm_reloc or | |
7951 | offset_reloc to the type of relocation to do if one of the operands | |
7952 | is an address expression. */ | |
7953 | ||
7954 | static void | |
7955 | mips_ip (str, ip) | |
7956 | char *str; | |
7957 | struct mips_cl_insn *ip; | |
7958 | { | |
7959 | char *s; | |
7960 | const char *args; | |
43841e91 | 7961 | char c = 0; |
252b5132 RH |
7962 | struct mips_opcode *insn; |
7963 | char *argsStart; | |
7964 | unsigned int regno; | |
7965 | unsigned int lastregno = 0; | |
7966 | char *s_reset; | |
7967 | char save_c = 0; | |
252b5132 RH |
7968 | |
7969 | insn_error = NULL; | |
7970 | ||
7971 | /* If the instruction contains a '.', we first try to match an instruction | |
7972 | including the '.'. Then we try again without the '.'. */ | |
7973 | insn = NULL; | |
3882b010 | 7974 | for (s = str; *s != '\0' && !ISSPACE (*s); ++s) |
252b5132 RH |
7975 | continue; |
7976 | ||
7977 | /* If we stopped on whitespace, then replace the whitespace with null for | |
7978 | the call to hash_find. Save the character we replaced just in case we | |
7979 | have to re-parse the instruction. */ | |
3882b010 | 7980 | if (ISSPACE (*s)) |
252b5132 RH |
7981 | { |
7982 | save_c = *s; | |
7983 | *s++ = '\0'; | |
7984 | } | |
bdaaa2e1 | 7985 | |
252b5132 RH |
7986 | insn = (struct mips_opcode *) hash_find (op_hash, str); |
7987 | ||
7988 | /* If we didn't find the instruction in the opcode table, try again, but | |
7989 | this time with just the instruction up to, but not including the | |
7990 | first '.'. */ | |
7991 | if (insn == NULL) | |
7992 | { | |
bdaaa2e1 | 7993 | /* Restore the character we overwrite above (if any). */ |
252b5132 RH |
7994 | if (save_c) |
7995 | *(--s) = save_c; | |
7996 | ||
7997 | /* Scan up to the first '.' or whitespace. */ | |
3882b010 L |
7998 | for (s = str; |
7999 | *s != '\0' && *s != '.' && !ISSPACE (*s); | |
8000 | ++s) | |
252b5132 RH |
8001 | continue; |
8002 | ||
8003 | /* If we did not find a '.', then we can quit now. */ | |
8004 | if (*s != '.') | |
8005 | { | |
8006 | insn_error = "unrecognized opcode"; | |
8007 | return; | |
8008 | } | |
8009 | ||
8010 | /* Lookup the instruction in the hash table. */ | |
8011 | *s++ = '\0'; | |
8012 | if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL) | |
8013 | { | |
8014 | insn_error = "unrecognized opcode"; | |
8015 | return; | |
8016 | } | |
252b5132 RH |
8017 | } |
8018 | ||
8019 | argsStart = s; | |
8020 | for (;;) | |
8021 | { | |
252b5132 RH |
8022 | boolean ok; |
8023 | ||
8024 | assert (strcmp (insn->name, str) == 0); | |
8025 | ||
1f25f5d3 CD |
8026 | if (OPCODE_IS_MEMBER (insn, |
8027 | (mips_opts.isa | |
3396de36 | 8028 | | (file_ase_mips16 ? INSN_MIPS16 : 0) |
deec1734 | 8029 | | (mips_opts.ase_mdmx ? INSN_MDMX : 0) |
98d3f06f | 8030 | | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)), |
1f25f5d3 | 8031 | mips_arch)) |
252b5132 | 8032 | ok = true; |
bdaaa2e1 | 8033 | else |
252b5132 | 8034 | ok = false; |
bdaaa2e1 | 8035 | |
252b5132 RH |
8036 | if (insn->pinfo != INSN_MACRO) |
8037 | { | |
ec68c924 | 8038 | if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0) |
252b5132 RH |
8039 | ok = false; |
8040 | } | |
8041 | ||
8042 | if (! ok) | |
8043 | { | |
8044 | if (insn + 1 < &mips_opcodes[NUMOPCODES] | |
8045 | && strcmp (insn->name, insn[1].name) == 0) | |
8046 | { | |
8047 | ++insn; | |
8048 | continue; | |
8049 | } | |
252b5132 | 8050 | else |
beae10d5 | 8051 | { |
268f6bed L |
8052 | if (!insn_error) |
8053 | { | |
8054 | static char buf[100]; | |
316f5878 RS |
8055 | if (mips_arch_info->is_isa) |
8056 | sprintf (buf, | |
8057 | _("opcode not supported at this ISA level (%s)"), | |
8058 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
8059 | else | |
8060 | sprintf (buf, | |
8061 | _("opcode not supported on this processor: %s (%s)"), | |
8062 | mips_arch_info->name, | |
8063 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
268f6bed L |
8064 | insn_error = buf; |
8065 | } | |
8066 | if (save_c) | |
8067 | *(--s) = save_c; | |
2bd7f1f3 | 8068 | return; |
252b5132 | 8069 | } |
252b5132 RH |
8070 | } |
8071 | ||
8072 | ip->insn_mo = insn; | |
8073 | ip->insn_opcode = insn->match; | |
268f6bed | 8074 | insn_error = NULL; |
252b5132 RH |
8075 | for (args = insn->args;; ++args) |
8076 | { | |
deec1734 CD |
8077 | int is_mdmx; |
8078 | ||
ad8d3bb3 | 8079 | s += strspn (s, " \t"); |
deec1734 | 8080 | is_mdmx = 0; |
252b5132 RH |
8081 | switch (*args) |
8082 | { | |
8083 | case '\0': /* end of args */ | |
8084 | if (*s == '\0') | |
8085 | return; | |
8086 | break; | |
8087 | ||
8088 | case ',': | |
8089 | if (*s++ == *args) | |
8090 | continue; | |
8091 | s--; | |
8092 | switch (*++args) | |
8093 | { | |
8094 | case 'r': | |
8095 | case 'v': | |
38487616 | 8096 | ip->insn_opcode |= lastregno << OP_SH_RS; |
252b5132 RH |
8097 | continue; |
8098 | ||
8099 | case 'w': | |
38487616 TS |
8100 | ip->insn_opcode |= lastregno << OP_SH_RT; |
8101 | continue; | |
8102 | ||
252b5132 | 8103 | case 'W': |
38487616 | 8104 | ip->insn_opcode |= lastregno << OP_SH_FT; |
252b5132 RH |
8105 | continue; |
8106 | ||
8107 | case 'V': | |
38487616 | 8108 | ip->insn_opcode |= lastregno << OP_SH_FS; |
252b5132 RH |
8109 | continue; |
8110 | } | |
8111 | break; | |
8112 | ||
8113 | case '(': | |
8114 | /* Handle optional base register. | |
8115 | Either the base register is omitted or | |
bdaaa2e1 | 8116 | we must have a left paren. */ |
252b5132 RH |
8117 | /* This is dependent on the next operand specifier |
8118 | is a base register specification. */ | |
8119 | assert (args[1] == 'b' || args[1] == '5' | |
8120 | || args[1] == '-' || args[1] == '4'); | |
8121 | if (*s == '\0') | |
8122 | return; | |
8123 | ||
8124 | case ')': /* these must match exactly */ | |
60b63b72 RS |
8125 | case '[': |
8126 | case ']': | |
252b5132 RH |
8127 | if (*s++ == *args) |
8128 | continue; | |
8129 | break; | |
8130 | ||
8131 | case '<': /* must be at least one digit */ | |
8132 | /* | |
8133 | * According to the manual, if the shift amount is greater | |
b6ff326e KH |
8134 | * than 31 or less than 0, then the shift amount should be |
8135 | * mod 32. In reality the mips assembler issues an error. | |
252b5132 RH |
8136 | * We issue a warning and mask out all but the low 5 bits. |
8137 | */ | |
8138 | my_getExpression (&imm_expr, s); | |
8139 | check_absolute_expr (ip, &imm_expr); | |
8140 | if ((unsigned long) imm_expr.X_add_number > 31) | |
8141 | { | |
793b27f4 TS |
8142 | as_warn (_("Improper shift amount (%lu)"), |
8143 | (unsigned long) imm_expr.X_add_number); | |
38487616 | 8144 | imm_expr.X_add_number &= OP_MASK_SHAMT; |
252b5132 | 8145 | } |
38487616 | 8146 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT; |
252b5132 RH |
8147 | imm_expr.X_op = O_absent; |
8148 | s = expr_end; | |
8149 | continue; | |
8150 | ||
8151 | case '>': /* shift amount minus 32 */ | |
8152 | my_getExpression (&imm_expr, s); | |
8153 | check_absolute_expr (ip, &imm_expr); | |
8154 | if ((unsigned long) imm_expr.X_add_number < 32 | |
8155 | || (unsigned long) imm_expr.X_add_number > 63) | |
8156 | break; | |
38487616 | 8157 | ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT; |
252b5132 RH |
8158 | imm_expr.X_op = O_absent; |
8159 | s = expr_end; | |
8160 | continue; | |
8161 | ||
252b5132 RH |
8162 | case 'k': /* cache code */ |
8163 | case 'h': /* prefx code */ | |
8164 | my_getExpression (&imm_expr, s); | |
8165 | check_absolute_expr (ip, &imm_expr); | |
8166 | if ((unsigned long) imm_expr.X_add_number > 31) | |
8167 | { | |
8168 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8169 | ip->insn_mo->name, | |
8170 | (unsigned long) imm_expr.X_add_number); | |
8171 | imm_expr.X_add_number &= 0x1f; | |
8172 | } | |
8173 | if (*args == 'k') | |
8174 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE; | |
8175 | else | |
8176 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX; | |
8177 | imm_expr.X_op = O_absent; | |
8178 | s = expr_end; | |
8179 | continue; | |
8180 | ||
8181 | case 'c': /* break code */ | |
8182 | my_getExpression (&imm_expr, s); | |
8183 | check_absolute_expr (ip, &imm_expr); | |
793b27f4 | 8184 | if ((unsigned long) imm_expr.X_add_number > 1023) |
252b5132 | 8185 | { |
793b27f4 TS |
8186 | as_warn (_("Illegal break code (%lu)"), |
8187 | (unsigned long) imm_expr.X_add_number); | |
38487616 | 8188 | imm_expr.X_add_number &= OP_MASK_CODE; |
252b5132 | 8189 | } |
38487616 | 8190 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE; |
252b5132 RH |
8191 | imm_expr.X_op = O_absent; |
8192 | s = expr_end; | |
8193 | continue; | |
8194 | ||
8195 | case 'q': /* lower break code */ | |
8196 | my_getExpression (&imm_expr, s); | |
8197 | check_absolute_expr (ip, &imm_expr); | |
793b27f4 | 8198 | if ((unsigned long) imm_expr.X_add_number > 1023) |
252b5132 | 8199 | { |
793b27f4 TS |
8200 | as_warn (_("Illegal lower break code (%lu)"), |
8201 | (unsigned long) imm_expr.X_add_number); | |
38487616 | 8202 | imm_expr.X_add_number &= OP_MASK_CODE2; |
252b5132 | 8203 | } |
38487616 | 8204 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2; |
252b5132 RH |
8205 | imm_expr.X_op = O_absent; |
8206 | s = expr_end; | |
8207 | continue; | |
8208 | ||
4372b673 | 8209 | case 'B': /* 20-bit syscall/break code. */ |
156c2f8b | 8210 | my_getExpression (&imm_expr, s); |
156c2f8b | 8211 | check_absolute_expr (ip, &imm_expr); |
793b27f4 TS |
8212 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20) |
8213 | as_warn (_("Illegal 20-bit code (%lu)"), | |
8214 | (unsigned long) imm_expr.X_add_number); | |
38487616 | 8215 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20; |
252b5132 RH |
8216 | imm_expr.X_op = O_absent; |
8217 | s = expr_end; | |
8218 | continue; | |
8219 | ||
98d3f06f | 8220 | case 'C': /* Coprocessor code */ |
beae10d5 | 8221 | my_getExpression (&imm_expr, s); |
252b5132 | 8222 | check_absolute_expr (ip, &imm_expr); |
98d3f06f | 8223 | if ((unsigned long) imm_expr.X_add_number >= (1 << 25)) |
252b5132 | 8224 | { |
793b27f4 TS |
8225 | as_warn (_("Coproccesor code > 25 bits (%lu)"), |
8226 | (unsigned long) imm_expr.X_add_number); | |
98d3f06f | 8227 | imm_expr.X_add_number &= ((1 << 25) - 1); |
252b5132 | 8228 | } |
beae10d5 KH |
8229 | ip->insn_opcode |= imm_expr.X_add_number; |
8230 | imm_expr.X_op = O_absent; | |
8231 | s = expr_end; | |
8232 | continue; | |
252b5132 | 8233 | |
4372b673 NC |
8234 | case 'J': /* 19-bit wait code. */ |
8235 | my_getExpression (&imm_expr, s); | |
8236 | check_absolute_expr (ip, &imm_expr); | |
793b27f4 TS |
8237 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19) |
8238 | as_warn (_("Illegal 19-bit code (%lu)"), | |
8239 | (unsigned long) imm_expr.X_add_number); | |
38487616 | 8240 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19; |
4372b673 NC |
8241 | imm_expr.X_op = O_absent; |
8242 | s = expr_end; | |
8243 | continue; | |
8244 | ||
252b5132 | 8245 | case 'P': /* Performance register */ |
beae10d5 | 8246 | my_getExpression (&imm_expr, s); |
252b5132 | 8247 | check_absolute_expr (ip, &imm_expr); |
beae10d5 | 8248 | if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1) |
252b5132 | 8249 | { |
793b27f4 TS |
8250 | as_warn (_("Invalid performance register (%lu)"), |
8251 | (unsigned long) imm_expr.X_add_number); | |
38487616 | 8252 | imm_expr.X_add_number &= OP_MASK_PERFREG; |
252b5132 | 8253 | } |
38487616 | 8254 | ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG); |
beae10d5 KH |
8255 | imm_expr.X_op = O_absent; |
8256 | s = expr_end; | |
8257 | continue; | |
252b5132 RH |
8258 | |
8259 | case 'b': /* base register */ | |
8260 | case 'd': /* destination register */ | |
8261 | case 's': /* source register */ | |
8262 | case 't': /* target register */ | |
8263 | case 'r': /* both target and source */ | |
8264 | case 'v': /* both dest and source */ | |
8265 | case 'w': /* both dest and target */ | |
8266 | case 'E': /* coprocessor target register */ | |
8267 | case 'G': /* coprocessor destination register */ | |
8268 | case 'x': /* ignore register name */ | |
8269 | case 'z': /* must be zero register */ | |
4372b673 | 8270 | case 'U': /* destination register (clo/clz). */ |
252b5132 RH |
8271 | s_reset = s; |
8272 | if (s[0] == '$') | |
8273 | { | |
8274 | ||
3882b010 | 8275 | if (ISDIGIT (s[1])) |
252b5132 RH |
8276 | { |
8277 | ++s; | |
8278 | regno = 0; | |
8279 | do | |
8280 | { | |
8281 | regno *= 10; | |
8282 | regno += *s - '0'; | |
8283 | ++s; | |
8284 | } | |
3882b010 | 8285 | while (ISDIGIT (*s)); |
252b5132 RH |
8286 | if (regno > 31) |
8287 | as_bad (_("Invalid register number (%d)"), regno); | |
8288 | } | |
8289 | else if (*args == 'E' || *args == 'G') | |
8290 | goto notreg; | |
8291 | else | |
8292 | { | |
76db943d TS |
8293 | if (s[1] == 'r' && s[2] == 'a') |
8294 | { | |
8295 | s += 3; | |
8296 | regno = RA; | |
8297 | } | |
8298 | else if (s[1] == 'f' && s[2] == 'p') | |
252b5132 RH |
8299 | { |
8300 | s += 3; | |
8301 | regno = FP; | |
8302 | } | |
8303 | else if (s[1] == 's' && s[2] == 'p') | |
8304 | { | |
8305 | s += 3; | |
8306 | regno = SP; | |
8307 | } | |
8308 | else if (s[1] == 'g' && s[2] == 'p') | |
8309 | { | |
8310 | s += 3; | |
8311 | regno = GP; | |
8312 | } | |
8313 | else if (s[1] == 'a' && s[2] == 't') | |
8314 | { | |
8315 | s += 3; | |
8316 | regno = AT; | |
8317 | } | |
8318 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
8319 | { | |
8320 | s += 4; | |
8321 | regno = KT0; | |
8322 | } | |
8323 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
8324 | { | |
8325 | s += 4; | |
8326 | regno = KT1; | |
8327 | } | |
85b51719 TS |
8328 | else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o') |
8329 | { | |
8330 | s += 5; | |
8331 | regno = ZERO; | |
8332 | } | |
252b5132 RH |
8333 | else if (itbl_have_entries) |
8334 | { | |
8335 | char *p, *n; | |
d7ba4a77 | 8336 | unsigned long r; |
252b5132 | 8337 | |
d7ba4a77 | 8338 | p = s + 1; /* advance past '$' */ |
252b5132 RH |
8339 | n = itbl_get_field (&p); /* n is name */ |
8340 | ||
d7ba4a77 ILT |
8341 | /* See if this is a register defined in an |
8342 | itbl entry. */ | |
8343 | if (itbl_get_reg_val (n, &r)) | |
252b5132 RH |
8344 | { |
8345 | /* Get_field advances to the start of | |
8346 | the next field, so we need to back | |
d7ba4a77 | 8347 | rack to the end of the last field. */ |
bdaaa2e1 | 8348 | if (p) |
252b5132 | 8349 | s = p - 1; |
bdaaa2e1 | 8350 | else |
d7ba4a77 | 8351 | s = strchr (s, '\0'); |
252b5132 RH |
8352 | regno = r; |
8353 | } | |
8354 | else | |
8355 | goto notreg; | |
beae10d5 | 8356 | } |
252b5132 RH |
8357 | else |
8358 | goto notreg; | |
8359 | } | |
8360 | if (regno == AT | |
8361 | && ! mips_opts.noat | |
8362 | && *args != 'E' | |
8363 | && *args != 'G') | |
8364 | as_warn (_("Used $at without \".set noat\"")); | |
8365 | c = *args; | |
8366 | if (*s == ' ') | |
f9419b05 | 8367 | ++s; |
252b5132 RH |
8368 | if (args[1] != *s) |
8369 | { | |
8370 | if (c == 'r' || c == 'v' || c == 'w') | |
8371 | { | |
8372 | regno = lastregno; | |
8373 | s = s_reset; | |
f9419b05 | 8374 | ++args; |
252b5132 RH |
8375 | } |
8376 | } | |
8377 | /* 'z' only matches $0. */ | |
8378 | if (c == 'z' && regno != 0) | |
8379 | break; | |
8380 | ||
bdaaa2e1 KH |
8381 | /* Now that we have assembled one operand, we use the args string |
8382 | * to figure out where it goes in the instruction. */ | |
252b5132 RH |
8383 | switch (c) |
8384 | { | |
8385 | case 'r': | |
8386 | case 's': | |
8387 | case 'v': | |
8388 | case 'b': | |
38487616 | 8389 | ip->insn_opcode |= regno << OP_SH_RS; |
252b5132 RH |
8390 | break; |
8391 | case 'd': | |
8392 | case 'G': | |
38487616 | 8393 | ip->insn_opcode |= regno << OP_SH_RD; |
252b5132 | 8394 | break; |
4372b673 | 8395 | case 'U': |
38487616 TS |
8396 | ip->insn_opcode |= regno << OP_SH_RD; |
8397 | ip->insn_opcode |= regno << OP_SH_RT; | |
4372b673 | 8398 | break; |
252b5132 RH |
8399 | case 'w': |
8400 | case 't': | |
8401 | case 'E': | |
38487616 | 8402 | ip->insn_opcode |= regno << OP_SH_RT; |
252b5132 RH |
8403 | break; |
8404 | case 'x': | |
8405 | /* This case exists because on the r3000 trunc | |
8406 | expands into a macro which requires a gp | |
8407 | register. On the r6000 or r4000 it is | |
8408 | assembled into a single instruction which | |
8409 | ignores the register. Thus the insn version | |
8410 | is MIPS_ISA2 and uses 'x', and the macro | |
8411 | version is MIPS_ISA1 and uses 't'. */ | |
8412 | break; | |
8413 | case 'z': | |
8414 | /* This case is for the div instruction, which | |
8415 | acts differently if the destination argument | |
8416 | is $0. This only matches $0, and is checked | |
8417 | outside the switch. */ | |
8418 | break; | |
8419 | case 'D': | |
8420 | /* Itbl operand; not yet implemented. FIXME ?? */ | |
8421 | break; | |
8422 | /* What about all other operands like 'i', which | |
8423 | can be specified in the opcode table? */ | |
8424 | } | |
8425 | lastregno = regno; | |
8426 | continue; | |
8427 | } | |
8428 | notreg: | |
8429 | switch (*args++) | |
8430 | { | |
8431 | case 'r': | |
8432 | case 'v': | |
38487616 | 8433 | ip->insn_opcode |= lastregno << OP_SH_RS; |
252b5132 RH |
8434 | continue; |
8435 | case 'w': | |
38487616 | 8436 | ip->insn_opcode |= lastregno << OP_SH_RT; |
252b5132 RH |
8437 | continue; |
8438 | } | |
8439 | break; | |
8440 | ||
deec1734 CD |
8441 | case 'O': /* MDMX alignment immediate constant. */ |
8442 | my_getExpression (&imm_expr, s); | |
8443 | check_absolute_expr (ip, &imm_expr); | |
8444 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN) | |
8445 | { | |
8446 | as_warn ("Improper align amount (%ld), using low bits", | |
8447 | (long) imm_expr.X_add_number); | |
8448 | imm_expr.X_add_number &= OP_MASK_ALN; | |
8449 | } | |
8450 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_ALN; | |
8451 | imm_expr.X_op = O_absent; | |
8452 | s = expr_end; | |
8453 | continue; | |
8454 | ||
8455 | case 'Q': /* MDMX vector, element sel, or const. */ | |
8456 | if (s[0] != '$') | |
8457 | { | |
8458 | /* MDMX Immediate. */ | |
8459 | my_getExpression (&imm_expr, s); | |
8460 | check_absolute_expr (ip, &imm_expr); | |
8461 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT) | |
8462 | { | |
8463 | as_warn (_("Invalid MDMX Immediate (%ld)"), | |
8464 | (long) imm_expr.X_add_number); | |
8465 | imm_expr.X_add_number &= OP_MASK_FT; | |
8466 | } | |
8467 | imm_expr.X_add_number &= OP_MASK_FT; | |
8468 | if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL)) | |
8469 | ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL; | |
8470 | else | |
8471 | ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL; | |
8472 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_FT; | |
8473 | imm_expr.X_op = O_absent; | |
8474 | s = expr_end; | |
8475 | continue; | |
8476 | } | |
8477 | /* Not MDMX Immediate. Fall through. */ | |
8478 | case 'X': /* MDMX destination register. */ | |
8479 | case 'Y': /* MDMX source register. */ | |
8480 | case 'Z': /* MDMX target register. */ | |
8481 | is_mdmx = 1; | |
252b5132 RH |
8482 | case 'D': /* floating point destination register */ |
8483 | case 'S': /* floating point source register */ | |
8484 | case 'T': /* floating point target register */ | |
8485 | case 'R': /* floating point source register */ | |
8486 | case 'V': | |
8487 | case 'W': | |
8488 | s_reset = s; | |
deec1734 CD |
8489 | /* Accept $fN for FP and MDMX register numbers, and in |
8490 | addition accept $vN for MDMX register numbers. */ | |
8491 | if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2])) | |
8492 | || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v' | |
8493 | && ISDIGIT (s[2]))) | |
252b5132 RH |
8494 | { |
8495 | s += 2; | |
8496 | regno = 0; | |
8497 | do | |
8498 | { | |
8499 | regno *= 10; | |
8500 | regno += *s - '0'; | |
8501 | ++s; | |
8502 | } | |
3882b010 | 8503 | while (ISDIGIT (*s)); |
252b5132 RH |
8504 | |
8505 | if (regno > 31) | |
8506 | as_bad (_("Invalid float register number (%d)"), regno); | |
8507 | ||
8508 | if ((regno & 1) != 0 | |
ca4e0257 | 8509 | && HAVE_32BIT_FPRS |
252b5132 RH |
8510 | && ! (strcmp (str, "mtc1") == 0 |
8511 | || strcmp (str, "mfc1") == 0 | |
8512 | || strcmp (str, "lwc1") == 0 | |
8513 | || strcmp (str, "swc1") == 0 | |
8514 | || strcmp (str, "l.s") == 0 | |
8515 | || strcmp (str, "s.s") == 0)) | |
8516 | as_warn (_("Float register should be even, was %d"), | |
8517 | regno); | |
8518 | ||
8519 | c = *args; | |
8520 | if (*s == ' ') | |
f9419b05 | 8521 | ++s; |
252b5132 RH |
8522 | if (args[1] != *s) |
8523 | { | |
8524 | if (c == 'V' || c == 'W') | |
8525 | { | |
8526 | regno = lastregno; | |
8527 | s = s_reset; | |
f9419b05 | 8528 | ++args; |
252b5132 RH |
8529 | } |
8530 | } | |
8531 | switch (c) | |
8532 | { | |
8533 | case 'D': | |
deec1734 | 8534 | case 'X': |
38487616 | 8535 | ip->insn_opcode |= regno << OP_SH_FD; |
252b5132 RH |
8536 | break; |
8537 | case 'V': | |
8538 | case 'S': | |
deec1734 | 8539 | case 'Y': |
38487616 | 8540 | ip->insn_opcode |= regno << OP_SH_FS; |
252b5132 | 8541 | break; |
deec1734 CD |
8542 | case 'Q': |
8543 | /* This is like 'Z', but also needs to fix the MDMX | |
8544 | vector/scalar select bits. Note that the | |
8545 | scalar immediate case is handled above. */ | |
8546 | if (*s == '[') | |
8547 | { | |
8548 | int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL)); | |
8549 | int max_el = (is_qh ? 3 : 7); | |
8550 | s++; | |
8551 | my_getExpression(&imm_expr, s); | |
8552 | check_absolute_expr (ip, &imm_expr); | |
8553 | s = expr_end; | |
8554 | if (imm_expr.X_add_number > max_el) | |
8555 | as_bad(_("Bad element selector %ld"), | |
8556 | (long) imm_expr.X_add_number); | |
8557 | imm_expr.X_add_number &= max_el; | |
8558 | ip->insn_opcode |= (imm_expr.X_add_number | |
8559 | << (OP_SH_VSEL + | |
8560 | (is_qh ? 2 : 1))); | |
8561 | if (*s != ']') | |
8562 | as_warn(_("Expecting ']' found '%s'"), s); | |
8563 | else | |
8564 | s++; | |
8565 | } | |
8566 | else | |
8567 | { | |
8568 | if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL)) | |
8569 | ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH | |
8570 | << OP_SH_VSEL); | |
8571 | else | |
8572 | ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB << | |
8573 | OP_SH_VSEL); | |
8574 | } | |
8575 | /* Fall through */ | |
252b5132 RH |
8576 | case 'W': |
8577 | case 'T': | |
deec1734 | 8578 | case 'Z': |
38487616 | 8579 | ip->insn_opcode |= regno << OP_SH_FT; |
252b5132 RH |
8580 | break; |
8581 | case 'R': | |
38487616 | 8582 | ip->insn_opcode |= regno << OP_SH_FR; |
252b5132 RH |
8583 | break; |
8584 | } | |
8585 | lastregno = regno; | |
8586 | continue; | |
8587 | } | |
8588 | ||
252b5132 RH |
8589 | switch (*args++) |
8590 | { | |
8591 | case 'V': | |
38487616 | 8592 | ip->insn_opcode |= lastregno << OP_SH_FS; |
252b5132 RH |
8593 | continue; |
8594 | case 'W': | |
38487616 | 8595 | ip->insn_opcode |= lastregno << OP_SH_FT; |
252b5132 RH |
8596 | continue; |
8597 | } | |
8598 | break; | |
8599 | ||
8600 | case 'I': | |
8601 | my_getExpression (&imm_expr, s); | |
8602 | if (imm_expr.X_op != O_big | |
8603 | && imm_expr.X_op != O_constant) | |
8604 | insn_error = _("absolute expression required"); | |
8605 | s = expr_end; | |
8606 | continue; | |
8607 | ||
8608 | case 'A': | |
8609 | my_getExpression (&offset_expr, s); | |
f6688943 | 8610 | *imm_reloc = BFD_RELOC_32; |
252b5132 RH |
8611 | s = expr_end; |
8612 | continue; | |
8613 | ||
8614 | case 'F': | |
8615 | case 'L': | |
8616 | case 'f': | |
8617 | case 'l': | |
8618 | { | |
8619 | int f64; | |
ca4e0257 | 8620 | int using_gprs; |
252b5132 RH |
8621 | char *save_in; |
8622 | char *err; | |
8623 | unsigned char temp[8]; | |
8624 | int len; | |
8625 | unsigned int length; | |
8626 | segT seg; | |
8627 | subsegT subseg; | |
8628 | char *p; | |
8629 | ||
8630 | /* These only appear as the last operand in an | |
8631 | instruction, and every instruction that accepts | |
8632 | them in any variant accepts them in all variants. | |
8633 | This means we don't have to worry about backing out | |
8634 | any changes if the instruction does not match. | |
8635 | ||
8636 | The difference between them is the size of the | |
8637 | floating point constant and where it goes. For 'F' | |
8638 | and 'L' the constant is 64 bits; for 'f' and 'l' it | |
8639 | is 32 bits. Where the constant is placed is based | |
8640 | on how the MIPS assembler does things: | |
8641 | F -- .rdata | |
8642 | L -- .lit8 | |
8643 | f -- immediate value | |
8644 | l -- .lit4 | |
8645 | ||
8646 | The .lit4 and .lit8 sections are only used if | |
8647 | permitted by the -G argument. | |
8648 | ||
8649 | When generating embedded PIC code, we use the | |
8650 | .lit8 section but not the .lit4 section (we can do | |
8651 | .lit4 inline easily; we need to put .lit8 | |
8652 | somewhere in the data segment, and using .lit8 | |
8653 | permits the linker to eventually combine identical | |
ca4e0257 RS |
8654 | .lit8 entries). |
8655 | ||
8656 | The code below needs to know whether the target register | |
8657 | is 32 or 64 bits wide. It relies on the fact 'f' and | |
8658 | 'F' are used with GPR-based instructions and 'l' and | |
8659 | 'L' are used with FPR-based instructions. */ | |
252b5132 RH |
8660 | |
8661 | f64 = *args == 'F' || *args == 'L'; | |
ca4e0257 | 8662 | using_gprs = *args == 'F' || *args == 'f'; |
252b5132 RH |
8663 | |
8664 | save_in = input_line_pointer; | |
8665 | input_line_pointer = s; | |
8666 | err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len); | |
8667 | length = len; | |
8668 | s = input_line_pointer; | |
8669 | input_line_pointer = save_in; | |
8670 | if (err != NULL && *err != '\0') | |
8671 | { | |
8672 | as_bad (_("Bad floating point constant: %s"), err); | |
8673 | memset (temp, '\0', sizeof temp); | |
8674 | length = f64 ? 8 : 4; | |
8675 | } | |
8676 | ||
156c2f8b | 8677 | assert (length == (unsigned) (f64 ? 8 : 4)); |
252b5132 RH |
8678 | |
8679 | if (*args == 'f' | |
8680 | || (*args == 'l' | |
8681 | && (! USE_GLOBAL_POINTER_OPT | |
8682 | || mips_pic == EMBEDDED_PIC | |
8683 | || g_switch_value < 4 | |
8684 | || (temp[0] == 0 && temp[1] == 0) | |
8685 | || (temp[2] == 0 && temp[3] == 0)))) | |
8686 | { | |
8687 | imm_expr.X_op = O_constant; | |
8688 | if (! target_big_endian) | |
8689 | imm_expr.X_add_number = bfd_getl32 (temp); | |
8690 | else | |
8691 | imm_expr.X_add_number = bfd_getb32 (temp); | |
8692 | } | |
8693 | else if (length > 4 | |
119d663a | 8694 | && ! mips_disable_float_construction |
ca4e0257 RS |
8695 | /* Constants can only be constructed in GPRs and |
8696 | copied to FPRs if the GPRs are at least as wide | |
8697 | as the FPRs. Force the constant into memory if | |
8698 | we are using 64-bit FPRs but the GPRs are only | |
8699 | 32 bits wide. */ | |
8700 | && (using_gprs | |
8701 | || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS)) | |
252b5132 RH |
8702 | && ((temp[0] == 0 && temp[1] == 0) |
8703 | || (temp[2] == 0 && temp[3] == 0)) | |
8704 | && ((temp[4] == 0 && temp[5] == 0) | |
8705 | || (temp[6] == 0 && temp[7] == 0))) | |
8706 | { | |
ca4e0257 RS |
8707 | /* The value is simple enough to load with a couple of |
8708 | instructions. If using 32-bit registers, set | |
8709 | imm_expr to the high order 32 bits and offset_expr to | |
8710 | the low order 32 bits. Otherwise, set imm_expr to | |
8711 | the entire 64 bit constant. */ | |
8712 | if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS) | |
252b5132 RH |
8713 | { |
8714 | imm_expr.X_op = O_constant; | |
8715 | offset_expr.X_op = O_constant; | |
8716 | if (! target_big_endian) | |
8717 | { | |
8718 | imm_expr.X_add_number = bfd_getl32 (temp + 4); | |
8719 | offset_expr.X_add_number = bfd_getl32 (temp); | |
8720 | } | |
8721 | else | |
8722 | { | |
8723 | imm_expr.X_add_number = bfd_getb32 (temp); | |
8724 | offset_expr.X_add_number = bfd_getb32 (temp + 4); | |
8725 | } | |
8726 | if (offset_expr.X_add_number == 0) | |
8727 | offset_expr.X_op = O_absent; | |
8728 | } | |
8729 | else if (sizeof (imm_expr.X_add_number) > 4) | |
8730 | { | |
8731 | imm_expr.X_op = O_constant; | |
8732 | if (! target_big_endian) | |
8733 | imm_expr.X_add_number = bfd_getl64 (temp); | |
8734 | else | |
8735 | imm_expr.X_add_number = bfd_getb64 (temp); | |
8736 | } | |
8737 | else | |
8738 | { | |
8739 | imm_expr.X_op = O_big; | |
8740 | imm_expr.X_add_number = 4; | |
8741 | if (! target_big_endian) | |
8742 | { | |
8743 | generic_bignum[0] = bfd_getl16 (temp); | |
8744 | generic_bignum[1] = bfd_getl16 (temp + 2); | |
8745 | generic_bignum[2] = bfd_getl16 (temp + 4); | |
8746 | generic_bignum[3] = bfd_getl16 (temp + 6); | |
8747 | } | |
8748 | else | |
8749 | { | |
8750 | generic_bignum[0] = bfd_getb16 (temp + 6); | |
8751 | generic_bignum[1] = bfd_getb16 (temp + 4); | |
8752 | generic_bignum[2] = bfd_getb16 (temp + 2); | |
8753 | generic_bignum[3] = bfd_getb16 (temp); | |
8754 | } | |
8755 | } | |
8756 | } | |
8757 | else | |
8758 | { | |
8759 | const char *newname; | |
8760 | segT new_seg; | |
8761 | ||
8762 | /* Switch to the right section. */ | |
8763 | seg = now_seg; | |
8764 | subseg = now_subseg; | |
8765 | switch (*args) | |
8766 | { | |
8767 | default: /* unused default case avoids warnings. */ | |
8768 | case 'L': | |
8769 | newname = RDATA_SECTION_NAME; | |
bb2d6cd7 GK |
8770 | if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8) |
8771 | || mips_pic == EMBEDDED_PIC) | |
252b5132 RH |
8772 | newname = ".lit8"; |
8773 | break; | |
8774 | case 'F': | |
bb2d6cd7 GK |
8775 | if (mips_pic == EMBEDDED_PIC) |
8776 | newname = ".lit8"; | |
8777 | else | |
8778 | newname = RDATA_SECTION_NAME; | |
252b5132 RH |
8779 | break; |
8780 | case 'l': | |
8781 | assert (!USE_GLOBAL_POINTER_OPT | |
8782 | || g_switch_value >= 4); | |
8783 | newname = ".lit4"; | |
8784 | break; | |
8785 | } | |
8786 | new_seg = subseg_new (newname, (subsegT) 0); | |
8787 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
8788 | bfd_set_section_flags (stdoutput, new_seg, | |
8789 | (SEC_ALLOC | |
8790 | | SEC_LOAD | |
8791 | | SEC_READONLY | |
8792 | | SEC_DATA)); | |
8793 | frag_align (*args == 'l' ? 2 : 3, 0, 0); | |
8794 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
8795 | && strcmp (TARGET_OS, "elf") != 0) | |
8796 | record_alignment (new_seg, 4); | |
8797 | else | |
8798 | record_alignment (new_seg, *args == 'l' ? 2 : 3); | |
8799 | if (seg == now_seg) | |
8800 | as_bad (_("Can't use floating point insn in this section")); | |
8801 | ||
8802 | /* Set the argument to the current address in the | |
8803 | section. */ | |
8804 | offset_expr.X_op = O_symbol; | |
8805 | offset_expr.X_add_symbol = | |
8806 | symbol_new ("L0\001", now_seg, | |
8807 | (valueT) frag_now_fix (), frag_now); | |
8808 | offset_expr.X_add_number = 0; | |
8809 | ||
8810 | /* Put the floating point number into the section. */ | |
8811 | p = frag_more ((int) length); | |
8812 | memcpy (p, temp, length); | |
8813 | ||
8814 | /* Switch back to the original section. */ | |
8815 | subseg_set (seg, subseg); | |
8816 | } | |
8817 | } | |
8818 | continue; | |
8819 | ||
8820 | case 'i': /* 16 bit unsigned immediate */ | |
8821 | case 'j': /* 16 bit signed immediate */ | |
f6688943 | 8822 | *imm_reloc = BFD_RELOC_LO16; |
252b5132 | 8823 | c = my_getSmallExpression (&imm_expr, s); |
fb1b3232 | 8824 | if (c != S_EX_NONE) |
252b5132 | 8825 | { |
fb1b3232 | 8826 | if (c != S_EX_LO) |
252b5132 | 8827 | { |
fdb987ee RS |
8828 | if (c == S_EX_HI) |
8829 | { | |
8830 | *imm_reloc = BFD_RELOC_HI16_S; | |
8831 | imm_unmatched_hi = true; | |
8832 | } | |
ad8d3bb3 | 8833 | #ifdef OBJ_ELF |
fb1b3232 | 8834 | else if (c == S_EX_HIGHEST) |
98d3f06f | 8835 | *imm_reloc = BFD_RELOC_MIPS_HIGHEST; |
fb1b3232 | 8836 | else if (c == S_EX_HIGHER) |
98d3f06f | 8837 | *imm_reloc = BFD_RELOC_MIPS_HIGHER; |
ad8d3bb3 TS |
8838 | else if (c == S_EX_GP_REL) |
8839 | { | |
8840 | /* This occurs in NewABI only. */ | |
8841 | c = my_getSmallExpression (&imm_expr, s); | |
8842 | if (c != S_EX_NEG) | |
8843 | as_bad (_("bad composition of relocations")); | |
8844 | else | |
8845 | { | |
8846 | c = my_getSmallExpression (&imm_expr, s); | |
8847 | if (c != S_EX_LO) | |
8848 | as_bad (_("bad composition of relocations")); | |
8849 | else | |
8850 | { | |
8851 | imm_reloc[0] = BFD_RELOC_GPREL16; | |
8852 | imm_reloc[1] = BFD_RELOC_MIPS_SUB; | |
8853 | imm_reloc[2] = BFD_RELOC_LO16; | |
8854 | } | |
8855 | } | |
8856 | } | |
8857 | #endif | |
252b5132 | 8858 | else |
f6688943 | 8859 | *imm_reloc = BFD_RELOC_HI16; |
252b5132 RH |
8860 | } |
8861 | else if (imm_expr.X_op == O_constant) | |
8862 | imm_expr.X_add_number &= 0xffff; | |
8863 | } | |
8864 | if (*args == 'i') | |
8865 | { | |
fb1b3232 | 8866 | if ((c == S_EX_NONE && imm_expr.X_op != O_constant) |
252b5132 | 8867 | || ((imm_expr.X_add_number < 0 |
beae10d5 KH |
8868 | || imm_expr.X_add_number >= 0x10000) |
8869 | && imm_expr.X_op == O_constant)) | |
252b5132 RH |
8870 | { |
8871 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
8872 | !strcmp (insn->name, insn[1].name)) | |
8873 | break; | |
2ae7e77b AH |
8874 | if (imm_expr.X_op == O_constant |
8875 | || imm_expr.X_op == O_big) | |
252b5132 RH |
8876 | as_bad (_("16 bit expression not in range 0..65535")); |
8877 | } | |
8878 | } | |
8879 | else | |
8880 | { | |
8881 | int more; | |
8882 | offsetT max; | |
8883 | ||
8884 | /* The upper bound should be 0x8000, but | |
8885 | unfortunately the MIPS assembler accepts numbers | |
8886 | from 0x8000 to 0xffff and sign extends them, and | |
8887 | we want to be compatible. We only permit this | |
8888 | extended range for an instruction which does not | |
8889 | provide any further alternates, since those | |
8890 | alternates may handle other cases. People should | |
8891 | use the numbers they mean, rather than relying on | |
8892 | a mysterious sign extension. */ | |
8893 | more = (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
8894 | strcmp (insn->name, insn[1].name) == 0); | |
8895 | if (more) | |
8896 | max = 0x8000; | |
8897 | else | |
8898 | max = 0x10000; | |
fb1b3232 | 8899 | if ((c == S_EX_NONE && imm_expr.X_op != O_constant) |
252b5132 | 8900 | || ((imm_expr.X_add_number < -0x8000 |
beae10d5 KH |
8901 | || imm_expr.X_add_number >= max) |
8902 | && imm_expr.X_op == O_constant) | |
252b5132 RH |
8903 | || (more |
8904 | && imm_expr.X_add_number < 0 | |
ca4e0257 | 8905 | && HAVE_64BIT_GPRS |
252b5132 RH |
8906 | && imm_expr.X_unsigned |
8907 | && sizeof (imm_expr.X_add_number) <= 4)) | |
8908 | { | |
8909 | if (more) | |
8910 | break; | |
2ae7e77b AH |
8911 | if (imm_expr.X_op == O_constant |
8912 | || imm_expr.X_op == O_big) | |
252b5132 RH |
8913 | as_bad (_("16 bit expression not in range -32768..32767")); |
8914 | } | |
8915 | } | |
8916 | s = expr_end; | |
8917 | continue; | |
8918 | ||
8919 | case 'o': /* 16 bit offset */ | |
8920 | c = my_getSmallExpression (&offset_expr, s); | |
8921 | ||
8922 | /* If this value won't fit into a 16 bit offset, then go | |
8923 | find a macro that will generate the 32 bit offset | |
afdbd6d0 | 8924 | code pattern. */ |
fb1b3232 | 8925 | if (c == S_EX_NONE |
252b5132 RH |
8926 | && (offset_expr.X_op != O_constant |
8927 | || offset_expr.X_add_number >= 0x8000 | |
afdbd6d0 | 8928 | || offset_expr.X_add_number < -0x8000)) |
252b5132 RH |
8929 | break; |
8930 | ||
fb1b3232 | 8931 | if (c == S_EX_HI) |
252b5132 RH |
8932 | { |
8933 | if (offset_expr.X_op != O_constant) | |
8934 | break; | |
8935 | offset_expr.X_add_number = | |
8936 | (offset_expr.X_add_number >> 16) & 0xffff; | |
8937 | } | |
f6688943 | 8938 | *offset_reloc = BFD_RELOC_LO16; |
252b5132 RH |
8939 | s = expr_end; |
8940 | continue; | |
8941 | ||
8942 | case 'p': /* pc relative offset */ | |
cb56d3d3 | 8943 | if (mips_pic == EMBEDDED_PIC) |
f6688943 | 8944 | *offset_reloc = BFD_RELOC_16_PCREL_S2; |
cb56d3d3 | 8945 | else |
f6688943 | 8946 | *offset_reloc = BFD_RELOC_16_PCREL; |
252b5132 RH |
8947 | my_getExpression (&offset_expr, s); |
8948 | s = expr_end; | |
8949 | continue; | |
8950 | ||
8951 | case 'u': /* upper 16 bits */ | |
8952 | c = my_getSmallExpression (&imm_expr, s); | |
f6688943 | 8953 | *imm_reloc = BFD_RELOC_LO16; |
e7d556df | 8954 | if (c != S_EX_NONE) |
252b5132 | 8955 | { |
fb1b3232 | 8956 | if (c != S_EX_LO) |
252b5132 | 8957 | { |
fdb987ee | 8958 | if (c == S_EX_HI) |
252b5132 | 8959 | { |
f6688943 | 8960 | *imm_reloc = BFD_RELOC_HI16_S; |
252b5132 RH |
8961 | imm_unmatched_hi = true; |
8962 | } | |
645dc66c TS |
8963 | #ifdef OBJ_ELF |
8964 | else if (c == S_EX_HIGHEST) | |
98d3f06f | 8965 | *imm_reloc = BFD_RELOC_MIPS_HIGHEST; |
ad8d3bb3 TS |
8966 | else if (c == S_EX_GP_REL) |
8967 | { | |
8968 | /* This occurs in NewABI only. */ | |
8969 | c = my_getSmallExpression (&imm_expr, s); | |
8970 | if (c != S_EX_NEG) | |
8971 | as_bad (_("bad composition of relocations")); | |
8972 | else | |
8973 | { | |
8974 | c = my_getSmallExpression (&imm_expr, s); | |
8975 | if (c != S_EX_HI) | |
8976 | as_bad (_("bad composition of relocations")); | |
8977 | else | |
8978 | { | |
8979 | imm_reloc[0] = BFD_RELOC_GPREL16; | |
8980 | imm_reloc[1] = BFD_RELOC_MIPS_SUB; | |
8981 | imm_reloc[2] = BFD_RELOC_HI16_S; | |
8982 | } | |
8983 | } | |
8984 | } | |
8985 | #endif | |
252b5132 | 8986 | else |
f6688943 | 8987 | *imm_reloc = BFD_RELOC_HI16; |
252b5132 RH |
8988 | } |
8989 | else if (imm_expr.X_op == O_constant) | |
8990 | imm_expr.X_add_number &= 0xffff; | |
8991 | } | |
fdb987ee RS |
8992 | else if (imm_expr.X_op == O_constant |
8993 | && (imm_expr.X_add_number < 0 | |
8994 | || imm_expr.X_add_number >= 0x10000)) | |
252b5132 RH |
8995 | as_bad (_("lui expression not in range 0..65535")); |
8996 | s = expr_end; | |
8997 | continue; | |
8998 | ||
8999 | case 'a': /* 26 bit address */ | |
9000 | my_getExpression (&offset_expr, s); | |
9001 | s = expr_end; | |
f6688943 | 9002 | *offset_reloc = BFD_RELOC_MIPS_JMP; |
252b5132 RH |
9003 | continue; |
9004 | ||
9005 | case 'N': /* 3 bit branch condition code */ | |
9006 | case 'M': /* 3 bit compare condition code */ | |
9007 | if (strncmp (s, "$fcc", 4) != 0) | |
9008 | break; | |
9009 | s += 4; | |
9010 | regno = 0; | |
9011 | do | |
9012 | { | |
9013 | regno *= 10; | |
9014 | regno += *s - '0'; | |
9015 | ++s; | |
9016 | } | |
3882b010 | 9017 | while (ISDIGIT (*s)); |
252b5132 RH |
9018 | if (regno > 7) |
9019 | as_bad (_("invalid condition code register $fcc%d"), regno); | |
9020 | if (*args == 'N') | |
9021 | ip->insn_opcode |= regno << OP_SH_BCC; | |
9022 | else | |
9023 | ip->insn_opcode |= regno << OP_SH_CCC; | |
beae10d5 | 9024 | continue; |
252b5132 | 9025 | |
156c2f8b NC |
9026 | case 'H': |
9027 | if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) | |
9028 | s += 2; | |
3882b010 | 9029 | if (ISDIGIT (*s)) |
156c2f8b NC |
9030 | { |
9031 | c = 0; | |
9032 | do | |
9033 | { | |
9034 | c *= 10; | |
9035 | c += *s - '0'; | |
9036 | ++s; | |
9037 | } | |
3882b010 | 9038 | while (ISDIGIT (*s)); |
156c2f8b NC |
9039 | } |
9040 | else | |
9041 | c = 8; /* Invalid sel value. */ | |
9042 | ||
9043 | if (c > 7) | |
9044 | as_bad (_("invalid coprocessor sub-selection value (0-7)")); | |
9045 | ip->insn_opcode |= c; | |
9046 | continue; | |
9047 | ||
60b63b72 RS |
9048 | case 'e': |
9049 | /* Must be at least one digit. */ | |
9050 | my_getExpression (&imm_expr, s); | |
9051 | check_absolute_expr (ip, &imm_expr); | |
9052 | ||
9053 | if ((unsigned long) imm_expr.X_add_number | |
9054 | > (unsigned long) OP_MASK_VECBYTE) | |
9055 | { | |
9056 | as_bad (_("bad byte vector index (%ld)"), | |
9057 | (long) imm_expr.X_add_number); | |
9058 | imm_expr.X_add_number = 0; | |
9059 | } | |
9060 | ||
9061 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECBYTE; | |
9062 | imm_expr.X_op = O_absent; | |
9063 | s = expr_end; | |
9064 | continue; | |
9065 | ||
9066 | case '%': | |
9067 | my_getExpression (&imm_expr, s); | |
9068 | check_absolute_expr (ip, &imm_expr); | |
9069 | ||
9070 | if ((unsigned long) imm_expr.X_add_number | |
9071 | > (unsigned long) OP_MASK_VECALIGN) | |
9072 | { | |
9073 | as_bad (_("bad byte vector index (%ld)"), | |
9074 | (long) imm_expr.X_add_number); | |
9075 | imm_expr.X_add_number = 0; | |
9076 | } | |
9077 | ||
9078 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_VECALIGN; | |
9079 | imm_expr.X_op = O_absent; | |
9080 | s = expr_end; | |
9081 | continue; | |
9082 | ||
252b5132 RH |
9083 | default: |
9084 | as_bad (_("bad char = '%c'\n"), *args); | |
9085 | internalError (); | |
9086 | } | |
9087 | break; | |
9088 | } | |
9089 | /* Args don't match. */ | |
9090 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
9091 | !strcmp (insn->name, insn[1].name)) | |
9092 | { | |
9093 | ++insn; | |
9094 | s = argsStart; | |
268f6bed | 9095 | insn_error = _("illegal operands"); |
252b5132 RH |
9096 | continue; |
9097 | } | |
268f6bed L |
9098 | if (save_c) |
9099 | *(--s) = save_c; | |
252b5132 RH |
9100 | insn_error = _("illegal operands"); |
9101 | return; | |
9102 | } | |
9103 | } | |
9104 | ||
9105 | /* This routine assembles an instruction into its binary format when | |
9106 | assembling for the mips16. As a side effect, it sets one of the | |
9107 | global variables imm_reloc or offset_reloc to the type of | |
9108 | relocation to do if one of the operands is an address expression. | |
9109 | It also sets mips16_small and mips16_ext if the user explicitly | |
9110 | requested a small or extended instruction. */ | |
9111 | ||
9112 | static void | |
9113 | mips16_ip (str, ip) | |
9114 | char *str; | |
9115 | struct mips_cl_insn *ip; | |
9116 | { | |
9117 | char *s; | |
9118 | const char *args; | |
9119 | struct mips_opcode *insn; | |
9120 | char *argsstart; | |
9121 | unsigned int regno; | |
9122 | unsigned int lastregno = 0; | |
9123 | char *s_reset; | |
9124 | ||
9125 | insn_error = NULL; | |
9126 | ||
9127 | mips16_small = false; | |
9128 | mips16_ext = false; | |
9129 | ||
3882b010 | 9130 | for (s = str; ISLOWER (*s); ++s) |
252b5132 RH |
9131 | ; |
9132 | switch (*s) | |
9133 | { | |
9134 | case '\0': | |
9135 | break; | |
9136 | ||
9137 | case ' ': | |
9138 | *s++ = '\0'; | |
9139 | break; | |
9140 | ||
9141 | case '.': | |
9142 | if (s[1] == 't' && s[2] == ' ') | |
9143 | { | |
9144 | *s = '\0'; | |
9145 | mips16_small = true; | |
9146 | s += 3; | |
9147 | break; | |
9148 | } | |
9149 | else if (s[1] == 'e' && s[2] == ' ') | |
9150 | { | |
9151 | *s = '\0'; | |
9152 | mips16_ext = true; | |
9153 | s += 3; | |
9154 | break; | |
9155 | } | |
9156 | /* Fall through. */ | |
9157 | default: | |
9158 | insn_error = _("unknown opcode"); | |
9159 | return; | |
9160 | } | |
9161 | ||
9162 | if (mips_opts.noautoextend && ! mips16_ext) | |
9163 | mips16_small = true; | |
9164 | ||
9165 | if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL) | |
9166 | { | |
9167 | insn_error = _("unrecognized opcode"); | |
9168 | return; | |
9169 | } | |
9170 | ||
9171 | argsstart = s; | |
9172 | for (;;) | |
9173 | { | |
9174 | assert (strcmp (insn->name, str) == 0); | |
9175 | ||
9176 | ip->insn_mo = insn; | |
9177 | ip->insn_opcode = insn->match; | |
9178 | ip->use_extend = false; | |
9179 | imm_expr.X_op = O_absent; | |
f6688943 TS |
9180 | imm_reloc[0] = BFD_RELOC_UNUSED; |
9181 | imm_reloc[1] = BFD_RELOC_UNUSED; | |
9182 | imm_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 | 9183 | offset_expr.X_op = O_absent; |
f6688943 TS |
9184 | offset_reloc[0] = BFD_RELOC_UNUSED; |
9185 | offset_reloc[1] = BFD_RELOC_UNUSED; | |
9186 | offset_reloc[2] = BFD_RELOC_UNUSED; | |
252b5132 RH |
9187 | for (args = insn->args; 1; ++args) |
9188 | { | |
9189 | int c; | |
9190 | ||
9191 | if (*s == ' ') | |
9192 | ++s; | |
9193 | ||
9194 | /* In this switch statement we call break if we did not find | |
9195 | a match, continue if we did find a match, or return if we | |
9196 | are done. */ | |
9197 | ||
9198 | c = *args; | |
9199 | switch (c) | |
9200 | { | |
9201 | case '\0': | |
9202 | if (*s == '\0') | |
9203 | { | |
9204 | /* Stuff the immediate value in now, if we can. */ | |
9205 | if (imm_expr.X_op == O_constant | |
f6688943 | 9206 | && *imm_reloc > BFD_RELOC_UNUSED |
252b5132 RH |
9207 | && insn->pinfo != INSN_MACRO) |
9208 | { | |
c4e7957c | 9209 | mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED, |
252b5132 RH |
9210 | imm_expr.X_add_number, true, mips16_small, |
9211 | mips16_ext, &ip->insn_opcode, | |
9212 | &ip->use_extend, &ip->extend); | |
9213 | imm_expr.X_op = O_absent; | |
f6688943 | 9214 | *imm_reloc = BFD_RELOC_UNUSED; |
252b5132 RH |
9215 | } |
9216 | ||
9217 | return; | |
9218 | } | |
9219 | break; | |
9220 | ||
9221 | case ',': | |
9222 | if (*s++ == c) | |
9223 | continue; | |
9224 | s--; | |
9225 | switch (*++args) | |
9226 | { | |
9227 | case 'v': | |
9228 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
9229 | continue; | |
9230 | case 'w': | |
9231 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
9232 | continue; | |
9233 | } | |
9234 | break; | |
9235 | ||
9236 | case '(': | |
9237 | case ')': | |
9238 | if (*s++ == c) | |
9239 | continue; | |
9240 | break; | |
9241 | ||
9242 | case 'v': | |
9243 | case 'w': | |
9244 | if (s[0] != '$') | |
9245 | { | |
9246 | if (c == 'v') | |
9247 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
9248 | else | |
9249 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
9250 | ++args; | |
9251 | continue; | |
9252 | } | |
9253 | /* Fall through. */ | |
9254 | case 'x': | |
9255 | case 'y': | |
9256 | case 'z': | |
9257 | case 'Z': | |
9258 | case '0': | |
9259 | case 'S': | |
9260 | case 'R': | |
9261 | case 'X': | |
9262 | case 'Y': | |
9263 | if (s[0] != '$') | |
9264 | break; | |
9265 | s_reset = s; | |
3882b010 | 9266 | if (ISDIGIT (s[1])) |
252b5132 RH |
9267 | { |
9268 | ++s; | |
9269 | regno = 0; | |
9270 | do | |
9271 | { | |
9272 | regno *= 10; | |
9273 | regno += *s - '0'; | |
9274 | ++s; | |
9275 | } | |
3882b010 | 9276 | while (ISDIGIT (*s)); |
252b5132 RH |
9277 | if (regno > 31) |
9278 | { | |
9279 | as_bad (_("invalid register number (%d)"), regno); | |
9280 | regno = 2; | |
9281 | } | |
9282 | } | |
9283 | else | |
9284 | { | |
76db943d TS |
9285 | if (s[1] == 'r' && s[2] == 'a') |
9286 | { | |
9287 | s += 3; | |
9288 | regno = RA; | |
9289 | } | |
9290 | else if (s[1] == 'f' && s[2] == 'p') | |
252b5132 RH |
9291 | { |
9292 | s += 3; | |
9293 | regno = FP; | |
9294 | } | |
9295 | else if (s[1] == 's' && s[2] == 'p') | |
9296 | { | |
9297 | s += 3; | |
9298 | regno = SP; | |
9299 | } | |
9300 | else if (s[1] == 'g' && s[2] == 'p') | |
9301 | { | |
9302 | s += 3; | |
9303 | regno = GP; | |
9304 | } | |
9305 | else if (s[1] == 'a' && s[2] == 't') | |
9306 | { | |
9307 | s += 3; | |
9308 | regno = AT; | |
9309 | } | |
9310 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
9311 | { | |
9312 | s += 4; | |
9313 | regno = KT0; | |
9314 | } | |
9315 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
9316 | { | |
9317 | s += 4; | |
9318 | regno = KT1; | |
9319 | } | |
85b51719 TS |
9320 | else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o') |
9321 | { | |
9322 | s += 5; | |
9323 | regno = ZERO; | |
9324 | } | |
252b5132 RH |
9325 | else |
9326 | break; | |
9327 | } | |
9328 | ||
9329 | if (*s == ' ') | |
9330 | ++s; | |
9331 | if (args[1] != *s) | |
9332 | { | |
9333 | if (c == 'v' || c == 'w') | |
9334 | { | |
9335 | regno = mips16_to_32_reg_map[lastregno]; | |
9336 | s = s_reset; | |
f9419b05 | 9337 | ++args; |
252b5132 RH |
9338 | } |
9339 | } | |
9340 | ||
9341 | switch (c) | |
9342 | { | |
9343 | case 'x': | |
9344 | case 'y': | |
9345 | case 'z': | |
9346 | case 'v': | |
9347 | case 'w': | |
9348 | case 'Z': | |
9349 | regno = mips32_to_16_reg_map[regno]; | |
9350 | break; | |
9351 | ||
9352 | case '0': | |
9353 | if (regno != 0) | |
9354 | regno = ILLEGAL_REG; | |
9355 | break; | |
9356 | ||
9357 | case 'S': | |
9358 | if (regno != SP) | |
9359 | regno = ILLEGAL_REG; | |
9360 | break; | |
9361 | ||
9362 | case 'R': | |
9363 | if (regno != RA) | |
9364 | regno = ILLEGAL_REG; | |
9365 | break; | |
9366 | ||
9367 | case 'X': | |
9368 | case 'Y': | |
9369 | if (regno == AT && ! mips_opts.noat) | |
9370 | as_warn (_("used $at without \".set noat\"")); | |
9371 | break; | |
9372 | ||
9373 | default: | |
9374 | internalError (); | |
9375 | } | |
9376 | ||
9377 | if (regno == ILLEGAL_REG) | |
9378 | break; | |
9379 | ||
9380 | switch (c) | |
9381 | { | |
9382 | case 'x': | |
9383 | case 'v': | |
9384 | ip->insn_opcode |= regno << MIPS16OP_SH_RX; | |
9385 | break; | |
9386 | case 'y': | |
9387 | case 'w': | |
9388 | ip->insn_opcode |= regno << MIPS16OP_SH_RY; | |
9389 | break; | |
9390 | case 'z': | |
9391 | ip->insn_opcode |= regno << MIPS16OP_SH_RZ; | |
9392 | break; | |
9393 | case 'Z': | |
9394 | ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z; | |
9395 | case '0': | |
9396 | case 'S': | |
9397 | case 'R': | |
9398 | break; | |
9399 | case 'X': | |
9400 | ip->insn_opcode |= regno << MIPS16OP_SH_REGR32; | |
9401 | break; | |
9402 | case 'Y': | |
9403 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
9404 | ip->insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
9405 | break; | |
9406 | default: | |
9407 | internalError (); | |
9408 | } | |
9409 | ||
9410 | lastregno = regno; | |
9411 | continue; | |
9412 | ||
9413 | case 'P': | |
9414 | if (strncmp (s, "$pc", 3) == 0) | |
9415 | { | |
9416 | s += 3; | |
9417 | continue; | |
9418 | } | |
9419 | break; | |
9420 | ||
9421 | case '<': | |
9422 | case '>': | |
9423 | case '[': | |
9424 | case ']': | |
9425 | case '4': | |
9426 | case '5': | |
9427 | case 'H': | |
9428 | case 'W': | |
9429 | case 'D': | |
9430 | case 'j': | |
9431 | case '8': | |
9432 | case 'V': | |
9433 | case 'C': | |
9434 | case 'U': | |
9435 | case 'k': | |
9436 | case 'K': | |
9437 | if (s[0] == '%' | |
9438 | && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0) | |
9439 | { | |
9440 | /* This is %gprel(SYMBOL). We need to read SYMBOL, | |
9441 | and generate the appropriate reloc. If the text | |
9442 | inside %gprel is not a symbol name with an | |
9443 | optional offset, then we generate a normal reloc | |
9444 | and will probably fail later. */ | |
9445 | my_getExpression (&imm_expr, s + sizeof "%gprel" - 1); | |
9446 | if (imm_expr.X_op == O_symbol) | |
9447 | { | |
9448 | mips16_ext = true; | |
f6688943 | 9449 | *imm_reloc = BFD_RELOC_MIPS16_GPREL; |
252b5132 RH |
9450 | s = expr_end; |
9451 | ip->use_extend = true; | |
9452 | ip->extend = 0; | |
9453 | continue; | |
9454 | } | |
9455 | } | |
9456 | else | |
9457 | { | |
9458 | /* Just pick up a normal expression. */ | |
9459 | my_getExpression (&imm_expr, s); | |
9460 | } | |
9461 | ||
9462 | if (imm_expr.X_op == O_register) | |
9463 | { | |
9464 | /* What we thought was an expression turned out to | |
9465 | be a register. */ | |
9466 | ||
9467 | if (s[0] == '(' && args[1] == '(') | |
9468 | { | |
9469 | /* It looks like the expression was omitted | |
9470 | before a register indirection, which means | |
9471 | that the expression is implicitly zero. We | |
9472 | still set up imm_expr, so that we handle | |
9473 | explicit extensions correctly. */ | |
9474 | imm_expr.X_op = O_constant; | |
9475 | imm_expr.X_add_number = 0; | |
f6688943 | 9476 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
9477 | continue; |
9478 | } | |
9479 | ||
9480 | break; | |
9481 | } | |
9482 | ||
9483 | /* We need to relax this instruction. */ | |
f6688943 | 9484 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
9485 | s = expr_end; |
9486 | continue; | |
9487 | ||
9488 | case 'p': | |
9489 | case 'q': | |
9490 | case 'A': | |
9491 | case 'B': | |
9492 | case 'E': | |
9493 | /* We use offset_reloc rather than imm_reloc for the PC | |
9494 | relative operands. This lets macros with both | |
9495 | immediate and address operands work correctly. */ | |
9496 | my_getExpression (&offset_expr, s); | |
9497 | ||
9498 | if (offset_expr.X_op == O_register) | |
9499 | break; | |
9500 | ||
9501 | /* We need to relax this instruction. */ | |
f6688943 | 9502 | *offset_reloc = (int) BFD_RELOC_UNUSED + c; |
252b5132 RH |
9503 | s = expr_end; |
9504 | continue; | |
9505 | ||
9506 | case '6': /* break code */ | |
9507 | my_getExpression (&imm_expr, s); | |
9508 | check_absolute_expr (ip, &imm_expr); | |
9509 | if ((unsigned long) imm_expr.X_add_number > 63) | |
9510 | { | |
9511 | as_warn (_("Invalid value for `%s' (%lu)"), | |
9512 | ip->insn_mo->name, | |
9513 | (unsigned long) imm_expr.X_add_number); | |
9514 | imm_expr.X_add_number &= 0x3f; | |
9515 | } | |
9516 | ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6; | |
9517 | imm_expr.X_op = O_absent; | |
9518 | s = expr_end; | |
9519 | continue; | |
9520 | ||
9521 | case 'a': /* 26 bit address */ | |
9522 | my_getExpression (&offset_expr, s); | |
9523 | s = expr_end; | |
f6688943 | 9524 | *offset_reloc = BFD_RELOC_MIPS16_JMP; |
252b5132 RH |
9525 | ip->insn_opcode <<= 16; |
9526 | continue; | |
9527 | ||
9528 | case 'l': /* register list for entry macro */ | |
9529 | case 'L': /* register list for exit macro */ | |
9530 | { | |
9531 | int mask; | |
9532 | ||
9533 | if (c == 'l') | |
9534 | mask = 0; | |
9535 | else | |
9536 | mask = 7 << 3; | |
9537 | while (*s != '\0') | |
9538 | { | |
9539 | int freg, reg1, reg2; | |
9540 | ||
9541 | while (*s == ' ' || *s == ',') | |
9542 | ++s; | |
9543 | if (*s != '$') | |
9544 | { | |
9545 | as_bad (_("can't parse register list")); | |
9546 | break; | |
9547 | } | |
9548 | ++s; | |
9549 | if (*s != 'f') | |
9550 | freg = 0; | |
9551 | else | |
9552 | { | |
9553 | freg = 1; | |
9554 | ++s; | |
9555 | } | |
9556 | reg1 = 0; | |
3882b010 | 9557 | while (ISDIGIT (*s)) |
252b5132 RH |
9558 | { |
9559 | reg1 *= 10; | |
9560 | reg1 += *s - '0'; | |
9561 | ++s; | |
9562 | } | |
9563 | if (*s == ' ') | |
9564 | ++s; | |
9565 | if (*s != '-') | |
9566 | reg2 = reg1; | |
9567 | else | |
9568 | { | |
9569 | ++s; | |
9570 | if (*s != '$') | |
9571 | break; | |
9572 | ++s; | |
9573 | if (freg) | |
9574 | { | |
9575 | if (*s == 'f') | |
9576 | ++s; | |
9577 | else | |
9578 | { | |
9579 | as_bad (_("invalid register list")); | |
9580 | break; | |
9581 | } | |
9582 | } | |
9583 | reg2 = 0; | |
3882b010 | 9584 | while (ISDIGIT (*s)) |
252b5132 RH |
9585 | { |
9586 | reg2 *= 10; | |
9587 | reg2 += *s - '0'; | |
9588 | ++s; | |
9589 | } | |
9590 | } | |
9591 | if (freg && reg1 == 0 && reg2 == 0 && c == 'L') | |
9592 | { | |
9593 | mask &= ~ (7 << 3); | |
9594 | mask |= 5 << 3; | |
9595 | } | |
9596 | else if (freg && reg1 == 0 && reg2 == 1 && c == 'L') | |
9597 | { | |
9598 | mask &= ~ (7 << 3); | |
9599 | mask |= 6 << 3; | |
9600 | } | |
9601 | else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L') | |
9602 | mask |= (reg2 - 3) << 3; | |
9603 | else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17) | |
9604 | mask |= (reg2 - 15) << 1; | |
f9419b05 | 9605 | else if (reg1 == RA && reg2 == RA) |
252b5132 RH |
9606 | mask |= 1; |
9607 | else | |
9608 | { | |
9609 | as_bad (_("invalid register list")); | |
9610 | break; | |
9611 | } | |
9612 | } | |
9613 | /* The mask is filled in in the opcode table for the | |
9614 | benefit of the disassembler. We remove it before | |
9615 | applying the actual mask. */ | |
9616 | ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6); | |
9617 | ip->insn_opcode |= mask << MIPS16OP_SH_IMM6; | |
9618 | } | |
9619 | continue; | |
9620 | ||
9621 | case 'e': /* extend code */ | |
9622 | my_getExpression (&imm_expr, s); | |
9623 | check_absolute_expr (ip, &imm_expr); | |
9624 | if ((unsigned long) imm_expr.X_add_number > 0x7ff) | |
9625 | { | |
9626 | as_warn (_("Invalid value for `%s' (%lu)"), | |
9627 | ip->insn_mo->name, | |
9628 | (unsigned long) imm_expr.X_add_number); | |
9629 | imm_expr.X_add_number &= 0x7ff; | |
9630 | } | |
9631 | ip->insn_opcode |= imm_expr.X_add_number; | |
9632 | imm_expr.X_op = O_absent; | |
9633 | s = expr_end; | |
9634 | continue; | |
9635 | ||
9636 | default: | |
9637 | internalError (); | |
9638 | } | |
9639 | break; | |
9640 | } | |
9641 | ||
9642 | /* Args don't match. */ | |
9643 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] && | |
9644 | strcmp (insn->name, insn[1].name) == 0) | |
9645 | { | |
9646 | ++insn; | |
9647 | s = argsstart; | |
9648 | continue; | |
9649 | } | |
9650 | ||
9651 | insn_error = _("illegal operands"); | |
9652 | ||
9653 | return; | |
9654 | } | |
9655 | } | |
9656 | ||
9657 | /* This structure holds information we know about a mips16 immediate | |
9658 | argument type. */ | |
9659 | ||
e972090a NC |
9660 | struct mips16_immed_operand |
9661 | { | |
252b5132 RH |
9662 | /* The type code used in the argument string in the opcode table. */ |
9663 | int type; | |
9664 | /* The number of bits in the short form of the opcode. */ | |
9665 | int nbits; | |
9666 | /* The number of bits in the extended form of the opcode. */ | |
9667 | int extbits; | |
9668 | /* The amount by which the short form is shifted when it is used; | |
9669 | for example, the sw instruction has a shift count of 2. */ | |
9670 | int shift; | |
9671 | /* The amount by which the short form is shifted when it is stored | |
9672 | into the instruction code. */ | |
9673 | int op_shift; | |
9674 | /* Non-zero if the short form is unsigned. */ | |
9675 | int unsp; | |
9676 | /* Non-zero if the extended form is unsigned. */ | |
9677 | int extu; | |
9678 | /* Non-zero if the value is PC relative. */ | |
9679 | int pcrel; | |
9680 | }; | |
9681 | ||
9682 | /* The mips16 immediate operand types. */ | |
9683 | ||
9684 | static const struct mips16_immed_operand mips16_immed_operands[] = | |
9685 | { | |
9686 | { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
9687 | { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
9688 | { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
9689 | { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
9690 | { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 }, | |
9691 | { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9692 | { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9693 | { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9694 | { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
9695 | { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 }, | |
9696 | { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9697 | { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9698 | { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
9699 | { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 }, | |
9700 | { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
9701 | { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
9702 | { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
9703 | { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
9704 | { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 }, | |
9705 | { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 }, | |
9706 | { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 } | |
9707 | }; | |
9708 | ||
9709 | #define MIPS16_NUM_IMMED \ | |
9710 | (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0]) | |
9711 | ||
9712 | /* Handle a mips16 instruction with an immediate value. This or's the | |
9713 | small immediate value into *INSN. It sets *USE_EXTEND to indicate | |
9714 | whether an extended value is needed; if one is needed, it sets | |
9715 | *EXTEND to the value. The argument type is TYPE. The value is VAL. | |
9716 | If SMALL is true, an unextended opcode was explicitly requested. | |
9717 | If EXT is true, an extended opcode was explicitly requested. If | |
9718 | WARN is true, warn if EXT does not match reality. */ | |
9719 | ||
9720 | static void | |
9721 | mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend, | |
9722 | extend) | |
9723 | char *file; | |
9724 | unsigned int line; | |
9725 | int type; | |
9726 | offsetT val; | |
9727 | boolean warn; | |
9728 | boolean small; | |
9729 | boolean ext; | |
9730 | unsigned long *insn; | |
9731 | boolean *use_extend; | |
9732 | unsigned short *extend; | |
9733 | { | |
9734 | register const struct mips16_immed_operand *op; | |
9735 | int mintiny, maxtiny; | |
9736 | boolean needext; | |
9737 | ||
9738 | op = mips16_immed_operands; | |
9739 | while (op->type != type) | |
9740 | { | |
9741 | ++op; | |
9742 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
9743 | } | |
9744 | ||
9745 | if (op->unsp) | |
9746 | { | |
9747 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
9748 | { | |
9749 | mintiny = 1; | |
9750 | maxtiny = 1 << op->nbits; | |
9751 | } | |
9752 | else | |
9753 | { | |
9754 | mintiny = 0; | |
9755 | maxtiny = (1 << op->nbits) - 1; | |
9756 | } | |
9757 | } | |
9758 | else | |
9759 | { | |
9760 | mintiny = - (1 << (op->nbits - 1)); | |
9761 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
9762 | } | |
9763 | ||
9764 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
9765 | if (type == 'p' || type == 'q') | |
9766 | val /= 2; | |
9767 | ||
9768 | if ((val & ((1 << op->shift) - 1)) != 0 | |
9769 | || val < (mintiny << op->shift) | |
9770 | || val > (maxtiny << op->shift)) | |
9771 | needext = true; | |
9772 | else | |
9773 | needext = false; | |
9774 | ||
9775 | if (warn && ext && ! needext) | |
beae10d5 KH |
9776 | as_warn_where (file, line, |
9777 | _("extended operand requested but not required")); | |
252b5132 RH |
9778 | if (small && needext) |
9779 | as_bad_where (file, line, _("invalid unextended operand value")); | |
9780 | ||
9781 | if (small || (! ext && ! needext)) | |
9782 | { | |
9783 | int insnval; | |
9784 | ||
9785 | *use_extend = false; | |
9786 | insnval = ((val >> op->shift) & ((1 << op->nbits) - 1)); | |
9787 | insnval <<= op->op_shift; | |
9788 | *insn |= insnval; | |
9789 | } | |
9790 | else | |
9791 | { | |
9792 | long minext, maxext; | |
9793 | int extval; | |
9794 | ||
9795 | if (op->extu) | |
9796 | { | |
9797 | minext = 0; | |
9798 | maxext = (1 << op->extbits) - 1; | |
9799 | } | |
9800 | else | |
9801 | { | |
9802 | minext = - (1 << (op->extbits - 1)); | |
9803 | maxext = (1 << (op->extbits - 1)) - 1; | |
9804 | } | |
9805 | if (val < minext || val > maxext) | |
9806 | as_bad_where (file, line, | |
9807 | _("operand value out of range for instruction")); | |
9808 | ||
9809 | *use_extend = true; | |
9810 | if (op->extbits == 16) | |
9811 | { | |
9812 | extval = ((val >> 11) & 0x1f) | (val & 0x7e0); | |
9813 | val &= 0x1f; | |
9814 | } | |
9815 | else if (op->extbits == 15) | |
9816 | { | |
9817 | extval = ((val >> 11) & 0xf) | (val & 0x7f0); | |
9818 | val &= 0xf; | |
9819 | } | |
9820 | else | |
9821 | { | |
9822 | extval = ((val & 0x1f) << 6) | (val & 0x20); | |
9823 | val = 0; | |
9824 | } | |
9825 | ||
9826 | *extend = (unsigned short) extval; | |
9827 | *insn |= val; | |
9828 | } | |
9829 | } | |
9830 | \f | |
ad8d3bb3 TS |
9831 | static struct percent_op_match |
9832 | { | |
9833 | const char *str; | |
9834 | const enum small_ex_type type; | |
9835 | } percent_op[] = | |
9836 | { | |
ad8d3bb3 TS |
9837 | {"%lo", S_EX_LO}, |
9838 | #ifdef OBJ_ELF | |
394f9b3a TS |
9839 | {"%call_hi", S_EX_CALL_HI}, |
9840 | {"%call_lo", S_EX_CALL_LO}, | |
ad8d3bb3 TS |
9841 | {"%call16", S_EX_CALL16}, |
9842 | {"%got_disp", S_EX_GOT_DISP}, | |
9843 | {"%got_page", S_EX_GOT_PAGE}, | |
9844 | {"%got_ofst", S_EX_GOT_OFST}, | |
9845 | {"%got_hi", S_EX_GOT_HI}, | |
9846 | {"%got_lo", S_EX_GOT_LO}, | |
394f9b3a TS |
9847 | {"%got", S_EX_GOT}, |
9848 | {"%gp_rel", S_EX_GP_REL}, | |
9849 | {"%half", S_EX_HALF}, | |
ad8d3bb3 | 9850 | {"%highest", S_EX_HIGHEST}, |
394f9b3a TS |
9851 | {"%higher", S_EX_HIGHER}, |
9852 | {"%neg", S_EX_NEG}, | |
ad8d3bb3 | 9853 | #endif |
394f9b3a | 9854 | {"%hi", S_EX_HI} |
ad8d3bb3 TS |
9855 | }; |
9856 | ||
9857 | /* Parse small expression input. STR gets adjusted to eat up whitespace. | |
9858 | It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's | |
9859 | can be nested, this is handled by blanking the innermost, parsing the | |
9860 | rest by subsequent calls. */ | |
252b5132 RH |
9861 | |
9862 | static int | |
ad8d3bb3 TS |
9863 | my_getSmallParser (str, len, nestlevel) |
9864 | char **str; | |
9865 | unsigned int *len; | |
9866 | int *nestlevel; | |
252b5132 | 9867 | { |
ad8d3bb3 TS |
9868 | *len = 0; |
9869 | *str += strspn (*str, " \t"); | |
394f9b3a | 9870 | /* Check for expression in parentheses. */ |
ad8d3bb3 | 9871 | if (**str == '(') |
252b5132 | 9872 | { |
ad8d3bb3 TS |
9873 | char *b = *str + 1 + strspn (*str + 1, " \t"); |
9874 | char *e; | |
9875 | ||
9876 | /* Check for base register. */ | |
9877 | if (b[0] == '$') | |
9878 | { | |
9879 | if (strchr (b, ')') | |
9880 | && (e = b + strcspn (b, ") \t")) | |
9881 | && e - b > 1 && e - b < 4) | |
9882 | { | |
98d3f06f KH |
9883 | if ((e - b == 3 |
9884 | && ((b[1] == 'f' && b[2] == 'p') | |
9885 | || (b[1] == 's' && b[2] == 'p') | |
9886 | || (b[1] == 'g' && b[2] == 'p') | |
9887 | || (b[1] == 'a' && b[2] == 't') | |
9888 | || (ISDIGIT (b[1]) | |
9889 | && ISDIGIT (b[2])))) | |
9890 | || (ISDIGIT (b[1]))) | |
9891 | { | |
9892 | *len = strcspn (*str, ")") + 1; | |
9893 | return S_EX_REGISTER; | |
9894 | } | |
ad8d3bb3 TS |
9895 | } |
9896 | } | |
394f9b3a | 9897 | /* Check for percent_op (in parentheses). */ |
ad8d3bb3 TS |
9898 | else if (b[0] == '%') |
9899 | { | |
9900 | *str = b; | |
394f9b3a | 9901 | return my_getPercentOp (str, len, nestlevel); |
ad8d3bb3 | 9902 | } |
76b3015f | 9903 | |
394f9b3a TS |
9904 | /* Some other expression in the parentheses, which can contain |
9905 | parentheses itself. Attempt to find the matching one. */ | |
9906 | { | |
9907 | int pcnt = 1; | |
9908 | char *s; | |
9909 | ||
9910 | *len = 1; | |
9911 | for (s = *str + 1; *s && pcnt; s++, (*len)++) | |
9912 | { | |
9913 | if (*s == '(') | |
f9419b05 | 9914 | ++pcnt; |
394f9b3a | 9915 | else if (*s == ')') |
f9419b05 | 9916 | --pcnt; |
394f9b3a TS |
9917 | } |
9918 | } | |
fb1b3232 | 9919 | } |
394f9b3a | 9920 | /* Check for percent_op (outside of parentheses). */ |
ad8d3bb3 | 9921 | else if (*str[0] == '%') |
394f9b3a TS |
9922 | return my_getPercentOp (str, len, nestlevel); |
9923 | ||
9924 | /* Any other expression. */ | |
9925 | return S_EX_NONE; | |
9926 | } | |
ad8d3bb3 | 9927 | |
394f9b3a TS |
9928 | static int |
9929 | my_getPercentOp (str, len, nestlevel) | |
9930 | char **str; | |
9931 | unsigned int *len; | |
9932 | int *nestlevel; | |
9933 | { | |
9934 | char *tmp = *str + 1; | |
9935 | unsigned int i = 0; | |
ad8d3bb3 | 9936 | |
394f9b3a TS |
9937 | while (ISALPHA (*tmp) || *tmp == '_') |
9938 | { | |
9939 | *tmp = TOLOWER (*tmp); | |
9940 | tmp++; | |
9941 | } | |
9942 | while (i < (sizeof (percent_op) / sizeof (struct percent_op_match))) | |
9943 | { | |
9944 | if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str))) | |
98d3f06f | 9945 | i++; |
394f9b3a | 9946 | else |
ad8d3bb3 | 9947 | { |
394f9b3a | 9948 | int type = percent_op[i].type; |
ad8d3bb3 | 9949 | |
394f9b3a TS |
9950 | /* Only %hi and %lo are allowed for OldABI. */ |
9951 | if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO) | |
9952 | return S_EX_NONE; | |
ad8d3bb3 | 9953 | |
394f9b3a | 9954 | *len = strlen (percent_op[i].str); |
f9419b05 | 9955 | ++(*nestlevel); |
394f9b3a | 9956 | return type; |
ad8d3bb3 | 9957 | } |
fb1b3232 | 9958 | } |
ad8d3bb3 TS |
9959 | return S_EX_NONE; |
9960 | } | |
9961 | ||
9962 | static int | |
9963 | my_getSmallExpression (ep, str) | |
9964 | expressionS *ep; | |
9965 | char *str; | |
9966 | { | |
9967 | static char *oldstr = NULL; | |
9968 | int c = S_EX_NONE; | |
9969 | int oldc; | |
394f9b3a | 9970 | int nestlevel = -1; |
ad8d3bb3 TS |
9971 | unsigned int len; |
9972 | ||
394f9b3a TS |
9973 | /* Don't update oldstr if the last call had nested percent_op's. We need |
9974 | it to parse the outer ones later. */ | |
ad8d3bb3 TS |
9975 | if (! oldstr) |
9976 | oldstr = str; | |
76b3015f | 9977 | |
ad8d3bb3 | 9978 | do |
fb1b3232 | 9979 | { |
ad8d3bb3 | 9980 | oldc = c; |
394f9b3a | 9981 | c = my_getSmallParser (&str, &len, &nestlevel); |
ad8d3bb3 TS |
9982 | if (c != S_EX_NONE && c != S_EX_REGISTER) |
9983 | str += len; | |
fb1b3232 | 9984 | } |
ad8d3bb3 TS |
9985 | while (c != S_EX_NONE && c != S_EX_REGISTER); |
9986 | ||
394f9b3a | 9987 | if (nestlevel >= 0) |
fb1b3232 | 9988 | { |
394f9b3a TS |
9989 | /* A percent_op was encountered. Don't try to get an expression if |
9990 | it is already blanked out. */ | |
ad8d3bb3 TS |
9991 | if (*(str + strspn (str + 1, " )")) != ')') |
9992 | { | |
9993 | char save; | |
9994 | ||
394f9b3a | 9995 | /* Let my_getExpression() stop at the closing parenthesis. */ |
ad8d3bb3 TS |
9996 | save = *(str + len); |
9997 | *(str + len) = '\0'; | |
9998 | my_getExpression (ep, str); | |
9999 | *(str + len) = save; | |
10000 | } | |
394f9b3a | 10001 | if (nestlevel > 0) |
ad8d3bb3 | 10002 | { |
394f9b3a TS |
10003 | /* Blank out including the % sign and the proper matching |
10004 | parenthesis. */ | |
10005 | int pcnt = 1; | |
10006 | char *s = strrchr (oldstr, '%'); | |
10007 | char *end; | |
10008 | ||
10009 | for (end = strchr (s, '(') + 1; *end && pcnt; end++) | |
10010 | { | |
10011 | if (*end == '(') | |
f9419b05 | 10012 | ++pcnt; |
394f9b3a | 10013 | else if (*end == ')') |
f9419b05 | 10014 | --pcnt; |
394f9b3a TS |
10015 | } |
10016 | ||
10017 | memset (s, ' ', end - s); | |
ad8d3bb3 TS |
10018 | str = oldstr; |
10019 | } | |
10020 | else | |
394f9b3a TS |
10021 | expr_end = str + len; |
10022 | ||
ad8d3bb3 | 10023 | c = oldc; |
fb1b3232 | 10024 | } |
ad8d3bb3 | 10025 | else if (c == S_EX_NONE) |
fb1b3232 | 10026 | { |
ad8d3bb3 | 10027 | my_getExpression (ep, str); |
fb1b3232 | 10028 | } |
ad8d3bb3 | 10029 | else if (c == S_EX_REGISTER) |
fb1b3232 | 10030 | { |
ad8d3bb3 TS |
10031 | ep->X_op = O_constant; |
10032 | expr_end = str; | |
10033 | ep->X_add_symbol = NULL; | |
10034 | ep->X_op_symbol = NULL; | |
10035 | ep->X_add_number = 0; | |
fb1b3232 | 10036 | } |
fb1b3232 TS |
10037 | else |
10038 | { | |
98d3f06f | 10039 | as_fatal (_("internal error")); |
fb1b3232 | 10040 | } |
252b5132 | 10041 | |
394f9b3a TS |
10042 | if (nestlevel <= 0) |
10043 | /* All percent_op's have been handled. */ | |
ad8d3bb3 | 10044 | oldstr = NULL; |
fb1b3232 | 10045 | |
fb1b3232 | 10046 | return c; |
252b5132 RH |
10047 | } |
10048 | ||
10049 | static void | |
10050 | my_getExpression (ep, str) | |
10051 | expressionS *ep; | |
10052 | char *str; | |
10053 | { | |
10054 | char *save_in; | |
98aa84af | 10055 | valueT val; |
252b5132 RH |
10056 | |
10057 | save_in = input_line_pointer; | |
10058 | input_line_pointer = str; | |
10059 | expression (ep); | |
10060 | expr_end = input_line_pointer; | |
10061 | input_line_pointer = save_in; | |
10062 | ||
10063 | /* If we are in mips16 mode, and this is an expression based on `.', | |
10064 | then we bump the value of the symbol by 1 since that is how other | |
10065 | text symbols are handled. We don't bother to handle complex | |
10066 | expressions, just `.' plus or minus a constant. */ | |
10067 | if (mips_opts.mips16 | |
10068 | && ep->X_op == O_symbol | |
10069 | && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0 | |
10070 | && S_GET_SEGMENT (ep->X_add_symbol) == now_seg | |
49309057 ILT |
10071 | && symbol_get_frag (ep->X_add_symbol) == frag_now |
10072 | && symbol_constant_p (ep->X_add_symbol) | |
98aa84af AM |
10073 | && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ()) |
10074 | S_SET_VALUE (ep->X_add_symbol, val + 1); | |
252b5132 RH |
10075 | } |
10076 | ||
10077 | /* Turn a string in input_line_pointer into a floating point constant | |
bc0d738a NC |
10078 | of type TYPE, and store the appropriate bytes in *LITP. The number |
10079 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
252b5132 RH |
10080 | returned, or NULL on OK. */ |
10081 | ||
10082 | char * | |
10083 | md_atof (type, litP, sizeP) | |
10084 | int type; | |
10085 | char *litP; | |
10086 | int *sizeP; | |
10087 | { | |
10088 | int prec; | |
10089 | LITTLENUM_TYPE words[4]; | |
10090 | char *t; | |
10091 | int i; | |
10092 | ||
10093 | switch (type) | |
10094 | { | |
10095 | case 'f': | |
10096 | prec = 2; | |
10097 | break; | |
10098 | ||
10099 | case 'd': | |
10100 | prec = 4; | |
10101 | break; | |
10102 | ||
10103 | default: | |
10104 | *sizeP = 0; | |
10105 | return _("bad call to md_atof"); | |
10106 | } | |
10107 | ||
10108 | t = atof_ieee (input_line_pointer, type, words); | |
10109 | if (t) | |
10110 | input_line_pointer = t; | |
10111 | ||
10112 | *sizeP = prec * 2; | |
10113 | ||
10114 | if (! target_big_endian) | |
10115 | { | |
10116 | for (i = prec - 1; i >= 0; i--) | |
10117 | { | |
10118 | md_number_to_chars (litP, (valueT) words[i], 2); | |
10119 | litP += 2; | |
10120 | } | |
10121 | } | |
10122 | else | |
10123 | { | |
10124 | for (i = 0; i < prec; i++) | |
10125 | { | |
10126 | md_number_to_chars (litP, (valueT) words[i], 2); | |
10127 | litP += 2; | |
10128 | } | |
10129 | } | |
bdaaa2e1 | 10130 | |
252b5132 RH |
10131 | return NULL; |
10132 | } | |
10133 | ||
10134 | void | |
10135 | md_number_to_chars (buf, val, n) | |
10136 | char *buf; | |
10137 | valueT val; | |
10138 | int n; | |
10139 | { | |
10140 | if (target_big_endian) | |
10141 | number_to_chars_bigendian (buf, val, n); | |
10142 | else | |
10143 | number_to_chars_littleendian (buf, val, n); | |
10144 | } | |
10145 | \f | |
ae948b86 | 10146 | #ifdef OBJ_ELF |
e013f690 TS |
10147 | static int support_64bit_objects(void) |
10148 | { | |
10149 | const char **list, **l; | |
10150 | ||
10151 | list = bfd_target_list (); | |
10152 | for (l = list; *l != NULL; l++) | |
10153 | #ifdef TE_TMIPS | |
10154 | /* This is traditional mips */ | |
10155 | if (strcmp (*l, "elf64-tradbigmips") == 0 | |
10156 | || strcmp (*l, "elf64-tradlittlemips") == 0) | |
10157 | #else | |
10158 | if (strcmp (*l, "elf64-bigmips") == 0 | |
10159 | || strcmp (*l, "elf64-littlemips") == 0) | |
10160 | #endif | |
10161 | break; | |
10162 | free (list); | |
10163 | return (*l != NULL); | |
10164 | } | |
ae948b86 | 10165 | #endif /* OBJ_ELF */ |
e013f690 | 10166 | |
5a38dc70 | 10167 | const char *md_shortopts = "nO::g::G:"; |
252b5132 | 10168 | |
e972090a NC |
10169 | struct option md_longopts[] = |
10170 | { | |
252b5132 RH |
10171 | #define OPTION_MIPS1 (OPTION_MD_BASE + 1) |
10172 | {"mips0", no_argument, NULL, OPTION_MIPS1}, | |
10173 | {"mips1", no_argument, NULL, OPTION_MIPS1}, | |
10174 | #define OPTION_MIPS2 (OPTION_MD_BASE + 2) | |
10175 | {"mips2", no_argument, NULL, OPTION_MIPS2}, | |
10176 | #define OPTION_MIPS3 (OPTION_MD_BASE + 3) | |
10177 | {"mips3", no_argument, NULL, OPTION_MIPS3}, | |
10178 | #define OPTION_MIPS4 (OPTION_MD_BASE + 4) | |
10179 | {"mips4", no_argument, NULL, OPTION_MIPS4}, | |
ae948b86 TS |
10180 | #define OPTION_MIPS5 (OPTION_MD_BASE + 5) |
10181 | {"mips5", no_argument, NULL, OPTION_MIPS5}, | |
10182 | #define OPTION_MIPS32 (OPTION_MD_BASE + 6) | |
10183 | {"mips32", no_argument, NULL, OPTION_MIPS32}, | |
10184 | #define OPTION_MIPS64 (OPTION_MD_BASE + 7) | |
10185 | {"mips64", no_argument, NULL, OPTION_MIPS64}, | |
10186 | #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8) | |
252b5132 | 10187 | {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC}, |
ae948b86 | 10188 | #define OPTION_TRAP (OPTION_MD_BASE + 9) |
252b5132 RH |
10189 | {"trap", no_argument, NULL, OPTION_TRAP}, |
10190 | {"no-break", no_argument, NULL, OPTION_TRAP}, | |
ae948b86 | 10191 | #define OPTION_BREAK (OPTION_MD_BASE + 10) |
252b5132 RH |
10192 | {"break", no_argument, NULL, OPTION_BREAK}, |
10193 | {"no-trap", no_argument, NULL, OPTION_BREAK}, | |
ae948b86 | 10194 | #define OPTION_EB (OPTION_MD_BASE + 11) |
252b5132 | 10195 | {"EB", no_argument, NULL, OPTION_EB}, |
ae948b86 | 10196 | #define OPTION_EL (OPTION_MD_BASE + 12) |
252b5132 | 10197 | {"EL", no_argument, NULL, OPTION_EL}, |
ae948b86 | 10198 | #define OPTION_MIPS16 (OPTION_MD_BASE + 13) |
252b5132 | 10199 | {"mips16", no_argument, NULL, OPTION_MIPS16}, |
ae948b86 | 10200 | #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14) |
252b5132 | 10201 | {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16}, |
ae948b86 | 10202 | #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15) |
6b76fefe | 10203 | {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX}, |
9ee72ff1 TS |
10204 | #define OPTION_MNO_7000_HILO_FIX (OPTION_MD_BASE + 16) |
10205 | {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX}, | |
10206 | {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX}, | |
ae948b86 TS |
10207 | #define OPTION_FP32 (OPTION_MD_BASE + 17) |
10208 | {"mfp32", no_argument, NULL, OPTION_FP32}, | |
10209 | #define OPTION_GP32 (OPTION_MD_BASE + 18) | |
c97ef257 | 10210 | {"mgp32", no_argument, NULL, OPTION_GP32}, |
ae948b86 | 10211 | #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19) |
119d663a | 10212 | {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS}, |
ae948b86 | 10213 | #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20) |
119d663a | 10214 | {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS}, |
ae948b86 | 10215 | #define OPTION_MARCH (OPTION_MD_BASE + 21) |
ec68c924 | 10216 | {"march", required_argument, NULL, OPTION_MARCH}, |
ae948b86 | 10217 | #define OPTION_MTUNE (OPTION_MD_BASE + 22) |
ec68c924 | 10218 | {"mtune", required_argument, NULL, OPTION_MTUNE}, |
316f5878 RS |
10219 | #define OPTION_FP64 (OPTION_MD_BASE + 23) |
10220 | {"mfp64", no_argument, NULL, OPTION_FP64}, | |
ae948b86 TS |
10221 | #define OPTION_M4650 (OPTION_MD_BASE + 24) |
10222 | {"m4650", no_argument, NULL, OPTION_M4650}, | |
10223 | #define OPTION_NO_M4650 (OPTION_MD_BASE + 25) | |
10224 | {"no-m4650", no_argument, NULL, OPTION_NO_M4650}, | |
10225 | #define OPTION_M4010 (OPTION_MD_BASE + 26) | |
10226 | {"m4010", no_argument, NULL, OPTION_M4010}, | |
10227 | #define OPTION_NO_M4010 (OPTION_MD_BASE + 27) | |
10228 | {"no-m4010", no_argument, NULL, OPTION_NO_M4010}, | |
10229 | #define OPTION_M4100 (OPTION_MD_BASE + 28) | |
10230 | {"m4100", no_argument, NULL, OPTION_M4100}, | |
10231 | #define OPTION_NO_M4100 (OPTION_MD_BASE + 29) | |
10232 | {"no-m4100", no_argument, NULL, OPTION_NO_M4100}, | |
10233 | #define OPTION_M3900 (OPTION_MD_BASE + 30) | |
10234 | {"m3900", no_argument, NULL, OPTION_M3900}, | |
10235 | #define OPTION_NO_M3900 (OPTION_MD_BASE + 31) | |
10236 | {"no-m3900", no_argument, NULL, OPTION_NO_M3900}, | |
10237 | #define OPTION_GP64 (OPTION_MD_BASE + 32) | |
10238 | {"mgp64", no_argument, NULL, OPTION_GP64}, | |
1f25f5d3 CD |
10239 | #define OPTION_MIPS3D (OPTION_MD_BASE + 33) |
10240 | {"mips3d", no_argument, NULL, OPTION_MIPS3D}, | |
10241 | #define OPTION_NO_MIPS3D (OPTION_MD_BASE + 34) | |
10242 | {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D}, | |
deec1734 CD |
10243 | #define OPTION_MDMX (OPTION_MD_BASE + 35) |
10244 | {"mdmx", no_argument, NULL, OPTION_MDMX}, | |
10245 | #define OPTION_NO_MDMX (OPTION_MD_BASE + 36) | |
10246 | {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX}, | |
60b63b72 RS |
10247 | #define OPTION_FIX_VR4122 (OPTION_MD_BASE + 37) |
10248 | #define OPTION_NO_FIX_VR4122 (OPTION_MD_BASE + 38) | |
10249 | {"mfix-vr4122-bugs", no_argument, NULL, OPTION_FIX_VR4122}, | |
10250 | {"no-mfix-vr4122-bugs", no_argument, NULL, OPTION_NO_FIX_VR4122}, | |
4a6a3df4 AO |
10251 | #define OPTION_RELAX_BRANCH (OPTION_MD_BASE + 39) |
10252 | #define OPTION_NO_RELAX_BRANCH (OPTION_MD_BASE + 40) | |
10253 | {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH}, | |
10254 | {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH}, | |
156c2f8b | 10255 | #ifdef OBJ_ELF |
4a6a3df4 | 10256 | #define OPTION_ELF_BASE (OPTION_MD_BASE + 41) |
156c2f8b | 10257 | #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0) |
156c2f8b NC |
10258 | {"KPIC", no_argument, NULL, OPTION_CALL_SHARED}, |
10259 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, | |
ae948b86 | 10260 | #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1) |
156c2f8b | 10261 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, |
ae948b86 | 10262 | #define OPTION_XGOT (OPTION_ELF_BASE + 2) |
156c2f8b | 10263 | {"xgot", no_argument, NULL, OPTION_XGOT}, |
ae948b86 TS |
10264 | #define OPTION_MABI (OPTION_ELF_BASE + 3) |
10265 | {"mabi", required_argument, NULL, OPTION_MABI}, | |
10266 | #define OPTION_32 (OPTION_ELF_BASE + 4) | |
156c2f8b | 10267 | {"32", no_argument, NULL, OPTION_32}, |
ae948b86 | 10268 | #define OPTION_N32 (OPTION_ELF_BASE + 5) |
e013f690 | 10269 | {"n32", no_argument, NULL, OPTION_N32}, |
ae948b86 | 10270 | #define OPTION_64 (OPTION_ELF_BASE + 6) |
156c2f8b | 10271 | {"64", no_argument, NULL, OPTION_64}, |
ecb4347a DJ |
10272 | #define OPTION_MDEBUG (OPTION_ELF_BASE + 7) |
10273 | {"mdebug", no_argument, NULL, OPTION_MDEBUG}, | |
10274 | #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8) | |
10275 | {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG}, | |
ae948b86 | 10276 | #endif /* OBJ_ELF */ |
252b5132 RH |
10277 | {NULL, no_argument, NULL, 0} |
10278 | }; | |
156c2f8b | 10279 | size_t md_longopts_size = sizeof (md_longopts); |
252b5132 | 10280 | |
316f5878 RS |
10281 | /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to |
10282 | NEW_VALUE. Warn if another value was already specified. Note: | |
10283 | we have to defer parsing the -march and -mtune arguments in order | |
10284 | to handle 'from-abi' correctly, since the ABI might be specified | |
10285 | in a later argument. */ | |
10286 | ||
10287 | static void | |
10288 | mips_set_option_string (string_ptr, new_value) | |
10289 | const char **string_ptr, *new_value; | |
10290 | { | |
10291 | if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0) | |
10292 | as_warn (_("A different %s was already specified, is now %s"), | |
10293 | string_ptr == &mips_arch_string ? "-march" : "-mtune", | |
10294 | new_value); | |
10295 | ||
10296 | *string_ptr = new_value; | |
10297 | } | |
10298 | ||
252b5132 RH |
10299 | int |
10300 | md_parse_option (c, arg) | |
10301 | int c; | |
10302 | char *arg; | |
10303 | { | |
10304 | switch (c) | |
10305 | { | |
119d663a NC |
10306 | case OPTION_CONSTRUCT_FLOATS: |
10307 | mips_disable_float_construction = 0; | |
10308 | break; | |
bdaaa2e1 | 10309 | |
119d663a NC |
10310 | case OPTION_NO_CONSTRUCT_FLOATS: |
10311 | mips_disable_float_construction = 1; | |
10312 | break; | |
bdaaa2e1 | 10313 | |
252b5132 RH |
10314 | case OPTION_TRAP: |
10315 | mips_trap = 1; | |
10316 | break; | |
10317 | ||
10318 | case OPTION_BREAK: | |
10319 | mips_trap = 0; | |
10320 | break; | |
10321 | ||
10322 | case OPTION_EB: | |
10323 | target_big_endian = 1; | |
10324 | break; | |
10325 | ||
10326 | case OPTION_EL: | |
10327 | target_big_endian = 0; | |
10328 | break; | |
10329 | ||
39c0a331 L |
10330 | case 'n': |
10331 | warn_nops = 1; | |
10332 | break; | |
10333 | ||
252b5132 RH |
10334 | case 'O': |
10335 | if (arg && arg[1] == '0') | |
10336 | mips_optimize = 1; | |
10337 | else | |
10338 | mips_optimize = 2; | |
10339 | break; | |
10340 | ||
10341 | case 'g': | |
10342 | if (arg == NULL) | |
10343 | mips_debug = 2; | |
10344 | else | |
10345 | mips_debug = atoi (arg); | |
10346 | /* When the MIPS assembler sees -g or -g2, it does not do | |
10347 | optimizations which limit full symbolic debugging. We take | |
10348 | that to be equivalent to -O0. */ | |
10349 | if (mips_debug == 2) | |
10350 | mips_optimize = 1; | |
10351 | break; | |
10352 | ||
10353 | case OPTION_MIPS1: | |
316f5878 | 10354 | file_mips_isa = ISA_MIPS1; |
252b5132 RH |
10355 | break; |
10356 | ||
10357 | case OPTION_MIPS2: | |
316f5878 | 10358 | file_mips_isa = ISA_MIPS2; |
252b5132 RH |
10359 | break; |
10360 | ||
10361 | case OPTION_MIPS3: | |
316f5878 | 10362 | file_mips_isa = ISA_MIPS3; |
252b5132 RH |
10363 | break; |
10364 | ||
10365 | case OPTION_MIPS4: | |
316f5878 | 10366 | file_mips_isa = ISA_MIPS4; |
e7af610e NC |
10367 | break; |
10368 | ||
84ea6cf2 | 10369 | case OPTION_MIPS5: |
316f5878 | 10370 | file_mips_isa = ISA_MIPS5; |
84ea6cf2 NC |
10371 | break; |
10372 | ||
e7af610e | 10373 | case OPTION_MIPS32: |
316f5878 | 10374 | file_mips_isa = ISA_MIPS32; |
252b5132 RH |
10375 | break; |
10376 | ||
84ea6cf2 | 10377 | case OPTION_MIPS64: |
316f5878 | 10378 | file_mips_isa = ISA_MIPS64; |
84ea6cf2 NC |
10379 | break; |
10380 | ||
ec68c924 | 10381 | case OPTION_MTUNE: |
316f5878 RS |
10382 | mips_set_option_string (&mips_tune_string, arg); |
10383 | break; | |
ec68c924 | 10384 | |
316f5878 RS |
10385 | case OPTION_MARCH: |
10386 | mips_set_option_string (&mips_arch_string, arg); | |
252b5132 RH |
10387 | break; |
10388 | ||
10389 | case OPTION_M4650: | |
316f5878 RS |
10390 | mips_set_option_string (&mips_arch_string, "4650"); |
10391 | mips_set_option_string (&mips_tune_string, "4650"); | |
252b5132 RH |
10392 | break; |
10393 | ||
10394 | case OPTION_NO_M4650: | |
10395 | break; | |
10396 | ||
10397 | case OPTION_M4010: | |
316f5878 RS |
10398 | mips_set_option_string (&mips_arch_string, "4010"); |
10399 | mips_set_option_string (&mips_tune_string, "4010"); | |
252b5132 RH |
10400 | break; |
10401 | ||
10402 | case OPTION_NO_M4010: | |
10403 | break; | |
10404 | ||
10405 | case OPTION_M4100: | |
316f5878 RS |
10406 | mips_set_option_string (&mips_arch_string, "4100"); |
10407 | mips_set_option_string (&mips_tune_string, "4100"); | |
252b5132 RH |
10408 | break; |
10409 | ||
10410 | case OPTION_NO_M4100: | |
10411 | break; | |
10412 | ||
252b5132 | 10413 | case OPTION_M3900: |
316f5878 RS |
10414 | mips_set_option_string (&mips_arch_string, "3900"); |
10415 | mips_set_option_string (&mips_tune_string, "3900"); | |
252b5132 | 10416 | break; |
bdaaa2e1 | 10417 | |
252b5132 RH |
10418 | case OPTION_NO_M3900: |
10419 | break; | |
10420 | ||
deec1734 CD |
10421 | case OPTION_MDMX: |
10422 | mips_opts.ase_mdmx = 1; | |
10423 | break; | |
10424 | ||
10425 | case OPTION_NO_MDMX: | |
10426 | mips_opts.ase_mdmx = 0; | |
10427 | break; | |
10428 | ||
252b5132 RH |
10429 | case OPTION_MIPS16: |
10430 | mips_opts.mips16 = 1; | |
10431 | mips_no_prev_insn (false); | |
10432 | break; | |
10433 | ||
10434 | case OPTION_NO_MIPS16: | |
10435 | mips_opts.mips16 = 0; | |
10436 | mips_no_prev_insn (false); | |
10437 | break; | |
10438 | ||
1f25f5d3 CD |
10439 | case OPTION_MIPS3D: |
10440 | mips_opts.ase_mips3d = 1; | |
10441 | break; | |
10442 | ||
10443 | case OPTION_NO_MIPS3D: | |
10444 | mips_opts.ase_mips3d = 0; | |
10445 | break; | |
10446 | ||
252b5132 RH |
10447 | case OPTION_MEMBEDDED_PIC: |
10448 | mips_pic = EMBEDDED_PIC; | |
10449 | if (USE_GLOBAL_POINTER_OPT && g_switch_seen) | |
10450 | { | |
10451 | as_bad (_("-G may not be used with embedded PIC code")); | |
10452 | return 0; | |
10453 | } | |
10454 | g_switch_value = 0x7fffffff; | |
10455 | break; | |
10456 | ||
60b63b72 RS |
10457 | case OPTION_FIX_VR4122: |
10458 | mips_fix_4122_bugs = 1; | |
10459 | break; | |
10460 | ||
10461 | case OPTION_NO_FIX_VR4122: | |
10462 | mips_fix_4122_bugs = 0; | |
10463 | break; | |
10464 | ||
4a6a3df4 AO |
10465 | case OPTION_RELAX_BRANCH: |
10466 | mips_relax_branch = 1; | |
10467 | break; | |
10468 | ||
10469 | case OPTION_NO_RELAX_BRANCH: | |
10470 | mips_relax_branch = 0; | |
10471 | break; | |
10472 | ||
0f074f60 | 10473 | #ifdef OBJ_ELF |
252b5132 RH |
10474 | /* When generating ELF code, we permit -KPIC and -call_shared to |
10475 | select SVR4_PIC, and -non_shared to select no PIC. This is | |
10476 | intended to be compatible with Irix 5. */ | |
10477 | case OPTION_CALL_SHARED: | |
10478 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
10479 | { | |
10480 | as_bad (_("-call_shared is supported only for ELF format")); | |
10481 | return 0; | |
10482 | } | |
10483 | mips_pic = SVR4_PIC; | |
10484 | if (g_switch_seen && g_switch_value != 0) | |
10485 | { | |
10486 | as_bad (_("-G may not be used with SVR4 PIC code")); | |
10487 | return 0; | |
10488 | } | |
10489 | g_switch_value = 0; | |
10490 | break; | |
10491 | ||
10492 | case OPTION_NON_SHARED: | |
10493 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
10494 | { | |
10495 | as_bad (_("-non_shared is supported only for ELF format")); | |
10496 | return 0; | |
10497 | } | |
10498 | mips_pic = NO_PIC; | |
10499 | break; | |
10500 | ||
10501 | /* The -xgot option tells the assembler to use 32 offsets when | |
10502 | accessing the got in SVR4_PIC mode. It is for Irix | |
10503 | compatibility. */ | |
10504 | case OPTION_XGOT: | |
10505 | mips_big_got = 1; | |
10506 | break; | |
0f074f60 | 10507 | #endif /* OBJ_ELF */ |
252b5132 RH |
10508 | |
10509 | case 'G': | |
10510 | if (! USE_GLOBAL_POINTER_OPT) | |
10511 | { | |
10512 | as_bad (_("-G is not supported for this configuration")); | |
10513 | return 0; | |
10514 | } | |
10515 | else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC) | |
10516 | { | |
10517 | as_bad (_("-G may not be used with SVR4 or embedded PIC code")); | |
10518 | return 0; | |
10519 | } | |
10520 | else | |
10521 | g_switch_value = atoi (arg); | |
10522 | g_switch_seen = 1; | |
10523 | break; | |
10524 | ||
0f074f60 | 10525 | #ifdef OBJ_ELF |
34ba82a8 TS |
10526 | /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32 |
10527 | and -mabi=64. */ | |
252b5132 | 10528 | case OPTION_32: |
34ba82a8 TS |
10529 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
10530 | { | |
10531 | as_bad (_("-32 is supported for ELF format only")); | |
10532 | return 0; | |
10533 | } | |
316f5878 | 10534 | mips_abi = O32_ABI; |
252b5132 RH |
10535 | break; |
10536 | ||
e013f690 | 10537 | case OPTION_N32: |
34ba82a8 TS |
10538 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
10539 | { | |
10540 | as_bad (_("-n32 is supported for ELF format only")); | |
10541 | return 0; | |
10542 | } | |
316f5878 | 10543 | mips_abi = N32_ABI; |
e013f690 | 10544 | break; |
252b5132 | 10545 | |
e013f690 | 10546 | case OPTION_64: |
34ba82a8 TS |
10547 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
10548 | { | |
10549 | as_bad (_("-64 is supported for ELF format only")); | |
10550 | return 0; | |
10551 | } | |
316f5878 | 10552 | mips_abi = N64_ABI; |
e013f690 TS |
10553 | if (! support_64bit_objects()) |
10554 | as_fatal (_("No compiled in support for 64 bit object file format")); | |
252b5132 | 10555 | break; |
ae948b86 | 10556 | #endif /* OBJ_ELF */ |
252b5132 | 10557 | |
c97ef257 | 10558 | case OPTION_GP32: |
a325df1d | 10559 | file_mips_gp32 = 1; |
c97ef257 AH |
10560 | break; |
10561 | ||
10562 | case OPTION_GP64: | |
a325df1d | 10563 | file_mips_gp32 = 0; |
c97ef257 | 10564 | break; |
252b5132 | 10565 | |
ca4e0257 | 10566 | case OPTION_FP32: |
a325df1d | 10567 | file_mips_fp32 = 1; |
316f5878 RS |
10568 | break; |
10569 | ||
10570 | case OPTION_FP64: | |
10571 | file_mips_fp32 = 0; | |
ca4e0257 RS |
10572 | break; |
10573 | ||
ae948b86 | 10574 | #ifdef OBJ_ELF |
252b5132 | 10575 | case OPTION_MABI: |
34ba82a8 TS |
10576 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
10577 | { | |
10578 | as_bad (_("-mabi is supported for ELF format only")); | |
10579 | return 0; | |
10580 | } | |
e013f690 | 10581 | if (strcmp (arg, "32") == 0) |
316f5878 | 10582 | mips_abi = O32_ABI; |
e013f690 | 10583 | else if (strcmp (arg, "o64") == 0) |
316f5878 | 10584 | mips_abi = O64_ABI; |
e013f690 | 10585 | else if (strcmp (arg, "n32") == 0) |
316f5878 | 10586 | mips_abi = N32_ABI; |
e013f690 TS |
10587 | else if (strcmp (arg, "64") == 0) |
10588 | { | |
316f5878 | 10589 | mips_abi = N64_ABI; |
e013f690 TS |
10590 | if (! support_64bit_objects()) |
10591 | as_fatal (_("No compiled in support for 64 bit object file " | |
10592 | "format")); | |
10593 | } | |
10594 | else if (strcmp (arg, "eabi") == 0) | |
316f5878 | 10595 | mips_abi = EABI_ABI; |
e013f690 | 10596 | else |
da0e507f TS |
10597 | { |
10598 | as_fatal (_("invalid abi -mabi=%s"), arg); | |
10599 | return 0; | |
10600 | } | |
252b5132 | 10601 | break; |
e013f690 | 10602 | #endif /* OBJ_ELF */ |
252b5132 | 10603 | |
6b76fefe CM |
10604 | case OPTION_M7000_HILO_FIX: |
10605 | mips_7000_hilo_fix = true; | |
10606 | break; | |
10607 | ||
9ee72ff1 | 10608 | case OPTION_MNO_7000_HILO_FIX: |
6b76fefe CM |
10609 | mips_7000_hilo_fix = false; |
10610 | break; | |
10611 | ||
ecb4347a DJ |
10612 | #ifdef OBJ_ELF |
10613 | case OPTION_MDEBUG: | |
10614 | mips_flag_mdebug = true; | |
10615 | break; | |
10616 | ||
10617 | case OPTION_NO_MDEBUG: | |
10618 | mips_flag_mdebug = false; | |
10619 | break; | |
10620 | #endif /* OBJ_ELF */ | |
10621 | ||
252b5132 RH |
10622 | default: |
10623 | return 0; | |
10624 | } | |
10625 | ||
10626 | return 1; | |
10627 | } | |
316f5878 RS |
10628 | \f |
10629 | /* Set up globals to generate code for the ISA or processor | |
10630 | described by INFO. */ | |
252b5132 | 10631 | |
252b5132 | 10632 | static void |
316f5878 RS |
10633 | mips_set_architecture (info) |
10634 | const struct mips_cpu_info *info; | |
252b5132 | 10635 | { |
316f5878 | 10636 | if (info != 0) |
252b5132 | 10637 | { |
316f5878 RS |
10638 | mips_arch_info = info; |
10639 | mips_arch = info->cpu; | |
10640 | mips_opts.isa = info->isa; | |
252b5132 | 10641 | } |
252b5132 RH |
10642 | } |
10643 | ||
252b5132 | 10644 | |
316f5878 | 10645 | /* Likewise for tuning. */ |
252b5132 | 10646 | |
316f5878 RS |
10647 | static void |
10648 | mips_set_tune (info) | |
10649 | const struct mips_cpu_info *info; | |
10650 | { | |
10651 | if (info != 0) | |
10652 | { | |
10653 | mips_tune_info = info; | |
10654 | mips_tune = info->cpu; | |
10655 | } | |
10656 | } | |
80cc45a5 | 10657 | |
34ba82a8 | 10658 | |
252b5132 | 10659 | void |
e9670677 MR |
10660 | mips_after_parse_args () |
10661 | { | |
e9670677 MR |
10662 | /* GP relative stuff not working for PE */ |
10663 | if (strncmp (TARGET_OS, "pe", 2) == 0 | |
10664 | && g_switch_value != 0) | |
10665 | { | |
10666 | if (g_switch_seen) | |
10667 | as_bad (_("-G not supported in this configuration.")); | |
10668 | g_switch_value = 0; | |
10669 | } | |
10670 | ||
22923709 RS |
10671 | /* The following code determines the architecture and register size. |
10672 | Similar code was added to GCC 3.3 (see override_options() in | |
10673 | config/mips/mips.c). The GAS and GCC code should be kept in sync | |
10674 | as much as possible. */ | |
e9670677 | 10675 | |
316f5878 RS |
10676 | if (mips_arch_string != 0) |
10677 | mips_set_architecture (mips_parse_cpu ("-march", mips_arch_string)); | |
e9670677 | 10678 | |
316f5878 RS |
10679 | if (mips_tune_string != 0) |
10680 | mips_set_tune (mips_parse_cpu ("-mtune", mips_tune_string)); | |
e9670677 | 10681 | |
316f5878 | 10682 | if (file_mips_isa != ISA_UNKNOWN) |
e9670677 | 10683 | { |
316f5878 RS |
10684 | /* Handle -mipsN. At this point, file_mips_isa contains the |
10685 | ISA level specified by -mipsN, while mips_opts.isa contains | |
10686 | the -march selection (if any). */ | |
10687 | if (mips_arch_info != 0) | |
e9670677 | 10688 | { |
316f5878 RS |
10689 | /* -march takes precedence over -mipsN, since it is more descriptive. |
10690 | There's no harm in specifying both as long as the ISA levels | |
10691 | are the same. */ | |
10692 | if (file_mips_isa != mips_opts.isa) | |
10693 | as_bad (_("-%s conflicts with the other architecture options, which imply -%s"), | |
10694 | mips_cpu_info_from_isa (file_mips_isa)->name, | |
10695 | mips_cpu_info_from_isa (mips_opts.isa)->name); | |
e9670677 | 10696 | } |
316f5878 RS |
10697 | else |
10698 | mips_set_architecture (mips_cpu_info_from_isa (file_mips_isa)); | |
e9670677 MR |
10699 | } |
10700 | ||
316f5878 RS |
10701 | if (mips_arch_info == 0) |
10702 | mips_set_architecture (mips_parse_cpu ("default CPU", | |
10703 | MIPS_CPU_STRING_DEFAULT)); | |
e9670677 | 10704 | |
316f5878 RS |
10705 | if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (mips_opts.isa)) |
10706 | as_bad ("-march=%s is not compatible with the selected ABI", | |
10707 | mips_arch_info->name); | |
e9670677 | 10708 | |
316f5878 RS |
10709 | /* Optimize for mips_arch, unless -mtune selects a different processor. */ |
10710 | if (mips_tune_info == 0) | |
10711 | mips_set_tune (mips_arch_info); | |
e9670677 | 10712 | |
316f5878 | 10713 | if (file_mips_gp32 >= 0) |
e9670677 | 10714 | { |
316f5878 RS |
10715 | /* The user specified the size of the integer registers. Make sure |
10716 | it agrees with the ABI and ISA. */ | |
10717 | if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
10718 | as_bad (_("-mgp64 used with a 32-bit processor")); | |
10719 | else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi)) | |
10720 | as_bad (_("-mgp32 used with a 64-bit ABI")); | |
10721 | else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi)) | |
10722 | as_bad (_("-mgp64 used with a 32-bit ABI")); | |
e9670677 MR |
10723 | } |
10724 | else | |
10725 | { | |
316f5878 RS |
10726 | /* Infer the integer register size from the ABI and processor. |
10727 | Restrict ourselves to 32-bit registers if that's all the | |
10728 | processor has, or if the ABI cannot handle 64-bit registers. */ | |
10729 | file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi) | |
10730 | || !ISA_HAS_64BIT_REGS (mips_opts.isa)); | |
e9670677 MR |
10731 | } |
10732 | ||
316f5878 RS |
10733 | /* ??? GAS treats single-float processors as though they had 64-bit |
10734 | float registers (although it complains when double-precision | |
10735 | instructions are used). As things stand, saying they have 32-bit | |
10736 | registers would lead to spurious "register must be even" messages. | |
10737 | So here we assume float registers are always the same size as | |
10738 | integer ones, unless the user says otherwise. */ | |
10739 | if (file_mips_fp32 < 0) | |
10740 | file_mips_fp32 = file_mips_gp32; | |
e9670677 | 10741 | |
316f5878 | 10742 | /* End of GCC-shared inference code. */ |
e9670677 | 10743 | |
316f5878 RS |
10744 | /* ??? When do we want this flag to be set? Who uses it? */ |
10745 | if (file_mips_gp32 == 1 | |
10746 | && mips_abi == NO_ABI | |
10747 | && ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
10748 | mips_32bitmode = 1; | |
e9670677 MR |
10749 | |
10750 | if (mips_opts.isa == ISA_MIPS1 && mips_trap) | |
10751 | as_bad (_("trap exception not supported at ISA 1")); | |
10752 | ||
e9670677 MR |
10753 | /* If the selected architecture includes support for ASEs, enable |
10754 | generation of code for them. */ | |
a4672219 TS |
10755 | if (mips_opts.mips16 == -1) |
10756 | mips_opts.mips16 = (CPU_HAS_MIPS16 (mips_arch)) ? 1 : 0; | |
ffdefa66 | 10757 | if (mips_opts.ase_mips3d == -1) |
a4672219 | 10758 | mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (mips_arch)) ? 1 : 0; |
ffdefa66 | 10759 | if (mips_opts.ase_mdmx == -1) |
a4672219 | 10760 | mips_opts.ase_mdmx = (CPU_HAS_MDMX (mips_arch)) ? 1 : 0; |
e9670677 | 10761 | |
e9670677 | 10762 | file_mips_isa = mips_opts.isa; |
a4672219 | 10763 | file_ase_mips16 = mips_opts.mips16; |
e9670677 MR |
10764 | file_ase_mips3d = mips_opts.ase_mips3d; |
10765 | file_ase_mdmx = mips_opts.ase_mdmx; | |
10766 | mips_opts.gp32 = file_mips_gp32; | |
10767 | mips_opts.fp32 = file_mips_fp32; | |
10768 | ||
ecb4347a DJ |
10769 | if (mips_flag_mdebug < 0) |
10770 | { | |
10771 | #ifdef OBJ_MAYBE_ECOFF | |
10772 | if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour) | |
10773 | mips_flag_mdebug = 1; | |
10774 | else | |
10775 | #endif /* OBJ_MAYBE_ECOFF */ | |
10776 | mips_flag_mdebug = 0; | |
10777 | } | |
e9670677 MR |
10778 | } |
10779 | \f | |
10780 | void | |
252b5132 RH |
10781 | mips_init_after_args () |
10782 | { | |
10783 | /* initialize opcodes */ | |
10784 | bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes; | |
beae10d5 | 10785 | mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes; |
252b5132 RH |
10786 | } |
10787 | ||
10788 | long | |
10789 | md_pcrel_from (fixP) | |
10790 | fixS *fixP; | |
10791 | { | |
10792 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour | |
10793 | && fixP->fx_addsy != (symbolS *) NULL | |
10794 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
10795 | { | |
6478892d TS |
10796 | /* This makes a branch to an undefined symbol be a branch to the |
10797 | current location. */ | |
cb56d3d3 | 10798 | if (mips_pic == EMBEDDED_PIC) |
6478892d | 10799 | return 4; |
cb56d3d3 | 10800 | else |
6478892d | 10801 | return 1; |
252b5132 RH |
10802 | } |
10803 | ||
c9914766 | 10804 | /* Return the address of the delay slot. */ |
252b5132 RH |
10805 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; |
10806 | } | |
10807 | ||
252b5132 RH |
10808 | /* This is called before the symbol table is processed. In order to |
10809 | work with gcc when using mips-tfile, we must keep all local labels. | |
10810 | However, in other cases, we want to discard them. If we were | |
10811 | called with -g, but we didn't see any debugging information, it may | |
10812 | mean that gcc is smuggling debugging information through to | |
10813 | mips-tfile, in which case we must generate all local labels. */ | |
10814 | ||
10815 | void | |
10816 | mips_frob_file_before_adjust () | |
10817 | { | |
10818 | #ifndef NO_ECOFF_DEBUGGING | |
10819 | if (ECOFF_DEBUGGING | |
10820 | && mips_debug != 0 | |
10821 | && ! ecoff_debugging_seen) | |
10822 | flag_keep_locals = 1; | |
10823 | #endif | |
10824 | } | |
10825 | ||
10826 | /* Sort any unmatched HI16_S relocs so that they immediately precede | |
94f592af | 10827 | the corresponding LO reloc. This is called before md_apply_fix3 and |
252b5132 RH |
10828 | tc_gen_reloc. Unmatched HI16_S relocs can only be generated by |
10829 | explicit use of the %hi modifier. */ | |
10830 | ||
10831 | void | |
10832 | mips_frob_file () | |
10833 | { | |
10834 | struct mips_hi_fixup *l; | |
10835 | ||
10836 | for (l = mips_hi_fixup_list; l != NULL; l = l->next) | |
10837 | { | |
10838 | segment_info_type *seginfo; | |
10839 | int pass; | |
10840 | ||
10841 | assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S); | |
10842 | ||
10843 | /* Check quickly whether the next fixup happens to be a matching | |
10844 | %lo. */ | |
10845 | if (l->fixp->fx_next != NULL | |
10846 | && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16 | |
10847 | && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy | |
10848 | && l->fixp->fx_offset == l->fixp->fx_next->fx_offset) | |
10849 | continue; | |
10850 | ||
10851 | /* Look through the fixups for this segment for a matching %lo. | |
10852 | When we find one, move the %hi just in front of it. We do | |
10853 | this in two passes. In the first pass, we try to find a | |
10854 | unique %lo. In the second pass, we permit multiple %hi | |
10855 | relocs for a single %lo (this is a GNU extension). */ | |
10856 | seginfo = seg_info (l->seg); | |
10857 | for (pass = 0; pass < 2; pass++) | |
10858 | { | |
10859 | fixS *f, *prev; | |
10860 | ||
10861 | prev = NULL; | |
10862 | for (f = seginfo->fix_root; f != NULL; f = f->fx_next) | |
10863 | { | |
10864 | /* Check whether this is a %lo fixup which matches l->fixp. */ | |
10865 | if (f->fx_r_type == BFD_RELOC_LO16 | |
10866 | && f->fx_addsy == l->fixp->fx_addsy | |
10867 | && f->fx_offset == l->fixp->fx_offset | |
10868 | && (pass == 1 | |
10869 | || prev == NULL | |
10870 | || prev->fx_r_type != BFD_RELOC_HI16_S | |
10871 | || prev->fx_addsy != f->fx_addsy | |
10872 | || prev->fx_offset != f->fx_offset)) | |
10873 | { | |
10874 | fixS **pf; | |
10875 | ||
10876 | /* Move l->fixp before f. */ | |
10877 | for (pf = &seginfo->fix_root; | |
10878 | *pf != l->fixp; | |
10879 | pf = &(*pf)->fx_next) | |
10880 | assert (*pf != NULL); | |
10881 | ||
10882 | *pf = l->fixp->fx_next; | |
10883 | ||
10884 | l->fixp->fx_next = f; | |
10885 | if (prev == NULL) | |
10886 | seginfo->fix_root = l->fixp; | |
10887 | else | |
10888 | prev->fx_next = l->fixp; | |
10889 | ||
10890 | break; | |
10891 | } | |
10892 | ||
10893 | prev = f; | |
10894 | } | |
10895 | ||
10896 | if (f != NULL) | |
10897 | break; | |
10898 | ||
10899 | #if 0 /* GCC code motion plus incomplete dead code elimination | |
10900 | can leave a %hi without a %lo. */ | |
10901 | if (pass == 1) | |
10902 | as_warn_where (l->fixp->fx_file, l->fixp->fx_line, | |
10903 | _("Unmatched %%hi reloc")); | |
10904 | #endif | |
10905 | } | |
10906 | } | |
10907 | } | |
10908 | ||
10909 | /* When generating embedded PIC code we need to use a special | |
10910 | relocation to represent the difference of two symbols in the .text | |
10911 | section (switch tables use a difference of this sort). See | |
10912 | include/coff/mips.h for details. This macro checks whether this | |
10913 | fixup requires the special reloc. */ | |
10914 | #define SWITCH_TABLE(fixp) \ | |
10915 | ((fixp)->fx_r_type == BFD_RELOC_32 \ | |
bb2d6cd7 | 10916 | && OUTPUT_FLAVOR != bfd_target_elf_flavour \ |
252b5132 RH |
10917 | && (fixp)->fx_addsy != NULL \ |
10918 | && (fixp)->fx_subsy != NULL \ | |
10919 | && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \ | |
10920 | && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section) | |
10921 | ||
10922 | /* When generating embedded PIC code we must keep all PC relative | |
10923 | relocations, in case the linker has to relax a call. We also need | |
f6688943 TS |
10924 | to keep relocations for switch table entries. |
10925 | ||
10926 | We may have combined relocations without symbols in the N32/N64 ABI. | |
10927 | We have to prevent gas from dropping them. */ | |
252b5132 | 10928 | |
252b5132 RH |
10929 | int |
10930 | mips_force_relocation (fixp) | |
10931 | fixS *fixp; | |
10932 | { | |
10933 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
a161fe53 AM |
10934 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY |
10935 | || S_FORCE_RELOC (fixp->fx_addsy)) | |
252b5132 RH |
10936 | return 1; |
10937 | ||
f6688943 TS |
10938 | if (HAVE_NEWABI |
10939 | && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr | |
10940 | && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB | |
10941 | || fixp->fx_r_type == BFD_RELOC_HI16_S | |
10942 | || fixp->fx_r_type == BFD_RELOC_LO16)) | |
10943 | return 1; | |
10944 | ||
252b5132 RH |
10945 | return (mips_pic == EMBEDDED_PIC |
10946 | && (fixp->fx_pcrel | |
10947 | || SWITCH_TABLE (fixp) | |
10948 | || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S | |
10949 | || fixp->fx_r_type == BFD_RELOC_PCREL_LO16)); | |
10950 | } | |
10951 | ||
add55e1f RS |
10952 | #ifdef OBJ_ELF |
10953 | static int | |
10954 | mips_need_elf_addend_fixup (fixP) | |
10955 | fixS *fixP; | |
10956 | { | |
2d2bf3e0 CD |
10957 | if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16) |
10958 | return 1; | |
b25a253c CD |
10959 | if (mips_pic == EMBEDDED_PIC |
10960 | && S_IS_WEAK (fixP->fx_addsy)) | |
10961 | return 1; | |
10962 | if (mips_pic != EMBEDDED_PIC | |
10963 | && (S_IS_WEAK (fixP->fx_addsy) | |
bad9ca53 | 10964 | || S_IS_EXTERNAL (fixP->fx_addsy)) |
2d2bf3e0 CD |
10965 | && !S_IS_COMMON (fixP->fx_addsy)) |
10966 | return 1; | |
10967 | if (symbol_used_in_reloc_p (fixP->fx_addsy) | |
10968 | && (((bfd_get_section_flags (stdoutput, | |
10969 | S_GET_SEGMENT (fixP->fx_addsy)) | |
10970 | & SEC_LINK_ONCE) != 0) | |
10971 | || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)), | |
10972 | ".gnu.linkonce", | |
10973 | sizeof (".gnu.linkonce") - 1))) | |
10974 | return 1; | |
10975 | return 0; | |
add55e1f RS |
10976 | } |
10977 | #endif | |
10978 | ||
252b5132 RH |
10979 | /* Apply a fixup to the object file. */ |
10980 | ||
94f592af NC |
10981 | void |
10982 | md_apply_fix3 (fixP, valP, seg) | |
252b5132 | 10983 | fixS *fixP; |
98d3f06f | 10984 | valueT *valP; |
94f592af | 10985 | segT seg ATTRIBUTE_UNUSED; |
252b5132 | 10986 | { |
874e8986 | 10987 | bfd_byte *buf; |
98aa84af AM |
10988 | long insn; |
10989 | valueT value; | |
ed6fb7bd | 10990 | static int previous_fx_r_type = 0; |
252b5132 | 10991 | |
65551fa4 CD |
10992 | /* FIXME: Maybe just return for all reloc types not listed below? |
10993 | Eric Christopher says: "This is stupid, please rewrite md_apply_fix3. */ | |
10994 | if (fixP->fx_r_type == BFD_RELOC_8) | |
10995 | return; | |
10996 | ||
252b5132 RH |
10997 | assert (fixP->fx_size == 4 |
10998 | || fixP->fx_r_type == BFD_RELOC_16 | |
f6688943 TS |
10999 | || fixP->fx_r_type == BFD_RELOC_32 |
11000 | || fixP->fx_r_type == BFD_RELOC_MIPS_JMP | |
11001 | || fixP->fx_r_type == BFD_RELOC_HI16_S | |
11002 | || fixP->fx_r_type == BFD_RELOC_LO16 | |
11003 | || fixP->fx_r_type == BFD_RELOC_GPREL16 | |
76b3015f | 11004 | || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL |
f6688943 | 11005 | || fixP->fx_r_type == BFD_RELOC_GPREL32 |
252b5132 | 11006 | || fixP->fx_r_type == BFD_RELOC_64 |
f6688943 TS |
11007 | || fixP->fx_r_type == BFD_RELOC_CTOR |
11008 | || fixP->fx_r_type == BFD_RELOC_MIPS_SUB | |
11009 | || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST | |
11010 | || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER | |
11011 | || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP | |
11012 | || fixP->fx_r_type == BFD_RELOC_MIPS_REL16 | |
11013 | || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT | |
252b5132 | 11014 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
438c16b8 TS |
11015 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY |
11016 | || fixP->fx_r_type == BFD_RELOC_MIPS_JALR); | |
252b5132 | 11017 | |
98d3f06f | 11018 | value = *valP; |
252b5132 RH |
11019 | |
11020 | /* If we aren't adjusting this fixup to be against the section | |
11021 | symbol, we need to adjust the value. */ | |
11022 | #ifdef OBJ_ELF | |
11023 | if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
bb2d6cd7 | 11024 | { |
add55e1f | 11025 | if (mips_need_elf_addend_fixup (fixP)) |
98aa84af | 11026 | { |
d6e9d61a | 11027 | reloc_howto_type *howto; |
98aa84af | 11028 | valueT symval = S_GET_VALUE (fixP->fx_addsy); |
94f592af | 11029 | |
98aa84af | 11030 | value -= symval; |
d6e9d61a MR |
11031 | |
11032 | howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type); | |
7a49a8c2 L |
11033 | if (value != 0 && howto->partial_inplace |
11034 | && (! fixP->fx_pcrel || howto->pcrel_offset)) | |
98aa84af AM |
11035 | { |
11036 | /* In this case, the bfd_install_relocation routine will | |
11037 | incorrectly add the symbol value back in. We just want | |
7a49a8c2 L |
11038 | the addend to appear in the object file. |
11039 | ||
11040 | howto->pcrel_offset is added for R_MIPS_PC16, which is | |
11041 | generated for code like | |
11042 | ||
11043 | globl g1 .text | |
11044 | .text | |
11045 | .space 20 | |
11046 | g1: | |
11047 | x: | |
11048 | bal g1 | |
11049 | */ | |
98aa84af | 11050 | value -= symval; |
7461da6e RS |
11051 | |
11052 | /* Make sure the addend is still non-zero. If it became zero | |
11053 | after the last operation, set it to a spurious value and | |
11054 | subtract the same value from the object file's contents. */ | |
11055 | if (value == 0) | |
11056 | { | |
11057 | value = 8; | |
11058 | ||
11059 | /* The in-place addends for LO16 relocations are signed; | |
11060 | leave the matching HI16 in-place addends as zero. */ | |
11061 | if (fixP->fx_r_type != BFD_RELOC_HI16_S) | |
11062 | { | |
7461da6e RS |
11063 | bfd_vma contents, mask, field; |
11064 | ||
7461da6e RS |
11065 | contents = bfd_get_bits (fixP->fx_frag->fr_literal |
11066 | + fixP->fx_where, | |
11067 | fixP->fx_size * 8, | |
11068 | target_big_endian); | |
11069 | ||
11070 | /* MASK has bits set where the relocation should go. | |
11071 | FIELD is -value, shifted into the appropriate place | |
11072 | for this relocation. */ | |
11073 | mask = 1 << (howto->bitsize - 1); | |
11074 | mask = (((mask - 1) << 1) | 1) << howto->bitpos; | |
11075 | field = (-value >> howto->rightshift) << howto->bitpos; | |
11076 | ||
11077 | bfd_put_bits ((field & mask) | (contents & ~mask), | |
11078 | fixP->fx_frag->fr_literal + fixP->fx_where, | |
11079 | fixP->fx_size * 8, | |
11080 | target_big_endian); | |
11081 | } | |
11082 | } | |
98aa84af AM |
11083 | } |
11084 | } | |
252b5132 | 11085 | |
bb2d6cd7 GK |
11086 | /* This code was generated using trial and error and so is |
11087 | fragile and not trustworthy. If you change it, you should | |
11088 | rerun the elf-rel, elf-rel2, and empic testcases and ensure | |
11089 | they still pass. */ | |
11090 | if (fixP->fx_pcrel || fixP->fx_subsy != NULL) | |
11091 | { | |
11092 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
11093 | ||
11094 | /* BFD's REL handling, for MIPS, is _very_ weird. | |
11095 | This gives the right results, but it can't possibly | |
11096 | be the way things are supposed to work. */ | |
cb56d3d3 TS |
11097 | if ((fixP->fx_r_type != BFD_RELOC_16_PCREL |
11098 | && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2) | |
bb2d6cd7 GK |
11099 | || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section) |
11100 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
11101 | } | |
11102 | } | |
11103 | #endif | |
252b5132 | 11104 | |
94f592af | 11105 | fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */ |
252b5132 | 11106 | |
ed6fb7bd SC |
11107 | /* We are not done if this is a composite relocation to set up gp. */ |
11108 | if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel | |
11109 | && !(fixP->fx_r_type == BFD_RELOC_MIPS_SUB | |
10181a0d AO |
11110 | || (fixP->fx_r_type == BFD_RELOC_64 |
11111 | && (previous_fx_r_type == BFD_RELOC_GPREL32 | |
11112 | || previous_fx_r_type == BFD_RELOC_GPREL16)) | |
ed6fb7bd SC |
11113 | || (previous_fx_r_type == BFD_RELOC_MIPS_SUB |
11114 | && (fixP->fx_r_type == BFD_RELOC_HI16_S | |
11115 | || fixP->fx_r_type == BFD_RELOC_LO16)))) | |
252b5132 | 11116 | fixP->fx_done = 1; |
ed6fb7bd | 11117 | previous_fx_r_type = fixP->fx_r_type; |
252b5132 RH |
11118 | |
11119 | switch (fixP->fx_r_type) | |
11120 | { | |
11121 | case BFD_RELOC_MIPS_JMP: | |
e369bcce TS |
11122 | case BFD_RELOC_MIPS_SHIFT5: |
11123 | case BFD_RELOC_MIPS_SHIFT6: | |
11124 | case BFD_RELOC_MIPS_GOT_DISP: | |
11125 | case BFD_RELOC_MIPS_GOT_PAGE: | |
11126 | case BFD_RELOC_MIPS_GOT_OFST: | |
11127 | case BFD_RELOC_MIPS_SUB: | |
11128 | case BFD_RELOC_MIPS_INSERT_A: | |
11129 | case BFD_RELOC_MIPS_INSERT_B: | |
11130 | case BFD_RELOC_MIPS_DELETE: | |
11131 | case BFD_RELOC_MIPS_HIGHEST: | |
11132 | case BFD_RELOC_MIPS_HIGHER: | |
11133 | case BFD_RELOC_MIPS_SCN_DISP: | |
11134 | case BFD_RELOC_MIPS_REL16: | |
11135 | case BFD_RELOC_MIPS_RELGOT: | |
11136 | case BFD_RELOC_MIPS_JALR: | |
252b5132 RH |
11137 | case BFD_RELOC_HI16: |
11138 | case BFD_RELOC_HI16_S: | |
cdf6fd85 | 11139 | case BFD_RELOC_GPREL16: |
252b5132 RH |
11140 | case BFD_RELOC_MIPS_LITERAL: |
11141 | case BFD_RELOC_MIPS_CALL16: | |
11142 | case BFD_RELOC_MIPS_GOT16: | |
cdf6fd85 | 11143 | case BFD_RELOC_GPREL32: |
252b5132 RH |
11144 | case BFD_RELOC_MIPS_GOT_HI16: |
11145 | case BFD_RELOC_MIPS_GOT_LO16: | |
11146 | case BFD_RELOC_MIPS_CALL_HI16: | |
11147 | case BFD_RELOC_MIPS_CALL_LO16: | |
11148 | case BFD_RELOC_MIPS16_GPREL: | |
11149 | if (fixP->fx_pcrel) | |
11150 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11151 | _("Invalid PC relative reloc")); | |
11152 | /* Nothing needed to do. The value comes from the reloc entry */ | |
11153 | break; | |
11154 | ||
11155 | case BFD_RELOC_MIPS16_JMP: | |
11156 | /* We currently always generate a reloc against a symbol, which | |
11157 | means that we don't want an addend even if the symbol is | |
11158 | defined. */ | |
11159 | fixP->fx_addnumber = 0; | |
11160 | break; | |
11161 | ||
11162 | case BFD_RELOC_PCREL_HI16_S: | |
11163 | /* The addend for this is tricky if it is internal, so we just | |
11164 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 11165 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
11166 | && !fixP->fx_done |
11167 | && value != 0) | |
11168 | break; | |
11169 | if (fixP->fx_addsy | |
11170 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
11171 | { |
11172 | /* For an external symbol adjust by the address to make it | |
11173 | pcrel_offset. We use the address of the RELLO reloc | |
11174 | which follows this one. */ | |
11175 | value += (fixP->fx_next->fx_frag->fr_address | |
11176 | + fixP->fx_next->fx_where); | |
11177 | } | |
e7d556df | 11178 | value = ((value + 0x8000) >> 16) & 0xffff; |
874e8986 | 11179 | buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where; |
252b5132 RH |
11180 | if (target_big_endian) |
11181 | buf += 2; | |
874e8986 | 11182 | md_number_to_chars ((char *) buf, value, 2); |
252b5132 RH |
11183 | break; |
11184 | ||
11185 | case BFD_RELOC_PCREL_LO16: | |
11186 | /* The addend for this is tricky if it is internal, so we just | |
11187 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 11188 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
11189 | && !fixP->fx_done |
11190 | && value != 0) | |
11191 | break; | |
11192 | if (fixP->fx_addsy | |
11193 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 | 11194 | value += fixP->fx_frag->fr_address + fixP->fx_where; |
874e8986 | 11195 | buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where; |
252b5132 RH |
11196 | if (target_big_endian) |
11197 | buf += 2; | |
874e8986 | 11198 | md_number_to_chars ((char *) buf, value, 2); |
252b5132 RH |
11199 | break; |
11200 | ||
11201 | case BFD_RELOC_64: | |
11202 | /* This is handled like BFD_RELOC_32, but we output a sign | |
11203 | extended value if we are only 32 bits. */ | |
11204 | if (fixP->fx_done | |
11205 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
11206 | { | |
11207 | if (8 <= sizeof (valueT)) | |
11208 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
11209 | value, 8); | |
11210 | else | |
11211 | { | |
11212 | long w1, w2; | |
11213 | long hiv; | |
11214 | ||
11215 | w1 = w2 = fixP->fx_where; | |
11216 | if (target_big_endian) | |
11217 | w1 += 4; | |
11218 | else | |
11219 | w2 += 4; | |
11220 | md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4); | |
11221 | if ((value & 0x80000000) != 0) | |
11222 | hiv = 0xffffffff; | |
11223 | else | |
11224 | hiv = 0; | |
11225 | md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4); | |
11226 | } | |
11227 | } | |
11228 | break; | |
11229 | ||
056350c6 | 11230 | case BFD_RELOC_RVA: |
252b5132 RH |
11231 | case BFD_RELOC_32: |
11232 | /* If we are deleting this reloc entry, we must fill in the | |
11233 | value now. This can happen if we have a .word which is not | |
11234 | resolved when it appears but is later defined. We also need | |
11235 | to fill in the value if this is an embedded PIC switch table | |
11236 | entry. */ | |
11237 | if (fixP->fx_done | |
11238 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
11239 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
11240 | value, 4); | |
11241 | break; | |
11242 | ||
11243 | case BFD_RELOC_16: | |
11244 | /* If we are deleting this reloc entry, we must fill in the | |
11245 | value now. */ | |
11246 | assert (fixP->fx_size == 2); | |
11247 | if (fixP->fx_done) | |
11248 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
11249 | value, 2); | |
11250 | break; | |
11251 | ||
11252 | case BFD_RELOC_LO16: | |
11253 | /* When handling an embedded PIC switch statement, we can wind | |
11254 | up deleting a LO16 reloc. See the 'o' case in mips_ip. */ | |
11255 | if (fixP->fx_done) | |
11256 | { | |
98aa84af | 11257 | if (value + 0x8000 > 0xffff) |
252b5132 RH |
11258 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11259 | _("relocation overflow")); | |
874e8986 | 11260 | buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where; |
252b5132 RH |
11261 | if (target_big_endian) |
11262 | buf += 2; | |
874e8986 | 11263 | md_number_to_chars ((char *) buf, value, 2); |
252b5132 RH |
11264 | } |
11265 | break; | |
11266 | ||
11267 | case BFD_RELOC_16_PCREL_S2: | |
cb56d3d3 TS |
11268 | if ((value & 0x3) != 0) |
11269 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11270 | _("Branch to odd address (%lx)"), (long) value); | |
11271 | ||
11272 | /* Fall through. */ | |
11273 | ||
11274 | case BFD_RELOC_16_PCREL: | |
252b5132 RH |
11275 | /* |
11276 | * We need to save the bits in the instruction since fixup_segment() | |
11277 | * might be deleting the relocation entry (i.e., a branch within | |
11278 | * the current segment). | |
11279 | */ | |
bb2d6cd7 GK |
11280 | if (!fixP->fx_done && value != 0) |
11281 | break; | |
11282 | /* If 'value' is zero, the remaining reloc code won't actually | |
11283 | do the store, so it must be done here. This is probably | |
11284 | a bug somewhere. */ | |
b25a253c CD |
11285 | if (!fixP->fx_done |
11286 | && (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2 | |
11287 | || fixP->fx_addsy == NULL /* ??? */ | |
11288 | || ! S_IS_DEFINED (fixP->fx_addsy))) | |
bb2d6cd7 | 11289 | value -= fixP->fx_frag->fr_address + fixP->fx_where; |
bdaaa2e1 | 11290 | |
98aa84af | 11291 | value = (offsetT) value >> 2; |
252b5132 RH |
11292 | |
11293 | /* update old instruction data */ | |
874e8986 | 11294 | buf = (bfd_byte *) (fixP->fx_where + fixP->fx_frag->fr_literal); |
252b5132 RH |
11295 | if (target_big_endian) |
11296 | insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
11297 | else | |
11298 | insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | |
11299 | ||
98aa84af | 11300 | if (value + 0x8000 <= 0xffff) |
252b5132 RH |
11301 | insn |= value & 0xffff; |
11302 | else | |
11303 | { | |
11304 | /* The branch offset is too large. If this is an | |
11305 | unconditional branch, and we are not generating PIC code, | |
11306 | we can convert it to an absolute jump instruction. */ | |
11307 | if (mips_pic == NO_PIC | |
11308 | && fixP->fx_done | |
11309 | && fixP->fx_frag->fr_address >= text_section->vma | |
11310 | && (fixP->fx_frag->fr_address | |
11311 | < text_section->vma + text_section->_raw_size) | |
11312 | && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */ | |
11313 | || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */ | |
11314 | || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */ | |
11315 | { | |
11316 | if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */ | |
11317 | insn = 0x0c000000; /* jal */ | |
11318 | else | |
11319 | insn = 0x08000000; /* j */ | |
11320 | fixP->fx_r_type = BFD_RELOC_MIPS_JMP; | |
11321 | fixP->fx_done = 0; | |
11322 | fixP->fx_addsy = section_symbol (text_section); | |
11323 | fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP); | |
11324 | } | |
11325 | else | |
11326 | { | |
4a6a3df4 AO |
11327 | /* If we got here, we have branch-relaxation disabled, |
11328 | and there's nothing we can do to fix this instruction | |
11329 | without turning it into a longer sequence. */ | |
252b5132 RH |
11330 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11331 | _("Branch out of range")); | |
11332 | } | |
11333 | } | |
11334 | ||
11335 | md_number_to_chars ((char *) buf, (valueT) insn, 4); | |
11336 | break; | |
11337 | ||
11338 | case BFD_RELOC_VTABLE_INHERIT: | |
11339 | fixP->fx_done = 0; | |
11340 | if (fixP->fx_addsy | |
11341 | && !S_IS_DEFINED (fixP->fx_addsy) | |
11342 | && !S_IS_WEAK (fixP->fx_addsy)) | |
11343 | S_SET_WEAK (fixP->fx_addsy); | |
11344 | break; | |
11345 | ||
11346 | case BFD_RELOC_VTABLE_ENTRY: | |
11347 | fixP->fx_done = 0; | |
11348 | break; | |
11349 | ||
11350 | default: | |
11351 | internalError (); | |
11352 | } | |
252b5132 RH |
11353 | } |
11354 | ||
11355 | #if 0 | |
11356 | void | |
11357 | printInsn (oc) | |
11358 | unsigned long oc; | |
11359 | { | |
11360 | const struct mips_opcode *p; | |
11361 | int treg, sreg, dreg, shamt; | |
11362 | short imm; | |
11363 | const char *args; | |
11364 | int i; | |
11365 | ||
11366 | for (i = 0; i < NUMOPCODES; ++i) | |
11367 | { | |
11368 | p = &mips_opcodes[i]; | |
11369 | if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO)) | |
11370 | { | |
11371 | printf ("%08lx %s\t", oc, p->name); | |
11372 | treg = (oc >> 16) & 0x1f; | |
11373 | sreg = (oc >> 21) & 0x1f; | |
11374 | dreg = (oc >> 11) & 0x1f; | |
11375 | shamt = (oc >> 6) & 0x1f; | |
11376 | imm = oc; | |
11377 | for (args = p->args;; ++args) | |
11378 | { | |
11379 | switch (*args) | |
11380 | { | |
11381 | case '\0': | |
11382 | printf ("\n"); | |
11383 | break; | |
11384 | ||
11385 | case ',': | |
11386 | case '(': | |
11387 | case ')': | |
11388 | printf ("%c", *args); | |
11389 | continue; | |
11390 | ||
11391 | case 'r': | |
11392 | assert (treg == sreg); | |
11393 | printf ("$%d,$%d", treg, sreg); | |
11394 | continue; | |
11395 | ||
11396 | case 'd': | |
11397 | case 'G': | |
11398 | printf ("$%d", dreg); | |
11399 | continue; | |
11400 | ||
11401 | case 't': | |
11402 | case 'E': | |
11403 | printf ("$%d", treg); | |
11404 | continue; | |
11405 | ||
11406 | case 'k': | |
11407 | printf ("0x%x", treg); | |
11408 | continue; | |
11409 | ||
11410 | case 'b': | |
11411 | case 's': | |
11412 | printf ("$%d", sreg); | |
11413 | continue; | |
11414 | ||
11415 | case 'a': | |
11416 | printf ("0x%08lx", oc & 0x1ffffff); | |
11417 | continue; | |
11418 | ||
11419 | case 'i': | |
11420 | case 'j': | |
11421 | case 'o': | |
11422 | case 'u': | |
11423 | printf ("%d", imm); | |
11424 | continue; | |
11425 | ||
11426 | case '<': | |
11427 | case '>': | |
11428 | printf ("$%d", shamt); | |
11429 | continue; | |
11430 | ||
11431 | default: | |
11432 | internalError (); | |
11433 | } | |
11434 | break; | |
11435 | } | |
11436 | return; | |
11437 | } | |
11438 | } | |
11439 | printf (_("%08lx UNDEFINED\n"), oc); | |
11440 | } | |
11441 | #endif | |
11442 | ||
11443 | static symbolS * | |
11444 | get_symbol () | |
11445 | { | |
11446 | int c; | |
11447 | char *name; | |
11448 | symbolS *p; | |
11449 | ||
11450 | name = input_line_pointer; | |
11451 | c = get_symbol_end (); | |
11452 | p = (symbolS *) symbol_find_or_make (name); | |
11453 | *input_line_pointer = c; | |
11454 | return p; | |
11455 | } | |
11456 | ||
11457 | /* Align the current frag to a given power of two. The MIPS assembler | |
11458 | also automatically adjusts any preceding label. */ | |
11459 | ||
11460 | static void | |
11461 | mips_align (to, fill, label) | |
11462 | int to; | |
11463 | int fill; | |
11464 | symbolS *label; | |
11465 | { | |
11466 | mips_emit_delays (false); | |
11467 | frag_align (to, fill, 0); | |
11468 | record_alignment (now_seg, to); | |
11469 | if (label != NULL) | |
11470 | { | |
11471 | assert (S_GET_SEGMENT (label) == now_seg); | |
49309057 | 11472 | symbol_set_frag (label, frag_now); |
252b5132 RH |
11473 | S_SET_VALUE (label, (valueT) frag_now_fix ()); |
11474 | } | |
11475 | } | |
11476 | ||
11477 | /* Align to a given power of two. .align 0 turns off the automatic | |
11478 | alignment used by the data creating pseudo-ops. */ | |
11479 | ||
11480 | static void | |
11481 | s_align (x) | |
43841e91 | 11482 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11483 | { |
11484 | register int temp; | |
11485 | register long temp_fill; | |
11486 | long max_alignment = 15; | |
11487 | ||
11488 | /* | |
11489 | ||
11490 | o Note that the assembler pulls down any immediately preceeding label | |
11491 | to the aligned address. | |
11492 | o It's not documented but auto alignment is reinstated by | |
11493 | a .align pseudo instruction. | |
11494 | o Note also that after auto alignment is turned off the mips assembler | |
11495 | issues an error on attempt to assemble an improperly aligned data item. | |
11496 | We don't. | |
11497 | ||
11498 | */ | |
11499 | ||
11500 | temp = get_absolute_expression (); | |
11501 | if (temp > max_alignment) | |
11502 | as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment); | |
11503 | else if (temp < 0) | |
11504 | { | |
11505 | as_warn (_("Alignment negative: 0 assumed.")); | |
11506 | temp = 0; | |
11507 | } | |
11508 | if (*input_line_pointer == ',') | |
11509 | { | |
f9419b05 | 11510 | ++input_line_pointer; |
252b5132 RH |
11511 | temp_fill = get_absolute_expression (); |
11512 | } | |
11513 | else | |
11514 | temp_fill = 0; | |
11515 | if (temp) | |
11516 | { | |
11517 | auto_align = 1; | |
11518 | mips_align (temp, (int) temp_fill, | |
11519 | insn_labels != NULL ? insn_labels->label : NULL); | |
11520 | } | |
11521 | else | |
11522 | { | |
11523 | auto_align = 0; | |
11524 | } | |
11525 | ||
11526 | demand_empty_rest_of_line (); | |
11527 | } | |
11528 | ||
11529 | void | |
11530 | mips_flush_pending_output () | |
11531 | { | |
11532 | mips_emit_delays (false); | |
11533 | mips_clear_insn_labels (); | |
11534 | } | |
11535 | ||
11536 | static void | |
11537 | s_change_sec (sec) | |
11538 | int sec; | |
11539 | { | |
11540 | segT seg; | |
11541 | ||
11542 | /* When generating embedded PIC code, we only use the .text, .lit8, | |
11543 | .sdata and .sbss sections. We change the .data and .rdata | |
11544 | pseudo-ops to use .sdata. */ | |
11545 | if (mips_pic == EMBEDDED_PIC | |
11546 | && (sec == 'd' || sec == 'r')) | |
11547 | sec = 's'; | |
11548 | ||
11549 | #ifdef OBJ_ELF | |
11550 | /* The ELF backend needs to know that we are changing sections, so | |
11551 | that .previous works correctly. We could do something like check | |
b6ff326e | 11552 | for an obj_section_change_hook macro, but that might be confusing |
252b5132 RH |
11553 | as it would not be appropriate to use it in the section changing |
11554 | functions in read.c, since obj-elf.c intercepts those. FIXME: | |
11555 | This should be cleaner, somehow. */ | |
11556 | obj_elf_section_change_hook (); | |
11557 | #endif | |
11558 | ||
11559 | mips_emit_delays (false); | |
11560 | switch (sec) | |
11561 | { | |
11562 | case 't': | |
11563 | s_text (0); | |
11564 | break; | |
11565 | case 'd': | |
11566 | s_data (0); | |
11567 | break; | |
11568 | case 'b': | |
11569 | subseg_set (bss_section, (subsegT) get_absolute_expression ()); | |
11570 | demand_empty_rest_of_line (); | |
11571 | break; | |
11572 | ||
11573 | case 'r': | |
11574 | if (USE_GLOBAL_POINTER_OPT) | |
11575 | { | |
11576 | seg = subseg_new (RDATA_SECTION_NAME, | |
11577 | (subsegT) get_absolute_expression ()); | |
11578 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
11579 | { | |
11580 | bfd_set_section_flags (stdoutput, seg, | |
11581 | (SEC_ALLOC | |
11582 | | SEC_LOAD | |
11583 | | SEC_READONLY | |
11584 | | SEC_RELOC | |
11585 | | SEC_DATA)); | |
11586 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 11587 | record_alignment (seg, 4); |
252b5132 RH |
11588 | } |
11589 | demand_empty_rest_of_line (); | |
11590 | } | |
11591 | else | |
11592 | { | |
11593 | as_bad (_("No read only data section in this object file format")); | |
11594 | demand_empty_rest_of_line (); | |
11595 | return; | |
11596 | } | |
11597 | break; | |
11598 | ||
11599 | case 's': | |
11600 | if (USE_GLOBAL_POINTER_OPT) | |
11601 | { | |
11602 | seg = subseg_new (".sdata", (subsegT) get_absolute_expression ()); | |
11603 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
11604 | { | |
11605 | bfd_set_section_flags (stdoutput, seg, | |
11606 | SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
11607 | | SEC_DATA); | |
11608 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 11609 | record_alignment (seg, 4); |
252b5132 RH |
11610 | } |
11611 | demand_empty_rest_of_line (); | |
11612 | break; | |
11613 | } | |
11614 | else | |
11615 | { | |
11616 | as_bad (_("Global pointers not supported; recompile -G 0")); | |
11617 | demand_empty_rest_of_line (); | |
11618 | return; | |
11619 | } | |
11620 | } | |
11621 | ||
11622 | auto_align = 1; | |
11623 | } | |
cca86cc8 SC |
11624 | |
11625 | void | |
11626 | s_change_section (ignore) | |
11627 | int ignore ATTRIBUTE_UNUSED; | |
11628 | { | |
7ed4a06a | 11629 | #ifdef OBJ_ELF |
cca86cc8 SC |
11630 | char *section_name; |
11631 | char c; | |
4cf0dd0d | 11632 | char next_c; |
cca86cc8 SC |
11633 | int section_type; |
11634 | int section_flag; | |
11635 | int section_entry_size; | |
11636 | int section_alignment; | |
cca86cc8 | 11637 | |
7ed4a06a TS |
11638 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
11639 | return; | |
11640 | ||
cca86cc8 SC |
11641 | section_name = input_line_pointer; |
11642 | c = get_symbol_end (); | |
4cf0dd0d | 11643 | next_c = *(input_line_pointer + 1); |
cca86cc8 | 11644 | |
4cf0dd0d TS |
11645 | /* Do we have .section Name<,"flags">? */ |
11646 | if (c != ',' || (c == ',' && next_c == '"')) | |
cca86cc8 | 11647 | { |
4cf0dd0d TS |
11648 | /* just after name is now '\0'. */ |
11649 | *input_line_pointer = c; | |
cca86cc8 SC |
11650 | input_line_pointer = section_name; |
11651 | obj_elf_section (ignore); | |
11652 | return; | |
11653 | } | |
11654 | input_line_pointer++; | |
11655 | ||
11656 | /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */ | |
11657 | if (c == ',') | |
11658 | section_type = get_absolute_expression (); | |
11659 | else | |
11660 | section_type = 0; | |
11661 | if (*input_line_pointer++ == ',') | |
11662 | section_flag = get_absolute_expression (); | |
11663 | else | |
11664 | section_flag = 0; | |
11665 | if (*input_line_pointer++ == ',') | |
11666 | section_entry_size = get_absolute_expression (); | |
11667 | else | |
11668 | section_entry_size = 0; | |
11669 | if (*input_line_pointer++ == ',') | |
11670 | section_alignment = get_absolute_expression (); | |
11671 | else | |
11672 | section_alignment = 0; | |
11673 | ||
11674 | obj_elf_change_section (section_name, section_type, section_flag, | |
11675 | section_entry_size, 0, 0, 0); | |
7ed4a06a | 11676 | #endif /* OBJ_ELF */ |
cca86cc8 | 11677 | } |
252b5132 RH |
11678 | |
11679 | void | |
11680 | mips_enable_auto_align () | |
11681 | { | |
11682 | auto_align = 1; | |
11683 | } | |
11684 | ||
11685 | static void | |
11686 | s_cons (log_size) | |
11687 | int log_size; | |
11688 | { | |
11689 | symbolS *label; | |
11690 | ||
11691 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
11692 | mips_emit_delays (false); | |
11693 | if (log_size > 0 && auto_align) | |
11694 | mips_align (log_size, 0, label); | |
11695 | mips_clear_insn_labels (); | |
11696 | cons (1 << log_size); | |
11697 | } | |
11698 | ||
11699 | static void | |
11700 | s_float_cons (type) | |
11701 | int type; | |
11702 | { | |
11703 | symbolS *label; | |
11704 | ||
11705 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
11706 | ||
11707 | mips_emit_delays (false); | |
11708 | ||
11709 | if (auto_align) | |
49309057 ILT |
11710 | { |
11711 | if (type == 'd') | |
11712 | mips_align (3, 0, label); | |
11713 | else | |
11714 | mips_align (2, 0, label); | |
11715 | } | |
252b5132 RH |
11716 | |
11717 | mips_clear_insn_labels (); | |
11718 | ||
11719 | float_cons (type); | |
11720 | } | |
11721 | ||
11722 | /* Handle .globl. We need to override it because on Irix 5 you are | |
11723 | permitted to say | |
11724 | .globl foo .text | |
11725 | where foo is an undefined symbol, to mean that foo should be | |
11726 | considered to be the address of a function. */ | |
11727 | ||
11728 | static void | |
11729 | s_mips_globl (x) | |
43841e91 | 11730 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11731 | { |
11732 | char *name; | |
11733 | int c; | |
11734 | symbolS *symbolP; | |
11735 | flagword flag; | |
11736 | ||
11737 | name = input_line_pointer; | |
11738 | c = get_symbol_end (); | |
11739 | symbolP = symbol_find_or_make (name); | |
11740 | *input_line_pointer = c; | |
11741 | SKIP_WHITESPACE (); | |
11742 | ||
11743 | /* On Irix 5, every global symbol that is not explicitly labelled as | |
11744 | being a function is apparently labelled as being an object. */ | |
11745 | flag = BSF_OBJECT; | |
11746 | ||
11747 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
11748 | { | |
11749 | char *secname; | |
11750 | asection *sec; | |
11751 | ||
11752 | secname = input_line_pointer; | |
11753 | c = get_symbol_end (); | |
11754 | sec = bfd_get_section_by_name (stdoutput, secname); | |
11755 | if (sec == NULL) | |
11756 | as_bad (_("%s: no such section"), secname); | |
11757 | *input_line_pointer = c; | |
11758 | ||
11759 | if (sec != NULL && (sec->flags & SEC_CODE) != 0) | |
11760 | flag = BSF_FUNCTION; | |
11761 | } | |
11762 | ||
49309057 | 11763 | symbol_get_bfdsym (symbolP)->flags |= flag; |
252b5132 RH |
11764 | |
11765 | S_SET_EXTERNAL (symbolP); | |
11766 | demand_empty_rest_of_line (); | |
11767 | } | |
11768 | ||
11769 | static void | |
11770 | s_option (x) | |
43841e91 | 11771 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11772 | { |
11773 | char *opt; | |
11774 | char c; | |
11775 | ||
11776 | opt = input_line_pointer; | |
11777 | c = get_symbol_end (); | |
11778 | ||
11779 | if (*opt == 'O') | |
11780 | { | |
11781 | /* FIXME: What does this mean? */ | |
11782 | } | |
11783 | else if (strncmp (opt, "pic", 3) == 0) | |
11784 | { | |
11785 | int i; | |
11786 | ||
11787 | i = atoi (opt + 3); | |
11788 | if (i == 0) | |
11789 | mips_pic = NO_PIC; | |
11790 | else if (i == 2) | |
11791 | mips_pic = SVR4_PIC; | |
11792 | else | |
11793 | as_bad (_(".option pic%d not supported"), i); | |
11794 | ||
11795 | if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC) | |
11796 | { | |
11797 | if (g_switch_seen && g_switch_value != 0) | |
11798 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
11799 | g_switch_value = 0; | |
11800 | bfd_set_gp_size (stdoutput, 0); | |
11801 | } | |
11802 | } | |
11803 | else | |
11804 | as_warn (_("Unrecognized option \"%s\""), opt); | |
11805 | ||
11806 | *input_line_pointer = c; | |
11807 | demand_empty_rest_of_line (); | |
11808 | } | |
11809 | ||
11810 | /* This structure is used to hold a stack of .set values. */ | |
11811 | ||
e972090a NC |
11812 | struct mips_option_stack |
11813 | { | |
252b5132 RH |
11814 | struct mips_option_stack *next; |
11815 | struct mips_set_options options; | |
11816 | }; | |
11817 | ||
11818 | static struct mips_option_stack *mips_opts_stack; | |
11819 | ||
11820 | /* Handle the .set pseudo-op. */ | |
11821 | ||
11822 | static void | |
11823 | s_mipsset (x) | |
43841e91 | 11824 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11825 | { |
11826 | char *name = input_line_pointer, ch; | |
11827 | ||
11828 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
f9419b05 | 11829 | ++input_line_pointer; |
252b5132 RH |
11830 | ch = *input_line_pointer; |
11831 | *input_line_pointer = '\0'; | |
11832 | ||
11833 | if (strcmp (name, "reorder") == 0) | |
11834 | { | |
11835 | if (mips_opts.noreorder && prev_nop_frag != NULL) | |
11836 | { | |
11837 | /* If we still have pending nops, we can discard them. The | |
11838 | usual nop handling will insert any that are still | |
bdaaa2e1 | 11839 | needed. */ |
252b5132 RH |
11840 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds |
11841 | * (mips_opts.mips16 ? 2 : 4)); | |
11842 | prev_nop_frag = NULL; | |
11843 | } | |
11844 | mips_opts.noreorder = 0; | |
11845 | } | |
11846 | else if (strcmp (name, "noreorder") == 0) | |
11847 | { | |
11848 | mips_emit_delays (true); | |
11849 | mips_opts.noreorder = 1; | |
11850 | mips_any_noreorder = 1; | |
11851 | } | |
11852 | else if (strcmp (name, "at") == 0) | |
11853 | { | |
11854 | mips_opts.noat = 0; | |
11855 | } | |
11856 | else if (strcmp (name, "noat") == 0) | |
11857 | { | |
11858 | mips_opts.noat = 1; | |
11859 | } | |
11860 | else if (strcmp (name, "macro") == 0) | |
11861 | { | |
11862 | mips_opts.warn_about_macros = 0; | |
11863 | } | |
11864 | else if (strcmp (name, "nomacro") == 0) | |
11865 | { | |
11866 | if (mips_opts.noreorder == 0) | |
11867 | as_bad (_("`noreorder' must be set before `nomacro'")); | |
11868 | mips_opts.warn_about_macros = 1; | |
11869 | } | |
11870 | else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0) | |
11871 | { | |
11872 | mips_opts.nomove = 0; | |
11873 | } | |
11874 | else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0) | |
11875 | { | |
11876 | mips_opts.nomove = 1; | |
11877 | } | |
11878 | else if (strcmp (name, "bopt") == 0) | |
11879 | { | |
11880 | mips_opts.nobopt = 0; | |
11881 | } | |
11882 | else if (strcmp (name, "nobopt") == 0) | |
11883 | { | |
11884 | mips_opts.nobopt = 1; | |
11885 | } | |
11886 | else if (strcmp (name, "mips16") == 0 | |
11887 | || strcmp (name, "MIPS-16") == 0) | |
11888 | mips_opts.mips16 = 1; | |
11889 | else if (strcmp (name, "nomips16") == 0 | |
11890 | || strcmp (name, "noMIPS-16") == 0) | |
11891 | mips_opts.mips16 = 0; | |
1f25f5d3 CD |
11892 | else if (strcmp (name, "mips3d") == 0) |
11893 | mips_opts.ase_mips3d = 1; | |
11894 | else if (strcmp (name, "nomips3d") == 0) | |
11895 | mips_opts.ase_mips3d = 0; | |
a4672219 TS |
11896 | else if (strcmp (name, "mdmx") == 0) |
11897 | mips_opts.ase_mdmx = 1; | |
11898 | else if (strcmp (name, "nomdmx") == 0) | |
11899 | mips_opts.ase_mdmx = 0; | |
252b5132 RH |
11900 | else if (strncmp (name, "mips", 4) == 0) |
11901 | { | |
11902 | int isa; | |
11903 | ||
11904 | /* Permit the user to change the ISA on the fly. Needless to | |
11905 | say, misuse can cause serious problems. */ | |
11906 | isa = atoi (name + 4); | |
553178e4 | 11907 | switch (isa) |
98d3f06f KH |
11908 | { |
11909 | case 0: | |
11910 | mips_opts.gp32 = file_mips_gp32; | |
11911 | mips_opts.fp32 = file_mips_fp32; | |
98d3f06f KH |
11912 | break; |
11913 | case 1: | |
11914 | case 2: | |
11915 | case 32: | |
11916 | mips_opts.gp32 = 1; | |
11917 | mips_opts.fp32 = 1; | |
11918 | break; | |
11919 | case 3: | |
11920 | case 4: | |
11921 | case 5: | |
11922 | case 64: | |
98d3f06f KH |
11923 | mips_opts.gp32 = 0; |
11924 | mips_opts.fp32 = 0; | |
11925 | break; | |
11926 | default: | |
11927 | as_bad (_("unknown ISA level %s"), name + 4); | |
11928 | break; | |
11929 | } | |
553178e4 | 11930 | |
e7af610e | 11931 | switch (isa) |
98d3f06f KH |
11932 | { |
11933 | case 0: mips_opts.isa = file_mips_isa; break; | |
11934 | case 1: mips_opts.isa = ISA_MIPS1; break; | |
11935 | case 2: mips_opts.isa = ISA_MIPS2; break; | |
11936 | case 3: mips_opts.isa = ISA_MIPS3; break; | |
11937 | case 4: mips_opts.isa = ISA_MIPS4; break; | |
11938 | case 5: mips_opts.isa = ISA_MIPS5; break; | |
11939 | case 32: mips_opts.isa = ISA_MIPS32; break; | |
11940 | case 64: mips_opts.isa = ISA_MIPS64; break; | |
11941 | default: as_bad (_("unknown ISA level %s"), name + 4); break; | |
11942 | } | |
252b5132 RH |
11943 | } |
11944 | else if (strcmp (name, "autoextend") == 0) | |
11945 | mips_opts.noautoextend = 0; | |
11946 | else if (strcmp (name, "noautoextend") == 0) | |
11947 | mips_opts.noautoextend = 1; | |
11948 | else if (strcmp (name, "push") == 0) | |
11949 | { | |
11950 | struct mips_option_stack *s; | |
11951 | ||
11952 | s = (struct mips_option_stack *) xmalloc (sizeof *s); | |
11953 | s->next = mips_opts_stack; | |
11954 | s->options = mips_opts; | |
11955 | mips_opts_stack = s; | |
11956 | } | |
11957 | else if (strcmp (name, "pop") == 0) | |
11958 | { | |
11959 | struct mips_option_stack *s; | |
11960 | ||
11961 | s = mips_opts_stack; | |
11962 | if (s == NULL) | |
11963 | as_bad (_(".set pop with no .set push")); | |
11964 | else | |
11965 | { | |
11966 | /* If we're changing the reorder mode we need to handle | |
11967 | delay slots correctly. */ | |
11968 | if (s->options.noreorder && ! mips_opts.noreorder) | |
11969 | mips_emit_delays (true); | |
11970 | else if (! s->options.noreorder && mips_opts.noreorder) | |
11971 | { | |
11972 | if (prev_nop_frag != NULL) | |
11973 | { | |
11974 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds | |
11975 | * (mips_opts.mips16 ? 2 : 4)); | |
11976 | prev_nop_frag = NULL; | |
11977 | } | |
11978 | } | |
11979 | ||
11980 | mips_opts = s->options; | |
11981 | mips_opts_stack = s->next; | |
11982 | free (s); | |
11983 | } | |
11984 | } | |
11985 | else | |
11986 | { | |
11987 | as_warn (_("Tried to set unrecognized symbol: %s\n"), name); | |
11988 | } | |
11989 | *input_line_pointer = ch; | |
11990 | demand_empty_rest_of_line (); | |
11991 | } | |
11992 | ||
11993 | /* Handle the .abicalls pseudo-op. I believe this is equivalent to | |
11994 | .option pic2. It means to generate SVR4 PIC calls. */ | |
11995 | ||
11996 | static void | |
11997 | s_abicalls (ignore) | |
43841e91 | 11998 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
11999 | { |
12000 | mips_pic = SVR4_PIC; | |
12001 | if (USE_GLOBAL_POINTER_OPT) | |
12002 | { | |
12003 | if (g_switch_seen && g_switch_value != 0) | |
12004 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
12005 | g_switch_value = 0; | |
12006 | } | |
12007 | bfd_set_gp_size (stdoutput, 0); | |
12008 | demand_empty_rest_of_line (); | |
12009 | } | |
12010 | ||
12011 | /* Handle the .cpload pseudo-op. This is used when generating SVR4 | |
12012 | PIC code. It sets the $gp register for the function based on the | |
12013 | function address, which is in the register named in the argument. | |
12014 | This uses a relocation against _gp_disp, which is handled specially | |
12015 | by the linker. The result is: | |
12016 | lui $gp,%hi(_gp_disp) | |
12017 | addiu $gp,$gp,%lo(_gp_disp) | |
12018 | addu $gp,$gp,.cpload argument | |
12019 | The .cpload argument is normally $25 == $t9. */ | |
12020 | ||
12021 | static void | |
12022 | s_cpload (ignore) | |
43841e91 | 12023 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
12024 | { |
12025 | expressionS ex; | |
12026 | int icnt = 0; | |
12027 | ||
6478892d TS |
12028 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
12029 | .cpload is ignored. */ | |
12030 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) | |
252b5132 RH |
12031 | { |
12032 | s_ignore (0); | |
12033 | return; | |
12034 | } | |
12035 | ||
d3ecfc59 | 12036 | /* .cpload should be in a .set noreorder section. */ |
252b5132 RH |
12037 | if (mips_opts.noreorder == 0) |
12038 | as_warn (_(".cpload not in noreorder section")); | |
12039 | ||
12040 | ex.X_op = O_symbol; | |
12041 | ex.X_add_symbol = symbol_find_or_make ("_gp_disp"); | |
12042 | ex.X_op_symbol = NULL; | |
12043 | ex.X_add_number = 0; | |
12044 | ||
12045 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ | |
49309057 | 12046 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
252b5132 | 12047 | |
c9914766 TS |
12048 | macro_build_lui (NULL, &icnt, &ex, mips_gp_register); |
12049 | macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", | |
12050 | mips_gp_register, mips_gp_register, (int) BFD_RELOC_LO16); | |
252b5132 RH |
12051 | |
12052 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t", | |
c9914766 | 12053 | mips_gp_register, mips_gp_register, tc_get_register (0)); |
252b5132 RH |
12054 | |
12055 | demand_empty_rest_of_line (); | |
12056 | } | |
12057 | ||
6478892d TS |
12058 | /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is: |
12059 | .cpsetup $reg1, offset|$reg2, label | |
12060 | ||
12061 | If offset is given, this results in: | |
12062 | sd $gp, offset($sp) | |
956cd1d6 | 12063 | lui $gp, %hi(%neg(%gp_rel(label))) |
698b7d9d TS |
12064 | addiu $gp, $gp, %lo(%neg(%gp_rel(label))) |
12065 | daddu $gp, $gp, $reg1 | |
6478892d TS |
12066 | |
12067 | If $reg2 is given, this results in: | |
12068 | daddu $reg2, $gp, $0 | |
956cd1d6 | 12069 | lui $gp, %hi(%neg(%gp_rel(label))) |
698b7d9d TS |
12070 | addiu $gp, $gp, %lo(%neg(%gp_rel(label))) |
12071 | daddu $gp, $gp, $reg1 | |
12072 | $reg1 is normally $25 == $t9. */ | |
6478892d TS |
12073 | static void |
12074 | s_cpsetup (ignore) | |
12075 | int ignore ATTRIBUTE_UNUSED; | |
12076 | { | |
12077 | expressionS ex_off; | |
12078 | expressionS ex_sym; | |
12079 | int reg1; | |
12080 | int icnt = 0; | |
f21f8242 | 12081 | char *f; |
6478892d | 12082 | |
8586fc66 | 12083 | /* If we are not generating SVR4 PIC code, .cpsetup is ignored. |
6478892d TS |
12084 | We also need NewABI support. */ |
12085 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
12086 | { | |
12087 | s_ignore (0); | |
12088 | return; | |
12089 | } | |
12090 | ||
12091 | reg1 = tc_get_register (0); | |
12092 | SKIP_WHITESPACE (); | |
12093 | if (*input_line_pointer != ',') | |
12094 | { | |
12095 | as_bad (_("missing argument separator ',' for .cpsetup")); | |
12096 | return; | |
12097 | } | |
12098 | else | |
80245285 | 12099 | ++input_line_pointer; |
6478892d TS |
12100 | SKIP_WHITESPACE (); |
12101 | if (*input_line_pointer == '$') | |
80245285 TS |
12102 | { |
12103 | mips_cpreturn_register = tc_get_register (0); | |
12104 | mips_cpreturn_offset = -1; | |
12105 | } | |
6478892d | 12106 | else |
80245285 TS |
12107 | { |
12108 | mips_cpreturn_offset = get_absolute_expression (); | |
12109 | mips_cpreturn_register = -1; | |
12110 | } | |
6478892d TS |
12111 | SKIP_WHITESPACE (); |
12112 | if (*input_line_pointer != ',') | |
12113 | { | |
12114 | as_bad (_("missing argument separator ',' for .cpsetup")); | |
12115 | return; | |
12116 | } | |
12117 | else | |
f9419b05 | 12118 | ++input_line_pointer; |
6478892d | 12119 | SKIP_WHITESPACE (); |
f21f8242 | 12120 | expression (&ex_sym); |
6478892d TS |
12121 | |
12122 | if (mips_cpreturn_register == -1) | |
12123 | { | |
12124 | ex_off.X_op = O_constant; | |
12125 | ex_off.X_add_symbol = NULL; | |
12126 | ex_off.X_op_symbol = NULL; | |
12127 | ex_off.X_add_number = mips_cpreturn_offset; | |
12128 | ||
12129 | macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)", | |
12130 | mips_gp_register, (int) BFD_RELOC_LO16, SP); | |
12131 | } | |
12132 | else | |
12133 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu", | |
12134 | "d,v,t", mips_cpreturn_register, mips_gp_register, 0); | |
12135 | ||
f21f8242 AO |
12136 | /* Ensure there's room for the next two instructions, so that `f' |
12137 | doesn't end up with an address in the wrong frag. */ | |
12138 | frag_grow (8); | |
12139 | f = frag_more (0); | |
6478892d TS |
12140 | macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register, |
12141 | (int) BFD_RELOC_GPREL16); | |
f21f8242 AO |
12142 | fix_new (frag_now, f - frag_now->fr_literal, |
12143 | 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB); | |
12144 | fix_new (frag_now, f - frag_now->fr_literal, | |
12145 | 0, NULL, 0, 0, BFD_RELOC_HI16_S); | |
12146 | ||
12147 | f = frag_more (0); | |
6478892d TS |
12148 | macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j", |
12149 | mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16); | |
f21f8242 AO |
12150 | fix_new (frag_now, f - frag_now->fr_literal, |
12151 | 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB); | |
12152 | fix_new (frag_now, f - frag_now->fr_literal, | |
12153 | 0, NULL, 0, 0, BFD_RELOC_LO16); | |
12154 | ||
8586fc66 TS |
12155 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
12156 | HAVE_64BIT_ADDRESSES ? "daddu" : "addu", "d,v,t", | |
12157 | mips_gp_register, mips_gp_register, reg1); | |
6478892d TS |
12158 | |
12159 | demand_empty_rest_of_line (); | |
12160 | } | |
12161 | ||
12162 | static void | |
12163 | s_cplocal (ignore) | |
12164 | int ignore ATTRIBUTE_UNUSED; | |
12165 | { | |
12166 | /* If we are not generating SVR4 PIC code, or if this is not NewABI code, | |
12167 | .cplocal is ignored. */ | |
12168 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
12169 | { | |
12170 | s_ignore (0); | |
12171 | return; | |
12172 | } | |
12173 | ||
12174 | mips_gp_register = tc_get_register (0); | |
85b51719 | 12175 | demand_empty_rest_of_line (); |
6478892d TS |
12176 | } |
12177 | ||
252b5132 RH |
12178 | /* Handle the .cprestore pseudo-op. This stores $gp into a given |
12179 | offset from $sp. The offset is remembered, and after making a PIC | |
12180 | call $gp is restored from that location. */ | |
12181 | ||
12182 | static void | |
12183 | s_cprestore (ignore) | |
43841e91 | 12184 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
12185 | { |
12186 | expressionS ex; | |
12187 | int icnt = 0; | |
12188 | ||
6478892d | 12189 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
c9914766 | 12190 | .cprestore is ignored. */ |
6478892d | 12191 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) |
252b5132 RH |
12192 | { |
12193 | s_ignore (0); | |
12194 | return; | |
12195 | } | |
12196 | ||
12197 | mips_cprestore_offset = get_absolute_expression (); | |
7a621144 | 12198 | mips_cprestore_valid = 1; |
252b5132 RH |
12199 | |
12200 | ex.X_op = O_constant; | |
12201 | ex.X_add_symbol = NULL; | |
12202 | ex.X_op_symbol = NULL; | |
12203 | ex.X_add_number = mips_cprestore_offset; | |
12204 | ||
885add95 CD |
12205 | macro_build_ldst_constoffset ((char *) NULL, &icnt, &ex, |
12206 | HAVE_32BIT_ADDRESSES ? "sw" : "sd", | |
12207 | mips_gp_register, SP); | |
252b5132 RH |
12208 | |
12209 | demand_empty_rest_of_line (); | |
12210 | } | |
12211 | ||
6478892d TS |
12212 | /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset |
12213 | was given in the preceeding .gpsetup, it results in: | |
12214 | ld $gp, offset($sp) | |
76b3015f | 12215 | |
6478892d TS |
12216 | If a register $reg2 was given there, it results in: |
12217 | daddiu $gp, $gp, $reg2 | |
12218 | */ | |
12219 | static void | |
12220 | s_cpreturn (ignore) | |
12221 | int ignore ATTRIBUTE_UNUSED; | |
12222 | { | |
12223 | expressionS ex; | |
12224 | int icnt = 0; | |
12225 | ||
12226 | /* If we are not generating SVR4 PIC code, .cpreturn is ignored. | |
12227 | We also need NewABI support. */ | |
12228 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
12229 | { | |
12230 | s_ignore (0); | |
12231 | return; | |
12232 | } | |
12233 | ||
12234 | if (mips_cpreturn_register == -1) | |
12235 | { | |
12236 | ex.X_op = O_constant; | |
12237 | ex.X_add_symbol = NULL; | |
12238 | ex.X_op_symbol = NULL; | |
12239 | ex.X_add_number = mips_cpreturn_offset; | |
12240 | ||
12241 | macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)", | |
12242 | mips_gp_register, (int) BFD_RELOC_LO16, SP); | |
12243 | } | |
12244 | else | |
12245 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu", | |
12246 | "d,v,t", mips_gp_register, mips_cpreturn_register, 0); | |
12247 | ||
12248 | demand_empty_rest_of_line (); | |
12249 | } | |
12250 | ||
12251 | /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC | |
12252 | code. It sets the offset to use in gp_rel relocations. */ | |
12253 | ||
12254 | static void | |
12255 | s_gpvalue (ignore) | |
12256 | int ignore ATTRIBUTE_UNUSED; | |
12257 | { | |
12258 | /* If we are not generating SVR4 PIC code, .gpvalue is ignored. | |
12259 | We also need NewABI support. */ | |
12260 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) | |
12261 | { | |
12262 | s_ignore (0); | |
12263 | return; | |
12264 | } | |
12265 | ||
def2e0dd | 12266 | mips_gprel_offset = get_absolute_expression (); |
6478892d TS |
12267 | |
12268 | demand_empty_rest_of_line (); | |
12269 | } | |
12270 | ||
252b5132 RH |
12271 | /* Handle the .gpword pseudo-op. This is used when generating PIC |
12272 | code. It generates a 32 bit GP relative reloc. */ | |
12273 | ||
12274 | static void | |
12275 | s_gpword (ignore) | |
43841e91 | 12276 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
12277 | { |
12278 | symbolS *label; | |
12279 | expressionS ex; | |
12280 | char *p; | |
12281 | ||
12282 | /* When not generating PIC code, this is treated as .word. */ | |
12283 | if (mips_pic != SVR4_PIC) | |
12284 | { | |
12285 | s_cons (2); | |
12286 | return; | |
12287 | } | |
12288 | ||
12289 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
12290 | mips_emit_delays (true); | |
12291 | if (auto_align) | |
12292 | mips_align (2, 0, label); | |
12293 | mips_clear_insn_labels (); | |
12294 | ||
12295 | expression (&ex); | |
12296 | ||
12297 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
12298 | { | |
12299 | as_bad (_("Unsupported use of .gpword")); | |
12300 | ignore_rest_of_line (); | |
12301 | } | |
12302 | ||
12303 | p = frag_more (4); | |
12304 | md_number_to_chars (p, (valueT) 0, 4); | |
c9914766 | 12305 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, false, |
cdf6fd85 | 12306 | BFD_RELOC_GPREL32); |
252b5132 RH |
12307 | |
12308 | demand_empty_rest_of_line (); | |
12309 | } | |
12310 | ||
10181a0d AO |
12311 | static void |
12312 | s_gpdword (ignore) | |
12313 | int ignore ATTRIBUTE_UNUSED; | |
12314 | { | |
12315 | symbolS *label; | |
12316 | expressionS ex; | |
12317 | char *p; | |
12318 | ||
12319 | /* When not generating PIC code, this is treated as .dword. */ | |
12320 | if (mips_pic != SVR4_PIC) | |
12321 | { | |
12322 | s_cons (3); | |
12323 | return; | |
12324 | } | |
12325 | ||
12326 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
12327 | mips_emit_delays (true); | |
12328 | if (auto_align) | |
12329 | mips_align (3, 0, label); | |
12330 | mips_clear_insn_labels (); | |
12331 | ||
12332 | expression (&ex); | |
12333 | ||
12334 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
12335 | { | |
12336 | as_bad (_("Unsupported use of .gpdword")); | |
12337 | ignore_rest_of_line (); | |
12338 | } | |
12339 | ||
12340 | p = frag_more (8); | |
12341 | md_number_to_chars (p, (valueT) 0, 8); | |
12342 | fix_new_exp (frag_now, p - frag_now->fr_literal, 8, &ex, false, | |
12343 | BFD_RELOC_GPREL32); | |
12344 | ||
12345 | /* GPREL32 composed with 64 gives a 64-bit GP offset. */ | |
12346 | ex.X_op = O_absent; | |
12347 | ex.X_add_symbol = 0; | |
12348 | ex.X_add_number = 0; | |
12349 | fix_new_exp (frag_now, p - frag_now->fr_literal, 8, &ex, false, | |
12350 | BFD_RELOC_64); | |
12351 | ||
12352 | demand_empty_rest_of_line (); | |
12353 | } | |
12354 | ||
252b5132 RH |
12355 | /* Handle the .cpadd pseudo-op. This is used when dealing with switch |
12356 | tables in SVR4 PIC code. */ | |
12357 | ||
12358 | static void | |
12359 | s_cpadd (ignore) | |
43841e91 | 12360 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
12361 | { |
12362 | int icnt = 0; | |
12363 | int reg; | |
12364 | ||
10181a0d AO |
12365 | /* This is ignored when not generating SVR4 PIC code. */ |
12366 | if (mips_pic != SVR4_PIC) | |
252b5132 RH |
12367 | { |
12368 | s_ignore (0); | |
12369 | return; | |
12370 | } | |
12371 | ||
12372 | /* Add $gp to the register named as an argument. */ | |
12373 | reg = tc_get_register (0); | |
12374 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
ca4e0257 | 12375 | HAVE_32BIT_ADDRESSES ? "addu" : "daddu", |
c9914766 | 12376 | "d,v,t", reg, reg, mips_gp_register); |
252b5132 | 12377 | |
bdaaa2e1 | 12378 | demand_empty_rest_of_line (); |
252b5132 RH |
12379 | } |
12380 | ||
12381 | /* Handle the .insn pseudo-op. This marks instruction labels in | |
12382 | mips16 mode. This permits the linker to handle them specially, | |
12383 | such as generating jalx instructions when needed. We also make | |
12384 | them odd for the duration of the assembly, in order to generate the | |
12385 | right sort of code. We will make them even in the adjust_symtab | |
12386 | routine, while leaving them marked. This is convenient for the | |
12387 | debugger and the disassembler. The linker knows to make them odd | |
12388 | again. */ | |
12389 | ||
12390 | static void | |
12391 | s_insn (ignore) | |
43841e91 | 12392 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 12393 | { |
f9419b05 | 12394 | mips16_mark_labels (); |
252b5132 RH |
12395 | |
12396 | demand_empty_rest_of_line (); | |
12397 | } | |
12398 | ||
12399 | /* Handle a .stabn directive. We need these in order to mark a label | |
12400 | as being a mips16 text label correctly. Sometimes the compiler | |
12401 | will emit a label, followed by a .stabn, and then switch sections. | |
12402 | If the label and .stabn are in mips16 mode, then the label is | |
12403 | really a mips16 text label. */ | |
12404 | ||
12405 | static void | |
12406 | s_mips_stab (type) | |
12407 | int type; | |
12408 | { | |
f9419b05 | 12409 | if (type == 'n') |
252b5132 RH |
12410 | mips16_mark_labels (); |
12411 | ||
12412 | s_stab (type); | |
12413 | } | |
12414 | ||
12415 | /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. | |
12416 | */ | |
12417 | ||
12418 | static void | |
12419 | s_mips_weakext (ignore) | |
43841e91 | 12420 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
12421 | { |
12422 | char *name; | |
12423 | int c; | |
12424 | symbolS *symbolP; | |
12425 | expressionS exp; | |
12426 | ||
12427 | name = input_line_pointer; | |
12428 | c = get_symbol_end (); | |
12429 | symbolP = symbol_find_or_make (name); | |
12430 | S_SET_WEAK (symbolP); | |
12431 | *input_line_pointer = c; | |
12432 | ||
12433 | SKIP_WHITESPACE (); | |
12434 | ||
12435 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
12436 | { | |
12437 | if (S_IS_DEFINED (symbolP)) | |
12438 | { | |
956cd1d6 | 12439 | as_bad ("ignoring attempt to redefine symbol %s", |
252b5132 RH |
12440 | S_GET_NAME (symbolP)); |
12441 | ignore_rest_of_line (); | |
12442 | return; | |
12443 | } | |
bdaaa2e1 | 12444 | |
252b5132 RH |
12445 | if (*input_line_pointer == ',') |
12446 | { | |
12447 | ++input_line_pointer; | |
12448 | SKIP_WHITESPACE (); | |
12449 | } | |
bdaaa2e1 | 12450 | |
252b5132 RH |
12451 | expression (&exp); |
12452 | if (exp.X_op != O_symbol) | |
12453 | { | |
12454 | as_bad ("bad .weakext directive"); | |
98d3f06f | 12455 | ignore_rest_of_line (); |
252b5132 RH |
12456 | return; |
12457 | } | |
49309057 | 12458 | symbol_set_value_expression (symbolP, &exp); |
252b5132 RH |
12459 | } |
12460 | ||
12461 | demand_empty_rest_of_line (); | |
12462 | } | |
12463 | ||
12464 | /* Parse a register string into a number. Called from the ECOFF code | |
12465 | to parse .frame. The argument is non-zero if this is the frame | |
12466 | register, so that we can record it in mips_frame_reg. */ | |
12467 | ||
12468 | int | |
12469 | tc_get_register (frame) | |
12470 | int frame; | |
12471 | { | |
12472 | int reg; | |
12473 | ||
12474 | SKIP_WHITESPACE (); | |
12475 | if (*input_line_pointer++ != '$') | |
12476 | { | |
12477 | as_warn (_("expected `$'")); | |
85b51719 | 12478 | reg = ZERO; |
252b5132 | 12479 | } |
3882b010 | 12480 | else if (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
12481 | { |
12482 | reg = get_absolute_expression (); | |
12483 | if (reg < 0 || reg >= 32) | |
12484 | { | |
12485 | as_warn (_("Bad register number")); | |
85b51719 | 12486 | reg = ZERO; |
252b5132 RH |
12487 | } |
12488 | } | |
12489 | else | |
12490 | { | |
76db943d | 12491 | if (strncmp (input_line_pointer, "ra", 2) == 0) |
85b51719 TS |
12492 | { |
12493 | reg = RA; | |
12494 | input_line_pointer += 2; | |
12495 | } | |
76db943d | 12496 | else if (strncmp (input_line_pointer, "fp", 2) == 0) |
85b51719 TS |
12497 | { |
12498 | reg = FP; | |
12499 | input_line_pointer += 2; | |
12500 | } | |
252b5132 | 12501 | else if (strncmp (input_line_pointer, "sp", 2) == 0) |
85b51719 TS |
12502 | { |
12503 | reg = SP; | |
12504 | input_line_pointer += 2; | |
12505 | } | |
252b5132 | 12506 | else if (strncmp (input_line_pointer, "gp", 2) == 0) |
85b51719 TS |
12507 | { |
12508 | reg = GP; | |
12509 | input_line_pointer += 2; | |
12510 | } | |
252b5132 | 12511 | else if (strncmp (input_line_pointer, "at", 2) == 0) |
85b51719 TS |
12512 | { |
12513 | reg = AT; | |
12514 | input_line_pointer += 2; | |
12515 | } | |
12516 | else if (strncmp (input_line_pointer, "kt0", 3) == 0) | |
12517 | { | |
12518 | reg = KT0; | |
12519 | input_line_pointer += 3; | |
12520 | } | |
12521 | else if (strncmp (input_line_pointer, "kt1", 3) == 0) | |
12522 | { | |
12523 | reg = KT1; | |
12524 | input_line_pointer += 3; | |
12525 | } | |
12526 | else if (strncmp (input_line_pointer, "zero", 4) == 0) | |
12527 | { | |
12528 | reg = ZERO; | |
12529 | input_line_pointer += 4; | |
12530 | } | |
252b5132 RH |
12531 | else |
12532 | { | |
12533 | as_warn (_("Unrecognized register name")); | |
85b51719 TS |
12534 | reg = ZERO; |
12535 | while (ISALNUM(*input_line_pointer)) | |
12536 | input_line_pointer++; | |
252b5132 | 12537 | } |
252b5132 RH |
12538 | } |
12539 | if (frame) | |
7a621144 DJ |
12540 | { |
12541 | mips_frame_reg = reg != 0 ? reg : SP; | |
12542 | mips_frame_reg_valid = 1; | |
12543 | mips_cprestore_valid = 0; | |
12544 | } | |
252b5132 RH |
12545 | return reg; |
12546 | } | |
12547 | ||
12548 | valueT | |
12549 | md_section_align (seg, addr) | |
12550 | asection *seg; | |
12551 | valueT addr; | |
12552 | { | |
12553 | int align = bfd_get_section_alignment (stdoutput, seg); | |
12554 | ||
12555 | #ifdef OBJ_ELF | |
12556 | /* We don't need to align ELF sections to the full alignment. | |
12557 | However, Irix 5 may prefer that we align them at least to a 16 | |
12558 | byte boundary. We don't bother to align the sections if we are | |
12559 | targeted for an embedded system. */ | |
12560 | if (strcmp (TARGET_OS, "elf") == 0) | |
12561 | return addr; | |
12562 | if (align > 4) | |
12563 | align = 4; | |
12564 | #endif | |
12565 | ||
12566 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
12567 | } | |
12568 | ||
12569 | /* Utility routine, called from above as well. If called while the | |
12570 | input file is still being read, it's only an approximation. (For | |
12571 | example, a symbol may later become defined which appeared to be | |
12572 | undefined earlier.) */ | |
12573 | ||
12574 | static int | |
12575 | nopic_need_relax (sym, before_relaxing) | |
12576 | symbolS *sym; | |
12577 | int before_relaxing; | |
12578 | { | |
12579 | if (sym == 0) | |
12580 | return 0; | |
12581 | ||
6478892d | 12582 | if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0) |
252b5132 RH |
12583 | { |
12584 | const char *symname; | |
12585 | int change; | |
12586 | ||
c9914766 | 12587 | /* Find out whether this symbol can be referenced off the $gp |
252b5132 RH |
12588 | register. It can be if it is smaller than the -G size or if |
12589 | it is in the .sdata or .sbss section. Certain symbols can | |
c9914766 | 12590 | not be referenced off the $gp, although it appears as though |
252b5132 RH |
12591 | they can. */ |
12592 | symname = S_GET_NAME (sym); | |
12593 | if (symname != (const char *) NULL | |
12594 | && (strcmp (symname, "eprol") == 0 | |
12595 | || strcmp (symname, "etext") == 0 | |
12596 | || strcmp (symname, "_gp") == 0 | |
12597 | || strcmp (symname, "edata") == 0 | |
12598 | || strcmp (symname, "_fbss") == 0 | |
12599 | || strcmp (symname, "_fdata") == 0 | |
12600 | || strcmp (symname, "_ftext") == 0 | |
12601 | || strcmp (symname, "end") == 0 | |
12602 | || strcmp (symname, "_gp_disp") == 0)) | |
12603 | change = 1; | |
12604 | else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym)) | |
12605 | && (0 | |
12606 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 ILT |
12607 | || (symbol_get_obj (sym)->ecoff_extern_size != 0 |
12608 | && (symbol_get_obj (sym)->ecoff_extern_size | |
12609 | <= g_switch_value)) | |
252b5132 RH |
12610 | #endif |
12611 | /* We must defer this decision until after the whole | |
12612 | file has been read, since there might be a .extern | |
12613 | after the first use of this symbol. */ | |
12614 | || (before_relaxing | |
12615 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 | 12616 | && symbol_get_obj (sym)->ecoff_extern_size == 0 |
252b5132 RH |
12617 | #endif |
12618 | && S_GET_VALUE (sym) == 0) | |
12619 | || (S_GET_VALUE (sym) != 0 | |
12620 | && S_GET_VALUE (sym) <= g_switch_value))) | |
12621 | change = 0; | |
12622 | else | |
12623 | { | |
12624 | const char *segname; | |
12625 | ||
12626 | segname = segment_name (S_GET_SEGMENT (sym)); | |
12627 | assert (strcmp (segname, ".lit8") != 0 | |
12628 | && strcmp (segname, ".lit4") != 0); | |
12629 | change = (strcmp (segname, ".sdata") != 0 | |
fba2b7f9 GK |
12630 | && strcmp (segname, ".sbss") != 0 |
12631 | && strncmp (segname, ".sdata.", 7) != 0 | |
12632 | && strncmp (segname, ".gnu.linkonce.s.", 16) != 0); | |
252b5132 RH |
12633 | } |
12634 | return change; | |
12635 | } | |
12636 | else | |
c9914766 | 12637 | /* We are not optimizing for the $gp register. */ |
252b5132 RH |
12638 | return 1; |
12639 | } | |
12640 | ||
12641 | /* Given a mips16 variant frag FRAGP, return non-zero if it needs an | |
12642 | extended opcode. SEC is the section the frag is in. */ | |
12643 | ||
12644 | static int | |
12645 | mips16_extended_frag (fragp, sec, stretch) | |
12646 | fragS *fragp; | |
12647 | asection *sec; | |
12648 | long stretch; | |
12649 | { | |
12650 | int type; | |
12651 | register const struct mips16_immed_operand *op; | |
12652 | offsetT val; | |
12653 | int mintiny, maxtiny; | |
12654 | segT symsec; | |
98aa84af | 12655 | fragS *sym_frag; |
252b5132 RH |
12656 | |
12657 | if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) | |
12658 | return 0; | |
12659 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) | |
12660 | return 1; | |
12661 | ||
12662 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
12663 | op = mips16_immed_operands; | |
12664 | while (op->type != type) | |
12665 | { | |
12666 | ++op; | |
12667 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
12668 | } | |
12669 | ||
12670 | if (op->unsp) | |
12671 | { | |
12672 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
12673 | { | |
12674 | mintiny = 1; | |
12675 | maxtiny = 1 << op->nbits; | |
12676 | } | |
12677 | else | |
12678 | { | |
12679 | mintiny = 0; | |
12680 | maxtiny = (1 << op->nbits) - 1; | |
12681 | } | |
12682 | } | |
12683 | else | |
12684 | { | |
12685 | mintiny = - (1 << (op->nbits - 1)); | |
12686 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
12687 | } | |
12688 | ||
98aa84af | 12689 | sym_frag = symbol_get_frag (fragp->fr_symbol); |
ac62c346 | 12690 | val = S_GET_VALUE (fragp->fr_symbol); |
98aa84af | 12691 | symsec = S_GET_SEGMENT (fragp->fr_symbol); |
252b5132 RH |
12692 | |
12693 | if (op->pcrel) | |
12694 | { | |
12695 | addressT addr; | |
12696 | ||
12697 | /* We won't have the section when we are called from | |
12698 | mips_relax_frag. However, we will always have been called | |
12699 | from md_estimate_size_before_relax first. If this is a | |
12700 | branch to a different section, we mark it as such. If SEC is | |
12701 | NULL, and the frag is not marked, then it must be a branch to | |
12702 | the same section. */ | |
12703 | if (sec == NULL) | |
12704 | { | |
12705 | if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype)) | |
12706 | return 1; | |
12707 | } | |
12708 | else | |
12709 | { | |
98aa84af | 12710 | /* Must have been called from md_estimate_size_before_relax. */ |
252b5132 RH |
12711 | if (symsec != sec) |
12712 | { | |
12713 | fragp->fr_subtype = | |
12714 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
12715 | ||
12716 | /* FIXME: We should support this, and let the linker | |
12717 | catch branches and loads that are out of range. */ | |
12718 | as_bad_where (fragp->fr_file, fragp->fr_line, | |
12719 | _("unsupported PC relative reference to different section")); | |
12720 | ||
12721 | return 1; | |
12722 | } | |
98aa84af AM |
12723 | if (fragp != sym_frag && sym_frag->fr_address == 0) |
12724 | /* Assume non-extended on the first relaxation pass. | |
12725 | The address we have calculated will be bogus if this is | |
12726 | a forward branch to another frag, as the forward frag | |
12727 | will have fr_address == 0. */ | |
12728 | return 0; | |
252b5132 RH |
12729 | } |
12730 | ||
12731 | /* In this case, we know for sure that the symbol fragment is in | |
98aa84af AM |
12732 | the same section. If the relax_marker of the symbol fragment |
12733 | differs from the relax_marker of this fragment, we have not | |
12734 | yet adjusted the symbol fragment fr_address. We want to add | |
252b5132 RH |
12735 | in STRETCH in order to get a better estimate of the address. |
12736 | This particularly matters because of the shift bits. */ | |
12737 | if (stretch != 0 | |
98aa84af | 12738 | && sym_frag->relax_marker != fragp->relax_marker) |
252b5132 RH |
12739 | { |
12740 | fragS *f; | |
12741 | ||
12742 | /* Adjust stretch for any alignment frag. Note that if have | |
12743 | been expanding the earlier code, the symbol may be | |
12744 | defined in what appears to be an earlier frag. FIXME: | |
12745 | This doesn't handle the fr_subtype field, which specifies | |
12746 | a maximum number of bytes to skip when doing an | |
12747 | alignment. */ | |
98aa84af | 12748 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) |
252b5132 RH |
12749 | { |
12750 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
12751 | { | |
12752 | if (stretch < 0) | |
12753 | stretch = - ((- stretch) | |
12754 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
12755 | else | |
12756 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
12757 | if (stretch == 0) | |
12758 | break; | |
12759 | } | |
12760 | } | |
12761 | if (f != NULL) | |
12762 | val += stretch; | |
12763 | } | |
12764 | ||
12765 | addr = fragp->fr_address + fragp->fr_fix; | |
12766 | ||
12767 | /* The base address rules are complicated. The base address of | |
12768 | a branch is the following instruction. The base address of a | |
12769 | PC relative load or add is the instruction itself, but if it | |
12770 | is in a delay slot (in which case it can not be extended) use | |
12771 | the address of the instruction whose delay slot it is in. */ | |
12772 | if (type == 'p' || type == 'q') | |
12773 | { | |
12774 | addr += 2; | |
12775 | ||
12776 | /* If we are currently assuming that this frag should be | |
12777 | extended, then, the current address is two bytes | |
bdaaa2e1 | 12778 | higher. */ |
252b5132 RH |
12779 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
12780 | addr += 2; | |
12781 | ||
12782 | /* Ignore the low bit in the target, since it will be set | |
12783 | for a text label. */ | |
12784 | if ((val & 1) != 0) | |
12785 | --val; | |
12786 | } | |
12787 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
12788 | addr -= 4; | |
12789 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
12790 | addr -= 2; | |
12791 | ||
12792 | val -= addr & ~ ((1 << op->shift) - 1); | |
12793 | ||
12794 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
12795 | if (type == 'p' || type == 'q') | |
12796 | val /= 2; | |
12797 | ||
12798 | /* If any of the shifted bits are set, we must use an extended | |
12799 | opcode. If the address depends on the size of this | |
12800 | instruction, this can lead to a loop, so we arrange to always | |
12801 | use an extended opcode. We only check this when we are in | |
12802 | the main relaxation loop, when SEC is NULL. */ | |
12803 | if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL) | |
12804 | { | |
12805 | fragp->fr_subtype = | |
12806 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
12807 | return 1; | |
12808 | } | |
12809 | ||
12810 | /* If we are about to mark a frag as extended because the value | |
12811 | is precisely maxtiny + 1, then there is a chance of an | |
12812 | infinite loop as in the following code: | |
12813 | la $4,foo | |
12814 | .skip 1020 | |
12815 | .align 2 | |
12816 | foo: | |
12817 | In this case when the la is extended, foo is 0x3fc bytes | |
12818 | away, so the la can be shrunk, but then foo is 0x400 away, so | |
12819 | the la must be extended. To avoid this loop, we mark the | |
12820 | frag as extended if it was small, and is about to become | |
12821 | extended with a value of maxtiny + 1. */ | |
12822 | if (val == ((maxtiny + 1) << op->shift) | |
12823 | && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype) | |
12824 | && sec == NULL) | |
12825 | { | |
12826 | fragp->fr_subtype = | |
12827 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
12828 | return 1; | |
12829 | } | |
12830 | } | |
12831 | else if (symsec != absolute_section && sec != NULL) | |
12832 | as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation")); | |
12833 | ||
12834 | if ((val & ((1 << op->shift) - 1)) != 0 | |
12835 | || val < (mintiny << op->shift) | |
12836 | || val > (maxtiny << op->shift)) | |
12837 | return 1; | |
12838 | else | |
12839 | return 0; | |
12840 | } | |
12841 | ||
4a6a3df4 AO |
12842 | /* Compute the length of a branch sequence, and adjust the |
12843 | RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the | |
12844 | worst-case length is computed, with UPDATE being used to indicate | |
12845 | whether an unconditional (-1), branch-likely (+1) or regular (0) | |
12846 | branch is to be computed. */ | |
12847 | static int | |
12848 | relaxed_branch_length (fragp, sec, update) | |
12849 | fragS *fragp; | |
12850 | asection *sec; | |
12851 | int update; | |
12852 | { | |
12853 | boolean toofar; | |
12854 | int length; | |
12855 | ||
12856 | if (fragp | |
12857 | && S_IS_DEFINED (fragp->fr_symbol) | |
12858 | && sec == S_GET_SEGMENT (fragp->fr_symbol)) | |
12859 | { | |
12860 | addressT addr; | |
12861 | offsetT val; | |
12862 | ||
12863 | val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; | |
12864 | ||
12865 | addr = fragp->fr_address + fragp->fr_fix + 4; | |
12866 | ||
12867 | val -= addr; | |
12868 | ||
12869 | toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2); | |
12870 | } | |
12871 | else if (fragp) | |
12872 | /* If the symbol is not defined or it's in a different segment, | |
12873 | assume the user knows what's going on and emit a short | |
12874 | branch. */ | |
12875 | toofar = false; | |
12876 | else | |
12877 | toofar = true; | |
12878 | ||
12879 | if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype)) | |
12880 | fragp->fr_subtype | |
12881 | = RELAX_BRANCH_ENCODE (RELAX_BRANCH_RELOC_S2 (fragp->fr_subtype), | |
12882 | RELAX_BRANCH_UNCOND (fragp->fr_subtype), | |
12883 | RELAX_BRANCH_LIKELY (fragp->fr_subtype), | |
12884 | RELAX_BRANCH_LINK (fragp->fr_subtype), | |
12885 | toofar); | |
12886 | ||
12887 | length = 4; | |
12888 | if (toofar) | |
12889 | { | |
12890 | if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0)) | |
12891 | length += 8; | |
12892 | ||
12893 | if (mips_pic != NO_PIC) | |
12894 | { | |
12895 | /* Additional space for PIC loading of target address. */ | |
12896 | length += 8; | |
12897 | if (mips_opts.isa == ISA_MIPS1) | |
12898 | /* Additional space for $at-stabilizing nop. */ | |
12899 | length += 4; | |
12900 | } | |
12901 | ||
12902 | /* If branch is conditional. */ | |
12903 | if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0)) | |
12904 | length += 8; | |
12905 | } | |
12906 | ||
12907 | return length; | |
12908 | } | |
12909 | ||
252b5132 RH |
12910 | /* Estimate the size of a frag before relaxing. Unless this is the |
12911 | mips16, we are not really relaxing here, and the final size is | |
12912 | encoded in the subtype information. For the mips16, we have to | |
12913 | decide whether we are using an extended opcode or not. */ | |
12914 | ||
252b5132 RH |
12915 | int |
12916 | md_estimate_size_before_relax (fragp, segtype) | |
12917 | fragS *fragp; | |
12918 | asection *segtype; | |
12919 | { | |
43841e91 | 12920 | int change = 0; |
8614eeee | 12921 | boolean linkonce = false; |
252b5132 | 12922 | |
4a6a3df4 AO |
12923 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
12924 | { | |
12925 | ||
12926 | fragp->fr_var = relaxed_branch_length (fragp, segtype, false); | |
12927 | ||
12928 | return fragp->fr_var; | |
12929 | } | |
12930 | ||
252b5132 | 12931 | if (RELAX_MIPS16_P (fragp->fr_subtype)) |
177b4a6a AO |
12932 | /* We don't want to modify the EXTENDED bit here; it might get us |
12933 | into infinite loops. We change it only in mips_relax_frag(). */ | |
12934 | return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2); | |
252b5132 RH |
12935 | |
12936 | if (mips_pic == NO_PIC) | |
12937 | { | |
12938 | change = nopic_need_relax (fragp->fr_symbol, 0); | |
12939 | } | |
12940 | else if (mips_pic == SVR4_PIC) | |
12941 | { | |
12942 | symbolS *sym; | |
12943 | asection *symsec; | |
12944 | ||
12945 | sym = fragp->fr_symbol; | |
12946 | ||
12947 | /* Handle the case of a symbol equated to another symbol. */ | |
e0890092 | 12948 | while (symbol_equated_reloc_p (sym)) |
252b5132 RH |
12949 | { |
12950 | symbolS *n; | |
12951 | ||
12952 | /* It's possible to get a loop here in a badly written | |
12953 | program. */ | |
49309057 | 12954 | n = symbol_get_value_expression (sym)->X_add_symbol; |
252b5132 RH |
12955 | if (n == sym) |
12956 | break; | |
12957 | sym = n; | |
12958 | } | |
12959 | ||
12960 | symsec = S_GET_SEGMENT (sym); | |
12961 | ||
8614eeee UC |
12962 | /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */ |
12963 | if (symsec != segtype && ! S_IS_LOCAL (sym)) | |
beae10d5 KH |
12964 | { |
12965 | if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) | |
12966 | != 0) | |
12967 | linkonce = true; | |
12968 | ||
12969 | /* The GNU toolchain uses an extension for ELF: a section | |
12970 | beginning with the magic string .gnu.linkonce is a linkonce | |
12971 | section. */ | |
12972 | if (strncmp (segment_name (symsec), ".gnu.linkonce", | |
12973 | sizeof ".gnu.linkonce" - 1) == 0) | |
12974 | linkonce = true; | |
12975 | } | |
8614eeee | 12976 | |
252b5132 RH |
12977 | /* This must duplicate the test in adjust_reloc_syms. */ |
12978 | change = (symsec != &bfd_und_section | |
12979 | && symsec != &bfd_abs_section | |
426b0403 | 12980 | && ! bfd_is_com_section (symsec) |
8614eeee | 12981 | && !linkonce |
426b0403 | 12982 | #ifdef OBJ_ELF |
ea4ff978 | 12983 | /* A global or weak symbol is treated as external. */ |
9151e8bf | 12984 | && (OUTPUT_FLAVOR != bfd_target_elf_flavour |
b25a253c | 12985 | || (! S_IS_WEAK (sym) |
bad9ca53 TS |
12986 | && (! S_IS_EXTERNAL (sym) |
12987 | || mips_pic == EMBEDDED_PIC))) | |
426b0403 AM |
12988 | #endif |
12989 | ); | |
252b5132 RH |
12990 | } |
12991 | else | |
12992 | abort (); | |
12993 | ||
12994 | if (change) | |
12995 | { | |
12996 | /* Record the offset to the first reloc in the fr_opcode field. | |
12997 | This lets md_convert_frag and tc_gen_reloc know that the code | |
12998 | must be expanded. */ | |
12999 | fragp->fr_opcode = (fragp->fr_literal | |
13000 | + fragp->fr_fix | |
13001 | - RELAX_OLD (fragp->fr_subtype) | |
13002 | + RELAX_RELOC1 (fragp->fr_subtype)); | |
13003 | /* FIXME: This really needs as_warn_where. */ | |
13004 | if (RELAX_WARN (fragp->fr_subtype)) | |
9a41af64 TS |
13005 | as_warn (_("AT used after \".set noat\" or macro used after " |
13006 | "\".set nomacro\"")); | |
13007 | ||
13008 | return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype); | |
252b5132 RH |
13009 | } |
13010 | ||
9a41af64 | 13011 | return 0; |
252b5132 RH |
13012 | } |
13013 | ||
13014 | /* This is called to see whether a reloc against a defined symbol | |
13015 | should be converted into a reloc against a section. Don't adjust | |
13016 | MIPS16 jump relocations, so we don't have to worry about the format | |
13017 | of the offset in the .o file. Don't adjust relocations against | |
13018 | mips16 symbols, so that the linker can find them if it needs to set | |
13019 | up a stub. */ | |
13020 | ||
13021 | int | |
13022 | mips_fix_adjustable (fixp) | |
13023 | fixS *fixp; | |
13024 | { | |
13025 | if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP) | |
13026 | return 0; | |
a161fe53 | 13027 | |
252b5132 RH |
13028 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
13029 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
13030 | return 0; | |
a161fe53 | 13031 | |
252b5132 RH |
13032 | if (fixp->fx_addsy == NULL) |
13033 | return 1; | |
a161fe53 | 13034 | |
252b5132 RH |
13035 | #ifdef OBJ_ELF |
13036 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
13037 | && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16 | |
13038 | && fixp->fx_subsy == NULL) | |
13039 | return 0; | |
13040 | #endif | |
a161fe53 | 13041 | |
252b5132 RH |
13042 | return 1; |
13043 | } | |
13044 | ||
13045 | /* Translate internal representation of relocation info to BFD target | |
13046 | format. */ | |
13047 | ||
13048 | arelent ** | |
13049 | tc_gen_reloc (section, fixp) | |
43841e91 | 13050 | asection *section ATTRIBUTE_UNUSED; |
252b5132 RH |
13051 | fixS *fixp; |
13052 | { | |
13053 | static arelent *retval[4]; | |
13054 | arelent *reloc; | |
13055 | bfd_reloc_code_real_type code; | |
13056 | ||
13057 | reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent)); | |
13058 | retval[1] = NULL; | |
13059 | ||
49309057 ILT |
13060 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
13061 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
13062 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
13063 | ||
13064 | if (mips_pic == EMBEDDED_PIC | |
13065 | && SWITCH_TABLE (fixp)) | |
13066 | { | |
13067 | /* For a switch table entry we use a special reloc. The addend | |
13068 | is actually the difference between the reloc address and the | |
13069 | subtrahend. */ | |
13070 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); | |
13071 | if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour) | |
13072 | as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc")); | |
13073 | fixp->fx_r_type = BFD_RELOC_GPREL32; | |
13074 | } | |
13075 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16) | |
13076 | { | |
4514d474 CD |
13077 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) |
13078 | reloc->addend = fixp->fx_addnumber; | |
252b5132 | 13079 | else |
4514d474 CD |
13080 | { |
13081 | /* We use a special addend for an internal RELLO reloc. */ | |
13082 | if (symbol_section_p (fixp->fx_addsy)) | |
13083 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); | |
13084 | else | |
13085 | reloc->addend = fixp->fx_addnumber + reloc->address; | |
13086 | } | |
252b5132 RH |
13087 | } |
13088 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S) | |
13089 | { | |
13090 | assert (fixp->fx_next != NULL | |
13091 | && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16); | |
4514d474 CD |
13092 | |
13093 | /* The reloc is relative to the RELLO; adjust the addend | |
252b5132 | 13094 | accordingly. */ |
4514d474 CD |
13095 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) |
13096 | reloc->addend = fixp->fx_next->fx_addnumber; | |
252b5132 | 13097 | else |
4514d474 CD |
13098 | { |
13099 | /* We use a special addend for an internal RELHI reloc. */ | |
13100 | if (symbol_section_p (fixp->fx_addsy)) | |
13101 | reloc->addend = (fixp->fx_next->fx_frag->fr_address | |
13102 | + fixp->fx_next->fx_where | |
13103 | - S_GET_VALUE (fixp->fx_subsy)); | |
13104 | else | |
13105 | reloc->addend = (fixp->fx_addnumber | |
13106 | + fixp->fx_next->fx_frag->fr_address | |
13107 | + fixp->fx_next->fx_where); | |
13108 | } | |
252b5132 | 13109 | } |
4514d474 CD |
13110 | else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour) |
13111 | reloc->addend = fixp->fx_addnumber; | |
252b5132 RH |
13112 | else |
13113 | { | |
13114 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour) | |
13115 | /* A gruesome hack which is a result of the gruesome gas reloc | |
13116 | handling. */ | |
13117 | reloc->addend = reloc->address; | |
13118 | else | |
13119 | reloc->addend = -reloc->address; | |
13120 | } | |
13121 | ||
13122 | /* If this is a variant frag, we may need to adjust the existing | |
13123 | reloc and generate a new one. */ | |
13124 | if (fixp->fx_frag->fr_opcode != NULL | |
ed6fb7bd SC |
13125 | && ((fixp->fx_r_type == BFD_RELOC_GPREL16 |
13126 | && ! HAVE_NEWABI) | |
252b5132 RH |
13127 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16 |
13128 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16 | |
13129 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
13130 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16 | |
13131 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
6478892d | 13132 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16) |
ed6fb7bd | 13133 | ) |
252b5132 RH |
13134 | { |
13135 | arelent *reloc2; | |
13136 | ||
13137 | assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype)); | |
13138 | ||
13139 | /* If this is not the last reloc in this frag, then we have two | |
13140 | GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a | |
13141 | CALL_HI16/CALL_LO16, both of which are being replaced. Let | |
13142 | the second one handle all of them. */ | |
13143 | if (fixp->fx_next != NULL | |
13144 | && fixp->fx_frag == fixp->fx_next->fx_frag) | |
13145 | { | |
cdf6fd85 TS |
13146 | assert ((fixp->fx_r_type == BFD_RELOC_GPREL16 |
13147 | && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16) | |
252b5132 RH |
13148 | || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 |
13149 | && (fixp->fx_next->fx_r_type | |
13150 | == BFD_RELOC_MIPS_GOT_LO16)) | |
13151 | || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
13152 | && (fixp->fx_next->fx_r_type | |
13153 | == BFD_RELOC_MIPS_CALL_LO16))); | |
13154 | retval[0] = NULL; | |
13155 | return retval; | |
13156 | } | |
13157 | ||
13158 | fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal; | |
13159 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
13160 | reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent)); | |
13161 | retval[2] = NULL; | |
49309057 ILT |
13162 | reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
13163 | *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
13164 | reloc2->address = (reloc->address |
13165 | + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype) | |
13166 | - RELAX_RELOC1 (fixp->fx_frag->fr_subtype))); | |
13167 | reloc2->addend = fixp->fx_addnumber; | |
13168 | reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16); | |
13169 | assert (reloc2->howto != NULL); | |
13170 | ||
13171 | if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype)) | |
13172 | { | |
13173 | arelent *reloc3; | |
13174 | ||
13175 | reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent)); | |
13176 | retval[3] = NULL; | |
13177 | *reloc3 = *reloc2; | |
13178 | reloc3->address += 4; | |
13179 | } | |
13180 | ||
13181 | if (mips_pic == NO_PIC) | |
13182 | { | |
cdf6fd85 | 13183 | assert (fixp->fx_r_type == BFD_RELOC_GPREL16); |
252b5132 RH |
13184 | fixp->fx_r_type = BFD_RELOC_HI16_S; |
13185 | } | |
13186 | else if (mips_pic == SVR4_PIC) | |
13187 | { | |
13188 | switch (fixp->fx_r_type) | |
13189 | { | |
13190 | default: | |
13191 | abort (); | |
13192 | case BFD_RELOC_MIPS_GOT16: | |
13193 | break; | |
252b5132 RH |
13194 | case BFD_RELOC_MIPS_GOT_LO16: |
13195 | case BFD_RELOC_MIPS_CALL_LO16: | |
13196 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT16; | |
13197 | break; | |
ed6fb7bd SC |
13198 | case BFD_RELOC_MIPS_CALL16: |
13199 | if (HAVE_NEWABI) | |
13200 | { | |
13201 | /* BFD_RELOC_MIPS_GOT16;*/ | |
13202 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT_PAGE; | |
13203 | reloc2->howto = bfd_reloc_type_lookup | |
13204 | (stdoutput, BFD_RELOC_MIPS_GOT_OFST); | |
13205 | } | |
13206 | else | |
13207 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT16; | |
13208 | break; | |
252b5132 RH |
13209 | } |
13210 | } | |
13211 | else | |
13212 | abort (); | |
ed6fb7bd SC |
13213 | |
13214 | /* newabi uses R_MIPS_GOT_DISP for local symbols */ | |
13215 | if (HAVE_NEWABI && BFD_RELOC_MIPS_GOT_LO16) | |
13216 | { | |
13217 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT_DISP; | |
13218 | retval[1] = NULL; | |
13219 | } | |
252b5132 RH |
13220 | } |
13221 | ||
438c16b8 TS |
13222 | /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable |
13223 | entry to be used in the relocation's section offset. */ | |
13224 | if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
252b5132 RH |
13225 | { |
13226 | reloc->address = reloc->addend; | |
13227 | reloc->addend = 0; | |
13228 | } | |
13229 | ||
13230 | /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that | |
13231 | fixup_segment converted a non-PC relative reloc into a PC | |
13232 | relative reloc. In such a case, we need to convert the reloc | |
13233 | code. */ | |
13234 | code = fixp->fx_r_type; | |
13235 | if (fixp->fx_pcrel) | |
13236 | { | |
13237 | switch (code) | |
13238 | { | |
13239 | case BFD_RELOC_8: | |
13240 | code = BFD_RELOC_8_PCREL; | |
13241 | break; | |
13242 | case BFD_RELOC_16: | |
13243 | code = BFD_RELOC_16_PCREL; | |
13244 | break; | |
13245 | case BFD_RELOC_32: | |
13246 | code = BFD_RELOC_32_PCREL; | |
13247 | break; | |
13248 | case BFD_RELOC_64: | |
13249 | code = BFD_RELOC_64_PCREL; | |
13250 | break; | |
13251 | case BFD_RELOC_8_PCREL: | |
13252 | case BFD_RELOC_16_PCREL: | |
13253 | case BFD_RELOC_32_PCREL: | |
13254 | case BFD_RELOC_64_PCREL: | |
13255 | case BFD_RELOC_16_PCREL_S2: | |
13256 | case BFD_RELOC_PCREL_HI16_S: | |
13257 | case BFD_RELOC_PCREL_LO16: | |
13258 | break; | |
13259 | default: | |
13260 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
13261 | _("Cannot make %s relocation PC relative"), | |
13262 | bfd_get_reloc_code_name (code)); | |
13263 | } | |
13264 | } | |
13265 | ||
add55e1f RS |
13266 | #ifdef OBJ_ELF |
13267 | /* md_apply_fix3 has a double-subtraction hack to get | |
13268 | bfd_install_relocation to behave nicely. GPREL relocations are | |
13269 | handled correctly without this hack, so undo it here. We can't | |
13270 | stop md_apply_fix3 from subtracting twice in the first place since | |
13271 | the fake addend is required for variant frags above. */ | |
13272 | if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour | |
98605598 | 13273 | && (code == BFD_RELOC_GPREL16 || code == BFD_RELOC_MIPS16_GPREL) |
add55e1f RS |
13274 | && reloc->addend != 0 |
13275 | && mips_need_elf_addend_fixup (fixp)) | |
13276 | reloc->addend += S_GET_VALUE (fixp->fx_addsy); | |
13277 | #endif | |
13278 | ||
252b5132 RH |
13279 | /* To support a PC relative reloc when generating embedded PIC code |
13280 | for ECOFF, we use a Cygnus extension. We check for that here to | |
13281 | make sure that we don't let such a reloc escape normally. */ | |
bb2d6cd7 GK |
13282 | if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
13283 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
252b5132 RH |
13284 | && code == BFD_RELOC_16_PCREL_S2 |
13285 | && mips_pic != EMBEDDED_PIC) | |
13286 | reloc->howto = NULL; | |
13287 | else | |
13288 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
13289 | ||
13290 | if (reloc->howto == NULL) | |
13291 | { | |
13292 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
13293 | _("Can not represent %s relocation in this object file format"), | |
13294 | bfd_get_reloc_code_name (code)); | |
13295 | retval[0] = NULL; | |
13296 | } | |
13297 | ||
13298 | return retval; | |
13299 | } | |
13300 | ||
13301 | /* Relax a machine dependent frag. This returns the amount by which | |
13302 | the current size of the frag should change. */ | |
13303 | ||
13304 | int | |
4a6a3df4 AO |
13305 | mips_relax_frag (sec, fragp, stretch) |
13306 | asection *sec; | |
252b5132 RH |
13307 | fragS *fragp; |
13308 | long stretch; | |
13309 | { | |
4a6a3df4 AO |
13310 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
13311 | { | |
13312 | offsetT old_var = fragp->fr_var; | |
13313 | ||
13314 | fragp->fr_var = relaxed_branch_length (fragp, sec, true); | |
13315 | ||
13316 | return fragp->fr_var - old_var; | |
13317 | } | |
13318 | ||
252b5132 RH |
13319 | if (! RELAX_MIPS16_P (fragp->fr_subtype)) |
13320 | return 0; | |
13321 | ||
c4e7957c | 13322 | if (mips16_extended_frag (fragp, NULL, stretch)) |
252b5132 RH |
13323 | { |
13324 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
13325 | return 0; | |
13326 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
13327 | return 2; | |
13328 | } | |
13329 | else | |
13330 | { | |
13331 | if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
13332 | return 0; | |
13333 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
13334 | return -2; | |
13335 | } | |
13336 | ||
13337 | return 0; | |
13338 | } | |
13339 | ||
13340 | /* Convert a machine dependent frag. */ | |
13341 | ||
13342 | void | |
13343 | md_convert_frag (abfd, asec, fragp) | |
43841e91 | 13344 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
13345 | segT asec; |
13346 | fragS *fragp; | |
13347 | { | |
13348 | int old, new; | |
13349 | char *fixptr; | |
13350 | ||
4a6a3df4 AO |
13351 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
13352 | { | |
13353 | bfd_byte *buf; | |
13354 | unsigned long insn; | |
13355 | expressionS exp; | |
13356 | fixS *fixp; | |
13357 | ||
13358 | buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix; | |
13359 | ||
13360 | if (target_big_endian) | |
13361 | insn = bfd_getb32 (buf); | |
13362 | else | |
13363 | insn = bfd_getl32 (buf); | |
13364 | ||
13365 | if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype)) | |
13366 | { | |
13367 | /* We generate a fixup instead of applying it right now | |
13368 | because, if there are linker relaxations, we're going to | |
13369 | need the relocations. */ | |
13370 | exp.X_op = O_symbol; | |
13371 | exp.X_add_symbol = fragp->fr_symbol; | |
13372 | exp.X_add_number = fragp->fr_offset; | |
13373 | ||
13374 | fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal, | |
13375 | 4, &exp, 1, | |
13376 | RELAX_BRANCH_RELOC_S2 (fragp->fr_subtype) | |
13377 | ? BFD_RELOC_16_PCREL_S2 | |
13378 | : BFD_RELOC_16_PCREL); | |
13379 | fixp->fx_file = fragp->fr_file; | |
13380 | fixp->fx_line = fragp->fr_line; | |
13381 | ||
13382 | md_number_to_chars ((char *)buf, insn, 4); | |
13383 | buf += 4; | |
13384 | } | |
13385 | else | |
13386 | { | |
13387 | int i; | |
13388 | ||
13389 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
13390 | _("relaxed out-of-range branch into a jump")); | |
13391 | ||
13392 | if (RELAX_BRANCH_UNCOND (fragp->fr_subtype)) | |
13393 | goto uncond; | |
13394 | ||
13395 | if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype)) | |
13396 | { | |
13397 | /* Reverse the branch. */ | |
13398 | switch ((insn >> 28) & 0xf) | |
13399 | { | |
13400 | case 4: | |
13401 | /* bc[0-3][tf]l? and bc1any[24][ft] instructions can | |
13402 | have the condition reversed by tweaking a single | |
13403 | bit, and their opcodes all have 0x4???????. */ | |
13404 | assert ((insn & 0xf1000000) == 0x41000000); | |
13405 | insn ^= 0x00010000; | |
13406 | break; | |
13407 | ||
13408 | case 0: | |
13409 | /* bltz 0x04000000 bgez 0x04010000 | |
13410 | bltzal 0x04100000 bgezal 0x04110000 */ | |
13411 | assert ((insn & 0xfc0e0000) == 0x04000000); | |
13412 | insn ^= 0x00010000; | |
13413 | break; | |
13414 | ||
13415 | case 1: | |
13416 | /* beq 0x10000000 bne 0x14000000 | |
13417 | blez 0x18000000 bgtz 0x1c000000 */ | |
13418 | insn ^= 0x04000000; | |
13419 | break; | |
13420 | ||
13421 | default: | |
13422 | abort (); | |
13423 | } | |
13424 | } | |
13425 | ||
13426 | if (RELAX_BRANCH_LINK (fragp->fr_subtype)) | |
13427 | { | |
13428 | /* Clear the and-link bit. */ | |
13429 | assert ((insn & 0xfc1c0000) == 0x04100000); | |
13430 | ||
13431 | /* bltzal 0x04100000 bgezal 0x04110000 | |
13432 | bltzall 0x04120000 bgezall 0x04130000 */ | |
13433 | insn &= ~0x00100000; | |
13434 | } | |
13435 | ||
13436 | /* Branch over the branch (if the branch was likely) or the | |
13437 | full jump (not likely case). Compute the offset from the | |
13438 | current instruction to branch to. */ | |
13439 | if (RELAX_BRANCH_LIKELY (fragp->fr_subtype)) | |
13440 | i = 16; | |
13441 | else | |
13442 | { | |
13443 | /* How many bytes in instructions we've already emitted? */ | |
13444 | i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix; | |
13445 | /* How many bytes in instructions from here to the end? */ | |
13446 | i = fragp->fr_var - i; | |
13447 | } | |
13448 | /* Convert to instruction count. */ | |
13449 | i >>= 2; | |
13450 | /* Branch counts from the next instruction. */ | |
13451 | i--; | |
13452 | insn |= i; | |
13453 | /* Branch over the jump. */ | |
13454 | md_number_to_chars ((char *)buf, insn, 4); | |
13455 | buf += 4; | |
13456 | ||
13457 | /* Nop */ | |
13458 | md_number_to_chars ((char*)buf, 0, 4); | |
13459 | buf += 4; | |
13460 | ||
13461 | if (RELAX_BRANCH_LIKELY (fragp->fr_subtype)) | |
13462 | { | |
13463 | /* beql $0, $0, 2f */ | |
13464 | insn = 0x50000000; | |
13465 | /* Compute the PC offset from the current instruction to | |
13466 | the end of the variable frag. */ | |
13467 | /* How many bytes in instructions we've already emitted? */ | |
13468 | i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix; | |
13469 | /* How many bytes in instructions from here to the end? */ | |
13470 | i = fragp->fr_var - i; | |
13471 | /* Convert to instruction count. */ | |
13472 | i >>= 2; | |
13473 | /* Don't decrement i, because we want to branch over the | |
13474 | delay slot. */ | |
13475 | ||
13476 | insn |= i; | |
13477 | md_number_to_chars ((char *)buf, insn, 4); | |
13478 | buf += 4; | |
13479 | ||
13480 | md_number_to_chars ((char *)buf, 0, 4); | |
13481 | buf += 4; | |
13482 | } | |
13483 | ||
13484 | uncond: | |
13485 | if (mips_pic == NO_PIC) | |
13486 | { | |
13487 | /* j or jal. */ | |
13488 | insn = (RELAX_BRANCH_LINK (fragp->fr_subtype) | |
13489 | ? 0x0c000000 : 0x08000000); | |
13490 | exp.X_op = O_symbol; | |
13491 | exp.X_add_symbol = fragp->fr_symbol; | |
13492 | exp.X_add_number = fragp->fr_offset; | |
13493 | ||
13494 | fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal, | |
13495 | 4, &exp, 0, BFD_RELOC_MIPS_JMP); | |
13496 | fixp->fx_file = fragp->fr_file; | |
13497 | fixp->fx_line = fragp->fr_line; | |
13498 | ||
13499 | md_number_to_chars ((char*)buf, insn, 4); | |
13500 | buf += 4; | |
13501 | } | |
13502 | else | |
13503 | { | |
13504 | /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */ | |
13505 | insn = HAVE_64BIT_ADDRESSES ? 0xdf810000 : 0x8f810000; | |
13506 | exp.X_op = O_symbol; | |
13507 | exp.X_add_symbol = fragp->fr_symbol; | |
13508 | exp.X_add_number = fragp->fr_offset; | |
13509 | ||
13510 | if (fragp->fr_offset) | |
13511 | { | |
13512 | exp.X_add_symbol = make_expr_symbol (&exp); | |
13513 | exp.X_add_number = 0; | |
13514 | } | |
13515 | ||
13516 | fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal, | |
13517 | 4, &exp, 0, BFD_RELOC_MIPS_GOT16); | |
13518 | fixp->fx_file = fragp->fr_file; | |
13519 | fixp->fx_line = fragp->fr_line; | |
13520 | ||
13521 | md_number_to_chars ((char*)buf, insn, 4); | |
13522 | buf += 4; | |
13523 | ||
13524 | if (mips_opts.isa == ISA_MIPS1) | |
13525 | { | |
13526 | /* nop */ | |
13527 | md_number_to_chars ((char*)buf, 0, 4); | |
13528 | buf += 4; | |
13529 | } | |
13530 | ||
13531 | /* d/addiu $at, $at, <sym> R_MIPS_LO16 */ | |
13532 | insn = HAVE_64BIT_ADDRESSES ? 0x64210000 : 0x24210000; | |
13533 | ||
13534 | fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal, | |
13535 | 4, &exp, 0, BFD_RELOC_LO16); | |
13536 | fixp->fx_file = fragp->fr_file; | |
13537 | fixp->fx_line = fragp->fr_line; | |
13538 | ||
13539 | md_number_to_chars ((char*)buf, insn, 4); | |
13540 | buf += 4; | |
13541 | ||
13542 | /* j(al)r $at. */ | |
13543 | if (RELAX_BRANCH_LINK (fragp->fr_subtype)) | |
13544 | insn = 0x0020f809; | |
13545 | else | |
13546 | insn = 0x00200008; | |
13547 | ||
13548 | md_number_to_chars ((char*)buf, insn, 4); | |
13549 | buf += 4; | |
13550 | } | |
13551 | } | |
13552 | ||
13553 | assert (buf == (bfd_byte *)fragp->fr_literal | |
13554 | + fragp->fr_fix + fragp->fr_var); | |
13555 | ||
13556 | fragp->fr_fix += fragp->fr_var; | |
13557 | ||
13558 | return; | |
13559 | } | |
13560 | ||
252b5132 RH |
13561 | if (RELAX_MIPS16_P (fragp->fr_subtype)) |
13562 | { | |
13563 | int type; | |
13564 | register const struct mips16_immed_operand *op; | |
13565 | boolean small, ext; | |
13566 | offsetT val; | |
13567 | bfd_byte *buf; | |
13568 | unsigned long insn; | |
13569 | boolean use_extend; | |
13570 | unsigned short extend; | |
13571 | ||
13572 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
13573 | op = mips16_immed_operands; | |
13574 | while (op->type != type) | |
13575 | ++op; | |
13576 | ||
13577 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
13578 | { | |
13579 | small = false; | |
13580 | ext = true; | |
13581 | } | |
13582 | else | |
13583 | { | |
13584 | small = true; | |
13585 | ext = false; | |
13586 | } | |
13587 | ||
6386f3a7 | 13588 | resolve_symbol_value (fragp->fr_symbol); |
252b5132 RH |
13589 | val = S_GET_VALUE (fragp->fr_symbol); |
13590 | if (op->pcrel) | |
13591 | { | |
13592 | addressT addr; | |
13593 | ||
13594 | addr = fragp->fr_address + fragp->fr_fix; | |
13595 | ||
13596 | /* The rules for the base address of a PC relative reloc are | |
13597 | complicated; see mips16_extended_frag. */ | |
13598 | if (type == 'p' || type == 'q') | |
13599 | { | |
13600 | addr += 2; | |
13601 | if (ext) | |
13602 | addr += 2; | |
13603 | /* Ignore the low bit in the target, since it will be | |
13604 | set for a text label. */ | |
13605 | if ((val & 1) != 0) | |
13606 | --val; | |
13607 | } | |
13608 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
13609 | addr -= 4; | |
13610 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
13611 | addr -= 2; | |
13612 | ||
13613 | addr &= ~ (addressT) ((1 << op->shift) - 1); | |
13614 | val -= addr; | |
13615 | ||
13616 | /* Make sure the section winds up with the alignment we have | |
13617 | assumed. */ | |
13618 | if (op->shift > 0) | |
13619 | record_alignment (asec, op->shift); | |
13620 | } | |
13621 | ||
13622 | if (ext | |
13623 | && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype) | |
13624 | || RELAX_MIPS16_DSLOT (fragp->fr_subtype))) | |
13625 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
13626 | _("extended instruction in delay slot")); | |
13627 | ||
13628 | buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix); | |
13629 | ||
13630 | if (target_big_endian) | |
13631 | insn = bfd_getb16 (buf); | |
13632 | else | |
13633 | insn = bfd_getl16 (buf); | |
13634 | ||
13635 | mips16_immed (fragp->fr_file, fragp->fr_line, type, val, | |
13636 | RELAX_MIPS16_USER_EXT (fragp->fr_subtype), | |
13637 | small, ext, &insn, &use_extend, &extend); | |
13638 | ||
13639 | if (use_extend) | |
13640 | { | |
874e8986 | 13641 | md_number_to_chars ((char *) buf, 0xf000 | extend, 2); |
252b5132 RH |
13642 | fragp->fr_fix += 2; |
13643 | buf += 2; | |
13644 | } | |
13645 | ||
874e8986 | 13646 | md_number_to_chars ((char *) buf, insn, 2); |
252b5132 RH |
13647 | fragp->fr_fix += 2; |
13648 | buf += 2; | |
13649 | } | |
13650 | else | |
13651 | { | |
13652 | if (fragp->fr_opcode == NULL) | |
13653 | return; | |
13654 | ||
13655 | old = RELAX_OLD (fragp->fr_subtype); | |
13656 | new = RELAX_NEW (fragp->fr_subtype); | |
13657 | fixptr = fragp->fr_literal + fragp->fr_fix; | |
13658 | ||
13659 | if (new > 0) | |
13660 | memcpy (fixptr - old, fixptr, new); | |
13661 | ||
13662 | fragp->fr_fix += new - old; | |
13663 | } | |
13664 | } | |
13665 | ||
13666 | #ifdef OBJ_ELF | |
13667 | ||
13668 | /* This function is called after the relocs have been generated. | |
13669 | We've been storing mips16 text labels as odd. Here we convert them | |
13670 | back to even for the convenience of the debugger. */ | |
13671 | ||
13672 | void | |
13673 | mips_frob_file_after_relocs () | |
13674 | { | |
13675 | asymbol **syms; | |
13676 | unsigned int count, i; | |
13677 | ||
13678 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
13679 | return; | |
13680 | ||
13681 | syms = bfd_get_outsymbols (stdoutput); | |
13682 | count = bfd_get_symcount (stdoutput); | |
13683 | for (i = 0; i < count; i++, syms++) | |
13684 | { | |
13685 | if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16 | |
13686 | && ((*syms)->value & 1) != 0) | |
13687 | { | |
13688 | (*syms)->value &= ~1; | |
13689 | /* If the symbol has an odd size, it was probably computed | |
13690 | incorrectly, so adjust that as well. */ | |
13691 | if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0) | |
13692 | ++elf_symbol (*syms)->internal_elf_sym.st_size; | |
13693 | } | |
13694 | } | |
13695 | } | |
13696 | ||
13697 | #endif | |
13698 | ||
13699 | /* This function is called whenever a label is defined. It is used | |
13700 | when handling branch delays; if a branch has a label, we assume we | |
13701 | can not move it. */ | |
13702 | ||
13703 | void | |
13704 | mips_define_label (sym) | |
13705 | symbolS *sym; | |
13706 | { | |
13707 | struct insn_label_list *l; | |
13708 | ||
13709 | if (free_insn_labels == NULL) | |
13710 | l = (struct insn_label_list *) xmalloc (sizeof *l); | |
13711 | else | |
13712 | { | |
13713 | l = free_insn_labels; | |
13714 | free_insn_labels = l->next; | |
13715 | } | |
13716 | ||
13717 | l->label = sym; | |
13718 | l->next = insn_labels; | |
13719 | insn_labels = l; | |
13720 | } | |
13721 | \f | |
13722 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
13723 | ||
13724 | /* Some special processing for a MIPS ELF file. */ | |
13725 | ||
13726 | void | |
13727 | mips_elf_final_processing () | |
13728 | { | |
13729 | /* Write out the register information. */ | |
316f5878 | 13730 | if (mips_abi != N64_ABI) |
252b5132 RH |
13731 | { |
13732 | Elf32_RegInfo s; | |
13733 | ||
13734 | s.ri_gprmask = mips_gprmask; | |
13735 | s.ri_cprmask[0] = mips_cprmask[0]; | |
13736 | s.ri_cprmask[1] = mips_cprmask[1]; | |
13737 | s.ri_cprmask[2] = mips_cprmask[2]; | |
13738 | s.ri_cprmask[3] = mips_cprmask[3]; | |
13739 | /* The gp_value field is set by the MIPS ELF backend. */ | |
13740 | ||
13741 | bfd_mips_elf32_swap_reginfo_out (stdoutput, &s, | |
13742 | ((Elf32_External_RegInfo *) | |
13743 | mips_regmask_frag)); | |
13744 | } | |
13745 | else | |
13746 | { | |
13747 | Elf64_Internal_RegInfo s; | |
13748 | ||
13749 | s.ri_gprmask = mips_gprmask; | |
13750 | s.ri_pad = 0; | |
13751 | s.ri_cprmask[0] = mips_cprmask[0]; | |
13752 | s.ri_cprmask[1] = mips_cprmask[1]; | |
13753 | s.ri_cprmask[2] = mips_cprmask[2]; | |
13754 | s.ri_cprmask[3] = mips_cprmask[3]; | |
13755 | /* The gp_value field is set by the MIPS ELF backend. */ | |
13756 | ||
13757 | bfd_mips_elf64_swap_reginfo_out (stdoutput, &s, | |
13758 | ((Elf64_External_RegInfo *) | |
13759 | mips_regmask_frag)); | |
13760 | } | |
13761 | ||
13762 | /* Set the MIPS ELF flag bits. FIXME: There should probably be some | |
13763 | sort of BFD interface for this. */ | |
13764 | if (mips_any_noreorder) | |
13765 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER; | |
13766 | if (mips_pic != NO_PIC) | |
13767 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC; | |
13768 | ||
98d3f06f | 13769 | /* Set MIPS ELF flags for ASEs. */ |
a4672219 TS |
13770 | if (file_ase_mips16) |
13771 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16; | |
1f25f5d3 CD |
13772 | #if 0 /* XXX FIXME */ |
13773 | if (file_ase_mips3d) | |
13774 | elf_elfheader (stdoutput)->e_flags |= ???; | |
13775 | #endif | |
deec1734 CD |
13776 | if (file_ase_mdmx) |
13777 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX; | |
1f25f5d3 | 13778 | |
bdaaa2e1 | 13779 | /* Set the MIPS ELF ABI flags. */ |
316f5878 | 13780 | if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32) |
252b5132 | 13781 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32; |
316f5878 | 13782 | else if (mips_abi == O64_ABI) |
252b5132 | 13783 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64; |
316f5878 | 13784 | else if (mips_abi == EABI_ABI) |
252b5132 | 13785 | { |
316f5878 | 13786 | if (!file_mips_gp32) |
252b5132 RH |
13787 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64; |
13788 | else | |
13789 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32; | |
13790 | } | |
316f5878 | 13791 | else if (mips_abi == N32_ABI) |
be00bddd TS |
13792 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2; |
13793 | ||
c9914766 | 13794 | /* Nothing to do for N64_ABI. */ |
252b5132 RH |
13795 | |
13796 | if (mips_32bitmode) | |
13797 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE; | |
13798 | } | |
13799 | ||
13800 | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ | |
13801 | \f | |
beae10d5 KH |
13802 | typedef struct proc { |
13803 | symbolS *isym; | |
13804 | unsigned long reg_mask; | |
13805 | unsigned long reg_offset; | |
13806 | unsigned long fpreg_mask; | |
13807 | unsigned long fpreg_offset; | |
13808 | unsigned long frame_offset; | |
13809 | unsigned long frame_reg; | |
13810 | unsigned long pc_reg; | |
13811 | } procS; | |
252b5132 RH |
13812 | |
13813 | static procS cur_proc; | |
13814 | static procS *cur_proc_ptr; | |
13815 | static int numprocs; | |
13816 | ||
0a9ef439 | 13817 | /* Fill in an rs_align_code fragment. */ |
a19d8eb0 | 13818 | |
0a9ef439 RH |
13819 | void |
13820 | mips_handle_align (fragp) | |
13821 | fragS *fragp; | |
a19d8eb0 | 13822 | { |
0a9ef439 RH |
13823 | if (fragp->fr_type != rs_align_code) |
13824 | return; | |
13825 | ||
13826 | if (mips_opts.mips16) | |
a19d8eb0 CP |
13827 | { |
13828 | static const unsigned char be_nop[] = { 0x65, 0x00 }; | |
13829 | static const unsigned char le_nop[] = { 0x00, 0x65 }; | |
13830 | ||
0a9ef439 RH |
13831 | int bytes; |
13832 | char *p; | |
a19d8eb0 | 13833 | |
0a9ef439 RH |
13834 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
13835 | p = fragp->fr_literal + fragp->fr_fix; | |
13836 | ||
13837 | if (bytes & 1) | |
13838 | { | |
13839 | *p++ = 0; | |
f9419b05 | 13840 | fragp->fr_fix++; |
0a9ef439 RH |
13841 | } |
13842 | ||
13843 | memcpy (p, (target_big_endian ? be_nop : le_nop), 2); | |
13844 | fragp->fr_var = 2; | |
a19d8eb0 CP |
13845 | } |
13846 | ||
0a9ef439 | 13847 | /* For mips32, a nop is a zero, which we trivially get by doing nothing. */ |
a19d8eb0 CP |
13848 | } |
13849 | ||
252b5132 RH |
13850 | static void |
13851 | md_obj_begin () | |
13852 | { | |
13853 | } | |
13854 | ||
13855 | static void | |
13856 | md_obj_end () | |
13857 | { | |
13858 | /* check for premature end, nesting errors, etc */ | |
13859 | if (cur_proc_ptr) | |
9a41af64 | 13860 | as_warn (_("missing .end at end of assembly")); |
252b5132 RH |
13861 | } |
13862 | ||
13863 | static long | |
13864 | get_number () | |
13865 | { | |
13866 | int negative = 0; | |
13867 | long val = 0; | |
13868 | ||
13869 | if (*input_line_pointer == '-') | |
13870 | { | |
13871 | ++input_line_pointer; | |
13872 | negative = 1; | |
13873 | } | |
3882b010 | 13874 | if (!ISDIGIT (*input_line_pointer)) |
956cd1d6 | 13875 | as_bad (_("expected simple number")); |
252b5132 RH |
13876 | if (input_line_pointer[0] == '0') |
13877 | { | |
13878 | if (input_line_pointer[1] == 'x') | |
13879 | { | |
13880 | input_line_pointer += 2; | |
3882b010 | 13881 | while (ISXDIGIT (*input_line_pointer)) |
252b5132 RH |
13882 | { |
13883 | val <<= 4; | |
13884 | val |= hex_value (*input_line_pointer++); | |
13885 | } | |
13886 | return negative ? -val : val; | |
13887 | } | |
13888 | else | |
13889 | { | |
13890 | ++input_line_pointer; | |
3882b010 | 13891 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
13892 | { |
13893 | val <<= 3; | |
13894 | val |= *input_line_pointer++ - '0'; | |
13895 | } | |
13896 | return negative ? -val : val; | |
13897 | } | |
13898 | } | |
3882b010 | 13899 | if (!ISDIGIT (*input_line_pointer)) |
252b5132 RH |
13900 | { |
13901 | printf (_(" *input_line_pointer == '%c' 0x%02x\n"), | |
13902 | *input_line_pointer, *input_line_pointer); | |
956cd1d6 | 13903 | as_warn (_("invalid number")); |
252b5132 RH |
13904 | return -1; |
13905 | } | |
3882b010 | 13906 | while (ISDIGIT (*input_line_pointer)) |
252b5132 RH |
13907 | { |
13908 | val *= 10; | |
13909 | val += *input_line_pointer++ - '0'; | |
13910 | } | |
13911 | return negative ? -val : val; | |
13912 | } | |
13913 | ||
13914 | /* The .file directive; just like the usual .file directive, but there | |
c5dd6aab DJ |
13915 | is an initial number which is the ECOFF file index. In the non-ECOFF |
13916 | case .file implies DWARF-2. */ | |
13917 | ||
13918 | static void | |
13919 | s_mips_file (x) | |
13920 | int x ATTRIBUTE_UNUSED; | |
13921 | { | |
ecb4347a DJ |
13922 | static int first_file_directive = 0; |
13923 | ||
c5dd6aab DJ |
13924 | if (ECOFF_DEBUGGING) |
13925 | { | |
13926 | get_number (); | |
13927 | s_app_file (0); | |
13928 | } | |
13929 | else | |
ecb4347a DJ |
13930 | { |
13931 | char *filename; | |
13932 | ||
13933 | filename = dwarf2_directive_file (0); | |
13934 | ||
13935 | /* Versions of GCC up to 3.1 start files with a ".file" | |
13936 | directive even for stabs output. Make sure that this | |
13937 | ".file" is handled. Note that you need a version of GCC | |
13938 | after 3.1 in order to support DWARF-2 on MIPS. */ | |
13939 | if (filename != NULL && ! first_file_directive) | |
13940 | { | |
13941 | (void) new_logical_line (filename, -1); | |
13942 | s_app_file_string (filename); | |
13943 | } | |
13944 | first_file_directive = 1; | |
13945 | } | |
c5dd6aab DJ |
13946 | } |
13947 | ||
13948 | /* The .loc directive, implying DWARF-2. */ | |
252b5132 RH |
13949 | |
13950 | static void | |
c5dd6aab | 13951 | s_mips_loc (x) |
43841e91 | 13952 | int x ATTRIBUTE_UNUSED; |
252b5132 | 13953 | { |
c5dd6aab DJ |
13954 | if (!ECOFF_DEBUGGING) |
13955 | dwarf2_directive_loc (0); | |
252b5132 RH |
13956 | } |
13957 | ||
252b5132 RH |
13958 | /* The .end directive. */ |
13959 | ||
13960 | static void | |
13961 | s_mips_end (x) | |
43841e91 | 13962 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
13963 | { |
13964 | symbolS *p; | |
13965 | int maybe_text; | |
13966 | ||
7a621144 DJ |
13967 | /* Following functions need their own .frame and .cprestore directives. */ |
13968 | mips_frame_reg_valid = 0; | |
13969 | mips_cprestore_valid = 0; | |
13970 | ||
252b5132 RH |
13971 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
13972 | { | |
13973 | p = get_symbol (); | |
13974 | demand_empty_rest_of_line (); | |
13975 | } | |
13976 | else | |
13977 | p = NULL; | |
13978 | ||
13979 | #ifdef BFD_ASSEMBLER | |
13980 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
13981 | maybe_text = 1; | |
13982 | else | |
13983 | maybe_text = 0; | |
13984 | #else | |
13985 | if (now_seg != data_section && now_seg != bss_section) | |
13986 | maybe_text = 1; | |
13987 | else | |
13988 | maybe_text = 0; | |
13989 | #endif | |
13990 | ||
13991 | if (!maybe_text) | |
13992 | as_warn (_(".end not in text section")); | |
13993 | ||
13994 | if (!cur_proc_ptr) | |
13995 | { | |
13996 | as_warn (_(".end directive without a preceding .ent directive.")); | |
13997 | demand_empty_rest_of_line (); | |
13998 | return; | |
13999 | } | |
14000 | ||
14001 | if (p != NULL) | |
14002 | { | |
14003 | assert (S_GET_NAME (p)); | |
14004 | if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym))) | |
14005 | as_warn (_(".end symbol does not match .ent symbol.")); | |
ecb4347a DJ |
14006 | |
14007 | if (debug_type == DEBUG_STABS) | |
14008 | stabs_generate_asm_endfunc (S_GET_NAME (p), | |
14009 | S_GET_NAME (p)); | |
252b5132 RH |
14010 | } |
14011 | else | |
14012 | as_warn (_(".end directive missing or unknown symbol")); | |
14013 | ||
ecb4347a DJ |
14014 | #ifdef OBJ_ELF |
14015 | /* Generate a .pdr section. */ | |
14016 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING) | |
14017 | { | |
14018 | segT saved_seg = now_seg; | |
14019 | subsegT saved_subseg = now_subseg; | |
14020 | valueT dot; | |
14021 | expressionS exp; | |
14022 | char *fragp; | |
252b5132 | 14023 | |
ecb4347a | 14024 | dot = frag_now_fix (); |
252b5132 RH |
14025 | |
14026 | #ifdef md_flush_pending_output | |
ecb4347a | 14027 | md_flush_pending_output (); |
252b5132 RH |
14028 | #endif |
14029 | ||
ecb4347a DJ |
14030 | assert (pdr_seg); |
14031 | subseg_set (pdr_seg, 0); | |
252b5132 | 14032 | |
ecb4347a DJ |
14033 | /* Write the symbol. */ |
14034 | exp.X_op = O_symbol; | |
14035 | exp.X_add_symbol = p; | |
14036 | exp.X_add_number = 0; | |
14037 | emit_expr (&exp, 4); | |
252b5132 | 14038 | |
ecb4347a | 14039 | fragp = frag_more (7 * 4); |
252b5132 | 14040 | |
ecb4347a DJ |
14041 | md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4); |
14042 | md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4); | |
14043 | md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4); | |
14044 | md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4); | |
14045 | md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4); | |
14046 | md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4); | |
14047 | md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4); | |
252b5132 | 14048 | |
ecb4347a DJ |
14049 | subseg_set (saved_seg, saved_subseg); |
14050 | } | |
14051 | #endif /* OBJ_ELF */ | |
252b5132 RH |
14052 | |
14053 | cur_proc_ptr = NULL; | |
14054 | } | |
14055 | ||
14056 | /* The .aent and .ent directives. */ | |
14057 | ||
14058 | static void | |
14059 | s_mips_ent (aent) | |
14060 | int aent; | |
14061 | { | |
252b5132 RH |
14062 | symbolS *symbolP; |
14063 | int maybe_text; | |
14064 | ||
14065 | symbolP = get_symbol (); | |
14066 | if (*input_line_pointer == ',') | |
f9419b05 | 14067 | ++input_line_pointer; |
252b5132 | 14068 | SKIP_WHITESPACE (); |
3882b010 | 14069 | if (ISDIGIT (*input_line_pointer) |
d9a62219 | 14070 | || *input_line_pointer == '-') |
874e8986 | 14071 | get_number (); |
252b5132 RH |
14072 | |
14073 | #ifdef BFD_ASSEMBLER | |
14074 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
14075 | maybe_text = 1; | |
14076 | else | |
14077 | maybe_text = 0; | |
14078 | #else | |
14079 | if (now_seg != data_section && now_seg != bss_section) | |
14080 | maybe_text = 1; | |
14081 | else | |
14082 | maybe_text = 0; | |
14083 | #endif | |
14084 | ||
14085 | if (!maybe_text) | |
14086 | as_warn (_(".ent or .aent not in text section.")); | |
14087 | ||
14088 | if (!aent && cur_proc_ptr) | |
9a41af64 | 14089 | as_warn (_("missing .end")); |
252b5132 RH |
14090 | |
14091 | if (!aent) | |
14092 | { | |
7a621144 DJ |
14093 | /* This function needs its own .frame and .cprestore directives. */ |
14094 | mips_frame_reg_valid = 0; | |
14095 | mips_cprestore_valid = 0; | |
14096 | ||
252b5132 RH |
14097 | cur_proc_ptr = &cur_proc; |
14098 | memset (cur_proc_ptr, '\0', sizeof (procS)); | |
14099 | ||
14100 | cur_proc_ptr->isym = symbolP; | |
14101 | ||
49309057 | 14102 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 | 14103 | |
f9419b05 | 14104 | ++numprocs; |
ecb4347a DJ |
14105 | |
14106 | if (debug_type == DEBUG_STABS) | |
14107 | stabs_generate_asm_func (S_GET_NAME (symbolP), | |
14108 | S_GET_NAME (symbolP)); | |
252b5132 RH |
14109 | } |
14110 | ||
14111 | demand_empty_rest_of_line (); | |
14112 | } | |
14113 | ||
14114 | /* The .frame directive. If the mdebug section is present (IRIX 5 native) | |
bdaaa2e1 | 14115 | then ecoff.c (ecoff_directive_frame) is used. For embedded targets, |
252b5132 | 14116 | s_mips_frame is used so that we can set the PDR information correctly. |
bdaaa2e1 | 14117 | We can't use the ecoff routines because they make reference to the ecoff |
252b5132 RH |
14118 | symbol table (in the mdebug section). */ |
14119 | ||
14120 | static void | |
14121 | s_mips_frame (ignore) | |
2b3c5a5d | 14122 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 14123 | { |
ecb4347a DJ |
14124 | #ifdef OBJ_ELF |
14125 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING) | |
14126 | { | |
14127 | long val; | |
252b5132 | 14128 | |
ecb4347a DJ |
14129 | if (cur_proc_ptr == (procS *) NULL) |
14130 | { | |
14131 | as_warn (_(".frame outside of .ent")); | |
14132 | demand_empty_rest_of_line (); | |
14133 | return; | |
14134 | } | |
252b5132 | 14135 | |
ecb4347a DJ |
14136 | cur_proc_ptr->frame_reg = tc_get_register (1); |
14137 | ||
14138 | SKIP_WHITESPACE (); | |
14139 | if (*input_line_pointer++ != ',' | |
14140 | || get_absolute_expression_and_terminator (&val) != ',') | |
14141 | { | |
14142 | as_warn (_("Bad .frame directive")); | |
14143 | --input_line_pointer; | |
14144 | demand_empty_rest_of_line (); | |
14145 | return; | |
14146 | } | |
252b5132 | 14147 | |
ecb4347a DJ |
14148 | cur_proc_ptr->frame_offset = val; |
14149 | cur_proc_ptr->pc_reg = tc_get_register (0); | |
252b5132 | 14150 | |
252b5132 | 14151 | demand_empty_rest_of_line (); |
252b5132 | 14152 | } |
ecb4347a DJ |
14153 | else |
14154 | #endif /* OBJ_ELF */ | |
14155 | s_ignore (ignore); | |
252b5132 RH |
14156 | } |
14157 | ||
bdaaa2e1 KH |
14158 | /* The .fmask and .mask directives. If the mdebug section is present |
14159 | (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For | |
252b5132 | 14160 | embedded targets, s_mips_mask is used so that we can set the PDR |
bdaaa2e1 | 14161 | information correctly. We can't use the ecoff routines because they |
252b5132 RH |
14162 | make reference to the ecoff symbol table (in the mdebug section). */ |
14163 | ||
14164 | static void | |
14165 | s_mips_mask (reg_type) | |
14166 | char reg_type; | |
14167 | { | |
ecb4347a DJ |
14168 | #ifdef OBJ_ELF |
14169 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING) | |
252b5132 | 14170 | { |
ecb4347a | 14171 | long mask, off; |
252b5132 | 14172 | |
ecb4347a DJ |
14173 | if (cur_proc_ptr == (procS *) NULL) |
14174 | { | |
14175 | as_warn (_(".mask/.fmask outside of .ent")); | |
14176 | demand_empty_rest_of_line (); | |
14177 | return; | |
14178 | } | |
252b5132 | 14179 | |
ecb4347a DJ |
14180 | if (get_absolute_expression_and_terminator (&mask) != ',') |
14181 | { | |
14182 | as_warn (_("Bad .mask/.fmask directive")); | |
14183 | --input_line_pointer; | |
14184 | demand_empty_rest_of_line (); | |
14185 | return; | |
14186 | } | |
252b5132 | 14187 | |
ecb4347a DJ |
14188 | off = get_absolute_expression (); |
14189 | ||
14190 | if (reg_type == 'F') | |
14191 | { | |
14192 | cur_proc_ptr->fpreg_mask = mask; | |
14193 | cur_proc_ptr->fpreg_offset = off; | |
14194 | } | |
14195 | else | |
14196 | { | |
14197 | cur_proc_ptr->reg_mask = mask; | |
14198 | cur_proc_ptr->reg_offset = off; | |
14199 | } | |
14200 | ||
14201 | demand_empty_rest_of_line (); | |
252b5132 RH |
14202 | } |
14203 | else | |
ecb4347a DJ |
14204 | #endif /* OBJ_ELF */ |
14205 | s_ignore (reg_type); | |
252b5132 RH |
14206 | } |
14207 | ||
14208 | /* The .loc directive. */ | |
14209 | ||
14210 | #if 0 | |
14211 | static void | |
14212 | s_loc (x) | |
14213 | int x; | |
14214 | { | |
14215 | symbolS *symbolP; | |
14216 | int lineno; | |
14217 | int addroff; | |
14218 | ||
14219 | assert (now_seg == text_section); | |
14220 | ||
14221 | lineno = get_number (); | |
14222 | addroff = frag_now_fix (); | |
14223 | ||
14224 | symbolP = symbol_new ("", N_SLINE, addroff, frag_now); | |
14225 | S_SET_TYPE (symbolP, N_SLINE); | |
14226 | S_SET_OTHER (symbolP, 0); | |
14227 | S_SET_DESC (symbolP, lineno); | |
14228 | symbolP->sy_segment = now_seg; | |
14229 | } | |
14230 | #endif | |
e7af610e | 14231 | |
316f5878 RS |
14232 | /* A table describing all the processors gas knows about. Names are |
14233 | matched in the order listed. | |
e7af610e | 14234 | |
316f5878 RS |
14235 | To ease comparison, please keep this table in the same order as |
14236 | gcc's mips_cpu_info_table[]. */ | |
e972090a NC |
14237 | static const struct mips_cpu_info mips_cpu_info_table[] = |
14238 | { | |
316f5878 RS |
14239 | /* Entries for generic ISAs */ |
14240 | { "mips1", 1, ISA_MIPS1, CPU_R3000 }, | |
14241 | { "mips2", 1, ISA_MIPS2, CPU_R6000 }, | |
14242 | { "mips3", 1, ISA_MIPS3, CPU_R4000 }, | |
14243 | { "mips4", 1, ISA_MIPS4, CPU_R8000 }, | |
14244 | { "mips5", 1, ISA_MIPS5, CPU_MIPS5 }, | |
14245 | { "mips32", 1, ISA_MIPS32, CPU_MIPS32 }, | |
14246 | { "mips64", 1, ISA_MIPS64, CPU_MIPS64 }, | |
14247 | ||
14248 | /* MIPS I */ | |
14249 | { "r3000", 0, ISA_MIPS1, CPU_R3000 }, | |
14250 | { "r2000", 0, ISA_MIPS1, CPU_R3000 }, | |
14251 | { "r3900", 0, ISA_MIPS1, CPU_R3900 }, | |
14252 | ||
14253 | /* MIPS II */ | |
14254 | { "r6000", 0, ISA_MIPS2, CPU_R6000 }, | |
14255 | ||
14256 | /* MIPS III */ | |
14257 | { "r4000", 0, ISA_MIPS3, CPU_R4000 }, | |
14258 | { "r4010", 0, ISA_MIPS2, CPU_R4010 }, | |
14259 | { "vr4100", 0, ISA_MIPS3, CPU_VR4100 }, | |
14260 | { "vr4111", 0, ISA_MIPS3, CPU_R4111 }, | |
60b63b72 RS |
14261 | { "vr4120", 0, ISA_MIPS3, CPU_VR4120 }, |
14262 | { "vr4130", 0, ISA_MIPS3, CPU_VR4120 }, | |
14263 | { "vr4181", 0, ISA_MIPS3, CPU_R4111 }, | |
316f5878 RS |
14264 | { "vr4300", 0, ISA_MIPS3, CPU_R4300 }, |
14265 | { "r4400", 0, ISA_MIPS3, CPU_R4400 }, | |
14266 | { "r4600", 0, ISA_MIPS3, CPU_R4600 }, | |
14267 | { "orion", 0, ISA_MIPS3, CPU_R4600 }, | |
14268 | { "r4650", 0, ISA_MIPS3, CPU_R4650 }, | |
14269 | ||
14270 | /* MIPS IV */ | |
14271 | { "r8000", 0, ISA_MIPS4, CPU_R8000 }, | |
14272 | { "r10000", 0, ISA_MIPS4, CPU_R10000 }, | |
14273 | { "r12000", 0, ISA_MIPS4, CPU_R12000 }, | |
14274 | { "vr5000", 0, ISA_MIPS4, CPU_R5000 }, | |
60b63b72 RS |
14275 | { "vr5400", 0, ISA_MIPS4, CPU_VR5400 }, |
14276 | { "vr5500", 0, ISA_MIPS4, CPU_VR5500 }, | |
316f5878 RS |
14277 | { "rm5200", 0, ISA_MIPS4, CPU_R5000 }, |
14278 | { "rm5230", 0, ISA_MIPS4, CPU_R5000 }, | |
14279 | { "rm5231", 0, ISA_MIPS4, CPU_R5000 }, | |
14280 | { "rm5261", 0, ISA_MIPS4, CPU_R5000 }, | |
14281 | { "rm5721", 0, ISA_MIPS4, CPU_R5000 }, | |
14282 | { "r7000", 0, ISA_MIPS4, CPU_R5000 }, | |
14283 | ||
14284 | /* MIPS 32 */ | |
14285 | { "4kc", 0, ISA_MIPS32, CPU_MIPS32, }, | |
14286 | { "4km", 0, ISA_MIPS32, CPU_MIPS32 }, | |
14287 | { "4kp", 0, ISA_MIPS32, CPU_MIPS32 }, | |
e7af610e | 14288 | |
316f5878 RS |
14289 | /* MIPS 64 */ |
14290 | { "5kc", 0, ISA_MIPS64, CPU_MIPS64 }, | |
14291 | { "20kc", 0, ISA_MIPS64, CPU_MIPS64 }, | |
e7af610e | 14292 | |
c7a23324 | 14293 | /* Broadcom SB-1 CPU core */ |
316f5878 | 14294 | { "sb1", 0, ISA_MIPS64, CPU_SB1 }, |
e7af610e | 14295 | |
316f5878 RS |
14296 | /* End marker */ |
14297 | { NULL, 0, 0, 0 } | |
14298 | }; | |
e7af610e | 14299 | |
84ea6cf2 | 14300 | |
316f5878 RS |
14301 | /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL |
14302 | with a final "000" replaced by "k". Ignore case. | |
e7af610e | 14303 | |
316f5878 | 14304 | Note: this function is shared between GCC and GAS. */ |
c6c98b38 | 14305 | |
316f5878 RS |
14306 | static boolean |
14307 | mips_strict_matching_cpu_name_p (canonical, given) | |
14308 | const char *canonical, *given; | |
14309 | { | |
14310 | while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical)) | |
14311 | given++, canonical++; | |
14312 | ||
14313 | return ((*given == 0 && *canonical == 0) | |
14314 | || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0)); | |
14315 | } | |
14316 | ||
14317 | ||
14318 | /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied | |
14319 | CPU name. We've traditionally allowed a lot of variation here. | |
14320 | ||
14321 | Note: this function is shared between GCC and GAS. */ | |
14322 | ||
14323 | static boolean | |
14324 | mips_matching_cpu_name_p (canonical, given) | |
14325 | const char *canonical, *given; | |
14326 | { | |
14327 | /* First see if the name matches exactly, or with a final "000" | |
14328 | turned into "k". */ | |
14329 | if (mips_strict_matching_cpu_name_p (canonical, given)) | |
14330 | return true; | |
14331 | ||
14332 | /* If not, try comparing based on numerical designation alone. | |
14333 | See if GIVEN is an unadorned number, or 'r' followed by a number. */ | |
14334 | if (TOLOWER (*given) == 'r') | |
14335 | given++; | |
14336 | if (!ISDIGIT (*given)) | |
14337 | return false; | |
14338 | ||
14339 | /* Skip over some well-known prefixes in the canonical name, | |
14340 | hoping to find a number there too. */ | |
14341 | if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r') | |
14342 | canonical += 2; | |
14343 | else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm') | |
14344 | canonical += 2; | |
14345 | else if (TOLOWER (canonical[0]) == 'r') | |
14346 | canonical += 1; | |
14347 | ||
14348 | return mips_strict_matching_cpu_name_p (canonical, given); | |
14349 | } | |
14350 | ||
14351 | ||
14352 | /* Parse an option that takes the name of a processor as its argument. | |
14353 | OPTION is the name of the option and CPU_STRING is the argument. | |
14354 | Return the corresponding processor enumeration if the CPU_STRING is | |
14355 | recognized, otherwise report an error and return null. | |
14356 | ||
14357 | A similar function exists in GCC. */ | |
e7af610e NC |
14358 | |
14359 | static const struct mips_cpu_info * | |
316f5878 RS |
14360 | mips_parse_cpu (option, cpu_string) |
14361 | const char *option, *cpu_string; | |
e7af610e | 14362 | { |
316f5878 | 14363 | const struct mips_cpu_info *p; |
e7af610e | 14364 | |
316f5878 RS |
14365 | /* 'from-abi' selects the most compatible architecture for the given |
14366 | ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the | |
14367 | EABIs, we have to decide whether we're using the 32-bit or 64-bit | |
14368 | version. Look first at the -mgp options, if given, otherwise base | |
14369 | the choice on MIPS_DEFAULT_64BIT. | |
e7af610e | 14370 | |
316f5878 RS |
14371 | Treat NO_ABI like the EABIs. One reason to do this is that the |
14372 | plain 'mips' and 'mips64' configs have 'from-abi' as their default | |
14373 | architecture. This code picks MIPS I for 'mips' and MIPS III for | |
14374 | 'mips64', just as we did in the days before 'from-abi'. */ | |
14375 | if (strcasecmp (cpu_string, "from-abi") == 0) | |
14376 | { | |
14377 | if (ABI_NEEDS_32BIT_REGS (mips_abi)) | |
14378 | return mips_cpu_info_from_isa (ISA_MIPS1); | |
14379 | ||
14380 | if (ABI_NEEDS_64BIT_REGS (mips_abi)) | |
14381 | return mips_cpu_info_from_isa (ISA_MIPS3); | |
14382 | ||
14383 | if (file_mips_gp32 >= 0) | |
14384 | return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3); | |
14385 | ||
14386 | return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT | |
14387 | ? ISA_MIPS3 | |
14388 | : ISA_MIPS1); | |
14389 | } | |
14390 | ||
14391 | /* 'default' has traditionally been a no-op. Probably not very useful. */ | |
14392 | if (strcasecmp (cpu_string, "default") == 0) | |
14393 | return 0; | |
14394 | ||
14395 | for (p = mips_cpu_info_table; p->name != 0; p++) | |
14396 | if (mips_matching_cpu_name_p (p->name, cpu_string)) | |
14397 | return p; | |
14398 | ||
14399 | as_bad ("Bad value (%s) for %s", cpu_string, option); | |
14400 | return 0; | |
e7af610e NC |
14401 | } |
14402 | ||
316f5878 RS |
14403 | /* Return the canonical processor information for ISA (a member of the |
14404 | ISA_MIPS* enumeration). */ | |
14405 | ||
e7af610e NC |
14406 | static const struct mips_cpu_info * |
14407 | mips_cpu_info_from_isa (isa) | |
14408 | int isa; | |
14409 | { | |
14410 | int i; | |
14411 | ||
14412 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
14413 | if (mips_cpu_info_table[i].is_isa | |
316f5878 | 14414 | && isa == mips_cpu_info_table[i].isa) |
e7af610e NC |
14415 | return (&mips_cpu_info_table[i]); |
14416 | ||
e972090a | 14417 | return NULL; |
e7af610e | 14418 | } |
316f5878 RS |
14419 | \f |
14420 | static void | |
14421 | show (stream, string, col_p, first_p) | |
14422 | FILE *stream; | |
14423 | const char *string; | |
14424 | int *col_p; | |
14425 | int *first_p; | |
14426 | { | |
14427 | if (*first_p) | |
14428 | { | |
14429 | fprintf (stream, "%24s", ""); | |
14430 | *col_p = 24; | |
14431 | } | |
14432 | else | |
14433 | { | |
14434 | fprintf (stream, ", "); | |
14435 | *col_p += 2; | |
14436 | } | |
e7af610e | 14437 | |
316f5878 RS |
14438 | if (*col_p + strlen (string) > 72) |
14439 | { | |
14440 | fprintf (stream, "\n%24s", ""); | |
14441 | *col_p = 24; | |
14442 | } | |
14443 | ||
14444 | fprintf (stream, "%s", string); | |
14445 | *col_p += strlen (string); | |
14446 | ||
14447 | *first_p = 0; | |
14448 | } | |
14449 | ||
14450 | void | |
14451 | md_show_usage (stream) | |
14452 | FILE *stream; | |
e7af610e | 14453 | { |
316f5878 RS |
14454 | int column, first; |
14455 | size_t i; | |
14456 | ||
14457 | fprintf (stream, _("\ | |
14458 | MIPS options:\n\ | |
14459 | -membedded-pic generate embedded position independent code\n\ | |
14460 | -EB generate big endian output\n\ | |
14461 | -EL generate little endian output\n\ | |
14462 | -g, -g2 do not remove unneeded NOPs or swap branches\n\ | |
14463 | -G NUM allow referencing objects up to NUM bytes\n\ | |
14464 | implicitly with the gp register [default 8]\n")); | |
14465 | fprintf (stream, _("\ | |
14466 | -mips1 generate MIPS ISA I instructions\n\ | |
14467 | -mips2 generate MIPS ISA II instructions\n\ | |
14468 | -mips3 generate MIPS ISA III instructions\n\ | |
14469 | -mips4 generate MIPS ISA IV instructions\n\ | |
14470 | -mips5 generate MIPS ISA V instructions\n\ | |
14471 | -mips32 generate MIPS32 ISA instructions\n\ | |
14472 | -mips64 generate MIPS64 ISA instructions\n\ | |
14473 | -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n")); | |
14474 | ||
14475 | first = 1; | |
e7af610e NC |
14476 | |
14477 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) | |
316f5878 RS |
14478 | show (stream, mips_cpu_info_table[i].name, &column, &first); |
14479 | show (stream, "from-abi", &column, &first); | |
14480 | fputc ('\n', stream); | |
e7af610e | 14481 | |
316f5878 RS |
14482 | fprintf (stream, _("\ |
14483 | -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\ | |
14484 | -no-mCPU don't generate code specific to CPU.\n\ | |
14485 | For -mCPU and -no-mCPU, CPU must be one of:\n")); | |
14486 | ||
14487 | first = 1; | |
14488 | ||
14489 | show (stream, "3900", &column, &first); | |
14490 | show (stream, "4010", &column, &first); | |
14491 | show (stream, "4100", &column, &first); | |
14492 | show (stream, "4650", &column, &first); | |
14493 | fputc ('\n', stream); | |
14494 | ||
14495 | fprintf (stream, _("\ | |
14496 | -mips16 generate mips16 instructions\n\ | |
14497 | -no-mips16 do not generate mips16 instructions\n")); | |
14498 | fprintf (stream, _("\ | |
14499 | -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\ | |
14500 | -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\ | |
14501 | -O0 remove unneeded NOPs, do not swap branches\n\ | |
14502 | -O remove unneeded NOPs and swap branches\n\ | |
14503 | -n warn about NOPs generated from macros\n\ | |
14504 | --[no-]construct-floats [dis]allow floating point values to be constructed\n\ | |
14505 | --trap, --no-break trap exception on div by 0 and mult overflow\n\ | |
14506 | --break, --no-trap break exception on div by 0 and mult overflow\n")); | |
14507 | #ifdef OBJ_ELF | |
14508 | fprintf (stream, _("\ | |
14509 | -KPIC, -call_shared generate SVR4 position independent code\n\ | |
14510 | -non_shared do not generate position independent code\n\ | |
14511 | -xgot assume a 32 bit GOT\n\ | |
14512 | -mabi=ABI create ABI conformant object file for:\n")); | |
14513 | ||
14514 | first = 1; | |
14515 | ||
14516 | show (stream, "32", &column, &first); | |
14517 | show (stream, "o64", &column, &first); | |
14518 | show (stream, "n32", &column, &first); | |
14519 | show (stream, "64", &column, &first); | |
14520 | show (stream, "eabi", &column, &first); | |
14521 | ||
14522 | fputc ('\n', stream); | |
14523 | ||
14524 | fprintf (stream, _("\ | |
14525 | -32 create o32 ABI object file (default)\n\ | |
14526 | -n32 create n32 ABI object file\n\ | |
14527 | -64 create 64 ABI object file\n")); | |
14528 | #endif | |
e7af610e | 14529 | } |